@copilotkit/shared 2.0.0-rc.2 → 2.0.0-rc.3

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 (39) hide show
  1. package/dist/index.cjs +2 -0
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +2 -1
  4. package/dist/index.d.cts.map +1 -1
  5. package/dist/index.d.mts +2 -1
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +2 -1
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/index.umd.js +16 -2
  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-disabled.cjs +3 -1
  14. package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
  15. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
  16. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
  17. package/dist/telemetry/telemetry-disabled.mjs +4 -1
  18. package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
  19. package/dist/utils/index.cjs +1 -0
  20. package/dist/utils/index.cjs.map +1 -1
  21. package/dist/utils/index.d.cts +1 -0
  22. package/dist/utils/index.d.cts.map +1 -1
  23. package/dist/utils/index.d.mts +1 -0
  24. package/dist/utils/index.d.mts.map +1 -1
  25. package/dist/utils/index.mjs +1 -0
  26. package/dist/utils/index.mjs.map +1 -1
  27. package/dist/utils/process-env.cjs +14 -0
  28. package/dist/utils/process-env.cjs.map +1 -0
  29. package/dist/utils/process-env.d.cts +10 -0
  30. package/dist/utils/process-env.d.cts.map +1 -0
  31. package/dist/utils/process-env.d.mts +10 -0
  32. package/dist/utils/process-env.d.mts.map +1 -0
  33. package/dist/utils/process-env.mjs +13 -0
  34. package/dist/utils/process-env.mjs.map +1 -0
  35. package/package.json +1 -1
  36. package/src/telemetry/telemetry-disabled.ts +7 -7
  37. package/src/utils/__tests__/process-env.test.ts +22 -0
  38. package/src/utils/index.ts +1 -0
  39. package/src/utils/process-env.ts +14 -0
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-rc.2";
3
+ var version = "2.0.0-rc.3";
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.2";
2
+ var version = "2.0.0-rc.3";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -1,3 +1,4 @@
1
+ const require_process_env = require('../utils/process-env.cjs');
1
2
 
2
3
  //#region src/telemetry/telemetry-disabled.ts
3
4
  /**
@@ -12,7 +13,8 @@
12
13
  * bundler module graphs. See the note in `../index.ts`.
13
14
  */
14
15
  function isTelemetryDisabled() {
15
- return process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
16
+ const env = require_process_env.processEnv();
17
+ return env.COPILOTKIT_TELEMETRY_DISABLED === "true" || env.COPILOTKIT_TELEMETRY_DISABLED === "1" || env.DO_NOT_TRACK === "true" || env.DO_NOT_TRACK === "1";
16
18
  }
17
19
 
