@parallelworks/code 0.4.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 (77) hide show
  1. package/README.md +39 -12
  2. package/dist/agentSwitcher.d.ts +13 -2
  3. package/dist/agentSwitcher.js +28 -6
  4. package/dist/ago.d.ts +1 -3
  5. package/dist/ago.js +1 -3
  6. package/dist/api.d.ts +200 -0
  7. package/dist/chatStrings.d.ts +1 -0
  8. package/dist/chatStrings.js +2 -1
  9. package/dist/claudeAccounts.d.ts +20 -2
  10. package/dist/claudeAccounts.js +51 -7
  11. package/dist/claudeApi.d.ts +2 -1
  12. package/dist/claudeApi.js +49 -3
  13. package/dist/command.d.ts +5 -1
  14. package/dist/command.js +6 -1
  15. package/dist/createPwCodeApi.d.ts +70 -1
  16. package/dist/createPwCodeApi.js +4 -2
  17. package/dist/index.d.ts +5 -4
  18. package/dist/index.js +5 -4
  19. package/dist/locales/en/agentTranscript.js +2 -1
  20. package/dist/locales/en/agents.js +16 -3
  21. package/dist/locales/en.d.ts +13 -0
  22. package/dist/locales/es/agentTranscript.js +2 -1
  23. package/dist/locales/es/agents.js +16 -3
  24. package/dist/locales/ja/agentTranscript.js +2 -1
  25. package/dist/locales/ja/agents.js +16 -3
  26. package/dist/locales/ko/agentTranscript.js +2 -1
  27. package/dist/locales/ko/agents.js +16 -3
  28. package/dist/locales/zh/agentTranscript.js +2 -1
  29. package/dist/locales/zh/agents.js +16 -3
  30. package/dist/notices.d.ts +2 -0
  31. package/dist/notices.js +20 -13
  32. package/dist/query.d.ts +4 -1
  33. package/dist/query.js +9 -3
  34. package/dist/session.d.ts +6 -0
  35. package/dist/session.js +5 -1
  36. package/dist/sessionEvents.d.ts +29 -2
  37. package/dist/sessionEvents.js +187 -73
  38. package/dist/sessionGroups.d.ts +3 -3
  39. package/dist/sessionGroups.js +3 -3
  40. package/dist/sessionHeader.js +6 -2
  41. package/dist/sessionList.d.ts +13 -8
  42. package/dist/sessionList.js +20 -10
  43. package/dist/sessionScreen.d.ts +5 -1
  44. package/dist/sessionScreen.js +12 -7
  45. package/dist/sessionsApi.d.ts +19 -3
  46. package/dist/sessionsApi.js +100 -12
  47. package/dist/sessionsFeed.d.ts +22 -0
  48. package/dist/sessionsFeed.js +125 -0
  49. package/dist/todos.d.ts +42 -0
  50. package/dist/todos.js +104 -0
  51. package/dist/transcript.d.ts +1 -2
  52. package/dist/transcript.js +63 -102
  53. package/dist/transcriptRead.d.ts +56 -0
  54. package/dist/transcriptRead.js +121 -0
  55. package/dist/useComposer.d.ts +14 -5
  56. package/dist/useComposer.js +20 -7
  57. package/dist/useComposerImages.js +3 -4
  58. package/dist/useComposerPastes.js +3 -8
  59. package/dist/useConversation.d.ts +6 -0
  60. package/dist/useConversation.js +72 -5
  61. package/dist/useMounted.d.ts +3 -0
  62. package/dist/useMounted.js +14 -0
  63. package/dist/useSubagent.d.ts +2 -0
  64. package/dist/useSubagent.js +2 -0
  65. package/dist/wording.d.ts +5 -2
  66. package/dist/wording.js +6 -4
  67. package/locales/en/agentTranscript.json +2 -1
  68. package/locales/en/agents.json +14 -2
  69. package/locales/es/agentTranscript.json +2 -1
  70. package/locales/es/agents.json +14 -2
  71. package/locales/ja/agentTranscript.json +2 -1
  72. package/locales/ja/agents.json +14 -2
  73. package/locales/ko/agentTranscript.json +2 -1
  74. package/locales/ko/agents.json +14 -2
  75. package/locales/zh/agentTranscript.json +2 -1
  76. package/locales/zh/agents.json +14 -2
  77. package/package.json +2 -2
