@copilotkit/react-core 1.57.0 → 1.57.1-canary.1778272612
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{copilotkit-CPe2-340.mjs → copilotkit-3XTEoVQO.mjs} +1367 -1200
- package/dist/copilotkit-3XTEoVQO.mjs.map +1 -0
- package/dist/{copilotkit-DFaI4j2r.d.mts → copilotkit-BCJ2yvV6.d.mts} +68 -8
- package/dist/copilotkit-BCJ2yvV6.d.mts.map +1 -0
- package/dist/{copilotkit-Dg4r4Gi_.d.cts → copilotkit-CBbSvze0.d.cts} +68 -8
- package/dist/copilotkit-CBbSvze0.d.cts.map +1 -0
- package/dist/{copilotkit-DGbvw8n2.cjs → copilotkit-Dnj9pi4m.cjs} +1369 -1196
- package/dist/copilotkit-Dnj9pi4m.cjs.map +1 -0
- package/dist/index.cjs +2 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +733 -610
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.cjs +135 -0
- package/dist/v2/context.cjs.map +1 -0
- package/dist/v2/context.d.cts +148 -0
- package/dist/v2/context.d.cts.map +1 -0
- package/dist/v2/context.d.mts +148 -0
- package/dist/v2/context.d.mts.map +1 -0
- package/dist/v2/context.mjs +129 -0
- package/dist/v2/context.mjs.map +1 -0
- package/dist/v2/headless.cjs +1043 -0
- package/dist/v2/headless.cjs.map +1 -0
- package/dist/v2/headless.d.cts +605 -0
- package/dist/v2/headless.d.cts.map +1 -0
- package/dist/v2/headless.d.mts +512 -0
- package/dist/v2/headless.d.mts.map +1 -0
- package/dist/v2/headless.mjs +997 -0
- package/dist/v2/headless.mjs.map +1 -0
- package/dist/v2/index.cjs +2 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +1385 -1204
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +14 -6
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +5 -6
- package/src/hooks/use-copilot-chat_internal.ts +0 -1
- package/src/v2/components/chat/CopilotChat.tsx +2 -1
- package/src/v2/components/chat/CopilotChatMessageView.tsx +24 -9
- package/src/v2/components/chat/CopilotChatView.tsx +2 -2
- package/src/v2/components/chat/CopilotSidebar.tsx +5 -1
- package/src/v2/components/chat/CopilotSidebarView.tsx +24 -10
- package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +1 -3
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +29 -25
- package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +159 -0
- package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +5 -60
- package/src/v2/components/index.ts +1 -0
- package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +286 -0
- package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +464 -0
- package/src/v2/components/intelligence-indicator/index.ts +2 -0
- package/src/v2/context.ts +62 -0
- package/src/v2/headless.ts +42 -0
- package/src/v2/hooks/__tests__/standard-schema.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-agent-context.test.tsx +3 -3
- package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +3 -3
- package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +85 -85
- package/src/v2/hooks/__tests__/use-interrupt.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-render-tool.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-threads.test.tsx +2 -2
- package/src/v2/hooks/__tests__/zod-regression.test.tsx +2 -2
- package/src/v2/hooks/use-agent-context.tsx +1 -1
- package/src/v2/hooks/use-agent.tsx +9 -118
- package/src/v2/hooks/use-configure-suggestions.tsx +1 -1
- package/src/v2/hooks/use-default-render-tool.tsx +18 -1
- package/src/v2/hooks/use-frontend-tool.tsx +2 -2
- package/src/v2/hooks/use-human-in-the-loop.tsx +1 -1
- package/src/v2/hooks/use-interrupt.tsx +1 -1
- package/src/v2/hooks/use-render-activity-message.tsx +3 -11
- package/src/v2/hooks/use-render-custom-messages.tsx +1 -6
- package/src/v2/hooks/use-render-tool-call.tsx +36 -6
- package/src/v2/hooks/use-render-tool.tsx +2 -2
- package/src/v2/hooks/use-suggestions.tsx +1 -1
- package/src/v2/hooks/use-threads.tsx +1 -1
- package/src/v2/providers/CopilotKitProvider.tsx +19 -59
- package/src/v2/styles/globals.css +118 -0
- package/tsdown.config.ts +75 -0
- package/dist/copilotkit-CPe2-340.mjs.map +0 -1
- package/dist/copilotkit-DFaI4j2r.d.mts.map +0 -1
- package/dist/copilotkit-DGbvw8n2.cjs.map +0 -1
- package/dist/copilotkit-Dg4r4Gi_.d.cts.map +0 -1
- package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +0 -333
package/dist/index.umd.js
CHANGED
|
@@ -204,119 +204,507 @@ react_markdown = __toESM(react_markdown);
|
|
|
204
204
|
};
|
|
205
205
|
|
|
206
206
|
//#endregion
|
|
207
|
-
//#region src/v2/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
207
|
+
//#region src/v2/lib/react-core.ts
|
|
208
|
+
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
209
|
+
constructor(config) {
|
|
210
|
+
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
211
|
+
super(config);
|
|
212
|
+
this._renderToolCalls = [];
|
|
213
|
+
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
214
|
+
this._cachedMergedRenderToolCalls = null;
|
|
215
|
+
this._renderCustomMessages = [];
|
|
216
|
+
this._renderActivityMessages = [];
|
|
217
|
+
this._interruptElement = null;
|
|
218
|
+
this._renderToolCalls = (_config$renderToolCal = config.renderToolCalls) !== null && _config$renderToolCal !== void 0 ? _config$renderToolCal : [];
|
|
219
|
+
this._renderCustomMessages = (_config$renderCustomM = config.renderCustomMessages) !== null && _config$renderCustomM !== void 0 ? _config$renderCustomM : [];
|
|
220
|
+
this._renderActivityMessages = (_config$renderActivit = config.renderActivityMessages) !== null && _config$renderActivit !== void 0 ? _config$renderActivit : [];
|
|
221
|
+
}
|
|
222
|
+
get renderCustomMessages() {
|
|
223
|
+
return this._renderCustomMessages;
|
|
224
|
+
}
|
|
225
|
+
get renderActivityMessages() {
|
|
226
|
+
return this._renderActivityMessages;
|
|
227
|
+
}
|
|
228
|
+
get renderToolCalls() {
|
|
229
|
+
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
230
|
+
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
231
|
+
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
|
+
}
|
|
236
|
+
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
237
|
+
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
238
|
+
return this._cachedMergedRenderToolCalls;
|
|
239
|
+
}
|
|
240
|
+
setRenderActivityMessages(renderers) {
|
|
241
|
+
this._renderActivityMessages = renderers;
|
|
242
|
+
}
|
|
243
|
+
setRenderCustomMessages(renderers) {
|
|
244
|
+
this._renderCustomMessages = renderers;
|
|
245
|
+
}
|
|
246
|
+
setRenderToolCalls(renderToolCalls) {
|
|
247
|
+
this._renderToolCalls = renderToolCalls;
|
|
248
|
+
this._cachedMergedRenderToolCalls = null;
|
|
249
|
+
this._notifyRenderToolCallsChanged();
|
|
250
|
+
}
|
|
251
|
+
addHookRenderToolCall(entry) {
|
|
252
|
+
var _entry$agentId;
|
|
253
|
+
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
254
|
+
this._hookRenderToolCalls.set(key, entry);
|
|
255
|
+
this._cachedMergedRenderToolCalls = null;
|
|
256
|
+
this._notifyRenderToolCallsChanged();
|
|
257
|
+
}
|
|
258
|
+
removeHookRenderToolCall(name, agentId) {
|
|
259
|
+
const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
|
|
260
|
+
if (this._hookRenderToolCalls.delete(key)) {
|
|
261
|
+
this._cachedMergedRenderToolCalls = null;
|
|
262
|
+
this._notifyRenderToolCallsChanged();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
_notifyRenderToolCallsChanged() {
|
|
266
|
+
this.notifySubscribers((subscriber) => {
|
|
267
|
+
const reactSubscriber = subscriber;
|
|
268
|
+
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
269
|
+
copilotkit: this,
|
|
270
|
+
renderToolCalls: this.renderToolCalls
|
|
219
271
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
272
|
+
}, "Subscriber onRenderToolCallsChanged error:");
|
|
273
|
+
}
|
|
274
|
+
get interruptElement() {
|
|
275
|
+
return this._interruptElement;
|
|
276
|
+
}
|
|
277
|
+
setInterruptElement(element) {
|
|
278
|
+
this._interruptElement = element;
|
|
279
|
+
this.notifySubscribers((subscriber) => {
|
|
280
|
+
var _reactSubscriber$onIn;
|
|
281
|
+
const reactSubscriber = subscriber;
|
|
282
|
+
(_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
|
|
283
|
+
copilotkit: this,
|
|
284
|
+
interruptElement: this._interruptElement
|
|
285
|
+
});
|
|
286
|
+
}, "Subscriber onInterruptElementChanged error:");
|
|
287
|
+
}
|
|
288
|
+
subscribe(subscriber) {
|
|
289
|
+
return super.subscribe(subscriber);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Wait for pending React state updates before the follow-up agent run.
|
|
293
|
+
*
|
|
294
|
+
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
295
|
+
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
296
|
+
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
297
|
+
* synchronously after React commits that batch.
|
|
298
|
+
*
|
|
299
|
+
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
300
|
+
* MessageChannel task runs first, committing the pending state and running
|
|
301
|
+
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
302
|
+
* call then reads fresh context.
|
|
303
|
+
*/
|
|
304
|
+
async waitForPendingFrameworkUpdates() {
|
|
305
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
306
|
+
}
|
|
231
307
|
};
|
|
232
|
-
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
233
308
|
|
|
234
309
|
//#endregion
|
|
235
|
-
//#region src/v2/
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
bottom: "8px",
|
|
242
|
-
left: "50%",
|
|
243
|
-
transform: "translateX(-50%)",
|
|
244
|
-
zIndex: 99999,
|
|
245
|
-
display: "inline-flex",
|
|
246
|
-
alignItems: "center",
|
|
247
|
-
gap: "12px",
|
|
248
|
-
whiteSpace: "nowrap",
|
|
249
|
-
padding: "8px 16px",
|
|
250
|
-
fontSize: "13px",
|
|
251
|
-
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
252
|
-
borderRadius: "6px",
|
|
253
|
-
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
|
|
254
|
-
},
|
|
255
|
-
info: {
|
|
256
|
-
backgroundColor: "#eff6ff",
|
|
257
|
-
border: "1px solid #93c5fd",
|
|
258
|
-
color: "#1e40af"
|
|
259
|
-
},
|
|
260
|
-
warning: {
|
|
261
|
-
backgroundColor: "#fffbeb",
|
|
262
|
-
border: "1px solid #fbbf24",
|
|
263
|
-
color: "#92400e"
|
|
264
|
-
},
|
|
265
|
-
critical: {
|
|
266
|
-
backgroundColor: "#fef2f2",
|
|
267
|
-
border: "1px solid #fca5a5",
|
|
268
|
-
color: "#991b1b"
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
function getSeverityStyle(severity) {
|
|
272
|
-
switch (severity) {
|
|
273
|
-
case "warning": return BANNER_STYLES.warning;
|
|
274
|
-
case "critical": return BANNER_STYLES.critical;
|
|
275
|
-
default: return BANNER_STYLES.info;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
function BannerShell({ severity, message, actionLabel, actionUrl, onDismiss }) {
|
|
310
|
+
//#region src/v2/context.ts
|
|
311
|
+
const CopilotKitContext = (0, react.createContext)(null);
|
|
312
|
+
const useCopilotKit = () => {
|
|
313
|
+
const context = (0, react.useContext)(CopilotKitContext);
|
|
314
|
+
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
315
|
+
if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
279
316
|
(0, react.useEffect)(() => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
317
|
+
const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
|
|
318
|
+
forceUpdate();
|
|
319
|
+
} });
|
|
283
320
|
return () => {
|
|
284
|
-
|
|
321
|
+
subscription.unsubscribe();
|
|
285
322
|
};
|
|
286
323
|
}, []);
|
|
287
|
-
return
|
|
324
|
+
return context;
|
|
325
|
+
};
|
|
326
|
+
const LicenseContext = (0, react.createContext)({
|
|
327
|
+
status: null,
|
|
328
|
+
license: null,
|
|
329
|
+
checkFeature: () => true,
|
|
330
|
+
getLimit: () => null
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/v2/types/defineToolCallRenderer.ts
|
|
335
|
+
function defineToolCallRenderer(def) {
|
|
336
|
+
const argsSchema = def.name === "*" && !def.args ? zod.z.any() : def.args;
|
|
337
|
+
return {
|
|
338
|
+
name: def.name,
|
|
339
|
+
args: argsSchema,
|
|
340
|
+
render: def.render,
|
|
341
|
+
...def.agentId ? { agentId: def.agentId } : {}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/v2/hooks/use-default-render-tool.tsx
|
|
347
|
+
function DefaultToolCallRenderer({ name, parameters, status, result }) {
|
|
348
|
+
const [isExpanded, setIsExpanded] = (0, react.useState)(false);
|
|
349
|
+
const statusString = String(status);
|
|
350
|
+
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
351
|
+
const isComplete = statusString === "complete";
|
|
352
|
+
const statusLabel = isActive ? "Running" : isComplete ? "Done" : status;
|
|
353
|
+
const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa";
|
|
354
|
+
const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5";
|
|
355
|
+
const badgeColor = isActive ? "#92400e" : isComplete ? "#065f46" : "#3f3f46";
|
|
356
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
357
|
+
"data-testid": "copilot-tool-render",
|
|
358
|
+
"data-tool-name": name,
|
|
359
|
+
"data-status": statusString,
|
|
360
|
+
"data-args": safeStringifyForAttr(parameters),
|
|
361
|
+
"data-result": safeStringifyForAttr(result),
|
|
288
362
|
style: {
|
|
289
|
-
|
|
290
|
-
|
|
363
|
+
marginTop: "8px",
|
|
364
|
+
paddingBottom: "8px"
|
|
291
365
|
},
|
|
292
|
-
children:
|
|
366
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
293
367
|
style: {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
368
|
+
borderRadius: "12px",
|
|
369
|
+
border: "1px solid #e4e4e7",
|
|
370
|
+
backgroundColor: "#fafafa",
|
|
371
|
+
padding: "14px 16px"
|
|
297
372
|
},
|
|
298
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
299
|
-
|
|
300
|
-
target: "_blank",
|
|
301
|
-
rel: "noopener noreferrer",
|
|
373
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
374
|
+
onClick: () => setIsExpanded(!isExpanded),
|
|
302
375
|
style: {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
376
|
+
display: "flex",
|
|
377
|
+
alignItems: "center",
|
|
378
|
+
justifyContent: "space-between",
|
|
379
|
+
gap: "10px",
|
|
380
|
+
cursor: "pointer",
|
|
381
|
+
userSelect: "none"
|
|
306
382
|
},
|
|
307
|
-
children:
|
|
308
|
-
|
|
309
|
-
|
|
383
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
384
|
+
style: {
|
|
385
|
+
display: "flex",
|
|
386
|
+
alignItems: "center",
|
|
387
|
+
gap: "8px",
|
|
388
|
+
minWidth: 0
|
|
389
|
+
},
|
|
390
|
+
children: [
|
|
391
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
392
|
+
style: {
|
|
393
|
+
height: "14px",
|
|
394
|
+
width: "14px",
|
|
395
|
+
color: "#71717a",
|
|
396
|
+
transition: "transform 0.15s",
|
|
397
|
+
transform: isExpanded ? "rotate(90deg)" : "rotate(0deg)",
|
|
398
|
+
flexShrink: 0
|
|
399
|
+
},
|
|
400
|
+
fill: "none",
|
|
401
|
+
viewBox: "0 0 24 24",
|
|
402
|
+
strokeWidth: 2,
|
|
403
|
+
stroke: "currentColor",
|
|
404
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
405
|
+
strokeLinecap: "round",
|
|
406
|
+
strokeLinejoin: "round",
|
|
407
|
+
d: "M8.25 4.5l7.5 7.5-7.5 7.5"
|
|
408
|
+
})
|
|
409
|
+
}),
|
|
410
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: {
|
|
411
|
+
display: "inline-block",
|
|
412
|
+
height: "8px",
|
|
413
|
+
width: "8px",
|
|
414
|
+
borderRadius: "50%",
|
|
415
|
+
backgroundColor: dotColor,
|
|
416
|
+
flexShrink: 0
|
|
417
|
+
} }),
|
|
418
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
419
|
+
"data-testid": "copilot-tool-render-name",
|
|
420
|
+
style: {
|
|
421
|
+
fontSize: "13px",
|
|
422
|
+
fontWeight: 600,
|
|
423
|
+
color: "#18181b",
|
|
424
|
+
overflow: "hidden",
|
|
425
|
+
textOverflow: "ellipsis",
|
|
426
|
+
whiteSpace: "nowrap"
|
|
427
|
+
},
|
|
428
|
+
children: name
|
|
429
|
+
})
|
|
430
|
+
]
|
|
431
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
432
|
+
"data-testid": "copilot-tool-render-status",
|
|
433
|
+
style: {
|
|
434
|
+
display: "inline-flex",
|
|
435
|
+
alignItems: "center",
|
|
436
|
+
borderRadius: "9999px",
|
|
437
|
+
padding: "2px 8px",
|
|
438
|
+
fontSize: "11px",
|
|
439
|
+
fontWeight: 500,
|
|
440
|
+
backgroundColor: badgeBg,
|
|
441
|
+
color: badgeColor,
|
|
442
|
+
flexShrink: 0
|
|
443
|
+
},
|
|
444
|
+
children: statusLabel
|
|
445
|
+
})]
|
|
446
|
+
}), isExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
310
447
|
style: {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
color: "inherit",
|
|
315
|
-
fontSize: "16px"
|
|
448
|
+
marginTop: "12px",
|
|
449
|
+
display: "grid",
|
|
450
|
+
gap: "12px"
|
|
316
451
|
},
|
|
317
|
-
children: "
|
|
452
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
453
|
+
style: {
|
|
454
|
+
fontSize: "10px",
|
|
455
|
+
textTransform: "uppercase",
|
|
456
|
+
letterSpacing: "0.05em",
|
|
457
|
+
color: "#71717a"
|
|
458
|
+
},
|
|
459
|
+
children: "Arguments"
|
|
460
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
461
|
+
style: {
|
|
462
|
+
marginTop: "6px",
|
|
463
|
+
maxHeight: "200px",
|
|
464
|
+
overflow: "auto",
|
|
465
|
+
borderRadius: "6px",
|
|
466
|
+
backgroundColor: "#f4f4f5",
|
|
467
|
+
padding: "10px",
|
|
468
|
+
fontSize: "11px",
|
|
469
|
+
lineHeight: 1.6,
|
|
470
|
+
color: "#27272a",
|
|
471
|
+
whiteSpace: "pre-wrap",
|
|
472
|
+
wordBreak: "break-word"
|
|
473
|
+
},
|
|
474
|
+
children: JSON.stringify(parameters !== null && parameters !== void 0 ? parameters : {}, null, 2)
|
|
475
|
+
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
476
|
+
style: {
|
|
477
|
+
fontSize: "10px",
|
|
478
|
+
textTransform: "uppercase",
|
|
479
|
+
letterSpacing: "0.05em",
|
|
480
|
+
color: "#71717a"
|
|
481
|
+
},
|
|
482
|
+
children: "Result"
|
|
483
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
484
|
+
style: {
|
|
485
|
+
marginTop: "6px",
|
|
486
|
+
maxHeight: "200px",
|
|
487
|
+
overflow: "auto",
|
|
488
|
+
borderRadius: "6px",
|
|
489
|
+
backgroundColor: "#f4f4f5",
|
|
490
|
+
padding: "10px",
|
|
491
|
+
fontSize: "11px",
|
|
492
|
+
lineHeight: 1.6,
|
|
493
|
+
color: "#27272a",
|
|
494
|
+
whiteSpace: "pre-wrap",
|
|
495
|
+
wordBreak: "break-word"
|
|
496
|
+
},
|
|
497
|
+
children: typeof result === "string" ? result : JSON.stringify(result, null, 2)
|
|
498
|
+
})] })]
|
|
318
499
|
})]
|
|
319
|
-
})
|
|
500
|
+
})
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function safeStringifyForAttr(value) {
|
|
504
|
+
if (value === void 0 || value === null) return "";
|
|
505
|
+
if (typeof value === "string") return value;
|
|
506
|
+
try {
|
|
507
|
+
return JSON.stringify(value);
|
|
508
|
+
} catch (_unused) {
|
|
509
|
+
return String(value);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
515
|
+
/**
|
|
516
|
+
* Memoized component that renders a single tool call.
|
|
517
|
+
* This prevents unnecessary re-renders when parent components update
|
|
518
|
+
* but the tool call data hasn't changed.
|
|
519
|
+
*/
|
|
520
|
+
const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
521
|
+
const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
522
|
+
const toolName = toolCall.function.name;
|
|
523
|
+
if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
524
|
+
name: toolName,
|
|
525
|
+
toolCallId: toolCall.id,
|
|
526
|
+
args,
|
|
527
|
+
status: _copilotkit_core.ToolCallStatus.Complete,
|
|
528
|
+
result: toolMessage.content
|
|
529
|
+
});
|
|
530
|
+
else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
531
|
+
name: toolName,
|
|
532
|
+
toolCallId: toolCall.id,
|
|
533
|
+
args,
|
|
534
|
+
status: _copilotkit_core.ToolCallStatus.Executing,
|
|
535
|
+
result: void 0
|
|
536
|
+
});
|
|
537
|
+
else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
538
|
+
name: toolName,
|
|
539
|
+
toolCallId: toolCall.id,
|
|
540
|
+
args,
|
|
541
|
+
status: _copilotkit_core.ToolCallStatus.InProgress,
|
|
542
|
+
result: void 0
|
|
543
|
+
});
|
|
544
|
+
}, (prevProps, nextProps) => {
|
|
545
|
+
var _prevProps$toolMessag, _nextProps$toolMessag;
|
|
546
|
+
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
547
|
+
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
548
|
+
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
549
|
+
if (((_prevProps$toolMessag = prevProps.toolMessage) === null || _prevProps$toolMessag === void 0 ? void 0 : _prevProps$toolMessag.content) !== ((_nextProps$toolMessag = nextProps.toolMessage) === null || _nextProps$toolMessag === void 0 ? void 0 : _nextProps$toolMessag.content)) return false;
|
|
550
|
+
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
551
|
+
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
552
|
+
return true;
|
|
553
|
+
});
|
|
554
|
+
/**
|
|
555
|
+
* Hook that returns a function to render tool calls based on the render functions
|
|
556
|
+
* defined in CopilotKitProvider.
|
|
557
|
+
*
|
|
558
|
+
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
559
|
+
*/
|
|
560
|
+
function useRenderToolCall$1() {
|
|
561
|
+
var _config$agentId;
|
|
562
|
+
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
563
|
+
const config = useCopilotChatConfiguration();
|
|
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;
|
|
565
|
+
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
566
|
+
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
567
|
+
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
568
|
+
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
569
|
+
var _renderConfig$render;
|
|
570
|
+
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
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
573
|
+
toolCall,
|
|
574
|
+
toolMessage,
|
|
575
|
+
RenderComponent: (_renderConfig$render = renderConfig === null || renderConfig === void 0 ? void 0 : renderConfig.render) !== null && _renderConfig$render !== void 0 ? _renderConfig$render : defaultToolCallRenderAdapter,
|
|
576
|
+
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
577
|
+
}, toolCall.id);
|
|
578
|
+
}, [
|
|
579
|
+
renderToolCalls,
|
|
580
|
+
executingToolCallIds,
|
|
581
|
+
agentId
|
|
582
|
+
]);
|
|
583
|
+
}
|
|
584
|
+
function defaultToolCallRenderAdapter(props) {
|
|
585
|
+
const status = props.status === _copilotkit_core.ToolCallStatus.Complete ? "complete" : props.status === _copilotkit_core.ToolCallStatus.Executing ? "executing" : "inProgress";
|
|
586
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultToolCallRenderer, {
|
|
587
|
+
name: props.name,
|
|
588
|
+
parameters: props.args,
|
|
589
|
+
status,
|
|
590
|
+
result: props.result
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/v2/components/CopilotKitInspector.tsx
|
|
596
|
+
const CopilotKitInspector = ({ core, ...rest }) => {
|
|
597
|
+
const [InspectorComponent, setInspectorComponent] = react.useState(null);
|
|
598
|
+
react.useEffect(() => {
|
|
599
|
+
let mounted = true;
|
|
600
|
+
import("@copilotkit/web-inspector").then((mod) => {
|
|
601
|
+
var _mod$defineWebInspect;
|
|
602
|
+
(_mod$defineWebInspect = mod.defineWebInspector) === null || _mod$defineWebInspect === void 0 || _mod$defineWebInspect.call(mod);
|
|
603
|
+
const Component = (0, _lit_labs_react.createComponent)({
|
|
604
|
+
tagName: mod.WEB_INSPECTOR_TAG,
|
|
605
|
+
elementClass: mod.WebInspectorElement,
|
|
606
|
+
react
|
|
607
|
+
});
|
|
608
|
+
if (mounted) setInspectorComponent(() => Component);
|
|
609
|
+
});
|
|
610
|
+
return () => {
|
|
611
|
+
mounted = false;
|
|
612
|
+
};
|
|
613
|
+
}, []);
|
|
614
|
+
if (!InspectorComponent) return null;
|
|
615
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
|
|
616
|
+
...rest,
|
|
617
|
+
core: core !== null && core !== void 0 ? core : null
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
621
|
+
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/v2/components/license-warning-banner.tsx
|
|
624
|
+
const LICENSE_BANNER_OFFSET_PX = 52;
|
|
625
|
+
const LICENSE_BANNER_OFFSET_VAR = "--copilotkit-license-banner-offset";
|
|
626
|
+
const BANNER_STYLES = {
|
|
627
|
+
base: {
|
|
628
|
+
position: "fixed",
|
|
629
|
+
bottom: "8px",
|
|
630
|
+
left: "50%",
|
|
631
|
+
transform: "translateX(-50%)",
|
|
632
|
+
zIndex: 99999,
|
|
633
|
+
display: "inline-flex",
|
|
634
|
+
alignItems: "center",
|
|
635
|
+
gap: "12px",
|
|
636
|
+
whiteSpace: "nowrap",
|
|
637
|
+
padding: "8px 16px",
|
|
638
|
+
fontSize: "13px",
|
|
639
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
640
|
+
borderRadius: "6px",
|
|
641
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
|
|
642
|
+
},
|
|
643
|
+
info: {
|
|
644
|
+
backgroundColor: "#eff6ff",
|
|
645
|
+
border: "1px solid #93c5fd",
|
|
646
|
+
color: "#1e40af"
|
|
647
|
+
},
|
|
648
|
+
warning: {
|
|
649
|
+
backgroundColor: "#fffbeb",
|
|
650
|
+
border: "1px solid #fbbf24",
|
|
651
|
+
color: "#92400e"
|
|
652
|
+
},
|
|
653
|
+
critical: {
|
|
654
|
+
backgroundColor: "#fef2f2",
|
|
655
|
+
border: "1px solid #fca5a5",
|
|
656
|
+
color: "#991b1b"
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
function getSeverityStyle(severity) {
|
|
660
|
+
switch (severity) {
|
|
661
|
+
case "warning": return BANNER_STYLES.warning;
|
|
662
|
+
case "critical": return BANNER_STYLES.critical;
|
|
663
|
+
default: return BANNER_STYLES.info;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function BannerShell({ severity, message, actionLabel, actionUrl, onDismiss }) {
|
|
667
|
+
(0, react.useEffect)(() => {
|
|
668
|
+
if (typeof document === "undefined") return;
|
|
669
|
+
const root = document.documentElement;
|
|
670
|
+
root.style.setProperty(LICENSE_BANNER_OFFSET_VAR, `${LICENSE_BANNER_OFFSET_PX}px`);
|
|
671
|
+
return () => {
|
|
672
|
+
root.style.removeProperty(LICENSE_BANNER_OFFSET_VAR);
|
|
673
|
+
};
|
|
674
|
+
}, []);
|
|
675
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
676
|
+
style: {
|
|
677
|
+
...BANNER_STYLES.base,
|
|
678
|
+
...getSeverityStyle(severity)
|
|
679
|
+
},
|
|
680
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: message }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
681
|
+
style: {
|
|
682
|
+
display: "flex",
|
|
683
|
+
gap: "8px",
|
|
684
|
+
alignItems: "center"
|
|
685
|
+
},
|
|
686
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
687
|
+
href: actionUrl,
|
|
688
|
+
target: "_blank",
|
|
689
|
+
rel: "noopener noreferrer",
|
|
690
|
+
style: {
|
|
691
|
+
fontWeight: 600,
|
|
692
|
+
textDecoration: "underline",
|
|
693
|
+
color: "inherit"
|
|
694
|
+
},
|
|
695
|
+
children: actionLabel
|
|
696
|
+
}), onDismiss && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
697
|
+
onClick: onDismiss,
|
|
698
|
+
style: {
|
|
699
|
+
background: "none",
|
|
700
|
+
border: "none",
|
|
701
|
+
cursor: "pointer",
|
|
702
|
+
color: "inherit",
|
|
703
|
+
fontSize: "16px"
|
|
704
|
+
},
|
|
705
|
+
children: "×"
|
|
706
|
+
})]
|
|
707
|
+
})]
|
|
320
708
|
});
|
|
321
709
|
}
|
|
322
710
|
function LicenseWarningBanner({ type, featureName, expiryDate, graceRemaining, onDismiss }) {
|
|
@@ -1429,18 +1817,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1429
1817
|
return (_ref = (_ref2 = (_ref3 = (_operation$createSurf = operation === null || operation === void 0 || (_operation$createSurf2 = operation.createSurface) === null || _operation$createSurf2 === void 0 ? void 0 : _operation$createSurf2.surfaceId) !== null && _operation$createSurf !== void 0 ? _operation$createSurf : operation === null || operation === void 0 || (_operation$updateComp = operation.updateComponents) === null || _operation$updateComp === void 0 ? void 0 : _operation$updateComp.surfaceId) !== null && _ref3 !== void 0 ? _ref3 : operation === null || operation === void 0 || (_operation$updateData = operation.updateDataModel) === null || _operation$updateData === void 0 ? void 0 : _operation$updateData.surfaceId) !== null && _ref2 !== void 0 ? _ref2 : operation === null || operation === void 0 || (_operation$deleteSurf = operation.deleteSurface) === null || _operation$deleteSurf === void 0 ? void 0 : _operation$deleteSurf.surfaceId) !== null && _ref !== void 0 ? _ref : null;
|
|
1430
1818
|
}
|
|
1431
1819
|
|
|
1432
|
-
//#endregion
|
|
1433
|
-
//#region src/v2/types/defineToolCallRenderer.ts
|
|
1434
|
-
function defineToolCallRenderer(def) {
|
|
1435
|
-
const argsSchema = def.name === "*" && !def.args ? zod.z.any() : def.args;
|
|
1436
|
-
return {
|
|
1437
|
-
name: def.name,
|
|
1438
|
-
args: argsSchema,
|
|
1439
|
-
render: def.render,
|
|
1440
|
-
...def.agentId ? { agentId: def.agentId } : {}
|
|
1441
|
-
};
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
1820
|
//#endregion
|
|
1445
1821
|
//#region src/v2/a2ui/A2UIToolCallRenderer.tsx
|
|
1446
1822
|
/**
|
|
@@ -1835,109 +2211,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1835
2211
|
return null;
|
|
1836
2212
|
}
|
|
1837
2213
|
|
|
1838
|
-
//#endregion
|
|
1839
|
-
//#region src/v2/lib/react-core.ts
|
|
1840
|
-
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
1841
|
-
constructor(config) {
|
|
1842
|
-
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
1843
|
-
super(config);
|
|
1844
|
-
this._renderToolCalls = [];
|
|
1845
|
-
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
1846
|
-
this._cachedMergedRenderToolCalls = null;
|
|
1847
|
-
this._renderCustomMessages = [];
|
|
1848
|
-
this._renderActivityMessages = [];
|
|
1849
|
-
this._interruptElement = null;
|
|
1850
|
-
this._renderToolCalls = (_config$renderToolCal = config.renderToolCalls) !== null && _config$renderToolCal !== void 0 ? _config$renderToolCal : [];
|
|
1851
|
-
this._renderCustomMessages = (_config$renderCustomM = config.renderCustomMessages) !== null && _config$renderCustomM !== void 0 ? _config$renderCustomM : [];
|
|
1852
|
-
this._renderActivityMessages = (_config$renderActivit = config.renderActivityMessages) !== null && _config$renderActivit !== void 0 ? _config$renderActivit : [];
|
|
1853
|
-
}
|
|
1854
|
-
get renderCustomMessages() {
|
|
1855
|
-
return this._renderCustomMessages;
|
|
1856
|
-
}
|
|
1857
|
-
get renderActivityMessages() {
|
|
1858
|
-
return this._renderActivityMessages;
|
|
1859
|
-
}
|
|
1860
|
-
get renderToolCalls() {
|
|
1861
|
-
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
1862
|
-
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
1863
|
-
const merged = /* @__PURE__ */ new Map();
|
|
1864
|
-
for (const rc of this._renderToolCalls) {
|
|
1865
|
-
var _rc$agentId;
|
|
1866
|
-
merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
|
|
1867
|
-
}
|
|
1868
|
-
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
1869
|
-
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
1870
|
-
return this._cachedMergedRenderToolCalls;
|
|
1871
|
-
}
|
|
1872
|
-
setRenderActivityMessages(renderers) {
|
|
1873
|
-
this._renderActivityMessages = renderers;
|
|
1874
|
-
}
|
|
1875
|
-
setRenderCustomMessages(renderers) {
|
|
1876
|
-
this._renderCustomMessages = renderers;
|
|
1877
|
-
}
|
|
1878
|
-
setRenderToolCalls(renderToolCalls) {
|
|
1879
|
-
this._renderToolCalls = renderToolCalls;
|
|
1880
|
-
this._cachedMergedRenderToolCalls = null;
|
|
1881
|
-
this._notifyRenderToolCallsChanged();
|
|
1882
|
-
}
|
|
1883
|
-
addHookRenderToolCall(entry) {
|
|
1884
|
-
var _entry$agentId;
|
|
1885
|
-
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
1886
|
-
this._hookRenderToolCalls.set(key, entry);
|
|
1887
|
-
this._cachedMergedRenderToolCalls = null;
|
|
1888
|
-
this._notifyRenderToolCallsChanged();
|
|
1889
|
-
}
|
|
1890
|
-
removeHookRenderToolCall(name, agentId) {
|
|
1891
|
-
const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
|
|
1892
|
-
if (this._hookRenderToolCalls.delete(key)) {
|
|
1893
|
-
this._cachedMergedRenderToolCalls = null;
|
|
1894
|
-
this._notifyRenderToolCallsChanged();
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
_notifyRenderToolCallsChanged() {
|
|
1898
|
-
this.notifySubscribers((subscriber) => {
|
|
1899
|
-
const reactSubscriber = subscriber;
|
|
1900
|
-
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
1901
|
-
copilotkit: this,
|
|
1902
|
-
renderToolCalls: this.renderToolCalls
|
|
1903
|
-
});
|
|
1904
|
-
}, "Subscriber onRenderToolCallsChanged error:");
|
|
1905
|
-
}
|
|
1906
|
-
get interruptElement() {
|
|
1907
|
-
return this._interruptElement;
|
|
1908
|
-
}
|
|
1909
|
-
setInterruptElement(element) {
|
|
1910
|
-
this._interruptElement = element;
|
|
1911
|
-
this.notifySubscribers((subscriber) => {
|
|
1912
|
-
var _reactSubscriber$onIn;
|
|
1913
|
-
const reactSubscriber = subscriber;
|
|
1914
|
-
(_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
|
|
1915
|
-
copilotkit: this,
|
|
1916
|
-
interruptElement: this._interruptElement
|
|
1917
|
-
});
|
|
1918
|
-
}, "Subscriber onInterruptElementChanged error:");
|
|
1919
|
-
}
|
|
1920
|
-
subscribe(subscriber) {
|
|
1921
|
-
return super.subscribe(subscriber);
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Wait for pending React state updates before the follow-up agent run.
|
|
1925
|
-
*
|
|
1926
|
-
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
1927
|
-
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
1928
|
-
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
1929
|
-
* synchronously after React commits that batch.
|
|
1930
|
-
*
|
|
1931
|
-
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
1932
|
-
* MessageChannel task runs first, committing the pending state and running
|
|
1933
|
-
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
1934
|
-
* call then reads fresh context.
|
|
1935
|
-
*/
|
|
1936
|
-
async waitForPendingFrameworkUpdates() {
|
|
1937
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1938
|
-
}
|
|
1939
|
-
};
|
|
1940
|
-
|
|
1941
2214
|
//#endregion
|
|
1942
2215
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
1943
2216
|
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
@@ -1953,11 +2226,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1953
2226
|
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
1954
2227
|
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
|
|
1955
2228
|
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)";
|
|
1956
|
-
const CopilotKitContext = (0, react.createContext)({
|
|
1957
|
-
copilotkit: null,
|
|
1958
|
-
executingToolCallIds: /* @__PURE__ */ new Set()
|
|
1959
|
-
});
|
|
1960
|
-
const LicenseContext = (0, react.createContext)((0, _copilotkit_shared.createLicenseContextValue)(null));
|
|
1961
2229
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
1962
2230
|
const empty = (0, react.useMemo)(() => [], []);
|
|
1963
2231
|
const value = prop !== null && prop !== void 0 ? prop : empty;
|
|
@@ -2167,399 +2435,145 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2167
2435
|
next.add(toolCallId);
|
|
2168
2436
|
return next;
|
|
2169
2437
|
});
|
|
2170
|
-
},
|
|
2171
|
-
onToolExecutionEnd: ({ toolCallId }) => {
|
|
2172
|
-
setExecutingToolCallIds((prev) => {
|
|
2173
|
-
if (!prev.has(toolCallId)) return prev;
|
|
2174
|
-
const next = new Set(prev);
|
|
2175
|
-
next.delete(toolCallId);
|
|
2176
|
-
return next;
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
});
|
|
2180
|
-
return () => {
|
|
2181
|
-
subscription.unsubscribe();
|
|
2182
|
-
};
|
|
2183
|
-
}, [copilotkit]);
|
|
2184
|
-
const onErrorRef = (0, react.useRef)(onError);
|
|
2185
|
-
(0, react.useEffect)(() => {
|
|
2186
|
-
onErrorRef.current = onError;
|
|
2187
|
-
}, [onError]);
|
|
2188
|
-
(0, react.useEffect)(() => {
|
|
2189
|
-
if (!onErrorRef.current) return;
|
|
2190
|
-
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
2191
|
-
var _onErrorRef$current;
|
|
2192
|
-
(_onErrorRef$current = onErrorRef.current) === null || _onErrorRef$current === void 0 || _onErrorRef$current.call(onErrorRef, {
|
|
2193
|
-
error: event.error,
|
|
2194
|
-
code: event.code,
|
|
2195
|
-
context: event.context
|
|
2196
|
-
});
|
|
2197
|
-
} });
|
|
2198
|
-
return () => {
|
|
2199
|
-
subscription.unsubscribe();
|
|
2200
|
-
};
|
|
2201
|
-
}, [copilotkit]);
|
|
2202
|
-
(0, react.useEffect)(() => {
|
|
2203
|
-
copilotkit.setRuntimeUrl(chatApiEndpoint);
|
|
2204
|
-
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
2205
|
-
copilotkit.setHeaders(mergedHeaders);
|
|
2206
|
-
copilotkit.setCredentials(credentials);
|
|
2207
|
-
copilotkit.setProperties(properties);
|
|
2208
|
-
copilotkit.setAgents__unsafe_dev_only(mergedAgents);
|
|
2209
|
-
copilotkit.setDebug(debug);
|
|
2210
|
-
}, [
|
|
2211
|
-
copilotkit,
|
|
2212
|
-
chatApiEndpoint,
|
|
2213
|
-
mergedHeaders,
|
|
2214
|
-
credentials,
|
|
2215
|
-
properties,
|
|
2216
|
-
mergedAgents,
|
|
2217
|
-
useSingleEndpoint,
|
|
2218
|
-
debug
|
|
2219
|
-
]);
|
|
2220
|
-
const didMountRef = (0, react.useRef)(false);
|
|
2221
|
-
(0, react.useEffect)(() => {
|
|
2222
|
-
if (!didMountRef.current) return;
|
|
2223
|
-
copilotkit.setTools(allTools);
|
|
2224
|
-
}, [copilotkit, allTools]);
|
|
2225
|
-
(0, react.useEffect)(() => {
|
|
2226
|
-
if (!didMountRef.current) return;
|
|
2227
|
-
copilotkit.setRenderToolCalls(allRenderToolCalls);
|
|
2228
|
-
}, [copilotkit, allRenderToolCalls]);
|
|
2229
|
-
(0, react.useEffect)(() => {
|
|
2230
|
-
if (!didMountRef.current) return;
|
|
2231
|
-
copilotkit.setRenderActivityMessages(allActivityRenderers);
|
|
2232
|
-
}, [copilotkit, allActivityRenderers]);
|
|
2233
|
-
(0, react.useEffect)(() => {
|
|
2234
|
-
if (!didMountRef.current) return;
|
|
2235
|
-
copilotkit.setRenderCustomMessages(renderCustomMessagesList);
|
|
2236
|
-
}, [copilotkit, renderCustomMessagesList]);
|
|
2237
|
-
(0, react.useEffect)(() => {
|
|
2238
|
-
didMountRef.current = true;
|
|
2239
|
-
}, []);
|
|
2240
|
-
(0, react.useEffect)(() => {
|
|
2241
|
-
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
2242
|
-
}, [copilotkit, defaultThrottleMs]);
|
|
2243
|
-
const designSkill = (_openGenerativeUI$des = openGenerativeUI === null || openGenerativeUI === void 0 ? void 0 : openGenerativeUI.designSkill) !== null && _openGenerativeUI$des !== void 0 ? _openGenerativeUI$des : DEFAULT_DESIGN_SKILL;
|
|
2244
|
-
(0, react.useLayoutEffect)(() => {
|
|
2245
|
-
if (!copilotkit || !openGenUIActive) return;
|
|
2246
|
-
const id = copilotkit.addContext({
|
|
2247
|
-
description: "Design guidelines for the generateSandboxedUi tool. Follow these when building UI.",
|
|
2248
|
-
value: designSkill
|
|
2249
|
-
});
|
|
2250
|
-
return () => {
|
|
2251
|
-
copilotkit.removeContext(id);
|
|
2252
|
-
};
|
|
2253
|
-
}, [
|
|
2254
|
-
copilotkit,
|
|
2255
|
-
designSkill,
|
|
2256
|
-
openGenUIActive
|
|
2257
|
-
]);
|
|
2258
|
-
const sandboxFunctionsDescriptors = (0, react.useMemo)(() => {
|
|
2259
|
-
if (sandboxFunctionsList.length === 0) return null;
|
|
2260
|
-
return JSON.stringify(sandboxFunctionsList.map((fn) => ({
|
|
2261
|
-
name: fn.name,
|
|
2262
|
-
description: fn.description,
|
|
2263
|
-
parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema })
|
|
2264
|
-
})));
|
|
2265
|
-
}, [sandboxFunctionsList]);
|
|
2266
|
-
(0, react.useLayoutEffect)(() => {
|
|
2267
|
-
if (!copilotkit || !sandboxFunctionsDescriptors || !openGenUIActive) return;
|
|
2268
|
-
const id = copilotkit.addContext({
|
|
2269
|
-
description: "Sandbox functions available in generated sandboxed UI code. Call via: await Websandbox.connection.remote.<functionName>(args)",
|
|
2270
|
-
value: sandboxFunctionsDescriptors
|
|
2271
|
-
});
|
|
2272
|
-
return () => {
|
|
2273
|
-
copilotkit.removeContext(id);
|
|
2274
|
-
};
|
|
2275
|
-
}, [
|
|
2276
|
-
copilotkit,
|
|
2277
|
-
sandboxFunctionsDescriptors,
|
|
2278
|
-
openGenUIActive
|
|
2279
|
-
]);
|
|
2280
|
-
const contextValue = (0, react.useMemo)(() => ({
|
|
2281
|
-
copilotkit,
|
|
2282
|
-
executingToolCallIds
|
|
2283
|
-
}), [copilotkit, executingToolCallIds]);
|
|
2284
|
-
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(null), []);
|
|
2285
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
|
|
2286
|
-
value: sandboxFunctionsList,
|
|
2287
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
|
|
2288
|
-
value: contextValue,
|
|
2289
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
|
|
2290
|
-
value: licenseContextValue,
|
|
2291
|
-
children: [
|
|
2292
|
-
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
2293
|
-
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
2294
|
-
catalog: a2ui === null || a2ui === void 0 ? void 0 : a2ui.catalog,
|
|
2295
|
-
includeSchema: a2ui === null || a2ui === void 0 ? void 0 : a2ui.includeSchema
|
|
2296
|
-
}),
|
|
2297
|
-
children,
|
|
2298
|
-
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
2299
|
-
core: copilotkit,
|
|
2300
|
-
defaultAnchor: inspectorDefaultAnchor
|
|
2301
|
-
}) : null,
|
|
2302
|
-
runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
|
|
2303
|
-
runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
|
|
2304
|
-
runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
|
|
2305
|
-
runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
|
|
2306
|
-
]
|
|
2307
|
-
})
|
|
2308
|
-
})
|
|
2309
|
-
});
|
|
2310
|
-
};
|
|
2311
|
-
const useCopilotKit = () => {
|
|
2312
|
-
const context = (0, react.useContext)(CopilotKitContext);
|
|
2313
|
-
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
2314
|
-
if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
2315
|
-
(0, react.useEffect)(() => {
|
|
2316
|
-
const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
|
|
2317
|
-
forceUpdate();
|
|
2318
|
-
} });
|
|
2319
|
-
return () => {
|
|
2320
|
-
subscription.unsubscribe();
|
|
2321
|
-
};
|
|
2322
|
-
}, []);
|
|
2323
|
-
return context;
|
|
2324
|
-
};
|
|
2325
|
-
|
|
2326
|
-
//#endregion
|
|
2327
|
-
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
2328
|
-
/**
|
|
2329
|
-
* Memoized component that renders a single tool call.
|
|
2330
|
-
* This prevents unnecessary re-renders when parent components update
|
|
2331
|
-
* but the tool call data hasn't changed.
|
|
2332
|
-
*/
|
|
2333
|
-
const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
2334
|
-
const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
2335
|
-
const toolName = toolCall.function.name;
|
|
2336
|
-
if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
2337
|
-
name: toolName,
|
|
2338
|
-
toolCallId: toolCall.id,
|
|
2339
|
-
args,
|
|
2340
|
-
status: _copilotkit_core.ToolCallStatus.Complete,
|
|
2341
|
-
result: toolMessage.content
|
|
2342
|
-
});
|
|
2343
|
-
else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
2344
|
-
name: toolName,
|
|
2345
|
-
toolCallId: toolCall.id,
|
|
2346
|
-
args,
|
|
2347
|
-
status: _copilotkit_core.ToolCallStatus.Executing,
|
|
2348
|
-
result: void 0
|
|
2349
|
-
});
|
|
2350
|
-
else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
2351
|
-
name: toolName,
|
|
2352
|
-
toolCallId: toolCall.id,
|
|
2353
|
-
args,
|
|
2354
|
-
status: _copilotkit_core.ToolCallStatus.InProgress,
|
|
2355
|
-
result: void 0
|
|
2356
|
-
});
|
|
2357
|
-
}, (prevProps, nextProps) => {
|
|
2358
|
-
var _prevProps$toolMessag, _nextProps$toolMessag;
|
|
2359
|
-
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
2360
|
-
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
2361
|
-
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
2362
|
-
if (((_prevProps$toolMessag = prevProps.toolMessage) === null || _prevProps$toolMessag === void 0 ? void 0 : _prevProps$toolMessag.content) !== ((_nextProps$toolMessag = nextProps.toolMessage) === null || _nextProps$toolMessag === void 0 ? void 0 : _nextProps$toolMessag.content)) return false;
|
|
2363
|
-
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
2364
|
-
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
2365
|
-
return true;
|
|
2366
|
-
});
|
|
2367
|
-
/**
|
|
2368
|
-
* Hook that returns a function to render tool calls based on the render functions
|
|
2369
|
-
* defined in CopilotKitProvider.
|
|
2370
|
-
*
|
|
2371
|
-
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
2372
|
-
*/
|
|
2373
|
-
function useRenderToolCall$1() {
|
|
2374
|
-
var _config$agentId;
|
|
2375
|
-
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
2376
|
-
const config = useCopilotChatConfiguration();
|
|
2377
|
-
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;
|
|
2378
|
-
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
2379
|
-
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
2380
|
-
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
2381
|
-
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
2382
|
-
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
2383
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
2384
|
-
if (!renderConfig) return null;
|
|
2385
|
-
const RenderComponent = renderConfig.render;
|
|
2386
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
2387
|
-
toolCall,
|
|
2388
|
-
toolMessage,
|
|
2389
|
-
RenderComponent,
|
|
2390
|
-
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
2391
|
-
}, toolCall.id);
|
|
2392
|
-
}, [
|
|
2393
|
-
renderToolCalls,
|
|
2394
|
-
executingToolCallIds,
|
|
2395
|
-
agentId
|
|
2396
|
-
]);
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
//#endregion
|
|
2400
|
-
//#region src/v2/hooks/use-agent.tsx
|
|
2401
|
-
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
2402
|
-
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
2403
|
-
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
2404
|
-
UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
2405
|
-
return UseAgentUpdate;
|
|
2406
|
-
}({});
|
|
2407
|
-
const ALL_UPDATES = [
|
|
2408
|
-
UseAgentUpdate.OnMessagesChanged,
|
|
2409
|
-
UseAgentUpdate.OnStateChanged,
|
|
2410
|
-
UseAgentUpdate.OnRunStatusChanged
|
|
2411
|
-
];
|
|
2412
|
-
/**
|
|
2413
|
-
* Clone a registry agent for per-thread isolation.
|
|
2414
|
-
* Copies agent configuration (transport, headers, etc.) but resets conversation
|
|
2415
|
-
* state (messages, threadId, state) so each thread starts fresh.
|
|
2416
|
-
*/
|
|
2417
|
-
function cloneForThread(source, threadId, headers) {
|
|
2418
|
-
const clone = source.clone();
|
|
2419
|
-
if (clone === source) throw new Error(`useAgent: ${source.constructor.name}.clone() returned the same instance. clone() must return a new, independent object.`);
|
|
2420
|
-
clone.threadId = threadId;
|
|
2421
|
-
clone.setMessages([]);
|
|
2422
|
-
clone.setState({});
|
|
2423
|
-
if (clone instanceof _ag_ui_client.HttpAgent) clone.headers = { ...headers };
|
|
2424
|
-
return clone;
|
|
2425
|
-
}
|
|
2426
|
-
/**
|
|
2427
|
-
* Module-level WeakMap: registryAgent → (threadId → clone).
|
|
2428
|
-
* Shared across all useAgent() calls so that every component using the same
|
|
2429
|
-
* (agentId, threadId) pair receives the same agent instance. Using WeakMap
|
|
2430
|
-
* ensures the clone map is garbage-collected when the registry agent is
|
|
2431
|
-
* replaced (e.g. after reconnect or hot-reload).
|
|
2432
|
-
*/
|
|
2433
|
-
const globalThreadCloneMap = /* @__PURE__ */ new WeakMap();
|
|
2434
|
-
/**
|
|
2435
|
-
* Look up an existing per-thread clone without creating one.
|
|
2436
|
-
* Returns undefined when no clone has been created yet for this pair.
|
|
2437
|
-
*/
|
|
2438
|
-
function getThreadClone(registryAgent, threadId) {
|
|
2439
|
-
var _globalThreadCloneMap;
|
|
2440
|
-
if (!registryAgent || !threadId) return void 0;
|
|
2441
|
-
return (_globalThreadCloneMap = globalThreadCloneMap.get(registryAgent)) === null || _globalThreadCloneMap === void 0 ? void 0 : _globalThreadCloneMap.get(threadId);
|
|
2442
|
-
}
|
|
2443
|
-
function getOrCreateThreadClone(existing, threadId, headers) {
|
|
2444
|
-
let byThread = globalThreadCloneMap.get(existing);
|
|
2445
|
-
if (!byThread) {
|
|
2446
|
-
byThread = /* @__PURE__ */ new Map();
|
|
2447
|
-
globalThreadCloneMap.set(existing, byThread);
|
|
2448
|
-
}
|
|
2449
|
-
const cached = byThread.get(threadId);
|
|
2450
|
-
if (cached) return cached;
|
|
2451
|
-
const clone = cloneForThread(existing, threadId, headers);
|
|
2452
|
-
byThread.set(threadId, clone);
|
|
2453
|
-
return clone;
|
|
2454
|
-
}
|
|
2455
|
-
function useAgent({ agentId, threadId, updates, throttleMs } = {}) {
|
|
2456
|
-
var _agentId, _threadId;
|
|
2457
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2458
|
-
const { copilotkit } = useCopilotKit();
|
|
2459
|
-
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
2460
|
-
const chatConfig = useCopilotChatConfiguration();
|
|
2461
|
-
(_threadId = threadId) !== null && _threadId !== void 0 || (threadId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.threadId);
|
|
2462
|
-
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
2463
|
-
const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
|
|
2464
|
-
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
2465
|
-
const agent = (0, react.useMemo)(() => {
|
|
2466
|
-
var _copilotkit$agents;
|
|
2467
|
-
const cacheKey = threadId ? `${agentId}:${threadId}` : agentId;
|
|
2468
|
-
const existing = copilotkit.getAgent(agentId);
|
|
2469
|
-
if (existing) {
|
|
2470
|
-
provisionalAgentCache.current.delete(cacheKey);
|
|
2471
|
-
provisionalAgentCache.current.delete(agentId);
|
|
2472
|
-
if (!threadId) return existing;
|
|
2473
|
-
return getOrCreateThreadClone(existing, threadId, copilotkit.headers);
|
|
2474
|
-
}
|
|
2475
|
-
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
2476
|
-
const status = copilotkit.runtimeConnectionStatus;
|
|
2477
|
-
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
2478
|
-
const cached = provisionalAgentCache.current.get(cacheKey);
|
|
2479
|
-
if (cached) {
|
|
2480
|
-
cached.headers = { ...copilotkit.headers };
|
|
2481
|
-
return cached;
|
|
2482
|
-
}
|
|
2483
|
-
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
2484
|
-
runtimeUrl: copilotkit.runtimeUrl,
|
|
2485
|
-
agentId,
|
|
2486
|
-
transport: copilotkit.runtimeTransport,
|
|
2487
|
-
runtimeMode: "pending"
|
|
2488
|
-
});
|
|
2489
|
-
provisional.headers = { ...copilotkit.headers };
|
|
2490
|
-
if (threadId) provisional.threadId = threadId;
|
|
2491
|
-
provisionalAgentCache.current.set(cacheKey, provisional);
|
|
2492
|
-
return provisional;
|
|
2493
|
-
}
|
|
2494
|
-
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
2495
|
-
const cached = provisionalAgentCache.current.get(cacheKey);
|
|
2496
|
-
if (cached) {
|
|
2497
|
-
cached.headers = { ...copilotkit.headers };
|
|
2498
|
-
return cached;
|
|
2499
|
-
}
|
|
2500
|
-
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
2501
|
-
runtimeUrl: copilotkit.runtimeUrl,
|
|
2502
|
-
agentId,
|
|
2503
|
-
transport: copilotkit.runtimeTransport,
|
|
2504
|
-
runtimeMode: "pending"
|
|
2505
|
-
});
|
|
2506
|
-
provisional.headers = { ...copilotkit.headers };
|
|
2507
|
-
if (threadId) provisional.threadId = threadId;
|
|
2508
|
-
provisionalAgentCache.current.set(cacheKey, provisional);
|
|
2509
|
-
return provisional;
|
|
2510
|
-
}
|
|
2511
|
-
const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
|
|
2512
|
-
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
2513
|
-
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.");
|
|
2514
|
-
}, [
|
|
2515
|
-
agentId,
|
|
2516
|
-
threadId,
|
|
2517
|
-
copilotkit.agents,
|
|
2518
|
-
copilotkit.runtimeConnectionStatus,
|
|
2519
|
-
copilotkit.runtimeUrl,
|
|
2520
|
-
copilotkit.runtimeTransport,
|
|
2521
|
-
JSON.stringify(copilotkit.headers)
|
|
2522
|
-
]);
|
|
2523
|
-
(0, react.useEffect)(() => {
|
|
2524
|
-
if (updateFlags.length === 0) return;
|
|
2525
|
-
let active = true;
|
|
2526
|
-
const handlers = {};
|
|
2527
|
-
let batchScheduled = false;
|
|
2528
|
-
const batchedForceUpdate = () => {
|
|
2529
|
-
if (!active) return;
|
|
2530
|
-
if (!batchScheduled) {
|
|
2531
|
-
batchScheduled = true;
|
|
2532
|
-
queueMicrotask(() => {
|
|
2533
|
-
batchScheduled = false;
|
|
2534
|
-
if (active) forceUpdate();
|
|
2535
|
-
});
|
|
2438
|
+
},
|
|
2439
|
+
onToolExecutionEnd: ({ toolCallId }) => {
|
|
2440
|
+
setExecutingToolCallIds((prev) => {
|
|
2441
|
+
if (!prev.has(toolCallId)) return prev;
|
|
2442
|
+
const next = new Set(prev);
|
|
2443
|
+
next.delete(toolCallId);
|
|
2444
|
+
return next;
|
|
2445
|
+
});
|
|
2536
2446
|
}
|
|
2447
|
+
});
|
|
2448
|
+
return () => {
|
|
2449
|
+
subscription.unsubscribe();
|
|
2537
2450
|
};
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2451
|
+
}, [copilotkit]);
|
|
2452
|
+
const onErrorRef = (0, react.useRef)(onError);
|
|
2453
|
+
(0, react.useEffect)(() => {
|
|
2454
|
+
onErrorRef.current = onError;
|
|
2455
|
+
}, [onError]);
|
|
2456
|
+
(0, react.useEffect)(() => {
|
|
2457
|
+
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
2458
|
+
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
|
+
}
|
|
2463
|
+
} });
|
|
2547
2464
|
return () => {
|
|
2548
|
-
active = false;
|
|
2549
2465
|
subscription.unsubscribe();
|
|
2550
2466
|
};
|
|
2467
|
+
}, [copilotkit]);
|
|
2468
|
+
(0, react.useEffect)(() => {
|
|
2469
|
+
copilotkit.setRuntimeUrl(chatApiEndpoint);
|
|
2470
|
+
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
2471
|
+
copilotkit.setHeaders(mergedHeaders);
|
|
2472
|
+
copilotkit.setCredentials(credentials);
|
|
2473
|
+
copilotkit.setProperties(properties);
|
|
2474
|
+
copilotkit.setAgents__unsafe_dev_only(mergedAgents);
|
|
2475
|
+
copilotkit.setDebug(debug);
|
|
2551
2476
|
}, [
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2477
|
+
copilotkit,
|
|
2478
|
+
chatApiEndpoint,
|
|
2479
|
+
mergedHeaders,
|
|
2480
|
+
credentials,
|
|
2481
|
+
properties,
|
|
2482
|
+
mergedAgents,
|
|
2483
|
+
useSingleEndpoint,
|
|
2484
|
+
debug
|
|
2557
2485
|
]);
|
|
2486
|
+
const didMountRef = (0, react.useRef)(false);
|
|
2558
2487
|
(0, react.useEffect)(() => {
|
|
2559
|
-
if (
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2488
|
+
if (!didMountRef.current) return;
|
|
2489
|
+
copilotkit.setTools(allTools);
|
|
2490
|
+
}, [copilotkit, allTools]);
|
|
2491
|
+
(0, react.useEffect)(() => {
|
|
2492
|
+
if (!didMountRef.current) return;
|
|
2493
|
+
copilotkit.setRenderToolCalls(allRenderToolCalls);
|
|
2494
|
+
}, [copilotkit, allRenderToolCalls]);
|
|
2495
|
+
(0, react.useEffect)(() => {
|
|
2496
|
+
if (!didMountRef.current) return;
|
|
2497
|
+
copilotkit.setRenderActivityMessages(allActivityRenderers);
|
|
2498
|
+
}, [copilotkit, allActivityRenderers]);
|
|
2499
|
+
(0, react.useEffect)(() => {
|
|
2500
|
+
if (!didMountRef.current) return;
|
|
2501
|
+
copilotkit.setRenderCustomMessages(renderCustomMessagesList);
|
|
2502
|
+
}, [copilotkit, renderCustomMessagesList]);
|
|
2503
|
+
(0, react.useEffect)(() => {
|
|
2504
|
+
didMountRef.current = true;
|
|
2505
|
+
}, []);
|
|
2506
|
+
(0, react.useEffect)(() => {
|
|
2507
|
+
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
2508
|
+
}, [copilotkit, defaultThrottleMs]);
|
|
2509
|
+
const designSkill = (_openGenerativeUI$des = openGenerativeUI === null || openGenerativeUI === void 0 ? void 0 : openGenerativeUI.designSkill) !== null && _openGenerativeUI$des !== void 0 ? _openGenerativeUI$des : DEFAULT_DESIGN_SKILL;
|
|
2510
|
+
(0, react.useLayoutEffect)(() => {
|
|
2511
|
+
if (!copilotkit || !openGenUIActive) return;
|
|
2512
|
+
const id = copilotkit.addContext({
|
|
2513
|
+
description: "Design guidelines for the generateSandboxedUi tool. Follow these when building UI.",
|
|
2514
|
+
value: designSkill
|
|
2515
|
+
});
|
|
2516
|
+
return () => {
|
|
2517
|
+
copilotkit.removeContext(id);
|
|
2518
|
+
};
|
|
2519
|
+
}, [
|
|
2520
|
+
copilotkit,
|
|
2521
|
+
designSkill,
|
|
2522
|
+
openGenUIActive
|
|
2523
|
+
]);
|
|
2524
|
+
const sandboxFunctionsDescriptors = (0, react.useMemo)(() => {
|
|
2525
|
+
if (sandboxFunctionsList.length === 0) return null;
|
|
2526
|
+
return JSON.stringify(sandboxFunctionsList.map((fn) => ({
|
|
2527
|
+
name: fn.name,
|
|
2528
|
+
description: fn.description,
|
|
2529
|
+
parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema })
|
|
2530
|
+
})));
|
|
2531
|
+
}, [sandboxFunctionsList]);
|
|
2532
|
+
(0, react.useLayoutEffect)(() => {
|
|
2533
|
+
if (!copilotkit || !sandboxFunctionsDescriptors || !openGenUIActive) return;
|
|
2534
|
+
const id = copilotkit.addContext({
|
|
2535
|
+
description: "Sandbox functions available in generated sandboxed UI code. Call via: await Websandbox.connection.remote.<functionName>(args)",
|
|
2536
|
+
value: sandboxFunctionsDescriptors
|
|
2537
|
+
});
|
|
2538
|
+
return () => {
|
|
2539
|
+
copilotkit.removeContext(id);
|
|
2540
|
+
};
|
|
2541
|
+
}, [
|
|
2542
|
+
copilotkit,
|
|
2543
|
+
sandboxFunctionsDescriptors,
|
|
2544
|
+
openGenUIActive
|
|
2545
|
+
]);
|
|
2546
|
+
const contextValue = (0, react.useMemo)(() => ({
|
|
2547
|
+
copilotkit,
|
|
2548
|
+
executingToolCallIds
|
|
2549
|
+
}), [copilotkit, executingToolCallIds]);
|
|
2550
|
+
const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(null), []);
|
|
2551
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
|
|
2552
|
+
value: sandboxFunctionsList,
|
|
2553
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
|
|
2554
|
+
value: contextValue,
|
|
2555
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
|
|
2556
|
+
value: licenseContextValue,
|
|
2557
|
+
children: [
|
|
2558
|
+
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
2559
|
+
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
2560
|
+
catalog: a2ui === null || a2ui === void 0 ? void 0 : a2ui.catalog,
|
|
2561
|
+
includeSchema: a2ui === null || a2ui === void 0 ? void 0 : a2ui.includeSchema
|
|
2562
|
+
}),
|
|
2563
|
+
children,
|
|
2564
|
+
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
2565
|
+
core: copilotkit,
|
|
2566
|
+
defaultAnchor: inspectorDefaultAnchor
|
|
2567
|
+
}) : null,
|
|
2568
|
+
runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
|
|
2569
|
+
runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
|
|
2570
|
+
runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
|
|
2571
|
+
runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
|
|
2572
|
+
]
|
|
2573
|
+
})
|
|
2574
|
+
})
|
|
2575
|
+
});
|
|
2576
|
+
};
|
|
2563
2577
|
|
|
2564
2578
|
//#endregion
|
|
2565
2579
|
//#region src/v2/hooks/use-render-custom-messages.tsx
|
|
@@ -2574,13 +2588,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2574
2588
|
return aHasAgent ? -1 : 1;
|
|
2575
2589
|
});
|
|
2576
2590
|
return function(params) {
|
|
2577
|
-
var _copilotkit$getRunIdF
|
|
2591
|
+
var _copilotkit$getRunIdF;
|
|
2578
2592
|
if (!customMessageRenderers.length) return null;
|
|
2579
2593
|
const { message, position } = params;
|
|
2580
2594
|
const resolvedRunId = (_copilotkit$getRunIdF = copilotkit.getRunIdForMessage(agentId, threadId, message.id)) !== null && _copilotkit$getRunIdF !== void 0 ? _copilotkit$getRunIdF : copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
|
|
2581
2595
|
const runId = resolvedRunId !== null && resolvedRunId !== void 0 ? resolvedRunId : `missing-run-id:${message.id}`;
|
|
2582
|
-
const
|
|
2583
|
-
const agent = (_getThreadClone = getThreadClone(registryAgent, threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
|
|
2596
|
+
const agent = copilotkit.getAgent(agentId);
|
|
2584
2597
|
if (!agent) return null;
|
|
2585
2598
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
2586
2599
|
const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
|
|
@@ -2637,8 +2650,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2637
2650
|
tool.name,
|
|
2638
2651
|
tool.available,
|
|
2639
2652
|
copilotkit,
|
|
2640
|
-
extraDeps
|
|
2641
|
-
...extraDeps
|
|
2653
|
+
JSON.stringify(extraDeps)
|
|
2642
2654
|
]);
|
|
2643
2655
|
}
|
|
2644
2656
|
|
|
@@ -2708,6 +2720,120 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2708
2720
|
]);
|
|
2709
2721
|
}
|
|
2710
2722
|
|
|
2723
|
+
//#endregion
|
|
2724
|
+
//#region src/v2/hooks/use-agent.tsx
|
|
2725
|
+
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
2726
|
+
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
2727
|
+
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
2728
|
+
UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
2729
|
+
return UseAgentUpdate;
|
|
2730
|
+
}({});
|
|
2731
|
+
const ALL_UPDATES = [
|
|
2732
|
+
UseAgentUpdate.OnMessagesChanged,
|
|
2733
|
+
UseAgentUpdate.OnStateChanged,
|
|
2734
|
+
UseAgentUpdate.OnRunStatusChanged
|
|
2735
|
+
];
|
|
2736
|
+
function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
2737
|
+
var _agentId;
|
|
2738
|
+
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2739
|
+
const { copilotkit } = useCopilotKit();
|
|
2740
|
+
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
2741
|
+
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
2742
|
+
const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
|
|
2743
|
+
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
2744
|
+
const agent = (0, react.useMemo)(() => {
|
|
2745
|
+
var _copilotkit$agents;
|
|
2746
|
+
const existing = copilotkit.getAgent(agentId);
|
|
2747
|
+
if (existing) {
|
|
2748
|
+
provisionalAgentCache.current.delete(agentId);
|
|
2749
|
+
return existing;
|
|
2750
|
+
}
|
|
2751
|
+
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
2752
|
+
const status = copilotkit.runtimeConnectionStatus;
|
|
2753
|
+
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
2754
|
+
const cached = provisionalAgentCache.current.get(agentId);
|
|
2755
|
+
if (cached) {
|
|
2756
|
+
cached.headers = { ...copilotkit.headers };
|
|
2757
|
+
return cached;
|
|
2758
|
+
}
|
|
2759
|
+
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
2760
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
2761
|
+
agentId,
|
|
2762
|
+
transport: copilotkit.runtimeTransport,
|
|
2763
|
+
runtimeMode: "pending"
|
|
2764
|
+
});
|
|
2765
|
+
provisional.headers = { ...copilotkit.headers };
|
|
2766
|
+
provisionalAgentCache.current.set(agentId, provisional);
|
|
2767
|
+
return provisional;
|
|
2768
|
+
}
|
|
2769
|
+
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
2770
|
+
const cached = provisionalAgentCache.current.get(agentId);
|
|
2771
|
+
if (cached) {
|
|
2772
|
+
cached.headers = { ...copilotkit.headers };
|
|
2773
|
+
return cached;
|
|
2774
|
+
}
|
|
2775
|
+
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
2776
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
2777
|
+
agentId,
|
|
2778
|
+
transport: copilotkit.runtimeTransport,
|
|
2779
|
+
runtimeMode: "pending"
|
|
2780
|
+
});
|
|
2781
|
+
provisional.headers = { ...copilotkit.headers };
|
|
2782
|
+
provisionalAgentCache.current.set(agentId, provisional);
|
|
2783
|
+
return provisional;
|
|
2784
|
+
}
|
|
2785
|
+
const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
|
|
2786
|
+
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
2787
|
+
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
|
+
}, [
|
|
2789
|
+
agentId,
|
|
2790
|
+
copilotkit.agents,
|
|
2791
|
+
copilotkit.runtimeConnectionStatus,
|
|
2792
|
+
copilotkit.runtimeUrl,
|
|
2793
|
+
copilotkit.runtimeTransport,
|
|
2794
|
+
JSON.stringify(copilotkit.headers)
|
|
2795
|
+
]);
|
|
2796
|
+
(0, react.useEffect)(() => {
|
|
2797
|
+
if (updateFlags.length === 0) return;
|
|
2798
|
+
let active = true;
|
|
2799
|
+
const handlers = {};
|
|
2800
|
+
let batchScheduled = false;
|
|
2801
|
+
const batchedForceUpdate = () => {
|
|
2802
|
+
if (!active) return;
|
|
2803
|
+
if (!batchScheduled) {
|
|
2804
|
+
batchScheduled = true;
|
|
2805
|
+
queueMicrotask(() => {
|
|
2806
|
+
batchScheduled = false;
|
|
2807
|
+
if (active) forceUpdate();
|
|
2808
|
+
});
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = batchedForceUpdate;
|
|
2812
|
+
if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
|
|
2813
|
+
if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
|
|
2814
|
+
handlers.onRunInitialized = batchedForceUpdate;
|
|
2815
|
+
handlers.onRunFinalized = batchedForceUpdate;
|
|
2816
|
+
handlers.onRunFailed = batchedForceUpdate;
|
|
2817
|
+
handlers.onRunErrorEvent = batchedForceUpdate;
|
|
2818
|
+
}
|
|
2819
|
+
const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
|
|
2820
|
+
return () => {
|
|
2821
|
+
active = false;
|
|
2822
|
+
subscription.unsubscribe();
|
|
2823
|
+
};
|
|
2824
|
+
}, [
|
|
2825
|
+
agent,
|
|
2826
|
+
forceUpdate,
|
|
2827
|
+
throttleMs,
|
|
2828
|
+
providerThrottleMs,
|
|
2829
|
+
updateFlags
|
|
2830
|
+
]);
|
|
2831
|
+
(0, react.useEffect)(() => {
|
|
2832
|
+
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
2833
|
+
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
2834
|
+
return { agent };
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2711
2837
|
//#endregion
|
|
2712
2838
|
//#region src/v2/hooks/use-suggestions.tsx
|
|
2713
2839
|
function useSuggestions({ agentId } = {}) {
|
|
@@ -5299,10 +5425,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5299
5425
|
const existingConfig = useCopilotChatConfiguration();
|
|
5300
5426
|
const [agentAvailable, setAgentAvailable] = (0, react.useState)(false);
|
|
5301
5427
|
const resolvedAgentId = (_existingConfig$agent = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId) !== null && _existingConfig$agent !== void 0 ? _existingConfig$agent : "default";
|
|
5302
|
-
const { agent } = useAgent({
|
|
5303
|
-
agentId: resolvedAgentId,
|
|
5304
|
-
threadId: existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.threadId
|
|
5305
|
-
});
|
|
5428
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
5306
5429
|
const lastConnectedAgentRef = (0, react.useRef)(null);
|
|
5307
5430
|
(0, react.useEffect)(() => {
|
|
5308
5431
|
let detached = false;
|