18
20
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-disabled.cjs","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n *\n * Lives in its own module so that the browser-facing root entry can\n * re-export it without pulling in `telemetry-client.ts`, whose\n * `@segment/analytics-node` import drags Node built-ins into browser\n * bundler module graphs. See the note in `../index.ts`.\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"],"mappings":";;;;;;;;;;;;;AAWA,SAAgB,sBAA+B;AAC7C,QACG,QAAQ,IACN,kCAAkC,UACpC,QAAQ,IACN,kCAAkC,OACpC,QAAQ,IAA2C,iBAClD,UACD,QAAQ,IAA2C,iBAAiB"}
1
+ {"version":3,"file":"telemetry-disabled.cjs","names":["processEnv"],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["import { processEnv } from \"../utils/process-env\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n *\n * Lives in its own module so that the browser-facing root entry can\n * re-export it without pulling in `telemetry-client.ts`, whose\n * `@segment/analytics-node` import drags Node built-ins into browser\n * bundler module graphs. See the note in `../index.ts`.\n */\nexport function isTelemetryDisabled(): boolean {\n const env = processEnv();\n return (\n env.COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n env.COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n env.DO_NOT_TRACK === \"true\" ||\n env.DO_NOT_TRACK === \"1\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,sBAA+B;CAC7C,MAAM,MAAMA,gCAAY;AACxB,QACE,IAAI,kCAAkC,UACtC,IAAI,kCAAkC,OACtC,IAAI,iBAAiB,UACrB,IAAI,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-disabled.d.cts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;AAWA;;;;;;;;;;iBAAgB,mBAAA,CAAA"}
1
+ {"version":3,"file":"telemetry-disabled.d.cts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;AAaA;;;;;;;;;;iBAAgB,mBAAA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-disabled.d.mts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;AAWA;;;;;;;;;;iBAAgB,mBAAA,CAAA"}
1
+ {"version":3,"file":"telemetry-disabled.d.mts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;AAaA;;;;;;;;;;iBAAgB,mBAAA,CAAA"}
@@ -1,3 +1,5 @@
1
+ import { processEnv } from "../utils/process-env.mjs";
2
+
1
3
  //#region src/telemetry/telemetry-disabled.ts
2
4
  /**
3
5
  * Checks if telemetry is disabled via environment variables.
@@ -11,7 +13,8 @@
11
13
  * bundler module graphs. See the note in `../index.ts`.
12
14
  */
13
15
  function isTelemetryDisabled() {
14
- return process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
16
+ const env = processEnv();
17
+ return env.COPILOTKIT_TELEMETRY_DISABLED === "true" || env.COPILOTKIT_TELEMETRY_DISABLED === "1" || env.DO_NOT_TRACK === "true" || env.DO_NOT_TRACK === "1";
15
18
  }
16
19
 
17
20
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-disabled.mjs","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n *\n * Lives in its own module so that the browser-facing root entry can\n * re-export it without pulling in `telemetry-client.ts`, whose\n * `@segment/analytics-node` import drags Node built-ins into browser\n * bundler module graphs. See the note in `../index.ts`.\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"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,sBAA+B;AAC7C,QACG,QAAQ,IACN,kCAAkC,UACpC,QAAQ,IACN,kCAAkC,OACpC,QAAQ,IAA2C,iBAClD,UACD,QAAQ,IAA2C,iBAAiB"}
1
+ {"version":3,"file":"telemetry-disabled.mjs","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["import { processEnv } from \"../utils/process-env\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n *\n * Lives in its own module so that the browser-facing root entry can\n * re-export it without pulling in `telemetry-client.ts`, whose\n * `@segment/analytics-node` import drags Node built-ins into browser\n * bundler module graphs. See the note in `../index.ts`.\n */\nexport function isTelemetryDisabled(): boolean {\n const env = processEnv();\n return (\n env.COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n env.COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n env.DO_NOT_TRACK === \"true\" ||\n env.DO_NOT_TRACK === \"1\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,sBAA+B;CAC7C,MAAM,MAAM,YAAY;AACxB,QACE,IAAI,kCAAkC,UACtC,IAAI,kCAAkC,OACtC,IAAI,iBAAiB,UACrB,IAAI,iBAAiB"}
@@ -9,6 +9,7 @@ const require_inspector_learning = require('./inspector-learning.cjs');
9
9
  const require_inspector_visibility = require('./inspector-visibility.cjs');
10
10
  const require_types = require('./types.cjs');
11
11
  const require_random_id = require('./random-id.cjs');
12
+ const require_process_env = require('./process-env.cjs');
12
13
  const require_requests = require('./requests.cjs');
13
14
  const require_row_render_keys = require('./row-render-keys.cjs');
14
15
  let partial_json = require("partial-json");
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./inspector-metadata\";\nexport * from \"./inspector-learning\";\nexport * from \"./inspector-visibility\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\nexport * from \"./row-render-keys\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n// Allow partial values of every type except unterminated numbers. A cut-off\n// number is a *different* number (`{\"max\":1` is about to become 100, not 1),\n// while a cut-off string is still the beginning of the final string. Numbers\n// therefore only appear once terminated by `,`, `}` or `]`.\nconst PARTIAL_JSON_ALLOW = PartialJSON.Allow.ALL & ~PartialJSON.Allow.NUM;\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json, PARTIAL_JSON_ALLOW);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO,aAAa,UAAU,OAAO;;;AAQzC,MAAM,qBAAqBA,aAAY,MAAM,MAAM,CAACA,aAAY,MAAM;;;;;AAMtE,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAASA,aAAY,MAAM,MAAM,mBAAmB;AAC1D,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"}
1
+ {"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./inspector-metadata\";\nexport * from \"./inspector-learning\";\nexport * from \"./inspector-visibility\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./process-env\";\nexport * from \"./requests\";\nexport * from \"./row-render-keys\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n// Allow partial values of every type except unterminated numbers. A cut-off\n// number is a *different* number (`{\"max\":1` is about to become 100, not 1),\n// while a cut-off string is still the beginning of the final string. Numbers\n// therefore only appear once terminated by `,`, `}` or `]`.\nconst PARTIAL_JSON_ALLOW = PartialJSON.Allow.ALL & ~PartialJSON.Allow.NUM;\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json, PARTIAL_JSON_ALLOW);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO,aAAa,UAAU,OAAO;;;AAQzC,MAAM,qBAAqBA,aAAY,MAAM,MAAM,CAACA,aAAY,MAAM;;;;;AAMtE,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAASA,aAAY,MAAM,MAAM,mBAAmB;AAC1D,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"}
@@ -8,6 +8,7 @@ import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningP
8
8
  import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.cjs";
9
9
  import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeEntitlementResponse, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SingleRouteRuntimeInfo, ThreadEndpointRuntimeInfo } from "./types.cjs";
10
10
  import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.cjs";
