@copilotkit/react-core 1.57.0 → 1.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/{copilotkit-DFaI4j2r.d.mts → copilotkit-BN4I_y1n.d.mts} +64 -8
  2. package/dist/copilotkit-BN4I_y1n.d.mts.map +1 -0
  3. package/dist/{copilotkit-DGbvw8n2.cjs → copilotkit-C3k13WZn.cjs} +572 -435
  4. package/dist/copilotkit-C3k13WZn.cjs.map +1 -0
  5. package/dist/{copilotkit-CPe2-340.mjs → copilotkit-DjxXMYHG.mjs} +571 -440
  6. package/dist/copilotkit-DjxXMYHG.mjs.map +1 -0
  7. package/dist/{copilotkit-Dg4r4Gi_.d.cts → copilotkit-sQWiKtxA.d.cts} +64 -8
  8. package/dist/copilotkit-sQWiKtxA.d.cts.map +1 -0
  9. package/dist/index.cjs +2 -5
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +2 -5
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +449 -502
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/context.cjs +135 -0
  18. package/dist/v2/context.cjs.map +1 -0
  19. package/dist/v2/context.d.cts +148 -0
  20. package/dist/v2/context.d.cts.map +1 -0
  21. package/dist/v2/context.d.mts +148 -0
  22. package/dist/v2/context.d.mts.map +1 -0
  23. package/dist/v2/context.mjs +129 -0
  24. package/dist/v2/context.mjs.map +1 -0
  25. package/dist/v2/headless.cjs +1043 -0
  26. package/dist/v2/headless.cjs.map +1 -0
  27. package/dist/v2/headless.d.cts +605 -0
  28. package/dist/v2/headless.d.cts.map +1 -0
  29. package/dist/v2/headless.d.mts +512 -0
  30. package/dist/v2/headless.d.mts.map +1 -0
  31. package/dist/v2/headless.mjs +997 -0
  32. package/dist/v2/headless.mjs.map +1 -0
  33. package/dist/v2/index.cjs +2 -1
  34. package/dist/v2/index.css +1 -1
  35. package/dist/v2/index.d.cts +2 -2
  36. package/dist/v2/index.d.mts +2 -2
  37. package/dist/v2/index.mjs +2 -2
  38. package/dist/v2/index.umd.js +584 -441
  39. package/dist/v2/index.umd.js.map +1 -1
  40. package/package.json +14 -6
  41. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +5 -6
  42. package/src/hooks/use-copilot-chat_internal.ts +0 -1
  43. package/src/v2/components/chat/CopilotChat.tsx +2 -1
  44. package/src/v2/components/chat/CopilotChatMessageView.tsx +24 -9
  45. package/src/v2/components/chat/CopilotChatView.tsx +2 -2
  46. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +1 -3
  47. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +29 -25
  48. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +5 -60
  49. package/src/v2/components/index.ts +1 -0
  50. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +286 -0
  51. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +464 -0
  52. package/src/v2/components/intelligence-indicator/index.ts +2 -0
  53. package/src/v2/context.ts +62 -0
  54. package/src/v2/headless.ts +42 -0
  55. package/src/v2/hooks/__tests__/standard-schema.test.tsx +2 -2
  56. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +3 -3
  57. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +3 -3
  58. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +85 -85
  59. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +2 -2
  60. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +2 -2
  61. package/src/v2/hooks/__tests__/use-threads.test.tsx +2 -2
  62. package/src/v2/hooks/__tests__/zod-regression.test.tsx +2 -2
  63. package/src/v2/hooks/use-agent-context.tsx +1 -1
  64. package/src/v2/hooks/use-agent.tsx +9 -118
  65. package/src/v2/hooks/use-configure-suggestions.tsx +1 -1
  66. package/src/v2/hooks/use-frontend-tool.tsx +2 -2
  67. package/src/v2/hooks/use-human-in-the-loop.tsx +1 -1
  68. package/src/v2/hooks/use-interrupt.tsx +1 -1
  69. package/src/v2/hooks/use-render-activity-message.tsx +3 -11
  70. package/src/v2/hooks/use-render-custom-messages.tsx +1 -6
  71. package/src/v2/hooks/use-render-tool-call.tsx +1 -1
  72. package/src/v2/hooks/use-render-tool.tsx +2 -2
  73. package/src/v2/hooks/use-suggestions.tsx +1 -1
  74. package/src/v2/hooks/use-threads.tsx +1 -1
  75. package/src/v2/providers/CopilotKitProvider.tsx +19 -59
  76. package/src/v2/styles/globals.css +118 -0
  77. package/tsdown.config.ts +75 -0
  78. package/dist/copilotkit-CPe2-340.mjs.map +0 -1
  79. package/dist/copilotkit-DFaI4j2r.d.mts.map +0 -1
  80. package/dist/copilotkit-DGbvw8n2.cjs.map +0 -1
  81. package/dist/copilotkit-Dg4r4Gi_.d.cts.map +0 -1
  82. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +0 -333
