@parallelworks/code 0.3.0 → 0.5.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 (118) hide show
  1. package/README.md +625 -113
  2. package/dist/accountApi.d.ts +31 -0
  3. package/dist/accountApi.js +182 -0
  4. package/dist/agentSwitcher.d.ts +120 -0
  5. package/dist/agentSwitcher.js +187 -0
  6. package/dist/ago.d.ts +1 -3
  7. package/dist/ago.js +8 -10
  8. package/dist/allocations.d.ts +41 -0
  9. package/dist/allocations.js +76 -0
  10. package/dist/api.d.ts +1319 -50
  11. package/dist/chatStrings.d.ts +189 -0
  12. package/dist/chatStrings.js +218 -0
  13. package/dist/claudeAccounts.d.ts +57 -2
  14. package/dist/claudeAccounts.js +144 -6
  15. package/dist/claudeApi.d.ts +2 -1
  16. package/dist/claudeApi.js +50 -4
  17. package/dist/claudeSignIn.d.ts +19 -1
  18. package/dist/claudeSignIn.js +12 -2
  19. package/dist/command.d.ts +5 -1
  20. package/dist/command.js +6 -1
  21. package/dist/commandsApi.d.ts +11 -1
  22. package/dist/commandsApi.js +24 -5
  23. package/dist/createPwCodeApi.d.ts +114 -6
  24. package/dist/createPwCodeApi.js +21 -3
  25. package/dist/directories.d.ts +161 -0
  26. package/dist/directories.js +301 -0
  27. package/dist/goal.d.ts +89 -0
  28. package/dist/goal.js +164 -0
  29. package/dist/imageFit.d.ts +23 -0
  30. package/dist/imageFit.js +27 -0
  31. package/dist/images.d.ts +28 -0
  32. package/dist/images.js +38 -6
  33. package/dist/index.d.ts +31 -15
  34. package/dist/index.js +29 -14
  35. package/dist/loadError.d.ts +8 -0
  36. package/dist/loadError.js +19 -0
  37. package/dist/locales/en/agentTranscript.js +74 -12
  38. package/dist/locales/en/agents.js +86 -11
  39. package/dist/locales/en.d.ts +137 -8
  40. package/dist/locales/es/agentTranscript.js +74 -12
  41. package/dist/locales/es/agents.js +86 -11
  42. package/dist/locales/ja/agentTranscript.js +77 -15
  43. package/dist/locales/ja/agents.js +60 -122
  44. package/dist/locales/ko/agentTranscript.js +74 -12
  45. package/dist/locales/ko/agents.js +86 -11
  46. package/dist/locales/zh/agentTranscript.js +72 -10
  47. package/dist/locales/zh/agents.js +86 -11
  48. package/dist/machine.d.ts +2 -0
  49. package/dist/modelPicker.d.ts +79 -0
  50. package/dist/modelPicker.js +107 -0
  51. package/dist/notices.d.ts +2 -0
  52. package/dist/notices.js +67 -32
  53. package/dist/platformDefaults.d.ts +22 -0
  54. package/dist/platformDefaults.js +30 -0
  55. package/dist/preferences.d.ts +78 -0
  56. package/dist/preferences.js +128 -0
  57. package/dist/pullRequestList.d.ts +10 -2
  58. package/dist/pullRequestList.js +41 -22
  59. package/dist/query.d.ts +9 -2
  60. package/dist/query.js +91 -10
  61. package/dist/session.d.ts +11 -2
  62. package/dist/session.js +16 -8
  63. package/dist/sessionActions.d.ts +11 -1
  64. package/dist/sessionActions.js +14 -6
  65. package/dist/sessionEvents.d.ts +37 -5
  66. package/dist/sessionEvents.js +196 -77
  67. package/dist/sessionGroups.d.ts +5 -4
  68. package/dist/sessionGroups.js +6 -5
  69. package/dist/sessionHeader.js +6 -2
  70. package/dist/sessionList.d.ts +68 -15
  71. package/dist/sessionList.js +91 -19
  72. package/dist/sessionScreen.d.ts +197 -0
  73. package/dist/sessionScreen.js +218 -0
  74. package/dist/sessionsApi.d.ts +29 -3
  75. package/dist/sessionsApi.js +180 -33
  76. package/dist/sessionsFeed.d.ts +22 -0
  77. package/dist/sessionsFeed.js +125 -0
  78. package/dist/settingsApi.d.ts +3 -1
  79. package/dist/startPage.d.ts +153 -0
  80. package/dist/startPage.js +174 -0
  81. package/dist/startSession.d.ts +41 -7
  82. package/dist/startSession.js +26 -4
  83. package/dist/todos.d.ts +42 -0
  84. package/dist/todos.js +104 -0
  85. package/dist/transcript.d.ts +1 -2
  86. package/dist/transcript.js +111 -117
  87. package/dist/transcriptRead.d.ts +56 -0
  88. package/dist/transcriptRead.js +121 -0
  89. package/dist/types.d.ts +11 -1
  90. package/dist/useComposer.d.ts +39 -6
  91. package/dist/useComposer.js +73 -9
  92. package/dist/useComposerImages.d.ts +5 -0
  93. package/dist/useComposerImages.js +27 -5
  94. package/dist/useComposerPastes.d.ts +70 -0
  95. package/dist/useComposerPastes.js +125 -0
  96. package/dist/useConversation.d.ts +16 -1
  97. package/dist/useConversation.js +104 -10
  98. package/dist/useMounted.d.ts +3 -0
  99. package/dist/useMounted.js +14 -0
  100. package/dist/useSubagent.d.ts +51 -3
  101. package/dist/useSubagent.js +72 -7
  102. package/dist/useTranscript.d.ts +23 -3
  103. package/dist/useTranscript.js +76 -19
  104. package/dist/wording.d.ts +5 -2
  105. package/dist/wording.js +8 -6
  106. package/dist/workingDirectories.d.ts +31 -0
  107. package/dist/workingDirectories.js +25 -1
  108. package/locales/en/agentTranscript.json +68 -11
  109. package/locales/en/agents.json +82 -10
  110. package/locales/es/agentTranscript.json +68 -11
  111. package/locales/es/agents.json +82 -10
  112. package/locales/ja/agentTranscript.json +71 -14
  113. package/locales/ja/agents.json +82 -10
  114. package/locales/ko/agentTranscript.json +68 -11
  115. package/locales/ko/agents.json +82 -10
  116. package/locales/zh/agentTranscript.json +66 -9
  117. package/locales/zh/agents.json +82 -10
  118. package/package.json +6 -3
