@parallelworks/code 0.1.0 → 0.3.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 +171 -24
  2. package/dist/ago.d.ts +8 -0
  3. package/dist/ago.js +26 -0
  4. package/dist/api.d.ts +3547 -0
  5. package/dist/apiClient.d.ts +26 -0
  6. package/dist/apiClient.js +5 -0
  7. package/dist/base64.d.ts +3 -0
  8. package/dist/base64.js +15 -0
  9. package/dist/chatHandoff.d.ts +12 -0
  10. package/dist/chatHandoff.js +27 -0
  11. package/dist/claudeAccounts.d.ts +112 -0
  12. package/dist/claudeAccounts.js +234 -0
  13. package/dist/claudeApi.d.ts +27 -0
  14. package/dist/claudeApi.js +250 -0
  15. package/dist/claudeSignIn.d.ts +62 -0
  16. package/dist/claudeSignIn.js +239 -0
  17. package/dist/command.d.ts +47 -0
  18. package/dist/command.js +64 -0
  19. package/dist/commandsApi.d.ts +64 -0
  20. package/dist/commandsApi.js +267 -0
  21. package/dist/contextRow.d.ts +25 -0
  22. package/dist/contextRow.js +16 -0
  23. package/dist/createPwCodeApi.d.ts +696 -0
  24. package/dist/createPwCodeApi.js +33 -0
  25. package/dist/howSessionsAppear.d.ts +12 -0
  26. package/dist/howSessionsAppear.js +24 -0
  27. package/dist/index.d.ts +39 -3
  28. package/dist/index.js +38 -3
  29. package/dist/locales/en/agentTranscript.js +162 -0
  30. package/dist/locales/en/agents.js +380 -0
  31. package/dist/locales/en.d.ts +523 -0
  32. package/dist/locales/en.js +8 -0
  33. package/dist/locales/es/agentTranscript.js +162 -0
  34. package/dist/locales/es/agents.js +380 -0
  35. package/dist/locales/es.d.ts +3 -0
  36. package/dist/locales/es.js +8 -0
  37. package/dist/locales/ja/agentTranscript.js +162 -0
  38. package/dist/locales/ja/agents.js +380 -0
  39. package/dist/locales/ja.d.ts +3 -0
  40. package/dist/locales/ja.js +8 -0
  41. package/dist/locales/ko/agentTranscript.js +162 -0
  42. package/dist/locales/ko/agents.js +380 -0
  43. package/dist/locales/ko.d.ts +3 -0
  44. package/dist/locales/ko.js +8 -0
  45. package/dist/locales/zh/agentTranscript.js +162 -0
  46. package/dist/locales/zh/agents.js +380 -0
  47. package/dist/locales/zh.d.ts +3 -0
  48. package/dist/locales/zh.js +8 -0
  49. package/dist/machine.d.ts +51 -0
  50. package/dist/machine.js +60 -0
  51. package/dist/messages.d.ts +17 -0
  52. package/dist/messages.js +31 -0
  53. package/dist/models.d.ts +47 -0
  54. package/dist/models.js +49 -0
  55. package/dist/notices.d.ts +12 -0
  56. package/dist/notices.js +120 -0
  57. package/dist/pullRequest.d.ts +8 -0
  58. package/dist/pullRequest.js +29 -0
  59. package/dist/pullRequestList.d.ts +52 -0
  60. package/dist/pullRequestList.js +106 -0
  61. package/dist/query.d.ts +28 -0
  62. package/dist/query.js +25 -0
  63. package/dist/session.d.ts +75 -1
  64. package/dist/session.js +101 -1
  65. package/dist/sessionActions.d.ts +105 -0
  66. package/dist/sessionActions.js +178 -0
  67. package/dist/sessionEvents.d.ts +27 -0
  68. package/dist/sessionEvents.js +212 -0
  69. package/dist/sessionGroups.d.ts +49 -0
  70. package/dist/sessionGroups.js +72 -0
  71. package/dist/sessionHeader.d.ts +14 -0
  72. package/dist/sessionHeader.js +16 -0
  73. package/dist/sessionList.d.ts +134 -0
  74. package/dist/sessionList.js +271 -0
  75. package/dist/sessionsApi.d.ts +105 -0
  76. package/dist/sessionsApi.js +511 -0
  77. package/dist/settingsApi.d.ts +36 -0
  78. package/dist/settingsApi.js +151 -0
  79. package/dist/startSession.d.ts +138 -0
  80. package/dist/startSession.js +234 -0
  81. package/dist/terminalHandoffPanel.d.ts +30 -0
  82. package/dist/terminalHandoffPanel.js +33 -0
  83. package/dist/toolStrings.d.ts +4 -0
  84. package/dist/toolStrings.js +95 -0
  85. package/dist/transcript.d.ts +14 -1
  86. package/dist/transcript.js +55 -14
  87. package/dist/types.d.ts +20 -1
  88. package/dist/usageLimit.d.ts +8 -0
  89. package/dist/usageLimit.js +13 -0
  90. package/dist/useAwayRecap.d.ts +30 -0
  91. package/dist/useAwayRecap.js +75 -0
  92. package/dist/useComposer.d.ts +121 -0
  93. package/dist/useComposer.js +244 -0
  94. package/dist/useComposerImages.d.ts +66 -0
  95. package/dist/useComposerImages.js +195 -0
  96. package/dist/useConversation.d.ts +190 -0
  97. package/dist/useConversation.js +287 -0
  98. package/dist/useSubagent.d.ts +58 -0
  99. package/dist/useSubagent.js +149 -0
  100. package/dist/useTranscript.d.ts +4 -1
  101. package/dist/useTranscript.js +54 -11
  102. package/dist/wording.d.ts +43 -0
  103. package/dist/wording.js +101 -0
  104. package/dist/workingDirectories.d.ts +32 -0
  105. package/dist/workingDirectories.js +71 -0
  106. package/dist/worktreeChoice.d.ts +31 -0
  107. package/dist/worktreeChoice.js +38 -0
  108. package/locales/en/agentTranscript.json +154 -0
  109. package/locales/en/agents.json +366 -0
  110. package/locales/es/agentTranscript.json +154 -0
  111. package/locales/es/agents.json +366 -0
  112. package/locales/ja/agentTranscript.json +154 -0
  113. package/locales/ja/agents.json +366 -0
  114. package/locales/ko/agentTranscript.json +154 -0
  115. package/locales/ko/agents.json +366 -0
  116. package/locales/zh/agentTranscript.json +154 -0
  117. package/locales/zh/agents.json +366 -0
  118. package/package.json +24 -9
