@copilotkit/react-core 1.59.3 → 1.59.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{copilotkit-D16eCFkt.d.cts → copilotkit-CtqalfG8.d.cts} +381 -58
- package/dist/copilotkit-CtqalfG8.d.cts.map +1 -0
- package/dist/{copilotkit-CEJz6krE.d.mts → copilotkit-D42EuTt0.d.mts} +381 -58
- package/dist/copilotkit-D42EuTt0.d.mts.map +1 -0
- package/dist/{copilotkit-BRNy5UvX.mjs → copilotkit-DoIlZQqa.mjs} +552 -124
- package/dist/copilotkit-DoIlZQqa.mjs.map +1 -0
- package/dist/{copilotkit-DhONbYmz.cjs → copilotkit-LdQ8w20l.cjs} +594 -124
- package/dist/copilotkit-LdQ8w20l.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/v2/index.cjs +8 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +558 -123
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/dist/copilotkit-BRNy5UvX.mjs.map +0 -1
- package/dist/copilotkit-CEJz6krE.d.mts.map +0 -1
- package/dist/copilotkit-D16eCFkt.d.cts.map +0 -1
- package/dist/copilotkit-DhONbYmz.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React$1 from "react";
|
|
2
2
|
import React, { createContext, forwardRef, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, ɵcreateThreadStore, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
3
|
+
import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, isRunCompletionAware, ɵcreateThreadStore, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
4
4
|
import { HttpAgent } from "@ag-ui/client";
|
|
5
5
|
import { extendTailwindMerge, twMerge } from "tailwind-merge";
|
|
6
6
|
import { ArrowUp, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, Copy, Edit, Loader2, MessageCircle, Mic, Play, Plus, RefreshCw, Square, ThumbsDown, ThumbsUp, Upload, Volume2, X } from "lucide-react";
|
|
@@ -4781,6 +4781,175 @@ function useThreads$1({ agentId, includeArchived, limit }) {
|
|
|
4781
4781
|
};
|
|
4782
4782
|
}
|
|
4783
4783
|
|
|
4784
|
+
//#endregion
|
|
4785
|
+
//#region src/v2/lib/record-annotation.ts
|
|
4786
|
+
/**
|
|
4787
|
+
* Low-level function that posts an arbitrary annotation to the CopilotKit
|
|
4788
|
+
* runtime's general annotation endpoint (`POST /annotate`).
|
|
4789
|
+
*
|
|
4790
|
+
* This is the single transport entry point for all annotation types. Higher-
|
|
4791
|
+
* level hooks (e.g. `useLearnFromUserAction`) build the `type`/`payload` pair
|
|
4792
|
+
* for their specific annotation shape and delegate the HTTP call here.
|
|
4793
|
+
*
|
|
4794
|
+
* The function uses the same transport as `useLearnFromUserAction`:
|
|
4795
|
+
* - `runtimeUrl` from `copilotkit.runtimeUrl` (BFF proxies to the platform)
|
|
4796
|
+
* - `headers` from `copilotkit.headers` (customer auth forwarded to BFF)
|
|
4797
|
+
* - `clientEventId` auto-generated via `randomUUID()` when omitted
|
|
4798
|
+
* - `userId` is resolved server-side by the runtime; the client never sends it
|
|
4799
|
+
* - Errors propagate to the caller (fire-and-propagate, not fire-and-forget)
|
|
4800
|
+
*
|
|
4801
|
+
* @param args - Transport dependencies plus annotation fields.
|
|
4802
|
+
* @returns The platform result containing the annotation row `id` and a
|
|
4803
|
+
* `duplicate` flag.
|
|
4804
|
+
* @throws When the network request fails or the runtime returns a non-2xx
|
|
4805
|
+
* status. Callers that want fire-and-forget behavior should `.catch`
|
|
4806
|
+
* at the call site.
|
|
4807
|
+
*/
|
|
4808
|
+
async function recordAnnotation(args) {
|
|
4809
|
+
const { runtimeUrl, headers, type, payload, threadId, occurredAt } = args;
|
|
4810
|
+
const body = {
|
|
4811
|
+
type,
|
|
4812
|
+
threadId,
|
|
4813
|
+
clientEventId: args.clientEventId ?? randomUUID(),
|
|
4814
|
+
...payload !== void 0 ? { payload } : {},
|
|
4815
|
+
...occurredAt !== void 0 ? { occurredAt } : {}
|
|
4816
|
+
};
|
|
4817
|
+
const response = await fetch(`${runtimeUrl}/annotate`, {
|
|
4818
|
+
method: "POST",
|
|
4819
|
+
headers: {
|
|
4820
|
+
"Content-Type": "application/json",
|
|
4821
|
+
...headers
|
|
4822
|
+
},
|
|
4823
|
+
body: JSON.stringify(body)
|
|
4824
|
+
});
|
|
4825
|
+
if (!response.ok) {
|
|
4826
|
+
const text = await response.text().catch(() => "");
|
|
4827
|
+
throw new Error(`recordAnnotation: request failed (${response.status})${text ? `: ${text}` : ""}`);
|
|
4828
|
+
}
|
|
4829
|
+
const text = await response.text();
|
|
4830
|
+
if (!text) throw new Error(`recordAnnotation: runtime ${runtimeUrl}/annotate returned ${response.status} with an empty body`);
|
|
4831
|
+
try {
|
|
4832
|
+
return JSON.parse(text);
|
|
4833
|
+
} catch {
|
|
4834
|
+
throw new Error(`recordAnnotation: runtime ${runtimeUrl}/annotate returned a non-JSON body (status ${response.status})`);
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4837
|
+
|
|
4838
|
+
//#endregion
|
|
4839
|
+
//#region src/v2/hooks/use-learn-from-user-action.tsx
|
|
4840
|
+
/**
|
|
4841
|
+
* Record a user UI interaction in the Intelligence platform's user-actions
|
|
4842
|
+
* stream. The platform's auto-curated knowledge base agent reads these
|
|
4843
|
+
* (alongside finished agent runs) and writes free-form Obsidian-flavored
|
|
4844
|
+
* markdown to `/project`, where any agent in the same project can later
|
|
4845
|
+
* read it via the `copilotkit_knowledge_base_shell` MCP tool.
|
|
4846
|
+
*
|
|
4847
|
+
* The hook returns a stable function. Calling it issues a request to the
|
|
4848
|
+
* customer's CopilotKit runtime (`POST ${runtimeUrl}/annotate`), which
|
|
4849
|
+
* resolves the Intel user from the BFF's auth and forwards to the
|
|
4850
|
+
* platform — the Intel API key never reaches the browser.
|
|
4851
|
+
*
|
|
4852
|
+
* If `clientEventId` is omitted `recordAnnotation` generates a UUID per call,
|
|
4853
|
+
* so a naive double-call (e.g. React 18 strict-mode double-mount, or a retry
|
|
4854
|
+
* after a network blip on a fresh Promise) is naturally safe. Supply your
|
|
4855
|
+
* own key when a single semantic event must remain idempotent across
|
|
4856
|
+
* multiple `learnFromUserAction(...)` calls.
|
|
4857
|
+
*
|
|
4858
|
+
* @example
|
|
4859
|
+
* ```tsx
|
|
4860
|
+
* import { useLearnFromUserAction } from "@copilotkit/react-core";
|
|
4861
|
+
*
|
|
4862
|
+
* function SettingsPage({ threadId }) {
|
|
4863
|
+
* const learnFromUserAction = useLearnFromUserAction();
|
|
4864
|
+
*
|
|
4865
|
+
* const onRename = (oldName: string, newName: string) => {
|
|
4866
|
+
* void learnFromUserAction({
|
|
4867
|
+
* threadId,
|
|
4868
|
+
* title: "Renamed project",
|
|
4869
|
+
* data: { previous: { name: oldName }, next: { name: newName } },
|
|
4870
|
+
* });
|
|
4871
|
+
* };
|
|
4872
|
+
* }
|
|
4873
|
+
* ```
|
|
4874
|
+
*/
|
|
4875
|
+
function useLearnFromUserAction() {
|
|
4876
|
+
const { copilotkit } = useCopilotKit();
|
|
4877
|
+
return useCallback(async (input) => {
|
|
4878
|
+
const runtimeUrl = copilotkit.runtimeUrl;
|
|
4879
|
+
if (!runtimeUrl) throw new Error("useLearnFromUserAction: runtimeUrl is not configured. Set it on <CopilotKitProvider runtimeUrl=...>.");
|
|
4880
|
+
const payload = {
|
|
4881
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
4882
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
4883
|
+
...input.data !== void 0 ? { data: input.data } : {}
|
|
4884
|
+
};
|
|
4885
|
+
return recordAnnotation({
|
|
4886
|
+
runtimeUrl,
|
|
4887
|
+
headers: copilotkit.headers ?? {},
|
|
4888
|
+
type: "user_action",
|
|
4889
|
+
payload: Object.keys(payload).length > 0 ? payload : void 0,
|
|
4890
|
+
threadId: input.threadId,
|
|
4891
|
+
clientEventId: input.clientEventId,
|
|
4892
|
+
occurredAt: input.occurredAt
|
|
4893
|
+
});
|
|
4894
|
+
}, [copilotkit]);
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4897
|
+
//#endregion
|
|
4898
|
+
//#region src/v2/hooks/use-learn-from-user-action-in-current-thread.tsx
|
|
4899
|
+
/**
|
|
4900
|
+
* Record a user UI interaction against the **current chat's** thread. The
|
|
4901
|
+
* `threadId` is sourced from the surrounding
|
|
4902
|
+
* `<CopilotChatConfigurationProvider>` (the same provider `<CopilotChat>`,
|
|
4903
|
+
* `<CopilotSidebar>`, and friends set up), so callers in a chat-aware
|
|
4904
|
+
* subtree don't need to thread an id through manually.
|
|
4905
|
+
*
|
|
4906
|
+
* Throws on **call** (not on mount) when there is no chat-config provider
|
|
4907
|
+
* in scope — matches the "throw on call when runtimeUrl is missing"
|
|
4908
|
+
* behavior of {@link useLearnFromUserAction}. Mounting the hook in a branch
|
|
4909
|
+
* that never fires is harmless.
|
|
4910
|
+
*
|
|
4911
|
+
* The recorder does NOT accept a `threadId` override. If you need to
|
|
4912
|
+
* record against an explicit thread, use {@link useLearnFromUserAction}
|
|
4913
|
+
* directly — two hooks, two crisp contracts, no mode confusion.
|
|
4914
|
+
*
|
|
4915
|
+
* This hook always uses `config.threadId`, regardless of whether the
|
|
4916
|
+
* surrounding chat config minted it internally or received one from
|
|
4917
|
+
* the caller. Auto-minted threads simply mean the action lands under
|
|
4918
|
+
* a thread the platform never saw — the writer agent still distills
|
|
4919
|
+
* user-action-only threads (it does not require the thread to exist
|
|
4920
|
+
* in `cpki.threads`), so the loop keeps learning.
|
|
4921
|
+
*
|
|
4922
|
+
* @example
|
|
4923
|
+
* ```tsx
|
|
4924
|
+
* import { useLearnFromUserActionInCurrentThread } from "@copilotkit/react-core";
|
|
4925
|
+
*
|
|
4926
|
+
* function SettingsPanel() {
|
|
4927
|
+
* const learnFromUserAction = useLearnFromUserActionInCurrentThread();
|
|
4928
|
+
*
|
|
4929
|
+
* const onRename = (oldName: string, newName: string) => {
|
|
4930
|
+
* void learnFromUserAction({
|
|
4931
|
+
* title: "Renamed project",
|
|
4932
|
+
* data: { previous: { name: oldName }, next: { name: newName } },
|
|
4933
|
+
* });
|
|
4934
|
+
* };
|
|
4935
|
+
*
|
|
4936
|
+
* // ...
|
|
4937
|
+
* }
|
|
4938
|
+
* ```
|
|
4939
|
+
*/
|
|
4940
|
+
function useLearnFromUserActionInCurrentThread() {
|
|
4941
|
+
const config = useCopilotChatConfiguration();
|
|
4942
|
+
const learnFromUserAction = useLearnFromUserAction();
|
|
4943
|
+
return useCallback(async (input) => {
|
|
4944
|
+
const threadId = config?.threadId;
|
|
4945
|
+
if (!threadId) throw new Error("useLearnFromUserActionInCurrentThread: no CopilotChatConfigurationProvider in scope. Wrap the call site in <CopilotChat>, <CopilotSidebar>, or <CopilotChatConfigurationProvider>, or use `useLearnFromUserAction()` and pass `threadId` explicitly.");
|
|
4946
|
+
return learnFromUserAction({
|
|
4947
|
+
...input,
|
|
4948
|
+
threadId
|
|
4949
|
+
});
|
|
4950
|
+
}, [config?.threadId, learnFromUserAction]);
|
|
4951
|
+
}
|
|
4952
|
+
|
|
4784
4953
|
//#endregion
|
|
4785
4954
|
//#region src/v2/hooks/use-attachments.tsx
|
|
4786
4955
|
/**
|
|
@@ -4939,6 +5108,153 @@ function useAttachments({ config }) {
|
|
|
4939
5108
|
};
|
|
4940
5109
|
}
|
|
4941
5110
|
|
|
5111
|
+
//#endregion
|
|
5112
|
+
//#region src/v2/hooks/use-learning-containers.tsx
|
|
5113
|
+
/** The default learning containers value. Matches the backend default. */
|
|
5114
|
+
const DEFAULT_CONTAINERS = ["project"];
|
|
5115
|
+
/**
|
|
5116
|
+
* Declaratively keeps a thread's learning containers in sync by emitting
|
|
5117
|
+
* `set_learning_containers` annotations via the CopilotKit runtime annotate
|
|
5118
|
+
* endpoint (`POST ${runtimeUrl}/annotate`).
|
|
5119
|
+
*
|
|
5120
|
+
* **Emit rules:**
|
|
5121
|
+
* - On mount with `["project"]` (the backend default) → does NOT emit.
|
|
5122
|
+
* Absence of an annotation equals the default, so the round-trip is skipped.
|
|
5123
|
+
* - On mount with any other value → emits immediately.
|
|
5124
|
+
* - On any subsequent content change (including a switch back to
|
|
5125
|
+
* `["project"]`) → emits (a deliberate switch is always recorded).
|
|
5126
|
+
* - On unmount or threadId change → emits a reset to `["project"]`
|
|
5127
|
+
* so the backend is left in a clean state for the next consumer.
|
|
5128
|
+
* Changing `learningContainers` within the same thread does NOT reset the
|
|
5129
|
+
* thread; only the new value is emitted.
|
|
5130
|
+
*
|
|
5131
|
+
* Content-equality is evaluated via `JSON.stringify` so a fresh array literal
|
|
5132
|
+
* with the same items does NOT trigger a redundant emit.
|
|
5133
|
+
*
|
|
5134
|
+
* If `runtimeUrl` is absent, all emits are silently skipped.
|
|
5135
|
+
*
|
|
5136
|
+
* @example
|
|
5137
|
+
* ```tsx
|
|
5138
|
+
* function ThreadPane({ threadId, userScope }: Props) {
|
|
5139
|
+
* useLearningContainers({
|
|
5140
|
+
* threadId,
|
|
5141
|
+
* learningContainers: [userScope],
|
|
5142
|
+
* });
|
|
5143
|
+
* // ...
|
|
5144
|
+
* }
|
|
5145
|
+
* ```
|
|
5146
|
+
*/
|
|
5147
|
+
function useLearningContainers({ threadId, learningContainers }) {
|
|
5148
|
+
const { copilotkit } = useCopilotKit();
|
|
5149
|
+
/**
|
|
5150
|
+
* Tracks the last-synced container list so content-identical rerenders
|
|
5151
|
+
* (fresh array, same values) do not fire a redundant emit.
|
|
5152
|
+
* `null` = nothing synced yet (initial state or after a threadId reset).
|
|
5153
|
+
*/
|
|
5154
|
+
const lastSyncedRef = useRef(null);
|
|
5155
|
+
/** Guards the missing-runtimeUrl warning so it fires at most once per hook instance. */
|
|
5156
|
+
const warnedMissingUrlRef = useRef(false);
|
|
5157
|
+
const runtimeUrlRef = useRef(copilotkit.runtimeUrl);
|
|
5158
|
+
const headersRef = useRef(copilotkit.headers ?? {});
|
|
5159
|
+
runtimeUrlRef.current = copilotkit.runtimeUrl;
|
|
5160
|
+
headersRef.current = copilotkit.headers ?? {};
|
|
5161
|
+
const key = JSON.stringify(learningContainers);
|
|
5162
|
+
const defaultKey = JSON.stringify(DEFAULT_CONTAINERS);
|
|
5163
|
+
useEffect(() => {
|
|
5164
|
+
const runtimeUrl = copilotkit.runtimeUrl;
|
|
5165
|
+
const headers = copilotkit.headers ?? {};
|
|
5166
|
+
/**
|
|
5167
|
+
* Fire-and-forget emit; errors must not surface in render.
|
|
5168
|
+
* Failures are logged as warnings so they are diagnosable without
|
|
5169
|
+
* propagating into the React render cycle.
|
|
5170
|
+
*/
|
|
5171
|
+
const emit = (containers) => {
|
|
5172
|
+
if (!runtimeUrl) {
|
|
5173
|
+
if (!warnedMissingUrlRef.current) {
|
|
5174
|
+
warnedMissingUrlRef.current = true;
|
|
5175
|
+
console.warn("useLearningContainers: runtimeUrl not configured; learning-container sync disabled");
|
|
5176
|
+
}
|
|
5177
|
+
return;
|
|
5178
|
+
}
|
|
5179
|
+
recordAnnotation({
|
|
5180
|
+
runtimeUrl,
|
|
5181
|
+
headers,
|
|
5182
|
+
type: "set_learning_containers",
|
|
5183
|
+
payload: { containers },
|
|
5184
|
+
threadId
|
|
5185
|
+
}).catch((err) => {
|
|
5186
|
+
console.warn("useLearningContainers: failed to record set_learning_containers", err);
|
|
5187
|
+
});
|
|
5188
|
+
};
|
|
5189
|
+
if (lastSyncedRef.current === null) {
|
|
5190
|
+
if (key === defaultKey) {
|
|
5191
|
+
lastSyncedRef.current = learningContainers;
|
|
5192
|
+
return;
|
|
5193
|
+
}
|
|
5194
|
+
emit(learningContainers);
|
|
5195
|
+
lastSyncedRef.current = learningContainers;
|
|
5196
|
+
} else if (key !== JSON.stringify(lastSyncedRef.current)) {
|
|
5197
|
+
emit(learningContainers);
|
|
5198
|
+
lastSyncedRef.current = learningContainers;
|
|
5199
|
+
}
|
|
5200
|
+
}, [threadId, key]);
|
|
5201
|
+
useEffect(() => {
|
|
5202
|
+
const capturedThreadId = threadId;
|
|
5203
|
+
return () => {
|
|
5204
|
+
const capturedRuntimeUrl = runtimeUrlRef.current;
|
|
5205
|
+
const capturedHeaders = headersRef.current;
|
|
5206
|
+
if (capturedRuntimeUrl) recordAnnotation({
|
|
5207
|
+
runtimeUrl: capturedRuntimeUrl,
|
|
5208
|
+
headers: capturedHeaders,
|
|
5209
|
+
type: "set_learning_containers",
|
|
5210
|
+
payload: { containers: DEFAULT_CONTAINERS },
|
|
5211
|
+
threadId: capturedThreadId
|
|
5212
|
+
}).catch((err) => {
|
|
5213
|
+
console.warn("useLearningContainers: failed to record set_learning_containers", err);
|
|
5214
|
+
});
|
|
5215
|
+
lastSyncedRef.current = null;
|
|
5216
|
+
};
|
|
5217
|
+
}, [threadId]);
|
|
5218
|
+
}
|
|
5219
|
+
|
|
5220
|
+
//#endregion
|
|
5221
|
+
//#region src/v2/hooks/use-learning-containers-in-current-thread.tsx
|
|
5222
|
+
/**
|
|
5223
|
+
* Declaratively keeps the **current chat thread's** learning containers in
|
|
5224
|
+
* sync. The `threadId` is sourced from the surrounding
|
|
5225
|
+
* `<CopilotChatConfigurationProvider>` (the same provider `<CopilotChat>`,
|
|
5226
|
+
* `<CopilotSidebar>`, and friends set up), so callers in a chat-aware
|
|
5227
|
+
* subtree don't need to thread an id through manually.
|
|
5228
|
+
*
|
|
5229
|
+
* **Throws on render** when there is no chat-config provider in scope or
|
|
5230
|
+
* when the provider does not yet have an active `threadId`. Mount the hook
|
|
5231
|
+
* inside a subtree that is guaranteed to have a thread context.
|
|
5232
|
+
*
|
|
5233
|
+
* If you need to manage an explicit thread, use {@link useLearningContainers}
|
|
5234
|
+
* directly — two hooks, two crisp contracts, no mode confusion.
|
|
5235
|
+
*
|
|
5236
|
+
* @throws When no `CopilotChatConfigurationProvider` is in scope or when the
|
|
5237
|
+
* active `threadId` is absent/empty.
|
|
5238
|
+
*
|
|
5239
|
+
* @example
|
|
5240
|
+
* ```tsx
|
|
5241
|
+
* function ThreadPanel({ scope }: Props) {
|
|
5242
|
+
* useLearningContainersInCurrentThread({
|
|
5243
|
+
* learningContainers: [scope],
|
|
5244
|
+
* });
|
|
5245
|
+
* // ...
|
|
5246
|
+
* }
|
|
5247
|
+
* ```
|
|
5248
|
+
*/
|
|
5249
|
+
function useLearningContainersInCurrentThread({ learningContainers }) {
|
|
5250
|
+
const threadId = useCopilotChatConfiguration()?.threadId;
|
|
5251
|
+
if (!threadId) throw new Error("useLearningContainersInCurrentThread must be used within a thread context (no active threadId). Wrap the component in <CopilotChat>, <CopilotSidebar>, or <CopilotChatConfigurationProvider>, or use `useLearningContainers()` and pass `threadId` explicitly.");
|
|
5252
|
+
useLearningContainers({
|
|
5253
|
+
threadId,
|
|
5254
|
+
learningContainers
|
|
5255
|
+
});
|
|
5256
|
+
}
|
|
5257
|
+
|
|
4942
5258
|
//#endregion
|
|
4943
5259
|
//#region src/v2/components/chat/CopilotChatToolCallsView.tsx
|
|
4944
5260
|
function CopilotChatToolCallsView({ message, messages = [] }) {
|
|
@@ -5711,33 +6027,174 @@ CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
|
|
|
5711
6027
|
*/
|
|
5712
6028
|
const ScrollElementContext = React.createContext(null);
|
|
5713
6029
|
|
|
6030
|
+
//#endregion
|
|
6031
|
+
//#region src/v2/components/intelligence-indicator/IntelligenceIndicatorView.tsx
|
|
6032
|
+
/**
|
|
6033
|
+
* The presentational "CopilotKit Intelligence" face — the default
|
|
6034
|
+
* rendered by the {@link IntelligenceIndicator} brain and the default
|
|
6035
|
+
* value for the `intelligenceIndicator` slot.
|
|
6036
|
+
*
|
|
6037
|
+
* Single-element three-stage design:
|
|
6038
|
+
* 1. **In-progress.** Glassmorphism pill chrome around a 270° arc icon
|
|
6039
|
+
* and the label. The arc has a single continuous visible stroke
|
|
6040
|
+
* (one `stroke-dasharray` dash + one gap, summing to the path
|
|
6041
|
+
* length) and the whole SVG rotates — so the viewer sees one
|
|
6042
|
+
* C-shaped arc spinning around the visual center.
|
|
6043
|
+
* 2. **Icon morph (~250 ms).** On status flip the single icon path
|
|
6044
|
+
* interpolates from the arc to a checkmark via CSS `d:` while the
|
|
6045
|
+
* dashed stroke transitions to solid (filling in the gap that was
|
|
6046
|
+
* the spinner's open portion). The SVG rotation animation is
|
|
6047
|
+
* removed; the snap back to identity is masked by the simultaneous
|
|
6048
|
+
* shape change. Chrome and text stay at full opacity throughout.
|
|
6049
|
+
* 3. **Settle (~400 ms, starts at +250 ms).** Chrome (background,
|
|
6050
|
+
* border, shadow, backdrop-blur) fades to zero opacity. The label
|
|
6051
|
+
* and icon stroke color transitions from saturated purple to a
|
|
6052
|
+
* true-neutral gray at 0.8 alpha — no hue cast, reads as "settled
|
|
6053
|
+
* history metadata." The label simultaneously skews to ~10° (a
|
|
6054
|
+
* transform-based italic feel that interpolates smoothly with the
|
|
6055
|
+
* color, rather than the discrete `font-style: italic` snap that
|
|
6056
|
+
* would cause a layout pop). The label text stays put — only its
|
|
6057
|
+
* color and slant change — so there is no "bump" where the brand
|
|
6058
|
+
* text disappears and reappears.
|
|
6059
|
+
*
|
|
6060
|
+
* Hard sequence: stage 3 has a 250 ms transition-delay so it waits
|
|
6061
|
+
* for stage 2 to finish. Total settle time ~650 ms in production.
|
|
6062
|
+
*
|
|
6063
|
+
* Both shapes are 3-segment cubic Bézier paths with matched command
|
|
6064
|
+
* structure (one `M` plus three `C`s), which is what makes the d
|
|
6065
|
+
* morph interpolate as a continuous shape change rather than snapping.
|
|
6066
|
+
*
|
|
6067
|
+
* The label is identical in both states (default "CopilotKit
|
|
6068
|
+
* Intelligence"). The static check icon carries the "done" semantic;
|
|
6069
|
+
* the color + slant transition does the "settle" work without needing
|
|
6070
|
+
* any wording change.
|
|
6071
|
+
*
|
|
6072
|
+
* Customize via the `intelligenceIndicator` slot on `CopilotChat`:
|
|
6073
|
+
* a className string restyles the wrapper, a props object tweaks
|
|
6074
|
+
* the default (`{ label }`), and a component replaces it entirely
|
|
6075
|
+
* with full control over visuals and timing.
|
|
6076
|
+
*/
|
|
6077
|
+
function IntelligenceIndicatorView({ message, status, label, className, ...rest }) {
|
|
6078
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
6079
|
+
className: twMerge("cpk-intelligence-indicator", className),
|
|
6080
|
+
role: "status",
|
|
6081
|
+
"aria-live": "polite",
|
|
6082
|
+
"data-testid": `cpk-intelligence-indicator-${message.id}`,
|
|
6083
|
+
"data-status": status,
|
|
6084
|
+
title: label,
|
|
6085
|
+
...rest,
|
|
6086
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
6087
|
+
className: "cpk-intelligence-indicator__chrome",
|
|
6088
|
+
"aria-hidden": "true"
|
|
6089
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
6090
|
+
className: "cpk-intelligence-indicator__content",
|
|
6091
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
6092
|
+
className: "cpk-intelligence-indicator__icon",
|
|
6093
|
+
viewBox: "0 0 24 24",
|
|
6094
|
+
width: "14",
|
|
6095
|
+
height: "14",
|
|
6096
|
+
"aria-hidden": "true",
|
|
6097
|
+
children: /* @__PURE__ */ jsx("path", { className: "cpk-intelligence-indicator__icon-path" })
|
|
6098
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
6099
|
+
className: "cpk-intelligence-indicator__label",
|
|
6100
|
+
children: label
|
|
6101
|
+
})]
|
|
6102
|
+
})]
|
|
6103
|
+
});
|
|
6104
|
+
}
|
|
6105
|
+
|
|
5714
6106
|
//#endregion
|
|
5715
6107
|
//#region src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx
|
|
5716
6108
|
/**
|
|
5717
6109
|
* Grace window before showing the spinner. A matching tool call must
|
|
5718
6110
|
* remain unresolved (no `tool`-role result message in `agent.messages`)
|
|
5719
|
-
* for at least this long before the
|
|
5720
|
-
* history-replay flashes — during
|
|
5721
|
-
*
|
|
5722
|
-
*
|
|
5723
|
-
*
|
|
6111
|
+
* for at least this long before the indicator transitions out of
|
|
6112
|
+
* `hidden`. This filters out history-replay flashes — during
|
|
6113
|
+
* `connectAgent` replay, tool calls and their results arrive
|
|
6114
|
+
* back-to-back in sub-millisecond bursts, so the timer is cancelled
|
|
6115
|
+
* before it fires. Live runs cross the threshold easily because the
|
|
6116
|
+
* tool actually has to execute.
|
|
5724
6117
|
*/
|
|
5725
6118
|
const PENDING_THRESHOLD_MS = 100;
|
|
5726
|
-
/** Hold the checkmark briefly before fading out. */
|
|
5727
|
-
const CHECK_HOLD_MS = 800;
|
|
5728
6119
|
/**
|
|
5729
|
-
*
|
|
5730
|
-
*
|
|
6120
|
+
* Tool-name regex patterns that trigger the indicator. Matches any tool
|
|
6121
|
+
* name *containing* the Intelligence MCP server's canonical tool name, so
|
|
6122
|
+
* both the bare `copilotkit_knowledge_base_shell` and the namespaced
|
|
6123
|
+
* `mcp__<server>__copilotkit_knowledge_base_shell` form (emitted by
|
|
6124
|
+
* `@ag-ui/mcp-middleware`) light up the pill. If we add per-instance
|
|
6125
|
+
* customization later (e.g. a `CopilotKitProvider` prop or a runtime-info
|
|
6126
|
+
* field), this constant becomes the fallback.
|
|
6127
|
+
*/
|
|
6128
|
+
const DEFAULT_TOOL_PATTERNS = [/copilotkit_knowledge_base_shell/];
|
|
6129
|
+
/**
|
|
6130
|
+
* Phase to start in when an indicator first mounts. A turn that is already
|
|
6131
|
+
* complete at mount jumps straight to `finished` — no `hidden` flash, no
|
|
6132
|
+
* spinner blip — which is what makes scrolled-back / replayed history render
|
|
6133
|
+
* its indicators directly in the finished state.
|
|
6134
|
+
*
|
|
6135
|
+
* Pure and timing-free on purpose: the grace window ({@link
|
|
6136
|
+
* PENDING_THRESHOLD_MS}) only controls *when* the live transition is applied;
|
|
6137
|
+
* these functions decide *what* it resolves to, so the decision can be unit
|
|
6138
|
+
* tested deterministically without any timers.
|
|
5731
6139
|
*/
|
|
5732
|
-
|
|
6140
|
+
function initialIndicatorPhase(turnComplete) {
|
|
6141
|
+
return turnComplete ? "finished" : "hidden";
|
|
6142
|
+
}
|
|
5733
6143
|
/**
|
|
5734
|
-
*
|
|
5735
|
-
*
|
|
5736
|
-
*
|
|
5737
|
-
*
|
|
6144
|
+
* Phase the grace window resolves to once it elapses:
|
|
6145
|
+
* - completed turn → `finished` (replay-flash suppression: a tool whose
|
|
6146
|
+
* result lands within the window skips the spinner entirely),
|
|
6147
|
+
* - a still-pending matching tool call → `spinner`,
|
|
6148
|
+
* - otherwise stay `hidden` (the matching tool call hasn't landed yet).
|
|
5738
6149
|
*/
|
|
5739
|
-
|
|
6150
|
+
function resolveGracePhase(turnComplete, hasPending) {
|
|
6151
|
+
if (turnComplete) return "finished";
|
|
6152
|
+
if (hasPending) return "spinner";
|
|
6153
|
+
return "hidden";
|
|
6154
|
+
}
|
|
5740
6155
|
const isMatchingToolCallName = (name) => typeof name === "string" && DEFAULT_TOOL_PATTERNS.some((p) => p.test(name));
|
|
6156
|
+
const messageHasMatchingToolCall = (m) => {
|
|
6157
|
+
if (m.role !== "assistant") return false;
|
|
6158
|
+
return (Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => isMatchingToolCallName(tc?.function?.name));
|
|
6159
|
+
};
|
|
6160
|
+
/**
|
|
6161
|
+
* Stable turn id for the messages that precede the first user message (a turn
|
|
6162
|
+
* with no opening user message of its own). Used as the React key so the
|
|
6163
|
+
* indicator for that turn never collides with a real user-message id.
|
|
6164
|
+
*/
|
|
6165
|
+
const INTELLIGENCE_TURN_HEAD = "__cpk_turn_head__";
|
|
6166
|
+
/**
|
|
6167
|
+
* Map each Intelligence-using turn to its anchor message — the FIRST bash-using
|
|
6168
|
+
* assistant message of the turn — and a stable turn id (the id of the user
|
|
6169
|
+
* message that opened the turn, or {@link INTELLIGENCE_TURN_HEAD} for the
|
|
6170
|
+
* pre-first-user turn). Returns `Map<anchorMessageId, turnId>`.
|
|
6171
|
+
*
|
|
6172
|
+
* Anchoring to the FIRST (not last) bash-using message keeps the indicator
|
|
6173
|
+
* fixed in place for the whole turn: later bash steps don't reposition it, so
|
|
6174
|
+
* the spinner never abruptly jumps mid-turn (bug 1). `CopilotChatMessageView`
|
|
6175
|
+
* emits exactly one `IntelligenceIndicator` per entry, keyed by the turn id and
|
|
6176
|
+
* positioned at the anchor; the per-turn key also lets every past turn keep its
|
|
6177
|
+
* own indicator in scroll-back.
|
|
6178
|
+
*/
|
|
6179
|
+
function getIntelligenceTurnAnchors(messages) {
|
|
6180
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
6181
|
+
let turnId = INTELLIGENCE_TURN_HEAD;
|
|
6182
|
+
let anchorId = null;
|
|
6183
|
+
const commit = () => {
|
|
6184
|
+
if (anchorId !== null) anchors.set(anchorId, turnId);
|
|
6185
|
+
anchorId = null;
|
|
6186
|
+
};
|
|
6187
|
+
for (const m of messages) {
|
|
6188
|
+
if (m.role === "user") {
|
|
6189
|
+
commit();
|
|
6190
|
+
turnId = m.id;
|
|
6191
|
+
continue;
|
|
6192
|
+
}
|
|
6193
|
+
if (anchorId === null && messageHasMatchingToolCall(m)) anchorId = m.id;
|
|
6194
|
+
}
|
|
6195
|
+
commit();
|
|
6196
|
+
return anchors;
|
|
6197
|
+
}
|
|
5741
6198
|
/**
|
|
5742
6199
|
* "Tool-call-like" messages do NOT count as a real follow-up: tool
|
|
5743
6200
|
* result messages, assistant messages that carry tool calls, and
|
|
@@ -5756,45 +6213,51 @@ const isToolCallLikeMessage = (m) => {
|
|
|
5756
6213
|
return false;
|
|
5757
6214
|
};
|
|
5758
6215
|
/**
|
|
5759
|
-
* The "Using CopilotKit Intelligence"
|
|
5760
|
-
* `CopilotChatMessageView`
|
|
5761
|
-
*
|
|
5762
|
-
*
|
|
5763
|
-
*
|
|
6216
|
+
* The "Using CopilotKit Intelligence" indicator brain. Auto-mounted by
|
|
6217
|
+
* `CopilotChatMessageView` — once per Intelligence-using turn, at that
|
|
6218
|
+
* turn's anchor message and keyed by the turn id (see
|
|
6219
|
+
* {@link getIntelligenceTurnAnchors}). Callers do not register this
|
|
6220
|
+
* themselves. It owns the run subscription and the phase machine and
|
|
6221
|
+
* renders its swappable face via the `intelligenceIndicator` slot.
|
|
6222
|
+
*
|
|
6223
|
+
* Placement (which message anchors the turn) is decided by the view, so
|
|
6224
|
+
* this component does not self-gate its own placement; it only derives
|
|
6225
|
+
* in-progress/finished for the turn it was mounted on.
|
|
5764
6226
|
*
|
|
5765
6227
|
* Render gates (all must hold):
|
|
5766
6228
|
* 1. `copilotkit.intelligence !== undefined`
|
|
5767
|
-
* 2. The message is an assistant message with at least one
|
|
5768
|
-
* whose name matches {@link DEFAULT_TOOL_PATTERNS}
|
|
5769
|
-
* 3. The
|
|
5770
|
-
*
|
|
5771
|
-
*
|
|
5772
|
-
*
|
|
5773
|
-
*
|
|
5774
|
-
*
|
|
6229
|
+
* 2. The (anchor) message is an assistant message with at least one
|
|
6230
|
+
* tool call whose name matches {@link DEFAULT_TOOL_PATTERNS}.
|
|
6231
|
+
* 3. The phase machine is past `hidden`.
|
|
6232
|
+
*
|
|
6233
|
+
* Because the view keys each indicator by its turn id, the instance moves
|
|
6234
|
+
* with the anchor across a hand-off (no remount, no spinner restart), and
|
|
6235
|
+
* every prior Intelligence-using turn keeps its own persistent indicator
|
|
6236
|
+
* in chat history.
|
|
5775
6237
|
*
|
|
5776
6238
|
* Phase machine (per-instance, all timers local):
|
|
5777
|
-
* - Starts in `
|
|
5778
|
-
*
|
|
6239
|
+
* - Starts in `hidden`, unless the message mounts onto an
|
|
6240
|
+
* already-completed turn (no pending work, agent stopped or a
|
|
6241
|
+
* real follow-up already present), in which case the lazy
|
|
6242
|
+
* `useState` initializer starts directly in `finished`. This is
|
|
6243
|
+
* what avoids a "hidden flash" on history replay.
|
|
6244
|
+
* - `hidden → spinner` once a matching tool call has been pending
|
|
5779
6245
|
* (no `tool`-role result with a matching `toolCallId`) for
|
|
5780
6246
|
* {@link PENDING_THRESHOLD_MS}. Replay flashes (tool call + result
|
|
5781
6247
|
* in the same tick) never cross this threshold.
|
|
5782
|
-
* - `
|
|
6248
|
+
* - `hidden → finished` if after the grace window the turn is
|
|
6249
|
+
* already complete (no pending work AND
|
|
6250
|
+
* `sawRealFollowup || !agent.isRunning`). Handles very fast tools
|
|
6251
|
+
* whose result lands within the grace window.
|
|
6252
|
+
* - `spinner → finished` as soon as EITHER `agent.isRunning` flips
|
|
5783
6253
|
* false OR a non-tool-call-like message appears later in
|
|
5784
|
-
* `agent.messages` (i.e. the agent
|
|
5785
|
-
*
|
|
5786
|
-
* - `
|
|
5787
|
-
*
|
|
5788
|
-
*
|
|
5789
|
-
* Once `hidden`, the phase is sticky — a finished pill never re-spawns
|
|
5790
|
-
* on the same message. New runs mount fresh indicator instances on
|
|
5791
|
-
* their own assistant messages.
|
|
5792
|
-
*
|
|
5793
|
-
* The "exactly one pill at a time" guarantee is structural: only one
|
|
5794
|
-
* message satisfies the latest-matching-assistant gate at any moment.
|
|
6254
|
+
* `agent.messages` (i.e. the agent produced a "real" follow-up —
|
|
6255
|
+
* prose answer or a new user turn).
|
|
6256
|
+
* - `finished` is terminal: the indicator settles into its
|
|
6257
|
+
* persistent tag form and stays mounted.
|
|
5795
6258
|
*/
|
|
5796
6259
|
function IntelligenceIndicator(props) {
|
|
5797
|
-
const { message, agentId, label = "
|
|
6260
|
+
const { message, agentId, label = "CopilotKit Intelligence", intelligenceIndicator } = props;
|
|
5798
6261
|
const { copilotkit } = useCopilotKit();
|
|
5799
6262
|
const config = useCopilotChatConfiguration();
|
|
5800
6263
|
const { agent } = useAgent({
|
|
@@ -5814,84 +6277,37 @@ function IntelligenceIndicator(props) {
|
|
|
5814
6277
|
for (const m of agent.messages) if (m.role === "tool" && m.toolCallId) resolved.add(m.toolCallId);
|
|
5815
6278
|
return matchingToolCallIds.some((id) => !resolved.has(id));
|
|
5816
6279
|
}, [matchingToolCallIds, agent.messages]);
|
|
5817
|
-
const
|
|
6280
|
+
const turnComplete = useMemo(() => {
|
|
5818
6281
|
const idx = agent.messages.findIndex((m) => m.id === message.id);
|
|
5819
6282
|
if (idx < 0) return false;
|
|
5820
6283
|
for (let i = idx + 1; i < agent.messages.length; i += 1) if (!isToolCallLikeMessage(agent.messages[i])) return true;
|
|
5821
6284
|
return false;
|
|
5822
|
-
}, [agent.messages, message.id]);
|
|
5823
|
-
const [phase, setPhase] = useState(
|
|
6285
|
+
}, [agent.messages, message.id]) || !agent.isRunning;
|
|
6286
|
+
const [phase, setPhase] = useState(() => initialIndicatorPhase(turnComplete));
|
|
5824
6287
|
useEffect(() => {
|
|
5825
|
-
if (phase !== "
|
|
5826
|
-
|
|
5827
|
-
|
|
6288
|
+
if (phase !== "hidden") return void 0;
|
|
6289
|
+
const t = setTimeout(() => {
|
|
6290
|
+
setPhase(resolveGracePhase(turnComplete, hasPending));
|
|
6291
|
+
}, PENDING_THRESHOLD_MS);
|
|
5828
6292
|
return () => clearTimeout(t);
|
|
5829
|
-
}, [phase, hasPending]);
|
|
5830
|
-
useEffect(() => {
|
|
5831
|
-
if (phase !== "spinner") return void 0;
|
|
5832
|
-
if (!agent.isRunning || sawRealFollowup) setPhase("check");
|
|
5833
6293
|
}, [
|
|
5834
6294
|
phase,
|
|
5835
|
-
|
|
5836
|
-
|
|
6295
|
+
hasPending,
|
|
6296
|
+
turnComplete
|
|
5837
6297
|
]);
|
|
5838
6298
|
useEffect(() => {
|
|
5839
|
-
if (phase !== "
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
}, [phase]);
|
|
5843
|
-
useEffect(() => {
|
|
5844
|
-
if (phase !== "fading") return void 0;
|
|
5845
|
-
const t = setTimeout(() => setPhase("hidden"), FADE_OUT_ANIMATION_MS);
|
|
5846
|
-
return () => clearTimeout(t);
|
|
5847
|
-
}, [phase]);
|
|
6299
|
+
if (phase !== "spinner") return void 0;
|
|
6300
|
+
if (turnComplete) setPhase("finished");
|
|
6301
|
+
}, [phase, turnComplete]);
|
|
5848
6302
|
if (copilotkit.intelligence === void 0) return null;
|
|
5849
6303
|
if (!config) return null;
|
|
5850
|
-
if (phase === "
|
|
6304
|
+
if (phase === "hidden") return null;
|
|
5851
6305
|
if (message.role !== "assistant") return null;
|
|
5852
|
-
if (!(
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => isMatchingToolCallName(tc?.function?.name))) {
|
|
5858
|
-
latestMatchingAssistantId = m.id;
|
|
5859
|
-
break;
|
|
5860
|
-
}
|
|
5861
|
-
}
|
|
5862
|
-
if (latestMatchingAssistantId !== message.id) return null;
|
|
5863
|
-
const showSpinner = phase === "spinner";
|
|
5864
|
-
const isFading = phase === "fading";
|
|
5865
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
5866
|
-
className: "cpk-intelligence-pill" + (isFading ? " cpk-intelligence-pill--fading" : ""),
|
|
5867
|
-
role: "status",
|
|
5868
|
-
"aria-live": "polite",
|
|
5869
|
-
"aria-hidden": isFading || void 0,
|
|
5870
|
-
"data-testid": `cpk-intelligence-pill-${message.id}`,
|
|
5871
|
-
title: label,
|
|
5872
|
-
children: [/* @__PURE__ */ jsxs("svg", {
|
|
5873
|
-
className: "cpk-intelligence-pill__icon",
|
|
5874
|
-
viewBox: "0 0 24 24",
|
|
5875
|
-
width: "14",
|
|
5876
|
-
height: "14",
|
|
5877
|
-
"aria-hidden": "true",
|
|
5878
|
-
children: [/* @__PURE__ */ jsx("circle", {
|
|
5879
|
-
cx: "12",
|
|
5880
|
-
cy: "12",
|
|
5881
|
-
r: "9",
|
|
5882
|
-
fill: "none",
|
|
5883
|
-
strokeWidth: "2.5",
|
|
5884
|
-
strokeLinecap: "round",
|
|
5885
|
-
className: "cpk-intelligence-pill__ring" + (showSpinner ? "" : " cpk-intelligence-pill__ring--done")
|
|
5886
|
-
}), /* @__PURE__ */ jsx("path", {
|
|
5887
|
-
d: "M8 12.5l3 3 5-6",
|
|
5888
|
-
fill: "none",
|
|
5889
|
-
strokeWidth: "2.5",
|
|
5890
|
-
strokeLinecap: "round",
|
|
5891
|
-
strokeLinejoin: "round",
|
|
5892
|
-
className: "cpk-intelligence-pill__check" + (showSpinner ? "" : " cpk-intelligence-pill__check--shown")
|
|
5893
|
-
})]
|
|
5894
|
-
}), /* @__PURE__ */ jsx("span", { children: label })]
|
|
6306
|
+
if (!messageHasMatchingToolCall(message)) return null;
|
|
6307
|
+
return renderSlot(intelligenceIndicator, IntelligenceIndicatorView, {
|
|
6308
|
+
message,
|
|
6309
|
+
status: phase === "finished" ? "finished" : "in-progress",
|
|
6310
|
+
label
|
|
5895
6311
|
});
|
|
5896
6312
|
}
|
|
5897
6313
|
|
|
@@ -6044,7 +6460,7 @@ function deduplicateMessages(messages) {
|
|
|
6044
6460
|
return [...acc.values()];
|
|
6045
6461
|
}
|
|
6046
6462
|
const VIRTUALIZE_THRESHOLD = 50;
|
|
6047
|
-
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, isRunning = false, children, className, ...props }) {
|
|
6463
|
+
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, isRunning = false, children, className, ...props }) {
|
|
6048
6464
|
const renderCustomMessage = useRenderCustomMessages();
|
|
6049
6465
|
const { renderActivityMessage } = useRenderActivityMessage();
|
|
6050
6466
|
const { copilotkit } = useCopilotKit();
|
|
@@ -6102,6 +6518,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
|
|
|
6102
6518
|
if (!shouldVirtualize || !deduplicatedMessages.length) return;
|
|
6103
6519
|
virtualizer.scrollToIndex(deduplicatedMessages.length - 1, { align: "end" });
|
|
6104
6520
|
}, [shouldVirtualize, firstMessageId]);
|
|
6521
|
+
const intelligenceTurnAnchors = useMemo(() => getIntelligenceTurnAnchors(deduplicatedMessages), [deduplicatedMessages]);
|
|
6105
6522
|
const renderMessageBlock = (message) => {
|
|
6106
6523
|
const elements = [];
|
|
6107
6524
|
const stateSnapshot = getStateSnapshotForMessage(message.id);
|
|
@@ -6140,10 +6557,12 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
|
|
|
6140
6557
|
renderCustomMessage,
|
|
6141
6558
|
stateSnapshot
|
|
6142
6559
|
}, `${message.id}-custom-after`));
|
|
6143
|
-
|
|
6560
|
+
const intelligenceTurnId = intelligenceTurnAnchors.get(message.id);
|
|
6561
|
+
if (intelligenceTurnId !== void 0) elements.push(/* @__PURE__ */ jsx(IntelligenceIndicator, {
|
|
6144
6562
|
message,
|
|
6145
|
-
agentId: config?.agentId ?? DEFAULT_AGENT_ID
|
|
6146
|
-
|
|
6563
|
+
agentId: config?.agentId ?? DEFAULT_AGENT_ID,
|
|
6564
|
+
intelligenceIndicator
|
|
6565
|
+
}, `intelligence-${intelligenceTurnId}`));
|
|
6147
6566
|
return elements.filter(Boolean);
|
|
6148
6567
|
};
|
|
6149
6568
|
const messageElements = shouldVirtualize ? [] : deduplicatedMessages.flatMap(renderMessageBlock);
|
|
@@ -6580,7 +6999,7 @@ function DropOverlay() {
|
|
|
6580
6999
|
})
|
|
6581
7000
|
});
|
|
6582
7001
|
}
|
|
6583
|
-
function CopilotChatView({ messageView, input, scrollView, suggestionView, welcomeScreen, messages = [], autoScroll = true, isRunning = false, suggestions, suggestionLoadingIndexes, onSelectSuggestion, onSubmitMessage, onStop, inputMode, inputValue, onInputChange, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onFinishTranscribeWithAudio, attachments, onRemoveAttachment, onAddFile, dragOver, onDragOver, onDragLeave, onDrop, isConnecting = false, hasExplicitThreadId = false, disclaimer, children, className, ...props }) {
|
|
7002
|
+
function CopilotChatView({ messageView, input, scrollView, suggestionView, welcomeScreen, messages = [], autoScroll = true, isRunning = false, suggestions, suggestionLoadingIndexes, onSelectSuggestion, onSubmitMessage, onStop, inputMode, inputValue, onInputChange, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onFinishTranscribeWithAudio, attachments, onRemoveAttachment, onAddFile, dragOver, onDragOver, onDragLeave, onDrop, isConnecting = false, hasExplicitThreadId = false, disclaimer, intelligenceIndicator, children, className, ...props }) {
|
|
6584
7003
|
const [inputContainerEl, setInputContainerEl] = useState(null);
|
|
6585
7004
|
const [inputContainerHeight, setInputContainerHeight] = useState(0);
|
|
6586
7005
|
const [isResizing, setIsResizing] = useState(false);
|
|
@@ -6617,7 +7036,8 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
|
|
|
6617
7036
|
}, [inputContainerEl]);
|
|
6618
7037
|
const BoundMessageView = renderSlot(messageView, CopilotChatMessageView, {
|
|
6619
7038
|
messages,
|
|
6620
|
-
isRunning
|
|
7039
|
+
isRunning,
|
|
7040
|
+
intelligenceIndicator
|
|
6621
7041
|
});
|
|
6622
7042
|
const BoundInput = renderSlot(input, CopilotChatInput_default, {
|
|
6623
7043
|
onSubmitMessage,
|
|
@@ -7162,6 +7582,13 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
7162
7582
|
resolvedAgentId,
|
|
7163
7583
|
hasExplicitThreadId
|
|
7164
7584
|
]);
|
|
7585
|
+
const waitForActiveRunToSettle = useCallback(async () => {
|
|
7586
|
+
if (agent.isRunning && isRunCompletionAware(agent) && agent.activeRunCompletionPromise) try {
|
|
7587
|
+
await agent.activeRunCompletionPromise;
|
|
7588
|
+
} catch (error) {
|
|
7589
|
+
console.error("CopilotChat: in-flight run rejected while queuing send", error);
|
|
7590
|
+
}
|
|
7591
|
+
}, [agent]);
|
|
7165
7592
|
const onSubmitInput = useCallback(async (value) => {
|
|
7166
7593
|
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
7167
7594
|
console.error("[CopilotKit] Cannot send while attachments are uploading (pre-await guard)");
|
|
@@ -7169,11 +7596,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
7169
7596
|
return;
|
|
7170
7597
|
}
|
|
7171
7598
|
setInputValue("");
|
|
7172
|
-
|
|
7173
|
-
await agent.activeRunCompletionPromise;
|
|
7174
|
-
} catch (error) {
|
|
7175
|
-
console.error("CopilotChat: in-flight run rejected while queuing send", error);
|
|
7176
|
-
}
|
|
7599
|
+
await waitForActiveRunToSettle();
|
|
7177
7600
|
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
7178
7601
|
console.error("[CopilotKit] Cannot send while attachments are uploading (post-await re-check)");
|
|
7179
7602
|
setTranscriptionError("Cannot send while attachments are uploading.");
|
|
@@ -7210,8 +7633,13 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
7210
7633
|
} catch (error) {
|
|
7211
7634
|
console.error("CopilotChat: runAgent failed", error);
|
|
7212
7635
|
}
|
|
7213
|
-
}, [
|
|
7636
|
+
}, [
|
|
7637
|
+
agent,
|
|
7638
|
+
consumeAttachments,
|
|
7639
|
+
waitForActiveRunToSettle
|
|
7640
|
+
]);
|
|
7214
7641
|
const handleSelectSuggestion = useCallback(async (suggestion) => {
|
|
7642
|
+
await waitForActiveRunToSettle();
|
|
7215
7643
|
agent.addMessage({
|
|
7216
7644
|
id: randomUUID(),
|
|
7217
7645
|
role: "user",
|
|
@@ -7222,7 +7650,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
7222
7650
|
} catch (error) {
|
|
7223
7651
|
console.error("CopilotChat: runAgent failed after selecting suggestion", error);
|
|
7224
7652
|
}
|
|
7225
|
-
}, [agent]);
|
|
7653
|
+
}, [agent, waitForActiveRunToSettle]);
|
|
7226
7654
|
const stopCurrentRun = useCallback(() => {
|
|
7227
7655
|
try {
|
|
7228
7656
|
copilotkit.stopAgent({ agent });
|
|
@@ -10098,5 +10526,5 @@ function validateProps(props) {
|
|
|
10098
10526
|
}
|
|
10099
10527
|
|
|
10100
10528
|
//#endregion
|
|
10101
|
-
export {
|
|
10102
|
-
//# sourceMappingURL=copilotkit-
|
|
10529
|
+
export { useHumanInTheLoop as $, INTELLIGENCE_TURN_HEAD as A, CopilotChatToolCallsView as B, CopilotChatToggleButton as C, useCopilotChatConfiguration as Ct, CopilotChatView_default as D, CopilotChat as E, CopilotChatSuggestionPill as F, useLearnFromUserAction as G, useLearningContainers as H, CopilotChatReasoningMessage_default as I, useConfigureSuggestions as J, useThreads$1 as K, CopilotChatUserMessage_default as L, getIntelligenceTurnAnchors as M, IntelligenceIndicatorView as N, CopilotChatAttachmentQueue as O, CopilotChatSuggestionView as P, useAgent as Q, CopilotChatAttachmentRenderer as R, CopilotModalHeader as S, CopilotChatConfigurationProvider as St, DefaultOpenIcon as T, useAttachments as U, useLearningContainersInCurrentThread as V, useLearnFromUserActionInCurrentThread as W, useCapabilities as X, useSuggestions as Y, UseAgentUpdate as Z, WildcardToolCallRender as _, useCopilotKit as _t, ThreadsProvider as a, useAgentContext as at, CopilotPopupView as b, AudioRecorderError as bt, CoAgentStateRendersProvider as c, useSandboxFunctions as ct, shouldShowDevConsole as d, MCPAppsActivityType as dt, useComponent as et, useToast as f, CopilotKitInspector as ft, useCopilotContext as g, defineToolCallRenderer as gt, CopilotContext as h, useRenderTool as ht, ThreadsContext as i, CopilotKitProvider as it, IntelligenceIndicator as j, CopilotChatMessageView as k, useCoAgentStateRenders as l, MCPAppsActivityContentSchema as lt, useCopilotMessagesContext as m, useDefaultRenderTool as mt, defaultCopilotContextCategories as n, useRenderActivityMessage as nt, useThreads as o, createA2UIMessageRenderer as ot, CopilotMessagesContext as p, useRenderToolCall as pt, useInterrupt as q, CoAgentStateRenderBridge as r, useRenderCustomMessages as rt, CoAgentStateRendersContext as s, SandboxFunctionsContext as st, CopilotKit as t, useFrontendTool as tt, useAsyncCallback as u, MCPAppsActivityRenderer as ut, CopilotPopup as v, CopilotKitCoreReact as vt, DefaultCloseIcon as w, CopilotSidebarView as x, CopilotChatAudioRecorder as xt, CopilotSidebar as y, CopilotChatInput_default as yt, CopilotChatAssistantMessage_default as z };
|
|
10530
|
+
//# sourceMappingURL=copilotkit-DoIlZQqa.mjs.map
|