@copilotkit/shared 2.0.0-rc.2 → 2.0.0-rc.21
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/README.md +3 -14
- package/dist/a2ui-envelope.cjs +2 -2
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +2 -2
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/attachments/types.d.cts +1 -3
- package/dist/attachments/types.d.cts.map +1 -1
- package/dist/attachments/types.d.mts +1 -3
- package/dist/attachments/types.d.mts.map +1 -1
- package/dist/finalize-events.cjs +16 -0
- package/dist/finalize-events.cjs.map +1 -1
- package/dist/finalize-events.d.cts.map +1 -1
- package/dist/finalize-events.d.mts.map +1 -1
- package/dist/finalize-events.mjs +16 -0
- package/dist/finalize-events.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/child-refs.cjs +3 -3
- package/dist/generative-ui/child-refs.cjs.map +1 -1
- package/dist/generative-ui/child-refs.d.cts.map +1 -1
- package/dist/generative-ui/child-refs.d.mts.map +1 -1
- package/dist/generative-ui/child-refs.mjs +3 -3
- package/dist/generative-ui/child-refs.mjs.map +1 -1
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/render-ui-args.cjs +1 -0
- package/dist/generative-ui/render-ui-args.cjs.map +1 -1
- package/dist/generative-ui/render-ui-args.d.cts.map +1 -1
- package/dist/generative-ui/render-ui-args.d.mts.map +1 -1
- package/dist/generative-ui/render-ui-args.mjs +1 -0
- package/dist/generative-ui/render-ui-args.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +242 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +239 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- package/dist/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +7 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +7 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/generative-ui/validate-operation.cjs +2 -2
- package/dist/generative-ui/validate-operation.cjs.map +1 -1
- package/dist/generative-ui/validate-operation.mjs +2 -2
- package/dist/generative-ui/validate-operation.mjs.map +1 -1
- package/dist/index.cjs +18 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +11 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -8
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +864 -450
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +20 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +15 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +15 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +20 -8
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/lambda-client.cjs +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +3 -6
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +4 -6
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/types/message.d.cts +1 -18
- package/dist/types/message.d.cts.map +1 -1
- package/dist/types/message.d.mts +1 -18
- package/dist/types/message.d.mts.map +1 -1
- package/dist/utils/errors.cjs +5 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +6 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +1 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +5 -6
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +5 -6
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +5 -6
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/inspector-visibility.cjs +25 -3
- package/dist/utils/inspector-visibility.cjs.map +1 -1
- package/dist/utils/inspector-visibility.d.cts +26 -3
- package/dist/utils/inspector-visibility.d.cts.map +1 -1
- package/dist/utils/inspector-visibility.d.mts +26 -3
- package/dist/utils/inspector-visibility.d.mts.map +1 -1
- package/dist/utils/inspector-visibility.mjs +25 -4
- package/dist/utils/inspector-visibility.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +4 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +5 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/process-env.cjs +14 -0
- package/dist/utils/process-env.cjs.map +1 -0
- package/dist/utils/process-env.d.cts +10 -0
- package/dist/utils/process-env.d.cts.map +1 -0
- package/dist/utils/process-env.d.mts +10 -0
- package/dist/utils/process-env.d.mts.map +1 -0
- package/dist/utils/process-env.mjs +13 -0
- package/dist/utils/process-env.mjs.map +1 -0
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/package.json +8 -32
- package/scripts/verify-cjs-exports.cjs +1 -1
- package/src/__tests__/a2ui-envelope.test.ts +18 -13
- package/src/__tests__/a2ui-prompts.test.ts +47 -14
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/__tests__/standard-schema.test.ts +61 -101
- package/src/a2ui-envelope.ts +7 -6
- package/src/a2ui-prompts.ts +47 -96
- package/src/attachments/types.ts +1 -3
- package/src/finalize-events.ts +16 -0
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- package/src/generative-ui/basic-functions.ts +1 -1
- package/src/generative-ui/child-refs.ts +5 -4
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +3 -0
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/render-ui-args.ts +3 -0
- package/src/generative-ui/schema-render.ts +377 -0
- package/src/generative-ui/types.ts +10 -7
- package/src/generative-ui/validate-operation.ts +2 -2
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +24 -27
- package/src/telemetry/lambda-client.ts +8 -3
- package/src/telemetry/model-host.test.ts +2 -5
- package/src/telemetry/telemetry-disabled.ts +7 -12
- package/src/types/message.ts +1 -19
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/__tests__/process-env.test.ts +22 -0
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +28 -85
- package/src/utils/index.ts +1 -2
- package/src/utils/inspector-visibility.test.ts +26 -0
- package/src/utils/inspector-visibility.ts +35 -3
- package/src/utils/json-schema.ts +5 -152
- package/src/utils/process-env.ts +14 -0
- package/src/utils/random-id.ts +17 -37
- package/tsconfig.json +3 -1
- package/tsdown.config.ts +2 -19
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- package/src/utils/console-styling.ts +0 -126
package/dist/utils/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_clipboard = require('./clipboard.cjs');
|
|
3
|
-
const require_conditions = require('./conditions.cjs');
|
|
4
|
-
const require_console_styling = require('./console-styling.cjs');
|
|
5
3
|
const require_errors = require('./errors.cjs');
|
|
6
4
|
const require_json_schema = require('./json-schema.cjs');
|
|
7
5
|
const require_inspector_metadata = require('./inspector-metadata.cjs');
|
|
@@ -9,6 +7,7 @@ const require_inspector_learning = require('./inspector-learning.cjs');
|
|
|
9
7
|
const require_inspector_visibility = require('./inspector-visibility.cjs');
|
|
10
8
|
const require_types = require('./types.cjs');
|
|
11
9
|
const require_random_id = require('./random-id.cjs');
|
|
10
|
+
const require_process_env = require('./process-env.cjs');
|
|
12
11
|
const require_requests = require('./requests.cjs');
|
|
13
12
|
const require_row_render_keys = require('./row-render-keys.cjs');
|
|
14
13
|
let partial_json = require("partial-json");
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\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":";;;;;;;;;;;;;;;;;;;;;;AAoBA,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"}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { copyToClipboard } from "./clipboard.cjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { 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 } from "./errors.cjs";
|
|
5
|
-
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.cjs";
|
|
2
|
+
import { 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 } from "./errors.cjs";
|
|
3
|
+
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.cjs";
|
|
6
4
|
import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.cjs";
|
|
7
5
|
import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningPage, InspectorLearningRequestV1, InspectorLearningSkill, InspectorLearningSnapshotV1, InspectorLearningTrajectoryEvidence, parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.cjs";
|
|
8
|
-
import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.cjs";
|
|
6
|
+
import { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS } from "./inspector-visibility.cjs";
|
|
9
7
|
import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeEntitlementResponse, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SingleRouteRuntimeInfo, ThreadEndpointRuntimeInfo } from "./types.cjs";
|
|
10
|
-
import {
|
|
8
|
+
import { randomId, randomUUID } from "./random-id.cjs";
|
|
9
|
+
import { processEnv } from "./process-env.cjs";
|
|
11
10
|
import { readBody } from "./requests.cjs";
|
|
12
11
|
import { RowKeyStore, commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById } from "./row-render-keys.cjs";
|
|
13
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;AAoBA;;;;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"}
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { copyToClipboard } from "./clipboard.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { 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 } from "./errors.mjs";
|
|
5
|
-
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
2
|
+
import { 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 } from "./errors.mjs";
|
|
3
|
+
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
6
4
|
import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.mjs";
|
|
7
5
|
import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningPage, InspectorLearningRequestV1, InspectorLearningSkill, InspectorLearningSnapshotV1, InspectorLearningTrajectoryEvidence, parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.mjs";
|
|
8
|
-
import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.mjs";
|
|
6
|
+
import { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS } from "./inspector-visibility.mjs";
|
|
9
7
|
import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeEntitlementResponse, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SingleRouteRuntimeInfo, ThreadEndpointRuntimeInfo } from "./types.mjs";
|
|
10
|
-
import {
|
|
8
|
+
import { randomId, randomUUID } from "./random-id.mjs";
|
|
9
|
+
import { processEnv } from "./process-env.mjs";
|
|
11
10
|
import { readBody } from "./requests.mjs";
|
|
12
11
|
import { RowKeyStore, commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById } from "./row-render-keys.mjs";
|
|
13
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;AAoBA;;;;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"}
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { copyToClipboard } from "./clipboard.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { 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 } from "./errors.mjs";
|
|
5
|
-
import { actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
2
|
+
import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, isStructuredCopilotKitError } from "./errors.mjs";
|
|
3
|
+
import { actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
6
4
|
import { parseInspectorMetadataV1 } from "./inspector-metadata.mjs";
|
|
7
5
|
import { parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.mjs";
|
|
8
|
-
import { shouldEnableInspector } from "./inspector-visibility.mjs";
|
|
6
|
+
import { shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS } from "./inspector-visibility.mjs";
|
|
9
7
|
import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "./types.mjs";
|
|
10
|
-
import {
|
|
8
|
+
import { randomId, randomUUID } from "./random-id.mjs";
|
|
9
|
+
import { processEnv } from "./process-env.mjs";
|
|
11
10
|
import { readBody } from "./requests.mjs";
|
|
12
11
|
import { commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById } from "./row-render-keys.mjs";
|
|
13
12
|
import * as PartialJSON from "partial-json";
|
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\nexport * from \"./
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./clipboard\";\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":";;;;;;;;;;;;;;;;;;;;AAoBA,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,13 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/utils/inspector-visibility.ts
|
|
3
3
|
/**
|
|
4
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
5
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
6
|
+
*
|
|
7
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
8
|
+
*/
|
|
9
|
+
const ɵINSPECTOR_LOOPBACK_HOSTS = Object.freeze([
|
|
10
|
+
"localhost",
|
|
11
|
+
"127.0.0.1",
|
|
12
|
+
"[::1]"
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
4
15
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
5
|
-
* but an explicit `true` never overrides a production or server environment
|
|
16
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
17
|
+
* or a page served from a non-loopback host.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* shouldEnableInspector({
|
|
21
|
+
* enableInspector,
|
|
22
|
+
* isBrowser: true,
|
|
23
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
24
|
+
* hostname: window.location.hostname,
|
|
25
|
+
* });
|
|
6
26
|
*/
|
|
7
|
-
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment }) {
|
|
8
|
-
|
|
27
|
+
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment, hostname }) {
|
|
28
|
+
const isAllowedHost = hostname === void 0 || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);
|
|
29
|
+
return isBrowser && isDevelopment && enableInspector !== false && isAllowedHost;
|
|
9
30
|
}
|
|
10
31
|
|
|
11
32
|
//#endregion
|
|
12
33
|
exports.shouldEnableInspector = shouldEnableInspector;
|
|
34
|
+
exports.ɵINSPECTOR_LOOPBACK_HOSTS = ɵINSPECTOR_LOOPBACK_HOSTS;
|
|
13
35
|
//# sourceMappingURL=inspector-visibility.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.cjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"inspector-visibility.cjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["/**\n * Hosts the Inspector runs on. The Inspector reads agent state, messages and\n * request headers, so it only mounts on a page served from this machine.\n *\n * @internal Framework adapters use this list. Applications must not depend on it.\n */\nexport const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[] = Object.freeze([\n \"localhost\",\n \"127.0.0.1\",\n \"[::1]\",\n]);\n\nexport interface InspectorVisibilityOptions {\n enableInspector?: boolean;\n isBrowser: boolean;\n isDevelopment: boolean;\n /**\n * The page's `location.hostname`. When set, the Inspector is enabled only on\n * a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development\n * build served on a LAN or tunnel address does not expose it.\n */\n hostname?: string;\n}\n\n/**\n * The Inspector is a development-only browser tool. Consumers may disable it,\n * but an explicit `true` never overrides a production or server environment,\n * or a page served from a non-loopback host.\n *\n * @example\n * shouldEnableInspector({\n * enableInspector,\n * isBrowser: true,\n * isDevelopment: process.env.NODE_ENV === \"development\",\n * hostname: window.location.hostname,\n * });\n */\nexport function shouldEnableInspector({\n enableInspector,\n isBrowser,\n isDevelopment,\n hostname,\n}: InspectorVisibilityOptions) {\n const isAllowedHost =\n hostname === undefined || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);\n return (\n isBrowser && isDevelopment && enableInspector !== false && isAllowedHost\n );\n}\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA+C,OAAO,OAAO;CACxE;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;;AA2BF,SAAgB,sBAAsB,EACpC,iBACA,WACA,eACA,YAC6B;CAC7B,MAAM,gBACJ,aAAa,UAAa,0BAA0B,SAAS,SAAS;AACxE,QACE,aAAa,iBAAiB,oBAAoB,SAAS"}
|
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
//#region src/utils/inspector-visibility.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
4
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
5
|
+
*
|
|
6
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
7
|
+
*/
|
|
8
|
+
declare const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[];
|
|
2
9
|
interface InspectorVisibilityOptions {
|
|
3
10
|
enableInspector?: boolean;
|
|
4
11
|
isBrowser: boolean;
|
|
5
12
|
isDevelopment: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The page's `location.hostname`. When set, the Inspector is enabled only on
|
|
15
|
+
* a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development
|
|
16
|
+
* build served on a LAN or tunnel address does not expose it.
|
|
17
|
+
*/
|
|
18
|
+
hostname?: string;
|
|
6
19
|
}
|
|
7
20
|
/**
|
|
8
21
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
9
|
-
* but an explicit `true` never overrides a production or server environment
|
|
22
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
23
|
+
* or a page served from a non-loopback host.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* shouldEnableInspector({
|
|
27
|
+
* enableInspector,
|
|
28
|
+
* isBrowser: true,
|
|
29
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
30
|
+
* hostname: window.location.hostname,
|
|
31
|
+
* });
|
|
10
32
|
*/
|
|
11
33
|
declare function shouldEnableInspector({
|
|
12
34
|
enableInspector,
|
|
13
35
|
isBrowser,
|
|
14
|
-
isDevelopment
|
|
36
|
+
isDevelopment,
|
|
37
|
+
hostname
|
|
15
38
|
}: InspectorVisibilityOptions): boolean;
|
|
16
39
|
//#endregion
|
|
17
|
-
export { InspectorVisibilityOptions, shouldEnableInspector };
|
|
40
|
+
export { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS };
|
|
18
41
|
//# sourceMappingURL=inspector-visibility.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.d.cts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"inspector-visibility.d.cts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";;AAMA;;;;;cAAa,yBAAA;AAAA,UAMI,0BAAA;EACf,eAAA;EACA,SAAA;EACA,aAAA;EADA;;;;;EAOA,QAAA;AAAA;;;;;;;;;;;;;;iBAgBc,qBAAA,CAAA;EACd,eAAA;EACA,SAAA;EACA,aAAA;EACA;AAAA,GACC,0BAAA"}
|
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
//#region src/utils/inspector-visibility.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
4
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
5
|
+
*
|
|
6
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
7
|
+
*/
|
|
8
|
+
declare const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[];
|
|
2
9
|
interface InspectorVisibilityOptions {
|
|
3
10
|
enableInspector?: boolean;
|
|
4
11
|
isBrowser: boolean;
|
|
5
12
|
isDevelopment: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The page's `location.hostname`. When set, the Inspector is enabled only on
|
|
15
|
+
* a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development
|
|
16
|
+
* build served on a LAN or tunnel address does not expose it.
|
|
17
|
+
*/
|
|
18
|
+
hostname?: string;
|
|
6
19
|
}
|
|
7
20
|
/**
|
|
8
21
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
9
|
-
* but an explicit `true` never overrides a production or server environment
|
|
22
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
23
|
+
* or a page served from a non-loopback host.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* shouldEnableInspector({
|
|
27
|
+
* enableInspector,
|
|
28
|
+
* isBrowser: true,
|
|
29
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
30
|
+
* hostname: window.location.hostname,
|
|
31
|
+
* });
|
|
10
32
|
*/
|
|
11
33
|
declare function shouldEnableInspector({
|
|
12
34
|
enableInspector,
|
|
13
35
|
isBrowser,
|
|
14
|
-
isDevelopment
|
|
36
|
+
isDevelopment,
|
|
37
|
+
hostname
|
|
15
38
|
}: InspectorVisibilityOptions): boolean;
|
|
16
39
|
//#endregion
|
|
17
|
-
export { InspectorVisibilityOptions, shouldEnableInspector };
|
|
40
|
+
export { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS };
|
|
18
41
|
//# sourceMappingURL=inspector-visibility.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.d.mts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"inspector-visibility.d.mts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";;AAMA;;;;;cAAa,yBAAA;AAAA,UAMI,0BAAA;EACf,eAAA;EACA,SAAA;EACA,aAAA;EADA;;;;;EAOA,QAAA;AAAA;;;;;;;;;;;;;;iBAgBc,qBAAA,CAAA;EACd,eAAA;EACA,SAAA;EACA,aAAA;EACA;AAAA,GACC,0BAAA"}
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
//#region src/utils/inspector-visibility.ts
|
|
2
2
|
/**
|
|
3
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
4
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
5
|
+
*
|
|
6
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
7
|
+
*/
|
|
8
|
+
const ɵINSPECTOR_LOOPBACK_HOSTS = Object.freeze([
|
|
9
|
+
"localhost",
|
|
10
|
+
"127.0.0.1",
|
|
11
|
+
"[::1]"
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
3
14
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
4
|
-
* but an explicit `true` never overrides a production or server environment
|
|
15
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
16
|
+
* or a page served from a non-loopback host.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* shouldEnableInspector({
|
|
20
|
+
* enableInspector,
|
|
21
|
+
* isBrowser: true,
|
|
22
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
23
|
+
* hostname: window.location.hostname,
|
|
24
|
+
* });
|
|
5
25
|
*/
|
|
6
|
-
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment }) {
|
|
7
|
-
|
|
26
|
+
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment, hostname }) {
|
|
27
|
+
const isAllowedHost = hostname === void 0 || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);
|
|
28
|
+
return isBrowser && isDevelopment && enableInspector !== false && isAllowedHost;
|
|
8
29
|
}
|
|
9
30
|
|
|
10
31
|
//#endregion
|
|
11
|
-
export { shouldEnableInspector };
|
|
32
|
+
export { shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS };
|
|
12
33
|
//# sourceMappingURL=inspector-visibility.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.mjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"inspector-visibility.mjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["/**\n * Hosts the Inspector runs on. The Inspector reads agent state, messages and\n * request headers, so it only mounts on a page served from this machine.\n *\n * @internal Framework adapters use this list. Applications must not depend on it.\n */\nexport const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[] = Object.freeze([\n \"localhost\",\n \"127.0.0.1\",\n \"[::1]\",\n]);\n\nexport interface InspectorVisibilityOptions {\n enableInspector?: boolean;\n isBrowser: boolean;\n isDevelopment: boolean;\n /**\n * The page's `location.hostname`. When set, the Inspector is enabled only on\n * a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development\n * build served on a LAN or tunnel address does not expose it.\n */\n hostname?: string;\n}\n\n/**\n * The Inspector is a development-only browser tool. Consumers may disable it,\n * but an explicit `true` never overrides a production or server environment,\n * or a page served from a non-loopback host.\n *\n * @example\n * shouldEnableInspector({\n * enableInspector,\n * isBrowser: true,\n * isDevelopment: process.env.NODE_ENV === \"development\",\n * hostname: window.location.hostname,\n * });\n */\nexport function shouldEnableInspector({\n enableInspector,\n isBrowser,\n isDevelopment,\n hostname,\n}: InspectorVisibilityOptions) {\n const isAllowedHost =\n hostname === undefined || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);\n return (\n isBrowser && isDevelopment && enableInspector !== false && isAllowedHost\n );\n}\n"],"mappings":";;;;;;;AAMA,MAAa,4BAA+C,OAAO,OAAO;CACxE;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;;AA2BF,SAAgB,sBAAsB,EACpC,iBACA,WACA,eACA,YAC6B;CAC7B,MAAM,gBACJ,aAAa,UAAa,0BAA0B,SAAS,SAAS;AACxE,QACE,aAAa,iBAAiB,oBAAoB,SAAS"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
let zod = require("zod");
|
|
3
1
|
|
|
4
2
|
//#region src/utils/json-schema.ts
|
|
5
3
|
function actionParametersToJsonSchema(actionParameters) {
|
|
@@ -119,6 +117,10 @@ function convertAttribute(attribute) {
|
|
|
119
117
|
...properties && { properties },
|
|
120
118
|
...required && required.length > 0 && { required }
|
|
121
119
|
};
|
|
120
|
+
case "string[]":
|
|
121
|
+
case "number[]":
|
|
122
|
+
case "boolean[]":
|
|
123
|
+
case void 0:
|
|
122
124
|
default:
|
|
123
125
|
if (attribute.type?.endsWith("[]")) return {
|
|
124
126
|
type: "array",
|
|
@@ -131,85 +133,8 @@ function convertAttribute(attribute) {
|
|
|
131
133
|
};
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required, definitions, visitedRefs) {
|
|
135
|
-
if (jsonSchema.$ref && definitions) {
|
|
136
|
-
const refPath = jsonSchema.$ref.replace(/^#\/\$defs\/|^#\/definitions\//, "");
|
|
137
|
-
const refs = visitedRefs ?? /* @__PURE__ */ new Set();
|
|
138
|
-
if (refs.has(refPath)) {
|
|
139
|
-
console.warn(`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`);
|
|
140
|
-
let schema = zod.z.any();
|
|
141
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
142
|
-
return required ? schema : schema.optional();
|
|
143
|
-
}
|
|
144
|
-
const resolved = definitions[refPath];
|
|
145
|
-
if (resolved) {
|
|
146
|
-
const nextRefs = new Set(refs);
|
|
147
|
-
nextRefs.add(refPath);
|
|
148
|
-
return convertJsonSchemaToZodSchema(resolved, required, definitions, nextRefs);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;
|
|
152
|
-
if (Array.isArray(jsonSchema.type)) {
|
|
153
|
-
const types = jsonSchema.type;
|
|
154
|
-
const hasNull = types.includes("null");
|
|
155
|
-
const nonNullTypes = types.filter((t) => t !== "null");
|
|
156
|
-
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
157
|
-
const innerSchema = convertJsonSchemaToZodSchema({
|
|
158
|
-
...jsonSchema,
|
|
159
|
-
type: resolvedType
|
|
160
|
-
}, true, defs, visitedRefs);
|
|
161
|
-
let schema = hasNull ? zod.z.union([innerSchema, zod.z.null()]) : innerSchema;
|
|
162
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
163
|
-
return required ? schema : schema.optional();
|
|
164
|
-
}
|
|
165
|
-
const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;
|
|
166
|
-
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
167
|
-
if (unionVariants.length === 1) return convertJsonSchemaToZodSchema(unionVariants[0], required, defs, visitedRefs);
|
|
168
|
-
const schemas = unionVariants.map((v) => convertJsonSchemaToZodSchema(v, true, defs, visitedRefs));
|
|
169
|
-
let schema = zod.z.union(schemas);
|
|
170
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
171
|
-
return required ? schema : schema.optional();
|
|
172
|
-
}
|
|
173
|
-
if (jsonSchema.type === "object") {
|
|
174
|
-
const spec = {};
|
|
175
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) return !required ? zod.z.object(spec).optional() : zod.z.object(spec);
|
|
176
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false, defs, visitedRefs);
|
|
177
|
-
let schema = zod.z.object(spec).describe(jsonSchema.description);
|
|
178
|
-
return required ? schema : schema.optional();
|
|
179
|
-
} else if (jsonSchema.type === "string") {
|
|
180
|
-
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
181
|
-
let schema = zod.z.enum(jsonSchema.enum).describe(jsonSchema.description);
|
|
182
|
-
return required ? schema : schema.optional();
|
|
183
|
-
}
|
|
184
|
-
let schema = zod.z.string().describe(jsonSchema.description);
|
|
185
|
-
return required ? schema : schema.optional();
|
|
186
|
-
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
187
|
-
let schema = zod.z.number().describe(jsonSchema.description);
|
|
188
|
-
return required ? schema : schema.optional();
|
|
189
|
-
} else if (jsonSchema.type === "boolean") {
|
|
190
|
-
let schema = zod.z.boolean().describe(jsonSchema.description);
|
|
191
|
-
return required ? schema : schema.optional();
|
|
192
|
-
} else if (jsonSchema.type === "array") {
|
|
193
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true, defs, visitedRefs);
|
|
194
|
-
let schema = zod.z.array(itemSchema).describe(jsonSchema.description);
|
|
195
|
-
return required ? schema : schema.optional();
|
|
196
|
-
} else if (jsonSchema.type === "null") {
|
|
197
|
-
let schema = zod.z.null().describe(jsonSchema.description);
|
|
198
|
-
return required ? schema : schema.optional();
|
|
199
|
-
}
|
|
200
|
-
console.warn(`[CopilotKit] Unsupported JSON schema type "${jsonSchema.type ?? "unknown"}" — falling back to z.any()`);
|
|
201
|
-
let schema = zod.z.any();
|
|
202
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
203
|
-
return required ? schema : schema.optional();
|
|
204
|
-
}
|
|
205
|
-
function getZodParameters(parameters) {
|
|
206
|
-
if (!parameters) return zod.z.object({});
|
|
207
|
-
return convertJsonSchemaToZodSchema(actionParametersToJsonSchema(parameters), true);
|
|
208
|
-
}
|
|
209
136
|
|
|
210
137
|
//#endregion
|
|
211
138
|
exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
|
|
212
|
-
exports.convertJsonSchemaToZodSchema = convertJsonSchemaToZodSchema;
|
|
213
|
-
exports.getZodParameters = getZodParameters;
|
|
214
139
|
exports.jsonSchemaToActionParameters = jsonSchemaToActionParameters;
|
|
215
140
|
//# sourceMappingURL=json-schema.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.cjs","names":["z"],"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n // Handle null-union types like [\"string\", \"null\"] by picking the non-null type\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n return convertJsonSchemaToParameter(\n name,\n { ...schema, type: resolvedType } as JSONSchema,\n hasNull ? false : isRequired,\n );\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(\n jsonSchema: any,\n required: boolean,\n definitions?: Record<string, any>,\n visitedRefs?: Set<string>,\n): z.ZodSchema {\n // Resolve $ref references\n if (jsonSchema.$ref && definitions) {\n const refPath = jsonSchema.$ref.replace(\n /^#\\/\\$defs\\/|^#\\/definitions\\//,\n \"\",\n );\n\n // Detect circular $ref cycles\n const refs = visitedRefs ?? new Set<string>();\n if (refs.has(refPath)) {\n console.warn(\n `[CopilotKit] Circular $ref detected for \"${refPath}\" — falling back to z.any()`,\n );\n let schema = z.any();\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n const resolved = definitions[refPath];\n if (resolved) {\n // Clone the set so sibling branches don't see each other's visited refs\n const nextRefs = new Set(refs);\n nextRefs.add(refPath);\n return convertJsonSchemaToZodSchema(\n resolved,\n required,\n definitions,\n nextRefs,\n );\n }\n }\n\n // Collect top-level definitions for $ref resolution\n const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;\n\n // Handle null-union types like [\"string\", \"null\"]\n if (Array.isArray(jsonSchema.type)) {\n const types = jsonSchema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n const innerSchema = convertJsonSchemaToZodSchema(\n { ...jsonSchema, type: resolvedType },\n true,\n defs,\n visitedRefs,\n );\n let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n // Handle anyOf / oneOf as z.union\n const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;\n if (Array.isArray(unionVariants) && unionVariants.length > 0) {\n if (unionVariants.length === 1) {\n return convertJsonSchemaToZodSchema(\n unionVariants[0],\n required,\n defs,\n visitedRefs,\n );\n }\n const schemas = unionVariants.map((v: any) =>\n convertJsonSchemaToZodSchema(v, true, defs, visitedRefs),\n );\n let schema = z.union(\n schemas as [z.ZodSchema, z.ZodSchema, ...z.ZodSchema[]],\n );\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n defs,\n visitedRefs,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n if (jsonSchema.enum && jsonSchema.enum.length > 0) {\n let schema = z\n .enum(jsonSchema.enum as [string, ...string[]])\n .describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\" || jsonSchema.type === \"integer\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(\n jsonSchema.items,\n true,\n defs,\n visitedRefs,\n );\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"null\") {\n let schema = z.null().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n\n // Fallback: accept any value rather than throwing\n console.warn(\n `[CopilotKit] Unsupported JSON schema type \"${jsonSchema.type ?? \"unknown\"}\" — falling back to z.any()`,\n );\n let schema = z.any();\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n}\n\nexport function getZodParameters<T extends [] | Parameter[] | undefined>(\n parameters: T,\n): any {\n if (!parameters) return z.object({});\n const jsonParams = actionParametersToJsonSchema(parameters);\n return convertJsonSchemaToZodSchema(jsonParams, true);\n}\n"],"mappings":";;;;AAuCA,SAAgB,6BACd,kBACY;CAEZ,IAAI,aAAqC,EAAE;AAC3C,MAAK,IAAI,aAAa,oBAAoB,EAAE,CAC1C,YAAW,UAAU,QAAQ,iBAAiB,UAAU;CAG1D,IAAI,yBAAmC,EAAE;AACzC,MAAK,IAAI,OAAO,oBAAoB,EAAE,CACpC,KAAI,IAAI,aAAa,MACnB,wBAAuB,KAAK,IAAI,KAAK;AAKzC,QAAO;EACL,MAAM;EACN,YAAY;EACZ,UAAU;EACX;;AAIH,SAAgB,6BACd,YACa;AACb,KAAI,WAAW,SAAS,YAAY,CAAC,WAAW,WAC9C,QAAO,EAAE;CAGX,MAAM,aAA0B,EAAE;CAClC,MAAM,iBAAiB,WAAW,YAAY,EAAE;AAEhD,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,WAAW,WAAW,EAAE;EAClE,MAAM,YAAY,6B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,QAAQ;EACrC,IAAI,SAASA,MAAE,MAAM,CAAC,SAAS,WAAW,YAAY;AACtD,SAAO,WAAW,SAAS,OAAO,UAAU;;AAI9C,SAAQ,KACN,8CAA8C,WAAW,QAAQ,UAAU,6BAC5E;CACD,IAAI,SAASA,MAAE,KAAK;AACpB,KAAI,WAAW,YACb,UAAS,OAAO,SAAS,WAAW,YAAY;AAElD,QAAO,WAAW,SAAS,OAAO,UAAU;;AAG9C,SAAgB,iBACd,YACK;AACL,KAAI,CAAC,WAAY,QAAOA,MAAE,OAAO,EAAE,CAAC;AAEpC,QAAO,6BADY,6BAA6B,WAAW,EACX,KAAK"}
|
|
1
|
+
{"version":3,"file":"json-schema.cjs","names":[],"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import type { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n // Handle null-union types like [\"string\", \"null\"] by picking the non-null type\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n return convertJsonSchemaToParameter(\n name,\n { ...schema, type: resolvedType } as JSONSchema,\n hasNull ? false : isRequired,\n );\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n case \"string[]\":\n case \"number[]\":\n case \"boolean[]\":\n case undefined:\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n"],"mappings":";;AAsCA,SAAgB,6BACd,kBACY;CAEZ,IAAI,aAAqC,EAAE;AAC3C,MAAK,IAAI,aAAa,oBAAoB,EAAE,CAC1C,YAAW,UAAU,QAAQ,iBAAiB,UAAU;CAG1D,IAAI,yBAAmC,EAAE;AACzC,MAAK,IAAI,OAAO,oBAAoB,EAAE,CACpC,KAAI,IA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U;IACvB,GAAI,cAAc,EAAE,YAAY;IAChC,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,UAAU;IACpD;EACH,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL;AAEE,OAAI,UAAU,MAAM,SAAS,KAAK,CAEhC,QAAO;IACL,MAAM;IACN,OAAO,EAAE,MAHM,UAAU,KAAK,MAAM,GAAG,GAAG,EAGV;IAChC,aAAa,UAAU;IACxB;AAGH,UAAO;IACL,MAAM;IACN,aAAa,UAAU;IACxB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Parameter } from "../types/action.cjs";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/json-schema.d.ts
|
|
5
4
|
type JSONSchemaString = {
|
|
@@ -29,8 +28,6 @@ type JSONSchemaArray = {
|
|
|
29
28
|
type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaBoolean | JSONSchemaObject | JSONSchemaArray;
|
|
30
29
|
declare function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema;
|
|
31
30
|
declare function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[];
|
|
32
|
-
declare function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean, definitions?: Record<string, any>, visitedRefs?: Set<string>): z.ZodSchema;
|
|
33
|
-
declare function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any;
|
|
34
31
|
//#endregion
|
|
35
|
-
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema,
|
|
32
|
+
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters };
|
|
36
33
|
//# sourceMappingURL=json-schema.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.cts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-schema.d.cts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":";;;KAEY,gBAAA;EACV,IAAA;EACA,WAAA;EACA,IAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,iBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,UAAA;EAC5B,QAAA;EACA,WAAA;AAAA;AAAA,KAGU,eAAA;EACV,IAAA;EACA,KAAA,EAAO,UAAA;EACP,WAAA;AAAA;AAAA,KAGU,UAAA,GACR,gBAAA,GACA,gBAAA,GACA,iBAAA,GACA,gBAAA,GACA,eAAA;AAAA,iBAEY,4BAAA,CACd,gBAAA,EAAkB,SAAA,KACjB,UAAA;AAAA,iBAuBa,4BAAA,CACd,UAAA,EAAY,UAAA,GACX,SAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Parameter } from "../types/action.mjs";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/json-schema.d.ts
|
|
5
4
|
type JSONSchemaString = {
|
|
@@ -29,8 +28,6 @@ type JSONSchemaArray = {
|
|
|
29
28
|
type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaBoolean | JSONSchemaObject | JSONSchemaArray;
|
|
30
29
|
declare function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema;
|
|
31
30
|
declare function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[];
|
|
32
|
-
declare function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean, definitions?: Record<string, any>, visitedRefs?: Set<string>): z.ZodSchema;
|
|
33
|
-
declare function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any;
|
|
34
31
|
//#endregion
|
|
35
|
-
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema,
|
|
32
|
+
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters };
|
|
36
33
|
//# sourceMappingURL=json-schema.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.mts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-schema.d.mts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":";;;KAEY,gBAAA;EACV,IAAA;EACA,WAAA;EACA,IAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,iBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,UAAA;EAC5B,QAAA;EACA,WAAA;AAAA;AAAA,KAGU,eAAA;EACV,IAAA;EACA,KAAA,EAAO,UAAA;EACP,WAAA;AAAA;AAAA,KAGU,UAAA,GACR,gBAAA,GACA,gBAAA,GACA,iBAAA,GACA,gBAAA,GACA,eAAA;AAAA,iBAEY,4BAAA,CACd,gBAAA,EAAkB,SAAA,KACjB,UAAA;AAAA,iBAuBa,4BAAA,CACd,UAAA,EAAY,UAAA,GACX,SAAA"}
|