@copilotkit/shared
Advanced tools
| //#region src/utils/inspector-metadata.ts | ||
| function isRecord(value) { | ||
| if (typeof value !== "object" || value === null || Array.isArray(value)) return false; | ||
| try { | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return prototype === Object.prototype || prototype === null; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function readOwnDataProperty(value, key) { | ||
| try { | ||
| const descriptor = Object.getOwnPropertyDescriptor(value, key); | ||
| return descriptor !== void 0 && "value" in descriptor ? descriptor.value : void 0; | ||
| } catch { | ||
| return; | ||
| } | ||
| } | ||
| function parseNonBlankString(value) { | ||
| if (typeof value !== "string") return; | ||
| const parsed = value.trim(); | ||
| return parsed.length > 0 ? parsed : void 0; | ||
| } | ||
| function parseIdentity(value) { | ||
| if (!isRecord(value)) return; | ||
| const organizationName = parseNonBlankString(value.organizationName); | ||
| const projectName = parseNonBlankString(value.projectName); | ||
| if (organizationName === void 0 || projectName === void 0) return; | ||
| return { | ||
| organizationName, | ||
| projectName | ||
| }; | ||
| } | ||
| function parsePlan(value) { | ||
| if (!isRecord(value)) return; | ||
| const code = parseNonBlankString(value.code); | ||
| const label = parseNonBlankString(value.label); | ||
| if (code === void 0 || label === void 0) return; | ||
| return { | ||
| code, | ||
| label | ||
| }; | ||
| } | ||
| function parseLicense(value) { | ||
| if (!isRecord(value)) return; | ||
| switch (value.state) { | ||
| case "valid": | ||
| case "none": | ||
| case "expired": | ||
| case "unknown": return { state: value.state }; | ||
| default: return; | ||
| } | ||
| } | ||
| function parseActionKind(value) { | ||
| switch (value) { | ||
| case "manage_plan": | ||
| case "renew": | ||
| case "enable_intelligence": return value; | ||
| default: return; | ||
| } | ||
| } | ||
| function parseSafeActionUrl(value) { | ||
| const url = parseNonBlankString(value); | ||
| if (url === void 0 || url.includes("?") || url.includes("#")) return; | ||
| const authorityStart = url.indexOf("://"); | ||
| if (authorityStart < 1) return; | ||
| const authorityAndPath = url.slice(authorityStart + 3); | ||
| const pathStart = authorityAndPath.indexOf("/"); | ||
| if ((pathStart === -1 ? authorityAndPath : authorityAndPath.slice(0, pathStart)).includes("@")) return; | ||
| let parsed; | ||
| try { | ||
| parsed = new URL(url); | ||
| } catch { | ||
| return; | ||
| } | ||
| if (parsed.hostname.length === 0 || parsed.username || parsed.password) return; | ||
| if (parsed.protocol === "https:") return url; | ||
| const isLoopbackHost = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "[::1]"; | ||
| if (parsed.protocol === "http:" && isLoopbackHost) return url; | ||
| } | ||
| function parseAction(value) { | ||
| if (!isRecord(value)) return; | ||
| const kind = parseActionKind(value.kind); | ||
| const url = parseSafeActionUrl(value.url); | ||
| if (kind === void 0 || url === void 0) return; | ||
| return { | ||
| kind, | ||
| url | ||
| }; | ||
| } | ||
| function isFiniteNonnegativeInteger(value) { | ||
| return typeof value === "number" && Number.isSafeInteger(value) && value >= 0; | ||
| } | ||
| function parseUsageLimit(value) { | ||
| if (!isRecord(value)) return; | ||
| if (value.kind === "finite") { | ||
| if (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 1) return; | ||
| return { | ||
| kind: "finite", | ||
| value: value.value | ||
| }; | ||
| } | ||
| if (value.kind === "unlimited") return { kind: "unlimited" }; | ||
| if (value.kind === "unknown") return { kind: "unknown" }; | ||
| } | ||
| function parseUsage(value) { | ||
| if (!isRecord(value)) return; | ||
| const limit = parseUsageLimit(value.limit); | ||
| const used = value.used; | ||
| if (!isFiniteNonnegativeInteger(used) || limit === void 0) return; | ||
| const rawExpiringSoonCount = readOwnDataProperty(value, "expiringSoonCount"); | ||
| const expiringSoonCount = isFiniteNonnegativeInteger(rawExpiringSoonCount) ? rawExpiringSoonCount : void 0; | ||
| return { | ||
| used, | ||
| limit, | ||
| ...expiringSoonCount === void 0 ? {} : { expiringSoonCount } | ||
| }; | ||
| } | ||
| /** | ||
| * Parses untrusted inspector metadata without letting one invalid optional | ||
| * module hide the other valid modules. | ||
| * | ||
| * @param value - The decoded runtime response body. | ||
| * @returns Normalized version 1 metadata, or `undefined` for an unsupported | ||
| * top-level payload. | ||
| */ | ||
| function parseInspectorMetadataV1(value) { | ||
| if (!isRecord(value) || value.schemaVersion !== 1) return; | ||
| const identity = parseIdentity(value.identity); | ||
| const plan = parsePlan(value.plan); | ||
| const license = parseLicense(value.license); | ||
| const action = parseAction(value.action); | ||
| const usage = parseUsage(value.usage); | ||
| return { | ||
| schemaVersion: 1, | ||
| ...identity === void 0 ? {} : { identity }, | ||
| ...plan === void 0 ? {} : { plan }, | ||
| ...license === void 0 ? {} : { license }, | ||
| ...action === void 0 ? {} : { action }, | ||
| ...usage === void 0 ? {} : { usage } | ||
| }; | ||
| } | ||
| //#endregion | ||
| exports.parseInspectorMetadataV1 = parseInspectorMetadataV1; | ||
| //# sourceMappingURL=inspector-metadata.cjs.map |
| {"version":3,"file":"inspector-metadata.cjs","names":[],"sources":["../../src/utils/inspector-metadata.ts"],"sourcesContent":["/**\n * Inspector metadata supplied by a trusted CopilotKit runtime.\n *\n * Each optional module is independent so clients can render partial metadata\n * from runtimes that do not expose every module.\n */\nexport interface InspectorMetadataV1 {\n readonly schemaVersion: 1;\n readonly identity?: {\n readonly organizationName: string;\n readonly projectName: string;\n };\n readonly plan?: {\n readonly code: string;\n readonly label: string;\n };\n readonly license?: {\n readonly state: \"valid\" | \"none\" | \"expired\" | \"unknown\";\n };\n readonly action?:\n | { readonly kind: \"manage_plan\"; readonly url: string }\n | { readonly kind: \"renew\"; readonly url: string }\n | { readonly kind: \"enable_intelligence\"; readonly url: string };\n readonly usage?: {\n readonly used: number;\n readonly limit:\n | { readonly kind: \"finite\"; readonly value: number }\n | { readonly kind: \"unlimited\" }\n | { readonly kind: \"unknown\" };\n readonly expiringSoonCount?: number;\n };\n}\n\ntype UnknownRecord = Record<string, unknown>;\ntype InspectorIdentity = NonNullable<InspectorMetadataV1[\"identity\"]>;\ntype InspectorPlan = NonNullable<InspectorMetadataV1[\"plan\"]>;\ntype InspectorLicense = NonNullable<InspectorMetadataV1[\"license\"]>;\ntype InspectorAction = NonNullable<InspectorMetadataV1[\"action\"]>;\ntype InspectorUsage = NonNullable<InspectorMetadataV1[\"usage\"]>;\ntype InspectorUsageLimit = InspectorUsage[\"limit\"];\n\nfunction isRecord(value: unknown): value is UnknownRecord {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n\n try {\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n } catch {\n return false;\n }\n}\n\nfunction readOwnDataProperty(value: UnknownRecord, key: string): unknown {\n try {\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n return descriptor !== undefined && \"value\" in descriptor\n ? descriptor.value\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction parseNonBlankString(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const parsed = value.trim();\n return parsed.length > 0 ? parsed : undefined;\n}\n\nfunction parseIdentity(value: unknown): InspectorIdentity | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const organizationName = parseNonBlankString(value.organizationName);\n const projectName = parseNonBlankString(value.projectName);\n if (organizationName === undefined || projectName === undefined) {\n return undefined;\n }\n\n return { organizationName, projectName };\n}\n\nfunction parsePlan(value: unknown): InspectorPlan | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const code = parseNonBlankString(value.code);\n const label = parseNonBlankString(value.label);\n if (code === undefined || label === undefined) {\n return undefined;\n }\n\n return { code, label };\n}\n\nfunction parseLicense(value: unknown): InspectorLicense | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n switch (value.state) {\n case \"valid\":\n case \"none\":\n case \"expired\":\n case \"unknown\":\n return { state: value.state };\n default:\n return undefined;\n }\n}\n\nfunction parseActionKind(value: unknown): InspectorAction[\"kind\"] | undefined {\n switch (value) {\n case \"manage_plan\":\n case \"renew\":\n case \"enable_intelligence\":\n return value;\n default:\n return undefined;\n }\n}\n\nfunction parseSafeActionUrl(value: unknown): string | undefined {\n const url = parseNonBlankString(value);\n if (url === undefined || url.includes(\"?\") || url.includes(\"#\")) {\n return undefined;\n }\n\n const authorityStart = url.indexOf(\"://\");\n if (authorityStart < 1) {\n return undefined;\n }\n\n const authorityAndPath = url.slice(authorityStart + 3);\n const pathStart = authorityAndPath.indexOf(\"/\");\n const authority =\n pathStart === -1 ? authorityAndPath : authorityAndPath.slice(0, pathStart);\n if (authority.includes(\"@\")) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return undefined;\n }\n\n if (parsed.hostname.length === 0 || parsed.username || parsed.password) {\n return undefined;\n }\n\n if (parsed.protocol === \"https:\") {\n return url;\n }\n\n const isLoopbackHost =\n parsed.hostname === \"localhost\" ||\n parsed.hostname === \"127.0.0.1\" ||\n parsed.hostname === \"[::1]\";\n if (parsed.protocol === \"http:\" && isLoopbackHost) {\n return url;\n }\n\n return undefined;\n}\n\nfunction parseAction(value: unknown): InspectorAction | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const kind = parseActionKind(value.kind);\n const url = parseSafeActionUrl(value.url);\n if (kind === undefined || url === undefined) {\n return undefined;\n }\n\n return { kind, url };\n}\n\nfunction isFiniteNonnegativeInteger(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction parseUsageLimit(value: unknown): InspectorUsageLimit | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n if (value.kind === \"finite\") {\n if (\n typeof value.value !== \"number\" ||\n !Number.isSafeInteger(value.value) ||\n value.value < 1\n ) {\n return undefined;\n }\n\n return { kind: \"finite\", value: value.value };\n }\n\n if (value.kind === \"unlimited\") {\n return { kind: \"unlimited\" };\n }\n\n if (value.kind === \"unknown\") {\n return { kind: \"unknown\" };\n }\n\n return undefined;\n}\n\nfunction parseUsage(value: unknown): InspectorUsage | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const limit = parseUsageLimit(value.limit);\n const used = value.used;\n if (!isFiniteNonnegativeInteger(used) || limit === undefined) {\n return undefined;\n }\n\n const rawExpiringSoonCount = readOwnDataProperty(value, \"expiringSoonCount\");\n const expiringSoonCount = isFiniteNonnegativeInteger(rawExpiringSoonCount)\n ? rawExpiringSoonCount\n : undefined;\n\n return {\n used,\n limit,\n ...(expiringSoonCount === undefined ? {} : { expiringSoonCount }),\n };\n}\n\n/**\n * Parses untrusted inspector metadata without letting one invalid optional\n * module hide the other valid modules.\n *\n * @param value - The decoded runtime response body.\n * @returns Normalized version 1 metadata, or `undefined` for an unsupported\n * top-level payload.\n */\nexport function parseInspectorMetadataV1(\n value: unknown,\n): InspectorMetadataV1 | undefined {\n if (!isRecord(value) || value.schemaVersion !== 1) {\n return undefined;\n }\n\n const identity = parseIdentity(value.identity);\n const plan = parsePlan(value.plan);\n const license = parseLicense(value.license);\n const action = parseAction(value.action);\n const usage = parseUsage(value.usage);\n\n return {\n schemaVersion: 1,\n ...(identity === undefined ? {} : { identity }),\n ...(plan === undefined ? {} : { plan }),\n ...(license === undefined ? {} : { license }),\n ...(action === undefined ? {} : { action }),\n ...(usage === undefined ? {} : { usage }),\n };\n}\n"],"mappings":"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"} |
| //#region src/utils/inspector-metadata.d.ts | ||
| /** | ||
| * Inspector metadata supplied by a trusted CopilotKit runtime. | ||
| * | ||
| * Each optional module is independent so clients can render partial metadata | ||
| * from runtimes that do not expose every module. | ||
| */ | ||
| interface InspectorMetadataV1 { | ||
| readonly schemaVersion: 1; | ||
| readonly identity?: { | ||
| readonly organizationName: string; | ||
| readonly projectName: string; | ||
| }; | ||
| readonly plan?: { | ||
| readonly code: string; | ||
| readonly label: string; | ||
| }; | ||
| readonly license?: { | ||
| readonly state: "valid" | "none" | "expired" | "unknown"; | ||
| }; | ||
| readonly action?: { | ||
| readonly kind: "manage_plan"; | ||
| readonly url: string; | ||
| } | { | ||
| readonly kind: "renew"; | ||
| readonly url: string; | ||
| } | { | ||
| readonly kind: "enable_intelligence"; | ||
| readonly url: string; | ||
| }; | ||
| readonly usage?: { | ||
| readonly used: number; | ||
| readonly limit: { | ||
| readonly kind: "finite"; | ||
| readonly value: number; | ||
| } | { | ||
| readonly kind: "unlimited"; | ||
| } | { | ||
| readonly kind: "unknown"; | ||
| }; | ||
| readonly expiringSoonCount?: number; | ||
| }; | ||
| } | ||
| /** | ||
| * Parses untrusted inspector metadata without letting one invalid optional | ||
| * module hide the other valid modules. | ||
| * | ||
| * @param value - The decoded runtime response body. | ||
| * @returns Normalized version 1 metadata, or `undefined` for an unsupported | ||
| * top-level payload. | ||
| */ | ||
| declare function parseInspectorMetadataV1(value: unknown): InspectorMetadataV1 | undefined; | ||
| //#endregion | ||
| export { InspectorMetadataV1, parseInspectorMetadataV1 }; | ||
| //# sourceMappingURL=inspector-metadata.d.cts.map |
| {"version":3,"file":"inspector-metadata.d.cts","names":[],"sources":["../../src/utils/inspector-metadata.ts"],"mappings":";;AAMA;;;;;UAAiB,mBAAA;EAAA,SACN,aAAA;EAAA,SACA,QAAA;IAAA,SACE,gBAAA;IAAA,SACA,WAAA;EAAA;EAAA,SAEF,IAAA;IAAA,SACE,IAAA;IAAA,SACA,KAAA;EAAA;EAAA,SAEF,OAAA;IAAA,SACE,KAAA;EAAA;EAAA,SAEF,MAAA;IAAA,SACM,IAAA;IAAA,SAA8B,GAAA;EAAA;IAAA,SAC9B,IAAA;IAAA,SAAwB,GAAA;EAAA;IAAA,SACxB,IAAA;IAAA,SAAsC,GAAA;EAAA;EAAA,SAC5C,KAAA;IAAA,SACE,IAAA;IAAA,SACA,KAAA;MAAA,SACM,IAAA;MAAA,SAAyB,KAAA;IAAA;MAAA,SACzB,IAAA;IAAA;MAAA,SACA,IAAA;IAAA;IAAA,SACN,iBAAA;EAAA;AAAA;;;;;;;;;iBA8NG,wBAAA,CACd,KAAA,YACC,mBAAA"} |
| //#region src/utils/inspector-metadata.d.ts | ||
| /** | ||
| * Inspector metadata supplied by a trusted CopilotKit runtime. | ||
| * | ||
| * Each optional module is independent so clients can render partial metadata | ||
| * from runtimes that do not expose every module. | ||
| */ | ||
| interface InspectorMetadataV1 { | ||
| readonly schemaVersion: 1; | ||
| readonly identity?: { | ||
| readonly organizationName: string; | ||
| readonly projectName: string; | ||
| }; | ||
| readonly plan?: { | ||
| readonly code: string; | ||
| readonly label: string; | ||
| }; | ||
| readonly license?: { | ||
| readonly state: "valid" | "none" | "expired" | "unknown"; | ||
| }; | ||
| readonly action?: { | ||
| readonly kind: "manage_plan"; | ||
| readonly url: string; | ||
| } | { | ||
| readonly kind: "renew"; | ||
| readonly url: string; | ||
| } | { | ||
| readonly kind: "enable_intelligence"; | ||
| readonly url: string; | ||
| }; | ||
| readonly usage?: { | ||
| readonly used: number; | ||
| readonly limit: { | ||
| readonly kind: "finite"; | ||
| readonly value: number; | ||
| } | { | ||
| readonly kind: "unlimited"; | ||
| } | { | ||
| readonly kind: "unknown"; | ||
| }; | ||
| readonly expiringSoonCount?: number; | ||
| }; | ||
| } | ||
| /** | ||
| * Parses untrusted inspector metadata without letting one invalid optional | ||
| * module hide the other valid modules. | ||
| * | ||
| * @param value - The decoded runtime response body. | ||
| * @returns Normalized version 1 metadata, or `undefined` for an unsupported | ||
| * top-level payload. | ||
| */ | ||
| declare function parseInspectorMetadataV1(value: unknown): InspectorMetadataV1 | undefined; | ||
| //#endregion | ||
| export { InspectorMetadataV1, parseInspectorMetadataV1 }; | ||
| //# sourceMappingURL=inspector-metadata.d.mts.map |
| {"version":3,"file":"inspector-metadata.d.mts","names":[],"sources":["../../src/utils/inspector-metadata.ts"],"mappings":";;AAMA;;;;;UAAiB,mBAAA;EAAA,SACN,aAAA;EAAA,SACA,QAAA;IAAA,SACE,gBAAA;IAAA,SACA,WAAA;EAAA;EAAA,SAEF,IAAA;IAAA,SACE,IAAA;IAAA,SACA,KAAA;EAAA;EAAA,SAEF,OAAA;IAAA,SACE,KAAA;EAAA;EAAA,SAEF,MAAA;IAAA,SACM,IAAA;IAAA,SAA8B,GAAA;EAAA;IAAA,SAC9B,IAAA;IAAA,SAAwB,GAAA;EAAA;IAAA,SACxB,IAAA;IAAA,SAAsC,GAAA;EAAA;EAAA,SAC5C,KAAA;IAAA,SACE,IAAA;IAAA,SACA,KAAA;MAAA,SACM,IAAA;MAAA,SAAyB,KAAA;IAAA;MAAA,SACzB,IAAA;IAAA;MAAA,SACA,IAAA;IAAA;IAAA,SACN,iBAAA;EAAA;AAAA;;;;;;;;;iBA8NG,wBAAA,CACd,KAAA,YACC,mBAAA"} |
| //#region src/utils/inspector-metadata.ts | ||
| function isRecord(value) { | ||
| if (typeof value !== "object" || value === null || Array.isArray(value)) return false; | ||
| try { | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return prototype === Object.prototype || prototype === null; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function readOwnDataProperty(value, key) { | ||
| try { | ||
| const descriptor = Object.getOwnPropertyDescriptor(value, key); | ||
| return descriptor !== void 0 && "value" in descriptor ? descriptor.value : void 0; | ||
| } catch { | ||
| return; | ||
| } | ||
| } | ||
| function parseNonBlankString(value) { | ||
| if (typeof value !== "string") return; | ||
| const parsed = value.trim(); | ||
| return parsed.length > 0 ? parsed : void 0; | ||
| } | ||
| function parseIdentity(value) { | ||
| if (!isRecord(value)) return; | ||
| const organizationName = parseNonBlankString(value.organizationName); | ||
| const projectName = parseNonBlankString(value.projectName); | ||
| if (organizationName === void 0 || projectName === void 0) return; | ||
| return { | ||
| organizationName, | ||
| projectName | ||
| }; | ||
| } | ||
| function parsePlan(value) { | ||
| if (!isRecord(value)) return; | ||
| const code = parseNonBlankString(value.code); | ||
| const label = parseNonBlankString(value.label); | ||
| if (code === void 0 || label === void 0) return; | ||
| return { | ||
| code, | ||
| label | ||
| }; | ||
| } | ||
| function parseLicense(value) { | ||
| if (!isRecord(value)) return; | ||
| switch (value.state) { | ||
| case "valid": | ||
| case "none": | ||
| case "expired": | ||
| case "unknown": return { state: value.state }; | ||
| default: return; | ||
| } | ||
| } | ||
| function parseActionKind(value) { | ||
| switch (value) { | ||
| case "manage_plan": | ||
| case "renew": | ||
| case "enable_intelligence": return value; | ||
| default: return; | ||
| } | ||
| } | ||
| function parseSafeActionUrl(value) { | ||
| const url = parseNonBlankString(value); | ||
| if (url === void 0 || url.includes("?") || url.includes("#")) return; | ||
| const authorityStart = url.indexOf("://"); | ||
| if (authorityStart < 1) return; | ||
| const authorityAndPath = url.slice(authorityStart + 3); | ||
| const pathStart = authorityAndPath.indexOf("/"); | ||
| if ((pathStart === -1 ? authorityAndPath : authorityAndPath.slice(0, pathStart)).includes("@")) return; | ||
| let parsed; | ||
| try { | ||
| parsed = new URL(url); | ||
| } catch { | ||
| return; | ||
| } | ||
| if (parsed.hostname.length === 0 || parsed.username || parsed.password) return; | ||
| if (parsed.protocol === "https:") return url; | ||
| const isLoopbackHost = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "[::1]"; | ||
| if (parsed.protocol === "http:" && isLoopbackHost) return url; | ||
| } | ||
| function parseAction(value) { | ||
| if (!isRecord(value)) return; | ||
| const kind = parseActionKind(value.kind); | ||
| const url = parseSafeActionUrl(value.url); | ||
| if (kind === void 0 || url === void 0) return; | ||
| return { | ||
| kind, | ||
| url | ||
| }; | ||
| } | ||
| function isFiniteNonnegativeInteger(value) { | ||
| return typeof value === "number" && Number.isSafeInteger(value) && value >= 0; | ||
| } | ||
| function parseUsageLimit(value) { | ||
| if (!isRecord(value)) return; | ||
| if (value.kind === "finite") { | ||
| if (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 1) return; | ||
| return { | ||
| kind: "finite", | ||
| value: value.value | ||
| }; | ||
| } | ||
| if (value.kind === "unlimited") return { kind: "unlimited" }; | ||
| if (value.kind === "unknown") return { kind: "unknown" }; | ||
| } | ||
| function parseUsage(value) { | ||
| if (!isRecord(value)) return; | ||
| const limit = parseUsageLimit(value.limit); | ||
| const used = value.used; | ||
| if (!isFiniteNonnegativeInteger(used) || limit === void 0) return; | ||
| const rawExpiringSoonCount = readOwnDataProperty(value, "expiringSoonCount"); | ||
| const expiringSoonCount = isFiniteNonnegativeInteger(rawExpiringSoonCount) ? rawExpiringSoonCount : void 0; | ||
| return { | ||
| used, | ||
| limit, | ||
| ...expiringSoonCount === void 0 ? {} : { expiringSoonCount } | ||
| }; | ||
| } | ||
| /** | ||
| * Parses untrusted inspector metadata without letting one invalid optional | ||
| * module hide the other valid modules. | ||
| * | ||
| * @param value - The decoded runtime response body. | ||
| * @returns Normalized version 1 metadata, or `undefined` for an unsupported | ||
| * top-level payload. | ||
| */ | ||
| function parseInspectorMetadataV1(value) { | ||
| if (!isRecord(value) || value.schemaVersion !== 1) return; | ||
| const identity = parseIdentity(value.identity); | ||
| const plan = parsePlan(value.plan); | ||
| const license = parseLicense(value.license); | ||
| const action = parseAction(value.action); | ||
| const usage = parseUsage(value.usage); | ||
| return { | ||
| schemaVersion: 1, | ||
| ...identity === void 0 ? {} : { identity }, | ||
| ...plan === void 0 ? {} : { plan }, | ||
| ...license === void 0 ? {} : { license }, | ||
| ...action === void 0 ? {} : { action }, | ||
| ...usage === void 0 ? {} : { usage } | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { parseInspectorMetadataV1 }; | ||
| //# sourceMappingURL=inspector-metadata.mjs.map |
| {"version":3,"file":"inspector-metadata.mjs","names":[],"sources":["../../src/utils/inspector-metadata.ts"],"sourcesContent":["/**\n * Inspector metadata supplied by a trusted CopilotKit runtime.\n *\n * Each optional module is independent so clients can render partial metadata\n * from runtimes that do not expose every module.\n */\nexport interface InspectorMetadataV1 {\n readonly schemaVersion: 1;\n readonly identity?: {\n readonly organizationName: string;\n readonly projectName: string;\n };\n readonly plan?: {\n readonly code: string;\n readonly label: string;\n };\n readonly license?: {\n readonly state: \"valid\" | \"none\" | \"expired\" | \"unknown\";\n };\n readonly action?:\n | { readonly kind: \"manage_plan\"; readonly url: string }\n | { readonly kind: \"renew\"; readonly url: string }\n | { readonly kind: \"enable_intelligence\"; readonly url: string };\n readonly usage?: {\n readonly used: number;\n readonly limit:\n | { readonly kind: \"finite\"; readonly value: number }\n | { readonly kind: \"unlimited\" }\n | { readonly kind: \"unknown\" };\n readonly expiringSoonCount?: number;\n };\n}\n\ntype UnknownRecord = Record<string, unknown>;\ntype InspectorIdentity = NonNullable<InspectorMetadataV1[\"identity\"]>;\ntype InspectorPlan = NonNullable<InspectorMetadataV1[\"plan\"]>;\ntype InspectorLicense = NonNullable<InspectorMetadataV1[\"license\"]>;\ntype InspectorAction = NonNullable<InspectorMetadataV1[\"action\"]>;\ntype InspectorUsage = NonNullable<InspectorMetadataV1[\"usage\"]>;\ntype InspectorUsageLimit = InspectorUsage[\"limit\"];\n\nfunction isRecord(value: unknown): value is UnknownRecord {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n\n try {\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n } catch {\n return false;\n }\n}\n\nfunction readOwnDataProperty(value: UnknownRecord, key: string): unknown {\n try {\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n return descriptor !== undefined && \"value\" in descriptor\n ? descriptor.value\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction parseNonBlankString(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const parsed = value.trim();\n return parsed.length > 0 ? parsed : undefined;\n}\n\nfunction parseIdentity(value: unknown): InspectorIdentity | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const organizationName = parseNonBlankString(value.organizationName);\n const projectName = parseNonBlankString(value.projectName);\n if (organizationName === undefined || projectName === undefined) {\n return undefined;\n }\n\n return { organizationName, projectName };\n}\n\nfunction parsePlan(value: unknown): InspectorPlan | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const code = parseNonBlankString(value.code);\n const label = parseNonBlankString(value.label);\n if (code === undefined || label === undefined) {\n return undefined;\n }\n\n return { code, label };\n}\n\nfunction parseLicense(value: unknown): InspectorLicense | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n switch (value.state) {\n case \"valid\":\n case \"none\":\n case \"expired\":\n case \"unknown\":\n return { state: value.state };\n default:\n return undefined;\n }\n}\n\nfunction parseActionKind(value: unknown): InspectorAction[\"kind\"] | undefined {\n switch (value) {\n case \"manage_plan\":\n case \"renew\":\n case \"enable_intelligence\":\n return value;\n default:\n return undefined;\n }\n}\n\nfunction parseSafeActionUrl(value: unknown): string | undefined {\n const url = parseNonBlankString(value);\n if (url === undefined || url.includes(\"?\") || url.includes(\"#\")) {\n return undefined;\n }\n\n const authorityStart = url.indexOf(\"://\");\n if (authorityStart < 1) {\n return undefined;\n }\n\n const authorityAndPath = url.slice(authorityStart + 3);\n const pathStart = authorityAndPath.indexOf(\"/\");\n const authority =\n pathStart === -1 ? authorityAndPath : authorityAndPath.slice(0, pathStart);\n if (authority.includes(\"@\")) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return undefined;\n }\n\n if (parsed.hostname.length === 0 || parsed.username || parsed.password) {\n return undefined;\n }\n\n if (parsed.protocol === \"https:\") {\n return url;\n }\n\n const isLoopbackHost =\n parsed.hostname === \"localhost\" ||\n parsed.hostname === \"127.0.0.1\" ||\n parsed.hostname === \"[::1]\";\n if (parsed.protocol === \"http:\" && isLoopbackHost) {\n return url;\n }\n\n return undefined;\n}\n\nfunction parseAction(value: unknown): InspectorAction | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const kind = parseActionKind(value.kind);\n const url = parseSafeActionUrl(value.url);\n if (kind === undefined || url === undefined) {\n return undefined;\n }\n\n return { kind, url };\n}\n\nfunction isFiniteNonnegativeInteger(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction parseUsageLimit(value: unknown): InspectorUsageLimit | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n if (value.kind === \"finite\") {\n if (\n typeof value.value !== \"number\" ||\n !Number.isSafeInteger(value.value) ||\n value.value < 1\n ) {\n return undefined;\n }\n\n return { kind: \"finite\", value: value.value };\n }\n\n if (value.kind === \"unlimited\") {\n return { kind: \"unlimited\" };\n }\n\n if (value.kind === \"unknown\") {\n return { kind: \"unknown\" };\n }\n\n return undefined;\n}\n\nfunction parseUsage(value: unknown): InspectorUsage | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n const limit = parseUsageLimit(value.limit);\n const used = value.used;\n if (!isFiniteNonnegativeInteger(used) || limit === undefined) {\n return undefined;\n }\n\n const rawExpiringSoonCount = readOwnDataProperty(value, \"expiringSoonCount\");\n const expiringSoonCount = isFiniteNonnegativeInteger(rawExpiringSoonCount)\n ? rawExpiringSoonCount\n : undefined;\n\n return {\n used,\n limit,\n ...(expiringSoonCount === undefined ? {} : { expiringSoonCount }),\n };\n}\n\n/**\n * Parses untrusted inspector metadata without letting one invalid optional\n * module hide the other valid modules.\n *\n * @param value - The decoded runtime response body.\n * @returns Normalized version 1 metadata, or `undefined` for an unsupported\n * top-level payload.\n */\nexport function parseInspectorMetadataV1(\n value: unknown,\n): InspectorMetadataV1 | undefined {\n if (!isRecord(value) || value.schemaVersion !== 1) {\n return undefined;\n }\n\n const identity = parseIdentity(value.identity);\n const plan = parsePlan(value.plan);\n const license = parseLicense(value.license);\n const action = parseAction(value.action);\n const usage = parseUsage(value.usage);\n\n return {\n schemaVersion: 1,\n ...(identity === undefined ? {} : { identity }),\n ...(plan === undefined ? {} : { plan }),\n ...(license === undefined ? {} : { license }),\n ...(action === undefined ? {} : { action }),\n ...(usage === undefined ? {} : { usage }),\n };\n}\n"],"mappings":"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"} |
| import { expect, test, vi } from "vitest"; | ||
| import { parseInspectorMetadataV1 } from "./inspector-metadata"; | ||
| function metadataWithUsage(usage: unknown): Record<string, unknown> { | ||
| return { | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| usage, | ||
| }; | ||
| } | ||
| function validUsage(limit: unknown = { kind: "finite", value: 100 }) { | ||
| return { | ||
| used: 12, | ||
| limit, | ||
| }; | ||
| } | ||
| function nullPrototypeRecord( | ||
| fields: Record<string, unknown>, | ||
| ): Record<string, unknown> { | ||
| return Object.assign(Object.create(null), fields); | ||
| } | ||
| test("parses complete metadata and strips unknown fields", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: " Acme Inc. ", | ||
| projectName: " Support ", | ||
| organizationId: "org-secret", | ||
| }, | ||
| plan: { | ||
| code: " enterprise ", | ||
| label: " Enterprise ", | ||
| internalPriceId: "price-secret", | ||
| }, | ||
| license: { | ||
| state: "valid", | ||
| expiresAt: "2030-01-01T00:00:00.000Z", | ||
| }, | ||
| action: { | ||
| kind: "manage_plan", | ||
| url: " https://cloud.copilotkit.ai/manage ", | ||
| method: "POST", | ||
| }, | ||
| usage: { | ||
| used: 12, | ||
| limit: { | ||
| kind: "finite", | ||
| value: 100, | ||
| unit: "threads", | ||
| }, | ||
| internalThreadIds: ["thread-secret"], | ||
| }, | ||
| internalOrganizationId: "org-secret", | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme Inc.", | ||
| projectName: "Support", | ||
| }, | ||
| plan: { | ||
| code: "enterprise", | ||
| label: "Enterprise", | ||
| }, | ||
| license: { | ||
| state: "valid", | ||
| }, | ||
| action: { | ||
| kind: "manage_plan", | ||
| url: "https://cloud.copilotkit.ai/manage", | ||
| }, | ||
| usage: { | ||
| used: 12, | ||
| limit: { | ||
| kind: "finite", | ||
| value: 100, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| test("parses identity when it is the only metadata module", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| }); | ||
| }); | ||
| test("parses plan when it is the only metadata module", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| plan: { | ||
| code: "enterprise", | ||
| label: "Enterprise", | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| plan: { | ||
| code: "enterprise", | ||
| label: "Enterprise", | ||
| }, | ||
| }); | ||
| }); | ||
| test("parses license when it is the only metadata module", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| license: { | ||
| state: "expired", | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| license: { | ||
| state: "expired", | ||
| }, | ||
| }); | ||
| }); | ||
| test("parses action when it is the only metadata module", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| action: { | ||
| kind: "renew", | ||
| url: "https://cloud.copilotkit.ai/renew", | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| action: { | ||
| kind: "renew", | ||
| url: "https://cloud.copilotkit.ai/renew", | ||
| }, | ||
| }); | ||
| }); | ||
| test("parses usage when it is the only metadata module", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| usage: validUsage(), | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| usage: validUsage(), | ||
| }); | ||
| }); | ||
| test.each([ | ||
| { | ||
| name: "identity", | ||
| value: { | ||
| schemaVersion: 1, | ||
| identity: { organizationName: " ", projectName: "Support" }, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| }, | ||
| expected: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "plan", | ||
| value: { | ||
| schemaVersion: 1, | ||
| identity: { organizationName: "Acme", projectName: "Support" }, | ||
| plan: { code: "enterprise", label: "" }, | ||
| }, | ||
| expected: { | ||
| schemaVersion: 1, | ||
| identity: { organizationName: "Acme", projectName: "Support" }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "license", | ||
| value: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| license: { state: "revoked" }, | ||
| }, | ||
| expected: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "action", | ||
| value: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| action: { | ||
| kind: "manage_plan", | ||
| url: "http://cloud.copilotkit.ai/manage", | ||
| }, | ||
| }, | ||
| expected: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "usage", | ||
| value: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| usage: validUsage({ kind: "finite", value: 0 }), | ||
| }, | ||
| expected: { | ||
| schemaVersion: 1, | ||
| plan: { code: "developer", label: "Developer" }, | ||
| }, | ||
| }, | ||
| ])( | ||
| "omits an invalid $name module while retaining valid metadata", | ||
| (testCase) => { | ||
| const result = parseInspectorMetadataV1(testCase.value); | ||
| expect(result).toStrictEqual(testCase.expected); | ||
| }, | ||
| ); | ||
| test.each([undefined, null, "metadata", 1, true, [], new Date()])( | ||
| "rejects non-record top-level input: %s", | ||
| (value) => { | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toBeUndefined(); | ||
| }, | ||
| ); | ||
| test("rejects a Date instance with an own schema version", () => { | ||
| const value = Object.assign(new Date(), { schemaVersion: 1 }); | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
| test("rejects a class instance with metadata fields", () => { | ||
| class MetadataEnvelope { | ||
| readonly schemaVersion = 1; | ||
| readonly identity = { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }; | ||
| } | ||
| const value = new MetadataEnvelope(); | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
| test("rejects a top-level object with an inherited schema version", () => { | ||
| const value = Object.create({ | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| }); | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
| test("omits a module whose fields come from its prototype", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| identity: Object.create({ | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }), | ||
| plan: { | ||
| code: "developer", | ||
| label: "Developer", | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| plan: { | ||
| code: "developer", | ||
| label: "Developer", | ||
| }, | ||
| }); | ||
| }); | ||
| test("accepts null-prototype metadata records", () => { | ||
| const identity = nullPrototypeRecord({ | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }); | ||
| const value = nullPrototypeRecord({ | ||
| schemaVersion: 1, | ||
| identity, | ||
| }); | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| }); | ||
| }); | ||
| test("rejects a proxy that throws while its prototype is inspected", () => { | ||
| const value = new Proxy( | ||
| {}, | ||
| { | ||
| getPrototypeOf() { | ||
| throw new Error("prototype unavailable"); | ||
| }, | ||
| }, | ||
| ); | ||
| const parse = () => parseInspectorMetadataV1(value); | ||
| expect(parse).not.toThrow(); | ||
| expect(parse()).toBeUndefined(); | ||
| }); | ||
| test.each([undefined, null, 0, 2, "1", true])( | ||
| "rejects an unknown or missing schema version: %s", | ||
| (schemaVersion) => { | ||
| const result = parseInspectorMetadataV1({ schemaVersion }); | ||
| expect(result).toBeUndefined(); | ||
| }, | ||
| ); | ||
| test.each([ | ||
| "https://cloud.copilotkit.ai/manage", | ||
| "https://cloud.copilotkit.ai/manage/plan", | ||
| "http://localhost/manage", | ||
| "http://localhost:3000/manage", | ||
| "http://127.0.0.1:3000/manage", | ||
| "http://[::1]:3000/manage", | ||
| ])("accepts a safe action URL: %s", (url) => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| action: { | ||
| kind: "enable_intelligence", | ||
| url, | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.action).toStrictEqual({ | ||
| kind: "enable_intelligence", | ||
| url, | ||
| }); | ||
| }); | ||
| test.each([ | ||
| "", | ||
| " ", | ||
| "/manage", | ||
| "mailto:billing@copilotkit.ai", | ||
| "ftp://cloud.copilotkit.ai/manage", | ||
| "http://cloud.copilotkit.ai/manage", | ||
| "http://localhost.example.com/manage", | ||
| "http://sub.localhost/manage", | ||
| "http://127.0.0.2/manage", | ||
| "http://[::2]/manage", | ||
| "http://0.0.0.0/manage", | ||
| "https://@cloud.copilotkit.ai/manage", | ||
| "https://user@cloud.copilotkit.ai/manage", | ||
| "https://user:password@cloud.copilotkit.ai/manage", | ||
| "https://cloud.copilotkit.ai/manage?source=inspector", | ||
| "https://cloud.copilotkit.ai/manage?", | ||
| "https://cloud.copilotkit.ai/manage#billing", | ||
| "https://cloud.copilotkit.ai/manage#", | ||
| ])("rejects an unsafe action URL: %s", (url) => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| plan: { | ||
| code: "developer", | ||
| label: "Developer", | ||
| }, | ||
| action: { | ||
| kind: "renew", | ||
| url, | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| plan: { | ||
| code: "developer", | ||
| label: "Developer", | ||
| }, | ||
| }); | ||
| }); | ||
| test.each([ | ||
| { kind: "finite", value: 100 }, | ||
| { kind: "unlimited" }, | ||
| { kind: "unknown" }, | ||
| ])("parses the $kind usage limit", (limit) => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| usage: validUsage(limit), | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.usage?.limit).toStrictEqual(limit); | ||
| }); | ||
| test.each([ | ||
| { | ||
| name: "finite absent", | ||
| limit: { kind: "finite", value: 200 }, | ||
| expiringSoonCount: undefined, | ||
| }, | ||
| { | ||
| name: "finite zero", | ||
| limit: { kind: "finite", value: 200 }, | ||
| expiringSoonCount: 0, | ||
| }, | ||
| { | ||
| name: "finite positive", | ||
| limit: { kind: "finite", value: 200 }, | ||
| expiringSoonCount: 37, | ||
| }, | ||
| { | ||
| name: "unlimited absent", | ||
| limit: { kind: "unlimited" }, | ||
| expiringSoonCount: undefined, | ||
| }, | ||
| { | ||
| name: "unlimited zero", | ||
| limit: { kind: "unlimited" }, | ||
| expiringSoonCount: 0, | ||
| }, | ||
| { | ||
| name: "unlimited positive", | ||
| limit: { kind: "unlimited" }, | ||
| expiringSoonCount: 37, | ||
| }, | ||
| { | ||
| name: "unknown absent", | ||
| limit: { kind: "unknown" }, | ||
| expiringSoonCount: undefined, | ||
| }, | ||
| { | ||
| name: "unknown zero", | ||
| limit: { kind: "unknown" }, | ||
| expiringSoonCount: 0, | ||
| }, | ||
| { | ||
| name: "unknown positive", | ||
| limit: { kind: "unknown" }, | ||
| expiringSoonCount: 37, | ||
| }, | ||
| ])("parses $name expiring-soon usage", ({ limit, expiringSoonCount }) => { | ||
| const expiry = expiringSoonCount === undefined ? {} : { expiringSoonCount }; | ||
| const value = { | ||
| schemaVersion: 1, | ||
| usage: { used: 148, limit, ...expiry }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| usage: { used: 148, limit, ...expiry }, | ||
| }); | ||
| expect( | ||
| Object.prototype.hasOwnProperty.call( | ||
| result?.usage ?? {}, | ||
| "expiringSoonCount", | ||
| ), | ||
| ).toBe(expiringSoonCount !== undefined); | ||
| }); | ||
| test("parses the maximum safe expiring-soon count", () => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| usage: { | ||
| used: 148, | ||
| limit: { kind: "finite", value: 200 }, | ||
| expiringSoonCount: Number.MAX_SAFE_INTEGER, | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.usage).toStrictEqual({ | ||
| used: 148, | ||
| limit: { kind: "finite", value: 200 }, | ||
| expiringSoonCount: Number.MAX_SAFE_INTEGER, | ||
| }); | ||
| }); | ||
| test.each([ | ||
| { name: "negative", expiringSoonCount: -1 }, | ||
| { name: "fractional", expiringSoonCount: 1.5 }, | ||
| { | ||
| name: "unsafe", | ||
| expiringSoonCount: Number.MAX_SAFE_INTEGER + 1, | ||
| }, | ||
| { name: "string", expiringSoonCount: "37" }, | ||
| { name: "NaN", expiringSoonCount: Number.NaN }, | ||
| { name: "infinite", expiringSoonCount: Number.POSITIVE_INFINITY }, | ||
| ])( | ||
| "drops a $name expiring-soon leaf without dropping usage", | ||
| ({ expiringSoonCount }) => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| usage: { | ||
| used: 148, | ||
| limit: { kind: "finite", value: 200 }, | ||
| expiringSoonCount, | ||
| }, | ||
| plan: { code: "free", label: "Free" }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| usage: { | ||
| used: 148, | ||
| limit: { kind: "finite", value: 200 }, | ||
| }, | ||
| plan: { code: "free", label: "Free" }, | ||
| }); | ||
| }, | ||
| ); | ||
| test("ignores an inherited expiring-soon count", () => { | ||
| const prototype = { expiringSoonCount: 37 }; | ||
| const target = Object.assign( | ||
| Object.create(prototype), | ||
| validUsage({ kind: "finite", value: 200 }), | ||
| ); | ||
| const usage = new Proxy(target, { | ||
| getPrototypeOf() { | ||
| return Object.prototype; | ||
| }, | ||
| }); | ||
| const value = { schemaVersion: 1, usage }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.usage).toStrictEqual( | ||
| validUsage({ kind: "finite", value: 200 }), | ||
| ); | ||
| }); | ||
| test("does not invoke an expiring-soon getter", () => { | ||
| const readExpiringSoonCount = vi.fn(() => 37); | ||
| const usage = validUsage({ kind: "finite", value: 200 }); | ||
| Object.defineProperty(usage, "expiringSoonCount", { | ||
| enumerable: true, | ||
| get: readExpiringSoonCount, | ||
| }); | ||
| const value = { schemaVersion: 1, usage }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.usage).toStrictEqual( | ||
| validUsage({ kind: "finite", value: 200 }), | ||
| ); | ||
| expect(readExpiringSoonCount).not.toHaveBeenCalled(); | ||
| }); | ||
| test("keeps usage when the expiring-soon descriptor cannot be read", () => { | ||
| const usage = new Proxy(validUsage({ kind: "finite", value: 200 }), { | ||
| getOwnPropertyDescriptor(target, property) { | ||
| if (property === "expiringSoonCount") { | ||
| throw new Error("descriptor unavailable"); | ||
| } | ||
| return Reflect.getOwnPropertyDescriptor(target, property); | ||
| }, | ||
| }); | ||
| const value = { schemaVersion: 1, usage }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.usage).toStrictEqual( | ||
| validUsage({ kind: "finite", value: 200 }), | ||
| ); | ||
| }); | ||
| test("returns validated usage when expiry descriptor work mutates input", () => { | ||
| const usage = new Proxy(validUsage({ kind: "finite", value: 200 }), { | ||
| getOwnPropertyDescriptor(target, property) { | ||
| if (property === "expiringSoonCount") { | ||
| target.used = -1; | ||
| throw new Error("descriptor unavailable"); | ||
| } | ||
| return Reflect.getOwnPropertyDescriptor(target, property); | ||
| }, | ||
| }); | ||
| const value = { schemaVersion: 1, usage }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result?.usage).toStrictEqual( | ||
| validUsage({ kind: "finite", value: 200 }), | ||
| ); | ||
| }); | ||
| test.each([ | ||
| -1, | ||
| 0.5, | ||
| Number.NaN, | ||
| Number.POSITIVE_INFINITY, | ||
| Number.MAX_SAFE_INTEGER + 1, | ||
| "12", | ||
| null, | ||
| ])("omits usage when used is not a finite nonnegative integer: %s", (used) => { | ||
| const value = metadataWithUsage({ | ||
| ...validUsage(), | ||
| used, | ||
| }); | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| }); | ||
| }); | ||
| test.each([ | ||
| 0, | ||
| -1, | ||
| 1.5, | ||
| Number.NaN, | ||
| Number.POSITIVE_INFINITY, | ||
| Number.MAX_SAFE_INTEGER + 1, | ||
| "100", | ||
| null, | ||
| ])("omits usage when a finite limit value is invalid: %s", (limitValue) => { | ||
| const value = metadataWithUsage( | ||
| validUsage({ | ||
| kind: "finite", | ||
| value: limitValue, | ||
| }), | ||
| ); | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ | ||
| schemaVersion: 1, | ||
| identity: { | ||
| organizationName: "Acme", | ||
| projectName: "Support", | ||
| }, | ||
| }); | ||
| }); | ||
| test.each([ | ||
| { kind: "finite" }, | ||
| { kind: "unlimited", value: 100 }, | ||
| { kind: "unknown", reason: "hidden" }, | ||
| { kind: "metered" }, | ||
| ])("normalizes or rejects the usage limit shape: $kind", (limit) => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| usage: validUsage(limit), | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| if (limit.kind === "finite" || limit.kind === "metered") { | ||
| expect(result).toStrictEqual({ schemaVersion: 1 }); | ||
| return; | ||
| } | ||
| expect(result?.usage?.limit).toStrictEqual({ kind: limit.kind }); | ||
| }); | ||
| test.each(["", " ", "manage-plan", null, 1])( | ||
| "omits an action with an unsupported kind: %s", | ||
| (kind) => { | ||
| const value = { | ||
| schemaVersion: 1, | ||
| action: { | ||
| kind, | ||
| url: "https://cloud.copilotkit.ai/manage", | ||
| }, | ||
| }; | ||
| const result = parseInspectorMetadataV1(value); | ||
| expect(result).toStrictEqual({ schemaVersion: 1 }); | ||
| }, | ||
| ); |
| /** | ||
| * Inspector metadata supplied by a trusted CopilotKit runtime. | ||
| * | ||
| * Each optional module is independent so clients can render partial metadata | ||
| * from runtimes that do not expose every module. | ||
| */ | ||
| export interface InspectorMetadataV1 { | ||
| readonly schemaVersion: 1; | ||
| readonly identity?: { | ||
| readonly organizationName: string; | ||
| readonly projectName: string; | ||
| }; | ||
| readonly plan?: { | ||
| readonly code: string; | ||
| readonly label: string; | ||
| }; | ||
| readonly license?: { | ||
| readonly state: "valid" | "none" | "expired" | "unknown"; | ||
| }; | ||
| readonly action?: | ||
| | { readonly kind: "manage_plan"; readonly url: string } | ||
| | { readonly kind: "renew"; readonly url: string } | ||
| | { readonly kind: "enable_intelligence"; readonly url: string }; | ||
| readonly usage?: { | ||
| readonly used: number; | ||
| readonly limit: | ||
| | { readonly kind: "finite"; readonly value: number } | ||
| | { readonly kind: "unlimited" } | ||
| | { readonly kind: "unknown" }; | ||
| readonly expiringSoonCount?: number; | ||
| }; | ||
| } | ||
| type UnknownRecord = Record<string, unknown>; | ||
| type InspectorIdentity = NonNullable<InspectorMetadataV1["identity"]>; | ||
| type InspectorPlan = NonNullable<InspectorMetadataV1["plan"]>; | ||
| type InspectorLicense = NonNullable<InspectorMetadataV1["license"]>; | ||
| type InspectorAction = NonNullable<InspectorMetadataV1["action"]>; | ||
| type InspectorUsage = NonNullable<InspectorMetadataV1["usage"]>; | ||
| type InspectorUsageLimit = InspectorUsage["limit"]; | ||
| function isRecord(value: unknown): value is UnknownRecord { | ||
| if (typeof value !== "object" || value === null || Array.isArray(value)) { | ||
| return false; | ||
| } | ||
| try { | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return prototype === Object.prototype || prototype === null; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function readOwnDataProperty(value: UnknownRecord, key: string): unknown { | ||
| try { | ||
| const descriptor = Object.getOwnPropertyDescriptor(value, key); | ||
| return descriptor !== undefined && "value" in descriptor | ||
| ? descriptor.value | ||
| : undefined; | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
| function parseNonBlankString(value: unknown): string | undefined { | ||
| if (typeof value !== "string") { | ||
| return undefined; | ||
| } | ||
| const parsed = value.trim(); | ||
| return parsed.length > 0 ? parsed : undefined; | ||
| } | ||
| function parseIdentity(value: unknown): InspectorIdentity | undefined { | ||
| if (!isRecord(value)) { | ||
| return undefined; | ||
| } | ||
| const organizationName = parseNonBlankString(value.organizationName); | ||
| const projectName = parseNonBlankString(value.projectName); | ||
| if (organizationName === undefined || projectName === undefined) { | ||
| return undefined; | ||
| } | ||
| return { organizationName, projectName }; | ||
| } | ||
| function parsePlan(value: unknown): InspectorPlan | undefined { | ||
| if (!isRecord(value)) { | ||
| return undefined; | ||
| } | ||
| const code = parseNonBlankString(value.code); | ||
| const label = parseNonBlankString(value.label); | ||
| if (code === undefined || label === undefined) { | ||
| return undefined; | ||
| } | ||
| return { code, label }; | ||
| } | ||
| function parseLicense(value: unknown): InspectorLicense | undefined { | ||
| if (!isRecord(value)) { | ||
| return undefined; | ||
| } | ||
| switch (value.state) { | ||
| case "valid": | ||
| case "none": | ||
| case "expired": | ||
| case "unknown": | ||
| return { state: value.state }; | ||
| default: | ||
| return undefined; | ||
| } | ||
| } | ||
| function parseActionKind(value: unknown): InspectorAction["kind"] | undefined { | ||
| switch (value) { | ||
| case "manage_plan": | ||
| case "renew": | ||
| case "enable_intelligence": | ||
| return value; | ||
| default: | ||
| return undefined; | ||
| } | ||
| } | ||
| function parseSafeActionUrl(value: unknown): string | undefined { | ||
| const url = parseNonBlankString(value); | ||
| if (url === undefined || url.includes("?") || url.includes("#")) { | ||
| return undefined; | ||
| } | ||
| const authorityStart = url.indexOf("://"); | ||
| if (authorityStart < 1) { | ||
| return undefined; | ||
| } | ||
| const authorityAndPath = url.slice(authorityStart + 3); | ||
| const pathStart = authorityAndPath.indexOf("/"); | ||
| const authority = | ||
| pathStart === -1 ? authorityAndPath : authorityAndPath.slice(0, pathStart); | ||
| if (authority.includes("@")) { | ||
| return undefined; | ||
| } | ||
| let parsed: URL; | ||
| try { | ||
| parsed = new URL(url); | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| if (parsed.hostname.length === 0 || parsed.username || parsed.password) { | ||
| return undefined; | ||
| } | ||
| if (parsed.protocol === "https:") { | ||
| return url; | ||
| } | ||
| const isLoopbackHost = | ||
| parsed.hostname === "localhost" || | ||
| parsed.hostname === "127.0.0.1" || | ||
| parsed.hostname === "[::1]"; | ||
| if (parsed.protocol === "http:" && isLoopbackHost) { | ||
| return url; | ||
| } | ||
| return undefined; | ||
| } | ||
| function parseAction(value: unknown): InspectorAction | undefined { | ||
| if (!isRecord(value)) { | ||
| return undefined; | ||
| } | ||
| const kind = parseActionKind(value.kind); | ||
| const url = parseSafeActionUrl(value.url); | ||
| if (kind === undefined || url === undefined) { | ||
| return undefined; | ||
| } | ||
| return { kind, url }; | ||
| } | ||
| function isFiniteNonnegativeInteger(value: unknown): value is number { | ||
| return typeof value === "number" && Number.isSafeInteger(value) && value >= 0; | ||
| } | ||
| function parseUsageLimit(value: unknown): InspectorUsageLimit | undefined { | ||
| if (!isRecord(value)) { | ||
| return undefined; | ||
| } | ||
| if (value.kind === "finite") { | ||
| if ( | ||
| typeof value.value !== "number" || | ||
| !Number.isSafeInteger(value.value) || | ||
| value.value < 1 | ||
| ) { | ||
| return undefined; | ||
| } | ||
| return { kind: "finite", value: value.value }; | ||
| } | ||
| if (value.kind === "unlimited") { | ||
| return { kind: "unlimited" }; | ||
| } | ||
| if (value.kind === "unknown") { | ||
| return { kind: "unknown" }; | ||
| } | ||
| return undefined; | ||
| } | ||
| function parseUsage(value: unknown): InspectorUsage | undefined { | ||
| if (!isRecord(value)) { | ||
| return undefined; | ||
| } | ||
| const limit = parseUsageLimit(value.limit); | ||
| const used = value.used; | ||
| if (!isFiniteNonnegativeInteger(used) || limit === undefined) { | ||
| return undefined; | ||
| } | ||
| const rawExpiringSoonCount = readOwnDataProperty(value, "expiringSoonCount"); | ||
| const expiringSoonCount = isFiniteNonnegativeInteger(rawExpiringSoonCount) | ||
| ? rawExpiringSoonCount | ||
| : undefined; | ||
| return { | ||
| used, | ||
| limit, | ||
| ...(expiringSoonCount === undefined ? {} : { expiringSoonCount }), | ||
| }; | ||
| } | ||
| /** | ||
| * Parses untrusted inspector metadata without letting one invalid optional | ||
| * module hide the other valid modules. | ||
| * | ||
| * @param value - The decoded runtime response body. | ||
| * @returns Normalized version 1 metadata, or `undefined` for an unsupported | ||
| * top-level payload. | ||
| */ | ||
| export function parseInspectorMetadataV1( | ||
| value: unknown, | ||
| ): InspectorMetadataV1 | undefined { | ||
| if (!isRecord(value) || value.schemaVersion !== 1) { | ||
| return undefined; | ||
| } | ||
| const identity = parseIdentity(value.identity); | ||
| const plan = parsePlan(value.plan); | ||
| const license = parseLicense(value.license); | ||
| const action = parseAction(value.action); | ||
| const usage = parseUsage(value.usage); | ||
| return { | ||
| schemaVersion: 1, | ||
| ...(identity === undefined ? {} : { identity }), | ||
| ...(plan === undefined ? {} : { plan }), | ||
| ...(license === undefined ? {} : { license }), | ||
| ...(action === undefined ? {} : { action }), | ||
| ...(usage === undefined ? {} : { usage }), | ||
| }; | ||
| } |
+2
-0
@@ -7,2 +7,3 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
| const require_json_schema = require('./utils/json-schema.cjs'); | ||
| const require_inspector_metadata = require('./utils/inspector-metadata.cjs'); | ||
| const require_types = require('./utils/types.cjs'); | ||
@@ -112,2 +113,3 @@ const require_random_id = require('./utils/random-id.cjs'); | ||
| exports.parseAndWarnTelemetryId = require_lambda_client.parseAndWarnTelemetryId; | ||
| exports.parseInspectorMetadataV1 = require_inspector_metadata.parseInspectorMetadataV1; | ||
| exports.parseJson = require_index.parseJson; | ||
@@ -114,0 +116,0 @@ exports.parseTelemetryIdFromLicense = require_lambda_client.parseTelemetryIdFromLicense; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\nexport * from \"./debug\";\nexport * from \"./standard-schema\";\nexport * from \"./attachments\";\n\nexport { logger } from \"./logger\";\nexport { finalizeRunEvents } from \"./finalize-events\";\n\nexport {\n TranscriptionErrorCode,\n TranscriptionErrors,\n type TranscriptionErrorResponse,\n} from \"./transcription-errors\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n\n// Re-export only types from license-verifier (types are erased at compile time,\n// so they don't pull in the Node-only `crypto` dependency into client bundles).\n// Server-side packages (e.g. @copilotkit/runtime) should import runtime functions\n// like createLicenseChecker and getLicenseWarningHeader directly from\n// @copilotkit/license-verifier.\nexport type {\n LicenseChecker,\n LicenseStatus,\n LicensePayload,\n LicenseFeatures,\n LicenseTier,\n LicenseOwner,\n} from \"@copilotkit/license-verifier\";\n\nimport type { LicensePayload } from \"@copilotkit/license-verifier\";\nimport type { RuntimeLicenseStatus } from \"./utils/types\";\n\n// LicenseContextValue was dropped from license-verifier's public API in\n// 0.3.0, so it is defined here. The context shape is owned by this package\n// anyway via createLicenseContextValue below.\n\n/**\n * License context value exposed to child components.\n * Frontend providers create their own context using this shape.\n */\nexport interface LicenseContextValue {\n /** Server-reported license status from the runtime's /info endpoint. Null until known. */\n status: RuntimeLicenseStatus | null;\n /** The license payload if available. Always null on the client; the payload stays server-side. */\n license: LicensePayload | null;\n /** Whether a specific feature is licensed. Returns true if no licensing is active (no token). */\n checkFeature: (feature: string) => boolean;\n /** Get a numeric feature limit. Returns null if not applicable. */\n getLimit: (feature: string) => number | null;\n}\n\n/**\n * Client-safe license context factory, driven by the license status the\n * runtime reports via /info.\n *\n * Features are enabled unless the runtime definitively reports the license\n * as \"expired\" or \"invalid\". A null/\"none\"/\"unknown\" status fails open\n * (unlicensed = unrestricted, with branding), and \"expiring\" keeps features\n * on while the provider surfaces a warning banner. Per-feature data is not\n * in /info yet, so checkFeature is uniform across features and getLimit has\n * no limits to report. This is inlined here to avoid importing the full\n * license-verifier bundle (which depends on Node's `crypto`) into browser\n * bundles.\n */\nexport function createLicenseContextValue(\n status: RuntimeLicenseStatus | null | undefined,\n): LicenseContextValue {\n const resolvedStatus = status ?? null;\n const featuresEnabled =\n resolvedStatus !== \"expired\" && resolvedStatus !== \"invalid\";\n return {\n status: resolvedStatus,\n license: null,\n checkFeature: () => featuresEnabled,\n getLimit: () => null,\n };\n}\n\nexport {\n A2UI_DEFAULT_GENERATION_GUIDELINES,\n A2UI_DEFAULT_DESIGN_GUIDELINES,\n} from \"./a2ui-prompts\";\n\nexport type { DebugEventEnvelope } from \"./debug-event-envelope\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa;;;;;;;;;;;;;;AAmDb,SAAgB,0BACd,QACqB;CACrB,MAAM,iBAAiB,UAAU;CACjC,MAAM,kBACJ,mBAAmB,aAAa,mBAAmB;AACrD,QAAO;EACL,QAAQ;EACR,SAAS;EACT,oBAAoB;EACpB,gBAAgB;EACjB"} | ||
| {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\nexport * from \"./debug\";\nexport * from \"./standard-schema\";\nexport * from \"./attachments\";\n\nexport { logger } from \"./logger\";\nexport { finalizeRunEvents } from \"./finalize-events\";\n\nexport {\n TranscriptionErrorCode,\n TranscriptionErrors,\n type TranscriptionErrorResponse,\n} from \"./transcription-errors\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n\n// Re-export only types from license-verifier (types are erased at compile time,\n// so they don't pull in the Node-only `crypto` dependency into client bundles).\n// Server-side packages (e.g. @copilotkit/runtime) should import runtime functions\n// like createLicenseChecker and getLicenseWarningHeader directly from\n// @copilotkit/license-verifier.\nexport type {\n LicenseChecker,\n LicenseStatus,\n LicensePayload,\n LicenseFeatures,\n LicenseTier,\n LicenseOwner,\n} from \"@copilotkit/license-verifier\";\n\nimport type { LicensePayload } from \"@copilotkit/license-verifier\";\nimport type { RuntimeLicenseStatus } from \"./utils/types\";\n\n// LicenseContextValue was dropped from license-verifier's public API in\n// 0.3.0, so it is defined here. The context shape is owned by this package\n// anyway via createLicenseContextValue below.\n\n/**\n * License context value exposed to child components.\n * Frontend providers create their own context using this shape.\n */\nexport interface LicenseContextValue {\n /** Server-reported license status from the runtime's /info endpoint. Null until known. */\n status: RuntimeLicenseStatus | null;\n /** The license payload if available. Always null on the client; the payload stays server-side. */\n license: LicensePayload | null;\n /** Whether a specific feature is licensed. Returns true if no licensing is active (no token). */\n checkFeature: (feature: string) => boolean;\n /** Get a numeric feature limit. Returns null if not applicable. */\n getLimit: (feature: string) => number | null;\n}\n\n/**\n * Client-safe license context factory, driven by the license status the\n * runtime reports via /info.\n *\n * Features are enabled unless the runtime definitively reports the license\n * as \"expired\" or \"invalid\". A null/\"none\"/\"unknown\" status fails open\n * (unlicensed = unrestricted, with branding), and \"expiring\" keeps features\n * on while the provider surfaces a warning banner. Per-feature data is not\n * in /info yet, so checkFeature is uniform across features and getLimit has\n * no limits to report. This is inlined here to avoid importing the full\n * license-verifier bundle (which depends on Node's `crypto`) into browser\n * bundles.\n */\nexport function createLicenseContextValue(\n status: RuntimeLicenseStatus | null | undefined,\n): LicenseContextValue {\n const resolvedStatus = status ?? null;\n const featuresEnabled =\n resolvedStatus !== \"expired\" && resolvedStatus !== \"invalid\";\n return {\n status: resolvedStatus,\n license: null,\n checkFeature: () => featuresEnabled,\n getLimit: () => null,\n };\n}\n\nexport {\n A2UI_DEFAULT_GENERATION_GUIDELINES,\n A2UI_DEFAULT_DESIGN_GUIDELINES,\n} from \"./a2ui-prompts\";\n\nexport type { DebugEventEnvelope } from \"./debug-event-envelope\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa;;;;;;;;;;;;;;AAmDb,SAAgB,0BACd,QACqB;CACrB,MAAM,iBAAiB,UAAU;CACjC,MAAM,kBACJ,mBAAmB,aAAa,mBAAmB;AACrD,QAAO;EACL,QAAQ;EACR,SAAS;EACT,oBAAoB;EACpB,gBAAgB;EACjB"} |
+2
-1
@@ -12,2 +12,3 @@ import { AssistantMessage, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, JSONValue, ToolDefinition } from "./types/openai-assistant.cjs"; | ||
| import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./utils/json-schema.cjs"; | ||
| import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./utils/inspector-metadata.cjs"; | ||
| import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, ThreadEndpointRuntimeInfo } from "./utils/types.cjs"; | ||
@@ -62,3 +63,3 @@ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./utils/random-id.cjs"; | ||
| //#endregion | ||
| export { A2UIRuntimeInfo, A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, AG_UI_CHANNEL_EVENT, AIMessage, Action, ActivityMessage, AgentDescription, AssistantMessage, Attachment, AttachmentModality, AttachmentUploadError, AttachmentUploadErrorReason, AttachmentUploadResult, AttachmentsConfig, AudioInputPart, BANNER_ERROR_NAMES, BaseCondition, COPILOTKIT_VERSION, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_ERROR_NAMES, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, ComparisonCondition, ComparisonRule, Condition, ConfigurationError, ConsoleColors, ConsoleStyles, CopilotCloudConfig, CopilotErrorEvent, CopilotErrorHandler, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, CopilotRequestContext, DEFAULT_AGENT_ID, DebugConfig, type DebugEventEnvelope, DeveloperMessage, DocumentInputPart, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, ExistenceCondition, ExistenceRule, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, ImageData, ImageInputPart, InferSchemaOutput, InputContent, InputContentDataSource, InputContentSource, InputContentUrlSource, IntelligenceRuntimeInfo, JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, JSONValue, LambdaSendOptions, type LicenseChecker, LicenseContextValue, type LicenseFeatures, type LicenseOwner, type LicensePayload, type LicenseStatus, type LicenseTier, LogicalCondition, LogicalRule, MappedParameterTypes, MaybePromise, Message, MissingPublicApiKeyError, NonEmptyRecord, Parameter, PartialBy, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ReasoningMessage, RequiredBy, ResolvedCopilotKitError, ResolvedDebugConfig, Role, Rule, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SchemaToJsonSchemaOptions, Severity, StandardJSONSchemaV1, StandardSchemaV1, SystemMessage, TelemetryClient, TextInputPart, ThreadEndpointRuntimeInfo, ToolCall, ToolDefinition, ToolResult, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, UpgradeRequiredError, UserMessage, VideoInputPart, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, copyToClipboard, createLicenseContextValue, dataToUUID, ensureStructuredError, exceedsMaxSize, executeConditions, finalizeRunEvents, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getPossibleVersionMismatch, getSourceUrl, getZodParameters, isMacOS, isStructuredCopilotKitError, isTelemetryDisabled, isValidUUID, jsonSchemaToActionParameters, lambdaClient, logCopilotKitPlatformMessage, logStyled, logger, matchesAcceptFilter, parseAndWarnTelemetryId, parseJson, parseTelemetryIdFromLicense, partialJSONParse, phoenixExponentialBackoff, publicApiKeyRequired, randomId, randomUUID, readBody, readFileAsBase64, resolveDebugConfig, safeParseToolArgs, schemaToJsonSchema, styledConsole, tryMap }; | ||
| export { A2UIRuntimeInfo, A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, AG_UI_CHANNEL_EVENT, AIMessage, Action, ActivityMessage, AgentDescription, AssistantMessage, Attachment, AttachmentModality, AttachmentUploadError, AttachmentUploadErrorReason, AttachmentUploadResult, AttachmentsConfig, AudioInputPart, BANNER_ERROR_NAMES, BaseCondition, COPILOTKIT_VERSION, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_ERROR_NAMES, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, ComparisonCondition, ComparisonRule, Condition, ConfigurationError, ConsoleColors, ConsoleStyles, CopilotCloudConfig, CopilotErrorEvent, CopilotErrorHandler, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, CopilotRequestContext, DEFAULT_AGENT_ID, DebugConfig, type DebugEventEnvelope, DeveloperMessage, DocumentInputPart, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, ExistenceCondition, ExistenceRule, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, ImageData, ImageInputPart, InferSchemaOutput, InputContent, InputContentDataSource, InputContentSource, InputContentUrlSource, InspectorMetadataV1, IntelligenceRuntimeInfo, JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, JSONValue, LambdaSendOptions, type LicenseChecker, LicenseContextValue, type LicenseFeatures, type LicenseOwner, type LicensePayload, type LicenseStatus, type LicenseTier, LogicalCondition, LogicalRule, MappedParameterTypes, MaybePromise, Message, MissingPublicApiKeyError, NonEmptyRecord, Parameter, PartialBy, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ReasoningMessage, RequiredBy, ResolvedCopilotKitError, ResolvedDebugConfig, Role, Rule, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SchemaToJsonSchemaOptions, Severity, StandardJSONSchemaV1, StandardSchemaV1, SystemMessage, TelemetryClient, TextInputPart, ThreadEndpointRuntimeInfo, ToolCall, ToolDefinition, ToolResult, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, UpgradeRequiredError, UserMessage, VideoInputPart, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, copyToClipboard, createLicenseContextValue, dataToUUID, ensureStructuredError, exceedsMaxSize, executeConditions, finalizeRunEvents, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getPossibleVersionMismatch, getSourceUrl, getZodParameters, isMacOS, isStructuredCopilotKitError, isTelemetryDisabled, isValidUUID, jsonSchemaToActionParameters, lambdaClient, logCopilotKitPlatformMessage, logStyled, logger, matchesAcceptFilter, parseAndWarnTelemetryId, parseInspectorMetadataV1, parseJson, parseTelemetryIdFromLicense, partialJSONParse, phoenixExponentialBackoff, publicApiKeyRequired, randomId, randomUUID, readBody, readFileAsBase64, resolveDebugConfig, safeParseToolArgs, schemaToJsonSchema, styledConsole, tryMap }; | ||
| //# sourceMappingURL=index.d.cts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkBa,kBAAA;;;;;UA2BI,mBAAA;;EAEf,MAAA,EAAQ,oBAAA;;EAER,OAAA,EAAS,gBAAA;;EAET,YAAA,GAAe,OAAA;;EAEf,QAAA,GAAW,OAAA;AAAA;;;AAnCb;;;;;AA2BA;;;;;;iBAwBgB,yBAAA,CACd,MAAA,EAAQ,oBAAA,sBACP,mBAAA"} | ||
| {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkBa,kBAAA;;;;;UA2BI,mBAAA;;EAEf,MAAA,EAAQ,oBAAA;;EAER,OAAA,EAAS,gBAAA;;EAET,YAAA,GAAe,OAAA;;EAEf,QAAA,GAAW,OAAA;AAAA;;;;AAnCb;;;;;AA2BA;;;;;iBAwBgB,yBAAA,CACd,MAAA,EAAQ,oBAAA,sBACP,mBAAA"} |
+2
-1
@@ -12,2 +12,3 @@ import { AssistantMessage, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, JSONValue, ToolDefinition } from "./types/openai-assistant.mjs"; | ||
| import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./utils/json-schema.mjs"; | ||
| import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./utils/inspector-metadata.mjs"; | ||
| import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, ThreadEndpointRuntimeInfo } from "./utils/types.mjs"; | ||
@@ -63,3 +64,3 @@ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./utils/random-id.mjs"; | ||
| //#endregion | ||
| export { A2UIRuntimeInfo, A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, AG_UI_CHANNEL_EVENT, AIMessage, Action, ActivityMessage, AgentDescription, AssistantMessage, Attachment, AttachmentModality, AttachmentUploadError, AttachmentUploadErrorReason, AttachmentUploadResult, AttachmentsConfig, AudioInputPart, BANNER_ERROR_NAMES, BaseCondition, COPILOTKIT_VERSION, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_ERROR_NAMES, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, ComparisonCondition, ComparisonRule, Condition, ConfigurationError, ConsoleColors, ConsoleStyles, CopilotCloudConfig, CopilotErrorEvent, CopilotErrorHandler, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, CopilotRequestContext, DEFAULT_AGENT_ID, DebugConfig, type DebugEventEnvelope, DeveloperMessage, DocumentInputPart, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, ExistenceCondition, ExistenceRule, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, ImageData, ImageInputPart, InferSchemaOutput, InputContent, InputContentDataSource, InputContentSource, InputContentUrlSource, IntelligenceRuntimeInfo, JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, JSONValue, LambdaSendOptions, type LicenseChecker, LicenseContextValue, type LicenseFeatures, type LicenseOwner, type LicensePayload, type LicenseStatus, type LicenseTier, LogicalCondition, LogicalRule, MappedParameterTypes, MaybePromise, Message, MissingPublicApiKeyError, NonEmptyRecord, Parameter, PartialBy, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ReasoningMessage, RequiredBy, ResolvedCopilotKitError, ResolvedDebugConfig, Role, Rule, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SchemaToJsonSchemaOptions, Severity, StandardJSONSchemaV1, StandardSchemaV1, SystemMessage, TelemetryClient, TextInputPart, ThreadEndpointRuntimeInfo, ToolCall, ToolDefinition, ToolResult, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, UpgradeRequiredError, UserMessage, VideoInputPart, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, copyToClipboard, createLicenseContextValue, dataToUUID, ensureStructuredError, exceedsMaxSize, executeConditions, finalizeRunEvents, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getPossibleVersionMismatch, getSourceUrl, getZodParameters, isMacOS, isStructuredCopilotKitError, isTelemetryDisabled, isValidUUID, jsonSchemaToActionParameters, lambdaClient, logCopilotKitPlatformMessage, logStyled, logger, matchesAcceptFilter, parseAndWarnTelemetryId, parseJson, parseTelemetryIdFromLicense, partialJSONParse, phoenixExponentialBackoff, publicApiKeyRequired, randomId, randomUUID, readBody, readFileAsBase64, resolveDebugConfig, safeParseToolArgs, schemaToJsonSchema, styledConsole, tryMap }; | ||
| export { A2UIRuntimeInfo, A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, AG_UI_CHANNEL_EVENT, AIMessage, Action, ActivityMessage, AgentDescription, AssistantMessage, Attachment, AttachmentModality, AttachmentUploadError, AttachmentUploadErrorReason, AttachmentUploadResult, AttachmentsConfig, AudioInputPart, BANNER_ERROR_NAMES, BaseCondition, COPILOTKIT_VERSION, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_ERROR_NAMES, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, ComparisonCondition, ComparisonRule, Condition, ConfigurationError, ConsoleColors, ConsoleStyles, CopilotCloudConfig, CopilotErrorEvent, CopilotErrorHandler, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, CopilotRequestContext, DEFAULT_AGENT_ID, DebugConfig, type DebugEventEnvelope, DeveloperMessage, DocumentInputPart, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, ExistenceCondition, ExistenceRule, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, ImageData, ImageInputPart, InferSchemaOutput, InputContent, InputContentDataSource, InputContentSource, InputContentUrlSource, InspectorMetadataV1, IntelligenceRuntimeInfo, JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, JSONValue, LambdaSendOptions, type LicenseChecker, LicenseContextValue, type LicenseFeatures, type LicenseOwner, type LicensePayload, type LicenseStatus, type LicenseTier, LogicalCondition, LogicalRule, MappedParameterTypes, MaybePromise, Message, MissingPublicApiKeyError, NonEmptyRecord, Parameter, PartialBy, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ReasoningMessage, RequiredBy, ResolvedCopilotKitError, ResolvedDebugConfig, Role, Rule, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SchemaToJsonSchemaOptions, Severity, StandardJSONSchemaV1, StandardSchemaV1, SystemMessage, TelemetryClient, TextInputPart, ThreadEndpointRuntimeInfo, ToolCall, ToolDefinition, ToolResult, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, UpgradeRequiredError, UserMessage, VideoInputPart, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, copyToClipboard, createLicenseContextValue, dataToUUID, ensureStructuredError, exceedsMaxSize, executeConditions, finalizeRunEvents, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getPossibleVersionMismatch, getSourceUrl, getZodParameters, isMacOS, isStructuredCopilotKitError, isTelemetryDisabled, isValidUUID, jsonSchemaToActionParameters, lambdaClient, logCopilotKitPlatformMessage, logStyled, logger, matchesAcceptFilter, parseAndWarnTelemetryId, parseInspectorMetadataV1, parseJson, parseTelemetryIdFromLicense, partialJSONParse, phoenixExponentialBackoff, publicApiKeyRequired, randomId, randomUUID, readBody, readFileAsBase64, resolveDebugConfig, safeParseToolArgs, schemaToJsonSchema, styledConsole, tryMap }; | ||
| //# sourceMappingURL=index.d.mts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkBa,kBAAA;;;;;UA2BI,mBAAA;;EAEf,MAAA,EAAQ,oBAAA;;EAER,OAAA,EAAS,gBAAA;;EAET,YAAA,GAAe,OAAA;;EAEf,QAAA,GAAW,OAAA;AAAA;;;;AAnCb;;;;;AA2BA;;;;;iBAwBgB,yBAAA,CACd,MAAA,EAAQ,oBAAA,sBACP,mBAAA"} | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkBa,kBAAA;;;;;UA2BI,mBAAA;;EAEf,MAAA,EAAQ,oBAAA;;EAER,OAAA,EAAS,gBAAA;;EAET,YAAA,GAAe,OAAA;;EAEf,QAAA,GAAW,OAAA;AAAA;;;;;AAnCb;;;;;AA2BA;;;;iBAwBgB,yBAAA,CACd,MAAA,EAAQ,oBAAA,sBACP,mBAAA"} |
+2
-1
@@ -6,2 +6,3 @@ import { copyToClipboard } from "./utils/clipboard.mjs"; | ||
| import { actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./utils/json-schema.mjs"; | ||
| import { parseInspectorMetadataV1 } from "./utils/inspector-metadata.mjs"; | ||
| import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "./utils/types.mjs"; | ||
@@ -50,3 +51,3 @@ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./utils/random-id.mjs"; | ||
| //#endregion | ||
| export { A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, AG_UI_CHANNEL_EVENT, BANNER_ERROR_NAMES, COPILOTKIT_VERSION, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_ERROR_NAMES, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, ConfigurationError, ConsoleColors, ConsoleStyles, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, DEFAULT_AGENT_ID, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ResolvedCopilotKitError, Severity, TelemetryClient, TranscriptionErrorCode, TranscriptionErrors, UpgradeRequiredError, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, copyToClipboard, createLicenseContextValue, dataToUUID, ensureStructuredError, exceedsMaxSize, executeConditions, finalizeRunEvents, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getPossibleVersionMismatch, getSourceUrl, getZodParameters, isMacOS, isStructuredCopilotKitError, isTelemetryDisabled, isValidUUID, jsonSchemaToActionParameters, lambdaClient, logCopilotKitPlatformMessage, logStyled, logger, matchesAcceptFilter, parseAndWarnTelemetryId, parseJson, parseTelemetryIdFromLicense, partialJSONParse, phoenixExponentialBackoff, publicApiKeyRequired, randomId, randomUUID, readBody, readFileAsBase64, resolveDebugConfig, safeParseToolArgs, schemaToJsonSchema, styledConsole, tryMap }; | ||
| export { A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, AG_UI_CHANNEL_EVENT, BANNER_ERROR_NAMES, COPILOTKIT_VERSION, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_ERROR_NAMES, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, ConfigurationError, ConsoleColors, ConsoleStyles, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, DEFAULT_AGENT_ID, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ResolvedCopilotKitError, Severity, TelemetryClient, TranscriptionErrorCode, TranscriptionErrors, UpgradeRequiredError, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, copyToClipboard, createLicenseContextValue, dataToUUID, ensureStructuredError, exceedsMaxSize, executeConditions, finalizeRunEvents, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getPossibleVersionMismatch, getSourceUrl, getZodParameters, isMacOS, isStructuredCopilotKitError, isTelemetryDisabled, isValidUUID, jsonSchemaToActionParameters, lambdaClient, logCopilotKitPlatformMessage, logStyled, logger, matchesAcceptFilter, parseAndWarnTelemetryId, parseInspectorMetadataV1, parseJson, parseTelemetryIdFromLicense, partialJSONParse, phoenixExponentialBackoff, publicApiKeyRequired, randomId, randomUUID, readBody, readFileAsBase64, resolveDebugConfig, safeParseToolArgs, schemaToJsonSchema, styledConsole, tryMap }; | ||
| //# sourceMappingURL=index.mjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.mjs","names":["packageJson.version"],"sources":["../src/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\nexport * from \"./debug\";\nexport * from \"./standard-schema\";\nexport * from \"./attachments\";\n\nexport { logger } from \"./logger\";\nexport { finalizeRunEvents } from \"./finalize-events\";\n\nexport {\n TranscriptionErrorCode,\n TranscriptionErrors,\n type TranscriptionErrorResponse,\n} from \"./transcription-errors\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n\n// Re-export only types from license-verifier (types are erased at compile time,\n// so they don't pull in the Node-only `crypto` dependency into client bundles).\n// Server-side packages (e.g. @copilotkit/runtime) should import runtime functions\n// like createLicenseChecker and getLicenseWarningHeader directly from\n// @copilotkit/license-verifier.\nexport type {\n LicenseChecker,\n LicenseStatus,\n LicensePayload,\n LicenseFeatures,\n LicenseTier,\n LicenseOwner,\n} from \"@copilotkit/license-verifier\";\n\nimport type { LicensePayload } from \"@copilotkit/license-verifier\";\nimport type { RuntimeLicenseStatus } from \"./utils/types\";\n\n// LicenseContextValue was dropped from license-verifier's public API in\n// 0.3.0, so it is defined here. The context shape is owned by this package\n// anyway via createLicenseContextValue below.\n\n/**\n * License context value exposed to child components.\n * Frontend providers create their own context using this shape.\n */\nexport interface LicenseContextValue {\n /** Server-reported license status from the runtime's /info endpoint. Null until known. */\n status: RuntimeLicenseStatus | null;\n /** The license payload if available. Always null on the client; the payload stays server-side. */\n license: LicensePayload | null;\n /** Whether a specific feature is licensed. Returns true if no licensing is active (no token). */\n checkFeature: (feature: string) => boolean;\n /** Get a numeric feature limit. Returns null if not applicable. */\n getLimit: (feature: string) => number | null;\n}\n\n/**\n * Client-safe license context factory, driven by the license status the\n * runtime reports via /info.\n *\n * Features are enabled unless the runtime definitively reports the license\n * as \"expired\" or \"invalid\". A null/\"none\"/\"unknown\" status fails open\n * (unlicensed = unrestricted, with branding), and \"expiring\" keeps features\n * on while the provider surfaces a warning banner. Per-feature data is not\n * in /info yet, so checkFeature is uniform across features and getLimit has\n * no limits to report. This is inlined here to avoid importing the full\n * license-verifier bundle (which depends on Node's `crypto`) into browser\n * bundles.\n */\nexport function createLicenseContextValue(\n status: RuntimeLicenseStatus | null | undefined,\n): LicenseContextValue {\n const resolvedStatus = status ?? null;\n const featuresEnabled =\n resolvedStatus !== \"expired\" && resolvedStatus !== \"invalid\";\n return {\n status: resolvedStatus,\n license: null,\n checkFeature: () => featuresEnabled,\n getLimit: () => null,\n };\n}\n\nexport {\n A2UI_DEFAULT_GENERATION_GUIDELINES,\n A2UI_DEFAULT_DESIGN_GUIDELINES,\n} from \"./a2ui-prompts\";\n\nexport type { DebugEventEnvelope } from \"./debug-event-envelope\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,qBAAqBA;;;;;;;;;;;;;;AAmDlC,SAAgB,0BACd,QACqB;CACrB,MAAM,iBAAiB,UAAU;CACjC,MAAM,kBACJ,mBAAmB,aAAa,mBAAmB;AACrD,QAAO;EACL,QAAQ;EACR,SAAS;EACT,oBAAoB;EACpB,gBAAgB;EACjB"} | ||
| {"version":3,"file":"index.mjs","names":["packageJson.version"],"sources":["../src/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\nexport * from \"./debug\";\nexport * from \"./standard-schema\";\nexport * from \"./attachments\";\n\nexport { logger } from \"./logger\";\nexport { finalizeRunEvents } from \"./finalize-events\";\n\nexport {\n TranscriptionErrorCode,\n TranscriptionErrors,\n type TranscriptionErrorResponse,\n} from \"./transcription-errors\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n\n// Re-export only types from license-verifier (types are erased at compile time,\n// so they don't pull in the Node-only `crypto` dependency into client bundles).\n// Server-side packages (e.g. @copilotkit/runtime) should import runtime functions\n// like createLicenseChecker and getLicenseWarningHeader directly from\n// @copilotkit/license-verifier.\nexport type {\n LicenseChecker,\n LicenseStatus,\n LicensePayload,\n LicenseFeatures,\n LicenseTier,\n LicenseOwner,\n} from \"@copilotkit/license-verifier\";\n\nimport type { LicensePayload } from \"@copilotkit/license-verifier\";\nimport type { RuntimeLicenseStatus } from \"./utils/types\";\n\n// LicenseContextValue was dropped from license-verifier's public API in\n// 0.3.0, so it is defined here. The context shape is owned by this package\n// anyway via createLicenseContextValue below.\n\n/**\n * License context value exposed to child components.\n * Frontend providers create their own context using this shape.\n */\nexport interface LicenseContextValue {\n /** Server-reported license status from the runtime's /info endpoint. Null until known. */\n status: RuntimeLicenseStatus | null;\n /** The license payload if available. Always null on the client; the payload stays server-side. */\n license: LicensePayload | null;\n /** Whether a specific feature is licensed. Returns true if no licensing is active (no token). */\n checkFeature: (feature: string) => boolean;\n /** Get a numeric feature limit. Returns null if not applicable. */\n getLimit: (feature: string) => number | null;\n}\n\n/**\n * Client-safe license context factory, driven by the license status the\n * runtime reports via /info.\n *\n * Features are enabled unless the runtime definitively reports the license\n * as \"expired\" or \"invalid\". A null/\"none\"/\"unknown\" status fails open\n * (unlicensed = unrestricted, with branding), and \"expiring\" keeps features\n * on while the provider surfaces a warning banner. Per-feature data is not\n * in /info yet, so checkFeature is uniform across features and getLimit has\n * no limits to report. This is inlined here to avoid importing the full\n * license-verifier bundle (which depends on Node's `crypto`) into browser\n * bundles.\n */\nexport function createLicenseContextValue(\n status: RuntimeLicenseStatus | null | undefined,\n): LicenseContextValue {\n const resolvedStatus = status ?? null;\n const featuresEnabled =\n resolvedStatus !== \"expired\" && resolvedStatus !== \"invalid\";\n return {\n status: resolvedStatus,\n license: null,\n checkFeature: () => featuresEnabled,\n getLimit: () => null,\n };\n}\n\nexport {\n A2UI_DEFAULT_GENERATION_GUIDELINES,\n A2UI_DEFAULT_DESIGN_GUIDELINES,\n} from \"./a2ui-prompts\";\n\nexport type { DebugEventEnvelope } from \"./debug-event-envelope\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,qBAAqBA;;;;;;;;;;;;;;AAmDlC,SAAgB,0BACd,QACqB;CACrB,MAAM,iBAAiB,UAAU;CACjC,MAAM,kBACJ,mBAAmB,aAAa,mBAAmB;AACrD,QAAO;EACL,QAAQ;EACR,SAAS;EACT,oBAAoB;EACpB,gBAAgB;EACjB"} |
+1
-1
| //#region package.json | ||
| var version = "1.66.4"; | ||
| var version = "1.67.0"; | ||
@@ -5,0 +5,0 @@ //#endregion |
+1
-1
| //#region package.json | ||
| var version = "1.66.4"; | ||
| var version = "1.67.0"; | ||
@@ -4,0 +4,0 @@ //#endregion |
@@ -7,2 +7,3 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); | ||
| const require_json_schema = require('./json-schema.cjs'); | ||
| const require_inspector_metadata = require('./inspector-metadata.cjs'); | ||
| const require_types = require('./types.cjs'); | ||
@@ -24,3 +25,3 @@ const require_random_id = require('./random-id.cjs'); | ||
| return JSON.parse(json); | ||
| } catch (e) { | ||
| } catch { | ||
| return fallback === "unset" ? null : fallback; | ||
@@ -38,3 +39,3 @@ } | ||
| return {}; | ||
| } catch (error) { | ||
| } catch { | ||
| return {}; | ||
@@ -41,0 +42,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch (error) {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;AAQzC,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAASA,aAAY,MAAM,KAAK;AACtC,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;UACF,OAAO;AACd,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"} | ||
| {"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./inspector-metadata\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO,aAAa,UAAU,OAAO;;;;;;;AAQzC,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAASA,aAAY,MAAM,KAAK;AACtC,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"} |
@@ -6,2 +6,3 @@ import { copyToClipboard } from "./clipboard.cjs"; | ||
| import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.cjs"; | ||
| import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.cjs"; | ||
| import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, ThreadEndpointRuntimeInfo } from "./types.cjs"; | ||
@@ -8,0 +9,0 @@ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.cjs"; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;AAiBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAYxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"} | ||
| {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;AAkBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAYxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"} |
@@ -6,2 +6,3 @@ import { copyToClipboard } from "./clipboard.mjs"; | ||
| import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.mjs"; | ||
| import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.mjs"; | ||
| import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, ThreadEndpointRuntimeInfo } from "./types.mjs"; | ||
@@ -8,0 +9,0 @@ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.mjs"; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;AAiBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAYxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"} | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;AAkBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAYxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"} |
@@ -6,2 +6,3 @@ import { copyToClipboard } from "./clipboard.mjs"; | ||
| import { actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.mjs"; | ||
| import { parseInspectorMetadataV1 } from "./inspector-metadata.mjs"; | ||
| import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "./types.mjs"; | ||
@@ -22,3 +23,3 @@ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.mjs"; | ||
| return JSON.parse(json); | ||
| } catch (e) { | ||
| } catch { | ||
| return fallback === "unset" ? null : fallback; | ||
@@ -36,3 +37,3 @@ } | ||
| return {}; | ||
| } catch (error) { | ||
| } catch { | ||
| return {}; | ||
@@ -39,0 +40,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch (error) {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;AAQzC,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAAS,YAAY,MAAM,KAAK;AACtC,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;UACF,OAAO;AACd,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"} | ||
| {"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./inspector-metadata\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO,aAAa,UAAU,OAAO;;;;;;;AAQzC,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAAS,YAAY,MAAM,KAAK;AACtC,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.cjs","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\n\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown>\n ? keyof T extends never\n ? never\n : T\n : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n capabilities?: AgentCapabilities;\n}\n\nexport type RuntimeMode = \"sse\" | \"intelligence\";\n\nexport const RUNTIME_MODE_SSE = \"sse\" as const;\nexport const RUNTIME_MODE_INTELLIGENCE = \"intelligence\" as const;\n\nexport interface IntelligenceRuntimeInfo {\n wsUrl: string;\n}\n\nexport interface ThreadEndpointRuntimeInfo {\n list: boolean;\n inspect: boolean;\n mutations: boolean;\n realtimeMetadata: boolean;\n}\n\nexport type RuntimeLicenseStatus =\n | \"valid\"\n | \"none\"\n | \"expired\"\n | \"expiring\"\n | \"invalid\"\n | \"unknown\";\n\nexport interface A2UIRuntimeInfo {\n enabled: boolean;\n /**\n * Agent ids the runtime applies A2UI to. When omitted, A2UI applies to\n * every agent served by the runtime.\n */\n agents?: string[];\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n mode: RuntimeMode;\n intelligence?: IntelligenceRuntimeInfo;\n threadEndpoints?: ThreadEndpointRuntimeInfo;\n /**\n * When true, the runtime exposes POST /agent/:agentId/suggest for stateless\n * suggestion generation. Absent on older runtimes; clients fall back to a\n * client-side agent run.\n */\n suggestions?: boolean;\n /**\n * @deprecated Use `a2ui` instead, which preserves per-agent scoping.\n * Kept for backward compatibility with older clients.\n */\n a2uiEnabled?: boolean;\n a2ui?: A2UIRuntimeInfo;\n openGenerativeUIEnabled?: boolean;\n licenseStatus?: RuntimeLicenseStatus;\n telemetryDisabled?: boolean;\n}\n"],"mappings":";;AA0BA,MAAa,mBAAmB;AAChC,MAAa,4BAA4B"} | ||
| {"version":3,"file":"types.cjs","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\n\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown>\n ? keyof T extends never\n ? never\n : T\n : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n capabilities?: AgentCapabilities;\n}\n\nexport type RuntimeMode = \"sse\" | \"intelligence\";\n\nexport const RUNTIME_MODE_SSE = \"sse\" as const;\nexport const RUNTIME_MODE_INTELLIGENCE = \"intelligence\" as const;\n\nexport interface IntelligenceRuntimeInfo {\n wsUrl: string;\n}\n\nexport interface ThreadEndpointRuntimeInfo {\n list: boolean;\n inspect: boolean;\n mutations: boolean;\n realtimeMetadata: boolean;\n}\n\nexport type RuntimeLicenseStatus =\n | \"valid\"\n | \"none\"\n | \"expired\"\n | \"expiring\"\n | \"invalid\"\n | \"unknown\";\n\nexport interface A2UIRuntimeInfo {\n enabled: boolean;\n /**\n * Agent ids the runtime applies A2UI to. When omitted, A2UI applies to\n * every agent served by the runtime.\n */\n agents?: string[];\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n mode: RuntimeMode;\n intelligence?: IntelligenceRuntimeInfo;\n threadEndpoints?: ThreadEndpointRuntimeInfo;\n /** Whether this runtime exposes trusted inspector metadata. */\n inspectorMetadata?: boolean;\n /**\n * When true, the runtime exposes POST /agent/:agentId/suggest for stateless\n * suggestion generation. Absent on older runtimes; clients fall back to a\n * client-side agent run.\n */\n suggestions?: boolean;\n /**\n * @deprecated Use `a2ui` instead, which preserves per-agent scoping.\n * Kept for backward compatibility with older clients.\n */\n a2uiEnabled?: boolean;\n a2ui?: A2UIRuntimeInfo;\n openGenerativeUIEnabled?: boolean;\n licenseStatus?: RuntimeLicenseStatus;\n telemetryDisabled?: boolean;\n}\n"],"mappings":";;AA0BA,MAAa,mBAAmB;AAChC,MAAa,4BAA4B"} |
@@ -46,2 +46,4 @@ import { AgentCapabilities } from "@ag-ui/core"; | ||
| threadEndpoints?: ThreadEndpointRuntimeInfo; | ||
| /** Whether this runtime exposes trusted inspector metadata. */ | ||
| inspectorMetadata?: boolean; | ||
| /** | ||
@@ -48,0 +50,0 @@ * When true, the runtime exposes POST /agent/:agentId/suggest for stateless |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";;;KAEY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;;AAA9C;;KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;EACA,YAAA,GAAe,iBAAA;AAAA;AAAA,KAGL,WAAA;AAAA,cAEC,gBAAA;AAAA,cACA,yBAAA;AAAA,UAEI,uBAAA;EACf,KAAA;AAAA;AAAA,UAGe,yBAAA;EACf,IAAA;EACA,OAAA;EACA,SAAA;EACA,gBAAA;AAAA;AAAA,KAGU,oBAAA;AAAA,UAQK,eAAA;EACf,OAAA;EAtCM;;;AAMR;EAqCE,MAAA;AAAA;AAAA,UAGe,WAAA;EACf,OAAA;EACA,MAAA,EAAQ,MAAA,SAAe,gBAAA;EACvB,6BAAA;EACA,IAAA,EAAM,WAAA;EACN,YAAA,GAAe,uBAAA;EACf,eAAA,GAAkB,yBAAA;EA1Cc;AAGlC;;;;EA6CE,WAAA;EA3CW;;;;EAgDX,WAAA;EACA,IAAA,GAAO,eAAA;EACP,uBAAA;EACA,aAAA,GAAgB,oBAAA;EAChB,iBAAA;AAAA"} | ||
| {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";;;KAEY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;;AAA9C;;KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;EACA,YAAA,GAAe,iBAAA;AAAA;AAAA,KAGL,WAAA;AAAA,cAEC,gBAAA;AAAA,cACA,yBAAA;AAAA,UAEI,uBAAA;EACf,KAAA;AAAA;AAAA,UAGe,yBAAA;EACf,IAAA;EACA,OAAA;EACA,SAAA;EACA,gBAAA;AAAA;AAAA,KAGU,oBAAA;AAAA,UAQK,eAAA;EACf,OAAA;EAtCM;;;AAMR;EAqCE,MAAA;AAAA;AAAA,UAGe,WAAA;EACf,OAAA;EACA,MAAA,EAAQ,MAAA,SAAe,gBAAA;EACvB,6BAAA;EACA,IAAA,EAAM,WAAA;EACN,YAAA,GAAe,uBAAA;EACf,eAAA,GAAkB,yBAAA;EA1Cc;EA4ChC,iBAAA;EAzCqB;;;;AAEvB;EA6CE,WAAA;;;;AA5CF;EAiDE,WAAA;EACA,IAAA,GAAO,eAAA;EACP,uBAAA;EACA,aAAA,GAAgB,oBAAA;EAChB,iBAAA;AAAA"} |
@@ -46,2 +46,4 @@ import { AgentCapabilities } from "@ag-ui/core"; | ||
| threadEndpoints?: ThreadEndpointRuntimeInfo; | ||
| /** Whether this runtime exposes trusted inspector metadata. */ | ||
| inspectorMetadata?: boolean; | ||
| /** | ||
@@ -48,0 +50,0 @@ * When true, the runtime exposes POST /agent/:agentId/suggest for stateless |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";;;KAEY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;;AAA9C;;KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;EACA,YAAA,GAAe,iBAAA;AAAA;AAAA,KAGL,WAAA;AAAA,cAEC,gBAAA;AAAA,cACA,yBAAA;AAAA,UAEI,uBAAA;EACf,KAAA;AAAA;AAAA,UAGe,yBAAA;EACf,IAAA;EACA,OAAA;EACA,SAAA;EACA,gBAAA;AAAA;AAAA,KAGU,oBAAA;AAAA,UAQK,eAAA;EACf,OAAA;EAtCM;;;AAMR;EAqCE,MAAA;AAAA;AAAA,UAGe,WAAA;EACf,OAAA;EACA,MAAA,EAAQ,MAAA,SAAe,gBAAA;EACvB,6BAAA;EACA,IAAA,EAAM,WAAA;EACN,YAAA,GAAe,uBAAA;EACf,eAAA,GAAkB,yBAAA;EA1Cc;AAGlC;;;;EA6CE,WAAA;EA3CW;;;;EAgDX,WAAA;EACA,IAAA,GAAO,eAAA;EACP,uBAAA;EACA,aAAA,GAAgB,oBAAA;EAChB,iBAAA;AAAA"} | ||
| {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";;;KAEY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;;AAA9C;;KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;EACA,YAAA,GAAe,iBAAA;AAAA;AAAA,KAGL,WAAA;AAAA,cAEC,gBAAA;AAAA,cACA,yBAAA;AAAA,UAEI,uBAAA;EACf,KAAA;AAAA;AAAA,UAGe,yBAAA;EACf,IAAA;EACA,OAAA;EACA,SAAA;EACA,gBAAA;AAAA;AAAA,KAGU,oBAAA;AAAA,UAQK,eAAA;EACf,OAAA;EAtCM;;;AAMR;EAqCE,MAAA;AAAA;AAAA,UAGe,WAAA;EACf,OAAA;EACA,MAAA,EAAQ,MAAA,SAAe,gBAAA;EACvB,6BAAA;EACA,IAAA,EAAM,WAAA;EACN,YAAA,GAAe,uBAAA;EACf,eAAA,GAAkB,yBAAA;EA1Cc;EA4ChC,iBAAA;EAzCqB;;;;AAEvB;EA6CE,WAAA;;;;AA5CF;EAiDE,WAAA;EACA,IAAA,GAAO,eAAA;EACP,uBAAA;EACA,aAAA,GAAgB,oBAAA;EAChB,iBAAA;AAAA"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.mjs","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\n\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown>\n ? keyof T extends never\n ? never\n : T\n : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n capabilities?: AgentCapabilities;\n}\n\nexport type RuntimeMode = \"sse\" | \"intelligence\";\n\nexport const RUNTIME_MODE_SSE = \"sse\" as const;\nexport const RUNTIME_MODE_INTELLIGENCE = \"intelligence\" as const;\n\nexport interface IntelligenceRuntimeInfo {\n wsUrl: string;\n}\n\nexport interface ThreadEndpointRuntimeInfo {\n list: boolean;\n inspect: boolean;\n mutations: boolean;\n realtimeMetadata: boolean;\n}\n\nexport type RuntimeLicenseStatus =\n | \"valid\"\n | \"none\"\n | \"expired\"\n | \"expiring\"\n | \"invalid\"\n | \"unknown\";\n\nexport interface A2UIRuntimeInfo {\n enabled: boolean;\n /**\n * Agent ids the runtime applies A2UI to. When omitted, A2UI applies to\n * every agent served by the runtime.\n */\n agents?: string[];\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n mode: RuntimeMode;\n intelligence?: IntelligenceRuntimeInfo;\n threadEndpoints?: ThreadEndpointRuntimeInfo;\n /**\n * When true, the runtime exposes POST /agent/:agentId/suggest for stateless\n * suggestion generation. Absent on older runtimes; clients fall back to a\n * client-side agent run.\n */\n suggestions?: boolean;\n /**\n * @deprecated Use `a2ui` instead, which preserves per-agent scoping.\n * Kept for backward compatibility with older clients.\n */\n a2uiEnabled?: boolean;\n a2ui?: A2UIRuntimeInfo;\n openGenerativeUIEnabled?: boolean;\n licenseStatus?: RuntimeLicenseStatus;\n telemetryDisabled?: boolean;\n}\n"],"mappings":";AA0BA,MAAa,mBAAmB;AAChC,MAAa,4BAA4B"} | ||
| {"version":3,"file":"types.mjs","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\n\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown>\n ? keyof T extends never\n ? never\n : T\n : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n capabilities?: AgentCapabilities;\n}\n\nexport type RuntimeMode = \"sse\" | \"intelligence\";\n\nexport const RUNTIME_MODE_SSE = \"sse\" as const;\nexport const RUNTIME_MODE_INTELLIGENCE = \"intelligence\" as const;\n\nexport interface IntelligenceRuntimeInfo {\n wsUrl: string;\n}\n\nexport interface ThreadEndpointRuntimeInfo {\n list: boolean;\n inspect: boolean;\n mutations: boolean;\n realtimeMetadata: boolean;\n}\n\nexport type RuntimeLicenseStatus =\n | \"valid\"\n | \"none\"\n | \"expired\"\n | \"expiring\"\n | \"invalid\"\n | \"unknown\";\n\nexport interface A2UIRuntimeInfo {\n enabled: boolean;\n /**\n * Agent ids the runtime applies A2UI to. When omitted, A2UI applies to\n * every agent served by the runtime.\n */\n agents?: string[];\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n mode: RuntimeMode;\n intelligence?: IntelligenceRuntimeInfo;\n threadEndpoints?: ThreadEndpointRuntimeInfo;\n /** Whether this runtime exposes trusted inspector metadata. */\n inspectorMetadata?: boolean;\n /**\n * When true, the runtime exposes POST /agent/:agentId/suggest for stateless\n * suggestion generation. Absent on older runtimes; clients fall back to a\n * client-side agent run.\n */\n suggestions?: boolean;\n /**\n * @deprecated Use `a2ui` instead, which preserves per-agent scoping.\n * Kept for backward compatibility with older clients.\n */\n a2uiEnabled?: boolean;\n a2ui?: A2UIRuntimeInfo;\n openGenerativeUIEnabled?: boolean;\n licenseStatus?: RuntimeLicenseStatus;\n telemetryDisabled?: boolean;\n}\n"],"mappings":";AA0BA,MAAa,mBAAmB;AAChC,MAAa,4BAA4B"} |
+1
-1
| { | ||
| "name": "@copilotkit/shared", | ||
| "version": "1.66.4", | ||
| "version": "1.67.0", | ||
| "private": false, | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+53
-0
@@ -145,4 +145,57 @@ # CopilotKit - Shared | ||
| ## Trusted Inspector metadata | ||
| `@copilotkit/shared` exports the versioned `InspectorMetadataV1` contract and | ||
| `parseInspectorMetadataV1()` parser. A Copilot Runtime can use this contract to | ||
| send project and license context to the Inspector: | ||
| ```ts | ||
| interface InspectorMetadataV1 { | ||
| readonly schemaVersion: 1; | ||
| readonly identity?: { | ||
| readonly organizationName: string; | ||
| readonly projectName: string; | ||
| }; | ||
| readonly plan?: { readonly code: string; readonly label: string }; | ||
| readonly license?: { | ||
| readonly state: "valid" | "none" | "expired" | "unknown"; | ||
| }; | ||
| readonly action?: | ||
| | { readonly kind: "manage_plan"; readonly url: string } | ||
| | { readonly kind: "renew"; readonly url: string } | ||
| | { readonly kind: "enable_intelligence"; readonly url: string }; | ||
| readonly usage?: { | ||
| readonly used: number; | ||
| readonly limit: | ||
| | { readonly kind: "finite"; readonly value: number } | ||
| | { readonly kind: "unlimited" } | ||
| | { readonly kind: "unknown" }; | ||
| readonly expiringSoonCount?: number; | ||
| }; | ||
| } | ||
| ``` | ||
| Every optional module is independent. The parser drops an invalid `identity`, | ||
| `plan`, `license`, `action`, or `usage` module without hiding valid sibling | ||
| modules. It returns `undefined` when the top-level value is not a plain object | ||
| with `schemaVersion: 1`. | ||
| Action URLs are treated as trusted navigation only after parsing. They must use | ||
| HTTPS, or HTTP on `localhost`, `127.0.0.1`, or `[::1]`; URLs with credentials, a | ||
| query string, or a fragment are rejected. Consumers use the accepted URL as | ||
| supplied and must not derive a destination from identity or plan values. | ||
| The optional `usage.expiringSoonCount` field lets V1 producers report a known | ||
| count. Older producers may omit it; absence remains valid V1 usage, while `0` | ||
| is a known count and stays distinct from absence. The parser drops a malformed, | ||
| inherited, or accessor-backed expiry leaf without removing `used`, `limit`, or | ||
| valid sibling modules. Older V1 consumers ignore the additive field, so | ||
| producers and consumers do not need a V2 schema or lock-step deployment. | ||
| `RuntimeInfo.inspectorMetadata?: boolean` is the capability signal. Clients only | ||
| request the optional metadata route when a runtime reports | ||
| `inspectorMetadata: true` in its runtime-info response. | ||
| # Documentation | ||
| To get started with CopilotKit, please check out the [documentation](https://docs.copilotkit.ai). |
@@ -6,2 +6,3 @@ export * from "./clipboard"; | ||
| export * from "./json-schema"; | ||
| export * from "./inspector-metadata"; | ||
| export * from "./types"; | ||
@@ -22,3 +23,3 @@ export * from "./random-id"; | ||
| return JSON.parse(json); | ||
| } catch (e) { | ||
| } catch { | ||
| return fallback === "unset" ? null : fallback; | ||
@@ -39,3 +40,3 @@ } | ||
| return {}; | ||
| } catch (error) { | ||
| } catch { | ||
| return {}; | ||
@@ -42,0 +43,0 @@ } |
@@ -65,2 +65,4 @@ import type { AgentCapabilities } from "@ag-ui/core"; | ||
| threadEndpoints?: ThreadEndpointRuntimeInfo; | ||
| /** Whether this runtime exposes trusted inspector metadata. */ | ||
| inspectorMetadata?: boolean; | ||
| /** | ||
@@ -67,0 +69,0 @@ * When true, the runtime exposes POST /agent/:agentId/suggest for stateless |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1026467
8.2%273
3.8%11767
12.68%201
35.81%