@@ -1,16 +1,19 @@
1
- import { INTERRUPTED_NOTICE, applyPartDelta, askQuestionsFromArgs, classifyPseudoUserMessage, finalizeParts, firstNonEmptyLine, hiddenTranscriptTool, interruptionNotice, parseSubagentNotice, planFromArgs, resultFailed, subagentDeliveryLine, taskCallFromArgs } from "@parallelworks/ui/ai/headless";
2
1
  import { DateTime } from "luxon";
2
+ import { INTERRUPTED_NOTICE, applyPartDelta, askQuestionsFromArgs, classifyPseudoUserMessage, finalizeParts, firstNonEmptyLine, hiddenTranscriptTool, interruptionNotice, parseSubagentNotice, planFromArgs, resultFailed, subagentDeliveryLine, taskCallFromArgs } from "@parallelworks/ui/ai/headless";
3
3
  // src/transcript.ts
4
- var MAIN_SESSION_AUTHOR = {
5
- id: "main",
6
- username: "main session"
7
- };
4
+ function mainConversationAuthor(words) {
5
+ return {
6
+ id: "main",
7
+ username: "main session",
8
+ name: words?.mainConversation ?? "Main conversation"
9
+ };
10
+ }
8
11
  var synthCounter = 0;
9
12
  function synthId(prefix) {
10
13
  synthCounter += 1;
11
14
  return `${prefix}-${synthCounter}`;
12
15
  }
