@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,153 @@
|
|
|
1
|
+
import type { ApprovalAnswerValue, ApprovalPart } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import { type PwCodeHandoffChat } from './chatHandoff.js';
|
|
3
|
+
import { type PwCodePalette, type PwCodeSlashCommand } from './command.js';
|
|
4
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
5
|
+
import { type PwCodeMachine } from './machine.js';
|
|
6
|
+
import type { PwCodeTranslator } from './messages.js';
|
|
7
|
+
import { runsClaude } from './models.js';
|
|
8
|
+
import { type PwCodeSession } from './session.js';
|
|
9
|
+
import type { PwCodeStartLocation, PwCodeStartMachine } from './startSession.js';
|
|
10
|
+
import { type TranscriptWords } from './transcript.js';
|
|
11
|
+
import type { PwCodeApprovalRequest } from './types.js';
|
|
12
|
+
import { sessionStateText } from './wording.js';
|
|
13
|
+
type Translate = PwCodeTranslator<'agents'>;
|
|
14
|
+
/** As many sessions as a new chat offers starters, so the page fits. */
|
|
15
|
+
export declare const START_SHORTLIST = 4;
|
|
16
|
+
/** The sessions a start page offers to pick back up: the live ones, then the
|
|
17
|
+
* idle ones, each newest first as `triageSessions` orders them. */
|
|
18
|
+
export declare function startShortlist<S>(triage: {
|
|
19
|
+
active: readonly S[];
|
|
20
|
+
idle: readonly S[];
|
|
21
|
+
}, size?: number): S[];
|
|
22
|
+
/** A shortlisted session that is live shows a mark named by its state, which
|
|
23
|
+
* nothing else on its row spells out; one at rest shows none. */
|
|
24
|
+
export declare function shortlistMark(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
|
|
25
|
+
label: string;
|
|
26
|
+
} | null;
|
|
27
|
+
/** When a session began waiting on the reader: its first pending question,
|
|
28
|
+
* else its last change. */
|
|
29
|
+
export declare function waitingSince(s: Pick<PwCodeSession, 'updatedAt'> & {
|
|
30
|
+
approvals?: readonly Pick<PwCodeApprovalRequest, 'createdAt'>[] | null;
|
|
31
|
+
}): string | undefined;
|
|
32
|
+
/** What a session waiting on the reader asks, answerable where it is listed,
|
|
33
|
+
* or, when the listing carries none of its questions, `inSession`: a line
|
|
34
|
+
* sending the reader into the session to answer. */
|
|
35
|
+
export declare function waitingQuestions(s: {
|
|
36
|
+
approvals?: readonly PwCodeApprovalRequest[] | null;
|
|
37
|
+
}, words: Pick<TranscriptWords, 'allowDirectory'>, t: Translate): {
|
|
38
|
+
questions: ApprovalPart[];
|
|
39
|
+
inSession: string | null;
|
|
40
|
+
};
|
|
41
|
+
/** A start page around its composer, from the listing `api.useSessions` reads. */
|
|
42
|
+
export interface PwCodeStartScreen {
|
|
43
|
+
/** The listing has yet to answer. */
|
|
44
|
+
loading: boolean;
|
|
45
|
+
/** Shown in place of the page while the listing never loaded, since an
|
|
46
|
+
* empty one would read as having no sessions: why, or undefined for the
|
|
47
|
+
* host's own line. */
|
|
48
|
+
failed: {
|
|
49
|
+
message: string | undefined;
|
|
50
|
+
} | null;
|
|
51
|
+
/** Otherwise no machine lets a session start here, and the host says so.
|
|
52
|
+
* A machine not answering keeps it: such a machine reports starting off,
|
|
53
|
+
* so the menu says why rather than sending the reader to that setting. */
|
|
54
|
+
showComposer: boolean;
|
|
55
|
+
/** Nothing is listed, so the host explains how sessions appear (`howSessionsAppear`). */
|
|
56
|
+
explainEmpty: boolean;
|
|
57
|
+
/** Answers a listed session's question, then reads the listing again;
|
|
58
|
+
* resolves to the refusal in `describeError`'s words, or null. */
|
|
59
|
+
answer: (session: Pick<PwCodeSession, 'machineId' | 'id'>, approvalId: string, value: ApprovalAnswerValue) => Promise<string | null>;
|
|
60
|
+
}
|
|
61
|
+
export declare function useStartScreen(api: Pick<PwCodeApi, 'useSessions' | 'answerApproval'>, { location, describeError, }: {
|
|
62
|
+
location: {
|
|
63
|
+
startable: readonly unknown[];
|
|
64
|
+
down: readonly unknown[];
|
|
65
|
+
};
|
|
66
|
+
/** Words a refusal or failure for the reader. */
|
|
67
|
+
describeError: (error: unknown) => string;
|
|
68
|
+
}): PwCodeStartScreen;
|
|
69
|
+
/** What a start page's address asks for: a session to open, named by the
|
|
70
|
+
* link pw code's /rc prints, or a chat to hand to a new session. */
|
|
71
|
+
export interface PwCodeStartSearch {
|
|
72
|
+
session?: string | undefined;
|
|
73
|
+
fromChat?: string | undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The start page's parameters from its parsed query; any that is not a
|
|
76
|
+
* single string is left out. */
|
|
77
|
+
export declare function startSearch(search: Record<string, unknown>): PwCodeStartSearch;
|
|
78
|
+
/** How a link to a session stands: still being looked for, or missing from
|
|
79
|
+
* the listing; null without one. */
|
|
80
|
+
export type PwCodeSessionLinkState = 'resolving' | 'missing' | null;
|
|
81
|
+
/** Follows a link that names only a session, since the machine listed with
|
|
82
|
+
* it is not known where the link was printed: once the listing names the
|
|
83
|
+
* session, `open` takes it to the session. */
|
|
84
|
+
export declare function useSessionLink<S extends Pick<PwCodeSession, 'id'>>(session: string | undefined, listing: {
|
|
85
|
+
sessions: readonly S[];
|
|
86
|
+
loading: boolean;
|
|
87
|
+
}, open: (found: S) => void): PwCodeSessionLinkState;
|
|
88
|
+
/** The card over the composer while a link to a session is followed: news
|
|
89
|
+
* while it is looked for, a warning once the listing lacks it. Null without
|
|
90
|
+
* a link. */
|
|
91
|
+
export declare function sessionLinkNotice(state: PwCodeSessionLinkState, session: string | undefined, t: Translate): {
|
|
92
|
+
text: string;
|
|
93
|
+
tone: 'neutral' | 'warning';
|
|
94
|
+
} | null;
|
|
95
|
+
/** The commands a new session's composer offers: the directory's palette,
|
|
96
|
+
* led by the Claude Code account choice on a machine where Claude Code
|
|
97
|
+
* runs. Archiving needs a session, so it is not offered. */
|
|
98
|
+
export declare function startCommands(palette: PwCodePalette | null, machine: Parameters<typeof runsClaude>[0], t: Translate): PwCodeSlashCommand[];
|
|
99
|
+
/** A machine as the start page's menu offers it. */
|
|
100
|
+
export interface PwCodeMachineChoice {
|
|
101
|
+
id: string;
|
|
102
|
+
label: string;
|
|
103
|
+
/** A computer or a resource, or for one not answering, why. */
|
|
104
|
+
description: string | undefined;
|
|
105
|
+
checked: boolean;
|
|
106
|
+
disabled: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** The machines a session can start on, then the ones not answering, each
|
|
109
|
+
* saying why, so a missing machine can be traced. With both, the ones not
|
|
110
|
+
* answering go under `downLabel`; with one kind only, it stands alone. */
|
|
111
|
+
export interface PwCodeMachineMenu {
|
|
112
|
+
startable: PwCodeMachineChoice[];
|
|
113
|
+
down: PwCodeMachineChoice[];
|
|
114
|
+
downLabel: string | undefined;
|
|
115
|
+
/** Picks a machine; the one picked already stays as it is. */
|
|
116
|
+
pick: (id: string) => void;
|
|
117
|
+
}
|
|
118
|
+
export declare function machineMenu<M extends PwCodeStartMachine>(location: Pick<PwCodeStartLocation<M>, 'startable' | 'down' | 'machine' | 'pickMachine'>, t: Translate): PwCodeMachineMenu;
|
|
119
|
+
/** The chip naming the machine a session starts on, which opens the
|
|
120
|
+
* `machineMenu`: the machine's name after a dot in the `success` tone, since
|
|
121
|
+
* only a machine that answers can be chosen, or, until one is, a call to
|
|
122
|
+
* choose one and no dot. While the machines are still being listed
|
|
123
|
+
* (`finding`), it says so and opens nothing. `label` names the chip's action. */
|
|
124
|
+
export declare function machineChip(machine: Pick<PwCodeStartMachine, 'name'> | undefined, t: Translate, finding?: boolean): {
|
|
125
|
+
text: string;
|
|
126
|
+
label: string;
|
|
127
|
+
dot: 'success' | null;
|
|
128
|
+
};
|
|
129
|
+
/** A chat handed to a new session, while it loads or once it failed to. */
|
|
130
|
+
export interface PwCodeStartHandoff {
|
|
131
|
+
conversation: PwCodeHandoffChat | undefined;
|
|
132
|
+
error: unknown;
|
|
133
|
+
}
|
|
134
|
+
/** How a start carries a chat handed to it: it waits until the chat has
|
|
135
|
+
* arrived, since starting sooner would quietly leave it behind, then sends
|
|
136
|
+
* the chat after what was typed. A chat that failed to load holds nothing
|
|
137
|
+
* back. */
|
|
138
|
+
export declare function chatHandoffStart(handoff: PwCodeStartHandoff | undefined, t: Translate,
|
|
139
|
+
/** Words a failure for the reader. */
|
|
140
|
+
describeError: (error: unknown) => string): {
|
|
141
|
+
waiting: boolean;
|
|
142
|
+
firstPrompt: ((typed: string) => string) | undefined;
|
|
143
|
+
/** The composer's placeholder; once the chat has arrived, it asks what to do with it. */
|
|
144
|
+
placeholder: string;
|
|
145
|
+
/** The card above the composer naming the chat, or saying it is loading
|
|
146
|
+
* or why it failed to, which is a warning; null without a chat. */
|
|
147
|
+
notice: {
|
|
148
|
+
text: string;
|
|
149
|
+
failed: boolean;
|
|
150
|
+
tone: 'neutral' | 'warning';
|
|
151
|
+
} | null;
|
|
152
|
+
};
|
|
153
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { chatHandoffPrompt } from "./chatHandoff.js";
|
|
2
|
+
import { paletteOptions } from "./command.js";
|
|
3
|
+
import { loadErrorMessage } from "./loadError.js";
|
|
4
|
+
import { isComputer } from "./machine.js";
|
|
5
|
+
import { runsClaude } from "./models.js";
|
|
6
|
+
import { isActiveSession } from "./session.js";
|
|
7
|
+
import { approvalToPart } from "./transcript.js";
|
|
8
|
+
import { machineHint, sessionStateText } from "./wording.js";
|
|
9
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
10
|
+
// src/startPage.ts
|
|
11
|
+
/** As many sessions as a new chat offers starters, so the page fits. */
|
|
12
|
+
var START_SHORTLIST = 4;
|
|
13
|
+
/** The sessions a start page offers to pick back up: the live ones, then the
|
|
14
|
+
* idle ones, each newest first as `triageSessions` orders them. */
|
|
15
|
+
function startShortlist(triage, size = 4) {
|
|
16
|
+
return [...triage.active, ...triage.idle].slice(0, size);
|
|
17
|
+
}
|
|
18
|
+
/** A shortlisted session that is live shows a mark named by its state, which
|
|
19
|
+
* nothing else on its row spells out; one at rest shows none. */
|
|
20
|
+
function shortlistMark(session, machine, t) {
|
|
21
|
+
return isActiveSession(session) ? { label: sessionStateText(session, machine, t) } : null;
|
|
22
|
+
}
|
|
23
|
+
/** When a session began waiting on the reader: its first pending question,
|
|
24
|
+
* else its last change. */
|
|
25
|
+
function waitingSince(s) {
|
|
26
|
+
return s.approvals?.[0]?.createdAt ?? s.updatedAt;
|
|
27
|
+
}
|
|
28
|
+
/** What a session waiting on the reader asks, answerable where it is listed,
|
|
29
|
+
* or, when the listing carries none of its questions, `inSession`: a line
|
|
30
|
+
* sending the reader into the session to answer. */
|
|
31
|
+
function waitingQuestions(s, words, t) {
|
|
32
|
+
const questions = (s.approvals ?? []).map((req) => approvalToPart(req, words));
|
|
33
|
+
return {
|
|
34
|
+
questions,
|
|
35
|
+
inSession: questions.length > 0 ? null : t("dash.answerInSession")
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function useStartScreen(api, { location, describeError }) {
|
|
39
|
+
const { data, error, mutate } = api.useSessions();
|
|
40
|
+
const answer = useCallback(async (session, approvalId, value) => {
|
|
41
|
+
const refusal = await api.answerApproval(session.machineId, session.id, approvalId, value);
|
|
42
|
+
if (refusal) return describeError(refusal);
|
|
43
|
+
mutate();
|
|
44
|
+
return null;
|
|
45
|
+
}, [
|
|
46
|
+
api,
|
|
47
|
+
describeError,
|
|
48
|
+
mutate
|
|
49
|
+
]);
|
|
50
|
+
const loading = data === void 0;
|
|
51
|
+
return {
|
|
52
|
+
loading,
|
|
53
|
+
failed: error && !data ? { message: loadErrorMessage(error, describeError) } : null,
|
|
54
|
+
showComposer: loading || location.startable.length > 0 || location.down.length > 0,
|
|
55
|
+
explainEmpty: !loading && (data.sessions ?? []).length === 0,
|
|
56
|
+
answer
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The start page's parameters from its parsed query; any that is not a
|
|
60
|
+
* single string is left out. */
|
|
61
|
+
function startSearch(search) {
|
|
62
|
+
const text = (value) => typeof value === "string" ? value : void 0;
|
|
63
|
+
return {
|
|
64
|
+
session: text(search["session"]),
|
|
65
|
+
fromChat: text(search["fromChat"])
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Follows a link that names only a session, since the machine listed with
|
|
69
|
+
* it is not known where the link was printed: once the listing names the
|
|
70
|
+
* session, `open` takes it to the session. */
|
|
71
|
+
function useSessionLink(session, listing, open) {
|
|
72
|
+
const found = session ? listing.sessions.find((s) => s.id === session) : void 0;
|
|
73
|
+
const latest = useRef(open);
|
|
74
|
+
latest.current = open;
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (found) latest.current(found);
|
|
77
|
+
}, [found]);
|
|
78
|
+
if (!session) return null;
|
|
79
|
+
return found || listing.loading ? "resolving" : "missing";
|
|
80
|
+
}
|
|
81
|
+
/** The card over the composer while a link to a session is followed: news
|
|
82
|
+
* while it is looked for, a warning once the listing lacks it. Null without
|
|
83
|
+
* a link. */
|
|
84
|
+
function sessionLinkNotice(state, session, t) {
|
|
85
|
+
if (state === null) return null;
|
|
86
|
+
const missing = state === "missing";
|
|
87
|
+
const values = { id: session ?? "" };
|
|
88
|
+
return {
|
|
89
|
+
text: missing ? t("start.linkMissing", values) : t("start.linkResolving", values),
|
|
90
|
+
tone: missing ? "warning" : "neutral"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The commands a new session's composer offers: the directory's palette,
|
|
94
|
+
* led by the Claude Code account choice on a machine where Claude Code
|
|
95
|
+
* runs. Archiving needs a session, so it is not offered. */
|
|
96
|
+
function startCommands(palette, machine, t) {
|
|
97
|
+
return paletteOptions(palette, runsClaude(machine) ? t("claude.choose") : void 0);
|
|
98
|
+
}
|
|
99
|
+
function machineMenu(location, t) {
|
|
100
|
+
const picked = location.machine?.id;
|
|
101
|
+
const startable = location.startable.map((m) => ({
|
|
102
|
+
id: m.id,
|
|
103
|
+
label: m.name,
|
|
104
|
+
description: isComputer(m) ? t("machine.computer") : t("machine.resource"),
|
|
105
|
+
checked: m.id === picked,
|
|
106
|
+
disabled: false
|
|
107
|
+
}));
|
|
108
|
+
const down = location.down.map((m) => ({
|
|
109
|
+
id: m.id,
|
|
110
|
+
label: m.name,
|
|
111
|
+
description: machineHint(m, t)?.text,
|
|
112
|
+
checked: false,
|
|
113
|
+
disabled: true
|
|
114
|
+
}));
|
|
115
|
+
return {
|
|
116
|
+
startable,
|
|
117
|
+
down,
|
|
118
|
+
downLabel: startable.length > 0 && down.length > 0 ? t("start.notAnswering", { count: down.length }) : void 0,
|
|
119
|
+
pick: (id) => {
|
|
120
|
+
if (id !== picked) location.pickMachine(id);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** The chip naming the machine a session starts on, which opens the
|
|
125
|
+
* `machineMenu`: the machine's name after a dot in the `success` tone, since
|
|
126
|
+
* only a machine that answers can be chosen, or, until one is, a call to
|
|
127
|
+
* choose one and no dot. While the machines are still being listed
|
|
128
|
+
* (`finding`), it says so and opens nothing. `label` names the chip's action. */
|
|
129
|
+
function machineChip(machine, t, finding = false) {
|
|
130
|
+
if (finding) {
|
|
131
|
+
const text = t("start.findingMachines");
|
|
132
|
+
return {
|
|
133
|
+
text,
|
|
134
|
+
label: text,
|
|
135
|
+
dot: null
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const choose = t("start.chooseMachine");
|
|
139
|
+
return machine ? {
|
|
140
|
+
text: machine.name,
|
|
141
|
+
label: choose,
|
|
142
|
+
dot: "success"
|
|
143
|
+
} : {
|
|
144
|
+
text: choose,
|
|
145
|
+
label: choose,
|
|
146
|
+
dot: null
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** How a start carries a chat handed to it: it waits until the chat has
|
|
150
|
+
* arrived, since starting sooner would quietly leave it behind, then sends
|
|
151
|
+
* the chat after what was typed. A chat that failed to load holds nothing
|
|
152
|
+
* back. */
|
|
153
|
+
function chatHandoffStart(handoff, t, describeError) {
|
|
154
|
+
const conversation = handoff?.conversation;
|
|
155
|
+
return {
|
|
156
|
+
waiting: !!handoff && !conversation && !handoff.error,
|
|
157
|
+
firstPrompt: conversation ? (typed) => chatHandoffPrompt(conversation, typed, t) : void 0,
|
|
158
|
+
placeholder: conversation ? t("start.handoffPlaceholder") : t("start.composerPlaceholder"),
|
|
159
|
+
notice: handoff ? handoffNotice(handoff, t, describeError) : null
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function handoffNotice({ conversation, error }, t, describeError) {
|
|
163
|
+
if (error) return {
|
|
164
|
+
text: describeError(error),
|
|
165
|
+
failed: true,
|
|
166
|
+
tone: "warning"
|
|
167
|
+
};
|
|
168
|
+
return {
|
|
169
|
+
text: conversation ? t("start.handoffCard", { title: conversation.title || t("start.handoffUntitled") }) : t("start.handoffLoading"),
|
|
170
|
+
failed: false,
|
|
171
|
+
tone: "neutral"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export { START_SHORTLIST, chatHandoffStart, machineChip, machineMenu, sessionLinkNotice, shortlistMark, startCommands, startSearch, startShortlist, useSessionLink, useStartScreen, waitingQuestions, waitingSince };
|
|
@@ -0,0 +1,172 @@
|
|
|
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, else the one picked last time, 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'>[],
|
|
47
|
+
/** The machine the host saved the last pick of. */
|
|
48
|
+
preference?: {
|
|
49
|
+
saved: string | undefined;
|
|
50
|
+
remember: (id: string) => void;
|
|
51
|
+
}): PwCodeStartLocation<M>;
|
|
52
|
+
export interface PwCodeStartPermission {
|
|
53
|
+
mode: PermissionMode;
|
|
54
|
+
pick: (mode: PermissionMode) => void;
|
|
55
|
+
/** The widest mode the machine lets a picker offer, for `permissionModesUpTo`. */
|
|
56
|
+
ceiling: string | undefined;
|
|
57
|
+
/** The modes the machine's pw code takes, for `permissionModesUpTo`. */
|
|
58
|
+
accepted: readonly string[] | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** The mode a session starts in: the one saved, or one picked on this visit,
|
|
61
|
+
* within what the machine allows. A pick holds until the visit ends, so one
|
|
62
|
+
* the host declines to save, such as bypass, still applies to this start. */
|
|
63
|
+
export declare function useStartPermissionMode(preference: {
|
|
64
|
+
saved: PermissionMode;
|
|
65
|
+
remember: (mode: PermissionMode) => void;
|
|
66
|
+
}, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): PwCodeStartPermission;
|
|
67
|
+
/** Which of a start's controls can change, each disabled while true. */
|
|
68
|
+
export interface PwCodeStartControls {
|
|
69
|
+
disabled: {
|
|
70
|
+
model: boolean;
|
|
71
|
+
effort: boolean;
|
|
72
|
+
allocation: boolean;
|
|
73
|
+
/** The account, as its panel and the model picker change it. */
|
|
74
|
+
account: boolean;
|
|
75
|
+
/** The chip naming the account, which opens its panel. */
|
|
76
|
+
accountChip: boolean;
|
|
77
|
+
/** Removing an image waiting to go with the first prompt. */
|
|
78
|
+
images: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** A session can start on the machine, so the model picker reads its Claude
|
|
81
|
+
* models before it opens. */
|
|
82
|
+
canStart: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** The model, effort, allocation, account and images hold while a session
|
|
85
|
+
* starts. The permission mode, machine and directory are not held, and a pick
|
|
86
|
+
* there reaches only the next start. Until a machine is chosen, its model,
|
|
87
|
+
* effort and account chip wait for one too. */
|
|
88
|
+
export declare function startControls(machine: Pick<PwCodeStartMachine, 'status' | 'remoteStart'> | undefined, starting: boolean): PwCodeStartControls;
|
|
89
|
+
type ClaudeMachine = Pick<PwCodeStartMachine, 'id' | 'claudeInstalled' | 'claudeCodeAllowed'>;
|
|
90
|
+
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'useSessions'>;
|
|
91
|
+
/** A model last picked for a session, and the allocation that billed it. */
|
|
92
|
+
export interface PwCodeLastModel {
|
|
93
|
+
model?: string | undefined;
|
|
94
|
+
allocation?: string | undefined;
|
|
95
|
+
}
|
|
96
|
+
/** The model, allocation and Claude Code account a session starts on. */
|
|
97
|
+
export interface PwCodeStartModel {
|
|
98
|
+
model: string | null | undefined;
|
|
99
|
+
allocation: string | null | undefined;
|
|
100
|
+
account: string | undefined;
|
|
101
|
+
/** The account picked on this visit, rather than one remembered. */
|
|
102
|
+
pickedAccount: string | undefined;
|
|
103
|
+
pickModel: (model: string) => void;
|
|
104
|
+
pickAllocation: (allocation: string) => void;
|
|
105
|
+
/** Picks the account and remembers it for the machine. */
|
|
106
|
+
pickAccount: (account: string) => void;
|
|
107
|
+
}
|
|
108
|
+
/** Picks hold for the machine they were made on. Until then a session starts
|
|
109
|
+
* on the model last picked where the machine and the platform still offer
|
|
110
|
+
* it, else on the host's selected one, and on the account saved for the
|
|
111
|
+
* machine where the machine still lists it. */
|
|
112
|
+
export declare function useStartModel(api: Pick<StartApi, 'useClaudeModels' | 'useClaudeAccountNames'>, { machine, platform, last, account: accountPreference, handedOff, }: {
|
|
113
|
+
machine: ClaudeMachine | undefined;
|
|
114
|
+
/** The platform's models and the host's selected model and allocation,
|
|
115
|
+
* such as its chat's; `usePlatformDefaults` gives all three to a host
|
|
116
|
+
* without one. */
|
|
117
|
+
platform: {
|
|
118
|
+
/** The platform's models: undefined while they load, or when they failed to. */
|
|
119
|
+
models: readonly {
|
|
120
|
+
id: string;
|
|
121
|
+
}[] | undefined;
|
|
122
|
+
model: string | null | undefined;
|
|
123
|
+
allocation: string | null | undefined;
|
|
124
|
+
};
|
|
125
|
+
last: PwCodeLastModel;
|
|
126
|
+
/** The Claude Code account saved for this machine. */
|
|
127
|
+
account: {
|
|
128
|
+
saved: string | undefined;
|
|
129
|
+
remember: (account: string) => void;
|
|
130
|
+
};
|
|
131
|
+
/** A chat handed off to the session, which keeps the host's selected model. */
|
|
132
|
+
handedOff: boolean;
|
|
133
|
+
}): PwCodeStartModel;
|
|
134
|
+
/** Images that wait to go with a session's first prompt. */
|
|
135
|
+
export interface PwCodeStartImages {
|
|
136
|
+
count: number;
|
|
137
|
+
/** Saves them with the session; null when one could not be saved, which
|
|
138
|
+
* the host reports. */
|
|
139
|
+
saveTo: (machine: string, sessionId: string) => Promise<PwCodeImageRef[] | null>;
|
|
140
|
+
}
|
|
141
|
+
export interface PwCodeStartSession {
|
|
142
|
+
/** A machine and an absolute directory are chosen, and nothing holds the start back. */
|
|
143
|
+
ready: boolean;
|
|
144
|
+
starting: boolean;
|
|
145
|
+
/** Why the last start failed: the machine's refusal, or what was thrown. */
|
|
146
|
+
error: unknown;
|
|
147
|
+
/** Starts the session with `prompt` as its first message. False hands the
|
|
148
|
+
* prompt back to the composer. */
|
|
149
|
+
start: (prompt: string) => Promise<boolean>;
|
|
150
|
+
}
|
|
151
|
+
/** Starts a session, reads the listing again so it shows there, and hands it
|
|
152
|
+
* to `onStarted` once its first prompt is sent. With images, the session is
|
|
153
|
+
* created first and they are saved with it; a retry after they fail reuses
|
|
154
|
+
* that session while nothing it started with has changed. */
|
|
155
|
+
export declare function useStartSession(api: Pick<StartApi, 'createSession' | 'sendMessage' | 'useSessions'>, options: {
|
|
156
|
+
machine: Pick<PwCodeStartMachine, 'id' | 'claudeCodeAllowed'> | undefined;
|
|
157
|
+
directory: string;
|
|
158
|
+
mode: PermissionMode;
|
|
159
|
+
model: string | null | undefined;
|
|
160
|
+
/** Empty starts at the machine's own level. */
|
|
161
|
+
effort: EffortLevel | '';
|
|
162
|
+
allocation: string | null | undefined;
|
|
163
|
+
account: string | undefined;
|
|
164
|
+
images?: PwCodeStartImages | undefined;
|
|
165
|
+
/** The first message to send for what the reader typed. */
|
|
166
|
+
firstPrompt?: ((typed: string) => string) | undefined;
|
|
167
|
+
/** Something the first message needs has not arrived yet. */
|
|
168
|
+
waiting?: boolean | undefined;
|
|
169
|
+
/** The host opens the session. */
|
|
170
|
+
onStarted: (machine: string, sessionId: string) => void;
|
|
171
|
+
}): PwCodeStartSession;
|
|
172
|
+
export {};
|