@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/types.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface PwCodeToolDecision {
|
|
|
21
21
|
at: string;
|
|
22
22
|
answers?: PwCodeAskAnswer[] | null;
|
|
23
23
|
}
|
|
24
|
-
/** One question's answer: the options picked, the user's own words, and their notes on a question
|
|
24
|
+
/** One question's answer: the options picked, the user's own words, and their notes on a single-select question. */
|
|
25
25
|
export interface PwCodeAskAnswer {
|
|
26
26
|
question?: string;
|
|
27
27
|
picked?: string[] | null;
|
|
@@ -45,6 +45,12 @@ export interface PwCodeHistoryItem {
|
|
|
45
45
|
startLine?: number;
|
|
46
46
|
/** On a thinking item: how long the thought took, when the session recorded it. */
|
|
47
47
|
durationMs?: number;
|
|
48
|
+
/** On a user item a scheduled task sent rather than a person. */
|
|
49
|
+
scheduled?: PwCodeScheduledRun;
|
|
50
|
+
}
|
|
51
|
+
/** The scheduled task that started a turn; a self-paced loop's wakeup has no taskId. */
|
|
52
|
+
export interface PwCodeScheduledRun {
|
|
53
|
+
taskId?: string;
|
|
48
54
|
}
|
|
49
55
|
/** A preview of an image a message carried, base64-encoded; ref names the
|
|
50
56
|
* full-size image when the daemon can serve it, and originalMime and
|
|
@@ -199,14 +205,20 @@ export interface PwCodeStreamEvent {
|
|
|
199
205
|
turnId?: string;
|
|
200
206
|
pastes?: PwCodePasteView[] | null;
|
|
201
207
|
images?: PwCodeImage[] | null;
|
|
208
|
+
/** On a user_message a scheduled task sent rather than a person. */
|
|
209
|
+
scheduled?: PwCodeScheduledRun;
|
|
202
210
|
/** On a usage_limit_wait that starts a wait: when the limit resets. */
|
|
203
211
|
resumeAt?: string;
|
|
204
212
|
/** On subagent_delivered: the line the main conversation was handed. */
|
|
205
213
|
notice?: string;
|
|
214
|
+
/** On command_started: the request id the command was sent with. */
|
|
215
|
+
client?: string;
|
|
206
216
|
}
|
|
207
217
|
export interface PwCodeSessionDetail {
|
|
208
218
|
status: PwCodeSessionStatus;
|
|
209
219
|
history?: PwCodeHistoryItem[] | null;
|
|
220
|
+
/** Where history begins in the session's whole history, when it is only the end of it. */
|
|
221
|
+
historyStart?: number;
|
|
210
222
|
approvals?: PwCodeApprovalRequest[] | null;
|
|
211
223
|
lastSeq?: number;
|
|
212
224
|
/** The turn in flight as of lastSeq, cleared with that turn's last frame. */
|
package/dist/useComposer.d.ts
CHANGED
|
@@ -1,25 +1,39 @@
|
|
|
1
|
-
import type { MessagePaste } from '@parallelworks/ui/ai/headless';
|
|
1
|
+
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 {
|
|
9
9
|
/** Composers with the same name share one history. */
|
|
10
10
|
name: string;
|
|
11
|
+
/** What was sent before this tab, oldest first. */
|
|
12
|
+
seed?: readonly string[] | undefined;
|
|
11
13
|
/** Text to forget, such as a command carrying a secret. */
|
|
12
14
|
skip?: ((text: string) => boolean) | undefined;
|
|
13
15
|
}
|
|
16
|
+
/** What the reader typed into a conversation, oldest first: not the recorded
|
|
17
|
+
* commands and `!` runs, nor what the main session told a subagent. */
|
|
18
|
+
export declare function typedPrompts(messages: readonly ChatMessage[]): string[];
|
|
14
19
|
/** Per person, since someone else can sign in where the history is kept, and
|
|
15
|
-
*
|
|
16
|
-
|
|
20
|
+
* per conversation, such as a session or one of its subagents, so ↑ in one
|
|
21
|
+
* recalls only what was sent to it. Without `/auth`, which can carry a key. */
|
|
22
|
+
export declare function promptHistory(username: string, conversation?: {
|
|
23
|
+
id: string;
|
|
24
|
+
messages: readonly ChatMessage[] | undefined;
|
|
25
|
+
}): PwCodeComposerHistory;
|
|
17
26
|
/** What a command printed, shown below the transcript under the command as typed. */
|
|
18
27
|
export interface PwCodeCommandOutput {
|
|
19
28
|
id: number;
|
|
20
29
|
command: string;
|
|
21
30
|
text: string;
|
|
22
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
|
+
}
|
|
23
37
|
export declare function useCommandOutputs(): {
|
|
24
38
|
outputs: PwCodeCommandOutput[];
|
|
25
39
|
add: (command: string, text: string) => void;
|
|
@@ -47,19 +61,15 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
|
|
|
47
61
|
/** How long ago the transcript was last read, already abbreviated: see `useLastReadAt`. */
|
|
48
62
|
staleFor: string;
|
|
49
63
|
/** The images waiting to go with the next message, as `useComposerImages` holds them. */
|
|
50
|
-
images?:
|
|
51
|
-
take: () => Promise<PwCodeTakenImages>;
|
|
52
|
-
restore: (saved: readonly PwCodeSavedImage[]) => void;
|
|
53
|
-
taking: boolean;
|
|
54
|
-
} | undefined;
|
|
64
|
+
images?: PwCodeMessageImages | undefined;
|
|
55
65
|
/** Typed text the host acts on itself, such as a command that opens one of
|
|
56
66
|
* its own panels; true takes it, sending nothing. */
|
|
57
67
|
handleLocally?: ((typed: string) => boolean) | undefined;
|
|
58
68
|
/** Tells the reader something in passing, such as in a toast. */
|
|
59
69
|
notify: (text: string) => void;
|
|
60
|
-
/** Shows the session `/clear` started in place of this one. */
|
|
70
|
+
/** Shows the session `/clear` started in place of this one, while this screen is still open. */
|
|
61
71
|
onCleared: (newId: string) => void;
|
|
62
|
-
/** Leaves the session `/archive` archived. */
|
|
72
|
+
/** Leaves the session `/archive` archived, while this screen is still open. */
|
|
63
73
|
onArchived: () => void;
|
|
64
74
|
}): {
|
|
65
75
|
/** Sends what was typed; false hands it back to the composer. */
|
|
@@ -78,11 +88,20 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
|
|
|
78
88
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
79
89
|
recall: {
|
|
80
90
|
available: boolean;
|
|
81
|
-
take: () => Promise<
|
|
82
|
-
|
|
83
|
-
pastes: MessagePaste[] | undefined;
|
|
84
|
-
}[]>;
|
|
91
|
+
take: () => Promise<Pick<import("./useTranscript.js").PwCodeTakenBack, "pastes" | "shown" | "text">[]>;
|
|
92
|
+
placed: (messages: readonly object[]) => void;
|
|
85
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;
|
|
86
105
|
/** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
|
|
87
106
|
sessionLock: {
|
|
88
107
|
placeholder: string;
|
|
@@ -90,6 +109,8 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
|
|
|
90
109
|
locked: boolean;
|
|
91
110
|
} | null;
|
|
92
111
|
shellRun: string | null;
|
|
112
|
+
/** The commands the activity line can name, oldest first. */
|
|
113
|
+
runningCommands: PwCodeRunningCommand[];
|
|
93
114
|
outputs: PwCodeCommandOutput[];
|
|
94
115
|
dismissOutput: (id: number) => void;
|
|
95
116
|
palette: {
|
package/dist/useComposer.js
CHANGED
|
@@ -2,18 +2,37 @@ 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";
|
|
7
|
+
import { useMounted } from "./useMounted.js";
|
|
6
8
|
import { composerState, sessionLabel } from "./wording.js";
|
|
7
9
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
10
|
+
import { DateTime } from "luxon";
|
|
8
11
|
// src/useComposer.ts
|
|
12
|
+
var RECORDED_COMMAND = /^\/(?:compact|goal|plan)(?:\s|$)/;
|
|
13
|
+
/** What the reader typed into a conversation, oldest first: not the recorded
|
|
14
|
+
* commands and `!` runs, nor what the main session told a subagent. */
|
|
15
|
+
function typedPrompts(messages) {
|
|
16
|
+
return messages.flatMap((m) => m.role === "user" && m.content && !m.pseudo && !(m.commandAnswer && RECORDED_COMMAND.test(m.content)) && !m.author ? [m.content] : []);
|
|
17
|
+
}
|
|
9
18
|
/** Per person, since someone else can sign in where the history is kept, and
|
|
10
|
-
*
|
|
11
|
-
|
|
19
|
+
* per conversation, such as a session or one of its subagents, so ↑ in one
|
|
20
|
+
* recalls only what was sent to it. Without `/auth`, which can carry a key. */
|
|
21
|
+
function promptHistory(username, conversation) {
|
|
12
22
|
return {
|
|
13
|
-
name: `agents:${username}`,
|
|
23
|
+
name: conversation ? `agents:${username}:${conversation.id}` : `agents:${username}`,
|
|
24
|
+
seed: conversation?.messages && typedPrompts(conversation.messages),
|
|
14
25
|
skip: (text) => /^\/auth(\s|$)/.test(text)
|
|
15
26
|
};
|
|
16
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
|
+
}
|
|
17
36
|
/** Typed text steers a running turn; what a command resolved to runs as a turn of its own, and comes back as typed. */
|
|
18
37
|
function resolvedDelivery(text, typed) {
|
|
19
38
|
return text === typed ? { steer: true } : {
|
|
@@ -46,8 +65,14 @@ function useCommandOutputs() {
|
|
|
46
65
|
* elsewhere, or it waits on an approval. */
|
|
47
66
|
function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo, feed, staleFor, images, handleLocally, notify, onCleared, onArchived }) {
|
|
48
67
|
const t = usePwCodeTranslations("agents");
|
|
49
|
-
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;
|
|
50
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]);
|
|
51
76
|
const delivering = useRef(null);
|
|
52
77
|
const { palette, loading: paletteLoading, load: loadPalette } = api.usePalette(machine, sessionId);
|
|
53
78
|
const openPalette = useCallback(() => void loadPalette().catch(() => {}), [loadPalette]);
|
|
@@ -65,6 +90,7 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
65
90
|
warn
|
|
66
91
|
]);
|
|
67
92
|
const { archiveSession, archiveAfterTurn, stopSession } = api.useSessionMutations();
|
|
93
|
+
const mounted = useMounted();
|
|
68
94
|
/** Resolves to the machine's refusal. A session archived once its turn ends stays open, and the machine says so in the transcript. */
|
|
69
95
|
const archiveTyped = useCallback(async (s, waits) => {
|
|
70
96
|
const { refusal, deferred } = waits ? await archiveAfterTurn(s) : {
|
|
@@ -73,12 +99,13 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
73
99
|
};
|
|
74
100
|
if (!refusal && !deferred) {
|
|
75
101
|
notify(t("detail.archived", { name: sessionLabel(s, t) }));
|
|
76
|
-
onArchived();
|
|
102
|
+
if (mounted.current) onArchived();
|
|
77
103
|
}
|
|
78
104
|
return refusal;
|
|
79
105
|
}, [
|
|
80
106
|
archiveAfterTurn,
|
|
81
107
|
archiveSession,
|
|
108
|
+
mounted,
|
|
82
109
|
notify,
|
|
83
110
|
onArchived,
|
|
84
111
|
t
|
|
@@ -106,7 +133,38 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
106
133
|
onOutput: commandOutputs.add,
|
|
107
134
|
onShellRun,
|
|
108
135
|
onCompacted: () => void refetch(),
|
|
109
|
-
|
|
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
|
+
},
|
|
165
|
+
onCleared: (newId) => {
|
|
166
|
+
if (mounted.current) onCleared(newId);
|
|
167
|
+
},
|
|
110
168
|
onArchive: async () => {
|
|
111
169
|
const waits = machineInfo?.archiveAfterTurn === true;
|
|
112
170
|
if (running && !waits) {
|
|
@@ -124,17 +182,12 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
124
182
|
}).finally(() => setShellRun(null));
|
|
125
183
|
if (text === null) return !refused;
|
|
126
184
|
commandOutputs.clear();
|
|
127
|
-
const {
|
|
128
|
-
saved: [],
|
|
129
|
-
settle: () => {}
|
|
130
|
-
};
|
|
131
|
-
const refs = saved.map((i) => i.ref);
|
|
132
|
-
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);
|
|
133
186
|
const delivery = deliver(message, {
|
|
134
187
|
...resolvedDelivery(text, typed),
|
|
135
188
|
pastes,
|
|
136
189
|
images: refs,
|
|
137
|
-
previews
|
|
190
|
+
previews
|
|
138
191
|
});
|
|
139
192
|
delivering.current = delivery;
|
|
140
193
|
const refusal = await delivery;
|
|
@@ -152,6 +205,7 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
152
205
|
loadPalette,
|
|
153
206
|
machine,
|
|
154
207
|
machineInfo?.archiveAfterTurn,
|
|
208
|
+
mounted,
|
|
155
209
|
onCleared,
|
|
156
210
|
onShellRun,
|
|
157
211
|
palette,
|
|
@@ -160,6 +214,7 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
160
214
|
running,
|
|
161
215
|
session,
|
|
162
216
|
sessionId,
|
|
217
|
+
showCommand,
|
|
163
218
|
showError,
|
|
164
219
|
t,
|
|
165
220
|
takeImages,
|
|
@@ -178,27 +233,21 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
178
233
|
session,
|
|
179
234
|
stopSession
|
|
180
235
|
]);
|
|
181
|
-
const
|
|
236
|
+
const takenBack = useTakeBackImages(images?.restore);
|
|
237
|
+
const backWithImages = takenBack.back;
|
|
182
238
|
/** Takes back what waits into the composer, as ↑ does in the terminal; one the model read meanwhile stays sent. */
|
|
183
239
|
const takeBack = useCallback(async () => {
|
|
184
240
|
const { taken, refusal } = await takeBackPending();
|
|
185
241
|
if (refusal) warn(refusal);
|
|
186
|
-
|
|
187
|
-
const preview = previews[i];
|
|
188
|
-
return preview ? [{
|
|
189
|
-
ref,
|
|
190
|
-
preview
|
|
191
|
-
}] : [];
|
|
192
|
-
})));
|
|
193
|
-
return taken.map((m) => ({
|
|
194
|
-
text: withoutAppendedImages(m.text, m.images),
|
|
195
|
-
pastes: m.pastes
|
|
196
|
-
}));
|
|
242
|
+
return backWithImages(taken);
|
|
197
243
|
}, [
|
|
198
|
-
|
|
244
|
+
backWithImages,
|
|
199
245
|
takeBackPending,
|
|
200
246
|
warn
|
|
201
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;
|
|
202
251
|
const status = detail ? liveSessionStatus(detail.status, transcript, goal) : null;
|
|
203
252
|
const approvals = transcript ? pendingApprovals(transcript).map((p) => ({ kind: p.approvalKind })) : detail?.approvals;
|
|
204
253
|
const unreachable = isMachineDown(machineInfo) && !feed.connected;
|
|
@@ -241,16 +290,30 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
|
|
|
241
290
|
},
|
|
242
291
|
composer: {
|
|
243
292
|
...state,
|
|
244
|
-
disabled: sending || !!images?.taking || state.locked
|
|
293
|
+
disabled: sending || !!images?.taking || state.locked || conversation.endOnly
|
|
245
294
|
},
|
|
246
295
|
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
247
296
|
recall: {
|
|
248
|
-
available:
|
|
249
|
-
take: takeBack
|
|
297
|
+
available: canTakeBack(handedBack, queued, canRemoveQueued),
|
|
298
|
+
take: takeBack,
|
|
299
|
+
placed
|
|
250
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,
|
|
251
312
|
/** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
|
|
252
313
|
sessionLock: unreachable || archived || liveElsewhere ? state : null,
|
|
253
314
|
shellRun,
|
|
315
|
+
/** The commands the activity line can name, oldest first. */
|
|
316
|
+
runningCommands,
|
|
254
317
|
outputs: commandOutputs.outputs,
|
|
255
318
|
dismissOutput: commandOutputs.dismiss,
|
|
256
319
|
palette,
|
|
@@ -292,4 +355,4 @@ async function stopTurn(composer, takeBack) {
|
|
|
292
355
|
await composer.turn.stop();
|
|
293
356
|
return failure;
|
|
294
357
|
}
|
|
295
|
-
export { promptHistory, stopTurn, useCommandOutputs, usePwCodeComposer };
|
|
358
|
+
export { promptHistory, stopTurn, typedPrompts, useCommandOutputs, usePwCodeComposer };
|
|
@@ -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;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { usePwCodeTranslations } from "./messages.js";
|
|
2
|
+
import { useMounted } from "./useMounted.js";
|
|
2
3
|
import { IMAGE_PLACEHOLDER } from "./wording.js";
|
|
3
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
5
|
// src/useComposerImages.ts
|
|
@@ -23,6 +24,11 @@ function nextImageSeq(texts, after) {
|
|
|
23
24
|
}
|
|
24
25
|
return seq + 1;
|
|
25
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
|
+
}
|
|
26
32
|
/** The send appends the placeholders of images its text left out; a message
|
|
27
33
|
* taken back gives them back as images, so they leave its text. */
|
|
28
34
|
function withoutAppendedImages(text, images) {
|
|
@@ -31,8 +37,56 @@ function withoutAppendedImages(text, images) {
|
|
|
31
37
|
else if (rest.endsWith(` ${placeholder}`)) rest = rest.slice(0, -placeholder.length - 1);
|
|
32
38
|
return rest;
|
|
33
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
|
+
}
|
|
34
88
|
/** Images stay with the reader until there is a session to save them with. */
|
|
35
|
-
function useComposerImages({ api, machine, sessionId, messages, onError, describeError, encode, preview, release }) {
|
|
89
|
+
function useComposerImages({ api, machine, sessionId, messages, numbering, onError, describeError, encode, preview, release }) {
|
|
36
90
|
const t = usePwCodeTranslations("agents");
|
|
37
91
|
const [images, setImages] = useState([]);
|
|
38
92
|
const [taking, setTaking] = useState(false);
|
|
@@ -54,7 +108,8 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
54
108
|
preview,
|
|
55
109
|
release
|
|
56
110
|
};
|
|
57
|
-
const
|
|
111
|
+
const ownSeq = useRef(0);
|
|
112
|
+
const lastSeq = numbering ?? ownSeq;
|
|
58
113
|
const uploads = useRef(/* @__PURE__ */ new Map());
|
|
59
114
|
const staged = useRef(/* @__PURE__ */ new Map());
|
|
60
115
|
const releasePreview = useCallback((url) => {
|
|
@@ -80,11 +135,9 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
80
135
|
}
|
|
81
136
|
};
|
|
82
137
|
}, []);
|
|
83
|
-
const mounted =
|
|
138
|
+
const mounted = useMounted();
|
|
84
139
|
useEffect(() => {
|
|
85
|
-
mounted.current = true;
|
|
86
140
|
return () => {
|
|
87
|
-
mounted.current = false;
|
|
88
141
|
for (const image of imagesRef.current) releasePreview(image.previewUrl);
|
|
89
142
|
};
|
|
90
143
|
}, [releasePreview]);
|
|
@@ -138,6 +191,7 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
138
191
|
}
|
|
139
192
|
}, [
|
|
140
193
|
discard,
|
|
194
|
+
lastSeq,
|
|
141
195
|
machine,
|
|
142
196
|
onError,
|
|
143
197
|
reportError,
|
|
@@ -196,7 +250,7 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
196
250
|
}
|
|
197
251
|
}
|
|
198
252
|
};
|
|
199
|
-
}, [releasePreview]),
|
|
253
|
+
}, [mounted, releasePreview]),
|
|
200
254
|
restore: useCallback((saved) => {
|
|
201
255
|
if (saved.length === 0) return;
|
|
202
256
|
lastSeq.current = nextImageSeq(saved.map((s) => s.ref.placeholder), lastSeq.current) - 1;
|
|
@@ -211,8 +265,8 @@ function useComposerImages({ api, machine, sessionId, messages, onError, describ
|
|
|
211
265
|
};
|
|
212
266
|
});
|
|
213
267
|
setImages((current) => [...restored, ...current]);
|
|
214
|
-
}, []),
|
|
268
|
+
}, [lastSeq]),
|
|
215
269
|
saveTo
|
|
216
270
|
};
|
|
217
271
|
}
|
|
218
|
-
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 };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMounted } from "./useMounted.js";
|
|
1
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
3
|
import { createPasteCards, joinPastes, pasteInlineMaxBytes } from "@parallelworks/ui/ai/headless";
|
|
3
4
|
import { formatBytes } from "@parallelworks/ui/headless";
|
|
@@ -84,13 +85,7 @@ function usePasteCards({ pastes, input, setInput, composer }) {
|
|
|
84
85
|
useEffect(() => {
|
|
85
86
|
if (inlineMax !== void 0) controller.applyInlineLimit(inlineMax);
|
|
86
87
|
}, [inlineMax, controller]);
|
|
87
|
-
const mounted =
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
mounted.current = true;
|
|
90
|
-
return () => {
|
|
91
|
-
mounted.current = false;
|
|
92
|
-
};
|
|
93
|
-
}, []);
|
|
88
|
+
const mounted = useMounted();
|
|
94
89
|
const send = useCallback(() => {
|
|
95
90
|
const { input: sent, composer: from, cards: taken } = latest.current;
|
|
96
91
|
if (taken.some((c) => !c.paste)) return null;
|
|
@@ -110,7 +105,7 @@ function usePasteCards({ pastes, input, setInput, composer }) {
|
|
|
110
105
|
return true;
|
|
111
106
|
}
|
|
112
107
|
};
|
|
113
|
-
}, [controller]);
|
|
108
|
+
}, [controller, mounted]);
|
|
114
109
|
return {
|
|
115
110
|
cards,
|
|
116
111
|
blocking: cards.some((c) => !c.paste),
|
|
@@ -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>;
|
|
@@ -46,6 +47,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
46
47
|
/** The session, as `api.useSessionDetail` reads it. */
|
|
47
48
|
detail: {
|
|
48
49
|
data: SessionDetail | undefined;
|
|
50
|
+
preview?: SessionDetail | undefined;
|
|
49
51
|
mutate: () => Promise<unknown>;
|
|
50
52
|
};
|
|
51
53
|
/** Words a refusal or failure for the reader. */
|
|
@@ -61,6 +63,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
61
63
|
messages: ChatMessage[];
|
|
62
64
|
queued: ChatMessage[];
|
|
63
65
|
all: ChatMessage[];
|
|
66
|
+
streaming: ChatMessage | null;
|
|
64
67
|
/** The session as the listing has it, or as its fetch does until then. */
|
|
65
68
|
session: {
|
|
66
69
|
allocation?: string;
|
|
@@ -91,6 +94,8 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
91
94
|
status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
|
|
92
95
|
turnStartedAt?: string;
|
|
93
96
|
updatedAt: string;
|
|
97
|
+
usageLimitResumeAt?: string;
|
|
98
|
+
waitingForUsageLimit?: boolean;
|
|
94
99
|
workspace: string;
|
|
95
100
|
} | undefined;
|
|
96
101
|
detail: {
|
|
@@ -107,6 +112,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
107
112
|
goal?: import("./api.js").components["schemas"]["GoalStatus"];
|
|
108
113
|
group?: string;
|
|
109
114
|
history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
|
|
115
|
+
historyStart?: number;
|
|
110
116
|
id: string;
|
|
111
117
|
inputTokens?: number;
|
|
112
118
|
lastError?: string;
|
|
@@ -141,6 +147,8 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
141
147
|
allowedDirs: import("./types.js").PwCodeAllowedDirectory[] | null | undefined;
|
|
142
148
|
refetch: () => Promise<unknown>;
|
|
143
149
|
transcript: TranscriptState | null;
|
|
150
|
+
/** Only the end of the conversation is drawn: the rest of its transcript is still arriving. */
|
|
151
|
+
endOnly: boolean;
|
|
144
152
|
sending: boolean;
|
|
145
153
|
/** Hands each frame of the session's feed to the transcript and the subagent views. */
|
|
146
154
|
onEvent: (ev: StreamEvent) => void;
|
|
@@ -166,6 +174,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
166
174
|
unreachable: boolean;
|
|
167
175
|
} | null>;
|
|
168
176
|
noteShellRun: (command: string, output: string) => void;
|
|
177
|
+
showCommand: (command: string) => (filed: boolean) => void;
|
|
169
178
|
canRemoveQueued: (id: string) => boolean;
|
|
170
179
|
removeQueued: (id: string) => Promise<void>;
|
|
171
180
|
/** Takes back every message the machine still holds, with the first refusal. */
|
|
@@ -173,6 +182,12 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
173
182
|
taken: import("./useTranscript.js").PwCodeTakenBack[];
|
|
174
183
|
refusal: string | null;
|
|
175
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;
|
|
176
191
|
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
177
192
|
queueDelivery: (id: string) => 'nextStep' | 'afterReply';
|
|
178
193
|
answerApproval: (approvalId: string, answer: ApprovalAnswerValue) => Promise<void>;
|
|
@@ -193,6 +208,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
193
208
|
refreshSubagents: () => void;
|
|
194
209
|
stopSubagent: (id: string) => Promise<void>;
|
|
195
210
|
stopAllSubagents: () => Promise<void>;
|
|
211
|
+
dismissSubagent: (id: string) => Promise<boolean>;
|
|
196
212
|
mainState: PwCodeConversationState;
|
|
197
213
|
};
|
|
198
214
|
export type PwCodeConversation = ReturnType<typeof usePwCodeConversation>;
|