@tangle-network/agent-app 0.60.34 → 0.60.36
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/VaultPane-A2RGT5PI.js +7 -0
- package/dist/chat-routes/completed-sandbox-turn.d.ts +4 -0
- package/dist/chat-routes/index.js +83 -14
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/native-completion.d.ts +13 -0
- package/dist/{chunk-FMX3IOJM.js → chunk-QBNV6BJ4.js} +5 -4
- package/dist/chunk-QBNV6BJ4.js.map +1 -0
- package/dist/preset-cloudflare/detached-turn-workflow.d.ts +4 -1
- package/dist/preset-cloudflare/index.js +14 -4
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/preset-cloudflare/native-completion-workflow.d.ts +8 -2
- package/dist/vault/index.js +1 -1
- package/dist/vault/lazy.js +1 -1
- package/package.json +1 -1
- package/dist/VaultPane-OH4W5MXW.js +0 -7
- package/dist/chunk-FMX3IOJM.js.map +0 -1
- /package/dist/{VaultPane-OH4W5MXW.js.map → VaultPane-A2RGT5PI.js.map} +0 -0
|
@@ -17,6 +17,10 @@ export type CompletedSandboxTurnSource = Pick<SandboxInstance, 'findCompletedTur
|
|
|
17
17
|
export interface ReadCompletedSandboxTurnOptions {
|
|
18
18
|
turnId: string;
|
|
19
19
|
sessionId: string;
|
|
20
|
+
/** Read only session messages newer than this Unix-ms time. A long session
|
|
21
|
+
* holds more than one page of messages, oldest first, so an unbounded read
|
|
22
|
+
* both grows with the session and can miss the newest turn. */
|
|
23
|
+
since?: number;
|
|
20
24
|
log?: (message: string, meta?: Record<string, unknown>) => void;
|
|
21
25
|
}
|
|
22
26
|
/** @internal Shared terminal-result decoder; callers must establish exact turn identity. */
|
|
@@ -1638,7 +1638,7 @@ async function readCompletedSandboxTurn(box, options) {
|
|
|
1638
1638
|
const session = box.session(sessionId);
|
|
1639
1639
|
const [cacheOutcome, messagesOutcome] = await Promise.allSettled([
|
|
1640
1640
|
box.findCompletedTurn(turnId, { sessionId }),
|
|
1641
|
-
session.messages({ limit: 1e3 })
|
|
1641
|
+
session.messages({ limit: 1e3, ...options.since !== void 0 ? { since: options.since } : {} })
|
|
1642
1642
|
]);
|
|
1643
1643
|
if (cacheOutcome.status === "rejected") {
|
|
1644
1644
|
log?.("[chat-routes] completed Sandbox turn cache lookup failed", {
|
|
@@ -1701,6 +1701,76 @@ async function readCompletedSandboxTurn(box, options) {
|
|
|
1701
1701
|
// src/chat-routes/native-completion.ts
|
|
1702
1702
|
var DEFAULT_ABSENT_DISPATCH_DEADLINE_MS = 10 * 6e4;
|
|
1703
1703
|
var DEFAULT_RECEIPT_DEADLINE_MS = 10 * 6e4;
|
|
1704
|
+
var MESSAGE_READ_SKEW_MS = 10 * 6e4;
|
|
1705
|
+
var INTERRUPTED_RESULT_REPLAY_MAX_EVENTS = 2e3;
|
|
1706
|
+
function replayableExecution(run) {
|
|
1707
|
+
return typeof run.eventCount === "number" && run.eventCount <= INTERRUPTED_RESULT_REPLAY_MAX_EVENTS;
|
|
1708
|
+
}
|
|
1709
|
+
var NATIVE_COMPLETION_RECEIPT_MAX_BYTES = 900 * 1024;
|
|
1710
|
+
var RECEIPT_STRING_CAPS = [16384, 4096, 1024, 256];
|
|
1711
|
+
var encoder = new TextEncoder();
|
|
1712
|
+
function serializedBytes(value) {
|
|
1713
|
+
return encoder.encode(JSON.stringify(value)).length;
|
|
1714
|
+
}
|
|
1715
|
+
function capString(value, cap) {
|
|
1716
|
+
if (value.length <= cap) return value;
|
|
1717
|
+
return `${value.slice(0, cap)}\u2026[truncated ${value.length - cap} characters; the Sandbox session keeps the full value]`;
|
|
1718
|
+
}
|
|
1719
|
+
function capStrings(value, cap) {
|
|
1720
|
+
if (typeof value === "string") return capString(value, cap);
|
|
1721
|
+
if (Array.isArray(value)) return value.map((item) => capStrings(item, cap));
|
|
1722
|
+
const object = record(value);
|
|
1723
|
+
if (!object) return value;
|
|
1724
|
+
return Object.fromEntries(Object.entries(object).map(([key, item]) => [key, capStrings(item, cap)]));
|
|
1725
|
+
}
|
|
1726
|
+
function capReceiptPart(part, cap) {
|
|
1727
|
+
const type = String(part.type ?? "");
|
|
1728
|
+
if (type === "tool") {
|
|
1729
|
+
const state = record(part.state);
|
|
1730
|
+
if (!state) return part;
|
|
1731
|
+
const capped = capStrings(state, cap);
|
|
1732
|
+
if (serializedBytes(capped) === serializedBytes(state)) return part;
|
|
1733
|
+
return { ...part, state: { ...capped, metadata: { ...record(capped.metadata), receiptTruncated: true } } };
|
|
1734
|
+
}
|
|
1735
|
+
if (type === "reasoning" && typeof part.text === "string" && part.text.length > cap) {
|
|
1736
|
+
return { ...part, text: capString(part.text, cap), receiptTruncated: true };
|
|
1737
|
+
}
|
|
1738
|
+
return part;
|
|
1739
|
+
}
|
|
1740
|
+
function skeletonPart(part) {
|
|
1741
|
+
const type = String(part.type ?? "");
|
|
1742
|
+
if (type === "reasoning") return null;
|
|
1743
|
+
if (type !== "tool") return part;
|
|
1744
|
+
const state = record(part.state);
|
|
1745
|
+
return {
|
|
1746
|
+
type: "tool",
|
|
1747
|
+
...part.id !== void 0 ? { id: part.id } : {},
|
|
1748
|
+
...part.tool !== void 0 ? { tool: part.tool } : {},
|
|
1749
|
+
state: { status: state?.status ?? "completed", metadata: { receiptTruncated: true } }
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
function boundNativeCompletionReceipt(receipt, maxBytes = NATIVE_COMPLETION_RECEIPT_MAX_BYTES) {
|
|
1753
|
+
if (serializedBytes(receipt) <= maxBytes) return receipt;
|
|
1754
|
+
for (const cap of RECEIPT_STRING_CAPS) {
|
|
1755
|
+
const bounded = { ...receipt, parts: receipt.parts.map((part) => capReceiptPart(part, cap)) };
|
|
1756
|
+
if (serializedBytes(bounded) <= maxBytes) return bounded;
|
|
1757
|
+
}
|
|
1758
|
+
const skeleton = {
|
|
1759
|
+
...receipt,
|
|
1760
|
+
parts: receipt.parts.map(skeletonPart).filter((part) => part !== null)
|
|
1761
|
+
};
|
|
1762
|
+
if (serializedBytes(skeleton) <= maxBytes) return skeleton;
|
|
1763
|
+
const textBudget = Math.max(0, Math.floor(maxBytes / 4));
|
|
1764
|
+
return {
|
|
1765
|
+
...skeleton,
|
|
1766
|
+
text: capString(skeleton.text, textBudget),
|
|
1767
|
+
parts: skeleton.parts.map((part) => part.type === "text" && typeof part.text === "string" ? { ...part, text: capString(part.text, textBudget) } : part)
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
function terminal(receipt) {
|
|
1771
|
+
const bounded = boundNativeCompletionReceipt(receipt);
|
|
1772
|
+
return bounded.state === "completed" ? { state: "completed", receipt: bounded } : { state: "failed", receipt: bounded };
|
|
1773
|
+
}
|
|
1704
1774
|
function timestamp(value) {
|
|
1705
1775
|
if (value instanceof Date) return value.getTime();
|
|
1706
1776
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
@@ -1777,12 +1847,9 @@ async function observeNativeCompletion(options) {
|
|
|
1777
1847
|
if (admission.state === "open" || now - options.registeredAt < (options.absentDispatchDeadlineMs ?? DEFAULT_ABSENT_DISPATCH_DEADLINE_MS)) {
|
|
1778
1848
|
return { state: "running" };
|
|
1779
1849
|
}
|
|
1780
|
-
return
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
missingTurnReceipt(options.turnId, "Native Sandbox dispatch was not observed before the admission deadline")
|
|
1784
|
-
])
|
|
1785
|
-
};
|
|
1850
|
+
return terminal(aggregateNativeCompletionReceipts([
|
|
1851
|
+
missingTurnReceipt(options.turnId, "Native Sandbox dispatch was not observed before the admission deadline")
|
|
1852
|
+
]));
|
|
1786
1853
|
}
|
|
1787
1854
|
const exactSession = session;
|
|
1788
1855
|
if (admission.state === "open") {
|
|
@@ -1804,6 +1871,7 @@ async function observeNativeCompletion(options) {
|
|
|
1804
1871
|
return { state: "running" };
|
|
1805
1872
|
}
|
|
1806
1873
|
if (admittedTurnIds.some((turnId) => runsByTurnId.get(turnId)?.status === "active")) return { state: "running" };
|
|
1874
|
+
const since = Math.max(0, options.registeredAt - MESSAGE_READ_SKEW_MS);
|
|
1807
1875
|
let messages;
|
|
1808
1876
|
const recovered = [];
|
|
1809
1877
|
for (const turnId of admittedTurnIds) {
|
|
@@ -1812,7 +1880,7 @@ async function observeNativeCompletion(options) {
|
|
|
1812
1880
|
recovered.push(missingTurnReceipt(turnId, "Native Sandbox execution ledger is missing the admitted turn"));
|
|
1813
1881
|
continue;
|
|
1814
1882
|
}
|
|
1815
|
-
const completed = run.status === "completed" ? await readCompletedSandboxTurn(source, { turnId, sessionId: options.sessionId }) : null;
|
|
1883
|
+
const completed = run.status === "completed" ? await readCompletedSandboxTurn(source, { turnId, sessionId: options.sessionId, since }) : null;
|
|
1816
1884
|
if (run.status === "completed" && completed) {
|
|
1817
1885
|
recovered.push({
|
|
1818
1886
|
...completed,
|
|
@@ -1824,18 +1892,18 @@ async function observeNativeCompletion(options) {
|
|
|
1824
1892
|
});
|
|
1825
1893
|
continue;
|
|
1826
1894
|
}
|
|
1827
|
-
const interrupted = run.status === "failed" || run.status === "cancelled" ? interruptedMessages(messages ??= await exactSession.messages({ limit: 1e3 }), turnId) : [];
|
|
1895
|
+
const interrupted = run.status === "failed" || run.status === "cancelled" ? interruptedMessages(messages ??= await exactSession.messages({ limit: 1e3, since }), turnId) : [];
|
|
1828
1896
|
if ((run.status === "failed" || run.status === "cancelled") && interrupted.length === 1) {
|
|
1829
1897
|
const message = recoverSandboxAssistantMessage(interrupted[0]);
|
|
1830
|
-
const result = await exactSession.result({ executionId: turnId });
|
|
1898
|
+
const result = replayableExecution(run) ? await exactSession.result({ executionId: turnId }) : void 0;
|
|
1831
1899
|
recovered.push({
|
|
1832
1900
|
turnId,
|
|
1833
1901
|
state: "failed",
|
|
1834
|
-
text: message.text ?? result.response ?? "",
|
|
1902
|
+
text: message.text ?? (typeof result?.response === "string" ? result.response : void 0) ?? "",
|
|
1835
1903
|
parts: message.parts ?? [],
|
|
1836
1904
|
usage: { ...message.usage, ...usageFromResult(result) },
|
|
1837
1905
|
...attributionFromResult(result),
|
|
1838
|
-
error: result.error ?? interrupted[0].metadata?.interruptReason ?? status.failureReason?.message
|
|
1906
|
+
error: (typeof result?.error === "string" ? result.error : void 0) ?? interrupted[0].metadata?.interruptReason ?? status.failureReason?.message
|
|
1839
1907
|
});
|
|
1840
1908
|
continue;
|
|
1841
1909
|
}
|
|
@@ -1846,8 +1914,7 @@ async function observeNativeCompletion(options) {
|
|
|
1846
1914
|
`Admitted native execution did not produce an exact completion: ${turnId}`
|
|
1847
1915
|
));
|
|
1848
1916
|
}
|
|
1849
|
-
|
|
1850
|
-
return receipt.state === "completed" ? { state: "completed", receipt } : { state: "failed", receipt };
|
|
1917
|
+
return terminal(aggregateNativeCompletionReceipts(recovered));
|
|
1851
1918
|
}
|
|
1852
1919
|
|
|
1853
1920
|
// src/chat-routes/plan-follow-up.ts
|
|
@@ -3296,6 +3363,7 @@ export {
|
|
|
3296
3363
|
MAX_TEXT_ATTACHMENT_BYTES,
|
|
3297
3364
|
MENTION_MAX_COUNT,
|
|
3298
3365
|
ModelFailoverTimeoutError,
|
|
3366
|
+
NATIVE_COMPLETION_RECEIPT_MAX_BYTES,
|
|
3299
3367
|
OOXML_PRESENTATION_MACRO_ENABLED_MIME,
|
|
3300
3368
|
OOXML_PRESENTATION_MIME,
|
|
3301
3369
|
OOXML_SNIFFED_MIMES,
|
|
@@ -3312,6 +3380,7 @@ export {
|
|
|
3312
3380
|
attachmentSizeErrorMessage,
|
|
3313
3381
|
attachmentTotalSizeErrorMessage,
|
|
3314
3382
|
base64WireLen,
|
|
3383
|
+
boundNativeCompletionReceipt,
|
|
3315
3384
|
buildDispatchParts,
|
|
3316
3385
|
buildMentionPromptBlock,
|
|
3317
3386
|
bytesToBase64,
|