@copilotkitnext/shared 1.51.4 → 1.51.5-next.1

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 (58) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/constants.cjs +7 -0
  3. package/dist/constants.cjs.map +1 -0
  4. package/dist/constants.d.cts +5 -0
  5. package/dist/constants.d.cts.map +1 -0
  6. package/dist/constants.d.mts +5 -0
  7. package/dist/constants.d.mts.map +1 -0
  8. package/dist/constants.mjs +6 -0
  9. package/dist/constants.mjs.map +1 -0
  10. package/dist/finalize-events.cjs +106 -0
  11. package/dist/finalize-events.cjs.map +1 -0
  12. package/dist/finalize-events.d.cts +11 -0
  13. package/dist/finalize-events.d.cts.map +1 -0
  14. package/dist/finalize-events.d.mts +11 -0
  15. package/dist/finalize-events.d.mts.map +1 -0
  16. package/dist/finalize-events.mjs +105 -0
  17. package/dist/finalize-events.mjs.map +1 -0
  18. package/dist/index.cjs +14 -0
  19. package/dist/index.d.cts +7 -0
  20. package/dist/index.d.mts +7 -84
  21. package/dist/index.mjs +6 -213
  22. package/dist/index.umd.js +245 -2
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/logger.cjs +7 -0
  25. package/dist/logger.cjs.map +1 -0
  26. package/dist/logger.d.cts +5 -0
  27. package/dist/logger.d.cts.map +1 -0
  28. package/dist/logger.d.mts +5 -0
  29. package/dist/logger.d.mts.map +1 -0
  30. package/dist/logger.mjs +6 -0
  31. package/dist/logger.mjs.map +1 -0
  32. package/dist/transcription-errors.cjs +84 -0
  33. package/dist/transcription-errors.cjs.map +1 -0
  34. package/dist/transcription-errors.d.cts +52 -0
  35. package/dist/transcription-errors.d.cts.map +1 -0
  36. package/dist/transcription-errors.d.mts +52 -0
  37. package/dist/transcription-errors.d.mts.map +1 -0
  38. package/dist/transcription-errors.mjs +82 -0
  39. package/dist/transcription-errors.mjs.map +1 -0
  40. package/dist/types.d.cts +22 -0
  41. package/dist/types.d.cts.map +1 -0
  42. package/dist/types.d.mts +22 -0
  43. package/dist/types.d.mts.map +1 -0
  44. package/dist/utils.cjs +21 -0
  45. package/dist/utils.cjs.map +1 -0
  46. package/dist/utils.d.cts +6 -0
  47. package/dist/utils.d.cts.map +1 -0
  48. package/dist/utils.d.mts +6 -0
  49. package/dist/utils.d.mts.map +1 -0
  50. package/dist/utils.mjs +18 -0
  51. package/dist/utils.mjs.map +1 -0
  52. package/package.json +17 -13
  53. package/tsdown.config.ts +36 -0
  54. package/dist/index.d.ts +0 -84
  55. package/dist/index.js +0 -257
  56. package/dist/index.js.map +0 -1
  57. package/dist/index.mjs.map +0 -1
  58. package/rollup.config.mjs +0 -36
