@copilotkit/shared 1.54.1 → 1.55.0-next.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/constants/index.cjs +5 -0
  3. package/dist/constants/index.cjs.map +1 -1
  4. package/dist/constants/index.d.cts +4 -1
  5. package/dist/constants/index.d.cts.map +1 -1
  6. package/dist/constants/index.d.mts +4 -1
  7. package/dist/constants/index.d.mts.map +1 -1
  8. package/dist/constants/index.mjs +4 -1
  9. package/dist/constants/index.mjs.map +1 -1
  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 +25 -0
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +9 -4
  21. package/dist/index.d.cts.map +1 -1
  22. package/dist/index.d.mts +9 -4
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +10 -3
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/index.umd.js +286 -5
  27. package/dist/index.umd.js.map +1 -1
  28. package/dist/logger.cjs +7 -0
  29. package/dist/logger.cjs.map +1 -0
  30. package/dist/logger.d.cts +5 -0
  31. package/dist/logger.d.cts.map +1 -0
  32. package/dist/logger.d.mts +5 -0
  33. package/dist/logger.d.mts.map +1 -0
  34. package/dist/logger.mjs +6 -0
  35. package/dist/logger.mjs.map +1 -0
  36. package/dist/package.cjs +1 -1
  37. package/dist/package.mjs +1 -1
  38. package/dist/standard-schema.cjs +29 -0
  39. package/dist/standard-schema.cjs.map +1 -0
  40. package/dist/standard-schema.d.cts +32 -0
  41. package/dist/standard-schema.d.cts.map +1 -0
  42. package/dist/standard-schema.d.mts +32 -0
  43. package/dist/standard-schema.d.mts.map +1 -0
  44. package/dist/standard-schema.mjs +28 -0
  45. package/dist/standard-schema.mjs.map +1 -0
  46. package/dist/transcription-errors.cjs +84 -0
  47. package/dist/transcription-errors.cjs.map +1 -0
  48. package/dist/transcription-errors.d.cts +52 -0
  49. package/dist/transcription-errors.d.cts.map +1 -0
  50. package/dist/transcription-errors.d.mts +52 -0
  51. package/dist/transcription-errors.d.mts.map +1 -0
  52. package/dist/transcription-errors.mjs +82 -0
  53. package/dist/transcription-errors.mjs.map +1 -0
  54. package/dist/types/message.d.cts +1 -1
  55. package/dist/types/message.d.mts +1 -1
  56. package/dist/utils/index.cjs +49 -0
  57. package/dist/utils/index.cjs.map +1 -1
  58. package/dist/utils/index.d.cts +24 -2
  59. package/dist/utils/index.d.cts.map +1 -1
  60. package/dist/utils/index.d.mts +24 -2
  61. package/dist/utils/index.d.mts.map +1 -1
  62. package/dist/utils/index.mjs +45 -1
  63. package/dist/utils/index.mjs.map +1 -1
  64. package/dist/utils/types.cjs +9 -0
  65. package/dist/utils/types.cjs.map +1 -0
  66. package/dist/utils/types.d.cts +12 -1
  67. package/dist/utils/types.d.cts.map +1 -1
  68. package/dist/utils/types.d.mts +12 -1
  69. package/dist/utils/types.d.mts.map +1 -1
  70. package/dist/utils/types.mjs +7 -0
  71. package/dist/utils/types.mjs.map +1 -0
  72. package/package.json +11 -4
  73. package/src/__tests__/standard-schema-types.test.ts +144 -0
  74. package/src/__tests__/standard-schema.test.ts +267 -0
  75. package/src/__tests__/zod-regression.test.ts +319 -0
  76. package/src/constants/index.ts +5 -0
  77. package/src/finalize-events.ts +154 -0
  78. package/src/index.ts +12 -0
  79. package/src/logger.ts +1 -0
  80. package/src/standard-schema.ts +76 -0
  81. package/src/transcription-errors.ts +99 -0
  82. package/src/types/message.ts +1 -1
  83. package/src/utils/index.ts +58 -0
  84. package/src/utils/types.ts +21 -0
  85. package/src/utils.test.ts +66 -0
  86. package/tsconfig.json +9 -1
  87. package/tsdown.config.ts +10 -2
