@copilotkit/runtime 1.9.2-next.1 → 1.9.2-next.11

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 (84) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/dist/chunk-AMUJQ6IR.mjs +50 -0
  3. package/dist/chunk-AMUJQ6IR.mjs.map +1 -0
  4. package/dist/{chunk-C3SWOFLO.mjs → chunk-B2BL6HPT.mjs} +2 -2
  5. package/dist/{chunk-RIPQZJB5.mjs → chunk-CBVVBPVJ.mjs} +2 -2
  6. package/dist/{chunk-IIXJVVTV.mjs → chunk-GS7DO47Q.mjs} +155 -78
  7. package/dist/chunk-GS7DO47Q.mjs.map +1 -0
  8. package/dist/{chunk-XGBY45FP.mjs → chunk-NI7RVCMB.mjs} +2343 -1857
  9. package/dist/chunk-NI7RVCMB.mjs.map +1 -0
  10. package/dist/{chunk-YV3YXRMR.mjs → chunk-VVXCPFVN.mjs} +19 -2
  11. package/dist/chunk-VVXCPFVN.mjs.map +1 -0
  12. package/dist/{chunk-5BIEM2UU.mjs → chunk-XWBDEXDA.mjs} +4 -3
  13. package/dist/{chunk-5BIEM2UU.mjs.map → chunk-XWBDEXDA.mjs.map} +1 -1
  14. package/dist/{chunk-KPFOAXRX.mjs → chunk-ZIEDTGZF.mjs} +2 -2
  15. package/dist/{groq-adapter-25a2bd35.d.ts → groq-adapter-172a2ca4.d.ts} +1 -1
  16. package/dist/index.d.ts +4 -3
  17. package/dist/index.js +3487 -2863
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +12 -8
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/lib/index.d.ts +7 -133
  22. package/dist/lib/index.js +3329 -2748
  23. package/dist/lib/index.js.map +1 -1
  24. package/dist/lib/index.mjs +9 -8
  25. package/dist/lib/integrations/index.d.ts +3 -3
  26. package/dist/lib/integrations/index.js +162 -98
  27. package/dist/lib/integrations/index.js.map +1 -1
  28. package/dist/lib/integrations/index.mjs +7 -6
  29. package/dist/lib/integrations/nest/index.d.ts +2 -2
  30. package/dist/lib/integrations/nest/index.js +162 -98
  31. package/dist/lib/integrations/nest/index.js.map +1 -1
  32. package/dist/lib/integrations/nest/index.mjs +5 -4
  33. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  34. package/dist/lib/integrations/node-express/index.js +162 -98
  35. package/dist/lib/integrations/node-express/index.js.map +1 -1
  36. package/dist/lib/integrations/node-express/index.mjs +5 -4
  37. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  38. package/dist/lib/integrations/node-http/index.js +162 -98
  39. package/dist/lib/integrations/node-http/index.js.map +1 -1
  40. package/dist/lib/integrations/node-http/index.mjs +4 -3
  41. package/dist/service-adapters/index.d.ts +6 -4
  42. package/dist/service-adapters/index.js +225 -107
  43. package/dist/service-adapters/index.js.map +1 -1
  44. package/dist/service-adapters/index.mjs +6 -2
  45. package/dist/service-adapters/shared/index.d.ts +9 -0
  46. package/dist/service-adapters/shared/index.js +72 -0
  47. package/dist/service-adapters/shared/index.js.map +1 -0
  48. package/dist/service-adapters/shared/index.mjs +8 -0
  49. package/dist/service-adapters/shared/index.mjs.map +1 -0
  50. package/dist/{shared-e272b15a.d.ts → shared-4164c674.d.ts} +45 -5
  51. package/dist/utils/index.d.ts +17 -1
  52. package/dist/utils/index.js +3 -2
  53. package/dist/utils/index.js.map +1 -1
  54. package/dist/utils/index.mjs +1 -1
  55. package/package.json +4 -4
  56. package/src/agents/langgraph/event-source.ts +36 -38
  57. package/src/agents/langgraph/events.ts +19 -1
  58. package/src/graphql/resolvers/copilot.resolver.ts +108 -45
  59. package/src/graphql/resolvers/state.resolver.ts +3 -3
  60. package/src/lib/error-messages.ts +200 -0
  61. package/src/lib/integrations/shared.ts +43 -0
  62. package/src/lib/runtime/__tests__/copilot-runtime-trace.test.ts +169 -0
  63. package/src/lib/runtime/copilot-runtime.ts +383 -83
  64. package/src/lib/runtime/langgraph/langgraph-agent.ts +12 -0
  65. package/src/lib/runtime/remote-action-constructors.ts +28 -3
  66. package/src/lib/runtime/remote-lg-action.ts +130 -40
  67. package/src/lib/streaming.ts +125 -36
  68. package/src/service-adapters/anthropic/anthropic-adapter.ts +67 -8
  69. package/src/service-adapters/anthropic/utils.ts +3 -8
  70. package/src/service-adapters/events.ts +37 -81
  71. package/src/service-adapters/groq/groq-adapter.ts +66 -56
  72. package/src/service-adapters/index.ts +1 -0
  73. package/src/service-adapters/openai/openai-adapter.ts +18 -3
  74. package/src/service-adapters/shared/error-utils.ts +61 -0
  75. package/src/service-adapters/shared/index.ts +1 -0
  76. package/src/utils/failed-response-status-reasons.ts +23 -1
  77. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +172 -387
  78. package/dist/chunk-IIXJVVTV.mjs.map +0 -1
  79. package/dist/chunk-XGBY45FP.mjs.map +0 -1
  80. package/dist/chunk-YV3YXRMR.mjs.map +0 -1
  81. package/dist/{chunk-C3SWOFLO.mjs.map → chunk-B2BL6HPT.mjs.map} +0 -0
  82. package/dist/{chunk-RIPQZJB5.mjs.map → chunk-CBVVBPVJ.mjs.map} +0 -0
  83. package/dist/{chunk-KPFOAXRX.mjs.map → chunk-ZIEDTGZF.mjs.map} +0 -0
  84. package/dist/{langserve-4a5c9217.d.ts → langserve-fc5cac89.d.ts} +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,78 @@
