@copilotkit/react-core 1.63.0 → 1.63.2-canary.1784918757

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.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_copilotkit = require('./copilotkit-nu7NwzH6.cjs');
4
+ const require_copilotkit = require('./copilotkit-rYTwMndy.cjs');
5
5
  let react = require("react");
6
6
  react = require_copilotkit.__toESM(react);
7
7
  let _copilotkit_core = require("@copilotkit/core");
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-BHs-vx6l.cjs";
1
+ import { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-CXvuYw_F.cjs";
2
2
  import "./v2/index.cjs";
3
3
  import * as react_jsx_runtime0 from "react/jsx-runtime";
4
4
  import { CopilotRuntimeClient, CopilotRuntimeClientOptions, ForwardedParametersInput, Message } from "@copilotkit/runtime-client-gql";
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-CN_LykOC.mjs";
1
+ import { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-BE1n5tSI.mjs";
2
2
  import "./v2/index.mjs";
3
3
  import React, { ReactNode, RefObject, SetStateAction } from "react";
4
4
  import { StaticSuggestionsConfig, Suggestion } from "@copilotkit/core";
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { Tt as useCopilotKit, X as useConfigureSuggestions, Y as useInterrupt, Z as useSuggestions, a as ThreadsProvider, c as CoAgentStateRendersProvider, ct as useRenderCustomMessages, d as shouldShowDevConsole, f as useToast, g as useCopilotContext, h as CopilotContext, i as ThreadsContext, jt as useCopilotChatConfiguration, l as useCoAgentStateRenders, m as useCopilotMessagesContext, n as defaultCopilotContextCategories, nt as useHumanInTheLoop$1, o as useThreads, ot as useFrontendTool$1, p as CopilotMessagesContext, r as CoAgentStateRenderBridge, s as CoAgentStateRendersContext, t as CopilotKit, tt as useAgent, u as useAsyncCallback, ut as defineToolCallRenderer, wt as useRenderToolCall$1 } from "./copilotkit-BLh58_Tt.mjs";
3
+ import { Tt as useCopilotKit, X as useConfigureSuggestions, Y as useInterrupt, Z as useSuggestions, a as ThreadsProvider, c as CoAgentStateRendersProvider, ct as useRenderCustomMessages, d as shouldShowDevConsole, f as useToast, g as useCopilotContext, h as CopilotContext, i as ThreadsContext, jt as useCopilotChatConfiguration, l as useCoAgentStateRenders, m as useCopilotMessagesContext, n as defaultCopilotContextCategories, nt as useHumanInTheLoop$1, o as useThreads, ot as useFrontendTool$1, p as CopilotMessagesContext, r as CoAgentStateRenderBridge, s as CoAgentStateRendersContext, t as CopilotKit, tt as useAgent, u as useAsyncCallback, ut as defineToolCallRenderer, wt as useRenderToolCall$1 } from "./copilotkit-DL0LvmwQ.mjs";
4
4
  import React, { Fragment, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
5
5
  import { CopilotKitCoreRuntimeConnectionStatus, ToolCallStatus } from "@copilotkit/core";
6
6
  import { AGUIConnectNotImplementedError, HttpAgent } from "@ag-ui/client";
package/dist/index.umd.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  (function(global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@copilotkit/core'), require('@ag-ui/client'), require('tailwind-merge'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('zod'), require('@lit-labs/react'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('react-markdown'), require('@copilotkit/runtime-client-gql')) :
5
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@copilotkit/core', '@ag-ui/client', 'tailwind-merge', '@copilotkit/shared', 'react/jsx-runtime', 'zod', '@lit-labs/react', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', 'react-markdown', '@copilotkit/runtime-client-gql'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.React,global.CopilotKitCore,global.AgUIClient,global.tailwind_merge,global.CopilotKitShared,global.ReactJsxRuntime,global.Zod,global._lit_labs_react,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global.ReactMarkdown,global.CopilotKitRuntimeClientGQL));
7
- })(this, function(exports, react, _copilotkit_core, _ag_ui_client, tailwind_merge, _copilotkit_shared, react_jsx_runtime, zod, _lit_labs_react, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, react_markdown, _copilotkit_runtime_client_gql) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@copilotkit/core'), require('@ag-ui/client'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('zod'), require('@lit-labs/react'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('react-markdown'), require('@copilotkit/runtime-client-gql')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@copilotkit/core', '@ag-ui/client', '@copilotkit/shared', 'react/jsx-runtime', 'zod', '@lit-labs/react', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', 'react-markdown', '@copilotkit/runtime-client-gql'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.React,global.CopilotKitCore,global.AgUIClient,global.CopilotKitShared,global.ReactJsxRuntime,global.Zod,global._lit_labs_react,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global.ReactMarkdown,global.CopilotKitRuntimeClientGQL));
7
+ })(this, function(exports, react, _copilotkit_core, _ag_ui_client, _copilotkit_shared, react_jsx_runtime, zod, _lit_labs_react, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, react_markdown, _copilotkit_runtime_client_gql) {
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
@@ -36,7 +36,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
36
  react = __toESM(react);
37
37
  react_markdown = __toESM(react_markdown);
38
38
 
39
- //#region src/v2/lib/slots.tsx
39
+ //#region src/v2/lib/shallow-stable-ref.ts
40
40
  /**
41
41
  * Shallow equality comparison for objects.
42
42
  */
@@ -76,49 +76,6 @@ react_markdown = __toESM(react_markdown);
76
76
  ref.current = value;
77
77
  return ref.current;
78
78
  }
79
- /**
80
- * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
81
- */
82
- function isReactComponentType(value) {
83
- if (typeof value === "function") return true;
84
- if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
85
- return false;
86
- }
87
- /**
88
- * Internal function to render a slot value as a React element (non-memoized).
89
- */
90
- function renderSlotElement(slot, DefaultComponent, props) {
91
- if (typeof slot === "string") {
92
- const existingClassName = props.className;
93
- return react.default.createElement(DefaultComponent, {
94
- ...props,
95
- className: (0, tailwind_merge.twMerge)(existingClassName, slot)
96
- });
97
- }
98
- if (isReactComponentType(slot)) return react.default.createElement(slot, props);
99
- if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
100
- ...props,
101
- ...slot
102
- });
103
- return react.default.createElement(DefaultComponent, props);
104
- }
105
- /**
106
- * Internal memoized wrapper component for renderSlot.
107
- * Uses forwardRef to support ref forwarding.
108
- */
109
- const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
110
- const { $slot, $component, ...rest } = props;
111
- return renderSlotElement($slot, $component, ref !== null ? {
112
- ...rest,
113
- ref
114
- } : rest);
115
- }), (prev, next) => {
116
- if (prev.$slot !== next.$slot) return false;
117
- if (prev.$component !== next.$component) return false;
118
- const { $slot: _ps, $component: _pc, ...prevRest } = prev;
119
- const { $slot: _ns, $component: _nc, ...nextRest } = next;
120
- return shallowEqual(prevRest, nextRest);
121
- });
122
79
 
