@parallelworks/code 0.4.0 → 0.6.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 +92 -24
- package/dist/agentSwitcher.d.ts +13 -2
- package/dist/agentSwitcher.js +28 -6
- package/dist/ago.d.ts +1 -3
- package/dist/ago.js +1 -3
- package/dist/api.d.ts +267 -5
- package/dist/chatStrings.d.ts +4 -0
- package/dist/chatStrings.js +5 -1
- package/dist/claudeAccounts.d.ts +20 -2
- package/dist/claudeAccounts.js +51 -7
- package/dist/claudeApi.d.ts +2 -1
- package/dist/claudeApi.js +49 -3
- package/dist/command.d.ts +7 -1
- package/dist/command.js +11 -2
- package/dist/commandsApi.d.ts +8 -3
- package/dist/commandsApi.js +25 -4
- package/dist/createPwCodeApi.d.ts +92 -58
- package/dist/createPwCodeApi.js +4 -2
- package/dist/index.d.ts +11 -9
- package/dist/index.js +7 -5
- package/dist/locales/en/agentTranscript.js +6 -2
- package/dist/locales/en/agents.js +50 -6
- package/dist/locales/en.d.ts +46 -0
- package/dist/locales/es/agentTranscript.js +6 -2
- package/dist/locales/es/agents.js +50 -6
- package/dist/locales/ja/agentTranscript.js +6 -2
- package/dist/locales/ja/agents.js +45 -6
- package/dist/locales/ko/agentTranscript.js +6 -2
- package/dist/locales/ko/agents.js +50 -6
- package/dist/locales/zh/agentTranscript.js +6 -2
- package/dist/locales/zh/agents.js +50 -6
- package/dist/machine.d.ts +27 -2
- package/dist/machine.js +23 -2
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +29 -14
- package/dist/pwUpdate.d.ts +52 -0
- package/dist/pwUpdate.js +115 -0
- package/dist/query.d.ts +4 -1
- package/dist/query.js +9 -3
- package/dist/session.d.ts +7 -1
- package/dist/session.js +6 -2
- package/dist/sessionActions.js +5 -2
- package/dist/sessionEvents.d.ts +39 -5
- package/dist/sessionEvents.js +213 -83
- package/dist/sessionGroups.d.ts +3 -3
- package/dist/sessionGroups.js +3 -3
- package/dist/sessionHeader.js +6 -2
- package/dist/sessionList.d.ts +13 -8
- package/dist/sessionList.js +20 -10
- package/dist/sessionScreen.d.ts +8 -3
- package/dist/sessionScreen.js +20 -9
- package/dist/sessionsApi.d.ts +27 -5
- package/dist/sessionsApi.js +128 -17
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/startPage.d.ts +6 -3
- package/dist/startPage.js +34 -12
- package/dist/startSession.d.ts +31 -11
- package/dist/startSession.js +126 -44
- package/dist/terminalHandoffPanel.js +8 -1
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +27 -5
- package/dist/transcript.js +148 -112
- package/dist/transcriptRead.d.ts +57 -0
- package/dist/transcriptRead.js +122 -0
- package/dist/types.d.ts +13 -1
- package/dist/useComposer.d.ts +36 -15
- package/dist/useComposer.js +94 -31
- package/dist/useComposerImages.d.ts +38 -1
- package/dist/useComposerImages.js +62 -8
- package/dist/useComposerPastes.js +3 -8
- package/dist/useConversation.d.ts +16 -0
- package/dist/useConversation.js +78 -8
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +22 -5
- package/dist/useSubagent.js +41 -17
- package/dist/useTranscript.d.ts +27 -1
- package/dist/useTranscript.js +217 -45
- package/dist/wording.d.ts +6 -3
- package/dist/wording.js +20 -6
- package/locales/en/agentTranscript.json +6 -2
- package/locales/en/agents.json +46 -4
- package/locales/es/agentTranscript.json +6 -2
- package/locales/es/agents.json +46 -4
- package/locales/ja/agentTranscript.json +6 -2
- package/locales/ja/agents.json +46 -4
- package/locales/ko/agentTranscript.json +6 -2
- package/locales/ko/agents.json +46 -4
- package/locales/zh/agentTranscript.json +6 -2
- package/locales/zh/agents.json +46 -4
- package/package.json +3 -3
package/dist/useConversation.js
CHANGED
|
@@ -6,23 +6,25 @@ import { useCompactionNotice, useRecapNotice, useTranscriptWords } from "./notic
|
|
|
6
6
|
import { isSession, sharedStoreCopy } from "./session.js";
|
|
7
7
|
import { changesSubagents } from "./sessionEvents.js";
|
|
8
8
|
import { pasteRefs, patchSessionNames } from "./sessionsApi.js";
|
|
9
|
-
import { pendingApprovals, pendingMessages } from "./transcript.js";
|
|
9
|
+
import { initialTranscript, pendingApprovals, pendingMessages } from "./transcript.js";
|
|
10
10
|
import { usePwCodeTranscript } from "./useTranscript.js";
|
|
11
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
11
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
12
12
|
// src/useConversation.ts
|
|
13
13
|
/** A transcript's messages as a view draws them: those it holds, then the one
|
|
14
14
|
* streaming, then those still waiting to be taken. */
|
|
15
15
|
function transcriptMessages(transcript) {
|
|
16
16
|
const messages = transcript?.messages ?? [];
|
|
17
17
|
const queued = transcript ? pendingMessages(transcript) : [];
|
|
18
|
+
const streaming = transcript?.streaming ?? null;
|
|
18
19
|
return {
|
|
19
20
|
messages,
|
|
20
21
|
queued,
|
|
21
22
|
all: transcript ? [
|
|
22
23
|
...messages,
|
|
23
|
-
...
|
|
24
|
+
...streaming ? [streaming] : [],
|
|
24
25
|
...queued
|
|
25
|
-
] : messages
|
|
26
|
+
] : messages,
|
|
27
|
+
streaming
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
30
|
/** A direction that got no answer may have landed, so it reads as lost, never as refused. */
|
|
@@ -55,6 +57,35 @@ function mainTurnAfter(ev) {
|
|
|
55
57
|
if (ev.type === "user_message" || ev.type === "turn_start") return true;
|
|
56
58
|
if (ev.turnId && (ev.type === "done" || ev.type === "error")) return false;
|
|
57
59
|
}
|
|
60
|
+
/** The end of a conversation, drawn while the rest of its transcript is still
|
|
61
|
+
* arriving: nothing is live until the whole of it has. It stays until the
|
|
62
|
+
* whole is drawn in its place, a render after it arrives. */
|
|
63
|
+
function useConversationEnd(transcript, preview, { goalNotice, ...notices }) {
|
|
64
|
+
const [held, setHeld] = useState(preview);
|
|
65
|
+
if (preview && preview !== held) setHeld(preview);
|
|
66
|
+
const end = transcript ? void 0 : preview ?? held;
|
|
67
|
+
const { compactionNotice, recapNotice, words, imageUrl } = notices;
|
|
68
|
+
return useMemo(() => {
|
|
69
|
+
if (!end) return null;
|
|
70
|
+
return transcriptMessages(initialTranscript({
|
|
71
|
+
...end,
|
|
72
|
+
approvals: []
|
|
73
|
+
}, {
|
|
74
|
+
...goalNotice ? { goalNotice } : {},
|
|
75
|
+
compactionNotice,
|
|
76
|
+
recapNotice,
|
|
77
|
+
words,
|
|
78
|
+
imageUrl
|
|
79
|
+
}));
|
|
80
|
+
}, [
|
|
81
|
+
end,
|
|
82
|
+
goalNotice,
|
|
83
|
+
compactionNotice,
|
|
84
|
+
recapNotice,
|
|
85
|
+
words,
|
|
86
|
+
imageUrl
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
58
89
|
/** An open session's conversation: its live transcript, sends routed to the
|
|
59
90
|
* machine, approvals, the notice above the composer, and its subagents. The
|
|
60
91
|
* host reads the listing and the session (`api.useSessions`,
|
|
@@ -63,7 +94,9 @@ function mainTurnAfter(ev) {
|
|
|
63
94
|
function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read, describeError, notify, onCleared, onMoved, goalNotice }) {
|
|
64
95
|
const t = usePwCodeTranslations("agents");
|
|
65
96
|
const { data: list, mutate: mutateSessions } = sessions;
|
|
66
|
-
const
|
|
97
|
+
const listNow = useRef(list);
|
|
98
|
+
listNow.current = list;
|
|
99
|
+
const { data: detail, mutate, preview } = read;
|
|
67
100
|
const session = list?.sessions?.find((s) => isSession(s, machine, sessionId)) ?? detail;
|
|
68
101
|
const moved = sharedStoreCopy(list, machine, sessionId);
|
|
69
102
|
const onMovedRef = useRef(onMoved);
|
|
@@ -104,7 +137,11 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
104
137
|
name: effect.state.name ?? "",
|
|
105
138
|
autoName: effect.state.autoName ?? ""
|
|
106
139
|
};
|
|
107
|
-
|
|
140
|
+
const renamed = patchSessionNames(listNow.current, machine, sessionId, names);
|
|
141
|
+
if (renamed !== listNow.current) {
|
|
142
|
+
listNow.current = renamed;
|
|
143
|
+
mutateSessions((current) => patchSessionNames(current, machine, sessionId, names), { revalidate: false });
|
|
144
|
+
}
|
|
108
145
|
break;
|
|
109
146
|
}
|
|
110
147
|
case "notice": setNotice({
|
|
@@ -180,7 +217,7 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
180
217
|
const recapNotice = useRecapNotice();
|
|
181
218
|
const words = useTranscriptWords();
|
|
182
219
|
const imageUrl = useCallback((ref) => sessionImageUrl(machine, sessionId, ref), [machine, sessionId]);
|
|
183
|
-
const { transcript, sending, onEvent: applyEvent, sendMessage: sendToTranscript, resolveApproval, noteShellRun, canRemoveQueued, removeQueued: removeFromTranscript, takeBackPending, cursor } = usePwCodeTranscript({
|
|
220
|
+
const { transcript, sending, onEvent: applyEvent, sendMessage: sendToTranscript, resolveApproval, noteShellRun, showCommand, canRemoveQueued, removeQueued: removeFromTranscript, takeBackPending, handedBack, handedBackShown, dropShownHandedBack, cursor } = usePwCodeTranscript({
|
|
184
221
|
sessionId,
|
|
185
222
|
detail,
|
|
186
223
|
send: postMessage,
|
|
@@ -263,6 +300,22 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
263
300
|
sessionId,
|
|
264
301
|
showError
|
|
265
302
|
]);
|
|
303
|
+
/** Resolves to whether the machine took the subagent off the list. */
|
|
304
|
+
const dismissSubagent = useCallback(async (id) => {
|
|
305
|
+
const refusal = await api.dismissSubagent(machine, sessionId, id);
|
|
306
|
+
if (refusal) {
|
|
307
|
+
showError(refusal);
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
refreshSubagents();
|
|
311
|
+
return true;
|
|
312
|
+
}, [
|
|
313
|
+
api,
|
|
314
|
+
machine,
|
|
315
|
+
sessionId,
|
|
316
|
+
showError,
|
|
317
|
+
refreshSubagents
|
|
318
|
+
]);
|
|
266
319
|
const goal = liveState ? liveState.goal : detail?.goal;
|
|
267
320
|
const addDirs = liveState ? liveState.addDirs : detail?.addDirs;
|
|
268
321
|
const allowedDirs = liveState ? liveState.allowedDirs : detail?.allowedDirs;
|
|
@@ -270,6 +323,13 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
270
323
|
const mainWaits = !!transcript && pendingApprovals(transcript).some((p) => !p.agent);
|
|
271
324
|
const mainRuns = mainTurn ?? !!detail?.turnId;
|
|
272
325
|
const mainState = mainWaits ? "approval" : mainRuns ? "running" : "idle";
|
|
326
|
+
const early = useConversationEnd(transcript, preview, {
|
|
327
|
+
goalNotice,
|
|
328
|
+
compactionNotice,
|
|
329
|
+
recapNotice,
|
|
330
|
+
words,
|
|
331
|
+
imageUrl
|
|
332
|
+
});
|
|
273
333
|
return {
|
|
274
334
|
/** The session as the listing has it, or as its fetch does until then. */
|
|
275
335
|
session,
|
|
@@ -281,7 +341,9 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
281
341
|
allowedDirs,
|
|
282
342
|
refetch: mutate,
|
|
283
343
|
transcript,
|
|
284
|
-
...transcriptMessages(transcript),
|
|
344
|
+
...early ?? transcriptMessages(transcript),
|
|
345
|
+
/** Only the end of the conversation is drawn: the rest of its transcript is still arriving. */
|
|
346
|
+
endOnly: early !== null,
|
|
285
347
|
sending,
|
|
286
348
|
/** Hands each frame of the session's feed to the transcript and the subagent views. */
|
|
287
349
|
onEvent,
|
|
@@ -297,10 +359,17 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
297
359
|
reached,
|
|
298
360
|
deliver,
|
|
299
361
|
noteShellRun,
|
|
362
|
+
showCommand,
|
|
300
363
|
canRemoveQueued,
|
|
301
364
|
removeQueued,
|
|
302
365
|
/** Takes back every message the machine still holds, with the first refusal. */
|
|
303
366
|
takeBackPending,
|
|
367
|
+
/** Messages a turn failed or stopped on before the model read them, which go back to the composer. */
|
|
368
|
+
handedBack,
|
|
369
|
+
/** A message waiting to come back is one a failed turn left drawn where it was sent. */
|
|
370
|
+
handedBackShown,
|
|
371
|
+
/** Lets go of what failed turns gave back, which stays in the transcript. */
|
|
372
|
+
dropShownHandedBack,
|
|
304
373
|
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
305
374
|
queueDelivery: (id) => steered.has(id) ? "nextStep" : "afterReply",
|
|
306
375
|
answerApproval,
|
|
@@ -308,6 +377,7 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
308
377
|
refreshSubagents,
|
|
309
378
|
stopSubagent,
|
|
310
379
|
stopAllSubagents,
|
|
380
|
+
dismissSubagent,
|
|
311
381
|
mainState
|
|
312
382
|
};
|
|
313
383
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
// src/useMounted.ts
|
|
3
|
+
/** Whether the caller is still mounted, for work that finishes after it may have gone. */
|
|
4
|
+
function useMounted() {
|
|
5
|
+
const mounted = useRef(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
mounted.current = true;
|
|
8
|
+
return () => {
|
|
9
|
+
mounted.current = false;
|
|
10
|
+
};
|
|
11
|
+
}, []);
|
|
12
|
+
return mounted;
|
|
13
|
+
}
|
|
14
|
+
export { useMounted };
|
package/dist/useSubagent.d.ts
CHANGED
|
@@ -3,12 +3,13 @@ import { type PwCodeSwitcherAgent } from './agentSwitcher.js';
|
|
|
3
3
|
import type { Schemas } from './apiClient.js';
|
|
4
4
|
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
5
5
|
import type { PwCodeSubagentUsage } from './types.js';
|
|
6
|
+
import { type PwCodeMessageImages } from './useComposerImages.js';
|
|
6
7
|
declare const nextStep: (_id: string) => 'nextStep' | 'afterReply';
|
|
7
8
|
/** One subagent's conversation in place of the main one: its transcript, kept
|
|
8
9
|
* current from the session's feed, and a composer that talks to it. Commands
|
|
9
10
|
* and `!` stay with the main conversation's composer. The host reads the
|
|
10
11
|
* subagent with `api.useSubagentDetail`. */
|
|
11
|
-
export declare function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, usage, subscribe, loadPalette, describeError, sessionLock, modelNames, onSent, }: {
|
|
12
|
+
export declare function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, usage, subscribe, loadPalette, describeError, sessionLock, modelNames, images, onSent, }: {
|
|
12
13
|
api: PwCodeApi;
|
|
13
14
|
machine: string;
|
|
14
15
|
sessionId: string;
|
|
@@ -36,16 +37,23 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
36
37
|
} | null;
|
|
37
38
|
/** Names the session gives its models, as its state frames carry them. */
|
|
38
39
|
modelNames?: Readonly<Record<string, string>> | undefined;
|
|
40
|
+
/** The images waiting to go with the next message, as `useComposerImages`
|
|
41
|
+
* holds them for this composer, numbered with the session's other
|
|
42
|
+
* composers through its `numbering`. */
|
|
43
|
+
images?: PwCodeMessageImages | undefined;
|
|
39
44
|
/** The subagent took a message, so the session's list of them reads differently. */
|
|
40
45
|
onSent: () => void;
|
|
41
46
|
}): {
|
|
42
47
|
messages: import("@parallelworks/ui/ai/headless").ChatMessage[];
|
|
43
48
|
queued: import("@parallelworks/ui/ai/headless").ChatMessage[];
|
|
44
49
|
all: import("@parallelworks/ui/ai/headless").ChatMessage[];
|
|
50
|
+
streaming: import("@parallelworks/ui/ai/headless").ChatMessage | null;
|
|
45
51
|
/** The subagent as its own view shows it; unset until it is listed or read. */
|
|
46
52
|
agent: PwCodeSwitcherAgent | undefined;
|
|
47
53
|
/** The composer's draft key, under its session's and apart from the main conversation's. */
|
|
48
54
|
draftKey: string;
|
|
55
|
+
/** The `id` its `promptHistory` takes, so ↑ in its composer recalls only what was sent to it. */
|
|
56
|
+
historyId: string;
|
|
49
57
|
/** The model it runs on; empty until it is read, or when it names none. */
|
|
50
58
|
model: string;
|
|
51
59
|
/** That model's name as the session gives it, or its id without the provider. */
|
|
@@ -63,11 +71,20 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
63
71
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
64
72
|
recall: {
|
|
65
73
|
available: boolean;
|
|
66
|
-
take: () => Promise<
|
|
67
|
-
|
|
68
|
-
pastes: MessagePaste[] | undefined;
|
|
69
|
-
}[]>;
|
|
74
|
+
take: () => Promise<Pick<import("./useTranscript.js").PwCodeTakenBack, "pastes" | "shown" | "text">[]>;
|
|
75
|
+
placed: (messages: readonly object[]) => void;
|
|
70
76
|
};
|
|
77
|
+
/** Grows as a turn gives back a message the model never read; the host
|
|
78
|
+
* takes it into its composer then, as `recall` does on ↑. */
|
|
79
|
+
handedBack: number;
|
|
80
|
+
/** A message waiting to come back is one a failed turn left drawn where
|
|
81
|
+
* it was sent: take back only into an empty composer
|
|
82
|
+
* (`recall({ ifEmpty: true })` on the session view's handle), and call
|
|
83
|
+
* `dropShownHandedBack` when nothing came back; the rest then comes back
|
|
84
|
+
* as `handedBack` drops. */
|
|
85
|
+
handedBackShown: boolean;
|
|
86
|
+
/** Lets go of what failed turns gave back, which stays in the transcript and in the composer's history. */
|
|
87
|
+
dropShownHandedBack: () => void;
|
|
71
88
|
showAuthor: boolean;
|
|
72
89
|
/** The subagent has yet to load for the first time. */
|
|
73
90
|
loading: boolean;
|
package/dist/useSubagent.js
CHANGED
|
@@ -6,10 +6,11 @@ import { usePwCodeTranslations } from "./messages.js";
|
|
|
6
6
|
import { useTranscriptWords } from "./notices.js";
|
|
7
7
|
import { pendingApprovals, subagentSessionDetail, turnRunning } from "./transcript.js";
|
|
8
8
|
import { directionOutcome, transcriptMessages, withdrawalOutcome } from "./useConversation.js";
|
|
9
|
-
import { usePwCodeTranscript } from "./useTranscript.js";
|
|
9
|
+
import { canTakeBack, usePwCodeTranscript } from "./useTranscript.js";
|
|
10
10
|
import { modelLabel } from "./models.js";
|
|
11
11
|
import { sessionDraftKey, workingActivity } from "./sessionScreen.js";
|
|
12
12
|
import { pasteRefs } from "./sessionsApi.js";
|
|
13
|
+
import { takeMessageImages, useTakeBackImages } from "./useComposerImages.js";
|
|
13
14
|
import { composerState } from "./wording.js";
|
|
14
15
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
15
16
|
// src/useSubagent.ts
|
|
@@ -18,7 +19,7 @@ var nextStep = (_id) => "nextStep";
|
|
|
18
19
|
* current from the session's feed, and a composer that talks to it. Commands
|
|
19
20
|
* and `!` stay with the main conversation's composer. The host reads the
|
|
20
21
|
* subagent with `api.useSubagentDetail`. */
|
|
21
|
-
function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, usage, subscribe, loadPalette, describeError, sessionLock, modelNames, onSent }) {
|
|
22
|
+
function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, usage, subscribe, loadPalette, describeError, sessionLock, modelNames, images, onSent }) {
|
|
22
23
|
const t = usePwCodeTranslations("agents");
|
|
23
24
|
const typeLabel = useAgentTypeLabel();
|
|
24
25
|
const { data, error, refresh } = subagent;
|
|
@@ -26,11 +27,12 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
26
27
|
const name = known ? typeLabel(known.agentType) : "";
|
|
27
28
|
const detail = useMemo(() => data ? subagentSessionDetail(data) : void 0, [data]);
|
|
28
29
|
const [notice, setNotice] = useState(null);
|
|
29
|
-
const postMessage = useCallback(async (text, sent) => {
|
|
30
|
+
const postMessage = useCallback(async (text, sent, images) => {
|
|
30
31
|
try {
|
|
31
32
|
const { data: accepted, error: refusal } = await api.messageSubagent(machine, sessionId, subId, {
|
|
32
33
|
text,
|
|
33
|
-
...pasteRefs(sent)
|
|
34
|
+
...pasteRefs(sent),
|
|
35
|
+
...images?.length ? { images } : {}
|
|
34
36
|
});
|
|
35
37
|
return refusal ? { error: describeError(refusal) } : { turnId: accepted?.turnId };
|
|
36
38
|
} catch (thrown) {
|
|
@@ -43,9 +45,10 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
43
45
|
sessionId,
|
|
44
46
|
subId
|
|
45
47
|
]);
|
|
46
|
-
const postDirection = useCallback((text, sent) => directionOutcome(() => api.steerSubagent(machine, sessionId, subId, {
|
|
48
|
+
const postDirection = useCallback((text, sent, images) => directionOutcome(() => api.steerSubagent(machine, sessionId, subId, {
|
|
47
49
|
text,
|
|
48
|
-
...pasteRefs(sent)
|
|
50
|
+
...pasteRefs(sent),
|
|
51
|
+
...images?.length ? { images } : {}
|
|
49
52
|
}), t("detail.steerUncertain"), describeError), [
|
|
50
53
|
api,
|
|
51
54
|
describeError,
|
|
@@ -67,7 +70,7 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
67
70
|
}, [refresh]);
|
|
68
71
|
const words = useTranscriptWords();
|
|
69
72
|
const imageUrl = useCallback((ref) => sessionImageUrl(machine, sessionId, ref), [machine, sessionId]);
|
|
70
|
-
const { transcript, sending, onEvent, sendMessage: sendToTranscript, resolveApproval, canRemoveQueued, removeQueued: removeFromTranscript, takeBackPending } = usePwCodeTranscript({
|
|
73
|
+
const { transcript, sending, onEvent, sendMessage: sendToTranscript, resolveApproval, canRemoveQueued, removeQueued: removeFromTranscript, takeBackPending, handedBack, handedBackShown, dropShownHandedBack } = usePwCodeTranscript({
|
|
71
74
|
subagent: subId,
|
|
72
75
|
detail,
|
|
73
76
|
send: postMessage,
|
|
@@ -82,20 +85,26 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
82
85
|
const refusal = await removeFromTranscript(id);
|
|
83
86
|
if (refusal) setNotice(refusal);
|
|
84
87
|
}, [removeFromTranscript]);
|
|
88
|
+
const takenBack = useTakeBackImages(images?.restore);
|
|
89
|
+
const backWithImages = takenBack.back;
|
|
85
90
|
const takeBack = useCallback(async () => {
|
|
86
91
|
const { taken, refusal } = await takeBackPending();
|
|
87
92
|
if (refusal) setNotice(refusal);
|
|
88
|
-
return taken
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}));
|
|
92
|
-
}, [takeBackPending]);
|
|
93
|
+
return backWithImages(taken);
|
|
94
|
+
}, [backWithImages, takeBackPending]);
|
|
95
|
+
const takeImages = images?.take;
|
|
93
96
|
const send = useCallback(async (typed, sent) => {
|
|
94
97
|
if (shellCommand(typed) !== null || typed.trimStart().startsWith("/") && slashAction(typed, await loadPalette().catch(() => null)).kind !== "message") {
|
|
95
98
|
setNotice(t("switcher.commandsOnMain"));
|
|
96
99
|
return false;
|
|
97
100
|
}
|
|
98
|
-
const
|
|
101
|
+
const { text, images: refs, previews, settle } = await takeMessageImages(typed, takeImages);
|
|
102
|
+
const refusal = await sendToTranscript(text, {
|
|
103
|
+
pastes: sent,
|
|
104
|
+
images: refs,
|
|
105
|
+
previews
|
|
106
|
+
});
|
|
107
|
+
settle(!refusal);
|
|
99
108
|
setNotice(refusal);
|
|
100
109
|
if (!refusal) onSent();
|
|
101
110
|
return !refusal;
|
|
@@ -103,7 +112,8 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
103
112
|
loadPalette,
|
|
104
113
|
onSent,
|
|
105
114
|
sendToTranscript,
|
|
106
|
-
t
|
|
115
|
+
t,
|
|
116
|
+
takeImages
|
|
107
117
|
]);
|
|
108
118
|
const [stopping, setStopping] = useState(false);
|
|
109
119
|
const stop = useCallback(async () => {
|
|
@@ -166,6 +176,8 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
166
176
|
agent,
|
|
167
177
|
/** The composer's draft key, under its session's and apart from the main conversation's. */
|
|
168
178
|
draftKey: `${sessionDraftKey(sessionId, void 0)}:${subId}`,
|
|
179
|
+
/** The `id` its `promptHistory` takes, so ↑ in its composer recalls only what was sent to it. */
|
|
180
|
+
historyId: `${sessionId}:${subId}`,
|
|
169
181
|
/** The model it runs on; empty until it is read, or when it names none. */
|
|
170
182
|
model,
|
|
171
183
|
/** That model's name as the session gives it, or its id without the provider. */
|
|
@@ -183,9 +195,21 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
183
195
|
removeQueued,
|
|
184
196
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
185
197
|
recall: {
|
|
186
|
-
available: messages.queued
|
|
187
|
-
take: takeBack
|
|
198
|
+
available: canTakeBack(handedBack, messages.queued, canRemoveQueued),
|
|
199
|
+
take: takeBack,
|
|
200
|
+
placed: takenBack.placed
|
|
188
201
|
},
|
|
202
|
+
/** Grows as a turn gives back a message the model never read; the host
|
|
203
|
+
* takes it into its composer then, as `recall` does on ↑. */
|
|
204
|
+
handedBack,
|
|
205
|
+
/** A message waiting to come back is one a failed turn left drawn where
|
|
206
|
+
* it was sent: take back only into an empty composer
|
|
207
|
+
* (`recall({ ifEmpty: true })` on the session view's handle), and call
|
|
208
|
+
* `dropShownHandedBack` when nothing came back; the rest then comes back
|
|
209
|
+
* as `handedBack` drops. */
|
|
210
|
+
handedBackShown,
|
|
211
|
+
/** Lets go of what failed turns gave back, which stays in the transcript and in the composer's history. */
|
|
212
|
+
dropShownHandedBack,
|
|
189
213
|
showAuthor: messages.all.some((m) => m.author),
|
|
190
214
|
/** The subagent has yet to load for the first time. */
|
|
191
215
|
loading: !data && !error,
|
|
@@ -205,7 +229,7 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, u
|
|
|
205
229
|
answerApproval,
|
|
206
230
|
composer: {
|
|
207
231
|
...composer,
|
|
208
|
-
disabled: sending || composer.locked || !data
|
|
232
|
+
disabled: sending || !!images?.taking || composer.locked || !data
|
|
209
233
|
}
|
|
210
234
|
};
|
|
211
235
|
}
|
package/dist/useTranscript.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ export interface PwCodeTakenBack {
|
|
|
26
26
|
pastes?: MessagePaste[] | undefined;
|
|
27
27
|
images?: PwCodeImageRef[] | undefined;
|
|
28
28
|
previews?: PwCodeImage[] | undefined;
|
|
29
|
+
/** Still drawn where it was sent, as a failed turn leaves it: a composer
|
|
30
|
+
* that filled meanwhile can let it go, as the terminal does. */
|
|
31
|
+
shown?: boolean | undefined;
|
|
29
32
|
}
|
|
30
33
|
interface SendOptions {
|
|
31
34
|
steer?: boolean;
|
|
@@ -36,6 +39,11 @@ interface SendOptions {
|
|
|
36
39
|
/** Drawn on the message until its echo brings the daemon's; a note can wait a whole tool call for that. */
|
|
37
40
|
previews?: PwCodeImage[] | undefined;
|
|
38
41
|
}
|
|
42
|
+
/** Whether a composer's ↑ has anything to take back: a message a turn gave
|
|
43
|
+
* back, or one still waiting that the machine would give up. */
|
|
44
|
+
export declare function canTakeBack(handedBack: number, queued: readonly {
|
|
45
|
+
id: string;
|
|
46
|
+
}[], canRemoveQueued: (id: string) => boolean): boolean;
|
|
39
47
|
/** Holds the live transcript for one session. The host still owns the socket
|
|
40
48
|
* and the fetch: it feeds events to `onEvent` and posts through `send`. */
|
|
41
49
|
export declare function usePwCodeTranscript({ sessionId, subagent, detail, send, steer, withdraw, withdrawDirection, onEffect, goalNotice, compactionNotice, recapNotice, words, imageUrl, }: {
|
|
@@ -66,17 +74,35 @@ export declare function usePwCodeTranscript({ sessionId, subagent, detail, send,
|
|
|
66
74
|
sendMessage: (text: string, options?: SendOptions) => Promise<string | null>;
|
|
67
75
|
resolveApproval: (approvalId: string) => void;
|
|
68
76
|
noteShellRun: (command: string, output: string) => void;
|
|
77
|
+
/** Shows a command as typed while the machine runs it, until the call it
|
|
78
|
+
* returns: then, `filed`, the record the machine filed of it takes its
|
|
79
|
+
* place at the next read; otherwise it goes at once. */
|
|
80
|
+
showCommand: (command: string) => (filed: boolean) => void;
|
|
69
81
|
/** Pending messages the daemon named a turn or note for can be taken back
|
|
70
82
|
* until they reach the model. */
|
|
71
83
|
canRemoveQueued: (id: string) => boolean;
|
|
72
84
|
/** Resolves to the refusal, or null once the message is gone. */
|
|
73
85
|
removeQueued: (id: string) => Promise<string | null>;
|
|
74
86
|
/** Takes back every pending message the machine still holds, with the first
|
|
75
|
-
* refusal; one the model read meanwhile stays sent.
|
|
87
|
+
* refusal; one the model read meanwhile stays sent. What a turn gave back
|
|
88
|
+
* comes first. */
|
|
76
89
|
takeBackPending: () => Promise<{
|
|
77
90
|
taken: PwCodeTakenBack[];
|
|
78
91
|
refusal: string | null;
|
|
79
92
|
}>;
|
|
93
|
+
/** Messages this window sent that a turn failed or stopped on before the
|
|
94
|
+
* model read them, so the conversation left them out: as the terminal
|
|
95
|
+
* does, they go back to the composer. `takeBackPending` returns them; the
|
|
96
|
+
* host takes them into its composer as this grows. */
|
|
97
|
+
handedBack: number;
|
|
98
|
+
/** A message waiting to come back is still drawn where it was sent, as a
|
|
99
|
+
* failed turn leaves it: as the terminal refills only an empty line, it
|
|
100
|
+
* goes back only into an empty composer. */
|
|
101
|
+
handedBackShown: boolean;
|
|
102
|
+
/** Lets go of the messages still drawn where they were sent, for a
|
|
103
|
+
* composer that held something: they stay in the transcript, and in its
|
|
104
|
+
* history. A take running meanwhile collects them instead. */
|
|
105
|
+
dropShownHandedBack: () => void;
|
|
80
106
|
/** Where a reconnect resumes from: the last seq applied, read outside render. */
|
|
81
107
|
cursor: () => number;
|
|
82
108
|
};
|