@@ -0,0 +1,512 @@
1
+ import React$1, { ComponentType, ReactNode } from "react";
2
+ import { InferSchemaOutput, StandardSchemaV1 } from "@copilotkit/shared";
3
+ import { AbstractAgent } from "@ag-ui/client";
4
+ import { DynamicSuggestionsConfig, FrontendTool, StaticSuggestionsConfig, Suggestion, ToolCallStatus } from "@copilotkit/core";
5
+ import { CopilotKitCoreReact, CopilotKitCoreReactConfig } from "./context";
6
+
7
+ //#region src/v2/providers/CopilotChatConfigurationProvider.d.ts
8
+ declare const CopilotChatDefaultLabels: {
9
+ chatInputPlaceholder: string;
10
+ chatInputToolbarStartTranscribeButtonLabel: string;
11
+ chatInputToolbarCancelTranscribeButtonLabel: string;
12
+ chatInputToolbarFinishTranscribeButtonLabel: string;
13
+ chatInputToolbarAddButtonLabel: string;
14
+ chatInputToolbarToolsButtonLabel: string;
15
+ assistantMessageToolbarCopyCodeLabel: string;
16
+ assistantMessageToolbarCopyCodeCopiedLabel: string;
17
+ assistantMessageToolbarCopyMessageLabel: string;
18
+ assistantMessageToolbarThumbsUpLabel: string;
19
+ assistantMessageToolbarThumbsDownLabel: string;
20
+ assistantMessageToolbarReadAloudLabel: string;
21
+ assistantMessageToolbarRegenerateLabel: string;
22
+ userMessageToolbarCopyMessageLabel: string;
23
+ userMessageToolbarEditMessageLabel: string;
24
+ chatDisclaimerText: string;
25
+ chatToggleOpenLabel: string;
26
+ chatToggleCloseLabel: string;
27
+ modalHeaderTitle: string;
28
+ welcomeMessageText: string;
29
+ };
30
+ type CopilotChatLabels = typeof CopilotChatDefaultLabels;
31
+ interface CopilotChatConfigurationValue {
32
+ labels: CopilotChatLabels;
33
+ agentId: string;
34
+ threadId: string;
35
+ isModalOpen: boolean;
36
+ setModalOpen: (open: boolean) => void;
37
+ hasExplicitThreadId: boolean;
38
+ }
39
+ interface CopilotChatConfigurationProviderProps {
40
+ children: ReactNode;
41
+ labels?: Partial<CopilotChatLabels>;
42
+ agentId?: string;
43
+ threadId?: string;
44
+ hasExplicitThreadId?: boolean;
45
+ isModalDefaultOpen?: boolean;
46
+ }
47
+ declare const CopilotChatConfigurationProvider: React$1.FC<CopilotChatConfigurationProviderProps>;
48
+ declare const useCopilotChatConfiguration: () => CopilotChatConfigurationValue | null;
49
+ //#endregion
50
+ //#region src/v2/hooks/use-agent.d.ts
51
+ declare enum UseAgentUpdate {
52
+ OnMessagesChanged = "OnMessagesChanged",
53
+ OnStateChanged = "OnStateChanged",
54
+ OnRunStatusChanged = "OnRunStatusChanged"
55
+ }
56
+ interface UseAgentProps {
57
+ agentId?: string;
58
+ updates?: UseAgentUpdate[];
59
+ /**
60
+ * Throttle interval (in milliseconds) for re-renders triggered by
61
+ * `onMessagesChanged` and `onStateChanged` notifications. Useful to reduce
62
+ * re-render frequency during high-frequency streaming updates.
63
+ *
64
+ * Uses a leading+trailing pattern with a shared window — first update
65
+ * fires immediately, subsequent updates within the window are coalesced,
66
+ * and a trailing timer ensures the most recent update fires after the
67
+ * window expires. See `CopilotKitCore.subscribeToAgentWithOptions` in `@copilotkit/core`
68
+ * for details.
69
+ *
70
+ * Resolved as: `throttleMs ?? provider defaultThrottleMs ?? 0`.
71
+ * Passing `throttleMs={0}` explicitly disables throttling even when the
72
+ * provider specifies a non-zero `defaultThrottleMs`.
73
+ *
74
+ * Run lifecycle callbacks (`onRunInitialized`, `onRunFinalized`,
75
+ * `onRunFailed`, `onRunErrorEvent`) always fire immediately.
76
+ *
77
+ * @default undefined
78
+ * When unset, inherits from the provider's `defaultThrottleMs`;
79
+ * if that is also unset, the effective value is `0` (no throttle).
80
+ */
81
+ throttleMs?: number;
82
+ }
83
+ declare function useAgent({
84
+ agentId,
85
+ updates,
86
+ throttleMs
87
+ }?: UseAgentProps): {
88
+ agent: AbstractAgent;
89
+ };
90
+ //#endregion
91
+ //#region src/v2/types/react-tool-call-renderer.d.ts
92
+ interface ReactToolCallRenderer<T = unknown> {
93
+ name: string;
94
+ args: StandardSchemaV1<any, T>;
95
+ /**
96
+ * Optional agent ID to constrain this tool renderer to a specific agent.
97
+ * If specified, this renderer will only be used for the specified agent.
98
+ */
99
+ agentId?: string;
100
+ render: React.ComponentType<{
101
+ name: string;
102
+ toolCallId: string;
103
+ args: Partial<T>;
104
+ status: ToolCallStatus.InProgress;
105
+ result: undefined;
106
+ } | {
107
+ name: string;
108
+ toolCallId: string;
109
+ args: T;
110
+ status: ToolCallStatus.Executing;
111
+ result: undefined;
112
+ } | {
113
+ name: string;
114
+ toolCallId: string;
115
+ args: T;
116
+ status: ToolCallStatus.Complete;
117
+ result: string;
118
+ }>;
119
+ }
120
+ //#endregion
121
+ //#region src/v2/types/frontend-tool.d.ts
122
+ type ReactFrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = FrontendTool<T> & {
123
+ render?: ReactToolCallRenderer<T>["render"];
124
+ };
125
+ //#endregion
126
+ //#region src/v2/hooks/use-frontend-tool.d.ts
127
+ declare function useFrontendTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactFrontendTool<T>, deps?: ReadonlyArray<unknown>): void;
128
+ //#endregion
129
+ //#region src/v2/hooks/use-component.d.ts
130
+ type InferRenderProps<T> = T extends StandardSchemaV1 ? InferSchemaOutput<T> : any;
131
+ /**
132
+ * Registers a React component as a frontend tool renderer in chat.
133
+ *
134
+ * This hook is a convenience wrapper around `useFrontendTool` that:
135
+ * - builds a model-facing tool description,
136
+ * - forwards optional schema parameters (any Standard Schema V1 compatible library),
137
+ * - renders your component with tool call parameters.
138
+ *
139
+ * Use this when you want to display a typed visual component for a tool call
140
+ * without manually wiring a full frontend tool object.
141
+ *
142
+ * When `parameters` is provided, render props are inferred from the schema.
143
+ * When omitted, the render component may accept any props.
144
+ *
145
+ * @typeParam TSchema - Schema describing tool parameters, or `undefined` when no schema is given.
146
+ * @param config - Tool registration config.
147
+ * @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
148
+ *
149
+ * @example
150
+ * ```tsx
151
+ * // Without parameters — render accepts any props
152
+ * useComponent({
153
+ * name: "showGreeting",
154
+ * render: ({ message }: { message: string }) => <div>{message}</div>,
155
+ * });
156
+ * ```
157
+ *
158
+ * @example
159
+ * ```tsx
160
+ * // With parameters — render props inferred from schema
161
+ * useComponent({
162
+ * name: "showWeatherCard",
163
+ * parameters: z.object({ city: z.string() }),
164
+ * render: ({ city }) => <div>{city}</div>,
165
+ * });
166
+ * ```
167
+ *
168
+ * @example
169
+ * ```tsx
170
+ * useComponent(
171
+ * {
172
+ * name: "renderProfile",
173
+ * parameters: z.object({ userId: z.string() }),
174
+ * render: ProfileCard,
175
+ * agentId: "support-agent",
176
+ * },
177
+ * [selectedAgentId],
178
+ * );
179
+ * ```
180
+ */
181
+ declare function useComponent<TSchema extends StandardSchemaV1 | undefined = undefined>(config: {
182
+ name: string;
183
+ description?: string;
184
+ parameters?: TSchema;
185
+ render: ComponentType<NoInfer<InferRenderProps<TSchema>>>;
186
+ agentId?: string;
187
+ }, deps?: ReadonlyArray<unknown>): void;
188
+ //#endregion
189
+ //#region src/v2/types/human-in-the-loop.d.ts
190
+ type ReactHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>> = Omit<FrontendTool<T>, "handler"> & {
191
+ render: React$1.ComponentType<{
192
+ name: string;
193
+ description: string;
194
+ args: Partial<T>;
195
+ status: ToolCallStatus.InProgress;
196
+ result: undefined;
197
+ respond: undefined;
198
+ } | {
199
+ name: string;
200
+ description: string;
201
+ args: T;
202
+ status: ToolCallStatus.Executing;
203
+ result: undefined;
204
+ respond: (result: unknown) => Promise<void>;
205
+ } | {
206
+ name: string;
207
+ description: string;
208
+ args: T;
209
+ status: ToolCallStatus.Complete;
210
+ result: string;
211
+ respond: undefined;
212
+ }>;
213
+ };
214
+ //#endregion
215
+ //#region src/v2/hooks/use-human-in-the-loop.d.ts
216
+ declare function useHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>): void;
217
+ //#endregion
218
+ //#region src/v2/types/interrupt.d.ts
219
+ interface InterruptEvent<TValue = unknown> {
220
+ name: string;
221
+ value: TValue;
222
+ }
223
+ interface InterruptHandlerProps<TValue = unknown> {
224
+ event: InterruptEvent<TValue>;
225
+ resolve: (response: unknown) => void;
226
+ }
227
+ interface InterruptRenderProps<TValue = unknown, TResult = unknown> {
228
+ event: InterruptEvent<TValue>;
229
+ result: TResult;
230
+ resolve: (response: unknown) => void;
231
+ }
232
+ //#endregion
233
+ //#region src/v2/hooks/use-interrupt.d.ts
234
+ type InterruptHandlerFn<TValue, TResult> = (props: InterruptHandlerProps<TValue>) => TResult | PromiseLike<TResult>;
235
+ type InterruptResultFromHandler<THandler> = THandler extends ((...args: never[]) => infer TResult) ? TResult extends PromiseLike<infer TResolved> ? TResolved | null : TResult | null : null;
236
+ type InterruptResult<TValue, TResult> = InterruptResultFromHandler<InterruptHandlerFn<TValue, TResult>>;
237
+ type InterruptRenderInChat = boolean | undefined;
238
+ type UseInterruptReturn<TRenderInChat extends InterruptRenderInChat> = TRenderInChat extends false ? React$1.ReactElement | null : TRenderInChat extends true | undefined ? void : React$1.ReactElement | null | void;
239
+ /**
240
+ * Configuration options for `useInterrupt`.
241
+ */
242
+ interface UseInterruptConfigBase<TValue = unknown, TResult = never> {
243
+ /**
244
+ * Render function for the interrupt UI.
245
+ *
246
+ * This is called once an interrupt is finalized and accepted by `enabled` (if provided).
247
+ * Use `resolve` from render props to resume the agent run with user input.
248
+ */
249
+ render: (props: InterruptRenderProps<TValue, InterruptResult<TValue, TResult>>) => React$1.ReactElement;
250
+ /**
251
+ * Optional pre-render handler invoked when an interrupt is received.
252
+ *
253
+ * Return either a sync value or an async value to pass into `render` as `result`.
254
+ * Rejecting/throwing falls back to `result = null`.
255
+ */
256
+ handler?: InterruptHandlerFn<TValue, TResult>;
257
+ /**
258
+ * Optional predicate to filter which interrupts should be handled by this hook.
259
+ * Return `false` to ignore an interrupt.
260
+ */
261
+ enabled?: (event: InterruptEvent<TValue>) => boolean;
262
+ /** Optional agent id. Defaults to the current configured chat agent. */
263
+ agentId?: string;
264
+ }
265
+ type UseInterruptConfig<TValue = unknown, TResult = never, TRenderInChat extends InterruptRenderInChat = undefined> = UseInterruptConfigBase<TValue, TResult> & {
266
+ /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. Set to false to render it yourself. */renderInChat?: TRenderInChat;
267
+ };
268
+ /**
269
+ * Handles agent interrupts (`on_interrupt`) with optional filtering, preprocessing, and resume behavior.
270
+ *
271
+ * The hook listens to custom events on the active agent, stores interrupt payloads per run,
272
+ * and surfaces a render callback once the run finalizes. Call `resolve` from your UI to resume
273
+ * execution with user-provided data.
274
+ *
275
+ * - `renderInChat: true` (default): the element is published into `<CopilotChat>` and this hook returns `void`.
276
+ * - `renderInChat: false`: the hook returns the interrupt element so you can place it anywhere in your component tree.
277
+ *
278
+ * `event.value` is typed as `any` since the interrupt payload shape depends on your agent.
279
+ * Type-narrow it in your callbacks (e.g. `handler`, `enabled`, `render`) as needed.
280
+ *
281
+ * @typeParam TResult - Inferred from `handler` return type. Exposed as `result` in `render`.
282
+ * @param config - Interrupt configuration (renderer, optional handler/filter, and render mode).
283
+ * @returns When `renderInChat` is `false`, returns the interrupt element (or `null` when idle).
284
+ * Otherwise returns `void` and publishes the element into chat. In `render`, `result` is always
285
+ * either the handler's resolved return value or `null` (including when no handler is provided,
286
+ * when filtering skips the interrupt, or when handler execution fails).
287
+ *
288
+ * @example
289
+ * ```tsx
290
+ * import { useInterrupt } from "@copilotkit/react-core/v2";
291
+ *
292
+ * function InterruptUI() {
293
+ * useInterrupt({
294
+ * render: ({ event, resolve }) => (
295
+ * <div>
296
+ * <p>{event.value.question}</p>
297
+ * <button onClick={() => resolve({ approved: true })}>Approve</button>
298
+ * <button onClick={() => resolve({ approved: false })}>Reject</button>
299
+ * </div>
300
+ * ),
301
+ * });
302
+ *
303
+ * return null;
304
+ * }
305
+ * ```
306
+ *
307
+ * @example
308
+ * ```tsx
309
+ * import { useInterrupt } from "@copilotkit/react-core/v2";
310
+ *
311
+ * function CustomPanel() {
312
+ * const interruptElement = useInterrupt({
313
+ * renderInChat: false,
314
+ * enabled: (event) => event.value.startsWith("approval:"),
315
+ * handler: async ({ event }) => ({ label: event.value.toUpperCase() }),
316
+ * render: ({ event, result, resolve }) => (
317
+ * <aside>
318
+ * <strong>{result?.label ?? ""}</strong>
319
+ * <button onClick={() => resolve({ value: event.value })}>Continue</button>
320
+ * </aside>
321
+ * ),
322
+ * });
323
+ *
324
+ * return <>{interruptElement}</>;
325
+ * }
326
+ * ```
327
+ */
328
+ declare function useInterrupt<TResult = never, TRenderInChat extends InterruptRenderInChat = undefined>(config: UseInterruptConfig<any, TResult, TRenderInChat>): UseInterruptReturn<TRenderInChat>;
329
+ //#endregion
330
+ //#region src/v2/hooks/use-suggestions.d.ts
331
+ interface UseSuggestionsOptions {
332
+ agentId?: string;
333
+ }
334
+ interface UseSuggestionsResult {
335
+ suggestions: Suggestion[];
336
+ reloadSuggestions: () => void;
337
+ clearSuggestions: () => void;
338
+ isLoading: boolean;
339
+ }
340
+ declare function useSuggestions({
341
+ agentId
342
+ }?: UseSuggestionsOptions): UseSuggestionsResult;
343
+ //#endregion
344
+ //#region src/v2/hooks/use-configure-suggestions.d.ts
345
+ type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
346
+ type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & {
347
+ suggestions: StaticSuggestionInput[];
348
+ };
349
+ type SuggestionsConfigInput = DynamicSuggestionsConfig | StaticSuggestionsConfigInput;
350
+ declare function useConfigureSuggestions(config: SuggestionsConfigInput | null | undefined, deps?: ReadonlyArray<unknown>): void;
351
+ //#endregion
352
+ //#region src/v2/hooks/use-agent-context.d.ts
353
+ /**
354
+ * Represents any value that can be serialized to JSON.
355
+ */
356
+ type JsonSerializable = string | number | boolean | null | JsonSerializable[] | {
357
+ [key: string]: JsonSerializable;
358
+ };
359
+ /**
360
+ * Context configuration for useAgentContext.
361
+ * Accepts any JSON-serializable value which will be converted to a string.
362
+ */
363
+ interface AgentContextInput {
364
+ /** A human-readable description of what this context represents */
365
+ description: string;
366
+ /** The context value - will be converted to a JSON string if not already a string */
367
+ value: JsonSerializable;
368
+ }
369
+ declare function useAgentContext(context: AgentContextInput): void;
370
+ //#endregion
371
+ //#region src/v2/hooks/use-threads.d.ts
372
+ /**
373
+ * A conversation thread managed by the Intelligence platform.
374
+ *
375
+ * Each thread has a unique `id`, an optional human-readable `name`, and
376
+ * timestamp fields tracking creation and update times.
377
+ */
378
+ interface Thread {
379
+ id: string;
380
+ agentId: string;
381
+ name: string | null;
382
+ archived: boolean;
383
+ createdAt: string;
384
+ updatedAt: string;
385
+ /**
386
+ * ISO-8601 timestamp of the most recent agent run on this thread. Absent
387
+ * when the thread has never been run. Prefer this over `updatedAt` for
388
+ * user-facing "last activity" displays — it is not bumped by metadata-only
389
+ * actions like rename or archive.
390
+ */
391
+ lastRunAt?: string;
392
+ }
393
+ /**
394
+ * Configuration for the {@link useThreads} hook.
395
+ *
396
+ * Thread operations are scoped to the runtime-authenticated user and the
397
+ * provided agent on the Intelligence platform.
398
+ */
399
+ interface UseThreadsInput {
400
+ /** The ID of the agent whose threads to list and manage. */
401
+ agentId: string;
402
+ /** When `true`, archived threads are included in the list. Defaults to `false`. */
403
+ includeArchived?: boolean;
404
+ /** Maximum number of threads to fetch per page. When set, enables cursor-based pagination. */
405
+ limit?: number;
406
+ }
407
+ /**
408
+ * Return value of the {@link useThreads} hook.
409
+ *
410
+ * The `threads` array is kept in sync with the platform via a realtime
411
+ * WebSocket subscription (when available) and is sorted most-recently-updated
412
+ * first. Mutations reject with an `Error` if the platform request fails.
413
+ */
414
+ interface UseThreadsResult {
415
+ /**
416
+ * Threads for the current user/agent pair, sorted by most recently
417
+ * updated first. Updated in realtime when the platform pushes metadata
418
+ * events. Includes archived threads only when `includeArchived` is set.
419
+ */
420
+ threads: Thread[];
421
+ /**
422
+ * `true` while the initial thread list is being fetched from the platform.
423
+ * Subsequent realtime updates do not re-enter the loading state.
424
+ */
425
+ isLoading: boolean;
426
+ /**
427
+ * The most recent error from fetching threads or executing a mutation,
428
+ * or `null` when there is no error. Reset to `null` on the next
429
+ * successful fetch.
430
+ */
431
+ error: Error | null;
432
+ /**
433
+ * `true` when there are more threads available to fetch via
434
+ * {@link fetchMoreThreads}. Only meaningful when `limit` is set.
435
+ */
436
+ hasMoreThreads: boolean;
437
+ /**
438
+ * `true` while a subsequent page of threads is being fetched.
439
+ */
440
+ isFetchingMoreThreads: boolean;
441
+ /**
442
+ * Fetch the next page of threads. No-op when {@link hasMoreThreads} is
443
+ * `false` or a fetch is already in progress.
444
+ */
445
+ fetchMoreThreads: () => void;
446
+ /**
447
+ * Rename a thread on the platform.
448
+ * Resolves when the server confirms the update; rejects on failure.
449
+ */
450
+ renameThread: (threadId: string, name: string) => Promise<void>;
451
+ /**
452
+ * Archive a thread on the platform.
453
+ * Archived threads are excluded from subsequent list results.
454
+ * Resolves when the server confirms the update; rejects on failure.
455
+ */
456
+ archiveThread: (threadId: string) => Promise<void>;
457
+ /**
458
+ * Permanently delete a thread from the platform.
459
+ * This is irreversible. Resolves when the server confirms deletion;
460
+ * rejects on failure.
461
+ */
462
+ deleteThread: (threadId: string) => Promise<void>;
463
+ }
464
+ /**
465
+ * React hook for listing and managing Intelligence platform threads.
466
+ *
467
+ * On mount the hook fetches the thread list for the runtime-authenticated user
468
+ * and the given `agentId`. When the Intelligence platform exposes a WebSocket
469
+ * URL, it also opens a realtime subscription so the `threads` array stays
470
+ * current without polling — thread creates, renames, archives, and deletes
471
+ * from any client are reflected immediately.
472
+ *
473
+ * Mutation methods (`renameThread`, `archiveThread`, `deleteThread`) return
474
+ * promises that resolve once the platform confirms the operation and reject
475
+ * with an `Error` on failure.
476
+ *
477
+ * @param input - Agent identifier and optional list controls.
478
+ * @returns Thread list state and stable mutation callbacks.
479
+ *
480
+ * @example
481
+ * ```tsx
482
+ * import { useThreads } from "@copilotkit/react-core";
483
+ *
484
+ * function ThreadList() {
485
+ * const { threads, isLoading, renameThread, deleteThread } = useThreads({
486
+ * agentId: "agent-1",
487
+ * });
488
+ *
489
+ * if (isLoading) return <p>Loading…</p>;
490
+ *
491
+ * return (
492
+ * <ul>
493
+ * {threads.map((t) => (
494
+ * <li key={t.id}>
495
+ * {t.name ?? "Untitled"}
496
+ * <button onClick={() => renameThread(t.id, "New name")}>Rename</button>
497
+ * <button onClick={() => deleteThread(t.id)}>Delete</button>
498
+ * </li>
499
+ * ))}
500
+ * </ul>
501
+ * );
502
+ * }
503
+ * ```
504
+ */
505
+ declare function useThreads({
506
+ agentId,
507
+ includeArchived,
508
+ limit
509
+ }: UseThreadsInput): UseThreadsResult;
510
+ //#endregion
511
+ export { type AgentContextInput, CopilotChatConfigurationProvider, type CopilotChatConfigurationProviderProps, type CopilotChatConfigurationValue, CopilotChatDefaultLabels, type CopilotChatLabels, CopilotKitCoreReact, type CopilotKitCoreReactConfig, type JsonSerializable, type Thread, type UseAgentUpdate, type UseInterruptConfig, type UseThreadsInput, type UseThreadsResult, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useFrontendTool, useHumanInTheLoop, useInterrupt, useSuggestions, useThreads };
512
+ //# sourceMappingURL=headless.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headless.d.mts","names":[],"sources":["../../src/v2/providers/CopilotChatConfigurationProvider.tsx","../../src/v2/hooks/use-agent.tsx","../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/frontend-tool.ts","../../src/v2/hooks/use-frontend-tool.tsx","../../src/v2/hooks/use-component.tsx","../../src/v2/types/human-in-the-loop.ts","../../src/v2/hooks/use-human-in-the-loop.tsx","../../src/v2/types/interrupt.ts","../../src/v2/hooks/use-interrupt.tsx","../../src/v2/hooks/use-suggestions.tsx","../../src/v2/hooks/use-configure-suggestions.tsx","../../src/v2/hooks/use-agent-context.tsx","../../src/v2/hooks/use-threads.tsx"],"mappings":";;;;;;;cAca,wBAAA;;;;;;;;;;;;;;;;;;;;;;KAwBD,iBAAA,UAA2B,wBAAA;AAAA,UAGtB,6BAAA;EACf,MAAA,EAAQ,iBAAA;EACR,OAAA;EACA,QAAA;EACA,WAAA;EACA,YAAA,GAAe,IAAA;EAKf,mBAAA;AAAA;AAAA,UAQe,qCAAA;EACf,QAAA,EAAU,SAAA;EACV,MAAA,GAAS,OAAA,CAAQ,iBAAA;EACjB,OAAA;EACA,QAAA;EAMA,mBAAA;EACA,kBAAA;AAAA;AAAA,cAIW,gCAAA,EAAkC,OAAA,CAAM,EAAA,CACnD,qCAAA;AAAA,cAoHW,2BAAA,QACP,6BAAA;;;aCtLM,cAAA;EACV,iBAAA;EACA,cAAA;EACA,kBAAA;AAAA;AAAA,UASe,aAAA;EACf,OAAA;EACA,OAAA,GAAU,cAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBV,UAAA;AAAA;AAAA,i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