@copilotkit/shared 1.84.0 → 1.84.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function(global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('graphql'), require('zod'), require('uuid'), require('partial-json'), require('@ag-ui/client')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'graphql', 'zod', 'uuid', 'partial-json', '@ag-ui/client'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitShared = {}), global.GraphQL,global.Zod,global.UUID,global.PartialJSON,global.AgUIClient));
5
- })(this, function(exports, graphql, zod, uuid, partial_json, _ag_ui_client) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('graphql'), require('zod'), require('uuid'), require('partial-json'), require('@ag-ui/client'), require('zod-to-json-schema')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'graphql', 'zod', 'uuid', 'partial-json', '@ag-ui/client', 'zod-to-json-schema'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitShared = {}), global.GraphQL,global.Zod,global.UUID,global.PartialJSON,global.AgUIClient,global.zod_to_json_schema));
5
+ })(this, function(exports, graphql, zod, uuid, partial_json, _ag_ui_client, zod_to_json_schema) {
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
7
7
  //#region \0rolldown/runtime.js
8
8
  var __create = Object.create;
@@ -2323,7 +2323,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2323
2323
 
2324
2324
  //#endregion
2325
2325
  //#region package.json
2326
- var version = "1.84.0";
2326
+ var version = "1.84.1";
2327
2327
 
2328
2328
  //#endregion
2329
2329
  //#region src/generative-ui/basic-functions.ts
@@ -3162,6 +3162,264 @@ Use the SAME surfaceId as the main surface. Match action names to button action
3162
3162
  */
3163
3163
  const GENERATIVE_UI_MARKDOWN_GUIDELINES = buildGenerativeUIMarkdownGuidelines();
3164
3164
 
3165
+ //#endregion
3166
+ //#region src/a2ui-catalog-schema.ts
3167
+ /**
3168
+ * Context description used to identify the A2UI component schema in
3169
+ * RunAgentInput.context. Must match the constant in @ag-ui/a2ui-middleware so
3170
+ * the middleware can overwrite a frontend-provided schema with a server-side one.
3171
+ */
3172
+ const A2UI_SCHEMA_CONTEXT_DESCRIPTION = "A2UI Component Schema — available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.";
3173
+ /** Id of the A2UI v0.9 basic catalog. */
3174
+ const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json";
3175
+ /**
3176
+ * Serialize a catalog's Zod schemas in the A2UI v0.9 inline catalog format.
3177
+ *
3178
+ * Each component composes `ComponentCommon` with its own properties, matching
3179
+ * the flat wire format the agent must produce:
3180
+ *
3181
+ * { "Column": { "allOf": [
3182
+ * { "$ref": "common_types.json#/$defs/ComponentCommon" },
3183
+ * { "properties": { "component": {"const":"Column"}, "gap": ..., "children": ... },
3184
+ * "required": ["component"] }
3185
+ * ]}}
3186
+ *
3187
+ * This follows `getClientCapabilities` in `@a2ui/web_core` with these
3188
+ * deliberate differences:
3189
+ *
3190
+ * - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which
3191
+ * would dangle once properties move under `allOf[1]`.
3192
+ * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but
3193
+ * the shape it replaced is kept once under
3194
+ * `"common_types.json": { "$defs": { <Name>: ... } }`. Every
3195
+ * `common_types.json#/$defs/<Name>` ref therefore resolves within the
3196
+ * payload, both for agents that only see it as prompt text and for SDKs
3197
+ * (such as Google's A2UI SDK used by ADK) that read the `$ref`. Each type is
3198
+ * stated once rather than at every use site, which keeps the payload small.
3199
+ * A use whose shape differs from the stored one keeps its shape inline next
3200
+ * to the `$ref`, so the agent never sees a looser type than the client
3201
+ * accepts.
3202
+ * - A `REF:` marker on a schema's root only sets its description; replacing
3203
+ * the root would drop every property.
3204
+ * - A component's root `.describe()` is kept as the component `description`.
3205
+ * - Function parameters drop `$schema` and the description already given on
3206
+ * the function itself, to keep the prompt small.
3207
+ */
3208
+ function extractA2UICatalogSchemas(catalog) {
3209
+ const components = Object.create(null);
3210
+ const commonTypes = Object.create(null);
3211
+ for (const [name, component] of catalog.components) {
3212
+ var _schema$properties, _schema$required;
3213
+ const schema = serializeA2UISchema(component.schema, commonTypes);
3214
+ const properties = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
3215
+ const required = (_schema$required = schema.required) !== null && _schema$required !== void 0 ? _schema$required : [];
3216
+ components[name] = {
3217
+ ...typeof schema.description === "string" ? { description: schema.description } : {},
3218
+ allOf: [{ $ref: "common_types.json#/$defs/ComponentCommon" }, {
3219
+ properties: {
3220
+ component: { const: name },
3221
+ ...properties
3222
+ },
3223
+ required: ["component", ...required]
3224
+ }]
3225
+ };
3226
+ }
3227
+ const functions = catalogFunctions(catalog.functions).map((fn) => {
3228
+ var _fn$returnType;
3229
+ const { description, ...parameters } = serializeA2UISchema(fn.schema, commonTypes);
3230
+ return {
3231
+ name: fn.name,
3232
+ ...typeof description === "string" ? { description } : {},
3233
+ returnType: (_fn$returnType = fn.returnType) !== null && _fn$returnType !== void 0 ? _fn$returnType : "any",
3234
+ parameters
3235
+ };
3236
+ });
3237
+ const theme = catalog.themeSchema ? serializeA2UISchema(catalog.themeSchema, commonTypes).properties : void 0;
3238
+ return {
3239
+ catalogId: catalog.id,
3240
+ components,
3241
+ ...functions.length > 0 ? { functions } : {},
3242
+ ...theme ? { theme } : {},
3243
+ ...Object.keys(commonTypes).length > 0 ? { "common_types.json": { $defs: commonTypes } } : {}
3244
+ };
3245
+ }
3246
+ /**
3247
+ * Build a context string describing the catalog's id and the components it
3248
+ * adds beyond the basic catalog.
3249
+ *
3250
+ * Schemas are serialized as in {@link extractA2UICatalogSchemas}, with the
3251
+ * common types they reference listed once after the components.
3252
+ *
3253
+ * When `options.includeSchema` is `false`, custom components are listed by name
3254
+ * only and their JSON schemas are omitted.
3255
+ */
3256
+ function buildA2UICatalogContextValue(catalog, basicComponentNames, options) {
3257
+ const lines = ["Available A2UI catalog:"];
3258
+ if (catalog.id === A2UI_BASIC_CATALOG_ID) {
3259
+ lines.push(`- ${catalog.id} (basic catalog)`);
3260
+ return lines.join("\n");
3261
+ }
3262
+ const isSuperset = [...basicComponentNames].every((name) => catalog.components.has(name));
3263
+ lines.push(`- ${catalog.id}`);
3264
+ if (isSuperset) lines.push(" Extends the basic catalog with all standard components plus:");
3265
+ else {
3266
+ lines.push(" Custom catalog (does NOT include all basic components).");
3267
+ lines.push(" Custom components:");
3268
+ }
3269
+ const commonTypes = Object.create(null);
3270
+ for (const [name, component] of catalog.components) {
3271
+ if (basicComponentNames.has(name)) continue;
3272
+ if ((options === null || options === void 0 ? void 0 : options.includeSchema) === false) {
3273
+ lines.push(` - ${name}`);
3274
+ continue;
3275
+ }
3276
+ lines.push(` - ${name}:`);
3277
+ lines.push(indented(serializeA2UISchema(component.schema, commonTypes)));
3278
+ }
3279
+ if (Object.keys(commonTypes).length > 0) {
3280
+ lines.push(" Common types referenced above (common_types.json#/$defs):");
3281
+ lines.push(indented(commonTypes));
3282
+ }
3283
+ return lines.join("\n");
3284
+ }
3285
+ /** JSON for the catalog context value, indented under a list item. */
3286
+ function indented(value) {
3287
+ return ` ${JSON.stringify(value, null, 2).split("\n").join("\n ")}`;
3288
+ }
3289
+ /** Raw zod-to-json-schema output per Zod schema, stored as JSON text. */
3290
+ const serializedSchemas = /* @__PURE__ */ new WeakMap();
3291
+ /**
3292
+ * Convert one A2UI Zod schema to JSON Schema 2019-09, inlining reused schemas
3293
+ * and resolving `REF:` markers (see {@link extractA2UICatalogSchemas}). The
3294
+ * shapes behind `common_types.json` refs are recorded in `commonTypes`; pass
3295
+ * the same map for every schema of one payload.
3296
+ *
3297
+ * The raw conversion is cached per schema object as JSON text, and every call
3298
+ * parses a fresh copy. The JSON round-trip, unlike structuredClone, never
3299
+ * throws on values such as a function or a Vue reactive proxy in a
3300
+ * `.default()`, and yields exactly what the agent receives.
3301
+ */
3302
+ function serializeA2UISchema(schema, commonTypes = Object.create(null)) {
3303
+ const key = typeof schema === "object" && schema !== null ? schema : null;
3304
+ let serialized = key ? serializedSchemas.get(key) : void 0;
3305
+ if (serialized === void 0) {
3306
+ const jsonSchema = (0, zod_to_json_schema.zodToJsonSchema)(schema, {
3307
+ target: "jsonSchema2019-09",
3308
+ $refStrategy: "none",
3309
+ override: (_def, refs, seen, forceResolution) => seen && !forceResolution && seen.path.length < refs.currentPath.length && seen.path.every((part, i) => refs.currentPath[i] === part) ? {} : zod_to_json_schema.ignoreOverride
3310
+ });
3311
+ delete jsonSchema.$schema;
3312
+ serialized = JSON.stringify(jsonSchema);
3313
+ if (key) serializedSchemas.set(key, serialized);
3314
+ }
3315
+ const root = JSON.parse(serialized);
3316
+ const marker = parseRefMarker(root.description);
3317
+ if (marker) {
3318
+ delete root.description;
3319
+ if (marker.description) root.description = marker.description;
3320
+ }
3321
+ return resolveSubschemas(root, commonTypes);
3322
+ }
3323
+ /** Keywords whose value is a subschema, or an array of subschemas. */
3324
+ const SUBSCHEMA_KEYWORDS = [
3325
+ "items",
3326
+ "additionalItems",
3327
+ "additionalProperties",
3328
+ "unevaluatedItems",
3329
+ "unevaluatedProperties",
3330
+ "contains",
3331
+ "propertyNames",
3332
+ "not",
3333
+ "if",
3334
+ "then",
3335
+ "else",
3336
+ "allOf",
3337
+ "anyOf",
3338
+ "oneOf",
3339
+ "prefixItems"
3340
+ ];
3341
+ /** Keywords whose value maps names to subschemas. */
3342
+ const SUBSCHEMA_MAP_KEYWORDS = [
3343
+ "properties",
3344
+ "patternProperties",
3345
+ "dependentSchemas",
3346
+ "$defs",
3347
+ "definitions"
3348
+ ];
3349
+ const COMMON_TYPE_REF = /^common_types\.json#\/\$defs\/([^/]+)$/;
3350
+ function isObject(value) {
3351
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3352
+ }
3353
+ /**
3354
+ * Split a `REF:<ref>|<description>` marker at its first `|`, so a description
3355
+ * containing `|` is kept whole. The convention comes from
3356
+ * `MessageProcessor.processRefs` in `@a2ui/web_core`.
3357
+ */
3358
+ function parseRefMarker(description) {
3359
+ if (typeof description !== "string" || !description.startsWith("REF:")) return;
3360
+ const body = description.slice(4);
3361
+ const separator = body.indexOf("|");
3362
+ return separator === -1 ? { ref: body } : {
3363
+ ref: body.slice(0, separator),
3364
+ description: body.slice(separator + 1)
3365
+ };
3366
+ }
3367
+ /**
3368
+ * Resolve `REF:` markers in a schema's subschemas, innermost first, so a
3369
+ * stored common type refers to the types it contains by bare `$ref` too.
3370
+ *
3371
+ * Only schema-valued keywords are traversed, so literal values under
3372
+ * `default`, `const`, `enum` or `examples` are never rewritten.
3373
+ */
3374
+ function resolveSubschemas(node, commonTypes) {
3375
+ const resolve = (value) => Array.isArray(value) ? value.map(resolve) : isObject(value) ? resolveRefMarker(resolveSubschemas(value, commonTypes), commonTypes) : value;
3376
+ const out = { ...node };
3377
+ for (const keyword of SUBSCHEMA_KEYWORDS) if (keyword in out) out[keyword] = resolve(out[keyword]);
3378
+ for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
3379
+ const map = out[keyword];
3380
+ if (isObject(map)) out[keyword] = Object.fromEntries(Object.entries(map).map(([name, child]) => [name, resolve(child)]));
3381
+ }
3382
+ return out;
3383
+ }
3384
+ /**
3385
+ * Turn a node carrying a `REF:` marker into a bare `$ref`, recording the
3386
+ * shape it replaced under its `common_types.json` name. A shape that differs
3387
+ * from the one already recorded, or a ref outside `common_types.json`, stays
3388
+ * inline next to the `$ref`.
3389
+ */
3390
+ function resolveRefMarker(node, commonTypes) {
3391
+ var _COMMON_TYPE_REF$exec;
3392
+ const marker = parseRefMarker(node.description);
3393
+ if (!marker) return node;
3394
+ const { description: _marker, ...shape } = node;
3395
+ const ref = {
3396
+ $ref: marker.ref,
3397
+ ...marker.description ? { description: marker.description } : {}
3398
+ };
3399
+ const name = (_COMMON_TYPE_REF$exec = COMMON_TYPE_REF.exec(marker.ref)) === null || _COMMON_TYPE_REF$exec === void 0 ? void 0 : _COMMON_TYPE_REF$exec[1];
3400
+ if (name !== void 0) {
3401
+ const known = commonTypes[name];
3402
+ if (known === void 0) {
3403
+ commonTypes[name] = shape;
3404
+ return ref;
3405
+ }
3406
+ if (JSON.stringify(known) === JSON.stringify(shape)) return ref;
3407
+ }
3408
+ return {
3409
+ ...ref,
3410
+ ...shape
3411
+ };
3412
+ }
3413
+ /**
3414
+ * Read a catalog's functions, tolerating catalog-shaped objects whose
3415
+ * `functions` is missing, a plain object or an array, and skipping entries
3416
+ * without a name or schema.
3417
+ */
3418
+ function catalogFunctions(functions) {
3419
+ if (typeof functions !== "object" || functions === null) return [];
3420
+ return (functions instanceof Map ? [...functions.values()] : Array.isArray(functions) ? functions : Object.values(functions)).filter((fn) => typeof fn === "object" && fn !== null && typeof fn.name === "string" && typeof fn.schema === "object" && fn.schema !== null);
3421
+ }
3422
+
3165
3423
  //#endregion
3166
3424
  //#region src/a2ui-envelope.ts
3167
3425
  /**
@@ -4401,6 +4659,7 @@ ${rules.map((rule, index) => `${index + 1}. ${rule}`).join("\n")}`,
4401
4659
  }
4402
4660
 
4403
4661
  //#endregion
4662
+ exports.A2UI_BASIC_CATALOG_ID = A2UI_BASIC_CATALOG_ID;
4404
4663
  exports.A2UI_BASIC_FUNCTIONS = A2UI_BASIC_FUNCTIONS;
4405
4664
  exports.A2UI_CHILD_LIST_MARK = A2UI_CHILD_LIST_MARK;
4406
4665
  exports.A2UI_CHILD_LIST_REF = A2UI_CHILD_LIST_REF;
@@ -4410,6 +4669,7 @@ exports.A2UI_COMPONENT_ID_REF = A2UI_COMPONENT_ID_REF;
4410
4669
  exports.A2UI_DEFAULT_DESIGN_GUIDELINES = A2UI_DEFAULT_DESIGN_GUIDELINES;
4411
4670
  exports.A2UI_DEFAULT_GENERATION_GUIDELINES = A2UI_DEFAULT_GENERATION_GUIDELINES;
4412
4671
  exports.A2UI_INDEX_FUNCTION = A2UI_INDEX_FUNCTION;
4672
+ exports.A2UI_SCHEMA_CONTEXT_DESCRIPTION = A2UI_SCHEMA_CONTEXT_DESCRIPTION;
4413
4673
  exports.A2UI_VERSION = A2UI_VERSION;
4414
4674
  exports.AG_UI_CHANNEL_EVENT = AG_UI_CHANNEL_EVENT;
4415
4675
  exports.ALL_GENERATIVE_UI_GUIDE_FEATURES = ALL_GENERATIVE_UI_GUIDE_FEATURES;
@@ -4477,6 +4737,7 @@ exports.UpgradeRequiredError = UpgradeRequiredError;
4477
4737
  exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
4478
4738
  exports.applyChildRefMarks = applyChildRefMarks;
4479
4739
  exports.applyDescriptionOverrides = applyDescriptionOverrides;
4740
+ exports.buildA2UICatalogContextValue = buildA2UICatalogContextValue;
4480
4741
  exports.buildCompactGenerativeUISchema = buildCompactGenerativeUISchema;
4481
4742
  exports.buildGenerativeUIMarkdownGuidelines = buildGenerativeUIMarkdownGuidelines;
4482
4743
  exports.buildGenerativeUIPrompt = buildGenerativeUIPrompt;
@@ -4499,6 +4760,7 @@ exports.ensureStructuredError = ensureStructuredError;
4499
4760
  exports.envelopeToManifest = envelopeToManifest;
4500
4761
  exports.exceedsMaxSize = exceedsMaxSize;
4501
4762
  exports.executeConditions = executeConditions;
4763
+ exports.extractA2UICatalogSchemas = extractA2UICatalogSchemas;
4502
4764
  exports.extractRenderUIArgs = extractRenderUIArgs;
4503
4765
  exports.finalizeRunEvents = finalizeRunEvents;
4504
4766
  exports.firstNonBlankTelemetryId = firstNonBlankTelemetryId;
@@ -4560,6 +4822,7 @@ exports.safeParseToolArgs = safeParseToolArgs;
4560
4822
  exports.schemaCoverage = schemaCoverage;
4561
4823
  exports.schemaToJsonSchema = schemaToJsonSchema;
4562
4824
  exports.selectPromptItems = selectPromptItems;
4825
+ exports.serializeA2UISchema = serializeA2UISchema;
4563
4826
  exports.shouldEnableInspector = shouldEnableInspector;
4564
4827
  exports.stripIntelligenceRoutingFields = stripIntelligenceRoutingFields;
4565
4828
  exports.styledConsole = styledConsole;