@@ -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 : {
@@ -27,12 +29,13 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
27
29
  name: string;
28
30
  plan?: string;
29
31
  refreshing?: boolean;
32
+ sessions?: string[] | null;
30
33
  signInRequired?: boolean;
31
34
  usage?: string;
32
35
  weeklyResetsAt?: string;
33
36
  weeklyUsedPercent?: number;
34
37
  }[] | null>;
35
- useClaudeAccounts: (machine: string, sessionId: string | undefined, enabled: boolean) => {
38
+ useClaudeAccounts: (machine: string, sessionId: string | undefined, enabled: boolean, fresh?: boolean) => {
36
39
  accounts: {
37
40
  email?: string;
38
41
  error?: string;
@@ -43,6 +46,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
43
46
  name: string;
44
47
  plan?: string;
45
48
  refreshing?: boolean;
49
+ sessions?: string[] | null;
46
50
  signInRequired?: boolean;
47
51
  usage?: string;
48
52
  weeklyResetsAt?: string;
@@ -50,15 +54,17 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
50
54
  }[];
51
55
  loadedUsage: boolean;
52
56
  loading: boolean;
53
- error: import("./apiClient.js").PwCodeApiError | undefined;
57
+ error: PwCodeApiError | undefined;
54
58
  refreshing: boolean;
55
59
  refresh: () => Promise<void>;
56
60
  };
57
61
  useRemoveClaudeAccount: (machine: string, sessionId: string | undefined) => (name: string) => Promise<void>;
62
+ useMoveClaudeAccountSessions: (machine: string, sessionId: string | undefined) => (from: string, to: string) => Promise<string[]>;
58
63
  startClaudeLogin: (machine: string, account: string, sessionId: string | undefined, columns: number, rows: number) => Promise<import("./claudeApi.js").ClaudeLoginEvent>;
59
64
  writeClaudeLogin: (machine: string, loginId: string, input: import("./claudeApi.js").ClaudeLoginInput) => Promise<void>;
60
65
  cancelClaudeLogin: (machine: string, loginId: string) => Promise<void>;
61
66
  followClaudeLogin: (machine: string, login: import("./claudeApi.js").ClaudeLogin, after: number, signal: AbortSignal, receive: (event: import("./claudeApi.js").ClaudeLoginEvent) => void) => Promise<void>;
67
+ runGoal: (machine: string, id: string, args: string) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentGoalResult']>>;
62
68
  runSlashAction: (machine: string, id: string, action: Exclude<import("./command.js").SlashAction, {
63
69
  kind: 'message' | 'archive';
64
70
  }>, planOnMachine: (path: string) => string) => Promise<import("./commandsApi.js").CommandOutcome>;
@@ -96,6 +102,32 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
96
102
  move: () => Promise<void>;
97
103
  };
