@copilotkit/shared 1.82.0 → 1.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +242 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +239 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- 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.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +756 -165
- 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 +47 -14
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/a2ui-envelope.ts +5 -5
- package/src/a2ui-prompts.ts +47 -96
- 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/basic-functions.ts +1 -1
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +3 -0
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/schema-render.ts +374 -0
- package/src/generative-ui/types.ts +10 -7
- package/src/utils/__tests__/conditions.test.ts +153 -43
|
@@ -19,39 +19,83 @@ describe("executeConditions", () => {
|
|
|
19
19
|
{ rule: "EQUALS", path: "b", value: 2 },
|
|
20
20
|
];
|
|
21
21
|
expect(executeConditions({ conditions, value: { a: 1, b: 2 } })).toBe(true);
|
|
22
|
-
expect(executeConditions({ conditions, value: { a: 1, b: 3 } })).toBe(
|
|
22
|
+
expect(executeConditions({ conditions, value: { a: 1, b: 3 } })).toBe(
|
|
23
|
+
false,
|
|
24
|
+
);
|
|
23
25
|
});
|
|
24
26
|
|
|
25
27
|
describe("comparison rules", () => {
|
|
26
28
|
it("EQUALS and NOT_EQUALS", () => {
|
|
27
29
|
const eq: ComparisonCondition = { rule: "EQUALS", path: "a", value: 5 };
|
|
28
|
-
const neq: ComparisonCondition = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const neq: ComparisonCondition = {
|
|
31
|
+
rule: "NOT_EQUALS",
|
|
32
|
+
path: "a",
|
|
33
|
+
value: 5,
|
|
34
|
+
};
|
|
35
|
+
expect(executeConditions({ conditions: [eq], value: { a: 5 } })).toBe(
|
|
36
|
+
true,
|
|
37
|
+
);
|
|
38
|
+
expect(executeConditions({ conditions: [eq], value: { a: 6 } })).toBe(
|
|
39
|
+
false,
|
|
40
|
+
);
|
|
41
|
+
expect(executeConditions({ conditions: [neq], value: { a: 6 } })).toBe(
|
|
42
|
+
true,
|
|
43
|
+
);
|
|
44
|
+
expect(executeConditions({ conditions: [neq], value: { a: 5 } })).toBe(
|
|
45
|
+
false,
|
|
46
|
+
);
|
|
33
47
|
});
|
|
34
48
|
|
|
35
49
|
it("GREATER_THAN and LESS_THAN", () => {
|
|
36
|
-
const gt: ComparisonCondition = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
const gt: ComparisonCondition = {
|
|
51
|
+
rule: "GREATER_THAN",
|
|
52
|
+
path: "n",
|
|
53
|
+
value: 10,
|
|
54
|
+
};
|
|
55
|
+
const lt: ComparisonCondition = {
|
|
56
|
+
rule: "LESS_THAN",
|
|
57
|
+
path: "n",
|
|
58
|
+
value: 10,
|
|
59
|
+
};
|
|
60
|
+
expect(executeConditions({ conditions: [gt], value: { n: 11 } })).toBe(
|
|
61
|
+
true,
|
|
62
|
+
);
|
|
63
|
+
expect(executeConditions({ conditions: [gt], value: { n: 10 } })).toBe(
|
|
64
|
+
false,
|
|
65
|
+
);
|
|
66
|
+
expect(executeConditions({ conditions: [lt], value: { n: 9 } })).toBe(
|
|
67
|
+
true,
|
|
68
|
+
);
|
|
69
|
+
expect(executeConditions({ conditions: [lt], value: { n: 10 } })).toBe(
|
|
70
|
+
false,
|
|
71
|
+
);
|
|
42
72
|
});
|
|
43
73
|
|
|
44
74
|
it("CONTAINS and NOT_CONTAINS only apply to arrays", () => {
|
|
45
|
-
const contains: ComparisonCondition = {
|
|
46
|
-
|
|
75
|
+
const contains: ComparisonCondition = {
|
|
76
|
+
rule: "CONTAINS",
|
|
77
|
+
path: "tags",
|
|
78
|
+
value: "ts",
|
|
79
|
+
};
|
|
80
|
+
const notContains: ComparisonCondition = {
|
|
81
|
+
rule: "NOT_CONTAINS",
|
|
82
|
+
path: "tags",
|
|
83
|
+
value: "ts",
|
|
84
|
+
};
|
|
47
85
|
expect(
|
|
48
|
-
executeConditions({
|
|
86
|
+
executeConditions({
|
|
87
|
+
conditions: [contains],
|
|
88
|
+
value: { tags: ["js", "ts"] },
|
|
89
|
+
}),
|
|
49
90
|
).toBe(true);
|
|
50
91
|
expect(
|
|
51
92
|
executeConditions({ conditions: [contains], value: { tags: ["js"] } }),
|
|
52
93
|
).toBe(false);
|
|
53
94
|
expect(
|
|
54
|
-
executeConditions({
|
|
95
|
+
executeConditions({
|
|
96
|
+
conditions: [notContains],
|
|
97
|
+
value: { tags: ["js"] },
|
|
98
|
+
}),
|
|
55
99
|
).toBe(true);
|
|
56
100
|
// non-array target always fails both CONTAINS and NOT_CONTAINS
|
|
57
101
|
expect(
|
|
@@ -63,36 +107,76 @@ describe("executeConditions", () => {
|
|
|
63
107
|
});
|
|
64
108
|
|
|
65
109
|
it("MATCHES uses the value as a regular expression", () => {
|
|
66
|
-
const matches: ComparisonCondition = {
|
|
67
|
-
|
|
68
|
-
|
|
110
|
+
const matches: ComparisonCondition = {
|
|
111
|
+
rule: "MATCHES",
|
|
112
|
+
path: "code",
|
|
113
|
+
value: "^CK-[0-9]+$",
|
|
114
|
+
};
|
|
115
|
+
expect(
|
|
116
|
+
executeConditions({ conditions: [matches], value: { code: "CK-123" } }),
|
|
117
|
+
).toBe(true);
|
|
118
|
+
expect(
|
|
119
|
+
executeConditions({ conditions: [matches], value: { code: "nope" } }),
|
|
120
|
+
).toBe(false);
|
|
69
121
|
});
|
|
70
122
|
|
|
71
123
|
it("STARTS_WITH and ENDS_WITH", () => {
|
|
72
|
-
const sw: ComparisonCondition = {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
124
|
+
const sw: ComparisonCondition = {
|
|
125
|
+
rule: "STARTS_WITH",
|
|
126
|
+
path: "s",
|
|
127
|
+
value: "foo",
|
|
128
|
+
};
|
|
129
|
+
const ew: ComparisonCondition = {
|
|
130
|
+
rule: "ENDS_WITH",
|
|
131
|
+
path: "s",
|
|
132
|
+
value: "bar",
|
|
133
|
+
};
|
|
134
|
+
expect(
|
|
135
|
+
executeConditions({ conditions: [sw], value: { s: "foobar" } }),
|
|
136
|
+
).toBe(true);
|
|
137
|
+
expect(
|
|
138
|
+
executeConditions({ conditions: [sw], value: { s: "barfoo" } }),
|
|
139
|
+
).toBe(false);
|
|
140
|
+
expect(
|
|
141
|
+
executeConditions({ conditions: [ew], value: { s: "foobar" } }),
|
|
142
|
+
).toBe(true);
|
|
143
|
+
expect(
|
|
144
|
+
executeConditions({ conditions: [ew], value: { s: "barfoo" } }),
|
|
145
|
+
).toBe(false);
|
|
78
146
|
});
|
|
79
147
|
});
|
|
80
148
|
|
|
81
149
|
describe("existence rules", () => {
|
|
82
150
|
it("EXISTS passes only for defined non-null values", () => {
|
|
83
151
|
const exists: ExistenceCondition = { rule: "EXISTS", path: "a" };
|
|
84
|
-
expect(executeConditions({ conditions: [exists], value: { a: 0 } })).toBe(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
expect(
|
|
88
|
-
|
|
152
|
+
expect(executeConditions({ conditions: [exists], value: { a: 0 } })).toBe(
|
|
153
|
+
true,
|
|
154
|
+
);
|
|
155
|
+
expect(
|
|
156
|
+
executeConditions({ conditions: [exists], value: { a: "" } }),
|
|
157
|
+
).toBe(true);
|
|
158
|
+
expect(
|
|
159
|
+
executeConditions({ conditions: [exists], value: { a: false } }),
|
|
160
|
+
).toBe(true);
|
|
161
|
+
expect(
|
|
162
|
+
executeConditions({ conditions: [exists], value: { a: null } }),
|
|
163
|
+
).toBe(false);
|
|
164
|
+
expect(executeConditions({ conditions: [exists], value: {} })).toBe(
|
|
165
|
+
false,
|
|
166
|
+
);
|
|
89
167
|
});
|
|
90
168
|
|
|
91
169
|
it("NOT_EXISTS is the inverse of EXISTS", () => {
|
|
92
170
|
const notExists: ExistenceCondition = { rule: "NOT_EXISTS", path: "a" };
|
|
93
|
-
expect(
|
|
94
|
-
|
|
95
|
-
|
|
171
|
+
expect(
|
|
172
|
+
executeConditions({ conditions: [notExists], value: { a: 1 } }),
|
|
173
|
+
).toBe(false);
|
|
174
|
+
expect(
|
|
175
|
+
executeConditions({ conditions: [notExists], value: { a: null } }),
|
|
176
|
+
).toBe(true);
|
|
177
|
+
expect(executeConditions({ conditions: [notExists], value: {} })).toBe(
|
|
178
|
+
true,
|
|
179
|
+
);
|
|
96
180
|
});
|
|
97
181
|
});
|
|
98
182
|
|
|
@@ -105,8 +189,12 @@ describe("executeConditions", () => {
|
|
|
105
189
|
{ rule: "EQUALS", path: "b", value: 2 },
|
|
106
190
|
],
|
|
107
191
|
};
|
|
108
|
-
expect(
|
|
109
|
-
|
|
192
|
+
expect(
|
|
193
|
+
executeConditions({ conditions: [and], value: { a: 1, b: 2 } }),
|
|
194
|
+
).toBe(true);
|
|
195
|
+
expect(
|
|
196
|
+
executeConditions({ conditions: [and], value: { a: 1, b: 3 } }),
|
|
197
|
+
).toBe(false);
|
|
110
198
|
});
|
|
111
199
|
|
|
112
200
|
it("OR passes when any nested condition passes", () => {
|
|
@@ -117,8 +205,12 @@ describe("executeConditions", () => {
|
|
|
117
205
|
{ rule: "EQUALS", path: "b", value: 2 },
|
|
118
206
|
],
|
|
119
207
|
};
|
|
120
|
-
expect(
|
|
121
|
-
|
|
208
|
+
expect(
|
|
209
|
+
executeConditions({ conditions: [or], value: { a: 9, b: 2 } }),
|
|
210
|
+
).toBe(true);
|
|
211
|
+
expect(
|
|
212
|
+
executeConditions({ conditions: [or], value: { a: 9, b: 9 } }),
|
|
213
|
+
).toBe(false);
|
|
122
214
|
});
|
|
123
215
|
|
|
124
216
|
it("NOT inverts the AND of nested conditions", () => {
|
|
@@ -130,25 +222,43 @@ describe("executeConditions", () => {
|
|
|
130
222
|
],
|
|
131
223
|
};
|
|
132
224
|
// both true → NOT(AND) = false
|
|
133
|
-
expect(
|
|
225
|
+
expect(
|
|
226
|
+
executeConditions({ conditions: [notAll], value: { a: 1, b: 2 } }),
|
|
227
|
+
).toBe(false);
|
|
134
228
|
// one false → NOT(AND) = true
|
|
135
|
-
expect(
|
|
229
|
+
expect(
|
|
230
|
+
executeConditions({ conditions: [notAll], value: { a: 1, b: 3 } }),
|
|
231
|
+
).toBe(true);
|
|
136
232
|
});
|
|
137
233
|
});
|
|
138
234
|
|
|
139
235
|
describe("path resolution", () => {
|
|
140
236
|
it("resolves nested dot paths", () => {
|
|
141
|
-
const cond: ComparisonCondition = {
|
|
237
|
+
const cond: ComparisonCondition = {
|
|
238
|
+
rule: "EQUALS",
|
|
239
|
+
path: "user.profile.age",
|
|
240
|
+
value: 30,
|
|
241
|
+
};
|
|
142
242
|
expect(
|
|
143
|
-
executeConditions({
|
|
243
|
+
executeConditions({
|
|
244
|
+
conditions: [cond],
|
|
245
|
+
value: { user: { profile: { age: 30 } } },
|
|
246
|
+
}),
|
|
144
247
|
).toBe(true);
|
|
145
248
|
expect(
|
|
146
|
-
executeConditions({
|
|
249
|
+
executeConditions({
|
|
250
|
+
conditions: [cond],
|
|
251
|
+
value: { user: { profile: { age: 31 } } },
|
|
252
|
+
}),
|
|
147
253
|
).toBe(false);
|
|
148
254
|
});
|
|
149
255
|
|
|
150
256
|
it("returns false for a missing nested path (undefined target)", () => {
|
|
151
|
-
const eq: ComparisonCondition = {
|
|
257
|
+
const eq: ComparisonCondition = {
|
|
258
|
+
rule: "EQUALS",
|
|
259
|
+
path: "a.b.c",
|
|
260
|
+
value: 1,
|
|
261
|
+
};
|
|
152
262
|
expect(executeConditions({ conditions: [eq], value: {} })).toBe(false);
|
|
153
263
|
});
|
|
154
264
|
|