@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.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",
@@ -3110,7 +3110,6 @@ async function fetchWithRetry(url, options, logger2) {
3110
3110
  __name(fetchWithRetry, "fetchWithRetry");
3111
3111
 
3112
3112
  // src/lib/runtime/remote-lg-action.ts
3113
- var activeInterruptEvent = false;
3114
3113
  async function execute(args) {
3115
3114
  return new ReadableStream({
3116
3115
  async start(controller) {
@@ -3153,7 +3152,7 @@ async function execute(args) {
3153
3152
  }
3154
3153
  __name(execute, "execute");
3155
3154
  async function streamEvents(controller, args) {
3156
- var _a, _b, _c, _d, _e, _f, _g, _h;
3155
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3157
3156
  const { deploymentUrl, langsmithApiKey, threadId: argsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, config: explicitConfig, messages, actions, logger: logger2, properties, metaEvents } = args;
3158
3157
  let nodeName = initialNodeName;
3159
3158
  let state = initialState;
@@ -3211,18 +3210,14 @@ async function streamEvents(controller, args) {
3211
3210
  command: void 0
3212
3211
  };
3213
3212
  const lgInterruptMetaEvent = metaEvents == null ? void 0 : metaEvents.find((ev) => ev.name === MetaEventName.LangGraphInterruptEvent);
3214
- if (activeInterruptEvent && !lgInterruptMetaEvent) {
3215
- payload.command = {
3216
- resume: state.messages
3217
- };
3218
- }
3219
3213
  if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
3220
3214
  let response = lgInterruptMetaEvent.response;
3221
3215
  payload.command = {
3222
3216
  resume: (0, import_shared9.parseJson)(response, response)
3223
3217
  };
3224
3218
  }
3225
- if (mode === "continue" && !activeInterruptEvent) {
3219
+ const interrupts = ((_b = (_a = agentState.tasks) == null ? void 0 : _a[0]) == null ? void 0 : _b.interrupts) ?? [];
3220
+ if (mode === "continue" && !interrupts.length) {
3226
3221
  await client.threads.updateState(threadId, {
3227
3222
  values: state,
3228
3223
  asNode: nodeName
@@ -3284,12 +3279,23 @@ async function streamEvents(controller, args) {
3284
3279
  let emitIntermediateStateUntilEnd = null;
3285
3280
  let shouldExit = false;
3286
3281
  let externalRunId = null;
3287
- const streamResponse = client.runs.stream(threadId, assistantId, payload);
3288
3282
  const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
3283
+ if ((interrupts == null ? void 0 : interrupts.length) && !((_c = payload.command) == null ? void 0 : _c.resume)) {
3284
+ if (!lgInterruptMetaEvent) {
3285
+ payload.command = {
3286
+ resume: state.messages
3287
+ };
3288
+ } else {
3289
+ interrupts.forEach((interrupt) => {
3290
+ emitInterrupt(interrupt.value, emit);
3291
+ });
3292
+ return Promise.resolve();
3293
+ }
3294
+ }
3295
+ const streamResponse = client.runs.stream(threadId, assistantId, payload);
3289
3296
  let latestStateValues = {};
3290
3297
  let updatedState = state;
3291
3298
  let manuallyEmittedState = null;
3292
- activeInterruptEvent = false;
3293
3299
  try {
3294
3300
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
3295
3301
  hashedLgcKey: streamInfo.hashedLgcKey
@@ -3308,23 +3314,8 @@ async function streamEvents(controller, args) {
3308
3314
  const chunk = streamResponseChunk;
3309
3315
  const interruptEvents = chunk.data.__interrupt__;
3310
3316
  if (interruptEvents == null ? void 0 : interruptEvents.length) {
3311
- activeInterruptEvent = true;
3312
3317
  const interruptValue = interruptEvents == null ? void 0 : interruptEvents[0].value;
3313
- if (typeof interruptValue != "string" && "__copilotkit_interrupt_value__" in interruptValue) {
3314
- const evValue = interruptValue.__copilotkit_interrupt_value__;
3315
- emit(JSON.stringify({
3316
- event: LangGraphEventTypes.OnCopilotKitInterrupt,
3317
- data: {
3318
- value: typeof evValue === "string" ? evValue : JSON.stringify(evValue),
3319
- messages: langchainMessagesToCopilotKit(interruptValue.__copilotkit_messages__)
3320
- }
3321
- }) + "\n");
3322
- } else {
3323
- emit(JSON.stringify({
3324
- event: LangGraphEventTypes.OnInterrupt,
3325
- value: typeof interruptValue === "string" ? interruptValue : JSON.stringify(interruptValue)
3326
- }) + "\n");
3327
- }
3318
+ emitInterrupt(interruptValue, emit);
3328
3319
  continue;
3329
3320
  }
3330
3321
  if (streamResponseChunk.event === "updates")
@@ -3339,8 +3330,8 @@ async function streamEvents(controller, args) {
3339
3330
  const runId = chunkData.metadata.run_id;
3340
3331
  externalRunId = runId;
3341
3332
  const metadata = chunkData.metadata;
3342
- 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) != "") {
3343
- streamInfo.provider = (_f = (_e = chunkData.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
3333
+ 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) != "") {
3334
+ streamInfo.provider = (_i = (_h = chunkData.data) == null ? void 0 : _h.output) == null ? void 0 : _i.model;
3344
3335
  }
3345
3336
  if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
3346
3337
  streamInfo.langGraphHost = metadata.langgraph_host;
@@ -3411,9 +3402,9 @@ async function streamEvents(controller, args) {
3411
3402
  emit(JSON.stringify(chunkData) + "\n");
3412
3403
  }
3413
3404
  state = await client.threads.getState(threadId);
3414
- const interrupts = (_h = (_g = state.tasks) == null ? void 0 : _g[0]) == null ? void 0 : _h.interrupts;
3415
- nodeName = interrupts ? nodeName : Object.keys(state.metadata.writes)[0];
3416
- const isEndNode = state.next.length === 0 && !interrupts;
3405
+ const interrupts2 = (_k = (_j = state.tasks) == null ? void 0 : _j[0]) == null ? void 0 : _k.interrupts;
3406
+ nodeName = interrupts2 ? nodeName : Object.keys(state.metadata.writes)[0];
3407
+ const isEndNode = state.next.length === 0 && !interrupts2;
3417
3408
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
3418
3409
  emit(getStateSyncEvent({
3419
3410
  threadId,
@@ -3745,6 +3736,24 @@ function filterObjectBySchemaKeys(obj, schemaKeys) {
3745
3736
  return Object.fromEntries(Object.entries(obj).filter(([key]) => schemaKeys.includes(key)));
3746
3737
  }
3747
3738
  __name(filterObjectBySchemaKeys, "filterObjectBySchemaKeys");
3739
+ function emitInterrupt(interruptValue, emit) {
3740
+ if (typeof interruptValue != "string" && "__copilotkit_interrupt_value__" in interruptValue) {
3741
+ const evValue = interruptValue.__copilotkit_interrupt_value__;
3742
+ emit(JSON.stringify({
3743
+ event: LangGraphEventTypes.OnCopilotKitInterrupt,
3744
+ data: {
3745
+ value: typeof evValue === "string" ? evValue : JSON.stringify(evValue),
3746
+ messages: langchainMessagesToCopilotKit(interruptValue.__copilotkit_messages__)
3747
+ }
3748
+ }) + "\n");
3749
+ } else {
3750
+ emit(JSON.stringify({
3751
+ event: LangGraphEventTypes.OnInterrupt,
3752
+ value: typeof interruptValue === "string" ? interruptValue : JSON.stringify(interruptValue)
3753
+ }) + "\n");
3754
+ }
3755
+ }
3756
+ __name(emitInterrupt, "emitInterrupt");
3748
3757
 
3749
3758
  // src/lib/runtime/remote-action-constructors.ts
3750
3759
  var import_shared11 = require("@copilotkit/shared");