98
104
  requestRecap: (machine: string, id: string, signal?: AbortSignal) => Promise<import("./apiClient.js").PwCodeResult<undefined>>;
105
+ listDirectories: (machine: string, path: string, filter?: string) => Promise<import("./apiClient.js").PwCodeResult<import("./directories.js").PwCodeDirectories>>;
106
+ useDirectories: (machine: string | undefined, path: string | null, filter?: string) => import("./apiClient.js").PwCodeQuery<import("./directories.js").PwCodeDirectories>;
107
+ usePathCompletion: ({ machine, typed, untouched, recents, describeError, }: {
108
+ machine: Pick<Schemas['AgentMachine'], 'id' | 'directories'> | undefined;
109
+ typed: string;
110
+ untouched: boolean;
111
+ recents: readonly import("./session.js").RecentDirectory[];
112
+ describeError: (error: unknown) => string;
113
+ }) => {
114
+ rows: import("./directories.js").PwCodePathRow[];
115
+ sections: import("./directories.js").PwCodePathSection[];
116
+ note: string | null;
117
+ canBrowse: boolean;
118
+ browseFrom: string;
119
+ cut: boolean;
120
+ listing: import("./directories.js").PwCodeDirectories | undefined;
121
+ loading: boolean;
122
+ error: unknown;
123
+ };
124
+ useDirectoryTree: (machine: Pick<Schemas['AgentMachine'], 'id' | 'name'>, from: string) => {
125
+ root: string | undefined;
126
+ title: string;
127
+ above: string | null;
128
+ goUp: () => void;
129
+ error: unknown;
130
+ };
99
131
  useSessions: () => import("./apiClient.js").PwCodeQuery<{
100
132
  machines: import("./api.js").components["schemas"]["AgentMachine"][] | null;
101
133
  sessions: import("./api.js").components["schemas"]["AgentSession"][] | null;
@@ -130,6 +162,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
130
162
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
131
163
  turnStartedAt?: string;
132
164
  updatedAt: string;
165
+ usageLimitResumeAt?: string;
166
+ waitingForUsageLimit?: boolean;
133
167
  workspace: string;
134
168
  } | undefined) => {
135
169
  data: {
@@ -173,7 +207,48 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
173
207
  workspace: string;
174
208
  workspaceUntrusted?: boolean;
175
209
  } | undefined;
176
- error: import("./apiClient.js").PwCodeApiError | undefined;
210
+ preview: {
211
+ addDirs?: import("./api.js").components["schemas"]["AddedDirectory"][] | null;
212
+ allocation?: string;
213
+ allowedDirs?: import("./api.js").components["schemas"]["AllowedDirectory"][] | null;
214
+ approvals?: import("./api.js").components["schemas"]["ApprovalRequest"][] | null;
215
+ archivedAt?: string;
216
+ autoName?: string;
217
+ branch?: string;
218
+ claudeAccount?: string;
219
+ createdAt: string;
220
+ effort?: string;
221
+ goal?: import("./api.js").components["schemas"]["GoalStatus"];
222
+ group?: string;
223
+ history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
224
+ id: string;
225
+ inputTokens?: number;
226
+ lastError?: string;
227
+ lastSeq?: number;
228
+ liveHost?: string;
229
+ machineId: string;
230
+ messages: number;
231
+ model: string;
232
+ name?: string;
233
+ outputTokens?: number;
234
+ permissionMode?: string;
235
+ pinnedAt?: string;
236
+ preview: string;
237
+ pullRequestStates?: {
238
+ [key: string]: string;
239
+ };
240
+ pullRequests?: string[] | null;
241
+ remoteControl?: boolean;
242
+ status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
243
+ turnId?: string;
244
+ turnStartedAt?: string;
245
+ updatedAt: string;
246
+ usageLimitResumeAt?: string;
247
+ waitingForUsageLimit?: boolean;
248
+ workspace: string;
249
+ workspaceUntrusted?: boolean;
250
+ } | undefined;
251
+ error: PwCodeApiError | undefined;
177
252
  isLoading: boolean;
178
253
  mutate: import("swr").KeyedMutator<{
179
254
  addDirs?: import("./api.js").components["schemas"]["AddedDirectory"][] | null;
@@ -222,7 +297,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
222
297
  state?: "open" | "draft" | "merged" | "closed";
223
298
  url: string;
224
299
  }[]) => void) => import("./apiClient.js").PwCodeQuery<Schemas['AgentPullRequests']>;
