@jini-ai/agentic 0.1.0 → 0.1.1

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 (53) hide show
  1. package/dist/a2ui/agent-to-renderer.d.ts +579 -0
  2. package/dist/a2ui/agent-to-renderer.d.ts.map +1 -0
  3. package/dist/a2ui/agent-to-renderer.js +169 -0
  4. package/dist/a2ui/agent-to-renderer.js.map +1 -0
  5. package/dist/a2ui/catalog.d.ts +73 -0
  6. package/dist/a2ui/catalog.d.ts.map +1 -0
  7. package/dist/a2ui/catalog.js +304 -0
  8. package/dist/a2ui/catalog.js.map +1 -0
  9. package/dist/a2ui/common-types.d.ts +401 -0
  10. package/dist/a2ui/common-types.d.ts.map +1 -0
  11. package/dist/a2ui/common-types.js +130 -0
  12. package/dist/a2ui/common-types.js.map +1 -0
  13. package/dist/a2ui/index.d.ts +16 -0
  14. package/dist/a2ui/index.d.ts.map +1 -0
  15. package/dist/a2ui/index.js +16 -0
  16. package/dist/a2ui/index.js.map +1 -0
  17. package/dist/a2ui/interpreter.d.ts +48 -0
  18. package/dist/a2ui/interpreter.d.ts.map +1 -0
  19. package/dist/a2ui/interpreter.js +287 -0
  20. package/dist/a2ui/interpreter.js.map +1 -0
  21. package/dist/a2ui/json-pointer.d.ts +48 -0
  22. package/dist/a2ui/json-pointer.d.ts.map +1 -0
  23. package/dist/a2ui/json-pointer.js +149 -0
  24. package/dist/a2ui/json-pointer.js.map +1 -0
  25. package/dist/a2ui/renderer-to-agent.d.ts +318 -0
  26. package/dist/a2ui/renderer-to-agent.d.ts.map +1 -0
  27. package/dist/a2ui/renderer-to-agent.js +98 -0
  28. package/dist/a2ui/renderer-to-agent.js.map +1 -0
  29. package/dist/a2ui/resolve.d.ts +28 -0
  30. package/dist/a2ui/resolve.d.ts.map +1 -0
  31. package/dist/a2ui/resolve.js +118 -0
  32. package/dist/a2ui/resolve.js.map +1 -0
  33. package/dist/a2ui/tree.d.ts +41 -0
  34. package/dist/a2ui/tree.d.ts.map +1 -0
  35. package/dist/a2ui/tree.js +35 -0
  36. package/dist/a2ui/tree.js.map +1 -0
  37. package/dist/dom/model-context.d.ts +15 -0
  38. package/dist/dom/model-context.d.ts.map +1 -1
  39. package/dist/dom/model-context.js +8 -0
  40. package/dist/dom/model-context.js.map +1 -1
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +2 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/mcp-ui-apps.d.ts +81 -10
  46. package/dist/mcp-ui-apps.d.ts.map +1 -1
  47. package/dist/mcp-ui-apps.js +84 -11
  48. package/dist/mcp-ui-apps.js.map +1 -1
  49. package/dist/webmcp.d.ts +126 -5
  50. package/dist/webmcp.d.ts.map +1 -1
  51. package/dist/webmcp.js +110 -4
  52. package/dist/webmcp.js.map +1 -1
  53. package/package.json +14 -5