@@ -0,0 +1,84 @@
1
+
2
+ //#region src/transcription-errors.ts
3
+ /**
4
+ * Error codes for transcription HTTP responses.
5
+ * Uses snake_case to align with existing CopilotKitCoreErrorCode pattern.
6
+ * These codes are returned by the runtime and parsed by the client.
7
+ */
8
+ let TranscriptionErrorCode = /* @__PURE__ */ function(TranscriptionErrorCode) {
9
+ /** Transcription service not configured in runtime */
10
+ TranscriptionErrorCode["SERVICE_NOT_CONFIGURED"] = "service_not_configured";
11
+ /** Audio format not supported */
12
+ TranscriptionErrorCode["INVALID_AUDIO_FORMAT"] = "invalid_audio_format";
13
+ /** Audio file is too long */
14
+ TranscriptionErrorCode["AUDIO_TOO_LONG"] = "audio_too_long";
15
+ /** Audio file is empty or too short */
16
+ TranscriptionErrorCode["AUDIO_TOO_SHORT"] = "audio_too_short";
17
+ /** Rate limited by transcription provider */
18
+ TranscriptionErrorCode["RATE_LIMITED"] = "rate_limited";
19
+ /** Authentication failed with transcription provider */
20
+ TranscriptionErrorCode["AUTH_FAILED"] = "auth_failed";
21
+ /** Transcription provider returned an error */
22
+ TranscriptionErrorCode["PROVIDER_ERROR"] = "provider_error";
23
+ /** Network error during transcription */
24
+ TranscriptionErrorCode["NETWORK_ERROR"] = "network_error";
25
+ /** Invalid request format */
26
+ TranscriptionErrorCode["INVALID_REQUEST"] = "invalid_request";
27
+ return TranscriptionErrorCode;
28
+ }({});
29
+ /**
30
+ * Helper functions to create transcription error responses.
31
+ * Used by the runtime to return consistent error responses.
32
+ */
33
+ const TranscriptionErrors = {
34
+ serviceNotConfigured: () => ({
35
+ error: TranscriptionErrorCode.SERVICE_NOT_CONFIGURED,
36
+ message: "Transcription service is not configured",
37
+ retryable: false
38
+ }),
39
+ invalidAudioFormat: (format, supported) => ({
40
+ error: TranscriptionErrorCode.INVALID_AUDIO_FORMAT,
41
+ message: `Unsupported audio format: ${format}. Supported: ${supported.join(", ")}`,
42
+ retryable: false
43
+ }),
44
+ invalidRequest: (details) => ({
45
+ error: TranscriptionErrorCode.INVALID_REQUEST,
46
+ message: details,
47
+ retryable: false
48
+ }),
49
+ rateLimited: () => ({
50
+ error: TranscriptionErrorCode.RATE_LIMITED,
51
+ message: "Rate limited. Please try again later.",
52
+ retryable: true
53
+ }),
54
+ authFailed: () => ({
55
+ error: TranscriptionErrorCode.AUTH_FAILED,
56
+ message: "Authentication failed with transcription provider",
57
+ retryable: false
58
+ }),
59
+ providerError: (message) => ({
60
+ error: TranscriptionErrorCode.PROVIDER_ERROR,
61
+ message,
62
+ retryable: true
63
+ }),
64
+ networkError: (message = "Network error during transcription") => ({
65
+ error: TranscriptionErrorCode.NETWORK_ERROR,
66
+ message,
67
+ retryable: true
68
+ }),
69
+ audioTooLong: () => ({
70
+ error: TranscriptionErrorCode.AUDIO_TOO_LONG,
71
+ message: "Audio file is too long",
72
+ retryable: false
73
+ }),
74
+ audioTooShort: () => ({
75
+ error: TranscriptionErrorCode.AUDIO_TOO_SHORT,
76
+ message: "Audio is too short to transcribe",
77
+ retryable: false
78
+ })
79
+ };
80
+
81
+ //#endregion
82
+ exports.TranscriptionErrorCode = TranscriptionErrorCode;
83
+ exports.TranscriptionErrors = TranscriptionErrors;
84
+ //# sourceMappingURL=transcription-errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcription-errors.cjs","names":[],"sources":["../src/transcription-errors.ts"],"sourcesContent":["/**\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":";;;;;;;AAKA,IAAY,0EAAL;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;;;;;;AAgBF,MAAa,sBAAsB;CACjC,6BAAyD;EACvD,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,qBACE,QACA,eACgC;EAChC,OAAO,uBAAuB;EAC9B,SAAS,6BAA6B,OAAO,eAAe,UAAU,KAAK,KAAK;EAChF,WAAW;EACZ;CAED,iBAAiB,aAAiD;EAChE,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,oBAAgD;EAC9C,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,mBAA+C;EAC7C,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,gBAAgB,aAAiD;EAC/D,OAAO,uBAAuB;EAC9B;EACA,WAAW;EACZ;CAED,eACE,UAAkB,0CACc;EAChC,OAAO,uBAAuB;EAC9B;EACA,WAAW;EACZ;CAED,qBAAiD;EAC/C,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,sBAAkD;EAChD,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CACF"}
@@ -0,0 +1,52 @@
1
+ //#region src/transcription-errors.d.ts
2
+ /**
3
+ * Error codes for transcription HTTP responses.
4
+ * Uses snake_case to align with existing CopilotKitCoreErrorCode pattern.
5
+ * These codes are returned by the runtime and parsed by the client.
6
+ */
7
+ declare enum TranscriptionErrorCode {
8
+ /** Transcription service not configured in runtime */
9
+ SERVICE_NOT_CONFIGURED = "service_not_configured",
10
+ /** Audio format not supported */
11
+ INVALID_AUDIO_FORMAT = "invalid_audio_format",
12
+ /** Audio file is too long */
13
+ AUDIO_TOO_LONG = "audio_too_long",
14
+ /** Audio file is empty or too short */
15
+ AUDIO_TOO_SHORT = "audio_too_short",
16
+ /** Rate limited by transcription provider */
17
+ RATE_LIMITED = "rate_limited",
18
+ /** Authentication failed with transcription provider */
19
+ AUTH_FAILED = "auth_failed",
20
+ /** Transcription provider returned an error */
21
+ PROVIDER_ERROR = "provider_error",
22
+ /** Network error during transcription */
23
+ NETWORK_ERROR = "network_error",
24
+ /** Invalid request format */
25
+ INVALID_REQUEST = "invalid_request"
26
+ }
27
+ /**
28
+ * Error response format returned by the transcription endpoint.
29
+ */
30
+ interface TranscriptionErrorResponse {
31
+ error: TranscriptionErrorCode;
32
+ message: string;
33
+ retryable?: boolean;
34
+ }
35
+ /**
36
+ * Helper functions to create transcription error responses.
37
+ * Used by the runtime to return consistent error responses.
38
+ */
39
+ declare const TranscriptionErrors: {
40
+ serviceNotConfigured: () => TranscriptionErrorResponse;
41
+ invalidAudioFormat: (format: string, supported: string[]) => TranscriptionErrorResponse;
42
+ invalidRequest: (details: string) => TranscriptionErrorResponse;
43
+ rateLimited: () => TranscriptionErrorResponse;
44
+ authFailed: () => TranscriptionErrorResponse;
45
+ providerError: (message: string) => TranscriptionErrorResponse;
46
+ networkError: (message?: string) => TranscriptionErrorResponse;
47
+ audioTooLong: () => TranscriptionErrorResponse;
48
+ audioTooShort: () => TranscriptionErrorResponse;
49
+ };
50
+ //#endregion
51
+ export { TranscriptionErrorCode, TranscriptionErrorResponse, TranscriptionErrors };
52
+ //# sourceMappingURL=transcription-errors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcription-errors.d.cts","names":[],"sources":["../src/transcription-errors.ts"],"mappings":";;AAKA;;;;aAAY,sBAAA;EAIV;EAFA,sBAAA;EAMA;EAJA,oBAAA;EAQA;EANA,cAAA;EAUA;EARA,eAAA;EAUe;EARf,YAAA;EAce;EAZf,WAAA;;EAEA,cAAA;EAWA;EATA,aAAA;EAUA;EARA,eAAA;AAAA;;AAgBF;;UAViB,0BAAA;EACf,KAAA,EAAO,sBAAA;EACP,OAAA;EACA,SAAA;AAAA;;;;;cAOW,mBAAA;8BACe,0BAAA;uCAOV,SAAA,eAEb,0BAAA;uCAMgC,0BAAA;qBAMlB,0BAAA;oBAMD,0BAAA;sCAMkB,0BAAA;sCAQ/B,0BAAA;sBAMe,0BAAA;uBAMC,0BAAA;AAAA"}
@@ -0,0 +1,52 @@
1
+ //#region src/transcription-errors.d.ts
2
+ /**
3
+ * Error codes for transcription HTTP responses.
4
+ * Uses snake_case to align with existing CopilotKitCoreErrorCode pattern.
5
+ * These codes are returned by the runtime and parsed by the client.
6
+ */
7
+ declare enum TranscriptionErrorCode {
8
+ /** Transcription service not configured in runtime */
9
+ SERVICE_NOT_CONFIGURED = "service_not_configured",
10
+ /** Audio format not supported */
11
+ INVALID_AUDIO_FORMAT = "invalid_audio_format",
12
+ /** Audio file is too long */
13
+ AUDIO_TOO_LONG = "audio_too_long",
14
+ /** Audio file is empty or too short */
15
+ AUDIO_TOO_SHORT = "audio_too_short",
16
+ /** Rate limited by transcription provider */
17
+ RATE_LIMITED = "rate_limited",
18
+ /** Authentication failed with transcription provider */
19
+ AUTH_FAILED = "auth_failed",
20
+ /** Transcription provider returned an error */
21
+ PROVIDER_ERROR = "provider_error",
22
+ /** Network error during transcription */
23
+ NETWORK_ERROR = "network_error",
24
+ /** Invalid request format */
25
+ INVALID_REQUEST = "invalid_request"
26
+ }
27
+ /**
28
+ * Error response format returned by the transcription endpoint.
29
+ */
30
+ interface TranscriptionErrorResponse {
31
+ error: TranscriptionErrorCode;
32
+ message: string;
33
+ retryable?: boolean;
34
+ }
35
+ /**
36
+ * Helper functions to create transcription error responses.
37
+ * Used by the runtime to return consistent error responses.
38
+ */
39
+ declare const TranscriptionErrors: {
40
+ serviceNotConfigured: () => TranscriptionErrorResponse;
41
+ invalidAudioFormat: (format: string, supported: string[]) => TranscriptionErrorResponse;
42
+ invalidRequest: (details: string) => TranscriptionErrorResponse;
43
+ rateLimited: () => TranscriptionErrorResponse;
44
+ authFailed: () => TranscriptionErrorResponse;
45
+ providerError: (message: string) => TranscriptionErrorResponse;
46
+ networkError: (message?: string) => TranscriptionErrorResponse;
47
+ audioTooLong: () => TranscriptionErrorResponse;
48
+ audioTooShort: () => TranscriptionErrorResponse;
49
+ };
50
+ //#endregion
51
+ export { TranscriptionErrorCode, TranscriptionErrorResponse, TranscriptionErrors };
52
+ //# sourceMappingURL=transcription-errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcription-errors.d.mts","names":[],"sources":["../src/transcription-errors.ts"],"mappings":";;AAKA;;;;aAAY,sBAAA;EAIV;EAFA,sBAAA;EAMA;EAJA,oBAAA;EAQA;EANA,cAAA;EAUA;EARA,eAAA;EAUe;EARf,YAAA;EAce;EAZf,WAAA;;EAEA,cAAA;EAWA;EATA,aAAA;EAUA;EARA,eAAA;AAAA;;AAgBF;;UAViB,0BAAA;EACf,KAAA,EAAO,sBAAA;EACP,OAAA;EACA,SAAA;AAAA;;;;;cAOW,mBAAA;8BACe,0BAAA;uCAOV,SAAA,eAEb,0BAAA;uCAMgC,0BAAA;qBAMlB,0BAAA;oBAMD,0BAAA;sCAMkB,0BAAA;sCAQ/B,0BAAA;sBAMe,0BAAA;uBAMC,0BAAA;AAAA"}
@@ -0,0 +1,82 @@
1
+ //#region src/transcription-errors.ts
2
+ /**
3
+ * Error codes for transcription HTTP responses.
4
+ * Uses snake_case to align with existing CopilotKitCoreErrorCode pattern.
5
+ * These codes are returned by the runtime and parsed by the client.
6
+ */
7
+ let TranscriptionErrorCode = /* @__PURE__ */ function(TranscriptionErrorCode) {
8
+ /** Transcription service not configured in runtime */
9
+ TranscriptionErrorCode["SERVICE_NOT_CONFIGURED"] = "service_not_configured";
10
+ /** Audio format not supported */
11
+ TranscriptionErrorCode["INVALID_AUDIO_FORMAT"] = "invalid_audio_format";
12
+ /** Audio file is too long */
13
+ TranscriptionErrorCode["AUDIO_TOO_LONG"] = "audio_too_long";
14
+ /** Audio file is empty or too short */
15
+ TranscriptionErrorCode["AUDIO_TOO_SHORT"] = "audio_too_short";
16
+ /** Rate limited by transcription provider */
17
+ TranscriptionErrorCode["RATE_LIMITED"] = "rate_limited";
18
+ /** Authentication failed with transcription provider */
19
+ TranscriptionErrorCode["AUTH_FAILED"] = "auth_failed";
20
+ /** Transcription provider returned an error */
21
+ TranscriptionErrorCode["PROVIDER_ERROR"] = "provider_error";
22
+ /** Network error during transcription */
23
+ TranscriptionErrorCode["NETWORK_ERROR"] = "network_error";
24
+ /** Invalid request format */
25
+ TranscriptionErrorCode["INVALID_REQUEST"] = "invalid_request";
26
+ return TranscriptionErrorCode;
27
+ }({});
28
+ /**
29
+ * Helper functions to create transcription error responses.
30
+ * Used by the runtime to return consistent error responses.
31
+ */
32
+ const TranscriptionErrors = {
33
+ serviceNotConfigured: () => ({
34
+ error: TranscriptionErrorCode.SERVICE_NOT_CONFIGURED,
35
+ message: "Transcription service is not configured",
36
+ retryable: false
37
+ }),
38
+ invalidAudioFormat: (format, supported) => ({
39
+ error: TranscriptionErrorCode.INVALID_AUDIO_FORMAT,
40
+ message: `Unsupported audio format: ${format}. Supported: ${supported.join(", ")}`,
41
+ retryable: false
42
+ }),
43
+ invalidRequest: (details) => ({
44
+ error: TranscriptionErrorCode.INVALID_REQUEST,
45
+ message: details,
46
+ retryable: false
47
+ }),
48
+ rateLimited: () => ({
49
+ error: TranscriptionErrorCode.RATE_LIMITED,
50
+ message: "Rate limited. Please try again later.",
51
+ retryable: true
52
+ }),
53
+ authFailed: () => ({
54
+ error: TranscriptionErrorCode.AUTH_FAILED,
55
+ message: "Authentication failed with transcription provider",
56
+ retryable: false
57
+ }),
58
+ providerError: (message) => ({
59
+ error: TranscriptionErrorCode.PROVIDER_ERROR,
60
+ message,
61
+ retryable: true
62
+ }),
63
+ networkError: (message = "Network error during transcription") => ({
64
+ error: TranscriptionErrorCode.NETWORK_ERROR,
65
+ message,
66
+ retryable: true
67
+ }),
68
+ audioTooLong: () => ({
69
+ error: TranscriptionErrorCode.AUDIO_TOO_LONG,
70
+ message: "Audio file is too long",
71
+ retryable: false
72
+ }),
73
+ audioTooShort: () => ({
74
+ error: TranscriptionErrorCode.AUDIO_TOO_SHORT,
75
+ message: "Audio is too short to transcribe",
76
+ retryable: false
77
+ })
78
+ };
79
+
80
+ //#endregion
81
+ export { TranscriptionErrorCode, TranscriptionErrors };
82
+ //# sourceMappingURL=transcription-errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcription-errors.mjs","names":[],"sources":["../src/transcription-errors.ts"],"sourcesContent":["/**\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":";;;;;;AAKA,IAAY,0EAAL;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;;;;;;AAgBF,MAAa,sBAAsB;CACjC,6BAAyD;EACvD,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,qBACE,QACA,eACgC;EAChC,OAAO,uBAAuB;EAC9B,SAAS,6BAA6B,OAAO,eAAe,UAAU,KAAK,KAAK;EAChF,WAAW;EACZ;CAED,iBAAiB,aAAiD;EAChE,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,oBAAgD;EAC9C,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,mBAA+C;EAC7C,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,gBAAgB,aAAiD;EAC/D,OAAO,uBAAuB;EAC9B;EACA,WAAW;EACZ;CAED,eACE,UAAkB,0CACc;EAChC,OAAO,uBAAuB;EAC9B;EACA,WAAW;EACZ;CAED,qBAAiD;EAC/C,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CAED,sBAAkD;EAChD,OAAO,uBAAuB;EAC9B,SAAS;EACT,WAAW;EACZ;CACF"}
@@ -1,4 +1,4 @@
1
- import agui from "@ag-ui/core";
1
+ import * as agui from "@ag-ui/core";
2
2
 