@@ -4,6 +4,10 @@ import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "
4
4
  // src/sessionEvents.ts
5
5
  var INITIAL_RETRY_MS = 1e3;
6
6
  var MAX_RETRY_MS = 3e4;
7
+ /** How long a socket that has sent a heartbeat may say nothing: two are missed. */
8
+ var SILENT_AFTER_MS = 25e3;
9
+ /** The platform gives a machine 15 seconds to answer before it refuses a socket. */
10
+ var OPEN_WITHIN_MS = 2e4;
7
11
  var SOCKET_OPEN = 1;
8
12
  var SOCKET_CLOSED = 3;
9
13
  /** The path a session's event feed is served at, resuming after frame `after`.
@@ -12,12 +16,21 @@ var SOCKET_CLOSED = 3;
12
16
  * connection what the session says next waits behind it. */
13
17
  function sessionEventsPath(machine, id, after, previewsByRef = false) {
14
18
  const previews = previewsByRef ? `&previews=${PREVIEWS_BY_REF}` : "";
15
- return `/ws/code/machines/${encodeURIComponent(machine)}/sessions/${encodeURIComponent(id)}/events?after=${after}${previews}`;
19
+ return `/ws/code/machines/${encodeURIComponent(machine)}/sessions/${encodeURIComponent(id)}/events?after=${after}${previews}&heartbeat=10`;
16
20
  }
17
- /** Frames after which the list of subagents may read differently: one started
18
- * or ended, one asked for or got an approval, or a turn began or closed. */
21
+ /** Whether a frame is the heartbeat the platform sends a feed that asked for one. */
22
+ function isHeartbeat(data) {
23
+ if (typeof data !== "string" || data.length > 64) return false;
24
+ try {
25
+ return JSON.parse(data).type === "heartbeat";
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+ /** Frames after which the list of subagents may read differently: one started,
31
+ * ended or was dismissed, one asked for or got an approval, or a turn began or closed. */
19
32
  function changesSubagents(ev) {
20
- return ev.type === "subagent_start" || ev.type === "subagent_end" || ev.type === "approval_request" || ev.type === "approval_resolved" || ev.type === "user_message" || ev.type === "done" || ev.type === "error";
33
+ return ev.type === "subagent_start" || ev.type === "subagent_end" || ev.type === "subagent_dismissed" || ev.type === "approval_request" || ev.type === "approval_resolved" || ev.type === "user_message" || ev.type === "done" || ev.type === "error";
21
34
  }
22
35
  /** `machines` with each one in `fed` that the listing lost counted as connected. */
23
36
  function reachedByFeed(machines, fed) {
@@ -32,90 +45,173 @@ function reachedByFeed(machines, fed) {
32
45
  };
33
46
  });
34
47
  }
