@copilotkit/runtime 1.9.2-next.7 → 1.9.2-next.8

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 (32) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{chunk-GW6ERFKI.mjs → chunk-4TLMVLU4.mjs} +2 -2
  3. package/dist/{chunk-2PQGAIVB.mjs → chunk-5SG4WWXH.mjs} +2 -2
  4. package/dist/{chunk-LSB3QZHS.mjs → chunk-JWPSIGSA.mjs} +2 -2
  5. package/dist/{chunk-2UAJCT5X.mjs → chunk-KYCDL2KX.mjs} +2 -2
  6. package/dist/{chunk-HB4D2KJC.mjs → chunk-WIXS6EG7.mjs} +42 -33
  7. package/dist/chunk-WIXS6EG7.mjs.map +1 -0
  8. package/dist/index.js +41 -32
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +5 -5
  11. package/dist/lib/index.js +41 -32
  12. package/dist/lib/index.js.map +1 -1
  13. package/dist/lib/index.mjs +5 -5
  14. package/dist/lib/integrations/index.js +1 -1
  15. package/dist/lib/integrations/index.js.map +1 -1
  16. package/dist/lib/integrations/index.mjs +4 -4
  17. package/dist/lib/integrations/nest/index.js +1 -1
  18. package/dist/lib/integrations/nest/index.js.map +1 -1
  19. package/dist/lib/integrations/nest/index.mjs +2 -2
  20. package/dist/lib/integrations/node-express/index.js +1 -1
  21. package/dist/lib/integrations/node-express/index.js.map +1 -1
  22. package/dist/lib/integrations/node-express/index.mjs +2 -2
  23. package/dist/lib/integrations/node-http/index.js +1 -1
  24. package/dist/lib/integrations/node-http/index.js.map +1 -1
  25. package/dist/lib/integrations/node-http/index.mjs +1 -1
  26. package/package.json +2 -2
  27. package/src/lib/runtime/remote-lg-action.ts +45 -37
  28. package/dist/chunk-HB4D2KJC.mjs.map +0 -1
  29. /package/dist/{chunk-GW6ERFKI.mjs.map → chunk-4TLMVLU4.mjs.map} +0 -0
  30. /package/dist/{chunk-2PQGAIVB.mjs.map → chunk-5SG4WWXH.mjs.map} +0 -0
  31. /package/dist/{chunk-LSB3QZHS.mjs.map → chunk-JWPSIGSA.mjs.map} +0 -0
  32. /package/dist/{chunk-2UAJCT5X.mjs.map → chunk-KYCDL2KX.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @copilotkit/runtime
2
2
 
3
+ ## 1.9.2-next.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 9b986ba: - fix: use active interrupt from thread instead of saving to global state
8
+ - @copilotkit/shared@1.9.2-next.8
9
+
3
10
  ## 1.9.2-next.7
4
11
 
5
12
  ### Patch Changes
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-HB4D2KJC.mjs";
5
+ } from "./chunk-WIXS6EG7.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-GW6ERFKI.mjs.map
25
+ //# sourceMappingURL=chunk-4TLMVLU4.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LangGraphEventTypes
3
- } from "./chunk-HB4D2KJC.mjs";
3
+ } from "./chunk-WIXS6EG7.mjs";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-FHD4JECV.mjs";
@@ -155,4 +155,4 @@ export {
155
155
  CustomEventNames,
156
156
  LangGraphAgent
157
157
  };
158
- //# sourceMappingURL=chunk-2PQGAIVB.mjs.map
158
+ //# sourceMappingURL=chunk-5SG4WWXH.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  getCommonConfig,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-HB4D2KJC.mjs";
5
+ } from "./chunk-WIXS6EG7.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-LSB3QZHS.mjs.map
80
+ //# sourceMappingURL=chunk-JWPSIGSA.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-HB4D2KJC.mjs";
5
+ } from "./chunk-WIXS6EG7.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
22
22
  export {
23
23
  copilotRuntimeNodeExpressEndpoint
24
24
  };
