@copilotkit/runtime 2.0.0-rc.42 → 2.0.0-rc.44

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.
Files changed (63) hide show
  1. package/dist/agent/converters/aisdk.cjs +1 -1
  2. package/dist/agent/converters/aisdk.mjs +1 -1
  3. package/dist/agent/converters/tanstack.cjs +1 -1
  4. package/dist/agent/converters/tanstack.mjs +1 -1
  5. package/dist/index.cjs +2 -1
  6. package/dist/index.d.cts +3 -2
  7. package/dist/index.d.mts +3 -2
  8. package/dist/index.mjs +3 -2
  9. package/dist/runtime/core/package-info.cjs +1 -1
  10. package/dist/runtime/core/package-info.mjs +1 -1
  11. package/dist/runtime/core/runtime.cjs +1 -19
  12. package/dist/runtime/core/runtime.cjs.map +1 -1
  13. package/dist/runtime/core/runtime.d.cts +77 -29
  14. package/dist/runtime/core/runtime.d.cts.map +1 -1
  15. package/dist/runtime/core/runtime.d.mts +77 -29
  16. package/dist/runtime/core/runtime.d.mts.map +1 -1
  17. package/dist/runtime/core/runtime.mjs +2 -19
  18. package/dist/runtime/core/runtime.mjs.map +1 -1
  19. package/dist/runtime/event-transforms/recorded-events.cjs +4 -0
  20. package/dist/runtime/event-transforms/recorded-events.cjs.map +1 -1
  21. package/dist/runtime/event-transforms/recorded-events.d.cts +5 -1
  22. package/dist/runtime/event-transforms/recorded-events.d.cts.map +1 -1
  23. package/dist/runtime/event-transforms/recorded-events.d.mts +5 -1
  24. package/dist/runtime/event-transforms/recorded-events.d.mts.map +1 -1
  25. package/dist/runtime/event-transforms/recorded-events.mjs +4 -0
  26. package/dist/runtime/event-transforms/recorded-events.mjs.map +1 -1
  27. package/dist/runtime/generative-ui/a2ui-v09-actions.cjs +106 -0
  28. package/dist/runtime/generative-ui/a2ui-v09-actions.cjs.map +1 -0
  29. package/dist/runtime/generative-ui/a2ui-v09-actions.mjs +106 -0
  30. package/dist/runtime/generative-ui/a2ui-v09-actions.mjs.map +1 -0
  31. package/dist/runtime/generative-ui/a2ui-v09-catalog.cjs +422 -0
  32. package/dist/runtime/generative-ui/a2ui-v09-catalog.cjs.map +1 -0
  33. package/dist/runtime/generative-ui/a2ui-v09-catalog.mjs +422 -0
  34. package/dist/runtime/generative-ui/a2ui-v09-catalog.mjs.map +1 -0
  35. package/dist/runtime/generative-ui/a2ui-v09-middleware.cjs +84 -0
  36. package/dist/runtime/generative-ui/a2ui-v09-middleware.cjs.map +1 -0
  37. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.cts +41 -0
  38. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.cts.map +1 -0
  39. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.mts +41 -0
  40. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.mts.map +1 -0
  41. package/dist/runtime/generative-ui/a2ui-v09-middleware.mjs +83 -0
  42. package/dist/runtime/generative-ui/a2ui-v09-middleware.mjs.map +1 -0
  43. package/dist/runtime/generative-ui/a2ui-v09-operations.cjs +620 -0
  44. package/dist/runtime/generative-ui/a2ui-v09-operations.cjs.map +1 -0
  45. package/dist/runtime/generative-ui/a2ui-v09-operations.mjs +620 -0
  46. package/dist/runtime/generative-ui/a2ui-v09-operations.mjs.map +1 -0
  47. package/dist/runtime/generative-ui/index.d.cts +1 -0
  48. package/dist/runtime/generative-ui/index.d.mts +1 -0
  49. package/dist/runtime/handlers/get-runtime-info.cjs +19 -5
  50. package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
  51. package/dist/runtime/handlers/get-runtime-info.mjs +20 -6
  52. package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
  53. package/dist/runtime/handlers/handle-run.cjs +0 -2
  54. package/dist/runtime/handlers/handle-run.cjs.map +1 -1
  55. package/dist/runtime/handlers/handle-run.mjs +0 -2
  56. package/dist/runtime/handlers/handle-run.mjs.map +1 -1
  57. package/dist/runtime/handlers/shared/agent-utils.cjs +17 -14
  58. package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  59. package/dist/runtime/handlers/shared/agent-utils.mjs +18 -15
  60. package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  61. package/dist/runtime/index.d.cts +2 -1
  62. package/dist/runtime/index.d.mts +2 -1
  63. package/package.json +6 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-v09-operations.mjs","names":[],"sources":["../../../src/runtime/generative-ui/a2ui-v09-operations.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type {\n ActivityDeltaEvent,\n ActivitySnapshotEvent,\n BaseEvent,\n} from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CHAT_TARGET,\n cloneValue,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\nimport { STANDARD_CATALOG_ID } from \"@copilotkit/shared/generative-ui\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The activity type and content key of v0.9 surfaces, as\n * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.\n */\nconst A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\nconst A2UI_OPERATIONS_KEY = \"a2ui_operations\";\n\n/** The `version` values of A2UI v0.9 messages. */\nconst V09_VERSIONS: ReadonlySet<string> = new Set([\"v0.9\", \"v0.9.1\"]);\nconst V09_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n] as const;\ntype V09Kind = (typeof V09_KINDS)[number];\n\n/**\n * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of\n * the published catalog document. Both become the standard catalog, which has\n * the same 18 components.\n */\nconst V09_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\",\n \"https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json\",\n]);\n\n/**\n * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for\n * example ADK) send. It has the 18 components of the v0.9 basic catalog\n * with 1.0 bindings, so it becomes the standard catalog too.\n */\nconst V10_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json\",\n]);\n\n/** The A2UI version that an `a2ui-surface` operation was written in. */\ntype SourceVersion = \"0.9\" | \"1.0\";\n\n/** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */\nconst HEADING_SIZES: Readonly<Record<string, string>> = {\n h1: \"2xl\",\n h2: \"xl\",\n h3: \"lg\",\n h4: \"md\",\n h5: \"sm\",\n};\n\n/** The one v0.9 operation key of `op`, when it has exactly one. */\nfunction v09Kind(op: Record<string, unknown>): V09Kind | undefined {\n const kinds = V09_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/**\n * True for an A2UI v0.9 operation: an object whose `version` is `\"v0.9\"` (or\n * `\"v0.9.1\"`). An object without `version` counts when it has exactly one\n * v0.9 operation key with an object payload. A 1.0 operation always carries\n * `version: \"1.0\"` (the client rejects one without it), and v0.8 uses other\n * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with\n * a v0.9 key can only be v0.9. Agents leave `version` out often enough that\n * requiring it would drop their surfaces.\n *\n * @example\n * ```ts\n * isA2UIV09Operation({ version: \"v0.9\", deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ version: \"1.0\", deleteSurface: { surfaceId: \"s\" } }); // false\n * ```\n */\nexport function isA2UIV09Operation(value: unknown): boolean {\n if (!isRecord(value)) return false;\n if (value.version !== undefined) {\n return typeof value.version === \"string\" && V09_VERSIONS.has(value.version);\n }\n const kind = v09Kind(value);\n return kind !== undefined && isRecord(value[kind]);\n}\n\n// Checked with `ok === false`: runtime compiles non-strict, where a check of\n// `reason` does not narrow the union.\ntype Converted<T> = { ok: true; value: T } | { ok: false; reason: string };\n\nconst ok = <T>(value: T): { ok: true; value: T } => ({ ok: true, value });\nconst failed = (reason: string): { ok: false; reason: string } => ({\n ok: false,\n reason,\n});\n\n/**\n * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ \"@path\" }` and\n * `{ call, args }` becomes `{ \"@call\", args }`, at any depth. Literals stay.\n */\nfunction convertValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(convertValue);\n if (!isRecord(value)) return value;\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.path === \"string\") {\n return { \"@path\": value.path };\n }\n const isCall =\n typeof value.call === \"string\" &&\n keys.every(\n (key) => key === \"call\" || key === \"args\" || key === \"returnType\",\n );\n if (isCall) return convertCall(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, convertValue(item)]),\n );\n}\n\n/** A v0.9 function call `{ call, args, returnType }` as `{ \"@call\", args }`. */\nfunction convertCall(call: Record<string, unknown>) {\n return {\n \"@call\": call.call as string,\n ...(call.args === undefined ? {} : { args: convertValue(call.args) }),\n };\n}\n\n/** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */\nfunction isV09Action(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n return (\n keys.length === 1 && (isRecord(value.event) || isRecord(value.functionCall))\n );\n}\n\n/**\n * A v0.9 action as a 1.0 event binding. The event keeps its name and\n * context (with converted values); a function call gets the `@call` form.\n */\nfunction convertAction(action: unknown): Converted<unknown> {\n if (!isV09Action(action)) {\n return failed('action must be { \"event\": ... } or { \"functionCall\": ... }');\n }\n if (isRecord(action.functionCall)) {\n const call = action.functionCall;\n if (typeof call.call !== \"string\" || !call.call) {\n return failed(\"action.functionCall.call must be a function name\");\n }\n return ok({ functionCall: convertCall(call) });\n }\n const event = action.event as Record<string, unknown>;\n if (typeof event.name !== \"string\" || !event.name) {\n return failed(\"action.event.name is required\");\n }\n return ok({\n event: {\n name: event.name,\n ...(event.context === undefined\n ? {}\n : { context: convertValue(event.context) }),\n },\n });\n}\n\n/**\n * The basic-catalog changes of one component. Every other prop keeps its\n * name; the 1.0 standard catalog uses the v0.9 names.\n *\n * - `Text` with a heading `variant` becomes `Title` (h1 \"2xl\" to h5 \"sm\"),\n * with `caption` it becomes `Caption`; `variant` goes. Title and Caption\n * have no `weight`, so it goes too.\n * - `Button.action` becomes `onClick`.\n * - `TextField.validationRegexp` becomes a `regex` check on its value.\n */\nfunction applyBasicCatalogChanges(node: Record<string, unknown>) {\n if (node.component === \"Text\" && \"variant\" in node) {\n const { variant, ...rest } = node;\n const size =\n typeof variant === \"string\" ? HEADING_SIZES[variant] : undefined;\n if (size !== undefined) {\n const { weight: _weight, ...title } = rest;\n return { ...title, component: \"Title\", size };\n }\n if (variant === \"caption\") {\n const { weight: _weight, ...caption } = rest;\n return { ...caption, component: \"Caption\" };\n }\n return rest;\n }\n if (node.component === \"Button\" && \"action\" in node) {\n const { action, ...rest } = node;\n return { ...rest, onClick: action };\n }\n if (node.component === \"TextField\" && \"validationRegexp\" in node) {\n const { validationRegexp, ...rest } = node;\n if (typeof validationRegexp !== \"string\" || rest.value === undefined) {\n return rest;\n }\n const check = {\n condition: {\n \"@call\": \"regex\",\n args: { value: rest.value, pattern: validationRegexp },\n },\n };\n const checks = Array.isArray(rest.checks) ? rest.checks : [];\n return { ...rest, checks: [...checks, check] };\n }\n return node;\n}\n\n/** One v0.9 component (flat format) as a 1.0 component node. */\nfunction convertComponent(node: unknown): Converted<A2UIComponentNode> {\n if (!isRecord(node) || typeof node.id !== \"string\" || !node.id) {\n return failed(\"a component needs a string id\");\n }\n if (typeof node.component !== \"string\" || !node.component) {\n return failed(\n `component \"${node.id}\": the component type must be a string (the v0.9 flat format)`,\n );\n }\n const converted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\") {\n converted[key] = value;\n } else if (key === \"action\" || isV09Action(value)) {\n const action = convertAction(value);\n if (action.ok === false) {\n return failed(`component \"${node.id}\": ${action.reason}`);\n }\n converted[key] = action.value;\n } else {\n converted[key] = convertValue(value);\n }\n }\n return ok(applyBasicCatalogChanges(converted) as A2UIComponentNode);\n}\n\nfunction convertUpdateComponents(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { components } = payload;\n if (!Array.isArray(components) || components.length === 0) {\n return failed(\"updateComponents.components must be a non-empty array\");\n }\n const nodes: A2UIComponentNode[] = [];\n for (const component of components) {\n const converted = convertComponent(component);\n if (converted.ok === false) return converted;\n nodes.push(converted.value);\n }\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n });\n}\n\n/**\n * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it\n * for `null`. At the root, removing means an empty data model.\n */\nfunction convertUpdateDataModel(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { path, value } = payload;\n if (path !== undefined && typeof path !== \"string\") {\n return failed(\"updateDataModel.path must be a string\");\n }\n const relative = typeof path === \"string\" ? path : \"\";\n const pointer = relative.startsWith(\"/\") ? relative : `/${relative}`;\n const isRoot = pointer === \"/\";\n if (isRoot && value !== undefined && !isRecord(value)) {\n return failed(\n \"a root updateDataModel value must be a JSON object in A2UI 1.0\",\n );\n }\n const nextValue = value === undefined ? (isRoot ? {} : null) : value;\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path: pointer, value: nextValue },\n });\n}\n\nfunction convertCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n): A2UIOperation {\n const { catalogId } = payload;\n const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;\n return {\n version: A2UI_VERSION,\n createSurface: {\n surfaceId,\n ...(typeof catalogId === \"string\" && catalogId\n ? {\n catalogId: V09_BASIC_CATALOG_IDS.has(catalogId)\n ? STANDARD_CATALOG_ID\n : catalogId,\n }\n : {}),\n ...(typeof sendDataModel === \"boolean\" ? { sendDataModel } : {}),\n },\n };\n}\n\n/** Basic catalog components as standard ones; anything else stays. */\nfunction standardComponents(components: unknown) {\n return Array.isArray(components)\n ? components.map((node) =>\n isRecord(node) ? applyBasicCatalogChanges(node) : node,\n )\n : components;\n}\n\n/**\n * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic\n * catalog id becomes the standard catalog id, and the basic catalog\n * components (inline in createSurface, or in updateComponents) get the\n * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.\n * Everything else stays; the client validates the operation.\n */\nfunction upgradeV10Operation(op: Record<string, unknown>): A2UIOperation {\n const { createSurface: create, updateComponents: update } = op;\n if (isRecord(create)) {\n const { catalogId } = create;\n return {\n ...op,\n createSurface: {\n ...create,\n ...(typeof catalogId === \"string\" &&\n V10_BASIC_CATALOG_IDS.has(catalogId)\n ? { catalogId: STANDARD_CATALOG_ID }\n : {}),\n ...(create.components === undefined\n ? {}\n : { components: standardComponents(create.components) }),\n },\n } as A2UIOperation;\n }\n if (isRecord(update)) {\n return {\n ...op,\n updateComponents: {\n ...update,\n ...(update.components === undefined\n ? {}\n : { components: standardComponents(update.components) }),\n },\n } as A2UIOperation;\n }\n return op as A2UIOperation;\n}\n\n/** One operation as 1.0, or why it cannot be converted. */\nfunction upgradeOperation(op: unknown): Converted<A2UIOperation> {\n if (!isRecord(op)) return failed(\"operation must be a JSON object\");\n if (op.version === A2UI_VERSION) return ok(upgradeV10Operation(op));\n if (!isA2UIV09Operation(op)) {\n return failed(\n typeof op.version === \"string\"\n ? `unsupported A2UI version \"${op.version}\"; only v0.9 and 1.0 operations are supported`\n : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const kind = v09Kind(op);\n if (!kind) {\n return failed(\n `operation must contain exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return failed(`${kind}.surfaceId is required`);\n }\n const { surfaceId } = payload;\n switch (kind) {\n case \"createSurface\":\n return ok(convertCreateSurface(payload, surfaceId));\n case \"updateComponents\":\n return convertUpdateComponents(payload, surfaceId);\n case \"updateDataModel\":\n return convertUpdateDataModel(payload, surfaceId);\n case \"deleteSurface\":\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n deleteSurface: { surfaceId },\n });\n }\n}\n\n/**\n * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.\n *\n * - createSurface: the v0.9 basic catalog id becomes the standard catalog\n * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no\n * 1.0 field and goes; `sendDataModel` stays.\n * - updateComponents: `{ path }` becomes `{ \"@path\" }` and `{ call, args }`\n * becomes `{ \"@call\", args }` at any depth; an action becomes an\n * `{ event }` or `{ functionCall }` binding; child lists and templates\n * stay. See {@link applyBasicCatalogChanges} for the props that change.\n * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at\n * the root.\n * - deleteSurface: unchanged.\n *\n * An operation that is already 1.0 (native, for example from ADK) keeps its\n * form: only the 1.0 basic catalog id becomes the standard catalog id, and\n * its basic catalog components get the same changes as v0.9 ones. Any other\n * operation, and any v0.9 operation that cannot be converted, goes to\n * `dropped` with the reason.\n *\n * @example\n * ```ts\n * upgradeA2UIV09Operations([\n * { version: \"v0.9\", updateDataModel: { surfaceId: \"s\", path: \"/x\" } },\n * ]);\n * // { operations: [{ version: \"1.0\", updateDataModel: { surfaceId: \"s\", path: \"/x\", value: null } }], dropped: [] }\n * ```\n */\nexport function upgradeA2UIV09Operations(operations: unknown[]): {\n operations: A2UIOperation[];\n dropped: Array<{ operation: unknown; reason: string }>;\n} {\n const upgraded: A2UIOperation[] = [];\n const dropped: Array<{ operation: unknown; reason: string }> = [];\n for (const operation of Array.isArray(operations) ? operations : []) {\n let result: Converted<A2UIOperation>;\n try {\n result = upgradeOperation(operation);\n } catch (error) {\n // A getter or a Proxy trap of the operation threw while it was read.\n result = failed(\n `operation could not be read: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n if (result.ok === false) {\n dropped.push({ operation, reason: result.reason });\n } else {\n upgraded.push(result.value);\n }\n }\n return { operations: upgraded, dropped };\n}\n\n/** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */\nfunction surfaceIdOf(op: unknown) {\n if (!isRecord(op)) return undefined;\n for (const kind of V09_KINDS) {\n const payload = op[kind];\n if (isRecord(payload) && typeof payload.surfaceId === \"string\") {\n return payload.surfaceId || undefined;\n }\n }\n return undefined;\n}\n\n/** The operations of `a2ui-surface` content. Lifecycle content has none. */\nfunction readOperations(content: unknown): unknown[] {\n if (!isRecord(content)) return [];\n const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;\n return Array.isArray(operations) ? operations : [];\n}\n\ntype JsonPatchOperation = {\n op: \"add\" | \"remove\" | \"replace\" | \"move\" | \"copy\" | \"test\";\n path: string;\n from?: string;\n value?: unknown;\n};\n\nfunction pointerSegments(pointer: string) {\n if (pointer === \"\") return [];\n if (!pointer.startsWith(\"/\")) throw new Error(`invalid pointer \"${pointer}\"`);\n return pointer\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Applies RFC 6902 operations to `document` in place and returns the new\n * root. Throws on a path that does not resolve, like `fast-json-patch` in\n * the AG-UI client, so a bad delta leaves the stored content alone.\n */\nfunction applyJsonPatch(document: unknown, patch: unknown): unknown {\n if (!Array.isArray(patch)) throw new Error(\"patch must be an array\");\n let root = document;\n const parentOf = (pointer: string) => {\n const segments = pointerSegments(pointer);\n const key = segments.pop();\n let parent: unknown = root;\n for (const segment of segments) {\n if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error(\"forbidden path\");\n parent = Array.isArray(parent)\n ? parent[Number(segment)]\n : isRecord(parent)\n ? parent[segment]\n : undefined;\n if (parent === undefined) throw new Error(`path \"${pointer}\" not found`);\n }\n if (key !== undefined && FORBIDDEN_SEGMENTS.has(key)) {\n throw new Error(\"forbidden path\");\n }\n return { parent, key };\n };\n const read = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) return root;\n if (Array.isArray(parent)) return parent[Number(key)];\n return isRecord(parent) ? parent[key] : undefined;\n };\n const remove = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) throw new Error(\"cannot remove the root\");\n if (Array.isArray(parent)) parent.splice(Number(key), 1);\n else if (isRecord(parent) && key in parent) delete parent[key];\n else throw new Error(`path \"${pointer}\" not found`);\n };\n const write = (pointer: string, value: unknown, insert: boolean) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) {\n root = value;\n } else if (Array.isArray(parent)) {\n const index = key === \"-\" ? parent.length : Number(key);\n if (!Number.isInteger(index) || index < 0 || index > parent.length) {\n throw new Error(`index \"${key}\" is out of range`);\n }\n parent.splice(index, insert ? 0 : 1, value);\n } else if (isRecord(parent)) {\n parent[key] = value;\n } else {\n throw new Error(`path \"${pointer}\" not found`);\n }\n };\n for (const entry of patch as JsonPatchOperation[]) {\n if (!isRecord(entry) || typeof entry.path !== \"string\") {\n throw new Error(\"invalid patch operation\");\n }\n switch (entry.op) {\n case \"add\":\n write(entry.path, cloneValue(entry.value), true);\n break;\n case \"replace\":\n if (read(entry.path) === undefined) {\n throw new Error(`path \"${entry.path}\" not found`);\n }\n write(entry.path, cloneValue(entry.value), false);\n break;\n case \"remove\":\n remove(entry.path);\n break;\n case \"copy\":\n write(entry.path, cloneValue(read(entry.from ?? \"\")), true);\n break;\n case \"move\": {\n const value = read(entry.from ?? \"\");\n remove(entry.from ?? \"\");\n write(entry.path, value, true);\n break;\n }\n case \"test\":\n if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) {\n throw new Error(`test failed at \"${entry.path}\"`);\n }\n break;\n default:\n throw new Error(`unknown patch op \"${String(entry.op)}\"`);\n }\n }\n return root;\n}\n\n/** One converted operation, with where it came from. */\ninterface SourceOperation {\n operation: A2UIOperation;\n /** Its index in the source message. */\n index: number;\n version: SourceVersion;\n}\n\n/** The converted part of one surface that one source message holds. */\ninterface SourcePart {\n operations: SourceOperation[];\n rejected: GenerativeUIRejectedOperation[];\n}\n\ninterface SurfaceState {\n /** The part of each source message, in the order they first touched it. */\n parts: Map<string, SourcePart>;\n /** JSON of the last snapshot content. */\n lastSnapshot?: string;\n /** Operations sent as deltas, for a surface created in an earlier run. */\n sentOperations: A2UIOperation[];\n /** JSON of the last `rejected` sent as a delta. */\n sentRejected: string;\n}\n\n/**\n * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native\n * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass\n * every event of the run through `transform`, in order.\n *\n * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per\n * messageId (a delta is applied to the stored content), and its\n * operations are converted with {@link upgradeA2UIV09Operations}.\n * - Each surface becomes one `generative-ui-surface` message,\n * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is\n * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the\n * cumulative 1.0 content: the operations of every source message for it,\n * in order, with only the first createSurface. The target is the chat,\n * the status is \"ready\", dropped operations are `rejected` (at their\n * index in the source message), and `a2uiSourceVersion` is \"0.9\" for a\n * surface written in v0.9.\n * - A surface written in native A2UI 1.0 (`version: \"1.0\"`, for example\n * from ADK) becomes the same `generative-ui-surface` message, without\n * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the\n * agent unchanged. One surface has one version, the version of its\n * first operation; an operation of the other version is rejected.\n * - A surface that this run updates but does not create (v0.9 sends no\n * second createSurface) was created in an earlier run, so its new\n * operations are appended to its message with an `ACTIVITY_DELTA`, as\n * the `render_ui` path updates an existing surface.\n * - A lifecycle snapshot (`status: \"building\"` and so on, no operations)\n * names no surface, so it is consumed. Every other event passes through.\n *\n * @example\n * ```ts\n * const upgrader = createA2UIV09ActivityUpgrader();\n * source.pipe(mergeMap((event) => upgrader.transform(event)));\n * ```\n */\nexport function createA2UIV09ActivityUpgrader(): {\n transform(event: BaseEvent): BaseEvent[];\n} {\n const sources = new Map<string, unknown>();\n const surfaces = new Map<string, SurfaceState>();\n\n const snapshotOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n version: SourceVersion,\n ): BaseEvent[] => {\n const create = operations.find((op) => \"createSurface\" in op);\n const catalogId =\n (create && \"createSurface\" in create && create.createSurface.catalogId) ||\n STANDARD_CATALOG_ID;\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId,\n operations,\n status: \"ready\",\n rejected,\n ...(version === \"0.9\" ? { a2uiSourceVersion: \"0.9\" as const } : {}),\n };\n const json = JSON.stringify(content);\n if (json === state.lastSnapshot) return [];\n state.lastSnapshot = json;\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content: cloneValue(content),\n replace: true,\n };\n return [event];\n };\n\n const deltaOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n ): BaseEvent[] => {\n const sent = state.sentOperations;\n let same = 0;\n while (\n same < sent.length &&\n same < operations.length &&\n JSON.stringify(sent[same]) === JSON.stringify(operations[same])\n ) {\n same++;\n }\n // Operations that changed after they were sent cannot be taken back.\n // v0.9 updates replace by id or path, so sending them again is safe.\n const patch: unknown[] = operations.slice(same).map((op) => ({\n op: \"add\",\n path: \"/operations/-\",\n value: cloneValue(op),\n }));\n const rejectedJson = JSON.stringify(rejected);\n if (rejectedJson !== state.sentRejected) {\n patch.push({ op: \"replace\", path: \"/rejected\", value: rejected });\n }\n state.sentOperations = operations;\n state.sentRejected = rejectedJson;\n if (patch.length === 0) return [];\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: patch as ActivityDeltaEvent[\"patch\"],\n };\n return [event];\n };\n\n const emitSurface = (surfaceId: string): BaseEvent[] => {\n const state = surfaces.get(surfaceId);\n if (!state) return [];\n const operations: A2UIOperation[] = [];\n const rejected: GenerativeUIRejectedOperation[] = [];\n let created = false;\n let version: SourceVersion | undefined;\n for (const part of state.parts.values()) {\n for (const { operation, index, version: opVersion } of part.operations) {\n version ??= opVersion;\n if (opVersion !== version) {\n rejected.push({\n index,\n reason: `surface \"${surfaceId}\" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`,\n });\n continue;\n }\n if (\"createSurface\" in operation) {\n // A second createSurface of the same id is rejected in 1.0.\n if (created) continue;\n created = true;\n }\n operations.push(operation);\n }\n rejected.push(...part.rejected);\n }\n return created\n ? snapshotOf(surfaceId, state, operations, rejected, version ?? \"0.9\")\n : deltaOf(surfaceId, state, operations, rejected);\n };\n\n /** Converts the stored content of one source message again. */\n const refresh = (messageId: string): BaseEvent[] => {\n const parts = new Map<string, SourcePart>();\n readOperations(sources.get(messageId)).forEach((op, index) => {\n // An operation with no surface cannot be shown anywhere.\n const surfaceId = surfaceIdOf(op);\n if (surfaceId === undefined) return;\n let part = parts.get(surfaceId);\n if (!part) {\n part = { operations: [], rejected: [] };\n parts.set(surfaceId, part);\n }\n const { operations, dropped } = upgradeA2UIV09Operations([op]);\n // Only v0.9 and 1.0 operations convert.\n const version: SourceVersion =\n isRecord(op) && op.version === A2UI_VERSION ? \"1.0\" : \"0.9\";\n for (const operation of operations) {\n part.operations.push({ operation, index, version });\n }\n for (const { reason } of dropped) part.rejected.push({ index, reason });\n });\n const touched = new Set(parts.keys());\n for (const [surfaceId, state] of surfaces) {\n if (!parts.has(surfaceId) && state.parts.delete(messageId)) {\n touched.add(surfaceId);\n }\n }\n for (const [surfaceId, part] of parts) {\n let state = surfaces.get(surfaceId);\n if (!state) {\n state = { parts: new Map(), sentOperations: [], sentRejected: \"[]\" };\n surfaces.set(surfaceId, state);\n }\n state.parts.set(messageId, part);\n }\n return [...touched].flatMap(emitSurface);\n };\n\n return {\n transform(event) {\n if (event.type === EventType.ACTIVITY_SNAPSHOT) {\n const snapshot = event as ActivitySnapshotEvent;\n if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n return [event];\n }\n const { messageId } = snapshot;\n // `replace: false` does not replace a message that already exists.\n if (snapshot.replace === false && sources.has(messageId)) return [];\n sources.set(messageId, cloneValue(snapshot.content));\n return refresh(messageId);\n }\n if (event.type === EventType.ACTIVITY_DELTA) {\n const delta = event as ActivityDeltaEvent;\n if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];\n const { messageId } = delta;\n if (!sources.has(messageId)) return [];\n let content: unknown;\n try {\n content = applyJsonPatch(\n cloneValue(sources.get(messageId)),\n delta.patch,\n );\n } catch {\n // The AG-UI client also skips a delta that does not apply.\n return [];\n }\n sources.set(messageId, content);\n return refresh(messageId);\n }\n return [event];\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,6BAA6B;AACnC,MAAM,sBAAsB;;AAG5B,MAAM,eAAoC,IAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AACrE,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACD;;;;;;AAQD,MAAM,wBAA6C,IAAI,IAAI,CACzD,0DACA,kEACD,CAAC;;;;;;AAOF,MAAM,wBAA6C,IAAI,IAAI,CACzD,kEACD,CAAC;;AAMF,MAAM,gBAAkD;CACtD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;;AAGD,SAAS,QAAQ,IAAkD;CACjE,MAAM,QAAQ,UAAU,QAAQ,SAAS,QAAQ,GAAG;AACpD,QAAO,MAAM,WAAW,IAAI,MA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,CAAC,GAAG,QAAQ,CAAC,QAAQ,YAAY;;AAG1C,QAAO,EACL,UAAU,OAAO;AACf,MAAI,MAAM,SAAS,UAAU,mBAAmB;GAC9C,MAAM,WAAW;AACjB,OAAI,SAAS,iBAAiB,2BAC5B,QAAO,CAAC,MAAM;GAEhB,MAAM,EAAE,cAAc;AAEtB,OAAI,SAAS,YAAY,SAAS,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;AACnE,WAAQ,IAAI,WAAW,WAAW,SAAS,QAAQ,CAAC;AACpD,UAAO,QAAQ,UAAU;;AAE3B,MAAI,MAAM,SAAS,UAAU,gBAAgB;GAC3C,MAAM,QAAQ;AACd,OAAI,MAAM,iBAAiB,2BAA4B,QAAO,CAAC,MAAM;GACrE,MAAM,EAAE,cAAc;AACtB,OAAI,CAAC,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;GACtC,IAAI;AACJ,OAAI;AACF,cAAU,eACR,WAAW,QAAQ,IAAI,UAAU,CAAC,EAClC,MAAM,MACP;WACK;AAEN,WAAO,EAAE;;AAEX,WAAQ,IAAI,WAAW,QAAQ;AAC/B,UAAO,QAAQ,UAAU;;AAE3B,SAAO,CAAC,MAAM;IAEjB"}