225
- useSessionPullRequestStates: (machine: string, id: string, urls: string[]) => {
300
+ useSessionPullRequestStates: (machine: string, id: string, pullRequests: readonly string[] | null | undefined) => {
226
301
  url: string;
227
302
  state: string | undefined;
228
303
  }[] | undefined;
@@ -241,6 +316,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
241
316
  };
242
317
  stopSubagent: (machine: string, id: string, subId: string) => Promise<unknown>;
243
318
  stopAllSubagents: (machine: string, id: string) => Promise<unknown>;
319
+ dismissSubagent: (machine: string, id: string, subId: string) => Promise<unknown>;
244
320
  useSessionWorktree: (s: {
245
321
  allocation?: string;
246
322
  approvals?: import("./api.js").components["schemas"]["ApprovalRequest"][] | null;
@@ -270,6 +346,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
270
346
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
271
347
  turnStartedAt?: string;
272
348
  updatedAt: string;
349
+ usageLimitResumeAt?: string;
350
+ waitingForUsageLimit?: boolean;
273
351
  workspace: string;
274
352
  } | undefined) => import("./apiClient.js").PwCodeQuery<Schemas['AgentSessionWorktree']>;
275
353
  leaveWorktree: (s: {
@@ -301,6 +379,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
301
379
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
302
380
  turnStartedAt?: string;
303
381
  updatedAt: string;
382
+ usageLimitResumeAt?: string;
383
+ waitingForUsageLimit?: boolean;
304
384
  workspace: string;
305
385
  }, removeRoot?: string) => Promise<{
306
386
  left?: Schemas['AgentWorktreeLeft'];
@@ -336,6 +416,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
336
416
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
337
417
  turnStartedAt?: string;
338
418
  updatedAt: string;
419
+ usageLimitResumeAt?: string;
420
+ waitingForUsageLimit?: boolean;
339
421
  workspace: string;
340
422
  }, removeWorktree?: string) => Promise<unknown>;
341
423
  renameSession: (s: {
@@ -367,6 +449,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
367
449
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
368
450
  turnStartedAt?: string;
369
451
  updatedAt: string;
452
+ usageLimitResumeAt?: string;
453
+ waitingForUsageLimit?: boolean;
370
454
  workspace: string;
371
455
  }, name: string) => Promise<unknown>;
372
456
  archiveSession: (s: {
@@ -398,6 +482,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
398
482
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
399
483
  turnStartedAt?: string;
400
484
  updatedAt: string;
485
+ usageLimitResumeAt?: string;
486
+ waitingForUsageLimit?: boolean;
401
487
  workspace: string;
402
488
  }) => Promise<unknown>;
403
489
  archiveAfterTurn: (s: {
@@ -429,6 +515,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
429
515
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
430
516
  turnStartedAt?: string;
431
517
  updatedAt: string;
518
+ usageLimitResumeAt?: string;
519
+ waitingForUsageLimit?: boolean;
432
520
  workspace: string;
433
521
  }) => Promise<{
434
522
  refusal: unknown;
@@ -463,6 +551,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
463
551
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
464
552
  turnStartedAt?: string;
465
553
  updatedAt: string;
554
+ usageLimitResumeAt?: string;
555
+ waitingForUsageLimit?: boolean;
466
556
  workspace: string;
467
557
  }) => Promise<unknown>;
468
558
  pinSession: (s: {
@@ -494,6 +584,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
494
584
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
495
585
  turnStartedAt?: string;
496
586
  updatedAt: string;
587
+ usageLimitResumeAt?: string;
588
+ waitingForUsageLimit?: boolean;
497
589
  workspace: string;
498
590
  }, pinned: boolean) => Promise<unknown>;
499
591
  groupSession: (s: {
@@ -525,6 +617,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
525
617
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
526
618
  turnStartedAt?: string;
527
619
  updatedAt: string;
620
+ usageLimitResumeAt?: string;
621
+ waitingForUsageLimit?: boolean;
528
622
  workspace: string;
529
623
  }, group: string | null) => Promise<unknown>;
530
624
  stopSession: (s: {
@@ -556,6 +650,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
556
650
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
557
651
  turnStartedAt?: string;
558
652
  updatedAt: string;
653
+ usageLimitResumeAt?: string;
654
+ waitingForUsageLimit?: boolean;
559
655
  workspace: string;
560
656
  }) => Promise<unknown>;