48
+ /** Holds one socket open until the returned call, reopening it with backoff
49
+ * after it drops. */
50
+ function holdSocket(latest, setConnected) {
51
+ let stopped = false;
52
+ let socket = null;
53
+ let silent = null;
54
+ let attempt = 0;
55
+ let attempts = 0;
56
+ let hurried = false;
57
+ let timer;
58
+ let opening;
59
+ let silence;
60
+ const retry = () => {
61
+ const delay = Math.min(INITIAL_RETRY_MS * 2 ** attempts, MAX_RETRY_MS);
62
+ attempts += 1;
63
+ timer = setTimeout(connect, delay);
64
+ };
65
+ const failed = () => {
66
+ clearTimeout(opening);
67
+ if (stopped) return;
68
+ latest.current.onClose();
69
+ retry();
70
+ };
71
+ const attach = (ws) => {
72
+ if (stopped) {
73
+ ws.close();
74
+ return;
75
+ }
76
+ socket = ws;
77
+ let beats = false;
78
+ const opened = () => {
79
+ if (socket !== ws) return;
80
+ clearTimeout(opening);
81
+ const left = silent;
82
+ silent = null;
83
+ left?.close();
84
+ attempts = 0;
85
+ hurried = false;
86
+ setConnected(true);
87
+ latest.current.onOpen(false);
88
+ };
89
+ const revived = () => {
90
+ silent = null;
91
+ clearTimeout(timer);
92
+ timer = void 0;
93
+ clearTimeout(opening);
94
+ attempt += 1;
95
+ const tried = socket;
96
+ socket = ws;
97
+ tried?.close();
98
+ attempts = 0;
99
+ hurried = false;
100
+ setConnected(true);
101
+ latest.current.onOpen(true);
102
+ };
103
+ const wentSilent = () => {
104
+ if (socket !== ws) return;
105
+ silent = ws;
106
+ socket = null;
107
+ setConnected(false);
108
+ latest.current.onClose();
109
+ connect();
110
+ };
111
+ const closed = () => {
112
+ if (silent === ws) {
113
+ silent = null;
114
+ return;
115
+ }
116
+ if (socket !== ws) return;
117
+ socket = null;
118
+ clearTimeout(opening);
119
+ clearTimeout(silence);
120
+ setConnected(false);
121
+ latest.current.onClose();
122
+ if (!stopped) retry();
123
+ };
124
+ ws.addEventListener("open", opened);
125
+ const heartbeat = (data) => {
126
+ const beat = latest.current.heartbeat?.(data) === true;
127
+ beats ||= beat;
128
+ if (beats) {
129
+ clearTimeout(silence);
130
+ silence = setTimeout(wentSilent, SILENT_AFTER_MS);
131
+ }
132
+ return beat;
133
+ };
134
+ ws.addEventListener("message", (event) => {
135
+ if (silent === ws) revived();
136
+ if (socket === ws && !heartbeat(event.data)) latest.current.onMessage(event.data);
137
+ });
138
+ ws.addEventListener("close", closed);
139
+ if (ws.readyState === SOCKET_OPEN) opened();
140
+ else if (ws.readyState === SOCKET_CLOSED) closed();
141
+ };
142
+ function connect() {
143
+ timer = void 0;
144
+ const opener = latest.current.open;
145
+ if (!opener) return;
146
+ attempt += 1;
147
+ const mine = attempt;
148
+ opening = setTimeout(() => {
149
+ const ws = socket;
150
+ socket = null;
151
+ latest.current.onClose();
152
+ ws?.close();
153
+ connect();
154
+ }, OPEN_WITHIN_MS);
155
+ let made;
156
+ try {
157
+ made = opener(latest.current.path());
158
+ } catch {
159
+ failed();
160
+ return;
161
+ }
162
+ if ("then" in made) made.then((ws) => mine === attempt ? attach(ws) : ws.close(), () => {
163
+ if (mine === attempt) failed();
164
+ });
165
+ else attach(made);
166
+ }
167
+ connect();
168
+ const forget = latest.current.whenReachable?.(() => {
169
+ if (stopped || timer === void 0 || hurried) return;
170
+ hurried = true;
171
+ clearTimeout(timer);
172
+ attempts = 0;
173
+ connect();
174
+ });
175
+ return () => {
176
+ stopped = true;
177
+ forget?.();
178
+ clearTimeout(timer);
179
+ clearTimeout(opening);
180
+ clearTimeout(silence);
181
+ const ws = socket;
182
+ const left = silent;
183
+ socket = null;
184
+ silent = null;
185
+ ws?.close();
186
+ left?.close();
187
+ setConnected(false);
188
+ };
189
+ }
35
190
  /** Holds one socket open while `enabled`, reopening it with backoff after it
36
191
  * drops, and from scratch whenever `connectionKey` changes. */
