@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,134 @@
|
|
|
1
|
+
import type { PwCodeApiError, Schemas } from './apiClient.js';
|
|
2
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
3
|
+
import { type PwCodeMachine } from './machine.js';
|
|
4
|
+
import { type PwCodeTranslator } from './messages.js';
|
|
5
|
+
import { type PwCodeSession, sessionVariant } from './session.js';
|
|
6
|
+
import { type OpenSessionRef, type SessionActions, type SessionMenuItem, type SessionRowKey } from './sessionActions.js';
|
|
7
|
+
import { type SessionGroup, type SessionGroups } from './sessionGroups.js';
|
|
8
|
+
import { sessionStateText } from './wording.js';
|
|
9
|
+
type Session = Schemas['AgentSession'];
|
|
10
|
+
type Translate = PwCodeTranslator<'agents'>;
|
|
11
|
+
type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
|
|
12
|
+
type Listed = Pick<PwCodeSession, 'machineId' | 'status' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'updatedAt'>;
|
|
13
|
+
/** Where a session dropped on a section goes: with the pinned ones, into one
|
|
14
|
+
* of the reader's groups or out of any, or into the archive. */
|
|
15
|
+
export type SessionDropTarget = {
|
|
16
|
+
pinned: true;
|
|
17
|
+
} | {
|
|
18
|
+
groupId: string | null;
|
|
19
|
+
} | {
|
|
20
|
+
archived: true;
|
|
21
|
+
};
|
|
22
|
+
export type SessionSectionKind = 'pinned' | 'group' | 'needsYou' | 'active' | 'inactive' | 'archived';
|
|
23
|
+
export interface SessionSection<S> {
|
|
24
|
+
/** The same on every visit, so a host can keep which sections are folded by it. */
|
|
25
|
+
key: string;
|
|
26
|
+
kind: SessionSectionKind;
|
|
27
|
+
label: string;
|
|
28
|
+
sessions: S[];
|
|
29
|
+
target: SessionDropTarget;
|
|
30
|
+
/** How many of its sessions wait on the reader and how many are working,
|
|
31
|
+
* for the pinned ones and the reader's groups, whose headings count them. */
|
|
32
|
+
rollup?: {
|
|
33
|
+
waiting: number;
|
|
34
|
+
running: number;
|
|
35
|
+
};
|
|
36
|
+
group?: SessionGroup;
|
|
37
|
+
}
|
|
38
|
+
export declare const groupSectionKey: (id: string) => string;
|
|
39
|
+
/** The sections a list of sessions reads in: the pinned ones, each of the
|
|
40
|
+
* reader's groups, then the rest by whether they need the reader, are live,
|
|
41
|
+
* are at rest or are archived. A pinned session is listed with the pinned
|
|
42
|
+
* ones alone; it keeps its group and goes back to it once it is unpinned. */
|
|
43
|
+
export declare function sessionSections<S extends Listed>(sessions: S[], groups: readonly SessionGroup[], machineById: Machines, t: Translate): SessionSection<S>[];
|
|
44
|
+
/** The archive is listed only while it holds a session, so a dragged one
|
|
45
|
+
* would otherwise have nowhere to be dropped until the first is archived. */
|
|
46
|
+
export declare function withArchiveSection<S>(sections: SessionSection<S>[], t: Translate): SessionSection<S>[];
|
|
47
|
+
export declare function isUngroupedTarget(target: SessionDropTarget): boolean;
|
|
48
|
+
/** The sessions a search lists: archived ones stay out until a search reaches for them. */
|
|
49
|
+
export declare function searchedSessions<S extends Pick<PwCodeSession, 'archivedAt'>>(sessions: readonly S[], search: string): S[];
|
|
50
|
+
/** What a search finds a session by: `value` its label, machine, directory,
|
|
51
|
+
* id and pull requests, and `keywords` the name it was given or gave itself. */
|
|
52
|
+
export declare function sessionSearchText(session: Pick<PwCodeSession, 'machineId' | 'id' | 'name' | 'autoName' | 'preview' | 'workspace' | 'pullRequests'>, machine: Pick<PwCodeMachine, 'name'> | undefined, t: Translate): {
|
|
53
|
+
value: string;
|
|
54
|
+
keywords: string[];
|
|
55
|
+
};
|
|
56
|
+
/** A second line costs a row its height, so the state takes one only when the
|
|
57
|
+
* mark cannot express it: not "idle" or "running", but "waiting on you" and a
|
|
58
|
+
* dead machine. */
|
|
59
|
+
export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
|
|
60
|
+
stateText: string;
|
|
61
|
+
showSecondLine: boolean;
|
|
62
|
+
live: boolean;
|
|
63
|
+
};
|
|
64
|
+
/** A pinned session is under the pinned ones' heading, which says so; only an
|
|
65
|
+
* archived one, listed with the archive, needs the mark. */
|
|
66
|
+
export declare function showsPinMark(session: Pick<PwCodeSession, 'pinnedAt' | 'archivedAt'>): boolean;
|
|
67
|
+
/** A session at work shows a turning mark, which tells it from one resting
|
|
68
|
+
* between turns by its shape and so holds with reduced motion. Any other
|
|
69
|
+
* shows a dot in its state's tone, pulsing while it waits on the reader. */
|
|
70
|
+
export declare function sessionMark(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): {
|
|
71
|
+
working: true;
|
|
72
|
+
} | {
|
|
73
|
+
working: false;
|
|
74
|
+
tone: ReturnType<typeof sessionVariant<'success'>>;
|
|
75
|
+
pulse: boolean;
|
|
76
|
+
};
|
|
77
|
+
/** The server stores nothing, so a dropped machine contributes no sessions to
|
|
78
|
+
* the next poll; without this its sessions vanish instead of explaining themselves. */
|
|
79
|
+
export declare function useRetainedSessions<S extends Pick<PwCodeSession, 'machineId'>>(machines: readonly Pick<PwCodeMachine, 'id' | 'status'>[], sessions: S[]): S[];
|
|
80
|
+
export interface SessionListOptions<R> {
|
|
81
|
+
api: Pick<PwCodeApi, 'useSessions'>;
|
|
82
|
+
machineById: ReadonlyMap<string, PwCodeMachine>;
|
|
83
|
+
groups: SessionGroups;
|
|
84
|
+
/** The keys of the folded sections as the host keeps them, which may hold
|
|
85
|
+
* anything an older copy stored, and how it keeps new ones. */
|
|
86
|
+
folded: readonly [unknown, (keys: string[]) => void];
|
|
87
|
+
open: OpenSessionRef;
|
|
88
|
+
actions: Pick<SessionActions<R>, 'menu' | 'shortcuts' | 'togglePin' | 'moveToGroup' | 'groupBlocked' | 'archiveBlocked' | 'requestArchive'>;
|
|
89
|
+
newSession: () => void;
|
|
90
|
+
/** Asks the reader to name a group: one just made, or one to rename. */
|
|
91
|
+
promptGroupName: (group: SessionGroup) => void;
|
|
92
|
+
/** Asks the reader before a group goes; confirming calls `deleteGroup`. */
|
|
93
|
+
confirmGroupDelete: (group: SessionGroup) => void;
|
|
94
|
+
/** Says why a dropped session stays where it was. */
|
|
95
|
+
onBlocked: (reason: string) => void;
|
|
96
|
+
}
|
|
97
|
+
export interface SessionList<R> {
|
|
98
|
+
data: Schemas['AgentSessionsResponse'] | undefined;
|
|
99
|
+
error: PwCodeApiError | undefined;
|
|
100
|
+
/** The first listing has not answered yet. */
|
|
101
|
+
loading: boolean;
|
|
102
|
+
/** The listing, with what a machine that stopped answering listed last. */
|
|
103
|
+
sessions: Session[];
|
|
104
|
+
sections: SessionSection<Session>[];
|
|
105
|
+
/** There is something to search for, or soon may be. */
|
|
106
|
+
searchable: boolean;
|
|
107
|
+
/** The sessions span machines, so each one's names its machine. */
|
|
108
|
+
multiMachine: boolean;
|
|
109
|
+
openSession: Session | undefined;
|
|
110
|
+
/** What a collapsed list shows: what is live, and the open session so it
|
|
111
|
+
* keeps a place while it is idle. */
|
|
112
|
+
rail: Session[];
|
|
113
|
+
folded: string[];
|
|
114
|
+
toggleFold: (key: string) => void;
|
|
115
|
+
/** Folded over the open session, which would otherwise have no mark. */
|
|
116
|
+
holdsOpen: (section: Pick<SessionSection<Session>, 'key' | 'sessions'>) => boolean;
|
|
117
|
+
/** `key` is the dropped session's `sessionKey`. */
|
|
118
|
+
dropSession: (key: string, target: SessionDropTarget) => void;
|
|
119
|
+
/** Made first and named second: what joins it is in it either way. */
|
|
120
|
+
newGroup: () => SessionGroup;
|
|
121
|
+
renameGroup: (group: SessionGroup, name: string) => void;
|
|
122
|
+
/** Its sessions stay in the list, in no group. */
|
|
123
|
+
deleteGroup: (group: SessionGroup) => void;
|
|
124
|
+
/** The session's actions, with a choice of the reader's groups. */
|
|
125
|
+
menu: (session: Session, row?: R) => SessionMenuItem[];
|
|
126
|
+
groupMenu: (group: SessionGroup) => SessionMenuItem[];
|
|
127
|
+
/** For the list's empty space. */
|
|
128
|
+
listMenu: SessionMenuItem[];
|
|
129
|
+
shortcuts: (session: Session) => SessionRowKey<R>[];
|
|
130
|
+
}
|
|
131
|
+
/** The sessions as a list shows them, in sections, with what the reader can
|
|
132
|
+
* do to a row, a group or the list. */
|
|
133
|
+
export declare function useSessionList<R = unknown>({ api, machineById, groups, folded: [storedFolded, setFolded], open, actions, newSession, promptGroupName, confirmGroupDelete, onBlocked, }: SessionListOptions<R>): SessionList<R>;
|
|
134
|
+
export {};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { isConnected, isMachineDown } from "./machine.js";
|
|
2
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
3
|
+
import { pullRequestLabel } from "./pullRequest.js";
|
|
4
|
+
import { isActiveSession, isArchived, isSession, needsYou, newestFirst, sessionKey, sessionVariant, spansMachines } from "./session.js";
|
|
5
|
+
import { menuCommand } 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
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: "active",
|
|
38
|
+
kind: "active",
|
|
39
|
+
label: t("sidebar.groupActive"),
|
|
40
|
+
sessions: rest.filter(isActiveSession),
|
|
41
|
+
target: UNGROUPED
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: "inactive",
|
|
45
|
+
kind: "inactive",
|
|
46
|
+
label: t("sidebar.groupInactive"),
|
|
47
|
+
sessions: rest.filter((s) => !isActiveSession(s)),
|
|
48
|
+
target: UNGROUPED
|
|
49
|
+
},
|
|
50
|
+
archiveSection(sessions.filter(isArchived), t)
|
|
51
|
+
].filter((g) => g.sessions.length > 0);
|
|
52
|
+
}
|
|
53
|
+
/** The sections a list of sessions reads in: the pinned ones, each of the
|
|
54
|
+
* reader's groups, then the rest by whether they need the reader, are live,
|
|
55
|
+
* are at rest or are archived. A pinned session is listed with the pinned
|
|
56
|
+
* ones alone; it keeps its group and goes back to it once it is unpinned. */
|
|
57
|
+
function sessionSections(sessions, groups, machineById, t) {
|
|
58
|
+
const visible = newestFirst(sessions);
|
|
59
|
+
const waiting = sessions.filter((s) => needsYou(s, machineById.get(s.machineId)));
|
|
60
|
+
const isPinned = (s) => !!s.pinnedAt && !isArchived(s);
|
|
61
|
+
const pinned = inFlightFirst(visible.filter(isPinned), machineById);
|
|
62
|
+
const { listed, ungrouped } = listGroups(groups, visible.filter((s) => !isPinned(s)), machineById);
|
|
63
|
+
return [
|
|
64
|
+
...pinned.sessions.length > 0 ? [{
|
|
65
|
+
key: "pinned",
|
|
66
|
+
kind: "pinned",
|
|
67
|
+
label: t("sidebar.pinned"),
|
|
68
|
+
sessions: pinned.sessions,
|
|
69
|
+
target: PINNED,
|
|
70
|
+
rollup: {
|
|
71
|
+
waiting: pinned.waiting,
|
|
72
|
+
running: pinned.running
|
|
73
|
+
}
|
|
74
|
+
}] : [],
|
|
75
|
+
...(visible.length > 0 ? listed : []).map((l) => ({
|
|
76
|
+
key: groupSectionKey(l.group.id),
|
|
77
|
+
kind: "group",
|
|
78
|
+
label: l.group.name,
|
|
79
|
+
sessions: l.sessions,
|
|
80
|
+
target: { groupId: l.group.id },
|
|
81
|
+
rollup: {
|
|
82
|
+
waiting: l.waiting,
|
|
83
|
+
running: l.running
|
|
84
|
+
},
|
|
85
|
+
group: l.group
|
|
86
|
+
})),
|
|
87
|
+
...statusSections(ungrouped, waiting.filter((s) => ungrouped.includes(s)), t)
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
/** The archive is listed only while it holds a session, so a dragged one
|
|
91
|
+
* would otherwise have nowhere to be dropped until the first is archived. */
|
|
92
|
+
function withArchiveSection(sections, t) {
|
|
93
|
+
return sections.some((s) => s.kind === "archived") ? sections : [...sections, archiveSection([], t)];
|
|
94
|
+
}
|
|
95
|
+
function isUngroupedTarget(target) {
|
|
96
|
+
return "groupId" in target && target.groupId === null;
|
|
97
|
+
}
|
|
98
|
+
/** The sessions a search lists: archived ones stay out until a search reaches for them. */
|
|
99
|
+
function searchedSessions(sessions, search) {
|
|
100
|
+
const current = sessions.filter((s) => !isArchived(s));
|
|
101
|
+
return search ? [...current, ...sessions.filter(isArchived)] : current;
|
|
102
|
+
}
|
|
103
|
+
/** What a search finds a session by: `value` its label, machine, directory,
|
|
104
|
+
* id and pull requests, and `keywords` the name it was given or gave itself. */
|
|
105
|
+
function sessionSearchText(session, machine, t) {
|
|
106
|
+
const pullRequests = (session.pullRequests ?? []).flatMap((url) => pullRequestLabel(url) ?? []);
|
|
107
|
+
return {
|
|
108
|
+
value: `${sessionLabel(session, t)} ${machine?.name ?? ""} ${session.workspace ?? ""} ${session.id} ${pullRequests.join(" ")}`,
|
|
109
|
+
keywords: [session.name || session.autoName || session.preview || ""]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** A second line costs a row its height, so the state takes one only when the
|
|
113
|
+
* mark cannot express it: not "idle" or "running", but "waiting on you" and a
|
|
114
|
+
* dead machine. */
|
|
115
|
+
function sessionRowState(session, machine, t) {
|
|
116
|
+
const degraded = isMachineDown(machine);
|
|
117
|
+
return {
|
|
118
|
+
stateText: sessionStateText(session, machine, t),
|
|
119
|
+
showSecondLine: degraded || session.status !== "idle" && session.status !== "running",
|
|
120
|
+
live: isActiveSession(session) && !degraded
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** A pinned session is under the pinned ones' heading, which says so; only an
|
|
124
|
+
* archived one, listed with the archive, needs the mark. */
|
|
125
|
+
function showsPinMark(session) {
|
|
126
|
+
return !!session.pinnedAt && isArchived(session);
|
|
127
|
+
}
|
|
128
|
+
/** A session at work shows a turning mark, which tells it from one resting
|
|
129
|
+
* between turns by its shape and so holds with reduced motion. Any other
|
|
130
|
+
* shows a dot in its state's tone, pulsing while it waits on the reader. */
|
|
131
|
+
function sessionMark(session, machine) {
|
|
132
|
+
if (isWorking(session, machine)) return { working: true };
|
|
133
|
+
return {
|
|
134
|
+
working: false,
|
|
135
|
+
tone: sessionVariant(session.status, machine, "success"),
|
|
136
|
+
pulse: session.status === "awaiting_approval"
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** The server stores nothing, so a dropped machine contributes no sessions to
|
|
140
|
+
* the next poll; without this its sessions vanish instead of explaining themselves. */
|
|
141
|
+
function useRetainedSessions(machines, sessions) {
|
|
142
|
+
const lastSeen = useRef(/* @__PURE__ */ new Map());
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const byMachine = /* @__PURE__ */ new Map();
|
|
145
|
+
for (const s of sessions) {
|
|
146
|
+
const found = byMachine.get(s.machineId);
|
|
147
|
+
if (found) found.push(s);
|
|
148
|
+
else byMachine.set(s.machineId, [s]);
|
|
149
|
+
}
|
|
150
|
+
const known = new Set(machines.map((m) => m.id));
|
|
151
|
+
for (const id of [...lastSeen.current.keys()]) if (!known.has(id)) lastSeen.current.delete(id);
|
|
152
|
+
for (const machine of machines) if (isConnected(machine)) lastSeen.current.set(machine.id, byMachine.get(machine.id) ?? []);
|
|
153
|
+
}, [machines, sessions]);
|
|
154
|
+
return useMemo(() => {
|
|
155
|
+
const retained = [];
|
|
156
|
+
for (const machine of machines) if (!isConnected(machine)) retained.push(...lastSeen.current.get(machine.id) ?? []);
|
|
157
|
+
return retained.length > 0 ? [...sessions, ...retained] : sessions;
|
|
158
|
+
}, [machines, sessions]);
|
|
159
|
+
}
|
|
160
|
+
/** The sessions as a list shows them, in sections, with what the reader can
|
|
161
|
+
* do to a row, a group or the list. */
|
|
162
|
+
function useSessionList({ api, machineById, groups, folded: [storedFolded, setFolded], open, actions, newSession, promptGroupName, confirmGroupDelete, onBlocked }) {
|
|
163
|
+
const t = usePwCodeTranslations("agents");
|
|
164
|
+
const { data, error, isLoading } = api.useSessions();
|
|
165
|
+
const sessions = useRetainedSessions(useMemo(() => data?.machines ?? [], [data]), useMemo(() => data?.sessions ?? [], [data]));
|
|
166
|
+
const folded = Array.isArray(storedFolded) ? storedFolded : [];
|
|
167
|
+
const sections = sessionSections(sessions, groups.groups, machineById, t);
|
|
168
|
+
const listedSessions = sections.flatMap((s) => s.sessions);
|
|
169
|
+
const openSession = listedSessions.find((s) => isSession(s, open.machine, open.sessionId));
|
|
170
|
+
const loading = isLoading && !data;
|
|
171
|
+
const newGroup = () => {
|
|
172
|
+
const group = groups.create(t("sidebar.newGroupName"));
|
|
173
|
+
promptGroupName(group);
|
|
174
|
+
return group;
|
|
175
|
+
};
|
|
176
|
+
const deleteGroup = (group) => {
|
|
177
|
+
groups.remove(group.id);
|
|
178
|
+
const key = groupSectionKey(group.id);
|
|
179
|
+
if (folded.includes(key)) setFolded(folded.filter((k) => k !== key));
|
|
180
|
+
for (const s of sessions) if (s.group === group.id && !actions.groupBlocked(s)) actions.moveToGroup(s, null);
|
|
181
|
+
};
|
|
182
|
+
const dropOnArchive = (session) => {
|
|
183
|
+
const blocked = actions.archiveBlocked(session);
|
|
184
|
+
if (blocked) {
|
|
185
|
+
onBlocked(blocked);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
actions.requestArchive(session);
|
|
189
|
+
};
|
|
190
|
+
const dropSession = (key, target) => {
|
|
191
|
+
const session = sessions.find((s) => sessionKey(s) === key);
|
|
192
|
+
if (!session) return;
|
|
193
|
+
if ("archived" in target) {
|
|
194
|
+
dropOnArchive(session);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const pin = "pinned" in target;
|
|
198
|
+
if (pin !== !!session.pinnedAt) actions.togglePin(session);
|
|
199
|
+
if (!pin && (groupOf(groups.groups, session)?.id ?? null) !== target.groupId) {
|
|
200
|
+
const blocked = actions.groupBlocked(session);
|
|
201
|
+
if (blocked) {
|
|
202
|
+
onBlocked(blocked);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
actions.moveToGroup(session, target.groupId);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const menu = (session, row) => {
|
|
209
|
+
const items = actions.menu(session, row);
|
|
210
|
+
if (isArchived(session)) return items;
|
|
211
|
+
const current = groupOf(groups.groups, session);
|
|
212
|
+
const blocked = actions.groupBlocked(session);
|
|
213
|
+
const choices = [
|
|
214
|
+
...groups.groups.map((g) => ({
|
|
215
|
+
action: "joinGroup",
|
|
216
|
+
label: g.name,
|
|
217
|
+
checked: g === current,
|
|
218
|
+
run: () => actions.moveToGroup(session, g === current ? null : g.id)
|
|
219
|
+
})),
|
|
220
|
+
...groups.groups.length > 0 ? ["divider"] : [],
|
|
221
|
+
menuCommand("moveToNewGroup", t("sidebar.newGroup"), () => actions.moveToGroup(session, newGroup().id))
|
|
222
|
+
];
|
|
223
|
+
const move = {
|
|
224
|
+
action: "moveToGroup",
|
|
225
|
+
label: t("sidebar.moveToGroup"),
|
|
226
|
+
...blocked ? { disabledReason: blocked } : {},
|
|
227
|
+
items: choices
|
|
228
|
+
};
|
|
229
|
+
const at = items.lastIndexOf("divider");
|
|
230
|
+
return at < 0 ? [...items, move] : [
|
|
231
|
+
...items.slice(0, at),
|
|
232
|
+
move,
|
|
233
|
+
...items.slice(at)
|
|
234
|
+
];
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
data,
|
|
238
|
+
error,
|
|
239
|
+
loading,
|
|
240
|
+
sessions,
|
|
241
|
+
sections,
|
|
242
|
+
searchable: loading || sections.length > 0,
|
|
243
|
+
multiMachine: spansMachines(sessions),
|
|
244
|
+
openSession,
|
|
245
|
+
rail: listedSessions.filter((s) => isActiveSession(s) && isConnected(machineById.get(s.machineId)) || s === openSession),
|
|
246
|
+
folded,
|
|
247
|
+
toggleFold: (key) => setFolded(folded.includes(key) ? folded.filter((k) => k !== key) : [...folded, key]),
|
|
248
|
+
holdsOpen: (section) => folded.includes(section.key) && !!openSession && section.sessions.includes(openSession),
|
|
249
|
+
dropSession,
|
|
250
|
+
newGroup,
|
|
251
|
+
renameGroup: (group, name) => groups.patch(group.id, { name }),
|
|
252
|
+
deleteGroup,
|
|
253
|
+
menu,
|
|
254
|
+
groupMenu: (group) => [
|
|
255
|
+
menuCommand("renameGroup", t("sidebar.renameGroup"), () => promptGroupName(group)),
|
|
256
|
+
"divider",
|
|
257
|
+
{
|
|
258
|
+
...menuCommand("deleteGroup", t("sidebar.deleteGroup"), () => confirmGroupDelete(group)),
|
|
259
|
+
destructive: true
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
listMenu: [menuCommand("newSession", t("sidebar.newSession"), newSession), ...sessions.length > 0 ? [menuCommand("newGroup", t("sidebar.newGroup"), () => {
|
|
263
|
+
newGroup();
|
|
264
|
+
})] : []],
|
|
265
|
+
shortcuts: (session) => [...actions.shortcuts(session), {
|
|
266
|
+
keys: "C",
|
|
267
|
+
run: newSession
|
|
268
|
+
}]
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export { groupSectionKey, isUngroupedTarget, searchedSessions, sessionMark, sessionRowState, sessionSearchText, sessionSections, showsPinMark, useRetainedSessions, useSessionList, withArchiveSection };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ApprovalAnswerValue, MessagePaste } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
import type { KeyedMutator } from 'swr';
|
|
4
|
+
import { type PwCodeApiError, type PwCodeClient, type PwCodeQuery, type PwCodeResult, type Schemas } from './apiClient.js';
|
|
5
|
+
type Session = Schemas['AgentSession'];
|
|
6
|
+
type SessionDetail = Schemas['AgentSessionDetail'];
|
|
7
|
+
type SessionsResponse = Schemas['AgentSessionsResponse'];
|
|
8
|
+
type PullRequest = Schemas['AgentPullRequest'];
|
|
9
|
+
export declare const SESSIONS_REFRESH_MS = 5000;
|
|
10
|
+
/** Whether a copy cached by an earlier visit still holds everything the
|
|
11
|
+
* session's listed row reports. A running session's copy trails its turn. */
|
|
12
|
+
export declare function cachedCopyCurrent(listed: Session | undefined, cached: SessionDetail): boolean;
|
|
13
|
+
/** Each session listed from `machine` that links a pull request in `read` takes its state, as the machine stores it for every one of them. */
|
|
14
|
+
export declare function patchPullRequestStates(current: SessionsResponse | undefined, machine: string, read: PullRequest[]): SessionsResponse | undefined;
|
|
15
|
+
type PullRequestStates = {
|
|
16
|
+
pullRequests?: PullRequest[] | null;
|
|
17
|
+
};
|
|
18
|
+
/** Every minute while any of `urls` may still change or has no state yet, hourly once all are merged or closed, and never once all are merged. */
|
|
19
|
+
export declare function pullRequestsRefreshMs(data: PullRequestStates | undefined, urls: string[]): number;
|
|
20
|
+
/** When this client last read the session from its machine: its fetch, or the
|
|
21
|
+
* moment its open feed closed, since an open feed is still reading. */
|
|
22
|
+
export declare function useLastReadAt(detail: SessionDetail | undefined, feedOpen: boolean): DateTime | null;
|
|
23
|
+
export declare function patchSessionNames(current: SessionsResponse | undefined, machine: string, id: string, names: Pick<Session, 'name' | 'autoName'>): SessionsResponse | undefined;
|
|
24
|
+
/** The part of a paste a message names it by. */
|
|
25
|
+
export declare function pasteRefs(pastes: MessagePaste[] | undefined): {
|
|
26
|
+
pastes: {
|
|
27
|
+
placeholder: string;
|
|
28
|
+
id: number;
|
|
29
|
+
}[];
|
|
30
|
+
} | {
|
|
31
|
+
pastes?: never;
|
|
32
|
+
};
|
|
33
|
+
export type PwCodePasteUpload = {
|
|
34
|
+
paste: Schemas['AgentPasteSaved'];
|
|
35
|
+
} | {
|
|
36
|
+
error: string;
|
|
37
|
+
} | {
|
|
38
|
+
unsupported: true;
|
|
39
|
+
};
|
|
40
|
+
export declare function sessionsApi(client: PwCodeClient): {
|
|
41
|
+
useSessions: () => PwCodeQuery<SessionsResponse>;
|
|
42
|
+
useWaitingSessionCount: (enabled: boolean) => number;
|
|
43
|
+
useSessionDetail: (machine: string, id: string, listed: Session | undefined) => {
|
|
44
|
+
data: SessionDetail | undefined;
|
|
45
|
+
error: PwCodeApiError | undefined;
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
mutate: KeyedMutator<SessionDetail>;
|
|
48
|
+
fresh: boolean;
|
|
49
|
+
};
|
|
50
|
+
usePullRequests: (machine: string, id: string, urls: string[], onRead?: (read: PullRequest[]) => void) => PwCodeQuery<Schemas['AgentPullRequests']>;
|
|
51
|
+
useSessionPullRequestStates: (machine: string, id: string, urls: string[]) => {
|
|
52
|
+
url: string;
|
|
53
|
+
state: string | undefined;
|
|
54
|
+
}[] | undefined;
|
|
55
|
+
useMachine: (machine: string) => {
|
|
56
|
+
machine: Schemas['AgentMachine'] | undefined;
|
|
57
|
+
recheck: () => void;
|
|
58
|
+
};
|
|
59
|
+
useSubagents: (machine: string, id: string, enabled: boolean) => {
|
|
60
|
+
subagents: Schemas['Subagent'][];
|
|
61
|
+
refresh: () => void;
|
|
62
|
+
};
|
|
63
|
+
useSubagentDetail: (machine: string, id: string, subId: string) => {
|
|
64
|
+
data: Schemas['SubagentDetail'] | undefined;
|
|
65
|
+
error: unknown;
|
|
66
|
+
refresh: () => void;
|
|
67
|
+
};
|
|
68
|
+
stopSubagent: (machine: string, id: string, subId: string) => Promise<unknown>;
|
|
69
|
+
stopAllSubagents: (machine: string, id: string) => Promise<unknown>;
|
|
70
|
+
useSessionWorktree: (s: Session | undefined) => PwCodeQuery<Schemas['AgentSessionWorktree']>;
|
|
71
|
+
leaveWorktree: (s: Session, removeRoot?: string) => Promise<{
|
|
72
|
+
left?: Schemas['AgentWorktreeLeft'];
|
|
73
|
+
refusal?: unknown;
|
|
74
|
+
}>;
|
|
75
|
+
useSessionMutations: () => {
|
|
76
|
+
/** Given the root of the worktree the session works in, removes that worktree too. */
|
|
77
|
+
deleteSession: (s: Session, removeWorktree?: string) => Promise<unknown>;
|
|
78
|
+
renameSession: (s: Session, name: string) => Promise<unknown>;
|
|
79
|
+
archiveSession: (s: Session) => Promise<unknown>;
|
|
80
|
+
archiveAfterTurn: (s: Session) => Promise<{
|
|
81
|
+
refusal: unknown;
|
|
82
|
+
deferred: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
restoreSession: (s: Session) => Promise<unknown>;
|
|
85
|
+
pinSession: (s: Session, pinned: boolean) => Promise<unknown>;
|
|
86
|
+
/** `group` is the id of one of the reader's groups, or null for none. */
|
|
87
|
+
groupSession: (s: Session, group: string | null) => Promise<unknown>;
|
|
88
|
+
stopSession: (s: Session) => Promise<unknown>;
|
|
89
|
+
forkSession: (s: Session) => Promise<{
|
|
90
|
+
forked?: Schemas['AgentSessionForked'];
|
|
91
|
+
refusal?: unknown;
|
|
92
|
+
}>;
|
|
93
|
+
};
|
|
94
|
+
createSession: (machine: string, body: Schemas['CreateSessionBody']) => Promise<PwCodeResult<SessionDetail>>;
|
|
95
|
+
sendMessage: (machine: string, id: string, body: Schemas['SendMessageBody']) => Promise<PwCodeResult<Schemas['AgentMessageAccepted']>>;
|
|
96
|
+
steer: (machine: string, id: string, body: Schemas['AgentDirectionBody']) => Promise<PwCodeResult<Schemas['AgentDirectionDelivered']>>;
|
|
97
|
+
withdrawQueued: (machine: string, id: string, turnId: string) => Promise<PwCodeResult<undefined>>;
|
|
98
|
+
messageSubagent: (machine: string, id: string, subId: string, body: Schemas['SendMessageBody']) => Promise<PwCodeResult<Schemas['AgentMessageAccepted']>>;
|
|
99
|
+
steerSubagent: (machine: string, id: string, subId: string, body: Schemas['AgentDirectionBody']) => Promise<PwCodeResult<Schemas['AgentDirectionDelivered']>>;
|
|
100
|
+
saveImage: (machine: string, id: string, body: Schemas['AgentImageBody']) => Promise<PwCodeResult<Schemas['AgentImageSaved']>>;
|
|
101
|
+
answerApproval: (machine: string, sessionId: string, approvalId: string, answer: ApprovalAnswerValue) => Promise<unknown>;
|
|
102
|
+
removeSessionDirectory: (machine: string, sessionId: string, path: string) => Promise<unknown>;
|
|
103
|
+
uploadPaste: (machine: string, sessionId: string, text: string, describe: (error: unknown) => string) => Promise<PwCodePasteUpload>;
|
|
104
|
+
};
|
|
105
|
+
export {};
|