13
- function userMessage(text, fromMain, id, pastes, images, imageUrl) {
16
+ function userMessage(text, author, id, pastes, images, imageUrl) {
14
17
  const pseudo = classifyPseudoUserMessage("user", text);
15
18
  const attachments = imageAttachments(images, imageUrl);
16
19
  return {
@@ -18,7 +21,7 @@ function userMessage(text, fromMain, id, pastes, images, imageUrl) {
18
21
  role: "user",
19
22
  content: text,
20
23
  ...pseudo ? { pseudo } : {},
21
- ...fromMain ? { author: MAIN_SESSION_AUTHOR } : {},
24
+ ...author ? { author } : {},
22
25
  ...pastes?.length ? { pastes } : {},
23
26
  ...attachments.length ? { attachments } : {}
24
27
  };
@@ -208,7 +211,7 @@ function historyToMessages(history, options = {}) {
208
211
  }
209
212
  flush(true);
210
213
  messages.push({
211
- ...userMessage(command, false, `h-u-${index}`),
214
+ ...userMessage(command, void 0, `h-u-${index}`),
212
215
  commandAnswer: answer
213
216
  });
214
217
  };
@@ -236,7 +239,7 @@ function historyToMessages(history, options = {}) {
236
239
  append(shellRunPart(shell.command, shell.output), index);
237
240
  return;
238
241
  }
239
- messages.push(userMessage(item.text ?? "", item.fromMain ?? false, `h-u-${index}`, item.pastes, item.images, options.imageUrl));
242
+ messages.push(userMessage(item.text ?? "", item.fromMain ? mainConversationAuthor(words) : void 0, `h-u-${index}`, item.pastes, item.images, options.imageUrl));
240
243
  return;
241
244
  }
242
245
  case "assistant": {
@@ -500,6 +503,34 @@ function initialTranscript(detail, options = {}) {
500
503
  seededSeq: detail.lastSeq ?? 0
501
504
  };
502
505
  }
506
+ /** A subagent's detail as the session detail its transcript seeds from. Its run
507
+ * has no turn id on the wire, so its own id names the one in flight. */
508
+ function subagentSessionDetail(sub) {
509
+ const running = sub.status === "running";
510
+ return {
511
+ status: sub.approvals?.length ? "awaiting_approval" : running ? "running" : "idle",
512
+ history: sub.history ?? [],
513
+ approvals: sub.approvals ?? [],
514
+ lastSeq: sub.lastSeq ?? 0,
515
+ ...running ? { turnId: sub.id } : {},
516
+ ...running && sub.startedAt ? { turnStartedAt: sub.startedAt } : {}
517
+ };
518
+ }
519
+ /** A session frame as one subagent's transcript reads it. A turn someone
520
+ * prompted on the subagent streams under its id, and a note it was handed
521
+ * arrives as its own event; the task it was given streams nothing, so a frame
522
+ * that only says it moved on is `refetch`. Null is a frame for someone else. */
523
+ function subagentFrame(ev, id) {
524
+ if (ev.type === "replay_truncated" || ev.type === "approval_resolved") return ev;
525
+ if (ev.type === "approval_request") return ev.approval?.subagentId === id ? ev : null;
526
+ if (ev.id !== id || ev.seq === 0) return null;
527
+ const { id: _, ...frame } = ev;
528
+ if (ev.type === "subagent_user_note") return {
529
+ ...frame,
530
+ type: "user_note"
531
+ };
532
+ return ev.type.startsWith("subagent_") ? "refetch" : frame;
533
+ }
503
534
  /** The approvals the live feed is still waiting on. */
504
535
  function pendingApprovals(transcript) {
505
536
  return (transcript.streaming?.parts ?? []).filter((p) => p.kind === "approval" && !p.resolved);
@@ -546,7 +577,7 @@ function resolveApprovalEverywhere(state, id) {
546
577
  * short, so the page must not close the turn either: its open tool calls
547
578
  * would read as interrupted while they are still running. */
548
579
  function appendOwnMessage(state, text, id, pastes, previews) {
549
- const message = userMessage(text, false, id, pastes, previews);
580
+ const message = userMessage(text, void 0, id, pastes, previews);
550
581
  if (turnRunning(state)) return {
551
582
  ...state,
552
583
  queued: [...state.queued, message]
@@ -560,6 +591,11 @@ function appendOwnMessage(state, text, id, pastes, previews) {
560
591
  opening: message.id
561
592
  };
562
593
  }
594
+ /** A subagent runs one turn at a time, so a message sent to it starts its next:
595
+ * a turn the transcript still shows running has ended. */
596
+ function appendTurnMessage(state, text, id, pastes, previews) {
597
+ return appendOwnMessage(finishTurn(state), text, id, pastes, previews);
598
+ }
563
599
  /** An own message takes the pastes and images its echo says the model received. */
564
600
  function withSentPastesAndImages(messages, ev, id, imageUrl) {
565
601
  const pastes = ev.pastes?.length ? ev.pastes : null;
@@ -578,7 +614,7 @@ function withSentPastesAndImages(messages, ev, id, imageUrl) {
578
614
  function appendSteeredMessage(state, text, id, pastes, previews) {
579
615
  return {
580
616
  ...state,
581
- steered: [...state.steered, userMessage(text, false, id, pastes, previews)]
617
+ steered: [...state.steered, userMessage(text, void 0, id, pastes, previews)]
582
618
  };
583
619
  }
584
620
  /** The daemon queued a message this page had shown as sent, because the turn
@@ -1048,6 +1084,10 @@ function placeNotes(state) {
1048
1084
  streaming: null
1049
1085
  };
1050
1086
  }
1087
+ function onlyAnsweredApprovals(message) {
1088
+ const parts = message?.parts ?? [];
1089
+ return parts.length > 0 && parts.every((p) => p.kind === "approval" && p.resolved);
1090
+ }
1051
1091
  var OUTPUT_EVENTS = /* @__PURE__ */ new Set([
1052
1092
  "chunk",
1053
1093
  "reasoning",
@@ -1088,7 +1128,7 @@ function noteHandedOver(state, id, ev, imageUrl) {
1088
1128
  return {
1089
1129
  ...state,
1090
1130
  steered,
1091
- notes: note ? withSentPastesAndImages([...state.notes, note], ev, note.id, imageUrl) : [...state.notes, userMessage(text, false, void 0, ev.pastes, ev.images, imageUrl)]
1131
+ notes: note ? withSentPastesAndImages([...state.notes, note], ev, note.id, imageUrl) : [...state.notes, userMessage(text, void 0, void 0, ev.pastes, ev.images, imageUrl)]
1092
1132
  };
1093
1133
  }
1094
1134
  function nowIso() {
@@ -1211,7 +1251,7 @@ function applyStreamEvent(state, ev, options = {}) {
1211
1251
  next = finishTurn(next);
1212
1252
  next = ownEcho ? takeEcho(next, options.echoOf, ev, options.imageUrl) : {
1213
1253
  ...next,
1214
- messages: [...next.messages, userMessage(ev.content ?? "", false, void 0, ev.pastes, ev.images, options.imageUrl)]
1254
+ messages: [...next.messages, userMessage(ev.content ?? "", void 0, void 0, ev.pastes, ev.images, options.imageUrl)]
1215
1255
  };
1216
1256
  next = {
1217
1257
  ...next,
@@ -1232,6 +1272,7 @@ function applyStreamEvent(state, ev, options = {}) {
1232
1272
  break;
1233
1273
  case "approval_resolved":
1234
1274
  if (ev.approvalId) next = resolveApprovalEverywhere(next, ev.approvalId);
1275
+ if (next.turnEnded && onlyAnsweredApprovals(next.streaming)) next = finishTurn(next);
1235
1276
  break;
1236
1277
  case "usage_limit_wait":
1237
1278
  next = {
@@ -1274,4 +1315,4 @@ function applyStreamEvent(state, ev, options = {}) {
1274
1315
  effects: controlEffects(ev)
1275
1316
  };
1276
1317
  }
1277
- export { TURN_VERBS, appendOwnMessage, appendShellRun, appendSteeredMessage, applyStreamEvent, approvalAnswerBody, approvalToPart, bashRunning, dropMessage, historyToMessages, initialTranscript, liveSessionStatus, markQueued, pendingApprovals, pendingMessages, resolveApprovalEverywhere, resumeCursor, reviewingCount, todosFromArgs, toolDecision, turnRunning, turnVerb, userInterruptedTool };
1318
+ export { TURN_VERBS, appendOwnMessage, appendShellRun, appendSteeredMessage, appendTurnMessage, applyStreamEvent, approvalAnswerBody, approvalToPart, bashRunning, dropMessage, historyToMessages, initialTranscript, liveSessionStatus, markQueued, pendingApprovals, pendingMessages, resolveApprovalEverywhere, resumeCursor, reviewingCount, subagentFrame, subagentSessionDetail, todosFromArgs, toolDecision, turnRunning, turnVerb, userInterruptedTool };
package/dist/types.d.ts CHANGED
@@ -110,7 +110,7 @@ export interface PwCodeSessionState {
110
110
  model: string;
111
111
  /** The names to show in place of model IDs; an ID it leaves out has none. */
112
112
  modelNames?: Record<string, string>;
113
- /** Empty for the model's own default. */
113
+ /** A level on pw code's scale; empty from a daemon that predates it. */
114
114
  effort?: string;
115
115
  allocation?: string;
116
116
  permissionMode?: string;
@@ -126,6 +126,14 @@ export interface PwCodeSessionState {
126
126
  allowedDirs?: PwCodeAllowedDirectory[] | null;
127
127
  /** The session's directory in the git worktree it moved into; unset while it works where it launched. */
128
128
  worktree?: string;
129
+ /** Each subagent's own tokens, by its id; one that has used none is left out. */
130
+ subagentUsage?: Record<string, PwCodeSubagentUsage>;
131
+ }
132
+ export interface PwCodeSubagentUsage {
133
+ inputTokens?: number;
134
+ outputTokens?: number;
135
+ /** Its latest request's input, cached tokens included. */
136
+ latestInputTokens?: number;
129
137
  }
130
138
  /** Where a session's /goal loop stands; unset when it has no goal. */
131
139
  export interface PwCodeGoalStatus {
@@ -204,6 +212,17 @@ export interface PwCodeSessionDetail {
204
212
  addDirs?: PwCodeAddedDirectory[] | null;
205
213
  allowedDirs?: PwCodeAllowedDirectory[] | null;
206
214
  }
215
+ /** A subagent's transcript, read at lastSeq of its session's feed. */
216
+ export interface PwCodeSubagentDetail {
217
+ id: string;
218
+ status: 'running' | 'done' | 'failed' | 'stopped';
219
+ /** When its latest run began: the task it was given, or a turn someone prompted on it. */
220
+ startedAt?: string;
221
+ history?: PwCodeHistoryItem[] | null;
222
+ /** The approvals it is waiting on. */
223
+ approvals?: PwCodeApprovalRequest[] | null;
224
+ lastSeq?: number;
225
+ }
207
226
  /** The body the daemon accepts as the answer to an approval. */
208
227
  export interface PwCodeApprovalAnswer {
209
228
  allowed?: boolean;
@@ -0,0 +1,8 @@
1
+ export interface UsageLimitWait {
2
+ /** That the turn waits for the limit to reset, and when once that is known. */
3
+ waiting: string;
4
+ /** What offers another Claude Code account, which takes the turn over at once. */
5
+ switchAccount: string;
6
+ }
7
+ /** The running turn's line while it waits for a usage limit to reset. */
8
+ export declare function useUsageLimitWait(resumeAt: string | null | undefined): UsageLimitWait;
@@ -0,0 +1,13 @@
1
+ import { usePwCodeTranslations } from "./messages.js";
2
+ import { useResumeTime } from "./notices.js";
3
+ // src/usageLimit.ts
4
+ /** The running turn's line while it waits for a usage limit to reset. */
5
+ function useUsageLimitWait(resumeAt) {
6
+ const t = usePwCodeTranslations("agents");
7
+ const resumeTime = useResumeTime();
8
+ return {
9
+ waiting: resumeAt ? t("detail.waitingForUsageLimitUntil", { time: resumeTime(resumeAt) }) : t("detail.waitingForUsageLimit"),
10
+ switchAccount: t("detail.switchClaudeAccount")
11
+ };
12
+ }
13
+ export { useUsageLimitWait };
@@ -0,0 +1,30 @@
1
+ import type { PwCodeApi } from './createPwCodeApi.js';
2
+ export declare const recapAfterTurnMs: number;
3
+ export declare const recapAfterLeavingMs = 2000;
4
+ /** Whether the reader has the session in front of them, as the host's app knows it. */
5
+ export interface PwCodePresence {
6
+ /** Whether the reader is away: the app is out of sight or out of focus. */
7
+ away: () => boolean;
8
+ /** Calls `leave` when the reader may have left and `back` when they may
9
+ * have come back, until the returned call. Each reads `away` itself. */
10
+ watch: (on: {
11
+ leave: () => void;
12
+ back: () => void;
13
+ }) => () => void;
14
+ }
15
+ /** Has the session recapped while the reader is away from it, as pw code
16
+ * does while its terminal is out of focus, so the recap is waiting when they
17
+ * come back. The machine declines while its recaps are off. */
18
+ export declare function useAwayRecap({ api, machine, sessionId, turnEndSeq, idle, drafting, presence, }: {
19
+ api: Pick<PwCodeApi, 'requestRecap'>;
20
+ machine: string;
21
+ sessionId: string;
22
+ /** Changes each time the reader's view sees a main turn end. */
23
+ turnEndSeq: number | undefined;
24
+ /** Whether the session rests between turns and can be reached; read when the wait ends. */
25
+ idle: boolean;
26
+ /** Whether a message is being typed: nothing is asked for over one. Read when the wait ends. */
27
+ drafting: () => boolean;
28
+ /** Read when the session opens and whenever it is asked again. */
29
+ presence: PwCodePresence;
30
+ }): void;
@@ -0,0 +1,75 @@
1
+ import { useCallback, useEffect, useRef } from "react";
2
+ import { DateTime } from "luxon";
3
+ // src/useAwayRecap.ts
4
+ var recapAfterTurnMs = 12e4;
5
+ var recapAfterLeavingMs = 2e3;
6
+ function nowMs() {
7
+ return DateTime.now().toMillis();
8
+ }
9
+ /** Has the session recapped while the reader is away from it, as pw code
10
+ * does while its terminal is out of focus, so the recap is waiting when they
11
+ * come back. The machine declines while its recaps are off. */
12
+ function useAwayRecap({ api, machine, sessionId, turnEndSeq, idle, drafting, presence }) {
13
+ const idleRef = useRef(idle);
14
+ idleRef.current = idle;
15
+ const draftingRef = useRef(drafting);
16
+ draftingRef.current = drafting;
17
+ const presenceRef = useRef(presence);
18
+ presenceRef.current = presence;
19
+ const apiRef = useRef(api);
20
+ apiRef.current = api;
21
+ const turnEndedAt = useRef(null);
22
+ const counted = useRef(void 0);
23
+ const leftAt = useRef(null);
24
+ const timer = useRef(void 0);
25
+ const request = useRef(null);
26
+ const ask = useCallback(async () => {
27
+ if (request.current || !presenceRef.current.away() || !idleRef.current || draftingRef.current()) return;
28
+ const controller = new AbortController();
29
+ request.current = controller;
30
+ await apiRef.current.requestRecap(machine, sessionId, controller.signal).catch(() => void 0);
31
+ if (request.current === controller) request.current = null;
32
+ }, [machine, sessionId]);
33
+ const arm = useCallback(() => {
34
+ clearTimeout(timer.current);
35
+ const ended = turnEndedAt.current;
36
+ const left = leftAt.current;
37
+ if (ended === null || left === null) return;
38
+ const now = nowMs();
39
+ const wait = Math.max(ended + recapAfterTurnMs - now, left + recapAfterLeavingMs - now);
40
+ timer.current = setTimeout(() => void ask(), wait);
41
+ }, [ask]);
42
+ useEffect(() => {
43
+ const away = () => presenceRef.current.away();
44
+ leftAt.current = away() ? nowMs() : null;
45
+ const leave = () => {
46
+ if (leftAt.current === null && away()) {
47
+ leftAt.current = nowMs();
48
+ arm();
49
+ }
50
+ };
51
+ const back = () => {
52
+ if (!away()) {
53
+ leftAt.current = null;
54
+ clearTimeout(timer.current);
55
+ }
56
+ };
57
+ const unwatch = presenceRef.current.watch({
58
+ leave,
59
+ back
60
+ });
61
+ return () => {
62
+ unwatch();
63
+ clearTimeout(timer.current);
64
+ request.current?.abort();
65
+ request.current = null;
66
+ };
67
+ }, [arm]);
68
+ useEffect(() => {
69
+ if (turnEndSeq === void 0 || turnEndSeq === counted.current) return;
70
+ counted.current = turnEndSeq;
71
+ turnEndedAt.current = nowMs();
72
+ arm();
73
+ }, [turnEndSeq, arm]);
74
+ }
75
+ export { recapAfterLeavingMs, recapAfterTurnMs, useAwayRecap };
@@ -0,0 +1,121 @@
1
+ import type { MessagePaste } from '@parallelworks/ui/ai/headless';
2
+ import type { Schemas } from './apiClient.js';
3
+ import type { PwCodeApi } from './createPwCodeApi.js';
4
+ import type { PwCodeConversation } from './useConversation.js';
5
+ import type { PwCodeTakenImages } from './useComposerImages.js';
6
+ /** The composer's history of sent prompts, as `@parallelworks/ui/ai`'s
7
+ * `ComposerHistory` takes it. */
8
+ export interface PwCodeComposerHistory {
9
+ /** Composers with the same name share one history. */
10
+ name: string;
11
+ /** Text to forget, such as a command carrying a secret. */
12
+ skip?: ((text: string) => boolean) | undefined;
13
+ }
14
+ /** Per person, since someone else can sign in where the history is kept, and
15
+ * without `/auth`, which can carry a key. */
16
+ export declare function promptHistory(username: string): PwCodeComposerHistory;
17
+ /** What a command printed, shown below the transcript under the command as typed. */
18
+ export interface PwCodeCommandOutput {
19
+ id: number;
20
+ command: string;
21
+ text: string;
22
+ }
23
+ export declare function useCommandOutputs(): {
24
+ outputs: PwCodeCommandOutput[];
25
+ add: (command: string, text: string) => void;
26
+ dismiss: (id: number) => void;
27
+ clear: () => void;
28
+ };
29
+ /** What the reader can do from an open session's composer, and how the
30
+ * session stands for it: what is typed goes out as a message, a direction to
31
+ * the running turn, a command or a `!` shell run, and the composer locks
32
+ * while the machine is unreachable, the session is archived or live
33
+ * elsewhere, or it waits on an approval. */
34
+ export declare function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo, feed, staleFor, images, handleLocally, notify, onCleared, onArchived, }: {
35
+ api: PwCodeApi;
36
+ machine: string;
37
+ sessionId: string;
38
+ /** What `usePwCodeConversation` returned for the session. */
39
+ conversation: PwCodeConversation;
40
+ /** The session's machine, as `api.useMachine` reads it. */
41
+ machineInfo: Schemas['AgentMachine'] | undefined;
42
+ /** The session's feed, as `api.useSessionEvents` reports it. */
43
+ feed: {
44
+ connected: boolean;
45
+ disconnected: boolean;
46
+ };
47
+ /** How long ago the transcript was last read, already abbreviated: see `useLastReadAt`. */
48
+ staleFor: string;
49
+ /** The images waiting to go with the next message, as `useComposerImages` holds them. */
50
+ images?: {
51
+ take: () => Promise<PwCodeTakenImages>;
52
+ taking: boolean;
53
+ } | undefined;
54
+ /** Typed text the host acts on itself, such as a command that opens one of
55
+ * its own panels; true takes it, sending nothing. */
56
+ handleLocally?: ((typed: string) => boolean) | undefined;
57
+ /** Tells the reader something in passing, such as in a toast. */
58
+ notify: (text: string) => void;
59
+ /** Shows the session `/clear` started in place of this one. */
60
+ onCleared: (newId: string) => void;
61
+ /** Leaves the session `/archive` archived. */
62
+ onArchived: () => void;
63
+ }): {
64
+ /** Sends what was typed; false hands it back to the composer. */
65
+ send: (typed: string, pastes?: MessagePaste[]) => Promise<boolean>;
66
+ turn: {
67
+ running: boolean;
68
+ stop: () => Promise<void>;
69
+ stopping: boolean;
70
+ };
71
+ composer: {
72
+ placeholder: string;
73
+ hint: string;
74
+ locked: boolean;
75
+ disabled: boolean;
76
+ };
77
+ /** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
78
+ sessionLock: {
79
+ placeholder: string;
80
+ hint: string;
81
+ locked: boolean;
82
+ } | null;
83
+ shellRun: string | null;
84
+ outputs: PwCodeCommandOutput[];
85
+ dismissOutput: (id: number) => void;
86
+ palette: {
87
+ commands: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
88
+ mcpPrompts: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
89
+ prompts: string[] | null;
90
+ } | null;
91
+ paletteLoading: boolean;
92
+ /** Opens the command menu, which asks for the session's palette again. */
93
+ openPalette: () => undefined;
94
+ loadPalette: () => Promise<{
95
+ commands: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
96
+ mcpPrompts: import("./api.js").components["schemas"]["AgentSlashCommand"][] | null;
97
+ prompts: string[] | null;
98
+ } | null>;
99
+ status: import("./types.js").PwCodeSessionStatus | null;
100
+ approvals: {
101
+ kind: "ask" | "confirm" | "plan";
102
+ }[] | null | undefined;
103
+ unreachable: boolean;
104
+ reconnecting: boolean;
105
+ archived: boolean;
106
+ machineName: string;
107
+ /** A turn is under way on a machine that answers. */
108
+ working: boolean;
109
+ checkingGoal: boolean;
110
+ /** The session rests between turns and can be reached. */
111
+ idle: boolean;
112
+ /** Ends the transcript while the machine cannot be reached. */
113
+ endNote: string | undefined;
114
+ /** The offer to move the Bash commands the turn waits on to the background. */
115
+ background: {
116
+ offered: boolean;
117
+ moving: boolean;
118
+ move: () => Promise<void>;
119
+ };
120
+ };
121
+ export type PwCodeComposer = ReturnType<typeof usePwCodeComposer>;