@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
|
@@ -1520,10 +1520,20 @@ function useRenderTool(config, deps) {
|
|
|
1520
1520
|
}) : defineToolCallRenderer({
|
|
1521
1521
|
name: config.name,
|
|
1522
1522
|
args: config.parameters,
|
|
1523
|
-
render: (props) =>
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1523
|
+
render: (props) => {
|
|
1524
|
+
if (props.status === _copilotkit_core.ToolCallStatus.InProgress) return config.render({
|
|
1525
|
+
...props,
|
|
1526
|
+
parameters: props.args
|
|
1527
|
+
});
|
|
1528
|
+
if (props.status === _copilotkit_core.ToolCallStatus.Executing) return config.render({
|
|
1529
|
+
...props,
|
|
1530
|
+
parameters: props.args
|
|
1531
|
+
});
|
|
1532
|
+
return config.render({
|
|
1533
|
+
...props,
|
|
1534
|
+
parameters: props.args
|
|
1535
|
+
});
|
|
1536
|
+
},
|
|
1527
1537
|
...config.agentId ? { agentId: config.agentId } : {}
|
|
1528
1538
|
});
|
|
1529
1539
|
copilotkit.addHookRenderToolCall(renderer);
|
|
@@ -3561,6 +3571,10 @@ function A2UICatalogContext({ catalog, includeSchema }) {
|
|
|
3561
3571
|
|
|
3562
3572
|
//#endregion
|
|
3563
3573
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
3574
|
+
const zodToJsonSchemaAdapter = (schema, options) => {
|
|
3575
|
+
const refStrategy = options?.$refStrategy;
|
|
3576
|
+
return (0, zod_to_json_schema.zodToJsonSchema)(schema, refStrategy === "root" || refStrategy === "relative" || refStrategy === "none" || refStrategy === "seen" ? { $refStrategy: refStrategy } : {});
|
|
3577
|
+
};
|
|
3564
3578
|
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
3565
3579
|
const COPILOT_CLOUD_CHAT_URL$1 = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
3566
3580
|
const EMPTY_HEADERS = Object.freeze({});
|
|
@@ -3591,6 +3605,8 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3591
3605
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
3592
3606
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
3593
3607
|
const openGenUIActive = runtimeOpenGenUIEnabled || !!openGenerativeUI;
|
|
3608
|
+
const a2uiCatalogProvided = !!a2ui?.catalog;
|
|
3609
|
+
const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
|
|
3594
3610
|
const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
|
|
3595
3611
|
(0, react.useEffect)(() => {
|
|
3596
3612
|
if (typeof window === "undefined") return;
|
|
@@ -3621,7 +3637,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3621
3637
|
content: OpenGenerativeUIContentSchema,
|
|
3622
3638
|
render: OpenGenerativeUIActivityRenderer
|
|
3623
3639
|
});
|
|
3624
|
-
if (
|
|
3640
|
+
if (a2uiActive) renderers.unshift(createA2UIMessageRenderer({
|
|
3625
3641
|
theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
|
|
3626
3642
|
catalog: a2ui?.catalog,
|
|
3627
3643
|
loadingComponent: a2ui?.loadingComponent,
|
|
@@ -3629,7 +3645,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3629
3645
|
}));
|
|
3630
3646
|
return renderers;
|
|
3631
3647
|
}, [
|
|
3632
|
-
|
|
3648
|
+
a2uiActive,
|
|
3633
3649
|
openGenUIActive,
|
|
3634
3650
|
a2ui
|
|
3635
3651
|
]);
|
|
@@ -3816,7 +3832,10 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3816
3832
|
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
3817
3833
|
copilotkit.setHeaders(mergedHeaders);
|
|
3818
3834
|
copilotkit.setCredentials(credentials);
|
|
3819
|
-
copilotkit.setProperties(
|
|
3835
|
+
copilotkit.setProperties(a2uiCatalogProvided ? {
|
|
3836
|
+
...properties,
|
|
3837
|
+
a2uiCatalogAvailable: true
|
|
3838
|
+
} : properties);
|
|
3820
3839
|
copilotkit.setAgents__unsafe_dev_only(mergedAgents);
|
|
3821
3840
|
copilotkit.setDebug(debug);
|
|
3822
3841
|
}, [
|
|
@@ -3825,6 +3844,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3825
3844
|
mergedHeaders,
|
|
3826
3845
|
credentials,
|
|
3827
3846
|
properties,
|
|
3847
|
+
a2uiCatalogProvided,
|
|
3828
3848
|
mergedAgents,
|
|
3829
3849
|
useSingleEndpoint,
|
|
3830
3850
|
debug
|
|
@@ -3872,7 +3892,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3872
3892
|
return JSON.stringify(sandboxFunctionsList.map((fn) => ({
|
|
3873
3893
|
name: fn.name,
|
|
3874
3894
|
description: fn.description,
|
|
3875
|
-
parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema:
|
|
3895
|
+
parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zodToJsonSchemaAdapter })
|
|
3876
3896
|
})));
|
|
3877
3897
|
}, [sandboxFunctionsList]);
|
|
3878
3898
|
(0, react.useLayoutEffect)(() => {
|
|
@@ -3893,7 +3913,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3893
3913
|
copilotkit,
|
|
3894
3914
|
executingToolCallIds
|
|
3895
3915
|
}), [copilotkit, executingToolCallIds]);
|
|
3896
|
-
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(
|
|
3916
|
+
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(runtimeLicenseStatus), [runtimeLicenseStatus]);
|
|
3897
3917
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
|
|
3898
3918
|
value: sandboxFunctionsList,
|
|
3899
3919
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
|
|
@@ -3901,8 +3921,8 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3901
3921
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
|
|
3902
3922
|
value: licenseContextValue,
|
|
3903
3923
|
children: [
|
|
3904
|
-
|
|
3905
|
-
|
|
3924
|
+
a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
3925
|
+
a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
3906
3926
|
catalog: a2ui?.catalog,
|
|
3907
3927
|
includeSchema: a2ui?.includeSchema
|
|
3908
3928
|
}),
|
|
@@ -3980,16 +4000,20 @@ function useRenderActivityMessage() {
|
|
|
3980
4000
|
const renderActivityMessage = (0, react.useCallback)((message) => {
|
|
3981
4001
|
const renderer = findRenderer(message.activityType);
|
|
3982
4002
|
if (!renderer) return null;
|
|
3983
|
-
const parseResult = renderer.content.
|
|
3984
|
-
if (
|
|
3985
|
-
console.warn(`
|
|
4003
|
+
const parseResult = renderer.content["~standard"].validate(message.content);
|
|
4004
|
+
if (parseResult instanceof Promise) {
|
|
4005
|
+
console.warn(`Async content validation is not supported for activity message '${message.activityType}'`);
|
|
4006
|
+
return null;
|
|
4007
|
+
}
|
|
4008
|
+
if (parseResult.issues) {
|
|
4009
|
+
console.warn(`Failed to parse content for activity message '${message.activityType}':`, parseResult.issues);
|
|
3986
4010
|
return null;
|
|
3987
4011
|
}
|
|
3988
4012
|
const Component = renderer.render;
|
|
3989
4013
|
const agent = copilotkit.getAgent(agentId);
|
|
3990
4014
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
3991
4015
|
activityType: message.activityType,
|
|
3992
|
-
content: parseResult.
|
|
4016
|
+
content: parseResult.value,
|
|
3993
4017
|
message,
|
|
3994
4018
|
agent
|
|
3995
4019
|
}, message.id);
|
|
@@ -4225,7 +4249,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4225
4249
|
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
4226
4250
|
const cached = provisionalAgentCache.current.get(agentId);
|
|
4227
4251
|
if (cached) {
|
|
4228
|
-
|
|
4252
|
+
copilotkit.applyHeadersToAgent(cached);
|
|
4229
4253
|
return cached;
|
|
4230
4254
|
}
|
|
4231
4255
|
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
@@ -4234,14 +4258,14 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4234
4258
|
transport: copilotkit.runtimeTransport,
|
|
4235
4259
|
runtimeMode: "pending"
|
|
4236
4260
|
});
|
|
4237
|
-
|
|
4261
|
+
copilotkit.applyHeadersToAgent(provisional);
|
|
4238
4262
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
4239
4263
|
return provisional;
|
|
4240
4264
|
}
|
|
4241
4265
|
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
4242
4266
|
const cached = provisionalAgentCache.current.get(agentId);
|
|
4243
4267
|
if (cached) {
|
|
4244
|
-
|
|
4268
|
+
copilotkit.applyHeadersToAgent(cached);
|
|
4245
4269
|
return cached;
|
|
4246
4270
|
}
|
|
4247
4271
|
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
@@ -4250,7 +4274,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4250
4274
|
transport: copilotkit.runtimeTransport,
|
|
4251
4275
|
runtimeMode: "pending"
|
|
4252
4276
|
});
|
|
4253
|
-
|
|
4277
|
+
copilotkit.applyHeadersToAgent(provisional);
|
|
4254
4278
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
4255
4279
|
return provisional;
|
|
4256
4280
|
}
|
|
@@ -4301,7 +4325,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4301
4325
|
updateFlags
|
|
4302
4326
|
]);
|
|
4303
4327
|
(0, react.useEffect)(() => {
|
|
4304
|
-
if (agent instanceof _ag_ui_client.HttpAgent)
|
|
4328
|
+
if (agent instanceof _ag_ui_client.HttpAgent) copilotkit.applyHeadersToAgent(agent);
|
|
4305
4329
|
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
4306
4330
|
const chatConfig = useCopilotChatConfiguration();
|
|
4307
4331
|
const configThreadId = chatConfig?.threadId;
|
|
@@ -4578,114 +4602,165 @@ const INTERRUPT_EVENT_NAME = "on_interrupt";
|
|
|
4578
4602
|
function isPromiseLike(value) {
|
|
4579
4603
|
return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
|
|
4580
4604
|
}
|
|
4605
|
+
/** Derive the legacy-compatible `event` for any pending interrupt. */
|
|
4606
|
+
function toLegacyEvent(pending) {
|
|
4607
|
+
if (pending.kind === "legacy") return pending.event;
|
|
4608
|
+
return {
|
|
4609
|
+
name: INTERRUPT_EVENT_NAME,
|
|
4610
|
+
value: pending.interrupts[0]
|
|
4611
|
+
};
|
|
4612
|
+
}
|
|
4581
4613
|
/**
|
|
4582
|
-
* Handles agent interrupts
|
|
4583
|
-
*
|
|
4584
|
-
* The hook listens to custom events on the active agent, stores interrupt payloads per run,
|
|
4585
|
-
* and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
|
|
4586
|
-
* execution with user-provided data.
|
|
4614
|
+
* Handles agent interrupts with optional filtering, preprocessing, and resume behavior.
|
|
4587
4615
|
*
|
|
4588
|
-
*
|
|
4589
|
-
*
|
|
4616
|
+
* Supports both the AG-UI standard interrupt flow (`RUN_FINISHED` with
|
|
4617
|
+
* `outcome.type === "interrupt"`) and the legacy custom-event flow
|
|
4618
|
+
* (`on_interrupt`). For standard interrupts, `render` receives `interrupt`
|
|
4619
|
+
* (the primary one) and `interrupts` (the full open set); call `resolve(payload)`
|
|
4620
|
+
* to resume or `cancel()` to cancel. Resuming addresses the targeted interrupt
|
|
4621
|
+
* and, once every open interrupt is addressed, submits a single spec `resume`
|
|
4622
|
+
* array via `copilotkit.runAgent`.
|
|
4590
4623
|
*
|
|
4591
|
-
* `
|
|
4592
|
-
*
|
|
4593
|
-
*
|
|
4594
|
-
* @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.
|
|
4595
|
-
* @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).
|
|
4596
|
-
* @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).
|
|
4597
|
-
* Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always
|
|
4598
|
-
* either the handler's resolved return value or `null` (including when no handler is provided,
|
|
4599
|
-
* when filtering skips the interrupt, or when handler execution fails).
|
|
4624
|
+
* - `renderInChat: true` (default): the element is published into `<CopilotChat>`; returns `void`.
|
|
4625
|
+
* - `renderInChat: false`: the hook returns the interrupt element for manual placement.
|
|
4600
4626
|
*
|
|
4601
4627
|
* @example
|
|
4602
4628
|
* ```tsx
|
|
4603
|
-
*
|
|
4604
|
-
*
|
|
4605
|
-
*
|
|
4606
|
-
*
|
|
4607
|
-
*
|
|
4608
|
-
* <
|
|
4609
|
-
*
|
|
4610
|
-
*
|
|
4611
|
-
*
|
|
4612
|
-
* </div>
|
|
4613
|
-
* ),
|
|
4614
|
-
* });
|
|
4615
|
-
*
|
|
4616
|
-
* return null;
|
|
4617
|
-
* }
|
|
4618
|
-
* ```
|
|
4619
|
-
*
|
|
4620
|
-
* @example
|
|
4621
|
-
* ```tsx
|
|
4622
|
-
* import { useInterrupt } from "@copilotkit/react-core/v2";
|
|
4623
|
-
*
|
|
4624
|
-
* function CustomPanel() {
|
|
4625
|
-
* const interruptElement = useInterrupt({
|
|
4626
|
-
* renderInChat: false,
|
|
4627
|
-
* enabled: (event) => event.value.startsWith("approval:"),
|
|
4628
|
-
* handler: async ({ event }) => ({ label: event.value.toUpperCase() }),
|
|
4629
|
-
* render: ({ event, result, resolve }) => (
|
|
4630
|
-
* <aside>
|
|
4631
|
-
* <strong>{result?.label ?? ""}</strong>
|
|
4632
|
-
* <button onClick={() => resolve({ value: event.value })}>Continue</button>
|
|
4633
|
-
* </aside>
|
|
4634
|
-
* ),
|
|
4635
|
-
* });
|
|
4636
|
-
*
|
|
4637
|
-
* return <>{interruptElement}</>;
|
|
4638
|
-
* }
|
|
4629
|
+
* useInterrupt({
|
|
4630
|
+
* render: ({ interrupt, resolve, cancel }) => (
|
|
4631
|
+
* <div>
|
|
4632
|
+
* <p>{interrupt?.message}</p>
|
|
4633
|
+
* <button onClick={() => resolve({ approved: true })}>Approve</button>
|
|
4634
|
+
* <button onClick={() => cancel()}>Cancel</button>
|
|
4635
|
+
* </div>
|
|
4636
|
+
* ),
|
|
4637
|
+
* });
|
|
4639
4638
|
* ```
|
|
4640
4639
|
*/
|
|
4641
4640
|
function useInterrupt(config) {
|
|
4642
4641
|
const { copilotkit } = useCopilotKit();
|
|
4643
4642
|
const { agent } = useAgent({ agentId: config.agentId });
|
|
4644
|
-
const [
|
|
4645
|
-
const
|
|
4646
|
-
|
|
4643
|
+
const [pending, setPending] = (0, react.useState)(null);
|
|
4644
|
+
const pendingRef = (0, react.useRef)(pending);
|
|
4645
|
+
pendingRef.current = pending;
|
|
4647
4646
|
const [handlerResult, setHandlerResult] = (0, react.useState)(null);
|
|
4647
|
+
const responsesRef = (0, react.useRef)({});
|
|
4648
4648
|
(0, react.useEffect)(() => {
|
|
4649
|
-
let
|
|
4649
|
+
let localLegacy = null;
|
|
4650
|
+
let localStandard = null;
|
|
4650
4651
|
const subscription = agent.subscribe({
|
|
4651
4652
|
onCustomEvent: ({ event }) => {
|
|
4652
|
-
if (event.name === INTERRUPT_EVENT_NAME)
|
|
4653
|
+
if (event.name === INTERRUPT_EVENT_NAME) localLegacy = {
|
|
4653
4654
|
name: event.name,
|
|
4654
4655
|
value: event.value
|
|
4655
4656
|
};
|
|
4656
4657
|
},
|
|
4658
|
+
onRunFinishedEvent: (params) => {
|
|
4659
|
+
if (params.outcome === "interrupt") localStandard = params.interrupts;
|
|
4660
|
+
},
|
|
4657
4661
|
onRunStartedEvent: () => {
|
|
4658
|
-
|
|
4659
|
-
|
|
4662
|
+
localLegacy = null;
|
|
4663
|
+
localStandard = null;
|
|
4664
|
+
responsesRef.current = {};
|
|
4665
|
+
setPending(null);
|
|
4660
4666
|
},
|
|
4661
4667
|
onRunFinalized: () => {
|
|
4662
|
-
if (
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
}
|
|
4668
|
+
if (localStandard && localStandard.length > 0) setPending({
|
|
4669
|
+
kind: "standard",
|
|
4670
|
+
interrupts: localStandard
|
|
4671
|
+
});
|
|
4672
|
+
else if (localLegacy) setPending({
|
|
4673
|
+
kind: "legacy",
|
|
4674
|
+
event: localLegacy
|
|
4675
|
+
});
|
|
4676
|
+
localLegacy = null;
|
|
4677
|
+
localStandard = null;
|
|
4666
4678
|
},
|
|
4667
4679
|
onRunFailed: () => {
|
|
4668
|
-
|
|
4669
|
-
|
|
4680
|
+
localLegacy = null;
|
|
4681
|
+
localStandard = null;
|
|
4682
|
+
responsesRef.current = {};
|
|
4683
|
+
setPending(null);
|
|
4670
4684
|
}
|
|
4671
4685
|
});
|
|
4672
4686
|
return () => subscription.unsubscribe();
|
|
4673
4687
|
}, [agent]);
|
|
4674
|
-
const
|
|
4688
|
+
const submitStandardIfComplete = (0, react.useCallback)(async (interrupts) => {
|
|
4689
|
+
if (!interrupts.every((i) => responsesRef.current[i.id])) return;
|
|
4690
|
+
const expired = interrupts.find((i) => (0, _ag_ui_client.isInterruptExpired)(i));
|
|
4691
|
+
if (expired) {
|
|
4692
|
+
console.error(`[CopilotKit] useInterrupt: interrupt ${expired.id} expired at ${expired.expiresAt}; not resuming.`);
|
|
4693
|
+
responsesRef.current = {};
|
|
4694
|
+
setPending(null);
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4697
|
+
const resume = (0, _ag_ui_client.buildResumeArray)(interrupts, responsesRef.current);
|
|
4698
|
+
for (const i of interrupts) {
|
|
4699
|
+
if (!i.toolCallId) continue;
|
|
4700
|
+
const response = responsesRef.current[i.id];
|
|
4701
|
+
const content = response.status === "cancelled" ? { status: "cancelled" } : response.payload ?? { status: "resolved" };
|
|
4702
|
+
agent.addMessage({
|
|
4703
|
+
id: (0, _ag_ui_client.randomUUID)(),
|
|
4704
|
+
role: "tool",
|
|
4705
|
+
toolCallId: i.toolCallId,
|
|
4706
|
+
content: JSON.stringify(content)
|
|
4707
|
+
});
|
|
4708
|
+
}
|
|
4709
|
+
responsesRef.current = {};
|
|
4675
4710
|
try {
|
|
4711
|
+
return await copilotkit.runAgent({
|
|
4712
|
+
agent,
|
|
4713
|
+
resume
|
|
4714
|
+
});
|
|
4715
|
+
} catch (err) {
|
|
4716
|
+
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
4717
|
+
setPending(null);
|
|
4718
|
+
throw err;
|
|
4719
|
+
}
|
|
4720
|
+
}, [agent, copilotkit]);
|
|
4721
|
+
const resolve = (0, react.useCallback)(async (payload, interruptId) => {
|
|
4722
|
+
const current = pendingRef.current;
|
|
4723
|
+
if (!current) return;
|
|
4724
|
+
if (current.kind === "legacy") try {
|
|
4676
4725
|
return await copilotkit.runAgent({
|
|
4677
4726
|
agent,
|
|
4678
4727
|
forwardedProps: { command: {
|
|
4679
|
-
resume:
|
|
4680
|
-
interruptEvent:
|
|
4728
|
+
resume: payload,
|
|
4729
|
+
interruptEvent: current.event.value
|
|
4681
4730
|
} }
|
|
4682
4731
|
});
|
|
4683
4732
|
} catch (err) {
|
|
4684
4733
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
4685
|
-
|
|
4734
|
+
setPending(null);
|
|
4686
4735
|
throw err;
|
|
4687
4736
|
}
|
|
4688
|
-
|
|
4737
|
+
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.`);
|
|
4738
|
+
const id = interruptId ?? current.interrupts[0]?.id;
|
|
4739
|
+
if (!id) return;
|
|
4740
|
+
responsesRef.current[id] = {
|
|
4741
|
+
status: "resolved",
|
|
4742
|
+
payload
|
|
4743
|
+
};
|
|
4744
|
+
return submitStandardIfComplete(current.interrupts);
|
|
4745
|
+
}, [
|
|
4746
|
+
agent,
|
|
4747
|
+
copilotkit,
|
|
4748
|
+
submitStandardIfComplete
|
|
4749
|
+
]);
|
|
4750
|
+
const cancel = (0, react.useCallback)(async (interruptId) => {
|
|
4751
|
+
const current = pendingRef.current;
|
|
4752
|
+
if (!current) return;
|
|
4753
|
+
if (current.kind === "legacy") {
|
|
4754
|
+
console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
|
|
4755
|
+
setPending(null);
|
|
4756
|
+
return;
|
|
4757
|
+
}
|
|
4758
|
+
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.`);
|
|
4759
|
+
const id = interruptId ?? current.interrupts[0]?.id;
|
|
4760
|
+
if (!id) return;
|
|
4761
|
+
responsesRef.current[id] = { status: "cancelled" };
|
|
4762
|
+
return submitStandardIfComplete(current.interrupts);
|
|
4763
|
+
}, [submitStandardIfComplete]);
|
|
4689
4764
|
const renderRef = (0, react.useRef)(config.render);
|
|
4690
4765
|
renderRef.current = config.render;
|
|
4691
4766
|
const enabledRef = (0, react.useRef)(config.enabled);
|
|
@@ -4694,6 +4769,8 @@ function useInterrupt(config) {
|
|
|
4694
4769
|
handlerRef.current = config.handler;
|
|
4695
4770
|
const resolveRef = (0, react.useRef)(resolve);
|
|
4696
4771
|
resolveRef.current = resolve;
|
|
4772
|
+
const cancelRef = (0, react.useRef)(cancel);
|
|
4773
|
+
cancelRef.current = cancel;
|
|
4697
4774
|
const isEnabled = (event) => {
|
|
4698
4775
|
const predicate = enabledRef.current;
|
|
4699
4776
|
if (!predicate) return true;
|
|
@@ -4705,11 +4782,12 @@ function useInterrupt(config) {
|
|
|
4705
4782
|
}
|
|
4706
4783
|
};
|
|
4707
4784
|
(0, react.useEffect)(() => {
|
|
4708
|
-
if (!
|
|
4785
|
+
if (!pending) {
|
|
4709
4786
|
setHandlerResult(null);
|
|
4710
4787
|
return;
|
|
4711
4788
|
}
|
|
4712
|
-
|
|
4789
|
+
const legacyEvent = toLegacyEvent(pending);
|
|
4790
|
+
if (!isEnabled(legacyEvent)) {
|
|
4713
4791
|
setHandlerResult(null);
|
|
4714
4792
|
return;
|
|
4715
4793
|
}
|
|
@@ -4722,8 +4800,11 @@ function useInterrupt(config) {
|
|
|
4722
4800
|
let maybePromise;
|
|
4723
4801
|
try {
|
|
4724
4802
|
maybePromise = handler({
|
|
4725
|
-
event:
|
|
4726
|
-
|
|
4803
|
+
event: legacyEvent,
|
|
4804
|
+
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
4805
|
+
interrupts: pending.kind === "standard" ? pending.interrupts : [],
|
|
4806
|
+
resolve: resolveRef.current,
|
|
4807
|
+
cancel: cancelRef.current
|
|
4727
4808
|
});
|
|
4728
4809
|
} catch (err) {
|
|
4729
4810
|
console.error("[CopilotKit] useInterrupt handler threw; result will be null:", err);
|
|
@@ -4742,19 +4823,24 @@ function useInterrupt(config) {
|
|
|
4742
4823
|
return () => {
|
|
4743
4824
|
cancelled = true;
|
|
4744
4825
|
};
|
|
4745
|
-
}, [
|
|
4826
|
+
}, [pending]);
|
|
4746
4827
|
const element = (0, react.useMemo)(() => {
|
|
4747
|
-
if (!
|
|
4748
|
-
|
|
4828
|
+
if (!pending) return null;
|
|
4829
|
+
const legacyEvent = toLegacyEvent(pending);
|
|
4830
|
+
if (!isEnabled(legacyEvent)) return null;
|
|
4749
4831
|
return renderRef.current({
|
|
4750
|
-
event:
|
|
4832
|
+
event: legacyEvent,
|
|
4833
|
+
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
4834
|
+
interrupts: pending.kind === "standard" ? pending.interrupts : [],
|
|
4751
4835
|
result: handlerResult,
|
|
4752
|
-
resolve
|
|
4836
|
+
resolve,
|
|
4837
|
+
cancel
|
|
4753
4838
|
});
|
|
4754
4839
|
}, [
|
|
4755
|
-
|
|
4840
|
+
pending,
|
|
4756
4841
|
handlerResult,
|
|
4757
|
-
resolve
|
|
4842
|
+
resolve,
|
|
4843
|
+
cancel
|
|
4758
4844
|
]);
|
|
4759
4845
|
(0, react.useEffect)(() => {
|
|
4760
4846
|
if (config.renderInChat === false) return;
|
|
@@ -4790,9 +4876,9 @@ function useThreadStoreSelector(store, selector) {
|
|
|
4790
4876
|
* current without polling — thread creates, renames, archives, and deletes
|
|
4791
4877
|
* from any client are reflected immediately.
|
|
4792
4878
|
*
|
|
4793
|
-
* Mutation methods (`renameThread`, `archiveThread`, `
|
|
4794
|
-
* promises that resolve once the platform confirms the
|
|
4795
|
-
* with an `Error` on failure.
|
|
4879
|
+
* Mutation methods (`renameThread`, `archiveThread`, `unarchiveThread`,
|
|
4880
|
+
* `deleteThread`) return promises that resolve once the platform confirms the
|
|
4881
|
+
* operation and reject with an `Error` on failure.
|
|
4796
4882
|
*
|
|
4797
4883
|
* @param input - Agent identifier and optional list controls.
|
|
4798
4884
|
* @returns Thread list state and stable mutation callbacks.
|
|
@@ -4919,6 +5005,7 @@ function useThreads$1({ agentId, includeArchived, limit }) {
|
|
|
4919
5005
|
}, [threadMutationsError]);
|
|
4920
5006
|
const renameThread = (0, react.useMemo)(() => guardMutation((threadId, name) => store.renameThread(threadId, name)), [store, guardMutation]);
|
|
4921
5007
|
const archiveThread = (0, react.useMemo)(() => guardMutation((threadId) => store.archiveThread(threadId)), [store, guardMutation]);
|
|
5008
|
+
const unarchiveThread = (0, react.useMemo)(() => guardMutation((threadId) => store.unarchiveThread(threadId)), [store, guardMutation]);
|
|
4922
5009
|
const deleteThread = (0, react.useMemo)(() => guardMutation((threadId) => store.deleteThread(threadId)), [store, guardMutation]);
|
|
4923
5010
|
return {
|
|
4924
5011
|
threads,
|
|
@@ -4929,6 +5016,7 @@ function useThreads$1({ agentId, includeArchived, limit }) {
|
|
|
4929
5016
|
fetchMoreThreads: (0, react.useCallback)(() => store.fetchNextPage(), [store]),
|
|
4930
5017
|
renameThread,
|
|
4931
5018
|
archiveThread,
|
|
5019
|
+
unarchiveThread,
|
|
4932
5020
|
deleteThread
|
|
4933
5021
|
};
|
|
4934
5022
|
}
|
|
@@ -7726,8 +7814,10 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
7726
7814
|
hasExplicitThreadId
|
|
7727
7815
|
]);
|
|
7728
7816
|
const waitForActiveRunToSettle = (0, react.useCallback)(async () => {
|
|
7729
|
-
|
|
7730
|
-
|
|
7817
|
+
const maybeAware = agent;
|
|
7818
|
+
const activeRunCompletionPromise = (0, _copilotkit_core.isRunCompletionAware)(maybeAware) ? maybeAware.activeRunCompletionPromise : void 0;
|
|
7819
|
+
if (agent.isRunning && activeRunCompletionPromise) try {
|
|
7820
|
+
await activeRunCompletionPromise;
|
|
7731
7821
|
} catch (error) {
|
|
7732
7822
|
console.error("CopilotChat: in-flight run rejected while queuing send", error);
|
|
7733
7823
|
}
|
|
@@ -10166,6 +10256,7 @@ function CopilotKit({ children, ...props }) {
|
|
|
10166
10256
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
10167
10257
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
10168
10258
|
const renderArr = (0, react.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
10259
|
+
const { onError: _onError, ...v2Props } = props;
|
|
10169
10260
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToastProvider, {
|
|
10170
10261
|
enabled,
|
|
10171
10262
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotErrorBoundary, {
|
|
@@ -10174,7 +10265,7 @@ function CopilotKit({ children, ...props }) {
|
|
|
10174
10265
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ThreadsProvider, {
|
|
10175
10266
|
threadId: props.threadId,
|
|
10176
10267
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitProvider, {
|
|
10177
|
-
...
|
|
10268
|
+
...v2Props,
|
|
10178
10269
|
showDevConsole: showInspector,
|
|
10179
10270
|
renderCustomMessages: renderArr,
|
|
10180
10271
|
useSingleEndpoint: props.useSingleEndpoint ?? true,
|
|
@@ -11126,4 +11217,4 @@ Object.defineProperty(exports, 'useToast', {
|
|
|
11126
11217
|
return useToast;
|
|
11127
11218
|
}
|
|
11128
11219
|
});
|
|
11129
|
-
//# sourceMappingURL=copilotkit-
|
|
11220
|
+
//# sourceMappingURL=copilotkit-CTCjVxkH.cjs.map
|