123
80
  //#endregion
124
81
  //#region src/v2/providers/CopilotChatConfigurationProvider.tsx
@@ -2893,11 +2850,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2893
2850
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
2894
2851
  const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
2895
2852
  const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
2896
- const agent = (0, react.useMemo)(() => {
2853
+ const { agent, isReady } = (0, react.useMemo)(() => {
2897
2854
  const existing = copilotkit.getAgent(resolvedAgentId);
2898
2855
  if (existing) {
2899
2856
  provisionalAgentCache.current.delete(resolvedAgentId);
2900
- return existing;
2857
+ return {
2858
+ agent: existing,
2859
+ isReady: true
2860
+ };
2901
2861
  }
2902
2862
  const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
2903
2863
  const status = copilotkit.runtimeConnectionStatus;
@@ -2905,7 +2865,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2905
2865
  const cached = provisionalAgentCache.current.get(resolvedAgentId);
2906
2866
  if (cached) {
2907
2867
  copilotkit.applyHeadersToAgent(cached);
2908
- return cached;
2868
+ return {
2869
+ agent: cached,
2870
+ isReady: false
2871
+ };
2909
2872
  }
2910
2873
  const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
2911
2874
  runtimeUrl: copilotkit.runtimeUrl,
@@ -2915,13 +2878,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2915
2878
  });
2916
2879
  copilotkit.applyHeadersToAgent(provisional);
2917
2880
  provisionalAgentCache.current.set(resolvedAgentId, provisional);
2918
- return provisional;
2881
+ return {
2882
+ agent: provisional,
2883
+ isReady: false
2884
+ };
2919
2885
  }
2920
2886
  if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
2921
2887
  const cached = provisionalAgentCache.current.get(resolvedAgentId);
2922
2888
  if (cached) {
2923
2889
  copilotkit.applyHeadersToAgent(cached);
2924
- return cached;
2890
+ return {
2891
+ agent: cached,
2892
+ isReady: false
2893
+ };
2925
2894
  }
2926
2895
  const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
2927
2896
  runtimeUrl: copilotkit.runtimeUrl,
@@ -2931,7 +2900,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2931
2900
  });