1
1
  # @copilotkit/runtime
2
2
 
3
+ ## 1.9.2-next.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 1f4949a: - fix: remove agent discovery for agui agents
8
+ - @copilotkit/shared@1.9.2-next.11
9
+
10
+ ## 1.9.2-next.10
11
+
12
+ ### Patch Changes
13
+
14
+ - 20e8c3c: - fix(anthropic-adapter): resolve infinite loop caused by duplicate result messages
15
+ - @copilotkit/shared@1.9.2-next.10
16
+
17
+ ## 1.9.2-next.9
18
+
19
+ ### Patch Changes
20
+
21
+ - 1d1c51d: - feat: surface all errors in structured format
22
+ - Updated dependencies [1d1c51d]
23
+ - @copilotkit/shared@1.9.2-next.9
24
+
25
+ ## 1.9.2-next.8
26
+
27
+ ### Patch Changes
28
+
29
+ - 9b986ba: - fix: use active interrupt from thread instead of saving to global state
30
+ - @copilotkit/shared@1.9.2-next.8
31
+
32
+ ## 1.9.2-next.7
33
+
34
+ ### Patch Changes
35
+
36
+ - 54b62f0: - fix: add default schema keys for input and output of agui langgraph
37
+ - @copilotkit/shared@1.9.2-next.7
38
+
39
+ ## 1.9.2-next.6
40
+
41
+ ### Patch Changes
42
+
43
+ - 4fd92d1: - fix: enable resolving of langgraph agents when cpk starts
44
+ - @copilotkit/shared@1.9.2-next.6
45
+
46
+ ## 1.9.2-next.5
47
+
48
+ ### Patch Changes
49
+
50
+ - @copilotkit/shared@1.9.2-next.5
51
+
52
+ ## 1.9.2-next.4
53
+
54
+ ### Patch Changes
55
+
56
+ - 9169ad7: - feat: add onTrace handler for runtime and UI error/event tracking
57
+ - 9169ad7: - feat: add onTrace handler for comprehensive debugging and observability - Add CopilotTraceEvent interfaces with rich debugging context, implement runtime-side tracing with publicApiKey gating, add UI-side error tracing, include comprehensive test coverage, and fix tsup build config to exclude test files
58
+ - fix: extract publicApiKey for all requests + trace GraphQL errors
59
+ - Updated dependencies [9169ad7]
60
+ - Updated dependencies [9169ad7]
61
+ - @copilotkit/shared@1.9.2-next.4
62
+
63
+ ## 1.9.2-next.3
64
+
65
+ ### Patch Changes
66
+
67
+ - @copilotkit/shared@1.9.2-next.3
68
+
69
+ ## 1.9.2-next.2
70
+
71
+ ### Patch Changes
72
+
73
+ - 9b81464: - fix: use latest langgraph agui
74
+ - @copilotkit/shared@1.9.2-next.2
75
+
3
76
  ## 1.9.2-next.1
