@copilotkit/react-core 1.59.0 → 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-L4mM_JqG.mjs → copilotkit-B5RsC6la.mjs} +144 -39
- 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-B4ouY7qC.cjs → copilotkit-IQO0VDZb.cjs} +144 -39
- 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 +368 -398
- 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 +444 -523
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +12 -7
- package/dist/copilotkit-B4ouY7qC.cjs.map +0 -1
- package/dist/copilotkit-L4mM_JqG.mjs.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;
|
|
@@ -2215,6 +2244,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2215
2244
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
2216
2245
|
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
2217
2246
|
const COPILOT_CLOUD_CHAT_URL$1 = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
2247
|
+
const EMPTY_HEADERS = Object.freeze({});
|
|
2248
|
+
const EMPTY_PROPERTIES = Object.freeze({});
|
|
2249
|
+
const EMPTY_AGENTS = Object.freeze({});
|
|
2218
2250
|
const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follow these design principles inspired by shadcn/ui:
|
|
2219
2251
|
|
|
2220
2252
|
- Use a minimal, flat aesthetic. Avoid drop shadows and gradients — rely on subtle borders (1px solid, light gray like #e5e7eb) to define surfaces.
|
|
@@ -2228,15 +2260,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2228
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)";
|
|
2229
2261
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
2230
2262
|
const empty = (0, react.useMemo)(() => [], []);
|
|
2231
|
-
const value = prop
|
|
2263
|
+
const value = prop ?? empty;
|
|
2232
2264
|
const initial = (0, react.useRef)(value);
|
|
2233
2265
|
(0, react.useEffect)(() => {
|
|
2234
2266
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) console.error(warningMessage);
|
|
2235
2267
|
}, [value, warningMessage]);
|
|
2236
2268
|
return value;
|
|
2237
2269
|
}
|
|
2238
|
-
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp =
|
|
2239
|
-
var _openGenerativeUI$des;
|
|
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 }) => {
|
|
2240
2271
|
const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
|
|
2241
2272
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
2242
2273
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
@@ -2250,10 +2281,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2250
2281
|
else setShouldRenderInspector(false);
|
|
2251
2282
|
}, [showDevConsole]);
|
|
2252
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) => {
|
|
2253
|
-
const key = (rc) => {
|
|
2254
|
-
var _rc$agentId, _rc$name;
|
|
2255
|
-
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 : ""}`;
|
|
2256
|
-
};
|
|
2284
|
+
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
2257
2285
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
2258
2286
|
const a = setFrom(initial);
|
|
2259
2287
|
const b = setFrom(next);
|
|
@@ -2274,14 +2302,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2274
2302
|
content: OpenGenerativeUIContentSchema,
|
|
2275
2303
|
render: OpenGenerativeUIActivityRenderer
|
|
2276
2304
|
});
|
|
2277
|
-
if (runtimeA2UIEnabled) {
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
loadingComponent: a2ui === null || a2ui === void 0 ? void 0 : a2ui.loadingComponent
|
|
2283
|
-
}));
|
|
2284
|
-
}
|
|
2305
|
+
if (runtimeA2UIEnabled) renderers.unshift(createA2UIMessageRenderer({
|
|
2306
|
+
theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
|
|
2307
|
+
catalog: a2ui?.catalog,
|
|
2308
|
+
loadingComponent: a2ui?.loadingComponent
|
|
2309
|
+
}));
|
|
2285
2310
|
return renderers;
|
|
2286
2311
|
}, [
|
|
2287
2312
|
runtimeA2UIEnabled,
|
|
@@ -2291,7 +2316,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2291
2316
|
const allActivityRenderers = (0, react.useMemo)(() => {
|
|
2292
2317
|
return [...renderActivityMessagesList, ...builtInActivityRenderers];
|
|
2293
2318
|
}, [renderActivityMessagesList, builtInActivityRenderers]);
|
|
2294
|
-
const resolvedPublicKey = publicApiKey
|
|
2319
|
+
const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
|
|
2295
2320
|
const mergedAgents = (0, react.useMemo)(() => ({
|
|
2296
2321
|
...agents,
|
|
2297
2322
|
...selfManagedAgents
|
|
@@ -2311,10 +2336,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2311
2336
|
if (process.env.NODE_ENV === "production") throw new Error(message);
|
|
2312
2337
|
else console.warn(message);
|
|
2313
2338
|
}
|
|
2314
|
-
const chatApiEndpoint = runtimeUrl
|
|
2339
|
+
const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL$1 : void 0);
|
|
2315
2340
|
const frontendToolsList = useStableArrayProp(frontendTools, "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.");
|
|
2316
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.");
|
|
2317
|
-
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI
|
|
2342
|
+
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI?.sandboxFunctions, "openGenerativeUI.sandboxFunctions must be a stable array.");
|
|
2318
2343
|
const processedHumanInTheLoopTools = (0, react.useMemo)(() => {
|
|
2319
2344
|
const processedTools = [];
|
|
2320
2345
|
const processedRenderToolCalls = [];
|
|
@@ -2456,10 +2481,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2456
2481
|
(0, react.useEffect)(() => {
|
|
2457
2482
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
2458
2483
|
if (onErrorRef.current) onErrorRef.current(event);
|
|
2459
|
-
else {
|
|
2460
|
-
var _event$context;
|
|
2461
|
-
console.error(`[CopilotKit] Error (${event.code}):`, event.error, (_event$context = event.context) !== null && _event$context !== void 0 ? _event$context : {});
|
|
2462
|
-
}
|
|
2484
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
2463
2485
|
} });
|
|
2464
2486
|
return () => {
|
|
2465
2487
|
subscription.unsubscribe();
|
|
@@ -2506,7 +2528,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2506
2528
|
(0, react.useEffect)(() => {
|
|
2507
2529
|
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
2508
2530
|
}, [copilotkit, defaultThrottleMs]);
|
|
2509
|
-
const designSkill =
|
|
2531
|
+
const designSkill = openGenerativeUI?.designSkill ?? DEFAULT_DESIGN_SKILL;
|
|
2510
2532
|
(0, react.useLayoutEffect)(() => {
|
|
2511
2533
|
if (!copilotkit || !openGenUIActive) return;
|
|
2512
2534
|
const id = copilotkit.addContext({
|
|
@@ -2557,8 +2579,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2557
2579
|
children: [
|
|
2558
2580
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
2559
2581
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
2560
|
-
catalog: a2ui
|
|
2561
|
-
includeSchema: a2ui
|
|
2582
|
+
catalog: a2ui?.catalog,
|
|
2583
|
+
includeSchema: a2ui?.includeSchema
|
|
2562
2584
|
}),
|
|
2563
2585
|
children,
|
|
2564
2586
|
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
@@ -2588,11 +2610,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2588
2610
|
return aHasAgent ? -1 : 1;
|
|
2589
2611
|
});
|
|
2590
2612
|
return function(params) {
|
|
2591
|
-
var _copilotkit$getRunIdF;
|
|
2592
2613
|
if (!customMessageRenderers.length) return null;
|
|
2593
2614
|
const { message, position } = params;
|
|
2594
|
-
const resolvedRunId =
|
|
2595
|
-
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}`;
|
|
2596
2617
|
const agent = copilotkit.getAgent(agentId);
|
|
2597
2618
|
if (!agent) return null;
|
|
2598
2619
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
@@ -2626,7 +2647,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2626
2647
|
const EMPTY_DEPS = [];
|
|
2627
2648
|
function useFrontendTool$1(tool, deps) {
|
|
2628
2649
|
const { copilotkit } = useCopilotKit();
|
|
2629
|
-
const extraDeps = deps
|
|
2650
|
+
const extraDeps = deps ?? EMPTY_DEPS;
|
|
2630
2651
|
(0, react.useEffect)(() => {
|
|
2631
2652
|
const name = tool.name;
|
|
2632
2653
|
if (copilotkit.getTool({
|
|
@@ -2734,15 +2755,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2734
2755
|
UseAgentUpdate.OnRunStatusChanged
|
|
2735
2756
|
];
|
|
2736
2757
|
function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
2737
|
-
|
|
2738
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2758
|
+
agentId ?? (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2739
2759
|
const { copilotkit } = useCopilotKit();
|
|
2740
2760
|
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
2741
2761
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
2742
|
-
const updateFlags = (0, react.useMemo)(() => updates
|
|
2762
|
+
const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
|
|
2743
2763
|
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
2744
2764
|
const agent = (0, react.useMemo)(() => {
|
|
2745
|
-
var _copilotkit$agents;
|
|
2746
2765
|
const existing = copilotkit.getAgent(agentId);
|
|
2747
2766
|
if (existing) {
|
|
2748
2767
|
provisionalAgentCache.current.delete(agentId);
|
|
@@ -2782,7 +2801,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2782
2801
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
2783
2802
|
return provisional;
|
|
2784
2803
|
}
|
|
2785
|
-
const knownAgents = Object.keys(
|
|
2804
|
+
const knownAgents = Object.keys(copilotkit.agents ?? {});
|
|
2786
2805
|
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
2787
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.");
|
|
2788
2807
|
}, [
|
|
@@ -2832,8 +2851,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2832
2851
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
2833
2852
|
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
2834
2853
|
const chatConfig = useCopilotChatConfiguration();
|
|
2835
|
-
const configThreadId = chatConfig
|
|
2836
|
-
const configHasExplicitThreadId = chatConfig
|
|
2854
|
+
const configThreadId = chatConfig?.threadId;
|
|
2855
|
+
const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
|
|
2837
2856
|
(0, react.useEffect)(() => {
|
|
2838
2857
|
if (!configHasExplicitThreadId || !configThreadId) return;
|
|
2839
2858
|
agent.threadId = configThreadId;
|
|
@@ -2850,10 +2869,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2850
2869
|
function useSuggestions({ agentId } = {}) {
|
|
2851
2870
|
const { copilotkit } = useCopilotKit();
|
|
2852
2871
|
const config = useCopilotChatConfiguration();
|
|
2853
|
-
const resolvedAgentId = (0, react.useMemo)(() =>
|
|
2854
|
-
var _ref;
|
|
2855
|
-
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;
|
|
2856
|
-
}, [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]);
|
|
2857
2873
|
const [suggestions, setSuggestions] = (0, react.useState)(() => {
|
|
2858
2874
|
return copilotkit.getSuggestions(resolvedAgentId).suggestions;
|
|
2859
2875
|
});
|
|
@@ -2906,11 +2922,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2906
2922
|
function useConfigureSuggestions(config, deps) {
|
|
2907
2923
|
const { copilotkit } = useCopilotKit();
|
|
2908
2924
|
const chatConfig = useCopilotChatConfiguration();
|
|
2909
|
-
const extraDeps = deps
|
|
2910
|
-
const resolvedConsumerAgentId = (0, react.useMemo)(() =>
|
|
2911
|
-
var _chatConfig$agentId;
|
|
2912
|
-
return (_chatConfig$agentId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.agentId) !== null && _chatConfig$agentId !== void 0 ? _chatConfig$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
2913
|
-
}, [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]);
|
|
2914
2927
|
const rawConsumerAgentId = (0, react.useMemo)(() => config ? config.consumerAgentId : void 0, [config]);
|
|
2915
2928
|
const normalizationCacheRef = (0, react.useRef)({
|
|
2916
2929
|
serialized: null,
|
|
@@ -2979,9 +2992,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2979
2992
|
const requestReload = (0, react.useCallback)(() => {
|
|
2980
2993
|
if (!normalizedConfig) return;
|
|
2981
2994
|
if (isGlobalConfig) {
|
|
2982
|
-
var _copilotkit$agents;
|
|
2983
2995
|
const seen = /* @__PURE__ */ new Set();
|
|
2984
|
-
const agents = Object.values(
|
|
2996
|
+
const agents = Object.values(copilotkit.agents ?? {});
|
|
2985
2997
|
for (const entry of agents) {
|
|
2986
2998
|
const agentId = entry.agentId;
|
|
2987
2999
|
if (!agentId) continue;
|
|
@@ -3058,13 +3070,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3058
3070
|
return "instructions" in config;
|
|
3059
3071
|
}
|
|
3060
3072
|
function normalizeStaticSuggestions(suggestions) {
|
|
3061
|
-
return suggestions.map((suggestion) => {
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
isLoading: (_suggestion$isLoading = suggestion.isLoading) !== null && _suggestion$isLoading !== void 0 ? _suggestion$isLoading : false
|
|
3066
|
-
};
|
|
3067
|
-
});
|
|
3073
|
+
return suggestions.map((suggestion) => ({
|
|
3074
|
+
...suggestion,
|
|
3075
|
+
isLoading: suggestion.isLoading ?? false
|
|
3076
|
+
}));
|
|
3068
3077
|
}
|
|
3069
3078
|
|
|
3070
3079
|
//#endregion
|
|
@@ -3166,54 +3175,75 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3166
3175
|
return () => subscription.unsubscribe();
|
|
3167
3176
|
}, [agent]);
|
|
3168
3177
|
const resolve = (0, react.useCallback)((response) => {
|
|
3169
|
-
var _pendingEventRef$curr;
|
|
3170
|
-
setPendingEvent(null);
|
|
3171
3178
|
copilotkit.runAgent({
|
|
3172
3179
|
agent,
|
|
3173
3180
|
forwardedProps: { command: {
|
|
3174
3181
|
resume: response,
|
|
3175
|
-
interruptEvent:
|
|
3182
|
+
interruptEvent: pendingEventRef.current?.value
|
|
3176
3183
|
} }
|
|
3177
3184
|
});
|
|
3178
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
|
+
};
|
|
3179
3204
|
(0, react.useEffect)(() => {
|
|
3180
3205
|
if (!pendingEvent) {
|
|
3181
3206
|
setHandlerResult(null);
|
|
3182
3207
|
return;
|
|
3183
3208
|
}
|
|
3184
|
-
if (
|
|
3209
|
+
if (!isEnabled(pendingEvent)) {
|
|
3185
3210
|
setHandlerResult(null);
|
|
3186
3211
|
return;
|
|
3187
3212
|
}
|
|
3188
|
-
const handler =
|
|
3213
|
+
const handler = handlerRef.current;
|
|
3189
3214
|
if (!handler) {
|
|
3190
3215
|
setHandlerResult(null);
|
|
3191
3216
|
return;
|
|
3192
3217
|
}
|
|
3193
3218
|
let cancelled = false;
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
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
|
+
}
|
|
3198
3232
|
if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).then((resolved) => {
|
|
3199
3233
|
if (!cancelled) setHandlerResult(resolved);
|
|
3200
|
-
}).catch(() => {
|
|
3234
|
+
}).catch((err) => {
|
|
3235
|
+
console.error("[CopilotKit] useInterrupt handler rejected; result will be null:", err);
|
|
3201
3236
|
if (!cancelled) setHandlerResult(null);
|
|
3202
3237
|
});
|
|
3203
3238
|
else setHandlerResult(maybePromise);
|
|
3204
3239
|
return () => {
|
|
3205
3240
|
cancelled = true;
|
|
3206
3241
|
};
|
|
3207
|
-
}, [
|
|
3208
|
-
pendingEvent,
|
|
3209
|
-
config.enabled,
|
|
3210
|
-
config.handler,
|
|
3211
|
-
resolve
|
|
3212
|
-
]);
|
|
3242
|
+
}, [pendingEvent]);
|
|
3213
3243
|
const element = (0, react.useMemo)(() => {
|
|
3214
3244
|
if (!pendingEvent) return null;
|
|
3215
|
-
if (
|
|
3216
|
-
return
|
|
3245
|
+
if (!isEnabled(pendingEvent)) return null;
|
|
3246
|
+
return renderRef.current({
|
|
3217
3247
|
event: pendingEvent,
|
|
3218
3248
|
result: handlerResult,
|
|
3219
3249
|
resolve
|
|
@@ -3221,19 +3251,22 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3221
3251
|
}, [
|
|
3222
3252
|
pendingEvent,
|
|
3223
3253
|
handlerResult,
|
|
3224
|
-
config.enabled,
|
|
3225
|
-
config.render,
|
|
3226
3254
|
resolve
|
|
3227
3255
|
]);
|
|
3228
3256
|
(0, react.useEffect)(() => {
|
|
3229
3257
|
if (config.renderInChat === false) return;
|
|
3230
3258
|
copilotkit.setInterruptElement(element);
|
|
3231
|
-
return () => copilotkit.setInterruptElement(null);
|
|
3232
3259
|
}, [
|
|
3233
3260
|
element,
|
|
3234
3261
|
config.renderInChat,
|
|
3235
3262
|
copilotkit
|
|
3236
3263
|
]);
|
|
3264
|
+
(0, react.useEffect)(() => {
|
|
3265
|
+
if (config.renderInChat === false) return;
|
|
3266
|
+
return () => {
|
|
3267
|
+
copilotkit.setInterruptElement(null);
|
|
3268
|
+
};
|
|
3269
|
+
}, []);
|
|
3237
3270
|
if (config.renderInChat === false) return element;
|
|
3238
3271
|
}
|
|
3239
3272
|
|
|
@@ -3573,6 +3606,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3573
3606
|
const details = bannerError.details;
|
|
3574
3607
|
const link = extractUrl(bannerError.message);
|
|
3575
3608
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3609
|
+
"data-testid": "copilot-error-banner",
|
|
3576
3610
|
style: {
|
|
3577
3611
|
position: "fixed",
|
|
3578
3612
|
bottom: "20px",
|
|
@@ -3772,9 +3806,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3772
3806
|
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
3773
3807
|
}, []);
|
|
3774
3808
|
const addToast = (0, react.useCallback)((toast) => {
|
|
3775
|
-
var _toast$id;
|
|
3776
3809
|
if (!enabled) return;
|
|
3777
|
-
const id =
|
|
3810
|
+
const id = toast.id ?? Math.random().toString(36).slice(2, 9);
|
|
3778
3811
|
setToasts((currentToasts) => {
|
|
3779
3812
|
if (currentToasts.find((toast) => toast.id === id)) return currentToasts;
|
|
3780
3813
|
return [...currentToasts, {
|
|
@@ -3901,8 +3934,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3901
3934
|
]);
|
|
3902
3935
|
const createStructuredError = (gqlError) => {
|
|
3903
3936
|
const extensions = gqlError.extensions;
|
|
3904
|
-
const originalError = extensions
|
|
3905
|
-
if (originalError
|
|
3937
|
+
const originalError = extensions?.originalError;
|
|
3938
|
+
if (originalError?.stack) {
|
|
3906
3939
|
if (originalError.stack.includes("CopilotApiDiscoveryError")) return new _copilotkit_shared.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
3907
3940
|
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) return new _copilotkit_shared.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
3908
3941
|
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) return new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
@@ -3910,8 +3943,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3910
3943
|
availableAgents: []
|
|
3911
3944
|
});
|
|
3912
3945
|
}
|
|
3913
|
-
const message =
|
|
3914
|
-
const code = extensions
|
|
3946
|
+
const message = originalError?.message || gqlError.message;
|
|
3947
|
+
const code = extensions?.code;
|
|
3915
3948
|
if (code) return new _copilotkit_shared.CopilotKitError({
|
|
3916
3949
|
message,
|
|
3917
3950
|
code
|
|
@@ -3919,12 +3952,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3919
3952
|
return null;
|
|
3920
3953
|
};
|
|
3921
3954
|
(0, react.useCallback)((error) => {
|
|
3922
|
-
|
|
3923
|
-
if ((_error$graphQLErrors = error.graphQLErrors) === null || _error$graphQLErrors === void 0 ? void 0 : _error$graphQLErrors.length) {
|
|
3955
|
+
if (error.graphQLErrors?.length) {
|
|
3924
3956
|
const graphQLErrors = error.graphQLErrors;
|
|
3925
3957
|
const routeError = (gqlError) => {
|
|
3926
|
-
const
|
|
3927
|
-
const suppression = getErrorSuppression(
|
|
3958
|
+
const visibility = gqlError.extensions?.visibility;
|
|
3959
|
+
const suppression = getErrorSuppression(visibility, shouldShowDevConsole(showDevConsole));
|
|
3928
3960
|
if (suppression) {
|
|
3929
3961
|
console.error(suppression, gqlError.message);
|
|
3930
3962
|
return;
|
|
@@ -3945,7 +3977,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3945
3977
|
graphQLErrors.forEach(routeError);
|
|
3946
3978
|
} else {
|
|
3947
3979
|
const fallbackError = new _copilotkit_shared.CopilotKitError({
|
|
3948
|
-
message:
|
|
3980
|
+
message: error?.message || String(error),
|
|
3949
3981
|
code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
|
|
3950
3982
|
});
|
|
3951
3983
|
setBannerError(fallbackError);
|
|
@@ -4132,6 +4164,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4132
4164
|
}
|
|
4133
4165
|
` }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4134
4166
|
className: "usage-banner",
|
|
4167
|
+
"data-testid": "copilot-error-banner",
|
|
4135
4168
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4136
4169
|
className: "banner-content",
|
|
4137
4170
|
children: [
|
|
@@ -4139,7 +4172,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4139
4172
|
className: "banner-message",
|
|
4140
4173
|
children: message
|
|
4141
4174
|
}),
|
|
4142
|
-
|
|
4175
|
+
actions?.primary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4143
4176
|
className: "btn-primary",
|
|
4144
4177
|
onClick: actions.primary.onClick,
|
|
4145
4178
|
children: actions.primary.label
|
|
@@ -4199,7 +4232,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4199
4232
|
headers: { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey }
|
|
4200
4233
|
}).then((response) => response.json());
|
|
4201
4234
|
this.lastResponse = response;
|
|
4202
|
-
onUpdate
|
|
4235
|
+
onUpdate?.(response);
|
|
4203
4236
|
return response;
|
|
4204
4237
|
} catch (error) {
|
|
4205
4238
|
return null;
|
|
@@ -4270,10 +4303,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4270
4303
|
maxWidth: "600px"
|
|
4271
4304
|
},
|
|
4272
4305
|
children: [errors.map((error, idx) => {
|
|
4273
|
-
|
|
4274
|
-
const
|
|
4275
|
-
const message = (_originalError$messag = originalError === null || originalError === void 0 ? void 0 : originalError.message) !== null && _originalError$messag !== void 0 ? _originalError$messag : error.message;
|
|
4276
|
-
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;
|
|
4277
4308
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4278
4309
|
style: {
|
|
4279
4310
|
marginTop: idx === 0 ? 0 : 10,
|
|
@@ -4316,8 +4347,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4316
4347
|
addToast({
|
|
4317
4348
|
type: "error",
|
|
4318
4349
|
id: errors.map((err) => {
|
|
4319
|
-
|
|
4320
|
-
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;
|
|
4321
4351
|
const stack = err.stack || "";
|
|
4322
4352
|
return btoa(message + stack).slice(0, 32);
|
|
4323
4353
|
}).join("|"),
|
|
@@ -4355,8 +4385,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4355
4385
|
componentDidMount() {
|
|
4356
4386
|
if (this.props.publicApiKey) statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
4357
4387
|
this.setState((prevState) => {
|
|
4358
|
-
|
|
4359
|
-
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 };
|
|
4360
4389
|
return null;
|
|
4361
4390
|
});
|
|
4362
4391
|
});
|
|
@@ -4369,14 +4398,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4369
4398
|
}
|
|
4370
4399
|
render() {
|
|
4371
4400
|
if (this.state.hasError) {
|
|
4372
|
-
if (this.state.error instanceof _copilotkit_shared.CopilotKitError) {
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
actions: getErrorActions(this.state.error)
|
|
4378
|
-
})] });
|
|
4379
|
-
}
|
|
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
|
+
})] });
|
|
4380
4406
|
throw this.state.error;
|
|
4381
4407
|
}
|
|
4382
4408
|
return this.props.children;
|
|
@@ -4424,7 +4450,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4424
4450
|
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
4425
4451
|
const [internalThreadId, setInternalThreadId] = (0, react.useState)(() => (0, _copilotkit_shared.randomUUID)());
|
|
4426
4452
|
const [internalIsExplicit, setInternalIsExplicit] = (0, react.useState)(false);
|
|
4427
|
-
const threadId = explicitThreadId
|
|
4453
|
+
const threadId = explicitThreadId ?? internalThreadId;
|
|
4428
4454
|
const isThreadIdExplicit = explicitThreadId != null || internalIsExplicit;
|
|
4429
4455
|
const setThreadId = (0, react.useCallback)((value) => {
|
|
4430
4456
|
setInternalThreadId(value);
|
|
@@ -4505,13 +4531,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4505
4531
|
updateRunId: shouldUpdateRunId ? runId : void 0
|
|
4506
4532
|
};
|
|
4507
4533
|
}
|
|
4508
|
-
const normalizedRunId = runId
|
|
4509
|
-
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(([, claim]) =>
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
});
|
|
4513
|
-
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[1];
|
|
4514
|
-
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];
|
|
4515
4538
|
if (renderClaimedByOtherMessage) {
|
|
4516
4539
|
if (messageIndex !== void 0 && renderClaimedByOtherMessage.messageIndex !== void 0 && messageIndex > renderClaimedByOtherMessage.messageIndex) return {
|
|
4517
4540
|
canRender: true,
|
|
@@ -4580,17 +4603,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4580
4603
|
* 5) last cached snapshot for stateRenderId
|
|
4581
4604
|
*/
|
|
4582
4605
|
function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
|
|
4583
|
-
|
|
4584
|
-
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;
|
|
4585
4607
|
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
4586
4608
|
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
4587
|
-
const messageRole = messageIndex >= 0 && agentMessages ?
|
|
4609
|
+
const messageRole = messageIndex >= 0 && agentMessages ? agentMessages[messageIndex]?.role : void 0;
|
|
4588
4610
|
let previousUserMessageId;
|
|
4589
|
-
if (messageIndex > 0 && agentMessages)
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
var _agentMessages$i2;
|
|
4593
|
-
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;
|
|
4594
4614
|
break;
|
|
4595
4615
|
}
|
|
4596
4616
|
}
|
|
@@ -4602,11 +4622,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4602
4622
|
const messageCacheEntry = caches.byMessageId[messageId];
|
|
4603
4623
|
const cachedMessageSnapshot = readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
4604
4624
|
const cacheKey = stateRenderId !== void 0 ? `${stateRenderId}::${effectiveRunId}` : void 0;
|
|
4605
|
-
let cachedSnapshot = cachedMessageSnapshot
|
|
4625
|
+
let cachedSnapshot = cachedMessageSnapshot ?? caches.byMessageId[messageId];
|
|
4606
4626
|
if (cachedSnapshot === void 0 && cacheKey && caches.byStateRenderAndRun[cacheKey] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
4607
4627
|
if (cachedSnapshot === void 0 && stateRenderId && previousUserMessageId && caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`];
|
|
4608
4628
|
if (cachedSnapshot === void 0 && !skipLatestCache && stateRenderId && messageRole !== "assistant" && (stateSnapshotProp !== void 0 || agentState && Object.keys(agentState).length > 0)) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::latest`];
|
|
4609
|
-
const snapshotForClaim =
|
|
4629
|
+
const snapshotForClaim = existingClaim?.locked ? existingClaim.stateSnapshot ?? cachedSnapshot : hasSnapshotKeys ? snapshot : existingClaim?.stateSnapshot ?? cachedSnapshot;
|
|
4610
4630
|
return {
|
|
4611
4631
|
snapshot,
|
|
4612
4632
|
hasSnapshotKeys,
|
|
@@ -4624,37 +4644,36 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4624
4644
|
return claimsRef.current;
|
|
4625
4645
|
}
|
|
4626
4646
|
function getSnapshotCaches(claimsRef) {
|
|
4627
|
-
var _store$LAST_SNAPSHOTS, _store$LAST_SNAPSHOTS2;
|
|
4628
4647
|
const store = getClaimsStore(claimsRef);
|
|
4629
4648
|
return {
|
|
4630
|
-
byStateRenderAndRun:
|
|
4631
|
-
byMessageId:
|
|
4649
|
+
byStateRenderAndRun: store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] ?? {},
|
|
4650
|
+
byMessageId: store[LAST_SNAPSHOTS_BY_MESSAGE] ?? {}
|
|
4632
4651
|
};
|
|
4633
4652
|
}
|
|
4634
4653
|
function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex, stateSnapshot, agentState, agentMessages, claimsRef }) {
|
|
4635
|
-
var _store$LAST_SNAPSHOTS3, _claimsRef$current$me;
|
|
4636
4654
|
const store = getClaimsStore(claimsRef);
|
|
4637
4655
|
const runId = message.runId;
|
|
4638
|
-
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;
|
|
4639
4659
|
const effectiveRunId = getEffectiveRunId({
|
|
4640
|
-
existingClaimRunId
|
|
4660
|
+
existingClaimRunId,
|
|
4641
4661
|
cachedMessageRunId,
|
|
4642
4662
|
runId
|
|
4643
4663
|
});
|
|
4644
4664
|
(0, react.useEffect)(() => {
|
|
4645
4665
|
return () => {
|
|
4646
4666
|
const existingClaim = claimsRef.current[message.id];
|
|
4647
|
-
if (
|
|
4648
|
-
var _existingClaim$runId, _existingClaim$runId2;
|
|
4667
|
+
if (existingClaim?.stateSnapshot && Object.keys(existingClaim.stateSnapshot).length > 0) {
|
|
4649
4668
|
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
4650
|
-
const cacheKey = `${existingClaim.stateRenderId}::${
|
|
4669
|
+
const cacheKey = `${existingClaim.stateRenderId}::${existingClaim.runId ?? "pending"}`;
|
|
4651
4670
|
snapshotCache[cacheKey] = existingClaim.stateSnapshot;
|
|
4652
4671
|
snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
|
|
4653
4672
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
4654
4673
|
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
4655
4674
|
messageCache[message.id] = {
|
|
4656
4675
|
snapshot: existingClaim.stateSnapshot,
|
|
4657
|
-
runId:
|
|
4676
|
+
runId: existingClaim.runId ?? effectiveRunId
|
|
4658
4677
|
};
|
|
4659
4678
|
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
4660
4679
|
}
|
|
@@ -4698,7 +4717,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4698
4717
|
if (resolution.lockOthers) Object.entries(claimsRef.current).forEach(([id, claim]) => {
|
|
4699
4718
|
if (id !== message.id && claim.stateRenderId === stateRenderId) claim.locked = true;
|
|
4700
4719
|
});
|
|
4701
|
-
if (existingClaim && !existingClaim.locked &&
|
|
4720
|
+
if (existingClaim && !existingClaim.locked && agentMessages?.length) {
|
|
4702
4721
|
const indexInAgentMessages = agentMessages.findIndex((msg) => msg.id === message.id);
|
|
4703
4722
|
if (indexInAgentMessages >= 0 && indexInAgentMessages < agentMessages.length - 1) existingClaim.locked = true;
|
|
4704
4723
|
}
|
|
@@ -4742,7 +4761,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4742
4761
|
//#endregion
|
|
4743
4762
|
//#region src/hooks/use-coagent-state-render-bridge.tsx
|
|
4744
4763
|
function useCoagentStateRenderBridge(agentId, props) {
|
|
4745
|
-
var _props$runId;
|
|
4746
4764
|
const { stateSnapshot, message } = props;
|
|
4747
4765
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
4748
4766
|
const { agent } = useAgent({ agentId });
|
|
@@ -4778,46 +4796,42 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4778
4796
|
agentId
|
|
4779
4797
|
]);
|
|
4780
4798
|
const stateRenderEntry = (0, react.useMemo)(() => getStateRender(message.id), [getStateRender, message.id]);
|
|
4781
|
-
const stateRenderId = stateRenderEntry
|
|
4782
|
-
const stateRender = stateRenderEntry
|
|
4799
|
+
const stateRenderId = stateRenderEntry?.[0];
|
|
4800
|
+
const stateRender = stateRenderEntry?.[1];
|
|
4783
4801
|
const { canRender } = useStateRenderRegistry({
|
|
4784
4802
|
agentId,
|
|
4785
4803
|
stateRenderId,
|
|
4786
4804
|
message: {
|
|
4787
4805
|
...message,
|
|
4788
|
-
runId:
|
|
4806
|
+
runId: props.runId ?? message.runId
|
|
4789
4807
|
},
|
|
4790
4808
|
messageIndex: props.messageIndex,
|
|
4791
4809
|
stateSnapshot,
|
|
4792
|
-
agentState: agent
|
|
4793
|
-
agentMessages: agent
|
|
4810
|
+
agentState: agent?.state,
|
|
4811
|
+
agentMessages: agent?.messages,
|
|
4794
4812
|
claimsRef
|
|
4795
4813
|
});
|
|
4796
4814
|
return (0, react.useMemo)(() => {
|
|
4797
4815
|
if (!stateRender || !stateRenderId) return null;
|
|
4798
4816
|
if (!canRender) return null;
|
|
4799
|
-
if (stateRender.handler) {
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
nodeName: nodeName !== null && nodeName !== void 0 ? nodeName : ""
|
|
4804
|
-
});
|
|
4805
|
-
}
|
|
4817
|
+
if (stateRender.handler) stateRender.handler({
|
|
4818
|
+
state: stateSnapshot ? (0, _copilotkit_shared.parseJson)(stateSnapshot, stateSnapshot) : agent?.state ?? {},
|
|
4819
|
+
nodeName: nodeName ?? ""
|
|
4820
|
+
});
|
|
4806
4821
|
if (stateRender.render) {
|
|
4807
|
-
|
|
4808
|
-
const status = (agent === null || agent === void 0 ? void 0 : agent.isRunning) ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
4822
|
+
const status = agent?.isRunning ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
4809
4823
|
if (typeof stateRender.render === "string") return stateRender.render;
|
|
4810
4824
|
return stateRender.render({
|
|
4811
4825
|
status,
|
|
4812
|
-
state:
|
|
4813
|
-
nodeName: nodeName
|
|
4826
|
+
state: claimsRef.current[message.id].stateSnapshot ?? {},
|
|
4827
|
+
nodeName: nodeName ?? ""
|
|
4814
4828
|
});
|
|
4815
4829
|
}
|
|
4816
4830
|
}, [
|
|
4817
4831
|
stateRender,
|
|
4818
4832
|
stateRenderId,
|
|
4819
|
-
agent
|
|
4820
|
-
agent
|
|
4833
|
+
agent?.state,
|
|
4834
|
+
agent?.isRunning,
|
|
4821
4835
|
nodeName,
|
|
4822
4836
|
message.id,
|
|
4823
4837
|
stateSnapshot,
|
|
@@ -4838,7 +4852,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4838
4852
|
},
|
|
4839
4853
|
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
4840
4854
|
predictStateToolsRef.current.forEach((t) => {
|
|
4841
|
-
if (
|
|
4855
|
+
if (t?.tool !== toolCallName) return;
|
|
4842
4856
|
const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
|
|
4843
4857
|
agent.setState({ [t.state_key]: emittedState[t.state_key] });
|
|
4844
4858
|
});
|
|
@@ -4854,16 +4868,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4854
4868
|
}, [agent, getSubscriber]);
|
|
4855
4869
|
};
|
|
4856
4870
|
function CopilotListenersAgentSubscription() {
|
|
4857
|
-
const
|
|
4858
|
-
const { agent } = useAgent({ agentId:
|
|
4871
|
+
const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
|
|
4872
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
4859
4873
|
usePredictStateSubscription(agent);
|
|
4860
4874
|
return null;
|
|
4861
4875
|
}
|
|
4862
4876
|
function CopilotListeners() {
|
|
4863
|
-
var _copilotkit$agents;
|
|
4864
4877
|
const { copilotkit } = useCopilotKit();
|
|
4865
4878
|
const { setBannerError } = useToast();
|
|
4866
|
-
const hasAgents = Object.keys(
|
|
4879
|
+
const hasAgents = Object.keys(copilotkit.agents ?? {}).length > 0;
|
|
4867
4880
|
const hasRuntime = copilotkit.runtimeUrl !== void 0;
|
|
4868
4881
|
(0, react.useEffect)(() => {
|
|
4869
4882
|
const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
|
|
@@ -4885,7 +4898,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4885
4898
|
return () => {
|
|
4886
4899
|
subscription.unsubscribe();
|
|
4887
4900
|
};
|
|
4888
|
-
}, [copilotkit
|
|
4901
|
+
}, [copilotkit?.subscribe]);
|
|
4889
4902
|
return hasAgents || hasRuntime ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListenersAgentSubscription, {}) : null;
|
|
4890
4903
|
}
|
|
4891
4904
|
|
|
@@ -4907,7 +4920,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4907
4920
|
* ```
|
|
4908
4921
|
*/
|
|
4909
4922
|
function CopilotKit({ children, ...props }) {
|
|
4910
|
-
var _props$useSingleEndpo;
|
|
4911
4923
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
4912
4924
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
4913
4925
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
@@ -4923,7 +4935,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4923
4935
|
...props,
|
|
4924
4936
|
showDevConsole: showInspector,
|
|
4925
4937
|
renderCustomMessages: renderArr,
|
|
4926
|
-
useSingleEndpoint:
|
|
4938
|
+
useSingleEndpoint: props.useSingleEndpoint ?? true,
|
|
4927
4939
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
|
|
4928
4940
|
...props,
|
|
4929
4941
|
children
|
|
@@ -4952,7 +4964,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4952
4964
|
source: "agent",
|
|
4953
4965
|
request: {
|
|
4954
4966
|
operation: event.code || "unknown",
|
|
4955
|
-
url: copilotApiConfig
|
|
4967
|
+
url: copilotApiConfig?.chatApiEndpoint,
|
|
4956
4968
|
startTime: Date.now()
|
|
4957
4969
|
},
|
|
4958
4970
|
technical: {
|
|
@@ -4981,7 +4993,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4981
4993
|
return null;
|
|
4982
4994
|
}
|
|
4983
4995
|
function CopilotKitInternal(cpkProps) {
|
|
4984
|
-
var _props$agent2;
|
|
4985
4996
|
const { children, ...props } = cpkProps;
|
|
4986
4997
|
/**
|
|
4987
4998
|
* This will throw an error if the props are invalid.
|
|
@@ -5045,14 +5056,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5045
5056
|
}, [removeDocument]);
|
|
5046
5057
|
const copilotApiConfig = (0, react.useMemo)(() => {
|
|
5047
5058
|
let cloud = void 0;
|
|
5048
|
-
if (publicApiKey) {
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
invalidTopics: ((_props$guardrails_c2 = props.guardrails_c) === null || _props$guardrails_c2 === void 0 ? void 0 : _props$guardrails_c2.invalidTopics) || []
|
|
5054
|
-
} } } };
|
|
5055
|
-
}
|
|
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
|
+
} } } };
|
|
5056
5064
|
return {
|
|
5057
5065
|
publicApiKey,
|
|
5058
5066
|
...cloud ? { cloud } : {},
|
|
@@ -5208,14 +5216,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5208
5216
|
}, []);
|
|
5209
5217
|
const memoizedChildren = (0, react.useMemo)(() => children, [children]);
|
|
5210
5218
|
const [bannerError, setBannerError] = (0, react.useState)(null);
|
|
5211
|
-
const agentLock = (0, react.useMemo)(() =>
|
|
5212
|
-
|
|
5213
|
-
return (_props$agent = props.agent) !== null && _props$agent !== void 0 ? _props$agent : null;
|
|
5214
|
-
}, [props.agent]);
|
|
5215
|
-
const forwardedParameters = (0, react.useMemo)(() => {
|
|
5216
|
-
var _props$forwardedParam;
|
|
5217
|
-
return (_props$forwardedParam = props.forwardedParameters) !== null && _props$forwardedParam !== void 0 ? _props$forwardedParam : {};
|
|
5218
|
-
}, [props.forwardedParameters]);
|
|
5219
|
+
const agentLock = (0, react.useMemo)(() => props.agent ?? null, [props.agent]);
|
|
5220
|
+
const forwardedParameters = (0, react.useMemo)(() => props.forwardedParameters ?? {}, [props.forwardedParameters]);
|
|
5219
5221
|
const updateExtensions = (0, react.useCallback)((newExtensions) => {
|
|
5220
5222
|
setExtensions((prev) => {
|
|
5221
5223
|
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
@@ -5358,7 +5360,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5358
5360
|
removeInternalErrorHandler
|
|
5359
5361
|
]);
|
|
5360
5362
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatConfigurationProvider, {
|
|
5361
|
-
agentId:
|
|
5363
|
+
agentId: props.agent ?? "default",
|
|
5362
5364
|
threadId,
|
|
5363
5365
|
hasExplicitThreadId: isThreadIdExplicit,
|
|
5364
5366
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotContext.Provider, {
|
|
@@ -5387,8 +5389,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5387
5389
|
await new Promise((resolve, reject) => {
|
|
5388
5390
|
(0, react_dom.flushSync)(async () => {
|
|
5389
5391
|
try {
|
|
5390
|
-
|
|
5391
|
-
result = await ((_action$handler = action.handler) === null || _action$handler === void 0 ? void 0 : _action$handler.call(action, args));
|
|
5392
|
+
result = await action.handler?.(args);
|
|
5392
5393
|
resolve();
|
|
5393
5394
|
} catch (error) {
|
|
5394
5395
|
reject(error);
|
|
@@ -5415,11 +5416,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5415
5416
|
function useLazyToolRenderer() {
|
|
5416
5417
|
const renderToolCall = useRenderToolCall$1();
|
|
5417
5418
|
return (0, react.useCallback)((message, messages) => {
|
|
5418
|
-
|
|
5419
|
-
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;
|
|
5420
5420
|
const toolCall = message.toolCalls[0];
|
|
5421
5421
|
if (!toolCall) return null;
|
|
5422
|
-
const toolMessage = messages
|
|
5422
|
+
const toolMessage = messages?.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
|
|
5423
5423
|
return () => renderToolCall({
|
|
5424
5424
|
toolCall,
|
|
5425
5425
|
toolMessage
|
|
@@ -5430,12 +5430,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5430
5430
|
//#endregion
|
|
5431
5431
|
//#region src/hooks/use-copilot-chat_internal.ts
|
|
5432
5432
|
function useCopilotChatInternal({ suggestions, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages } = {}) {
|
|
5433
|
-
var _existingConfig$agent, _existingConfig$threa, _agent$messages5;
|
|
5434
5433
|
const { copilotkit } = useCopilotKit();
|
|
5435
5434
|
const { threadId, agentSession } = useCopilotContext();
|
|
5436
5435
|
const existingConfig = useCopilotChatConfiguration();
|
|
5437
5436
|
const [agentAvailable, setAgentAvailable] = (0, react.useState)(false);
|
|
5438
|
-
const resolvedAgentId =
|
|
5437
|
+
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
5439
5438
|
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
5440
5439
|
const lastConnectedAgentRef = (0, react.useRef)(null);
|
|
5441
5440
|
(0, react.useEffect)(() => {
|
|
@@ -5460,18 +5459,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5460
5459
|
lastConnectedAgentRef.current = null;
|
|
5461
5460
|
detached = true;
|
|
5462
5461
|
connectAbortController.abort();
|
|
5463
|
-
agent
|
|
5462
|
+
agent?.detachActiveRun();
|
|
5464
5463
|
};
|
|
5465
5464
|
}, [
|
|
5466
|
-
existingConfig
|
|
5465
|
+
existingConfig?.threadId,
|
|
5467
5466
|
agent,
|
|
5468
5467
|
copilotkit,
|
|
5469
5468
|
copilotkit.runtimeConnectionStatus,
|
|
5470
5469
|
resolvedAgentId
|
|
5471
5470
|
]);
|
|
5472
5471
|
(0, react.useEffect)(() => {
|
|
5473
|
-
onInProgress
|
|
5474
|
-
}, [agent
|
|
5472
|
+
onInProgress?.(Boolean(agent?.isRunning));
|
|
5473
|
+
}, [agent?.isRunning, onInProgress]);
|
|
5475
5474
|
const [interrupt, setInterrupt] = (0, react.useState)(null);
|
|
5476
5475
|
(0, react.useEffect)(() => {
|
|
5477
5476
|
setInterrupt(copilotkit.interruptElement);
|
|
@@ -5481,22 +5480,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5481
5480
|
return () => subscription.unsubscribe();
|
|
5482
5481
|
}, [copilotkit]);
|
|
5483
5482
|
const reset = () => {
|
|
5484
|
-
agent
|
|
5485
|
-
agent
|
|
5483
|
+
agent?.setMessages([]);
|
|
5484
|
+
agent?.setState(null);
|
|
5486
5485
|
};
|
|
5487
5486
|
const latestDelete = useUpdatedRef((0, react.useCallback)((messageId) => {
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
}, [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]));
|
|
5492
5490
|
const latestDeleteFunc = (0, react.useCallback)((messageId) => {
|
|
5493
5491
|
return latestDelete.current(messageId);
|
|
5494
5492
|
}, [latestDelete]);
|
|
5495
5493
|
const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });
|
|
5496
5494
|
const reload = useAsyncCallback(async (reloadMessageId) => {
|
|
5497
|
-
var _agent$messages2;
|
|
5498
5495
|
if (!agent) return;
|
|
5499
|
-
const messages =
|
|
5496
|
+
const messages = agent?.messages ?? [];
|
|
5500
5497
|
if (agent.isRunning || messages.length === 0) return;
|
|
5501
5498
|
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
5502
5499
|
if (reloadMessageIndex === -1) {
|
|
@@ -5517,23 +5514,22 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5517
5514
|
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
5518
5515
|
}
|
|
5519
5516
|
} else if (messages.length > 2 && reloadMessageIndex === 0) historyCutoff = [messages[0], messages[1]];
|
|
5520
|
-
agent
|
|
5517
|
+
agent?.setMessages(historyCutoff);
|
|
5521
5518
|
if (agent) try {
|
|
5522
5519
|
await copilotkit.runAgent({ agent });
|
|
5523
5520
|
} catch (error) {
|
|
5524
5521
|
console.error("CopilotChat: runAgent failed during reload", error);
|
|
5525
5522
|
}
|
|
5526
5523
|
}, [
|
|
5527
|
-
agent
|
|
5528
|
-
agent
|
|
5529
|
-
agent
|
|
5530
|
-
copilotkit
|
|
5524
|
+
agent?.messages.length,
|
|
5525
|
+
agent?.isRunning,
|
|
5526
|
+
agent?.setMessages,
|
|
5527
|
+
copilotkit?.runAgent
|
|
5531
5528
|
]);
|
|
5532
5529
|
const latestSendMessageFunc = useAsyncCallback(async (message, options) => {
|
|
5533
|
-
var _options$followUp;
|
|
5534
5530
|
if (!agent) return;
|
|
5535
|
-
const followUp =
|
|
5536
|
-
if (options
|
|
5531
|
+
const followUp = options?.followUp ?? true;
|
|
5532
|
+
if (options?.clearSuggestions) copilotkit.clearSuggestions(resolvedAgentId);
|
|
5537
5533
|
if (onSubmitMessage) {
|
|
5538
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 : "";
|
|
5539
5535
|
try {
|
|
@@ -5542,7 +5538,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5542
5538
|
console.error("Error in onSubmitMessage:", error);
|
|
5543
5539
|
}
|
|
5544
5540
|
}
|
|
5545
|
-
agent
|
|
5541
|
+
agent?.addMessage(message);
|
|
5546
5542
|
if (followUp) try {
|
|
5547
5543
|
await copilotkit.runAgent({ agent });
|
|
5548
5544
|
} catch (error) {
|
|
@@ -5558,20 +5554,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5558
5554
|
return latestSendMessageFunc((0, _copilotkit_runtime_client_gql.gqlToAGUI)([message])[0], options);
|
|
5559
5555
|
}, [latestSendMessageFunc]);
|
|
5560
5556
|
const latestSetMessagesFunc = (0, react.useCallback)((messages) => {
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
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));
|
|
5565
|
-
}
|
|
5566
|
-
return agent === null || agent === void 0 || (_agent$setMessages2 = agent.setMessages) === null || _agent$setMessages2 === void 0 ? void 0 : _agent$setMessages2.call(agent, messages);
|
|
5567
|
-
}, [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]);
|
|
5568
5560
|
const latestReload = useUpdatedRef(reload);
|
|
5569
5561
|
const latestReloadFunc = useAsyncCallback(async (messageId) => {
|
|
5570
|
-
|
|
5571
|
-
onReloadMessages === null || onReloadMessages === void 0 || onReloadMessages({
|
|
5562
|
+
onReloadMessages?.({
|
|
5572
5563
|
messageId,
|
|
5573
|
-
currentAgentName: agent
|
|
5574
|
-
messages:
|
|
5564
|
+
currentAgentName: agent?.agentId,
|
|
5565
|
+
messages: agent?.messages ?? []
|
|
5575
5566
|
});
|
|
5576
5567
|
return await latestReload.current(messageId);
|
|
5577
5568
|
}, [
|
|
@@ -5580,12 +5571,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5580
5571
|
onReloadMessages
|
|
5581
5572
|
]);
|
|
5582
5573
|
const latestStopFunc = (0, react.useCallback)(() => {
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
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 ?? []
|
|
5587
5577
|
});
|
|
5588
|
-
return agent
|
|
5578
|
+
return agent?.abortRun?.();
|
|
5589
5579
|
}, [onStopGeneration, agent]);
|
|
5590
5580
|
const latestReset = useUpdatedRef(reset);
|
|
5591
5581
|
const latestResetFunc = (0, react.useCallback)(() => {
|
|
@@ -5597,11 +5587,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5597
5587
|
copilotkit,
|
|
5598
5588
|
agent,
|
|
5599
5589
|
agentId: resolvedAgentId,
|
|
5600
|
-
threadId:
|
|
5590
|
+
threadId: existingConfig?.threadId ?? threadId
|
|
5601
5591
|
});
|
|
5602
|
-
const allMessages =
|
|
5592
|
+
const allMessages = agent?.messages ?? [];
|
|
5603
5593
|
const resolvedMessages = (0, react.useMemo)(() => {
|
|
5604
|
-
var _copilotkit$getAgent, _ref;
|
|
5605
5594
|
let processedMessages = allMessages.map((message) => {
|
|
5606
5595
|
if (message.role !== "assistant") return message;
|
|
5607
5596
|
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
@@ -5618,11 +5607,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5618
5607
|
position: "before"
|
|
5619
5608
|
});
|
|
5620
5609
|
try {
|
|
5621
|
-
|
|
5622
|
-
return (_renderCustomMessage = renderCustomMessage === null || renderCustomMessage === void 0 ? void 0 : renderCustomMessage({
|
|
5610
|
+
return renderCustomMessage?.({
|
|
5623
5611
|
message,
|
|
5624
5612
|
position: "before"
|
|
5625
|
-
})
|
|
5613
|
+
}) ?? null;
|
|
5626
5614
|
} catch (error) {
|
|
5627
5615
|
console.warn("[CopilotKit] renderCustomMessages failed, falling back to legacy renderer", error);
|
|
5628
5616
|
return null;
|
|
@@ -5636,10 +5624,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5636
5624
|
return message;
|
|
5637
5625
|
});
|
|
5638
5626
|
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
5639
|
-
const canUseCustomRenderer = Boolean(renderCustomMessage &&
|
|
5627
|
+
const canUseCustomRenderer = Boolean(renderCustomMessage && copilotkit?.getAgent?.(resolvedAgentId));
|
|
5640
5628
|
const placeholderRenderer = legacyCustomMessageRenderer ? legacyCustomMessageRenderer : canUseCustomRenderer ? renderCustomMessage : null;
|
|
5641
|
-
const shouldRenderPlaceholder = Boolean(agent
|
|
5642
|
-
const effectiveThreadId =
|
|
5629
|
+
const shouldRenderPlaceholder = Boolean(agent?.isRunning) || Boolean(agent?.state && Object.keys(agent.state).length);
|
|
5630
|
+
const effectiveThreadId = threadId ?? agent?.threadId ?? "default";
|
|
5643
5631
|
let latestUserIndex = -1;
|
|
5644
5632
|
for (let i = processedMessages.length - 1; i >= 0; i -= 1) if (processedMessages[i].role === "user") {
|
|
5645
5633
|
latestUserIndex = i;
|
|
@@ -5667,15 +5655,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5667
5655
|
}
|
|
5668
5656
|
return processedMessages;
|
|
5669
5657
|
}, [
|
|
5670
|
-
agent
|
|
5658
|
+
agent?.messages,
|
|
5671
5659
|
lazyToolRendered,
|
|
5672
5660
|
allMessages,
|
|
5673
5661
|
renderCustomMessage,
|
|
5674
5662
|
legacyCustomMessageRenderer,
|
|
5675
5663
|
resolvedAgentId,
|
|
5676
5664
|
copilotkit,
|
|
5677
|
-
agent
|
|
5678
|
-
agent
|
|
5665
|
+
agent?.isRunning,
|
|
5666
|
+
agent?.state
|
|
5679
5667
|
]);
|
|
5680
5668
|
const renderedSuggestions = (0, react.useMemo)(() => {
|
|
5681
5669
|
if (Array.isArray(suggestions)) return {
|
|
@@ -5697,7 +5685,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5697
5685
|
reset: latestResetFunc,
|
|
5698
5686
|
deleteMessage: latestDeleteFunc,
|
|
5699
5687
|
isAvailable: agentAvailable,
|
|
5700
|
-
isLoading: Boolean(agent
|
|
5688
|
+
isLoading: Boolean(agent?.isRunning),
|
|
5701
5689
|
suggestions: renderedSuggestions.suggestions,
|
|
5702
5690
|
setSuggestions: (suggestions) => copilotkit.addSuggestionsConfig({ suggestions }),
|
|
5703
5691
|
generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),
|
|
@@ -5719,8 +5707,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5719
5707
|
return (0, react.useMemo)(() => {
|
|
5720
5708
|
if (!copilotkit || !agent) return null;
|
|
5721
5709
|
return ({ message, position }) => {
|
|
5722
|
-
|
|
5723
|
-
const effectiveThreadId = (_ref2 = threadId !== null && threadId !== void 0 ? threadId : agent.threadId) !== null && _ref2 !== void 0 ? _ref2 : "default";
|
|
5710
|
+
const effectiveThreadId = threadId ?? agent.threadId ?? "default";
|
|
5724
5711
|
const providedRunId = message.runId;
|
|
5725
5712
|
return (0, react.createElement)(CoAgentStateRenderBridge, {
|
|
5726
5713
|
message,
|
|
@@ -5990,7 +5977,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5990
5977
|
const renderRef = (0, react.useRef)(render);
|
|
5991
5978
|
(0, react.useEffect)(() => {
|
|
5992
5979
|
renderRef.current = render;
|
|
5993
|
-
}, [render, ...dependencies
|
|
5980
|
+
}, [render, ...dependencies ?? []]);
|
|
5994
5981
|
const normalizedRender = (0, react.useMemo)(() => {
|
|
5995
5982
|
if (typeof render === "undefined") return;
|
|
5996
5983
|
return ((args) => {
|
|
@@ -6002,21 +5989,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6002
5989
|
result: typeof args.result === "string" ? (0, _copilotkit_shared.parseJson)(args.result, args.result) : args.result
|
|
6003
5990
|
});
|
|
6004
5991
|
if (typeof rendered === "string") return react.default.createElement(react.default.Fragment, null, rendered);
|
|
6005
|
-
return rendered
|
|
5992
|
+
return rendered ?? null;
|
|
6006
5993
|
});
|
|
6007
5994
|
}, []);
|
|
6008
5995
|
const handlerRef = (0, react.useRef)(tool.handler);
|
|
6009
5996
|
(0, react.useEffect)(() => {
|
|
6010
5997
|
handlerRef.current = tool.handler;
|
|
6011
|
-
}, [tool.handler, ...dependencies
|
|
5998
|
+
}, [tool.handler, ...dependencies ?? []]);
|
|
6012
5999
|
useFrontendTool$1({
|
|
6013
6000
|
name,
|
|
6014
6001
|
description,
|
|
6015
6002
|
parameters: zodParameters,
|
|
6016
|
-
handler: tool.handler ? (args) =>
|
|
6017
|
-
var _handlerRef$current;
|
|
6018
|
-
return (_handlerRef$current = handlerRef.current) === null || _handlerRef$current === void 0 ? void 0 : _handlerRef$current.call(handlerRef, args);
|
|
6019
|
-
} : void 0,
|
|
6003
|
+
handler: tool.handler ? (args) => handlerRef.current?.(args) : void 0,
|
|
6020
6004
|
followUp,
|
|
6021
6005
|
render: normalizedRender,
|
|
6022
6006
|
available: available === void 0 ? void 0 : available !== "disabled"
|
|
@@ -6060,7 +6044,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6060
6044
|
hasAddedRef.current = false;
|
|
6061
6045
|
}
|
|
6062
6046
|
};
|
|
6063
|
-
}, [tool, ...dependencies
|
|
6047
|
+
}, [tool, ...dependencies ?? []]);
|
|
6064
6048
|
}
|
|
6065
6049
|
|
|
6066
6050
|
//#endregion
|
|
@@ -6103,18 +6087,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6103
6087
|
}
|
|
6104
6088
|
})());
|
|
6105
6089
|
if (typeof rendered === "string") return react.default.createElement(react.default.Fragment, null, rendered);
|
|
6106
|
-
return rendered
|
|
6090
|
+
return rendered ?? null;
|
|
6107
6091
|
};
|
|
6108
|
-
}, [render, ...dependencies
|
|
6092
|
+
}, [render, ...dependencies ?? []]);
|
|
6109
6093
|
useHumanInTheLoop$1({
|
|
6110
6094
|
name,
|
|
6111
6095
|
description,
|
|
6112
6096
|
followUp,
|
|
6113
6097
|
parameters: zodParameters,
|
|
6114
|
-
render: ((args) =>
|
|
6115
|
-
var _renderRef$current, _renderRef$current2;
|
|
6116
|
-
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;
|
|
6117
|
-
})
|
|
6098
|
+
render: ((args) => renderRef.current?.(args) ?? null)
|
|
6118
6099
|
});
|
|
6119
6100
|
}
|
|
6120
6101
|
|
|
@@ -6374,7 +6355,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6374
6355
|
const idRef = (0, react.useRef)((0, _copilotkit_shared.randomId)());
|
|
6375
6356
|
const { setBannerError, addToast } = useToast();
|
|
6376
6357
|
(0, react.useEffect)(() => {
|
|
6377
|
-
if (
|
|
6358
|
+
if (availableAgents?.length && !availableAgents.some((a) => a.name === action.name)) {
|
|
6378
6359
|
`${action.name}`;
|
|
6379
6360
|
setBannerError(new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
6380
6361
|
agentName: action.name,
|
|
@@ -6538,7 +6519,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6538
6519
|
if (!found && available === "disabled") return;
|
|
6539
6520
|
ctxIdRef.current = copilotkit.addContext({
|
|
6540
6521
|
description,
|
|
6541
|
-
value: (convert
|
|
6522
|
+
value: (convert ?? JSON.stringify)(value)
|
|
6542
6523
|
});
|
|
6543
6524
|
return () => {
|
|
6544
6525
|
if (!ctxIdRef.current) return;
|
|
@@ -6690,11 +6671,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6690
6671
|
...agent.state,
|
|
6691
6672
|
...newState
|
|
6692
6673
|
});
|
|
6693
|
-
}, [agent
|
|
6674
|
+
}, [agent?.state, agent?.setState]);
|
|
6694
6675
|
(0, react.useEffect)(() => {
|
|
6695
|
-
var _options$config;
|
|
6696
6676
|
if (!options.config && !options.configurable) return;
|
|
6697
|
-
let config =
|
|
6677
|
+
let config = options.config ?? {};
|
|
6698
6678
|
if (options.configurable) config = {
|
|
6699
6679
|
...config,
|
|
6700
6680
|
configurable: {
|
|
@@ -6705,7 +6685,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6705
6685
|
copilotkit.setProperties(config);
|
|
6706
6686
|
}, [options.config, options.configurable]);
|
|
6707
6687
|
(0, react.useEffect)(() => {
|
|
6708
|
-
if (
|
|
6688
|
+
if (agent?.state && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) handleStateUpdate(options.state);
|
|
6709
6689
|
}, [
|
|
6710
6690
|
agent,
|
|
6711
6691
|
(0, react.useMemo)(() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]),
|
|
@@ -6743,12 +6723,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6743
6723
|
hasStateValues
|
|
6744
6724
|
]);
|
|
6745
6725
|
return (0, react.useMemo)(() => {
|
|
6746
|
-
var _agent$agentId;
|
|
6747
6726
|
if (!agent) {
|
|
6748
|
-
var _ref, _ref2;
|
|
6749
6727
|
const noop = () => {};
|
|
6750
6728
|
const noopAsync = async () => {};
|
|
6751
|
-
const initialState = (
|
|
6729
|
+
const initialState = ("state" in options && options.state) ?? ("initialState" in options && options.initialState) ?? {};
|
|
6752
6730
|
return {
|
|
6753
6731
|
name: options.name,
|
|
6754
6732
|
nodeName,
|
|
@@ -6762,7 +6740,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6762
6740
|
};
|
|
6763
6741
|
}
|
|
6764
6742
|
return {
|
|
6765
|
-
name:
|
|
6743
|
+
name: agent?.agentId ?? options.name,
|
|
6766
6744
|
nodeName,
|
|
6767
6745
|
threadId: agent.threadId,
|
|
6768
6746
|
running: agent.isRunning,
|
|
@@ -6773,13 +6751,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6773
6751
|
run: agent.runAgent
|
|
6774
6752
|
};
|
|
6775
6753
|
}, [
|
|
6776
|
-
agent
|
|
6777
|
-
agent
|
|
6778
|
-
agent
|
|
6779
|
-
agent
|
|
6780
|
-
agent
|
|
6781
|
-
agent
|
|
6782
|
-
agent
|
|
6754
|
+
agent?.state,
|
|
6755
|
+
agent?.runAgent,
|
|
6756
|
+
agent?.abortRun,
|
|
6757
|
+
agent?.runAgent,
|
|
6758
|
+
agent?.threadId,
|
|
6759
|
+
agent?.isRunning,
|
|
6760
|
+
agent?.agentId,
|
|
6783
6761
|
handleStateUpdate,
|
|
6784
6762
|
options.name
|
|
6785
6763
|
]);
|
|
@@ -6822,12 +6800,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6822
6800
|
return new _copilotkit_runtime_client_gql.CopilotRuntimeClient({
|
|
6823
6801
|
...runtimeOptions,
|
|
6824
6802
|
handleGQLErrors: (error) => {
|
|
6825
|
-
|
|
6826
|
-
if ((_graphQLErrors = error.graphQLErrors) === null || _graphQLErrors === void 0 ? void 0 : _graphQLErrors.length) {
|
|
6803
|
+
if (error.graphQLErrors?.length) {
|
|
6827
6804
|
const graphQLErrors = error.graphQLErrors;
|
|
6828
6805
|
const routeError = (gqlError) => {
|
|
6829
|
-
|
|
6830
|
-
if ((extensions === null || extensions === void 0 ? void 0 : extensions.visibility) === _copilotkit_shared.ErrorVisibility.SILENT) {
|
|
6806
|
+
if (gqlError.extensions?.visibility === _copilotkit_shared.ErrorVisibility.SILENT) {
|
|
6831
6807
|
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
6832
6808
|
return;
|
|
6833
6809
|
}
|
|
@@ -6854,7 +6830,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6854
6830
|
graphQLErrors.forEach(routeError);
|
|
6855
6831
|
} else {
|
|
6856
6832
|
const fallbackError = new _copilotkit_shared.CopilotKitError({
|
|
6857
|
-
message:
|
|
6833
|
+
message: error?.message || String(error),
|
|
6858
6834
|
code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
|
|
6859
6835
|
});
|
|
6860
6836
|
setBannerError(fallbackError);
|
|
@@ -6876,18 +6852,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6876
6852
|
]);
|
|
6877
6853
|
};
|
|
6878
6854
|
function createStructuredError(gqlError) {
|
|
6879
|
-
var _originalError$stack, _originalError$stack2, _originalError$stack3;
|
|
6880
6855
|
const extensions = gqlError.extensions;
|
|
6881
|
-
const originalError = extensions
|
|
6882
|
-
const message =
|
|
6883
|
-
const code = extensions
|
|
6856
|
+
const originalError = extensions?.originalError;
|
|
6857
|
+
const message = originalError?.message || gqlError.message;
|
|
6858
|
+
const code = extensions?.code;
|
|
6884
6859
|
if (code) return new _copilotkit_shared.CopilotKitError({
|
|
6885
6860
|
message,
|
|
6886
6861
|
code
|
|
6887
6862
|
});
|
|
6888
|
-
if (originalError
|
|
6889
|
-
if (originalError
|
|
6890
|
-
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({
|
|
6891
6866
|
agentName: "",
|
|
6892
6867
|
availableAgents: []
|
|
6893
6868
|
});
|
|
@@ -6916,8 +6891,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6916
6891
|
const wrappedRender = (0, react.useCallback)((props) => {
|
|
6917
6892
|
if (!Object.values(authStates_c || {}).some((state) => state.status === "authenticated")) {
|
|
6918
6893
|
pendingActionRef.current = props;
|
|
6919
|
-
return
|
|
6920
|
-
setAuthStates_c
|
|
6894
|
+
return authConfig_c?.SignInComponent ? react.default.createElement(authConfig_c.SignInComponent, { onSignInComplete: (authState) => {
|
|
6895
|
+
setAuthStates_c?.((prev) => ({
|
|
6921
6896
|
...prev,
|
|
6922
6897
|
[action.name]: authState
|
|
6923
6898
|
}));
|
|
@@ -6954,12 +6929,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6954
6929
|
};
|
|
6955
6930
|
}
|
|
6956
6931
|
function useLangGraphInterrupt(action, _dependencies) {
|
|
6957
|
-
var _ref, _action$agentId;
|
|
6958
6932
|
const actionRef = (0, react.useRef)(action);
|
|
6959
6933
|
actionRef.current = action;
|
|
6960
6934
|
const existingConfig = useCopilotChatConfiguration();
|
|
6961
|
-
const resolvedAgentId =
|
|
6962
|
-
const threadId = existingConfig
|
|
6935
|
+
const resolvedAgentId = action.agentId ?? existingConfig?.agentId ?? "default";
|
|
6936
|
+
const threadId = existingConfig?.threadId;
|
|
6963
6937
|
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
6964
6938
|
const metadataRef = (0, react.useRef)({
|
|
6965
6939
|
agentName: resolvedAgentId,
|
|
@@ -6984,8 +6958,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6984
6958
|
return rendered;
|
|
6985
6959
|
}, []),
|
|
6986
6960
|
handler: (0, react.useCallback)(({ event, resolve }) => {
|
|
6987
|
-
|
|
6988
|
-
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?.({
|
|
6989
6962
|
event: toV1Event(event),
|
|
6990
6963
|
resolve: (r) => resolve(r)
|
|
6991
6964
|
});
|
|
@@ -7050,7 +7023,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7050
7023
|
if (available === "disabled") return;
|
|
7051
7024
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
7052
7025
|
return () => {
|
|
7053
|
-
setAdditionalInstructions((prevInstructions) =>
|
|
7026
|
+
setAdditionalInstructions((prevInstructions) => prevInstructions?.filter((instruction) => instruction !== instructions) || []);
|
|
7054
7027
|
};
|
|
7055
7028
|
}, [
|
|
7056
7029
|
available,
|
|
@@ -7132,10 +7105,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7132
7105
|
* removes it on unmount, ensuring a clean and efficient lifecycle management.
|
|
7133
7106
|
*/
|
|
7134
7107
|
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
7135
|
-
|
|
7136
|
-
const
|
|
7137
|
-
const resolvedAgentId = (_existingConfig$agent = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId) !== null && _existingConfig$agent !== void 0 ? _existingConfig$agent : "default";
|
|
7138
|
-
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";
|
|
7139
7110
|
useConfigureSuggestions({
|
|
7140
7111
|
...config,
|
|
7141
7112
|
available,
|
|
@@ -7223,7 +7194,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7223
7194
|
* @param data The data to use for the task.
|
|
7224
7195
|
*/
|
|
7225
7196
|
async run(context, data) {
|
|
7226
|
-
var _response$data;
|
|
7227
7197
|
const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
|
|
7228
7198
|
for (const fn of this.actions) actions[fn.name] = fn;
|
|
7229
7199
|
let contextString = "";
|
|
@@ -7254,7 +7224,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7254
7224
|
properties: context.copilotApiConfig.properties
|
|
7255
7225
|
}).toPromise();
|
|
7256
7226
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
7257
|
-
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());
|
|
7258
7228
|
for (const functionCall of functionCalls) await functionCallHandler({
|
|
7259
7229
|
messages,
|
|
7260
7230
|
name: functionCall.name,
|