2932
2901
  copilotkit.applyHeadersToAgent(provisional);
2933
2902
  provisionalAgentCache.current.set(resolvedAgentId, provisional);
2934
- return provisional;
2903
+ return {
2904
+ agent: provisional,
2905
+ isReady: false
2906
+ };
2935
2907
  }
2936
2908
  const knownAgents = Object.keys(copilotkit.agents ?? {});
2937
2909
  const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
@@ -2992,7 +2964,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2992
2964
  configThreadId,
2993
2965
  configHasExplicitThreadId
2994
2966
  ]);
2995
- return { agent };
2967
+ return {
2968
+ agent,
2969
+ isReady
2970
+ };
2996
2971
  }
2997
2972
 
2998
2973
  //#endregion
@@ -3255,8 +3230,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3255
3230
  const pendingRef = (0, react.useRef)(pending);
3256
3231
  pendingRef.current = pending;
3257
3232
  const [handlerResult, setHandlerResult] = (0, react.useState)(null);
3258
- const responsesRef = (0, react.useRef)({});
3233
+ const interruptStateRef = (0, react.useRef)(new _copilotkit_core.ɵInterruptState());
3259
3234
  (0, react.useEffect)(() => {
3235
+ const interruptState = interruptStateRef.current;
3260
3236
  let localLegacy = null;
3261
3237
  let localStandard = null;
3262
3238
  const subscription = agent.subscribe({
@@ -3272,106 +3248,111 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3272
3248
  onRunStartedEvent: () => {
3273
3249
  localLegacy = null;
3274
3250
  localStandard = null;
3275
- responsesRef.current = {};
3251
+ interruptState.clear();
3276
3252
  setPending(null);
3277
3253
  },
3278
3254
  onRunFinalized: () => {
3279
- if (localStandard && localStandard.length > 0) setPending({
3280
- kind: "standard",
3281
- interrupts: localStandard
3282
- });
3283
- else if (localLegacy) setPending({
3284
- kind: "legacy",
3285
- event: localLegacy
3286
- });
3255
+ if (localStandard && localStandard.length > 0) {
3256
+ interruptState.setStandard(localStandard);
3257
+ setPending(interruptState.pending);
3258
+ } else if (localLegacy) {
3259
+ interruptState.setLegacy(localLegacy);
3260
+ setPending(interruptState.pending);
3261
+ }
3287
3262
  localLegacy = null;
3288
3263
  localStandard = null;
3289
3264
  },
3290
3265
  onRunFailed: () => {
3291
3266
  localLegacy = null;
3292
3267
  localStandard = null;
3293
- responsesRef.current = {};
3268
+ interruptState.clear();
3294
3269
  setPending(null);
3295
3270
  }
3296
3271
  });
3297
- return () => subscription.unsubscribe();
3272
+ return () => {
3273
+ subscription.unsubscribe();
3274
+ interruptState.clear();
3275
+ };
3298
3276
  }, [agent]);
