@parallelworks/code 0.3.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.
Files changed (103) hide show
  1. package/README.md +598 -113
  2. package/dist/accountApi.d.ts +31 -0
  3. package/dist/accountApi.js +182 -0
  4. package/dist/agentSwitcher.d.ts +109 -0
  5. package/dist/agentSwitcher.js +165 -0
  6. package/dist/ago.d.ts +3 -3
  7. package/dist/ago.js +10 -10
  8. package/dist/allocations.d.ts +41 -0
  9. package/dist/allocations.js +76 -0
  10. package/dist/api.d.ts +1080 -11
  11. package/dist/chatStrings.d.ts +188 -0
  12. package/dist/chatStrings.js +217 -0
  13. package/dist/claudeAccounts.d.ts +38 -1
  14. package/dist/claudeAccounts.js +98 -4
  15. package/dist/claudeApi.js +1 -1
  16. package/dist/claudeSignIn.d.ts +19 -1
  17. package/dist/claudeSignIn.js +12 -2
  18. package/dist/commandsApi.d.ts +11 -1
  19. package/dist/commandsApi.js +24 -5
  20. package/dist/createPwCodeApi.d.ts +44 -5
  21. package/dist/createPwCodeApi.js +18 -2
  22. package/dist/directories.d.ts +161 -0
  23. package/dist/directories.js +301 -0
  24. package/dist/goal.d.ts +89 -0
  25. package/dist/goal.js +164 -0
  26. package/dist/imageFit.d.ts +23 -0
  27. package/dist/imageFit.js +27 -0
  28. package/dist/images.d.ts +28 -0
  29. package/dist/images.js +38 -6
  30. package/dist/index.d.ts +27 -12
  31. package/dist/index.js +26 -12
  32. package/dist/loadError.d.ts +8 -0
  33. package/dist/loadError.js +19 -0
  34. package/dist/locales/en/agentTranscript.js +73 -12
  35. package/dist/locales/en/agents.js +71 -9
  36. package/dist/locales/en.d.ts +124 -8
  37. package/dist/locales/es/agentTranscript.js +73 -12
  38. package/dist/locales/es/agents.js +71 -9
  39. package/dist/locales/ja/agentTranscript.js +76 -15
  40. package/dist/locales/ja/agents.js +45 -120
  41. package/dist/locales/ko/agentTranscript.js +73 -12
  42. package/dist/locales/ko/agents.js +71 -9
  43. package/dist/locales/zh/agentTranscript.js +71 -10
  44. package/dist/locales/zh/agents.js +71 -9
  45. package/dist/machine.d.ts +2 -0
  46. package/dist/modelPicker.d.ts +79 -0
  47. package/dist/modelPicker.js +107 -0
  48. package/dist/notices.js +47 -19
  49. package/dist/platformDefaults.d.ts +22 -0
  50. package/dist/platformDefaults.js +30 -0
  51. package/dist/preferences.d.ts +78 -0
  52. package/dist/preferences.js +128 -0
  53. package/dist/pullRequestList.d.ts +10 -2
  54. package/dist/pullRequestList.js +41 -22
  55. package/dist/query.d.ts +6 -2
  56. package/dist/query.js +85 -10
  57. package/dist/session.d.ts +5 -2
  58. package/dist/session.js +12 -8
  59. package/dist/sessionActions.d.ts +11 -1
  60. package/dist/sessionActions.js +14 -6
  61. package/dist/sessionEvents.d.ts +8 -3
  62. package/dist/sessionEvents.js +10 -5
  63. package/dist/sessionGroups.d.ts +3 -2
  64. package/dist/sessionGroups.js +4 -3
  65. package/dist/sessionList.d.ts +57 -9
  66. package/dist/sessionList.js +74 -12
  67. package/dist/sessionScreen.d.ts +193 -0
  68. package/dist/sessionScreen.js +213 -0
  69. package/dist/sessionsApi.d.ts +13 -3
  70. package/dist/sessionsApi.js +88 -29
  71. package/dist/settingsApi.d.ts +3 -1
  72. package/dist/startPage.d.ts +153 -0
  73. package/dist/startPage.js +174 -0
  74. package/dist/startSession.d.ts +41 -7
  75. package/dist/startSession.js +26 -4
  76. package/dist/transcript.js +48 -15
  77. package/dist/types.d.ts +11 -1
  78. package/dist/useComposer.d.ts +25 -1
  79. package/dist/useComposer.js +54 -3
  80. package/dist/useComposerImages.d.ts +5 -0
  81. package/dist/useComposerImages.js +24 -1
  82. package/dist/useComposerPastes.d.ts +70 -0
  83. package/dist/useComposerPastes.js +130 -0
  84. package/dist/useConversation.d.ts +10 -1
  85. package/dist/useConversation.js +32 -5
  86. package/dist/useSubagent.d.ts +49 -3
  87. package/dist/useSubagent.js +70 -7
  88. package/dist/useTranscript.d.ts +23 -3
  89. package/dist/useTranscript.js +76 -19
  90. package/dist/wording.js +2 -2
  91. package/dist/workingDirectories.d.ts +31 -0
  92. package/dist/workingDirectories.js +25 -1
  93. package/locales/en/agentTranscript.json +67 -11
  94. package/locales/en/agents.json +68 -8
  95. package/locales/es/agentTranscript.json +67 -11
  96. package/locales/es/agents.json +68 -8
  97. package/locales/ja/agentTranscript.json +70 -14
  98. package/locales/ja/agents.json +68 -8
  99. package/locales/ko/agentTranscript.json +67 -11
  100. package/locales/ko/agents.json +68 -8
  101. package/locales/zh/agentTranscript.json +65 -9
  102. package/locales/zh/agents.json +68 -8
  103. package/package.json +6 -3