561
657
  forkSession: (s: {
@@ -587,6 +683,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
587
683
  status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
588
684
  turnStartedAt?: string;
589
685
  updatedAt: string;
686
+ usageLimitResumeAt?: string;
687
+ waitingForUsageLimit?: boolean;
590
688
  workspace: string;
591
689
  }) => Promise<{
592
690
  forked?: Schemas['AgentSessionForked'];
@@ -636,9 +734,11 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
636
734
  }>>;
637
735
  sendMessage: (machine: string, id: string, body: Schemas['SendMessageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentMessageAccepted']>>;
638
736
  steer: (machine: string, id: string, body: Schemas['AgentDirectionBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionDelivered']>>;
737
+ withdrawDirection: (machine: string, id: string, ids: string[]) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionWithdrawn']>>;
639
738
  withdrawQueued: (machine: string, id: string, turnId: string) => Promise<import("./apiClient.js").PwCodeResult<undefined>>;
640
739
  messageSubagent: (machine: string, id: string, subId: string, body: Schemas['SendMessageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentMessageAccepted']>>;
641
740
  steerSubagent: (machine: string, id: string, subId: string, body: Schemas['AgentDirectionBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionDelivered']>>;
741
+ withdrawSubagentDirection: (machine: string, id: string, subId: string, ids: string[]) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentDirectionWithdrawn']>>;
642
742
  saveImage: (machine: string, id: string, body: Schemas['AgentImageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentImageSaved']>>;
643
743
  answerApproval: (machine: string, sessionId: string, approvalId: string, answer: import("@parallelworks/ui/ai/headless").ApprovalAnswerValue) => Promise<unknown>;
644
744
  removeSessionDirectory: (machine: string, sessionId: string, path: string) => Promise<unknown>;
@@ -691,6 +791,14 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
691
791
  connected: boolean;
692
792
  disconnected: boolean;
693
793
  };
794
+ useChatHandoff: (chat: string | undefined) => {
795
+ conversation: Schemas['ConversationResponse'] | undefined;
796
+ error: PwCodeApiError | undefined;
797
+ } | undefined;
798
+ usePlatformModels: () => import("./accountApi.js").PwCodePlatformModels;
799
+ useAllocations: (read?: boolean) => import("./apiClient.js").PwCodeQuery<Schemas['Allocation'][] | null>;
800
+ usePwCodeEnabled: () => boolean | undefined;
801
+ usePreference: <T>(key: string, fallback: T) => [T, import("react").Dispatch<import("react").SetStateAction<T>>];
694
802
  };
695
803
  export type PwCodeApi = ReturnType<typeof createPwCodeApi>;
696
804
  export {};
@@ -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 { sessionsFeed } from "./sessionsFeed.js";
5
9
  import { settingsApi } from "./settingsApi.js";
6
10
  import { useMemo } from "react";
7
11
  // src/createPwCodeApi.ts
@@ -11,8 +15,19 @@ import { useMemo } from "react";
11
15
  * `@parallelworks/client/swr`'s are, and the open feeds it counts are its own. */
12
16
  function createPwCodeApi(client, options = {}) {
13
17
  const routes = client;
14
- const sessions = sessionsApi(routes);
15
- const { useSessionEvents, useFedMachines } = sessionEvents(options);
18
+ const useQuery = createQuery(routes);
19
+ const { useSessionEvents, useFedMachines, listed } = sessionEvents(options);
20
+ const feed = sessionsFeed(options, (listing) => listed(listing.machines ?? []));
21
+ const sessions = sessionsApi(routes, options, listed, feed);
22
+ /** The AI chat a new session is to carry on, for `chatHandoffStart`;
23
+ * undefined without one. */
24
+ function useChatHandoff(chat) {
25
+ const { data, error } = useQuery("/api/aichat/conversations/{id}", chat ? { params: { path: { id: chat } } } : null);
26
+ return chat ? {
27
+ conversation: data,
28
+ error
29
+ } : void 0;
30
+ }
16
31
  /** The listing's machines. One with a session feed open counts as connected
17
32
  * whatever the poll says: the feed is the machine answering, and the polled
18
33
  * listing can lose a machine it still reaches. */
@@ -24,10 +39,13 @@ function createPwCodeApi(client, options = {}) {
24
39
  return {
25
40
  ...sessions,
26
41
  ...commandsApi(routes),
42
+ ...directoriesApi(routes),
27
43
  ...claudeApi(routes),
28
44
  ...settingsApi(routes),
45
+ ...accountApi(routes, options),
29
46
  useMachines,
30
- useSessionEvents
47
+ useSessionEvents,
48
+ useChatHandoff
31
49
  };
32
50
  }
33
51
  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 {};