3299
- const submitStandardIfComplete = (0, react.useCallback)(async (interrupts) => {
3300
- if (!interrupts.every((i) => responsesRef.current[i.id])) return;
3301
- const expired = interrupts.find((i) => (0, _ag_ui_client.isInterruptExpired)(i));
3302
- if (expired) {
3303
- console.error(`[CopilotKit] useInterrupt: interrupt ${expired.id} expired at ${expired.expiresAt}; not resuming.`);
3304
- responsesRef.current = {};
3305
- setPending(null);
3306
- return;
3307
- }
3308
- const resume = (0, _ag_ui_client.buildResumeArray)(interrupts, responsesRef.current);
3309
- for (const i of interrupts) {
3310
- if (!i.toolCallId) continue;
3311
- const response = responsesRef.current[i.id];
3312
- const content = response.status === "cancelled" ? { status: "cancelled" } : response.payload ?? { status: "resolved" };
3313
- agent.addMessage({
3314
- id: (0, _ag_ui_client.randomUUID)(),
3315
- role: "tool",
3316
- toolCallId: i.toolCallId,
3317
- content: JSON.stringify(content)
3318
- });
3319
- }
3320
- responsesRef.current = {};
3321
- try {
3277
+ const resolve = (0, react.useCallback)(async (payload, interruptId) => {
3278
+ const current = pendingRef.current;
3279
+ if (!current) return;
3280
+ if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
3281
+ const decision = interruptStateRef.current.resolve(payload, interruptId);
3282
+ if (decision.kind === "legacy-resume") try {
3322
3283
  return await copilotkit.runAgent({
3323
3284
  agent,
3324
- resume
3285
+ forwardedProps: { command: {
3286
+ resume: decision.payload,
3287
+ interruptEvent: decision.interruptValue
3288
+ } }
3325
3289
  });
3326
3290
  } catch (err) {
3327
3291
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
3328
3292
  setPending(null);
3329
3293
  throw err;
3330
3294
  }
3331
- }, [agent, copilotkit]);
3332
- const resolve = (0, react.useCallback)(async (payload, interruptId) => {
3333
- const current = pendingRef.current;
3334
- if (!current) return;
3335
- if (current.kind === "legacy") try {
3295
+ if (decision.kind === "expired") {
3296
+ console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
3297
+ interruptStateRef.current.clear();
3298
+ setPending(null);
3299
+ return;
3300
+ }
3301
+ if (decision.kind !== "resume") return;
3302
+ for (const toolResult of decision.toolResults) agent.addMessage({
3303
+ id: (0, _ag_ui_client.randomUUID)(),
3304
+ role: "tool",
3305
+ toolCallId: toolResult.toolCallId,
3306
+ content: toolResult.content
3307
+ });
3308
+ try {
3336
3309
  return await copilotkit.runAgent({
3337
3310
  agent,
3338
- forwardedProps: { command: {
3339
- resume: payload,
3340
- interruptEvent: current.event.value
3341
- } }
3311
+ resume: decision.resume
3342
3312
  });
3343
3313
  } catch (err) {
3344
3314
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
3315
+ interruptStateRef.current.clear();
3345
3316
  setPending(null);
3346
3317
  throw err;
3347
3318
  }
3348
- if (current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
3349
- const id = interruptId ?? current.interrupts[0]?.id;
3350
- if (!id) return;
3351
- responsesRef.current[id] = {
3352
- status: "resolved",
3353
- payload
3354
- };
3355
- return submitStandardIfComplete(current.interrupts);
3356
- }, [
3357
- agent,
3358
- copilotkit,
3359
- submitStandardIfComplete
3360
- ]);
3319
+ }, [agent, copilotkit]);
3361
3320
  const cancel = (0, react.useCallback)(async (interruptId) => {
3362
3321
  const current = pendingRef.current;
3363
3322
  if (!current) return;
3364
- if (current.kind === "legacy") {
3323
+ if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
3324
+ const decision = interruptStateRef.current.cancel(interruptId);
3325
+ if (decision.kind === "dismiss") {
3365
3326
  console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
3327
+ interruptStateRef.current.clear();
3366
3328
  setPending(null);
3367
3329
  return;
3368
3330
  }
3369
- if (current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
3370
- const id = interruptId ?? current.interrupts[0]?.id;
3371
- if (!id) return;
3372
- responsesRef.current[id] = { status: "cancelled" };
3373
- return submitStandardIfComplete(current.interrupts);
3374
- }, [submitStandardIfComplete]);
3331
+ if (decision.kind === "expired") {
3332
+ console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
3333
+ interruptStateRef.current.clear();
3334
+ setPending(null);
3335
+ return;
3336
+ }
3337
+ if (decision.kind !== "resume") return;
3338
+ for (const toolResult of decision.toolResults) agent.addMessage({
3339
+ id: (0, _ag_ui_client.randomUUID)(),
3340
+ role: "tool",
3341
+ toolCallId: toolResult.toolCallId,
3342
+ content: toolResult.content
3343
+ });
3344
+ try {
3345
+ return await copilotkit.runAgent({
3346
+ agent,
3347
+ resume: decision.resume
3348
+ });
3349
+ } catch (err) {
3350
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
3351
+ interruptStateRef.current.clear();
3352
+ setPending(null);
3353
+ throw err;
3354
+ }
3355
+ }, [agent, copilotkit]);
3375
3356
  const renderRef = (0, react.useRef)(config.render);
3376
3357
  renderRef.current = config.render;
3377
3358
  const enabledRef = (0, react.useRef)(config.enabled);
@@ -3413,7 +3394,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3413
3394
  maybePromise = handler({
3414
3395
  event: legacyEvent,
3415
3396
  interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
3416
- interrupts: pending.kind === "standard" ? pending.interrupts : [],
3397
+ interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
3417
3398
  resolve: resolveRef.current,
3418
3399
  cancel: cancelRef.current
3419
3400
  });
@@ -3442,7 +3423,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3442
3423
  return renderRef.current({
3443
3424
  event: legacyEvent,
3444
3425
  interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
3445
- interrupts: pending.kind === "standard" ? pending.interrupts : [],
3426
+ interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
3446
3427
  result: handlerResult,
3447
3428
  resolve,
3448
3429
  cancel