@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.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",
@@ -583,20 +583,39 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
583
583
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
584
584
  let reader = result.getReader();
585
585
  let mode = null;
586
+ const toolCallDetails = {
587
+ name: null,
588
+ id: null,
589
+ index: null,
590
+ prevIndex: null
591
+ };
586
592
  while (true) {
587
593
  try {
588
594
  const { done, value } = await reader.read();
589
595
  let toolCallName = void 0;
590
596
  let toolCallId = void 0;
591
597
  let toolCallArgs = void 0;
598
+ let toolCallIndex = void 0;
599
+ let toolCallPrevIndex = void 0;
592
600
  let hasToolCall = false;
593
601
  let content = value == null ? void 0 : value.content;
594
602
  if (isAIMessageChunk(value)) {
595
603
  let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
596
- toolCallName = chunk == null ? void 0 : chunk.name;
597
- toolCallId = chunk == null ? void 0 : chunk.id;
598
604
  toolCallArgs = chunk == null ? void 0 : chunk.args;
599
605
  hasToolCall = chunk != void 0;
606
+ if (chunk == null ? void 0 : chunk.name)
607
+ toolCallDetails.name = chunk.name;
608
+ if ((chunk == null ? void 0 : chunk.index) != null) {
609
+ toolCallDetails.index = chunk.index;
610
+ if (toolCallDetails.prevIndex == null)
611
+ toolCallDetails.prevIndex = chunk.index;
612
+ }
613
+ if (chunk == null ? void 0 : chunk.id)
614
+ toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;
615
+ toolCallName = toolCallDetails.name;
616
+ toolCallId = toolCallDetails.id;
617
+ toolCallIndex = toolCallDetails.index;
618
+ toolCallPrevIndex = toolCallDetails.prevIndex;
600
619
  } else if (isBaseMessageChunk(value)) {
601
620
  let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
602
621
  toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
@@ -615,7 +634,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
615
634
  break;
616
635
  }
617
636
  if (mode === null) {
618
- if (hasToolCall) {
637
+ if (hasToolCall && toolCallId && toolCallName) {
619
638
  mode = "function";
620
639
  eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
621
640
  } else if (content) {
@@ -626,6 +645,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
626
645
  if (mode === "message" && content) {
627
646
  eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
628
647
  } else if (mode === "function" && toolCallArgs) {
648
+ if (toolCallIndex !== toolCallPrevIndex) {
649
+ eventStream$.sendActionExecutionEnd();
650
+ eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
651
+ toolCallDetails.prevIndex = toolCallDetails.index;
652
+ }
629
653
  eventStream$.sendActionExecutionArgs(toolCallArgs);
630
654
  }
631
655
  } catch (error) {
@@ -1705,34 +1729,41 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1705
1729
  state = JSON.parse(jsonState);
1706
1730
  }
1707
1731
  }
1708
- const response = await fetch(`${url}/agents/execute`, {
1709
- method: "POST",
1710
- headers,
1711
- body: JSON.stringify({
1712
- name,
1713
- threadId,
1714
- nodeName,
1715
- messages,
1716
- state,
1717
- properties: graphqlContext.properties,
1718
- actions: actionInputsWithoutAgents.map((action) => ({
1719
- name: action.name,
1720
- description: action.description,
1721
- parameters: JSON.parse(action.jsonSchema)
1722
- }))
1723
- })
1724
- });
1725
- if (!response.ok) {
1732
+ try {
1733
+ const response = await fetch(`${url}/agents/execute`, {
1734
+ method: "POST",
1735
+ headers,
1736
+ body: JSON.stringify({
1737
+ name,
1738
+ threadId,
1739
+ nodeName,
1740
+ messages,
1741
+ state,
1742
+ properties: graphqlContext.properties,
1743
+ actions: actionInputsWithoutAgents.map((action) => ({
1744
+ name: action.name,
1745
+ description: action.description,
1746
+ parameters: JSON.parse(action.jsonSchema)
1747
+ }))
1748
+ })
1749
+ });
1750
+ if (!response.ok) {
1751
+ logger2.error({
1752
+ url,
1753
+ status: response.status,
1754
+ body: await response.text()
1755
+ }, "Failed to execute remote agent");
1756
+ throw "Failed to execute remote agent";
1757
+ }
1758
+ const eventSource = new RemoteLangGraphEventSource();
1759
+ eventSource.streamResponse(response);
1760
+ return eventSource.processLangGraphEvents();
1761
+ } catch (error) {
1726
1762
  logger2.error({
1727
- url,
1728
- status: response.status,
1729
- body: await response.text()
1763
+ error: error.message ? error.message : error + ""
1730
1764
  }, "Failed to execute remote agent");
1731
- throw new Error("Failed to execute remote agent");
1765
+ throw "Failed to execute remote agent";
1732
1766
  }
1733
- const eventSource = new RemoteLangGraphEventSource();
1734
- eventSource.streamResponse(response);
1735
- return eventSource.processLangGraphEvents();
1736
1767
  }
1737
1768
  }));
1738
1769
  return [