@copilotkit/react-core 1.61.1 → 1.61.2
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/{copilotkit-UY-H6Kx7.mjs → copilotkit-Be-o2UaU.mjs} +210 -119
- package/dist/copilotkit-Be-o2UaU.mjs.map +1 -0
- package/dist/{copilotkit-M1FiciGd.d.mts → copilotkit-Bpt1c_-q.d.mts} +79 -71
- package/dist/copilotkit-Bpt1c_-q.d.mts.map +1 -0
- package/dist/{copilotkit-BCJDP8qd.cjs → copilotkit-CTCjVxkH.cjs} +199 -108
- package/dist/copilotkit-CTCjVxkH.cjs.map +1 -0
- package/dist/{copilotkit-CEdu_aie.d.cts → copilotkit-ClqbUuGX.d.cts} +79 -71
- package/dist/copilotkit-ClqbUuGX.d.cts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +167 -94
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.d.cts +5 -1
- package/dist/v2/context.d.cts.map +1 -1
- package/dist/v2/context.d.mts +5 -1
- package/dist/v2/context.d.mts.map +1 -1
- package/dist/v2/headless.cjs +167 -93
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +76 -68
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +76 -68
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +168 -94
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +198 -107
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/dist/copilotkit-BCJDP8qd.cjs.map +0 -1
- package/dist/copilotkit-CEdu_aie.d.cts.map +0 -1
- package/dist/copilotkit-M1FiciGd.d.mts.map +0 -1
- package/dist/copilotkit-UY-H6Kx7.mjs.map +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -2280,6 +2280,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2280
2280
|
|
|
2281
2281
|
//#endregion
|
|
2282
2282
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
2283
|
+
const zodToJsonSchemaAdapter = (schema, options) => {
|
|
2284
|
+
const refStrategy = options?.$refStrategy;
|
|
2285
|
+
return (0, zod_to_json_schema.zodToJsonSchema)(schema, refStrategy === "root" || refStrategy === "relative" || refStrategy === "none" || refStrategy === "seen" ? { $refStrategy: refStrategy } : {});
|
|
2286
|
+
};
|
|
2283
2287
|
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
2284
2288
|
const COPILOT_CLOUD_CHAT_URL$1 = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
2285
2289
|
const EMPTY_HEADERS = Object.freeze({});
|
|
@@ -2310,6 +2314,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2310
2314
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
2311
2315
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
2312
2316
|
const openGenUIActive = runtimeOpenGenUIEnabled || !!openGenerativeUI;
|
|
2317
|
+
const a2uiCatalogProvided = !!a2ui?.catalog;
|
|
2318
|
+
const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
|
|
2313
2319
|
const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
|
|
2314
2320
|
(0, react.useEffect)(() => {
|
|
2315
2321
|
if (typeof window === "undefined") return;
|
|
@@ -2340,7 +2346,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2340
2346
|
content: OpenGenerativeUIContentSchema,
|
|
2341
2347
|
render: OpenGenerativeUIActivityRenderer
|
|
2342
2348
|
});
|
|
2343
|
-
if (
|
|
2349
|
+
if (a2uiActive) renderers.unshift(createA2UIMessageRenderer({
|
|
2344
2350
|
theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
|
|
2345
2351
|
catalog: a2ui?.catalog,
|
|
2346
2352
|
loadingComponent: a2ui?.loadingComponent,
|
|
@@ -2348,7 +2354,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2348
2354
|
}));
|
|
2349
2355
|
return renderers;
|
|
2350
2356
|
}, [
|
|
2351
|
-
|
|
2357
|
+
a2uiActive,
|
|
2352
2358
|
openGenUIActive,
|
|
2353
2359
|
a2ui
|
|
2354
2360
|
]);
|
|
@@ -2535,7 +2541,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2535
2541
|
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
2536
2542
|
copilotkit.setHeaders(mergedHeaders);
|
|
2537
2543
|
copilotkit.setCredentials(credentials);
|
|
2538
|
-
copilotkit.setProperties(
|
|
2544
|
+
copilotkit.setProperties(a2uiCatalogProvided ? {
|
|
2545
|
+
...properties,
|
|
2546
|
+
a2uiCatalogAvailable: true
|
|
2547
|
+
} : properties);
|
|
2539
2548
|
copilotkit.setAgents__unsafe_dev_only(mergedAgents);
|
|
2540
2549
|
copilotkit.setDebug(debug);
|
|
2541
2550
|
}, [
|
|
@@ -2544,6 +2553,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2544
2553
|
mergedHeaders,
|
|
2545
2554
|
credentials,
|
|
2546
2555
|
properties,
|
|
2556
|
+
a2uiCatalogProvided,
|
|
2547
2557
|
mergedAgents,
|
|
2548
2558
|
useSingleEndpoint,
|
|
2549
2559
|
debug
|
|
@@ -2591,7 +2601,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2591
2601
|
return JSON.stringify(sandboxFunctionsList.map((fn) => ({
|
|
2592
2602
|
name: fn.name,
|
|
2593
2603
|
description: fn.description,
|
|
2594
|
-
parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema:
|
|
2604
|
+
parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zodToJsonSchemaAdapter })
|
|
2595
2605
|
})));
|
|
2596
2606
|
}, [sandboxFunctionsList]);
|
|
2597
2607
|
(0, react.useLayoutEffect)(() => {
|
|
@@ -2612,7 +2622,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2612
2622
|
copilotkit,
|
|
2613
2623
|
executingToolCallIds
|
|
2614
2624
|
}), [copilotkit, executingToolCallIds]);
|
|
2615
|
-
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(
|
|
2625
|
+
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(runtimeLicenseStatus), [runtimeLicenseStatus]);
|
|
2616
2626
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
|
|
2617
2627
|
value: sandboxFunctionsList,
|
|
2618
2628
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
|
|
@@ -2620,8 +2630,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2620
2630
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
|
|
2621
2631
|
value: licenseContextValue,
|
|
2622
2632
|
children: [
|
|
2623
|
-
|
|
2624
|
-
|
|
2633
|
+
a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
2634
|
+
a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
2625
2635
|
catalog: a2ui?.catalog,
|
|
2626
2636
|
includeSchema: a2ui?.includeSchema
|
|
2627
2637
|
}),
|
|
@@ -2838,7 +2848,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2838
2848
|
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
2839
2849
|
const cached = provisionalAgentCache.current.get(agentId);
|
|
2840
2850
|
if (cached) {
|
|
2841
|
-
|
|
2851
|
+
copilotkit.applyHeadersToAgent(cached);
|
|
2842
2852
|
return cached;
|
|
2843
2853
|
}
|
|
2844
2854
|
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
@@ -2847,14 +2857,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2847
2857
|
transport: copilotkit.runtimeTransport,
|
|
2848
2858
|
runtimeMode: "pending"
|
|
2849
2859
|
});
|
|
2850
|
-
|
|
2860
|
+
copilotkit.applyHeadersToAgent(provisional);
|
|
2851
2861
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
2852
2862
|
return provisional;
|
|
2853
2863
|
}
|
|
2854
2864
|
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
2855
2865
|
const cached = provisionalAgentCache.current.get(agentId);
|
|
2856
2866
|
if (cached) {
|
|
2857
|
-
|
|
2867
|
+
copilotkit.applyHeadersToAgent(cached);
|
|
2858
2868
|
return cached;
|
|
2859
2869
|
}
|
|
2860
2870
|
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
@@ -2863,7 +2873,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2863
2873
|
transport: copilotkit.runtimeTransport,
|
|
2864
2874
|
runtimeMode: "pending"
|
|
2865
2875
|
});
|
|
2866
|
-
|
|
2876
|
+
copilotkit.applyHeadersToAgent(provisional);
|
|
2867
2877
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
2868
2878
|
return provisional;
|
|
2869
2879
|
}
|
|
@@ -2914,7 +2924,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2914
2924
|
updateFlags
|
|
2915
2925
|
]);
|
|
2916
2926
|
(0, react.useEffect)(() => {
|
|
2917
|
-
if (agent instanceof _ag_ui_client.HttpAgent)
|
|
2927
|
+
if (agent instanceof _ag_ui_client.HttpAgent) copilotkit.applyHeadersToAgent(agent);
|
|
2918
2928
|
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
2919
2929
|
const chatConfig = useCopilotChatConfiguration();
|
|
2920
2930
|
const configThreadId = chatConfig?.threadId;
|
|
@@ -3148,114 +3158,165 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3148
3158
|
function isPromiseLike(value) {
|
|
3149
3159
|
return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
|
|
3150
3160
|
}
|
|
3161
|
+
/** Derive the legacy-compatible `event` for any pending interrupt. */
|
|
3162
|
+
function toLegacyEvent(pending) {
|
|
3163
|
+
if (pending.kind === "legacy") return pending.event;
|
|
3164
|
+
return {
|
|
3165
|
+
name: INTERRUPT_EVENT_NAME,
|
|
3166
|
+
value: pending.interrupts[0]
|
|
3167
|
+
};
|
|
3168
|
+
}
|
|
3151
3169
|
/**
|
|
3152
|
-
* Handles agent interrupts
|
|
3153
|
-
*
|
|
3154
|
-
* The hook listens to custom events on the active agent, stores interrupt payloads per run,
|
|
3155
|
-
* and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
|
|
3156
|
-
* execution with user-provided data.
|
|
3157
|
-
*
|
|
3158
|
-
* - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.
|
|
3159
|
-
* - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.
|
|
3170
|
+
* Handles agent interrupts with optional filtering, preprocessing, and resume behavior.
|
|
3160
3171
|
*
|
|
3161
|
-
*
|
|
3162
|
-
*
|
|
3163
|
-
*
|
|
3164
|
-
*
|
|
3165
|
-
*
|
|
3166
|
-
*
|
|
3167
|
-
*
|
|
3168
|
-
* either the handler's resolved return value or `null` (including when no handler is provided,
|
|
3169
|
-
* when filtering skips the interrupt, or when handler execution fails).
|
|
3170
|
-
*
|
|
3171
|
-
* @example
|
|
3172
|
-
* ```tsx
|
|
3173
|
-
* import { useInterrupt } from "@copilotkit/react-core/v2";
|
|
3174
|
-
*
|
|
3175
|
-
* function InterruptUI() {
|
|
3176
|
-
* useInterrupt({
|
|
3177
|
-
* render: ({ event, resolve }) => (
|
|
3178
|
-
* <div>
|
|
3179
|
-
* <p>{event.value.question}</p>
|
|
3180
|
-
* <button onClick={() => resolve({ approved: true })}>Approve</button>
|
|
3181
|
-
* <button onClick={() => resolve({ approved: false })}>Reject</button>
|
|
3182
|
-
* </div>
|
|
3183
|
-
* ),
|
|
3184
|
-
* });
|
|
3172
|
+
* Supports both the AG-UI standard interrupt flow (`RUN_FINISHED` with
|
|
3173
|
+
* `outcome.type === "interrupt"`) and the legacy custom-event flow
|
|
3174
|
+
* (`on_interrupt`). For standard interrupts, `render` receives `interrupt`
|
|
3175
|
+
* (the primary one) and `interrupts` (the full open set); call `resolve(payload)`
|
|
3176
|
+
* to resume or `cancel()` to cancel. Resuming addresses the targeted interrupt
|
|
3177
|
+
* and, once every open interrupt is addressed, submits a single spec `resume`
|
|
3178
|
+
* array via `copilotkit.runAgent`.
|
|
3185
3179
|
*
|
|
3186
|
-
*
|
|
3187
|
-
*
|
|
3188
|
-
* ```
|
|
3180
|
+
* - `renderInChat: true` (default): the element is published into `<CopilotChat>`; returns `void`.
|
|
3181
|
+
* - `renderInChat: false`: the hook returns the interrupt element for manual placement.
|
|
3189
3182
|
*
|
|
3190
3183
|
* @example
|
|
3191
3184
|
* ```tsx
|
|
3192
|
-
*
|
|
3193
|
-
*
|
|
3194
|
-
*
|
|
3195
|
-
*
|
|
3196
|
-
*
|
|
3197
|
-
*
|
|
3198
|
-
*
|
|
3199
|
-
*
|
|
3200
|
-
*
|
|
3201
|
-
* <strong>{result?.label ?? ""}</strong>
|
|
3202
|
-
* <button onClick={() => resolve({ value: event.value })}>Continue</button>
|
|
3203
|
-
* </aside>
|
|
3204
|
-
* ),
|
|
3205
|
-
* });
|
|
3206
|
-
*
|
|
3207
|
-
* return <>{interruptElement}</>;
|
|
3208
|
-
* }
|
|
3185
|
+
* useInterrupt({
|
|
3186
|
+
* render: ({ interrupt, resolve, cancel }) => (
|
|
3187
|
+
* <div>
|
|
3188
|
+
* <p>{interrupt?.message}</p>
|
|
3189
|
+
* <button onClick={() => resolve({ approved: true })}>Approve</button>
|
|
3190
|
+
* <button onClick={() => cancel()}>Cancel</button>
|
|
3191
|
+
* </div>
|
|
3192
|
+
* ),
|
|
3193
|
+
* });
|
|
3209
3194
|
* ```
|
|
3210
3195
|
*/
|
|
3211
3196
|
function useInterrupt(config) {
|
|
3212
3197
|
const { copilotkit } = useCopilotKit();
|
|
3213
3198
|
const { agent } = useAgent({ agentId: config.agentId });
|
|
3214
|
-
const [
|
|
3215
|
-
const
|
|
3216
|
-
|
|
3199
|
+
const [pending, setPending] = (0, react.useState)(null);
|
|
3200
|
+
const pendingRef = (0, react.useRef)(pending);
|
|
3201
|
+
pendingRef.current = pending;
|
|
3217
3202
|
const [handlerResult, setHandlerResult] = (0, react.useState)(null);
|
|
3203
|
+
const responsesRef = (0, react.useRef)({});
|
|
3218
3204
|
(0, react.useEffect)(() => {
|
|
3219
|
-
let
|
|
3205
|
+
let localLegacy = null;
|
|
3206
|
+
let localStandard = null;
|
|
3220
3207
|
const subscription = agent.subscribe({
|
|
3221
3208
|
onCustomEvent: ({ event }) => {
|
|
3222
|
-
if (event.name === INTERRUPT_EVENT_NAME)
|
|
3209
|
+
if (event.name === INTERRUPT_EVENT_NAME) localLegacy = {
|
|
3223
3210
|
name: event.name,
|
|
3224
3211
|
value: event.value
|
|
3225
3212
|
};
|
|
3226
3213
|
},
|
|
3214
|
+
onRunFinishedEvent: (params) => {
|
|
3215
|
+
if (params.outcome === "interrupt") localStandard = params.interrupts;
|
|
3216
|
+
},
|
|
3227
3217
|
onRunStartedEvent: () => {
|
|
3228
|
-
|
|
3229
|
-
|
|
3218
|
+
localLegacy = null;
|
|
3219
|
+
localStandard = null;
|
|
3220
|
+
responsesRef.current = {};
|
|
3221
|
+
setPending(null);
|
|
3230
3222
|
},
|
|
3231
3223
|
onRunFinalized: () => {
|
|
3232
|
-
if (
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
}
|
|
3224
|
+
if (localStandard && localStandard.length > 0) setPending({
|
|
3225
|
+
kind: "standard",
|
|
3226
|
+
interrupts: localStandard
|
|
3227
|
+
});
|
|
3228
|
+
else if (localLegacy) setPending({
|
|
3229
|
+
kind: "legacy",
|
|
3230
|
+
event: localLegacy
|
|
3231
|
+
});
|
|
3232
|
+
localLegacy = null;
|
|
3233
|
+
localStandard = null;
|
|
3236
3234
|
},
|
|
3237
3235
|
onRunFailed: () => {
|
|
3238
|
-
|
|
3239
|
-
|
|
3236
|
+
localLegacy = null;
|
|
3237
|
+
localStandard = null;
|
|
3238
|
+
responsesRef.current = {};
|
|
3239
|
+
setPending(null);
|
|
3240
3240
|
}
|
|
3241
3241
|
});
|
|
3242
3242
|
return () => subscription.unsubscribe();
|
|
3243
3243
|
}, [agent]);
|
|
3244
|
-
const
|
|
3244
|
+
const submitStandardIfComplete = (0, react.useCallback)(async (interrupts) => {
|
|
3245
|
+
if (!interrupts.every((i) => responsesRef.current[i.id])) return;
|
|
3246
|
+
const expired = interrupts.find((i) => (0, _ag_ui_client.isInterruptExpired)(i));
|
|
3247
|
+
if (expired) {
|
|
3248
|
+
console.error(`[CopilotKit] useInterrupt: interrupt ${expired.id} expired at ${expired.expiresAt}; not resuming.`);
|
|
3249
|
+
responsesRef.current = {};
|
|
3250
|
+
setPending(null);
|
|
3251
|
+
return;
|
|
3252
|
+
}
|
|
3253
|
+
const resume = (0, _ag_ui_client.buildResumeArray)(interrupts, responsesRef.current);
|
|
3254
|
+
for (const i of interrupts) {
|
|
3255
|
+
if (!i.toolCallId) continue;
|
|
3256
|
+
const response = responsesRef.current[i.id];
|
|
3257
|
+
const content = response.status === "cancelled" ? { status: "cancelled" } : response.payload ?? { status: "resolved" };
|
|
3258
|
+
agent.addMessage({
|
|
3259
|
+
id: (0, _ag_ui_client.randomUUID)(),
|
|
3260
|
+
role: "tool",
|
|
3261
|
+
toolCallId: i.toolCallId,
|
|
3262
|
+
content: JSON.stringify(content)
|
|
3263
|
+
});
|
|
3264
|
+
}
|
|
3265
|
+
responsesRef.current = {};
|
|
3245
3266
|
try {
|
|
3267
|
+
return await copilotkit.runAgent({
|
|
3268
|
+
agent,
|
|
3269
|
+
resume
|
|
3270
|
+
});
|
|
3271
|
+
} catch (err) {
|
|
3272
|
+
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
3273
|
+
setPending(null);
|
|
3274
|
+
throw err;
|
|
3275
|
+
}
|
|
3276
|
+
}, [agent, copilotkit]);
|
|
3277
|
+
const resolve = (0, react.useCallback)(async (payload, interruptId) => {
|
|
3278
|
+
const current = pendingRef.current;
|
|
3279
|
+
if (!current) return;
|
|
3280
|
+
if (current.kind === "legacy") try {
|
|
3246
3281
|
return await copilotkit.runAgent({
|
|
3247
3282
|
agent,
|
|
3248
3283
|
forwardedProps: { command: {
|
|
3249
|
-
resume:
|
|
3250
|
-
interruptEvent:
|
|
3284
|
+
resume: payload,
|
|
3285
|
+
interruptEvent: current.event.value
|
|
3251
3286
|
} }
|
|
3252
3287
|
});
|
|
3253
3288
|
} catch (err) {
|
|
3254
3289
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
3255
|
-
|
|
3290
|
+
setPending(null);
|
|
3256
3291
|
throw err;
|
|
3257
3292
|
}
|
|
3258
|
-
|
|
3293
|
+
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.`);
|
|
3294
|
+
const id = interruptId ?? current.interrupts[0]?.id;
|
|
3295
|
+
if (!id) return;
|
|
3296
|
+
responsesRef.current[id] = {
|
|
3297
|
+
status: "resolved",
|
|
3298
|
+
payload
|
|
3299
|
+
};
|
|
3300
|
+
return submitStandardIfComplete(current.interrupts);
|
|
3301
|
+
}, [
|
|
3302
|
+
agent,
|
|
3303
|
+
copilotkit,
|
|
3304
|
+
submitStandardIfComplete
|
|
3305
|
+
]);
|
|
3306
|
+
const cancel = (0, react.useCallback)(async (interruptId) => {
|
|
3307
|
+
const current = pendingRef.current;
|
|
3308
|
+
if (!current) return;
|
|
3309
|
+
if (current.kind === "legacy") {
|
|
3310
|
+
console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
|
|
3311
|
+
setPending(null);
|
|
3312
|
+
return;
|
|
3313
|
+
}
|
|
3314
|
+
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.`);
|
|
3315
|
+
const id = interruptId ?? current.interrupts[0]?.id;
|
|
3316
|
+
if (!id) return;
|
|
3317
|
+
responsesRef.current[id] = { status: "cancelled" };
|
|
3318
|
+
return submitStandardIfComplete(current.interrupts);
|
|
3319
|
+
}, [submitStandardIfComplete]);
|
|
3259
3320
|
const renderRef = (0, react.useRef)(config.render);
|
|
3260
3321
|
renderRef.current = config.render;
|
|
3261
3322
|
const enabledRef = (0, react.useRef)(config.enabled);
|
|
@@ -3264,6 +3325,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3264
3325
|
handlerRef.current = config.handler;
|
|
3265
3326
|
const resolveRef = (0, react.useRef)(resolve);
|
|
3266
3327
|
resolveRef.current = resolve;
|
|
3328
|
+
const cancelRef = (0, react.useRef)(cancel);
|
|
3329
|
+
cancelRef.current = cancel;
|
|
3267
3330
|
const isEnabled = (event) => {
|
|
3268
3331
|
const predicate = enabledRef.current;
|
|
3269
3332
|
if (!predicate) return true;
|
|
@@ -3275,11 +3338,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3275
3338
|
}
|
|
3276
3339
|
};
|
|
3277
3340
|
(0, react.useEffect)(() => {
|
|
3278
|
-
if (!
|
|
3341
|
+
if (!pending) {
|
|
3279
3342
|
setHandlerResult(null);
|
|
3280
3343
|
return;
|
|
3281
3344
|
}
|
|
3282
|
-
|
|
3345
|
+
const legacyEvent = toLegacyEvent(pending);
|
|
3346
|
+
if (!isEnabled(legacyEvent)) {
|
|
3283
3347
|
setHandlerResult(null);
|
|
3284
3348
|
return;
|
|
3285
3349
|
}
|
|
@@ -3292,8 +3356,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3292
3356
|
let maybePromise;
|
|
3293
3357
|
try {
|
|
3294
3358
|
maybePromise = handler({
|
|
3295
|
-
event:
|
|
3296
|
-
|
|
3359
|
+
event: legacyEvent,
|
|
3360
|
+
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
3361
|
+
interrupts: pending.kind === "standard" ? pending.interrupts : [],
|
|
3362
|
+
resolve: resolveRef.current,
|
|
3363
|
+
cancel: cancelRef.current
|
|
3297
3364
|
});
|
|
3298
3365
|
} catch (err) {
|
|
3299
3366
|
console.error("[CopilotKit] useInterrupt handler threw; result will be null:", err);
|
|
@@ -3312,19 +3379,24 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3312
3379
|
return () => {
|
|
3313
3380
|
cancelled = true;
|
|
3314
3381
|
};
|
|
3315
|
-
}, [
|
|
3382
|
+
}, [pending]);
|
|
3316
3383
|
const element = (0, react.useMemo)(() => {
|
|
3317
|
-
if (!
|
|
3318
|
-
|
|
3384
|
+
if (!pending) return null;
|
|
3385
|
+
const legacyEvent = toLegacyEvent(pending);
|
|
3386
|
+
if (!isEnabled(legacyEvent)) return null;
|
|
3319
3387
|
return renderRef.current({
|
|
3320
|
-
event:
|
|
3388
|
+
event: legacyEvent,
|
|
3389
|
+
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
3390
|
+
interrupts: pending.kind === "standard" ? pending.interrupts : [],
|
|
3321
3391
|
result: handlerResult,
|
|
3322
|
-
resolve
|
|
3392
|
+
resolve,
|
|
3393
|
+
cancel
|
|
3323
3394
|
});
|
|
3324
3395
|
}, [
|
|
3325
|
-
|
|
3396
|
+
pending,
|
|
3326
3397
|
handlerResult,
|
|
3327
|
-
resolve
|
|
3398
|
+
resolve,
|
|
3399
|
+
cancel
|
|
3328
3400
|
]);
|
|
3329
3401
|
(0, react.useEffect)(() => {
|
|
3330
3402
|
if (config.renderInChat === false) return;
|
|
@@ -4982,6 +5054,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4982
5054
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
4983
5055
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
4984
5056
|
const renderArr = (0, react.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
5057
|
+
const { onError: _onError, ...v2Props } = props;
|
|
4985
5058
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToastProvider, {
|
|
4986
5059
|
enabled,
|
|
4987
5060
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotErrorBoundary, {
|
|
@@ -4990,7 +5063,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4990
5063
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ThreadsProvider, {
|
|
4991
5064
|
threadId: props.threadId,
|
|
4992
5065
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitProvider, {
|
|
4993
|
-
...
|
|
5066
|
+
...v2Props,
|
|
4994
5067
|
showDevConsole: showInspector,
|
|
4995
5068
|
renderCustomMessages: renderArr,
|
|
4996
5069
|
useSingleEndpoint: props.useSingleEndpoint ?? true,
|