@wherever-dev/client 0.3.1 → 0.3.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 +51 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +220 -59
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
- package/src/client.ts +222 -61
- package/src/types.ts +28 -0
- package/test/tool-aborted-render.test.ts +170 -0
- package/test/tool-interrupted-history.test.ts +294 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @wherever-dev/client
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4836b65: Fix dangling tool calls being hoisted to the end of the transcript on the web frontend, showing as a phantom "series of aborted tool calls" after the latest reply.
|
|
8
|
+
|
|
9
|
+
When loaded history contained a tool call with no matching tool result (e.g. an interrupted long-running `bash` that was superseded by a new user turn, then more replies), the web history mapping deferred every unmatched tool call and appended them all AFTER the last mapped message. So dangling calls from the MIDDLE of the conversation piled up below the latest assistant reply, even though the CLI (and the actual transcript) has them inline where they were issued. The reproducing session was a deliberate recoverability test ("Generate a long message..."/"long running tool call using bash sleep" then interrupting it).
|
|
10
|
+
|
|
11
|
+
The mapping now renders each tool call IN PLACE at its position in the stream: a result-less tool message is emitted when the tool call is seen, and its matching tool result fills it in later (oldest-open-first per tool name, preserving the parallel-call FIFO behaviour). A call that never receives a result stays exactly where it was issued, correctly marked `interrupted` (neutral "no result" state), instead of migrating to the end. On the live streaming tail, only the newest still-open call is kept streaming ("Elapsed" ticking); earlier open calls in the window are interrupted.
|
|
12
|
+
|
|
13
|
+
Tests: two new client tests covering (1) a mid-conversation dangling call staying in place with the final message still an assistant reply, and (2) multiple dangling calls where only the newest streams on the live tail while earlier ones are interrupted in place. All existing tool abort/interrupted/duration tests still pass.
|
|
14
|
+
|
|
15
|
+
- 12083e5: Render an aborted tool call as interrupted, not a red error.
|
|
16
|
+
|
|
17
|
+
When you hit the web "abort" button while tools are running, pi kills the in-flight tools and surfaces each as an errored result with a trailing "...aborted" status ("Command aborted" for bash, "Operation aborted" for edit/write). The web then rendered that as a red error tick, as if the tool had genuinely failed. With parallel tool calls this was especially confusing: a tool that happened to finish just before the abort showed a green success tick while the killed one showed a red error, even though the user aborted the whole turn.
|
|
18
|
+
|
|
19
|
+
The client now detects an abort result (an errored result whose trailing status line is "...aborted") and renders it with the neutral "interrupted" state (muted icon, neutral border) instead of a red error, on both the live tool_end path and when reconstructing from loaded history. A tool that genuinely completed keeps its green success, and a genuine failure keeps its red error. The match is anchored to the trailing status line, so ordinary command output that merely contains the word "aborted" is not misclassified.
|
|
20
|
+
|
|
21
|
+
Also fixes a related mismatch with PARALLEL same-named tools. Live tool_end frames were matched to a tool message by name via a last-match search, so with two concurrent bash calls both tool_end frames could land on the same message, leaving the other tool stuck streaming; it was then finalized by the agent_end sweep with no result and shown as a bogus green success tick. tool_end now claims the OLDEST still-streaming tool of that name (FIFO), so each concurrent call settles a distinct message. And any tool still streaming when the turn ends (agent_end) is now marked interrupted rather than left to render green, since its outcome is unknown.
|
|
22
|
+
|
|
23
|
+
Also adds a `tool-calls` (parallel tool_use) behavior to the test fake LLM to exercise concurrent tool execution.
|
|
24
|
+
|
|
25
|
+
- db16623: Render `read`-tool image output inline in the web frontend, mirroring the CLI's inline image display.
|
|
26
|
+
|
|
27
|
+
When the agent uses the builtin `read` tool on an image path, the pi tool result carries an image content block (`{type:'image', data, mimeType}`) alongside the text note. Previously the server's `extractToolResult` kept only text blocks, so the web never saw the image. The server now also pulls image blocks out of the tool result and ships them (base64 + mimeType) on the `tool_end` frame via a new optional `images` field, and reconstructs them from history when a session is reloaded. The client stores them on the `ChatMessage` (`images`), and the web renders each image inline right under the tool header, always visible (not hidden behind the collapse toggle), while the textual arguments/output stay collapsible. Click an image to open it full size. Text-only tools are unaffected.
|
|
28
|
+
|
|
29
|
+
- 9931867: Pair reconstructed tool results to their exact tool call by id, not just by tool name.
|
|
30
|
+
|
|
31
|
+
The server now forwards the tool-call id on both `tool_call` (the id the assistant issued) and `tool_result` (the `toolCallId` it satisfies) history messages, and the web history mapping matches a result to its exact call by that id, falling back to the previous oldest-open-first per-tool-name behaviour only when no id is present (older sessions, or the synthesized `bashExecution` pair).
|
|
32
|
+
|
|
33
|
+
This fixes mis-pairing when same-named calls interleave with some left dangling: e.g. two `bash` calls issued back-to-back where only the second returns a result. Name-FIFO alone would resolve the first call and leave the second dangling; id matching resolves the correct one and leaves the genuinely-interrupted call marked interrupted, in place.
|
|
34
|
+
|
|
35
|
+
Tests: a new client test covering id-exact pairing (result resolves call #2 by id, leaving call #1 dangling/interrupted, order preserved).
|
|
36
|
+
|
|
37
|
+
- 8536f30: Warn both the web frontend and the CLI when a CLI takeover discards an in-flight turn.
|
|
38
|
+
|
|
39
|
+
When a `pi` CLI resumes/registers a session while the standalone server is mid-turn for a web viewer, the CLI seizes control and the server disposes its live agent. Disposing mid-turn discards the whole in-flight turn without persisting it (persistence only happens on turn completion), so the web viewer, who was watching a tool run or a reply stream, lost it silently with no explanation.
|
|
40
|
+
|
|
41
|
+
The server now detects that the server-side agent was mid-turn at takeover and sends the attached web clients a non-fatal `session_notice` (level: warning). The web frontend renders it as a dismissible banner. The wording is tailored to what was lost: a running tool call (tracked via a per-session in-flight tool-execution count, so its result never arrives) or a streaming reply (the partial text is discarded and not saved). A takeover of an already-settled (idle) session is not flagged. The session stays attached (informational, unlike `session_interrupted`).
|
|
42
|
+
|
|
43
|
+
The notice also states the takeover semantics accurately: once the CLI has taken over it owns the session's execution loop, so messages sent from the web frontend are relayed to the CLI rather than wresting control back. The web frontend regains control only when the CLI disconnects.
|
|
44
|
+
|
|
45
|
+
The CLI side is covered too. On register, the server sends the taking-over CLI a `cli_takeover_interrupted` message, and the Wherever extension surfaces a single matching notice. This closes a blind spot: a still-streaming turn is never persisted, so the extension's own resumed-mid-tool-call check (which reads the saved transcript) cannot see the streaming-text case. For the tool-call case, the extension's transcript check already warns with the tool names, so the server-driven notice defers to it to avoid a duplicate.
|
|
46
|
+
|
|
47
|
+
Also fixes the web frontend rendering a killed-then-orphaned tool call as a green success tick. When a CLI takeover kills an in-flight tool (the pi SDK aborts the run and SIGKILLs the tool's process tree, so it does not keep running in the background), the transcript keeps a dangling toolCall with no toolResult. The web history mapping now flags such a result-less, non-streaming tool call as `interrupted`, and the UI shows a neutral "interrupted, no result" state (a muted ⊘ icon, neutral border, and an explanatory output note) instead of the green ✅ "Succeeded": its outcome is genuinely unknown, neither success nor failure.
|
|
48
|
+
|
|
49
|
+
Also cleans up the CLI's resumed-mid-run warning (the extension's dangling-tool-call widget):
|
|
50
|
+
- It now counts only the TRAILING dangling tool calls (those after the last user message on the active branch), not every unsatisfied tool call in the whole session. Earlier turns' interrupted tool calls are already superseded by a later human turn and do not block auto-continue, so they were over-counted (e.g. "4 tool calls" when only 1 was actually blocking).
|
|
51
|
+
- It shows a single persistent widget instead of a widget plus a duplicate transient notify.
|
|
52
|
+
- Its guidance is corrected: the CLI has already taken over, so it says to send a message to retry or continue, rather than the stale "send a message to take over".
|
|
53
|
+
|
|
3
54
|
## 0.3.1
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -52,6 +52,18 @@ export declare class WhereverClient {
|
|
|
52
52
|
private clearCreateWatchdog;
|
|
53
53
|
private scheduleReconnect;
|
|
54
54
|
private handleMessage;
|
|
55
|
+
/**
|
|
56
|
+
* True when an errored tool result is the product of a USER ABORT (e.g. the
|
|
57
|
+
* web "abort" button killed a running tool), rather than a genuine tool
|
|
58
|
+
* failure. The pi tools append a trailing status line on abort ("Command
|
|
59
|
+
* aborted" for bash, "Operation aborted" for edit/write, bare "aborted" for a
|
|
60
|
+
* pre-execution abort). We match that trailing status so the UI can render a
|
|
61
|
+
* neutral "interrupted" state instead of a red error: you cancelling a tool is
|
|
62
|
+
* not the tool failing. Only meaningful when isError is already true; matched
|
|
63
|
+
* as the LAST non-empty line to avoid false positives from command output that
|
|
64
|
+
* merely contains the word "aborted".
|
|
65
|
+
*/
|
|
66
|
+
private isAbortedToolResult;
|
|
55
67
|
/**
|
|
56
68
|
* Map a server `HistoryMessage[]` window into UI `ChatMessage[]`. When
|
|
57
69
|
* `applyStreamingTail` is true, the last assistant/thinking message and any
|
|
@@ -84,6 +96,7 @@ export declare class WhereverClient {
|
|
|
84
96
|
ping(): void;
|
|
85
97
|
clearMessages(): void;
|
|
86
98
|
dismissSessionError(): void;
|
|
99
|
+
dismissNotice(): void;
|
|
87
100
|
changeModel(model: string): void;
|
|
88
101
|
setConfig(updates: Partial<WhereverClientConfig>): void;
|
|
89
102
|
onMessage(cb: (msg: any) => void): () => void;
|
package/dist/client.js
CHANGED
|
@@ -14,6 +14,7 @@ const defaultState = {
|
|
|
14
14
|
clientId: null,
|
|
15
15
|
conflict: null,
|
|
16
16
|
isInterrupted: false,
|
|
17
|
+
notice: null,
|
|
17
18
|
sessionError: null,
|
|
18
19
|
readOnly: false,
|
|
19
20
|
activeSessionFile: null,
|
|
@@ -730,6 +731,13 @@ export class WhereverClient {
|
|
|
730
731
|
? {
|
|
731
732
|
...m,
|
|
732
733
|
isStreaming: false,
|
|
734
|
+
// A tool still streaming when the turn ends never got a
|
|
735
|
+
// tool_end (e.g. the turn was aborted, or its result frame
|
|
736
|
+
// was lost): its outcome is unknown. Mark it interrupted
|
|
737
|
+
// (neutral), never let it fall through to a green success
|
|
738
|
+
// tick, which would falsely claim it succeeded. Assistant/
|
|
739
|
+
// thinking messages just stop streaming.
|
|
740
|
+
...(m.role === 'tool' ? { interrupted: true } : {}),
|
|
733
741
|
// Freeze a still-running tool's duration if it never got a
|
|
734
742
|
// tool_end (turn ended between steps), so "Elapsed" stops
|
|
735
743
|
// ticking and shows the final "Took".
|
|
@@ -804,15 +812,35 @@ export class WhereverClient {
|
|
|
804
812
|
}
|
|
805
813
|
case 'tool_end': {
|
|
806
814
|
const result = msg.result ? `${msg.result}` : '';
|
|
815
|
+
// An abort (e.g. the web "abort" button killed the tool mid-run) surfaces
|
|
816
|
+
// as isError with a trailing "...aborted" status. That is not a tool
|
|
817
|
+
// FAILURE, so render it as the neutral interrupted state, not a red
|
|
818
|
+
// error.
|
|
819
|
+
const aborted = !!msg.isError && this.isAbortedToolResult(result);
|
|
820
|
+
const effectiveIsError = !!msg.isError && !aborted;
|
|
821
|
+
const toolImages = Array.isArray(msg.images) && msg.images.length > 0
|
|
822
|
+
? msg.images
|
|
823
|
+
: undefined;
|
|
807
824
|
this.stateStore.update((s) => {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
825
|
+
// Claim the OLDEST still-streaming tool of this name (FIFO). Parallel
|
|
826
|
+
// tool calls share a name, so matching the LAST one (or any already
|
|
827
|
+
// finalized one) would let two tool_end frames land on the SAME
|
|
828
|
+
// message and leave the other tool stuck streaming: it would then be
|
|
829
|
+
// finalized by the 'aborted'/agent_end sweep with no result and render
|
|
830
|
+
// as a bogus green success. Preferring a streaming message means each
|
|
831
|
+
// tool_end settles a distinct in-flight call. Fall back to the newest
|
|
832
|
+
// non-error tool of this name only if none are still streaming.
|
|
833
|
+
const toolMsg = s.messages.find((m) => m.role === 'tool' &&
|
|
811
834
|
m.toolName === msg.toolName &&
|
|
812
|
-
|
|
835
|
+
m.isStreaming) ??
|
|
836
|
+
[...s.messages]
|
|
837
|
+
.reverse()
|
|
838
|
+
.find((m) => m.role === 'tool' &&
|
|
839
|
+
m.toolName === msg.toolName &&
|
|
840
|
+
!m.content.startsWith('Tool error:'));
|
|
813
841
|
const endedAt = Date.now();
|
|
814
842
|
if (toolMsg) {
|
|
815
|
-
const errorPrefix =
|
|
843
|
+
const errorPrefix = effectiveIsError ? 'Error: ' : '';
|
|
816
844
|
return {
|
|
817
845
|
...s,
|
|
818
846
|
messages: s.messages.map((m) => m.id === toolMsg.id
|
|
@@ -820,15 +848,17 @@ export class WhereverClient {
|
|
|
820
848
|
...m,
|
|
821
849
|
content: `${errorPrefix}${m.content}\n${result}`,
|
|
822
850
|
isStreaming: false,
|
|
823
|
-
isError:
|
|
851
|
+
isError: effectiveIsError,
|
|
852
|
+
interrupted: aborted,
|
|
824
853
|
toolOutput: result,
|
|
854
|
+
...(toolImages ? { images: toolImages } : {}),
|
|
825
855
|
endedAt,
|
|
826
856
|
}
|
|
827
857
|
: m),
|
|
828
858
|
};
|
|
829
859
|
}
|
|
830
860
|
else {
|
|
831
|
-
const content =
|
|
861
|
+
const content = effectiveIsError
|
|
832
862
|
? `Tool error: ${msg.toolName}\n${result}`
|
|
833
863
|
: `${msg.toolName}\n${result}`;
|
|
834
864
|
const message = {
|
|
@@ -840,7 +870,9 @@ export class WhereverClient {
|
|
|
840
870
|
toolName: msg.toolName,
|
|
841
871
|
toolArgs: '',
|
|
842
872
|
toolOutput: result,
|
|
843
|
-
|
|
873
|
+
...(toolImages ? { images: toolImages } : {}),
|
|
874
|
+
isError: effectiveIsError,
|
|
875
|
+
interrupted: aborted,
|
|
844
876
|
endedAt,
|
|
845
877
|
};
|
|
846
878
|
return {
|
|
@@ -860,6 +892,11 @@ export class WhereverClient {
|
|
|
860
892
|
? {
|
|
861
893
|
...m,
|
|
862
894
|
isStreaming: false,
|
|
895
|
+
// A tool still streaming when the turn is aborted was killed
|
|
896
|
+
// with no result: mark it interrupted (neutral), never leave
|
|
897
|
+
// it to fall through to a green success tick. Assistant/
|
|
898
|
+
// thinking messages just stop streaming.
|
|
899
|
+
...(m.role === 'tool' ? { interrupted: true } : {}),
|
|
863
900
|
endedAt: m.role === 'tool' && m.endedAt === undefined
|
|
864
901
|
? abortedAt
|
|
865
902
|
: m.endedAt,
|
|
@@ -914,6 +951,17 @@ export class WhereverClient {
|
|
|
914
951
|
contextUsage: msg.contextUsage ?? null,
|
|
915
952
|
}));
|
|
916
953
|
break;
|
|
954
|
+
case 'session_notice':
|
|
955
|
+
// A non-fatal notice for the active session (e.g. a CLI took over while
|
|
956
|
+
// this session was mid-turn here, discarding the in-flight tool call or
|
|
957
|
+
// streaming reply). Keep the session attached; surface it as a
|
|
958
|
+
// dismissible banner. Ignore a notice for a session we switched away from.
|
|
959
|
+
this.stateStore.update((s) => {
|
|
960
|
+
if (s.sessionId && msg.sessionId && s.sessionId !== msg.sessionId)
|
|
961
|
+
return s;
|
|
962
|
+
return { ...s, notice: { level: msg.level, message: msg.message } };
|
|
963
|
+
});
|
|
964
|
+
break;
|
|
917
965
|
case 'session_destroyed':
|
|
918
966
|
this.stateStore.update((s) => {
|
|
919
967
|
if (s.sessionId === msg.sessionId) {
|
|
@@ -927,6 +975,7 @@ export class WhereverClient {
|
|
|
927
975
|
activeModel: null,
|
|
928
976
|
loadingSession: false,
|
|
929
977
|
agentPending: false,
|
|
978
|
+
notice: null,
|
|
930
979
|
};
|
|
931
980
|
}
|
|
932
981
|
return s;
|
|
@@ -974,6 +1023,7 @@ export class WhereverClient {
|
|
|
974
1023
|
creatingSession: false,
|
|
975
1024
|
loadingSession: false,
|
|
976
1025
|
agentPending: false,
|
|
1026
|
+
notice: null,
|
|
977
1027
|
}));
|
|
978
1028
|
break;
|
|
979
1029
|
case 'message_history': {
|
|
@@ -1049,6 +1099,24 @@ export class WhereverClient {
|
|
|
1049
1099
|
break;
|
|
1050
1100
|
}
|
|
1051
1101
|
}
|
|
1102
|
+
/**
|
|
1103
|
+
* True when an errored tool result is the product of a USER ABORT (e.g. the
|
|
1104
|
+
* web "abort" button killed a running tool), rather than a genuine tool
|
|
1105
|
+
* failure. The pi tools append a trailing status line on abort ("Command
|
|
1106
|
+
* aborted" for bash, "Operation aborted" for edit/write, bare "aborted" for a
|
|
1107
|
+
* pre-execution abort). We match that trailing status so the UI can render a
|
|
1108
|
+
* neutral "interrupted" state instead of a red error: you cancelling a tool is
|
|
1109
|
+
* not the tool failing. Only meaningful when isError is already true; matched
|
|
1110
|
+
* as the LAST non-empty line to avoid false positives from command output that
|
|
1111
|
+
* merely contains the word "aborted".
|
|
1112
|
+
*/
|
|
1113
|
+
isAbortedToolResult(result) {
|
|
1114
|
+
if (!result)
|
|
1115
|
+
return false;
|
|
1116
|
+
const lines = result.trimEnd().split('\n');
|
|
1117
|
+
const last = (lines[lines.length - 1] || '').trim();
|
|
1118
|
+
return /^(command|operation)?\s*aborted$/i.test(last);
|
|
1119
|
+
}
|
|
1052
1120
|
/**
|
|
1053
1121
|
* Map a server `HistoryMessage[]` window into UI `ChatMessage[]`. When
|
|
1054
1122
|
* `applyStreamingTail` is true, the last assistant/thinking message and any
|
|
@@ -1057,48 +1125,134 @@ export class WhereverClient {
|
|
|
1057
1125
|
*/
|
|
1058
1126
|
mapHistory(rawMessages, sessionId, applyStreamingTail) {
|
|
1059
1127
|
const mapped = [];
|
|
1060
|
-
//
|
|
1061
|
-
//
|
|
1062
|
-
//
|
|
1063
|
-
//
|
|
1064
|
-
|
|
1128
|
+
// A tool_call is rendered IN PLACE, at its position in the stream, as a tool
|
|
1129
|
+
// message that is initially result-less. Its matching tool_result fills it
|
|
1130
|
+
// in later. We track the still-open calls per tool name as indices into
|
|
1131
|
+
// `mapped`, so a call that never receives a result simply stays where it was
|
|
1132
|
+
// issued (correctly marked interrupted below) instead of being hoisted to
|
|
1133
|
+
// the very end of the transcript. The end-hoisting was the bug: dangling
|
|
1134
|
+
// tool calls from EARLIER in the conversation (e.g. an interrupted long-
|
|
1135
|
+
// running bash, later superseded by a new user turn) would all pile up as a
|
|
1136
|
+
// "series of aborted tool calls" AFTER the latest reply, even though the CLI
|
|
1137
|
+
// shows them inline where they happened.
|
|
1138
|
+
//
|
|
1139
|
+
// Matching is by tool-call id when present (the server forwards it on both
|
|
1140
|
+
// tool_call and tool_result), which pairs a result to its EXACT call even
|
|
1141
|
+
// when same-named calls interleave with some left dangling. When the id is
|
|
1142
|
+
// absent (older sessions, or the synthesized bashExecution pair) we fall
|
|
1143
|
+
// back to oldest-open-first per tool name.
|
|
1144
|
+
const openCalls = {};
|
|
1145
|
+
const openById = {};
|
|
1146
|
+
// Drop a resolved call's index from the name-FIFO list so an id match and a
|
|
1147
|
+
// later name-fallback can never both consume the same call.
|
|
1148
|
+
const removeFromNameQueue = (tName, idx) => {
|
|
1149
|
+
const q = openCalls[tName];
|
|
1150
|
+
if (!q)
|
|
1151
|
+
return;
|
|
1152
|
+
const at = q.indexOf(idx);
|
|
1153
|
+
if (at !== -1)
|
|
1154
|
+
q.splice(at, 1);
|
|
1155
|
+
};
|
|
1065
1156
|
for (const m of rawMessages) {
|
|
1066
1157
|
if (m.role === 'tool_call') {
|
|
1067
1158
|
const tName = m.toolName || 'unknown';
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
}
|
|
1071
|
-
pendingCalls[tName].push({ args: m.content || '', startedAt: m.timestamp });
|
|
1072
|
-
}
|
|
1073
|
-
else if (m.role === 'tool_result') {
|
|
1074
|
-
const tName = m.toolName || 'unknown';
|
|
1075
|
-
const call = pendingCalls[tName] && pendingCalls[tName].length > 0
|
|
1076
|
-
? pendingCalls[tName].shift()
|
|
1077
|
-
: undefined;
|
|
1078
|
-
const tArgs = call?.args ?? '';
|
|
1159
|
+
const args = m.content || '';
|
|
1160
|
+
const idx = mapped.length;
|
|
1079
1161
|
mapped.push({
|
|
1080
1162
|
id: this.generateId(),
|
|
1081
1163
|
role: 'tool',
|
|
1082
|
-
content:
|
|
1083
|
-
? `$ ${tName} ${tArgs}\n${m.content}`
|
|
1084
|
-
: `$ ${tName}\n${m.content}`,
|
|
1164
|
+
content: args ? `$ ${tName} ${args}` : `$ ${tName}`,
|
|
1085
1165
|
timestamp: m.timestamp,
|
|
1166
|
+
// No result yet. Marked as interrupted below if it stays unmatched;
|
|
1167
|
+
// the streaming tail promotes the last one back to streaming.
|
|
1086
1168
|
isStreaming: false,
|
|
1087
1169
|
toolName: tName,
|
|
1088
|
-
toolArgs:
|
|
1089
|
-
toolOutput:
|
|
1090
|
-
isError: m.isError,
|
|
1170
|
+
toolArgs: args,
|
|
1171
|
+
toolOutput: '',
|
|
1091
1172
|
sessionId,
|
|
1092
|
-
//
|
|
1093
|
-
//
|
|
1094
|
-
|
|
1095
|
-
...(call &&
|
|
1096
|
-
Number.isFinite(call.startedAt) &&
|
|
1097
|
-
Number.isFinite(m.timestamp) &&
|
|
1098
|
-
m.timestamp >= call.startedAt
|
|
1099
|
-
? { startedAt: call.startedAt, endedAt: m.timestamp }
|
|
1100
|
-
: {}),
|
|
1173
|
+
// Keep the start so a matched result (or a still-running streaming
|
|
1174
|
+
// tail) can show a coherent duration / "Elapsed".
|
|
1175
|
+
...(Number.isFinite(m.timestamp) ? { startedAt: m.timestamp } : {}),
|
|
1101
1176
|
});
|
|
1177
|
+
if (!openCalls[tName])
|
|
1178
|
+
openCalls[tName] = [];
|
|
1179
|
+
openCalls[tName].push(idx);
|
|
1180
|
+
if (typeof m.toolCallId === 'string' && m.toolCallId) {
|
|
1181
|
+
openById[m.toolCallId] = idx;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
else if (m.role === 'tool_result') {
|
|
1185
|
+
const tName = m.toolName || 'unknown';
|
|
1186
|
+
// Prefer an exact id match; else fill the OLDEST still-open call of this
|
|
1187
|
+
// name (FIFO), mirroring how parallel same-named calls resolve in order.
|
|
1188
|
+
let callIdx;
|
|
1189
|
+
if (typeof m.toolCallId === 'string' &&
|
|
1190
|
+
m.toolCallId &&
|
|
1191
|
+
openById[m.toolCallId] !== undefined) {
|
|
1192
|
+
callIdx = openById[m.toolCallId];
|
|
1193
|
+
delete openById[m.toolCallId];
|
|
1194
|
+
removeFromNameQueue(tName, callIdx);
|
|
1195
|
+
}
|
|
1196
|
+
else if (openCalls[tName] && openCalls[tName].length > 0) {
|
|
1197
|
+
callIdx = openCalls[tName].shift();
|
|
1198
|
+
// Keep openById consistent if this call had also registered an id.
|
|
1199
|
+
for (const [id, i] of Object.entries(openById)) {
|
|
1200
|
+
if (i === callIdx)
|
|
1201
|
+
delete openById[id];
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
const isError = m.isError && !this.isAbortedToolResult(m.content);
|
|
1205
|
+
const interrupted = !!m.isError && this.isAbortedToolResult(m.content);
|
|
1206
|
+
if (callIdx !== undefined) {
|
|
1207
|
+
const call = mapped[callIdx];
|
|
1208
|
+
const tArgs = call.toolArgs || '';
|
|
1209
|
+
const startedAt = call.startedAt;
|
|
1210
|
+
mapped[callIdx] = {
|
|
1211
|
+
...call,
|
|
1212
|
+
content: tArgs
|
|
1213
|
+
? `$ ${tName} ${tArgs}\n${m.content}`
|
|
1214
|
+
: `$ ${tName}\n${m.content}`,
|
|
1215
|
+
isStreaming: false,
|
|
1216
|
+
toolOutput: m.content,
|
|
1217
|
+
...(Array.isArray(m.images) && m.images.length > 0
|
|
1218
|
+
? { images: m.images }
|
|
1219
|
+
: {}),
|
|
1220
|
+
// A user abort surfaces as an errored result with a trailing
|
|
1221
|
+
// "...aborted" status. Render it as interrupted (neutral), not a red
|
|
1222
|
+
// error: aborting a tool is not the tool failing.
|
|
1223
|
+
isError,
|
|
1224
|
+
interrupted,
|
|
1225
|
+
timestamp: m.timestamp,
|
|
1226
|
+
// Duration only when both timestamps are finite and coherent
|
|
1227
|
+
// (end >= start); otherwise leave unset rather than show a bogus one.
|
|
1228
|
+
...(startedAt !== undefined &&
|
|
1229
|
+
Number.isFinite(startedAt) &&
|
|
1230
|
+
Number.isFinite(m.timestamp) &&
|
|
1231
|
+
m.timestamp >= startedAt
|
|
1232
|
+
? { endedAt: m.timestamp }
|
|
1233
|
+
: {}),
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
else {
|
|
1237
|
+
// A result with no preceding open call (shouldn't normally happen).
|
|
1238
|
+
// Render it in place as a standalone tool message so nothing is lost.
|
|
1239
|
+
mapped.push({
|
|
1240
|
+
id: this.generateId(),
|
|
1241
|
+
role: 'tool',
|
|
1242
|
+
content: `$ ${tName}\n${m.content}`,
|
|
1243
|
+
timestamp: m.timestamp,
|
|
1244
|
+
isStreaming: false,
|
|
1245
|
+
toolName: tName,
|
|
1246
|
+
toolArgs: '',
|
|
1247
|
+
toolOutput: m.content,
|
|
1248
|
+
...(Array.isArray(m.images) && m.images.length > 0
|
|
1249
|
+
? { images: m.images }
|
|
1250
|
+
: {}),
|
|
1251
|
+
isError,
|
|
1252
|
+
interrupted,
|
|
1253
|
+
sessionId,
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1102
1256
|
}
|
|
1103
1257
|
else {
|
|
1104
1258
|
mapped.push({
|
|
@@ -1112,26 +1266,28 @@ export class WhereverClient {
|
|
|
1112
1266
|
});
|
|
1113
1267
|
}
|
|
1114
1268
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1269
|
+
// Any call still open (issued a toolCall, never got a tool_result) is FROZEN
|
|
1270
|
+
// in place with no result. Meaning depends on context:
|
|
1271
|
+
// - streaming tail (applyStreamingTail): only the MOST RECENT open call is
|
|
1272
|
+
// plausibly still running; keep it streaming so the UI ticks "Elapsed".
|
|
1273
|
+
// Earlier open calls in the same window are already superseded and are
|
|
1274
|
+
// interrupted.
|
|
1275
|
+
// - otherwise: its outcome is unknown (e.g. a CLI takeover / interruption
|
|
1276
|
+
// killed it mid-run), so mark it `interrupted` for a neutral "no result"
|
|
1277
|
+
// state instead of a bogus green success tick.
|
|
1278
|
+
const allOpen = [];
|
|
1279
|
+
for (const idxs of Object.values(openCalls))
|
|
1280
|
+
allOpen.push(...idxs);
|
|
1281
|
+
allOpen.sort((a, b) => a - b);
|
|
1282
|
+
const lastOpenIdx = applyStreamingTail && allOpen.length > 0
|
|
1283
|
+
? allOpen[allOpen.length - 1]
|
|
1284
|
+
: -1;
|
|
1285
|
+
for (const idx of allOpen) {
|
|
1286
|
+
if (idx === lastOpenIdx) {
|
|
1287
|
+
mapped[idx] = { ...mapped[idx], isStreaming: true };
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
mapped[idx] = { ...mapped[idx], interrupted: true };
|
|
1135
1291
|
}
|
|
1136
1292
|
}
|
|
1137
1293
|
if (applyStreamingTail && mapped.length > 0) {
|
|
@@ -1466,6 +1622,7 @@ export class WhereverClient {
|
|
|
1466
1622
|
readOnly: false,
|
|
1467
1623
|
conflict: null,
|
|
1468
1624
|
sessionError: null,
|
|
1625
|
+
notice: null,
|
|
1469
1626
|
creatingSession: false,
|
|
1470
1627
|
resyncing: false,
|
|
1471
1628
|
agentPending: false,
|
|
@@ -1525,6 +1682,7 @@ export class WhereverClient {
|
|
|
1525
1682
|
activeCwd: null,
|
|
1526
1683
|
activeModel: null,
|
|
1527
1684
|
readOnly: false,
|
|
1685
|
+
notice: null,
|
|
1528
1686
|
creatingSession: false,
|
|
1529
1687
|
loadingSession: false,
|
|
1530
1688
|
resyncing: false,
|
|
@@ -1561,6 +1719,9 @@ export class WhereverClient {
|
|
|
1561
1719
|
dismissSessionError() {
|
|
1562
1720
|
this.stateStore.update((s) => ({ ...s, sessionError: null }));
|
|
1563
1721
|
}
|
|
1722
|
+
dismissNotice() {
|
|
1723
|
+
this.stateStore.update((s) => ({ ...s, notice: null }));
|
|
1724
|
+
}
|
|
1564
1725
|
changeModel(model) {
|
|
1565
1726
|
this.send({ type: 'model_change', model });
|
|
1566
1727
|
}
|