@parallelworks/code 0.2.0 → 0.4.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 +602 -84
- package/dist/accountApi.d.ts +31 -0
- package/dist/accountApi.js +182 -0
- package/dist/agentSwitcher.d.ts +109 -0
- package/dist/agentSwitcher.js +165 -0
- package/dist/ago.d.ts +8 -0
- package/dist/ago.js +26 -0
- package/dist/allocations.d.ts +41 -0
- package/dist/allocations.js +76 -0
- package/dist/api.d.ts +1213 -66
- 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/chatStrings.d.ts +188 -0
- package/dist/chatStrings.js +217 -0
- package/dist/claudeAccounts.d.ts +149 -0
- package/dist/claudeAccounts.js +328 -0
- package/dist/claudeApi.js +1 -1
- package/dist/claudeSignIn.d.ts +80 -0
- package/dist/claudeSignIn.js +249 -0
- package/dist/commandsApi.d.ts +11 -1
- package/dist/commandsApi.js +24 -5
- package/dist/contextRow.d.ts +25 -0
- package/dist/contextRow.js +16 -0
- package/dist/createPwCodeApi.d.ts +52 -5
- package/dist/createPwCodeApi.js +20 -2
- 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/howSessionsAppear.d.ts +12 -0
- package/dist/howSessionsAppear.js +24 -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 +41 -3
- package/dist/index.js +40 -4
- package/dist/loadError.d.ts +8 -0
- package/dist/loadError.js +19 -0
- package/dist/locales/en/agentTranscript.js +75 -22
- package/dist/locales/en/agents.js +76 -14
- package/dist/locales/en.d.ts +129 -21
- package/dist/locales/es/agentTranscript.js +75 -22
- package/dist/locales/es/agents.js +76 -14
- package/dist/locales/ja/agentTranscript.js +78 -25
- package/dist/locales/ja/agents.js +49 -124
- package/dist/locales/ko/agentTranscript.js +75 -22
- package/dist/locales/ko/agents.js +76 -14
- package/dist/locales/zh/agentTranscript.js +73 -20
- package/dist/locales/zh/agents.js +76 -14
- package/dist/machine.d.ts +4 -0
- package/dist/modelPicker.d.ts +79 -0
- package/dist/modelPicker.js +107 -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 +75 -21
- 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 +60 -0
- package/dist/pullRequestList.js +125 -0
- package/dist/query.d.ts +6 -2
- package/dist/query.js +85 -10
- package/dist/session.d.ts +10 -2
- package/dist/session.js +12 -8
- package/dist/sessionActions.d.ts +115 -0
- package/dist/sessionActions.js +186 -0
- package/dist/sessionEvents.d.ts +8 -3
- package/dist/sessionEvents.js +10 -5
- package/dist/sessionGroups.d.ts +50 -0
- package/dist/sessionGroups.js +73 -0
- package/dist/sessionHeader.d.ts +14 -0
- package/dist/sessionHeader.js +16 -0
- package/dist/sessionList.d.ts +182 -0
- package/dist/sessionList.js +333 -0
- package/dist/sessionScreen.d.ts +193 -0
- package/dist/sessionScreen.js +213 -0
- package/dist/sessionsApi.d.ts +13 -3
- package/dist/sessionsApi.js +90 -33
- package/dist/settingsApi.d.ts +38 -0
- package/dist/settingsApi.js +151 -0
- package/dist/startPage.d.ts +153 -0
- package/dist/startPage.js +174 -0
- package/dist/startSession.d.ts +172 -0
- package/dist/startSession.js +256 -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 +62 -26
- package/dist/types.d.ts +11 -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 +145 -0
- package/dist/useComposer.js +295 -0
- package/dist/useComposerImages.d.ts +71 -0
- package/dist/useComposerImages.js +218 -0
- package/dist/useComposerPastes.d.ts +70 -0
- package/dist/useComposerPastes.js +130 -0
- package/dist/useConversation.d.ts +199 -0
- package/dist/useConversation.js +314 -0
- package/dist/useSubagent.d.ts +104 -0
- package/dist/useSubagent.js +212 -0
- package/dist/useTranscript.d.ts +23 -3
- package/dist/useTranscript.js +76 -19
- package/dist/wording.js +2 -2
- package/dist/workingDirectories.d.ts +63 -0
- package/dist/workingDirectories.js +95 -0
- package/dist/worktreeChoice.d.ts +31 -0
- package/dist/worktreeChoice.js +38 -0
- package/locales/en/agentTranscript.json +69 -21
- package/locales/en/agents.json +73 -13
- package/locales/es/agentTranscript.json +69 -21
- package/locales/es/agents.json +73 -13
- package/locales/ja/agentTranscript.json +72 -24
- package/locales/ja/agents.json +73 -13
- package/locales/ko/agentTranscript.json +69 -21
- package/locales/ko/agents.json +73 -13
- package/locales/zh/agentTranscript.json +67 -19
- package/locales/zh/agents.json +73 -13
- package/package.json +6 -3
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { isConnected, isMachineDown } from "./machine.js";
|
|
2
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
3
|
+
import { pastedPullRequestLabel, pullRequestLabel } from "./pullRequest.js";
|
|
4
|
+
import { isActiveSession, isArchived, isSession, needsYou, newestCreatedFirst, newestFirst, sessionKey, sessionVariant, spansMachines } from "./session.js";
|
|
5
|
+
import { DELETE_KEYS, menuCommand, nameToSave } from "./sessionActions.js";
|
|
6
|
+
import { groupOf, inFlightFirst, isWorking, listGroups } from "./sessionGroups.js";
|
|
7
|
+
import { sessionLabel, sessionStateText } from "./wording.js";
|
|
8
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
9
|
+
// src/sessionList.ts
|
|
10
|
+
var PINNED = { pinned: true };
|
|
11
|
+
var UNGROUPED = { groupId: null };
|
|
12
|
+
var ARCHIVED = { archived: true };
|
|
13
|
+
var groupSectionKey = (id) => `group:${id}`;
|
|
14
|
+
function archiveSection(sessions, t) {
|
|
15
|
+
return {
|
|
16
|
+
key: "archived",
|
|
17
|
+
kind: "archived",
|
|
18
|
+
label: t("sidebar.groupArchived"),
|
|
19
|
+
sessions,
|
|
20
|
+
target: ARCHIVED
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** A reader scanning for what needs them, then what is live, should not have
|
|
24
|
+
* to read every mark. */
|
|
25
|
+
function statusSections(sessions, waiting, t) {
|
|
26
|
+
const needsYou = new Set(waiting);
|
|
27
|
+
const rest = sessions.filter((s) => !needsYou.has(s) && !isArchived(s));
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
key: "needsYou",
|
|
31
|
+
kind: "needsYou",
|
|
32
|
+
label: t("sidebar.groupNeedsYou"),
|
|
33
|
+
sessions: waiting,
|
|
34
|
+
target: UNGROUPED,
|
|
35
|
+
tone: "attention"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "active",
|
|
39
|
+
kind: "active",
|
|
40
|
+
label: t("sidebar.groupActive"),
|
|
41
|
+
sessions: newestCreatedFirst(rest.filter(isActiveSession)),
|
|
42
|
+
target: UNGROUPED
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "inactive",
|
|
46
|
+
kind: "inactive",
|
|
47
|
+
label: t("sidebar.groupInactive"),
|
|
48
|
+
sessions: rest.filter((s) => !isActiveSession(s)),
|
|
49
|
+
target: UNGROUPED
|
|
50
|
+
},
|
|
51
|
+
archiveSection(sessions.filter(isArchived), t)
|
|
52
|
+
].filter((g) => g.sessions.length > 0);
|
|
53
|
+
}
|
|
54
|
+
/** The sections a list of sessions reads in: the pinned ones, each of the
|
|
55
|
+
* reader's groups, then the rest by whether they need the reader, are live,
|
|
56
|
+
* are at rest or are archived. A pinned session is listed with the pinned
|
|
57
|
+
* ones alone; it keeps its group and goes back to it once it is unpinned. */
|
|
58
|
+
function sessionSections(sessions, groups, machineById, t) {
|
|
59
|
+
const visible = newestFirst(sessions);
|
|
60
|
+
const waiting = sessions.filter((s) => needsYou(s, machineById.get(s.machineId)));
|
|
61
|
+
const isPinned = (s) => !!s.pinnedAt && !isArchived(s);
|
|
62
|
+
const pinned = inFlightFirst(visible.filter(isPinned), machineById);
|
|
63
|
+
const { listed, ungrouped } = listGroups(groups, visible.filter((s) => !isPinned(s)), machineById);
|
|
64
|
+
return [
|
|
65
|
+
...pinned.sessions.length > 0 ? [{
|
|
66
|
+
key: "pinned",
|
|
67
|
+
kind: "pinned",
|
|
68
|
+
label: t("sidebar.pinned"),
|
|
69
|
+
sessions: pinned.sessions,
|
|
70
|
+
target: PINNED,
|
|
71
|
+
rollup: {
|
|
72
|
+
waiting: pinned.waiting,
|
|
73
|
+
running: pinned.running
|
|
74
|
+
}
|
|
75
|
+
}] : [],
|
|
76
|
+
...(visible.length > 0 ? listed : []).map((l) => ({
|
|
77
|
+
key: groupSectionKey(l.group.id),
|
|
78
|
+
kind: "group",
|
|
79
|
+
label: l.group.name,
|
|
80
|
+
sessions: l.sessions,
|
|
81
|
+
target: { groupId: l.group.id },
|
|
82
|
+
rollup: {
|
|
83
|
+
waiting: l.waiting,
|
|
84
|
+
running: l.running
|
|
85
|
+
},
|
|
86
|
+
group: l.group
|
|
87
|
+
})),
|
|
88
|
+
...statusSections(ungrouped, waiting.filter((s) => ungrouped.includes(s)), t)
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
/** The archive is listed only while it holds a session, so a dragged one
|
|
92
|
+
* would otherwise have nowhere to be dropped until the first is archived. */
|
|
93
|
+
function withArchiveSection(sections, t) {
|
|
94
|
+
return sections.some((s) => s.kind === "archived") ? sections : [...sections, archiveSection([], t)];
|
|
95
|
+
}
|
|
96
|
+
function isUngroupedTarget(target) {
|
|
97
|
+
return "groupId" in target && target.groupId === null;
|
|
98
|
+
}
|
|
99
|
+
/** The sessions a search lists: archived ones stay out until a search reaches for them. */
|
|
100
|
+
function searchedSessions(sessions, search) {
|
|
101
|
+
const current = sessions.filter((s) => !isArchived(s));
|
|
102
|
+
return search ? [...current, ...sessions.filter(isArchived)] : current;
|
|
103
|
+
}
|
|
104
|
+
/** What a search finds a session by: `value` its label, machine, directory,
|
|
105
|
+
* id and pull requests, and `keywords` the name it was given or gave itself. */
|
|
106
|
+
function sessionSearchText(session, machine, t) {
|
|
107
|
+
const pullRequests = (session.pullRequests ?? []).flatMap((url) => pullRequestLabel(url) ?? []);
|
|
108
|
+
return {
|
|
109
|
+
value: `${sessionLabel(session, t)} ${machine?.name ?? ""} ${session.workspace ?? ""} ${session.id} ${pullRequests.join(" ")}`,
|
|
110
|
+
keywords: [session.name || session.autoName || session.preview || ""]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var MIN_SCORE = .1;
|
|
114
|
+
/** How well `search` finds a session by its `sessionSearchText`, 0 for not at
|
|
115
|
+
* all: a pasted pull request link finds the sessions with that one, a number
|
|
116
|
+
* only text holding it as typed, and `score` ranks the rest. */
|
|
117
|
+
function sessionSearchScore({ value, keywords }, search, score) {
|
|
118
|
+
const text = [value, ...keywords].join(" ");
|
|
119
|
+
const pr = pastedPullRequestLabel(search)?.toLowerCase();
|
|
120
|
+
if (pr && text.toLowerCase().split(/\s+/).includes(pr)) return 1;
|
|
121
|
+
if (search.match(/\d+/g)?.some((number) => !text.includes(number))) return 0;
|
|
122
|
+
const fuzzy = score(value, search, keywords);
|
|
123
|
+
return fuzzy < MIN_SCORE ? 0 : fuzzy;
|
|
124
|
+
}
|
|
125
|
+
/** The state a search result shows: that it is archived, or what a live one
|
|
126
|
+
* is doing. One at rest shows none. */
|
|
127
|
+
function sessionSearchStatus(session, machine, t) {
|
|
128
|
+
if (isArchived(session)) return {
|
|
129
|
+
kind: "archived",
|
|
130
|
+
text: t("sidebar.groupArchived")
|
|
131
|
+
};
|
|
132
|
+
return isActiveSession(session) ? {
|
|
133
|
+
kind: "active",
|
|
134
|
+
text: sessionStateText(session, machine, t)
|
|
135
|
+
} : void 0;
|
|
136
|
+
}
|
|
137
|
+
/** What a session's mark on a collapsed list is called: its label, its
|
|
138
|
+
* machine and its state. */
|
|
139
|
+
function sessionRailLabel(session, machine, t) {
|
|
140
|
+
return [
|
|
141
|
+
sessionLabel(session, t),
|
|
142
|
+
machine?.name,
|
|
143
|
+
sessionStateText(session, machine, t)
|
|
144
|
+
].filter(Boolean).join(" · ");
|
|
145
|
+
}
|
|
146
|
+
/** A second line costs a row its height, so the state takes one only when the
|
|
147
|
+
* mark cannot express it: not "idle" or "running", but "waiting on you" and a
|
|
148
|
+
* dead machine. */
|
|
149
|
+
function sessionRowState(session, machine, t) {
|
|
150
|
+
const degraded = isMachineDown(machine);
|
|
151
|
+
return {
|
|
152
|
+
stateText: sessionStateText(session, machine, t),
|
|
153
|
+
showSecondLine: degraded || session.status !== "idle" && session.status !== "running",
|
|
154
|
+
live: isActiveSession(session) && !degraded
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** A pinned session is under the pinned ones' heading, which says so; only an
|
|
158
|
+
* archived one, listed with the archive, needs the mark. */
|
|
159
|
+
function showsPinMark(session) {
|
|
160
|
+
return !!session.pinnedAt && isArchived(session);
|
|
161
|
+
}
|
|
162
|
+
/** A session at work shows a turning mark, which tells it from one resting
|
|
163
|
+
* between turns by its shape and so holds with reduced motion. Any other
|
|
164
|
+
* shows a dot in its state's tone, pulsing while it waits on the reader. */
|
|
165
|
+
function sessionMark(session, machine) {
|
|
166
|
+
if (isWorking(session, machine)) return { working: true };
|
|
167
|
+
return {
|
|
168
|
+
working: false,
|
|
169
|
+
tone: sessionVariant(session.status, machine, "success"),
|
|
170
|
+
pulse: session.status === "awaiting_approval"
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** The server stores nothing, so a dropped machine contributes no sessions to
|
|
174
|
+
* the next poll; without this its sessions vanish instead of explaining themselves. */
|
|
175
|
+
function useRetainedSessions(machines, sessions) {
|
|
176
|
+
const lastSeen = useRef(/* @__PURE__ */ new Map());
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
const byMachine = /* @__PURE__ */ new Map();
|
|
179
|
+
for (const s of sessions) {
|
|
180
|
+
const found = byMachine.get(s.machineId);
|
|
181
|
+
if (found) found.push(s);
|
|
182
|
+
else byMachine.set(s.machineId, [s]);
|
|
183
|
+
}
|
|
184
|
+
const known = new Set(machines.map((m) => m.id));
|
|
185
|
+
for (const id of [...lastSeen.current.keys()]) if (!known.has(id)) lastSeen.current.delete(id);
|
|
186
|
+
for (const machine of machines) if (isConnected(machine)) lastSeen.current.set(machine.id, byMachine.get(machine.id) ?? []);
|
|
187
|
+
}, [machines, sessions]);
|
|
188
|
+
return useMemo(() => {
|
|
189
|
+
const retained = [];
|
|
190
|
+
for (const machine of machines) if (!isConnected(machine)) retained.push(...lastSeen.current.get(machine.id) ?? []);
|
|
191
|
+
return retained.length > 0 ? [...sessions, ...retained] : sessions;
|
|
192
|
+
}, [machines, sessions]);
|
|
193
|
+
}
|
|
194
|
+
function foldedKeys(stored) {
|
|
195
|
+
return Array.isArray(stored) ? stored : [];
|
|
196
|
+
}
|
|
197
|
+
/** The sessions as a list shows them, in sections, with what the reader can
|
|
198
|
+
* do to a row, a group or the list. */
|
|
199
|
+
function useSessionList({ api, machineById, groups, folded: [storedFolded, setFolded], open, actions, newSession, promptGroupName, confirmGroupDelete, onBlocked }) {
|
|
200
|
+
const t = usePwCodeTranslations("agents");
|
|
201
|
+
const { data, error, isLoading } = api.useSessions();
|
|
202
|
+
const sessions = useRetainedSessions(useMemo(() => data?.machines ?? [], [data]), useMemo(() => data?.sessions ?? [], [data]));
|
|
203
|
+
const folded = foldedKeys(storedFolded);
|
|
204
|
+
const sections = sessionSections(sessions, groups.groups, machineById, t);
|
|
205
|
+
const listedSessions = sections.flatMap((s) => s.sessions);
|
|
206
|
+
const openSession = listedSessions.find((s) => isSession(s, open.machine, open.sessionId));
|
|
207
|
+
const loading = isLoading && !data;
|
|
208
|
+
const newGroup = () => {
|
|
209
|
+
const group = groups.create(t("sidebar.newGroupName"));
|
|
210
|
+
promptGroupName(group);
|
|
211
|
+
return group;
|
|
212
|
+
};
|
|
213
|
+
const deleteGroup = (group) => {
|
|
214
|
+
groups.remove(group.id);
|
|
215
|
+
const key = groupSectionKey(group.id);
|
|
216
|
+
if (folded.includes(key)) setFolded((previous) => foldedKeys(previous).filter((k) => k !== key));
|
|
217
|
+
for (const s of sessions) if (s.group === group.id && !actions.groupBlocked(s)) actions.moveToGroup(s, null);
|
|
218
|
+
};
|
|
219
|
+
const dropOnArchive = (session) => {
|
|
220
|
+
const blocked = actions.archiveBlocked(session);
|
|
221
|
+
if (blocked) {
|
|
222
|
+
onBlocked(blocked);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
actions.requestArchive(session);
|
|
226
|
+
};
|
|
227
|
+
const canDrag = (session) => !isArchived(session);
|
|
228
|
+
const dropSession = (key, target) => {
|
|
229
|
+
const session = sessions.find((s) => sessionKey(s) === key);
|
|
230
|
+
if (!session || !canDrag(session)) return;
|
|
231
|
+
if ("archived" in target) {
|
|
232
|
+
dropOnArchive(session);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const pin = "pinned" in target;
|
|
236
|
+
if (pin !== !!session.pinnedAt) actions.togglePin(session);
|
|
237
|
+
if (!pin && (groupOf(groups.groups, session)?.id ?? null) !== target.groupId) {
|
|
238
|
+
const blocked = actions.groupBlocked(session);
|
|
239
|
+
if (blocked) {
|
|
240
|
+
onBlocked(blocked);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
actions.moveToGroup(session, target.groupId);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const menu = (session, row) => {
|
|
247
|
+
const items = actions.menu(session, row);
|
|
248
|
+
if (isArchived(session)) return items;
|
|
249
|
+
const current = groupOf(groups.groups, session);
|
|
250
|
+
const blocked = actions.groupBlocked(session);
|
|
251
|
+
const choices = [
|
|
252
|
+
...groups.groups.map((g) => ({
|
|
253
|
+
action: "joinGroup",
|
|
254
|
+
label: g.name,
|
|
255
|
+
checked: g === current,
|
|
256
|
+
run: () => actions.moveToGroup(session, g === current ? null : g.id)
|
|
257
|
+
})),
|
|
258
|
+
...groups.groups.length > 0 ? ["divider"] : [],
|
|
259
|
+
menuCommand("moveToNewGroup", t("sidebar.newGroup"), () => actions.moveToGroup(session, newGroup().id))
|
|
260
|
+
];
|
|
261
|
+
const move = {
|
|
262
|
+
action: "moveToGroup",
|
|
263
|
+
label: t("sidebar.moveToGroup"),
|
|
264
|
+
...blocked ? { disabledReason: blocked } : {},
|
|
265
|
+
items: choices
|
|
266
|
+
};
|
|
267
|
+
const at = items.lastIndexOf("divider");
|
|
268
|
+
return at < 0 ? [...items, move] : [
|
|
269
|
+
...items.slice(0, at),
|
|
270
|
+
move,
|
|
271
|
+
...items.slice(at)
|
|
272
|
+
];
|
|
273
|
+
};
|
|
274
|
+
return {
|
|
275
|
+
data,
|
|
276
|
+
error,
|
|
277
|
+
loading,
|
|
278
|
+
loadError: data ? void 0 : error,
|
|
279
|
+
sessions,
|
|
280
|
+
sections,
|
|
281
|
+
searchable: loading || sections.length > 0,
|
|
282
|
+
multiMachine: spansMachines(sessions),
|
|
283
|
+
openSession,
|
|
284
|
+
rail: listedSessions.filter((s) => isActiveSession(s) && isConnected(machineById.get(s.machineId)) || s === openSession),
|
|
285
|
+
folded,
|
|
286
|
+
toggleFold: (key) => setFolded((previous) => {
|
|
287
|
+
const keys = foldedKeys(previous);
|
|
288
|
+
return keys.includes(key) ? keys.filter((k) => k !== key) : [...keys, key];
|
|
289
|
+
}),
|
|
290
|
+
holdsOpen: (section) => folded.includes(section.key) && !!openSession && section.sessions.includes(openSession),
|
|
291
|
+
canDrag,
|
|
292
|
+
dropSession,
|
|
293
|
+
newGroup,
|
|
294
|
+
renameGroup: (group, name) => {
|
|
295
|
+
const saved = nameToSave(name);
|
|
296
|
+
if (saved) groups.patch(group.id, { name: saved });
|
|
297
|
+
return !!saved;
|
|
298
|
+
},
|
|
299
|
+
groupNameWords: {
|
|
300
|
+
title: t("sidebar.renameGroupTitle"),
|
|
301
|
+
label: t("sidebar.groupNameLabel"),
|
|
302
|
+
placeholder: t("sidebar.groupNamePlaceholder"),
|
|
303
|
+
confirmLabel: t("sidebar.renameAction")
|
|
304
|
+
},
|
|
305
|
+
groupDeleteWords: {
|
|
306
|
+
title: t("sidebar.deleteGroupTitle"),
|
|
307
|
+
description: (group) => t("sidebar.deleteGroupBody", { name: group.name }),
|
|
308
|
+
confirmLabel: t("sidebar.deleteAction")
|
|
309
|
+
},
|
|
310
|
+
deleteGroup,
|
|
311
|
+
menu,
|
|
312
|
+
groupMenu: (group) => [
|
|
313
|
+
menuCommand("renameGroup", t("sidebar.renameGroup"), () => promptGroupName(group)),
|
|
314
|
+
"divider",
|
|
315
|
+
{
|
|
316
|
+
...menuCommand("deleteGroup", t("sidebar.deleteGroup"), () => confirmGroupDelete(group), void 0, DELETE_KEYS[0]),
|
|
317
|
+
destructive: true
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
groupShortcuts: (group) => [{
|
|
321
|
+
keys: DELETE_KEYS,
|
|
322
|
+
run: () => confirmGroupDelete(group, true)
|
|
323
|
+
}],
|
|
324
|
+
listMenu: [menuCommand("newSession", t("sidebar.newSession"), newSession), ...sessions.length > 0 ? [menuCommand("newGroup", t("sidebar.newGroup"), () => {
|
|
325
|
+
newGroup();
|
|
326
|
+
})] : []],
|
|
327
|
+
shortcuts: (session) => [...actions.shortcuts(session), {
|
|
328
|
+
keys: "C",
|
|
329
|
+
run: newSession
|
|
330
|
+
}]
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export { groupSectionKey, isUngroupedTarget, searchedSessions, sessionMark, sessionRailLabel, sessionRowState, sessionSearchScore, sessionSearchStatus, sessionSearchText, sessionSections, showsPinMark, useRetainedSessions, useSessionList, withArchiveSection };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
|
+
import type { Schemas } from './apiClient.js';
|
|
3
|
+
import { type PwCodeGoalMark } from './goal.js';
|
|
4
|
+
import { type PwCodeTranslator } from './messages.js';
|
|
5
|
+
import { type PwCodePicker } from './models.js';
|
|
6
|
+
import type { PwCodeSessionSettingsOptions } from './settingsApi.js';
|
|
7
|
+
import { type TranscriptState } from './transcript.js';
|
|
8
|
+
import type { PwCodeGoalStatus, PwCodeSessionState } from './types.js';
|
|
9
|
+
import type { PwCodeComposer } from './useComposer.js';
|
|
10
|
+
import type { PwCodeConversation } from './useConversation.js';
|
|
11
|
+
type Translate = PwCodeTranslator<'agents'>;
|
|
12
|
+
type Machine = Schemas['AgentMachine'];
|
|
13
|
+
type SessionDetail = Schemas['AgentSessionDetail'];
|
|
14
|
+
/** The bar above an open session's transcript while nothing new can reach it. */
|
|
15
|
+
export interface PwCodeSessionBanner {
|
|
16
|
+
/** `unreachable` asks for the machine again and reads the session again;
|
|
17
|
+
* `liveElsewhere` only reads the session again. */
|
|
18
|
+
kind: 'unreachable' | 'liveElsewhere';
|
|
19
|
+
/** A machine that does not answer is a fault; a session live elsewhere is news. */
|
|
20
|
+
tone: 'danger' | 'info';
|
|
21
|
+
title: string;
|
|
22
|
+
body: string;
|
|
23
|
+
action: string;
|
|
24
|
+
}
|
|
25
|
+
/** A machine that does not answer outranks a session running in pw code elsewhere. */
|
|
26
|
+
export declare function sessionBanner({ unreachable, liveElsewhere, machineName, staleFor, liveHost, }: {
|
|
27
|
+
unreachable: boolean;
|
|
28
|
+
liveElsewhere: boolean;
|
|
29
|
+
machineName: string;
|
|
30
|
+
/** How long ago the transcript was last read, already abbreviated. */
|
|
31
|
+
staleFor: string;
|
|
32
|
+
liveHost: string | undefined;
|
|
33
|
+
}, t: Translate): PwCodeSessionBanner | null;
|
|
34
|
+
export interface PwCodeGoalLabel extends PwCodeGoalMark {
|
|
35
|
+
active: boolean;
|
|
36
|
+
text: string;
|
|
37
|
+
}
|
|
38
|
+
/** The goal loop's state, which stands apart from the session's: a paused
|
|
39
|
+
* goal leaves the turn it paused in running. Null without a goal. */
|
|
40
|
+
export declare function goalLabel(goal: PwCodeGoalStatus | null | undefined, t: Translate): PwCodeGoalLabel | null;
|
|
41
|
+
export interface PwCodeAccountChip {
|
|
42
|
+
account: string;
|
|
43
|
+
label: string;
|
|
44
|
+
}
|
|
45
|
+
/** The Claude Code account a Claude model runs as, pw code's `default` until
|
|
46
|
+
* one is chosen; null for any other model. */
|
|
47
|
+
export declare function claudeAccountChip(model: string | null | undefined, account: string | null | undefined, t: Translate): PwCodeAccountChip | null;
|
|
48
|
+
/** The composer's draft key. By the session rather than its machine: the
|
|
49
|
+
* screen follows a session to another login node, and the draft goes with it. */
|
|
50
|
+
export declare function sessionDraftKey(sessionId: string, detail: Pick<SessionDetail, 'id'> | undefined): string;
|
|
51
|
+
/** The draft key of the composer that starts a session, one per reader. */
|
|
52
|
+
export declare function newSessionDraftKey(username: string): string;
|
|
53
|
+
/** How long ago the transcript was last read, abbreviated, for the composer
|
|
54
|
+
* and banner to say how stale it is once the machine stops answering. */
|
|
55
|
+
export declare function useStaleFor(detail: SessionDetail | undefined, feedOpen: boolean): string;
|
|
56
|
+
/** The model a session runs: the one it reports while live, else the one
|
|
57
|
+
* read of it. */
|
|
58
|
+
export declare function sessionModel(liveState: Partial<Pick<PwCodeSessionState, 'model'>> | null | undefined, detail: Pick<SessionDetail, 'model'> | undefined): string | undefined;
|
|
59
|
+
/** What an open session's settings pickers show and whether they can change. */
|
|
60
|
+
export declare function sessionSettingsOptions(machine: string, conversation: Pick<PwCodeConversation, 'liveState' | 'detail'>, composer: Pick<PwCodeComposer, 'unreachable' | 'archived' | 'status'>): Pick<PwCodeSessionSettingsOptions, 'machine' | 'sessionId' | 'model' | 'effort' | 'allocation' | 'claudeAccount' | 'locked' | 'live'>;
|
|
61
|
+
/** Which of the composer's pickers is open; `/model` and `/claude-code` open
|
|
62
|
+
* one in place of being sent, and stay out of the transcript. */
|
|
63
|
+
export declare function useSessionPicker(): {
|
|
64
|
+
picker: PwCodePicker;
|
|
65
|
+
setPicker: Dispatch<SetStateAction<PwCodePicker>>;
|
|
66
|
+
/** Closes `panel` unless another has opened since. */
|
|
67
|
+
close: (panel: Exclude<PwCodePicker, null>) => void;
|
|
68
|
+
/** For the composer's `handleLocally`. */
|
|
69
|
+
handleLocally: (typed: string) => boolean;
|
|
70
|
+
addsToTranscript: (typed: string) => boolean;
|
|
71
|
+
};
|
|
72
|
+
/** The line in place of the composer's activity while the session is busy or
|
|
73
|
+
* its feed is down. */
|
|
74
|
+
export type PwCodeSessionActivity = {
|
|
75
|
+
kind: 'reconnecting';
|
|
76
|
+
text: string;
|
|
77
|
+
} | {
|
|
78
|
+
kind: 'usageLimit';
|
|
79
|
+
resumeAt: string | null | undefined;
|
|
80
|
+
/** Another Claude Code account can take the turn over. */
|
|
81
|
+
offersAccounts: boolean;
|
|
82
|
+
} | {
|
|
83
|
+
kind: 'working';
|
|
84
|
+
startedAt: string | null;
|
|
85
|
+
inputTokens: number | undefined;
|
|
86
|
+
outputTokens: number | undefined;
|
|
87
|
+
/** What the turn is doing when it is more than working. */
|
|
88
|
+
word: string | undefined;
|
|
89
|
+
};
|
|
90
|
+
/** A turn at work: when it started and what it has used so far. */
|
|
91
|
+
export declare function workingActivity(transcript: Pick<TranscriptState, 'turnStartedAt'> | null, tokens: {
|
|
92
|
+
inputTokens?: number | undefined;
|
|
93
|
+
outputTokens?: number | undefined;
|
|
94
|
+
} | null | undefined, word?: string | undefined): Extract<PwCodeSessionActivity, {
|
|
95
|
+
kind: 'working';
|
|
96
|
+
}>;
|
|
97
|
+
/** What the composer's activity line says: the feed reconnecting outranks a
|
|
98
|
+
* turn, and a turn waiting on a usage limit says so in place of working. */
|
|
99
|
+
export declare function sessionActivity({ composer, transcript, liveState, claudeModel, }: {
|
|
100
|
+
composer: Pick<PwCodeComposer, 'reconnecting' | 'working' | 'checkingGoal'>;
|
|
101
|
+
transcript: TranscriptState | null;
|
|
102
|
+
liveState: PwCodeSessionState | null;
|
|
103
|
+
/** The session runs a Claude Code model on a machine where Claude Code runs. */
|
|
104
|
+
claudeModel: boolean;
|
|
105
|
+
}, t: Translate, tTranscript: PwCodeTranslator<'agentTranscript'>): PwCodeSessionActivity | null;
|
|
106
|
+
/** What a machine allows of Claude Code, for its account panel and model picker. */
|
|
107
|
+
export declare function claudeOnMachine(machine: Machine | undefined): {
|
|
108
|
+
/** Claude Code is installed and its owner allows it. */
|
|
109
|
+
available: boolean;
|
|
110
|
+
installed: boolean;
|
|
111
|
+
allowed: boolean;
|
|
112
|
+
login: boolean;
|
|
113
|
+
accountRemove: boolean;
|
|
114
|
+
};
|
|
115
|
+
/** An open session's screen around its transcript and composer: the banner,
|
|
116
|
+
* the activity line, the goal, what the transcript shows when it never
|
|
117
|
+
* loaded, the command menu and the settings row. The host reads the session
|
|
118
|
+
* (`api.useSessionDetail`, `api.useMachine`) and runs the conversation,
|
|
119
|
+
* composer and settings it passes here. */
|
|
120
|
+
export declare function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFor, settings, images, describeError, }: {
|
|
121
|
+
conversation: PwCodeConversation;
|
|
122
|
+
composer: PwCodeComposer;
|
|
123
|
+
/** The session, as `api.useSessionDetail` reads it. */
|
|
124
|
+
read: {
|
|
125
|
+
error?: unknown;
|
|
126
|
+
isLoading: boolean;
|
|
127
|
+
};
|
|
128
|
+
/** The session's machine, as `api.useMachine` reads it. */
|
|
129
|
+
machine: {
|
|
130
|
+
machine: Machine | undefined;
|
|
131
|
+
recheck: () => void;
|
|
132
|
+
};
|
|
133
|
+
/** What `useStaleFor` says, as the composer was given it. */
|
|
134
|
+
staleFor: string;
|
|
135
|
+
/** The session's own model, and whether a change to its settings is saving. */
|
|
136
|
+
settings: {
|
|
137
|
+
model: {
|
|
138
|
+
value?: string | null | undefined;
|
|
139
|
+
};
|
|
140
|
+
saving: boolean;
|
|
141
|
+
};
|
|
142
|
+
/** The images waiting to go with the next message. */
|
|
143
|
+
images: readonly unknown[];
|
|
144
|
+
/** Words a refusal or failure for the reader. */
|
|
145
|
+
describeError: (error: unknown) => string;
|
|
146
|
+
}): {
|
|
147
|
+
/** The session's state in a sentence, for a screen reader. */
|
|
148
|
+
statusText: string;
|
|
149
|
+
banner: {
|
|
150
|
+
/** `unreachable` asks for the machine again and reads the session again;
|
|
151
|
+
* `liveElsewhere` only reads the session again. */
|
|
152
|
+
kind: 'unreachable' | 'liveElsewhere';
|
|
153
|
+
/** A machine that does not answer is a fault; a session live elsewhere is news. */
|
|
154
|
+
tone: 'danger' | 'info';
|
|
155
|
+
title: string;
|
|
156
|
+
body: string;
|
|
157
|
+
action: string;
|
|
158
|
+
act: () => void;
|
|
159
|
+
} | null;
|
|
160
|
+
/** The transcript has yet to load for the first time. */
|
|
161
|
+
loading: boolean;
|
|
162
|
+
/** Shown in place of a transcript that never loaded: why, or undefined
|
|
163
|
+
* for the host's own line. */
|
|
164
|
+
failed: {
|
|
165
|
+
message: string | undefined;
|
|
166
|
+
} | null;
|
|
167
|
+
retry: () => undefined;
|
|
168
|
+
/** Why the workspace's own settings, skills and hooks did not load. */
|
|
169
|
+
untrusted: string | null;
|
|
170
|
+
activity: PwCodeSessionActivity | null;
|
|
171
|
+
goal: PwCodeGoalLabel | null;
|
|
172
|
+
commands: import("./command.js").PwCodeSlashCommand[];
|
|
173
|
+
showAuthor: boolean;
|
|
174
|
+
/** A message may go without text while images go with it. */
|
|
175
|
+
allowEmpty: boolean;
|
|
176
|
+
permission: {
|
|
177
|
+
mode: string | undefined;
|
|
178
|
+
ceiling: "" | "accept-edits" | "auto" | "bypass-permissions" | "plan" | "read-only" | undefined;
|
|
179
|
+
accepted: ("accept-edits" | "auto" | "bypass-permissions" | "plan" | "read-only")[] | undefined;
|
|
180
|
+
disabled: boolean;
|
|
181
|
+
};
|
|
182
|
+
claude: {
|
|
183
|
+
/** Claude Code is installed and its owner allows it. */
|
|
184
|
+
available: boolean;
|
|
185
|
+
installed: boolean;
|
|
186
|
+
allowed: boolean;
|
|
187
|
+
login: boolean;
|
|
188
|
+
accountRemove: boolean;
|
|
189
|
+
};
|
|
190
|
+
canStart: boolean;
|
|
191
|
+
};
|
|
192
|
+
export type PwCodeSessionScreen = ReturnType<typeof usePwCodeSessionScreen>;
|
|
193
|
+
export {};
|