@copilotkit/react-core 2.0.0-rc.31 → 2.0.0-rc.32
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/README.md +1 -1
- package/dist/MarkdownRendererContext-CPfNVyde.d.mts +241 -0
- package/dist/MarkdownRendererContext-CPfNVyde.d.mts.map +1 -0
- package/dist/MarkdownRendererContext-iOl2pj9l.d.cts +241 -0
- package/dist/MarkdownRendererContext-iOl2pj9l.d.cts.map +1 -0
- package/dist/MarkdownSurfaces-BFoO6wSB.cjs +1650 -0
- package/dist/MarkdownSurfaces-BFoO6wSB.cjs.map +1 -0
- package/dist/MarkdownSurfaces-BQ1HGCzB.mjs +1442 -0
- package/dist/MarkdownSurfaces-BQ1HGCzB.mjs.map +1 -0
- package/dist/generative-ui.cjs +687 -2964
- package/dist/generative-ui.cjs.map +1 -1
- package/dist/generative-ui.d.cts +2478 -2683
- package/dist/generative-ui.d.cts.map +1 -1
- package/dist/generative-ui.d.mts +2477 -2682
- package/dist/generative-ui.d.mts.map +1 -1
- package/dist/generative-ui.mjs +299 -2585
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/index.cjs +26 -1367
- 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 +11 -1352
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +124 -3358
- package/dist/index.umd.js.map +1 -1
- package/package.json +9 -9
- package/dist/MarkdownRendererContext-BX26QLwl.d.cts +0 -937
- package/dist/MarkdownRendererContext-BX26QLwl.d.cts.map +0 -1
- package/dist/MarkdownRendererContext-DAOMewji.d.mts +0 -937
- package/dist/MarkdownRendererContext-DAOMewji.d.mts.map +0 -1
- package/dist/MarkdownSurfaces-BbrHcSHN.cjs +0 -3903
- package/dist/MarkdownSurfaces-BbrHcSHN.cjs.map +0 -1
- package/dist/MarkdownSurfaces-DQbRS91-.mjs +0 -3587
- package/dist/MarkdownSurfaces-DQbRS91-.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_MarkdownSurfaces = require('./MarkdownSurfaces-
|
|
4
|
+
const require_MarkdownSurfaces = require('./MarkdownSurfaces-BFoO6wSB.cjs');
|
|
5
5
|
let _copilotkit_core = require("@copilotkit/core");
|
|
6
6
|
let react = require("react");
|
|
7
7
|
react = require_MarkdownSurfaces.__toESM(react);
|
|
@@ -18,7 +18,8 @@ let _copilotkit_a2ui_renderer = require("@copilotkit/a2ui-renderer");
|
|
|
18
18
|
let _copilotkit_a2ui_renderer_engine_core = require("@copilotkit/a2ui-renderer/engine-core");
|
|
19
19
|
let zod = require("zod");
|
|
20
20
|
zod = require_MarkdownSurfaces.__toESM(zod);
|
|
21
|
-
let
|
|
21
|
+
let _copilotkit_core_generative_ui = require("@copilotkit/core/generative-ui");
|
|
22
|
+
let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
|
|
22
23
|
let _copilotkit_a2ui_renderer_catalog_schema = require("@copilotkit/a2ui-renderer/catalog-schema");
|
|
23
24
|
let _copilotkit_core_styles = require("@copilotkit/core/styles");
|
|
24
25
|
let _radix_ui_react_popover = require("@radix-ui/react-popover");
|
|
@@ -823,7 +824,7 @@ function ɵuseOwnedCore(ref, create) {
|
|
|
823
824
|
|
|
824
825
|
//#endregion
|
|
825
826
|
//#region package.json
|
|
826
|
-
var version$1 = "2.0.0-rc.
|
|
827
|
+
var version$1 = "2.0.0-rc.32";
|
|
827
828
|
|
|
828
829
|
//#endregion
|
|
829
830
|
//#region src/components/CopilotKitInspector.tsx
|
|
@@ -1470,550 +1471,6 @@ function A2UIBuiltInToolCallRenderer() {
|
|
|
1470
1471
|
return null;
|
|
1471
1472
|
}
|
|
1472
1473
|
|
|
1473
|
-
//#endregion
|
|
1474
|
-
//#region src/generative-ui/action-message.ts
|
|
1475
|
-
/** Context keys that supply the message's first line, in priority order. */
|
|
1476
|
-
const TEXT_KEYS = ["message", "label"];
|
|
1477
|
-
function isNonEmptyString(value) {
|
|
1478
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
1479
|
-
}
|
|
1480
|
-
/** `choose_plan`, `choose-plan` and `choosePlan` all become "Choose plan". */
|
|
1481
|
-
function humanize(name) {
|
|
1482
|
-
const spaced = name.replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim();
|
|
1483
|
-
return spaced.charAt(0).toUpperCase() + spaced.slice(1).toLowerCase();
|
|
1484
|
-
}
|
|
1485
|
-
function formatContextValue(value) {
|
|
1486
|
-
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Turns a user event that no function handles into the text of a visible
|
|
1490
|
-
* user message.
|
|
1491
|
-
*
|
|
1492
|
-
* The first line is, in order: `userMessage`, `context.message`,
|
|
1493
|
-
* `context.label`, the label of the source component (from `resolveLabel`),
|
|
1494
|
-
* or the event name made readable (`choose_plan` becomes "Choose plan").
|
|
1495
|
-
* Each other context field follows as one `key: value` line. Objects are
|
|
1496
|
-
* written as JSON. `null` and `undefined` fields are skipped.
|
|
1497
|
-
*
|
|
1498
|
-
* @param event - The user event, as sent by a surface.
|
|
1499
|
-
* @param resolveLabel - Finds the visible label of a component by id. Build
|
|
1500
|
-
* one with {@link createComponentLabelResolver}.
|
|
1501
|
-
*
|
|
1502
|
-
* @example
|
|
1503
|
-
* ```ts
|
|
1504
|
-
* buildActionMessageText({
|
|
1505
|
-
* name: "choose_plan",
|
|
1506
|
-
* surfaceId: "plans",
|
|
1507
|
-
* componentId: "team-button",
|
|
1508
|
-
* userMessage: "I pick the Team plan",
|
|
1509
|
-
* context: { seats: 12 },
|
|
1510
|
-
* });
|
|
1511
|
-
* // "I pick the Team plan\n\nseats: 12"
|
|
1512
|
-
* ```
|
|
1513
|
-
*/
|
|
1514
|
-
function buildActionMessageText(event, resolveLabel) {
|
|
1515
|
-
const { context, userMessage } = event;
|
|
1516
|
-
const explicit = [userMessage, ...TEXT_KEYS.map((key) => context[key])].find(isNonEmptyString);
|
|
1517
|
-
const resolved = explicit ? void 0 : resolveLabel?.(event.componentId);
|
|
1518
|
-
const head = explicit ?? (isNonEmptyString(resolved) ? resolved.trim() : humanize(event.name));
|
|
1519
|
-
const lines = Object.entries(context).filter(([key, value]) => !TEXT_KEYS.includes(key) && value !== void 0 && value !== null).map(([key, value]) => `${key}: ${formatContextValue(value)}`);
|
|
1520
|
-
return lines.length > 0 ? `${head}\n\n${lines.join("\n")}` : head;
|
|
1521
|
-
}
|
|
1522
|
-
function ownText(component) {
|
|
1523
|
-
if (!component) return void 0;
|
|
1524
|
-
if (isNonEmptyString(component.label)) return component.label;
|
|
1525
|
-
if (isNonEmptyString(component.text)) return component.text;
|
|
1526
|
-
}
|
|
1527
|
-
function childIds(component) {
|
|
1528
|
-
const { child, children } = component;
|
|
1529
|
-
const single = typeof child === "string" ? [child] : [];
|
|
1530
|
-
const multiple = Array.isArray(children) ? children.filter((id) => typeof id === "string") : [];
|
|
1531
|
-
return [...single, ...multiple];
|
|
1532
|
-
}
|
|
1533
|
-
/** The components that an operation adds, inline or in an update. */
|
|
1534
|
-
function componentsOf(operation) {
|
|
1535
|
-
if ("createSurface" in operation) return operation.createSurface.components ?? [];
|
|
1536
|
-
if ("updateComponents" in operation) return operation.updateComponents.components;
|
|
1537
|
-
return [];
|
|
1538
|
-
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Builds a function that finds the visible label of a component on a surface.
|
|
1541
|
-
*
|
|
1542
|
-
* The label is the component's own string `label`, else its string `text`,
|
|
1543
|
-
* else the first `child` or `children` component that has a string `label`
|
|
1544
|
-
* or `text`. When a component id is defined more than once, the last
|
|
1545
|
-
* definition wins, as in the renderer.
|
|
1546
|
-
*
|
|
1547
|
-
* @param operations - The committed operations of the surface.
|
|
1548
|
-
*
|
|
1549
|
-
* @example
|
|
1550
|
-
* ```ts
|
|
1551
|
-
* const resolveLabel = createComponentLabelResolver(surface.operations);
|
|
1552
|
-
* buildActionMessageText(event, resolveLabel);
|
|
1553
|
-
* ```
|
|
1554
|
-
*/
|
|
1555
|
-
function createComponentLabelResolver(operations) {
|
|
1556
|
-
const byId = /* @__PURE__ */ new Map();
|
|
1557
|
-
for (const operation of operations) {
|
|
1558
|
-
const components = componentsOf(operation);
|
|
1559
|
-
for (const component of components) byId.set(component.id, component);
|
|
1560
|
-
}
|
|
1561
|
-
return (componentId) => {
|
|
1562
|
-
const component = byId.get(componentId);
|
|
1563
|
-
if (!component) return void 0;
|
|
1564
|
-
const own = ownText(component);
|
|
1565
|
-
if (own) return own;
|
|
1566
|
-
const ids = childIds(component);
|
|
1567
|
-
for (const id of ids) {
|
|
1568
|
-
const text = ownText(byId.get(id));
|
|
1569
|
-
if (text) return text;
|
|
1570
|
-
}
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
|
-
//#endregion
|
|
1575
|
-
//#region src/generative-ui/manifest.ts
|
|
1576
|
-
/**
|
|
1577
|
-
* The built-in functions (the A2UI basic catalog plus calc and series) as
|
|
1578
|
-
* manifest entries. Their args are described by the short signature, not
|
|
1579
|
-
* by a full JSON Schema: the renderer checks them when they run. An app
|
|
1580
|
-
* function of the same name replaces the entry.
|
|
1581
|
-
*/
|
|
1582
|
-
function builtInFunctionManifests() {
|
|
1583
|
-
return Object.fromEntries(Object.entries(_copilotkit_shared.GENERATIVE_UI_FUNCTIONS).map(([name, fn]) => [name, {
|
|
1584
|
-
description: fn.description,
|
|
1585
|
-
parameters: {
|
|
1586
|
-
type: "object",
|
|
1587
|
-
description: fn.parameters
|
|
1588
|
-
},
|
|
1589
|
-
returnType: fn.returnType,
|
|
1590
|
-
allowedCallers: fn.allowedCallers,
|
|
1591
|
-
...fn.requiresUserActivation ? { requiresUserActivation: true } : {}
|
|
1592
|
-
}]));
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* The manifest of a catalog, with no React runtime: the components of `ui`,
|
|
1596
|
-
* the built-in functions (minus the names the app declares) and
|
|
1597
|
-
* `options.functions`, the chat target and `options.targets`, and
|
|
1598
|
-
* `options.surfaces`. `buildGenerativeUIManifest` builds the per-run
|
|
1599
|
-
* manifest with it; tools that run outside React use it directly.
|
|
1600
|
-
*
|
|
1601
|
-
* @example
|
|
1602
|
-
* ```ts
|
|
1603
|
-
* const manifest = buildCatalogManifest(standardUI);
|
|
1604
|
-
* manifest.targets; // [{ id: "chat", kind: "chat" }]
|
|
1605
|
-
* ```
|
|
1606
|
-
*/
|
|
1607
|
-
function buildCatalogManifest(ui, options = {}) {
|
|
1608
|
-
return {
|
|
1609
|
-
catalogId: ui.id,
|
|
1610
|
-
catalogIds: require_MarkdownSurfaces.catalogIdsOf(ui),
|
|
1611
|
-
components: (0, _copilotkit_shared.applyDescriptionOverrides)({ components: ui.manifestComponents }, (0, _copilotkit_shared.defaultGenerativeUIPromptSpec)().descriptions).manifest.components,
|
|
1612
|
-
functions: {
|
|
1613
|
-
...Object.fromEntries(Object.entries(builtInFunctionManifests()).filter(([name]) => !ui.functions.has(name))),
|
|
1614
|
-
...options.functions
|
|
1615
|
-
},
|
|
1616
|
-
targets: [{
|
|
1617
|
-
id: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET,
|
|
1618
|
-
kind: "chat"
|
|
1619
|
-
}, ...options.targets ?? []],
|
|
1620
|
-
surfaces: options.surfaces ?? {}
|
|
1621
|
-
};
|
|
1622
|
-
}
|
|
1623
|
-
/**
|
|
1624
|
-
* Builds the per-run manifest. Never contains handlers or renderers.
|
|
1625
|
-
*
|
|
1626
|
-
* - `functions`: the built-in functions, then the declared functions with
|
|
1627
|
-
* exactly one mounted handler.
|
|
1628
|
-
* - `targets`: the chat first, then each mounted `<GenerativeUISurface>`,
|
|
1629
|
-
* with its `description` and its `components` when it has them.
|
|
1630
|
-
*/
|
|
1631
|
-
function buildGenerativeUIManifest(runtime, threadId) {
|
|
1632
|
-
const { ui, manager, dispatcher } = runtime;
|
|
1633
|
-
const inlineTargets = manager.getMountedTargets().filter((target) => target.id !== _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET).map(({ id, ...rest }) => ({
|
|
1634
|
-
id,
|
|
1635
|
-
kind: "inline",
|
|
1636
|
-
...rest
|
|
1637
|
-
}));
|
|
1638
|
-
return buildCatalogManifest(ui, {
|
|
1639
|
-
functions: dispatcher.listExposed(),
|
|
1640
|
-
targets: inlineTargets,
|
|
1641
|
-
surfaces: threadId ? manager.describeSurfaces(threadId) : {}
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
/**
|
|
1645
|
-
* Builds the envelope that a run sends as `forwardedProps.copilotkit.ui`,
|
|
1646
|
-
* from the per-run manifest. It has the A2UI v1.0 renderer capabilities
|
|
1647
|
-
* shape: one inline catalog with the id of the UI, and the CopilotKit data
|
|
1648
|
-
* in `metadata.extensions`.
|
|
1649
|
-
*
|
|
1650
|
-
* The inline catalog has no `components` only for the markdown transport
|
|
1651
|
-
* with `includeCatalog: false`. It has `instructions` for the markdown
|
|
1652
|
-
* transport, or when given.
|
|
1653
|
-
*
|
|
1654
|
-
* @param runtime - The generative UI runtime of the provider.
|
|
1655
|
-
* @param threadId - The thread of the run. Its surfaces go in `copilotkit_surfaces`.
|
|
1656
|
-
* @param options - The transport and what to send.
|
|
1657
|
-
*
|
|
1658
|
-
* @example
|
|
1659
|
-
* ```ts
|
|
1660
|
-
* const envelope = buildGenerativeUIEnvelope(runtime, agent.threadId, {
|
|
1661
|
-
* transport: "tool",
|
|
1662
|
-
* includeCatalog: true,
|
|
1663
|
-
* contextSent: false,
|
|
1664
|
-
* });
|
|
1665
|
-
* envelope["1.0"].supportedCatalogIds; // [runtime.ui.id]
|
|
1666
|
-
* ```
|
|
1667
|
-
*/
|
|
1668
|
-
function buildGenerativeUIEnvelope(runtime, threadId, options) {
|
|
1669
|
-
const { transport, includeCatalog, contextSent, action } = options;
|
|
1670
|
-
const manifest = buildGenerativeUIManifest(runtime, threadId);
|
|
1671
|
-
const instructions = options.instructions ?? (transport === "markdown" ? (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest)) : void 0);
|
|
1672
|
-
const omitComponents = transport === "markdown" && !includeCatalog;
|
|
1673
|
-
return {
|
|
1674
|
-
"1.0": {
|
|
1675
|
-
supportedCatalogIds: manifest.catalogIds ?? [manifest.catalogId],
|
|
1676
|
-
inlineCatalogs: [{
|
|
1677
|
-
catalogId: manifest.catalogId,
|
|
1678
|
-
protocolVersion: "1.0",
|
|
1679
|
-
...omitComponents ? {} : { components: manifest.components },
|
|
1680
|
-
functions: manifest.functions,
|
|
1681
|
-
...instructions === void 0 ? {} : { instructions }
|
|
1682
|
-
}]
|
|
1683
|
-
},
|
|
1684
|
-
metadata: { extensions: {
|
|
1685
|
-
copilotkit_format: _copilotkit_shared.COPILOTKIT_UI_ENVELOPE_FORMAT,
|
|
1686
|
-
copilotkit_transport: transport,
|
|
1687
|
-
copilotkit_targets: manifest.targets,
|
|
1688
|
-
copilotkit_surfaces: manifest.surfaces,
|
|
1689
|
-
copilotkit_contextSent: contextSent,
|
|
1690
|
-
...action === void 0 ? {} : { copilotkit_action: action }
|
|
1691
|
-
} }
|
|
1692
|
-
};
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
//#endregion
|
|
1696
|
-
//#region src/generative-ui/debug-source.ts
|
|
1697
|
-
/**
|
|
1698
|
-
* What a run of `threadId` sends: its envelope, and the text that goes into
|
|
1699
|
-
* the prompt of the model because of it.
|
|
1700
|
-
*
|
|
1701
|
-
* - Tool transport: the runtime adds the `render_ui` guide. It builds it
|
|
1702
|
-
* from the envelope with `buildGenerativeUIPrompt`, as done here.
|
|
1703
|
-
* - Markdown transport: the provider sends the guideline and the compact
|
|
1704
|
-
* schema as context entries. With `sendContext: false`, the backend builds
|
|
1705
|
-
* its own prompt, usually from the `instructions` of the envelope.
|
|
1706
|
-
*/
|
|
1707
|
-
function describeGenerativeUIRun(runtime, threadId, options) {
|
|
1708
|
-
const envelope = buildGenerativeUIEnvelope(runtime, threadId, options);
|
|
1709
|
-
if (options.transport === "tool") return {
|
|
1710
|
-
envelope,
|
|
1711
|
-
prompt: [{
|
|
1712
|
-
title: "render_ui guide",
|
|
1713
|
-
source: "runtime",
|
|
1714
|
-
text: (0, _copilotkit_shared.buildGenerativeUIPrompt)((0, _copilotkit_shared.envelopeToManifest)(envelope))
|
|
1715
|
-
}]
|
|
1716
|
-
};
|
|
1717
|
-
const manifest = buildGenerativeUIManifest(runtime, threadId);
|
|
1718
|
-
if (!options.contextSent) return {
|
|
1719
|
-
envelope,
|
|
1720
|
-
prompt: [{
|
|
1721
|
-
title: "Envelope instructions",
|
|
1722
|
-
source: "backend",
|
|
1723
|
-
text: (0, _copilotkit_shared.envelopeToManifest)(envelope).instructions ?? ""
|
|
1724
|
-
}]
|
|
1725
|
-
};
|
|
1726
|
-
const guideline = (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest));
|
|
1727
|
-
const schema = (0, _copilotkit_shared.renderGenerativeUISchema)(manifest, (0, _copilotkit_shared.defaultGenerativeUIPromptSpec)().schema.markdown);
|
|
1728
|
-
return {
|
|
1729
|
-
envelope,
|
|
1730
|
-
prompt: [{
|
|
1731
|
-
title: "Markdown guideline",
|
|
1732
|
-
source: "context",
|
|
1733
|
-
text: guideline
|
|
1734
|
-
}, {
|
|
1735
|
-
title: "Component schema",
|
|
1736
|
-
source: "context",
|
|
1737
|
-
text: schema
|
|
1738
|
-
}]
|
|
1739
|
-
};
|
|
1740
|
-
}
|
|
1741
|
-
/** The declared functions, with the JSON Schema of their parameters. */
|
|
1742
|
-
function debugFunctions(runtime) {
|
|
1743
|
-
const functions = {};
|
|
1744
|
-
for (const [name, declared] of runtime.ui.functions) {
|
|
1745
|
-
let parameters = {};
|
|
1746
|
-
try {
|
|
1747
|
-
parameters = require_MarkdownSurfaces.toJsonSchema(declared.parameters);
|
|
1748
|
-
} catch {}
|
|
1749
|
-
functions[name] = {
|
|
1750
|
-
...declared.description ? { description: declared.description } : {},
|
|
1751
|
-
parameters,
|
|
1752
|
-
handlers: runtime.dispatcher.handlerCount(name)
|
|
1753
|
-
};
|
|
1754
|
-
}
|
|
1755
|
-
return functions;
|
|
1756
|
-
}
|
|
1757
|
-
/**
|
|
1758
|
-
* The debug source that the provider gives core for the inspector. It builds
|
|
1759
|
-
* a snapshot only when the inspector reads one.
|
|
1760
|
-
*
|
|
1761
|
-
* @param runtime - The generative UI parts of the provider.
|
|
1762
|
-
* @param getOptions - The envelope options and agent ids of the current config.
|
|
1763
|
-
* @returns The source, and `recordRun` for each run start.
|
|
1764
|
-
*/
|
|
1765
|
-
function createGenerativeUIDebugSource(runtime, getOptions) {
|
|
1766
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1767
|
-
let lastRun;
|
|
1768
|
-
const notify = () => {
|
|
1769
|
-
for (const listener of [...listeners]) listener();
|
|
1770
|
-
};
|
|
1771
|
-
return {
|
|
1772
|
-
source: {
|
|
1773
|
-
getSnapshot() {
|
|
1774
|
-
const { options, agentIds } = getOptions();
|
|
1775
|
-
const threadId = runtime.manager.getActiveThread();
|
|
1776
|
-
const manifest = buildGenerativeUIManifest(runtime, threadId);
|
|
1777
|
-
return {
|
|
1778
|
-
catalogId: runtime.ui.id,
|
|
1779
|
-
transport: options.transport,
|
|
1780
|
-
...agentIds ? { agentIds } : {},
|
|
1781
|
-
components: runtime.ui.manifestComponents,
|
|
1782
|
-
componentCatalogs: Object.fromEntries(require_MarkdownSurfaces.componentCatalogIds(runtime.ui)),
|
|
1783
|
-
functions: debugFunctions(runtime),
|
|
1784
|
-
state: { ...runtime.manager.getState() },
|
|
1785
|
-
targets: manifest.targets,
|
|
1786
|
-
activeThreadId: threadId,
|
|
1787
|
-
surfaces: runtime.manager.debugSurfaces(),
|
|
1788
|
-
lastRun,
|
|
1789
|
-
nextRun: {
|
|
1790
|
-
agentId: void 0,
|
|
1791
|
-
threadId,
|
|
1792
|
-
...describeGenerativeUIRun(runtime, threadId, options)
|
|
1793
|
-
}
|
|
1794
|
-
};
|
|
1795
|
-
},
|
|
1796
|
-
subscribe(listener) {
|
|
1797
|
-
listeners.add(listener);
|
|
1798
|
-
const unsubscribe = runtime.manager.subscribe(listener);
|
|
1799
|
-
return () => {
|
|
1800
|
-
listeners.delete(listener);
|
|
1801
|
-
unsubscribe();
|
|
1802
|
-
};
|
|
1803
|
-
}
|
|
1804
|
-
},
|
|
1805
|
-
recordRun(run) {
|
|
1806
|
-
lastRun = run;
|
|
1807
|
-
notify();
|
|
1808
|
-
}
|
|
1809
|
-
};
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
//#endregion
|
|
1813
|
-
//#region src/generative-ui/dispatcher.ts
|
|
1814
|
-
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
1815
|
-
/**
|
|
1816
|
-
* Creates the registry of functions that generated UI may call.
|
|
1817
|
-
*
|
|
1818
|
-
* A function is callable when it is declared in `getDeclared()` and exactly
|
|
1819
|
-
* one handler is mounted for it with `register`. Names are resolved at call
|
|
1820
|
-
* time and fail closed. Nothing is sent to the agent.
|
|
1821
|
-
* Neither `invoke` nor `listExposed` throws.
|
|
1822
|
-
*
|
|
1823
|
-
* @param options.getDeclared - Returns the declared functions.
|
|
1824
|
-
* @param options.onError - Gets each failed call.
|
|
1825
|
-
*
|
|
1826
|
-
* @example
|
|
1827
|
-
* ```ts
|
|
1828
|
-
* const dispatcher = createGenerativeUIDispatcher({
|
|
1829
|
-
* getDeclared: () => new Map(Object.entries(ui.functions)),
|
|
1830
|
-
* });
|
|
1831
|
-
* const unregister = dispatcher.register("addToCart", handlerRef);
|
|
1832
|
-
* await dispatcher.invoke("addToCart", { productId: "p1" }, origin);
|
|
1833
|
-
* unregister();
|
|
1834
|
-
* ```
|
|
1835
|
-
*/
|
|
1836
|
-
/**
|
|
1837
|
-
* True while the browser counts the current task as user-activated (a
|
|
1838
|
-
* click, a key press). Where the API is missing (older browsers, test
|
|
1839
|
-
* environments), the gesture is assumed.
|
|
1840
|
-
*/
|
|
1841
|
-
function hasUserActivation() {
|
|
1842
|
-
if (typeof navigator === "undefined") return true;
|
|
1843
|
-
const activation = navigator.userActivation;
|
|
1844
|
-
return activation === void 0 || activation.isActive;
|
|
1845
|
-
}
|
|
1846
|
-
/**
|
|
1847
|
-
* The permissions of a declared function as the manifest states them: the
|
|
1848
|
-
* callers always written out, so a reader needs no default.
|
|
1849
|
-
*/
|
|
1850
|
-
function permissionsOf(fn) {
|
|
1851
|
-
const callers = (0, _copilotkit_shared.functionCallers)(fn);
|
|
1852
|
-
return {
|
|
1853
|
-
allowedCallers: callers.renderer && callers.agent ? "rendererOrAgent" : callers.agent ? "agentOnly" : "rendererOnly",
|
|
1854
|
-
...fn.requiresUserActivation ? { requiresUserActivation: true } : {}
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
function createGenerativeUIDispatcher(options) {
|
|
1858
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
1859
|
-
const resolveUnchecked = (name) => {
|
|
1860
|
-
const declared = options.getDeclared().get(name);
|
|
1861
|
-
if (!declared) return {
|
|
1862
|
-
ok: false,
|
|
1863
|
-
error: new require_MarkdownSurfaces.GenerativeUIError("function_not_found", `No generative UI function named "${name}" is declared in createGenerativeUI({ functions })`)
|
|
1864
|
-
};
|
|
1865
|
-
const mounted = [...handlers.get(name) ?? []];
|
|
1866
|
-
const [ref] = mounted;
|
|
1867
|
-
if (!ref) return {
|
|
1868
|
-
ok: false,
|
|
1869
|
-
error: new require_MarkdownSurfaces.GenerativeUIError("function_not_found", `"${name}" is declared, but no useGenerativeUIFunction handler is mounted for it`)
|
|
1870
|
-
};
|
|
1871
|
-
if (mounted.length > 1) return {
|
|
1872
|
-
ok: false,
|
|
1873
|
-
error: new require_MarkdownSurfaces.GenerativeUIError("function_conflict", `"${name}" has ${mounted.length} useGenerativeUIFunction handlers mounted. Mount exactly one.`)
|
|
1874
|
-
};
|
|
1875
|
-
return {
|
|
1876
|
-
ok: true,
|
|
1877
|
-
declared,
|
|
1878
|
-
ref
|
|
1879
|
-
};
|
|
1880
|
-
};
|
|
1881
|
-
const isDeclared = (name) => {
|
|
1882
|
-
try {
|
|
1883
|
-
return options.getDeclared().has(name);
|
|
1884
|
-
} catch {
|
|
1885
|
-
return false;
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
const resolve = (name) => {
|
|
1889
|
-
try {
|
|
1890
|
-
return resolveUnchecked(name);
|
|
1891
|
-
} catch (error) {
|
|
1892
|
-
return {
|
|
1893
|
-
ok: false,
|
|
1894
|
-
error: new require_MarkdownSurfaces.GenerativeUIError("handler_failed", `"${name}" could not be resolved: ${messageOf(error)}`)
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
};
|
|
1898
|
-
const validateArgs = async (name, schema, args) => {
|
|
1899
|
-
try {
|
|
1900
|
-
const validation = await schema["~standard"].validate(args);
|
|
1901
|
-
if (!validation.issues) return {
|
|
1902
|
-
ok: true,
|
|
1903
|
-
value: validation.value
|
|
1904
|
-
};
|
|
1905
|
-
return {
|
|
1906
|
-
ok: false,
|
|
1907
|
-
error: new require_MarkdownSurfaces.GenerativeUIError("invalid_arguments", `Invalid arguments for "${name}": ${validation.issues.map((i) => `${(i.path ?? []).map((p) => typeof p === "object" ? p.key : p).join(".") || "args"}: ${i.message}`).join("; ")}`)
|
|
1908
|
-
};
|
|
1909
|
-
} catch (error) {
|
|
1910
|
-
return {
|
|
1911
|
-
ok: false,
|
|
1912
|
-
error: new require_MarkdownSurfaces.GenerativeUIError("invalid_arguments", `Invalid arguments for "${name}": ${messageOf(error)}`)
|
|
1913
|
-
};
|
|
1914
|
-
}
|
|
1915
|
-
};
|
|
1916
|
-
const failWith = (name, origin, error) => {
|
|
1917
|
-
try {
|
|
1918
|
-
options.onError?.({
|
|
1919
|
-
name,
|
|
1920
|
-
origin,
|
|
1921
|
-
error
|
|
1922
|
-
});
|
|
1923
|
-
} catch {}
|
|
1924
|
-
return {
|
|
1925
|
-
ok: false,
|
|
1926
|
-
error
|
|
1927
|
-
};
|
|
1928
|
-
};
|
|
1929
|
-
/**
|
|
1930
|
-
* Why `origin` may not call a function with these permissions now, as an
|
|
1931
|
-
* error, or `undefined` when it may. The agent is refused what is for the
|
|
1932
|
-
* renderer; a component is refused what is for the agent, and a gesture
|
|
1933
|
-
* function when the browser counts no user activation.
|
|
1934
|
-
*/
|
|
1935
|
-
const callerError = (name, fn, origin) => {
|
|
1936
|
-
const isComponent = "componentId" in origin;
|
|
1937
|
-
if (!isComponent && !_copilotkit_shared.GENERATIVE_UI_AGENT_FUNCTION_CALLS) return new require_MarkdownSurfaces.GenerativeUIError("invalid_function_call", _copilotkit_shared.GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);
|
|
1938
|
-
const problem = (0, _copilotkit_shared.callerProblem)(name, fn, isComponent ? "renderer" : "agent");
|
|
1939
|
-
if (problem !== void 0) return new require_MarkdownSurfaces.GenerativeUIError("invalid_function_call", problem);
|
|
1940
|
-
if (isComponent && fn.requiresUserActivation && !hasUserActivation()) return new require_MarkdownSurfaces.GenerativeUIError("invalid_function_call", `function "${name}" runs only from a user gesture; this event was not one`);
|
|
1941
|
-
};
|
|
1942
|
-
/**
|
|
1943
|
-
* Runs a basic function of the A2UI catalog. They are value functions of
|
|
1944
|
-
* the renderer: the agent cannot call them, and one that needs a user
|
|
1945
|
-
* gesture runs only from an event binding.
|
|
1946
|
-
*/
|
|
1947
|
-
const invokeBasic = (name, args, origin) => {
|
|
1948
|
-
const info = _copilotkit_shared.GENERATIVE_UI_FUNCTIONS[name];
|
|
1949
|
-
const run = require_MarkdownSurfaces.BASIC_FUNCTIONS[name];
|
|
1950
|
-
if (info === void 0 || run === void 0) throw new Error(`"${name}" is not a basic function`);
|
|
1951
|
-
const refused = callerError(name, info, origin);
|
|
1952
|
-
if (refused) return failWith(name, origin, refused);
|
|
1953
|
-
if (args !== void 0 && !(typeof args === "object" && args !== null && !Array.isArray(args))) return failWith(name, origin, new require_MarkdownSurfaces.GenerativeUIError("invalid_arguments", `Invalid arguments for "${name}": args must be an object`));
|
|
1954
|
-
try {
|
|
1955
|
-
return {
|
|
1956
|
-
ok: true,
|
|
1957
|
-
result: run(args ?? {})
|
|
1958
|
-
};
|
|
1959
|
-
} catch (error) {
|
|
1960
|
-
return failWith(name, origin, new require_MarkdownSurfaces.GenerativeUIError(error instanceof require_MarkdownSurfaces.ExpressionError ? "invalid_arguments" : "handler_failed", `"${name}" failed: ${messageOf(error)}`));
|
|
1961
|
-
}
|
|
1962
|
-
};
|
|
1963
|
-
return {
|
|
1964
|
-
async invoke(name, args, origin) {
|
|
1965
|
-
const resolved = resolve(name);
|
|
1966
|
-
if (!resolved.ok && resolved.error.code === "function_not_found" && !isDeclared(name) && Object.prototype.hasOwnProperty.call(require_MarkdownSurfaces.BASIC_FUNCTIONS, name)) return invokeBasic(name, args, origin);
|
|
1967
|
-
if (!resolved.ok) return failWith(name, origin, resolved.error);
|
|
1968
|
-
const refused = callerError(name, resolved.declared, origin);
|
|
1969
|
-
if (refused) return failWith(name, origin, refused);
|
|
1970
|
-
const validated = await validateArgs(name, resolved.declared.parameters, args ?? {});
|
|
1971
|
-
if (!validated.ok) return failWith(name, origin, validated.error);
|
|
1972
|
-
try {
|
|
1973
|
-
return {
|
|
1974
|
-
ok: true,
|
|
1975
|
-
result: await resolved.ref.current(validated.value)
|
|
1976
|
-
};
|
|
1977
|
-
} catch (error) {
|
|
1978
|
-
return failWith(name, origin, new require_MarkdownSurfaces.GenerativeUIError("handler_failed", `"${name}" failed: ${messageOf(error)}`));
|
|
1979
|
-
}
|
|
1980
|
-
},
|
|
1981
|
-
listExposed() {
|
|
1982
|
-
let names;
|
|
1983
|
-
try {
|
|
1984
|
-
names = [...options.getDeclared().keys()];
|
|
1985
|
-
} catch {
|
|
1986
|
-
return {};
|
|
1987
|
-
}
|
|
1988
|
-
const listed = {};
|
|
1989
|
-
for (const name of names) {
|
|
1990
|
-
const resolved = resolve(name);
|
|
1991
|
-
if (!resolved.ok) continue;
|
|
1992
|
-
if (!(0, _copilotkit_shared.functionCallers)(resolved.declared).renderer && !_copilotkit_shared.GENERATIVE_UI_AGENT_FUNCTION_CALLS) continue;
|
|
1993
|
-
const { description, parameters, returnType } = resolved.declared;
|
|
1994
|
-
try {
|
|
1995
|
-
listed[name] = {
|
|
1996
|
-
...description ? { description } : {},
|
|
1997
|
-
parameters: require_MarkdownSurfaces.toJsonSchema(parameters),
|
|
1998
|
-
...returnType ? { returnType } : {},
|
|
1999
|
-
...permissionsOf(resolved.declared)
|
|
2000
|
-
};
|
|
2001
|
-
} catch {}
|
|
2002
|
-
}
|
|
2003
|
-
return listed;
|
|
2004
|
-
},
|
|
2005
|
-
register(name, ref) {
|
|
2006
|
-
const mounted = handlers.get(name) ?? /* @__PURE__ */ new Set();
|
|
2007
|
-
mounted.add(ref);
|
|
2008
|
-
handlers.set(name, mounted);
|
|
2009
|
-
return () => {
|
|
2010
|
-
mounted.delete(ref);
|
|
2011
|
-
};
|
|
2012
|
-
},
|
|
2013
|
-
handlerCount: (name) => handlers.get(name)?.size ?? 0
|
|
2014
|
-
};
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
1474
|
//#endregion
|
|
2018
1475
|
//#region src/generative-ui/markdown/context.ts
|
|
2019
1476
|
/**
|
|
@@ -2048,7 +1505,7 @@ function useGenerativeUIMarkdownContext(copilotkit, runtime, options) {
|
|
|
2048
1505
|
let schemaId;
|
|
2049
1506
|
let schemaValue;
|
|
2050
1507
|
const refreshSchema = (threadId) => {
|
|
2051
|
-
const manifest = buildGenerativeUIManifest(runtime, threadId);
|
|
1508
|
+
const manifest = (0, _copilotkit_core_generative_ui.buildGenerativeUIManifest)(runtime, threadId);
|
|
2052
1509
|
const guideline = (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest));
|
|
2053
1510
|
if (guideline !== guidelineValue) {
|
|
2054
1511
|
if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
|
|
@@ -2092,815 +1549,13 @@ function useGenerativeUIMarkdownContext(copilotkit, runtime, options) {
|
|
|
2092
1549
|
]);
|
|
2093
1550
|
}
|
|
2094
1551
|
|
|
2095
|
-
//#endregion
|
|
2096
|
-
//#region src/generative-ui/surface-manager.ts
|
|
2097
|
-
function surfaceKey(threadId, surfaceId) {
|
|
2098
|
-
return `${threadId}::${surfaceId}`;
|
|
2099
|
-
}
|
|
2100
|
-
let creationCounter = 0;
|
|
2101
|
-
const FORBIDDEN_SEGMENTS = new Set([
|
|
2102
|
-
"__proto__",
|
|
2103
|
-
"constructor",
|
|
2104
|
-
"prototype"
|
|
2105
|
-
]);
|
|
2106
|
-
/** "/a/b/" to "/a/b". The root stays "/". */
|
|
2107
|
-
function normalizePath(path) {
|
|
2108
|
-
return (path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path) || "/";
|
|
2109
|
-
}
|
|
2110
|
-
/** True when `path` is `ancestor` or below it. */
|
|
2111
|
-
function isAtOrBelow(path, ancestor) {
|
|
2112
|
-
if (ancestor === "/") return true;
|
|
2113
|
-
return path === ancestor || path.startsWith(`${ancestor}/`);
|
|
2114
|
-
}
|
|
2115
|
-
/**
|
|
2116
|
-
* Rejections as `"operation <index>: <reason>"` lines, cut to the size that
|
|
2117
|
-
* the envelope reader accepts.
|
|
2118
|
-
*/
|
|
2119
|
-
function summarizeRejections(rejections) {
|
|
2120
|
-
return rejections.slice(0, _copilotkit_shared.GENERATIVE_UI_MAX_SUMMARY_REJECTIONS).map(({ index, reason }) => `operation ${index}: ${reason}`.slice(0, _copilotkit_shared.GENERATIVE_UI_MAX_REJECTION_LENGTH));
|
|
2121
|
-
}
|
|
2122
|
-
/**
|
|
2123
|
-
* Framework-agnostic store of generated surfaces. One web_core SurfaceModel per
|
|
2124
|
-
* (threadId, surfaceId), shared by every mount. Applies only newly committed
|
|
2125
|
-
* operations, validates each before applying it, and owns app state and the
|
|
2126
|
-
* data model paths that the user wrote, so agent updates cannot overwrite
|
|
2127
|
-
* them. App state never goes into a surface's data model. Selectors read it
|
|
2128
|
-
* with `getState()`.
|
|
2129
|
-
*/
|
|
2130
|
-
var GenerativeUISurfaceManager = class {
|
|
2131
|
-
surfaces = /* @__PURE__ */ new Map();
|
|
2132
|
-
bookkeeping = /* @__PURE__ */ new Map();
|
|
2133
|
-
listeners = /* @__PURE__ */ new Set();
|
|
2134
|
-
/** Mounts of each target id, in mount order. */
|
|
2135
|
-
targets = /* @__PURE__ */ new Map();
|
|
2136
|
-
state = {};
|
|
2137
|
-
/**
|
|
2138
|
-
* User-owned data model values, by surface key, then by path. Kept when a
|
|
2139
|
-
* surface is rebuilt. Cleared when the surface is deleted.
|
|
2140
|
-
*/
|
|
2141
|
-
owned = /* @__PURE__ */ new Map();
|
|
2142
|
-
/**
|
|
2143
|
-
* Keys of the surfaces that a `deleteSurface` removed. A surface id is
|
|
2144
|
-
* unique for the life of the page, so a key stays here when its surface is
|
|
2145
|
-
* built again.
|
|
2146
|
-
*/
|
|
2147
|
-
deletedKeys = /* @__PURE__ */ new Set();
|
|
2148
|
-
/**
|
|
2149
|
-
* Surfaces that share their data model, by surface key: the parts of a
|
|
2150
|
-
* chat surface that the prose lift split. A user write to one part goes
|
|
2151
|
-
* to every part, so an input in one part drives a binding in another.
|
|
2152
|
-
*/
|
|
2153
|
-
linked = /* @__PURE__ */ new Map();
|
|
2154
|
-
webCoreCatalog;
|
|
2155
|
-
activeThreadId;
|
|
2156
|
-
version = 0;
|
|
2157
|
-
constructor(ui, options = {}) {
|
|
2158
|
-
this.ui = ui;
|
|
2159
|
-
this.options = options;
|
|
2160
|
-
this.webCoreCatalog = new _a2ui_web_core_v0_9.Catalog(ui.id, [...ui.components.keys()].map((name) => ({
|
|
2161
|
-
name,
|
|
2162
|
-
schema: zod.any()
|
|
2163
|
-
})), []);
|
|
2164
|
-
}
|
|
2165
|
-
subscribe = (listener) => {
|
|
2166
|
-
this.listeners.add(listener);
|
|
2167
|
-
return () => {
|
|
2168
|
-
this.listeners.delete(listener);
|
|
2169
|
-
};
|
|
2170
|
-
};
|
|
2171
|
-
getVersion = () => this.version;
|
|
2172
|
-
notify() {
|
|
2173
|
-
this.version++;
|
|
2174
|
-
for (const listener of [...this.listeners]) listener();
|
|
2175
|
-
}
|
|
2176
|
-
setActiveThread(threadId) {
|
|
2177
|
-
if (threadId === this.activeThreadId) return;
|
|
2178
|
-
this.activeThreadId = threadId;
|
|
2179
|
-
this.notify();
|
|
2180
|
-
}
|
|
2181
|
-
getActiveThread() {
|
|
2182
|
-
return this.activeThreadId;
|
|
2183
|
-
}
|
|
2184
|
-
ingest(threadId, agentId, content) {
|
|
2185
|
-
const key = surfaceKey(threadId, content.surfaceId);
|
|
2186
|
-
const operations = content.operations ?? [];
|
|
2187
|
-
let surface = this.surfaces.get(key);
|
|
2188
|
-
let book = this.bookkeeping.get(key);
|
|
2189
|
-
let changed = false;
|
|
2190
|
-
if (surface && book && !this.extendsApplied(book, operations)) {
|
|
2191
|
-
this.disposeSurface(key);
|
|
2192
|
-
surface = void 0;
|
|
2193
|
-
book = void 0;
|
|
2194
|
-
}
|
|
2195
|
-
if (!surface || !book) {
|
|
2196
|
-
surface = this.createSurface(key, threadId, agentId, content);
|
|
2197
|
-
this.restoreOwnedValues(surface);
|
|
2198
|
-
book = {
|
|
2199
|
-
appliedCount: 0,
|
|
2200
|
-
lastFingerprint: void 0
|
|
2201
|
-
};
|
|
2202
|
-
this.surfaces.set(key, surface);
|
|
2203
|
-
this.bookkeeping.set(key, book);
|
|
2204
|
-
changed = true;
|
|
2205
|
-
}
|
|
2206
|
-
const serverRejected = content.rejected ?? [];
|
|
2207
|
-
if (surface.clientRejected.length > 0 && (surface.status !== "streaming" && content.status === "streaming" || serverRejected.length < surface.serverRejected.length)) {
|
|
2208
|
-
surface.clientRejected = [];
|
|
2209
|
-
changed = true;
|
|
2210
|
-
}
|
|
2211
|
-
if (operations.length > 0) {
|
|
2212
|
-
const lastFingerprint = JSON.stringify(operations[operations.length - 1]);
|
|
2213
|
-
const isReplay = operations.some((op) => (0, _copilotkit_shared.getOperationKind)(op) === "deleteSurface");
|
|
2214
|
-
for (let index = book.appliedCount; index < operations.length; index++) {
|
|
2215
|
-
this.applyOperation(surface, operations[index], {
|
|
2216
|
-
index,
|
|
2217
|
-
isReplay
|
|
2218
|
-
});
|
|
2219
|
-
changed = true;
|
|
2220
|
-
}
|
|
2221
|
-
book.appliedCount = operations.length;
|
|
2222
|
-
surface.operations = operations;
|
|
2223
|
-
book.lastFingerprint = lastFingerprint;
|
|
2224
|
-
}
|
|
2225
|
-
if (surface.status !== content.status || surface.target !== content.target || surface.serverRejected.length !== serverRejected.length) {
|
|
2226
|
-
surface.status = content.status;
|
|
2227
|
-
surface.target = content.target;
|
|
2228
|
-
surface.serverRejected = serverRejected;
|
|
2229
|
-
changed = true;
|
|
2230
|
-
}
|
|
2231
|
-
if (changed) this.notify();
|
|
2232
|
-
}
|
|
2233
|
-
/** The surface of a `key` (see `surfaceKey`), unless it is deleted. */
|
|
2234
|
-
getSurfaceByKey(key) {
|
|
2235
|
-
const surface = this.surfaces.get(key);
|
|
2236
|
-
return surface && !surface.deleted ? surface : void 0;
|
|
2237
|
-
}
|
|
2238
|
-
getSurface(threadId, surfaceId) {
|
|
2239
|
-
const surface = this.surfaces.get(surfaceKey(threadId, surfaceId));
|
|
2240
|
-
return surface && !surface.deleted ? surface : void 0;
|
|
2241
|
-
}
|
|
2242
|
-
getSurfaceForTarget(target, threadId = this.activeThreadId) {
|
|
2243
|
-
if (!threadId) return void 0;
|
|
2244
|
-
let latest;
|
|
2245
|
-
for (const surface of this.surfaces.values()) {
|
|
2246
|
-
if (surface.threadId !== threadId || surface.target !== target || surface.deleted) continue;
|
|
2247
|
-
if (!latest || surface.createdAt > latest.createdAt) latest = surface;
|
|
2248
|
-
}
|
|
2249
|
-
return latest;
|
|
2250
|
-
}
|
|
2251
|
-
/**
|
|
2252
|
-
* A surface whose first createSurface was rejected, so the chat can show
|
|
2253
|
-
* the error where the surface would be. `undefined` for any other surface.
|
|
2254
|
-
*/
|
|
2255
|
-
getFailedSurface(threadId, surfaceId) {
|
|
2256
|
-
const surface = this.surfaces.get(surfaceKey(threadId, surfaceId));
|
|
2257
|
-
return surface?.failed ? surface : void 0;
|
|
2258
|
-
}
|
|
2259
|
-
/**
|
|
2260
|
-
* The surfaces of a thread, for the model. A surface with user-owned
|
|
2261
|
-
* values lists them in `dataModel`, so the model can read what the user
|
|
2262
|
-
* entered. A surface with dropped operations lists them in `rejected`, so
|
|
2263
|
-
* the model can fix them on the next run. A deleted surface, or one that
|
|
2264
|
-
* was never created, has a `status`, so the model knows that the id is
|
|
2265
|
-
* not a live surface.
|
|
2266
|
-
*/
|
|
2267
|
-
describeSurfaces(threadId) {
|
|
2268
|
-
const described = {};
|
|
2269
|
-
for (const surface of this.surfaces.values()) {
|
|
2270
|
-
if (surface.threadId !== threadId) continue;
|
|
2271
|
-
const owned = this.owned.get(surface.key);
|
|
2272
|
-
const rejections = [...surface.serverRejected, ...surface.clientRejected];
|
|
2273
|
-
const status = this.deletedKeys.has(surface.key) ? "deleted" : surface.failed ? "failed" : void 0;
|
|
2274
|
-
described[surface.surfaceId] = {
|
|
2275
|
-
target: surface.target,
|
|
2276
|
-
...owned && owned.size > 0 ? { dataModel: Object.fromEntries(owned) } : {},
|
|
2277
|
-
...rejections.length > 0 && status !== "deleted" ? { rejected: summarizeRejections(rejections) } : {},
|
|
2278
|
-
...status ? { status } : {}
|
|
2279
|
-
};
|
|
2280
|
-
}
|
|
2281
|
-
return described;
|
|
2282
|
-
}
|
|
2283
|
-
/** Every surface that is not deleted, oldest first, for the inspector. */
|
|
2284
|
-
debugSurfaces() {
|
|
2285
|
-
return [...this.surfaces.values()].filter((surface) => !surface.deleted).sort((a, b) => a.createdAt - b.createdAt).map((surface) => ({
|
|
2286
|
-
surfaceId: surface.surfaceId,
|
|
2287
|
-
threadId: surface.threadId,
|
|
2288
|
-
agentId: surface.agentId,
|
|
2289
|
-
target: surface.target,
|
|
2290
|
-
status: surface.status,
|
|
2291
|
-
operations: surface.operations,
|
|
2292
|
-
dataModel: surface.model.dataModel.get("/"),
|
|
2293
|
-
userValues: Object.fromEntries(this.owned.get(surface.key) ?? []),
|
|
2294
|
-
rejected: [...surface.serverRejected.map((r) => ({
|
|
2295
|
-
...r,
|
|
2296
|
-
source: "runtime"
|
|
2297
|
-
})), ...surface.clientRejected.map((r) => ({
|
|
2298
|
-
...r,
|
|
2299
|
-
source: "browser"
|
|
2300
|
-
}))]
|
|
2301
|
-
}));
|
|
2302
|
-
}
|
|
2303
|
-
/**
|
|
2304
|
-
* Marks a target as mounted. Returns the function that unmounts it. Calling
|
|
2305
|
-
* that function more than once has no effect.
|
|
2306
|
-
*
|
|
2307
|
-
* @param id - The target id.
|
|
2308
|
-
* @param options - The description and the allowed components of this mount.
|
|
2309
|
-
*/
|
|
2310
|
-
registerTarget(id, options = {}) {
|
|
2311
|
-
const registration = { ...options };
|
|
2312
|
-
const registrations = this.targets.get(id) ?? /* @__PURE__ */ new Set();
|
|
2313
|
-
registrations.add(registration);
|
|
2314
|
-
this.targets.set(id, registrations);
|
|
2315
|
-
this.notify();
|
|
2316
|
-
let released = false;
|
|
2317
|
-
return () => {
|
|
2318
|
-
if (released) return;
|
|
2319
|
-
released = true;
|
|
2320
|
-
registrations.delete(registration);
|
|
2321
|
-
if (registrations.size === 0) this.targets.delete(id);
|
|
2322
|
-
this.notify();
|
|
2323
|
-
};
|
|
2324
|
-
}
|
|
2325
|
-
/**
|
|
2326
|
-
* The mounted targets. Each has the description and the component list of
|
|
2327
|
-
* its earliest mount that has one.
|
|
2328
|
-
*/
|
|
2329
|
-
getMountedTargets() {
|
|
2330
|
-
const mounted = [];
|
|
2331
|
-
for (const [id, registrations] of this.targets) {
|
|
2332
|
-
const description = [...registrations].find((registration) => registration.description !== void 0)?.description;
|
|
2333
|
-
const components = this.targetComponents(id);
|
|
2334
|
-
mounted.push({
|
|
2335
|
-
id,
|
|
2336
|
-
...description === void 0 ? {} : { description },
|
|
2337
|
-
...components === void 0 ? {} : { components: [...components] }
|
|
2338
|
-
});
|
|
2339
|
-
}
|
|
2340
|
-
return mounted;
|
|
2341
|
-
}
|
|
2342
|
-
/**
|
|
2343
|
-
* The component list of the earliest mount of `id` that has one.
|
|
2344
|
-
* `undefined` when no mount of `id` limits its components.
|
|
2345
|
-
*/
|
|
2346
|
-
targetComponents(id) {
|
|
2347
|
-
return [...this.targets.get(id) ?? /* @__PURE__ */ new Set()].find((registration) => registration.components !== void 0)?.components;
|
|
2348
|
-
}
|
|
2349
|
-
/** The components that `validateOperation` allows on a surface. */
|
|
2350
|
-
allowedComponentsFor(surface) {
|
|
2351
|
-
const components = this.targetComponents(surface.target);
|
|
2352
|
-
return components === void 0 ? void 0 : {
|
|
2353
|
-
target: surface.target,
|
|
2354
|
-
names: new Set(components)
|
|
2355
|
-
};
|
|
2356
|
-
}
|
|
2357
|
-
/**
|
|
2358
|
-
* The app state object. It is the same object until a key changes, so it
|
|
2359
|
-
* can be a `useSyncExternalStore` snapshot.
|
|
2360
|
-
*/
|
|
2361
|
-
getState = () => this.state;
|
|
2362
|
-
/** Sets one state key. Notifies only when the value changed. */
|
|
2363
|
-
setState(key, value) {
|
|
2364
|
-
if (Object.hasOwn(this.state, key) && Object.is(this.state[key], value)) return;
|
|
2365
|
-
this.state = {
|
|
2366
|
-
...this.state,
|
|
2367
|
-
[key]: value
|
|
2368
|
-
};
|
|
2369
|
-
this.notify();
|
|
2370
|
-
}
|
|
2371
|
-
/** Removes one state key. Notifies only when the key was set. */
|
|
2372
|
-
removeState(key) {
|
|
2373
|
-
if (!Object.hasOwn(this.state, key)) return;
|
|
2374
|
-
const { [key]: _removed, ...rest } = this.state;
|
|
2375
|
-
this.state = rest;
|
|
2376
|
-
this.notify();
|
|
2377
|
-
}
|
|
2378
|
-
/**
|
|
2379
|
-
* Makes the surfaces of `surfaceIds` share their data model: a user write
|
|
2380
|
-
* to one of them goes to all of them (see `setOwnedValue`). The markdown
|
|
2381
|
-
* transport links the parts of a chat surface that the prose lift split.
|
|
2382
|
-
* A later call for one of the surfaces replaces its group.
|
|
2383
|
-
*
|
|
2384
|
-
* @param threadId - The thread of the surfaces.
|
|
2385
|
-
* @param surfaceIds - The surface ids of the group. One id clears a link.
|
|
2386
|
-
*/
|
|
2387
|
-
linkSurfaces(threadId, surfaceIds) {
|
|
2388
|
-
const keys = new Set(surfaceIds.map((id) => surfaceKey(threadId, id)));
|
|
2389
|
-
for (const key of keys) if (keys.size > 1) this.linked.set(key, keys);
|
|
2390
|
-
else this.linked.delete(key);
|
|
2391
|
-
}
|
|
2392
|
-
/**
|
|
2393
|
-
* Writes a user value into the data model of a surface, and marks `path`
|
|
2394
|
-
* as user-owned. Then agent writes to that path, or below it, are ignored.
|
|
2395
|
-
* An agent write above it keeps the user value. Ownership ends when the
|
|
2396
|
-
* surface is deleted. Does nothing for an unknown or deleted surface. The
|
|
2397
|
-
* surfaces linked to it (see `linkSurfaces`) get the same write.
|
|
2398
|
-
*
|
|
2399
|
-
* @param key - The `key` of the surface.
|
|
2400
|
-
* @param path - An absolute JSON pointer, for example "/form/email".
|
|
2401
|
-
* @param value - The new value. It is copied.
|
|
2402
|
-
* @throws Error when a path segment is "__proto__", "constructor" or
|
|
2403
|
-
* "prototype", or when the path does not fit the data (for example, a
|
|
2404
|
-
* segment above it holds a string).
|
|
2405
|
-
*/
|
|
2406
|
-
setOwnedValue(key, path, value) {
|
|
2407
|
-
const normalized = normalizePath(path);
|
|
2408
|
-
const forbidden = normalized.split("/").find((segment) => FORBIDDEN_SEGMENTS.has(segment));
|
|
2409
|
-
if (forbidden !== void 0) throw new Error(`[generativeUI] path segment "${forbidden}" is not allowed in "${path}".`);
|
|
2410
|
-
for (const target of this.linked.get(key) ?? [key]) this.writeOwnedValue(target, normalized, value);
|
|
2411
|
-
}
|
|
2412
|
-
writeOwnedValue(key, path, value) {
|
|
2413
|
-
const surface = this.surfaces.get(key);
|
|
2414
|
-
if (!surface || surface.deleted) return;
|
|
2415
|
-
surface.model.dataModel.set(path, structuredClone(value));
|
|
2416
|
-
const owned = this.owned.get(key) ?? /* @__PURE__ */ new Map();
|
|
2417
|
-
owned.set(path, structuredClone(value));
|
|
2418
|
-
this.owned.set(key, owned);
|
|
2419
|
-
}
|
|
2420
|
-
/**
|
|
2421
|
-
* Writes the user-owned values into the new, empty data model of a rebuilt
|
|
2422
|
-
* surface. The agent operations are applied after it.
|
|
2423
|
-
*/
|
|
2424
|
-
restoreOwnedValues(surface) {
|
|
2425
|
-
const owned = this.owned.get(surface.key) ?? /* @__PURE__ */ new Map();
|
|
2426
|
-
for (const [path, value] of owned) surface.model.dataModel.set(path, structuredClone(value));
|
|
2427
|
-
}
|
|
2428
|
-
/**
|
|
2429
|
-
* The value that an agent write puts at `path`, with the user-owned values
|
|
2430
|
-
* below `path` written back into it. `undefined` when `path` is user-owned
|
|
2431
|
-
* or below a user-owned path, so the agent cannot write it. Throws when a
|
|
2432
|
-
* user value does not fit the new value.
|
|
2433
|
-
*/
|
|
2434
|
-
mergeOwnedValues(key, path, value) {
|
|
2435
|
-
const merged = { value: structuredClone(value) };
|
|
2436
|
-
const owned = this.owned.get(key);
|
|
2437
|
-
if (!owned) return merged;
|
|
2438
|
-
const ownedPaths = [...owned.keys()];
|
|
2439
|
-
if (ownedPaths.some((ownedPath) => isAtOrBelow(path, ownedPath))) return void 0;
|
|
2440
|
-
const below = ownedPaths.filter((ownedPath) => isAtOrBelow(ownedPath, path));
|
|
2441
|
-
if (below.length === 0) return merged;
|
|
2442
|
-
const scratch = new _a2ui_web_core_v0_9.DataModel({ value: merged.value });
|
|
2443
|
-
const prefix = path === "/" ? "" : path;
|
|
2444
|
-
for (const ownedPath of below) {
|
|
2445
|
-
const relative = ownedPath.slice(prefix.length);
|
|
2446
|
-
scratch.set(`/value${relative}`, structuredClone(owned.get(ownedPath)));
|
|
2447
|
-
}
|
|
2448
|
-
return { value: scratch.get("/value") };
|
|
2449
|
-
}
|
|
2450
|
-
extendsApplied(book, operations) {
|
|
2451
|
-
if (operations.length < book.appliedCount) return false;
|
|
2452
|
-
if (book.appliedCount === 0) return true;
|
|
2453
|
-
return JSON.stringify(operations[book.appliedCount - 1]) === book.lastFingerprint;
|
|
2454
|
-
}
|
|
2455
|
-
createSurface(key, threadId, agentId, content) {
|
|
2456
|
-
return {
|
|
2457
|
-
key,
|
|
2458
|
-
threadId,
|
|
2459
|
-
surfaceId: content.surfaceId,
|
|
2460
|
-
agentId,
|
|
2461
|
-
model: new _a2ui_web_core_v0_9.SurfaceModel(content.surfaceId, this.webCoreCatalog),
|
|
2462
|
-
createdAt: ++creationCounter,
|
|
2463
|
-
target: content.target,
|
|
2464
|
-
status: content.status,
|
|
2465
|
-
deleted: false,
|
|
2466
|
-
failed: false,
|
|
2467
|
-
serverRejected: content.rejected ?? [],
|
|
2468
|
-
clientRejected: [],
|
|
2469
|
-
operations: []
|
|
2470
|
-
};
|
|
2471
|
-
}
|
|
2472
|
-
disposeSurface(key) {
|
|
2473
|
-
this.surfaces.get(key)?.model.dispose();
|
|
2474
|
-
this.surfaces.delete(key);
|
|
2475
|
-
this.bookkeeping.delete(key);
|
|
2476
|
-
}
|
|
2477
|
-
/**
|
|
2478
|
-
* Marks a surface deleted and frees its components and data. The record
|
|
2479
|
-
* stays, so the model is still told about the id and the bookkeeping does
|
|
2480
|
-
* not rebuild the surface for content that was already applied.
|
|
2481
|
-
*/
|
|
2482
|
-
closeSurface(surface) {
|
|
2483
|
-
surface.deleted = true;
|
|
2484
|
-
surface.model.dispose();
|
|
2485
|
-
surface.model = new _a2ui_web_core_v0_9.SurfaceModel(surface.surfaceId, this.webCoreCatalog);
|
|
2486
|
-
this.owned.delete(surface.key);
|
|
2487
|
-
this.linked.delete(surface.key);
|
|
2488
|
-
}
|
|
2489
|
-
/** The surfaces of a thread that a part of `surfaceId` reads, for tests. */
|
|
2490
|
-
getLinkedSurfaceIds(threadId, surfaceId) {
|
|
2491
|
-
const keys = this.linked.get(surfaceKey(threadId, surfaceId));
|
|
2492
|
-
if (!keys) return [surfaceId];
|
|
2493
|
-
const prefix = `${threadId}::`;
|
|
2494
|
-
return [...keys].map((key) => key.slice(prefix.length));
|
|
2495
|
-
}
|
|
2496
|
-
/**
|
|
2497
|
-
* Drops the node keys that the app sets: bound props and matched events.
|
|
2498
|
-
* The model does not see them, so a model value for one is ignored, not
|
|
2499
|
-
* rejected. This runs before validation, because validation rejects keys
|
|
2500
|
-
* that are not in the manifest. It never changes the given operation.
|
|
2501
|
-
*/
|
|
2502
|
-
dropAppSetKeys(op) {
|
|
2503
|
-
const kind = (0, _copilotkit_shared.getOperationKind)(op);
|
|
2504
|
-
if (kind !== "updateComponents" && kind !== "createSurface") return op;
|
|
2505
|
-
const record = op;
|
|
2506
|
-
const payload = record[kind];
|
|
2507
|
-
const nodes = payload?.components;
|
|
2508
|
-
if (!Array.isArray(nodes)) return op;
|
|
2509
|
-
return {
|
|
2510
|
-
...record,
|
|
2511
|
-
[kind]: {
|
|
2512
|
-
...payload,
|
|
2513
|
-
components: nodes.map((node) => this.dropAppSetNodeKeys(node))
|
|
2514
|
-
}
|
|
2515
|
-
};
|
|
2516
|
-
}
|
|
2517
|
-
dropAppSetNodeKeys(node) {
|
|
2518
|
-
if (typeof node !== "object" || node === null || !("component" in node)) return node;
|
|
2519
|
-
const { component } = node;
|
|
2520
|
-
if (typeof component !== "string") return node;
|
|
2521
|
-
const definition = this.ui.components.get(component);
|
|
2522
|
-
if (!definition) return node;
|
|
2523
|
-
return Object.fromEntries(Object.entries(node).filter(([key]) => !Object.hasOwn(definition.selectors, key) && !Object.hasOwn(definition.eventFunctions, key)));
|
|
2524
|
-
}
|
|
2525
|
-
/**
|
|
2526
|
-
* The surfaces that `validateOperation` gets for one operation of the
|
|
2527
|
-
* content of `surface`.
|
|
2528
|
-
*
|
|
2529
|
-
* - `knownSurfaces`: the surface, when it exists before the operation. It
|
|
2530
|
-
* does not exist before its first createSurface, or after a delete.
|
|
2531
|
-
* - `createdSurfaces`: the surface, when a createSurface at this position
|
|
2532
|
-
* uses its id again. That is the case after the first operation, and for
|
|
2533
|
-
* a surface that was deleted before, unless the content replays that
|
|
2534
|
-
* delete.
|
|
2535
|
-
*/
|
|
2536
|
-
surfacesFor(surface, kind, position) {
|
|
2537
|
-
const isFirstCreate = kind === "createSurface" && position.index === 0;
|
|
2538
|
-
const exists = !surface.deleted && !isFirstCreate;
|
|
2539
|
-
const isRecreate = this.deletedKeys.has(surface.key) && !position.isReplay;
|
|
2540
|
-
const isUsedAgain = position.index > 0 || isRecreate;
|
|
2541
|
-
return {
|
|
2542
|
-
knownSurfaces: new Set(exists ? [surface.surfaceId] : []),
|
|
2543
|
-
createdSurfaces: new Set(isUsedAgain ? [surface.surfaceId] : [])
|
|
2544
|
-
};
|
|
2545
|
-
}
|
|
2546
|
-
applyOperation(surface, received, position) {
|
|
2547
|
-
const { index } = position;
|
|
2548
|
-
const kind = (0, _copilotkit_shared.getOperationKind)(received);
|
|
2549
|
-
if (kind === "callRendererFunction") return;
|
|
2550
|
-
const reject = (reason) => {
|
|
2551
|
-
if (kind === "createSurface" && index === 0) {
|
|
2552
|
-
this.closeSurface(surface);
|
|
2553
|
-
surface.failed = true;
|
|
2554
|
-
}
|
|
2555
|
-
surface.clientRejected.push({
|
|
2556
|
-
index,
|
|
2557
|
-
reason
|
|
2558
|
-
});
|
|
2559
|
-
this.options.onOperationRejected?.({
|
|
2560
|
-
surfaceId: surface.surfaceId,
|
|
2561
|
-
index,
|
|
2562
|
-
reason
|
|
2563
|
-
});
|
|
2564
|
-
};
|
|
2565
|
-
const targetId = (0, _copilotkit_shared.getOperationSurfaceId)(received);
|
|
2566
|
-
if (targetId !== void 0 && targetId !== surface.surfaceId) return reject(`operation is for surface "${targetId}", not "${surface.surfaceId}"`);
|
|
2567
|
-
const op = this.dropAppSetKeys(received);
|
|
2568
|
-
const validation = (0, _copilotkit_shared.validateOperation)(op, {
|
|
2569
|
-
manifest: {
|
|
2570
|
-
catalogId: this.ui.id,
|
|
2571
|
-
catalogIds: require_MarkdownSurfaces.catalogIdsOf(this.ui),
|
|
2572
|
-
components: this.ui.manifestComponents
|
|
2573
|
-
},
|
|
2574
|
-
...this.surfacesFor(surface, kind, position),
|
|
2575
|
-
allowedComponents: this.allowedComponentsFor(surface)
|
|
2576
|
-
});
|
|
2577
|
-
if (!validation.ok) return reject(validation.reason);
|
|
2578
|
-
const typed = op;
|
|
2579
|
-
if ("createSurface" in typed) {
|
|
2580
|
-
const { dataModel, components = [] } = typed.createSurface;
|
|
2581
|
-
const problem = this.nodesProblem(components);
|
|
2582
|
-
if (problem) return reject(problem);
|
|
2583
|
-
if (dataModel) {
|
|
2584
|
-
const failure = this.writeAgentData(surface, "/", dataModel);
|
|
2585
|
-
if (failure) return reject(failure);
|
|
2586
|
-
}
|
|
2587
|
-
for (const node of components) this.upsertNode(surface.model, node);
|
|
2588
|
-
return;
|
|
2589
|
-
}
|
|
2590
|
-
if ("updateComponents" in typed) {
|
|
2591
|
-
const nodes = typed.updateComponents.components;
|
|
2592
|
-
const problem = this.nodesProblem(nodes);
|
|
2593
|
-
if (problem) return reject(problem);
|
|
2594
|
-
for (const node of nodes) this.upsertNode(surface.model, node);
|
|
2595
|
-
return;
|
|
2596
|
-
}
|
|
2597
|
-
if ("updateDataModel" in typed) {
|
|
2598
|
-
const { path = "/", value } = typed.updateDataModel;
|
|
2599
|
-
const written = value === null ? void 0 : value;
|
|
2600
|
-
const failure = this.writeAgentData(surface, normalizePath(path), written);
|
|
2601
|
-
if (failure) return reject(failure);
|
|
2602
|
-
return;
|
|
2603
|
-
}
|
|
2604
|
-
if ("deleteSurface" in typed) {
|
|
2605
|
-
this.closeSurface(surface);
|
|
2606
|
-
this.deletedKeys.add(surface.key);
|
|
2607
|
-
}
|
|
2608
|
-
}
|
|
2609
|
-
/** The first node with props of the wrong type, as a reason. */
|
|
2610
|
-
nodesProblem(nodes) {
|
|
2611
|
-
for (const node of nodes) {
|
|
2612
|
-
const problem = this.checkNodeProps(node);
|
|
2613
|
-
if (problem) return `component "${node.id}": ${problem}`;
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
/**
|
|
2617
|
-
* Writes an agent value at `path` and keeps the user-owned values. A write
|
|
2618
|
-
* to a user-owned path is ignored, not rejected. Gives the reason when the
|
|
2619
|
-
* value does not fit the data, else `undefined`.
|
|
2620
|
-
*/
|
|
2621
|
-
writeAgentData(surface, path, value) {
|
|
2622
|
-
try {
|
|
2623
|
-
const merged = this.mergeOwnedValues(surface.key, path, value);
|
|
2624
|
-
if (merged) surface.model.dataModel.set(path, merged.value);
|
|
2625
|
-
return;
|
|
2626
|
-
} catch (error) {
|
|
2627
|
-
return error instanceof Error ? error.message : String(error);
|
|
2628
|
-
}
|
|
2629
|
-
}
|
|
2630
|
-
checkNodeProps(node) {
|
|
2631
|
-
const definition = this.ui.components.get(node.component);
|
|
2632
|
-
if (!definition) return `unknown component "${node.component}"`;
|
|
2633
|
-
const { id: _id, component: _component, ...rest } = node;
|
|
2634
|
-
const dataProps = Object.fromEntries(Object.entries(rest).filter(([key]) => !definition.events?.[key] && !definition.slots?.[key] && !_copilotkit_shared.A2UI_COMPONENT_ENVELOPE_KEYS.has(key)));
|
|
2635
|
-
if (!definition.props) return void 0;
|
|
2636
|
-
const unknownNow = new Set(Object.keys(definition.selectors));
|
|
2637
|
-
const literals = {};
|
|
2638
|
-
for (const [key, value] of Object.entries(dataProps)) if (require_MarkdownSurfaces.containsDynamicValue(value)) unknownNow.add(key);
|
|
2639
|
-
else literals[key] = value;
|
|
2640
|
-
let result = require_MarkdownSurfaces.validateSchemaSync(definition.props, literals);
|
|
2641
|
-
if (!result.success) {
|
|
2642
|
-
const unset = require_MarkdownSurfaces.withoutRejectedNulls(literals, result.issues);
|
|
2643
|
-
if (unset) result = require_MarkdownSurfaces.validateSchemaSync(definition.props, unset);
|
|
2644
|
-
}
|
|
2645
|
-
if (result.success) return void 0;
|
|
2646
|
-
const issues = result.issues.filter((issue) => {
|
|
2647
|
-
const key = require_MarkdownSurfaces.issueKey(issue);
|
|
2648
|
-
return key === void 0 ? require_MarkdownSurfaces.isAsyncIssue(issue) : !unknownNow.has(key);
|
|
2649
|
-
});
|
|
2650
|
-
return issues.length > 0 ? require_MarkdownSurfaces.formatIssues(issues) : void 0;
|
|
2651
|
-
}
|
|
2652
|
-
upsertNode(model, node) {
|
|
2653
|
-
const { id, component, ...rest } = node;
|
|
2654
|
-
const properties = structuredClone(rest);
|
|
2655
|
-
const existing = model.componentsModel.get(id);
|
|
2656
|
-
if (existing && existing.type === component) {
|
|
2657
|
-
existing.properties = properties;
|
|
2658
|
-
return;
|
|
2659
|
-
}
|
|
2660
|
-
if (existing) model.componentsModel.removeComponent(id);
|
|
2661
|
-
model.componentsModel.addComponent(new _a2ui_web_core_v0_9.ComponentModel(id, component, properties));
|
|
2662
|
-
}
|
|
2663
|
-
};
|
|
2664
|
-
|
|
2665
1552
|
//#endregion
|
|
2666
1553
|
//#region src/generative-ui/use-generative-ui-root.ts
|
|
2667
1554
|
const isDevelopment = () => process.env.NODE_ENV !== "production";
|
|
2668
|
-
/** At most this many function follow-up runs for each user turn. */
|
|
2669
|
-
const MAX_FUNCTION_FOLLOW_UPS = 5;
|
|
2670
1555
|
function ingestMessages(manager, agent, messages) {
|
|
2671
1556
|
if (!agent.threadId) return;
|
|
2672
1557
|
for (const message of messages) if (message.role === "activity" && message.activityType === _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE) manager.ingest(agent.threadId, agent.agentId, message.content);
|
|
2673
1558
|
}
|
|
2674
|
-
/** What the envelope of a run says, from the provider config. */
|
|
2675
|
-
function envelopeOptionsFor(config) {
|
|
2676
|
-
if (config.transport === "markdown") return {
|
|
2677
|
-
transport: "markdown",
|
|
2678
|
-
includeCatalog: config.includeCatalog !== false,
|
|
2679
|
-
contextSent: config.sendContext !== false
|
|
2680
|
-
};
|
|
2681
|
-
return {
|
|
2682
|
-
transport: "tool",
|
|
2683
|
-
includeCatalog: true,
|
|
2684
|
-
contextSent: false
|
|
2685
|
-
};
|
|
2686
|
-
}
|
|
2687
|
-
/**
|
|
2688
|
-
* The components of a surface as one `updateComponents` operation, so that
|
|
2689
|
-
* the label of the component that sent an event can be found.
|
|
2690
|
-
*/
|
|
2691
|
-
function surfaceComponents(surface) {
|
|
2692
|
-
const components = [...surface.model.componentsModel.entries].map(([id, model]) => ({
|
|
2693
|
-
...model.properties,
|
|
2694
|
-
id,
|
|
2695
|
-
component: model.type
|
|
2696
|
-
}));
|
|
2697
|
-
return [{
|
|
2698
|
-
version: _copilotkit_shared.A2UI_VERSION,
|
|
2699
|
-
updateComponents: {
|
|
2700
|
-
surfaceId: surface.surfaceId,
|
|
2701
|
-
components
|
|
2702
|
-
}
|
|
2703
|
-
}];
|
|
2704
|
-
}
|
|
2705
|
-
/** True when `value` names a `functionCallId`. */
|
|
2706
|
-
function hasFunctionCallId(value) {
|
|
2707
|
-
return typeof value === "object" && value !== null && "functionCallId" in value && typeof value.functionCallId === "string" && value.functionCallId !== "";
|
|
2708
|
-
}
|
|
2709
|
-
/** The `functionCallId` that a developer message answers, if any. */
|
|
2710
|
-
function answeredCallId(content) {
|
|
2711
|
-
if (!content.includes("rendererFunctionResponse")) return void 0;
|
|
2712
|
-
try {
|
|
2713
|
-
const parsed = JSON.parse(content);
|
|
2714
|
-
const response = typeof parsed === "object" && parsed !== null && "rendererFunctionResponse" in parsed ? parsed.rendererFunctionResponse : void 0;
|
|
2715
|
-
return hasFunctionCallId(response) ? response.functionCallId : void 0;
|
|
2716
|
-
} catch {
|
|
2717
|
-
return;
|
|
2718
|
-
}
|
|
2719
|
-
}
|
|
2720
|
-
/** The function calls that a developer message in `messages` answers. */
|
|
2721
|
-
function answeredCallIds(messages) {
|
|
2722
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2723
|
-
for (const message of messages) {
|
|
2724
|
-
if (message.role !== "developer") continue;
|
|
2725
|
-
const id = answeredCallId(message.content);
|
|
2726
|
-
if (id !== void 0) ids.add(id);
|
|
2727
|
-
}
|
|
2728
|
-
return ids;
|
|
2729
|
-
}
|
|
2730
|
-
/** The id of the last user message. A user turn starts with it. */
|
|
2731
|
-
function lastUserMessageId(messages) {
|
|
2732
|
-
for (let index = messages.length - 1; index >= 0; index--) {
|
|
2733
|
-
const message = messages[index];
|
|
2734
|
-
if (message?.role === "user") return message.id;
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
/** The function calls of the tool transport: its function-call activities. */
|
|
2738
|
-
function activityFunctionCalls(messages) {
|
|
2739
|
-
const requests = [];
|
|
2740
|
-
for (const message of messages) {
|
|
2741
|
-
if (!(message.role === "activity" && message.activityType === _copilotkit_shared.GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE) || !hasFunctionCallId(message.content)) continue;
|
|
2742
|
-
requests.push({
|
|
2743
|
-
functionCallId: message.content.functionCallId,
|
|
2744
|
-
operation: {
|
|
2745
|
-
version: _copilotkit_shared.A2UI_VERSION,
|
|
2746
|
-
callRendererFunction: message.content
|
|
2747
|
-
}
|
|
2748
|
-
});
|
|
2749
|
-
}
|
|
2750
|
-
return requests;
|
|
2751
|
-
}
|
|
2752
|
-
/** The function calls of the markdown transport: its fence lines. */
|
|
2753
|
-
function markdownFunctionCalls(calls) {
|
|
2754
|
-
const requests = [];
|
|
2755
|
-
for (const { operation } of calls) {
|
|
2756
|
-
const payload = operation.callRendererFunction;
|
|
2757
|
-
if (!hasFunctionCallId(payload)) continue;
|
|
2758
|
-
requests.push({
|
|
2759
|
-
functionCallId: payload.functionCallId,
|
|
2760
|
-
operation
|
|
2761
|
-
});
|
|
2762
|
-
}
|
|
2763
|
-
return requests;
|
|
2764
|
-
}
|
|
2765
|
-
/** The text of a `rendererFunctionResponse` developer message. */
|
|
2766
|
-
function responseContent(response) {
|
|
2767
|
-
return JSON.stringify({
|
|
2768
|
-
version: _copilotkit_shared.A2UI_VERSION,
|
|
2769
|
-
rendererFunctionResponse: response
|
|
2770
|
-
});
|
|
2771
|
-
}
|
|
2772
|
-
function errorAnswer(functionCallId, code, message) {
|
|
2773
|
-
return {
|
|
2774
|
-
content: responseContent({
|
|
2775
|
-
functionCallId,
|
|
2776
|
-
error: {
|
|
2777
|
-
code,
|
|
2778
|
-
message
|
|
2779
|
-
}
|
|
2780
|
-
}),
|
|
2781
|
-
followUp: true
|
|
2782
|
-
};
|
|
2783
|
-
}
|
|
2784
|
-
const overCapAnswer = (functionCallId) => ({
|
|
2785
|
-
content: responseContent({
|
|
2786
|
-
functionCallId,
|
|
2787
|
-
error: {
|
|
2788
|
-
code: "follow_up_limit",
|
|
2789
|
-
message: `The function did not run. A user turn can have at most ${MAX_FUNCTION_FOLLOW_UPS} function follow-up runs. Wait for the next user message.`
|
|
2790
|
-
}
|
|
2791
|
-
}),
|
|
2792
|
-
followUp: false
|
|
2793
|
-
});
|
|
2794
|
-
/**
|
|
2795
|
-
* Runs the functions that the agent calls with `callRendererFunction`, for
|
|
2796
|
-
* both transports, and answers each call.
|
|
2797
|
-
*
|
|
2798
|
-
* - Each `functionCallId` runs once for each thread. A replay, a sync of
|
|
2799
|
-
* the same messages again, or a call that already has an answer message
|
|
2800
|
-
* does not run it again.
|
|
2801
|
-
* - The answer is a hidden developer message with a `rendererFunctionResponse`.
|
|
2802
|
-
* The answers go to the agent only when it is not running. Then one
|
|
2803
|
-
* follow-up run starts for all of them.
|
|
2804
|
-
* - A user turn has at most {@link MAX_FUNCTION_FOLLOW_UPS} follow-up runs.
|
|
2805
|
-
* A call after that does not run. It gets a `follow_up_limit` error and
|
|
2806
|
-
* starts no follow-up run.
|
|
2807
|
-
*/
|
|
2808
|
-
function createFunctionCallRunner(options) {
|
|
2809
|
-
const { copilotkit, dispatcher, manifest } = options;
|
|
2810
|
-
const threads = /* @__PURE__ */ new Map();
|
|
2811
|
-
const threadState = (threadId) => {
|
|
2812
|
-
let state = threads.get(threadId);
|
|
2813
|
-
if (!state) {
|
|
2814
|
-
state = {
|
|
2815
|
-
done: /* @__PURE__ */ new Set(),
|
|
2816
|
-
pending: [],
|
|
2817
|
-
turn: void 0,
|
|
2818
|
-
followUps: 0,
|
|
2819
|
-
flushing: false
|
|
2820
|
-
};
|
|
2821
|
-
threads.set(threadId, state);
|
|
2822
|
-
}
|
|
2823
|
-
return state;
|
|
2824
|
-
};
|
|
2825
|
-
const answer = async (request) => {
|
|
2826
|
-
const { functionCallId } = request;
|
|
2827
|
-
const validation = (0, _copilotkit_shared.validateOperation)(request.operation, {
|
|
2828
|
-
manifest,
|
|
2829
|
-
knownSurfaces: /* @__PURE__ */ new Set()
|
|
2830
|
-
});
|
|
2831
|
-
if (!validation.ok) return errorAnswer(functionCallId, "invalid_arguments", validation.reason);
|
|
2832
|
-
const operation = request.operation;
|
|
2833
|
-
if (!("callRendererFunction" in operation)) return errorAnswer(functionCallId, "invalid_arguments", "the operation is not a callRendererFunction");
|
|
2834
|
-
const { callFunction } = operation.callRendererFunction;
|
|
2835
|
-
const name = callFunction["@call"];
|
|
2836
|
-
const result = await dispatcher.invoke(name, callFunction.args ?? {}, { functionCallId });
|
|
2837
|
-
if (!result.ok) return errorAnswer(functionCallId, result.error.code, result.error.message);
|
|
2838
|
-
try {
|
|
2839
|
-
return {
|
|
2840
|
-
content: responseContent({
|
|
2841
|
-
functionCallId,
|
|
2842
|
-
value: result.result ?? null
|
|
2843
|
-
}),
|
|
2844
|
-
followUp: true
|
|
2845
|
-
};
|
|
2846
|
-
} catch (cause) {
|
|
2847
|
-
return errorAnswer(functionCallId, "handler_failed", `The result of "${name}" is not JSON: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
2848
|
-
}
|
|
2849
|
-
};
|
|
2850
|
-
/**
|
|
2851
|
-
* Adds the pending answers of a thread to the agent, then starts one
|
|
2852
|
-
* follow-up run. It waits while the agent runs: the next read of the
|
|
2853
|
-
* thread, at the end of the run, flushes again.
|
|
2854
|
-
*/
|
|
2855
|
-
const flush = async (agent, threadId, state) => {
|
|
2856
|
-
if (state.flushing) return;
|
|
2857
|
-
state.flushing = true;
|
|
2858
|
-
try {
|
|
2859
|
-
while (state.pending.length > 0) {
|
|
2860
|
-
const batch = [...state.pending];
|
|
2861
|
-
const answers = await Promise.all(batch);
|
|
2862
|
-
await copilotkit.waitForPendingFrameworkUpdates();
|
|
2863
|
-
if (agent.isRunning || agent.threadId !== threadId) return;
|
|
2864
|
-
if (state.pending.length > batch.length) continue;
|
|
2865
|
-
state.pending = [];
|
|
2866
|
-
for (const { content } of answers) agent.addMessage({
|
|
2867
|
-
id: (0, _copilotkit_shared.randomUUID)(),
|
|
2868
|
-
role: "developer",
|
|
2869
|
-
content
|
|
2870
|
-
});
|
|
2871
|
-
if (!answers.some((item) => item.followUp)) continue;
|
|
2872
|
-
state.followUps++;
|
|
2873
|
-
await copilotkit.runAgent({ agent });
|
|
2874
|
-
}
|
|
2875
|
-
} catch (error) {
|
|
2876
|
-
if (isDevelopment()) console.warn("[generativeUI] function follow-up run failed:", error);
|
|
2877
|
-
} finally {
|
|
2878
|
-
state.flushing = false;
|
|
2879
|
-
}
|
|
2880
|
-
};
|
|
2881
|
-
return { run(agent, requests, messages, running) {
|
|
2882
|
-
const { threadId } = agent;
|
|
2883
|
-
if (!threadId) return;
|
|
2884
|
-
const state = threadState(threadId);
|
|
2885
|
-
const turn = lastUserMessageId(messages);
|
|
2886
|
-
if (turn !== state.turn) {
|
|
2887
|
-
state.turn = turn;
|
|
2888
|
-
state.followUps = 0;
|
|
2889
|
-
}
|
|
2890
|
-
const isNew = (request) => !state.done.has(request.functionCallId);
|
|
2891
|
-
const fresh = requests.filter(isNew);
|
|
2892
|
-
const answered = fresh.length > 0 ? answeredCallIds(messages) : /* @__PURE__ */ new Set();
|
|
2893
|
-
for (const request of fresh) {
|
|
2894
|
-
const { functionCallId } = request;
|
|
2895
|
-
if (state.done.has(functionCallId)) continue;
|
|
2896
|
-
state.done.add(functionCallId);
|
|
2897
|
-
if (answered.has(functionCallId)) continue;
|
|
2898
|
-
const isOverCap = state.followUps >= MAX_FUNCTION_FOLLOW_UPS;
|
|
2899
|
-
state.pending.push(isOverCap ? Promise.resolve(overCapAnswer(functionCallId)) : answer(request));
|
|
2900
|
-
}
|
|
2901
|
-
if (!running) flush(agent, threadId, state);
|
|
2902
|
-
} };
|
|
2903
|
-
}
|
|
2904
1559
|
/** Provider-side wiring: manager, dispatcher, agent subscriptions, envelope. */
|
|
2905
1560
|
function useGenerativeUIRoot(copilotkit, config) {
|
|
2906
1561
|
const configRef = (0, react.useRef)(config);
|
|
@@ -2918,12 +1573,12 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
2918
1573
|
}
|
|
2919
1574
|
if (isDevelopment()) console.warn(`[generativeUI] ${info.kind} error in ${info.surfaceId}${info.componentId ? `/${info.componentId}` : ""}: ${info.error?.message}`);
|
|
2920
1575
|
};
|
|
2921
|
-
const manager = new GenerativeUISurfaceManager(ui, { onOperationRejected: ({ surfaceId, index, reason }) => reportError({
|
|
1576
|
+
const manager = new _copilotkit_core_generative_ui.GenerativeUISurfaceManager(ui, { onOperationRejected: ({ surfaceId, index, reason }) => reportError({
|
|
2922
1577
|
kind: "operation",
|
|
2923
1578
|
surfaceId,
|
|
2924
1579
|
error: /* @__PURE__ */ new Error(`operation ${index} rejected: ${reason}`)
|
|
2925
1580
|
}) });
|
|
2926
|
-
const dispatcher = createGenerativeUIDispatcher({
|
|
1581
|
+
const dispatcher = (0, _copilotkit_core_generative_ui.createGenerativeUIDispatcher)({
|
|
2927
1582
|
getDeclared: () => ui.functions,
|
|
2928
1583
|
onError: ({ name, origin, error }) => {
|
|
2929
1584
|
if ("functionCallId" in origin) {
|
|
@@ -2937,13 +1592,17 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
2937
1592
|
});
|
|
2938
1593
|
}
|
|
2939
1594
|
});
|
|
2940
|
-
const functionCalls = createFunctionCallRunner({
|
|
2941
|
-
copilotkit,
|
|
1595
|
+
const functionCalls = (0, _copilotkit_core_generative_ui.createFunctionCallRunner)({
|
|
1596
|
+
core: copilotkit,
|
|
2942
1597
|
dispatcher,
|
|
2943
1598
|
manifest: {
|
|
2944
1599
|
catalogId: ui.id,
|
|
2945
|
-
catalogIds:
|
|
1600
|
+
catalogIds: (0, _copilotkit_shared_generative_ui.catalogIdsOf)(ui),
|
|
2946
1601
|
components: ui.manifestComponents
|
|
1602
|
+
},
|
|
1603
|
+
settle: () => copilotkit.waitForPendingFrameworkUpdates(),
|
|
1604
|
+
warn: (message, error) => {
|
|
1605
|
+
if (isDevelopment()) console.warn(message, error);
|
|
2947
1606
|
}
|
|
2948
1607
|
});
|
|
2949
1608
|
const forwardingAgents = /* @__PURE__ */ new Set();
|
|
@@ -2972,12 +1631,12 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
2972
1631
|
actions.delete(agent);
|
|
2973
1632
|
const latest = configRef.current;
|
|
2974
1633
|
if (!latest) return;
|
|
2975
|
-
const envelope = buildGenerativeUIEnvelope({
|
|
1634
|
+
const envelope = (0, _copilotkit_core_generative_ui.buildGenerativeUIEnvelope)({
|
|
2976
1635
|
ui,
|
|
2977
1636
|
manager,
|
|
2978
1637
|
dispatcher
|
|
2979
1638
|
}, agent.threadId, {
|
|
2980
|
-
...envelopeOptionsFor(latest),
|
|
1639
|
+
...(0, _copilotkit_core_generative_ui.envelopeOptionsFor)(latest),
|
|
2981
1640
|
action
|
|
2982
1641
|
});
|
|
2983
1642
|
const id = copilotkit.addScopedProperties({
|
|
@@ -3002,7 +1661,7 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
3002
1661
|
};
|
|
3003
1662
|
const forwardEvent = async (event, agentId) => {
|
|
3004
1663
|
const fail = (message) => {
|
|
3005
|
-
const error = new
|
|
1664
|
+
const error = new _copilotkit_shared_generative_ui.GenerativeUIError("event_forward_failed", message);
|
|
3006
1665
|
reportError({
|
|
3007
1666
|
kind: "event",
|
|
3008
1667
|
surfaceId: event.surfaceId,
|
|
@@ -3018,16 +1677,16 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
3018
1677
|
if (!agent) return fail(`No agent "${agentId}" to receive "${event.name}"`);
|
|
3019
1678
|
if (agent.isRunning || forwardingAgents.has(agent)) return {
|
|
3020
1679
|
ok: false,
|
|
3021
|
-
error: new
|
|
1680
|
+
error: new _copilotkit_shared_generative_ui.GenerativeUIError("agent_busy", `"${event.name}" was not sent: the agent is running`)
|
|
3022
1681
|
};
|
|
3023
1682
|
forwardingAgents.add(agent);
|
|
3024
1683
|
try {
|
|
3025
1684
|
const surface = agent.threadId ? manager.getSurface(agent.threadId, event.surfaceId) : void 0;
|
|
3026
|
-
const resolveLabel = surface ?
|
|
1685
|
+
const resolveLabel = surface ? (0, _copilotkit_core_generative_ui.surfaceLabelResolver)(surface) : void 0;
|
|
3027
1686
|
agent.addMessage({
|
|
3028
1687
|
id: (0, _copilotkit_shared.randomUUID)(),
|
|
3029
1688
|
role: "user",
|
|
3030
|
-
content: buildActionMessageText(event, resolveLabel)
|
|
1689
|
+
content: (0, _copilotkit_core_generative_ui.buildActionMessageText)(event, resolveLabel)
|
|
3031
1690
|
});
|
|
3032
1691
|
setAction(agent, (0, _copilotkit_shared.toA2UIActionMessage)(event));
|
|
3033
1692
|
await copilotkit.runAgent({ agent });
|
|
@@ -3081,10 +1740,10 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
3081
1740
|
const watched = /* @__PURE__ */ new WeakSet();
|
|
3082
1741
|
const agentSubscriptions = [];
|
|
3083
1742
|
let envelopeId;
|
|
3084
|
-
const debug = createGenerativeUIDebugSource(core, () => {
|
|
1743
|
+
const debug = (0, _copilotkit_core_generative_ui.createGenerativeUIDebugSource)(core, () => {
|
|
3085
1744
|
const latest = configRef.current ?? { ui: core.ui };
|
|
3086
1745
|
return {
|
|
3087
|
-
options: envelopeOptionsFor(latest),
|
|
1746
|
+
options: (0, _copilotkit_core_generative_ui.envelopeOptionsFor)(latest),
|
|
3088
1747
|
agentIds: latest.agentIds
|
|
3089
1748
|
};
|
|
3090
1749
|
});
|
|
@@ -3101,7 +1760,7 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
3101
1760
|
*/
|
|
3102
1761
|
const setEnvelope = (agent, latest) => {
|
|
3103
1762
|
removeEnvelope();
|
|
3104
|
-
const run = describeGenerativeUIRun(core, agent.threadId, envelopeOptionsFor(latest));
|
|
1763
|
+
const run = (0, _copilotkit_core_generative_ui.describeGenerativeUIRun)(core, agent.threadId, (0, _copilotkit_core_generative_ui.envelopeOptionsFor)(latest));
|
|
3105
1764
|
envelopeId = copilotkit.addScopedProperties({
|
|
3106
1765
|
properties: { [_copilotkit_shared.COPILOTKIT_FORWARDED_PROPS_KEY]: { ui: run.envelope } },
|
|
3107
1766
|
agentIds: latest.agentIds
|
|
@@ -3121,13 +1780,13 @@ function useGenerativeUIRoot(copilotkit, config) {
|
|
|
3121
1780
|
* Both give their function calls to the one runner.
|
|
3122
1781
|
*/
|
|
3123
1782
|
const readMessages = (agent, messages, running) => {
|
|
3124
|
-
const requests = activityFunctionCalls(messages);
|
|
1783
|
+
const requests = (0, _copilotkit_core_generative_ui.activityFunctionCalls)(messages);
|
|
3125
1784
|
const { threadId } = agent;
|
|
3126
1785
|
if (configRef.current?.transport !== "markdown") ingestMessages(core.manager, agent, messages);
|
|
3127
1786
|
else if (threadId) {
|
|
3128
1787
|
core.manager.setActiveThread(threadId);
|
|
3129
|
-
const calls =
|
|
3130
|
-
requests.push(...markdownFunctionCalls(calls));
|
|
1788
|
+
const calls = (0, _copilotkit_core_generative_ui.getMarkdownSurfaceSource)(core).sync(threadId, agent.agentId, messages, { running });
|
|
1789
|
+
requests.push(...(0, _copilotkit_core_generative_ui.markdownFunctionCalls)(calls));
|
|
3131
1790
|
}
|
|
3132
1791
|
core.functionCalls.run(agent, requests, messages, running);
|
|
3133
1792
|
};
|