@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
package/dist/commandsApi.js
CHANGED
|
@@ -3,6 +3,16 @@ import { shellCommand, slashAction } from "./command.js";
|
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
// src/commandsApi.ts
|
|
5
5
|
var backgroundOfferDelayMs = 2e3;
|
|
6
|
+
/** The tool whose running calls the machine can move to the background. */
|
|
7
|
+
var BACKGROUND_TOOL = "Bash";
|
|
8
|
+
function runsInBackgroundTool(part) {
|
|
9
|
+
return part.name === "Bash" && part.status === "running";
|
|
10
|
+
}
|
|
11
|
+
/** The offer to move a turn's commands to the background sits under each of
|
|
12
|
+
* its running `BACKGROUND_TOOL` calls, once the session makes it. */
|
|
13
|
+
function offersBackground(part, background) {
|
|
14
|
+
return !!background?.offered && runsInBackgroundTool(part);
|
|
15
|
+
}
|
|
6
16
|
function planOutcome(plan, args, planOnMachine) {
|
|
7
17
|
switch (plan.action) {
|
|
8
18
|
case "answer": return {
|
|
@@ -45,6 +55,17 @@ function settle(outcome, command, kind, deps) {
|
|
|
45
55
|
function commandsApi(client) {
|
|
46
56
|
const useQuery = createQuery(client);
|
|
47
57
|
const palettes = /* @__PURE__ */ new Map();
|
|
58
|
+
/** Runs /goal with the terminal's arguments, answering with the goal as the
|
|
59
|
+
* call left it. A bare `edit` only reads it. */
|
|
60
|
+
function runGoal(machine, id, args) {
|
|
61
|
+
return client.POST("/api/code/machines/{machine}/sessions/{id}/goal", {
|
|
62
|
+
params: { path: {
|
|
63
|
+
machine,
|
|
64
|
+
id
|
|
65
|
+
} },
|
|
66
|
+
body: { args }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
48
69
|
/** Runs a command against the session's daemon, answering with what the
|
|
49
70
|
* host owes next. /plan's actions follow the terminal's, except that opening
|
|
50
71
|
* the plan file needs the machine's own editor. */
|
|
@@ -79,10 +100,7 @@ function commandsApi(client) {
|
|
|
79
100
|
};
|
|
80
101
|
}
|
|
81
102
|
case "goal": {
|
|
82
|
-
const { data, error } = await
|
|
83
|
-
...path,
|
|
84
|
-
body: { args: action.args }
|
|
85
|
-
});
|
|
103
|
+
const { data, error } = await runGoal(machine, id, action.args);
|
|
86
104
|
return error ? {
|
|
87
105
|
kind: "refused",
|
|
88
106
|
error
|
|
@@ -256,6 +274,7 @@ function commandsApi(client) {
|
|
|
256
274
|
});
|
|
257
275
|
}
|
|
258
276
|
return {
|
|
277
|
+
runGoal,
|
|
259
278
|
runSlashAction,
|
|
260
279
|
resolveTyped,
|
|
261
280
|
usePalette,
|
|
@@ -264,4 +283,4 @@ function commandsApi(client) {
|
|
|
264
283
|
requestRecap
|
|
265
284
|
};
|
|
266
285
|
}
|
|
267
|
-
export { backgroundOfferDelayMs, commandsApi };
|
|
286
|
+
export { BACKGROUND_TOOL, backgroundOfferDelayMs, commandsApi, offersBackground, runsInBackgroundTool };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type LabeledPullRequest, type PullRequestStateOf } from './pullRequestList.js';
|
|
2
|
+
import type { PwCodeAddedDirectory, PwCodeAllowedDirectory } from './types.js';
|
|
3
|
+
/** What a session's context shows besides its working directory and goal. */
|
|
4
|
+
export interface PwCodeContextRow {
|
|
5
|
+
/** The directories added to the session. */
|
|
6
|
+
added: PwCodeAddedDirectory[];
|
|
7
|
+
/** The directories approvals opened for the session. */
|
|
8
|
+
allowed: PwCodeAllowedDirectory[];
|
|
9
|
+
/** In `orderPullRequests` order. */
|
|
10
|
+
pullRequests: LabeledPullRequest[];
|
|
11
|
+
stateOf: PullRequestStateOf;
|
|
12
|
+
/** For each of `pullRequests`, whether it folds into the merged-or-closed count. */
|
|
13
|
+
foldGroups: boolean[];
|
|
14
|
+
}
|
|
15
|
+
/** A session's context from its detail and the states read for its pull
|
|
16
|
+
* requests, which come from the URLs `labeledPullRequests` keeps. */
|
|
17
|
+
export declare function sessionContextRow({ added, allowed, pullRequests, states, }: {
|
|
18
|
+
added: PwCodeAddedDirectory[] | null | undefined;
|
|
19
|
+
allowed: PwCodeAllowedDirectory[] | null | undefined;
|
|
20
|
+
pullRequests: readonly string[] | null | undefined;
|
|
21
|
+
states: readonly {
|
|
22
|
+
url: string;
|
|
23
|
+
state?: string | undefined;
|
|
24
|
+
}[] | undefined;
|
|
25
|
+
}): PwCodeContextRow;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { labeledPullRequests, orderPullRequests, pullRequestFoldGroups, pullRequestStateOf } from "./pullRequestList.js";
|
|
2
|
+
// src/contextRow.ts
|
|
3
|
+
/** A session's context from its detail and the states read for its pull
|
|
4
|
+
* requests, which come from the URLs `labeledPullRequests` keeps. */
|
|
5
|
+
function sessionContextRow({ added, allowed, pullRequests, states }) {
|
|
6
|
+
const stateOf = pullRequestStateOf(states);
|
|
7
|
+
const ordered = orderPullRequests(labeledPullRequests(pullRequests), stateOf);
|
|
8
|
+
return {
|
|
9
|
+
added: added ?? [],
|
|
10
|
+
allowed: allowed ?? [],
|
|
11
|
+
pullRequests: ordered,
|
|
12
|
+
stateOf,
|
|
13
|
+
foldGroups: pullRequestFoldGroups(ordered, stateOf)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { sessionContextRow };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Client } from 'openapi-fetch';
|
|
2
|
-
import
|
|
2
|
+
import { type PwCodeAccountOptions } from './accountApi.js';
|
|
3
|
+
import type { PwCodeApiError, PwCodePaths, Schemas } from './apiClient.js';
|
|
3
4
|
import { type PwCodeSocketOptions } from './sessionEvents.js';
|
|
4
|
-
|
|
5
|
+
import { type PwCodeSessionOptions } from './sessionsApi.js';
|
|
6
|
+
export type PwCodeApiOptions = PwCodeSocketOptions & PwCodeAccountOptions & PwCodeSessionOptions;
|
|
5
7
|
/** Refuses a client whose API types lack a route this package calls, or type
|
|
6
8
|
* one differently, naming the routes it lacks. */
|
|
7
9
|
type CoversPwCodeRoutes<P> = [P] extends [PwCodePaths] ? unknown : {
|
|
@@ -50,7 +52,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
50
52
|
}[];
|
|
51
53
|
loadedUsage: boolean;
|
|
52
54
|
loading: boolean;
|
|
53
|
-
error:
|
|
55
|
+
error: PwCodeApiError | undefined;
|
|
54
56
|
refreshing: boolean;
|
|
55
57
|
refresh: () => Promise<void>;
|
|
56
58
|
};
|
|
@@ -59,6 +61,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
59
61
|
writeClaudeLogin: (machine: string, loginId: string, input: import("./claudeApi.js").ClaudeLoginInput) => Promise<void>;
|
|
60
62
|
cancelClaudeLogin: (machine: string, loginId: string) => Promise<void>;
|
|
61
63
|
followClaudeLogin: (machine: string, login: import("./claudeApi.js").ClaudeLogin, after: number, signal: AbortSignal, receive: (event: import("./claudeApi.js").ClaudeLoginEvent) => void) => Promise<void>;
|
|
64
|
+
runGoal: (machine: string, id: string, args: string) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentGoalResult']>>;
|
|
62
65
|
runSlashAction: (machine: string, id: string, action: Exclude<import("./command.js").SlashAction, {
|
|
63
66
|
kind: 'message' | 'archive';
|
|
64
67
|
}>, planOnMachine: (path: string) => string) => Promise<import("./commandsApi.js").CommandOutcome>;
|
|
@@ -96,6 +99,32 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
96
99
|
move: () => Promise<void>;
|
|
97
100
|
};
|
|
98
101
|
requestRecap: (machine: string, id: string, signal?: AbortSignal) => Promise<import("./apiClient.js").PwCodeResult<undefined>>;
|
|
102
|
+
listDirectories: (machine: string, path: string, filter?: string) => Promise<import("./apiClient.js").PwCodeResult<import("./directories.js").PwCodeDirectories>>;
|
|
103
|
+
useDirectories: (machine: string | undefined, path: string | null, filter?: string) => import("./apiClient.js").PwCodeQuery<import("./directories.js").PwCodeDirectories>;
|
|
104
|
+
usePathCompletion: ({ machine, typed, untouched, recents, describeError, }: {
|
|
105
|
+
machine: Pick<Schemas['AgentMachine'], 'id' | 'directories'> | undefined;
|
|
106
|
+
typed: string;
|
|
107
|
+
untouched: boolean;
|
|
108
|
+
recents: readonly import("./session.js").RecentDirectory[];
|
|
109
|
+
describeError: (error: unknown) => string;
|
|
110
|
+
}) => {
|
|
111
|
+
rows: import("./directories.js").PwCodePathRow[];
|
|
112
|
+
sections: import("./directories.js").PwCodePathSection[];
|
|
113
|
+
note: string | null;
|
|
114
|
+
canBrowse: boolean;
|
|
115
|
+
browseFrom: string;
|
|
116
|
+
cut: boolean;
|
|
117
|
+
listing: import("./directories.js").PwCodeDirectories | undefined;
|
|
118
|
+
loading: boolean;
|
|
119
|
+
error: unknown;
|
|
120
|
+
};
|
|
121
|
+
useDirectoryTree: (machine: Pick<Schemas['AgentMachine'], 'id' | 'name'>, from: string) => {
|
|
122
|
+
root: string | undefined;
|
|
123
|
+
title: string;
|
|
124
|
+
above: string | null;
|
|
125
|
+
goUp: () => void;
|
|
126
|
+
error: unknown;
|
|
127
|
+
};
|
|
99
128
|
useSessions: () => import("./apiClient.js").PwCodeQuery<{
|
|
100
129
|
machines: import("./api.js").components["schemas"]["AgentMachine"][] | null;
|
|
101
130
|
sessions: import("./api.js").components["schemas"]["AgentSession"][] | null;
|
|
@@ -173,7 +202,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
173
202
|
workspace: string;
|
|
174
203
|
workspaceUntrusted?: boolean;
|
|
175
204
|
} | undefined;
|
|
176
|
-
error:
|
|
205
|
+
error: PwCodeApiError | undefined;
|
|
177
206
|
isLoading: boolean;
|
|
178
207
|
mutate: import("swr").KeyedMutator<{
|
|
179
208
|
addDirs?: import("./api.js").components["schemas"]["AddedDirectory"][] | null;
|
|
@@ -222,7 +251,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
222
251
|
state?: "open" | "draft" | "merged" | "closed";
|
|
223
252
|
url: string;
|
|
224
253
|
}[]) => void) => import("./apiClient.js").PwCodeQuery<Schemas['AgentPullRequests']>;
|
|
225
|
-
useSessionPullRequestStates: (machine: string, id: string,
|
|
254
|
+
useSessionPullRequestStates: (machine: string, id: string, pullRequests: readonly string[] | null | undefined) => {
|
|
226
255
|
url: string;
|
|
227
256
|
state: string | undefined;
|
|
228
257
|
}[] | undefined;
|
|
@@ -636,13 +665,23 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
636
665
|
}>>;
|
|
637
666
|
sendMessage: (machine: string, id: string, body: Schemas['SendMessageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentMessageAccepted']>>;
|
|
638
667
|
steer: (machine: string, id: string, body: Schemas['AgentDirectionBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionDelivered']>>;
|
|
668
|
+
withdrawDirection: (machine: string, id: string, ids: string[]) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionWithdrawn']>>;
|
|
639
669
|
withdrawQueued: (machine: string, id: string, turnId: string) => Promise<import("./apiClient.js").PwCodeResult<undefined>>;
|
|
640
670
|
messageSubagent: (machine: string, id: string, subId: string, body: Schemas['SendMessageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentMessageAccepted']>>;
|
|
641
671
|
steerSubagent: (machine: string, id: string, subId: string, body: Schemas['AgentDirectionBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionDelivered']>>;
|
|
672
|
+
withdrawSubagentDirection: (machine: string, id: string, subId: string, ids: string[]) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionWithdrawn']>>;
|
|
642
673
|
saveImage: (machine: string, id: string, body: Schemas['AgentImageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentImageSaved']>>;
|
|
643
674
|
answerApproval: (machine: string, sessionId: string, approvalId: string, answer: import("@parallelworks/ui/ai/headless").ApprovalAnswerValue) => Promise<unknown>;
|
|
644
675
|
removeSessionDirectory: (machine: string, sessionId: string, path: string) => Promise<unknown>;
|
|
645
676
|
uploadPaste: (machine: string, sessionId: string, text: string, describe: (error: unknown) => string) => Promise<import("./sessionsApi.js").PwCodePasteUpload>;
|
|
677
|
+
updateSessionSettings: (machine: string, id: string, body: {
|
|
678
|
+
allocation?: string;
|
|
679
|
+
claudeAccount?: string;
|
|
680
|
+
effort?: "default" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
681
|
+
model?: string;
|
|
682
|
+
permissionMode?: "read-only" | "accept-edits" | "auto" | "bypass-permissions";
|
|
683
|
+
}) => Promise<import("./apiClient.js").PwCodeResult<Schemas['SessionState']>>;
|
|
684
|
+
useSessionSettings: ({ machine, sessionId, model, effort, allocation, claudeAccount, nativeAllocation, locked, live, onPatched, onError, onModePicked, onEffortPicked, onAccountSaved, }: import("./settingsApi.js").PwCodeSessionSettingsOptions) => import("./settingsApi.js").PwCodeSessionSettings;
|
|
646
685
|
useMachines: () => Schemas['AgentMachine'][];
|
|
647
686
|
useSessionEvents: (machine: string, id: string, cursor: (() => number) | undefined, onEvent: (event: {
|
|
648
687
|
agentType?: string;
|
|
@@ -683,6 +722,14 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
|
|
|
683
722
|
connected: boolean;
|
|
684
723
|
disconnected: boolean;
|
|
685
724
|
};
|
|
725
|
+
useChatHandoff: (chat: string | undefined) => {
|
|
726
|
+
conversation: Schemas['ConversationResponse'] | undefined;
|
|
727
|
+
error: PwCodeApiError | undefined;
|
|
728
|
+
} | undefined;
|
|
729
|
+
usePlatformModels: () => import("./accountApi.js").PwCodePlatformModels;
|
|
730
|
+
useAllocations: (read?: boolean) => import("./apiClient.js").PwCodeQuery<Schemas['Allocation'][] | null>;
|
|
731
|
+
usePwCodeEnabled: () => boolean | undefined;
|
|
732
|
+
usePreference: <T>(key: string, fallback: T) => [T, import("react").Dispatch<import("react").SetStateAction<T>>];
|
|
686
733
|
};
|
|
687
734
|
export type PwCodeApi = ReturnType<typeof createPwCodeApi>;
|
|
688
735
|
export {};
|
package/dist/createPwCodeApi.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { accountApi } from "./accountApi.js";
|
|
1
2
|
import { claudeApi } from "./claudeApi.js";
|
|
2
3
|
import { commandsApi } from "./commandsApi.js";
|
|
4
|
+
import { directoriesApi } from "./directories.js";
|
|
5
|
+
import { createQuery } from "./query.js";
|
|
3
6
|
import { reachedByFeed, sessionEvents } from "./sessionEvents.js";
|
|
4
7
|
import { sessionsApi } from "./sessionsApi.js";
|
|
8
|
+
import { settingsApi } from "./settingsApi.js";
|
|
5
9
|
import { useMemo } from "react";
|
|
6
10
|
// src/createPwCodeApi.ts
|
|
7
11
|
/** The calls and data hooks of pw code sessions over the host's API client,
|
|
@@ -10,8 +14,18 @@ import { useMemo } from "react";
|
|
|
10
14
|
* `@parallelworks/client/swr`'s are, and the open feeds it counts are its own. */
|
|
11
15
|
function createPwCodeApi(client, options = {}) {
|
|
12
16
|
const routes = client;
|
|
13
|
-
const
|
|
17
|
+
const useQuery = createQuery(routes);
|
|
18
|
+
const sessions = sessionsApi(routes, options);
|
|
14
19
|
const { useSessionEvents, useFedMachines } = sessionEvents(options);
|
|
20
|
+
/** The AI chat a new session is to carry on, for `chatHandoffStart`;
|
|
21
|
+
* undefined without one. */
|
|
22
|
+
function useChatHandoff(chat) {
|
|
23
|
+
const { data, error } = useQuery("/api/aichat/conversations/{id}", chat ? { params: { path: { id: chat } } } : null);
|
|
24
|
+
return chat ? {
|
|
25
|
+
conversation: data,
|
|
26
|
+
error
|
|
27
|
+
} : void 0;
|
|
28
|
+
}
|
|
15
29
|
/** The listing's machines. One with a session feed open counts as connected
|
|
16
30
|
* whatever the poll says: the feed is the machine answering, and the polled
|
|
17
31
|
* listing can lose a machine it still reaches. */
|
|
@@ -23,9 +37,13 @@ function createPwCodeApi(client, options = {}) {
|
|
|
23
37
|
return {
|
|
24
38
|
...sessions,
|
|
25
39
|
...commandsApi(routes),
|
|
40
|
+
...directoriesApi(routes),
|
|
26
41
|
...claudeApi(routes),
|
|
42
|
+
...settingsApi(routes),
|
|
43
|
+
...accountApi(routes, options),
|
|
27
44
|
useMachines,
|
|
28
|
-
useSessionEvents
|
|
45
|
+
useSessionEvents,
|
|
46
|
+
useChatHandoff
|
|
29
47
|
};
|
|
30
48
|
}
|
|
31
49
|
export { createPwCodeApi };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { PwCodeClient, PwCodeQuery, PwCodeResult, Schemas } from './apiClient.js';
|
|
2
|
+
import { type PwCodeTranslator } from './messages.js';
|
|
3
|
+
import { type RecentDirectory } from './session.js';
|
|
4
|
+
type Translate = PwCodeTranslator<'agents'>;
|
|
5
|
+
/** The folders in one directory of a machine. */
|
|
6
|
+
export type PwCodeDirectories = Schemas['AgentDirectories'];
|
|
7
|
+
/** What typed text points at: the directory to list, and the start of a folder's name in it. */
|
|
8
|
+
export interface TypedPath {
|
|
9
|
+
parent: string;
|
|
10
|
+
partial: string;
|
|
11
|
+
}
|
|
12
|
+
/** Text that starts at neither the root nor ~ is read from the home directory, so a bare name finds a folder there. */
|
|
13
|
+
export declare function splitTypedPath(typed: string): TypedPath;
|
|
14
|
+
/** The absolute path typed text names, with ~ read as `home`; null while it names none. */
|
|
15
|
+
export declare function typedDirectory(typed: string, home: string | undefined): string | null;
|
|
16
|
+
export declare const joinDirectory: (parent: string, name: string) => string;
|
|
17
|
+
/** The directory that holds `path`; null at the root. */
|
|
18
|
+
export declare function parentDirectory(path: string): string | null;
|
|
19
|
+
/** A path as the field holds it while its folders are listed: it ends at a separator. */
|
|
20
|
+
export declare const listedText: (path: string) => string;
|
|
21
|
+
/** One row a path field offers under what is typed. */
|
|
22
|
+
export type PathCompletion =
|
|
23
|
+
/** The directory the text names itself. Unlisted, nothing has confirmed it exists. */
|
|
24
|
+
{
|
|
25
|
+
kind: 'use';
|
|
26
|
+
path: string;
|
|
27
|
+
listed: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** A directory one of the machine's sessions worked in. */
|
|
30
|
+
| {
|
|
31
|
+
kind: 'recent';
|
|
32
|
+
path: string;
|
|
33
|
+
name: string;
|
|
34
|
+
}
|
|
35
|
+
/** The directory that holds the one listed. */
|
|
36
|
+
| {
|
|
37
|
+
kind: 'up';
|
|
38
|
+
path: string;
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'folder';
|
|
41
|
+
path: string;
|
|
42
|
+
name: string;
|
|
43
|
+
repository: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** How many recent directories lead the rows before anything is typed. */
|
|
46
|
+
export declare const RECENT_LIMIT = 5;
|
|
47
|
+
/** How many folders the rows list at once; typing narrows to the rest. */
|
|
48
|
+
export declare const FOLDER_LIMIT = 100;
|
|
49
|
+
/** The folders of `listing` to show: a hidden one, named from a dot, only once hidden folders are asked for. */
|
|
50
|
+
export declare function visibleFolders(listing: PwCodeDirectories, showHidden: boolean): Schemas['AgentDirectory'][];
|
|
51
|
+
/** The folders of `listing` whose names hold `partial`, the closest first. A hidden folder shows once the name typed starts with a dot. */
|
|
52
|
+
export declare function matchingFolders(listing: PwCodeDirectories, partial: string): Schemas['AgentDirectory'][];
|
|
53
|
+
/** The text starts at the root or at ~, rather than being a name to look for. */
|
|
54
|
+
export declare const isPathText: (typed: string) => boolean;
|
|
55
|
+
/** The rows under a path field, and whether they leave folders out, which
|
|
56
|
+
* typing a name reaches. `listing` is the listing of the directory `typed`
|
|
57
|
+
* points at, once loaded; `untouched` holds until the text is edited, which
|
|
58
|
+
* is when the recent directories lead. */
|
|
59
|
+
export declare function pathCompletions({ typed, untouched, listing, recents, }: {
|
|
60
|
+
typed: string;
|
|
61
|
+
untouched: boolean;
|
|
62
|
+
listing: PwCodeDirectories | undefined;
|
|
63
|
+
recents: readonly RecentDirectory[];
|
|
64
|
+
}): {
|
|
65
|
+
rows: PathCompletion[];
|
|
66
|
+
cut: boolean;
|
|
67
|
+
};
|
|
68
|
+
/** The listing was refused because the path is no directory the machine's account can read. */
|
|
69
|
+
export declare function isUnlistedDirectory(error: unknown): boolean;
|
|
70
|
+
/** A row under a path field as it is shown. */
|
|
71
|
+
export type PwCodePathRow = PathCompletion & {
|
|
72
|
+
/** Choosing the row lists its folders in the field rather than picking it. */
|
|
73
|
+
opens: boolean;
|
|
74
|
+
/** The line beside its name: what choosing it does, or where it is. */
|
|
75
|
+
detail: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
/** A run of a path field's rows, under its heading where it has one. */
|
|
78
|
+
export interface PwCodePathSection {
|
|
79
|
+
key: 'named' | 'recent' | 'folders';
|
|
80
|
+
label: string | undefined;
|
|
81
|
+
rows: PwCodePathRow[];
|
|
82
|
+
}
|
|
83
|
+
/** `rows`, in the order `pathCompletions` gives them, as the sections a path
|
|
84
|
+
* field shows: the directory the text names, the recent ones, then the
|
|
85
|
+
* folders listed, which are headed only below recent ones. Empty sections
|
|
86
|
+
* are left out. */
|
|
87
|
+
export declare function pathSections(rows: readonly PathCompletion[], { typed, untouched }: {
|
|
88
|
+
typed: string;
|
|
89
|
+
untouched: boolean;
|
|
90
|
+
}, t: Translate): PwCodePathSection[];
|
|
91
|
+
/** The one line under a path field's rows: why there are none, or what they
|
|
92
|
+
* leave out; null for none. */
|
|
93
|
+
export declare function pathNote({ typed, listable, loading, error, listing, rows, cut, }: {
|
|
94
|
+
typed: string;
|
|
95
|
+
listable: boolean;
|
|
96
|
+
loading: boolean;
|
|
97
|
+
error: unknown;
|
|
98
|
+
listing: PwCodeDirectories | undefined;
|
|
99
|
+
rows: readonly PathCompletion[];
|
|
100
|
+
cut: boolean;
|
|
101
|
+
}, t: Translate, describeError: (error: unknown) => string): string | null;
|
|
102
|
+
/** Where browsing from a path field opens: the directory listed, else the one
|
|
103
|
+
* the text names; empty for the home directory. */
|
|
104
|
+
export declare function browseStart(typed: string, listing: PwCodeDirectories | undefined): string;
|
|
105
|
+
/** The directory a path field picks as it closes, from what it was left
|
|
106
|
+
* holding: the one an edited text names, unless that is `chosen` already;
|
|
107
|
+
* null for none. A field closed to cancel picks nothing; the host does not
|
|
108
|
+
* ask this of it. */
|
|
109
|
+
export declare function pickedOnClose(left: {
|
|
110
|
+
typed: string;
|
|
111
|
+
home: string | undefined;
|
|
112
|
+
edited: boolean;
|
|
113
|
+
}, chosen: string): string | null;
|
|
114
|
+
/** The chip naming the directory a session starts in: its last segment, with
|
|
115
|
+
* the whole path as its label; both ask for one while `directory` is empty. */
|
|
116
|
+
export declare function directoryChip(directory: string, t: Translate): {
|
|
117
|
+
text: string;
|
|
118
|
+
label: string;
|
|
119
|
+
};
|
|
120
|
+
export declare function directoriesApi(client: PwCodeClient): {
|
|
121
|
+
listDirectories: (machine: string, path: string, filter?: string) => Promise<PwCodeResult<PwCodeDirectories>>;
|
|
122
|
+
useDirectories: (machine: string | undefined, path: string | null, filter?: string) => PwCodeQuery<PwCodeDirectories>;
|
|
123
|
+
usePathCompletion: ({ machine, typed, untouched, recents, describeError, }: {
|
|
124
|
+
machine: Pick<Schemas['AgentMachine'], 'id' | 'directories'> | undefined;
|
|
125
|
+
typed: string;
|
|
126
|
+
untouched: boolean;
|
|
127
|
+
recents: readonly RecentDirectory[];
|
|
128
|
+
/** Words a failed listing for the reader. */
|
|
129
|
+
describeError: (error: unknown) => string;
|
|
130
|
+
}) => {
|
|
131
|
+
/** The sections' rows, in order. */
|
|
132
|
+
rows: PwCodePathRow[];
|
|
133
|
+
sections: PwCodePathSection[];
|
|
134
|
+
/** The line under the rows (`pathNote`). */
|
|
135
|
+
note: string | null;
|
|
136
|
+
/** The machine lists its folders, so the field offers to browse them. */
|
|
137
|
+
canBrowse: boolean;
|
|
138
|
+
/** Where browsing opens (`browseStart`). */
|
|
139
|
+
browseFrom: string;
|
|
140
|
+
/** The rows leave folders out; typing a name reaches them. */
|
|
141
|
+
cut: boolean;
|
|
142
|
+
/** The directory whose folders the rows list, once it answered. */
|
|
143
|
+
listing: PwCodeDirectories | undefined;
|
|
144
|
+
loading: boolean;
|
|
145
|
+
/** Why the directory could not be listed. */
|
|
146
|
+
error: unknown;
|
|
147
|
+
};
|
|
148
|
+
useDirectoryTree: (machine: Pick<Schemas['AgentMachine'], 'id' | 'name'>, from: string) => {
|
|
149
|
+
/** The directory the tree lists; undefined until the home directory is found. */
|
|
150
|
+
root: string | undefined;
|
|
151
|
+
/** The tree's name: its directory's, or the machine's until that is known. */
|
|
152
|
+
title: string;
|
|
153
|
+
/** The directory above `root`; null at the root. */
|
|
154
|
+
above: string | null;
|
|
155
|
+
/** Moves the tree to `above`. */
|
|
156
|
+
goUp: () => void;
|
|
157
|
+
/** Why the home directory could not be found. */
|
|
158
|
+
error: unknown;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
export {};
|