@copilotkit/runtime 1.3.12 → 1.3.14-fix-handle-execute-agent-error.0

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 (41) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{chunk-ZEHCLFJ2.mjs → chunk-CPAHDRLS.mjs} +28 -4
  3. package/dist/chunk-CPAHDRLS.mjs.map +1 -0
  4. package/dist/{chunk-F2KJWMGD.mjs → chunk-GVAUIADR.mjs} +35 -28
  5. package/dist/chunk-GVAUIADR.mjs.map +1 -0
  6. package/dist/{chunk-IXVCESAR.mjs → chunk-LB3EPUOQ.mjs} +3 -3
  7. package/dist/{chunk-PRG6VWHR.mjs → chunk-LOMWWP44.mjs} +2 -2
  8. package/dist/{chunk-IZP72K7I.mjs → chunk-QXHQKRLT.mjs} +2 -2
  9. package/dist/{chunk-WBLYFYMZ.mjs → chunk-VN26GZV4.mjs} +2 -2
  10. package/dist/{chunk-24WEOOFX.mjs → chunk-Y6RQG5HF.mjs} +2 -2
  11. package/dist/index.js +60 -29
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +7 -7
  14. package/dist/lib/index.js +60 -29
  15. package/dist/lib/index.js.map +1 -1
  16. package/dist/lib/index.mjs +7 -7
  17. package/dist/lib/integrations/index.js +1 -1
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +5 -5
  20. package/dist/lib/integrations/nest/index.js +1 -1
  21. package/dist/lib/integrations/nest/index.js.map +1 -1
  22. package/dist/lib/integrations/nest/index.mjs +3 -3
  23. package/dist/lib/integrations/node-express/index.js +1 -1
  24. package/dist/lib/integrations/node-express/index.js.map +1 -1
  25. package/dist/lib/integrations/node-express/index.mjs +3 -3
  26. package/dist/lib/integrations/node-http/index.js +1 -1
  27. package/dist/lib/integrations/node-http/index.js.map +1 -1
  28. package/dist/lib/integrations/node-http/index.mjs +2 -2
  29. package/dist/service-adapters/index.js +27 -3
  30. package/dist/service-adapters/index.js.map +1 -1
  31. package/dist/service-adapters/index.mjs +2 -2
  32. package/package.json +4 -4
  33. package/src/lib/runtime/remote-actions.ts +33 -24
  34. package/src/service-adapters/langchain/utils.ts +31 -3
  35. package/dist/chunk-F2KJWMGD.mjs.map +0 -1
  36. package/dist/chunk-ZEHCLFJ2.mjs.map +0 -1
  37. /package/dist/{chunk-IXVCESAR.mjs.map → chunk-LB3EPUOQ.mjs.map} +0 -0
  38. /package/dist/{chunk-PRG6VWHR.mjs.map → chunk-LOMWWP44.mjs.map} +0 -0
  39. /package/dist/{chunk-IZP72K7I.mjs.map → chunk-QXHQKRLT.mjs.map} +0 -0
  40. /package/dist/{chunk-WBLYFYMZ.mjs.map → chunk-VN26GZV4.mjs.map} +0 -0
  41. /package/dist/{chunk-24WEOOFX.mjs.map → chunk-Y6RQG5HF.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CopilotRuntime,
3
3
  flattenToolCallsNoDuplicates
4
- } from "./chunk-IXVCESAR.mjs";
4
+ } from "./chunk-LB3EPUOQ.mjs";
5
5
  import {
6
6
  AnthropicAdapter,
7
7
  GoogleGenerativeAIAdapter,
@@ -11,25 +11,25 @@ import {
11
11
  OpenAIAssistantAdapter,
12
12
  RemoteChain,
13
13
  UnifyAdapter
14
- } from "./chunk-24WEOOFX.mjs";
14
+ } from "./chunk-Y6RQG5HF.mjs";
15
15
  import {
16
16
  config,
17
17
  copilotRuntimeNextJSAppRouterEndpoint,
18
18
  copilotRuntimeNextJSPagesRouterEndpoint
19
- } from "./chunk-IZP72K7I.mjs";
19
+ } from "./chunk-QXHQKRLT.mjs";
20
20
  import {
21
21
  copilotRuntimeNestEndpoint
22
- } from "./chunk-PRG6VWHR.mjs";
22
+ } from "./chunk-LOMWWP44.mjs";
23
23
  import {
24
24
  copilotRuntimeNodeExpressEndpoint
25
- } from "./chunk-WBLYFYMZ.mjs";
25
+ } from "./chunk-VN26GZV4.mjs";
26
26
  import {
27
27
  buildSchema,
28
28
  copilotRuntimeNodeHttpEndpoint,
29
29
  createContext,
30
30
  getCommonConfig
31
- } from "./chunk-F2KJWMGD.mjs";
32
- import "./chunk-ZEHCLFJ2.mjs";
31
+ } from "./chunk-GVAUIADR.mjs";
32
+ import "./chunk-CPAHDRLS.mjs";
33
33
  import {
34
34
  GuardrailsValidationFailureResponse,
35
35
  MessageStreamInterruptedResponse,
package/dist/lib/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.3.12",
47
+ version: "1.3.14-fix-handle-execute-agent-error.0",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -577,20 +577,39 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
577
577
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
578
578
  let reader = result.getReader();
579
579
  let mode = null;
580
+ const toolCallDetails = {
581
+ name: null,
582
+ id: null,
583
+ index: null,
584
+ prevIndex: null
585
+ };
580
586
  while (true) {
581
587
  try {
582
588
  const { done, value } = await reader.read();
583
589
  let toolCallName = void 0;
584
590
  let toolCallId = void 0;
585
591
  let toolCallArgs = void 0;
592
+ let toolCallIndex = void 0;
593
+ let toolCallPrevIndex = void 0;
586
594
  let hasToolCall = false;
587
595
  let content = value == null ? void 0 : value.content;
588
596
  if (isAIMessageChunk(value)) {
589
597
  let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
590
- toolCallName = chunk == null ? void 0 : chunk.name;
591
- toolCallId = chunk == null ? void 0 : chunk.id;
592
598
  toolCallArgs = chunk == null ? void 0 : chunk.args;
593
599
  hasToolCall = chunk != void 0;
600
+ if (chunk == null ? void 0 : chunk.name)
601
+ toolCallDetails.name = chunk.name;
602
+ if ((chunk == null ? void 0 : chunk.index) != null) {
603
+ toolCallDetails.index = chunk.index;
604
+ if (toolCallDetails.prevIndex == null)
605
+ toolCallDetails.prevIndex = chunk.index;
606
+ }
607
+ if (chunk == null ? void 0 : chunk.id)
608
+ toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;
609
+ toolCallName = toolCallDetails.name;
610
+ toolCallId = toolCallDetails.id;
611
+ toolCallIndex = toolCallDetails.index;
612
+ toolCallPrevIndex = toolCallDetails.prevIndex;
594
613
  } else if (isBaseMessageChunk(value)) {
595
614
  let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
596
615
  toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
@@ -609,7 +628,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
609
628
  break;
610
629
  }
611
630
  if (mode === null) {
612
- if (hasToolCall) {
631
+ if (hasToolCall && toolCallId && toolCallName) {
613
632
  mode = "function";
614
633
  eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
615
634
  } else if (content) {
@@ -620,6 +639,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
620
639
  if (mode === "message" && content) {
621
640
  eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
622
641
  } else if (mode === "function" && toolCallArgs) {
642
+ if (toolCallIndex !== toolCallPrevIndex) {
643
+ eventStream$.sendActionExecutionEnd();
644
+ eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
645
+ toolCallDetails.prevIndex = toolCallDetails.index;
646
+ }
623
647
  eventStream$.sendActionExecutionArgs(toolCallArgs);
624
648
  }
625
649
  } catch (error) {
@@ -1435,34 +1459,41 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1435
1459
  state = JSON.parse(jsonState);
1436
1460
  }
1437
1461
  }
1438
- const response = await fetch(`${url}/agents/execute`, {
1439
- method: "POST",
1440
- headers,
1441
- body: JSON.stringify({
1442
- name,
1443
- threadId,
1444
- nodeName,
1445
- messages,
1446
- state,
1447
- properties: graphqlContext.properties,
1448
- actions: actionInputsWithoutAgents.map((action) => ({
1449
- name: action.name,
1450
- description: action.description,
1451
- parameters: JSON.parse(action.jsonSchema)
1452
- }))
1453
- })
1454
- });
1455
- if (!response.ok) {
1462
+ try {
1463
+ const response = await fetch(`${url}/agents/execute`, {
1464
+ method: "POST",
1465
+ headers,
1466
+ body: JSON.stringify({
1467
+ name,
1468
+ threadId,
1469
+ nodeName,
1470
+ messages,
1471
+ state,
1472
+ properties: graphqlContext.properties,
1473
+ actions: actionInputsWithoutAgents.map((action) => ({
1474
+ name: action.name,
1475
+ description: action.description,
1476
+ parameters: JSON.parse(action.jsonSchema)
1477
+ }))
1478
+ })
1479
+ });
1480
+ if (!response.ok) {
1481
+ logger2.error({
1482
+ url,
1483
+ status: response.status,
1484
+ body: await response.text()
1485
+ }, "Failed to execute remote agent");
1486
+ throw "Failed to execute remote agent";
1487
+ }
1488
+ const eventSource = new RemoteLangGraphEventSource();
1489
+ eventSource.streamResponse(response);
1490
+ return eventSource.processLangGraphEvents();
1491
+ } catch (error) {
1456
1492
  logger2.error({
1457
- url,
1458
- status: response.status,
1459
- body: await response.text()
1493
+ error: error.message ? error.message : error + ""
1460
1494
  }, "Failed to execute remote agent");
1461
- throw new Error("Failed to execute remote agent");
1495
+ throw "Failed to execute remote agent";
1462
1496
  }
1463
- const eventSource = new RemoteLangGraphEventSource();
1464
- eventSource.streamResponse(response);
1465
- return eventSource.processLangGraphEvents();
1466
1497
  }
1467
1498
  }));
1468
1499
  return [