37
- function useReconnectingSocket({ open, path, connectionKey, enabled, onOpen, onMessage, onClose }) {
192
+ function useReconnectingSocket({ open, path, connectionKey, enabled, onOpen, onMessage, onClose, whenReachable, heartbeat }) {
38
193
  const [connected, setConnected] = useState(false);
39
194
  const latest = useRef({
40
195
  open,
41
196
  path,
42
197
  onOpen,
43
198
  onMessage,
44
- onClose
199
+ onClose,
200
+ whenReachable,
201
+ heartbeat
45
202
  });
46
203
  latest.current = {
47
204
  open,
48
205
  path,
49
206
  onOpen,
50
207
  onMessage,
51
- onClose
208
+ onClose,
209
+ whenReachable,
210
+ heartbeat
52
211
  };
53
212
  useEffect(() => {
54
213
  if (!enabled || !latest.current.open) return;
55
- let stopped = false;
56
- let socket = null;
57
- let attempts = 0;
58
- let timer;
59
- const retry = () => {
60
- const delay = Math.min(INITIAL_RETRY_MS * 2 ** attempts, MAX_RETRY_MS);
61
- attempts += 1;
62
- timer = setTimeout(connect, delay);
63
- };
64
- const failed = () => {
65
- if (stopped) return;
66
- latest.current.onClose();
67
- retry();
68
- };
69
- const attach = (ws) => {
70
- if (stopped) {
71
- ws.close();
72
- return;
73
- }
74
- socket = ws;
75
- const opened = () => {
76
- if (socket !== ws) return;
77
- attempts = 0;
78
- setConnected(true);
79
- latest.current.onOpen();
80
- };
81
- const closed = () => {
82
- if (socket !== ws) return;
83
- socket = null;
84
- setConnected(false);
85
- latest.current.onClose();
86
- if (!stopped) retry();
87
- };
88
- ws.addEventListener("open", opened);
89
- ws.addEventListener("message", (event) => {
90
- if (socket === ws) latest.current.onMessage(event.data);
91
- });
92
- ws.addEventListener("close", closed);
93
- if (ws.readyState === SOCKET_OPEN) opened();
94
- else if (ws.readyState === SOCKET_CLOSED) closed();
95
- };
96
- function connect() {
97
- timer = void 0;
98
- const opener = latest.current.open;
99
- if (!opener) return;
100
- let made;
101
- try {
102
- made = opener(latest.current.path());
103
- } catch {
104
- failed();
105
- return;
106
- }
107
- if ("then" in made) made.then(attach, failed);
108
- else attach(made);
109
- }
110
- connect();
111
- return () => {
112
- stopped = true;
113
- clearTimeout(timer);
114
- const ws = socket;
115
- socket = null;
116
- ws?.close();
117
- setConnected(false);
118
- };
214
+ return holdSocket(latest, setConnected);
119
215
  }, [enabled, connectionKey]);
120
216
  return connected;
121
217
  }
@@ -139,6 +235,21 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
139
235
  listeners.delete(notify);
140
236
  };
141
237
  }
238
+ const waiting = /* @__PURE__ */ new Map();
239
+ function whenListed(machine, tryNow) {
240
+ const feeds = waiting.get(machine) ?? /* @__PURE__ */ new Set();
241
+ waiting.set(machine, feeds.add(tryNow));
242
+ return () => {
243
+ feeds.delete(tryNow);
244
+ if (feeds.size === 0) waiting.delete(machine);
245
+ };
246
+ }
247
+ /** The listing answered, so the platform can be reached: a feed waiting to
248
+ * try a machine the listing shows connected again tries at once, once for
249
+ * each time it drops. */
250
+ function listed(machines) {
251
+ for (const machine of machines) if (isConnected(machine)) for (const tryNow of [...waiting.get(machine.id) ?? []]) tryNow();
252
+ }
142
253
  /** The machines a session feed is open to. */
