@copilotkit/shared 2.0.0-rc.14 → 2.0.0-rc.16
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/a2ui-envelope.cjs +2 -2
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +2 -2
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/generative-ui/child-refs.cjs +3 -3
- package/dist/generative-ui/child-refs.cjs.map +1 -1
- package/dist/generative-ui/child-refs.d.cts.map +1 -1
- package/dist/generative-ui/child-refs.d.mts.map +1 -1
- package/dist/generative-ui/child-refs.mjs +3 -3
- package/dist/generative-ui/child-refs.mjs.map +1 -1
- package/dist/generative-ui/prompt-spec.cjs +11 -11
- package/dist/generative-ui/prompt-spec.cjs.map +1 -1
- package/dist/generative-ui/prompt-spec.mjs +11 -11
- package/dist/generative-ui/prompt-spec.mjs.map +1 -1
- package/dist/generative-ui/prompt.cjs +1 -1
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.mjs +1 -1
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +1 -1
- package/dist/generative-ui/schema-render.cjs.map +1 -1
- package/dist/generative-ui/schema-render.d.cts.map +1 -1
- package/dist/generative-ui/schema-render.d.mts.map +1 -1
- package/dist/generative-ui/schema-render.mjs +1 -1
- package/dist/generative-ui/schema-render.mjs.map +1 -1
- package/dist/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +7 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +7 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/generative-ui/validate-operation.cjs +2 -2
- package/dist/generative-ui/validate-operation.cjs.map +1 -1
- package/dist/generative-ui/validate-operation.mjs +2 -2
- package/dist/generative-ui/validate-operation.mjs.map +1 -1
- package/dist/index.umd.js +24 -24
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/telemetry/lambda-client.cjs +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/a2ui-envelope.test.ts +18 -13
- package/src/__tests__/a2ui-prompts.test.ts +5 -5
- package/src/__tests__/fixtures/prompt-goldens.json +64 -64
- package/src/a2ui-envelope.ts +7 -6
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- package/src/generative-ui/child-refs.ts +5 -4
- package/src/generative-ui/prompt-spec.ts +11 -11
- package/src/generative-ui/prompt.ts +1 -1
- package/src/generative-ui/schema-render.ts +4 -1
- package/src/generative-ui/types.ts +10 -7
- package/src/generative-ui/validate-operation.ts +2 -2
- package/src/telemetry/lambda-client.ts +5 -1
- package/tsconfig.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-render.cjs","names":["compactType","compactProps","functionCallers","GENERATIVE_UI_AGENT_FUNCTION_CALLS","buildCompactGenerativeUISchema"],"sources":["../../src/generative-ui/schema-render.ts"],"sourcesContent":["import { functionCallers } from \"./basic-functions\";\nimport {\n buildCompactGenerativeUISchema,\n compactProps,\n compactType,\n} from \"./compact-schema\";\nimport type { GenerativeUISchemaSettings } from \"./prompt-spec\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type {\n GenerativeUIComponentManifest,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\n\ntype SchemaManifest = Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"components\" | \"functions\" | \"targets\" | \"surfaces\"\n>;\n\n/** An own key (shared compiles to ES2017, which has no Object.hasOwn). */\nconst hasOwn = (target: object, key: string) =>\n Object.prototype.hasOwnProperty.call(target, key);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The props schema without the description of each prop. */\nfunction withoutPropDescriptions(\n schema: GenerativeUIJSONSchema,\n): GenerativeUIJSONSchema {\n if (!isRecord(schema.properties)) return schema;\n return {\n ...schema,\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => {\n if (!isRecord(value)) return [key, value];\n const { description: _description, ...rest } = value;\n return [key, rest];\n }),\n ),\n };\n}\n\n/** The short signature of a function: its built-in signature, or its schema made short. */\nfunction functionSignature(fn: GenerativeUIManifest[\"functions\"][string]) {\n const signature = fn.parameters.description;\n const hasSignature =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(fn.parameters).length === 2;\n return hasSignature ? signature : compactType(fn.parameters, 0);\n}\n\n/**\n * A function name with its parameters: `pick{ id: string }`, `clearCart{}`\n * for no arguments, `setVolume(number)` for a parameter that is not an object.\n */\nfunction nameWithParameters(name: string, parameters: string) {\n if (parameters.startsWith(\"{\")) return `${name}${parameters}`;\n if (parameters === \"object\") return `${name}{}`;\n return `${name}(${parameters})`;\n}\n\n/**\n * One component as a TypeScript-like signature line, with its events and\n * slots on the lines below:\n * `- Text(text?: string // The text): Shows text`.\n */\nfunction signatureLines(\n name: string,\n component: GenerativeUIComponentManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const props = Object.entries(\n compactProps(component.props, settings.propDescriptions),\n ).map(([key, type]) => `${key}: ${type}`);\n const lines = [\n `- ${name}(${props.join(\", \")})${component.description ? `: ${oneLine(component.description)}` : \"\"}`,\n ];\n const events = Object.entries(component.events ?? {}).map(\n ([event, definition]) =>\n `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`,\n );\n if (events.length > 0) lines.push(` events: ${events.join(\", \")}`);\n const slots = Object.entries(component.slots ?? {}).map(\n ([slot, kind]) => `${slot} (${kind})`,\n );\n if (slots.length > 0) lines.push(` slots: ${slots.join(\", \")}`);\n return lines;\n}\n\n/** The whole schema as signature text: targets, functions, components, surfaces. */\nfunction signatureSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const targets = manifest.targets.map((t) => {\n const limit = t.components ? `; only ${t.components.join(\", \")}` : \"\";\n return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n });\n const functions = Object.entries(manifest.functions).map(([name, fn]) => {\n const callers = functionCallers(fn);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`;\n });\n const components = Object.entries(manifest.components).flatMap(\n ([name, component]) => signatureLines(name, component, settings),\n );\n const surfaces = Object.entries(manifest.surfaces).map(\n ([id, s]) =>\n `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : \"\"}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : \"\"}${(s.rejected ?? []).map((r) => ` rejected: ${r}`).join(\"\")}`,\n );\n return [\n `Catalog: ${manifest.catalogId}`,\n `Targets:\\n${targets.join(\"\\n\") || \"- none\"}`,\n `Functions:\\n${functions.join(\"\\n\") || \"- none\"}`,\n `Components:\\n${components.join(\"\\n\") || \"- none\"}`,\n `Surfaces:\\n${surfaces.join(\"\\n\") || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n\n/** A description on one line, so its lines cannot read as new entries. */\nfunction oneLine(text: string) {\n return text.replace(/\\s*\\n\\s*/g, \" \");\n}\n\n/** Values that would read as a type or a number once their quotes are gone. */\nconst AMBIGUOUS_VALUE =\n /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\\d[\\d.]*)$/;\n\n/**\n * A compact type with bare enum values and tight unions:\n * `\"sm\" | \"md\" | \"lg\"` becomes `sm|md|lg`. A union keeps its quotes when it\n * also holds a type (`\"sm\" | number`) or a value that reads as a type or a\n * number (`\"number\" | \"currency\"`, `\"1\" | \"2\"`), and so do values that are\n * not plain words.\n */\nfunction bareType(type: string) {\n return type\n .replace(\n /\"[A-Za-z0-9_#%.-]+\"(?: \\| \"[A-Za-z0-9_#%.-]+\")*(?! \\|)/g,\n (union: string, offset: number, whole: string) => {\n if (whole.slice(offset - 2, offset) === \"| \") return union;\n const values = union.split(\" | \").map((v) => v.slice(1, -1));\n if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;\n return values.join(\"|\");\n },\n )\n .replace(/ \\| /g, \"|\");\n}\n\n/** A compact prop (`type // description`) as `name: type - description`. */\nfunction propLine(key: string, value: string) {\n const name = key.endsWith(\"?\") ? key.slice(0, -1) : `${key}*`;\n const cut = value.indexOf(\" // \");\n const type = bareType(cut < 0 ? value : value.slice(0, cut));\n const text = cut < 0 ? \"\" : value.slice(cut + 4).trim();\n const description = text ? ` - ${oneLine(text)}` : \"\";\n return ` ${name}: ${type}${description}`;\n}\n\n/**\n * The whole schema as plain lines: a header line per component and one\n * indented line per prop: events are `action` props and slots `componentId`\n * or `childList` props. Props are optional unless marked `*`, enum values\n * are bare, and the common props are listed once. It carries the same names, types and descriptions as\n * `compact`, in fewer tokens.\n */\nfunction linesSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const compact = buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n });\n const targets = compact.targets\n .map((t) => {\n const limit = t.components ? `, only ${t.components.join(\", \")}` : \"\";\n return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n })\n .join(\"; \");\n const functions = Object.entries(compact.functions).map(\n ([name, fn]) =>\n `${nameWithParameters(name, fn.parameters)}${\"callers\" in fn ? ` (${fn.callers})` : \"\"}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`,\n );\n const common = compact.commonProps\n ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v))\n : [];\n const lineSets = Object.entries(compact.components).map(([name, c]) => ({\n name,\n c,\n own: [\n ...Object.entries(c.props).map(([k, v]) => propLine(k, v)),\n ...Object.entries(c.events ?? {}).map(\n ([e, d]) => ` ${e}: action - ${oneLine(d)}`,\n ),\n ],\n }));\n const components = lineSets.flatMap(({ name, c, own }) => {\n const lines = [\n `${name}${c.includesCommonProps ? \" +common\" : \"\"}${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ...own,\n ];\n // Slots are props that take component ids.\n for (const [slot, kind] of Object.entries(c.slots ?? {})) {\n lines.push(\n ` ${slot}: ${kind === \"single\" ? \"componentId\" : \"childList\"}`,\n );\n }\n return lines;\n });\n const surfaces = Object.keys(compact.surfaces).length\n ? JSON.stringify(compact.surfaces)\n : \"none\";\n return [\n `Catalog ${compact.catalogId}. Targets: ${targets || \"none\"}`,\n 'Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.',\n `Functions:\\n${functions.join(\"\\n\")}`,\n ...(common.length ? [`Common props:\\n${common.join(\"\\n\")}`] : []),\n `Components:\\n${components.join(\"\\n\")}`,\n `Surfaces: ${surfaces}`,\n ].join(\"\\n\\n\");\n}\n\n/**\n * The component schema of the markdown transport, as the text of its\n * context entry, in the notation of `settings`. `compact` is the schema that\n * ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts\n * as JSON, `ts-signature` one line per component, `lines` one line per\n * prop with bare enums (the fewest tokens).\n *\n * @example\n * ```ts\n * const value = renderGenerativeUISchema(manifest, spec.schema.markdown);\n * ```\n */\nexport function renderGenerativeUISchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n): string {\n switch (settings.notation) {\n case \"compact\":\n return JSON.stringify(\n buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n }),\n );\n case \"json-schema\": {\n const components = Object.fromEntries(\n Object.entries(manifest.components).map(([name, c]) => [\n name,\n settings.propDescriptions\n ? c\n : { ...c, props: withoutPropDescriptions(c.props) },\n ]),\n );\n return JSON.stringify({\n catalogId: manifest.catalogId,\n targets: manifest.targets,\n functions: manifest.functions,\n components,\n surfaces: manifest.surfaces,\n });\n }\n case \"ts-signature\":\n return signatureSchema(manifest, settings);\n case \"lines\":\n return linesSchema(manifest, settings);\n }\n}\n\n/**\n * The component list of the tool guide, one entry per component, in the\n * notation of `settings`. `json-schema` is the list that ships.\n */\nexport function renderGenerativeUIComponentList(\n components: GenerativeUIManifest[\"components\"],\n settings: GenerativeUISchemaSettings,\n): string {\n return Object.entries(components)\n .map(([name, c]) => {\n if (\n settings.notation === \"ts-signature\" ||\n settings.notation === \"lines\"\n ) {\n return signatureLines(name, c, settings).join(\"\\n\");\n }\n const props =\n settings.notation === \"compact\"\n ? compactProps(c.props, settings.propDescriptions)\n : settings.propDescriptions\n ? c.props\n : withoutPropDescriptions(c.props);\n const lines = [\n `- **${name}**${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ` props: ${JSON.stringify(props)}`,\n ];\n if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);\n if (c.slots)\n lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n}\n\n/**\n * The manifest with replaced descriptions: `\"Name\"` replaces the\n * description of a component, `\"Name.prop\"` the description of one of its\n * props. Keys that name no component or prop are left out of the result\n * and listed in `unknown`. The manifest is not changed.\n */\nexport function applyDescriptionOverrides<\n M extends Pick<GenerativeUIManifest, \"components\">,\n>(\n manifest: M,\n overrides: Record<string, string>,\n): { manifest: M; unknown: string[] } {\n const components = structuredClone(manifest.components);\n const unknown: string[] = [];\n for (const [key, description] of Object.entries(overrides)) {\n const [name, prop, ...rest] = key.split(\".\");\n // Own keys only: \"__proto__\" must never reach Object.prototype.\n const component = hasOwn(components, name) ? components[name] : undefined;\n if (!component || rest.length > 0) {\n unknown.push(key);\n continue;\n }\n if (prop === undefined) {\n component.description = description;\n continue;\n }\n const properties = component.props.properties;\n const property =\n isRecord(properties) && hasOwn(properties, prop)\n ? properties[prop]\n : undefined;\n if (!isRecord(property)) {\n unknown.push(key);\n continue;\n }\n property.description = description;\n }\n return { manifest: { ...manifest, components }, unknown };\n}\n\n/**\n * The components and props of `manifest` whose names do not appear in\n * `rendered`. A schema notation that leaves one out would hide part of the\n * catalog from the model.\n */\nexport function schemaCoverage(\n manifest: Pick<GenerativeUIManifest, \"components\">,\n rendered: string,\n): { missing: string[] } {\n const missing: string[] = [];\n for (const [name, component] of Object.entries(manifest.components)) {\n if (!rendered.includes(name)) missing.push(name);\n const properties = isRecord(component.props.properties)\n ? component.props.properties\n : {};\n for (const prop of Object.keys(properties)) {\n if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);\n }\n }\n return { missing };\n}\n"],"mappings":";;;;;;AAoBA,MAAM,UAAU,QAAgB,QAC9B,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;AAEnD,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;AAI7E,SAAS,wBACP,QACwB;AACxB,KAAI,CAAC,SAAS,OAAO,WAAW,CAAE,QAAO;AACzC,QAAO;EACL,GAAG;EACH,YAAY,OAAO,YACjB,OAAO,QAAQ,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,WAAW;AACtD,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AAU,EAAE;EAC1D,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,IAAI;EAE5C,MAAM,YAAY,OAAO,YAAY,KAAK,GAAG,WAAW,QAAQ;AAChE,MAAI,CAAC,aAAa,KAAK,SAAS,GAAG;AACjC,WAAQ,KAAK,IAAI;AACjB;;AAEF,MAAI,SAAS,QAAW;AACtB,aAAU,cAAc;AACxB;;EAEF,MAAM,aAAa,UAAU,MAAM;EACnC,MAAM,WACJ,SAAS,WAAW,IAAI,OAAO,YAAY,KAAK,GAC5C,WAAW,QACX;AACN,MAAI,CAAC,SAAS,SAAS,EAAE;AACvB,WAAQ,KAAK,IAAI;AACjB;;AAEF,WAAS,cAAc;;AAEzB,QAAO;EAAE,UAAU;GAAE,GAAG;GAAU;GAAY;EAAE;EAAS;;;;;;;AAQ3D,SAAgB,eACd,UACA,UACuB;CACvB,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,SAAS,WAAW,EAAE;AACnE,MAAI,CAAC,SAAS,SAAS,KAAK,CAAE,SAAQ,KAAK,KAAK;EAChD,MAAM,aAAa,SAAS,UAAU,MAAM,WAAW,GACnD,UAAU,MAAM,aAChB,EAAE;AACN,OAAK,MAAM,QAAQ,OAAO,KAAK,WAAW,CACxC,KAAI,CAAC,SAAS,SAAS,KAAK,CAAE,SAAQ,KAAK,GAAG,KAAK,GAAG,OAAO;;AAGjE,QAAO,EAAE,SAAS"}
|
|
1
|
+
{"version":3,"file":"schema-render.cjs","names":["compactType","compactProps","functionCallers","GENERATIVE_UI_AGENT_FUNCTION_CALLS","buildCompactGenerativeUISchema"],"sources":["../../src/generative-ui/schema-render.ts"],"sourcesContent":["import { functionCallers } from \"./basic-functions\";\nimport {\n buildCompactGenerativeUISchema,\n compactProps,\n compactType,\n} from \"./compact-schema\";\nimport type { GenerativeUISchemaSettings } from \"./prompt-spec\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type {\n GenerativeUIComponentManifest,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\n\ntype SchemaManifest = Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"components\" | \"functions\" | \"targets\" | \"surfaces\"\n>;\n\n/** An own key (shared compiles to ES2017, which has no Object.hasOwn). */\nconst hasOwn = (target: object, key: string) =>\n Object.prototype.hasOwnProperty.call(target, key);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The props schema without the description of each prop. */\nfunction withoutPropDescriptions(\n schema: GenerativeUIJSONSchema,\n): GenerativeUIJSONSchema {\n if (!isRecord(schema.properties)) return schema;\n return {\n ...schema,\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => {\n if (!isRecord(value)) return [key, value];\n const { description: _description, ...rest } = value;\n return [key, rest];\n }),\n ),\n };\n}\n\n/** The short signature of a function: its built-in signature, or its schema made short. */\nfunction functionSignature(fn: GenerativeUIManifest[\"functions\"][string]) {\n const signature = fn.parameters.description;\n const hasSignature =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(fn.parameters).length === 2;\n return hasSignature ? signature : compactType(fn.parameters, 0);\n}\n\n/**\n * A function name with its parameters: `pick{ id: string }`, `clearCart{}`\n * for no arguments, `setVolume(number)` for a parameter that is not an object.\n */\nfunction nameWithParameters(name: string, parameters: string) {\n if (parameters.startsWith(\"{\")) return `${name}${parameters}`;\n if (parameters === \"object\") return `${name}{}`;\n return `${name}(${parameters})`;\n}\n\n/**\n * One component as a TypeScript-like signature line, with its events and\n * slots on the lines below:\n * `- Text(text?: string // The text): Shows text`.\n */\nfunction signatureLines(\n name: string,\n component: GenerativeUIComponentManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const props = Object.entries(\n compactProps(component.props, settings.propDescriptions),\n ).map(([key, type]) => `${key}: ${type}`);\n const lines = [\n `- ${name}(${props.join(\", \")})${component.description ? `: ${oneLine(component.description)}` : \"\"}`,\n ];\n const events = Object.entries(component.events ?? {}).map(\n ([event, definition]) =>\n `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`,\n );\n if (events.length > 0) lines.push(` events: ${events.join(\", \")}`);\n const slots = Object.entries(component.slots ?? {}).map(\n ([slot, kind]) => `${slot} (${kind})`,\n );\n if (slots.length > 0) lines.push(` slots: ${slots.join(\", \")}`);\n return lines;\n}\n\n/** The whole schema as signature text: targets, functions, components, surfaces. */\nfunction signatureSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const targets = manifest.targets.map((t) => {\n const limit = t.components ? `; only ${t.components.join(\", \")}` : \"\";\n return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n });\n const functions = Object.entries(manifest.functions).map(([name, fn]) => {\n const callers = functionCallers(fn);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`;\n });\n const components = Object.entries(manifest.components).flatMap(\n ([name, component]) => signatureLines(name, component, settings),\n );\n const surfaces = Object.entries(manifest.surfaces).map(\n ([id, s]) =>\n `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : \"\"}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : \"\"}${(s.rejected ?? []).map((r) => ` rejected: ${r}`).join(\"\")}`,\n );\n return [\n `Catalog: ${manifest.catalogId}`,\n `Targets:\\n${targets.join(\"\\n\") || \"- none\"}`,\n `Functions:\\n${functions.join(\"\\n\") || \"- none\"}`,\n `Components:\\n${components.join(\"\\n\") || \"- none\"}`,\n `Surfaces:\\n${surfaces.join(\"\\n\") || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n\n/** A description on one line, so its lines cannot read as new entries. */\nfunction oneLine(text: string) {\n return text.replace(/\\s*\\n\\s*/g, \" \");\n}\n\n/** Values that would read as a type or a number once their quotes are gone. */\nconst AMBIGUOUS_VALUE =\n /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\\d[\\d.]*)$/;\n\n/**\n * A compact type with bare enum values and tight unions:\n * `\"sm\" | \"md\" | \"lg\"` becomes `sm|md|lg`. A union keeps its quotes when it\n * also holds a type (`\"sm\" | number`) or a value that reads as a type or a\n * number (`\"number\" | \"currency\"`, `\"1\" | \"2\"`), and so do values that are\n * not plain words.\n */\nfunction bareType(type: string) {\n return type\n .replace(\n /\"[A-Za-z0-9_#%.-]+\"(?: \\| \"[A-Za-z0-9_#%.-]+\")*(?! \\|)/g,\n (union: string, offset: number, whole: string) => {\n if (whole.slice(offset - 2, offset) === \"| \") return union;\n const values = union.split(\" | \").map((v) => v.slice(1, -1));\n if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;\n return values.join(\"|\");\n },\n )\n .replace(/ \\| /g, \"|\");\n}\n\n/** A compact prop (`type // description`) as `name: type - description`. */\nfunction propLine(key: string, value: string) {\n const name = key.endsWith(\"?\") ? key.slice(0, -1) : `${key}*`;\n const cut = value.indexOf(\" // \");\n const type = bareType(cut < 0 ? value : value.slice(0, cut));\n const text = cut < 0 ? \"\" : value.slice(cut + 4).trim();\n const description = text ? ` - ${oneLine(text)}` : \"\";\n return ` ${name}: ${type}${description}`;\n}\n\n/**\n * The whole schema as plain lines: a header line per component and one\n * indented line per prop: events are `action` props and slots `componentId`\n * or `childList` props. Props are optional unless marked `*`, enum values\n * are bare, and the common props are listed once. It carries the same names, types and descriptions as\n * `compact`, in fewer tokens.\n */\nfunction linesSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const compact = buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n });\n const targets = compact.targets\n .map((t) => {\n const limit = t.components ? `, only ${t.components.join(\", \")}` : \"\";\n return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n })\n .join(\"; \");\n const functions = Object.entries(compact.functions).map(\n ([name, fn]) =>\n `${nameWithParameters(name, fn.parameters)}${\"callers\" in fn ? ` (${fn.callers})` : \"\"}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`,\n );\n const common = compact.commonProps\n ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v))\n : [];\n const lineSets = Object.entries(compact.components).map(([name, c]) => ({\n name,\n c,\n own: [\n ...Object.entries(c.props).map(([k, v]) => propLine(k, v)),\n ...Object.entries(c.events ?? {}).map(\n ([e, d]) => ` ${e}: action - ${oneLine(d)}`,\n ),\n ],\n }));\n const components = lineSets.flatMap(({ name, c, own }) => {\n const lines = [\n `${name}${c.includesCommonProps ? \" +common\" : \"\"}${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ...own,\n ];\n // Slots are props that take component ids.\n for (const [slot, kind] of Object.entries(c.slots ?? {})) {\n lines.push(\n ` ${slot}: ${kind === \"single\" ? \"componentId\" : \"childList\"}`,\n );\n }\n return lines;\n });\n const surfaces = Object.keys(compact.surfaces).length\n ? JSON.stringify(compact.surfaces)\n : \"none\";\n return [\n `Catalog ${compact.catalogId}. Targets: ${targets || \"none\"}`,\n 'Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.',\n `Functions:\\n${functions.join(\"\\n\")}`,\n ...(common.length ? [`Common props:\\n${common.join(\"\\n\")}`] : []),\n `Components:\\n${components.join(\"\\n\")}`,\n `Surfaces: ${surfaces}`,\n ].join(\"\\n\\n\");\n}\n\n/**\n * The component schema of the markdown transport, as the text of its\n * context entry, in the notation of `settings`. `compact` is the schema that\n * ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts\n * as JSON, `ts-signature` one line per component, `lines` one line per\n * prop with bare enums (the fewest tokens).\n *\n * @example\n * ```ts\n * const value = renderGenerativeUISchema(manifest, spec.schema.markdown);\n * ```\n */\nexport function renderGenerativeUISchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n): string {\n switch (settings.notation) {\n case \"compact\":\n return JSON.stringify(\n buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n }),\n );\n case \"json-schema\": {\n const components = Object.fromEntries(\n Object.entries(manifest.components).map(([name, c]) => [\n name,\n settings.propDescriptions\n ? c\n : { ...c, props: withoutPropDescriptions(c.props) },\n ]),\n );\n return JSON.stringify({\n catalogId: manifest.catalogId,\n targets: manifest.targets,\n functions: manifest.functions,\n components,\n surfaces: manifest.surfaces,\n });\n }\n case \"ts-signature\":\n return signatureSchema(manifest, settings);\n case \"lines\":\n return linesSchema(manifest, settings);\n }\n}\n\n/**\n * The component list of the tool guide, one entry per component, in the\n * notation of `settings`. `json-schema` is the list that ships.\n */\nexport function renderGenerativeUIComponentList(\n components: GenerativeUIManifest[\"components\"],\n settings: GenerativeUISchemaSettings,\n): string {\n return Object.entries(components)\n .map(([name, c]) => {\n if (\n settings.notation === \"ts-signature\" ||\n settings.notation === \"lines\"\n ) {\n return signatureLines(name, c, settings).join(\"\\n\");\n }\n const props =\n settings.notation === \"compact\"\n ? compactProps(c.props, settings.propDescriptions)\n : settings.propDescriptions\n ? c.props\n : withoutPropDescriptions(c.props);\n const lines = [\n `- **${name}**${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ` props: ${JSON.stringify(props)}`,\n ];\n if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);\n if (c.slots)\n lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n}\n\n/**\n * The manifest with replaced descriptions: `\"Name\"` replaces the\n * description of a component, `\"Name.prop\"` the description of one of its\n * props. Keys that name no component or prop are left out of the result\n * and listed in `unknown`. The manifest is not changed.\n */\nexport function applyDescriptionOverrides<\n M extends Pick<GenerativeUIManifest, \"components\">,\n>(\n manifest: M,\n overrides: Record<string, string>,\n): { manifest: M; unknown: string[] } {\n const components = structuredClone(manifest.components);\n const unknown: string[] = [];\n for (const [key, description] of Object.entries(overrides)) {\n const [name, prop, ...rest] = key.split(\".\");\n // Own keys only: \"__proto__\" must never reach Object.prototype.\n const component =\n name !== undefined && hasOwn(components, name)\n ? components[name]\n : undefined;\n if (!component || rest.length > 0) {\n unknown.push(key);\n continue;\n }\n if (prop === undefined) {\n component.description = description;\n continue;\n }\n const properties = component.props.properties;\n const property =\n isRecord(properties) && hasOwn(properties, prop)\n ? properties[prop]\n : undefined;\n if (!isRecord(property)) {\n unknown.push(key);\n continue;\n }\n property.description = description;\n }\n return { manifest: { ...manifest, components }, unknown };\n}\n\n/**\n * The components and props of `manifest` whose names do not appear in\n * `rendered`. A schema notation that leaves one out would hide part of the\n * catalog from the model.\n */\nexport function schemaCoverage(\n manifest: Pick<GenerativeUIManifest, \"components\">,\n rendered: string,\n): { missing: string[] } {\n const missing: string[] = [];\n for (const [name, component] of Object.entries(manifest.components)) {\n if (!rendered.includes(name)) missing.push(name);\n const properties = isRecord(component.props.properties)\n ? component.props.properties\n : {};\n for (const prop of Object.keys(properties)) {\n if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);\n }\n }\n return { missing };\n}\n"],"mappings":";;;;;;AAoBA,MAAM,UAAU,QAAgB,QAC9B,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;AAEnD,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;AAI7E,SAAS,wBACP,QACwB;AACxB,KAAI,CAAC,SAAS,OAAO,WAAW,CAAE,QAAO;AACzC,QAAO;EACL,GAAG;EACH,YAAY,OAAO,YACjB,OAAO,QAAQ,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK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QAAA,EAAU,0BAAA;;;;;;;iBAkCI,yBAAA,WACJ,IAAA,CAAK,oBAAA,gBAAA,CAEf,QAAA,EAAU,CAAA,EACV,SAAA,EAAW,MAAA;EACR,QAAA,EAAU,CAAA;EAAG,OAAA;AAAA;;;;;;
|
|
1
|
+
{"version":3,"file":"schema-render.d.cts","names":[],"sources":["../../src/generative-ui/schema-render.ts"],"mappings":";;;;KAcK,cAAA,GAAiB,IAAA,CACpB,oBAAA;;AAHe;;;;;AAuOjB;;;;;;iBAAgB,wBAAA,CACd,QAAA,EAAU,cAAA,EACV,QAAA,EAAU,0BAAA;;;;AAsCZ;iBAAgB,+BAAA,CACd,UAAA,EAAY,oBAAA,gBACZ,QAAA,EAAU,0BAAA;;;;;;;iBAkCI,yBAAA,WACJ,IAAA,CAAK,oBAAA,gBAAA,CAEf,QAAA,EAAU,CAAA,EACV,SAAA,EAAW,MAAA;EACR,QAAA,EAAU,CAAA;EAAG,OAAA;AAAA;;;;;;iBAqCF,cAAA,CACd,QAAA,EAAU,IAAA,CAAK,oBAAA,iBACf,QAAA;EACG,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-render.d.mts","names":[],"sources":["../../src/generative-ui/schema-render.ts"],"mappings":";;;;KAcK,cAAA,GAAiB,IAAA,CACpB,oBAAA;;AAHe;;;;;AAuOjB;;;;;;iBAAgB,wBAAA,CACd,QAAA,EAAU,cAAA,EACV,QAAA,EAAU,0BAAA;;;;AAsCZ;iBAAgB,+BAAA,CACd,UAAA,EAAY,oBAAA,gBACZ,QAAA,EAAU,0BAAA;;;;;;;iBAkCI,yBAAA,WACJ,IAAA,CAAK,oBAAA,gBAAA,CAEf,QAAA,EAAU,CAAA,EACV,SAAA,EAAW,MAAA;EACR,QAAA,EAAU,CAAA;EAAG,OAAA;AAAA;;;;;;
|
|
1
|
+
{"version":3,"file":"schema-render.d.mts","names":[],"sources":["../../src/generative-ui/schema-render.ts"],"mappings":";;;;KAcK,cAAA,GAAiB,IAAA,CACpB,oBAAA;;AAHe;;;;;AAuOjB;;;;;;iBAAgB,wBAAA,CACd,QAAA,EAAU,cAAA,EACV,QAAA,EAAU,0BAAA;;;;AAsCZ;iBAAgB,+BAAA,CACd,UAAA,EAAY,oBAAA,gBACZ,QAAA,EAAU,0BAAA;;;;;;;iBAkCI,yBAAA,WACJ,IAAA,CAAK,oBAAA,gBAAA,CAEf,QAAA,EAAU,CAAA,EACV,SAAA,EAAW,MAAA;EACR,QAAA,EAAU,CAAA;EAAG,OAAA;AAAA;;;;;;iBAqCF,cAAA,CACd,QAAA,EAAU,IAAA,CAAK,oBAAA,iBACf,QAAA;EACG,OAAA;AAAA"}
|
|
@@ -194,7 +194,7 @@ function applyDescriptionOverrides(manifest, overrides) {
|
|
|
194
194
|
const unknown = [];
|
|
195
195
|
for (const [key, description] of Object.entries(overrides)) {
|
|
196
196
|
const [name, prop, ...rest] = key.split(".");
|
|
197
|
-
const component = hasOwn(components, name) ? components[name] : void 0;
|
|
197
|
+
const component = name !== void 0 && hasOwn(components, name) ? components[name] : void 0;
|
|
198
198
|
if (!component || rest.length > 0) {
|
|
199
199
|
unknown.push(key);
|
|
200
200
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-render.mjs","names":[],"sources":["../../src/generative-ui/schema-render.ts"],"sourcesContent":["import { functionCallers } from \"./basic-functions\";\nimport {\n buildCompactGenerativeUISchema,\n compactProps,\n compactType,\n} from \"./compact-schema\";\nimport type { GenerativeUISchemaSettings } from \"./prompt-spec\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type {\n GenerativeUIComponentManifest,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\n\ntype SchemaManifest = Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"components\" | \"functions\" | \"targets\" | \"surfaces\"\n>;\n\n/** An own key (shared compiles to ES2017, which has no Object.hasOwn). */\nconst hasOwn = (target: object, key: string) =>\n Object.prototype.hasOwnProperty.call(target, key);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The props schema without the description of each prop. */\nfunction withoutPropDescriptions(\n schema: GenerativeUIJSONSchema,\n): GenerativeUIJSONSchema {\n if (!isRecord(schema.properties)) return schema;\n return {\n ...schema,\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => {\n if (!isRecord(value)) return [key, value];\n const { description: _description, ...rest } = value;\n return [key, rest];\n }),\n ),\n };\n}\n\n/** The short signature of a function: its built-in signature, or its schema made short. */\nfunction functionSignature(fn: GenerativeUIManifest[\"functions\"][string]) {\n const signature = fn.parameters.description;\n const hasSignature =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(fn.parameters).length === 2;\n return hasSignature ? signature : compactType(fn.parameters, 0);\n}\n\n/**\n * A function name with its parameters: `pick{ id: string }`, `clearCart{}`\n * for no arguments, `setVolume(number)` for a parameter that is not an object.\n */\nfunction nameWithParameters(name: string, parameters: string) {\n if (parameters.startsWith(\"{\")) return `${name}${parameters}`;\n if (parameters === \"object\") return `${name}{}`;\n return `${name}(${parameters})`;\n}\n\n/**\n * One component as a TypeScript-like signature line, with its events and\n * slots on the lines below:\n * `- Text(text?: string // The text): Shows text`.\n */\nfunction signatureLines(\n name: string,\n component: GenerativeUIComponentManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const props = Object.entries(\n compactProps(component.props, settings.propDescriptions),\n ).map(([key, type]) => `${key}: ${type}`);\n const lines = [\n `- ${name}(${props.join(\", \")})${component.description ? `: ${oneLine(component.description)}` : \"\"}`,\n ];\n const events = Object.entries(component.events ?? {}).map(\n ([event, definition]) =>\n `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`,\n );\n if (events.length > 0) lines.push(` events: ${events.join(\", \")}`);\n const slots = Object.entries(component.slots ?? {}).map(\n ([slot, kind]) => `${slot} (${kind})`,\n );\n if (slots.length > 0) lines.push(` slots: ${slots.join(\", \")}`);\n return lines;\n}\n\n/** The whole schema as signature text: targets, functions, components, surfaces. */\nfunction signatureSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const targets = manifest.targets.map((t) => {\n const limit = t.components ? `; only ${t.components.join(\", \")}` : \"\";\n return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n });\n const functions = Object.entries(manifest.functions).map(([name, fn]) => {\n const callers = functionCallers(fn);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`;\n });\n const components = Object.entries(manifest.components).flatMap(\n ([name, component]) => signatureLines(name, component, settings),\n );\n const surfaces = Object.entries(manifest.surfaces).map(\n ([id, s]) =>\n `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : \"\"}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : \"\"}${(s.rejected ?? []).map((r) => ` rejected: ${r}`).join(\"\")}`,\n );\n return [\n `Catalog: ${manifest.catalogId}`,\n `Targets:\\n${targets.join(\"\\n\") || \"- none\"}`,\n `Functions:\\n${functions.join(\"\\n\") || \"- none\"}`,\n `Components:\\n${components.join(\"\\n\") || \"- none\"}`,\n `Surfaces:\\n${surfaces.join(\"\\n\") || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n\n/** A description on one line, so its lines cannot read as new entries. */\nfunction oneLine(text: string) {\n return text.replace(/\\s*\\n\\s*/g, \" \");\n}\n\n/** Values that would read as a type or a number once their quotes are gone. */\nconst AMBIGUOUS_VALUE =\n /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\\d[\\d.]*)$/;\n\n/**\n * A compact type with bare enum values and tight unions:\n * `\"sm\" | \"md\" | \"lg\"` becomes `sm|md|lg`. A union keeps its quotes when it\n * also holds a type (`\"sm\" | number`) or a value that reads as a type or a\n * number (`\"number\" | \"currency\"`, `\"1\" | \"2\"`), and so do values that are\n * not plain words.\n */\nfunction bareType(type: string) {\n return type\n .replace(\n /\"[A-Za-z0-9_#%.-]+\"(?: \\| \"[A-Za-z0-9_#%.-]+\")*(?! \\|)/g,\n (union: string, offset: number, whole: string) => {\n if (whole.slice(offset - 2, offset) === \"| \") return union;\n const values = union.split(\" | \").map((v) => v.slice(1, -1));\n if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;\n return values.join(\"|\");\n },\n )\n .replace(/ \\| /g, \"|\");\n}\n\n/** A compact prop (`type // description`) as `name: type - description`. */\nfunction propLine(key: string, value: string) {\n const name = key.endsWith(\"?\") ? key.slice(0, -1) : `${key}*`;\n const cut = value.indexOf(\" // \");\n const type = bareType(cut < 0 ? value : value.slice(0, cut));\n const text = cut < 0 ? \"\" : value.slice(cut + 4).trim();\n const description = text ? ` - ${oneLine(text)}` : \"\";\n return ` ${name}: ${type}${description}`;\n}\n\n/**\n * The whole schema as plain lines: a header line per component and one\n * indented line per prop: events are `action` props and slots `componentId`\n * or `childList` props. Props are optional unless marked `*`, enum values\n * are bare, and the common props are listed once. It carries the same names, types and descriptions as\n * `compact`, in fewer tokens.\n */\nfunction linesSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const compact = buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n });\n const targets = compact.targets\n .map((t) => {\n const limit = t.components ? `, only ${t.components.join(\", \")}` : \"\";\n return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n })\n .join(\"; \");\n const functions = Object.entries(compact.functions).map(\n ([name, fn]) =>\n `${nameWithParameters(name, fn.parameters)}${\"callers\" in fn ? ` (${fn.callers})` : \"\"}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`,\n );\n const common = compact.commonProps\n ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v))\n : [];\n const lineSets = Object.entries(compact.components).map(([name, c]) => ({\n name,\n c,\n own: [\n ...Object.entries(c.props).map(([k, v]) => propLine(k, v)),\n ...Object.entries(c.events ?? {}).map(\n ([e, d]) => ` ${e}: action - ${oneLine(d)}`,\n ),\n ],\n }));\n const components = lineSets.flatMap(({ name, c, own }) => {\n const lines = [\n `${name}${c.includesCommonProps ? \" +common\" : \"\"}${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ...own,\n ];\n // Slots are props that take component ids.\n for (const [slot, kind] of Object.entries(c.slots ?? {})) {\n lines.push(\n ` ${slot}: ${kind === \"single\" ? \"componentId\" : \"childList\"}`,\n );\n }\n return lines;\n });\n const surfaces = Object.keys(compact.surfaces).length\n ? JSON.stringify(compact.surfaces)\n : \"none\";\n return [\n `Catalog ${compact.catalogId}. Targets: ${targets || \"none\"}`,\n 'Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.',\n `Functions:\\n${functions.join(\"\\n\")}`,\n ...(common.length ? [`Common props:\\n${common.join(\"\\n\")}`] : []),\n `Components:\\n${components.join(\"\\n\")}`,\n `Surfaces: ${surfaces}`,\n ].join(\"\\n\\n\");\n}\n\n/**\n * The component schema of the markdown transport, as the text of its\n * context entry, in the notation of `settings`. `compact` is the schema that\n * ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts\n * as JSON, `ts-signature` one line per component, `lines` one line per\n * prop with bare enums (the fewest tokens).\n *\n * @example\n * ```ts\n * const value = renderGenerativeUISchema(manifest, spec.schema.markdown);\n * ```\n */\nexport function renderGenerativeUISchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n): string {\n switch (settings.notation) {\n case \"compact\":\n return JSON.stringify(\n buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n }),\n );\n case \"json-schema\": {\n const components = Object.fromEntries(\n Object.entries(manifest.components).map(([name, c]) => [\n name,\n settings.propDescriptions\n ? c\n : { ...c, props: withoutPropDescriptions(c.props) },\n ]),\n );\n return JSON.stringify({\n catalogId: manifest.catalogId,\n targets: manifest.targets,\n functions: manifest.functions,\n components,\n surfaces: manifest.surfaces,\n });\n }\n case \"ts-signature\":\n return signatureSchema(manifest, settings);\n case \"lines\":\n return linesSchema(manifest, settings);\n }\n}\n\n/**\n * The component list of the tool guide, one entry per component, in the\n * notation of `settings`. `json-schema` is the list that ships.\n */\nexport function renderGenerativeUIComponentList(\n components: GenerativeUIManifest[\"components\"],\n settings: GenerativeUISchemaSettings,\n): string {\n return Object.entries(components)\n .map(([name, c]) => {\n if (\n settings.notation === \"ts-signature\" ||\n settings.notation === \"lines\"\n ) {\n return signatureLines(name, c, settings).join(\"\\n\");\n }\n const props =\n settings.notation === \"compact\"\n ? compactProps(c.props, settings.propDescriptions)\n : settings.propDescriptions\n ? c.props\n : withoutPropDescriptions(c.props);\n const lines = [\n `- **${name}**${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ` props: ${JSON.stringify(props)}`,\n ];\n if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);\n if (c.slots)\n lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n}\n\n/**\n * The manifest with replaced descriptions: `\"Name\"` replaces the\n * description of a component, `\"Name.prop\"` the description of one of its\n * props. Keys that name no component or prop are left out of the result\n * and listed in `unknown`. The manifest is not changed.\n */\nexport function applyDescriptionOverrides<\n M extends Pick<GenerativeUIManifest, \"components\">,\n>(\n manifest: M,\n overrides: Record<string, string>,\n): { manifest: M; unknown: string[] } {\n const components = structuredClone(manifest.components);\n const unknown: string[] = [];\n for (const [key, description] of Object.entries(overrides)) {\n const [name, prop, ...rest] = key.split(\".\");\n // Own keys only: \"__proto__\" must never reach Object.prototype.\n const component = hasOwn(components, name) ? components[name] : undefined;\n if (!component || rest.length > 0) {\n unknown.push(key);\n continue;\n }\n if (prop === undefined) {\n component.description = description;\n continue;\n }\n const properties = component.props.properties;\n const property =\n isRecord(properties) && hasOwn(properties, prop)\n ? properties[prop]\n : undefined;\n if (!isRecord(property)) {\n unknown.push(key);\n continue;\n }\n property.description = description;\n }\n return { manifest: { ...manifest, components }, unknown };\n}\n\n/**\n * The components and props of `manifest` whose names do not appear in\n * `rendered`. A schema notation that leaves one out would hide part of the\n * catalog from the model.\n */\nexport function schemaCoverage(\n manifest: Pick<GenerativeUIManifest, \"components\">,\n rendered: string,\n): { missing: string[] } {\n const missing: string[] = [];\n for (const [name, component] of Object.entries(manifest.components)) {\n if (!rendered.includes(name)) missing.push(name);\n const properties = isRecord(component.props.properties)\n ? component.props.properties\n : {};\n for (const prop of Object.keys(properties)) {\n if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);\n }\n }\n return { missing };\n}\n"],"mappings":";;;;;;AAoBA,MAAM,UAAU,QAAgB,QAC9B,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;AAEnD,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;AAI7E,SAAS,wBACP,QACwB;AACxB,KAAI,CAAC,SAAS,OAAO,WAAW,CAAE,QAAO;AACzC,QAAO;EACL,GAAG;EACH,YAAY,OAAO,YACjB,OAAO,QAAQ,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,WAAW;AACtD,OAAI,CAAC,SAAS,MAAM,CAAE,QAAO,CAAC,KAAK,MAAM;GACzC,MAAM,EAAE,aAAa,cAAc,GAAG,SAAS;AAC/C,UAAO,CAAC,KAAK,KAAK;IAClB,CACH;EACF;;;AAIH,SAAS,kBAAkB,IAA+C;CACxE,MAAM,YAAY,GAAG,WAAW;AAKhC,QAHE,OAAO,cAA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,cAAc;AACxB;;EAEF,MAAM,aAAa,UAAU,MAAM;EACnC,MAAM,WACJ,SAAS,WAAW,IAAI,OAAO,YAAY,KAAK,GAC5C,WAAW,QACX;AACN,MAAI,CAAC,SAAS,SAAS,EAAE;AACvB,WAAQ,KAAK,IAAI;AACjB;;AAEF,WAAS,cAAc;;AAEzB,QAAO;EAAE,UAAU;GAAE,GAAG;GAAU;GAAY;EAAE;EAAS;;;;;;;AAQ3D,SAAgB,eACd,UACA,UACuB;CACvB,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,SAAS,WAAW,EAAE;AACnE,MAAI,CAAC,SAAS,SAAS,KAAK,CAAE,SAAQ,KAAK,KAAK;EAChD,MAAM,aAAa,SAAS,UAAU,MAAM,WAAW,GACnD,UAAU,MAAM,aAChB,EAAE;AACN,OAAK,MAAM,QAAQ,OAAO,KAAK,WAAW,CACxC,KAAI,CAAC,SAAS,SAAS,KAAK,CAAE,SAAQ,KAAK,GAAG,KAAK,GAAG,OAAO;;AAGjE,QAAO,EAAE,SAAS"}
|
|
1
|
+
{"version":3,"file":"schema-render.mjs","names":[],"sources":["../../src/generative-ui/schema-render.ts"],"sourcesContent":["import { functionCallers } from \"./basic-functions\";\nimport {\n buildCompactGenerativeUISchema,\n compactProps,\n compactType,\n} from \"./compact-schema\";\nimport type { GenerativeUISchemaSettings } from \"./prompt-spec\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type {\n GenerativeUIComponentManifest,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\n\ntype SchemaManifest = Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"components\" | \"functions\" | \"targets\" | \"surfaces\"\n>;\n\n/** An own key (shared compiles to ES2017, which has no Object.hasOwn). */\nconst hasOwn = (target: object, key: string) =>\n Object.prototype.hasOwnProperty.call(target, key);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The props schema without the description of each prop. */\nfunction withoutPropDescriptions(\n schema: GenerativeUIJSONSchema,\n): GenerativeUIJSONSchema {\n if (!isRecord(schema.properties)) return schema;\n return {\n ...schema,\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => {\n if (!isRecord(value)) return [key, value];\n const { description: _description, ...rest } = value;\n return [key, rest];\n }),\n ),\n };\n}\n\n/** The short signature of a function: its built-in signature, or its schema made short. */\nfunction functionSignature(fn: GenerativeUIManifest[\"functions\"][string]) {\n const signature = fn.parameters.description;\n const hasSignature =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(fn.parameters).length === 2;\n return hasSignature ? signature : compactType(fn.parameters, 0);\n}\n\n/**\n * A function name with its parameters: `pick{ id: string }`, `clearCart{}`\n * for no arguments, `setVolume(number)` for a parameter that is not an object.\n */\nfunction nameWithParameters(name: string, parameters: string) {\n if (parameters.startsWith(\"{\")) return `${name}${parameters}`;\n if (parameters === \"object\") return `${name}{}`;\n return `${name}(${parameters})`;\n}\n\n/**\n * One component as a TypeScript-like signature line, with its events and\n * slots on the lines below:\n * `- Text(text?: string // The text): Shows text`.\n */\nfunction signatureLines(\n name: string,\n component: GenerativeUIComponentManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const props = Object.entries(\n compactProps(component.props, settings.propDescriptions),\n ).map(([key, type]) => `${key}: ${type}`);\n const lines = [\n `- ${name}(${props.join(\", \")})${component.description ? `: ${oneLine(component.description)}` : \"\"}`,\n ];\n const events = Object.entries(component.events ?? {}).map(\n ([event, definition]) =>\n `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`,\n );\n if (events.length > 0) lines.push(` events: ${events.join(\", \")}`);\n const slots = Object.entries(component.slots ?? {}).map(\n ([slot, kind]) => `${slot} (${kind})`,\n );\n if (slots.length > 0) lines.push(` slots: ${slots.join(\", \")}`);\n return lines;\n}\n\n/** The whole schema as signature text: targets, functions, components, surfaces. */\nfunction signatureSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const targets = manifest.targets.map((t) => {\n const limit = t.components ? `; only ${t.components.join(\", \")}` : \"\";\n return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n });\n const functions = Object.entries(manifest.functions).map(([name, fn]) => {\n const callers = functionCallers(fn);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`;\n });\n const components = Object.entries(manifest.components).flatMap(\n ([name, component]) => signatureLines(name, component, settings),\n );\n const surfaces = Object.entries(manifest.surfaces).map(\n ([id, s]) =>\n `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : \"\"}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : \"\"}${(s.rejected ?? []).map((r) => ` rejected: ${r}`).join(\"\")}`,\n );\n return [\n `Catalog: ${manifest.catalogId}`,\n `Targets:\\n${targets.join(\"\\n\") || \"- none\"}`,\n `Functions:\\n${functions.join(\"\\n\") || \"- none\"}`,\n `Components:\\n${components.join(\"\\n\") || \"- none\"}`,\n `Surfaces:\\n${surfaces.join(\"\\n\") || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n\n/** A description on one line, so its lines cannot read as new entries. */\nfunction oneLine(text: string) {\n return text.replace(/\\s*\\n\\s*/g, \" \");\n}\n\n/** Values that would read as a type or a number once their quotes are gone. */\nconst AMBIGUOUS_VALUE =\n /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\\d[\\d.]*)$/;\n\n/**\n * A compact type with bare enum values and tight unions:\n * `\"sm\" | \"md\" | \"lg\"` becomes `sm|md|lg`. A union keeps its quotes when it\n * also holds a type (`\"sm\" | number`) or a value that reads as a type or a\n * number (`\"number\" | \"currency\"`, `\"1\" | \"2\"`), and so do values that are\n * not plain words.\n */\nfunction bareType(type: string) {\n return type\n .replace(\n /\"[A-Za-z0-9_#%.-]+\"(?: \\| \"[A-Za-z0-9_#%.-]+\")*(?! \\|)/g,\n (union: string, offset: number, whole: string) => {\n if (whole.slice(offset - 2, offset) === \"| \") return union;\n const values = union.split(\" | \").map((v) => v.slice(1, -1));\n if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;\n return values.join(\"|\");\n },\n )\n .replace(/ \\| /g, \"|\");\n}\n\n/** A compact prop (`type // description`) as `name: type - description`. */\nfunction propLine(key: string, value: string) {\n const name = key.endsWith(\"?\") ? key.slice(0, -1) : `${key}*`;\n const cut = value.indexOf(\" // \");\n const type = bareType(cut < 0 ? value : value.slice(0, cut));\n const text = cut < 0 ? \"\" : value.slice(cut + 4).trim();\n const description = text ? ` - ${oneLine(text)}` : \"\";\n return ` ${name}: ${type}${description}`;\n}\n\n/**\n * The whole schema as plain lines: a header line per component and one\n * indented line per prop: events are `action` props and slots `componentId`\n * or `childList` props. Props are optional unless marked `*`, enum values\n * are bare, and the common props are listed once. It carries the same names, types and descriptions as\n * `compact`, in fewer tokens.\n */\nfunction linesSchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n) {\n const compact = buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n });\n const targets = compact.targets\n .map((t) => {\n const limit = t.components ? `, only ${t.components.join(\", \")}` : \"\";\n return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : \"\"}`;\n })\n .join(\"; \");\n const functions = Object.entries(compact.functions).map(\n ([name, fn]) =>\n `${nameWithParameters(name, fn.parameters)}${\"callers\" in fn ? ` (${fn.callers})` : \"\"}${fn.description ? `: ${oneLine(fn.description)}` : \"\"}`,\n );\n const common = compact.commonProps\n ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v))\n : [];\n const lineSets = Object.entries(compact.components).map(([name, c]) => ({\n name,\n c,\n own: [\n ...Object.entries(c.props).map(([k, v]) => propLine(k, v)),\n ...Object.entries(c.events ?? {}).map(\n ([e, d]) => ` ${e}: action - ${oneLine(d)}`,\n ),\n ],\n }));\n const components = lineSets.flatMap(({ name, c, own }) => {\n const lines = [\n `${name}${c.includesCommonProps ? \" +common\" : \"\"}${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ...own,\n ];\n // Slots are props that take component ids.\n for (const [slot, kind] of Object.entries(c.slots ?? {})) {\n lines.push(\n ` ${slot}: ${kind === \"single\" ? \"componentId\" : \"childList\"}`,\n );\n }\n return lines;\n });\n const surfaces = Object.keys(compact.surfaces).length\n ? JSON.stringify(compact.surfaces)\n : \"none\";\n return [\n `Catalog ${compact.catalogId}. Targets: ${targets || \"none\"}`,\n 'Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.',\n `Functions:\\n${functions.join(\"\\n\")}`,\n ...(common.length ? [`Common props:\\n${common.join(\"\\n\")}`] : []),\n `Components:\\n${components.join(\"\\n\")}`,\n `Surfaces: ${surfaces}`,\n ].join(\"\\n\\n\");\n}\n\n/**\n * The component schema of the markdown transport, as the text of its\n * context entry, in the notation of `settings`. `compact` is the schema that\n * ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts\n * as JSON, `ts-signature` one line per component, `lines` one line per\n * prop with bare enums (the fewest tokens).\n *\n * @example\n * ```ts\n * const value = renderGenerativeUISchema(manifest, spec.schema.markdown);\n * ```\n */\nexport function renderGenerativeUISchema(\n manifest: SchemaManifest,\n settings: GenerativeUISchemaSettings,\n): string {\n switch (settings.notation) {\n case \"compact\":\n return JSON.stringify(\n buildCompactGenerativeUISchema(manifest, {\n propDescriptions: settings.propDescriptions,\n commonProps: settings.commonProps,\n }),\n );\n case \"json-schema\": {\n const components = Object.fromEntries(\n Object.entries(manifest.components).map(([name, c]) => [\n name,\n settings.propDescriptions\n ? c\n : { ...c, props: withoutPropDescriptions(c.props) },\n ]),\n );\n return JSON.stringify({\n catalogId: manifest.catalogId,\n targets: manifest.targets,\n functions: manifest.functions,\n components,\n surfaces: manifest.surfaces,\n });\n }\n case \"ts-signature\":\n return signatureSchema(manifest, settings);\n case \"lines\":\n return linesSchema(manifest, settings);\n }\n}\n\n/**\n * The component list of the tool guide, one entry per component, in the\n * notation of `settings`. `json-schema` is the list that ships.\n */\nexport function renderGenerativeUIComponentList(\n components: GenerativeUIManifest[\"components\"],\n settings: GenerativeUISchemaSettings,\n): string {\n return Object.entries(components)\n .map(([name, c]) => {\n if (\n settings.notation === \"ts-signature\" ||\n settings.notation === \"lines\"\n ) {\n return signatureLines(name, c, settings).join(\"\\n\");\n }\n const props =\n settings.notation === \"compact\"\n ? compactProps(c.props, settings.propDescriptions)\n : settings.propDescriptions\n ? c.props\n : withoutPropDescriptions(c.props);\n const lines = [\n `- **${name}**${c.description ? `: ${oneLine(c.description)}` : \"\"}`,\n ` props: ${JSON.stringify(props)}`,\n ];\n if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);\n if (c.slots)\n lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n}\n\n/**\n * The manifest with replaced descriptions: `\"Name\"` replaces the\n * description of a component, `\"Name.prop\"` the description of one of its\n * props. Keys that name no component or prop are left out of the result\n * and listed in `unknown`. The manifest is not changed.\n */\nexport function applyDescriptionOverrides<\n M extends Pick<GenerativeUIManifest, \"components\">,\n>(\n manifest: M,\n overrides: Record<string, string>,\n): { manifest: M; unknown: string[] } {\n const components = structuredClone(manifest.components);\n const unknown: string[] = [];\n for (const [key, description] of Object.entries(overrides)) {\n const [name, prop, ...rest] = key.split(\".\");\n // Own keys only: \"__proto__\" must never reach Object.prototype.\n const component =\n name !== undefined && hasOwn(components, name)\n ? components[name]\n : undefined;\n if (!component || rest.length > 0) {\n unknown.push(key);\n continue;\n }\n if (prop === undefined) {\n component.description = description;\n continue;\n }\n const properties = component.props.properties;\n const property =\n isRecord(properties) && hasOwn(properties, prop)\n ? properties[prop]\n : undefined;\n if (!isRecord(property)) {\n unknown.push(key);\n continue;\n }\n property.description = description;\n }\n return { manifest: { ...manifest, components }, unknown };\n}\n\n/**\n * The components and props of `manifest` whose names do not appear in\n * `rendered`. A schema notation that leaves one out would hide part of the\n * catalog from the model.\n */\nexport function schemaCoverage(\n manifest: Pick<GenerativeUIManifest, \"components\">,\n rendered: string,\n): { missing: string[] } {\n const missing: string[] = [];\n for (const [name, component] of Object.entries(manifest.components)) {\n if (!rendered.includes(name)) missing.push(name);\n const properties = isRecord(component.props.properties)\n ? component.props.properties\n : {};\n for (const prop of Object.keys(properties)) {\n if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);\n }\n }\n return { missing };\n}\n"],"mappings":";;;;;;AAoBA,MAAM,UAAU,QAAgB,QAC9B,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;AAEnD,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;AAI7E,SAAS,wBACP,QACwB;AACxB,KAAI,CAAC,SAAS,OAAO,WAAW,CAAE,QAAO;AACzC,QAAO;EACL,GAAG;EACH,YAAY,OAAO,YACjB,OAAO,QAAQ,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,WAAW;AACtD,OAAI,CAAC,SAAS,MAAM,CAAE,QAAO,CAAC,KAAK,MAAM;GACzC,MAAM,EAAE,aAAa,cAAc,GAAG,SAAS;AAC/C,UAAO,CAAC,KAAK,KAAK;IAClB,CACH;EACF;;;AAIH,SAAS,kBAAkB,IAA+C;CACxE,MAAM,YAAY,GAAG,WAAW;AAKhC,QAHE,OAAO,cAAc,YACrB,UAAU,WAAW,IAAI,IACzB,OAAO,KAAK,GAAG,WAAW,CAAC,WAAW,I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,SAAS,WAAW,IAAI,OAAO,YAAY,KAAK,GAC5C,WAAW,QACX;AACN,MAAI,CAAC,SAAS,SAAS,EAAE;AACvB,WAAQ,KAAK,IAAI;AACjB;;AAEF,WAAS,cAAc;;AAEzB,QAAO;EAAE,UAAU;GAAE,GAAG;GAAU;GAAY;EAAE;EAAS;;;;;;;AAQ3D,SAAgB,eACd,UACA,UACuB;CACvB,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,SAAS,WAAW,EAAE;AACnE,MAAI,CAAC,SAAS,SAAS,KAAK,CAAE,SAAQ,KAAK,KAAK;EAChD,MAAM,aAAa,SAAS,UAAU,MAAM,WAAW,GACnD,UAAU,MAAM,aAChB,EAAE;AACN,OAAK,MAAM,QAAQ,OAAO,KAAK,WAAW,CACxC,KAAI,CAAC,SAAS,SAAS,KAAK,CAAE,SAAQ,KAAK,GAAG,KAAK,GAAG,OAAO;;AAGjE,QAAO,EAAE,SAAS"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/generative-ui/types.ts
|
|
3
3
|
/** A2UI protocol version used on the wire. */
|
|
4
|
-
const A2UI_VERSION = "
|
|
4
|
+
const A2UI_VERSION = "1.0";
|
|
5
5
|
/** Activity type of a generated surface message. */
|
|
6
6
|
const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
7
7
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -65,7 +65,7 @@ const GENERATIVE_UI_MAX_REJECTION_LENGTH = 500;
|
|
|
65
65
|
* @example
|
|
66
66
|
* ```ts
|
|
67
67
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
68
|
-
* // { version: "
|
|
68
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
function toA2UIActionMessage(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/generative-ui/types.ts"],"sourcesContent":["/** A2UI protocol version used on the wire. */\nexport const A2UI_VERSION = \"v1.0\";\n/** Activity type of a generated surface message. */\nexport const GENERATIVE_UI_ACTIVITY_TYPE = \"generative-ui-surface\";\n/** Activity type of a function call that the agent asks the client to run. */\nexport const GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE =\n \"generative-ui-function-call\";\n/** Tool the model calls to render or update surfaces. */\nexport const GENERATIVE_UI_RENDER_TOOL = \"render_ui\";\n/** Target id of the chat transcript. */\nexport const GENERATIVE_UI_CHAT_TARGET = \"chat\";\n/** Component id every surface renders from. */\nexport const GENERATIVE_UI_ROOT_ID = \"root\";\n/**\n * Whether the agent may call renderer functions with `callRendererFunction`.\n * Off for now: the result goes back as a developer message, and not every\n * backend keeps that message where the model reads it in order. While off,\n * the prompts do not mention the operation, the validator rejects it, and\n * the dispatcher refuses the agent, whatever a declaration's\n * `allowedCallers` says. The code and its tests stay for when it is on.\n */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS = false;\n/** The reason an agent function call is rejected while they are off. */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON =\n \"callRendererFunction is not supported in this version: the agent cannot call renderer functions until their results can be sent back to it reliably\";\n\n/** Activity message id of a surface. One message per surface. */\nexport function generativeUISurfaceMessageId(surfaceId: string) {\n return `genui:${surfaceId}`;\n}\n\n/**\n * Activity message id of an agent-called function. One message per\n * `functionCallId`.\n *\n * @param functionCallId - The `functionCallId` of the `callRendererFunction` operation.\n *\n * @example\n * ```ts\n * generativeUIFunctionCallMessageId(\"f1\"); // \"genui-fn:f1\"\n * ```\n */\nexport function generativeUIFunctionCallMessageId(functionCallId: string) {\n return `genui-fn:${functionCallId}`;\n}\n\nimport type {\n A2UIFunctionPermissions,\n A2UIFunctionReturnType,\n} from \"./basic-functions\";\n\n// Named `GenerativeUIJSONSchema` because the package root already exports a\n// `JSONSchema` (utils/json-schema.ts); the bare name would collide.\nexport type GenerativeUIJSONSchema = Record<string, unknown>;\n\nexport type A2UIComponentNode = {\n id: string;\n component: string;\n [prop: string]: unknown;\n};\n\n/**\n * The keys of the A2UI 1.0 component envelope next to `id` and\n * `component`: `catalogId`, `accessibility` and `metadata`. They are not\n * props of the component. The renderer reads `accessibility` and ignores\n * the other two.\n */\nexport const A2UI_COMPONENT_ENVELOPE_KEYS: ReadonlySet<string> = new Set([\n \"catalogId\",\n \"accessibility\",\n \"metadata\",\n]);\n\n/**\n * A call of a named function: `{ \"@call\": \"addToCart\", \"args\": { ... } }`.\n * Without `catalogId`, the function comes from the catalog of the run.\n */\nexport type A2UIFunctionCall = {\n \"@call\": string;\n args?: Record<string, unknown>;\n catalogId?: string;\n};\n\nexport type A2UIOperation =\n | {\n version: \"v1.0\";\n createSurface: {\n surfaceId: string;\n /** Left out by the model. The run's catalog id is filled in. */\n catalogId?: string;\n /** Components to add at once, checked like `updateComponents`. */\n components?: A2UIComponentNode[];\n /** The initial root data model. */\n dataModel?: Record<string, unknown>;\n sendDataModel?: boolean;\n metadata?: { extensions?: Record<string, unknown> };\n };\n }\n | {\n version: \"v1.0\";\n updateComponents: { surfaceId: string; components: A2UIComponentNode[] };\n }\n | {\n version: \"v1.0\";\n /**\n * Sets `value` at `path`. A `null` value deletes the key at `path`.\n * With no `path`, or `\"/\"`, it sets the whole data model.\n */\n updateDataModel: { surfaceId: string; path?: string; value: unknown };\n }\n | { version: \"v1.0\"; deleteSurface: { surfaceId: string } }\n | {\n version: \"v1.0\";\n /** Runs an app function in the browser, with no user interaction. */\n callRendererFunction: {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n };\n };\n\n/** Value of an event prop: run a host function, or report the event to the agent. */\nexport type GenerativeUIActionBinding =\n | {\n event: {\n name: string;\n /**\n * First line of the user message that the event becomes: text, a\n * data binding, or a function value such as formatString.\n */\n userMessage?: string | { \"@path\": string } | A2UIFunctionCall;\n context?: Record<string, unknown>;\n };\n }\n | { functionCall: A2UIFunctionCall };\n\nexport type GenerativeUISurfaceStatus = \"streaming\" | \"ready\" | \"error\";\n\nexport interface GenerativeUIRejectedOperation {\n /** Position of the operation in the render_ui call, or in the content list. */\n index: number;\n reason: string;\n}\n\n/** Content of a `generative-ui-surface` activity message. */\nexport interface GenerativeUISurfaceContent {\n surfaceId: string;\n target: string;\n catalogId: string;\n /** Committed (validated) operations, cumulative. */\n operations: A2UIOperation[];\n status: GenerativeUISurfaceStatus;\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/** Content of a `generative-ui-function-call` activity message. */\nexport interface GenerativeUIFunctionCallContent {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n}\n\n/**\n * Value of a \"multiple\" slot that repeats one component for each item of the\n * list at `path`. Paths inside the repeated component are relative to the item.\n */\nexport type GenerativeUITemplateChildren = {\n componentId: string;\n path: string;\n};\n\nexport interface GenerativeUIComponentManifest {\n /** CopilotKit positional order across model-visible props, slots and events.\n * Exporters encode this as JSON Schema property order; it is not an A2UI keyword. */\n parameterOrder?: readonly string[];\n description?: string;\n props: GenerativeUIJSONSchema;\n events?: Record<\n string,\n { description?: string; parameters: GenerativeUIJSONSchema }\n >;\n /**\n * Props that hold child components. A \"single\" slot takes one component id.\n * A \"multiple\" slot takes a `string[]` of component ids, or a\n * {@link GenerativeUITemplateChildren} template.\n */\n slots?: Record<string, \"single\" | \"multiple\">;\n}\n\nexport interface GenerativeUIFunctionManifest extends A2UIFunctionPermissions {\n description?: string;\n parameters: GenerativeUIJSONSchema;\n /** What the function gives back, as A2UI 1.0 names it. */\n returnType?: A2UIFunctionReturnType;\n}\n\n/** Serializable description of what the browser can render and call. */\nexport interface GenerativeUIManifest {\n /** The catalog of the run. A surface with no `catalogId` gets this one. */\n catalogId: string;\n /**\n * Every catalog that a `catalogId` can name: `catalogId` first, then the\n * catalogs of `extends`. Left out, only `catalogId`.\n */\n catalogIds?: string[];\n components: Record<string, GenerativeUIComponentManifest>;\n functions: Record<string, GenerativeUIFunctionManifest>;\n /**\n * Places where the model can render surfaces. Only mounted targets are\n * listed. `description` tells the model where the target is on the page\n * and what to put in it.\n */\n targets: GenerativeUITarget[];\n /** Surfaces the client already holds for the current thread. */\n surfaces: Record<string, GenerativeUISurfaceSummary>;\n}\n\n/** A place where the model can render surfaces. */\nexport interface GenerativeUITarget {\n id: string;\n kind: \"chat\" | \"inline\";\n description?: string;\n /**\n * The only components that the surfaces of this target can use, at most\n * {@link GENERATIVE_UI_MAX_TARGET_COMPONENTS} names. Left out, the target\n * takes every component of the catalog.\n */\n components?: string[];\n}\n\n/** Most component names that one target can list. */\nexport const GENERATIVE_UI_MAX_TARGET_COMPONENTS = 100;\n\n/** Most rejections that a surface summary lists. */\nexport const GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = 20;\n/** Most characters of one rejection in a surface summary. */\nexport const GENERATIVE_UI_MAX_REJECTION_LENGTH = 500;\n\n/** One surface that the client holds, as the model sees it. */\nexport interface GenerativeUISurfaceSummary {\n target: string;\n /** The values that the user set, by path. Left out when there are none. */\n dataModel?: Record<string, unknown>;\n /**\n * Operations that the client dropped, as `\"operation <index>: <reason>\"`.\n * At most {@link GENERATIVE_UI_MAX_SUMMARY_REJECTIONS} entries of at most\n * {@link GENERATIVE_UI_MAX_REJECTION_LENGTH} characters. Left out when\n * there are none.\n */\n rejected?: string[];\n /**\n * Left out while the surface exists. `\"deleted\"`: a deleteSurface removed\n * it, and its id cannot be used again. `\"failed\"`: its createSurface was\n * rejected, so it does not exist; a corrected createSurface can use the id.\n */\n status?: \"deleted\" | \"failed\";\n}\n\n/** A user interaction bound to `{ event }`, sent to the agent. */\nexport interface GenerativeUIUserEvent {\n name: string;\n surfaceId: string;\n componentId: string;\n context: Record<string, unknown>;\n /** The resolved `event.userMessage`: the first line of the user message. */\n userMessage?: string;\n /** When the user acted, as an ISO 8601 string. Filled in when left out. */\n timestamp?: string;\n}\n\n/**\n * The A2UI 1.0 action message of a user event: what a renderer sends to the\n * agent when the user triggers an `{ event }` action. The run that the\n * event starts carries it in the envelope (`copilotkit_action`), next to\n * the visible user message.\n */\nexport interface A2UIActionMessage {\n version: typeof A2UI_VERSION;\n action: {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n /** ISO 8601. */\n timestamp: string;\n userMessage?: string;\n context: Record<string, unknown>;\n };\n}\n\n/**\n * The action message of a user event, with the A2UI field names. Takes the\n * time of the call when the event has no timestamp.\n *\n * @example\n * ```ts\n * toA2UIActionMessage({ name: \"buy\", surfaceId: \"s1\", componentId: \"b\", context: { sku: \"a\" } });\n * // { version: \"v1.0\", action: { name: \"buy\", surfaceId: \"s1\", sourceComponentId: \"b\", timestamp: \"2026-…\", context: { sku: \"a\" } } }\n * ```\n */\nexport function toA2UIActionMessage(\n event: GenerativeUIUserEvent,\n): A2UIActionMessage {\n return {\n version: A2UI_VERSION,\n action: {\n name: event.name,\n surfaceId: event.surfaceId,\n sourceComponentId: event.componentId,\n timestamp: event.timestamp ?? new Date().toISOString(),\n ...(event.userMessage === undefined\n ? {}\n : { userMessage: event.userMessage }),\n context: event.context,\n },\n };\n}\n"],"mappings":";;;AACA,MAAa,eAAe;;AAE5B,MAAa,8BAA8B;;AAE3C,MAAa,4CACX;;AAEF,MAAa,4BAA4B;;AAEzC,MAAa,4BAA4B;;AAEzC,MAAa,wBAAwB;;;;;;;;;AASrC,MAAa,qCAAqC;;AAElD,MAAa,gDACX;;AAGF,SAAgB,6BAA6B,WAAmB;AAC9D,QAAO,SAAS;;;;;;;;;;;;;AAclB,SAAgB,kCAAkC,gBAAwB;AACxE,QAAO,YAAY;;;;;;;;AAwBrB,MAAa,+BAAoD,IAAI,IAAI;CACvE;CACA;CACA;CACD,CAAC;;AA8JF,MAAa,sCAAsC;;AAGnD,MAAa,uCAAuC;;AAEpD,MAAa,qCAAqC;;;;;;;;;;;AA+DlD,SAAgB,oBACd,OACmB;AACnB,QAAO;EACL,SAAS;EACT,QAAQ;GACN,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,mBAAmB,MAAM;GACzB,WAAW,MAAM,8BAAa,IAAI,MAAM,EAAC,aAAa;GACtD,GAAI,MAAM,gBAAgB,SACtB,EAAE,GACF,EAAE,aAAa,MAAM,aAAa;GACtC,SAAS,MAAM;GAChB;EACF"}
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/generative-ui/types.ts"],"sourcesContent":["/** A2UI protocol version used on the wire. */\nexport const A2UI_VERSION = \"1.0\";\n/** Activity type of a generated surface message. */\nexport const GENERATIVE_UI_ACTIVITY_TYPE = \"generative-ui-surface\";\n/** Activity type of a function call that the agent asks the client to run. */\nexport const GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE =\n \"generative-ui-function-call\";\n/** Tool the model calls to render or update surfaces. */\nexport const GENERATIVE_UI_RENDER_TOOL = \"render_ui\";\n/** Target id of the chat transcript. */\nexport const GENERATIVE_UI_CHAT_TARGET = \"chat\";\n/** Component id every surface renders from. */\nexport const GENERATIVE_UI_ROOT_ID = \"root\";\n/**\n * Whether the agent may call renderer functions with `callRendererFunction`.\n * Off for now: the result goes back as a developer message, and not every\n * backend keeps that message where the model reads it in order. While off,\n * the prompts do not mention the operation, the validator rejects it, and\n * the dispatcher refuses the agent, whatever a declaration's\n * `allowedCallers` says. The code and its tests stay for when it is on.\n */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS = false;\n/** The reason an agent function call is rejected while they are off. */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON =\n \"callRendererFunction is not supported in this version: the agent cannot call renderer functions until their results can be sent back to it reliably\";\n\n/** Activity message id of a surface. One message per surface. */\nexport function generativeUISurfaceMessageId(surfaceId: string) {\n return `genui:${surfaceId}`;\n}\n\n/**\n * Activity message id of an agent-called function. One message per\n * `functionCallId`.\n *\n * @param functionCallId - The `functionCallId` of the `callRendererFunction` operation.\n *\n * @example\n * ```ts\n * generativeUIFunctionCallMessageId(\"f1\"); // \"genui-fn:f1\"\n * ```\n */\nexport function generativeUIFunctionCallMessageId(functionCallId: string) {\n return `genui-fn:${functionCallId}`;\n}\n\nimport type {\n A2UIFunctionPermissions,\n A2UIFunctionReturnType,\n} from \"./basic-functions\";\n\n// Named `GenerativeUIJSONSchema` because the package root already exports a\n// `JSONSchema` (utils/json-schema.ts); the bare name would collide.\nexport type GenerativeUIJSONSchema = Record<string, unknown>;\n\nexport type A2UIComponentNode = {\n id: string;\n component: string;\n [prop: string]: unknown;\n};\n\n/**\n * The keys of the A2UI 1.0 component envelope next to `id` and\n * `component`: `catalogId`, `accessibility` and `metadata`. They are not\n * props of the component. The renderer reads `accessibility` and ignores\n * the other two.\n */\nexport const A2UI_COMPONENT_ENVELOPE_KEYS: ReadonlySet<string> = new Set([\n \"catalogId\",\n \"accessibility\",\n \"metadata\",\n]);\n\n/**\n * A call of a named function: `{ \"@call\": \"addToCart\", \"args\": { ... } }`.\n * Without `catalogId`, the function comes from the catalog of the run.\n */\nexport type A2UIFunctionCall = {\n \"@call\": string;\n args?: Record<string, unknown>;\n catalogId?: string;\n};\n\nexport type A2UIOperation =\n | {\n version: typeof A2UI_VERSION;\n createSurface: {\n surfaceId: string;\n /** Left out by the model. The run's catalog id is filled in. */\n catalogId?: string;\n /** Components to add at once, checked like `updateComponents`. */\n components?: A2UIComponentNode[];\n /** The initial root data model. */\n dataModel?: Record<string, unknown>;\n sendDataModel?: boolean;\n metadata?: { extensions?: Record<string, unknown> };\n };\n }\n | {\n version: typeof A2UI_VERSION;\n updateComponents: { surfaceId: string; components: A2UIComponentNode[] };\n }\n | {\n version: typeof A2UI_VERSION;\n /**\n * Sets `value` at `path`. A `null` value deletes the key at `path`.\n * With no `path`, or `\"/\"`, it sets the whole data model.\n */\n updateDataModel: { surfaceId: string; path?: string; value: unknown };\n }\n | {\n version: typeof A2UI_VERSION;\n deleteSurface: { surfaceId: string };\n }\n | {\n version: typeof A2UI_VERSION;\n /** Runs an app function in the browser, with no user interaction. */\n callRendererFunction: {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n };\n };\n\n/** Value of an event prop: run a host function, or report the event to the agent. */\nexport type GenerativeUIActionBinding =\n | {\n event: {\n name: string;\n /**\n * First line of the user message that the event becomes: text, a\n * data binding, or a function value such as formatString.\n */\n userMessage?: string | { \"@path\": string } | A2UIFunctionCall;\n context?: Record<string, unknown>;\n };\n }\n | { functionCall: A2UIFunctionCall };\n\nexport type GenerativeUISurfaceStatus = \"streaming\" | \"ready\" | \"error\";\n\nexport interface GenerativeUIRejectedOperation {\n /** Position of the operation in the render_ui call, or in the content list. */\n index: number;\n reason: string;\n}\n\n/** Content of a `generative-ui-surface` activity message. */\nexport interface GenerativeUISurfaceContent {\n surfaceId: string;\n target: string;\n catalogId: string;\n /** Committed (validated) operations, cumulative. */\n operations: A2UIOperation[];\n status: GenerativeUISurfaceStatus;\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/** Content of a `generative-ui-function-call` activity message. */\nexport interface GenerativeUIFunctionCallContent {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n}\n\n/**\n * Value of a \"multiple\" slot that repeats one component for each item of the\n * list at `path`. Paths inside the repeated component are relative to the item.\n */\nexport type GenerativeUITemplateChildren = {\n componentId: string;\n path: string;\n};\n\nexport interface GenerativeUIComponentManifest {\n /** CopilotKit positional order across model-visible props, slots and events.\n * Exporters encode this as JSON Schema property order; it is not an A2UI keyword. */\n parameterOrder?: readonly string[];\n description?: string;\n props: GenerativeUIJSONSchema;\n events?: Record<\n string,\n { description?: string; parameters: GenerativeUIJSONSchema }\n >;\n /**\n * Props that hold child components. A \"single\" slot takes one component id.\n * A \"multiple\" slot takes a `string[]` of component ids, or a\n * {@link GenerativeUITemplateChildren} template.\n */\n slots?: Record<string, \"single\" | \"multiple\">;\n}\n\nexport interface GenerativeUIFunctionManifest extends A2UIFunctionPermissions {\n description?: string;\n parameters: GenerativeUIJSONSchema;\n /** What the function gives back, as A2UI 1.0 names it. */\n returnType?: A2UIFunctionReturnType;\n}\n\n/** Serializable description of what the browser can render and call. */\nexport interface GenerativeUIManifest {\n /** The catalog of the run. A surface with no `catalogId` gets this one. */\n catalogId: string;\n /**\n * Every catalog that a `catalogId` can name: `catalogId` first, then the\n * catalogs of `extends`. Left out, only `catalogId`.\n */\n catalogIds?: string[];\n components: Record<string, GenerativeUIComponentManifest>;\n functions: Record<string, GenerativeUIFunctionManifest>;\n /**\n * Places where the model can render surfaces. Only mounted targets are\n * listed. `description` tells the model where the target is on the page\n * and what to put in it.\n */\n targets: GenerativeUITarget[];\n /** Surfaces the client already holds for the current thread. */\n surfaces: Record<string, GenerativeUISurfaceSummary>;\n}\n\n/** A place where the model can render surfaces. */\nexport interface GenerativeUITarget {\n id: string;\n kind: \"chat\" | \"inline\";\n description?: string;\n /**\n * The only components that the surfaces of this target can use, at most\n * {@link GENERATIVE_UI_MAX_TARGET_COMPONENTS} names. Left out, the target\n * takes every component of the catalog.\n */\n components?: string[];\n}\n\n/** Most component names that one target can list. */\nexport const GENERATIVE_UI_MAX_TARGET_COMPONENTS = 100;\n\n/** Most rejections that a surface summary lists. */\nexport const GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = 20;\n/** Most characters of one rejection in a surface summary. */\nexport const GENERATIVE_UI_MAX_REJECTION_LENGTH = 500;\n\n/** One surface that the client holds, as the model sees it. */\nexport interface GenerativeUISurfaceSummary {\n target: string;\n /** The values that the user set, by path. Left out when there are none. */\n dataModel?: Record<string, unknown>;\n /**\n * Operations that the client dropped, as `\"operation <index>: <reason>\"`.\n * At most {@link GENERATIVE_UI_MAX_SUMMARY_REJECTIONS} entries of at most\n * {@link GENERATIVE_UI_MAX_REJECTION_LENGTH} characters. Left out when\n * there are none.\n */\n rejected?: string[];\n /**\n * Left out while the surface exists. `\"deleted\"`: a deleteSurface removed\n * it, and its id cannot be used again. `\"failed\"`: its createSurface was\n * rejected, so it does not exist; a corrected createSurface can use the id.\n */\n status?: \"deleted\" | \"failed\";\n}\n\n/** A user interaction bound to `{ event }`, sent to the agent. */\nexport interface GenerativeUIUserEvent {\n name: string;\n surfaceId: string;\n componentId: string;\n context: Record<string, unknown>;\n /** The resolved `event.userMessage`: the first line of the user message. */\n userMessage?: string;\n /** When the user acted, as an ISO 8601 string. Filled in when left out. */\n timestamp?: string;\n}\n\n/**\n * The A2UI 1.0 action message of a user event: what a renderer sends to the\n * agent when the user triggers an `{ event }` action. The run that the\n * event starts carries it in the envelope (`copilotkit_action`), next to\n * the visible user message.\n */\nexport interface A2UIActionMessage {\n version: typeof A2UI_VERSION;\n action: {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n /** ISO 8601. */\n timestamp: string;\n userMessage?: string;\n context: Record<string, unknown>;\n };\n}\n\n/**\n * The action message of a user event, with the A2UI field names. Takes the\n * time of the call when the event has no timestamp.\n *\n * @example\n * ```ts\n * toA2UIActionMessage({ name: \"buy\", surfaceId: \"s1\", componentId: \"b\", context: { sku: \"a\" } });\n * // { version: \"1.0\", action: { name: \"buy\", surfaceId: \"s1\", sourceComponentId: \"b\", timestamp: \"2026-…\", context: { sku: \"a\" } } }\n * ```\n */\nexport function toA2UIActionMessage(\n event: GenerativeUIUserEvent,\n): A2UIActionMessage {\n return {\n version: A2UI_VERSION,\n action: {\n name: event.name,\n surfaceId: event.surfaceId,\n sourceComponentId: event.componentId,\n timestamp: event.timestamp ?? new Date().toISOString(),\n ...(event.userMessage === undefined\n ? {}\n : { userMessage: event.userMessage }),\n context: event.context,\n },\n };\n}\n"],"mappings":";;;AACA,MAAa,eAAe;;AAE5B,MAAa,8BAA8B;;AAE3C,MAAa,4CACX;;AAEF,MAAa,4BAA4B;;AAEzC,MAAa,4BAA4B;;AAEzC,MAAa,wBAAwB;;;;;;;;;AASrC,MAAa,qCAAqC;;AAElD,MAAa,gDACX;;AAGF,SAAgB,6BAA6B,WAAmB;AAC9D,QAAO,SAAS;;;;;;;;;;;;;AAclB,SAAgB,kCAAkC,gBAAwB;AACxE,QAAO,YAAY;;;;;;;;AAwBrB,MAAa,+BAAoD,IAAI,IAAI;CACvE;CACA;CACA;CACD,CAAC;;AAiKF,MAAa,sCAAsC;;AAGnD,MAAa,uCAAuC;;AAEpD,MAAa,qCAAqC;;;;;;;;;;;AA+DlD,SAAgB,oBACd,OACmB;AACnB,QAAO;EACL,SAAS;EACT,QAAQ;GACN,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,mBAAmB,MAAM;GACzB,WAAW,MAAM,8BAAa,IAAI,MAAM,EAAC,aAAa;GACtD,GAAI,MAAM,gBAAgB,SACtB,EAAE,GACF,EAAE,aAAa,MAAM,aAAa;GACtC,SAAS,MAAM;GAChB;EACF"}
|
|
@@ -2,7 +2,7 @@ import { A2UIFunctionPermissions, A2UIFunctionReturnType } from "./basic-functio
|
|
|
2
2
|
|
|
3
3
|
//#region src/generative-ui/types.d.ts
|
|
4
4
|
/** A2UI protocol version used on the wire. */
|
|
5
|
-
declare const A2UI_VERSION = "
|
|
5
|
+
declare const A2UI_VERSION = "1.0";
|
|
6
6
|
/** Activity type of a generated surface message. */
|
|
7
7
|
declare const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
8
8
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -61,7 +61,7 @@ type A2UIFunctionCall = {
|
|
|
61
61
|
catalogId?: string;
|
|
62
62
|
};
|
|
63
63
|
type A2UIOperation = {
|
|
64
|
-
version:
|
|
64
|
+
version: typeof A2UI_VERSION;
|
|
65
65
|
createSurface: {
|
|
66
66
|
surfaceId: string; /** Left out by the model. The run's catalog id is filled in. */
|
|
67
67
|
catalogId?: string; /** Components to add at once, checked like `updateComponents`. */
|
|
@@ -73,13 +73,13 @@ type A2UIOperation = {
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
} | {
|
|
76
|
-
version:
|
|
76
|
+
version: typeof A2UI_VERSION;
|
|
77
77
|
updateComponents: {
|
|
78
78
|
surfaceId: string;
|
|
79
79
|
components: A2UIComponentNode[];
|
|
80
80
|
};
|
|
81
81
|
} | {
|
|
82
|
-
version:
|
|
82
|
+
version: typeof A2UI_VERSION;
|
|
83
83
|
/**
|
|
84
84
|
* Sets `value` at `path`. A `null` value deletes the key at `path`.
|
|
85
85
|
* With no `path`, or `"/"`, it sets the whole data model.
|
|
@@ -90,12 +90,12 @@ type A2UIOperation = {
|
|
|
90
90
|
value: unknown;
|
|
91
91
|
};
|
|
92
92
|
} | {
|
|
93
|
-
version:
|
|
93
|
+
version: typeof A2UI_VERSION;
|
|
94
94
|
deleteSurface: {
|
|
95
95
|
surfaceId: string;
|
|
96
96
|
};
|
|
97
97
|
} | {
|
|
98
|
-
version:
|
|
98
|
+
version: typeof A2UI_VERSION; /** Runs an app function in the browser, with no user interaction. */
|
|
99
99
|
callRendererFunction: {
|
|
100
100
|
functionCallId: string;
|
|
101
101
|
callFunction: A2UIFunctionCall;
|
|
@@ -261,7 +261,7 @@ interface A2UIActionMessage {
|
|
|
261
261
|
* @example
|
|
262
262
|
* ```ts
|
|
263
263
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
264
|
-
* // { version: "
|
|
264
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
265
265
|
* ```
|
|
266
266
|
*/
|
|
267
267
|
declare function toA2UIActionMessage(event: GenerativeUIUserEvent): A2UIActionMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/generative-ui/types.ts"],"mappings":";;;;cACa,YAAA;;cAEA,2BAAA;;cAEA,yCAAA;;cAGA,yBAAA;AALb;AAAA,cAOa,yBAAA;;cAEA,qBAAA;;AAPb;;;;;AAGA;;cAaa,kCAAA;;cAEA,6CAAA;AAbb;AAAA,iBAiBgB,4BAAA,CAA6B,SAAA;;;;AAf7C;;;;;AASA;;;iBAqBgB,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A;;cAEA,kCAAA;;UAGI,0BAAA;EACf,MAAA;EAtDA;EAwDA,SAAA,GAAY,MAAA;EAxDE;;AAGhB;;;;EA4DE,QAAA;EA5DoD;;;;;EAkEpD,MAAA;AAAA;;UAIe,qBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;EACA,OAAA,EAAS,MAAA;;EAET,WAAA;EA5DY;EA8DZ,SAAA;AAAA;;;;;;;UASe,iBAAA;EACf,OAAA,SAAgB,YAAA;EAChB,MAAA;IACE,IAAA;IACA,SAAA;IACA,iBAAA,UA3EwB;IA6ExB,SAAA;IACA,WAAA;IACA,OAAA,EAAS,MAAA;EAAA;AAAA;;;AAnEb;;;;;;;;iBAiFgB,mBAAA,CACd,KAAA,EAAO,qBAAA,GACN,iBAAA"}
|
|
@@ -2,7 +2,7 @@ import { A2UIFunctionPermissions, A2UIFunctionReturnType } from "./basic-functio
|
|
|
2
2
|
|
|
3
3
|
//#region src/generative-ui/types.d.ts
|
|
4
4
|
/** A2UI protocol version used on the wire. */
|
|
5
|
-
declare const A2UI_VERSION = "
|
|
5
|
+
declare const A2UI_VERSION = "1.0";
|
|
6
6
|
/** Activity type of a generated surface message. */
|
|
7
7
|
declare const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
8
8
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -61,7 +61,7 @@ type A2UIFunctionCall = {
|
|
|
61
61
|
catalogId?: string;
|
|
62
62
|
};
|
|
63
63
|
type A2UIOperation = {
|
|
64
|
-
version:
|
|
64
|
+
version: typeof A2UI_VERSION;
|
|
65
65
|
createSurface: {
|
|
66
66
|
surfaceId: string; /** Left out by the model. The run's catalog id is filled in. */
|
|
67
67
|
catalogId?: string; /** Components to add at once, checked like `updateComponents`. */
|
|
@@ -73,13 +73,13 @@ type A2UIOperation = {
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
} | {
|
|
76
|
-
version:
|
|
76
|
+
version: typeof A2UI_VERSION;
|
|
77
77
|
updateComponents: {
|
|
78
78
|
surfaceId: string;
|
|
79
79
|
components: A2UIComponentNode[];
|
|
80
80
|
};
|
|
81
81
|
} | {
|
|
82
|
-
version:
|
|
82
|
+
version: typeof A2UI_VERSION;
|
|
83
83
|
/**
|
|
84
84
|
* Sets `value` at `path`. A `null` value deletes the key at `path`.
|
|
85
85
|
* With no `path`, or `"/"`, it sets the whole data model.
|
|
@@ -90,12 +90,12 @@ type A2UIOperation = {
|
|
|
90
90
|
value: unknown;
|
|
91
91
|
};
|
|
92
92
|
} | {
|
|
93
|
-
version:
|
|
93
|
+
version: typeof A2UI_VERSION;
|
|
94
94
|
deleteSurface: {
|
|
95
95
|
surfaceId: string;
|
|
96
96
|
};
|
|
97
97
|
} | {
|
|
98
|
-
version:
|
|
98
|
+
version: typeof A2UI_VERSION; /** Runs an app function in the browser, with no user interaction. */
|
|
99
99
|
callRendererFunction: {
|
|
100
100
|
functionCallId: string;
|
|
101
101
|
callFunction: A2UIFunctionCall;
|
|
@@ -261,7 +261,7 @@ interface A2UIActionMessage {
|
|
|
261
261
|
* @example
|
|
262
262
|
* ```ts
|
|
263
263
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
264
|
-
* // { version: "
|
|
264
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
265
265
|
* ```
|
|
266
266
|
*/
|
|
267
267
|
declare function toA2UIActionMessage(event: GenerativeUIUserEvent): A2UIActionMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/generative-ui/types.ts"],"mappings":";;;;cACa,YAAA;;cAEA,2BAAA;;cAEA,yCAAA;;cAGA,yBAAA;AALb;AAAA,cAOa,yBAAA;;cAEA,qBAAA;;AAPb;;;;;AAGA;;cAaa,kCAAA;;cAEA,6CAAA;AAbb;AAAA,iBAiBgB,4BAAA,C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EAMA,UAAA;AAAA;;cAIW,mCAAA;;cAGA,oCAAA;;cAEA,kCAAA;;UAGI,0BAAA;EACf,MAAA;EAtDA;EAwDA,SAAA,GAAY,MAAA;EAxDE;;AAGhB;;;;EA4DE,QAAA;EA5DoD;;;;;EAkEpD,MAAA;AAAA;;UAIe,qBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;EACA,OAAA,EAAS,MAAA;;EAET,WAAA;EA5DY;EA8DZ,SAAA;AAAA;;;;;;;UASe,iBAAA;EACf,OAAA,SAAgB,YAAA;EAChB,MAAA;IACE,IAAA;IACA,SAAA;IACA,iBAAA,UA3EwB;IA6ExB,SAAA;IACA,WAAA;IACA,OAAA,EAAS,MAAA;EAAA;AAAA;;;AAnEb;;;;;;;;iBAiFgB,mBAAA,CACd,KAAA,EAAO,qBAAA,GACN,iBAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/generative-ui/types.ts
|
|
2
2
|
/** A2UI protocol version used on the wire. */
|
|
3
|
-
const A2UI_VERSION = "
|
|
3
|
+
const A2UI_VERSION = "1.0";
|
|
4
4
|
/** Activity type of a generated surface message. */
|
|
5
5
|
const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
6
6
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -64,7 +64,7 @@ const GENERATIVE_UI_MAX_REJECTION_LENGTH = 500;
|
|
|
64
64
|
* @example
|
|
65
65
|
* ```ts
|
|
66
66
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
67
|
-
* // { version: "
|
|
67
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
function toA2UIActionMessage(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/generative-ui/types.ts"],"sourcesContent":["/** A2UI protocol version used on the wire. */\nexport const A2UI_VERSION = \"v1.0\";\n/** Activity type of a generated surface message. */\nexport const GENERATIVE_UI_ACTIVITY_TYPE = \"generative-ui-surface\";\n/** Activity type of a function call that the agent asks the client to run. */\nexport const GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE =\n \"generative-ui-function-call\";\n/** Tool the model calls to render or update surfaces. */\nexport const GENERATIVE_UI_RENDER_TOOL = \"render_ui\";\n/** Target id of the chat transcript. */\nexport const GENERATIVE_UI_CHAT_TARGET = \"chat\";\n/** Component id every surface renders from. */\nexport const GENERATIVE_UI_ROOT_ID = \"root\";\n/**\n * Whether the agent may call renderer functions with `callRendererFunction`.\n * Off for now: the result goes back as a developer message, and not every\n * backend keeps that message where the model reads it in order. While off,\n * the prompts do not mention the operation, the validator rejects it, and\n * the dispatcher refuses the agent, whatever a declaration's\n * `allowedCallers` says. The code and its tests stay for when it is on.\n */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS = false;\n/** The reason an agent function call is rejected while they are off. */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON =\n \"callRendererFunction is not supported in this version: the agent cannot call renderer functions until their results can be sent back to it reliably\";\n\n/** Activity message id of a surface. One message per surface. */\nexport function generativeUISurfaceMessageId(surfaceId: string) {\n return `genui:${surfaceId}`;\n}\n\n/**\n * Activity message id of an agent-called function. One message per\n * `functionCallId`.\n *\n * @param functionCallId - The `functionCallId` of the `callRendererFunction` operation.\n *\n * @example\n * ```ts\n * generativeUIFunctionCallMessageId(\"f1\"); // \"genui-fn:f1\"\n * ```\n */\nexport function generativeUIFunctionCallMessageId(functionCallId: string) {\n return `genui-fn:${functionCallId}`;\n}\n\nimport type {\n A2UIFunctionPermissions,\n A2UIFunctionReturnType,\n} from \"./basic-functions\";\n\n// Named `GenerativeUIJSONSchema` because the package root already exports a\n// `JSONSchema` (utils/json-schema.ts); the bare name would collide.\nexport type GenerativeUIJSONSchema = Record<string, unknown>;\n\nexport type A2UIComponentNode = {\n id: string;\n component: string;\n [prop: string]: unknown;\n};\n\n/**\n * The keys of the A2UI 1.0 component envelope next to `id` and\n * `component`: `catalogId`, `accessibility` and `metadata`. They are not\n * props of the component. The renderer reads `accessibility` and ignores\n * the other two.\n */\nexport const A2UI_COMPONENT_ENVELOPE_KEYS: ReadonlySet<string> = new Set([\n \"catalogId\",\n \"accessibility\",\n \"metadata\",\n]);\n\n/**\n * A call of a named function: `{ \"@call\": \"addToCart\", \"args\": { ... } }`.\n * Without `catalogId`, the function comes from the catalog of the run.\n */\nexport type A2UIFunctionCall = {\n \"@call\": string;\n args?: Record<string, unknown>;\n catalogId?: string;\n};\n\nexport type A2UIOperation =\n | {\n version: \"v1.0\";\n createSurface: {\n surfaceId: string;\n /** Left out by the model. The run's catalog id is filled in. */\n catalogId?: string;\n /** Components to add at once, checked like `updateComponents`. */\n components?: A2UIComponentNode[];\n /** The initial root data model. */\n dataModel?: Record<string, unknown>;\n sendDataModel?: boolean;\n metadata?: { extensions?: Record<string, unknown> };\n };\n }\n | {\n version: \"v1.0\";\n updateComponents: { surfaceId: string; components: A2UIComponentNode[] };\n }\n | {\n version: \"v1.0\";\n /**\n * Sets `value` at `path`. A `null` value deletes the key at `path`.\n * With no `path`, or `\"/\"`, it sets the whole data model.\n */\n updateDataModel: { surfaceId: string; path?: string; value: unknown };\n }\n | { version: \"v1.0\"; deleteSurface: { surfaceId: string } }\n | {\n version: \"v1.0\";\n /** Runs an app function in the browser, with no user interaction. */\n callRendererFunction: {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n };\n };\n\n/** Value of an event prop: run a host function, or report the event to the agent. */\nexport type GenerativeUIActionBinding =\n | {\n event: {\n name: string;\n /**\n * First line of the user message that the event becomes: text, a\n * data binding, or a function value such as formatString.\n */\n userMessage?: string | { \"@path\": string } | A2UIFunctionCall;\n context?: Record<string, unknown>;\n };\n }\n | { functionCall: A2UIFunctionCall };\n\nexport type GenerativeUISurfaceStatus = \"streaming\" | \"ready\" | \"error\";\n\nexport interface GenerativeUIRejectedOperation {\n /** Position of the operation in the render_ui call, or in the content list. */\n index: number;\n reason: string;\n}\n\n/** Content of a `generative-ui-surface` activity message. */\nexport interface GenerativeUISurfaceContent {\n surfaceId: string;\n target: string;\n catalogId: string;\n /** Committed (validated) operations, cumulative. */\n operations: A2UIOperation[];\n status: GenerativeUISurfaceStatus;\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/** Content of a `generative-ui-function-call` activity message. */\nexport interface GenerativeUIFunctionCallContent {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n}\n\n/**\n * Value of a \"multiple\" slot that repeats one component for each item of the\n * list at `path`. Paths inside the repeated component are relative to the item.\n */\nexport type GenerativeUITemplateChildren = {\n componentId: string;\n path: string;\n};\n\nexport interface GenerativeUIComponentManifest {\n /** CopilotKit positional order across model-visible props, slots and events.\n * Exporters encode this as JSON Schema property order; it is not an A2UI keyword. */\n parameterOrder?: readonly string[];\n description?: string;\n props: GenerativeUIJSONSchema;\n events?: Record<\n string,\n { description?: string; parameters: GenerativeUIJSONSchema }\n >;\n /**\n * Props that hold child components. A \"single\" slot takes one component id.\n * A \"multiple\" slot takes a `string[]` of component ids, or a\n * {@link GenerativeUITemplateChildren} template.\n */\n slots?: Record<string, \"single\" | \"multiple\">;\n}\n\nexport interface GenerativeUIFunctionManifest extends A2UIFunctionPermissions {\n description?: string;\n parameters: GenerativeUIJSONSchema;\n /** What the function gives back, as A2UI 1.0 names it. */\n returnType?: A2UIFunctionReturnType;\n}\n\n/** Serializable description of what the browser can render and call. */\nexport interface GenerativeUIManifest {\n /** The catalog of the run. A surface with no `catalogId` gets this one. */\n catalogId: string;\n /**\n * Every catalog that a `catalogId` can name: `catalogId` first, then the\n * catalogs of `extends`. Left out, only `catalogId`.\n */\n catalogIds?: string[];\n components: Record<string, GenerativeUIComponentManifest>;\n functions: Record<string, GenerativeUIFunctionManifest>;\n /**\n * Places where the model can render surfaces. Only mounted targets are\n * listed. `description` tells the model where the target is on the page\n * and what to put in it.\n */\n targets: GenerativeUITarget[];\n /** Surfaces the client already holds for the current thread. */\n surfaces: Record<string, GenerativeUISurfaceSummary>;\n}\n\n/** A place where the model can render surfaces. */\nexport interface GenerativeUITarget {\n id: string;\n kind: \"chat\" | \"inline\";\n description?: string;\n /**\n * The only components that the surfaces of this target can use, at most\n * {@link GENERATIVE_UI_MAX_TARGET_COMPONENTS} names. Left out, the target\n * takes every component of the catalog.\n */\n components?: string[];\n}\n\n/** Most component names that one target can list. */\nexport const GENERATIVE_UI_MAX_TARGET_COMPONENTS = 100;\n\n/** Most rejections that a surface summary lists. */\nexport const GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = 20;\n/** Most characters of one rejection in a surface summary. */\nexport const GENERATIVE_UI_MAX_REJECTION_LENGTH = 500;\n\n/** One surface that the client holds, as the model sees it. */\nexport interface GenerativeUISurfaceSummary {\n target: string;\n /** The values that the user set, by path. Left out when there are none. */\n dataModel?: Record<string, unknown>;\n /**\n * Operations that the client dropped, as `\"operation <index>: <reason>\"`.\n * At most {@link GENERATIVE_UI_MAX_SUMMARY_REJECTIONS} entries of at most\n * {@link GENERATIVE_UI_MAX_REJECTION_LENGTH} characters. Left out when\n * there are none.\n */\n rejected?: string[];\n /**\n * Left out while the surface exists. `\"deleted\"`: a deleteSurface removed\n * it, and its id cannot be used again. `\"failed\"`: its createSurface was\n * rejected, so it does not exist; a corrected createSurface can use the id.\n */\n status?: \"deleted\" | \"failed\";\n}\n\n/** A user interaction bound to `{ event }`, sent to the agent. */\nexport interface GenerativeUIUserEvent {\n name: string;\n surfaceId: string;\n componentId: string;\n context: Record<string, unknown>;\n /** The resolved `event.userMessage`: the first line of the user message. */\n userMessage?: string;\n /** When the user acted, as an ISO 8601 string. Filled in when left out. */\n timestamp?: string;\n}\n\n/**\n * The A2UI 1.0 action message of a user event: what a renderer sends to the\n * agent when the user triggers an `{ event }` action. The run that the\n * event starts carries it in the envelope (`copilotkit_action`), next to\n * the visible user message.\n */\nexport interface A2UIActionMessage {\n version: typeof A2UI_VERSION;\n action: {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n /** ISO 8601. */\n timestamp: string;\n userMessage?: string;\n context: Record<string, unknown>;\n };\n}\n\n/**\n * The action message of a user event, with the A2UI field names. Takes the\n * time of the call when the event has no timestamp.\n *\n * @example\n * ```ts\n * toA2UIActionMessage({ name: \"buy\", surfaceId: \"s1\", componentId: \"b\", context: { sku: \"a\" } });\n * // { version: \"v1.0\", action: { name: \"buy\", surfaceId: \"s1\", sourceComponentId: \"b\", timestamp: \"2026-…\", context: { sku: \"a\" } } }\n * ```\n */\nexport function toA2UIActionMessage(\n event: GenerativeUIUserEvent,\n): A2UIActionMessage {\n return {\n version: A2UI_VERSION,\n action: {\n name: event.name,\n surfaceId: event.surfaceId,\n sourceComponentId: event.componentId,\n timestamp: event.timestamp ?? new Date().toISOString(),\n ...(event.userMessage === undefined\n ? {}\n : { userMessage: event.userMessage }),\n context: event.context,\n },\n };\n}\n"],"mappings":";;AACA,MAAa,eAAe;;AAE5B,MAAa,8BAA8B;;AAE3C,MAAa,4CACX;;AAEF,MAAa,4BAA4B;;AAEzC,MAAa,4BAA4B;;AAEzC,MAAa,wBAAwB;;;;;;;;;AASrC,MAAa,qCAAqC;;AAElD,MAAa,gDACX;;AAGF,SAAgB,6BAA6B,WAAmB;AAC9D,QAAO,SAAS;;;;;;;;;;;;;AAclB,SAAgB,kCAAkC,gBAAwB;AACxE,QAAO,YAAY;;;;;;;;AAwBrB,MAAa,+BAAoD,IAAI,IAAI;CACvE;CACA;CACA;CACD,CAAC;;AA8JF,MAAa,sCAAsC;;AAGnD,MAAa,uCAAuC;;AAEpD,MAAa,qCAAqC;;;;;;;;;;;AA+DlD,SAAgB,oBACd,OACmB;AACnB,QAAO;EACL,SAAS;EACT,QAAQ;GACN,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,mBAAmB,MAAM;GACzB,WAAW,MAAM,8BAAa,IAAI,MAAM,EAAC,aAAa;GACtD,GAAI,MAAM,gBAAgB,SACtB,EAAE,GACF,EAAE,aAAa,MAAM,aAAa;GACtC,SAAS,MAAM;GAChB;EACF"}
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/generative-ui/types.ts"],"sourcesContent":["/** A2UI protocol version used on the wire. */\nexport const A2UI_VERSION = \"1.0\";\n/** Activity type of a generated surface message. */\nexport const GENERATIVE_UI_ACTIVITY_TYPE = \"generative-ui-surface\";\n/** Activity type of a function call that the agent asks the client to run. */\nexport const GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE =\n \"generative-ui-function-call\";\n/** Tool the model calls to render or update surfaces. */\nexport const GENERATIVE_UI_RENDER_TOOL = \"render_ui\";\n/** Target id of the chat transcript. */\nexport const GENERATIVE_UI_CHAT_TARGET = \"chat\";\n/** Component id every surface renders from. */\nexport const GENERATIVE_UI_ROOT_ID = \"root\";\n/**\n * Whether the agent may call renderer functions with `callRendererFunction`.\n * Off for now: the result goes back as a developer message, and not every\n * backend keeps that message where the model reads it in order. While off,\n * the prompts do not mention the operation, the validator rejects it, and\n * the dispatcher refuses the agent, whatever a declaration's\n * `allowedCallers` says. The code and its tests stay for when it is on.\n */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS = false;\n/** The reason an agent function call is rejected while they are off. */\nexport const GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON =\n \"callRendererFunction is not supported in this version: the agent cannot call renderer functions until their results can be sent back to it reliably\";\n\n/** Activity message id of a surface. One message per surface. */\nexport function generativeUISurfaceMessageId(surfaceId: string) {\n return `genui:${surfaceId}`;\n}\n\n/**\n * Activity message id of an agent-called function. One message per\n * `functionCallId`.\n *\n * @param functionCallId - The `functionCallId` of the `callRendererFunction` operation.\n *\n * @example\n * ```ts\n * generativeUIFunctionCallMessageId(\"f1\"); // \"genui-fn:f1\"\n * ```\n */\nexport function generativeUIFunctionCallMessageId(functionCallId: string) {\n return `genui-fn:${functionCallId}`;\n}\n\nimport type {\n A2UIFunctionPermissions,\n A2UIFunctionReturnType,\n} from \"./basic-functions\";\n\n// Named `GenerativeUIJSONSchema` because the package root already exports a\n// `JSONSchema` (utils/json-schema.ts); the bare name would collide.\nexport type GenerativeUIJSONSchema = Record<string, unknown>;\n\nexport type A2UIComponentNode = {\n id: string;\n component: string;\n [prop: string]: unknown;\n};\n\n/**\n * The keys of the A2UI 1.0 component envelope next to `id` and\n * `component`: `catalogId`, `accessibility` and `metadata`. They are not\n * props of the component. The renderer reads `accessibility` and ignores\n * the other two.\n */\nexport const A2UI_COMPONENT_ENVELOPE_KEYS: ReadonlySet<string> = new Set([\n \"catalogId\",\n \"accessibility\",\n \"metadata\",\n]);\n\n/**\n * A call of a named function: `{ \"@call\": \"addToCart\", \"args\": { ... } }`.\n * Without `catalogId`, the function comes from the catalog of the run.\n */\nexport type A2UIFunctionCall = {\n \"@call\": string;\n args?: Record<string, unknown>;\n catalogId?: string;\n};\n\nexport type A2UIOperation =\n | {\n version: typeof A2UI_VERSION;\n createSurface: {\n surfaceId: string;\n /** Left out by the model. The run's catalog id is filled in. */\n catalogId?: string;\n /** Components to add at once, checked like `updateComponents`. */\n components?: A2UIComponentNode[];\n /** The initial root data model. */\n dataModel?: Record<string, unknown>;\n sendDataModel?: boolean;\n metadata?: { extensions?: Record<string, unknown> };\n };\n }\n | {\n version: typeof A2UI_VERSION;\n updateComponents: { surfaceId: string; components: A2UIComponentNode[] };\n }\n | {\n version: typeof A2UI_VERSION;\n /**\n * Sets `value` at `path`. A `null` value deletes the key at `path`.\n * With no `path`, or `\"/\"`, it sets the whole data model.\n */\n updateDataModel: { surfaceId: string; path?: string; value: unknown };\n }\n | {\n version: typeof A2UI_VERSION;\n deleteSurface: { surfaceId: string };\n }\n | {\n version: typeof A2UI_VERSION;\n /** Runs an app function in the browser, with no user interaction. */\n callRendererFunction: {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n };\n };\n\n/** Value of an event prop: run a host function, or report the event to the agent. */\nexport type GenerativeUIActionBinding =\n | {\n event: {\n name: string;\n /**\n * First line of the user message that the event becomes: text, a\n * data binding, or a function value such as formatString.\n */\n userMessage?: string | { \"@path\": string } | A2UIFunctionCall;\n context?: Record<string, unknown>;\n };\n }\n | { functionCall: A2UIFunctionCall };\n\nexport type GenerativeUISurfaceStatus = \"streaming\" | \"ready\" | \"error\";\n\nexport interface GenerativeUIRejectedOperation {\n /** Position of the operation in the render_ui call, or in the content list. */\n index: number;\n reason: string;\n}\n\n/** Content of a `generative-ui-surface` activity message. */\nexport interface GenerativeUISurfaceContent {\n surfaceId: string;\n target: string;\n catalogId: string;\n /** Committed (validated) operations, cumulative. */\n operations: A2UIOperation[];\n status: GenerativeUISurfaceStatus;\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/** Content of a `generative-ui-function-call` activity message. */\nexport interface GenerativeUIFunctionCallContent {\n functionCallId: string;\n callFunction: A2UIFunctionCall;\n}\n\n/**\n * Value of a \"multiple\" slot that repeats one component for each item of the\n * list at `path`. Paths inside the repeated component are relative to the item.\n */\nexport type GenerativeUITemplateChildren = {\n componentId: string;\n path: string;\n};\n\nexport interface GenerativeUIComponentManifest {\n /** CopilotKit positional order across model-visible props, slots and events.\n * Exporters encode this as JSON Schema property order; it is not an A2UI keyword. */\n parameterOrder?: readonly string[];\n description?: string;\n props: GenerativeUIJSONSchema;\n events?: Record<\n string,\n { description?: string; parameters: GenerativeUIJSONSchema }\n >;\n /**\n * Props that hold child components. A \"single\" slot takes one component id.\n * A \"multiple\" slot takes a `string[]` of component ids, or a\n * {@link GenerativeUITemplateChildren} template.\n */\n slots?: Record<string, \"single\" | \"multiple\">;\n}\n\nexport interface GenerativeUIFunctionManifest extends A2UIFunctionPermissions {\n description?: string;\n parameters: GenerativeUIJSONSchema;\n /** What the function gives back, as A2UI 1.0 names it. */\n returnType?: A2UIFunctionReturnType;\n}\n\n/** Serializable description of what the browser can render and call. */\nexport interface GenerativeUIManifest {\n /** The catalog of the run. A surface with no `catalogId` gets this one. */\n catalogId: string;\n /**\n * Every catalog that a `catalogId` can name: `catalogId` first, then the\n * catalogs of `extends`. Left out, only `catalogId`.\n */\n catalogIds?: string[];\n components: Record<string, GenerativeUIComponentManifest>;\n functions: Record<string, GenerativeUIFunctionManifest>;\n /**\n * Places where the model can render surfaces. Only mounted targets are\n * listed. `description` tells the model where the target is on the page\n * and what to put in it.\n */\n targets: GenerativeUITarget[];\n /** Surfaces the client already holds for the current thread. */\n surfaces: Record<string, GenerativeUISurfaceSummary>;\n}\n\n/** A place where the model can render surfaces. */\nexport interface GenerativeUITarget {\n id: string;\n kind: \"chat\" | \"inline\";\n description?: string;\n /**\n * The only components that the surfaces of this target can use, at most\n * {@link GENERATIVE_UI_MAX_TARGET_COMPONENTS} names. Left out, the target\n * takes every component of the catalog.\n */\n components?: string[];\n}\n\n/** Most component names that one target can list. */\nexport const GENERATIVE_UI_MAX_TARGET_COMPONENTS = 100;\n\n/** Most rejections that a surface summary lists. */\nexport const GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = 20;\n/** Most characters of one rejection in a surface summary. */\nexport const GENERATIVE_UI_MAX_REJECTION_LENGTH = 500;\n\n/** One surface that the client holds, as the model sees it. */\nexport interface GenerativeUISurfaceSummary {\n target: string;\n /** The values that the user set, by path. Left out when there are none. */\n dataModel?: Record<string, unknown>;\n /**\n * Operations that the client dropped, as `\"operation <index>: <reason>\"`.\n * At most {@link GENERATIVE_UI_MAX_SUMMARY_REJECTIONS} entries of at most\n * {@link GENERATIVE_UI_MAX_REJECTION_LENGTH} characters. Left out when\n * there are none.\n */\n rejected?: string[];\n /**\n * Left out while the surface exists. `\"deleted\"`: a deleteSurface removed\n * it, and its id cannot be used again. `\"failed\"`: its createSurface was\n * rejected, so it does not exist; a corrected createSurface can use the id.\n */\n status?: \"deleted\" | \"failed\";\n}\n\n/** A user interaction bound to `{ event }`, sent to the agent. */\nexport interface GenerativeUIUserEvent {\n name: string;\n surfaceId: string;\n componentId: string;\n context: Record<string, unknown>;\n /** The resolved `event.userMessage`: the first line of the user message. */\n userMessage?: string;\n /** When the user acted, as an ISO 8601 string. Filled in when left out. */\n timestamp?: string;\n}\n\n/**\n * The A2UI 1.0 action message of a user event: what a renderer sends to the\n * agent when the user triggers an `{ event }` action. The run that the\n * event starts carries it in the envelope (`copilotkit_action`), next to\n * the visible user message.\n */\nexport interface A2UIActionMessage {\n version: typeof A2UI_VERSION;\n action: {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n /** ISO 8601. */\n timestamp: string;\n userMessage?: string;\n context: Record<string, unknown>;\n };\n}\n\n/**\n * The action message of a user event, with the A2UI field names. Takes the\n * time of the call when the event has no timestamp.\n *\n * @example\n * ```ts\n * toA2UIActionMessage({ name: \"buy\", surfaceId: \"s1\", componentId: \"b\", context: { sku: \"a\" } });\n * // { version: \"1.0\", action: { name: \"buy\", surfaceId: \"s1\", sourceComponentId: \"b\", timestamp: \"2026-…\", context: { sku: \"a\" } } }\n * ```\n */\nexport function toA2UIActionMessage(\n event: GenerativeUIUserEvent,\n): A2UIActionMessage {\n return {\n version: A2UI_VERSION,\n action: {\n name: event.name,\n surfaceId: event.surfaceId,\n sourceComponentId: event.componentId,\n timestamp: event.timestamp ?? new Date().toISOString(),\n ...(event.userMessage === undefined\n ? {}\n : { userMessage: event.userMessage }),\n context: event.context,\n },\n };\n}\n"],"mappings":";;AACA,MAAa,eAAe;;AAE5B,MAAa,8BAA8B;;AAE3C,MAAa,4CACX;;AAEF,MAAa,4BAA4B;;AAEzC,MAAa,4BAA4B;;AAEzC,MAAa,wBAAwB;;;;;;;;;AASrC,MAAa,qCAAqC;;AAElD,MAAa,gDACX;;AAGF,SAAgB,6BAA6B,WAAmB;AAC9D,QAAO,SAAS;;;;;;;;;;;;;AAclB,SAAgB,kCAAkC,gBAAwB;AACxE,QAAO,YAAY;;;;;;;;AAwBrB,MAAa,+BAAoD,IAAI,IAAI;CACvE;CACA;CACA;CACD,CAAC;;AAiKF,MAAa,sCAAsC;;AAGnD,MAAa,uCAAuC;;AAEpD,MAAa,qCAAqC;;;;;;;;;;;AA+DlD,SAAgB,oBACd,OACmB;AACnB,QAAO;EACL,SAAS;EACT,QAAQ;GACN,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,mBAAmB,MAAM;GACzB,WAAW,MAAM,8BAAa,IAAI,MAAM,EAAC,aAAa;GACtD,GAAI,MAAM,gBAAgB,SACtB,EAAE,GACF,EAAE,aAAa,MAAM,aAAa;GACtC,SAAS,MAAM;GAChB;EACF"}
|
|
@@ -375,11 +375,11 @@ function childRefProblem(node, ref, ownId) {
|
|
|
375
375
|
const isDynamic = (value) => isPathBinding(value) || require_is_record.isRecord(value) && "@call" in value;
|
|
376
376
|
const visit = (value, steps) => {
|
|
377
377
|
if (isDynamic(value)) return void 0;
|
|
378
|
-
|
|
378
|
+
const [head, ...rest] = steps;
|
|
379
|
+
if (head === void 0) {
|
|
379
380
|
const reason = slotProblem(value, ref.kind, ownId);
|
|
380
381
|
return reason ? `${label}: ${reason}` : void 0;
|
|
381
382
|
}
|
|
382
|
-
const [head, ...rest] = steps;
|
|
383
383
|
if (head === "*") {
|
|
384
384
|
if (!Array.isArray(value)) return void 0;
|
|
385
385
|
for (const item of value) {
|