4
77
 
5
78
  ### Patch Changes
@@ -0,0 +1,50 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-FHD4JECV.mjs";
4
+
5
+ // src/service-adapters/shared/error-utils.ts
6
+ import { CopilotKitLowLevelError, CopilotKitErrorCode } from "@copilotkit/shared";
7
+ function convertServiceAdapterError(error, adapterName) {
8
+ var _a, _b, _c;
9
+ const errorName = ((_a = error == null ? void 0 : error.constructor) == null ? void 0 : _a.name) || error.name;
10
+ const errorMessage = (error == null ? void 0 : error.message) || String(error);
11
+ const statusCode = error.status || error.statusCode || ((_b = error.response) == null ? void 0 : _b.status);
12
+ const responseData = error.error || ((_c = error.response) == null ? void 0 : _c.data) || error.data;
13
+ const structuredError = new CopilotKitLowLevelError({
14
+ error: error instanceof Error ? error : new Error(errorMessage),
15
+ url: `${adapterName} service adapter`,
16
+ message: `${adapterName} API error: ${errorMessage}`
17
+ });
18
+ if (statusCode) {
19
+ structuredError.statusCode = statusCode;
20
+ }
21
+ if (responseData) {
22
+ structuredError.responseData = responseData;
23
+ }
24
+ if (errorName) {
25
+ structuredError.originalErrorType = errorName;
26
+ }
27
+ let newCode;
28
+ if (statusCode === 401) {
29
+ newCode = CopilotKitErrorCode.AUTHENTICATION_ERROR;
30
+ } else if (statusCode >= 400 && statusCode < 500) {
31
+ newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;
32
+ } else if (statusCode >= 500) {
33
+ newCode = CopilotKitErrorCode.NETWORK_ERROR;
34
+ } else if (statusCode) {
35
+ newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;
36
+ } else {
37
+ newCode = CopilotKitErrorCode.NETWORK_ERROR;
38
+ }
39
+ structuredError.code = newCode;
40
+ if (structuredError.extensions) {
41
+ structuredError.extensions.code = newCode;
42
+ }
43
+ return structuredError;
44
+ }
45
+ __name(convertServiceAdapterError, "convertServiceAdapterError");
46
+
47
+ export {
48
+ convertServiceAdapterError
49
+ };
50
+ //# sourceMappingURL=chunk-AMUJQ6IR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/service-adapters/shared/error-utils.ts"],"sourcesContent":["import { CopilotKitLowLevelError, CopilotKitErrorCode } from \"@copilotkit/shared\";\n\n/**\n * Converts service adapter errors to structured CopilotKitError format using HTTP status codes.\n * This provides consistent error classification across all service adapters.\n */\nexport function convertServiceAdapterError(\n error: any,\n adapterName: string,\n): CopilotKitLowLevelError {\n const errorName = error?.constructor?.name || error.name;\n const errorMessage = error?.message || String(error);\n const statusCode = error.status || error.statusCode || error.response?.status;\n const responseData = error.error || error.response?.data || error.data;\n\n // Create the base error with the constructor signature\n const structuredError = new CopilotKitLowLevelError({\n error: error instanceof Error ? error : new Error(errorMessage),\n url: `${adapterName} service adapter`,\n message: `${adapterName} API error: ${errorMessage}`,\n });\n\n // Add additional properties after construction\n if (statusCode) {\n (structuredError as any).statusCode = statusCode;\n }\n if (responseData) {\n (structuredError as any).responseData = responseData;\n }\n if (errorName) {\n (structuredError as any).originalErrorType = errorName;\n }\n\n // Classify error based on HTTP status codes (reliable and provider-agnostic)\n let newCode: CopilotKitErrorCode;\n\n if (statusCode === 401) {\n // 401 = Authentication/API key issues\n newCode = CopilotKitErrorCode.AUTHENTICATION_ERROR;\n } else if (statusCode >= 400 && statusCode < 500) {\n // 4xx = Client errors (bad request, invalid params, etc.) - these are configuration issues\n newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;\n } else if (statusCode >= 500) {\n // 5xx = Server errors - keep as NETWORK_ERROR since it's infrastructure related\n newCode = CopilotKitErrorCode.NETWORK_ERROR;\n } else if (statusCode) {\n // Any other HTTP status with an error - likely configuration\n newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;\n } else {\n // No status code - likely a genuine network/connection error\n newCode = CopilotKitErrorCode.NETWORK_ERROR;\n }\n\n // Update both the instance property and the extensions\n (structuredError as any).code = newCode;\n if ((structuredError as any).extensions) {\n (structuredError as any).extensions.code = newCode;\n }\n\n return structuredError;\n}\n"],"mappings":";;;;;AAAA,SAASA,yBAAyBC,2BAA2B;AAMtD,SAASC,2BACdC,OACAC,aAAmB;AARrB;AAUE,QAAMC,cAAYF,oCAAOG,gBAAPH,mBAAoBI,SAAQJ,MAAMI;AACpD,QAAMC,gBAAeL,+BAAOM,YAAWC,OAAOP,KAAAA;AAC9C,QAAMQ,aAAaR,MAAMS,UAAUT,MAAMQ,gBAAcR,WAAMU,aAANV,mBAAgBS;AACvE,QAAME,eAAeX,MAAMA,WAASA,WAAMU,aAANV,mBAAgBY,SAAQZ,MAAMY;AAGlE,QAAMC,kBAAkB,IAAIC,wBAAwB;IAClDd,OAAOA,iBAAiBe,QAAQf,QAAQ,IAAIe,MAAMV,YAAAA;IAClDW,KAAK,GAAGf;IACRK,SAAS,GAAGL,0BAA0BI;EACxC,CAAA;AAGA,MAAIG,YAAY;AACbK,oBAAwBL,aAAaA;EACxC;AACA,MAAIG,cAAc;AACfE,oBAAwBF,eAAeA;EAC1C;AACA,MAAIT,WAAW;AACZW,oBAAwBI,oBAAoBf;EAC/C;AAGA,MAAIgB;AAEJ,MAAIV,eAAe,KAAK;AAEtBU,cAAUC,oBAAoBC;EAChC,WAAWZ,cAAc,OAAOA,aAAa,KAAK;AAEhDU,cAAUC,oBAAoBE;EAChC,WAAWb,cAAc,KAAK;AAE5BU,cAAUC,oBAAoBG;EAChC,WAAWd,YAAY;AAErBU,cAAUC,oBAAoBE;EAChC,OAAO;AAELH,cAAUC,oBAAoBG;EAChC;AAGCT,kBAAwBU,OAAOL;AAChC,MAAKL,gBAAwBW,YAAY;AACtCX,oBAAwBW,WAAWD,OAAOL;EAC7C;AAEA,SAAOL;AACT;AAtDgBd;","names":["CopilotKitLowLevelError","CopilotKitErrorCode","convertServiceAdapterError","error","adapterName","errorName","constructor","name","errorMessage","message","String","statusCode","status","response","responseData","data","structuredError","CopilotKitLowLevelError","Error","url","originalErrorType","newCode","CopilotKitErrorCode","AUTHENTICATION_ERROR","CONFIGURATION_ERROR","NETWORK_ERROR","code","extensions"]}
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-XGBY45FP.mjs";
5
+ } from "./chunk-NI7RVCMB.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
22
22
  export {
23
23
  copilotRuntimeNestEndpoint
24
24
  };
