UNPKG

langsmith

Version:

Client library to connect to the LangSmith Observability and Evaluation Platform.

31 lines (30 loc) 1.05 kB
import { getInvalidPromptIdentifierMsg } from "./error.js"; /** * Parse a hub repo identifier (owner/name:hash, name, etc.). * * Prompts, agents, and skills share the same identifier grammar on Hub. */ export function parseHubIdentifier(identifier) { if (!identifier || identifier.split("/").length > 2 || identifier.startsWith("/") || identifier.endsWith("/") || identifier.split(":").length > 2) { throw new Error(getInvalidPromptIdentifierMsg(identifier)); } const [ownerNamePart, commitPart] = identifier.split(":"); const commit = commitPart || "latest"; if (ownerNamePart.includes("/")) { const [owner, name] = ownerNamePart.split("/", 2); if (!owner || !name) { throw new Error(getInvalidPromptIdentifierMsg(identifier)); } return [owner, name, commit]; } else { if (!ownerNamePart) { throw new Error(getInvalidPromptIdentifierMsg(identifier)); } return ["-", ownerNamePart, commit]; } }