@parallelworks/code 0.5.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 +53 -12
- package/dist/api.d.ts +67 -5
- package/dist/chatStrings.d.ts +3 -0
- package/dist/chatStrings.js +4 -1
- package/dist/command.d.ts +2 -0
- package/dist/command.js +5 -1
- package/dist/commandsApi.d.ts +8 -3
- package/dist/commandsApi.js +25 -4
- package/dist/createPwCodeApi.d.ts +26 -61
- package/dist/index.d.ts +6 -5
- package/dist/index.js +3 -2
- package/dist/locales/en/agentTranscript.js +5 -2
- package/dist/locales/en/agents.js +35 -4
- package/dist/locales/en.d.ts +33 -0
- package/dist/locales/es/agentTranscript.js +5 -2
- package/dist/locales/es/agents.js +35 -4
- package/dist/locales/ja/agentTranscript.js +5 -2
- package/dist/locales/ja/agents.js +30 -4
- package/dist/locales/ko/agentTranscript.js +5 -2
- package/dist/locales/ko/agents.js +35 -4
- package/dist/locales/zh/agentTranscript.js +5 -2
- package/dist/locales/zh/agents.js +35 -4
- package/dist/machine.d.ts +27 -2
- package/dist/machine.js +23 -2
- package/dist/notices.js +9 -1
- package/dist/pwUpdate.d.ts +52 -0
- package/dist/pwUpdate.js +115 -0
- package/dist/session.d.ts +1 -1
- package/dist/session.js +1 -1
- package/dist/sessionActions.js +5 -2
- package/dist/sessionEvents.d.ts +10 -3
- package/dist/sessionEvents.js +27 -11
- package/dist/sessionScreen.d.ts +3 -2
- package/dist/sessionScreen.js +8 -2
- package/dist/sessionsApi.d.ts +8 -2
- package/dist/sessionsApi.js +28 -5
- 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/transcript.d.ts +26 -3
- package/dist/transcript.js +87 -12
- package/dist/transcriptRead.d.ts +1 -0
- package/dist/transcriptRead.js +2 -1
- package/dist/types.d.ts +13 -1
- package/dist/useComposer.d.ts +22 -10
- package/dist/useComposer.js +75 -25
- package/dist/useComposerImages.d.ts +38 -1
- package/dist/useComposerImages.js +59 -4
- package/dist/useConversation.d.ts +10 -0
- package/dist/useConversation.js +14 -11
- package/dist/useSubagent.d.ts +20 -5
- package/dist/useSubagent.js +39 -17
- package/dist/useTranscript.d.ts +27 -1
- package/dist/useTranscript.js +217 -45
- package/dist/wording.d.ts +1 -1
- package/dist/wording.js +14 -2
- package/locales/en/agentTranscript.json +5 -2
- package/locales/en/agents.json +32 -2
- package/locales/es/agentTranscript.json +5 -2
- package/locales/es/agents.json +32 -2
- package/locales/ja/agentTranscript.json +5 -2
- package/locales/ja/agents.json +32 -2
- package/locales/ko/agentTranscript.json +5 -2
- package/locales/ko/agents.json +32 -2
- package/locales/zh/agentTranscript.json +5 -2
- package/locales/zh/agents.json +32 -2
- package/package.json +3 -3
package/dist/useComposer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ChatMessage, MessagePaste } from '@parallelworks/ui/ai/headless';
|
|
|
2
2
|
import type { Schemas } from './apiClient.js';
|
|
3
3
|
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
4
4
|
import type { PwCodeConversation } from './useConversation.js';
|
|
5
|
-
import { type
|
|
5
|
+
import { type PwCodeMessageImages } from './useComposerImages.js';
|
|
6
6
|
/** The composer's history of sent prompts, as `@parallelworks/ui/ai`'s
|
|
7
7
|
* `ComposerHistory` takes it. */
|
|
8
8
|
export interface PwCodeComposerHistory {
|
|
@@ -29,6 +29,11 @@ export interface PwCodeCommandOutput {
|
|
|
29
29
|
command: string;
|
|
30
30
|
text: string;
|
|
31
31
|
}
|
|
32
|
+
/** A command running on the machine, which the activity line names until it settles. */
|
|
33
|
+
export interface PwCodeRunningCommand {
|
|
34
|
+
word: string;
|
|
35
|
+
startedAt: string;
|
|
36
|
+
}
|
|
32
37
|
export declare function useCommandOutputs(): {
|
|
33
38
|
outputs: PwCodeCommandOutput[];
|
|
34
39
|
add: (command: string, text: string) => void;
|
|
@@ -56,11 +61,7 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
|
|
|
56
61
|
/** How long ago the transcript was last read, already abbreviated: see `useLastReadAt`. */
|
|
57
62
|
staleFor: string;
|
|
58
63
|
/** The images waiting to go with the next message, as `useComposerImages` holds them. */
|
|
59
|
-
images?:
|
|
60
|
-
take: () => Promise<PwCodeTakenImages>;
|
|
61
|
-
restore: (saved: readonly PwCodeSavedImage[]) => void;
|
|
62
|
-
taking: boolean;
|
|
63
|
-
} | undefined;
|
|
64
|
+
images?: PwCodeMessageImages | undefined;
|
|
64
65
|
/** Typed text the host acts on itself, such as a command that opens one of
|
|
65
66
|
* its own panels; true takes it, sending nothing. */
|
|
66
67
|
handleLocally?: ((typed: string) => boolean) | undefined;
|
|
@@ -87,11 +88,20 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
|
|
|
87
88
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
88
89
|
recall: {
|
|
89
90
|
available: boolean;
|
|
90
|
-
take: () => Promise<
|
|
91
|
-
|
|
92
|
-
pastes: MessagePaste[] | undefined;
|
|
93
|
-
}[]>;
|
|
91
|
+
take: () => Promise<Pick<import("./useTranscript.js").PwCodeTakenBack, "pastes" | "shown" | "text">[]>;
|
|
92
|
+
placed: (messages: readonly object[]) => void;
|
|
94
93
|
};
|
|
94
|
+
/** Grows as a turn gives back a message the model never read; the host
|
|
95
|
+
* takes it into its composer then, as `recall` does on ↑. */
|
|
96
|
+
handedBack: number;
|
|
97
|
+
/** A message waiting to come back is one a failed turn left drawn where
|
|
98
|
+
* it was sent: take back only into an empty composer
|
|
99
|
+
* (`recall({ ifEmpty: true })` on the session view's handle), and call
|
|
100
|
+
* `dropShownHandedBack` when nothing came back; the rest then comes back
|
|
101
|
+
* as `handedBack` drops. */
|
|
102
|
+
handedBackShown: boolean;
|
|
103
|
+
/** Lets go of what failed turns gave back, which stays in the transcript and in the composer's history. */
|
|
104
|
+
dropShownHandedBack: () => void;
|
|
95
105
|
/** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
|
|
96
106
|
sessionLock: {
|
|
97
107
|
placeholder: string;
|
|
@@ -99,6 +109,8 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
|
|
|
99
109
|
locked: boolean;
|
|
100
110
|
} | null;
|
|
101
111
|
shellRun: string | null;
|
|
112
|
+
/** The commands the activity line can name, oldest first. */
|
|
113
|
+
runningCommands: PwCodeRunningCommand[];
|
|
102
114
|
outputs: PwCodeCommandOutput[];
|
|
103
115
|
dismissOutput: (id: number) => void;
|
|
104
116
|
palette: {
|
package/dist/useComposer.js
CHANGED
|
@@ -2,15 +2,18 @@ import { shellCommand } from "./command.js";
|
|
|
2
2
|
import { isMachineDown } from "./machine.js";
|
|
3
3
|
import { usePwCodeTranslations } from "./messages.js";
|
|
4
4
|
import { bashRunning, liveSessionStatus, pendingApprovals, turnRunning } from "./transcript.js";
|
|
5
|
-
import {
|
|
5
|
+
import { canTakeBack } from "./useTranscript.js";
|
|
6
|
+
import { takeMessageImages, useTakeBackImages } from "./useComposerImages.js";
|
|
6
7
|
import { useMounted } from "./useMounted.js";
|
|
7
8
|
import { composerState, sessionLabel } from "./wording.js";
|
|
8
9
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
10
|
+
import { DateTime } from "luxon";
|
|
9
11
|
// src/useComposer.ts
|
|
12
|
+
var RECORDED_COMMAND = /^\/(?:compact|goal|plan)(?:\s|$)/;
|
|
10
13
|
/** What the reader typed into a conversation, oldest first: not the recorded
|
|
11
14
|
* commands and `!` runs, nor what the main session told a subagent. */
|
|
12
15
|
function typedPrompts(messages) {
|
|
13
|
-
return messages.flatMap((m) => m.role === "user" && m.content && !m.pseudo && !m.commandAnswer && !m.author ? [m.content] : []);
|
|
16
|
+
return messages.flatMap((m) => m.role === "user" && m.content && !m.pseudo && !(m.commandAnswer && RECORDED_COMMAND.test(m.content)) && !m.author ? [m.content] : []);
|
|
14
17
|
}
|
|
15
18
|
/** Per person, since someone else can sign in where the history is kept, and
|
|
16
19
|
* per conversation, such as a session or one of its subagents, so ↑ in one
|
|
@@ -22,6 +25,14 @@ function promptHistory(username, conversation) {
|
|
|
22
25
|
skip: (text) => /^\/auth(\s|$)/.test(text)
|
|
23
26
|
};
|
|
24
27
|
}
|
|
28
|
+
/** What the activity line says while a command runs on the machine; the
|
|
29
|
+
* commands it says nothing for settle too soon to show. */
|
|
30
|
+
function runningWord(kind, t) {
|
|
31
|
+
switch (kind) {
|
|
32
|
+
case "compact": return t("detail.compacting");
|
|
33
|
+
default: return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
25
36
|
/** Typed text steers a running turn; what a command resolved to runs as a turn of its own, and comes back as typed. */
|
|
26
37
|
function resolvedDelivery(text, typed) {
|
|
27
38
|
return text === typed ? { steer: true } : {
|
|
@@ -54,8 +65,14 @@ function useCommandOutputs() {
|
|
|
54
65
|
* elsewhere, or it waits on an approval. */
|
|
55
66
|
function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo, feed, staleFor, images, handleLocally, notify, onCleared, onArchived }) {
|
|
56
67
|
const t = usePwCodeTranslations("agents");
|
|
57
|
-
const { session, detail, transcript, goal, sending, refetch, warn, showError, reached, deliver, noteShellRun, queued, canRemoveQueued, takeBackPending } = conversation;
|
|
68
|
+
const { session, detail, transcript, goal, sending, refetch, warn, showError, reached, deliver, noteShellRun, showCommand, subscribe, queued, canRemoveQueued, takeBackPending, handedBack, handedBackShown, dropShownHandedBack } = conversation;
|
|
58
69
|
const [shellRun, setShellRun] = useState(null);
|
|
70
|
+
const [runningCommands, setRunningCommands] = useState([]);
|
|
71
|
+
const commandsInFlight = useRef(0);
|
|
72
|
+
const awaitingStart = useRef(/* @__PURE__ */ new Map());
|
|
73
|
+
useEffect(() => subscribe((ev) => {
|
|
74
|
+
if (ev.type === "command_started" && ev.client) awaitingStart.current.get(ev.client)?.();
|
|
75
|
+
}), [subscribe]);
|
|
59
76
|
const delivering = useRef(null);
|
|
60
77
|
const { palette, loading: paletteLoading, load: loadPalette } = api.usePalette(machine, sessionId);
|
|
61
78
|
const openPalette = useCallback(() => void loadPalette().catch(() => {}), [loadPalette]);
|
|
@@ -116,6 +133,35 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
116
133
|
onOutput: commandOutputs.add,
|
|
117
134
|
onShellRun,
|
|
118
135
|
onCompacted: () => void refetch(),
|
|
136
|
+
onRunning: (command, kind, requestId) => {
|
|
137
|
+
const word = runningWord(kind, t);
|
|
138
|
+
if (!word) return;
|
|
139
|
+
const started = () => {
|
|
140
|
+
const shown = {
|
|
141
|
+
word,
|
|
142
|
+
startedAt: DateTime.now().toISO()
|
|
143
|
+
};
|
|
144
|
+
const hide = showCommand(command);
|
|
145
|
+
setRunningCommands((current) => [...current, shown]);
|
|
146
|
+
return (filed) => {
|
|
147
|
+
hide(filed);
|
|
148
|
+
setRunningCommands((current) => current.filter((c) => c !== shown));
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const waits = running || commandsInFlight.current > 0;
|
|
152
|
+
commandsInFlight.current += 1;
|
|
153
|
+
let end;
|
|
154
|
+
if (waits) awaitingStart.current.set(requestId, () => {
|
|
155
|
+
awaitingStart.current.delete(requestId);
|
|
156
|
+
end = started();
|
|
157
|
+
});
|
|
158
|
+
else end = started();
|
|
159
|
+
return (filed) => {
|
|
160
|
+
commandsInFlight.current -= 1;
|
|
161
|
+
awaitingStart.current.delete(requestId);
|
|
162
|
+
end?.(filed);
|
|
163
|
+
};
|
|
164
|
+
},
|
|
119
165
|
onCleared: (newId) => {
|
|
120
166
|
if (mounted.current) onCleared(newId);
|
|
121
167
|
},
|
|
@@ -136,17 +182,12 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
136
182
|
}).finally(() => setShellRun(null));
|
|
137
183
|
if (text === null) return !refused;
|
|
138
184
|
commandOutputs.clear();
|
|
139
|
-
const {
|
|
140
|
-
saved: [],
|
|
141
|
-
settle: () => {}
|
|
142
|
-
};
|
|
143
|
-
const refs = saved.map((i) => i.ref);
|
|
144
|
-
const message = [text, ...refs.map((i) => i.placeholder).filter((p) => !text.includes(p))].filter(Boolean).join(" ");
|
|
185
|
+
const { text: message, images: refs, previews, settle } = await takeMessageImages(text, takeImages);
|
|
145
186
|
const delivery = deliver(message, {
|
|
146
187
|
...resolvedDelivery(text, typed),
|
|
147
188
|
pastes,
|
|
148
189
|
images: refs,
|
|
149
|
-
previews
|
|
190
|
+
previews
|
|
150
191
|
});
|
|
151
192
|
delivering.current = delivery;
|
|
152
193
|
const refusal = await delivery;
|
|
@@ -173,6 +214,7 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
173
214
|
running,
|
|
174
215
|
session,
|
|
175
216
|
sessionId,
|
|
217
|
+
showCommand,
|
|
176
218
|
showError,
|
|
177
219
|
t,
|
|
178
220
|
takeImages,
|
|
@@ -191,27 +233,21 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
191
233
|
session,
|
|
192
234
|
stopSession
|
|
193
235
|
]);
|
|
194
|
-
const
|
|
236
|
+
const takenBack = useTakeBackImages(images?.restore);
|
|
237
|
+
const backWithImages = takenBack.back;
|
|
195
238
|
/** Takes back what waits into the composer, as ↑ does in the terminal; one the model read meanwhile stays sent. */
|
|
196
239
|
const takeBack = useCallback(async () => {
|
|
197
240
|
const { taken, refusal } = await takeBackPending();
|
|
198
241
|
if (refusal) warn(refusal);
|
|
199
|
-
|
|
200
|
-
const preview = previews[i];
|
|
201
|
-
return preview ? [{
|
|
202
|
-
ref,
|
|
203
|
-
preview
|
|
204
|
-
}] : [];
|
|
205
|
-
})));
|
|
206
|
-
return taken.map((m) => ({
|
|
207
|
-
text: withoutAppendedImages(m.text, m.images),
|
|
208
|
-
pastes: m.pastes
|
|
209
|
-
}));
|
|
242
|
+
return backWithImages(taken);
|
|
210
243
|
}, [
|
|
211
|
-
|
|
244
|
+
backWithImages,
|
|
212
245
|
takeBackPending,
|
|
213
246
|
warn
|
|
214
247
|
]);
|
|
248
|
+
/** The composer's word on which taken messages went into its box: those
|
|
249
|
+
* still drawn where they were sent get their images back only now. */
|
|
250
|
+
const placed = takenBack.placed;
|
|
215
251
|
const status = detail ? liveSessionStatus(detail.status, transcript, goal) : null;
|
|
216
252
|
const approvals = transcript ? pendingApprovals(transcript).map((p) => ({ kind: p.approvalKind })) : detail?.approvals;
|
|
217
253
|
const unreachable = isMachineDown(machineInfo) && !feed.connected;
|
|
@@ -258,12 +294,26 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
258
294
|
},
|
|
259
295
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
260
296
|
recall: {
|
|
261
|
-
available:
|
|
262
|
-
take: takeBack
|
|
297
|
+
available: canTakeBack(handedBack, queued, canRemoveQueued),
|
|
298
|
+
take: takeBack,
|
|
299
|
+
placed
|
|
263
300
|
},
|
|
301
|
+
/** Grows as a turn gives back a message the model never read; the host
|
|
302
|
+
* takes it into its composer then, as `recall` does on ↑. */
|
|
303
|
+
handedBack,
|
|
304
|
+
/** A message waiting to come back is one a failed turn left drawn where
|
|
305
|
+
* it was sent: take back only into an empty composer
|
|
306
|
+
* (`recall({ ifEmpty: true })` on the session view's handle), and call
|
|
307
|
+
* `dropShownHandedBack` when nothing came back; the rest then comes back
|
|
308
|
+
* as `handedBack` drops. */
|
|
309
|
+
handedBackShown,
|
|
310
|
+
/** Lets go of what failed turns gave back, which stays in the transcript and in the composer's history. */
|
|
311
|
+
dropShownHandedBack,
|
|
264
312
|
/** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
|
|
265
313
|
sessionLock: unreachable || archived || liveElsewhere ? state : null,
|
|
266
314
|
shellRun,
|
|
315
|
+
/** The commands the activity line can name, oldest first. */
|
|
316
|
+
runningCommands,
|
|
267
317
|
outputs: commandOutputs.outputs,
|
|
268
318
|
dismissOutput: commandOutputs.dismiss,
|
|
269
319
|
palette,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
2
2
|
import type { PwCodeImage, PwCodeImageRef } from './types.js';
|
|
3
|
+
import type { PwCodeTakenBack } from './useTranscript.js';
|
|
3
4
|
export type PwCodeImageType = PwCodeImageRef['mime'];
|
|
4
5
|
export declare const IMAGE_TYPES: readonly PwCodeImageType[];
|
|
5
6
|
export declare const IMAGE_MAX_BYTES: number;
|
|
@@ -31,11 +32,41 @@ export interface PwCodeTakenImages {
|
|
|
31
32
|
}
|
|
32
33
|
/** Numbers past every placeholder the texts name, as the terminal does. */
|
|
33
34
|
export declare function nextImageSeq(texts: Iterable<string | null | undefined> | undefined, after: number): number;
|
|
35
|
+
/** The text, then each image's placeholder it does not name already, so the
|
|
36
|
+
* model is told about every image sent. */
|
|
37
|
+
export declare function withImagePlaceholders(text: string, images: readonly PwCodeImageRef[]): string;
|
|
34
38
|
/** The send appends the placeholders of images its text left out; a message
|
|
35
39
|
* taken back gives them back as images, so they leave its text. */
|
|
36
40
|
export declare function withoutAppendedImages(text: string, images: readonly PwCodeImageRef[] | undefined): string;
|
|
41
|
+
/** The images messages taken back were sent with, each with its preview, to put back in the composer. */
|
|
42
|
+
export declare function takenBackImages(taken: readonly {
|
|
43
|
+
images?: readonly PwCodeImageRef[] | undefined;
|
|
44
|
+
previews?: readonly PwCodeImage[] | undefined;
|
|
45
|
+
}[]): PwCodeSavedImage[];
|
|
46
|
+
/** The part of `useComposerImages` a composer's send and take-back use. */
|
|
47
|
+
export interface PwCodeMessageImages {
|
|
48
|
+
take: () => Promise<PwCodeTakenImages>;
|
|
49
|
+
restore: (saved: readonly PwCodeSavedImage[]) => void;
|
|
50
|
+
taking: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** Takes the images waiting for a message, and its text naming each. */
|
|
53
|
+
export declare function takeMessageImages(text: string, take: PwCodeMessageImages['take'] | undefined): Promise<{
|
|
54
|
+
text: string;
|
|
55
|
+
images: PwCodeImageRef[];
|
|
56
|
+
previews: PwCodeImage[];
|
|
57
|
+
settle: (sent: boolean) => void;
|
|
58
|
+
}>;
|
|
59
|
+
/** A composer's take-back with images: each message's text loses the
|
|
60
|
+
* placeholders its send appended, and its images go back in the composer,
|
|
61
|
+
* except those of a message still drawn where it was sent, which wait until
|
|
62
|
+
* the composer says it placed that message (`placed`), since it can let the
|
|
63
|
+
* message go for what was typed meanwhile. */
|
|
64
|
+
export declare function useTakeBackImages(restore: PwCodeMessageImages['restore'] | undefined): {
|
|
65
|
+
back: (taken: readonly PwCodeTakenBack[]) => Pick<PwCodeTakenBack, 'text' | 'pastes' | 'shown'>[];
|
|
66
|
+
placed: (messages: readonly object[]) => void;
|
|
67
|
+
};
|
|
37
68
|
/** Images stay with the reader until there is a session to save them with. */
|
|
38
|
-
export declare function useComposerImages<F extends PwCodeImageFile>({ api, machine, sessionId, messages, onError, describeError, encode, preview, release, }: {
|
|
69
|
+
export declare function useComposerImages<F extends PwCodeImageFile>({ api, machine, sessionId, messages, numbering, onError, describeError, encode, preview, release, }: {
|
|
39
70
|
api: Pick<PwCodeApi, 'saveImage'>;
|
|
40
71
|
machine?: string | undefined;
|
|
41
72
|
sessionId?: string | undefined;
|
|
@@ -43,6 +74,12 @@ export declare function useComposerImages<F extends PwCodeImageFile>({ api, mach
|
|
|
43
74
|
messages: readonly {
|
|
44
75
|
content?: string | null | undefined;
|
|
45
76
|
}[] | undefined;
|
|
77
|
+
/** The last number given, shared by every composer on one session: each
|
|
78
|
+
* image is saved as its number, so two composers giving the same one would
|
|
79
|
+
* overwrite an image the other has yet to send. */
|
|
80
|
+
numbering?: {
|
|
81
|
+
current: number;
|
|
82
|
+
} | undefined;
|
|
46
83
|
onError: (text: string) => void;
|
|
47
84
|
/** Words a refusal or failure for the reader. */
|
|
48
85
|
describeError: (error: unknown) => string;
|
|
@@ -24,6 +24,11 @@ function nextImageSeq(texts, after) {
|
|
|
24
24
|
}
|
|
25
25
|
return seq + 1;
|
|
26
26
|
}
|
|
27
|
+
/** The text, then each image's placeholder it does not name already, so the
|
|
28
|
+
* model is told about every image sent. */
|
|
29
|
+
function withImagePlaceholders(text, images) {
|
|
30
|
+
return [text, ...images.map((image) => image.placeholder).filter((placeholder) => !text.includes(placeholder))].filter(Boolean).join(" ");
|
|
31
|
+
}
|
|
27
32
|
/** The send appends the placeholders of images its text left out; a message
|
|
28
33
|
* taken back gives them back as images, so they leave its text. */
|
|
29
34
|
function withoutAppendedImages(text, images) {
|
|
@@ -32,8 +37,56 @@ function withoutAppendedImages(text, images) {
|
|
|
32
37
|
else if (rest.endsWith(` ${placeholder}`)) rest = rest.slice(0, -placeholder.length - 1);
|
|
33
38
|
return rest;
|
|
34
39
|
}
|
|
40
|
+
/** The images messages taken back were sent with, each with its preview, to put back in the composer. */
|
|
41
|
+
function takenBackImages(taken) {
|
|
42
|
+
return taken.flatMap(({ images = [], previews = [] }) => images.flatMap((ref, i) => {
|
|
43
|
+
const preview = previews[i];
|
|
44
|
+
return preview ? [{
|
|
45
|
+
ref,
|
|
46
|
+
preview
|
|
47
|
+
}] : [];
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/** Takes the images waiting for a message, and its text naming each. */
|
|
51
|
+
async function takeMessageImages(text, take) {
|
|
52
|
+
const { saved, settle } = take ? await take() : {
|
|
53
|
+
saved: [],
|
|
54
|
+
settle: () => {}
|
|
55
|
+
};
|
|
56
|
+
const images = saved.map((i) => i.ref);
|
|
57
|
+
return {
|
|
58
|
+
text: withImagePlaceholders(text, images),
|
|
59
|
+
images,
|
|
60
|
+
previews: saved.map((i) => i.preview),
|
|
61
|
+
settle
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** A composer's take-back with images: each message's text loses the
|
|
65
|
+
* placeholders its send appended, and its images go back in the composer,
|
|
66
|
+
* except those of a message still drawn where it was sent, which wait until
|
|
67
|
+
* the composer says it placed that message (`placed`), since it can let the
|
|
68
|
+
* message go for what was typed meanwhile. */
|
|
69
|
+
function useTakeBackImages(restore) {
|
|
70
|
+
const held = useRef(/* @__PURE__ */ new WeakMap());
|
|
71
|
+
return {
|
|
72
|
+
back: useCallback((taken) => {
|
|
73
|
+
const messages = taken.map((m) => {
|
|
74
|
+
const message = {
|
|
75
|
+
text: withoutAppendedImages(m.text, m.images),
|
|
76
|
+
pastes: m.pastes,
|
|
77
|
+
shown: m.shown
|
|
78
|
+
};
|
|
79
|
+
if (m.shown) held.current.set(message, takenBackImages([m]));
|
|
80
|
+
return message;
|
|
81
|
+
});
|
|
82
|
+
restore?.(takenBackImages(taken.filter((m) => !m.shown)));
|
|
83
|
+
return messages;
|
|
84
|
+
}, [restore]),
|
|
85
|
+
placed: useCallback((messages) => restore?.(messages.flatMap((m) => held.current.get(m) ?? [])), [restore])
|
|
86
|
+
};
|
|
87
|
+
}
|
|
35
88
|
/** Images stay with the reader until there is a session to save them with. */
|
|
36
|
-
function useComposerImages({ api, machine, sessionId, messages, onError, describeError, encode, preview, release }) {
|
|
89
|
+
function useComposerImages({ api, machine, sessionId, messages, numbering, onError, describeError, encode, preview, release }) {
|
|
37
90
|
const t = usePwCodeTranslations("agents");
|
|
38
91
|
const [images, setImages] = useState([]);
|
|
39
92
|
const [taking, setTaking] = useState(false);
|
|
@@ -55,7 +108,8 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
55
108
|
preview,
|
|
56
109
|
release
|
|
57
110
|
};
|
|
58
|
-
const
|
|
111
|
+
const ownSeq = useRef(0);
|
|
112
|
+
const lastSeq = numbering ?? ownSeq;
|
|
59
113
|
const uploads = useRef(/* @__PURE__ */ new Map());
|
|
60
114
|
const staged = useRef(/* @__PURE__ */ new Map());
|
|
61
115
|
const releasePreview = useCallback((url) => {
|
|
@@ -137,6 +191,7 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
137
191
|
}
|
|
138
192
|
}, [
|
|
139
193
|
discard,
|
|
194
|
+
lastSeq,
|
|
140
195
|
machine,
|
|
141
196
|
onError,
|
|
142
197
|
reportError,
|
|
@@ -210,8 +265,8 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
210
265
|
};
|
|
211
266
|
});
|
|
212
267
|
setImages((current) => [...restored, ...current]);
|
|
213
|
-
}, []),
|
|
268
|
+
}, [lastSeq]),
|
|
214
269
|
saveTo
|
|
215
270
|
};
|
|
216
271
|
}
|
|
217
|
-
export { IMAGE_MAX_BYTES, IMAGE_MAX_SIDE, IMAGE_READ_MAX_BYTES, IMAGE_TYPES, PwCodeImageTooLarge, nextImageSeq, useComposerImages, withoutAppendedImages };
|
|
272
|
+
export { IMAGE_MAX_BYTES, IMAGE_MAX_SIDE, IMAGE_READ_MAX_BYTES, IMAGE_TYPES, PwCodeImageTooLarge, nextImageSeq, takeMessageImages, takenBackImages, useComposerImages, useTakeBackImages, withImagePlaceholders, withoutAppendedImages };
|
|
@@ -24,6 +24,7 @@ export declare function transcriptMessages(transcript: TranscriptState | null):
|
|
|
24
24
|
messages: ChatMessage[];
|
|
25
25
|
queued: ChatMessage[];
|
|
26
26
|
all: ChatMessage[];
|
|
27
|
+
streaming: ChatMessage | null;
|
|
27
28
|
};
|
|
28
29
|
/** A direction that got no answer may have landed, so it reads as lost, never as refused. */
|
|
29
30
|
export declare function directionOutcome(request: () => Promise<PwCodeResult<Schemas['AgentDirectionDelivered']>>, lost: string, describeError: (error: unknown) => string): Promise<PwCodeSteerResult>;
|
|
@@ -62,6 +63,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
62
63
|
messages: ChatMessage[];
|
|
63
64
|
queued: ChatMessage[];
|
|
64
65
|
all: ChatMessage[];
|
|
66
|
+
streaming: ChatMessage | null;
|
|
65
67
|
/** The session as the listing has it, or as its fetch does until then. */
|
|
66
68
|
session: {
|
|
67
69
|
allocation?: string;
|
|
@@ -110,6 +112,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
110
112
|
goal?: import("./api.js").components["schemas"]["GoalStatus"];
|
|
111
113
|
group?: string;
|
|
112
114
|
history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
|
|
115
|
+
historyStart?: number;
|
|
113
116
|
id: string;
|
|
114
117
|
inputTokens?: number;
|
|
115
118
|
lastError?: string;
|
|
@@ -171,6 +174,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
171
174
|
unreachable: boolean;
|
|
172
175
|
} | null>;
|
|
173
176
|
noteShellRun: (command: string, output: string) => void;
|
|
177
|
+
showCommand: (command: string) => (filed: boolean) => void;
|
|
174
178
|
canRemoveQueued: (id: string) => boolean;
|
|
175
179
|
removeQueued: (id: string) => Promise<void>;
|
|
176
180
|
/** Takes back every message the machine still holds, with the first refusal. */
|
|
@@ -178,6 +182,12 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
178
182
|
taken: import("./useTranscript.js").PwCodeTakenBack[];
|
|
179
183
|
refusal: string | null;
|
|
180
184
|
}>;
|
|
185
|
+
/** Messages a turn failed or stopped on before the model read them, which go back to the composer. */
|
|
186
|
+
handedBack: number;
|
|
187
|
+
/** A message waiting to come back is one a failed turn left drawn where it was sent. */
|
|
188
|
+
handedBackShown: boolean;
|
|
189
|
+
/** Lets go of what failed turns gave back, which stays in the transcript. */
|
|
190
|
+
dropShownHandedBack: () => void;
|
|
181
191
|
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
182
192
|
queueDelivery: (id: string) => 'nextStep' | 'afterReply';
|
|
183
193
|
answerApproval: (approvalId: string, answer: ApprovalAnswerValue) => Promise<void>;
|
package/dist/useConversation.js
CHANGED
|
@@ -15,14 +15,16 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
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. */
|
|
@@ -65,7 +67,7 @@ function useConversationEnd(transcript, preview, { goalNotice, ...notices }) {
|
|
|
65
67
|
const { compactionNotice, recapNotice, words, imageUrl } = notices;
|
|
66
68
|
return useMemo(() => {
|
|
67
69
|
if (!end) return null;
|
|
68
|
-
|
|
70
|
+
return transcriptMessages(initialTranscript({
|
|
69
71
|
...end,
|
|
70
72
|
approvals: []
|
|
71
73
|
}, {
|
|
@@ -74,13 +76,7 @@ function useConversationEnd(transcript, preview, { goalNotice, ...notices }) {
|
|
|
74
76
|
recapNotice,
|
|
75
77
|
words,
|
|
76
78
|
imageUrl
|
|
77
|
-
});
|
|
78
|
-
const messages = state.streaming ? [...state.messages, state.streaming] : state.messages;
|
|
79
|
-
return {
|
|
80
|
-
messages,
|
|
81
|
-
queued: [],
|
|
82
|
-
all: messages
|
|
83
|
-
};
|
|
79
|
+
}));
|
|
84
80
|
}, [
|
|
85
81
|
end,
|
|
86
82
|
goalNotice,
|
|
@@ -221,7 +217,7 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
221
217
|
const recapNotice = useRecapNotice();
|
|
222
218
|
const words = useTranscriptWords();
|
|
223
219
|
const imageUrl = useCallback((ref) => sessionImageUrl(machine, sessionId, ref), [machine, sessionId]);
|
|
224
|
-
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({
|
|
225
221
|
sessionId,
|
|
226
222
|
detail,
|
|
227
223
|
send: postMessage,
|
|
@@ -363,10 +359,17 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
363
359
|
reached,
|
|
364
360
|
deliver,
|
|
365
361
|
noteShellRun,
|
|
362
|
+
showCommand,
|
|
366
363
|
canRemoveQueued,
|
|
367
364
|
removeQueued,
|
|
368
365
|
/** Takes back every message the machine still holds, with the first refusal. */
|
|
369
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,
|
|
370
373
|
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
371
374
|
queueDelivery: (id) => steered.has(id) ? "nextStep" : "afterReply",
|
|
372
375
|
answerApproval,
|
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,12 +37,17 @@ 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. */
|
|
@@ -65,11 +71,20 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
65
71
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
66
72
|
recall: {
|
|
67
73
|
available: boolean;
|
|
68
|
-
take: () => Promise<
|
|
69
|
-
|
|
70
|
-
pastes: MessagePaste[] | undefined;
|
|
71
|
-
}[]>;
|
|
74
|
+
take: () => Promise<Pick<import("./useTranscript.js").PwCodeTakenBack, "pastes" | "shown" | "text">[]>;
|
|
75
|
+
placed: (messages: readonly object[]) => void;
|
|
72
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;
|
|
73
88
|
showAuthor: boolean;
|
|
74
89
|
/** The subagent has yet to load for the first time. */
|
|
75
90
|
loading: boolean;
|