@copilotkit/react-core 1.69.1 → 1.69.3
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-Dr0speVK.cjs → copilotkit-BPeh62mW.cjs} +104 -341
- package/dist/copilotkit-BPeh62mW.cjs.map +1 -0
- package/dist/{copilotkit-Hl1t9Y1v.d.cts → copilotkit-CrNUgJiq.d.cts} +18 -21
- package/dist/copilotkit-CrNUgJiq.d.cts.map +1 -0
- package/dist/{copilotkit-DYKpg4pD.d.mts → copilotkit-DgO31tBq.d.mts} +18 -21
- package/dist/copilotkit-DgO31tBq.d.mts.map +1 -0
- package/dist/{copilotkit-Dr6g885f.mjs → copilotkit-JdHy0xdu.mjs} +106 -343
- package/dist/copilotkit-JdHy0xdu.mjs.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/index.umd.js +77 -100
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +1 -2
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +0 -1
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +0 -1
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +1 -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 +107 -343
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +7 -8
- package/skills/react-core/SKILL.md +5 -3
- package/skills/react-core/references/agent-access.md +68 -1
- package/skills/react-core/references/debug-mode.md +21 -34
- package/skills/react-core/references/switching-agents-recipes.md +1 -0
- package/skills/react-core/references/switching-agents.md +9 -0
- package/skills/react-core/references/threads.md +65 -0
- package/dist/copilotkit-DYKpg4pD.d.mts.map +0 -1
- package/dist/copilotkit-Dr0speVK.cjs.map +0 -1
- package/dist/copilotkit-Dr6g885f.mjs.map +0 -1
- package/dist/copilotkit-Hl1t9Y1v.d.cts.map +0 -1
|
@@ -3,8 +3,8 @@ import React, { createContext, forwardRef, memo, useCallback, useContext, useEff
|
|
|
3
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,
|
|
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";
|
|
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";
|
|
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, shouldEnableInspector } 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";
|
|
10
10
|
import { cva } from "class-variance-authority";
|
|
@@ -14,7 +14,6 @@ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
|
14
14
|
import { Streamdown } from "streamdown";
|
|
15
15
|
import { CopilotKitContext, LicenseContext, useCopilotKit, useCopilotKit as useCopilotKit$1, useLicenseContext, useLicenseContext as useLicenseContext$1 } from "@copilotkit/react-core/v2/context";
|
|
16
16
|
import { z } from "zod";
|
|
17
|
-
import { createComponent } from "@lit-labs/react";
|
|
18
17
|
import { A2UIProvider, A2UIRenderer, A2UI_SCHEMA_CONTEXT_DESCRIPTION, Catalog, DEFAULT_SURFACE_ID, buildCatalogContextValue, extractCatalogComponentSchemas, filterCatalog, initializeDefaultCatalog, injectStyles, useA2UIActions, useA2UIError, viewerTheme } from "@copilotkit/a2ui-renderer";
|
|
19
18
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
20
19
|
import { createPortal, flushSync } from "react-dom";
|
|
@@ -77,8 +76,7 @@ const CopilotChatDefaultLabels = {
|
|
|
77
76
|
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
78
77
|
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
79
78
|
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
80
|
-
assistantMessageToolbarInspectorLocalOnlyLabel: "
|
|
81
|
-
assistantMessageToolbarSaveSnippetLabel: "Save as snippet",
|
|
79
|
+
assistantMessageToolbarInspectorLocalOnlyLabel: "Development Only",
|
|
82
80
|
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
83
81
|
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
84
82
|
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
@@ -1497,32 +1495,43 @@ function useRenderToolCall() {
|
|
|
1497
1495
|
|
|
1498
1496
|
//#endregion
|
|
1499
1497
|
//#region src/v2/components/CopilotKitInspector.tsx
|
|
1500
|
-
const CopilotKitInspector = ({ core, openRequest
|
|
1501
|
-
const
|
|
1498
|
+
const CopilotKitInspector = ({ core, openRequest }) => {
|
|
1499
|
+
const mountRef = React$1.useRef(null);
|
|
1502
1500
|
const inspectorRef = React$1.useRef(null);
|
|
1501
|
+
const latestCoreRef = React$1.useRef(core ?? null);
|
|
1502
|
+
const latestOpenRequestRef = React$1.useRef(openRequest);
|
|
1503
|
+
latestCoreRef.current = core ?? null;
|
|
1504
|
+
latestOpenRequestRef.current = openRequest;
|
|
1503
1505
|
React$1.useEffect(() => {
|
|
1504
1506
|
let mounted = true;
|
|
1507
|
+
let inspector = null;
|
|
1505
1508
|
import("@copilotkit/web-inspector").then((mod) => {
|
|
1509
|
+
if (!mounted || !mountRef.current) return;
|
|
1506
1510
|
mod.defineWebInspector?.();
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
if (
|
|
1511
|
+
inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
|
|
1512
|
+
mod.configureWebInspectorElement(inspector, latestCoreRef.current);
|
|
1513
|
+
mountRef.current.appendChild(inspector);
|
|
1514
|
+
inspectorRef.current = inspector;
|
|
1515
|
+
const request = latestOpenRequestRef.current;
|
|
1516
|
+
if (request) inspector.openInspector("message_toolbar", request);
|
|
1517
|
+
}).catch((error) => {
|
|
1518
|
+
console.error("Failed to load CopilotKit inspector:", error);
|
|
1513
1519
|
});
|
|
1514
1520
|
return () => {
|
|
1515
1521
|
mounted = false;
|
|
1522
|
+
inspector?.remove();
|
|
1523
|
+
if (inspectorRef.current === inspector) inspectorRef.current = null;
|
|
1516
1524
|
};
|
|
1517
1525
|
}, []);
|
|
1526
|
+
React$1.useEffect(() => {
|
|
1527
|
+
if (inspectorRef.current) inspectorRef.current.core = core ?? null;
|
|
1528
|
+
}, [core]);
|
|
1518
1529
|
React$1.useEffect(() => {
|
|
1519
1530
|
if (openRequest) inspectorRef.current?.openInspector("message_toolbar", openRequest);
|
|
1520
|
-
}, [
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
...rest,
|
|
1525
|
-
core: core ?? null
|
|
1531
|
+
}, [openRequest]);
|
|
1532
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1533
|
+
ref: mountRef,
|
|
1534
|
+
style: { display: "contents" }
|
|
1526
1535
|
});
|
|
1527
1536
|
};
|
|
1528
1537
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
@@ -1530,9 +1539,8 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
|
1530
1539
|
//#endregion
|
|
1531
1540
|
//#region src/v2/components/CopilotKitInspectorContext.tsx
|
|
1532
1541
|
const CopilotKitInspectorContext = React$1.createContext({
|
|
1533
|
-
|
|
1534
|
-
openInspector: () => void 0
|
|
1535
|
-
saveEventSnippet: async () => void 0
|
|
1542
|
+
isInspectorEnabled: false,
|
|
1543
|
+
openInspector: () => void 0
|
|
1536
1544
|
});
|
|
1537
1545
|
const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
|
|
1538
1546
|
function useCopilotKitInspector() {
|
|
@@ -2346,7 +2354,6 @@ function injectCssIntoHtml(html, css) {
|
|
|
2346
2354
|
const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
|
|
2347
2355
|
const initialHeight = content.initialHeight ?? 200;
|
|
2348
2356
|
const [autoHeight, setAutoHeight] = useState(null);
|
|
2349
|
-
const [sandboxReady, setSandboxReady] = useState(false);
|
|
2350
2357
|
const sandboxFunctions = useSandboxFunctions();
|
|
2351
2358
|
const localApi = useMemo(() => {
|
|
2352
2359
|
const api = {};
|
|
@@ -2448,7 +2455,6 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2448
2455
|
sandbox.promise.then(() => {
|
|
2449
2456
|
if (cancelled) return;
|
|
2450
2457
|
sandboxReadyRef.current = true;
|
|
2451
|
-
setSandboxReady(true);
|
|
2452
2458
|
sandbox.run(`
|
|
2453
2459
|
var s = document.createElement('style');
|
|
2454
2460
|
s.textContent = 'html, body { overflow: hidden !important; }';
|
|
@@ -2473,7 +2479,6 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2473
2479
|
sandboxRef.current = null;
|
|
2474
2480
|
}
|
|
2475
2481
|
sandboxReadyRef.current = false;
|
|
2476
|
-
setSandboxReady(false);
|
|
2477
2482
|
setAutoHeight(null);
|
|
2478
2483
|
};
|
|
2479
2484
|
}, [
|
|
@@ -2504,7 +2509,7 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2504
2509
|
const generationDone = content.generating === false;
|
|
2505
2510
|
useEffect(() => {
|
|
2506
2511
|
const sandbox = sandboxRef.current;
|
|
2507
|
-
if (!generationDone || !
|
|
2512
|
+
if (!generationDone || !sandbox) return;
|
|
2508
2513
|
let handled = false;
|
|
2509
2514
|
const onMessage = (e) => {
|
|
2510
2515
|
if (handled) return;
|
|
@@ -2533,7 +2538,7 @@ const OpenGenerativeUIActivityRendererInner = React.memo(function OpenGenerative
|
|
|
2533
2538
|
return () => {
|
|
2534
2539
|
window.removeEventListener("message", onMessage);
|
|
2535
2540
|
};
|
|
2536
|
-
}, [generationDone
|
|
2541
|
+
}, [generationDone]);
|
|
2537
2542
|
const height = autoHeight ?? initialHeight;
|
|
2538
2543
|
const isGenerating = content.generating !== false;
|
|
2539
2544
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -3484,9 +3489,15 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
|
3484
3489
|
}, [value, warningMessage]);
|
|
3485
3490
|
return value;
|
|
3486
3491
|
}
|
|
3487
|
-
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI,
|
|
3492
|
+
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
|
|
3488
3493
|
const [shouldRenderInspector, setShouldRenderInspector] = useState(false);
|
|
3489
|
-
|
|
3494
|
+
useEffect(() => {
|
|
3495
|
+
setShouldRenderInspector(shouldEnableInspector({
|
|
3496
|
+
enableInspector,
|
|
3497
|
+
isBrowser: true,
|
|
3498
|
+
isDevelopment: process.env.NODE_ENV === "development"
|
|
3499
|
+
}));
|
|
3500
|
+
}, [enableInspector]);
|
|
3490
3501
|
const [inspectorOpenRequest, setInspectorOpenRequest] = useState(null);
|
|
3491
3502
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = useState(false);
|
|
3492
3503
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = useState(false);
|
|
@@ -3495,68 +3506,13 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3495
3506
|
const a2uiCatalogProvided = !!a2ui?.catalog;
|
|
3496
3507
|
const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
|
|
3497
3508
|
const [runtimeLicenseStatus, setRuntimeLicenseStatus] = useState(void 0);
|
|
3498
|
-
useEffect(() => {
|
|
3499
|
-
if (typeof window === "undefined") return;
|
|
3500
|
-
const isLocalhost = new Set(["localhost", "127.0.0.1"]).has(window.location?.hostname ?? "");
|
|
3501
|
-
const canShowLocalInspectorAction = process.env.NODE_ENV === "development" && isLocalhost;
|
|
3502
|
-
if (showDevConsole === true) {
|
|
3503
|
-
setShouldRenderInspector(true);
|
|
3504
|
-
setIsLocalInspectorEnabled(canShowLocalInspectorAction);
|
|
3505
|
-
} else if (showDevConsole === "auto") if (isLocalhost) {
|
|
3506
|
-
setShouldRenderInspector(true);
|
|
3507
|
-
setIsLocalInspectorEnabled(canShowLocalInspectorAction);
|
|
3508
|
-
} else {
|
|
3509
|
-
setShouldRenderInspector(false);
|
|
3510
|
-
setIsLocalInspectorEnabled(false);
|
|
3511
|
-
}
|
|
3512
|
-
else {
|
|
3513
|
-
setShouldRenderInspector(false);
|
|
3514
|
-
setIsLocalInspectorEnabled(false);
|
|
3515
|
-
}
|
|
3516
|
-
}, [showDevConsole]);
|
|
3517
3509
|
const requestInspectorOpen = useCallback((request) => {
|
|
3518
3510
|
setInspectorOpenRequest({ ...request });
|
|
3519
3511
|
}, []);
|
|
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]);
|
|
3551
3512
|
const inspectorContextValue = useMemo(() => ({
|
|
3552
|
-
|
|
3553
|
-
openInspector: requestInspectorOpen
|
|
3554
|
-
|
|
3555
|
-
}), [
|
|
3556
|
-
isLocalInspectorEnabled,
|
|
3557
|
-
requestInspectorOpen,
|
|
3558
|
-
saveEventSnippet
|
|
3559
|
-
]);
|
|
3513
|
+
isInspectorEnabled: shouldRenderInspector,
|
|
3514
|
+
openInspector: requestInspectorOpen
|
|
3515
|
+
}), [shouldRenderInspector, requestInspectorOpen]);
|
|
3560
3516
|
const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
|
|
3561
3517
|
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
3562
3518
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
@@ -3897,7 +3853,6 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3897
3853
|
value: inspectorContextValue,
|
|
3898
3854
|
children: [children, shouldRenderInspector ? /* @__PURE__ */ jsx(CopilotKitInspector, {
|
|
3899
3855
|
core: copilotkit,
|
|
3900
|
-
defaultAnchor: inspectorDefaultAnchor,
|
|
3901
3856
|
openRequest: inspectorOpenRequest
|
|
3902
3857
|
}) : null]
|
|
3903
3858
|
}),
|
|
@@ -5933,191 +5888,25 @@ function useLearningContainersInCurrentThread({ learningContainers }) {
|
|
|
5933
5888
|
});
|
|
5934
5889
|
}
|
|
5935
5890
|
|
|
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
|
-
|
|
6054
5891
|
//#endregion
|
|
6055
5892
|
//#region src/v2/components/chat/CopilotChatToolCallsView.tsx
|
|
6056
5893
|
function CopilotChatToolCallsView({ message, messages = [] }) {
|
|
6057
5894
|
const renderToolCall = useRenderToolCall();
|
|
6058
|
-
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6059
|
-
const chatConfiguration = useCopilotChatConfiguration();
|
|
6060
|
-
const labels = chatConfiguration?.labels ?? CopilotChatDefaultLabels;
|
|
6061
5895
|
if (!message.toolCalls || message.toolCalls.length === 0) return null;
|
|
6062
5896
|
return /* @__PURE__ */ jsx(Fragment$1, { children: message.toolCalls.map((toolCall) => {
|
|
6063
|
-
const
|
|
5897
|
+
const toolMessage = messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
|
|
5898
|
+
return /* @__PURE__ */ jsx(React.Fragment, { children: renderToolCall({
|
|
6064
5899
|
toolCall,
|
|
6065
|
-
toolMessage
|
|
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);
|
|
5900
|
+
toolMessage
|
|
5901
|
+
}) }, toolCall.id);
|
|
6082
5902
|
}) });
|
|
6083
5903
|
}
|
|
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
|
-
}
|
|
6115
5904
|
|
|
6116
5905
|
//#endregion
|
|
6117
5906
|
//#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
|
|
6118
|
-
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton,
|
|
5907
|
+
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
6119
5908
|
useKatexStyles();
|
|
6120
|
-
const {
|
|
5909
|
+
const { isInspectorEnabled, openInspector } = useCopilotKitInspector();
|
|
6121
5910
|
const chatConfiguration = useCopilotChatConfiguration();
|
|
6122
5911
|
const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
6123
5912
|
const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
@@ -6130,17 +5919,6 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6130
5919
|
threadId: chatConfiguration?.threadId,
|
|
6131
5920
|
agentId: chatConfiguration?.agentId
|
|
6132
5921
|
}) });
|
|
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
|
-
} });
|
|
6144
5922
|
const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
|
|
6145
5923
|
const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
|
|
6146
5924
|
const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
|
|
@@ -6148,8 +5926,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6148
5926
|
className: "cpk:flex cpk:items-center cpk:gap-1",
|
|
6149
5927
|
children: [
|
|
6150
5928
|
boundCopyButton,
|
|
6151
|
-
|
|
6152
|
-
isLocalInspectorEnabled && hasContent && boundSaveSnippetButton,
|
|
5929
|
+
isInspectorEnabled && boundInspectorButton,
|
|
6153
5930
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
6154
5931
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
6155
5932
|
(onReadAloud || readAloudButton) && boundReadAloudButton,
|
|
@@ -6161,8 +5938,9 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6161
5938
|
message,
|
|
6162
5939
|
messages
|
|
6163
5940
|
});
|
|
5941
|
+
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
6164
5942
|
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
6165
|
-
const shouldShowToolbar = toolbarVisible && (hasContent ||
|
|
5943
|
+
const shouldShowToolbar = toolbarVisible && (hasContent || isInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
|
|
6166
5944
|
if (children) return /* @__PURE__ */ jsx("div", {
|
|
6167
5945
|
"data-copilotkit": true,
|
|
6168
5946
|
style: { display: "contents" },
|
|
@@ -6172,7 +5950,6 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6172
5950
|
toolCallsView: boundToolCallsView,
|
|
6173
5951
|
copyButton: boundCopyButton,
|
|
6174
5952
|
inspectorButton: boundInspectorButton,
|
|
6175
|
-
saveSnippetButton: boundSaveSnippetButton,
|
|
6176
5953
|
thumbsUpButton: boundThumbsUpButton,
|
|
6177
5954
|
thumbsDownButton: boundThumbsDownButton,
|
|
6178
5955
|
readAloudButton: boundReadAloudButton,
|
|
@@ -6319,7 +6096,7 @@ function CopilotKitColoredIcon() {
|
|
|
6319
6096
|
className: twMerge("cpk:w-full cpk:bg-transparent cpk:flex cpk:items-center cpk:-ml-[5px] cpk:-mt-[0px]", className),
|
|
6320
6097
|
...props
|
|
6321
6098
|
});
|
|
6322
|
-
const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, tooltip, children, ...props }) => {
|
|
6099
|
+
const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, tooltip, tooltipClassName, children, ...props }) => {
|
|
6323
6100
|
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
6324
6101
|
asChild: true,
|
|
6325
6102
|
children: /* @__PURE__ */ jsx(Button, {
|
|
@@ -6331,6 +6108,7 @@ function CopilotKitColoredIcon() {
|
|
|
6331
6108
|
})
|
|
6332
6109
|
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
6333
6110
|
side: "bottom",
|
|
6111
|
+
className: tooltipClassName,
|
|
6334
6112
|
children: tooltip ?? /* @__PURE__ */ jsx("p", { children: title })
|
|
6335
6113
|
})] });
|
|
6336
6114
|
};
|
|
@@ -6364,29 +6142,30 @@ function CopilotKitColoredIcon() {
|
|
|
6364
6142
|
children: copied ? /* @__PURE__ */ jsx(Check, { className: "cpk:size-[18px]" }) : /* @__PURE__ */ jsx(Copy, { className: "cpk:size-[18px]" })
|
|
6365
6143
|
});
|
|
6366
6144
|
};
|
|
6367
|
-
_CopilotChatAssistantMessage.InspectorButton = ({ title, ...props }) => {
|
|
6145
|
+
_CopilotChatAssistantMessage.InspectorButton = ({ title, className, ...props }) => {
|
|
6368
6146
|
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6369
6147
|
const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
|
|
6370
|
-
const
|
|
6371
|
-
|
|
6372
|
-
return /* @__PURE__ */ jsx(ToolbarButton, {
|
|
6148
|
+
const accessibleLabel = `${primaryLabel} (local only)`;
|
|
6149
|
+
return /* @__PURE__ */ jsxs(ToolbarButton, {
|
|
6373
6150
|
"data-testid": "copilot-inspector-button",
|
|
6374
6151
|
title: accessibleLabel,
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
className: "cpk:text-[10px] cpk:opacity-65",
|
|
6379
|
-
children: localOnlyLabel
|
|
6380
|
-
})]
|
|
6381
|
-
}),
|
|
6152
|
+
className: twMerge("cpk:w-auto cpk:gap-1.5 cpk:px-2", className),
|
|
6153
|
+
tooltipClassName: "cpk:max-w-64 cpk:text-left cpk:leading-4",
|
|
6154
|
+
tooltip: "View this message in the Inspector to get more information. This button and the inspector only display during local development (localhost, dev env).",
|
|
6382
6155
|
...props,
|
|
6383
|
-
children:
|
|
6156
|
+
children: [
|
|
6157
|
+
/* @__PURE__ */ jsx(CopilotKitColoredIcon, {}),
|
|
6158
|
+
/* @__PURE__ */ jsx("span", {
|
|
6159
|
+
className: "cpk:font-medium",
|
|
6160
|
+
children: primaryLabel
|
|
6161
|
+
}),
|
|
6162
|
+
/* @__PURE__ */ jsx("span", {
|
|
6163
|
+
className: "cpk:text-xs cpk:text-muted-foreground",
|
|
6164
|
+
children: "(local only)"
|
|
6165
|
+
})
|
|
6166
|
+
]
|
|
6384
6167
|
});
|
|
6385
6168
|
};
|
|
6386
|
-
_CopilotChatAssistantMessage.SaveSnippetButton = (props) => /* @__PURE__ */ jsx(SaveSnippetIconButton, {
|
|
6387
|
-
"data-testid": "copilot-save-snippet-button",
|
|
6388
|
-
...props
|
|
6389
|
-
});
|
|
6390
6169
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
6391
6170
|
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6392
6171
|
return /* @__PURE__ */ jsx(ToolbarButton, {
|
|
@@ -6428,7 +6207,6 @@ CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistant
|
|
|
6428
6207
|
CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
|
|
6429
6208
|
CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
|
|
6430
6209
|
CopilotChatAssistantMessage.InspectorButton.displayName = "CopilotChatAssistantMessage.InspectorButton";
|
|
6431
|
-
CopilotChatAssistantMessage.SaveSnippetButton.displayName = "CopilotChatAssistantMessage.SaveSnippetButton";
|
|
6432
6210
|
CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
|
|
6433
6211
|
CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
|
|
6434
6212
|
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
@@ -6799,8 +6577,6 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
|
|
|
6799
6577
|
const isLatest = messages?.[messages.length - 1]?.id === message.id;
|
|
6800
6578
|
const isStreaming = !!(isRunning && isLatest);
|
|
6801
6579
|
const hasContent = !!(message.content && message.content.length > 0);
|
|
6802
|
-
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6803
|
-
const chatConfiguration = useCopilotChatConfiguration();
|
|
6804
6580
|
const startTimeRef = useRef(null);
|
|
6805
6581
|
const [elapsed, setElapsed] = useState(0);
|
|
6806
6582
|
useEffect(() => {
|
|
@@ -6860,16 +6636,7 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
|
|
|
6860
6636
|
className: twMerge("cpk:my-1", className),
|
|
6861
6637
|
"data-message-id": message.id,
|
|
6862
6638
|
...props,
|
|
6863
|
-
children: [
|
|
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]
|
|
6639
|
+
children: [boundHeader, boundToggle]
|
|
6873
6640
|
});
|
|
6874
6641
|
}
|
|
6875
6642
|
(function(_CopilotChatReasoningMessage) {
|
|
@@ -7388,33 +7155,8 @@ const MemoizedUserMessage = React.memo(function MemoizedUserMessage({ message, U
|
|
|
7388
7155
|
/**
|
|
7389
7156
|
* Memoized wrapper for activity messages to prevent re-renders when other messages change.
|
|
7390
7157
|
*/
|
|
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
|
-
}
|
|
7413
7158
|
const MemoizedActivityMessage = React.memo(function MemoizedActivityMessage({ message, renderActivityMessage }) {
|
|
7414
|
-
return
|
|
7415
|
-
message,
|
|
7416
|
-
children: renderActivityMessage(message)
|
|
7417
|
-
});
|
|
7159
|
+
return renderActivityMessage(message);
|
|
7418
7160
|
}, (prevProps, nextProps) => {
|
|
7419
7161
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
7420
7162
|
if (prevProps.message.activityType !== nextProps.message.activityType) return false;
|
|
@@ -11769,20 +11511,42 @@ function CoAgentStateRenderBridge(props) {
|
|
|
11769
11511
|
|
|
11770
11512
|
//#endregion
|
|
11771
11513
|
//#region src/v1-deprecated/components/CopilotListeners.tsx
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
const
|
|
11514
|
+
function isPredictStateTool(value) {
|
|
11515
|
+
if (value === null || typeof value !== "object") return false;
|
|
11516
|
+
const config = value;
|
|
11517
|
+
return typeof config.tool === "string" && typeof config.state_key === "string" && (config.tool_argument === void 0 || typeof config.tool_argument === "string");
|
|
11518
|
+
}
|
|
11519
|
+
function getPredictStateUpdate(config, toolCallName, partialToolCallArgs) {
|
|
11520
|
+
if (config.tool !== toolCallName) return void 0;
|
|
11521
|
+
const emittedState = typeof partialToolCallArgs === "string" ? partialJSONParse(partialToolCallArgs) : partialToolCallArgs;
|
|
11522
|
+
if (emittedState === null || typeof emittedState !== "object") return;
|
|
11523
|
+
if (config.tool_argument) {
|
|
11524
|
+
if (!(config.tool_argument in emittedState)) return void 0;
|
|
11525
|
+
return { [config.state_key]: emittedState[config.tool_argument] };
|
|
11526
|
+
}
|
|
11527
|
+
return { [config.state_key]: emittedState };
|
|
11528
|
+
}
|
|
11529
|
+
function createPredictStateSubscriber(agent, predictStateToolsRef) {
|
|
11530
|
+
return {
|
|
11775
11531
|
onCustomEvent: ({ event }) => {
|
|
11776
|
-
if (event.name === "PredictState") predictStateToolsRef.current = event.value;
|
|
11532
|
+
if (event.name === "PredictState") predictStateToolsRef.current = Array.isArray(event.value) ? event.value.filter(isPredictStateTool) : [];
|
|
11777
11533
|
},
|
|
11778
11534
|
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
const
|
|
11782
|
-
|
|
11535
|
+
const updates = {};
|
|
11536
|
+
predictStateToolsRef.current.forEach((config) => {
|
|
11537
|
+
const update = getPredictStateUpdate(config, toolCallName, partialToolCallArgs);
|
|
11538
|
+
if (update) Object.assign(updates, update);
|
|
11539
|
+
});
|
|
11540
|
+
if (Object.keys(updates).length > 0) agent.setState({
|
|
11541
|
+
...agent.state,
|
|
11542
|
+
...updates
|
|
11783
11543
|
});
|
|
11784
11544
|
}
|
|
11785
|
-
}
|
|
11545
|
+
};
|
|
11546
|
+
}
|
|
11547
|
+
const usePredictStateSubscription = (agent) => {
|
|
11548
|
+
const predictStateToolsRef = useRef([]);
|
|
11549
|
+
const getSubscriber = useCallback((subscriptionAgent) => createPredictStateSubscriber(subscriptionAgent, predictStateToolsRef), []);
|
|
11786
11550
|
useEffect(() => {
|
|
11787
11551
|
if (!agent) return;
|
|
11788
11552
|
const subscriber = getSubscriber(agent);
|
|
@@ -11841,7 +11605,6 @@ function CopilotListeners() {
|
|
|
11841
11605
|
//#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
|
|
11842
11606
|
function CopilotKit({ children, ...props }) {
|
|
11843
11607
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
11844
|
-
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
11845
11608
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
11846
11609
|
const renderArr = useMemo(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
11847
11610
|
const { onError: _onError, ...v2Props } = props;
|
|
@@ -11854,7 +11617,7 @@ function CopilotKit({ children, ...props }) {
|
|
|
11854
11617
|
threadId: props.threadId,
|
|
11855
11618
|
children: /* @__PURE__ */ jsx(CopilotKitProvider, {
|
|
11856
11619
|
...v2Props,
|
|
11857
|
-
|
|
11620
|
+
enableInspector: props.enableInspector,
|
|
11858
11621
|
renderCustomMessages: renderArr,
|
|
11859
11622
|
children: /* @__PURE__ */ jsx(CopilotKitInternal, {
|
|
11860
11623
|
...props,
|
|
@@ -12337,4 +12100,4 @@ function validateProps(props) {
|
|
|
12337
12100
|
|
|
12338
12101
|
//#endregion
|
|
12339
12102
|
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 };
|
|
12340
|
-
//# sourceMappingURL=copilotkit-
|
|
12103
|
+
//# sourceMappingURL=copilotkit-JdHy0xdu.mjs.map
|