@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.
Files changed (90) hide show
  1. package/dist/a2ui-envelope.cjs +2 -2
  2. package/dist/a2ui-envelope.cjs.map +1 -1
  3. package/dist/a2ui-envelope.d.cts +1 -1
  4. package/dist/a2ui-envelope.d.cts.map +1 -1
  5. package/dist/a2ui-envelope.d.mts +1 -1
  6. package/dist/a2ui-envelope.d.mts.map +1 -1
  7. package/dist/a2ui-envelope.mjs +2 -2
  8. package/dist/a2ui-envelope.mjs.map +1 -1
  9. package/dist/a2ui-prompts.cjs +21 -62
  10. package/dist/a2ui-prompts.cjs.map +1 -1
  11. package/dist/a2ui-prompts.d.cts +8 -1
  12. package/dist/a2ui-prompts.d.cts.map +1 -1
  13. package/dist/a2ui-prompts.d.mts +8 -1
  14. package/dist/a2ui-prompts.d.mts.map +1 -1
  15. package/dist/a2ui-prompts.mjs +22 -62
  16. package/dist/a2ui-prompts.mjs.map +1 -1
  17. package/dist/generative-ui/basic-functions.cjs +1 -1
  18. package/dist/generative-ui/basic-functions.cjs.map +1 -1
  19. package/dist/generative-ui/basic-functions.mjs +1 -1
  20. package/dist/generative-ui/basic-functions.mjs.map +1 -1
  21. package/dist/generative-ui/compact-schema.cjs +187 -0
  22. package/dist/generative-ui/compact-schema.cjs.map +1 -0
  23. package/dist/generative-ui/compact-schema.d.cts +55 -0
  24. package/dist/generative-ui/compact-schema.d.cts.map +1 -0
  25. package/dist/generative-ui/compact-schema.d.mts +55 -0
  26. package/dist/generative-ui/compact-schema.d.mts.map +1 -0
  27. package/dist/generative-ui/compact-schema.mjs +185 -0
  28. package/dist/generative-ui/compact-schema.mjs.map +1 -0
  29. package/dist/generative-ui/prompt-spec.cjs +225 -0
  30. package/dist/generative-ui/prompt-spec.cjs.map +1 -0
  31. package/dist/generative-ui/prompt-spec.d.cts +94 -0
  32. package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
  33. package/dist/generative-ui/prompt-spec.d.mts +94 -0
  34. package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
  35. package/dist/generative-ui/prompt-spec.mjs +220 -0
  36. package/dist/generative-ui/prompt-spec.mjs.map +1 -0
  37. package/dist/generative-ui/prompt.cjs +10 -36
  38. package/dist/generative-ui/prompt.cjs.map +1 -1
  39. package/dist/generative-ui/prompt.d.cts +2 -1
  40. package/dist/generative-ui/prompt.d.cts.map +1 -1
  41. package/dist/generative-ui/prompt.d.mts +2 -1
  42. package/dist/generative-ui/prompt.d.mts.map +1 -1
  43. package/dist/generative-ui/prompt.mjs +12 -38
  44. package/dist/generative-ui/prompt.mjs.map +1 -1
  45. package/dist/generative-ui/schema-render.cjs +242 -0
  46. package/dist/generative-ui/schema-render.cjs.map +1 -0
  47. package/dist/generative-ui/schema-render.d.cts +44 -0
  48. package/dist/generative-ui/schema-render.d.cts.map +1 -0
  49. package/dist/generative-ui/schema-render.d.mts +44 -0
  50. package/dist/generative-ui/schema-render.d.mts.map +1 -0
  51. package/dist/generative-ui/schema-render.mjs +239 -0
  52. package/dist/generative-ui/schema-render.mjs.map +1 -0
  53. package/dist/generative-ui/types.cjs +2 -2
  54. package/dist/generative-ui/types.cjs.map +1 -1
  55. package/dist/generative-ui/types.d.cts +7 -7
  56. package/dist/generative-ui/types.d.cts.map +1 -1
  57. package/dist/generative-ui/types.d.mts +7 -7
  58. package/dist/generative-ui/types.d.mts.map +1 -1
  59. package/dist/generative-ui/types.mjs +2 -2
  60. package/dist/generative-ui/types.mjs.map +1 -1
  61. package/dist/index.cjs +14 -0
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +4 -1
  64. package/dist/index.d.cts.map +1 -1
  65. package/dist/index.d.mts +4 -1
  66. package/dist/index.d.mts.map +1 -1
  67. package/dist/index.mjs +4 -1
  68. package/dist/index.mjs.map +1 -1
  69. package/dist/index.umd.js +756 -165
  70. package/dist/index.umd.js.map +1 -1
  71. package/dist/package.cjs +1 -1
  72. package/dist/package.mjs +1 -1
  73. package/package.json +1 -1
  74. package/src/__tests__/a2ui-envelope.test.ts +18 -13
  75. package/src/__tests__/a2ui-prompts.test.ts +47 -14
  76. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  77. package/src/__tests__/prompt-spec.test.ts +191 -0
  78. package/src/__tests__/schema-render.test.ts +245 -0
  79. package/src/a2ui-envelope.ts +5 -5
  80. package/src/a2ui-prompts.ts +47 -96
  81. package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
  82. package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
  83. package/src/generative-ui/basic-functions.ts +1 -1
  84. package/src/generative-ui/compact-schema.ts +277 -0
  85. package/src/generative-ui/index.ts +3 -0
  86. package/src/generative-ui/prompt-spec.ts +335 -0
  87. package/src/generative-ui/prompt.ts +25 -75
  88. package/src/generative-ui/schema-render.ts +374 -0
  89. package/src/generative-ui/types.ts +10 -7
  90. 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(false);
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 = { rule: "NOT_EQUALS", path: "a", value: 5 };
29
- expect(executeConditions({ conditions: [eq], value: { a: 5 } })).toBe(true);
30
- expect(executeConditions({ conditions: [eq], value: { a: 6 } })).toBe(false);
31
- expect(executeConditions({ conditions: [neq], value: { a: 6 } })).toBe(true);
32
- expect(executeConditions({ conditions: [neq], value: { a: 5 } })).toBe(false);
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 = { rule: "GREATER_THAN", path: "n", value: 10 };
37
- const lt: ComparisonCondition = { rule: "LESS_THAN", path: "n", value: 10 };
38
- expect(executeConditions({ conditions: [gt], value: { n: 11 } })).toBe(true);
39
- expect(executeConditions({ conditions: [gt], value: { n: 10 } })).toBe(false);
40
- expect(executeConditions({ conditions: [lt], value: { n: 9 } })).toBe(true);
41
- expect(executeConditions({ conditions: [lt], value: { n: 10 } })).toBe(false);
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 = { rule: "CONTAINS", path: "tags", value: "ts" };
46
- const notContains: ComparisonCondition = { rule: "NOT_CONTAINS", path: "tags", value: "ts" };
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({ conditions: [contains], value: { tags: ["js", "ts"] } }),
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({ conditions: [notContains], value: { tags: ["js"] } }),
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 = { rule: "MATCHES", path: "code", value: "^CK-[0-9]+$" };
67
- expect(executeConditions({ conditions: [matches], value: { code: "CK-123" } })).toBe(true);
68
- expect(executeConditions({ conditions: [matches], value: { code: "nope" } })).toBe(false);
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 = { rule: "STARTS_WITH", path: "s", value: "foo" };
73
- const ew: ComparisonCondition = { rule: "ENDS_WITH", path: "s", value: "bar" };
74
- expect(executeConditions({ conditions: [sw], value: { s: "foobar" } })).toBe(true);
75
- expect(executeConditions({ conditions: [sw], value: { s: "barfoo" } })).toBe(false);
76
- expect(executeConditions({ conditions: [ew], value: { s: "foobar" } })).toBe(true);
77
- expect(executeConditions({ conditions: [ew], value: { s: "barfoo" } })).toBe(false);
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(true);
85
- expect(executeConditions({ conditions: [exists], value: { a: "" } })).toBe(true);
86
- expect(executeConditions({ conditions: [exists], value: { a: false } })).toBe(true);
87
- expect(executeConditions({ conditions: [exists], value: { a: null } })).toBe(false);
88
- expect(executeConditions({ conditions: [exists], value: {} })).toBe(false);
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(executeConditions({ conditions: [notExists], value: { a: 1 } })).toBe(false);
94
- expect(executeConditions({ conditions: [notExists], value: { a: null } })).toBe(true);
95
- expect(executeConditions({ conditions: [notExists], value: {} })).toBe(true);
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(executeConditions({ conditions: [and], value: { a: 1, b: 2 } })).toBe(true);
109
- expect(executeConditions({ conditions: [and], value: { a: 1, b: 3 } })).toBe(false);
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(executeConditions({ conditions: [or], value: { a: 9, b: 2 } })).toBe(true);
121
- expect(executeConditions({ conditions: [or], value: { a: 9, b: 9 } })).toBe(false);
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(executeConditions({ conditions: [notAll], value: { a: 1, b: 2 } })).toBe(false);
225
+ expect(
226
+ executeConditions({ conditions: [notAll], value: { a: 1, b: 2 } }),
227
+ ).toBe(false);
134
228
  // one false → NOT(AND) = true
135
- expect(executeConditions({ conditions: [notAll], value: { a: 1, b: 3 } })).toBe(true);
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 = { rule: "EQUALS", path: "user.profile.age", value: 30 };
237
+ const cond: ComparisonCondition = {
238
+ rule: "EQUALS",
239
+ path: "user.profile.age",
240
+ value: 30,
241
+ };
142
242
  expect(
143
- executeConditions({ conditions: [cond], value: { user: { profile: { age: 30 } } } }),
243
+ executeConditions({
244
+ conditions: [cond],
245
+ value: { user: { profile: { age: 30 } } },
246
+ }),
144
247
  ).toBe(true);
145
248
  expect(
146
- executeConditions({ conditions: [cond], value: { user: { profile: { age: 31 } } } }),
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 = { rule: "EQUALS", path: "a.b.c", value: 1 };
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