@copilotkit/shared 2.0.0-rc.4 → 2.0.0-rc.6

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.
Files changed (67) hide show
  1. package/dist/index.cjs +0 -13
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +3 -5
  4. package/dist/index.d.cts.map +1 -1
  5. package/dist/index.d.mts +3 -5
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +3 -5
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/index.umd.js +22 -187
  10. package/dist/index.umd.js.map +1 -1
  11. package/dist/package.cjs +1 -1
  12. package/dist/package.mjs +1 -1
  13. package/dist/telemetry/telemetry-client.cjs +3 -3
  14. package/dist/telemetry/telemetry-client.cjs.map +1 -1
  15. package/dist/telemetry/telemetry-client.mjs +3 -3
  16. package/dist/telemetry/telemetry-client.mjs.map +1 -1
  17. package/dist/utils/errors.cjs +4 -42
  18. package/dist/utils/errors.cjs.map +1 -1
  19. package/dist/utils/errors.d.cts +16 -34
  20. package/dist/utils/errors.d.cts.map +1 -1
  21. package/dist/utils/errors.d.mts +16 -34
  22. package/dist/utils/errors.d.mts.map +1 -1
  23. package/dist/utils/errors.mjs +5 -41
  24. package/dist/utils/errors.mjs.map +1 -1
  25. package/dist/utils/index.cjs +0 -2
  26. package/dist/utils/index.cjs.map +1 -1
  27. package/dist/utils/index.d.cts +2 -4
  28. package/dist/utils/index.d.cts.map +1 -1
  29. package/dist/utils/index.d.mts +2 -4
  30. package/dist/utils/index.d.mts.map +1 -1
  31. package/dist/utils/index.mjs +2 -4
  32. package/dist/utils/index.mjs.map +1 -1
  33. package/dist/utils/random-id.cjs +13 -26
  34. package/dist/utils/random-id.cjs.map +1 -1
  35. package/dist/utils/random-id.d.cts +6 -3
  36. package/dist/utils/random-id.d.cts.map +1 -1
  37. package/dist/utils/random-id.d.mts +6 -3
  38. package/dist/utils/random-id.d.mts.map +1 -1
  39. package/dist/utils/random-id.mjs +14 -25
  40. package/dist/utils/random-id.mjs.map +1 -1
  41. package/package.json +3 -6
  42. package/src/telemetry/telemetry-client.ts +3 -3
  43. package/src/utils/__tests__/errors.test.ts +44 -0
  44. package/src/utils/__tests__/random-id.test.ts +37 -0
  45. package/src/utils/errors.ts +27 -85
  46. package/src/utils/index.ts +0 -2
  47. package/src/utils/random-id.ts +17 -37
  48. package/tsdown.config.ts +1 -10
  49. package/dist/utils/conditions.cjs +0 -32
  50. package/dist/utils/conditions.cjs.map +0 -1
  51. package/dist/utils/conditions.d.cts +0 -31
  52. package/dist/utils/conditions.d.cts.map +0 -1
  53. package/dist/utils/conditions.d.mts +0 -31
  54. package/dist/utils/conditions.d.mts.map +0 -1
  55. package/dist/utils/conditions.mjs +0 -31
  56. package/dist/utils/conditions.mjs.map +0 -1
  57. package/dist/utils/console-styling.cjs +0 -91
  58. package/dist/utils/console-styling.cjs.map +0 -1
  59. package/dist/utils/console-styling.d.cts +0 -65
  60. package/dist/utils/console-styling.d.cts.map +0 -1
  61. package/dist/utils/console-styling.d.mts +0 -65
  62. package/dist/utils/console-styling.d.mts.map +0 -1
  63. package/dist/utils/console-styling.mjs +0 -85
  64. package/dist/utils/console-styling.mjs.map +0 -1
  65. package/src/utils/__tests__/conditions.test.ts +0 -161
  66. package/src/utils/conditions.ts +0 -116
  67. package/src/utils/console-styling.ts +0 -126
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-rc.4";
3
+ var version = "2.0.0-rc.6";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.0.0-rc.4";
2
+ var version = "2.0.0-rc.6";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -1,9 +1,9 @@
1
1
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_random_id = require('../utils/random-id.cjs');
2
3
  const require_telemetry_disabled = require('./telemetry-disabled.cjs');
3
4
  const require_sampling = require('./sampling.cjs');
4
5
  const require_lambda_client = require('./lambda-client.cjs');
5
6
  const require_utils = require('./utils.cjs');
6
- let uuid = require("uuid");
7
7
  let _segment_analytics_node = require("@segment/analytics-node");
8
8
 
9
9
  //#region src/telemetry/telemetry-client.ts
