@copilotkit/shared 0.0.0-main-20250416144141 → 0.0.0-main-20250908181442

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 (87) hide show
  1. package/CHANGELOG.md +382 -1
  2. package/README.md +123 -28
  3. package/dist/{chunk-JP2M4U4G.mjs → chunk-2KQ6HEWZ.mjs} +83 -1
  4. package/dist/chunk-2KQ6HEWZ.mjs.map +1 -0
  5. package/dist/chunk-2OJ5OJ2D.mjs +1 -0
  6. package/dist/{chunk-FDYHD5WN.mjs → chunk-4VYF77PM.mjs} +104 -39
  7. package/dist/chunk-4VYF77PM.mjs.map +1 -0
  8. package/dist/chunk-6W2UEO2M.mjs +94 -0
  9. package/dist/chunk-6W2UEO2M.mjs.map +1 -0
  10. package/dist/chunk-EDB7MSUL.mjs +38 -0
  11. package/dist/chunk-EDB7MSUL.mjs.map +1 -0
  12. package/dist/{chunk-QFITLWYZ.mjs → chunk-FDWH72Z2.mjs} +9 -2
  13. package/dist/chunk-FDWH72Z2.mjs.map +1 -0
  14. package/dist/chunk-N5EP5OD5.mjs +1 -0
  15. package/dist/chunk-N5EP5OD5.mjs.map +1 -0
  16. package/dist/chunk-UYARLQNA.mjs +1 -0
  17. package/dist/chunk-UYARLQNA.mjs.map +1 -0
  18. package/dist/index.d.ts +7 -3
  19. package/dist/index.js +324 -39
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +37 -8
  22. package/dist/telemetry/events.d.ts +6 -0
  23. package/dist/telemetry/events.js.map +1 -1
  24. package/dist/telemetry/index.js +40 -1
  25. package/dist/telemetry/index.js.map +1 -1
  26. package/dist/telemetry/index.mjs +2 -1
  27. package/dist/telemetry/scarf-client.d.ts +7 -0
  28. package/dist/telemetry/scarf-client.js +59 -0
  29. package/dist/telemetry/scarf-client.js.map +1 -0
  30. package/dist/telemetry/scarf-client.mjs +7 -0
  31. package/dist/telemetry/scarf-client.mjs.map +1 -0
  32. package/dist/telemetry/telemetry-client.js +40 -1
  33. package/dist/telemetry/telemetry-client.js.map +1 -1
  34. package/dist/telemetry/telemetry-client.mjs +2 -1
  35. package/dist/types/error.d.ts +55 -0
  36. package/dist/types/error.js +19 -0
  37. package/dist/types/error.js.map +1 -0
  38. package/dist/types/error.mjs +2 -0
  39. package/dist/types/error.mjs.map +1 -0
  40. package/dist/types/index.d.ts +3 -0
  41. package/dist/types/index.js.map +1 -1
  42. package/dist/types/index.mjs +4 -2
  43. package/dist/types/message.d.ts +25 -0
  44. package/dist/types/message.js +19 -0
  45. package/dist/types/message.js.map +1 -0
  46. package/dist/types/message.mjs +2 -0
  47. package/dist/types/message.mjs.map +1 -0
  48. package/dist/utils/console-styling.d.ts +84 -0
  49. package/dist/utils/console-styling.js +123 -0
  50. package/dist/utils/console-styling.js.map +1 -0
  51. package/dist/utils/console-styling.mjs +17 -0
  52. package/dist/utils/console-styling.mjs.map +1 -0
  53. package/dist/utils/errors.d.ts +58 -4
  54. package/dist/utils/errors.js +102 -38
  55. package/dist/utils/errors.js.map +1 -1
  56. package/dist/utils/errors.mjs +19 -7
  57. package/dist/utils/index.d.ts +9 -3
  58. package/dist/utils/index.js +285 -36
  59. package/dist/utils/index.js.map +1 -1
  60. package/dist/utils/index.mjs +37 -8
  61. package/dist/utils/json-schema.d.ts +2 -1
  62. package/dist/utils/json-schema.js +85 -2
  63. package/dist/utils/json-schema.js.map +1 -1
  64. package/dist/utils/json-schema.mjs +5 -3
  65. package/package.json +2 -1
  66. package/src/telemetry/events.ts +6 -0
  67. package/src/telemetry/scarf-client.ts +39 -0
  68. package/src/telemetry/telemetry-client.ts +7 -1
  69. package/src/types/error.ts +70 -0
  70. package/src/types/index.ts +2 -0
  71. package/src/types/message.ts +30 -0
  72. package/src/utils/console-styling.ts +124 -0
  73. package/src/utils/errors.ts +112 -24
  74. package/src/utils/index.ts +9 -0
  75. package/src/utils/json-schema.test.ts +215 -1
  76. package/src/utils/json-schema.ts +98 -0
  77. package/tsup.config.ts +1 -6
  78. package/dist/chunk-BANDZXMP.mjs +0 -1
  79. package/dist/chunk-FDYHD5WN.mjs.map +0 -1
  80. package/dist/chunk-JP2M4U4G.mjs.map +0 -1
  81. package/dist/chunk-QFITLWYZ.mjs.map +0 -1
  82. package/dist/utils/json-schema.test.d.ts +0 -2
  83. package/dist/utils/json-schema.test.js +0 -173
  84. package/dist/utils/json-schema.test.js.map +0 -1
  85. package/dist/utils/json-schema.test.mjs +0 -140
  86. package/dist/utils/json-schema.test.mjs.map +0 -1
  87. /package/dist/{chunk-BANDZXMP.mjs.map → chunk-2OJ5OJ2D.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,387 @@
1
1
  # @copilotkit/shared
2
2
 
3
- ## 0.0.0-main-20250416144141
3
+ ## 0.0.0-main-20250908181442
4
+
5
+ ### Patch Changes
6
+
7
+ - a640d8e: - feat: update latest agui langgraph for subgraphs support
8
+ - feat: update latest agui core packages
9
+
10
+ ## 1.10.4-next.3
11
+
12
+ ## 1.10.4-next.2
13
+
14
+ ## 1.10.4-next.1
15
+
16
+ ### Patch Changes
17
+
18
+ - a640d8e: - feat: update latest agui langgraph for subgraphs support
19
+ - feat: update latest agui core packages
20
+
21
+ ## 1.10.4-next.0
22
+
23
+ ## 1.10.3
24
+
25
+ ### Patch Changes
26
+
27
+ - ea74047: - fix: surface run errors from agui
28
+
29
+ ## 1.10.3-next.3
30
+
31
+ ## 1.10.3-next.2
32
+
33
+ ## 1.10.3-next.1
34
+
35
+ ## 1.10.3-next.0
36
+
37
+ ### Patch Changes
38
+
39
+ - ea74047: - fix: surface run errors from agui
40
+
41
+ ## 1.10.2
42
+
43
+ ## 1.10.2-next.0
44
+
45
+ ## 1.10.1
46
+
47
+ ## 1.10.1-next.2
48
+
49
+ ## 1.10.1-next.1
50
+
51
+ ## 1.10.1-next.0
52
+
53
+ ## 1.10.0
54
+
55
+ ### Minor Changes
56
+
57
+ - 8674da1: - refactor(headless): completely overhaul headless ui to better support agentic features
58
+
59
+ Headless UI has been in a bad state for a bit now. When we added support for different
60
+ agentic runtimes we acquired tech-debt that, with this PR, is being alleviated.
61
+
62
+ As such, the following features have been updated to be completely functional with Headless UI.
63
+
64
+ - Generative UI
65
+ - Suggestions
66
+ - Agentic Generative UI
67
+ - Interrupts
68
+
69
+ In addition, a variety of QOL changes have been made.
70
+
71
+ - New AG-UI based message types
72
+ - Inline code rendering is fixed
73
+
74
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
75
+
76
+ ### Patch Changes
77
+
78
+ - a8c0263: - feat: add event hooks system for chat components
79
+ - 6d1de58: - fix: address issues that would cause headless UI breaking changes in the next release
80
+
81
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
82
+
83
+ - fix: more fixes addressing breaking changes in new Headless UI
84
+
85
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
86
+
87
+ - chore: address linting issues
88
+
89
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
90
+
91
+ - chore: fixing branding and docs
92
+
93
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
94
+
95
+ - chore: more docs fixing
96
+
97
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
98
+
99
+ ## 1.10.0-next.13
100
+
101
+ ## 1.10.0-next.12
102
+
103
+ ## 1.10.0-next.11
104
+
105
+ ## 1.10.0-next.10
106
+
107
+ ### Patch Changes
108
+
109
+ - 6d1de58: - fix: address issues that would cause headless UI breaking changes in the next release
110
+
111
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
112
+
113
+ - fix: more fixes addressing breaking changes in new Headless UI
114
+
115
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
116
+
117
+ - chore: address linting issues
118
+
119
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
120
+
121
+ - chore: fixing branding and docs
122
+
123
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
124
+
125
+ - chore: more docs fixing
126
+
127
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
128
+
129
+ ## 1.10.0-next.9
130
+
131
+ ## 1.10.0-next.8
132
+
133
+ ## 1.10.0-next.7
134
+
135
+ ## 1.10.0-next.6
136
+
137
+ ## 1.10.0-next.5
138
+
139
+ ### Patch Changes
140
+
141
+ - a8c0263: - feat: add event hooks system for chat components
142
+
143
+ ## 1.10.0-next.4
144
+
145
+ ## 1.10.0-next.3
146
+
147
+ ## 1.10.0-next.2
148
+
149
+ ## 1.10.0-next.1
150
+
151
+ ## 1.10.0-next.0
152
+
153
+ ### Minor Changes
154
+
155
+ - 8674da1: - refactor(headless): completely overhaul headless ui to better support agentic features
156
+
157
+ Headless UI has been in a bad state for a bit now. When we added support for different
158
+ agentic runtimes we acquired tech-debt that, with this PR, is being alleviated.
159
+
160
+ As such, the following features have been updated to be completely functional with Headless UI.
161
+
162
+ - Generative UI
163
+ - Suggestions
164
+ - Agentic Generative UI
165
+ - Interrupts
166
+
167
+ In addition, a variety of QOL changes have been made.
168
+
169
+ - New AG-UI based message types
170
+ - Inline code rendering is fixed
171
+
172
+ Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
173
+
174
+ ## 1.9.3
175
+
176
+ ### Patch Changes
177
+
178
+ - 1bda332: - chore(telemetry): integrate Scarf for usage analytics
179
+
180
+ ## 1.9.3-next.4
181
+
182
+ ## 1.9.3-next.3
183
+
184
+ ### Patch Changes
185
+
186
+ - 1bda332: - chore(telemetry): integrate Scarf for usage analytics
187
+
188
+ ## 1.9.3-next.2
189
+
190
+ ## 1.9.3-next.1
191
+
192
+ ## 1.9.3-next.0
193
+
194
+ ## 1.9.2
195
+
196
+ ### Patch Changes
197
+
198
+ - fac89c2: - refactor: rename onTrace to onError throughout codebase
199
+
200
+ - Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
201
+
202
+ - 9169ad7: - feat: add onTrace handler for runtime and UI error/event tracking
203
+ - 1d1c51d: - feat: surface all errors in structured format
204
+ - 10345a5: - feat: structured error visibility system for streaming errors
205
+ - 9169ad7: - feat: add onTrace handler for comprehensive debugging and observability - Add CopilotTraceEvent interfaces with rich debugging context, implement runtime-side tracing with publicApiKey gating, add UI-side error tracing, include comprehensive test coverage, and fix tsup build config to exclude test files
206
+ - fix: extract publicApiKey for all requests + trace GraphQL errors
207
+
208
+ ## 1.9.2-next.26
209
+
210
+ ## 1.9.2-next.25
211
+
212
+ ## 1.9.2-next.24
213
+
214
+ ## 1.9.2-next.23
215
+
216
+ ## 1.9.2-next.22
217
+
218
+ ## 1.9.2-next.21
219
+
220
+ ## 1.9.2-next.20
221
+
222
+ ## 1.9.2-next.19
223
+
224
+ ## 1.9.2-next.18
225
+
226
+ ### Patch Changes
227
+
228
+ - fac89c2: - refactor: rename onTrace to onError throughout codebase
229
+
230
+ - Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
231
+
232
+ ## 1.9.2-next.17
233
+
234
+ ## 1.9.2-next.16
235
+
236
+ ## 1.9.2-next.15
237
+
238
+ ## 1.9.2-next.14
239
+
240
+ ## 1.9.2-next.13
241
+
242
+ ## 1.9.2-next.12
243
+
244
+ ## 1.9.2-next.11
245
+
246
+ ## 1.9.2-next.10
247
+
248
+ ## 1.9.2-next.9
249
+
250
+ ### Patch Changes
251
+
252
+ - 1d1c51d: - feat: surface all errors in structured format
253
+
254
+ ## 1.9.2-next.8
255
+
256
+ ## 1.9.2-next.7
257
+
258
+ ## 1.9.2-next.6
259
+
260
+ ## 1.9.2-next.5
261
+
262
+ ## 1.9.2-next.4
263
+
264
+ ### Patch Changes
265
+
266
+ - 9169ad7: - feat: add onTrace handler for runtime and UI error/event tracking
267
+ - 9169ad7: - feat: add onTrace handler for comprehensive debugging and observability - Add CopilotTraceEvent interfaces with rich debugging context, implement runtime-side tracing with publicApiKey gating, add UI-side error tracing, include comprehensive test coverage, and fix tsup build config to exclude test files
268
+ - fix: extract publicApiKey for all requests + trace GraphQL errors
269
+
270
+ ## 1.9.2-next.3
271
+
272
+ ## 1.9.2-next.2
273
+
274
+ ## 1.9.2-next.1
275
+
276
+ ## 1.9.2-next.0
277
+
278
+ ### Patch Changes
279
+
280
+ - 10345a5: - feat: structured error visibility system for streaming errors
281
+
282
+ ## 1.9.1
283
+
284
+ ### Patch Changes
285
+
286
+ - deaeca0: - feat: Add public key
287
+
288
+ Signed-off-by: Luis Valdes <luis@copilotkit.ai>
289
+
290
+ ## 1.9.1-next.0
291
+
292
+ ### Patch Changes
293
+
294
+ - deaeca0: - feat: Add public key
295
+
296
+ Signed-off-by: Luis Valdes <luis@copilotkit.ai>
297
+
298
+ ## 1.9.0
299
+
300
+ ## 1.9.0-next.2
301
+
302
+ ## 1.8.15-next.1
303
+
304
+ ## 1.8.15-next.0
305
+
306
+ ## 1.8.14
307
+
308
+ ### Patch Changes
309
+
310
+ - 34a78d8: - jsonSchemaToActionParameters implementation
311
+
312
+ ## 1.8.14-next.5
313
+
314
+ ## 1.8.14-next.4
315
+
316
+ ## 1.8.14-next.3
317
+
318
+ ## 1.8.14-next.2
319
+
320
+ ## 1.8.14-next.1
321
+
322
+ ### Patch Changes
323
+
324
+ - 34a78d8: - jsonSchemaToActionParameters implementation
325
+
326
+ ## 1.8.14-next.0
327
+
328
+ ## 1.8.13
329
+
330
+ ## 1.8.13-next.3
331
+
332
+ ## 1.8.13-next.2
333
+
334
+ ## 1.8.13-next.1
335
+
336
+ ## 1.8.13-next.0
337
+
338
+ ## 1.8.12
339
+
340
+ ## 1.8.12-next.6
341
+
342
+ ## 1.8.12-next.5
343
+
344
+ ## 1.8.12-next.4
345
+
346
+ ## 1.8.12-next.3
347
+
348
+ ## 1.8.12-next.2
349
+
350
+ ## 1.8.12-next.1
351
+
352
+ ## 1.8.12-next.0
353
+
354
+ ## 1.8.11
355
+
356
+ ## 1.8.11-next.1
357
+
358
+ ## 1.8.11-next.0
359
+
360
+ ## 1.8.10
361
+
362
+ ## 1.8.10-next.3
363
+
364
+ ## 1.8.10-next.2
365
+
366
+ ## 1.8.10-next.1
367
+
368
+ ## 1.8.10-next.0
369
+
370
+ ## 1.8.9
371
+
372
+ ## 1.8.9-next.0
373
+
374
+ ## 1.8.8
375
+
376
+ ## 1.8.8-next.1
377
+
378
+ ## 1.8.8-next.0
379
+
380
+ ## 1.8.7
381
+
382
+ ## 1.8.7-next.0
383
+
384
+ ## 1.8.6
4
385
 
5
386
  ## 1.8.6-next.0
6
387
 
package/README.md CHANGED
@@ -1,45 +1,140 @@
1
- <div align="center">
2
- <a href="https://copilotkit.ai" target="_blank">
3
- <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo">
4
- </a>
5
-
6
- <br/>
7
-
8
- <strong>
9
- CopilotKit is the open-source framework for integrating powerful AI Copilots into any application. Easily implement custom AI Chatbots, AI Agents, AI Textareas, and more.
10
- </strong>
11
- </div>
1
+ # CopilotKit - Shared
12
2
 
13
- <br/>
3
+ <img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
14
4
 
15
- <div align="center">
5
+ <br>
6
+ <div align="center" style="display:flex;justify-content:center;gap:16px;height:20px;margin: 0;">
16
7
  <a href="https://www.npmjs.com/package/@copilotkit/react-core" target="_blank">
17
- <img src="https://img.shields.io/npm/v/%40copilotkit%2Freact-core?logo=npm&logoColor=%23FFFFFF&label=Version&color=%236963ff" alt="NPM">
8
+ <img src="https://img.shields.io/npm/v/%40copilotkit%2Fshared?logo=npm&logoColor=%23FFFFFF&label=Version&color=%236963ff" alt="NPM">
9
+ </a>
10
+ <a href="https://github.com/copilotkit/copilotkit/blob/main/LICENSE" target="_blank">
11
+ <img src="https://img.shields.io/github/license/copilotkit/copilotkit?color=%236963ff&label=License" alt="MIT">
18
12
  </a>
19
- <img src="https://img.shields.io/github/license/copilotkit/copilotkit?color=%236963ff&label=License" alt="MIT">
20
13
  <a href="https://discord.gg/6dffbvGU3D" target="_blank">
21
14
  <img src="https://img.shields.io/discord/1122926057641742418?logo=discord&logoColor=%23FFFFFF&label=Discord&color=%236963ff" alt="Discord">
22
15
  </a>
23
16
  </div>
24
17
  <br/>
25
-
26
18
  <div align="center">
27
- <a href="https://discord.gg/6dffbvGU3D?ref=github_readme" target="_blank">
28
- <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/btn_discord.png" alt="CopilotKit Discord" height="40px">
29
- </a>
30
- <a href="https://docs.copilotkit.ai?ref=github_readme" target="_blank">
31
- <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/btn_docs.png" alt="CopilotKit GitHub" height="40px">
32
- </a>
33
- <a href="https://cloud.copilotkit.ai?ref=github_readme" target="_blank">
34
- <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/btn_cloud.png" alt="CopilotKit GitHub" height="40px">
19
+ <a href="https://www.producthunt.com/posts/copilotkit" target="_blank">
20
+ <img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=428778&theme=light&period=daily">
35
21
  </a>
36
22
  </div>
37
23
 
38
- <br />
24
+ ## ✨ Why CopilotKit?
39
25
 
40
- <div align="center">
41
- <img src="https://github.com/CopilotKit/CopilotKit/raw/main/assets/animated-banner.gif" alt="CopilotKit Screenshot" style="border-radius: 15px;" />
42
- </div>
26
+ - Minutes to integrate - Get started quickly with our CLI
27
+ - Framework agnostic - Works with React, Next.js, AGUI and more
28
+ - Production-ready UI - Use customizable components or build with headless UI
29
+ - Built-in security - Prompt injection protection
30
+ - Open source - Full transparency and community-driven
31
+
32
+ <img src="https://github.com/user-attachments/assets/6cb425f8-ffcb-49d2-9bbb-87cab5995b78" alt="class-support-ecosystem" style="border-radius: 12px; border: 2px solid #d6d4fa;">
33
+
34
+ ## 🧑‍💻 Real life use cases
35
+
36
+ <span>Deploy deeply-integrated AI assistants & agents that work alongside your users inside your applications.</span>
37
+
38
+ <img src="https://github.com/user-attachments/assets/3b810240-e9f8-43ae-acec-31a58095e223" alt="headless-ui" style="border-radius: 12px; border: 2px solid #d6d4fa;">
39
+
40
+ ## 🖥️ Code Samples
41
+
42
+ <span>Drop in these building blocks and tailor them to your needs.</span>
43
+
44
+ <h3>Build with Headless APIs and Pre-Built Components</h3>
45
+
46
+ ```ts
47
+ // Headless UI with full control
48
+ const { visibleMessages, appendMessage, setMessages, ... } = useCopilotChat();
49
+
50
+ // Pre-built components with deep customization options (CSS + pass custom sub-components)
51
+ <CopilotPopup
52
+ instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."}
53
+ labels={{ title: "Popup Assistant", initial: "Need any help?" }}
54
+ />
55
+ ```
56
+
57
+ ```ts
58
+ // Frontend actions + generative UI, with full streaming support
59
+ useCopilotAction({
60
+ name: "appendToSpreadsheet",
61
+ description: "Append rows to the current spreadsheet",
62
+ parameters: [
63
+ { name: "rows", type: "object[]", attributes: [{ name: "cells", type: "object[]", attributes: [{ name: "value", type: "string" }] }] }
64
+ ],
65
+ render: ({ status, args }) => <Spreadsheet data={canonicalSpreadsheetData(args.rows)} />,
66
+ handler: ({ rows }) => setSpreadsheet({ ...spreadsheet, rows: [...spreadsheet.rows, ...canonicalSpreadsheetData(rows)] }),
67
+ });
68
+ ```
69
+
70
+ <h3>Integrate In-App CoAgents with LangGraph</h3>
71
+
72
+ ```ts
73
+ // Share state between app and agent
74
+ const { agentState } = useCoAgent({
75
+ name: "basic_agent",
76
+ initialState: { input: "NYC" }
77
+ });
78
+
79
+ // agentic generative UI
80
+ useCoAgentStateRender({
81
+ name: "basic_agent",
82
+ render: ({ state }) => <WeatherDisplay {...state.final_response} />,
83
+ });
84
+
85
+ // Human in the Loop (Approval)
86
+ useCopilotAction({
87
+ name: "email_tool",
88
+ parameters: [
89
+ {
90
+ name: "email_draft",
91
+ type: "string",
92
+ description: "The email content",
93
+ required: true,
94
+ },
95
+ ],
96
+ renderAndWaitForResponse: ({ args, status, respond }) => {
97
+ return (
98
+ <EmailConfirmation
99
+ emailContent={args.email_draft || ""}
100
+ isExecuting={status === "executing"}
101
+ onCancel={() => respond?.({ approved: false })}
102
+ onSend={() =>
103
+ respond?.({
104
+ approved: true,
105
+ metadata: { sentAt: new Date().toISOString() },
106
+ })
107
+ }
108
+ />
109
+ );
110
+ },
111
+ });
112
+ ```
113
+
114
+ ```ts
115
+ // intermediate agent state streaming (supports both LangGraph.js + LangGraph python)
116
+ const modifiedConfig = copilotKitCustomizeConfig(config, {
117
+ emitIntermediateState: [{
118
+ stateKey: "outline",
119
+ tool: "set_outline",
120
+ toolArgument: "outline"
121
+ }],
122
+ });
123
+ const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(messages, modifiedConfig);
124
+ ```
125
+ ## 🏆 Featured Examples
126
+
127
+ <p align="center">
128
+ <a href="https://www.copilotkit.ai/examples/form-filling-copilot">
129
+ <img src="https://github.com/user-attachments/assets/874da84a-67ff-47fa-a6b4-cbc3c65eb704" width="300" style="border-radius: 16px;" />
130
+ </a>
131
+ <a href="https://www.copilotkit.ai/examples/state-machine-copilot">
132
+ <img src="https://github.com/user-attachments/assets/0b5e45b3-2704-4678-82dc-2f3e1c58e2dd" width="300" style="border-radius: 16px;" />
133
+ </a>
134
+ <a href="https://www.copilotkit.ai/examples/chat-with-your-data">
135
+ <img src="https://github.com/user-attachments/assets/0fed66be-a4c2-4093-8eab-75c0b27a62f6" width="300" style="border-radius: 16px;" />
136
+ </a>
137
+ </p>
43
138
 
44
139
  # Documentation
45
140
 
@@ -17,6 +17,87 @@ function actionParametersToJsonSchema(actionParameters) {
17
17
  required: requiredParameterNames
18
18
  };
19
19
  }