25
- //# sourceMappingURL=chunk-C3SWOFLO.mjs.map
25
+ //# sourceMappingURL=chunk-B2BL6HPT.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  getCommonConfig,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-XGBY45FP.mjs";
5
+ } from "./chunk-NI7RVCMB.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -77,4 +77,4 @@ export {
77
77
  config,
78
78
  copilotRuntimeNextJSPagesRouterEndpoint
79
79
  };
80
- //# sourceMappingURL=chunk-RIPQZJB5.mjs.map
80
+ //# sourceMappingURL=chunk-CBVVBPVJ.mjs.map
@@ -1,3 +1,6 @@
1
+ import {
2
+ convertServiceAdapterError
3
+ } from "./chunk-AMUJQ6IR.mjs";
1
4
  import {
2
5
  __name
3
6
  } from "./chunk-FHD4JECV.mjs";
@@ -288,6 +291,7 @@ var OpenAIAdapter = class {
288
291
  const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
289
292
  const tools = actions.map(convertActionInputToOpenAITool);
290
293
  const threadId = threadIdFromRequest ?? randomUUID();
294
+ console.log("messages", messages);
291
295
  const validToolUseIds = /* @__PURE__ */ new Set();
292
296
  for (const message of messages) {
293
297
  if (message.isActionExecutionMessage()) {
@@ -317,6 +321,29 @@ var OpenAIAdapter = class {
317
321
  }
318
322
  };
319
323
  }
324
+ console.log("INPUT", {
325
+ model,
326
+ stream: true,
327
+ messages: openaiMessages,
328
+ ...tools.length > 0 && {
329
+ tools
330
+ },
331
+ ...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
332
+ max_tokens: forwardedParameters.maxTokens
333
+ },
334
+ ...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
335
+ stop: forwardedParameters.stop
336
+ },
337
+ ...toolChoice && {
338
+ tool_choice: toolChoice
339
+ },
340
+ ...this.disableParallelToolCalls && {
341
+ parallel_tool_calls: false
342
+ },
343
+ ...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
344
+ temperature: forwardedParameters.temperature
345
+ }
346
+ });
320
347
  try {
321
348
  const stream = this.openai.beta.chat.completions.stream({
322
349
  model,
@@ -403,14 +430,14 @@ var OpenAIAdapter = class {
403
430
  });
404
431
  }
405
432
  } catch (error) {
406
- console.error("[OpenAI] Error processing stream:", error);
407
- throw error;
433
+ console.error("[OpenAI] Error during API call:", error);
434
+ throw convertServiceAdapterError(error, "OpenAI");
408
435
  }