@@ -16,7 +16,7 @@ var TelemetryClient = class {
16
16
  this.licenseTelemetryId = null;
17
17
  this.telemetryDisabled = false;
18
18
  this.segmentSampleRate = .05;
19
- this.anonymousId = `anon_${(0, uuid.v4)()}`;
19
+ this.anonymousId = `anon_${require_random_id.randomUUID()}`;
20
20
  this.packageName = packageName;
21
21
  this.packageVersion = packageVersion;
22
22
  this.telemetryDisabled = telemetryDisabled || require_telemetry_disabled.isTelemetryDisabled();
@@ -52,7 +52,7 @@ var TelemetryClient = class {
52
52
  const eventMeta = {
53
53
  telemetry_emitter: require_sampling.TELEMETRY_EMITTER_V1,
54
54
  telemetry_surface: require_sampling.TELEMETRY_SURFACE_V1,
55
- telemetry_event_id: (0, uuid.v4)()
55
+ telemetry_event_id: require_random_id.randomUUID()
56
56
  };
57
57
  const flattenedProperties = require_utils.flattenObject(properties);
58
58
  const propertiesWithGlobal = {
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-client.cjs","names":["isTelemetryDisabled","Analytics","computeSamplingMeta","UNSAMPLED_RATE","TELEMETRY_EMITTER_V1","TELEMETRY_SURFACE_V1","flattenObject","lambdaClient","firstNonBlankTelemetryId","parseAndWarnTelemetryId"],"sources":["../../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport type { AnalyticsEvents } from \"./events\";\nimport { flattenObject } from \"./utils\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport {\n firstNonBlankTelemetryId,\n lambdaClient,\n parseAndWarnTelemetryId,\n} from \"./lambda-client\";\nimport {\n computeSamplingMeta,\n TELEMETRY_EMITTER_V1,\n TELEMETRY_SURFACE_V1,\n UNSAMPLED_RATE,\n} from \"./sampling\";\nimport { isTelemetryDisabled } from \"./telemetry-disabled\";\n\nexport { isTelemetryDisabled };\n\n/** Transport identity and sampling authority resolved for one runtime. */\nexport interface TelemetryIdentity {\n telemetryId?: string;\n licenseToken?: string;\n}\n\n/** Capture-only telemetry client bound to one runtime identity. */\nexport interface TelemetryCapture {\n capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void>;\n}\n\ninterface ResolvedTelemetryIdentity {\n telemetryId: string | null;\n licenseToken: string | null;\n licenseTelemetryId: string | null;\n}\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n // EIP / Intelligence license token (Ed25519-signed JWT). The lambda\n // client decodes its payload to extract telemetry_id. Customer API\n // keys are NOT used here — they flow only into Segment.\n private licenseToken: string | null = null;\n // Standalone analytics identity. This stays separate from the effective\n // identity so legacy callers continue sending only their license token to\n // the Lambda transport.\n private telemetryId: string | null = null;\n // License-derived identity used only as sampling authority. A standalone\n // telemetry id remains a transport claim and does not bypass the\n // Segment gate.\n private licenseTelemetryId: string | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n // Client-side sampling rate for anonymous events on the Segment wire\n // only. The lambda sink is ours and takes every event; Segment is\n // billed per event, so the anonymous population stays capped there.\n // Identified events (those whose license token yielded a telemetry_id)\n // bypass the gate on both wires.\n private segmentSampleRate: number = 0.05;\n private anonymousId = `anon_${uuidv4()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n // Anonymous sampling rate for the Segment wire. Named without the\n // prefix for backward compatibility; the lambda sink ignores it.\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey =\n process.env.COPILOTKIT_SEGMENT_WRITE_KEY ||\n \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendToSegment() {\n const randomNumber = Math.random();\n return randomNumber < this.segmentSampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void> {\n return this.captureWithIdentity(event, properties, {\n telemetryId: this.telemetryId,\n licenseToken: this.licenseToken,\n licenseTelemetryId: this.licenseTelemetryId,\n });\n }\n\n private async captureWithIdentity<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n identity: ResolvedTelemetryIdentity,\n ): Promise<void> {\n // Re-read the environment: an opt-out set after import (for example a\n // dotenv call below the imports) must still stop events.\n if (this.telemetryDisabled || isTelemetryDisabled()) {\n return;\n }\n\n // The two wires are gated separately. The lambda sink takes every\n // event: it is CopilotKit-owned, so anonymous volume costs nothing\n // per event there and a real count beats one extrapolated from 5% of\n // the population. Segment is billed per event, so it keeps the gate —\n // callers without license-derived sampling authority are dropped from\n // that copy at segmentSampleRate. Legacy license tokens with a\n // telemetry_id send on both wires: the volume is bounded by\n // paying-customer count and full fidelity per identified customer is\n // worth the marginal cost.\n const sendToSegment =\n Boolean(identity.licenseTelemetryId) || this.shouldSendToSegment();\n\n // Sampling metadata is computed in ./sampling so this client and the\n // v2 runtime client can't drift apart again — see the note there.\n // One call per wire, because the two wires were gated differently and\n // a shared block would overweight the lambda copy by 1/sampleRate.\n const lambdaSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: UNSAMPLED_RATE,\n });\n const segmentSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.segmentSampleRate,\n });\n\n // Everything below travels identically on both copies of this event.\n // The event id is what makes the dual-write dedupable downstream:\n // one capture() produces one id, stamped on the lambda copy and the\n // Segment copy alike, so consumers no longer have to infer the\n // duplication from $lib or from which fields happen to be present\n // (OSS-1019).\n const eventMeta = {\n telemetry_emitter: TELEMETRY_EMITTER_V1,\n telemetry_surface: TELEMETRY_SURFACE_V1,\n telemetry_event_id: uuidv4(),\n };\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal: Record<string, any> = {\n ...this.globalProperties,\n ...eventMeta,\n ...segmentSamplingMeta,\n telemetry_transport: \"segment\",\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n await lambdaClient.send({\n event,\n properties: flattenedProperties,\n globalProperties: {\n ...this.globalProperties,\n ...eventMeta,\n ...lambdaSamplingMeta,\n telemetry_transport: \"lambda\",\n },\n packageName: this.packageName,\n packageVersion: this.packageVersion,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\n });\n\n if (this.segment && sendToSegment) {\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n /**\n * Atomically configure standalone, legacy, or anonymous telemetry identity.\n *\n * A standalone id takes transport precedence over a supplied legacy license\n * token, but only a license-derived id grants sampling authority. Neither\n * value is added to event properties.\n *\n * @param identity - One standalone id, one legacy license token, or neither.\n */\n setTelemetryIdentity(identity: {\n telemetryId?: string;\n licenseToken?: string;\n }): void {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n this.telemetryId = resolvedIdentity.telemetryId;\n this.licenseToken = resolvedIdentity.licenseToken;\n this.licenseTelemetryId = resolvedIdentity.licenseTelemetryId;\n }\n\n /**\n * Configure legacy license-derived telemetry identity.\n *\n * @param licenseToken - License token whose telemetry claim identifies sends.\n */\n setLicenseToken(licenseToken: string) {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /**\n * Create an immutable capture scope for one runtime.\n *\n * The scope shares this client's sinks, process-wide opt-out, global\n * properties, and Segment sampling rate, but snapshots transport identity and\n * license-derived sampling authority. Constructing another runtime cannot\n * rewrite an existing scope.\n *\n * @param identity - The runtime's construction-time telemetry identity.\n * @returns A capture-only client bound to that identity.\n */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n\n return {\n capture: <K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ) => this.captureWithIdentity(event, properties, resolvedIdentity),\n };\n }\n\n private resolveTelemetryIdentity(\n identity: TelemetryIdentity,\n ): ResolvedTelemetryIdentity {\n const telemetryId = firstNonBlankTelemetryId(identity.telemetryId);\n if (telemetryId !== undefined) {\n return {\n telemetryId,\n licenseToken: null,\n licenseTelemetryId: null,\n };\n }\n\n return {\n telemetryId: null,\n licenseToken: identity.licenseToken ?? null,\n licenseTelemetryId: identity.licenseToken\n ? parseAndWarnTelemetryId(identity.licenseToken)\n : null,\n };\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n // Number.isNaN guards against parseFloat(\"nonsense\") slipping past the\n // range check (all NaN comparisons are false), which would silently\n // drop every anonymous Segment event with no signal.\n if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.segmentSampleRate = _sampleRate;\n // Per-event sampling metadata (sampleRate/sampleRateAdjustmentFactor/\n // sampleWeight) is computed per capture() in ./sampling, once per\n // wire. Only license-authorized events get effectiveSampleRate=1 on\n // the Segment copy; standalone transport identity stays in the\n // sampled population there. The lambda copy is always unsampled.\n }\n}\n"],"mappings":";;;;;;;;;AAuCA,IAAa,kBAAb,MAA6B;CA2B3B,YAAY,EACV,aACA,gBACA,mBACA,kBACA,cASC;0BAvCqC,EAAE;4BAC6B;sBAIjC;qBAID;4BAIO;2BAGP;2BAMD;qBACd,sBAAgB;AAiBpC,OAAK,cAAc;AACnB,OAAK,iBAAiB;AACtB,OAAK,oBAAoB,qBAAqBA,gDAAqB;AAEnE,MAAI,KAAK,kBACP;AAGF,OAAK,cAAc,WAAW;AAO9B,OAAK,UAAU,IAAIC,kCAAU,EAC3B,UAJA,QAAQ,IAAI,gCACZ,oCAID,CAAC;AAEF,OAAK,oBAAoB;GACvB,2BAA2B;GAC3B,8BAA8B;GAC/B,CAAC;;CAGJ,AAAQ,sBAAsB;AAE5B,SADqB,KAAK,QAAQ,GACZ,KAAK;;CAG7B,MAAM,QACJ,OACA,YACe;AACf,SAAO,KAAK,oBAAoB,OAAO,YAAY;GACjD,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB,oBAAoB,KAAK;GAC1B,CAAC;;CAGJ,MAAc,oBACZ,OACA,YACA,UACe;AAGf,MAAI,KAAK,qBAAqBD,gDAAqB,CACjD;EAYF,MAAM,gBACJ,QAAQ,SAAS,mBAAmB,IAAI,KAAK,qBAAqB;EAMpE,MAAM,qBAAqBE,qCAAoB;GAC7C,aAAa,SAAS;GACtB,YAAYC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;CAc7C,YAAY,UAA+C;EACzD,MAAM,mBAAmB,KAAK,yBAAyB,SAAS;AAEhE,SAAO,EACL,UACE,OACA,eACG,KAAK,oBAAoB,OAAO,YAAY,iBAAiB,EACnE;;CAGH,AAAQ,yBACN,UAC2B;EAC3B,MAAM,cAAcE,+CAAyB,SAAS,YAAY;AAClE,MAAI,gBAAgB,OAClB,QAAO;GACL;GACA,cAAc;GACd,oBAAoB;GACrB;AAGH,SAAO;GACL,aAAa;GACb,cAAc,SAAS,gBAAgB;GACvC,oBAAoB,SAAS,eACzBC,8CAAwB,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAG5B,MAAI,QAAQ,IAAI,iCAEd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,oBAAoB"}
1
+ {"version":3,"file":"telemetry-client.cjs","names":["randomUUID","isTelemetryDisabled","Analytics","computeSamplingMeta","UNSAMPLED_RATE","TELEMETRY_EMITTER_V1","TELEMETRY_SURFACE_V1","flattenObject","lambdaClient","firstNonBlankTelemetryId","parseAndWarnTelemetryId"],"sources":["../../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport type { AnalyticsEvents } from \"./events\";\nimport { flattenObject } from \"./utils\";\nimport { randomUUID } from \"../utils/random-id\";\nimport {\n firstNonBlankTelemetryId,\n lambdaClient,\n parseAndWarnTelemetryId,\n} from \"./lambda-client\";\nimport {\n computeSamplingMeta,\n TELEMETRY_EMITTER_V1,\n TELEMETRY_SURFACE_V1,\n UNSAMPLED_RATE,\n} from \"./sampling\";\nimport { isTelemetryDisabled } from \"./telemetry-disabled\";\n\nexport { isTelemetryDisabled };\n\n/** Transport identity and sampling authority resolved for one runtime. */\nexport interface TelemetryIdentity {\n telemetryId?: string;\n licenseToken?: string;\n}\n\n/** Capture-only telemetry client bound to one runtime identity. */\nexport interface TelemetryCapture {\n capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void>;\n}\n\ninterface ResolvedTelemetryIdentity {\n telemetryId: string | null;\n licenseToken: string | null;\n licenseTelemetryId: string | null;\n}\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n // EIP / Intelligence license token (Ed25519-signed JWT). The lambda\n // client decodes its payload to extract telemetry_id. Customer API\n // keys are NOT used here — they flow only into Segment.\n private licenseToken: string | null = null;\n // Standalone analytics identity. This stays separate from the effective\n // identity so legacy callers continue sending only their license token to\n // the Lambda transport.\n private telemetryId: string | null = null;\n // License-derived identity used only as sampling authority. A standalone\n // telemetry id remains a transport claim and does not bypass the\n // Segment gate.\n private licenseTelemetryId: string | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n // Client-side sampling rate for anonymous events on the Segment wire\n // only. The lambda sink is ours and takes every event; Segment is\n // billed per event, so the anonymous population stays capped there.\n // Identified events (those whose license token yielded a telemetry_id)\n // bypass the gate on both wires.\n private segmentSampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n // Anonymous sampling rate for the Segment wire. Named without the\n // prefix for backward compatibility; the lambda sink ignores it.\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey =\n process.env.COPILOTKIT_SEGMENT_WRITE_KEY ||\n \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendToSegment() {\n const randomNumber = Math.random();\n return randomNumber < this.segmentSampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void> {\n return this.captureWithIdentity(event, properties, {\n telemetryId: this.telemetryId,\n licenseToken: this.licenseToken,\n licenseTelemetryId: this.licenseTelemetryId,\n });\n }\n\n private async captureWithIdentity<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n identity: ResolvedTelemetryIdentity,\n ): Promise<void> {\n // Re-read the environment: an opt-out set after import (for example a\n // dotenv call below the imports) must still stop events.\n if (this.telemetryDisabled || isTelemetryDisabled()) {\n return;\n }\n\n // The two wires are gated separately. The lambda sink takes every\n // event: it is CopilotKit-owned, so anonymous volume costs nothing\n // per event there and a real count beats one extrapolated from 5% of\n // the population. Segment is billed per event, so it keeps the gate —\n // callers without license-derived sampling authority are dropped from\n // that copy at segmentSampleRate. Legacy license tokens with a\n // telemetry_id send on both wires: the volume is bounded by\n // paying-customer count and full fidelity per identified customer is\n // worth the marginal cost.\n const sendToSegment =\n Boolean(identity.licenseTelemetryId) || this.shouldSendToSegment();\n\n // Sampling metadata is computed in ./sampling so this client and the\n // v2 runtime client can't drift apart again — see the note there.\n // One call per wire, because the two wires were gated differently and\n // a shared block would overweight the lambda copy by 1/sampleRate.\n const lambdaSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: UNSAMPLED_RATE,\n });\n const segmentSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.segmentSampleRate,\n });\n\n // Everything below travels identically on both copies of this event.\n // The event id is what makes the dual-write dedupable downstream:\n // one capture() produces one id, stamped on the lambda copy and the\n // Segment copy alike, so consumers no longer have to infer the\n // duplication from $lib or from which fields happen to be present\n // (OSS-1019).\n const eventMeta = {\n telemetry_emitter: TELEMETRY_EMITTER_V1,\n telemetry_surface: TELEMETRY_SURFACE_V1,\n telemetry_event_id: randomUUID(),\n };\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal: Record<string, any> = {\n ...this.globalProperties,\n ...eventMeta,\n ...segmentSamplingMeta,\n telemetry_transport: \"segment\",\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n await lambdaClient.send({\n event,\n properties: flattenedProperties,\n globalProperties: {\n ...this.globalProperties,\n ...eventMeta,\n ...lambdaSamplingMeta,\n telemetry_transport: \"lambda\",\n },\n packageName: this.packageName,\n packageVersion: this.packageVersion,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\n });\n\n if (this.segment && sendToSegment) {\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n /**\n * Atomically configure standalone, legacy, or anonymous telemetry identity.\n *\n * A standalone id takes transport precedence over a supplied legacy license\n * token, but only a license-derived id grants sampling authority. Neither\n * value is added to event properties.\n *\n * @param identity - One standalone id, one legacy license token, or neither.\n */\n setTelemetryIdentity(identity: {\n telemetryId?: string;\n licenseToken?: string;\n }): void {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n this.telemetryId = resolvedIdentity.telemetryId;\n this.licenseToken = resolvedIdentity.licenseToken;\n this.licenseTelemetryId = resolvedIdentity.licenseTelemetryId;\n }\n\n /**\n * Configure legacy license-derived telemetry identity.\n *\n * @param licenseToken - License token whose telemetry claim identifies sends.\n */\n setLicenseToken(licenseToken: string) {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /**\n * Create an immutable capture scope for one runtime.\n *\n * The scope shares this client's sinks, process-wide opt-out, global\n * properties, and Segment sampling rate, but snapshots transport identity and\n * license-derived sampling authority. Constructing another runtime cannot\n * rewrite an existing scope.\n *\n * @param identity - The runtime's construction-time telemetry identity.\n * @returns A capture-only client bound to that identity.\n */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n\n return {\n capture: <K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ) => this.captureWithIdentity(event, properties, resolvedIdentity),\n };\n }\n\n private resolveTelemetryIdentity(\n identity: TelemetryIdentity,\n ): ResolvedTelemetryIdentity {\n const telemetryId = firstNonBlankTelemetryId(identity.telemetryId);\n if (telemetryId !== undefined) {\n return {\n telemetryId,\n licenseToken: null,\n licenseTelemetryId: null,\n };\n }\n\n return {\n telemetryId: null,\n licenseToken: identity.licenseToken ?? null,\n licenseTelemetryId: identity.licenseToken\n ? parseAndWarnTelemetryId(identity.licenseToken)\n : null,\n };\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n // Number.isNaN guards against parseFloat(\"nonsense\") slipping past the\n // range check (all NaN comparisons are false), which would silently\n // drop every anonymous Segment event with no signal.\n if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.segmentSampleRate = _sampleRate;\n // Per-event sampling metadata (sampleRate/sampleRateAdjustmentFactor/\n // sampleWeight) is computed per capture() in ./sampling, once per\n // wire. Only license-authorized events get effectiveSampleRate=1 on\n // the Segment copy; standalone transport identity stays in the\n // sampled population there. The lambda copy is always unsampled.\n }\n}\n"],"mappings":";;;;;;;;;AAuCA,IAAa,kBAAb,MAA6B;CA2B3B,YAAY,EACV,aACA,gBACA,mBACA,kBACA,cASC;0BAvCqC,EAAE;4BAC6B;sBAIjC;qBAID;4BAIO;2BAGP;2BAMD;qBACd,QAAQA,8BAAY;AAiBxC,OAAK,cAAc;AACnB,OAAK,iBAAiB;AACtB,OAAK,oBAAoB,qBAAqBC,gDAAqB;AAEnE,MAAI,KAAK,kBACP;AAGF,OAAK,cAAc,WAAW;AAO9B,OAAK,UAAU,IAAIC,kCAAU,EAC3B,UAJA,QAAQ,IAAI,gCACZ,oCAID,CAAC;AAEF,OAAK,oBAAoB;GACvB,2BAA2B;GAC3B,8BAA8B;GAC/B,CAAC;;CAGJ,AAAQ,sBAAsB;AAE5B,SADqB,KAAK,QAAQ,GACZ,KAAK;;CAG7B,MAAM,QACJ,OACA,YACe;AACf,SAAO,KAAK,oBAAoB,OAAO,YAAY;GACjD,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB,oBAAoB,KAAK;GAC1B,CAAC;;CAGJ,MAAc,oBACZ,OACA,YACA,UACe;AAGf,MAAI,KAAK,qBAAqBD,gDAAqB,CACjD;EAYF,MAAM,gBACJ,QAAQ,SAAS,mBAAmB,IAAI,KAAK,qBAAqB;EAMpE,MAAM,qBAAqBE,qCAAoB;GAC7C,aAAa,SAAS;GACtB,YAAYC;GACb,CAAC;EACF,MAAM,sBAAsBD,qCAAoB;GAC9C,aAAa,SAAS;GACtB,YAAY,KAAK;GAClB,CAAC;EAQF,MAAM,YAAY;GAChB,mBAAmBE;GACnB,mBAAmBC;GACnB,oBAAoBN,8B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yBACN,UAC2B;EAC3B,MAAM,cAAcE,+CAAyB,SAAS,YAAY;AAClE,MAAI,gBAAgB,OAClB,QAAO;GACL;GACA,cAAc;GACd,oBAAoB;GACrB;AAGH,SAAO;GACL,aAAa;GACb,cAAc,SAAS,gBAAgB;GACvC,oBAAoB,SAAS,eACzBC,8CAAwB,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAG5B,MAAI,QAAQ,IAAI,iCAEd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,oBAAoB"}
@@ -1,8 +1,8 @@
1
+ import { randomUUID } from "../utils/random-id.mjs";
1
2
  import { isTelemetryDisabled } from "./telemetry-disabled.mjs";
2
3
  import { TELEMETRY_EMITTER_V1, TELEMETRY_SURFACE_V1, UNSAMPLED_RATE, computeSamplingMeta } from "./sampling.mjs";
3
4
  import { firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId } from "./lambda-client.mjs";
4
5
  import { flattenObject } from "./utils.mjs";
5
- import { v4 } from "uuid";
6
6
  import { Analytics } from "@segment/analytics-node";
7
7
 
8
8
  //#region src/telemetry/telemetry-client.ts
@@ -15,7 +15,7 @@ var TelemetryClient = class {
15
15
  this.licenseTelemetryId = null;
16
16
  this.telemetryDisabled = false;
17
17
  this.segmentSampleRate = .05;
18
- this.anonymousId = `anon_${v4()}`;
18
+ this.anonymousId = `anon_${randomUUID()}`;
19
19
  this.packageName = packageName;
20
20
  this.packageVersion = packageVersion;
21
21
  this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();
@@ -51,7 +51,7 @@ var TelemetryClient = class {
51
51
  const eventMeta = {
52
52
  telemetry_emitter: TELEMETRY_EMITTER_V1,
53
53
  telemetry_surface: TELEMETRY_SURFACE_V1,
54
- telemetry_event_id: v4()
54
+ telemetry_event_id: randomUUID()
55
55
  };
56
56
  const flattenedProperties = flattenObject(properties);
57
57
  const propertiesWithGlobal = {
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-client.mjs","names":["uuidv4"],"sources":["../../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport type { AnalyticsEvents } from \"./events\";\nimport { flattenObject } from \"./utils\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport {\n firstNonBlankTelemetryId,\n lambdaClient,\n parseAndWarnTelemetryId,\n} from \"./lambda-client\";\nimport {\n computeSamplingMeta,\n TELEMETRY_EMITTER_V1,\n TELEMETRY_SURFACE_V1,\n UNSAMPLED_RATE,\n} from \"./sampling\";\nimport { isTelemetryDisabled } from \"./telemetry-disabled\";\n\nexport { isTelemetryDisabled };\n\n/** Transport identity and sampling authority resolved for one runtime. */\nexport interface TelemetryIdentity {\n telemetryId?: string;\n licenseToken?: string;\n}\n\n/** Capture-only telemetry client bound to one runtime identity. */\nexport interface TelemetryCapture {\n capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void>;\n}\n\ninterface ResolvedTelemetryIdentity {\n telemetryId: string | null;\n licenseToken: string | null;\n licenseTelemetryId: string | null;\n}\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n // EIP / Intelligence license token (Ed25519-signed JWT). The lambda\n // client decodes its payload to extract telemetry_id. Customer API\n // keys are NOT used here — they flow only into Segment.\n private licenseToken: string | null = null;\n // Standalone analytics identity. This stays separate from the effective\n // identity so legacy callers continue sending only their license token to\n // the Lambda transport.\n private telemetryId: string | null = null;\n // License-derived identity used only as sampling authority. A standalone\n // telemetry id remains a transport claim and does not bypass the\n // Segment gate.\n private licenseTelemetryId: string | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n // Client-side sampling rate for anonymous events on the Segment wire\n // only. The lambda sink is ours and takes every event; Segment is\n // billed per event, so the anonymous population stays capped there.\n // Identified events (those whose license token yielded a telemetry_id)\n // bypass the gate on both wires.\n private segmentSampleRate: number = 0.05;\n private anonymousId = `anon_${uuidv4()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n // Anonymous sampling rate for the Segment wire. Named without the\n // prefix for backward compatibility; the lambda sink ignores it.\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey =\n process.env.COPILOTKIT_SEGMENT_WRITE_KEY ||\n \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendToSegment() {\n const randomNumber = Math.random();\n return randomNumber < this.segmentSampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void> {\n return this.captureWithIdentity(event, properties, {\n telemetryId: this.telemetryId,\n licenseToken: this.licenseToken,\n licenseTelemetryId: this.licenseTelemetryId,\n });\n }\n\n private async captureWithIdentity<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n identity: ResolvedTelemetryIdentity,\n ): Promise<void> {\n // Re-read the environment: an opt-out set after import (for example a\n // dotenv call below the imports) must still stop events.\n if (this.telemetryDisabled || isTelemetryDisabled()) {\n return;\n }\n\n // The two wires are gated separately. The lambda sink takes every\n // event: it is CopilotKit-owned, so anonymous volume costs nothing\n // per event there and a real count beats one extrapolated from 5% of\n // the population. Segment is billed per event, so it keeps the gate —\n // callers without license-derived sampling authority are dropped from\n // that copy at segmentSampleRate. Legacy license tokens with a\n // telemetry_id send on both wires: the volume is bounded by\n // paying-customer count and full fidelity per identified customer is\n // worth the marginal cost.\n const sendToSegment =\n Boolean(identity.licenseTelemetryId) || this.shouldSendToSegment();\n\n // Sampling metadata is computed in ./sampling so this client and the\n // v2 runtime client can't drift apart again — see the note there.\n // One call per wire, because the two wires were gated differently and\n // a shared block would overweight the lambda copy by 1/sampleRate.\n const lambdaSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: UNSAMPLED_RATE,\n });\n const segmentSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.segmentSampleRate,\n });\n\n // Everything below travels identically on both copies of this event.\n // The event id is what makes the dual-write dedupable downstream:\n // one capture() produces one id, stamped on the lambda copy and the\n // Segment copy alike, so consumers no longer have to infer the\n // duplication from $lib or from which fields happen to be present\n // (OSS-1019).\n const eventMeta = {\n telemetry_emitter: TELEMETRY_EMITTER_V1,\n telemetry_surface: TELEMETRY_SURFACE_V1,\n telemetry_event_id: uuidv4(),\n };\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal: Record<string, any> = {\n ...this.globalProperties,\n ...eventMeta,\n ...segmentSamplingMeta,\n telemetry_transport: \"segment\",\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n await lambdaClient.send({\n event,\n properties: flattenedProperties,\n globalProperties: {\n ...this.globalProperties,\n ...eventMeta,\n ...lambdaSamplingMeta,\n telemetry_transport: \"lambda\",\n },\n packageName: this.packageName,\n packageVersion: this.packageVersion,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\n });\n\n if (this.segment && sendToSegment) {\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n /**\n * Atomically configure standalone, legacy, or anonymous telemetry identity.\n *\n * A standalone id takes transport precedence over a supplied legacy license\n * token, but only a license-derived id grants sampling authority. Neither\n * value is added to event properties.\n *\n * @param identity - One standalone id, one legacy license token, or neither.\n */\n setTelemetryIdentity(identity: {\n telemetryId?: string;\n licenseToken?: string;\n }): void {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n this.telemetryId = resolvedIdentity.telemetryId;\n this.licenseToken = resolvedIdentity.licenseToken;\n this.licenseTelemetryId = resolvedIdentity.licenseTelemetryId;\n }\n\n /**\n * Configure legacy license-derived telemetry identity.\n *\n * @param licenseToken - License token whose telemetry claim identifies sends.\n */\n setLicenseToken(licenseToken: string) {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /**\n * Create an immutable capture scope for one runtime.\n *\n * The scope shares this client's sinks, process-wide opt-out, global\n * properties, and Segment sampling rate, but snapshots transport identity and\n * license-derived sampling authority. Constructing another runtime cannot\n * rewrite an existing scope.\n *\n * @param identity - The runtime's construction-time telemetry identity.\n * @returns A capture-only client bound to that identity.\n */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n\n return {\n capture: <K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ) => this.captureWithIdentity(event, properties, resolvedIdentity),\n };\n }\n\n private resolveTelemetryIdentity(\n identity: TelemetryIdentity,\n ): ResolvedTelemetryIdentity {\n const telemetryId = firstNonBlankTelemetryId(identity.telemetryId);\n if (telemetryId !== undefined) {\n return {\n telemetryId,\n licenseToken: null,\n licenseTelemetryId: null,\n };\n }\n\n return {\n telemetryId: null,\n licenseToken: identity.licenseToken ?? null,\n licenseTelemetryId: identity.licenseToken\n ? parseAndWarnTelemetryId(identity.licenseToken)\n : null,\n };\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n // Number.isNaN guards against parseFloat(\"nonsense\") slipping past the\n // range check (all NaN comparisons are false), which would silently\n // drop every anonymous Segment event with no signal.\n if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.segmentSampleRate = _sampleRate;\n // Per-event sampling metadata (sampleRate/sampleRateAdjustmentFactor/\n // sampleWeight) is computed per capture() in ./sampling, once per\n // wire. Only license-authorized events get effectiveSampleRate=1 on\n // the Segment copy; standalone transport identity stays in the\n // sampled population there. The lambda copy is always unsampled.\n }\n}\n"],"mappings":";;;;;;;;AAuCA,IAAa,kBAAb,MAA6B;CA2B3B,YAAY,EACV,aACA,gBACA,mBACA,kBACA,cASC;0BAvCqC,EAAE;4BAC6B;sBAIjC;qBAID;4BAIO;2BAGP;2BAMD;qBACd,QAAQA,IAAQ;AAiBpC,OAAK,cAAc;AACnB,OAAK,iBAAiB;AACtB,OAAK,oBAAoB,qBAAqB,qBAAqB;AAEnE,MAAI,KAAK,kBACP;AAGF,OAAK,cAAc,WAAW;AAO9B,OAAK,UAAU,IAAI,UAAU,EAC3B,UAJA,QAAQ,IAAI,gCACZ,oCAID,CAAC;AAEF,OAAK,oBAAoB;GACvB,2BAA2B;GAC3B,8BAA8B;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AmB;GACtB,GAAG,KAAK;GACR,GAAG;GACJ;;CAGH,sBAAsB,YAAuD;AAC3E,OAAK,qBAAqB;AAE1B,OAAK,oBAAoB,EACvB,OAAO;GACL,cAAc,WAAW;GACzB,SAAS,WAAW;GACrB,EACF,CAAC;;;;;;;;;;;CAYJ,qBAAqB,UAGZ;EACP,MAAM,mBAAmB,KAAK,yBAAyB,SAAS;AAChE,OAAK,cAAc,iBAAiB;AACpC,OAAK,eAAe,iBAAiB;AACrC,OAAK,qBAAqB,iBAAiB;;;;;;;CAQ7C,gBAAgB,cAAsB;AACpC,OAAK,qBAAqB,EAAE,cAAc,CAAC;;;;;;;;;;;;;CAc7C,YAAY,UAA+C;EACzD,MAAM,mBAAmB,KAAK,yBAAyB,SAAS;AAEhE,SAAO,EACL,UACE,OACA,eACG,KAAK,oBAAoB,OAAO,YAAY,iBAAiB,EACnE;;CAGH,AAAQ,yBACN,UAC2B;EAC3B,MAAM,cAAc,yBAAyB,SAAS,YAAY;AAClE,MAAI,gBAAgB,OAClB,QAAO;GACL;GACA,cAAc;GACd,oBAAoB;GACrB;AAGH,SAAO;GACL,aAAa;GACb,cAAc,SAAS,gBAAgB;GACvC,oBAAoB,SAAS,eACzB,wBAAwB,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAG5B,MAAI,QAAQ,IAAI,iCAEd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,oBAAoB"}
1
+ {"version":3,"file":"telemetry-client.mjs","names":[],"sources":["../../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport type { AnalyticsEvents } from \"./events\";\nimport { flattenObject } from \"./utils\";\nimport { randomUUID } from \"../utils/random-id\";\nimport {\n firstNonBlankTelemetryId,\n lambdaClient,\n parseAndWarnTelemetryId,\n} from \"./lambda-client\";\nimport {\n computeSamplingMeta,\n TELEMETRY_EMITTER_V1,\n TELEMETRY_SURFACE_V1,\n UNSAMPLED_RATE,\n} from \"./sampling\";\nimport { isTelemetryDisabled } from \"./telemetry-disabled\";\n\nexport { isTelemetryDisabled };\n\n/** Transport identity and sampling authority resolved for one runtime. */\nexport interface TelemetryIdentity {\n telemetryId?: string;\n licenseToken?: string;\n}\n\n/** Capture-only telemetry client bound to one runtime identity. */\nexport interface TelemetryCapture {\n capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void>;\n}\n\ninterface ResolvedTelemetryIdentity {\n telemetryId: string | null;\n licenseToken: string | null;\n licenseTelemetryId: string | null;\n}\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n // EIP / Intelligence license token (Ed25519-signed JWT). The lambda\n // client decodes its payload to extract telemetry_id. Customer API\n // keys are NOT used here — they flow only into Segment.\n private licenseToken: string | null = null;\n // Standalone analytics identity. This stays separate from the effective\n // identity so legacy callers continue sending only their license token to\n // the Lambda transport.\n private telemetryId: string | null = null;\n // License-derived identity used only as sampling authority. A standalone\n // telemetry id remains a transport claim and does not bypass the\n // Segment gate.\n private licenseTelemetryId: string | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n // Client-side sampling rate for anonymous events on the Segment wire\n // only. The lambda sink is ours and takes every event; Segment is\n // billed per event, so the anonymous population stays capped there.\n // Identified events (those whose license token yielded a telemetry_id)\n // bypass the gate on both wires.\n private segmentSampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n // Anonymous sampling rate for the Segment wire. Named without the\n // prefix for backward compatibility; the lambda sink ignores it.\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey =\n process.env.COPILOTKIT_SEGMENT_WRITE_KEY ||\n \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendToSegment() {\n const randomNumber = Math.random();\n return randomNumber < this.segmentSampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ): Promise<void> {\n return this.captureWithIdentity(event, properties, {\n telemetryId: this.telemetryId,\n licenseToken: this.licenseToken,\n licenseTelemetryId: this.licenseTelemetryId,\n });\n }\n\n private async captureWithIdentity<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n identity: ResolvedTelemetryIdentity,\n ): Promise<void> {\n // Re-read the environment: an opt-out set after import (for example a\n // dotenv call below the imports) must still stop events.\n if (this.telemetryDisabled || isTelemetryDisabled()) {\n return;\n }\n\n // The two wires are gated separately. The lambda sink takes every\n // event: it is CopilotKit-owned, so anonymous volume costs nothing\n // per event there and a real count beats one extrapolated from 5% of\n // the population. Segment is billed per event, so it keeps the gate —\n // callers without license-derived sampling authority are dropped from\n // that copy at segmentSampleRate. Legacy license tokens with a\n // telemetry_id send on both wires: the volume is bounded by\n // paying-customer count and full fidelity per identified customer is\n // worth the marginal cost.\n const sendToSegment =\n Boolean(identity.licenseTelemetryId) || this.shouldSendToSegment();\n\n // Sampling metadata is computed in ./sampling so this client and the\n // v2 runtime client can't drift apart again — see the note there.\n // One call per wire, because the two wires were gated differently and\n // a shared block would overweight the lambda copy by 1/sampleRate.\n const lambdaSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: UNSAMPLED_RATE,\n });\n const segmentSamplingMeta = computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.segmentSampleRate,\n });\n\n // Everything below travels identically on both copies of this event.\n // The event id is what makes the dual-write dedupable downstream:\n // one capture() produces one id, stamped on the lambda copy and the\n // Segment copy alike, so consumers no longer have to infer the\n // duplication from $lib or from which fields happen to be present\n // (OSS-1019).\n const eventMeta = {\n telemetry_emitter: TELEMETRY_EMITTER_V1,\n telemetry_surface: TELEMETRY_SURFACE_V1,\n telemetry_event_id: randomUUID(),\n };\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal: Record<string, any> = {\n ...this.globalProperties,\n ...eventMeta,\n ...segmentSamplingMeta,\n telemetry_transport: \"segment\",\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n await lambdaClient.send({\n event,\n properties: flattenedProperties,\n globalProperties: {\n ...this.globalProperties,\n ...eventMeta,\n ...lambdaSamplingMeta,\n telemetry_transport: \"lambda\",\n },\n packageName: this.packageName,\n packageVersion: this.packageVersion,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\n });\n\n if (this.segment && sendToSegment) {\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n /**\n * Atomically configure standalone, legacy, or anonymous telemetry identity.\n *\n * A standalone id takes transport precedence over a supplied legacy license\n * token, but only a license-derived id grants sampling authority. Neither\n * value is added to event properties.\n *\n * @param identity - One standalone id, one legacy license token, or neither.\n */\n setTelemetryIdentity(identity: {\n telemetryId?: string;\n licenseToken?: string;\n }): void {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n this.telemetryId = resolvedIdentity.telemetryId;\n this.licenseToken = resolvedIdentity.licenseToken;\n this.licenseTelemetryId = resolvedIdentity.licenseTelemetryId;\n }\n\n /**\n * Configure legacy license-derived telemetry identity.\n *\n * @param licenseToken - License token whose telemetry claim identifies sends.\n */\n setLicenseToken(licenseToken: string) {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /**\n * Create an immutable capture scope for one runtime.\n *\n * The scope shares this client's sinks, process-wide opt-out, global\n * properties, and Segment sampling rate, but snapshots transport identity and\n * license-derived sampling authority. Constructing another runtime cannot\n * rewrite an existing scope.\n *\n * @param identity - The runtime's construction-time telemetry identity.\n * @returns A capture-only client bound to that identity.\n */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\n\n return {\n capture: <K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ) => this.captureWithIdentity(event, properties, resolvedIdentity),\n };\n }\n\n private resolveTelemetryIdentity(\n identity: TelemetryIdentity,\n ): ResolvedTelemetryIdentity {\n const telemetryId = firstNonBlankTelemetryId(identity.telemetryId);\n if (telemetryId !== undefined) {\n return {\n telemetryId,\n licenseToken: null,\n licenseTelemetryId: null,\n };\n }\n\n return {\n telemetryId: null,\n licenseToken: identity.licenseToken ?? null,\n licenseTelemetryId: identity.licenseToken\n ? parseAndWarnTelemetryId(identity.licenseToken)\n : null,\n };\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n // Number.isNaN guards against parseFloat(\"nonsense\") slipping past the\n // range check (all NaN comparisons are false), which would silently\n // drop every anonymous Segment event with no signal.\n if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.segmentSampleRate = _sampleRate;\n // Per-event sampling metadata (sampleRate/sampleRateAdjustmentFactor/\n // sampleWeight) is computed per capture() in ./sampling, once per\n // wire. Only license-authorized events get effectiveSampleRate=1 on\n // the Segment copy; standalone transport identity stays in the\n // sampled population there. The lambda copy is always unsampled.\n }\n}\n"],"mappings":";;;;;;;;AAuCA,IAAa,kBAAb,MAA6B;CA2B3B,YAAY,EACV,aACA,gBACA,mBACA,kBACA,cASC;0BAvCqC,EAAE;4BAC6B;sBAIjC;qBAID;4BAIO;2BAGP;2BAMD;qBACd,QAAQ,YAAY;AAiBxC,OAAK,cAAc;AACnB,OAAK,iBAAiB;AACtB,OAAK,oBAAoB,qBAAqB,qBAAqB;AAEnE,MAAI,KAAK,kBACP;AAGF,OAAK,cAAc,WAAW;AAO9B,OAAK,UAAU,IAAI,UAAU,EAC3B,UAJA,QAAQ,IAAI,gCACZ,oCAID,CAAC;AAEF,OAAK,oBAAoB;GACvB,2BAA2B;GAC3B,8BAA8B;GAC/B,CAAC;;CAGJ,AAAQ,sBAAsB;AAE5B,SADqB,KAAK,QAAQ,GACZ,KAAK;;CAG7B,MAAM,QACJ,OACA,YACe;AACf,SAAO,KAAK,oBAAoB,OAAO,YAAY;GACjD,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB,oBAAoB,KAAK;GAC1B,CAAC;;CAGJ,MAAc,oBACZ,OACA,YACA,UACe;AAGf,MAAI,KAAK,qBAAqB,qBAAqB,CACjD;EAYF,MAAM,gBACJ,QAAQ,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AAiB;;;;;;;CAQ7C,gBAAgB,cAAsB;AACpC,OAAK,qBAAqB,EAAE,cAAc,CAAC;;;;;;;;;;;;;CAc7C,YAAY,UAA+C;EACzD,MAAM,mBAAmB,KAAK,yBAAyB,SAAS;AAEhE,SAAO,EACL,UACE,OACA,eACG,KAAK,oBAAoB,OAAO,YAAY,iBAAiB,EACnE;;CAGH,AAAQ,yBACN,UAC2B;EAC3B,MAAM,cAAc,yBAAyB,SAAS,YAAY;AAClE,MAAI,gBAAgB,OAClB,QAAO;GACL;GACA,cAAc;GACd,oBAAoB;GACrB;AAGH,SAAO;GACL,aAAa;GACb,cAAc,SAAS,gBAAgB;GACvC,oBAAoB,SAAS,eACzB,wBAAwB,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAG5B,MAAI,QAAQ,IAAI,iCAEd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,oBAAoB"}
@@ -1,6 +1,3 @@
1
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
- const require_index = require('../index.cjs');
3
- let graphql = require("graphql");
4
1
 
5
2
  //#region src/utils/errors.ts
6
3
  let Severity = /* @__PURE__ */ function(Severity) {
@@ -22,7 +19,6 @@ const ERROR_NAMES = {
22
19
  COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
23
20
  COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
24
21
  COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
25
- COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
26
22
  RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
27
23
  CONFIGURATION_ERROR: "ConfigurationError",
28
24
  MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
@@ -127,14 +123,15 @@ const ERROR_CONFIG = {
127
123
  severity: Severity.INFO
128
124
  }
129
125
  };
130
- var CopilotKitError = class extends graphql.GraphQLError {
126
+ var CopilotKitError = class extends Error {
131
127
  constructor({ message = "Unknown error occurred", code, severity, visibility }) {
132
128
  const name = ERROR_NAMES.COPILOT_ERROR;
133
129
  const config = ERROR_CONFIG[code];
134
130
  const { statusCode } = config;
135
131
  const resolvedVisibility = visibility ?? config.visibility ?? ErrorVisibility.TOAST;
136
132
  const resolvedSeverity = severity ?? ("severity" in config ? config.severity : void 0);
137
- super(message, { extensions: {
133
+ super(message);
134
+ this.extensions = {
138
135
  name,
139
136
  statusCode,
140
137
  code,
@@ -145,7 +142,7 @@ var CopilotKitError = class extends graphql.GraphQLError {
145
142
  message,
146
143
  stack: (/* @__PURE__ */ new Error()).stack
147
144
  }
148
- } });
145
+ };
149
146
  this.code = code;
150
147
  this.name = name;
151
148
  this.statusCode = statusCode;
@@ -170,26 +167,6 @@ var CopilotKitMisuseError = class extends CopilotKitError {
170
167
  this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
171
168
  }
172
169
  };
173
- const getVersionMismatchErrorMessage = ({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
174
- /**
175
- * Error thrown when CPK versions does not match
176
- *
177
- * @extends CopilotKitError
178
- */
179
- var CopilotKitVersionMismatchError = class extends CopilotKitError {
180
- constructor({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) {
181
- const code = CopilotKitErrorCode.VERSION_MISMATCH;
182
- super({
183
- message: getVersionMismatchErrorMessage({
184
- reactCoreVersion,
185
- runtimeVersion,
186
- runtimeClientGqlVersion
187
- }),
188
- code
189
- });
190
- this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
191
- }
192
- };
193
170
  /**
194
171
  * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
195
172
  * This typically occurs when:
@@ -377,19 +354,6 @@ function isStructuredCopilotKitError(error) {
377
354
  function ensureStructuredError(error, converter) {
378
355
  return isStructuredCopilotKitError(error) ? error : converter(error);
379
356
  }
380
- async function getPossibleVersionMismatch({ runtimeVersion, runtimeClientGqlVersion }) {
381
- if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion) return;
382
- if (require_index.COPILOTKIT_VERSION !== runtimeVersion || require_index.COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) return {
383
- runtimeVersion,
384
- runtimeClientGqlVersion,
385
- reactCoreVersion: require_index.COPILOTKIT_VERSION,
386
- message: getVersionMismatchErrorMessage({
387
- runtimeVersion,
388
- runtimeClientGqlVersion,
389
- reactCoreVersion: require_index.COPILOTKIT_VERSION
390
- })
391
- };
392
- }
393
357
  const resolveLowLevelErrorMessage = ({ errorCode, url }) => {
394
358
  const troubleshootingLink = ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;
395
359
  const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
@@ -425,7 +389,6 @@ exports.CopilotKitErrorCode = CopilotKitErrorCode;
425
389
  exports.CopilotKitLowLevelError = CopilotKitLowLevelError;
426
390
  exports.CopilotKitMisuseError = CopilotKitMisuseError;
427
391
  exports.CopilotKitRemoteEndpointDiscoveryError = CopilotKitRemoteEndpointDiscoveryError;
428
- exports.CopilotKitVersionMismatchError = CopilotKitVersionMismatchError;
429
392
  exports.ERROR_CONFIG = ERROR_CONFIG;
430
393
  exports.ERROR_NAMES = ERROR_NAMES;
431
394
  exports.ErrorVisibility = ErrorVisibility;
@@ -434,6 +397,5 @@ exports.ResolvedCopilotKitError = ResolvedCopilotKitError;
434
397
  exports.Severity = Severity;
435
398
  exports.UpgradeRequiredError = UpgradeRequiredError;
436
399
  exports.ensureStructuredError = ensureStructuredError;
437
- exports.getPossibleVersionMismatch = getPossibleVersionMismatch;
438
400
  exports.isStructuredCopilotKitError = isStructuredCopilotKitError;
439
401
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":["GraphQLError","COPILOTKIT_VERSION"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["import { GraphQLError } from \"graphql\";\nimport { COPILOTKIT_VERSION } from \"../index\";\n\nexport enum Severity {\n CRITICAL = \"critical\", // Critical errors that block core functionality\n WARNING = \"warning\", // Configuration/setup issues that need attention\n INFO = \"info\", // General errors and network issues\n}\n\nexport enum ErrorVisibility {\n BANNER = \"banner\", // Critical errors shown as fixed banners\n TOAST = \"toast\", // Regular errors shown as dismissible toasts\n SILENT = \"silent\", // Errors logged but not shown to user\n DEV_ONLY = \"dev_only\", // Errors only shown in development mode\n}\n\nexport const ERROR_NAMES = {\n COPILOT_ERROR: \"CopilotError\",\n COPILOT_API_DISCOVERY_ERROR: \"CopilotApiDiscoveryError\",\n COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR:\n \"CopilotKitRemoteEndpointDiscoveryError\",\n COPILOT_KIT_AGENT_DISCOVERY_ERROR: \"CopilotKitAgentDiscoveryError\",\n COPILOT_KIT_LOW_LEVEL_ERROR: \"CopilotKitLowLevelError\",\n COPILOT_KIT_VERSION_MISMATCH_ERROR: \"CopilotKitVersionMismatchError\",\n RESOLVED_COPILOT_KIT_ERROR: \"ResolvedCopilotKitError\",\n CONFIGURATION_ERROR: \"ConfigurationError\",\n MISSING_PUBLIC_API_KEY_ERROR: \"MissingPublicApiKeyError\",\n UPGRADE_REQUIRED_ERROR: \"UpgradeRequiredError\",\n} as const;\n\n// Banner errors - critical configuration/discovery issues\nexport const BANNER_ERROR_NAMES = [\n ERROR_NAMES.CONFIGURATION_ERROR,\n ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,\n ERROR_NAMES.UPGRADE_REQUIRED_ERROR,\n ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR,\n];\n\n// Legacy cloud error names for backward compatibility\nexport const COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;\n\nexport enum CopilotKitErrorCode {\n NETWORK_ERROR = \"NETWORK_ERROR\",\n NOT_FOUND = \"NOT_FOUND\",\n AGENT_NOT_FOUND = \"AGENT_NOT_FOUND\",\n API_NOT_FOUND = \"API_NOT_FOUND\",\n REMOTE_ENDPOINT_NOT_FOUND = \"REMOTE_ENDPOINT_NOT_FOUND\",\n AUTHENTICATION_ERROR = \"AUTHENTICATION_ERROR\",\n MISUSE = \"MISUSE\",\n UNKNOWN = \"UNKNOWN\",\n VERSION_MISMATCH = \"VERSION_MISMATCH\",\n CONFIGURATION_ERROR = \"CONFIGURATION_ERROR\",\n MISSING_PUBLIC_API_KEY_ERROR = \"MISSING_PUBLIC_API_KEY_ERROR\",\n UPGRADE_REQUIRED_ERROR = \"UPGRADE_REQUIRED_ERROR\",\n}\n\nconst BASE_URL = \"https://docs.copilotkit.ai\";\n\nconst getSeeMoreMarkdown = (link: string) => `See more: [${link}](${link})`;\n\nexport const ERROR_CONFIG = {\n [CopilotKitErrorCode.NETWORK_ERROR]: {\n statusCode: 503,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#network-errors-api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#network-errors-api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AGENT_NOT_FOUND]: {\n statusCode: 500,\n troubleshootingUrl: `${BASE_URL}/langgraph-python/coagent-troubleshooting/common-coagent-issues#i-am-getting-agent-not-found-error`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.API_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#network-errors-api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#remote-endpoint-not-found-error`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AUTHENTICATION_ERROR]: {\n statusCode: 401,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.MISUSE]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.WARNING,\n },\n [CopilotKitErrorCode.UNKNOWN]: {\n statusCode: 500,\n visibility: ErrorVisibility.TOAST,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.CONFIGURATION_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.CRITICAL,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR]: {\n statusCode: 402,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.VERSION_MISMATCH]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.INFO,\n },\n};\n\nexport class CopilotKitError extends GraphQLError {\n code: CopilotKitErrorCode;\n statusCode: number;\n severity?: Severity;\n visibility: ErrorVisibility;\n\n constructor({\n message = \"Unknown error occurred\",\n code,\n severity,\n visibility,\n }: {\n message?: string;\n code: CopilotKitErrorCode;\n severity?: Severity;\n visibility?: ErrorVisibility;\n }) {\n const name = ERROR_NAMES.COPILOT_ERROR;\n const config = ERROR_CONFIG[code];\n const { statusCode } = config;\n const resolvedVisibility =\n visibility ?? config.visibility ?? ErrorVisibility.TOAST;\n const resolvedSeverity =\n severity ?? (\"severity\" in config ? config.severity : undefined);\n\n super(message, {\n extensions: {\n name,\n statusCode,\n code,\n visibility: resolvedVisibility,\n severity: resolvedSeverity,\n troubleshootingUrl:\n \"troubleshootingUrl\" in config ? config.troubleshootingUrl : null,\n originalError: {\n message,\n stack: new Error().stack,\n },\n },\n });\n\n this.code = code;\n this.name = name;\n this.statusCode = statusCode;\n this.severity = resolvedSeverity;\n this.visibility = resolvedVisibility;\n }\n}\n\n/**\n * Error thrown when we can identify wrong usage of our components.\n * This helps us notify the developer before real errors can happen\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitMisuseError extends CopilotKitError {\n constructor({\n message,\n code = CopilotKitErrorCode.MISUSE,\n }: {\n message: string;\n code?: CopilotKitErrorCode;\n }) {\n const docsLink =\n \"troubleshootingUrl\" in ERROR_CONFIG[code] &&\n ERROR_CONFIG[code].troubleshootingUrl\n ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl as string)\n : null;\n const finalMessage = docsLink ? `${message}.\\n\\n${docsLink}` : message;\n super({ message: finalMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\nconst getVersionMismatchErrorMessage = ({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n}: VersionMismatchResponse) =>\n `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? \"\"} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;\n/**\n * Error thrown when CPK versions does not match\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitVersionMismatchError extends CopilotKitError {\n constructor({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n }: VersionMismatchResponse) {\n const code = CopilotKitErrorCode.VERSION_MISMATCH;\n super({\n message: getVersionMismatchErrorMessage({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n }),\n code,\n });\n this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;\n }\n}\n\n/**\n * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n * - There are network/firewall issues preventing access\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitApiDiscoveryError extends CopilotKitError {\n constructor(\n params: {\n message?: string;\n code?:\n | CopilotKitErrorCode.API_NOT_FOUND\n | CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n url?: string;\n } = {},\n ) {\n const url = params.url ?? \"\";\n let operationSuffix = \"\";\n if (url?.includes(\"/info\"))\n operationSuffix = `when fetching CopilotKit info`;\n else if (url.includes(\"/actions/execute\"))\n operationSuffix = `when attempting to execute actions.`;\n else if (url.includes(\"/agents/state\"))\n operationSuffix = `when attempting to get agent state.`;\n else if (url.includes(\"/agents/execute\"))\n operationSuffix = `when attempting to execute agent(s).`;\n const message =\n params.message ??\n (params.url\n ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}`\n : `Failed to find CopilotKit API endpoint.`);\n const code = params.code ?? CopilotKitErrorCode.API_NOT_FOUND;\n const errorMessage = `${message}.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;\n super({ message: errorMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\n/**\n * This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n *\n * @extends CopilotKitApiDiscoveryError\n */\nexport class CopilotKitRemoteEndpointDiscoveryError extends CopilotKitApiDiscoveryError {\n constructor(params?: { message?: string; url?: string }) {\n const message =\n params?.message ??\n (params?.url\n ? `Failed to find or contact remote endpoint at url ${params.url}`\n : \"Failed to find or contact remote endpoint\");\n const code = CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Error thrown when a LangGraph agent cannot be found or accessed.\n * This typically occurs when:\n * - The specified agent name does not exist in the deployment\n * - The agent configuration is invalid or missing\n * - The agent service is not properly deployed or initialized\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitAgentDiscoveryError extends CopilotKitError {\n constructor(params: {\n agentName?: string;\n availableAgents: { name: string; id: string }[];\n }) {\n const { agentName, availableAgents } = params;\n const code = CopilotKitErrorCode.AGENT_NOT_FOUND;\n\n const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);\n let message;\n\n if (availableAgents.length) {\n const agentList = availableAgents.map((agent) => agent.name).join(\", \");\n\n if (agentName) {\n message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n } else {\n message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n }\n } else {\n message = `${agentName ? `Agent '${agentName}'` : \"The requested agent\"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;\n }\n\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Handles low-level networking errors that occur before a request reaches the server.\n * These errors arise from issues in the underlying communication infrastructure rather than\n * application-level logic or server responses. Typically used to handle \"fetch failed\" errors\n * where no HTTP status code is available.\n *\n * Common scenarios include:\n * - Connection failures (ECONNREFUSED) when server is down/unreachable\n * - DNS resolution failures (ENOTFOUND) when domain can't be resolved\n * - Timeouts (ETIMEDOUT) when request takes too long\n * - Protocol/transport layer errors like SSL/TLS issues\n */\nexport class CopilotKitLowLevelError extends CopilotKitError {\n constructor({\n error,\n url,\n message,\n }: {\n error: Error;\n url: string;\n message?: string;\n }) {\n let code = CopilotKitErrorCode.NETWORK_ERROR;\n\n // @ts-expect-error -- code may exist\n const errorCode = error.code as string;\n const errorMessage =\n message ?? resolveLowLevelErrorMessage({ errorCode, url });\n\n super({ message: errorMessage, code });\n\n this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;\n }\n}\n\n/**\n * Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.\n * Used when we receive an HTTP error status and wish to handle broad range of them\n *\n * This differs from CopilotKitLowLevelError in that:\n * - ResolvedCopilotKitError: Server was reached and returned an HTTP status\n * - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)\n *\n * @param status - The HTTP status code received from the API response\n * @param message - Optional error message to include\n * @param code - Optional specific CopilotKitErrorCode to override default behavior\n *\n * Default behavior:\n * - 400 Bad Request: Maps to CopilotKitApiDiscoveryError\n * - All other status codes: Maps to UNKNOWN error code if no specific code provided\n */\nexport class ResolvedCopilotKitError extends CopilotKitError {\n constructor({\n status,\n message,\n code,\n isRemoteEndpoint,\n url,\n }: {\n status: number;\n message?: string;\n code?: CopilotKitErrorCode;\n isRemoteEndpoint?: boolean;\n url?: string;\n }) {\n let resolvedCode = code;\n if (!resolvedCode) {\n switch (status) {\n case 400:\n throw new CopilotKitApiDiscoveryError({ message, url });\n case 404:\n throw isRemoteEndpoint\n ? new CopilotKitRemoteEndpointDiscoveryError({ message, url })\n : new CopilotKitApiDiscoveryError({ message, url });\n default:\n resolvedCode = CopilotKitErrorCode.UNKNOWN;\n break;\n }\n }\n\n super({ message, code: resolvedCode });\n this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;\n }\n}\n\nexport class ConfigurationError extends CopilotKitError {\n constructor(message: string) {\n super({ message, code: CopilotKitErrorCode.CONFIGURATION_ERROR });\n this.name = ERROR_NAMES.CONFIGURATION_ERROR;\n this.severity = Severity.WARNING;\n }\n}\n\nexport class MissingPublicApiKeyError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;\n this.severity = Severity.CRITICAL;\n }\n}\n\nexport class UpgradeRequiredError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;\n this.severity = Severity.WARNING;\n }\n}\n\n/**\n * Checks if an error is already a structured CopilotKit error.\n * This utility centralizes the logic for detecting structured errors across the codebase.\n *\n * @param error - The error to check\n * @returns true if the error is already structured, false otherwise\n */\nexport function isStructuredCopilotKitError(error: any): boolean {\n return (\n error instanceof CopilotKitError ||\n error instanceof CopilotKitLowLevelError ||\n (error?.name && error.name.includes(\"CopilotKit\")) ||\n error?.extensions?.code !== undefined // Check if it has our structured error properties\n );\n}\n\n/**\n * Returns the error as-is if it's already structured, otherwise converts it using the provided converter function.\n * This utility centralizes the pattern of preserving structured errors while converting unstructured ones.\n *\n * @param error - The error to process\n * @param converter - Function to convert unstructured errors to structured ones\n * @returns The structured error\n */\nexport function ensureStructuredError<T extends CopilotKitError>(\n error: any,\n converter: (error: any) => T,\n): T | any {\n return isStructuredCopilotKitError(error) ? error : converter(error);\n}\n\ninterface VersionMismatchResponse {\n runtimeVersion?: string;\n runtimeClientGqlVersion: string;\n reactCoreVersion: string;\n}\n\nexport async function getPossibleVersionMismatch({\n runtimeVersion,\n runtimeClientGqlVersion,\n}: {\n runtimeVersion?: string;\n runtimeClientGqlVersion: string;\n}) {\n if (!runtimeVersion || runtimeVersion === \"\" || !runtimeClientGqlVersion)\n return;\n if (\n COPILOTKIT_VERSION !== runtimeVersion ||\n COPILOTKIT_VERSION !== runtimeClientGqlVersion ||\n runtimeVersion !== runtimeClientGqlVersion\n ) {\n return {\n runtimeVersion,\n runtimeClientGqlVersion,\n reactCoreVersion: COPILOTKIT_VERSION,\n message: getVersionMismatchErrorMessage({\n runtimeVersion,\n runtimeClientGqlVersion,\n reactCoreVersion: COPILOTKIT_VERSION,\n }),\n };\n }\n\n return;\n}\n\nconst resolveLowLevelErrorMessage = ({\n errorCode,\n url,\n}: {\n errorCode?: string;\n url: string;\n}) => {\n const troubleshootingLink =\n ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;\n const genericMessage = (\n description = `Failed to fetch from url ${url}.`,\n ) => `${description}.\n\nPossible reasons:\n- -The server may have an error preventing it from returning a response (Check the server logs for more info).\n- -The server might be down or unreachable\n- -There might be a network issue (e.g., DNS failure, connection timeout) \n- -The URL might be incorrect\n- -The server is not running on the specified port\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n\n if (url.includes(\"/info\"))\n return genericMessage(\n `Failed to fetch CopilotKit agents/action information from url ${url}.`,\n );\n if (url.includes(\"/actions/execute\"))\n return genericMessage(`Fetch call to ${url} to execute actions failed.`);\n if (url.includes(\"/agents/state\"))\n return genericMessage(`Fetch call to ${url} to get agent state failed.`);\n if (url.includes(\"/agents/execute\"))\n return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);\n\n switch (errorCode) {\n case \"ECONNREFUSED\":\n return `Connection to ${url} was refused. Ensure the server is running and accessible.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n case \"ENOTFOUND\":\n return `The server on ${url} could not be found. Check the URL or your network configuration.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;\n case \"ETIMEDOUT\":\n return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\\n\\n${getSeeMoreMarkdown(troublesh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AO,eAAe,iBAAiB,IAAI,8BAA8B;AAE3E,SAAQ,WAAR;EACE,KAAK,eACH,QAAO,iBAAiB,IAAI,gEAAgE,mBAAmB,oBAAoB;EACrI,KAAK,YACH,QAAO,iBAAiB,IAAI,uEAAuE,mBAAmB,aAAa,oBAAoB,WAAW,mBAAmB;EACvL,KAAK,YACH,QAAO,qBAAqB,IAAI,+EAA+E,mBAAmB,oBAAoB;EACxJ,QACE"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["export enum Severity {\n CRITICAL = \"critical\", // Critical errors that block core functionality\n WARNING = \"warning\", // Configuration/setup issues that need attention\n INFO = \"info\", // General errors and network issues\n}\n\nexport enum ErrorVisibility {\n BANNER = \"banner\", // Critical errors shown as fixed banners\n TOAST = \"toast\", // Regular errors shown as dismissible toasts\n SILENT = \"silent\", // Errors logged but not shown to user\n DEV_ONLY = \"dev_only\", // Errors only shown in development mode\n}\n\nexport const ERROR_NAMES = {\n COPILOT_ERROR: \"CopilotError\",\n COPILOT_API_DISCOVERY_ERROR: \"CopilotApiDiscoveryError\",\n COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR:\n \"CopilotKitRemoteEndpointDiscoveryError\",\n COPILOT_KIT_AGENT_DISCOVERY_ERROR: \"CopilotKitAgentDiscoveryError\",\n COPILOT_KIT_LOW_LEVEL_ERROR: \"CopilotKitLowLevelError\",\n RESOLVED_COPILOT_KIT_ERROR: \"ResolvedCopilotKitError\",\n CONFIGURATION_ERROR: \"ConfigurationError\",\n MISSING_PUBLIC_API_KEY_ERROR: \"MissingPublicApiKeyError\",\n UPGRADE_REQUIRED_ERROR: \"UpgradeRequiredError\",\n} as const;\n\n// Banner errors - critical configuration/discovery issues\nexport const BANNER_ERROR_NAMES = [\n ERROR_NAMES.CONFIGURATION_ERROR,\n ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,\n ERROR_NAMES.UPGRADE_REQUIRED_ERROR,\n ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR,\n];\n\n// Legacy cloud error names for backward compatibility\nexport const COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;\n\nexport enum CopilotKitErrorCode {\n NETWORK_ERROR = \"NETWORK_ERROR\",\n NOT_FOUND = \"NOT_FOUND\",\n AGENT_NOT_FOUND = \"AGENT_NOT_FOUND\",\n API_NOT_FOUND = \"API_NOT_FOUND\",\n REMOTE_ENDPOINT_NOT_FOUND = \"REMOTE_ENDPOINT_NOT_FOUND\",\n AUTHENTICATION_ERROR = \"AUTHENTICATION_ERROR\",\n MISUSE = \"MISUSE\",\n UNKNOWN = \"UNKNOWN\",\n VERSION_MISMATCH = \"VERSION_MISMATCH\",\n CONFIGURATION_ERROR = \"CONFIGURATION_ERROR\",\n MISSING_PUBLIC_API_KEY_ERROR = \"MISSING_PUBLIC_API_KEY_ERROR\",\n UPGRADE_REQUIRED_ERROR = \"UPGRADE_REQUIRED_ERROR\",\n}\n\nconst BASE_URL = \"https://docs.copilotkit.ai\";\n\nconst getSeeMoreMarkdown = (link: string) => `See more: [${link}](${link})`;\n\nexport const ERROR_CONFIG = {\n [CopilotKitErrorCode.NETWORK_ERROR]: {\n statusCode: 503,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#network-errors-api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#network-errors-api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AGENT_NOT_FOUND]: {\n statusCode: 500,\n troubleshootingUrl: `${BASE_URL}/langgraph-python/coagent-troubleshooting/common-coagent-issues#i-am-getting-agent-not-found-error`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.API_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#network-errors-api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#remote-endpoint-not-found-error`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AUTHENTICATION_ERROR]: {\n statusCode: 401,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.MISUSE]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.WARNING,\n },\n [CopilotKitErrorCode.UNKNOWN]: {\n statusCode: 500,\n visibility: ErrorVisibility.TOAST,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.CONFIGURATION_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.CRITICAL,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR]: {\n statusCode: 402,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.VERSION_MISMATCH]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.INFO,\n },\n};\n\nexport interface CopilotKitErrorExtensions {\n name: string;\n statusCode: number;\n code: CopilotKitErrorCode;\n visibility: ErrorVisibility;\n severity?: Severity;\n troubleshootingUrl: string | null;\n originalError: { message: string; stack?: string };\n}\n\nexport class CopilotKitError extends Error {\n /** Structured error details, kept in the shape GraphQL errors used in 1.x. */\n extensions: CopilotKitErrorExtensions;\n code: CopilotKitErrorCode;\n statusCode: number;\n severity?: Severity;\n visibility: ErrorVisibility;\n\n constructor({\n message = \"Unknown error occurred\",\n code,\n severity,\n visibility,\n }: {\n message?: string;\n code: CopilotKitErrorCode;\n severity?: Severity;\n visibility?: ErrorVisibility;\n }) {\n const name = ERROR_NAMES.COPILOT_ERROR;\n const config = ERROR_CONFIG[code];\n const { statusCode } = config;\n const resolvedVisibility =\n visibility ?? config.visibility ?? ErrorVisibility.TOAST;\n const resolvedSeverity =\n severity ?? (\"severity\" in config ? config.severity : undefined);\n\n super(message);\n\n this.extensions = {\n name,\n statusCode,\n code,\n visibility: resolvedVisibility,\n severity: resolvedSeverity,\n troubleshootingUrl:\n \"troubleshootingUrl\" in config ? config.troubleshootingUrl : null,\n originalError: {\n message,\n stack: new Error().stack,\n },\n };\n this.code = code;\n this.name = name;\n this.statusCode = statusCode;\n this.severity = resolvedSeverity;\n this.visibility = resolvedVisibility;\n }\n}\n\n/**\n * Error thrown when we can identify wrong usage of our components.\n * This helps us notify the developer before real errors can happen\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitMisuseError extends CopilotKitError {\n constructor({\n message,\n code = CopilotKitErrorCode.MISUSE,\n }: {\n message: string;\n code?: CopilotKitErrorCode;\n }) {\n const docsLink =\n \"troubleshootingUrl\" in ERROR_CONFIG[code] &&\n ERROR_CONFIG[code].troubleshootingUrl\n ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl as string)\n : null;\n const finalMessage = docsLink ? `${message}.\\n\\n${docsLink}` : message;\n super({ message: finalMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n * - There are network/firewall issues preventing access\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitApiDiscoveryError extends CopilotKitError {\n constructor(\n params: {\n message?: string;\n code?:\n | CopilotKitErrorCode.API_NOT_FOUND\n | CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n url?: string;\n } = {},\n ) {\n const url = params.url ?? \"\";\n let operationSuffix = \"\";\n if (url?.includes(\"/info\"))\n operationSuffix = `when fetching CopilotKit info`;\n else if (url.includes(\"/actions/execute\"))\n operationSuffix = `when attempting to execute actions.`;\n else if (url.includes(\"/agents/state\"))\n operationSuffix = `when attempting to get agent state.`;\n else if (url.includes(\"/agents/execute\"))\n operationSuffix = `when attempting to execute agent(s).`;\n const message =\n params.message ??\n (params.url\n ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}`\n : `Failed to find CopilotKit API endpoint.`);\n const code = params.code ?? CopilotKitErrorCode.API_NOT_FOUND;\n const errorMessage = `${message}.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;\n super({ message: errorMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\n/**\n * This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n *\n * @extends CopilotKitApiDiscoveryError\n */\nexport class CopilotKitRemoteEndpointDiscoveryError extends CopilotKitApiDiscoveryError {\n constructor(params?: { message?: string; url?: string }) {\n const message =\n params?.message ??\n (params?.url\n ? `Failed to find or contact remote endpoint at url ${params.url}`\n : \"Failed to find or contact remote endpoint\");\n const code = CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Error thrown when a LangGraph agent cannot be found or accessed.\n * This typically occurs when:\n * - The specified agent name does not exist in the deployment\n * - The agent configuration is invalid or missing\n * - The agent service is not properly deployed or initialized\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitAgentDiscoveryError extends CopilotKitError {\n constructor(params: {\n agentName?: string;\n availableAgents: { name: string; id: string }[];\n }) {\n const { agentName, availableAgents } = params;\n const code = CopilotKitErrorCode.AGENT_NOT_FOUND;\n\n const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);\n let message;\n\n if (availableAgents.length) {\n const agentList = availableAgents.map((agent) => agent.name).join(\", \");\n\n if (agentName) {\n message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n } else {\n message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n }\n } else {\n message = `${agentName ? `Agent '${agentName}'` : \"The requested agent\"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;\n }\n\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Handles low-level networking errors that occur before a request reaches the server.\n * These errors arise from issues in the underlying communication infrastructure rather than\n * application-level logic or server responses. Typically used to handle \"fetch failed\" errors\n * where no HTTP status code is available.\n *\n * Common scenarios include:\n * - Connection failures (ECONNREFUSED) when server is down/unreachable\n * - DNS resolution failures (ENOTFOUND) when domain can't be resolved\n * - Timeouts (ETIMEDOUT) when request takes too long\n * - Protocol/transport layer errors like SSL/TLS issues\n */\nexport class CopilotKitLowLevelError extends CopilotKitError {\n constructor({\n error,\n url,\n message,\n }: {\n error: Error;\n url: string;\n message?: string;\n }) {\n let code = CopilotKitErrorCode.NETWORK_ERROR;\n\n // @ts-expect-error -- code may exist\n const errorCode = error.code as string;\n const errorMessage =\n message ?? resolveLowLevelErrorMessage({ errorCode, url });\n\n super({ message: errorMessage, code });\n\n this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;\n }\n}\n\n/**\n * Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.\n * Used when we receive an HTTP error status and wish to handle broad range of them\n *\n * This differs from CopilotKitLowLevelError in that:\n * - ResolvedCopilotKitError: Server was reached and returned an HTTP status\n * - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)\n *\n * @param status - The HTTP status code received from the API response\n * @param message - Optional error message to include\n * @param code - Optional specific CopilotKitErrorCode to override default behavior\n *\n * Default behavior:\n * - 400 Bad Request: Maps to CopilotKitApiDiscoveryError\n * - All other status codes: Maps to UNKNOWN error code if no specific code provided\n */\nexport class ResolvedCopilotKitError extends CopilotKitError {\n constructor({\n status,\n message,\n code,\n isRemoteEndpoint,\n url,\n }: {\n status: number;\n message?: string;\n code?: CopilotKitErrorCode;\n isRemoteEndpoint?: boolean;\n url?: string;\n }) {\n let resolvedCode = code;\n if (!resolvedCode) {\n switch (status) {\n case 400:\n throw new CopilotKitApiDiscoveryError({ message, url });\n case 404:\n throw isRemoteEndpoint\n ? new CopilotKitRemoteEndpointDiscoveryError({ message, url })\n : new CopilotKitApiDiscoveryError({ message, url });\n default:\n resolvedCode = CopilotKitErrorCode.UNKNOWN;\n break;\n }\n }\n\n super({ message, code: resolvedCode });\n this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;\n }\n}\n\nexport class ConfigurationError extends CopilotKitError {\n constructor(message: string) {\n super({ message, code: CopilotKitErrorCode.CONFIGURATION_ERROR });\n this.name = ERROR_NAMES.CONFIGURATION_ERROR;\n this.severity = Severity.WARNING;\n }\n}\n\nexport class MissingPublicApiKeyError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;\n this.severity = Severity.CRITICAL;\n }\n}\n\nexport class UpgradeRequiredError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;\n this.severity = Severity.WARNING;\n }\n}\n\n/**\n * Checks if an error is already a structured CopilotKit error.\n * This utility centralizes the logic for detecting structured errors across the codebase.\n *\n * @param error - The error to check\n * @returns true if the error is already structured, false otherwise\n */\nexport function isStructuredCopilotKitError(error: any): boolean {\n return (\n error instanceof CopilotKitError ||\n error instanceof CopilotKitLowLevelError ||\n (error?.name && error.name.includes(\"CopilotKit\")) ||\n error?.extensions?.code !== undefined // Check if it has our structured error properties\n );\n}\n\n/**\n * Returns the error as-is if it's already structured, otherwise converts it using the provided converter function.\n * This utility centralizes the pattern of preserving structured errors while converting unstructured ones.\n *\n * @param error - The error to process\n * @param converter - Function to convert unstructured errors to structured ones\n * @returns The structured error\n */\nexport function ensureStructuredError<T extends CopilotKitError>(\n error: any,\n converter: (error: any) => T,\n): T | any {\n return isStructuredCopilotKitError(error) ? error : converter(error);\n}\n\nconst resolveLowLevelErrorMessage = ({\n errorCode,\n url,\n}: {\n errorCode?: string;\n url: string;\n}) => {\n const troubleshootingLink =\n ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;\n const genericMessage = (\n description = `Failed to fetch from url ${url}.`,\n ) => `${description}.\n\nPossible reasons:\n- -The server may have an error preventing it from returning a response (Check the server logs for more info).\n- -The server might be down or unreachable\n- -There might be a network issue (e.g., DNS failure, connection timeout) \n- -The URL might be incorrect\n- -The server is not running on the specified port\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n\n if (url.includes(\"/info\"))\n return genericMessage(\n `Failed to fetch CopilotKit agents/action information from url ${url}.`,\n );\n if (url.includes(\"/actions/execute\"))\n return genericMessage(`Fetch call to ${url} to execute actions failed.`);\n if (url.includes(\"/agents/state\"))\n return genericMessage(`Fetch call to ${url} to get agent state failed.`);\n if (url.includes(\"/agents/execute\"))\n return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);\n\n switch (errorCode) {\n case \"ECONNREFUSED\":\n return `Connection to ${url} was refused. Ensure the server is running and accessible.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n case \"ENOTFOUND\":\n return `The server on ${url} could not be found. Check the URL or your network configuration.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;\n case \"ETIMEDOUT\":\n return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n default:\n return;\n }\n};\n"],"mappings":";;AAAA,IAAY,8CAAL;AACL;AACA;AACA;;;AAGF,IAAY,4DAAL;AACL;AACA;AACA;AACA;;;AAGF,MAAa,cAAc;CACzB,eAAe;CACf,6BAA6B;CAC7B,yCACE;CACF,mCAAmC;CACnC,6BAA6B;CAC7B,4BAA4B;CAC5B,qBAAqB;CACrB,8BAA8B;CAC9B,wBAAwB;CACzB;AAGD,MAAa,qBAAqB;CAChC,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACb;AAGD,MAAa,4BAA4B;AAEzC,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGF,MAAM,WAAW;AAEjB,MAAM,sBAAsB,SAAiB,cAAc,KAAK,IAAI,KAAK;AAEzE,MAAa,eAAe;EACzB,oBAAoB,gBAAgB;EACnC,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,YAAY;EAC/B,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,kBAAkB;EACrC,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,gBAAgB;EACnC,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAA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
3
1
  //#region src/utils/errors.d.ts
4
2
  declare enum Severity {
5
3
  CRITICAL = "critical",
@@ -23,7 +21,6 @@ declare const ERROR_NAMES: {
23
21
  readonly COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError";
24
22
  readonly COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError";
25
23
  readonly COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError";
26
- readonly COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError";
27
24
  readonly RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError";
28
25
  readonly CONFIGURATION_ERROR: "ConfigurationError";
29
26
  readonly MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError";
@@ -118,7 +115,21 @@ declare const ERROR_CONFIG: {
118
115
  severity: Severity;
119
116
  };
120
117
  };
121
- declare class CopilotKitError extends GraphQLError {
118
+ interface CopilotKitErrorExtensions {
119
+ name: string;
120
+ statusCode: number;
121
+ code: CopilotKitErrorCode;
122
+ visibility: ErrorVisibility;
123
+ severity?: Severity;
124
+ troubleshootingUrl: string | null;
125
+ originalError: {
126
+ message: string;
127
+ stack?: string;
128
+ };
129
+ }
130
+ declare class CopilotKitError extends Error {
131
+ /** Structured error details, kept in the shape GraphQL errors used in 1.x. */
132
+ extensions: CopilotKitErrorExtensions;
122
133
  code: CopilotKitErrorCode;
123
134
  statusCode: number;
124
135
  severity?: Severity;
@@ -150,18 +161,6 @@ declare class CopilotKitMisuseError extends CopilotKitError {
150
161
  code?: CopilotKitErrorCode;
151
162
  });
152
163
  }
153
- /**
154
- * Error thrown when CPK versions does not match
155
- *
156
- * @extends CopilotKitError
157
- */
158
- declare class CopilotKitVersionMismatchError extends CopilotKitError {
159
- constructor({
160
- reactCoreVersion,
161
- runtimeVersion,
162
- runtimeClientGqlVersion
163
- }: VersionMismatchResponse);
164
- }
165
164
  /**
166
165
  * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
167
166
  * This typically occurs when:
@@ -290,23 +289,6 @@ declare function isStructuredCopilotKitError(error: any): boolean;
290
289
  * @returns The structured error
291
290
  */
292
291
  declare function ensureStructuredError<T extends CopilotKitError>(error: any, converter: (error: any) => T): T | any;
293
- interface VersionMismatchResponse {
294
- runtimeVersion?: string;
295
- runtimeClientGqlVersion: string;
296
- reactCoreVersion: string;
297
- }
298
- declare function getPossibleVersionMismatch({
299
- runtimeVersion,
300
- runtimeClientGqlVersion
301
- }: {
302
- runtimeVersion?: string;
303
- runtimeClientGqlVersion: string;
304
- }): Promise<{
305
- runtimeVersion: string;
306
- runtimeClientGqlVersion: string;
307
- reactCoreVersion: string;
308
- message: string;
309
- } | undefined>;
310
292
  //#endregion
311
- export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError };
293
+ export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitErrorExtensions, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, isStructuredCopilotKitError };
312
294
  //# sourceMappingURL=errors.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/utils/errors.ts"],"mapp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;;;;;;;cA+BS,uBAAA,SAAgC,eAAA;;IAEzC,MAAA;IACA,OAAA;IACA,IAAA;IACA,gBAAA;IACA;EAAA;IAEA,MAAA;IACA,OAAA;IACA,IAAA,GAAO,mBAAA;IACP,gBAAA;IACA,GAAA;EAAA;AAAA;AAAA,cAsBS,kBAAA,SAA2B,eAAA;cAC1B,OAAA;AAAA;AAAA,cAOD,wBAAA,SAAiC,kBAAA;cAChC,OAAA;AAAA;AAAA,cAOD,oBAAA,SAA6B,kBAAA;cAC5B,OAAA;AAAA;;;;;;;;iBAcE,2BAAA,CAA4B,KAAA;;;;;;;AA9M5C;;iBA+NgB,qBAAA,WAAgC,eAAA,CAAA,CAC9C,KAAA,OACA,SAAA,GAAY,KAAA,UAAe,CAAA,GAC1B,CAAA"}
@@ -1,5 +1,3 @@
1
- import { GraphQLError } from "graphql";
2
-
3
1
  //#region src/utils/errors.d.ts
4
2
  declare enum Severity {
5
3
  CRITICAL = "critical",
@@ -23,7 +21,6 @@ declare const ERROR_NAMES: {
23
21
  readonly COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError";
24
22
  readonly COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError";
25
23
  readonly COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError";
26
- readonly COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError";
27
24
  readonly RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError";
28
25
  readonly CONFIGURATION_ERROR: "ConfigurationError";
29
26
  readonly MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError";
@@ -118,7 +115,21 @@ declare const ERROR_CONFIG: {
118
115
  severity: Severity;
119
116
  };
120
117
  };
121
- declare class CopilotKitError extends GraphQLError {
118
+ interface CopilotKitErrorExtensions {
119
+ name: string;
120
+ statusCode: number;
121
+ code: CopilotKitErrorCode;
122
+ visibility: ErrorVisibility;
123
+ severity?: Severity;
124
+ troubleshootingUrl: string | null;
125
+ originalError: {
126
+ message: string;
127
+ stack?: string;
128
+ };
129
+ }
130
+ declare class CopilotKitError extends Error {
131
+ /** Structured error details, kept in the shape GraphQL errors used in 1.x. */
132
+ extensions: CopilotKitErrorExtensions;
122
133
  code: CopilotKitErrorCode;
123
134
  statusCode: number;
124
135
  severity?: Severity;
@@ -150,18 +161,6 @@ declare class CopilotKitMisuseError extends CopilotKitError {
150
161
  code?: CopilotKitErrorCode;
151
162
  });
152
163
  }
153
- /**
154
- * Error thrown when CPK versions does not match
155
- *
156
- * @extends CopilotKitError
157
- */
158
- declare class CopilotKitVersionMismatchError extends CopilotKitError {
159
- constructor({
160
- reactCoreVersion,
161
- runtimeVersion,
162
- runtimeClientGqlVersion
163
- }: VersionMismatchResponse);
164
- }
165
164
  /**
166
165
  * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
167
166
  * This typically occurs when:
@@ -290,23 +289,6 @@ declare function isStructuredCopilotKitError(error: any): boolean;
290
289
  * @returns The structured error
291
290
  */
292
291
  declare function ensureStructuredError<T extends CopilotKitError>(error: any, converter: (error: any) => T): T | any;
293
- interface VersionMismatchResponse {
294
- runtimeVersion?: string;
295
- runtimeClientGqlVersion: string;
296
- reactCoreVersion: string;
297
- }
298
- declare function getPossibleVersionMismatch({
299
- runtimeVersion,
300
- runtimeClientGqlVersion
301
- }: {
302
- runtimeVersion?: string;
303
- runtimeClientGqlVersion: string;
304
- }): Promise<{
305
- runtimeVersion: string;
306
- runtimeClientGqlVersion: string;
307
- reactCoreVersion: string;
308
- message: string;
309
- } | undefined>;
310
292
  //#endregion
311
- export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError };
293
+ export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitErrorExtensions, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, isStructuredCopilotKitError };
312
294
  //# sourceMappingURL=errors.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/utils/errors.ts"],"mappings":";;;aAGY,QAAA;EACV,QAAA;EAAA;EACA,OAAA;EAAA;EACA,IAAA;AAAA;AAAA,aAGU,eAAA;EACV,MAAA;EAAA;EACA,KAAA;EAAA;EACA,MAAA;EAAA;EACA,QAAA;AAAA;AAAA,cAGW,WAAA;EAAA;;;;;;;;;;;cAeA,kBAAA;AAAA,cAUA,yBAAA;AAAA,aAED,mBAAA;EACV,aAAA;EACA,SAAA;EACA,eAAA;EACA,aAAA;EACA,yBAAA;EACA,oBAAA;EACA,MAAA;EACA,OAAA;EACA,gBAAA;EACA,mBAAA;EACA,4BAAA;EACA,sBAAA;AAAA;AAAA,cAOW,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0EA,eAAA,SAAwB,YAAA;EACnC,IAAA,EAAM,mBAAA;EACN,UAAA;EACA,QAAA,GAAW,QAAA;EACX,UAAA,EAAY,eAAA;;IAGV,OAAA;IACA,IAAA;IACA,QAAA;IACA;EAAA;IAEA,OAAA;IACA,IAAA,EAAM,mBAAA;IACN,QAAA,GAAW,QAA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