@@ -1,2 +1,3 @@
1
1
  import { GenerativeUIMiddleware } from "./generative-ui-middleware.cjs";
2
+ import { A2UIV09BridgeMiddleware } from "./a2ui-v09-middleware.cjs";
2
3
  import { GenerativeUISurfaceWriter, createSurfaceWriter } from "./surface-writer.cjs";
@@ -1,2 +1,3 @@
1
1
  import { GenerativeUIMiddleware } from "./generative-ui-middleware.mjs";
2
+ import { A2UIV09BridgeMiddleware } from "./a2ui-v09-middleware.mjs";
2
3
  import { GenerativeUISurfaceWriter, createSurfaceWriter } from "./surface-writer.mjs";
@@ -105,12 +105,8 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
105
105
  inspectorMetadata: true,
106
106
  ...require_learning.hasLearningContainerConfiguration(runtime) ? { inspectorLearning: true } : {}
107
107
  } : {},
108
- a2uiEnabled: webEnabled && require_runtime.isA2UIEnabled(runtime.a2ui),
109
- ...webEnabled && require_runtime.isA2UIEnabled(runtime.a2ui) ? { a2ui: {
110
- enabled: true,
111
- ...runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}
112
- } } : {},
113
108
  openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,
109
+ generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),
114
110
  ...require_runtime.isIntelligenceRuntime(runtime) ? { licenseStatus: resolveCompatibilityLicenseStatus(licenseChecker, runtimeEntitlements) } : {},
