@copilotkit/react-core 1.69.0 → 1.69.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.
- package/dist/{copilotkit-pkDPhwkR.d.mts → copilotkit-DYKpg4pD.d.mts} +28 -22
- package/dist/copilotkit-DYKpg4pD.d.mts.map +1 -0
- package/dist/{copilotkit-DOMr3DRO.cjs → copilotkit-Dr0speVK.cjs} +429 -46
- package/dist/copilotkit-Dr0speVK.cjs.map +1 -0
- package/dist/{copilotkit-ykQW_VJZ.mjs → copilotkit-Dr6g885f.mjs} +431 -48
- package/dist/copilotkit-Dr6g885f.mjs.map +1 -0
- package/dist/{copilotkit-DYM5ChMS.d.cts → copilotkit-Hl1t9Y1v.d.cts} +28 -22
- package/dist/copilotkit-Hl1t9Y1v.d.cts.map +1 -0
- package/dist/index.cjs +119 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +904 -28
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +904 -28
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +119 -75
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +185 -100
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +3 -2
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +5 -4
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +5 -4
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +3 -2
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +426 -43
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -8
- package/skills/react-core/SKILL.md +1 -1
- package/skills/react-core/references/provider-setup.md +1 -1
- package/skills/react-core/references/threads.md +2 -2
- package/dist/copilotkit-DOMr3DRO.cjs.map +0 -1
- package/dist/copilotkit-DYM5ChMS.d.cts.map +0 -1
- package/dist/copilotkit-pkDPhwkR.d.mts.map +0 -1
- package/dist/copilotkit-ykQW_VJZ.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
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, isRunCompletionAware, ɵInterruptState, ɵcreateThreadStore, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
3
|
+
import { CopilotKitCore, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, emitInspectorActiveThread, emitInspectorViewThreadResult, isInspectorThreadBridgeEnabled, isRunCompletionAware, onInspectorStopViewing, onInspectorViewThread, ɵInterruptState, ɵcreateThreadStore, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
4
4
|
import { HttpAgent, randomUUID } from "@ag-ui/client";
|
|
5
5
|
import { extendTailwindMerge, twMerge } from "tailwind-merge";
|
|
6
|
-
import { ArrowUp, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, Copy, Edit, Loader2, MessageCircle, Mic, PanelLeftOpen, Play, Plus, RefreshCw, Square, ThumbsDown, ThumbsUp, Upload, Volume2, X } from "lucide-react";
|
|
6
|
+
import { ArrowUp, Bookmark, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, Copy, Edit, Loader2, MessageCircle, Mic, PanelLeftOpen, Play, Plus, RefreshCw, Square, ThumbsDown, ThumbsUp, Upload, Volume2, X } from "lucide-react";
|
|
7
7
|
import { A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitRemoteEndpointDiscoveryError, DEFAULT_AGENT_ID, ErrorVisibility, MissingPublicApiKeyError, Severity, TranscriptionErrorCode, TranscriptionErrorCode as TranscriptionErrorCode$1, copyToClipboard, createLicenseContextValue, dataToUUID, exceedsMaxSize, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getSourceUrl, matchesAcceptFilter, parseJson, partialJSONParse, randomId, randomUUID as randomUUID$1, readFileAsBase64, schemaToJsonSchema } from "@copilotkit/shared";
|
|
8
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { Slot } from "@radix-ui/react-slot";
|
|
@@ -78,6 +78,7 @@ const CopilotChatDefaultLabels = {
|
|
|
78
78
|
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
79
79
|
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
80
80
|
assistantMessageToolbarInspectorLocalOnlyLabel: "Local Only",
|
|
81
|
+
assistantMessageToolbarSaveSnippetLabel: "Save as snippet",
|
|
81
82
|
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
82
83
|
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
83
84
|
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
@@ -1530,7 +1531,8 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
|
1530
1531
|
//#region src/v2/components/CopilotKitInspectorContext.tsx
|
|
1531
1532
|
const CopilotKitInspectorContext = React$1.createContext({
|
|
1532
1533
|
isLocalInspectorEnabled: false,
|
|
1533
|
-
openInspector: () => void 0
|
|
1534
|
+
openInspector: () => void 0,
|
|
1535
|
+
saveEventSnippet: async () => void 0
|
|
1534
1536
|
});
|
|
1535
1537
|
const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
|
|
1536
1538
|
function useCopilotKitInspector() {
|
|
@@ -2344,6 +2346,7 @@ function injectCssIntoHtml(html, css) {
|
|
|
2344
2346
|
const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
|
|
2345
2347
|
const initialHeight = content.initialHeight ?? 200;
|
|
2346
2348
|
const [autoHeight, setAutoHeight] = useState(null);
|
|
2349
|
+
const [sandboxReady, setSandboxReady] = useState(false);
|
|
2347
2350
|
const sandboxFunctions = useSandboxFunctions();
|
|
2348
2351
|
const localApi = useMemo(() => {
|
|
2349
2352
|
const api = {};
|
|
@@ -2445,6 +2448,7 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2445
2448
|
sandbox.promise.then(() => {
|
|
2446
2449
|
if (cancelled) return;
|
|
2447
2450
|
sandboxReadyRef.current = true;
|
|
2451
|
+
setSandboxReady(true);
|
|
2448
2452
|
sandbox.run(`
|
|
2449
2453
|
var s = document.createElement('style');
|
|
2450
2454
|
s.textContent = 'html, body { overflow: hidden !important; }';
|
|
@@ -2469,6 +2473,7 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2469
2473
|
sandboxRef.current = null;
|
|
2470
2474
|
}
|
|
2471
2475
|
sandboxReadyRef.current = false;
|
|
2476
|
+
setSandboxReady(false);
|
|
2472
2477
|
setAutoHeight(null);
|
|
2473
2478
|
};
|
|
2474
2479
|
}, [
|
|
@@ -2499,7 +2504,7 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2499
2504
|
const generationDone = content.generating === false;
|
|
2500
2505
|
useEffect(() => {
|
|
2501
2506
|
const sandbox = sandboxRef.current;
|
|
2502
|
-
if (!generationDone || !sandbox) return;
|
|
2507
|
+
if (!generationDone || !sandboxReady || !sandbox) return;
|
|
2503
2508
|
let handled = false;
|
|
2504
2509
|
const onMessage = (e) => {
|
|
2505
2510
|
if (handled) return;
|
|
@@ -2528,7 +2533,7 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2528
2533
|
return () => {
|
|
2529
2534
|
window.removeEventListener("message", onMessage);
|
|
2530
2535
|
};
|
|
2531
|
-
}, [generationDone]);
|
|
2536
|
+
}, [generationDone, sandboxReady]);
|
|
2532
2537
|
const height = autoHeight ?? initialHeight;
|
|
2533
2538
|
const isGenerating = content.generating !== false;
|
|
2534
2539
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -3512,10 +3517,46 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3512
3517
|
const requestInspectorOpen = useCallback((request) => {
|
|
3513
3518
|
setInspectorOpenRequest({ ...request });
|
|
3514
3519
|
}, []);
|
|
3520
|
+
const saveEventSnippet = useCallback(async (request) => {
|
|
3521
|
+
try {
|
|
3522
|
+
const mod = await import("@copilotkit/web-inspector");
|
|
3523
|
+
const threadId = request.threadId ?? "inspector-snippet";
|
|
3524
|
+
const runId = `inspector-snippet-${Date.now()}`;
|
|
3525
|
+
const compiled = mod.compileChatSnippet({
|
|
3526
|
+
...request,
|
|
3527
|
+
threadId,
|
|
3528
|
+
runId
|
|
3529
|
+
});
|
|
3530
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3531
|
+
const snippet = {
|
|
3532
|
+
id: crypto.randomUUID(),
|
|
3533
|
+
name: compiled.name,
|
|
3534
|
+
recipe: compiled.recipe,
|
|
3535
|
+
events: compiled.events,
|
|
3536
|
+
createdAt: now,
|
|
3537
|
+
updatedAt: now
|
|
3538
|
+
};
|
|
3539
|
+
mod.upsertEventSnippet(snippet);
|
|
3540
|
+
requestInspectorOpen({
|
|
3541
|
+
messageId: request.messageId,
|
|
3542
|
+
threadId: request.threadId,
|
|
3543
|
+
agentId: request.agentId,
|
|
3544
|
+
menu: "event-snippets",
|
|
3545
|
+
snippetId: snippet.id
|
|
3546
|
+
});
|
|
3547
|
+
} catch (error) {
|
|
3548
|
+
console.error("[CopilotKit] Could not save the event snippet.", error);
|
|
3549
|
+
}
|
|
3550
|
+
}, [requestInspectorOpen]);
|
|
3515
3551
|
const inspectorContextValue = useMemo(() => ({
|
|
3516
3552
|
isLocalInspectorEnabled,
|
|
3517
|
-
openInspector: requestInspectorOpen
|
|
3518
|
-
|
|
3553
|
+
openInspector: requestInspectorOpen,
|
|
3554
|
+
saveEventSnippet
|
|
3555
|
+
}), [
|
|
3556
|
+
isLocalInspectorEnabled,
|
|
3557
|
+
requestInspectorOpen,
|
|
3558
|
+
saveEventSnippet
|
|
3559
|
+
]);
|
|
3519
3560
|
const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
|
|
3520
3561
|
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
3521
3562
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
@@ -3570,7 +3611,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3570
3611
|
const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;
|
|
3571
3612
|
const hasSelfManagedAgents = Object.keys(selfManagedAgents).length > 0;
|
|
3572
3613
|
useEffect(() => {
|
|
3573
|
-
if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence
|
|
3614
|
+
if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence tier. Provide a `publicLicenseKey` for production use — contact the CopilotKit team about licensing.");
|
|
3574
3615
|
}, [hasSelfManagedAgents, resolvedPublicKey]);
|
|
3575
3616
|
const headers = typeof headersProp === "function" ? headersProp() : headersProp;
|
|
3576
3617
|
const mergedHeaders = useMemo(() => {
|
|
@@ -5167,10 +5208,10 @@ function useThreadStoreSelector(store, selector) {
|
|
|
5167
5208
|
}, [store, selector]), () => selector(store.getState()), () => selector(store.getServerState()));
|
|
5168
5209
|
}
|
|
5169
5210
|
/**
|
|
5170
|
-
* React hook for listing and managing Intelligence
|
|
5211
|
+
* React hook for listing and managing CopilotKit Intelligence threads.
|
|
5171
5212
|
*
|
|
5172
5213
|
* On mount the hook fetches the thread list for the runtime-authenticated user
|
|
5173
|
-
* and the given `agentId`. When
|
|
5214
|
+
* and the given `agentId`. When CopilotKit Intelligence exposes a WebSocket
|
|
5174
5215
|
* URL, it also opens a realtime subscription so the `threads` array stays
|
|
5175
5216
|
* current without polling — thread creates, renames, archives, and deletes
|
|
5176
5217
|
* from any client are reflected immediately.
|
|
@@ -5466,7 +5507,7 @@ async function recordAnnotation(args) {
|
|
|
5466
5507
|
//#endregion
|
|
5467
5508
|
//#region src/v2/hooks/use-learn-from-user-action.tsx
|
|
5468
5509
|
/**
|
|
5469
|
-
* Record a user UI interaction in
|
|
5510
|
+
* Record a user UI interaction in CopilotKit Intelligence's user-actions
|
|
5470
5511
|
* stream. The platform's auto-curated knowledge base agent reads these
|
|
5471
5512
|
* (alongside finished agent runs) and writes free-form Obsidian-flavored
|
|
5472
5513
|
* markdown to `/project`, where any agent in the same project can later
|
|
@@ -5892,25 +5933,191 @@ function useLearningContainersInCurrentThread({ learningContainers }) {
|
|
|
5892
5933
|
});
|
|
5893
5934
|
}
|
|
5894
5935
|
|
|
5936
|
+
//#endregion
|
|
5937
|
+
//#region src/v2/components/chat/save-snippet-beside.ts
|
|
5938
|
+
const SAVE_SNIPPET_ICON_SLOT_PX = 36;
|
|
5939
|
+
const SAVE_SNIPPET_BESIDE_WRAP_CLASS = "cpk:relative cpk:w-full cpk:overflow-visible";
|
|
5940
|
+
const SAVE_SNIPPET_BESIDE_BODY_CLASS = "cpk:w-full";
|
|
5941
|
+
const SAVE_SNIPPET_BESIDE_SAVE_CLASS = "cpk:absolute cpk:top-0 cpk:z-10";
|
|
5942
|
+
function saveSnippetBesideStyle(side) {
|
|
5943
|
+
if (side === "left") return {
|
|
5944
|
+
left: "auto",
|
|
5945
|
+
right: "100%",
|
|
5946
|
+
marginLeft: 0,
|
|
5947
|
+
marginRight: 4
|
|
5948
|
+
};
|
|
5949
|
+
return {
|
|
5950
|
+
left: "100%",
|
|
5951
|
+
right: "auto",
|
|
5952
|
+
marginLeft: 4,
|
|
5953
|
+
marginRight: 0
|
|
5954
|
+
};
|
|
5955
|
+
}
|
|
5956
|
+
function pickSaveSnippetSide(roomRight, roomLeft, slotPx = SAVE_SNIPPET_ICON_SLOT_PX) {
|
|
5957
|
+
if (roomRight >= slotPx) return "right";
|
|
5958
|
+
if (roomLeft >= slotPx) return "left";
|
|
5959
|
+
return "right";
|
|
5960
|
+
}
|
|
5961
|
+
function findOverflowAncestor(el) {
|
|
5962
|
+
let node = el.parentElement;
|
|
5963
|
+
while (node) {
|
|
5964
|
+
const style = getComputedStyle(node);
|
|
5965
|
+
const overflowX = style.overflowX;
|
|
5966
|
+
const overflow = style.overflow;
|
|
5967
|
+
if (overflowX === "hidden" || overflowX === "auto" || overflowX === "scroll" || overflow === "hidden" || overflow === "auto" || overflow === "scroll") return node;
|
|
5968
|
+
node = node.parentElement;
|
|
5969
|
+
}
|
|
5970
|
+
return document.documentElement;
|
|
5971
|
+
}
|
|
5972
|
+
function measurableBox(el) {
|
|
5973
|
+
let node = el;
|
|
5974
|
+
while (node && getComputedStyle(node).display === "contents") node = node.firstElementChild;
|
|
5975
|
+
return node ?? el;
|
|
5976
|
+
}
|
|
5977
|
+
function measureSaveSnippetSide(wrap, body) {
|
|
5978
|
+
const clipRect = findOverflowAncestor(wrap).getBoundingClientRect();
|
|
5979
|
+
const bodyRect = measurableBox(body.firstElementChild ?? body).getBoundingClientRect();
|
|
5980
|
+
return pickSaveSnippetSide(clipRect.right - bodyRect.right, bodyRect.left - clipRect.left);
|
|
5981
|
+
}
|
|
5982
|
+
|
|
5983
|
+
//#endregion
|
|
5984
|
+
//#region src/v2/components/chat/SaveSnippetIconButton.tsx
|
|
5985
|
+
function SaveSnippetIconButton({ title, className, ...props }) {
|
|
5986
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5987
|
+
const primaryLabel = title || labels.assistantMessageToolbarSaveSnippetLabel;
|
|
5988
|
+
const localOnlyLabel = labels.assistantMessageToolbarInspectorLocalOnlyLabel;
|
|
5989
|
+
const accessibleLabel = `${primaryLabel} (${localOnlyLabel})`;
|
|
5990
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
5991
|
+
asChild: true,
|
|
5992
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
5993
|
+
type: "button",
|
|
5994
|
+
variant: "assistantMessageToolbarButton",
|
|
5995
|
+
"aria-label": accessibleLabel,
|
|
5996
|
+
title: accessibleLabel,
|
|
5997
|
+
className,
|
|
5998
|
+
...props,
|
|
5999
|
+
children: /* @__PURE__ */ jsx(Bookmark, { className: "cpk:size-[18px]" })
|
|
6000
|
+
})
|
|
6001
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
6002
|
+
side: "bottom",
|
|
6003
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
6004
|
+
className: "cpk:flex cpk:flex-col cpk:gap-0.5",
|
|
6005
|
+
children: [/* @__PURE__ */ jsx("span", { children: primaryLabel }), /* @__PURE__ */ jsx("span", {
|
|
6006
|
+
className: "cpk:text-[10px] cpk:opacity-65",
|
|
6007
|
+
children: localOnlyLabel
|
|
6008
|
+
})]
|
|
6009
|
+
})
|
|
6010
|
+
})] });
|
|
6011
|
+
}
|
|
6012
|
+
function SaveSnippetBesideChrome({ children, showSave, saveButton }) {
|
|
6013
|
+
const wrapRef = useRef(null);
|
|
6014
|
+
const bodyRef = useRef(null);
|
|
6015
|
+
const [side, setSide] = useState("right");
|
|
6016
|
+
useLayoutEffect(() => {
|
|
6017
|
+
if (!showSave) return;
|
|
6018
|
+
const wrap = wrapRef.current;
|
|
6019
|
+
const body = bodyRef.current;
|
|
6020
|
+
if (!wrap || !body) return;
|
|
6021
|
+
const measure = () => {
|
|
6022
|
+
setSide(measureSaveSnippetSide(wrap, body));
|
|
6023
|
+
};
|
|
6024
|
+
measure();
|
|
6025
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
6026
|
+
const observer = new ResizeObserver(measure);
|
|
6027
|
+
observer.observe(wrap);
|
|
6028
|
+
observer.observe(body);
|
|
6029
|
+
const clip = findOverflowAncestor(wrap);
|
|
6030
|
+
if (clip !== wrap) observer.observe(clip);
|
|
6031
|
+
window.addEventListener("resize", measure);
|
|
6032
|
+
return () => {
|
|
6033
|
+
observer.disconnect();
|
|
6034
|
+
window.removeEventListener("resize", measure);
|
|
6035
|
+
};
|
|
6036
|
+
}, [showSave]);
|
|
6037
|
+
if (!showSave) return children;
|
|
6038
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
6039
|
+
ref: wrapRef,
|
|
6040
|
+
className: SAVE_SNIPPET_BESIDE_WRAP_CLASS,
|
|
6041
|
+
"data-save-snippet-side": side,
|
|
6042
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
6043
|
+
ref: bodyRef,
|
|
6044
|
+
className: SAVE_SNIPPET_BESIDE_BODY_CLASS,
|
|
6045
|
+
children
|
|
6046
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
6047
|
+
className: SAVE_SNIPPET_BESIDE_SAVE_CLASS,
|
|
6048
|
+
style: saveSnippetBesideStyle(side),
|
|
6049
|
+
children: saveButton
|
|
6050
|
+
})]
|
|
6051
|
+
});
|
|
6052
|
+
}
|
|
6053
|
+
|
|
5895
6054
|
//#endregion
|
|
5896
6055
|
//#region src/v2/components/chat/CopilotChatToolCallsView.tsx
|
|
5897
6056
|
function CopilotChatToolCallsView({ message, messages = [] }) {
|
|
5898
6057
|
const renderToolCall = useRenderToolCall();
|
|
6058
|
+
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6059
|
+
const chatConfiguration = useCopilotChatConfiguration();
|
|
6060
|
+
const labels = chatConfiguration?.labels ?? CopilotChatDefaultLabels;
|
|
5899
6061
|
if (!message.toolCalls || message.toolCalls.length === 0) return null;
|
|
5900
6062
|
return /* @__PURE__ */ jsx(Fragment$1, { children: message.toolCalls.map((toolCall) => {
|
|
5901
|
-
const
|
|
5902
|
-
return /* @__PURE__ */ jsx(React.Fragment, { children: renderToolCall({
|
|
6063
|
+
const rendered = renderToolCall({
|
|
5903
6064
|
toolCall,
|
|
5904
|
-
toolMessage
|
|
5905
|
-
})
|
|
6065
|
+
toolMessage: messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id)
|
|
6066
|
+
});
|
|
6067
|
+
if (!isLocalInspectorEnabled || !hasCompleteArgs(toolCall.function.arguments)) return /* @__PURE__ */ jsx(React.Fragment, { children: rendered }, toolCall.id);
|
|
6068
|
+
const primaryLabel = labels.assistantMessageToolbarSaveSnippetLabel;
|
|
6069
|
+
return /* @__PURE__ */ jsx(ToolCallSnippetChrome, {
|
|
6070
|
+
label: primaryLabel,
|
|
6071
|
+
onSave: () => void saveEventSnippet({
|
|
6072
|
+
kind: "tool-call",
|
|
6073
|
+
messageId: message.id,
|
|
6074
|
+
toolCallId: toolCall.id,
|
|
6075
|
+
toolName: toolCall.function.name,
|
|
6076
|
+
argsJson: toolCall.function.arguments || "{}",
|
|
6077
|
+
threadId: chatConfiguration?.threadId,
|
|
6078
|
+
agentId: chatConfiguration?.agentId
|
|
6079
|
+
}),
|
|
6080
|
+
children: rendered
|
|
6081
|
+
}, toolCall.id);
|
|
5906
6082
|
}) });
|
|
5907
6083
|
}
|
|
6084
|
+
function hasCompleteArgs(args) {
|
|
6085
|
+
const trimmed = (args ?? "").trim();
|
|
6086
|
+
if (!trimmed) return true;
|
|
6087
|
+
try {
|
|
6088
|
+
JSON.parse(trimmed);
|
|
6089
|
+
return true;
|
|
6090
|
+
} catch {
|
|
6091
|
+
return false;
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
function ToolCallSnippetChrome({ children, label, onSave }) {
|
|
6095
|
+
const bodyRef = useRef(null);
|
|
6096
|
+
const [showSave, setShowSave] = useState(false);
|
|
6097
|
+
useLayoutEffect(() => {
|
|
6098
|
+
const el = bodyRef.current;
|
|
6099
|
+
setShowSave(!!el && el.childElementCount > 0);
|
|
6100
|
+
});
|
|
6101
|
+
return /* @__PURE__ */ jsx(SaveSnippetBesideChrome, {
|
|
6102
|
+
showSave,
|
|
6103
|
+
saveButton: /* @__PURE__ */ jsx(SaveSnippetIconButton, {
|
|
6104
|
+
"data-testid": "copilot-tool-save-snippet-button",
|
|
6105
|
+
title: label,
|
|
6106
|
+
onClick: onSave
|
|
6107
|
+
}),
|
|
6108
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
6109
|
+
ref: bodyRef,
|
|
6110
|
+
className: "cpk:contents",
|
|
6111
|
+
children
|
|
6112
|
+
})
|
|
6113
|
+
});
|
|
6114
|
+
}
|
|
5908
6115
|
|
|
5909
6116
|
//#endregion
|
|
5910
6117
|
//#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
|
|
5911
|
-
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
6118
|
+
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, saveSnippetButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
5912
6119
|
useKatexStyles();
|
|
5913
|
-
const { isLocalInspectorEnabled, openInspector } = useCopilotKitInspector();
|
|
6120
|
+
const { isLocalInspectorEnabled, openInspector, saveEventSnippet } = useCopilotKitInspector();
|
|
5914
6121
|
const chatConfiguration = useCopilotChatConfiguration();
|
|
5915
6122
|
const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
5916
6123
|
const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
@@ -5923,6 +6130,17 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
5923
6130
|
threadId: chatConfiguration?.threadId,
|
|
5924
6131
|
agentId: chatConfiguration?.agentId
|
|
5925
6132
|
}) });
|
|
6133
|
+
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
6134
|
+
const boundSaveSnippetButton = renderSlot(saveSnippetButton, CopilotChatAssistantMessage.SaveSnippetButton, { onClick: () => {
|
|
6135
|
+
if (!hasContent) return;
|
|
6136
|
+
saveEventSnippet({
|
|
6137
|
+
kind: "text",
|
|
6138
|
+
messageId: message.id,
|
|
6139
|
+
content: message.content ?? "",
|
|
6140
|
+
threadId: chatConfiguration?.threadId,
|
|
6141
|
+
agentId: chatConfiguration?.agentId
|
|
6142
|
+
});
|
|
6143
|
+
} });
|
|
5926
6144
|
const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
|
|
5927
6145
|
const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
|
|
5928
6146
|
const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
|
|
@@ -5931,6 +6149,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
5931
6149
|
children: [
|
|
5932
6150
|
boundCopyButton,
|
|
5933
6151
|
isLocalInspectorEnabled && boundInspectorButton,
|
|
6152
|
+
isLocalInspectorEnabled && hasContent && boundSaveSnippetButton,
|
|
5934
6153
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
5935
6154
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
5936
6155
|
(onReadAloud || readAloudButton) && boundReadAloudButton,
|
|
@@ -5942,9 +6161,8 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
5942
6161
|
message,
|
|
5943
6162
|
messages
|
|
5944
6163
|
});
|
|
5945
|
-
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
5946
6164
|
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
5947
|
-
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
6165
|
+
const shouldShowToolbar = toolbarVisible && (hasContent || isLocalInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
|
|
5948
6166
|
if (children) return /* @__PURE__ */ jsx("div", {
|
|
5949
6167
|
"data-copilotkit": true,
|
|
5950
6168
|
style: { display: "contents" },
|
|
@@ -5954,6 +6172,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
5954
6172
|
toolCallsView: boundToolCallsView,
|
|
5955
6173
|
copyButton: boundCopyButton,
|
|
5956
6174
|
inspectorButton: boundInspectorButton,
|
|
6175
|
+
saveSnippetButton: boundSaveSnippetButton,
|
|
5957
6176
|
thumbsUpButton: boundThumbsUpButton,
|
|
5958
6177
|
thumbsDownButton: boundThumbsDownButton,
|
|
5959
6178
|
readAloudButton: boundReadAloudButton,
|
|
@@ -6164,6 +6383,10 @@ function CopilotKitColoredIcon() {
|
|
|
6164
6383
|
children: /* @__PURE__ */ jsx(CopilotKitColoredIcon, {})
|
|
6165
6384
|
});
|
|
6166
6385
|
};
|
|
6386
|
+
_CopilotChatAssistantMessage.SaveSnippetButton = (props) => /* @__PURE__ */ jsx(SaveSnippetIconButton, {
|
|
6387
|
+
"data-testid": "copilot-save-snippet-button",
|
|
6388
|
+
...props
|
|
6389
|
+
});
|
|
6167
6390
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
6168
6391
|
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6169
6392
|
return /* @__PURE__ */ jsx(ToolbarButton, {
|
|
@@ -6205,6 +6428,7 @@ CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistant
|
|
|
6205
6428
|
CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
|
|
6206
6429
|
CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
|
|
6207
6430
|
CopilotChatAssistantMessage.InspectorButton.displayName = "CopilotChatAssistantMessage.InspectorButton";
|
|
6431
|
+
CopilotChatAssistantMessage.SaveSnippetButton.displayName = "CopilotChatAssistantMessage.SaveSnippetButton";
|
|
6208
6432
|
CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
|
|
6209
6433
|
CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
|
|
6210
6434
|
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
@@ -6575,6 +6799,8 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
|
|
|
6575
6799
|
const isLatest = messages?.[messages.length - 1]?.id === message.id;
|
|
6576
6800
|
const isStreaming = !!(isRunning && isLatest);
|
|
6577
6801
|
const hasContent = !!(message.content && message.content.length > 0);
|
|
6802
|
+
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6803
|
+
const chatConfiguration = useCopilotChatConfiguration();
|
|
6578
6804
|
const startTimeRef = useRef(null);
|
|
6579
6805
|
const [elapsed, setElapsed] = useState(0);
|
|
6580
6806
|
useEffect(() => {
|
|
@@ -6634,7 +6860,16 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
|
|
|
6634
6860
|
className: twMerge("cpk:my-1", className),
|
|
6635
6861
|
"data-message-id": message.id,
|
|
6636
6862
|
...props,
|
|
6637
|
-
children: [
|
|
6863
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
6864
|
+
className: "cpk:flex cpk:items-center cpk:gap-1",
|
|
6865
|
+
children: [boundHeader, isLocalInspectorEnabled && hasContent && /* @__PURE__ */ jsx(CopilotChatAssistantMessage_default.SaveSnippetButton, { onClick: () => void saveEventSnippet({
|
|
6866
|
+
kind: "reasoning",
|
|
6867
|
+
messageId: message.id,
|
|
6868
|
+
content: message.content ?? "",
|
|
6869
|
+
threadId: chatConfiguration?.threadId,
|
|
6870
|
+
agentId: chatConfiguration?.agentId
|
|
6871
|
+
}) })]
|
|
6872
|
+
}), boundToggle]
|
|
6638
6873
|
});
|
|
6639
6874
|
}
|
|
6640
6875
|
(function(_CopilotChatReasoningMessage) {
|
|
@@ -7153,8 +7388,33 @@ const MemoizedUserMessage = React.memo(function MemoizedUserMessage({ message, U
|
|
|
7153
7388
|
/**
|
|
7154
7389
|
* Memoized wrapper for activity messages to prevent re-renders when other messages change.
|
|
7155
7390
|
*/
|
|
7391
|
+
function ActivitySnippetChrome({ message, children }) {
|
|
7392
|
+
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
7393
|
+
const chatConfiguration = useCopilotChatConfiguration();
|
|
7394
|
+
if (!(isLocalInspectorEnabled && (message.activityType === "a2ui-surface" || message.activityType === "open-generative-ui"))) return children;
|
|
7395
|
+
const primaryLabel = (chatConfiguration?.labels ?? CopilotChatDefaultLabels).assistantMessageToolbarSaveSnippetLabel;
|
|
7396
|
+
return /* @__PURE__ */ jsx(SaveSnippetBesideChrome, {
|
|
7397
|
+
showSave: true,
|
|
7398
|
+
saveButton: /* @__PURE__ */ jsx(SaveSnippetIconButton, {
|
|
7399
|
+
"data-testid": "copilot-activity-save-snippet-button",
|
|
7400
|
+
title: primaryLabel,
|
|
7401
|
+
onClick: () => void saveEventSnippet({
|
|
7402
|
+
kind: "activity",
|
|
7403
|
+
messageId: message.id,
|
|
7404
|
+
activityType: message.activityType,
|
|
7405
|
+
content: message.content,
|
|
7406
|
+
threadId: chatConfiguration?.threadId,
|
|
7407
|
+
agentId: chatConfiguration?.agentId
|
|
7408
|
+
})
|
|
7409
|
+
}),
|
|
7410
|
+
children
|
|
7411
|
+
});
|
|
7412
|
+
}
|
|
7156
7413
|
const MemoizedActivityMessage = React.memo(function MemoizedActivityMessage({ message, renderActivityMessage }) {
|
|
7157
|
-
return
|
|
7414
|
+
return /* @__PURE__ */ jsx(ActivitySnippetChrome, {
|
|
7415
|
+
message,
|
|
7416
|
+
children: renderActivityMessage(message)
|
|
7417
|
+
});
|
|
7158
7418
|
}, (prevProps, nextProps) => {
|
|
7159
7419
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
7160
7420
|
if (prevProps.message.activityType !== nextProps.message.activityType) return false;
|
|
@@ -8322,14 +8582,109 @@ async function transcribeAudio(core, audioBlob, filename = "recording.webm") {
|
|
|
8322
8582
|
return await response.json();
|
|
8323
8583
|
}
|
|
8324
8584
|
|
|
8585
|
+
//#endregion
|
|
8586
|
+
//#region src/v2/providers/use-inspector-thread-override.ts
|
|
8587
|
+
function useInspectorThreadOverride(args) {
|
|
8588
|
+
const [override, setOverride] = useState(null);
|
|
8589
|
+
const latestRef = useRef({
|
|
8590
|
+
...args,
|
|
8591
|
+
override
|
|
8592
|
+
});
|
|
8593
|
+
latestRef.current = {
|
|
8594
|
+
...args,
|
|
8595
|
+
override
|
|
8596
|
+
};
|
|
8597
|
+
const restoreOverride = useCallback((current, nextThreadId) => {
|
|
8598
|
+
setOverride(null);
|
|
8599
|
+
emitInspectorActiveThread({
|
|
8600
|
+
requestId: current.requestId,
|
|
8601
|
+
threadId: nextThreadId,
|
|
8602
|
+
agentId: current.agentId,
|
|
8603
|
+
source: "app"
|
|
8604
|
+
});
|
|
8605
|
+
}, []);
|
|
8606
|
+
const failInspectorOverride = useCallback((requestId) => {
|
|
8607
|
+
const current = latestRef.current.override;
|
|
8608
|
+
if (!current || current.requestId !== requestId) return;
|
|
8609
|
+
emitInspectorViewThreadResult({
|
|
8610
|
+
requestId,
|
|
8611
|
+
threadId: current.threadId,
|
|
8612
|
+
agentId: current.agentId,
|
|
8613
|
+
ok: false,
|
|
8614
|
+
reason: "connect-failed"
|
|
8615
|
+
});
|
|
8616
|
+
restoreOverride(current, current.previousThreadId);
|
|
8617
|
+
}, [restoreOverride]);
|
|
8618
|
+
useEffect(() => {
|
|
8619
|
+
if (!isInspectorThreadBridgeEnabled()) return;
|
|
8620
|
+
const offView = onInspectorViewThread((payload) => {
|
|
8621
|
+
const current = latestRef.current;
|
|
8622
|
+
if (payload.agentId !== current.agentId) return false;
|
|
8623
|
+
setOverride(current.override ? {
|
|
8624
|
+
...current.override,
|
|
8625
|
+
...payload
|
|
8626
|
+
} : {
|
|
8627
|
+
...payload,
|
|
8628
|
+
previousThreadId: current.baseThreadId
|
|
8629
|
+
});
|
|
8630
|
+
emitInspectorViewThreadResult({
|
|
8631
|
+
...payload,
|
|
8632
|
+
ok: true
|
|
8633
|
+
});
|
|
8634
|
+
emitInspectorActiveThread({
|
|
8635
|
+
...payload,
|
|
8636
|
+
source: "override"
|
|
8637
|
+
});
|
|
8638
|
+
return true;
|
|
8639
|
+
});
|
|
8640
|
+
const offStop = onInspectorStopViewing((payload) => {
|
|
8641
|
+
const current = latestRef.current.override;
|
|
8642
|
+
if (!current) return;
|
|
8643
|
+
if (payload.requestId !== current.requestId) return;
|
|
8644
|
+
if (payload.agentId !== current.agentId) return;
|
|
8645
|
+
restoreOverride(current, current.previousThreadId);
|
|
8646
|
+
});
|
|
8647
|
+
return () => {
|
|
8648
|
+
offView();
|
|
8649
|
+
offStop();
|
|
8650
|
+
};
|
|
8651
|
+
}, [restoreOverride]);
|
|
8652
|
+
useEffect(() => {
|
|
8653
|
+
if (!override) return;
|
|
8654
|
+
if (args.agentId !== override.agentId) {
|
|
8655
|
+
restoreOverride(override, override.previousThreadId);
|
|
8656
|
+
return;
|
|
8657
|
+
}
|
|
8658
|
+
if (args.baseThreadId === override.previousThreadId) return;
|
|
8659
|
+
if (args.baseThreadId === override.threadId) return;
|
|
8660
|
+
restoreOverride(override, args.baseThreadId);
|
|
8661
|
+
}, [
|
|
8662
|
+
args.agentId,
|
|
8663
|
+
args.baseThreadId,
|
|
8664
|
+
override,
|
|
8665
|
+
restoreOverride
|
|
8666
|
+
]);
|
|
8667
|
+
return {
|
|
8668
|
+
inspectorThreadId: override?.threadId ?? null,
|
|
8669
|
+
inspectorRequestId: override?.requestId ?? null,
|
|
8670
|
+
failInspectorOverride
|
|
8671
|
+
};
|
|
8672
|
+
}
|
|
8673
|
+
|
|
8325
8674
|
//#endregion
|
|
8326
8675
|
//#region src/v2/components/chat/CopilotChat.tsx
|
|
8327
8676
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
|
|
8328
8677
|
const existingConfig = useCopilotChatConfiguration();
|
|
8329
8678
|
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;
|
|
8330
8679
|
const providedThreadId = threadId ?? existingConfig?.threadId;
|
|
8331
|
-
const
|
|
8332
|
-
const
|
|
8680
|
+
const baseThreadId = useMemo(() => providedThreadId ?? randomUUID$1(), [providedThreadId]);
|
|
8681
|
+
const baseHasExplicitThreadId = !!threadId || !!existingConfig?.hasExplicitThreadId;
|
|
8682
|
+
const { inspectorThreadId, inspectorRequestId, failInspectorOverride } = useInspectorThreadOverride({
|
|
8683
|
+
agentId: resolvedAgentId,
|
|
8684
|
+
baseThreadId
|
|
8685
|
+
});
|
|
8686
|
+
const resolvedThreadId = inspectorThreadId ?? baseThreadId;
|
|
8687
|
+
const hasExplicitThreadId = inspectorThreadId !== null || baseHasExplicitThreadId;
|
|
8333
8688
|
const { agent, isReady } = useAgent({
|
|
8334
8689
|
agentId: resolvedAgentId,
|
|
8335
8690
|
throttleMs
|
|
@@ -8358,6 +8713,24 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
8358
8713
|
subscription.unsubscribe();
|
|
8359
8714
|
};
|
|
8360
8715
|
}, [copilotkit, resolvedAgentId]);
|
|
8716
|
+
useEffect(() => {
|
|
8717
|
+
if (!inspectorRequestId) return;
|
|
8718
|
+
const requestId = inspectorRequestId;
|
|
8719
|
+
const expectedThreadId = resolvedThreadId;
|
|
8720
|
+
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
8721
|
+
if (event.code !== CopilotKitCoreErrorCode.AGENT_CONNECT_FAILED) return;
|
|
8722
|
+
if (event.context?.agentId !== resolvedAgentId) return;
|
|
8723
|
+
if (event.context?.threadId !== expectedThreadId) return;
|
|
8724
|
+
failInspectorOverride(requestId);
|
|
8725
|
+
} });
|
|
8726
|
+
return () => subscription.unsubscribe();
|
|
8727
|
+
}, [
|
|
8728
|
+
copilotkit,
|
|
8729
|
+
failInspectorOverride,
|
|
8730
|
+
inspectorRequestId,
|
|
8731
|
+
resolvedAgentId,
|
|
8732
|
+
resolvedThreadId
|
|
8733
|
+
]);
|
|
8361
8734
|
const [transcribeMode, setTranscribeMode] = useState("input");
|
|
8362
8735
|
const [inputValue, setInputValue] = useState("");
|
|
8363
8736
|
const [transcriptionError, setTranscriptionError] = useState(null);
|
|
@@ -8384,7 +8757,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
8384
8757
|
const runtimeStatus = copilotkit.runtimeConnectionStatus === CopilotKitCoreRuntimeConnectionStatus.Connected ? "Connected" : copilotkit.runtimeConnectionStatus;
|
|
8385
8758
|
const hasNativeIntelligenceRunActivity = hasExplicitThreadId && runtimeStatus === "Connected" && !!copilotkit.intelligence?.wsUrl && copilotkit.threadEndpoints?.realtimeMetadata === true;
|
|
8386
8759
|
const [standaloneRunActivityStore] = useState(() => ɵcreateThreadStore({ fetch: globalThis.fetch }));
|
|
8387
|
-
const
|
|
8760
|
+
const previousThreadRef = useRef(null);
|
|
8388
8761
|
const hasExplicitThreadIdRef = useRef(hasExplicitThreadId);
|
|
8389
8762
|
hasExplicitThreadIdRef.current = hasExplicitThreadId;
|
|
8390
8763
|
const rememberRecentlyLocalRunId = useCallback((runId) => {
|
|
@@ -8424,8 +8797,15 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
8424
8797
|
};
|
|
8425
8798
|
}, []);
|
|
8426
8799
|
useEffect(() => {
|
|
8427
|
-
const
|
|
8428
|
-
|
|
8800
|
+
const previousThread = previousThreadRef.current;
|
|
8801
|
+
const threadChanged = previousThread?.threadId !== resolvedThreadId;
|
|
8802
|
+
const inspectorTransition = threadChanged && previousThread !== null && previousThread.inspectorRequestId !== inspectorRequestId && (previousThread.inspectorRequestId !== null || inspectorRequestId !== null);
|
|
8803
|
+
previousThreadRef.current = {
|
|
8804
|
+
threadId: resolvedThreadId,
|
|
8805
|
+
inspectorRequestId
|
|
8806
|
+
};
|
|
8807
|
+
if (inspectorTransition) if (typeof copilotkit.stopAgent === "function") copilotkit.stopAgent({ agent });
|
|
8808
|
+
else agent.abortRun?.();
|
|
8429
8809
|
agent.threadId = resolvedThreadId;
|
|
8430
8810
|
if (!hasExplicitThreadId) {
|
|
8431
8811
|
if (threadChanged && agent.messages.length > 0) agent.setMessages([]);
|
|
@@ -8441,6 +8821,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
8441
8821
|
} catch (error) {
|
|
8442
8822
|
if (detached) return;
|
|
8443
8823
|
console.error("CopilotChat: connectAgent failed", error);
|
|
8824
|
+
if (inspectorRequestId) failInspectorOverride(inspectorRequestId);
|
|
8444
8825
|
} finally {
|
|
8445
8826
|
if (!detached) (typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16))(() => {
|
|
8446
8827
|
if (!detached) setLastConnectedThreadId(resolvedThreadId);
|
|
@@ -8466,7 +8847,9 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
8466
8847
|
resolvedThreadId,
|
|
8467
8848
|
agent,
|
|
8468
8849
|
resolvedAgentId,
|
|
8469
|
-
hasExplicitThreadId
|
|
8850
|
+
hasExplicitThreadId,
|
|
8851
|
+
inspectorRequestId,
|
|
8852
|
+
failInspectorOverride
|
|
8470
8853
|
]);
|
|
8471
8854
|
useEffect(() => {
|
|
8472
8855
|
if (!hasNativeIntelligenceRunActivity) return;
|
|
@@ -9823,7 +10206,7 @@ const WildcardToolCallRender = defineToolCallRenderer({
|
|
|
9823
10206
|
});
|
|
9824
10207
|
|
|
9825
10208
|
//#endregion
|
|
9826
|
-
//#region src/context/copilot-context.tsx
|
|
10209
|
+
//#region src/v1-deprecated/context/copilot-context.tsx
|
|
9827
10210
|
const emptyCopilotContext$1 = {
|
|
9828
10211
|
actions: {},
|
|
9829
10212
|
setAction: () => {},
|
|
@@ -9903,7 +10286,7 @@ function returnAndThrowInDebug(_value) {
|
|
|
9903
10286
|
}
|
|
9904
10287
|
|
|
9905
10288
|
//#endregion
|
|
9906
|
-
//#region src/hooks/use-tree.ts
|
|
10289
|
+
//#region src/v1-deprecated/hooks/use-tree.ts
|
|
9907
10290
|
const removeNode = (nodes, id) => {
|
|
9908
10291
|
return nodes.reduce((result, node) => {
|
|
9909
10292
|
if (node.id !== id) {
|
|
@@ -10016,7 +10399,7 @@ function setsHaveIntersection$1(setA, setB) {
|
|
|
10016
10399
|
}
|
|
10017
10400
|
|
|
10018
10401
|
//#endregion
|
|
10019
|
-
//#region src/hooks/use-flat-category-store.ts
|
|
10402
|
+
//#region src/v1-deprecated/hooks/use-flat-category-store.ts
|
|
10020
10403
|
const useFlatCategoryStore = () => {
|
|
10021
10404
|
const [elements, dispatch] = useReducer(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
|
|
10022
10405
|
return {
|
|
@@ -10074,7 +10457,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
10074
10457
|
}
|
|
10075
10458
|
|
|
10076
10459
|
//#endregion
|
|
10077
|
-
//#region src/context/copilot-messages-context.tsx
|
|
10460
|
+
//#region src/v1-deprecated/context/copilot-messages-context.tsx
|
|
10078
10461
|
const emptyCopilotContext = {
|
|
10079
10462
|
messages: [],
|
|
10080
10463
|
setMessages: () => [],
|
|
@@ -10089,7 +10472,7 @@ function useCopilotMessagesContext() {
|
|
|
10089
10472
|
}
|
|
10090
10473
|
|
|
10091
10474
|
//#endregion
|
|
10092
|
-
//#region src/components/toast/toast-provider.tsx
|
|
10475
|
+
//#region src/v1-deprecated/components/toast/toast-provider.tsx
|
|
10093
10476
|
const ToastContext = createContext(void 0);
|
|
10094
10477
|
function getErrorSeverity(error) {
|
|
10095
10478
|
if (error.severity) switch (error.severity) {
|
|
@@ -10396,7 +10779,7 @@ function ToastProvider({ enabled, children }) {
|
|
|
10396
10779
|
}
|
|
10397
10780
|
|
|
10398
10781
|
//#endregion
|
|
10399
|
-
//#region src/utils/dev-console.ts
|
|
10782
|
+
//#region src/v1-deprecated/utils/dev-console.ts
|
|
10400
10783
|
function isLocalhost() {
|
|
10401
10784
|
if (typeof window === "undefined") return false;
|
|
10402
10785
|
return window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0";
|
|
@@ -10407,7 +10790,7 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
10407
10790
|
}
|
|
10408
10791
|
|
|
10409
10792
|
//#endregion
|
|
10410
|
-
//#region src/components/copilot-provider/copilot-messages.tsx
|
|
10793
|
+
//#region src/v1-deprecated/components/copilot-provider/copilot-messages.tsx
|
|
10411
10794
|
/**
|
|
10412
10795
|
* An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context
|
|
10413
10796
|
*/
|
|
@@ -10557,7 +10940,7 @@ function CopilotMessages({ children }) {
|
|
|
10557
10940
|
}
|
|
10558
10941
|
|
|
10559
10942
|
//#endregion
|
|
10560
|
-
//#region src/components/usage-banner.tsx
|
|
10943
|
+
//#region src/v1-deprecated/components/usage-banner.tsx
|
|
10561
10944
|
function UsageBanner({ severity = Severity.CRITICAL, message = "", onClose, actions }) {
|
|
10562
10945
|
if (!message || !severity) return null;
|
|
10563
10946
|
const theme = {
|
|
@@ -10754,7 +11137,7 @@ const getErrorActions = (error) => {
|
|
|
10754
11137
|
};
|
|
10755
11138
|
|
|
10756
11139
|
//#endregion
|
|
10757
|
-
//#region src/lib/status-checker.ts
|
|
11140
|
+
//#region src/v1-deprecated/lib/status-checker.ts
|
|
10758
11141
|
const STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
10759
11142
|
var StatusChecker = class {
|
|
10760
11143
|
constructor() {
|
|
@@ -10776,7 +11159,7 @@ var StatusChecker = class {
|
|
|
10776
11159
|
this.lastResponse = response;
|
|
10777
11160
|
onUpdate?.(response);
|
|
10778
11161
|
return response;
|
|
10779
|
-
} catch
|
|
11162
|
+
} catch {
|
|
10780
11163
|
return null;
|
|
10781
11164
|
}
|
|
10782
11165
|
};
|
|
@@ -10802,7 +11185,7 @@ var StatusChecker = class {
|
|
|
10802
11185
|
};
|
|
10803
11186
|
|
|
10804
11187
|
//#endregion
|
|
10805
|
-
//#region src/components/toast/exclamation-mark-icon.tsx
|
|
11188
|
+
//#region src/v1-deprecated/components/toast/exclamation-mark-icon.tsx
|
|
10806
11189
|
const ExclamationMarkIcon = ({ className, style }) => /* @__PURE__ */ jsxs("svg", {
|
|
10807
11190
|
xmlns: "http://www.w3.org/2000/svg",
|
|
10808
11191
|
width: "24",
|
|
@@ -10837,7 +11220,7 @@ const ExclamationMarkIcon = ({ className, style }) => /* @__PURE__ */ jsxs("svg"
|
|
|
10837
11220
|
});
|
|
10838
11221
|
|
|
10839
11222
|
//#endregion
|
|
10840
|
-
//#region src/components/error-boundary/error-utils.tsx
|
|
11223
|
+
//#region src/v1-deprecated/components/error-boundary/error-utils.tsx
|
|
10841
11224
|
function ErrorToast({ errors }) {
|
|
10842
11225
|
return /* @__PURE__ */ jsxs("div", {
|
|
10843
11226
|
style: {
|
|
@@ -10911,7 +11294,7 @@ function useAsyncCallback(callback, deps) {
|
|
|
10911
11294
|
}
|
|
10912
11295
|
|
|
10913
11296
|
//#endregion
|
|
10914
|
-
//#region src/components/error-boundary/error-boundary.tsx
|
|
11297
|
+
//#region src/v1-deprecated/components/error-boundary/error-boundary.tsx
|
|
10915
11298
|
const statusChecker = new StatusChecker();
|
|
10916
11299
|
var CopilotErrorBoundary = class extends React.Component {
|
|
10917
11300
|
constructor(props) {
|
|
@@ -10952,7 +11335,7 @@ var CopilotErrorBoundary = class extends React.Component {
|
|
|
10952
11335
|
};
|
|
10953
11336
|
|
|
10954
11337
|
//#endregion
|
|
10955
|
-
//#region src/context/coagent-state-renders-context.tsx
|
|
11338
|
+
//#region src/v1-deprecated/context/coagent-state-renders-context.tsx
|
|
10956
11339
|
const CoAgentStateRendersContext = createContext(void 0);
|
|
10957
11340
|
function CoAgentStateRendersProvider({ children }) {
|
|
10958
11341
|
const [coAgentStateRenders, setCoAgentStateRenders] = useState({});
|
|
@@ -10987,7 +11370,7 @@ function useCoAgentStateRenders() {
|
|
|
10987
11370
|
}
|
|
10988
11371
|
|
|
10989
11372
|
//#endregion
|
|
10990
|
-
//#region src/context/threads-context.tsx
|
|
11373
|
+
//#region src/v1-deprecated/context/threads-context.tsx
|
|
10991
11374
|
const ThreadsContext = createContext(void 0);
|
|
10992
11375
|
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
10993
11376
|
const [internalThreadId, setInternalThreadId] = useState(() => randomUUID$1());
|
|
@@ -11014,7 +11397,7 @@ function useThreads() {
|
|
|
11014
11397
|
}
|
|
11015
11398
|
|
|
11016
11399
|
//#endregion
|
|
11017
|
-
//#region src/hooks/use-coagent-state-render-bridge.helpers.ts
|
|
11400
|
+
//#region src/v1-deprecated/hooks/use-coagent-state-render-bridge.helpers.ts
|
|
11018
11401
|
let RenderStatus = /* @__PURE__ */ function(RenderStatus) {
|
|
11019
11402
|
RenderStatus["InProgress"] = "inProgress";
|
|
11020
11403
|
RenderStatus["Complete"] = "complete";
|
|
@@ -11179,7 +11562,7 @@ function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCach
|
|
|
11179
11562
|
}
|
|
11180
11563
|
|
|
11181
11564
|
//#endregion
|
|
11182
|
-
//#region src/hooks/use-coagent-state-render-registry.ts
|
|
11565
|
+
//#region src/v1-deprecated/hooks/use-coagent-state-render-registry.ts
|
|
11183
11566
|
const LAST_SNAPSHOTS_BY_RENDER_AND_RUN = "__lastSnapshotsByStateRenderIdAndRun";
|
|
11184
11567
|
const LAST_SNAPSHOTS_BY_MESSAGE = "__lastSnapshotsByMessageId";
|
|
11185
11568
|
function getClaimsStore(claimsRef) {
|
|
@@ -11301,7 +11684,7 @@ function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex,
|
|
|
11301
11684
|
}
|
|
11302
11685
|
|
|
11303
11686
|
//#endregion
|
|
11304
|
-
//#region src/hooks/use-coagent-state-render-bridge.tsx
|
|
11687
|
+
//#region src/v1-deprecated/hooks/use-coagent-state-render-bridge.tsx
|
|
11305
11688
|
function useCoagentStateRenderBridge(agentId, props) {
|
|
11306
11689
|
const { stateSnapshot, message } = props;
|
|
11307
11690
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
@@ -11385,7 +11768,7 @@ function CoAgentStateRenderBridge(props) {
|
|
|
11385
11768
|
}
|
|
11386
11769
|
|
|
11387
11770
|
//#endregion
|
|
11388
|
-
//#region src/components/CopilotListeners.tsx
|
|
11771
|
+
//#region src/v1-deprecated/components/CopilotListeners.tsx
|
|
11389
11772
|
const usePredictStateSubscription = (agent) => {
|
|
11390
11773
|
const predictStateToolsRef = useRef([]);
|
|
11391
11774
|
const getSubscriber = useCallback((agent) => ({
|
|
@@ -11455,7 +11838,7 @@ function CopilotListeners() {
|
|
|
11455
11838
|
}
|
|
11456
11839
|
|
|
11457
11840
|
//#endregion
|
|
11458
|
-
//#region src/components/copilot-provider/copilotkit.tsx
|
|
11841
|
+
//#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
|
|
11459
11842
|
function CopilotKit({ children, ...props }) {
|
|
11460
11843
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
11461
11844
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
@@ -11954,4 +12337,4 @@ function validateProps(props) {
|
|
|
11954
12337
|
|
|
11955
12338
|
//#endregion
|
|
11956
12339
|
export { useCapabilities as $, CopilotChatMessageView as A, CopilotChatAudioRecorder as At, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, MCPAppsActivityRenderer as Ct, CopilotChat as D, useRenderToolCall as Dt, DefaultOpenIcon as E, CopilotKitInspector as Et, CopilotChatSuggestionView as F, useLearnFromUserActionInCurrentThread as G, useLearningContainersInCurrentThread as H, CopilotChatSuggestionPill as I, useThreads$1 as J, useLearnFromUserAction as K, CopilotChatReasoningMessage_default as L, IntelligenceIndicator as M, useCopilotChatConfiguration as Mt, getIntelligenceTurnAnchors as N, CopilotChatView_default as O, CopilotChatInput_default as Ot, IntelligenceIndicatorView as P, useAgentContext as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, MCPAppsActivityContentSchema as St, DefaultCloseIcon as T, ɵrunMcpFollowUp as Tt, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, useConfigureSuggestions as X, useInterrupt as Y, useSuggestions as Z, WildcardToolCallRender as _, OpenGenerativeUIActivityType as _t, ThreadsProvider as a, useComponent as at, CopilotSidebar as b, SandboxFunctionsContext as bt, CoAgentStateRendersProvider as c, useRenderCustomMessages as ct, shouldShowDevConsole as d, useLicenseContext$1 as dt, UseAgentUpdate as et, useToast as f, CopilotKitCoreReact as ft, useCopilotContext as g, OpenGenerativeUIActivityRenderer as gt, CopilotContext as h, GenerateSandboxedUiArgsSchema as ht, ThreadsContext as i, useRenderTool as it, INTELLIGENCE_TURN_HEAD as j, CopilotChatConfigurationProvider as jt, CopilotChatAttachmentQueue as k, AudioRecorderError as kt, useCoAgentStateRenders as l, CopilotKitProvider as lt, useCopilotMessagesContext as m, createA2UIMessageRenderer as mt, defaultCopilotContextCategories as n, useHumanInTheLoop as nt, useThreads as o, useFrontendTool as ot, CopilotMessagesContext as p, defineToolCallRenderer as pt, useMemories as q, CoAgentStateRenderBridge as r, useDefaultRenderTool as rt, CoAgentStateRendersContext as s, useRenderActivityMessage as st, CopilotKit as t, useAgent as tt, useAsyncCallback as u, useCopilotKit$1 as ut, CopilotThreadsDrawer as v, OpenGenerativeUIContentSchema as vt, CopilotChatToggleButton as w, MCPAppsActivityType as wt, CopilotPopupView as x, useSandboxFunctions as xt, CopilotPopup as y, OpenGenerativeUIToolRenderer as yt, CopilotChatAttachmentRenderer as z };
|
|
11957
|
-
//# sourceMappingURL=copilotkit-
|
|
12340
|
+
//# sourceMappingURL=copilotkit-Dr6g885f.mjs.map
|