25
- //# sourceMappingURL=chunk-2UAJCT5X.mjs.map
25
+ //# sourceMappingURL=chunk-KYCDL2KX.mjs.map
@@ -40,7 +40,7 @@ var require_package = __commonJS({
40
40
  publishConfig: {
41
41
  access: "public"
42
42
  },
43
- version: "1.9.2-next.7",
43
+ version: "1.9.2-next.8",
44
44
  sideEffects: false,
45
45
  main: "./dist/index.js",
46
46
  module: "./dist/index.mjs",
@@ -1851,7 +1851,6 @@ async function fetchWithRetry(url, options, logger2) {
1851
1851
  __name(fetchWithRetry, "fetchWithRetry");
1852
1852
 
1853
1853
  // src/lib/runtime/remote-lg-action.ts
1854
- var activeInterruptEvent = false;
1855
1854
  async function execute(args) {
1856
1855
  return new ReadableStream({
1857
1856
  async start(controller) {
@@ -1894,7 +1893,7 @@ async function execute(args) {
1894
1893
  }
1895
1894
  __name(execute, "execute");
1896
1895
  async function streamEvents(controller, args) {
1897
- var _a, _b, _c, _d, _e, _f, _g, _h;
1896
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1898
1897
  const { deploymentUrl, langsmithApiKey, threadId: argsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, config: explicitConfig, messages, actions, logger: logger2, properties, metaEvents } = args;
1899
1898
  let nodeName = initialNodeName;
1900
1899
  let state = initialState;
@@ -1952,18 +1951,14 @@ async function streamEvents(controller, args) {
1952
1951
  command: void 0
1953
1952
  };
1954
1953
  const lgInterruptMetaEvent = metaEvents == null ? void 0 : metaEvents.find((ev) => ev.name === MetaEventName.LangGraphInterruptEvent);
1955
- if (activeInterruptEvent && !lgInterruptMetaEvent) {
1956
- payload.command = {
1957
- resume: state.messages
1958
- };
1959
- }
1960
1954
  if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
1961
1955
  let response = lgInterruptMetaEvent.response;
1962
1956
  payload.command = {
1963
1957
  resume: parseJson(response, response)
1964
1958
  };
1965
1959
  }
1966
- if (mode === "continue" && !activeInterruptEvent) {
1960
+ const interrupts = ((_b = (_a = agentState.tasks) == null ? void 0 : _a[0]) == null ? void 0 : _b.interrupts) ?? [];
1961
+ if (mode === "continue" && !interrupts.length) {
1967
1962
  await client.threads.updateState(threadId, {
1968
1963
  values: state,
1969
1964
  asNode: nodeName
@@ -2025,12 +2020,23 @@ async function streamEvents(controller, args) {
2025
2020
  let emitIntermediateStateUntilEnd = null;
2026
2021
  let shouldExit = false;
2027
2022
  let externalRunId = null;
2028
- const streamResponse = client.runs.stream(threadId, assistantId, payload);
2029
2023
  const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
2024
+ if ((interrupts == null ? void 0 : interrupts.length) && !((_c = payload.command) == null ? void 0 : _c.resume)) {
2025
+ if (!lgInterruptMetaEvent) {
2026
+ payload.command = {
2027
+ resume: state.messages
2028
+ };
2029
+ } else {
2030
+ interrupts.forEach((interrupt) => {
2031
+ emitInterrupt(interrupt.value, emit);
2032
+ });
2033
+ return Promise.resolve();
2034
+ }
2035
+ }
2036
+ const streamResponse = client.runs.stream(threadId, assistantId, payload);
2030
2037
  let latestStateValues = {};
2031
2038
  let updatedState = state;
2032
2039
  let manuallyEmittedState = null;
2033
- activeInterruptEvent = false;
2034
2040
  try {
2035
2041
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
2036
2042
  hashedLgcKey: streamInfo.hashedLgcKey
@@ -2049,23 +2055,8 @@ async function streamEvents(controller, args) {
2049
2055
  const chunk = streamResponseChunk;
2050
2056
  const interruptEvents = chunk.data.__interrupt__;
2051
2057
  if (interruptEvents == null ? void 0 : interruptEvents.length) {
2052
- activeInterruptEvent = true;
2053
2058
  const interruptValue = interruptEvents == null ? void 0 : interruptEvents[0].value;
2054
- if (typeof interruptValue != "string" && "__copilotkit_interrupt_value__" in interruptValue) {
2055
- const evValue = interruptValue.__copilotkit_interrupt_value__;
2056
- emit(JSON.stringify({
2057
- event: LangGraphEventTypes.OnCopilotKitInterrupt,
2058
- data: {
2059
- value: typeof evValue === "string" ? evValue : JSON.stringify(evValue),
2060
- messages: langchainMessagesToCopilotKit(interruptValue.__copilotkit_messages__)
2061
- }
2062
- }) + "\n");
2063
- } else {
2064
- emit(JSON.stringify({
2065
- event: LangGraphEventTypes.OnInterrupt,
2066
- value: typeof interruptValue === "string" ? interruptValue : JSON.stringify(interruptValue)
2067
- }) + "\n");
2068
- }
2059
+ emitInterrupt(interruptValue, emit);
2069
2060
  continue;
2070
2061
  }
2071
2062
  if (streamResponseChunk.event === "updates")
@@ -2080,8 +2071,8 @@ async function streamEvents(controller, args) {
2080
2071
  const runId = chunkData.metadata.run_id;
2081
2072
  externalRunId = runId;
2082
2073
  const metadata = chunkData.metadata;
2083
- if (((_b = (_a = chunkData.data) == null ? void 0 : _a.output) == null ? void 0 : _b.model) != null && ((_d = (_c = chunkData.data) == null ? void 0 : _c.output) == null ? void 0 : _d.model) != "") {
2084
- streamInfo.provider = (_f = (_e = chunkData.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
2074
+ if (((_e = (_d = chunkData.data) == null ? void 0 : _d.output) == null ? void 0 : _e.model) != null && ((_g = (_f = chunkData.data) == null ? void 0 : _f.output) == null ? void 0 : _g.model) != "") {
2075
+ streamInfo.provider = (_i = (_h = chunkData.data) == null ? void 0 : _h.output) == null ? void 0 : _i.model;
2085
2076
  }
2086
2077
  if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
2087
2078
  streamInfo.langGraphHost = metadata.langgraph_host;
@@ -2152,9 +2143,9 @@ async function streamEvents(controller, args) {
2152
2143
  emit(JSON.stringify(chunkData) + "\n");
2153
2144
  }
2154
2145
  state = await client.threads.getState(threadId);
2155
- const interrupts = (_h = (_g = state.tasks) == null ? void 0 : _g[0]) == null ? void 0 : _h.interrupts;
2156
- nodeName = interrupts ? nodeName : Object.keys(state.metadata.writes)[0];
2157
- const isEndNode = state.next.length === 0 && !interrupts;
2146
+ const interrupts2 = (_k = (_j = state.tasks) == null ? void 0 : _j[0]) == null ? void 0 : _k.interrupts;
2147
+ nodeName = interrupts2 ? nodeName : Object.keys(state.metadata.writes)[0];
2148
+ const isEndNode = state.next.length === 0 && !interrupts2;
2158
2149
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
2159
2150
  emit(getStateSyncEvent({
2160
2151
  threadId,
@@ -2486,6 +2477,24 @@ function filterObjectBySchemaKeys(obj, schemaKeys) {
2486
2477
  return Object.fromEntries(Object.entries(obj).filter(([key]) => schemaKeys.includes(key)));
2487
2478
  }
2488
2479
  __name(filterObjectBySchemaKeys, "filterObjectBySchemaKeys");
2480
+ function emitInterrupt(interruptValue, emit) {
2481
+ if (typeof interruptValue != "string" && "__copilotkit_interrupt_value__" in interruptValue) {
2482
+ const evValue = interruptValue.__copilotkit_interrupt_value__;
2483
+ emit(JSON.stringify({
2484
+ event: LangGraphEventTypes.OnCopilotKitInterrupt,
2485
+ data: {
2486
+ value: typeof evValue === "string" ? evValue : JSON.stringify(evValue),
2487
+ messages: langchainMessagesToCopilotKit(interruptValue.__copilotkit_messages__)
2488
+ }
2489
+ }) + "\n");
2490
+ } else {
2491
+ emit(JSON.stringify({
2492
+ event: LangGraphEventTypes.OnInterrupt,
2493
+ value: typeof interruptValue === "string" ? interruptValue : JSON.stringify(interruptValue)
2494
+ }) + "\n");
2495
+ }
2496
+ }
2497
+ __name(emitInterrupt, "emitInterrupt");
2489
2498
 
2490
2499
  // src/lib/runtime/remote-action-constructors.ts
2491
2500
  import { CopilotKitError as CopilotKitError3, CopilotKitLowLevelError as CopilotKitLowLevelError2 } from "@copilotkit/shared";
@@ -5560,4 +5569,4 @@ export {
5560
5569
  getCommonConfig,
5561
5570
  copilotRuntimeNodeHttpEndpoint
5562
5571
  };
5563
- //# sourceMappingURL=chunk-HB4D2KJC.mjs.map
5572
+ //# sourceMappingURL=chunk-WIXS6EG7.mjs.map