115
111
  ...runtimeEntitlements ? { runtimeEntitlements } : {},
116
112
  telemetryDisabled: require_telemetry_client.isTelemetryDisabled()
@@ -129,6 +125,24 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
129
125
  });
130
126
  }
131
127
  }
128
+ /**
129
+ * Report generative UI with the rules `configureAgentForRequest` uses to
130
+ * attach the generative UI middlewares: it is on unless `generativeUI` is
131
+ * `false`, and `{ agents }` limits it to those agents. The A2UI version of an
132
+ * agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,
133
+ * as the runtime converts v0.9 surfaces. When the option is omitted, the
134
+ * middlewares run only for a client that asks for them, so the client can
135
+ * still turn generative UI on.
136
+ */
137
+ function resolveGenerativeUIInfo(runtime, webEnabled) {
138
+ const generativeUI = runtime.generativeUI;
139
+ if (!webEnabled || generativeUI === false) return { enabled: false };
140
+ const agents = typeof generativeUI === "object" ? generativeUI.agents : void 0;
141
+ return {
142
+ enabled: true,
143
+ ...agents ? { agents } : {}
144
+ };
145
+ }
132
146
  function resolveThreadEndpointInfo(runtime, threadEndpointsEnabled) {
133
147
  const available = (operation) => threadEndpointsEnabled && (require_runtime.isIntelligenceRuntime(runtime) || require_agent_runner.supportsLocalThreadEndpoints(runtime.runner) && require_thread_access.isThreadOperationAvailable(runtime, operation));
134
148
  const managedThreadMetadata = threadEndpointsEnabled && require_runtime.isIntelligenceRuntime(runtime);
@@ -1 +1 @@
1
- {"version":3,"file":"get-runtime-info.cjs","names":["isIntelligenceRuntime","PlatformRequestError","resolveAgents","VERSION","hasLearningContainerConfiguration","isA2UIEnabled","isTelemetryDisabled","supportsLocalThreadEndpoints","isThreadOperationAvailable"],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;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GAAIL,sCAAsB,QAAQ,GAC9B,EACE,eAAe,kCACb,gBACA,oBACD,EACF,GACD,EAAE;GACN,GAAI,sBAAsB,EAAE,qBAAqB,GAAG,EAAE;GACtD,mBAAmBM,8CAAqB;GACzC;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;;;AAIL,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACCN,sCAAsB,QAAQ,IAC5BO,kDAA6B,QAAQ,OAAO,IAC3CC,iDAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0BR,sCAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
1
+ {"version":3,"file":"get-runtime-info.cjs","names":["isIntelligenceRuntime","PlatformRequestError","resolveAgents","VERSION","hasLearningContainerConfiguration","isTelemetryDisabled","supportsLocalThreadEndpoints","isThreadOperationAvailable"],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport type {\n AgentDescription,\n GenerativeUIRuntimeInfo,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\n/**\n * Report generative UI with the rules `configureAgentForRequest` uses to\n * attach the generative UI middlewares: it is on unless `generativeUI` is\n * `false`, and `{ agents }` limits it to those agents. The A2UI version of an\n * agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,\n * as the runtime converts v0.9 surfaces. When the option is omitted, the\n * middlewares run only for a client that asks for them, so the client can\n * still turn generative UI on.\n */\nfunction resolveGenerativeUIInfo(\n runtime: CopilotRuntimeLike,\n webEnabled: boolean,\n): GenerativeUIRuntimeInfo {\n const generativeUI = runtime.generativeUI;\n if (!webEnabled || generativeUI === false) return { enabled: false };\n const agents =\n typeof generativeUI === \"object\" ? generativeUI.agents : undefined;\n return { enabled: true, ...(agents ? { agents } : {}) };\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4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,OAAO,iBAAiB,WAAW,aAAa,SAAS;AAC3D,QAAO;EAAE,SAAS;EAAM,GAAI,SAAS,EAAE,QAAQ,GAAG,EAAE;EAAG;;AAGzD,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACCL,sCAAsB,QAAQ,IAC5BM,kDAA6B,QAAQ,OAAO,IAC3CC,iDAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0BP,sCAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
@@ -4,7 +4,7 @@ import { hasLearningContainerConfiguration } from "../core/learning.mjs";
4
4
  import { PlatformRequestError } from "../intelligence-platform/client.mjs";
5
5
  import { isThreadOperationAvailable } from "./shared/thread-access.mjs";
6
6
  import { isTelemetryDisabled } from "../telemetry/telemetry-client.mjs";
7
- import { VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "../core/runtime.mjs";
7
+ import { VERSION, isIntelligenceRuntime, resolveAgents } from "../core/runtime.mjs";
8
8
 
9
9
  //#region src/runtime/handlers/get-runtime-info.ts
10
10
  function resolveLicenseStatus(licenseChecker) {
@@ -105,12 +105,8 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
105
105
  inspectorMetadata: true,
106
106
  ...hasLearningContainerConfiguration(runtime) ? { inspectorLearning: true } : {}
107
107
  } : {},
108
- a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),
109
- ...webEnabled && isA2UIEnabled(runtime.a2ui) ? { a2ui: {
110
- enabled: true,
111
- ...runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}
112
- } } : {},
113
108
  openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,
109
+ generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),
114
110
  ...isIntelligenceRuntime(runtime) ? { licenseStatus: resolveCompatibilityLicenseStatus(licenseChecker, runtimeEntitlements) } : {},
115
111
  ...runtimeEntitlements ? { runtimeEntitlements } : {},
116
112
  telemetryDisabled: isTelemetryDisabled()
@@ -129,6 +125,24 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
129
125
  });
130
126
  }
