@copilotkit/shared 2.0.0-rc.15 → 2.0.0-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2ui-envelope.cjs +2 -2
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +2 -2
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/generative-ui/prompt-spec.cjs +11 -11
- package/dist/generative-ui/prompt-spec.cjs.map +1 -1
- package/dist/generative-ui/prompt-spec.mjs +11 -11
- package/dist/generative-ui/prompt-spec.mjs.map +1 -1
- package/dist/generative-ui/prompt.cjs +1 -1
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.mjs +1 -1
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +7 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +7 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/index.umd.js +17 -17
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
- package/src/__tests__/a2ui-envelope.test.ts +18 -13
- package/src/__tests__/a2ui-prompts.test.ts +5 -5
- package/src/__tests__/fixtures/prompt-goldens.json +64 -64
- package/src/a2ui-envelope.ts +5 -5
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- package/src/generative-ui/prompt-spec.ts +11 -11
- package/src/generative-ui/prompt.ts +1 -1
- package/src/generative-ui/types.ts +10 -7
- package/src/telemetry/model-host.test.ts +2 -5
|
@@ -62,19 +62,19 @@ const functions = {
|
|
|
62
62
|
const knownSurfaces = new Set(["s1"]);
|
|
63
63
|
|
|
64
64
|
const update = (...components: unknown[]) => ({
|
|
65
|
-
version: "
|
|
65
|
+
version: "1.0",
|
|
66
66
|
updateComponents: { surfaceId: "s1", components },
|
|
67
67
|
});
|
|
68
68
|
const setData = (fields: { path?: string; value?: unknown }) => ({
|
|
69
|
-
version: "
|
|
69
|
+
version: "1.0",
|
|
70
70
|
updateDataModel: { surfaceId: "s1", ...fields },
|
|
71
71
|
});
|
|
72
72
|
const create = (fields: Record<string, unknown>) => ({
|
|
73
|
-
version: "
|
|
73
|
+
version: "1.0",
|
|
74
74
|
createSurface: { surfaceId: "s2", ...fields },
|
|
75
75
|
});
|
|
76
76
|
const callFunction = (fields: Record<string, unknown>) => ({
|
|
77
|
-
version: "
|
|
77
|
+
version: "1.0",
|
|
78
78
|
callRendererFunction: { functionCallId: "f1", ...fields },
|
|
79
79
|
});
|
|
80
80
|
/** A valid ProductCard with `props` added or replaced. */
|
|
@@ -90,23 +90,29 @@ const reasonOf = (
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
describe("validateOperation: version and kind", () => {
|
|
93
|
-
it("rejects
|
|
93
|
+
it("rejects the pre-release v1.0 spelling", () => {
|
|
94
|
+
expect(
|
|
95
|
+
reasonOf({ version: "v1.0", deleteSurface: { surfaceId: "s1" } }),
|
|
96
|
+
).toBe('unsupported version "v1.0"; use "1.0"');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("rejects a v0.9 operation with a reason that names 1.0", () => {
|
|
94
100
|
expect(
|
|
95
101
|
reasonOf({ version: "v0.9", deleteSurface: { surfaceId: "s1" } }),
|
|
96
|
-
).toBe('unsupported version "v0.9"; use "
|
|
102
|
+
).toBe('unsupported version "v0.9"; use "1.0"');
|
|
97
103
|
});
|
|
98
104
|
|
|
99
105
|
it("rejects an operation without a version", () => {
|
|
100
106
|
expect(reasonOf({ deleteSurface: { surfaceId: "s1" } })).toBe(
|
|
101
|
-
'operation needs "version":"
|
|
107
|
+
'operation needs "version":"1.0"',
|
|
102
108
|
);
|
|
103
109
|
});
|
|
104
110
|
|
|
105
111
|
it("rejects ops with zero or several kinds", () => {
|
|
106
|
-
expect(reasonOf({ version: "
|
|
112
|
+
expect(reasonOf({ version: "1.0" })).toMatch(/exactly one/);
|
|
107
113
|
expect(
|
|
108
114
|
reasonOf({
|
|
109
|
-
version: "
|
|
115
|
+
version: "1.0",
|
|
110
116
|
deleteSurface: { surfaceId: "s1" },
|
|
111
117
|
updateDataModel: { surfaceId: "s1", value: 1 },
|
|
112
118
|
}),
|
|
@@ -133,7 +139,7 @@ describe("validateOperation: createSurface", () => {
|
|
|
133
139
|
};
|
|
134
140
|
const check = (catalogId: string) =>
|
|
135
141
|
validateOperation(
|
|
136
|
-
{ version: "
|
|
142
|
+
{ version: "1.0", createSurface: { surfaceId: "s2", catalogId } },
|
|
137
143
|
options,
|
|
138
144
|
);
|
|
139
145
|
expect(check("copilotkit/standard@1")).toEqual({ ok: true });
|
|
@@ -146,13 +152,13 @@ describe("validateOperation: createSurface", () => {
|
|
|
146
152
|
|
|
147
153
|
it("rejects a createSurface without a surfaceId", () => {
|
|
148
154
|
expect(
|
|
149
|
-
reasonOf({ version: "
|
|
155
|
+
reasonOf({ version: "1.0", createSurface: { catalogId: "shop" } }),
|
|
150
156
|
).toBe("createSurface.surfaceId is required");
|
|
151
157
|
});
|
|
152
158
|
|
|
153
159
|
it("rejects an existing surface", () => {
|
|
154
160
|
expect(
|
|
155
|
-
reasonOf({ version: "
|
|
161
|
+
reasonOf({ version: "1.0", createSurface: { surfaceId: "s1" } }),
|
|
156
162
|
).toBe('surface "s1" already exists');
|
|
157
163
|
});
|
|
158
164
|
|
|
@@ -201,7 +207,7 @@ describe("validateOperation: surface updates", () => {
|
|
|
201
207
|
it("rejects updates to surfaces that do not exist", () => {
|
|
202
208
|
expect(
|
|
203
209
|
reasonOf({
|
|
204
|
-
version: "
|
|
210
|
+
version: "1.0",
|
|
205
211
|
updateComponents: {
|
|
206
212
|
surfaceId: "missing",
|
|
207
213
|
components: [{ id: "root", component: "ProductGrid" }],
|
|
@@ -134,8 +134,8 @@ export function defaultGenerativeUIPromptSpec(): GenerativeUIPromptSpec {
|
|
|
134
134
|
"Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target limits its components, its surfaces can use only those components.",
|
|
135
135
|
"Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
|
|
136
136
|
"Keep each operation whole on its line.",
|
|
137
|
-
'Give every operation "version":"
|
|
138
|
-
'Start a surface with one createSurface. Put all the initial data in "dataModel" and the "root" component in "components". Then write the children in updateComponents lines, so that they show while you write:\n ```a2ui\n {"version":"
|
|
137
|
+
'Give every operation "version":"1.0".',
|
|
138
|
+
'Start a surface with one createSurface. Put all the initial data in "dataModel" and the "root" component in "components". Then write the children in updateComponents lines, so that they show while you write:\n ```a2ui\n {"version":"1.0","createSurface":{"surfaceId":"plan-picker","dataModel":{ ...initial data... },"components":[{"id":"root","component":"<Name>","children":["seats","pick"]}]}}\n {"version":"1.0","updateComponents":{"surfaceId":"plan-picker","components":[ ...the children... ]}}\n ```',
|
|
139
139
|
'Keep "dataModel" flat: top-level keys such as "seats" or "form", never one wrapper object around everything. Check that every { and [ you open in a line is closed.',
|
|
140
140
|
'Every surface renders from the component with id "root". Make every other component reachable from "root" through slots.',
|
|
141
141
|
"Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.",
|
|
@@ -156,7 +156,7 @@ export function defaultGenerativeUIPromptSpec(): GenerativeUIPromptSpec {
|
|
|
156
156
|
'For a computed list (chart data, template items) use series. Its description under Functions in the schema gives the rules and an example. Bind the "data" of a Chart or the "items" of a List to it; a template path stays a literal path.',
|
|
157
157
|
'Bind a writable prop to let the user edit it: "value":{"@path":"/form/email"}. The user\'s input goes to that path.',
|
|
158
158
|
'The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use "yes" and "no", not true and false.',
|
|
159
|
-
'To change data, write updateDataModel with a "path" and a "value": {"version":"
|
|
159
|
+
'To change data, write updateDataModel with a "path" and a "value": {"version":"1.0","updateDataModel":{"surfaceId":"plan-picker","path":"/seats","value":12}}. Always give "value".',
|
|
160
160
|
'Set "value":null to delete the key at "path".',
|
|
161
161
|
{
|
|
162
162
|
when: ["events"],
|
|
@@ -206,9 +206,9 @@ export function defaultGenerativeUIPromptSpec(): GenerativeUIPromptSpec {
|
|
|
206
206
|
{
|
|
207
207
|
when: ["agentCalls"],
|
|
208
208
|
items: [
|
|
209
|
-
'To run an app function now, with no click, write a callRendererFunction line in a fence: {"version":"
|
|
209
|
+
'To run an app function now, with no click, write a callRendererFunction line in a fence: {"version":"1.0","callRendererFunction":{"functionCallId":"<unique id>","callFunction":{"@call":"<function>","args":{...}}}}. It needs no surface.',
|
|
210
210
|
"Give every callRendererFunction a new functionCallId. Call only a function that the schema marks UI or agent, or agent only; a function with no mark is for the UI only. A function marked agent only is only for callRendererFunction: do not bind an event to it.",
|
|
211
|
-
'The result of a callRendererFunction comes back to you as a developer message: {"version":"
|
|
211
|
+
'The result of a callRendererFunction comes back to you as a developer message: {"version":"1.0","rendererFunctionResponse":{"functionCallId":"<id>","value":...}}. If the call failed, it has "error" in place of "value". Then you get a new turn.',
|
|
212
212
|
"Do not guess the result of a callRendererFunction. Wait for the developer message.",
|
|
213
213
|
],
|
|
214
214
|
},
|
|
@@ -223,14 +223,14 @@ export function defaultGenerativeUIPromptSpec(): GenerativeUIPromptSpec {
|
|
|
223
223
|
intro: `Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).`,
|
|
224
224
|
whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,
|
|
225
225
|
operations: [
|
|
226
|
-
'{"version":"
|
|
227
|
-
'{"version":"
|
|
228
|
-
'{"version":"
|
|
229
|
-
'{"version":"
|
|
226
|
+
'{"version":"1.0","createSurface":{"surfaceId":"<new id>","dataModel":{...},"components":[{"id":"root","component":"<Name>","children":["<child id>"]}]}}: the first operation of a new surface. "dataModel" and "components" are optional.',
|
|
227
|
+
'{"version":"1.0","updateComponents":{"surfaceId":"<id>","components":[<component>, ...]}}: add or replace components by id.',
|
|
228
|
+
'{"version":"1.0","updateDataModel":{"surfaceId":"<id>","path":"/some/path","value":<json>}}: set the value at "path". Always give "value". "value":null deletes the key at "path".',
|
|
229
|
+
'{"version":"1.0","deleteSurface":{"surfaceId":"<id>"}}: remove the surface.',
|
|
230
230
|
{
|
|
231
231
|
when: ["agentCalls"],
|
|
232
232
|
items: [
|
|
233
|
-
'{"version":"
|
|
233
|
+
'{"version":"1.0","callRendererFunction":{"functionCallId":"<unique id>","callFunction":{"@call":"<function>","args":{...}}}}: run an app function now, with no click. It needs no surface.',
|
|
234
234
|
],
|
|
235
235
|
},
|
|
236
236
|
],
|
|
@@ -273,7 +273,7 @@ export function defaultGenerativeUIPromptSpec(): GenerativeUIPromptSpec {
|
|
|
273
273
|
when: ["agentCalls"],
|
|
274
274
|
items: [
|
|
275
275
|
"Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.",
|
|
276
|
-
'The result of a callRendererFunction comes back to you in a new turn, as a developer message: {"version":"
|
|
276
|
+
'The result of a callRendererFunction comes back to you in a new turn, as a developer message: {"version":"1.0","rendererFunctionResponse":{"functionCallId":"<id>","value":...}}. If the call failed, it has "error" in place of "value". Do not wait for the result in this reply, and do not guess it.',
|
|
277
277
|
],
|
|
278
278
|
},
|
|
279
279
|
],
|
|
@@ -111,7 +111,7 @@ export function buildGenerativeUIPrompt(
|
|
|
111
111
|
`## Generative UI
|
|
112
112
|
${intro}
|
|
113
113
|
|
|
114
|
-
${when}Every operation has "version":"
|
|
114
|
+
${when}Every operation has "version":"1.0" and exactly one of:
|
|
115
115
|
${operations.map((op) => `- ${op}`).join("\n")}
|
|
116
116
|
|
|
117
117
|
Rules:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** A2UI protocol version used on the wire. */
|
|
2
|
-
export const A2UI_VERSION = "
|
|
2
|
+
export const A2UI_VERSION = "1.0";
|
|
3
3
|
/** Activity type of a generated surface message. */
|
|
4
4
|
export const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
5
5
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -83,7 +83,7 @@ export type A2UIFunctionCall = {
|
|
|
83
83
|
|
|
84
84
|
export type A2UIOperation =
|
|
85
85
|
| {
|
|
86
|
-
version:
|
|
86
|
+
version: typeof A2UI_VERSION;
|
|
87
87
|
createSurface: {
|
|
88
88
|
surfaceId: string;
|
|
89
89
|
/** Left out by the model. The run's catalog id is filled in. */
|
|
@@ -97,20 +97,23 @@ export type A2UIOperation =
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
| {
|
|
100
|
-
version:
|
|
100
|
+
version: typeof A2UI_VERSION;
|
|
101
101
|
updateComponents: { surfaceId: string; components: A2UIComponentNode[] };
|
|
102
102
|
}
|
|
103
103
|
| {
|
|
104
|
-
version:
|
|
104
|
+
version: typeof A2UI_VERSION;
|
|
105
105
|
/**
|
|
106
106
|
* Sets `value` at `path`. A `null` value deletes the key at `path`.
|
|
107
107
|
* With no `path`, or `"/"`, it sets the whole data model.
|
|
108
108
|
*/
|
|
109
109
|
updateDataModel: { surfaceId: string; path?: string; value: unknown };
|
|
110
110
|
}
|
|
111
|
-
| { version: "v1.0"; deleteSurface: { surfaceId: string } }
|
|
112
111
|
| {
|
|
113
|
-
version:
|
|
112
|
+
version: typeof A2UI_VERSION;
|
|
113
|
+
deleteSurface: { surfaceId: string };
|
|
114
|
+
}
|
|
115
|
+
| {
|
|
116
|
+
version: typeof A2UI_VERSION;
|
|
114
117
|
/** Runs an app function in the browser, with no user interaction. */
|
|
115
118
|
callRendererFunction: {
|
|
116
119
|
functionCallId: string;
|
|
@@ -292,7 +295,7 @@ export interface A2UIActionMessage {
|
|
|
292
295
|
* @example
|
|
293
296
|
* ```ts
|
|
294
297
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
295
|
-
* // { version: "
|
|
298
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
296
299
|
* ```
|
|
297
300
|
*/
|
|
298
301
|
export function toA2UIActionMessage(
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
MODEL_HOST_CLASSES,
|
|
5
|
-
type ModelHostClass,
|
|
6
|
-
} from "./model-host";
|
|
2
|
+
import { classifyModelHost, MODEL_HOST_CLASSES } from "./model-host";
|
|
3
|
+
import type { ModelHostClass } from "./model-host";
|
|
7
4
|
|
|
8
5
|
describe("classifyModelHost", () => {
|
|
9
6
|
describe("the case this exists for: an OpenAI-shaped client aimed elsewhere", () => {
|