@assistant-ui/react-generative-ui 0.0.19 → 0.0.20
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/JSONGenerativeUI.client.d.ts +14 -15
- package/dist/JSONGenerativeUI.client.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.client.js +28 -8
- package/dist/JSONGenerativeUI.client.js.map +1 -1
- package/dist/JSONGenerativeUI.server.d.ts +5 -7
- package/dist/JSONGenerativeUI.server.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.shared.d.ts +35 -36
- package/dist/JSONGenerativeUI.shared.d.ts.map +1 -1
- package/dist/a2ui/convert.d.ts +7 -7
- package/dist/a2ui/convert.d.ts.map +1 -1
- package/dist/a2ui/convert.js +115 -16
- package/dist/a2ui/convert.js.map +1 -1
- package/dist/a2ui/reducer.d.ts +1 -3
- package/dist/a2ui/reducer.d.ts.map +1 -1
- package/dist/a2ui/reducer.js +8 -0
- package/dist/a2ui/reducer.js.map +1 -1
- package/dist/a2ui/snapshot.d.ts +3 -0
- package/dist/a2ui/snapshot.d.ts.map +1 -0
- package/dist/a2ui/snapshot.js +33 -0
- package/dist/a2ui/snapshot.js.map +1 -0
- package/dist/a2ui/types.d.ts +50 -40
- package/dist/a2ui/types.d.ts.map +1 -1
- package/dist/a2ui/types.js.map +1 -1
- package/dist/a2ui.d.ts +5 -4
- package/dist/a2ui.d.ts.map +1 -0
- package/dist/a2ui.js +2 -1
- package/dist/actionRegistry.d.ts +12 -14
- package/dist/actionRegistry.d.ts.map +1 -1
- package/dist/actionRegistry.js.map +1 -1
- package/dist/buildPresentParameters.d.ts +2 -4
- package/dist/buildPresentParameters.d.ts.map +1 -1
- package/dist/buildPresentParameters.js +16 -4
- package/dist/buildPresentParameters.js.map +1 -1
- package/dist/constants.d.ts +0 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/convert/boundSpec.d.ts +0 -2
- package/dist/convert/boundSpec.d.ts.map +1 -1
- package/dist/convert/copyBounded.d.ts +2 -4
- package/dist/convert/copyBounded.d.ts.map +1 -1
- package/dist/convert/isElement.d.ts +1 -3
- package/dist/convert/isElement.d.ts.map +1 -1
- package/dist/convert/takeRun.d.ts +3 -5
- package/dist/convert/takeRun.d.ts.map +1 -1
- package/dist/defineGenerativeComponents.d.ts +1 -3
- package/dist/defineGenerativeComponents.d.ts.map +1 -1
- package/dist/generativeUIToJSX.d.ts +4 -6
- package/dist/generativeUIToJSX.d.ts.map +1 -1
- package/dist/index.d.ts +3 -13
- package/dist/index.d.ts.map +1 -0
- package/dist/index.server.d.ts +3 -13
- package/dist/index.server.d.ts.map +1 -0
- package/dist/index.shared.d.ts +15 -11
- package/dist/index.shared.d.ts.map +1 -0
- package/dist/ir.d.ts +17 -19
- package/dist/ir.d.ts.map +1 -1
- package/dist/renderGenerativeUI.d.ts +2 -4
- package/dist/renderGenerativeUI.d.ts.map +1 -1
- package/dist/scopeSchema.d.ts +6 -0
- package/dist/scopeSchema.d.ts.map +1 -0
- package/dist/scopeSchema.js +56 -0
- package/dist/scopeSchema.js.map +1 -0
- package/dist/slack/constants.d.ts +8 -9
- package/dist/slack/constants.d.ts.map +1 -1
- package/dist/slack/decodeBlockAction.d.ts +1 -3
- package/dist/slack/decodeBlockAction.d.ts.map +1 -1
- package/dist/slack/fromSlackBlocks.d.ts +1 -3
- package/dist/slack/fromSlackBlocks.d.ts.map +1 -1
- package/dist/slack/toSlackBlocks.d.ts +1 -3
- package/dist/slack/toSlackBlocks.d.ts.map +1 -1
- package/dist/slack/toSlackBlocks.js +1 -1
- package/dist/slack/types.d.ts +78 -80
- package/dist/slack/types.d.ts.map +1 -1
- package/dist/slack.d.ts +5 -5
- package/dist/slack.d.ts.map +1 -0
- package/dist/teams/constants.d.ts +1 -3
- package/dist/teams/constants.d.ts.map +1 -1
- package/dist/teams/decodeSubmitData.d.ts +1 -3
- package/dist/teams/decodeSubmitData.d.ts.map +1 -1
- package/dist/teams/toAdaptiveCard.d.ts +4 -6
- package/dist/teams/toAdaptiveCard.d.ts.map +1 -1
- package/dist/teams/toTeamsAttachments.d.ts +1 -3
- package/dist/teams/toTeamsAttachments.d.ts.map +1 -1
- package/dist/teams/types.d.ts +108 -109
- package/dist/teams/types.d.ts.map +1 -1
- package/dist/teams.d.ts +5 -5
- package/dist/teams.d.ts.map +1 -0
- package/dist/types.d.ts +36 -37
- package/dist/types.d.ts.map +1 -1
- package/dist/vocabulary/alert.d.ts +21 -23
- package/dist/vocabulary/alert.d.ts.map +1 -1
- package/dist/vocabulary/collectFormValues.d.ts +8 -10
- package/dist/vocabulary/collectFormValues.d.ts.map +1 -1
- package/dist/vocabulary/data.d.ts +45 -47
- package/dist/vocabulary/data.d.ts.map +1 -1
- package/dist/vocabulary/dispatch.d.ts +2 -4
- package/dist/vocabulary/dispatch.d.ts.map +1 -1
- package/dist/vocabulary/fact.d.ts +8 -10
- package/dist/vocabulary/fact.d.ts.map +1 -1
- package/dist/vocabulary/form.d.ts +7 -9
- package/dist/vocabulary/form.d.ts.map +1 -1
- package/dist/vocabulary/icon.d.ts +37 -39
- package/dist/vocabulary/icon.d.ts.map +1 -1
- package/dist/vocabulary/index.d.ts +1 -3
- package/dist/vocabulary/index.d.ts.map +1 -1
- package/dist/vocabulary/interactive.d.ts +87 -86
- package/dist/vocabulary/interactive.d.ts.map +1 -1
- package/dist/vocabulary/interactive.js +4 -4
- package/dist/vocabulary/interactive.js.map +1 -1
- package/dist/vocabulary/layout.d.ts +75 -77
- package/dist/vocabulary/layout.d.ts.map +1 -1
- package/dist/vocabulary/list.d.ts +10 -12
- package/dist/vocabulary/list.d.ts.map +1 -1
- package/dist/vocabulary/media.d.ts +21 -23
- package/dist/vocabulary/media.d.ts.map +1 -1
- package/dist/vocabulary/text.d.ts +53 -55
- package/dist/vocabulary/text.d.ts.map +1 -1
- package/dist/vocabulary/toTextContent.d.ts +0 -2
- package/dist/vocabulary/toTextContent.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/JSONGenerativeUI.client.tsx +57 -15
- package/src/JSONGenerativeUI.test.tsx +298 -4
- package/src/a2ui/convert.test.ts +496 -0
- package/src/a2ui/convert.ts +170 -25
- package/src/a2ui/reducer.test.ts +18 -0
- package/src/a2ui/reducer.ts +16 -0
- package/src/a2ui/snapshot.test.ts +52 -0
- package/src/a2ui/snapshot.ts +52 -0
- package/src/a2ui/types.ts +16 -0
- package/src/a2ui.ts +2 -0
- package/src/actionRegistry.ts +5 -5
- package/src/buildPresentParameters.test.ts +246 -0
- package/src/buildPresentParameters.ts +18 -3
- package/src/scopeSchema.test.ts +72 -0
- package/src/scopeSchema.ts +71 -0
- package/src/vocabulary/interactive.dispatch.test.tsx +17 -3
- package/src/vocabulary/interactive.test.tsx +19 -0
- package/src/vocabulary/interactive.tsx +4 -1
package/dist/a2ui/convert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.js","names":[],"sources":["../../src/a2ui/convert.ts"],"sourcesContent":["import type { UIElement } from \"../ir\";\nimport {\n A2UI_SURFACE_ID,\n type A2uiSurfaceState,\n type A2uiTemplateChildren,\n} from \"./types\";\n\nconst DEPTH_CAP = 32;\nconst TEMPLATE_ITEM_CAP = 100;\nconst NODE_BUDGET = 5000;\n\nconst SUPPORTED_COMPONENTS = new Set([\n \"Text\",\n \"Image\",\n \"Row\",\n \"Column\",\n \"Card\",\n \"Divider\",\n \"Button\",\n \"TextField\",\n \"CheckBox\",\n]);\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n if (!isRecord(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\nconst setOwnProperty = (\n target: Record<string, unknown>,\n key: string,\n value: unknown,\n) => {\n if (key === \"__proto__\") {\n Object.defineProperty(target, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n } else {\n target[key] = value;\n }\n};\n\nconst isBinding = (value: unknown): value is { readonly path: string } =>\n isPlainObject(value) &&\n Object.keys(value).length === 1 &&\n typeof value[\"path\"] === \"string\";\n\nconst isTemplateChildren = (value: unknown): value is A2uiTemplateChildren =>\n isPlainObject(value) &&\n Object.keys(value).length === 1 &&\n isPlainObject(value[\"template\"]) &&\n Object.keys(value[\"template\"]).length === 2 &&\n typeof value[\"template\"][\"componentId\"] === \"string\" &&\n typeof value[\"template\"][\"path\"] === \"string\";\n\nconst decodePointer = (path: string): string[] | undefined => {\n if (path === \"\" || path === \"/\") return [];\n if (!path.startsWith(\"/\")) return undefined;\n return path\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n};\n\nconst resolvePointer = (source: unknown, path: string): unknown => {\n const segments = decodePointer(path);\n if (!segments) return undefined;\n let current = source;\n for (const segment of segments) {\n if (Array.isArray(current)) {\n if (!/^(0|[1-9]\\d*)$/.test(segment)) return undefined;\n current = current[Number(segment)];\n continue;\n }\n if (!isRecord(current) || !Object.hasOwn(current, segment)) {\n return undefined;\n }\n current = current[segment];\n }\n return current;\n};\n\nconst bindingPath = (value: unknown): string | undefined =>\n isBinding(value) ? value.path : undefined;\n\nconst lastPointerSegment = (path: string | undefined): string | undefined => {\n if (!path) return undefined;\n const segments = decodePointer(path);\n return segments?.at(-1);\n};\n\nconst materialize = (value: unknown, source: unknown): unknown => {\n if (isBinding(value)) return resolvePointer(source, value.path);\n if (Array.isArray(value)) {\n return value\n .map((entry) => materialize(entry, source))\n .filter((entry) => entry !== undefined);\n }\n if (!isPlainObject(value)) return value;\n const result: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n const resolved = materialize(entry, source);\n if (resolved !== undefined) {\n setOwnProperty(result, key, resolved);\n }\n }\n return result;\n};\n\nconst firstDefined = (\n props: Record<string, unknown>,\n keys: readonly string[],\n): unknown => {\n for (const key of keys) {\n if (props[key] !== undefined) return props[key];\n }\n return undefined;\n};\n\nconst stringProp = (\n props: Record<string, unknown>,\n keys: readonly string[],\n): string | undefined => {\n const value = firstDefined(props, keys);\n return typeof value === \"string\" ? value : undefined;\n};\n\nconst sourceSurfaceId = (surface: A2uiSurfaceState): string =>\n (surface as A2uiSurfaceState & { [A2UI_SURFACE_ID]?: string })[\n A2UI_SURFACE_ID\n ] ?? \"\";\n\ntype ConversionContext = {\n readonly surface: A2uiSurfaceState;\n readonly surfaceId: string;\n readonly warnings: string[];\n emittedNodes: number;\n depthWarned: boolean;\n budgetWarned: boolean;\n templateCapWarned: boolean;\n};\n\nconst reserveNode = (context: ConversionContext): boolean => {\n if (context.emittedNodes >= NODE_BUDGET) {\n if (!context.budgetWarned) {\n context.warnings.push(`A2UI node budget of ${NODE_BUDGET} was reached.`);\n context.budgetWarned = true;\n }\n return false;\n }\n context.emittedNodes++;\n return true;\n};\n\nconst childrenOf = (\n node: Record<string, unknown>,\n dataSource: unknown,\n context: ConversionContext,\n depth: number,\n visited: Set<string>,\n): UIElement[] => {\n const children = node[\"children\"];\n if (!Array.isArray(children)) return [];\n const result: UIElement[] = [];\n for (const childId of children) {\n if (typeof childId !== \"string\") {\n context.warnings.push(\n `Component \"${String(node[\"id\"] ?? \"\")}\" has a malformed child reference.`,\n );\n continue;\n }\n const child = convertComponent(\n childId,\n dataSource,\n context,\n depth + 1,\n visited,\n );\n if (child) result.push(child);\n }\n return result;\n};\n\nconst mappedAction = (\n node: Record<string, unknown>,\n props: Record<string, unknown>,\n dataSource: unknown,\n context: ConversionContext,\n): UIElement[\"$action\"] | undefined => {\n const action = props[\"action\"];\n const actionName =\n typeof action === \"string\"\n ? action\n : isRecord(action) && typeof action[\"name\"] === \"string\"\n ? action[\"name\"]\n : undefined;\n if (!actionName) return undefined;\n const rawContext = isRecord(action) ? action[\"context\"] : undefined;\n const resolvedContext =\n rawContext === undefined ? undefined : materialize(rawContext, dataSource);\n return {\n type: \"a2ui:action\",\n name: actionName,\n surfaceId: context.surfaceId,\n sourceComponentId: typeof node[\"id\"] === \"string\" ? node[\"id\"] : \"\",\n ...(resolvedContext !== undefined ? { context: resolvedContext } : {}),\n };\n};\n\nconst mappedProps = (\n node: Record<string, unknown>,\n props: Record<string, unknown>,\n dataSource: unknown,\n context: ConversionContext,\n): UIElement | undefined => {\n const component = node[\"component\"];\n\n if (component === \"Text\") {\n const text = stringProp(props, [\"text\", \"value\"]);\n const variant = props[\"variant\"];\n if (typeof variant === \"string\" && /^h[1-6]$/.test(variant)) {\n return {\n $type: \"Header\",\n ...(text !== undefined ? { text } : {}),\n };\n }\n if (variant === \"caption\") {\n return {\n $type: \"Caption\",\n ...(text !== undefined ? { value: text } : {}),\n };\n }\n return {\n $type: \"Markdown\",\n ...(text !== undefined ? { value: text } : {}),\n };\n }\n\n if (component === \"Image\") {\n const src = stringProp(props, [\"src\", \"url\"]);\n const alt = stringProp(props, [\"alt\", \"altText\"]);\n const size = props[\"size\"];\n const round = props[\"round\"];\n return {\n $type: \"Image\",\n ...(src !== undefined ? { src } : {}),\n ...(alt !== undefined ? { alt } : {}),\n ...(typeof size === \"string\" || typeof size === \"number\" ? { size } : {}),\n ...(typeof round === \"boolean\" ? { round } : {}),\n };\n }\n\n if (component === \"Row\") {\n const gap = props[\"gap\"];\n const align = firstDefined(props, [\"align\", \"alignment\"]);\n const justify = firstDefined(props, [\"justify\", \"distribution\"]);\n return {\n $type: \"Row\",\n ...(typeof gap === \"number\" ? { gap } : {}),\n ...(typeof align === \"string\" ? { align } : {}),\n ...(typeof justify === \"string\" ? { justify } : {}),\n };\n }\n\n if (component === \"Column\") {\n const gap = props[\"gap\"];\n const align = firstDefined(props, [\"align\", \"alignment\"]);\n return {\n $type: \"Col\",\n ...(typeof gap === \"number\" ? { gap } : {}),\n ...(typeof align === \"string\" ? { align } : {}),\n };\n }\n\n if (component === \"Card\") {\n const title = props[\"title\"];\n const padding = props[\"padding\"];\n const background = props[\"background\"];\n return {\n $type: \"Card\",\n ...(typeof title === \"string\" ? { title } : {}),\n ...(typeof padding === \"number\" ? { padding } : {}),\n ...(typeof background === \"string\" ? { background } : {}),\n };\n }\n\n if (component === \"Divider\") {\n return {\n $type: \"Divider\",\n ...(typeof props[\"flush\"] === \"boolean\" ? { flush: props[\"flush\"] } : {}),\n };\n }\n\n if (component === \"Button\") {\n const label = stringProp(props, [\"label\", \"text\"]);\n const buttonStyle = props[\"buttonStyle\"];\n const block = props[\"block\"];\n const submit = props[\"submit\"];\n const action = mappedAction(node, props, dataSource, context);\n return {\n $type: \"Button\",\n ...(label !== undefined ? { label } : {}),\n ...(typeof buttonStyle === \"string\" ? { buttonStyle } : {}),\n ...(typeof block === \"boolean\" ? { block } : {}),\n ...(typeof submit === \"boolean\" ? { submit } : {}),\n ...(action ? { $action: action } : {}),\n };\n }\n\n const binding = firstDefined(node, [\"text\", \"value\", \"binding\"]);\n const name = lastPointerSegment(bindingPath(binding));\n const label = stringProp(props, [\"label\"]);\n\n if (component === \"TextField\") {\n const placeholder = stringProp(props, [\"placeholder\"]);\n const multiline =\n typeof props[\"multiline\"] === \"boolean\"\n ? props[\"multiline\"]\n : props[\"textFieldType\"] === \"longText\"\n ? true\n : undefined;\n return {\n $type: \"Input\",\n ...(placeholder !== undefined ? { placeholder } : {}),\n ...(multiline !== undefined ? { multiline } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n };\n }\n\n if (component === \"CheckBox\") {\n const defaultChecked = firstDefined(props, [\"defaultChecked\", \"value\"]);\n return {\n $type: \"Checkbox\",\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n ...(typeof defaultChecked === \"boolean\" ? { defaultChecked } : {}),\n };\n }\n\n return undefined;\n};\n\nconst convertTemplate = (\n node: Record<string, unknown>,\n templateChildren: A2uiTemplateChildren,\n dataSource: unknown,\n context: ConversionContext,\n depth: number,\n visited: Set<string>,\n): UIElement | null => {\n if (!reserveNode(context)) return null;\n const list = resolvePointer(dataSource, templateChildren.template.path);\n if (!Array.isArray(list)) {\n context.warnings.push(\n `Template on component \"${String(node[\"id\"] ?? \"\")}\" did not resolve to a list.`,\n );\n return { $type: \"ListView\", children: [] };\n }\n const itemCount = Math.min(list.length, TEMPLATE_ITEM_CAP);\n if (list.length > TEMPLATE_ITEM_CAP && !context.templateCapWarned) {\n context.warnings.push(\n `A2UI template expansion was capped at ${TEMPLATE_ITEM_CAP} items.`,\n );\n context.templateCapWarned = true;\n }\n const children: UIElement[] = [];\n for (let index = 0; index < itemCount; index++) {\n if (!reserveNode(context)) break;\n const child = convertComponent(\n templateChildren.template.componentId,\n list[index],\n context,\n depth + 1,\n visited,\n );\n children.push({\n $type: \"ListViewItem\",\n ...(child ? { children: child } : {}),\n });\n }\n return { $type: \"ListView\", children };\n};\n\nfunction convertComponent(\n componentId: string,\n dataSource: unknown,\n context: ConversionContext,\n depth: number,\n visited: Set<string>,\n): UIElement | null {\n if (depth >= DEPTH_CAP) {\n if (!context.depthWarned) {\n context.warnings.push(`A2UI depth cap of ${DEPTH_CAP} was reached.`);\n context.depthWarned = true;\n }\n return null;\n }\n if (visited.has(componentId)) {\n context.warnings.push(`A2UI component cycle detected at \"${componentId}\".`);\n return null;\n }\n const node = context.surface.components.get(componentId);\n if (!node) {\n context.warnings.push(`A2UI component \"${componentId}\" was not found.`);\n return null;\n }\n const component = node[\"component\"];\n\n visited.add(componentId);\n try {\n const templateChildren = node[\"children\"];\n if (isTemplateChildren(templateChildren)) {\n return convertTemplate(\n node,\n templateChildren,\n dataSource,\n context,\n depth,\n visited,\n );\n }\n if (typeof component !== \"string\" || !SUPPORTED_COMPONENTS.has(component)) {\n context.warnings.push(\n `Unknown A2UI component \"${String(component ?? \"\")}\" was skipped.`,\n );\n return null;\n }\n if (!reserveNode(context)) return null;\n const props: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\" || key === \"children\") continue;\n const resolved = materialize(value, dataSource);\n if (resolved !== undefined) setOwnProperty(props, key, resolved);\n }\n const mapped = mappedProps(node, props, dataSource, context);\n if (!mapped) return null;\n const children = childrenOf(node, dataSource, context, depth, visited);\n return {\n ...mapped,\n ...(children.length > 0 ? { children } : {}),\n };\n } finally {\n visited.delete(componentId);\n }\n}\n\nexport function convertSurfaceToUISpec(surface: A2uiSurfaceState): {\n spec: UIElement | null;\n warnings: string[];\n} {\n const warnings: string[] = [];\n if (!surface.components.has(\"root\")) {\n return {\n spec: null,\n warnings: ['A2UI root component \"root\" was not found.'],\n };\n }\n const context: ConversionContext = {\n surface,\n surfaceId: sourceSurfaceId(surface),\n warnings,\n emittedNodes: 0,\n depthWarned: false,\n budgetWarned: false,\n templateCapWarned: false,\n };\n try {\n const spec = convertComponent(\n \"root\",\n surface.dataModel,\n context,\n 0,\n new Set(),\n );\n return { spec, warnings };\n } catch {\n warnings.push(\"A2UI surface conversion encountered malformed input.\");\n return { spec: null, warnings };\n }\n}\n"],"mappings":";;AAOA,MAAM,YAAY;AAClB,MAAM,oBAAoB;AAC1B,MAAM,cAAc;AAEpB,MAAM,uCAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAErE,MAAM,iBAAiB,UAAqD;CAC1E,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO;CAC7B,MAAM,YAAY,OAAO,eAAe,KAAK;CAC7C,OAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAEA,MAAM,kBACJ,QACA,KACA,UACG;CACH,IAAI,QAAQ,aACV,OAAO,eAAe,QAAQ,KAAK;EACjC;EACA,YAAY;EACZ,cAAc;EACd,UAAU;CACZ,CAAC;MAED,OAAO,OAAO;AAElB;AAEA,MAAM,aAAa,UACjB,cAAc,KAAK,KACnB,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAC9B,OAAO,MAAM,YAAY;AAE3B,MAAM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F,OAAO;GAAE,MAPI,iBACX,QACA,QAAQ,WACR,SACA,mBACA,IAAI,IAAI,CAEE;GAAG;EAAS;CAC1B,QAAQ;EACN,SAAS,KAAK,sDAAsD;EACpE,OAAO;GAAE,MAAM;GAAM;EAAS;CAChC;AACF"}
|
|
1
|
+
{"version":3,"file":"convert.js","names":[],"sources":["../../src/a2ui/convert.ts"],"sourcesContent":["import { ICON_NAMES, type UIElement } from \"../ir\";\nimport {\n A2UI_SURFACE_ID,\n type A2uiSurfaceState,\n type A2uiTemplateChildren,\n} from \"./types\";\n\nconst DEPTH_CAP = 32;\nconst TEMPLATE_ITEM_CAP = 100;\nconst NODE_BUDGET = 5000;\n\nconst SUPPORTED_COMPONENTS = new Set([\n \"Text\",\n \"Image\",\n \"Icon\",\n \"Row\",\n \"Column\",\n \"List\",\n \"Card\",\n \"Divider\",\n \"Button\",\n \"TextField\",\n \"CheckBox\",\n \"ChoicePicker\",\n \"DateTimeInput\",\n]);\n\nconst ICON_NAME_SET: ReadonlySet<string> = new Set(ICON_NAMES);\nconst ICON_SIZE_SET: ReadonlySet<string> = new Set([\"sm\", \"md\", \"lg\"]);\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n if (!isRecord(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\nconst setOwnProperty = (\n target: Record<string, unknown>,\n key: string,\n value: unknown,\n) => {\n if (key === \"__proto__\") {\n Object.defineProperty(target, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n } else {\n target[key] = value;\n }\n};\n\nconst isBinding = (value: unknown): value is { readonly path: string } =>\n isPlainObject(value) &&\n Object.keys(value).length === 1 &&\n typeof value[\"path\"] === \"string\";\n\nconst isTemplateChildren = (value: unknown): value is A2uiTemplateChildren =>\n isPlainObject(value) &&\n Object.keys(value).length === 1 &&\n isPlainObject(value[\"template\"]) &&\n Object.keys(value[\"template\"]).length === 2 &&\n typeof value[\"template\"][\"componentId\"] === \"string\" &&\n typeof value[\"template\"][\"path\"] === \"string\";\n\nconst decodePointer = (path: string): string[] | undefined => {\n if (path === \"\" || path === \"/\") return [];\n if (!path.startsWith(\"/\")) return undefined;\n return path\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n};\n\nconst resolvePointer = (source: unknown, path: string): unknown => {\n const segments = decodePointer(path);\n if (!segments) return undefined;\n let current = source;\n for (const segment of segments) {\n if (Array.isArray(current)) {\n if (!/^(0|[1-9]\\d*)$/.test(segment)) return undefined;\n current = current[Number(segment)];\n continue;\n }\n if (!isRecord(current) || !Object.hasOwn(current, segment)) {\n return undefined;\n }\n current = current[segment];\n }\n return current;\n};\n\nconst bindingPath = (value: unknown): string | undefined =>\n isBinding(value) ? value.path : undefined;\n\nconst lastPointerSegment = (path: string | undefined): string | undefined => {\n if (!path) return undefined;\n const segments = decodePointer(path);\n return segments?.at(-1);\n};\n\nconst materialize = (value: unknown, source: unknown): unknown => {\n if (isBinding(value)) return resolvePointer(source, value.path);\n if (Array.isArray(value)) {\n return value\n .map((entry) => materialize(entry, source))\n .filter((entry) => entry !== undefined);\n }\n if (!isPlainObject(value)) return value;\n const result: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n const resolved = materialize(entry, source);\n if (resolved !== undefined) {\n setOwnProperty(result, key, resolved);\n }\n }\n return result;\n};\n\nconst firstDefined = (\n props: Record<string, unknown>,\n keys: readonly string[],\n): unknown => {\n for (const key of keys) {\n if (props[key] !== undefined) return props[key];\n }\n return undefined;\n};\n\nconst stringProp = (\n props: Record<string, unknown>,\n keys: readonly string[],\n): string | undefined => {\n const value = firstDefined(props, keys);\n return typeof value === \"string\" ? value : undefined;\n};\n\nconst sourceSurfaceId = (surface: A2uiSurfaceState): string =>\n (surface as A2uiSurfaceState & { [A2UI_SURFACE_ID]?: string })[\n A2UI_SURFACE_ID\n ] ?? \"\";\n\ntype ConversionContext = {\n readonly surface: A2uiSurfaceState;\n readonly surfaceId: string;\n readonly warnings: string[];\n emittedNodes: number;\n depthWarned: boolean;\n budgetWarned: boolean;\n templateCapWarned: boolean;\n readonly keepUnknownComponents: boolean;\n};\n\nconst reserveNode = (context: ConversionContext): boolean => {\n if (context.emittedNodes >= NODE_BUDGET) {\n if (!context.budgetWarned) {\n context.warnings.push(`A2UI node budget of ${NODE_BUDGET} was reached.`);\n context.budgetWarned = true;\n }\n return false;\n }\n context.emittedNodes++;\n return true;\n};\n\nconst childrenOf = (\n node: Record<string, unknown>,\n dataSource: unknown,\n context: ConversionContext,\n depth: number,\n visited: Set<string>,\n): UIElement[] => {\n const children = node[\"children\"];\n if (!Array.isArray(children)) return [];\n const result: UIElement[] = [];\n for (const childId of children) {\n if (typeof childId !== \"string\") {\n context.warnings.push(\n `Component \"${String(node[\"id\"] ?? \"\")}\" has a malformed child reference.`,\n );\n continue;\n }\n const child = convertComponent(\n childId,\n dataSource,\n context,\n depth + 1,\n visited,\n );\n if (child) result.push(child);\n }\n return result;\n};\n\nconst mappedAction = (\n node: Record<string, unknown>,\n props: Record<string, unknown>,\n dataSource: unknown,\n context: ConversionContext,\n): UIElement[\"$action\"] | undefined => {\n const action = props[\"action\"];\n const actionName =\n typeof action === \"string\"\n ? action\n : isRecord(action) && typeof action[\"name\"] === \"string\"\n ? action[\"name\"]\n : undefined;\n if (!actionName) return undefined;\n const rawContext = isRecord(action) ? action[\"context\"] : undefined;\n const resolvedContext =\n rawContext === undefined ? undefined : materialize(rawContext, dataSource);\n return {\n type: \"a2ui:action\",\n name: actionName,\n surfaceId: context.surfaceId,\n sourceComponentId: typeof node[\"id\"] === \"string\" ? node[\"id\"] : \"\",\n ...(resolvedContext !== undefined ? { context: resolvedContext } : {}),\n };\n};\n\nconst choiceOptions = (value: unknown): { label: string; value: string }[] => {\n if (!Array.isArray(value)) return [];\n const options: { label: string; value: string }[] = [];\n for (const option of value) {\n if (\n isRecord(option) &&\n typeof option[\"label\"] === \"string\" &&\n typeof option[\"value\"] === \"string\"\n ) {\n options.push({ label: option[\"label\"], value: option[\"value\"] });\n }\n }\n return options;\n};\n\nconst mappedProps = (\n node: Record<string, unknown>,\n props: Record<string, unknown>,\n dataSource: unknown,\n context: ConversionContext,\n): UIElement | undefined => {\n const component = node[\"component\"];\n\n if (component === \"Text\") {\n const text = stringProp(props, [\"text\", \"value\"]);\n const variant = props[\"variant\"];\n if (typeof variant === \"string\" && /^h[1-6]$/.test(variant)) {\n return {\n $type: \"Header\",\n ...(text !== undefined ? { text } : {}),\n };\n }\n if (variant === \"caption\") {\n return {\n $type: \"Caption\",\n ...(text !== undefined ? { value: text } : {}),\n };\n }\n return {\n $type: \"Markdown\",\n ...(text !== undefined ? { value: text } : {}),\n };\n }\n\n if (component === \"Image\") {\n const src = stringProp(props, [\"src\", \"url\"]);\n const alt = stringProp(props, [\"alt\", \"altText\", \"description\"]);\n const size = props[\"size\"];\n const round = props[\"round\"];\n return {\n $type: \"Image\",\n ...(src !== undefined ? { src } : {}),\n ...(alt !== undefined ? { alt } : {}),\n ...(typeof size === \"string\" || typeof size === \"number\" ? { size } : {}),\n ...(typeof round === \"boolean\" ? { round } : {}),\n };\n }\n\n if (component === \"Icon\") {\n const name = stringProp(props, [\"name\"]);\n if (!name || !ICON_NAME_SET.has(name)) return undefined;\n const size = props[\"size\"];\n return {\n $type: \"Icon\",\n name,\n ...(typeof size === \"string\" && ICON_SIZE_SET.has(size) ? { size } : {}),\n };\n }\n\n if (component === \"Row\") {\n const gap = props[\"gap\"];\n const align = firstDefined(props, [\"align\", \"alignment\"]);\n const justify = firstDefined(props, [\"justify\", \"distribution\"]);\n return {\n $type: \"Row\",\n ...(typeof gap === \"number\" ? { gap } : {}),\n ...(typeof align === \"string\" ? { align } : {}),\n ...(typeof justify === \"string\" ? { justify } : {}),\n };\n }\n\n if (component === \"Column\") {\n const gap = props[\"gap\"];\n const align = firstDefined(props, [\"align\", \"alignment\"]);\n return {\n $type: \"Col\",\n ...(typeof gap === \"number\" ? { gap } : {}),\n ...(typeof align === \"string\" ? { align } : {}),\n };\n }\n\n if (component === \"List\") {\n const direction = props[\"direction\"];\n const align = props[\"align\"];\n if (direction === \"horizontal\") {\n return {\n $type: \"Row\",\n ...(typeof align === \"string\" ? { align } : {}),\n };\n }\n return { $type: \"ListView\" };\n }\n\n if (component === \"Card\") {\n const title = props[\"title\"];\n const padding = props[\"padding\"];\n const background = props[\"background\"];\n return {\n $type: \"Card\",\n ...(typeof title === \"string\" ? { title } : {}),\n ...(typeof padding === \"number\" ? { padding } : {}),\n ...(typeof background === \"string\" ? { background } : {}),\n };\n }\n\n if (component === \"Divider\") {\n return {\n $type: \"Divider\",\n ...(typeof props[\"flush\"] === \"boolean\" ? { flush: props[\"flush\"] } : {}),\n };\n }\n\n if (component === \"Button\") {\n const label = stringProp(props, [\"label\", \"text\"]);\n const buttonStyle = props[\"buttonStyle\"];\n const block = props[\"block\"];\n const submit = props[\"submit\"];\n const action = mappedAction(node, props, dataSource, context);\n return {\n $type: \"Button\",\n ...(label !== undefined ? { label } : {}),\n ...(typeof buttonStyle === \"string\" ? { buttonStyle } : {}),\n ...(typeof block === \"boolean\" ? { block } : {}),\n ...(typeof submit === \"boolean\" ? { submit } : {}),\n ...(action ? { $action: action } : {}),\n };\n }\n\n const binding = firstDefined(node, [\"text\", \"value\", \"binding\"]);\n const name = lastPointerSegment(bindingPath(binding));\n const label = stringProp(props, [\"label\"]);\n\n if (component === \"TextField\") {\n const placeholder = stringProp(props, [\"placeholder\"]);\n const multiline =\n typeof props[\"multiline\"] === \"boolean\"\n ? props[\"multiline\"]\n : props[\"textFieldType\"] === \"longText\"\n ? true\n : undefined;\n return {\n $type: \"Input\",\n ...(placeholder !== undefined ? { placeholder } : {}),\n ...(multiline !== undefined ? { multiline } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n };\n }\n\n if (component === \"CheckBox\") {\n const defaultChecked = firstDefined(props, [\"defaultChecked\", \"value\"]);\n return {\n $type: \"Checkbox\",\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n ...(typeof defaultChecked === \"boolean\" ? { defaultChecked } : {}),\n };\n }\n\n if (component === \"ChoicePicker\") {\n const options = choiceOptions(props[\"options\"]);\n const value = props[\"value\"];\n const defaultValue =\n typeof value === \"string\"\n ? value\n : Array.isArray(value) && typeof value[0] === \"string\"\n ? value[0]\n : undefined;\n const radioStyle =\n props[\"variant\"] === \"radio\" ||\n props[\"variant\"] === \"single\" ||\n props[\"variant\"] === \"singleSelection\" ||\n props[\"displayStyle\"] === \"radio\" ||\n (props[\"variant\"] === \"mutuallyExclusive\" &&\n props[\"displayStyle\"] !== \"chips\");\n if (radioStyle) {\n return {\n $type: \"RadioGroup\",\n options,\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n ...(defaultValue !== undefined ? { defaultValue } : {}),\n };\n }\n const placeholder = stringProp(props, [\"placeholder\"]);\n return {\n $type: \"Select\",\n options,\n ...(placeholder !== undefined ? { placeholder } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n };\n }\n\n if (component === \"DateTimeInput\") {\n const value = stringProp(props, [\"value\"]);\n const min = stringProp(props, [\"min\"]);\n const max = stringProp(props, [\"max\"]);\n return {\n $type: \"DatePicker\",\n ...(value !== undefined ? { value } : {}),\n ...(min !== undefined ? { min } : {}),\n ...(max !== undefined ? { max } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(name !== undefined ? { name } : {}),\n };\n }\n\n return undefined;\n};\n\nconst convertTemplate = (\n node: Record<string, unknown>,\n templateChildren: A2uiTemplateChildren,\n dataSource: unknown,\n context: ConversionContext,\n depth: number,\n visited: Set<string>,\n retained?: UIElement,\n mappedContainer?: UIElement,\n): UIElement | null => {\n if (!reserveNode(context)) return null;\n const horizontalList =\n node[\"component\"] === \"List\" &&\n materialize(node[\"direction\"], dataSource) === \"horizontal\";\n const container = mappedContainer ??\n retained ?? {\n $type: horizontalList ? \"Row\" : \"ListView\",\n };\n const list = resolvePointer(dataSource, templateChildren.template.path);\n if (!Array.isArray(list)) {\n context.warnings.push(\n `Template on component \"${String(node[\"id\"] ?? \"\")}\" did not resolve to a list.`,\n );\n return { ...container, children: [] };\n }\n const itemCount = Math.min(list.length, TEMPLATE_ITEM_CAP);\n if (list.length > TEMPLATE_ITEM_CAP && !context.templateCapWarned) {\n context.warnings.push(\n `A2UI template expansion was capped at ${TEMPLATE_ITEM_CAP} items.`,\n );\n context.templateCapWarned = true;\n }\n const children: UIElement[] = [];\n for (let index = 0; index < itemCount; index++) {\n if (!retained && !horizontalList && !reserveNode(context)) break;\n const child = convertComponent(\n templateChildren.template.componentId,\n list[index],\n context,\n depth + 1,\n visited,\n );\n if (retained || horizontalList) {\n if (child) children.push(child);\n } else {\n children.push({\n $type: \"ListViewItem\",\n ...(child ? { children: child } : {}),\n });\n }\n }\n return { ...container, children };\n};\n\nfunction convertComponent(\n componentId: string,\n dataSource: unknown,\n context: ConversionContext,\n depth: number,\n visited: Set<string>,\n): UIElement | null {\n if (depth >= DEPTH_CAP) {\n if (!context.depthWarned) {\n context.warnings.push(`A2UI depth cap of ${DEPTH_CAP} was reached.`);\n context.depthWarned = true;\n }\n return null;\n }\n if (visited.has(componentId)) {\n context.warnings.push(`A2UI component cycle detected at \"${componentId}\".`);\n return null;\n }\n const node = context.surface.components.get(componentId);\n if (!node) {\n context.warnings.push(`A2UI component \"${componentId}\" was not found.`);\n return null;\n }\n const component = node[\"component\"];\n\n visited.add(componentId);\n try {\n if (typeof component !== \"string\") {\n context.warnings.push(\n `Unknown A2UI component \"${String(component ?? \"\")}\" was skipped.`,\n );\n return null;\n }\n const templateChildren = node[\"children\"];\n const hasTemplate = isTemplateChildren(templateChildren);\n if (\n !SUPPORTED_COMPONENTS.has(component) &&\n !context.keepUnknownComponents &&\n !hasTemplate\n ) {\n context.warnings.push(\n `Unknown A2UI component \"${component}\" was skipped.`,\n );\n return null;\n }\n const props: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\" || key === \"children\") continue;\n const resolved = materialize(value, dataSource);\n if (resolved !== undefined) setOwnProperty(props, key, resolved);\n }\n const mapped = mappedProps(node, props, dataSource, context);\n if (!mapped && SUPPORTED_COMPONENTS.has(component)) {\n context.warnings.push(\n `A2UI component \"${component}\" could not be mapped and was skipped.`,\n );\n return null;\n }\n const retained =\n !mapped && context.keepUnknownComponents\n ? {\n $type: component,\n ...Object.fromEntries(\n Object.entries(props).filter(([key]) => !key.startsWith(\"$\")),\n ),\n }\n : undefined;\n if (hasTemplate) {\n return convertTemplate(\n node,\n templateChildren,\n dataSource,\n context,\n depth,\n visited,\n retained,\n component === \"List\" ? mapped : undefined,\n );\n }\n if (!reserveNode(context)) return null;\n const converted = mapped ?? retained;\n if (!converted) return null;\n const children = childrenOf(node, dataSource, context, depth, visited);\n const listChildren =\n component === \"List\" && mapped?.$type === \"ListView\"\n ? children.map((child) => ({ $type: \"ListViewItem\", children: child }))\n : children;\n return {\n ...converted,\n ...(listChildren.length > 0 ? { children: listChildren } : {}),\n };\n } finally {\n visited.delete(componentId);\n }\n}\n\nexport function convertSurfaceToUISpec(\n surface: A2uiSurfaceState,\n options: { readonly keepUnknownComponents?: boolean } = {},\n): {\n spec: UIElement | null;\n warnings: string[];\n} {\n const warnings: string[] = [];\n if (!surface.components.has(\"root\")) {\n return {\n spec: null,\n warnings: ['A2UI root component \"root\" was not found.'],\n };\n }\n const context: ConversionContext = {\n surface,\n surfaceId: sourceSurfaceId(surface),\n warnings,\n emittedNodes: 0,\n depthWarned: false,\n budgetWarned: false,\n templateCapWarned: false,\n keepUnknownComponents: options.keepUnknownComponents === true,\n };\n try {\n const spec = convertComponent(\n \"root\",\n surface.dataModel,\n context,\n 0,\n new Set(),\n );\n return { spec, warnings };\n } catch {\n warnings.push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,0BAA0B;CAC3D;CACA,IAAI;EAQF,OAAO;GAAE,MAPI,iBACX,QACA,QAAQ,WACR,SACA,mBACA,IAAI,IAAI,CAEE;GAAG;EAAS;CAC1B,QAAQ;EACN,SAAS,KAAK,sDAAsD;EACpE,OAAO;GAAE,MAAM;GAAM;EAAS;CAChC;AACF"}
|
package/dist/a2ui/reducer.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { A2uiOperationResult, A2uiState } from "./types.js";
|
|
2
|
-
//#region src/a2ui/reducer.d.ts
|
|
1
|
+
import { type A2uiOperationResult, type A2uiState } from "./types.js";
|
|
3
2
|
export declare function applyA2uiOperations(state: A2uiState, operations: unknown): A2uiOperationResult;
|
|
4
|
-
//#endregion
|
|
5
3
|
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/a2ui/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,SAAS,EAEf,mBAAgB;AAgOjB,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,OAAO,GAClB,mBAAmB,CAiIrB"}
|
package/dist/a2ui/reducer.js
CHANGED
|
@@ -14,6 +14,11 @@ const surfaceIdOf = (payload) => {
|
|
|
14
14
|
const surfaceId = payload["surfaceId"];
|
|
15
15
|
return typeof surfaceId === "string" && surfaceId.length > 0 ? surfaceId : void 0;
|
|
16
16
|
};
|
|
17
|
+
const catalogIdOf = (payload) => {
|
|
18
|
+
if (typeof payload["catalogId"] === "string") return payload["catalogId"];
|
|
19
|
+
const surfaceProperties = payload["surfaceProperties"];
|
|
20
|
+
return isRecord(surfaceProperties) && typeof surfaceProperties["catalogId"] === "string" ? surfaceProperties["catalogId"] : void 0;
|
|
21
|
+
};
|
|
17
22
|
const withSurfaceId = (surface, surfaceId) => {
|
|
18
23
|
Object.defineProperty(surface, A2UI_SURFACE_ID, {
|
|
19
24
|
value: surfaceId,
|
|
@@ -23,6 +28,7 @@ const withSurfaceId = (surface, surfaceId) => {
|
|
|
23
28
|
};
|
|
24
29
|
const getSurfaceId = (surface) => surface[A2UI_SURFACE_ID];
|
|
25
30
|
const cloneSurface = (surface, surfaceId) => withSurfaceId({
|
|
31
|
+
...surface.catalogId !== void 0 ? { catalogId: surface.catalogId } : {},
|
|
26
32
|
components: new Map(surface.components),
|
|
27
33
|
dataModel: surface.dataModel
|
|
28
34
|
}, getSurfaceId(surface) ?? surfaceId);
|
|
@@ -180,7 +186,9 @@ function applyA2uiOperations(state, operations) {
|
|
|
180
186
|
continue;
|
|
181
187
|
}
|
|
182
188
|
if (operationKey === "createSurface") {
|
|
189
|
+
const catalogId = catalogIdOf(payload);
|
|
183
190
|
const surface = withSurfaceId({
|
|
191
|
+
...catalogId !== void 0 ? { catalogId } : {},
|
|
184
192
|
components: /* @__PURE__ */ new Map(),
|
|
185
193
|
dataModel: version === "v1.0" && payload["dataModel"] !== void 0 ? payload["dataModel"] : void 0
|
|
186
194
|
}, surfaceId);
|
package/dist/a2ui/reducer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.js","names":[],"sources":["../../src/a2ui/reducer.ts"],"sourcesContent":["import {\n A2UI_SURFACE_ID,\n type A2uiOperationResult,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"./types\";\n\nconst OPERATION_KEYS = new Set([\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n]);\n// This defensive ceiling is well above the renderer's displayed-item limit.\nconst MAX_AUTO_VIVIFY_ARRAY_INDEX = 10_000;\nconst INVALID_POINTER = Symbol(\"invalidPointer\");\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isVersion = (value: unknown): value is \"v0.9\" | \"v1.0\" =>\n value === \"v0.9\" || value === \"v1.0\";\n\nconst surfaceIdOf = (payload: Record<string, unknown>): string | undefined => {\n const surfaceId = payload[\"surfaceId\"];\n return typeof surfaceId === \"string\" && surfaceId.length > 0\n ? surfaceId\n : undefined;\n};\n\nconst withSurfaceId = (\n surface: A2uiSurfaceState,\n surfaceId: string,\n): A2uiSurfaceState => {\n Object.defineProperty(surface, A2UI_SURFACE_ID, {\n value: surfaceId,\n enumerable: false,\n });\n return surface;\n};\n\nconst getSurfaceId = (surface: A2uiSurfaceState): string | undefined =>\n (surface as A2uiSurfaceState & { [A2UI_SURFACE_ID]?: string })[\n A2UI_SURFACE_ID\n ];\n\nconst cloneSurface = (\n surface: A2uiSurfaceState,\n surfaceId: string,\n): A2uiSurfaceState =>\n withSurfaceId(\n {\n components: new Map(surface.components),\n dataModel: surface.dataModel,\n },\n getSurfaceId(surface) ?? surfaceId,\n );\n\nconst upsertComponents = (\n surface: A2uiSurfaceState,\n components: unknown,\n warnings: string[],\n operationIndex: number,\n): void => {\n if (!Array.isArray(components)) {\n warnings.push(\n `Operation at index ${operationIndex} has malformed components.`,\n );\n return;\n }\n\n for (\n let componentIndex = 0;\n componentIndex < components.length;\n componentIndex++\n ) {\n const component = components[componentIndex];\n if (\n !isRecord(component) ||\n typeof component[\"id\"] !== \"string\" ||\n component[\"id\"].length === 0 ||\n typeof component[\"component\"] !== \"string\" ||\n component[\"component\"].length === 0\n ) {\n warnings.push(\n `Component at index ${componentIndex} in operation ${operationIndex} is malformed.`,\n );\n continue;\n }\n surface.components.set(component[\"id\"], { ...component });\n }\n};\n\nconst decodePointer = (path: string): string[] | undefined => {\n if (path === \"\" || path === \"/\") return [];\n if (!path.startsWith(\"/\")) return undefined;\n return path\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n};\n\nconst isArrayIndex = (segment: string): boolean =>\n segment === \"0\" || /^[1-9]\\d*$/.test(segment);\n\nconst setAtPointer = (\n model: unknown,\n path: string,\n value: unknown,\n nullDeletes: boolean,\n): { readonly ok: boolean; readonly value: unknown } => {\n const segments = decodePointer(path);\n if (!segments) return { ok: false, value: model };\n if (segments.length === 0) return { ok: true, value };\n\n const remove = (current: unknown, index: number): unknown => {\n const segment = segments[index]!;\n const isLast = index === segments.length - 1;\n\n if (Array.isArray(current)) {\n if (segment !== \"-\" && !isArrayIndex(segment)) return current;\n const targetIndex = segment === \"-\" ? current.length : Number(segment);\n if (isLast) {\n if (\n segment === \"-\" ||\n !Object.prototype.hasOwnProperty.call(current, targetIndex)\n ) {\n return current;\n }\n const clone = current.slice();\n // Preserve indices referenced by other JSON Pointers.\n delete clone[targetIndex];\n return clone;\n }\n const child = current[targetIndex];\n if (!Array.isArray(child) && !isRecord(child)) return current;\n const next = remove(child, index + 1);\n if (next === child) return current;\n const clone = current.slice();\n clone[targetIndex] = next;\n return clone;\n }\n\n if (!isRecord(current)) return current;\n if (!Object.prototype.hasOwnProperty.call(current, segment)) return current;\n if (isLast) {\n const clone = { ...current };\n delete clone[segment];\n return clone;\n }\n const child = current[segment];\n if (!Array.isArray(child) && !isRecord(child)) return current;\n const next = remove(child, index + 1);\n if (next === child) return current;\n return { ...current, [segment]: next };\n };\n\n if (nullDeletes && value === null) {\n return { ok: true, value: remove(model, 0) };\n }\n\n const update = (current: unknown, index: number): unknown => {\n const segment = segments[index]!;\n const isLast = index === segments.length - 1;\n\n if (Array.isArray(current)) {\n if (segment !== \"-\" && !isArrayIndex(segment)) return current;\n const targetIndex = segment === \"-\" ? current.length : Number(segment);\n if (\n segment !== \"-\" &&\n targetIndex >= current.length &&\n targetIndex > MAX_AUTO_VIVIFY_ARRAY_INDEX\n ) {\n return INVALID_POINTER;\n }\n const next = isLast ? value : update(current[targetIndex], index + 1);\n if (next === INVALID_POINTER) return INVALID_POINTER;\n const clone = current.slice();\n clone[targetIndex] = next;\n return clone;\n }\n\n const record: Record<string, unknown> = isRecord(current) ? current : {};\n const child = Object.hasOwn(record, segment) ? record[segment] : undefined;\n const next = isLast\n ? value\n : update(\n child ??\n (isArrayIndex(segments[index + 1] ?? \"\") ||\n segments[index + 1] === \"-\"\n ? []\n : {}),\n index + 1,\n );\n if (next === INVALID_POINTER) return INVALID_POINTER;\n return { ...record, [segment]: next };\n };\n\n const result = update(model, 0);\n return result === INVALID_POINTER\n ? { ok: false, value: model }\n : { ok: true, value: result };\n};\n\nconst dataModelValue = (\n payload: Record<string, unknown>,\n): { readonly found: boolean; readonly value: unknown } => {\n for (const key of [\"contents\", \"value\", \"data\"] as const) {\n if (payload[key] !== undefined) {\n return { found: true, value: payload[key] };\n }\n }\n return { found: false, value: undefined };\n};\n\nexport function applyA2uiOperations(\n state: A2uiState,\n operations: unknown,\n): A2uiOperationResult {\n const nextState = new Map(state);\n const warnings: string[] = [];\n\n if (!Array.isArray(operations)) {\n return {\n state: nextState,\n warnings: [\"A2UI operations must be an array.\"],\n };\n }\n\n for (let index = 0; index < operations.length; index++) {\n try {\n const entry = operations[index];\n if (!isRecord(entry)) {\n warnings.push(`Operation at index ${index} is malformed.`);\n continue;\n }\n\n const version = entry[\"version\"];\n if (!isVersion(version)) {\n warnings.push(\n `Operation at index ${index} has an unsupported version.`,\n );\n continue;\n }\n\n const operationKeys = Object.keys(entry).filter(\n (key) => key !== \"version\",\n );\n if (operationKeys.length !== 1) {\n warnings.push(\n `Operation at index ${index} must contain exactly one operation key.`,\n );\n continue;\n }\n\n const operationKey = operationKeys[0]!;\n if (!OPERATION_KEYS.has(operationKey)) {\n warnings.push(\n `Unknown A2UI operation \"${operationKey}\" at index ${index}.`,\n );\n continue;\n }\n\n const payload = entry[operationKey];\n if (!isRecord(payload)) {\n warnings.push(`Operation at index ${index} has a malformed payload.`);\n continue;\n }\n\n const surfaceId = surfaceIdOf(payload);\n if (!surfaceId) {\n warnings.push(`Operation at index ${index} has no valid surfaceId.`);\n continue;\n }\n\n if (operationKey === \"createSurface\") {\n const surface = withSurfaceId(\n {\n components: new Map(),\n dataModel:\n version === \"v1.0\" && payload[\"dataModel\"] !== undefined\n ? payload[\"dataModel\"]\n : undefined,\n },\n surfaceId,\n );\n if (version === \"v1.0\" && payload[\"components\"] !== undefined) {\n upsertComponents(surface, payload[\"components\"], warnings, index);\n }\n nextState.set(surfaceId, surface);\n continue;\n }\n\n if (operationKey === \"deleteSurface\") {\n nextState.delete(surfaceId);\n continue;\n }\n\n const currentSurface = nextState.get(surfaceId);\n if (!currentSurface) {\n warnings.push(\n `Operation at index ${index} references missing surface \"${surfaceId}\".`,\n );\n continue;\n }\n const surface = cloneSurface(currentSurface, surfaceId);\n\n if (operationKey === \"updateComponents\") {\n upsertComponents(surface, payload[\"components\"], warnings, index);\n nextState.set(surfaceId, surface);\n continue;\n }\n\n const update = dataModelValue(payload);\n if (!update.found) {\n warnings.push(`Operation at index ${index} has no data model value.`);\n continue;\n }\n const path = payload[\"path\"] ?? \"/\";\n if (typeof path !== \"string\") {\n warnings.push(\n `Operation at index ${index} has a malformed data model path.`,\n );\n continue;\n }\n const result = setAtPointer(\n surface.dataModel,\n path,\n update.value,\n version === \"v1.0\",\n );\n if (!result.ok) {\n warnings.push(\n `Operation at index ${index} has an invalid JSON Pointer path.`,\n );\n continue;\n }\n surface.dataModel = result.value;\n nextState.set(surfaceId, surface);\n } catch {\n warnings.push(`Operation at index ${index} is malformed.`);\n }\n }\n\n return { state: nextState, warnings };\n}\n"],"mappings":";;AAOA,MAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,8BAA8B;AACpC,MAAM,kBAAkB,OAAO,gBAAgB;AAE/C,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAErE,MAAM,aAAa,UACjB,UAAU,UAAU,UAAU;AAEhC,MAAM,eAAe,YAAyD;CAC5E,MAAM,YAAY,QAAQ;CAC1B,OAAO,OAAO,cAAc,YAAY,UAAU,SAAS,IACvD,YACA,KA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EAEA,MAAM,iBAAiB,UAAU,IAAI,SAAS;EAC9C,IAAI,CAAC,gBAAgB;GACnB,SAAS,KACP,sBAAsB,MAAM,+BAA+B,UAAU,GACvE;GACA;EACF;EACA,MAAM,UAAU,aAAa,gBAAgB,SAAS;EAEtD,IAAI,iBAAiB,oBAAoB;GACvC,iBAAiB,SAAS,QAAQ,eAAe,UAAU,KAAK;GAChE,UAAU,IAAI,WAAW,OAAO;GAChC;EACF;EAEA,MAAM,SAAS,eAAe,OAAO;EACrC,IAAI,CAAC,OAAO,OAAO;GACjB,SAAS,KAAK,sBAAsB,MAAM,0BAA0B;GACpE;EACF;EACA,MAAM,OAAO,QAAQ,WAAW;EAChC,IAAI,OAAO,SAAS,UAAU;GAC5B,SAAS,KACP,sBAAsB,MAAM,kCAC9B;GACA;EACF;EACA,MAAM,SAAS,aACb,QAAQ,WACR,MACA,OAAO,OACP,YAAY,MACd;EACA,IAAI,CAAC,OAAO,IAAI;GACd,SAAS,KACP,sBAAsB,MAAM,mCAC9B;GACA;EACF;EACA,QAAQ,YAAY,OAAO;EAC3B,UAAU,IAAI,WAAW,OAAO;CAClC,QAAQ;EACN,SAAS,KAAK,sBAAsB,MAAM,eAAe;CAC3D;CAGF,OAAO;EAAE,OAAO;EAAW;CAAS;AACtC"}
|
|
1
|
+
{"version":3,"file":"reducer.js","names":[],"sources":["../../src/a2ui/reducer.ts"],"sourcesContent":["import {\n A2UI_SURFACE_ID,\n type A2uiOperationResult,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"./types\";\n\nconst OPERATION_KEYS = new Set([\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n]);\n// This defensive ceiling is well above the renderer's displayed-item limit.\nconst MAX_AUTO_VIVIFY_ARRAY_INDEX = 10_000;\nconst INVALID_POINTER = Symbol(\"invalidPointer\");\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isVersion = (value: unknown): value is \"v0.9\" | \"v1.0\" =>\n value === \"v0.9\" || value === \"v1.0\";\n\nconst surfaceIdOf = (payload: Record<string, unknown>): string | undefined => {\n const surfaceId = payload[\"surfaceId\"];\n return typeof surfaceId === \"string\" && surfaceId.length > 0\n ? surfaceId\n : undefined;\n};\n\nconst catalogIdOf = (payload: Record<string, unknown>): string | undefined => {\n if (typeof payload[\"catalogId\"] === \"string\") {\n return payload[\"catalogId\"];\n }\n const surfaceProperties = payload[\"surfaceProperties\"];\n return isRecord(surfaceProperties) &&\n typeof surfaceProperties[\"catalogId\"] === \"string\"\n ? surfaceProperties[\"catalogId\"]\n : undefined;\n};\n\nconst withSurfaceId = (\n surface: A2uiSurfaceState,\n surfaceId: string,\n): A2uiSurfaceState => {\n Object.defineProperty(surface, A2UI_SURFACE_ID, {\n value: surfaceId,\n enumerable: false,\n });\n return surface;\n};\n\nconst getSurfaceId = (surface: A2uiSurfaceState): string | undefined =>\n (surface as A2uiSurfaceState & { [A2UI_SURFACE_ID]?: string })[\n A2UI_SURFACE_ID\n ];\n\nconst cloneSurface = (\n surface: A2uiSurfaceState,\n surfaceId: string,\n): A2uiSurfaceState =>\n withSurfaceId(\n {\n ...(surface.catalogId !== undefined\n ? { catalogId: surface.catalogId }\n : {}),\n components: new Map(surface.components),\n dataModel: surface.dataModel,\n },\n getSurfaceId(surface) ?? surfaceId,\n );\n\nconst upsertComponents = (\n surface: A2uiSurfaceState,\n components: unknown,\n warnings: string[],\n operationIndex: number,\n): void => {\n if (!Array.isArray(components)) {\n warnings.push(\n `Operation at index ${operationIndex} has malformed components.`,\n );\n return;\n }\n\n for (\n let componentIndex = 0;\n componentIndex < components.length;\n componentIndex++\n ) {\n const component = components[componentIndex];\n if (\n !isRecord(component) ||\n typeof component[\"id\"] !== \"string\" ||\n component[\"id\"].length === 0 ||\n typeof component[\"component\"] !== \"string\" ||\n component[\"component\"].length === 0\n ) {\n warnings.push(\n `Component at index ${componentIndex} in operation ${operationIndex} is malformed.`,\n );\n continue;\n }\n surface.components.set(component[\"id\"], { ...component });\n }\n};\n\nconst decodePointer = (path: string): string[] | undefined => {\n if (path === \"\" || path === \"/\") return [];\n if (!path.startsWith(\"/\")) return undefined;\n return path\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n};\n\nconst isArrayIndex = (segment: string): boolean =>\n segment === \"0\" || /^[1-9]\\d*$/.test(segment);\n\nconst setAtPointer = (\n model: unknown,\n path: string,\n value: unknown,\n nullDeletes: boolean,\n): { readonly ok: boolean; readonly value: unknown } => {\n const segments = decodePointer(path);\n if (!segments) return { ok: false, value: model };\n if (segments.length === 0) return { ok: true, value };\n\n const remove = (current: unknown, index: number): unknown => {\n const segment = segments[index]!;\n const isLast = index === segments.length - 1;\n\n if (Array.isArray(current)) {\n if (segment !== \"-\" && !isArrayIndex(segment)) return current;\n const targetIndex = segment === \"-\" ? current.length : Number(segment);\n if (isLast) {\n if (\n segment === \"-\" ||\n !Object.prototype.hasOwnProperty.call(current, targetIndex)\n ) {\n return current;\n }\n const clone = current.slice();\n // Preserve indices referenced by other JSON Pointers.\n delete clone[targetIndex];\n return clone;\n }\n const child = current[targetIndex];\n if (!Array.isArray(child) && !isRecord(child)) return current;\n const next = remove(child, index + 1);\n if (next === child) return current;\n const clone = current.slice();\n clone[targetIndex] = next;\n return clone;\n }\n\n if (!isRecord(current)) return current;\n if (!Object.prototype.hasOwnProperty.call(current, segment)) return current;\n if (isLast) {\n const clone = { ...current };\n delete clone[segment];\n return clone;\n }\n const child = current[segment];\n if (!Array.isArray(child) && !isRecord(child)) return current;\n const next = remove(child, index + 1);\n if (next === child) return current;\n return { ...current, [segment]: next };\n };\n\n if (nullDeletes && value === null) {\n return { ok: true, value: remove(model, 0) };\n }\n\n const update = (current: unknown, index: number): unknown => {\n const segment = segments[index]!;\n const isLast = index === segments.length - 1;\n\n if (Array.isArray(current)) {\n if (segment !== \"-\" && !isArrayIndex(segment)) return current;\n const targetIndex = segment === \"-\" ? current.length : Number(segment);\n if (\n segment !== \"-\" &&\n targetIndex >= current.length &&\n targetIndex > MAX_AUTO_VIVIFY_ARRAY_INDEX\n ) {\n return INVALID_POINTER;\n }\n const next = isLast ? value : update(current[targetIndex], index + 1);\n if (next === INVALID_POINTER) return INVALID_POINTER;\n const clone = current.slice();\n clone[targetIndex] = next;\n return clone;\n }\n\n const record: Record<string, unknown> = isRecord(current) ? current : {};\n const child = Object.hasOwn(record, segment) ? record[segment] : undefined;\n const next = isLast\n ? value\n : update(\n child ??\n (isArrayIndex(segments[index + 1] ?? \"\") ||\n segments[index + 1] === \"-\"\n ? []\n : {}),\n index + 1,\n );\n if (next === INVALID_POINTER) return INVALID_POINTER;\n return { ...record, [segment]: next };\n };\n\n const result = update(model, 0);\n return result === INVALID_POINTER\n ? { ok: false, value: model }\n : { ok: true, value: result };\n};\n\nconst dataModelValue = (\n payload: Record<string, unknown>,\n): { readonly found: boolean; readonly value: unknown } => {\n for (const key of [\"contents\", \"value\", \"data\"] as const) {\n if (payload[key] !== undefined) {\n return { found: true, value: payload[key] };\n }\n }\n return { found: false, value: undefined };\n};\n\nexport function applyA2uiOperations(\n state: A2uiState,\n operations: unknown,\n): A2uiOperationResult {\n const nextState = new Map(state);\n const warnings: string[] = [];\n\n if (!Array.isArray(operations)) {\n return {\n state: nextState,\n warnings: [\"A2UI operations must be an array.\"],\n };\n }\n\n for (let index = 0; index < operations.length; index++) {\n try {\n const entry = operations[index];\n if (!isRecord(entry)) {\n warnings.push(`Operation at index ${index} is malformed.`);\n continue;\n }\n\n const version = entry[\"version\"];\n if (!isVersion(version)) {\n warnings.push(\n `Operation at index ${index} has an unsupported version.`,\n );\n continue;\n }\n\n const operationKeys = Object.keys(entry).filter(\n (key) => key !== \"version\",\n );\n if (operationKeys.length !== 1) {\n warnings.push(\n `Operation at index ${index} must contain exactly one operation key.`,\n );\n continue;\n }\n\n const operationKey = operationKeys[0]!;\n if (!OPERATION_KEYS.has(operationKey)) {\n warnings.push(\n `Unknown A2UI operation \"${operationKey}\" at index ${index}.`,\n );\n continue;\n }\n\n const payload = entry[operationKey];\n if (!isRecord(payload)) {\n warnings.push(`Operation at index ${index} has a malformed payload.`);\n continue;\n }\n\n const surfaceId = surfaceIdOf(payload);\n if (!surfaceId) {\n warnings.push(`Operation at index ${index} has no valid surfaceId.`);\n continue;\n }\n\n if (operationKey === \"createSurface\") {\n const catalogId = catalogIdOf(payload);\n const surface = withSurfaceId(\n {\n ...(catalogId !== undefined ? { catalogId } : {}),\n components: new Map(),\n dataModel:\n version === \"v1.0\" && payload[\"dataModel\"] !== undefined\n ? payload[\"dataModel\"]\n : undefined,\n },\n surfaceId,\n );\n if (version === \"v1.0\" && payload[\"components\"] !== undefined) {\n upsertComponents(surface, payload[\"components\"], warnings, index);\n }\n nextState.set(surfaceId, surface);\n continue;\n }\n\n if (operationKey === \"deleteSurface\") {\n nextState.delete(surfaceId);\n continue;\n }\n\n const currentSurface = nextState.get(surfaceId);\n if (!currentSurface) {\n warnings.push(\n `Operation at index ${index} references missing surface \"${surfaceId}\".`,\n );\n continue;\n }\n const surface = cloneSurface(currentSurface, surfaceId);\n\n if (operationKey === \"updateComponents\") {\n upsertComponents(surface, payload[\"components\"], warnings, index);\n nextState.set(surfaceId, surface);\n continue;\n }\n\n const update = dataModelValue(payload);\n if (!update.found) {\n warnings.push(`Operation at index ${index} has no data model value.`);\n continue;\n }\n const path = payload[\"path\"] ?? \"/\";\n if (typeof path !== \"string\") {\n warnings.push(\n `Operation at index ${index} has a malformed data model path.`,\n );\n continue;\n }\n const result = setAtPointer(\n surface.dataModel,\n path,\n update.value,\n version === \"v1.0\",\n );\n if (!result.ok) {\n warnings.push(\n `Operation at index ${index} has an invalid JSON Pointer path.`,\n );\n continue;\n }\n surface.dataModel = result.value;\n nextState.set(surfaceId, surface);\n } catch {\n warnings.push(`Operation at index ${index} is malformed.`);\n }\n }\n\n return { state: nextState, warnings };\n}\n"],"mappings":";;AAO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AAQ,WACR,MACA,OAAO,OACP,YAAY,MACd;EACA,IAAI,CAAC,OAAO,IAAI;GACd,SAAS,KACP,sBAAsB,MAAM,mCAC9B;GACA;EACF;EACA,QAAQ,YAAY,OAAO;EAC3B,UAAU,IAAI,WAAW,OAAO;CAClC,QAAQ;EACN,SAAS,KAAK,sBAAsB,MAAM,eAAe;CAC3D;CAGF,OAAO;EAAE,OAAO;EAAW;CAAS;AACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/a2ui/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,4BAA4B,EAElC,mBAAgB;AAOjB,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gBAAgB,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,SAAS,4BAA4B,EAAE,CAoCzC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { A2UI_SURFACE_ID } from "./types.js";
|
|
2
|
+
//#region src/a2ui/snapshot.ts
|
|
3
|
+
const surfaceIdOf = (surface) => surface[A2UI_SURFACE_ID];
|
|
4
|
+
function surfaceToOperations(surface, surfaceId) {
|
|
5
|
+
const resolvedSurfaceId = surfaceId ?? surfaceIdOf(surface);
|
|
6
|
+
if (!resolvedSurfaceId) throw new Error("A2UI surfaces must have a surface id to be replayed.");
|
|
7
|
+
const operations = [{
|
|
8
|
+
version: "v0.9",
|
|
9
|
+
createSurface: {
|
|
10
|
+
surfaceId: resolvedSurfaceId,
|
|
11
|
+
...surface.catalogId !== void 0 ? { catalogId: surface.catalogId } : {}
|
|
12
|
+
}
|
|
13
|
+
}, {
|
|
14
|
+
version: "v0.9",
|
|
15
|
+
updateComponents: {
|
|
16
|
+
surfaceId: resolvedSurfaceId,
|
|
17
|
+
components: [...surface.components.values()].map((component) => ({ ...component }))
|
|
18
|
+
}
|
|
19
|
+
}];
|
|
20
|
+
if (surface.dataModel !== void 0) operations.push({
|
|
21
|
+
version: "v0.9",
|
|
22
|
+
updateDataModel: {
|
|
23
|
+
surfaceId: resolvedSurfaceId,
|
|
24
|
+
path: "/",
|
|
25
|
+
contents: surface.dataModel
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return operations;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { surfaceToOperations };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","names":[],"sources":["../../src/a2ui/snapshot.ts"],"sourcesContent":["import {\n A2UI_SURFACE_ID,\n type A2uiSurfaceState,\n type A2uiSurfaceSnapshotOperation,\n type ComponentNode,\n} from \"./types\";\n\nconst surfaceIdOf = (surface: A2uiSurfaceState): string | undefined =>\n (surface as A2uiSurfaceState & { [A2UI_SURFACE_ID]?: string })[\n A2UI_SURFACE_ID\n ];\n\nexport function surfaceToOperations(\n surface: A2uiSurfaceState,\n surfaceId?: string,\n): readonly A2uiSurfaceSnapshotOperation[] {\n const resolvedSurfaceId = surfaceId ?? surfaceIdOf(surface);\n if (!resolvedSurfaceId) {\n throw new Error(\"A2UI surfaces must have a surface id to be replayed.\");\n }\n const operations: A2uiSurfaceSnapshotOperation[] = [\n {\n version: \"v0.9\",\n createSurface: {\n surfaceId: resolvedSurfaceId,\n ...(surface.catalogId !== undefined\n ? { catalogId: surface.catalogId }\n : {}),\n },\n },\n {\n version: \"v0.9\",\n updateComponents: {\n surfaceId: resolvedSurfaceId,\n components: [...surface.components.values()].map((component) => ({\n ...component,\n })) as ComponentNode[],\n },\n },\n ];\n if (surface.dataModel !== undefined) {\n operations.push({\n version: \"v0.9\",\n updateDataModel: {\n surfaceId: resolvedSurfaceId,\n path: \"/\",\n contents: surface.dataModel,\n },\n });\n }\n return operations;\n}\n"],"mappings":";;AAOA,MAAM,eAAe,YAClB,QACC;AAGJ,SAAgB,oBACd,SACA,WACyC;CACzC,MAAM,oBAAoB,aAAa,YAAY,OAAO;CAC1D,IAAI,CAAC,mBACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,MAAM,aAA6C,CACjD;EACE,SAAS;EACT,eAAe;GACb,WAAW;GACX,GAAI,QAAQ,cAAc,KAAA,IACtB,EAAE,WAAW,QAAQ,UAAU,IAC/B,CAAC;EACP;CACF,GACA;EACE,SAAS;EACT,kBAAkB;GAChB,WAAW;GACX,YAAY,CAAC,GAAG,QAAQ,WAAW,OAAO,CAAC,CAAC,CAAC,KAAK,eAAe,EAC/D,GAAG,UACL,EAAE;EACJ;CACF,CACF;CACA,IAAI,QAAQ,cAAc,KAAA,GACxB,WAAW,KAAK;EACd,SAAS;EACT,iBAAiB;GACf,WAAW;GACX,MAAM;GACN,UAAU,QAAQ;EACpB;CACF,CAAC;CAEH,OAAO;AACT"}
|
package/dist/a2ui/types.d.ts
CHANGED
|
@@ -1,72 +1,82 @@
|
|
|
1
|
-
//#region src/a2ui/types.d.ts
|
|
2
1
|
export declare const A2UI_SURFACE_ID: unique symbol;
|
|
3
2
|
export type A2uiVersion = "v0.9" | "v1.0";
|
|
4
3
|
export interface A2uiTemplateChildren {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
readonly template: {
|
|
5
|
+
readonly componentId: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
};
|
|
9
8
|
}
|
|
10
9
|
export interface ComponentNode extends Record<string, unknown> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly component: string;
|
|
12
|
+
readonly children?: readonly string[] | A2uiTemplateChildren;
|
|
14
13
|
}
|
|
15
14
|
export interface A2uiCreateSurfaceV09Payload {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
readonly surfaceId: string;
|
|
16
|
+
readonly catalogId?: string;
|
|
17
|
+
readonly theme?: unknown;
|
|
18
|
+
readonly attachDataModel?: unknown;
|
|
20
19
|
}
|
|
21
20
|
export interface A2uiCreateSurfaceV10Payload {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
readonly surfaceId: string;
|
|
22
|
+
readonly catalogId?: string;
|
|
23
|
+
readonly surfaceProperties?: unknown;
|
|
24
|
+
readonly sendDataModel?: unknown;
|
|
25
|
+
readonly components?: readonly ComponentNode[];
|
|
26
|
+
readonly dataModel?: unknown;
|
|
27
27
|
}
|
|
28
28
|
export interface A2uiUpdateComponentsPayload {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
readonly surfaceId: string;
|
|
30
|
+
readonly components: readonly ComponentNode[];
|
|
31
31
|
}
|
|
32
32
|
export interface A2uiUpdateDataModelPayload {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
readonly surfaceId: string;
|
|
34
|
+
readonly path?: string;
|
|
35
|
+
readonly contents?: unknown;
|
|
36
|
+
readonly value?: unknown;
|
|
37
|
+
readonly data?: unknown;
|
|
38
38
|
}
|
|
39
39
|
export interface A2uiDeleteSurfacePayload {
|
|
40
|
-
|
|
40
|
+
readonly surfaceId: string;
|
|
41
41
|
}
|
|
42
42
|
export type A2uiCreateSurfaceOperation = {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
readonly version: "v0.9";
|
|
44
|
+
readonly createSurface: A2uiCreateSurfaceV09Payload;
|
|
45
45
|
} | {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
readonly version: "v1.0";
|
|
47
|
+
readonly createSurface: A2uiCreateSurfaceV10Payload;
|
|
48
48
|
};
|
|
49
49
|
export interface A2uiUpdateComponentsOperation {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
readonly version: A2uiVersion;
|
|
51
|
+
readonly updateComponents: A2uiUpdateComponentsPayload;
|
|
52
52
|
}
|
|
53
53
|
export interface A2uiUpdateDataModelOperation {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
readonly version: A2uiVersion;
|
|
55
|
+
readonly updateDataModel: A2uiUpdateDataModelPayload;
|
|
56
56
|
}
|
|
57
57
|
export interface A2uiDeleteSurfaceOperation {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
readonly version: A2uiVersion;
|
|
59
|
+
readonly deleteSurface: A2uiDeleteSurfacePayload;
|
|
60
60
|
}
|
|
61
61
|
export type A2uiOperation = A2uiCreateSurfaceOperation | A2uiUpdateComponentsOperation | A2uiUpdateDataModelOperation | A2uiDeleteSurfaceOperation;
|
|
62
|
+
export type A2uiSurfaceSnapshotOperation = {
|
|
63
|
+
readonly version: "v0.9";
|
|
64
|
+
readonly createSurface: A2uiCreateSurfaceV09Payload;
|
|
65
|
+
} | {
|
|
66
|
+
readonly version: "v0.9";
|
|
67
|
+
readonly updateComponents: A2uiUpdateComponentsPayload;
|
|
68
|
+
} | {
|
|
69
|
+
readonly version: "v0.9";
|
|
70
|
+
readonly updateDataModel: A2uiUpdateDataModelPayload;
|
|
71
|
+
};
|
|
62
72
|
export type A2uiSurfaceState = {
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
catalogId?: string;
|
|
74
|
+
components: Map<string, Record<string, unknown>>;
|
|
75
|
+
dataModel: unknown;
|
|
65
76
|
};
|
|
66
77
|
export type A2uiState = ReadonlyMap<string, A2uiSurfaceState>;
|
|
67
78
|
export interface A2uiOperationResult {
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
readonly state: A2uiState;
|
|
80
|
+
readonly warnings: string[];
|
|
70
81
|
}
|
|
71
|
-
//#endregion
|
|
72
82
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/a2ui/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/a2ui/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eAA0B,CAAC;A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,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,EAAE,0BAA0B,CAAC;CACtD,CAAC;AAEN,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE9D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;CAC7B"}
|
package/dist/a2ui/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/a2ui/types.ts"],"sourcesContent":["export const A2UI_SURFACE_ID = Symbol(\"a2uiSurfaceId\");\n\nexport type A2uiVersion = \"v0.9\" | \"v1.0\";\n\nexport interface A2uiTemplateChildren {\n readonly template: {\n readonly componentId: string;\n readonly path: string;\n };\n}\n\nexport interface ComponentNode extends Record<string, unknown> {\n readonly id: string;\n readonly component: string;\n readonly children?: readonly string[] | A2uiTemplateChildren;\n}\n\nexport interface A2uiCreateSurfaceV09Payload {\n readonly surfaceId: string;\n readonly catalogId?: string;\n readonly theme?: unknown;\n readonly attachDataModel?: unknown;\n}\n\nexport interface A2uiCreateSurfaceV10Payload {\n readonly surfaceId: string;\n readonly surfaceProperties?: unknown;\n readonly sendDataModel?: unknown;\n readonly components?: readonly ComponentNode[];\n readonly dataModel?: unknown;\n}\n\nexport interface A2uiUpdateComponentsPayload {\n readonly surfaceId: string;\n readonly components: readonly ComponentNode[];\n}\n\nexport interface A2uiUpdateDataModelPayload {\n readonly surfaceId: string;\n readonly path?: string;\n readonly contents?: unknown;\n readonly value?: unknown;\n readonly data?: unknown;\n}\n\nexport interface A2uiDeleteSurfacePayload {\n readonly surfaceId: string;\n}\n\nexport type A2uiCreateSurfaceOperation =\n | {\n readonly version: \"v0.9\";\n readonly createSurface: A2uiCreateSurfaceV09Payload;\n }\n | {\n readonly version: \"v1.0\";\n readonly createSurface: A2uiCreateSurfaceV10Payload;\n };\n\nexport interface A2uiUpdateComponentsOperation {\n readonly version: A2uiVersion;\n readonly updateComponents: A2uiUpdateComponentsPayload;\n}\n\nexport interface A2uiUpdateDataModelOperation {\n readonly version: A2uiVersion;\n readonly updateDataModel: A2uiUpdateDataModelPayload;\n}\n\nexport interface A2uiDeleteSurfaceOperation {\n readonly version: A2uiVersion;\n readonly deleteSurface: A2uiDeleteSurfacePayload;\n}\n\nexport type A2uiOperation =\n | A2uiCreateSurfaceOperation\n | A2uiUpdateComponentsOperation\n | A2uiUpdateDataModelOperation\n | A2uiDeleteSurfaceOperation;\n\nexport type A2uiSurfaceState = {\n components: Map<string, Record<string, unknown>>;\n dataModel: unknown;\n};\n\nexport type A2uiState = ReadonlyMap<string, A2uiSurfaceState>;\n\nexport interface A2uiOperationResult {\n readonly state: A2uiState;\n readonly warnings: string[];\n}\n"],"mappings":";AAAA,MAAa,kBAAkB,OAAO,eAAe"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/a2ui/types.ts"],"sourcesContent":["export const A2UI_SURFACE_ID = Symbol(\"a2uiSurfaceId\");\n\nexport type A2uiVersion = \"v0.9\" | \"v1.0\";\n\nexport interface A2uiTemplateChildren {\n readonly template: {\n readonly componentId: string;\n readonly path: string;\n };\n}\n\nexport interface ComponentNode extends Record<string, unknown> {\n readonly id: string;\n readonly component: string;\n readonly children?: readonly string[] | A2uiTemplateChildren;\n}\n\nexport interface A2uiCreateSurfaceV09Payload {\n readonly surfaceId: string;\n readonly catalogId?: string;\n readonly theme?: unknown;\n readonly attachDataModel?: unknown;\n}\n\nexport interface A2uiCreateSurfaceV10Payload {\n readonly surfaceId: string;\n readonly catalogId?: string;\n readonly surfaceProperties?: unknown;\n readonly sendDataModel?: unknown;\n readonly components?: readonly ComponentNode[];\n readonly dataModel?: unknown;\n}\n\nexport interface A2uiUpdateComponentsPayload {\n readonly surfaceId: string;\n readonly components: readonly ComponentNode[];\n}\n\nexport interface A2uiUpdateDataModelPayload {\n readonly surfaceId: string;\n readonly path?: string;\n readonly contents?: unknown;\n readonly value?: unknown;\n readonly data?: unknown;\n}\n\nexport interface A2uiDeleteSurfacePayload {\n readonly surfaceId: string;\n}\n\nexport type A2uiCreateSurfaceOperation =\n | {\n readonly version: \"v0.9\";\n readonly createSurface: A2uiCreateSurfaceV09Payload;\n }\n | {\n readonly version: \"v1.0\";\n readonly createSurface: A2uiCreateSurfaceV10Payload;\n };\n\nexport interface A2uiUpdateComponentsOperation {\n readonly version: A2uiVersion;\n readonly updateComponents: A2uiUpdateComponentsPayload;\n}\n\nexport interface A2uiUpdateDataModelOperation {\n readonly version: A2uiVersion;\n readonly updateDataModel: A2uiUpdateDataModelPayload;\n}\n\nexport interface A2uiDeleteSurfaceOperation {\n readonly version: A2uiVersion;\n readonly deleteSurface: A2uiDeleteSurfacePayload;\n}\n\nexport type A2uiOperation =\n | A2uiCreateSurfaceOperation\n | A2uiUpdateComponentsOperation\n | A2uiUpdateDataModelOperation\n | A2uiDeleteSurfaceOperation;\n\nexport type A2uiSurfaceSnapshotOperation =\n | {\n readonly version: \"v0.9\";\n readonly createSurface: A2uiCreateSurfaceV09Payload;\n }\n | {\n readonly version: \"v0.9\";\n readonly updateComponents: A2uiUpdateComponentsPayload;\n }\n | {\n readonly version: \"v0.9\";\n readonly updateDataModel: A2uiUpdateDataModelPayload;\n };\n\nexport type A2uiSurfaceState = {\n catalogId?: string;\n components: Map<string, Record<string, unknown>>;\n dataModel: unknown;\n};\n\nexport type A2uiState = ReadonlyMap<string, A2uiSurfaceState>;\n\nexport interface A2uiOperationResult {\n readonly state: A2uiState;\n readonly warnings: string[];\n}\n"],"mappings":";AAAA,MAAa,kBAAkB,OAAO,eAAe"}
|
package/dist/a2ui.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
1
|
+
export { applyA2uiOperations } from "./a2ui/reducer.js";
|
|
2
|
+
export { convertSurfaceToUISpec } from "./a2ui/convert.js";
|
|
3
|
+
export { surfaceToOperations } from "./a2ui/snapshot.js";
|
|
4
|
+
export type { A2uiCreateSurfaceOperation, A2uiCreateSurfaceV09Payload, A2uiCreateSurfaceV10Payload, A2uiDeleteSurfaceOperation, A2uiDeleteSurfacePayload, A2uiOperation, A2uiOperationResult, A2uiState, A2uiSurfaceSnapshotOperation, A2uiSurfaceState, A2uiTemplateChildren, A2uiUpdateComponentsOperation, A2uiUpdateComponentsPayload, A2uiUpdateDataModelOperation, A2uiUpdateDataModelPayload, A2uiVersion, ComponentNode, } from "./a2ui/types.js";
|
|
5
|
+
//# sourceMappingURL=a2ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2ui.d.ts","sourceRoot":"","sources":["../src/a2ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,0BAAuB;AACrD,OAAO,EAAE,sBAAsB,EAAE,0BAAuB;AACxD,OAAO,EAAE,mBAAmB,EAAE,2BAAwB;AACtD,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EACxB,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,4BAA4B,EAC5B,gBAAgB,EAChB,oBAAoB,EACpB,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,EAC1B,WAAW,EACX,aAAa,GACd,wBAAqB"}
|
package/dist/a2ui.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { applyA2uiOperations } from "./a2ui/reducer.js";
|
|
2
2
|
import { convertSurfaceToUISpec } from "./a2ui/convert.js";
|
|
3
|
-
|
|
3
|
+
import { surfaceToOperations } from "./a2ui/snapshot.js";
|
|
4
|
+
export { applyA2uiOperations, convertSurfaceToUISpec, surfaceToOperations };
|
package/dist/actionRegistry.d.ts
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import { Action } from "./ir.js";
|
|
2
|
-
//#region src/actionRegistry.d.ts
|
|
1
|
+
import type { Action } from "./ir.js";
|
|
3
2
|
/** Context handed to an {@link ActionHandler} when an `$action` fires. */
|
|
4
3
|
export type ActionDispatchContext = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The action payload. For fire-and-forget actions this is the `$action` as the model emitted it. For an interactive component the user's runtime input is merged in under the reserved `$input` key: a single value for a standalone control's dispatch, or an object keyed by each field's `name` for a `Form` or a `Card` with `asForm` set. A model-supplied `value` field is never clobbered.
|
|
6
|
+
*/
|
|
7
|
+
readonly payload: Action;
|
|
9
8
|
};
|
|
10
9
|
/**
|
|
11
10
|
* Resolves a single `$action.type`. Fire-and-forget actions return `void` or a
|
|
12
|
-
* promise that resolves to it
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* handed back to `dispatch`'s caller as `unknown`.
|
|
11
|
+
* promise that resolves to it. For a `prompt_user` tool whose call has no
|
|
12
|
+
* result yet, a non-`undefined` return value becomes the tool result. Whether
|
|
13
|
+
* that resumes the run depends on the runtime, including how it treats human
|
|
14
|
+
* tools. The return value is handed back to `dispatch`'s caller as `unknown`.
|
|
16
15
|
*/
|
|
17
16
|
export type ActionHandler = (ctx: ActionDispatchContext) => unknown | Promise<unknown>;
|
|
18
17
|
/**
|
|
19
|
-
* The host-provided map from `$action.type` to {@link ActionHandler}. This is the single dispatch target for rendered generative UI: every interactive component fires its `$action` here through the injected `$dispatch` (a submit Button defers to its ancestor form's dispatch instead). The payload's `$input` takes one of two shapes: a single value for a standalone control's dispatch (`Select`, `Input`, `DatePicker`, `Checkbox`, `RadioGroup`), or an object keyed by field `name` for a `Form` or a `Card` with `asForm` set. Construct it with {@link createActionRegistry} and pass it to `JSONGenerativeUI`.
|
|
18
|
+
* The host-provided map from `$action.type` to {@link ActionHandler}. This is the single dispatch target for rendered generative UI: every interactive component fires its `$action` here through the injected `$dispatch` (a submit Button defers to its ancestor form's dispatch instead). The payload's `$input` takes one of two shapes: a single value for a standalone control's dispatch (`Select`, `Input`, `DatePicker`, `Checkbox`, `RadioGroup`), or an object keyed by field `name` for a `Form` or a `Card` with `asForm` set. When a registry is used in a `JSONGenerativeUI` tool, each dispatched payload, including `$input`, is recorded on the tool call on a best-effort basis. Recording depends on the runtime and interaction log limits, and never delays or prevents dispatch. Construct it with {@link createActionRegistry} and pass it to `JSONGenerativeUI`.
|
|
20
19
|
*/
|
|
21
20
|
export type ActionRegistry = {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
dispatch(action: Action): unknown;
|
|
22
|
+
has(type: string): boolean;
|
|
24
23
|
};
|
|
25
24
|
export declare function createActionRegistry(handlers: Readonly<Record<string, ActionHandler>>): ActionRegistry;
|
|
26
25
|
/** A no-op registry used when no handlers are provided. Dispatch resolves to
|
|
27
26
|
* `undefined` and logs a warning in dev for unknown types, so a model-emitted
|
|
28
27
|
* action with no handler degrades to "does nothing" rather than throwing. */
|
|
29
28
|
export declare const emptyActionRegistry: ActionRegistry;
|
|
30
|
-
//#endregion
|
|
31
29
|
//# sourceMappingURL=actionRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionRegistry.d.ts","
|
|
1
|
+
{"version":3,"file":"actionRegistry.d.ts","sourceRoot":"","sources":["../src/actionRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAa;AAEnC,0EAA0E;AAC1E,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,GAAG,EAAE,qBAAqB,KACvB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,GAChD,cAAc,CAqChB;AAED;;6EAE6E;AAC7E,eAAO,MAAM,mBAAmB,EAAE,cAAyC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionRegistry.js","names":[],"sources":["../src/actionRegistry.ts"],"sourcesContent":["import type { Action } from \"./ir\";\n\n/** Context handed to an {@link ActionHandler} when an `$action` fires. */\nexport type ActionDispatchContext = {\n /**\n * The action payload. For fire-and-forget actions this is the `$action` as the model emitted it. For an interactive component the user's runtime input is merged in under the reserved `$input` key: a single value for a standalone control's dispatch, or an object keyed by each field's `name` for a `Form` or a `Card` with `asForm` set. A model-supplied `value` field is never clobbered.\n */\n readonly payload: Action;\n};\n\n/**\n * Resolves a single `$action.type`. Fire-and-forget actions return `void` or a\n * promise that resolves to it
|
|
1
|
+
{"version":3,"file":"actionRegistry.js","names":[],"sources":["../src/actionRegistry.ts"],"sourcesContent":["import type { Action } from \"./ir\";\n\n/** Context handed to an {@link ActionHandler} when an `$action` fires. */\nexport type ActionDispatchContext = {\n /**\n * The action payload. For fire-and-forget actions this is the `$action` as the model emitted it. For an interactive component the user's runtime input is merged in under the reserved `$input` key: a single value for a standalone control's dispatch, or an object keyed by each field's `name` for a `Form` or a `Card` with `asForm` set. A model-supplied `value` field is never clobbered.\n */\n readonly payload: Action;\n};\n\n/**\n * Resolves a single `$action.type`. Fire-and-forget actions return `void` or a\n * promise that resolves to it. For a `prompt_user` tool whose call has no\n * result yet, a non-`undefined` return value becomes the tool result. Whether\n * that resumes the run depends on the runtime, including how it treats human\n * tools. The return value is handed back to `dispatch`'s caller as `unknown`.\n */\nexport type ActionHandler = (\n ctx: ActionDispatchContext,\n) => unknown | Promise<unknown>;\n\n/**\n * The host-provided map from `$action.type` to {@link ActionHandler}. This is the single dispatch target for rendered generative UI: every interactive component fires its `$action` here through the injected `$dispatch` (a submit Button defers to its ancestor form's dispatch instead). The payload's `$input` takes one of two shapes: a single value for a standalone control's dispatch (`Select`, `Input`, `DatePicker`, `Checkbox`, `RadioGroup`), or an object keyed by field `name` for a `Form` or a `Card` with `asForm` set. When a registry is used in a `JSONGenerativeUI` tool, each dispatched payload, including `$input`, is recorded on the tool call on a best-effort basis. Recording depends on the runtime and interaction log limits, and never delays or prevents dispatch. Construct it with {@link createActionRegistry} and pass it to `JSONGenerativeUI`.\n */\nexport type ActionRegistry = {\n dispatch(action: Action): unknown;\n has(type: string): boolean;\n};\n\nexport function createActionRegistry(\n handlers: Readonly<Record<string, ActionHandler>>,\n): ActionRegistry {\n const map = new Map(Object.entries(handlers));\n return {\n dispatch(action) {\n if (typeof action?.type !== \"string\") {\n if (process.env[\"NODE_ENV\"] !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\n \"[@assistant-ui/react-generative-ui] Skipping malformed action; \" +\n \"`$action.type` must be a string. \" +\n `Received ${formatReceivedType(action?.type)}. Update the emitted ` +\n \"`$action` payload.\",\n );\n }\n return undefined;\n }\n\n const handler = map.get(action.type);\n if (!handler) {\n if (process.env[\"NODE_ENV\"] !== \"production\") {\n const actionTypes = [...map.keys()];\n // eslint-disable-next-line no-console\n console.warn(\n `[@assistant-ui/react-generative-ui] Action \"${action.type}\" has ` +\n `no registered handler. ${formatRegisteredActions(actionTypes)} ` +\n \"Register it with createActionRegistry(...) or update the emitted \" +\n \"`$action.type`.\",\n );\n }\n return undefined;\n }\n return handler({ payload: action });\n },\n has(type) {\n return map.has(type);\n },\n };\n}\n\n/** A no-op registry used when no handlers are provided. Dispatch resolves to\n * `undefined` and logs a warning in dev for unknown types, so a model-emitted\n * action with no handler degrades to \"does nothing\" rather than throwing. */\nexport const emptyActionRegistry: ActionRegistry = createActionRegistry({});\n\nfunction formatRegisteredActions(actionTypes: string[]) {\n if (actionTypes.length === 0) return \"No actions are registered.\";\n\n return `Registered actions: ${actionTypes\n .map((type) => `\"${type}\"`)\n .join(\", \")}.`;\n}\n\nfunction formatReceivedType(value: unknown) {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n return typeof value;\n}\n"],"mappings":";AA6BA,SAAgB,qBACd,UACgB;CAChB,MAAM,MAAM,IAAI,IAAI,OAAO,QAAQ,QAAQ,CAAC;CAC5C,OAAO;EACL,SAAS,QAAQ;GACf,IAAI,OAAO,QAAQ,SAAS,UAAU;IACpC,IAAI,QAAQ,IAAI,gBAAgB,cAE9B,QAAQ,KACN,+GAEc,mBAAmB,QAAQ,IAAI,EAAE,2CAEjD;IAEF;GACF;GAEA,MAAM,UAAU,IAAI,IAAI,OAAO,IAAI;GACnC,IAAI,CAAC,SAAS;IACZ,IAAI,QAAQ,IAAI,gBAAgB,cAAc;KAC5C,MAAM,cAAc,CAAC,GAAG,IAAI,KAAK,CAAC;KAElC,QAAQ,KACN,+CAA+C,OAAO,KAAK,+BAC/B,wBAAwB,WAAW,EAAE,qFAGnE;IACF;IACA;GACF;GACA,OAAO,QAAQ,EAAE,SAAS,OAAO,CAAC;EACpC;EACA,IAAI,MAAM;GACR,OAAO,IAAI,IAAI,IAAI;EACrB;CACF;AACF;;;;AAKA,MAAa,sBAAsC,qBAAqB,CAAC,CAAC;AAE1E,SAAS,wBAAwB,aAAuB;CACtD,IAAI,YAAY,WAAW,GAAG,OAAO;CAErC,OAAO,uBAAuB,YAC3B,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC,CAC1B,KAAK,IAAI,EAAE;AAChB;AAEA,SAAS,mBAAmB,OAAgB;CAC1C,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO;CACjC,OAAO,OAAO;AAChB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/buildPresentParameters.d.ts
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
import type { GenerativeUILibrary } from "./types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Builds the JSON schema for the `present` tool from a {@link GenerativeUILibrary}.
|
|
6
5
|
*
|
|
@@ -19,5 +18,4 @@ import { JSONSchema7 } from "json-schema";
|
|
|
19
18
|
* at render time — so a looser schema only costs the model a hint, not safety.
|
|
20
19
|
*/
|
|
21
20
|
export declare function buildPresentParameters(library: GenerativeUILibrary): JSONSchema7;
|
|
22
|
-
//#endregion
|
|
23
21
|
//# sourceMappingURL=buildPresentParameters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPresentParameters.d.ts","
|
|
1
|
+
{"version":3,"file":"buildPresentParameters.d.ts","sourceRoot":"","sources":["../src/buildPresentParameters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAgB;AAGnD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,mBAAmB,GAC3B,WAAW,CA+Fb"}
|