131
127
  }
128
+ /**
129
+ * Report generative UI with the rules `configureAgentForRequest` uses to
130
+ * attach the generative UI middlewares: it is on unless `generativeUI` is
131
+ * `false`, and `{ agents }` limits it to those agents. The A2UI version of an
132
+ * agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,
133
+ * as the runtime converts v0.9 surfaces. When the option is omitted, the
134
+ * middlewares run only for a client that asks for them, so the client can
135
+ * still turn generative UI on.
136
+ */
137
+ function resolveGenerativeUIInfo(runtime, webEnabled) {
138
+ const generativeUI = runtime.generativeUI;
139
+ if (!webEnabled || generativeUI === false) return { enabled: false };
140
+ const agents = typeof generativeUI === "object" ? generativeUI.agents : void 0;
141
+ return {
142
+ enabled: true,
143
+ ...agents ? { agents } : {}
144
+ };
145
+ }
132
146
  function resolveThreadEndpointInfo(runtime, threadEndpointsEnabled) {
133
147
  const available = (operation) => threadEndpointsEnabled && (isIntelligenceRuntime(runtime) || supportsLocalThreadEndpoints(runtime.runner) && isThreadOperationAvailable(runtime, operation));
134
148
  const managedThreadMetadata = threadEndpointsEnabled && isIntelligenceRuntime(runtime);
@@ -1 +1 @@
1
- {"version":3,"file":"get-runtime-info.mjs","names":[],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4BAC3C,oBAAoB,YAAY,WAC9B,kCAEF,QAAO,oBAAoB,YAAY,SAAS,UAAU;AAG5D,MAAI,oBAAoB,YAAY,OAClC,QAAO;;CAIX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,OAAO,IAC3C,2BAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0B,sBAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
1
+ {"version":3,"file":"get-runtime-info.mjs","names":[],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport type {\n AgentDescription,\n GenerativeUIRuntimeInfo,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\n/**\n * Report generative UI with the rules `configureAgentForRequest` uses to\n * attach the generative UI middlewares: it is on unless `generativeUI` is\n * `false`, and `{ agents }` limits it to those agents. The A2UI version of an\n * agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,\n * as the runtime converts v0.9 surfaces. When the option is omitted, the\n * middlewares run only for a client that asks for them, so the client can\n * still turn generative UI on.\n */\nfunction resolveGenerativeUIInfo(\n runtime: CopilotRuntimeLike,\n webEnabled: boolean,\n): GenerativeUIRuntimeInfo {\n const generativeUI = runtime.generativeUI;\n if (!webEnabled || generativeUI === false) return { enabled: false };\n const agents =\n typeof generativeUI === \"object\" ? generativeUI.agents : undefined;\n return { enabled: true, ...(agents ? { agents } : {}) };\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4BAC3C,oBAAoB,YAAY,WAC9B,kCAEF,QAAO,oBAAoB,YAAY,SAAS,UAAU;AAG5D,MAAI,oBAAoB,YAAY,OAClC,QAAO;;CAIX,MAAM,sBAAsB,qBAAqB,eAAe;AAChE,KACE,wBAAwB,UACxB,qBAAqB,WAAW,WAChC,qBAAqB,MAAM,UAE3B,QAAO;AAGT,QAAO;;;;;;;;;AAiBT,eAAe,2BACb,SACiD;AACjD,KAAI,CAAC,sBAAsB,QAAQ,CACjC;AAGF,KAAI;AACF,SAAO,MAAM,QAAQ,aAAa,wBAAwB;UACnD,OAAO;AACd,MAAI,iBAAiB,wBAAwB,MAAM,cAAc,MAC/D,QAAO;GACL,QAAQ;GACR,OAAO;IACL,MAAM;IACN,SAAS;IACT,WAAW;IACZ;GACF;AAGH,SAAO;GACL,QAAQ;GACR,OAAO;IACL,MAAM;IACN,SAAS;IACT,WAAW;IACZ;GACF;;;AAIL,eAAsB,qBAAqB,EACzC,SACA,SACA,yBAAyB,MACzB,uCAAuC,SACN;A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B,SAAS,WAAW;GAC1D,GAAI,sBAAsB,QAAQ,GAC9B,EACE,eAAe,kCACb,gBACA,oBACD,EACF,GACD,EAAE;GACN,GAAI,sBAAsB,EAAE,qBAAqB,GAAG,EAAE;GACtD,mBAAmB,qBAAqB;GACzC;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;;;;;;;;;;;;AAaL,SAAS,wBACP,SACA,YACyB;CACzB,MAAM,eAAe,QAAQ;AAC7B,KAAI,CAAC,cAAc,iBAAiB,MAAO,QAAO,EAAE,SAAS,OAAO;CACpE,MAAM,SACJ,OAAO,iBAAiB,WAAW,aAAa,SAAS;AAC3D,QAAO;EAAE,SAAS;EAAM,GAAI,SAAS,EAAE,QAAQ,GAAG,EAAE;EAAG;;AAGzD,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACC,sBAAsB,QAAQ,IAC5B,6BAA6B,QAAQ,OAAO,IAC3C,2BAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0B,sBAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
@@ -39,14 +39,12 @@ async function handleRunAgent({ runtime, request, agentId }) {
39
39
  if (require_agent_runner.enforcesThreadOwnership(runtime.runner) && !await runtime.runner.isThreadAccessible(input.threadId, { ownerId: owner })) return require_thread_access.threadAccessDeniedResponse();
40
40
  ownerId = owner;
41
41
  }
42
- const providerA2UIHasCatalog = input.forwardedProps?.a2uiCatalogAvailable === true;
43
42
  const providerGenerativeUITransport = (0, _copilotkit_shared.readCopilotKitUIEnvelope)(input.forwardedProps)?.metadata.extensions.copilotkit_transport;
44
43
  require_agent_utils.configureAgentForRequest({
45
44
  runtime,
46
45
  request,
47
46
  agentId,
48
47
  agent,
49
- providerA2UIHasCatalog,
50
48
  providerGenerativeUITransport,
51
49
  isMcpProxyRequest: Object.prototype.hasOwnProperty.call(input.forwardedProps ?? {}, "__proxiedMCPRequest")
52
50
  });
@@ -1 +1 @@
1
- {"version":3,"file":"handle-run.cjs","names":["telemetry","readGuardrailsEnabled","cloneAgentForRequest","parseRunRequest","getRuntimeLogger","takeAnalyticsContext","isIntelligenceRuntime","resolveLocalThreadOwner","enforcesThreadOwnership","threadAccessDeniedResponse","attachIntelligenceEnterpriseLearning","handleIntelligenceRun","handleSseRun"],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the A2UI catalog signal the React provider forwards (see\n // `a2uiCatalogAvailable` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // `<CopilotKit a2ui={{ catalog }}>` forwards this flag on every run. Its\n // presence alone is enough to turn A2UI on end-to-end — no runtime-side\n // `a2ui` config required.\n const providerA2UIHasCatalog =\n (input.forwardedProps as Record<string, unknown> | undefined)\n ?.a2uiCatalogAvailable === true;\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerA2UIHasCatalog,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n debugLogger: runtime.debugLogger,\n startTime,\n ownerId,\n });\n } catch (error) {\n getRuntimeErrorReporter(runtime)?.report({\n request,\n error,\n operation: \"agent.run\",\n agentId,\n phase: \"common\",\n startTime,\n });\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;CACrB,MAAM,YAAY,KAAK,KAAK;CAC5B,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAaA,kCAAW,QACpC,uCACA;EACE,4BAA4B,MAAMC,8CAAsB,QAAQ;EAChE,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EACF,MAAM,QAAQ,MAAMC,yC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D,CAAC;UACK,OAAO;AACd,yDAAwB,QAAQ,EAAE,OAAO;GACvC;GACA;GACA,WAAW;GACX;GACA,OAAO;GACP;GACD,CAAC;AACF,kCAAiB,QAAQ,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,sBAAsB;AAEtE,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"handle-run.cjs","names":["telemetry","readGuardrailsEnabled","cloneAgentForRequest","parseRunRequest","getRuntimeLogger","takeAnalyticsContext","isIntelligenceRuntime","resolveLocalThreadOwner","enforcesThreadOwnership","threadAccessDeniedResponse","attachIntelligenceEnterpriseLearning","handleIntelligenceRun","handleSseRun"],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the generative UI envelope the React provider forwards (see\n // `providerGenerativeUITransport` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n debugLogger: runtime.debugLogger,\n startTime,\n ownerId,\n });\n } catch (error) {\n getRuntimeErrorReporter(runtime)?.report({\n request,\n error,\n operation: \"agent.run\",\n agentId,\n phase: \"common\",\n startTime,\n });\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;CACrB,MAAM,YAAY,KAAK,KAAK;CAC5B,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAaA,kCAAW,QACpC,uCACA;EACE,4BAA4B,MAAMC,8CAAsB,QAAQ;EAChE,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EACF,MAAM,QAAQ,MAAMC,yCAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAKT,QAAM,UAAU;EAOhB,MAAM,SAAS,MAAMC,oCACnB,QAAQ,OAAO,EACfC,gCAAiB,QAAQ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I,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -39,14 +39,12 @@ async function handleRunAgent({ runtime, request, agentId }) {
39
39
  if (enforcesThreadOwnership(runtime.runner) && !await runtime.runner.isThreadAccessible(input.threadId, { ownerId: owner })) return threadAccessDeniedResponse();
40
40
  ownerId = owner;
41
41
  }
42
- const providerA2UIHasCatalog = input.forwardedProps?.a2uiCatalogAvailable === true;
43
42
  const providerGenerativeUITransport = readCopilotKitUIEnvelope(input.forwardedProps)?.metadata.extensions.copilotkit_transport;
44
43
  configureAgentForRequest({
45
44
  runtime,
46
45
  request,
47
46
  agentId,
48
47
  agent,
49
- providerA2UIHasCatalog,
50
48
  providerGenerativeUITransport,
51
49
  isMcpProxyRequest: Object.prototype.hasOwnProperty.call(input.forwardedProps ?? {}, "__proxiedMCPRequest")
52
50
  });
@@ -1 +1 @@
1
- {"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the A2UI catalog signal the React provider forwards (see\n // `a2uiCatalogAvailable` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // `<CopilotKit a2ui={{ catalog }}>` forwards this flag on every run. Its\n // presence alone is enough to turn A2UI on end-to-end — no runtime-side\n // `a2ui` config required.\n const providerA2UIHasCatalog =\n (input.forwardedProps as Record<string, unknown> | undefined)\n ?.a2uiCatalogAvailable === true;\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerA2UIHasCatalog,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n debugLogger: runtime.debugLogger,\n startTime,\n ownerId,\n });\n } catch (error) {\n getRuntimeErrorReporter(runtime)?.report({\n request,\n error,\n operation: \"agent.run\",\n agentId,\n phase: \"common\",\n startTime,\n });\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;CACrB,MAAM,YAAY,KAAK,KAAK;CAC5B,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAa,WAAW,QACpC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AsB,QAAQ,CAChC,QAAO,sBAAsB;GAC3B;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAO,aAAa;GAClB;GACA;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,aAAa,QAAQ;GACrB;GACA;GACD,CAAC;UACK,OAAO;AACd,0BAAwB,QAAQ,EAAE,OAAO;GACvC;GACA;GACA,WAAW;GACX;GACA,OAAO;GACP;GACD,CAAC;AACF,mBAAiB,QAAQ,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,sBAAsB;AAEtE,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the generative UI envelope the React provider forwards (see\n // `providerGenerativeUITransport` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n debugLogger: runtime.debugLogger,\n startTime,\n ownerId,\n });\n } catch (error) {\n getRuntimeErrorReporter(runtime)?.report({\n request,\n error,\n operation: \"agent.run\",\n agentId,\n phase: \"common\",\n startTime,\n });\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;CACrB,MAAM,YAAY,KAAK,KAAK;CAC5B,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAa,WAAW,QACpC,uCACA;EACE,4BAA4B,MAAM,sBAAsB,QAAQ;EAChE,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EACF,MAAM,QAAQ,MAAM,qBAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAKT,QAAM,UAAU;EAOhB,MAAM,SAAS,MAAM,gBACnB,QAAQ,OAAO,EACf,iBAAiB,QAAQ,CAC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AK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -5,6 +5,7 @@ const require_client = require('../../intelligence-platform/client.cjs');
5
5
  const require_resolve_intelligence_user = require('./resolve-intelligence-user.cjs');
6
6
  const require_runtime = require('../../core/runtime.cjs');
7
7
  const require_generative_ui_middleware = require('../../generative-ui/generative-ui-middleware.cjs');
8
+ const require_a2ui_v09_middleware = require('../../generative-ui/a2ui-v09-middleware.cjs');
8
9
  const require_open_generative_ui_middleware = require('../../event-transforms/open-generative-ui-middleware.cjs');
9
10
  const require_mcp_apps_servers = require('./mcp-apps-servers.cjs');
10
11
  const require_memory_policy = require('./memory-policy.cjs');
@@ -43,15 +44,22 @@ async function cloneAgentForRequest(runtime, agentId, request) {
43
44
  return agents[agentId].clone();
44
45
  }
45
46
  function configureAgentForRequest(params) {
46
- const { runtime, request, agentId, providerA2UIHasCatalog, isMcpProxyRequest } = params;
47
+ const { runtime, request, agentId, isMcpProxyRequest } = params;
47
48
  const agent = params.agent;
48
- const a2uiEnabledByCatalog = !!providerA2UIHasCatalog && runtime.a2ui?.enabled !== false;
49
- if (require_runtime.isA2UIEnabled(runtime.a2ui) || a2uiEnabledByCatalog) {
50
- const { agents: targetAgents, enabled: _enabled, injectA2UITool, ...a2uiOptions } = runtime.a2ui ?? {};
51
- if ((!targetAgents || targetAgents.includes(agentId)) && typeof agent.use === "function") agent.use(new _ag_ui_a2ui_middleware.A2UIMiddleware({
52
- ...a2uiOptions,
53
- injectA2UITool: injectA2UITool ?? (providerA2UIHasCatalog ? true : void 0)
54
- }));
49
+ const generativeUI = runtime.generativeUI;
50
+ const generativeUIOptions = typeof generativeUI === "object" ? generativeUI : void 0;
51
+ const transport = params.providerGenerativeUITransport;
52
+ const isGenerativeUIRun = generativeUI !== false && (transport === "tool" || transport !== "markdown" && !!generativeUI) && (!generativeUIOptions?.agents || generativeUIOptions.agents.includes(agentId)) && typeof agent.use === "function";
53
+ const a2uiVersion = require_a2ui_v09_middleware.resolveA2UIVersion(generativeUI, agentId);
54
+ if (isGenerativeUIRun) {
55
+ agent.use(new require_a2ui_v09_middleware.A2UIV09BridgeMiddleware({ agentVersion: a2uiVersion }));
56
+ if (a2uiVersion === "0.9") {
57
+ const { agents: _agents, a2uiVersion: _a2uiVersion, injectA2UITool, ...a2uiOptions } = generativeUIOptions ?? {};
58
+ agent.use(new _ag_ui_a2ui_middleware.A2UIMiddleware({
59
+ ...a2uiOptions,
60
+ injectA2UITool: injectA2UITool ?? transport === "tool"
61
+ }));
62
+ } else agent.use(new _ag_ui_a2ui_middleware.A2UIMiddleware());
55
63
  }
56
64
  if (require_runtime.isIntelligenceRuntime(runtime) && typeof agent.use === "function") {
57
65
  const mcpServers = require_mcp_apps_servers.resolveMcpAppsServers(runtime.mcpApps?.servers ?? [], agentId);
@@ -68,12 +76,7 @@ function configureAgentForRequest(params) {
68
76
  const targetAgents = typeof config === "object" ? config.agents : void 0;
69
77
  if ((!targetAgents || targetAgents.includes(agentId)) && typeof agent.use === "function") agent.use(new require_open_generative_ui_middleware.OpenGenerativeUIMiddleware());
70
78
  }
71
- const generativeUI = runtime.generativeUI;
72
- const transport = params.providerGenerativeUITransport;
73
- if ((transport === "tool" || transport !== "markdown" && !!generativeUI) && generativeUI !== false && typeof agent.use === "function") {
74
- const targetAgents = typeof generativeUI === "object" ? generativeUI.agents : void 0;
75
- if (!targetAgents || targetAgents.includes(agentId)) agent.use(new require_generative_ui_middleware.GenerativeUIMiddleware());
76
- }
79
+ if (isGenerativeUIRun && a2uiVersion === "1.0") agent.use(new require_generative_ui_middleware.GenerativeUIMiddleware());
77
80
  agent.headers = require_header_utils.mergeForwardableHeaders(agent.headers, request, runtime.forwardHeadersPolicy ?? require_header_utils.resolveForwardHeadersPolicy(void 0));
78
81
  }
79
82
  /**