@copilotkit/react-core 2.0.0-rc.31 → 2.0.0-rc.33

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