@@ -0,0 +1,318 @@
1
+ /**
2
+ * @module renderer-to-agent
3
+ *
4
+ * A2UI v1.0 renderer→agent envelope — mirrors `specification/v1_0/json/renderer_to_agent.json`
5
+ * (fetched from https://github.com/a2ui-project/a2ui, `main` branch, this session). Three message
6
+ * kinds, each envelope carrying `version` plus **exactly one** of `action` | `functionResponse` |
7
+ * `error` (`minProperties: 2, maxProperties: 2` in the real schema — enforced below via `.refine`,
8
+ * since zod's object schema has no direct min/max-properties primitive).
9
+ */
10
+ import { z } from 'zod';
11
+ /** `renderer_to_agent.json#/properties/action` — "Reports a user-initiated action from a component." */
12
+ export declare const ActionMessagePayloadSchema: z.ZodObject<{
13
+ name: z.ZodString;
14
+ surfaceId: z.ZodString;
15
+ sourceComponentId: z.ZodString;
16
+ /** ISO 8601 timestamp — validated as a non-empty string, not parsed as a `Date`: the real schema only declares `format: "date-time"` (an annotation, not a structural constraint zod enforces by default). */
17
+ timestamp: z.ZodString;
18
+ context: z.ZodRecord<z.ZodString, z.ZodUnknown>;
19
+ wantResponse: z.ZodOptional<z.ZodBoolean>;
20
+ actionId: z.ZodOptional<z.ZodString>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ name: string;
23
+ surfaceId: string;
24
+ context: Record<string, unknown>;
25
+ sourceComponentId: string;
26
+ timestamp: string;
27
+ wantResponse?: boolean | undefined;
28
+ actionId?: string | undefined;
29
+ }, {
30
+ name: string;
31
+ surfaceId: string;
32
+ context: Record<string, unknown>;
33
+ sourceComponentId: string;
34
+ timestamp: string;
35
+ wantResponse?: boolean | undefined;
36
+ actionId?: string | undefined;
37
+ }>;
38
+ export type ActionMessagePayload = z.infer<typeof ActionMessagePayloadSchema>;
39
+ /** `renderer_to_agent.json#/properties/functionResponse`. */
40
+ export declare const FunctionResponsePayloadSchema: z.ZodObject<{
41
+ functionCallId: z.ZodString;
42
+ call: z.ZodString;
43
+ value: z.ZodUnknown;
44
+ }, "strip", z.ZodTypeAny, {
45
+ call: string;
46
+ functionCallId: string;
47
+ value?: unknown;
48
+ }, {
49
+ call: string;
50
+ functionCallId: string;
51
+ value?: unknown;
52
+ }>;
53
+ export type FunctionResponsePayload = z.infer<typeof FunctionResponsePayloadSchema>;
54
+ /**
55
+ * `renderer_to_agent.json#/properties/error` — two mutually-exclusive shapes: a `VALIDATION_FAILED`
56
+ * error (always carries `surfaceId` + a JSON-Pointer `path`), or a generic error (any other `code`,
57
+ * carrying exactly one of `surfaceId` XOR `functionCallId`).
58
+ */
59
+ export declare const ValidationFailedErrorSchema: z.ZodObject<{
60
+ code: z.ZodLiteral<"VALIDATION_FAILED">;
61
+ surfaceId: z.ZodString;
62
+ path: z.ZodString;
63
+ message: z.ZodString;
64
+ }, "strict", z.ZodTypeAny, {
65
+ surfaceId: string;
66
+ code: "VALIDATION_FAILED";
67
+ path: string;
68
+ message: string;
69
+ }, {
70
+ surfaceId: string;
71
+ code: "VALIDATION_FAILED";
72
+ path: string;
73
+ message: string;
74
+ }>;
75
+ export type ValidationFailedError = z.infer<typeof ValidationFailedErrorSchema>;
76
+ export declare const GenericErrorSchema: z.ZodEffects<z.ZodObject<{
77
+ code: z.ZodEffects<z.ZodString, string, string>;
78
+ message: z.ZodString;
79
+ surfaceId: z.ZodOptional<z.ZodString>;
80
+ functionCallId: z.ZodOptional<z.ZodString>;
81
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
82
+ code: z.ZodEffects<z.ZodString, string, string>;
83
+ message: z.ZodString;
84
+ surfaceId: z.ZodOptional<z.ZodString>;
85
+ functionCallId: z.ZodOptional<z.ZodString>;
86
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
87
+ code: z.ZodEffects<z.ZodString, string, string>;
88
+ message: z.ZodString;
89
+ surfaceId: z.ZodOptional<z.ZodString>;
90
+ functionCallId: z.ZodOptional<z.ZodString>;
91
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
92
+ code: z.ZodEffects<z.ZodString, string, string>;
93
+ message: z.ZodString;
94
+ surfaceId: z.ZodOptional<z.ZodString>;
95
+ functionCallId: z.ZodOptional<z.ZodString>;
96
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
97
+ code: z.ZodEffects<z.ZodString, string, string>;
98
+ message: z.ZodString;
99
+ surfaceId: z.ZodOptional<z.ZodString>;
100
+ functionCallId: z.ZodOptional<z.ZodString>;
101
+ }, z.ZodTypeAny, "passthrough">>;
102
+ export type GenericError = z.infer<typeof GenericErrorSchema>;
103
+ export declare const ErrorPayloadSchema: z.ZodUnion<[z.ZodObject<{
104
+ code: z.ZodLiteral<"VALIDATION_FAILED">;
105
+ surfaceId: z.ZodString;
106
+ path: z.ZodString;
107
+ message: z.ZodString;
108
+ }, "strict", z.ZodTypeAny, {
109
+ surfaceId: string;
110
+ code: "VALIDATION_FAILED";
111
+ path: string;
112
+ message: string;
113
+ }, {
114
+ surfaceId: string;
115
+ code: "VALIDATION_FAILED";
116
+ path: string;
117
+ message: string;
118
+ }>, z.ZodEffects<z.ZodObject<{
119
+ code: z.ZodEffects<z.ZodString, string, string>;
120
+ message: z.ZodString;
121
+ surfaceId: z.ZodOptional<z.ZodString>;
122
+ functionCallId: z.ZodOptional<z.ZodString>;
123
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
124
+ code: z.ZodEffects<z.ZodString, string, string>;
125
+ message: z.ZodString;
126
+ surfaceId: z.ZodOptional<z.ZodString>;
127
+ functionCallId: z.ZodOptional<z.ZodString>;
128
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
129
+ code: z.ZodEffects<z.ZodString, string, string>;
130
+ message: z.ZodString;
131
+ surfaceId: z.ZodOptional<z.ZodString>;
132
+ functionCallId: z.ZodOptional<z.ZodString>;
133
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
134
+ code: z.ZodEffects<z.ZodString, string, string>;
135
+ message: z.ZodString;
136
+ surfaceId: z.ZodOptional<z.ZodString>;
137
+ functionCallId: z.ZodOptional<z.ZodString>;
138
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
139
+ code: z.ZodEffects<z.ZodString, string, string>;
140
+ message: z.ZodString;
141
+ surfaceId: z.ZodOptional<z.ZodString>;
142
+ functionCallId: z.ZodOptional<z.ZodString>;
143
+ }, z.ZodTypeAny, "passthrough">>]>;
144
+ export type ErrorPayload = z.infer<typeof ErrorPayloadSchema>;
145
+ export declare const ActionMessageSchema: z.ZodObject<{
146
+ version: z.ZodLiteral<"v1.0">;
147
+ action: z.ZodObject<{
148
+ name: z.ZodString;
149
+ surfaceId: z.ZodString;
150
+ sourceComponentId: z.ZodString;
151
+ /** ISO 8601 timestamp — validated as a non-empty string, not parsed as a `Date`: the real schema only declares `format: "date-time"` (an annotation, not a structural constraint zod enforces by default). */
152
+ timestamp: z.ZodString;
153
+ context: z.ZodRecord<z.ZodString, z.ZodUnknown>;
154
+ wantResponse: z.ZodOptional<z.ZodBoolean>;
155
+ actionId: z.ZodOptional<z.ZodString>;
156
+ }, "strip", z.ZodTypeAny, {
157
+ name: string;
158
+ surfaceId: string;
159
+ context: Record<string, unknown>;
160
+ sourceComponentId: string;
161
+ timestamp: string;
162
+ wantResponse?: boolean | undefined;
163
+ actionId?: string | undefined;
164
+ }, {
165
+ name: string;
166
+ surfaceId: string;
167
+ context: Record<string, unknown>;
168
+ sourceComponentId: string;
169
+ timestamp: string;
170
+ wantResponse?: boolean | undefined;
171
+ actionId?: string | undefined;
172
+ }>;
173
+ }, "strict", z.ZodTypeAny, {
174
+ version: "v1.0";
175
+ action: {
176
+ name: string;
177
+ surfaceId: string;
178
+ context: Record<string, unknown>;
179
+ sourceComponentId: string;
180
+ timestamp: string;
181
+ wantResponse?: boolean | undefined;
182
+ actionId?: string | undefined;
183
+ };
184
+ }, {
185
+ version: "v1.0";
186
+ action: {
187
+ name: string;
188
+ surfaceId: string;
189
+ context: Record<string, unknown>;
190
+ sourceComponentId: string;
191
+ timestamp: string;
192
+ wantResponse?: boolean | undefined;
193
+ actionId?: string | undefined;
194
+ };
195
+ }>;
196
+ export type ActionMessage = z.infer<typeof ActionMessageSchema>;
197
+ export declare const FunctionResponseMessageSchema: z.ZodObject<{
198
+ version: z.ZodLiteral<"v1.0">;
199
+ functionResponse: z.ZodObject<{
200
+ functionCallId: z.ZodString;
201
+ call: z.ZodString;
202
+ value: z.ZodUnknown;
203
+ }, "strip", z.ZodTypeAny, {
204
+ call: string;
205
+ functionCallId: string;
206
+ value?: unknown;
207
+ }, {
208
+ call: string;
209
+ functionCallId: string;
210
+ value?: unknown;
211
+ }>;
212
+ }, "strict", z.ZodTypeAny, {
213
+ version: "v1.0";
214
+ functionResponse: {
215
+ call: string;
216
+ functionCallId: string;
217
+ value?: unknown;
218
+ };
219
+ }, {
220
+ version: "v1.0";
221
+ functionResponse: {
222
+ call: string;
223
+ functionCallId: string;
224
+ value?: unknown;
225
+ };
226
+ }>;
227
+ export type FunctionResponseMessage = z.infer<typeof FunctionResponseMessageSchema>;
228
+ export declare const ErrorMessageSchema: z.ZodObject<{
229
+ version: z.ZodLiteral<"v1.0">;
230
+ error: z.ZodUnion<[z.ZodObject<{
231
+ code: z.ZodLiteral<"VALIDATION_FAILED">;
232
+ surfaceId: z.ZodString;
233
+ path: z.ZodString;
234
+ message: z.ZodString;
235
+ }, "strict", z.ZodTypeAny, {
236
+ surfaceId: string;
237
+ code: "VALIDATION_FAILED";
238
+ path: string;
239
+ message: string;
240
+ }, {
241
+ surfaceId: string;
242
+ code: "VALIDATION_FAILED";
243
+ path: string;
244
+ message: string;
245
+ }>, z.ZodEffects<z.ZodObject<{
246
+ code: z.ZodEffects<z.ZodString, string, string>;
247
+ message: z.ZodString;
248
+ surfaceId: z.ZodOptional<z.ZodString>;
249
+ functionCallId: z.ZodOptional<z.ZodString>;
250
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
251
+ code: z.ZodEffects<z.ZodString, string, string>;
252
+ message: z.ZodString;
253
+ surfaceId: z.ZodOptional<z.ZodString>;
254
+ functionCallId: z.ZodOptional<z.ZodString>;
255
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
256
+ code: z.ZodEffects<z.ZodString, string, string>;
257
+ message: z.ZodString;
258
+ surfaceId: z.ZodOptional<z.ZodString>;
259
+ functionCallId: z.ZodOptional<z.ZodString>;
260
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
261
+ code: z.ZodEffects<z.ZodString, string, string>;
262
+ message: z.ZodString;
263
+ surfaceId: z.ZodOptional<z.ZodString>;
264
+ functionCallId: z.ZodOptional<z.ZodString>;
265
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
266
+ code: z.ZodEffects<z.ZodString, string, string>;
267
+ message: z.ZodString;
268
+ surfaceId: z.ZodOptional<z.ZodString>;
269
+ functionCallId: z.ZodOptional<z.ZodString>;
270
+ }, z.ZodTypeAny, "passthrough">>]>;
271
+ }, "strict", z.ZodTypeAny, {
272
+ error: {
273
+ surfaceId: string;
274
+ code: "VALIDATION_FAILED";
275
+ path: string;
276
+ message: string;
277
+ } | z.objectOutputType<{
278
+ code: z.ZodEffects<z.ZodString, string, string>;
279
+ message: z.ZodString;
280
+ surfaceId: z.ZodOptional<z.ZodString>;
281
+ functionCallId: z.ZodOptional<z.ZodString>;
282
+ }, z.ZodTypeAny, "passthrough">;
283
+ version: "v1.0";
284
+ }, {
285
+ error: {
286
+ surfaceId: string;
287
+ code: "VALIDATION_FAILED";
288
+ path: string;
289
+ message: string;
290
+ } | z.objectInputType<{
291
+ code: z.ZodEffects<z.ZodString, string, string>;
292
+ message: z.ZodString;
293
+ surfaceId: z.ZodOptional<z.ZodString>;
294
+ functionCallId: z.ZodOptional<z.ZodString>;
295
+ }, z.ZodTypeAny, "passthrough">;
296
+ version: "v1.0";
297
+ }>;
298
+ export type ErrorMessage = z.infer<typeof ErrorMessageSchema>;
299
+ export type RendererToAgentMessage = ActionMessage | FunctionResponseMessage | ErrorMessage;
300
+ export declare function buildActionMessage(payload: ActionMessagePayload): ActionMessage;
301
+ export declare function buildFunctionResponseMessage(payload: FunctionResponsePayload): FunctionResponseMessage;
302
+ export declare function buildValidationFailedMessage(surfaceId: string, path: string, message: string): ErrorMessage;
303
+ export declare function buildGenericErrorMessage(code: string, message: string, target: {
304
+ surfaceId: string;
305
+ } | {
306
+ functionCallId: string;
307
+ }): ErrorMessage;
308
+ export interface RendererParseFailure {
309
+ readonly ok: false;
310
+ readonly reason: string;
311
+ }
312
+ export interface RendererParseSuccess {
313
+ readonly ok: true;
314
+ readonly message: RendererToAgentMessage;
315
+ }
316
+ /** Same "inspect the shape, validate the one matching branch" dispatcher as `parseAgentToRendererMessage` — see that function's doc for why this beats a plain `z.union`. Used by tests and by anything on the agent side of this fixture that needs to validate what the browser sent. */
317
+ export declare function parseRendererToAgentMessage(raw: unknown): RendererParseSuccess | RendererParseFailure;
318
+ //# sourceMappingURL=renderer-to-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer-to-agent.d.ts","sourceRoot":"","sources":["../../src/a2ui/renderer-to-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEpB,CAAC;AACZ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG,uBAAuB,GAAG,YAAY,CAAC;AAE5F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAE/E;AACD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,uBAAuB,GAAG,uBAAuB,CAEtG;AACD,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAE3G;AACD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,GACzD,YAAY,CAEd;AAID,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AACD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;CAC1C;AAED,2RAA2R;AAC3R,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,GAAG,oBAAoB,GAAG,oBAAoB,CAqBrG"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @module renderer-to-agent
3
+ *
4
+ * A2UI v1.0 renderer→agent envelope — mirrors `specification/v1_0/json/renderer_to_agent.json`
5
+ * (fetched from https://github.com/a2ui-project/a2ui, `main` branch, this session). Three message
6
+ * kinds, each envelope carrying `version` plus **exactly one** of `action` | `functionResponse` |
7
+ * `error` (`minProperties: 2, maxProperties: 2` in the real schema — enforced below via `.refine`,
8
+ * since zod's object schema has no direct min/max-properties primitive).
9
+ */
10
+ import { z } from 'zod';
11
+ import { CallIdSchema } from './common-types.js';
12
+ const PROTOCOL_VERSION = 'v1.0';
13
+ /** `renderer_to_agent.json#/properties/action` — "Reports a user-initiated action from a component." */
14
+ export const ActionMessagePayloadSchema = z.object({
15
+ name: z.string(),
16
+ surfaceId: z.string(),
17
+ sourceComponentId: z.string(),
18
+ /** ISO 8601 timestamp — validated as a non-empty string, not parsed as a `Date`: the real schema only declares `format: "date-time"` (an annotation, not a structural constraint zod enforces by default). */
19
+ timestamp: z.string(),
20
+ context: z.record(z.string(), z.unknown()),
21
+ wantResponse: z.boolean().optional(),
22
+ actionId: z.string().optional(),
23
+ });
24
+ /** `renderer_to_agent.json#/properties/functionResponse`. */
25
+ export const FunctionResponsePayloadSchema = z.object({
26
+ functionCallId: CallIdSchema,
27
+ call: z.string(),
28
+ value: z.unknown(),
29
+ });
30
+ /**
31
+ * `renderer_to_agent.json#/properties/error` — two mutually-exclusive shapes: a `VALIDATION_FAILED`
32
+ * error (always carries `surfaceId` + a JSON-Pointer `path`), or a generic error (any other `code`,
33
+ * carrying exactly one of `surfaceId` XOR `functionCallId`).
34
+ */
35
+ export const ValidationFailedErrorSchema = z
36
+ .object({
37
+ code: z.literal('VALIDATION_FAILED'),
38
+ surfaceId: z.string(),
39
+ path: z.string(),
40
+ message: z.string(),
41
+ })
42
+ .strict();
43
+ export const GenericErrorSchema = z
44
+ .object({
45
+ code: z.string().refine((c) => c !== 'VALIDATION_FAILED', 'code must not be VALIDATION_FAILED here'),
46
+ message: z.string(),
47
+ surfaceId: z.string().optional(),
48
+ functionCallId: CallIdSchema.optional(),
49
+ })
50
+ .passthrough()
51
+ .refine((v) => ('surfaceId' in v) !== ('functionCallId' in v), 'exactly one of surfaceId/functionCallId is required');
52
+ export const ErrorPayloadSchema = z.union([ValidationFailedErrorSchema, GenericErrorSchema]);
53
+ export const ActionMessageSchema = z
54
+ .object({ version: z.literal(PROTOCOL_VERSION), action: ActionMessagePayloadSchema })
55
+ .strict();
56
+ export const FunctionResponseMessageSchema = z
57
+ .object({ version: z.literal(PROTOCOL_VERSION), functionResponse: FunctionResponsePayloadSchema })
58
+ .strict();
59
+ export const ErrorMessageSchema = z
60
+ .object({ version: z.literal(PROTOCOL_VERSION), error: ErrorPayloadSchema })
61
+ .strict();
62
+ export function buildActionMessage(payload) {
63
+ return { version: PROTOCOL_VERSION, action: payload };
64
+ }
65
+ export function buildFunctionResponseMessage(payload) {
66
+ return { version: PROTOCOL_VERSION, functionResponse: payload };
67
+ }
68
+ export function buildValidationFailedMessage(surfaceId, path, message) {
69
+ return { version: PROTOCOL_VERSION, error: { code: 'VALIDATION_FAILED', surfaceId, path, message } };
70
+ }
71
+ export function buildGenericErrorMessage(code, message, target) {
72
+ return { version: PROTOCOL_VERSION, error: { code, message, ...target } };
73
+ }
74
+ const MESSAGE_KEYS = ['action', 'functionResponse', 'error'];
75
+ /** Same "inspect the shape, validate the one matching branch" dispatcher as `parseAgentToRendererMessage` — see that function's doc for why this beats a plain `z.union`. Used by tests and by anything on the agent side of this fixture that needs to validate what the browser sent. */
76
+ export function parseRendererToAgentMessage(raw) {
77
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
78
+ return { ok: false, reason: 'envelope must be a JSON object' };
79
+ }
80
+ const obj = raw;
81
+ if (obj.version !== PROTOCOL_VERSION) {
82
+ return { ok: false, reason: `envelope declares version ${JSON.stringify(obj.version)}, expected "${PROTOCOL_VERSION}"` };
83
+ }
84
+ const presentKeys = MESSAGE_KEYS.filter((key) => key in obj);
85
+ if (presentKeys.length !== 1) {
86
+ return { ok: false, reason: `expected exactly one of ${MESSAGE_KEYS.join(', ')}, found ${presentKeys.length}` };
87
+ }
88
+ const key = presentKeys[0];
89
+ const schema = key === 'action' ? ActionMessageSchema : key === 'functionResponse' ? FunctionResponseMessageSchema : ErrorMessageSchema;
90
+ const result = schema.safeParse(obj);
91
+ if (!result.success) {
92
+ // Same zod guarantee as `parseAgentToRendererMessage` relies on: `success: false` implies a
93
+ // non-empty `issues` array — see that function's comment for why this is asserted, not branched.
94
+ return { ok: false, reason: result.error.issues[0].message };
95
+ }
96
+ return { ok: true, message: result.data };
97
+ }
98
+ //# sourceMappingURL=renderer-to-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer-to-agent.js","sourceRoot":"","sources":["../../src/a2ui/renderer-to-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,gBAAgB,GAAG,MAAe,CAAC;AAEzC,wGAAwG;AACxG,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE;IAC7B,8MAA8M;IAC9M,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;IAC1C,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACpC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAGH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IACpD,cAAc,EAAE,YAAY;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE;CACnB,CAAC,CAAC;AAGH;;;;GAIG;AACH,MAAM,CAAC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a `ChildList` template (`common_types.json`'s "Collection Scope"): relative (no leading `/`) `DataBinding` paths resolve under `${basePath}/${index}/...` instead of the data-model root. */
4
+ export interface ItemScope {
5
+ readonly basePath: string;
6
+ readonly index: number;
7
+ }
8
+ export interface ResolveContext {
9
+ readonly dataModel: unknown;
10
+ readonly catalog: Catalog;
11
+ /** Which side is *evaluating* this binding — the renderer resolving a component's own props (`'renderer'`), or something acting on the agent's behalf. A2UI's spec doesn't explicitly name a case where the agent-side evaluates a `Dynamic*` binding (that's a renderer-only concept — the agent only ever sends `callFunction` for direct RPC), but `callableFromOf` is checked against this side regardless, so a future agent-side evaluator (e.g. resolving `action.event.context` bindings before dispatch — which today happens on the renderer, see `interpreter.ts`'s `buildAction`) is covered by the same boundary without a second resolver. */
12
+ readonly side: ResolveSide;
13
+ readonly itemScope?: ItemScope;
14
+ }
15
+ export type ResolveFailureReason = 'PATH_NOT_FOUND' | 'FUNCTION_NOT_REGISTERED' | 'FUNCTION_NOT_CALLABLE_FROM_SIDE' | 'FUNCTION_NOT_IMPLEMENTED' | 'INDEX_OUTSIDE_LIST_CONTEXT' | 'RELATIVE_PATH_OUTSIDE_LIST_CONTEXT';
16
+ export interface ResolveFailure {
17
+ readonly ok: false;
18
+ readonly reason: ResolveFailureReason;
19
+ readonly detail: string;
20
+ }
21
+ export interface ResolveOk {
22
+ readonly ok: true;
23
+ readonly value: unknown;
24
+ }
25
+ export type ResolveResult = ResolveOk | ResolveFailure;
26
+ /** Resolves any `Dynamic*` value (`DynamicString`/`DynamicNumber`/`DynamicBoolean`/`DynamicStringList`/`DynamicValue` all share this one shape: literal | `DataBinding` | `FunctionCall`). */
27
+ export declare function resolveDynamicValue(value: unknown, ctx: ResolveContext): ResolveResult;
28
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/a2ui/resolve.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAE/C,gOAAgO;AAChO,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,4nBAA4nB;IAC5nB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;CAChC;AAED,MAAM,MAAM,oBAAoB,GAC5B,gBAAgB,GAChB,yBAAyB,GACzB,iCAAiC,GACjC,0BAA0B,GAC1B,4BAA4B,GAC5B,oCAAoC,CAAC;AAEzC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AACD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AACD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,cAAc,CAAC;AAgGvD,8LAA8L;AAC9L,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,aAAa,CAItF"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @module resolve
3
+ *
4
+ * Resolves A2UI's `Dynamic*` binding types (literal | `DataBinding` | `FunctionCall`) against a
5
+ * surface's data model. This is the piece the task brief called out as GenUI/AG-UI having no
6
+ * equivalent of: AG-UI's `state_update` event is "some path changed, some value" with no binding
7
+ * *resolution* step — A2UI's `Dynamic*` types are unresolved references a renderer must actively
8
+ * walk the data model to answer.
9
+ *
10
+ * **Never throws.** Every failure mode (a path that doesn't resolve, a function that isn't
11
+ * registered, a function that crosses a `callableFrom` boundary it isn't allowed to cross, `@index`
12
+ * used outside a list-template context) returns a tagged `ResolveFailure` instead — this is the
13
+ * direct answer to this task's adversarial question "a binding whose path doesn't resolve — does
14
+ * it crash or degrade sanely?": it degrades sanely, always, by construction (no code path in this
15
+ * module can throw on bad *input data*; only a genuine programming error, e.g. calling this module
16
+ * incorrectly, would).
17
+ */
18
+ import { getAtPointer, joinPointer, parsePointerTokens } from './json-pointer.js';
19
+ import { callableFromOf, isFunctionRegistered } from './catalog.js';
20
+ function isDataBinding(value) {
21
+ return typeof value === 'object' && value !== null && !Array.isArray(value) && 'path' in value && Object.keys(value).length === 1;
22
+ }
23
+ function isFunctionCall(value) {
24
+ return typeof value === 'object' && value !== null && !Array.isArray(value) && 'call' in value && typeof value.call === 'string';
25
+ }
26
+ function resolveBindingPath(path, ctx) {
27
+ // A relative path is still RFC 6901 syntax, so its `~0`/`~1` escapes must be decoded into real
28
+ // token text before `joinPointer` re-escapes them. Splitting the raw string on `/` instead would
29
+ // hand `joinPointer` already-escaped text and double-escape it, making a relative `a~1b` resolve
30
+ // the literal key `a~1b` while the equivalent absolute pointer correctly resolves `a/b`.
31
+ const absolute = path.startsWith('/')
32
+ ? path
33
+ : ctx.itemScope
34
+ ? joinPointer(ctx.itemScope.basePath, String(ctx.itemScope.index), ...parsePointerTokens(`/${path}`))
35
+ : null;
36
+ if (absolute === null) {
37
+ return { ok: false, reason: 'RELATIVE_PATH_OUTSIDE_LIST_CONTEXT', detail: `relative path "${path}" used outside a list-template item context` };
38
+ }
39
+ const result = getAtPointer(ctx.dataModel, absolute);
40
+ if (!result.found) {
41
+ return { ok: false, reason: 'PATH_NOT_FOUND', detail: `no value at "${absolute}" in the current data model` };
42
+ }
43
+ return { ok: true, value: result.value };
44
+ }
45
+ function resolveFunctionCall(call, ctx) {
46
+ if (call.call === '@index') {
47
+ if (!ctx.itemScope) {
48
+ return { ok: false, reason: 'INDEX_OUTSIDE_LIST_CONTEXT', detail: '@index used outside a list-template item context' };
49
+ }
50
+ const offsetArg = call.args?.offset;
51
+ const offsetResult = offsetArg === undefined ? { ok: true, value: 0 } : resolveDynamicValue(offsetArg, ctx);
52
+ if (!offsetResult.ok)
53
+ return offsetResult;
54
+ const offset = typeof offsetResult.value === 'number' ? offsetResult.value : 0;
55
+ return { ok: true, value: ctx.itemScope.index + offset };
56
+ }
57
+ if (!isFunctionRegistered(ctx.catalog, call.call)) {
58
+ return { ok: false, reason: 'FUNCTION_NOT_REGISTERED', detail: `function "${call.call}" is not registered in catalog "${ctx.catalog.catalogId}"` };
59
+ }
60
+ const callableFrom = callableFromOf(ctx.catalog, call.call);
61
+ const allowed = callableFrom === 'rendererOrAgent' || (callableFrom === 'rendererOnly' && ctx.side === 'renderer') || (callableFrom === 'agentOnly' && ctx.side === 'agent');
62
+ if (!allowed) {
63
+ return {
64
+ ok: false,
65
+ reason: 'FUNCTION_NOT_CALLABLE_FROM_SIDE',
66
+ detail: `function "${call.call}" has callableFrom="${callableFrom}", not callable from the "${ctx.side}" side`,
67
+ };
68
+ }
69
+ const spec = ctx.catalog.functions.get(call.call);
70
+ if (!spec?.impl) {
71
+ return { ok: false, reason: 'FUNCTION_NOT_IMPLEMENTED', detail: `function "${call.call}" is registered but this renderer has no implementation for it` };
72
+ }
73
+ const resolvedArgs = {};
74
+ for (const [key, argValue] of Object.entries(call.args ?? {})) {
75
+ const argResult = resolveArgValue(argValue, ctx);
76
+ if (!argResult.ok)
77
+ return argResult;
78
+ resolvedArgs[key] = argResult.value;
79
+ }
80
+ return { ok: true, value: spec.impl(resolvedArgs) };
81
+ }
82
+ /**
83
+ * Resolves one `FunctionCall` arg value, recursing into arrays element-by-element. Real
84
+ * basic-catalog functions commonly type an arg as an *array* of `Dynamic*` values (e.g. `and`/`or`'s
85
+ * `values: DynamicBoolean[]`, confirmed against `specification/v1_0/catalogs/basic/catalog.json`'s
86
+ * own function definitions and the spec repo's `button_checks.json` conformance fixture, both
87
+ * fetched this session) — `common_types.json`'s generic `DynamicValue` schema's own `array` branch
88
+ * has no `items` sub-schema (it does not itself promise recursive binding resolution), so this
89
+ * per-element recursion is a deliberate generalization by this port, not a literal requirement of
90
+ * that one generic type — done because without it, an array-of-`DynamicBoolean` arg's own nested
91
+ * `DataBinding`/`FunctionCall` entries would pass through unresolved (as raw, non-boolean objects)
92
+ * to a function's `impl`, silently producing wrong results instead of a clean failure or a correct
93
+ * answer. `resolveDynamicValue` itself is left alone (a literal-array `DynamicValue` at the top
94
+ * level — e.g. a `DynamicStringList`'s literal-array branch — still passes through as-is, matching
95
+ * the generic type's own contract); only this arg-resolution path recurses.
96
+ */
97
+ function resolveArgValue(argValue, ctx) {
98
+ if (Array.isArray(argValue)) {
99
+ const resolvedItems = [];
100
+ for (const item of argValue) {
101
+ const itemResult = resolveArgValue(item, ctx);
102
+ if (!itemResult.ok)
103
+ return itemResult;
104
+ resolvedItems.push(itemResult.value);
105
+ }
106
+ return { ok: true, value: resolvedItems };
107
+ }
108
+ return resolveDynamicValue(argValue, ctx);
109
+ }
110
+ /** Resolves any `Dynamic*` value (`DynamicString`/`DynamicNumber`/`DynamicBoolean`/`DynamicStringList`/`DynamicValue` all share this one shape: literal | `DataBinding` | `FunctionCall`). */
111
+ export function resolveDynamicValue(value, ctx) {
112
+ if (isDataBinding(value))
113
+ return resolveBindingPath(value.path, ctx);
114
+ if (isFunctionCall(value))
115
+ return resolveFunctionCall(value, ctx);
116
+ return { ok: true, value };
117
+ }
118
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/a2ui/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEl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C;IACtC,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,eAAe,CAAC,QAAiB,EAAE,GAAmB;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,aAAa,GAAc,EAAE,CAAC;QACpC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC9C,IAAI,CAAC,UAAU,CAAC,EAAE;gBAAE,OAAO,UAAU,CAAC;YACtC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,mBAAmB,CAAC,QAAwB,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED,8LAA8L;AAC9L,MAAM,UAAU,mBAAmB,CAAC,KAAc,EAAE,GAAmB;IACrE,IAAI,aAAa,CAAC,KAAK,CAAC;QAAE,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACrE,IAAI,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @module tree
3
+ *
4
+ * Flattens the component adjacency list (`id -> ComponentInstance`, each instance's `children`
5
+ * being an array of other ids) into an ordered, depth-first render list — the two adversarial
6
+ * cases this exists to answer sanely: **a child id that doesn't exist** in the map, and **a
7
+ * circular reference** (A -> B -> A). Neither may crash or infinite-loop a renderer; both must
8
+ * degrade to a visible, inert placeholder node instead.
9
+ *
10
+ * Scope: only the *static array* form of `ChildList` (`common_types.json#/$defs/ChildList`'s
11
+ * first `oneOf` branch) is walked here. The *template* form (`{componentId, path}`, generating N
12
+ * children from a data-model list) is accepted by the wire schema (`ChildListSchema`) but not
13
+ * expanded by this port — see `../source-map.md` for why (a distinct, substantially larger
14
+ * rendering feature: item-scoped relative-path resolution, `@index`, per-item React keys for one
15
+ * shared component definition rendered N times). A `getChildIds` callback that always returns
16
+ * `[]` for a template-shaped `children` value is a safe, honest way to consume this module without
17
+ * pretending template lists render.
18
+ */
19
+ export interface ComponentLike {
20
+ readonly id: string;
21
+ }
22
+ export type RenderNodeStatus = 'ok' | 'missing' | 'cycle';
23
+ export interface RenderNode {
24
+ readonly id: string;
25
+ readonly depth: number;
26
+ readonly status: RenderNodeStatus;
27
+ }
28
+ /**
29
+ * @param components The full component map (id -> instance).
30
+ * @param rootId The id to start walking from (typically `'root'`, but not assumed — a surface
31
+ * with no `root` component yet is the caller's concern, not this function's; see
32
+ * `interpreter.ts`'s `getRoot()`).
33
+ * @param getChildIds Given a present component, returns its child ids in render order (`[]` for
34
+ * a leaf, or a template-shaped `ChildList` this port doesn't expand — see module doc).
35
+ * @returns A depth-first, pre-order flattening. A `missing` node is a leaf in the output (its own
36
+ * children are never visited — there is nothing to look up). A `cycle` node is also a leaf: the
37
+ * id is emitted once more so a renderer can show *where* the cycle closes, but its children are
38
+ * not walked again (that walk already happened higher up the same path).
39
+ */
40
+ export declare function flattenRenderTree<C extends ComponentLike>(components: ReadonlyMap<string, C>, rootId: string, getChildIds: (component: C) => readonly string[]): RenderNode[];
41
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../src/a2ui/tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,aAAa,EACvD,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAClC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,SAAS,MAAM,EAAE,GAC/C,UAAU,EAAE,CAuBd"}