409
436
  eventStream$.complete();
410
437
  });
411
438
  } catch (error) {
412
439
  console.error("[OpenAI] Error during API call:", error);
413
- throw error;
440
+ throw convertServiceAdapterError(error, "OpenAI");
414
441
  }
415
442
  return {
416
443
  threadId
@@ -1064,85 +1091,94 @@ var GroqAdapter = class {
1064
1091
  }
1065
1092
  };
1066
1093
  }
1067
- const stream = await this.groq.chat.completions.create({
1068
- model,
1069
- stream: true,
1070
- messages: openaiMessages,
1071
- ...tools.length > 0 && {
1072
- tools
1073
- },
1074
- ...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
1075
- max_tokens: forwardedParameters.maxTokens
1076
- },
1077
- ...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
1078
- stop: forwardedParameters.stop
1079
- },
1080
- ...toolChoice && {
1081
- tool_choice: toolChoice
1082
- },
1083
- ...this.disableParallelToolCalls && {
1084
- parallel_tool_calls: false
1085
- },
1086
- ...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
1087
- temperature: forwardedParameters.temperature
1088
- }
1089
- });
1094
+ let stream;
1095
+ try {
1096
+ stream = await this.groq.chat.completions.create({
1097
+ model,
1098
+ stream: true,
1099
+ messages: openaiMessages,
1100
+ ...tools.length > 0 && {
1101
+ tools
1102
+ },
1103
+ ...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
1104
+ max_tokens: forwardedParameters.maxTokens
1105
+ },
1106
+ ...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
1107
+ stop: forwardedParameters.stop
1108
+ },
1109
+ ...toolChoice && {
1110
+ tool_choice: toolChoice
1111
+ },
1112
+ ...this.disableParallelToolCalls && {
1113
+ parallel_tool_calls: false
1114
+ },
1115
+ ...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
1116
+ temperature: forwardedParameters.temperature
1117
+ }
1118
+ });
1119
+ } catch (error) {
1120
+ throw convertServiceAdapterError(error, "Groq");
1121
+ }
1090
1122
  eventSource.stream(async (eventStream$) => {
1091
1123
  var _a, _b;
1092
1124
  let mode = null;
1093
1125
  let currentMessageId;
1094
1126
  let currentToolCallId;
1095
- for await (const chunk of stream) {
1096
- const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
1097
- const content = chunk.choices[0].delta.content;
1098
- if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
1099
- mode = null;
1100
- eventStream$.sendTextMessageEnd({
1101
- messageId: currentMessageId
1102
- });
1103
- } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
1104
- mode = null;
1105
- eventStream$.sendActionExecutionEnd({
1106
- actionExecutionId: currentToolCallId
1107
- });
1108
- }
1109
- if (mode === null) {
1110
- if (toolCall == null ? void 0 : toolCall.id) {
1111
- mode = "function";
1112
- currentToolCallId = toolCall.id;
1113
- eventStream$.sendActionExecutionStart({
1114
- actionExecutionId: currentToolCallId,
1115
- actionName: toolCall.function.name,
1116
- parentMessageId: chunk.id
1117
- });
1118
- } else if (content) {
1119
- mode = "message";
1120
- currentMessageId = chunk.id;
1121
- eventStream$.sendTextMessageStart({
1127
+ try {
1128
+ for await (const chunk of stream) {
1129
+ const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
1130
+ const content = chunk.choices[0].delta.content;
1131
+ if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
1132
+ mode = null;
1133
+ eventStream$.sendTextMessageEnd({
1122
1134
  messageId: currentMessageId
1123
1135
  });
1136
+ } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
1137
+ mode = null;
1138
+ eventStream$.sendActionExecutionEnd({
1139
+ actionExecutionId: currentToolCallId
1140
+ });
1141
+ }
1142
+ if (mode === null) {
1143
+ if (toolCall == null ? void 0 : toolCall.id) {
1144
+ mode = "function";
1145
+ currentToolCallId = toolCall.id;
1146
+ eventStream$.sendActionExecutionStart({
1147
+ actionExecutionId: currentToolCallId,
1148
+ actionName: toolCall.function.name,
1149
+ parentMessageId: chunk.id
1150
+ });
1151
+ } else if (content) {
1152
+ mode = "message";
1153
+ currentMessageId = chunk.id;
1154
+ eventStream$.sendTextMessageStart({
1155
+ messageId: currentMessageId
1156
+ });
1157
+ }
1158
+ }
1159
+ if (mode === "message" && content) {
1160
+ eventStream$.sendTextMessageContent({
1161
+ messageId: currentMessageId,
1162
+ content
1163
+ });
1164
+ } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
1165
+ eventStream$.sendActionExecutionArgs({
1166
+ actionExecutionId: currentToolCallId,
1167
+ args: toolCall.function.arguments
1168
+ });
1124
1169
  }
1125
1170
  }
1126
- if (mode === "message" && content) {
1127
- eventStream$.sendTextMessageContent({
1128
- messageId: currentMessageId,
1129
- content
1171
+ if (mode === "message") {
1172
+ eventStream$.sendTextMessageEnd({
1173
+ messageId: currentMessageId
1130
1174
  });
1131
- } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
1132
- eventStream$.sendActionExecutionArgs({
1133
- actionExecutionId: currentToolCallId,
1134
- args: toolCall.function.arguments
1175
+ } else if (mode === "function") {
1176
+ eventStream$.sendActionExecutionEnd({
1177
+ actionExecutionId: currentToolCallId
1135
1178
  });
1136
1179
  }
1137
- }
1138
- if (mode === "message") {
1139
- eventStream$.sendTextMessageEnd({
1140
- messageId: currentMessageId
1141
- });
1142
- } else if (mode === "function") {
1143
- eventStream$.sendActionExecutionEnd({
1144
- actionExecutionId: currentToolCallId
1145
- });
1180
+ } catch (error) {
1181
+ throw convertServiceAdapterError(error, "Groq");
1146
1182
  }
1147
1183
  eventStream$.complete();
1148
1184
  });
@@ -1293,7 +1329,7 @@ function convertMessageToAnthropicMessage(message) {
1293
1329
  content: [
1294
1330
  {
1295
1331
  type: "tool_result",
1296
- content: message.result,
1332
+ content: message.result || "Action completed successfully",
1297
1333
  tool_use_id: message.actionExecutionId
1298
1334
  }
1299
1335
  ]
@@ -1317,6 +1353,22 @@ var AnthropicAdapter = class {
1317
1353
  this.model = params.model;
1318
1354
  }
1319
1355
  }
1356
+ shouldGenerateFallbackResponse(messages) {
1357
+ var _a, _b, _c;
1358
+ if (messages.length === 0)
1359
+ return false;
1360
+ const lastMessage = messages[messages.length - 1];
1361
+ const endsWithToolResult = lastMessage.role === "user" && Array.isArray(lastMessage.content) && lastMessage.content.some((content) => content.type === "tool_result");
1362
+ if (messages.length >= 3 && endsWithToolResult) {
1363
+ const lastThree = messages.slice(-3);
1364
+ const hasRecentToolPattern = ((_a = lastThree[0]) == null ? void 0 : _a.role) === "user" && // Initial user message
1365
+ ((_b = lastThree[1]) == null ? void 0 : _b.role) === "assistant" && // Assistant tool use
1366
+ Array.isArray(lastThree[1].content) && lastThree[1].content.some((content) => content.type === "tool_use") && ((_c = lastThree[2]) == null ? void 0 : _c.role) === "user" && // Tool result
1367
+ Array.isArray(lastThree[2].content) && lastThree[2].content.some((content) => content.type === "tool_result");
1368
+ return hasRecentToolPattern;
1369
+ }
1370
+ return endsWithToolResult;
1371
+ }
1320
1372
  async process(request) {
1321
1373
  const { threadId, model = this.model, messages: rawMessages, actions, eventSource, forwardedParameters } = request;
1322
1374
  const tools = actions.map(convertActionInputToAnthropicTool);
@@ -1331,18 +1383,22 @@ var AnthropicAdapter = class {
1331
1383
  validToolUseIds.add(message.id);
1332
1384
  }
1333
1385
  }
1386
+ const processedToolResultIds = /* @__PURE__ */ new Set();
1334
1387
  const anthropicMessages = messages.map((message) => {
1335
1388
  if (message.isResultMessage()) {
1336
1389
  if (!validToolUseIds.has(message.actionExecutionId)) {
1337
1390
  return null;
1338
1391
  }
1339
- validToolUseIds.delete(message.actionExecutionId);
1392
+ if (processedToolResultIds.has(message.actionExecutionId)) {
1393
+ return null;
1394
+ }
1395
+ processedToolResultIds.add(message.actionExecutionId);
1340
1396
  return {
1341
1397
  role: "user",
1342
1398
  content: [
1343
1399
  {
1344
1400
  type: "tool_result",
1345
- content: message.result,
1401
+ content: message.result || "Action completed successfully",
1346
1402
  tool_use_id: message.actionExecutionId
1347
1403
  }
1348
1404
  ]
@@ -1388,11 +1444,13 @@ var AnthropicAdapter = class {
1388
1444
  let currentMessageId = randomId3();
1389
1445
  let currentToolCallId = randomId3();
1390
1446
  let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
1447
+ let hasReceivedContent = false;
1391
1448
  try {
1392
1449
  for await (const chunk of stream) {
1393
1450
  if (chunk.type === "message_start") {
1394
1451
  currentMessageId = chunk.message.id;
1395
1452
  } else if (chunk.type === "content_block_start") {
1453
+ hasReceivedContent = true;
1396
1454
  if (chunk.content_block.type === "text") {
1397
1455
  didOutputText = false;
1398
1456
  filterThinkingTextBuffer.reset();
@@ -1442,14 +1500,33 @@ var AnthropicAdapter = class {
1442
1500
  }
1443
1501
  }
1444
1502
  } catch (error) {
1445
- console.error("[Anthropic] Error processing stream:", error);
1446
- throw error;
1503
+ throw convertServiceAdapterError(error, "Anthropic");
1504
+ }
1505
+ if (!hasReceivedContent && this.shouldGenerateFallbackResponse(limitedMessages)) {
1506
+ let fallbackContent = "Task completed successfully.";
1507
+ const lastMessage = limitedMessages[limitedMessages.length - 1];
1508
+ if ((lastMessage == null ? void 0 : lastMessage.role) === "user" && Array.isArray(lastMessage.content)) {
1509
+ const toolResult = lastMessage.content.find((c) => c.type === "tool_result");
1510
+ if ((toolResult == null ? void 0 : toolResult.content) && toolResult.content !== "Action completed successfully") {
1511
+ fallbackContent = toolResult.content;
1512
+ }
1513
+ }
1514
+ currentMessageId = randomId3();
1515
+ eventStream$.sendTextMessageStart({
1516
+ messageId: currentMessageId
1517
+ });
1518
+ eventStream$.sendTextMessageContent({
1519
+ messageId: currentMessageId,
1520
+ content: fallbackContent
1521
+ });
1522
+ eventStream$.sendTextMessageEnd({
1523
+ messageId: currentMessageId
1524
+ });
1447
1525
  }
1448
1526
  eventStream$.complete();
1449
1527
  });
1450
1528
  } catch (error) {
1451
- console.error("[Anthropic] Error during API call:", error);
1452
- throw error;
1529
+ throw convertServiceAdapterError(error, "Anthropic");
1453
1530
  }
1454
1531
  return {
1455
1532
  threadId: threadId || randomUUID5()
@@ -1581,4 +1658,4 @@ export {
1581
1658
  EmptyAdapter,
1582
1659
  ExperimentalEmptyAdapter
1583
1660
  };
1584
- //# sourceMappingURL=chunk-IIXJVVTV.mjs.map
1661
+ //# sourceMappingURL=chunk-GS7DO47Q.mjs.map