@agentdocumentformat/cli 0.7.7 → 0.8.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/README.md +1 -1
- package/dist/adf.mjs +59 -8
- package/dist/chunks/{APEv2Parser-2CNNHMXV.mjs → APEv2Parser-WIXRJLHB.mjs} +2 -2
- package/dist/chunks/{AiffParser-7BR4RL6G.mjs → AiffParser-ZC4QFOVJ.mjs} +5 -5
- package/dist/chunks/{App-5KXVPMBV.mjs → App-A5GUFCFJ.mjs} +279 -291
- package/dist/chunks/{DsdiffParser-CMD4AX7A.mjs → DsdiffParser-UAPAJHFX.mjs} +5 -5
- package/dist/chunks/{DsfParser-UOGZDS2M.mjs → DsfParser-NNYZK2QX.mjs} +6 -6
- package/dist/chunks/{FlacParser-HB3T3CD4.mjs → FlacParser-MW2W4LO3.mjs} +6 -6
- package/dist/chunks/{MP4Parser-66HBRUSX.mjs → MP4Parser-Z57SYOOQ.mjs} +4 -4
- package/dist/chunks/{MpegParser-YW6LIUEW.mjs → MpegParser-XIIPAZVM.mjs} +7 -7
- package/dist/chunks/{MusepackParser-PAUSXP7D.mjs → MusepackParser-QWNDEYHJ.mjs} +6 -6
- package/dist/chunks/{OggParser-NUBV3GWC.mjs → OggParser-WRX53F77.mjs} +9 -9
- package/dist/chunks/{WavPackParser-WQAGT7TC.mjs → WavPackParser-MJ7WCSJ5.mjs} +2 -2
- package/dist/chunks/{WaveParser-EWLQVDX4.mjs → WaveParser-RAVLHZ5S.mjs} +7 -7
- package/dist/chunks/{adf-schema-US4NFHMR.mjs → adf-schema-YJSGLMA4.mjs} +2 -2
- package/dist/chunks/auth-manager-AJ32FZWS.mjs +19 -0
- package/dist/chunks/auth-manager-C5OBEQK2.mjs +18 -0
- package/dist/chunks/auth-manager-TBNKCJ45.mjs +17 -0
- package/dist/chunks/{chatgpt-subscription-E4MXTIAT.mjs → chatgpt-subscription-MMGNW5KJ.mjs} +5 -2
- package/dist/chunks/chunk-3UGZFWIF.mjs +26 -0
- package/dist/chunks/{chunk-5PO5PKRV.mjs → chunk-4OGZFUKA.mjs} +126 -67
- package/dist/chunks/{chunk-VN7UH7I5.mjs → chunk-6XQZGYMK.mjs} +246 -67
- package/dist/chunks/{chunk-XNPZBLYL.mjs → chunk-75DC5EWN.mjs} +13 -2
- package/dist/chunks/chunk-AZYOXXVL.mjs +865 -0
- package/dist/chunks/{chunk-6VQEXLE2.mjs → chunk-BHY7QDCM.mjs} +41 -3
- package/dist/chunks/chunk-C2S64Y6F.mjs +203 -0
- package/dist/chunks/chunk-C4GA5SI4.mjs +12799 -0
- package/dist/chunks/chunk-DDTTSKGG.mjs +2443 -0
- package/dist/chunks/{chunk-VAUOM3IN.mjs → chunk-DLWCKKIO.mjs} +1 -1
- package/dist/chunks/{chunk-HPVFJYXR.mjs → chunk-ESP3VNMX.mjs} +1 -1
- package/dist/chunks/{chunk-QPLEAE6V.mjs → chunk-G6NBFYG5.mjs} +152 -824
- package/dist/chunks/{chunk-KXEF4F4E.mjs → chunk-GAZO6UMI.mjs} +1 -1
- package/dist/chunks/{chunk-XYTWGHFS.mjs → chunk-H3XLRWVE.mjs} +1 -1
- package/dist/chunks/{chunk-7T2YMTWL.mjs → chunk-H4C65MTP.mjs} +4 -4
- package/dist/chunks/chunk-HBOFZRUS.mjs +738 -0
- package/dist/chunks/chunk-JVPZIMXW.mjs +976 -0
- package/dist/chunks/{chunk-XYV3VCIX.mjs → chunk-JZFONJSL.mjs} +79 -20
- package/dist/chunks/chunk-KDDVQKCG.mjs +65 -0
- package/dist/chunks/chunk-KRPKWOMB.mjs +290 -0
- package/dist/chunks/{chunk-4N4ASPH6.mjs → chunk-LCMANRYY.mjs} +4 -254
- package/dist/chunks/{chunk-TPRZQ7Z4.mjs → chunk-LGL6ML37.mjs} +4 -4
- package/dist/chunks/chunk-LKFHERRV.mjs +145 -0
- package/dist/chunks/chunk-LTX74NU6.mjs +29 -0
- package/dist/chunks/chunk-M2F7C2UJ.mjs +425 -0
- package/dist/chunks/{chunk-62NE4LG4.mjs → chunk-MQAMI5BF.mjs} +5 -5
- package/dist/chunks/chunk-MZRXFWPQ.mjs +278 -0
- package/dist/chunks/{chunk-PRMGZZM5.mjs → chunk-NZLEPJ5M.mjs} +2 -0
- package/dist/chunks/{chunk-CD3ATSXE.mjs → chunk-NZO5O4VN.mjs} +1 -1
- package/dist/chunks/{chunk-I3UYSITV.mjs → chunk-O7XKQ6CH.mjs} +1 -1
- package/dist/chunks/chunk-P3RG5LQA.mjs +244 -0
- package/dist/chunks/chunk-PAK5JCO2.mjs +48 -0
- package/dist/chunks/chunk-PC63YFB7.mjs +34 -0
- package/dist/chunks/{daemon-control-HKFVSQTQ.mjs → chunk-PRPTKMQW.mjs} +67 -26
- package/dist/chunks/{chunk-LFMB4PAA.mjs → chunk-TKXIH27X.mjs} +974 -113
- package/dist/chunks/{chunk-5W7KES6P.mjs → chunk-UZPDETEU.mjs} +1 -1
- package/dist/chunks/chunk-V2T6NZX2.mjs +517 -0
- package/dist/chunks/chunk-V3MM6PCH.mjs +366 -0
- package/dist/chunks/chunk-WJGPNHGX.mjs +67 -0
- package/dist/chunks/chunk-WVTPPOKK.mjs +290 -0
- package/dist/chunks/{chunk-J74STFKE.mjs → chunk-WX6QCUWI.mjs} +272 -51
- package/dist/chunks/{chunk-Y5ZLKFLE.mjs → chunk-XNNJQCZP.mjs} +196 -165
- package/dist/chunks/{chunk-HDBPBORT.mjs → chunk-XT2BJUFC.mjs} +15 -6
- package/dist/chunks/chunk-YRMKSHW3.mjs +9076 -0
- package/dist/chunks/{chunk-BNXUAOO4.mjs → chunk-ZGXUOAWZ.mjs} +3186 -959
- package/dist/chunks/chunk-ZPB3HYM7.mjs +45 -0
- package/dist/chunks/claude-subscription-33BMZB6I.mjs +29 -0
- package/dist/chunks/{cli-AFHQ2XTN.mjs → cli-I47IFDHJ.mjs} +797 -56
- package/dist/chunks/{commands-XNJMCD5L.mjs → commands-E4EQUHE5.mjs} +5 -2
- package/dist/chunks/{daemon-CHZHTLGR.mjs → daemon-FQ5BV3AP.mjs} +84550 -70518
- package/dist/chunks/daemon-control-L3CLG63P.mjs +59 -0
- package/dist/chunks/{daemon-token-WRSULP7G.mjs → daemon-token-L5QKTHU5.mjs} +3 -1
- package/dist/chunks/{discord-DSP4HUWI.mjs → discord-IR62565M.mjs} +3 -52
- package/dist/chunks/{email-BRG7KUO2.mjs → email-KHHTJBDW.mjs} +4 -2
- package/dist/chunks/{environment-NX277MQG.mjs → environment-R47X44GM.mjs} +1 -1
- package/dist/chunks/{grok-subscription-4PYX7TBF.mjs → grok-subscription-E74FS5EG.mjs} +5 -2
- package/dist/chunks/{lib-N7FCZWKH.mjs → lib-L27L5PXM.mjs} +22 -22
- package/dist/chunks/{open-VAU7PXT6.mjs → open-TLGS2Z3Q.mjs} +4 -4
- package/dist/chunks/{parser-JVY2PWSM.mjs → parser-7GARNT5L.mjs} +1 -1
- package/dist/chunks/{pipeline-executor-U6IMCCP3.mjs → pipeline-executor-FD4FBWQA.mjs} +8 -5
- package/dist/chunks/prompt-RRHZX4YT.mjs +13 -0
- package/dist/chunks/remote-access-cli-XXAPQWH6.mjs +268 -0
- package/dist/chunks/remote-hello-UFWUBDQI.mjs +37 -0
- package/dist/chunks/sdk-5FD2ZP7N.mjs +28422 -0
- package/dist/chunks/{slack-OCNNF4DX.mjs → slack-IYC5RAB5.mjs} +3 -4
- package/dist/chunks/{store-HUVDJPYN.mjs → store-ZRN2WCFB.mjs} +6 -3
- package/dist/chunks/tailscale-WLJATFMB.mjs +25 -0
- package/dist/chunks/{theme-SFE3JMA2.mjs → theme-HLBDTF6F.mjs} +1 -1
- package/dist/chunks/{themes-YLXLOIJF.mjs → themes-BQ72P446.mjs} +2 -2
- package/dist/chunks/{token-6G3HCMNX.mjs → token-6D22WECM.mjs} +20 -16
- package/dist/chunks/{token-util-UXYSDQIW.mjs → token-util-YF3ZWBZ4.mjs} +1 -2
- package/dist/chunks/{tui-4ZWZKD4C.mjs → tui-SPSPDADM.mjs} +17 -14
- package/dist/chunks/{welcome-XHXFV7SH.mjs → welcome-J5JZZAM5.mjs} +1 -1
- package/dist/chunks/{whatsapp-AVKT3CTJ.mjs → whatsapp-YJFFVN4Q.mjs} +8 -8
- package/package.json +1 -1
- package/dist/chunks/chunk-GKKCMXIZ.mjs +0 -94
- package/dist/chunks/chunk-IHDDCZBS.mjs +0 -112
- package/dist/chunks/chunk-KWFOS5WC.mjs +0 -41
- package/dist/chunks/chunk-UEZR2CNS.mjs +0 -65
- package/dist/chunks/chunk-VMHTYDH4.mjs +0 -172
- package/dist/chunks/chunk-ZROSGV65.mjs +0 -3112
- package/dist/chunks/{chunk-NBTUWMGP.mjs → chunk-2MTE22CR.mjs} +3 -3
- package/dist/chunks/{telegram-YI2OHNTD.mjs → telegram-JYY2VDTI.mjs} +4 -4
|
@@ -4,6 +4,12 @@ import { dirname as __adfDirname } from 'node:path';
|
|
|
4
4
|
const require = __adfCreateRequire(import.meta.url);
|
|
5
5
|
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = __adfDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
attachmentsOf,
|
|
9
|
+
displayAttachment,
|
|
10
|
+
isFileRefBlock,
|
|
11
|
+
splitLegacyUploads
|
|
12
|
+
} from "./chunk-LKFHERRV.mjs";
|
|
7
13
|
import {
|
|
8
14
|
__export
|
|
9
15
|
} from "./chunk-M2RX3S2T.mjs";
|
|
@@ -11,27 +17,76 @@ import {
|
|
|
11
17
|
// src/shared/utils/loop-parser.ts
|
|
12
18
|
var loop_parser_exports = {};
|
|
13
19
|
__export(loop_parser_exports, {
|
|
20
|
+
RUNTIME_NOTICE_PREFIXES: () => RUNTIME_NOTICE_PREFIXES,
|
|
21
|
+
TURN_ERROR_DETAILS_MARKER: () => TURN_ERROR_DETAILS_MARKER,
|
|
14
22
|
TURN_ERROR_MARKER: () => TURN_ERROR_MARKER,
|
|
23
|
+
classifyInjectedText: () => classifyInjectedText,
|
|
24
|
+
detectTriggerType: () => detectTriggerType,
|
|
15
25
|
findToolResult: () => findToolResult,
|
|
26
|
+
formatTurnErrorRow: () => formatTurnErrorRow,
|
|
16
27
|
getLoopSummary: () => getLoopSummary,
|
|
17
|
-
|
|
28
|
+
isNoticeCategory: () => isNoticeCategory,
|
|
29
|
+
isRuntimeNotice: () => isRuntimeNotice,
|
|
18
30
|
loopToLLMMessages: () => loopToLLMMessages,
|
|
19
31
|
parseLoopSendStamp: () => parseLoopSendStamp,
|
|
20
32
|
parseLoopToDisplay: () => parseLoopToDisplay,
|
|
21
33
|
parseLoopWithToolPairs: () => parseLoopWithToolPairs,
|
|
22
|
-
parseTurnErrorMarker: () => parseTurnErrorMarker
|
|
34
|
+
parseTurnErrorMarker: () => parseTurnErrorMarker,
|
|
35
|
+
parseTurnErrorRow: () => parseTurnErrorRow,
|
|
36
|
+
providerContextCategory: () => providerContextCategory
|
|
23
37
|
});
|
|
24
|
-
function isContextEntry(text) {
|
|
25
|
-
let match = text.match(/^\[Context: ([^\]]+)\]/);
|
|
26
|
-
return match ? match[1] : null;
|
|
27
|
-
}
|
|
28
38
|
function parseLoopSendStamp(text) {
|
|
29
39
|
let match = text.match(/^\[from loop:([a-z0-9][a-z0-9_-]{0,31})\] ([\s\S]*)$/);
|
|
30
40
|
return match ? { fromLoop: match[1], body: match[2] } : null;
|
|
31
41
|
}
|
|
32
|
-
var TURN_ERROR_MARKER = "[Turn error] "
|
|
42
|
+
var TURN_ERROR_MARKER = "[Turn error] ", TURN_ERROR_DETAILS_MARKER = `
|
|
43
|
+
|
|
44
|
+
[Error details] `;
|
|
45
|
+
function formatTurnErrorRow(message, details) {
|
|
46
|
+
return `${TURN_ERROR_MARKER}${message}${details ? `${TURN_ERROR_DETAILS_MARKER}${details}` : ""}`;
|
|
47
|
+
}
|
|
48
|
+
function parseTurnErrorRow(text) {
|
|
49
|
+
if (!text.startsWith(TURN_ERROR_MARKER)) return null;
|
|
50
|
+
let body = text.slice(TURN_ERROR_MARKER.length), at = body.lastIndexOf(TURN_ERROR_DETAILS_MARKER);
|
|
51
|
+
return at < 0 ? { message: body } : { message: body.slice(0, at), details: body.slice(at + TURN_ERROR_DETAILS_MARKER.length) };
|
|
52
|
+
}
|
|
33
53
|
function parseTurnErrorMarker(text) {
|
|
34
|
-
return
|
|
54
|
+
return parseTurnErrorRow(text)?.message ?? null;
|
|
55
|
+
}
|
|
56
|
+
var RUNTIME_NOTICE_PREFIXES = [
|
|
57
|
+
"[System]",
|
|
58
|
+
"[System notice:",
|
|
59
|
+
"[Provider unavailable (",
|
|
60
|
+
"[Provider error (",
|
|
61
|
+
"[Turn error (",
|
|
62
|
+
"[Continue working autonomously",
|
|
63
|
+
"[You have responded ",
|
|
64
|
+
"Context is about to be compacted."
|
|
65
|
+
];
|
|
66
|
+
function isRuntimeNotice(text) {
|
|
67
|
+
return RUNTIME_NOTICE_PREFIXES.some((prefix) => text.startsWith(prefix));
|
|
68
|
+
}
|
|
69
|
+
function isNoticeCategory(category) {
|
|
70
|
+
return category === "runtime" || category === "status";
|
|
71
|
+
}
|
|
72
|
+
function providerContextCategory(addedBy) {
|
|
73
|
+
return `provider_context | from=${addedBy.replace(/[\]|\n]/g, " ")}`;
|
|
74
|
+
}
|
|
75
|
+
function classifyInjectedText(text) {
|
|
76
|
+
let context = text.match(/^\[Context: ([^\]]+)\] ?([\s\S]*)$/);
|
|
77
|
+
if (context) {
|
|
78
|
+
let [name, ...fields] = context[1].split(" | "), field = (key) => fields.find((f) => f.startsWith(`${key}=`))?.slice(key.length + 1), content = context[2];
|
|
79
|
+
if (fields.includes("loop_inject=v2"))
|
|
80
|
+
return { content, metadata: { category: "injected", injectCategory: name, origin: field("origin") ?? "system:unknown" } };
|
|
81
|
+
if (name === "System" || name === "status") return { content, metadata: { category: "status" } };
|
|
82
|
+
if (name === "provider_context") {
|
|
83
|
+
let addedBy = field("from");
|
|
84
|
+
return { content, metadata: { category: "provider_context", ...addedBy ? { addedBy } : {} } };
|
|
85
|
+
}
|
|
86
|
+
return { content, metadata: { category: name } };
|
|
87
|
+
}
|
|
88
|
+
let loopSend = parseLoopSendStamp(text);
|
|
89
|
+
return loopSend ? { content: loopSend.body, metadata: { category: "loop", fromLoop: loopSend.fromLoop } } : isRuntimeNotice(text) ? { content: text, metadata: { category: "runtime" } } : null;
|
|
35
90
|
}
|
|
36
91
|
function extractImageUrl(content) {
|
|
37
92
|
let match = content.match(/\[image: ([^\s]+) \(/);
|
|
@@ -40,8 +95,22 @@ function extractImageUrl(content) {
|
|
|
40
95
|
function collectImageUrls(blocks) {
|
|
41
96
|
return blocks.filter((b) => b.type === "image_url" && b.image_url?.url).map((b) => b.image_url.url);
|
|
42
97
|
}
|
|
98
|
+
function toolResultAttachments(blocks, index) {
|
|
99
|
+
let out = [];
|
|
100
|
+
for (let i = index + 1; i < blocks.length; i++) {
|
|
101
|
+
let b = blocks[i];
|
|
102
|
+
if (b.type === "tool_result") break;
|
|
103
|
+
isFileRefBlock(b) && out.push(displayAttachment(b.file_ref));
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function withToolAttachments(meta, attachments) {
|
|
108
|
+
if (attachments.length === 0) return meta;
|
|
109
|
+
let next = { ...meta, attachments };
|
|
110
|
+
return attachments.some((a) => a.deleted && a.kind === "image") && delete next.imageUrl, next;
|
|
111
|
+
}
|
|
43
112
|
function detectTriggerType(text) {
|
|
44
|
-
return text.startsWith("The user has edited the document.") ? "document_edit" : text.startsWith("You received a message from agent") ? "message_received" : text.startsWith("A scheduled timer has fired") ? "
|
|
113
|
+
return text.startsWith("The user has edited the document.") ? "document_edit" : text.startsWith("You received a message from agent") ? "message_received" : text.startsWith("A scheduled timer has fired") ? "timer" : text.startsWith("[Inbox notification]") ? "inbox" : text === "Go." ? "autonomous_start" : text === "The user has manually triggered you. Review the document and respond." ? "manual_invoke" : text.startsWith("Agent started. Review your mind") ? "startup" : text.startsWith("A batch of ") && text.includes(" events fired: ") ? "batch" : text.startsWith("A file has been ") ? "file_change" : text.startsWith("An outbound message was sent") ? "outbox" : text.startsWith("A tool call has been intercepted") || text.startsWith("A tool call was intercepted") ? "tool_call" : text.startsWith("A task has been created.") ? "task_create" : text.startsWith("A task has completed") ? "task_complete" : text.startsWith("A log entry has been recorded.") ? "log_entry" : text.startsWith("An LLM call completed.") ? "llm_call" : text.startsWith("You have been triggered. Review the current state") ? "unknown" : null;
|
|
45
114
|
}
|
|
46
115
|
function summarizeReasoning(details) {
|
|
47
116
|
return !Array.isArray(details) || details.length === 0 ? { preserved: !1, encrypted: !1 } : { preserved: !0, encrypted: details.some((d) => d?.type === "reasoning.encrypted") };
|
|
@@ -51,7 +120,7 @@ function parseLoopToDisplay(entries) {
|
|
|
51
120
|
for (let entry of entries) {
|
|
52
121
|
let blocks = entry.content_json, timestamp = entry.created_at || 0;
|
|
53
122
|
if (entry.role === "user") {
|
|
54
|
-
let imagePreviewUrls = collectImageUrls(blocks);
|
|
123
|
+
let imagePreviewUrls = collectImageUrls(blocks), attachments = blocks.some((b) => b.type === "tool_result") ? [] : attachmentsOf(blocks), firstEntryOfRow = displayEntries.length;
|
|
55
124
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
56
125
|
let block = blocks[bi];
|
|
57
126
|
if (block.type === "text" && block.text) {
|
|
@@ -67,51 +136,39 @@ function parseLoopToDisplay(entries) {
|
|
|
67
136
|
});
|
|
68
137
|
continue;
|
|
69
138
|
}
|
|
70
|
-
let turnError =
|
|
139
|
+
let turnError = parseTurnErrorRow(block.text);
|
|
71
140
|
if (turnError !== null) {
|
|
72
141
|
displayEntries.push({
|
|
73
142
|
id: `loop-${entry.seq}-${bi}`,
|
|
74
143
|
type: "error",
|
|
75
|
-
content: turnError,
|
|
144
|
+
content: turnError.message,
|
|
76
145
|
timestamp,
|
|
77
|
-
metadata: { seq: entry.seq }
|
|
146
|
+
metadata: turnError.details ? { seq: entry.seq, details: turnError.details } : { seq: entry.seq }
|
|
78
147
|
});
|
|
79
148
|
continue;
|
|
80
149
|
}
|
|
81
|
-
let
|
|
82
|
-
if (
|
|
83
|
-
let content = block.text.replace(/^\[Context: [^\]]+\] /, "");
|
|
150
|
+
let injected = classifyInjectedText(block.text);
|
|
151
|
+
if (injected) {
|
|
84
152
|
displayEntries.push({
|
|
85
153
|
id: `loop-${entry.seq}-${bi}`,
|
|
86
154
|
type: "context",
|
|
87
|
-
content,
|
|
155
|
+
content: injected.content,
|
|
88
156
|
timestamp,
|
|
89
|
-
metadata: { seq: entry.seq,
|
|
157
|
+
metadata: { seq: entry.seq, ...injected.metadata }
|
|
90
158
|
});
|
|
91
159
|
continue;
|
|
92
160
|
}
|
|
93
|
-
let
|
|
94
|
-
if (loopSend) {
|
|
95
|
-
displayEntries.push({
|
|
96
|
-
id: `loop-${entry.seq}-${bi}`,
|
|
97
|
-
type: "context",
|
|
98
|
-
content: loopSend.body,
|
|
99
|
-
timestamp,
|
|
100
|
-
metadata: { seq: entry.seq, category: "loop", fromLoop: loopSend.fromLoop }
|
|
101
|
-
});
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
let triggerType = detectTriggerType(block.text);
|
|
105
|
-
if (triggerType === "autonomous_continue") continue;
|
|
161
|
+
let triggerType = detectTriggerType(block.text), legacy = triggerType ? { text: block.text, attachments: [] } : splitLegacyUploads(block.text), shown = [...attachments, ...legacy.attachments];
|
|
106
162
|
displayEntries.push({
|
|
107
163
|
id: `loop-${entry.seq}-${bi}`,
|
|
108
164
|
type: triggerType && triggerType !== "manual_invoke" ? "trigger" : "user",
|
|
109
|
-
content:
|
|
165
|
+
content: legacy.text,
|
|
110
166
|
timestamp,
|
|
111
167
|
metadata: {
|
|
112
168
|
seq: entry.seq,
|
|
113
169
|
...triggerType ? { triggerType } : {},
|
|
114
|
-
...!triggerType && imagePreviewUrls.length > 0 ? { imagePreviewUrls } : {}
|
|
170
|
+
...!triggerType && imagePreviewUrls.length > 0 ? { imagePreviewUrls } : {},
|
|
171
|
+
...!triggerType && shown.length > 0 ? { attachments: shown } : {}
|
|
115
172
|
}
|
|
116
173
|
});
|
|
117
174
|
} else if (block.type === "tool_result") {
|
|
@@ -121,16 +178,17 @@ function parseLoopToDisplay(entries) {
|
|
|
121
178
|
type: "tool_result",
|
|
122
179
|
content: block.content ?? "",
|
|
123
180
|
timestamp,
|
|
124
|
-
metadata: {
|
|
181
|
+
metadata: withToolAttachments({
|
|
125
182
|
seq: entry.seq,
|
|
126
183
|
tool_use_id: block.tool_use_id,
|
|
127
184
|
name: toolName,
|
|
128
185
|
isError: block.is_error,
|
|
129
186
|
...imageUrl ? { imageUrl } : {}
|
|
130
|
-
}
|
|
187
|
+
}, toolResultAttachments(blocks, bi))
|
|
131
188
|
});
|
|
132
189
|
}
|
|
133
190
|
}
|
|
191
|
+
pushAttachmentOnlyEntry(displayEntries, firstEntryOfRow, entry, attachments, imagePreviewUrls);
|
|
134
192
|
} else if (entry.role === "assistant") {
|
|
135
193
|
let firstEntryOfRow = displayEntries.length, reasoningTokens = typeof entry.tokens?.reasoning == "number" ? entry.tokens.reasoning : void 0;
|
|
136
194
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
@@ -141,7 +199,7 @@ function parseLoopToDisplay(entries) {
|
|
|
141
199
|
type: "text",
|
|
142
200
|
content: block.text,
|
|
143
201
|
timestamp,
|
|
144
|
-
metadata: { seq: entry.seq, model: entry.model }
|
|
202
|
+
metadata: { seq: entry.seq, model: entry.model, ...block.interrupted ? { interrupted: !0 } : {} }
|
|
145
203
|
});
|
|
146
204
|
else if (block.type === "tool_use")
|
|
147
205
|
block.id && block.name && toolIdToName.set(block.id, block.name), displayEntries.push({
|
|
@@ -165,6 +223,7 @@ function parseLoopToDisplay(entries) {
|
|
|
165
223
|
timestamp,
|
|
166
224
|
metadata: {
|
|
167
225
|
seq: entry.seq,
|
|
226
|
+
...block.interrupted ? { interrupted: !0 } : {},
|
|
168
227
|
model: entry.model,
|
|
169
228
|
...reasoningTokens !== void 0 ? { reasoningTokens } : {},
|
|
170
229
|
...preserved ? { preservedReasoning: !0 } : {},
|
|
@@ -178,6 +237,15 @@ function parseLoopToDisplay(entries) {
|
|
|
178
237
|
}
|
|
179
238
|
return displayEntries;
|
|
180
239
|
}
|
|
240
|
+
function pushAttachmentOnlyEntry(displayEntries, firstEntryOfRow, entry, attachments, imagePreviewUrls) {
|
|
241
|
+
attachments.length === 0 || displayEntries.length > firstEntryOfRow || displayEntries.push({
|
|
242
|
+
id: `loop-${entry.seq}-attachments`,
|
|
243
|
+
type: "user",
|
|
244
|
+
content: "",
|
|
245
|
+
timestamp: entry.created_at || 0,
|
|
246
|
+
metadata: { seq: entry.seq, attachments, ...imagePreviewUrls.length > 0 ? { imagePreviewUrls } : {} }
|
|
247
|
+
});
|
|
248
|
+
}
|
|
181
249
|
function stampRowTokens(displayEntries, firstEntryOfRow, tokens) {
|
|
182
250
|
if (!tokens || displayEntries.length <= firstEntryOfRow) return;
|
|
183
251
|
let last = displayEntries[displayEntries.length - 1];
|
|
@@ -208,7 +276,7 @@ function parseLoopWithToolPairs(entries) {
|
|
|
208
276
|
for (let entry of entries) {
|
|
209
277
|
let blocks = entry.content_json, timestamp = entry.created_at || 0;
|
|
210
278
|
if (entry.role === "user") {
|
|
211
|
-
let imagePreviewUrls = collectImageUrls(blocks);
|
|
279
|
+
let imagePreviewUrls = collectImageUrls(blocks), attachments = blocks.some((b) => b.type === "tool_result") ? [] : attachmentsOf(blocks), firstEntryOfRow = displayEntries.length;
|
|
212
280
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
213
281
|
let block = blocks[bi];
|
|
214
282
|
if (block.type === "text" && block.text) {
|
|
@@ -224,74 +292,63 @@ function parseLoopWithToolPairs(entries) {
|
|
|
224
292
|
});
|
|
225
293
|
continue;
|
|
226
294
|
}
|
|
227
|
-
let turnError =
|
|
295
|
+
let turnError = parseTurnErrorRow(block.text);
|
|
228
296
|
if (turnError !== null) {
|
|
229
297
|
displayEntries.push({
|
|
230
298
|
id: `loop-${entry.seq}-${bi}`,
|
|
231
299
|
type: "error",
|
|
232
|
-
content: turnError,
|
|
233
|
-
timestamp,
|
|
234
|
-
metadata: { seq: entry.seq }
|
|
235
|
-
});
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
let contextCategory = isContextEntry(block.text);
|
|
239
|
-
if (contextCategory) {
|
|
240
|
-
let content = block.text.replace(/^\[Context: [^\]]+\] /, "");
|
|
241
|
-
displayEntries.push({
|
|
242
|
-
id: `loop-${entry.seq}-${bi}`,
|
|
243
|
-
type: "context",
|
|
244
|
-
content,
|
|
300
|
+
content: turnError.message,
|
|
245
301
|
timestamp,
|
|
246
|
-
metadata: { seq: entry.seq,
|
|
302
|
+
metadata: turnError.details ? { seq: entry.seq, details: turnError.details } : { seq: entry.seq }
|
|
247
303
|
});
|
|
248
304
|
continue;
|
|
249
305
|
}
|
|
250
|
-
let
|
|
251
|
-
if (
|
|
306
|
+
let injected = classifyInjectedText(block.text);
|
|
307
|
+
if (injected) {
|
|
252
308
|
displayEntries.push({
|
|
253
309
|
id: `loop-${entry.seq}-${bi}`,
|
|
254
310
|
type: "context",
|
|
255
|
-
content:
|
|
311
|
+
content: injected.content,
|
|
256
312
|
timestamp,
|
|
257
|
-
metadata: { seq: entry.seq,
|
|
313
|
+
metadata: { seq: entry.seq, ...injected.metadata }
|
|
258
314
|
});
|
|
259
315
|
continue;
|
|
260
316
|
}
|
|
261
|
-
let triggerType = detectTriggerType(block.text);
|
|
262
|
-
if (triggerType === "autonomous_continue") continue;
|
|
317
|
+
let triggerType = detectTriggerType(block.text), legacy = triggerType ? { text: block.text, attachments: [] } : splitLegacyUploads(block.text), shown = [...attachments, ...legacy.attachments];
|
|
263
318
|
displayEntries.push({
|
|
264
319
|
id: `loop-${entry.seq}-${bi}`,
|
|
265
320
|
type: triggerType && triggerType !== "manual_invoke" ? "trigger" : "user",
|
|
266
|
-
content:
|
|
321
|
+
content: legacy.text,
|
|
267
322
|
timestamp,
|
|
268
323
|
metadata: {
|
|
269
324
|
seq: entry.seq,
|
|
270
325
|
...triggerType ? { triggerType } : {},
|
|
271
|
-
...!triggerType && imagePreviewUrls.length > 0 ? { imagePreviewUrls } : {}
|
|
326
|
+
...!triggerType && imagePreviewUrls.length > 0 ? { imagePreviewUrls } : {},
|
|
327
|
+
...!triggerType && shown.length > 0 ? { attachments: shown } : {}
|
|
272
328
|
}
|
|
273
329
|
});
|
|
274
330
|
} else if (block.type === "tool_result" && block.tool_use_id) {
|
|
275
|
-
let pending = pendingToolCalls.get(block.tool_use_id), imageUrl = extractImageUrl(block.content ?? "");
|
|
276
|
-
pending && (pending.entry.metadata = {
|
|
331
|
+
let pending = pendingToolCalls.get(block.tool_use_id), imageUrl = extractImageUrl(block.content ?? ""), resultAttachments = toolResultAttachments(blocks, bi);
|
|
332
|
+
pending && (pending.entry.metadata = withToolAttachments({
|
|
277
333
|
...pending.entry.metadata,
|
|
278
334
|
result: block.content,
|
|
279
335
|
isError: block.is_error,
|
|
280
336
|
...imageUrl ? { imageUrl } : {}
|
|
281
|
-
}, pendingToolCalls.delete(block.tool_use_id)), displayEntries.push({
|
|
337
|
+
}, resultAttachments), pendingToolCalls.delete(block.tool_use_id)), displayEntries.push({
|
|
282
338
|
id: `loop-${entry.seq}-${bi}`,
|
|
283
339
|
type: "tool_result",
|
|
284
340
|
content: block.content ?? "",
|
|
285
341
|
timestamp,
|
|
286
|
-
metadata: {
|
|
342
|
+
metadata: withToolAttachments({
|
|
287
343
|
seq: entry.seq,
|
|
288
344
|
tool_use_id: block.tool_use_id,
|
|
289
345
|
isError: block.is_error,
|
|
290
346
|
...imageUrl ? { imageUrl } : {}
|
|
291
|
-
}
|
|
347
|
+
}, resultAttachments)
|
|
292
348
|
});
|
|
293
349
|
}
|
|
294
350
|
}
|
|
351
|
+
pushAttachmentOnlyEntry(displayEntries, firstEntryOfRow, entry, attachments, imagePreviewUrls);
|
|
295
352
|
} else if (entry.role === "assistant") {
|
|
296
353
|
let firstEntryOfRow = displayEntries.length, reasoningTokens = typeof entry.tokens?.reasoning == "number" ? entry.tokens.reasoning : void 0;
|
|
297
354
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
@@ -302,7 +359,7 @@ function parseLoopWithToolPairs(entries) {
|
|
|
302
359
|
type: "text",
|
|
303
360
|
content: block.text,
|
|
304
361
|
timestamp,
|
|
305
|
-
metadata: { seq: entry.seq, model: entry.model }
|
|
362
|
+
metadata: { seq: entry.seq, model: entry.model, ...block.interrupted ? { interrupted: !0 } : {} }
|
|
306
363
|
});
|
|
307
364
|
else if (block.type === "tool_use" && block.id) {
|
|
308
365
|
let toolEntry = {
|
|
@@ -327,6 +384,7 @@ function parseLoopWithToolPairs(entries) {
|
|
|
327
384
|
timestamp,
|
|
328
385
|
metadata: {
|
|
329
386
|
seq: entry.seq,
|
|
387
|
+
...block.interrupted ? { interrupted: !0 } : {},
|
|
330
388
|
model: entry.model,
|
|
331
389
|
...reasoningTokens !== void 0 ? { reasoningTokens } : {},
|
|
332
390
|
...preserved ? { preservedReasoning: !0 } : {},
|
|
@@ -360,7 +418,8 @@ function loopToLLMMessages(entries) {
|
|
|
360
418
|
}
|
|
361
419
|
|
|
362
420
|
export {
|
|
363
|
-
|
|
421
|
+
formatTurnErrorRow,
|
|
422
|
+
providerContextCategory,
|
|
364
423
|
parseLoopToDisplay,
|
|
365
424
|
loop_parser_exports
|
|
366
425
|
};
|