143
254
  function useFedMachines() {
144
255
  return useSyncExternalStore(subscribe, () => fedMachines);
@@ -174,6 +285,8 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
174
285
  path: () => sessionEventsPath(machine, id, cursor?.() ?? 0, previewsByRef),
175
286
  connectionKey: key,
176
287
  enabled: cursor !== void 0,
288
+ whenReachable: (tryNow) => whenListed(machine, tryNow),
289
+ heartbeat: isHeartbeat,
177
290
  onOpen: () => setFeed({
178
291
  key,
179
292
  open: true
@@ -211,7 +324,8 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
211
324
  }
212
325
  return {
213
326
  useSessionEvents,
214
- useFedMachines
327
+ useFedMachines,
328
+ listed
215
329
  };
216
330
  }
217
- export { changesSubagents, reachedByFeed, sessionEvents, sessionEventsPath };
331
+ export { changesSubagents, holdSocket, isHeartbeat, reachedByFeed, sessionEvents, sessionEventsPath };
@@ -14,13 +14,13 @@ export interface ListedGroup<S = PwCodeSession> {
14
14
  waiting: number;
15
15
  running: number;
16
16
  }
17
- type Grouped = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'liveHost' | 'archivedAt' | 'group' | 'createdAt'>;
17
+ type Grouped = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'waitingForUsageLimit' | 'liveHost' | 'archivedAt' | 'group' | 'createdAt'>;
18
18
  type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
19
19
  export declare function patchGroup(groups: readonly SessionGroup[], id: string, patch: Partial<Omit<SessionGroup, 'id'>>): SessionGroup[];
20
20
  /** The reader's group a session is in. One naming a group since deleted is in none. */
21
21
  export declare function groupOf(groups: readonly SessionGroup[], session: Pick<PwCodeSession, 'group'>): SessionGroup | undefined;
22
- /** A turn is running on a machine that still answers. */
23
- export declare function isWorking(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): boolean;
22
+ /** A turn is running on a machine that still answers, and not held by a usage limit. */
23
+ export declare function isWorking(session: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>, machine: Pick<PwCodeMachine, 'status'> | undefined): boolean;
24
24
  /** Sessions as a group lists them: what waits on the reader, then what is
25
25
  * live, newest begun first, then the rest, with how many wait and how many
26
26
  * are working. */
@@ -1,5 +1,5 @@
1
1
  import { isMachineDown } from "./machine.js";
2
- import { isActiveSession, isArchived, needsYou, newestCreatedFirst } from "./session.js";
2
+ import { isActiveSession, isArchived, needsYou, newestCreatedFirst, waitsOnUsageLimit } from "./session.js";
3
3
  import { useCallback, useMemo } from "react";
4
4
  // src/sessionGroups.ts
5
5
  function patchGroup(groups, id, patch) {
@@ -12,9 +12,9 @@ function patchGroup(groups, id, patch) {
12
12
  function groupOf(groups, session) {
13
13
  return session.group ? groups.find((g) => g.id === session.group) : void 0;
14
14
  }
15
- /** A turn is running on a machine that still answers. */
15
+ /** A turn is running on a machine that still answers, and not held by a usage limit. */
16
16
  function isWorking(session, machine) {
17
- return session.status === "running" && !isMachineDown(machine);
17
+ return session.status === "running" && !waitsOnUsageLimit(session) && !isMachineDown(machine);
18
18
  }
19
19
  /** Sessions as a group lists them: what waits on the reader, then what is
20
20
  * live, newest begun first, then the rest, with how many wait and how many
@@ -1,12 +1,16 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useRef } from "react";
2
2
  // src/sessionHeader.ts
3
3
  /** The worktree `useSessionWorktree` read, read again whenever the live
4
4
  * session reports it moved; undefined while the session works where it
5
5
  * launched. */
6
6
  function useFollowedWorktree(worktree, liveWorktree) {
7
7
  const { data, mutate } = worktree;
8
+ const followed = useRef(liveWorktree);
8
9
  useEffect(() => {
9
- mutate();
10
+ if (followed.current !== liveWorktree) {
11
+ followed.current = liveWorktree;
12
+ mutate();
13
+ }
10
14
  }, [liveWorktree, mutate]);
11
15
  return data?.root ? {
12
16
  root: data.root,
@@ -9,7 +9,7 @@ import { sessionLabel, sessionStateText } from './wording.js';
9
9
  type Session = Schemas['AgentSession'];
10
10
  type Translate = PwCodeTranslator<'agents'>;
11
11
  type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
12
- type Listed = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'createdAt' | 'updatedAt'>;
12
+ type Listed = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'waitingForUsageLimit' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'createdAt' | 'updatedAt'>;
13
13
  /** Where a session dropped on a section goes: with the pinned ones, into one
14
14
  * of the reader's groups or out of any, or into the archive. */
15
15
  export type SessionDropTarget = {
@@ -74,12 +74,14 @@ export declare function sessionSearchStatus(session: Parameters<typeof sessionSt
74
74
  } | undefined;
75
75
  /** What a session's mark on a collapsed list is called: its label, its
76
76
  * machine and its state. */
77
- export declare function sessionRailLabel(session: Parameters<typeof sessionLabel>[0] & Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'name' | 'status'> | undefined, t: Translate): string;
77
+ export declare function sessionRailLabel(session: Parameters<typeof sessionLabel>[0] & Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'name' | 'status'> | undefined, t: Translate, resumeClock?: (at: string) => string): string;
78
78
  /** A second line costs a row its height, so the state takes one only when the
79
- * mark cannot express it: not "idle" or "running", but "waiting on you" and a
80
- * dead machine. */
81
- export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
79
+ * mark cannot express it: not "idle" or "running", but "waiting on you", a
80
+ * usage limit and when it resets, and a dead machine. */
81
+ export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate, resumeClock?: (at: string) => string): {
82
82
  stateText: string;
83
+ /** The tone the state's words read in. */
84
+ tone: ReturnType<typeof sessionVariant<'muted'>>;
83
85
  showSecondLine: boolean;
84
86
  live: boolean;
85
87
  };
@@ -87,12 +89,15 @@ export declare function sessionRowState(session: Parameters<typeof sessionStateT
87
89
  * archived one, listed with the archive, needs the mark. */
88
90
  export declare function showsPinMark(session: Pick<PwCodeSession, 'pinnedAt' | 'archivedAt'>): boolean;
89
91
  /** A session at work shows a turning mark, which tells it from one resting
90
- * between turns by its shape and so holds with reduced motion. Any other
91
- * shows a dot in its state's tone, pulsing while it waits on the reader. */
92
- export declare function sessionMark(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): {
92
+ * between turns by its shape and so holds with reduced motion. One held by a
93
+ * usage limit is still, and keeps a dot's tone for a host that draws only
94
+ * dots. Any other shows a dot in its state's tone, pulsing while it waits on
95
+ * the reader. */
96
+ export declare function sessionMark(session: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>, machine: Pick<PwCodeMachine, 'status'> | undefined): {
93
97
  working: true;
94
98
  } | {
95
99
  working: false;
100
+ usageLimit?: boolean;
96
101
  tone: ReturnType<typeof sessionVariant<'success'>>;
97
102
  pulse: boolean;
98
103
  };
@@ -1,7 +1,7 @@
1
1
  import { isConnected, isMachineDown } from "./machine.js";
2
2
  import { usePwCodeTranslations } from "./messages.js";
3
3
  import { pastedPullRequestLabel, pullRequestLabel } from "./pullRequest.js";
4
- import { isActiveSession, isArchived, isSession, needsYou, newestCreatedFirst, newestFirst, sessionKey, sessionVariant, spansMachines } from "./session.js";
4
+ import { isActiveSession, isArchived, isSession, needsYou, newestCreatedFirst, newestFirst, sessionKey, sessionVariant, spansMachines, waitsOnUsageLimit } from "./session.js";
5
5
  import { DELETE_KEYS, menuCommand, nameToSave } from "./sessionActions.js";
6
6
  import { groupOf, inFlightFirst, isWorking, listGroups } from "./sessionGroups.js";
7
7
  import { sessionLabel, sessionStateText } from "./wording.js";
@@ -136,21 +136,23 @@ function sessionSearchStatus(session, machine, t) {
136
136
  }
137
137
  /** What a session's mark on a collapsed list is called: its label, its
138
138
  * machine and its state. */
139
- function sessionRailLabel(session, machine, t) {
139
+ function sessionRailLabel(session, machine, t, resumeClock) {
140
140
  return [
141
141
  sessionLabel(session, t),
142
142
  machine?.name,
143
- sessionStateText(session, machine, t)
143
+ sessionStateText(session, machine, t, resumeClock)
144
144
  ].filter(Boolean).join(" · ");
145
145
  }
146
146
  /** A second line costs a row its height, so the state takes one only when the
147
- * mark cannot express it: not "idle" or "running", but "waiting on you" and a
148
- * dead machine. */
149
- function sessionRowState(session, machine, t) {
147
+ * mark cannot express it: not "idle" or "running", but "waiting on you", a
148
+ * usage limit and when it resets, and a dead machine. */
149
+ function sessionRowState(session, machine, t, resumeClock) {
150
150
  const degraded = isMachineDown(machine);
151
+ const held = waitsOnUsageLimit(session);
151
152
  return {
152
- stateText: sessionStateText(session, machine, t),
153
- showSecondLine: degraded || session.status !== "idle" && session.status !== "running",
153
+ stateText: sessionStateText(session, machine, t, resumeClock),
154
+ tone: held && !degraded ? "warning" : sessionVariant(session.status, machine, "muted"),
155
+ showSecondLine: degraded || held || session.status !== "idle" && session.status !== "running",
154
156
  live: isActiveSession(session) && !degraded
155
157
  };
156
158
  }
@@ -160,10 +162,18 @@ function showsPinMark(session) {
160
162
  return !!session.pinnedAt && isArchived(session);
161
163
  }
162
164
  /** A session at work shows a turning mark, which tells it from one resting
163
- * between turns by its shape and so holds with reduced motion. Any other
164
- * shows a dot in its state's tone, pulsing while it waits on the reader. */
165
+ * between turns by its shape and so holds with reduced motion. One held by a
166
+ * usage limit is still, and keeps a dot's tone for a host that draws only
167
+ * dots. Any other shows a dot in its state's tone, pulsing while it waits on
168
+ * the reader. */
165
169
  function sessionMark(session, machine) {
166
170
  if (isWorking(session, machine)) return { working: true };
171
+ if (waitsOnUsageLimit(session) && !isMachineDown(machine)) return {
172
+ working: false,
173
+ usageLimit: true,
174
+ tone: "warning",
175
+ pulse: false
176
+ };
167
177
  return {
168
178
  working: false,
169
179
  tone: sessionVariant(session.status, machine, "success"),
@@ -168,8 +168,12 @@ export declare function usePwCodeSessionScreen({ conversation, composer, read, m
168
168
  /** Why the workspace's own settings, skills and hooks did not load. */
169
169
  untrusted: string | null;
170
170
  activity: PwCodeSessionActivity | null;
171
+ /** The turn waits at its account's usage limit, as the activity line
172
+ * says; not while the feed reconnects, which that line says instead. For
173
+ * `useClaudeAccountPanel`'s `waitingAtLimit`. */
174
+ waitingAtLimit: boolean;
171
175
  goal: PwCodeGoalLabel | null;
172
- commands: import("./command.js").PwCodeSlashCommand[];
176
+ commands: import("./command.js").PwCodePaletteOption[];
173
177
  showAuthor: boolean;
174
178
  /** A message may go without text while images go with it. */
175
179
  allowEmpty: boolean;
@@ -170,6 +170,12 @@ function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFo
170
170
  recheck,
171
171
  refetch
172
172
  ]);
173
+ const activity = sessionActivity({
174
+ composer,
175
+ transcript,
176
+ liveState,
177
+ claudeModel: claude.available && isClaudeModel(settings.model.value)
178
+ }, t, tTranscript);
173
179
  return {
174
180
  /** The session's state in a sentence, for a screen reader. */
175
181
  statusText: composer.status ? sessionStatusText({
@@ -182,19 +188,18 @@ function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFo
182
188
  act
183
189
  },
184
190
  /** The transcript has yet to load for the first time. */
185
- loading: read.isLoading && !detail,
191
+ loading: read.isLoading && !detail && !conversation.endOnly,
186
192
  /** Shown in place of a transcript that never loaded: why, or undefined
187
193
  * for the host's own line. */
188
194
  failed: loadFailure(read.error, !!detail, describeError),
189
195
  retry,
190
196
  /** Why the workspace's own settings, skills and hooks did not load. */
191
197
  untrusted: detail?.workspaceUntrusted ? t("detail.untrusted") : null,
192
- activity: sessionActivity({
193
- composer,
194
- transcript,
195
- liveState,
196
- claudeModel: claude.available && isClaudeModel(settings.model.value)
197
- }, t, tTranscript),
198
+ activity,
199
+ /** The turn waits at its account's usage limit, as the activity line
200
+ * says; not while the feed reconnects, which that line says instead. For
201
+ * `useClaudeAccountPanel`'s `waitingAtLimit`. */
202
+ waitingAtLimit: activity?.kind === "usageLimit",
198
203
  goal: goalLabel(conversation.goal, t),
199
204
  commands: paletteOptions(composer.palette, claude.available ? t("claude.choose") : void 0, t("detail.archiveCommand")),
200
205
  showAuthor: conversation.all.some((m) => m.author),
@@ -1,7 +1,8 @@
1
1
  import type { ApprovalAnswerValue, MessagePaste } from '@parallelworks/ui/ai/headless';
2
2
  import { DateTime } from 'luxon';
3
- import type { KeyedMutator } from 'swr';
4
- import type { PwCodeApiError, PwCodeClient, PwCodeQuery, PwCodeResult, Schemas } from './apiClient.js';
3
+ import { type KeyedMutator } from 'swr';
4
+ import { type PwCodeApiError, type PwCodeClient, type PwCodeQuery, type PwCodeResult, type Schemas } from './apiClient.js';
5
+ import type { SessionsFeed } from './sessionsFeed.js';
5
6
  type Session = Schemas['AgentSession'];
6
7
  type SessionDetail = Schemas['AgentSessionDetail'];
7
8
  type SessionsResponse = Schemas['AgentSessionsResponse'];
@@ -44,12 +45,26 @@ export interface PwCodeSessionOptions {
44
45
  * and the preview is loaded from there when it is drawn: previews are most
45
46
  * of what a transcript with pictures weighs. */
46
47
  previewsByRef?: boolean | undefined;
48
+ /** Whether the host's `fetch` hands over a response's body as it arrives
49
+ * (`response.body`), as a browser's does. Set, a session's transcript is
50
+ * read end first, and the end of the conversation is drawn while the rest
51
+ * arrives: over a slow connection the transcript is most of the wait. A
52
+ * host without it, such as React Native's own fetch, reads the session
53
+ * whole. */
54
+ transcriptEndFirst?: boolean | undefined;
47
55
  }
48
- export declare function sessionsApi(client: PwCodeClient, { previewsByRef }?: PwCodeSessionOptions): {
56
+ export declare function sessionsApi(client: PwCodeClient, { previewsByRef, transcriptEndFirst, }?: PwCodeSessionOptions,
57
+ /** Told the machines of each listing that answers. */
58
+ listed?: (machines: Schemas['AgentMachine'][]) => void,
59
+ /** The listing as the platform sends it over a socket, for a host that opens them. */
60
+ feed?: SessionsFeed): {
49
61
  useSessions: () => PwCodeQuery<SessionsResponse>;
50
62
  useWaitingSessionCount: (enabled: boolean) => number;
51
63
  useSessionDetail: (machine: string, id: string, listed: Session | undefined) => {
52
64
  data: SessionDetail | undefined;
65
+ /** The session with only the end of its history, while the rest of the
66
+ * transcript is still arriving and there is nothing else to show. */
67
+ preview: SessionDetail | undefined;
53
68
  error: PwCodeApiError | undefined;
54
69
  isLoading: boolean;
55
70
  mutate: KeyedMutator<SessionDetail>;
@@ -75,6 +90,7 @@ export declare function sessionsApi(client: PwCodeClient, { previewsByRef }?: Pw
75
90
  };
76
91
  stopSubagent: (machine: string, id: string, subId: string) => Promise<unknown>;
77
92
  stopAllSubagents: (machine: string, id: string) => Promise<unknown>;
93
+ dismissSubagent: (machine: string, id: string, subId: string) => Promise<unknown>;
78
94
  useSessionWorktree: (s: Session | undefined) => PwCodeQuery<Schemas['AgentSessionWorktree']>;
79
95
  leaveWorktree: (s: Session, removeRoot?: string) => Promise<{
80
96
  left?: Schemas['AgentWorktreeLeft'];