@copilotkit/react-core 2.0.0-rc.7 → 2.0.0-rc.8
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/{MarkdownRendererContext-B4Us6mwL.d.cts → MarkdownRendererContext-DAuVISwv.d.cts} +14 -30
- package/dist/MarkdownRendererContext-DAuVISwv.d.cts.map +1 -0
- package/dist/{MarkdownRendererContext-CRKFzsEB.d.mts → MarkdownRendererContext-XWC2OXD5.d.mts} +15 -31
- package/dist/MarkdownRendererContext-XWC2OXD5.d.mts.map +1 -0
- package/dist/{MarkdownSurfaces-Bd--93O1.mjs → MarkdownSurfaces-BXaxgpm_.mjs} +91 -74
- package/dist/MarkdownSurfaces-BXaxgpm_.mjs.map +1 -0
- package/dist/{MarkdownSurfaces-S4wfUl3J.cjs → MarkdownSurfaces-DQZM4lSI.cjs} +96 -73
- package/dist/MarkdownSurfaces-DQZM4lSI.cjs.map +1 -0
- package/dist/context.cjs +20 -17
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +38 -98
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.mts +38 -98
- package/dist/context.d.mts.map +1 -1
- package/dist/context.mjs +20 -17
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui.cjs +35 -15
- package/dist/generative-ui.cjs.map +1 -1
- package/dist/generative-ui.d.cts +9 -9
- package/dist/generative-ui.d.mts +9 -9
- package/dist/generative-ui.mjs +35 -15
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/headless.cjs +50 -76
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +78 -253
- package/dist/headless.d.cts.map +1 -1
- package/dist/headless.d.mts +56 -202
- package/dist/headless.d.mts.map +1 -1
- package/dist/headless.mjs +43 -74
- package/dist/headless.mjs.map +1 -1
- package/dist/index.cjs +664 -958
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +168 -472
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +168 -472
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +443 -949
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +754 -1029
- package/dist/index.umd.js.map +1 -1
- package/package.json +9 -10
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
- package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
- package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
package/dist/headless.d.mts
CHANGED
|
@@ -1,59 +1,13 @@
|
|
|
1
1
|
import React$1, { ComponentType, ReactNode } from "react";
|
|
2
2
|
import { InferSchemaOutput, StandardSchemaV1 } from "@copilotkit/shared";
|
|
3
|
-
import { DynamicSuggestionsConfig, FrontendTool, StaticSuggestionsConfig, Suggestion,
|
|
4
|
-
import { AbstractAgent, Interrupt, ResumeEntry, ResumeStatus
|
|
3
|
+
import { CopilotChatDefaultLabels, CopilotChatLabels, CopilotChatLabels as CopilotChatLabels$1, DynamicSuggestionsConfig, FrontendTool, HumanInTheLoopRenderProps, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, StaticSuggestionsConfig, Suggestion, ToolCallRenderProps, ToolCallRendererDef } from "@copilotkit/core";
|
|
4
|
+
import { AbstractAgent, Interrupt, ResumeEntry, ResumeStatus } from "@ag-ui/client";
|
|
5
5
|
import { AgentCapabilities, ToolCall, ToolMessage } from "@ag-ui/core";
|
|
6
6
|
import { CopilotKitCoreReact, CopilotKitCoreReactConfig, useCopilotKit } from "@copilotkit/react-core/context";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/CopilotChatConfigurationProvider.d.ts
|
|
9
|
-
declare const CopilotChatDefaultLabels: {
|
|
10
|
-
chatInputPlaceholder: string;
|
|
11
|
-
chatInputToolbarStartTranscribeButtonLabel: string;
|
|
12
|
-
chatInputToolbarCancelTranscribeButtonLabel: string;
|
|
13
|
-
chatInputToolbarFinishTranscribeButtonLabel: string;
|
|
14
|
-
chatInputToolbarAddButtonLabel: string;
|
|
15
|
-
chatInputToolbarToolsButtonLabel: string;
|
|
16
|
-
chatInputToolbarSendButtonLabel: string;
|
|
17
|
-
chatInputToolbarStopButtonLabel: string;
|
|
18
|
-
assistantMessageToolbarCopyCodeLabel: string;
|
|
19
|
-
assistantMessageToolbarCopyCodeCopiedLabel: string;
|
|
20
|
-
assistantMessageToolbarCopyMessageLabel: string;
|
|
21
|
-
assistantMessageToolbarInspectorLabel: string;
|
|
22
|
-
assistantMessageToolbarInspectorDescription: string;
|
|
23
|
-
assistantMessageToolbarInspectorLocalOnlyLabel: string;
|
|
24
|
-
assistantMessageToolbarInspectorLocalOnlyDescription: string;
|
|
25
|
-
assistantMessageToolbarInspectorTitle: string;
|
|
26
|
-
assistantMessageToolbarInspectorHideLabel: string;
|
|
27
|
-
assistantMessageToolbarInspectorHideDescription: string;
|
|
28
|
-
assistantMessageToolbarThumbsUpLabel: string;
|
|
29
|
-
assistantMessageToolbarThumbsDownLabel: string;
|
|
30
|
-
assistantMessageFeedbackCommentPlaceholder: string;
|
|
31
|
-
assistantMessageFeedbackCommentSubmitLabel: string;
|
|
32
|
-
assistantMessageToolbarReadAloudLabel: string;
|
|
33
|
-
assistantMessageToolbarRegenerateLabel: string;
|
|
34
|
-
userMessageToolbarCopyMessageLabel: string;
|
|
35
|
-
userMessageToolbarEditMessageLabel: string;
|
|
36
|
-
userMessageToolbarPreviousBranchLabel: string;
|
|
37
|
-
userMessageToolbarNextBranchLabel: string;
|
|
38
|
-
chatDisclaimerText: string;
|
|
39
|
-
chatToggleOpenLabel: string;
|
|
40
|
-
chatToggleCloseLabel: string;
|
|
41
|
-
chatScrollToBottomLabel: string;
|
|
42
|
-
modalHeaderTitle: string;
|
|
43
|
-
welcomeMessageText: string;
|
|
44
|
-
reasoningMessageThinkingLabel: string;
|
|
45
|
-
chatInputSlashMenuLabel: string;
|
|
46
|
-
chatInputSlashMenuEmptyText: string;
|
|
47
|
-
attachmentRemoveButtonLabel: string;
|
|
48
|
-
attachmentPlayVideoButtonLabel: string;
|
|
49
|
-
attachmentPreviewCloseButtonLabel: string;
|
|
50
|
-
modalHeaderCloseButtonLabel: string;
|
|
51
|
-
modalHeaderThreadsButtonLabel: string;
|
|
52
|
-
sidebarLabel: string;
|
|
53
|
-
};
|
|
54
|
-
type CopilotChatLabels = typeof CopilotChatDefaultLabels;
|
|
55
9
|
interface CopilotChatConfigurationValue {
|
|
56
|
-
labels: CopilotChatLabels;
|
|
10
|
+
labels: CopilotChatLabels$1;
|
|
57
11
|
agentId: string;
|
|
58
12
|
threadId: string;
|
|
59
13
|
isModalOpen: boolean;
|
|
@@ -129,7 +83,7 @@ interface CopilotChatConfigurationValue {
|
|
|
129
83
|
}
|
|
130
84
|
interface CopilotChatConfigurationProviderProps {
|
|
131
85
|
children: ReactNode;
|
|
132
|
-
labels?: Partial<CopilotChatLabels>;
|
|
86
|
+
labels?: Partial<CopilotChatLabels$1>;
|
|
133
87
|
agentId?: string;
|
|
134
88
|
threadId?: string;
|
|
135
89
|
hasExplicitThreadId?: boolean;
|
|
@@ -282,45 +236,16 @@ declare function useAgent({
|
|
|
282
236
|
};
|
|
283
237
|
//#endregion
|
|
284
238
|
//#region src/types/react-tool-call-renderer.d.ts
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*/
|
|
296
|
-
agentId?: string;
|
|
297
|
-
/**
|
|
298
|
-
* Whether calls this renderer draws join the chat's tool-call groups (see
|
|
299
|
-
* `toolCallDisplay` on `CopilotChatMessageView`). CopilotKit's built-in card
|
|
300
|
-
* sets it; a renderer that leaves it unset always shows its calls on their
|
|
301
|
-
* own, since the chat can't tell what it draws (it may even draw nothing).
|
|
302
|
-
*/
|
|
303
|
-
group?: boolean;
|
|
304
|
-
render: React.ComponentType<{
|
|
305
|
-
name: string;
|
|
306
|
-
toolCallId: string;
|
|
307
|
-
args: Partial<T>;
|
|
308
|
-
status: ToolCallStatus.InProgress;
|
|
309
|
-
result: undefined;
|
|
310
|
-
} | {
|
|
311
|
-
name: string;
|
|
312
|
-
toolCallId: string;
|
|
313
|
-
args: T;
|
|
314
|
-
status: ToolCallStatus.Executing;
|
|
315
|
-
result: undefined;
|
|
316
|
-
} | {
|
|
317
|
-
name: string;
|
|
318
|
-
toolCallId: string;
|
|
319
|
-
args: T;
|
|
320
|
-
status: ToolCallStatus.Complete;
|
|
321
|
-
result: string;
|
|
322
|
-
}>;
|
|
323
|
-
}
|
|
239
|
+
/**
|
|
240
|
+
* A tool call renderer for React: a React component that draws one tool call
|
|
241
|
+
* in the chat. The component receives {@link ToolCallRenderProps}.
|
|
242
|
+
*
|
|
243
|
+
* Pass a list of these to `renderToolCalls` on `CopilotKitProvider`, or build
|
|
244
|
+
* one with `defineToolCallRenderer`.
|
|
245
|
+
*
|
|
246
|
+
* @typeParam T - The shape of the tool arguments.
|
|
247
|
+
*/
|
|
248
|
+
type ReactToolCallRenderer<T = unknown> = ToolCallRendererDef<T, React$1.ComponentType<ToolCallRenderProps<T>>>;
|
|
324
249
|
//#endregion
|
|
325
250
|
//#region src/types/frontend-tool.d.ts
|
|
326
251
|
type ReactFrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = FrontendTool<T> & {
|
|
@@ -328,6 +253,30 @@ type ReactFrontendTool<T extends Record<string, unknown> = Record<string, unknow
|
|
|
328
253
|
};
|
|
329
254
|
//#endregion
|
|
330
255
|
//#region src/hooks/use-frontend-tool.d.ts
|
|
256
|
+
/**
|
|
257
|
+
* Register a frontend tool while the component is mounted. The agent can
|
|
258
|
+
* call it, and its `render` component draws the call in the chat.
|
|
259
|
+
*
|
|
260
|
+
* A tool with the same name and agentId as a tool that is already registered
|
|
261
|
+
* (for example one from the provider's `tools`) overrides it while this
|
|
262
|
+
* component is mounted. When the component unmounts, the overridden tool is
|
|
263
|
+
* active again. The renderer stays registered after unmount, so past tool
|
|
264
|
+
* calls still render in the chat history.
|
|
265
|
+
*
|
|
266
|
+
* @param tool - The tool to register.
|
|
267
|
+
* @param deps - Extra values that re-register the tool when they change. Use
|
|
268
|
+
* it when the handler closes over a value that is not part of the tool.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```tsx
|
|
272
|
+
* useFrontendTool({
|
|
273
|
+
* name: "showWeather",
|
|
274
|
+
* description: "Show the weather for a city",
|
|
275
|
+
* parameters: z.object({ city: z.string() }),
|
|
276
|
+
* handler: async ({ city }) => `Sunny in ${city}`,
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
331
280
|
declare function useFrontendTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactFrontendTool<T>, deps?: ReadonlyArray<unknown>): void;
|
|
332
281
|
//#endregion
|
|
333
282
|
//#region src/hooks/use-frontend-tools.d.ts
|
|
@@ -341,8 +290,10 @@ declare function useFrontendTool<T extends Record<string, unknown> = Record<stri
|
|
|
341
290
|
*
|
|
342
291
|
* Tools are keyed by `name` plus `agentId`, the same as `useFrontendTool`. A
|
|
343
292
|
* tool that disappears from the array is unregistered on the next render, and
|
|
344
|
-
* every tool is unregistered on unmount.
|
|
345
|
-
*
|
|
293
|
+
* every tool is unregistered on unmount. A listed tool hides a tool with the
|
|
294
|
+
* same name and agentId (for example one from the provider's `tools`) until it
|
|
295
|
+
* is unregistered, and then the hidden tool is active again. Renderers stay
|
|
296
|
+
* registered after unmount so past tool calls still render in the chat history.
|
|
346
297
|
*
|
|
347
298
|
* @param tools - The tools to register. May be empty and may change length.
|
|
348
299
|
* @param deps - Extra dependencies that force re-registration, compared by
|
|
@@ -444,102 +395,24 @@ declare function useComponent<TSchema extends StandardSchemaV1<any, Record<strin
|
|
|
444
395
|
}, deps?: ReadonlyArray<unknown>): void;
|
|
445
396
|
//#endregion
|
|
446
397
|
//#region src/types/human-in-the-loop.d.ts
|
|
398
|
+
/**
|
|
399
|
+
* A human-in-the-loop tool for React. It has no handler: the agent waits until
|
|
400
|
+
* the `render` component calls `respond` with the user's answer.
|
|
401
|
+
*
|
|
402
|
+
* @typeParam T - The shape of the tool arguments.
|
|
403
|
+
*/
|
|
447
404
|
type ReactHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>> = Omit<FrontendTool<T>, "handler"> & {
|
|
448
405
|
/**
|
|
449
|
-
* Render the human-in-the-loop UI for this tool call.
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
* stable key for correlating this interrupt with runtime (sub)agent
|
|
455
|
-
* attribution — e.g. the `agentId` reported by `onToolExecutionStart`, or
|
|
456
|
-
* per-run attribution stamped on the event stream — so the UI can label
|
|
457
|
-
* the interrupt with the agent that actually raised it.
|
|
458
|
-
* - `agentId` — the agent this tool was *registered* to (the tool's own
|
|
459
|
-
* `agentId`), or `undefined` for an unscoped tool. This is the static
|
|
460
|
-
* registration scope; it is NOT necessarily the runtime (sub)agent that
|
|
461
|
-
* raised the interrupt. For runtime attribution, correlate `toolCallId`
|
|
462
|
-
* with the event-stream/`onToolExecutionStart` agent id.
|
|
463
|
-
*/
|
|
464
|
-
render: React$1.ComponentType<{
|
|
465
|
-
name: string;
|
|
466
|
-
description: string;
|
|
467
|
-
toolCallId: string;
|
|
468
|
-
agentId?: string;
|
|
469
|
-
args: Partial<T>;
|
|
470
|
-
status: ToolCallStatus.InProgress;
|
|
471
|
-
result: undefined;
|
|
472
|
-
respond: undefined;
|
|
473
|
-
} | {
|
|
474
|
-
name: string;
|
|
475
|
-
description: string;
|
|
476
|
-
toolCallId: string;
|
|
477
|
-
agentId?: string;
|
|
478
|
-
args: T;
|
|
479
|
-
status: ToolCallStatus.Executing;
|
|
480
|
-
result: undefined;
|
|
481
|
-
respond: (result: unknown) => Promise<void>;
|
|
482
|
-
} | {
|
|
483
|
-
name: string;
|
|
484
|
-
description: string;
|
|
485
|
-
toolCallId: string;
|
|
486
|
-
agentId?: string;
|
|
487
|
-
args: T;
|
|
488
|
-
status: ToolCallStatus.Complete;
|
|
489
|
-
result: string;
|
|
490
|
-
respond: undefined;
|
|
491
|
-
}>;
|
|
406
|
+
* Render the human-in-the-loop UI for this tool call. The component
|
|
407
|
+
* receives {@link HumanInTheLoopRenderProps}, which also carry `toolCallId`
|
|
408
|
+
* and `agentId` for attribution.
|
|
409
|
+
*/
|
|
410
|
+
render: React$1.ComponentType<HumanInTheLoopRenderProps<T>>;
|
|
492
411
|
};
|
|
493
412
|
//#endregion
|
|
494
413
|
//#region src/hooks/use-human-in-the-loop.d.ts
|
|
495
414
|
declare function useHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>): void;
|
|
496
415
|
//#endregion
|
|
497
|
-
//#region src/types/interrupt.d.ts
|
|
498
|
-
/** Legacy custom-event interrupt payload (agent emits a custom `on_interrupt` event). */
|
|
499
|
-
interface InterruptEvent<TValue = unknown> {
|
|
500
|
-
name: string;
|
|
501
|
-
value: TValue;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Resolve the agent with user input for an interrupt.
|
|
505
|
-
*
|
|
506
|
-
* - Standard interrupts: records `{ status: "resolved", payload }` for the target
|
|
507
|
-
* interrupt (defaults to the primary one). Resumes once every open interrupt is
|
|
508
|
-
* addressed; returns the resume run result, or `void` while still awaiting others.
|
|
509
|
-
* - Legacy interrupts: resumes immediately via `command.resume = payload`.
|
|
510
|
-
*/
|
|
511
|
-
type InterruptResolveFn = (payload?: unknown, interruptId?: string) => Promise<RunAgentResult | void>;
|
|
512
|
-
/**
|
|
513
|
-
* Cancel an interrupt.
|
|
514
|
-
*
|
|
515
|
-
* - Standard interrupts: records `{ status: "cancelled" }` for the target interrupt
|
|
516
|
-
* (defaults to the primary one), then resumes once all are addressed.
|
|
517
|
-
* - Legacy interrupts: dismisses the pending interrupt without resuming.
|
|
518
|
-
*/
|
|
519
|
-
type InterruptCancelFn = (interruptId?: string) => Promise<RunAgentResult | void>;
|
|
520
|
-
interface InterruptHandlerProps<TValue = unknown> {
|
|
521
|
-
/**
|
|
522
|
-
* Legacy event shape (`{ name, value }`). Always present for back-compat: for
|
|
523
|
-
* standard interrupts, `value` is the primary `Interrupt` and `name` is `"on_interrupt"`.
|
|
524
|
-
* Prefer `interrupt` / `interrupts` for standard interrupts.
|
|
525
|
-
*/
|
|
526
|
-
event: InterruptEvent<TValue>;
|
|
527
|
-
/** Primary standard interrupt (`interrupts[0]`), or `null` for legacy interrupts. */
|
|
528
|
-
interrupt: Interrupt | null;
|
|
529
|
-
/** All open standard interrupts (empty array for legacy interrupts). */
|
|
530
|
-
interrupts: Interrupt[];
|
|
531
|
-
resolve: InterruptResolveFn;
|
|
532
|
-
cancel: InterruptCancelFn;
|
|
533
|
-
}
|
|
534
|
-
interface InterruptRenderProps<TValue = unknown, TResult = unknown> {
|
|
535
|
-
event: InterruptEvent<TValue>;
|
|
536
|
-
interrupt: Interrupt | null;
|
|
537
|
-
interrupts: Interrupt[];
|
|
538
|
-
result: TResult;
|
|
539
|
-
resolve: InterruptResolveFn;
|
|
540
|
-
cancel: InterruptCancelFn;
|
|
541
|
-
}
|
|
542
|
-
//#endregion
|
|
543
416
|
//#region src/hooks/use-interrupt.d.ts
|
|
544
417
|
type InterruptHandlerFn<TValue, TResult> = (props: InterruptHandlerProps<TValue>) => TResult | PromiseLike<TResult>;
|
|
545
418
|
type InterruptResultFromHandler<THandler> = THandler extends ((...args: never[]) => infer TResult) ? TResult extends PromiseLike<infer TResolved> ? TResolved | null : TResult | null : null;
|
|
@@ -953,37 +826,18 @@ declare function useRenderToolCall(): ({
|
|
|
953
826
|
* - Accepts a single object whose keys match ReactToolCallRenderer's fields: { name, args, render, agentId? }.
|
|
954
827
|
* - Derives `args` type from the provided schema (any Standard Schema V1 compatible library).
|
|
955
828
|
* - Ensures the render function param type exactly matches ReactToolCallRenderer<T>["render"]'s param.
|
|
956
|
-
* - For wildcard tools (name: "*"), args is optional and defaults to
|
|
829
|
+
* - For wildcard tools (name: "*"), args is optional and defaults to a schema that accepts any value.
|
|
957
830
|
*/
|
|
958
|
-
type RenderProps<T> = {
|
|
959
|
-
name: string;
|
|
960
|
-
toolCallId: string;
|
|
961
|
-
args: Partial<T>;
|
|
962
|
-
status: ToolCallStatus.InProgress;
|
|
963
|
-
result: undefined;
|
|
964
|
-
} | {
|
|
965
|
-
name: string;
|
|
966
|
-
toolCallId: string;
|
|
967
|
-
args: T;
|
|
968
|
-
status: ToolCallStatus.Executing;
|
|
969
|
-
result: undefined;
|
|
970
|
-
} | {
|
|
971
|
-
name: string;
|
|
972
|
-
toolCallId: string;
|
|
973
|
-
args: T;
|
|
974
|
-
status: ToolCallStatus.Complete;
|
|
975
|
-
result: string;
|
|
976
|
-
};
|
|
977
831
|
declare function defineToolCallRenderer(def: {
|
|
978
832
|
name: "*";
|
|
979
|
-
render: (props:
|
|
833
|
+
render: (props: ToolCallRenderProps<any>) => React$1.ReactElement | null;
|
|
980
834
|
agentId?: string;
|
|
981
835
|
group?: boolean;
|
|
982
836
|
}): ReactToolCallRenderer<any>;
|
|
983
837
|
declare function defineToolCallRenderer<S extends StandardSchemaV1>(def: {
|
|
984
838
|
name: string;
|
|
985
839
|
args: S;
|
|
986
|
-
render: (props:
|
|
840
|
+
render: (props: ToolCallRenderProps<InferSchemaOutput<S>>) => React$1.ReactElement | null;
|
|
987
841
|
agentId?: string;
|
|
988
842
|
group?: boolean;
|
|
989
843
|
}): ReactToolCallRenderer<InferSchemaOutput<S>>;
|
package/dist/headless.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.d.mts","names":[],"sources":["../src/providers/CopilotChatConfigurationProvider.tsx","../src/hooks/use-agent.tsx","../src/types/react-tool-call-renderer.ts","../src/types/frontend-tool.ts","../src/hooks/use-frontend-tool.tsx","../src/hooks/use-frontend-tools.tsx","../src/hooks/use-component.tsx","../src/types/human-in-the-loop.ts","../src/hooks/use-human-in-the-loop.tsx","../src/
|
|
1
|
+
{"version":3,"file":"headless.d.mts","names":[],"sources":["../src/providers/CopilotChatConfigurationProvider.tsx","../src/hooks/use-agent.tsx","../src/types/react-tool-call-renderer.ts","../src/types/frontend-tool.ts","../src/hooks/use-frontend-tool.tsx","../src/hooks/use-frontend-tools.tsx","../src/hooks/use-component.tsx","../src/types/human-in-the-loop.ts","../src/hooks/use-human-in-the-loop.tsx","../src/hooks/use-interrupt.tsx","../src/hooks/use-suggestions.tsx","../src/hooks/use-configure-suggestions.tsx","../src/hooks/use-agent-context.tsx","../src/hooks/use-threads.tsx","../src/hooks/use-render-tool.tsx","../src/hooks/use-render-tool-call.tsx","../src/types/defineToolCallRenderer.ts","../src/hooks/use-capabilities.tsx"],"mappings":";;;;;;;;UAgDiB,6BAAA;EACf,MAAA,EAAQ,mBAAA;EACR,OAAA;EACA,QAAA;EACA,WAAA;EACA,YAAA,GAAe,IAAA;EAL6B;;;;;EAW5C,UAAA;EARA;;;;;EAcA,aAAA,GAAgB,IAAA;EAAA;;;;;EAMhB,gBAAA;EAwBA;;;;;;;EAhBA,cAAA;EAuDe;;;;;;;;;;EA5Cf,oBAAA,GAAuB,UAAA,GAAa,IAAA;EAKpC,mBAAA;EAyCiB;;;;;;;AAanB;;;;;;;;;AAgXA;EApZE,iBAAA,GACE,QAAA,UACA,OAAA;IAAY,QAAA;EAAA;EAmZmB;;;;AC1fnC;;;;;EDkHE,cAAA;AAAA;AAAA,UAQe,qCAAA;EACf,QAAA,EAAU,SAAA;EACV,MAAA,GAAS,OAAA,CAAQ,mBAAA;EACjB,OAAA;EACA,QAAA;EAMA,mBAAA;EACA,kBAAA;AAAA;AAAA,cAIW,gCAAA,EAAkC,OAAA,CAAM,EAAA,CACnD,qCAAA;AAAA,cA+WW,2BAAA,QACP,6BAAA;;;aC1fM,cAAA;EACV,iBAAA;EACA,cAAA;EACA,kBAAA;AAAA;AAAA,UASQ,iBAAA;EACR,OAAA,G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AA,WdyEF;EcvEE,KAAA;AAAA,GAEF,IAAA,GAAO,aAAA;AdyET;;;;;;;;;AAgXA;;;;;;;;ACzfA;;;;;;;;;AAIC;ADqID,iBc3CgB,aAAA,WAAwB,gBAAA,CAAA,CACtC,MAAA;EACE,IAAA;EACA,UAAA,EAAY,CAAA;EACZ,MAAA,GAAS,KAAA,EAAO,eAAA,CAAgB,CAAA,MAAO,KAAA,CAAM,YAAA;EAC7C,OAAA,Wb/DF;EaiEE,KAAA;AAAA,GAEF,IAAA,GAAO,aAAA;;;UC/FQ,sBAAA;EACf,QAAA,EAAU,QAAA;EACV,WAAA,GAAc,WAAA;AAAA;;;;;;;iBA0KA,iBAAA,CAAA;EAAiB,QAAA;EAAA;AAAA,GAsB1B,sBAAA,KAAyB,OAAA,CAAM,YAAA;;;;;;;AftKtC;;;iBgBlCgB,sBAAA,CAAuB,GAAA;EACrC,IAAA;EACA,MAAA,GAAS,KAAA,EAAO,mBAAA,UAA6B,OAAA,CAAM,YAAA;EACnD,OAAA;EACA,KAAA;AAAA,IACE,qBAAA;AAAA,iBAGY,sBAAA,WAAiC,gBAAA,CAAA,CAAkB,GAAA;EACjE,IAAA;EACA,IAAA,EAAM,CAAA;EACN,MAAA,GACE,KAAA,EAAO,mBAAA,CAAoB,iBAAA,CAAkB,CAAA,OAC1C,OAAA,CAAM,YAAA;EACX,OAAA;EACA,KAAA;AAAA,IACE,qBAAA,CAAsB,iBAAA,CAAkB,CAAA;;;;;;;;;;AhBkB5C;;;;;;iBiBhCgB,eAAA,CACd,OAAA,YACC,iBAAA"}
|
package/dist/headless.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { CopilotKitContext, CopilotKitCoreReact, useCopilotKit, useCopilotKit as useCopilotKit$1, useDefaultAgentId } from "@copilotkit/react-core/context";
|
|
2
2
|
import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { DEFAULT_AGENT_ID, partialJSONParse, randomUUID } from "@copilotkit/shared";
|
|
3
|
+
import { DEFAULT_AGENT_ID, partialJSONParse, randomUUID, ɵanySchema } from "@copilotkit/shared";
|
|
4
|
+
import { CopilotChatDefaultLabels, CopilotChatDefaultLabels as CopilotChatDefaultLabels$1, CopilotKitCoreRuntimeConnectionStatus, INTERRUPT_EVENT_NAME, ProxiedCopilotRuntimeAgent, ToolCallStatus, ɵInterruptState, ɵclearAgentInterruptState, ɵcreateThreadStore, ɵgetAgentInterruptState, ɵisHttpAgent, ɵresolveToolCallRenderer, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
4
5
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
-
import { CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, ɵInterruptState, ɵclearAgentInterruptState, ɵcreateThreadStore, ɵgetAgentInterruptState, ɵisHttpAgent, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
6
6
|
import { randomUUID as randomUUID$1 } from "@ag-ui/client";
|
|
7
|
-
import { z } from "zod";
|
|
8
7
|
import { contentToText } from "@ag-ui/core";
|
|
9
8
|
|
|
10
9
|
//#region src/lib/shallow-stable-ref.ts
|
|
@@ -50,51 +49,6 @@ function useShallowStableRef(value) {
|
|
|
50
49
|
|
|
51
50
|
//#endregion
|
|
52
51
|
//#region src/providers/CopilotChatConfigurationProvider.tsx
|
|
53
|
-
const CopilotChatDefaultLabels = {
|
|
54
|
-
chatInputPlaceholder: "Type a message...",
|
|
55
|
-
chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
|
|
56
|
-
chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
|
|
57
|
-
chatInputToolbarFinishTranscribeButtonLabel: "Finish",
|
|
58
|
-
chatInputToolbarAddButtonLabel: "Add attachments",
|
|
59
|
-
chatInputToolbarToolsButtonLabel: "Tools",
|
|
60
|
-
chatInputToolbarSendButtonLabel: "Send message",
|
|
61
|
-
chatInputToolbarStopButtonLabel: "Stop",
|
|
62
|
-
assistantMessageToolbarCopyCodeLabel: "Copy",
|
|
63
|
-
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
64
|
-
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
65
|
-
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
66
|
-
assistantMessageToolbarInspectorDescription: "Open this message in the Inspector",
|
|
67
|
-
assistantMessageToolbarInspectorLocalOnlyLabel: "Local only",
|
|
68
|
-
assistantMessageToolbarInspectorLocalOnlyDescription: "Only visible on localhost or loopback hosts in development. Never shown in production.",
|
|
69
|
-
assistantMessageToolbarInspectorTitle: "CopilotKit Inspector",
|
|
70
|
-
assistantMessageToolbarInspectorHideLabel: "Hide this icon",
|
|
71
|
-
assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
|
|
72
|
-
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
73
|
-
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
74
|
-
assistantMessageFeedbackCommentPlaceholder: "Add a comment (optional)",
|
|
75
|
-
assistantMessageFeedbackCommentSubmitLabel: "Send comment",
|
|
76
|
-
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
77
|
-
assistantMessageToolbarRegenerateLabel: "Regenerate",
|
|
78
|
-
userMessageToolbarCopyMessageLabel: "Copy",
|
|
79
|
-
userMessageToolbarEditMessageLabel: "Edit",
|
|
80
|
-
userMessageToolbarPreviousBranchLabel: "Previous branch",
|
|
81
|
-
userMessageToolbarNextBranchLabel: "Next branch",
|
|
82
|
-
chatDisclaimerText: "AI can make mistakes. Please verify important information.",
|
|
83
|
-
chatToggleOpenLabel: "Open chat",
|
|
84
|
-
chatToggleCloseLabel: "Close chat",
|
|
85
|
-
chatScrollToBottomLabel: "Scroll to bottom",
|
|
86
|
-
modalHeaderTitle: "CopilotKit Chat",
|
|
87
|
-
welcomeMessageText: "How can I help you today?",
|
|
88
|
-
reasoningMessageThinkingLabel: "Thinking…",
|
|
89
|
-
chatInputSlashMenuLabel: "Slash commands",
|
|
90
|
-
chatInputSlashMenuEmptyText: "No commands found",
|
|
91
|
-
attachmentRemoveButtonLabel: "Remove attachment",
|
|
92
|
-
attachmentPlayVideoButtonLabel: "Play video",
|
|
93
|
-
attachmentPreviewCloseButtonLabel: "Close preview",
|
|
94
|
-
modalHeaderCloseButtonLabel: "Close",
|
|
95
|
-
modalHeaderThreadsButtonLabel: "Open threads",
|
|
96
|
-
sidebarLabel: "Copilot chat sidebar"
|
|
97
|
-
};
|
|
98
52
|
/**
|
|
99
53
|
* Mobile breakpoint below which the chat modal and the thread-list drawer are
|
|
100
54
|
* mutually exclusive. At or above this width both surfaces may coexist. This
|
|
@@ -119,7 +73,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
119
73
|
const parentConfig = useContext(CopilotChatConfiguration);
|
|
120
74
|
const stableLabels = useShallowStableRef(labels);
|
|
121
75
|
const mergedLabels = useMemo(() => ({
|
|
122
|
-
...CopilotChatDefaultLabels,
|
|
76
|
+
...CopilotChatDefaultLabels$1,
|
|
123
77
|
...parentConfig?.labels,
|
|
124
78
|
...stableLabels
|
|
125
79
|
}), [stableLabels, parentConfig?.labels]);
|
|
@@ -626,6 +580,30 @@ function useDepsVersion(deps) {
|
|
|
626
580
|
|
|
627
581
|
//#endregion
|
|
628
582
|
//#region src/hooks/use-frontend-tool.tsx
|
|
583
|
+
/**
|
|
584
|
+
* Register a frontend tool while the component is mounted. The agent can
|
|
585
|
+
* call it, and its `render` component draws the call in the chat.
|
|
586
|
+
*
|
|
587
|
+
* A tool with the same name and agentId as a tool that is already registered
|
|
588
|
+
* (for example one from the provider's `tools`) overrides it while this
|
|
589
|
+
* component is mounted. When the component unmounts, the overridden tool is
|
|
590
|
+
* active again. The renderer stays registered after unmount, so past tool
|
|
591
|
+
* calls still render in the chat history.
|
|
592
|
+
*
|
|
593
|
+
* @param tool - The tool to register.
|
|
594
|
+
* @param deps - Extra values that re-register the tool when they change. Use
|
|
595
|
+
* it when the handler closes over a value that is not part of the tool.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```tsx
|
|
599
|
+
* useFrontendTool({
|
|
600
|
+
* name: "showWeather",
|
|
601
|
+
* description: "Show the weather for a city",
|
|
602
|
+
* parameters: z.object({ city: z.string() }),
|
|
603
|
+
* handler: async ({ city }) => `Sunny in ${city}`,
|
|
604
|
+
* });
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
629
607
|
function useFrontendTool(tool, deps) {
|
|
630
608
|
const { copilotkit } = useCopilotKit$1();
|
|
631
609
|
const depsVersion = useDepsVersion(deps);
|
|
@@ -634,11 +612,8 @@ function useFrontendTool(tool, deps) {
|
|
|
634
612
|
if (copilotkit.getTool({
|
|
635
613
|
toolName: name,
|
|
636
614
|
agentId: tool.agentId
|
|
637
|
-
})) {
|
|
638
|
-
|
|
639
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
640
|
-
}
|
|
641
|
-
copilotkit.addTool(tool);
|
|
615
|
+
})) console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
616
|
+
const unregister = copilotkit.addTool(tool);
|
|
642
617
|
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
643
618
|
name,
|
|
644
619
|
args: tool.parameters,
|
|
@@ -646,7 +621,7 @@ function useFrontendTool(tool, deps) {
|
|
|
646
621
|
render: tool.render
|
|
647
622
|
});
|
|
648
623
|
return () => {
|
|
649
|
-
|
|
624
|
+
unregister();
|
|
650
625
|
};
|
|
651
626
|
}, [
|
|
652
627
|
tool.name,
|
|
@@ -671,8 +646,10 @@ const EMPTY_TOOLS = [];
|
|
|
671
646
|
*
|
|
672
647
|
* Tools are keyed by `name` plus `agentId`, the same as `useFrontendTool`. A
|
|
673
648
|
* tool that disappears from the array is unregistered on the next render, and
|
|
674
|
-
* every tool is unregistered on unmount.
|
|
675
|
-
*
|
|
649
|
+
* every tool is unregistered on unmount. A listed tool hides a tool with the
|
|
650
|
+
* same name and agentId (for example one from the provider's `tools`) until it
|
|
651
|
+
* is unregistered, and then the hidden tool is active again. Renderers stay
|
|
652
|
+
* registered after unmount so past tool calls still render in the chat history.
|
|
676
653
|
*
|
|
677
654
|
* @param tools - The tools to register. May be empty and may change length.
|
|
678
655
|
* @param deps - Extra dependencies that force re-registration, compared by
|
|
@@ -722,15 +699,13 @@ function useFrontendTools(tools, deps) {
|
|
|
722
699
|
deduped.set(key, tool);
|
|
723
700
|
}
|
|
724
701
|
const registered = [...deduped.values()];
|
|
702
|
+
const unregisters = [];
|
|
725
703
|
for (const tool of registered) {
|
|
726
704
|
if (copilotkit.getTool({
|
|
727
705
|
toolName: tool.name,
|
|
728
706
|
agentId: tool.agentId
|
|
729
|
-
})) {
|
|
730
|
-
|
|
731
|
-
copilotkit.removeTool(tool.name, tool.agentId);
|
|
732
|
-
}
|
|
733
|
-
copilotkit.addTool(tool);
|
|
707
|
+
})) console.warn(`Tool '${tool.name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
708
|
+
unregisters.push(copilotkit.addTool(tool));
|
|
734
709
|
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
735
710
|
name: tool.name,
|
|
736
711
|
args: tool.parameters,
|
|
@@ -739,7 +714,7 @@ function useFrontendTools(tools, deps) {
|
|
|
739
714
|
});
|
|
740
715
|
}
|
|
741
716
|
return () => {
|
|
742
|
-
for (const
|
|
717
|
+
for (const unregister of unregisters) unregister();
|
|
743
718
|
};
|
|
744
719
|
}, [
|
|
745
720
|
JSON.stringify(toolList.map((tool) => [
|
|
@@ -915,11 +890,6 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
915
890
|
]);
|
|
916
891
|
}
|
|
917
892
|
|
|
918
|
-
//#endregion
|
|
919
|
-
//#region src/types/interrupt.ts
|
|
920
|
-
/** Name of the legacy custom event agents emit to signal an interrupt. */
|
|
921
|
-
const INTERRUPT_EVENT_NAME = "on_interrupt";
|
|
922
|
-
|
|
923
893
|
//#endregion
|
|
924
894
|
//#region src/hooks/use-interrupt.tsx
|
|
925
895
|
/** Recognize thenables returned by interrupt preprocessing handlers. */
|
|
@@ -1635,7 +1605,7 @@ function useThreads({ agentId, includeArchived, limit, enabled = true }) {
|
|
|
1635
1605
|
//#endregion
|
|
1636
1606
|
//#region src/types/defineToolCallRenderer.ts
|
|
1637
1607
|
function defineToolCallRenderer(def) {
|
|
1638
|
-
const argsSchema = def.name === "*" && !def.args ?
|
|
1608
|
+
const argsSchema = def.name === "*" && !def.args ? ɵanySchema : def.args;
|
|
1639
1609
|
return {
|
|
1640
1610
|
name: def.name,
|
|
1641
1611
|
args: argsSchema,
|
|
@@ -1813,18 +1783,17 @@ function useRenderToolCall() {
|
|
|
1813
1783
|
const warnedToolNames = useRef(/* @__PURE__ */ new Set());
|
|
1814
1784
|
const renderToolCalls = useToolCallRenderers();
|
|
1815
1785
|
const renderToolCall = useCallback(({ toolCall, toolMessage }) => {
|
|
1816
|
-
const
|
|
1817
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1786
|
+
const renderConfig = ɵresolveToolCallRenderer(renderToolCalls, toolCall.function.name, agentId);
|
|
1818
1787
|
if (!renderConfig) {
|
|
1819
1788
|
if (IS_DEVELOPMENT) unrenderedToolNames.current.add(toolCall.function.name);
|
|
1820
1789
|
return null;
|
|
1821
1790
|
}
|
|
1822
|
-
const
|
|
1791
|
+
const isExecuting = executingToolCallIds.has(toolCall.id);
|
|
1823
1792
|
return /* @__PURE__ */ jsx(ToolCallRenderer, {
|
|
1824
1793
|
toolCall,
|
|
1825
1794
|
toolMessage,
|
|
1826
|
-
RenderComponent,
|
|
1827
|
-
isExecuting
|
|
1795
|
+
RenderComponent: renderConfig.render,
|
|
1796
|
+
isExecuting
|
|
1828
1797
|
}, toolCall.id);
|
|
1829
1798
|
}, [
|
|
1830
1799
|
renderToolCalls,
|