@tangle-network/agent-app 0.61.3 → 0.62.0
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/{DesignCanvas-L6J72JQ2.js → DesignCanvas-IQKYAEC4.js} +3 -2
- package/dist/{DesignCanvasEditor-QFQD63MR.js → DesignCanvasEditor-O7OCZTGC.js} +5 -4
- package/dist/{TimelineEditor-7KBPJQLT.js → TimelineEditor-VB2UJ34D.js} +4 -2
- package/dist/VaultPane-AYW7CO33.js +8 -0
- package/dist/agent-profiles/d1.js +1 -1
- package/dist/agent-profiles/index.d.ts +0 -82
- package/dist/agent-profiles/index.js +1 -21
- package/dist/agent-profiles/self-management.d.ts +0 -55
- package/dist/alerting/index.d.ts +1 -1
- package/dist/alerting/index.js +1 -3
- package/dist/alerting/slack.d.ts +6 -79
- package/dist/app-auth/drizzle.d.ts +17 -271
- package/dist/app-auth/drizzle.js +6 -2
- package/dist/app-auth/drizzle.js.map +1 -1
- package/dist/app-auth/index.js +3 -3
- package/dist/assets/types.d.ts +2 -1
- package/dist/assistant/AssistantPanel.d.ts +1 -1
- package/dist/assistant/index.js +635 -392
- package/dist/assistant/index.js.map +1 -1
- package/dist/billing/identity-locks.d.ts +5 -0
- package/dist/billing/index.js +1 -1
- package/dist/brand-extraction/index.js.map +1 -1
- package/dist/brand-extraction/types.d.ts +2 -1
- package/dist/chat-react/index.js +6 -5
- package/dist/chat-routes/attachment-write-safety.d.ts +4 -0
- package/dist/chat-routes/draft-persistence.d.ts +2 -14
- package/dist/chat-routes/index.d.ts +1 -0
- package/dist/chat-routes/index.js +853 -773
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/sandbox-model-source.d.ts +20 -0
- package/dist/chat-routes/stored-attachments.d.ts +18 -0
- package/dist/chat-routes/turn-admission.d.ts +1 -1
- package/dist/chat-routes/turn-execution.d.ts +2 -2
- package/dist/chat-routes/turn-route-contracts.d.ts +3 -29
- package/dist/chat-store/core.d.ts +19 -1
- package/dist/chat-store/index.js.map +1 -1
- package/dist/chat-store/store.d.ts +3 -29
- package/dist/{chunk-ATQQCG4I.js → chunk-2VJLLRVV.js} +2 -2
- package/dist/{chunk-R4X5474U.js → chunk-52SDU43B.js} +12 -27
- package/dist/chunk-52SDU43B.js.map +1 -0
- package/dist/{chunk-MDRH3SDA.js → chunk-54YIL7WM.js} +3 -3
- package/dist/{chunk-6QJ3GB3A.js → chunk-5GSZGTPJ.js} +2 -2
- package/dist/{chunk-5IM2CLYX.js → chunk-6JEDSKFH.js} +232 -218
- package/dist/chunk-6JEDSKFH.js.map +1 -0
- package/dist/{chunk-6PRQ45QE.js → chunk-6OG4244Y.js} +1 -1
- package/dist/chunk-6OG4244Y.js.map +1 -0
- package/dist/{chunk-ZDPUC6CM.js → chunk-6ZVSMA4T.js} +3 -3
- package/dist/{chunk-TXUAGSFR.js → chunk-76MPX7JQ.js} +47 -1
- package/dist/chunk-76MPX7JQ.js.map +1 -0
- package/dist/{chunk-BOQ4HVVH.js → chunk-7ISHKBAD.js} +61 -52
- package/dist/chunk-7ISHKBAD.js.map +1 -0
- package/dist/chunk-7PULOECS.js +22 -0
- package/dist/chunk-7PULOECS.js.map +1 -0
- package/dist/{chunk-KJODHPWM.js → chunk-CPVGRQ43.js} +511 -339
- package/dist/chunk-CPVGRQ43.js.map +1 -0
- package/dist/{chunk-LO6VQ35O.js → chunk-CQZVJVME.js} +2 -2
- package/dist/{chunk-Y43PXON2.js → chunk-EFQUAWWF.js} +577 -546
- package/dist/chunk-EFQUAWWF.js.map +1 -0
- package/dist/{chunk-FPNZMIAW.js → chunk-ELX5YITO.js} +1 -1
- package/dist/chunk-ELX5YITO.js.map +1 -0
- package/dist/chunk-FGAROAUF.js +19 -0
- package/dist/chunk-FGAROAUF.js.map +1 -0
- package/dist/{chunk-HN6MZ2XL.js → chunk-FTNGGR37.js} +641 -466
- package/dist/chunk-FTNGGR37.js.map +1 -0
- package/dist/{chunk-G4F2NWZH.js → chunk-FZ3ZFVAC.js} +4 -4
- package/dist/{chunk-UCCSJX64.js → chunk-GIEUZBQQ.js} +1112 -644
- package/dist/chunk-GIEUZBQQ.js.map +1 -0
- package/dist/{chunk-MEKOWH5E.js → chunk-IVBREL7A.js} +785 -526
- package/dist/chunk-IVBREL7A.js.map +1 -0
- package/dist/{chunk-WSEXFTN4.js → chunk-JBXNU5WD.js} +26 -26
- package/dist/chunk-JBXNU5WD.js.map +1 -0
- package/dist/{chunk-F2VX6TTJ.js → chunk-JRCZHDRG.js} +2 -41
- package/dist/chunk-JRCZHDRG.js.map +1 -0
- package/dist/{chunk-LXYQOOXU.js → chunk-JRW6LCIA.js} +552 -302
- package/dist/chunk-JRW6LCIA.js.map +1 -0
- package/dist/{chunk-TVPH5T4F.js → chunk-KS4I7KVC.js} +16 -22
- package/dist/{chunk-TVPH5T4F.js.map → chunk-KS4I7KVC.js.map} +1 -1
- package/dist/{chunk-J2BBYVGF.js → chunk-MRZP65DZ.js} +1 -117
- package/dist/chunk-MRZP65DZ.js.map +1 -0
- package/dist/{chunk-4ZSLX3LY.js → chunk-OODZCBSM.js} +1 -1
- package/dist/chunk-OODZCBSM.js.map +1 -0
- package/dist/chunk-P4RRC4AO.js +47 -0
- package/dist/chunk-P4RRC4AO.js.map +1 -0
- package/dist/{chunk-ORQD4AUO.js → chunk-PCAY23GS.js} +1 -6
- package/dist/chunk-PCAY23GS.js.map +1 -0
- package/dist/{chunk-NMZUW6VJ.js → chunk-PEJ5OP5B.js} +3 -3
- package/dist/chunk-PEJ5OP5B.js.map +1 -0
- package/dist/{chunk-NHYRIM4I.js → chunk-PIPNDZ6H.js} +304 -194
- package/dist/chunk-PIPNDZ6H.js.map +1 -0
- package/dist/{chunk-DJIN3YUJ.js → chunk-TCJ4TMOW.js} +83 -47
- package/dist/{chunk-DJIN3YUJ.js.map → chunk-TCJ4TMOW.js.map} +1 -1
- package/dist/chunk-UHSUY6H6.js +79 -0
- package/dist/chunk-UHSUY6H6.js.map +1 -0
- package/dist/{chunk-PDD5A43Y.js → chunk-UTL6TEN6.js} +3 -3
- package/dist/{chunk-VJBFCNAU.js → chunk-UW2DKTEM.js} +123 -130
- package/dist/chunk-UW2DKTEM.js.map +1 -0
- package/dist/{chunk-S27DKRI6.js → chunk-VDYEVCQQ.js} +2 -2
- package/dist/{chunk-UFQM46NV.js → chunk-VK3F4N4U.js} +2 -2
- package/dist/{chunk-6ZIC6OG5.js → chunk-VYBTQK25.js} +126 -122
- package/dist/chunk-VYBTQK25.js.map +1 -0
- package/dist/{chunk-RL3Z747H.js → chunk-W2BV2XOC.js} +1491 -700
- package/dist/chunk-W2BV2XOC.js.map +1 -0
- package/dist/{chunk-FUZETA6Z.js → chunk-X6SZGQTK.js} +2 -2
- package/dist/{chunk-CD2LQXY6.js → chunk-XOHE6SKU.js} +14 -16
- package/dist/{chunk-CD2LQXY6.js.map → chunk-XOHE6SKU.js.map} +1 -1
- package/dist/{chunk-ZBB5KQ6B.js → chunk-Y3GO6SG3.js} +73 -66
- package/dist/chunk-Y3GO6SG3.js.map +1 -0
- package/dist/chunk-ZAMHLXNS.js +56 -0
- package/dist/chunk-ZAMHLXNS.js.map +1 -0
- package/dist/{chunk-RHFN7TUV.js → chunk-ZDHCV462.js} +47 -44
- package/dist/{chunk-RHFN7TUV.js.map → chunk-ZDHCV462.js.map} +1 -1
- package/dist/chunk-ZOS3D26Z.js +72 -0
- package/dist/chunk-ZOS3D26Z.js.map +1 -0
- package/dist/design-canvas/index.js +32 -32
- package/dist/design-canvas/index.js.map +1 -1
- package/dist/design-canvas-react/components/DesignCanvas.d.ts +1 -1
- package/dist/design-canvas-react/components/Workspace.d.ts +1 -1
- package/dist/design-canvas-react/components/glyphs.d.ts +31 -40
- package/dist/design-canvas-react/components/transform-math.d.ts +0 -8
- package/dist/design-canvas-react/components/use-workspace-keyboard.d.ts +2 -2
- package/dist/design-canvas-react/contracts.d.ts +2 -2
- package/dist/design-canvas-react/engine.js +1 -1
- package/dist/design-canvas-react/index.js +9 -7
- package/dist/design-canvas-react/index.js.map +1 -1
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/eval/calibration.d.ts +1 -38
- package/dist/eval/index.d.ts +2 -4
- package/dist/eval/index.js +0 -84
- package/dist/eval/index.js.map +1 -1
- package/dist/harness/index.d.ts +1 -1
- package/dist/harness/index.js +1 -1
- package/dist/harness/session-selection.d.ts +2 -2
- package/dist/hub-approvals/index.js +1 -1
- package/dist/hub-approvals/result.d.ts +1 -1
- package/dist/hub-approvals-react/index.js +4 -4
- package/dist/hub-approvals-react/index.js.map +1 -1
- package/dist/hub-approvals-react/parts.d.ts +1 -1
- package/dist/launch-invariants/cli.js +4 -4
- package/dist/launch-invariants/index.js +3 -3
- package/dist/launch-invariants/testing.js +4 -4
- package/dist/legibility/cli.js +1 -1
- package/dist/legibility/index.js +1 -1
- package/dist/{mention-editor-B23OMFT2.js → mention-editor-4BKBMWIK.js} +83 -57
- package/dist/mention-editor-4BKBMWIK.js.map +1 -0
- package/dist/missions/index.js +144 -137
- package/dist/missions/index.js.map +1 -1
- package/dist/operator/index.js +1 -1
- package/dist/peer-floors/check.js +1 -1
- package/dist/peer-floors/cli.js +6 -14
- package/dist/peer-floors/cli.js.map +1 -1
- package/dist/peer-floors/source-entries.d.ts +6 -0
- package/dist/platform/index.js +10 -10
- package/dist/preset-cloudflare/index.js +1 -1
- package/dist/profile/index.d.ts +0 -1
- package/dist/profile/index.js +1 -422
- package/dist/profile/index.js.map +1 -1
- package/dist/profile-editor/server.d.ts +0 -1
- package/dist/profile-editor/server.js +0 -1
- package/dist/profile-editor/server.js.map +1 -1
- package/dist/public-consultation/index.d.ts +2 -2
- package/dist/public-consultation/index.js +6 -6
- package/dist/record/drizzle.js +156 -148
- package/dist/record/drizzle.js.map +1 -1
- package/dist/runtime/index.js +4 -4
- package/dist/runtime/router-turn.js +3 -3
- package/dist/sandbox/box-health.d.ts +1 -1
- package/dist/sandbox/index.js +5 -5
- package/dist/sequences/drizzle.js +5 -15
- package/dist/sequences/drizzle.js.map +1 -1
- package/dist/sequences/index.d.ts +1 -0
- package/dist/sequences/index.js +18 -14
- package/dist/sequences/index.js.map +1 -1
- package/dist/sequences/row-mapping.d.ts +7 -0
- package/dist/sequences-react/components/TimelineEditor.d.ts +0 -40
- package/dist/sequences-react/components/TimelineHistory.d.ts +31 -0
- package/dist/sequences-react/components/glyphs.d.ts +12 -21
- package/dist/sequences-react/components/index.d.ts +0 -2
- package/dist/sequences-react/components/interaction-math.d.ts +3 -3
- package/dist/sequences-react/contracts.d.ts +1 -1
- package/dist/sequences-react/engine/snap.d.ts +2 -2
- package/dist/sequences-react/index.js +4 -4
- package/dist/sequences-react/index.js.map +1 -1
- package/dist/settings-react/index.js +13 -30
- package/dist/settings-react/index.js.map +1 -1
- package/dist/settings-react/timezone-picker.d.ts +0 -6
- package/dist/signoff/browser-budget.d.ts +6 -1
- package/dist/signoff/cli.d.ts +0 -7
- package/dist/signoff/cli.js +1 -2
- package/dist/signoff/cli.js.map +1 -1
- package/dist/signoff/index.js +1 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.js +5 -25
- package/dist/skills/marketplace.d.ts +1 -75
- package/dist/skills-placement/box.js +3 -4
- package/dist/skills-placement/box.js.map +1 -1
- package/dist/skills-placement/index.js +3 -4
- package/dist/spend/cli-args.d.ts +1 -1
- package/dist/spend/cli.js +3 -3
- package/dist/spend/cli.js.map +1 -1
- package/dist/spend/index.js +1 -1
- package/dist/stories/design-canvas/fixtures.d.ts +1 -14
- package/dist/stream/index.js +17 -17
- package/dist/studio/generation.d.ts +1 -1
- package/dist/studio/index.js +1 -1
- package/dist/studio-react/index.js +353 -184
- package/dist/studio-react/index.js.map +1 -1
- package/dist/studio-react/studio-composer.d.ts +1 -5
- package/dist/studio-react/studio-history-screen.d.ts +1 -1
- package/dist/teams/invitations-api.d.ts +3 -3
- package/dist/teams/invitations-api.js +74 -72
- package/dist/teams/invitations-api.js.map +1 -1
- package/dist/teams/member-sync.d.ts +2 -0
- package/dist/teams/members-api.d.ts +2 -2
- package/dist/teams/members-api.js +1 -1
- package/dist/teams-react/index.js +28 -45
- package/dist/teams-react/index.js.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/mcp-arguments.d.ts +1 -1
- package/dist/trace/index.d.ts +1 -18
- package/dist/trace/index.js +1 -36
- package/dist/trace/index.js.map +1 -1
- package/dist/trace/mission-flow.d.ts +1 -59
- package/dist/turn-health/index.d.ts +1 -1
- package/dist/turn-health/index.js +2 -2
- package/dist/turn-health/sink.d.ts +2 -1
- package/dist/turn-trace/index.js +2 -4
- package/dist/turn-trace/recorder.d.ts +0 -2
- package/dist/vault/VaultPane.d.ts +0 -20
- package/dist/vault/VaultPaneOperations.d.ts +318 -0
- package/dist/vault/index.js +2 -1
- package/dist/vault/index.js.map +1 -1
- package/dist/vault/lazy.js +1 -1
- package/dist/web-react/agent-profile-editor.d.ts +1 -2
- package/dist/web-react/agent-profile-editor.js +6 -5
- package/dist/web-react/chat-composer.d.ts +1 -1
- package/dist/web-react/durable-plan-flow.d.ts +6 -1
- package/dist/web-react/editor-glyphs.d.ts +12 -0
- package/dist/web-react/focus-navigation.d.ts +12 -0
- package/dist/web-react/history-controls.d.ts +37 -0
- package/dist/web-react/index.js +36 -34
- package/dist/web-react/interaction-question-card.d.ts +1 -1
- package/dist/web-react/record-grid-writes.d.ts +31 -0
- package/dist/web-react/record-grid.d.ts +1 -48
- package/dist/web-react/session-history-panel.d.ts +1 -9
- package/dist/web-react/use-document-dark.d.ts +1 -0
- package/dist/workspace-export/engine.d.ts +1 -6
- package/dist/workspace-export/index.js +198 -185
- package/dist/workspace-export/index.js.map +1 -1
- package/dist/workspace-export/routes.d.ts +1 -1
- package/dist/workspace-react/index.js +9 -8
- package/dist/workspace-react/index.js.map +1 -1
- package/package.json +7 -17
- package/dist/VaultPane-RXL3WLA2.js +0 -7
- package/dist/agent-profiles/reaper.d.ts +0 -31
- package/dist/agent-profiles/reaper.js +0 -29
- package/dist/agent-profiles/reaper.js.map +0 -1
- package/dist/chunk-4ZSLX3LY.js.map +0 -1
- package/dist/chunk-5IM2CLYX.js.map +0 -1
- package/dist/chunk-6OSJNJA2.js +0 -251
- package/dist/chunk-6OSJNJA2.js.map +0 -1
- package/dist/chunk-6PRQ45QE.js.map +0 -1
- package/dist/chunk-6ZIC6OG5.js.map +0 -1
- package/dist/chunk-BDEBQ4WO.js +0 -38
- package/dist/chunk-BDEBQ4WO.js.map +0 -1
- package/dist/chunk-BOQ4HVVH.js.map +0 -1
- package/dist/chunk-F2VX6TTJ.js.map +0 -1
- package/dist/chunk-FPNZMIAW.js.map +0 -1
- package/dist/chunk-HN6MZ2XL.js.map +0 -1
- package/dist/chunk-J2BBYVGF.js.map +0 -1
- package/dist/chunk-KJODHPWM.js.map +0 -1
- package/dist/chunk-LTWJYNEC.js +0 -100
- package/dist/chunk-LTWJYNEC.js.map +0 -1
- package/dist/chunk-LXYQOOXU.js.map +0 -1
- package/dist/chunk-MEKOWH5E.js.map +0 -1
- package/dist/chunk-NHYRIM4I.js.map +0 -1
- package/dist/chunk-NMZUW6VJ.js.map +0 -1
- package/dist/chunk-ORQD4AUO.js.map +0 -1
- package/dist/chunk-R4X5474U.js.map +0 -1
- package/dist/chunk-RL3Z747H.js.map +0 -1
- package/dist/chunk-TXUAGSFR.js.map +0 -1
- package/dist/chunk-UCCSJX64.js.map +0 -1
- package/dist/chunk-VJBFCNAU.js.map +0 -1
- package/dist/chunk-WSEXFTN4.js.map +0 -1
- package/dist/chunk-Y43PXON2.js.map +0 -1
- package/dist/chunk-ZBB5KQ6B.js.map +0 -1
- package/dist/eval/parity.d.ts +0 -74
- package/dist/mention-editor-B23OMFT2.js.map +0 -1
- package/dist/profile/humanizer-skill.d.ts +0 -23
- package/dist/profile/humanizer-skill.vendored.d.ts +0 -4
- package/dist/sequences-react/components/BrandMark.d.ts +0 -10
- package/dist/skills/marketplace-drizzle.d.ts +0 -121
- package/dist/skills/marketplace-drizzle.js +0 -34
- package/dist/skills/marketplace-drizzle.js.map +0 -1
- package/dist/teams-react/components/BrandMark.d.ts +0 -10
- /package/dist/{DesignCanvas-L6J72JQ2.js.map → DesignCanvas-IQKYAEC4.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-QFQD63MR.js.map → DesignCanvasEditor-O7OCZTGC.js.map} +0 -0
- /package/dist/{TimelineEditor-7KBPJQLT.js.map → TimelineEditor-VB2UJ34D.js.map} +0 -0
- /package/dist/{VaultPane-RXL3WLA2.js.map → VaultPane-AYW7CO33.js.map} +0 -0
- /package/dist/{chunk-ATQQCG4I.js.map → chunk-2VJLLRVV.js.map} +0 -0
- /package/dist/{chunk-MDRH3SDA.js.map → chunk-54YIL7WM.js.map} +0 -0
- /package/dist/{chunk-6QJ3GB3A.js.map → chunk-5GSZGTPJ.js.map} +0 -0
- /package/dist/{chunk-ZDPUC6CM.js.map → chunk-6ZVSMA4T.js.map} +0 -0
- /package/dist/{chunk-LO6VQ35O.js.map → chunk-CQZVJVME.js.map} +0 -0
- /package/dist/{chunk-G4F2NWZH.js.map → chunk-FZ3ZFVAC.js.map} +0 -0
- /package/dist/{chunk-PDD5A43Y.js.map → chunk-UTL6TEN6.js.map} +0 -0
- /package/dist/{chunk-S27DKRI6.js.map → chunk-VDYEVCQQ.js.map} +0 -0
- /package/dist/{chunk-UFQM46NV.js.map → chunk-VK3F4N4U.js.map} +0 -0
- /package/dist/{chunk-FUZETA6Z.js.map → chunk-X6SZGQTK.js.map} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/web-react/use-infinite-scroll.ts
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
function rethrowAsync(error) {
|
|
4
|
+
queueMicrotask(() => {
|
|
5
|
+
throw error;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function useInfiniteScroll(onLoadMore, { enabled, root, rootMargin = "300px" }) {
|
|
9
|
+
const [sentinel, setSentinel] = useState(null);
|
|
10
|
+
const sentinelRef = useCallback((node) => setSentinel(node), []);
|
|
11
|
+
const onLoadMoreRef = useRef(onLoadMore);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
onLoadMoreRef.current = onLoadMore;
|
|
14
|
+
}, [onLoadMore]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!sentinel || !enabled) return;
|
|
17
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
18
|
+
const observer = new IntersectionObserver(
|
|
19
|
+
(entries) => {
|
|
20
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
21
|
+
try {
|
|
22
|
+
onLoadMoreRef.current();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
rethrowAsync(error);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{ root: root?.current ?? null, rootMargin }
|
|
28
|
+
);
|
|
29
|
+
observer.observe(sentinel);
|
|
30
|
+
return () => observer.disconnect();
|
|
31
|
+
}, [sentinel, enabled, root, rootMargin]);
|
|
32
|
+
return sentinelRef;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/web-react/history-controls.ts
|
|
36
|
+
import { useCallback as useCallback2, useEffect as useEffect2 } from "react";
|
|
37
|
+
function useHistoryControls({ items, nextCursor, phase, loadMore }, { lastOpRef, setReloadKey, resetAbortRef, loadMoreAbortRef }) {
|
|
38
|
+
const retry = useCallback2(() => {
|
|
39
|
+
if (lastOpRef.current === "more") loadMore();
|
|
40
|
+
else setReloadKey((key) => key + 1);
|
|
41
|
+
}, [loadMore]);
|
|
42
|
+
const reload = useCallback2(() => {
|
|
43
|
+
setReloadKey((key) => key + 1);
|
|
44
|
+
}, []);
|
|
45
|
+
useEffect2(() => () => {
|
|
46
|
+
resetAbortRef.current?.abort();
|
|
47
|
+
loadMoreAbortRef.current?.abort();
|
|
48
|
+
}, []);
|
|
49
|
+
return {
|
|
50
|
+
items,
|
|
51
|
+
hasMore: nextCursor !== null,
|
|
52
|
+
isLoadingFirst: phase === "loadingFirst",
|
|
53
|
+
isLoadingMore: phase === "loadingMore",
|
|
54
|
+
isError: phase === "error",
|
|
55
|
+
loadMore,
|
|
56
|
+
retry,
|
|
57
|
+
reload
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function loadHistoryPage(request, onPage, { controller, seq, seqRef, setPhase, onSettled }) {
|
|
61
|
+
try {
|
|
62
|
+
const page = await request();
|
|
63
|
+
if (seq !== seqRef.current) return;
|
|
64
|
+
onPage(page);
|
|
65
|
+
setPhase("idle");
|
|
66
|
+
} catch {
|
|
67
|
+
if (controller.signal.aborted || seq !== seqRef.current) return;
|
|
68
|
+
setPhase("error");
|
|
69
|
+
} finally {
|
|
70
|
+
if (seq === seqRef.current) onSettled?.();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
useInfiniteScroll,
|
|
76
|
+
useHistoryControls,
|
|
77
|
+
loadHistoryPage
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=chunk-UHSUY6H6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/web-react/use-infinite-scroll.ts","../src/web-react/history-controls.ts"],"sourcesContent":["/** Intersection-observer admission for paged lists. */\nimport { useCallback, useEffect, useRef, useState, type RefObject } from 'react'\n\n// ---------------------------------------------------------------------------\n// useInfiniteScroll\n// ---------------------------------------------------------------------------\n\nexport interface UseInfiniteScrollOptions {\n /** Only fire `onLoadMore` while true (a next page exists, none in flight). */\n enabled: boolean\n /** Scroll container the sentinel lives in. Defaults to the viewport. */\n root?: RefObject<HTMLElement | null>\n /** Prefetch distance before the sentinel is actually reached. */\n rootMargin?: string\n}\n\nfunction rethrowAsync(error: unknown) {\n queueMicrotask(() => {\n throw error\n })\n}\n\n/**\n * Fires `onLoadMore` when a sentinel element scrolls into view. Returns a ref\n * callback for that sentinel (typically the last element in a list).\n *\n * The observer is re-created whenever `enabled` flips, so a short first page\n * that leaves the sentinel on-screen keeps loading: when a load finishes and\n * `enabled` returns to true, the fresh observer re-reads the current\n * intersection state and fires again until the sentinel is pushed off-screen.\n */\nexport function useInfiniteScroll(\n onLoadMore: () => void,\n { enabled, root, rootMargin = '300px' }: UseInfiniteScrollOptions,\n): (node: HTMLElement | null) => void {\n const [sentinel, setSentinel] = useState<HTMLElement | null>(null)\n const sentinelRef = useCallback((node: HTMLElement | null) => setSentinel(node), [])\n const onLoadMoreRef = useRef(onLoadMore)\n\n useEffect(() => {\n onLoadMoreRef.current = onLoadMore\n }, [onLoadMore])\n\n useEffect(() => {\n if (!sentinel || !enabled) return\n if (typeof IntersectionObserver === 'undefined') return\n const observer = new IntersectionObserver(\n (entries) => {\n if (!entries.some((entry) => entry.isIntersecting)) return\n try {\n onLoadMoreRef.current()\n } catch (error) {\n rethrowAsync(error)\n }\n },\n { root: root?.current ?? null, rootMargin },\n )\n observer.observe(sentinel)\n return () => observer.disconnect()\n }, [sentinel, enabled, root, rootMargin])\n\n return sentinelRef\n}\n","import { useCallback, useEffect } from 'react'\n\n/** Cursor histories share retry, reload, cancellation and their visible loading projection. */\nexport function useHistoryControls<T>({ items, nextCursor, phase, loadMore }: {\n items: T[]\n nextCursor: string | null\n phase: 'idle' | 'loadingFirst' | 'loadingMore' | 'error'\n loadMore: () => void\n}, { lastOpRef, setReloadKey, resetAbortRef, loadMoreAbortRef }: {\n lastOpRef: { current: 'first' | 'more' }\n setReloadKey: (update: (current: number) => number) => void\n resetAbortRef: { current: AbortController | null }\n loadMoreAbortRef: { current: AbortController | null }\n}) {\n const retry = useCallback(() => {\n if (lastOpRef.current === 'more') loadMore()\n else setReloadKey((key) => key + 1)\n }, [loadMore])\n const reload = useCallback(() => {\n setReloadKey((key) => key + 1)\n }, [])\n useEffect(() => () => {\n resetAbortRef.current?.abort()\n loadMoreAbortRef.current?.abort()\n }, [])\n return {\n items,\n hasMore: nextCursor !== null,\n isLoadingFirst: phase === 'loadingFirst',\n isLoadingMore: phase === 'loadingMore',\n isError: phase === 'error',\n loadMore,\n retry,\n reload,\n }\n}\n\n\n/** Apply a page only to the view that requested it; cancellation and failures share one policy. */\nexport async function loadHistoryPage<T>(request: () => Promise<T>, onPage: (page: T) => void, { controller, seq, seqRef, setPhase, onSettled }: {\n controller: AbortController\n seq: number\n seqRef: { current: number }\n setPhase: (phase: 'idle' | 'loadingFirst' | 'loadingMore' | 'error') => void\n onSettled?: () => void\n}): Promise<void> {\n try {\n const page = await request()\n if (seq !== seqRef.current) return\n onPage(page)\n setPhase('idle')\n } catch {\n if (controller.signal.aborted || seq !== seqRef.current) return\n setPhase('error')\n } finally {\n if (seq === seqRef.current) onSettled?.()\n }\n}\n"],"mappings":";AACA,SAAS,aAAa,WAAW,QAAQ,gBAAgC;AAezE,SAAS,aAAa,OAAgB;AACpC,iBAAe,MAAM;AACnB,UAAM;AAAA,EACR,CAAC;AACH;AAWO,SAAS,kBACd,YACA,EAAE,SAAS,MAAM,aAAa,QAAQ,GACF;AACpC,QAAM,CAAC,UAAU,WAAW,IAAI,SAA6B,IAAI;AACjE,QAAM,cAAc,YAAY,CAAC,SAA6B,YAAY,IAAI,GAAG,CAAC,CAAC;AACnF,QAAM,gBAAgB,OAAO,UAAU;AAEvC,YAAU,MAAM;AACd,kBAAc,UAAU;AAAA,EAC1B,GAAG,CAAC,UAAU,CAAC;AAEf,YAAU,MAAM;AACd,QAAI,CAAC,YAAY,CAAC,QAAS;AAC3B,QAAI,OAAO,yBAAyB,YAAa;AACjD,UAAM,WAAW,IAAI;AAAA,MACnB,CAAC,YAAY;AACX,YAAI,CAAC,QAAQ,KAAK,CAAC,UAAU,MAAM,cAAc,EAAG;AACpD,YAAI;AACF,wBAAc,QAAQ;AAAA,QACxB,SAAS,OAAO;AACd,uBAAa,KAAK;AAAA,QACpB;AAAA,MACF;AAAA,MACA,EAAE,MAAM,MAAM,WAAW,MAAM,WAAW;AAAA,IAC5C;AACA,aAAS,QAAQ,QAAQ;AACzB,WAAO,MAAM,SAAS,WAAW;AAAA,EACnC,GAAG,CAAC,UAAU,SAAS,MAAM,UAAU,CAAC;AAExC,SAAO;AACT;;;AC9DA,SAAS,eAAAA,cAAa,aAAAC,kBAAiB;AAGhC,SAAS,mBAAsB,EAAE,OAAO,YAAY,OAAO,SAAS,GAKxE,EAAE,WAAW,cAAc,eAAe,iBAAiB,GAK3D;AACD,QAAM,QAAQD,aAAY,MAAM;AAC9B,QAAI,UAAU,YAAY,OAAQ,UAAS;AAAA,QACtC,cAAa,CAAC,QAAQ,MAAM,CAAC;AAAA,EACpC,GAAG,CAAC,QAAQ,CAAC;AACb,QAAM,SAASA,aAAY,MAAM;AAC/B,iBAAa,CAAC,QAAQ,MAAM,CAAC;AAAA,EAC/B,GAAG,CAAC,CAAC;AACL,EAAAC,WAAU,MAAM,MAAM;AACpB,kBAAc,SAAS,MAAM;AAC7B,qBAAiB,SAAS,MAAM;AAAA,EAClC,GAAG,CAAC,CAAC;AACL,SAAO;AAAA,IACL;AAAA,IACA,SAAS,eAAe;AAAA,IACxB,gBAAgB,UAAU;AAAA,IAC1B,eAAe,UAAU;AAAA,IACzB,SAAS,UAAU;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAIA,eAAsB,gBAAmB,SAA2B,QAA2B,EAAE,YAAY,KAAK,QAAQ,UAAU,UAAU,GAM5H;AAChB,MAAI;AACF,UAAM,OAAO,MAAM,QAAQ;AAC3B,QAAI,QAAQ,OAAO,QAAS;AAC5B,WAAO,IAAI;AACX,aAAS,MAAM;AAAA,EACjB,QAAQ;AACN,QAAI,WAAW,OAAO,WAAW,QAAQ,OAAO,QAAS;AACzD,aAAS,OAAO;AAAA,EAClB,UAAE;AACA,QAAI,QAAQ,OAAO,QAAS,aAAY;AAAA,EAC1C;AACF;","names":["useCallback","useEffect"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/design-canvas-react/lazy.tsx
|
|
2
2
|
import { lazy } from "react";
|
|
3
3
|
var DesignCanvasLazy = lazy(
|
|
4
|
-
() => import("./DesignCanvasEditor-
|
|
4
|
+
() => import("./DesignCanvasEditor-O7OCZTGC.js").then((m) => ({ default: m.DesignCanvasEditor }))
|
|
5
5
|
);
|
|
6
6
|
var DesignCanvasChromeLazy = lazy(
|
|
7
|
-
() => import("./DesignCanvas-
|
|
7
|
+
() => import("./DesignCanvas-IQKYAEC4.js").then((m) => ({ default: m.DesignCanvas }))
|
|
8
8
|
);
|
|
9
9
|
|
|
10
10
|
export {
|
|
11
11
|
DesignCanvasLazy,
|
|
12
12
|
DesignCanvasChromeLazy
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=chunk-
|
|
14
|
+
//# sourceMappingURL=chunk-UTL6TEN6.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nextCallIndex,
|
|
3
3
|
tracedModelFetch
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VK3F4N4U.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_TANGLE_ROUTER_BASE_URL
|
|
7
7
|
} from "./chunk-D6UJEOZQ.js";
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "./chunk-AMUXRAUO.js";
|
|
11
11
|
import {
|
|
12
12
|
turnTraceId
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PCAY23GS.js";
|
|
14
14
|
|
|
15
15
|
// src/runtime/loop.ts
|
|
16
16
|
import {
|
|
@@ -191,11 +191,7 @@ function servedFromBody(model, requestedModel) {
|
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
193
|
async function* streamChatCompletions(doFetch, url, apiKey, body, attribution, headers) {
|
|
194
|
-
const res = await doFetch
|
|
195
|
-
method: "POST",
|
|
196
|
-
headers: { ...headers, Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "text/event-stream" },
|
|
197
|
-
body: JSON.stringify(body)
|
|
198
|
-
});
|
|
194
|
+
const res = await postOpenAIEventStream(doFetch, url, apiKey, body, headers);
|
|
199
195
|
if (!res.ok || !res.body) throw await httpFailure(res, "stream");
|
|
200
196
|
let reported = false;
|
|
201
197
|
const report = (served) => {
|
|
@@ -207,30 +203,16 @@ async function* streamChatCompletions(doFetch, url, apiKey, body, attribution, h
|
|
|
207
203
|
const served = servedFromHeader(res, attribution.requestedModel);
|
|
208
204
|
if (served) report(served);
|
|
209
205
|
}
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
buffer += decoder.decode(value, { stream: true });
|
|
217
|
-
const lines = buffer.split("\n");
|
|
218
|
-
buffer = lines.pop() ?? "";
|
|
219
|
-
for (const line of lines) {
|
|
220
|
-
const trimmed = line.trim();
|
|
221
|
-
if (!trimmed.startsWith("data:")) continue;
|
|
222
|
-
const data = trimmed.slice(5).trim();
|
|
223
|
-
if (data === "[DONE]") return;
|
|
224
|
-
let chunk;
|
|
225
|
-
try {
|
|
226
|
-
chunk = JSON.parse(data);
|
|
227
|
-
} catch {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
if (attribution && !reported && chunk.model) report(servedFromBody(chunk.model, attribution.requestedModel));
|
|
231
|
-
if (chunk.error) throw streamFailure(chunk.error);
|
|
232
|
-
yield chunk;
|
|
206
|
+
for await (const data of readOpenAISseFrames(res.body)) {
|
|
207
|
+
let chunk;
|
|
208
|
+
try {
|
|
209
|
+
chunk = JSON.parse(data);
|
|
210
|
+
} catch {
|
|
211
|
+
continue;
|
|
233
212
|
}
|
|
213
|
+
if (attribution && !reported && chunk.model) report(servedFromBody(chunk.model, attribution.requestedModel));
|
|
214
|
+
if (chunk.error) throw streamFailure(chunk.error);
|
|
215
|
+
yield chunk;
|
|
234
216
|
}
|
|
235
217
|
}
|
|
236
218
|
function streamFailure(failure) {
|
|
@@ -294,11 +276,7 @@ function createOpenAIResponsesTurn(opts) {
|
|
|
294
276
|
};
|
|
295
277
|
}
|
|
296
278
|
async function* streamResponses(doFetch, url, apiKey, body, attribution, headers) {
|
|
297
|
-
const res = await doFetch
|
|
298
|
-
method: "POST",
|
|
299
|
-
headers: { ...headers, Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "text/event-stream" },
|
|
300
|
-
body: JSON.stringify(body)
|
|
301
|
-
});
|
|
279
|
+
const res = await postOpenAIEventStream(doFetch, url, apiKey, body, headers);
|
|
302
280
|
if (!res.ok || !res.body) throw await httpFailure(res, "responses");
|
|
303
281
|
let reported = false;
|
|
304
282
|
const report = (served) => {
|
|
@@ -310,10 +288,68 @@ async function* streamResponses(doFetch, url, apiKey, body, attribution, headers
|
|
|
310
288
|
const served = servedFromHeader(res, attribution.requestedModel);
|
|
311
289
|
if (served) report(served);
|
|
312
290
|
}
|
|
313
|
-
|
|
291
|
+
let lastSummary = null;
|
|
292
|
+
for await (const data of readOpenAISseFrames(res.body)) {
|
|
293
|
+
let event;
|
|
294
|
+
try {
|
|
295
|
+
event = JSON.parse(data);
|
|
296
|
+
} catch {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
switch (event.type) {
|
|
300
|
+
case "response.output_text.delta":
|
|
301
|
+
if (event.delta) yield { choices: [{ delta: { content: event.delta } }] };
|
|
302
|
+
break;
|
|
303
|
+
case "response.reasoning_summary_text.delta": {
|
|
304
|
+
if (!event.delta) break;
|
|
305
|
+
const part = `${event.output_index ?? 0}:${event.summary_index ?? 0}`;
|
|
306
|
+
const lead = lastSummary !== null && lastSummary !== part ? "\n\n" : "";
|
|
307
|
+
lastSummary = part;
|
|
308
|
+
yield { choices: [{ delta: { reasoning_content: lead + event.delta } }] };
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case "response.output_item.added":
|
|
312
|
+
if (event.item?.type === "function_call" && event.item.name) {
|
|
313
|
+
yield { choices: [{ delta: { tool_calls: [{
|
|
314
|
+
index: event.output_index ?? 0,
|
|
315
|
+
...event.item.call_id ? { id: event.item.call_id } : {},
|
|
316
|
+
function: { name: event.item.name, arguments: event.item.arguments ?? "" }
|
|
317
|
+
}] } }] };
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
case "response.function_call_arguments.delta":
|
|
321
|
+
if (event.delta) yield { choices: [{ delta: { tool_calls: [{ index: event.output_index ?? 0, function: { arguments: event.delta } }] } }] };
|
|
322
|
+
break;
|
|
323
|
+
case "response.completed":
|
|
324
|
+
case "response.incomplete": {
|
|
325
|
+
const model = event.response?.model;
|
|
326
|
+
if (attribution && !reported && model) report(servedFromBody(model, attribution.requestedModel));
|
|
327
|
+
const usage = event.response?.usage;
|
|
328
|
+
yield {
|
|
329
|
+
...model ? { model } : {},
|
|
330
|
+
choices: [],
|
|
331
|
+
...usage ? { usage: {
|
|
332
|
+
prompt_tokens: usage.input_tokens ?? 0,
|
|
333
|
+
completion_tokens: usage.output_tokens ?? 0,
|
|
334
|
+
...usage.input_tokens_details ? { prompt_tokens_details: usage.input_tokens_details } : {}
|
|
335
|
+
} } : {}
|
|
336
|
+
};
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
case "response.failed":
|
|
340
|
+
case "error": {
|
|
341
|
+
const failure = event.response?.error ?? event.error ?? { message: event.message };
|
|
342
|
+
throw new Error(`OpenAI-compat responses failed: ${(failure?.code ? `${failure.code}: ` : "") + (failure?.message ?? "no detail")}`.slice(0, 300));
|
|
343
|
+
}
|
|
344
|
+
default:
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function* readOpenAISseFrames(body) {
|
|
350
|
+
const reader = body.getReader();
|
|
314
351
|
const decoder = new TextDecoder();
|
|
315
352
|
let buffer = "";
|
|
316
|
-
let lastSummary = null;
|
|
317
353
|
for (; ; ) {
|
|
318
354
|
const { done, value } = await reader.read();
|
|
319
355
|
if (done) break;
|
|
@@ -325,63 +361,17 @@ async function* streamResponses(doFetch, url, apiKey, body, attribution, headers
|
|
|
325
361
|
if (!trimmed.startsWith("data:")) continue;
|
|
326
362
|
const data = trimmed.slice(5).trim();
|
|
327
363
|
if (data === "[DONE]") return;
|
|
328
|
-
|
|
329
|
-
try {
|
|
330
|
-
event = JSON.parse(data);
|
|
331
|
-
} catch {
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
switch (event.type) {
|
|
335
|
-
case "response.output_text.delta":
|
|
336
|
-
if (event.delta) yield { choices: [{ delta: { content: event.delta } }] };
|
|
337
|
-
break;
|
|
338
|
-
case "response.reasoning_summary_text.delta": {
|
|
339
|
-
if (!event.delta) break;
|
|
340
|
-
const part = `${event.output_index ?? 0}:${event.summary_index ?? 0}`;
|
|
341
|
-
const lead = lastSummary !== null && lastSummary !== part ? "\n\n" : "";
|
|
342
|
-
lastSummary = part;
|
|
343
|
-
yield { choices: [{ delta: { reasoning_content: lead + event.delta } }] };
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case "response.output_item.added":
|
|
347
|
-
if (event.item?.type === "function_call" && event.item.name) {
|
|
348
|
-
yield { choices: [{ delta: { tool_calls: [{
|
|
349
|
-
index: event.output_index ?? 0,
|
|
350
|
-
...event.item.call_id ? { id: event.item.call_id } : {},
|
|
351
|
-
function: { name: event.item.name, arguments: event.item.arguments ?? "" }
|
|
352
|
-
}] } }] };
|
|
353
|
-
}
|
|
354
|
-
break;
|
|
355
|
-
case "response.function_call_arguments.delta":
|
|
356
|
-
if (event.delta) yield { choices: [{ delta: { tool_calls: [{ index: event.output_index ?? 0, function: { arguments: event.delta } }] } }] };
|
|
357
|
-
break;
|
|
358
|
-
case "response.completed":
|
|
359
|
-
case "response.incomplete": {
|
|
360
|
-
const model = event.response?.model;
|
|
361
|
-
if (attribution && !reported && model) report(servedFromBody(model, attribution.requestedModel));
|
|
362
|
-
const usage = event.response?.usage;
|
|
363
|
-
yield {
|
|
364
|
-
...model ? { model } : {},
|
|
365
|
-
choices: [],
|
|
366
|
-
...usage ? { usage: {
|
|
367
|
-
prompt_tokens: usage.input_tokens ?? 0,
|
|
368
|
-
completion_tokens: usage.output_tokens ?? 0,
|
|
369
|
-
...usage.input_tokens_details ? { prompt_tokens_details: usage.input_tokens_details } : {}
|
|
370
|
-
} } : {}
|
|
371
|
-
};
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
case "response.failed":
|
|
375
|
-
case "error": {
|
|
376
|
-
const failure = event.response?.error ?? event.error ?? { message: event.message };
|
|
377
|
-
throw new Error(`OpenAI-compat responses failed: ${(failure?.code ? `${failure.code}: ` : "") + (failure?.message ?? "no detail")}`.slice(0, 300));
|
|
378
|
-
}
|
|
379
|
-
default:
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
364
|
+
yield data;
|
|
382
365
|
}
|
|
383
366
|
}
|
|
384
367
|
}
|
|
368
|
+
function postOpenAIEventStream(doFetch, url, apiKey, body, headers) {
|
|
369
|
+
return doFetch(url, {
|
|
370
|
+
method: "POST",
|
|
371
|
+
headers: { ...headers, Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "text/event-stream" },
|
|
372
|
+
body: JSON.stringify(body)
|
|
373
|
+
});
|
|
374
|
+
}
|
|
385
375
|
|
|
386
376
|
// src/runtime/turn-knowledge.ts
|
|
387
377
|
var DEFAULT_FILE_BYTES = 8e3;
|
|
@@ -688,41 +678,8 @@ async function runRouterTurn(options) {
|
|
|
688
678
|
});
|
|
689
679
|
const traceId = options.traceId !== void 0 ? turnTraceId(options.traceId) : options.trace?.traceId;
|
|
690
680
|
const { trace } = options;
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
const gzipAbove = options.gzipRequestAboveBytes ?? (URL.canParse(options.baseUrl ?? DEFAULT_TANGLE_ROUTER_BASE_URL) && new URL(options.baseUrl ?? DEFAULT_TANGLE_ROUTER_BASE_URL).origin === new URL(DEFAULT_TANGLE_ROUTER_BASE_URL).origin ? 32 * 1024 : void 0);
|
|
694
|
-
const baseFetch = gzipAbove !== void 0 && gzipAbove >= 0 ? gzipRequestBodies(options.fetchImpl ?? fetch, gzipAbove) : options.fetchImpl;
|
|
695
|
-
const sendOnce = trace ? tracedModelFetch(trace, baseFetch ?? fetch, {
|
|
696
|
-
onSpan: (span) => {
|
|
697
|
-
lastModelSpan = span;
|
|
698
|
-
span.set({ "gen_ai.request.model": currentModel });
|
|
699
|
-
}
|
|
700
|
-
}) : baseFetch;
|
|
701
|
-
const fetchImpl = signal || attempts > 1 || attemptTimeoutMs ? async (input, init) => {
|
|
702
|
-
const firstSentAt = Date.now();
|
|
703
|
-
const spent = (attempt) => attempts === 1 || attempt >= attempts && Date.now() - firstSentAt >= RETRY_WINDOW_MS;
|
|
704
|
-
for (let attempt = 1; ; attempt++) {
|
|
705
|
-
signal?.throwIfAborted();
|
|
706
|
-
const signals = [signal, attemptTimeoutMs ? AbortSignal.timeout(attemptTimeoutMs) : void 0].filter((value) => Boolean(value));
|
|
707
|
-
const attemptSignal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
708
|
-
const backoff = () => Math.min(MAX_RETRY_DELAY_MS, baseDelayMs * 2 ** (attempt - 1)) * (0.5 + Math.random() / 2);
|
|
709
|
-
const wait = (ms, reason) => trace ? trace.measure("model.retry_wait", "other", () => pause(ms), { "retry.attempt": attempt, "retry.reason": reason, "retry.wait_ms": Math.round(ms) }) : pause(ms);
|
|
710
|
-
let response;
|
|
711
|
-
try {
|
|
712
|
-
response = await (sendOnce ?? fetch)(input, { ...init, ...attemptSignal ? { signal: attemptSignal } : {} });
|
|
713
|
-
} catch (error) {
|
|
714
|
-
if (signal?.aborted || spent(attempt)) throw error;
|
|
715
|
-
await wait(backoff(), "send_failed");
|
|
716
|
-
continue;
|
|
717
|
-
}
|
|
718
|
-
if (spent(attempt) || !RETRY_STATUS.has(response.status)) return response;
|
|
719
|
-
if (DEAD_CREDENTIAL_CATEGORIES.has(response.headers.get("x-tangle-failure-category") ?? "")) return response;
|
|
720
|
-
const retryAfter = Number(response.headers.get("retry-after"));
|
|
721
|
-
await response.body?.cancel().catch(() => {
|
|
722
|
-
});
|
|
723
|
-
await wait(Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter * 1e3, MAX_RETRY_DELAY_MS) : backoff(), `http_${response.status}`);
|
|
724
|
-
}
|
|
725
|
-
} : sendOnce;
|
|
681
|
+
const transportState = { currentModel: options.model, lastModelSpan: void 0 };
|
|
682
|
+
const { fetchImpl } = createRouterTurnTransport(options, trace, transportState, signal, attempts, attemptTimeoutMs, baseDelayMs, pause);
|
|
726
683
|
const extraBody = {
|
|
727
684
|
...options.maxTokens ? { max_tokens: options.maxTokens } : {},
|
|
728
685
|
...options.maxCompletionTokens ? { max_completion_tokens: options.maxCompletionTokens } : {},
|
|
@@ -752,7 +709,7 @@ async function runRouterTurn(options) {
|
|
|
752
709
|
...fetchImpl ? { fetchImpl } : {},
|
|
753
710
|
onServedModel: (served) => {
|
|
754
711
|
servedModel = served.servedModel;
|
|
755
|
-
if (served.servedModel) lastModelSpan?.set({ "gen_ai.response.model": served.servedModel });
|
|
712
|
+
if (served.servedModel) transportState.lastModelSpan?.set({ "gen_ai.response.model": served.servedModel });
|
|
756
713
|
}
|
|
757
714
|
});
|
|
758
715
|
const segments = [];
|
|
@@ -780,7 +737,7 @@ async function runRouterTurn(options) {
|
|
|
780
737
|
return "placement_refused";
|
|
781
738
|
}
|
|
782
739
|
}
|
|
783
|
-
currentModel = model;
|
|
740
|
+
transportState.currentModel = model;
|
|
784
741
|
const streamTurn = streamTurnFor(model);
|
|
785
742
|
for await (const step of streamToolLoop({
|
|
786
743
|
systemPrompt: options.systemPrompt,
|
|
@@ -840,7 +797,7 @@ async function runRouterTurn(options) {
|
|
|
840
797
|
reasoning.chars += event.text.length;
|
|
841
798
|
emit({ type: "reasoning", delta: event.text });
|
|
842
799
|
} else if (event.type === "usage") {
|
|
843
|
-
addCallUsage(usage, event.usage, lastModelSpan);
|
|
800
|
+
addCallUsage(usage, event.usage, transportState.lastModelSpan);
|
|
844
801
|
emit({ type: "usage", ...event.usage });
|
|
845
802
|
} else if (event.type === "tool_call_start") {
|
|
846
803
|
emit({ type: "tool_start", toolName: byFunction.get(event.toolName)?.name ?? event.toolName });
|
|
@@ -957,6 +914,42 @@ async function runRouterTurn(options) {
|
|
|
957
914
|
}
|
|
958
915
|
return outcome();
|
|
959
916
|
}
|
|
917
|
+
function createRouterTurnTransport(options, trace, transportState, signal, attempts, attemptTimeoutMs, baseDelayMs, pause) {
|
|
918
|
+
const gzipAbove = options.gzipRequestAboveBytes ?? (URL.canParse(options.baseUrl ?? DEFAULT_TANGLE_ROUTER_BASE_URL) && new URL(options.baseUrl ?? DEFAULT_TANGLE_ROUTER_BASE_URL).origin === new URL(DEFAULT_TANGLE_ROUTER_BASE_URL).origin ? 32 * 1024 : void 0);
|
|
919
|
+
const baseFetch = gzipAbove !== void 0 && gzipAbove >= 0 ? gzipRequestBodies(options.fetchImpl ?? fetch, gzipAbove) : options.fetchImpl;
|
|
920
|
+
const sendOnce = trace ? tracedModelFetch(trace, baseFetch ?? fetch, {
|
|
921
|
+
onSpan: (span) => {
|
|
922
|
+
transportState.lastModelSpan = span;
|
|
923
|
+
span.set({ "gen_ai.request.model": transportState.currentModel });
|
|
924
|
+
}
|
|
925
|
+
}) : baseFetch;
|
|
926
|
+
const fetchImpl = signal || attempts > 1 || attemptTimeoutMs ? async (input, init) => {
|
|
927
|
+
const firstSentAt = Date.now();
|
|
928
|
+
const spent = (attempt) => attempts === 1 || attempt >= attempts && Date.now() - firstSentAt >= RETRY_WINDOW_MS;
|
|
929
|
+
for (let attempt = 1; ; attempt++) {
|
|
930
|
+
signal?.throwIfAborted();
|
|
931
|
+
const signals = [signal, attemptTimeoutMs ? AbortSignal.timeout(attemptTimeoutMs) : void 0].filter((value) => Boolean(value));
|
|
932
|
+
const attemptSignal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
933
|
+
const backoff = () => Math.min(MAX_RETRY_DELAY_MS, baseDelayMs * 2 ** (attempt - 1)) * (0.5 + Math.random() / 2);
|
|
934
|
+
const wait = (ms, reason) => trace ? trace.measure("model.retry_wait", "other", () => pause(ms), { "retry.attempt": attempt, "retry.reason": reason, "retry.wait_ms": Math.round(ms) }) : pause(ms);
|
|
935
|
+
let response;
|
|
936
|
+
try {
|
|
937
|
+
response = await (sendOnce ?? fetch)(input, { ...init, ...attemptSignal ? { signal: attemptSignal } : {} });
|
|
938
|
+
} catch (error) {
|
|
939
|
+
if (signal?.aborted || spent(attempt)) throw error;
|
|
940
|
+
await wait(backoff(), "send_failed");
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
if (spent(attempt) || !RETRY_STATUS.has(response.status)) return response;
|
|
944
|
+
if (DEAD_CREDENTIAL_CATEGORIES.has(response.headers.get("x-tangle-failure-category") ?? "")) return response;
|
|
945
|
+
const retryAfter = Number(response.headers.get("retry-after"));
|
|
946
|
+
await response.body?.cancel().catch(() => {
|
|
947
|
+
});
|
|
948
|
+
await wait(Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter * 1e3, MAX_RETRY_DELAY_MS) : backoff(), `http_${response.status}`);
|
|
949
|
+
}
|
|
950
|
+
} : sendOnce;
|
|
951
|
+
return { fetchImpl };
|
|
952
|
+
}
|
|
960
953
|
|
|
961
954
|
export {
|
|
962
955
|
toLoopEvents,
|
|
@@ -982,4 +975,4 @@ export {
|
|
|
982
975
|
composeRouterTurnPrompt,
|
|
983
976
|
runRouterTurn
|
|
984
977
|
};
|
|
985
|
-
//# sourceMappingURL=chunk-
|
|
978
|
+
//# sourceMappingURL=chunk-UW2DKTEM.js.map
|