@copilotkitnext/shared 1.52.2-next.1 → 1.52.2-next.3

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.
@@ -1,7 +1,10 @@
1
1
 
2
2
  //#region src/constants.ts
3
3
  const DEFAULT_AGENT_ID = "default";
4
+ /** Phoenix channel event name used for all AG-UI events. */
5
+ const AG_UI_CHANNEL_EVENT = "ag-ui";
4
6
 
5
7
  //#endregion
8
+ exports.AG_UI_CHANNEL_EVENT = AG_UI_CHANNEL_EVENT;
6
9
  exports.DEFAULT_AGENT_ID = DEFAULT_AGENT_ID;
7
10
  //# sourceMappingURL=constants.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_AGENT_ID = \"default\";\n"],"mappings":";;AAAA,MAAa,mBAAmB"}
1
+ {"version":3,"file":"constants.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export 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,mBAAmB;;AAGhC,MAAa,sBAAsB"}
@@ -1,5 +1,7 @@
1
1
  //#region src/constants.d.ts
2
2
  declare const DEFAULT_AGENT_ID = "default";
3
+ /** Phoenix channel event name used for all AG-UI events. */
4
+ declare const AG_UI_CHANNEL_EVENT = "ag-ui";
3
5
  //#endregion
4
- export { DEFAULT_AGENT_ID };
6
+ export { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID };
5
7
  //# sourceMappingURL=constants.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAAa,gBAAA"}
1
+ {"version":3,"file":"constants.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAAa,gBAAA;AAAb;AAAA,cAGa,mBAAA"}
@@ -1,5 +1,7 @@
1
1
  //#region src/constants.d.ts
2
2
  declare const DEFAULT_AGENT_ID = "default";
3
+ /** Phoenix channel event name used for all AG-UI events. */
4
+ declare const AG_UI_CHANNEL_EVENT = "ag-ui";
3
5
  //#endregion
4
- export { DEFAULT_AGENT_ID };
6
+ export { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID };
5
7
  //# sourceMappingURL=constants.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAAa,gBAAA"}
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAAa,gBAAA;AAAb;AAAA,cAGa,mBAAA"}
@@ -1,6 +1,8 @@
1
1
  //#region src/constants.ts
2
2
  const DEFAULT_AGENT_ID = "default";
3
+ /** Phoenix channel event name used for all AG-UI events. */
4
+ const AG_UI_CHANNEL_EVENT = "ag-ui";
3
5
 
4
6
  //#endregion
5
- export { DEFAULT_AGENT_ID };
7
+ export { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID };
6
8
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_AGENT_ID = \"default\";\n"],"mappings":";AAAA,MAAa,mBAAmB"}
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export 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,mBAAmB;;AAGhC,MAAa,sBAAsB"}
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ const require_constants = require('./constants.cjs');
5
5
  const require_finalize_events = require('./finalize-events.cjs');
6
6
  const require_transcription_errors = require('./transcription-errors.cjs');
7
7
 
8
+ exports.AG_UI_CHANNEL_EVENT = require_constants.AG_UI_CHANNEL_EVENT;
8
9
  exports.DEFAULT_AGENT_ID = require_constants.DEFAULT_AGENT_ID;
9
10
  exports.TranscriptionErrorCode = require_transcription_errors.TranscriptionErrorCode;
10
11
  exports.TranscriptionErrors = require_transcription_errors.TranscriptionErrors;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from "./types.cjs";
2
2
  import { partialJSONParse, randomUUID } from "./utils.cjs";
3
3
  import { logger } from "./logger.cjs";
4
- import { DEFAULT_AGENT_ID } from "./constants.cjs";
4
+ import { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID } from "./constants.cjs";
5
5
  import { finalizeRunEvents } from "./finalize-events.cjs";
6
6
  import { TranscriptionErrorCode, TranscriptionErrorResponse, TranscriptionErrors } from "./transcription-errors.cjs";
7
- export { type AgentDescription, DEFAULT_AGENT_ID, type MaybePromise, type NonEmptyRecord, type RuntimeInfo, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, finalizeRunEvents, logger, partialJSONParse, randomUUID };
7
+ export { AG_UI_CHANNEL_EVENT, type AgentDescription, DEFAULT_AGENT_ID, type MaybePromise, type NonEmptyRecord, type RuntimeInfo, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, finalizeRunEvents, logger, partialJSONParse, randomUUID };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from "./types.mjs";
2
2
  import { partialJSONParse, randomUUID } from "./utils.mjs";
3
3
  import { logger } from "./logger.mjs";
4
- import { DEFAULT_AGENT_ID } from "./constants.mjs";
4
+ import { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID } from "./constants.mjs";
5
5
  import { finalizeRunEvents } from "./finalize-events.mjs";
6
6
  import { TranscriptionErrorCode, TranscriptionErrorResponse, TranscriptionErrors } from "./transcription-errors.mjs";
