@copilotkitnext/react 1.52.0-next.6 → 1.52.0-next.7
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/components/chat/CopilotChatMessageView.cjs +18 -5
- package/dist/components/chat/CopilotChatMessageView.cjs.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.d.cts +1 -0
- package/dist/components/chat/CopilotChatMessageView.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.d.mts +1 -0
- package/dist/components/chat/CopilotChatMessageView.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.mjs +19 -6
- package/dist/components/chat/CopilotChatMessageView.mjs.map +1 -1
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.d.cts +2 -1
- package/dist/hooks/index.d.mts +2 -1
- package/dist/hooks/index.mjs +1 -0
- package/dist/hooks/use-interrupt.cjs +171 -0
- package/dist/hooks/use-interrupt.cjs.map +1 -0
- package/dist/hooks/use-interrupt.d.cts +102 -0
- package/dist/hooks/use-interrupt.d.cts.map +1 -0
- package/dist/hooks/use-interrupt.d.mts +102 -0
- package/dist/hooks/use-interrupt.d.mts.map +1 -0
- package/dist/hooks/use-interrupt.mjs +170 -0
- package/dist/hooks/use-interrupt.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +2 -1
- package/dist/index.umd.js +198 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/react-core.cjs +13 -0
- package/dist/lib/react-core.cjs.map +1 -1
- package/dist/lib/react-core.d.cts +8 -0
- package/dist/lib/react-core.d.cts.map +1 -1
- package/dist/lib/react-core.d.mts +8 -0
- package/dist/lib/react-core.d.mts.map +1 -1
- package/dist/lib/react-core.mjs +13 -0
- package/dist/lib/react-core.mjs.map +1 -1
- package/dist/types/index.d.cts +2 -1
- package/dist/types/index.d.mts +2 -1
- package/dist/types/interrupt.d.cts +17 -0
- package/dist/types/interrupt.d.cts.map +1 -0
- package/dist/types/interrupt.d.mts +17 -0
- package/dist/types/interrupt.d.mts.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { InterruptEvent, InterruptHandlerProps, InterruptRenderProps } from "../types/interrupt.cjs";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-interrupt.d.ts
|
|
5
|
+
type InterruptHandlerFn<TValue, TResult> = (props: InterruptHandlerProps<TValue>) => TResult | PromiseLike<TResult>;
|
|
6
|
+
type InterruptResultFromHandler<THandler> = THandler extends ((...args: never[]) => infer TResult) ? TResult extends PromiseLike<infer TResolved> ? TResolved | null : TResult | null : null;
|
|
7
|
+
type InterruptResult<TValue, TResult> = InterruptResultFromHandler<InterruptHandlerFn<TValue, TResult>>;
|
|
8
|
+
type InterruptRenderInChat = boolean | undefined;
|
|
9
|
+
type UseInterruptReturn<TRenderInChat extends InterruptRenderInChat> = TRenderInChat extends false ? React.ReactElement | null : TRenderInChat extends true | undefined ? void : React.ReactElement | null | void;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for `useInterrupt`.
|
|
12
|
+
*/
|
|
13
|
+
interface UseInterruptConfigBase<TValue = unknown, TResult = never> {
|
|
14
|
+
/**
|
|
15
|
+
* Render function for the interrupt UI.
|
|
16
|
+
*
|
|
17
|
+
* This is called once an interrupt is finalized and accepted by `enabled` (if provided).
|
|
18
|
+
* Use `resolve` from render props to resume the agent run with user input.
|
|
19
|
+
*/
|
|
20
|
+
render: (props: InterruptRenderProps<TValue, InterruptResult<TValue, TResult>>) => React.ReactElement;
|
|
21
|
+
/**
|
|
22
|
+
* Optional pre-render handler invoked when an interrupt is received.
|
|
23
|
+
*
|
|
24
|
+
* Return either a sync value or an async value to pass into `render` as `result`.
|
|
25
|
+
* Rejecting/throwing falls back to `result = null`.
|
|
26
|
+
*/
|
|
27
|
+
handler?: InterruptHandlerFn<TValue, TResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Optional predicate to filter which interrupts should be handled by this hook.
|
|
30
|
+
* Return `false` to ignore an interrupt.
|
|
31
|
+
*/
|
|
32
|
+
enabled?: (event: InterruptEvent<TValue>) => boolean;
|
|
33
|
+
/** Optional agent id. Defaults to the current configured chat agent. */
|
|
34
|
+
agentId?: string;
|
|
35
|
+
}
|
|
36
|
+
type UseInterruptConfig<TValue = unknown, TResult = never, TRenderInChat extends InterruptRenderInChat = undefined> = UseInterruptConfigBase<TValue, TResult> & {
|
|
37
|
+
/** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */renderInChat?: TRenderInChat;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Handles agent interrupts (`on_interrupt`) with optional filtering, preprocessing, and resume behavior.
|
|
41
|
+
*
|
|
42
|
+
* The hook listens to custom events on the active agent, stores interrupt payloads per run,
|
|
43
|
+
* and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
|
|
44
|
+
* execution with user-provided data.
|
|
45
|
+
*
|
|
46
|
+
* - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.
|
|
47
|
+
* - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.
|
|
48
|
+
*
|
|
49
|
+
* `event.value` is typed as `any` since the interrupt payload shape depends on your agent.
|
|
50
|
+
* Type-narrow it in your callbacks (e.g. `handler`, `enabled`, `render`) as needed.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.
|
|
53
|
+
* @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).
|
|
54
|
+
* @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).
|
|
55
|
+
* Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always
|
|
56
|
+
* either the handler's resolved return value or `null` (including when no handler is provided,
|
|
57
|
+
* when filtering skips the interrupt, or when handler execution fails).
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* import { useInterrupt } from "@copilotkitnext/react";
|
|
62
|
+
*
|
|
63
|
+
* function InterruptUI() {
|
|
64
|
+
* useInterrupt({
|
|
65
|
+
* render: ({ event, resolve }) => (
|
|
66
|
+
* <div>
|
|
67
|
+
* <p>{event.value.question}</p>
|
|
68
|
+
* <button onClick={() => resolve({ approved: true })}>Approve</button>
|
|
69
|
+
* <button onClick={() => resolve({ approved: false })}>Reject</button>
|
|
70
|
+
* </div>
|
|
71
|
+
* ),
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* return null;
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* import { useInterrupt } from "@copilotkitnext/react";
|
|
81
|
+
*
|
|
82
|
+
* function CustomPanel() {
|
|
83
|
+
* const interruptElement = useInterrupt({
|
|
84
|
+
* renderInChat: false,
|
|
85
|
+
* enabled: (event) => event.value.startsWith("approval:"),
|
|
86
|
+
* handler: async ({ event }) => ({ label: event.value.toUpperCase() }),
|
|
87
|
+
* render: ({ event, result, resolve }) => (
|
|
88
|
+
* <aside>
|
|
89
|
+
* <strong>{result?.label ?? ""}</strong>
|
|
90
|
+
* <button onClick={() => resolve({ value: event.value })}>Continue</button>
|
|
91
|
+
* </aside>
|
|
92
|
+
* ),
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* return <>{interruptElement}</>;
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function useInterrupt<TResult = never, TRenderInChat extends InterruptRenderInChat = undefined>(config: UseInterruptConfig<any, TResult, TRenderInChat>): UseInterruptReturn<TRenderInChat>;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { UseInterruptConfig, useInterrupt };
|
|
102
|
+
//# sourceMappingURL=use-interrupt.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-interrupt.d.cts","names":[],"sources":["../../src/hooks/use-interrupt.tsx"],"mappings":";;;;KAaK,kBAAA,qBACH,KAAA,EAAO,qBAAA,CAAsB,MAAA,MAC1B,OAAA,GAAU,WAAA,CAAY,OAAA;AAAA,KAEtB,0BAAA,aAAuC,QAAA,cACvC,IAAA,+BAED,OAAA,SAAgB,WAAA,oBACd,SAAA,UACA,OAAA;AAAA,KAGD,eAAA,oBAAmC,0BAAA,CACtC,kBAAA,CAAmB,MAAA,EAAQ,OAAA;AAAA,KAGxB,qBAAA;AAAA,KAEA,kBAAA,uBAAyC,qBAAA,IAC5C,aAAA,iBACI,KAAA,CAAM,YAAA,UACN,aAAA,mCAEE,KAAA,CAAM,YAAA;;;;UAeJ,sBAAA;EApCgB;;;;;;EA2CxB,MAAA,GACE,KAAA,EAAO,oBAAA,CAAqB,MAAA,EAAQ,eAAA,CAAgB,MAAA,EAAQ,OAAA,OACzD,KAAA,CAAM,YAAA;EA7CE;;;;AAAmB;;EAoDhC,OAAA,GAAU,kBAAA,CAAmB,MAAA,EAAQ,OAAA;EAlDK;;;;EAuD1C,OAAA,IAAW,KAAA,EAAO,cAAA,CAAe,MAAA;EAlDtB;EAoDX,OAAA;AAAA;AAAA,KA2BU,kBAAA,0DAGY,qBAAA,gBACpB,sBAAA,CAAuB,MAAA,EAAQ,OAAA;EA/EN,8HAiF3B,YAAA,GAAe,aAAA;AAAA;;;;;;;;;;;AAjFmB;;;;;AAGV;;;;;;;;;;;;;;;;;;;;AAiBzB;;;;;;;;;;;;;;;;;;;;;;;;;iBA6He,YAAA,wCAEQ,qBAAA,aAAA,CAEtB,MAAA,EAAQ,kBAAA,MAAwB,OAAA,EAAS,aAAA,IACxC,kBAAA,CAAmB,aAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { InterruptEvent, InterruptHandlerProps, InterruptRenderProps } from "../types/interrupt.mjs";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-interrupt.d.ts
|
|
5
|
+
type InterruptHandlerFn<TValue, TResult> = (props: InterruptHandlerProps<TValue>) => TResult | PromiseLike<TResult>;
|
|
6
|
+
type InterruptResultFromHandler<THandler> = THandler extends ((...args: never[]) => infer TResult) ? TResult extends PromiseLike<infer TResolved> ? TResolved | null : TResult | null : null;
|
|
7
|
+
type InterruptResult<TValue, TResult> = InterruptResultFromHandler<InterruptHandlerFn<TValue, TResult>>;
|
|
8
|
+
type InterruptRenderInChat = boolean | undefined;
|
|
9
|
+
type UseInterruptReturn<TRenderInChat extends InterruptRenderInChat> = TRenderInChat extends false ? React.ReactElement | null : TRenderInChat extends true | undefined ? void : React.ReactElement | null | void;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for `useInterrupt`.
|
|
12
|
+
*/
|
|
13
|
+
interface UseInterruptConfigBase<TValue = unknown, TResult = never> {
|
|
14
|
+
/**
|
|
15
|
+
* Render function for the interrupt UI.
|
|
16
|
+
*
|
|
17
|
+
* This is called once an interrupt is finalized and accepted by `enabled` (if provided).
|
|
18
|
+
* Use `resolve` from render props to resume the agent run with user input.
|
|
19
|
+
*/
|
|
20
|
+
render: (props: InterruptRenderProps<TValue, InterruptResult<TValue, TResult>>) => React.ReactElement;
|
|
21
|
+
/**
|
|
22
|
+
* Optional pre-render handler invoked when an interrupt is received.
|
|
23
|
+
*
|
|
24
|
+
* Return either a sync value or an async value to pass into `render` as `result`.
|
|
25
|
+
* Rejecting/throwing falls back to `result = null`.
|
|
26
|
+
*/
|
|
27
|
+
handler?: InterruptHandlerFn<TValue, TResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Optional predicate to filter which interrupts should be handled by this hook.
|
|
30
|
+
* Return `false` to ignore an interrupt.
|
|
31
|
+
*/
|
|
32
|
+
enabled?: (event: InterruptEvent<TValue>) => boolean;
|
|
33
|
+
/** Optional agent id. Defaults to the current configured chat agent. */
|
|
34
|
+
agentId?: string;
|
|
35
|
+
}
|
|
36
|
+
type UseInterruptConfig<TValue = unknown, TResult = never, TRenderInChat extends InterruptRenderInChat = undefined> = UseInterruptConfigBase<TValue, TResult> & {
|
|
37
|
+
/** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */renderInChat?: TRenderInChat;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Handles agent interrupts (`on_interrupt`) with optional filtering, preprocessing, and resume behavior.
|
|
41
|
+
*
|
|
42
|
+
* The hook listens to custom events on the active agent, stores interrupt payloads per run,
|
|
43
|
+
* and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
|
|
44
|
+
* execution with user-provided data.
|
|
45
|
+
*
|
|
46
|
+
* - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.
|
|
47
|
+
* - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.
|
|
48
|
+
*
|
|
49
|
+
* `event.value` is typed as `any` since the interrupt payload shape depends on your agent.
|
|
50
|
+
* Type-narrow it in your callbacks (e.g. `handler`, `enabled`, `render`) as needed.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.
|
|
53
|
+
* @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).
|
|
54
|
+
* @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).
|
|
55
|
+
* Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always
|
|
56
|
+
* either the handler's resolved return value or `null` (including when no handler is provided,
|
|
57
|
+
* when filtering skips the interrupt, or when handler execution fails).
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* import { useInterrupt } from "@copilotkitnext/react";
|
|
62
|
+
*
|
|
63
|
+
* function InterruptUI() {
|
|
64
|
+
* useInterrupt({
|
|
65
|
+
* render: ({ event, resolve }) => (
|
|
66
|
+
* <div>
|
|
67
|
+
* <p>{event.value.question}</p>
|
|
68
|
+
* <button onClick={() => resolve({ approved: true })}>Approve</button>
|
|
69
|
+
* <button onClick={() => resolve({ approved: false })}>Reject</button>
|
|
70
|
+
* </div>
|
|
71
|
+
* ),
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* return null;
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* import { useInterrupt } from "@copilotkitnext/react";
|
|
81
|
+
*
|
|
82
|
+
* function CustomPanel() {
|
|
83
|
+
* const interruptElement = useInterrupt({
|
|
84
|
+
* renderInChat: false,
|
|
85
|
+
* enabled: (event) => event.value.startsWith("approval:"),
|
|
86
|
+
* handler: async ({ event }) => ({ label: event.value.toUpperCase() }),
|
|
87
|
+
* render: ({ event, result, resolve }) => (
|
|
88
|
+
* <aside>
|
|
89
|
+
* <strong>{result?.label ?? ""}</strong>
|
|
90
|
+
* <button onClick={() => resolve({ value: event.value })}>Continue</button>
|
|
91
|
+
* </aside>
|
|
92
|
+
* ),
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* return <>{interruptElement}</>;
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function useInterrupt<TResult = never, TRenderInChat extends InterruptRenderInChat = undefined>(config: UseInterruptConfig<any, TResult, TRenderInChat>): UseInterruptReturn<TRenderInChat>;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { UseInterruptConfig, useInterrupt };
|
|
102
|
+
//# sourceMappingURL=use-interrupt.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-interrupt.d.mts","names":[],"sources":["../../src/hooks/use-interrupt.tsx"],"mappings":";;;;KAaK,kBAAA,qBACH,KAAA,EAAO,qBAAA,CAAsB,MAAA,MAC1B,OAAA,GAAU,WAAA,CAAY,OAAA;AAAA,KAEtB,0BAAA,aAAuC,QAAA,cACvC,IAAA,+BAED,OAAA,SAAgB,WAAA,oBACd,SAAA,UACA,OAAA;AAAA,KAGD,eAAA,oBAAmC,0BAAA,CACtC,kBAAA,CAAmB,MAAA,EAAQ,OAAA;AAAA,KAGxB,qBAAA;AAAA,KAEA,kBAAA,uBAAyC,qBAAA,IAC5C,aAAA,iBACI,KAAA,CAAM,YAAA,UACN,aAAA,mCAEE,KAAA,CAAM,YAAA;;;;UAeJ,sBAAA;EApCgB;;;;;;EA2CxB,MAAA,GACE,KAAA,EAAO,oBAAA,CAAqB,MAAA,EAAQ,eAAA,CAAgB,MAAA,EAAQ,OAAA,OACzD,KAAA,CAAM,YAAA;EA7CE;;;;AAAmB;;EAoDhC,OAAA,GAAU,kBAAA,CAAmB,MAAA,EAAQ,OAAA;EAlDK;;;;EAuD1C,OAAA,IAAW,KAAA,EAAO,cAAA,CAAe,MAAA;EAlDtB;EAoDX,OAAA;AAAA;AAAA,KA2BU,kBAAA,0DAGY,qBAAA,gBACpB,sBAAA,CAAuB,MAAA,EAAQ,OAAA;EA/EN,8HAiF3B,YAAA,GAAe,aAAA;AAAA;;;;;;;;;;;AAjFmB;;;;;AAGV;;;;;;;;;;;;;;;;;;;;AAiBzB;;;;;;;;;;;;;;;;;;;;;;;;;iBA6He,YAAA,wCAEQ,qBAAA,aAAA,CAEtB,MAAA,EAAQ,kBAAA,MAAwB,OAAA,EAAS,aAAA,IACxC,kBAAA,CAAmB,aAAA"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { useCopilotKit } from "../providers/CopilotKitProvider.mjs";
|
|
2
|
+
import { useAgent } from "./use-agent.mjs";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/use-interrupt.tsx
|
|
6
|
+
const INTERRUPT_EVENT_NAME = "on_interrupt";
|
|
7
|
+
function isPromiseLike(value) {
|
|
8
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Handles agent interrupts (`on_interrupt`) with optional filtering, preprocessing, and resume behavior.
|
|
12
|
+
*
|
|
13
|
+
* The hook listens to custom events on the active agent, stores interrupt payloads per run,
|
|
14
|
+
* and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
|
|
15
|
+
* execution with user-provided data.
|
|
16
|
+
*
|
|
17
|
+
* - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.
|
|
18
|
+
* - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.
|
|
19
|
+
*
|
|
20
|
+
* `event.value` is typed as `any` since the interrupt payload shape depends on your agent.
|
|
21
|
+
* Type-narrow it in your callbacks (e.g. `handler`, `enabled`, `render`) as needed.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.
|
|
24
|
+
* @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).
|
|
25
|
+
* @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).
|
|
26
|
+
* Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always
|
|
27
|
+
* either the handler's resolved return value or `null` (including when no handler is provided,
|
|
28
|
+
* when filtering skips the interrupt, or when handler execution fails).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { useInterrupt } from "@copilotkitnext/react";
|
|
33
|
+
*
|
|
34
|
+
* function InterruptUI() {
|
|
35
|
+
* useInterrupt({
|
|
36
|
+
* render: ({ event, resolve }) => (
|
|
37
|
+
* <div>
|
|
38
|
+
* <p>{event.value.question}</p>
|
|
39
|
+
* <button onClick={() => resolve({ approved: true })}>Approve</button>
|
|
40
|
+
* <button onClick={() => resolve({ approved: false })}>Reject</button>
|
|
41
|
+
* </div>
|
|
42
|
+
* ),
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* return null;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* import { useInterrupt } from "@copilotkitnext/react";
|
|
52
|
+
*
|
|
53
|
+
* function CustomPanel() {
|
|
54
|
+
* const interruptElement = useInterrupt({
|
|
55
|
+
* renderInChat: false,
|
|
56
|
+
* enabled: (event) => event.value.startsWith("approval:"),
|
|
57
|
+
* handler: async ({ event }) => ({ label: event.value.toUpperCase() }),
|
|
58
|
+
* render: ({ event, result, resolve }) => (
|
|
59
|
+
* <aside>
|
|
60
|
+
* <strong>{result?.label ?? ""}</strong>
|
|
61
|
+
* <button onClick={() => resolve({ value: event.value })}>Continue</button>
|
|
62
|
+
* </aside>
|
|
63
|
+
* ),
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* return <>{interruptElement}</>;
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function useInterrupt(config) {
|
|
71
|
+
const { copilotkit } = useCopilotKit();
|
|
72
|
+
const { agent } = useAgent({ agentId: config.agentId });
|
|
73
|
+
const [pendingEvent, setPendingEvent] = useState(null);
|
|
74
|
+
const [handlerResult, setHandlerResult] = useState(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
let localInterrupt = null;
|
|
77
|
+
const subscription = agent.subscribe({
|
|
78
|
+
onCustomEvent: ({ event }) => {
|
|
79
|
+
if (event.name === INTERRUPT_EVENT_NAME) localInterrupt = {
|
|
80
|
+
name: event.name,
|
|
81
|
+
value: event.value
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
onRunStartedEvent: () => {
|
|
85
|
+
localInterrupt = null;
|
|
86
|
+
setPendingEvent(null);
|
|
87
|
+
},
|
|
88
|
+
onRunFinalized: () => {
|
|
89
|
+
if (localInterrupt) {
|
|
90
|
+
setPendingEvent(localInterrupt);
|
|
91
|
+
localInterrupt = null;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
onRunFailed: () => {
|
|
95
|
+
localInterrupt = null;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return () => subscription.unsubscribe();
|
|
99
|
+
}, [agent]);
|
|
100
|
+
const resolve = useCallback((response) => {
|
|
101
|
+
setPendingEvent(null);
|
|
102
|
+
copilotkit.runAgent({
|
|
103
|
+
agent,
|
|
104
|
+
forwardedProps: { command: { resume: response } }
|
|
105
|
+
});
|
|
106
|
+
}, [agent, copilotkit]);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!pendingEvent) {
|
|
109
|
+
setHandlerResult(null);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (config.enabled && !config.enabled(pendingEvent)) {
|
|
113
|
+
setHandlerResult(null);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const handler = config.handler;
|
|
117
|
+
if (!handler) {
|
|
118
|
+
setHandlerResult(null);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let cancelled = false;
|
|
122
|
+
const maybePromise = handler({
|
|
123
|
+
event: pendingEvent,
|
|
124
|
+
resolve
|
|
125
|
+
});
|
|
126
|
+
if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).then((resolved) => {
|
|
127
|
+
if (!cancelled) setHandlerResult(resolved);
|
|
128
|
+
}).catch(() => {
|
|
129
|
+
if (!cancelled) setHandlerResult(null);
|
|
130
|
+
});
|
|
131
|
+
else setHandlerResult(maybePromise);
|
|
132
|
+
return () => {
|
|
133
|
+
cancelled = true;
|
|
134
|
+
};
|
|
135
|
+
}, [
|
|
136
|
+
pendingEvent,
|
|
137
|
+
config.enabled,
|
|
138
|
+
config.handler,
|
|
139
|
+
resolve
|
|
140
|
+
]);
|
|
141
|
+
const element = useMemo(() => {
|
|
142
|
+
if (!pendingEvent) return null;
|
|
143
|
+
if (config.enabled && !config.enabled(pendingEvent)) return null;
|
|
144
|
+
return config.render({
|
|
145
|
+
event: pendingEvent,
|
|
146
|
+
result: handlerResult,
|
|
147
|
+
resolve
|
|
148
|
+
});
|
|
149
|
+
}, [
|
|
150
|
+
pendingEvent,
|
|
151
|
+
handlerResult,
|
|
152
|
+
config.enabled,
|
|
153
|
+
config.render,
|
|
154
|
+
resolve
|
|
155
|
+
]);
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (config.renderInChat === false) return;
|
|
158
|
+
copilotkit.setInterruptElement(element);
|
|
159
|
+
return () => copilotkit.setInterruptElement(null);
|
|
160
|
+
}, [
|
|
161
|
+
element,
|
|
162
|
+
config.renderInChat,
|
|
163
|
+
copilotkit
|
|
164
|
+
]);
|
|
165
|
+
if (config.renderInChat === false) return element;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
export { useInterrupt };
|
|
170
|
+
//# sourceMappingURL=use-interrupt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-interrupt.mjs","names":[],"sources":["../../src/hooks/use-interrupt.tsx"],"sourcesContent":["import React, { useState, useEffect, useCallback, useMemo } from \"react\";\nimport { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport { useAgent } from \"./use-agent\";\nimport type {\n InterruptEvent,\n InterruptRenderProps,\n InterruptHandlerProps,\n} from \"../types/interrupt\";\n\nexport type { InterruptEvent, InterruptRenderProps, InterruptHandlerProps };\n\nconst INTERRUPT_EVENT_NAME = \"on_interrupt\";\n\ntype InterruptHandlerFn<TValue, TResult> = (\n props: InterruptHandlerProps<TValue>,\n) => TResult | PromiseLike<TResult>;\n\ntype InterruptResultFromHandler<THandler> = THandler extends (\n ...args: never[]\n) => infer TResult\n ? TResult extends PromiseLike<infer TResolved>\n ? TResolved | null\n : TResult | null\n : null;\n\ntype InterruptResult<TValue, TResult> = InterruptResultFromHandler<\n InterruptHandlerFn<TValue, TResult>\n>;\n\ntype InterruptRenderInChat = boolean | undefined;\n\ntype UseInterruptReturn<TRenderInChat extends InterruptRenderInChat> =\n TRenderInChat extends false\n ? React.ReactElement | null\n : TRenderInChat extends true | undefined\n ? void\n : React.ReactElement | null | void;\n\nexport function isPromiseLike<TValue>(\n value: TValue | PromiseLike<TValue>,\n): value is PromiseLike<TValue> {\n return (\n (typeof value === \"object\" || typeof value === \"function\") &&\n value !== null &&\n typeof Reflect.get(value, \"then\") === \"function\"\n );\n}\n\n/**\n * Configuration options for `useInterrupt`.\n */\ninterface UseInterruptConfigBase<TValue = unknown, TResult = never> {\n /**\n * Render function for the interrupt UI.\n *\n * This is called once an interrupt is finalized and accepted by `enabled` (if provided).\n * Use `resolve` from render props to resume the agent run with user input.\n */\n render: (\n props: InterruptRenderProps<TValue, InterruptResult<TValue, TResult>>,\n ) => React.ReactElement;\n /**\n * Optional pre-render handler invoked when an interrupt is received.\n *\n * Return either a sync value or an async value to pass into `render` as `result`.\n * Rejecting/throwing falls back to `result = null`.\n */\n handler?: InterruptHandlerFn<TValue, TResult>;\n /**\n * Optional predicate to filter which interrupts should be handled by this hook.\n * Return `false` to ignore an interrupt.\n */\n enabled?: (event: InterruptEvent<TValue>) => boolean;\n /** Optional agent id. Defaults to the current configured chat agent. */\n agentId?: string;\n}\n\nexport interface UseInterruptInChatConfig<\n TValue = unknown,\n TResult = never,\n> extends UseInterruptConfigBase<TValue, TResult> {\n /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */\n renderInChat?: true;\n}\n\nexport interface UseInterruptExternalConfig<\n TValue = unknown,\n TResult = never,\n> extends UseInterruptConfigBase<TValue, TResult> {\n /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */\n renderInChat: false;\n}\n\nexport interface UseInterruptDynamicConfig<\n TValue = unknown,\n TResult = never,\n> extends UseInterruptConfigBase<TValue, TResult> {\n /** Dynamic boolean mode. When non-literal, return type is a union. */\n renderInChat: boolean;\n}\n\nexport type UseInterruptConfig<\n TValue = unknown,\n TResult = never,\n TRenderInChat extends InterruptRenderInChat = undefined,\n> = UseInterruptConfigBase<TValue, TResult> & {\n /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */\n renderInChat?: TRenderInChat;\n};\n\n/**\n * Handles agent interrupts (`on_interrupt`) with optional filtering, preprocessing, and resume behavior.\n *\n * The hook listens to custom events on the active agent, stores interrupt payloads per run,\n * and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume\n * execution with user-provided data.\n *\n * - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.\n * - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.\n *\n * `event.value` is typed as `any` since the interrupt payload shape depends on your agent.\n * Type-narrow it in your callbacks (e.g. `handler`, `enabled`, `render`) as needed.\n *\n * @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.\n * @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).\n * @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).\n * Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always\n * either the handler's resolved return value or `null` (including when no handler is provided,\n * when filtering skips the interrupt, or when handler execution fails).\n *\n * @example\n * ```tsx\n * import { useInterrupt } from \"@copilotkitnext/react\";\n *\n * function InterruptUI() {\n * useInterrupt({\n * render: ({ event, resolve }) => (\n * <div>\n * <p>{event.value.question}</p>\n * <button onClick={() => resolve({ approved: true })}>Approve</button>\n * <button onClick={() => resolve({ approved: false })}>Reject</button>\n * </div>\n * ),\n * });\n *\n * return null;\n * }\n * ```\n *\n * @example\n * ```tsx\n * import { useInterrupt } from \"@copilotkitnext/react\";\n *\n * function CustomPanel() {\n * const interruptElement = useInterrupt({\n * renderInChat: false,\n * enabled: (event) => event.value.startsWith(\"approval:\"),\n * handler: async ({ event }) => ({ label: event.value.toUpperCase() }),\n * render: ({ event, result, resolve }) => (\n * <aside>\n * <strong>{result?.label ?? \"\"}</strong>\n * <button onClick={() => resolve({ value: event.value })}>Continue</button>\n * </aside>\n * ),\n * });\n *\n * return <>{interruptElement}</>;\n * }\n * ```\n */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport function useInterrupt<\n TResult = never,\n TRenderInChat extends InterruptRenderInChat = undefined,\n>(\n config: UseInterruptConfig<any, TResult, TRenderInChat>,\n): UseInterruptReturn<TRenderInChat> {\n /* eslint-enable @typescript-eslint/no-explicit-any */\n const { copilotkit } = useCopilotKit();\n const { agent } = useAgent({ agentId: config.agentId });\n const [pendingEvent, setPendingEvent] = useState<InterruptEvent | null>(null);\n const [handlerResult, setHandlerResult] =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n useState<InterruptResult<any, TResult>>(null);\n\n useEffect(() => {\n let localInterrupt: InterruptEvent | null = null;\n\n const subscription = agent.subscribe({\n onCustomEvent: ({ event }) => {\n if (event.name === INTERRUPT_EVENT_NAME) {\n localInterrupt = { name: event.name, value: event.value };\n }\n },\n onRunStartedEvent: () => {\n localInterrupt = null;\n setPendingEvent(null);\n },\n onRunFinalized: () => {\n if (localInterrupt) {\n setPendingEvent(localInterrupt);\n localInterrupt = null;\n }\n },\n onRunFailed: () => {\n localInterrupt = null;\n },\n });\n\n return () => subscription.unsubscribe();\n }, [agent]);\n\n const resolve = useCallback(\n (response: unknown) => {\n setPendingEvent(null);\n copilotkit.runAgent({\n agent,\n forwardedProps: { command: { resume: response } },\n });\n },\n [agent, copilotkit],\n );\n\n useEffect(() => {\n // No interrupt to process — reset any stale handler result from a previous interrupt\n if (!pendingEvent) {\n setHandlerResult(null);\n return;\n }\n // Interrupt exists but the consumer's filter rejects it — treat as no-op\n if (config.enabled && !config.enabled(pendingEvent)) {\n setHandlerResult(null);\n return;\n }\n const handler = config.handler;\n // No handler provided — skip straight to rendering with a null result\n if (!handler) {\n setHandlerResult(null);\n return;\n }\n\n let cancelled = false;\n const maybePromise = handler({\n event: pendingEvent,\n resolve,\n });\n\n // If the handler returns a promise/thenable, wait for resolution before setting result.\n if (isPromiseLike(maybePromise)) {\n Promise.resolve(maybePromise)\n .then((resolved) => {\n if (!cancelled) setHandlerResult(resolved);\n })\n .catch(() => {\n if (!cancelled) setHandlerResult(null);\n });\n } else {\n setHandlerResult(maybePromise);\n }\n\n return () => {\n cancelled = true;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [pendingEvent, config.enabled, config.handler, resolve]);\n\n const element = useMemo(() => {\n if (!pendingEvent) return null;\n if (config.enabled && !config.enabled(pendingEvent)) return null;\n\n return config.render({\n event: pendingEvent,\n result: handlerResult,\n resolve,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [pendingEvent, handlerResult, config.enabled, config.render, resolve]);\n\n // Publish to core for in-chat rendering\n useEffect(() => {\n if (config.renderInChat === false) return;\n copilotkit.setInterruptElement(element);\n return () => copilotkit.setInterruptElement(null);\n }, [element, config.renderInChat, copilotkit]);\n\n // Only return element when rendering outside chat\n if (config.renderInChat === false) {\n return element as UseInterruptReturn<TRenderInChat>;\n }\n\n return undefined as UseInterruptReturn<TRenderInChat>;\n}\n"],"mappings":";;;;;AAWA,MAAM,uBAAuB;AA2B7B,SAAgB,cACd,OAC8B;AAC9B,SACG,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,UAAU,QACV,OAAO,QAAQ,IAAI,OAAO,OAAO,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+H1C,SAAgB,aAId,QACmC;CAEnC,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,EAAE,UAAU,SAAS,EAAE,SAAS,OAAO,SAAS,CAAC;CACvD,MAAM,CAAC,cAAc,mBAAmB,SAAgC,KAAK;CAC7E,MAAM,CAAC,eAAe,oBAEpB,SAAwC,KAAK;AAE/C,iBAAgB;EACd,IAAI,iBAAwC;EAE5C,MAAM,eAAe,MAAM,UAAU;GACnC,gBAAgB,EAAE,YAAY;AAC5B,QAAI,MAAM,SAAS,qBACjB,kBAAiB;KAAE,MAAM,MAAM;KAAM,OAAO,MAAM;KAAO;;GAG7D,yBAAyB;AACvB,qBAAiB;AACjB,oBAAgB,KAAK;;GAEvB,sBAAsB;AACpB,QAAI,gBAAgB;AAClB,qBAAgB,eAAe;AAC/B,sBAAiB;;;GAGrB,mBAAmB;AACjB,qBAAiB;;GAEpB,CAAC;AAEF,eAAa,aAAa,aAAa;IACtC,CAAC,MAAM,CAAC;CAEX,MAAM,UAAU,aACb,aAAsB;AACrB,kBAAgB,KAAK;AACrB,aAAW,SAAS;GAClB;GACA,gBAAgB,EAAE,SAAS,EAAE,QAAQ,UAAU,EAAE;GAClD,CAAC;IAEJ,CAAC,OAAO,WAAW,CACpB;AAED,iBAAgB;AAEd,MAAI,CAAC,cAAc;AACjB,oBAAiB,KAAK;AACtB;;AAGF,MAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,aAAa,EAAE;AACnD,oBAAiB,KAAK;AACtB;;EAEF,MAAM,UAAU,OAAO;AAEvB,MAAI,CAAC,SAAS;AACZ,oBAAiB,KAAK;AACtB;;EAGF,IAAI,YAAY;EAChB,MAAM,eAAe,QAAQ;GAC3B,OAAO;GACP;GACD,CAAC;AAGF,MAAI,cAAc,aAAa,CAC7B,SAAQ,QAAQ,aAAa,CAC1B,MAAM,aAAa;AAClB,OAAI,CAAC,UAAW,kBAAiB,SAAS;IAC1C,CACD,YAAY;AACX,OAAI,CAAC,UAAW,kBAAiB,KAAK;IACtC;MAEJ,kBAAiB,aAAa;AAGhC,eAAa;AACX,eAAY;;IAGb;EAAC;EAAc,OAAO;EAAS,OAAO;EAAS;EAAQ,CAAC;CAE3D,MAAM,UAAU,cAAc;AAC5B,MAAI,CAAC,aAAc,QAAO;AAC1B,MAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,aAAa,CAAE,QAAO;AAE5D,SAAO,OAAO,OAAO;GACnB,OAAO;GACP,QAAQ;GACR;GACD,CAAC;IAED;EAAC;EAAc;EAAe,OAAO;EAAS,OAAO;EAAQ;EAAQ,CAAC;AAGzE,iBAAgB;AACd,MAAI,OAAO,iBAAiB,MAAO;AACnC,aAAW,oBAAoB,QAAQ;AACvC,eAAa,WAAW,oBAAoB,KAAK;IAChD;EAAC;EAAS,OAAO;EAAc;EAAW,CAAC;AAG9C,KAAI,OAAO,iBAAiB,MAC1B,QAAO"}
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ const require_use_agent = require('./hooks/use-agent.cjs');
|
|
|
22
22
|
const require_use_agent_context = require('./hooks/use-agent-context.cjs');
|
|
23
23
|
const require_use_suggestions = require('./hooks/use-suggestions.cjs');
|
|
24
24
|
const require_use_configure_suggestions = require('./hooks/use-configure-suggestions.cjs');
|
|
25
|
+
const require_use_interrupt = require('./hooks/use-interrupt.cjs');
|
|
25
26
|
require('./hooks/index.cjs');
|
|
26
27
|
const require_CopilotChatToolCallsView = require('./components/chat/CopilotChatToolCallsView.cjs');
|
|
27
28
|
const require_CopilotChatAssistantMessage = require('./components/chat/CopilotChatAssistantMessage.cjs');
|
|
@@ -101,6 +102,7 @@ exports.useCopilotKit = require_CopilotKitProvider.useCopilotKit;
|
|
|
101
102
|
exports.useDefaultRenderTool = require_use_default_render_tool.useDefaultRenderTool;
|
|
102
103
|
exports.useFrontendTool = require_use_frontend_tool.useFrontendTool;
|
|
103
104
|
exports.useHumanInTheLoop = require_use_human_in_the_loop.useHumanInTheLoop;
|
|
105
|
+
exports.useInterrupt = require_use_interrupt.useInterrupt;
|
|
104
106
|
exports.useRenderActivityMessage = require_use_render_activity_message.useRenderActivityMessage;
|
|
105
107
|
exports.useRenderCustomMessages = require_use_render_custom_messages.useRenderCustomMessages;
|
|
106
108
|
exports.useRenderTool = require_use_render_tool.useRenderTool;
|
package/dist/index.d.cts
CHANGED
|
@@ -28,6 +28,7 @@ import { ReactActivityMessageRenderer } from "./types/react-activity-message-ren
|
|
|
28
28
|
import { ReactFrontendTool } from "./types/frontend-tool.cjs";
|
|
29
29
|
import { ReactHumanInTheLoop } from "./types/human-in-the-loop.cjs";
|
|
30
30
|
import { defineToolCallRenderer } from "./types/defineToolCallRenderer.cjs";
|
|
31
|
+
import { InterruptEvent, InterruptHandlerProps, InterruptRenderProps } from "./types/interrupt.cjs";
|
|
31
32
|
import "./types/index.cjs";
|
|
32
33
|
import { useRenderActivityMessage } from "./hooks/use-render-activity-message.cjs";
|
|
33
34
|
import { useFrontendTool } from "./hooks/use-frontend-tool.cjs";
|
|
@@ -39,9 +40,10 @@ import { UseAgentUpdate, useAgent } from "./hooks/use-agent.cjs";
|
|
|
39
40
|
import { AgentContextInput, JsonSerializable, useAgentContext } from "./hooks/use-agent-context.cjs";
|
|
40
41
|
import { useSuggestions } from "./hooks/use-suggestions.cjs";
|
|
41
42
|
import { useConfigureSuggestions } from "./hooks/use-configure-suggestions.cjs";
|
|
43
|
+
import { UseInterruptConfig, useInterrupt } from "./hooks/use-interrupt.cjs";
|
|
42
44
|
import "./hooks/index.cjs";
|
|
43
45
|
import { CopilotKitCoreReact, CopilotKitCoreReactConfig, CopilotKitCoreReactSubscriber } from "./lib/react-core.cjs";
|
|
44
46
|
import { CopilotKitContextValue, CopilotKitProvider, CopilotKitProviderProps, useCopilotKit } from "./providers/CopilotKitProvider.cjs";
|
|
45
47
|
import "./providers/index.cjs";
|
|
46
48
|
export * from "@ag-ui/client";
|
|
47
|
-
export { AgentContextInput, AudioRecorderError, AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, CopilotChatConfigurationProviderProps, CopilotChatConfigurationValue, CopilotChatInput, CopilotChatInputProps, CopilotChatLabels, CopilotChatMessageView, CopilotChatMessageViewProps, CopilotChatProps, CopilotChatReasoningMessage, CopilotChatReasoningMessageProps, CopilotChatSuggestionPill, CopilotChatSuggestionPillProps, CopilotChatSuggestionView, CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, CopilotChatToggleButtonProps, CopilotChatToolCallsView, CopilotChatToolCallsViewProps, CopilotChatUserMessage, CopilotChatUserMessageProps, CopilotChatView, CopilotChatViewProps, CopilotKitContextValue, CopilotKitCoreReact, CopilotKitCoreReactConfig, CopilotKitCoreReactSubscriber, CopilotKitInspector, CopilotKitInspectorProps, CopilotKitProvider, CopilotKitProviderProps, CopilotModalHeader, CopilotModalHeaderProps, CopilotPopup, CopilotPopupProps, CopilotPopupView, CopilotPopupViewProps, CopilotSidebar, CopilotSidebarProps, CopilotSidebarView, CopilotSidebarViewProps, JsonSerializable, MCPAppsActivityContent, MCPAppsActivityContentSchema, MCPAppsActivityRenderer, MCPAppsActivityType, ReactActivityMessageRenderer, ReactCustomMessageRenderer, ReactCustomMessageRendererPosition, ReactFrontendTool, ReactHumanInTheLoop, ReactToolCallRenderer, ToolsMenuItem, UseAgentUpdate, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useDefaultRenderTool, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderTool, useRenderToolCall, useSuggestions };
|
|
49
|
+
export { AgentContextInput, AudioRecorderError, AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, CopilotChatConfigurationProviderProps, CopilotChatConfigurationValue, CopilotChatInput, CopilotChatInputProps, CopilotChatLabels, CopilotChatMessageView, CopilotChatMessageViewProps, CopilotChatProps, CopilotChatReasoningMessage, CopilotChatReasoningMessageProps, CopilotChatSuggestionPill, CopilotChatSuggestionPillProps, CopilotChatSuggestionView, CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, CopilotChatToggleButtonProps, CopilotChatToolCallsView, CopilotChatToolCallsViewProps, CopilotChatUserMessage, CopilotChatUserMessageProps, CopilotChatView, CopilotChatViewProps, CopilotKitContextValue, CopilotKitCoreReact, CopilotKitCoreReactConfig, CopilotKitCoreReactSubscriber, CopilotKitInspector, CopilotKitInspectorProps, CopilotKitProvider, CopilotKitProviderProps, CopilotModalHeader, CopilotModalHeaderProps, CopilotPopup, CopilotPopupProps, CopilotPopupView, CopilotPopupViewProps, CopilotSidebar, CopilotSidebarProps, CopilotSidebarView, CopilotSidebarViewProps, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, MCPAppsActivityContent, MCPAppsActivityContentSchema, MCPAppsActivityRenderer, MCPAppsActivityType, ReactActivityMessageRenderer, ReactCustomMessageRenderer, ReactCustomMessageRendererPosition, ReactFrontendTool, ReactHumanInTheLoop, ReactToolCallRenderer, ToolsMenuItem, UseAgentUpdate, UseInterruptConfig, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useDefaultRenderTool, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderActivityMessage, useRenderCustomMessages, useRenderTool, useRenderToolCall, useSuggestions };
|
package/dist/index.d.mts
CHANGED
|
@@ -28,6 +28,7 @@ import { ReactActivityMessageRenderer } from "./types/react-activity-message-ren
|
|
|
28
28
|
import { ReactFrontendTool } from "./types/frontend-tool.mjs";
|
|
29
29
|
import { ReactHumanInTheLoop } from "./types/human-in-the-loop.mjs";
|
|
30
30
|
import { defineToolCallRenderer } from "./types/defineToolCallRenderer.mjs";
|
|
31
|
+
import { InterruptEvent, InterruptHandlerProps, InterruptRenderProps } from "./types/interrupt.mjs";
|
|
31
32
|
import "./types/index.mjs";
|
|
32
33
|
import { useRenderActivityMessage } from "./hooks/use-render-activity-message.mjs";
|
|
33
34
|
import { useFrontendTool } from "./hooks/use-frontend-tool.mjs";
|
|
@@ -39,9 +40,10 @@ import { UseAgentUpdate, useAgent } from "./hooks/use-agent.mjs";
|
|
|
39
40
|
import { AgentContextInput, JsonSerializable, useAgentContext } from "./hooks/use-agent-context.mjs";
|
|
40
41
|
import { useSuggestions } from "./hooks/use-suggestions.mjs";
|
|
41
42
|
import { useConfigureSuggestions } from "./hooks/use-configure-suggestions.mjs";
|
|
43
|
+
import { UseInterruptConfig, useInterrupt } from "./hooks/use-interrupt.mjs";
|
|
42
44
|
import "./hooks/index.mjs";
|
|
43
45
|
import { CopilotKitCoreReact, CopilotKitCoreReactConfig, CopilotKitCoreReactSubscriber } from "./lib/react-core.mjs";
|
|
44
46
|
import { CopilotKitContextValue, CopilotKitProvider, CopilotKitProviderProps, useCopilotKit } from "./providers/CopilotKitProvider.mjs";
|
|
45
47
|
import "./providers/index.mjs";
|
|
46
48
|
export * from "@ag-ui/client";
|
|
47
|
-
export { AgentContextInput, AudioRecorderError, AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, CopilotChatConfigurationProviderProps, CopilotChatConfigurationValue, CopilotChatInput, CopilotChatInputProps, CopilotChatLabels, CopilotChatMessageView, CopilotChatMessageViewProps, CopilotChatProps, CopilotChatReasoningMessage, CopilotChatReasoningMessageProps, CopilotChatSuggestionPill, CopilotChatSuggestionPillProps, CopilotChatSuggestionView, CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, CopilotChatToggleButtonProps, CopilotChatToolCallsView, CopilotChatToolCallsViewProps, CopilotChatUserMessage, CopilotChatUserMessageProps, CopilotChatView, CopilotChatViewProps, CopilotKitContextValue, CopilotKitCoreReact, CopilotKitCoreReactConfig, CopilotKitCoreReactSubscriber, CopilotKitInspector, CopilotKitInspectorProps, CopilotKitProvider, CopilotKitProviderProps, CopilotModalHeader, CopilotModalHeaderProps, CopilotPopup, CopilotPopupProps, CopilotPopupView, CopilotPopupViewProps, CopilotSidebar, CopilotSidebarProps, CopilotSidebarView, CopilotSidebarViewProps, JsonSerializable, MCPAppsActivityContent, MCPAppsActivityContentSchema, MCPAppsActivityRenderer, MCPAppsActivityType, ReactActivityMessageRenderer, ReactCustomMessageRenderer, ReactCustomMessageRendererPosition, ReactFrontendTool, ReactHumanInTheLoop, ReactToolCallRenderer, ToolsMenuItem, UseAgentUpdate, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useDefaultRenderTool, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderTool, useRenderToolCall, useSuggestions };
|
|
49
|
+
export { AgentContextInput, AudioRecorderError, AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, CopilotChatConfigurationProviderProps, CopilotChatConfigurationValue, CopilotChatInput, CopilotChatInputProps, CopilotChatLabels, CopilotChatMessageView, CopilotChatMessageViewProps, CopilotChatProps, CopilotChatReasoningMessage, CopilotChatReasoningMessageProps, CopilotChatSuggestionPill, CopilotChatSuggestionPillProps, CopilotChatSuggestionView, CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, CopilotChatToggleButtonProps, CopilotChatToolCallsView, CopilotChatToolCallsViewProps, CopilotChatUserMessage, CopilotChatUserMessageProps, CopilotChatView, CopilotChatViewProps, CopilotKitContextValue, CopilotKitCoreReact, CopilotKitCoreReactConfig, CopilotKitCoreReactSubscriber, CopilotKitInspector, CopilotKitInspectorProps, CopilotKitProvider, CopilotKitProviderProps, CopilotModalHeader, CopilotModalHeaderProps, CopilotPopup, CopilotPopupProps, CopilotPopupView, CopilotPopupViewProps, CopilotSidebar, CopilotSidebarProps, CopilotSidebarView, CopilotSidebarViewProps, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, MCPAppsActivityContent, MCPAppsActivityContentSchema, MCPAppsActivityRenderer, MCPAppsActivityType, ReactActivityMessageRenderer, ReactCustomMessageRenderer, ReactCustomMessageRendererPosition, ReactFrontendTool, ReactHumanInTheLoop, ReactToolCallRenderer, ToolsMenuItem, UseAgentUpdate, UseInterruptConfig, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useDefaultRenderTool, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderActivityMessage, useRenderCustomMessages, useRenderTool, useRenderToolCall, useSuggestions };
|
package/dist/index.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { UseAgentUpdate, useAgent } from "./hooks/use-agent.mjs";
|
|
|
21
21
|
import { useAgentContext } from "./hooks/use-agent-context.mjs";
|
|
22
22
|
import { useSuggestions } from "./hooks/use-suggestions.mjs";
|
|
23
23
|
import { useConfigureSuggestions } from "./hooks/use-configure-suggestions.mjs";
|
|
24
|
+
import { useInterrupt } from "./hooks/use-interrupt.mjs";
|
|
24
25
|
import "./hooks/index.mjs";
|
|
25
26
|
import CopilotChatToolCallsView from "./components/chat/CopilotChatToolCallsView.mjs";
|
|
26
27
|
import CopilotChatAssistantMessage_default from "./components/chat/CopilotChatAssistantMessage.mjs";
|
|
@@ -43,4 +44,4 @@ import "./types/index.mjs";
|
|
|
43
44
|
|
|
44
45
|
export * from "@ag-ui/client"
|
|
45
46
|
|
|
46
|
-
export { AudioRecorderError, CopilotChat, CopilotChatAssistantMessage_default as CopilotChatAssistantMessage, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, CopilotChatInput_default as CopilotChatInput, CopilotChatMessageView, CopilotChatReasoningMessage_default as CopilotChatReasoningMessage, CopilotChatSuggestionPill, CopilotChatSuggestionView, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, CopilotChatToolCallsView, CopilotChatUserMessage_default as CopilotChatUserMessage, CopilotChatView_default as CopilotChatView, CopilotKitCoreReact, CopilotKitInspector, CopilotKitProvider, CopilotModalHeader, CopilotPopup, CopilotPopupView, CopilotSidebar, CopilotSidebarView, MCPAppsActivityContentSchema, MCPAppsActivityRenderer, MCPAppsActivityType, UseAgentUpdate, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useDefaultRenderTool, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderTool, useRenderToolCall, useSuggestions };
|
|
47
|
+
export { AudioRecorderError, CopilotChat, CopilotChatAssistantMessage_default as CopilotChatAssistantMessage, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, CopilotChatInput_default as CopilotChatInput, CopilotChatMessageView, CopilotChatReasoningMessage_default as CopilotChatReasoningMessage, CopilotChatSuggestionPill, CopilotChatSuggestionView, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, CopilotChatToolCallsView, CopilotChatUserMessage_default as CopilotChatUserMessage, CopilotChatView_default as CopilotChatView, CopilotKitCoreReact, CopilotKitInspector, CopilotKitProvider, CopilotModalHeader, CopilotPopup, CopilotPopupView, CopilotSidebar, CopilotSidebarView, MCPAppsActivityContentSchema, MCPAppsActivityRenderer, MCPAppsActivityType, UseAgentUpdate, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useDefaultRenderTool, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderActivityMessage, useRenderCustomMessages, useRenderTool, useRenderToolCall, useSuggestions };
|