@dudousxd/nestjs-agent-react 0.35.1 → 0.35.3
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/{generative-ui-D1efzu_K.d.ts → generative-ui-DySIh0up.d.ts} +3 -0
- package/dist/{generative-ui-ClYT7OgL.d.cts → generative-ui-Pz1t-Ap3.d.cts} +3 -0
- package/dist/genui-json-render.cjs +88 -45
- package/dist/genui-json-render.cjs.map +1 -1
- package/dist/genui-json-render.d.cts +1 -1
- package/dist/genui-json-render.d.ts +1 -1
- package/dist/genui-json-render.js +91 -46
- package/dist/genui-json-render.js.map +1 -1
- package/dist/genui.cjs +88 -45
- package/dist/genui.cjs.map +1 -1
- package/dist/genui.d.cts +1 -1
- package/dist/genui.d.ts +1 -1
- package/dist/genui.js +91 -46
- package/dist/genui.js.map +1 -1
- package/dist/index.cjs +172 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +251 -161
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1220,7 +1220,7 @@ function dragHasFiles(data) {
|
|
|
1220
1220
|
}
|
|
1221
1221
|
|
|
1222
1222
|
// src/attachments/use-attachments.ts
|
|
1223
|
-
import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo4, useRef as
|
|
1223
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo4, useRef as useRef4, useState as useState4 } from "react";
|
|
1224
1224
|
|
|
1225
1225
|
// src/backend.ts
|
|
1226
1226
|
var AgentBackendUnsupportedError = class extends Error {
|
|
@@ -1243,7 +1243,7 @@ function requireBackendMethod(backend, name) {
|
|
|
1243
1243
|
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
1244
1244
|
|
|
1245
1245
|
// src/provider.tsx
|
|
1246
|
-
import { useContext as useContext3, useMemo as useMemo3, useRef as
|
|
1246
|
+
import { useContext as useContext3, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
1247
1247
|
|
|
1248
1248
|
// src/components/ambient-ui.ts
|
|
1249
1249
|
import { createContext, useContext } from "react";
|
|
@@ -1265,11 +1265,46 @@ function useAmbientRenderUi() {
|
|
|
1265
1265
|
import {
|
|
1266
1266
|
Component,
|
|
1267
1267
|
createContext as createContext2,
|
|
1268
|
+
memo,
|
|
1268
1269
|
useCallback,
|
|
1269
1270
|
useContext as useContext2,
|
|
1270
|
-
useMemo as useMemo2
|
|
1271
|
+
useMemo as useMemo2,
|
|
1272
|
+
useRef as useRef2
|
|
1271
1273
|
} from "react";
|
|
1272
1274
|
|
|
1275
|
+
// src/genui/share-structure.ts
|
|
1276
|
+
function isPlainObject(value) {
|
|
1277
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
1278
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1279
|
+
return prototype === Object.prototype || prototype === null;
|
|
1280
|
+
}
|
|
1281
|
+
function shareStructure(previous, next) {
|
|
1282
|
+
if (Object.is(previous, next)) return next;
|
|
1283
|
+
if (Array.isArray(next)) {
|
|
1284
|
+
if (!Array.isArray(previous)) return next;
|
|
1285
|
+
let same = previous.length === next.length;
|
|
1286
|
+
const shared3 = next.map((value, index) => {
|
|
1287
|
+
const kept = shareStructure(previous[index], value);
|
|
1288
|
+
if (kept !== previous[index]) same = false;
|
|
1289
|
+
return kept;
|
|
1290
|
+
});
|
|
1291
|
+
return same ? previous : shared3;
|
|
1292
|
+
}
|
|
1293
|
+
if (isPlainObject(next)) {
|
|
1294
|
+
if (!isPlainObject(previous)) return next;
|
|
1295
|
+
const keys = Object.keys(next);
|
|
1296
|
+
let same = keys.length === Object.keys(previous).length;
|
|
1297
|
+
const shared3 = {};
|
|
1298
|
+
for (const key of keys) {
|
|
1299
|
+
const kept = shareStructure(previous[key], next[key]);
|
|
1300
|
+
if (kept !== previous[key] || !Object.hasOwn(previous, key)) same = false;
|
|
1301
|
+
shared3[key] = kept;
|
|
1302
|
+
}
|
|
1303
|
+
return same ? previous : shared3;
|
|
1304
|
+
}
|
|
1305
|
+
return next;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1273
1308
|
// src/genui/use-generative-ui.ts
|
|
1274
1309
|
import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
|
|
1275
1310
|
|
|
@@ -1441,10 +1476,10 @@ var TreeScopeContext = createContext2(null);
|
|
|
1441
1476
|
var GenuiNodeContext = sharedContext(
|
|
1442
1477
|
"@dudousxd/nestjs-agent-react:genui-node"
|
|
1443
1478
|
);
|
|
1444
|
-
function renderPlaceholder(
|
|
1445
|
-
const { placeholder } =
|
|
1479
|
+
function renderPlaceholder(look, node) {
|
|
1480
|
+
const { placeholder } = look;
|
|
1446
1481
|
if (typeof placeholder === "function") return placeholder(node);
|
|
1447
|
-
return placeholder !== void 0 ? placeholder :
|
|
1482
|
+
return placeholder !== void 0 ? placeholder : look.loading;
|
|
1448
1483
|
}
|
|
1449
1484
|
function renderFallback(fallback2, problem) {
|
|
1450
1485
|
if (typeof fallback2 === "function") return fallback2(problem);
|
|
@@ -1478,9 +1513,33 @@ var ItemBoundary = class extends Component {
|
|
|
1478
1513
|
function nodeItem(node, id) {
|
|
1479
1514
|
return { id, component: node.type, props: node.props ?? {}, version: null, toolCallId: null };
|
|
1480
1515
|
}
|
|
1481
|
-
function
|
|
1516
|
+
function failsWhole(scope) {
|
|
1517
|
+
return !scope.hasFallback && scope.fallbackText !== void 0;
|
|
1518
|
+
}
|
|
1519
|
+
var TreeNode = memo(
|
|
1520
|
+
function TreeNode2({ node, id, bounded }) {
|
|
1521
|
+
const scope = useContext2(TreeScopeContext);
|
|
1522
|
+
const item = useMemo2(() => nodeItem(node, id), [node, id]);
|
|
1523
|
+
if (scope === null) return null;
|
|
1524
|
+
if (!bounded || failsWhole(scope)) return /* @__PURE__ */ jsx(TreeNodeBody, { node, id, item });
|
|
1525
|
+
return /* @__PURE__ */ jsx(
|
|
1526
|
+
ItemBoundary,
|
|
1527
|
+
{
|
|
1528
|
+
item,
|
|
1529
|
+
fallback: scope.look.current.fallback,
|
|
1530
|
+
onError: scope.look.current.onError,
|
|
1531
|
+
children: /* @__PURE__ */ jsx(TreeNodeBody, { node, id, item })
|
|
1532
|
+
}
|
|
1533
|
+
);
|
|
1534
|
+
},
|
|
1535
|
+
(previous, next) => previous.node === next.node && previous.id === next.id && previous.bounded === next.bounded
|
|
1536
|
+
);
|
|
1537
|
+
function TreeNodeBody({
|
|
1538
|
+
node,
|
|
1539
|
+
id,
|
|
1540
|
+
item
|
|
1541
|
+
}) {
|
|
1482
1542
|
const scope = useContext2(TreeScopeContext);
|
|
1483
|
-
const item = useMemo2(() => nodeItem(node, id), [node, id]);
|
|
1484
1543
|
const incomplete = node.incomplete === true;
|
|
1485
1544
|
const held = node.held === true;
|
|
1486
1545
|
const state = useMemo2(
|
|
@@ -1502,45 +1561,37 @@ function TreeNode({ node, id }) {
|
|
|
1502
1561
|
item.props
|
|
1503
1562
|
);
|
|
1504
1563
|
if (scope === null) return null;
|
|
1564
|
+
const look = scope.look.current;
|
|
1505
1565
|
if (held) {
|
|
1506
|
-
return /* @__PURE__ */ jsx(GenuiNodeContext.Provider, { value: state, children: renderPlaceholder(
|
|
1566
|
+
return /* @__PURE__ */ jsx(GenuiNodeContext.Provider, { value: state, children: renderPlaceholder(look, state) });
|
|
1507
1567
|
}
|
|
1508
|
-
if (resolution.status === "loading" || validation.status === "pending") return
|
|
1568
|
+
if (resolution.status === "loading" || validation.status === "pending") return look.loading;
|
|
1509
1569
|
if (resolution.status === "unknown") {
|
|
1510
|
-
if (scope
|
|
1511
|
-
|
|
1512
|
-
return renderFallback(scope.fallback, { reason: "unknown", item });
|
|
1570
|
+
if (failsWhole(scope)) throw new Error("Unknown tree component");
|
|
1571
|
+
return renderFallback(look.fallback, { reason: "unknown", item });
|
|
1513
1572
|
}
|
|
1514
1573
|
if (resolution.status === "error") {
|
|
1515
|
-
if (scope
|
|
1516
|
-
return renderFallback(
|
|
1574
|
+
if (failsWhole(scope)) throw resolution.error;
|
|
1575
|
+
return renderFallback(look.fallback, { reason: "error", item, error: resolution.error });
|
|
1517
1576
|
}
|
|
1518
1577
|
if (validation.status === "invalid") {
|
|
1519
|
-
if (scope
|
|
1520
|
-
|
|
1521
|
-
return renderFallback(scope.fallback, { reason: "invalid", item, issues: validation.issues });
|
|
1578
|
+
if (failsWhole(scope)) throw new Error("Invalid tree component");
|
|
1579
|
+
return renderFallback(look.fallback, { reason: "invalid", item, issues: validation.issues });
|
|
1522
1580
|
}
|
|
1523
1581
|
const Renderer = resolution.Component;
|
|
1524
1582
|
const children = Array.isArray(node.children) ? node.children : [];
|
|
1525
1583
|
return /* @__PURE__ */ jsx(GenuiNodeContext.Provider, { value: state, children: /* @__PURE__ */ jsx(Renderer, { ...validation.props, children: children.length > 0 ? children.map((child, index) => {
|
|
1526
1584
|
const childId = `${id}.${index}`;
|
|
1527
|
-
|
|
1528
|
-
return /* @__PURE__ */ jsx(TreeNode, { node: child, id: childId }, childId);
|
|
1529
|
-
return /* @__PURE__ */ jsx(
|
|
1530
|
-
ItemBoundary,
|
|
1531
|
-
{
|
|
1532
|
-
item: nodeItem(child, childId),
|
|
1533
|
-
fallback: scope.fallback,
|
|
1534
|
-
onError: scope.onError,
|
|
1535
|
-
children: /* @__PURE__ */ jsx(TreeNode, { node: child, id: childId })
|
|
1536
|
-
},
|
|
1537
|
-
childId
|
|
1538
|
-
);
|
|
1585
|
+
return /* @__PURE__ */ jsx(TreeNode, { node: child, id: childId, bounded: true }, childId);
|
|
1539
1586
|
}) : void 0 }) });
|
|
1540
1587
|
}
|
|
1541
1588
|
function GenuiTree({ root }) {
|
|
1542
|
-
|
|
1543
|
-
|
|
1589
|
+
const previous = useRef2(void 0);
|
|
1590
|
+
const valid = root !== void 0 && root !== null && typeof root.type === "string";
|
|
1591
|
+
const shared3 = valid ? shareStructure(previous.current, root) : void 0;
|
|
1592
|
+
previous.current = shared3;
|
|
1593
|
+
if (shared3 === void 0) return null;
|
|
1594
|
+
return /* @__PURE__ */ jsx(TreeNode, { node: shared3, id: "root", bounded: false });
|
|
1544
1595
|
}
|
|
1545
1596
|
function GenerativeUIScope({
|
|
1546
1597
|
registry,
|
|
@@ -1554,6 +1605,12 @@ function GenerativeUIScope({
|
|
|
1554
1605
|
onError,
|
|
1555
1606
|
children
|
|
1556
1607
|
}) {
|
|
1608
|
+
const versionsRef = useRef2(void 0);
|
|
1609
|
+
const versions = shareStructure(versionsRef.current, componentVersions);
|
|
1610
|
+
versionsRef.current = versions;
|
|
1611
|
+
const look = useRef2({ fallback: fallback2, loading, placeholder, onError });
|
|
1612
|
+
look.current = { fallback: fallback2, loading, placeholder, onError };
|
|
1613
|
+
const hasFallback = fallback2 !== void 0;
|
|
1557
1614
|
const scope = useMemo2(
|
|
1558
1615
|
() => ({
|
|
1559
1616
|
options: {
|
|
@@ -1561,24 +1618,12 @@ function GenerativeUIScope({
|
|
|
1561
1618
|
...catalog !== void 0 ? { catalog } : {},
|
|
1562
1619
|
...resolveComponent !== void 0 ? { resolveComponent } : {}
|
|
1563
1620
|
},
|
|
1564
|
-
|
|
1565
|
-
...
|
|
1621
|
+
hasFallback,
|
|
1622
|
+
...versions !== void 0 ? { componentVersions: versions } : {},
|
|
1566
1623
|
...fallbackText !== void 0 ? { fallbackText } : {},
|
|
1567
|
-
|
|
1568
|
-
placeholder,
|
|
1569
|
-
onError
|
|
1624
|
+
look
|
|
1570
1625
|
}),
|
|
1571
|
-
[
|
|
1572
|
-
registry,
|
|
1573
|
-
catalog,
|
|
1574
|
-
resolveComponent,
|
|
1575
|
-
fallback2,
|
|
1576
|
-
fallbackText,
|
|
1577
|
-
componentVersions,
|
|
1578
|
-
loading,
|
|
1579
|
-
placeholder,
|
|
1580
|
-
onError
|
|
1581
|
-
]
|
|
1626
|
+
[registry, catalog, resolveComponent, hasFallback, fallbackText, versions]
|
|
1582
1627
|
);
|
|
1583
1628
|
return /* @__PURE__ */ jsx(TreeScopeContext.Provider, { value: scope, children });
|
|
1584
1629
|
}
|
|
@@ -1697,7 +1742,7 @@ function AgentProvider({
|
|
|
1697
1742
|
genui,
|
|
1698
1743
|
children
|
|
1699
1744
|
}) {
|
|
1700
|
-
const latestHeaders =
|
|
1745
|
+
const latestHeaders = useRef3({ headers, getHeaders, onHttpError });
|
|
1701
1746
|
latestHeaders.current = { headers, getHeaders, onHttpError };
|
|
1702
1747
|
const upload = attachments?.upload;
|
|
1703
1748
|
const value = useMemo3(
|
|
@@ -1803,12 +1848,12 @@ function useAttachments(options = {}) {
|
|
|
1803
1848
|
...maxBytes !== void 0 ? { maxBytes } : {},
|
|
1804
1849
|
...maxFiles !== void 0 ? { maxFiles } : {}
|
|
1805
1850
|
};
|
|
1806
|
-
const latest =
|
|
1851
|
+
const latest = useRef4(effective);
|
|
1807
1852
|
latest.current = effective;
|
|
1808
1853
|
const [items, setItems] = useState4([]);
|
|
1809
|
-
const itemsRef =
|
|
1854
|
+
const itemsRef = useRef4(items);
|
|
1810
1855
|
itemsRef.current = items;
|
|
1811
|
-
const controllers =
|
|
1856
|
+
const controllers = useRef4(/* @__PURE__ */ new Map());
|
|
1812
1857
|
const [dragDepth, setDragDepth] = useState4(0);
|
|
1813
1858
|
const patch = useCallback2((id, change) => {
|
|
1814
1859
|
setItems((current) => current.map((item) => item.id === id ? { ...item, ...change } : item));
|
|
@@ -2443,14 +2488,14 @@ function applyPatch(target, patch) {
|
|
|
2443
2488
|
import { useCallback as useCallback4, useMemo as useMemo5 } from "react";
|
|
2444
2489
|
|
|
2445
2490
|
// src/catalog/use-resource.ts
|
|
2446
|
-
import { useCallback as useCallback3, useEffect as useEffect5, useRef as
|
|
2491
|
+
import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef5, useState as useState5 } from "react";
|
|
2447
2492
|
function useResource(load3, key, enabled) {
|
|
2448
2493
|
const [data, setData] = useState5(void 0);
|
|
2449
2494
|
const [isLoading, setIsLoading] = useState5(enabled);
|
|
2450
2495
|
const [error, setError] = useState5(null);
|
|
2451
|
-
const loadRef =
|
|
2496
|
+
const loadRef = useRef5(load3);
|
|
2452
2497
|
loadRef.current = load3;
|
|
2453
|
-
const generation =
|
|
2498
|
+
const generation = useRef5(0);
|
|
2454
2499
|
const refresh = useCallback3(async () => {
|
|
2455
2500
|
const mine = ++generation.current;
|
|
2456
2501
|
setIsLoading(true);
|
|
@@ -2597,17 +2642,17 @@ function useQuota(options = {}) {
|
|
|
2597
2642
|
}
|
|
2598
2643
|
|
|
2599
2644
|
// src/feedback/use-message-feedback.ts
|
|
2600
|
-
import { useCallback as useCallback5, useRef as
|
|
2645
|
+
import { useCallback as useCallback5, useRef as useRef6, useState as useState6 } from "react";
|
|
2601
2646
|
function useMessageFeedback(options = {}) {
|
|
2602
2647
|
const backend = useAgentBackend(options.backend);
|
|
2603
|
-
const latest =
|
|
2648
|
+
const latest = useRef6({ ...options, backend });
|
|
2604
2649
|
latest.current = { ...options, backend };
|
|
2605
2650
|
const [local, setLocal] = useState6(/* @__PURE__ */ new Map());
|
|
2606
2651
|
const [pending, setPending] = useState6(/* @__PURE__ */ new Set());
|
|
2607
2652
|
const [error, setError] = useState6(null);
|
|
2608
|
-
const localRef =
|
|
2653
|
+
const localRef = useRef6(local);
|
|
2609
2654
|
localRef.current = local;
|
|
2610
|
-
const resolved =
|
|
2655
|
+
const resolved = useRef6(/* @__PURE__ */ new Map());
|
|
2611
2656
|
const feedbackOf = useCallback5(
|
|
2612
2657
|
(message) => {
|
|
2613
2658
|
const mine = local.get(message.id);
|
|
@@ -2690,16 +2735,16 @@ function metadataOf(message) {
|
|
|
2690
2735
|
}
|
|
2691
2736
|
|
|
2692
2737
|
// src/threads/use-threads.ts
|
|
2693
|
-
import { useCallback as useCallback6, useEffect as useEffect7, useRef as
|
|
2738
|
+
import { useCallback as useCallback6, useEffect as useEffect7, useRef as useRef7, useState as useState7 } from "react";
|
|
2694
2739
|
function useThreads(options = {}) {
|
|
2695
2740
|
const { enabled = true } = options;
|
|
2696
2741
|
const backend = useAgentBackend(options.backend);
|
|
2697
2742
|
const [threads, setThreads] = useState7([]);
|
|
2698
2743
|
const [isLoading, setIsLoading] = useState7(enabled);
|
|
2699
2744
|
const [error, setError] = useState7(null);
|
|
2700
|
-
const threadsRef =
|
|
2745
|
+
const threadsRef = useRef7(threads);
|
|
2701
2746
|
threadsRef.current = threads;
|
|
2702
|
-
const generation =
|
|
2747
|
+
const generation = useRef7(0);
|
|
2703
2748
|
const refresh = useCallback6(async () => {
|
|
2704
2749
|
const mine = ++generation.current;
|
|
2705
2750
|
setIsLoading(true);
|
|
@@ -2807,7 +2852,7 @@ function backgroundRunsFromThread(messages) {
|
|
|
2807
2852
|
import { useEffect as useEffect9, useState as useState9 } from "react";
|
|
2808
2853
|
|
|
2809
2854
|
// src/components/use-speech-recognition.ts
|
|
2810
|
-
import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo8, useRef as
|
|
2855
|
+
import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo8, useRef as useRef8, useState as useState8 } from "react";
|
|
2811
2856
|
function getRecognitionCtor() {
|
|
2812
2857
|
if (typeof window === "undefined") return null;
|
|
2813
2858
|
const scope = window;
|
|
@@ -2818,12 +2863,12 @@ function useSpeechRecognition({
|
|
|
2818
2863
|
onFinalTranscript,
|
|
2819
2864
|
onInterimTranscript
|
|
2820
2865
|
}) {
|
|
2821
|
-
const recognitionRef =
|
|
2866
|
+
const recognitionRef = useRef8(null);
|
|
2822
2867
|
const [isListening, setIsListening] = useState8(false);
|
|
2823
2868
|
const ctor = useMemo8(() => getRecognitionCtor(), []);
|
|
2824
2869
|
const isSupported = ctor !== null;
|
|
2825
|
-
const finalRef =
|
|
2826
|
-
const interimRef =
|
|
2870
|
+
const finalRef = useRef8(onFinalTranscript);
|
|
2871
|
+
const interimRef = useRef8(onInterimTranscript);
|
|
2827
2872
|
finalRef.current = onFinalTranscript;
|
|
2828
2873
|
interimRef.current = onInterimTranscript;
|
|
2829
2874
|
useEffect8(() => {
|
|
@@ -2992,7 +3037,7 @@ function ChatInput({
|
|
|
2992
3037
|
import React2 from "react";
|
|
2993
3038
|
|
|
2994
3039
|
// src/transcript/use-chat-transcript.ts
|
|
2995
|
-
import { useCallback as useCallback9, useEffect as useEffect11, useRef as
|
|
3040
|
+
import { useCallback as useCallback9, useEffect as useEffect11, useRef as useRef10, useState as useState11 } from "react";
|
|
2996
3041
|
|
|
2997
3042
|
// src/transcript/model.ts
|
|
2998
3043
|
import {
|
|
@@ -3938,12 +3983,12 @@ function proposalDescription(description, approval) {
|
|
|
3938
3983
|
}
|
|
3939
3984
|
|
|
3940
3985
|
// src/transcript/use-stick-to-bottom.ts
|
|
3941
|
-
import { useCallback as useCallback8, useEffect as useEffect10, useRef as
|
|
3986
|
+
import { useCallback as useCallback8, useEffect as useEffect10, useRef as useRef9, useState as useState10 } from "react";
|
|
3942
3987
|
function useStickToBottom({
|
|
3943
3988
|
contentKey,
|
|
3944
3989
|
threshold = 32
|
|
3945
3990
|
}) {
|
|
3946
|
-
const containerRef =
|
|
3991
|
+
const containerRef = useRef9(null);
|
|
3947
3992
|
const [isAtBottom, setIsAtBottom] = useState10(true);
|
|
3948
3993
|
const measure = useCallback8(() => {
|
|
3949
3994
|
const element = containerRef.current;
|
|
@@ -4000,7 +4045,7 @@ function useChatTranscript(options) {
|
|
|
4000
4045
|
followUps,
|
|
4001
4046
|
stickToBottomThreshold
|
|
4002
4047
|
} = options;
|
|
4003
|
-
const latest =
|
|
4048
|
+
const latest = useRef10(options);
|
|
4004
4049
|
latest.current = options;
|
|
4005
4050
|
const [visibleCount, setVisibleCount] = useState11(initialVisibleCount);
|
|
4006
4051
|
const [stopRequested, setStopRequested] = useState11(false);
|
|
@@ -4071,9 +4116,9 @@ function useChatTranscript(options) {
|
|
|
4071
4116
|
};
|
|
4072
4117
|
}
|
|
4073
4118
|
function useQueuedItems(queue, readOnly) {
|
|
4074
|
-
const latestQueue =
|
|
4119
|
+
const latestQueue = useRef10(queue);
|
|
4075
4120
|
latestQueue.current = queue;
|
|
4076
|
-
const removers =
|
|
4121
|
+
const removers = useRef10(/* @__PURE__ */ new Map());
|
|
4077
4122
|
const removerFor = useCallback9((id) => {
|
|
4078
4123
|
let remover = removers.current.get(id);
|
|
4079
4124
|
if (remover === void 0) {
|
|
@@ -4110,7 +4155,7 @@ function useQueuedItems(queue, readOnly) {
|
|
|
4110
4155
|
}
|
|
4111
4156
|
function useTranscriptItem(options) {
|
|
4112
4157
|
const { message, isStreaming = false } = options;
|
|
4113
|
-
const messagesRef =
|
|
4158
|
+
const messagesRef = useRef10([message]);
|
|
4114
4159
|
if (messagesRef.current[0] !== message) {
|
|
4115
4160
|
messagesRef.current = [message];
|
|
4116
4161
|
}
|
|
@@ -4136,9 +4181,9 @@ function useTranscriptItems({
|
|
|
4136
4181
|
const [settleErrors, setSettleErrors] = useState11(() => /* @__PURE__ */ new Map());
|
|
4137
4182
|
const backend = useAgentBackend();
|
|
4138
4183
|
const handlers = settleHandlers(options, backend);
|
|
4139
|
-
const latest =
|
|
4184
|
+
const latest = useRef10({ options, handlers, drafts, picks, messages });
|
|
4140
4185
|
latest.current = { options, handlers, drafts, picks, messages };
|
|
4141
|
-
const copyTimers =
|
|
4186
|
+
const copyTimers = useRef10(/* @__PURE__ */ new Map());
|
|
4142
4187
|
useEffect11(
|
|
4143
4188
|
() => () => {
|
|
4144
4189
|
for (const timer of copyTimers.current.values()) {
|
|
@@ -4148,8 +4193,9 @@ function useTranscriptItems({
|
|
|
4148
4193
|
},
|
|
4149
4194
|
[]
|
|
4150
4195
|
);
|
|
4151
|
-
const callbackCache =
|
|
4152
|
-
const reasoningToggleCache =
|
|
4196
|
+
const callbackCache = useRef10(/* @__PURE__ */ new Map());
|
|
4197
|
+
const reasoningToggleCache = useRef10(/* @__PURE__ */ new Map());
|
|
4198
|
+
const uiBlocks = useRef10(/* @__PURE__ */ new Map());
|
|
4153
4199
|
const toggleReasoning = useCallback9((key, open) => {
|
|
4154
4200
|
setOpenReasoning((current) => {
|
|
4155
4201
|
const next = new Map(current);
|
|
@@ -4344,6 +4390,14 @@ function useTranscriptItems({
|
|
|
4344
4390
|
}, []);
|
|
4345
4391
|
const lastAssistantId = findLastAssistant(messages)?.id ?? null;
|
|
4346
4392
|
const items = [];
|
|
4393
|
+
const previousUi = uiBlocks.current;
|
|
4394
|
+
const keptUi = /* @__PURE__ */ new Map();
|
|
4395
|
+
const keepUiIdentity = (blocks) => blocks.map((block) => {
|
|
4396
|
+
if (block.kind !== "ui") return block;
|
|
4397
|
+
const kept = shareStructure(previousUi.get(block.key), block);
|
|
4398
|
+
keptUi.set(block.key, kept);
|
|
4399
|
+
return kept;
|
|
4400
|
+
});
|
|
4347
4401
|
for (let index = visibleStart; index < messages.length; index++) {
|
|
4348
4402
|
const message = messages[index];
|
|
4349
4403
|
if (!message) {
|
|
@@ -4366,37 +4420,39 @@ function useTranscriptItems({
|
|
|
4366
4420
|
isAssistant,
|
|
4367
4421
|
isLastAssistant,
|
|
4368
4422
|
isStreaming: message.id === streamingMessageId,
|
|
4369
|
-
blocks:
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4423
|
+
blocks: keepUiIdentity(
|
|
4424
|
+
buildTranscriptBlocks(message, {
|
|
4425
|
+
isReasoningOpen: (key, isStreamingRun) => openReasoning.get(key) ?? isStreamingRun,
|
|
4426
|
+
toggleReasoning: (key, open) => stableToggle(key)(open),
|
|
4427
|
+
...options.sources !== void 0 ? { sources: options.sources } : {},
|
|
4428
|
+
...options.toolCatalog !== void 0 ? { toolCatalog: options.toolCatalog } : {},
|
|
4429
|
+
// Read-only still lifts question sets into their block, so the outcome shows.
|
|
4430
|
+
...handlers.onAnswer !== void 0 || options.readOnly === true && options.onAnswer !== null ? {
|
|
4431
|
+
elicitation: {
|
|
4432
|
+
picked: (toolCallId, questionId) => picks.get(pickKey(toolCallId, questionId)),
|
|
4433
|
+
pick,
|
|
4434
|
+
canAnswer: handlers.onAnswer !== void 0,
|
|
4435
|
+
canSkip: handlers.onSkip !== void 0,
|
|
4436
|
+
answer,
|
|
4437
|
+
skip,
|
|
4438
|
+
submitting: (toolCallId) => settling.get(toolCallId) ?? null,
|
|
4439
|
+
errorOf: (toolCallId) => settleErrors.get(toolCallId)?.message ?? null,
|
|
4440
|
+
errorCodeOf: (toolCallId) => settleErrors.get(toolCallId)?.code ?? null
|
|
4441
|
+
}
|
|
4442
|
+
} : {},
|
|
4443
|
+
...handlers.onApprove !== void 0 || handlers.onReject !== void 0 ? {
|
|
4444
|
+
approval: {
|
|
4445
|
+
canApprove: handlers.onApprove !== void 0,
|
|
4446
|
+
canReject: handlers.onReject !== void 0,
|
|
4447
|
+
approve,
|
|
4448
|
+
reject,
|
|
4449
|
+
submitting: (toolCallId) => settling.get(toolCallId) ?? null,
|
|
4450
|
+
errorOf: (toolCallId) => settleErrors.get(toolCallId)?.message ?? null,
|
|
4451
|
+
errorCodeOf: (toolCallId) => settleErrors.get(toolCallId)?.code ?? null
|
|
4452
|
+
}
|
|
4453
|
+
} : {}
|
|
4454
|
+
})
|
|
4455
|
+
),
|
|
4400
4456
|
text,
|
|
4401
4457
|
usage: usage ? describeUsage(usage) : null,
|
|
4402
4458
|
timestamp: describeTimestamp((options.getCreatedAt ?? createdAtFromMetadata)(message)),
|
|
@@ -4431,6 +4487,7 @@ function useTranscriptItems({
|
|
|
4431
4487
|
}
|
|
4432
4488
|
});
|
|
4433
4489
|
}
|
|
4490
|
+
uiBlocks.current = keptUi;
|
|
4434
4491
|
return items;
|
|
4435
4492
|
}
|
|
4436
4493
|
function settleHandlers(options, backend) {
|
|
@@ -5004,12 +5061,12 @@ function toItem(entry) {
|
|
|
5004
5061
|
}
|
|
5005
5062
|
|
|
5006
5063
|
// src/composer/use-composer-autocomplete.ts
|
|
5007
|
-
import { useCallback as useCallback10, useEffect as useEffect12, useId, useLayoutEffect, useMemo as useMemo9, useRef as
|
|
5064
|
+
import { useCallback as useCallback10, useEffect as useEffect12, useId, useLayoutEffect, useMemo as useMemo9, useRef as useRef11, useState as useState12 } from "react";
|
|
5008
5065
|
function useComposerAutocomplete(options) {
|
|
5009
5066
|
const { value, sources, acceptOnTab = true } = options;
|
|
5010
|
-
const latest =
|
|
5067
|
+
const latest = useRef11(options);
|
|
5011
5068
|
latest.current = options;
|
|
5012
|
-
const inputRef =
|
|
5069
|
+
const inputRef = useRef11(null);
|
|
5013
5070
|
const [caret, setCaret] = useState12(value.length);
|
|
5014
5071
|
const [items, setItems] = useState12([]);
|
|
5015
5072
|
const [isLoading, setLoading] = useState12(false);
|
|
@@ -5022,13 +5079,13 @@ function useComposerAutocomplete(options) {
|
|
|
5022
5079
|
[value, safeCaret, sources]
|
|
5023
5080
|
);
|
|
5024
5081
|
const isActive = match !== null && dismissedIndex !== match.index;
|
|
5025
|
-
const matchRef =
|
|
5082
|
+
const matchRef = useRef11(match);
|
|
5026
5083
|
matchRef.current = match;
|
|
5027
|
-
const caretRef =
|
|
5084
|
+
const caretRef = useRef11(safeCaret);
|
|
5028
5085
|
caretRef.current = safeCaret;
|
|
5029
|
-
const itemsRef =
|
|
5086
|
+
const itemsRef = useRef11(items);
|
|
5030
5087
|
itemsRef.current = items;
|
|
5031
|
-
const activeIndexRef =
|
|
5088
|
+
const activeIndexRef = useRef11(activeIndex);
|
|
5032
5089
|
activeIndexRef.current = activeIndex;
|
|
5033
5090
|
const requestKey = isActive && match ? `${match.source.id}\0${match.query}` : null;
|
|
5034
5091
|
useEffect12(() => {
|
|
@@ -5093,7 +5150,7 @@ function useComposerAutocomplete(options) {
|
|
|
5093
5150
|
const current = matchRef.current;
|
|
5094
5151
|
if (current) setDismissedIndex(current.index);
|
|
5095
5152
|
}, []);
|
|
5096
|
-
const pendingCaret =
|
|
5153
|
+
const pendingCaret = useRef11(null);
|
|
5097
5154
|
const accept = useCallback10((item) => {
|
|
5098
5155
|
const current = matchRef.current;
|
|
5099
5156
|
if (!current) return;
|
|
@@ -5303,7 +5360,7 @@ function useToolCatalog(options = {}) {
|
|
|
5303
5360
|
}
|
|
5304
5361
|
|
|
5305
5362
|
// src/approvals/countdown.ts
|
|
5306
|
-
import { useEffect as useEffect14, useRef as
|
|
5363
|
+
import { useEffect as useEffect14, useRef as useRef12, useState as useState14 } from "react";
|
|
5307
5364
|
function approvalCountdown(expiresAt, now = Date.now()) {
|
|
5308
5365
|
const deadline = expiresAt == null ? Number.NaN : Date.parse(expiresAt);
|
|
5309
5366
|
if (!Number.isFinite(deadline)) {
|
|
@@ -5314,7 +5371,7 @@ function approvalCountdown(expiresAt, now = Date.now()) {
|
|
|
5314
5371
|
}
|
|
5315
5372
|
function useApprovalCountdown(expiresAt, options = {}) {
|
|
5316
5373
|
const { intervalMs = 1e3 } = options;
|
|
5317
|
-
const nowRef =
|
|
5374
|
+
const nowRef = useRef12(options.now ?? Date.now);
|
|
5318
5375
|
nowRef.current = options.now ?? Date.now;
|
|
5319
5376
|
const [state, setState] = useState14(() => approvalCountdown(expiresAt, nowRef.current()));
|
|
5320
5377
|
useEffect14(() => {
|
|
@@ -5548,10 +5605,10 @@ function sumUsage(rows) {
|
|
|
5548
5605
|
|
|
5549
5606
|
// src/use-agent-chat.ts
|
|
5550
5607
|
import { useChat } from "@ai-sdk/react";
|
|
5551
|
-
import { useCallback as useCallback13, useEffect as useEffect16, useMemo as useMemo11, useRef as
|
|
5608
|
+
import { useCallback as useCallback13, useEffect as useEffect16, useMemo as useMemo11, useRef as useRef14, useState as useState16 } from "react";
|
|
5552
5609
|
|
|
5553
5610
|
// src/approvals/use-action-proposals.ts
|
|
5554
|
-
import { useCallback as useCallback12, useEffect as useEffect15, useRef as
|
|
5611
|
+
import { useCallback as useCallback12, useEffect as useEffect15, useRef as useRef13, useState as useState15 } from "react";
|
|
5555
5612
|
|
|
5556
5613
|
// src/approvals/proposals.ts
|
|
5557
5614
|
function proposalNeedsPolling(proposal) {
|
|
@@ -5624,13 +5681,28 @@ function outcomeId(value) {
|
|
|
5624
5681
|
}
|
|
5625
5682
|
|
|
5626
5683
|
// src/approvals/use-action-proposals.ts
|
|
5684
|
+
var UNSUPPORTED_STATUSES = /* @__PURE__ */ new Set([404, 405, 501]);
|
|
5685
|
+
var UNKNOWN_THREAD = /* @__PURE__ */ new Set(["Thread not found", "Unknown thread"]);
|
|
5686
|
+
var MAX_BACKOFF_MS = 3e4;
|
|
5687
|
+
var unsupportedBackends = /* @__PURE__ */ new WeakSet();
|
|
5688
|
+
function statusOf(cause) {
|
|
5689
|
+
const status = cause?.status;
|
|
5690
|
+
return typeof status === "number" ? status : void 0;
|
|
5691
|
+
}
|
|
5692
|
+
function isProposalsUnsupported(cause) {
|
|
5693
|
+
const status = statusOf(cause);
|
|
5694
|
+
if (status === void 0 || !UNSUPPORTED_STATUSES.has(status)) return false;
|
|
5695
|
+
return !(status === 404 && cause instanceof Error && UNKNOWN_THREAD.has(cause.message));
|
|
5696
|
+
}
|
|
5627
5697
|
function useActionProposals(backend, threadId, setMessages, refreshKey, pollMs = 1e3) {
|
|
5628
5698
|
const [items, setItems] = useState15([]);
|
|
5629
5699
|
const [error, setError] = useState15(null);
|
|
5630
|
-
const
|
|
5700
|
+
const [unsupported, setUnsupported] = useState15(() => unsupportedBackends.has(backend));
|
|
5701
|
+
const [failures, setFailures] = useState15(0);
|
|
5702
|
+
const latest = useRef13({ threadId, setMessages });
|
|
5631
5703
|
latest.current = { threadId, setMessages };
|
|
5632
|
-
const mounted =
|
|
5633
|
-
const requests =
|
|
5704
|
+
const mounted = useRef13(true);
|
|
5705
|
+
const requests = useRef13(/* @__PURE__ */ new Map());
|
|
5634
5706
|
useEffect15(() => {
|
|
5635
5707
|
mounted.current = true;
|
|
5636
5708
|
return () => {
|
|
@@ -5639,6 +5711,7 @@ function useActionProposals(backend, threadId, setMessages, refreshKey, pollMs =
|
|
|
5639
5711
|
}, []);
|
|
5640
5712
|
const refresh = useCallback12(async () => {
|
|
5641
5713
|
if (threadId === void 0 || backend.listActionProposals === void 0) return;
|
|
5714
|
+
if (unsupportedBackends.has(backend)) return;
|
|
5642
5715
|
const pending = requests.current.get(threadId);
|
|
5643
5716
|
if (pending) return pending;
|
|
5644
5717
|
const request = (async () => {
|
|
@@ -5655,12 +5728,23 @@ function useActionProposals(backend, threadId, setMessages, refreshKey, pollMs =
|
|
|
5655
5728
|
if (!mounted.current || latest.current.threadId !== threadId) return;
|
|
5656
5729
|
setItems(proposals);
|
|
5657
5730
|
setError(null);
|
|
5731
|
+
setFailures(0);
|
|
5658
5732
|
latest.current.setMessages(
|
|
5659
5733
|
(current) => reconcileProposalMessages(current, proposals, facts)
|
|
5660
5734
|
);
|
|
5661
5735
|
} catch (cause) {
|
|
5662
|
-
if (
|
|
5736
|
+
if (isProposalsUnsupported(cause)) {
|
|
5737
|
+
unsupportedBackends.add(backend);
|
|
5738
|
+
if (mounted.current) {
|
|
5739
|
+
setUnsupported(true);
|
|
5740
|
+
setError(null);
|
|
5741
|
+
}
|
|
5742
|
+
return;
|
|
5743
|
+
}
|
|
5744
|
+
if (mounted.current && latest.current.threadId === threadId) {
|
|
5663
5745
|
setError(cause instanceof Error ? cause : new Error(String(cause)));
|
|
5746
|
+
setFailures((count) => count + 1);
|
|
5747
|
+
}
|
|
5664
5748
|
}
|
|
5665
5749
|
})();
|
|
5666
5750
|
requests.current.set(threadId, request);
|
|
@@ -5673,18 +5757,24 @@ function useActionProposals(backend, threadId, setMessages, refreshKey, pollMs =
|
|
|
5673
5757
|
useEffect15(() => {
|
|
5674
5758
|
setItems([]);
|
|
5675
5759
|
setError(null);
|
|
5760
|
+
setFailures(0);
|
|
5676
5761
|
}, [threadId]);
|
|
5762
|
+
useEffect15(() => {
|
|
5763
|
+
setUnsupported(unsupportedBackends.has(backend));
|
|
5764
|
+
}, [backend]);
|
|
5677
5765
|
useEffect15(() => {
|
|
5678
5766
|
void refresh();
|
|
5679
5767
|
}, [refresh, refreshKey]);
|
|
5680
5768
|
useEffect15(() => {
|
|
5681
|
-
if (!items.some(proposalNeedsPolling) || pollMs <= 0) return;
|
|
5682
|
-
const
|
|
5769
|
+
if (unsupported || !items.some(proposalNeedsPolling) || pollMs <= 0) return;
|
|
5770
|
+
const wait = failures === 0 ? pollMs : Math.min(pollMs * 2 ** failures, MAX_BACKOFF_MS);
|
|
5771
|
+
const timer = setTimeout(() => {
|
|
5683
5772
|
void refresh();
|
|
5684
|
-
},
|
|
5685
|
-
return () =>
|
|
5686
|
-
}, [items, pollMs, refresh]);
|
|
5773
|
+
}, wait);
|
|
5774
|
+
return () => clearTimeout(timer);
|
|
5775
|
+
}, [items, failures, unsupported, pollMs, refresh]);
|
|
5687
5776
|
useEffect15(() => {
|
|
5777
|
+
if (unsupported) return;
|
|
5688
5778
|
const refetch = () => {
|
|
5689
5779
|
void refresh();
|
|
5690
5780
|
};
|
|
@@ -5699,8 +5789,8 @@ function useActionProposals(backend, threadId, setMessages, refreshKey, pollMs =
|
|
|
5699
5789
|
window.removeEventListener("online", refetch);
|
|
5700
5790
|
document.removeEventListener("visibilitychange", visible);
|
|
5701
5791
|
};
|
|
5702
|
-
}, [refresh]);
|
|
5703
|
-
return { items, error, refresh };
|
|
5792
|
+
}, [refresh, unsupported]);
|
|
5793
|
+
return { items, error, unsupported, refresh };
|
|
5704
5794
|
}
|
|
5705
5795
|
|
|
5706
5796
|
// src/use-agent-chat.ts
|
|
@@ -5759,15 +5849,15 @@ function localChatId() {
|
|
|
5759
5849
|
}
|
|
5760
5850
|
function useAgentChat(options = {}) {
|
|
5761
5851
|
const providerCapabilities = useAgentUiCapabilities();
|
|
5762
|
-
const capabilitiesRef =
|
|
5852
|
+
const capabilitiesRef = useRef14(providerCapabilities);
|
|
5763
5853
|
capabilitiesRef.current = providerCapabilities;
|
|
5764
|
-
const latest =
|
|
5854
|
+
const latest = useRef14(options);
|
|
5765
5855
|
latest.current = options;
|
|
5766
5856
|
const resolved = useAgentBackend(options.backend);
|
|
5767
|
-
const client =
|
|
5768
|
-
const createdThreadId =
|
|
5769
|
-
const chatIdRef =
|
|
5770
|
-
const boundThreadRef =
|
|
5857
|
+
const client = useRef14(resolved).current;
|
|
5858
|
+
const createdThreadId = useRef14(void 0);
|
|
5859
|
+
const chatIdRef = useRef14(options.threadId ?? localChatId());
|
|
5860
|
+
const boundThreadRef = useRef14(options.threadId);
|
|
5771
5861
|
if (options.threadId !== boundThreadRef.current) {
|
|
5772
5862
|
boundThreadRef.current = options.threadId;
|
|
5773
5863
|
const adopting = options.threadId !== void 0 && options.threadId === createdThreadId.current;
|
|
@@ -5778,10 +5868,10 @@ function useAgentChat(options = {}) {
|
|
|
5778
5868
|
}
|
|
5779
5869
|
const chatId = chatIdRef.current;
|
|
5780
5870
|
const [runId, setRunId] = useState16(options.resumeRunId);
|
|
5781
|
-
const runIdRef =
|
|
5871
|
+
const runIdRef = useRef14(runId);
|
|
5782
5872
|
runIdRef.current = runId;
|
|
5783
|
-
const settlingRunIdRef =
|
|
5784
|
-
const autoResumeRunIdRef =
|
|
5873
|
+
const settlingRunIdRef = useRef14(void 0);
|
|
5874
|
+
const autoResumeRunIdRef = useRef14(void 0);
|
|
5785
5875
|
const [activeRunId, setActiveRunId] = useState16(null);
|
|
5786
5876
|
const [historyFor, setHistoryFor] = useState16(void 0);
|
|
5787
5877
|
const [historyError, setHistoryError] = useState16(null);
|
|
@@ -5789,28 +5879,28 @@ function useAgentChat(options = {}) {
|
|
|
5789
5879
|
const [threadModel, setThreadModel] = useState16(null);
|
|
5790
5880
|
const [threadPersona, setThreadPersona] = useState16(null);
|
|
5791
5881
|
const [pickedModel, setPickedModel] = useState16(void 0);
|
|
5792
|
-
const pickedModelRef =
|
|
5882
|
+
const pickedModelRef = useRef14(pickedModel);
|
|
5793
5883
|
pickedModelRef.current = pickedModel;
|
|
5794
|
-
const lockedRef =
|
|
5795
|
-
const pendingPin =
|
|
5796
|
-
const regenerateNext =
|
|
5884
|
+
const lockedRef = useRef14(false);
|
|
5885
|
+
const pendingPin = useRef14(void 0);
|
|
5886
|
+
const regenerateNext = useRef14(false);
|
|
5797
5887
|
const currentThreadId = useCallback13(
|
|
5798
5888
|
() => latest.current.threadId ?? createdThreadId.current,
|
|
5799
5889
|
[]
|
|
5800
5890
|
);
|
|
5801
5891
|
const [queueState, setQueueState] = useState16(EMPTY_QUEUE);
|
|
5802
|
-
const queueStateRef =
|
|
5892
|
+
const queueStateRef = useRef14(queueState);
|
|
5803
5893
|
const applyQueue = useCallback13((next) => {
|
|
5804
5894
|
queueStateRef.current = next;
|
|
5805
5895
|
setQueueState(next);
|
|
5806
5896
|
}, []);
|
|
5807
5897
|
const [pendingSends, setPendingSends] = useState16([]);
|
|
5808
5898
|
const [queueError, setQueueError] = useState16(null);
|
|
5809
|
-
const handoff =
|
|
5810
|
-
const queuedSend =
|
|
5811
|
-
const proposalRefreshRef =
|
|
5899
|
+
const handoff = useRef14(void 0);
|
|
5900
|
+
const queuedSend = useRef14(void 0);
|
|
5901
|
+
const proposalRefreshRef = useRef14(async () => {
|
|
5812
5902
|
});
|
|
5813
|
-
const threadWaiters =
|
|
5903
|
+
const threadWaiters = useRef14([]);
|
|
5814
5904
|
const turnBody = useCallback13(() => {
|
|
5815
5905
|
const current = latest.current;
|
|
5816
5906
|
if (current.persona !== void 0) setThreadPersona(current.persona);
|
|
@@ -5829,7 +5919,7 @@ function useAgentChat(options = {}) {
|
|
|
5829
5919
|
};
|
|
5830
5920
|
}, [currentThreadId]);
|
|
5831
5921
|
const [connection, setConnection] = useState16({ status: "live" });
|
|
5832
|
-
const resyncAfterSettle =
|
|
5922
|
+
const resyncAfterSettle = useRef14(false);
|
|
5833
5923
|
const transport = useMemo11(() => {
|
|
5834
5924
|
function onMeta(meta) {
|
|
5835
5925
|
settlingRunIdRef.current = meta.runId;
|
|
@@ -5882,7 +5972,7 @@ function useAgentChat(options = {}) {
|
|
|
5882
5972
|
}
|
|
5883
5973
|
});
|
|
5884
5974
|
}, []);
|
|
5885
|
-
const backgroundRef =
|
|
5975
|
+
const backgroundRef = useRef14(() => Promise.resolve());
|
|
5886
5976
|
const chat = useChat({
|
|
5887
5977
|
transport,
|
|
5888
5978
|
id: chatId,
|
|
@@ -5937,7 +6027,7 @@ function useAgentChat(options = {}) {
|
|
|
5937
6027
|
}
|
|
5938
6028
|
}
|
|
5939
6029
|
});
|
|
5940
|
-
const chatRef =
|
|
6030
|
+
const chatRef = useRef14(chat);
|
|
5941
6031
|
chatRef.current = chat;
|
|
5942
6032
|
function onQueueData(data) {
|
|
5943
6033
|
const frame = data ?? {};
|
|
@@ -5985,7 +6075,7 @@ function useAgentChat(options = {}) {
|
|
|
5985
6075
|
} catch {
|
|
5986
6076
|
}
|
|
5987
6077
|
}
|
|
5988
|
-
const firstChatId =
|
|
6078
|
+
const firstChatId = useRef14(chatId);
|
|
5989
6079
|
useEffect16(() => {
|
|
5990
6080
|
if (chatId === firstChatId.current) return;
|
|
5991
6081
|
firstChatId.current = chatId;
|
|
@@ -6052,7 +6142,7 @@ function useAgentChat(options = {}) {
|
|
|
6052
6142
|
};
|
|
6053
6143
|
}, [client, chatId, options.threadId]);
|
|
6054
6144
|
const isLoadingHistory = options.threadId !== void 0 && options.threadId !== createdThreadId.current && options.history !== false && options.initialMessages === void 0 && historyFor !== options.threadId;
|
|
6055
|
-
const turnInFlight =
|
|
6145
|
+
const turnInFlight = useRef14(false);
|
|
6056
6146
|
const isTurnInFlight = useCallback13(
|
|
6057
6147
|
() => turnInFlight.current || transport.isAttemptLive,
|
|
6058
6148
|
[transport]
|
|
@@ -6062,12 +6152,12 @@ function useAgentChat(options = {}) {
|
|
|
6062
6152
|
enabled: options.quota !== false && typeof client.getQuota === "function"
|
|
6063
6153
|
});
|
|
6064
6154
|
const blocked = options.blocked !== void 0 ? options.blocked : quota.blocked;
|
|
6065
|
-
const blockedRef =
|
|
6155
|
+
const blockedRef = useRef14(blocked);
|
|
6066
6156
|
blockedRef.current = blocked;
|
|
6067
6157
|
const whileRunning = typeof client.enqueueMessage === "function" ? options.whileRunning ?? "queue" : "block";
|
|
6068
|
-
const whileRunningRef =
|
|
6158
|
+
const whileRunningRef = useRef14(whileRunning);
|
|
6069
6159
|
whileRunningRef.current = whileRunning;
|
|
6070
|
-
const canQueueRef =
|
|
6160
|
+
const canQueueRef = useRef14(false);
|
|
6071
6161
|
canQueueRef.current = typeof client.enqueueMessage === "function";
|
|
6072
6162
|
const threadForQueue = useCallback13(async () => {
|
|
6073
6163
|
const known = currentThreadId();
|
|
@@ -6260,7 +6350,7 @@ function useAgentChat(options = {}) {
|
|
|
6260
6350
|
else attachTo(turn);
|
|
6261
6351
|
}
|
|
6262
6352
|
}, [client, queueCall, currentThreadId, applyQueue, isTurnInFlight]);
|
|
6263
|
-
const resumeQueueRef =
|
|
6353
|
+
const resumeQueueRef = useRef14(resumeQueue);
|
|
6264
6354
|
resumeQueueRef.current = resumeQueue;
|
|
6265
6355
|
const queuedItems = [
|
|
6266
6356
|
...pendingSends.filter((item) => item.interrupt),
|
|
@@ -6494,7 +6584,7 @@ function useAgentChat(options = {}) {
|
|
|
6494
6584
|
[client, currentThreadId]
|
|
6495
6585
|
);
|
|
6496
6586
|
const [modelsWanted, setModelsWanted] = useState16(false);
|
|
6497
|
-
const modelsWantedRef =
|
|
6587
|
+
const modelsWantedRef = useRef14(modelsWanted);
|
|
6498
6588
|
modelsWantedRef.current = modelsWanted;
|
|
6499
6589
|
const catalog = useModels({
|
|
6500
6590
|
backend: client,
|
|
@@ -6550,12 +6640,12 @@ function useAgentChat(options = {}) {
|
|
|
6550
6640
|
};
|
|
6551
6641
|
const status = connection.status === "reconnecting" ? "reconnecting" : chat.status;
|
|
6552
6642
|
const isBusy = status === "submitted" || status === "streaming" || status === "reconnecting";
|
|
6553
|
-
const isBusyRef =
|
|
6643
|
+
const isBusyRef = useRef14(isBusy);
|
|
6554
6644
|
isBusyRef.current = isBusy;
|
|
6555
6645
|
const files = useAttachments({ ...options.composer, backend: client });
|
|
6556
6646
|
const [text, setText] = useState16("");
|
|
6557
6647
|
const blockedBy = blocked != null ? "quota" : files.isUploading ? "uploading" : isBusy && whileRunning === "block" ? "busy" : text.trim().length === 0 && files.refs.length === 0 ? "empty" : null;
|
|
6558
|
-
const composerRef =
|
|
6648
|
+
const composerRef = useRef14({ text, files, blockedBy });
|
|
6559
6649
|
composerRef.current = { text, files, blockedBy };
|
|
6560
6650
|
const submit = useCallback13(
|
|
6561
6651
|
async (options2) => {
|