@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":"validate-operation.cjs","names":["isRecord","A2UI_VERSION","GENERATIVE_UI_AGENT_FUNCTION_CALLS","GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON","isCallBinding","GENERATIVE_UI_FUNCTIONS","functionCallers","isA2UIValueFunction","isA2UIBasicFunction","collectChildRefs"],"sources":["../../src/generative-ui/validate-operation.ts"],"sourcesContent":["import {\n GENERATIVE_UI_FUNCTIONS,\n functionCallers,\n isA2UIBasicFunction,\n isA2UIValueFunction,\n isCallBinding,\n} from \"./basic-functions\";\nimport type { A2UIFunctionPermissions } from \"./basic-functions\";\nimport { collectChildRefs } from \"./child-refs\";\nimport type { ChildRef } from \"./child-refs\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON,\n} from \"./types\";\nimport type {\n GenerativeUIActionBinding,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\nimport { isRecord } from \"./is-record\";\n\nexport type OperationValidation = { ok: true } | { ok: false; reason: string };\n\nconst OPERATION_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n \"callRendererFunction\",\n] as const;\nexport type OperationKind = (typeof OPERATION_KINDS)[number];\n\nexport interface ValidateOperationOptions {\n manifest: Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"catalogIds\" | \"components\"\n >;\n /**\n * Surfaces that exist before this operation is applied. `updateComponents`,\n * `updateDataModel`, and `deleteSurface` need their surface in this set.\n */\n knownSurfaces: ReadonlySet<string>;\n /**\n * Surface ids that were created before, also the deleted ones. A surface id\n * is unique for the life of the page, so `createSurface` rejects them.\n */\n createdSurfaces?: ReadonlySet<string>;\n /**\n * UI-callable functions. When provided, `functionCall` bindings and\n * `callRendererFunction` must name one of them. The client omits it:\n * availability is checked when the function runs.\n */\n functions?: GenerativeUIManifest[\"functions\"];\n /**\n * The components that the target of the surface takes. When provided,\n * `updateComponents` and the inline components of `createSurface` can use\n * only these names. Left out, every catalog component is allowed.\n */\n allowedComponents?: AllowedComponents;\n}\n\n/** The component names that one target takes. */\nexport interface AllowedComponents {\n /** The target id, for the reason of a rejection. */\n target: string;\n names: ReadonlySet<string>;\n}\n\nconst OK: OperationValidation = { ok: true };\nconst fail = (reason: string): OperationValidation => ({ ok: false, reason });\n\n/** Models write the v0.9 binding from habit. The reason names the v1.0 form. */\nconst V09_PATH_REASON = 'bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}';\n\nfunction hasOwn(record: object, key: string) {\n return Object.prototype.hasOwnProperty.call(record, key);\n}\n\n/**\n * Reads an own property only. Model-controlled keys such as \"constructor\" or\n * \"toString\" must not resolve to Object.prototype members.\n */\nfunction ownValue<T>(record: Record<string, T> | undefined, key: string) {\n return record && hasOwn(record, key) ? record[key] : undefined;\n}\n\nexport function getOperationKind(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kinds = OPERATION_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/** The `surfaceId` of a surface operation. `callRendererFunction` has none. */\nexport function getOperationSurfaceId(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kind = getOperationKind(op);\n if (!kind) return undefined;\n const payload = op[kind];\n return isRecord(payload) && typeof payload.surfaceId === \"string\"\n ? payload.surfaceId\n : undefined;\n}\n\n/** `{ \"@path\": \"/x\" }`: a data-model binding. */\nexport function isPathBinding(value: unknown): value is { \"@path\": string } {\n return (\n isRecord(value) &&\n typeof value[\"@path\"] === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/** `{ \"path\": \"/x\" }`: the v0.9 binding, which v1.0 does not accept. */\nfunction isV09PathBinding(value: unknown) {\n return (\n isRecord(value) &&\n typeof value.path === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/**\n * `{ \"@call\": \"@index\" }` or `{ \"@call\": \"@index\", \"args\": { \"offset\": 1 } }`:\n * the 0-based position of the item in a template, plus `offset`.\n */\nexport function isIndexCall(\n value: unknown,\n): value is { \"@call\": \"@index\"; args?: { offset?: number } } {\n if (!isRecord(value) || value[\"@call\"] !== \"@index\") return false;\n const hasOnlyCallKeys = Object.keys(value).every(\n (key) => key === \"@call\" || key === \"args\",\n );\n if (!hasOnlyCallKeys) return false;\n const { args } = value;\n if (args === undefined) return true;\n return (\n isRecord(args) &&\n Object.keys(args).every((key) => key === \"offset\") &&\n (args.offset === undefined || Number.isFinite(args.offset))\n );\n}\n\nexport function isActionBinding(\n value: unknown,\n): value is GenerativeUIActionBinding {\n return (\n isRecord(value) &&\n Object.keys(value).length === 1 &&\n (isRecord(value.functionCall) || isRecord(value.event))\n );\n}\n\n/**\n * Checks one A2UI v1.0 operation against the catalog and the surfaces that\n * exist. The operation comes from the model, so nothing in it is trusted.\n *\n * @param op - The operation, as parsed from JSON.\n * @param options - The catalog, the known and created surfaces, the\n * functions that the UI can call, and the components that the target of\n * the surface takes.\n *\n * @example\n * ```ts\n * const result = validateOperation(op, { manifest, knownSurfaces });\n * if (!result.ok) rejected.push({ index, reason: result.reason });\n * ```\n */\nexport function validateOperation(\n op: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(op)) return fail(\"operation must be a JSON object\");\n if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));\n const kind = getOperationKind(op);\n if (!kind) {\n return fail(\n `operation must contain exactly one of ${OPERATION_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (kind === \"callRendererFunction\") {\n if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) {\n return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);\n }\n return validateRendererFunctionCall(payload, options);\n }\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return fail(`${kind}.surfaceId is required`);\n }\n const surfaceId = payload.surfaceId;\n if (kind === \"createSurface\") {\n return validateCreateSurface(payload, surfaceId, options);\n }\n if (!options.knownSurfaces.has(surfaceId)) {\n return fail(\n `surface \"${surfaceId}\" does not exist; send createSurface first`,\n );\n }\n switch (kind) {\n case \"deleteSurface\":\n return OK;\n case \"updateDataModel\":\n return validateDataModelUpdate(payload);\n case \"updateComponents\":\n return validateComponents(\n payload.components,\n \"updateComponents.components\",\n options,\n );\n }\n}\n\nfunction versionProblem(version: unknown) {\n return typeof version === \"string\"\n ? `unsupported version \"${version}\"; use \"${A2UI_VERSION}\"`\n : `operation needs \"version\":\"${A2UI_VERSION}\"`;\n}\n\n/** A `catalogId` can name the catalog of the run or one of its bases. */\nfunction catalogProblem(\n catalogId: unknown,\n manifest: ValidateOperationOptions[\"manifest\"],\n) {\n const ids = manifest.catalogIds ?? [manifest.catalogId];\n if (catalogId === undefined || ids.includes(catalogId as string)) {\n return undefined;\n }\n const names = ids.map((id) => `\"${id}\"`).join(\", \");\n const use = ids.length === 1 ? names : `one of: ${names}`;\n return `unknown catalog \"${String(catalogId)}\"; leave out catalogId or use ${use}`;\n}\n\nfunction validateCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n options: ValidateOperationOptions,\n) {\n if (options.knownSurfaces.has(surfaceId)) {\n return fail(`surface \"${surfaceId}\" already exists`);\n }\n if (options.createdSurfaces?.has(surfaceId)) {\n return fail(\n `surface id \"${surfaceId}\" was used before; use a new surfaceId`,\n );\n }\n const catalogReason = catalogProblem(payload.catalogId, options.manifest);\n if (catalogReason) return fail(catalogReason);\n const { dataModel, components } = payload;\n if (dataModel !== undefined && !isRecord(dataModel)) {\n return fail(\"createSurface.dataModel must be a JSON object\");\n }\n if (components === undefined) return OK;\n return validateComponents(components, \"createSurface.components\", options);\n}\n\nfunction validateRendererFunctionCall(\n payload: unknown,\n options: ValidateOperationOptions,\n) {\n const hasCallId =\n isRecord(payload) &&\n typeof payload.functionCallId === \"string\" &&\n payload.functionCallId !== \"\";\n if (!hasCallId) {\n return fail(\n \"callRendererFunction.functionCallId must be a non-empty string\",\n );\n }\n const reason = functionCallProblem(\n payload.callFunction,\n \"callRendererFunction.callFunction\",\n options,\n );\n return reason ? fail(reason) : OK;\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction decodeSegment(segment: string) {\n return segment.replace(/~([01])/g, (_, g) => (g === \"1\" ? \"/\" : \"~\"));\n}\n\nfunction validateDataModelUpdate(payload: Record<string, unknown>) {\n if (payload.value === undefined) {\n return fail(\n 'updateDataModel.value is required; use \"value\":null to delete',\n );\n }\n const path = payload.path ?? \"/\";\n if (typeof path !== \"string\" || !path.startsWith(\"/\")) {\n return fail(\"updateDataModel.path must be an absolute JSON pointer\");\n }\n if (path === \"/\") {\n // Paths such as \"/items\" point into the root, so the root must be an object.\n if (!isRecord(payload.value)) {\n return fail(\"a root updateDataModel value must be a JSON object\");\n }\n return OK;\n }\n const reason = pathProblem(path, \"updateDataModel.path\");\n return reason ? fail(reason) : OK;\n}\n\n/**\n * Checks the segments of an absolute JSON pointer (\"/a/b\") or of a path\n * relative to a template item (\"a/b\"). `label` names the field in the reason.\n */\nfunction pathProblem(path: string, label: string) {\n const relative = path.startsWith(\"/\") ? path.slice(1) : path;\n const segments = relative.split(\"/\");\n if (segments.some((segment) => segment === \"\")) {\n return `${label} must not contain empty segments`;\n }\n const decoded = segments.map(decodeSegment);\n const forbidden = decoded.find((segment) => FORBIDDEN_SEGMENTS.has(segment));\n if (forbidden !== undefined) {\n return `path segment \"${forbidden}\" is not allowed in ${label}`;\n }\n return undefined;\n}\n\nfunction validateComponents(\n components: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!Array.isArray(components) || components.length === 0) {\n return fail(`${label} must be a non-empty array`);\n }\n const ids = new Set<string>();\n for (const node of components) {\n if (!isRecord(node)) return fail(\"component must be a JSON object\");\n const { id } = node;\n if (typeof id !== \"string\" || !id) return fail(\"id is required\");\n const reason = nodeProblem(node, id, options);\n if (reason) return fail(`component \"${id}\": ${reason}`);\n if (ids.has(id)) {\n return fail(`component \"${id}\" appears twice in one update`);\n }\n ids.add(id);\n }\n return OK;\n}\n\nfunction nodeProblem(\n node: Record<string, unknown>,\n id: string,\n options: ValidateOperationOptions,\n) {\n if (typeof node.component !== \"string\") return \"component type is required\";\n const entry = ownValue(options.manifest.components, node.component);\n if (!entry) return `unknown component \"${node.component}\"`;\n const { allowedComponents } = options;\n if (allowedComponents && !allowedComponents.names.has(node.component)) {\n const names = [...allowedComponents.names].join(\", \") || \"none\";\n return `\"${node.component}\" is not allowed in target \"${allowedComponents.target}\"; use one of: ${names}`;\n }\n const { properties, required } = entry.props;\n const propNames = isRecord(properties) ? Object.keys(properties) : [];\n const props = Object.entries(node);\n for (const [key, value] of props) {\n if (key === \"id\" || key === \"component\") continue;\n if (key === \"catalogId\") {\n const reason = catalogProblem(value, options.manifest);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (key === \"metadata\") {\n const isMetadata =\n isRecord(value) &&\n (value.extensions === undefined || isRecord(value.extensions));\n if (!isMetadata) return 'metadata must be { \"extensions\": { ... } }';\n continue;\n }\n if (key === \"accessibility\") {\n const reason = accessibilityProblem(value);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (ownValue(entry.events, key)) {\n const reason = actionBindingProblem(value, options);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n const slot = ownValue(entry.slots, key);\n if (slot) {\n const reason = slotProblem(value, slot, id);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (!propNames.includes(key)) return `unknown prop \"${key}\"`;\n if (isV09PathBinding(value)) return `${key}: ${V09_PATH_REASON}`;\n const call = findForbiddenCall(value, { allowValueFunctions: true });\n if (call !== undefined) {\n return `${key}: ${call}; a data prop can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n for (const ref of childRefsOf(entry.props)) {\n const reason = childRefProblem(node, ref, id);\n if (reason) return reason;\n }\n const requiredNames = Array.isArray(required) ? required : [];\n for (const name of requiredNames) {\n if (typeof name === \"string\" && !(name in node)) {\n return `missing required prop \"${name}\"`;\n }\n }\n return undefined;\n}\n\nconst ACCESSIBILITY_KEYS = [\"label\", \"description\", \"live\", \"hidden\"];\nconst LIVE_VALUES = [\"off\", \"polite\", \"assertive\"];\n\n/**\n * Checks the `accessibility` of a component envelope: `label` and\n * `description` are strings or dynamic values, `live` is one of the ARIA\n * values, `hidden` is a boolean or a dynamic value.\n */\nfunction accessibilityProblem(value: unknown) {\n if (!isRecord(value)) {\n return 'must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }';\n }\n const isDynamic = (field: unknown) =>\n isPathBinding(field) || isCallBinding(field);\n for (const [key, field] of Object.entries(value)) {\n if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key \"${key}\"`;\n if (isV09PathBinding(field)) return `${key}: ${V09_PATH_REASON}`;\n if (isDynamic(field)) {\n const call = findForbiddenCall(field, { allowValueFunctions: true });\n if (call !== undefined) return `${key}: ${call}`;\n continue;\n }\n if (key === \"live\") {\n if (typeof field !== \"string\" || !LIVE_VALUES.includes(field)) {\n return `live must be one of ${LIVE_VALUES.join(\", \")}`;\n }\n } else if (key === \"hidden\") {\n if (typeof field !== \"boolean\") return \"hidden must be a boolean\";\n } else if (typeof field !== \"string\") {\n return `${key} must be a string`;\n }\n }\n return undefined;\n}\n\nfunction actionBindingProblem(\n value: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(value)) return \"must be an action object\";\n const keys = Object.keys(value);\n const isOneAction =\n keys.length === 1 && (keys[0] === \"functionCall\" || keys[0] === \"event\");\n if (!isOneAction) {\n return 'must be { \"event\": ... } or { \"functionCall\": ... }';\n }\n if (keys[0] === \"functionCall\") {\n return functionCallProblem(value.functionCall, \"functionCall\", options);\n }\n return eventProblem(value.event);\n}\n\n/**\n * Checks `{ \"@call\": \"<function>\", \"args\": { ... } }`. `label` names the\n * field in the reason.\n */\nfunction functionCallProblem(\n call: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(call)) {\n return `${label} must be { \"@call\": \"<function>\", \"args\": { ... } }`;\n }\n const name = call[\"@call\"];\n if (typeof name !== \"string\" || !name) {\n return typeof call.call === \"string\"\n ? `${label} names the function with \"@call\", not \"call\"`\n : `${label}[\"@call\"] must be a function name`;\n }\n const { args } = call;\n if (args !== undefined && !isRecord(args)) {\n return `${label}.args must be an object`;\n }\n const catalogReason = catalogProblem(call.catalogId, options.manifest);\n if (catalogReason) return `${label}: ${catalogReason}`;\n const argEntries = Object.entries(args ?? {});\n for (const [key, arg] of argEntries) {\n if (isV09PathBinding(arg))\n return `${label}.args.${key}: ${V09_PATH_REASON}`;\n }\n // A function the app declares under a built-in name is the app's; the\n // restrictions of the built-in do not apply to it.\n const appFunctions = options.functions;\n const declared =\n appFunctions !== undefined && hasOwn(appFunctions, name)\n ? appFunctions[name]\n : undefined;\n const builtIn =\n declared === undefined && hasOwn(GENERATIVE_UI_FUNCTIONS, name)\n ? GENERATIVE_UI_FUNCTIONS[name]\n : undefined;\n if (declared === undefined && builtIn === undefined) {\n return appFunctions === undefined\n ? undefined\n : `function \"${name}\" is not exposed to generative UI`;\n }\n // Without the list of app functions, a built-in name may be the app's own\n // function, so the dispatcher applies the restriction when the call runs.\n if (declared === undefined && appFunctions === undefined) return undefined;\n return callerProblem(\n name,\n declared ?? builtIn!,\n label.startsWith(\"callRendererFunction\") ? \"agent\" : \"renderer\",\n );\n}\n\n/**\n * Why `caller` may not call a function with these permissions, or\n * `undefined` when it may. The dispatcher gives the same reasons at run\n * time, for the calls that are not validated against a function list.\n */\nexport function callerProblem(\n name: string,\n fn: A2UIFunctionPermissions,\n caller: \"agent\" | \"renderer\",\n) {\n const callers = functionCallers(fn);\n if (caller === \"agent\" && !callers.agent) {\n return fn.requiresUserActivation\n ? `function \"${name}\" runs only from a user gesture; the agent cannot call it`\n : `function \"${name}\" runs only in the UI (allowedCallers \"rendererOnly\"); the agent cannot call it`;\n }\n if (caller === \"renderer\" && !callers.renderer) {\n return `function \"${name}\" runs only for the agent (allowedCallers \"agentOnly\"); the UI cannot call it`;\n }\n return undefined;\n}\n\nfunction eventProblem(event: unknown) {\n if (!isRecord(event) || typeof event.name !== \"string\" || !event.name) {\n return \"event.name is required\";\n }\n const { userMessage, context } = event;\n const isUserMessage =\n userMessage === undefined ||\n typeof userMessage === \"string\" ||\n isPathBinding(userMessage) ||\n (isRecord(userMessage) &&\n typeof userMessage[\"@call\"] === \"string\" &&\n findForbiddenCall(userMessage, { allowValueFunctions: true }) ===\n undefined);\n if (!isUserMessage) {\n return isV09PathBinding(userMessage)\n ? `event.userMessage: ${V09_PATH_REASON}`\n : 'event.userMessage must be a string, {\"@path\": \"/x\"} or a function value';\n }\n if (context === undefined) return undefined;\n if (!isRecord(context)) return \"event.context must be an object\";\n const entries = Object.entries(context);\n for (const [key, entry] of entries) {\n if (isV09PathBinding(entry)) {\n return `event.context.${key}: ${V09_PATH_REASON}`;\n }\n const call = findForbiddenCall(entry, { allowValueFunctions: true });\n if (call !== undefined) {\n return `event.context.${key}: ${call}; a context value can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n return undefined;\n}\n\nfunction slotProblem(\n value: unknown,\n kind: \"single\" | \"multiple\",\n ownId: string,\n) {\n const isTemplate = isRecord(value) && \"componentId\" in value;\n if (kind === \"single\" && isTemplate) {\n return 'a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot';\n }\n if (kind === \"multiple\" && isTemplate) {\n return templateProblem(value, ownId);\n }\n if (kind === \"multiple\" && !Array.isArray(value)) {\n return 'must be an array of component ids or a template { \"componentId\", \"path\" }';\n }\n const ids = kind === \"multiple\" && Array.isArray(value) ? value : [value];\n for (const id of ids) {\n if (typeof id !== \"string\" || !id)\n return \"must reference component ids (strings)\";\n if (id === ownId) return \"a component cannot be its own child\";\n }\n return undefined;\n}\n\nfunction templateProblem(template: Record<string, unknown>, ownId: string) {\n const hasOnlyTemplateKeys = Object.keys(template).every(\n (key) => key === \"componentId\" || key === \"path\",\n );\n if (!hasOnlyTemplateKeys) {\n return 'a template takes only \"componentId\" and \"path\"';\n }\n const { componentId, path } = template;\n if (typeof componentId !== \"string\" || !componentId) {\n return \"template componentId must be a component id\";\n }\n if (componentId === ownId) return \"a component cannot be its own child\";\n if (typeof path !== \"string\" || !path) {\n return \"template path must be a JSON pointer or a relative path\";\n }\n return pathProblem(path, \"template path\");\n}\n\nconst VALUE_FUNCTION_LIST = `@index and the built-in functions (${Object.keys(\n GENERATIVE_UI_FUNCTIONS,\n)\n .filter(isA2UIValueFunction)\n .join(\", \")})`;\n\n/**\n * The reason for the first function call in `value` that a data value may\n * not make, at any depth, or `undefined`. A data value may call `@index`\n * and, with `allowValueFunctions`, the basic functions that need no user\n * gesture; the renderer resolves those. An app function, `openUrl`, or an\n * event binding is not a value.\n */\n// The annotation is needed: the function calls itself in its return.\nfunction findForbiddenCall(\n value: unknown,\n options: { allowValueFunctions: boolean },\n): string | undefined {\n if (Array.isArray(value)) {\n for (const item of value) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n }\n if (!isRecord(value)) return undefined;\n if (isIndexCall(value)) return undefined;\n if (value[\"@call\"] === \"@index\") return \"@index takes only an offset\";\n if (typeof value.call === \"string\") {\n return 'name the function with \"@call\", not \"call\"';\n }\n if (\"functionCall\" in value) {\n return \"an event binding is not a value\";\n }\n const name = value[\"@call\"];\n if (typeof name === \"string\") {\n if (!options.allowValueFunctions || !isA2UIValueFunction(name)) {\n return isA2UIBasicFunction(name)\n ? `\"${name}\" runs only from an event`\n : `\"${name}\" is not a basic function`;\n }\n const args = value.args;\n if (args !== undefined && !isRecord(args)) {\n return `the args of \"${name}\" must be an object`;\n }\n return args === undefined ? undefined : findForbiddenCall(args, options);\n }\n for (const item of Object.values(value)) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n}\n\nconst childRefCache = new WeakMap<GenerativeUIJSONSchema, ChildRef[]>();\n\n/** The component references of a props schema, computed once per schema. */\nfunction childRefsOf(props: GenerativeUIJSONSchema) {\n let refs = childRefCache.get(props);\n if (!refs) {\n refs = collectChildRefs(props);\n childRefCache.set(props, refs);\n }\n return refs;\n}\n\n/**\n * Checks the component ids at one reference of a node: a typed `child()`\n * or `childList()` prop, at any depth. A missing key is fine; the props\n * schema reports a required one.\n */\nfunction childRefProblem(\n node: Record<string, unknown>,\n ref: ChildRef,\n ownId: string,\n): string | undefined {\n const label = ref.path.filter((step) => step !== \"*\").join(\".\");\n const isDynamic = (value: unknown) =>\n isPathBinding(value) || (isRecord(value) && \"@call\" in value);\n const visit = (\n value: unknown,\n steps: readonly string[],\n ): string | undefined => {\n // A bound or computed value, at the reference or above it, is known\n // only at render.\n if (isDynamic(value)) return undefined;\n if (steps.length === 0) {\n const reason = slotProblem(value, ref.kind, ownId);\n return reason ? `${label}: ${reason}` : undefined;\n }\n const [head, ...rest] = steps;\n if (head === \"*\") {\n if (!Array.isArray(value)) return undefined;\n for (const item of value) {\n const reason = visit(item, rest);\n if (reason) return reason;\n }\n return undefined;\n }\n if (!isRecord(value) || !hasOwn(value, head)) return undefined;\n return visit(value[head], rest);\n };\n return visit(node, ref.path);\n}\n"],"mappings":";;;;;;AAwBA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACD;AAuCD,MAAM,KAA0B,EAAE,IAAI,MAAM;AAC5C,MAAM,QAAQ,YAAyC;CAAE,IAAI;CAAO;CAAQ;;AAG5E,MAAM,kBAAkB;AAExB,SAAS,OAAO,QAAgB,KAAa;AAC3C,QAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;;;;;;AAO1D,SAAS,SAAY,QAAuC,KAAa;AACvE,QAAO,UAAU,OAAO,QAAQ,IAAI,GAAG,OAAO,OAAO;;AAGvD,SAAgB,iBAAiB,IAAa;AAC5C,KAAI,CAACA,2BAAS,GAAG,CAAE,QAAO;CAC1B,MAAM,QAAQ,gBAAgB,QAAQ,SAAS,QAAQ,GAAG;AAC1D,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK;;;AAIzC,SAAgB,sBAAsB,IAAa;AACjD,KAAI,CAACA,2BAAS,GAAG,CAAE,QAAO;CAC1B,MAAM,OAAO,iBAAiB,GAAG;AACjC,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,UAAU,GAAG;AACnB,QAAOA,2BAAS,QAAQ,IAAI,OAAO,QAAQ,cAAc,WACrD,QAAQ,YACR;;;AAIN,SAAgB,cAAc,OAA8C;AAC1E,QACEA,2BAA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,OAAO;IACxB,MAAM,SAAS,MAAM,MAAM,KAAK;AAChC,QAAI,OAAQ,QAAO;;AAErB;;AAEF,MAAI,CAACA,2BAAS,MAAM,IAAI,CAAC,OAAO,OAAO,KAAK,CAAE,QAAO;AACrD,SAAO,MAAM,MAAM,OAAO,KAAK;;AAEjC,QAAO,MAAM,MAAM,IAAI,KAAK"}
|
|
1
|
+
{"version":3,"file":"validate-operation.cjs","names":["isRecord","A2UI_VERSION","GENERATIVE_UI_AGENT_FUNCTION_CALLS","GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON","isCallBinding","GENERATIVE_UI_FUNCTIONS","functionCallers","isA2UIValueFunction","isA2UIBasicFunction","collectChildRefs"],"sources":["../../src/generative-ui/validate-operation.ts"],"sourcesContent":["import {\n GENERATIVE_UI_FUNCTIONS,\n functionCallers,\n isA2UIBasicFunction,\n isA2UIValueFunction,\n isCallBinding,\n} from \"./basic-functions\";\nimport type { A2UIFunctionPermissions } from \"./basic-functions\";\nimport { collectChildRefs } from \"./child-refs\";\nimport type { ChildRef } from \"./child-refs\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON,\n} from \"./types\";\nimport type {\n GenerativeUIActionBinding,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\nimport { isRecord } from \"./is-record\";\n\nexport type OperationValidation = { ok: true } | { ok: false; reason: string };\n\nconst OPERATION_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n \"callRendererFunction\",\n] as const;\nexport type OperationKind = (typeof OPERATION_KINDS)[number];\n\nexport interface ValidateOperationOptions {\n manifest: Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"catalogIds\" | \"components\"\n >;\n /**\n * Surfaces that exist before this operation is applied. `updateComponents`,\n * `updateDataModel`, and `deleteSurface` need their surface in this set.\n */\n knownSurfaces: ReadonlySet<string>;\n /**\n * Surface ids that were created before, also the deleted ones. A surface id\n * is unique for the life of the page, so `createSurface` rejects them.\n */\n createdSurfaces?: ReadonlySet<string>;\n /**\n * UI-callable functions. When provided, `functionCall` bindings and\n * `callRendererFunction` must name one of them. The client omits it:\n * availability is checked when the function runs.\n */\n functions?: GenerativeUIManifest[\"functions\"];\n /**\n * The components that the target of the surface takes. When provided,\n * `updateComponents` and the inline components of `createSurface` can use\n * only these names. Left out, every catalog component is allowed.\n */\n allowedComponents?: AllowedComponents;\n}\n\n/** The component names that one target takes. */\nexport interface AllowedComponents {\n /** The target id, for the reason of a rejection. */\n target: string;\n names: ReadonlySet<string>;\n}\n\nconst OK: OperationValidation = { ok: true };\nconst fail = (reason: string): OperationValidation => ({ ok: false, reason });\n\n/** Models write the v0.9 binding from habit. The reason names the v1.0 form. */\nconst V09_PATH_REASON = 'bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}';\n\nfunction hasOwn(record: object, key: string) {\n return Object.prototype.hasOwnProperty.call(record, key);\n}\n\n/**\n * Reads an own property only. Model-controlled keys such as \"constructor\" or\n * \"toString\" must not resolve to Object.prototype members.\n */\nfunction ownValue<T>(record: Record<string, T> | undefined, key: string) {\n return record && hasOwn(record, key) ? record[key] : undefined;\n}\n\nexport function getOperationKind(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kinds = OPERATION_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/** The `surfaceId` of a surface operation. `callRendererFunction` has none. */\nexport function getOperationSurfaceId(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kind = getOperationKind(op);\n if (!kind) return undefined;\n const payload = op[kind];\n return isRecord(payload) && typeof payload.surfaceId === \"string\"\n ? payload.surfaceId\n : undefined;\n}\n\n/** `{ \"@path\": \"/x\" }`: a data-model binding. */\nexport function isPathBinding(value: unknown): value is { \"@path\": string } {\n return (\n isRecord(value) &&\n typeof value[\"@path\"] === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/** `{ \"path\": \"/x\" }`: the v0.9 binding, which v1.0 does not accept. */\nfunction isV09PathBinding(value: unknown) {\n return (\n isRecord(value) &&\n typeof value.path === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/**\n * `{ \"@call\": \"@index\" }` or `{ \"@call\": \"@index\", \"args\": { \"offset\": 1 } }`:\n * the 0-based position of the item in a template, plus `offset`.\n */\nexport function isIndexCall(\n value: unknown,\n): value is { \"@call\": \"@index\"; args?: { offset?: number } } {\n if (!isRecord(value) || value[\"@call\"] !== \"@index\") return false;\n const hasOnlyCallKeys = Object.keys(value).every(\n (key) => key === \"@call\" || key === \"args\",\n );\n if (!hasOnlyCallKeys) return false;\n const { args } = value;\n if (args === undefined) return true;\n return (\n isRecord(args) &&\n Object.keys(args).every((key) => key === \"offset\") &&\n (args.offset === undefined || Number.isFinite(args.offset))\n );\n}\n\nexport function isActionBinding(\n value: unknown,\n): value is GenerativeUIActionBinding {\n return (\n isRecord(value) &&\n Object.keys(value).length === 1 &&\n (isRecord(value.functionCall) || isRecord(value.event))\n );\n}\n\n/**\n * Checks one A2UI v1.0 operation against the catalog and the surfaces that\n * exist. The operation comes from the model, so nothing in it is trusted.\n *\n * @param op - The operation, as parsed from JSON.\n * @param options - The catalog, the known and created surfaces, the\n * functions that the UI can call, and the components that the target of\n * the surface takes.\n *\n * @example\n * ```ts\n * const result = validateOperation(op, { manifest, knownSurfaces });\n * if (!result.ok) rejected.push({ index, reason: result.reason });\n * ```\n */\nexport function validateOperation(\n op: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(op)) return fail(\"operation must be a JSON object\");\n if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));\n const kind = getOperationKind(op);\n if (!kind) {\n return fail(\n `operation must contain exactly one of ${OPERATION_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (kind === \"callRendererFunction\") {\n if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) {\n return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);\n }\n return validateRendererFunctionCall(payload, options);\n }\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return fail(`${kind}.surfaceId is required`);\n }\n const surfaceId = payload.surfaceId;\n if (kind === \"createSurface\") {\n return validateCreateSurface(payload, surfaceId, options);\n }\n if (!options.knownSurfaces.has(surfaceId)) {\n return fail(\n `surface \"${surfaceId}\" does not exist; send createSurface first`,\n );\n }\n switch (kind) {\n case \"deleteSurface\":\n return OK;\n case \"updateDataModel\":\n return validateDataModelUpdate(payload);\n case \"updateComponents\":\n return validateComponents(\n payload.components,\n \"updateComponents.components\",\n options,\n );\n }\n}\n\nfunction versionProblem(version: unknown) {\n return typeof version === \"string\"\n ? `unsupported version \"${version}\"; use \"${A2UI_VERSION}\"`\n : `operation needs \"version\":\"${A2UI_VERSION}\"`;\n}\n\n/** A `catalogId` can name the catalog of the run or one of its bases. */\nfunction catalogProblem(\n catalogId: unknown,\n manifest: ValidateOperationOptions[\"manifest\"],\n) {\n const ids = manifest.catalogIds ?? [manifest.catalogId];\n if (catalogId === undefined || ids.includes(catalogId as string)) {\n return undefined;\n }\n const names = ids.map((id) => `\"${id}\"`).join(\", \");\n const use = ids.length === 1 ? names : `one of: ${names}`;\n return `unknown catalog \"${String(catalogId)}\"; leave out catalogId or use ${use}`;\n}\n\nfunction validateCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n options: ValidateOperationOptions,\n) {\n if (options.knownSurfaces.has(surfaceId)) {\n return fail(`surface \"${surfaceId}\" already exists`);\n }\n if (options.createdSurfaces?.has(surfaceId)) {\n return fail(\n `surface id \"${surfaceId}\" was used before; use a new surfaceId`,\n );\n }\n const catalogReason = catalogProblem(payload.catalogId, options.manifest);\n if (catalogReason) return fail(catalogReason);\n const { dataModel, components } = payload;\n if (dataModel !== undefined && !isRecord(dataModel)) {\n return fail(\"createSurface.dataModel must be a JSON object\");\n }\n if (components === undefined) return OK;\n return validateComponents(components, \"createSurface.components\", options);\n}\n\nfunction validateRendererFunctionCall(\n payload: unknown,\n options: ValidateOperationOptions,\n) {\n const hasCallId =\n isRecord(payload) &&\n typeof payload.functionCallId === \"string\" &&\n payload.functionCallId !== \"\";\n if (!hasCallId) {\n return fail(\n \"callRendererFunction.functionCallId must be a non-empty string\",\n );\n }\n const reason = functionCallProblem(\n payload.callFunction,\n \"callRendererFunction.callFunction\",\n options,\n );\n return reason ? fail(reason) : OK;\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction decodeSegment(segment: string) {\n return segment.replace(/~([01])/g, (_, g) => (g === \"1\" ? \"/\" : \"~\"));\n}\n\nfunction validateDataModelUpdate(payload: Record<string, unknown>) {\n if (payload.value === undefined) {\n return fail(\n 'updateDataModel.value is required; use \"value\":null to delete',\n );\n }\n const path = payload.path ?? \"/\";\n if (typeof path !== \"string\" || !path.startsWith(\"/\")) {\n return fail(\"updateDataModel.path must be an absolute JSON pointer\");\n }\n if (path === \"/\") {\n // Paths such as \"/items\" point into the root, so the root must be an object.\n if (!isRecord(payload.value)) {\n return fail(\"a root updateDataModel value must be a JSON object\");\n }\n return OK;\n }\n const reason = pathProblem(path, \"updateDataModel.path\");\n return reason ? fail(reason) : OK;\n}\n\n/**\n * Checks the segments of an absolute JSON pointer (\"/a/b\") or of a path\n * relative to a template item (\"a/b\"). `label` names the field in the reason.\n */\nfunction pathProblem(path: string, label: string) {\n const relative = path.startsWith(\"/\") ? path.slice(1) : path;\n const segments = relative.split(\"/\");\n if (segments.some((segment) => segment === \"\")) {\n return `${label} must not contain empty segments`;\n }\n const decoded = segments.map(decodeSegment);\n const forbidden = decoded.find((segment) => FORBIDDEN_SEGMENTS.has(segment));\n if (forbidden !== undefined) {\n return `path segment \"${forbidden}\" is not allowed in ${label}`;\n }\n return undefined;\n}\n\nfunction validateComponents(\n components: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!Array.isArray(components) || components.length === 0) {\n return fail(`${label} must be a non-empty array`);\n }\n const ids = new Set<string>();\n for (const node of components) {\n if (!isRecord(node)) return fail(\"component must be a JSON object\");\n const { id } = node;\n if (typeof id !== \"string\" || !id) return fail(\"id is required\");\n const reason = nodeProblem(node, id, options);\n if (reason) return fail(`component \"${id}\": ${reason}`);\n if (ids.has(id)) {\n return fail(`component \"${id}\" appears twice in one update`);\n }\n ids.add(id);\n }\n return OK;\n}\n\nfunction nodeProblem(\n node: Record<string, unknown>,\n id: string,\n options: ValidateOperationOptions,\n) {\n if (typeof node.component !== \"string\") return \"component type is required\";\n const entry = ownValue(options.manifest.components, node.component);\n if (!entry) return `unknown component \"${node.component}\"`;\n const { allowedComponents } = options;\n if (allowedComponents && !allowedComponents.names.has(node.component)) {\n const names = [...allowedComponents.names].join(\", \") || \"none\";\n return `\"${node.component}\" is not allowed in target \"${allowedComponents.target}\"; use one of: ${names}`;\n }\n const { properties, required } = entry.props;\n const propNames = isRecord(properties) ? Object.keys(properties) : [];\n const props = Object.entries(node);\n for (const [key, value] of props) {\n if (key === \"id\" || key === \"component\") continue;\n if (key === \"catalogId\") {\n const reason = catalogProblem(value, options.manifest);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (key === \"metadata\") {\n const isMetadata =\n isRecord(value) &&\n (value.extensions === undefined || isRecord(value.extensions));\n if (!isMetadata) return 'metadata must be { \"extensions\": { ... } }';\n continue;\n }\n if (key === \"accessibility\") {\n const reason = accessibilityProblem(value);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (ownValue(entry.events, key)) {\n const reason = actionBindingProblem(value, options);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n const slot = ownValue(entry.slots, key);\n if (slot) {\n const reason = slotProblem(value, slot, id);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (!propNames.includes(key)) return `unknown prop \"${key}\"`;\n if (isV09PathBinding(value)) return `${key}: ${V09_PATH_REASON}`;\n const call = findForbiddenCall(value, { allowValueFunctions: true });\n if (call !== undefined) {\n return `${key}: ${call}; a data prop can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n for (const ref of childRefsOf(entry.props)) {\n const reason = childRefProblem(node, ref, id);\n if (reason) return reason;\n }\n const requiredNames = Array.isArray(required) ? required : [];\n for (const name of requiredNames) {\n if (typeof name === \"string\" && !(name in node)) {\n return `missing required prop \"${name}\"`;\n }\n }\n return undefined;\n}\n\nconst ACCESSIBILITY_KEYS = [\"label\", \"description\", \"live\", \"hidden\"];\nconst LIVE_VALUES = [\"off\", \"polite\", \"assertive\"];\n\n/**\n * Checks the `accessibility` of a component envelope: `label` and\n * `description` are strings or dynamic values, `live` is one of the ARIA\n * values, `hidden` is a boolean or a dynamic value.\n */\nfunction accessibilityProblem(value: unknown) {\n if (!isRecord(value)) {\n return 'must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }';\n }\n const isDynamic = (field: unknown) =>\n isPathBinding(field) || isCallBinding(field);\n for (const [key, field] of Object.entries(value)) {\n if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key \"${key}\"`;\n if (isV09PathBinding(field)) return `${key}: ${V09_PATH_REASON}`;\n if (isDynamic(field)) {\n const call = findForbiddenCall(field, { allowValueFunctions: true });\n if (call !== undefined) return `${key}: ${call}`;\n continue;\n }\n if (key === \"live\") {\n if (typeof field !== \"string\" || !LIVE_VALUES.includes(field)) {\n return `live must be one of ${LIVE_VALUES.join(\", \")}`;\n }\n } else if (key === \"hidden\") {\n if (typeof field !== \"boolean\") return \"hidden must be a boolean\";\n } else if (typeof field !== \"string\") {\n return `${key} must be a string`;\n }\n }\n return undefined;\n}\n\nfunction actionBindingProblem(\n value: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(value)) return \"must be an action object\";\n const keys = Object.keys(value);\n const isOneAction =\n keys.length === 1 && (keys[0] === \"functionCall\" || keys[0] === \"event\");\n if (!isOneAction) {\n return 'must be { \"event\": ... } or { \"functionCall\": ... }';\n }\n if (keys[0] === \"functionCall\") {\n return functionCallProblem(value.functionCall, \"functionCall\", options);\n }\n return eventProblem(value.event);\n}\n\n/**\n * Checks `{ \"@call\": \"<function>\", \"args\": { ... } }`. `label` names the\n * field in the reason.\n */\nfunction functionCallProblem(\n call: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(call)) {\n return `${label} must be { \"@call\": \"<function>\", \"args\": { ... } }`;\n }\n const name = call[\"@call\"];\n if (typeof name !== \"string\" || !name) {\n return typeof call.call === \"string\"\n ? `${label} names the function with \"@call\", not \"call\"`\n : `${label}[\"@call\"] must be a function name`;\n }\n const { args } = call;\n if (args !== undefined && !isRecord(args)) {\n return `${label}.args must be an object`;\n }\n const catalogReason = catalogProblem(call.catalogId, options.manifest);\n if (catalogReason) return `${label}: ${catalogReason}`;\n const argEntries = Object.entries(args ?? {});\n for (const [key, arg] of argEntries) {\n if (isV09PathBinding(arg))\n return `${label}.args.${key}: ${V09_PATH_REASON}`;\n }\n // A function the app declares under a built-in name is the app's; the\n // restrictions of the built-in do not apply to it.\n const appFunctions = options.functions;\n const declared =\n appFunctions !== undefined && hasOwn(appFunctions, name)\n ? appFunctions[name]\n : undefined;\n const builtIn =\n declared === undefined && hasOwn(GENERATIVE_UI_FUNCTIONS, name)\n ? GENERATIVE_UI_FUNCTIONS[name]\n : undefined;\n if (declared === undefined && builtIn === undefined) {\n return appFunctions === undefined\n ? undefined\n : `function \"${name}\" is not exposed to generative UI`;\n }\n // Without the list of app functions, a built-in name may be the app's own\n // function, so the dispatcher applies the restriction when the call runs.\n if (declared === undefined && appFunctions === undefined) return undefined;\n return callerProblem(\n name,\n declared ?? builtIn!,\n label.startsWith(\"callRendererFunction\") ? \"agent\" : \"renderer\",\n );\n}\n\n/**\n * Why `caller` may not call a function with these permissions, or\n * `undefined` when it may. The dispatcher gives the same reasons at run\n * time, for the calls that are not validated against a function list.\n */\nexport function callerProblem(\n name: string,\n fn: A2UIFunctionPermissions,\n caller: \"agent\" | \"renderer\",\n) {\n const callers = functionCallers(fn);\n if (caller === \"agent\" && !callers.agent) {\n return fn.requiresUserActivation\n ? `function \"${name}\" runs only from a user gesture; the agent cannot call it`\n : `function \"${name}\" runs only in the UI (allowedCallers \"rendererOnly\"); the agent cannot call it`;\n }\n if (caller === \"renderer\" && !callers.renderer) {\n return `function \"${name}\" runs only for the agent (allowedCallers \"agentOnly\"); the UI cannot call it`;\n }\n return undefined;\n}\n\nfunction eventProblem(event: unknown) {\n if (!isRecord(event) || typeof event.name !== \"string\" || !event.name) {\n return \"event.name is required\";\n }\n const { userMessage, context } = event;\n const isUserMessage =\n userMessage === undefined ||\n typeof userMessage === \"string\" ||\n isPathBinding(userMessage) ||\n (isRecord(userMessage) &&\n typeof userMessage[\"@call\"] === \"string\" &&\n findForbiddenCall(userMessage, { allowValueFunctions: true }) ===\n undefined);\n if (!isUserMessage) {\n return isV09PathBinding(userMessage)\n ? `event.userMessage: ${V09_PATH_REASON}`\n : 'event.userMessage must be a string, {\"@path\": \"/x\"} or a function value';\n }\n if (context === undefined) return undefined;\n if (!isRecord(context)) return \"event.context must be an object\";\n const entries = Object.entries(context);\n for (const [key, entry] of entries) {\n if (isV09PathBinding(entry)) {\n return `event.context.${key}: ${V09_PATH_REASON}`;\n }\n const call = findForbiddenCall(entry, { allowValueFunctions: true });\n if (call !== undefined) {\n return `event.context.${key}: ${call}; a context value can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n return undefined;\n}\n\nfunction slotProblem(\n value: unknown,\n kind: \"single\" | \"multiple\",\n ownId: string,\n) {\n const isTemplate = isRecord(value) && \"componentId\" in value;\n if (kind === \"single\" && isTemplate) {\n return 'a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot';\n }\n if (kind === \"multiple\" && isTemplate) {\n return templateProblem(value, ownId);\n }\n if (kind === \"multiple\" && !Array.isArray(value)) {\n return 'must be an array of component ids or a template { \"componentId\", \"path\" }';\n }\n const ids = kind === \"multiple\" && Array.isArray(value) ? value : [value];\n for (const id of ids) {\n if (typeof id !== \"string\" || !id)\n return \"must reference component ids (strings)\";\n if (id === ownId) return \"a component cannot be its own child\";\n }\n return undefined;\n}\n\nfunction templateProblem(template: Record<string, unknown>, ownId: string) {\n const hasOnlyTemplateKeys = Object.keys(template).every(\n (key) => key === \"componentId\" || key === \"path\",\n );\n if (!hasOnlyTemplateKeys) {\n return 'a template takes only \"componentId\" and \"path\"';\n }\n const { componentId, path } = template;\n if (typeof componentId !== \"string\" || !componentId) {\n return \"template componentId must be a component id\";\n }\n if (componentId === ownId) return \"a component cannot be its own child\";\n if (typeof path !== \"string\" || !path) {\n return \"template path must be a JSON pointer or a relative path\";\n }\n return pathProblem(path, \"template path\");\n}\n\nconst VALUE_FUNCTION_LIST = `@index and the built-in functions (${Object.keys(\n GENERATIVE_UI_FUNCTIONS,\n)\n .filter(isA2UIValueFunction)\n .join(\", \")})`;\n\n/**\n * The reason for the first function call in `value` that a data value may\n * not make, at any depth, or `undefined`. A data value may call `@index`\n * and, with `allowValueFunctions`, the basic functions that need no user\n * gesture; the renderer resolves those. An app function, `openUrl`, or an\n * event binding is not a value.\n */\n// The annotation is needed: the function calls itself in its return.\nfunction findForbiddenCall(\n value: unknown,\n options: { allowValueFunctions: boolean },\n): string | undefined {\n if (Array.isArray(value)) {\n for (const item of value) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n }\n if (!isRecord(value)) return undefined;\n if (isIndexCall(value)) return undefined;\n if (value[\"@call\"] === \"@index\") return \"@index takes only an offset\";\n if (typeof value.call === \"string\") {\n return 'name the function with \"@call\", not \"call\"';\n }\n if (\"functionCall\" in value) {\n return \"an event binding is not a value\";\n }\n const name = value[\"@call\"];\n if (typeof name === \"string\") {\n if (!options.allowValueFunctions || !isA2UIValueFunction(name)) {\n return isA2UIBasicFunction(name)\n ? `\"${name}\" runs only from an event`\n : `\"${name}\" is not a basic function`;\n }\n const args = value.args;\n if (args !== undefined && !isRecord(args)) {\n return `the args of \"${name}\" must be an object`;\n }\n return args === undefined ? undefined : findForbiddenCall(args, options);\n }\n for (const item of Object.values(value)) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n}\n\nconst childRefCache = new WeakMap<GenerativeUIJSONSchema, ChildRef[]>();\n\n/** The component references of a props schema, computed once per schema. */\nfunction childRefsOf(props: GenerativeUIJSONSchema) {\n let refs = childRefCache.get(props);\n if (!refs) {\n refs = collectChildRefs(props);\n childRefCache.set(props, refs);\n }\n return refs;\n}\n\n/**\n * Checks the component ids at one reference of a node: a typed `child()`\n * or `childList()` prop, at any depth. A missing key is fine; the props\n * schema reports a required one.\n */\nfunction childRefProblem(\n node: Record<string, unknown>,\n ref: ChildRef,\n ownId: string,\n): string | undefined {\n const label = ref.path.filter((step) => step !== \"*\").join(\".\");\n const isDynamic = (value: unknown) =>\n isPathBinding(value) || (isRecord(value) && \"@call\" in value);\n const visit = (\n value: unknown,\n steps: readonly string[],\n ): string | undefined => {\n // A bound or computed value, at the reference or above it, is known\n // only at render.\n if (isDynamic(value)) return undefined;\n const [head, ...rest] = steps;\n if (head === undefined) {\n const reason = slotProblem(value, ref.kind, ownId);\n return reason ? `${label}: ${reason}` : undefined;\n }\n if (head === \"*\") {\n if (!Array.isArray(value)) return undefined;\n for (const item of value) {\n const reason = visit(item, rest);\n if (reason) return reason;\n }\n return undefined;\n }\n if (!isRecord(value) || !hasOwn(value, head)) return undefined;\n return visit(value[head], rest);\n };\n return visit(node, ref.path);\n}\n"],"mappings":";;;;;;AAwBA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACD;AAuCD,MAAM,KAA0B,EAAE,IAAI,MAAM;AAC5C,MAAM,QAAQ,YAAyC;CAAE,IAAI;CAAO;CAAQ;;AAG5E,MAAM,kBAAkB;AAExB,SAAS,OAAO,QAAgB,KAAa;AAC3C,QAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;;;;;;AAO1D,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AO,KAAK;;AAEhC,QAAO;;;;;;;AAQT,SAAS,gBACP,MACA,KACA,OACoB;CACpB,MAAM,QAAQ,IAAI,KAAK,QAAQ,SAAS,SAAS,IAAI,CAAC,KAAK,IAAI;CAC/D,MAAM,aAAa,UACjB,cAAc,MAAM,IAAKT,2BAAS,MAAM,IAAI,WAAW;CACzD,MAAM,SACJ,OACA,UACuB;AAGvB,MAAI,UAAU,MAAM,CAAE,QAAO;EAC7B,MAAM,CAAC,MAAM,GAAG,QAAQ;AACxB,MAAI,SAAS,QAAW;GACtB,MAAM,SAAS,YAAY,OAAO,IAAI,MAAM,MAAM;AAClD,UAAO,SAAS,GAAG,MAAM,IAAI,WAAW;;AAE1C,MAAI,SAAS,KAAK;AAChB,OAAI,CAAC,MAAM,QAAQ,MAAM,CAAE,QAAO;AAClC,QAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,SAAS,MAAM,MAAM,KAAK;AAChC,QAAI,OAAQ,QAAO;;AAErB;;AAEF,MAAI,CAACA,2BAAS,MAAM,IAAI,CAAC,OAAO,OAAO,KAAK,CAAE,QAAO;AACrD,SAAO,MAAM,MAAM,OAAO,KAAK;;AAEjC,QAAO,MAAM,MAAM,IAAI,KAAK"}
|
|
@@ -375,11 +375,11 @@ function childRefProblem(node, ref, ownId) {
|
|
|
375
375
|
const isDynamic = (value) => isPathBinding(value) || 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) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-operation.mjs","names":[],"sources":["../../src/generative-ui/validate-operation.ts"],"sourcesContent":["import {\n GENERATIVE_UI_FUNCTIONS,\n functionCallers,\n isA2UIBasicFunction,\n isA2UIValueFunction,\n isCallBinding,\n} from \"./basic-functions\";\nimport type { A2UIFunctionPermissions } from \"./basic-functions\";\nimport { collectChildRefs } from \"./child-refs\";\nimport type { ChildRef } from \"./child-refs\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON,\n} from \"./types\";\nimport type {\n GenerativeUIActionBinding,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\nimport { isRecord } from \"./is-record\";\n\nexport type OperationValidation = { ok: true } | { ok: false; reason: string };\n\nconst OPERATION_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n \"callRendererFunction\",\n] as const;\nexport type OperationKind = (typeof OPERATION_KINDS)[number];\n\nexport interface ValidateOperationOptions {\n manifest: Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"catalogIds\" | \"components\"\n >;\n /**\n * Surfaces that exist before this operation is applied. `updateComponents`,\n * `updateDataModel`, and `deleteSurface` need their surface in this set.\n */\n knownSurfaces: ReadonlySet<string>;\n /**\n * Surface ids that were created before, also the deleted ones. A surface id\n * is unique for the life of the page, so `createSurface` rejects them.\n */\n createdSurfaces?: ReadonlySet<string>;\n /**\n * UI-callable functions. When provided, `functionCall` bindings and\n * `callRendererFunction` must name one of them. The client omits it:\n * availability is checked when the function runs.\n */\n functions?: GenerativeUIManifest[\"functions\"];\n /**\n * The components that the target of the surface takes. When provided,\n * `updateComponents` and the inline components of `createSurface` can use\n * only these names. Left out, every catalog component is allowed.\n */\n allowedComponents?: AllowedComponents;\n}\n\n/** The component names that one target takes. */\nexport interface AllowedComponents {\n /** The target id, for the reason of a rejection. */\n target: string;\n names: ReadonlySet<string>;\n}\n\nconst OK: OperationValidation = { ok: true };\nconst fail = (reason: string): OperationValidation => ({ ok: false, reason });\n\n/** Models write the v0.9 binding from habit. The reason names the v1.0 form. */\nconst V09_PATH_REASON = 'bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}';\n\nfunction hasOwn(record: object, key: string) {\n return Object.prototype.hasOwnProperty.call(record, key);\n}\n\n/**\n * Reads an own property only. Model-controlled keys such as \"constructor\" or\n * \"toString\" must not resolve to Object.prototype members.\n */\nfunction ownValue<T>(record: Record<string, T> | undefined, key: string) {\n return record && hasOwn(record, key) ? record[key] : undefined;\n}\n\nexport function getOperationKind(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kinds = OPERATION_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/** The `surfaceId` of a surface operation. `callRendererFunction` has none. */\nexport function getOperationSurfaceId(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kind = getOperationKind(op);\n if (!kind) return undefined;\n const payload = op[kind];\n return isRecord(payload) && typeof payload.surfaceId === \"string\"\n ? payload.surfaceId\n : undefined;\n}\n\n/** `{ \"@path\": \"/x\" }`: a data-model binding. */\nexport function isPathBinding(value: unknown): value is { \"@path\": string } {\n return (\n isRecord(value) &&\n typeof value[\"@path\"] === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/** `{ \"path\": \"/x\" }`: the v0.9 binding, which v1.0 does not accept. */\nfunction isV09PathBinding(value: unknown) {\n return (\n isRecord(value) &&\n typeof value.path === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/**\n * `{ \"@call\": \"@index\" }` or `{ \"@call\": \"@index\", \"args\": { \"offset\": 1 } }`:\n * the 0-based position of the item in a template, plus `offset`.\n */\nexport function isIndexCall(\n value: unknown,\n): value is { \"@call\": \"@index\"; args?: { offset?: number } } {\n if (!isRecord(value) || value[\"@call\"] !== \"@index\") return false;\n const hasOnlyCallKeys = Object.keys(value).every(\n (key) => key === \"@call\" || key === \"args\",\n );\n if (!hasOnlyCallKeys) return false;\n const { args } = value;\n if (args === undefined) return true;\n return (\n isRecord(args) &&\n Object.keys(args).every((key) => key === \"offset\") &&\n (args.offset === undefined || Number.isFinite(args.offset))\n );\n}\n\nexport function isActionBinding(\n value: unknown,\n): value is GenerativeUIActionBinding {\n return (\n isRecord(value) &&\n Object.keys(value).length === 1 &&\n (isRecord(value.functionCall) || isRecord(value.event))\n );\n}\n\n/**\n * Checks one A2UI v1.0 operation against the catalog and the surfaces that\n * exist. The operation comes from the model, so nothing in it is trusted.\n *\n * @param op - The operation, as parsed from JSON.\n * @param options - The catalog, the known and created surfaces, the\n * functions that the UI can call, and the components that the target of\n * the surface takes.\n *\n * @example\n * ```ts\n * const result = validateOperation(op, { manifest, knownSurfaces });\n * if (!result.ok) rejected.push({ index, reason: result.reason });\n * ```\n */\nexport function validateOperation(\n op: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(op)) return fail(\"operation must be a JSON object\");\n if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));\n const kind = getOperationKind(op);\n if (!kind) {\n return fail(\n `operation must contain exactly one of ${OPERATION_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (kind === \"callRendererFunction\") {\n if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) {\n return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);\n }\n return validateRendererFunctionCall(payload, options);\n }\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return fail(`${kind}.surfaceId is required`);\n }\n const surfaceId = payload.surfaceId;\n if (kind === \"createSurface\") {\n return validateCreateSurface(payload, surfaceId, options);\n }\n if (!options.knownSurfaces.has(surfaceId)) {\n return fail(\n `surface \"${surfaceId}\" does not exist; send createSurface first`,\n );\n }\n switch (kind) {\n case \"deleteSurface\":\n return OK;\n case \"updateDataModel\":\n return validateDataModelUpdate(payload);\n case \"updateComponents\":\n return validateComponents(\n payload.components,\n \"updateComponents.components\",\n options,\n );\n }\n}\n\nfunction versionProblem(version: unknown) {\n return typeof version === \"string\"\n ? `unsupported version \"${version}\"; use \"${A2UI_VERSION}\"`\n : `operation needs \"version\":\"${A2UI_VERSION}\"`;\n}\n\n/** A `catalogId` can name the catalog of the run or one of its bases. */\nfunction catalogProblem(\n catalogId: unknown,\n manifest: ValidateOperationOptions[\"manifest\"],\n) {\n const ids = manifest.catalogIds ?? [manifest.catalogId];\n if (catalogId === undefined || ids.includes(catalogId as string)) {\n return undefined;\n }\n const names = ids.map((id) => `\"${id}\"`).join(\", \");\n const use = ids.length === 1 ? names : `one of: ${names}`;\n return `unknown catalog \"${String(catalogId)}\"; leave out catalogId or use ${use}`;\n}\n\nfunction validateCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n options: ValidateOperationOptions,\n) {\n if (options.knownSurfaces.has(surfaceId)) {\n return fail(`surface \"${surfaceId}\" already exists`);\n }\n if (options.createdSurfaces?.has(surfaceId)) {\n return fail(\n `surface id \"${surfaceId}\" was used before; use a new surfaceId`,\n );\n }\n const catalogReason = catalogProblem(payload.catalogId, options.manifest);\n if (catalogReason) return fail(catalogReason);\n const { dataModel, components } = payload;\n if (dataModel !== undefined && !isRecord(dataModel)) {\n return fail(\"createSurface.dataModel must be a JSON object\");\n }\n if (components === undefined) return OK;\n return validateComponents(components, \"createSurface.components\", options);\n}\n\nfunction validateRendererFunctionCall(\n payload: unknown,\n options: ValidateOperationOptions,\n) {\n const hasCallId =\n isRecord(payload) &&\n typeof payload.functionCallId === \"string\" &&\n payload.functionCallId !== \"\";\n if (!hasCallId) {\n return fail(\n \"callRendererFunction.functionCallId must be a non-empty string\",\n );\n }\n const reason = functionCallProblem(\n payload.callFunction,\n \"callRendererFunction.callFunction\",\n options,\n );\n return reason ? fail(reason) : OK;\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction decodeSegment(segment: string) {\n return segment.replace(/~([01])/g, (_, g) => (g === \"1\" ? \"/\" : \"~\"));\n}\n\nfunction validateDataModelUpdate(payload: Record<string, unknown>) {\n if (payload.value === undefined) {\n return fail(\n 'updateDataModel.value is required; use \"value\":null to delete',\n );\n }\n const path = payload.path ?? \"/\";\n if (typeof path !== \"string\" || !path.startsWith(\"/\")) {\n return fail(\"updateDataModel.path must be an absolute JSON pointer\");\n }\n if (path === \"/\") {\n // Paths such as \"/items\" point into the root, so the root must be an object.\n if (!isRecord(payload.value)) {\n return fail(\"a root updateDataModel value must be a JSON object\");\n }\n return OK;\n }\n const reason = pathProblem(path, \"updateDataModel.path\");\n return reason ? fail(reason) : OK;\n}\n\n/**\n * Checks the segments of an absolute JSON pointer (\"/a/b\") or of a path\n * relative to a template item (\"a/b\"). `label` names the field in the reason.\n */\nfunction pathProblem(path: string, label: string) {\n const relative = path.startsWith(\"/\") ? path.slice(1) : path;\n const segments = relative.split(\"/\");\n if (segments.some((segment) => segment === \"\")) {\n return `${label} must not contain empty segments`;\n }\n const decoded = segments.map(decodeSegment);\n const forbidden = decoded.find((segment) => FORBIDDEN_SEGMENTS.has(segment));\n if (forbidden !== undefined) {\n return `path segment \"${forbidden}\" is not allowed in ${label}`;\n }\n return undefined;\n}\n\nfunction validateComponents(\n components: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!Array.isArray(components) || components.length === 0) {\n return fail(`${label} must be a non-empty array`);\n }\n const ids = new Set<string>();\n for (const node of components) {\n if (!isRecord(node)) return fail(\"component must be a JSON object\");\n const { id } = node;\n if (typeof id !== \"string\" || !id) return fail(\"id is required\");\n const reason = nodeProblem(node, id, options);\n if (reason) return fail(`component \"${id}\": ${reason}`);\n if (ids.has(id)) {\n return fail(`component \"${id}\" appears twice in one update`);\n }\n ids.add(id);\n }\n return OK;\n}\n\nfunction nodeProblem(\n node: Record<string, unknown>,\n id: string,\n options: ValidateOperationOptions,\n) {\n if (typeof node.component !== \"string\") return \"component type is required\";\n const entry = ownValue(options.manifest.components, node.component);\n if (!entry) return `unknown component \"${node.component}\"`;\n const { allowedComponents } = options;\n if (allowedComponents && !allowedComponents.names.has(node.component)) {\n const names = [...allowedComponents.names].join(\", \") || \"none\";\n return `\"${node.component}\" is not allowed in target \"${allowedComponents.target}\"; use one of: ${names}`;\n }\n const { properties, required } = entry.props;\n const propNames = isRecord(properties) ? Object.keys(properties) : [];\n const props = Object.entries(node);\n for (const [key, value] of props) {\n if (key === \"id\" || key === \"component\") continue;\n if (key === \"catalogId\") {\n const reason = catalogProblem(value, options.manifest);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (key === \"metadata\") {\n const isMetadata =\n isRecord(value) &&\n (value.extensions === undefined || isRecord(value.extensions));\n if (!isMetadata) return 'metadata must be { \"extensions\": { ... } }';\n continue;\n }\n if (key === \"accessibility\") {\n const reason = accessibilityProblem(value);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (ownValue(entry.events, key)) {\n const reason = actionBindingProblem(value, options);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n const slot = ownValue(entry.slots, key);\n if (slot) {\n const reason = slotProblem(value, slot, id);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (!propNames.includes(key)) return `unknown prop \"${key}\"`;\n if (isV09PathBinding(value)) return `${key}: ${V09_PATH_REASON}`;\n const call = findForbiddenCall(value, { allowValueFunctions: true });\n if (call !== undefined) {\n return `${key}: ${call}; a data prop can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n for (const ref of childRefsOf(entry.props)) {\n const reason = childRefProblem(node, ref, id);\n if (reason) return reason;\n }\n const requiredNames = Array.isArray(required) ? required : [];\n for (const name of requiredNames) {\n if (typeof name === \"string\" && !(name in node)) {\n return `missing required prop \"${name}\"`;\n }\n }\n return undefined;\n}\n\nconst ACCESSIBILITY_KEYS = [\"label\", \"description\", \"live\", \"hidden\"];\nconst LIVE_VALUES = [\"off\", \"polite\", \"assertive\"];\n\n/**\n * Checks the `accessibility` of a component envelope: `label` and\n * `description` are strings or dynamic values, `live` is one of the ARIA\n * values, `hidden` is a boolean or a dynamic value.\n */\nfunction accessibilityProblem(value: unknown) {\n if (!isRecord(value)) {\n return 'must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }';\n }\n const isDynamic = (field: unknown) =>\n isPathBinding(field) || isCallBinding(field);\n for (const [key, field] of Object.entries(value)) {\n if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key \"${key}\"`;\n if (isV09PathBinding(field)) return `${key}: ${V09_PATH_REASON}`;\n if (isDynamic(field)) {\n const call = findForbiddenCall(field, { allowValueFunctions: true });\n if (call !== undefined) return `${key}: ${call}`;\n continue;\n }\n if (key === \"live\") {\n if (typeof field !== \"string\" || !LIVE_VALUES.includes(field)) {\n return `live must be one of ${LIVE_VALUES.join(\", \")}`;\n }\n } else if (key === \"hidden\") {\n if (typeof field !== \"boolean\") return \"hidden must be a boolean\";\n } else if (typeof field !== \"string\") {\n return `${key} must be a string`;\n }\n }\n return undefined;\n}\n\nfunction actionBindingProblem(\n value: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(value)) return \"must be an action object\";\n const keys = Object.keys(value);\n const isOneAction =\n keys.length === 1 && (keys[0] === \"functionCall\" || keys[0] === \"event\");\n if (!isOneAction) {\n return 'must be { \"event\": ... } or { \"functionCall\": ... }';\n }\n if (keys[0] === \"functionCall\") {\n return functionCallProblem(value.functionCall, \"functionCall\", options);\n }\n return eventProblem(value.event);\n}\n\n/**\n * Checks `{ \"@call\": \"<function>\", \"args\": { ... } }`. `label` names the\n * field in the reason.\n */\nfunction functionCallProblem(\n call: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(call)) {\n return `${label} must be { \"@call\": \"<function>\", \"args\": { ... } }`;\n }\n const name = call[\"@call\"];\n if (typeof name !== \"string\" || !name) {\n return typeof call.call === \"string\"\n ? `${label} names the function with \"@call\", not \"call\"`\n : `${label}[\"@call\"] must be a function name`;\n }\n const { args } = call;\n if (args !== undefined && !isRecord(args)) {\n return `${label}.args must be an object`;\n }\n const catalogReason = catalogProblem(call.catalogId, options.manifest);\n if (catalogReason) return `${label}: ${catalogReason}`;\n const argEntries = Object.entries(args ?? {});\n for (const [key, arg] of argEntries) {\n if (isV09PathBinding(arg))\n return `${label}.args.${key}: ${V09_PATH_REASON}`;\n }\n // A function the app declares under a built-in name is the app's; the\n // restrictions of the built-in do not apply to it.\n const appFunctions = options.functions;\n const declared =\n appFunctions !== undefined && hasOwn(appFunctions, name)\n ? appFunctions[name]\n : undefined;\n const builtIn =\n declared === undefined && hasOwn(GENERATIVE_UI_FUNCTIONS, name)\n ? GENERATIVE_UI_FUNCTIONS[name]\n : undefined;\n if (declared === undefined && builtIn === undefined) {\n return appFunctions === undefined\n ? undefined\n : `function \"${name}\" is not exposed to generative UI`;\n }\n // Without the list of app functions, a built-in name may be the app's own\n // function, so the dispatcher applies the restriction when the call runs.\n if (declared === undefined && appFunctions === undefined) return undefined;\n return callerProblem(\n name,\n declared ?? builtIn!,\n label.startsWith(\"callRendererFunction\") ? \"agent\" : \"renderer\",\n );\n}\n\n/**\n * Why `caller` may not call a function with these permissions, or\n * `undefined` when it may. The dispatcher gives the same reasons at run\n * time, for the calls that are not validated against a function list.\n */\nexport function callerProblem(\n name: string,\n fn: A2UIFunctionPermissions,\n caller: \"agent\" | \"renderer\",\n) {\n const callers = functionCallers(fn);\n if (caller === \"agent\" && !callers.agent) {\n return fn.requiresUserActivation\n ? `function \"${name}\" runs only from a user gesture; the agent cannot call it`\n : `function \"${name}\" runs only in the UI (allowedCallers \"rendererOnly\"); the agent cannot call it`;\n }\n if (caller === \"renderer\" && !callers.renderer) {\n return `function \"${name}\" runs only for the agent (allowedCallers \"agentOnly\"); the UI cannot call it`;\n }\n return undefined;\n}\n\nfunction eventProblem(event: unknown) {\n if (!isRecord(event) || typeof event.name !== \"string\" || !event.name) {\n return \"event.name is required\";\n }\n const { userMessage, context } = event;\n const isUserMessage =\n userMessage === undefined ||\n typeof userMessage === \"string\" ||\n isPathBinding(userMessage) ||\n (isRecord(userMessage) &&\n typeof userMessage[\"@call\"] === \"string\" &&\n findForbiddenCall(userMessage, { allowValueFunctions: true }) ===\n undefined);\n if (!isUserMessage) {\n return isV09PathBinding(userMessage)\n ? `event.userMessage: ${V09_PATH_REASON}`\n : 'event.userMessage must be a string, {\"@path\": \"/x\"} or a function value';\n }\n if (context === undefined) return undefined;\n if (!isRecord(context)) return \"event.context must be an object\";\n const entries = Object.entries(context);\n for (const [key, entry] of entries) {\n if (isV09PathBinding(entry)) {\n return `event.context.${key}: ${V09_PATH_REASON}`;\n }\n const call = findForbiddenCall(entry, { allowValueFunctions: true });\n if (call !== undefined) {\n return `event.context.${key}: ${call}; a context value can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n return undefined;\n}\n\nfunction slotProblem(\n value: unknown,\n kind: \"single\" | \"multiple\",\n ownId: string,\n) {\n const isTemplate = isRecord(value) && \"componentId\" in value;\n if (kind === \"single\" && isTemplate) {\n return 'a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot';\n }\n if (kind === \"multiple\" && isTemplate) {\n return templateProblem(value, ownId);\n }\n if (kind === \"multiple\" && !Array.isArray(value)) {\n return 'must be an array of component ids or a template { \"componentId\", \"path\" }';\n }\n const ids = kind === \"multiple\" && Array.isArray(value) ? value : [value];\n for (const id of ids) {\n if (typeof id !== \"string\" || !id)\n return \"must reference component ids (strings)\";\n if (id === ownId) return \"a component cannot be its own child\";\n }\n return undefined;\n}\n\nfunction templateProblem(template: Record<string, unknown>, ownId: string) {\n const hasOnlyTemplateKeys = Object.keys(template).every(\n (key) => key === \"componentId\" || key === \"path\",\n );\n if (!hasOnlyTemplateKeys) {\n return 'a template takes only \"componentId\" and \"path\"';\n }\n const { componentId, path } = template;\n if (typeof componentId !== \"string\" || !componentId) {\n return \"template componentId must be a component id\";\n }\n if (componentId === ownId) return \"a component cannot be its own child\";\n if (typeof path !== \"string\" || !path) {\n return \"template path must be a JSON pointer or a relative path\";\n }\n return pathProblem(path, \"template path\");\n}\n\nconst VALUE_FUNCTION_LIST = `@index and the built-in functions (${Object.keys(\n GENERATIVE_UI_FUNCTIONS,\n)\n .filter(isA2UIValueFunction)\n .join(\", \")})`;\n\n/**\n * The reason for the first function call in `value` that a data value may\n * not make, at any depth, or `undefined`. A data value may call `@index`\n * and, with `allowValueFunctions`, the basic functions that need no user\n * gesture; the renderer resolves those. An app function, `openUrl`, or an\n * event binding is not a value.\n */\n// The annotation is needed: the function calls itself in its return.\nfunction findForbiddenCall(\n value: unknown,\n options: { allowValueFunctions: boolean },\n): string | undefined {\n if (Array.isArray(value)) {\n for (const item of value) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n }\n if (!isRecord(value)) return undefined;\n if (isIndexCall(value)) return undefined;\n if (value[\"@call\"] === \"@index\") return \"@index takes only an offset\";\n if (typeof value.call === \"string\") {\n return 'name the function with \"@call\", not \"call\"';\n }\n if (\"functionCall\" in value) {\n return \"an event binding is not a value\";\n }\n const name = value[\"@call\"];\n if (typeof name === \"string\") {\n if (!options.allowValueFunctions || !isA2UIValueFunction(name)) {\n return isA2UIBasicFunction(name)\n ? `\"${name}\" runs only from an event`\n : `\"${name}\" is not a basic function`;\n }\n const args = value.args;\n if (args !== undefined && !isRecord(args)) {\n return `the args of \"${name}\" must be an object`;\n }\n return args === undefined ? undefined : findForbiddenCall(args, options);\n }\n for (const item of Object.values(value)) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n}\n\nconst childRefCache = new WeakMap<GenerativeUIJSONSchema, ChildRef[]>();\n\n/** The component references of a props schema, computed once per schema. */\nfunction childRefsOf(props: GenerativeUIJSONSchema) {\n let refs = childRefCache.get(props);\n if (!refs) {\n refs = collectChildRefs(props);\n childRefCache.set(props, refs);\n }\n return refs;\n}\n\n/**\n * Checks the component ids at one reference of a node: a typed `child()`\n * or `childList()` prop, at any depth. A missing key is fine; the props\n * schema reports a required one.\n */\nfunction childRefProblem(\n node: Record<string, unknown>,\n ref: ChildRef,\n ownId: string,\n): string | undefined {\n const label = ref.path.filter((step) => step !== \"*\").join(\".\");\n const isDynamic = (value: unknown) =>\n isPathBinding(value) || (isRecord(value) && \"@call\" in value);\n const visit = (\n value: unknown,\n steps: readonly string[],\n ): string | undefined => {\n // A bound or computed value, at the reference or above it, is known\n // only at render.\n if (isDynamic(value)) return undefined;\n if (steps.length === 0) {\n const reason = slotProblem(value, ref.kind, ownId);\n return reason ? `${label}: ${reason}` : undefined;\n }\n const [head, ...rest] = steps;\n if (head === \"*\") {\n if (!Array.isArray(value)) return undefined;\n for (const item of value) {\n const reason = visit(item, rest);\n if (reason) return reason;\n }\n return undefined;\n }\n if (!isRecord(value) || !hasOwn(value, head)) return undefined;\n return visit(value[head], rest);\n };\n return visit(node, ref.path);\n}\n"],"mappings":";;;;;;AAwBA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACD;AAuCD,MAAM,KAA0B,EAAE,IAAI,MAAM;AAC5C,MAAM,QAAQ,YAAyC;CAAE,IAAI;CAAO;CAAQ;;AAG5E,MAAM,kBAAkB;AAExB,SAAS,OAAO,QAAgB,KAAa;AAC3C,QAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;;;;;;AAO1D,SAAS,SAAY,QAAuC,KAAa;AACvE,QAAO,UAAU,OAAO,QAAQ,IAAI,GAAG,OAAO,OAAO;;AAGvD,SAAgB,iBAAiB,IAAa;AAC5C,KAAI,CAAC,SAAS,GAAG,CAAE,QAAO;CAC1B,MAAM,QAAQ,gBAAgB,QAAQ,SAAS,QAAQ,GAAG;AAC1D,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK;;;AAIzC,SAAgB,sBAAsB,IAAa;AACjD,KAAI,CAAC,SAAS,GAAG,CAAE,QAAO;CAC1B,MAAM,OAAO,iBAAiB,GAAG;AACjC,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,UAAU,GAAG;AACnB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,MAAM,CAAE,QAAO;AAClC,QAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,SAAS,MAAM,MAAM,KAAK;AAChC,QAAI,OAAQ,QAAO;;AAErB;;AAEF,MAAI,CAAC,SAAS,MAAM,IAAI,CAAC,OAAO,OAAO,KAAK,CAAE,QAAO;AACrD,SAAO,MAAM,MAAM,OAAO,KAAK;;AAEjC,QAAO,MAAM,MAAM,IAAI,KAAK"}
|
|
1
|
+
{"version":3,"file":"validate-operation.mjs","names":[],"sources":["../../src/generative-ui/validate-operation.ts"],"sourcesContent":["import {\n GENERATIVE_UI_FUNCTIONS,\n functionCallers,\n isA2UIBasicFunction,\n isA2UIValueFunction,\n isCallBinding,\n} from \"./basic-functions\";\nimport type { A2UIFunctionPermissions } from \"./basic-functions\";\nimport { collectChildRefs } from \"./child-refs\";\nimport type { ChildRef } from \"./child-refs\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON,\n} from \"./types\";\nimport type {\n GenerativeUIActionBinding,\n GenerativeUIJSONSchema,\n GenerativeUIManifest,\n} from \"./types\";\nimport { isRecord } from \"./is-record\";\n\nexport type OperationValidation = { ok: true } | { ok: false; reason: string };\n\nconst OPERATION_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n \"callRendererFunction\",\n] as const;\nexport type OperationKind = (typeof OPERATION_KINDS)[number];\n\nexport interface ValidateOperationOptions {\n manifest: Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"catalogIds\" | \"components\"\n >;\n /**\n * Surfaces that exist before this operation is applied. `updateComponents`,\n * `updateDataModel`, and `deleteSurface` need their surface in this set.\n */\n knownSurfaces: ReadonlySet<string>;\n /**\n * Surface ids that were created before, also the deleted ones. A surface id\n * is unique for the life of the page, so `createSurface` rejects them.\n */\n createdSurfaces?: ReadonlySet<string>;\n /**\n * UI-callable functions. When provided, `functionCall` bindings and\n * `callRendererFunction` must name one of them. The client omits it:\n * availability is checked when the function runs.\n */\n functions?: GenerativeUIManifest[\"functions\"];\n /**\n * The components that the target of the surface takes. When provided,\n * `updateComponents` and the inline components of `createSurface` can use\n * only these names. Left out, every catalog component is allowed.\n */\n allowedComponents?: AllowedComponents;\n}\n\n/** The component names that one target takes. */\nexport interface AllowedComponents {\n /** The target id, for the reason of a rejection. */\n target: string;\n names: ReadonlySet<string>;\n}\n\nconst OK: OperationValidation = { ok: true };\nconst fail = (reason: string): OperationValidation => ({ ok: false, reason });\n\n/** Models write the v0.9 binding from habit. The reason names the v1.0 form. */\nconst V09_PATH_REASON = 'bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}';\n\nfunction hasOwn(record: object, key: string) {\n return Object.prototype.hasOwnProperty.call(record, key);\n}\n\n/**\n * Reads an own property only. Model-controlled keys such as \"constructor\" or\n * \"toString\" must not resolve to Object.prototype members.\n */\nfunction ownValue<T>(record: Record<string, T> | undefined, key: string) {\n return record && hasOwn(record, key) ? record[key] : undefined;\n}\n\nexport function getOperationKind(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kinds = OPERATION_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/** The `surfaceId` of a surface operation. `callRendererFunction` has none. */\nexport function getOperationSurfaceId(op: unknown) {\n if (!isRecord(op)) return undefined;\n const kind = getOperationKind(op);\n if (!kind) return undefined;\n const payload = op[kind];\n return isRecord(payload) && typeof payload.surfaceId === \"string\"\n ? payload.surfaceId\n : undefined;\n}\n\n/** `{ \"@path\": \"/x\" }`: a data-model binding. */\nexport function isPathBinding(value: unknown): value is { \"@path\": string } {\n return (\n isRecord(value) &&\n typeof value[\"@path\"] === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/** `{ \"path\": \"/x\" }`: the v0.9 binding, which v1.0 does not accept. */\nfunction isV09PathBinding(value: unknown) {\n return (\n isRecord(value) &&\n typeof value.path === \"string\" &&\n Object.keys(value).length === 1\n );\n}\n\n/**\n * `{ \"@call\": \"@index\" }` or `{ \"@call\": \"@index\", \"args\": { \"offset\": 1 } }`:\n * the 0-based position of the item in a template, plus `offset`.\n */\nexport function isIndexCall(\n value: unknown,\n): value is { \"@call\": \"@index\"; args?: { offset?: number } } {\n if (!isRecord(value) || value[\"@call\"] !== \"@index\") return false;\n const hasOnlyCallKeys = Object.keys(value).every(\n (key) => key === \"@call\" || key === \"args\",\n );\n if (!hasOnlyCallKeys) return false;\n const { args } = value;\n if (args === undefined) return true;\n return (\n isRecord(args) &&\n Object.keys(args).every((key) => key === \"offset\") &&\n (args.offset === undefined || Number.isFinite(args.offset))\n );\n}\n\nexport function isActionBinding(\n value: unknown,\n): value is GenerativeUIActionBinding {\n return (\n isRecord(value) &&\n Object.keys(value).length === 1 &&\n (isRecord(value.functionCall) || isRecord(value.event))\n );\n}\n\n/**\n * Checks one A2UI v1.0 operation against the catalog and the surfaces that\n * exist. The operation comes from the model, so nothing in it is trusted.\n *\n * @param op - The operation, as parsed from JSON.\n * @param options - The catalog, the known and created surfaces, the\n * functions that the UI can call, and the components that the target of\n * the surface takes.\n *\n * @example\n * ```ts\n * const result = validateOperation(op, { manifest, knownSurfaces });\n * if (!result.ok) rejected.push({ index, reason: result.reason });\n * ```\n */\nexport function validateOperation(\n op: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(op)) return fail(\"operation must be a JSON object\");\n if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));\n const kind = getOperationKind(op);\n if (!kind) {\n return fail(\n `operation must contain exactly one of ${OPERATION_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (kind === \"callRendererFunction\") {\n if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) {\n return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);\n }\n return validateRendererFunctionCall(payload, options);\n }\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return fail(`${kind}.surfaceId is required`);\n }\n const surfaceId = payload.surfaceId;\n if (kind === \"createSurface\") {\n return validateCreateSurface(payload, surfaceId, options);\n }\n if (!options.knownSurfaces.has(surfaceId)) {\n return fail(\n `surface \"${surfaceId}\" does not exist; send createSurface first`,\n );\n }\n switch (kind) {\n case \"deleteSurface\":\n return OK;\n case \"updateDataModel\":\n return validateDataModelUpdate(payload);\n case \"updateComponents\":\n return validateComponents(\n payload.components,\n \"updateComponents.components\",\n options,\n );\n }\n}\n\nfunction versionProblem(version: unknown) {\n return typeof version === \"string\"\n ? `unsupported version \"${version}\"; use \"${A2UI_VERSION}\"`\n : `operation needs \"version\":\"${A2UI_VERSION}\"`;\n}\n\n/** A `catalogId` can name the catalog of the run or one of its bases. */\nfunction catalogProblem(\n catalogId: unknown,\n manifest: ValidateOperationOptions[\"manifest\"],\n) {\n const ids = manifest.catalogIds ?? [manifest.catalogId];\n if (catalogId === undefined || ids.includes(catalogId as string)) {\n return undefined;\n }\n const names = ids.map((id) => `\"${id}\"`).join(\", \");\n const use = ids.length === 1 ? names : `one of: ${names}`;\n return `unknown catalog \"${String(catalogId)}\"; leave out catalogId or use ${use}`;\n}\n\nfunction validateCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n options: ValidateOperationOptions,\n) {\n if (options.knownSurfaces.has(surfaceId)) {\n return fail(`surface \"${surfaceId}\" already exists`);\n }\n if (options.createdSurfaces?.has(surfaceId)) {\n return fail(\n `surface id \"${surfaceId}\" was used before; use a new surfaceId`,\n );\n }\n const catalogReason = catalogProblem(payload.catalogId, options.manifest);\n if (catalogReason) return fail(catalogReason);\n const { dataModel, components } = payload;\n if (dataModel !== undefined && !isRecord(dataModel)) {\n return fail(\"createSurface.dataModel must be a JSON object\");\n }\n if (components === undefined) return OK;\n return validateComponents(components, \"createSurface.components\", options);\n}\n\nfunction validateRendererFunctionCall(\n payload: unknown,\n options: ValidateOperationOptions,\n) {\n const hasCallId =\n isRecord(payload) &&\n typeof payload.functionCallId === \"string\" &&\n payload.functionCallId !== \"\";\n if (!hasCallId) {\n return fail(\n \"callRendererFunction.functionCallId must be a non-empty string\",\n );\n }\n const reason = functionCallProblem(\n payload.callFunction,\n \"callRendererFunction.callFunction\",\n options,\n );\n return reason ? fail(reason) : OK;\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction decodeSegment(segment: string) {\n return segment.replace(/~([01])/g, (_, g) => (g === \"1\" ? \"/\" : \"~\"));\n}\n\nfunction validateDataModelUpdate(payload: Record<string, unknown>) {\n if (payload.value === undefined) {\n return fail(\n 'updateDataModel.value is required; use \"value\":null to delete',\n );\n }\n const path = payload.path ?? \"/\";\n if (typeof path !== \"string\" || !path.startsWith(\"/\")) {\n return fail(\"updateDataModel.path must be an absolute JSON pointer\");\n }\n if (path === \"/\") {\n // Paths such as \"/items\" point into the root, so the root must be an object.\n if (!isRecord(payload.value)) {\n return fail(\"a root updateDataModel value must be a JSON object\");\n }\n return OK;\n }\n const reason = pathProblem(path, \"updateDataModel.path\");\n return reason ? fail(reason) : OK;\n}\n\n/**\n * Checks the segments of an absolute JSON pointer (\"/a/b\") or of a path\n * relative to a template item (\"a/b\"). `label` names the field in the reason.\n */\nfunction pathProblem(path: string, label: string) {\n const relative = path.startsWith(\"/\") ? path.slice(1) : path;\n const segments = relative.split(\"/\");\n if (segments.some((segment) => segment === \"\")) {\n return `${label} must not contain empty segments`;\n }\n const decoded = segments.map(decodeSegment);\n const forbidden = decoded.find((segment) => FORBIDDEN_SEGMENTS.has(segment));\n if (forbidden !== undefined) {\n return `path segment \"${forbidden}\" is not allowed in ${label}`;\n }\n return undefined;\n}\n\nfunction validateComponents(\n components: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!Array.isArray(components) || components.length === 0) {\n return fail(`${label} must be a non-empty array`);\n }\n const ids = new Set<string>();\n for (const node of components) {\n if (!isRecord(node)) return fail(\"component must be a JSON object\");\n const { id } = node;\n if (typeof id !== \"string\" || !id) return fail(\"id is required\");\n const reason = nodeProblem(node, id, options);\n if (reason) return fail(`component \"${id}\": ${reason}`);\n if (ids.has(id)) {\n return fail(`component \"${id}\" appears twice in one update`);\n }\n ids.add(id);\n }\n return OK;\n}\n\nfunction nodeProblem(\n node: Record<string, unknown>,\n id: string,\n options: ValidateOperationOptions,\n) {\n if (typeof node.component !== \"string\") return \"component type is required\";\n const entry = ownValue(options.manifest.components, node.component);\n if (!entry) return `unknown component \"${node.component}\"`;\n const { allowedComponents } = options;\n if (allowedComponents && !allowedComponents.names.has(node.component)) {\n const names = [...allowedComponents.names].join(\", \") || \"none\";\n return `\"${node.component}\" is not allowed in target \"${allowedComponents.target}\"; use one of: ${names}`;\n }\n const { properties, required } = entry.props;\n const propNames = isRecord(properties) ? Object.keys(properties) : [];\n const props = Object.entries(node);\n for (const [key, value] of props) {\n if (key === \"id\" || key === \"component\") continue;\n if (key === \"catalogId\") {\n const reason = catalogProblem(value, options.manifest);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (key === \"metadata\") {\n const isMetadata =\n isRecord(value) &&\n (value.extensions === undefined || isRecord(value.extensions));\n if (!isMetadata) return 'metadata must be { \"extensions\": { ... } }';\n continue;\n }\n if (key === \"accessibility\") {\n const reason = accessibilityProblem(value);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (ownValue(entry.events, key)) {\n const reason = actionBindingProblem(value, options);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n const slot = ownValue(entry.slots, key);\n if (slot) {\n const reason = slotProblem(value, slot, id);\n if (reason) return `${key}: ${reason}`;\n continue;\n }\n if (!propNames.includes(key)) return `unknown prop \"${key}\"`;\n if (isV09PathBinding(value)) return `${key}: ${V09_PATH_REASON}`;\n const call = findForbiddenCall(value, { allowValueFunctions: true });\n if (call !== undefined) {\n return `${key}: ${call}; a data prop can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n for (const ref of childRefsOf(entry.props)) {\n const reason = childRefProblem(node, ref, id);\n if (reason) return reason;\n }\n const requiredNames = Array.isArray(required) ? required : [];\n for (const name of requiredNames) {\n if (typeof name === \"string\" && !(name in node)) {\n return `missing required prop \"${name}\"`;\n }\n }\n return undefined;\n}\n\nconst ACCESSIBILITY_KEYS = [\"label\", \"description\", \"live\", \"hidden\"];\nconst LIVE_VALUES = [\"off\", \"polite\", \"assertive\"];\n\n/**\n * Checks the `accessibility` of a component envelope: `label` and\n * `description` are strings or dynamic values, `live` is one of the ARIA\n * values, `hidden` is a boolean or a dynamic value.\n */\nfunction accessibilityProblem(value: unknown) {\n if (!isRecord(value)) {\n return 'must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }';\n }\n const isDynamic = (field: unknown) =>\n isPathBinding(field) || isCallBinding(field);\n for (const [key, field] of Object.entries(value)) {\n if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key \"${key}\"`;\n if (isV09PathBinding(field)) return `${key}: ${V09_PATH_REASON}`;\n if (isDynamic(field)) {\n const call = findForbiddenCall(field, { allowValueFunctions: true });\n if (call !== undefined) return `${key}: ${call}`;\n continue;\n }\n if (key === \"live\") {\n if (typeof field !== \"string\" || !LIVE_VALUES.includes(field)) {\n return `live must be one of ${LIVE_VALUES.join(\", \")}`;\n }\n } else if (key === \"hidden\") {\n if (typeof field !== \"boolean\") return \"hidden must be a boolean\";\n } else if (typeof field !== \"string\") {\n return `${key} must be a string`;\n }\n }\n return undefined;\n}\n\nfunction actionBindingProblem(\n value: unknown,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(value)) return \"must be an action object\";\n const keys = Object.keys(value);\n const isOneAction =\n keys.length === 1 && (keys[0] === \"functionCall\" || keys[0] === \"event\");\n if (!isOneAction) {\n return 'must be { \"event\": ... } or { \"functionCall\": ... }';\n }\n if (keys[0] === \"functionCall\") {\n return functionCallProblem(value.functionCall, \"functionCall\", options);\n }\n return eventProblem(value.event);\n}\n\n/**\n * Checks `{ \"@call\": \"<function>\", \"args\": { ... } }`. `label` names the\n * field in the reason.\n */\nfunction functionCallProblem(\n call: unknown,\n label: string,\n options: ValidateOperationOptions,\n) {\n if (!isRecord(call)) {\n return `${label} must be { \"@call\": \"<function>\", \"args\": { ... } }`;\n }\n const name = call[\"@call\"];\n if (typeof name !== \"string\" || !name) {\n return typeof call.call === \"string\"\n ? `${label} names the function with \"@call\", not \"call\"`\n : `${label}[\"@call\"] must be a function name`;\n }\n const { args } = call;\n if (args !== undefined && !isRecord(args)) {\n return `${label}.args must be an object`;\n }\n const catalogReason = catalogProblem(call.catalogId, options.manifest);\n if (catalogReason) return `${label}: ${catalogReason}`;\n const argEntries = Object.entries(args ?? {});\n for (const [key, arg] of argEntries) {\n if (isV09PathBinding(arg))\n return `${label}.args.${key}: ${V09_PATH_REASON}`;\n }\n // A function the app declares under a built-in name is the app's; the\n // restrictions of the built-in do not apply to it.\n const appFunctions = options.functions;\n const declared =\n appFunctions !== undefined && hasOwn(appFunctions, name)\n ? appFunctions[name]\n : undefined;\n const builtIn =\n declared === undefined && hasOwn(GENERATIVE_UI_FUNCTIONS, name)\n ? GENERATIVE_UI_FUNCTIONS[name]\n : undefined;\n if (declared === undefined && builtIn === undefined) {\n return appFunctions === undefined\n ? undefined\n : `function \"${name}\" is not exposed to generative UI`;\n }\n // Without the list of app functions, a built-in name may be the app's own\n // function, so the dispatcher applies the restriction when the call runs.\n if (declared === undefined && appFunctions === undefined) return undefined;\n return callerProblem(\n name,\n declared ?? builtIn!,\n label.startsWith(\"callRendererFunction\") ? \"agent\" : \"renderer\",\n );\n}\n\n/**\n * Why `caller` may not call a function with these permissions, or\n * `undefined` when it may. The dispatcher gives the same reasons at run\n * time, for the calls that are not validated against a function list.\n */\nexport function callerProblem(\n name: string,\n fn: A2UIFunctionPermissions,\n caller: \"agent\" | \"renderer\",\n) {\n const callers = functionCallers(fn);\n if (caller === \"agent\" && !callers.agent) {\n return fn.requiresUserActivation\n ? `function \"${name}\" runs only from a user gesture; the agent cannot call it`\n : `function \"${name}\" runs only in the UI (allowedCallers \"rendererOnly\"); the agent cannot call it`;\n }\n if (caller === \"renderer\" && !callers.renderer) {\n return `function \"${name}\" runs only for the agent (allowedCallers \"agentOnly\"); the UI cannot call it`;\n }\n return undefined;\n}\n\nfunction eventProblem(event: unknown) {\n if (!isRecord(event) || typeof event.name !== \"string\" || !event.name) {\n return \"event.name is required\";\n }\n const { userMessage, context } = event;\n const isUserMessage =\n userMessage === undefined ||\n typeof userMessage === \"string\" ||\n isPathBinding(userMessage) ||\n (isRecord(userMessage) &&\n typeof userMessage[\"@call\"] === \"string\" &&\n findForbiddenCall(userMessage, { allowValueFunctions: true }) ===\n undefined);\n if (!isUserMessage) {\n return isV09PathBinding(userMessage)\n ? `event.userMessage: ${V09_PATH_REASON}`\n : 'event.userMessage must be a string, {\"@path\": \"/x\"} or a function value';\n }\n if (context === undefined) return undefined;\n if (!isRecord(context)) return \"event.context must be an object\";\n const entries = Object.entries(context);\n for (const [key, entry] of entries) {\n if (isV09PathBinding(entry)) {\n return `event.context.${key}: ${V09_PATH_REASON}`;\n }\n const call = findForbiddenCall(entry, { allowValueFunctions: true });\n if (call !== undefined) {\n return `event.context.${key}: ${call}; a context value can call only ${VALUE_FUNCTION_LIST}`;\n }\n }\n return undefined;\n}\n\nfunction slotProblem(\n value: unknown,\n kind: \"single\" | \"multiple\",\n ownId: string,\n) {\n const isTemplate = isRecord(value) && \"componentId\" in value;\n if (kind === \"single\" && isTemplate) {\n return 'a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot';\n }\n if (kind === \"multiple\" && isTemplate) {\n return templateProblem(value, ownId);\n }\n if (kind === \"multiple\" && !Array.isArray(value)) {\n return 'must be an array of component ids or a template { \"componentId\", \"path\" }';\n }\n const ids = kind === \"multiple\" && Array.isArray(value) ? value : [value];\n for (const id of ids) {\n if (typeof id !== \"string\" || !id)\n return \"must reference component ids (strings)\";\n if (id === ownId) return \"a component cannot be its own child\";\n }\n return undefined;\n}\n\nfunction templateProblem(template: Record<string, unknown>, ownId: string) {\n const hasOnlyTemplateKeys = Object.keys(template).every(\n (key) => key === \"componentId\" || key === \"path\",\n );\n if (!hasOnlyTemplateKeys) {\n return 'a template takes only \"componentId\" and \"path\"';\n }\n const { componentId, path } = template;\n if (typeof componentId !== \"string\" || !componentId) {\n return \"template componentId must be a component id\";\n }\n if (componentId === ownId) return \"a component cannot be its own child\";\n if (typeof path !== \"string\" || !path) {\n return \"template path must be a JSON pointer or a relative path\";\n }\n return pathProblem(path, \"template path\");\n}\n\nconst VALUE_FUNCTION_LIST = `@index and the built-in functions (${Object.keys(\n GENERATIVE_UI_FUNCTIONS,\n)\n .filter(isA2UIValueFunction)\n .join(\", \")})`;\n\n/**\n * The reason for the first function call in `value` that a data value may\n * not make, at any depth, or `undefined`. A data value may call `@index`\n * and, with `allowValueFunctions`, the basic functions that need no user\n * gesture; the renderer resolves those. An app function, `openUrl`, or an\n * event binding is not a value.\n */\n// The annotation is needed: the function calls itself in its return.\nfunction findForbiddenCall(\n value: unknown,\n options: { allowValueFunctions: boolean },\n): string | undefined {\n if (Array.isArray(value)) {\n for (const item of value) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n }\n if (!isRecord(value)) return undefined;\n if (isIndexCall(value)) return undefined;\n if (value[\"@call\"] === \"@index\") return \"@index takes only an offset\";\n if (typeof value.call === \"string\") {\n return 'name the function with \"@call\", not \"call\"';\n }\n if (\"functionCall\" in value) {\n return \"an event binding is not a value\";\n }\n const name = value[\"@call\"];\n if (typeof name === \"string\") {\n if (!options.allowValueFunctions || !isA2UIValueFunction(name)) {\n return isA2UIBasicFunction(name)\n ? `\"${name}\" runs only from an event`\n : `\"${name}\" is not a basic function`;\n }\n const args = value.args;\n if (args !== undefined && !isRecord(args)) {\n return `the args of \"${name}\" must be an object`;\n }\n return args === undefined ? undefined : findForbiddenCall(args, options);\n }\n for (const item of Object.values(value)) {\n const reason = findForbiddenCall(item, options);\n if (reason !== undefined) return reason;\n }\n return undefined;\n}\n\nconst childRefCache = new WeakMap<GenerativeUIJSONSchema, ChildRef[]>();\n\n/** The component references of a props schema, computed once per schema. */\nfunction childRefsOf(props: GenerativeUIJSONSchema) {\n let refs = childRefCache.get(props);\n if (!refs) {\n refs = collectChildRefs(props);\n childRefCache.set(props, refs);\n }\n return refs;\n}\n\n/**\n * Checks the component ids at one reference of a node: a typed `child()`\n * or `childList()` prop, at any depth. A missing key is fine; the props\n * schema reports a required one.\n */\nfunction childRefProblem(\n node: Record<string, unknown>,\n ref: ChildRef,\n ownId: string,\n): string | undefined {\n const label = ref.path.filter((step) => step !== \"*\").join(\".\");\n const isDynamic = (value: unknown) =>\n isPathBinding(value) || (isRecord(value) && \"@call\" in value);\n const visit = (\n value: unknown,\n steps: readonly string[],\n ): string | undefined => {\n // A bound or computed value, at the reference or above it, is known\n // only at render.\n if (isDynamic(value)) return undefined;\n const [head, ...rest] = steps;\n if (head === undefined) {\n const reason = slotProblem(value, ref.kind, ownId);\n return reason ? `${label}: ${reason}` : undefined;\n }\n if (head === \"*\") {\n if (!Array.isArray(value)) return undefined;\n for (const item of value) {\n const reason = visit(item, rest);\n if (reason) return reason;\n }\n return undefined;\n }\n if (!isRecord(value) || !hasOwn(value, head)) return undefined;\n return visit(value[head], rest);\n };\n return visit(node, ref.path);\n}\n"],"mappings":";;;;;;AAwBA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACD;AAuCD,MAAM,KAA0B,EAAE,IAAI,MAAM;AAC5C,MAAM,QAAQ,YAAyC;CAAE,IAAI;CAAO;CAAQ;;AAG5E,MAAM,kBAAkB;AAExB,SAAS,OAAO,QAAgB,KAAa;AAC3C,QAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;;;;;;AAO1D,SAAS,SAAY,QAAuC,KAAa;AACvE,QAAO,UAAU,OAAO,QAAQ,IAAI,GAAG,OAAO,OAAO;;AAGvD,SAAgB,iBAAiB,IAAa;AAC5C,KAAI,CAAC,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,WAAW;CACzD,MAAM,SACJ,OACA,UACuB;AAGvB,MAAI,UAAU,MAAM,CAAE,QAAO;EAC7B,MAAM,CAAC,MAAM,GAAG,QAAQ;AACxB,MAAI,SAAS,QAAW;GACtB,MAAM,SAAS,YAAY,OAAO,IAAI,MAAM,MAAM;AAClD,UAAO,SAAS,GAAG,MAAM,IAAI,WAAW;;AAE1C,MAAI,SAAS,KAAK;AAChB,OAAI,CAAC,MAAM,QAAQ,MAAM,CAAE,QAAO;AAClC,QAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,SAAS,MAAM,MAAM,KAAK;AAChC,QAAI,OAAQ,QAAO;;AAErB;;AAEF,MAAI,CAAC,SAAS,MAAM,IAAI,CAAC,OAAO,OAAO,KAAK,CAAE,QAAO;AACrD,SAAO,MAAM,MAAM,OAAO,KAAK;;AAEjC,QAAO,MAAM,MAAM,IAAI,KAAK"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1542,7 +1542,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1542
1542
|
try {
|
|
1543
1543
|
var _firstNonBlankTelemet;
|
|
1544
1544
|
const payload = parts[1];
|
|
1545
|
-
if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
1545
|
+
if (payload === void 0 || !/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
1546
1546
|
let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
1547
1547
|
const padding = (4 - b64.length % 4) % 4;
|
|
1548
1548
|
b64 += "=".repeat(padding);
|
|
@@ -2113,7 +2113,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2113
2113
|
|
|
2114
2114
|
//#endregion
|
|
2115
2115
|
//#region package.json
|
|
2116
|
-
var version = "2.0.0-rc.
|
|
2116
|
+
var version = "2.0.0-rc.16";
|
|
2117
2117
|
|
|
2118
2118
|
//#endregion
|
|
2119
2119
|
//#region src/generative-ui/basic-functions.ts
|
|
@@ -2391,8 +2391,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2391
2391
|
else if (isRecord$2(value) && typeof value.componentId === "string") ids.push(value.componentId);
|
|
2392
2392
|
};
|
|
2393
2393
|
const visit = (value, path) => {
|
|
2394
|
-
if (path.length === 0) return collect(value);
|
|
2395
2394
|
const [head, ...rest] = path;
|
|
2395
|
+
if (head === void 0) return collect(value);
|
|
2396
2396
|
if (head === "*") {
|
|
2397
2397
|
if (Array.isArray(value)) value.forEach((item) => visit(item, rest));
|
|
2398
2398
|
return;
|
|
@@ -2411,8 +2411,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2411
2411
|
const isDynamic = (value) => isRecord$2(value) && ("@path" in value || "@call" in value);
|
|
2412
2412
|
const visit = (value, path) => {
|
|
2413
2413
|
if (isDynamic(value)) return true;
|
|
2414
|
-
if (path.length === 0) return false;
|
|
2415
2414
|
const [head, ...rest] = path;
|
|
2415
|
+
if (head === void 0) return false;
|
|
2416
2416
|
if (head === "*") return Array.isArray(value) && value.some((item) => visit(item, rest));
|
|
2417
2417
|
return isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
|
|
2418
2418
|
};
|
|
@@ -2424,8 +2424,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2424
2424
|
* else keeps its identity. Missing keys are left alone.
|
|
2425
2425
|
*/
|
|
2426
2426
|
function mapAtChildRef(value, path, replace) {
|
|
2427
|
-
if (path.length === 0) return replace(value);
|
|
2428
2427
|
const [head, ...rest] = path;
|
|
2428
|
+
if (head === void 0) return replace(value);
|
|
2429
2429
|
if (head === "*") {
|
|
2430
2430
|
if (!Array.isArray(value)) return value;
|
|
2431
2431
|
return value.map((item) => mapAtChildRef(item, rest, replace));
|
|
@@ -2440,7 +2440,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2440
2440
|
//#endregion
|
|
2441
2441
|
//#region src/generative-ui/types.ts
|
|
2442
2442
|
/** A2UI protocol version used on the wire. */
|
|
2443
|
-
const A2UI_VERSION = "
|
|
2443
|
+
const A2UI_VERSION = "1.0";
|
|
2444
2444
|
/** Activity type of a generated surface message. */
|
|
2445
2445
|
const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
2446
2446
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -2504,7 +2504,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2504
2504
|
* @example
|
|
2505
2505
|
* ```ts
|
|
2506
2506
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
2507
|
-
* // { version: "
|
|
2507
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
2508
2508
|
* ```
|
|
2509
2509
|
*/
|
|
2510
2510
|
function toA2UIActionMessage(event) {
|
|
@@ -2582,8 +2582,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2582
2582
|
"Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target limits its components, its surfaces can use only those components.",
|
|
2583
2583
|
"Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
|
|
2584
2584
|
"Keep each operation whole on its line.",
|
|
2585
|
-
"Give every operation \"version\":\"
|
|
2586
|
-
"Start a surface with one createSurface. Put all the initial data in \"dataModel\" and the \"root\" component in \"components\". Then write the children in updateComponents lines, so that they show while you write:\n ```a2ui\n {\"version\":\"
|
|
2585
|
+
"Give every operation \"version\":\"1.0\".",
|
|
2586
|
+
"Start a surface with one createSurface. Put all the initial data in \"dataModel\" and the \"root\" component in \"components\". Then write the children in updateComponents lines, so that they show while you write:\n ```a2ui\n {\"version\":\"1.0\",\"createSurface\":{\"surfaceId\":\"plan-picker\",\"dataModel\":{ ...initial data... },\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"seats\",\"pick\"]}]}}\n {\"version\":\"1.0\",\"updateComponents\":{\"surfaceId\":\"plan-picker\",\"components\":[ ...the children... ]}}\n ```",
|
|
2587
2587
|
"Keep \"dataModel\" flat: top-level keys such as \"seats\" or \"form\", never one wrapper object around everything. Check that every { and [ you open in a line is closed.",
|
|
2588
2588
|
"Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
|
|
2589
2589
|
"Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.",
|
|
@@ -2604,7 +2604,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2604
2604
|
"For a computed list (chart data, template items) use series. Its description under Functions in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.",
|
|
2605
2605
|
"Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
|
|
2606
2606
|
"The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use \"yes\" and \"no\", not true and false.",
|
|
2607
|
-
"To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"
|
|
2607
|
+
"To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
|
|
2608
2608
|
"Set \"value\":null to delete the key at \"path\".",
|
|
2609
2609
|
{
|
|
2610
2610
|
when: ["events"],
|
|
@@ -2645,9 +2645,9 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2645
2645
|
{
|
|
2646
2646
|
when: ["agentCalls"],
|
|
2647
2647
|
items: [
|
|
2648
|
-
"To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"
|
|
2648
|
+
"To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.",
|
|
2649
2649
|
"Give every callRendererFunction a new functionCallId. Call only a function that the schema marks UI or agent, or agent only; a function with no mark is for the UI only. A function marked agent only is only for callRendererFunction: do not bind an event to it.",
|
|
2650
|
-
"The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"
|
|
2650
|
+
"The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.",
|
|
2651
2651
|
"Do not guess the result of a callRendererFunction. Wait for the developer message."
|
|
2652
2652
|
]
|
|
2653
2653
|
},
|
|
@@ -2662,13 +2662,13 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2662
2662
|
intro: `Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).`,
|
|
2663
2663
|
whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,
|
|
2664
2664
|
operations: [
|
|
2665
|
-
"{\"version\":\"
|
|
2666
|
-
"{\"version\":\"
|
|
2667
|
-
"{\"version\":\"
|
|
2668
|
-
"{\"version\":\"
|
|
2665
|
+
"{\"version\":\"1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
|
|
2666
|
+
"{\"version\":\"1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
|
|
2667
|
+
"{\"version\":\"1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
|
|
2668
|
+
"{\"version\":\"1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
|
|
2669
2669
|
{
|
|
2670
2670
|
when: ["agentCalls"],
|
|
2671
|
-
items: ["{\"version\":\"
|
|
2671
|
+
items: ["{\"version\":\"1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."]
|
|
2672
2672
|
}
|
|
2673
2673
|
],
|
|
2674
2674
|
rules: [
|
|
@@ -2700,7 +2700,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2700
2700
|
},
|
|
2701
2701
|
{
|
|
2702
2702
|
when: ["agentCalls"],
|
|
2703
|
-
items: ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"
|
|
2703
|
+
items: ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."]
|
|
2704
2704
|
}
|
|
2705
2705
|
]
|
|
2706
2706
|
},
|
|
@@ -3025,7 +3025,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
3025
3025
|
return isRecord$2(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
3026
3026
|
}
|
|
3027
3027
|
function isEnvelope(value) {
|
|
3028
|
-
return isRecord$2(value) && isCapabilities(value["
|
|
3028
|
+
return isRecord$2(value) && isCapabilities(value["1.0"]) && isRecord$2(value.metadata) && isExtensions(value.metadata.extensions);
|
|
3029
3029
|
}
|
|
3030
3030
|
/**
|
|
3031
3031
|
* Reads the generative UI envelope from the `forwardedProps` of a run.
|
|
@@ -3081,7 +3081,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
3081
3081
|
*/
|
|
3082
3082
|
function envelopeToManifest(envelope) {
|
|
3083
3083
|
var _catalog$components, _catalog$functions;
|
|
3084
|
-
const { supportedCatalogIds, inlineCatalogs } = envelope["
|
|
3084
|
+
const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
|
|
3085
3085
|
const catalogId = supportedCatalogIds[0];
|
|
3086
3086
|
const catalog = inlineCatalogs === null || inlineCatalogs === void 0 ? void 0 : inlineCatalogs.find((entry) => entry.catalogId === catalogId);
|
|
3087
3087
|
const extensions = envelope.metadata.extensions;
|
|
@@ -3481,11 +3481,11 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
3481
3481
|
const isDynamic = (value) => isPathBinding(value) || isRecord$2(value) && "@call" in value;
|
|
3482
3482
|
const visit = (value, steps) => {
|
|
3483
3483
|
if (isDynamic(value)) return void 0;
|
|
3484
|
-
|
|
3484
|
+
const [head, ...rest] = steps;
|
|
3485
|
+
if (head === void 0) {
|
|
3485
3486
|
const reason = slotProblem(value, ref.kind, ownId);
|
|
3486
3487
|
return reason ? `${label}: ${reason}` : void 0;
|
|
3487
3488
|
}
|
|
3488
|
-
const [head, ...rest] = steps;
|
|
3489
3489
|
if (head === "*") {
|
|
3490
3490
|
if (!Array.isArray(value)) return void 0;
|
|
3491
3491
|
for (const item of value) {
|
|
@@ -4043,7 +4043,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
4043
4043
|
const unknown = [];
|
|
4044
4044
|
for (const [key, description] of Object.entries(overrides)) {
|
|
4045
4045
|
const [name, prop, ...rest] = key.split(".");
|
|
4046
|
-
const component = hasOwn(components, name) ? components[name] : void 0;
|
|
4046
|
+
const component = name !== void 0 && hasOwn(components, name) ? components[name] : void 0;
|
|
4047
4047
|
if (!component || rest.length > 0) {
|
|
4048
4048
|
unknown.push(key);
|
|
4049
4049
|
continue;
|
|
@@ -4132,7 +4132,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
4132
4132
|
`## Generative UI
|
|
4133
4133
|
${intro}
|
|
4134
4134
|
|
|
4135
|
-
${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"
|
|
4135
|
+
${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"1.0" and exactly one of:
|
|
4136
4136
|
${operations.map((op) => `- ${op}`).join("\n")}
|
|
4137
4137
|
|
|
4138
4138
|
Rules:
|