@copilotkit/shared 0.0.0-main-20260220223427 → 0.0.0-main-20260403195251
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/CHANGELOG.md +117 -1
- package/dist/constants/index.cjs +5 -0
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +4 -1
- package/dist/constants/index.d.cts.map +1 -1
- package/dist/constants/index.d.mts +4 -1
- package/dist/constants/index.d.mts.map +1 -1
- package/dist/constants/index.d.ts +11 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.mjs +4 -1
- package/dist/constants/index.mjs.map +1 -1
- package/dist/finalize-events.cjs +106 -0
- package/dist/finalize-events.cjs.map +1 -0
- package/dist/finalize-events.d.cts +11 -0
- package/dist/finalize-events.d.cts.map +1 -0
- package/dist/finalize-events.d.mts +11 -0
- package/dist/finalize-events.d.mts.map +1 -0
- package/dist/finalize-events.d.ts +11 -0
- package/dist/finalize-events.d.ts.map +1 -0
- package/dist/finalize-events.mjs +105 -0
- package/dist/finalize-events.mjs.map +1 -0
- package/dist/index.cjs +34 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +23 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +24 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +299 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.d.ts +5 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.mjs +6 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +29 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.d.cts +32 -0
- package/dist/standard-schema.d.cts.map +1 -0
- package/dist/standard-schema.d.mts +32 -0
- package/dist/standard-schema.d.mts.map +1 -0
- package/dist/standard-schema.d.ts +32 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/standard-schema.mjs +28 -0
- package/dist/standard-schema.mjs.map +1 -0
- package/dist/telemetry/events.d.cts +0 -8
- package/dist/telemetry/events.d.cts.map +1 -1
- package/dist/telemetry/events.d.mts +0 -8
- package/dist/telemetry/events.d.mts.map +1 -1
- package/dist/telemetry/events.d.ts +39 -0
- package/dist/telemetry/events.d.ts.map +1 -0
- package/dist/telemetry/telemetry-client.d.ts +48 -0
- package/dist/telemetry/telemetry-client.d.ts.map +1 -0
- package/dist/transcription-errors.cjs +84 -0
- package/dist/transcription-errors.cjs.map +1 -0
- package/dist/transcription-errors.d.cts +52 -0
- package/dist/transcription-errors.d.cts.map +1 -0
- package/dist/transcription-errors.d.mts +52 -0
- package/dist/transcription-errors.d.mts.map +1 -0
- package/dist/transcription-errors.d.ts +52 -0
- package/dist/transcription-errors.d.ts.map +1 -0
- package/dist/transcription-errors.mjs +82 -0
- package/dist/transcription-errors.mjs.map +1 -0
- package/dist/types/action.d.ts +59 -0
- package/dist/types/action.d.ts.map +1 -0
- package/dist/types/copilot-cloud-config.d.ts +15 -0
- package/dist/types/copilot-cloud-config.d.ts.map +1 -0
- package/dist/types/error.d.ts +57 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/message.d.cts +1 -1
- package/dist/types/message.d.mts +1 -1
- package/dist/types/message.d.ts +31 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/openai-assistant.d.ts +55 -0
- package/dist/types/openai-assistant.d.ts.map +1 -0
- package/dist/types/utility.d.ts +6 -0
- package/dist/types/utility.d.ts.map +1 -0
- package/dist/utils/conditions.d.ts +31 -0
- package/dist/utils/conditions.d.ts.map +1 -0
- package/dist/utils/console-styling.d.ts +65 -0
- package/dist/utils/console-styling.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +312 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/index.cjs +49 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +24 -2
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +24 -2
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.d.ts +53 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.mjs +45 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +4 -0
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.d.ts +36 -0
- package/dist/utils/json-schema.d.ts.map +1 -0
- package/dist/utils/json-schema.mjs +4 -0
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/random-id.d.ts +8 -0
- package/dist/utils/random-id.d.ts.map +1 -0
- package/dist/utils/requests.d.ts +12 -0
- package/dist/utils/requests.d.ts.map +1 -0
- package/dist/utils/types.cjs +9 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +12 -1
- package/dist/utils/types.d.cts.map +1 -1
- package/dist/utils/types.d.mts +12 -1
- package/dist/utils/types.d.mts.map +1 -1
- package/dist/utils/types.d.ts +33 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.mjs +7 -0
- package/dist/utils/types.mjs.map +1 -0
- package/package.json +37 -31
- package/src/__tests__/standard-schema-types.test.ts +144 -0
- package/src/__tests__/standard-schema.test.ts +267 -0
- package/src/__tests__/zod-regression.test.ts +319 -0
- package/src/constants/index.ts +5 -0
- package/src/finalize-events.ts +154 -0
- package/src/index.ts +48 -0
- package/src/logger.ts +1 -0
- package/src/standard-schema.ts +76 -0
- package/src/telemetry/events.ts +0 -9
- package/src/transcription-errors.ts +99 -0
- package/src/types/message.ts +1 -1
- package/src/utils/{json-schema.test.ts → __tests__/json-schema.test.ts} +21 -2
- package/src/utils/index.ts +58 -0
- package/src/utils/json-schema.ts +6 -0
- package/src/utils/types.ts +21 -0
- package/src/utils.test.ts +66 -0
- package/tsconfig.json +9 -1
- package/tsdown.config.ts +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,110 @@
|
|
|
1
1
|
# @copilotkit/shared
|
|
2
2
|
|
|
3
|
-
## 0.0.0-main-
|
|
3
|
+
## 0.0.0-main-20260403195251
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1ceb963: refactor: consolidate V1/V2 packages into flat @copilotkit/\* structure
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 52a9322: Fixing license warnings, barrel export and typing
|
|
12
|
+
|
|
13
|
+
## 1.55.0-next.8
|
|
14
|
+
|
|
15
|
+
## 1.55.0-next.7
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 1ceb963: refactor: consolidate V1/V2 packages into flat @copilotkit/\* structure
|
|
20
|
+
|
|
21
|
+
## 1.54.1-next.6
|
|
22
|
+
|
|
23
|
+
## 1.54.1-next.5
|
|
24
|
+
|
|
25
|
+
## 1.54.1-next.4
|
|
26
|
+
|
|
27
|
+
## 1.54.1-next.3
|
|
28
|
+
|
|
29
|
+
## 1.54.1-next.2
|
|
30
|
+
|
|
31
|
+
## 1.54.1-next.1
|
|
32
|
+
|
|
33
|
+
## 1.54.1-next.0
|
|
34
|
+
|
|
35
|
+
## 1.54.0
|
|
36
|
+
|
|
37
|
+
## 1.54.0-next.9
|
|
38
|
+
|
|
39
|
+
## 1.54.0-next.8
|
|
40
|
+
|
|
41
|
+
## 1.54.0-next.7
|
|
42
|
+
|
|
43
|
+
## 1.54.0-next.6
|
|
44
|
+
|
|
45
|
+
## 1.54.0-next.5
|
|
46
|
+
|
|
47
|
+
## 1.54.0-next.4
|
|
48
|
+
|
|
49
|
+
## 1.54.0-next.3
|
|
50
|
+
|
|
51
|
+
## 1.53.1-next.2
|
|
52
|
+
|
|
53
|
+
## 1.53.1-next.1
|
|
54
|
+
|
|
55
|
+
## 1.53.1-next.0
|
|
56
|
+
|
|
57
|
+
## 1.53.0
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- 1510f64: feat: enable mcp and a2ui middleware directly from copilotkit runtime
|
|
62
|
+
- bf1fc6f: fix: `convertJsonSchemaToZodSchema` drops enum constraints
|
|
63
|
+
|
|
64
|
+
## 1.53.0-next.6
|
|
65
|
+
|
|
66
|
+
## 1.53.0-next.5
|
|
67
|
+
|
|
68
|
+
## 1.52.2-next.4
|
|
69
|
+
|
|
70
|
+
## 1.52.2-next.3
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- 1510f64: feat: enable mcp and a2ui middleware directly from copilotkit runtime
|
|
75
|
+
|
|
76
|
+
## 1.52.2-next.2
|
|
77
|
+
|
|
78
|
+
## 1.52.2-next.1
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- bf1fc6f: fix: `convertJsonSchemaToZodSchema` drops enum constraints
|
|
83
|
+
|
|
84
|
+
## 1.52.2-next.0
|
|
85
|
+
|
|
86
|
+
## 1.52.1
|
|
87
|
+
|
|
88
|
+
## 1.52.1-next.1
|
|
89
|
+
|
|
90
|
+
## 1.52.1-next.0
|
|
91
|
+
|
|
92
|
+
## 1.52.0
|
|
4
93
|
|
|
5
94
|
### Patch Changes
|
|
6
95
|
|
|
7
96
|
- ef0f539: Add reasoning support and default components for reasoning messages
|
|
8
97
|
|
|
98
|
+
## 1.52.0-next.8
|
|
99
|
+
|
|
100
|
+
## 1.52.0-next.7
|
|
101
|
+
|
|
102
|
+
## 1.52.0-next.6
|
|
103
|
+
|
|
104
|
+
## 1.52.0-next.5
|
|
105
|
+
|
|
106
|
+
## 1.51.5-next.4
|
|
107
|
+
|
|
9
108
|
## 1.51.5-next.3
|
|
10
109
|
|
|
11
110
|
## 1.51.5-next.2
|
|
@@ -336,12 +435,14 @@
|
|
|
336
435
|
agentic runtimes we acquired tech-debt that, with this PR, is being alleviated.
|
|
337
436
|
|
|
338
437
|
As such, the following features have been updated to be completely functional with Headless UI.
|
|
438
|
+
|
|
339
439
|
- Generative UI
|
|
340
440
|
- Suggestions
|
|
341
441
|
- Agentic Generative UI
|
|
342
442
|
- Interrupts
|
|
343
443
|
|
|
344
444
|
In addition, a variety of QOL changes have been made.
|
|
445
|
+
|
|
345
446
|
- New AG-UI based message types
|
|
346
447
|
- Inline code rendering is fixed
|
|
347
448
|
|
|
@@ -353,15 +454,19 @@
|
|
|
353
454
|
- 6d1de58: - fix: address issues that would cause headless UI breaking changes in the next release
|
|
354
455
|
|
|
355
456
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
457
|
+
|
|
356
458
|
- fix: more fixes addressing breaking changes in new Headless UI
|
|
357
459
|
|
|
358
460
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
461
|
+
|
|
359
462
|
- chore: address linting issues
|
|
360
463
|
|
|
361
464
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
465
|
+
|
|
362
466
|
- chore: fixing branding and docs
|
|
363
467
|
|
|
364
468
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
469
|
+
|
|
365
470
|
- chore: more docs fixing
|
|
366
471
|
|
|
367
472
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
@@ -379,15 +484,19 @@
|
|
|
379
484
|
- 6d1de58: - fix: address issues that would cause headless UI breaking changes in the next release
|
|
380
485
|
|
|
381
486
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
487
|
+
|
|
382
488
|
- fix: more fixes addressing breaking changes in new Headless UI
|
|
383
489
|
|
|
384
490
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
491
|
+
|
|
385
492
|
- chore: address linting issues
|
|
386
493
|
|
|
387
494
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
495
|
+
|
|
388
496
|
- chore: fixing branding and docs
|
|
389
497
|
|
|
390
498
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
499
|
+
|
|
391
500
|
- chore: more docs fixing
|
|
392
501
|
|
|
393
502
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
@@ -424,12 +533,14 @@
|
|
|
424
533
|
agentic runtimes we acquired tech-debt that, with this PR, is being alleviated.
|
|
425
534
|
|
|
426
535
|
As such, the following features have been updated to be completely functional with Headless UI.
|
|
536
|
+
|
|
427
537
|
- Generative UI
|
|
428
538
|
- Suggestions
|
|
429
539
|
- Agentic Generative UI
|
|
430
540
|
- Interrupts
|
|
431
541
|
|
|
432
542
|
In addition, a variety of QOL changes have been made.
|
|
543
|
+
|
|
433
544
|
- New AG-UI based message types
|
|
434
545
|
- Inline code rendering is fixed
|
|
435
546
|
|
|
@@ -460,6 +571,7 @@
|
|
|
460
571
|
### Patch Changes
|
|
461
572
|
|
|
462
573
|
- fac89c2: - refactor: rename onTrace to onError throughout codebase
|
|
574
|
+
|
|
463
575
|
- Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
|
|
464
576
|
|
|
465
577
|
- 9169ad7: - feat: add onTrace handler for runtime and UI error/event tracking
|
|
@@ -1092,6 +1204,7 @@
|
|
|
1092
1204
|
- e16d95e: New prerelease
|
|
1093
1205
|
- 1721cbd: Add convertActionsToDynamicStructuredTools to sdk-js
|
|
1094
1206
|
- CopilotKit Core:
|
|
1207
|
+
|
|
1095
1208
|
- Improved error messages and overall logs
|
|
1096
1209
|
- `useCopilotAction.renderAndAwait` renamed to `.renderAndAwaitForResponse` (backwards compatible, will be deprecated in the future)
|
|
1097
1210
|
- Improved scrolling behavior. It is now possible to scroll up during LLM response generation
|
|
@@ -1099,6 +1212,7 @@
|
|
|
1099
1212
|
- Updated interfaces for better developer ergonomics
|
|
1100
1213
|
|
|
1101
1214
|
CoAgents:
|
|
1215
|
+
|
|
1102
1216
|
- Renamed `remoteActions` to `remoteEndpoints` (backwards compatible, will be deprecated in the future)
|
|
1103
1217
|
- Support for LangGraph Platform in Remote Endpoints
|
|
1104
1218
|
- LangGraph JS Support for CoAgents (locally via `langgraph dev`, `langgraph up` or deployed to LangGraph Platform)
|
|
@@ -1106,6 +1220,7 @@
|
|
|
1106
1220
|
- Enhanced state management and message handling
|
|
1107
1221
|
|
|
1108
1222
|
CopilotKid Back-end SDK:
|
|
1223
|
+
|
|
1109
1224
|
- Released a whole-new `@copilotkit/sdk-js` for building agents with LangGraph JS Support
|
|
1110
1225
|
|
|
1111
1226
|
- 8d0144f: bump
|
|
@@ -1446,6 +1561,7 @@ CopilotKid Back-end SDK:
|
|
|
1446
1561
|
### Major Changes
|
|
1447
1562
|
|
|
1448
1563
|
- b6a4b6eb: V1.0 Release Candidate
|
|
1564
|
+
|
|
1449
1565
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
1450
1566
|
- Support for Copilot Cloud
|
|
1451
1567
|
- Generative UI
|
package/dist/constants/index.cjs
CHANGED
|
@@ -4,10 +4,15 @@ const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
|
4
4
|
const COPILOT_CLOUD_VERSION = "v1";
|
|
5
5
|
const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
|
|
6
6
|
const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
7
|
+
const DEFAULT_AGENT_ID = "default";
|
|
8
|
+
/** Phoenix channel event name used for all AG-UI events. */
|
|
9
|
+
const AG_UI_CHANNEL_EVENT = "ag-ui";
|
|
7
10
|
|
|
8
11
|
//#endregion
|
|
12
|
+
exports.AG_UI_CHANNEL_EVENT = AG_UI_CHANNEL_EVENT;
|
|
9
13
|
exports.COPILOT_CLOUD_API_URL = COPILOT_CLOUD_API_URL;
|
|
10
14
|
exports.COPILOT_CLOUD_CHAT_URL = COPILOT_CLOUD_CHAT_URL;
|
|
11
15
|
exports.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = COPILOT_CLOUD_PUBLIC_API_KEY_HEADER;
|
|
12
16
|
exports.COPILOT_CLOUD_VERSION = COPILOT_CLOUD_VERSION;
|
|
17
|
+
exports.DEFAULT_AGENT_ID = DEFAULT_AGENT_ID;
|
|
13
18
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/constants/index.ts"],"sourcesContent":["export const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER =\n \"X-CopilotCloud-Public-Api-Key\";\n"],"mappings":";;AAAA,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,yBAAyB,GAAG,sBAAsB,cAAc;AAC7E,MAAa,sCACX"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/constants/index.ts"],"sourcesContent":["export const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER =\n \"X-CopilotCloud-Public-Api-Key\";\n\nexport const DEFAULT_AGENT_ID = \"default\";\n\n/** Phoenix channel event name used for all AG-UI events. */\nexport const AG_UI_CHANNEL_EVENT = \"ag-ui\";\n"],"mappings":";;AAAA,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,yBAAyB,GAAG,sBAAsB,cAAc;AAC7E,MAAa,sCACX;AAEF,MAAa,mBAAmB;;AAGhC,MAAa,sBAAsB"}
|
|
@@ -3,6 +3,9 @@ declare const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
|
3
3
|
declare const COPILOT_CLOUD_VERSION = "v1";
|
|
4
4
|
declare const COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
5
5
|
declare const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
6
|
+
declare const DEFAULT_AGENT_ID = "default";
|
|
7
|
+
/** Phoenix channel event name used for all AG-UI events. */
|
|
8
|
+
declare const AG_UI_CHANNEL_EVENT = "ag-ui";
|
|
6
9
|
//#endregion
|
|
7
|
-
export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION };
|
|
10
|
+
export { AG_UI_CHANNEL_EVENT, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, DEFAULT_AGENT_ID };
|
|
8
11
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/constants/index.ts"],"mappings":";cAAa,qBAAA;AAAA,cACA,qBAAA;AAAA,cACA,sBAAA;AAAA,cACA,mCAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/constants/index.ts"],"mappings":";cAAa,qBAAA;AAAA,cACA,qBAAA;AAAA,cACA,sBAAA;AAAA,cACA,mCAAA;AAAA,cAGA,gBAAA;;cAGA,mBAAA"}
|
|
@@ -3,6 +3,9 @@ declare const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
|
3
3
|
declare const COPILOT_CLOUD_VERSION = "v1";
|
|
4
4
|
declare const COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
5
5
|
declare const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
6
|
+
declare const DEFAULT_AGENT_ID = "default";
|
|
7
|
+
/** Phoenix channel event name used for all AG-UI events. */
|
|
8
|
+
declare const AG_UI_CHANNEL_EVENT = "ag-ui";
|
|
6
9
|
//#endregion
|
|
7
|
-
export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION };
|
|
10
|
+
export { AG_UI_CHANNEL_EVENT, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, DEFAULT_AGENT_ID };
|
|
8
11
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/constants/index.ts"],"mappings":";cAAa,qBAAA;AAAA,cACA,qBAAA;AAAA,cACA,sBAAA;AAAA,cACA,mCAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/constants/index.ts"],"mappings":";cAAa,qBAAA;AAAA,cACA,qBAAA;AAAA,cACA,sBAAA;AAAA,cACA,mCAAA;AAAA,cAGA,gBAAA;;cAGA,mBAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/constants/index.d.ts
|
|
2
|
+
declare const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
3
|
+
declare const COPILOT_CLOUD_VERSION = "v1";
|
|
4
|
+
declare const COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
5
|
+
declare const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
6
|
+
declare const DEFAULT_AGENT_ID = "default";
|
|
7
|
+
/** Phoenix channel event name used for all AG-UI events. */
|
|
8
|
+
declare const AG_UI_CHANNEL_EVENT = "ag-ui";
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AG_UI_CHANNEL_EVENT, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, DEFAULT_AGENT_ID };
|
|
11
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/constants/index.ts"],"mappings":";cAAa,qBAAA;AAAA,cACA,qBAAA;AAAA,cACA,sBAAA;AAAA,cACA,mCAAA;AAAA,cAGA,gBAAA;;cAGA,mBAAA"}
|
package/dist/constants/index.mjs
CHANGED
|
@@ -3,7 +3,10 @@ const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
|
3
3
|
const COPILOT_CLOUD_VERSION = "v1";
|
|
4
4
|
const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
|
|
5
5
|
const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
6
|
+
const DEFAULT_AGENT_ID = "default";
|
|
7
|
+
/** Phoenix channel event name used for all AG-UI events. */
|
|
8
|
+
const AG_UI_CHANNEL_EVENT = "ag-ui";
|
|
6
9
|
|
|
7
10
|
//#endregion
|
|
8
|
-
export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION };
|
|
11
|
+
export { AG_UI_CHANNEL_EVENT, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION, DEFAULT_AGENT_ID };
|
|
9
12
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/constants/index.ts"],"sourcesContent":["export const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER =\n \"X-CopilotCloud-Public-Api-Key\";\n"],"mappings":";AAAA,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,yBAAyB,GAAG,sBAAsB,cAAc;AAC7E,MAAa,sCACX"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/constants/index.ts"],"sourcesContent":["export const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER =\n \"X-CopilotCloud-Public-Api-Key\";\n\nexport const DEFAULT_AGENT_ID = \"default\";\n\n/** Phoenix channel event name used for all AG-UI events. */\nexport const AG_UI_CHANNEL_EVENT = \"ag-ui\";\n"],"mappings":";AAAA,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,yBAAyB,GAAG,sBAAsB,cAAc;AAC7E,MAAa,sCACX;AAEF,MAAa,mBAAmB;;AAGhC,MAAa,sBAAsB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_random_id = require('./utils/random-id.cjs');
|
|
3
|
+
let _ag_ui_client = require("@ag-ui/client");
|
|
4
|
+
|
|
5
|
+
//#region src/finalize-events.ts
|
|
6
|
+
const defaultStopMessage = "Run stopped by user";
|
|
7
|
+
const defaultAbruptEndMessage = "Run ended without emitting a terminal event";
|
|
8
|
+
function finalizeRunEvents(events, options = {}) {
|
|
9
|
+
const { stopRequested = false, interruptionMessage } = options;
|
|
10
|
+
const resolvedStopMessage = interruptionMessage ?? defaultStopMessage;
|
|
11
|
+
const resolvedAbruptMessage = interruptionMessage && interruptionMessage !== defaultStopMessage ? interruptionMessage : defaultAbruptEndMessage;
|
|
12
|
+
const appended = [];
|
|
13
|
+
const openMessageIds = /* @__PURE__ */ new Set();
|
|
14
|
+
const openToolCalls = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const event of events) switch (event.type) {
|
|
16
|
+
case _ag_ui_client.EventType.TEXT_MESSAGE_START: {
|
|
17
|
+
const messageId = event.messageId;
|
|
18
|
+
if (typeof messageId === "string") openMessageIds.add(messageId);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case _ag_ui_client.EventType.TEXT_MESSAGE_END: {
|
|
22
|
+
const messageId = event.messageId;
|
|
23
|
+
if (typeof messageId === "string") openMessageIds.delete(messageId);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case _ag_ui_client.EventType.TOOL_CALL_START: {
|
|
27
|
+
const toolCallId = event.toolCallId;
|
|
28
|
+
if (typeof toolCallId === "string") openToolCalls.set(toolCallId, {
|
|
29
|
+
hasEnd: false,
|
|
30
|
+
hasResult: false
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case _ag_ui_client.EventType.TOOL_CALL_END: {
|
|
35
|
+
const toolCallId = event.toolCallId;
|
|
36
|
+
const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
|
|
37
|
+
if (info) info.hasEnd = true;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case _ag_ui_client.EventType.TOOL_CALL_RESULT: {
|
|
41
|
+
const toolCallId = event.toolCallId;
|
|
42
|
+
const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
|
|
43
|
+
if (info) info.hasResult = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
default: break;
|
|
47
|
+
}
|
|
48
|
+
const hasRunFinished = events.some((event) => event.type === _ag_ui_client.EventType.RUN_FINISHED);
|
|
49
|
+
const hasRunError = events.some((event) => event.type === _ag_ui_client.EventType.RUN_ERROR);
|
|
50
|
+
const terminalEventMissing = !(hasRunFinished || hasRunError);
|
|
51
|
+
for (const messageId of openMessageIds) {
|
|
52
|
+
const endEvent = {
|
|
53
|
+
type: _ag_ui_client.EventType.TEXT_MESSAGE_END,
|
|
54
|
+
messageId
|
|
55
|
+
};
|
|
56
|
+
events.push(endEvent);
|
|
57
|
+
appended.push(endEvent);
|
|
58
|
+
}
|
|
59
|
+
for (const [toolCallId, info] of openToolCalls) {
|
|
60
|
+
if (!info.hasEnd) {
|
|
61
|
+
const endEvent = {
|
|
62
|
+
type: _ag_ui_client.EventType.TOOL_CALL_END,
|
|
63
|
+
toolCallId
|
|
64
|
+
};
|
|
65
|
+
events.push(endEvent);
|
|
66
|
+
appended.push(endEvent);
|
|
67
|
+
}
|
|
68
|
+
if (terminalEventMissing && !info.hasResult) {
|
|
69
|
+
const resultEvent = {
|
|
70
|
+
type: _ag_ui_client.EventType.TOOL_CALL_RESULT,
|
|
71
|
+
toolCallId,
|
|
72
|
+
messageId: `${toolCallId ?? require_random_id.randomUUID()}-result`,
|
|
73
|
+
role: "tool",
|
|
74
|
+
content: JSON.stringify(stopRequested ? {
|
|
75
|
+
status: "stopped",
|
|
76
|
+
reason: "stop_requested",
|
|
77
|
+
message: resolvedStopMessage
|
|
78
|
+
} : {
|
|
79
|
+
status: "error",
|
|
80
|
+
reason: "missing_terminal_event",
|
|
81
|
+
message: resolvedAbruptMessage
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
events.push(resultEvent);
|
|
85
|
+
appended.push(resultEvent);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (terminalEventMissing) if (stopRequested) {
|
|
89
|
+
const finishedEvent = { type: _ag_ui_client.EventType.RUN_FINISHED };
|
|
90
|
+
events.push(finishedEvent);
|
|
91
|
+
appended.push(finishedEvent);
|
|
92
|
+
} else {
|
|
93
|
+
const errorEvent = {
|
|
94
|
+
type: _ag_ui_client.EventType.RUN_ERROR,
|
|
95
|
+
message: resolvedAbruptMessage,
|
|
96
|
+
code: "INCOMPLETE_STREAM"
|
|
97
|
+
};
|
|
98
|
+
events.push(errorEvent);
|
|
99
|
+
appended.push(errorEvent);
|
|
100
|
+
}
|
|
101
|
+
return appended;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
exports.finalizeRunEvents = finalizeRunEvents;
|
|
106
|
+
//# sourceMappingURL=finalize-events.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize-events.cjs","names":["EventType","randomUUID"],"sources":["../src/finalize-events.ts"],"sourcesContent":["import { BaseEvent, EventType, RunErrorEvent } from \"@ag-ui/client\";\nimport { randomUUID } from \"./utils\";\n\ninterface FinalizeRunOptions {\n stopRequested?: boolean;\n interruptionMessage?: string;\n}\n\nconst defaultStopMessage = \"Run stopped by user\";\nconst defaultAbruptEndMessage = \"Run ended without emitting a terminal event\";\n\nexport function finalizeRunEvents(\n events: BaseEvent[],\n options: FinalizeRunOptions = {},\n): BaseEvent[] {\n const { stopRequested = false, interruptionMessage } = options;\n\n const resolvedStopMessage = interruptionMessage ?? defaultStopMessage;\n const resolvedAbruptMessage =\n interruptionMessage && interruptionMessage !== defaultStopMessage\n ? interruptionMessage\n : defaultAbruptEndMessage;\n\n const appended: BaseEvent[] = [];\n\n const openMessageIds = new Set<string>();\n const openToolCalls = new Map<\n string,\n {\n hasEnd: boolean;\n hasResult: boolean;\n }\n >();\n\n for (const event of events) {\n switch (event.type) {\n case EventType.TEXT_MESSAGE_START: {\n const messageId = (event as { messageId?: string }).messageId;\n if (typeof messageId === \"string\") {\n openMessageIds.add(messageId);\n }\n break;\n }\n case EventType.TEXT_MESSAGE_END: {\n const messageId = (event as { messageId?: string }).messageId;\n if (typeof messageId === \"string\") {\n openMessageIds.delete(messageId);\n }\n break;\n }\n case EventType.TOOL_CALL_START: {\n const toolCallId = (event as { toolCallId?: string }).toolCallId;\n if (typeof toolCallId === \"string\") {\n openToolCalls.set(toolCallId, {\n hasEnd: false,\n hasResult: false,\n });\n }\n break;\n }\n case EventType.TOOL_CALL_END: {\n const toolCallId = (event as { toolCallId?: string }).toolCallId;\n const info = toolCallId ? openToolCalls.get(toolCallId) : undefined;\n if (info) {\n info.hasEnd = true;\n }\n break;\n }\n case EventType.TOOL_CALL_RESULT: {\n const toolCallId = (event as { toolCallId?: string }).toolCallId;\n const info = toolCallId ? openToolCalls.get(toolCallId) : undefined;\n if (info) {\n info.hasResult = true;\n }\n break;\n }\n default:\n break;\n }\n }\n\n const hasRunFinished = events.some(\n (event) => event.type === EventType.RUN_FINISHED,\n );\n const hasRunError = events.some(\n (event) => event.type === EventType.RUN_ERROR,\n );\n const hasTerminalEvent = hasRunFinished || hasRunError;\n const terminalEventMissing = !hasTerminalEvent;\n\n for (const messageId of openMessageIds) {\n const endEvent = {\n type: EventType.TEXT_MESSAGE_END,\n messageId,\n } as BaseEvent;\n events.push(endEvent);\n appended.push(endEvent);\n }\n\n for (const [toolCallId, info] of openToolCalls) {\n if (!info.hasEnd) {\n const endEvent = {\n type: EventType.TOOL_CALL_END,\n toolCallId,\n } as BaseEvent;\n events.push(endEvent);\n appended.push(endEvent);\n }\n\n if (terminalEventMissing && !info.hasResult) {\n const resultEvent = {\n type: EventType.TOOL_CALL_RESULT,\n toolCallId,\n messageId: `${toolCallId ?? randomUUID()}-result`,\n role: \"tool\",\n content: JSON.stringify(\n stopRequested\n ? {\n status: \"stopped\",\n reason: \"stop_requested\",\n message: resolvedStopMessage,\n }\n : {\n status: \"error\",\n reason: \"missing_terminal_event\",\n message: resolvedAbruptMessage,\n },\n ),\n } as BaseEvent;\n events.push(resultEvent);\n appended.push(resultEvent);\n }\n }\n\n if (terminalEventMissing) {\n if (stopRequested) {\n const finishedEvent = {\n type: EventType.RUN_FINISHED,\n } as BaseEvent;\n events.push(finishedEvent);\n appended.push(finishedEvent);\n } else {\n const errorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: resolvedAbruptMessage,\n code: \"INCOMPLETE_STREAM\",\n };\n events.push(errorEvent);\n appended.push(errorEvent);\n }\n }\n\n return appended;\n}\n"],"mappings":";;;;;AAQA,MAAM,qBAAqB;AAC3B,MAAM,0BAA0B;AAEhC,SAAgB,kBACd,QACA,UAA8B,EAAE,EACnB;CACb,MAAM,EAAE,gBAAgB,OAAO,wBAAwB;CAEvD,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,wBACJ,uBAAuB,wBAAwB,qBAC3C,sBACA;CAEN,MAAM,WAAwB,EAAE;CAEhC,MAAM,iCAAiB,IAAI,KAAa;CACxC,MAAM,gCAAgB,IAAI,KAMvB;AAEH,MAAK,MAAM,SAAS,OAClB,SAAQ,MAAM,MAAd;EACE,KAAKA,wBAAU,oBAAoB;GACjC,MAAM,YAAa,MAAiC;AACpD,OAAI,OAAO,cAAc,SACvB,gBAAe,IAAI,UAAU;AAE/B;;EAEF,KAAKA,wBAAU,kBAAkB;GAC/B,MAAM,YAAa,MAAiC;AACpD,OAAI,OAAO,cAAc,SACvB,gBAAe,OAAO,UAAU;AAElC;;EAEF,KAAKA,wBAAU,iBAAiB;GAC9B,MAAM,aAAc,MAAkC;AACtD,OAAI,OAAO,eAAe,SACxB,eAAc,IAAI,YAAY;IAC5B,QAAQ;IACR,WAAW;IACZ,CAAC;AAEJ;;EAEF,KAAKA,wBAAU,eAAe;GAC5B,MAAM,aAAc,MAAkC;GACtD,MAAM,OAAO,aAAa,cAAc,IAAI,WAAW,GAAG;AAC1D,OAAI,KACF,MAAK,SAAS;AAEhB;;EAEF,KAAKA,wBAAU,kBAAkB;GAC/B,MAAM,aAAc,MAAkC;GACtD,MAAM,OAAO,aAAa,cAAc,IAAI,WAAW,GAAG;AAC1D,OAAI,KACF,MAAK,YAAY;AAEnB;;EAEF,QACE;;CAIN,MAAM,iBAAiB,OAAO,MAC3B,UAAU,MAAM,SAASA,wBAAU,aACrC;CACD,MAAM,cAAc,OAAO,MACxB,UAAU,MAAM,SAASA,wBAAU,UACrC;CAED,MAAM,uBAAuB,EADJ,kBAAkB;AAG3C,MAAK,MAAM,aAAa,gBAAgB;EACtC,MAAM,WAAW;GACf,MAAMA,wBAAU;GAChB;GACD;AACD,SAAO,KAAK,SAAS;AACrB,WAAS,KAAK,SAAS;;AAGzB,MAAK,MAAM,CAAC,YAAY,SAAS,eAAe;AAC9C,MAAI,CAAC,KAAK,QAAQ;GAChB,MAAM,WAAW;IACf,MAAMA,wBAAU;IAChB;IACD;AACD,UAAO,KAAK,SAAS;AACrB,YAAS,KAAK,SAAS;;AAGzB,MAAI,wBAAwB,CAAC,KAAK,WAAW;GAC3C,MAAM,cAAc;IAClB,MAAMA,wBAAU;IAChB;IACA,WAAW,GAAG,cAAcC,8BAAY,CAAC;IACzC,MAAM;IACN,SAAS,KAAK,UACZ,gBACI;KACE,QAAQ;KACR,QAAQ;KACR,SAAS;KACV,GACD;KACE,QAAQ;KACR,QAAQ;KACR,SAAS;KACV,CACN;IACF;AACD,UAAO,KAAK,YAAY;AACxB,YAAS,KAAK,YAAY;;;AAI9B,KAAI,qBACF,KAAI,eAAe;EACjB,MAAM,gBAAgB,EACpB,MAAMD,wBAAU,cACjB;AACD,SAAO,KAAK,cAAc;AAC1B,WAAS,KAAK,cAAc;QACvB;EACL,MAAM,aAA4B;GAChC,MAAMA,wBAAU;GAChB,SAAS;GACT,MAAM;GACP;AACD,SAAO,KAAK,WAAW;AACvB,WAAS,KAAK,WAAW;;AAI7B,QAAO"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseEvent } from "@ag-ui/client";
|
|
2
|
+
|
|
3
|
+
//#region src/finalize-events.d.ts
|
|
4
|
+
interface FinalizeRunOptions {
|
|
5
|
+
stopRequested?: boolean;
|
|
6
|
+
interruptionMessage?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function finalizeRunEvents(events: BaseEvent[], options?: FinalizeRunOptions): BaseEvent[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { finalizeRunEvents };
|
|
11
|
+
//# sourceMappingURL=finalize-events.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize-events.d.cts","names":[],"sources":["../src/finalize-events.ts"],"mappings":";;;UAGU,kBAAA;EACR,aAAA;EACA,mBAAA;AAAA;AAAA,iBAMc,iBAAA,CACd,MAAA,EAAQ,SAAA,IACR,OAAA,GAAS,kBAAA,GACR,SAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseEvent } from "@ag-ui/client";
|
|
2
|
+
|
|
3
|
+
//#region src/finalize-events.d.ts
|
|
4
|
+
interface FinalizeRunOptions {
|
|
5
|
+
stopRequested?: boolean;
|
|
6
|
+
interruptionMessage?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function finalizeRunEvents(events: BaseEvent[], options?: FinalizeRunOptions): BaseEvent[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { finalizeRunEvents };
|
|
11
|
+
//# sourceMappingURL=finalize-events.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize-events.d.mts","names":[],"sources":["../src/finalize-events.ts"],"mappings":";;;UAGU,kBAAA;EACR,aAAA;EACA,mBAAA;AAAA;AAAA,iBAMc,iBAAA,CACd,MAAA,EAAQ,SAAA,IACR,OAAA,GAAS,kBAAA,GACR,SAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseEvent } from "@ag-ui/client";
|
|
2
|
+
|
|
3
|
+
//#region src/finalize-events.d.ts
|
|
4
|
+
interface FinalizeRunOptions {
|
|
5
|
+
stopRequested?: boolean;
|
|
6
|
+
interruptionMessage?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function finalizeRunEvents(events: BaseEvent[], options?: FinalizeRunOptions): BaseEvent[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { finalizeRunEvents };
|
|
11
|
+
//# sourceMappingURL=finalize-events.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize-events.d.cts","names":[],"sources":["../src/finalize-events.ts"],"mappings":";;;UAGU,kBAAA;EACR,aAAA;EACA,mBAAA;AAAA;AAAA,iBAMc,iBAAA,CACd,MAAA,EAAQ,SAAA,IACR,OAAA,GAAS,kBAAA,GACR,SAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { randomUUID } from "./utils/random-id.mjs";
|
|
2
|
+
import { EventType } from "@ag-ui/client";
|
|
3
|
+
|
|
4
|
+
//#region src/finalize-events.ts
|
|
5
|
+
const defaultStopMessage = "Run stopped by user";
|
|
6
|
+
const defaultAbruptEndMessage = "Run ended without emitting a terminal event";
|
|
7
|
+
function finalizeRunEvents(events, options = {}) {
|
|
8
|
+
const { stopRequested = false, interruptionMessage } = options;
|
|
9
|
+
const resolvedStopMessage = interruptionMessage ?? defaultStopMessage;
|
|
10
|
+
const resolvedAbruptMessage = interruptionMessage && interruptionMessage !== defaultStopMessage ? interruptionMessage : defaultAbruptEndMessage;
|
|
11
|
+
const appended = [];
|
|
12
|
+
const openMessageIds = /* @__PURE__ */ new Set();
|
|
13
|
+
const openToolCalls = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const event of events) switch (event.type) {
|
|
15
|
+
case EventType.TEXT_MESSAGE_START: {
|
|
16
|
+
const messageId = event.messageId;
|
|
17
|
+
if (typeof messageId === "string") openMessageIds.add(messageId);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case EventType.TEXT_MESSAGE_END: {
|
|
21
|
+
const messageId = event.messageId;
|
|
22
|
+
if (typeof messageId === "string") openMessageIds.delete(messageId);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case EventType.TOOL_CALL_START: {
|
|
26
|
+
const toolCallId = event.toolCallId;
|
|
27
|
+
if (typeof toolCallId === "string") openToolCalls.set(toolCallId, {
|
|
28
|
+
hasEnd: false,
|
|
29
|
+
hasResult: false
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case EventType.TOOL_CALL_END: {
|
|
34
|
+
const toolCallId = event.toolCallId;
|
|
35
|
+
const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
|
|
36
|
+
if (info) info.hasEnd = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case EventType.TOOL_CALL_RESULT: {
|
|
40
|
+
const toolCallId = event.toolCallId;
|
|
41
|
+
const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
|
|
42
|
+
if (info) info.hasResult = true;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
default: break;
|
|
46
|
+
}
|
|
47
|
+
const hasRunFinished = events.some((event) => event.type === EventType.RUN_FINISHED);
|
|
48
|
+
const hasRunError = events.some((event) => event.type === EventType.RUN_ERROR);
|
|
49
|
+
const terminalEventMissing = !(hasRunFinished || hasRunError);
|
|
50
|
+
for (const messageId of openMessageIds) {
|
|
51
|
+
const endEvent = {
|
|
52
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
53
|
+
messageId
|
|
54
|
+
};
|
|
55
|
+
events.push(endEvent);
|
|
56
|
+
appended.push(endEvent);
|
|
57
|
+
}
|
|
58
|
+
for (const [toolCallId, info] of openToolCalls) {
|
|
59
|
+
if (!info.hasEnd) {
|
|
60
|
+
const endEvent = {
|
|
61
|
+
type: EventType.TOOL_CALL_END,
|
|
62
|
+
toolCallId
|
|
63
|
+
};
|
|
64
|
+
events.push(endEvent);
|
|
65
|
+
appended.push(endEvent);
|
|
66
|
+
}
|
|
67
|
+
if (terminalEventMissing && !info.hasResult) {
|
|
68
|
+
const resultEvent = {
|
|
69
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
70
|
+
toolCallId,
|
|
71
|
+
messageId: `${toolCallId ?? randomUUID()}-result`,
|
|
72
|
+
role: "tool",
|
|
73
|
+
content: JSON.stringify(stopRequested ? {
|
|
74
|
+
status: "stopped",
|
|
75
|
+
reason: "stop_requested",
|
|
76
|
+
message: resolvedStopMessage
|
|
77
|
+
} : {
|
|
78
|
+
status: "error",
|
|
79
|
+
reason: "missing_terminal_event",
|
|
80
|
+
message: resolvedAbruptMessage
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
events.push(resultEvent);
|
|
84
|
+
appended.push(resultEvent);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (terminalEventMissing) if (stopRequested) {
|
|
88
|
+
const finishedEvent = { type: EventType.RUN_FINISHED };
|
|
89
|
+
events.push(finishedEvent);
|
|
90
|
+
appended.push(finishedEvent);
|
|
91
|
+
} else {
|
|
92
|
+
const errorEvent = {
|
|
93
|
+
type: EventType.RUN_ERROR,
|
|
94
|
+
message: resolvedAbruptMessage,
|
|
95
|
+
code: "INCOMPLETE_STREAM"
|
|
96
|
+
};
|
|
97
|
+
events.push(errorEvent);
|
|
98
|
+
appended.push(errorEvent);
|
|
99
|
+
}
|
|
100
|
+
return appended;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
export { finalizeRunEvents };
|
|
105
|
+
//# sourceMappingURL=finalize-events.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize-events.mjs","names":[],"sources":["../src/finalize-events.ts"],"sourcesContent":["import { BaseEvent, EventType, RunErrorEvent } from \"@ag-ui/client\";\nimport { randomUUID } from \"./utils\";\n\ninterface FinalizeRunOptions {\n stopRequested?: boolean;\n interruptionMessage?: string;\n}\n\nconst defaultStopMessage = \"Run stopped by user\";\nconst defaultAbruptEndMessage = \"Run ended without emitting a terminal event\";\n\nexport function finalizeRunEvents(\n events: BaseEvent[],\n options: FinalizeRunOptions = {},\n): BaseEvent[] {\n const { stopRequested = false, interruptionMessage } = options;\n\n const resolvedStopMessage = interruptionMessage ?? defaultStopMessage;\n const resolvedAbruptMessage =\n interruptionMessage && interruptionMessage !== defaultStopMessage\n ? interruptionMessage\n : defaultAbruptEndMessage;\n\n const appended: BaseEvent[] = [];\n\n const openMessageIds = new Set<string>();\n const openToolCalls = new Map<\n string,\n {\n hasEnd: boolean;\n hasResult: boolean;\n }\n >();\n\n for (const event of events) {\n switch (event.type) {\n case EventType.TEXT_MESSAGE_START: {\n const messageId = (event as { messageId?: string }).messageId;\n if (typeof messageId === \"string\") {\n openMessageIds.add(messageId);\n }\n break;\n }\n case EventType.TEXT_MESSAGE_END: {\n const messageId = (event as { messageId?: string }).messageId;\n if (typeof messageId === \"string\") {\n openMessageIds.delete(messageId);\n }\n break;\n }\n case EventType.TOOL_CALL_START: {\n const toolCallId = (event as { toolCallId?: string }).toolCallId;\n if (typeof toolCallId === \"string\") {\n openToolCalls.set(toolCallId, {\n hasEnd: false,\n hasResult: false,\n });\n }\n break;\n }\n case EventType.TOOL_CALL_END: {\n const toolCallId = (event as { toolCallId?: string }).toolCallId;\n const info = toolCallId ? openToolCalls.get(toolCallId) : undefined;\n if (info) {\n info.hasEnd = true;\n }\n break;\n }\n case EventType.TOOL_CALL_RESULT: {\n const toolCallId = (event as { toolCallId?: string }).toolCallId;\n const info = toolCallId ? openToolCalls.get(toolCallId) : undefined;\n if (info) {\n info.hasResult = true;\n }\n break;\n }\n default:\n break;\n }\n }\n\n const hasRunFinished = events.some(\n (event) => event.type === EventType.RUN_FINISHED,\n );\n const hasRunError = events.some(\n (event) => event.type === EventType.RUN_ERROR,\n );\n const hasTerminalEvent = hasRunFinished || hasRunError;\n const terminalEventMissing = !hasTerminalEvent;\n\n for (const messageId of openMessageIds) {\n const endEvent = {\n type: EventType.TEXT_MESSAGE_END,\n messageId,\n } as BaseEvent;\n events.push(endEvent);\n appended.push(endEvent);\n }\n\n for (const [toolCallId, info] of openToolCalls) {\n if (!info.hasEnd) {\n const endEvent = {\n type: EventType.TOOL_CALL_END,\n toolCallId,\n } as BaseEvent;\n events.push(endEvent);\n appended.push(endEvent);\n }\n\n if (terminalEventMissing && !info.hasResult) {\n const resultEvent = {\n type: EventType.TOOL_CALL_RESULT,\n toolCallId,\n messageId: `${toolCallId ?? randomUUID()}-result`,\n role: \"tool\",\n content: JSON.stringify(\n stopRequested\n ? {\n status: \"stopped\",\n reason: \"stop_requested\",\n message: resolvedStopMessage,\n }\n : {\n status: \"error\",\n reason: \"missing_terminal_event\",\n message: resolvedAbruptMessage,\n },\n ),\n } as BaseEvent;\n events.push(resultEvent);\n appended.push(resultEvent);\n }\n }\n\n if (terminalEventMissing) {\n if (stopRequested) {\n const finishedEvent = {\n type: EventType.RUN_FINISHED,\n } as BaseEvent;\n events.push(finishedEvent);\n appended.push(finishedEvent);\n } else {\n const errorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: resolvedAbruptMessage,\n code: \"INCOMPLETE_STREAM\",\n };\n events.push(errorEvent);\n appended.push(errorEvent);\n }\n }\n\n return appended;\n}\n"],"mappings":";;;;AAQA,MAAM,qBAAqB;AAC3B,MAAM,0BAA0B;AAEhC,SAAgB,kBACd,QACA,UAA8B,EAAE,EACnB;CACb,MAAM,EAAE,gBAAgB,OAAO,wBAAwB;CAEvD,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,wBACJ,uBAAuB,wBAAwB,qBAC3C,sBACA;CAEN,MAAM,WAAwB,EAAE;CAEhC,MAAM,iCAAiB,IAAI,KAAa;CACxC,MAAM,gCAAgB,IAAI,KAMvB;AAEH,MAAK,MAAM,SAAS,OAClB,SAAQ,MAAM,MAAd;EACE,KAAK,UAAU,oBAAoB;GACjC,MAAM,YAAa,MAAiC;AACpD,OAAI,OAAO,cAAc,SACvB,gBAAe,IAAI,UAAU;AAE/B;;EAEF,KAAK,UAAU,kBAAkB;GAC/B,MAAM,YAAa,MAAiC;AACpD,OAAI,OAAO,cAAc,SACvB,gBAAe,OAAO,UAAU;AAElC;;EAEF,KAAK,UAAU,iBAAiB;GAC9B,MAAM,aAAc,MAAkC;AACtD,OAAI,OAAO,eAAe,SACxB,eAAc,IAAI,YAAY;IAC5B,QAAQ;IACR,WAAW;IACZ,CAAC;AAEJ;;EAEF,KAAK,UAAU,eAAe;GAC5B,MAAM,aAAc,MAAkC;GACtD,MAAM,OAAO,aAAa,cAAc,IAAI,WAAW,GAAG;AAC1D,OAAI,KACF,MAAK,SAAS;AAEhB;;EAEF,KAAK,UAAU,kBAAkB;GAC/B,MAAM,aAAc,MAAkC;GACtD,MAAM,OAAO,aAAa,cAAc,IAAI,WAAW,GAAG;AAC1D,OAAI,KACF,MAAK,YAAY;AAEnB;;EAEF,QACE;;CAIN,MAAM,iBAAiB,OAAO,MAC3B,UAAU,MAAM,SAAS,UAAU,aACrC;CACD,MAAM,cAAc,OAAO,MACxB,UAAU,MAAM,SAAS,UAAU,UACrC;CAED,MAAM,uBAAuB,EADJ,kBAAkB;AAG3C,MAAK,MAAM,aAAa,gBAAgB;EACtC,MAAM,WAAW;GACf,MAAM,UAAU;GAChB;GACD;AACD,SAAO,KAAK,SAAS;AACrB,WAAS,KAAK,SAAS;;AAGzB,MAAK,MAAM,CAAC,YAAY,SAAS,eAAe;AAC9C,MAAI,CAAC,KAAK,QAAQ;GAChB,MAAM,WAAW;IACf,MAAM,UAAU;IAChB;IACD;AACD,UAAO,KAAK,SAAS;AACrB,YAAS,KAAK,SAAS;;AAGzB,MAAI,wBAAwB,CAAC,KAAK,WAAW;GAC3C,MAAM,cAAc;IAClB,MAAM,UAAU;IAChB;IACA,WAAW,GAAG,cAAc,YAAY,CAAC;IACzC,MAAM;IACN,SAAS,KAAK,UACZ,gBACI;KACE,QAAQ;KACR,QAAQ;KACR,SAAS;KACV,GACD;KACE,QAAQ;KACR,QAAQ;KACR,SAAS;KACV,CACN;IACF;AACD,UAAO,KAAK,YAAY;AACxB,YAAS,KAAK,YAAY;;;AAI9B,KAAI,qBACF,KAAI,eAAe;EACjB,MAAM,gBAAgB,EACpB,MAAM,UAAU,cACjB;AACD,SAAO,KAAK,cAAc;AAC1B,WAAS,KAAK,cAAc;QACvB;EACL,MAAM,aAA4B;GAChC,MAAM,UAAU;GAChB,SAAS;GACT,MAAM;GACP;AACD,SAAO,KAAK,WAAW;AACvB,WAAS,KAAK,WAAW;;AAI7B,QAAO"}
|