11
+ import { processEnv } from "./process-env.cjs";
11
12
  import { readBody } from "./requests.cjs";
12
13
  import { RowKeyStore, commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById } from "./row-render-keys.cjs";
13
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;;AAqBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAkBxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAsBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAkBxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"}
@@ -8,6 +8,7 @@ import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningP
8
8
  import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.mjs";
9
9
  import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeEntitlementResponse, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SingleRouteRuntimeInfo, ThreadEndpointRuntimeInfo } from "./types.mjs";
10
10
  import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.mjs";
11
+ import { processEnv } from "./process-env.mjs";
11
12
  import { readBody } from "./requests.mjs";
12
13
  import { RowKeyStore, commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById } from "./row-render-keys.mjs";
13
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;;AAqBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAkBxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAsBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAkBxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"}
@@ -8,6 +8,7 @@ import { parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, pars
8
8
  import { shouldEnableInspector } from "./inspector-visibility.mjs";
9
9
  import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "./types.mjs";
10
10
  import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.mjs";
11
+ import { processEnv } from "./process-env.mjs";
11
12
  import { readBody } from "./requests.mjs";
12
13
  import { commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById } from "./row-render-keys.mjs";
13
14
  import * as PartialJSON from "partial-json";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./inspector-metadata\";\nexport * from \"./inspector-learning\";\nexport * from \"./inspector-visibility\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\nexport * from \"./row-render-keys\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n// Allow partial values of every type except unterminated numbers. A cut-off\n// number is a *different* number (`{\"max\":1` is about to become 100, not 1),\n// while a cut-off string is still the beginning of the final string. Numbers\n// therefore only appear once terminated by `,`, `}` or `]`.\nconst PARTIAL_JSON_ALLOW = PartialJSON.Allow.ALL & ~PartialJSON.Allow.NUM;\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json, PARTIAL_JSON_ALLOW);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO,aAAa,UAAU,OAAO;;;AAQzC,MAAM,qBAAqB,YAAY,MAAM,MAAM,CAAC,YAAY,MAAM;;;;;AAMtE,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAAS,YAAY,MAAM,MAAM,mBAAmB;AAC1D,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./inspector-metadata\";\nexport * from \"./inspector-learning\";\nexport * from \"./inspector-visibility\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./process-env\";\nexport * from \"./requests\";\nexport * from \"./row-render-keys\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n// Allow partial values of every type except unterminated numbers. A cut-off\n// number is a *different* number (`{\"max\":1` is about to become 100, not 1),\n// while a cut-off string is still the beginning of the final string. Numbers\n// therefore only appear once terminated by `,`, `}` or `]`.\nconst PARTIAL_JSON_ALLOW = PartialJSON.Allow.ALL & ~PartialJSON.Allow.NUM;\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json, PARTIAL_JSON_ALLOW);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO,aAAa,UAAU,OAAO;;;AAQzC,MAAM,qBAAqB,YAAY,MAAM,MAAM,CAAC,YAAY,MAAM;;;;;AAMtE,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAAS,YAAY,MAAM,MAAM,mBAAmB;AAC1D,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"}