package/dist/index.js DELETED
@@ -1,257 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- DEFAULT_AGENT_ID: () => DEFAULT_AGENT_ID,
34
- TranscriptionErrorCode: () => TranscriptionErrorCode,
35
- TranscriptionErrors: () => TranscriptionErrors,
36
- finalizeRunEvents: () => finalizeRunEvents,
37
- logger: () => logger,
38
- partialJSONParse: () => partialJSONParse,
39
- randomUUID: () => randomUUID
40
- });
41
- module.exports = __toCommonJS(index_exports);
42
-
43
- // src/utils.ts
44
- var import_uuid = require("uuid");
45
- var PartialJSON = __toESM(require("partial-json"));
46
- function randomUUID() {
47
- return (0, import_uuid.v4)();
48
- }
49
- function partialJSONParse(json) {
50
- try {
51
- return PartialJSON.parse(json);
52
- } catch (error) {
53
- return {};
54
- }
55
- }
56
-
57
- // src/logger.ts
58
- var logger = console;
59
-
60
- // src/constants.ts
61
- var DEFAULT_AGENT_ID = "default";
62
-
63
- // src/finalize-events.ts
64
- var import_client = require("@ag-ui/client");
65
- var defaultStopMessage = "Run stopped by user";
66
- var defaultAbruptEndMessage = "Run ended without emitting a terminal event";
67
- function finalizeRunEvents(events, options = {}) {
68
- const { stopRequested = false, interruptionMessage } = options;
69
- const resolvedStopMessage = interruptionMessage ?? defaultStopMessage;
70
- const resolvedAbruptMessage = interruptionMessage && interruptionMessage !== defaultStopMessage ? interruptionMessage : defaultAbruptEndMessage;
71
- const appended = [];
72
- const openMessageIds = /* @__PURE__ */ new Set();
73
- const openToolCalls = /* @__PURE__ */ new Map();
74
- for (const event of events) {
75
- switch (event.type) {
76
- case import_client.EventType.TEXT_MESSAGE_START: {
77
- const messageId = event.messageId;
78
- if (typeof messageId === "string") {
79
- openMessageIds.add(messageId);
80
- }
81
- break;
82
- }
83
- case import_client.EventType.TEXT_MESSAGE_END: {
84
- const messageId = event.messageId;
85
- if (typeof messageId === "string") {
86
- openMessageIds.delete(messageId);
87
- }
88
- break;
89
- }
90
- case import_client.EventType.TOOL_CALL_START: {
91
- const toolCallId = event.toolCallId;
92
- if (typeof toolCallId === "string") {
93
- openToolCalls.set(toolCallId, {
94
- hasEnd: false,
95
- hasResult: false
96
- });
97
- }
98
- break;
99
- }
100
- case import_client.EventType.TOOL_CALL_END: {
101
- const toolCallId = event.toolCallId;
102
- const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
103
- if (info) {
104
- info.hasEnd = true;
105
- }
106
- break;
107
- }
108
- case import_client.EventType.TOOL_CALL_RESULT: {
109
- const toolCallId = event.toolCallId;
110
- const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
111
- if (info) {
112
- info.hasResult = true;
113
- }
114
- break;
115
- }
116
- default:
117
- break;
118
- }
119
- }
120
- const hasRunFinished = events.some(
121
- (event) => event.type === import_client.EventType.RUN_FINISHED
122
- );
123
- const hasRunError = events.some(
124
- (event) => event.type === import_client.EventType.RUN_ERROR
125
- );
126
- const hasTerminalEvent = hasRunFinished || hasRunError;
127
- const terminalEventMissing = !hasTerminalEvent;
128
- for (const messageId of openMessageIds) {
129
- const endEvent = {
130
- type: import_client.EventType.TEXT_MESSAGE_END,
131
- messageId
132
- };
133
- events.push(endEvent);
134
- appended.push(endEvent);
135
- }
136
- for (const [toolCallId, info] of openToolCalls) {
137
- if (!info.hasEnd) {
138
- const endEvent = {
139
- type: import_client.EventType.TOOL_CALL_END,
140
- toolCallId
141
- };
142
- events.push(endEvent);
143
- appended.push(endEvent);
144
- }
145
- if (terminalEventMissing && !info.hasResult) {
146
- const resultEvent = {
147
- type: import_client.EventType.TOOL_CALL_RESULT,
148
- toolCallId,
149
- messageId: `${toolCallId ?? randomUUID()}-result`,
150
- role: "tool",
151
- content: JSON.stringify(
152
- stopRequested ? {
153
- status: "stopped",
154
- reason: "stop_requested",
155
- message: resolvedStopMessage
156
- } : {
157
- status: "error",
158
- reason: "missing_terminal_event",
159
- message: resolvedAbruptMessage
160
- }
161
- )
162
- };
163
- events.push(resultEvent);
164
- appended.push(resultEvent);
165
- }
166
- }
167
- if (terminalEventMissing) {
168
- if (stopRequested) {
169
- const finishedEvent = {
170
- type: import_client.EventType.RUN_FINISHED
171
- };
172
- events.push(finishedEvent);
173
- appended.push(finishedEvent);
174
- } else {
175
- const errorEvent = {
176
- type: import_client.EventType.RUN_ERROR,
177
- message: resolvedAbruptMessage,
178
- code: "INCOMPLETE_STREAM"
179
- };
180
- events.push(errorEvent);
181
- appended.push(errorEvent);
182
- }
183
- }
184
- return appended;
185
- }
186
-
187
- // src/transcription-errors.ts
188
- var TranscriptionErrorCode = /* @__PURE__ */ ((TranscriptionErrorCode2) => {
189
- TranscriptionErrorCode2["SERVICE_NOT_CONFIGURED"] = "service_not_configured";
190
- TranscriptionErrorCode2["INVALID_AUDIO_FORMAT"] = "invalid_audio_format";
191
- TranscriptionErrorCode2["AUDIO_TOO_LONG"] = "audio_too_long";
192
- TranscriptionErrorCode2["AUDIO_TOO_SHORT"] = "audio_too_short";
193
- TranscriptionErrorCode2["RATE_LIMITED"] = "rate_limited";
194
- TranscriptionErrorCode2["AUTH_FAILED"] = "auth_failed";
195
- TranscriptionErrorCode2["PROVIDER_ERROR"] = "provider_error";
196
- TranscriptionErrorCode2["NETWORK_ERROR"] = "network_error";
197
- TranscriptionErrorCode2["INVALID_REQUEST"] = "invalid_request";
198
- return TranscriptionErrorCode2;
199
- })(TranscriptionErrorCode || {});
200
- var TranscriptionErrors = {
201
- serviceNotConfigured: () => ({
202
- error: "service_not_configured" /* SERVICE_NOT_CONFIGURED */,
203
- message: "Transcription service is not configured",
204
- retryable: false
205
- }),
206
- invalidAudioFormat: (format, supported) => ({
207
- error: "invalid_audio_format" /* INVALID_AUDIO_FORMAT */,
208
- message: `Unsupported audio format: ${format}. Supported: ${supported.join(", ")}`,
209
- retryable: false
210
- }),
211
- invalidRequest: (details) => ({
212
- error: "invalid_request" /* INVALID_REQUEST */,
213
- message: details,
214
- retryable: false
215
- }),
216
- rateLimited: () => ({
217
- error: "rate_limited" /* RATE_LIMITED */,
218
- message: "Rate limited. Please try again later.",
219
- retryable: true
220
- }),
221
- authFailed: () => ({
222
- error: "auth_failed" /* AUTH_FAILED */,
223
- message: "Authentication failed with transcription provider",
224
- retryable: false
225
- }),
226
- providerError: (message) => ({
227
- error: "provider_error" /* PROVIDER_ERROR */,
228
- message,
229
- retryable: true
230
- }),
231
- networkError: (message = "Network error during transcription") => ({
232
- error: "network_error" /* NETWORK_ERROR */,
233
- message,
234
- retryable: true
235
- }),
236
- audioTooLong: () => ({
237
- error: "audio_too_long" /* AUDIO_TOO_LONG */,
238
- message: "Audio file is too long",
239
- retryable: false
240
- }),
241
- audioTooShort: () => ({
242
- error: "audio_too_short" /* AUDIO_TOO_SHORT */,
243
- message: "Audio is too short to transcribe",
244
- retryable: false
245
- })
246
- };
247
- // Annotate the CommonJS export names for ESM import in node:
248
- 0 && (module.exports = {
249
- DEFAULT_AGENT_ID,
250
- TranscriptionErrorCode,
251
- TranscriptionErrors,
252
- finalizeRunEvents,
253
- logger,
254
- partialJSONParse,
255
- randomUUID
256
- });
257
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/logger.ts","../src/constants.ts","../src/finalize-events.ts","../src/transcription-errors.ts"],"sourcesContent":["export {\n type MaybePromise,\n type NonEmptyRecord,\n type AgentDescription,\n type RuntimeInfo,\n} from \"./types\";\n\nexport * from \"./utils\";\n\nexport { logger } from \"./logger\";\nexport { DEFAULT_AGENT_ID } from \"./constants\";\nexport { finalizeRunEvents } from \"./finalize-events\";\n\nexport {\n TranscriptionErrorCode,\n TranscriptionErrors,\n type TranscriptionErrorResponse,\n} from \"./transcription-errors\";\n","import { v4 as uuidv4 } from \"uuid\";\nimport * as PartialJSON from \"partial-json\";\n\nexport function randomUUID() {\n return uuidv4();\n}\n\nexport function partialJSONParse(json: string) {\n try {\n return PartialJSON.parse(json);\n } catch (error) {\n return {};\n }\n}\n","export const logger = console;\n","export const DEFAULT_AGENT_ID = \"default\";\n","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","/**\n * Error codes for transcription HTTP responses.\n * Uses snake_case to align with existing CopilotKitCoreErrorCode pattern.\n * These codes are returned by the runtime and parsed by the client.\n */\nexport enum TranscriptionErrorCode {\n /** Transcription service not configured in runtime */\n SERVICE_NOT_CONFIGURED = \"service_not_configured\",\n /** Audio format not supported */\n INVALID_AUDIO_FORMAT = \"invalid_audio_format\",\n /** Audio file is too long */\n AUDIO_TOO_LONG = \"audio_too_long\",\n /** Audio file is empty or too short */\n AUDIO_TOO_SHORT = \"audio_too_short\",\n /** Rate limited by transcription provider */\n RATE_LIMITED = \"rate_limited\",\n /** Authentication failed with transcription provider */\n AUTH_FAILED = \"auth_failed\",\n /** Transcription provider returned an error */\n PROVIDER_ERROR = \"provider_error\",\n /** Network error during transcription */\n NETWORK_ERROR = \"network_error\",\n /** Invalid request format */\n INVALID_REQUEST = \"invalid_request\",\n}\n\n/**\n * Error response format returned by the transcription endpoint.\n */\nexport interface TranscriptionErrorResponse {\n error: TranscriptionErrorCode;\n message: string;\n retryable?: boolean;\n}\n\n/**\n * Helper functions to create transcription error responses.\n * Used by the runtime to return consistent error responses.\n */\nexport const TranscriptionErrors = {\n serviceNotConfigured: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.SERVICE_NOT_CONFIGURED,\n message: \"Transcription service is not configured\",\n retryable: false,\n }),\n\n invalidAudioFormat: (\n format: string,\n supported: string[],\n ): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.INVALID_AUDIO_FORMAT,\n message: `Unsupported audio format: ${format}. Supported: ${supported.join(\", \")}`,\n retryable: false,\n }),\n\n invalidRequest: (details: string): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.INVALID_REQUEST,\n message: details,\n retryable: false,\n }),\n\n rateLimited: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.RATE_LIMITED,\n message: \"Rate limited. Please try again later.\",\n retryable: true,\n }),\n\n authFailed: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.AUTH_FAILED,\n message: \"Authentication failed with transcription provider\",\n retryable: false,\n }),\n\n providerError: (message: string): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.PROVIDER_ERROR,\n message,\n retryable: true,\n }),\n\n networkError: (\n message: string = \"Network error during transcription\",\n ): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.NETWORK_ERROR,\n message,\n retryable: true,\n }),\n\n audioTooLong: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.AUDIO_TOO_LONG,\n message: \"Audio file is too long\",\n retryable: false,\n }),\n\n audioTooShort: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.AUDIO_TOO_SHORT,\n message: \"Audio is too short to transcribe\",\n retryable: false,\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA6B;AAC7B,kBAA6B;AAEtB,SAAS,aAAa;AAC3B,aAAO,YAAAA,IAAO;AAChB;AAEO,SAAS,iBAAiB,MAAc;AAC7C,MAAI;AACF,WAAmB,kBAAM,IAAI;AAAA,EAC/B,SAAS,OAAO;AACd,WAAO,CAAC;AAAA,EACV;AACF;;;ACbO,IAAM,SAAS;;;ACAf,IAAM,mBAAmB;;;ACAhC,oBAAoD;AAQpD,IAAM,qBAAqB;AAC3B,IAAM,0BAA0B;AAEzB,SAAS,kBACd,QACA,UAA8B,CAAC,GAClB;AACb,QAAM,EAAE,gBAAgB,OAAO,oBAAoB,IAAI;AAEvD,QAAM,sBAAsB,uBAAuB;AACnD,QAAM,wBACJ,uBAAuB,wBAAwB,qBAC3C,sBACA;AAEN,QAAM,WAAwB,CAAC;AAE/B,QAAM,iBAAiB,oBAAI,IAAY;AACvC,QAAM,gBAAgB,oBAAI,IAMxB;AAEF,aAAW,SAAS,QAAQ;AAC1B,YAAQ,MAAM,MAAM;AAAA,MAClB,KAAK,wBAAU,oBAAoB;AACjC,cAAM,YAAa,MAAiC;AACpD,YAAI,OAAO,cAAc,UAAU;AACjC,yBAAe,IAAI,SAAS;AAAA,QAC9B;AACA;AAAA,MACF;AAAA,MACA,KAAK,wBAAU,kBAAkB;AAC/B,cAAM,YAAa,MAAiC;AACpD,YAAI,OAAO,cAAc,UAAU;AACjC,yBAAe,OAAO,SAAS;AAAA,QACjC;AACA;AAAA,MACF;AAAA,MACA,KAAK,wBAAU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EACb;AAAA,EAEA,gBAAgB,CAAC,aAAiD;AAAA,IAChE,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EAEA,aAAa,OAAmC;AAAA,IAC9C,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EAEA,YAAY,OAAmC;AAAA,IAC7C,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EAEA,eAAe,CAAC,aAAiD;AAAA,IAC/D,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,EACb;AAAA,EAEA,cAAc,CACZ,UAAkB,0CACc;AAAA,IAChC,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,EACb;AAAA,EAEA,cAAc,OAAmC;AAAA,IAC/C,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EAEA,eAAe,OAAmC;AAAA,IAChD,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;","names":["uuidv4","TranscriptionErrorCode"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/logger.ts","../src/constants.ts","../src/finalize-events.ts","../src/transcription-errors.ts"],"sourcesContent":["import { v4 as uuidv4 } from \"uuid\";\nimport * as PartialJSON from \"partial-json\";\n\nexport function randomUUID() {\n return uuidv4();\n}\n\nexport function partialJSONParse(json: string) {\n try {\n return PartialJSON.parse(json);\n } catch (error) {\n return {};\n }\n}\n","export const logger = console;\n","export const DEFAULT_AGENT_ID = \"default\";\n","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","/**\n * Error codes for transcription HTTP responses.\n * Uses snake_case to align with existing CopilotKitCoreErrorCode pattern.\n * These codes are returned by the runtime and parsed by the client.\n */\nexport enum TranscriptionErrorCode {\n /** Transcription service not configured in runtime */\n SERVICE_NOT_CONFIGURED = \"service_not_configured\",\n /** Audio format not supported */\n INVALID_AUDIO_FORMAT = \"invalid_audio_format\",\n /** Audio file is too long */\n AUDIO_TOO_LONG = \"audio_too_long\",\n /** Audio file is empty or too short */\n AUDIO_TOO_SHORT = \"audio_too_short\",\n /** Rate limited by transcription provider */\n RATE_LIMITED = \"rate_limited\",\n /** Authentication failed with transcription provider */\n AUTH_FAILED = \"auth_failed\",\n /** Transcription provider returned an error */\n PROVIDER_ERROR = \"provider_error\",\n /** Network error during transcription */\n NETWORK_ERROR = \"network_error\",\n /** Invalid request format */\n INVALID_REQUEST = \"invalid_request\",\n}\n\n/**\n * Error response format returned by the transcription endpoint.\n */\nexport interface TranscriptionErrorResponse {\n error: TranscriptionErrorCode;\n message: string;\n retryable?: boolean;\n}\n\n/**\n * Helper functions to create transcription error responses.\n * Used by the runtime to return consistent error responses.\n */\nexport const TranscriptionErrors = {\n serviceNotConfigured: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.SERVICE_NOT_CONFIGURED,\n message: \"Transcription service is not configured\",\n retryable: false,\n }),\n\n invalidAudioFormat: (\n format: string,\n supported: string[],\n ): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.INVALID_AUDIO_FORMAT,\n message: `Unsupported audio format: ${format}. Supported: ${supported.join(\", \")}`,\n retryable: false,\n }),\n\n invalidRequest: (details: string): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.INVALID_REQUEST,\n message: details,\n retryable: false,\n }),\n\n rateLimited: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.RATE_LIMITED,\n message: \"Rate limited. Please try again later.\",\n retryable: true,\n }),\n\n authFailed: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.AUTH_FAILED,\n message: \"Authentication failed with transcription provider\",\n retryable: false,\n }),\n\n providerError: (message: string): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.PROVIDER_ERROR,\n message,\n retryable: true,\n }),\n\n networkError: (\n message: string = \"Network error during transcription\",\n ): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.NETWORK_ERROR,\n message,\n retryable: true,\n }),\n\n audioTooLong: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.AUDIO_TOO_LONG,\n message: \"Audio file is too long\",\n retryable: false,\n }),\n\n audioTooShort: (): TranscriptionErrorResponse => ({\n error: TranscriptionErrorCode.AUDIO_TOO_SHORT,\n message: \"Audio is too short to transcribe\",\n retryable: false,\n }),\n};\n"],"mappings":";AAAA,SAAS,MAAM,cAAc;AAC7B,YAAY,iBAAiB;AAEtB,SAAS,aAAa;AAC3B,SAAO,OAAO;AAChB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CACZ,UAAkB,0CACc;AAAA,IAChC,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,EACb;AAAA,EAEA,cAAc,OAAmC;AAAA,IAC/C,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EAEA,eAAe,OAAmC;AAAA,IAChD,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;","names":["TranscriptionErrorCode"]}
package/rollup.config.mjs DELETED
@@ -1,36 +0,0 @@
1
- import resolve from '@rollup/plugin-node-resolve';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import typescript from '@rollup/plugin-typescript';
4
- import terser from '@rollup/plugin-terser';
5
- import json from '@rollup/plugin-json';
6
-
7
- function onwarn(warning, warn) {
8
- // Ignore circular dependency warnings from node_modules
9
- if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids?.some(id => id.includes('node_modules'))) return;
10
- // Ignore "this" rewritten to "undefined" warnings from node_modules
11
- if (warning.code === 'THIS_IS_UNDEFINED' && warning.id?.includes('node_modules')) return;
12
- warn(warning);
13
- }
14
-
15
- export default {
16
- input: 'src/index.ts',
17
- output: {
18
- file: 'dist/index.umd.js',
19
- format: 'umd',
20
- name: 'CopilotKitNextShared',
21
- sourcemap: true,
22
- inlineDynamicImports: true,
23
- globals: {
24
- 'zod': 'Zod',
25
- },
26
- },
27
- external: ['zod'],
28
- onwarn,
29
- plugins: [
30
- resolve({ browser: true }),
31
- commonjs(),
32
- json(),
33
- typescript({ tsconfig: './tsconfig.json', declaration: false, declarationMap: false, compilerOptions: { target: 'ES2018', module: 'ESNext', moduleResolution: 'Bundler' } }),
34
- terser(),
35
- ],
36
- };