@copilotkit/react-core 1.57.0 → 1.57.1-canary.1778272612
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-CPe2-340.mjs → copilotkit-3XTEoVQO.mjs} +1367 -1200
- package/dist/copilotkit-3XTEoVQO.mjs.map +1 -0
- package/dist/{copilotkit-DFaI4j2r.d.mts → copilotkit-BCJ2yvV6.d.mts} +68 -8
- package/dist/copilotkit-BCJ2yvV6.d.mts.map +1 -0
- package/dist/{copilotkit-Dg4r4Gi_.d.cts → copilotkit-CBbSvze0.d.cts} +68 -8
- package/dist/copilotkit-CBbSvze0.d.cts.map +1 -0
- package/dist/{copilotkit-DGbvw8n2.cjs → copilotkit-Dnj9pi4m.cjs} +1369 -1196
- package/dist/copilotkit-Dnj9pi4m.cjs.map +1 -0
- package/dist/index.cjs +2 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +733 -610
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.cjs +135 -0
- package/dist/v2/context.cjs.map +1 -0
- package/dist/v2/context.d.cts +148 -0
- package/dist/v2/context.d.cts.map +1 -0
- package/dist/v2/context.d.mts +148 -0
- package/dist/v2/context.d.mts.map +1 -0
- package/dist/v2/context.mjs +129 -0
- package/dist/v2/context.mjs.map +1 -0
- package/dist/v2/headless.cjs +1043 -0
- package/dist/v2/headless.cjs.map +1 -0
- package/dist/v2/headless.d.cts +605 -0
- package/dist/v2/headless.d.cts.map +1 -0
- package/dist/v2/headless.d.mts +512 -0
- package/dist/v2/headless.d.mts.map +1 -0
- package/dist/v2/headless.mjs +997 -0
- package/dist/v2/headless.mjs.map +1 -0
- package/dist/v2/index.cjs +2 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +1385 -1204
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +14 -6
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +5 -6
- package/src/hooks/use-copilot-chat_internal.ts +0 -1
- package/src/v2/components/chat/CopilotChat.tsx +2 -1
- package/src/v2/components/chat/CopilotChatMessageView.tsx +24 -9
- package/src/v2/components/chat/CopilotChatView.tsx +2 -2
- package/src/v2/components/chat/CopilotSidebar.tsx +5 -1
- package/src/v2/components/chat/CopilotSidebarView.tsx +24 -10
- package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +1 -3
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +29 -25
- package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +159 -0
- package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +5 -60
- package/src/v2/components/index.ts +1 -0
- package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +286 -0
- package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +464 -0
- package/src/v2/components/intelligence-indicator/index.ts +2 -0
- package/src/v2/context.ts +62 -0
- package/src/v2/headless.ts +42 -0
- package/src/v2/hooks/__tests__/standard-schema.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-agent-context.test.tsx +3 -3
- package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +3 -3
- package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +85 -85
- package/src/v2/hooks/__tests__/use-interrupt.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-render-tool.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-threads.test.tsx +2 -2
- package/src/v2/hooks/__tests__/zod-regression.test.tsx +2 -2
- package/src/v2/hooks/use-agent-context.tsx +1 -1
- package/src/v2/hooks/use-agent.tsx +9 -118
- package/src/v2/hooks/use-configure-suggestions.tsx +1 -1
- package/src/v2/hooks/use-default-render-tool.tsx +18 -1
- package/src/v2/hooks/use-frontend-tool.tsx +2 -2
- package/src/v2/hooks/use-human-in-the-loop.tsx +1 -1
- package/src/v2/hooks/use-interrupt.tsx +1 -1
- package/src/v2/hooks/use-render-activity-message.tsx +3 -11
- package/src/v2/hooks/use-render-custom-messages.tsx +1 -6
- package/src/v2/hooks/use-render-tool-call.tsx +36 -6
- package/src/v2/hooks/use-render-tool.tsx +2 -2
- package/src/v2/hooks/use-suggestions.tsx +1 -1
- package/src/v2/hooks/use-threads.tsx +1 -1
- package/src/v2/providers/CopilotKitProvider.tsx +19 -59
- package/src/v2/styles/globals.css +118 -0
- package/tsdown.config.ts +75 -0
- package/dist/copilotkit-CPe2-340.mjs.map +0 -1
- package/dist/copilotkit-DFaI4j2r.d.mts.map +0 -1
- package/dist/copilotkit-DGbvw8n2.cjs.map +0 -1
- package/dist/copilotkit-Dg4r4Gi_.d.cts.map +0 -1
- package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +0 -333
package/dist/v2/index.umd.js
CHANGED
|
@@ -1336,342 +1336,846 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1336
1336
|
}
|
|
1337
1337
|
|
|
1338
1338
|
//#endregion
|
|
1339
|
-
//#region src/v2/
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1339
|
+
//#region src/v2/lib/react-core.ts
|
|
1340
|
+
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
1341
|
+
constructor(config) {
|
|
1342
|
+
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
1343
|
+
super(config);
|
|
1344
|
+
this._renderToolCalls = [];
|
|
1345
|
+
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
1346
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1347
|
+
this._renderCustomMessages = [];
|
|
1348
|
+
this._renderActivityMessages = [];
|
|
1349
|
+
this._interruptElement = null;
|
|
1350
|
+
this._renderToolCalls = (_config$renderToolCal = config.renderToolCalls) !== null && _config$renderToolCal !== void 0 ? _config$renderToolCal : [];
|
|
1351
|
+
this._renderCustomMessages = (_config$renderCustomM = config.renderCustomMessages) !== null && _config$renderCustomM !== void 0 ? _config$renderCustomM : [];
|
|
1352
|
+
this._renderActivityMessages = (_config$renderActivit = config.renderActivityMessages) !== null && _config$renderActivit !== void 0 ? _config$renderActivit : [];
|
|
1353
|
+
}
|
|
1354
|
+
get renderCustomMessages() {
|
|
1355
|
+
return this._renderCustomMessages;
|
|
1356
|
+
}
|
|
1357
|
+
get renderActivityMessages() {
|
|
1358
|
+
return this._renderActivityMessages;
|
|
1359
|
+
}
|
|
1360
|
+
get renderToolCalls() {
|
|
1361
|
+
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
1362
|
+
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
1363
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1364
|
+
for (const rc of this._renderToolCalls) {
|
|
1365
|
+
var _rc$agentId;
|
|
1366
|
+
merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
|
|
1367
|
+
}
|
|
1368
|
+
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
1369
|
+
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
1370
|
+
return this._cachedMergedRenderToolCalls;
|
|
1371
|
+
}
|
|
1372
|
+
setRenderActivityMessages(renderers) {
|
|
1373
|
+
this._renderActivityMessages = renderers;
|
|
1374
|
+
}
|
|
1375
|
+
setRenderCustomMessages(renderers) {
|
|
1376
|
+
this._renderCustomMessages = renderers;
|
|
1377
|
+
}
|
|
1378
|
+
setRenderToolCalls(renderToolCalls) {
|
|
1379
|
+
this._renderToolCalls = renderToolCalls;
|
|
1380
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1381
|
+
this._notifyRenderToolCallsChanged();
|
|
1382
|
+
}
|
|
1383
|
+
addHookRenderToolCall(entry) {
|
|
1384
|
+
var _entry$agentId;
|
|
1385
|
+
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
1386
|
+
this._hookRenderToolCalls.set(key, entry);
|
|
1387
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1388
|
+
this._notifyRenderToolCallsChanged();
|
|
1389
|
+
}
|
|
1390
|
+
removeHookRenderToolCall(name, agentId) {
|
|
1391
|
+
const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
|
|
1392
|
+
if (this._hookRenderToolCalls.delete(key)) {
|
|
1393
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1394
|
+
this._notifyRenderToolCallsChanged();
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
_notifyRenderToolCallsChanged() {
|
|
1398
|
+
this.notifySubscribers((subscriber) => {
|
|
1399
|
+
const reactSubscriber = subscriber;
|
|
1400
|
+
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
1401
|
+
copilotkit: this,
|
|
1402
|
+
renderToolCalls: this.renderToolCalls
|
|
1351
1403
|
});
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1404
|
+
}, "Subscriber onRenderToolCallsChanged error:");
|
|
1405
|
+
}
|
|
1406
|
+
get interruptElement() {
|
|
1407
|
+
return this._interruptElement;
|
|
1408
|
+
}
|
|
1409
|
+
setInterruptElement(element) {
|
|
1410
|
+
this._interruptElement = element;
|
|
1411
|
+
this.notifySubscribers((subscriber) => {
|
|
1412
|
+
var _reactSubscriber$onIn;
|
|
1413
|
+
const reactSubscriber = subscriber;
|
|
1414
|
+
(_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
|
|
1415
|
+
copilotkit: this,
|
|
1416
|
+
interruptElement: this._interruptElement
|
|
1417
|
+
});
|
|
1418
|
+
}, "Subscriber onInterruptElementChanged error:");
|
|
1419
|
+
}
|
|
1420
|
+
subscribe(subscriber) {
|
|
1421
|
+
return super.subscribe(subscriber);
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Wait for pending React state updates before the follow-up agent run.
|
|
1425
|
+
*
|
|
1426
|
+
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
1427
|
+
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
1428
|
+
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
1429
|
+
* synchronously after React commits that batch.
|
|
1430
|
+
*
|
|
1431
|
+
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
1432
|
+
* MessageChannel task runs first, committing the pending state and running
|
|
1433
|
+
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
1434
|
+
* call then reads fresh context.
|
|
1435
|
+
*/
|
|
1436
|
+
async waitForPendingFrameworkUpdates() {
|
|
1437
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1438
|
+
}
|
|
1363
1439
|
};
|
|
1364
|
-
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
1365
1440
|
|
|
1366
1441
|
//#endregion
|
|
1367
|
-
//#region src/v2/
|
|
1368
|
-
const
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
bottom: "8px",
|
|
1374
|
-
left: "50%",
|
|
1375
|
-
transform: "translateX(-50%)",
|
|
1376
|
-
zIndex: 99999,
|
|
1377
|
-
display: "inline-flex",
|
|
1378
|
-
alignItems: "center",
|
|
1379
|
-
gap: "12px",
|
|
1380
|
-
whiteSpace: "nowrap",
|
|
1381
|
-
padding: "8px 16px",
|
|
1382
|
-
fontSize: "13px",
|
|
1383
|
-
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
1384
|
-
borderRadius: "6px",
|
|
1385
|
-
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
|
|
1386
|
-
},
|
|
1387
|
-
info: {
|
|
1388
|
-
backgroundColor: "#eff6ff",
|
|
1389
|
-
border: "1px solid #93c5fd",
|
|
1390
|
-
color: "#1e40af"
|
|
1391
|
-
},
|
|
1392
|
-
warning: {
|
|
1393
|
-
backgroundColor: "#fffbeb",
|
|
1394
|
-
border: "1px solid #fbbf24",
|
|
1395
|
-
color: "#92400e"
|
|
1396
|
-
},
|
|
1397
|
-
critical: {
|
|
1398
|
-
backgroundColor: "#fef2f2",
|
|
1399
|
-
border: "1px solid #fca5a5",
|
|
1400
|
-
color: "#991b1b"
|
|
1401
|
-
}
|
|
1402
|
-
};
|
|
1403
|
-
function getSeverityStyle(severity) {
|
|
1404
|
-
switch (severity) {
|
|
1405
|
-
case "warning": return BANNER_STYLES.warning;
|
|
1406
|
-
case "critical": return BANNER_STYLES.critical;
|
|
1407
|
-
default: return BANNER_STYLES.info;
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
function BannerShell({ severity, message, actionLabel, actionUrl, onDismiss }) {
|
|
1442
|
+
//#region src/v2/context.ts
|
|
1443
|
+
const CopilotKitContext = (0, react.createContext)(null);
|
|
1444
|
+
const useCopilotKit = () => {
|
|
1445
|
+
const context = (0, react.useContext)(CopilotKitContext);
|
|
1446
|
+
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
1447
|
+
if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1411
1448
|
(0, react.useEffect)(() => {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1449
|
+
const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
|
|
1450
|
+
forceUpdate();
|
|
1451
|
+
} });
|
|
1415
1452
|
return () => {
|
|
1416
|
-
|
|
1453
|
+
subscription.unsubscribe();
|
|
1417
1454
|
};
|
|
1418
1455
|
}, []);
|
|
1419
|
-
return
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
children: actionLabel
|
|
1440
|
-
}), onDismiss && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1441
|
-
onClick: onDismiss,
|
|
1442
|
-
style: {
|
|
1443
|
-
background: "none",
|
|
1444
|
-
border: "none",
|
|
1445
|
-
cursor: "pointer",
|
|
1446
|
-
color: "inherit",
|
|
1447
|
-
fontSize: "16px"
|
|
1448
|
-
},
|
|
1449
|
-
children: "×"
|
|
1450
|
-
})]
|
|
1451
|
-
})]
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
function LicenseWarningBanner({ type, featureName, expiryDate, graceRemaining, onDismiss }) {
|
|
1455
|
-
switch (type) {
|
|
1456
|
-
case "no_license": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1457
|
-
severity: "info",
|
|
1458
|
-
message: "Powered by CopilotKit",
|
|
1459
|
-
actionLabel: "Get a license",
|
|
1460
|
-
actionUrl: "https://copilotkit.ai/pricing",
|
|
1461
|
-
onDismiss
|
|
1462
|
-
});
|
|
1463
|
-
case "feature_unlicensed": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1464
|
-
severity: "warning",
|
|
1465
|
-
message: `⚠ The "${featureName}" feature requires a CopilotKit license.`,
|
|
1466
|
-
actionLabel: "Get a license",
|
|
1467
|
-
actionUrl: "https://copilotkit.ai/pricing",
|
|
1468
|
-
onDismiss
|
|
1469
|
-
});
|
|
1470
|
-
case "expiring": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1471
|
-
severity: "warning",
|
|
1472
|
-
message: `Your CopilotKit license expires in ${graceRemaining} day${graceRemaining !== 1 ? "s" : ""}. Please renew.`,
|
|
1473
|
-
actionLabel: "Renew",
|
|
1474
|
-
actionUrl: "https://cloud.copilotkit.ai",
|
|
1475
|
-
onDismiss
|
|
1476
|
-
});
|
|
1477
|
-
case "expired": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1478
|
-
severity: "critical",
|
|
1479
|
-
message: `Your CopilotKit license expired${expiryDate ? ` on ${expiryDate}` : ""}. Please renew at copilotkit.ai/pricing`,
|
|
1480
|
-
actionLabel: "Renew now",
|
|
1481
|
-
actionUrl: "https://copilotkit.ai/pricing",
|
|
1482
|
-
onDismiss
|
|
1483
|
-
});
|
|
1484
|
-
case "invalid": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1485
|
-
severity: "critical",
|
|
1486
|
-
message: "Invalid CopilotKit license token. Please check your configuration.",
|
|
1487
|
-
actionLabel: "Get a license",
|
|
1488
|
-
actionUrl: "https://copilotkit.ai/pricing",
|
|
1489
|
-
onDismiss
|
|
1490
|
-
});
|
|
1491
|
-
default: return null;
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
function InlineFeatureWarning({ featureName }) {
|
|
1495
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1496
|
-
style: {
|
|
1497
|
-
padding: "8px 12px",
|
|
1498
|
-
backgroundColor: "#fffbeb",
|
|
1499
|
-
border: "1px solid #fbbf24",
|
|
1500
|
-
borderRadius: "6px",
|
|
1501
|
-
fontSize: "13px",
|
|
1502
|
-
color: "#92400e",
|
|
1503
|
-
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif"
|
|
1504
|
-
},
|
|
1505
|
-
children: [
|
|
1506
|
-
"⚠ The \"",
|
|
1507
|
-
featureName,
|
|
1508
|
-
"\" feature requires a CopilotKit license.",
|
|
1509
|
-
" ",
|
|
1510
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1511
|
-
href: "https://copilotkit.ai/pricing",
|
|
1512
|
-
target: "_blank",
|
|
1513
|
-
rel: "noopener noreferrer",
|
|
1514
|
-
style: {
|
|
1515
|
-
color: "#b45309",
|
|
1516
|
-
textDecoration: "underline"
|
|
1517
|
-
},
|
|
1518
|
-
children: "Get one at copilotkit.ai/pricing"
|
|
1519
|
-
})
|
|
1520
|
-
]
|
|
1521
|
-
});
|
|
1456
|
+
return context;
|
|
1457
|
+
};
|
|
1458
|
+
const LicenseContext = (0, react.createContext)({
|
|
1459
|
+
status: null,
|
|
1460
|
+
license: null,
|
|
1461
|
+
checkFeature: () => true,
|
|
1462
|
+
getLimit: () => null
|
|
1463
|
+
});
|
|
1464
|
+
const useLicenseContext = () => (0, react.useContext)(LicenseContext);
|
|
1465
|
+
|
|
1466
|
+
//#endregion
|
|
1467
|
+
//#region src/v2/types/defineToolCallRenderer.ts
|
|
1468
|
+
function defineToolCallRenderer(def) {
|
|
1469
|
+
const argsSchema = def.name === "*" && !def.args ? zod.z.any() : def.args;
|
|
1470
|
+
return {
|
|
1471
|
+
name: def.name,
|
|
1472
|
+
args: argsSchema,
|
|
1473
|
+
render: def.render,
|
|
1474
|
+
...def.agentId ? { agentId: def.agentId } : {}
|
|
1475
|
+
};
|
|
1522
1476
|
}
|
|
1523
1477
|
|
|
1524
1478
|
//#endregion
|
|
1525
|
-
//#region src/v2/
|
|
1526
|
-
const
|
|
1527
|
-
function buildSandboxHTML(extraCspDomains) {
|
|
1528
|
-
const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
1529
|
-
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
1530
|
-
const extra = (extraCspDomains === null || extraCspDomains === void 0 ? void 0 : extraCspDomains.length) ? " " + extraCspDomains.join(" ") : "";
|
|
1531
|
-
return `<!doctype html>
|
|
1532
|
-
<html>
|
|
1533
|
-
<head>
|
|
1534
|
-
<meta charset="utf-8" />
|
|
1535
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${baseScriptSrc + extra}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${baseFrameSrc + extra}; base-uri 'self';" />
|
|
1536
|
-
<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>
|
|
1537
|
-
</head>
|
|
1538
|
-
<body>
|
|
1539
|
-
<script>
|
|
1540
|
-
if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
|
|
1541
|
-
const inner=document.createElement("iframe");
|
|
1542
|
-
inner.style="width:100%;height:100%;border:none;";
|
|
1543
|
-
inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
|
|
1544
|
-
document.body.appendChild(inner);
|
|
1545
|
-
window.addEventListener("message",async(event)=>{
|
|
1546
|
-
if(event.source===window.parent){
|
|
1547
|
-
if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
|
|
1548
|
-
const{html,sandbox}=event.data.params;
|
|
1549
|
-
if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
|
|
1550
|
-
if(typeof html==="string")inner.srcdoc=html;
|
|
1551
|
-
}else if(inner&&inner.contentWindow){
|
|
1552
|
-
inner.contentWindow.postMessage(event.data,"*");
|
|
1553
|
-
}
|
|
1554
|
-
}else if(event.source===inner.contentWindow){
|
|
1555
|
-
window.parent.postMessage(event.data,"*");
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1558
|
-
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
|
|
1559
|
-
<\/script>
|
|
1560
|
-
</body>
|
|
1561
|
-
</html>`;
|
|
1562
|
-
}
|
|
1479
|
+
//#region src/v2/hooks/use-render-tool.tsx
|
|
1480
|
+
const EMPTY_DEPS$1 = [];
|
|
1563
1481
|
/**
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1482
|
+
* Registers a renderer entry in CopilotKit's `renderToolCalls` registry.
|
|
1483
|
+
*
|
|
1484
|
+
* Key behavior:
|
|
1485
|
+
* - deduplicates by `agentId:name` (latest registration wins),
|
|
1486
|
+
* - keeps renderer entries on cleanup so historical chat tool calls can still render,
|
|
1487
|
+
* - refreshes registration when `deps` change.
|
|
1488
|
+
*
|
|
1489
|
+
* @typeParam S - Schema type describing tool call parameters.
|
|
1490
|
+
* @param config - Renderer config for wildcard or named tools.
|
|
1491
|
+
* @param deps - Optional dependencies to refresh registration.
|
|
1492
|
+
*
|
|
1493
|
+
* @example
|
|
1494
|
+
* ```tsx
|
|
1495
|
+
* useRenderTool(
|
|
1496
|
+
* {
|
|
1497
|
+
* name: "searchDocs",
|
|
1498
|
+
* parameters: z.object({ query: z.string() }),
|
|
1499
|
+
* render: ({ status, parameters, result }) => {
|
|
1500
|
+
* if (status === "executing") return <div>Searching {parameters.query}</div>;
|
|
1501
|
+
* if (status === "complete") return <div>{result}</div>;
|
|
1502
|
+
* return <div>Preparing...</div>;
|
|
1503
|
+
* },
|
|
1504
|
+
* },
|
|
1505
|
+
* [],
|
|
1506
|
+
* );
|
|
1507
|
+
* ```
|
|
1508
|
+
*
|
|
1509
|
+
* @example
|
|
1510
|
+
* ```tsx
|
|
1511
|
+
* useRenderTool(
|
|
1512
|
+
* {
|
|
1513
|
+
* name: "summarize",
|
|
1514
|
+
* parameters: z.object({ text: z.string() }),
|
|
1515
|
+
* agentId: "research-agent",
|
|
1516
|
+
* render: ({ name, status }) => <div>{name}: {status}</div>,
|
|
1517
|
+
* },
|
|
1518
|
+
* [selectedAgentId],
|
|
1519
|
+
* );
|
|
1520
|
+
* ```
|
|
1566
1521
|
*/
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
resolve,
|
|
1587
|
-
reject
|
|
1588
|
-
});
|
|
1589
|
-
this.processQueue(threadId, agent);
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
|
-
async processQueue(threadId, agent) {
|
|
1593
|
-
if (this.processing.get(threadId)) return;
|
|
1594
|
-
this.processing.set(threadId, true);
|
|
1595
|
-
try {
|
|
1596
|
-
const queue = this.queues.get(threadId);
|
|
1597
|
-
if (!queue) return;
|
|
1598
|
-
while (queue.length > 0) {
|
|
1599
|
-
const item = queue[0];
|
|
1600
|
-
try {
|
|
1601
|
-
await this.waitForAgentIdle(agent);
|
|
1602
|
-
const result = await item.execute();
|
|
1603
|
-
item.resolve(result);
|
|
1604
|
-
} catch (error) {
|
|
1605
|
-
item.reject(error instanceof Error ? error : new Error(String(error)));
|
|
1606
|
-
}
|
|
1607
|
-
queue.shift();
|
|
1608
|
-
}
|
|
1609
|
-
} finally {
|
|
1610
|
-
this.processing.set(threadId, false);
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
waitForAgentIdle(agent) {
|
|
1614
|
-
return new Promise((resolve) => {
|
|
1615
|
-
if (!agent.isRunning) {
|
|
1616
|
-
resolve();
|
|
1617
|
-
return;
|
|
1618
|
-
}
|
|
1619
|
-
let done = false;
|
|
1620
|
-
const finish = () => {
|
|
1621
|
-
if (done) return;
|
|
1622
|
-
done = true;
|
|
1623
|
-
clearInterval(checkInterval);
|
|
1624
|
-
sub.unsubscribe();
|
|
1625
|
-
resolve();
|
|
1626
|
-
};
|
|
1627
|
-
const sub = agent.subscribe({
|
|
1628
|
-
onRunFinalized: finish,
|
|
1629
|
-
onRunFailed: finish
|
|
1630
|
-
});
|
|
1631
|
-
const checkInterval = setInterval(() => {
|
|
1632
|
-
if (!agent.isRunning) finish();
|
|
1633
|
-
}, 500);
|
|
1522
|
+
function useRenderTool(config, deps) {
|
|
1523
|
+
const { copilotkit } = useCopilotKit();
|
|
1524
|
+
const extraDeps = deps !== null && deps !== void 0 ? deps : EMPTY_DEPS$1;
|
|
1525
|
+
(0, react.useEffect)(() => {
|
|
1526
|
+
const renderer = config.name === "*" && !config.parameters ? defineToolCallRenderer({
|
|
1527
|
+
name: "*",
|
|
1528
|
+
render: (props) => config.render({
|
|
1529
|
+
...props,
|
|
1530
|
+
parameters: props.args
|
|
1531
|
+
}),
|
|
1532
|
+
...config.agentId ? { agentId: config.agentId } : {}
|
|
1533
|
+
}) : defineToolCallRenderer({
|
|
1534
|
+
name: config.name,
|
|
1535
|
+
args: config.parameters,
|
|
1536
|
+
render: (props) => config.render({
|
|
1537
|
+
...props,
|
|
1538
|
+
parameters: props.args
|
|
1539
|
+
}),
|
|
1540
|
+
...config.agentId ? { agentId: config.agentId } : {}
|
|
1634
1541
|
});
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
const MCPAppsActivityType = "mcp-apps";
|
|
1642
|
-
const MCPAppsActivityContentSchema = zod.z.object({
|
|
1643
|
-
result: zod.z.object({
|
|
1644
|
-
content: zod.z.array(zod.z.any()).optional(),
|
|
1645
|
-
structuredContent: zod.z.any().optional(),
|
|
1646
|
-
isError: zod.z.boolean().optional()
|
|
1647
|
-
}),
|
|
1648
|
-
resourceUri: zod.z.string(),
|
|
1649
|
-
serverHash: zod.z.string(),
|
|
1650
|
-
serverId: zod.z.string().optional(),
|
|
1651
|
-
toolInput: zod.z.record(zod.z.unknown()).optional()
|
|
1652
|
-
});
|
|
1653
|
-
function isRequest(msg) {
|
|
1654
|
-
return "id" in msg && "method" in msg;
|
|
1655
|
-
}
|
|
1656
|
-
function isNotification(msg) {
|
|
1657
|
-
return !("id" in msg) && "method" in msg;
|
|
1542
|
+
copilotkit.addHookRenderToolCall(renderer);
|
|
1543
|
+
}, [
|
|
1544
|
+
config.name,
|
|
1545
|
+
copilotkit,
|
|
1546
|
+
JSON.stringify(extraDeps)
|
|
1547
|
+
]);
|
|
1658
1548
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1549
|
+
|
|
1550
|
+
//#endregion
|
|
1551
|
+
//#region src/v2/hooks/use-default-render-tool.tsx
|
|
1552
|
+
/**
|
|
1553
|
+
* Registers a wildcard (`"*"`) tool-call renderer via `useRenderTool`.
|
|
1661
1554
|
*
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1555
|
+
* - Call with no config to use CopilotKit's built-in default tool-call card.
|
|
1556
|
+
* - Pass `config.render` to replace the default UI with your own fallback renderer.
|
|
1557
|
+
*
|
|
1558
|
+
* This is useful when you want a generic renderer for tools that do not have a
|
|
1559
|
+
* dedicated `useRenderTool({ name: "..." })` registration.
|
|
1560
|
+
*
|
|
1561
|
+
* @param config - Optional custom wildcard render function.
|
|
1562
|
+
* @param deps - Optional dependencies to refresh registration.
|
|
1563
|
+
*
|
|
1564
|
+
* @example
|
|
1565
|
+
* ```tsx
|
|
1566
|
+
* useDefaultRenderTool();
|
|
1567
|
+
* ```
|
|
1568
|
+
*
|
|
1569
|
+
* @example
|
|
1570
|
+
* ```tsx
|
|
1571
|
+
* useDefaultRenderTool({
|
|
1572
|
+
* render: ({ name, status }) => <div>{name}: {status}</div>,
|
|
1573
|
+
* });
|
|
1574
|
+
* ```
|
|
1575
|
+
*
|
|
1576
|
+
* @example
|
|
1577
|
+
* ```tsx
|
|
1578
|
+
* useDefaultRenderTool(
|
|
1579
|
+
* {
|
|
1580
|
+
* render: ({ name, result }) => (
|
|
1581
|
+
* <ToolEventRow title={name} payload={result} compact={compactMode} />
|
|
1582
|
+
* ),
|
|
1583
|
+
* },
|
|
1584
|
+
* [compactMode],
|
|
1585
|
+
* );
|
|
1586
|
+
* ```
|
|
1587
|
+
*/
|
|
1588
|
+
function useDefaultRenderTool(config, deps) {
|
|
1589
|
+
var _config$render;
|
|
1590
|
+
useRenderTool({
|
|
1591
|
+
name: "*",
|
|
1592
|
+
render: (_config$render = config === null || config === void 0 ? void 0 : config.render) !== null && _config$render !== void 0 ? _config$render : DefaultToolCallRenderer
|
|
1593
|
+
}, deps);
|
|
1594
|
+
}
|
|
1595
|
+
function DefaultToolCallRenderer({ name, parameters, status, result }) {
|
|
1596
|
+
const [isExpanded, setIsExpanded] = (0, react.useState)(false);
|
|
1597
|
+
const statusString = String(status);
|
|
1598
|
+
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
1599
|
+
const isComplete = statusString === "complete";
|
|
1600
|
+
const statusLabel = isActive ? "Running" : isComplete ? "Done" : status;
|
|
1601
|
+
const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa";
|
|
1602
|
+
const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5";
|
|
1603
|
+
const badgeColor = isActive ? "#92400e" : isComplete ? "#065f46" : "#3f3f46";
|
|
1604
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1605
|
+
"data-testid": "copilot-tool-render",
|
|
1606
|
+
"data-tool-name": name,
|
|
1607
|
+
"data-status": statusString,
|
|
1608
|
+
"data-args": safeStringifyForAttr(parameters),
|
|
1609
|
+
"data-result": safeStringifyForAttr(result),
|
|
1610
|
+
style: {
|
|
1611
|
+
marginTop: "8px",
|
|
1612
|
+
paddingBottom: "8px"
|
|
1613
|
+
},
|
|
1614
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1615
|
+
style: {
|
|
1616
|
+
borderRadius: "12px",
|
|
1617
|
+
border: "1px solid #e4e4e7",
|
|
1618
|
+
backgroundColor: "#fafafa",
|
|
1619
|
+
padding: "14px 16px"
|
|
1620
|
+
},
|
|
1621
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1622
|
+
onClick: () => setIsExpanded(!isExpanded),
|
|
1623
|
+
style: {
|
|
1624
|
+
display: "flex",
|
|
1625
|
+
alignItems: "center",
|
|
1626
|
+
justifyContent: "space-between",
|
|
1627
|
+
gap: "10px",
|
|
1628
|
+
cursor: "pointer",
|
|
1629
|
+
userSelect: "none"
|
|
1630
|
+
},
|
|
1631
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1632
|
+
style: {
|
|
1633
|
+
display: "flex",
|
|
1634
|
+
alignItems: "center",
|
|
1635
|
+
gap: "8px",
|
|
1636
|
+
minWidth: 0
|
|
1637
|
+
},
|
|
1638
|
+
children: [
|
|
1639
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
1640
|
+
style: {
|
|
1641
|
+
height: "14px",
|
|
1642
|
+
width: "14px",
|
|
1643
|
+
color: "#71717a",
|
|
1644
|
+
transition: "transform 0.15s",
|
|
1645
|
+
transform: isExpanded ? "rotate(90deg)" : "rotate(0deg)",
|
|
1646
|
+
flexShrink: 0
|
|
1647
|
+
},
|
|
1648
|
+
fill: "none",
|
|
1649
|
+
viewBox: "0 0 24 24",
|
|
1650
|
+
strokeWidth: 2,
|
|
1651
|
+
stroke: "currentColor",
|
|
1652
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
1653
|
+
strokeLinecap: "round",
|
|
1654
|
+
strokeLinejoin: "round",
|
|
1655
|
+
d: "M8.25 4.5l7.5 7.5-7.5 7.5"
|
|
1656
|
+
})
|
|
1657
|
+
}),
|
|
1658
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: {
|
|
1659
|
+
display: "inline-block",
|
|
1660
|
+
height: "8px",
|
|
1661
|
+
width: "8px",
|
|
1662
|
+
borderRadius: "50%",
|
|
1663
|
+
backgroundColor: dotColor,
|
|
1664
|
+
flexShrink: 0
|
|
1665
|
+
} }),
|
|
1666
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1667
|
+
"data-testid": "copilot-tool-render-name",
|
|
1668
|
+
style: {
|
|
1669
|
+
fontSize: "13px",
|
|
1670
|
+
fontWeight: 600,
|
|
1671
|
+
color: "#18181b",
|
|
1672
|
+
overflow: "hidden",
|
|
1673
|
+
textOverflow: "ellipsis",
|
|
1674
|
+
whiteSpace: "nowrap"
|
|
1675
|
+
},
|
|
1676
|
+
children: name
|
|
1677
|
+
})
|
|
1678
|
+
]
|
|
1679
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1680
|
+
"data-testid": "copilot-tool-render-status",
|
|
1681
|
+
style: {
|
|
1682
|
+
display: "inline-flex",
|
|
1683
|
+
alignItems: "center",
|
|
1684
|
+
borderRadius: "9999px",
|
|
1685
|
+
padding: "2px 8px",
|
|
1686
|
+
fontSize: "11px",
|
|
1687
|
+
fontWeight: 500,
|
|
1688
|
+
backgroundColor: badgeBg,
|
|
1689
|
+
color: badgeColor,
|
|
1690
|
+
flexShrink: 0
|
|
1691
|
+
},
|
|
1692
|
+
children: statusLabel
|
|
1693
|
+
})]
|
|
1694
|
+
}), isExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1695
|
+
style: {
|
|
1696
|
+
marginTop: "12px",
|
|
1697
|
+
display: "grid",
|
|
1698
|
+
gap: "12px"
|
|
1699
|
+
},
|
|
1700
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1701
|
+
style: {
|
|
1702
|
+
fontSize: "10px",
|
|
1703
|
+
textTransform: "uppercase",
|
|
1704
|
+
letterSpacing: "0.05em",
|
|
1705
|
+
color: "#71717a"
|
|
1706
|
+
},
|
|
1707
|
+
children: "Arguments"
|
|
1708
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
1709
|
+
style: {
|
|
1710
|
+
marginTop: "6px",
|
|
1711
|
+
maxHeight: "200px",
|
|
1712
|
+
overflow: "auto",
|
|
1713
|
+
borderRadius: "6px",
|
|
1714
|
+
backgroundColor: "#f4f4f5",
|
|
1715
|
+
padding: "10px",
|
|
1716
|
+
fontSize: "11px",
|
|
1717
|
+
lineHeight: 1.6,
|
|
1718
|
+
color: "#27272a",
|
|
1719
|
+
whiteSpace: "pre-wrap",
|
|
1720
|
+
wordBreak: "break-word"
|
|
1721
|
+
},
|
|
1722
|
+
children: JSON.stringify(parameters !== null && parameters !== void 0 ? parameters : {}, null, 2)
|
|
1723
|
+
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1724
|
+
style: {
|
|
1725
|
+
fontSize: "10px",
|
|
1726
|
+
textTransform: "uppercase",
|
|
1727
|
+
letterSpacing: "0.05em",
|
|
1728
|
+
color: "#71717a"
|
|
1729
|
+
},
|
|
1730
|
+
children: "Result"
|
|
1731
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
1732
|
+
style: {
|
|
1733
|
+
marginTop: "6px",
|
|
1734
|
+
maxHeight: "200px",
|
|
1735
|
+
overflow: "auto",
|
|
1736
|
+
borderRadius: "6px",
|
|
1737
|
+
backgroundColor: "#f4f4f5",
|
|
1738
|
+
padding: "10px",
|
|
1739
|
+
fontSize: "11px",
|
|
1740
|
+
lineHeight: 1.6,
|
|
1741
|
+
color: "#27272a",
|
|
1742
|
+
whiteSpace: "pre-wrap",
|
|
1743
|
+
wordBreak: "break-word"
|
|
1744
|
+
},
|
|
1745
|
+
children: typeof result === "string" ? result : JSON.stringify(result, null, 2)
|
|
1746
|
+
})] })]
|
|
1747
|
+
})]
|
|
1748
|
+
})
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
function safeStringifyForAttr(value) {
|
|
1752
|
+
if (value === void 0 || value === null) return "";
|
|
1753
|
+
if (typeof value === "string") return value;
|
|
1754
|
+
try {
|
|
1755
|
+
return JSON.stringify(value);
|
|
1756
|
+
} catch (_unused) {
|
|
1757
|
+
return String(value);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
//#endregion
|
|
1762
|
+
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
1763
|
+
/**
|
|
1764
|
+
* Memoized component that renders a single tool call.
|
|
1765
|
+
* This prevents unnecessary re-renders when parent components update
|
|
1766
|
+
* but the tool call data hasn't changed.
|
|
1767
|
+
*/
|
|
1768
|
+
const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
1769
|
+
const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
1770
|
+
const toolName = toolCall.function.name;
|
|
1771
|
+
if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1772
|
+
name: toolName,
|
|
1773
|
+
toolCallId: toolCall.id,
|
|
1774
|
+
args,
|
|
1775
|
+
status: _copilotkit_core.ToolCallStatus.Complete,
|
|
1776
|
+
result: toolMessage.content
|
|
1777
|
+
});
|
|
1778
|
+
else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1779
|
+
name: toolName,
|
|
1780
|
+
toolCallId: toolCall.id,
|
|
1781
|
+
args,
|
|
1782
|
+
status: _copilotkit_core.ToolCallStatus.Executing,
|
|
1783
|
+
result: void 0
|
|
1784
|
+
});
|
|
1785
|
+
else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1786
|
+
name: toolName,
|
|
1787
|
+
toolCallId: toolCall.id,
|
|
1788
|
+
args,
|
|
1789
|
+
status: _copilotkit_core.ToolCallStatus.InProgress,
|
|
1790
|
+
result: void 0
|
|
1791
|
+
});
|
|
1792
|
+
}, (prevProps, nextProps) => {
|
|
1793
|
+
var _prevProps$toolMessag, _nextProps$toolMessag;
|
|
1794
|
+
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
1795
|
+
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
1796
|
+
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
1797
|
+
if (((_prevProps$toolMessag = prevProps.toolMessage) === null || _prevProps$toolMessag === void 0 ? void 0 : _prevProps$toolMessag.content) !== ((_nextProps$toolMessag = nextProps.toolMessage) === null || _nextProps$toolMessag === void 0 ? void 0 : _nextProps$toolMessag.content)) return false;
|
|
1798
|
+
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
1799
|
+
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
1800
|
+
return true;
|
|
1801
|
+
});
|
|
1802
|
+
/**
|
|
1803
|
+
* Hook that returns a function to render tool calls based on the render functions
|
|
1804
|
+
* defined in CopilotKitProvider.
|
|
1805
|
+
*
|
|
1806
|
+
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
1807
|
+
*/
|
|
1808
|
+
function useRenderToolCall() {
|
|
1809
|
+
var _config$agentId;
|
|
1810
|
+
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
1811
|
+
const config = useCopilotChatConfiguration();
|
|
1812
|
+
const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1813
|
+
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
1814
|
+
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
1815
|
+
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1816
|
+
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
1817
|
+
var _renderConfig$render;
|
|
1818
|
+
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
1819
|
+
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1820
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
1821
|
+
toolCall,
|
|
1822
|
+
toolMessage,
|
|
1823
|
+
RenderComponent: (_renderConfig$render = renderConfig === null || renderConfig === void 0 ? void 0 : renderConfig.render) !== null && _renderConfig$render !== void 0 ? _renderConfig$render : defaultToolCallRenderAdapter,
|
|
1824
|
+
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
1825
|
+
}, toolCall.id);
|
|
1826
|
+
}, [
|
|
1827
|
+
renderToolCalls,
|
|
1828
|
+
executingToolCallIds,
|
|
1829
|
+
agentId
|
|
1830
|
+
]);
|
|
1831
|
+
}
|
|
1832
|
+
function defaultToolCallRenderAdapter(props) {
|
|
1833
|
+
const status = props.status === _copilotkit_core.ToolCallStatus.Complete ? "complete" : props.status === _copilotkit_core.ToolCallStatus.Executing ? "executing" : "inProgress";
|
|
1834
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultToolCallRenderer, {
|
|
1835
|
+
name: props.name,
|
|
1836
|
+
parameters: props.args,
|
|
1837
|
+
status,
|
|
1838
|
+
result: props.result
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
//#endregion
|
|
1843
|
+
//#region src/v2/components/CopilotKitInspector.tsx
|
|
1844
|
+
const CopilotKitInspector = ({ core, ...rest }) => {
|
|
1845
|
+
const [InspectorComponent, setInspectorComponent] = react.useState(null);
|
|
1846
|
+
react.useEffect(() => {
|
|
1847
|
+
let mounted = true;
|
|
1848
|
+
import("@copilotkit/web-inspector").then((mod) => {
|
|
1849
|
+
var _mod$defineWebInspect;
|
|
1850
|
+
(_mod$defineWebInspect = mod.defineWebInspector) === null || _mod$defineWebInspect === void 0 || _mod$defineWebInspect.call(mod);
|
|
1851
|
+
const Component = (0, _lit_labs_react.createComponent)({
|
|
1852
|
+
tagName: mod.WEB_INSPECTOR_TAG,
|
|
1853
|
+
elementClass: mod.WebInspectorElement,
|
|
1854
|
+
react
|
|
1855
|
+
});
|
|
1856
|
+
if (mounted) setInspectorComponent(() => Component);
|
|
1857
|
+
});
|
|
1858
|
+
return () => {
|
|
1859
|
+
mounted = false;
|
|
1860
|
+
};
|
|
1861
|
+
}, []);
|
|
1862
|
+
if (!InspectorComponent) return null;
|
|
1863
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
|
|
1864
|
+
...rest,
|
|
1865
|
+
core: core !== null && core !== void 0 ? core : null
|
|
1866
|
+
});
|
|
1867
|
+
};
|
|
1868
|
+
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
1869
|
+
|
|
1870
|
+
//#endregion
|
|
1871
|
+
//#region src/v2/components/license-warning-banner.tsx
|
|
1872
|
+
const LICENSE_BANNER_OFFSET_PX = 52;
|
|
1873
|
+
const LICENSE_BANNER_OFFSET_VAR = "--copilotkit-license-banner-offset";
|
|
1874
|
+
const BANNER_STYLES = {
|
|
1875
|
+
base: {
|
|
1876
|
+
position: "fixed",
|
|
1877
|
+
bottom: "8px",
|
|
1878
|
+
left: "50%",
|
|
1879
|
+
transform: "translateX(-50%)",
|
|
1880
|
+
zIndex: 99999,
|
|
1881
|
+
display: "inline-flex",
|
|
1882
|
+
alignItems: "center",
|
|
1883
|
+
gap: "12px",
|
|
1884
|
+
whiteSpace: "nowrap",
|
|
1885
|
+
padding: "8px 16px",
|
|
1886
|
+
fontSize: "13px",
|
|
1887
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
1888
|
+
borderRadius: "6px",
|
|
1889
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
|
|
1890
|
+
},
|
|
1891
|
+
info: {
|
|
1892
|
+
backgroundColor: "#eff6ff",
|
|
1893
|
+
border: "1px solid #93c5fd",
|
|
1894
|
+
color: "#1e40af"
|
|
1895
|
+
},
|
|
1896
|
+
warning: {
|
|
1897
|
+
backgroundColor: "#fffbeb",
|
|
1898
|
+
border: "1px solid #fbbf24",
|
|
1899
|
+
color: "#92400e"
|
|
1900
|
+
},
|
|
1901
|
+
critical: {
|
|
1902
|
+
backgroundColor: "#fef2f2",
|
|
1903
|
+
border: "1px solid #fca5a5",
|
|
1904
|
+
color: "#991b1b"
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
function getSeverityStyle(severity) {
|
|
1908
|
+
switch (severity) {
|
|
1909
|
+
case "warning": return BANNER_STYLES.warning;
|
|
1910
|
+
case "critical": return BANNER_STYLES.critical;
|
|
1911
|
+
default: return BANNER_STYLES.info;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
function BannerShell({ severity, message, actionLabel, actionUrl, onDismiss }) {
|
|
1915
|
+
(0, react.useEffect)(() => {
|
|
1916
|
+
if (typeof document === "undefined") return;
|
|
1917
|
+
const root = document.documentElement;
|
|
1918
|
+
root.style.setProperty(LICENSE_BANNER_OFFSET_VAR, `${LICENSE_BANNER_OFFSET_PX}px`);
|
|
1919
|
+
return () => {
|
|
1920
|
+
root.style.removeProperty(LICENSE_BANNER_OFFSET_VAR);
|
|
1921
|
+
};
|
|
1922
|
+
}, []);
|
|
1923
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1924
|
+
style: {
|
|
1925
|
+
...BANNER_STYLES.base,
|
|
1926
|
+
...getSeverityStyle(severity)
|
|
1927
|
+
},
|
|
1928
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: message }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1929
|
+
style: {
|
|
1930
|
+
display: "flex",
|
|
1931
|
+
gap: "8px",
|
|
1932
|
+
alignItems: "center"
|
|
1933
|
+
},
|
|
1934
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1935
|
+
href: actionUrl,
|
|
1936
|
+
target: "_blank",
|
|
1937
|
+
rel: "noopener noreferrer",
|
|
1938
|
+
style: {
|
|
1939
|
+
fontWeight: 600,
|
|
1940
|
+
textDecoration: "underline",
|
|
1941
|
+
color: "inherit"
|
|
1942
|
+
},
|
|
1943
|
+
children: actionLabel
|
|
1944
|
+
}), onDismiss && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1945
|
+
onClick: onDismiss,
|
|
1946
|
+
style: {
|
|
1947
|
+
background: "none",
|
|
1948
|
+
border: "none",
|
|
1949
|
+
cursor: "pointer",
|
|
1950
|
+
color: "inherit",
|
|
1951
|
+
fontSize: "16px"
|
|
1952
|
+
},
|
|
1953
|
+
children: "×"
|
|
1954
|
+
})]
|
|
1955
|
+
})]
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
function LicenseWarningBanner({ type, featureName, expiryDate, graceRemaining, onDismiss }) {
|
|
1959
|
+
switch (type) {
|
|
1960
|
+
case "no_license": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1961
|
+
severity: "info",
|
|
1962
|
+
message: "Powered by CopilotKit",
|
|
1963
|
+
actionLabel: "Get a license",
|
|
1964
|
+
actionUrl: "https://copilotkit.ai/pricing",
|
|
1965
|
+
onDismiss
|
|
1966
|
+
});
|
|
1967
|
+
case "feature_unlicensed": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1968
|
+
severity: "warning",
|
|
1969
|
+
message: `⚠ The "${featureName}" feature requires a CopilotKit license.`,
|
|
1970
|
+
actionLabel: "Get a license",
|
|
1971
|
+
actionUrl: "https://copilotkit.ai/pricing",
|
|
1972
|
+
onDismiss
|
|
1973
|
+
});
|
|
1974
|
+
case "expiring": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1975
|
+
severity: "warning",
|
|
1976
|
+
message: `Your CopilotKit license expires in ${graceRemaining} day${graceRemaining !== 1 ? "s" : ""}. Please renew.`,
|
|
1977
|
+
actionLabel: "Renew",
|
|
1978
|
+
actionUrl: "https://cloud.copilotkit.ai",
|
|
1979
|
+
onDismiss
|
|
1980
|
+
});
|
|
1981
|
+
case "expired": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1982
|
+
severity: "critical",
|
|
1983
|
+
message: `Your CopilotKit license expired${expiryDate ? ` on ${expiryDate}` : ""}. Please renew at copilotkit.ai/pricing`,
|
|
1984
|
+
actionLabel: "Renew now",
|
|
1985
|
+
actionUrl: "https://copilotkit.ai/pricing",
|
|
1986
|
+
onDismiss
|
|
1987
|
+
});
|
|
1988
|
+
case "invalid": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BannerShell, {
|
|
1989
|
+
severity: "critical",
|
|
1990
|
+
message: "Invalid CopilotKit license token. Please check your configuration.",
|
|
1991
|
+
actionLabel: "Get a license",
|
|
1992
|
+
actionUrl: "https://copilotkit.ai/pricing",
|
|
1993
|
+
onDismiss
|
|
1994
|
+
});
|
|
1995
|
+
default: return null;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
function InlineFeatureWarning({ featureName }) {
|
|
1999
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2000
|
+
style: {
|
|
2001
|
+
padding: "8px 12px",
|
|
2002
|
+
backgroundColor: "#fffbeb",
|
|
2003
|
+
border: "1px solid #fbbf24",
|
|
2004
|
+
borderRadius: "6px",
|
|
2005
|
+
fontSize: "13px",
|
|
2006
|
+
color: "#92400e",
|
|
2007
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif"
|
|
2008
|
+
},
|
|
2009
|
+
children: [
|
|
2010
|
+
"⚠ The \"",
|
|
2011
|
+
featureName,
|
|
2012
|
+
"\" feature requires a CopilotKit license.",
|
|
2013
|
+
" ",
|
|
2014
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
2015
|
+
href: "https://copilotkit.ai/pricing",
|
|
2016
|
+
target: "_blank",
|
|
2017
|
+
rel: "noopener noreferrer",
|
|
2018
|
+
style: {
|
|
2019
|
+
color: "#b45309",
|
|
2020
|
+
textDecoration: "underline"
|
|
2021
|
+
},
|
|
2022
|
+
children: "Get one at copilotkit.ai/pricing"
|
|
2023
|
+
})
|
|
2024
|
+
]
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
//#endregion
|
|
2029
|
+
//#region src/v2/components/MCPAppsActivityRenderer.tsx
|
|
2030
|
+
const PROTOCOL_VERSION = "2025-06-18";
|
|
2031
|
+
function buildSandboxHTML(extraCspDomains) {
|
|
2032
|
+
const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
2033
|
+
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
2034
|
+
const extra = (extraCspDomains === null || extraCspDomains === void 0 ? void 0 : extraCspDomains.length) ? " " + extraCspDomains.join(" ") : "";
|
|
2035
|
+
return `<!doctype html>
|
|
2036
|
+
<html>
|
|
2037
|
+
<head>
|
|
2038
|
+
<meta charset="utf-8" />
|
|
2039
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${baseScriptSrc + extra}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${baseFrameSrc + extra}; base-uri 'self';" />
|
|
2040
|
+
<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>
|
|
2041
|
+
</head>
|
|
2042
|
+
<body>
|
|
2043
|
+
<script>
|
|
2044
|
+
if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
|
|
2045
|
+
const inner=document.createElement("iframe");
|
|
2046
|
+
inner.style="width:100%;height:100%;border:none;";
|
|
2047
|
+
inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
|
|
2048
|
+
document.body.appendChild(inner);
|
|
2049
|
+
window.addEventListener("message",async(event)=>{
|
|
2050
|
+
if(event.source===window.parent){
|
|
2051
|
+
if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
|
|
2052
|
+
const{html,sandbox}=event.data.params;
|
|
2053
|
+
if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
|
|
2054
|
+
if(typeof html==="string")inner.srcdoc=html;
|
|
2055
|
+
}else if(inner&&inner.contentWindow){
|
|
2056
|
+
inner.contentWindow.postMessage(event.data,"*");
|
|
2057
|
+
}
|
|
2058
|
+
}else if(event.source===inner.contentWindow){
|
|
2059
|
+
window.parent.postMessage(event.data,"*");
|
|
2060
|
+
}
|
|
2061
|
+
});
|
|
2062
|
+
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
|
|
2063
|
+
<\/script>
|
|
2064
|
+
</body>
|
|
2065
|
+
</html>`;
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Queue for serializing MCP app requests to an agent.
|
|
2069
|
+
* Ensures requests wait for the agent to stop running and are processed one at a time.
|
|
2070
|
+
*/
|
|
2071
|
+
var MCPAppsRequestQueue = class {
|
|
2072
|
+
constructor() {
|
|
2073
|
+
this.queues = /* @__PURE__ */ new Map();
|
|
2074
|
+
this.processing = /* @__PURE__ */ new Map();
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* Add a request to the queue for a specific agent thread.
|
|
2078
|
+
* Returns a promise that resolves when the request completes.
|
|
2079
|
+
*/
|
|
2080
|
+
async enqueue(agent, request) {
|
|
2081
|
+
const threadId = agent.threadId || "default";
|
|
2082
|
+
return new Promise((resolve, reject) => {
|
|
2083
|
+
let queue = this.queues.get(threadId);
|
|
2084
|
+
if (!queue) {
|
|
2085
|
+
queue = [];
|
|
2086
|
+
this.queues.set(threadId, queue);
|
|
2087
|
+
}
|
|
2088
|
+
queue.push({
|
|
2089
|
+
execute: request,
|
|
2090
|
+
resolve,
|
|
2091
|
+
reject
|
|
2092
|
+
});
|
|
2093
|
+
this.processQueue(threadId, agent);
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
async processQueue(threadId, agent) {
|
|
2097
|
+
if (this.processing.get(threadId)) return;
|
|
2098
|
+
this.processing.set(threadId, true);
|
|
2099
|
+
try {
|
|
2100
|
+
const queue = this.queues.get(threadId);
|
|
2101
|
+
if (!queue) return;
|
|
2102
|
+
while (queue.length > 0) {
|
|
2103
|
+
const item = queue[0];
|
|
2104
|
+
try {
|
|
2105
|
+
await this.waitForAgentIdle(agent);
|
|
2106
|
+
const result = await item.execute();
|
|
2107
|
+
item.resolve(result);
|
|
2108
|
+
} catch (error) {
|
|
2109
|
+
item.reject(error instanceof Error ? error : new Error(String(error)));
|
|
2110
|
+
}
|
|
2111
|
+
queue.shift();
|
|
2112
|
+
}
|
|
2113
|
+
} finally {
|
|
2114
|
+
this.processing.set(threadId, false);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
waitForAgentIdle(agent) {
|
|
2118
|
+
return new Promise((resolve) => {
|
|
2119
|
+
if (!agent.isRunning) {
|
|
2120
|
+
resolve();
|
|
2121
|
+
return;
|
|
2122
|
+
}
|
|
2123
|
+
let done = false;
|
|
2124
|
+
const finish = () => {
|
|
2125
|
+
if (done) return;
|
|
2126
|
+
done = true;
|
|
2127
|
+
clearInterval(checkInterval);
|
|
2128
|
+
sub.unsubscribe();
|
|
2129
|
+
resolve();
|
|
2130
|
+
};
|
|
2131
|
+
const sub = agent.subscribe({
|
|
2132
|
+
onRunFinalized: finish,
|
|
2133
|
+
onRunFailed: finish
|
|
2134
|
+
});
|
|
2135
|
+
const checkInterval = setInterval(() => {
|
|
2136
|
+
if (!agent.isRunning) finish();
|
|
2137
|
+
}, 500);
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
const mcpAppsRequestQueue = new MCPAppsRequestQueue();
|
|
2142
|
+
/**
|
|
2143
|
+
* Activity type for MCP Apps events - must match the middleware's MCPAppsActivityType
|
|
2144
|
+
*/
|
|
2145
|
+
const MCPAppsActivityType = "mcp-apps";
|
|
2146
|
+
const MCPAppsActivityContentSchema = zod.z.object({
|
|
2147
|
+
result: zod.z.object({
|
|
2148
|
+
content: zod.z.array(zod.z.any()).optional(),
|
|
2149
|
+
structuredContent: zod.z.any().optional(),
|
|
2150
|
+
isError: zod.z.boolean().optional()
|
|
2151
|
+
}),
|
|
2152
|
+
resourceUri: zod.z.string(),
|
|
2153
|
+
serverHash: zod.z.string(),
|
|
2154
|
+
serverId: zod.z.string().optional(),
|
|
2155
|
+
toolInput: zod.z.record(zod.z.unknown()).optional()
|
|
2156
|
+
});
|
|
2157
|
+
function isRequest(msg) {
|
|
2158
|
+
return "id" in msg && "method" in msg;
|
|
2159
|
+
}
|
|
2160
|
+
function isNotification(msg) {
|
|
2161
|
+
return !("id" in msg) && "method" in msg;
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* MCP Apps Extension Activity Renderer
|
|
2165
|
+
*
|
|
2166
|
+
* Renders MCP Apps UI in a sandboxed iframe with full protocol support.
|
|
2167
|
+
* Fetches resource content on-demand via proxied MCP requests.
|
|
2168
|
+
*/
|
|
2169
|
+
const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
|
|
2170
|
+
var _fetchedResource$_met2;
|
|
2171
|
+
const { copilotkit } = useCopilotKit();
|
|
2172
|
+
const containerRef = (0, react.useRef)(null);
|
|
2173
|
+
const iframeRef = (0, react.useRef)(null);
|
|
2174
|
+
const [iframeReady, setIframeReady] = (0, react.useState)(false);
|
|
2175
|
+
const [error, setError] = (0, react.useState)(null);
|
|
2176
|
+
const [isLoading, setIsLoading] = (0, react.useState)(true);
|
|
2177
|
+
const [iframeSize, setIframeSize] = (0, react.useState)({});
|
|
2178
|
+
const [fetchedResource, setFetchedResource] = (0, react.useState)(null);
|
|
1675
2179
|
const contentRef = (0, react.useRef)(content);
|
|
1676
2180
|
contentRef.current = content;
|
|
1677
2181
|
const agentRef = (0, react.useRef)(agent);
|
|
@@ -2590,18 +3094,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2590
3094
|
return (_ref = (_ref2 = (_ref3 = (_operation$createSurf = operation === null || operation === void 0 || (_operation$createSurf2 = operation.createSurface) === null || _operation$createSurf2 === void 0 ? void 0 : _operation$createSurf2.surfaceId) !== null && _operation$createSurf !== void 0 ? _operation$createSurf : operation === null || operation === void 0 || (_operation$updateComp = operation.updateComponents) === null || _operation$updateComp === void 0 ? void 0 : _operation$updateComp.surfaceId) !== null && _ref3 !== void 0 ? _ref3 : operation === null || operation === void 0 || (_operation$updateData = operation.updateDataModel) === null || _operation$updateData === void 0 ? void 0 : _operation$updateData.surfaceId) !== null && _ref2 !== void 0 ? _ref2 : operation === null || operation === void 0 || (_operation$deleteSurf = operation.deleteSurface) === null || _operation$deleteSurf === void 0 ? void 0 : _operation$deleteSurf.surfaceId) !== null && _ref !== void 0 ? _ref : null;
|
|
2591
3095
|
}
|
|
2592
3096
|
|
|
2593
|
-
//#endregion
|
|
2594
|
-
//#region src/v2/types/defineToolCallRenderer.ts
|
|
2595
|
-
function defineToolCallRenderer(def) {
|
|
2596
|
-
const argsSchema = def.name === "*" && !def.args ? zod.z.any() : def.args;
|
|
2597
|
-
return {
|
|
2598
|
-
name: def.name,
|
|
2599
|
-
args: argsSchema,
|
|
2600
|
-
render: def.render,
|
|
2601
|
-
...def.agentId ? { agentId: def.agentId } : {}
|
|
2602
|
-
};
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
3097
|
//#endregion
|
|
2606
3098
|
//#region src/v2/a2ui/A2UIToolCallRenderer.tsx
|
|
2607
3099
|
/**
|
|
@@ -2972,132 +3464,29 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2972
3464
|
description: "A2UI catalog capabilities: available catalog IDs and custom component definitions the client can render.",
|
|
2973
3465
|
value: (0, _copilotkit_a2ui_renderer.buildCatalogContextValue)(catalog)
|
|
2974
3466
|
});
|
|
2975
|
-
const { copilotkit } = useCopilotKit();
|
|
2976
|
-
const schemaValue = (0, react.useMemo)(() => includeSchema !== false ? JSON.stringify((0, _copilotkit_a2ui_renderer.extractCatalogComponentSchemas)(catalog)) : null, [catalog, includeSchema]);
|
|
2977
|
-
(0, react.useLayoutEffect)(() => {
|
|
2978
|
-
if (!copilotkit || !schemaValue) return;
|
|
2979
|
-
const ids = [];
|
|
2980
|
-
ids.push(copilotkit.addContext({
|
|
2981
|
-
description: _copilotkit_a2ui_renderer.A2UI_SCHEMA_CONTEXT_DESCRIPTION,
|
|
2982
|
-
value: schemaValue
|
|
2983
|
-
}));
|
|
2984
|
-
ids.push(copilotkit.addContext({
|
|
2985
|
-
description: "A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.",
|
|
2986
|
-
value: _copilotkit_shared.A2UI_DEFAULT_GENERATION_GUIDELINES
|
|
2987
|
-
}));
|
|
2988
|
-
ids.push(copilotkit.addContext({
|
|
2989
|
-
description: "A2UI design guidelines — visual design rules, component hierarchy tips, and action handler patterns.",
|
|
2990
|
-
value: _copilotkit_shared.A2UI_DEFAULT_DESIGN_GUIDELINES
|
|
2991
|
-
}));
|
|
2992
|
-
return () => {
|
|
2993
|
-
for (const id of ids) copilotkit.removeContext(id);
|
|
2994
|
-
};
|
|
2995
|
-
}, [copilotkit, schemaValue]);
|
|
2996
|
-
return null;
|
|
2997
|
-
}
|
|
2998
|
-
|
|
2999
|
-
//#endregion
|
|
3000
|
-
//#region src/v2/lib/react-core.ts
|
|
3001
|
-
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
3002
|
-
constructor(config) {
|
|
3003
|
-
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
3004
|
-
super(config);
|
|
3005
|
-
this._renderToolCalls = [];
|
|
3006
|
-
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
3007
|
-
this._cachedMergedRenderToolCalls = null;
|
|
3008
|
-
this._renderCustomMessages = [];
|
|
3009
|
-
this._renderActivityMessages = [];
|
|
3010
|
-
this._interruptElement = null;
|
|
3011
|
-
this._renderToolCalls = (_config$renderToolCal = config.renderToolCalls) !== null && _config$renderToolCal !== void 0 ? _config$renderToolCal : [];
|
|
3012
|
-
this._renderCustomMessages = (_config$renderCustomM = config.renderCustomMessages) !== null && _config$renderCustomM !== void 0 ? _config$renderCustomM : [];
|
|
3013
|
-
this._renderActivityMessages = (_config$renderActivit = config.renderActivityMessages) !== null && _config$renderActivit !== void 0 ? _config$renderActivit : [];
|
|
3014
|
-
}
|
|
3015
|
-
get renderCustomMessages() {
|
|
3016
|
-
return this._renderCustomMessages;
|
|
3017
|
-
}
|
|
3018
|
-
get renderActivityMessages() {
|
|
3019
|
-
return this._renderActivityMessages;
|
|
3020
|
-
}
|
|
3021
|
-
get renderToolCalls() {
|
|
3022
|
-
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
3023
|
-
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
3024
|
-
const merged = /* @__PURE__ */ new Map();
|
|
3025
|
-
for (const rc of this._renderToolCalls) {
|
|
3026
|
-
var _rc$agentId;
|
|
3027
|
-
merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
|
|
3028
|
-
}
|
|
3029
|
-
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
3030
|
-
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
3031
|
-
return this._cachedMergedRenderToolCalls;
|
|
3032
|
-
}
|
|
3033
|
-
setRenderActivityMessages(renderers) {
|
|
3034
|
-
this._renderActivityMessages = renderers;
|
|
3035
|
-
}
|
|
3036
|
-
setRenderCustomMessages(renderers) {
|
|
3037
|
-
this._renderCustomMessages = renderers;
|
|
3038
|
-
}
|
|
3039
|
-
setRenderToolCalls(renderToolCalls) {
|
|
3040
|
-
this._renderToolCalls = renderToolCalls;
|
|
3041
|
-
this._cachedMergedRenderToolCalls = null;
|
|
3042
|
-
this._notifyRenderToolCallsChanged();
|
|
3043
|
-
}
|
|
3044
|
-
addHookRenderToolCall(entry) {
|
|
3045
|
-
var _entry$agentId;
|
|
3046
|
-
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
3047
|
-
this._hookRenderToolCalls.set(key, entry);
|
|
3048
|
-
this._cachedMergedRenderToolCalls = null;
|
|
3049
|
-
this._notifyRenderToolCallsChanged();
|
|
3050
|
-
}
|
|
3051
|
-
removeHookRenderToolCall(name, agentId) {
|
|
3052
|
-
const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
|
|
3053
|
-
if (this._hookRenderToolCalls.delete(key)) {
|
|
3054
|
-
this._cachedMergedRenderToolCalls = null;
|
|
3055
|
-
this._notifyRenderToolCallsChanged();
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
_notifyRenderToolCallsChanged() {
|
|
3059
|
-
this.notifySubscribers((subscriber) => {
|
|
3060
|
-
const reactSubscriber = subscriber;
|
|
3061
|
-
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
3062
|
-
copilotkit: this,
|
|
3063
|
-
renderToolCalls: this.renderToolCalls
|
|
3064
|
-
});
|
|
3065
|
-
}, "Subscriber onRenderToolCallsChanged error:");
|
|
3066
|
-
}
|
|
3067
|
-
get interruptElement() {
|
|
3068
|
-
return this._interruptElement;
|
|
3069
|
-
}
|
|
3070
|
-
setInterruptElement(element) {
|
|
3071
|
-
this._interruptElement = element;
|
|
3072
|
-
this.notifySubscribers((subscriber) => {
|
|
3073
|
-
var _reactSubscriber$onIn;
|
|
3074
|
-
const reactSubscriber = subscriber;
|
|
3075
|
-
(_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
|
|
3076
|
-
copilotkit: this,
|
|
3077
|
-
interruptElement: this._interruptElement
|
|
3078
|
-
});
|
|
3079
|
-
}, "Subscriber onInterruptElementChanged error:");
|
|
3080
|
-
}
|
|
3081
|
-
subscribe(subscriber) {
|
|
3082
|
-
return super.subscribe(subscriber);
|
|
3083
|
-
}
|
|
3084
|
-
/**
|
|
3085
|
-
* Wait for pending React state updates before the follow-up agent run.
|
|
3086
|
-
*
|
|
3087
|
-
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
3088
|
-
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
3089
|
-
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
3090
|
-
* synchronously after React commits that batch.
|
|
3091
|
-
*
|
|
3092
|
-
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
3093
|
-
* MessageChannel task runs first, committing the pending state and running
|
|
3094
|
-
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
3095
|
-
* call then reads fresh context.
|
|
3096
|
-
*/
|
|
3097
|
-
async waitForPendingFrameworkUpdates() {
|
|
3098
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
3099
|
-
}
|
|
3100
|
-
};
|
|
3467
|
+
const { copilotkit } = useCopilotKit();
|
|
3468
|
+
const schemaValue = (0, react.useMemo)(() => includeSchema !== false ? JSON.stringify((0, _copilotkit_a2ui_renderer.extractCatalogComponentSchemas)(catalog)) : null, [catalog, includeSchema]);
|
|
3469
|
+
(0, react.useLayoutEffect)(() => {
|
|
3470
|
+
if (!copilotkit || !schemaValue) return;
|
|
3471
|
+
const ids = [];
|
|
3472
|
+
ids.push(copilotkit.addContext({
|
|
3473
|
+
description: _copilotkit_a2ui_renderer.A2UI_SCHEMA_CONTEXT_DESCRIPTION,
|
|
3474
|
+
value: schemaValue
|
|
3475
|
+
}));
|
|
3476
|
+
ids.push(copilotkit.addContext({
|
|
3477
|
+
description: "A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.",
|
|
3478
|
+
value: _copilotkit_shared.A2UI_DEFAULT_GENERATION_GUIDELINES
|
|
3479
|
+
}));
|
|
3480
|
+
ids.push(copilotkit.addContext({
|
|
3481
|
+
description: "A2UI design guidelines — visual design rules, component hierarchy tips, and action handler patterns.",
|
|
3482
|
+
value: _copilotkit_shared.A2UI_DEFAULT_DESIGN_GUIDELINES
|
|
3483
|
+
}));
|
|
3484
|
+
return () => {
|
|
3485
|
+
for (const id of ids) copilotkit.removeContext(id);
|
|
3486
|
+
};
|
|
3487
|
+
}, [copilotkit, schemaValue]);
|
|
3488
|
+
return null;
|
|
3489
|
+
}
|
|
3101
3490
|
|
|
3102
3491
|
//#endregion
|
|
3103
3492
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
@@ -3114,12 +3503,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3114
3503
|
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
3115
3504
|
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
|
|
3116
3505
|
const GENERATE_SANDBOXED_UI_DESCRIPTION = "Generate sandboxed UI. IMPORTANT: The generated code runs in a sandboxed iframe WITHOUT same-origin access. Do NOT use localStorage, sessionStorage, document.cookie, IndexedDB, or fetch/XMLHttpRequest to same-origin URLs. To communicate with the host application, use Websandbox.connection.remote.<functionName>(args) which returns a Promise.\n\nYou CAN use external libraries from CDNs by including <script> or <link> tags in the HTML <head> (e.g., Chart.js, D3, Three.js, x-data-spreadsheet, etc.). CDN resources load normally inside the sandbox.\n\nPARAMETER ORDER IS CRITICAL — generate parameters in exactly this order:\n1. initialHeight + placeholderMessages (shown to user while generating)\n2. css (all styles FIRST — the user sees a placeholder until CSS is complete)\n3. html (streams in live — the user watches the UI build as HTML is generated)\n4. jsFunctions (reusable helper functions)\n5. jsExpressions (applied one-by-one — the user sees each expression take effect)";
|
|
3117
|
-
const CopilotKitContext = (0, react.createContext)({
|
|
3118
|
-
copilotkit: null,
|
|
3119
|
-
executingToolCallIds: /* @__PURE__ */ new Set()
|
|
3120
|
-
});
|
|
3121
|
-
const LicenseContext = (0, react.createContext)((0, _copilotkit_shared.createLicenseContextValue)(null));
|
|
3122
|
-
const useLicenseContext = () => (0, react.useContext)(LicenseContext);
|
|
3123
3506
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
3124
3507
|
const empty = (0, react.useMemo)(() => [], []);
|
|
3125
3508
|
const value = prop !== null && prop !== void 0 ? prop : empty;
|
|
@@ -3348,14 +3731,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3348
3731
|
onErrorRef.current = onError;
|
|
3349
3732
|
}, [onError]);
|
|
3350
3733
|
(0, react.useEffect)(() => {
|
|
3351
|
-
if (!onErrorRef.current) return;
|
|
3352
3734
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
code
|
|
3357
|
-
|
|
3358
|
-
});
|
|
3735
|
+
if (onErrorRef.current) onErrorRef.current(event);
|
|
3736
|
+
else {
|
|
3737
|
+
var _event$context;
|
|
3738
|
+
console.error(`[CopilotKit] Error (${event.code}):`, event.error, (_event$context = event.context) !== null && _event$context !== void 0 ? _event$context : {});
|
|
3739
|
+
}
|
|
3359
3740
|
} });
|
|
3360
3741
|
return () => {
|
|
3361
3742
|
subscription.unsubscribe();
|
|
@@ -3426,302 +3807,50 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3426
3807
|
})));
|
|
3427
3808
|
}, [sandboxFunctionsList]);
|
|
3428
3809
|
(0, react.useLayoutEffect)(() => {
|
|
3429
|
-
if (!copilotkit || !sandboxFunctionsDescriptors || !openGenUIActive) return;
|
|
3430
|
-
const id = copilotkit.addContext({
|
|
3431
|
-
description: "Sandbox functions available in generated sandboxed UI code. Call via: await Websandbox.connection.remote.<functionName>(args)",
|
|
3432
|
-
value: sandboxFunctionsDescriptors
|
|
3433
|
-
});
|
|
3434
|
-
return () => {
|
|
3435
|
-
copilotkit.removeContext(id);
|
|
3436
|
-
};
|
|
3437
|
-
}, [
|
|
3438
|
-
copilotkit,
|
|
3439
|
-
sandboxFunctionsDescriptors,
|
|
3440
|
-
openGenUIActive
|
|
3441
|
-
]);
|
|
3442
|
-
const contextValue = (0, react.useMemo)(() => ({
|
|
3443
|
-
copilotkit,
|
|
3444
|
-
executingToolCallIds
|
|
3445
|
-
}), [copilotkit, executingToolCallIds]);
|
|
3446
|
-
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(null), []);
|
|
3447
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
|
|
3448
|
-
value: sandboxFunctionsList,
|
|
3449
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
|
|
3450
|
-
value: contextValue,
|
|
3451
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
|
|
3452
|
-
value: licenseContextValue,
|
|
3453
|
-
children: [
|
|
3454
|
-
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
3455
|
-
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
3456
|
-
catalog: a2ui === null || a2ui === void 0 ? void 0 : a2ui.catalog,
|
|
3457
|
-
includeSchema: a2ui === null || a2ui === void 0 ? void 0 : a2ui.includeSchema
|
|
3458
|
-
}),
|
|
3459
|
-
children,
|
|
3460
|
-
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
3461
|
-
core: copilotkit,
|
|
3462
|
-
defaultAnchor: inspectorDefaultAnchor
|
|
3463
|
-
}) : null,
|
|
3464
|
-
runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
|
|
3465
|
-
runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
|
|
3466
|
-
runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
|
|
3467
|
-
runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
|
|
3468
|
-
]
|
|
3469
|
-
})
|
|
3470
|
-
})
|
|
3471
|
-
});
|
|
3472
|
-
};
|
|
3473
|
-
const useCopilotKit = () => {
|
|
3474
|
-
const context = (0, react.useContext)(CopilotKitContext);
|
|
3475
|
-
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
3476
|
-
if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
3477
|
-
(0, react.useEffect)(() => {
|
|
3478
|
-
const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
|
|
3479
|
-
forceUpdate();
|
|
3480
|
-
} });
|
|
3481
|
-
return () => {
|
|
3482
|
-
subscription.unsubscribe();
|
|
3483
|
-
};
|
|
3484
|
-
}, []);
|
|
3485
|
-
return context;
|
|
3486
|
-
};
|
|
3487
|
-
|
|
3488
|
-
//#endregion
|
|
3489
|
-
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
3490
|
-
/**
|
|
3491
|
-
* Memoized component that renders a single tool call.
|
|
3492
|
-
* This prevents unnecessary re-renders when parent components update
|
|
3493
|
-
* but the tool call data hasn't changed.
|
|
3494
|
-
*/
|
|
3495
|
-
const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
3496
|
-
const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
3497
|
-
const toolName = toolCall.function.name;
|
|
3498
|
-
if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
3499
|
-
name: toolName,
|
|
3500
|
-
toolCallId: toolCall.id,
|
|
3501
|
-
args,
|
|
3502
|
-
status: _copilotkit_core.ToolCallStatus.Complete,
|
|
3503
|
-
result: toolMessage.content
|
|
3504
|
-
});
|
|
3505
|
-
else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
3506
|
-
name: toolName,
|
|
3507
|
-
toolCallId: toolCall.id,
|
|
3508
|
-
args,
|
|
3509
|
-
status: _copilotkit_core.ToolCallStatus.Executing,
|
|
3510
|
-
result: void 0
|
|
3511
|
-
});
|
|
3512
|
-
else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
3513
|
-
name: toolName,
|
|
3514
|
-
toolCallId: toolCall.id,
|
|
3515
|
-
args,
|
|
3516
|
-
status: _copilotkit_core.ToolCallStatus.InProgress,
|
|
3517
|
-
result: void 0
|
|
3518
|
-
});
|
|
3519
|
-
}, (prevProps, nextProps) => {
|
|
3520
|
-
var _prevProps$toolMessag, _nextProps$toolMessag;
|
|
3521
|
-
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
3522
|
-
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
3523
|
-
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
3524
|
-
if (((_prevProps$toolMessag = prevProps.toolMessage) === null || _prevProps$toolMessag === void 0 ? void 0 : _prevProps$toolMessag.content) !== ((_nextProps$toolMessag = nextProps.toolMessage) === null || _nextProps$toolMessag === void 0 ? void 0 : _nextProps$toolMessag.content)) return false;
|
|
3525
|
-
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
3526
|
-
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
3527
|
-
return true;
|
|
3528
|
-
});
|
|
3529
|
-
/**
|
|
3530
|
-
* Hook that returns a function to render tool calls based on the render functions
|
|
3531
|
-
* defined in CopilotKitProvider.
|
|
3532
|
-
*
|
|
3533
|
-
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
3534
|
-
*/
|
|
3535
|
-
function useRenderToolCall() {
|
|
3536
|
-
var _config$agentId;
|
|
3537
|
-
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
3538
|
-
const config = useCopilotChatConfiguration();
|
|
3539
|
-
const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
3540
|
-
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
3541
|
-
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
3542
|
-
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
3543
|
-
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
3544
|
-
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
3545
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
3546
|
-
if (!renderConfig) return null;
|
|
3547
|
-
const RenderComponent = renderConfig.render;
|
|
3548
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
3549
|
-
toolCall,
|
|
3550
|
-
toolMessage,
|
|
3551
|
-
RenderComponent,
|
|
3552
|
-
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
3553
|
-
}, toolCall.id);
|
|
3554
|
-
}, [
|
|
3555
|
-
renderToolCalls,
|
|
3556
|
-
executingToolCallIds,
|
|
3557
|
-
agentId
|
|
3558
|
-
]);
|
|
3559
|
-
}
|
|
3560
|
-
|
|
3561
|
-
//#endregion
|
|
3562
|
-
//#region src/v2/hooks/use-agent.tsx
|
|
3563
|
-
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
3564
|
-
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
3565
|
-
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
3566
|
-
UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
3567
|
-
return UseAgentUpdate;
|
|
3568
|
-
}({});
|
|
3569
|
-
const ALL_UPDATES = [
|
|
3570
|
-
UseAgentUpdate.OnMessagesChanged,
|
|
3571
|
-
UseAgentUpdate.OnStateChanged,
|
|
3572
|
-
UseAgentUpdate.OnRunStatusChanged
|
|
3573
|
-
];
|
|
3574
|
-
/**
|
|
3575
|
-
* Clone a registry agent for per-thread isolation.
|
|
3576
|
-
* Copies agent configuration (transport, headers, etc.) but resets conversation
|
|
3577
|
-
* state (messages, threadId, state) so each thread starts fresh.
|
|
3578
|
-
*/
|
|
3579
|
-
function cloneForThread(source, threadId, headers) {
|
|
3580
|
-
const clone = source.clone();
|
|
3581
|
-
if (clone === source) throw new Error(`useAgent: ${source.constructor.name}.clone() returned the same instance. clone() must return a new, independent object.`);
|
|
3582
|
-
clone.threadId = threadId;
|
|
3583
|
-
clone.setMessages([]);
|
|
3584
|
-
clone.setState({});
|
|
3585
|
-
if (clone instanceof _ag_ui_client.HttpAgent) clone.headers = { ...headers };
|
|
3586
|
-
return clone;
|
|
3587
|
-
}
|
|
3588
|
-
/**
|
|
3589
|
-
* Module-level WeakMap: registryAgent → (threadId → clone).
|
|
3590
|
-
* Shared across all useAgent() calls so that every component using the same
|
|
3591
|
-
* (agentId, threadId) pair receives the same agent instance. Using WeakMap
|
|
3592
|
-
* ensures the clone map is garbage-collected when the registry agent is
|
|
3593
|
-
* replaced (e.g. after reconnect or hot-reload).
|
|
3594
|
-
*/
|
|
3595
|
-
const globalThreadCloneMap = /* @__PURE__ */ new WeakMap();
|
|
3596
|
-
/**
|
|
3597
|
-
* Look up an existing per-thread clone without creating one.
|
|
3598
|
-
* Returns undefined when no clone has been created yet for this pair.
|
|
3599
|
-
*/
|
|
3600
|
-
function getThreadClone(registryAgent, threadId) {
|
|
3601
|
-
var _globalThreadCloneMap;
|
|
3602
|
-
if (!registryAgent || !threadId) return void 0;
|
|
3603
|
-
return (_globalThreadCloneMap = globalThreadCloneMap.get(registryAgent)) === null || _globalThreadCloneMap === void 0 ? void 0 : _globalThreadCloneMap.get(threadId);
|
|
3604
|
-
}
|
|
3605
|
-
function getOrCreateThreadClone(existing, threadId, headers) {
|
|
3606
|
-
let byThread = globalThreadCloneMap.get(existing);
|
|
3607
|
-
if (!byThread) {
|
|
3608
|
-
byThread = /* @__PURE__ */ new Map();
|
|
3609
|
-
globalThreadCloneMap.set(existing, byThread);
|
|
3610
|
-
}
|
|
3611
|
-
const cached = byThread.get(threadId);
|
|
3612
|
-
if (cached) return cached;
|
|
3613
|
-
const clone = cloneForThread(existing, threadId, headers);
|
|
3614
|
-
byThread.set(threadId, clone);
|
|
3615
|
-
return clone;
|
|
3616
|
-
}
|
|
3617
|
-
function useAgent({ agentId, threadId, updates, throttleMs } = {}) {
|
|
3618
|
-
var _agentId, _threadId;
|
|
3619
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
3620
|
-
const { copilotkit } = useCopilotKit();
|
|
3621
|
-
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
3622
|
-
const chatConfig = useCopilotChatConfiguration();
|
|
3623
|
-
(_threadId = threadId) !== null && _threadId !== void 0 || (threadId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.threadId);
|
|
3624
|
-
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
3625
|
-
const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
|
|
3626
|
-
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
3627
|
-
const agent = (0, react.useMemo)(() => {
|
|
3628
|
-
var _copilotkit$agents;
|
|
3629
|
-
const cacheKey = threadId ? `${agentId}:${threadId}` : agentId;
|
|
3630
|
-
const existing = copilotkit.getAgent(agentId);
|
|
3631
|
-
if (existing) {
|
|
3632
|
-
provisionalAgentCache.current.delete(cacheKey);
|
|
3633
|
-
provisionalAgentCache.current.delete(agentId);
|
|
3634
|
-
if (!threadId) return existing;
|
|
3635
|
-
return getOrCreateThreadClone(existing, threadId, copilotkit.headers);
|
|
3636
|
-
}
|
|
3637
|
-
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
3638
|
-
const status = copilotkit.runtimeConnectionStatus;
|
|
3639
|
-
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
3640
|
-
const cached = provisionalAgentCache.current.get(cacheKey);
|
|
3641
|
-
if (cached) {
|
|
3642
|
-
cached.headers = { ...copilotkit.headers };
|
|
3643
|
-
return cached;
|
|
3644
|
-
}
|
|
3645
|
-
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
3646
|
-
runtimeUrl: copilotkit.runtimeUrl,
|
|
3647
|
-
agentId,
|
|
3648
|
-
transport: copilotkit.runtimeTransport,
|
|
3649
|
-
runtimeMode: "pending"
|
|
3650
|
-
});
|
|
3651
|
-
provisional.headers = { ...copilotkit.headers };
|
|
3652
|
-
if (threadId) provisional.threadId = threadId;
|
|
3653
|
-
provisionalAgentCache.current.set(cacheKey, provisional);
|
|
3654
|
-
return provisional;
|
|
3655
|
-
}
|
|
3656
|
-
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
3657
|
-
const cached = provisionalAgentCache.current.get(cacheKey);
|
|
3658
|
-
if (cached) {
|
|
3659
|
-
cached.headers = { ...copilotkit.headers };
|
|
3660
|
-
return cached;
|
|
3661
|
-
}
|
|
3662
|
-
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
3663
|
-
runtimeUrl: copilotkit.runtimeUrl,
|
|
3664
|
-
agentId,
|
|
3665
|
-
transport: copilotkit.runtimeTransport,
|
|
3666
|
-
runtimeMode: "pending"
|
|
3667
|
-
});
|
|
3668
|
-
provisional.headers = { ...copilotkit.headers };
|
|
3669
|
-
if (threadId) provisional.threadId = threadId;
|
|
3670
|
-
provisionalAgentCache.current.set(cacheKey, provisional);
|
|
3671
|
-
return provisional;
|
|
3672
|
-
}
|
|
3673
|
-
const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
|
|
3674
|
-
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
3675
|
-
throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
|
|
3676
|
-
}, [
|
|
3677
|
-
agentId,
|
|
3678
|
-
threadId,
|
|
3679
|
-
copilotkit.agents,
|
|
3680
|
-
copilotkit.runtimeConnectionStatus,
|
|
3681
|
-
copilotkit.runtimeUrl,
|
|
3682
|
-
copilotkit.runtimeTransport,
|
|
3683
|
-
JSON.stringify(copilotkit.headers)
|
|
3684
|
-
]);
|
|
3685
|
-
(0, react.useEffect)(() => {
|
|
3686
|
-
if (updateFlags.length === 0) return;
|
|
3687
|
-
let active = true;
|
|
3688
|
-
const handlers = {};
|
|
3689
|
-
let batchScheduled = false;
|
|
3690
|
-
const batchedForceUpdate = () => {
|
|
3691
|
-
if (!active) return;
|
|
3692
|
-
if (!batchScheduled) {
|
|
3693
|
-
batchScheduled = true;
|
|
3694
|
-
queueMicrotask(() => {
|
|
3695
|
-
batchScheduled = false;
|
|
3696
|
-
if (active) forceUpdate();
|
|
3697
|
-
});
|
|
3698
|
-
}
|
|
3699
|
-
};
|
|
3700
|
-
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = forceUpdate;
|
|
3701
|
-
if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
|
|
3702
|
-
if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
|
|
3703
|
-
handlers.onRunInitialized = batchedForceUpdate;
|
|
3704
|
-
handlers.onRunFinalized = batchedForceUpdate;
|
|
3705
|
-
handlers.onRunFailed = batchedForceUpdate;
|
|
3706
|
-
handlers.onRunErrorEvent = batchedForceUpdate;
|
|
3707
|
-
}
|
|
3708
|
-
const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
|
|
3810
|
+
if (!copilotkit || !sandboxFunctionsDescriptors || !openGenUIActive) return;
|
|
3811
|
+
const id = copilotkit.addContext({
|
|
3812
|
+
description: "Sandbox functions available in generated sandboxed UI code. Call via: await Websandbox.connection.remote.<functionName>(args)",
|
|
3813
|
+
value: sandboxFunctionsDescriptors
|
|
3814
|
+
});
|
|
3709
3815
|
return () => {
|
|
3710
|
-
|
|
3711
|
-
subscription.unsubscribe();
|
|
3816
|
+
copilotkit.removeContext(id);
|
|
3712
3817
|
};
|
|
3713
3818
|
}, [
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
providerThrottleMs,
|
|
3718
|
-
updateFlags
|
|
3819
|
+
copilotkit,
|
|
3820
|
+
sandboxFunctionsDescriptors,
|
|
3821
|
+
openGenUIActive
|
|
3719
3822
|
]);
|
|
3720
|
-
(0, react.
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3823
|
+
const contextValue = (0, react.useMemo)(() => ({
|
|
3824
|
+
copilotkit,
|
|
3825
|
+
executingToolCallIds
|
|
3826
|
+
}), [copilotkit, executingToolCallIds]);
|
|
3827
|
+
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(null), []);
|
|
3828
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
|
|
3829
|
+
value: sandboxFunctionsList,
|
|
3830
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
|
|
3831
|
+
value: contextValue,
|
|
3832
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
|
|
3833
|
+
value: licenseContextValue,
|
|
3834
|
+
children: [
|
|
3835
|
+
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
3836
|
+
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
3837
|
+
catalog: a2ui === null || a2ui === void 0 ? void 0 : a2ui.catalog,
|
|
3838
|
+
includeSchema: a2ui === null || a2ui === void 0 ? void 0 : a2ui.includeSchema
|
|
3839
|
+
}),
|
|
3840
|
+
children,
|
|
3841
|
+
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
3842
|
+
core: copilotkit,
|
|
3843
|
+
defaultAnchor: inspectorDefaultAnchor
|
|
3844
|
+
}) : null,
|
|
3845
|
+
runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
|
|
3846
|
+
runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
|
|
3847
|
+
runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
|
|
3848
|
+
runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
|
|
3849
|
+
]
|
|
3850
|
+
})
|
|
3851
|
+
})
|
|
3852
|
+
});
|
|
3853
|
+
};
|
|
3725
3854
|
|
|
3726
3855
|
//#endregion
|
|
3727
3856
|
//#region src/v2/hooks/use-render-custom-messages.tsx
|
|
@@ -3736,13 +3865,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3736
3865
|
return aHasAgent ? -1 : 1;
|
|
3737
3866
|
});
|
|
3738
3867
|
return function(params) {
|
|
3739
|
-
var _copilotkit$getRunIdF
|
|
3868
|
+
var _copilotkit$getRunIdF;
|
|
3740
3869
|
if (!customMessageRenderers.length) return null;
|
|
3741
3870
|
const { message, position } = params;
|
|
3742
3871
|
const resolvedRunId = (_copilotkit$getRunIdF = copilotkit.getRunIdForMessage(agentId, threadId, message.id)) !== null && _copilotkit$getRunIdF !== void 0 ? _copilotkit$getRunIdF : copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
|
|
3743
3872
|
const runId = resolvedRunId !== null && resolvedRunId !== void 0 ? resolvedRunId : `missing-run-id:${message.id}`;
|
|
3744
|
-
const
|
|
3745
|
-
const agent = (_getThreadClone = getThreadClone(registryAgent, threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
|
|
3873
|
+
const agent = copilotkit.getAgent(agentId);
|
|
3746
3874
|
if (!agent) return null;
|
|
3747
3875
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
3748
3876
|
const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
|
|
@@ -3753,430 +3881,161 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3753
3881
|
let result = null;
|
|
3754
3882
|
for (const renderer of customMessageRenderers) {
|
|
3755
3883
|
if (!renderer.render) continue;
|
|
3756
|
-
const Component = renderer.render;
|
|
3757
|
-
result = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
3758
|
-
message,
|
|
3759
|
-
position,
|
|
3760
|
-
runId,
|
|
3761
|
-
messageIndex,
|
|
3762
|
-
messageIndexInRun,
|
|
3763
|
-
numberOfMessagesInRun,
|
|
3764
|
-
agentId,
|
|
3765
|
-
stateSnapshot
|
|
3766
|
-
}, `${runId}-${message.id}-${position}`);
|
|
3767
|
-
if (result) break;
|
|
3768
|
-
}
|
|
3769
|
-
return result;
|
|
3770
|
-
};
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
//#endregion
|
|
3774
|
-
//#region src/v2/hooks/use-render-activity-message.tsx
|
|
3775
|
-
function useRenderActivityMessage() {
|
|
3776
|
-
var
|
|
3777
|
-
const { copilotkit } = useCopilotKit();
|
|
3778
|
-
const config = useCopilotChatConfiguration();
|
|
3779
|
-
const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
3780
|
-
const renderers = copilotkit.renderActivityMessages;
|
|
3781
|
-
const findRenderer = (0, react.useCallback)((activityType) => {
|
|
3782
|
-
var _ref, _ref2, _matches$find;
|
|
3783
|
-
if (!renderers.length) return null;
|
|
3784
|
-
const matches = renderers.filter((renderer) => renderer.activityType === activityType);
|
|
3785
|
-
return (_ref = (_ref2 = (_matches$find = matches.find((candidate) => candidate.agentId === agentId)) !== null && _matches$find !== void 0 ? _matches$find : matches.find((candidate) => candidate.agentId === void 0)) !== null && _ref2 !== void 0 ? _ref2 : renderers.find((candidate) => candidate.activityType === "*")) !== null && _ref !== void 0 ? _ref : null;
|
|
3786
|
-
}, [agentId, renderers]);
|
|
3787
|
-
const renderActivityMessage = (0, react.useCallback)((message) => {
|
|
3788
|
-
var _getThreadClone;
|
|
3789
|
-
const renderer = findRenderer(message.activityType);
|
|
3790
|
-
if (!renderer) return null;
|
|
3791
|
-
const parseResult = renderer.content.safeParse(message.content);
|
|
3792
|
-
if (!parseResult.success) {
|
|
3793
|
-
console.warn(`Failed to parse content for activity message '${message.activityType}':`, parseResult.error);
|
|
3794
|
-
return null;
|
|
3795
|
-
}
|
|
3796
|
-
const Component = renderer.render;
|
|
3797
|
-
const registryAgent = copilotkit.getAgent(agentId);
|
|
3798
|
-
const agent = (_getThreadClone = getThreadClone(registryAgent, config === null || config === void 0 ? void 0 : config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
|
|
3799
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
3800
|
-
activityType: message.activityType,
|
|
3801
|
-
content: parseResult.data,
|
|
3802
|
-
message,
|
|
3803
|
-
agent
|
|
3804
|
-
}, message.id);
|
|
3805
|
-
}, [
|
|
3806
|
-
agentId,
|
|
3807
|
-
config === null || config === void 0 ? void 0 : config.threadId,
|
|
3808
|
-
copilotkit,
|
|
3809
|
-
findRenderer
|
|
3810
|
-
]);
|
|
3811
|
-
return (0, react.useMemo)(() => ({
|
|
3812
|
-
renderActivityMessage,
|
|
3813
|
-
findRenderer
|
|
3814
|
-
}), [renderActivityMessage, findRenderer]);
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
//#endregion
|
|
3818
|
-
//#region src/v2/hooks/use-frontend-tool.tsx
|
|
3819
|
-
const EMPTY_DEPS$1 = [];
|
|
3820
|
-
function useFrontendTool(tool, deps) {
|
|
3821
|
-
const { copilotkit } = useCopilotKit();
|
|
3822
|
-
const extraDeps = deps !== null && deps !== void 0 ? deps : EMPTY_DEPS$1;
|
|
3823
|
-
(0, react.useEffect)(() => {
|
|
3824
|
-
const name = tool.name;
|
|
3825
|
-
if (copilotkit.getTool({
|
|
3826
|
-
toolName: name,
|
|
3827
|
-
agentId: tool.agentId
|
|
3828
|
-
})) {
|
|
3829
|
-
console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
3830
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
3831
|
-
}
|
|
3832
|
-
copilotkit.addTool(tool);
|
|
3833
|
-
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
3834
|
-
name,
|
|
3835
|
-
args: tool.parameters,
|
|
3836
|
-
agentId: tool.agentId,
|
|
3837
|
-
render: tool.render
|
|
3838
|
-
});
|
|
3839
|
-
return () => {
|
|
3840
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
3841
|
-
};
|
|
3842
|
-
}, [
|
|
3843
|
-
tool.name,
|
|
3844
|
-
tool.available,
|
|
3845
|
-
copilotkit,
|
|
3846
|
-
extraDeps.length,
|
|
3847
|
-
...extraDeps
|
|
3848
|
-
]);
|
|
3849
|
-
}
|
|
3850
|
-
|
|
3851
|
-
//#endregion
|
|
3852
|
-
//#region src/v2/hooks/use-component.tsx
|
|
3853
|
-
/**
|
|
3854
|
-
* Registers a React component as a frontend tool renderer in chat.
|
|
3855
|
-
*
|
|
3856
|
-
* This hook is a convenience wrapper around `useFrontendTool` that:
|
|
3857
|
-
* - builds a model-facing tool description,
|
|
3858
|
-
* - forwards optional schema parameters (any Standard Schema V1 compatible library),
|
|
3859
|
-
* - renders your component with tool call parameters.
|
|
3860
|
-
*
|
|
3861
|
-
* Use this when you want to display a typed visual component for a tool call
|
|
3862
|
-
* without manually wiring a full frontend tool object.
|
|
3863
|
-
*
|
|
3864
|
-
* When `parameters` is provided, render props are inferred from the schema.
|
|
3865
|
-
* When omitted, the render component may accept any props.
|
|
3866
|
-
*
|
|
3867
|
-
* @typeParam TSchema - Schema describing tool parameters, or `undefined` when no schema is given.
|
|
3868
|
-
* @param config - Tool registration config.
|
|
3869
|
-
* @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
|
|
3870
|
-
*
|
|
3871
|
-
* @example
|
|
3872
|
-
* ```tsx
|
|
3873
|
-
* // Without parameters — render accepts any props
|
|
3874
|
-
* useComponent({
|
|
3875
|
-
* name: "showGreeting",
|
|
3876
|
-
* render: ({ message }: { message: string }) => <div>{message}</div>,
|
|
3877
|
-
* });
|
|
3878
|
-
* ```
|
|
3879
|
-
*
|
|
3880
|
-
* @example
|
|
3881
|
-
* ```tsx
|
|
3882
|
-
* // With parameters — render props inferred from schema
|
|
3883
|
-
* useComponent({
|
|
3884
|
-
* name: "showWeatherCard",
|
|
3885
|
-
* parameters: z.object({ city: z.string() }),
|
|
3886
|
-
* render: ({ city }) => <div>{city}</div>,
|
|
3887
|
-
* });
|
|
3888
|
-
* ```
|
|
3889
|
-
*
|
|
3890
|
-
* @example
|
|
3891
|
-
* ```tsx
|
|
3892
|
-
* useComponent(
|
|
3893
|
-
* {
|
|
3894
|
-
* name: "renderProfile",
|
|
3895
|
-
* parameters: z.object({ userId: z.string() }),
|
|
3896
|
-
* render: ProfileCard,
|
|
3897
|
-
* agentId: "support-agent",
|
|
3898
|
-
* },
|
|
3899
|
-
* [selectedAgentId],
|
|
3900
|
-
* );
|
|
3901
|
-
* ```
|
|
3902
|
-
*/
|
|
3903
|
-
function useComponent(config, deps) {
|
|
3904
|
-
const prefix = `Use this tool to display the "${config.name}" component in the chat. This tool renders a visual UI component for the user.`;
|
|
3905
|
-
const fullDescription = config.description ? `${prefix}\n\n${config.description}` : prefix;
|
|
3906
|
-
useFrontendTool({
|
|
3907
|
-
name: config.name,
|
|
3908
|
-
description: fullDescription,
|
|
3909
|
-
parameters: config.parameters,
|
|
3910
|
-
render: ({ args }) => {
|
|
3911
|
-
const Component = config.render;
|
|
3912
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { ...args });
|
|
3913
|
-
},
|
|
3914
|
-
agentId: config.agentId
|
|
3915
|
-
}, deps);
|
|
3916
|
-
}
|
|
3917
|
-
|
|
3918
|
-
//#endregion
|
|
3919
|
-
//#region src/v2/hooks/use-render-tool.tsx
|
|
3920
|
-
const EMPTY_DEPS = [];
|
|
3921
|
-
/**
|
|
3922
|
-
* Registers a renderer entry in CopilotKit's `renderToolCalls` registry.
|
|
3923
|
-
*
|
|
3924
|
-
* Key behavior:
|
|
3925
|
-
* - deduplicates by `agentId:name` (latest registration wins),
|
|
3926
|
-
* - keeps renderer entries on cleanup so historical chat tool calls can still render,
|
|
3927
|
-
* - refreshes registration when `deps` change.
|
|
3928
|
-
*
|
|
3929
|
-
* @typeParam S - Schema type describing tool call parameters.
|
|
3930
|
-
* @param config - Renderer config for wildcard or named tools.
|
|
3931
|
-
* @param deps - Optional dependencies to refresh registration.
|
|
3932
|
-
*
|
|
3933
|
-
* @example
|
|
3934
|
-
* ```tsx
|
|
3935
|
-
* useRenderTool(
|
|
3936
|
-
* {
|
|
3937
|
-
* name: "searchDocs",
|
|
3938
|
-
* parameters: z.object({ query: z.string() }),
|
|
3939
|
-
* render: ({ status, parameters, result }) => {
|
|
3940
|
-
* if (status === "executing") return <div>Searching {parameters.query}</div>;
|
|
3941
|
-
* if (status === "complete") return <div>{result}</div>;
|
|
3942
|
-
* return <div>Preparing...</div>;
|
|
3943
|
-
* },
|
|
3944
|
-
* },
|
|
3945
|
-
* [],
|
|
3946
|
-
* );
|
|
3947
|
-
* ```
|
|
3948
|
-
*
|
|
3949
|
-
* @example
|
|
3950
|
-
* ```tsx
|
|
3951
|
-
* useRenderTool(
|
|
3952
|
-
* {
|
|
3953
|
-
* name: "summarize",
|
|
3954
|
-
* parameters: z.object({ text: z.string() }),
|
|
3955
|
-
* agentId: "research-agent",
|
|
3956
|
-
* render: ({ name, status }) => <div>{name}: {status}</div>,
|
|
3957
|
-
* },
|
|
3958
|
-
* [selectedAgentId],
|
|
3959
|
-
* );
|
|
3960
|
-
* ```
|
|
3961
|
-
*/
|
|
3962
|
-
function useRenderTool(config, deps) {
|
|
3884
|
+
const Component = renderer.render;
|
|
3885
|
+
result = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
3886
|
+
message,
|
|
3887
|
+
position,
|
|
3888
|
+
runId,
|
|
3889
|
+
messageIndex,
|
|
3890
|
+
messageIndexInRun,
|
|
3891
|
+
numberOfMessagesInRun,
|
|
3892
|
+
agentId,
|
|
3893
|
+
stateSnapshot
|
|
3894
|
+
}, `${runId}-${message.id}-${position}`);
|
|
3895
|
+
if (result) break;
|
|
3896
|
+
}
|
|
3897
|
+
return result;
|
|
3898
|
+
};
|
|
3899
|
+
}
|
|
3900
|
+
|
|
3901
|
+
//#endregion
|
|
3902
|
+
//#region src/v2/hooks/use-render-activity-message.tsx
|
|
3903
|
+
function useRenderActivityMessage() {
|
|
3904
|
+
var _useCopilotChatConfig, _useCopilotChatConfig2;
|
|
3963
3905
|
const { copilotkit } = useCopilotKit();
|
|
3964
|
-
const
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3906
|
+
const agentId = (_useCopilotChatConfig = (_useCopilotChatConfig2 = useCopilotChatConfiguration()) === null || _useCopilotChatConfig2 === void 0 ? void 0 : _useCopilotChatConfig2.agentId) !== null && _useCopilotChatConfig !== void 0 ? _useCopilotChatConfig : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
3907
|
+
const renderers = copilotkit.renderActivityMessages;
|
|
3908
|
+
const findRenderer = (0, react.useCallback)((activityType) => {
|
|
3909
|
+
var _ref, _ref2, _matches$find;
|
|
3910
|
+
if (!renderers.length) return null;
|
|
3911
|
+
const matches = renderers.filter((renderer) => renderer.activityType === activityType);
|
|
3912
|
+
return (_ref = (_ref2 = (_matches$find = matches.find((candidate) => candidate.agentId === agentId)) !== null && _matches$find !== void 0 ? _matches$find : matches.find((candidate) => candidate.agentId === void 0)) !== null && _ref2 !== void 0 ? _ref2 : renderers.find((candidate) => candidate.activityType === "*")) !== null && _ref !== void 0 ? _ref : null;
|
|
3913
|
+
}, [agentId, renderers]);
|
|
3914
|
+
const renderActivityMessage = (0, react.useCallback)((message) => {
|
|
3915
|
+
const renderer = findRenderer(message.activityType);
|
|
3916
|
+
if (!renderer) return null;
|
|
3917
|
+
const parseResult = renderer.content.safeParse(message.content);
|
|
3918
|
+
if (!parseResult.success) {
|
|
3919
|
+
console.warn(`Failed to parse content for activity message '${message.activityType}':`, parseResult.error);
|
|
3920
|
+
return null;
|
|
3921
|
+
}
|
|
3922
|
+
const Component = renderer.render;
|
|
3923
|
+
const agent = copilotkit.getAgent(agentId);
|
|
3924
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
3925
|
+
activityType: message.activityType,
|
|
3926
|
+
content: parseResult.data,
|
|
3927
|
+
message,
|
|
3928
|
+
agent
|
|
3929
|
+
}, message.id);
|
|
3983
3930
|
}, [
|
|
3984
|
-
|
|
3931
|
+
agentId,
|
|
3985
3932
|
copilotkit,
|
|
3986
|
-
|
|
3987
|
-
...extraDeps
|
|
3933
|
+
findRenderer
|
|
3988
3934
|
]);
|
|
3935
|
+
return (0, react.useMemo)(() => ({
|
|
3936
|
+
renderActivityMessage,
|
|
3937
|
+
findRenderer
|
|
3938
|
+
}), [renderActivityMessage, findRenderer]);
|
|
3989
3939
|
}
|
|
3990
|
-
|
|
3991
|
-
//#endregion
|
|
3992
|
-
//#region src/v2/hooks/use-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
*
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
}),
|
|
4090
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: {
|
|
4091
|
-
display: "inline-block",
|
|
4092
|
-
height: "8px",
|
|
4093
|
-
width: "8px",
|
|
4094
|
-
borderRadius: "50%",
|
|
4095
|
-
backgroundColor: isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa",
|
|
4096
|
-
flexShrink: 0
|
|
4097
|
-
} }),
|
|
4098
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4099
|
-
style: {
|
|
4100
|
-
fontSize: "13px",
|
|
4101
|
-
fontWeight: 600,
|
|
4102
|
-
color: "#18181b",
|
|
4103
|
-
overflow: "hidden",
|
|
4104
|
-
textOverflow: "ellipsis",
|
|
4105
|
-
whiteSpace: "nowrap"
|
|
4106
|
-
},
|
|
4107
|
-
children: name
|
|
4108
|
-
})
|
|
4109
|
-
]
|
|
4110
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4111
|
-
style: {
|
|
4112
|
-
display: "inline-flex",
|
|
4113
|
-
alignItems: "center",
|
|
4114
|
-
borderRadius: "9999px",
|
|
4115
|
-
padding: "2px 8px",
|
|
4116
|
-
fontSize: "11px",
|
|
4117
|
-
fontWeight: 500,
|
|
4118
|
-
backgroundColor: isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5",
|
|
4119
|
-
color: isActive ? "#92400e" : isComplete ? "#065f46" : "#3f3f46",
|
|
4120
|
-
flexShrink: 0
|
|
4121
|
-
},
|
|
4122
|
-
children: isActive ? "Running" : isComplete ? "Done" : status
|
|
4123
|
-
})]
|
|
4124
|
-
}), isExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4125
|
-
style: {
|
|
4126
|
-
marginTop: "12px",
|
|
4127
|
-
display: "grid",
|
|
4128
|
-
gap: "12px"
|
|
4129
|
-
},
|
|
4130
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4131
|
-
style: {
|
|
4132
|
-
fontSize: "10px",
|
|
4133
|
-
textTransform: "uppercase",
|
|
4134
|
-
letterSpacing: "0.05em",
|
|
4135
|
-
color: "#71717a"
|
|
4136
|
-
},
|
|
4137
|
-
children: "Arguments"
|
|
4138
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
4139
|
-
style: {
|
|
4140
|
-
marginTop: "6px",
|
|
4141
|
-
maxHeight: "200px",
|
|
4142
|
-
overflow: "auto",
|
|
4143
|
-
borderRadius: "6px",
|
|
4144
|
-
backgroundColor: "#f4f4f5",
|
|
4145
|
-
padding: "10px",
|
|
4146
|
-
fontSize: "11px",
|
|
4147
|
-
lineHeight: 1.6,
|
|
4148
|
-
color: "#27272a",
|
|
4149
|
-
whiteSpace: "pre-wrap",
|
|
4150
|
-
wordBreak: "break-word"
|
|
4151
|
-
},
|
|
4152
|
-
children: JSON.stringify(parameters !== null && parameters !== void 0 ? parameters : {}, null, 2)
|
|
4153
|
-
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4154
|
-
style: {
|
|
4155
|
-
fontSize: "10px",
|
|
4156
|
-
textTransform: "uppercase",
|
|
4157
|
-
letterSpacing: "0.05em",
|
|
4158
|
-
color: "#71717a"
|
|
4159
|
-
},
|
|
4160
|
-
children: "Result"
|
|
4161
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
4162
|
-
style: {
|
|
4163
|
-
marginTop: "6px",
|
|
4164
|
-
maxHeight: "200px",
|
|
4165
|
-
overflow: "auto",
|
|
4166
|
-
borderRadius: "6px",
|
|
4167
|
-
backgroundColor: "#f4f4f5",
|
|
4168
|
-
padding: "10px",
|
|
4169
|
-
fontSize: "11px",
|
|
4170
|
-
lineHeight: 1.6,
|
|
4171
|
-
color: "#27272a",
|
|
4172
|
-
whiteSpace: "pre-wrap",
|
|
4173
|
-
wordBreak: "break-word"
|
|
4174
|
-
},
|
|
4175
|
-
children: typeof result === "string" ? result : JSON.stringify(result, null, 2)
|
|
4176
|
-
})] })]
|
|
4177
|
-
})]
|
|
4178
|
-
})
|
|
4179
|
-
});
|
|
3940
|
+
|
|
3941
|
+
//#endregion
|
|
3942
|
+
//#region src/v2/hooks/use-frontend-tool.tsx
|
|
3943
|
+
const EMPTY_DEPS = [];
|
|
3944
|
+
function useFrontendTool(tool, deps) {
|
|
3945
|
+
const { copilotkit } = useCopilotKit();
|
|
3946
|
+
const extraDeps = deps !== null && deps !== void 0 ? deps : EMPTY_DEPS;
|
|
3947
|
+
(0, react.useEffect)(() => {
|
|
3948
|
+
const name = tool.name;
|
|
3949
|
+
if (copilotkit.getTool({
|
|
3950
|
+
toolName: name,
|
|
3951
|
+
agentId: tool.agentId
|
|
3952
|
+
})) {
|
|
3953
|
+
console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
3954
|
+
copilotkit.removeTool(name, tool.agentId);
|
|
3955
|
+
}
|
|
3956
|
+
copilotkit.addTool(tool);
|
|
3957
|
+
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
3958
|
+
name,
|
|
3959
|
+
args: tool.parameters,
|
|
3960
|
+
agentId: tool.agentId,
|
|
3961
|
+
render: tool.render
|
|
3962
|
+
});
|
|
3963
|
+
return () => {
|
|
3964
|
+
copilotkit.removeTool(name, tool.agentId);
|
|
3965
|
+
};
|
|
3966
|
+
}, [
|
|
3967
|
+
tool.name,
|
|
3968
|
+
tool.available,
|
|
3969
|
+
copilotkit,
|
|
3970
|
+
JSON.stringify(extraDeps)
|
|
3971
|
+
]);
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
//#endregion
|
|
3975
|
+
//#region src/v2/hooks/use-component.tsx
|
|
3976
|
+
/**
|
|
3977
|
+
* Registers a React component as a frontend tool renderer in chat.
|
|
3978
|
+
*
|
|
3979
|
+
* This hook is a convenience wrapper around `useFrontendTool` that:
|
|
3980
|
+
* - builds a model-facing tool description,
|
|
3981
|
+
* - forwards optional schema parameters (any Standard Schema V1 compatible library),
|
|
3982
|
+
* - renders your component with tool call parameters.
|
|
3983
|
+
*
|
|
3984
|
+
* Use this when you want to display a typed visual component for a tool call
|
|
3985
|
+
* without manually wiring a full frontend tool object.
|
|
3986
|
+
*
|
|
3987
|
+
* When `parameters` is provided, render props are inferred from the schema.
|
|
3988
|
+
* When omitted, the render component may accept any props.
|
|
3989
|
+
*
|
|
3990
|
+
* @typeParam TSchema - Schema describing tool parameters, or `undefined` when no schema is given.
|
|
3991
|
+
* @param config - Tool registration config.
|
|
3992
|
+
* @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
|
|
3993
|
+
*
|
|
3994
|
+
* @example
|
|
3995
|
+
* ```tsx
|
|
3996
|
+
* // Without parameters — render accepts any props
|
|
3997
|
+
* useComponent({
|
|
3998
|
+
* name: "showGreeting",
|
|
3999
|
+
* render: ({ message }: { message: string }) => <div>{message}</div>,
|
|
4000
|
+
* });
|
|
4001
|
+
* ```
|
|
4002
|
+
*
|
|
4003
|
+
* @example
|
|
4004
|
+
* ```tsx
|
|
4005
|
+
* // With parameters — render props inferred from schema
|
|
4006
|
+
* useComponent({
|
|
4007
|
+
* name: "showWeatherCard",
|
|
4008
|
+
* parameters: z.object({ city: z.string() }),
|
|
4009
|
+
* render: ({ city }) => <div>{city}</div>,
|
|
4010
|
+
* });
|
|
4011
|
+
* ```
|
|
4012
|
+
*
|
|
4013
|
+
* @example
|
|
4014
|
+
* ```tsx
|
|
4015
|
+
* useComponent(
|
|
4016
|
+
* {
|
|
4017
|
+
* name: "renderProfile",
|
|
4018
|
+
* parameters: z.object({ userId: z.string() }),
|
|
4019
|
+
* render: ProfileCard,
|
|
4020
|
+
* agentId: "support-agent",
|
|
4021
|
+
* },
|
|
4022
|
+
* [selectedAgentId],
|
|
4023
|
+
* );
|
|
4024
|
+
* ```
|
|
4025
|
+
*/
|
|
4026
|
+
function useComponent(config, deps) {
|
|
4027
|
+
const prefix = `Use this tool to display the "${config.name}" component in the chat. This tool renders a visual UI component for the user.`;
|
|
4028
|
+
const fullDescription = config.description ? `${prefix}\n\n${config.description}` : prefix;
|
|
4029
|
+
useFrontendTool({
|
|
4030
|
+
name: config.name,
|
|
4031
|
+
description: fullDescription,
|
|
4032
|
+
parameters: config.parameters,
|
|
4033
|
+
render: ({ args }) => {
|
|
4034
|
+
const Component = config.render;
|
|
4035
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { ...args });
|
|
4036
|
+
},
|
|
4037
|
+
agentId: config.agentId
|
|
4038
|
+
}, deps);
|
|
4180
4039
|
}
|
|
4181
4040
|
|
|
4182
4041
|
//#endregion
|
|
@@ -4245,6 +4104,120 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4245
4104
|
]);
|
|
4246
4105
|
}
|
|
4247
4106
|
|
|
4107
|
+
//#endregion
|
|
4108
|
+
//#region src/v2/hooks/use-agent.tsx
|
|
4109
|
+
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
4110
|
+
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
4111
|
+
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
4112
|
+
UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
4113
|
+
return UseAgentUpdate;
|
|
4114
|
+
}({});
|
|
4115
|
+
const ALL_UPDATES = [
|
|
4116
|
+
UseAgentUpdate.OnMessagesChanged,
|
|
4117
|
+
UseAgentUpdate.OnStateChanged,
|
|
4118
|
+
UseAgentUpdate.OnRunStatusChanged
|
|
4119
|
+
];
|
|
4120
|
+
function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
4121
|
+
var _agentId;
|
|
4122
|
+
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
4123
|
+
const { copilotkit } = useCopilotKit();
|
|
4124
|
+
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
4125
|
+
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
4126
|
+
const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
|
|
4127
|
+
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
4128
|
+
const agent = (0, react.useMemo)(() => {
|
|
4129
|
+
var _copilotkit$agents;
|
|
4130
|
+
const existing = copilotkit.getAgent(agentId);
|
|
4131
|
+
if (existing) {
|
|
4132
|
+
provisionalAgentCache.current.delete(agentId);
|
|
4133
|
+
return existing;
|
|
4134
|
+
}
|
|
4135
|
+
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
4136
|
+
const status = copilotkit.runtimeConnectionStatus;
|
|
4137
|
+
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
4138
|
+
const cached = provisionalAgentCache.current.get(agentId);
|
|
4139
|
+
if (cached) {
|
|
4140
|
+
cached.headers = { ...copilotkit.headers };
|
|
4141
|
+
return cached;
|
|
4142
|
+
}
|
|
4143
|
+
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
4144
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
4145
|
+
agentId,
|
|
4146
|
+
transport: copilotkit.runtimeTransport,
|
|
4147
|
+
runtimeMode: "pending"
|
|
4148
|
+
});
|
|
4149
|
+
provisional.headers = { ...copilotkit.headers };
|
|
4150
|
+
provisionalAgentCache.current.set(agentId, provisional);
|
|
4151
|
+
return provisional;
|
|
4152
|
+
}
|
|
4153
|
+
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
4154
|
+
const cached = provisionalAgentCache.current.get(agentId);
|
|
4155
|
+
if (cached) {
|
|
4156
|
+
cached.headers = { ...copilotkit.headers };
|
|
4157
|
+
return cached;
|
|
4158
|
+
}
|
|
4159
|
+
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
4160
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
4161
|
+
agentId,
|
|
4162
|
+
transport: copilotkit.runtimeTransport,
|
|
4163
|
+
runtimeMode: "pending"
|
|
4164
|
+
});
|
|
4165
|
+
provisional.headers = { ...copilotkit.headers };
|
|
4166
|
+
provisionalAgentCache.current.set(agentId, provisional);
|
|
4167
|
+
return provisional;
|
|
4168
|
+
}
|
|
4169
|
+
const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
|
|
4170
|
+
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
4171
|
+
throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
|
|
4172
|
+
}, [
|
|
4173
|
+
agentId,
|
|
4174
|
+
copilotkit.agents,
|
|
4175
|
+
copilotkit.runtimeConnectionStatus,
|
|
4176
|
+
copilotkit.runtimeUrl,
|
|
4177
|
+
copilotkit.runtimeTransport,
|
|
4178
|
+
JSON.stringify(copilotkit.headers)
|
|
4179
|
+
]);
|
|
4180
|
+
(0, react.useEffect)(() => {
|
|
4181
|
+
if (updateFlags.length === 0) return;
|
|
4182
|
+
let active = true;
|
|
4183
|
+
const handlers = {};
|
|
4184
|
+
let batchScheduled = false;
|
|
4185
|
+
const batchedForceUpdate = () => {
|
|
4186
|
+
if (!active) return;
|
|
4187
|
+
if (!batchScheduled) {
|
|
4188
|
+
batchScheduled = true;
|
|
4189
|
+
queueMicrotask(() => {
|
|
4190
|
+
batchScheduled = false;
|
|
4191
|
+
if (active) forceUpdate();
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
};
|
|
4195
|
+
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = batchedForceUpdate;
|
|
4196
|
+
if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
|
|
4197
|
+
if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
|
|
4198
|
+
handlers.onRunInitialized = batchedForceUpdate;
|
|
4199
|
+
handlers.onRunFinalized = batchedForceUpdate;
|
|
4200
|
+
handlers.onRunFailed = batchedForceUpdate;
|
|
4201
|
+
handlers.onRunErrorEvent = batchedForceUpdate;
|
|
4202
|
+
}
|
|
4203
|
+
const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
|
|
4204
|
+
return () => {
|
|
4205
|
+
active = false;
|
|
4206
|
+
subscription.unsubscribe();
|
|
4207
|
+
};
|
|
4208
|
+
}, [
|
|
4209
|
+
agent,
|
|
4210
|
+
forceUpdate,
|
|
4211
|
+
throttleMs,
|
|
4212
|
+
providerThrottleMs,
|
|
4213
|
+
updateFlags
|
|
4214
|
+
]);
|
|
4215
|
+
(0, react.useEffect)(() => {
|
|
4216
|
+
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
4217
|
+
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
4218
|
+
return { agent };
|
|
4219
|
+
}
|
|
4220
|
+
|
|
4248
4221
|
//#endregion
|
|
4249
4222
|
//#region src/v2/hooks/use-capabilities.tsx
|
|
4250
4223
|
/**
|
|
@@ -5753,6 +5726,199 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5753
5726
|
*/
|
|
5754
5727
|
const ScrollElementContext = react.default.createContext(null);
|
|
5755
5728
|
|
|
5729
|
+
//#endregion
|
|
5730
|
+
//#region src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx
|
|
5731
|
+
/**
|
|
5732
|
+
* Grace window before showing the spinner. A matching tool call must
|
|
5733
|
+
* remain unresolved (no `tool`-role result message in `agent.messages`)
|
|
5734
|
+
* for at least this long before the pill appears. This filters out
|
|
5735
|
+
* history-replay flashes — during `connectAgent` replay, tool calls and
|
|
5736
|
+
* their results arrive back-to-back in sub-millisecond bursts, so the
|
|
5737
|
+
* timer is cancelled before it fires. Live runs cross the threshold
|
|
5738
|
+
* easily because the tool actually has to execute.
|
|
5739
|
+
*/
|
|
5740
|
+
const PENDING_THRESHOLD_MS = 100;
|
|
5741
|
+
/** Hold the checkmark briefly before fading out. */
|
|
5742
|
+
const CHECK_HOLD_MS = 800;
|
|
5743
|
+
/**
|
|
5744
|
+
* Duration of the fade-out animation. Must match
|
|
5745
|
+
* `cpk-intelligence-pill-fade-out` keyframes in `v2/styles/globals.css`.
|
|
5746
|
+
*/
|
|
5747
|
+
const FADE_OUT_ANIMATION_MS = 480;
|
|
5748
|
+
/**
|
|
5749
|
+
* Tool-name regex patterns that trigger the indicator. Currently
|
|
5750
|
+
* hardcoded to the Intelligence MCP server's canonical tool name. If
|
|
5751
|
+
* we add per-instance customization later (e.g. a `CopilotKitProvider`
|
|
5752
|
+
* prop or a runtime-info field), this constant becomes the fallback.
|
|
5753
|
+
*/
|
|
5754
|
+
const DEFAULT_TOOL_PATTERNS = [/^copilotkit_knowledge_base_shell$/];
|
|
5755
|
+
const isMatchingToolCallName = (name) => typeof name === "string" && DEFAULT_TOOL_PATTERNS.some((p) => p.test(name));
|
|
5756
|
+
/**
|
|
5757
|
+
* "Tool-call-like" messages do NOT count as a real follow-up: tool
|
|
5758
|
+
* result messages, assistant messages that carry tool calls, and
|
|
5759
|
+
* empty-content assistant messages (which some providers emit as a
|
|
5760
|
+
* standalone wrapper around a batch of tool calls). A real follow-up
|
|
5761
|
+
* is anything else — most importantly an assistant message with prose
|
|
5762
|
+
* content, or a fresh user message.
|
|
5763
|
+
*/
|
|
5764
|
+
const isToolCallLikeMessage = (m) => {
|
|
5765
|
+
if (m.role === "tool") return true;
|
|
5766
|
+
if (m.role === "assistant") {
|
|
5767
|
+
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).length > 0) return true;
|
|
5768
|
+
const content = m.content;
|
|
5769
|
+
return typeof content !== "string" || content.trim().length === 0;
|
|
5770
|
+
}
|
|
5771
|
+
return false;
|
|
5772
|
+
};
|
|
5773
|
+
/**
|
|
5774
|
+
* The "Using CopilotKit Intelligence" pill. Auto-mounted by
|
|
5775
|
+
* `CopilotChatMessageView` for every message slot when
|
|
5776
|
+
* `copilotkit.intelligence` is configured — callers do not register
|
|
5777
|
+
* this themselves. Self-gates so only the canonical message renders a
|
|
5778
|
+
* pill.
|
|
5779
|
+
*
|
|
5780
|
+
* Render gates (all must hold):
|
|
5781
|
+
* 1. `copilotkit.intelligence !== undefined`
|
|
5782
|
+
* 2. The message is an assistant message with at least one tool call
|
|
5783
|
+
* whose name matches {@link DEFAULT_TOOL_PATTERNS}
|
|
5784
|
+
* 3. The message is the *latest* such matching-assistant message in
|
|
5785
|
+
* `agent.messages` — tool-result messages and prose-only assistant
|
|
5786
|
+
* messages don't invalidate the slot, so the pill stays
|
|
5787
|
+
* continuously through a multi-step tool chain.
|
|
5788
|
+
* 4. The phase machine is past `idle` (the pending-grace timer fired)
|
|
5789
|
+
* and not yet `hidden`.
|
|
5790
|
+
*
|
|
5791
|
+
* Phase machine (per-instance, all timers local):
|
|
5792
|
+
* - Starts in `idle` — nothing rendered.
|
|
5793
|
+
* - `idle → spinner` once a matching tool call has been pending
|
|
5794
|
+
* (no `tool`-role result with a matching `toolCallId`) for
|
|
5795
|
+
* {@link PENDING_THRESHOLD_MS}. Replay flashes (tool call + result
|
|
5796
|
+
* in the same tick) never cross this threshold.
|
|
5797
|
+
* - `spinner → check` as soon as EITHER `agent.isRunning` flips
|
|
5798
|
+
* false OR a non-tool-call-like message appears later in
|
|
5799
|
+
* `agent.messages` (i.e. the agent has produced a "real"
|
|
5800
|
+
* follow-up — prose answer or a new user turn).
|
|
5801
|
+
* - `check → fading` after {@link CHECK_HOLD_MS}.
|
|
5802
|
+
* - `fading → hidden` after {@link FADE_OUT_ANIMATION_MS}.
|
|
5803
|
+
*
|
|
5804
|
+
* Once `hidden`, the phase is sticky — a finished pill never re-spawns
|
|
5805
|
+
* on the same message. New runs mount fresh indicator instances on
|
|
5806
|
+
* their own assistant messages.
|
|
5807
|
+
*
|
|
5808
|
+
* The "exactly one pill at a time" guarantee is structural: only one
|
|
5809
|
+
* message satisfies the latest-matching-assistant gate at any moment.
|
|
5810
|
+
*/
|
|
5811
|
+
function IntelligenceIndicator(props) {
|
|
5812
|
+
const { message, agentId, label = "Using CopilotKit Intelligence" } = props;
|
|
5813
|
+
const { copilotkit } = useCopilotKit();
|
|
5814
|
+
const config = useCopilotChatConfiguration();
|
|
5815
|
+
const { agent } = useAgent({
|
|
5816
|
+
agentId,
|
|
5817
|
+
updates: [UseAgentUpdate.OnRunStatusChanged, UseAgentUpdate.OnMessagesChanged]
|
|
5818
|
+
});
|
|
5819
|
+
const matchingToolCallIds = (0, react.useMemo)(() => {
|
|
5820
|
+
if (message.role !== "assistant") return [];
|
|
5821
|
+
const tcs = Array.isArray(message.toolCalls) ? message.toolCalls : [];
|
|
5822
|
+
const ids = [];
|
|
5823
|
+
for (const tc of tcs) {
|
|
5824
|
+
var _tc$function;
|
|
5825
|
+
if (isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function = tc.function) === null || _tc$function === void 0 ? void 0 : _tc$function.name) && (tc === null || tc === void 0 ? void 0 : tc.id)) ids.push(tc.id);
|
|
5826
|
+
}
|
|
5827
|
+
return ids;
|
|
5828
|
+
}, [message]);
|
|
5829
|
+
const hasPending = (0, react.useMemo)(() => {
|
|
5830
|
+
if (matchingToolCallIds.length === 0) return false;
|
|
5831
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
5832
|
+
for (const m of agent.messages) if (m.role === "tool" && m.toolCallId) resolved.add(m.toolCallId);
|
|
5833
|
+
return matchingToolCallIds.some((id) => !resolved.has(id));
|
|
5834
|
+
}, [matchingToolCallIds, agent.messages]);
|
|
5835
|
+
const sawRealFollowup = (0, react.useMemo)(() => {
|
|
5836
|
+
const idx = agent.messages.findIndex((m) => m.id === message.id);
|
|
5837
|
+
if (idx < 0) return false;
|
|
5838
|
+
for (let i = idx + 1; i < agent.messages.length; i += 1) if (!isToolCallLikeMessage(agent.messages[i])) return true;
|
|
5839
|
+
return false;
|
|
5840
|
+
}, [agent.messages, message.id]);
|
|
5841
|
+
const [phase, setPhase] = (0, react.useState)("idle");
|
|
5842
|
+
(0, react.useEffect)(() => {
|
|
5843
|
+
if (phase !== "idle") return void 0;
|
|
5844
|
+
if (!hasPending) return void 0;
|
|
5845
|
+
const t = setTimeout(() => setPhase("spinner"), PENDING_THRESHOLD_MS);
|
|
5846
|
+
return () => clearTimeout(t);
|
|
5847
|
+
}, [phase, hasPending]);
|
|
5848
|
+
(0, react.useEffect)(() => {
|
|
5849
|
+
if (phase !== "spinner") return void 0;
|
|
5850
|
+
if (!agent.isRunning || sawRealFollowup) setPhase("check");
|
|
5851
|
+
}, [
|
|
5852
|
+
phase,
|
|
5853
|
+
agent.isRunning,
|
|
5854
|
+
sawRealFollowup
|
|
5855
|
+
]);
|
|
5856
|
+
(0, react.useEffect)(() => {
|
|
5857
|
+
if (phase !== "check") return void 0;
|
|
5858
|
+
const t = setTimeout(() => setPhase("fading"), CHECK_HOLD_MS);
|
|
5859
|
+
return () => clearTimeout(t);
|
|
5860
|
+
}, [phase]);
|
|
5861
|
+
(0, react.useEffect)(() => {
|
|
5862
|
+
if (phase !== "fading") return void 0;
|
|
5863
|
+
const t = setTimeout(() => setPhase("hidden"), FADE_OUT_ANIMATION_MS);
|
|
5864
|
+
return () => clearTimeout(t);
|
|
5865
|
+
}, [phase]);
|
|
5866
|
+
if (copilotkit.intelligence === void 0) return null;
|
|
5867
|
+
if (!config) return null;
|
|
5868
|
+
if (phase === "idle" || phase === "hidden") return null;
|
|
5869
|
+
if (message.role !== "assistant") return null;
|
|
5870
|
+
if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) => {
|
|
5871
|
+
var _tc$function2;
|
|
5872
|
+
return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function2 = tc.function) === null || _tc$function2 === void 0 ? void 0 : _tc$function2.name);
|
|
5873
|
+
})) return null;
|
|
5874
|
+
let latestMatchingAssistantId;
|
|
5875
|
+
for (let i = agent.messages.length - 1; i >= 0; i -= 1) {
|
|
5876
|
+
const m = agent.messages[i];
|
|
5877
|
+
if (m.role !== "assistant") continue;
|
|
5878
|
+
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => {
|
|
5879
|
+
var _tc$function3;
|
|
5880
|
+
return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function3 = tc.function) === null || _tc$function3 === void 0 ? void 0 : _tc$function3.name);
|
|
5881
|
+
})) {
|
|
5882
|
+
latestMatchingAssistantId = m.id;
|
|
5883
|
+
break;
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5886
|
+
if (latestMatchingAssistantId !== message.id) return null;
|
|
5887
|
+
const showSpinner = phase === "spinner";
|
|
5888
|
+
const isFading = phase === "fading";
|
|
5889
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
5890
|
+
className: "cpk-intelligence-pill" + (isFading ? " cpk-intelligence-pill--fading" : ""),
|
|
5891
|
+
role: "status",
|
|
5892
|
+
"aria-live": "polite",
|
|
5893
|
+
"aria-hidden": isFading || void 0,
|
|
5894
|
+
"data-testid": `cpk-intelligence-pill-${message.id}`,
|
|
5895
|
+
title: label,
|
|
5896
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
5897
|
+
className: "cpk-intelligence-pill__icon",
|
|
5898
|
+
viewBox: "0 0 24 24",
|
|
5899
|
+
width: "14",
|
|
5900
|
+
height: "14",
|
|
5901
|
+
"aria-hidden": "true",
|
|
5902
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
5903
|
+
cx: "12",
|
|
5904
|
+
cy: "12",
|
|
5905
|
+
r: "9",
|
|
5906
|
+
fill: "none",
|
|
5907
|
+
strokeWidth: "2.5",
|
|
5908
|
+
strokeLinecap: "round",
|
|
5909
|
+
className: "cpk-intelligence-pill__ring" + (showSpinner ? "" : " cpk-intelligence-pill__ring--done")
|
|
5910
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
5911
|
+
d: "M8 12.5l3 3 5-6",
|
|
5912
|
+
fill: "none",
|
|
5913
|
+
strokeWidth: "2.5",
|
|
5914
|
+
strokeLinecap: "round",
|
|
5915
|
+
strokeLinejoin: "round",
|
|
5916
|
+
className: "cpk-intelligence-pill__check" + (showSpinner ? "" : " cpk-intelligence-pill__check--shown")
|
|
5917
|
+
})]
|
|
5918
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
|
|
5919
|
+
});
|
|
5920
|
+
}
|
|
5921
|
+
|
|
5756
5922
|
//#endregion
|
|
5757
5923
|
//#region src/v2/components/chat/CopilotChatMessageView.tsx
|
|
5758
5924
|
/**
|
|
@@ -5913,16 +6079,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5913
6079
|
const config = useCopilotChatConfiguration();
|
|
5914
6080
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
5915
6081
|
(0, react.useEffect)(() => {
|
|
5916
|
-
var _getThreadClone;
|
|
5917
6082
|
if (!(config === null || config === void 0 ? void 0 : config.agentId)) return;
|
|
5918
|
-
const
|
|
5919
|
-
const agent = (_getThreadClone = getThreadClone(registryAgent, config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
|
|
6083
|
+
const agent = copilotkit.getAgent(config.agentId);
|
|
5920
6084
|
if (!agent) return;
|
|
5921
6085
|
const subscription = agent.subscribe({ onStateChanged: forceUpdate });
|
|
5922
6086
|
return () => subscription.unsubscribe();
|
|
5923
6087
|
}, [
|
|
5924
6088
|
config === null || config === void 0 ? void 0 : config.agentId,
|
|
5925
|
-
config === null || config === void 0 ? void 0 : config.threadId,
|
|
5926
6089
|
copilotkit,
|
|
5927
6090
|
forceUpdate
|
|
5928
6091
|
]);
|
|
@@ -6008,6 +6171,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6008
6171
|
renderCustomMessage,
|
|
6009
6172
|
stateSnapshot
|
|
6010
6173
|
}, `${message.id}-custom-after`));
|
|
6174
|
+
if (copilotkit.intelligence !== void 0 && message.role === "assistant") {
|
|
6175
|
+
var _config$agentId;
|
|
6176
|
+
elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntelligenceIndicator, {
|
|
6177
|
+
message,
|
|
6178
|
+
agentId: (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID
|
|
6179
|
+
}, `${message.id}-intelligence`));
|
|
6180
|
+
}
|
|
6011
6181
|
return elements.filter(Boolean);
|
|
6012
6182
|
};
|
|
6013
6183
|
const messageElements = shouldVirtualize ? [] : deduplicatedMessages.flatMap(renderMessageBlock);
|
|
@@ -6961,7 +7131,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6961
7131
|
const hasExplicitThreadId = !!threadId || !!(existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.hasExplicitThreadId);
|
|
6962
7132
|
const { agent } = useAgent({
|
|
6963
7133
|
agentId: resolvedAgentId,
|
|
6964
|
-
threadId: resolvedThreadId,
|
|
6965
7134
|
throttleMs
|
|
6966
7135
|
});
|
|
6967
7136
|
const { copilotkit } = useCopilotKit();
|
|
@@ -7007,6 +7176,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7007
7176
|
let detached = false;
|
|
7008
7177
|
const connectAbortController = new AbortController();
|
|
7009
7178
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
|
|
7179
|
+
agent.threadId = resolvedThreadId;
|
|
7010
7180
|
const connect = async (agent) => {
|
|
7011
7181
|
try {
|
|
7012
7182
|
await copilotkit.connectAgent({ agent });
|
|
@@ -7422,18 +7592,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7422
7592
|
//#region src/v2/components/chat/CopilotSidebarView.tsx
|
|
7423
7593
|
const DEFAULT_SIDEBAR_WIDTH = 480;
|
|
7424
7594
|
const SIDEBAR_TRANSITION_MS = 260;
|
|
7425
|
-
function CopilotSidebarView({ header, toggleButton, width, defaultOpen = true, ...props }) {
|
|
7595
|
+
function CopilotSidebarView({ header, toggleButton, width, defaultOpen = true, position = "right", ...props }) {
|
|
7426
7596
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatConfigurationProvider, {
|
|
7427
7597
|
isModalDefaultOpen: defaultOpen,
|
|
7428
7598
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotSidebarViewInternal, {
|
|
7429
7599
|
header,
|
|
7430
7600
|
toggleButton,
|
|
7431
7601
|
width,
|
|
7602
|
+
position,
|
|
7432
7603
|
...props
|
|
7433
7604
|
})
|
|
7434
7605
|
});
|
|
7435
7606
|
}
|
|
7436
|
-
function CopilotSidebarViewInternal({ header, toggleButton, width, ...props }) {
|
|
7607
|
+
function CopilotSidebarViewInternal({ header, toggleButton, width, position = "right", ...props }) {
|
|
7437
7608
|
var _configuration$isModa;
|
|
7438
7609
|
const configuration = useCopilotChatConfiguration();
|
|
7439
7610
|
const isSidebarOpen = (_configuration$isModa = configuration === null || configuration === void 0 ? void 0 : configuration.isModalOpen) !== null && _configuration$isModa !== void 0 ? _configuration$isModa : false;
|
|
@@ -7468,26 +7639,33 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7468
7639
|
(0, react.useLayoutEffect)(() => {
|
|
7469
7640
|
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
7470
7641
|
if (!window.matchMedia("(min-width: 768px)").matches) return;
|
|
7642
|
+
const marginStyleProp = position === "left" ? "marginInlineStart" : "marginInlineEnd";
|
|
7643
|
+
const transitionCssProp = position === "left" ? "margin-inline-start" : "margin-inline-end";
|
|
7471
7644
|
if (isSidebarOpen) {
|
|
7472
|
-
if (hasMounted.current) document.body.style.transition =
|
|
7473
|
-
document.body.style
|
|
7645
|
+
if (hasMounted.current) document.body.style.transition = `${transitionCssProp} ${SIDEBAR_TRANSITION_MS}ms ease`;
|
|
7646
|
+
document.body.style[marginStyleProp] = widthToMargin(sidebarWidth);
|
|
7474
7647
|
} else if (hasMounted.current) {
|
|
7475
|
-
document.body.style.transition =
|
|
7476
|
-
document.body.style
|
|
7648
|
+
document.body.style.transition = `${transitionCssProp} ${SIDEBAR_TRANSITION_MS}ms ease`;
|
|
7649
|
+
document.body.style[marginStyleProp] = "";
|
|
7477
7650
|
}
|
|
7478
7651
|
hasMounted.current = true;
|
|
7479
7652
|
return () => {
|
|
7480
|
-
document.body.style
|
|
7653
|
+
document.body.style[marginStyleProp] = "";
|
|
7481
7654
|
document.body.style.transition = "";
|
|
7482
7655
|
};
|
|
7483
|
-
}, [
|
|
7656
|
+
}, [
|
|
7657
|
+
isSidebarOpen,
|
|
7658
|
+
sidebarWidth,
|
|
7659
|
+
position
|
|
7660
|
+
]);
|
|
7484
7661
|
const headerElement = renderSlot(header, CopilotModalHeader, {});
|
|
7485
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderSlot(toggleButton, CopilotChatToggleButton, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("aside", {
|
|
7662
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderSlot(toggleButton, CopilotChatToggleButton, position === "left" ? { className: "cpk:left-6 cpk:right-auto" } : {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("aside", {
|
|
7486
7663
|
ref: sidebarRef,
|
|
7487
7664
|
"data-copilotkit": true,
|
|
7488
7665
|
"data-testid": "copilot-sidebar",
|
|
7489
7666
|
"data-copilot-sidebar": true,
|
|
7490
|
-
|
|
7667
|
+
"data-position": position,
|
|
7668
|
+
className: cn("copilotKitSidebar copilotKitWindow", "cpk:fixed cpk:top-0 cpk:z-[1200] cpk:flex", position === "left" ? "cpk:left-0" : "cpk:right-0", "cpk:h-[100vh] cpk:h-[100dvh] cpk:max-h-screen", "cpk:w-full", position === "left" ? "cpk:border-r" : "cpk:border-l", "cpk:border-border cpk:bg-background cpk:text-foreground cpk:shadow-xl", "cpk:transition-transform cpk:duration-300 cpk:ease-out", isSidebarOpen ? "cpk:translate-x-0" : position === "left" ? "cpk:-translate-x-full cpk:pointer-events-none" : "cpk:translate-x-full cpk:pointer-events-none"),
|
|
7491
7669
|
style: {
|
|
7492
7670
|
["--sidebar-width"]: widthToCss(sidebarWidth),
|
|
7493
7671
|
paddingTop: "env(safe-area-inset-top)",
|
|
@@ -7696,7 +7874,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7696
7874
|
|
|
7697
7875
|
//#endregion
|
|
7698
7876
|
//#region src/v2/components/chat/CopilotSidebar.tsx
|
|
7699
|
-
function CopilotSidebar({ header, toggleButton, defaultOpen, width, ...chatProps }) {
|
|
7877
|
+
function CopilotSidebar({ header, toggleButton, defaultOpen, width, position, ...chatProps }) {
|
|
7700
7878
|
const { checkFeature } = useLicenseContext();
|
|
7701
7879
|
const isSidebarLicensed = checkFeature("sidebar");
|
|
7702
7880
|
(0, react.useEffect)(() => {
|
|
@@ -7704,13 +7882,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7704
7882
|
}, [isSidebarLicensed]);
|
|
7705
7883
|
const SidebarViewOverride = (0, react.useMemo)(() => {
|
|
7706
7884
|
const Component = (viewProps) => {
|
|
7707
|
-
const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
|
|
7885
|
+
const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, defaultOpen: viewDefaultOpen, position: viewPosition, ...restProps } = viewProps;
|
|
7708
7886
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotSidebarView, {
|
|
7709
7887
|
...restProps,
|
|
7710
7888
|
header: header !== null && header !== void 0 ? header : viewHeader,
|
|
7711
7889
|
toggleButton: toggleButton !== null && toggleButton !== void 0 ? toggleButton : viewToggleButton,
|
|
7712
7890
|
width: width !== null && width !== void 0 ? width : viewWidth,
|
|
7713
|
-
defaultOpen: defaultOpen !== null && defaultOpen !== void 0 ? defaultOpen : viewDefaultOpen
|
|
7891
|
+
defaultOpen: defaultOpen !== null && defaultOpen !== void 0 ? defaultOpen : viewDefaultOpen,
|
|
7892
|
+
position: position !== null && position !== void 0 ? position : viewPosition
|
|
7714
7893
|
});
|
|
7715
7894
|
};
|
|
7716
7895
|
return Object.assign(Component, CopilotChatView_default);
|
|
@@ -7718,7 +7897,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7718
7897
|
header,
|
|
7719
7898
|
toggleButton,
|
|
7720
7899
|
width,
|
|
7721
|
-
defaultOpen
|
|
7900
|
+
defaultOpen,
|
|
7901
|
+
position
|
|
7722
7902
|
]);
|
|
7723
7903
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!isSidebarLicensed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InlineFeatureWarning, { featureName: "Sidebar" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChat, {
|
|
7724
7904
|
welcomeScreen: CopilotSidebarView.WelcomeScreen,
|
|
@@ -9922,6 +10102,7 @@ Object.defineProperty(exports, 'CopilotSidebarView', {
|
|
|
9922
10102
|
return CopilotSidebarView;
|
|
9923
10103
|
}
|
|
9924
10104
|
});
|
|
10105
|
+
exports.IntelligenceIndicator = IntelligenceIndicator;
|
|
9925
10106
|
exports.MCPAppsActivityContentSchema = MCPAppsActivityContentSchema;
|
|
9926
10107
|
exports.MCPAppsActivityRenderer = MCPAppsActivityRenderer;
|
|
9927
10108
|
exports.MCPAppsActivityType = MCPAppsActivityType;
|