@copilotkit/runtime 2.0.0-rc.44 → 2.0.0-rc.46
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/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/generative-ui/a2ui-v09-operations.cjs +77 -3
- package/dist/runtime/generative-ui/a2ui-v09-operations.cjs.map +1 -1
- package/dist/runtime/generative-ui/a2ui-v09-operations.mjs +78 -4
- package/dist/runtime/generative-ui/a2ui-v09-operations.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/runtime/core/package-info.ts
|
|
3
3
|
const RUNTIME_PACKAGE_NAME = "@copilotkit/runtime";
|
|
4
|
-
const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.
|
|
4
|
+
const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.46";
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
exports.RUNTIME_PACKAGE_NAME = RUNTIME_PACKAGE_NAME;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/runtime/core/package-info.ts
|
|
2
2
|
const RUNTIME_PACKAGE_NAME = "@copilotkit/runtime";
|
|
3
|
-
const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.
|
|
3
|
+
const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.46";
|
|
4
4
|
|
|
5
5
|
//#endregion
|
|
6
6
|
export { RUNTIME_PACKAGE_NAME, RUNTIME_PACKAGE_VERSION };
|
|
@@ -343,6 +343,14 @@ function surfaceIdOf(op) {
|
|
|
343
343
|
if (require_usage.isRecord(payload) && typeof payload.surfaceId === "string") return payload.surfaceId || void 0;
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* The error of a `failed` lifecycle snapshot: the agent's A2UI recovery
|
|
348
|
+
* gave up (`a2ui_recovery_exhausted`). Undefined for any other content.
|
|
349
|
+
*/
|
|
350
|
+
function failedLifecycleError(content) {
|
|
351
|
+
if (!require_usage.isRecord(content) || content.status !== "failed") return void 0;
|
|
352
|
+
return (typeof content.error === "string" && content.error ? content.error : "A2UI generation failed").slice(0, _copilotkit_shared.GENERATIVE_UI_MAX_REJECTION_LENGTH);
|
|
353
|
+
}
|
|
346
354
|
/** The operations of `a2ui-surface` content. Lifecycle content has none. */
|
|
347
355
|
function readOperations(content) {
|
|
348
356
|
if (!require_usage.isRecord(content)) return [];
|
|
@@ -436,6 +444,35 @@ function applyJsonPatch(document, patch) {
|
|
|
436
444
|
return root;
|
|
437
445
|
}
|
|
438
446
|
/**
|
|
447
|
+
* The operations of the next snapshot of a surface, so that the client
|
|
448
|
+
* applies every change of the source.
|
|
449
|
+
*
|
|
450
|
+
* The client applies only the operations after the ones it applied, when the
|
|
451
|
+
* operation at its last applied index did not change. A source that changes
|
|
452
|
+
* an earlier operation but not that one (a progressive render that rewrites
|
|
453
|
+
* its components, then sends the same data again) would lose the change. In
|
|
454
|
+
* that case the changed operations of the source are appended to the sent
|
|
455
|
+
* ones: v0.9 updates replace by id or path, so sending them again is safe,
|
|
456
|
+
* and a second createSurface is left out. In every other case the source
|
|
457
|
+
* operations go as they are: the client either extends its surface with them
|
|
458
|
+
* or builds it again from them.
|
|
459
|
+
*
|
|
460
|
+
* @param lastSource - The source operations of the last snapshot (none
|
|
461
|
+
* before the first one).
|
|
462
|
+
* @param sent - The operations of the last snapshot.
|
|
463
|
+
* @param source - The source operations now.
|
|
464
|
+
* @returns The operations of the next snapshot.
|
|
465
|
+
*/
|
|
466
|
+
function clientOperations(lastSource, sent, source) {
|
|
467
|
+
let same = 0;
|
|
468
|
+
while (same < lastSource.length && same < source.length && JSON.stringify(lastSource[same]) === JSON.stringify(source[same])) same++;
|
|
469
|
+
const appended = source.slice(same);
|
|
470
|
+
if (same === lastSource.length) return [...sent, ...appended];
|
|
471
|
+
const last = sent.length - 1;
|
|
472
|
+
if (source.length < sent.length || JSON.stringify(source[last]) !== JSON.stringify(sent[last])) return source;
|
|
473
|
+
return [...sent, ...appended.filter((op) => !("createSurface" in op))];
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
439
476
|
* Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native
|
|
440
477
|
* A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass
|
|
441
478
|
* every event of the run through `transform`, in order.
|
|
@@ -461,7 +498,11 @@ function applyJsonPatch(document, patch) {
|
|
|
461
498
|
* operations are appended to its message with an `ACTIVITY_DELTA`, as
|
|
462
499
|
* the `render_ui` path updates an existing surface.
|
|
463
500
|
* - A lifecycle snapshot (`status: "building"` and so on, no operations)
|
|
464
|
-
* names no surface, so it is consumed.
|
|
501
|
+
* names no surface, so it is consumed. A `failed` one (the agent's
|
|
502
|
+
* recovery gave up) becomes a surface with no operations, status
|
|
503
|
+
* "error", and its error as the one rejected entry, so the chat shows
|
|
504
|
+
* that the UI could not be made. Its surfaceId is the source messageId.
|
|
505
|
+
* Every other event passes through.
|
|
465
506
|
*
|
|
466
507
|
* @example
|
|
467
508
|
* ```ts
|
|
@@ -472,7 +513,34 @@ function applyJsonPatch(document, patch) {
|
|
|
472
513
|
function createA2UIV09ActivityUpgrader() {
|
|
473
514
|
const sources = /* @__PURE__ */ new Map();
|
|
474
515
|
const surfaces = /* @__PURE__ */ new Map();
|
|
475
|
-
|
|
516
|
+
/** The source messages whose `failed` snapshot was sent. */
|
|
517
|
+
const failures = /* @__PURE__ */ new Set();
|
|
518
|
+
/** The surface that shows a failed lifecycle snapshot, sent once. */
|
|
519
|
+
const failureOf = (messageId, error) => {
|
|
520
|
+
if (failures.has(messageId)) return [];
|
|
521
|
+
failures.add(messageId);
|
|
522
|
+
const content = {
|
|
523
|
+
surfaceId: messageId,
|
|
524
|
+
target: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET,
|
|
525
|
+
catalogId: _copilotkit_shared_generative_ui.STANDARD_CATALOG_ID,
|
|
526
|
+
operations: [],
|
|
527
|
+
status: "error",
|
|
528
|
+
rejected: [{
|
|
529
|
+
index: 0,
|
|
530
|
+
reason: error
|
|
531
|
+
}],
|
|
532
|
+
a2uiSourceVersion: "0.9"
|
|
533
|
+
};
|
|
534
|
+
return [{
|
|
535
|
+
type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
|
|
536
|
+
messageId: (0, _copilotkit_shared.generativeUISurfaceMessageId)(messageId),
|
|
537
|
+
activityType: _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE,
|
|
538
|
+
content,
|
|
539
|
+
replace: true
|
|
540
|
+
}];
|
|
541
|
+
};
|
|
542
|
+
const snapshotOf = (surfaceId, state, source, rejected, version) => {
|
|
543
|
+
const operations = clientOperations(state.snapshotSource, state.snapshotOperations, source);
|
|
476
544
|
const create = operations.find((op) => "createSurface" in op);
|
|
477
545
|
const content = {
|
|
478
546
|
surfaceId,
|
|
@@ -486,6 +554,8 @@ function createA2UIV09ActivityUpgrader() {
|
|
|
486
554
|
const json = JSON.stringify(content);
|
|
487
555
|
if (json === state.lastSnapshot) return [];
|
|
488
556
|
state.lastSnapshot = json;
|
|
557
|
+
state.snapshotSource = source;
|
|
558
|
+
state.snapshotOperations = operations;
|
|
489
559
|
return [{
|
|
490
560
|
type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
|
|
491
561
|
messageId: (0, _copilotkit_shared.generativeUISurfaceMessageId)(surfaceId),
|
|
@@ -579,6 +649,8 @@ function createA2UIV09ActivityUpgrader() {
|
|
|
579
649
|
if (!state) {
|
|
580
650
|
state = {
|
|
581
651
|
parts: /* @__PURE__ */ new Map(),
|
|
652
|
+
snapshotSource: [],
|
|
653
|
+
snapshotOperations: [],
|
|
582
654
|
sentOperations: [],
|
|
583
655
|
sentRejected: "[]"
|
|
584
656
|
};
|
|
@@ -586,7 +658,9 @@ function createA2UIV09ActivityUpgrader() {
|
|
|
586
658
|
}
|
|
587
659
|
state.parts.set(messageId, part);
|
|
588
660
|
}
|
|
589
|
-
|
|
661
|
+
const events = [...touched].flatMap(emitSurface);
|
|
662
|
+
const error = failedLifecycleError(sources.get(messageId));
|
|
663
|
+
return error === void 0 ? events : [...events, ...failureOf(messageId, error)];
|
|
590
664
|
};
|
|
591
665
|
return { transform(event) {
|
|
592
666
|
if (event.type === _ag_ui_client.EventType.ACTIVITY_SNAPSHOT) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-v09-operations.cjs","names":["isRecord","A2UI_VERSION","STANDARD_CATALOG_ID","GENERATIVE_UI_CHAT_TARGET","EventType","GENERATIVE_UI_ACTIVITY_TYPE"],"sources":["../../../src/runtime/generative-ui/a2ui-v09-operations.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type {\n ActivityDeltaEvent,\n ActivitySnapshotEvent,\n BaseEvent,\n} from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CHAT_TARGET,\n cloneValue,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\nimport { STANDARD_CATALOG_ID } from \"@copilotkit/shared/generative-ui\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The activity type and content key of v0.9 surfaces, as\n * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.\n */\nconst A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\nconst A2UI_OPERATIONS_KEY = \"a2ui_operations\";\n\n/** The `version` values of A2UI v0.9 messages. */\nconst V09_VERSIONS: ReadonlySet<string> = new Set([\"v0.9\", \"v0.9.1\"]);\nconst V09_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n] as const;\ntype V09Kind = (typeof V09_KINDS)[number];\n\n/**\n * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of\n * the published catalog document. Both become the standard catalog, which has\n * the same 18 components.\n */\nconst V09_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\",\n \"https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json\",\n]);\n\n/**\n * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for\n * example ADK) send. It has the 18 components of the v0.9 basic catalog\n * with 1.0 bindings, so it becomes the standard catalog too.\n */\nconst V10_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json\",\n]);\n\n/** The A2UI version that an `a2ui-surface` operation was written in. */\ntype SourceVersion = \"0.9\" | \"1.0\";\n\n/** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */\nconst HEADING_SIZES: Readonly<Record<string, string>> = {\n h1: \"2xl\",\n h2: \"xl\",\n h3: \"lg\",\n h4: \"md\",\n h5: \"sm\",\n};\n\n/** The one v0.9 operation key of `op`, when it has exactly one. */\nfunction v09Kind(op: Record<string, unknown>): V09Kind | undefined {\n const kinds = V09_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/**\n * True for an A2UI v0.9 operation: an object whose `version` is `\"v0.9\"` (or\n * `\"v0.9.1\"`). An object without `version` counts when it has exactly one\n * v0.9 operation key with an object payload. A 1.0 operation always carries\n * `version: \"1.0\"` (the client rejects one without it), and v0.8 uses other\n * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with\n * a v0.9 key can only be v0.9. Agents leave `version` out often enough that\n * requiring it would drop their surfaces.\n *\n * @example\n * ```ts\n * isA2UIV09Operation({ version: \"v0.9\", deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ version: \"1.0\", deleteSurface: { surfaceId: \"s\" } }); // false\n * ```\n */\nexport function isA2UIV09Operation(value: unknown): boolean {\n if (!isRecord(value)) return false;\n if (value.version !== undefined) {\n return typeof value.version === \"string\" && V09_VERSIONS.has(value.version);\n }\n const kind = v09Kind(value);\n return kind !== undefined && isRecord(value[kind]);\n}\n\n// Checked with `ok === false`: runtime compiles non-strict, where a check of\n// `reason` does not narrow the union.\ntype Converted<T> = { ok: true; value: T } | { ok: false; reason: string };\n\nconst ok = <T>(value: T): { ok: true; value: T } => ({ ok: true, value });\nconst failed = (reason: string): { ok: false; reason: string } => ({\n ok: false,\n reason,\n});\n\n/**\n * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ \"@path\" }` and\n * `{ call, args }` becomes `{ \"@call\", args }`, at any depth. Literals stay.\n */\nfunction convertValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(convertValue);\n if (!isRecord(value)) return value;\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.path === \"string\") {\n return { \"@path\": value.path };\n }\n const isCall =\n typeof value.call === \"string\" &&\n keys.every(\n (key) => key === \"call\" || key === \"args\" || key === \"returnType\",\n );\n if (isCall) return convertCall(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, convertValue(item)]),\n );\n}\n\n/** A v0.9 function call `{ call, args, returnType }` as `{ \"@call\", args }`. */\nfunction convertCall(call: Record<string, unknown>) {\n return {\n \"@call\": call.call as string,\n ...(call.args === undefined ? {} : { args: convertValue(call.args) }),\n };\n}\n\n/** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */\nfunction isV09Action(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n return (\n keys.length === 1 && (isRecord(value.event) || isRecord(value.functionCall))\n );\n}\n\n/**\n * A v0.9 action as a 1.0 event binding. The event keeps its name and\n * context (with converted values); a function call gets the `@call` form.\n */\nfunction convertAction(action: unknown): Converted<unknown> {\n if (!isV09Action(action)) {\n return failed('action must be { \"event\": ... } or { \"functionCall\": ... }');\n }\n if (isRecord(action.functionCall)) {\n const call = action.functionCall;\n if (typeof call.call !== \"string\" || !call.call) {\n return failed(\"action.functionCall.call must be a function name\");\n }\n return ok({ functionCall: convertCall(call) });\n }\n const event = action.event as Record<string, unknown>;\n if (typeof event.name !== \"string\" || !event.name) {\n return failed(\"action.event.name is required\");\n }\n return ok({\n event: {\n name: event.name,\n ...(event.context === undefined\n ? {}\n : { context: convertValue(event.context) }),\n },\n });\n}\n\n/**\n * The basic-catalog changes of one component. Every other prop keeps its\n * name; the 1.0 standard catalog uses the v0.9 names.\n *\n * - `Text` with a heading `variant` becomes `Title` (h1 \"2xl\" to h5 \"sm\"),\n * with `caption` it becomes `Caption`; `variant` goes. Title and Caption\n * have no `weight`, so it goes too.\n * - `Button.action` becomes `onClick`.\n * - `TextField.validationRegexp` becomes a `regex` check on its value.\n */\nfunction applyBasicCatalogChanges(node: Record<string, unknown>) {\n if (node.component === \"Text\" && \"variant\" in node) {\n const { variant, ...rest } = node;\n const size =\n typeof variant === \"string\" ? HEADING_SIZES[variant] : undefined;\n if (size !== undefined) {\n const { weight: _weight, ...title } = rest;\n return { ...title, component: \"Title\", size };\n }\n if (variant === \"caption\") {\n const { weight: _weight, ...caption } = rest;\n return { ...caption, component: \"Caption\" };\n }\n return rest;\n }\n if (node.component === \"Button\" && \"action\" in node) {\n const { action, ...rest } = node;\n return { ...rest, onClick: action };\n }\n if (node.component === \"TextField\" && \"validationRegexp\" in node) {\n const { validationRegexp, ...rest } = node;\n if (typeof validationRegexp !== \"string\" || rest.value === undefined) {\n return rest;\n }\n const check = {\n condition: {\n \"@call\": \"regex\",\n args: { value: rest.value, pattern: validationRegexp },\n },\n };\n const checks = Array.isArray(rest.checks) ? rest.checks : [];\n return { ...rest, checks: [...checks, check] };\n }\n return node;\n}\n\n/** One v0.9 component (flat format) as a 1.0 component node. */\nfunction convertComponent(node: unknown): Converted<A2UIComponentNode> {\n if (!isRecord(node) || typeof node.id !== \"string\" || !node.id) {\n return failed(\"a component needs a string id\");\n }\n if (typeof node.component !== \"string\" || !node.component) {\n return failed(\n `component \"${node.id}\": the component type must be a string (the v0.9 flat format)`,\n );\n }\n const converted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\") {\n converted[key] = value;\n } else if (key === \"action\" || isV09Action(value)) {\n const action = convertAction(value);\n if (action.ok === false) {\n return failed(`component \"${node.id}\": ${action.reason}`);\n }\n converted[key] = action.value;\n } else {\n converted[key] = convertValue(value);\n }\n }\n return ok(applyBasicCatalogChanges(converted) as A2UIComponentNode);\n}\n\nfunction convertUpdateComponents(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { components } = payload;\n if (!Array.isArray(components) || components.length === 0) {\n return failed(\"updateComponents.components must be a non-empty array\");\n }\n const nodes: A2UIComponentNode[] = [];\n for (const component of components) {\n const converted = convertComponent(component);\n if (converted.ok === false) return converted;\n nodes.push(converted.value);\n }\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n });\n}\n\n/**\n * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it\n * for `null`. At the root, removing means an empty data model.\n */\nfunction convertUpdateDataModel(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { path, value } = payload;\n if (path !== undefined && typeof path !== \"string\") {\n return failed(\"updateDataModel.path must be a string\");\n }\n const relative = typeof path === \"string\" ? path : \"\";\n const pointer = relative.startsWith(\"/\") ? relative : `/${relative}`;\n const isRoot = pointer === \"/\";\n if (isRoot && value !== undefined && !isRecord(value)) {\n return failed(\n \"a root updateDataModel value must be a JSON object in A2UI 1.0\",\n );\n }\n const nextValue = value === undefined ? (isRoot ? {} : null) : value;\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path: pointer, value: nextValue },\n });\n}\n\nfunction convertCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n): A2UIOperation {\n const { catalogId } = payload;\n const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;\n return {\n version: A2UI_VERSION,\n createSurface: {\n surfaceId,\n ...(typeof catalogId === \"string\" && catalogId\n ? {\n catalogId: V09_BASIC_CATALOG_IDS.has(catalogId)\n ? STANDARD_CATALOG_ID\n : catalogId,\n }\n : {}),\n ...(typeof sendDataModel === \"boolean\" ? { sendDataModel } : {}),\n },\n };\n}\n\n/** Basic catalog components as standard ones; anything else stays. */\nfunction standardComponents(components: unknown) {\n return Array.isArray(components)\n ? components.map((node) =>\n isRecord(node) ? applyBasicCatalogChanges(node) : node,\n )\n : components;\n}\n\n/**\n * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic\n * catalog id becomes the standard catalog id, and the basic catalog\n * components (inline in createSurface, or in updateComponents) get the\n * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.\n * Everything else stays; the client validates the operation.\n */\nfunction upgradeV10Operation(op: Record<string, unknown>): A2UIOperation {\n const { createSurface: create, updateComponents: update } = op;\n if (isRecord(create)) {\n const { catalogId } = create;\n return {\n ...op,\n createSurface: {\n ...create,\n ...(typeof catalogId === \"string\" &&\n V10_BASIC_CATALOG_IDS.has(catalogId)\n ? { catalogId: STANDARD_CATALOG_ID }\n : {}),\n ...(create.components === undefined\n ? {}\n : { components: standardComponents(create.components) }),\n },\n } as A2UIOperation;\n }\n if (isRecord(update)) {\n return {\n ...op,\n updateComponents: {\n ...update,\n ...(update.components === undefined\n ? {}\n : { components: standardComponents(update.components) }),\n },\n } as A2UIOperation;\n }\n return op as A2UIOperation;\n}\n\n/** One operation as 1.0, or why it cannot be converted. */\nfunction upgradeOperation(op: unknown): Converted<A2UIOperation> {\n if (!isRecord(op)) return failed(\"operation must be a JSON object\");\n if (op.version === A2UI_VERSION) return ok(upgradeV10Operation(op));\n if (!isA2UIV09Operation(op)) {\n return failed(\n typeof op.version === \"string\"\n ? `unsupported A2UI version \"${op.version}\"; only v0.9 and 1.0 operations are supported`\n : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const kind = v09Kind(op);\n if (!kind) {\n return failed(\n `operation must contain exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return failed(`${kind}.surfaceId is required`);\n }\n const { surfaceId } = payload;\n switch (kind) {\n case \"createSurface\":\n return ok(convertCreateSurface(payload, surfaceId));\n case \"updateComponents\":\n return convertUpdateComponents(payload, surfaceId);\n case \"updateDataModel\":\n return convertUpdateDataModel(payload, surfaceId);\n case \"deleteSurface\":\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n deleteSurface: { surfaceId },\n });\n }\n}\n\n/**\n * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.\n *\n * - createSurface: the v0.9 basic catalog id becomes the standard catalog\n * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no\n * 1.0 field and goes; `sendDataModel` stays.\n * - updateComponents: `{ path }` becomes `{ \"@path\" }` and `{ call, args }`\n * becomes `{ \"@call\", args }` at any depth; an action becomes an\n * `{ event }` or `{ functionCall }` binding; child lists and templates\n * stay. See {@link applyBasicCatalogChanges} for the props that change.\n * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at\n * the root.\n * - deleteSurface: unchanged.\n *\n * An operation that is already 1.0 (native, for example from ADK) keeps its\n * form: only the 1.0 basic catalog id becomes the standard catalog id, and\n * its basic catalog components get the same changes as v0.9 ones. Any other\n * operation, and any v0.9 operation that cannot be converted, goes to\n * `dropped` with the reason.\n *\n * @example\n * ```ts\n * upgradeA2UIV09Operations([\n * { version: \"v0.9\", updateDataModel: { surfaceId: \"s\", path: \"/x\" } },\n * ]);\n * // { operations: [{ version: \"1.0\", updateDataModel: { surfaceId: \"s\", path: \"/x\", value: null } }], dropped: [] }\n * ```\n */\nexport function upgradeA2UIV09Operations(operations: unknown[]): {\n operations: A2UIOperation[];\n dropped: Array<{ operation: unknown; reason: string }>;\n} {\n const upgraded: A2UIOperation[] = [];\n const dropped: Array<{ operation: unknown; reason: string }> = [];\n for (const operation of Array.isArray(operations) ? operations : []) {\n let result: Converted<A2UIOperation>;\n try {\n result = upgradeOperation(operation);\n } catch (error) {\n // A getter or a Proxy trap of the operation threw while it was read.\n result = failed(\n `operation could not be read: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n if (result.ok === false) {\n dropped.push({ operation, reason: result.reason });\n } else {\n upgraded.push(result.value);\n }\n }\n return { operations: upgraded, dropped };\n}\n\n/** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */\nfunction surfaceIdOf(op: unknown) {\n if (!isRecord(op)) return undefined;\n for (const kind of V09_KINDS) {\n const payload = op[kind];\n if (isRecord(payload) && typeof payload.surfaceId === \"string\") {\n return payload.surfaceId || undefined;\n }\n }\n return undefined;\n}\n\n/** The operations of `a2ui-surface` content. Lifecycle content has none. */\nfunction readOperations(content: unknown): unknown[] {\n if (!isRecord(content)) return [];\n const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;\n return Array.isArray(operations) ? operations : [];\n}\n\ntype JsonPatchOperation = {\n op: \"add\" | \"remove\" | \"replace\" | \"move\" | \"copy\" | \"test\";\n path: string;\n from?: string;\n value?: unknown;\n};\n\nfunction pointerSegments(pointer: string) {\n if (pointer === \"\") return [];\n if (!pointer.startsWith(\"/\")) throw new Error(`invalid pointer \"${pointer}\"`);\n return pointer\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Applies RFC 6902 operations to `document` in place and returns the new\n * root. Throws on a path that does not resolve, like `fast-json-patch` in\n * the AG-UI client, so a bad delta leaves the stored content alone.\n */\nfunction applyJsonPatch(document: unknown, patch: unknown): unknown {\n if (!Array.isArray(patch)) throw new Error(\"patch must be an array\");\n let root = document;\n const parentOf = (pointer: string) => {\n const segments = pointerSegments(pointer);\n const key = segments.pop();\n let parent: unknown = root;\n for (const segment of segments) {\n if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error(\"forbidden path\");\n parent = Array.isArray(parent)\n ? parent[Number(segment)]\n : isRecord(parent)\n ? parent[segment]\n : undefined;\n if (parent === undefined) throw new Error(`path \"${pointer}\" not found`);\n }\n if (key !== undefined && FORBIDDEN_SEGMENTS.has(key)) {\n throw new Error(\"forbidden path\");\n }\n return { parent, key };\n };\n const read = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) return root;\n if (Array.isArray(parent)) return parent[Number(key)];\n return isRecord(parent) ? parent[key] : undefined;\n };\n const remove = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) throw new Error(\"cannot remove the root\");\n if (Array.isArray(parent)) parent.splice(Number(key), 1);\n else if (isRecord(parent) && key in parent) delete parent[key];\n else throw new Error(`path \"${pointer}\" not found`);\n };\n const write = (pointer: string, value: unknown, insert: boolean) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) {\n root = value;\n } else if (Array.isArray(parent)) {\n const index = key === \"-\" ? parent.length : Number(key);\n if (!Number.isInteger(index) || index < 0 || index > parent.length) {\n throw new Error(`index \"${key}\" is out of range`);\n }\n parent.splice(index, insert ? 0 : 1, value);\n } else if (isRecord(parent)) {\n parent[key] = value;\n } else {\n throw new Error(`path \"${pointer}\" not found`);\n }\n };\n for (const entry of patch as JsonPatchOperation[]) {\n if (!isRecord(entry) || typeof entry.path !== \"string\") {\n throw new Error(\"invalid patch operation\");\n }\n switch (entry.op) {\n case \"add\":\n write(entry.path, cloneValue(entry.value), true);\n break;\n case \"replace\":\n if (read(entry.path) === undefined) {\n throw new Error(`path \"${entry.path}\" not found`);\n }\n write(entry.path, cloneValue(entry.value), false);\n break;\n case \"remove\":\n remove(entry.path);\n break;\n case \"copy\":\n write(entry.path, cloneValue(read(entry.from ?? \"\")), true);\n break;\n case \"move\": {\n const value = read(entry.from ?? \"\");\n remove(entry.from ?? \"\");\n write(entry.path, value, true);\n break;\n }\n case \"test\":\n if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) {\n throw new Error(`test failed at \"${entry.path}\"`);\n }\n break;\n default:\n throw new Error(`unknown patch op \"${String(entry.op)}\"`);\n }\n }\n return root;\n}\n\n/** One converted operation, with where it came from. */\ninterface SourceOperation {\n operation: A2UIOperation;\n /** Its index in the source message. */\n index: number;\n version: SourceVersion;\n}\n\n/** The converted part of one surface that one source message holds. */\ninterface SourcePart {\n operations: SourceOperation[];\n rejected: GenerativeUIRejectedOperation[];\n}\n\ninterface SurfaceState {\n /** The part of each source message, in the order they first touched it. */\n parts: Map<string, SourcePart>;\n /** JSON of the last snapshot content. */\n lastSnapshot?: string;\n /** Operations sent as deltas, for a surface created in an earlier run. */\n sentOperations: A2UIOperation[];\n /** JSON of the last `rejected` sent as a delta. */\n sentRejected: string;\n}\n\n/**\n * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native\n * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass\n * every event of the run through `transform`, in order.\n *\n * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per\n * messageId (a delta is applied to the stored content), and its\n * operations are converted with {@link upgradeA2UIV09Operations}.\n * - Each surface becomes one `generative-ui-surface` message,\n * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is\n * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the\n * cumulative 1.0 content: the operations of every source message for it,\n * in order, with only the first createSurface. The target is the chat,\n * the status is \"ready\", dropped operations are `rejected` (at their\n * index in the source message), and `a2uiSourceVersion` is \"0.9\" for a\n * surface written in v0.9.\n * - A surface written in native A2UI 1.0 (`version: \"1.0\"`, for example\n * from ADK) becomes the same `generative-ui-surface` message, without\n * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the\n * agent unchanged. One surface has one version, the version of its\n * first operation; an operation of the other version is rejected.\n * - A surface that this run updates but does not create (v0.9 sends no\n * second createSurface) was created in an earlier run, so its new\n * operations are appended to its message with an `ACTIVITY_DELTA`, as\n * the `render_ui` path updates an existing surface.\n * - A lifecycle snapshot (`status: \"building\"` and so on, no operations)\n * names no surface, so it is consumed. Every other event passes through.\n *\n * @example\n * ```ts\n * const upgrader = createA2UIV09ActivityUpgrader();\n * source.pipe(mergeMap((event) => upgrader.transform(event)));\n * ```\n */\nexport function createA2UIV09ActivityUpgrader(): {\n transform(event: BaseEvent): BaseEvent[];\n} {\n const sources = new Map<string, unknown>();\n const surfaces = new Map<string, SurfaceState>();\n\n const snapshotOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n version: SourceVersion,\n ): BaseEvent[] => {\n const create = operations.find((op) => \"createSurface\" in op);\n const catalogId =\n (create && \"createSurface\" in create && create.createSurface.catalogId) ||\n STANDARD_CATALOG_ID;\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId,\n operations,\n status: \"ready\",\n rejected,\n ...(version === \"0.9\" ? { a2uiSourceVersion: \"0.9\" as const } : {}),\n };\n const json = JSON.stringify(content);\n if (json === state.lastSnapshot) return [];\n state.lastSnapshot = json;\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content: cloneValue(content),\n replace: true,\n };\n return [event];\n };\n\n const deltaOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n ): BaseEvent[] => {\n const sent = state.sentOperations;\n let same = 0;\n while (\n same < sent.length &&\n same < operations.length &&\n JSON.stringify(sent[same]) === JSON.stringify(operations[same])\n ) {\n same++;\n }\n // Operations that changed after they were sent cannot be taken back.\n // v0.9 updates replace by id or path, so sending them again is safe.\n const patch: unknown[] = operations.slice(same).map((op) => ({\n op: \"add\",\n path: \"/operations/-\",\n value: cloneValue(op),\n }));\n const rejectedJson = JSON.stringify(rejected);\n if (rejectedJson !== state.sentRejected) {\n patch.push({ op: \"replace\", path: \"/rejected\", value: rejected });\n }\n state.sentOperations = operations;\n state.sentRejected = rejectedJson;\n if (patch.length === 0) return [];\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: patch as ActivityDeltaEvent[\"patch\"],\n };\n return [event];\n };\n\n const emitSurface = (surfaceId: string): BaseEvent[] => {\n const state = surfaces.get(surfaceId);\n if (!state) return [];\n const operations: A2UIOperation[] = [];\n const rejected: GenerativeUIRejectedOperation[] = [];\n let created = false;\n let version: SourceVersion | undefined;\n for (const part of state.parts.values()) {\n for (const { operation, index, version: opVersion } of part.operations) {\n version ??= opVersion;\n if (opVersion !== version) {\n rejected.push({\n index,\n reason: `surface \"${surfaceId}\" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`,\n });\n continue;\n }\n if (\"createSurface\" in operation) {\n // A second createSurface of the same id is rejected in 1.0.\n if (created) continue;\n created = true;\n }\n operations.push(operation);\n }\n rejected.push(...part.rejected);\n }\n return created\n ? snapshotOf(surfaceId, state, operations, rejected, version ?? \"0.9\")\n : deltaOf(surfaceId, state, operations, rejected);\n };\n\n /** Converts the stored content of one source message again. */\n const refresh = (messageId: string): BaseEvent[] => {\n const parts = new Map<string, SourcePart>();\n readOperations(sources.get(messageId)).forEach((op, index) => {\n // An operation with no surface cannot be shown anywhere.\n const surfaceId = surfaceIdOf(op);\n if (surfaceId === undefined) return;\n let part = parts.get(surfaceId);\n if (!part) {\n part = { operations: [], rejected: [] };\n parts.set(surfaceId, part);\n }\n const { operations, dropped } = upgradeA2UIV09Operations([op]);\n // Only v0.9 and 1.0 operations convert.\n const version: SourceVersion =\n isRecord(op) && op.version === A2UI_VERSION ? \"1.0\" : \"0.9\";\n for (const operation of operations) {\n part.operations.push({ operation, index, version });\n }\n for (const { reason } of dropped) part.rejected.push({ index, reason });\n });\n const touched = new Set(parts.keys());\n for (const [surfaceId, state] of surfaces) {\n if (!parts.has(surfaceId) && state.parts.delete(messageId)) {\n touched.add(surfaceId);\n }\n }\n for (const [surfaceId, part] of parts) {\n let state = surfaces.get(surfaceId);\n if (!state) {\n state = { parts: new Map(), sentOperations: [], sentRejected: \"[]\" };\n surfaces.set(surfaceId, state);\n }\n state.parts.set(messageId, part);\n }\n return [...touched].flatMap(emitSurface);\n };\n\n return {\n transform(event) {\n if (event.type === EventType.ACTIVITY_SNAPSHOT) {\n const snapshot = event as ActivitySnapshotEvent;\n if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n return [event];\n }\n const { messageId } = snapshot;\n // `replace: false` does not replace a message that already exists.\n if (snapshot.replace === false && sources.has(messageId)) return [];\n sources.set(messageId, cloneValue(snapshot.content));\n return refresh(messageId);\n }\n if (event.type === EventType.ACTIVITY_DELTA) {\n const delta = event as ActivityDeltaEvent;\n if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];\n const { messageId } = delta;\n if (!sources.has(messageId)) return [];\n let content: unknown;\n try {\n content = applyJsonPatch(\n cloneValue(sources.get(messageId)),\n delta.patch,\n );\n } catch {\n // The AG-UI client also skips a delta that does not apply.\n return [];\n }\n sources.set(messageId, content);\n return refresh(messageId);\n }\n return [event];\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,6BAA6B;AACnC,MAAM,sBAAsB;;AAG5B,MAAM,eAAoC,IAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AACrE,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACD;;;;;;AAQD,MAAM,wBAA6C,IAAI,IAAI,CACzD,0DACA,kEACD,CAAC;;;;;;AAOF,MAAM,wBAA6C,IAAI,IAAI,CACzD,kEACD,CAAC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S,OAAO;GACrC,IAAI,QAAQ,SAAS,IAAI,UAAU;AACnC,OAAI,CAAC,OAAO;AACV,YAAQ;KAAE,uBAAO,IAAI,KAAK;KAAE,gBAAgB,EAAE;KAAE,cAAc;KAAM;AACpE,aAAS,IAAI,WAAW,MAAM;;AAEhC,SAAM,MAAM,IAAI,WAAW,KAAK;;AAElC,SAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,YAAY;;AAG1C,QAAO,EACL,UAAU,OAAO;AACf,MAAI,MAAM,SAASG,wBAAU,mBAAmB;GAC9C,MAAM,WAAW;AACjB,OAAI,SAAS,iBAAiB,2BAC5B,QAAO,CAAC,MAAM;GAEhB,MAAM,EAAE,cAAc;AAEtB,OAAI,SAAS,YAAY,SAAS,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;AACnE,WAAQ,IAAI,8CAAsB,SAAS,QAAQ,CAAC;AACpD,UAAO,QAAQ,UAAU;;AAE3B,MAAI,MAAM,SAASA,wBAAU,gBAAgB;GAC3C,MAAM,QAAQ;AACd,OAAI,MAAM,iBAAiB,2BAA4B,QAAO,CAAC,MAAM;GACrE,MAAM,EAAE,cAAc;AACtB,OAAI,CAAC,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;GACtC,IAAI;AACJ,OAAI;AACF,cAAU,kDACG,QAAQ,IAAI,UAAU,CAAC,EAClC,MAAM,MACP;WACK;AAEN,WAAO,EAAE;;AAEX,WAAQ,IAAI,WAAW,QAAQ;AAC/B,UAAO,QAAQ,UAAU;;AAE3B,SAAO,CAAC,MAAM;IAEjB"}
|
|
1
|
+
{"version":3,"file":"a2ui-v09-operations.cjs","names":["isRecord","A2UI_VERSION","STANDARD_CATALOG_ID","GENERATIVE_UI_MAX_REJECTION_LENGTH","GENERATIVE_UI_CHAT_TARGET","EventType","GENERATIVE_UI_ACTIVITY_TYPE"],"sources":["../../../src/runtime/generative-ui/a2ui-v09-operations.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type {\n ActivityDeltaEvent,\n ActivitySnapshotEvent,\n BaseEvent,\n} from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CHAT_TARGET,\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n cloneValue,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\nimport { STANDARD_CATALOG_ID } from \"@copilotkit/shared/generative-ui\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The activity type and content key of v0.9 surfaces, as\n * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.\n */\nconst A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\nconst A2UI_OPERATIONS_KEY = \"a2ui_operations\";\n\n/** The `version` values of A2UI v0.9 messages. */\nconst V09_VERSIONS: ReadonlySet<string> = new Set([\"v0.9\", \"v0.9.1\"]);\nconst V09_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n] as const;\ntype V09Kind = (typeof V09_KINDS)[number];\n\n/**\n * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of\n * the published catalog document. Both become the standard catalog, which has\n * the same 18 components.\n */\nconst V09_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\",\n \"https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json\",\n]);\n\n/**\n * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for\n * example ADK) send. It has the 18 components of the v0.9 basic catalog\n * with 1.0 bindings, so it becomes the standard catalog too.\n */\nconst V10_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json\",\n]);\n\n/** The A2UI version that an `a2ui-surface` operation was written in. */\ntype SourceVersion = \"0.9\" | \"1.0\";\n\n/** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */\nconst HEADING_SIZES: Readonly<Record<string, string>> = {\n h1: \"2xl\",\n h2: \"xl\",\n h3: \"lg\",\n h4: \"md\",\n h5: \"sm\",\n};\n\n/** The one v0.9 operation key of `op`, when it has exactly one. */\nfunction v09Kind(op: Record<string, unknown>): V09Kind | undefined {\n const kinds = V09_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/**\n * True for an A2UI v0.9 operation: an object whose `version` is `\"v0.9\"` (or\n * `\"v0.9.1\"`). An object without `version` counts when it has exactly one\n * v0.9 operation key with an object payload. A 1.0 operation always carries\n * `version: \"1.0\"` (the client rejects one without it), and v0.8 uses other\n * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with\n * a v0.9 key can only be v0.9. Agents leave `version` out often enough that\n * requiring it would drop their surfaces.\n *\n * @example\n * ```ts\n * isA2UIV09Operation({ version: \"v0.9\", deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ version: \"1.0\", deleteSurface: { surfaceId: \"s\" } }); // false\n * ```\n */\nexport function isA2UIV09Operation(value: unknown): boolean {\n if (!isRecord(value)) return false;\n if (value.version !== undefined) {\n return typeof value.version === \"string\" && V09_VERSIONS.has(value.version);\n }\n const kind = v09Kind(value);\n return kind !== undefined && isRecord(value[kind]);\n}\n\n// Checked with `ok === false`: runtime compiles non-strict, where a check of\n// `reason` does not narrow the union.\ntype Converted<T> = { ok: true; value: T } | { ok: false; reason: string };\n\nconst ok = <T>(value: T): { ok: true; value: T } => ({ ok: true, value });\nconst failed = (reason: string): { ok: false; reason: string } => ({\n ok: false,\n reason,\n});\n\n/**\n * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ \"@path\" }` and\n * `{ call, args }` becomes `{ \"@call\", args }`, at any depth. Literals stay.\n */\nfunction convertValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(convertValue);\n if (!isRecord(value)) return value;\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.path === \"string\") {\n return { \"@path\": value.path };\n }\n const isCall =\n typeof value.call === \"string\" &&\n keys.every(\n (key) => key === \"call\" || key === \"args\" || key === \"returnType\",\n );\n if (isCall) return convertCall(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, convertValue(item)]),\n );\n}\n\n/** A v0.9 function call `{ call, args, returnType }` as `{ \"@call\", args }`. */\nfunction convertCall(call: Record<string, unknown>) {\n return {\n \"@call\": call.call as string,\n ...(call.args === undefined ? {} : { args: convertValue(call.args) }),\n };\n}\n\n/** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */\nfunction isV09Action(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n return (\n keys.length === 1 && (isRecord(value.event) || isRecord(value.functionCall))\n );\n}\n\n/**\n * A v0.9 action as a 1.0 event binding. The event keeps its name and\n * context (with converted values); a function call gets the `@call` form.\n */\nfunction convertAction(action: unknown): Converted<unknown> {\n if (!isV09Action(action)) {\n return failed('action must be { \"event\": ... } or { \"functionCall\": ... }');\n }\n if (isRecord(action.functionCall)) {\n const call = action.functionCall;\n if (typeof call.call !== \"string\" || !call.call) {\n return failed(\"action.functionCall.call must be a function name\");\n }\n return ok({ functionCall: convertCall(call) });\n }\n const event = action.event as Record<string, unknown>;\n if (typeof event.name !== \"string\" || !event.name) {\n return failed(\"action.event.name is required\");\n }\n return ok({\n event: {\n name: event.name,\n ...(event.context === undefined\n ? {}\n : { context: convertValue(event.context) }),\n },\n });\n}\n\n/**\n * The basic-catalog changes of one component. Every other prop keeps its\n * name; the 1.0 standard catalog uses the v0.9 names.\n *\n * - `Text` with a heading `variant` becomes `Title` (h1 \"2xl\" to h5 \"sm\"),\n * with `caption` it becomes `Caption`; `variant` goes. Title and Caption\n * have no `weight`, so it goes too.\n * - `Button.action` becomes `onClick`.\n * - `TextField.validationRegexp` becomes a `regex` check on its value.\n */\nfunction applyBasicCatalogChanges(node: Record<string, unknown>) {\n if (node.component === \"Text\" && \"variant\" in node) {\n const { variant, ...rest } = node;\n const size =\n typeof variant === \"string\" ? HEADING_SIZES[variant] : undefined;\n if (size !== undefined) {\n const { weight: _weight, ...title } = rest;\n return { ...title, component: \"Title\", size };\n }\n if (variant === \"caption\") {\n const { weight: _weight, ...caption } = rest;\n return { ...caption, component: \"Caption\" };\n }\n return rest;\n }\n if (node.component === \"Button\" && \"action\" in node) {\n const { action, ...rest } = node;\n return { ...rest, onClick: action };\n }\n if (node.component === \"TextField\" && \"validationRegexp\" in node) {\n const { validationRegexp, ...rest } = node;\n if (typeof validationRegexp !== \"string\" || rest.value === undefined) {\n return rest;\n }\n const check = {\n condition: {\n \"@call\": \"regex\",\n args: { value: rest.value, pattern: validationRegexp },\n },\n };\n const checks = Array.isArray(rest.checks) ? rest.checks : [];\n return { ...rest, checks: [...checks, check] };\n }\n return node;\n}\n\n/** One v0.9 component (flat format) as a 1.0 component node. */\nfunction convertComponent(node: unknown): Converted<A2UIComponentNode> {\n if (!isRecord(node) || typeof node.id !== \"string\" || !node.id) {\n return failed(\"a component needs a string id\");\n }\n if (typeof node.component !== \"string\" || !node.component) {\n return failed(\n `component \"${node.id}\": the component type must be a string (the v0.9 flat format)`,\n );\n }\n const converted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\") {\n converted[key] = value;\n } else if (key === \"action\" || isV09Action(value)) {\n const action = convertAction(value);\n if (action.ok === false) {\n return failed(`component \"${node.id}\": ${action.reason}`);\n }\n converted[key] = action.value;\n } else {\n converted[key] = convertValue(value);\n }\n }\n return ok(applyBasicCatalogChanges(converted) as A2UIComponentNode);\n}\n\nfunction convertUpdateComponents(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { components } = payload;\n if (!Array.isArray(components) || components.length === 0) {\n return failed(\"updateComponents.components must be a non-empty array\");\n }\n const nodes: A2UIComponentNode[] = [];\n for (const component of components) {\n const converted = convertComponent(component);\n if (converted.ok === false) return converted;\n nodes.push(converted.value);\n }\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n });\n}\n\n/**\n * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it\n * for `null`. At the root, removing means an empty data model.\n */\nfunction convertUpdateDataModel(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { path, value } = payload;\n if (path !== undefined && typeof path !== \"string\") {\n return failed(\"updateDataModel.path must be a string\");\n }\n const relative = typeof path === \"string\" ? path : \"\";\n const pointer = relative.startsWith(\"/\") ? relative : `/${relative}`;\n const isRoot = pointer === \"/\";\n if (isRoot && value !== undefined && !isRecord(value)) {\n return failed(\n \"a root updateDataModel value must be a JSON object in A2UI 1.0\",\n );\n }\n const nextValue = value === undefined ? (isRoot ? {} : null) : value;\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path: pointer, value: nextValue },\n });\n}\n\nfunction convertCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n): A2UIOperation {\n const { catalogId } = payload;\n const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;\n return {\n version: A2UI_VERSION,\n createSurface: {\n surfaceId,\n ...(typeof catalogId === \"string\" && catalogId\n ? {\n catalogId: V09_BASIC_CATALOG_IDS.has(catalogId)\n ? STANDARD_CATALOG_ID\n : catalogId,\n }\n : {}),\n ...(typeof sendDataModel === \"boolean\" ? { sendDataModel } : {}),\n },\n };\n}\n\n/** Basic catalog components as standard ones; anything else stays. */\nfunction standardComponents(components: unknown) {\n return Array.isArray(components)\n ? components.map((node) =>\n isRecord(node) ? applyBasicCatalogChanges(node) : node,\n )\n : components;\n}\n\n/**\n * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic\n * catalog id becomes the standard catalog id, and the basic catalog\n * components (inline in createSurface, or in updateComponents) get the\n * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.\n * Everything else stays; the client validates the operation.\n */\nfunction upgradeV10Operation(op: Record<string, unknown>): A2UIOperation {\n const { createSurface: create, updateComponents: update } = op;\n if (isRecord(create)) {\n const { catalogId } = create;\n return {\n ...op,\n createSurface: {\n ...create,\n ...(typeof catalogId === \"string\" &&\n V10_BASIC_CATALOG_IDS.has(catalogId)\n ? { catalogId: STANDARD_CATALOG_ID }\n : {}),\n ...(create.components === undefined\n ? {}\n : { components: standardComponents(create.components) }),\n },\n } as A2UIOperation;\n }\n if (isRecord(update)) {\n return {\n ...op,\n updateComponents: {\n ...update,\n ...(update.components === undefined\n ? {}\n : { components: standardComponents(update.components) }),\n },\n } as A2UIOperation;\n }\n return op as A2UIOperation;\n}\n\n/** One operation as 1.0, or why it cannot be converted. */\nfunction upgradeOperation(op: unknown): Converted<A2UIOperation> {\n if (!isRecord(op)) return failed(\"operation must be a JSON object\");\n if (op.version === A2UI_VERSION) return ok(upgradeV10Operation(op));\n if (!isA2UIV09Operation(op)) {\n return failed(\n typeof op.version === \"string\"\n ? `unsupported A2UI version \"${op.version}\"; only v0.9 and 1.0 operations are supported`\n : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const kind = v09Kind(op);\n if (!kind) {\n return failed(\n `operation must contain exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return failed(`${kind}.surfaceId is required`);\n }\n const { surfaceId } = payload;\n switch (kind) {\n case \"createSurface\":\n return ok(convertCreateSurface(payload, surfaceId));\n case \"updateComponents\":\n return convertUpdateComponents(payload, surfaceId);\n case \"updateDataModel\":\n return convertUpdateDataModel(payload, surfaceId);\n case \"deleteSurface\":\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n deleteSurface: { surfaceId },\n });\n }\n}\n\n/**\n * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.\n *\n * - createSurface: the v0.9 basic catalog id becomes the standard catalog\n * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no\n * 1.0 field and goes; `sendDataModel` stays.\n * - updateComponents: `{ path }` becomes `{ \"@path\" }` and `{ call, args }`\n * becomes `{ \"@call\", args }` at any depth; an action becomes an\n * `{ event }` or `{ functionCall }` binding; child lists and templates\n * stay. See {@link applyBasicCatalogChanges} for the props that change.\n * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at\n * the root.\n * - deleteSurface: unchanged.\n *\n * An operation that is already 1.0 (native, for example from ADK) keeps its\n * form: only the 1.0 basic catalog id becomes the standard catalog id, and\n * its basic catalog components get the same changes as v0.9 ones. Any other\n * operation, and any v0.9 operation that cannot be converted, goes to\n * `dropped` with the reason.\n *\n * @example\n * ```ts\n * upgradeA2UIV09Operations([\n * { version: \"v0.9\", updateDataModel: { surfaceId: \"s\", path: \"/x\" } },\n * ]);\n * // { operations: [{ version: \"1.0\", updateDataModel: { surfaceId: \"s\", path: \"/x\", value: null } }], dropped: [] }\n * ```\n */\nexport function upgradeA2UIV09Operations(operations: unknown[]): {\n operations: A2UIOperation[];\n dropped: Array<{ operation: unknown; reason: string }>;\n} {\n const upgraded: A2UIOperation[] = [];\n const dropped: Array<{ operation: unknown; reason: string }> = [];\n for (const operation of Array.isArray(operations) ? operations : []) {\n let result: Converted<A2UIOperation>;\n try {\n result = upgradeOperation(operation);\n } catch (error) {\n // A getter or a Proxy trap of the operation threw while it was read.\n result = failed(\n `operation could not be read: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n if (result.ok === false) {\n dropped.push({ operation, reason: result.reason });\n } else {\n upgraded.push(result.value);\n }\n }\n return { operations: upgraded, dropped };\n}\n\n/** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */\nfunction surfaceIdOf(op: unknown) {\n if (!isRecord(op)) return undefined;\n for (const kind of V09_KINDS) {\n const payload = op[kind];\n if (isRecord(payload) && typeof payload.surfaceId === \"string\") {\n return payload.surfaceId || undefined;\n }\n }\n return undefined;\n}\n\n/**\n * The error of a `failed` lifecycle snapshot: the agent's A2UI recovery\n * gave up (`a2ui_recovery_exhausted`). Undefined for any other content.\n */\nfunction failedLifecycleError(content: unknown): string | undefined {\n if (!isRecord(content) || content.status !== \"failed\") return undefined;\n const error =\n typeof content.error === \"string\" && content.error\n ? content.error\n : \"A2UI generation failed\";\n return error.slice(0, GENERATIVE_UI_MAX_REJECTION_LENGTH);\n}\n\n/** The operations of `a2ui-surface` content. Lifecycle content has none. */\nfunction readOperations(content: unknown): unknown[] {\n if (!isRecord(content)) return [];\n const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;\n return Array.isArray(operations) ? operations : [];\n}\n\ntype JsonPatchOperation = {\n op: \"add\" | \"remove\" | \"replace\" | \"move\" | \"copy\" | \"test\";\n path: string;\n from?: string;\n value?: unknown;\n};\n\nfunction pointerSegments(pointer: string) {\n if (pointer === \"\") return [];\n if (!pointer.startsWith(\"/\")) throw new Error(`invalid pointer \"${pointer}\"`);\n return pointer\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Applies RFC 6902 operations to `document` in place and returns the new\n * root. Throws on a path that does not resolve, like `fast-json-patch` in\n * the AG-UI client, so a bad delta leaves the stored content alone.\n */\nfunction applyJsonPatch(document: unknown, patch: unknown): unknown {\n if (!Array.isArray(patch)) throw new Error(\"patch must be an array\");\n let root = document;\n const parentOf = (pointer: string) => {\n const segments = pointerSegments(pointer);\n const key = segments.pop();\n let parent: unknown = root;\n for (const segment of segments) {\n if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error(\"forbidden path\");\n parent = Array.isArray(parent)\n ? parent[Number(segment)]\n : isRecord(parent)\n ? parent[segment]\n : undefined;\n if (parent === undefined) throw new Error(`path \"${pointer}\" not found`);\n }\n if (key !== undefined && FORBIDDEN_SEGMENTS.has(key)) {\n throw new Error(\"forbidden path\");\n }\n return { parent, key };\n };\n const read = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) return root;\n if (Array.isArray(parent)) return parent[Number(key)];\n return isRecord(parent) ? parent[key] : undefined;\n };\n const remove = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) throw new Error(\"cannot remove the root\");\n if (Array.isArray(parent)) parent.splice(Number(key), 1);\n else if (isRecord(parent) && key in parent) delete parent[key];\n else throw new Error(`path \"${pointer}\" not found`);\n };\n const write = (pointer: string, value: unknown, insert: boolean) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) {\n root = value;\n } else if (Array.isArray(parent)) {\n const index = key === \"-\" ? parent.length : Number(key);\n if (!Number.isInteger(index) || index < 0 || index > parent.length) {\n throw new Error(`index \"${key}\" is out of range`);\n }\n parent.splice(index, insert ? 0 : 1, value);\n } else if (isRecord(parent)) {\n parent[key] = value;\n } else {\n throw new Error(`path \"${pointer}\" not found`);\n }\n };\n for (const entry of patch as JsonPatchOperation[]) {\n if (!isRecord(entry) || typeof entry.path !== \"string\") {\n throw new Error(\"invalid patch operation\");\n }\n switch (entry.op) {\n case \"add\":\n write(entry.path, cloneValue(entry.value), true);\n break;\n case \"replace\":\n if (read(entry.path) === undefined) {\n throw new Error(`path \"${entry.path}\" not found`);\n }\n write(entry.path, cloneValue(entry.value), false);\n break;\n case \"remove\":\n remove(entry.path);\n break;\n case \"copy\":\n write(entry.path, cloneValue(read(entry.from ?? \"\")), true);\n break;\n case \"move\": {\n const value = read(entry.from ?? \"\");\n remove(entry.from ?? \"\");\n write(entry.path, value, true);\n break;\n }\n case \"test\":\n if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) {\n throw new Error(`test failed at \"${entry.path}\"`);\n }\n break;\n default:\n throw new Error(`unknown patch op \"${String(entry.op)}\"`);\n }\n }\n return root;\n}\n\n/** One converted operation, with where it came from. */\ninterface SourceOperation {\n operation: A2UIOperation;\n /** Its index in the source message. */\n index: number;\n version: SourceVersion;\n}\n\n/** The converted part of one surface that one source message holds. */\ninterface SourcePart {\n operations: SourceOperation[];\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/**\n * The operations of the next snapshot of a surface, so that the client\n * applies every change of the source.\n *\n * The client applies only the operations after the ones it applied, when the\n * operation at its last applied index did not change. A source that changes\n * an earlier operation but not that one (a progressive render that rewrites\n * its components, then sends the same data again) would lose the change. In\n * that case the changed operations of the source are appended to the sent\n * ones: v0.9 updates replace by id or path, so sending them again is safe,\n * and a second createSurface is left out. In every other case the source\n * operations go as they are: the client either extends its surface with them\n * or builds it again from them.\n *\n * @param lastSource - The source operations of the last snapshot (none\n * before the first one).\n * @param sent - The operations of the last snapshot.\n * @param source - The source operations now.\n * @returns The operations of the next snapshot.\n */\nfunction clientOperations(\n lastSource: A2UIOperation[],\n sent: A2UIOperation[],\n source: A2UIOperation[],\n): A2UIOperation[] {\n let same = 0;\n while (\n same < lastSource.length &&\n same < source.length &&\n JSON.stringify(lastSource[same]) === JSON.stringify(source[same])\n ) {\n same++;\n }\n const appended = source.slice(same);\n if (same === lastSource.length) return [...sent, ...appended];\n // The client builds the surface again when the list is shorter than the\n // one it applied, or when the operation at its last applied index changed.\n const last = sent.length - 1;\n if (\n source.length < sent.length ||\n JSON.stringify(source[last]) !== JSON.stringify(sent[last])\n ) {\n return source;\n }\n return [...sent, ...appended.filter((op) => !(\"createSurface\" in op))];\n}\n\ninterface SurfaceState {\n /** The part of each source message, in the order they first touched it. */\n parts: Map<string, SourcePart>;\n /** JSON of the last snapshot content. */\n lastSnapshot?: string;\n /** The converted operations of the source, at the last snapshot. */\n snapshotSource: A2UIOperation[];\n /** The operations of the last snapshot, as the client applied them. */\n snapshotOperations: A2UIOperation[];\n /** Operations sent as deltas, for a surface created in an earlier run. */\n sentOperations: A2UIOperation[];\n /** JSON of the last `rejected` sent as a delta. */\n sentRejected: string;\n}\n\n/**\n * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native\n * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass\n * every event of the run through `transform`, in order.\n *\n * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per\n * messageId (a delta is applied to the stored content), and its\n * operations are converted with {@link upgradeA2UIV09Operations}.\n * - Each surface becomes one `generative-ui-surface` message,\n * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is\n * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the\n * cumulative 1.0 content: the operations of every source message for it,\n * in order, with only the first createSurface. The target is the chat,\n * the status is \"ready\", dropped operations are `rejected` (at their\n * index in the source message), and `a2uiSourceVersion` is \"0.9\" for a\n * surface written in v0.9.\n * - A surface written in native A2UI 1.0 (`version: \"1.0\"`, for example\n * from ADK) becomes the same `generative-ui-surface` message, without\n * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the\n * agent unchanged. One surface has one version, the version of its\n * first operation; an operation of the other version is rejected.\n * - A surface that this run updates but does not create (v0.9 sends no\n * second createSurface) was created in an earlier run, so its new\n * operations are appended to its message with an `ACTIVITY_DELTA`, as\n * the `render_ui` path updates an existing surface.\n * - A lifecycle snapshot (`status: \"building\"` and so on, no operations)\n * names no surface, so it is consumed. A `failed` one (the agent's\n * recovery gave up) becomes a surface with no operations, status\n * \"error\", and its error as the one rejected entry, so the chat shows\n * that the UI could not be made. Its surfaceId is the source messageId.\n * Every other event passes through.\n *\n * @example\n * ```ts\n * const upgrader = createA2UIV09ActivityUpgrader();\n * source.pipe(mergeMap((event) => upgrader.transform(event)));\n * ```\n */\nexport function createA2UIV09ActivityUpgrader(): {\n transform(event: BaseEvent): BaseEvent[];\n} {\n const sources = new Map<string, unknown>();\n const surfaces = new Map<string, SurfaceState>();\n /** The source messages whose `failed` snapshot was sent. */\n const failures = new Set<string>();\n\n /** The surface that shows a failed lifecycle snapshot, sent once. */\n const failureOf = (messageId: string, error: string): BaseEvent[] => {\n if (failures.has(messageId)) return [];\n failures.add(messageId);\n const content: GenerativeUISurfaceContent = {\n surfaceId: messageId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId: STANDARD_CATALOG_ID,\n operations: [],\n status: \"error\",\n rejected: [{ index: 0, reason: error }],\n a2uiSourceVersion: \"0.9\",\n };\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(messageId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n };\n return [event];\n };\n\n const snapshotOf = (\n surfaceId: string,\n state: SurfaceState,\n source: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n version: SourceVersion,\n ): BaseEvent[] => {\n const operations = clientOperations(\n state.snapshotSource,\n state.snapshotOperations,\n source,\n );\n const create = operations.find((op) => \"createSurface\" in op);\n const catalogId =\n (create && \"createSurface\" in create && create.createSurface.catalogId) ||\n STANDARD_CATALOG_ID;\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId,\n operations,\n status: \"ready\",\n rejected,\n ...(version === \"0.9\" ? { a2uiSourceVersion: \"0.9\" as const } : {}),\n };\n const json = JSON.stringify(content);\n if (json === state.lastSnapshot) return [];\n state.lastSnapshot = json;\n state.snapshotSource = source;\n state.snapshotOperations = operations;\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content: cloneValue(content),\n replace: true,\n };\n return [event];\n };\n\n const deltaOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n ): BaseEvent[] => {\n const sent = state.sentOperations;\n let same = 0;\n while (\n same < sent.length &&\n same < operations.length &&\n JSON.stringify(sent[same]) === JSON.stringify(operations[same])\n ) {\n same++;\n }\n // Operations that changed after they were sent cannot be taken back.\n // v0.9 updates replace by id or path, so sending them again is safe.\n const patch: unknown[] = operations.slice(same).map((op) => ({\n op: \"add\",\n path: \"/operations/-\",\n value: cloneValue(op),\n }));\n const rejectedJson = JSON.stringify(rejected);\n if (rejectedJson !== state.sentRejected) {\n patch.push({ op: \"replace\", path: \"/rejected\", value: rejected });\n }\n state.sentOperations = operations;\n state.sentRejected = rejectedJson;\n if (patch.length === 0) return [];\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: patch as ActivityDeltaEvent[\"patch\"],\n };\n return [event];\n };\n\n const emitSurface = (surfaceId: string): BaseEvent[] => {\n const state = surfaces.get(surfaceId);\n if (!state) return [];\n const operations: A2UIOperation[] = [];\n const rejected: GenerativeUIRejectedOperation[] = [];\n let created = false;\n let version: SourceVersion | undefined;\n for (const part of state.parts.values()) {\n for (const { operation, index, version: opVersion } of part.operations) {\n version ??= opVersion;\n if (opVersion !== version) {\n rejected.push({\n index,\n reason: `surface \"${surfaceId}\" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`,\n });\n continue;\n }\n if (\"createSurface\" in operation) {\n // A second createSurface of the same id is rejected in 1.0.\n if (created) continue;\n created = true;\n }\n operations.push(operation);\n }\n rejected.push(...part.rejected);\n }\n return created\n ? snapshotOf(surfaceId, state, operations, rejected, version ?? \"0.9\")\n : deltaOf(surfaceId, state, operations, rejected);\n };\n\n /** Converts the stored content of one source message again. */\n const refresh = (messageId: string): BaseEvent[] => {\n const parts = new Map<string, SourcePart>();\n readOperations(sources.get(messageId)).forEach((op, index) => {\n // An operation with no surface cannot be shown anywhere.\n const surfaceId = surfaceIdOf(op);\n if (surfaceId === undefined) return;\n let part = parts.get(surfaceId);\n if (!part) {\n part = { operations: [], rejected: [] };\n parts.set(surfaceId, part);\n }\n const { operations, dropped } = upgradeA2UIV09Operations([op]);\n // Only v0.9 and 1.0 operations convert.\n const version: SourceVersion =\n isRecord(op) && op.version === A2UI_VERSION ? \"1.0\" : \"0.9\";\n for (const operation of operations) {\n part.operations.push({ operation, index, version });\n }\n for (const { reason } of dropped) part.rejected.push({ index, reason });\n });\n const touched = new Set(parts.keys());\n for (const [surfaceId, state] of surfaces) {\n if (!parts.has(surfaceId) && state.parts.delete(messageId)) {\n touched.add(surfaceId);\n }\n }\n for (const [surfaceId, part] of parts) {\n let state = surfaces.get(surfaceId);\n if (!state) {\n state = {\n parts: new Map(),\n snapshotSource: [],\n snapshotOperations: [],\n sentOperations: [],\n sentRejected: \"[]\",\n };\n surfaces.set(surfaceId, state);\n }\n state.parts.set(messageId, part);\n }\n const events = [...touched].flatMap(emitSurface);\n const error = failedLifecycleError(sources.get(messageId));\n return error === undefined\n ? events\n : [...events, ...failureOf(messageId, error)];\n };\n\n return {\n transform(event) {\n if (event.type === EventType.ACTIVITY_SNAPSHOT) {\n const snapshot = event as ActivitySnapshotEvent;\n if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n return [event];\n }\n const { messageId } = snapshot;\n // `replace: false` does not replace a message that already exists.\n if (snapshot.replace === false && sources.has(messageId)) return [];\n sources.set(messageId, cloneValue(snapshot.content));\n return refresh(messageId);\n }\n if (event.type === EventType.ACTIVITY_DELTA) {\n const delta = event as ActivityDeltaEvent;\n if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];\n const { messageId } = delta;\n if (!sources.has(messageId)) return [];\n let content: unknown;\n try {\n content = applyJsonPatch(\n cloneValue(sources.get(messageId)),\n delta.patch,\n );\n } catch {\n // The AG-UI client also skips a delta that does not apply.\n return [];\n }\n sources.set(messageId, content);\n return refresh(messageId);\n }\n return [event];\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAM,6BAA6B;AACnC,MAAM,sBAAsB;;AAG5B,MAAM,eAAoC,IAAI,IAAI,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AAC/B,UAAO,QAAQ,UAAU;;AAE3B,SAAO,CAAC,MAAM;IAEjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isRecord } from "../../agent/converters/usage.mjs";
|
|
2
|
-
import { A2UI_VERSION, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, cloneValue, generativeUISurfaceMessageId } from "@copilotkit/shared";
|
|
2
|
+
import { A2UI_VERSION, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_MAX_REJECTION_LENGTH, cloneValue, generativeUISurfaceMessageId } from "@copilotkit/shared";
|
|
3
3
|
import { EventType } from "@ag-ui/client";
|
|
4
4
|
import { STANDARD_CATALOG_ID } from "@copilotkit/shared/generative-ui";
|
|
5
5
|
|
|
@@ -343,6 +343,14 @@ function surfaceIdOf(op) {
|
|
|
343
343
|
if (isRecord(payload) && typeof payload.surfaceId === "string") return payload.surfaceId || void 0;
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* The error of a `failed` lifecycle snapshot: the agent's A2UI recovery
|
|
348
|
+
* gave up (`a2ui_recovery_exhausted`). Undefined for any other content.
|
|
349
|
+
*/
|
|
350
|
+
function failedLifecycleError(content) {
|
|
351
|
+
if (!isRecord(content) || content.status !== "failed") return void 0;
|
|
352
|
+
return (typeof content.error === "string" && content.error ? content.error : "A2UI generation failed").slice(0, GENERATIVE_UI_MAX_REJECTION_LENGTH);
|
|
353
|
+
}
|
|
346
354
|
/** The operations of `a2ui-surface` content. Lifecycle content has none. */
|
|
347
355
|
function readOperations(content) {
|
|
348
356
|
if (!isRecord(content)) return [];
|
|
@@ -436,6 +444,35 @@ function applyJsonPatch(document, patch) {
|
|
|
436
444
|
return root;
|
|
437
445
|
}
|
|
438
446
|
/**
|
|
447
|
+
* The operations of the next snapshot of a surface, so that the client
|
|
448
|
+
* applies every change of the source.
|
|
449
|
+
*
|
|
450
|
+
* The client applies only the operations after the ones it applied, when the
|
|
451
|
+
* operation at its last applied index did not change. A source that changes
|
|
452
|
+
* an earlier operation but not that one (a progressive render that rewrites
|
|
453
|
+
* its components, then sends the same data again) would lose the change. In
|
|
454
|
+
* that case the changed operations of the source are appended to the sent
|
|
455
|
+
* ones: v0.9 updates replace by id or path, so sending them again is safe,
|
|
456
|
+
* and a second createSurface is left out. In every other case the source
|
|
457
|
+
* operations go as they are: the client either extends its surface with them
|
|
458
|
+
* or builds it again from them.
|
|
459
|
+
*
|
|
460
|
+
* @param lastSource - The source operations of the last snapshot (none
|
|
461
|
+
* before the first one).
|
|
462
|
+
* @param sent - The operations of the last snapshot.
|
|
463
|
+
* @param source - The source operations now.
|
|
464
|
+
* @returns The operations of the next snapshot.
|
|
465
|
+
*/
|
|
466
|
+
function clientOperations(lastSource, sent, source) {
|
|
467
|
+
let same = 0;
|
|
468
|
+
while (same < lastSource.length && same < source.length && JSON.stringify(lastSource[same]) === JSON.stringify(source[same])) same++;
|
|
469
|
+
const appended = source.slice(same);
|
|
470
|
+
if (same === lastSource.length) return [...sent, ...appended];
|
|
471
|
+
const last = sent.length - 1;
|
|
472
|
+
if (source.length < sent.length || JSON.stringify(source[last]) !== JSON.stringify(sent[last])) return source;
|
|
473
|
+
return [...sent, ...appended.filter((op) => !("createSurface" in op))];
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
439
476
|
* Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native
|
|
440
477
|
* A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass
|
|
441
478
|
* every event of the run through `transform`, in order.
|
|
@@ -461,7 +498,11 @@ function applyJsonPatch(document, patch) {
|
|
|
461
498
|
* operations are appended to its message with an `ACTIVITY_DELTA`, as
|
|
462
499
|
* the `render_ui` path updates an existing surface.
|
|
463
500
|
* - A lifecycle snapshot (`status: "building"` and so on, no operations)
|
|
464
|
-
* names no surface, so it is consumed.
|
|
501
|
+
* names no surface, so it is consumed. A `failed` one (the agent's
|
|
502
|
+
* recovery gave up) becomes a surface with no operations, status
|
|
503
|
+
* "error", and its error as the one rejected entry, so the chat shows
|
|
504
|
+
* that the UI could not be made. Its surfaceId is the source messageId.
|
|
505
|
+
* Every other event passes through.
|
|
465
506
|
*
|
|
466
507
|
* @example
|
|
467
508
|
* ```ts
|
|
@@ -472,7 +513,34 @@ function applyJsonPatch(document, patch) {
|
|
|
472
513
|
function createA2UIV09ActivityUpgrader() {
|
|
473
514
|
const sources = /* @__PURE__ */ new Map();
|
|
474
515
|
const surfaces = /* @__PURE__ */ new Map();
|
|
475
|
-
|
|
516
|
+
/** The source messages whose `failed` snapshot was sent. */
|
|
517
|
+
const failures = /* @__PURE__ */ new Set();
|
|
518
|
+
/** The surface that shows a failed lifecycle snapshot, sent once. */
|
|
519
|
+
const failureOf = (messageId, error) => {
|
|
520
|
+
if (failures.has(messageId)) return [];
|
|
521
|
+
failures.add(messageId);
|
|
522
|
+
const content = {
|
|
523
|
+
surfaceId: messageId,
|
|
524
|
+
target: GENERATIVE_UI_CHAT_TARGET,
|
|
525
|
+
catalogId: STANDARD_CATALOG_ID,
|
|
526
|
+
operations: [],
|
|
527
|
+
status: "error",
|
|
528
|
+
rejected: [{
|
|
529
|
+
index: 0,
|
|
530
|
+
reason: error
|
|
531
|
+
}],
|
|
532
|
+
a2uiSourceVersion: "0.9"
|
|
533
|
+
};
|
|
534
|
+
return [{
|
|
535
|
+
type: EventType.ACTIVITY_SNAPSHOT,
|
|
536
|
+
messageId: generativeUISurfaceMessageId(messageId),
|
|
537
|
+
activityType: GENERATIVE_UI_ACTIVITY_TYPE,
|
|
538
|
+
content,
|
|
539
|
+
replace: true
|
|
540
|
+
}];
|
|
541
|
+
};
|
|
542
|
+
const snapshotOf = (surfaceId, state, source, rejected, version) => {
|
|
543
|
+
const operations = clientOperations(state.snapshotSource, state.snapshotOperations, source);
|
|
476
544
|
const create = operations.find((op) => "createSurface" in op);
|
|
477
545
|
const content = {
|
|
478
546
|
surfaceId,
|
|
@@ -486,6 +554,8 @@ function createA2UIV09ActivityUpgrader() {
|
|
|
486
554
|
const json = JSON.stringify(content);
|
|
487
555
|
if (json === state.lastSnapshot) return [];
|
|
488
556
|
state.lastSnapshot = json;
|
|
557
|
+
state.snapshotSource = source;
|
|
558
|
+
state.snapshotOperations = operations;
|
|
489
559
|
return [{
|
|
490
560
|
type: EventType.ACTIVITY_SNAPSHOT,
|
|
491
561
|
messageId: generativeUISurfaceMessageId(surfaceId),
|
|
@@ -579,6 +649,8 @@ function createA2UIV09ActivityUpgrader() {
|
|
|
579
649
|
if (!state) {
|
|
580
650
|
state = {
|
|
581
651
|
parts: /* @__PURE__ */ new Map(),
|
|
652
|
+
snapshotSource: [],
|
|
653
|
+
snapshotOperations: [],
|
|
582
654
|
sentOperations: [],
|
|
583
655
|
sentRejected: "[]"
|
|
584
656
|
};
|
|
@@ -586,7 +658,9 @@ function createA2UIV09ActivityUpgrader() {
|
|
|
586
658
|
}
|
|
587
659
|
state.parts.set(messageId, part);
|
|
588
660
|
}
|
|
589
|
-
|
|
661
|
+
const events = [...touched].flatMap(emitSurface);
|
|
662
|
+
const error = failedLifecycleError(sources.get(messageId));
|
|
663
|
+
return error === void 0 ? events : [...events, ...failureOf(messageId, error)];
|
|
590
664
|
};
|
|
591
665
|
return { transform(event) {
|
|
592
666
|
if (event.type === EventType.ACTIVITY_SNAPSHOT) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-v09-operations.mjs","names":[],"sources":["../../../src/runtime/generative-ui/a2ui-v09-operations.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type {\n ActivityDeltaEvent,\n ActivitySnapshotEvent,\n BaseEvent,\n} from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CHAT_TARGET,\n cloneValue,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\nimport { STANDARD_CATALOG_ID } from \"@copilotkit/shared/generative-ui\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The activity type and content key of v0.9 surfaces, as\n * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.\n */\nconst A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\nconst A2UI_OPERATIONS_KEY = \"a2ui_operations\";\n\n/** The `version` values of A2UI v0.9 messages. */\nconst V09_VERSIONS: ReadonlySet<string> = new Set([\"v0.9\", \"v0.9.1\"]);\nconst V09_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n] as const;\ntype V09Kind = (typeof V09_KINDS)[number];\n\n/**\n * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of\n * the published catalog document. Both become the standard catalog, which has\n * the same 18 components.\n */\nconst V09_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\",\n \"https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json\",\n]);\n\n/**\n * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for\n * example ADK) send. It has the 18 components of the v0.9 basic catalog\n * with 1.0 bindings, so it becomes the standard catalog too.\n */\nconst V10_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json\",\n]);\n\n/** The A2UI version that an `a2ui-surface` operation was written in. */\ntype SourceVersion = \"0.9\" | \"1.0\";\n\n/** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */\nconst HEADING_SIZES: Readonly<Record<string, string>> = {\n h1: \"2xl\",\n h2: \"xl\",\n h3: \"lg\",\n h4: \"md\",\n h5: \"sm\",\n};\n\n/** The one v0.9 operation key of `op`, when it has exactly one. */\nfunction v09Kind(op: Record<string, unknown>): V09Kind | undefined {\n const kinds = V09_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/**\n * True for an A2UI v0.9 operation: an object whose `version` is `\"v0.9\"` (or\n * `\"v0.9.1\"`). An object without `version` counts when it has exactly one\n * v0.9 operation key with an object payload. A 1.0 operation always carries\n * `version: \"1.0\"` (the client rejects one without it), and v0.8 uses other\n * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with\n * a v0.9 key can only be v0.9. Agents leave `version` out often enough that\n * requiring it would drop their surfaces.\n *\n * @example\n * ```ts\n * isA2UIV09Operation({ version: \"v0.9\", deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ version: \"1.0\", deleteSurface: { surfaceId: \"s\" } }); // false\n * ```\n */\nexport function isA2UIV09Operation(value: unknown): boolean {\n if (!isRecord(value)) return false;\n if (value.version !== undefined) {\n return typeof value.version === \"string\" && V09_VERSIONS.has(value.version);\n }\n const kind = v09Kind(value);\n return kind !== undefined && isRecord(value[kind]);\n}\n\n// Checked with `ok === false`: runtime compiles non-strict, where a check of\n// `reason` does not narrow the union.\ntype Converted<T> = { ok: true; value: T } | { ok: false; reason: string };\n\nconst ok = <T>(value: T): { ok: true; value: T } => ({ ok: true, value });\nconst failed = (reason: string): { ok: false; reason: string } => ({\n ok: false,\n reason,\n});\n\n/**\n * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ \"@path\" }` and\n * `{ call, args }` becomes `{ \"@call\", args }`, at any depth. Literals stay.\n */\nfunction convertValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(convertValue);\n if (!isRecord(value)) return value;\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.path === \"string\") {\n return { \"@path\": value.path };\n }\n const isCall =\n typeof value.call === \"string\" &&\n keys.every(\n (key) => key === \"call\" || key === \"args\" || key === \"returnType\",\n );\n if (isCall) return convertCall(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, convertValue(item)]),\n );\n}\n\n/** A v0.9 function call `{ call, args, returnType }` as `{ \"@call\", args }`. */\nfunction convertCall(call: Record<string, unknown>) {\n return {\n \"@call\": call.call as string,\n ...(call.args === undefined ? {} : { args: convertValue(call.args) }),\n };\n}\n\n/** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */\nfunction isV09Action(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n return (\n keys.length === 1 && (isRecord(value.event) || isRecord(value.functionCall))\n );\n}\n\n/**\n * A v0.9 action as a 1.0 event binding. The event keeps its name and\n * context (with converted values); a function call gets the `@call` form.\n */\nfunction convertAction(action: unknown): Converted<unknown> {\n if (!isV09Action(action)) {\n return failed('action must be { \"event\": ... } or { \"functionCall\": ... }');\n }\n if (isRecord(action.functionCall)) {\n const call = action.functionCall;\n if (typeof call.call !== \"string\" || !call.call) {\n return failed(\"action.functionCall.call must be a function name\");\n }\n return ok({ functionCall: convertCall(call) });\n }\n const event = action.event as Record<string, unknown>;\n if (typeof event.name !== \"string\" || !event.name) {\n return failed(\"action.event.name is required\");\n }\n return ok({\n event: {\n name: event.name,\n ...(event.context === undefined\n ? {}\n : { context: convertValue(event.context) }),\n },\n });\n}\n\n/**\n * The basic-catalog changes of one component. Every other prop keeps its\n * name; the 1.0 standard catalog uses the v0.9 names.\n *\n * - `Text` with a heading `variant` becomes `Title` (h1 \"2xl\" to h5 \"sm\"),\n * with `caption` it becomes `Caption`; `variant` goes. Title and Caption\n * have no `weight`, so it goes too.\n * - `Button.action` becomes `onClick`.\n * - `TextField.validationRegexp` becomes a `regex` check on its value.\n */\nfunction applyBasicCatalogChanges(node: Record<string, unknown>) {\n if (node.component === \"Text\" && \"variant\" in node) {\n const { variant, ...rest } = node;\n const size =\n typeof variant === \"string\" ? HEADING_SIZES[variant] : undefined;\n if (size !== undefined) {\n const { weight: _weight, ...title } = rest;\n return { ...title, component: \"Title\", size };\n }\n if (variant === \"caption\") {\n const { weight: _weight, ...caption } = rest;\n return { ...caption, component: \"Caption\" };\n }\n return rest;\n }\n if (node.component === \"Button\" && \"action\" in node) {\n const { action, ...rest } = node;\n return { ...rest, onClick: action };\n }\n if (node.component === \"TextField\" && \"validationRegexp\" in node) {\n const { validationRegexp, ...rest } = node;\n if (typeof validationRegexp !== \"string\" || rest.value === undefined) {\n return rest;\n }\n const check = {\n condition: {\n \"@call\": \"regex\",\n args: { value: rest.value, pattern: validationRegexp },\n },\n };\n const checks = Array.isArray(rest.checks) ? rest.checks : [];\n return { ...rest, checks: [...checks, check] };\n }\n return node;\n}\n\n/** One v0.9 component (flat format) as a 1.0 component node. */\nfunction convertComponent(node: unknown): Converted<A2UIComponentNode> {\n if (!isRecord(node) || typeof node.id !== \"string\" || !node.id) {\n return failed(\"a component needs a string id\");\n }\n if (typeof node.component !== \"string\" || !node.component) {\n return failed(\n `component \"${node.id}\": the component type must be a string (the v0.9 flat format)`,\n );\n }\n const converted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\") {\n converted[key] = value;\n } else if (key === \"action\" || isV09Action(value)) {\n const action = convertAction(value);\n if (action.ok === false) {\n return failed(`component \"${node.id}\": ${action.reason}`);\n }\n converted[key] = action.value;\n } else {\n converted[key] = convertValue(value);\n }\n }\n return ok(applyBasicCatalogChanges(converted) as A2UIComponentNode);\n}\n\nfunction convertUpdateComponents(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { components } = payload;\n if (!Array.isArray(components) || components.length === 0) {\n return failed(\"updateComponents.components must be a non-empty array\");\n }\n const nodes: A2UIComponentNode[] = [];\n for (const component of components) {\n const converted = convertComponent(component);\n if (converted.ok === false) return converted;\n nodes.push(converted.value);\n }\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n });\n}\n\n/**\n * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it\n * for `null`. At the root, removing means an empty data model.\n */\nfunction convertUpdateDataModel(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { path, value } = payload;\n if (path !== undefined && typeof path !== \"string\") {\n return failed(\"updateDataModel.path must be a string\");\n }\n const relative = typeof path === \"string\" ? path : \"\";\n const pointer = relative.startsWith(\"/\") ? relative : `/${relative}`;\n const isRoot = pointer === \"/\";\n if (isRoot && value !== undefined && !isRecord(value)) {\n return failed(\n \"a root updateDataModel value must be a JSON object in A2UI 1.0\",\n );\n }\n const nextValue = value === undefined ? (isRoot ? {} : null) : value;\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path: pointer, value: nextValue },\n });\n}\n\nfunction convertCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n): A2UIOperation {\n const { catalogId } = payload;\n const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;\n return {\n version: A2UI_VERSION,\n createSurface: {\n surfaceId,\n ...(typeof catalogId === \"string\" && catalogId\n ? {\n catalogId: V09_BASIC_CATALOG_IDS.has(catalogId)\n ? STANDARD_CATALOG_ID\n : catalogId,\n }\n : {}),\n ...(typeof sendDataModel === \"boolean\" ? { sendDataModel } : {}),\n },\n };\n}\n\n/** Basic catalog components as standard ones; anything else stays. */\nfunction standardComponents(components: unknown) {\n return Array.isArray(components)\n ? components.map((node) =>\n isRecord(node) ? applyBasicCatalogChanges(node) : node,\n )\n : components;\n}\n\n/**\n * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic\n * catalog id becomes the standard catalog id, and the basic catalog\n * components (inline in createSurface, or in updateComponents) get the\n * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.\n * Everything else stays; the client validates the operation.\n */\nfunction upgradeV10Operation(op: Record<string, unknown>): A2UIOperation {\n const { createSurface: create, updateComponents: update } = op;\n if (isRecord(create)) {\n const { catalogId } = create;\n return {\n ...op,\n createSurface: {\n ...create,\n ...(typeof catalogId === \"string\" &&\n V10_BASIC_CATALOG_IDS.has(catalogId)\n ? { catalogId: STANDARD_CATALOG_ID }\n : {}),\n ...(create.components === undefined\n ? {}\n : { components: standardComponents(create.components) }),\n },\n } as A2UIOperation;\n }\n if (isRecord(update)) {\n return {\n ...op,\n updateComponents: {\n ...update,\n ...(update.components === undefined\n ? {}\n : { components: standardComponents(update.components) }),\n },\n } as A2UIOperation;\n }\n return op as A2UIOperation;\n}\n\n/** One operation as 1.0, or why it cannot be converted. */\nfunction upgradeOperation(op: unknown): Converted<A2UIOperation> {\n if (!isRecord(op)) return failed(\"operation must be a JSON object\");\n if (op.version === A2UI_VERSION) return ok(upgradeV10Operation(op));\n if (!isA2UIV09Operation(op)) {\n return failed(\n typeof op.version === \"string\"\n ? `unsupported A2UI version \"${op.version}\"; only v0.9 and 1.0 operations are supported`\n : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const kind = v09Kind(op);\n if (!kind) {\n return failed(\n `operation must contain exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return failed(`${kind}.surfaceId is required`);\n }\n const { surfaceId } = payload;\n switch (kind) {\n case \"createSurface\":\n return ok(convertCreateSurface(payload, surfaceId));\n case \"updateComponents\":\n return convertUpdateComponents(payload, surfaceId);\n case \"updateDataModel\":\n return convertUpdateDataModel(payload, surfaceId);\n case \"deleteSurface\":\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n deleteSurface: { surfaceId },\n });\n }\n}\n\n/**\n * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.\n *\n * - createSurface: the v0.9 basic catalog id becomes the standard catalog\n * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no\n * 1.0 field and goes; `sendDataModel` stays.\n * - updateComponents: `{ path }` becomes `{ \"@path\" }` and `{ call, args }`\n * becomes `{ \"@call\", args }` at any depth; an action becomes an\n * `{ event }` or `{ functionCall }` binding; child lists and templates\n * stay. See {@link applyBasicCatalogChanges} for the props that change.\n * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at\n * the root.\n * - deleteSurface: unchanged.\n *\n * An operation that is already 1.0 (native, for example from ADK) keeps its\n * form: only the 1.0 basic catalog id becomes the standard catalog id, and\n * its basic catalog components get the same changes as v0.9 ones. Any other\n * operation, and any v0.9 operation that cannot be converted, goes to\n * `dropped` with the reason.\n *\n * @example\n * ```ts\n * upgradeA2UIV09Operations([\n * { version: \"v0.9\", updateDataModel: { surfaceId: \"s\", path: \"/x\" } },\n * ]);\n * // { operations: [{ version: \"1.0\", updateDataModel: { surfaceId: \"s\", path: \"/x\", value: null } }], dropped: [] }\n * ```\n */\nexport function upgradeA2UIV09Operations(operations: unknown[]): {\n operations: A2UIOperation[];\n dropped: Array<{ operation: unknown; reason: string }>;\n} {\n const upgraded: A2UIOperation[] = [];\n const dropped: Array<{ operation: unknown; reason: string }> = [];\n for (const operation of Array.isArray(operations) ? operations : []) {\n let result: Converted<A2UIOperation>;\n try {\n result = upgradeOperation(operation);\n } catch (error) {\n // A getter or a Proxy trap of the operation threw while it was read.\n result = failed(\n `operation could not be read: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n if (result.ok === false) {\n dropped.push({ operation, reason: result.reason });\n } else {\n upgraded.push(result.value);\n }\n }\n return { operations: upgraded, dropped };\n}\n\n/** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */\nfunction surfaceIdOf(op: unknown) {\n if (!isRecord(op)) return undefined;\n for (const kind of V09_KINDS) {\n const payload = op[kind];\n if (isRecord(payload) && typeof payload.surfaceId === \"string\") {\n return payload.surfaceId || undefined;\n }\n }\n return undefined;\n}\n\n/** The operations of `a2ui-surface` content. Lifecycle content has none. */\nfunction readOperations(content: unknown): unknown[] {\n if (!isRecord(content)) return [];\n const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;\n return Array.isArray(operations) ? operations : [];\n}\n\ntype JsonPatchOperation = {\n op: \"add\" | \"remove\" | \"replace\" | \"move\" | \"copy\" | \"test\";\n path: string;\n from?: string;\n value?: unknown;\n};\n\nfunction pointerSegments(pointer: string) {\n if (pointer === \"\") return [];\n if (!pointer.startsWith(\"/\")) throw new Error(`invalid pointer \"${pointer}\"`);\n return pointer\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Applies RFC 6902 operations to `document` in place and returns the new\n * root. Throws on a path that does not resolve, like `fast-json-patch` in\n * the AG-UI client, so a bad delta leaves the stored content alone.\n */\nfunction applyJsonPatch(document: unknown, patch: unknown): unknown {\n if (!Array.isArray(patch)) throw new Error(\"patch must be an array\");\n let root = document;\n const parentOf = (pointer: string) => {\n const segments = pointerSegments(pointer);\n const key = segments.pop();\n let parent: unknown = root;\n for (const segment of segments) {\n if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error(\"forbidden path\");\n parent = Array.isArray(parent)\n ? parent[Number(segment)]\n : isRecord(parent)\n ? parent[segment]\n : undefined;\n if (parent === undefined) throw new Error(`path \"${pointer}\" not found`);\n }\n if (key !== undefined && FORBIDDEN_SEGMENTS.has(key)) {\n throw new Error(\"forbidden path\");\n }\n return { parent, key };\n };\n const read = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) return root;\n if (Array.isArray(parent)) return parent[Number(key)];\n return isRecord(parent) ? parent[key] : undefined;\n };\n const remove = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) throw new Error(\"cannot remove the root\");\n if (Array.isArray(parent)) parent.splice(Number(key), 1);\n else if (isRecord(parent) && key in parent) delete parent[key];\n else throw new Error(`path \"${pointer}\" not found`);\n };\n const write = (pointer: string, value: unknown, insert: boolean) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) {\n root = value;\n } else if (Array.isArray(parent)) {\n const index = key === \"-\" ? parent.length : Number(key);\n if (!Number.isInteger(index) || index < 0 || index > parent.length) {\n throw new Error(`index \"${key}\" is out of range`);\n }\n parent.splice(index, insert ? 0 : 1, value);\n } else if (isRecord(parent)) {\n parent[key] = value;\n } else {\n throw new Error(`path \"${pointer}\" not found`);\n }\n };\n for (const entry of patch as JsonPatchOperation[]) {\n if (!isRecord(entry) || typeof entry.path !== \"string\") {\n throw new Error(\"invalid patch operation\");\n }\n switch (entry.op) {\n case \"add\":\n write(entry.path, cloneValue(entry.value), true);\n break;\n case \"replace\":\n if (read(entry.path) === undefined) {\n throw new Error(`path \"${entry.path}\" not found`);\n }\n write(entry.path, cloneValue(entry.value), false);\n break;\n case \"remove\":\n remove(entry.path);\n break;\n case \"copy\":\n write(entry.path, cloneValue(read(entry.from ?? \"\")), true);\n break;\n case \"move\": {\n const value = read(entry.from ?? \"\");\n remove(entry.from ?? \"\");\n write(entry.path, value, true);\n break;\n }\n case \"test\":\n if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) {\n throw new Error(`test failed at \"${entry.path}\"`);\n }\n break;\n default:\n throw new Error(`unknown patch op \"${String(entry.op)}\"`);\n }\n }\n return root;\n}\n\n/** One converted operation, with where it came from. */\ninterface SourceOperation {\n operation: A2UIOperation;\n /** Its index in the source message. */\n index: number;\n version: SourceVersion;\n}\n\n/** The converted part of one surface that one source message holds. */\ninterface SourcePart {\n operations: SourceOperation[];\n rejected: GenerativeUIRejectedOperation[];\n}\n\ninterface SurfaceState {\n /** The part of each source message, in the order they first touched it. */\n parts: Map<string, SourcePart>;\n /** JSON of the last snapshot content. */\n lastSnapshot?: string;\n /** Operations sent as deltas, for a surface created in an earlier run. */\n sentOperations: A2UIOperation[];\n /** JSON of the last `rejected` sent as a delta. */\n sentRejected: string;\n}\n\n/**\n * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native\n * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass\n * every event of the run through `transform`, in order.\n *\n * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per\n * messageId (a delta is applied to the stored content), and its\n * operations are converted with {@link upgradeA2UIV09Operations}.\n * - Each surface becomes one `generative-ui-surface` message,\n * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is\n * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the\n * cumulative 1.0 content: the operations of every source message for it,\n * in order, with only the first createSurface. The target is the chat,\n * the status is \"ready\", dropped operations are `rejected` (at their\n * index in the source message), and `a2uiSourceVersion` is \"0.9\" for a\n * surface written in v0.9.\n * - A surface written in native A2UI 1.0 (`version: \"1.0\"`, for example\n * from ADK) becomes the same `generative-ui-surface` message, without\n * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the\n * agent unchanged. One surface has one version, the version of its\n * first operation; an operation of the other version is rejected.\n * - A surface that this run updates but does not create (v0.9 sends no\n * second createSurface) was created in an earlier run, so its new\n * operations are appended to its message with an `ACTIVITY_DELTA`, as\n * the `render_ui` path updates an existing surface.\n * - A lifecycle snapshot (`status: \"building\"` and so on, no operations)\n * names no surface, so it is consumed. Every other event passes through.\n *\n * @example\n * ```ts\n * const upgrader = createA2UIV09ActivityUpgrader();\n * source.pipe(mergeMap((event) => upgrader.transform(event)));\n * ```\n */\nexport function createA2UIV09ActivityUpgrader(): {\n transform(event: BaseEvent): BaseEvent[];\n} {\n const sources = new Map<string, unknown>();\n const surfaces = new Map<string, SurfaceState>();\n\n const snapshotOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n version: SourceVersion,\n ): BaseEvent[] => {\n const create = operations.find((op) => \"createSurface\" in op);\n const catalogId =\n (create && \"createSurface\" in create && create.createSurface.catalogId) ||\n STANDARD_CATALOG_ID;\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId,\n operations,\n status: \"ready\",\n rejected,\n ...(version === \"0.9\" ? { a2uiSourceVersion: \"0.9\" as const } : {}),\n };\n const json = JSON.stringify(content);\n if (json === state.lastSnapshot) return [];\n state.lastSnapshot = json;\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content: cloneValue(content),\n replace: true,\n };\n return [event];\n };\n\n const deltaOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n ): BaseEvent[] => {\n const sent = state.sentOperations;\n let same = 0;\n while (\n same < sent.length &&\n same < operations.length &&\n JSON.stringify(sent[same]) === JSON.stringify(operations[same])\n ) {\n same++;\n }\n // Operations that changed after they were sent cannot be taken back.\n // v0.9 updates replace by id or path, so sending them again is safe.\n const patch: unknown[] = operations.slice(same).map((op) => ({\n op: \"add\",\n path: \"/operations/-\",\n value: cloneValue(op),\n }));\n const rejectedJson = JSON.stringify(rejected);\n if (rejectedJson !== state.sentRejected) {\n patch.push({ op: \"replace\", path: \"/rejected\", value: rejected });\n }\n state.sentOperations = operations;\n state.sentRejected = rejectedJson;\n if (patch.length === 0) return [];\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: patch as ActivityDeltaEvent[\"patch\"],\n };\n return [event];\n };\n\n const emitSurface = (surfaceId: string): BaseEvent[] => {\n const state = surfaces.get(surfaceId);\n if (!state) return [];\n const operations: A2UIOperation[] = [];\n const rejected: GenerativeUIRejectedOperation[] = [];\n let created = false;\n let version: SourceVersion | undefined;\n for (const part of state.parts.values()) {\n for (const { operation, index, version: opVersion } of part.operations) {\n version ??= opVersion;\n if (opVersion !== version) {\n rejected.push({\n index,\n reason: `surface \"${surfaceId}\" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`,\n });\n continue;\n }\n if (\"createSurface\" in operation) {\n // A second createSurface of the same id is rejected in 1.0.\n if (created) continue;\n created = true;\n }\n operations.push(operation);\n }\n rejected.push(...part.rejected);\n }\n return created\n ? snapshotOf(surfaceId, state, operations, rejected, version ?? \"0.9\")\n : deltaOf(surfaceId, state, operations, rejected);\n };\n\n /** Converts the stored content of one source message again. */\n const refresh = (messageId: string): BaseEvent[] => {\n const parts = new Map<string, SourcePart>();\n readOperations(sources.get(messageId)).forEach((op, index) => {\n // An operation with no surface cannot be shown anywhere.\n const surfaceId = surfaceIdOf(op);\n if (surfaceId === undefined) return;\n let part = parts.get(surfaceId);\n if (!part) {\n part = { operations: [], rejected: [] };\n parts.set(surfaceId, part);\n }\n const { operations, dropped } = upgradeA2UIV09Operations([op]);\n // Only v0.9 and 1.0 operations convert.\n const version: SourceVersion =\n isRecord(op) && op.version === A2UI_VERSION ? \"1.0\" : \"0.9\";\n for (const operation of operations) {\n part.operations.push({ operation, index, version });\n }\n for (const { reason } of dropped) part.rejected.push({ index, reason });\n });\n const touched = new Set(parts.keys());\n for (const [surfaceId, state] of surfaces) {\n if (!parts.has(surfaceId) && state.parts.delete(messageId)) {\n touched.add(surfaceId);\n }\n }\n for (const [surfaceId, part] of parts) {\n let state = surfaces.get(surfaceId);\n if (!state) {\n state = { parts: new Map(), sentOperations: [], sentRejected: \"[]\" };\n surfaces.set(surfaceId, state);\n }\n state.parts.set(messageId, part);\n }\n return [...touched].flatMap(emitSurface);\n };\n\n return {\n transform(event) {\n if (event.type === EventType.ACTIVITY_SNAPSHOT) {\n const snapshot = event as ActivitySnapshotEvent;\n if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n return [event];\n }\n const { messageId } = snapshot;\n // `replace: false` does not replace a message that already exists.\n if (snapshot.replace === false && sources.has(messageId)) return [];\n sources.set(messageId, cloneValue(snapshot.content));\n return refresh(messageId);\n }\n if (event.type === EventType.ACTIVITY_DELTA) {\n const delta = event as ActivityDeltaEvent;\n if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];\n const { messageId } = delta;\n if (!sources.has(messageId)) return [];\n let content: unknown;\n try {\n content = applyJsonPatch(\n cloneValue(sources.get(messageId)),\n delta.patch,\n );\n } catch {\n // The AG-UI client also skips a delta that does not apply.\n return [];\n }\n sources.set(messageId, content);\n return refresh(messageId);\n }\n return [event];\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,6BAA6B;AACnC,MAAM,sBAAsB;;AAG5B,MAAM,eAAoC,IAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AACrE,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACD;;;;;;AAQD,MAAM,wBAA6C,IAAI,IAAI,CACzD,0DACA,kEACD,CAAC;;;;;;AAOF,MAAM,wBAA6C,IAAI,IAAI,CACzD,kEACD,CAAC;;AAMF,MAAM,gBAAkD;CACtD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;;AAGD,SAAS,QAAQ,IAAkD;CACjE,MAAM,QAAQ,UAAU,QAAQ,SAAS,QAAQ,GAAG;AACpD,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK;;;;;;;;;;;;;;;;;;AAmBzC,SAAgB,mBAAmB,OAAyB;AAC1D,KAAI,CAAC,SAAS,MAAM,CAAE,QAAO;AAC7B,KAAI,MAAM,YAAY,OACpB,QAAO,OAAO,MAAM,YAAY,YAAY,aAAa,IAAI,MAAM,QAAQ;CAE7E,MAAM,OAAO,QAAQ,MAAM;AAC3B,QAAO,SAAS,UAAa,SAAS,MAAM,MAAM;;AAOpD,MAAM,MAAS,WAAsC;CAAE,IAAI;CAAM;CAAO;AACxE,MAAM,UAAU,YAAmD;CACjE,IAAI;CACJ;CACD;;;;;AAMD,SAAS,aAAa,OAAyB;AAC7C,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,IAAI,aAAa;AACxD,KAAI,CAAC,SAAS,MAAM,CAAE,QAAO;CAC7B,MAAM,OAAO,OA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,CAAE,QAAO,EAAE;GACtC,IAAI;AACJ,OAAI;AACF,cAAU,eACR,WAAW,QAAQ,IAAI,UAAU,CAAC,EAClC,MAAM,MACP;WACK;AAEN,WAAO,EAAE;;AAEX,WAAQ,IAAI,WAAW,QAAQ;AAC/B,UAAO,QAAQ,UAAU;;AAE3B,SAAO,CAAC,MAAM;IAEjB"}
|
|
1
|
+
{"version":3,"file":"a2ui-v09-operations.mjs","names":[],"sources":["../../../src/runtime/generative-ui/a2ui-v09-operations.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type {\n ActivityDeltaEvent,\n ActivitySnapshotEvent,\n BaseEvent,\n} from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CHAT_TARGET,\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n cloneValue,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\nimport { STANDARD_CATALOG_ID } from \"@copilotkit/shared/generative-ui\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The activity type and content key of v0.9 surfaces, as\n * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.\n */\nconst A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\nconst A2UI_OPERATIONS_KEY = \"a2ui_operations\";\n\n/** The `version` values of A2UI v0.9 messages. */\nconst V09_VERSIONS: ReadonlySet<string> = new Set([\"v0.9\", \"v0.9.1\"]);\nconst V09_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n] as const;\ntype V09Kind = (typeof V09_KINDS)[number];\n\n/**\n * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of\n * the published catalog document. Both become the standard catalog, which has\n * the same 18 components.\n */\nconst V09_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\",\n \"https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json\",\n]);\n\n/**\n * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for\n * example ADK) send. It has the 18 components of the v0.9 basic catalog\n * with 1.0 bindings, so it becomes the standard catalog too.\n */\nconst V10_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json\",\n]);\n\n/** The A2UI version that an `a2ui-surface` operation was written in. */\ntype SourceVersion = \"0.9\" | \"1.0\";\n\n/** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */\nconst HEADING_SIZES: Readonly<Record<string, string>> = {\n h1: \"2xl\",\n h2: \"xl\",\n h3: \"lg\",\n h4: \"md\",\n h5: \"sm\",\n};\n\n/** The one v0.9 operation key of `op`, when it has exactly one. */\nfunction v09Kind(op: Record<string, unknown>): V09Kind | undefined {\n const kinds = V09_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/**\n * True for an A2UI v0.9 operation: an object whose `version` is `\"v0.9\"` (or\n * `\"v0.9.1\"`). An object without `version` counts when it has exactly one\n * v0.9 operation key with an object payload. A 1.0 operation always carries\n * `version: \"1.0\"` (the client rejects one without it), and v0.8 uses other\n * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with\n * a v0.9 key can only be v0.9. Agents leave `version` out often enough that\n * requiring it would drop their surfaces.\n *\n * @example\n * ```ts\n * isA2UIV09Operation({ version: \"v0.9\", deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ version: \"1.0\", deleteSurface: { surfaceId: \"s\" } }); // false\n * ```\n */\nexport function isA2UIV09Operation(value: unknown): boolean {\n if (!isRecord(value)) return false;\n if (value.version !== undefined) {\n return typeof value.version === \"string\" && V09_VERSIONS.has(value.version);\n }\n const kind = v09Kind(value);\n return kind !== undefined && isRecord(value[kind]);\n}\n\n// Checked with `ok === false`: runtime compiles non-strict, where a check of\n// `reason` does not narrow the union.\ntype Converted<T> = { ok: true; value: T } | { ok: false; reason: string };\n\nconst ok = <T>(value: T): { ok: true; value: T } => ({ ok: true, value });\nconst failed = (reason: string): { ok: false; reason: string } => ({\n ok: false,\n reason,\n});\n\n/**\n * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ \"@path\" }` and\n * `{ call, args }` becomes `{ \"@call\", args }`, at any depth. Literals stay.\n */\nfunction convertValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(convertValue);\n if (!isRecord(value)) return value;\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.path === \"string\") {\n return { \"@path\": value.path };\n }\n const isCall =\n typeof value.call === \"string\" &&\n keys.every(\n (key) => key === \"call\" || key === \"args\" || key === \"returnType\",\n );\n if (isCall) return convertCall(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, convertValue(item)]),\n );\n}\n\n/** A v0.9 function call `{ call, args, returnType }` as `{ \"@call\", args }`. */\nfunction convertCall(call: Record<string, unknown>) {\n return {\n \"@call\": call.call as string,\n ...(call.args === undefined ? {} : { args: convertValue(call.args) }),\n };\n}\n\n/** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */\nfunction isV09Action(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n return (\n keys.length === 1 && (isRecord(value.event) || isRecord(value.functionCall))\n );\n}\n\n/**\n * A v0.9 action as a 1.0 event binding. The event keeps its name and\n * context (with converted values); a function call gets the `@call` form.\n */\nfunction convertAction(action: unknown): Converted<unknown> {\n if (!isV09Action(action)) {\n return failed('action must be { \"event\": ... } or { \"functionCall\": ... }');\n }\n if (isRecord(action.functionCall)) {\n const call = action.functionCall;\n if (typeof call.call !== \"string\" || !call.call) {\n return failed(\"action.functionCall.call must be a function name\");\n }\n return ok({ functionCall: convertCall(call) });\n }\n const event = action.event as Record<string, unknown>;\n if (typeof event.name !== \"string\" || !event.name) {\n return failed(\"action.event.name is required\");\n }\n return ok({\n event: {\n name: event.name,\n ...(event.context === undefined\n ? {}\n : { context: convertValue(event.context) }),\n },\n });\n}\n\n/**\n * The basic-catalog changes of one component. Every other prop keeps its\n * name; the 1.0 standard catalog uses the v0.9 names.\n *\n * - `Text` with a heading `variant` becomes `Title` (h1 \"2xl\" to h5 \"sm\"),\n * with `caption` it becomes `Caption`; `variant` goes. Title and Caption\n * have no `weight`, so it goes too.\n * - `Button.action` becomes `onClick`.\n * - `TextField.validationRegexp` becomes a `regex` check on its value.\n */\nfunction applyBasicCatalogChanges(node: Record<string, unknown>) {\n if (node.component === \"Text\" && \"variant\" in node) {\n const { variant, ...rest } = node;\n const size =\n typeof variant === \"string\" ? HEADING_SIZES[variant] : undefined;\n if (size !== undefined) {\n const { weight: _weight, ...title } = rest;\n return { ...title, component: \"Title\", size };\n }\n if (variant === \"caption\") {\n const { weight: _weight, ...caption } = rest;\n return { ...caption, component: \"Caption\" };\n }\n return rest;\n }\n if (node.component === \"Button\" && \"action\" in node) {\n const { action, ...rest } = node;\n return { ...rest, onClick: action };\n }\n if (node.component === \"TextField\" && \"validationRegexp\" in node) {\n const { validationRegexp, ...rest } = node;\n if (typeof validationRegexp !== \"string\" || rest.value === undefined) {\n return rest;\n }\n const check = {\n condition: {\n \"@call\": \"regex\",\n args: { value: rest.value, pattern: validationRegexp },\n },\n };\n const checks = Array.isArray(rest.checks) ? rest.checks : [];\n return { ...rest, checks: [...checks, check] };\n }\n return node;\n}\n\n/** One v0.9 component (flat format) as a 1.0 component node. */\nfunction convertComponent(node: unknown): Converted<A2UIComponentNode> {\n if (!isRecord(node) || typeof node.id !== \"string\" || !node.id) {\n return failed(\"a component needs a string id\");\n }\n if (typeof node.component !== \"string\" || !node.component) {\n return failed(\n `component \"${node.id}\": the component type must be a string (the v0.9 flat format)`,\n );\n }\n const converted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\") {\n converted[key] = value;\n } else if (key === \"action\" || isV09Action(value)) {\n const action = convertAction(value);\n if (action.ok === false) {\n return failed(`component \"${node.id}\": ${action.reason}`);\n }\n converted[key] = action.value;\n } else {\n converted[key] = convertValue(value);\n }\n }\n return ok(applyBasicCatalogChanges(converted) as A2UIComponentNode);\n}\n\nfunction convertUpdateComponents(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { components } = payload;\n if (!Array.isArray(components) || components.length === 0) {\n return failed(\"updateComponents.components must be a non-empty array\");\n }\n const nodes: A2UIComponentNode[] = [];\n for (const component of components) {\n const converted = convertComponent(component);\n if (converted.ok === false) return converted;\n nodes.push(converted.value);\n }\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n });\n}\n\n/**\n * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it\n * for `null`. At the root, removing means an empty data model.\n */\nfunction convertUpdateDataModel(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { path, value } = payload;\n if (path !== undefined && typeof path !== \"string\") {\n return failed(\"updateDataModel.path must be a string\");\n }\n const relative = typeof path === \"string\" ? path : \"\";\n const pointer = relative.startsWith(\"/\") ? relative : `/${relative}`;\n const isRoot = pointer === \"/\";\n if (isRoot && value !== undefined && !isRecord(value)) {\n return failed(\n \"a root updateDataModel value must be a JSON object in A2UI 1.0\",\n );\n }\n const nextValue = value === undefined ? (isRoot ? {} : null) : value;\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path: pointer, value: nextValue },\n });\n}\n\nfunction convertCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n): A2UIOperation {\n const { catalogId } = payload;\n const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;\n return {\n version: A2UI_VERSION,\n createSurface: {\n surfaceId,\n ...(typeof catalogId === \"string\" && catalogId\n ? {\n catalogId: V09_BASIC_CATALOG_IDS.has(catalogId)\n ? STANDARD_CATALOG_ID\n : catalogId,\n }\n : {}),\n ...(typeof sendDataModel === \"boolean\" ? { sendDataModel } : {}),\n },\n };\n}\n\n/** Basic catalog components as standard ones; anything else stays. */\nfunction standardComponents(components: unknown) {\n return Array.isArray(components)\n ? components.map((node) =>\n isRecord(node) ? applyBasicCatalogChanges(node) : node,\n )\n : components;\n}\n\n/**\n * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic\n * catalog id becomes the standard catalog id, and the basic catalog\n * components (inline in createSurface, or in updateComponents) get the\n * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.\n * Everything else stays; the client validates the operation.\n */\nfunction upgradeV10Operation(op: Record<string, unknown>): A2UIOperation {\n const { createSurface: create, updateComponents: update } = op;\n if (isRecord(create)) {\n const { catalogId } = create;\n return {\n ...op,\n createSurface: {\n ...create,\n ...(typeof catalogId === \"string\" &&\n V10_BASIC_CATALOG_IDS.has(catalogId)\n ? { catalogId: STANDARD_CATALOG_ID }\n : {}),\n ...(create.components === undefined\n ? {}\n : { components: standardComponents(create.components) }),\n },\n } as A2UIOperation;\n }\n if (isRecord(update)) {\n return {\n ...op,\n updateComponents: {\n ...update,\n ...(update.components === undefined\n ? {}\n : { components: standardComponents(update.components) }),\n },\n } as A2UIOperation;\n }\n return op as A2UIOperation;\n}\n\n/** One operation as 1.0, or why it cannot be converted. */\nfunction upgradeOperation(op: unknown): Converted<A2UIOperation> {\n if (!isRecord(op)) return failed(\"operation must be a JSON object\");\n if (op.version === A2UI_VERSION) return ok(upgradeV10Operation(op));\n if (!isA2UIV09Operation(op)) {\n return failed(\n typeof op.version === \"string\"\n ? `unsupported A2UI version \"${op.version}\"; only v0.9 and 1.0 operations are supported`\n : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const kind = v09Kind(op);\n if (!kind) {\n return failed(\n `operation must contain exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return failed(`${kind}.surfaceId is required`);\n }\n const { surfaceId } = payload;\n switch (kind) {\n case \"createSurface\":\n return ok(convertCreateSurface(payload, surfaceId));\n case \"updateComponents\":\n return convertUpdateComponents(payload, surfaceId);\n case \"updateDataModel\":\n return convertUpdateDataModel(payload, surfaceId);\n case \"deleteSurface\":\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n deleteSurface: { surfaceId },\n });\n }\n}\n\n/**\n * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.\n *\n * - createSurface: the v0.9 basic catalog id becomes the standard catalog\n * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no\n * 1.0 field and goes; `sendDataModel` stays.\n * - updateComponents: `{ path }` becomes `{ \"@path\" }` and `{ call, args }`\n * becomes `{ \"@call\", args }` at any depth; an action becomes an\n * `{ event }` or `{ functionCall }` binding; child lists and templates\n * stay. See {@link applyBasicCatalogChanges} for the props that change.\n * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at\n * the root.\n * - deleteSurface: unchanged.\n *\n * An operation that is already 1.0 (native, for example from ADK) keeps its\n * form: only the 1.0 basic catalog id becomes the standard catalog id, and\n * its basic catalog components get the same changes as v0.9 ones. Any other\n * operation, and any v0.9 operation that cannot be converted, goes to\n * `dropped` with the reason.\n *\n * @example\n * ```ts\n * upgradeA2UIV09Operations([\n * { version: \"v0.9\", updateDataModel: { surfaceId: \"s\", path: \"/x\" } },\n * ]);\n * // { operations: [{ version: \"1.0\", updateDataModel: { surfaceId: \"s\", path: \"/x\", value: null } }], dropped: [] }\n * ```\n */\nexport function upgradeA2UIV09Operations(operations: unknown[]): {\n operations: A2UIOperation[];\n dropped: Array<{ operation: unknown; reason: string }>;\n} {\n const upgraded: A2UIOperation[] = [];\n const dropped: Array<{ operation: unknown; reason: string }> = [];\n for (const operation of Array.isArray(operations) ? operations : []) {\n let result: Converted<A2UIOperation>;\n try {\n result = upgradeOperation(operation);\n } catch (error) {\n // A getter or a Proxy trap of the operation threw while it was read.\n result = failed(\n `operation could not be read: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n if (result.ok === false) {\n dropped.push({ operation, reason: result.reason });\n } else {\n upgraded.push(result.value);\n }\n }\n return { operations: upgraded, dropped };\n}\n\n/** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */\nfunction surfaceIdOf(op: unknown) {\n if (!isRecord(op)) return undefined;\n for (const kind of V09_KINDS) {\n const payload = op[kind];\n if (isRecord(payload) && typeof payload.surfaceId === \"string\") {\n return payload.surfaceId || undefined;\n }\n }\n return undefined;\n}\n\n/**\n * The error of a `failed` lifecycle snapshot: the agent's A2UI recovery\n * gave up (`a2ui_recovery_exhausted`). Undefined for any other content.\n */\nfunction failedLifecycleError(content: unknown): string | undefined {\n if (!isRecord(content) || content.status !== \"failed\") return undefined;\n const error =\n typeof content.error === \"string\" && content.error\n ? content.error\n : \"A2UI generation failed\";\n return error.slice(0, GENERATIVE_UI_MAX_REJECTION_LENGTH);\n}\n\n/** The operations of `a2ui-surface` content. Lifecycle content has none. */\nfunction readOperations(content: unknown): unknown[] {\n if (!isRecord(content)) return [];\n const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;\n return Array.isArray(operations) ? operations : [];\n}\n\ntype JsonPatchOperation = {\n op: \"add\" | \"remove\" | \"replace\" | \"move\" | \"copy\" | \"test\";\n path: string;\n from?: string;\n value?: unknown;\n};\n\nfunction pointerSegments(pointer: string) {\n if (pointer === \"\") return [];\n if (!pointer.startsWith(\"/\")) throw new Error(`invalid pointer \"${pointer}\"`);\n return pointer\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Applies RFC 6902 operations to `document` in place and returns the new\n * root. Throws on a path that does not resolve, like `fast-json-patch` in\n * the AG-UI client, so a bad delta leaves the stored content alone.\n */\nfunction applyJsonPatch(document: unknown, patch: unknown): unknown {\n if (!Array.isArray(patch)) throw new Error(\"patch must be an array\");\n let root = document;\n const parentOf = (pointer: string) => {\n const segments = pointerSegments(pointer);\n const key = segments.pop();\n let parent: unknown = root;\n for (const segment of segments) {\n if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error(\"forbidden path\");\n parent = Array.isArray(parent)\n ? parent[Number(segment)]\n : isRecord(parent)\n ? parent[segment]\n : undefined;\n if (parent === undefined) throw new Error(`path \"${pointer}\" not found`);\n }\n if (key !== undefined && FORBIDDEN_SEGMENTS.has(key)) {\n throw new Error(\"forbidden path\");\n }\n return { parent, key };\n };\n const read = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) return root;\n if (Array.isArray(parent)) return parent[Number(key)];\n return isRecord(parent) ? parent[key] : undefined;\n };\n const remove = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) throw new Error(\"cannot remove the root\");\n if (Array.isArray(parent)) parent.splice(Number(key), 1);\n else if (isRecord(parent) && key in parent) delete parent[key];\n else throw new Error(`path \"${pointer}\" not found`);\n };\n const write = (pointer: string, value: unknown, insert: boolean) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) {\n root = value;\n } else if (Array.isArray(parent)) {\n const index = key === \"-\" ? parent.length : Number(key);\n if (!Number.isInteger(index) || index < 0 || index > parent.length) {\n throw new Error(`index \"${key}\" is out of range`);\n }\n parent.splice(index, insert ? 0 : 1, value);\n } else if (isRecord(parent)) {\n parent[key] = value;\n } else {\n throw new Error(`path \"${pointer}\" not found`);\n }\n };\n for (const entry of patch as JsonPatchOperation[]) {\n if (!isRecord(entry) || typeof entry.path !== \"string\") {\n throw new Error(\"invalid patch operation\");\n }\n switch (entry.op) {\n case \"add\":\n write(entry.path, cloneValue(entry.value), true);\n break;\n case \"replace\":\n if (read(entry.path) === undefined) {\n throw new Error(`path \"${entry.path}\" not found`);\n }\n write(entry.path, cloneValue(entry.value), false);\n break;\n case \"remove\":\n remove(entry.path);\n break;\n case \"copy\":\n write(entry.path, cloneValue(read(entry.from ?? \"\")), true);\n break;\n case \"move\": {\n const value = read(entry.from ?? \"\");\n remove(entry.from ?? \"\");\n write(entry.path, value, true);\n break;\n }\n case \"test\":\n if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) {\n throw new Error(`test failed at \"${entry.path}\"`);\n }\n break;\n default:\n throw new Error(`unknown patch op \"${String(entry.op)}\"`);\n }\n }\n return root;\n}\n\n/** One converted operation, with where it came from. */\ninterface SourceOperation {\n operation: A2UIOperation;\n /** Its index in the source message. */\n index: number;\n version: SourceVersion;\n}\n\n/** The converted part of one surface that one source message holds. */\ninterface SourcePart {\n operations: SourceOperation[];\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/**\n * The operations of the next snapshot of a surface, so that the client\n * applies every change of the source.\n *\n * The client applies only the operations after the ones it applied, when the\n * operation at its last applied index did not change. A source that changes\n * an earlier operation but not that one (a progressive render that rewrites\n * its components, then sends the same data again) would lose the change. In\n * that case the changed operations of the source are appended to the sent\n * ones: v0.9 updates replace by id or path, so sending them again is safe,\n * and a second createSurface is left out. In every other case the source\n * operations go as they are: the client either extends its surface with them\n * or builds it again from them.\n *\n * @param lastSource - The source operations of the last snapshot (none\n * before the first one).\n * @param sent - The operations of the last snapshot.\n * @param source - The source operations now.\n * @returns The operations of the next snapshot.\n */\nfunction clientOperations(\n lastSource: A2UIOperation[],\n sent: A2UIOperation[],\n source: A2UIOperation[],\n): A2UIOperation[] {\n let same = 0;\n while (\n same < lastSource.length &&\n same < source.length &&\n JSON.stringify(lastSource[same]) === JSON.stringify(source[same])\n ) {\n same++;\n }\n const appended = source.slice(same);\n if (same === lastSource.length) return [...sent, ...appended];\n // The client builds the surface again when the list is shorter than the\n // one it applied, or when the operation at its last applied index changed.\n const last = sent.length - 1;\n if (\n source.length < sent.length ||\n JSON.stringify(source[last]) !== JSON.stringify(sent[last])\n ) {\n return source;\n }\n return [...sent, ...appended.filter((op) => !(\"createSurface\" in op))];\n}\n\ninterface SurfaceState {\n /** The part of each source message, in the order they first touched it. */\n parts: Map<string, SourcePart>;\n /** JSON of the last snapshot content. */\n lastSnapshot?: string;\n /** The converted operations of the source, at the last snapshot. */\n snapshotSource: A2UIOperation[];\n /** The operations of the last snapshot, as the client applied them. */\n snapshotOperations: A2UIOperation[];\n /** Operations sent as deltas, for a surface created in an earlier run. */\n sentOperations: A2UIOperation[];\n /** JSON of the last `rejected` sent as a delta. */\n sentRejected: string;\n}\n\n/**\n * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native\n * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass\n * every event of the run through `transform`, in order.\n *\n * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per\n * messageId (a delta is applied to the stored content), and its\n * operations are converted with {@link upgradeA2UIV09Operations}.\n * - Each surface becomes one `generative-ui-surface` message,\n * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is\n * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the\n * cumulative 1.0 content: the operations of every source message for it,\n * in order, with only the first createSurface. The target is the chat,\n * the status is \"ready\", dropped operations are `rejected` (at their\n * index in the source message), and `a2uiSourceVersion` is \"0.9\" for a\n * surface written in v0.9.\n * - A surface written in native A2UI 1.0 (`version: \"1.0\"`, for example\n * from ADK) becomes the same `generative-ui-surface` message, without\n * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the\n * agent unchanged. One surface has one version, the version of its\n * first operation; an operation of the other version is rejected.\n * - A surface that this run updates but does not create (v0.9 sends no\n * second createSurface) was created in an earlier run, so its new\n * operations are appended to its message with an `ACTIVITY_DELTA`, as\n * the `render_ui` path updates an existing surface.\n * - A lifecycle snapshot (`status: \"building\"` and so on, no operations)\n * names no surface, so it is consumed. A `failed` one (the agent's\n * recovery gave up) becomes a surface with no operations, status\n * \"error\", and its error as the one rejected entry, so the chat shows\n * that the UI could not be made. Its surfaceId is the source messageId.\n * Every other event passes through.\n *\n * @example\n * ```ts\n * const upgrader = createA2UIV09ActivityUpgrader();\n * source.pipe(mergeMap((event) => upgrader.transform(event)));\n * ```\n */\nexport function createA2UIV09ActivityUpgrader(): {\n transform(event: BaseEvent): BaseEvent[];\n} {\n const sources = new Map<string, unknown>();\n const surfaces = new Map<string, SurfaceState>();\n /** The source messages whose `failed` snapshot was sent. */\n const failures = new Set<string>();\n\n /** The surface that shows a failed lifecycle snapshot, sent once. */\n const failureOf = (messageId: string, error: string): BaseEvent[] => {\n if (failures.has(messageId)) return [];\n failures.add(messageId);\n const content: GenerativeUISurfaceContent = {\n surfaceId: messageId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId: STANDARD_CATALOG_ID,\n operations: [],\n status: \"error\",\n rejected: [{ index: 0, reason: error }],\n a2uiSourceVersion: \"0.9\",\n };\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(messageId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n };\n return [event];\n };\n\n const snapshotOf = (\n surfaceId: string,\n state: SurfaceState,\n source: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n version: SourceVersion,\n ): BaseEvent[] => {\n const operations = clientOperations(\n state.snapshotSource,\n state.snapshotOperations,\n source,\n );\n const create = operations.find((op) => \"createSurface\" in op);\n const catalogId =\n (create && \"createSurface\" in create && create.createSurface.catalogId) ||\n STANDARD_CATALOG_ID;\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId,\n operations,\n status: \"ready\",\n rejected,\n ...(version === \"0.9\" ? { a2uiSourceVersion: \"0.9\" as const } : {}),\n };\n const json = JSON.stringify(content);\n if (json === state.lastSnapshot) return [];\n state.lastSnapshot = json;\n state.snapshotSource = source;\n state.snapshotOperations = operations;\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content: cloneValue(content),\n replace: true,\n };\n return [event];\n };\n\n const deltaOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n ): BaseEvent[] => {\n const sent = state.sentOperations;\n let same = 0;\n while (\n same < sent.length &&\n same < operations.length &&\n JSON.stringify(sent[same]) === JSON.stringify(operations[same])\n ) {\n same++;\n }\n // Operations that changed after they were sent cannot be taken back.\n // v0.9 updates replace by id or path, so sending them again is safe.\n const patch: unknown[] = operations.slice(same).map((op) => ({\n op: \"add\",\n path: \"/operations/-\",\n value: cloneValue(op),\n }));\n const rejectedJson = JSON.stringify(rejected);\n if (rejectedJson !== state.sentRejected) {\n patch.push({ op: \"replace\", path: \"/rejected\", value: rejected });\n }\n state.sentOperations = operations;\n state.sentRejected = rejectedJson;\n if (patch.length === 0) return [];\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: patch as ActivityDeltaEvent[\"patch\"],\n };\n return [event];\n };\n\n const emitSurface = (surfaceId: string): BaseEvent[] => {\n const state = surfaces.get(surfaceId);\n if (!state) return [];\n const operations: A2UIOperation[] = [];\n const rejected: GenerativeUIRejectedOperation[] = [];\n let created = false;\n let version: SourceVersion | undefined;\n for (const part of state.parts.values()) {\n for (const { operation, index, version: opVersion } of part.operations) {\n version ??= opVersion;\n if (opVersion !== version) {\n rejected.push({\n index,\n reason: `surface \"${surfaceId}\" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`,\n });\n continue;\n }\n if (\"createSurface\" in operation) {\n // A second createSurface of the same id is rejected in 1.0.\n if (created) continue;\n created = true;\n }\n operations.push(operation);\n }\n rejected.push(...part.rejected);\n }\n return created\n ? snapshotOf(surfaceId, state, operations, rejected, version ?? \"0.9\")\n : deltaOf(surfaceId, state, operations, rejected);\n };\n\n /** Converts the stored content of one source message again. */\n const refresh = (messageId: string): BaseEvent[] => {\n const parts = new Map<string, SourcePart>();\n readOperations(sources.get(messageId)).forEach((op, index) => {\n // An operation with no surface cannot be shown anywhere.\n const surfaceId = surfaceIdOf(op);\n if (surfaceId === undefined) return;\n let part = parts.get(surfaceId);\n if (!part) {\n part = { operations: [], rejected: [] };\n parts.set(surfaceId, part);\n }\n const { operations, dropped } = upgradeA2UIV09Operations([op]);\n // Only v0.9 and 1.0 operations convert.\n const version: SourceVersion =\n isRecord(op) && op.version === A2UI_VERSION ? \"1.0\" : \"0.9\";\n for (const operation of operations) {\n part.operations.push({ operation, index, version });\n }\n for (const { reason } of dropped) part.rejected.push({ index, reason });\n });\n const touched = new Set(parts.keys());\n for (const [surfaceId, state] of surfaces) {\n if (!parts.has(surfaceId) && state.parts.delete(messageId)) {\n touched.add(surfaceId);\n }\n }\n for (const [surfaceId, part] of parts) {\n let state = surfaces.get(surfaceId);\n if (!state) {\n state = {\n parts: new Map(),\n snapshotSource: [],\n snapshotOperations: [],\n sentOperations: [],\n sentRejected: \"[]\",\n };\n surfaces.set(surfaceId, state);\n }\n state.parts.set(messageId, part);\n }\n const events = [...touched].flatMap(emitSurface);\n const error = failedLifecycleError(sources.get(messageId));\n return error === undefined\n ? events\n : [...events, ...failureOf(messageId, error)];\n };\n\n return {\n transform(event) {\n if (event.type === EventType.ACTIVITY_SNAPSHOT) {\n const snapshot = event as ActivitySnapshotEvent;\n if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n return [event];\n }\n const { messageId } = snapshot;\n // `replace: false` does not replace a message that already exists.\n if (snapshot.replace === false && sources.has(messageId)) return [];\n sources.set(messageId, cloneValue(snapshot.content));\n return refresh(messageId);\n }\n if (event.type === EventType.ACTIVITY_DELTA) {\n const delta = event as ActivityDeltaEvent;\n if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];\n const { messageId } = delta;\n if (!sources.has(messageId)) return [];\n let content: unknown;\n try {\n content = applyJsonPatch(\n cloneValue(sources.get(messageId)),\n delta.patch,\n );\n } catch {\n // The AG-UI client also skips a delta that does not apply.\n return [];\n }\n sources.set(messageId, content);\n return refresh(messageId);\n }\n return [event];\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAM,6BAA6B;AACnC,MAAM,sBAAsB;;AAG5B,MAAM,eAAoC,IAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AACrE,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACD;;;;;;AAQD,MAAM,wBAA6C,IAAI,IAAI,CACzD,0DACA,kEACD,CAAC;;;;;;AAOF,MAAM,wBAA6C,IAAI,IAAI,CACzD,kEACD,CAAC;;AAMF,MAAM,gBAAkD;CACtD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;;AAGD,SAAS,QAAQ,IAAkD;CACjE,MAAM,QAAQ,UAAU,QAAQ,SAAS,QAAQ,GAAG;AACpD,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK;;;;;;;;;;;;;;;;;;AAmBzC,SAAgB,mBAAmB,OAAyB;AAC1D,KAAI,CAAC,SAAS,MAAM,CAAE,QAAO;AAC7B,KAAI,MAAM,YAAY,OACpB,QAAO,OAAO,MAAM,YAAY,YAAY,aAAa,IAAI,MAAM,QAAQ;CAE7E,MAAM,OAAO,QAAQ,MAAM;AAC3B,QAAO,SAAS,UAAa,SAAS,MAAM,MAAM;;AAOpD,MAAM,MAAS,WAAsC;CAAE,IAAI;CAAM;CAAO;AACxE,MAAM,UAAU,YAAmD;CACjE,IAAI;CACJ;CACD;;;;;AAMD,SAAS,aAAa,OAAyB;AAC7C,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,IAAI,aAAa;AACxD,KAAI,CAAC,SAAS,M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;;AAE3B,MAAI,MAAM,SAAS,UAAU,gBAAgB;GAC3C,MAAM,QAAQ;AACd,OAAI,MAAM,iBAAiB,2BAA4B,QAAO,CAAC,MAAM;GACrE,MAAM,EAAE,cAAc;AACtB,OAAI,CAAC,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;GACtC,IAAI;AACJ,OAAI;AACF,cAAU,eACR,WAAW,QAAQ,IAAI,UAAU,CAAC,EAClC,MAAM,MACP;WACK;AAEN,WAAO,EAAE;;AAEX,WAAQ,IAAI,WAAW,QAAQ;AAC/B,UAAO,QAAQ,UAAU;;AAE3B,SAAO,CAAC,MAAM;IAEjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/runtime",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.46",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@ag-ui/mcp-middleware": "0.0.2",
|
|
85
85
|
"@cfworker/json-schema": "^4.1.1",
|
|
86
86
|
"@copilotkit/license-verifier": "~0.5.0",
|
|
87
|
-
"@copilotkit/shared": "2.0.0-rc.
|
|
87
|
+
"@copilotkit/shared": "2.0.0-rc.46",
|
|
88
88
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
89
89
|
"@remix-run/node-fetch-server": "^0.13.0",
|
|
90
90
|
"@tanstack/ai": "^1.2.0",
|