@copilotkit/runtime 2.0.0-rc.2 → 2.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.cjs +14 -14
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +15 -15
- package/dist/agent/index.mjs.map +1 -1
- package/dist/agent/url-download.cjs +10 -11
- package/dist/agent/url-download.cjs.map +1 -1
- package/dist/agent/url-download.d.cts.map +1 -1
- package/dist/agent/url-download.d.mts.map +1 -1
- package/dist/agent/url-download.mjs +10 -11
- package/dist/agent/url-download.mjs.map +1 -1
- package/dist/runtime/core/channel-manager.cjs +4 -4
- package/dist/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/runtime/core/channel-manager.mjs +4 -4
- package/dist/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/runtime/core/debug-event-bus.cjs +3 -1
- package/dist/runtime/core/debug-event-bus.cjs.map +1 -1
- package/dist/runtime/core/debug-event-bus.d.cts.map +1 -1
- package/dist/runtime/core/debug-event-bus.d.mts.map +1 -1
- package/dist/runtime/core/debug-event-bus.mjs +3 -1
- package/dist/runtime/core/debug-event-bus.mjs.map +1 -1
- package/dist/runtime/core/logger.cjs +2 -1
- package/dist/runtime/core/logger.cjs.map +1 -1
- package/dist/runtime/core/logger.d.cts.map +1 -1
- package/dist/runtime/core/logger.d.mts.map +1 -1
- package/dist/runtime/core/logger.mjs +2 -1
- package/dist/runtime/core/logger.mjs.map +1 -1
- package/dist/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/core/runtime.cjs +19 -5
- package/dist/runtime/core/runtime.cjs.map +1 -1
- package/dist/runtime/core/runtime.d.cts +19 -3
- package/dist/runtime/core/runtime.d.cts.map +1 -1
- package/dist/runtime/core/runtime.d.mts +19 -3
- package/dist/runtime/core/runtime.d.mts.map +1 -1
- package/dist/runtime/core/runtime.mjs +20 -6
- package/dist/runtime/core/runtime.mjs.map +1 -1
- package/dist/runtime/core/web-crypto.cjs +22 -0
- package/dist/runtime/core/web-crypto.cjs.map +1 -0
- package/dist/runtime/core/web-crypto.mjs +20 -0
- package/dist/runtime/core/web-crypto.mjs.map +1 -0
- package/dist/runtime/handlers/get-runtime-info.cjs +7 -6
- package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.mjs +7 -6
- package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.cjs +3 -4
- package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.mjs +3 -4
- package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.cjs +1 -1
- package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.mjs +2 -2
- package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/client.cjs +1 -2
- package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/client.mjs +1 -2
- package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs +3 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.mjs +2 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +4 -5
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +4 -4
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs +3 -7
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs +3 -6
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs.map +1 -1
- package/dist/runtime/runner/intelligence.cjs +1 -2
- package/dist/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/runtime/runner/intelligence.mjs +1 -2
- package/dist/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.cjs +3 -1
- package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.mjs +3 -1
- package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.cjs +2 -2
- package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.d.cts.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.d.mts.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.mjs +3 -3
- package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-client.cjs","names":["lambdaClient","TELEMETRY_EMITTER_V2","TELEMETRY_SURFACE_V2","RUNTIME_PACKAGE_NAME","RUNTIME_PACKAGE_VERSION"],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"sourcesContent":["import type { AnalyticsEvents } from \"./events\";\nimport {\n lambdaClient,\n parseAndWarnTelemetryId,\n computeSamplingMeta,\n TELEMETRY_EMITTER_V2,\n TELEMETRY_SURFACE_V2,\n} from \"@copilotkit/shared\";\nimport {\n RUNTIME_PACKAGE_NAME,\n RUNTIME_PACKAGE_VERSION,\n} from \"../core/package-info\";\nimport { firstNonBlankTelemetryId } from \"./telemetry-identity\";\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 function isTelemetryDisabled(): boolean {\n return (\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK ===\n \"true\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n private telemetryDisabled: boolean = false;\n // Opt-down for anonymous events, defaulting to 1: the sink is ours, so a\n // real count beats one extrapolated from a fraction of the population.\n // It stays configurable because it is the cross-SDK lever for reducing or\n // stopping anonymous volume — the Go, Python, Ruby, and .NET runtimes all\n // expose it, and the cross-language conformance suite drives it to 0 to\n // assert silence. Identified callers bypass it.\n private sampleRate: number = 1;\n // EIP / Intelligence license token (Ed25519-signed JWT). Kept separate\n // from standalone identity so the transport receives only the selected\n // identity source.\n private licenseToken: string | null = null;\n // Standalone identity sent as a transport claim. It does not make an\n // event identified.\n private telemetryId: string | null = null;\n // License-derived identity. This client sends every event either way;\n // the id is what sets telemetry_identified on the sampling block, which\n // is how the two populations stay separable downstream.\n private licenseTelemetryId: string | null = null;\n // Properties merged into every event this client sends.\n //\n // For facts about the caller that are true for the whole process rather than\n // for one event: which product is embedding the runtime, for instance. A\n // distribution built on top of this can then be told apart in the existing\n // events instead of sending its own, which is the difference between one\n // extra field and a second pipeline nobody asked for.\n //\n // Sent as `global_properties`, a field of its own, so these stay separable\n // from an event's own properties all the way to the sink.\n //\n // Do not reuse a key an event already sets: the fanout spreads this bag last\n // for `oss.runtime.*`, so a collision resolves in favour of the global and\n // does so silently. Names here should describe the caller, not the call.\n private globalProperties: Record<string, unknown> = {};\n\n constructor({\n telemetryDisabled,\n sampleRate,\n }: {\n telemetryDisabled?: boolean;\n sampleRate?: number;\n } = {}) {\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n this.setSampleRate(sampleRate);\n }\n\n private shouldSendEvent() {\n if (this.sampleRate >= 1) return true;\n return Math.random() < this.sampleRate;\n }\n\n /**\n * Add properties carried by every subsequent event.\n *\n * Merged rather than replaced, so two callers setting different fields do not\n * erase each other. Set once at runtime construction in practice; nothing\n * here is per-request.\n */\n setGlobalProperties(properties: Record<string, unknown>) {\n this.globalProperties = { ...this.globalProperties, ...properties };\n }\n\n /** Atomically replace the process-wide telemetry identity. */\n setTelemetryIdentity(identity: TelemetryIdentity): 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 /** @deprecated Prefer {@link setTelemetryIdentity}. */\n setLicenseToken(licenseToken: string): void {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /** Create an immutable capture scope for one Runtime instance. */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\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 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()) return;\n // Nothing is gated at the default rate of 1. A caller who dialled it\n // down means it, and identified callers are exempt either way.\n if (!identity.licenseTelemetryId && !this.shouldSendEvent()) return;\n\n await lambdaClient.send({\n event,\n properties: properties as Record<string, unknown>,\n // Its own field on the wire rather than folded into `properties`, which\n // is what the sink expects: for `oss.runtime.*` the fanout treats\n // `global_properties` as the SDK's pass-through bag and spreads it into\n // the analytics event, and v1's client sends package name and version the\n // same way. Folding it in would work and would put a process-level fact\n // in the per-event slot, where nothing downstream expects to find one.\n // Sampling metadata rides in the same slot, as it does in v1. It\n // reads 1/1 unless a caller dialled the rate down, and is stamped\n // either way: a consumer summing sampleWeight across emitters must\n // not find the field missing on a quarter of the rows, which is the\n // state that made ~24% of runtime volume unweightable (OSS-1017).\n globalProperties: {\n ...this.globalProperties,\n ...computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.sampleRate,\n }),\n telemetry_emitter: TELEMETRY_EMITTER_V2,\n // Constant here: a v1 request never reaches this client. The v1\n // entrypoint hands its own capture scope to the V2 runtime it\n // builds, so v1 traffic is emitted by the v1 client and stamped\n // v1 there — which is also what keeps it on the Segment wire.\n telemetry_surface: TELEMETRY_SURFACE_V2,\n // This client has one transport, so the marker is constant here. It\n // is stamped anyway so the property means the same thing on every\n // event whichever client produced it (OSS-1019).\n telemetry_transport: \"lambda\",\n },\n packageName: RUNTIME_PACKAGE_NAME,\n packageVersion: RUNTIME_PACKAGE_VERSION,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\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 ?? 1;\n\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\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 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.sampleRate = _sampleRate;\n }\n}\n\nconst telemetry = new TelemetryClient();\nexport default telemetry;\n"],"mappings":";;;;;AAkCA,SAAgB,sBAA+B;AAC7C,QACG,QAAQ,IACN,kCAAkC,UACpC,QAAQ,IACN,kCAAkC,OACpC,QAAQ,IAA2C,iBAClD,UACD,QAAQ,IAA2C,iBAAiB;;AAIzE,IAAa,kBAAb,MAA6B;CAoC3B,YAAY,EACV,mBACA,eAIE,EAAE,EAAE;2BAzC6B;oBAOR;sBAIS;qBAGD;4BAIO;0BAeQ,EAAE;AASpD,OAAK,oBAAoB,qBAAqB,qBAAqB;AACnE,OAAK,cAAc,WAAW;;CAGhC,AAAQ,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SAAS,gBAAgB;GACvC,oBAAoB,SAAS,+DACD,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAE5B,MAAI,QAAQ,IAAI,iCACd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,aAAa;;;AAItB,MAAM,YAAY,IAAI,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"telemetry-client.cjs","names":["lambdaClient","TELEMETRY_EMITTER_V2","TELEMETRY_SURFACE_V2","RUNTIME_PACKAGE_NAME","RUNTIME_PACKAGE_VERSION"],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"sourcesContent":["import type { AnalyticsEvents } from \"./events\";\nimport {\n lambdaClient,\n parseAndWarnTelemetryId,\n computeSamplingMeta,\n TELEMETRY_EMITTER_V2,\n TELEMETRY_SURFACE_V2,\n processEnv,\n} from \"@copilotkit/shared\";\nimport {\n RUNTIME_PACKAGE_NAME,\n RUNTIME_PACKAGE_VERSION,\n} from \"../core/package-info\";\nimport { firstNonBlankTelemetryId } from \"./telemetry-identity\";\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 function isTelemetryDisabled(): boolean {\n return (\n processEnv().COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n processEnv().COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n processEnv().DO_NOT_TRACK === \"true\" ||\n processEnv().DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n private telemetryDisabled: boolean = false;\n // Opt-down for anonymous events, defaulting to 1: the sink is ours, so a\n // real count beats one extrapolated from a fraction of the population.\n // It stays configurable because it is the cross-SDK lever for reducing or\n // stopping anonymous volume — the Go, Python, Ruby, and .NET runtimes all\n // expose it, and the cross-language conformance suite drives it to 0 to\n // assert silence. Identified callers bypass it.\n private sampleRate: number = 1;\n // EIP / Intelligence license token (Ed25519-signed JWT). Kept separate\n // from standalone identity so the transport receives only the selected\n // identity source.\n private licenseToken: string | null = null;\n // Standalone identity sent as a transport claim. It does not make an\n // event identified.\n private telemetryId: string | null = null;\n // License-derived identity. This client sends every event either way;\n // the id is what sets telemetry_identified on the sampling block, which\n // is how the two populations stay separable downstream.\n private licenseTelemetryId: string | null = null;\n // Properties merged into every event this client sends.\n //\n // For facts about the caller that are true for the whole process rather than\n // for one event: which product is embedding the runtime, for instance. A\n // distribution built on top of this can then be told apart in the existing\n // events instead of sending its own, which is the difference between one\n // extra field and a second pipeline nobody asked for.\n //\n // Sent as `global_properties`, a field of its own, so these stay separable\n // from an event's own properties all the way to the sink.\n //\n // Do not reuse a key an event already sets: the fanout spreads this bag last\n // for `oss.runtime.*`, so a collision resolves in favour of the global and\n // does so silently. Names here should describe the caller, not the call.\n private globalProperties: Record<string, unknown> = {};\n\n constructor({\n telemetryDisabled,\n sampleRate,\n }: {\n telemetryDisabled?: boolean;\n sampleRate?: number;\n } = {}) {\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n this.setSampleRate(sampleRate);\n }\n\n private shouldSendEvent() {\n if (this.sampleRate >= 1) return true;\n return Math.random() < this.sampleRate;\n }\n\n /**\n * Add properties carried by every subsequent event.\n *\n * Merged rather than replaced, so two callers setting different fields do not\n * erase each other. Set once at runtime construction in practice; nothing\n * here is per-request.\n */\n setGlobalProperties(properties: Record<string, unknown>) {\n this.globalProperties = { ...this.globalProperties, ...properties };\n }\n\n /** Atomically replace the process-wide telemetry identity. */\n setTelemetryIdentity(identity: TelemetryIdentity): 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 /** @deprecated Prefer {@link setTelemetryIdentity}. */\n setLicenseToken(licenseToken: string): void {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /** Create an immutable capture scope for one Runtime instance. */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\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 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()) return;\n // Nothing is gated at the default rate of 1. A caller who dialled it\n // down means it, and identified callers are exempt either way.\n if (!identity.licenseTelemetryId && !this.shouldSendEvent()) return;\n\n await lambdaClient.send({\n event,\n properties: properties as Record<string, unknown>,\n // Its own field on the wire rather than folded into `properties`, which\n // is what the sink expects: for `oss.runtime.*` the fanout treats\n // `global_properties` as the SDK's pass-through bag and spreads it into\n // the analytics event, and v1's client sends package name and version the\n // same way. Folding it in would work and would put a process-level fact\n // in the per-event slot, where nothing downstream expects to find one.\n // Sampling metadata rides in the same slot, as it does in v1. It\n // reads 1/1 unless a caller dialled the rate down, and is stamped\n // either way: a consumer summing sampleWeight across emitters must\n // not find the field missing on a quarter of the rows, which is the\n // state that made ~24% of runtime volume unweightable (OSS-1017).\n globalProperties: {\n ...this.globalProperties,\n ...computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.sampleRate,\n }),\n telemetry_emitter: TELEMETRY_EMITTER_V2,\n // Constant here: a v1 request never reaches this client. The v1\n // entrypoint hands its own capture scope to the V2 runtime it\n // builds, so v1 traffic is emitted by the v1 client and stamped\n // v1 there — which is also what keeps it on the Segment wire.\n telemetry_surface: TELEMETRY_SURFACE_V2,\n // This client has one transport, so the marker is constant here. It\n // is stamped anyway so the property means the same thing on every\n // event whichever client produced it (OSS-1019).\n telemetry_transport: \"lambda\",\n },\n packageName: RUNTIME_PACKAGE_NAME,\n packageVersion: RUNTIME_PACKAGE_VERSION,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\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 ?? 1;\n\n if (processEnv().COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n _sampleRate = parseFloat(processEnv().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 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.sampleRate = _sampleRate;\n }\n}\n\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;IACR,+CAAuB;KACrB,aAAa,SAAS;KACtB,YAAY,KAAK;KAClB,CAAC;IACF,mBAAmBC;IAKnB,mBAAmBC;IAInB,qBAAqB;IACtB;GACD,aAAaC;GACb,gBAAgBC;GAChB,aAAa,SAAS,eAAe;GACrC,cAAc,SAAS,gBAAgB;GACxC,CAAC;;CAGJ,AAAQ,yBACN,UAC2B;EAC3B,MAAM,+DAAuC,SAAS,YAAY;AAClE,MAAI,gBAAgB,OAClB,QAAO;GACL;GACA,cAAc;GACd,oBAAoB;GACrB;AAGH,SAAO;GACL,aAAa;GACb,cAAc,SAAS,gBAAgB;GACvC,oBAAoB,SAAS,+DACD,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAE5B,0CAAgB,CAAC,iCACf,eAAc,+CAAuB,CAAC,iCAAiC;AAMzE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,aAAa;;;AAItB,MAAM,YAAY,IAAI,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-client.d.cts","names":[],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"telemetry-client.d.cts","names":[],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"mappings":";;;;UAsBiB,gBAAA;EACf,OAAA,iBAAwB,eAAA,EACtB,KAAA,EAAO,CAAA,EACP,UAAA,EAAY,eAAA,CAAgB,CAAA,IAC3B,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-client.d.mts","names":[],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"telemetry-client.d.mts","names":[],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"mappings":";;;;UAsBiB,gBAAA;EACf,OAAA,iBAAwB,eAAA,EACtB,KAAA,EAAO,CAAA,EACP,UAAA,EAAY,eAAA,CAAgB,CAAA,IAC3B,OAAA;AAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RUNTIME_PACKAGE_NAME, RUNTIME_PACKAGE_VERSION } from "../core/package-info.mjs";
|
|
2
2
|
import { firstNonBlankTelemetryId } from "./telemetry-identity.mjs";
|
|
3
|
-
import { TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V2, computeSamplingMeta, lambdaClient, parseAndWarnTelemetryId } from "@copilotkit/shared";
|
|
3
|
+
import { TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V2, computeSamplingMeta, lambdaClient, parseAndWarnTelemetryId, processEnv } from "@copilotkit/shared";
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/telemetry/telemetry-client.ts
|
|
6
6
|
function isTelemetryDisabled() {
|
|
7
|
-
return
|
|
7
|
+
return processEnv().COPILOTKIT_TELEMETRY_DISABLED === "true" || processEnv().COPILOTKIT_TELEMETRY_DISABLED === "1" || processEnv().DO_NOT_TRACK === "true" || processEnv().DO_NOT_TRACK === "1";
|
|
8
8
|
}
|
|
9
9
|
var TelemetryClient = class {
|
|
10
10
|
constructor({ telemetryDisabled, sampleRate } = {}) {
|
|
@@ -95,7 +95,7 @@ var TelemetryClient = class {
|
|
|
95
95
|
setSampleRate(sampleRate) {
|
|
96
96
|
let _sampleRate;
|
|
97
97
|
_sampleRate = sampleRate ?? 1;
|
|
98
|
-
if (
|
|
98
|
+
if (processEnv().COPILOTKIT_TELEMETRY_SAMPLE_RATE) _sampleRate = parseFloat(processEnv().COPILOTKIT_TELEMETRY_SAMPLE_RATE);
|
|
99
99
|
if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) throw new Error("Sample rate must be between 0 and 1");
|
|
100
100
|
this.sampleRate = _sampleRate;
|
|
101
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-client.mjs","names":[],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"sourcesContent":["import type { AnalyticsEvents } from \"./events\";\nimport {\n lambdaClient,\n parseAndWarnTelemetryId,\n computeSamplingMeta,\n TELEMETRY_EMITTER_V2,\n TELEMETRY_SURFACE_V2,\n} from \"@copilotkit/shared\";\nimport {\n RUNTIME_PACKAGE_NAME,\n RUNTIME_PACKAGE_VERSION,\n} from \"../core/package-info\";\nimport { firstNonBlankTelemetryId } from \"./telemetry-identity\";\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 function isTelemetryDisabled(): boolean {\n return (\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK ===\n \"true\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n private telemetryDisabled: boolean = false;\n // Opt-down for anonymous events, defaulting to 1: the sink is ours, so a\n // real count beats one extrapolated from a fraction of the population.\n // It stays configurable because it is the cross-SDK lever for reducing or\n // stopping anonymous volume — the Go, Python, Ruby, and .NET runtimes all\n // expose it, and the cross-language conformance suite drives it to 0 to\n // assert silence. Identified callers bypass it.\n private sampleRate: number = 1;\n // EIP / Intelligence license token (Ed25519-signed JWT). Kept separate\n // from standalone identity so the transport receives only the selected\n // identity source.\n private licenseToken: string | null = null;\n // Standalone identity sent as a transport claim. It does not make an\n // event identified.\n private telemetryId: string | null = null;\n // License-derived identity. This client sends every event either way;\n // the id is what sets telemetry_identified on the sampling block, which\n // is how the two populations stay separable downstream.\n private licenseTelemetryId: string | null = null;\n // Properties merged into every event this client sends.\n //\n // For facts about the caller that are true for the whole process rather than\n // for one event: which product is embedding the runtime, for instance. A\n // distribution built on top of this can then be told apart in the existing\n // events instead of sending its own, which is the difference between one\n // extra field and a second pipeline nobody asked for.\n //\n // Sent as `global_properties`, a field of its own, so these stay separable\n // from an event's own properties all the way to the sink.\n //\n // Do not reuse a key an event already sets: the fanout spreads this bag last\n // for `oss.runtime.*`, so a collision resolves in favour of the global and\n // does so silently. Names here should describe the caller, not the call.\n private globalProperties: Record<string, unknown> = {};\n\n constructor({\n telemetryDisabled,\n sampleRate,\n }: {\n telemetryDisabled?: boolean;\n sampleRate?: number;\n } = {}) {\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n this.setSampleRate(sampleRate);\n }\n\n private shouldSendEvent() {\n if (this.sampleRate >= 1) return true;\n return Math.random() < this.sampleRate;\n }\n\n /**\n * Add properties carried by every subsequent event.\n *\n * Merged rather than replaced, so two callers setting different fields do not\n * erase each other. Set once at runtime construction in practice; nothing\n * here is per-request.\n */\n setGlobalProperties(properties: Record<string, unknown>) {\n this.globalProperties = { ...this.globalProperties, ...properties };\n }\n\n /** Atomically replace the process-wide telemetry identity. */\n setTelemetryIdentity(identity: TelemetryIdentity): 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 /** @deprecated Prefer {@link setTelemetryIdentity}. */\n setLicenseToken(licenseToken: string): void {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /** Create an immutable capture scope for one Runtime instance. */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\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 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()) return;\n // Nothing is gated at the default rate of 1. A caller who dialled it\n // down means it, and identified callers are exempt either way.\n if (!identity.licenseTelemetryId && !this.shouldSendEvent()) return;\n\n await lambdaClient.send({\n event,\n properties: properties as Record<string, unknown>,\n // Its own field on the wire rather than folded into `properties`, which\n // is what the sink expects: for `oss.runtime.*` the fanout treats\n // `global_properties` as the SDK's pass-through bag and spreads it into\n // the analytics event, and v1's client sends package name and version the\n // same way. Folding it in would work and would put a process-level fact\n // in the per-event slot, where nothing downstream expects to find one.\n // Sampling metadata rides in the same slot, as it does in v1. It\n // reads 1/1 unless a caller dialled the rate down, and is stamped\n // either way: a consumer summing sampleWeight across emitters must\n // not find the field missing on a quarter of the rows, which is the\n // state that made ~24% of runtime volume unweightable (OSS-1017).\n globalProperties: {\n ...this.globalProperties,\n ...computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.sampleRate,\n }),\n telemetry_emitter: TELEMETRY_EMITTER_V2,\n // Constant here: a v1 request never reaches this client. The v1\n // entrypoint hands its own capture scope to the V2 runtime it\n // builds, so v1 traffic is emitted by the v1 client and stamped\n // v1 there — which is also what keeps it on the Segment wire.\n telemetry_surface: TELEMETRY_SURFACE_V2,\n // This client has one transport, so the marker is constant here. It\n // is stamped anyway so the property means the same thing on every\n // event whichever client produced it (OSS-1019).\n telemetry_transport: \"lambda\",\n },\n packageName: RUNTIME_PACKAGE_NAME,\n packageVersion: RUNTIME_PACKAGE_VERSION,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\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 ?? 1;\n\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\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 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.sampleRate = _sampleRate;\n }\n}\n\nconst telemetry = new TelemetryClient();\nexport default telemetry;\n"],"mappings":";;;;;AAkCA,SAAgB,sBAA+B;AAC7C,QACG,QAAQ,IACN,kCAAkC,UACpC,QAAQ,IACN,kCAAkC,OACpC,QAAQ,IAA2C,iBAClD,UACD,QAAQ,IAA2C,iBAAiB;;AAIzE,IAAa,kBAAb,MAA6B;CAoC3B,YAAY,EACV,mBACA,eAIE,EAAE,EAAE;2BAzC6B;oBAOR;sBAIS;qBAGD;4BAIO;0BAeQ,EAAE;AASpD,OAAK,oBAAoB,qBAAqB,qBAAqB;AACnE,OAAK,cAAc,WAAW;;CAGhC,AAAQ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,cAAc,SAAS,gBAAgB;GACvC,oBAAoB,SAAS,eACzB,wBAAwB,SAAS,aAAa,GAC9C;GACL;;CAGH,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAE5B,MAAI,QAAQ,IAAI,iCACd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,aAAa;;;AAItB,MAAM,YAAY,IAAI,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"telemetry-client.mjs","names":[],"sources":["../../../src/runtime/telemetry/telemetry-client.ts"],"sourcesContent":["import type { AnalyticsEvents } from \"./events\";\nimport {\n lambdaClient,\n parseAndWarnTelemetryId,\n computeSamplingMeta,\n TELEMETRY_EMITTER_V2,\n TELEMETRY_SURFACE_V2,\n processEnv,\n} from \"@copilotkit/shared\";\nimport {\n RUNTIME_PACKAGE_NAME,\n RUNTIME_PACKAGE_VERSION,\n} from \"../core/package-info\";\nimport { firstNonBlankTelemetryId } from \"./telemetry-identity\";\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 function isTelemetryDisabled(): boolean {\n return (\n processEnv().COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n processEnv().COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n processEnv().DO_NOT_TRACK === \"true\" ||\n processEnv().DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n private telemetryDisabled: boolean = false;\n // Opt-down for anonymous events, defaulting to 1: the sink is ours, so a\n // real count beats one extrapolated from a fraction of the population.\n // It stays configurable because it is the cross-SDK lever for reducing or\n // stopping anonymous volume — the Go, Python, Ruby, and .NET runtimes all\n // expose it, and the cross-language conformance suite drives it to 0 to\n // assert silence. Identified callers bypass it.\n private sampleRate: number = 1;\n // EIP / Intelligence license token (Ed25519-signed JWT). Kept separate\n // from standalone identity so the transport receives only the selected\n // identity source.\n private licenseToken: string | null = null;\n // Standalone identity sent as a transport claim. It does not make an\n // event identified.\n private telemetryId: string | null = null;\n // License-derived identity. This client sends every event either way;\n // the id is what sets telemetry_identified on the sampling block, which\n // is how the two populations stay separable downstream.\n private licenseTelemetryId: string | null = null;\n // Properties merged into every event this client sends.\n //\n // For facts about the caller that are true for the whole process rather than\n // for one event: which product is embedding the runtime, for instance. A\n // distribution built on top of this can then be told apart in the existing\n // events instead of sending its own, which is the difference between one\n // extra field and a second pipeline nobody asked for.\n //\n // Sent as `global_properties`, a field of its own, so these stay separable\n // from an event's own properties all the way to the sink.\n //\n // Do not reuse a key an event already sets: the fanout spreads this bag last\n // for `oss.runtime.*`, so a collision resolves in favour of the global and\n // does so silently. Names here should describe the caller, not the call.\n private globalProperties: Record<string, unknown> = {};\n\n constructor({\n telemetryDisabled,\n sampleRate,\n }: {\n telemetryDisabled?: boolean;\n sampleRate?: number;\n } = {}) {\n this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();\n this.setSampleRate(sampleRate);\n }\n\n private shouldSendEvent() {\n if (this.sampleRate >= 1) return true;\n return Math.random() < this.sampleRate;\n }\n\n /**\n * Add properties carried by every subsequent event.\n *\n * Merged rather than replaced, so two callers setting different fields do not\n * erase each other. Set once at runtime construction in practice; nothing\n * here is per-request.\n */\n setGlobalProperties(properties: Record<string, unknown>) {\n this.globalProperties = { ...this.globalProperties, ...properties };\n }\n\n /** Atomically replace the process-wide telemetry identity. */\n setTelemetryIdentity(identity: TelemetryIdentity): 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 /** @deprecated Prefer {@link setTelemetryIdentity}. */\n setLicenseToken(licenseToken: string): void {\n this.setTelemetryIdentity({ licenseToken });\n }\n\n /** Create an immutable capture scope for one Runtime instance. */\n createScope(identity: TelemetryIdentity): TelemetryCapture {\n const resolvedIdentity = this.resolveTelemetryIdentity(identity);\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 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()) return;\n // Nothing is gated at the default rate of 1. A caller who dialled it\n // down means it, and identified callers are exempt either way.\n if (!identity.licenseTelemetryId && !this.shouldSendEvent()) return;\n\n await lambdaClient.send({\n event,\n properties: properties as Record<string, unknown>,\n // Its own field on the wire rather than folded into `properties`, which\n // is what the sink expects: for `oss.runtime.*` the fanout treats\n // `global_properties` as the SDK's pass-through bag and spreads it into\n // the analytics event, and v1's client sends package name and version the\n // same way. Folding it in would work and would put a process-level fact\n // in the per-event slot, where nothing downstream expects to find one.\n // Sampling metadata rides in the same slot, as it does in v1. It\n // reads 1/1 unless a caller dialled the rate down, and is stamped\n // either way: a consumer summing sampleWeight across emitters must\n // not find the field missing on a quarter of the rows, which is the\n // state that made ~24% of runtime volume unweightable (OSS-1017).\n globalProperties: {\n ...this.globalProperties,\n ...computeSamplingMeta({\n telemetryId: identity.licenseTelemetryId,\n sampleRate: this.sampleRate,\n }),\n telemetry_emitter: TELEMETRY_EMITTER_V2,\n // Constant here: a v1 request never reaches this client. The v1\n // entrypoint hands its own capture scope to the V2 runtime it\n // builds, so v1 traffic is emitted by the v1 client and stamped\n // v1 there — which is also what keeps it on the Segment wire.\n telemetry_surface: TELEMETRY_SURFACE_V2,\n // This client has one transport, so the marker is constant here. It\n // is stamped anyway so the property means the same thing on every\n // event whichever client produced it (OSS-1019).\n telemetry_transport: \"lambda\",\n },\n packageName: RUNTIME_PACKAGE_NAME,\n packageVersion: RUNTIME_PACKAGE_VERSION,\n telemetryId: identity.telemetryId ?? undefined,\n licenseToken: identity.licenseToken ?? undefined,\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 ?? 1;\n\n if (processEnv().COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n _sampleRate = parseFloat(processEnv().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 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.sampleRate = _sampleRate;\n }\n}\n\nconst telemetry = new TelemetryClient();\nexport default telemetry;\n"],"mappings":";;;;;AAmCA,SAAgB,sBAA+B;AAC7C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AClB,CAAC;IACF,mBAAmB;IAKnB,mBAAmB;IAInB,qBAAqB;IACtB;GACD,aAAa;GACb,gBAAgB;GAChB,aAAa,SAAS,eAAe;GACrC,cAAc,SAAS,gBAAgB;GACxC,CAAC;;CAGJ,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;AAE5B,MAAI,YAAY,CAAC,iCACf,eAAc,WAAW,YAAY,CAAC,iCAAiC;AAMzE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,aAAa;;;AAItB,MAAM,YAAY,IAAI,iBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/runtime",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@ai-sdk/openai": "^3.0.36",
|
|
66
66
|
"@cfworker/json-schema": "^4.1.1",
|
|
67
67
|
"@copilotkit/license-verifier": "~0.5.0",
|
|
68
|
-
"@copilotkit/shared": "2.0.0-rc.
|
|
68
|
+
"@copilotkit/shared": "2.0.0-rc.4",
|
|
69
69
|
"@modelcontextprotocol/sdk": "^1.18.2",
|
|
70
70
|
"@remix-run/node-fetch-server": "^0.13.0",
|
|
71
71
|
"@scarf/scarf": "^1.3.0",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
124
|
"engines": {
|
|
125
|
-
"node": ">=
|
|
125
|
+
"node": "^20.19.3 || >=22.13.0"
|
|
126
126
|
},
|
|
127
127
|
"scripts": {
|
|
128
128
|
"build": "tsdown",
|