jg-agent-hq 10.5.0 → 10.5.2
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/CHANGELOG.md +9 -0
- package/api/README.md +3 -3
- package/dist/actions/live/live.d.ts +3 -2
- package/dist/actions/live/live.js +19 -9
- package/dist/providers/claude/history/history.model.js +11 -12
- package/dist/providers/claude/history/types.d.ts +2 -0
- package/dist/providers/claude/history/types.js +3 -0
- package/dist/providers/claude/history/utilities.d.ts +11 -0
- package/dist/providers/claude/history/utilities.js +30 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 10.5.2
|
|
4
|
+
|
|
5
|
+
- Show a Claude tool result made of content blocks, such as a browser tool's caption and screenshot, as its text, with each image as `[Image]`. Such results used to read `[Native tool_result]`.
|
|
6
|
+
|
|
7
|
+
## 10.5.1
|
|
8
|
+
|
|
9
|
+
- Read a compacted Claude session to the start of its conversation. A compaction starts a new chain whose boundary has no parent and names the record before it as its logical parent, and history used to stop there. Every indexed transcript is indexed again after the upgrade.
|
|
10
|
+
- Drop a live item that was still streaming when its turn ended, such as a message a Codex steer or an interrupt cut, once a native history page holds an item of that turn. Codex never saves a message a steer cut, so it stayed `awaiting-flush` until the window evicted it.
|
|
11
|
+
|
|
3
12
|
## 10.5.0
|
|
4
13
|
|
|
5
14
|
- Add per-session fast mode: `fast` in session and turn settings, `effective.fast` and `effective.fastUnavailableReason` in `configuration`, and `supportsFast` in `models`. Codex sends it as the `priority` service tier, or `default` to turn it off, and reads it back from the session's start, resume and settings updates. Claude sends `fastMode` as a flag setting at startup and before input, keeps it when a parked session reopens, and reads it back from `fast_mode_state`, with the reason Claude gives when fast mode can't serve the session.
|
package/api/README.md
CHANGED
|
@@ -241,9 +241,9 @@ The existing SQLite worker incrementally records file identity, complete-line of
|
|
|
241
241
|
|
|
242
242
|
Current-chain membership and turn starts are indexed as metadata. Ordinary item and turn continuations seek those indexes; they do not walk the full chain per page. A changed branch rebuilds membership before exposing that revision. Repeated native message identities can replace content while retaining their parent; a changed parent for the same identity is an unsupported format.
|
|
243
243
|
|
|
244
|
-
Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item and turn continuations. Only the current parent-linked conversation chain is returned. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
|
|
244
|
+
Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item and turn continuations. Only the current parent-linked conversation chain is returned. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. A result made of content blocks, such as a screenshot with its caption, reads as its text blocks, each image as `[Image]`. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
|
|
245
245
|
|
|
246
|
-
File timestamps and records do not prove that a native process is idle or a turn completed. Claude file-backed thread and turn states are therefore `unknown`, with no invented completion timestamp. Explicit native custom titles are preserved; a missing title remains null. A turn starts at a message the operator sends, including a slash command; task notifications, compaction summaries, local command output, interruption markers and `!` shell records belong to the turn before them. Grouping follows parent links and is not an authoritative execution boundary.
|
|
246
|
+
File timestamps and records do not prove that a native process is idle or a turn completed. Claude file-backed thread and turn states are therefore `unknown`, with no invented completion timestamp. Explicit native custom titles are preserved; a missing title remains null. A turn starts at a message the operator sends, including a slash command; task notifications, compaction summaries, local command output, interruption markers and `!` shell records belong to the turn before them. Grouping follows parent links and is not an authoritative execution boundary. A compaction starts a new chain whose first record names the record before it, so history reads on past the compaction to the start of the conversation.
|
|
247
247
|
|
|
248
248
|
## Thread control and live input
|
|
249
249
|
|
|
@@ -346,7 +346,7 @@ The installed CLI exposes `managed-thread-name --name <name>` and `suggest-threa
|
|
|
346
346
|
|
|
347
347
|
Control pages default to 32 and cap at 128. Seek cursors are bound to their complete query and ordering. Reads recheck allowed workspaces. Rejected controls retain their known thread association, and native availability failures appear in each affected thread's replay. Lifecycle replay contains metadata, not token or tool output. Each provider has a bounded native lifecycle backlog; overflow stops that source and marks its state uncertain rather than losing events silently. Other providers retain their independent connection and admission state.
|
|
348
348
|
|
|
349
|
-
Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. The outcome is enough because Codex shortens long command output when it saves it. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
|
|
349
|
+
Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
|
|
350
350
|
|
|
351
351
|
Items expose only normalized presentation fields, and one mapping per provider presents `items`, live items and `session-evidence` alike, as the provider's CLI shows them. Kinds are `user-message`, `agent-message`, `command`, `tool`, `file-change`, `notice` and `unsupported`. `callId` pairs a tool call with its result, or is null. `outcome` is `succeeded`, `failed`, or null when unknown or still running. `files` lists each file a file change touched, at most 128, with its added and removed lines, and is empty on other items. `outcome` and `files` come from the full native record, so `textLimit` never changes them. Unknown native kinds report `unsupported` without copying arbitrary payloads. Display text is bounded to 65,536 UTF-16 code units without splitting a surrogate pair; `isTruncated` reports omissions. An unsupported or oversized native transport frame fails explicitly. `createdAt` is the item's time in Unix milliseconds, or null when the provider records none. A Claude item takes its record's `timestamp`, and a live one the time its frame arrived. A Codex item takes its turn's times, which Codex records across all of its history: an operator message takes its turn's start and every other item its turn's end, or its start while the turn runs. A Codex history page reads the turns of its items newest first, 128 at a time and at most 8 times, so a recent page takes one read and an item whose turn lies further back has no time. A live Codex item takes its running turn's start.
|
|
352
352
|
|
|
@@ -28,10 +28,11 @@ export declare class LiveItems {
|
|
|
28
28
|
/**
|
|
29
29
|
* Drops completed items once persisted history holds them: with exactly matching normalized
|
|
30
30
|
* content, or, for an item with an outcome, the same final outcome, since a provider can shorten
|
|
31
|
-
* long output when it saves it, as Codex does.
|
|
31
|
+
* long output when it saves it, as Codex does. An item its turn ended before the provider
|
|
32
|
+
* finished goes once persisted history holds that turn, which then shows what was saved of it.
|
|
32
33
|
*/
|
|
33
34
|
reconcile(nativeId: string, persisted: IHistoryItem[]): void;
|
|
34
|
-
/** Keeps
|
|
35
|
+
/** Keeps a turn's partial items available until native history holds the turn. */
|
|
35
36
|
completeTurn(nativeId: string, turnId: string): void;
|
|
36
37
|
/** Releases one cached window when the bounded window collection must evict it. */
|
|
37
38
|
private __remove;
|
|
@@ -28,7 +28,7 @@ export class LiveItems {
|
|
|
28
28
|
if (previous)
|
|
29
29
|
this.__bytes -= previous.bytes;
|
|
30
30
|
const bytes = Buffer.byteLength(JSON.stringify({ ...item, state: 'awaiting-flush' }));
|
|
31
|
-
thread.items.set(key, { item, isComplete, bytes });
|
|
31
|
+
thread.items.set(key, { item, isComplete, isUnfinished: false, bytes });
|
|
32
32
|
this.__bytes += bytes;
|
|
33
33
|
while (thread.items.size > 128)
|
|
34
34
|
this.__drop(thread, thread.items.keys().next().value);
|
|
@@ -106,12 +106,20 @@ export class LiveItems {
|
|
|
106
106
|
/**
|
|
107
107
|
* Drops completed items once persisted history holds them: with exactly matching normalized
|
|
108
108
|
* content, or, for an item with an outcome, the same final outcome, since a provider can shorten
|
|
109
|
-
* long output when it saves it, as Codex does.
|
|
109
|
+
* long output when it saves it, as Codex does. An item its turn ended before the provider
|
|
110
|
+
* finished goes once persisted history holds that turn, which then shows what was saved of it.
|
|
110
111
|
*/
|
|
111
112
|
reconcile(nativeId, persisted) {
|
|
112
113
|
const thread = this.__threads.get(nativeId);
|
|
113
114
|
if (!thread)
|
|
114
115
|
return;
|
|
116
|
+
const turns = new Set(persisted.map((item) => item.turnId));
|
|
117
|
+
for (const [key, entry] of thread.items)
|
|
118
|
+
if (entry.isUnfinished && turns.has(entry.item.turnId)) {
|
|
119
|
+
this.__bytes -= entry.bytes;
|
|
120
|
+
thread.items.delete(key);
|
|
121
|
+
thread.revision = ++this.__revision;
|
|
122
|
+
}
|
|
115
123
|
for (const item of persisted) {
|
|
116
124
|
const key = JSON.stringify([item.turnId, item.nativeId]);
|
|
117
125
|
const entry = thread.items.get(key);
|
|
@@ -126,15 +134,17 @@ export class LiveItems {
|
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
}
|
|
129
|
-
/** Keeps
|
|
137
|
+
/** Keeps a turn's partial items available until native history holds the turn. */
|
|
130
138
|
completeTurn(nativeId, turnId) {
|
|
131
139
|
const thread = this.__threads.get(nativeId);
|
|
132
|
-
if (thread)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
if (!thread)
|
|
141
|
+
return;
|
|
142
|
+
thread.revision = ++this.__revision;
|
|
143
|
+
for (const entry of thread.items.values())
|
|
144
|
+
if (entry.item.turnId === turnId && !entry.isComplete) {
|
|
145
|
+
entry.isComplete = true;
|
|
146
|
+
entry.isUnfinished = true;
|
|
147
|
+
}
|
|
138
148
|
}
|
|
139
149
|
/** Releases one cached window when the bounded window collection must evict it. */
|
|
140
150
|
__remove(nativeId) {
|
|
@@ -6,9 +6,9 @@ import { HqResponseSchema, } from '../../../contracts/index.js';
|
|
|
6
6
|
import { decodeBase64Image, decodeHistoryCursor, encodeHistoryCursor, imageUnavailable, } from '../../../sessions/index.js';
|
|
7
7
|
import { evidencePosition, buildEvidencePage, EVIDENCE_SOURCE_PAGE_SIZE, } from '../../../sessions/evidence/index.js';
|
|
8
8
|
import { EntryRowSchema, EntrySeekSchema, FileRowSchema, RecordSchema, ApiRequestMetadataSchema, SeekSchema, } from './types.js';
|
|
9
|
-
import { isClaudeAnswer, isClaudeCallFor, isClaudeRecordCwd, isClaudeWorkspaceCwd, openTranscript, projectDirectory, toClaudeDetail, toClaudeImageData, toClaudeItem, } from './utilities.js';
|
|
9
|
+
import { isClaudeAnswer, isClaudeCallFor, isClaudeRecordCwd, isClaudeWorkspaceCwd, openTranscript, projectDirectory, readClaudeParentUuid, toClaudeDetail, toClaudeImageData, toClaudeItem, } from './utilities.js';
|
|
10
10
|
// identifies the path and record interpretation used by persisted projection entries
|
|
11
|
-
const HISTORY_PROJECTION_VERSION =
|
|
11
|
+
const HISTORY_PROJECTION_VERSION = 7;
|
|
12
12
|
// one record, such as a tool result holding images, and an indexing read, which fits the largest
|
|
13
13
|
const MAX_RECORD_BYTES = 8_388_608;
|
|
14
14
|
const MAX_REFRESH_BYTES = 16_777_216;
|
|
@@ -398,7 +398,7 @@ export class ClaudeHistoryModel {
|
|
|
398
398
|
this.__unavailable();
|
|
399
399
|
const record = RecordSchema.parse(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)));
|
|
400
400
|
if (record.uuid !== entry.uuid ||
|
|
401
|
-
(record
|
|
401
|
+
readClaudeParentUuid(record) !== entry.parent_uuid ||
|
|
402
402
|
record.sessionId !== command.nativeId ||
|
|
403
403
|
!isClaudeRecordCwd(record.cwd, command.workspaceRoot))
|
|
404
404
|
this.__unavailable();
|
|
@@ -703,19 +703,18 @@ export class ClaudeHistoryModel {
|
|
|
703
703
|
this.__unavailable();
|
|
704
704
|
const createdAt = Date.parse(record.timestamp);
|
|
705
705
|
const statements = this.__recordStatements;
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
: undefined;
|
|
706
|
+
const parentUuid = readClaudeParentUuid(record);
|
|
707
|
+
const parent = parentUuid ? statements.parentTurn.get(root, nativeId, parentUuid) : undefined;
|
|
709
708
|
// the CLI's presentation decides what is shown, the kind evidence filters on and where turns start
|
|
710
709
|
const item = record.message !== undefined && !record.isMeta ? toClaudeItem(record, record.uuid) : null;
|
|
711
710
|
const visible = item !== null;
|
|
712
|
-
if (
|
|
711
|
+
if (parentUuid === record.uuid)
|
|
713
712
|
this.__unavailable();
|
|
714
|
-
if (
|
|
713
|
+
if (parentUuid && !parent) {
|
|
715
714
|
if (visible)
|
|
716
715
|
this.__unavailable();
|
|
717
716
|
if (!isOrphanAllowed)
|
|
718
|
-
return
|
|
717
|
+
return parentUuid;
|
|
719
718
|
}
|
|
720
719
|
const textPrompt = item?.kind === 'user-message';
|
|
721
720
|
const turnId = textPrompt
|
|
@@ -724,10 +723,10 @@ export class ClaudeHistoryModel {
|
|
|
724
723
|
? parent.turn_id
|
|
725
724
|
: record.uuid;
|
|
726
725
|
const previous = statements.recordedParent.get(root, nativeId, record.uuid);
|
|
727
|
-
if (previous && previous.parent_uuid !==
|
|
726
|
+
if (previous && previous.parent_uuid !== parentUuid)
|
|
728
727
|
this.__unavailable();
|
|
729
728
|
const isAppend = row.leaf_id === null || parent?.anchor_id === row.leaf_id;
|
|
730
|
-
const isSameLeaf = record.uuid === row.leaf_id && previous?.parent_uuid ===
|
|
729
|
+
const isSameLeaf = record.uuid === row.leaf_id && previous?.parent_uuid === parentUuid;
|
|
731
730
|
if (visible && !isAppend)
|
|
732
731
|
row.revision = randomUUID();
|
|
733
732
|
const turnStart = textPrompt
|
|
@@ -742,7 +741,7 @@ export class ClaudeHistoryModel {
|
|
|
742
741
|
: typeof parent?.anchor_id === 'string'
|
|
743
742
|
? parent.anchor_id
|
|
744
743
|
: null;
|
|
745
|
-
statements.upsert.run(root, nativeId, record.uuid,
|
|
744
|
+
statements.upsert.run(root, nativeId, record.uuid, parentUuid, turnId, offset, bytes.length, createdAt, visible ? 1 : 0, visible ? 1 : 0, turnStart, anchorId, item?.kind ?? 'unsupported');
|
|
746
745
|
if (visible) {
|
|
747
746
|
if (!isAppend && !isSameLeaf)
|
|
748
747
|
statements.currentChain.run(root, nativeId, record.uuid, root, nativeId);
|
|
@@ -2274,6 +2274,8 @@ export declare const RecordSchema: z.ZodObject<{
|
|
|
2274
2274
|
type: z.ZodString;
|
|
2275
2275
|
uuid: z.ZodOptional<z.ZodString>;
|
|
2276
2276
|
parentUuid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
2277
|
+
logicalParentUuid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
2278
|
+
subtype: z.ZodOptional<z.ZodString>;
|
|
2277
2279
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
2278
2280
|
cwd: z.ZodOptional<z.ZodString>;
|
|
2279
2281
|
timestamp: z.ZodOptional<z.ZodString>;
|
|
@@ -43,6 +43,9 @@ export const RecordSchema = z.object({
|
|
|
43
43
|
type: z.string().min(1).max(256),
|
|
44
44
|
uuid: z.string().min(1).max(4096).optional(),
|
|
45
45
|
parentUuid: z.string().nullable().optional(),
|
|
46
|
+
// a compaction boundary starts a new chain, and names the record it follows here
|
|
47
|
+
logicalParentUuid: z.string().nullable().optional(),
|
|
48
|
+
subtype: z.string().optional(),
|
|
46
49
|
sessionId: z.string().optional(),
|
|
47
50
|
cwd: z.string().optional(),
|
|
48
51
|
timestamp: z.string().optional(),
|
|
@@ -7,6 +7,17 @@ import { type IRecord } from './types.js';
|
|
|
7
7
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
8
8
|
*/
|
|
9
9
|
export declare const projectDirectory: (workspaceRoot: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Names the record a record follows in its conversation: its parent, or, for the boundary a
|
|
12
|
+
* compaction writes, which starts a new chain with no parent, the record before the compaction,
|
|
13
|
+
* so the history reads on past it.
|
|
14
|
+
* @param record The record.
|
|
15
|
+
* @returns The record it follows, or null for the conversation's first.
|
|
16
|
+
* @example
|
|
17
|
+
* const parent = readClaudeParentUuid({ type: 'system', subtype: 'compact_boundary', parentUuid: null, logicalParentUuid: 'a1' });
|
|
18
|
+
* // => 'a1'
|
|
19
|
+
*/
|
|
20
|
+
export declare const readClaudeParentUuid: (record: IRecord) => string | null;
|
|
10
21
|
/**
|
|
11
22
|
* Verifies a native cwd within its selected workspace, including removed subdirectories.
|
|
12
23
|
* @returns Whether existing path ancestors remain inside the workspace without excluded segments.
|
|
@@ -54,6 +54,20 @@ export const projectDirectory = (workspaceRoot) => {
|
|
|
54
54
|
});
|
|
55
55
|
return directory;
|
|
56
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Names the record a record follows in its conversation: its parent, or, for the boundary a
|
|
59
|
+
* compaction writes, which starts a new chain with no parent, the record before the compaction,
|
|
60
|
+
* so the history reads on past it.
|
|
61
|
+
* @param record The record.
|
|
62
|
+
* @returns The record it follows, or null for the conversation's first.
|
|
63
|
+
* @example
|
|
64
|
+
* const parent = readClaudeParentUuid({ type: 'system', subtype: 'compact_boundary', parentUuid: null, logicalParentUuid: 'a1' });
|
|
65
|
+
* // => 'a1'
|
|
66
|
+
*/
|
|
67
|
+
export const readClaudeParentUuid = (record) => record.parentUuid ??
|
|
68
|
+
(record.type === 'system' && record.subtype === 'compact_boundary'
|
|
69
|
+
? (record.logicalParentUuid ?? null)
|
|
70
|
+
: null);
|
|
57
71
|
/**
|
|
58
72
|
* Verifies a native cwd within its selected workspace, including removed subdirectories.
|
|
59
73
|
* @returns Whether existing path ancestors remain inside the workspace without excluded segments.
|
|
@@ -147,8 +161,23 @@ const COMMAND = /^<command-(?:message|name)>/;
|
|
|
147
161
|
const COMMAND_NAME = /<command-name>\/?([^<]*)<\/command-name>/;
|
|
148
162
|
const COMMAND_ARGS = /<command-args>([\s\S]*?)<\/command-args>/;
|
|
149
163
|
const PERSISTED_OUTPUT = /^<persisted-output>\nOutput too large \(([^)\n]{1,64})\)\. Full output saved to: [^\n]*\n\nPreview \([^)\n]*\):\n([\s\S]*?)\n?<\/persisted-output>([\s\S]*)$/;
|
|
150
|
-
|
|
164
|
+
// a part of a tool result made of content blocks, as the CLI shows it, with an image as [Image]
|
|
165
|
+
const toResultPartText = (part) => {
|
|
166
|
+
const block = BlockSchema.safeParse(part).data;
|
|
167
|
+
if (!block)
|
|
168
|
+
return UNSUPPORTED;
|
|
169
|
+
if (block.type === 'text')
|
|
170
|
+
return block.text ?? '';
|
|
171
|
+
return block.type === 'image' ? '[Image]' : `[Native ${block.type}]`;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Shows a tool result as the CLI does: its text, the parts of one made of content blocks, such as
|
|
175
|
+
* a screenshot's caption and image, and one saved to a file as its size and preview, without the
|
|
176
|
+
* file's path.
|
|
177
|
+
*/
|
|
151
178
|
const toResultText = (block) => {
|
|
179
|
+
if (Array.isArray(block.content))
|
|
180
|
+
return block.content.map(toResultPartText).join('\n');
|
|
152
181
|
if (typeof block.content !== 'string')
|
|
153
182
|
return `[Native ${block.type}]`;
|
|
154
183
|
const persisted = PERSISTED_OUTPUT.exec(block.content);
|
package/package.json
CHANGED