20
+ function jsonSchemaToActionParameters(jsonSchema) {
21
+ if (jsonSchema.type !== "object" || !jsonSchema.properties) {
22
+ return [];
23
+ }
24
+ const parameters = [];
25
+ const requiredFields = jsonSchema.required || [];
26
+ for (const [name, schema] of Object.entries(jsonSchema.properties)) {
27
+ const parameter = convertJsonSchemaToParameter(name, schema, requiredFields.includes(name));
28
+ parameters.push(parameter);
29
+ }
30
+ return parameters;
31
+ }
32
+ function convertJsonSchemaToParameter(name, schema, isRequired) {
33
+ const baseParameter = {
34
+ name,
35
+ description: schema.description
36
+ };
37
+ if (!isRequired) {
38
+ baseParameter.required = false;
39
+ }
40
+ switch (schema.type) {
41
+ case "string":
42
+ return {
43
+ ...baseParameter,
44
+ type: "string",
45
+ ...schema.enum && { enum: schema.enum }
46
+ };
47
+ case "number":
48
+ case "boolean":
49
+ return {
50
+ ...baseParameter,
51
+ type: schema.type
52
+ };
53
+ case "object":
54
+ if (schema.properties) {
55
+ const attributes = [];
56
+ const requiredFields = schema.required || [];
57
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
58
+ attributes.push(
59
+ convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName))
60
+ );
61
+ }
62
+ return {
63
+ ...baseParameter,
64
+ type: "object",
65
+ attributes
66
+ };
67
+ }
68
+ return {
69
+ ...baseParameter,
70
+ type: "object"
71
+ };
72
+ case "array":
73
+ if (schema.items.type === "object" && "properties" in schema.items) {
74
+ const attributes = [];
75
+ const requiredFields = schema.items.required || [];
76
+ for (const [propName, propSchema] of Object.entries(schema.items.properties || {})) {
77
+ attributes.push(
78
+ convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName))
79
+ );
80
+ }
81
+ return {
82
+ ...baseParameter,
83
+ type: "object[]",
84
+ attributes
85
+ };
86
+ } else if (schema.items.type === "array") {
87
+ throw new Error("Nested arrays are not supported");
88
+ } else {
89
+ return {
90
+ ...baseParameter,
91
+ type: `${schema.items.type}[]`
92
+ };
93
+ }
94
+ default:
95
+ return {
96
+ ...baseParameter,
97
+ type: "string"
98
+ };
99
+ }
100
+ }
20
101
  function convertAttribute(attribute) {
21
102
  var _a, _b, _c;
22
103
  switch (attribute.type) {
@@ -107,6 +188,7 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
107
188
 
108
189
  export {
109
190
  actionParametersToJsonSchema,
191
+ jsonSchemaToActionParameters,
110
192
  convertJsonSchemaToZodSchema
111
193
  };
112
- //# sourceMappingURL=chunk-JP2M4U4G.mjs.map
194
+ //# sourceMappingURL=chunk-2KQ6HEWZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(name, schema, requiredFields.includes(name));\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(schema.properties)) {\n attributes.push(\n convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName)),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(schema.items.properties || {})) {\n attributes.push(\n convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName)),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAuCX,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI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