@parallelworks/code 0.3.0 → 0.5.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 +625 -113
- package/dist/accountApi.d.ts +31 -0
- package/dist/accountApi.js +182 -0
- package/dist/agentSwitcher.d.ts +120 -0
- package/dist/agentSwitcher.js +187 -0
- package/dist/ago.d.ts +1 -3
- package/dist/ago.js +8 -10
- package/dist/allocations.d.ts +41 -0
- package/dist/allocations.js +76 -0
- package/dist/api.d.ts +1319 -50
- package/dist/chatStrings.d.ts +189 -0
- package/dist/chatStrings.js +218 -0
- package/dist/claudeAccounts.d.ts +57 -2
- package/dist/claudeAccounts.js +144 -6
- package/dist/claudeApi.d.ts +2 -1
- package/dist/claudeApi.js +50 -4
- package/dist/claudeSignIn.d.ts +19 -1
- package/dist/claudeSignIn.js +12 -2
- package/dist/command.d.ts +5 -1
- package/dist/command.js +6 -1
- package/dist/commandsApi.d.ts +11 -1
- package/dist/commandsApi.js +24 -5
- package/dist/createPwCodeApi.d.ts +114 -6
- package/dist/createPwCodeApi.js +21 -3
- package/dist/directories.d.ts +161 -0
- package/dist/directories.js +301 -0
- package/dist/goal.d.ts +89 -0
- package/dist/goal.js +164 -0
- package/dist/imageFit.d.ts +23 -0
- package/dist/imageFit.js +27 -0
- package/dist/images.d.ts +28 -0
- package/dist/images.js +38 -6
- package/dist/index.d.ts +31 -15
- package/dist/index.js +29 -14
- package/dist/loadError.d.ts +8 -0
- package/dist/loadError.js +19 -0
- package/dist/locales/en/agentTranscript.js +74 -12
- package/dist/locales/en/agents.js +86 -11
- package/dist/locales/en.d.ts +137 -8
- package/dist/locales/es/agentTranscript.js +74 -12
- package/dist/locales/es/agents.js +86 -11
- package/dist/locales/ja/agentTranscript.js +77 -15
- package/dist/locales/ja/agents.js +60 -122
- package/dist/locales/ko/agentTranscript.js +74 -12
- package/dist/locales/ko/agents.js +86 -11
- package/dist/locales/zh/agentTranscript.js +72 -10
- package/dist/locales/zh/agents.js +86 -11
- package/dist/machine.d.ts +2 -0
- package/dist/modelPicker.d.ts +79 -0
- package/dist/modelPicker.js +107 -0
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +67 -32
- package/dist/platformDefaults.d.ts +22 -0
- package/dist/platformDefaults.js +30 -0
- package/dist/preferences.d.ts +78 -0
- package/dist/preferences.js +128 -0
- package/dist/pullRequestList.d.ts +10 -2
- package/dist/pullRequestList.js +41 -22
- package/dist/query.d.ts +9 -2
- package/dist/query.js +91 -10
- package/dist/session.d.ts +11 -2
- package/dist/session.js +16 -8
- package/dist/sessionActions.d.ts +11 -1
- package/dist/sessionActions.js +14 -6
- package/dist/sessionEvents.d.ts +37 -5
- package/dist/sessionEvents.js +196 -77
- package/dist/sessionGroups.d.ts +5 -4
- package/dist/sessionGroups.js +6 -5
- package/dist/sessionHeader.js +6 -2
- package/dist/sessionList.d.ts +68 -15
- package/dist/sessionList.js +91 -19
- package/dist/sessionScreen.d.ts +197 -0
- package/dist/sessionScreen.js +218 -0
- package/dist/sessionsApi.d.ts +29 -3
- package/dist/sessionsApi.js +180 -33
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/settingsApi.d.ts +3 -1
- package/dist/startPage.d.ts +153 -0
- package/dist/startPage.js +174 -0
- package/dist/startSession.d.ts +41 -7
- package/dist/startSession.js +26 -4
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +1 -2
- package/dist/transcript.js +111 -117
- package/dist/transcriptRead.d.ts +56 -0
- package/dist/transcriptRead.js +121 -0
- package/dist/types.d.ts +11 -1
- package/dist/useComposer.d.ts +39 -6
- package/dist/useComposer.js +73 -9
- package/dist/useComposerImages.d.ts +5 -0
- package/dist/useComposerImages.js +27 -5
- package/dist/useComposerPastes.d.ts +70 -0
- package/dist/useComposerPastes.js +125 -0
- package/dist/useConversation.d.ts +16 -1
- package/dist/useConversation.js +104 -10
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +51 -3
- package/dist/useSubagent.js +72 -7
- package/dist/useTranscript.d.ts +23 -3
- package/dist/useTranscript.js +76 -19
- package/dist/wording.d.ts +5 -2
- package/dist/wording.js +8 -6
- package/dist/workingDirectories.d.ts +31 -0
- package/dist/workingDirectories.js +25 -1
- package/locales/en/agentTranscript.json +68 -11
- package/locales/en/agents.json +82 -10
- package/locales/es/agentTranscript.json +68 -11
- package/locales/es/agents.json +82 -10
- package/locales/ja/agentTranscript.json +71 -14
- package/locales/ja/agents.json +82 -10
- package/locales/ko/agentTranscript.json +68 -11
- package/locales/ko/agents.json +82 -10
- package/locales/zh/agentTranscript.json +66 -9
- package/locales/zh/agents.json +82 -10
- package/package.json +6 -3
|
@@ -4,7 +4,7 @@ import type { PwCodeResult, Schemas } from './apiClient.js';
|
|
|
4
4
|
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
5
5
|
import { type GoalNotice, type TranscriptState } from './transcript.js';
|
|
6
6
|
import type { PwCodeImage, PwCodeImageRef, PwCodeSessionState } from './types.js';
|
|
7
|
-
import { type PwCodeSteerResult } from './useTranscript.js';
|
|
7
|
+
import { type PwCodeSteerResult, type PwCodeWithdrawResult } from './useTranscript.js';
|
|
8
8
|
type Session = Schemas['AgentSession'];
|
|
9
9
|
type SessionDetail = Schemas['AgentSessionDetail'];
|
|
10
10
|
type SessionsResponse = Schemas['AgentSessionsResponse'];
|
|
@@ -27,6 +27,8 @@ export declare function transcriptMessages(transcript: TranscriptState | null):
|
|
|
27
27
|
};
|
|
28
28
|
/** A direction that got no answer may have landed, so it reads as lost, never as refused. */
|
|
29
29
|
export declare function directionOutcome(request: () => Promise<PwCodeResult<Schemas['AgentDirectionDelivered']>>, lost: string, describeError: (error: unknown) => string): Promise<PwCodeSteerResult>;
|
|
30
|
+
/** Taking back a direction is refused once the model read it, and a lost connection refuses it too. */
|
|
31
|
+
export declare function withdrawalOutcome(noteId: string, request: () => Promise<PwCodeResult<Schemas['AgentDirectionWithdrawn']>>, alreadyRead: string, describeError: (error: unknown) => string): Promise<PwCodeWithdrawResult>;
|
|
30
32
|
/** An open session's conversation: its live transcript, sends routed to the
|
|
31
33
|
* machine, approvals, the notice above the composer, and its subagents. The
|
|
32
34
|
* host reads the listing and the session (`api.useSessions`,
|
|
@@ -44,6 +46,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
44
46
|
/** The session, as `api.useSessionDetail` reads it. */
|
|
45
47
|
detail: {
|
|
46
48
|
data: SessionDetail | undefined;
|
|
49
|
+
preview?: SessionDetail | undefined;
|
|
47
50
|
mutate: () => Promise<unknown>;
|
|
48
51
|
};
|
|
49
52
|
/** Words a refusal or failure for the reader. */
|
|
@@ -89,6 +92,8 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
89
92
|
status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
|
|
90
93
|
turnStartedAt?: string;
|
|
91
94
|
updatedAt: string;
|
|
95
|
+
usageLimitResumeAt?: string;
|
|
96
|
+
waitingForUsageLimit?: boolean;
|
|
92
97
|
workspace: string;
|
|
93
98
|
} | undefined;
|
|
94
99
|
detail: {
|
|
@@ -139,6 +144,8 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
139
144
|
allowedDirs: import("./types.js").PwCodeAllowedDirectory[] | null | undefined;
|
|
140
145
|
refetch: () => Promise<unknown>;
|
|
141
146
|
transcript: TranscriptState | null;
|
|
147
|
+
/** Only the end of the conversation is drawn: the rest of its transcript is still arriving. */
|
|
148
|
+
endOnly: boolean;
|
|
142
149
|
sending: boolean;
|
|
143
150
|
/** Hands each frame of the session's feed to the transcript and the subagent views. */
|
|
144
151
|
onEvent: (ev: StreamEvent) => void;
|
|
@@ -154,6 +161,8 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
154
161
|
reached: () => void;
|
|
155
162
|
deliver: (text: string, options: {
|
|
156
163
|
steer?: boolean;
|
|
164
|
+
/** What was typed, when the text is what a command resolved it to. */
|
|
165
|
+
typed?: string | undefined;
|
|
157
166
|
pastes?: MessagePaste[] | undefined;
|
|
158
167
|
images?: PwCodeImageRef[] | undefined;
|
|
159
168
|
previews?: PwCodeImage[] | undefined;
|
|
@@ -164,6 +173,11 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
164
173
|
noteShellRun: (command: string, output: string) => void;
|
|
165
174
|
canRemoveQueued: (id: string) => boolean;
|
|
166
175
|
removeQueued: (id: string) => Promise<void>;
|
|
176
|
+
/** Takes back every message the machine still holds, with the first refusal. */
|
|
177
|
+
takeBackPending: () => Promise<{
|
|
178
|
+
taken: import("./useTranscript.js").PwCodeTakenBack[];
|
|
179
|
+
refusal: string | null;
|
|
180
|
+
}>;
|
|
167
181
|
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
168
182
|
queueDelivery: (id: string) => 'nextStep' | 'afterReply';
|
|
169
183
|
answerApproval: (approvalId: string, answer: ApprovalAnswerValue) => Promise<void>;
|
|
@@ -184,6 +198,7 @@ export declare function usePwCodeConversation({ api, machine, sessionId, session
|
|
|
184
198
|
refreshSubagents: () => void;
|
|
185
199
|
stopSubagent: (id: string) => Promise<void>;
|
|
186
200
|
stopAllSubagents: () => Promise<void>;
|
|
201
|
+
dismissSubagent: (id: string) => Promise<boolean>;
|
|
187
202
|
mainState: PwCodeConversationState;
|
|
188
203
|
};
|
|
189
204
|
export type PwCodeConversation = ReturnType<typeof usePwCodeConversation>;
|
package/dist/useConversation.js
CHANGED
|
@@ -6,9 +6,9 @@ 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. */
|
|
@@ -29,12 +29,25 @@ function transcriptMessages(transcript) {
|
|
|
29
29
|
async function directionOutcome(request, lost, describeError) {
|
|
30
30
|
try {
|
|
31
31
|
const { data, error } = await request();
|
|
32
|
-
if (!error) return {
|
|
32
|
+
if (!error) return {
|
|
33
|
+
delivered: !!data?.delivered,
|
|
34
|
+
id: data?.id
|
|
35
|
+
};
|
|
33
36
|
return steerMayHaveLanded(error) ? { lost } : { error: describeError(error) };
|
|
34
37
|
} catch {
|
|
35
38
|
return { lost };
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
/** Taking back a direction is refused once the model read it, and a lost connection refuses it too. */
|
|
42
|
+
async function withdrawalOutcome(noteId, request, alreadyRead, describeError) {
|
|
43
|
+
try {
|
|
44
|
+
const { data, error } = await request();
|
|
45
|
+
if (error) return { error: describeError(error) };
|
|
46
|
+
return data?.withdrawn?.includes(noteId) ? {} : { error: alreadyRead };
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return { error: describeError(error) };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
38
51
|
/** What a frame says of the main conversation's own turn; null leaves it to the refetched detail, undefined says nothing. */
|
|
39
52
|
function mainTurnAfter(ev) {
|
|
40
53
|
if (ev.type === "replay_truncated") return null;
|
|
@@ -42,6 +55,41 @@ function mainTurnAfter(ev) {
|
|
|
42
55
|
if (ev.type === "user_message" || ev.type === "turn_start") return true;
|
|
43
56
|
if (ev.turnId && (ev.type === "done" || ev.type === "error")) return false;
|
|
44
57
|
}
|
|
58
|
+
/** The end of a conversation, drawn while the rest of its transcript is still
|
|
59
|
+
* arriving: nothing is live until the whole of it has. It stays until the
|
|
60
|
+
* whole is drawn in its place, a render after it arrives. */
|
|
61
|
+
function useConversationEnd(transcript, preview, { goalNotice, ...notices }) {
|
|
62
|
+
const [held, setHeld] = useState(preview);
|
|
63
|
+
if (preview && preview !== held) setHeld(preview);
|
|
64
|
+
const end = transcript ? void 0 : preview ?? held;
|
|
65
|
+
const { compactionNotice, recapNotice, words, imageUrl } = notices;
|
|
66
|
+
return useMemo(() => {
|
|
67
|
+
if (!end) return null;
|
|
68
|
+
const state = initialTranscript({
|
|
69
|
+
...end,
|
|
70
|
+
approvals: []
|
|
71
|
+
}, {
|
|
72
|
+
...goalNotice ? { goalNotice } : {},
|
|
73
|
+
compactionNotice,
|
|
74
|
+
recapNotice,
|
|
75
|
+
words,
|
|
76
|
+
imageUrl
|
|
77
|
+
});
|
|
78
|
+
const messages = state.streaming ? [...state.messages, state.streaming] : state.messages;
|
|
79
|
+
return {
|
|
80
|
+
messages,
|
|
81
|
+
queued: [],
|
|
82
|
+
all: messages
|
|
83
|
+
};
|
|
84
|
+
}, [
|
|
85
|
+
end,
|
|
86
|
+
goalNotice,
|
|
87
|
+
compactionNotice,
|
|
88
|
+
recapNotice,
|
|
89
|
+
words,
|
|
90
|
+
imageUrl
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
45
93
|
/** An open session's conversation: its live transcript, sends routed to the
|
|
46
94
|
* machine, approvals, the notice above the composer, and its subagents. The
|
|
47
95
|
* host reads the listing and the session (`api.useSessions`,
|
|
@@ -50,7 +98,9 @@ function mainTurnAfter(ev) {
|
|
|
50
98
|
function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read, describeError, notify, onCleared, onMoved, goalNotice }) {
|
|
51
99
|
const t = usePwCodeTranslations("agents");
|
|
52
100
|
const { data: list, mutate: mutateSessions } = sessions;
|
|
53
|
-
const
|
|
101
|
+
const listNow = useRef(list);
|
|
102
|
+
listNow.current = list;
|
|
103
|
+
const { data: detail, mutate, preview } = read;
|
|
54
104
|
const session = list?.sessions?.find((s) => isSession(s, machine, sessionId)) ?? detail;
|
|
55
105
|
const moved = sharedStoreCopy(list, machine, sessionId);
|
|
56
106
|
const onMovedRef = useRef(onMoved);
|
|
@@ -91,7 +141,11 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
91
141
|
name: effect.state.name ?? "",
|
|
92
142
|
autoName: effect.state.autoName ?? ""
|
|
93
143
|
};
|
|
94
|
-
|
|
144
|
+
const renamed = patchSessionNames(listNow.current, machine, sessionId, names);
|
|
145
|
+
if (renamed !== listNow.current) {
|
|
146
|
+
listNow.current = renamed;
|
|
147
|
+
mutateSessions((current) => patchSessionNames(current, machine, sessionId, names), { revalidate: false });
|
|
148
|
+
}
|
|
95
149
|
break;
|
|
96
150
|
}
|
|
97
151
|
case "notice": setNotice({
|
|
@@ -133,8 +187,12 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
133
187
|
sessionId
|
|
134
188
|
]);
|
|
135
189
|
const withdrawQueued = useCallback(async (turnId) => {
|
|
136
|
-
|
|
137
|
-
|
|
190
|
+
try {
|
|
191
|
+
const { error } = await api.withdrawQueued(machine, sessionId, turnId);
|
|
192
|
+
return error ? { error: describeError(error) } : {};
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return { error: describeError(error) };
|
|
195
|
+
}
|
|
138
196
|
}, [
|
|
139
197
|
api,
|
|
140
198
|
describeError,
|
|
@@ -152,16 +210,24 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
152
210
|
sessionId,
|
|
153
211
|
t
|
|
154
212
|
]);
|
|
213
|
+
const withdrawDirection = useCallback((noteId) => withdrawalOutcome(noteId, () => api.withdrawDirection(machine, sessionId, [noteId]), t("detail.steerAlreadyRead"), describeError), [
|
|
214
|
+
api,
|
|
215
|
+
describeError,
|
|
216
|
+
machine,
|
|
217
|
+
sessionId,
|
|
218
|
+
t
|
|
219
|
+
]);
|
|
155
220
|
const compactionNotice = useCompactionNotice();
|
|
156
221
|
const recapNotice = useRecapNotice();
|
|
157
222
|
const words = useTranscriptWords();
|
|
158
223
|
const imageUrl = useCallback((ref) => sessionImageUrl(machine, sessionId, ref), [machine, sessionId]);
|
|
159
|
-
const { transcript, sending, onEvent: applyEvent, sendMessage: sendToTranscript, resolveApproval, noteShellRun, canRemoveQueued, removeQueued: removeFromTranscript, cursor } = usePwCodeTranscript({
|
|
224
|
+
const { transcript, sending, onEvent: applyEvent, sendMessage: sendToTranscript, resolveApproval, noteShellRun, canRemoveQueued, removeQueued: removeFromTranscript, takeBackPending, cursor } = usePwCodeTranscript({
|
|
160
225
|
sessionId,
|
|
161
226
|
detail,
|
|
162
227
|
send: postMessage,
|
|
163
228
|
steer: postDirection,
|
|
164
229
|
withdraw: withdrawQueued,
|
|
230
|
+
withdrawDirection,
|
|
165
231
|
onEffect: runEffect,
|
|
166
232
|
...goalNotice ? { goalNotice } : {},
|
|
167
233
|
compactionNotice,
|
|
@@ -238,6 +304,22 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
238
304
|
sessionId,
|
|
239
305
|
showError
|
|
240
306
|
]);
|
|
307
|
+
/** Resolves to whether the machine took the subagent off the list. */
|
|
308
|
+
const dismissSubagent = useCallback(async (id) => {
|
|
309
|
+
const refusal = await api.dismissSubagent(machine, sessionId, id);
|
|
310
|
+
if (refusal) {
|
|
311
|
+
showError(refusal);
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
refreshSubagents();
|
|
315
|
+
return true;
|
|
316
|
+
}, [
|
|
317
|
+
api,
|
|
318
|
+
machine,
|
|
319
|
+
sessionId,
|
|
320
|
+
showError,
|
|
321
|
+
refreshSubagents
|
|
322
|
+
]);
|
|
241
323
|
const goal = liveState ? liveState.goal : detail?.goal;
|
|
242
324
|
const addDirs = liveState ? liveState.addDirs : detail?.addDirs;
|
|
243
325
|
const allowedDirs = liveState ? liveState.allowedDirs : detail?.allowedDirs;
|
|
@@ -245,6 +327,13 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
245
327
|
const mainWaits = !!transcript && pendingApprovals(transcript).some((p) => !p.agent);
|
|
246
328
|
const mainRuns = mainTurn ?? !!detail?.turnId;
|
|
247
329
|
const mainState = mainWaits ? "approval" : mainRuns ? "running" : "idle";
|
|
330
|
+
const early = useConversationEnd(transcript, preview, {
|
|
331
|
+
goalNotice,
|
|
332
|
+
compactionNotice,
|
|
333
|
+
recapNotice,
|
|
334
|
+
words,
|
|
335
|
+
imageUrl
|
|
336
|
+
});
|
|
248
337
|
return {
|
|
249
338
|
/** The session as the listing has it, or as its fetch does until then. */
|
|
250
339
|
session,
|
|
@@ -256,7 +345,9 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
256
345
|
allowedDirs,
|
|
257
346
|
refetch: mutate,
|
|
258
347
|
transcript,
|
|
259
|
-
...transcriptMessages(transcript),
|
|
348
|
+
...early ?? transcriptMessages(transcript),
|
|
349
|
+
/** Only the end of the conversation is drawn: the rest of its transcript is still arriving. */
|
|
350
|
+
endOnly: early !== null,
|
|
260
351
|
sending,
|
|
261
352
|
/** Hands each frame of the session's feed to the transcript and the subagent views. */
|
|
262
353
|
onEvent,
|
|
@@ -274,6 +365,8 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
274
365
|
noteShellRun,
|
|
275
366
|
canRemoveQueued,
|
|
276
367
|
removeQueued,
|
|
368
|
+
/** Takes back every message the machine still holds, with the first refusal. */
|
|
369
|
+
takeBackPending,
|
|
277
370
|
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
278
371
|
queueDelivery: (id) => steered.has(id) ? "nextStep" : "afterReply",
|
|
279
372
|
answerApproval,
|
|
@@ -281,7 +374,8 @@ function usePwCodeConversation({ api, machine, sessionId, sessions, detail: read
|
|
|
281
374
|
refreshSubagents,
|
|
282
375
|
stopSubagent,
|
|
283
376
|
stopAllSubagents,
|
|
377
|
+
dismissSubagent,
|
|
284
378
|
mainState
|
|
285
379
|
};
|
|
286
380
|
}
|
|
287
|
-
export { directionOutcome, transcriptMessages, usePwCodeConversation };
|
|
381
|
+
export { directionOutcome, transcriptMessages, usePwCodeConversation, withdrawalOutcome };
|
|
@@ -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
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { ApprovalAnswerValue, MessagePaste } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import { type PwCodeSwitcherAgent } from './agentSwitcher.js';
|
|
2
3
|
import type { Schemas } from './apiClient.js';
|
|
3
4
|
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
5
|
+
import type { PwCodeSubagentUsage } from './types.js';
|
|
6
|
+
declare const nextStep: (_id: string) => 'nextStep' | 'afterReply';
|
|
4
7
|
/** One subagent's conversation in place of the main one: its transcript, kept
|
|
5
8
|
* current from the session's feed, and a composer that talks to it. Commands
|
|
6
9
|
* and `!` stay with the main conversation's composer. The host reads the
|
|
7
10
|
* subagent with `api.useSubagentDetail`. */
|
|
8
|
-
export declare function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, subscribe, loadPalette, describeError, sessionLock,
|
|
11
|
+
export declare function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, usage, subscribe, loadPalette, describeError, sessionLock, modelNames, onSent, }: {
|
|
9
12
|
api: PwCodeApi;
|
|
10
13
|
machine: string;
|
|
11
14
|
sessionId: string;
|
|
@@ -13,8 +16,13 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
13
16
|
/** The subagent, as `api.useSubagentDetail` reads it. */
|
|
14
17
|
subagent: {
|
|
15
18
|
data: Schemas['SubagentDetail'] | undefined;
|
|
19
|
+
error?: unknown;
|
|
16
20
|
refresh: () => void;
|
|
17
21
|
};
|
|
22
|
+
/** Its row in the session's switcher, which the feed keeps current; its own read stands in until the list has it. */
|
|
23
|
+
listed: PwCodeSwitcherAgent | undefined;
|
|
24
|
+
/** Its tokens as the session's feed last counted them. */
|
|
25
|
+
usage: PwCodeSubagentUsage | undefined;
|
|
18
26
|
/** Hands over each frame of the session's feed until the returned call: the main conversation's `subscribe`. */
|
|
19
27
|
subscribe: (listener: (ev: Schemas['AgentStreamEvent']) => void) => () => void;
|
|
20
28
|
/** The session's palette, which says what typed text is a command. */
|
|
@@ -26,14 +34,24 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
26
34
|
placeholder: string;
|
|
27
35
|
hint: string;
|
|
28
36
|
} | null;
|
|
29
|
-
/**
|
|
30
|
-
|
|
37
|
+
/** Names the session gives its models, as its state frames carry them. */
|
|
38
|
+
modelNames?: Readonly<Record<string, string>> | undefined;
|
|
31
39
|
/** The subagent took a message, so the session's list of them reads differently. */
|
|
32
40
|
onSent: () => void;
|
|
33
41
|
}): {
|
|
34
42
|
messages: import("@parallelworks/ui/ai/headless").ChatMessage[];
|
|
35
43
|
queued: import("@parallelworks/ui/ai/headless").ChatMessage[];
|
|
36
44
|
all: import("@parallelworks/ui/ai/headless").ChatMessage[];
|
|
45
|
+
/** The subagent as its own view shows it; unset until it is listed or read. */
|
|
46
|
+
agent: PwCodeSwitcherAgent | undefined;
|
|
47
|
+
/** The composer's draft key, under its session's and apart from the main conversation's. */
|
|
48
|
+
draftKey: string;
|
|
49
|
+
/** The `id` its `promptHistory` takes, so ↑ in its composer recalls only what was sent to it. */
|
|
50
|
+
historyId: string;
|
|
51
|
+
/** The model it runs on; empty until it is read, or when it names none. */
|
|
52
|
+
model: string;
|
|
53
|
+
/** That model's name as the session gives it, or its id without the provider. */
|
|
54
|
+
modelLabel: string;
|
|
37
55
|
transcript: import("./transcript.js").TranscriptState | null;
|
|
38
56
|
sending: boolean;
|
|
39
57
|
running: boolean;
|
|
@@ -42,6 +60,35 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
42
60
|
dismissNotice: () => void;
|
|
43
61
|
/** Sends what was typed; false hands it back to the composer. */
|
|
44
62
|
send: (typed: string, sent?: MessagePaste[]) => Promise<boolean>;
|
|
63
|
+
canRemoveQueued: (id: string) => boolean;
|
|
64
|
+
removeQueued: (id: string) => Promise<void>;
|
|
65
|
+
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
66
|
+
recall: {
|
|
67
|
+
available: boolean;
|
|
68
|
+
take: () => Promise<{
|
|
69
|
+
text: string;
|
|
70
|
+
pastes: MessagePaste[] | undefined;
|
|
71
|
+
}[]>;
|
|
72
|
+
};
|
|
73
|
+
showAuthor: boolean;
|
|
74
|
+
/** The subagent has yet to load for the first time. */
|
|
75
|
+
loading: boolean;
|
|
76
|
+
/** Shown in place of a transcript that never loaded: why, or undefined
|
|
77
|
+
* for the host's own line. */
|
|
78
|
+
failed: {
|
|
79
|
+
message: string | undefined;
|
|
80
|
+
} | null;
|
|
81
|
+
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
82
|
+
queueDelivery: typeof nextStep;
|
|
83
|
+
/** The composer's activity line while the subagent's turn runs; until its
|
|
84
|
+
* read lands, timed from when its row in the list says it started. */
|
|
85
|
+
activity: {
|
|
86
|
+
kind: 'working';
|
|
87
|
+
startedAt: string | null;
|
|
88
|
+
inputTokens: number | undefined;
|
|
89
|
+
outputTokens: number | undefined;
|
|
90
|
+
word: string | undefined;
|
|
91
|
+
} | null;
|
|
45
92
|
turn: {
|
|
46
93
|
running: boolean;
|
|
47
94
|
stop: () => Promise<void>;
|
|
@@ -56,3 +103,4 @@ export declare function usePwCodeSubagent({ api, machine, sessionId, subId, suba
|
|
|
56
103
|
};
|
|
57
104
|
};
|
|
58
105
|
export type PwCodeSubagent = ReturnType<typeof usePwCodeSubagent>;
|
|
106
|
+
export {};
|
package/dist/useSubagent.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
+
import { switcherAgent, useAgentTypeLabel } from "./agentSwitcher.js";
|
|
1
2
|
import { shellCommand, slashAction } from "./command.js";
|
|
2
3
|
import { sessionImageUrl } from "./images.js";
|
|
4
|
+
import { loadFailure } from "./loadError.js";
|
|
3
5
|
import { usePwCodeTranslations } from "./messages.js";
|
|
4
6
|
import { useTranscriptWords } from "./notices.js";
|
|
5
7
|
import { pendingApprovals, subagentSessionDetail, turnRunning } from "./transcript.js";
|
|
6
|
-
import { directionOutcome, transcriptMessages } from "./useConversation.js";
|
|
8
|
+
import { directionOutcome, transcriptMessages, withdrawalOutcome } from "./useConversation.js";
|
|
7
9
|
import { usePwCodeTranscript } from "./useTranscript.js";
|
|
10
|
+
import { modelLabel } from "./models.js";
|
|
11
|
+
import { sessionDraftKey, workingActivity } from "./sessionScreen.js";
|
|
8
12
|
import { pasteRefs } from "./sessionsApi.js";
|
|
9
13
|
import { composerState } from "./wording.js";
|
|
10
14
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
11
15
|
// src/useSubagent.ts
|
|
16
|
+
var nextStep = (_id) => "nextStep";
|
|
12
17
|
/** One subagent's conversation in place of the main one: its transcript, kept
|
|
13
18
|
* current from the session's feed, and a composer that talks to it. Commands
|
|
14
19
|
* and `!` stay with the main conversation's composer. The host reads the
|
|
15
20
|
* subagent with `api.useSubagentDetail`. */
|
|
16
|
-
function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, subscribe, loadPalette, describeError, sessionLock,
|
|
21
|
+
function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, listed, usage, subscribe, loadPalette, describeError, sessionLock, modelNames, onSent }) {
|
|
17
22
|
const t = usePwCodeTranslations("agents");
|
|
18
|
-
const
|
|
23
|
+
const typeLabel = useAgentTypeLabel();
|
|
24
|
+
const { data, error, refresh } = subagent;
|
|
25
|
+
const known = listed ?? (data ? switcherAgent(data, usage) : void 0);
|
|
26
|
+
const name = known ? typeLabel(known.agentType) : "";
|
|
19
27
|
const detail = useMemo(() => data ? subagentSessionDetail(data) : void 0, [data]);
|
|
20
28
|
const [notice, setNotice] = useState(null);
|
|
21
29
|
const postMessage = useCallback(async (text, sent) => {
|
|
@@ -46,21 +54,42 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, subscribe
|
|
|
46
54
|
subId,
|
|
47
55
|
t
|
|
48
56
|
]);
|
|
57
|
+
const withdrawDirection = useCallback((noteId) => withdrawalOutcome(noteId, () => api.withdrawSubagentDirection(machine, sessionId, subId, [noteId]), t("detail.steerAlreadyRead"), describeError), [
|
|
58
|
+
api,
|
|
59
|
+
describeError,
|
|
60
|
+
machine,
|
|
61
|
+
sessionId,
|
|
62
|
+
subId,
|
|
63
|
+
t
|
|
64
|
+
]);
|
|
49
65
|
const runEffect = useCallback((effect) => {
|
|
50
66
|
if (effect.type === "refetch") refresh();
|
|
51
67
|
}, [refresh]);
|
|
52
68
|
const words = useTranscriptWords();
|
|
53
69
|
const imageUrl = useCallback((ref) => sessionImageUrl(machine, sessionId, ref), [machine, sessionId]);
|
|
54
|
-
const { transcript, sending, onEvent, sendMessage: sendToTranscript, resolveApproval } = usePwCodeTranscript({
|
|
70
|
+
const { transcript, sending, onEvent, sendMessage: sendToTranscript, resolveApproval, canRemoveQueued, removeQueued: removeFromTranscript, takeBackPending } = usePwCodeTranscript({
|
|
55
71
|
subagent: subId,
|
|
56
72
|
detail,
|
|
57
73
|
send: postMessage,
|
|
58
74
|
steer: postDirection,
|
|
75
|
+
withdrawDirection,
|
|
59
76
|
onEffect: runEffect,
|
|
60
77
|
words,
|
|
61
78
|
imageUrl
|
|
62
79
|
});
|
|
63
80
|
useEffect(() => subscribe(onEvent), [subscribe, onEvent]);
|
|
81
|
+
const removeQueued = useCallback(async (id) => {
|
|
82
|
+
const refusal = await removeFromTranscript(id);
|
|
83
|
+
if (refusal) setNotice(refusal);
|
|
84
|
+
}, [removeFromTranscript]);
|
|
85
|
+
const takeBack = useCallback(async () => {
|
|
86
|
+
const { taken, refusal } = await takeBackPending();
|
|
87
|
+
if (refusal) setNotice(refusal);
|
|
88
|
+
return taken.map(({ text, pastes }) => ({
|
|
89
|
+
text,
|
|
90
|
+
pastes
|
|
91
|
+
}));
|
|
92
|
+
}, [takeBackPending]);
|
|
64
93
|
const send = useCallback(async (typed, sent) => {
|
|
65
94
|
if (shellCommand(typed) !== null || typed.trimStart().startsWith("/") && slashAction(typed, await loadPalette().catch(() => null)).kind !== "message") {
|
|
66
95
|
setNotice(t("switcher.commandsOnMain"));
|
|
@@ -105,7 +134,12 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, subscribe
|
|
|
105
134
|
sessionId
|
|
106
135
|
]);
|
|
107
136
|
const dismissNotice = useCallback(() => setNotice(null), []);
|
|
108
|
-
const running = turnRunning(transcript);
|
|
137
|
+
const running = transcript ? turnRunning(transcript) : known?.status === "running";
|
|
138
|
+
const agent = known && running && known.status !== "running" ? {
|
|
139
|
+
...known,
|
|
140
|
+
status: "running",
|
|
141
|
+
endedAt: void 0
|
|
142
|
+
} : known;
|
|
109
143
|
const approvals = transcript ? pendingApprovals(transcript) : [];
|
|
110
144
|
const composer = sessionLock ? {
|
|
111
145
|
...sessionLock,
|
|
@@ -124,9 +158,22 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, subscribe
|
|
|
124
158
|
hint: running ? t("switcher.steerHint") : "",
|
|
125
159
|
locked: false
|
|
126
160
|
};
|
|
161
|
+
const messages = transcriptMessages(transcript);
|
|
162
|
+
const working = running && !sessionLock;
|
|
163
|
+
const model = data?.model ?? "";
|
|
127
164
|
return {
|
|
165
|
+
/** The subagent as its own view shows it; unset until it is listed or read. */
|
|
166
|
+
agent,
|
|
167
|
+
/** The composer's draft key, under its session's and apart from the main conversation's. */
|
|
168
|
+
draftKey: `${sessionDraftKey(sessionId, void 0)}:${subId}`,
|
|
169
|
+
/** The `id` its `promptHistory` takes, so ↑ in its composer recalls only what was sent to it. */
|
|
170
|
+
historyId: `${sessionId}:${subId}`,
|
|
171
|
+
/** The model it runs on; empty until it is read, or when it names none. */
|
|
172
|
+
model,
|
|
173
|
+
/** That model's name as the session gives it, or its id without the provider. */
|
|
174
|
+
modelLabel: modelLabel(model, modelNames?.[model]),
|
|
128
175
|
transcript,
|
|
129
|
-
...
|
|
176
|
+
...messages,
|
|
130
177
|
sending,
|
|
131
178
|
running,
|
|
132
179
|
approvals,
|
|
@@ -134,8 +181,26 @@ function usePwCodeSubagent({ api, machine, sessionId, subId, subagent, subscribe
|
|
|
134
181
|
dismissNotice,
|
|
135
182
|
/** Sends what was typed; false hands it back to the composer. */
|
|
136
183
|
send,
|
|
184
|
+
canRemoveQueued,
|
|
185
|
+
removeQueued,
|
|
186
|
+
/** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
|
|
187
|
+
recall: {
|
|
188
|
+
available: messages.queued.some((m) => canRemoveQueued(m.id)),
|
|
189
|
+
take: takeBack
|
|
190
|
+
},
|
|
191
|
+
showAuthor: messages.all.some((m) => m.author),
|
|
192
|
+
/** The subagent has yet to load for the first time. */
|
|
193
|
+
loading: !data && !error,
|
|
194
|
+
/** Shown in place of a transcript that never loaded: why, or undefined
|
|
195
|
+
* for the host's own line. */
|
|
196
|
+
failed: loadFailure(error, !!data, describeError),
|
|
197
|
+
/** Whether a queued message goes into the running turn's next step or waits for its reply. */
|
|
198
|
+
queueDelivery: nextStep,
|
|
199
|
+
/** The composer's activity line while the subagent's turn runs; until its
|
|
200
|
+
* read lands, timed from when its row in the list says it started. */
|
|
201
|
+
activity: working ? workingActivity(transcript ?? { turnStartedAt: known?.startedAt ?? null }, usage) : null,
|
|
137
202
|
turn: {
|
|
138
|
-
running:
|
|
203
|
+
running: working,
|
|
139
204
|
stop,
|
|
140
205
|
stopping
|
|
141
206
|
},
|
package/dist/useTranscript.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ export type PwCodeSendResult = {
|
|
|
7
7
|
} | {
|
|
8
8
|
error: string;
|
|
9
9
|
};
|
|
10
|
-
/** lost: no answer came, so the direction may have reached the turn.
|
|
10
|
+
/** lost: no answer came, so the direction may have reached the turn. id takes
|
|
11
|
+
* a delivered direction back; older machines name none. */
|
|
11
12
|
export type PwCodeSteerResult = {
|
|
12
13
|
delivered: boolean;
|
|
14
|
+
id?: string | undefined;
|
|
13
15
|
} | {
|
|
14
16
|
error: string;
|
|
15
17
|
} | {
|
|
@@ -18,8 +20,17 @@ export type PwCodeSteerResult = {
|
|
|
18
20
|
export type PwCodeWithdrawResult = {
|
|
19
21
|
error?: string;
|
|
20
22
|
};
|
|
23
|
+
/** A pending message taken back before the model read it, as it was sent. */
|
|
24
|
+
export interface PwCodeTakenBack {
|
|
25
|
+
text: string;
|
|
26
|
+
pastes?: MessagePaste[] | undefined;
|
|
27
|
+
images?: PwCodeImageRef[] | undefined;
|
|
28
|
+
previews?: PwCodeImage[] | undefined;
|
|
29
|
+
}
|
|
21
30
|
interface SendOptions {
|
|
22
31
|
steer?: boolean;
|
|
32
|
+
/** What was typed, when the text is what a command resolved it to, such as /plan's prompt; taken back, it returns as typed. */
|
|
33
|
+
typed?: string | undefined;
|
|
23
34
|
pastes?: MessagePaste[] | undefined;
|
|
24
35
|
images?: PwCodeImageRef[] | undefined;
|
|
25
36
|
/** Drawn on the message until its echo brings the daemon's; a note can wait a whole tool call for that. */
|
|
@@ -27,7 +38,7 @@ interface SendOptions {
|
|
|
27
38
|
}
|
|
28
39
|
/** Holds the live transcript for one session. The host still owns the socket
|
|
29
40
|
* and the fetch: it feeds events to `onEvent` and posts through `send`. */
|
|
30
|
-
export declare function usePwCodeTranscript({ sessionId, subagent, detail, send, steer, withdraw, onEffect, goalNotice, compactionNotice, recapNotice, words, imageUrl, }: {
|
|
41
|
+
export declare function usePwCodeTranscript({ sessionId, subagent, detail, send, steer, withdraw, withdrawDirection, onEffect, goalNotice, compactionNotice, recapNotice, words, imageUrl, }: {
|
|
31
42
|
/** The session shown, so frames from the conversation it cleared are dropped. */
|
|
32
43
|
sessionId?: string | undefined;
|
|
33
44
|
/** Shows this subagent's conversation instead of the main one: the frames
|
|
@@ -39,6 +50,8 @@ export declare function usePwCodeTranscript({ sessionId, subagent, detail, send,
|
|
|
39
50
|
steer?: (text: string, pastes?: MessagePaste[], images?: PwCodeImageRef[]) => Promise<PwCodeSteerResult>;
|
|
40
51
|
/** Takes back a queued message, by the turn it was accepted as. */
|
|
41
52
|
withdraw?: (turnId: string) => Promise<PwCodeWithdrawResult>;
|
|
53
|
+
/** Takes back a steered message by the id steering named it; refused once the model read it. */
|
|
54
|
+
withdrawDirection?: (noteId: string) => Promise<PwCodeWithdrawResult>;
|
|
42
55
|
onEffect: (effect: StreamEffect) => void;
|
|
43
56
|
goalNotice?: GoalNotice;
|
|
44
57
|
compactionNotice?: CompactionNotice;
|
|
@@ -53,10 +66,17 @@ export declare function usePwCodeTranscript({ sessionId, subagent, detail, send,
|
|
|
53
66
|
sendMessage: (text: string, options?: SendOptions) => Promise<string | null>;
|
|
54
67
|
resolveApproval: (approvalId: string) => void;
|
|
55
68
|
noteShellRun: (command: string, output: string) => void;
|
|
56
|
-
/**
|
|
69
|
+
/** Pending messages the daemon named a turn or note for can be taken back
|
|
70
|
+
* until they reach the model. */
|
|
57
71
|
canRemoveQueued: (id: string) => boolean;
|
|
58
72
|
/** Resolves to the refusal, or null once the message is gone. */
|
|
59
73
|
removeQueued: (id: string) => Promise<string | null>;
|
|
74
|
+
/** Takes back every pending message the machine still holds, with the first
|
|
75
|
+
* refusal; one the model read meanwhile stays sent. */
|
|
76
|
+
takeBackPending: () => Promise<{
|
|
77
|
+
taken: PwCodeTakenBack[];
|
|
78
|
+
refusal: string | null;
|
|
79
|
+
}>;
|
|
60
80
|
/** Where a reconnect resumes from: the last seq applied, read outside render. */
|
|
61
81
|
cursor: () => number;
|
|
62
82
|
};
|