@parallelworks/code 0.1.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 +171 -24
- package/dist/ago.d.ts +8 -0
- package/dist/ago.js +26 -0
- package/dist/api.d.ts +3547 -0
- package/dist/apiClient.d.ts +26 -0
- package/dist/apiClient.js +5 -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/claudeApi.d.ts +27 -0
- package/dist/claudeApi.js +250 -0
- package/dist/claudeSignIn.d.ts +62 -0
- package/dist/claudeSignIn.js +239 -0
- package/dist/command.d.ts +47 -0
- package/dist/command.js +64 -0
- package/dist/commandsApi.d.ts +64 -0
- package/dist/commandsApi.js +267 -0
- package/dist/contextRow.d.ts +25 -0
- package/dist/contextRow.js +16 -0
- package/dist/createPwCodeApi.d.ts +696 -0
- package/dist/createPwCodeApi.js +33 -0
- package/dist/howSessionsAppear.d.ts +12 -0
- package/dist/howSessionsAppear.js +24 -0
- package/dist/index.d.ts +39 -3
- package/dist/index.js +38 -3
- package/dist/locales/en/agentTranscript.js +162 -0
- package/dist/locales/en/agents.js +380 -0
- package/dist/locales/en.d.ts +523 -0
- package/dist/locales/en.js +8 -0
- package/dist/locales/es/agentTranscript.js +162 -0
- package/dist/locales/es/agents.js +380 -0
- package/dist/locales/es.d.ts +3 -0
- package/dist/locales/es.js +8 -0
- package/dist/locales/ja/agentTranscript.js +162 -0
- package/dist/locales/ja/agents.js +380 -0
- package/dist/locales/ja.d.ts +3 -0
- package/dist/locales/ja.js +8 -0
- package/dist/locales/ko/agentTranscript.js +162 -0
- package/dist/locales/ko/agents.js +380 -0
- package/dist/locales/ko.d.ts +3 -0
- package/dist/locales/ko.js +8 -0
- package/dist/locales/zh/agentTranscript.js +162 -0
- package/dist/locales/zh/agents.js +380 -0
- package/dist/locales/zh.d.ts +3 -0
- package/dist/locales/zh.js +8 -0
- package/dist/machine.d.ts +51 -0
- package/dist/machine.js +60 -0
- package/dist/messages.d.ts +17 -0
- package/dist/messages.js +31 -0
- package/dist/models.d.ts +47 -0
- package/dist/models.js +49 -0
- package/dist/notices.d.ts +12 -0
- package/dist/notices.js +120 -0
- package/dist/pullRequest.d.ts +8 -0
- package/dist/pullRequest.js +29 -0
- package/dist/pullRequestList.d.ts +52 -0
- package/dist/pullRequestList.js +106 -0
- package/dist/query.d.ts +28 -0
- package/dist/query.js +25 -0
- package/dist/session.d.ts +75 -1
- package/dist/session.js +101 -1
- package/dist/sessionActions.d.ts +105 -0
- package/dist/sessionActions.js +178 -0
- package/dist/sessionEvents.d.ts +27 -0
- package/dist/sessionEvents.js +212 -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.d.ts +105 -0
- package/dist/sessionsApi.js +511 -0
- 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/toolStrings.d.ts +4 -0
- package/dist/toolStrings.js +95 -0
- package/dist/transcript.d.ts +14 -1
- package/dist/transcript.js +55 -14
- package/dist/types.d.ts +20 -1
- 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/useTranscript.d.ts +4 -1
- package/dist/useTranscript.js +54 -11
- package/dist/wording.d.ts +43 -0
- package/dist/wording.js +101 -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 +154 -0
- package/locales/en/agents.json +366 -0
- package/locales/es/agentTranscript.json +154 -0
- package/locales/es/agents.json +366 -0
- package/locales/ja/agentTranscript.json +154 -0
- package/locales/ja/agents.json +366 -0
- package/locales/ko/agentTranscript.json +154 -0
- package/locales/ko/agents.json +366 -0
- package/locales/zh/agentTranscript.json +154 -0
- package/locales/zh/agents.json +366 -0
- package/package.json +24 -9
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type EffortLevel, type PermissionMode } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
3
|
+
import { type PwCodeMachine } from './machine.js';
|
|
4
|
+
import { type PwCodeSession, type RecentDirectory } from './session.js';
|
|
5
|
+
import type { PwCodeImageRef } from './types.js';
|
|
6
|
+
/** A machine as far as starting a session on it reads it. */
|
|
7
|
+
export interface PwCodeStartMachine extends PwCodeMachine {
|
|
8
|
+
/** The widest mode its owner lets a session started from another client run in. */
|
|
9
|
+
remoteMaxPermissionMode?: string | undefined;
|
|
10
|
+
/** The modes its pw code takes; one that lists none predates auto. */
|
|
11
|
+
permissionModes?: readonly string[] | null | undefined;
|
|
12
|
+
claudeInstalled?: boolean | undefined;
|
|
13
|
+
claudeCodeAllowed?: boolean | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** The machines a session can start on, then those listed but not answering,
|
|
16
|
+
* each with computers before resources. A resource with no agent on it is
|
|
17
|
+
* one the reader has not touched, so it is not counted as down. */
|
|
18
|
+
export declare function startMachines<M extends PwCodeStartMachine>(machines: readonly M[]): {
|
|
19
|
+
startable: M[];
|
|
20
|
+
down: M[];
|
|
21
|
+
};
|
|
22
|
+
/** clampPermissionMode falls to a machine's widest mode, which would turn auto
|
|
23
|
+
* into bypass on a machine too old for auto; capping at the mode itself first
|
|
24
|
+
* keeps the result from ever being wider than what was asked for. */
|
|
25
|
+
export declare function startingMode(mode: PermissionMode, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): PermissionMode;
|
|
26
|
+
/** Where a session starts: the machine, and the directory on it. */
|
|
27
|
+
export interface PwCodeStartLocation<M> {
|
|
28
|
+
/** The machines a session can start on, computers first. */
|
|
29
|
+
startable: M[];
|
|
30
|
+
/** The machines listed but not answering, computers first, so a missing one can be traced. */
|
|
31
|
+
down: M[];
|
|
32
|
+
/** The machine picked, or the only one a session can start on. */
|
|
33
|
+
machine: M | undefined;
|
|
34
|
+
pickMachine: (id: string) => void;
|
|
35
|
+
/** The directories the machine's sessions worked in, newest first. */
|
|
36
|
+
directories: RecentDirectory[];
|
|
37
|
+
/** The directory picked or typed, or else the newest one. */
|
|
38
|
+
directory: string;
|
|
39
|
+
/** The directory is typed rather than picked from the recent ones. */
|
|
40
|
+
typing: boolean;
|
|
41
|
+
pickDirectory: (path: string) => void;
|
|
42
|
+
typeDirectory: (path: string) => void;
|
|
43
|
+
/** Turns to typing a directory, keeping what was typed so far. */
|
|
44
|
+
typeOtherDirectory: () => void;
|
|
45
|
+
}
|
|
46
|
+
export declare function useStartLocation<M extends PwCodeStartMachine>(machines: readonly M[], sessions: readonly Pick<PwCodeSession, 'machineId' | 'workspace' | 'updatedAt'>[]): PwCodeStartLocation<M>;
|
|
47
|
+
/** The mode a session starts in: the one saved, or one picked on this visit,
|
|
48
|
+
* within what the machine allows. A pick holds until the visit ends, so one
|
|
49
|
+
* the host declines to save, such as bypass, still applies to this start. */
|
|
50
|
+
export declare function useStartPermissionMode(preference: {
|
|
51
|
+
saved: PermissionMode;
|
|
52
|
+
remember: (mode: PermissionMode) => void;
|
|
53
|
+
}, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): {
|
|
54
|
+
mode: PermissionMode;
|
|
55
|
+
pick: (mode: PermissionMode) => void;
|
|
56
|
+
};
|
|
57
|
+
type ClaudeMachine = Pick<PwCodeStartMachine, 'id' | 'claudeInstalled' | 'claudeCodeAllowed'>;
|
|
58
|
+
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'useSessions'>;
|
|
59
|
+
/** A model last picked for a session, and the allocation that billed it. */
|
|
60
|
+
export interface PwCodeLastModel {
|
|
61
|
+
model?: string | undefined;
|
|
62
|
+
allocation?: string | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** The model, allocation and Claude Code account a session starts on. */
|
|
65
|
+
export interface PwCodeStartModel {
|
|
66
|
+
model: string | null | undefined;
|
|
67
|
+
allocation: string | null | undefined;
|
|
68
|
+
account: string | undefined;
|
|
69
|
+
/** The account picked on this visit, rather than one remembered. */
|
|
70
|
+
pickedAccount: string | undefined;
|
|
71
|
+
pickModel: (model: string) => void;
|
|
72
|
+
pickAllocation: (allocation: string) => void;
|
|
73
|
+
/** Picks the account and remembers it for the machine. */
|
|
74
|
+
pickAccount: (account: string) => void;
|
|
75
|
+
}
|
|
76
|
+
/** Picks hold for the machine they were made on. Until then a session starts
|
|
77
|
+
* on the model last picked where the machine and the platform still offer
|
|
78
|
+
* it, else on the host's selected one, and on the account saved for the
|
|
79
|
+
* machine where the machine still lists it. */
|
|
80
|
+
export declare function useStartModel(api: Pick<StartApi, 'useClaudeModels' | 'useClaudeAccountNames'>, { machine, platform, last, account: accountPreference, handedOff, }: {
|
|
81
|
+
machine: ClaudeMachine | undefined;
|
|
82
|
+
platform: {
|
|
83
|
+
/** The platform's models: undefined while they load, or when they failed to. */
|
|
84
|
+
models: readonly {
|
|
85
|
+
id: string;
|
|
86
|
+
}[] | undefined;
|
|
87
|
+
/** The host's selected model and allocation. */
|
|
88
|
+
model: string | null | undefined;
|
|
89
|
+
allocation: string | null | undefined;
|
|
90
|
+
};
|
|
91
|
+
last: PwCodeLastModel;
|
|
92
|
+
/** The Claude Code account saved for this machine. */
|
|
93
|
+
account: {
|
|
94
|
+
saved: string | undefined;
|
|
95
|
+
remember: (account: string) => void;
|
|
96
|
+
};
|
|
97
|
+
/** A chat handed off to the session, which keeps the host's selected model. */
|
|
98
|
+
handedOff: boolean;
|
|
99
|
+
}): PwCodeStartModel;
|
|
100
|
+
/** Images that wait to go with a session's first prompt. */
|
|
101
|
+
export interface PwCodeStartImages {
|
|
102
|
+
count: number;
|
|
103
|
+
/** Saves them with the session; null when one could not be saved, which
|
|
104
|
+
* the host reports. */
|
|
105
|
+
saveTo: (machine: string, sessionId: string) => Promise<PwCodeImageRef[] | null>;
|
|
106
|
+
}
|
|
107
|
+
export interface PwCodeStartSession {
|
|
108
|
+
/** A machine and an absolute directory are chosen, and nothing holds the start back. */
|
|
109
|
+
ready: boolean;
|
|
110
|
+
starting: boolean;
|
|
111
|
+
/** Why the last start failed: the machine's refusal, or what was thrown. */
|
|
112
|
+
error: unknown;
|
|
113
|
+
/** Starts the session with `prompt` as its first message. False hands the
|
|
114
|
+
* prompt back to the composer. */
|
|
115
|
+
start: (prompt: string) => Promise<boolean>;
|
|
116
|
+
}
|
|
117
|
+
/** Starts a session, reads the listing again so it shows there, and hands it
|
|
118
|
+
* to `onStarted` once its first prompt is sent. With images, the session is
|
|
119
|
+
* created first and they are saved with it; a retry after they fail reuses
|
|
120
|
+
* that session while nothing it started with has changed. */
|
|
121
|
+
export declare function useStartSession(api: Pick<StartApi, 'createSession' | 'sendMessage' | 'useSessions'>, options: {
|
|
122
|
+
machine: Pick<PwCodeStartMachine, 'id' | 'claudeCodeAllowed'> | undefined;
|
|
123
|
+
directory: string;
|
|
124
|
+
mode: PermissionMode;
|
|
125
|
+
model: string | null | undefined;
|
|
126
|
+
/** Empty starts at the machine's own level. */
|
|
127
|
+
effort: EffortLevel | '';
|
|
128
|
+
allocation: string | null | undefined;
|
|
129
|
+
account: string | undefined;
|
|
130
|
+
images?: PwCodeStartImages | undefined;
|
|
131
|
+
/** The first message to send for what the reader typed. */
|
|
132
|
+
firstPrompt?: ((typed: string) => string) | undefined;
|
|
133
|
+
/** Something the first message needs has not arrived yet. */
|
|
134
|
+
waiting?: boolean | undefined;
|
|
135
|
+
/** The host opens the session. */
|
|
136
|
+
onStarted: (machine: string, sessionId: string) => void;
|
|
137
|
+
}): PwCodeStartSession;
|
|
138
|
+
export {};
|
|
@@ -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 };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
// src/toolStrings.ts
|
|
4
|
+
/** How a tool call's result is summed up, in the reader's language, for
|
|
5
|
+
* `toolSummary`, `rollupSentence` and the other tool formatters. */
|
|
6
|
+
function useToolStrings() {
|
|
7
|
+
const t = usePwCodeTranslations("agentTranscript");
|
|
8
|
+
return useMemo(() => ({
|
|
9
|
+
noOutput: t("tools.noOutput"),
|
|
10
|
+
firstLine: (line, more) => more > 0 ? t("tools.firstLineMore", {
|
|
11
|
+
line,
|
|
12
|
+
more
|
|
13
|
+
}) : line,
|
|
14
|
+
emptyFile: t("tools.emptyFile"),
|
|
15
|
+
readImage: t("tools.readImage"),
|
|
16
|
+
readLines: (lines, more) => more > 0 ? t("tools.readLinesMore", {
|
|
17
|
+
lines,
|
|
18
|
+
more
|
|
19
|
+
}) : t("tools.readLines", { lines }),
|
|
20
|
+
noMatches: t("tools.noMatches"),
|
|
21
|
+
foundMatches: (matches, files) => t("tools.foundMatches", {
|
|
22
|
+
matches,
|
|
23
|
+
files
|
|
24
|
+
}),
|
|
25
|
+
foundFiles: (files) => t("tools.foundFiles", { files }),
|
|
26
|
+
noFilesMatched: t("tools.noFilesMatched"),
|
|
27
|
+
truncated: (summary) => t("tools.truncated", { summary }),
|
|
28
|
+
exitCode: (code, lines) => lines > 0 ? t("tools.exitCodeLines", {
|
|
29
|
+
code,
|
|
30
|
+
lines
|
|
31
|
+
}) : t("tools.exitCode", { code }),
|
|
32
|
+
httpStatus: (status, lines) => t("tools.httpStatus", {
|
|
33
|
+
status,
|
|
34
|
+
lines
|
|
35
|
+
}),
|
|
36
|
+
outputTruncated: (summary) => t("tools.outputTruncated", { summary }),
|
|
37
|
+
edited: (added, removed) => {
|
|
38
|
+
if (added > 0 && removed > 0) return t("tools.addedRemoved", {
|
|
39
|
+
added,
|
|
40
|
+
removed
|
|
41
|
+
});
|
|
42
|
+
if (added > 0) return t("tools.added", { added });
|
|
43
|
+
return removed > 0 ? t("tools.removed", { removed }) : "";
|
|
44
|
+
},
|
|
45
|
+
rejected: (feedback) => feedback ? t("tools.rejectedWith", { feedback }) : t("tools.rejected"),
|
|
46
|
+
rejectedUpdate: (path, feedback) => feedback ? t("tools.rejectedUpdateWith", {
|
|
47
|
+
path,
|
|
48
|
+
feedback
|
|
49
|
+
}) : t("tools.rejectedUpdate", { path }),
|
|
50
|
+
rejectedWrite: (path, feedback) => feedback ? t("tools.rejectedWriteWith", {
|
|
51
|
+
path,
|
|
52
|
+
feedback
|
|
53
|
+
}) : t("tools.rejectedWrite", { path }),
|
|
54
|
+
unattended: t("tools.unattended"),
|
|
55
|
+
userInterrupted: (tool) => t("tools.userInterrupted", { tool }),
|
|
56
|
+
wrote: (lines, path) => path ? t("tools.wroteTo", {
|
|
57
|
+
lines,
|
|
58
|
+
path
|
|
59
|
+
}) : t("tools.wrote", { lines }),
|
|
60
|
+
rollup: {
|
|
61
|
+
searched: (count) => t("tools.rollupSearched", { count }),
|
|
62
|
+
read: (count) => t("tools.rollupRead", { count }),
|
|
63
|
+
ranCommands: (count) => t("tools.rollupRanCommands", { count }),
|
|
64
|
+
fetched: (count) => t("tools.rollupFetched", { count }),
|
|
65
|
+
loadedSkills: (count) => t("tools.rollupLoadedSkills", { count }),
|
|
66
|
+
sentMessages: (count) => t("tools.rollupSentMessages", { count }),
|
|
67
|
+
calledMcpTools: (count) => t("tools.rollupCalledMcpTools", { count }),
|
|
68
|
+
ranTools: (count) => t("tools.rollupRanTools", { count }),
|
|
69
|
+
sentence: (clauses) => {
|
|
70
|
+
const s = clauses.join(t("tools.rollupSeparator"));
|
|
71
|
+
return s.charAt(0).toLocaleUpperCase() + s.slice(1);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
rollupActive: {
|
|
75
|
+
searching: (count) => t("tools.rollupSearching", { count }),
|
|
76
|
+
reading: (count) => t("tools.rollupReading", { count }),
|
|
77
|
+
runningCommands: (count) => t("tools.rollupRunningCommands", { count }),
|
|
78
|
+
fetching: (count) => t("tools.rollupFetching", { count }),
|
|
79
|
+
loadingSkills: (count) => t("tools.rollupLoadingSkills", { count }),
|
|
80
|
+
sendingMessages: (count) => t("tools.rollupSendingMessages", { count }),
|
|
81
|
+
runningTools: (count) => t("tools.rollupRunningTools", { count })
|
|
82
|
+
},
|
|
83
|
+
rollupServer: {
|
|
84
|
+
called: (server, count) => t("tools.rollupCalledServer", {
|
|
85
|
+
server,
|
|
86
|
+
count
|
|
87
|
+
}),
|
|
88
|
+
calling: (server, count) => t("tools.rollupCallingServer", {
|
|
89
|
+
server,
|
|
90
|
+
count
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
}), [t]);
|
|
94
|
+
}
|
|
95
|
+
export { useToolStrings };
|
package/dist/transcript.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApprovalAnswerValue, type ApprovalPart, type ChatMessage, type MessagePart, type MessagePaste, type SubagentNotice, type TodoItem, type ToolDecision } from '@parallelworks/ui/ai/headless';
|
|
2
|
-
import type { PwCodeAllowedDirectory, PwCodeApprovalAnswer, PwCodeApprovalRequest, PwCodeGoalStatus, PwCodeHistoryItem, PwCodeImage, PwCodeSessionDetail, PwCodeSessionState, PwCodeSessionStatus, PwCodeGoalProgress, PwCodeStreamEvent, PwCodeToolDecision, PwCodeTurnEnd } from './types.js';
|
|
2
|
+
import type { PwCodeAllowedDirectory, PwCodeApprovalAnswer, PwCodeApprovalRequest, PwCodeGoalStatus, PwCodeHistoryItem, PwCodeImage, PwCodeSessionDetail, PwCodeSessionState, PwCodeSessionStatus, PwCodeGoalProgress, PwCodeStreamEvent, PwCodeSubagentDetail, PwCodeToolDecision, PwCodeTurnEnd } from './types.js';
|
|
3
3
|
export interface TranscriptState {
|
|
4
4
|
messages: ChatMessage[];
|
|
5
5
|
streaming: ChatMessage | null;
|
|
@@ -65,6 +65,14 @@ export declare function initialTranscript(detail: PwCodeSessionDetail, options?:
|
|
|
65
65
|
words?: TranscriptWords | undefined;
|
|
66
66
|
imageUrl?: ImageUrl | undefined;
|
|
67
67
|
}): TranscriptState;
|
|
68
|
+
/** A subagent's detail as the session detail its transcript seeds from. Its run
|
|
69
|
+
* has no turn id on the wire, so its own id names the one in flight. */
|
|
70
|
+
export declare function subagentSessionDetail(sub: PwCodeSubagentDetail): PwCodeSessionDetail;
|
|
71
|
+
/** A session frame as one subagent's transcript reads it. A turn someone
|
|
72
|
+
* prompted on the subagent streams under its id, and a note it was handed
|
|
73
|
+
* arrives as its own event; the task it was given streams nothing, so a frame
|
|
74
|
+
* that only says it moved on is `refetch`. Null is a frame for someone else. */
|
|
75
|
+
export declare function subagentFrame(ev: PwCodeStreamEvent, id: string): PwCodeStreamEvent | 'refetch' | null;
|
|
68
76
|
/** The approvals the live feed is still waiting on. */
|
|
69
77
|
export declare function pendingApprovals(transcript: TranscriptState): ApprovalPart[];
|
|
70
78
|
/** Status as the live feed shows it; `detail.status` is only the fetch moment. */
|
|
@@ -74,6 +82,9 @@ export declare function resolveApprovalEverywhere(state: TranscriptState, id: st
|
|
|
74
82
|
* short, so the page must not close the turn either: its open tool calls
|
|
75
83
|
* would read as interrupted while they are still running. */
|
|
76
84
|
export declare function appendOwnMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
85
|
+
/** A subagent runs one turn at a time, so a message sent to it starts its next:
|
|
86
|
+
* a turn the transcript still shows running has ended. */
|
|
87
|
+
export declare function appendTurnMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
77
88
|
/** Held apart until the daemon reports the model was handed it. */
|
|
78
89
|
export declare function appendSteeredMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
79
90
|
/** The daemon queued a message this page had shown as sent, because the turn
|
|
@@ -115,6 +126,8 @@ export interface TranscriptWords {
|
|
|
115
126
|
deliveryLine: (notice: SubagentNotice) => string;
|
|
116
127
|
/** An approval's option that opens the directory it names for the session. */
|
|
117
128
|
allowDirectory: (dir: PwCodeAllowedDirectory) => string;
|
|
129
|
+
/** Who wrote a subagent's prompt: the conversation that started it. */
|
|
130
|
+
mainConversation: string;
|
|
118
131
|
}
|
|
119
132
|
/** The verb the terminal picks for a turn, so the same turn reads the same in both. */
|
|
120
133
|
export declare function turnVerb(endedAt: string): TurnVerb;
|