@@ -0,0 +1,14 @@
1
+
2
+ //#region src/utils/process-env.ts
3
+ /**
4
+ * The process environment, or an empty object where there is no `process`
5
+ * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
6
+ * rather than caching it, so later changes to `process.env` are seen.
7
+ */
8
+ function processEnv() {
9
+ return globalThis.process?.env ?? {};
10
+ }
11
+
12
+ //#endregion
13
+ exports.processEnv = processEnv;
14
+ //# sourceMappingURL=process-env.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-env.cjs","names":[],"sources":["../../src/utils/process-env.ts"],"sourcesContent":["/**\n * The process environment, or an empty object where there is no `process`\n * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use\n * rather than caching it, so later changes to `process.env` are seen.\n */\nexport function processEnv(): Record<string, string | undefined> {\n return (\n (\n globalThis as {\n process?: { env?: Record<string, string | undefined> };\n }\n ).process?.env ?? {}\n );\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,aAAiD;AAC/D,QAEI,WAGA,SAAS,OAAO,EAAE"}
@@ -0,0 +1,10 @@
1
+ //#region src/utils/process-env.d.ts
2
+ /**
3
+ * The process environment, or an empty object where there is no `process`
4
+ * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
5
+ * rather than caching it, so later changes to `process.env` are seen.
6
+ */
7
+ declare function processEnv(): Record<string, string | undefined>;
8
+ //#endregion
9
+ export { processEnv };
10
+ //# sourceMappingURL=process-env.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-env.d.cts","names":[],"sources":["../../src/utils/process-env.ts"],"mappings":";;AAKA;;;;iBAAgB,UAAA,CAAA,GAAc,MAAA"}
@@ -0,0 +1,10 @@
1
+ //#region src/utils/process-env.d.ts
2
+ /**
3
+ * The process environment, or an empty object where there is no `process`
4
+ * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
5
+ * rather than caching it, so later changes to `process.env` are seen.
6
+ */
7
+ declare function processEnv(): Record<string, string | undefined>;
8
+ //#endregion
9
+ export { processEnv };
10
+ //# sourceMappingURL=process-env.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-env.d.mts","names":[],"sources":["../../src/utils/process-env.ts"],"mappings":";;AAKA;;;;iBAAgB,UAAA,CAAA,GAAc,MAAA"}
@@ -0,0 +1,13 @@
1
+ //#region src/utils/process-env.ts
2
+ /**
3
+ * The process environment, or an empty object where there is no `process`
4
+ * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
5
+ * rather than caching it, so later changes to `process.env` are seen.
6
+ */
7
+ function processEnv() {
8
+ return globalThis.process?.env ?? {};
9
+ }
10
+
11
+ //#endregion
12
+ export { processEnv };
13
+ //# sourceMappingURL=process-env.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-env.mjs","names":[],"sources":["../../src/utils/process-env.ts"],"sourcesContent":["/**\n * The process environment, or an empty object where there is no `process`\n * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use\n * rather than caching it, so later changes to `process.env` are seen.\n */\nexport function processEnv(): Record<string, string | undefined> {\n return (\n (\n globalThis as {\n process?: { env?: Record<string, string | undefined> };\n }\n ).process?.env ?? {}\n );\n}\n"],"mappings":";;;;;;AAKA,SAAgB,aAAiD;AAC/D,QAEI,WAGA,SAAS,OAAO,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/shared",
3
- "version": "2.0.0-rc.2",
3
+ "version": "2.0.0-rc.3",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -1,3 +1,5 @@
1
+ import { processEnv } from "../utils/process-env";
2
+
1
3
  /**
2
4
  * Checks if telemetry is disabled via environment variables.
3
5
  * Users can opt out by setting:
@@ -10,13 +12,11 @@
10
12
  * bundler module graphs. See the note in `../index.ts`.
11
13
  */
12
14
  export function isTelemetryDisabled(): boolean {
15
+ const env = processEnv();
13
16
  return (
14
- (process.env as Record<string, string | undefined>)
15
- .COPILOTKIT_TELEMETRY_DISABLED === "true" ||
16
- (process.env as Record<string, string | undefined>)
17
- .COPILOTKIT_TELEMETRY_DISABLED === "1" ||
18
- (process.env as Record<string, string | undefined>).DO_NOT_TRACK ===
19
- "true" ||
20
- (process.env as Record<string, string | undefined>).DO_NOT_TRACK === "1"
17
+ env.COPILOTKIT_TELEMETRY_DISABLED === "true" ||
18
+ env.COPILOTKIT_TELEMETRY_DISABLED === "1" ||
19
+ env.DO_NOT_TRACK === "true" ||
20
+ env.DO_NOT_TRACK === "1"
21
21
  );
22
22
  }
@@ -0,0 +1,22 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { processEnv } from "../process-env";
3
+
4
+ describe("processEnv", () => {
5
+ afterEach(() => {
6
+ vi.unstubAllGlobals();
7
+ vi.unstubAllEnvs();
8
+ });
9
+
10
+ it("reads the live process environment", () => {
11
+ vi.stubEnv("CPK_PROCESS_ENV_TEST", "first");
12
+ expect(processEnv().CPK_PROCESS_ENV_TEST).toBe("first");
13
+ vi.stubEnv("CPK_PROCESS_ENV_TEST", "second");
14
+ expect(processEnv().CPK_PROCESS_ENV_TEST).toBe("second");
15
+ });
16
+
17
+ // Cloudflare Workers without nodejs_compat define no `process`.
18
+ it("returns an empty environment where there is no process", () => {
19
+ vi.stubGlobal("process", undefined);
20
+ expect(processEnv()).toEqual({});
21
+ });
22
+ });
@@ -8,6 +8,7 @@ export * from "./inspector-learning";
8
8
  export * from "./inspector-visibility";
9
9
  export * from "./types";
10
10
  export * from "./random-id";
11
+ export * from "./process-env";
11
12
  export * from "./requests";
12
13
  export * from "./row-render-keys";
13
14
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The process environment, or an empty object where there is no `process`
3
+ * (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
4
+ * rather than caching it, so later changes to `process.env` are seen.
5
+ */
6
+ export function processEnv(): Record<string, string | undefined> {
7
+ return (
8
+ (
9
+ globalThis as {
10
+ process?: { env?: Record<string, string | undefined> };
11
+ }
12
+ ).process?.env ?? {}
13
+ );
14
+ }