3
3
  //#region src/types/message.d.ts
4
4
  interface ImageData {
@@ -1,4 +1,4 @@
1
- import agui from "@ag-ui/core";
1
+ import * as agui from "@ag-ui/core";
2
2
 
3
3
  //#region src/types/message.d.ts
4
4
  interface ImageData {
@@ -1,9 +1,13 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
1
2
  const require_conditions = require('./conditions.cjs');
2
3
  const require_console_styling = require('./console-styling.cjs');
3
4
  const require_errors = require('./errors.cjs');
4
5
  const require_json_schema = require('./json-schema.cjs');
6
+ const require_types = require('./types.cjs');
5
7
  const require_random_id = require('./random-id.cjs');
6
8
  const require_requests = require('./requests.cjs');
9
+ let partial_json = require("partial-json");
10
+ partial_json = require_runtime.__toESM(partial_json);
7
11
 
8
12
  //#region src/utils/index.ts
9
13
  /**
@@ -20,6 +24,32 @@ function parseJson(json, fallback = "unset") {
20
24
  }
21
25
  }
22
26
  /**
27
+ * Parses a partial/incomplete JSON string, returning as much valid data as possible.
28
+ * Falls back to an empty object if parsing fails entirely.
29
+ */
30
+ function partialJSONParse(json) {
31
+ try {
32
+ const parsed = partial_json.parse(json);
33
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
34
+ return {};
35
+ } catch (error) {
36
+ return {};
37
+ }
38
+ }
39
+ /**
40
+ * Returns an exponential backoff function suitable for Phoenix.js
41
+ * `reconnectAfterMs` and `rejoinAfterMs` options.
42
+ *
43
+ * @param baseMs - Initial delay for the first retry attempt.
44
+ * @param maxMs - Upper bound — delays are capped at this value.
45
+ *
46
+ * Phoenix calls the returned function with a 1-based `tries` count.
47
+ * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.
48
+ */
49
+ function phoenixExponentialBackoff(baseMs, maxMs) {
50
+ return (tries) => Math.min(baseMs * 2 ** (tries - 1), maxMs);
51
+ }
52
+ /**
23
53
  * Maps an array of items to a new array, skipping items that throw errors during mapping
24
54
  * @param items The array to map
25
55
  * @param callback The mapping function to apply to each item
@@ -42,9 +72,28 @@ function tryMap(items, callback) {
42
72
  function isMacOS() {
43
73
  return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
44
74
  }
75
+ /**
76
+ * Safely parses a JSON string into a tool arguments object.
77
+ * Returns the parsed object only if it's a plain object (not an array, null, etc.).
78
+ * Falls back to an empty object for any non-object JSON value or parse failure.
79
+ */
80
+ function safeParseToolArgs(raw) {
81
+ try {
82
+ const parsed = JSON.parse(raw);
83
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
84
+ console.warn(`[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`);
85
+ return {};
86
+ } catch {
87
+ console.warn("[CopilotKit] Failed to parse tool arguments, falling back to empty object");
88
+ return {};
89
+ }
90
+ }
45
91
 
46
92
  //#endregion
47
93
  exports.isMacOS = isMacOS;
48
94
  exports.parseJson = parseJson;
95
+ exports.partialJSONParse = partialJSONParse;
96
+ exports.phoenixExponentialBackoff = phoenixExponentialBackoff;
97
+ exports.safeParseToolArgs = safeParseToolArgs;
49
98
  exports.tryMap = tryMap;
50
99
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;;;AAUzC,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU"}
1
+ {"version":3,"file":"index.cjs","names":["PartialJSON"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch (error) {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;AAQzC,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAASA,aAAY,MAAM,KAAK;AACtC,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;UACF,OAAO;AACd,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"}
@@ -2,7 +2,7 @@ import { BaseCondition, ComparisonCondition, ComparisonRule, Condition, Existenc
2
2
  import { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole } from "./console-styling.cjs";
3
3
  import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from "./errors.cjs";
4
4
  import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.cjs";
5
- import { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from "./types.cjs";
5
+ import { AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode } from "./types.cjs";
6
6
  import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.cjs";
7
7
  import { readBody } from "./requests.cjs";
8
8
 
@@ -14,6 +14,22 @@ import { readBody } from "./requests.cjs";
14
14
  * @returns The parsed JSON object, or the fallback value (or null) if parsing fails
15
15
  */
16
16
  declare function parseJson(json: string, fallback?: any): any;
17
+ /**
18
+ * Parses a partial/incomplete JSON string, returning as much valid data as possible.
19
+ * Falls back to an empty object if parsing fails entirely.
20
+ */
21
+ declare function partialJSONParse(json: string): any;
22
+ /**
23
+ * Returns an exponential backoff function suitable for Phoenix.js
24
+ * `reconnectAfterMs` and `rejoinAfterMs` options.
25
+ *
26
+ * @param baseMs - Initial delay for the first retry attempt.
27
+ * @param maxMs - Upper bound — delays are capped at this value.
28
+ *
29
+ * Phoenix calls the returned function with a 1-based `tries` count.
30
+ * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.
31
+ */
32
+ declare function phoenixExponentialBackoff(baseMs: number, maxMs: number): (tries: number) => number;
17
33
  /**
18
34
  * Maps an array of items to a new array, skipping items that throw errors during mapping
19
35
  * @param items The array to map
@@ -26,6 +42,12 @@ declare function tryMap<TItem, TMapped>(items: TItem[], callback: (item: TItem,
26
42
  * @returns {boolean} True if running on macOS, false otherwise
27
43
  */
28
44
  declare function isMacOS(): boolean;
45
+ /**
46
+ * Safely parses a JSON string into a tool arguments object.
47
+ * Returns the parsed object only if it's a plain object (not an array, null, etc.).
48
+ * Falls back to an empty object for any non-object JSON value or parse failure.
49
+ */
50
+ declare function safeParseToolArgs(raw: string): Record<string, unknown>;
29
51
  //#endregion
30
- export { isMacOS, parseJson, tryMap };
52
+ export { isMacOS, parseJson, partialJSONParse, phoenixExponentialBackoff, safeParseToolArgs, tryMap };
31
53
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;AAcA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAcxC;;;;;;AAAA,iBAAgB,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;AAgBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAYxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"}
@@ -2,7 +2,7 @@ import { BaseCondition, ComparisonCondition, ComparisonRule, Condition, Existenc
2
2
  import { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole } from "./console-styling.mjs";
3
3
  import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from "./errors.mjs";
4
4
  import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.mjs";
5
- import { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from "./types.mjs";
5
+ import { AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode } from "./types.mjs";
6
6
  import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.mjs";
7
7
  import { readBody } from "./requests.mjs";
8
8
 
@@ -14,6 +14,22 @@ import { readBody } from "./requests.mjs";
14
14
  * @returns The parsed JSON object, or the fallback value (or null) if parsing fails
15
15
  */
16
16
  declare function parseJson(json: string, fallback?: any): any;
17
+ /**
18
+ * Parses a partial/incomplete JSON string, returning as much valid data as possible.
19
+ * Falls back to an empty object if parsing fails entirely.
20
+ */
21
+ declare function partialJSONParse(json: string): any;
22
+ /**
23
+ * Returns an exponential backoff function suitable for Phoenix.js
24
+ * `reconnectAfterMs` and `rejoinAfterMs` options.
25
+ *
26
+ * @param baseMs - Initial delay for the first retry attempt.
27
+ * @param maxMs - Upper bound — delays are capped at this value.
28
+ *
29
+ * Phoenix calls the returned function with a 1-based `tries` count.
30
+ * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.
31
+ */
32
+ declare function phoenixExponentialBackoff(baseMs: number, maxMs: number): (tries: number) => number;
17
33
  /**
18
34
  * Maps an array of items to a new array, skipping items that throw errors during mapping
19
35
  * @param items The array to map
@@ -26,6 +42,12 @@ declare function tryMap<TItem, TMapped>(items: TItem[], callback: (item: TItem,
26
42
  * @returns {boolean} True if running on macOS, false otherwise
27
43
  */
28
44
  declare function isMacOS(): boolean;
45
+ /**
46
+ * Safely parses a JSON string into a tool arguments object.
47
+ * Returns the parsed object only if it's a plain object (not an array, null, etc.).
48
+ * Falls back to an empty object for any non-object JSON value or parse failure.
49
+ */
50
+ declare function safeParseToolArgs(raw: string): Record<string, unknown>;
29
51
  //#endregion
30
- export { isMacOS, parseJson, tryMap };
52
+ export { isMacOS, parseJson, partialJSONParse, phoenixExponentialBackoff, safeParseToolArgs, tryMap };
31
53
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;AAcA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAcxC;;;;;;AAAA,iBAAgB,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;AAgBA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAYxC;;;;AAAA,iBAAgB,gBAAA,CAAiB,IAAA;AAsBjC;;;;;;;;;AAaA;AAbA,iBAAgB,yBAAA,CACd,MAAA,UACA,KAAA,YACE,KAAA;;;;;;;iBAUY,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA;;;;;;iBASA,iBAAA,CAAkB,GAAA,WAAc,MAAA"}
@@ -2,8 +2,10 @@ import { executeConditions } from "./conditions.mjs";
2
2
  import { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole } from "./console-styling.mjs";
3
3
  import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from "./errors.mjs";
4
4
  import { actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.mjs";
5
+ import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "./types.mjs";
5
6
  import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.mjs";
6
7
  import { readBody } from "./requests.mjs";
8
+ import * as PartialJSON from "partial-json";
7
9
 
8
10
  //#region src/utils/index.ts
9
11
  /**
@@ -20,6 +22,32 @@ function parseJson(json, fallback = "unset") {
20
22
  }
21
23
  }
22
24
  /**
25
+ * Parses a partial/incomplete JSON string, returning as much valid data as possible.
26
+ * Falls back to an empty object if parsing fails entirely.
27
+ */
28
+ function partialJSONParse(json) {
29
+ try {
30
+ const parsed = PartialJSON.parse(json);
31
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
32
+ return {};
33
+ } catch (error) {
34
+ return {};
35
+ }
36
+ }
37
+ /**
38
+ * Returns an exponential backoff function suitable for Phoenix.js
39
+ * `reconnectAfterMs` and `rejoinAfterMs` options.
40
+ *
41
+ * @param baseMs - Initial delay for the first retry attempt.
42
+ * @param maxMs - Upper bound — delays are capped at this value.
43
+ *
44
+ * Phoenix calls the returned function with a 1-based `tries` count.
45
+ * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.
46
+ */
47
+ function phoenixExponentialBackoff(baseMs, maxMs) {
48
+ return (tries) => Math.min(baseMs * 2 ** (tries - 1), maxMs);
49
+ }
50
+ /**
23
51
  * Maps an array of items to a new array, skipping items that throw errors during mapping
24
52
  * @param items The array to map
25
53
  * @param callback The mapping function to apply to each item
@@ -42,7 +70,23 @@ function tryMap(items, callback) {
42
70
  function isMacOS() {
43
71
  return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
44
72
  }
73
+ /**
74
+ * Safely parses a JSON string into a tool arguments object.
75
+ * Returns the parsed object only if it's a plain object (not an array, null, etc.).
76
+ * Falls back to an empty object for any non-object JSON value or parse failure.
77
+ */
78
+ function safeParseToolArgs(raw) {
79
+ try {
80
+ const parsed = JSON.parse(raw);
81
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
82
+ console.warn(`[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`);
83
+ return {};
84
+ } catch {
85
+ console.warn("[CopilotKit] Failed to parse tool arguments, falling back to empty object");
86
+ return {};
87
+ }
88
+ }
45
89
 
46
90
  //#endregion
47
- export { isMacOS, parseJson, tryMap };
91
+ export { isMacOS, parseJson, partialJSONParse, phoenixExponentialBackoff, safeParseToolArgs, tryMap };
48
92
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;;;AAUzC,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\nimport * as PartialJSON from \"partial-json\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Parses a partial/incomplete JSON string, returning as much valid data as possible.\n * Falls back to an empty object if parsing fails entirely.\n */\nexport function partialJSONParse(json: string) {\n try {\n const parsed = PartialJSON.parse(json);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n return {};\n } catch (error) {\n return {};\n }\n}\n\n/**\n * Returns an exponential backoff function suitable for Phoenix.js\n * `reconnectAfterMs` and `rejoinAfterMs` options.\n *\n * @param baseMs - Initial delay for the first retry attempt.\n * @param maxMs - Upper bound — delays are capped at this value.\n *\n * Phoenix calls the returned function with a 1-based `tries` count.\n * The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.\n */\nexport function phoenixExponentialBackoff(\n baseMs: number,\n maxMs: number,\n): (tries: number) => number {\n return (tries: number) => Math.min(baseMs * 2 ** (tries - 1), maxMs);\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n\n/**\n * Safely parses a JSON string into a tool arguments object.\n * Returns the parsed object only if it's a plain object (not an array, null, etc.).\n * Falls back to an empty object for any non-object JSON value or parse failure.\n */\nexport function safeParseToolArgs(raw: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed;\n }\n console.warn(\n `[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`,\n );\n return {};\n } catch {\n console.warn(\n \"[CopilotKit] Failed to parse tool arguments, falling back to empty object\",\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;AAQzC,SAAgB,iBAAiB,MAAc;AAC7C,KAAI;EACF,MAAM,SAAS,YAAY,MAAM,KAAK;AACtC,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,SAAO,EAAE;UACF,OAAO;AACd,SAAO,EAAE;;;;;;;;;;;;;AAcb,SAAgB,0BACd,QACA,OAC2B;AAC3B,SAAQ,UAAkB,KAAK,IAAI,SAAS,MAAM,QAAQ,IAAI,MAAM;;;;;;;;AAStE,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU;;;;;;;AAQxD,SAAgB,kBAAkB,KAAsC;AACtE,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAChE,QAAO;AAET,UAAQ,KACN,qDAAqD,OAAO,OAAO,iCACpE;AACD,SAAO,EAAE;SACH;AACN,UAAQ,KACN,4EACD;AACD,SAAO,EAAE"}
@@ -0,0 +1,9 @@
1
+
2
+ //#region src/utils/types.ts
3
+ const RUNTIME_MODE_SSE = "sse";
4
+ const RUNTIME_MODE_INTELLIGENCE = "intelligence";
5
+
6
+ //#endregion
7
+ exports.RUNTIME_MODE_INTELLIGENCE = RUNTIME_MODE_INTELLIGENCE;
8
+ exports.RUNTIME_MODE_SSE = RUNTIME_MODE_SSE;
9
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["export type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown>\n ? keyof T extends never\n ? never\n : T\n : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n}\n\nexport type RuntimeMode = \"sse\" | \"intelligence\";\n\nexport const RUNTIME_MODE_SSE = \"sse\" as const;\nexport const RUNTIME_MODE_INTELLIGENCE = \"intelligence\" as const;\n\nexport interface IntelligenceRuntimeInfo {\n wsUrl: string;\n}\n\nexport type RuntimeLicenseStatus =\n | \"valid\"\n | \"none\"\n | \"expired\"\n | \"expiring\"\n | \"invalid\"\n | \"unknown\";\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n mode: RuntimeMode;\n intelligence?: IntelligenceRuntimeInfo;\n a2uiEnabled?: boolean;\n licenseStatus?: RuntimeLicenseStatus;\n}\n"],"mappings":";;AAuBA,MAAa,mBAAmB;AAChC,MAAa,4BAA4B"}
@@ -12,11 +12,22 @@ interface AgentDescription {
12
12
  className: string;
13
13
  description: string;
14
14
  }
15
+ type RuntimeMode = "sse" | "intelligence";
16
+ declare const RUNTIME_MODE_SSE: "sse";
17
+ declare const RUNTIME_MODE_INTELLIGENCE: "intelligence";
18
+ interface IntelligenceRuntimeInfo {
19
+ wsUrl: string;
20
+ }
21
+ type RuntimeLicenseStatus = "valid" | "none" | "expired" | "expiring" | "invalid" | "unknown";
15
22
  interface RuntimeInfo {
16
23
  version: string;
17
24
  agents: Record<string, AgentDescription>;
18
25
  audioFileTranscriptionEnabled: boolean;
26
+ mode: RuntimeMode;
27
+ intelligence?: IntelligenceRuntimeInfo;
28
+ a2uiEnabled?: boolean;
29
+ licenseStatus?: RuntimeLicenseStatus;
19
30
  }
20
31
  //#endregion
21
- export { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo };
32
+ export { AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode };
22
33
  //# sourceMappingURL=types.d.cts.map