@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
@@ -24,31 +24,33 @@ var transcript = {
24
24
  "denyPath": "否,拒绝",
25
25
  "allowCall": "是,允许此调用",
26
26
  "denyCall": "否,拒绝此调用",
27
- "denyWithFeedback": "否,并向代理提供反馈",
28
- "feedbackPlaceholder": "告诉代理改为做什么…",
27
+ "denyWithFeedback": "否,并告诉助手原因",
28
+ "feedbackPlaceholder": "告诉助手改做什么…",
29
29
  "answered": "已回答",
30
30
  "allowedBy": "{name} 已允许",
31
+ "allowedWithChangesBy": "{name} 已更改后允许",
31
32
  "deniedBy": "{name} 已拒绝",
32
33
  "allowed": "已允许",
34
+ "allowedWithChanges": "已更改后允许",
33
35
  "denied": "已拒绝",
34
36
  "allowedByReviewer": "自动审核已允许",
35
37
  "deniedByReviewer": "自动审核已拒绝",
36
38
  "approvalExpired": "已过期,未获答复",
37
39
  "approvalTimedOut": "已拒绝:未及时答复",
38
- "reviewTimedOut": "已拒绝:自动审核超时",
39
- "reviewFailed": "已拒绝:自动审核失败",
40
+ "reviewTimedOut": "自动审核超时",
41
+ "reviewFailed": "自动审核失败",
40
42
  "writeOwnAnswer": "自己写答案…",
41
43
  "subagent": "任务",
42
44
  "tasks": "任务",
43
45
  "planPending": "计划正在终端中等待批准",
44
46
  "approvalPending": "正在终端中等待答复",
45
47
  "approvalOptions": "提供的选项",
46
- "approvalLabel": "正在等待你的答复",
48
+ "approvalLabel": "正在等待你的回答",
47
49
  "approvalAllowed": "已允许",
48
50
  "approvalDenied": "已拒绝",
49
51
  "approvalRequestExpired": "此请求已过期。请重新请求以运行。",
50
- "approvalWaitingOn": "正在等待 {name} 答复",
51
- "feedbackLabel": "给代理的反馈",
52
+ "approvalWaitingOn": "正在等待 {name} 回答",
53
+ "feedbackLabel": "给助手的反馈",
52
54
  "ownAnswerLabel": "你的答案",
53
55
  "typeYourAnswer": "输入你的答案…",
54
56
  "questionsLabel": "问题",
@@ -122,7 +124,10 @@ var queue = {
122
124
  "remove": "移除排队的消息",
123
125
  "waiting": "排队中 · 此回复结束后发送",
124
126
  "waitingNextStep": "排队中 · 在当前步骤后送达代理",
125
- "handedOver": "已发送到正在进行的轮次"
127
+ "handedOver": "已发送到正在进行的轮次",
128
+ "edit": "编辑",
129
+ "editLabel": "编辑排队的消息",
130
+ "editHint": "按 ↑ 编辑排队的消息"
126
131
  };
127
132
  var paste = {
128
133
  "title": "粘贴的文本",
@@ -130,7 +135,54 @@ var paste = {
130
135
  "saving": "保存中…",
131
136
  "remove": "移除粘贴内容"
132
137
  };
133
- var thinking = { "thoughtProcess": "思考过程" };
138
+ var thinking = {
139
+ "label": "思考中",
140
+ "ellipsis": "思考中...",
141
+ "thoughtFor": "思考了 {duration}",
142
+ "thoughtProcess": "思考过程",
143
+ "activity": "活动",
144
+ "ranToolCalls": "{count, plural, other {运行了 # 次工具调用}}",
145
+ "ranToolCallsAs": "{count, plural, other {以 {name} 的身份运行了 # 次工具调用}}"
146
+ };
147
+ var activity = {
148
+ "tokens": "↑{input} ↓{output} 个令牌",
149
+ "stop": "停止"
150
+ };
151
+ var input = {
152
+ "stopGenerating": "停止生成 (Escape)",
153
+ "loadingCommands": "正在加载命令..."
154
+ };
155
+ var thread = { "jumpToPrompt": "跳到消息:{text}" };
156
+ var find = {
157
+ "label": "在对话中查找",
158
+ "count": "{current, number} / {total, number}",
159
+ "countCapped": "{current, number} / {total, number}+",
160
+ "none": "无结果",
161
+ "previous": "上一个匹配项",
162
+ "next": "下一个匹配项",
163
+ "close": "关闭查找"
164
+ };
165
+ var chrome = { "jumpToLatest": "跳到最新" };
166
+ var messageMeta = { "copyLabel": "消息" };
167
+ var attachmentManager = {
168
+ "unnamedImage": "图片附件",
169
+ "unnamedFile": "文件",
170
+ "open": "打开 {name}",
171
+ "download": "下载 {name}",
172
+ "previousImage": "上一张图片",
173
+ "nextImage": "下一张图片",
174
+ "imagePosition": "第 {position, number} 张,共 {total, number} 张",
175
+ "fullImageFailed": "无法加载完整图片,正在显示预览。"
176
+ };
177
+ var markdownImage = {
178
+ "untitled": "图片",
179
+ "open": "在 GitHub 上打开 {name}"
180
+ };
181
+ var sidebar = {
182
+ "openSidebar": "打开侧边栏",
183
+ "closeSidebar": "关闭侧边栏",
184
+ "manageProviders": "管理提供商"
185
+ };
134
186
  var modelPicker = {
135
187
  "choose": "模型",
136
188
  "select": "选择模型",
@@ -155,8 +207,17 @@ var agentTranscript_default = {
155
207
  queue,
156
208
  paste,
157
209
  thinking,
210
+ activity,
211
+ input,
212
+ thread,
213
+ find,
214
+ chrome,
215
+ messageMeta,
216
+ attachmentManager,
217
+ markdownImage,
218
+ sidebar,
158
219
  modelPicker,
159
220
  allocationPicker,
160
221
  providerIssue
161
222
  };
162
- export { allocationPicker, agentTranscript_default as default, modelPicker, paste, providerIssue, queue, thinking, tools, transcript };
223
+ export { activity, allocationPicker, attachmentManager, chrome, agentTranscript_default as default, find, input, markdownImage, messageMeta, modelPicker, paste, providerIssue, queue, sidebar, thinking, thread, tools, transcript };
@@ -1,5 +1,11 @@
1
1
  // locales/zh/agents.json
2
2
  var title = "pw code";
3
+ var ago = {
4
+ "now": "刚刚",
5
+ "minutes": "{n}分",
6
+ "hours": "{n}小时",
7
+ "days": "{n}天"
8
+ };
3
9
  var sidebar = {
4
10
  "label": "会话",
5
11
  "listNoun": "会话",
@@ -7,6 +13,7 @@ var sidebar = {
7
13
  "search": "搜索会话",
8
14
  "find": "在此会话中查找",
9
15
  "noSessions": "还没有打开的会话",
16
+ "loading": "正在加载会话…",
10
17
  "open": "打开侧边栏",
11
18
  "close": "关闭侧边栏",
12
19
  "untitled": "未命名",
@@ -29,7 +36,6 @@ var sidebar = {
29
36
  "renameLabel": "会话名称",
30
37
  "renamePlaceholder": "输入新名称",
31
38
  "renameAction": "重命名",
32
- "moreOptions": "更多选项",
33
39
  "groupNeedsYou": "需要你处理",
34
40
  "groupActive": "活跃",
35
41
  "groupInactive": "非活跃",
@@ -45,8 +51,6 @@ var sidebar = {
45
51
  "deleteGroupTitle": "删除分组",
46
52
  "deleteGroupBody": "将删除“{name}”。其中的会话仍保留在列表中。",
47
53
  "groupsNeedUpdate": "请更新 {machine} 上的 pw,才能将其会话放入分组",
48
- "groupWaiting": "{count, plural, other {# 个会话需要你处理}}",
49
- "groupRunning": "{count, plural, other {# 个会话正在运行}}",
50
54
  "pin": "固定",
51
55
  "unpin": "取消固定",
52
56
  "pinned": "已固定",
@@ -72,9 +76,34 @@ var start = {
72
76
  "workspacePlaceholder": "/home/you/your-repo",
73
77
  "startButton": "启动会话",
74
78
  "chooseMachine": "选择机器",
79
+ "findingMachines": "正在查找你的机器…",
75
80
  "notAnswering": "无响应({count})",
76
81
  "chooseDirectory": "选择目录",
77
- "otherPath": "使用其他路径…",
82
+ "browse": "浏览",
83
+ "directorySuggestions": "目录",
84
+ "useDirectory": "使用此目录",
85
+ "useTypedPath": "按输入的路径使用",
86
+ "recentDirectories": "最近",
87
+ "inThisDirectory": "此目录中",
88
+ "inHomeDirectory": "主目录中",
89
+ "parentDirectory": "上级目录",
90
+ "repository": "Git 仓库",
91
+ "openDirectory": "打开 {name}",
92
+ "directoriesLoading": "正在列出目录…",
93
+ "directoryUnlisted": "{path} 处没有目录,或此账户无法读取。",
94
+ "directoriesUnsupported": "这台机器上的 pw code 版本过旧,无法列出目录。请输入路径,或在该机器上更新 pw。",
95
+ "noDirectories": "这里没有目录。",
96
+ "noDirectoryMatches": "这里没有与“{name}”匹配的目录。",
97
+ "directoriesCut": "目录太多,这里无法全部显示。请输入名称以缩小范围。",
98
+ "pathKeys": {
99
+ "move": "移动",
100
+ "use": "使用",
101
+ "open": "打开",
102
+ "cancel": "取消"
103
+ },
104
+ "browseTitle": "在 {machine} 上选择目录",
105
+ "showHidden": "显示隐藏目录",
106
+ "browseCancel": "取消",
78
107
  "composerPlaceholder": "描述任务或提出问题",
79
108
  "choosePermission": "选择代理可以执行的操作",
80
109
  "howTitle": "你打开的会话会显示在这里",
@@ -126,6 +155,7 @@ var detail = {
126
155
  "archiveWhileRunning": "请等待本轮结束后再运行 /archive。",
127
156
  "archived": "已归档“{name}”。要再次使用,请从“已归档”分组中恢复。",
128
157
  "steerUncertain": "没有收到回应,这条消息可能已送达智能体。再次发送前请先查看记录。",
158
+ "steerAlreadyRead": "智能体已读取这条消息,无法撤回。",
129
159
  "shellStopped": "钩子阻止了智能体作出回应:{reason}",
130
160
  "backgroundHint": "(按 {key} 在后台运行)",
131
161
  "backgroundTitle": "命令继续运行,智能体无需等待它即可继续工作",
@@ -158,7 +188,6 @@ var detail = {
158
188
  "waitingForUsageLimit": "正在等待用量上限重置",
159
189
  "waitingForUsageLimitUntil": "正在等待用量上限于 {time} 重置",
160
190
  "switchClaudeAccount": "切换账户",
161
- "loading": "正在加载记录…",
162
191
  "cleared": "会话已清空,正在显示新会话。",
163
192
  "dismiss": "关闭",
164
193
  "transcriptLabel": "会话记录",
@@ -187,9 +216,30 @@ var detail = {
187
216
  "goalAchieved": "✓ 目标已达成({elapsed} · {turns, plural, other {# 轮}} · {tokens} 个令牌)",
188
217
  "goalContinuing": "○ 目标尚未达成……继续中",
189
218
  "goalCheckFailed": "目标检查失败:{error}。目标仍然有效,将在下一轮结束后再次检查。",
219
+ "goalCheckin": "○ 目标进展确认:后台工作仍在运行({waited})",
190
220
  "goalUsageLimit": "已达到用量上限。将在 {time} 再次检查目标。",
191
221
  "goalActive": "目标进行中",
192
222
  "goalPaused": "目标已暂停",
223
+ "goalPanel": {
224
+ "title": "目标",
225
+ "loading": "正在读取目标…",
226
+ "none": "此会话目前没有目标。",
227
+ "active": "进行中",
228
+ "paused": "已暂停",
229
+ "checking": "检查中",
230
+ "turns": "{count, plural, other {已检查 # 轮}}",
231
+ "tokens": "{tokens} 个令牌",
232
+ "lastCheck": "上次检查",
233
+ "pausedNote": "暂停期间不会为它开始新的轮次。恢复后会立即开始一轮。",
234
+ "edit": "编辑",
235
+ "pause": "暂停",
236
+ "resume": "恢复",
237
+ "clear": "清除目标",
238
+ "conditionLabel": "目标条件",
239
+ "editHint": "进度会保留。请在条件中自行设定上限,例如“或在 20 轮后停止”。",
240
+ "cancel": "取消",
241
+ "save": "保存"
242
+ },
193
243
  "addedDirectory": "已添加的工作目录:{path}",
194
244
  "addedDirectoryAndMore": "{path} 及{count, plural, other {另外 # 个工作目录}}",
195
245
  "workingDirectory": "工作目录:{path}",
@@ -225,6 +275,11 @@ var detail = {
225
275
  "subagentMessage": "来自 {name} 的消息",
226
276
  "commandCompleted": "后台命令“{name}”已完成(退出码 0)",
227
277
  "commandFailed": "后台命令“{name}”失败,退出码 {code}",
278
+ "monitorEvent": "监视器事件:{line} · {name}",
279
+ "monitorEnded": "监视器“{name}”的流已结束",
280
+ "monitorFailed": "监视器“{name}”的脚本失败(退出码 {code})",
281
+ "monitorExpired": "监视器“{name}”在 {elapsed} 后过期,{count, plural, =0 {未送达任何事件} other {已送达 # 个事件}}",
282
+ "monitorFlooded": "监视器“{name}”因输出过多持续 {elapsed} 而停止",
228
283
  "agentEnded": "代理“{name}”{outcome, select, failed {失败} other {已完成}}",
229
284
  "agentEndedAfter": "代理“{name}”{outcome, select, failed {失败} other {已完成}} · {elapsed}",
230
285
  "expandAll": "全部展开",
@@ -283,6 +338,14 @@ var permission = {
283
338
  "plan": "在制定计划期间,工作区不会被更改。"
284
339
  }
285
340
  };
341
+ var allocation = {
342
+ "notRatedInUsd": "未以 USD 计价",
343
+ "noBudget": "未设置预算",
344
+ "noActivePeriod": "无进行中的周期",
345
+ "budgetSpent": "预算已用完",
346
+ "noAccess": "未与你共享计费权限",
347
+ "budgetExceeded": "预算已超出"
348
+ };
286
349
  var dash = {
287
350
  "needsYou": "需要你处理",
288
351
  "waitingFor": "已等待 {when}",
@@ -304,10 +367,7 @@ var claude = {
304
367
  "loadingUsage": "正在加载用量…",
305
368
  "signedOut": "未登录",
306
369
  "usageUnavailable": "用量不可用",
307
- "current": "已选择的账户",
308
370
  "loginOnHost": "如需登录,请在此主机的 pw code 中运行 /claude-code。",
309
- "fiveHour": "5 小时已使用 {percent}",
310
- "week": "本周已使用 {percent}",
311
371
  "resets": "于 {time} 重置",
312
372
  "platformModels": "平台模型",
313
373
  "shortAccount": "账户",
@@ -365,6 +425,7 @@ var terminal = {
365
425
  };
366
426
  var agents_default = {
367
427
  title,
428
+ ago,
368
429
  sidebar,
369
430
  start,
370
431
  status,
@@ -373,8 +434,9 @@ var agents_default = {
373
434
  switcher,
374
435
  effort,
375
436
  permission,
437
+ allocation,
376
438
  dash,
377
439
  claude,
378
440
  terminal
379
441
  };
380
- export { claude, dash, agents_default as default, detail, effort, machine, permission, sidebar, start, status, switcher, terminal, title };
442
+ export { ago, allocation, claude, dash, agents_default as default, detail, effort, machine, permission, sidebar, start, status, switcher, terminal, title };
package/dist/machine.d.ts CHANGED
@@ -17,6 +17,8 @@ export interface PwCodeMachine {
17
17
  storeId?: string | undefined;
18
18
  /** The daemon stores which of the reader's groups a session is in. */
19
19
  sessionGroups?: boolean | undefined;
20
+ /** The daemon lists the machine's folders, for choosing where a session starts. */
21
+ directories?: boolean | undefined;
20
22
  remoteStart?: boolean | undefined;
21
23
  }
22
24
  /** A computer's daemon connected itself; every other machine is a resource
@@ -0,0 +1,79 @@
1
+ import type { BoundSetting } from '@parallelworks/ui/ai/headless';
2
+ import type { Schemas } from './apiClient.js';
3
+ import type { PwCodeApi } from './createPwCodeApi.js';
4
+ import { type PwCodeTranslator } from './messages.js';
5
+ type PlatformModel = Pick<Schemas['ModelEntry'], 'id' | 'name' | 'provider' | 'provider_name' | 'provider_owner'>;
6
+ type ProviderIssue = Pick<Schemas['ProviderIssue'], 'provider_name' | 'provider_owner' | 'status'>;
7
+ /** The platform's models as a model picker reads them. */
8
+ export interface PwCodePlatformModelList {
9
+ models: readonly PlatformModel[];
10
+ providerIssues: readonly ProviderIssue[];
11
+ isLoading: boolean;
12
+ /** Set when the list failed to load. */
13
+ error: unknown;
14
+ /** Asks for the list again. */
15
+ refresh: () => void;
16
+ }
17
+ export interface PwCodeModelChoice {
18
+ value: string;
19
+ label: string;
20
+ disabled?: boolean;
21
+ }
22
+ export interface PwCodeModelGroup {
23
+ label: string;
24
+ description?: string | undefined;
25
+ items: PwCodeModelChoice[];
26
+ }
27
+ /** A model picker's entries: its groups, then the choice that reads the
28
+ * lists again. */
29
+ export type PwCodeModelEntry = PwCodeModelGroup | PwCodeModelChoice;
30
+ /** The issue that keeps a model's connection from serving it, if any. */
31
+ export declare function providerIssueOf<I extends ProviderIssue>(issues: readonly I[], model: Pick<PlatformModel, 'provider_name' | 'provider_owner'>): I | undefined;
32
+ type PickerWords = PwCodeTranslator<'agentTranscript'>;
33
+ /** The platform's models grouped by provider, the id's prefix. A connection
34
+ * that cannot serve its models leaves them listed, disabled, and its group
35
+ * says why; models another user shares name them. */
36
+ export declare function modelGroups(models: readonly PlatformModel[], issues: readonly ProviderIssue[], reader: string, t: PickerWords): PwCodeModelGroup[];
37
+ /** Why the platform offers no model: still loading, failed, or none. */
38
+ export declare function platformModelStatus(list: Pick<PwCodePlatformModelList, 'isLoading' | 'error'>, t: PickerWords): string;
39
+ export interface PwCodeModelPicker {
40
+ entries: PwCodeModelEntry[];
41
+ /** The chosen model's name, or what asks for one. */
42
+ label: string;
43
+ /** Called as the picker opens: the machine's Claude models are read from then on. */
44
+ opened: () => void;
45
+ /** Picks a choice from `entries`. */
46
+ pick: (value: string) => void;
47
+ /** The allocation the model bills, remembered with it as it is picked;
48
+ * null for a Claude model, which bills none. */
49
+ allocation: BoundSetting | null;
50
+ }
51
+ /** One picker for the platform's models and the machine's Claude ones. A
52
+ * model picked is remembered with the allocation it bills; the Claude
53
+ * accounts choice opens them instead, and the refresh choice reads both
54
+ * lists again. Which model and allocation stand before a pick is the host's. */
55
+ export declare function useModelPicker(api: Pick<PwCodeApi, 'useClaudeModels'>, { machine, sessionId, claudeReady, canStart, account, open, model, allocation, platform, reader, names, errorMessage, remember, onAccounts, }: {
56
+ machine: string;
57
+ sessionId?: string | undefined;
58
+ /** Claude Code is installed on the machine and its owner allows it. */
59
+ claudeReady: boolean;
60
+ /** A session can start on the machine. */
61
+ canStart: boolean;
62
+ account: string | undefined;
63
+ /** The picker is showing. */
64
+ open: boolean;
65
+ model: BoundSetting;
66
+ allocation: BoundSetting;
67
+ /** The host's list, such as its chat's, or `usePlatformDefaults`'s `list`. */
68
+ platform: PwCodePlatformModelList;
69
+ /** The reader's username, whose own shared models name no one. */
70
+ reader: string;
71
+ /** Names the session gives its models, over the lists' own. */
72
+ names?: Readonly<Record<string, string>> | undefined;
73
+ /** A failed request in the reader's language. */
74
+ errorMessage: (error: unknown) => string;
75
+ remember: (model: string, allocation: string | null | undefined) => void;
76
+ /** Opens the machine's Claude Code accounts. */
77
+ onAccounts: () => void;
78
+ }): PwCodeModelPicker;
79
+ export {};
@@ -0,0 +1,107 @@
1
+ import { usePwCodeTranslations } from "./messages.js";
2
+ import { isClaudeModel, modelLabel, useModelCatalog } from "./models.js";
3
+ // src/modelPicker.ts
4
+ /** The issue that keeps a model's connection from serving it, if any. */
5
+ function providerIssueOf(issues, model) {
6
+ if (!model.provider_name) return;
7
+ return issues.find((issue) => issue.provider_name === model.provider_name && (issue.provider_owner ?? "") === (model.provider_owner ?? ""));
8
+ }
9
+ function groupDescription(model, issue, reader, t) {
10
+ const owner = model.provider_owner;
11
+ return [owner && owner !== "org" && owner !== reader ? t("modelPicker.sharedBy", { owner }) : "", issue ? issue.status === "unauthorized" ? t("providerIssue.keyRejected") : t("providerIssue.unreachable") : ""].filter(Boolean).join(" · ") || void 0;
12
+ }
13
+ /** The platform's models grouped by provider, the id's prefix. A connection
14
+ * that cannot serve its models leaves them listed, disabled, and its group
15
+ * says why; models another user shares name them. */
16
+ function modelGroups(models, issues, reader, t) {
17
+ const groups = /* @__PURE__ */ new Map();
18
+ for (const model of models) {
19
+ const key = model.id.split("/")[0] ?? model.provider ?? "";
20
+ const issue = providerIssueOf(issues, model);
21
+ let group = groups.get(key);
22
+ if (!group) {
23
+ group = {
24
+ label: model.provider || key,
25
+ description: groupDescription(model, issue, reader, t),
26
+ items: []
27
+ };
28
+ groups.set(key, group);
29
+ }
30
+ group.items = [...group.items, {
31
+ value: model.id,
32
+ label: modelLabel(model.id, model.name),
33
+ disabled: !!issue
34
+ }];
35
+ }
36
+ return [...groups.values()];
37
+ }
38
+ /** Why the platform offers no model: still loading, failed, or none. */
39
+ function platformModelStatus(list, t) {
40
+ if (list.error) return t("modelPicker.failed");
41
+ return list.isLoading ? t("modelPicker.loading") : t("modelPicker.none");
42
+ }
43
+ var ACCOUNTS_CHOICE = "claude-code-accounts";
44
+ var REFRESH_CHOICE = "refresh";
45
+ /** One picker for the platform's models and the machine's Claude ones. A
46
+ * model picked is remembered with the allocation it bills; the Claude
47
+ * accounts choice opens them instead, and the refresh choice reads both
48
+ * lists again. Which model and allocation stand before a pick is the host's. */
49
+ function useModelPicker(api, { machine, sessionId, claudeReady, canStart, account, open, model, allocation, platform, reader, names, errorMessage, remember, onAccounts }) {
50
+ const t = usePwCodeTranslations("agents");
51
+ const words = usePwCodeTranslations("agentTranscript");
52
+ const catalog = useModelCatalog(api, {
53
+ machine,
54
+ sessionId,
55
+ claudeReady,
56
+ canStart,
57
+ model: model.value,
58
+ account,
59
+ open
60
+ });
61
+ const groups = modelGroups(platform.models, platform.providerIssues, reader, words);
62
+ if (platform.models.length === 0) groups.push({
63
+ label: t("claude.platformModels"),
64
+ description: platformModelStatus(platform, words),
65
+ items: []
66
+ });
67
+ const claudeModels = catalog.models;
68
+ if (claudeReady) groups.push({
69
+ label: t("claude.models"),
70
+ description: catalog.error ? errorMessage(catalog.error) : catalog.isLoading ? t("claude.loadingModels") : void 0,
71
+ items: [...claudeModels.map((entry) => ({
72
+ value: entry.id,
73
+ label: modelLabel(entry.id, entry.name)
74
+ })), {
75
+ value: ACCOUNTS_CHOICE,
76
+ label: t("claude.accounts")
77
+ }]
78
+ });
79
+ const id = model.value ?? "";
80
+ const listed = platform.models.find((m) => m.id === model.value) ?? claudeModels.find((m) => m.id === model.value);
81
+ return {
82
+ entries: [...groups, {
83
+ value: REFRESH_CHOICE,
84
+ label: t("claude.refreshModels")
85
+ }],
86
+ label: modelLabel(id, names?.[id] ?? listed?.name) || words("modelPicker.select"),
87
+ opened: catalog.request,
88
+ pick: (value) => {
89
+ if (value === ACCOUNTS_CHOICE) onAccounts();
90
+ else if (value === REFRESH_CHOICE) {
91
+ catalog.refresh();
92
+ platform.refresh();
93
+ } else if (value) {
94
+ remember(value, allocation.value);
95
+ model.onChange(value);
96
+ }
97
+ },
98
+ allocation: isClaudeModel(model.value) ? null : {
99
+ ...allocation,
100
+ onChange: (next) => {
101
+ if (model.value) remember(model.value, next);
102
+ allocation.onChange(next);
103
+ }
104
+ }
105
+ };
106
+ }
107
+ export { modelGroups, platformModelStatus, providerIssueOf, useModelPicker };
package/dist/notices.js CHANGED
@@ -1,8 +1,9 @@
1
+ import { goalElapsed } from "./goal.js";
1
2
  import { usePwCodeTranslations } from "./messages.js";
2
3
  import { useCallback, useMemo } from "react";
3
- import { DateTime } from "luxon";
4
4
  import { sanitizeLabel } from "@parallelworks/ui/ai/headless";
5
5
  import { useFormatter, useLocale } from "use-intl";
6
+ import { DateTime } from "luxon";
6
7
  import { formatDuration } from "@parallelworks/ui/headless";
7
8
  // src/notices.ts
8
9
  /** When a usage limit resets, as a session's notices name it. */
@@ -22,13 +23,14 @@ function useGoalNotice() {
22
23
  if (p.resumeAt) return t("detail.goalUsageLimit", { time: resumeTime(p.resumeAt) });
23
24
  if (p.err) return t("detail.goalCheckFailed", { error: p.err });
24
25
  if (p.outcome === "achieved") return t("detail.goalAchieved", {
25
- elapsed: formatDuration(Math.floor((p.elapsedMs ?? 0) / 1e3) * 1e3, locale),
26
+ elapsed: goalElapsed(p.elapsedMs ?? 0, "panel", locale),
26
27
  turns: p.turns ?? 0,
27
28
  tokens: format.number(p.tokens ?? 0, {
28
29
  notation: "compact",
29
30
  maximumFractionDigits: 1
30
31
  })
31
32
  });
33
+ if (p.waitedMs) return t("detail.goalCheckin", { waited: formatDuration(Math.floor(p.waitedMs / 6e4) * 6e4, locale) });
32
34
  return t("detail.goalContinuing");
33
35
  }, [
34
36
  t,
@@ -61,6 +63,48 @@ function turnDuration(t, ms) {
61
63
  minutes: Math.floor(total / 60) % 60
62
64
  });
63
65
  }
66
+ /** A monitor's line: the first line an event's script printed, or how the monitor ended. */
67
+ function monitorLine(t, n, name) {
68
+ const elapsed = turnDuration(t, n.elapsedMs ?? 0);
69
+ switch (n.ended) {
70
+ case "exited": return n.exitCode ? t("detail.monitorFailed", {
71
+ name,
72
+ code: n.exitCode
73
+ }) : t("detail.monitorEnded", { name });
74
+ case "expired": return t("detail.monitorExpired", {
75
+ name,
76
+ elapsed,
77
+ count: n.events ?? 0
78
+ });
79
+ case "flooded": return t("detail.monitorFlooded", {
80
+ name,
81
+ elapsed
82
+ });
83
+ default: return t("detail.monitorEvent", {
84
+ name,
85
+ line: n.preview
86
+ });
87
+ }
88
+ }
89
+ /** The line a background agent's report, a command's end or a monitor's notice enters the conversation with. */
90
+ function deliveryLine(t, n) {
91
+ const name = sanitizeLabel(n.description) || n.id;
92
+ if (n.monitor) return monitorLine(t, n, name);
93
+ if (n.interim) return t("detail.subagentMessage", { name });
94
+ if (n.shell) return n.exitCode ? t("detail.commandFailed", {
95
+ name,
96
+ code: n.exitCode
97
+ }) : t("detail.commandCompleted", { name });
98
+ const outcome = n.failed ? "failed" : "finished";
99
+ return n.elapsedMs ? t("detail.agentEndedAfter", {
100
+ name,
101
+ outcome,
102
+ elapsed: turnDuration(t, n.elapsedMs)
103
+ }) : t("detail.agentEnded", {
104
+ name,
105
+ outcome
106
+ });
107
+ }
64
108
  /** The session's own lines: what a goal step opens to, how a turn ended,
65
109
  * which plan a /plan showed, and how a background task reported back. */
66
110
  function useTranscriptWords() {
@@ -92,23 +136,7 @@ function useTranscriptWords() {
92
136
  });
93
137
  },
94
138
  planAnswer: (path, opened) => opened ? t("detail.planOpened", { path }) : path,
95
- deliveryLine: (n) => {
96
- const name = sanitizeLabel(n.description) || n.id;
97
- if (n.interim) return t("detail.subagentMessage", { name });
98
- if (n.shell) return n.exitCode ? t("detail.commandFailed", {
99
- name,
100
- code: n.exitCode
101
- }) : t("detail.commandCompleted", { name });
102
- const outcome = n.failed ? "failed" : "finished";
103
- return n.elapsedMs ? t("detail.agentEndedAfter", {
104
- name,
105
- outcome,
106
- elapsed: turnDuration(t, n.elapsedMs)
107
- }) : t("detail.agentEnded", {
108
- name,
109
- outcome
110
- });
111
- },
139
+ deliveryLine: (n) => deliveryLine(t, n),
112
140
  allowDirectory: ({ path, subtree }) => subtree ? tTranscript("transcript.allowDirectoryTree", { path }) : tTranscript("transcript.allowDirectoryOnly", { path }),
113
141
  mainConversation: t("switcher.main")
114
142
  }), [
@@ -0,0 +1,22 @@
1
+ import type { PwCodePlatformModels } from './accountApi.js';
2
+ import type { Schemas } from './apiClient.js';
3
+ import type { PwCodeApi } from './createPwCodeApi.js';
4
+ /** The platform model and allocation the AI chat selects, for a host with no
5
+ * chat to take them from. They fit `useStartModel`'s `platform`, and the
6
+ * allocation `useSessionSettings`'s `nativeAllocation`. */
7
+ export interface PwCodePlatformDefaults {
8
+ /** The platform's models, as `useModelPicker`'s `platform` takes them. */
9
+ list: PwCodePlatformModels;
10
+ /** The models once they load; undefined while they load or when they failed to. */
11
+ models: Schemas['ModelEntry'][] | undefined;
12
+ /** The chat model last chosen while the list still offers it, else the
13
+ * first whose provider has no issue, else the first; null until the list loads. */
14
+ model: string | null;
15
+ /** The allocation `model` bills: the first it can charge, once the
16
+ * allocations load; none for a model that bills none. */
17
+ allocation: string | null;
18
+ }
19
+ export declare function usePlatformDefaults(api: Pick<PwCodeApi, 'usePlatformModels' | 'useAllocations'>, { stored, }: {
20
+ /** The chat model last chosen, saved under `chatModelPreference`. */
21
+ stored: string | null | undefined;
22
+ }): PwCodePlatformDefaults;
@@ -0,0 +1,30 @@
1
+ import { aiAllocations, allocationProblem, billsAllocation } from "./allocations.js";
2
+ import { useMemo } from "react";
3
+ import { defaultAllocation, defaultModel } from "@parallelworks/ui/ai/headless";
4
+ // src/platformDefaults.ts
5
+ function usePlatformDefaults(api, { stored }) {
6
+ const list = api.usePlatformModels();
7
+ const model = defaultModel({
8
+ models: list.models,
9
+ providerIssues: list.providerIssues,
10
+ current: null,
11
+ stored: stored ?? null
12
+ });
13
+ const { data } = api.useAllocations(billsAllocation(model));
14
+ const allocations = useMemo(() => data ? aiAllocations(data).map((a) => ({
15
+ name: a.name,
16
+ total: a.total,
17
+ disabled: allocationProblem(a, false) !== null
18
+ })) : void 0, [data]);
19
+ return {
20
+ list,
21
+ models: list.loaded && !list.error ? list.models : void 0,
22
+ model,
23
+ allocation: defaultAllocation({
24
+ model,
25
+ allocations,
26
+ current: null
27
+ })
28
+ };
29
+ }
30
+ export { usePlatformDefaults };