@@ -8,10 +8,15 @@ var signInUrl = /https:\/\/claude\.(?:ai|com)\/[\w\-.~:/?#[\]@!$&'()*+,;=%]+(?=[
8
8
  var maxQueuedInput = 16384;
9
9
  var inputChunk = 4096;
10
10
  var inputBatchMs = 30;
11
+ /** Whether a link in the sign-in's output may be opened: web addresses only,
12
+ * never a script or a local file. */
13
+ function canOpenSignInLink(uri) {
14
+ return /^https?:\/\//i.test(uri);
15
+ }
11
16
  /** Runs Claude Code's sign-in for `account` on a machine: starts it at the
12
17
  * terminal's size, follows its output into the terminal, sends what is typed,
13
18
  * and cancels it when the host leaves before it finishes. */
14
- function useClaudeSignIn(calls, { machine, sessionId, account, terminal, onSignedIn }) {
19
+ function useClaudeSignIn(calls, { machine, machineName, sessionId, account, terminal, onSignedIn, onUse }) {
15
20
  const t = usePwCodeTranslations("agents");
16
21
  const [attempt, setAttempt] = useState(0);
17
22
  const [login, setLogin] = useState(null);
@@ -222,11 +227,16 @@ function useClaudeSignIn(calls, { machine, sessionId, account, terminal, onSigne
222
227
  truncated,
223
228
  inputTooLong,
224
229
  link,
230
+ signInPage: login?.status === "running" ? link : null,
231
+ instructions: signedIn ? null : t("claude.signInInstructions", { host: machineName }),
232
+ truncatedNote: truncated && !signedIn ? t("claude.terminalTruncated") : null,
233
+ closeLabel: finished ? t("claude.backToAccounts") : t("claude.cancelSignIn"),
225
234
  output,
226
235
  acceptsInput,
227
236
  starting: !login && !error,
228
237
  signedIn,
229
238
  finished,
239
+ use: signedIn ? onUse : void 0,
230
240
  canReconnect: Boolean(error) && !!login && !finished,
231
241
  canRetry: Boolean(error) && !login || finished && !signedIn,
232
242
  status: login ? t(`claude.signInStatus.${login.status}`, { email: login.email ?? account }) : null,
@@ -236,4 +246,4 @@ function useClaudeSignIn(calls, { machine, sessionId, account, terminal, onSigne
236
246
  retry
237
247
  };
238
248
  }
239
- export { useClaudeSignIn };
249
+ export { canOpenSignInLink, useClaudeSignIn };
@@ -1,4 +1,5 @@
1
- import { type PwCodeClient, type PwCodeResult, type Schemas } from './apiClient.js';
1
+ import type { ToolCallPart } from '@parallelworks/ui/ai/headless';
2
+ import type { PwCodeClient, PwCodeResult, Schemas } from './apiClient.js';
2
3
  import { type SlashAction } from './command.js';
3
4
  type Palette = Schemas['AgentPalette'];
4
5
  export type CommandOutcome = {
@@ -34,7 +35,16 @@ export interface SlashDeps {
34
35
  onRefused: (error: unknown) => void;
35
36
  }
36
37
  export declare const backgroundOfferDelayMs = 2000;
38
+ /** The tool whose running calls the machine can move to the background. */
39
+ export declare const BACKGROUND_TOOL = "Bash";
40
+ export declare function runsInBackgroundTool(part: Pick<ToolCallPart, 'name' | 'status'>): boolean;
41
+ /** The offer to move a turn's commands to the background sits under each of
42
+ * its running `BACKGROUND_TOOL` calls, once the session makes it. */
43
+ export declare function offersBackground(part: Pick<ToolCallPart, 'name' | 'status'>, background: {
44
+ offered: boolean;
45
+ } | null | undefined): boolean;
37
46
  export declare function commandsApi(client: PwCodeClient): {
47
+ runGoal: (machine: string, id: string, args: string) => Promise<PwCodeResult<Schemas['AgentGoalResult']>>;
38
48
  runSlashAction: (machine: string, id: string, action: Exclude<SlashAction, {
39
49
  kind: 'message' | 'archive';
40
50
  }>, planOnMachine: (path: string) => string) => Promise<CommandOutcome>;
@@ -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 client.POST("/api/code/machines/{machine}/sessions/{id}/goal", {
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 };
@@ -1,7 +1,9 @@
1
1
  import type { Client } from 'openapi-fetch';
2
- import type { PwCodePaths, Schemas } from './apiClient.js';
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
- export type PwCodeApiOptions = PwCodeSocketOptions;
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: import("./apiClient.js").PwCodeApiError | undefined;
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: import("./apiClient.js").PwCodeApiError | undefined;
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, urls: 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,9 +665,11 @@ 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>;
@@ -691,6 +722,14 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
691
722
  connected: boolean;
692
723
  disconnected: boolean;
693
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>>];
694
733
  };
695
734
  export type PwCodeApi = ReturnType<typeof createPwCodeApi>;
696
735
  export {};
@@ -1,5 +1,8 @@
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";
5
8
  import { settingsApi } from "./settingsApi.js";
@@ -11,8 +14,18 @@ import { useMemo } from "react";
11
14
  * `@parallelworks/client/swr`'s are, and the open feeds it counts are its own. */
12
15
  function createPwCodeApi(client, options = {}) {
13
16
  const routes = client;
14
- const sessions = sessionsApi(routes);
17
+ const useQuery = createQuery(routes);
18
+ const sessions = sessionsApi(routes, options);
15
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
+ }
16
29
  /** The listing's machines. One with a session feed open counts as connected
17
30
  * whatever the poll says: the feed is the machine answering, and the polled
18
31
  * listing can lose a machine it still reaches. */
@@ -24,10 +37,13 @@ function createPwCodeApi(client, options = {}) {
24
37
  return {
25
38
  ...sessions,
26
39
  ...commandsApi(routes),
40
+ ...directoriesApi(routes),
27
41
  ...claudeApi(routes),
28
42
  ...settingsApi(routes),
43
+ ...accountApi(routes, options),
29
44
  useMachines,
30
- useSessionEvents
45
+ useSessionEvents,
46
+ useChatHandoff
31
47
  };
32
48
  }
33
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 {};