@parallelworks/code 0.2.0 → 0.3.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 +43 -10
- package/dist/ago.d.ts +8 -0
- package/dist/ago.js +26 -0
- package/dist/api.d.ts +78 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.js +15 -0
- package/dist/chatHandoff.d.ts +12 -0
- package/dist/chatHandoff.js +27 -0
- package/dist/claudeAccounts.d.ts +112 -0
- package/dist/claudeAccounts.js +234 -0
- package/dist/claudeSignIn.d.ts +62 -0
- package/dist/claudeSignIn.js +239 -0
- package/dist/contextRow.d.ts +25 -0
- package/dist/contextRow.js +16 -0
- package/dist/createPwCodeApi.d.ts +8 -0
- package/dist/createPwCodeApi.js +2 -0
- package/dist/howSessionsAppear.d.ts +12 -0
- package/dist/howSessionsAppear.js +24 -0
- package/dist/index.d.ts +24 -1
- package/dist/index.js +24 -2
- package/dist/locales/en/agentTranscript.js +2 -10
- package/dist/locales/en/agents.js +5 -5
- package/dist/locales/en.d.ts +5 -13
- package/dist/locales/es/agentTranscript.js +2 -10
- package/dist/locales/es/agents.js +5 -5
- package/dist/locales/ja/agentTranscript.js +2 -10
- package/dist/locales/ja/agents.js +5 -5
- package/dist/locales/ko/agentTranscript.js +2 -10
- package/dist/locales/ko/agents.js +5 -5
- package/dist/locales/zh/agentTranscript.js +2 -10
- package/dist/locales/zh/agents.js +5 -5
- package/dist/machine.d.ts +2 -0
- package/dist/models.d.ts +47 -0
- package/dist/models.js +49 -0
- package/dist/notices.d.ts +2 -1
- package/dist/notices.js +29 -3
- package/dist/pullRequestList.d.ts +52 -0
- package/dist/pullRequestList.js +106 -0
- package/dist/session.d.ts +5 -0
- package/dist/sessionActions.d.ts +105 -0
- package/dist/sessionActions.js +178 -0
- package/dist/sessionGroups.d.ts +49 -0
- package/dist/sessionGroups.js +72 -0
- package/dist/sessionHeader.d.ts +14 -0
- package/dist/sessionHeader.js +16 -0
- package/dist/sessionList.d.ts +134 -0
- package/dist/sessionList.js +271 -0
- package/dist/sessionsApi.js +2 -4
- package/dist/settingsApi.d.ts +36 -0
- package/dist/settingsApi.js +151 -0
- package/dist/startSession.d.ts +138 -0
- package/dist/startSession.js +234 -0
- package/dist/terminalHandoffPanel.d.ts +30 -0
- package/dist/terminalHandoffPanel.js +33 -0
- package/dist/transcript.d.ts +2 -0
- package/dist/transcript.js +15 -12
- package/dist/usageLimit.d.ts +8 -0
- package/dist/usageLimit.js +13 -0
- package/dist/useAwayRecap.d.ts +30 -0
- package/dist/useAwayRecap.js +75 -0
- package/dist/useComposer.d.ts +121 -0
- package/dist/useComposer.js +244 -0
- package/dist/useComposerImages.d.ts +66 -0
- package/dist/useComposerImages.js +195 -0
- package/dist/useConversation.d.ts +190 -0
- package/dist/useConversation.js +287 -0
- package/dist/useSubagent.d.ts +58 -0
- package/dist/useSubagent.js +149 -0
- package/dist/workingDirectories.d.ts +32 -0
- package/dist/workingDirectories.js +71 -0
- package/dist/worktreeChoice.d.ts +31 -0
- package/dist/worktreeChoice.js +38 -0
- package/locales/en/agentTranscript.json +2 -10
- package/locales/en/agents.json +5 -5
- package/locales/es/agentTranscript.json +2 -10
- package/locales/es/agents.json +5 -5
- package/locales/ja/agentTranscript.json +2 -10
- package/locales/ja/agents.json +5 -5
- package/locales/ko/agentTranscript.json +2 -10
- package/locales/ko/agents.json +5 -5
- package/locales/zh/agentTranscript.json +2 -10
- package/locales/zh/agents.json +5 -5
- package/package.json +3 -3
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { canStartHere, isMachineDown, splitMachines } from "./machine.js";
|
|
2
|
+
import { canRunModel, isClaudeModel, runsClaude } from "./models.js";
|
|
3
|
+
import { recentDirectories } from "./session.js";
|
|
4
|
+
import { rememberSentPrompt } from "./wording.js";
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { clampPermissionMode } from "@parallelworks/ui/ai/headless";
|
|
7
|
+
// src/startSession.ts
|
|
8
|
+
/** The machines a session can start on, then those listed but not answering,
|
|
9
|
+
* each with computers before resources. A resource with no agent on it is
|
|
10
|
+
* one the reader has not touched, so it is not counted as down. */
|
|
11
|
+
function startMachines(machines) {
|
|
12
|
+
const ordered = (list) => {
|
|
13
|
+
const { computers, resources } = splitMachines(list);
|
|
14
|
+
return [...computers, ...resources];
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
startable: ordered(machines.filter(canStartHere)),
|
|
18
|
+
down: ordered(machines.filter((m) => m.status !== "no_agent" && isMachineDown(m)))
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** clampPermissionMode falls to a machine's widest mode, which would turn auto
|
|
22
|
+
* into bypass on a machine too old for auto; capping at the mode itself first
|
|
23
|
+
* keeps the result from ever being wider than what was asked for. */
|
|
24
|
+
function startingMode(mode, machine) {
|
|
25
|
+
const accepted = machine?.permissionModes ?? void 0;
|
|
26
|
+
return clampPermissionMode(clampPermissionMode(mode, mode, accepted), machine?.remoteMaxPermissionMode, accepted);
|
|
27
|
+
}
|
|
28
|
+
function useStartLocation(machines, sessions) {
|
|
29
|
+
const { startable, down } = useMemo(() => startMachines(machines), [machines]);
|
|
30
|
+
const [machineId, setMachineId] = useState("");
|
|
31
|
+
const machine = startable.find((m) => m.id === machineId) ?? (startable.length === 1 ? startable[0] : void 0);
|
|
32
|
+
const directories = useMemo(() => recentDirectories(sessions, machine?.id), [sessions, machine]);
|
|
33
|
+
const [dir, setDir] = useState("");
|
|
34
|
+
const [typing, setTyping] = useState(false);
|
|
35
|
+
const settledOn = useRef(void 0);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (settledOn.current === machine?.id) return;
|
|
38
|
+
settledOn.current = machine?.id;
|
|
39
|
+
setDir("");
|
|
40
|
+
setTyping(false);
|
|
41
|
+
}, [machine?.id]);
|
|
42
|
+
const directory = typing ? dir : dir || directories[0]?.path || "";
|
|
43
|
+
const typeDirectory = (path) => {
|
|
44
|
+
setTyping(true);
|
|
45
|
+
setDir(path);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
startable,
|
|
49
|
+
down,
|
|
50
|
+
machine,
|
|
51
|
+
pickMachine: (id) => {
|
|
52
|
+
setMachineId(id);
|
|
53
|
+
setDir("");
|
|
54
|
+
setTyping(false);
|
|
55
|
+
},
|
|
56
|
+
directories,
|
|
57
|
+
directory,
|
|
58
|
+
typing,
|
|
59
|
+
pickDirectory: (path) => {
|
|
60
|
+
setDir(path);
|
|
61
|
+
setTyping(false);
|
|
62
|
+
},
|
|
63
|
+
typeDirectory,
|
|
64
|
+
typeOtherDirectory: () => typeDirectory(typing ? directory : "")
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The mode a session starts in: the one saved, or one picked on this visit,
|
|
68
|
+
* within what the machine allows. A pick holds until the visit ends, so one
|
|
69
|
+
* the host declines to save, such as bypass, still applies to this start. */
|
|
70
|
+
function useStartPermissionMode(preference, machine) {
|
|
71
|
+
const [picked, setPicked] = useState(null);
|
|
72
|
+
return {
|
|
73
|
+
mode: startingMode(picked ?? preference.saved, machine),
|
|
74
|
+
pick: (mode) => {
|
|
75
|
+
setPicked(mode);
|
|
76
|
+
preference.remember(mode);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function useRememberedAccount(api, machine, saved) {
|
|
81
|
+
const claudeReady = runsClaude(machine);
|
|
82
|
+
const names = api.useClaudeAccountNames(machine?.id ?? "", claudeReady && !!saved);
|
|
83
|
+
const listed = !names.data || names.data.some((a) => a.name === saved);
|
|
84
|
+
const { mutate } = names;
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (saved && !listed) mutate();
|
|
87
|
+
}, [
|
|
88
|
+
saved,
|
|
89
|
+
listed,
|
|
90
|
+
mutate
|
|
91
|
+
]);
|
|
92
|
+
return claudeReady && listed ? saved : void 0;
|
|
93
|
+
}
|
|
94
|
+
function useRememberedModel(api, machine, account, last, platformModels, handedOff) {
|
|
95
|
+
const claudeReady = runsClaude(machine);
|
|
96
|
+
const claudeModels = api.useClaudeModels(machine?.id ?? "", void 0, account, claudeReady && !handedOff && isClaudeModel(last.model));
|
|
97
|
+
return canRunModel(last.model, claudeReady, platformModels, claudeModels.data ?? void 0) && !handedOff ? last : null;
|
|
98
|
+
}
|
|
99
|
+
/** Picks hold for the machine they were made on. Until then a session starts
|
|
100
|
+
* on the model last picked where the machine and the platform still offer
|
|
101
|
+
* it, else on the host's selected one, and on the account saved for the
|
|
102
|
+
* machine where the machine still lists it. */
|
|
103
|
+
function useStartModel(api, { machine, platform, last, account: accountPreference, handedOff }) {
|
|
104
|
+
const [picked, setPicked] = useState(null);
|
|
105
|
+
const choice = picked?.machine === machine?.id ? picked : null;
|
|
106
|
+
const remembered = useRememberedAccount(api, machine, accountPreference.saved);
|
|
107
|
+
const account = choice?.account ?? remembered;
|
|
108
|
+
const lastModel = useRememberedModel(api, machine, account, last, platform.models, handedOff);
|
|
109
|
+
const pick = (change) => {
|
|
110
|
+
if (machine) setPicked({
|
|
111
|
+
...choice,
|
|
112
|
+
...change,
|
|
113
|
+
machine: machine.id
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
model: choice?.model ?? lastModel?.model ?? platform.model,
|
|
118
|
+
allocation: choice?.allocation ?? lastModel?.allocation ?? platform.allocation,
|
|
119
|
+
account,
|
|
120
|
+
pickedAccount: choice?.account,
|
|
121
|
+
pickModel: (model) => pick({ model }),
|
|
122
|
+
pickAllocation: (allocation) => pick({ allocation }),
|
|
123
|
+
pickAccount: (next) => {
|
|
124
|
+
pick({ account: next });
|
|
125
|
+
accountPreference.remember(next);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function sessionBody(machine, { directory, mode, model, effort, allocation, account }, prompt) {
|
|
130
|
+
return {
|
|
131
|
+
workspace: directory,
|
|
132
|
+
...model ? { model } : {},
|
|
133
|
+
...effort ? { effort } : {},
|
|
134
|
+
...!isClaudeModel(model) && allocation ? { allocation } : {},
|
|
135
|
+
...machine.claudeCodeAllowed && account ? { claudeAccount: account } : {},
|
|
136
|
+
permissionMode: mode,
|
|
137
|
+
...prompt ? { prompt } : {}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** The prompt, then each image it does not name already. */
|
|
141
|
+
function withPlaceholders(prompt, images) {
|
|
142
|
+
return [prompt, ...images.map((image) => image.placeholder).filter((placeholder) => !prompt.includes(placeholder))].filter(Boolean).join(" ");
|
|
143
|
+
}
|
|
144
|
+
/** Starts a session, reads the listing again so it shows there, and hands it
|
|
145
|
+
* to `onStarted` once its first prompt is sent. With images, the session is
|
|
146
|
+
* created first and they are saved with it; a retry after they fail reuses
|
|
147
|
+
* that session while nothing it started with has changed. */
|
|
148
|
+
function useStartSession(api, options) {
|
|
149
|
+
const { machine, directory, images, firstPrompt, onStarted } = options;
|
|
150
|
+
const { mutate } = api.useSessions();
|
|
151
|
+
const [starting, setStarting] = useState(false);
|
|
152
|
+
const [error, setError] = useState(null);
|
|
153
|
+
const pendingSession = useRef(null);
|
|
154
|
+
const config = JSON.stringify([
|
|
155
|
+
machine?.id,
|
|
156
|
+
directory,
|
|
157
|
+
options.mode,
|
|
158
|
+
options.model,
|
|
159
|
+
options.effort,
|
|
160
|
+
options.allocation,
|
|
161
|
+
options.account
|
|
162
|
+
]);
|
|
163
|
+
const ready = !!machine && directory.startsWith("/") && !starting && !options.waiting;
|
|
164
|
+
const started = (machineId, id, text) => {
|
|
165
|
+
rememberSentPrompt(machineId, id, text);
|
|
166
|
+
mutate();
|
|
167
|
+
onStarted(machineId, id);
|
|
168
|
+
};
|
|
169
|
+
/** The new session's id, or null once its refusal is kept. */
|
|
170
|
+
const create = async (on, prompt) => {
|
|
171
|
+
const { data, error: failed } = await api.createSession(on.id, sessionBody(on, options, prompt));
|
|
172
|
+
if (failed) {
|
|
173
|
+
setError(failed);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return data?.id || null;
|
|
177
|
+
};
|
|
178
|
+
const send = async (on, id, first) => {
|
|
179
|
+
const saved = images ? await images.saveTo(on.id, id) : [];
|
|
180
|
+
if (saved === null) return false;
|
|
181
|
+
const text = withPlaceholders(first, saved);
|
|
182
|
+
const { error: failed } = await api.sendMessage(on.id, id, {
|
|
183
|
+
text,
|
|
184
|
+
images: saved
|
|
185
|
+
});
|
|
186
|
+
if (failed) {
|
|
187
|
+
setError(failed);
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
started(on.id, id, text);
|
|
191
|
+
return true;
|
|
192
|
+
};
|
|
193
|
+
const attempt = async (on, prompt) => {
|
|
194
|
+
const pending = pendingSession.current?.config === config ? pendingSession.current.id : "";
|
|
195
|
+
const first = firstPrompt ? firstPrompt(prompt) : prompt;
|
|
196
|
+
const withImages = !!images?.count;
|
|
197
|
+
if (withImages) pendingSession.current = {
|
|
198
|
+
id: pending,
|
|
199
|
+
config
|
|
200
|
+
};
|
|
201
|
+
if (pending) return send(on, pending, first);
|
|
202
|
+
const id = await create(on, withImages ? "" : first);
|
|
203
|
+
if (!id) return false;
|
|
204
|
+
if (!withImages) {
|
|
205
|
+
started(on.id, id, first);
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
pendingSession.current = {
|
|
209
|
+
id,
|
|
210
|
+
config
|
|
211
|
+
};
|
|
212
|
+
return send(on, id, first);
|
|
213
|
+
};
|
|
214
|
+
const start = async (prompt) => {
|
|
215
|
+
if (!ready || !machine) return false;
|
|
216
|
+
setStarting(true);
|
|
217
|
+
setError(null);
|
|
218
|
+
try {
|
|
219
|
+
return await attempt(machine, prompt);
|
|
220
|
+
} catch (thrown) {
|
|
221
|
+
setError(thrown);
|
|
222
|
+
return false;
|
|
223
|
+
} finally {
|
|
224
|
+
setStarting(false);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
ready,
|
|
229
|
+
starting,
|
|
230
|
+
error,
|
|
231
|
+
start
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
export { startMachines, startingMode, useStartLocation, useStartModel, useStartPermissionMode, useStartSession };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type PwCodeMachine, type TerminalHandoff } from './machine.js';
|
|
2
|
+
import type { PwCodeTranslator } from './messages.js';
|
|
3
|
+
import { type PwCodeSession } from './session.js';
|
|
4
|
+
/** What picking a session up in a terminal shows: a note until its machine
|
|
5
|
+
* is listed, then the command to copy and what running it does. */
|
|
6
|
+
export type TerminalHandoffPanel = {
|
|
7
|
+
status: 'loading' | 'missing';
|
|
8
|
+
note: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: 'ready';
|
|
11
|
+
handoff: TerminalHandoff;
|
|
12
|
+
/** What running the command does, and where. */
|
|
13
|
+
body: string;
|
|
14
|
+
/** What the copied command is announced as. */
|
|
15
|
+
commandLabel: string;
|
|
16
|
+
/** That a resource's session picks up from any terminal signed in to pw. */
|
|
17
|
+
anyTerminal: string | undefined;
|
|
18
|
+
/** That picking an archived session up restores it. */
|
|
19
|
+
archived: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
export declare function terminalHandoffPanel(listing: {
|
|
22
|
+
machines?: readonly PwCodeMachine[] | null | undefined;
|
|
23
|
+
sessions?: readonly Pick<PwCodeSession, 'machineId' | 'id' | 'archivedAt'>[] | null | undefined;
|
|
24
|
+
} | undefined, machine: string, sessionId: string, username: string | undefined, t: PwCodeTranslator<'agents'>): TerminalHandoffPanel;
|
|
25
|
+
/** A handoff command split before the session it names, which a narrow
|
|
26
|
+
* panel keeps whole rather than breaking at a hyphen in its id. */
|
|
27
|
+
export declare function handoffCommandParts(command: string): {
|
|
28
|
+
head: string;
|
|
29
|
+
session: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { terminalHandoff } from "./machine.js";
|
|
2
|
+
import { isArchived, isSession } from "./session.js";
|
|
3
|
+
// src/terminalHandoffPanel.ts
|
|
4
|
+
function terminalHandoffPanel(listing, machine, sessionId, username, t) {
|
|
5
|
+
const found = listing?.machines?.find((m) => m.id === machine);
|
|
6
|
+
if (!found) return listing ? {
|
|
7
|
+
status: "missing",
|
|
8
|
+
note: t("terminal.machineMissing")
|
|
9
|
+
} : {
|
|
10
|
+
status: "loading",
|
|
11
|
+
note: t("terminal.machineLoading")
|
|
12
|
+
};
|
|
13
|
+
const session = listing?.sessions?.find((s) => isSession(s, machine, sessionId));
|
|
14
|
+
const handoff = terminalHandoff(found, sessionId, username);
|
|
15
|
+
return {
|
|
16
|
+
status: "ready",
|
|
17
|
+
handoff,
|
|
18
|
+
body: handoff.on === "resource" ? t("terminal.resourceBody", { machine: found.name }) : t("terminal.computerBody", { host: handoff.host }),
|
|
19
|
+
commandLabel: t("terminal.commandLabel"),
|
|
20
|
+
anyTerminal: handoff.on === "resource" ? t("terminal.anyTerminal") : void 0,
|
|
21
|
+
archived: session && isArchived(session) ? t("terminal.archived") : void 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** A handoff command split before the session it names, which a narrow
|
|
25
|
+
* panel keeps whole rather than breaking at a hyphen in its id. */
|
|
26
|
+
function handoffCommandParts(command) {
|
|
27
|
+
const at = command.lastIndexOf(" ") + 1;
|
|
28
|
+
return {
|
|
29
|
+
head: command.slice(0, at),
|
|
30
|
+
session: command.slice(at)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { handoffCommandParts, terminalHandoffPanel };
|
package/dist/transcript.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ export interface TranscriptWords {
|
|
|
126
126
|
deliveryLine: (notice: SubagentNotice) => string;
|
|
127
127
|
/** An approval's option that opens the directory it names for the session. */
|
|
128
128
|
allowDirectory: (dir: PwCodeAllowedDirectory) => string;
|
|
129
|
+
/** Who wrote a subagent's prompt: the conversation that started it. */
|
|
130
|
+
mainConversation: string;
|
|
129
131
|
}
|
|
130
132
|
/** The verb the terminal picks for a turn, so the same turn reads the same in both. */
|
|
131
133
|
export declare function turnVerb(endedAt: string): TurnVerb;
|
package/dist/transcript.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { DateTime } from "luxon";
|
|
2
2
|
import { INTERRUPTED_NOTICE, applyPartDelta, askQuestionsFromArgs, classifyPseudoUserMessage, finalizeParts, firstNonEmptyLine, hiddenTranscriptTool, interruptionNotice, parseSubagentNotice, planFromArgs, resultFailed, subagentDeliveryLine, taskCallFromArgs } from "@parallelworks/ui/ai/headless";
|
|
3
3
|
// src/transcript.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
function mainConversationAuthor(words) {
|
|
5
|
+
return {
|
|
6
|
+
id: "main",
|
|
7
|
+
username: "main session",
|
|
8
|
+
name: words?.mainConversation ?? "Main conversation"
|
|
9
|
+
};
|
|
10
|
+
}
|
|
8
11
|
var synthCounter = 0;
|
|
9
12
|
function synthId(prefix) {
|
|
10
13
|
synthCounter += 1;
|
|
11
14
|
return `${prefix}-${synthCounter}`;
|
|
12
15
|
}
|
|
13
|
-
function userMessage(text,
|
|
16
|
+
function userMessage(text, author, id, pastes, images, imageUrl) {
|
|
14
17
|
const pseudo = classifyPseudoUserMessage("user", text);
|
|
15
18
|
const attachments = imageAttachments(images, imageUrl);
|
|
16
19
|
return {
|
|
@@ -18,7 +21,7 @@ function userMessage(text, fromMain, id, pastes, images, imageUrl) {
|
|
|
18
21
|
role: "user",
|
|
19
22
|
content: text,
|
|
20
23
|
...pseudo ? { pseudo } : {},
|
|
21
|
-
...
|
|
24
|
+
...author ? { author } : {},
|
|
22
25
|
...pastes?.length ? { pastes } : {},
|
|
23
26
|
...attachments.length ? { attachments } : {}
|
|
24
27
|
};
|
|
@@ -208,7 +211,7 @@ function historyToMessages(history, options = {}) {
|
|
|
208
211
|
}
|
|
209
212
|
flush(true);
|
|
210
213
|
messages.push({
|
|
211
|
-
...userMessage(command,
|
|
214
|
+
...userMessage(command, void 0, `h-u-${index}`),
|
|
212
215
|
commandAnswer: answer
|
|
213
216
|
});
|
|
214
217
|
};
|
|
@@ -236,7 +239,7 @@ function historyToMessages(history, options = {}) {
|
|
|
236
239
|
append(shellRunPart(shell.command, shell.output), index);
|
|
237
240
|
return;
|
|
238
241
|
}
|
|
239
|
-
messages.push(userMessage(item.text ?? "", item.fromMain
|
|
242
|
+
messages.push(userMessage(item.text ?? "", item.fromMain ? mainConversationAuthor(words) : void 0, `h-u-${index}`, item.pastes, item.images, options.imageUrl));
|
|
240
243
|
return;
|
|
241
244
|
}
|
|
242
245
|
case "assistant": {
|
|
@@ -574,7 +577,7 @@ function resolveApprovalEverywhere(state, id) {
|
|
|
574
577
|
* short, so the page must not close the turn either: its open tool calls
|
|
575
578
|
* would read as interrupted while they are still running. */
|
|
576
579
|
function appendOwnMessage(state, text, id, pastes, previews) {
|
|
577
|
-
const message = userMessage(text,
|
|
580
|
+
const message = userMessage(text, void 0, id, pastes, previews);
|
|
578
581
|
if (turnRunning(state)) return {
|
|
579
582
|
...state,
|
|
580
583
|
queued: [...state.queued, message]
|
|
@@ -611,7 +614,7 @@ function withSentPastesAndImages(messages, ev, id, imageUrl) {
|
|
|
611
614
|
function appendSteeredMessage(state, text, id, pastes, previews) {
|
|
612
615
|
return {
|
|
613
616
|
...state,
|
|
614
|
-
steered: [...state.steered, userMessage(text,
|
|
617
|
+
steered: [...state.steered, userMessage(text, void 0, id, pastes, previews)]
|
|
615
618
|
};
|
|
616
619
|
}
|
|
617
620
|
/** The daemon queued a message this page had shown as sent, because the turn
|
|
@@ -1125,7 +1128,7 @@ function noteHandedOver(state, id, ev, imageUrl) {
|
|
|
1125
1128
|
return {
|
|
1126
1129
|
...state,
|
|
1127
1130
|
steered,
|
|
1128
|
-
notes: note ? withSentPastesAndImages([...state.notes, note], ev, note.id, imageUrl) : [...state.notes, userMessage(text,
|
|
1131
|
+
notes: note ? withSentPastesAndImages([...state.notes, note], ev, note.id, imageUrl) : [...state.notes, userMessage(text, void 0, void 0, ev.pastes, ev.images, imageUrl)]
|
|
1129
1132
|
};
|
|
1130
1133
|
}
|
|
1131
1134
|
function nowIso() {
|
|
@@ -1248,7 +1251,7 @@ function applyStreamEvent(state, ev, options = {}) {
|
|
|
1248
1251
|
next = finishTurn(next);
|
|
1249
1252
|
next = ownEcho ? takeEcho(next, options.echoOf, ev, options.imageUrl) : {
|
|
1250
1253
|
...next,
|
|
1251
|
-
messages: [...next.messages, userMessage(ev.content ?? "",
|
|
1254
|
+
messages: [...next.messages, userMessage(ev.content ?? "", void 0, void 0, ev.pastes, ev.images, options.imageUrl)]
|
|
1252
1255
|
};
|
|
1253
1256
|
next = {
|
|
1254
1257
|
...next,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface UsageLimitWait {
|
|
2
|
+
/** That the turn waits for the limit to reset, and when once that is known. */
|
|
3
|
+
waiting: string;
|
|
4
|
+
/** What offers another Claude Code account, which takes the turn over at once. */
|
|
5
|
+
switchAccount: string;
|
|
6
|
+
}
|
|
7
|
+
/** The running turn's line while it waits for a usage limit to reset. */
|
|
8
|
+
export declare function useUsageLimitWait(resumeAt: string | null | undefined): UsageLimitWait;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
2
|
+
import { useResumeTime } from "./notices.js";
|
|
3
|
+
// src/usageLimit.ts
|
|
4
|
+
/** The running turn's line while it waits for a usage limit to reset. */
|
|
5
|
+
function useUsageLimitWait(resumeAt) {
|
|
6
|
+
const t = usePwCodeTranslations("agents");
|
|
7
|
+
const resumeTime = useResumeTime();
|
|
8
|
+
return {
|
|
9
|
+
waiting: resumeAt ? t("detail.waitingForUsageLimitUntil", { time: resumeTime(resumeAt) }) : t("detail.waitingForUsageLimit"),
|
|
10
|
+
switchAccount: t("detail.switchClaudeAccount")
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export { useUsageLimitWait };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
2
|
+
export declare const recapAfterTurnMs: number;
|
|
3
|
+
export declare const recapAfterLeavingMs = 2000;
|
|
4
|
+
/** Whether the reader has the session in front of them, as the host's app knows it. */
|
|
5
|
+
export interface PwCodePresence {
|
|
6
|
+
/** Whether the reader is away: the app is out of sight or out of focus. */
|
|
7
|
+
away: () => boolean;
|
|
8
|
+
/** Calls `leave` when the reader may have left and `back` when they may
|
|
9
|
+
* have come back, until the returned call. Each reads `away` itself. */
|
|
10
|
+
watch: (on: {
|
|
11
|
+
leave: () => void;
|
|
12
|
+
back: () => void;
|
|
13
|
+
}) => () => void;
|
|
14
|
+
}
|
|
15
|
+
/** Has the session recapped while the reader is away from it, as pw code
|
|
16
|
+
* does while its terminal is out of focus, so the recap is waiting when they
|
|
17
|
+
* come back. The machine declines while its recaps are off. */
|
|
18
|
+
export declare function useAwayRecap({ api, machine, sessionId, turnEndSeq, idle, drafting, presence, }: {
|
|
19
|
+
api: Pick<PwCodeApi, 'requestRecap'>;
|
|
20
|
+
machine: string;
|
|
21
|
+
sessionId: string;
|
|
22
|
+
/** Changes each time the reader's view sees a main turn end. */
|
|
23
|
+
turnEndSeq: number | undefined;
|
|
24
|
+
/** Whether the session rests between turns and can be reached; read when the wait ends. */
|
|
25
|
+
idle: boolean;
|
|
26
|
+
/** Whether a message is being typed: nothing is asked for over one. Read when the wait ends. */
|
|
27
|
+
drafting: () => boolean;
|
|
28
|
+
/** Read when the session opens and whenever it is asked again. */
|
|
29
|
+
presence: PwCodePresence;
|
|
30
|
+
}): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import { DateTime } from "luxon";
|
|
3
|
+
// src/useAwayRecap.ts
|
|
4
|
+
var recapAfterTurnMs = 12e4;
|
|
5
|
+
var recapAfterLeavingMs = 2e3;
|
|
6
|
+
function nowMs() {
|
|
7
|
+
return DateTime.now().toMillis();
|
|
8
|
+
}
|
|
9
|
+
/** Has the session recapped while the reader is away from it, as pw code
|
|
10
|
+
* does while its terminal is out of focus, so the recap is waiting when they
|
|
11
|
+
* come back. The machine declines while its recaps are off. */
|
|
12
|
+
function useAwayRecap({ api, machine, sessionId, turnEndSeq, idle, drafting, presence }) {
|
|
13
|
+
const idleRef = useRef(idle);
|
|
14
|
+
idleRef.current = idle;
|
|
15
|
+
const draftingRef = useRef(drafting);
|
|
16
|
+
draftingRef.current = drafting;
|
|
17
|
+
const presenceRef = useRef(presence);
|
|
18
|
+
presenceRef.current = presence;
|
|
19
|
+
const apiRef = useRef(api);
|
|
20
|
+
apiRef.current = api;
|
|
21
|
+
const turnEndedAt = useRef(null);
|
|
22
|
+
const counted = useRef(void 0);
|
|
23
|
+
const leftAt = useRef(null);
|
|
24
|
+
const timer = useRef(void 0);
|
|
25
|
+
const request = useRef(null);
|
|
26
|
+
const ask = useCallback(async () => {
|
|
27
|
+
if (request.current || !presenceRef.current.away() || !idleRef.current || draftingRef.current()) return;
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
request.current = controller;
|
|
30
|
+
await apiRef.current.requestRecap(machine, sessionId, controller.signal).catch(() => void 0);
|
|
31
|
+
if (request.current === controller) request.current = null;
|
|
32
|
+
}, [machine, sessionId]);
|
|
33
|
+
const arm = useCallback(() => {
|
|
34
|
+
clearTimeout(timer.current);
|
|
35
|
+
const ended = turnEndedAt.current;
|
|
36
|
+
const left = leftAt.current;
|
|
37
|
+
if (ended === null || left === null) return;
|
|
38
|
+
const now = nowMs();
|
|
39
|
+
const wait = Math.max(ended + recapAfterTurnMs - now, left + recapAfterLeavingMs - now);
|
|
40
|
+
timer.current = setTimeout(() => void ask(), wait);
|
|
41
|
+
}, [ask]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const away = () => presenceRef.current.away();
|
|
44
|
+
leftAt.current = away() ? nowMs() : null;
|
|
45
|
+
const leave = () => {
|
|
46
|
+
if (leftAt.current === null && away()) {
|
|
47
|
+
leftAt.current = nowMs();
|
|
48
|
+
arm();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const back = () => {
|
|
52
|
+
if (!away()) {
|
|
53
|
+
leftAt.current = null;
|
|
54
|
+
clearTimeout(timer.current);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const unwatch = presenceRef.current.watch({
|
|
58
|
+
leave,
|
|
59
|
+
back
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
unwatch();
|
|
63
|
+
clearTimeout(timer.current);
|
|
64
|
+
request.current?.abort();
|
|
65
|
+
request.current = null;
|
|
66
|
+
};
|
|
67
|
+
}, [arm]);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (turnEndSeq === void 0 || turnEndSeq === counted.current) return;
|
|
70
|
+
counted.current = turnEndSeq;
|
|
71
|
+
turnEndedAt.current = nowMs();
|
|
72
|
+
arm();
|
|
73
|
+
}, [turnEndSeq, arm]);
|
|
74
|
+
}
|
|
75
|
+
export { recapAfterLeavingMs, recapAfterTurnMs, useAwayRecap };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { MessagePaste } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import type { Schemas } from './apiClient.js';
|
|
3
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
4
|
+
import type { PwCodeConversation } from './useConversation.js';
|
|
5
|
+
import type { PwCodeTakenImages } from './useComposerImages.js';
|
|
6
|
+
/** The composer's history of sent prompts, as `@parallelworks/ui/ai`'s
|
|
7
|
+
* `ComposerHistory` takes it. */
|
|
8
|
+
export interface PwCodeComposerHistory {
|
|
9
|
+
/** Composers with the same name share one history. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Text to forget, such as a command carrying a secret. */
|
|
12
|
+
skip?: ((text: string) => boolean) | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** Per person, since someone else can sign in where the history is kept, and
|
|
15
|
+
* without `/auth`, which can carry a key. */
|
|
16
|
+
export declare function promptHistory(username: string): PwCodeComposerHistory;
|
|
17
|
+
/** What a command printed, shown below the transcript under the command as typed. */
|
|
18
|
+
export interface PwCodeCommandOutput {
|
|
19
|
+
id: number;
|
|
20
|
+
command: string;
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function useCommandOutputs(): {
|
|
24
|
+
outputs: PwCodeCommandOutput[];
|
|
25
|
+
add: (command: string, text: string) => void;
|
|
26
|
+
dismiss: (id: number) => void;
|
|
27
|
+
clear: () => void;
|
|
28
|
+
};
|
|
29
|
+
/** What the reader can do from an open session's composer, and how the
|
|
30
|
+
* session stands for it: what is typed goes out as a message, a direction to
|
|
31
|
+
* the running turn, a command or a `!` shell run, and the composer locks
|
|
32
|
+
* while the machine is unreachable, the session is archived or live
|
|
33
|
+
* elsewhere, or it waits on an approval. */
|
|
34
|
+
export declare function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo, feed, staleFor, images, handleLocally, notify, onCleared, onArchived, }: {
|
|
35
|
+
api: PwCodeApi;
|
|
36
|
+
machine: string;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
/** What `usePwCodeConversation` returned for the session. */
|
|
39
|
+
conversation: PwCodeConversation;
|
|
40
|
+
/** The session's machine, as `api.useMachine` reads it. */
|
|
41
|
+
machineInfo: Schemas['AgentMachine'] | undefined;
|
|
42
|
+
/** The session's feed, as `api.useSessionEvents` reports it. */
|
|
43
|
+
feed: {
|
|
44
|
+
connected: boolean;
|
|
45
|
+
disconnected: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** How long ago the transcript was last read, already abbreviated: see `useLastReadAt`. */
|
|
48
|
+
staleFor: string;
|
|
49
|
+
/** The images waiting to go with the next message, as `useComposerImages` holds them. */
|
|
50
|
+
images?: {
|
|
51
|
+
take: () => Promise<PwCodeTakenImages>;
|
|
52
|
+
taking: boolean;
|
|
53
|
+
} | undefined;
|
|
54
|
+
/** Typed text the host acts on itself, such as a command that opens one of
|
|
55
|
+
* its own panels; true takes it, sending nothing. */
|
|
56
|
+
handleLocally?: ((typed: string) => boolean) | undefined;
|
|
57
|
+
/** Tells the reader something in passing, such as in a toast. */
|
|
58
|
+
notify: (text: string) => void;
|
|
59
|
+
/** Shows the session `/clear` started in place of this one. */
|
|
60
|
+
onCleared: (newId: string) => void;
|
|
61
|
+
/** Leaves the session `/archive` archived. */
|
|
62
|
+
onArchived: () => void;
|
|
63
|
+
}): {
|
|
64
|
+
/** Sends what was typed; false hands it back to the composer. */
|
|
65
|
+
send: (typed: string, pastes?: MessagePaste[]) => Promise<boolean>;
|
|
66
|
+
turn: {
|
|
67
|
+
running: boolean;
|
|
68
|
+
stop: () => Promise<void>;
|
|
69
|
+
stopping: boolean;
|
|
70
|
+
};
|
|
71
|
+
composer: {
|
|
72
|
+
placeholder: string;
|
|
73
|
+
hint: string;
|
|
74
|
+
locked: boolean;
|
|
75
|
+
disabled: boolean;
|
|
76
|
+
};
|
|
77
|
+
/** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
|
|
78
|
+
sessionLock: {
|
|
79
|
+
placeholder: string;
|
|
80
|
+
hint: string;
|
|
81
|
+
locked: boolean;
|
|
82
|
+
} | null;
|
|
83
|
+
shellRun: string | null;
|
|
84
|
+
outputs: PwCodeCommandOutput[];
|
|
85
|
+
dismissOutput: (id: number) => void;
|
|
86
|
+
palette: {
|
|
87
|
+
commands: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
|
|
88
|
+
mcpPrompts: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
|
|
89
|
+
prompts: string[] | null;
|
|
90
|
+
} | null;
|
|
91
|
+
paletteLoading: boolean;
|
|
92
|
+
/** Opens the command menu, which asks for the session's palette again. */
|
|
93
|
+
openPalette: () => undefined;
|
|
94
|
+
loadPalette: () => Promise<{
|
|
95
|
+
commands: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
|
|
96
|
+
mcpPrompts: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
|
|
97
|
+
prompts: string[] | null;
|
|
98
|
+
} | null>;
|
|
99
|
+
status: import("./types.js").PwCodeSessionStatus | null;
|
|
100
|
+
approvals: {
|
|
101
|
+
kind: "ask" | "confirm" | "plan";
|
|
102
|
+
}[] | null | undefined;
|
|
103
|
+
unreachable: boolean;
|
|
104
|
+
reconnecting: boolean;
|
|
105
|
+
archived: boolean;
|
|
106
|
+
machineName: string;
|
|
107
|
+
/** A turn is under way on a machine that answers. */
|
|
108
|
+
working: boolean;
|
|
109
|
+
checkingGoal: boolean;
|
|
110
|
+
/** The session rests between turns and can be reached. */
|
|
111
|
+
idle: boolean;
|
|
112
|
+
/** Ends the transcript while the machine cannot be reached. */
|
|
113
|
+
endNote: string | undefined;
|
|
114
|
+
/** The offer to move the Bash commands the turn waits on to the background. */
|
|
115
|
+
background: {
|
|
116
|
+
offered: boolean;
|
|
117
|
+
moving: boolean;
|
|
118
|
+
move: () => Promise<void>;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export type PwCodeComposer = ReturnType<typeof usePwCodeComposer>;
|