7
- export { type AgentDescription, DEFAULT_AGENT_ID, type MaybePromise, type NonEmptyRecord, type RuntimeInfo, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, finalizeRunEvents, logger, partialJSONParse, randomUUID };
7
+ export { AG_UI_CHANNEL_EVENT, type AgentDescription, DEFAULT_AGENT_ID, type MaybePromise, type NonEmptyRecord, type RuntimeInfo, TranscriptionErrorCode, type TranscriptionErrorResponse, TranscriptionErrors, finalizeRunEvents, logger, partialJSONParse, randomUUID };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { partialJSONParse, randomUUID } from "./utils.mjs";
2
2
  import { logger } from "./logger.mjs";
3
- import { DEFAULT_AGENT_ID } from "./constants.mjs";
3
+ import { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID } from "./constants.mjs";
4
4
  import { finalizeRunEvents } from "./finalize-events.mjs";
5
5
  import { TranscriptionErrorCode, TranscriptionErrors } from "./transcription-errors.mjs";
6
6
 
7
- export { DEFAULT_AGENT_ID, TranscriptionErrorCode, TranscriptionErrors, finalizeRunEvents, logger, partialJSONParse, randomUUID };
7
+ export { AG_UI_CHANNEL_EVENT, DEFAULT_AGENT_ID, TranscriptionErrorCode, TranscriptionErrors, finalizeRunEvents, logger, partialJSONParse, randomUUID };
package/dist/index.umd.js CHANGED
@@ -52,6 +52,8 @@ partial_json = __toESM(partial_json);
52
52
  //#endregion
53
53
  //#region src/constants.ts
54
54
  const DEFAULT_AGENT_ID = "default";
55
+ /** Phoenix channel event name used for all AG-UI events. */
56
+ const AG_UI_CHANNEL_EVENT = "ag-ui";
55
57
 
56
58
  //#endregion
57
59
  //#region src/finalize-events.ts
@@ -234,6 +236,7 @@ partial_json = __toESM(partial_json);
234
236
  };
235
237
 
236
238
  //#endregion
239
+ exports.AG_UI_CHANNEL_EVENT = AG_UI_CHANNEL_EVENT;
237
240
  exports.DEFAULT_AGENT_ID = DEFAULT_AGENT_ID;
238
241
  exports.TranscriptionErrorCode = TranscriptionErrorCode;
