@copilotkit/shared 2.0.0-rc.13 → 2.0.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/generative-ui/child-refs.cjs +3 -3
- package/dist/generative-ui/child-refs.cjs.map +1 -1
- package/dist/generative-ui/child-refs.d.cts.map +1 -1
- package/dist/generative-ui/child-refs.d.mts.map +1 -1
- package/dist/generative-ui/child-refs.mjs +3 -3
- package/dist/generative-ui/child-refs.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +1 -1
- package/dist/generative-ui/schema-render.cjs.map +1 -1
- package/dist/generative-ui/schema-render.d.cts.map +1 -1
- package/dist/generative-ui/schema-render.d.mts.map +1 -1
- package/dist/generative-ui/schema-render.mjs +1 -1
- package/dist/generative-ui/schema-render.mjs.map +1 -1
- package/dist/generative-ui/validate-operation.cjs +2 -2
- package/dist/generative-ui/validate-operation.cjs.map +1 -1
- package/dist/generative-ui/validate-operation.mjs +2 -2
- package/dist/generative-ui/validate-operation.mjs.map +1 -1
- package/dist/index.umd.js +8 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/telemetry/lambda-client.cjs +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/package.json +2 -2
- package/src/a2ui-envelope.ts +2 -1
- package/src/generative-ui/child-refs.ts +5 -4
- package/src/generative-ui/schema-render.ts +4 -1
- package/src/generative-ui/validate-operation.ts +2 -2
- package/src/telemetry/lambda-client.ts +5 -1
- package/tsconfig.json +3 -1
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
|
@@ -33,7 +33,7 @@ function parseTelemetryIdFromLicense(token) {
|
|
|
33
33
|
if (parts.length !== 3) return null;
|
|
34
34
|
try {
|
|
35
35
|
const payload = parts[1];
|
|
36
|
-
if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
36
|
+
if (payload === void 0 || !/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
37
37
|
let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
38
38
|
const padding = (4 - b64.length % 4) % 4;
|
|
39
39
|
b64 += "=".repeat(padding);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-client.cjs","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"sourcesContent":["// Telemetry sink client.\n//\n// Posts events to a CopilotKit-controlled telemetry-sink endpoint, which\n// fans out to Scarf, Reo, and any future destinations. Replaces the direct\n// per-vendor calls (formerly a Scarf-specific client) so that vendor changes\n// don't require SDK releases and so that downstream services we don't want\n// exposed to OSS readers (e.g. the email-enrichment service backing Reo) stay\n// private.\n//\n// Two attribution modes:\n// - Identified: a standalone telemetry id or a CopilotKit license token is\n// configured. Standalone identity takes precedence. License tokens are\n// JWTs (header.payload.sig) whose payload carries `telemetry_id`; the SDK\n// base64url-decodes the payload — without verifying the Ed25519 signature,\n// which is the license-verifier's job. The resolved identity is emitted\n// only via `X-CopilotKit-Telemetry-Id`.\n// - Anonymous: no license token, or a malformed/non-JWT one. No\n// telemetry-id header; events still flow, attribution is best-effort\n// from request-level signals (IP, UA).\n//\n// Note: CopilotCloud customer API keys (`ck_<env>_<id>.<secret>`) are\n// unrelated to telemetry attribution. They flow into Segment / PostHog\n// via the v1 shared TelemetryClient and never reach this code path.\n//\n// Best-effort: every error is swallowed. Telemetry must not break the\n// host application.\n\nconst TELEMETRY_SINK_URL =\n (typeof process !== \"undefined\" && process.env?.COPILOTKIT_TELEMETRY_URL) ||\n \"https://telemetry.copilotkit.ai/ingest\";\n\nconst FETCH_TIMEOUT_MS = 3000;\nconst TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\nexport interface LambdaSendOptions {\n event: string;\n properties?: Record<string, unknown>;\n globalProperties?: Record<string, unknown>;\n packageName?: string;\n packageVersion?: string;\n /** Standalone analytics identity, resolved before any legacy license claim. */\n telemetryId?: string;\n // The CopilotKit license token (Ed25519-signed JWT), when one is\n // configured on the runtime. The sender base64url-decodes the payload\n // segment to extract `telemetry_id`; missing or malformed tokens\n // produce an anonymous send.\n licenseToken?: string;\n}\n\n/**\n * Return the first telemetry identity accepted by the ingest service.\n *\n * Empty and whitespace-only values are unconfigured placeholders and must not\n * suppress a later identity source. Leading and trailing HTTP spaces and tabs\n * are removed before validation. The ingest service accepts 1 to 128 ASCII\n * letters, digits, underscores, and hyphens.\n *\n * @internal\n */\nexport function firstNonBlankTelemetryId(\n ...candidates: ReadonlyArray<string | undefined>\n): string | undefined {\n for (const candidate of candidates) {\n if (candidate === undefined) {\n continue;\n }\n\n const normalized = candidate.replace(/^[\\t ]+|[\\t ]+$/g, \"\");\n if (TELEMETRY_ID_PATTERN.test(normalized)) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\n// These fields aren't used by the telemetry service, so we strip them\n// at the wire boundary rather than rely on every caller to omit them.\n// Both the snake_case and camelCase variants are listed because callers\n// upstream use different conventions.\nconst STRIPPED_KEYS = new Set([\"cloud.public_api_key\", \"cloud.publicApiKey\"]);\n\nfunction stripCloudKeys(\n obj: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n if (!obj) return {};\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!STRIPPED_KEYS.has(k)) out[k] = v;\n }\n return out;\n}\n\n// Pull telemetry_id out of a CopilotKit license token without verifying\n// the signature. The token shape is a standard JWT\n// (`<header>.<payload>.<sig>`) with base64url-encoded segments; the\n// payload is UTF-8 JSON with a telemetry_id accepted by the ingest service.\n//\n// Verification (Ed25519, key rotation, expiry) is the license-verifier\n// package's job. For telemetry attribution we only need the claimed id —\n// the trust model is claim-only on the Lambda side anyway.\n//\n// Exported so TelemetryClient setters can detect unparseable tokens at\n// configuration time and surface a single warning, instead of silently\n// emitting anonymous events on every capture.\nexport function parseTelemetryIdFromLicense(token?: string): string | null {\n if (!token) return null;\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n try {\n const payload = parts[1];\n if (!/^[A-Za-z0-9_-]+$/.test(payload)
|
|
1
|
+
{"version":3,"file":"lambda-client.cjs","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"sourcesContent":["// Telemetry sink client.\n//\n// Posts events to a CopilotKit-controlled telemetry-sink endpoint, which\n// fans out to Scarf, Reo, and any future destinations. Replaces the direct\n// per-vendor calls (formerly a Scarf-specific client) so that vendor changes\n// don't require SDK releases and so that downstream services we don't want\n// exposed to OSS readers (e.g. the email-enrichment service backing Reo) stay\n// private.\n//\n// Two attribution modes:\n// - Identified: a standalone telemetry id or a CopilotKit license token is\n// configured. Standalone identity takes precedence. License tokens are\n// JWTs (header.payload.sig) whose payload carries `telemetry_id`; the SDK\n// base64url-decodes the payload — without verifying the Ed25519 signature,\n// which is the license-verifier's job. The resolved identity is emitted\n// only via `X-CopilotKit-Telemetry-Id`.\n// - Anonymous: no license token, or a malformed/non-JWT one. No\n// telemetry-id header; events still flow, attribution is best-effort\n// from request-level signals (IP, UA).\n//\n// Note: CopilotCloud customer API keys (`ck_<env>_<id>.<secret>`) are\n// unrelated to telemetry attribution. They flow into Segment / PostHog\n// via the v1 shared TelemetryClient and never reach this code path.\n//\n// Best-effort: every error is swallowed. Telemetry must not break the\n// host application.\n\nconst TELEMETRY_SINK_URL =\n (typeof process !== \"undefined\" && process.env?.COPILOTKIT_TELEMETRY_URL) ||\n \"https://telemetry.copilotkit.ai/ingest\";\n\nconst FETCH_TIMEOUT_MS = 3000;\nconst TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\nexport interface LambdaSendOptions {\n event: string;\n properties?: Record<string, unknown>;\n globalProperties?: Record<string, unknown>;\n packageName?: string;\n packageVersion?: string;\n /** Standalone analytics identity, resolved before any legacy license claim. */\n telemetryId?: string;\n // The CopilotKit license token (Ed25519-signed JWT), when one is\n // configured on the runtime. The sender base64url-decodes the payload\n // segment to extract `telemetry_id`; missing or malformed tokens\n // produce an anonymous send.\n licenseToken?: string;\n}\n\n/**\n * Return the first telemetry identity accepted by the ingest service.\n *\n * Empty and whitespace-only values are unconfigured placeholders and must not\n * suppress a later identity source. Leading and trailing HTTP spaces and tabs\n * are removed before validation. The ingest service accepts 1 to 128 ASCII\n * letters, digits, underscores, and hyphens.\n *\n * @internal\n */\nexport function firstNonBlankTelemetryId(\n ...candidates: ReadonlyArray<string | undefined>\n): string | undefined {\n for (const candidate of candidates) {\n if (candidate === undefined) {\n continue;\n }\n\n const normalized = candidate.replace(/^[\\t ]+|[\\t ]+$/g, \"\");\n if (TELEMETRY_ID_PATTERN.test(normalized)) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\n// These fields aren't used by the telemetry service, so we strip them\n// at the wire boundary rather than rely on every caller to omit them.\n// Both the snake_case and camelCase variants are listed because callers\n// upstream use different conventions.\nconst STRIPPED_KEYS = new Set([\"cloud.public_api_key\", \"cloud.publicApiKey\"]);\n\nfunction stripCloudKeys(\n obj: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n if (!obj) return {};\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!STRIPPED_KEYS.has(k)) out[k] = v;\n }\n return out;\n}\n\n// Pull telemetry_id out of a CopilotKit license token without verifying\n// the signature. The token shape is a standard JWT\n// (`<header>.<payload>.<sig>`) with base64url-encoded segments; the\n// payload is UTF-8 JSON with a telemetry_id accepted by the ingest service.\n//\n// Verification (Ed25519, key rotation, expiry) is the license-verifier\n// package's job. For telemetry attribution we only need the claimed id —\n// the trust model is claim-only on the Lambda side anyway.\n//\n// Exported so TelemetryClient setters can detect unparseable tokens at\n// configuration time and surface a single warning, instead of silently\n// emitting anonymous events on every capture.\nexport function parseTelemetryIdFromLicense(token?: string): string | null {\n if (!token) return null;\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n try {\n const payload = parts[1];\n if (\n payload === undefined ||\n !/^[A-Za-z0-9_-]+$/.test(payload) ||\n payload.length % 4 === 1\n ) {\n return null;\n }\n\n let b64 = payload.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padding = (4 - (b64.length % 4)) % 4;\n b64 += \"=\".repeat(padding);\n const json =\n typeof Buffer !== \"undefined\"\n ? Buffer.from(b64, \"base64\").toString(\"utf8\")\n : new TextDecoder().decode(\n Uint8Array.from(atob(b64), (character) => character.charCodeAt(0)),\n );\n const decoded = JSON.parse(json) as { telemetry_id?: unknown };\n const telemetryId =\n typeof decoded.telemetry_id === \"string\"\n ? decoded.telemetry_id\n : undefined;\n return firstNonBlankTelemetryId(telemetryId) ?? null;\n } catch {\n return null;\n }\n}\n\n// Parse the telemetry_id from a license token AND emit the rollout smoke\n// signal if the parse returned null. Returning the parsed id lets callers\n// cache it in one step (avoiding a second parseTelemetryIdFromLicense\n// pass) while keeping the warn text in lockstep between the v1 (shared)\n// TelemetryClient.setLicenseToken and the v2 (runtime)\n// TelemetryClient.setTelemetryIdentity.\nexport function parseAndWarnTelemetryId(licenseToken: string): string | null {\n const telemetryId = parseTelemetryIdFromLicense(licenseToken);\n if (!telemetryId) {\n console.warn(\n \"[CopilotKit] License token did not yield a telemetry_id; telemetry events will be sent anonymously.\",\n );\n }\n return telemetryId;\n}\n\nexport async function send(opts: LambdaSendOptions): Promise<void> {\n try {\n const body = JSON.stringify({\n event: opts.event,\n properties: stripCloudKeys(opts.properties),\n global_properties: stripCloudKeys(opts.globalProperties),\n package: {\n name: opts.packageName,\n version: opts.packageVersion,\n },\n ts: Math.floor(Date.now() / 1000),\n });\n\n const telemetryId =\n firstNonBlankTelemetryId(opts.telemetryId) ??\n parseTelemetryIdFromLicense(opts.licenseToken);\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"User-Agent\": opts.packageName\n ? `CopilotKit-Runtime/${opts.packageVersion ?? \"unknown\"} (${opts.packageName})`\n : \"CopilotKit-Runtime\",\n };\n if (telemetryId) {\n headers[\"X-CopilotKit-Telemetry-Id\"] = telemetryId;\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);\n try {\n await fetch(TELEMETRY_SINK_URL, {\n method: \"POST\",\n headers,\n body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n } catch {\n // Silent failure — telemetry must not break the application.\n }\n}\n\nexport const lambdaClient = { send };\n"],"mappings":";;AA2BA,MAAM,qBACH,OAAO,YAAY,eAAe,QAAQ,KAAK,4BAChD;AAEF,MAAM,mBAAmB;AACzB,MAAM,uBAAuB;;;;;;;;;;;AA2B7B,SAAgB,yBACd,GAAG,YACiB;AACpB,MAAK,MAAM,aAAa,YAAY;AAClC,MAAI,cAAc,OAChB;EAGF,MAAM,aAAa,UAAU,QAAQ,oBAAoB,GAAG;AAC5D,MAAI,qBAAqB,KAAK,WAAW,CACvC,QAAO;;;AAWb,MAAM,gBAAgB,IAAI,IAAI,CAAC,wBAAwB,qBAAqB,CAAC;AAE7E,SAAS,eACP,KACyB;AACzB,KAAI,CAAC,IAAK,QAAO,EAAE;CACnB,MAAM,MAA+B,EAAE;AACvC,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,IAAI,CACtC,KAAI,CAAC,cAAc,IAAI,EAAE,CAAE,KAAI,KAAK;AAEtC,QAAO;;AAeT,SAAgB,4BAA4B,OAA+B;AACzE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,KAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,KAAI;EACF,MAAM,UAAU,MAAM;AACtB,MACE,YAAY,UACZ,CAAC,mBAAmB,KAAK,QAAQ,IACjC,QAAQ,SAAS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,CAAC;YACM;AACR,gBAAa,UAAU;;SAEnB;;AAKV,MAAa,eAAe,EAAE,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-client.d.cts","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"mappings":";UAkCiB,iBAAA;EACf,KAAA;EACA,UAAA,GAAa,MAAA;EACb,gBAAA,GAAmB,MAAA;EACnB,WAAA;EACA,cAAA;EAHA;EAKA,WAAA;EAKA,YAAA;AAAA;;;;;;;AAaF;;;;iBAAgB,wBAAA,CAAA,GACX,UAAA,EAAY,aAAA;AAAA,iBA6CD,2BAAA,CAA4B,KAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"lambda-client.d.cts","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"mappings":";UAkCiB,iBAAA;EACf,KAAA;EACA,UAAA,GAAa,MAAA;EACb,gBAAA,GAAmB,MAAA;EACnB,WAAA;EACA,cAAA;EAHA;EAKA,WAAA;EAKA,YAAA;AAAA;;;;;;;AAaF;;;;iBAAgB,wBAAA,CAAA,GACX,UAAA,EAAY,aAAA;AAAA,iBA6CD,2BAAA,CAA4B,KAAA;AAAA,iBAwC5B,uBAAA,CAAwB,YAAA;AAAA,iBAUlB,IAAA,CAAK,IAAA,EAAM,iBAAA,GAAoB,OAAA;AAAA,cA2CxC,YAAA;eAAuB,IAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-client.d.mts","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"mappings":";UAkCiB,iBAAA;EACf,KAAA;EACA,UAAA,GAAa,MAAA;EACb,gBAAA,GAAmB,MAAA;EACnB,WAAA;EACA,cAAA;EAHA;EAKA,WAAA;EAKA,YAAA;AAAA;;;;;;;AAaF;;;;iBAAgB,wBAAA,CAAA,GACX,UAAA,EAAY,aAAA;AAAA,iBA6CD,2BAAA,CAA4B,KAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"lambda-client.d.mts","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"mappings":";UAkCiB,iBAAA;EACf,KAAA;EACA,UAAA,GAAa,MAAA;EACb,gBAAA,GAAmB,MAAA;EACnB,WAAA;EACA,cAAA;EAHA;EAKA,WAAA;EAKA,YAAA;AAAA;;;;;;;AAaF;;;;iBAAgB,wBAAA,CAAA,GACX,UAAA,EAAY,aAAA;AAAA,iBA6CD,2BAAA,CAA4B,KAAA;AAAA,iBAwC5B,uBAAA,CAAwB,YAAA;AAAA,iBAUlB,IAAA,CAAK,IAAA,EAAM,iBAAA,GAAoB,OAAA;AAAA,cA2CxC,YAAA;eAAuB,IAAA;AAAA"}
|
|
@@ -32,7 +32,7 @@ function parseTelemetryIdFromLicense(token) {
|
|
|
32
32
|
if (parts.length !== 3) return null;
|
|
33
33
|
try {
|
|
34
34
|
const payload = parts[1];
|
|
35
|
-
if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
35
|
+
if (payload === void 0 || !/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
36
36
|
let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
37
37
|
const padding = (4 - b64.length % 4) % 4;
|
|
38
38
|
b64 += "=".repeat(padding);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-client.mjs","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"sourcesContent":["// Telemetry sink client.\n//\n// Posts events to a CopilotKit-controlled telemetry-sink endpoint, which\n// fans out to Scarf, Reo, and any future destinations. Replaces the direct\n// per-vendor calls (formerly a Scarf-specific client) so that vendor changes\n// don't require SDK releases and so that downstream services we don't want\n// exposed to OSS readers (e.g. the email-enrichment service backing Reo) stay\n// private.\n//\n// Two attribution modes:\n// - Identified: a standalone telemetry id or a CopilotKit license token is\n// configured. Standalone identity takes precedence. License tokens are\n// JWTs (header.payload.sig) whose payload carries `telemetry_id`; the SDK\n// base64url-decodes the payload — without verifying the Ed25519 signature,\n// which is the license-verifier's job. The resolved identity is emitted\n// only via `X-CopilotKit-Telemetry-Id`.\n// - Anonymous: no license token, or a malformed/non-JWT one. No\n// telemetry-id header; events still flow, attribution is best-effort\n// from request-level signals (IP, UA).\n//\n// Note: CopilotCloud customer API keys (`ck_<env>_<id>.<secret>`) are\n// unrelated to telemetry attribution. They flow into Segment / PostHog\n// via the v1 shared TelemetryClient and never reach this code path.\n//\n// Best-effort: every error is swallowed. Telemetry must not break the\n// host application.\n\nconst TELEMETRY_SINK_URL =\n (typeof process !== \"undefined\" && process.env?.COPILOTKIT_TELEMETRY_URL) ||\n \"https://telemetry.copilotkit.ai/ingest\";\n\nconst FETCH_TIMEOUT_MS = 3000;\nconst TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\nexport interface LambdaSendOptions {\n event: string;\n properties?: Record<string, unknown>;\n globalProperties?: Record<string, unknown>;\n packageName?: string;\n packageVersion?: string;\n /** Standalone analytics identity, resolved before any legacy license claim. */\n telemetryId?: string;\n // The CopilotKit license token (Ed25519-signed JWT), when one is\n // configured on the runtime. The sender base64url-decodes the payload\n // segment to extract `telemetry_id`; missing or malformed tokens\n // produce an anonymous send.\n licenseToken?: string;\n}\n\n/**\n * Return the first telemetry identity accepted by the ingest service.\n *\n * Empty and whitespace-only values are unconfigured placeholders and must not\n * suppress a later identity source. Leading and trailing HTTP spaces and tabs\n * are removed before validation. The ingest service accepts 1 to 128 ASCII\n * letters, digits, underscores, and hyphens.\n *\n * @internal\n */\nexport function firstNonBlankTelemetryId(\n ...candidates: ReadonlyArray<string | undefined>\n): string | undefined {\n for (const candidate of candidates) {\n if (candidate === undefined) {\n continue;\n }\n\n const normalized = candidate.replace(/^[\\t ]+|[\\t ]+$/g, \"\");\n if (TELEMETRY_ID_PATTERN.test(normalized)) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\n// These fields aren't used by the telemetry service, so we strip them\n// at the wire boundary rather than rely on every caller to omit them.\n// Both the snake_case and camelCase variants are listed because callers\n// upstream use different conventions.\nconst STRIPPED_KEYS = new Set([\"cloud.public_api_key\", \"cloud.publicApiKey\"]);\n\nfunction stripCloudKeys(\n obj: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n if (!obj) return {};\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!STRIPPED_KEYS.has(k)) out[k] = v;\n }\n return out;\n}\n\n// Pull telemetry_id out of a CopilotKit license token without verifying\n// the signature. The token shape is a standard JWT\n// (`<header>.<payload>.<sig>`) with base64url-encoded segments; the\n// payload is UTF-8 JSON with a telemetry_id accepted by the ingest service.\n//\n// Verification (Ed25519, key rotation, expiry) is the license-verifier\n// package's job. For telemetry attribution we only need the claimed id —\n// the trust model is claim-only on the Lambda side anyway.\n//\n// Exported so TelemetryClient setters can detect unparseable tokens at\n// configuration time and surface a single warning, instead of silently\n// emitting anonymous events on every capture.\nexport function parseTelemetryIdFromLicense(token?: string): string | null {\n if (!token) return null;\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n try {\n const payload = parts[1];\n if (!/^[A-Za-z0-9_-]+$/.test(payload)
|
|
1
|
+
{"version":3,"file":"lambda-client.mjs","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"sourcesContent":["// Telemetry sink client.\n//\n// Posts events to a CopilotKit-controlled telemetry-sink endpoint, which\n// fans out to Scarf, Reo, and any future destinations. Replaces the direct\n// per-vendor calls (formerly a Scarf-specific client) so that vendor changes\n// don't require SDK releases and so that downstream services we don't want\n// exposed to OSS readers (e.g. the email-enrichment service backing Reo) stay\n// private.\n//\n// Two attribution modes:\n// - Identified: a standalone telemetry id or a CopilotKit license token is\n// configured. Standalone identity takes precedence. License tokens are\n// JWTs (header.payload.sig) whose payload carries `telemetry_id`; the SDK\n// base64url-decodes the payload — without verifying the Ed25519 signature,\n// which is the license-verifier's job. The resolved identity is emitted\n// only via `X-CopilotKit-Telemetry-Id`.\n// - Anonymous: no license token, or a malformed/non-JWT one. No\n// telemetry-id header; events still flow, attribution is best-effort\n// from request-level signals (IP, UA).\n//\n// Note: CopilotCloud customer API keys (`ck_<env>_<id>.<secret>`) are\n// unrelated to telemetry attribution. They flow into Segment / PostHog\n// via the v1 shared TelemetryClient and never reach this code path.\n//\n// Best-effort: every error is swallowed. Telemetry must not break the\n// host application.\n\nconst TELEMETRY_SINK_URL =\n (typeof process !== \"undefined\" && process.env?.COPILOTKIT_TELEMETRY_URL) ||\n \"https://telemetry.copilotkit.ai/ingest\";\n\nconst FETCH_TIMEOUT_MS = 3000;\nconst TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\nexport interface LambdaSendOptions {\n event: string;\n properties?: Record<string, unknown>;\n globalProperties?: Record<string, unknown>;\n packageName?: string;\n packageVersion?: string;\n /** Standalone analytics identity, resolved before any legacy license claim. */\n telemetryId?: string;\n // The CopilotKit license token (Ed25519-signed JWT), when one is\n // configured on the runtime. The sender base64url-decodes the payload\n // segment to extract `telemetry_id`; missing or malformed tokens\n // produce an anonymous send.\n licenseToken?: string;\n}\n\n/**\n * Return the first telemetry identity accepted by the ingest service.\n *\n * Empty and whitespace-only values are unconfigured placeholders and must not\n * suppress a later identity source. Leading and trailing HTTP spaces and tabs\n * are removed before validation. The ingest service accepts 1 to 128 ASCII\n * letters, digits, underscores, and hyphens.\n *\n * @internal\n */\nexport function firstNonBlankTelemetryId(\n ...candidates: ReadonlyArray<string | undefined>\n): string | undefined {\n for (const candidate of candidates) {\n if (candidate === undefined) {\n continue;\n }\n\n const normalized = candidate.replace(/^[\\t ]+|[\\t ]+$/g, \"\");\n if (TELEMETRY_ID_PATTERN.test(normalized)) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\n// These fields aren't used by the telemetry service, so we strip them\n// at the wire boundary rather than rely on every caller to omit them.\n// Both the snake_case and camelCase variants are listed because callers\n// upstream use different conventions.\nconst STRIPPED_KEYS = new Set([\"cloud.public_api_key\", \"cloud.publicApiKey\"]);\n\nfunction stripCloudKeys(\n obj: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n if (!obj) return {};\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!STRIPPED_KEYS.has(k)) out[k] = v;\n }\n return out;\n}\n\n// Pull telemetry_id out of a CopilotKit license token without verifying\n// the signature. The token shape is a standard JWT\n// (`<header>.<payload>.<sig>`) with base64url-encoded segments; the\n// payload is UTF-8 JSON with a telemetry_id accepted by the ingest service.\n//\n// Verification (Ed25519, key rotation, expiry) is the license-verifier\n// package's job. For telemetry attribution we only need the claimed id —\n// the trust model is claim-only on the Lambda side anyway.\n//\n// Exported so TelemetryClient setters can detect unparseable tokens at\n// configuration time and surface a single warning, instead of silently\n// emitting anonymous events on every capture.\nexport function parseTelemetryIdFromLicense(token?: string): string | null {\n if (!token) return null;\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n try {\n const payload = parts[1];\n if (\n payload === undefined ||\n !/^[A-Za-z0-9_-]+$/.test(payload) ||\n payload.length % 4 === 1\n ) {\n return null;\n }\n\n let b64 = payload.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padding = (4 - (b64.length % 4)) % 4;\n b64 += \"=\".repeat(padding);\n const json =\n typeof Buffer !== \"undefined\"\n ? Buffer.from(b64, \"base64\").toString(\"utf8\")\n : new TextDecoder().decode(\n Uint8Array.from(atob(b64), (character) => character.charCodeAt(0)),\n );\n const decoded = JSON.parse(json) as { telemetry_id?: unknown };\n const telemetryId =\n typeof decoded.telemetry_id === \"string\"\n ? decoded.telemetry_id\n : undefined;\n return firstNonBlankTelemetryId(telemetryId) ?? null;\n } catch {\n return null;\n }\n}\n\n// Parse the telemetry_id from a license token AND emit the rollout smoke\n// signal if the parse returned null. Returning the parsed id lets callers\n// cache it in one step (avoiding a second parseTelemetryIdFromLicense\n// pass) while keeping the warn text in lockstep between the v1 (shared)\n// TelemetryClient.setLicenseToken and the v2 (runtime)\n// TelemetryClient.setTelemetryIdentity.\nexport function parseAndWarnTelemetryId(licenseToken: string): string | null {\n const telemetryId = parseTelemetryIdFromLicense(licenseToken);\n if (!telemetryId) {\n console.warn(\n \"[CopilotKit] License token did not yield a telemetry_id; telemetry events will be sent anonymously.\",\n );\n }\n return telemetryId;\n}\n\nexport async function send(opts: LambdaSendOptions): Promise<void> {\n try {\n const body = JSON.stringify({\n event: opts.event,\n properties: stripCloudKeys(opts.properties),\n global_properties: stripCloudKeys(opts.globalProperties),\n package: {\n name: opts.packageName,\n version: opts.packageVersion,\n },\n ts: Math.floor(Date.now() / 1000),\n });\n\n const telemetryId =\n firstNonBlankTelemetryId(opts.telemetryId) ??\n parseTelemetryIdFromLicense(opts.licenseToken);\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"User-Agent\": opts.packageName\n ? `CopilotKit-Runtime/${opts.packageVersion ?? \"unknown\"} (${opts.packageName})`\n : \"CopilotKit-Runtime\",\n };\n if (telemetryId) {\n headers[\"X-CopilotKit-Telemetry-Id\"] = telemetryId;\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);\n try {\n await fetch(TELEMETRY_SINK_URL, {\n method: \"POST\",\n headers,\n body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n } catch {\n // Silent failure — telemetry must not break the application.\n }\n}\n\nexport const lambdaClient = { send };\n"],"mappings":";AA2BA,MAAM,qBACH,OAAO,YAAY,eAAe,QAAQ,KAAK,4BAChD;AAEF,MAAM,mBAAmB;AACzB,MAAM,uBAAuB;;;;;;;;;;;AA2B7B,SAAgB,yBACd,GAAG,YACiB;AACpB,MAAK,MAAM,aAAa,YAAY;AAClC,MAAI,cAAc,OAChB;EAGF,MAAM,aAAa,UAAU,QAAQ,oBAAoB,GAAG;AAC5D,MAAI,qBAAqB,KAAK,WAAW,CACvC,QAAO;;;AAWb,MAAM,gBAAgB,IAAI,IAAI,CAAC,wBAAwB,qBAAqB,CAAC;AAE7E,SAAS,eACP,KACyB;AACzB,KAAI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AAK,GAAG,IAAK;GAClC,CAAC;EAEF,MAAM,cACJ,yBAAyB,KAAK,YAAY,IAC1C,4BAA4B,KAAK,aAAa;EAChD,MAAM,UAAkC;GACtC,gBAAgB;GAChB,cAAc,KAAK,cACf,sBAAsB,KAAK,kBAAkB,UAAU,IAAI,KAAK,YAAY,KAC5E;GACL;AACD,MAAI,YACF,SAAQ,+BAA+B;EAGzC,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,YAAY,iBAAiB,WAAW,OAAO,EAAE,iBAAiB;AACxE,MAAI;AACF,SAAM,MAAM,oBAAoB;IAC9B,QAAQ;IACR;IACA;IACA,QAAQ,WAAW;IACpB,CAAC;YACM;AACR,gBAAa,UAAU;;SAEnB;;AAKV,MAAa,eAAe,EAAE,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/shared",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"valibot": "^1.2.0",
|
|
57
57
|
"vitest": "^3.2.4",
|
|
58
58
|
"zod": "^4.2.0",
|
|
59
|
-
"
|
|
59
|
+
"@copilotkit/typescript-config": "1.55.0-next.8"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@ag-ui/core": "^1.0.2"
|
package/src/a2ui-envelope.ts
CHANGED
|
@@ -283,7 +283,8 @@ export function readCopilotKitUIEnvelope(forwardedProps: unknown) {
|
|
|
283
283
|
*/
|
|
284
284
|
export function envelopeToManifest(envelope: CopilotKitUIEnvelope) {
|
|
285
285
|
const { supportedCatalogIds, inlineCatalogs } = envelope["v1.0"];
|
|
286
|
-
|
|
286
|
+
// `readCopilotKitUIEnvelope` only accepts a non-empty `supportedCatalogIds`.
|
|
287
|
+
const catalogId = supportedCatalogIds[0]!;
|
|
287
288
|
const catalog = inlineCatalogs?.find(
|
|
288
289
|
(entry) => entry.catalogId === catalogId,
|
|
289
290
|
);
|
|
@@ -107,7 +107,8 @@ export function collectChildRefs(schema: GenerativeUIJSONSchema): ChildRef[] {
|
|
|
107
107
|
);
|
|
108
108
|
const key = (ref: ChildRef) =>
|
|
109
109
|
`${ref.kind}\u0000${ref.path.join("\u0000")}`;
|
|
110
|
-
|
|
110
|
+
// `list` is not empty (checked above), so `perVariant` is not empty.
|
|
111
|
+
const shared = perVariant[0]!.filter((ref) =>
|
|
111
112
|
perVariant.every((refs) => refs.some((r) => key(r) === key(ref))),
|
|
112
113
|
);
|
|
113
114
|
shared.forEach((ref) => add([...path, ...ref.path], ref.kind));
|
|
@@ -146,8 +147,8 @@ export function childIdsAtRefs(
|
|
|
146
147
|
}
|
|
147
148
|
};
|
|
148
149
|
const visit = (value: unknown, path: readonly string[]) => {
|
|
149
|
-
if (path.length === 0) return collect(value);
|
|
150
150
|
const [head, ...rest] = path;
|
|
151
|
+
if (head === undefined) return collect(value);
|
|
151
152
|
if (head === "*") {
|
|
152
153
|
if (Array.isArray(value)) value.forEach((item) => visit(item, rest));
|
|
153
154
|
return;
|
|
@@ -173,8 +174,8 @@ export function hasBoundChildRef(
|
|
|
173
174
|
isRecord(value) && ("@path" in value || "@call" in value);
|
|
174
175
|
const visit = (value: unknown, path: readonly string[]): boolean => {
|
|
175
176
|
if (isDynamic(value)) return true;
|
|
176
|
-
if (path.length === 0) return false;
|
|
177
177
|
const [head, ...rest] = path;
|
|
178
|
+
if (head === undefined) return false;
|
|
178
179
|
if (head === "*") {
|
|
179
180
|
return Array.isArray(value) && value.some((item) => visit(item, rest));
|
|
180
181
|
}
|
|
@@ -197,8 +198,8 @@ export function mapAtChildRef(
|
|
|
197
198
|
path: readonly string[],
|
|
198
199
|
replace: (found: unknown) => unknown,
|
|
199
200
|
): unknown {
|
|
200
|
-
if (path.length === 0) return replace(value);
|
|
201
201
|
const [head, ...rest] = path;
|
|
202
|
+
if (head === undefined) return replace(value);
|
|
202
203
|
if (head === "*") {
|
|
203
204
|
if (!Array.isArray(value)) return value;
|
|
204
205
|
return value.map((item) => mapAtChildRef(item, rest, replace));
|
|
@@ -328,7 +328,10 @@ export function applyDescriptionOverrides<
|
|
|
328
328
|
for (const [key, description] of Object.entries(overrides)) {
|
|
329
329
|
const [name, prop, ...rest] = key.split(".");
|
|
330
330
|
// Own keys only: "__proto__" must never reach Object.prototype.
|
|
331
|
-
const component =
|
|
331
|
+
const component =
|
|
332
|
+
name !== undefined && hasOwn(components, name)
|
|
333
|
+
? components[name]
|
|
334
|
+
: undefined;
|
|
332
335
|
if (!component || rest.length > 0) {
|
|
333
336
|
unknown.push(key);
|
|
334
337
|
continue;
|
|
@@ -703,11 +703,11 @@ function childRefProblem(
|
|
|
703
703
|
// A bound or computed value, at the reference or above it, is known
|
|
704
704
|
// only at render.
|
|
705
705
|
if (isDynamic(value)) return undefined;
|
|
706
|
-
|
|
706
|
+
const [head, ...rest] = steps;
|
|
707
|
+
if (head === undefined) {
|
|
707
708
|
const reason = slotProblem(value, ref.kind, ownId);
|
|
708
709
|
return reason ? `${label}: ${reason}` : undefined;
|
|
709
710
|
}
|
|
710
|
-
const [head, ...rest] = steps;
|
|
711
711
|
if (head === "*") {
|
|
712
712
|
if (!Array.isArray(value)) return undefined;
|
|
713
713
|
for (const item of value) {
|
|
@@ -109,7 +109,11 @@ export function parseTelemetryIdFromLicense(token?: string): string | null {
|
|
|
109
109
|
if (parts.length !== 3) return null;
|
|
110
110
|
try {
|
|
111
111
|
const payload = parts[1];
|
|
112
|
-
if (
|
|
112
|
+
if (
|
|
113
|
+
payload === undefined ||
|
|
114
|
+
!/^[A-Za-z0-9_-]+$/.test(payload) ||
|
|
115
|
+
payload.length % 4 === 1
|
|
116
|
+
) {
|
|
113
117
|
return null;
|
|
114
118
|
}
|
|
115
119
|
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "@copilotkit/typescript-config/base.json",
|
|
3
3
|
"include": ["."],
|
|
4
4
|
"compilerOptions": {
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
5
7
|
"target": "es2017",
|
|
6
8
|
"lib": ["es2017", "dom"],
|
|
7
9
|
"resolveJsonModule": true
|