@copilotkit/react-core 1.80.0 → 1.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MarkdownSurfaces-D-OkjUpU.cjs +3807 -0
- package/dist/MarkdownSurfaces-D-OkjUpU.cjs.map +1 -0
- package/dist/MarkdownSurfaces-L67964_B.mjs +3522 -0
- package/dist/MarkdownSurfaces-L67964_B.mjs.map +1 -0
- package/dist/{copilotkit-CWOSXhRO.d.mts → copilotkit-BEcaM4L4.d.mts} +25 -34
- package/dist/copilotkit-BEcaM4L4.d.mts.map +1 -0
- package/dist/{copilotkit-DKICi3nC.cjs → copilotkit-BjllYYjw.cjs} +2022 -600
- package/dist/copilotkit-BjllYYjw.cjs.map +1 -0
- package/dist/{copilotkit-Dfw9HzO9.d.cts → copilotkit-D9jIImy9.d.cts} +25 -34
- package/dist/copilotkit-D9jIImy9.d.cts.map +1 -0
- package/dist/{copilotkit-BNLtgOyD.mjs → copilotkit-fKrKqoiP.mjs} +1966 -493
- package/dist/copilotkit-fKrKqoiP.mjs.map +1 -0
- package/dist/index.cjs +8 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +4463 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/runtime-context-CrHq-iTf.d.mts +924 -0
- package/dist/runtime-context-CrHq-iTf.d.mts.map +1 -0
- package/dist/runtime-context-D3NcP9oE.d.cts +924 -0
- package/dist/runtime-context-D3NcP9oE.d.cts.map +1 -0
- package/dist/v2/generative-ui.cjs +8154 -0
- package/dist/v2/generative-ui.cjs.map +1 -0
- package/dist/v2/generative-ui.d.cts +4950 -0
- package/dist/v2/generative-ui.d.cts.map +1 -0
- package/dist/v2/generative-ui.d.mts +4950 -0
- package/dist/v2/generative-ui.d.mts.map +1 -0
- package/dist/v2/generative-ui.mjs +8140 -0
- package/dist/v2/generative-ui.mjs.map +1 -0
- package/dist/v2/index.cjs +65 -4
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +3 -2
- package/dist/v2/index.d.mts +3 -2
- package/dist/v2/index.mjs +3 -2
- package/dist/v2/index.umd.js +4832 -180
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +21 -8
- package/dist/copilotkit-BNLtgOyD.mjs.map +0 -1
- package/dist/copilotkit-CWOSXhRO.d.mts.map +0 -1
- package/dist/copilotkit-DKICi3nC.cjs.map +0 -1
- package/dist/copilotkit-Dfw9HzO9.d.cts.map +0 -1
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
import React$1, { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { AbstractAgent } from "@ag-ui/client";
|
|
3
|
+
import { A2UIFunctionPermissions, A2UIFunctionReturnType, A2UIOperation, ChildRef, GenerativeUIComponentManifest, GenerativeUIFunctionManifest, GenerativeUIRejectedOperation, GenerativeUISurfaceContent, GenerativeUISurfaceStatus, GenerativeUISurfaceSummary, GenerativeUIUserEvent, StandardSchemaV1 } from "@copilotkit/shared";
|
|
4
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
|
+
import { ActivityMessage } from "@ag-ui/core";
|
|
6
|
+
import { SurfaceModel } from "@a2ui/web_core/v0_9";
|
|
7
|
+
|
|
8
|
+
//#region src/v2/types/react-activity-message-renderer.d.ts
|
|
9
|
+
interface ReactActivityMessageRenderer<TActivityContent> {
|
|
10
|
+
/**
|
|
11
|
+
* Activity type to match when rendering. Use "*" as a wildcard renderer.
|
|
12
|
+
*/
|
|
13
|
+
activityType: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional agent ID to scope the renderer to a particular agent.
|
|
16
|
+
*/
|
|
17
|
+
agentId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Schema describing the activity content payload.
|
|
20
|
+
*/
|
|
21
|
+
content: StandardSchemaV1<any, TActivityContent>;
|
|
22
|
+
/**
|
|
23
|
+
* React component invoked to render the activity message.
|
|
24
|
+
*/
|
|
25
|
+
render: React.ComponentType<{
|
|
26
|
+
activityType: string;
|
|
27
|
+
content: TActivityContent;
|
|
28
|
+
message: ActivityMessage;
|
|
29
|
+
agent: AbstractAgent | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/v2/generative-ui/chat.d.ts
|
|
34
|
+
interface GenerativeUIChatSurfaceProps {
|
|
35
|
+
surfaceId: string;
|
|
36
|
+
isStreaming: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Set when operations from the latest render_ui call were rejected. The
|
|
39
|
+
* message is user-facing; `error.cause` holds the same list as `rejected`.
|
|
40
|
+
*/
|
|
41
|
+
error?: Error;
|
|
42
|
+
/** Rejected operations from the latest render_ui call, with validator reasons. */
|
|
43
|
+
rejected: GenerativeUIRejectedOperation[];
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
declare function DefaultGenerativeUIChatCard({
|
|
47
|
+
surfaceId,
|
|
48
|
+
isStreaming,
|
|
49
|
+
error,
|
|
50
|
+
children
|
|
51
|
+
}: GenerativeUIChatSurfaceProps): react_jsx_runtime0.JSX.Element;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/v2/generative-ui/accessibility.d.ts
|
|
54
|
+
/**
|
|
55
|
+
* The `accessibility` of the A2UI 1.0 component envelope, with its dynamic
|
|
56
|
+
* values resolved. Every component may carry it next to `id` and
|
|
57
|
+
* `component`; it is not a prop of the component.
|
|
58
|
+
*/
|
|
59
|
+
interface GenerativeUIAccessibility {
|
|
60
|
+
/** A short name for assistive technologies, 1 to 3 words. */
|
|
61
|
+
label?: string;
|
|
62
|
+
/** Instructions, format requirements, or what an action does. */
|
|
63
|
+
description?: string;
|
|
64
|
+
/** How screen readers announce changes (WAI-ARIA `aria-live`). */
|
|
65
|
+
live?: "off" | "polite" | "assertive";
|
|
66
|
+
/** True hides the component and its children from assistive technologies. */
|
|
67
|
+
hidden?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** The ARIA attributes of a resolved `accessibility`, ready to spread. */
|
|
70
|
+
interface GenerativeUIAriaAttributes {
|
|
71
|
+
"aria-label"?: string;
|
|
72
|
+
"aria-description"?: string;
|
|
73
|
+
"aria-live"?: "off" | "polite" | "assertive";
|
|
74
|
+
"aria-hidden"?: true;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Experimental. The ARIA attributes of the `accessibility` that the model
|
|
78
|
+
* gave the component being rendered, to spread on its root element. The
|
|
79
|
+
* standard components do this; a custom component does it itself:
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* function Panel({ children }: { children?: ReactNode }) {
|
|
84
|
+
* const aria = useGenerativeUIAccessibility();
|
|
85
|
+
* return <section {...aria}>{children}</section>;
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* Outside of generated UI it gives `{}`.
|
|
90
|
+
*/
|
|
91
|
+
declare function useGenerativeUIAccessibility(): GenerativeUIAriaAttributes;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/v2/generative-ui/errors.d.ts
|
|
94
|
+
type GenerativeUIErrorCode = "function_not_found" | "function_conflict" | "invalid_arguments" | "handler_failed" | "invalid_event_args" | "event_forward_failed" /** A function value or check could not be computed. */ | "expression_error" /** A function the caller may not call: `openUrl` from the agent. */ | "invalid_function_call" /** An event arrived while the agent was running: it was not sent. */ | "agent_busy";
|
|
95
|
+
declare class GenerativeUIError extends Error {
|
|
96
|
+
readonly code: GenerativeUIErrorCode;
|
|
97
|
+
constructor(code: GenerativeUIErrorCode, message: string);
|
|
98
|
+
}
|
|
99
|
+
type GenerativeUIInvokeResult = {
|
|
100
|
+
ok: true;
|
|
101
|
+
result: unknown;
|
|
102
|
+
} | {
|
|
103
|
+
ok: false;
|
|
104
|
+
error: GenerativeUIError;
|
|
105
|
+
};
|
|
106
|
+
type Components<UI extends GenerativeUI<any>> = GenerativeUIDefinitionsOf<UI>["components"];
|
|
107
|
+
type EventsOf<UI extends GenerativeUI<any>, Component extends keyof Components<UI>> = Components<UI>[Component]["events"] extends Record<string, unknown> ? Components<UI>[Component]["events"] : {};
|
|
108
|
+
type IsUnion<T, U = T> = T extends unknown ? [U] extends [T] ? false : true : never;
|
|
109
|
+
/** One member of a union. Used only after IsUnion proved the members equal. */
|
|
110
|
+
type OneOf<U> = UnionToIntersection<U extends unknown ? () => U : never> extends (() => infer R) ? R : never;
|
|
111
|
+
/** Every event name that a component of the UI declares, bases included. */
|
|
112
|
+
type GenerativeUIEventName<UI extends GenerativeUI<any>> = { [Component in keyof Components<UI>]: keyof EventsOf<UI, Component> & string }[keyof Components<UI>];
|
|
113
|
+
type EventArgs<UI extends GenerativeUI<any>, Name extends string> = { [Component in keyof Components<UI>]: Name extends keyof EventsOf<UI, Component> ? GenerativeUIEventInput<Name, EventsOf<UI, Component>[Name], GenerativeUIDefinitionsOf<UI>["functions"]> : never }[keyof Components<UI>];
|
|
114
|
+
/**
|
|
115
|
+
* Type of an event prop as seen by a component, looked up by event name in
|
|
116
|
+
* the generative UI that renders the component:
|
|
117
|
+
* `onSubmit?: GenerativeUIEventHandler<typeof ui, "onSubmit">`.
|
|
118
|
+
*
|
|
119
|
+
* The argument is the event `parameters` input. A matched event without
|
|
120
|
+
* `parameters` takes the input of its function.
|
|
121
|
+
*
|
|
122
|
+
* When components of the UI declare the event with different arguments, the
|
|
123
|
+
* result is not callable and names the conflict.
|
|
124
|
+
*/
|
|
125
|
+
type GenerativeUIEventHandler<UI extends GenerativeUI<any>, Name extends GenerativeUIEventName<UI>> = true extends IsUnion<EventArgs<UI, Name>> ? {
|
|
126
|
+
readonly error: `"${Name}" has different parameters on different components of this generative UI`;
|
|
127
|
+
} : (args: OneOf<EventArgs<UI, Name>>) => Promise<GenerativeUIInvokeResult>;
|
|
128
|
+
interface GenerativeUIErrorInfo {
|
|
129
|
+
kind: "render" | "props" | "operation" | "function" | "event";
|
|
130
|
+
surfaceId: string;
|
|
131
|
+
componentId?: string;
|
|
132
|
+
error: Error;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/v2/generative-ui/schema.d.ts
|
|
136
|
+
/** Any Standard Schema: zod, Valibot, ArkType, and more. */
|
|
137
|
+
type GenerativeUISchema = StandardSchemaV1;
|
|
138
|
+
/** The output type of a schema: what validation gives back. */
|
|
139
|
+
type SchemaOutput<Schema> = Schema extends StandardSchemaV1<any, infer Output> ? Output : never;
|
|
140
|
+
/** The input type of a schema: what validation takes. */
|
|
141
|
+
type SchemaInput<Schema> = Schema extends StandardSchemaV1<infer Input, any> ? Input : never;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/v2/generative-ui/catalog.d.ts
|
|
144
|
+
type GenerativeUISlotKind = "single" | "multiple";
|
|
145
|
+
/**
|
|
146
|
+
* The schema of the props of a component: any Standard Schema of an object,
|
|
147
|
+
* for example `z.object({ ... })` or `v.object({ ... })`. The model gets
|
|
148
|
+
* the props as JSON Schema, so the schema must give one: Standard JSON
|
|
149
|
+
* Schema (zod 4.2+, ArkType, Valibot with `toStandardJsonSchema`) or zod 3.
|
|
150
|
+
* It must validate synchronously, because props are checked while a
|
|
151
|
+
* surface renders.
|
|
152
|
+
*/
|
|
153
|
+
type PropsSchema = StandardSchemaV1<Record<string, unknown>, Record<string, unknown>>;
|
|
154
|
+
/** An event prop of a component. */
|
|
155
|
+
interface GenerativeUIEventDefinition {
|
|
156
|
+
description?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Arguments the component passes when it calls the event prop. An event
|
|
159
|
+
* that matches a declared function can leave this out. Then the function
|
|
160
|
+
* parameters are used.
|
|
161
|
+
*/
|
|
162
|
+
parameters?: GenerativeUISchema;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A function that generated UI can call. The handler comes from
|
|
166
|
+
* `useGenerativeUIFunction`.
|
|
167
|
+
*/
|
|
168
|
+
interface GenerativeUIFunctionDefinition extends A2UIFunctionPermissions {
|
|
169
|
+
description?: string;
|
|
170
|
+
parameters: GenerativeUISchema;
|
|
171
|
+
/**
|
|
172
|
+
* Who may call it. `"rendererOnly"` (the default, as in A2UI 1.0): event
|
|
173
|
+
* bindings and prop values. `"agentOnly"`: `callRendererFunction`.
|
|
174
|
+
* `"rendererOrAgent"`: both. The agent calls only what you allow.
|
|
175
|
+
*/
|
|
176
|
+
allowedCallers?: A2UIFunctionPermissions["allowedCallers"];
|
|
177
|
+
/**
|
|
178
|
+
* True for a function that runs only from a user gesture, like `openUrl`.
|
|
179
|
+
* It is then for the renderer only.
|
|
180
|
+
*/
|
|
181
|
+
requiresUserActivation?: boolean;
|
|
182
|
+
/** What the handler gives back, as A2UI 1.0 names it. */
|
|
183
|
+
returnType?: A2UIFunctionReturnType;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Gives a bound prop its value. It gets the full state and the model-set
|
|
187
|
+
* props of the node, before the props schema parses them (no defaults or
|
|
188
|
+
* transforms). It runs in the browser and must be pure.
|
|
189
|
+
*/
|
|
190
|
+
type GenerativeUISelector = (state: Record<string, unknown>, props: Record<string, unknown>) => unknown;
|
|
191
|
+
/**
|
|
192
|
+
* Method syntax makes the parameters bivariant. So a selector with typed
|
|
193
|
+
* parameters fits this runtime type.
|
|
194
|
+
*/
|
|
195
|
+
type RuntimeSelector = {
|
|
196
|
+
select(state: Record<string, unknown>, props: Record<string, unknown>): unknown;
|
|
197
|
+
}["select"];
|
|
198
|
+
/** One component of a generative UI, as the renderer reads it. */
|
|
199
|
+
interface GenerativeUIComponentDefinition {
|
|
200
|
+
component: ComponentType<any>;
|
|
201
|
+
description?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Positional prefix across props, slots and events for catalog consumers.
|
|
204
|
+
* Remaining visible keys follow in declaration order (props, slots, events).
|
|
205
|
+
* A2UI exports encode this as property order, not a protocol field.
|
|
206
|
+
*/
|
|
207
|
+
parameterOrder?: readonly string[];
|
|
208
|
+
/** All data props: the props the model sets and the bound props. */
|
|
209
|
+
props?: PropsSchema;
|
|
210
|
+
/** Explicit selectors for bound props. */
|
|
211
|
+
bind?: Record<string, RuntimeSelector>;
|
|
212
|
+
/** Callback props. */
|
|
213
|
+
events?: Record<string, GenerativeUIEventDefinition>;
|
|
214
|
+
/**
|
|
215
|
+
* Child props, filled with rendered child components. A "multiple" slot
|
|
216
|
+
* takes a list of component ids, or a template `{ componentId, path }`
|
|
217
|
+
* that renders one component for each item of the list at `path`.
|
|
218
|
+
*/
|
|
219
|
+
slots?: Record<string, GenerativeUISlotKind>;
|
|
220
|
+
/**
|
|
221
|
+
* Props that the component can write. Each one gets a setter prop named
|
|
222
|
+
* `set` + the prop name: `value` gets `setValue`. When the model binds the
|
|
223
|
+
* prop to `{ "@path" }`, the setter writes the surface data model at that
|
|
224
|
+
* path, and the agent can no longer change that path. Else the setter
|
|
225
|
+
* changes local state only.
|
|
226
|
+
*/
|
|
227
|
+
writable?: readonly string[];
|
|
228
|
+
/**
|
|
229
|
+
* Who applies the `accessibility` envelope of the component: by default
|
|
230
|
+
* the engine, in a wrapper element around the component. `"self"` for a
|
|
231
|
+
* component that must not be wrapped (a table row or cell) and applies
|
|
232
|
+
* the attributes itself with `useGenerativeUIAccessibility()`.
|
|
233
|
+
*/
|
|
234
|
+
accessibility?: "wrapper" | "self";
|
|
235
|
+
}
|
|
236
|
+
/** A component after `createGenerativeUI` resolved its bindings. */
|
|
237
|
+
interface ResolvedGenerativeUIComponent extends GenerativeUIComponentDefinition {
|
|
238
|
+
/**
|
|
239
|
+
* One selector for each bound prop. A prop with the name of a top-level
|
|
240
|
+
* state key reads `state[key]`. A `bind` entry wins over the name rule.
|
|
241
|
+
*/
|
|
242
|
+
selectors: Record<string, GenerativeUISelector>;
|
|
243
|
+
/** Event name to the name of the declared function it calls. */
|
|
244
|
+
eventFunctions: Record<string, string>;
|
|
245
|
+
/** The keys of `props`, read from its JSON Schema. */
|
|
246
|
+
propKeys: readonly string[];
|
|
247
|
+
/**
|
|
248
|
+
* The component references in `props` (`child()`, `childList()`), at any
|
|
249
|
+
* depth. The renderer replaces each one with the rendered component. The
|
|
250
|
+
* `slots` of the definition are not in here.
|
|
251
|
+
*/
|
|
252
|
+
childRefs: readonly ChildRef[];
|
|
253
|
+
/** Who applies the `accessibility` envelope; see the definition. */
|
|
254
|
+
accessibility: "wrapper" | "self";
|
|
255
|
+
}
|
|
256
|
+
/** Type-level data of one component, kept in `GenerativeUI["definitions"]`. */
|
|
257
|
+
interface GenerativeUIComponentTypes {
|
|
258
|
+
/** The `props` schema, or `unknown` when the component has none. */
|
|
259
|
+
props: unknown;
|
|
260
|
+
/** The `events` object, or `unknown` when the component has none. */
|
|
261
|
+
events: unknown;
|
|
262
|
+
/** The `slots` object, or `unknown` when the component has none. */
|
|
263
|
+
slots: unknown;
|
|
264
|
+
/** The `writable` list, or `unknown` when the component has none. */
|
|
265
|
+
writable: unknown;
|
|
266
|
+
}
|
|
267
|
+
/** Type-level data of a generative UI, with the keys of its bases merged in. */
|
|
268
|
+
interface GenerativeUIDefinitions {
|
|
269
|
+
state: Record<string, GenerativeUISchema>;
|
|
270
|
+
functions: Record<string, GenerativeUIFunctionDefinition>;
|
|
271
|
+
components: Record<string, GenerativeUIComponentTypes>;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Experimental. The result of `createGenerativeUI`: the components the model
|
|
275
|
+
* can render, the app state they read, and the functions they call. Give it
|
|
276
|
+
* to the provider (`generativeUI={{ ui }}`) and to the typed hooks.
|
|
277
|
+
*/
|
|
278
|
+
interface GenerativeUI<Definitions extends GenerativeUIDefinitions = GenerativeUIDefinitions> {
|
|
279
|
+
/** Surfaces pin to this id. */
|
|
280
|
+
readonly id: string;
|
|
281
|
+
/** State schemas, bases first. */
|
|
282
|
+
readonly state: ReadonlyMap<string, GenerativeUISchema>;
|
|
283
|
+
/** Declared functions, bases first. */
|
|
284
|
+
readonly functions: ReadonlyMap<string, GenerativeUIFunctionDefinition>;
|
|
285
|
+
/** Components, bases first. */
|
|
286
|
+
readonly components: ReadonlyMap<string, ResolvedGenerativeUIComponent>;
|
|
287
|
+
/** What the model sees: model-set props and unmatched events only. */
|
|
288
|
+
readonly manifestComponents: Record<string, GenerativeUIComponentManifest>;
|
|
289
|
+
/** Type only, never set at runtime. */
|
|
290
|
+
readonly definitions?: Definitions;
|
|
291
|
+
/**
|
|
292
|
+
* A copy without the named components. The model no longer sees them, so
|
|
293
|
+
* the prompt gets smaller. State and functions stay. Call it once, at
|
|
294
|
+
* module level, like `createGenerativeUI`.
|
|
295
|
+
*
|
|
296
|
+
* @throws Error when a name is not a component of this UI.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* const ui = createGenerativeUI({
|
|
301
|
+
* id: "acme/app@1",
|
|
302
|
+
* extends: [standardUI.omit(["Map", "Chart"])],
|
|
303
|
+
* components: {},
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
omit<Names extends keyof Definitions["components"] & string>(names: readonly Names[]): GenerativeUI<OmitComponents<Definitions, Names>>;
|
|
308
|
+
}
|
|
309
|
+
/** Definitions without some components. */
|
|
310
|
+
type OmitComponents<Definitions extends GenerativeUIDefinitions, Names extends PropertyKey> = {
|
|
311
|
+
state: Definitions["state"];
|
|
312
|
+
functions: Definitions["functions"];
|
|
313
|
+
components: Omit<Definitions["components"], Names>;
|
|
314
|
+
};
|
|
315
|
+
type AnyGenerativeUI = GenerativeUI<any>;
|
|
316
|
+
/**
|
|
317
|
+
* Any function or class component. Unlike `ComponentType`, checking a value
|
|
318
|
+
* against it does not read the component's props type. So a component can
|
|
319
|
+
* type its props from `typeof ui` without a circular type reference.
|
|
320
|
+
*/
|
|
321
|
+
type AnyComponent = ((...args: never) => unknown) | (abstract new (...args: never) => unknown);
|
|
322
|
+
type Simplify<T> = { [Key in keyof T]: T[Key] } & {};
|
|
323
|
+
/** `A | B` to `A & B`. */
|
|
324
|
+
type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends ((value: infer I) => void) ? I : never;
|
|
325
|
+
type OutputOf<Schema> = SchemaOutput<Schema>;
|
|
326
|
+
type InputOf<Schema> = SchemaInput<Schema>;
|
|
327
|
+
/** The prop names. None for a component without `props`. */
|
|
328
|
+
type PropKeys<Props> = Props extends PropsSchema ? keyof OutputOf<Props> & string : never;
|
|
329
|
+
/** The input type of one prop of a props schema. */
|
|
330
|
+
type PropInput<Props, Key> = Key extends keyof InputOf<Props> ? InputOf<Props>[Key] : never;
|
|
331
|
+
/** The type-level data of a generative UI. */
|
|
332
|
+
type GenerativeUIDefinitionsOf<UI extends AnyGenerativeUI> = NonNullable<UI["definitions"]>;
|
|
333
|
+
type StateValues<State> = Simplify<{ [Key in keyof State]: OutputOf<State[Key]> }>;
|
|
334
|
+
/**
|
|
335
|
+
* The state object of a generative UI, bases included. Selectors get it, and
|
|
336
|
+
* `useGenerativeUIState(ui, key, value)` sets one key of it.
|
|
337
|
+
*/
|
|
338
|
+
type GenerativeUIStateOf<UI extends AnyGenerativeUI> = StateValues<GenerativeUIDefinitionsOf<UI>["state"]>;
|
|
339
|
+
/** The declared functions of a generative UI, bases included. */
|
|
340
|
+
type GenerativeUIFunctionsOf<UI extends AnyGenerativeUI> = GenerativeUIDefinitionsOf<UI>["functions"];
|
|
341
|
+
/** The name of a declared function of a generative UI. */
|
|
342
|
+
type GenerativeUIFunctionName<UI extends AnyGenerativeUI> = keyof GenerativeUIFunctionsOf<UI> & string;
|
|
343
|
+
/**
|
|
344
|
+
* The name of a component of a generative UI, bases included. For
|
|
345
|
+
* `GenerativeUI<any>`, it is `string`.
|
|
346
|
+
*/
|
|
347
|
+
type GenerativeUIComponentName<UI extends AnyGenerativeUI> = keyof GenerativeUIDefinitionsOf<UI>["components"] & string;
|
|
348
|
+
type FunctionInput<Functions, Name> = Name extends keyof Functions ? Functions[Name] extends GenerativeUIFunctionDefinition ? InputOf<Functions[Name]["parameters"]> : never : never;
|
|
349
|
+
/** What a caller passes to a declared function (the schema input). */
|
|
350
|
+
type GenerativeUIFunctionInput<UI extends AnyGenerativeUI, Name extends GenerativeUIFunctionName<UI>> = FunctionInput<GenerativeUIFunctionsOf<UI>, Name>;
|
|
351
|
+
/**
|
|
352
|
+
* What the handler of a declared function gets: the parsed arguments (the
|
|
353
|
+
* schema output, with defaults set).
|
|
354
|
+
*/
|
|
355
|
+
type GenerativeUIFunctionArgs<UI extends AnyGenerativeUI, Name extends GenerativeUIFunctionName<UI>> = OutputOf<GenerativeUIFunctionsOf<UI>[Name]["parameters"]>;
|
|
356
|
+
/**
|
|
357
|
+
* The function an event calls: the function with the same name, else the
|
|
358
|
+
* name without `on` and with a lowercase first letter. `never` when none.
|
|
359
|
+
*/
|
|
360
|
+
type MatchedFunction<Name extends string, Functions> = Name extends keyof Functions ? Name : Name extends `on${infer Rest}` ? Uncapitalize<Rest> extends keyof Functions ? Uncapitalize<Rest> : never : never;
|
|
361
|
+
/**
|
|
362
|
+
* The argument type of an event prop. The event `parameters` input when it
|
|
363
|
+
* declares them, else the input of the matched function.
|
|
364
|
+
*/
|
|
365
|
+
type GenerativeUIEventInput<Name extends string, Event, Functions> = "parameters" extends keyof Event ? InputOf<Event["parameters" & keyof Event]> : FunctionInput<Functions, MatchedFunction<Name, Functions>>;
|
|
366
|
+
type DataProps<Props> = Props extends PropsSchema ? OutputOf<Props> : {};
|
|
367
|
+
type EventProps<Events, Functions> = Events extends Record<string, unknown> ? { [Name in keyof Events]?: (args: GenerativeUIEventInput<Name & string, Events[Name], Functions>) => Promise<GenerativeUIInvokeResult> } : {};
|
|
368
|
+
type SlotProps<Slots> = Slots extends Record<string, unknown> ? { [Name in keyof Slots]?: ReactNode } : {};
|
|
369
|
+
type WritableKeys<Writable> = Writable extends readonly (infer Key)[] ? Key & string : never;
|
|
370
|
+
/** One setter for each writable prop: `value` gets `setValue`. */
|
|
371
|
+
type SetterProps<Props, Writable> = { [Key in WritableKeys<Writable> & PropKeys<Props> as `set${Capitalize<Key>}`]: (value: PropInput<Props, Key>) => void };
|
|
372
|
+
/**
|
|
373
|
+
* Props that the renderer passes to a component:
|
|
374
|
+
* `function CheckoutForm(props: GenerativeUIComponentProps<typeof ui, "CheckoutForm">)`.
|
|
375
|
+
* Data props are the parsed `props` schema, bound props included. Event and
|
|
376
|
+
* slot props are present only when they are bound or filled. Each writable
|
|
377
|
+
* prop gets a setter (`value` gets `setValue`), which is always present.
|
|
378
|
+
*/
|
|
379
|
+
type GenerativeUIComponentProps<UI extends AnyGenerativeUI, Name extends keyof GenerativeUIDefinitionsOf<UI>["components"] & string> = Simplify<DataProps<GenerativeUIDefinitionsOf<UI>["components"][Name]["props"]> & EventProps<GenerativeUIDefinitionsOf<UI>["components"][Name]["events"], GenerativeUIDefinitionsOf<UI>["functions"]> & SlotProps<GenerativeUIDefinitionsOf<UI>["components"][Name]["slots"]> & SetterProps<GenerativeUIDefinitionsOf<UI>["components"][Name]["props"], GenerativeUIDefinitionsOf<UI>["components"][Name]["writable"]>>;
|
|
380
|
+
type BaseDefinitions<Bases extends readonly AnyGenerativeUI[]> = GenerativeUIDefinitionsOf<Bases[number]>;
|
|
381
|
+
type MergedState<Bases extends readonly AnyGenerativeUI[], State> = Simplify<UnionToIntersection<BaseDefinitions<Bases>["state"]> & State>;
|
|
382
|
+
type MergedFunctions<Bases extends readonly AnyGenerativeUI[], Functions> = Simplify<UnionToIntersection<BaseDefinitions<Bases>["functions"]> & Functions>;
|
|
383
|
+
/** Props keys with the name of a top-level state key. */
|
|
384
|
+
type NameKeys<Props, State> = PropKeys<Props> & keyof State;
|
|
385
|
+
type SelectorFor<Props, State, Key extends PropKeys<Props>> = (state: StateValues<State>, props: Simplify<Omit<InputOf<Props>, NameKeys<Props, State> | Key>>) => PropInput<Props, Key>;
|
|
386
|
+
type BindSelectors<Props, State> = { [Key in PropKeys<Props>]?: SelectorFor<Props, State, Key> };
|
|
387
|
+
/** Name-bound keys whose state type does not fit the prop schema input. */
|
|
388
|
+
type MismatchedNameKeys<Props, State> = { [Key in NameKeys<Props, State>]: [OutputOf<State[Key]>] extends [PropInput<Props, Key>] ? never : Key }[NameKeys<Props, State>];
|
|
389
|
+
/**
|
|
390
|
+
* `bind` is optional. When a prop has the name of a state key but the state
|
|
391
|
+
* type does not fit, `bind` must give that prop a selector.
|
|
392
|
+
*/
|
|
393
|
+
type BindField<Props, State> = [MismatchedNameKeys<Props, State>] extends [never] ? {
|
|
394
|
+
bind?: BindSelectors<Props, State>;
|
|
395
|
+
} : {
|
|
396
|
+
bind: BindSelectors<Props, State> & { [Key in MismatchedNameKeys<Props, State>]-?: SelectorFor<Props, State, Key> };
|
|
397
|
+
};
|
|
398
|
+
/** `unknown` (no props) or an object schema. Else `props` gets an error. */
|
|
399
|
+
type PropsCheck<Props> = unknown extends Props ? unknown : Props extends PropsSchema ? unknown : {
|
|
400
|
+
props?: PropsSchema;
|
|
401
|
+
};
|
|
402
|
+
type MatchCheck<Name extends string, Event, Functions> = [MatchedFunction<Name, Functions>] extends [never] ? "parameters" extends keyof Event ? unknown : {
|
|
403
|
+
parameters: GenerativeUISchema;
|
|
404
|
+
} : "parameters" extends keyof Event ? [OutputOf<Event["parameters" & keyof Event]>] extends [FunctionInput<Functions, MatchedFunction<Name, Functions>>] ? unknown : {
|
|
405
|
+
parameters: `The output of these parameters does not fit the input of function "${MatchedFunction<Name, Functions> & string}".`;
|
|
406
|
+
} : unknown;
|
|
407
|
+
/**
|
|
408
|
+
* `unknown` when the event is valid. Else a type the event does not fit, so
|
|
409
|
+
* `tsc` reports the error on the event.
|
|
410
|
+
*/
|
|
411
|
+
type EventCheck<Name extends string, Event, Functions> = Event extends GenerativeUIEventDefinition ? MatchCheck<Name, Event, Functions> : GenerativeUIEventDefinition;
|
|
412
|
+
type EventsCheck<Events, Functions> = { [Name in keyof Events]: EventCheck<Name & string, Events[Name], Functions> };
|
|
413
|
+
/** Props that a component can list in `writable`: not bound by name. */
|
|
414
|
+
type WritableKey<Props, State> = Exclude<PropKeys<Props>, NameKeys<Props, State>>;
|
|
415
|
+
/**
|
|
416
|
+
* Each component config is split over four mapped types. Each one infers
|
|
417
|
+
* one part (props, events, slots, writable) of every component. The checks
|
|
418
|
+
* are in `NoInfer`, so they do not change what is inferred. They are not
|
|
419
|
+
* intersected with schema types directly, because two schema class types do
|
|
420
|
+
* not intersect cleanly.
|
|
421
|
+
*/
|
|
422
|
+
type ComponentsConfig<Props, Events, Slots, Writable, State, Functions> = { [Name in keyof Props]: {
|
|
423
|
+
component: AnyComponent;
|
|
424
|
+
description?: string;
|
|
425
|
+
parameterOrder?: readonly string[];
|
|
426
|
+
props?: Props[Name];
|
|
427
|
+
accessibility?: "wrapper" | "self";
|
|
428
|
+
} & NoInfer<PropsCheck<Props[Name]> & BindField<Props[Name], State>> } & { [Name in keyof Events]: {
|
|
429
|
+
events?: Events[Name] & NoInfer<EventsCheck<Events[Name], Functions>>;
|
|
430
|
+
} } & { [Name in keyof Slots]: {
|
|
431
|
+
slots?: Slots[Name] & Record<string, GenerativeUISlotKind>;
|
|
432
|
+
} } & { [Name in keyof Writable]: {
|
|
433
|
+
writable?: Writable[Name] & NoInfer<readonly WritableKey<Props[Name & keyof Props], State>[]>;
|
|
434
|
+
} };
|
|
435
|
+
/** The config of `createGenerativeUI`. */
|
|
436
|
+
interface CreateGenerativeUIConfig<Bases extends readonly AnyGenerativeUI[], State extends Record<string, GenerativeUISchema>, Functions extends Record<string, GenerativeUIFunctionDefinition>, Props extends Record<string, unknown>, Events extends Record<string, unknown>, Slots extends Record<string, unknown>, Writable extends Record<string, unknown>> {
|
|
437
|
+
/** Surfaces pin to it. Use a versioned id, for example "acme/store@1". */
|
|
438
|
+
id: string;
|
|
439
|
+
/** Bases. Their state, functions and components merge in, in order. */
|
|
440
|
+
extends?: Bases;
|
|
441
|
+
/** App state schemas, by top-level key. Put it before `components`. */
|
|
442
|
+
state?: State;
|
|
443
|
+
/** Functions that components can call. */
|
|
444
|
+
functions?: Functions;
|
|
445
|
+
/**
|
|
446
|
+
* New React components for components of the bases, by name. The model
|
|
447
|
+
* sees the same component: its description, props, events and slots stay.
|
|
448
|
+
* The new component gets the same props as the one it replaces.
|
|
449
|
+
*/
|
|
450
|
+
overrides?: NoInfer<OverridesConfig<Bases>>;
|
|
451
|
+
/** The components the model can render. */
|
|
452
|
+
components: ComponentsConfig<Props, Events, Slots, Writable, MergedState<Bases, State>, MergedFunctions<Bases, Functions>>;
|
|
453
|
+
}
|
|
454
|
+
/** The definitions of the bases, merged. */
|
|
455
|
+
type BasesDefinitions<Bases extends readonly AnyGenerativeUI[]> = ResultDefinitions<Bases, {}, {}, {}, {}, {}, {}>;
|
|
456
|
+
/** One new React component for each component of the bases that it names. */
|
|
457
|
+
type OverridesConfig<Bases extends readonly AnyGenerativeUI[]> = { [Name in keyof BasesDefinitions<Bases>["components"] & string]?: {
|
|
458
|
+
component: ComponentType<BasesDefinitions<Bases> extends infer Definitions extends GenerativeUIDefinitions ? GenerativeUIComponentProps<GenerativeUI<Definitions>, Name> : never>;
|
|
459
|
+
} };
|
|
460
|
+
type OwnComponents<Props, Events, Slots, Writable> = { [Name in keyof Props]: {
|
|
461
|
+
props: Props[Name];
|
|
462
|
+
events: Name extends keyof Events ? Events[Name] : unknown;
|
|
463
|
+
slots: Name extends keyof Slots ? Slots[Name] : unknown;
|
|
464
|
+
writable: Name extends keyof Writable ? Writable[Name] : unknown;
|
|
465
|
+
} };
|
|
466
|
+
type ResultDefinitions<Bases extends readonly AnyGenerativeUI[], State, Functions, Props, Events, Slots, Writable> = {
|
|
467
|
+
state: MergedState<Bases, State>;
|
|
468
|
+
functions: MergedFunctions<Bases, Functions>;
|
|
469
|
+
components: Simplify<UnionToIntersection<BaseDefinitions<Bases>["components"]> & OwnComponents<Props, Events, Slots, Writable>>;
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* The id of the catalog that declared each component of `ui`. A component
|
|
473
|
+
* from `extends` keeps the id of its base. Not exported from the package.
|
|
474
|
+
*/
|
|
475
|
+
/**
|
|
476
|
+
* Experimental. Declares the components the model can render, the app state
|
|
477
|
+
* they read, and the functions they call.
|
|
478
|
+
*
|
|
479
|
+
* - A prop with the name of a top-level state key is bound to that state.
|
|
480
|
+
* - `bind: { prop: (state, props) => value }` binds a prop to a selector.
|
|
481
|
+
* - An event binds to the function with its name, else to the name without
|
|
482
|
+
* `on` (`onAddToCart` calls `addToCart`).
|
|
483
|
+
* - `writable: ["value"]` gives the component a `setValue` prop. See
|
|
484
|
+
* `GenerativeUIComponentDefinition.writable`.
|
|
485
|
+
*
|
|
486
|
+
* The model does not see bound props or matched events.
|
|
487
|
+
*
|
|
488
|
+
* @param config - `id`, then optional `extends`, `state`, `functions` and
|
|
489
|
+
* `overrides`, then `components`. Put `state` before `components`, so the selectors
|
|
490
|
+
* get typed state.
|
|
491
|
+
* @throws Error when a name comes from two places, an override names no
|
|
492
|
+
* component of the bases, `props` is not an object
|
|
493
|
+
* schema with a JSON Schema, a key is reserved or used
|
|
494
|
+
* twice on a component, an event matches two functions, an unmatched event
|
|
495
|
+
* has no `parameters`, a `bind` key is not a prop, a `writable` key is not
|
|
496
|
+
* a prop or is a bound prop, or a setter name is already a key of the
|
|
497
|
+
* component. Also throws when `parameterOrder` contains duplicate or unknown
|
|
498
|
+
* keys, or an ordered component declares integer-index keys whose JSON object
|
|
499
|
+
* enumeration order cannot be controlled.
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```ts
|
|
503
|
+
* const ui = createGenerativeUI({
|
|
504
|
+
* id: "acme/store@1",
|
|
505
|
+
* state: { cart: cartSchema },
|
|
506
|
+
* functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
|
|
507
|
+
* components: {
|
|
508
|
+
* CartSummary: {
|
|
509
|
+
* component: CartSummary,
|
|
510
|
+
* props: z.object({ count: z.number() }),
|
|
511
|
+
* bind: { count: (state) => state.cart.count },
|
|
512
|
+
* },
|
|
513
|
+
* },
|
|
514
|
+
* });
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
declare function createGenerativeUI<Bases extends readonly AnyGenerativeUI[] = [], State extends Record<string, GenerativeUISchema> = {}, Functions extends Record<string, GenerativeUIFunctionDefinition> = {}, Props extends Record<string, unknown> = {}, Events extends Record<string, unknown> = {}, Slots extends Record<string, unknown> = {}, Writable extends Record<string, unknown> = {}>(config: CreateGenerativeUIConfig<Bases, State, Functions, Props, Events, Slots, Writable>): GenerativeUI<ResultDefinitions<Bases, State, Functions, Props, Events, Slots, Writable>>;
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/v2/generative-ui/dispatcher.d.ts
|
|
520
|
+
/**
|
|
521
|
+
* Holds the latest handler of one mounted `useGenerativeUIFunction`. The hook
|
|
522
|
+
* updates `current` on each render, so it registers only once per mount.
|
|
523
|
+
*/
|
|
524
|
+
interface GenerativeUIHandlerRef {
|
|
525
|
+
current: (args: any) => unknown;
|
|
526
|
+
}
|
|
527
|
+
/** The component of a surface that called a function. */
|
|
528
|
+
interface GenerativeUIInvocationOrigin {
|
|
529
|
+
surfaceId: string;
|
|
530
|
+
componentId: string;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* What called a function: a component of a surface, or the agent with a
|
|
534
|
+
* `callRendererFunction` operation.
|
|
535
|
+
*/
|
|
536
|
+
type GenerativeUICallOrigin = GenerativeUIInvocationOrigin | {
|
|
537
|
+
functionCallId: string;
|
|
538
|
+
};
|
|
539
|
+
interface GenerativeUIDispatcher {
|
|
540
|
+
/**
|
|
541
|
+
* Call a declared function with arguments from generated UI or from the
|
|
542
|
+
* agent. Never throws: every failure becomes `{ ok: false, error }`.
|
|
543
|
+
*/
|
|
544
|
+
invoke(name: string, args: unknown, origin: GenerativeUICallOrigin): Promise<GenerativeUIInvokeResult>;
|
|
545
|
+
/** The declared functions that have exactly one mounted handler, as JSON Schema. */
|
|
546
|
+
listExposed(): Record<string, GenerativeUIFunctionManifest>;
|
|
547
|
+
/**
|
|
548
|
+
* Mount a handler for a declared function. Returns the function that
|
|
549
|
+
* unmounts it. Calling the returned function more than once is safe.
|
|
550
|
+
*/
|
|
551
|
+
register(name: string, ref: GenerativeUIHandlerRef): () => void;
|
|
552
|
+
/** How many handlers are mounted for `name`, for the inspector. */
|
|
553
|
+
handlerCount(name: string): number;
|
|
554
|
+
}
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region src/v2/generative-ui/surface-manager.d.ts
|
|
557
|
+
interface ManagedSurface {
|
|
558
|
+
readonly key: string;
|
|
559
|
+
readonly threadId: string;
|
|
560
|
+
readonly surfaceId: string;
|
|
561
|
+
readonly agentId: string | undefined;
|
|
562
|
+
/** Replaced by an empty model when the surface closes, to free its data. */
|
|
563
|
+
model: SurfaceModel<any>;
|
|
564
|
+
readonly createdAt: number;
|
|
565
|
+
target: string;
|
|
566
|
+
status: GenerativeUISurfaceStatus;
|
|
567
|
+
deleted: boolean;
|
|
568
|
+
/** Its first createSurface was rejected, so it never existed. */
|
|
569
|
+
failed: boolean;
|
|
570
|
+
/** Rejections reported by the runtime. */
|
|
571
|
+
serverRejected: GenerativeUIRejectedOperation[];
|
|
572
|
+
/** Rejections detected while applying operations in the browser. */
|
|
573
|
+
clientRejected: GenerativeUIRejectedOperation[];
|
|
574
|
+
/** The committed operations of the latest content, for the inspector. */
|
|
575
|
+
operations: readonly A2UIOperation[];
|
|
576
|
+
}
|
|
577
|
+
interface GenerativeUISurfaceManagerOptions {
|
|
578
|
+
onOperationRejected?: (info: {
|
|
579
|
+
surfaceId: string;
|
|
580
|
+
index: number;
|
|
581
|
+
reason: string;
|
|
582
|
+
}) => void;
|
|
583
|
+
}
|
|
584
|
+
/** What one mount of a target tells the model. */
|
|
585
|
+
interface GenerativeUITargetOptions {
|
|
586
|
+
/** Where the target is on the page and what to show in it. */
|
|
587
|
+
description?: string;
|
|
588
|
+
/**
|
|
589
|
+
* The only components that the surfaces of the target can use. Left out,
|
|
590
|
+
* every component of the UI is allowed.
|
|
591
|
+
*/
|
|
592
|
+
components?: readonly string[];
|
|
593
|
+
}
|
|
594
|
+
/** A mounted target, as the manifest lists it. */
|
|
595
|
+
interface GenerativeUIMountedTarget {
|
|
596
|
+
id: string;
|
|
597
|
+
description?: string;
|
|
598
|
+
components?: string[];
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Framework-agnostic store of generated surfaces. One web_core SurfaceModel per
|
|
602
|
+
* (threadId, surfaceId), shared by every mount. Applies only newly committed
|
|
603
|
+
* operations, validates each before applying it, and owns app state and the
|
|
604
|
+
* data model paths that the user wrote, so agent updates cannot overwrite
|
|
605
|
+
* them. App state never goes into a surface's data model. Selectors read it
|
|
606
|
+
* with `getState()`.
|
|
607
|
+
*/
|
|
608
|
+
declare class GenerativeUISurfaceManager {
|
|
609
|
+
private readonly ui;
|
|
610
|
+
private readonly options;
|
|
611
|
+
private readonly surfaces;
|
|
612
|
+
private readonly bookkeeping;
|
|
613
|
+
private readonly listeners;
|
|
614
|
+
/** Mounts of each target id, in mount order. */
|
|
615
|
+
private readonly targets;
|
|
616
|
+
private state;
|
|
617
|
+
/**
|
|
618
|
+
* User-owned data model values, by surface key, then by path. Kept when a
|
|
619
|
+
* surface is rebuilt. Cleared when the surface is deleted.
|
|
620
|
+
*/
|
|
621
|
+
private readonly owned;
|
|
622
|
+
/**
|
|
623
|
+
* Keys of the surfaces that a `deleteSurface` removed. A surface id is
|
|
624
|
+
* unique for the life of the page, so a key stays here when its surface is
|
|
625
|
+
* built again.
|
|
626
|
+
*/
|
|
627
|
+
private readonly deletedKeys;
|
|
628
|
+
/**
|
|
629
|
+
* Surfaces that share their data model, by surface key: the parts of a
|
|
630
|
+
* chat surface that the prose lift split. A user write to one part goes
|
|
631
|
+
* to every part, so an input in one part drives a binding in another.
|
|
632
|
+
*/
|
|
633
|
+
private readonly linked;
|
|
634
|
+
private readonly webCoreCatalog;
|
|
635
|
+
private activeThreadId;
|
|
636
|
+
private version;
|
|
637
|
+
constructor(ui: GenerativeUI, options?: GenerativeUISurfaceManagerOptions);
|
|
638
|
+
subscribe: (listener: () => void) => (() => void);
|
|
639
|
+
getVersion: () => number;
|
|
640
|
+
private notify;
|
|
641
|
+
setActiveThread(threadId: string | undefined): void;
|
|
642
|
+
getActiveThread(): string | undefined;
|
|
643
|
+
ingest(threadId: string, agentId: string | undefined, content: GenerativeUISurfaceContent): void;
|
|
644
|
+
/** The surface of a `key` (see `surfaceKey`), unless it is deleted. */
|
|
645
|
+
getSurfaceByKey(key: string): ManagedSurface | undefined;
|
|
646
|
+
getSurface(threadId: string, surfaceId: string): ManagedSurface | undefined;
|
|
647
|
+
getSurfaceForTarget(target: string, threadId?: string | undefined): ManagedSurface | undefined;
|
|
648
|
+
/**
|
|
649
|
+
* A surface whose first createSurface was rejected, so the chat can show
|
|
650
|
+
* the error where the surface would be. `undefined` for any other surface.
|
|
651
|
+
*/
|
|
652
|
+
getFailedSurface(threadId: string, surfaceId: string): ManagedSurface | undefined;
|
|
653
|
+
/**
|
|
654
|
+
* The surfaces of a thread, for the model. A surface with user-owned
|
|
655
|
+
* values lists them in `dataModel`, so the model can read what the user
|
|
656
|
+
* entered. A surface with dropped operations lists them in `rejected`, so
|
|
657
|
+
* the model can fix them on the next run. A deleted surface, or one that
|
|
658
|
+
* was never created, has a `status`, so the model knows that the id is
|
|
659
|
+
* not a live surface.
|
|
660
|
+
*/
|
|
661
|
+
describeSurfaces(threadId: string): Record<string, GenerativeUISurfaceSummary>;
|
|
662
|
+
/** Every surface that is not deleted, oldest first, for the inspector. */
|
|
663
|
+
debugSurfaces(): {
|
|
664
|
+
surfaceId: string;
|
|
665
|
+
threadId: string;
|
|
666
|
+
agentId: string | undefined;
|
|
667
|
+
target: string;
|
|
668
|
+
status: GenerativeUISurfaceStatus;
|
|
669
|
+
operations: readonly A2UIOperation[];
|
|
670
|
+
dataModel: any;
|
|
671
|
+
userValues: {
|
|
672
|
+
[k: string]: unknown;
|
|
673
|
+
};
|
|
674
|
+
rejected: ({
|
|
675
|
+
source: "runtime";
|
|
676
|
+
index: number;
|
|
677
|
+
reason: string;
|
|
678
|
+
} | {
|
|
679
|
+
source: "browser";
|
|
680
|
+
index: number;
|
|
681
|
+
reason: string;
|
|
682
|
+
})[];
|
|
683
|
+
}[];
|
|
684
|
+
/**
|
|
685
|
+
* Marks a target as mounted. Returns the function that unmounts it. Calling
|
|
686
|
+
* that function more than once has no effect.
|
|
687
|
+
*
|
|
688
|
+
* @param id - The target id.
|
|
689
|
+
* @param options - The description and the allowed components of this mount.
|
|
690
|
+
*/
|
|
691
|
+
registerTarget(id: string, options?: GenerativeUITargetOptions): () => void;
|
|
692
|
+
/**
|
|
693
|
+
* The mounted targets. Each has the description and the component list of
|
|
694
|
+
* its earliest mount that has one.
|
|
695
|
+
*/
|
|
696
|
+
getMountedTargets(): GenerativeUIMountedTarget[];
|
|
697
|
+
/**
|
|
698
|
+
* The component list of the earliest mount of `id` that has one.
|
|
699
|
+
* `undefined` when no mount of `id` limits its components.
|
|
700
|
+
*/
|
|
701
|
+
private targetComponents;
|
|
702
|
+
/** The components that `validateOperation` allows on a surface. */
|
|
703
|
+
private allowedComponentsFor;
|
|
704
|
+
/**
|
|
705
|
+
* The app state object. It is the same object until a key changes, so it
|
|
706
|
+
* can be a `useSyncExternalStore` snapshot.
|
|
707
|
+
*/
|
|
708
|
+
getState: () => Readonly<Record<string, unknown>>;
|
|
709
|
+
/** Sets one state key. Notifies only when the value changed. */
|
|
710
|
+
setState(key: string, value: unknown): void;
|
|
711
|
+
/** Removes one state key. Notifies only when the key was set. */
|
|
712
|
+
removeState(key: string): void;
|
|
713
|
+
/**
|
|
714
|
+
* Makes the surfaces of `surfaceIds` share their data model: a user write
|
|
715
|
+
* to one of them goes to all of them (see `setOwnedValue`). The markdown
|
|
716
|
+
* transport links the parts of a chat surface that the prose lift split.
|
|
717
|
+
* A later call for one of the surfaces replaces its group.
|
|
718
|
+
*
|
|
719
|
+
* @param threadId - The thread of the surfaces.
|
|
720
|
+
* @param surfaceIds - The surface ids of the group. One id clears a link.
|
|
721
|
+
*/
|
|
722
|
+
linkSurfaces(threadId: string, surfaceIds: readonly string[]): void;
|
|
723
|
+
/**
|
|
724
|
+
* Writes a user value into the data model of a surface, and marks `path`
|
|
725
|
+
* as user-owned. Then agent writes to that path, or below it, are ignored.
|
|
726
|
+
* An agent write above it keeps the user value. Ownership ends when the
|
|
727
|
+
* surface is deleted. Does nothing for an unknown or deleted surface. The
|
|
728
|
+
* surfaces linked to it (see `linkSurfaces`) get the same write.
|
|
729
|
+
*
|
|
730
|
+
* @param key - The `key` of the surface.
|
|
731
|
+
* @param path - An absolute JSON pointer, for example "/form/email".
|
|
732
|
+
* @param value - The new value. It is copied.
|
|
733
|
+
* @throws Error when a path segment is "__proto__", "constructor" or
|
|
734
|
+
* "prototype", or when the path does not fit the data (for example, a
|
|
735
|
+
* segment above it holds a string).
|
|
736
|
+
*/
|
|
737
|
+
setOwnedValue(key: string, path: string, value: unknown): void;
|
|
738
|
+
private writeOwnedValue;
|
|
739
|
+
/**
|
|
740
|
+
* Writes the user-owned values into the new, empty data model of a rebuilt
|
|
741
|
+
* surface. The agent operations are applied after it.
|
|
742
|
+
*/
|
|
743
|
+
private restoreOwnedValues;
|
|
744
|
+
/**
|
|
745
|
+
* The value that an agent write puts at `path`, with the user-owned values
|
|
746
|
+
* below `path` written back into it. `undefined` when `path` is user-owned
|
|
747
|
+
* or below a user-owned path, so the agent cannot write it. Throws when a
|
|
748
|
+
* user value does not fit the new value.
|
|
749
|
+
*/
|
|
750
|
+
private mergeOwnedValues;
|
|
751
|
+
private extendsApplied;
|
|
752
|
+
private createSurface;
|
|
753
|
+
private disposeSurface;
|
|
754
|
+
/**
|
|
755
|
+
* Marks a surface deleted and frees its components and data. The record
|
|
756
|
+
* stays, so the model is still told about the id and the bookkeeping does
|
|
757
|
+
* not rebuild the surface for content that was already applied.
|
|
758
|
+
*/
|
|
759
|
+
private closeSurface;
|
|
760
|
+
/** The surfaces of a thread that a part of `surfaceId` reads, for tests. */
|
|
761
|
+
getLinkedSurfaceIds(threadId: string, surfaceId: string): string[];
|
|
762
|
+
/**
|
|
763
|
+
* Drops the node keys that the app sets: bound props and matched events.
|
|
764
|
+
* The model does not see them, so a model value for one is ignored, not
|
|
765
|
+
* rejected. This runs before validation, because validation rejects keys
|
|
766
|
+
* that are not in the manifest. It never changes the given operation.
|
|
767
|
+
*/
|
|
768
|
+
private dropAppSetKeys;
|
|
769
|
+
private dropAppSetNodeKeys;
|
|
770
|
+
/**
|
|
771
|
+
* The surfaces that `validateOperation` gets for one operation of the
|
|
772
|
+
* content of `surface`.
|
|
773
|
+
*
|
|
774
|
+
* - `knownSurfaces`: the surface, when it exists before the operation. It
|
|
775
|
+
* does not exist before its first createSurface, or after a delete.
|
|
776
|
+
* - `createdSurfaces`: the surface, when a createSurface at this position
|
|
777
|
+
* uses its id again. That is the case after the first operation, and for
|
|
778
|
+
* a surface that was deleted before, unless the content replays that
|
|
779
|
+
* delete.
|
|
780
|
+
*/
|
|
781
|
+
private surfacesFor;
|
|
782
|
+
private applyOperation;
|
|
783
|
+
/** The first node with props of the wrong type, as a reason. */
|
|
784
|
+
private nodesProblem;
|
|
785
|
+
/**
|
|
786
|
+
* Writes an agent value at `path` and keeps the user-owned values. A write
|
|
787
|
+
* to a user-owned path is ignored, not rejected. Gives the reason when the
|
|
788
|
+
* value does not fit the data, else `undefined`.
|
|
789
|
+
*/
|
|
790
|
+
private writeAgentData;
|
|
791
|
+
private checkNodeProps;
|
|
792
|
+
private upsertNode;
|
|
793
|
+
}
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region src/v2/generative-ui/standard/tokens.d.ts
|
|
796
|
+
declare const RADII: readonly ["2xs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl", "4xl", "full"];
|
|
797
|
+
declare const TEXT_COLORS: readonly ["default", "prose", "primary", "emphasis", "secondary", "tertiary", "success", "info", "warning", "caution", "danger", "discovery"];
|
|
798
|
+
declare const BORDER_COLORS: readonly ["default", "subtle", "strong", "info", "warning", "caution", "success", "danger", "discovery"];
|
|
799
|
+
declare const BACKGROUNDS: readonly ["surface", "surface-secondary", "surface-tertiary", "surface-elevated", "surface-elevated-secondary", "surface-inverted", "surface-soft", "info", "warning", "caution", "success", "danger", "discovery", "info-solid", "warning-solid", "caution-solid", "success-solid", "danger-solid", "discovery-solid"];
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/v2/generative-ui/theme.d.ts
|
|
802
|
+
type TextColor = (typeof TEXT_COLORS)[number];
|
|
803
|
+
type BorderColor = (typeof BORDER_COLORS)[number];
|
|
804
|
+
type Background = (typeof BACKGROUNDS)[number];
|
|
805
|
+
type Radius = Exclude<(typeof RADII)[number], "full">;
|
|
806
|
+
type Tint = "info" | "warning" | "caution" | "success" | "danger" | "discovery";
|
|
807
|
+
type ChartSeries = 1 | 2 | 3 | 4 | 5 | 6;
|
|
808
|
+
/** Every CSS variable that the standard components read. */
|
|
809
|
+
type GenerativeUIThemeVariable = `--a2ui-color-text-${TextColor}` | `--a2ui-color-${Background}` | `--a2ui-color-border-${BorderColor}` | `--a2ui-color-${Tint}-soft` | `--a2ui-radius-${Radius}` | `--a2ui-chart-${ChartSeries}` | "--a2ui-color-accent" | "--a2ui-color-on-accent" | "--a2ui-color-panel" | "--a2ui-color-control" | "--a2ui-color-focus" | "--a2ui-color-shimmer" | "--a2ui-color-chart-cursor" | "--a2ui-color-slider-track" | "--a2ui-color-badge-secondary" | "--a2ui-color-border-control" | "--a2ui-color-highlight-green" | "--a2ui-color-highlight-orange" | "--a2ui-color-highlight-pink" | "--a2ui-color-backdrop" | "--a2ui-color-overlay" | "--a2ui-color-rating" | "--a2ui-shadow-xs" | "--a2ui-shadow-sm" | "--a2ui-shadow-soft" | "--a2ui-shadow-md" | "--a2ui-font-family" | "--a2ui-heading-margin" | "--a2ui-block-margin";
|
|
810
|
+
/** Values for the theme variables. A name that is not one is a type error. */
|
|
811
|
+
type GenerativeUIThemeVariables = { [Variable in GenerativeUIThemeVariable]?: string };
|
|
812
|
+
/** The values of one color scheme, plus the map style of that scheme. */
|
|
813
|
+
type GenerativeUIThemeValues = GenerativeUIThemeVariables & {
|
|
814
|
+
/** A MapLibre style URL for the Map component. */mapStyle?: string;
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* The look of generated UI. Values at the top level apply in light and in
|
|
818
|
+
* dark mode. Values in `dark` replace them in dark mode. Dark mode is on
|
|
819
|
+
* when an ancestor of the surface has the `dark` class, like the CopilotKit
|
|
820
|
+
* chat.
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```ts
|
|
824
|
+
* const theme: GenerativeUITheme = {
|
|
825
|
+
* "--a2ui-color-accent": "#d97706",
|
|
826
|
+
* "--a2ui-font-family": "Inter, sans-serif",
|
|
827
|
+
* dark: { "--a2ui-color-panel": "#1f2937" },
|
|
828
|
+
* };
|
|
829
|
+
* ```
|
|
830
|
+
*/
|
|
831
|
+
type GenerativeUITheme = GenerativeUIThemeValues & {
|
|
832
|
+
dark?: GenerativeUIThemeValues;
|
|
833
|
+
};
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region src/v2/generative-ui/runtime-context.d.ts
|
|
836
|
+
interface GenerativeUIErrorBoundaryConfig {
|
|
837
|
+
/** Replaces the default per-component fallback. */
|
|
838
|
+
fallback?: (props: {
|
|
839
|
+
error: Error;
|
|
840
|
+
retry: () => void;
|
|
841
|
+
surfaceId: string;
|
|
842
|
+
componentId: string;
|
|
843
|
+
}) => ReactNode;
|
|
844
|
+
/** Called for render, props, operation, function and event failures. */
|
|
845
|
+
onError?: (info: GenerativeUIErrorInfo) => void;
|
|
846
|
+
}
|
|
847
|
+
interface GenerativeUIBaseConfig {
|
|
848
|
+
/**
|
|
849
|
+
* The result of `createGenerativeUI`: the components the model can render,
|
|
850
|
+
* the app state they read and the functions they call.
|
|
851
|
+
*/
|
|
852
|
+
ui: GenerativeUI;
|
|
853
|
+
/**
|
|
854
|
+
* The agents that get the generative UI. When omitted, every agent gets
|
|
855
|
+
* it. Other agents get no envelope.
|
|
856
|
+
*/
|
|
857
|
+
agentIds?: string[];
|
|
858
|
+
/**
|
|
859
|
+
* Values for the `--a2ui-*` CSS variables and the map style. Top-level
|
|
860
|
+
* values apply in both modes. `dark` changes them in dark mode, which is
|
|
861
|
+
* on under a `.dark` class, like the CopilotKit chat.
|
|
862
|
+
*/
|
|
863
|
+
theme?: GenerativeUITheme;
|
|
864
|
+
/** Fallback UI and error reporting for generated UI. */
|
|
865
|
+
errorBoundary?: GenerativeUIErrorBoundaryConfig;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* The tool transport: the model calls the `render_ui` tool, and the runtime
|
|
869
|
+
* validates each operation before it streams it to the client.
|
|
870
|
+
*/
|
|
871
|
+
interface GenerativeUIToolConfig extends GenerativeUIBaseConfig {
|
|
872
|
+
/** Leave it out, or set "tool". */
|
|
873
|
+
transport?: "tool";
|
|
874
|
+
sendContext?: never;
|
|
875
|
+
includeCatalog?: never;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* The markdown transport: the model writes the operations in ```a2ui fences
|
|
879
|
+
* in its reply. The client reads and validates them.
|
|
880
|
+
*/
|
|
881
|
+
interface GenerativeUIMarkdownConfig extends GenerativeUIBaseConfig {
|
|
882
|
+
transport: "markdown";
|
|
883
|
+
/**
|
|
884
|
+
* Send the component schema and the fence guideline as context entries.
|
|
885
|
+
* Set `false` when the backend builds its own prompt from the envelope.
|
|
886
|
+
* Default `true`.
|
|
887
|
+
*/
|
|
888
|
+
sendContext?: boolean;
|
|
889
|
+
/**
|
|
890
|
+
* Send the component schemas in the envelope (`catalog.components`).
|
|
891
|
+
* Default `true`.
|
|
892
|
+
*/
|
|
893
|
+
includeCatalog?: boolean;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Experimental. The `generativeUI` prop of `CopilotKitProvider`. Set
|
|
897
|
+
* `transport: "markdown"` to get the markdown options.
|
|
898
|
+
*
|
|
899
|
+
* @example
|
|
900
|
+
* ```tsx
|
|
901
|
+
* <CopilotKitProvider generativeUI={{ ui }} />
|
|
902
|
+
* <CopilotKitProvider generativeUI={{ ui, transport: "markdown", sendContext: false }} />
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
type GenerativeUIConfig = GenerativeUIToolConfig | GenerativeUIMarkdownConfig;
|
|
906
|
+
interface GenerativeUIRuntime {
|
|
907
|
+
manager: GenerativeUISurfaceManager;
|
|
908
|
+
dispatcher: GenerativeUIDispatcher;
|
|
909
|
+
/** The generative UI given to the provider as `generativeUI={{ ui }}`. */
|
|
910
|
+
ui: GenerativeUI;
|
|
911
|
+
/** How the model sends operations. "tool" when the config leaves it out. */
|
|
912
|
+
transport: "tool" | "markdown";
|
|
913
|
+
/** The latest `generativeUI` config of the provider. */
|
|
914
|
+
readonly config: GenerativeUIConfig;
|
|
915
|
+
/** The latest `theme`. Each surface root sets its CSS variables. */
|
|
916
|
+
theme?: GenerativeUITheme;
|
|
917
|
+
forwardEvent: (event: GenerativeUIUserEvent, agentId: string | undefined) => Promise<GenerativeUIInvokeResult>;
|
|
918
|
+
reportError: (info: GenerativeUIErrorInfo) => void;
|
|
919
|
+
readonly errorFallback?: GenerativeUIErrorBoundaryConfig["fallback"];
|
|
920
|
+
}
|
|
921
|
+
declare function useGenerativeUIRuntime(): GenerativeUIRuntime | null;
|
|
922
|
+
//#endregion
|
|
923
|
+
export { GenerativeUIAccessibility as A, createGenerativeUI as C, GenerativeUIErrorInfo as D, GenerativeUIErrorCode as E, ReactActivityMessageRenderer as F, useGenerativeUIAccessibility as M, DefaultGenerativeUIChatCard as N, GenerativeUIEventHandler as O, GenerativeUIChatSurfaceProps as P, GenerativeUIStateOf as S, GenerativeUIError as T, GenerativeUIFunctionArgs as _, useGenerativeUIRuntime as a, GenerativeUIFunctionName as b, GenerativeUIThemeVariable as c, GenerativeUI as d, GenerativeUIComponentDefinition as f, GenerativeUIEventDefinition as g, GenerativeUIDefinitionsOf as h, GenerativeUIToolConfig as i, GenerativeUIAriaAttributes as j, GenerativeUIInvokeResult as k, GenerativeUIThemeVariables as l, GenerativeUIComponentProps as m, GenerativeUIErrorBoundaryConfig as n, GenerativeUITheme as o, GenerativeUIComponentName as p, GenerativeUIMarkdownConfig as r, GenerativeUIThemeValues as s, GenerativeUIConfig as t, CreateGenerativeUIConfig as u, GenerativeUIFunctionDefinition as v, SchemaInput as w, GenerativeUISlotKind as x, GenerativeUIFunctionInput as y };
|
|
924
|
+
//# sourceMappingURL=runtime-context-CrHq-iTf.d.mts.map
|