239
242
  exports.TranscriptionErrors = TranscriptionErrors;
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","names":["PartialJSON","EventType"],"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGA,SAAgB,aAAa;AAC3B,uBAAe;;CAGjB,SAAgB,iBAAiB,MAAc;AAC7C,MAAI;AACF,UAAOA,aAAY,MAAM,KAAK;WACvB,OAAO;AACd,UAAO,EAAE;;;;;;CCXb,MAAa,SAAS;;;;CCAtB,MAAa,mBAAmB;;;;CCQhC,MAAM,qBAAqB;CAC3B,MAAM,0BAA0B;CAEhC,SAAgB,kBACd,QACA,UAA8B,EAAE,EACnB;EACb,MAAM,EAAE,gBAAgB,OAAO,wBAAwB;EAEvD,MAAM,sBAAsB,uFAAuB;EACnD,MAAM,wBACJ,uBAAuB,wBAAwB,qBAC3C,sBACA;EAEN,MAAM,WAAwB,EAAE;EAEhC,MAAM,iCAAiB,IAAI,KAAa;EACxC,MAAM,gCAAgB,IAAI,KAMvB;AAEH,OAAK,MAAM,SAAS,OAClB,SAAQ,MAAM,MAAd;GACE,KAAKC,wBAAU,oBAAoB;IACjC,MAAM,YAAa,MAAiC;AACpD,QAAI,OAAO,cAAc,SACvB,gBAAe,IAAI,UAAU;AAE/B;;GAEF,KAAKA,wBAAU,kBAAkB;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,CACN;KACF;AACD,WAAO,KAAK,YAAY;AACxB,aAAS,KAAK,YAAY;;;AAI9B,MAAI,qBACF,KAAI,eAAe;GACjB,MAAM,gBAAgB,EACpB,MAAMA,wBAAU,cACjB;AACD,UAAO,KAAK,cAAc;AAC1B,YAAS,KAAK,cAAc;SACvB;GACL,MAAM,aAA4B;IAChC,MAAMA,wBAAU;IAChB,SAAS;IACT,MAAM;IACP;AACD,UAAO,KAAK,WAAW;AACvB,YAAS,KAAK,WAAW;;AAI7B,SAAO;;;;;;;;;;CCnJT,IAAY,0EAAL;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;;;;;;CAgBF,MAAa,sBAAsB;EACjC,6BAAyD;GACvD,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,qBACE,QACA,eACgC;GAChC,OAAO,uBAAuB;GAC9B,SAAS,6BAA6B,OAAO,eAAe,UAAU,KAAK,KAAK;GAChF,WAAW;GACZ;EAED,iBAAiB,aAAiD;GAChE,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,oBAAgD;GAC9C,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,mBAA+C;GAC7C,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,gBAAgB,aAAiD;GAC/D,OAAO,uBAAuB;GAC9B;GACA,WAAW;GACZ;EAED,eACE,UAAkB,0CACc;GAChC,OAAO,uBAAuB;GAC9B;GACA,WAAW;GACZ;EAED,qBAAiD;GAC/C,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,sBAAkD;GAChD,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EACF"}
1
+ {"version":3,"file":"index.umd.js","names":["PartialJSON","EventType"],"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\n/** Phoenix channel event name used for all AG-UI events. */\nexport const AG_UI_CHANNEL_EVENT = \"ag-ui\";\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGA,SAAgB,aAAa;AAC3B,uBAAe;;CAGjB,SAAgB,iBAAiB,MAAc;AAC7C,MAAI;AACF,UAAOA,aAAY,MAAM,KAAK;WACvB,OAAO;AACd,UAAO,EAAE;;;;;;CCXb,MAAa,SAAS;;;;CCAtB,MAAa,mBAAmB;;CAGhC,MAAa,sBAAsB;;;;CCKnC,MAAM,qBAAqB;CAC3B,MAAM,0BAA0B;CAEhC,SAAgB,kBACd,QACA,UAA8B,EAAE,EACnB;EACb,MAAM,EAAE,gBAAgB,OAAO,wBAAwB;EAEvD,MAAM,sBAAsB,uFAAuB;EACnD,MAAM,wBACJ,uBAAuB,wBAAwB,qBAC3C,sBACA;EAEN,MAAM,WAAwB,EAAE;EAEhC,MAAM,iCAAiB,IAAI,KAAa;EACxC,MAAM,gCAAgB,IAAI,KAMvB;AAEH,OAAK,MAAM,SAAS,OAClB,SAAQ,MAAM,MAAd;GACE,KAAKC,wBAAU,oBAAoB;IACjC,MAAM,YAAa,MAAiC;AACpD,QAAI,OAAO,cAAc,SACvB,gBAAe,IAAI,UAAU;AAE/B;;GAEF,KAAKA,wBAAU,kBAAkB;IAC/B,MAAM,YAAa,MAAiC;AACpD,QAAI,OAAO,cAAc,SACvB,gBAAe,OAAO,UAA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qBACF,KAAI,eAAe;GACjB,MAAM,gBAAgB,EACpB,MAAMA,wBAAU,cACjB;AACD,UAAO,KAAK,cAAc;AAC1B,YAAS,KAAK,cAAc;SACvB;GACL,MAAM,aAA4B;IAChC,MAAMA,wBAAU;IAChB,SAAS;IACT,MAAM;IACP;AACD,UAAO,KAAK,WAAW;AACvB,YAAS,KAAK,WAAW;;AAI7B,SAAO;;;;;;;;;;CCnJT,IAAY,0EAAL;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;;;;;;CAgBF,MAAa,sBAAsB;EACjC,6BAAyD;GACvD,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,qBACE,QACA,eACgC;GAChC,OAAO,uBAAuB;GAC9B,SAAS,6BAA6B,OAAO,eAAe,UAAU,KAAK,KAAK;GAChF,WAAW;GACZ;EAED,iBAAiB,aAAiD;GAChE,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,oBAAgD;GAC9C,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,mBAA+C;GAC7C,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,gBAAgB,aAAiD;GAC/D,OAAO,uBAAuB;GAC9B;GACA,WAAW;GACZ;EAED,eACE,UAAkB,0CACc;GAChC,OAAO,uBAAuB;GAC9B;GACA,WAAW;GACZ;EAED,qBAAiD;GAC/C,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EAED,sBAAkD;GAChD,OAAO,uBAAuB;GAC9B,SAAS;GACT,WAAW;GACZ;EACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkitnext/shared",
3
- "version": "1.52.2-next.1",
3
+ "version": "1.52.2-next.3",
4
4
  "description": "Shared utilities and types for CopilotKit2",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",
@@ -22,11 +22,11 @@
22
22
  "eslint": "^9.30.0",
23
23
  "tsdown": "^0.20.3",
24
24
  "typescript": "5.8.2",
25
- "@copilotkitnext/eslint-config": "1.52.2-next.1",
26
- "@copilotkitnext/typescript-config": "1.52.2-next.1"
25
+ "@copilotkitnext/eslint-config": "1.52.2-next.3",
26
+ "@copilotkitnext/typescript-config": "1.52.2-next.3"
27
27
  },
28
28
  "dependencies": {
29
- "@ag-ui/client": "0.0.46",
29
+ "@ag-ui/client": "0.0.47",
30
30
  "uuid": "^11.1.0",
31
31
  "partial-json": "^0.1.7"
32
32
  },