@openuidev/a2ui 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2024 Thesys Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # `@openuidev/a2ui`
2
+
3
+ An experimental A2UI v1.0 profile that keeps the protocol lifecycle and envelopes intact while representing component lists as OpenUI Lang statements.
4
+
5
+ ```json
6
+ {
7
+ "version": "v1.0",
8
+ "updateComponents": {
9
+ "surfaceId": "main",
10
+ "components": ["root = Stack([title])", "title = TextContent(\"Hello\")"]
11
+ }
12
+ }
13
+ ```
14
+
15
+ `updateDataModel`, `deleteSurface`, actions, `callRendererFunction`, `agentFunctionResponse`, `callAgentFunction`, `rendererFunctionResponse`, errors, capabilities, and renderer data-model metadata retain their A2UI v1.0 shapes. For v1.0 single-message creation, optional `createSurface.components` uses the same Lang statement array as `updateComponents.components`, so there is exactly one component representation on the wire.
16
+
17
+ Incoming protocol messages are validated with the exported Zod schemas in the package. The public TypeScript message types are inferred from the same definitions, so runtime validation and static types stay aligned.
18
+
19
+ ## Installation
20
+
21
+ Install the framework-neutral protocol client with its runtime schema peer:
22
+
23
+ ```bash
24
+ npm install @openuidev/a2ui zod
25
+ ```
26
+
27
+ The React adapter is optional. Install its peers only when importing `@openuidev/a2ui/react`:
28
+
29
+ ```bash
30
+ npm install react @openuidev/react-lang
31
+ ```
32
+
33
+ ## How updates work
34
+
35
+ Each array item is one complete OpenUI Lang statement (a multiline statement block is also accepted). Repeated messages are merged by statement ID and the resulting source is parsed by `@openuidev/lang-core`. A newer assignment replaces the previous statement, and `statementId = null` deletes it. The `root` statement remains the surface root.
36
+
37
+ ## Usage
38
+
39
+ ```tsx
40
+ import { createA2UIClient } from "@openuidev/a2ui";
41
+ import { A2UIRenderer } from "@openuidev/a2ui/react";
42
+ import { openuiLibrary } from "@openuidev/react-ui";
43
+
44
+ const client = createA2UIClient({
45
+ schema: openuiLibrary.toJSONSchema(),
46
+ rootName: openuiLibrary.root,
47
+ rendererCapabilities: {
48
+ "v1.0": { supportedCatalogIds: ["com.example:openui"] },
49
+ },
50
+ onMessage(message, metadata) {
51
+ transport.send(message, metadata);
52
+ },
53
+ });
54
+
55
+ await client.process({
56
+ version: "v1.0",
57
+ createSurface: {
58
+ surfaceId: "main",
59
+ catalogId: "com.example:openui",
60
+ dataModel: { user: { name: "Alice" } },
61
+ },
62
+ });
63
+
64
+ await client.process({
65
+ version: "v1.0",
66
+ updateComponents: {
67
+ surfaceId: "main",
68
+ components: ["root = Stack([greeting])", 'greeting = TextContent("Hello, " + $user.name)'],
69
+ },
70
+ });
71
+
72
+ export function Surface() {
73
+ return (
74
+ <A2UIRenderer
75
+ client={client}
76
+ surfaceId="main"
77
+ library={openuiLibrary}
78
+ isStreaming={transport.isStreaming}
79
+ mapAction={(event) => ({ name: event.type })}
80
+ />
81
+ );
82
+ }
83
+ ```
84
+
85
+ The client is framework-neutral: it owns surface lifecycle, runtime envelope validation, Lang parsing and merging, data-model patches, actions, RPC, and protocol errors. `A2UIRenderer` is the React adapter; it subscribes to one surface and delegates the parsed OpenUI Lang UI to `@openuidev/react-lang`.
86
+
87
+ When `sendDataModel` is enabled, the second `onMessage` argument contains `a2uiRendererDataModel` metadata filtered to opted-in surfaces. Configured renderer capabilities are exposed in the same metadata object. The host transport decides where to attach this metadata.
88
+
89
+ Renderer functions can be registered as a direct function shorthand or as `{ handler, catalogId, allowedCallers }`. Explicit registrations default to `rendererOnly`; incoming `callRendererFunction` messages are accepted only when the catalog ID matches and `allowedCallers` is `agentOnly` or `rendererOrAgent`.
90
+
91
+ When no `toolProvider` is passed to `A2UIRenderer`, OpenUI Lang `Query()` and `Mutation()` calls automatically use A2UI `callAgentFunction` and settle from the matching `agentFunctionResponse`. Pass a `toolProvider` to handle those calls locally instead.
92
+
93
+ Use `mapAction` to provide `sourceComponentId` when the host renderer does not include one in its action event. Otherwise actions fall back to the surface `root` ID.
94
+
95
+ ## Development
96
+
97
+ The `check:attw` script intentionally ignores the `no-resolution` rule. `./react` is exported through modern package `exports`; `attw` reports `no-resolution` only for legacy Node 10 resolution, which this package does not support.
@@ -0,0 +1,399 @@
1
+ import { ActionEvent, LibraryJSONSchema, OpenUIError, ParseResult } from "@openuidev/lang-core";
2
+ import { z } from "zod/v4";
3
+
4
+ //#region src/protocol-schema.d.ts
5
+ declare const jsonValueSchema: z.ZodJSONSchema;
6
+ declare const jsonObjectSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
7
+ declare const messageMetadataSchema: z.ZodObject<{
8
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
9
+ }, z.core.$strict>;
10
+ declare const a2uiFunctionCallSchema: z.ZodObject<{
11
+ call: z.ZodString;
12
+ catalogId: z.ZodOptional<z.ZodString>;
13
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
14
+ }, z.core.$strict>;
15
+ declare const a2uiFunctionResponseSchema: z.ZodUnion<readonly [z.ZodObject<{
16
+ functionCallId: z.ZodString;
17
+ value: z.ZodJSONSchema;
18
+ }, z.core.$strict>, z.ZodObject<{
19
+ functionCallId: z.ZodString;
20
+ error: z.ZodObject<{
21
+ code: z.ZodString;
22
+ message: z.ZodString;
23
+ }, z.core.$strict>;
24
+ }, z.core.$strict>]>;
25
+ declare const createSurfaceMessageSchema: z.ZodObject<{
26
+ version: z.ZodLiteral<"v1.0">;
27
+ createSurface: z.ZodObject<{
28
+ surfaceId: z.ZodString;
29
+ catalogId: z.ZodOptional<z.ZodString>;
30
+ sendDataModel: z.ZodOptional<z.ZodBoolean>;
31
+ components: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
+ dataModel: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
33
+ metadata: z.ZodOptional<z.ZodObject<{
34
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
35
+ }, z.core.$strict>>;
36
+ }, z.core.$strict>;
37
+ }, z.core.$strict>;
38
+ declare const updateComponentsMessageSchema: z.ZodObject<{
39
+ version: z.ZodLiteral<"v1.0">;
40
+ updateComponents: z.ZodObject<{
41
+ surfaceId: z.ZodString;
42
+ components: z.ZodArray<z.ZodString>;
43
+ }, z.core.$strict>;
44
+ }, z.core.$strict>;
45
+ declare const updateDataModelMessageSchema: z.ZodObject<{
46
+ version: z.ZodLiteral<"v1.0">;
47
+ updateDataModel: z.ZodObject<{
48
+ surfaceId: z.ZodString;
49
+ path: z.ZodOptional<z.ZodString>;
50
+ value: z.ZodJSONSchema;
51
+ }, z.core.$strict>;
52
+ }, z.core.$strict>;
53
+ declare const deleteSurfaceMessageSchema: z.ZodObject<{
54
+ version: z.ZodLiteral<"v1.0">;
55
+ deleteSurface: z.ZodObject<{
56
+ surfaceId: z.ZodString;
57
+ }, z.core.$strict>;
58
+ }, z.core.$strict>;
59
+ declare const callRendererFunctionMessageSchema: z.ZodObject<{
60
+ version: z.ZodLiteral<"v1.0">;
61
+ callRendererFunction: z.ZodObject<{
62
+ functionCallId: z.ZodString;
63
+ callFunction: z.ZodObject<{
64
+ call: z.ZodString;
65
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
66
+ catalogId: z.ZodString;
67
+ }, z.core.$strict>;
68
+ }, z.core.$strict>;
69
+ }, z.core.$strict>;
70
+ declare const agentFunctionResponseMessageSchema: z.ZodObject<{
71
+ version: z.ZodLiteral<"v1.0">;
72
+ agentFunctionResponse: z.ZodUnion<readonly [z.ZodObject<{
73
+ functionCallId: z.ZodString;
74
+ value: z.ZodJSONSchema;
75
+ }, z.core.$strict>, z.ZodObject<{
76
+ functionCallId: z.ZodString;
77
+ error: z.ZodObject<{
78
+ code: z.ZodString;
79
+ message: z.ZodString;
80
+ }, z.core.$strict>;
81
+ }, z.core.$strict>]>;
82
+ }, z.core.$strict>;
83
+ declare const agentToRendererMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
84
+ version: z.ZodLiteral<"v1.0">;
85
+ createSurface: z.ZodObject<{
86
+ surfaceId: z.ZodString;
87
+ catalogId: z.ZodOptional<z.ZodString>;
88
+ sendDataModel: z.ZodOptional<z.ZodBoolean>;
89
+ components: z.ZodOptional<z.ZodArray<z.ZodString>>;
90
+ dataModel: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
91
+ metadata: z.ZodOptional<z.ZodObject<{
92
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
93
+ }, z.core.$strict>>;
94
+ }, z.core.$strict>;
95
+ }, z.core.$strict>, z.ZodObject<{
96
+ version: z.ZodLiteral<"v1.0">;
97
+ updateComponents: z.ZodObject<{
98
+ surfaceId: z.ZodString;
99
+ components: z.ZodArray<z.ZodString>;
100
+ }, z.core.$strict>;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ version: z.ZodLiteral<"v1.0">;
103
+ updateDataModel: z.ZodObject<{
104
+ surfaceId: z.ZodString;
105
+ path: z.ZodOptional<z.ZodString>;
106
+ value: z.ZodJSONSchema;
107
+ }, z.core.$strict>;
108
+ }, z.core.$strict>, z.ZodObject<{
109
+ version: z.ZodLiteral<"v1.0">;
110
+ deleteSurface: z.ZodObject<{
111
+ surfaceId: z.ZodString;
112
+ }, z.core.$strict>;
113
+ }, z.core.$strict>, z.ZodObject<{
114
+ version: z.ZodLiteral<"v1.0">;
115
+ callRendererFunction: z.ZodObject<{
116
+ functionCallId: z.ZodString;
117
+ callFunction: z.ZodObject<{
118
+ call: z.ZodString;
119
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
120
+ catalogId: z.ZodString;
121
+ }, z.core.$strict>;
122
+ }, z.core.$strict>;
123
+ }, z.core.$strict>, z.ZodObject<{
124
+ version: z.ZodLiteral<"v1.0">;
125
+ agentFunctionResponse: z.ZodUnion<readonly [z.ZodObject<{
126
+ functionCallId: z.ZodString;
127
+ value: z.ZodJSONSchema;
128
+ }, z.core.$strict>, z.ZodObject<{
129
+ functionCallId: z.ZodString;
130
+ error: z.ZodObject<{
131
+ code: z.ZodString;
132
+ message: z.ZodString;
133
+ }, z.core.$strict>;
134
+ }, z.core.$strict>]>;
135
+ }, z.core.$strict>]>;
136
+ declare const actionMessageSchema: z.ZodObject<{
137
+ version: z.ZodLiteral<"v1.0">;
138
+ action: z.ZodObject<{
139
+ name: z.ZodString;
140
+ userMessage: z.ZodOptional<z.ZodString>;
141
+ surfaceId: z.ZodString;
142
+ sourceComponentId: z.ZodString;
143
+ timestamp: z.ZodISODateTime;
144
+ context: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
145
+ metadata: z.ZodOptional<z.ZodObject<{
146
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
147
+ }, z.core.$strict>>;
148
+ }, z.core.$strict>;
149
+ }, z.core.$strict>;
150
+ declare const callAgentFunctionMessageSchema: z.ZodObject<{
151
+ version: z.ZodLiteral<"v1.0">;
152
+ callAgentFunction: z.ZodObject<{
153
+ surfaceId: z.ZodString;
154
+ functionCallId: z.ZodString;
155
+ callFunction: z.ZodObject<{
156
+ call: z.ZodString;
157
+ catalogId: z.ZodOptional<z.ZodString>;
158
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
159
+ }, z.core.$strict>;
160
+ }, z.core.$strict>;
161
+ }, z.core.$strict>;
162
+ declare const rendererFunctionResponseMessageSchema: z.ZodObject<{
163
+ version: z.ZodLiteral<"v1.0">;
164
+ rendererFunctionResponse: z.ZodUnion<readonly [z.ZodObject<{
165
+ functionCallId: z.ZodString;
166
+ value: z.ZodJSONSchema;
167
+ }, z.core.$strict>, z.ZodObject<{
168
+ functionCallId: z.ZodString;
169
+ error: z.ZodObject<{
170
+ code: z.ZodString;
171
+ message: z.ZodString;
172
+ }, z.core.$strict>;
173
+ }, z.core.$strict>]>;
174
+ }, z.core.$strict>;
175
+ declare const validationFailedErrorMessageSchema: z.ZodObject<{
176
+ version: z.ZodLiteral<"v1.0">;
177
+ error: z.ZodObject<{
178
+ code: z.ZodEnum<{
179
+ VALIDATION_FAILED: "VALIDATION_FAILED";
180
+ UNALLOWED_PARENT: "UNALLOWED_PARENT";
181
+ UNALLOWED_CHILD: "UNALLOWED_CHILD";
182
+ }>;
183
+ surfaceId: z.ZodString;
184
+ path: z.ZodString;
185
+ message: z.ZodString;
186
+ }, z.core.$strict>;
187
+ }, z.core.$strict>;
188
+ declare const genericErrorMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
189
+ version: z.ZodLiteral<"v1.0">;
190
+ error: z.ZodObject<{
191
+ code: z.ZodString;
192
+ message: z.ZodString;
193
+ surfaceId: z.ZodString;
194
+ }, z.core.$strict>;
195
+ }, z.core.$strict>, z.ZodObject<{
196
+ version: z.ZodLiteral<"v1.0">;
197
+ error: z.ZodObject<{
198
+ code: z.ZodString;
199
+ message: z.ZodString;
200
+ functionCallId: z.ZodString;
201
+ }, z.core.$strict>;
202
+ }, z.core.$strict>]>;
203
+ declare const rendererToAgentMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
204
+ version: z.ZodLiteral<"v1.0">;
205
+ action: z.ZodObject<{
206
+ name: z.ZodString;
207
+ userMessage: z.ZodOptional<z.ZodString>;
208
+ surfaceId: z.ZodString;
209
+ sourceComponentId: z.ZodString;
210
+ timestamp: z.ZodISODateTime;
211
+ context: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
212
+ metadata: z.ZodOptional<z.ZodObject<{
213
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
214
+ }, z.core.$strict>>;
215
+ }, z.core.$strict>;
216
+ }, z.core.$strict>, z.ZodObject<{
217
+ version: z.ZodLiteral<"v1.0">;
218
+ callAgentFunction: z.ZodObject<{
219
+ surfaceId: z.ZodString;
220
+ functionCallId: z.ZodString;
221
+ callFunction: z.ZodObject<{
222
+ call: z.ZodString;
223
+ catalogId: z.ZodOptional<z.ZodString>;
224
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
225
+ }, z.core.$strict>;
226
+ }, z.core.$strict>;
227
+ }, z.core.$strict>, z.ZodObject<{
228
+ version: z.ZodLiteral<"v1.0">;
229
+ rendererFunctionResponse: z.ZodUnion<readonly [z.ZodObject<{
230
+ functionCallId: z.ZodString;
231
+ value: z.ZodJSONSchema;
232
+ }, z.core.$strict>, z.ZodObject<{
233
+ functionCallId: z.ZodString;
234
+ error: z.ZodObject<{
235
+ code: z.ZodString;
236
+ message: z.ZodString;
237
+ }, z.core.$strict>;
238
+ }, z.core.$strict>]>;
239
+ }, z.core.$strict>, z.ZodObject<{
240
+ version: z.ZodLiteral<"v1.0">;
241
+ error: z.ZodObject<{
242
+ code: z.ZodEnum<{
243
+ VALIDATION_FAILED: "VALIDATION_FAILED";
244
+ UNALLOWED_PARENT: "UNALLOWED_PARENT";
245
+ UNALLOWED_CHILD: "UNALLOWED_CHILD";
246
+ }>;
247
+ surfaceId: z.ZodString;
248
+ path: z.ZodString;
249
+ message: z.ZodString;
250
+ }, z.core.$strict>;
251
+ }, z.core.$strict>, z.ZodUnion<readonly [z.ZodObject<{
252
+ version: z.ZodLiteral<"v1.0">;
253
+ error: z.ZodObject<{
254
+ code: z.ZodString;
255
+ message: z.ZodString;
256
+ surfaceId: z.ZodString;
257
+ }, z.core.$strict>;
258
+ }, z.core.$strict>, z.ZodObject<{
259
+ version: z.ZodLiteral<"v1.0">;
260
+ error: z.ZodObject<{
261
+ code: z.ZodString;
262
+ message: z.ZodString;
263
+ functionCallId: z.ZodString;
264
+ }, z.core.$strict>;
265
+ }, z.core.$strict>]>]>;
266
+ declare const rendererCapabilitiesSchema: z.ZodObject<{
267
+ "v1.0": z.ZodObject<{
268
+ supportedCatalogIds: z.ZodArray<z.ZodString>;
269
+ inlineCatalogs: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>>;
270
+ }, z.core.$strict>;
271
+ }, z.core.$strict>;
272
+ declare const agentCapabilitiesSchema: z.ZodObject<{
273
+ "v1.0": z.ZodObject<{
274
+ supportedCatalogIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
275
+ acceptsInlineCatalogs: z.ZodOptional<z.ZodBoolean>;
276
+ }, z.core.$strict>;
277
+ }, z.core.$strict>;
278
+ declare const rendererDataModelSchema: z.ZodObject<{
279
+ version: z.ZodLiteral<"v1.0">;
280
+ surfaces: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
281
+ }, z.core.$strict>;
282
+ //#endregion
283
+ //#region src/types.d.ts
284
+ type JsonValue = z.infer<typeof jsonValueSchema>;
285
+ type JsonPrimitive = Extract<JsonValue, string | number | boolean | null>;
286
+ type JsonObject = z.infer<typeof jsonObjectSchema>;
287
+ type A2UIFunctionCall = z.infer<typeof a2uiFunctionCallSchema>;
288
+ type A2UIFunctionResponse = z.infer<typeof a2uiFunctionResponseSchema>;
289
+ type A2UIMessageMetadata = z.infer<typeof messageMetadataSchema>;
290
+ type CreateSurfaceMessage = z.infer<typeof createSurfaceMessageSchema>;
291
+ type UpdateComponentsMessage = z.infer<typeof updateComponentsMessageSchema>;
292
+ type UpdateDataModelMessage = z.infer<typeof updateDataModelMessageSchema>;
293
+ type DeleteSurfaceMessage = z.infer<typeof deleteSurfaceMessageSchema>;
294
+ type CallRendererFunctionMessage = z.infer<typeof callRendererFunctionMessageSchema>;
295
+ type AgentFunctionResponseMessage = z.infer<typeof agentFunctionResponseMessageSchema>;
296
+ type AgentToRendererMessage = z.infer<typeof agentToRendererMessageSchema>;
297
+ type ActionMessage = z.infer<typeof actionMessageSchema>;
298
+ type CallAgentFunctionMessage = z.infer<typeof callAgentFunctionMessageSchema>;
299
+ type RendererFunctionResponseMessage = z.infer<typeof rendererFunctionResponseMessageSchema>;
300
+ type ValidationFailedErrorMessage = z.infer<typeof validationFailedErrorMessageSchema>;
301
+ type GenericErrorMessage = z.infer<typeof genericErrorMessageSchema>;
302
+ type RendererToAgentMessage = z.infer<typeof rendererToAgentMessageSchema>;
303
+ type RendererCapabilities = z.infer<typeof rendererCapabilitiesSchema>;
304
+ type AgentCapabilities = z.infer<typeof agentCapabilitiesSchema>;
305
+ type RendererDataModel = z.infer<typeof rendererDataModelSchema>;
306
+ interface SurfaceSnapshot {
307
+ surfaceId: string;
308
+ catalogId?: string;
309
+ metadata?: A2UIMessageMetadata;
310
+ sendDataModel: boolean;
311
+ source: string;
312
+ dataModel: JsonObject;
313
+ parseResult: ParseResult | null;
314
+ errors: OpenUIError[];
315
+ revision: number;
316
+ }
317
+ type A2UIRendererFunction = (args: JsonObject) => JsonValue | Promise<JsonValue>;
318
+ type A2UIFunctionAllowedCaller = "rendererOnly" | "agentOnly" | "rendererOrAgent";
319
+ interface A2UIRendererFunctionRegistration {
320
+ handler: A2UIRendererFunction;
321
+ /** Catalog that defines this function. Required when the agent may call it. */
322
+ catalogId?: string;
323
+ /** Matches A2UI catalog allowedCallers semantics. Defaults to rendererOnly. */
324
+ allowedCallers?: A2UIFunctionAllowedCaller;
325
+ }
326
+ interface A2UIClientOptions {
327
+ schema: LibraryJSONSchema;
328
+ rootName?: string;
329
+ functions?: Record<string, A2UIRendererFunction | A2UIRendererFunctionRegistration>;
330
+ rendererCapabilities?: RendererCapabilities;
331
+ onMessage?: (message: RendererToAgentMessage, metadata: RendererMetadata) => void;
332
+ now?: () => Date;
333
+ createId?: () => string;
334
+ }
335
+ interface ProtocolValidationIssue {
336
+ path: string;
337
+ message: string;
338
+ }
339
+ interface ProcessResult {
340
+ ok: boolean;
341
+ outbound: RendererToAgentMessage[];
342
+ /** Present when malformed input cannot be represented as an A2UI error envelope. */
343
+ issues?: ProtocolValidationIssue[];
344
+ }
345
+ interface DispatchActionInput {
346
+ surfaceId: string;
347
+ sourceComponentId: string;
348
+ name: string;
349
+ userMessage?: string;
350
+ context?: JsonObject;
351
+ metadata?: A2UIMessageMetadata;
352
+ }
353
+ interface CallAgentFunctionInput {
354
+ surfaceId: string;
355
+ call: string;
356
+ catalogId?: string;
357
+ args?: JsonObject;
358
+ }
359
+ interface OpenUIActionOptions {
360
+ name?: string;
361
+ /** A2UI component ID to report for the action. Defaults to root. */
362
+ sourceComponentId?: string;
363
+ userMessage?: string;
364
+ context?: JsonObject;
365
+ metadata?: A2UIMessageMetadata;
366
+ }
367
+ type MapOpenUIAction = (event: ActionEvent, surface: SurfaceSnapshot) => OpenUIActionOptions;
368
+ interface RendererMetadata {
369
+ a2uiRendererCapabilities?: RendererCapabilities;
370
+ a2uiRendererDataModel?: RendererDataModel;
371
+ }
372
+ //#endregion
373
+ //#region src/client.d.ts
374
+ type SurfaceListener = () => void;
375
+ type MessageListener = (message: RendererToAgentMessage, metadata: RendererMetadata) => void;
376
+ declare class A2UIFunctionError extends Error {
377
+ readonly code: string;
378
+ constructor(code: string, message: string);
379
+ }
380
+ declare class A2UIClient {
381
+ #private;
382
+ constructor(options: A2UIClientOptions);
383
+ subscribe(listener: SurfaceListener): () => void;
384
+ subscribeMessages(listener: MessageListener): () => void;
385
+ getSurface(surfaceId: string): SurfaceSnapshot | undefined;
386
+ getSurfaces(): SurfaceSnapshot[];
387
+ getRendererDataModel(): RendererDataModel | undefined;
388
+ getRendererMetadata(): RendererMetadata;
389
+ process(input: unknown): Promise<ProcessResult>;
390
+ updateSurfaceFromOpenUIState(surfaceId: string, state: Record<string, unknown>): boolean;
391
+ dispatchOpenUIAction(surfaceId: string, event: ActionEvent, options?: OpenUIActionOptions): void;
392
+ dispatchAction(input: DispatchActionInput): void;
393
+ callAgentFunction(input: CallAgentFunctionInput): Promise<JsonValue>;
394
+ dispose(): void;
395
+ }
396
+ declare function createA2UIClient(options: A2UIClientOptions): A2UIClient;
397
+ //#endregion
398
+ export { rendererDataModelSchema as $, RendererDataModel as A, actionMessageSchema as B, JsonPrimitive as C, ProcessResult as D, OpenUIActionOptions as E, UpdateComponentsMessage as F, callRendererFunctionMessageSchema as G, agentFunctionResponseMessageSchema as H, UpdateDataModelMessage as I, genericErrorMessageSchema as J, createSurfaceMessageSchema as K, ValidationFailedErrorMessage as L, RendererMetadata as M, RendererToAgentMessage as N, ProtocolValidationIssue as O, SurfaceSnapshot as P, rendererCapabilitiesSchema as Q, a2uiFunctionCallSchema as R, JsonObject as S, MapOpenUIAction as T, agentToRendererMessageSchema as U, agentCapabilitiesSchema as V, callAgentFunctionMessageSchema as W, jsonValueSchema as X, jsonObjectSchema as Y, messageMetadataSchema as Z, CallRendererFunctionMessage as _, A2UIFunctionAllowedCaller as a, DispatchActionInput as b, A2UIMessageMetadata as c, ActionMessage as d, rendererFunctionResponseMessageSchema as et, AgentCapabilities as f, CallAgentFunctionMessage as g, CallAgentFunctionInput as h, A2UIClientOptions as i, validationFailedErrorMessageSchema as it, RendererFunctionResponseMessage as j, RendererCapabilities as k, A2UIRendererFunction as l, AgentToRendererMessage as m, A2UIFunctionError as n, updateComponentsMessageSchema as nt, A2UIFunctionCall as o, AgentFunctionResponseMessage as p, deleteSurfaceMessageSchema as q, createA2UIClient as r, updateDataModelMessageSchema as rt, A2UIFunctionResponse as s, A2UIClient as t, rendererToAgentMessageSchema as tt, A2UIRendererFunctionRegistration as u, CreateSurfaceMessage as v, JsonValue as w, GenericErrorMessage as x, DeleteSurfaceMessage as y, a2uiFunctionResponseSchema as z };
399
+ //# sourceMappingURL=client-D0JsJgUP.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-D0JsJgUP.d.cts","names":[],"sources":["../src/protocol-schema.ts","../src/types.ts","../src/client.ts"],"mappings":";;;;cAEa,eAAA,EAAe,CAAA,CAAA,aAAA;AAAA,cACf,gBAAA,EAAgB,CAAA,CAAA,SAAA,CAAA,CAAA,CAAA,SAAA,EAAA,CAAA,CAAA,aAAA;AAAA,cAMhB,qBAAA,EAAqB,CAAA,CAAA,SAAA;;;cAQrB,sBAAA,EAAsB,CAAA,CAAA,SAAA;;;;;cAMtB,0BAAA,EAA0B,CAAA,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA;;;;;;;;;;cAQ1B,0BAAA,EAA0B,CAAA,CAAA,SAAA;;;;;;;;;;;;;cAc1B,6BAAA,EAA6B,CAAA,CAAA,SAAA;;;;;;;cAQ7B,4BAAA,EAA4B,CAAA,CAAA,SAAA;;;;;;;;cAS5B,0BAAA,EAA0B,CAAA,CAAA,SAAA;;;;;;cAK1B,iCAAA,EAAiC,CAAA,CAAA,SAAA;;;;;;;;;;;cAQjC,kCAAA,EAAkC,CAAA,CAAA,SAAA;;;;;;;;;;;;;cAKlC,4BAAA,EAA4B,CAAA,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAS5B,mBAAA,EAAmB,CAAA,CAAA,S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