@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/dist/index.mjs CHANGED
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  CustomEventNames,
3
3
  LangGraphAgent
4
- } from "./chunk-2PQGAIVB.mjs";
4
+ } from "./chunk-5SG4WWXH.mjs";
5
5
  import {
6
6
  config,
7
7
  copilotRuntimeNextJSAppRouterEndpoint,
8
8
  copilotRuntimeNextJSPagesRouterEndpoint
9
- } from "./chunk-LSB3QZHS.mjs";
9
+ } from "./chunk-JWPSIGSA.mjs";
10
10
  import {
11
11
  copilotRuntimeNestEndpoint
12
- } from "./chunk-GW6ERFKI.mjs";
12
+ } from "./chunk-4TLMVLU4.mjs";
13
13
  import {
14
14
  copilotRuntimeNodeExpressEndpoint
15
- } from "./chunk-2UAJCT5X.mjs";
15
+ } from "./chunk-KYCDL2KX.mjs";
16
16
  import {
17
17
  CopilotRuntime,
18
18
  addCustomHeaderPlugin,
@@ -28,7 +28,7 @@ import {
28
28
  getCommonConfig,
29
29
  langGraphPlatformEndpoint,
30
30
  resolveEndpointType
31
- } from "./chunk-HB4D2KJC.mjs";
31
+ } from "./chunk-WIXS6EG7.mjs";
32
32
  import {
33
33
  AnthropicAdapter,
34
34
  BedrockAdapter,
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.9.2-next.7",
47
+ version: "1.9.2-next.8",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -3100,7 +3100,6 @@ async function fetchWithRetry(url, options, logger2) {
3100
3100
  __name(fetchWithRetry, "fetchWithRetry");
3101
3101
 
3102
3102
  // src/lib/runtime/remote-lg-action.ts
3103
- var activeInterruptEvent = false;
3104
3103
  async function execute(args) {
3105
3104
  return new ReadableStream({
3106
3105
  async start(controller) {
@@ -3143,7 +3142,7 @@ async function execute(args) {
3143
3142
  }
3144
3143
  __name(execute, "execute");
3145
3144
  async function streamEvents(controller, args) {
3146
- var _a, _b, _c, _d, _e, _f, _g, _h;
3145
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3147
3146
  const { deploymentUrl, langsmithApiKey, threadId: argsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, config: explicitConfig, messages, actions, logger: logger2, properties, metaEvents } = args;
3148
3147
  let nodeName = initialNodeName;
3149
3148
  let state = initialState;
@@ -3201,18 +3200,14 @@ async function streamEvents(controller, args) {
3201
3200
  command: void 0
3202
3201
  };
3203
3202
  const lgInterruptMetaEvent = metaEvents == null ? void 0 : metaEvents.find((ev) => ev.name === MetaEventName.LangGraphInterruptEvent);
3204
- if (activeInterruptEvent && !lgInterruptMetaEvent) {
3205
- payload.command = {
3206
- resume: state.messages
3207
- };
3208
- }
3209
3203
  if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
3210
3204
  let response = lgInterruptMetaEvent.response;
3211
3205
  payload.command = {
3212
3206
  resume: (0, import_shared9.parseJson)(response, response)
3213
3207
  };
3214
3208
  }
3215
- if (mode === "continue" && !activeInterruptEvent) {
3209
+ const interrupts = ((_b = (_a = agentState.tasks) == null ? void 0 : _a[0]) == null ? void 0 : _b.interrupts) ?? [];
3210
+ if (mode === "continue" && !interrupts.length) {
3216
3211
  await client.threads.updateState(threadId, {
3217
3212
  values: state,
3218
3213
  asNode: nodeName
@@ -3274,12 +3269,23 @@ async function streamEvents(controller, args) {
3274
3269
  let emitIntermediateStateUntilEnd = null;
3275
3270
  let shouldExit = false;
3276
3271
  let externalRunId = null;
3277
- const streamResponse = client.runs.stream(threadId, assistantId, payload);
3278
3272
  const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
3273
+ if ((interrupts == null ? void 0 : interrupts.length) && !((_c = payload.command) == null ? void 0 : _c.resume)) {
3274
+ if (!lgInterruptMetaEvent) {
3275
+ payload.command = {
3276
+ resume: state.messages
3277
+ };
3278
+ } else {
3279
+ interrupts.forEach((interrupt) => {
3280
+ emitInterrupt(interrupt.value, emit);
3281
+ });
3282
+ return Promise.resolve();
3283
+ }
3284
+ }
3285
+ const streamResponse = client.runs.stream(threadId, assistantId, payload);
3279
3286
  let latestStateValues = {};
3280
3287
  let updatedState = state;
3281
3288
  let manuallyEmittedState = null;
3282
- activeInterruptEvent = false;
3283
3289
  try {
3284
3290
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
3285
3291
  hashedLgcKey: streamInfo.hashedLgcKey
@@ -3298,23 +3304,8 @@ async function streamEvents(controller, args) {
3298
3304
  const chunk = streamResponseChunk;
3299
3305
  const interruptEvents = chunk.data.__interrupt__;
3300
3306
  if (interruptEvents == null ? void 0 : interruptEvents.length) {
3301
- activeInterruptEvent = true;
3302
3307
  const interruptValue = interruptEvents == null ? void 0 : interruptEvents[0].value;
3303
- if (typeof interruptValue != "string" && "__copilotkit_interrupt_value__" in interruptValue) {
3304
- const evValue = interruptValue.__copilotkit_interrupt_value__;
3305
- emit(JSON.stringify({
3306
- event: LangGraphEventTypes.OnCopilotKitInterrupt,
3307
- data: {
3308
- value: typeof evValue === "string" ? evValue : JSON.stringify(evValue),
3309
- messages: langchainMessagesToCopilotKit(interruptValue.__copilotkit_messages__)
3310
- }
3311
- }) + "\n");
3312
- } else {
3313
- emit(JSON.stringify({
3314
- event: LangGraphEventTypes.OnInterrupt,
3315
- value: typeof interruptValue === "string" ? interruptValue : JSON.stringify(interruptValue)
3316
- }) + "\n");
3317
- }
3308
+ emitInterrupt(interruptValue, emit);
3318
3309
  continue;
3319
3310
  }
3320
3311
  if (streamResponseChunk.event === "updates")
@@ -3329,8 +3320,8 @@ async function streamEvents(controller, args) {
3329
3320
  const runId = chunkData.metadata.run_id;
3330
3321
  externalRunId = runId;
3331
3322
  const metadata = chunkData.metadata;
3332
- 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) != "") {
3333
- streamInfo.provider = (_f = (_e = chunkData.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
3323
+ 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) != "") {
3324
+ streamInfo.provider = (_i = (_h = chunkData.data) == null ? void 0 : _h.output) == null ? void 0 : _i.model;
3334
3325
  }
3335
3326
  if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
3336
3327
  streamInfo.langGraphHost = metadata.langgraph_host;
@@ -3401,9 +3392,9 @@ async function streamEvents(controller, args) {
3401
3392
  emit(JSON.stringify(chunkData) + "\n");
3402
3393
  }
3403
3394
  state = await client.threads.getState(threadId);
3404
- const interrupts = (_h = (_g = state.tasks) == null ? void 0 : _g[0]) == null ? void 0 : _h.interrupts;
3405
- nodeName = interrupts ? nodeName : Object.keys(state.metadata.writes)[0];
3406
- const isEndNode = state.next.length === 0 && !interrupts;
3395
+ const interrupts2 = (_k = (_j = state.tasks) == null ? void 0 : _j[0]) == null ? void 0 : _k.interrupts;
3396
+ nodeName = interrupts2 ? nodeName : Object.keys(state.metadata.writes)[0];
3397
+ const isEndNode = state.next.length === 0 && !interrupts2;
3407
3398
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
3408
3399
  emit(getStateSyncEvent({
3409
3400
  threadId,
@@ -3735,6 +3726,24 @@ function filterObjectBySchemaKeys(obj, schemaKeys) {
3735
3726
  return Object.fromEntries(Object.entries(obj).filter(([key]) => schemaKeys.includes(key)));
3736
3727
  }
3737
3728
  __name(filterObjectBySchemaKeys, "filterObjectBySchemaKeys");
3729
+ function emitInterrupt(interruptValue, emit) {
3730
+ if (typeof interruptValue != "string" && "__copilotkit_interrupt_value__" in interruptValue) {
3731
+ const evValue = interruptValue.__copilotkit_interrupt_value__;
3732
+ emit(JSON.stringify({
3733
+ event: LangGraphEventTypes.OnCopilotKitInterrupt,
3734
+ data: {
3735
+ value: typeof evValue === "string" ? evValue : JSON.stringify(evValue),
3736
+ messages: langchainMessagesToCopilotKit(interruptValue.__copilotkit_messages__)
3737
+ }
3738
+ }) + "\n");
3739
+ } else {
3740
+ emit(JSON.stringify({
3741
+ event: LangGraphEventTypes.OnInterrupt,
3742
+ value: typeof interruptValue === "string" ? interruptValue : JSON.stringify(interruptValue)
3743
+ }) + "\n");
3744
+ }
3745
+ }
3746
+ __name(emitInterrupt, "emitInterrupt");
3738
3747
 
3739
3748
  // src/lib/runtime/remote-action-constructors.ts
3740
3749
  var import_shared11 = require("@copilotkit/shared");