@copilotkit/react-core 1.59.1 → 1.59.2
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-CDK5ny-e.mjs → copilotkit-B5RsC6la.mjs} +137 -35
- package/dist/copilotkit-B5RsC6la.mjs.map +1 -0
- package/dist/{copilotkit-WlmeVijs.d.mts → copilotkit-CEJz6krE.d.mts} +3 -2
- package/dist/{copilotkit-WlmeVijs.d.mts.map → copilotkit-CEJz6krE.d.mts.map} +1 -1
- package/dist/{copilotkit-BK9CVq9A.d.cts → copilotkit-D16eCFkt.d.cts} +3 -2
- package/dist/{copilotkit-BK9CVq9A.d.cts.map → copilotkit-D16eCFkt.d.cts.map} +1 -1
- package/dist/{copilotkit-DKPrBplZ.cjs → copilotkit-IQO0VDZb.cjs} +137 -35
- package/dist/copilotkit-IQO0VDZb.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +364 -397
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +44 -19
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.mjs +44 -19
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +437 -519
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +12 -7
- package/dist/copilotkit-CDK5ny-e.mjs.map +0 -1
- package/dist/copilotkit-DKPrBplZ.cjs.map +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -146,27 +146,26 @@ react_markdown = __toESM(react_markdown);
|
|
|
146
146
|
};
|
|
147
147
|
const CopilotChatConfiguration = (0, react.createContext)(null);
|
|
148
148
|
const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, hasExplicitThreadId, isModalDefaultOpen }) => {
|
|
149
|
-
var _ref, _parentConfig$isModal, _parentConfig$setModa;
|
|
150
149
|
const parentConfig = (0, react.useContext)(CopilotChatConfiguration);
|
|
151
150
|
const stableLabels = useShallowStableRef(labels);
|
|
152
151
|
const mergedLabels = (0, react.useMemo)(() => ({
|
|
153
152
|
...CopilotChatDefaultLabels,
|
|
154
|
-
...parentConfig
|
|
153
|
+
...parentConfig?.labels,
|
|
155
154
|
...stableLabels
|
|
156
|
-
}), [stableLabels, parentConfig
|
|
157
|
-
const resolvedAgentId =
|
|
155
|
+
}), [stableLabels, parentConfig?.labels]);
|
|
156
|
+
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
158
157
|
const resolvedThreadId = (0, react.useMemo)(() => {
|
|
159
158
|
if (threadId) return threadId;
|
|
160
|
-
if (parentConfig
|
|
159
|
+
if (parentConfig?.threadId) return parentConfig.threadId;
|
|
161
160
|
return (0, _copilotkit_shared.randomUUID)();
|
|
162
|
-
}, [threadId, parentConfig
|
|
163
|
-
const resolvedHasExplicitThreadId = (hasExplicitThreadId !== void 0 ? hasExplicitThreadId : !!threadId) || !!
|
|
164
|
-
const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen
|
|
161
|
+
}, [threadId, parentConfig?.threadId]);
|
|
162
|
+
const resolvedHasExplicitThreadId = (hasExplicitThreadId !== void 0 ? hasExplicitThreadId : !!threadId) || !!parentConfig?.hasExplicitThreadId;
|
|
163
|
+
const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen ?? true);
|
|
165
164
|
const hasExplicitDefault = isModalDefaultOpen !== void 0;
|
|
166
165
|
const setAndSync = (0, react.useCallback)((open) => {
|
|
167
166
|
setInternalModalOpen(open);
|
|
168
|
-
parentConfig
|
|
169
|
-
}, [parentConfig
|
|
167
|
+
parentConfig?.setModalOpen(open);
|
|
168
|
+
}, [parentConfig?.setModalOpen]);
|
|
170
169
|
const isMounted = (0, react.useRef)(false);
|
|
171
170
|
(0, react.useEffect)(() => {
|
|
172
171
|
if (!hasExplicitDefault) return;
|
|
@@ -174,11 +173,11 @@ react_markdown = __toESM(react_markdown);
|
|
|
174
173
|
isMounted.current = true;
|
|
175
174
|
return;
|
|
176
175
|
}
|
|
177
|
-
if (
|
|
176
|
+
if (parentConfig?.isModalOpen === void 0) return;
|
|
178
177
|
setInternalModalOpen(parentConfig.isModalOpen);
|
|
179
|
-
}, [parentConfig
|
|
180
|
-
const resolvedIsModalOpen = hasExplicitDefault ? internalModalOpen :
|
|
181
|
-
const resolvedSetModalOpen = hasExplicitDefault ? setAndSync :
|
|
178
|
+
}, [parentConfig?.isModalOpen, hasExplicitDefault]);
|
|
179
|
+
const resolvedIsModalOpen = hasExplicitDefault ? internalModalOpen : parentConfig?.isModalOpen ?? internalModalOpen;
|
|
180
|
+
const resolvedSetModalOpen = hasExplicitDefault ? setAndSync : parentConfig?.setModalOpen ?? setInternalModalOpen;
|
|
182
181
|
const configurationValue = (0, react.useMemo)(() => ({
|
|
183
182
|
labels: mergedLabels,
|
|
184
183
|
agentId: resolvedAgentId,
|
|
@@ -207,7 +206,6 @@ react_markdown = __toESM(react_markdown);
|
|
|
207
206
|
//#region src/v2/lib/react-core.ts
|
|
208
207
|
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
209
208
|
constructor(config) {
|
|
210
|
-
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
211
209
|
super(config);
|
|
212
210
|
this._renderToolCalls = [];
|
|
213
211
|
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
@@ -215,9 +213,9 @@ react_markdown = __toESM(react_markdown);
|
|
|
215
213
|
this._renderCustomMessages = [];
|
|
216
214
|
this._renderActivityMessages = [];
|
|
217
215
|
this._interruptElement = null;
|
|
218
|
-
this._renderToolCalls =
|
|
219
|
-
this._renderCustomMessages =
|
|
220
|
-
this._renderActivityMessages =
|
|
216
|
+
this._renderToolCalls = config.renderToolCalls ?? [];
|
|
217
|
+
this._renderCustomMessages = config.renderCustomMessages ?? [];
|
|
218
|
+
this._renderActivityMessages = config.renderActivityMessages ?? [];
|
|
221
219
|
}
|
|
222
220
|
get renderCustomMessages() {
|
|
223
221
|
return this._renderCustomMessages;
|
|
@@ -229,10 +227,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
229
227
|
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
230
228
|
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
231
229
|
const merged = /* @__PURE__ */ new Map();
|
|
232
|
-
for (const rc of this._renderToolCalls) {
|
|
233
|
-
var _rc$agentId;
|
|
234
|
-
merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
|
|
235
|
-
}
|
|
230
|
+
for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
|
|
236
231
|
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
237
232
|
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
238
233
|
return this._cachedMergedRenderToolCalls;
|
|
@@ -249,14 +244,13 @@ react_markdown = __toESM(react_markdown);
|
|
|
249
244
|
this._notifyRenderToolCallsChanged();
|
|
250
245
|
}
|
|
251
246
|
addHookRenderToolCall(entry) {
|
|
252
|
-
|
|
253
|
-
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
247
|
+
const key = `${entry.agentId ?? ""}:${entry.name}`;
|
|
254
248
|
this._hookRenderToolCalls.set(key, entry);
|
|
255
249
|
this._cachedMergedRenderToolCalls = null;
|
|
256
250
|
this._notifyRenderToolCallsChanged();
|
|
257
251
|
}
|
|
258
252
|
removeHookRenderToolCall(name, agentId) {
|
|
259
|
-
const key = `${agentId
|
|
253
|
+
const key = `${agentId ?? ""}:${name}`;
|
|
260
254
|
if (this._hookRenderToolCalls.delete(key)) {
|
|
261
255
|
this._cachedMergedRenderToolCalls = null;
|
|
262
256
|
this._notifyRenderToolCallsChanged();
|
|
@@ -277,9 +271,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
277
271
|
setInterruptElement(element) {
|
|
278
272
|
this._interruptElement = element;
|
|
279
273
|
this.notifySubscribers((subscriber) => {
|
|
280
|
-
|
|
281
|
-
const reactSubscriber = subscriber;
|
|
282
|
-
(_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
|
|
274
|
+
subscriber.onInterruptElementChanged?.({
|
|
283
275
|
copilotkit: this,
|
|
284
276
|
interruptElement: this._interruptElement
|
|
285
277
|
});
|
|
@@ -344,11 +336,54 @@ react_markdown = __toESM(react_markdown);
|
|
|
344
336
|
|
|
345
337
|
//#endregion
|
|
346
338
|
//#region src/v2/hooks/use-default-render-tool.tsx
|
|
347
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Module-level dedup set so an unknown status value only emits a console
|
|
341
|
+
* warning the FIRST time we encounter it. Otherwise a stuck/unmapped status
|
|
342
|
+
* would log on every re-render (potentially many per second).
|
|
343
|
+
*/
|
|
344
|
+
const warnedUnknownStatuses = /* @__PURE__ */ new Set();
|
|
345
|
+
/**
|
|
346
|
+
* Map a {@link ToolCallStatus} enum value to the documented string-union
|
|
347
|
+
* status the {@link DefaultRenderProps} contract exposes. Unknown / future
|
|
348
|
+
* enum members log a warning (once per distinct value) and fall back to
|
|
349
|
+
* `"inProgress"`.
|
|
350
|
+
*/
|
|
351
|
+
function mapToolCallStatus(status) {
|
|
352
|
+
switch (status) {
|
|
353
|
+
case _copilotkit_core.ToolCallStatus.Complete: return "complete";
|
|
354
|
+
case _copilotkit_core.ToolCallStatus.Executing: return "executing";
|
|
355
|
+
case _copilotkit_core.ToolCallStatus.InProgress: return "inProgress";
|
|
356
|
+
default: {
|
|
357
|
+
const key = String(status);
|
|
358
|
+
if (!warnedUnknownStatuses.has(key)) {
|
|
359
|
+
warnedUnknownStatuses.add(key);
|
|
360
|
+
console.warn(`[CopilotKit] Unknown ToolCallStatus "${key}" in default tool-call renderer; falling back to "inProgress".`);
|
|
361
|
+
}
|
|
362
|
+
return "inProgress";
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Guarded JSON.stringify used inside the expanded `<pre>` blocks. A circular
|
|
368
|
+
* reference would otherwise crash the entire React tree on render.
|
|
369
|
+
*/
|
|
370
|
+
function safeStringifyForPre(value) {
|
|
371
|
+
try {
|
|
372
|
+
return JSON.stringify(value, null, 2);
|
|
373
|
+
} catch (err) {
|
|
374
|
+
console.warn("[CopilotKit] Failed to JSON.stringify tool-call payload for default renderer; falling back to String():", err);
|
|
375
|
+
try {
|
|
376
|
+
return String(value);
|
|
377
|
+
} catch (innerErr) {
|
|
378
|
+
console.warn("[CopilotKit] safeStringifyForPre: value could not be stringified:", innerErr);
|
|
379
|
+
return "[unserializable]";
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function DefaultToolCallRenderer({ name, toolCallId, parameters, status, result }) {
|
|
348
384
|
const [isExpanded, setIsExpanded] = (0, react.useState)(false);
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
const isComplete = statusString === "complete";
|
|
385
|
+
const isActive = status === "inProgress" || status === "executing";
|
|
386
|
+
const isComplete = status === "complete";
|
|
352
387
|
const statusLabel = isActive ? "Running" : isComplete ? "Done" : status;
|
|
353
388
|
const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa";
|
|
354
389
|
const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5";
|
|
@@ -356,7 +391,8 @@ react_markdown = __toESM(react_markdown);
|
|
|
356
391
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
357
392
|
"data-testid": "copilot-tool-render",
|
|
358
393
|
"data-tool-name": name,
|
|
359
|
-
"data-
|
|
394
|
+
"data-tool-call-id": toolCallId,
|
|
395
|
+
"data-status": status,
|
|
360
396
|
"data-args": safeStringifyForAttr(parameters),
|
|
361
397
|
"data-result": safeStringifyForAttr(result),
|
|
362
398
|
style: {
|
|
@@ -370,7 +406,9 @@ react_markdown = __toESM(react_markdown);
|
|
|
370
406
|
backgroundColor: "#fafafa",
|
|
371
407
|
padding: "14px 16px"
|
|
372
408
|
},
|
|
373
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("
|
|
409
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
410
|
+
type: "button",
|
|
411
|
+
"aria-expanded": isExpanded,
|
|
374
412
|
onClick: () => setIsExpanded(!isExpanded),
|
|
375
413
|
style: {
|
|
376
414
|
display: "flex",
|
|
@@ -378,7 +416,15 @@ react_markdown = __toESM(react_markdown);
|
|
|
378
416
|
justifyContent: "space-between",
|
|
379
417
|
gap: "10px",
|
|
380
418
|
cursor: "pointer",
|
|
381
|
-
userSelect: "none"
|
|
419
|
+
userSelect: "none",
|
|
420
|
+
width: "100%",
|
|
421
|
+
border: "none",
|
|
422
|
+
padding: 0,
|
|
423
|
+
margin: 0,
|
|
424
|
+
background: "transparent",
|
|
425
|
+
textAlign: "left",
|
|
426
|
+
font: "inherit",
|
|
427
|
+
color: "inherit"
|
|
382
428
|
},
|
|
383
429
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
384
430
|
style: {
|
|
@@ -471,7 +517,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
471
517
|
whiteSpace: "pre-wrap",
|
|
472
518
|
wordBreak: "break-word"
|
|
473
519
|
},
|
|
474
|
-
children:
|
|
520
|
+
children: safeStringifyForPre(parameters ?? {})
|
|
475
521
|
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
476
522
|
style: {
|
|
477
523
|
fontSize: "10px",
|
|
@@ -494,7 +540,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
494
540
|
whiteSpace: "pre-wrap",
|
|
495
541
|
wordBreak: "break-word"
|
|
496
542
|
},
|
|
497
|
-
children: typeof result === "string" ? result :
|
|
543
|
+
children: typeof result === "string" ? result : safeStringifyForPre(result)
|
|
498
544
|
})] })]
|
|
499
545
|
})]
|
|
500
546
|
})
|
|
@@ -505,8 +551,14 @@ react_markdown = __toESM(react_markdown);
|
|
|
505
551
|
if (typeof value === "string") return value;
|
|
506
552
|
try {
|
|
507
553
|
return JSON.stringify(value);
|
|
508
|
-
} catch (
|
|
509
|
-
|
|
554
|
+
} catch (err) {
|
|
555
|
+
console.warn("[CopilotKit] Failed to JSON.stringify tool-call payload for data-* attribute; falling back to String():", err);
|
|
556
|
+
try {
|
|
557
|
+
return String(value);
|
|
558
|
+
} catch (innerErr) {
|
|
559
|
+
console.warn("[CopilotKit] safeStringifyForAttr: value could not be stringified:", innerErr);
|
|
560
|
+
return "";
|
|
561
|
+
}
|
|
510
562
|
}
|
|
511
563
|
}
|
|
512
564
|
|
|
@@ -542,11 +594,10 @@ react_markdown = __toESM(react_markdown);
|
|
|
542
594
|
result: void 0
|
|
543
595
|
});
|
|
544
596
|
}, (prevProps, nextProps) => {
|
|
545
|
-
var _prevProps$toolMessag, _nextProps$toolMessag;
|
|
546
597
|
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
547
598
|
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
548
599
|
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
549
|
-
if (
|
|
600
|
+
if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
|
|
550
601
|
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
551
602
|
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
552
603
|
return true;
|
|
@@ -558,21 +609,17 @@ react_markdown = __toESM(react_markdown);
|
|
|
558
609
|
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
559
610
|
*/
|
|
560
611
|
function useRenderToolCall$1() {
|
|
561
|
-
var _config$agentId;
|
|
562
612
|
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
563
|
-
const
|
|
564
|
-
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;
|
|
613
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
565
614
|
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
566
615
|
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
567
616
|
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
568
617
|
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
569
|
-
var _renderConfig$render;
|
|
570
618
|
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
571
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
572
619
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
573
620
|
toolCall,
|
|
574
621
|
toolMessage,
|
|
575
|
-
RenderComponent: (
|
|
622
|
+
RenderComponent: (exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*"))?.render ?? defaultToolCallRenderAdapter,
|
|
576
623
|
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
577
624
|
}, toolCall.id);
|
|
578
625
|
}, [
|
|
@@ -582,11 +629,11 @@ react_markdown = __toESM(react_markdown);
|
|
|
582
629
|
]);
|
|
583
630
|
}
|
|
584
631
|
function defaultToolCallRenderAdapter(props) {
|
|
585
|
-
const status = props.status === _copilotkit_core.ToolCallStatus.Complete ? "complete" : props.status === _copilotkit_core.ToolCallStatus.Executing ? "executing" : "inProgress";
|
|
586
632
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultToolCallRenderer, {
|
|
587
633
|
name: props.name,
|
|
634
|
+
toolCallId: props.toolCallId,
|
|
588
635
|
parameters: props.args,
|
|
589
|
-
status,
|
|
636
|
+
status: mapToolCallStatus(props.status),
|
|
590
637
|
result: props.result
|
|
591
638
|
});
|
|
592
639
|
}
|
|
@@ -598,8 +645,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
598
645
|
react.useEffect(() => {
|
|
599
646
|
let mounted = true;
|
|
600
647
|
import("@copilotkit/web-inspector").then((mod) => {
|
|
601
|
-
|
|
602
|
-
(_mod$defineWebInspect = mod.defineWebInspector) === null || _mod$defineWebInspect === void 0 || _mod$defineWebInspect.call(mod);
|
|
648
|
+
mod.defineWebInspector?.();
|
|
603
649
|
const Component = (0, _lit_labs_react.createComponent)({
|
|
604
650
|
tagName: mod.WEB_INSPECTOR_TAG,
|
|
605
651
|
elementClass: mod.WebInspectorElement,
|
|
@@ -614,7 +660,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
614
660
|
if (!InspectorComponent) return null;
|
|
615
661
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
|
|
616
662
|
...rest,
|
|
617
|
-
core: core
|
|
663
|
+
core: core ?? null
|
|
618
664
|
});
|
|
619
665
|
};
|
|
620
666
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
@@ -754,7 +800,7 @@ react_markdown = __toESM(react_markdown);
|
|
|
754
800
|
function buildSandboxHTML(extraCspDomains) {
|
|
755
801
|
const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
756
802
|
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
757
|
-
const extra =
|
|
803
|
+
const extra = extraCspDomains?.length ? " " + extraCspDomains.join(" ") : "";
|
|
758
804
|
return `<!doctype html>
|
|
759
805
|
<html>
|
|
760
806
|
<head>
|
|
@@ -890,7 +936,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
890
936
|
* Fetches resource content on-demand via proxied MCP requests.
|
|
891
937
|
*/
|
|
892
938
|
const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
|
|
893
|
-
var _fetchedResource$_met2;
|
|
894
939
|
const { copilotkit } = useCopilotKit();
|
|
895
940
|
const containerRef = (0, react.useRef)(null);
|
|
896
941
|
const iframeRef = (0, react.useRef)(null);
|
|
@@ -909,8 +954,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
909
954
|
resourceUri: null
|
|
910
955
|
});
|
|
911
956
|
const sendToIframe = (0, react.useCallback)((msg) => {
|
|
912
|
-
|
|
913
|
-
if ((_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : _iframeRef$current.contentWindow) {
|
|
957
|
+
if (iframeRef.current?.contentWindow) {
|
|
914
958
|
console.log("[MCPAppsRenderer] Sending to iframe:", msg);
|
|
915
959
|
iframeRef.current.contentWindow.postMessage(msg, "*");
|
|
916
960
|
}
|
|
@@ -942,8 +986,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
942
986
|
(0, react.useEffect)(() => {
|
|
943
987
|
const { resourceUri, serverHash, serverId } = content;
|
|
944
988
|
if (fetchStateRef.current.inProgress && fetchStateRef.current.resourceUri === resourceUri) {
|
|
945
|
-
|
|
946
|
-
(_fetchStateRef$curren = fetchStateRef.current.promise) === null || _fetchStateRef$curren === void 0 || _fetchStateRef$curren.then((resource) => {
|
|
989
|
+
fetchStateRef.current.promise?.then((resource) => {
|
|
947
990
|
if (resource) {
|
|
948
991
|
setFetchedResource(resource);
|
|
949
992
|
setIsLoading(false);
|
|
@@ -963,14 +1006,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
963
1006
|
fetchStateRef.current.resourceUri = resourceUri;
|
|
964
1007
|
const fetchPromise = (async () => {
|
|
965
1008
|
try {
|
|
966
|
-
|
|
967
|
-
const resultData = (await mcpAppsRequestQueue.enqueue(agent, () => agent.runAgent({ forwardedProps: { __proxiedMCPRequest: {
|
|
1009
|
+
const resource = (await mcpAppsRequestQueue.enqueue(agent, () => agent.runAgent({ forwardedProps: { __proxiedMCPRequest: {
|
|
968
1010
|
serverHash,
|
|
969
1011
|
serverId,
|
|
970
1012
|
method: "resources/read",
|
|
971
1013
|
params: { uri: resourceUri }
|
|
972
|
-
} } }))).result;
|
|
973
|
-
const resource = resultData === null || resultData === void 0 || (_resultData$contents = resultData.contents) === null || _resultData$contents === void 0 ? void 0 : _resultData$contents[0];
|
|
1014
|
+
} } }))).result?.contents?.[0];
|
|
974
1015
|
if (!resource) throw new Error("No resource content in response");
|
|
975
1016
|
return resource;
|
|
976
1017
|
} catch (err) {
|
|
@@ -1001,7 +1042,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1001
1042
|
let createdIframe = null;
|
|
1002
1043
|
const setup = async () => {
|
|
1003
1044
|
try {
|
|
1004
|
-
var _fetchedResource$_met;
|
|
1005
1045
|
const iframe = document.createElement("iframe");
|
|
1006
1046
|
createdIframe = iframe;
|
|
1007
1047
|
iframe.style.width = "100%";
|
|
@@ -1013,8 +1053,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1013
1053
|
const sandboxReady = new Promise((resolve) => {
|
|
1014
1054
|
initialListener = (event) => {
|
|
1015
1055
|
if (event.source === iframe.contentWindow) {
|
|
1016
|
-
|
|
1017
|
-
if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.method) === "ui/notifications/sandbox-proxy-ready") {
|
|
1056
|
+
if (event.data?.method === "ui/notifications/sandbox-proxy-ready") {
|
|
1018
1057
|
if (initialListener) {
|
|
1019
1058
|
window.removeEventListener("message", initialListener);
|
|
1020
1059
|
initialListener = null;
|
|
@@ -1032,7 +1071,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1032
1071
|
}
|
|
1033
1072
|
return;
|
|
1034
1073
|
}
|
|
1035
|
-
|
|
1074
|
+
const cspDomains = fetchedResource._meta?.ui?.csp?.resourceDomains;
|
|
1075
|
+
iframe.srcdoc = buildSandboxHTML(cspDomains);
|
|
1036
1076
|
iframeRef.current = iframe;
|
|
1037
1077
|
container.appendChild(iframe);
|
|
1038
1078
|
await sandboxReady;
|
|
@@ -1069,17 +1109,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1069
1109
|
break;
|
|
1070
1110
|
}
|
|
1071
1111
|
try {
|
|
1072
|
-
var _params$content, _params$followUp;
|
|
1073
1112
|
const params = msg.params;
|
|
1074
1113
|
const role = params.role || "user";
|
|
1075
|
-
const textContent =
|
|
1114
|
+
const textContent = params.content?.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("\n") || "";
|
|
1076
1115
|
if (textContent) currentAgent.addMessage({
|
|
1077
1116
|
id: crypto.randomUUID(),
|
|
1078
1117
|
role,
|
|
1079
1118
|
content: textContent
|
|
1080
1119
|
});
|
|
1081
1120
|
sendResponse(msg.id, { isError: false });
|
|
1082
|
-
if ((
|
|
1121
|
+
if ((params.followUp ?? role === "user") && textContent) mcpAppsRequestQueue.enqueue(currentAgent, () => copilotkit.runAgent({ agent: currentAgent })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
|
|
1083
1122
|
} catch (err) {
|
|
1084
1123
|
console.error("[MCPAppsRenderer] ui/message error:", err);
|
|
1085
1124
|
sendResponse(msg.id, { isError: true });
|
|
@@ -1087,8 +1126,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1087
1126
|
break;
|
|
1088
1127
|
}
|
|
1089
1128
|
case "ui/open-link": {
|
|
1090
|
-
|
|
1091
|
-
const url = (_msg$params = msg.params) === null || _msg$params === void 0 ? void 0 : _msg$params.url;
|
|
1129
|
+
const url = msg.params?.url;
|
|
1092
1130
|
if (url) {
|
|
1093
1131
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
1094
1132
|
sendResponse(msg.id, { isError: false });
|
|
@@ -1205,7 +1243,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1205
1243
|
content.result,
|
|
1206
1244
|
sendNotification
|
|
1207
1245
|
]);
|
|
1208
|
-
const borderStyle =
|
|
1246
|
+
const borderStyle = fetchedResource?._meta?.ui?.prefersBorder === true ? {
|
|
1209
1247
|
borderRadius: "8px",
|
|
1210
1248
|
backgroundColor: "#f9f9f9",
|
|
1211
1249
|
border: "1px solid #e0e0e0"
|
|
@@ -1311,13 +1349,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1311
1349
|
* (no throttle delay).
|
|
1312
1350
|
*/
|
|
1313
1351
|
function shouldFlushImmediately(prev, next) {
|
|
1314
|
-
var _next$jsExpressions$l, _next$jsExpressions, _prev$jsExpressions$l, _prev$jsExpressions, _next$html, _prev$html;
|
|
1315
1352
|
if (next.cssComplete && (!prev || !prev.cssComplete)) return true;
|
|
1316
1353
|
if (next.htmlComplete) return true;
|
|
1317
1354
|
if (next.generating === false) return true;
|
|
1318
1355
|
if (next.jsFunctions && (!prev || !prev.jsFunctions)) return true;
|
|
1319
|
-
if ((
|
|
1320
|
-
if (
|
|
1356
|
+
if ((next.jsExpressions?.length ?? 0) > (prev?.jsExpressions?.length ?? 0)) return true;
|
|
1357
|
+
if (next.html?.length && (!prev || !prev.html?.length)) return true;
|
|
1321
1358
|
return false;
|
|
1322
1359
|
}
|
|
1323
1360
|
/**
|
|
@@ -1367,8 +1404,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1367
1404
|
return `<head><style>${css}</style></head>${html}`;
|
|
1368
1405
|
}
|
|
1369
1406
|
const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
|
|
1370
|
-
|
|
1371
|
-
const initialHeight = (_content$initialHeigh = content.initialHeight) !== null && _content$initialHeigh !== void 0 ? _content$initialHeigh : 200;
|
|
1407
|
+
const initialHeight = content.initialHeight ?? 200;
|
|
1372
1408
|
const [autoHeight, setAutoHeight] = (0, react.useState)(null);
|
|
1373
1409
|
const sandboxFunctions = useSandboxFunctions();
|
|
1374
1410
|
const localApi = (0, react.useMemo)(() => {
|
|
@@ -1376,13 +1412,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1376
1412
|
for (const fn of sandboxFunctions) api[fn.name] = fn.handler;
|
|
1377
1413
|
return api;
|
|
1378
1414
|
}, [sandboxFunctions]);
|
|
1379
|
-
const fullHtml = content.htmlComplete &&
|
|
1415
|
+
const fullHtml = content.htmlComplete && content.html?.length ? content.html.join("") : void 0;
|
|
1380
1416
|
const css = content.cssComplete ? content.css : void 0;
|
|
1381
1417
|
const cssReady = !!content.cssComplete;
|
|
1382
|
-
const partialHtml = !content.htmlComplete &&
|
|
1418
|
+
const partialHtml = !content.htmlComplete && content.html?.length ? content.html.join("") : void 0;
|
|
1383
1419
|
const previewBody = partialHtml ? processPartialHtml(partialHtml) : void 0;
|
|
1384
1420
|
const previewStyles = partialHtml ? extractCompleteStyles(partialHtml) : "";
|
|
1385
|
-
const hasPreview = cssReady && !!
|
|
1421
|
+
const hasPreview = cssReady && !!previewBody?.trim();
|
|
1386
1422
|
const hasVisibleSandbox = !!fullHtml || hasPreview;
|
|
1387
1423
|
const containerRef = (0, react.useRef)(null);
|
|
1388
1424
|
const sandboxRef = (0, react.useRef)(null);
|
|
@@ -1397,9 +1433,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1397
1433
|
if (!container || fullHtml || !hasPreview || previewSandboxRef.current) return;
|
|
1398
1434
|
let cancelled = false;
|
|
1399
1435
|
import("@jetbrains/websandbox").then((mod) => {
|
|
1400
|
-
var _mod$default$default, _mod$default;
|
|
1401
1436
|
if (cancelled) return;
|
|
1402
|
-
const sandbox = (
|
|
1437
|
+
const sandbox = (mod.default?.default ?? mod.default).create({}, {
|
|
1403
1438
|
frameContainer: container,
|
|
1404
1439
|
frameContent: "<head></head><body></body>",
|
|
1405
1440
|
allowAdditionalAttributes: ""
|
|
@@ -1458,9 +1493,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1458
1493
|
pendingQueueRef.current = [];
|
|
1459
1494
|
const htmlContent = css ? injectCssIntoHtml(fullHtml, css) : fullHtml;
|
|
1460
1495
|
import("@jetbrains/websandbox").then((mod) => {
|
|
1461
|
-
var _mod$default$default2, _mod$default2;
|
|
1462
1496
|
if (cancelled) return;
|
|
1463
|
-
const sandbox = (
|
|
1497
|
+
const sandbox = (mod.default?.default ?? mod.default).create(localApi, {
|
|
1464
1498
|
frameContainer: container,
|
|
1465
1499
|
frameContent: ensureHead(htmlContent),
|
|
1466
1500
|
allowAdditionalAttributes: ""
|
|
@@ -1523,16 +1557,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1523
1557
|
for (const expr of newExprs) await sandbox.run(expr);
|
|
1524
1558
|
})();
|
|
1525
1559
|
else pendingQueueRef.current.push(...newExprs);
|
|
1526
|
-
}, [
|
|
1560
|
+
}, [content.jsExpressions?.length]);
|
|
1527
1561
|
const generationDone = content.generating === false;
|
|
1528
1562
|
(0, react.useEffect)(() => {
|
|
1529
1563
|
const sandbox = sandboxRef.current;
|
|
1530
1564
|
if (!generationDone || !sandbox) return;
|
|
1531
1565
|
let handled = false;
|
|
1532
1566
|
const onMessage = (e) => {
|
|
1533
|
-
var _e$data;
|
|
1534
1567
|
if (handled) return;
|
|
1535
|
-
if (e.source === sandbox.iframe.contentWindow &&
|
|
1568
|
+
if (e.source === sandbox.iframe.contentWindow && e.data?.type === "__ck_resize") {
|
|
1536
1569
|
handled = true;
|
|
1537
1570
|
setAutoHeight(e.data.height);
|
|
1538
1571
|
window.removeEventListener("message", onMessage);
|
|
@@ -1558,7 +1591,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1558
1591
|
window.removeEventListener("message", onMessage);
|
|
1559
1592
|
};
|
|
1560
1593
|
}, [generationDone]);
|
|
1561
|
-
const height = autoHeight
|
|
1594
|
+
const height = autoHeight ?? initialHeight;
|
|
1562
1595
|
const isGenerating = content.generating !== false;
|
|
1563
1596
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1564
1597
|
ref: containerRef,
|
|
@@ -1612,7 +1645,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1612
1645
|
* Displays placeholder messages while the UI is being generated.
|
|
1613
1646
|
*/
|
|
1614
1647
|
const OpenGenerativeUIToolRenderer = function OpenGenerativeUIToolRenderer(props) {
|
|
1615
|
-
var _messages$visibleMess;
|
|
1616
1648
|
const [visibleMessageIndex, setVisibleMessageIndex] = (0, react.useState)(0);
|
|
1617
1649
|
const prevMessageCountRef = (0, react.useRef)(0);
|
|
1618
1650
|
const messages = props.args.placeholderMessages;
|
|
@@ -1627,7 +1659,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1627
1659
|
setVisibleMessageIndex((i) => (i + 1) % messages.length);
|
|
1628
1660
|
}, 5e3);
|
|
1629
1661
|
return () => clearInterval(timer);
|
|
1630
|
-
}, [messages
|
|
1662
|
+
}, [messages?.length, props.status]);
|
|
1631
1663
|
if (props.status === _copilotkit_core.ToolCallStatus.Complete) return null;
|
|
1632
1664
|
if (!messages || messages.length === 0) return null;
|
|
1633
1665
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -1636,7 +1668,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1636
1668
|
color: "#999",
|
|
1637
1669
|
fontSize: "14px"
|
|
1638
1670
|
},
|
|
1639
|
-
children:
|
|
1671
|
+
children: messages[visibleMessageIndex] ?? messages[0]
|
|
1640
1672
|
});
|
|
1641
1673
|
};
|
|
1642
1674
|
|
|
@@ -1668,7 +1700,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1668
1700
|
(0, react.useEffect)(() => {
|
|
1669
1701
|
if (content === lastContentRef.current) return;
|
|
1670
1702
|
lastContentRef.current = content;
|
|
1671
|
-
const incoming = content
|
|
1703
|
+
const incoming = content?.[A2UI_OPERATIONS_KEY];
|
|
1672
1704
|
if (!content || !Array.isArray(incoming)) {
|
|
1673
1705
|
setOperations([]);
|
|
1674
1706
|
return;
|
|
@@ -1678,14 +1710,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1678
1710
|
const groupedOperations = (0, react.useMemo)(() => {
|
|
1679
1711
|
const groups = /* @__PURE__ */ new Map();
|
|
1680
1712
|
for (const operation of operations) {
|
|
1681
|
-
|
|
1682
|
-
const surfaceId = (_getOperationSurfaceI = getOperationSurfaceId(operation)) !== null && _getOperationSurfaceI !== void 0 ? _getOperationSurfaceI : _copilotkit_a2ui_renderer.DEFAULT_SURFACE_ID;
|
|
1713
|
+
const surfaceId = getOperationSurfaceId(operation) ?? _copilotkit_a2ui_renderer.DEFAULT_SURFACE_ID;
|
|
1683
1714
|
if (!groups.has(surfaceId)) groups.set(surfaceId, []);
|
|
1684
1715
|
groups.get(surfaceId).push(operation);
|
|
1685
1716
|
}
|
|
1686
1717
|
return groups;
|
|
1687
1718
|
}, [operations]);
|
|
1688
|
-
if (!groupedOperations.size) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(loadingComponent
|
|
1719
|
+
if (!groupedOperations.size) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(loadingComponent ?? DefaultA2UILoading, {});
|
|
1689
1720
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1690
1721
|
className: "cpk:flex cpk:min-h-0 cpk:flex-1 cpk:flex-col cpk:gap-6 cpk:overflow-auto cpk:py-6",
|
|
1691
1722
|
children: Array.from(groupedOperations.entries()).map(([surfaceId, ops]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ReactSurfaceHost, {
|
|
@@ -1759,7 +1790,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1759
1790
|
const hash = JSON.stringify(operations);
|
|
1760
1791
|
if (hash === lastHashRef.current) return;
|
|
1761
1792
|
lastHashRef.current = hash;
|
|
1762
|
-
processMessages(getSurface(surfaceId) ? operations.filter((op) => !
|
|
1793
|
+
processMessages(getSurface(surfaceId) ? operations.filter((op) => !op?.createSurface) : operations);
|
|
1763
1794
|
}, [
|
|
1764
1795
|
processMessages,
|
|
1765
1796
|
getSurface,
|
|
@@ -1811,10 +1842,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1811
1842
|
});
|
|
1812
1843
|
}
|
|
1813
1844
|
function getOperationSurfaceId(operation) {
|
|
1814
|
-
var _ref, _ref2, _ref3, _operation$createSurf, _operation$createSurf2, _operation$updateComp, _operation$updateData, _operation$deleteSurf;
|
|
1815
1845
|
if (!operation || typeof operation !== "object") return null;
|
|
1816
1846
|
if (typeof operation.surfaceId === "string") return operation.surfaceId;
|
|
1817
|
-
return
|
|
1847
|
+
return operation?.createSurface?.surfaceId ?? operation?.updateComponents?.surfaceId ?? operation?.updateDataModel?.surfaceId ?? operation?.deleteSurface?.surfaceId ?? null;
|
|
1818
1848
|
}
|
|
1819
1849
|
|
|
1820
1850
|
//#endregion
|
|
@@ -1839,7 +1869,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1839
1869
|
const now = Date.now();
|
|
1840
1870
|
let { tokens } = lastRef.current;
|
|
1841
1871
|
if (now - lastRef.current.time > 200) {
|
|
1842
|
-
const chars = JSON.stringify(parameters
|
|
1872
|
+
const chars = JSON.stringify(parameters ?? {}).length;
|
|
1843
1873
|
tokens = Math.round(chars / 4);
|
|
1844
1874
|
lastRef.current = {
|
|
1845
1875
|
time: now,
|
|
@@ -2127,21 +2157,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2127
2157
|
function A2UIBuiltInToolCallRenderer() {
|
|
2128
2158
|
const { copilotkit } = useCopilotKit();
|
|
2129
2159
|
(0, react.useEffect)(() => {
|
|
2130
|
-
var _renderToolCalls;
|
|
2131
2160
|
const renderer = defineToolCallRenderer({
|
|
2132
2161
|
name: RENDER_A2UI_TOOL_NAME,
|
|
2133
2162
|
args: zod.z.any(),
|
|
2134
2163
|
render: ({ status, args: parameters }) => {
|
|
2135
2164
|
if (status === "complete") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
2136
2165
|
const params = parameters;
|
|
2137
|
-
const items = params
|
|
2166
|
+
const items = params?.items;
|
|
2138
2167
|
if (Array.isArray(items) && items.length > 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
2139
|
-
const components = params
|
|
2168
|
+
const components = params?.components;
|
|
2140
2169
|
if (Array.isArray(components) && components.length > 2) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
2141
2170
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIProgressIndicator, { parameters });
|
|
2142
2171
|
}
|
|
2143
2172
|
});
|
|
2144
|
-
const existing =
|
|
2173
|
+
const existing = copilotkit._renderToolCalls ?? [];
|
|
2145
2174
|
copilotkit.setRenderToolCalls([...existing.filter((rc) => rc.name !== RENDER_A2UI_TOOL_NAME), renderer]);
|
|
2146
2175
|
}, [copilotkit]);
|
|
2147
2176
|
return null;
|
|
@@ -2231,7 +2260,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2231
2260
|
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)";
|
|
2232
2261
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
2233
2262
|
const empty = (0, react.useMemo)(() => [], []);
|
|
2234
|
-
const value = prop
|
|
2263
|
+
const value = prop ?? empty;
|
|
2235
2264
|
const initial = (0, react.useRef)(value);
|
|
2236
2265
|
(0, react.useEffect)(() => {
|
|
2237
2266
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) console.error(warningMessage);
|
|
@@ -2239,7 +2268,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2239
2268
|
return value;
|
|
2240
2269
|
}
|
|
2241
2270
|
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, showDevConsole = false, useSingleEndpoint, onError, a2ui, defaultThrottleMs, inspectorDefaultAnchor, debug }) => {
|
|
2242
|
-
var _openGenerativeUI$des;
|
|
2243
2271
|
const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
|
|
2244
2272
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
2245
2273
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
@@ -2253,10 +2281,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2253
2281
|
else setShouldRenderInspector(false);
|
|
2254
2282
|
}, [showDevConsole]);
|
|
2255
2283
|
const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
|
|
2256
|
-
const key = (rc) => {
|
|
2257
|
-
var _rc$agentId, _rc$name;
|
|
2258
|
-
return `${(_rc$agentId = rc === null || rc === void 0 ? void 0 : rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${(_rc$name = rc === null || rc === void 0 ? void 0 : rc.name) !== null && _rc$name !== void 0 ? _rc$name : ""}`;
|
|
2259
|
-
};
|
|
2284
|
+
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
2260
2285
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
2261
2286
|
const a = setFrom(initial);
|
|
2262
2287
|
const b = setFrom(next);
|
|
@@ -2277,14 +2302,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2277
2302
|
content: OpenGenerativeUIContentSchema,
|
|
2278
2303
|
render: OpenGenerativeUIActivityRenderer
|
|
2279
2304
|
});
|
|
2280
|
-
if (runtimeA2UIEnabled) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
loadingComponent: a2ui === null || a2ui === void 0 ? void 0 : a2ui.loadingComponent
|
|
2286
|
-
}));
|
|
2287
|
-
}
|
|
2305
|
+
if (runtimeA2UIEnabled) renderers.unshift(createA2UIMessageRenderer({
|
|
2306
|
+
theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
|
|
2307
|
+
catalog: a2ui?.catalog,
|
|
2308
|
+
loadingComponent: a2ui?.loadingComponent
|
|
2309
|
+
}));
|
|
2288
2310
|
return renderers;
|
|
2289
2311
|
}, [
|
|
2290
2312
|
runtimeA2UIEnabled,
|
|
@@ -2294,7 +2316,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2294
2316
|
const allActivityRenderers = (0, react.useMemo)(() => {
|
|
2295
2317
|
return [...renderActivityMessagesList, ...builtInActivityRenderers];
|
|
2296
2318
|
}, [renderActivityMessagesList, builtInActivityRenderers]);
|
|
2297
|
-
const resolvedPublicKey = publicApiKey
|
|
2319
|
+
const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
|
|
2298
2320
|
const mergedAgents = (0, react.useMemo)(() => ({
|
|
2299
2321
|
...agents,
|
|
2300
2322
|
...selfManagedAgents
|
|
@@ -2314,10 +2336,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2314
2336
|
if (process.env.NODE_ENV === "production") throw new Error(message);
|
|
2315
2337
|
else console.warn(message);
|
|
2316
2338
|
}
|
|
2317
|
-
const chatApiEndpoint = runtimeUrl
|
|
2339
|
+
const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL$1 : void 0);
|
|
2318
2340
|
const frontendToolsList = useStableArrayProp(frontendTools, "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.");
|
|
2319
2341
|
const humanInTheLoopList = useStableArrayProp(humanInTheLoop, "humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead.");
|
|
2320
|
-
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI
|
|
2342
|
+
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI?.sandboxFunctions, "openGenerativeUI.sandboxFunctions must be a stable array.");
|
|
2321
2343
|
const processedHumanInTheLoopTools = (0, react.useMemo)(() => {
|
|
2322
2344
|
const processedTools = [];
|
|
2323
2345
|
const processedRenderToolCalls = [];
|
|
@@ -2459,10 +2481,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2459
2481
|
(0, react.useEffect)(() => {
|
|
2460
2482
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
2461
2483
|
if (onErrorRef.current) onErrorRef.current(event);
|
|
2462
|
-
else {
|
|
2463
|
-
var _event$context;
|
|
2464
|
-
console.error(`[CopilotKit] Error (${event.code}):`, event.error, (_event$context = event.context) !== null && _event$context !== void 0 ? _event$context : {});
|
|
2465
|
-
}
|
|
2484
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
2466
2485
|
} });
|
|
2467
2486
|
return () => {
|
|
2468
2487
|
subscription.unsubscribe();
|
|
@@ -2509,7 +2528,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2509
2528
|
(0, react.useEffect)(() => {
|
|
2510
2529
|
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
2511
2530
|
}, [copilotkit, defaultThrottleMs]);
|
|
2512
|
-
const designSkill =
|
|
2531
|
+
const designSkill = openGenerativeUI?.designSkill ?? DEFAULT_DESIGN_SKILL;
|
|
2513
2532
|
(0, react.useLayoutEffect)(() => {
|
|
2514
2533
|
if (!copilotkit || !openGenUIActive) return;
|
|
2515
2534
|
const id = copilotkit.addContext({
|
|
@@ -2560,8 +2579,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2560
2579
|
children: [
|
|
2561
2580
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
2562
2581
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
2563
|
-
catalog: a2ui
|
|
2564
|
-
includeSchema: a2ui
|
|
2582
|
+
catalog: a2ui?.catalog,
|
|
2583
|
+
includeSchema: a2ui?.includeSchema
|
|
2565
2584
|
}),
|
|
2566
2585
|
children,
|
|
2567
2586
|
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
@@ -2591,11 +2610,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2591
2610
|
return aHasAgent ? -1 : 1;
|
|
2592
2611
|
});
|
|
2593
2612
|
return function(params) {
|
|
2594
|
-
var _copilotkit$getRunIdF;
|
|
2595
2613
|
if (!customMessageRenderers.length) return null;
|
|
2596
2614
|
const { message, position } = params;
|
|
2597
|
-
const resolvedRunId =
|
|
2598
|
-
const runId = resolvedRunId
|
|
2615
|
+
const resolvedRunId = copilotkit.getRunIdForMessage(agentId, threadId, message.id) ?? copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
|
|
2616
|
+
const runId = resolvedRunId ?? `missing-run-id:${message.id}`;
|
|
2599
2617
|
const agent = copilotkit.getAgent(agentId);
|
|
2600
2618
|
if (!agent) return null;
|
|
2601
2619
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
@@ -2629,7 +2647,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2629
2647
|
const EMPTY_DEPS = [];
|
|
2630
2648
|
function useFrontendTool$1(tool, deps) {
|
|
2631
2649
|
const { copilotkit } = useCopilotKit();
|
|
2632
|
-
const extraDeps = deps
|
|
2650
|
+
const extraDeps = deps ?? EMPTY_DEPS;
|
|
2633
2651
|
(0, react.useEffect)(() => {
|
|
2634
2652
|
const name = tool.name;
|
|
2635
2653
|
if (copilotkit.getTool({
|
|
@@ -2737,15 +2755,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2737
2755
|
UseAgentUpdate.OnRunStatusChanged
|
|
2738
2756
|
];
|
|
2739
2757
|
function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
2740
|
-
|
|
2741
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2758
|
+
agentId ?? (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2742
2759
|
const { copilotkit } = useCopilotKit();
|
|
2743
2760
|
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
2744
2761
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
2745
|
-
const updateFlags = (0, react.useMemo)(() => updates
|
|
2762
|
+
const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
|
|
2746
2763
|
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
2747
2764
|
const agent = (0, react.useMemo)(() => {
|
|
2748
|
-
var _copilotkit$agents;
|
|
2749
2765
|
const existing = copilotkit.getAgent(agentId);
|
|
2750
2766
|
if (existing) {
|
|
2751
2767
|
provisionalAgentCache.current.delete(agentId);
|
|
@@ -2785,7 +2801,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2785
2801
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
2786
2802
|
return provisional;
|
|
2787
2803
|
}
|
|
2788
|
-
const knownAgents = Object.keys(
|
|
2804
|
+
const knownAgents = Object.keys(copilotkit.agents ?? {});
|
|
2789
2805
|
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
2790
2806
|
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.");
|
|
2791
2807
|
}, [
|
|
@@ -2835,8 +2851,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2835
2851
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
2836
2852
|
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
2837
2853
|
const chatConfig = useCopilotChatConfiguration();
|
|
2838
|
-
const configThreadId = chatConfig
|
|
2839
|
-
const configHasExplicitThreadId = chatConfig
|
|
2854
|
+
const configThreadId = chatConfig?.threadId;
|
|
2855
|
+
const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
|
|
2840
2856
|
(0, react.useEffect)(() => {
|
|
2841
2857
|
if (!configHasExplicitThreadId || !configThreadId) return;
|
|
2842
2858
|
agent.threadId = configThreadId;
|
|
@@ -2853,10 +2869,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2853
2869
|
function useSuggestions({ agentId } = {}) {
|
|
2854
2870
|
const { copilotkit } = useCopilotKit();
|
|
2855
2871
|
const config = useCopilotChatConfiguration();
|
|
2856
|
-
const resolvedAgentId = (0, react.useMemo)(() =>
|
|
2857
|
-
var _ref;
|
|
2858
|
-
return (_ref = agentId !== null && agentId !== void 0 ? agentId : config === null || config === void 0 ? void 0 : config.agentId) !== null && _ref !== void 0 ? _ref : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
2859
|
-
}, [agentId, config === null || config === void 0 ? void 0 : config.agentId]);
|
|
2872
|
+
const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [agentId, config?.agentId]);
|
|
2860
2873
|
const [suggestions, setSuggestions] = (0, react.useState)(() => {
|
|
2861
2874
|
return copilotkit.getSuggestions(resolvedAgentId).suggestions;
|
|
2862
2875
|
});
|
|
@@ -2909,11 +2922,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2909
2922
|
function useConfigureSuggestions(config, deps) {
|
|
2910
2923
|
const { copilotkit } = useCopilotKit();
|
|
2911
2924
|
const chatConfig = useCopilotChatConfiguration();
|
|
2912
|
-
const extraDeps = deps
|
|
2913
|
-
const resolvedConsumerAgentId = (0, react.useMemo)(() =>
|
|
2914
|
-
var _chatConfig$agentId;
|
|
2915
|
-
return (_chatConfig$agentId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.agentId) !== null && _chatConfig$agentId !== void 0 ? _chatConfig$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
2916
|
-
}, [chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.agentId]);
|
|
2925
|
+
const extraDeps = deps ?? [];
|
|
2926
|
+
const resolvedConsumerAgentId = (0, react.useMemo)(() => chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [chatConfig?.agentId]);
|
|
2917
2927
|
const rawConsumerAgentId = (0, react.useMemo)(() => config ? config.consumerAgentId : void 0, [config]);
|
|
2918
2928
|
const normalizationCacheRef = (0, react.useRef)({
|
|
2919
2929
|
serialized: null,
|
|
@@ -2982,9 +2992,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2982
2992
|
const requestReload = (0, react.useCallback)(() => {
|
|
2983
2993
|
if (!normalizedConfig) return;
|
|
2984
2994
|
if (isGlobalConfig) {
|
|
2985
|
-
var _copilotkit$agents;
|
|
2986
2995
|
const seen = /* @__PURE__ */ new Set();
|
|
2987
|
-
const agents = Object.values(
|
|
2996
|
+
const agents = Object.values(copilotkit.agents ?? {});
|
|
2988
2997
|
for (const entry of agents) {
|
|
2989
2998
|
const agentId = entry.agentId;
|
|
2990
2999
|
if (!agentId) continue;
|
|
@@ -3061,13 +3070,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3061
3070
|
return "instructions" in config;
|
|
3062
3071
|
}
|
|
3063
3072
|
function normalizeStaticSuggestions(suggestions) {
|
|
3064
|
-
return suggestions.map((suggestion) => {
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
isLoading: (_suggestion$isLoading = suggestion.isLoading) !== null && _suggestion$isLoading !== void 0 ? _suggestion$isLoading : false
|
|
3069
|
-
};
|
|
3070
|
-
});
|
|
3073
|
+
return suggestions.map((suggestion) => ({
|
|
3074
|
+
...suggestion,
|
|
3075
|
+
isLoading: suggestion.isLoading ?? false
|
|
3076
|
+
}));
|
|
3071
3077
|
}
|
|
3072
3078
|
|
|
3073
3079
|
//#endregion
|
|
@@ -3169,54 +3175,75 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3169
3175
|
return () => subscription.unsubscribe();
|
|
3170
3176
|
}, [agent]);
|
|
3171
3177
|
const resolve = (0, react.useCallback)((response) => {
|
|
3172
|
-
var _pendingEventRef$curr;
|
|
3173
|
-
setPendingEvent(null);
|
|
3174
3178
|
copilotkit.runAgent({
|
|
3175
3179
|
agent,
|
|
3176
3180
|
forwardedProps: { command: {
|
|
3177
3181
|
resume: response,
|
|
3178
|
-
interruptEvent:
|
|
3182
|
+
interruptEvent: pendingEventRef.current?.value
|
|
3179
3183
|
} }
|
|
3180
3184
|
});
|
|
3181
3185
|
}, [agent, copilotkit]);
|
|
3186
|
+
const renderRef = (0, react.useRef)(config.render);
|
|
3187
|
+
renderRef.current = config.render;
|
|
3188
|
+
const enabledRef = (0, react.useRef)(config.enabled);
|
|
3189
|
+
enabledRef.current = config.enabled;
|
|
3190
|
+
const handlerRef = (0, react.useRef)(config.handler);
|
|
3191
|
+
handlerRef.current = config.handler;
|
|
3192
|
+
const resolveRef = (0, react.useRef)(resolve);
|
|
3193
|
+
resolveRef.current = resolve;
|
|
3194
|
+
const isEnabled = (event) => {
|
|
3195
|
+
const predicate = enabledRef.current;
|
|
3196
|
+
if (!predicate) return true;
|
|
3197
|
+
try {
|
|
3198
|
+
return predicate(event);
|
|
3199
|
+
} catch (err) {
|
|
3200
|
+
console.error("[CopilotKit] useInterrupt enabled predicate threw; treating interrupt as disabled:", err);
|
|
3201
|
+
return false;
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3182
3204
|
(0, react.useEffect)(() => {
|
|
3183
3205
|
if (!pendingEvent) {
|
|
3184
3206
|
setHandlerResult(null);
|
|
3185
3207
|
return;
|
|
3186
3208
|
}
|
|
3187
|
-
if (
|
|
3209
|
+
if (!isEnabled(pendingEvent)) {
|
|
3188
3210
|
setHandlerResult(null);
|
|
3189
3211
|
return;
|
|
3190
3212
|
}
|
|
3191
|
-
const handler =
|
|
3213
|
+
const handler = handlerRef.current;
|
|
3192
3214
|
if (!handler) {
|
|
3193
3215
|
setHandlerResult(null);
|
|
3194
3216
|
return;
|
|
3195
3217
|
}
|
|
3196
3218
|
let cancelled = false;
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3219
|
+
let maybePromise;
|
|
3220
|
+
try {
|
|
3221
|
+
maybePromise = handler({
|
|
3222
|
+
event: pendingEvent,
|
|
3223
|
+
resolve: resolveRef.current
|
|
3224
|
+
});
|
|
3225
|
+
} catch (err) {
|
|
3226
|
+
console.error("[CopilotKit] useInterrupt handler threw; result will be null:", err);
|
|
3227
|
+
if (!cancelled) setHandlerResult(null);
|
|
3228
|
+
return () => {
|
|
3229
|
+
cancelled = true;
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3201
3232
|
if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).then((resolved) => {
|
|
3202
3233
|
if (!cancelled) setHandlerResult(resolved);
|
|
3203
|
-
}).catch(() => {
|
|
3234
|
+
}).catch((err) => {
|
|
3235
|
+
console.error("[CopilotKit] useInterrupt handler rejected; result will be null:", err);
|
|
3204
3236
|
if (!cancelled) setHandlerResult(null);
|
|
3205
3237
|
});
|
|
3206
3238
|
else setHandlerResult(maybePromise);
|
|
3207
3239
|
return () => {
|
|
3208
3240
|
cancelled = true;
|
|
3209
3241
|
};
|
|
3210
|
-
}, [
|
|
3211
|
-
pendingEvent,
|
|
3212
|
-
config.enabled,
|
|
3213
|
-
config.handler,
|
|
3214
|
-
resolve
|
|
3215
|
-
]);
|
|
3242
|
+
}, [pendingEvent]);
|
|
3216
3243
|
const element = (0, react.useMemo)(() => {
|
|
3217
3244
|
if (!pendingEvent) return null;
|
|
3218
|
-
if (
|
|
3219
|
-
return
|
|
3245
|
+
if (!isEnabled(pendingEvent)) return null;
|
|
3246
|
+
return renderRef.current({
|
|
3220
3247
|
event: pendingEvent,
|
|
3221
3248
|
result: handlerResult,
|
|
3222
3249
|
resolve
|
|
@@ -3224,19 +3251,22 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3224
3251
|
}, [
|
|
3225
3252
|
pendingEvent,
|
|
3226
3253
|
handlerResult,
|
|
3227
|
-
config.enabled,
|
|
3228
|
-
config.render,
|
|
3229
3254
|
resolve
|
|
3230
3255
|
]);
|
|
3231
3256
|
(0, react.useEffect)(() => {
|
|
3232
3257
|
if (config.renderInChat === false) return;
|
|
3233
3258
|
copilotkit.setInterruptElement(element);
|
|
3234
|
-
return () => copilotkit.setInterruptElement(null);
|
|
3235
3259
|
}, [
|
|
3236
3260
|
element,
|
|
3237
3261
|
config.renderInChat,
|
|
3238
3262
|
copilotkit
|
|
3239
3263
|
]);
|
|
3264
|
+
(0, react.useEffect)(() => {
|
|
3265
|
+
if (config.renderInChat === false) return;
|
|
3266
|
+
return () => {
|
|
3267
|
+
copilotkit.setInterruptElement(null);
|
|
3268
|
+
};
|
|
3269
|
+
}, []);
|
|
3240
3270
|
if (config.renderInChat === false) return element;
|
|
3241
3271
|
}
|
|
3242
3272
|
|
|
@@ -3576,6 +3606,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3576
3606
|
const details = bannerError.details;
|
|
3577
3607
|
const link = extractUrl(bannerError.message);
|
|
3578
3608
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3609
|
+
"data-testid": "copilot-error-banner",
|
|
3579
3610
|
style: {
|
|
3580
3611
|
position: "fixed",
|
|
3581
3612
|
bottom: "20px",
|
|
@@ -3775,9 +3806,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3775
3806
|
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
3776
3807
|
}, []);
|
|
3777
3808
|
const addToast = (0, react.useCallback)((toast) => {
|
|
3778
|
-
var _toast$id;
|
|
3779
3809
|
if (!enabled) return;
|
|
3780
|
-
const id =
|
|
3810
|
+
const id = toast.id ?? Math.random().toString(36).slice(2, 9);
|
|
3781
3811
|
setToasts((currentToasts) => {
|
|
3782
3812
|
if (currentToasts.find((toast) => toast.id === id)) return currentToasts;
|
|
3783
3813
|
return [...currentToasts, {
|
|
@@ -3904,8 +3934,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3904
3934
|
]);
|
|
3905
3935
|
const createStructuredError = (gqlError) => {
|
|
3906
3936
|
const extensions = gqlError.extensions;
|
|
3907
|
-
const originalError = extensions
|
|
3908
|
-
if (originalError
|
|
3937
|
+
const originalError = extensions?.originalError;
|
|
3938
|
+
if (originalError?.stack) {
|
|
3909
3939
|
if (originalError.stack.includes("CopilotApiDiscoveryError")) return new _copilotkit_shared.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
3910
3940
|
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) return new _copilotkit_shared.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
3911
3941
|
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) return new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
@@ -3913,8 +3943,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3913
3943
|
availableAgents: []
|
|
3914
3944
|
});
|
|
3915
3945
|
}
|
|
3916
|
-
const message =
|
|
3917
|
-
const code = extensions
|
|
3946
|
+
const message = originalError?.message || gqlError.message;
|
|
3947
|
+
const code = extensions?.code;
|
|
3918
3948
|
if (code) return new _copilotkit_shared.CopilotKitError({
|
|
3919
3949
|
message,
|
|
3920
3950
|
code
|
|
@@ -3922,12 +3952,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3922
3952
|
return null;
|
|
3923
3953
|
};
|
|
3924
3954
|
(0, react.useCallback)((error) => {
|
|
3925
|
-
|
|
3926
|
-
if ((_error$graphQLErrors = error.graphQLErrors) === null || _error$graphQLErrors === void 0 ? void 0 : _error$graphQLErrors.length) {
|
|
3955
|
+
if (error.graphQLErrors?.length) {
|
|
3927
3956
|
const graphQLErrors = error.graphQLErrors;
|
|
3928
3957
|
const routeError = (gqlError) => {
|
|
3929
|
-
const
|
|
3930
|
-
const suppression = getErrorSuppression(
|
|
3958
|
+
const visibility = gqlError.extensions?.visibility;
|
|
3959
|
+
const suppression = getErrorSuppression(visibility, shouldShowDevConsole(showDevConsole));
|
|
3931
3960
|
if (suppression) {
|
|
3932
3961
|
console.error(suppression, gqlError.message);
|
|
3933
3962
|
return;
|
|
@@ -3948,7 +3977,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3948
3977
|
graphQLErrors.forEach(routeError);
|
|
3949
3978
|
} else {
|
|
3950
3979
|
const fallbackError = new _copilotkit_shared.CopilotKitError({
|
|
3951
|
-
message:
|
|
3980
|
+
message: error?.message || String(error),
|
|
3952
3981
|
code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
|
|
3953
3982
|
});
|
|
3954
3983
|
setBannerError(fallbackError);
|
|
@@ -4135,6 +4164,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4135
4164
|
}
|
|
4136
4165
|
` }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4137
4166
|
className: "usage-banner",
|
|
4167
|
+
"data-testid": "copilot-error-banner",
|
|
4138
4168
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4139
4169
|
className: "banner-content",
|
|
4140
4170
|
children: [
|
|
@@ -4142,7 +4172,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4142
4172
|
className: "banner-message",
|
|
4143
4173
|
children: message
|
|
4144
4174
|
}),
|
|
4145
|
-
|
|
4175
|
+
actions?.primary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4146
4176
|
className: "btn-primary",
|
|
4147
4177
|
onClick: actions.primary.onClick,
|
|
4148
4178
|
children: actions.primary.label
|
|
@@ -4202,7 +4232,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4202
4232
|
headers: { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey }
|
|
4203
4233
|
}).then((response) => response.json());
|
|
4204
4234
|
this.lastResponse = response;
|
|
4205
|
-
onUpdate
|
|
4235
|
+
onUpdate?.(response);
|
|
4206
4236
|
return response;
|
|
4207
4237
|
} catch (error) {
|
|
4208
4238
|
return null;
|
|
@@ -4273,10 +4303,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4273
4303
|
maxWidth: "600px"
|
|
4274
4304
|
},
|
|
4275
4305
|
children: [errors.map((error, idx) => {
|
|
4276
|
-
|
|
4277
|
-
const
|
|
4278
|
-
const message = (_originalError$messag = originalError === null || originalError === void 0 ? void 0 : originalError.message) !== null && _originalError$messag !== void 0 ? _originalError$messag : error.message;
|
|
4279
|
-
const code = "extensions" in error ? (_error$extensions2 = error.extensions) === null || _error$extensions2 === void 0 ? void 0 : _error$extensions2.code : null;
|
|
4306
|
+
const message = ("extensions" in error ? error.extensions?.originalError : {})?.message ?? error.message;
|
|
4307
|
+
const code = "extensions" in error ? error.extensions?.code : null;
|
|
4280
4308
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4281
4309
|
style: {
|
|
4282
4310
|
marginTop: idx === 0 ? 0 : 10,
|
|
@@ -4319,8 +4347,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4319
4347
|
addToast({
|
|
4320
4348
|
type: "error",
|
|
4321
4349
|
id: errors.map((err) => {
|
|
4322
|
-
|
|
4323
|
-
const message = "extensions" in err ? ((_err$extensions = err.extensions) === null || _err$extensions === void 0 || (_err$extensions = _err$extensions.originalError) === null || _err$extensions === void 0 ? void 0 : _err$extensions.message) || err.message : err.message;
|
|
4350
|
+
const message = "extensions" in err ? (err.extensions?.originalError)?.message || err.message : err.message;
|
|
4324
4351
|
const stack = err.stack || "";
|
|
4325
4352
|
return btoa(message + stack).slice(0, 32);
|
|
4326
4353
|
}).join("|"),
|
|
@@ -4358,8 +4385,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4358
4385
|
componentDidMount() {
|
|
4359
4386
|
if (this.props.publicApiKey) statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
4360
4387
|
this.setState((prevState) => {
|
|
4361
|
-
|
|
4362
|
-
if ((newStatus === null || newStatus === void 0 ? void 0 : newStatus.severity) !== ((_prevState$status = prevState.status) === null || _prevState$status === void 0 ? void 0 : _prevState$status.severity)) return { status: newStatus !== null && newStatus !== void 0 ? newStatus : void 0 };
|
|
4388
|
+
if (newStatus?.severity !== prevState.status?.severity) return { status: newStatus ?? void 0 };
|
|
4363
4389
|
return null;
|
|
4364
4390
|
});
|
|
4365
4391
|
});
|
|
@@ -4372,14 +4398,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4372
4398
|
}
|
|
4373
4399
|
render() {
|
|
4374
4400
|
if (this.state.hasError) {
|
|
4375
|
-
if (this.state.error instanceof _copilotkit_shared.CopilotKitError) {
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
actions: getErrorActions(this.state.error)
|
|
4381
|
-
})] });
|
|
4382
|
-
}
|
|
4401
|
+
if (this.state.error instanceof _copilotkit_shared.CopilotKitError) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [this.props.children, this.props.showUsageBanner && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageBanner, {
|
|
4402
|
+
severity: this.state.status?.severity ?? this.state.error.severity,
|
|
4403
|
+
message: this.state.status?.message ?? this.state.error.message,
|
|
4404
|
+
actions: getErrorActions(this.state.error)
|
|
4405
|
+
})] });
|
|
4383
4406
|
throw this.state.error;
|
|
4384
4407
|
}
|
|
4385
4408
|
return this.props.children;
|
|
@@ -4427,7 +4450,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4427
4450
|
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
4428
4451
|
const [internalThreadId, setInternalThreadId] = (0, react.useState)(() => (0, _copilotkit_shared.randomUUID)());
|
|
4429
4452
|
const [internalIsExplicit, setInternalIsExplicit] = (0, react.useState)(false);
|
|
4430
|
-
const threadId = explicitThreadId
|
|
4453
|
+
const threadId = explicitThreadId ?? internalThreadId;
|
|
4431
4454
|
const isThreadIdExplicit = explicitThreadId != null || internalIsExplicit;
|
|
4432
4455
|
const setThreadId = (0, react.useCallback)((value) => {
|
|
4433
4456
|
setInternalThreadId(value);
|
|
@@ -4508,13 +4531,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4508
4531
|
updateRunId: shouldUpdateRunId ? runId : void 0
|
|
4509
4532
|
};
|
|
4510
4533
|
}
|
|
4511
|
-
const normalizedRunId = runId
|
|
4512
|
-
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(([, claim]) =>
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
});
|
|
4516
|
-
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[1];
|
|
4517
|
-
const claimedMessageId = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[0];
|
|
4534
|
+
const normalizedRunId = runId ?? "pending";
|
|
4535
|
+
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(([, claim]) => claim.stateRenderId === stateRenderId && (claim.runId ?? "pending") === normalizedRunId && (0, _copilotkit_shared.dataToUUID)(getStateWithoutConstantKeys(claim.stateSnapshot)) === (0, _copilotkit_shared.dataToUUID)(getStateWithoutConstantKeys(stateSnapshot)));
|
|
4536
|
+
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry?.[1];
|
|
4537
|
+
const claimedMessageId = renderClaimedByOtherMessageEntry?.[0];
|
|
4518
4538
|
if (renderClaimedByOtherMessage) {
|
|
4519
4539
|
if (messageIndex !== void 0 && renderClaimedByOtherMessage.messageIndex !== void 0 && messageIndex > renderClaimedByOtherMessage.messageIndex) return {
|
|
4520
4540
|
canRender: true,
|
|
@@ -4583,17 +4603,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4583
4603
|
* 5) last cached snapshot for stateRenderId
|
|
4584
4604
|
*/
|
|
4585
4605
|
function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
|
|
4586
|
-
|
|
4587
|
-
const lastAssistantId = agentMessages ? (_toReversed$find = [...agentMessages].toReversed().find((msg) => msg.role === "assistant")) === null || _toReversed$find === void 0 ? void 0 : _toReversed$find.id : void 0;
|
|
4606
|
+
const lastAssistantId = agentMessages ? [...agentMessages].toReversed().find((msg) => msg.role === "assistant")?.id : void 0;
|
|
4588
4607
|
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
4589
4608
|
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
4590
|
-
const messageRole = messageIndex >= 0 && agentMessages ?
|
|
4609
|
+
const messageRole = messageIndex >= 0 && agentMessages ? agentMessages[messageIndex]?.role : void 0;
|
|
4591
4610
|
let previousUserMessageId;
|
|
4592
|
-
if (messageIndex > 0 && agentMessages)
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
var _agentMessages$i2;
|
|
4596
|
-
previousUserMessageId = (_agentMessages$i2 = agentMessages[i]) === null || _agentMessages$i2 === void 0 ? void 0 : _agentMessages$i2.id;
|
|
4611
|
+
if (messageIndex > 0 && agentMessages) {
|
|
4612
|
+
for (let i = messageIndex - 1; i >= 0; i -= 1) if (agentMessages[i]?.role === "user") {
|
|
4613
|
+
previousUserMessageId = agentMessages[i]?.id;
|
|
4597
4614
|
break;
|
|
4598
4615
|
}
|
|
4599
4616
|
}
|
|
@@ -4605,11 +4622,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4605
4622
|
const messageCacheEntry = caches.byMessageId[messageId];
|
|
4606
4623
|
const cachedMessageSnapshot = readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
4607
4624
|
const cacheKey = stateRenderId !== void 0 ? `${stateRenderId}::${effectiveRunId}` : void 0;
|
|
4608
|
-
let cachedSnapshot = cachedMessageSnapshot
|
|
4625
|
+
let cachedSnapshot = cachedMessageSnapshot ?? caches.byMessageId[messageId];
|
|
4609
4626
|
if (cachedSnapshot === void 0 && cacheKey && caches.byStateRenderAndRun[cacheKey] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
4610
4627
|
if (cachedSnapshot === void 0 && stateRenderId && previousUserMessageId && caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`];
|
|
4611
4628
|
if (cachedSnapshot === void 0 && !skipLatestCache && stateRenderId && messageRole !== "assistant" && (stateSnapshotProp !== void 0 || agentState && Object.keys(agentState).length > 0)) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::latest`];
|
|
4612
|
-
const snapshotForClaim =
|
|
4629
|
+
const snapshotForClaim = existingClaim?.locked ? existingClaim.stateSnapshot ?? cachedSnapshot : hasSnapshotKeys ? snapshot : existingClaim?.stateSnapshot ?? cachedSnapshot;
|
|
4613
4630
|
return {
|
|
4614
4631
|
snapshot,
|
|
4615
4632
|
hasSnapshotKeys,
|
|
@@ -4627,37 +4644,36 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4627
4644
|
return claimsRef.current;
|
|
4628
4645
|
}
|
|
4629
4646
|
function getSnapshotCaches(claimsRef) {
|
|
4630
|
-
var _store$LAST_SNAPSHOTS, _store$LAST_SNAPSHOTS2;
|
|
4631
4647
|
const store = getClaimsStore(claimsRef);
|
|
4632
4648
|
return {
|
|
4633
|
-
byStateRenderAndRun:
|
|
4634
|
-
byMessageId:
|
|
4649
|
+
byStateRenderAndRun: store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] ?? {},
|
|
4650
|
+
byMessageId: store[LAST_SNAPSHOTS_BY_MESSAGE] ?? {}
|
|
4635
4651
|
};
|
|
4636
4652
|
}
|
|
4637
4653
|
function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex, stateSnapshot, agentState, agentMessages, claimsRef }) {
|
|
4638
|
-
var _store$LAST_SNAPSHOTS3, _claimsRef$current$me;
|
|
4639
4654
|
const store = getClaimsStore(claimsRef);
|
|
4640
4655
|
const runId = message.runId;
|
|
4641
|
-
const
|
|
4656
|
+
const cachedMessageEntry = store[LAST_SNAPSHOTS_BY_MESSAGE]?.[message.id];
|
|
4657
|
+
const { runId: cachedMessageRunId } = readCachedMessageEntry(cachedMessageEntry);
|
|
4658
|
+
const existingClaimRunId = claimsRef.current[message.id]?.runId;
|
|
4642
4659
|
const effectiveRunId = getEffectiveRunId({
|
|
4643
|
-
existingClaimRunId
|
|
4660
|
+
existingClaimRunId,
|
|
4644
4661
|
cachedMessageRunId,
|
|
4645
4662
|
runId
|
|
4646
4663
|
});
|
|
4647
4664
|
(0, react.useEffect)(() => {
|
|
4648
4665
|
return () => {
|
|
4649
4666
|
const existingClaim = claimsRef.current[message.id];
|
|
4650
|
-
if (
|
|
4651
|
-
var _existingClaim$runId, _existingClaim$runId2;
|
|
4667
|
+
if (existingClaim?.stateSnapshot && Object.keys(existingClaim.stateSnapshot).length > 0) {
|
|
4652
4668
|
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
4653
|
-
const cacheKey = `${existingClaim.stateRenderId}::${
|
|
4669
|
+
const cacheKey = `${existingClaim.stateRenderId}::${existingClaim.runId ?? "pending"}`;
|
|
4654
4670
|
snapshotCache[cacheKey] = existingClaim.stateSnapshot;
|
|
4655
4671
|
snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
|
|
4656
4672
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
4657
4673
|
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
4658
4674
|
messageCache[message.id] = {
|
|
4659
4675
|
snapshot: existingClaim.stateSnapshot,
|
|
4660
|
-
runId:
|
|
4676
|
+
runId: existingClaim.runId ?? effectiveRunId
|
|
4661
4677
|
};
|
|
4662
4678
|
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
4663
4679
|
}
|
|
@@ -4701,7 +4717,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4701
4717
|
if (resolution.lockOthers) Object.entries(claimsRef.current).forEach(([id, claim]) => {
|
|
4702
4718
|
if (id !== message.id && claim.stateRenderId === stateRenderId) claim.locked = true;
|
|
4703
4719
|
});
|
|
4704
|
-
if (existingClaim && !existingClaim.locked &&
|
|
4720
|
+
if (existingClaim && !existingClaim.locked && agentMessages?.length) {
|
|
4705
4721
|
const indexInAgentMessages = agentMessages.findIndex((msg) => msg.id === message.id);
|
|
4706
4722
|
if (indexInAgentMessages >= 0 && indexInAgentMessages < agentMessages.length - 1) existingClaim.locked = true;
|
|
4707
4723
|
}
|
|
@@ -4745,7 +4761,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4745
4761
|
//#endregion
|
|
4746
4762
|
//#region src/hooks/use-coagent-state-render-bridge.tsx
|
|
4747
4763
|
function useCoagentStateRenderBridge(agentId, props) {
|
|
4748
|
-
var _props$runId;
|
|
4749
4764
|
const { stateSnapshot, message } = props;
|
|
4750
4765
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
4751
4766
|
const { agent } = useAgent({ agentId });
|
|
@@ -4781,46 +4796,42 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4781
4796
|
agentId
|
|
4782
4797
|
]);
|
|
4783
4798
|
const stateRenderEntry = (0, react.useMemo)(() => getStateRender(message.id), [getStateRender, message.id]);
|
|
4784
|
-
const stateRenderId = stateRenderEntry
|
|
4785
|
-
const stateRender = stateRenderEntry
|
|
4799
|
+
const stateRenderId = stateRenderEntry?.[0];
|
|
4800
|
+
const stateRender = stateRenderEntry?.[1];
|
|
4786
4801
|
const { canRender } = useStateRenderRegistry({
|
|
4787
4802
|
agentId,
|
|
4788
4803
|
stateRenderId,
|
|
4789
4804
|
message: {
|
|
4790
4805
|
...message,
|
|
4791
|
-
runId:
|
|
4806
|
+
runId: props.runId ?? message.runId
|
|
4792
4807
|
},
|
|
4793
4808
|
messageIndex: props.messageIndex,
|
|
4794
4809
|
stateSnapshot,
|
|
4795
|
-
agentState: agent
|
|
4796
|
-
agentMessages: agent
|
|
4810
|
+
agentState: agent?.state,
|
|
4811
|
+
agentMessages: agent?.messages,
|
|
4797
4812
|
claimsRef
|
|
4798
4813
|
});
|
|
4799
4814
|
return (0, react.useMemo)(() => {
|
|
4800
4815
|
if (!stateRender || !stateRenderId) return null;
|
|
4801
4816
|
if (!canRender) return null;
|
|
4802
|
-
if (stateRender.handler) {
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
nodeName: nodeName !== null && nodeName !== void 0 ? nodeName : ""
|
|
4807
|
-
});
|
|
4808
|
-
}
|
|
4817
|
+
if (stateRender.handler) stateRender.handler({
|
|
4818
|
+
state: stateSnapshot ? (0, _copilotkit_shared.parseJson)(stateSnapshot, stateSnapshot) : agent?.state ?? {},
|
|
4819
|
+
nodeName: nodeName ?? ""
|
|
4820
|
+
});
|
|
4809
4821
|
if (stateRender.render) {
|
|
4810
|
-
|
|
4811
|
-
const status = (agent === null || agent === void 0 ? void 0 : agent.isRunning) ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
4822
|
+
const status = agent?.isRunning ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
4812
4823
|
if (typeof stateRender.render === "string") return stateRender.render;
|
|
4813
4824
|
return stateRender.render({
|
|
4814
4825
|
status,
|
|
4815
|
-
state:
|
|
4816
|
-
nodeName: nodeName
|
|
4826
|
+
state: claimsRef.current[message.id].stateSnapshot ?? {},
|
|
4827
|
+
nodeName: nodeName ?? ""
|
|
4817
4828
|
});
|
|
4818
4829
|
}
|
|
4819
4830
|
}, [
|
|
4820
4831
|
stateRender,
|
|
4821
4832
|
stateRenderId,
|
|
4822
|
-
agent
|
|
4823
|
-
agent
|
|
4833
|
+
agent?.state,
|
|
4834
|
+
agent?.isRunning,
|
|
4824
4835
|
nodeName,
|
|
4825
4836
|
message.id,
|
|
4826
4837
|
stateSnapshot,
|
|
@@ -4841,7 +4852,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4841
4852
|
},
|
|
4842
4853
|
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
4843
4854
|
predictStateToolsRef.current.forEach((t) => {
|
|
4844
|
-
if (
|
|
4855
|
+
if (t?.tool !== toolCallName) return;
|
|
4845
4856
|
const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
|
|
4846
4857
|
agent.setState({ [t.state_key]: emittedState[t.state_key] });
|
|
4847
4858
|
});
|
|
@@ -4857,16 +4868,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4857
4868
|
}, [agent, getSubscriber]);
|
|
4858
4869
|
};
|
|
4859
4870
|
function CopilotListenersAgentSubscription() {
|
|
4860
|
-
const
|
|
4861
|
-
const { agent } = useAgent({ agentId:
|
|
4871
|
+
const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
|
|
4872
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
4862
4873
|
usePredictStateSubscription(agent);
|
|
4863
4874
|
return null;
|
|
4864
4875
|
}
|
|
4865
4876
|
function CopilotListeners() {
|
|
4866
|
-
var _copilotkit$agents;
|
|
4867
4877
|
const { copilotkit } = useCopilotKit();
|
|
4868
4878
|
const { setBannerError } = useToast();
|
|
4869
|
-
const hasAgents = Object.keys(
|
|
4879
|
+
const hasAgents = Object.keys(copilotkit.agents ?? {}).length > 0;
|
|
4870
4880
|
const hasRuntime = copilotkit.runtimeUrl !== void 0;
|
|
4871
4881
|
(0, react.useEffect)(() => {
|
|
4872
4882
|
const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
|
|
@@ -4888,7 +4898,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4888
4898
|
return () => {
|
|
4889
4899
|
subscription.unsubscribe();
|
|
4890
4900
|
};
|
|
4891
|
-
}, [copilotkit
|
|
4901
|
+
}, [copilotkit?.subscribe]);
|
|
4892
4902
|
return hasAgents || hasRuntime ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListenersAgentSubscription, {}) : null;
|
|
4893
4903
|
}
|
|
4894
4904
|
|
|
@@ -4910,7 +4920,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4910
4920
|
* ```
|
|
4911
4921
|
*/
|
|
4912
4922
|
function CopilotKit({ children, ...props }) {
|
|
4913
|
-
var _props$useSingleEndpo;
|
|
4914
4923
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
4915
4924
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
4916
4925
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
@@ -4926,7 +4935,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4926
4935
|
...props,
|
|
4927
4936
|
showDevConsole: showInspector,
|
|
4928
4937
|
renderCustomMessages: renderArr,
|
|
4929
|
-
useSingleEndpoint:
|
|
4938
|
+
useSingleEndpoint: props.useSingleEndpoint ?? true,
|
|
4930
4939
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
|
|
4931
4940
|
...props,
|
|
4932
4941
|
children
|
|
@@ -4955,7 +4964,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4955
4964
|
source: "agent",
|
|
4956
4965
|
request: {
|
|
4957
4966
|
operation: event.code || "unknown",
|
|
4958
|
-
url: copilotApiConfig
|
|
4967
|
+
url: copilotApiConfig?.chatApiEndpoint,
|
|
4959
4968
|
startTime: Date.now()
|
|
4960
4969
|
},
|
|
4961
4970
|
technical: {
|
|
@@ -4984,7 +4993,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4984
4993
|
return null;
|
|
4985
4994
|
}
|
|
4986
4995
|
function CopilotKitInternal(cpkProps) {
|
|
4987
|
-
var _props$agent2;
|
|
4988
4996
|
const { children, ...props } = cpkProps;
|
|
4989
4997
|
/**
|
|
4990
4998
|
* This will throw an error if the props are invalid.
|
|
@@ -5048,14 +5056,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5048
5056
|
}, [removeDocument]);
|
|
5049
5057
|
const copilotApiConfig = (0, react.useMemo)(() => {
|
|
5050
5058
|
let cloud = void 0;
|
|
5051
|
-
if (publicApiKey) {
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
invalidTopics: ((_props$guardrails_c2 = props.guardrails_c) === null || _props$guardrails_c2 === void 0 ? void 0 : _props$guardrails_c2.invalidTopics) || []
|
|
5057
|
-
} } } };
|
|
5058
|
-
}
|
|
5059
|
+
if (publicApiKey) cloud = { guardrails: { input: { restrictToTopic: {
|
|
5060
|
+
enabled: Boolean(props.guardrails_c),
|
|
5061
|
+
validTopics: props.guardrails_c?.validTopics || [],
|
|
5062
|
+
invalidTopics: props.guardrails_c?.invalidTopics || []
|
|
5063
|
+
} } } };
|
|
5059
5064
|
return {
|
|
5060
5065
|
publicApiKey,
|
|
5061
5066
|
...cloud ? { cloud } : {},
|
|
@@ -5211,14 +5216,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5211
5216
|
}, []);
|
|
5212
5217
|
const memoizedChildren = (0, react.useMemo)(() => children, [children]);
|
|
5213
5218
|
const [bannerError, setBannerError] = (0, react.useState)(null);
|
|
5214
|
-
const agentLock = (0, react.useMemo)(() =>
|
|
5215
|
-
|
|
5216
|
-
return (_props$agent = props.agent) !== null && _props$agent !== void 0 ? _props$agent : null;
|
|
5217
|
-
}, [props.agent]);
|
|
5218
|
-
const forwardedParameters = (0, react.useMemo)(() => {
|
|
5219
|
-
var _props$forwardedParam;
|
|
5220
|
-
return (_props$forwardedParam = props.forwardedParameters) !== null && _props$forwardedParam !== void 0 ? _props$forwardedParam : {};
|
|
5221
|
-
}, [props.forwardedParameters]);
|
|
5219
|
+
const agentLock = (0, react.useMemo)(() => props.agent ?? null, [props.agent]);
|
|
5220
|
+
const forwardedParameters = (0, react.useMemo)(() => props.forwardedParameters ?? {}, [props.forwardedParameters]);
|
|
5222
5221
|
const updateExtensions = (0, react.useCallback)((newExtensions) => {
|
|
5223
5222
|
setExtensions((prev) => {
|
|
5224
5223
|
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
@@ -5361,7 +5360,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5361
5360
|
removeInternalErrorHandler
|
|
5362
5361
|
]);
|
|
5363
5362
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatConfigurationProvider, {
|
|
5364
|
-
agentId:
|
|
5363
|
+
agentId: props.agent ?? "default",
|
|
5365
5364
|
threadId,
|
|
5366
5365
|
hasExplicitThreadId: isThreadIdExplicit,
|
|
5367
5366
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotContext.Provider, {
|
|
@@ -5390,8 +5389,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5390
5389
|
await new Promise((resolve, reject) => {
|
|
5391
5390
|
(0, react_dom.flushSync)(async () => {
|
|
5392
5391
|
try {
|
|
5393
|
-
|
|
5394
|
-
result = await ((_action$handler = action.handler) === null || _action$handler === void 0 ? void 0 : _action$handler.call(action, args));
|
|
5392
|
+
result = await action.handler?.(args);
|
|
5395
5393
|
resolve();
|
|
5396
5394
|
} catch (error) {
|
|
5397
5395
|
reject(error);
|
|
@@ -5418,11 +5416,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5418
5416
|
function useLazyToolRenderer() {
|
|
5419
5417
|
const renderToolCall = useRenderToolCall$1();
|
|
5420
5418
|
return (0, react.useCallback)((message, messages) => {
|
|
5421
|
-
|
|
5422
|
-
if (!(message === null || message === void 0 || (_message$toolCalls = message.toolCalls) === null || _message$toolCalls === void 0 ? void 0 : _message$toolCalls.length)) return null;
|
|
5419
|
+
if (!message?.toolCalls?.length) return null;
|
|
5423
5420
|
const toolCall = message.toolCalls[0];
|
|
5424
5421
|
if (!toolCall) return null;
|
|
5425
|
-
const toolMessage = messages
|
|
5422
|
+
const toolMessage = messages?.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
|
|
5426
5423
|
return () => renderToolCall({
|
|
5427
5424
|
toolCall,
|
|
5428
5425
|
toolMessage
|
|
@@ -5433,12 +5430,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5433
5430
|
//#endregion
|
|
5434
5431
|
//#region src/hooks/use-copilot-chat_internal.ts
|
|
5435
5432
|
function useCopilotChatInternal({ suggestions, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages } = {}) {
|
|
5436
|
-
var _existingConfig$agent, _existingConfig$threa, _agent$messages5;
|
|
5437
5433
|
const { copilotkit } = useCopilotKit();
|
|
5438
5434
|
const { threadId, agentSession } = useCopilotContext();
|
|
5439
5435
|
const existingConfig = useCopilotChatConfiguration();
|
|
5440
5436
|
const [agentAvailable, setAgentAvailable] = (0, react.useState)(false);
|
|
5441
|
-
const resolvedAgentId =
|
|
5437
|
+
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
5442
5438
|
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
5443
5439
|
const lastConnectedAgentRef = (0, react.useRef)(null);
|
|
5444
5440
|
(0, react.useEffect)(() => {
|
|
@@ -5463,18 +5459,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5463
5459
|
lastConnectedAgentRef.current = null;
|
|
5464
5460
|
detached = true;
|
|
5465
5461
|
connectAbortController.abort();
|
|
5466
|
-
agent
|
|
5462
|
+
agent?.detachActiveRun();
|
|
5467
5463
|
};
|
|
5468
5464
|
}, [
|
|
5469
|
-
existingConfig
|
|
5465
|
+
existingConfig?.threadId,
|
|
5470
5466
|
agent,
|
|
5471
5467
|
copilotkit,
|
|
5472
5468
|
copilotkit.runtimeConnectionStatus,
|
|
5473
5469
|
resolvedAgentId
|
|
5474
5470
|
]);
|
|
5475
5471
|
(0, react.useEffect)(() => {
|
|
5476
|
-
onInProgress
|
|
5477
|
-
}, [agent
|
|
5472
|
+
onInProgress?.(Boolean(agent?.isRunning));
|
|
5473
|
+
}, [agent?.isRunning, onInProgress]);
|
|
5478
5474
|
const [interrupt, setInterrupt] = (0, react.useState)(null);
|
|
5479
5475
|
(0, react.useEffect)(() => {
|
|
5480
5476
|
setInterrupt(copilotkit.interruptElement);
|
|
@@ -5484,22 +5480,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5484
5480
|
return () => subscription.unsubscribe();
|
|
5485
5481
|
}, [copilotkit]);
|
|
5486
5482
|
const reset = () => {
|
|
5487
|
-
agent
|
|
5488
|
-
agent
|
|
5483
|
+
agent?.setMessages([]);
|
|
5484
|
+
agent?.setState(null);
|
|
5489
5485
|
};
|
|
5490
5486
|
const latestDelete = useUpdatedRef((0, react.useCallback)((messageId) => {
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
}, [agent === null || agent === void 0 ? void 0 : agent.setMessages, agent === null || agent === void 0 ? void 0 : agent.messages]));
|
|
5487
|
+
const filteredMessages = (agent?.messages ?? []).filter((message) => message.id !== messageId);
|
|
5488
|
+
agent?.setMessages(filteredMessages);
|
|
5489
|
+
}, [agent?.setMessages, agent?.messages]));
|
|
5495
5490
|
const latestDeleteFunc = (0, react.useCallback)((messageId) => {
|
|
5496
5491
|
return latestDelete.current(messageId);
|
|
5497
5492
|
}, [latestDelete]);
|
|
5498
5493
|
const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });
|
|
5499
5494
|
const reload = useAsyncCallback(async (reloadMessageId) => {
|
|
5500
|
-
var _agent$messages2;
|
|
5501
5495
|
if (!agent) return;
|
|
5502
|
-
const messages =
|
|
5496
|
+
const messages = agent?.messages ?? [];
|
|
5503
5497
|
if (agent.isRunning || messages.length === 0) return;
|
|
5504
5498
|
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
5505
5499
|
if (reloadMessageIndex === -1) {
|
|
@@ -5520,23 +5514,22 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5520
5514
|
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
5521
5515
|
}
|
|
5522
5516
|
} else if (messages.length > 2 && reloadMessageIndex === 0) historyCutoff = [messages[0], messages[1]];
|
|
5523
|
-
agent
|
|
5517
|
+
agent?.setMessages(historyCutoff);
|
|
5524
5518
|
if (agent) try {
|
|
5525
5519
|
await copilotkit.runAgent({ agent });
|
|
5526
5520
|
} catch (error) {
|
|
5527
5521
|
console.error("CopilotChat: runAgent failed during reload", error);
|
|
5528
5522
|
}
|
|
5529
5523
|
}, [
|
|
5530
|
-
agent
|
|
5531
|
-
agent
|
|
5532
|
-
agent
|
|
5533
|
-
copilotkit
|
|
5524
|
+
agent?.messages.length,
|
|
5525
|
+
agent?.isRunning,
|
|
5526
|
+
agent?.setMessages,
|
|
5527
|
+
copilotkit?.runAgent
|
|
5534
5528
|
]);
|
|
5535
5529
|
const latestSendMessageFunc = useAsyncCallback(async (message, options) => {
|
|
5536
|
-
var _options$followUp;
|
|
5537
5530
|
if (!agent) return;
|
|
5538
|
-
const followUp =
|
|
5539
|
-
if (options
|
|
5531
|
+
const followUp = options?.followUp ?? true;
|
|
5532
|
+
if (options?.clearSuggestions) copilotkit.clearSuggestions(resolvedAgentId);
|
|
5540
5533
|
if (onSubmitMessage) {
|
|
5541
5534
|
const content = typeof message.content === "string" ? message.content : message.content && "text" in message.content ? message.content.text : message.content && "filename" in message.content ? message.content.filename : "";
|
|
5542
5535
|
try {
|
|
@@ -5545,7 +5538,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5545
5538
|
console.error("Error in onSubmitMessage:", error);
|
|
5546
5539
|
}
|
|
5547
5540
|
}
|
|
5548
|
-
agent
|
|
5541
|
+
agent?.addMessage(message);
|
|
5549
5542
|
if (followUp) try {
|
|
5550
5543
|
await copilotkit.runAgent({ agent });
|
|
5551
5544
|
} catch (error) {
|
|
@@ -5561,20 +5554,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5561
5554
|
return latestSendMessageFunc((0, _copilotkit_runtime_client_gql.gqlToAGUI)([message])[0], options);
|
|
5562
5555
|
}, [latestSendMessageFunc]);
|
|
5563
5556
|
const latestSetMessagesFunc = (0, react.useCallback)((messages) => {
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
return agent === null || agent === void 0 || (_agent$setMessages = agent.setMessages) === null || _agent$setMessages === void 0 ? void 0 : _agent$setMessages.call(agent, (0, _copilotkit_runtime_client_gql.gqlToAGUI)(messages));
|
|
5568
|
-
}
|
|
5569
|
-
return agent === null || agent === void 0 || (_agent$setMessages2 = agent.setMessages) === null || _agent$setMessages2 === void 0 ? void 0 : _agent$setMessages2.call(agent, messages);
|
|
5570
|
-
}, [agent === null || agent === void 0 ? void 0 : agent.setMessages, agent]);
|
|
5557
|
+
if (messages.every((message) => message instanceof _copilotkit_runtime_client_gql.Message)) return agent?.setMessages?.((0, _copilotkit_runtime_client_gql.gqlToAGUI)(messages));
|
|
5558
|
+
return agent?.setMessages?.(messages);
|
|
5559
|
+
}, [agent?.setMessages, agent]);
|
|
5571
5560
|
const latestReload = useUpdatedRef(reload);
|
|
5572
5561
|
const latestReloadFunc = useAsyncCallback(async (messageId) => {
|
|
5573
|
-
|
|
5574
|
-
onReloadMessages === null || onReloadMessages === void 0 || onReloadMessages({
|
|
5562
|
+
onReloadMessages?.({
|
|
5575
5563
|
messageId,
|
|
5576
|
-
currentAgentName: agent
|
|
5577
|
-
messages:
|
|
5564
|
+
currentAgentName: agent?.agentId,
|
|
5565
|
+
messages: agent?.messages ?? []
|
|
5578
5566
|
});
|
|
5579
5567
|
return await latestReload.current(messageId);
|
|
5580
5568
|
}, [
|
|
@@ -5583,12 +5571,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5583
5571
|
onReloadMessages
|
|
5584
5572
|
]);
|
|
5585
5573
|
const latestStopFunc = (0, react.useCallback)(() => {
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
messages: (_agent$messages4 = agent === null || agent === void 0 ? void 0 : agent.messages) !== null && _agent$messages4 !== void 0 ? _agent$messages4 : []
|
|
5574
|
+
onStopGeneration?.({
|
|
5575
|
+
currentAgentName: agent?.agentId,
|
|
5576
|
+
messages: agent?.messages ?? []
|
|
5590
5577
|
});
|
|
5591
|
-
return agent
|
|
5578
|
+
return agent?.abortRun?.();
|
|
5592
5579
|
}, [onStopGeneration, agent]);
|
|
5593
5580
|
const latestReset = useUpdatedRef(reset);
|
|
5594
5581
|
const latestResetFunc = (0, react.useCallback)(() => {
|
|
@@ -5600,11 +5587,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5600
5587
|
copilotkit,
|
|
5601
5588
|
agent,
|
|
5602
5589
|
agentId: resolvedAgentId,
|
|
5603
|
-
threadId:
|
|
5590
|
+
threadId: existingConfig?.threadId ?? threadId
|
|
5604
5591
|
});
|
|
5605
|
-
const allMessages =
|
|
5592
|
+
const allMessages = agent?.messages ?? [];
|
|
5606
5593
|
const resolvedMessages = (0, react.useMemo)(() => {
|
|
5607
|
-
var _copilotkit$getAgent, _ref;
|
|
5608
5594
|
let processedMessages = allMessages.map((message) => {
|
|
5609
5595
|
if (message.role !== "assistant") return message;
|
|
5610
5596
|
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
@@ -5621,11 +5607,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5621
5607
|
position: "before"
|
|
5622
5608
|
});
|
|
5623
5609
|
try {
|
|
5624
|
-
|
|
5625
|
-
return (_renderCustomMessage = renderCustomMessage === null || renderCustomMessage === void 0 ? void 0 : renderCustomMessage({
|
|
5610
|
+
return renderCustomMessage?.({
|
|
5626
5611
|
message,
|
|
5627
5612
|
position: "before"
|
|
5628
|
-
})
|
|
5613
|
+
}) ?? null;
|
|
5629
5614
|
} catch (error) {
|
|
5630
5615
|
console.warn("[CopilotKit] renderCustomMessages failed, falling back to legacy renderer", error);
|
|
5631
5616
|
return null;
|
|
@@ -5639,10 +5624,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5639
5624
|
return message;
|
|
5640
5625
|
});
|
|
5641
5626
|
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
5642
|
-
const canUseCustomRenderer = Boolean(renderCustomMessage &&
|
|
5627
|
+
const canUseCustomRenderer = Boolean(renderCustomMessage && copilotkit?.getAgent?.(resolvedAgentId));
|
|
5643
5628
|
const placeholderRenderer = legacyCustomMessageRenderer ? legacyCustomMessageRenderer : canUseCustomRenderer ? renderCustomMessage : null;
|
|
5644
|
-
const shouldRenderPlaceholder = Boolean(agent
|
|
5645
|
-
const effectiveThreadId =
|
|
5629
|
+
const shouldRenderPlaceholder = Boolean(agent?.isRunning) || Boolean(agent?.state && Object.keys(agent.state).length);
|
|
5630
|
+
const effectiveThreadId = threadId ?? agent?.threadId ?? "default";
|
|
5646
5631
|
let latestUserIndex = -1;
|
|
5647
5632
|
for (let i = processedMessages.length - 1; i >= 0; i -= 1) if (processedMessages[i].role === "user") {
|
|
5648
5633
|
latestUserIndex = i;
|
|
@@ -5670,15 +5655,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5670
5655
|
}
|
|
5671
5656
|
return processedMessages;
|
|
5672
5657
|
}, [
|
|
5673
|
-
agent
|
|
5658
|
+
agent?.messages,
|
|
5674
5659
|
lazyToolRendered,
|
|
5675
5660
|
allMessages,
|
|
5676
5661
|
renderCustomMessage,
|
|
5677
5662
|
legacyCustomMessageRenderer,
|
|
5678
5663
|
resolvedAgentId,
|
|
5679
5664
|
copilotkit,
|
|
5680
|
-
agent
|
|
5681
|
-
agent
|
|
5665
|
+
agent?.isRunning,
|
|
5666
|
+
agent?.state
|
|
5682
5667
|
]);
|
|
5683
5668
|
const renderedSuggestions = (0, react.useMemo)(() => {
|
|
5684
5669
|
if (Array.isArray(suggestions)) return {
|
|
@@ -5700,7 +5685,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5700
5685
|
reset: latestResetFunc,
|
|
5701
5686
|
deleteMessage: latestDeleteFunc,
|
|
5702
5687
|
isAvailable: agentAvailable,
|
|
5703
|
-
isLoading: Boolean(agent
|
|
5688
|
+
isLoading: Boolean(agent?.isRunning),
|
|
5704
5689
|
suggestions: renderedSuggestions.suggestions,
|
|
5705
5690
|
setSuggestions: (suggestions) => copilotkit.addSuggestionsConfig({ suggestions }),
|
|
5706
5691
|
generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),
|
|
@@ -5722,8 +5707,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5722
5707
|
return (0, react.useMemo)(() => {
|
|
5723
5708
|
if (!copilotkit || !agent) return null;
|
|
5724
5709
|
return ({ message, position }) => {
|
|
5725
|
-
|
|
5726
|
-
const effectiveThreadId = (_ref2 = threadId !== null && threadId !== void 0 ? threadId : agent.threadId) !== null && _ref2 !== void 0 ? _ref2 : "default";
|
|
5710
|
+
const effectiveThreadId = threadId ?? agent.threadId ?? "default";
|
|
5727
5711
|
const providedRunId = message.runId;
|
|
5728
5712
|
return (0, react.createElement)(CoAgentStateRenderBridge, {
|
|
5729
5713
|
message,
|
|
@@ -5993,7 +5977,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5993
5977
|
const renderRef = (0, react.useRef)(render);
|
|
5994
5978
|
(0, react.useEffect)(() => {
|
|
5995
5979
|
renderRef.current = render;
|
|
5996
|
-
}, [render, ...dependencies
|
|
5980
|
+
}, [render, ...dependencies ?? []]);
|
|
5997
5981
|
const normalizedRender = (0, react.useMemo)(() => {
|
|
5998
5982
|
if (typeof render === "undefined") return;
|
|
5999
5983
|
return ((args) => {
|
|
@@ -6005,21 +5989,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6005
5989
|
result: typeof args.result === "string" ? (0, _copilotkit_shared.parseJson)(args.result, args.result) : args.result
|
|
6006
5990
|
});
|
|
6007
5991
|
if (typeof rendered === "string") return react.default.createElement(react.default.Fragment, null, rendered);
|
|
6008
|
-
return rendered
|
|
5992
|
+
return rendered ?? null;
|
|
6009
5993
|
});
|
|
6010
5994
|
}, []);
|
|
6011
5995
|
const handlerRef = (0, react.useRef)(tool.handler);
|
|
6012
5996
|
(0, react.useEffect)(() => {
|
|
6013
5997
|
handlerRef.current = tool.handler;
|
|
6014
|
-
}, [tool.handler, ...dependencies
|
|
5998
|
+
}, [tool.handler, ...dependencies ?? []]);
|
|
6015
5999
|
useFrontendTool$1({
|
|
6016
6000
|
name,
|
|
6017
6001
|
description,
|
|
6018
6002
|
parameters: zodParameters,
|
|
6019
|
-
handler: tool.handler ? (args) =>
|
|
6020
|
-
var _handlerRef$current;
|
|
6021
|
-
return (_handlerRef$current = handlerRef.current) === null || _handlerRef$current === void 0 ? void 0 : _handlerRef$current.call(handlerRef, args);
|
|
6022
|
-
} : void 0,
|
|
6003
|
+
handler: tool.handler ? (args) => handlerRef.current?.(args) : void 0,
|
|
6023
6004
|
followUp,
|
|
6024
6005
|
render: normalizedRender,
|
|
6025
6006
|
available: available === void 0 ? void 0 : available !== "disabled"
|
|
@@ -6063,7 +6044,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6063
6044
|
hasAddedRef.current = false;
|
|
6064
6045
|
}
|
|
6065
6046
|
};
|
|
6066
|
-
}, [tool, ...dependencies
|
|
6047
|
+
}, [tool, ...dependencies ?? []]);
|
|
6067
6048
|
}
|
|
6068
6049
|
|
|
6069
6050
|
//#endregion
|
|
@@ -6106,18 +6087,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6106
6087
|
}
|
|
6107
6088
|
})());
|
|
6108
6089
|
if (typeof rendered === "string") return react.default.createElement(react.default.Fragment, null, rendered);
|
|
6109
|
-
return rendered
|
|
6090
|
+
return rendered ?? null;
|
|
6110
6091
|
};
|
|
6111
|
-
}, [render, ...dependencies
|
|
6092
|
+
}, [render, ...dependencies ?? []]);
|
|
6112
6093
|
useHumanInTheLoop$1({
|
|
6113
6094
|
name,
|
|
6114
6095
|
description,
|
|
6115
6096
|
followUp,
|
|
6116
6097
|
parameters: zodParameters,
|
|
6117
|
-
render: ((args) =>
|
|
6118
|
-
var _renderRef$current, _renderRef$current2;
|
|
6119
|
-
return (_renderRef$current = (_renderRef$current2 = renderRef.current) === null || _renderRef$current2 === void 0 ? void 0 : _renderRef$current2.call(renderRef, args)) !== null && _renderRef$current !== void 0 ? _renderRef$current : null;
|
|
6120
|
-
})
|
|
6098
|
+
render: ((args) => renderRef.current?.(args) ?? null)
|
|
6121
6099
|
});
|
|
6122
6100
|
}
|
|
6123
6101
|
|
|
@@ -6377,7 +6355,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6377
6355
|
const idRef = (0, react.useRef)((0, _copilotkit_shared.randomId)());
|
|
6378
6356
|
const { setBannerError, addToast } = useToast();
|
|
6379
6357
|
(0, react.useEffect)(() => {
|
|
6380
|
-
if (
|
|
6358
|
+
if (availableAgents?.length && !availableAgents.some((a) => a.name === action.name)) {
|
|
6381
6359
|
`${action.name}`;
|
|
6382
6360
|
setBannerError(new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
6383
6361
|
agentName: action.name,
|
|
@@ -6541,7 +6519,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6541
6519
|
if (!found && available === "disabled") return;
|
|
6542
6520
|
ctxIdRef.current = copilotkit.addContext({
|
|
6543
6521
|
description,
|
|
6544
|
-
value: (convert
|
|
6522
|
+
value: (convert ?? JSON.stringify)(value)
|
|
6545
6523
|
});
|
|
6546
6524
|
return () => {
|
|
6547
6525
|
if (!ctxIdRef.current) return;
|
|
@@ -6693,11 +6671,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6693
6671
|
...agent.state,
|
|
6694
6672
|
...newState
|
|
6695
6673
|
});
|
|
6696
|
-
}, [agent
|
|
6674
|
+
}, [agent?.state, agent?.setState]);
|
|
6697
6675
|
(0, react.useEffect)(() => {
|
|
6698
|
-
var _options$config;
|
|
6699
6676
|
if (!options.config && !options.configurable) return;
|
|
6700
|
-
let config =
|
|
6677
|
+
let config = options.config ?? {};
|
|
6701
6678
|
if (options.configurable) config = {
|
|
6702
6679
|
...config,
|
|
6703
6680
|
configurable: {
|
|
@@ -6708,7 +6685,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6708
6685
|
copilotkit.setProperties(config);
|
|
6709
6686
|
}, [options.config, options.configurable]);
|
|
6710
6687
|
(0, react.useEffect)(() => {
|
|
6711
|
-
if (
|
|
6688
|
+
if (agent?.state && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) handleStateUpdate(options.state);
|
|
6712
6689
|
}, [
|
|
6713
6690
|
agent,
|
|
6714
6691
|
(0, react.useMemo)(() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]),
|
|
@@ -6746,12 +6723,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6746
6723
|
hasStateValues
|
|
6747
6724
|
]);
|
|
6748
6725
|
return (0, react.useMemo)(() => {
|
|
6749
|
-
var _agent$agentId;
|
|
6750
6726
|
if (!agent) {
|
|
6751
|
-
var _ref, _ref2;
|
|
6752
6727
|
const noop = () => {};
|
|
6753
6728
|
const noopAsync = async () => {};
|
|
6754
|
-
const initialState = (
|
|
6729
|
+
const initialState = ("state" in options && options.state) ?? ("initialState" in options && options.initialState) ?? {};
|
|
6755
6730
|
return {
|
|
6756
6731
|
name: options.name,
|
|
6757
6732
|
nodeName,
|
|
@@ -6765,7 +6740,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6765
6740
|
};
|
|
6766
6741
|
}
|
|
6767
6742
|
return {
|
|
6768
|
-
name:
|
|
6743
|
+
name: agent?.agentId ?? options.name,
|
|
6769
6744
|
nodeName,
|
|
6770
6745
|
threadId: agent.threadId,
|
|
6771
6746
|
running: agent.isRunning,
|
|
@@ -6776,13 +6751,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6776
6751
|
run: agent.runAgent
|
|
6777
6752
|
};
|
|
6778
6753
|
}, [
|
|
6779
|
-
agent
|
|
6780
|
-
agent
|
|
6781
|
-
agent
|
|
6782
|
-
agent
|
|
6783
|
-
agent
|
|
6784
|
-
agent
|
|
6785
|
-
agent
|
|
6754
|
+
agent?.state,
|
|
6755
|
+
agent?.runAgent,
|
|
6756
|
+
agent?.abortRun,
|
|
6757
|
+
agent?.runAgent,
|
|
6758
|
+
agent?.threadId,
|
|
6759
|
+
agent?.isRunning,
|
|
6760
|
+
agent?.agentId,
|
|
6786
6761
|
handleStateUpdate,
|
|
6787
6762
|
options.name
|
|
6788
6763
|
]);
|
|
@@ -6825,12 +6800,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6825
6800
|
return new _copilotkit_runtime_client_gql.CopilotRuntimeClient({
|
|
6826
6801
|
...runtimeOptions,
|
|
6827
6802
|
handleGQLErrors: (error) => {
|
|
6828
|
-
|
|
6829
|
-
if ((_graphQLErrors = error.graphQLErrors) === null || _graphQLErrors === void 0 ? void 0 : _graphQLErrors.length) {
|
|
6803
|
+
if (error.graphQLErrors?.length) {
|
|
6830
6804
|
const graphQLErrors = error.graphQLErrors;
|
|
6831
6805
|
const routeError = (gqlError) => {
|
|
6832
|
-
|
|
6833
|
-
if ((extensions === null || extensions === void 0 ? void 0 : extensions.visibility) === _copilotkit_shared.ErrorVisibility.SILENT) {
|
|
6806
|
+
if (gqlError.extensions?.visibility === _copilotkit_shared.ErrorVisibility.SILENT) {
|
|
6834
6807
|
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
6835
6808
|
return;
|
|
6836
6809
|
}
|
|
@@ -6857,7 +6830,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6857
6830
|
graphQLErrors.forEach(routeError);
|
|
6858
6831
|
} else {
|
|
6859
6832
|
const fallbackError = new _copilotkit_shared.CopilotKitError({
|
|
6860
|
-
message:
|
|
6833
|
+
message: error?.message || String(error),
|
|
6861
6834
|
code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
|
|
6862
6835
|
});
|
|
6863
6836
|
setBannerError(fallbackError);
|
|
@@ -6879,18 +6852,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6879
6852
|
]);
|
|
6880
6853
|
};
|
|
6881
6854
|
function createStructuredError(gqlError) {
|
|
6882
|
-
var _originalError$stack, _originalError$stack2, _originalError$stack3;
|
|
6883
6855
|
const extensions = gqlError.extensions;
|
|
6884
|
-
const originalError = extensions
|
|
6885
|
-
const message =
|
|
6886
|
-
const code = extensions
|
|
6856
|
+
const originalError = extensions?.originalError;
|
|
6857
|
+
const message = originalError?.message || gqlError.message;
|
|
6858
|
+
const code = extensions?.code;
|
|
6887
6859
|
if (code) return new _copilotkit_shared.CopilotKitError({
|
|
6888
6860
|
message,
|
|
6889
6861
|
code
|
|
6890
6862
|
});
|
|
6891
|
-
if (originalError
|
|
6892
|
-
if (originalError
|
|
6893
|
-
if (originalError
|
|
6863
|
+
if (originalError?.stack?.includes("CopilotApiDiscoveryError")) return new _copilotkit_shared.CopilotKitApiDiscoveryError({ message });
|
|
6864
|
+
if (originalError?.stack?.includes("CopilotKitRemoteEndpointDiscoveryError")) return new _copilotkit_shared.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
6865
|
+
if (originalError?.stack?.includes("CopilotKitAgentDiscoveryError")) return new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
6894
6866
|
agentName: "",
|
|
6895
6867
|
availableAgents: []
|
|
6896
6868
|
});
|
|
@@ -6919,8 +6891,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6919
6891
|
const wrappedRender = (0, react.useCallback)((props) => {
|
|
6920
6892
|
if (!Object.values(authStates_c || {}).some((state) => state.status === "authenticated")) {
|
|
6921
6893
|
pendingActionRef.current = props;
|
|
6922
|
-
return
|
|
6923
|
-
setAuthStates_c
|
|
6894
|
+
return authConfig_c?.SignInComponent ? react.default.createElement(authConfig_c.SignInComponent, { onSignInComplete: (authState) => {
|
|
6895
|
+
setAuthStates_c?.((prev) => ({
|
|
6924
6896
|
...prev,
|
|
6925
6897
|
[action.name]: authState
|
|
6926
6898
|
}));
|
|
@@ -6957,12 +6929,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6957
6929
|
};
|
|
6958
6930
|
}
|
|
6959
6931
|
function useLangGraphInterrupt(action, _dependencies) {
|
|
6960
|
-
var _ref, _action$agentId;
|
|
6961
6932
|
const actionRef = (0, react.useRef)(action);
|
|
6962
6933
|
actionRef.current = action;
|
|
6963
6934
|
const existingConfig = useCopilotChatConfiguration();
|
|
6964
|
-
const resolvedAgentId =
|
|
6965
|
-
const threadId = existingConfig
|
|
6935
|
+
const resolvedAgentId = action.agentId ?? existingConfig?.agentId ?? "default";
|
|
6936
|
+
const threadId = existingConfig?.threadId;
|
|
6966
6937
|
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
6967
6938
|
const metadataRef = (0, react.useRef)({
|
|
6968
6939
|
agentName: resolvedAgentId,
|
|
@@ -6987,8 +6958,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6987
6958
|
return rendered;
|
|
6988
6959
|
}, []),
|
|
6989
6960
|
handler: (0, react.useCallback)(({ event, resolve }) => {
|
|
6990
|
-
|
|
6991
|
-
return (_actionRef$current$ha = (_actionRef$current = actionRef.current).handler) === null || _actionRef$current$ha === void 0 ? void 0 : _actionRef$current$ha.call(_actionRef$current, {
|
|
6961
|
+
return actionRef.current.handler?.({
|
|
6992
6962
|
event: toV1Event(event),
|
|
6993
6963
|
resolve: (r) => resolve(r)
|
|
6994
6964
|
});
|
|
@@ -7053,7 +7023,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7053
7023
|
if (available === "disabled") return;
|
|
7054
7024
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
7055
7025
|
return () => {
|
|
7056
|
-
setAdditionalInstructions((prevInstructions) =>
|
|
7026
|
+
setAdditionalInstructions((prevInstructions) => prevInstructions?.filter((instruction) => instruction !== instructions) || []);
|
|
7057
7027
|
};
|
|
7058
7028
|
}, [
|
|
7059
7029
|
available,
|
|
@@ -7135,10 +7105,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7135
7105
|
* removes it on unmount, ensuring a clean and efficient lifecycle management.
|
|
7136
7106
|
*/
|
|
7137
7107
|
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
7138
|
-
|
|
7139
|
-
const
|
|
7140
|
-
const resolvedAgentId = (_existingConfig$agent = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId) !== null && _existingConfig$agent !== void 0 ? _existingConfig$agent : "default";
|
|
7141
|
-
const available = (_ref = config.available === "enabled" ? "always" : config.available) !== null && _ref !== void 0 ? _ref : "before-first-message";
|
|
7108
|
+
const resolvedAgentId = useCopilotChatConfiguration()?.agentId ?? "default";
|
|
7109
|
+
const available = (config.available === "enabled" ? "always" : config.available) ?? "before-first-message";
|
|
7142
7110
|
useConfigureSuggestions({
|
|
7143
7111
|
...config,
|
|
7144
7112
|
available,
|
|
@@ -7226,7 +7194,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7226
7194
|
* @param data The data to use for the task.
|
|
7227
7195
|
*/
|
|
7228
7196
|
async run(context, data) {
|
|
7229
|
-
var _response$data;
|
|
7230
7197
|
const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
|
|
7231
7198
|
for (const fn of this.actions) actions[fn.name] = fn;
|
|
7232
7199
|
let contextString = "";
|
|
@@ -7257,7 +7224,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7257
7224
|
properties: context.copilotApiConfig.properties
|
|
7258
7225
|
}).toPromise();
|
|
7259
7226
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
7260
|
-
const functionCalls = (0, _copilotkit_runtime_client_gql.convertGqlOutputToMessages)(
|
|
7227
|
+
const functionCalls = (0, _copilotkit_runtime_client_gql.convertGqlOutputToMessages)(response.data?.generateCopilotResponse?.messages || []).filter((m) => m.isActionExecutionMessage());
|
|
7261
7228
|
for (const functionCall of functionCalls) await functionCallHandler({
|
|
7262
7229
|
messages,
|
|
7263
7230
|
name: functionCall.name,
|