@swirls/shuttle 0.0.0-stage → 0.1.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 (298) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +190 -0
  3. package/NOTICE +5 -0
  4. package/README.md +42 -2
  5. package/dist/api/auth.d.ts +18 -0
  6. package/dist/api/auth.js +15 -0
  7. package/dist/api/common.d.ts +8 -0
  8. package/dist/api/common.js +4 -0
  9. package/dist/api/connections.d.ts +292 -0
  10. package/dist/api/connections.js +114 -0
  11. package/dist/api/github.d.ts +20 -0
  12. package/dist/api/github.js +13 -0
  13. package/dist/api/harness.d.ts +97 -0
  14. package/dist/api/harness.js +47 -0
  15. package/dist/api/index.d.ts +2059 -0
  16. package/dist/api/index.js +37 -0
  17. package/dist/api/runners.d.ts +93 -0
  18. package/dist/api/runners.js +45 -0
  19. package/dist/api/sandbox.d.ts +550 -0
  20. package/dist/api/sandbox.js +210 -0
  21. package/dist/api/sessions.d.ts +318 -0
  22. package/dist/api/sessions.js +154 -0
  23. package/dist/api/tenant.d.ts +54 -0
  24. package/dist/api/tenant.js +19 -0
  25. package/dist/api/timings.d.ts +36 -0
  26. package/dist/api/timings.js +48 -0
  27. package/dist/api/workspace.d.ts +738 -0
  28. package/dist/api/workspace.js +246 -0
  29. package/dist/core/pulls.d.ts +1001 -0
  30. package/dist/core/pulls.js +170 -0
  31. package/dist/core/workspace.d.ts +985 -0
  32. package/dist/core/workspace.js +174 -0
  33. package/dist/react/components/command-palette.d.ts +22 -0
  34. package/dist/react/components/command-palette.js +66 -0
  35. package/dist/react/components/follow-list.d.ts +20 -0
  36. package/dist/react/components/follow-list.js +98 -0
  37. package/dist/react/components/json-tree.d.ts +11 -0
  38. package/dist/react/components/json-tree.js +120 -0
  39. package/dist/react/components/markdown.d.ts +5 -0
  40. package/dist/react/components/markdown.js +29 -0
  41. package/dist/react/components/shuttle-mark.d.ts +7 -0
  42. package/dist/react/components/shuttle-mark.js +9 -0
  43. package/dist/react/components/status-dot.d.ts +9 -0
  44. package/dist/react/components/status-dot.js +27 -0
  45. package/dist/react/components/status.d.ts +6 -0
  46. package/dist/react/components/status.js +66 -0
  47. package/dist/react/components/ui/badge.d.ts +7 -0
  48. package/dist/react/components/ui/badge.js +19 -0
  49. package/dist/react/components/ui/button.d.ts +10 -0
  50. package/dist/react/components/ui/button.js +40 -0
  51. package/dist/react/components/ui/dialog.d.ts +19 -0
  52. package/dist/react/components/ui/dialog.js +34 -0
  53. package/dist/react/components/ui/dropdown-menu.d.ts +14 -0
  54. package/dist/react/components/ui/dropdown-menu.js +33 -0
  55. package/dist/react/components/ui/input.d.ts +3 -0
  56. package/dist/react/components/ui/input.js +6 -0
  57. package/dist/react/components/ui/panel.d.ts +18 -0
  58. package/dist/react/components/ui/panel.js +22 -0
  59. package/dist/react/components/ui/popover.d.ts +7 -0
  60. package/dist/react/components/ui/popover.js +16 -0
  61. package/dist/react/components/ui/resizable.d.ts +7 -0
  62. package/dist/react/components/ui/resizable.js +14 -0
  63. package/dist/react/components/ui/scroll-area.d.ts +14 -0
  64. package/dist/react/components/ui/scroll-area.js +12 -0
  65. package/dist/react/components/ui/select.d.ts +10 -0
  66. package/dist/react/components/ui/select.js +20 -0
  67. package/dist/react/components/ui/sheet.d.ts +8 -0
  68. package/dist/react/components/ui/sheet.js +20 -0
  69. package/dist/react/components/ui/tabs.d.ts +7 -0
  70. package/dist/react/components/ui/tabs.js +16 -0
  71. package/dist/react/components/ui/textarea.d.ts +3 -0
  72. package/dist/react/components/ui/textarea.js +6 -0
  73. package/dist/react/components/ui/tooltip.d.ts +8 -0
  74. package/dist/react/components/ui/tooltip.js +17 -0
  75. package/dist/react/features/artifacts/artifact-links.d.ts +9 -0
  76. package/dist/react/features/artifacts/artifact-links.js +38 -0
  77. package/dist/react/features/artifacts/artifact-pane.d.ts +19 -0
  78. package/dist/react/features/artifacts/artifact-pane.js +64 -0
  79. package/dist/react/features/artifacts/artifact-types.d.ts +59 -0
  80. package/dist/react/features/artifacts/artifact-types.js +69 -0
  81. package/dist/react/features/artifacts/browser-viewer.d.ts +5 -0
  82. package/dist/react/features/artifacts/browser-viewer.js +60 -0
  83. package/dist/react/features/artifacts/diff-style.d.ts +10 -0
  84. package/dist/react/features/artifacts/diff-style.js +21 -0
  85. package/dist/react/features/artifacts/file-pane.d.ts +13 -0
  86. package/dist/react/features/artifacts/file-pane.js +305 -0
  87. package/dist/react/features/artifacts/file-quick-open.d.ts +15 -0
  88. package/dist/react/features/artifacts/file-quick-open.js +74 -0
  89. package/dist/react/features/artifacts/file-search.d.ts +12 -0
  90. package/dist/react/features/artifacts/file-search.js +90 -0
  91. package/dist/react/features/artifacts/media-viewer.d.ts +8 -0
  92. package/dist/react/features/artifacts/media-viewer.js +41 -0
  93. package/dist/react/features/artifacts/review-diff.d.ts +19 -0
  94. package/dist/react/features/artifacts/review-diff.js +59 -0
  95. package/dist/react/features/artifacts/review-viewer.d.ts +4 -0
  96. package/dist/react/features/artifacts/review-viewer.js +337 -0
  97. package/dist/react/features/artifacts/sandbox.d.ts +43 -0
  98. package/dist/react/features/artifacts/sandbox.js +109 -0
  99. package/dist/react/features/artifacts/tab-strip.d.ts +11 -0
  100. package/dist/react/features/artifacts/tab-strip.js +55 -0
  101. package/dist/react/features/artifacts/terminal-theme.d.ts +34 -0
  102. package/dist/react/features/artifacts/terminal-theme.js +62 -0
  103. package/dist/react/features/artifacts/terminal-viewer.d.ts +5 -0
  104. package/dist/react/features/artifacts/terminal-viewer.js +209 -0
  105. package/dist/react/features/artifacts/unified-diff.d.ts +16 -0
  106. package/dist/react/features/artifacts/unified-diff.js +55 -0
  107. package/dist/react/features/artifacts/workspace-viewer.d.ts +16 -0
  108. package/dist/react/features/artifacts/workspace-viewer.js +275 -0
  109. package/dist/react/features/connections/agent-sign-in.d.ts +71 -0
  110. package/dist/react/features/connections/agent-sign-in.js +251 -0
  111. package/dist/react/features/connections/connections-panel.d.ts +8 -0
  112. package/dist/react/features/connections/connections-panel.js +42 -0
  113. package/dist/react/features/connections/login.d.ts +24 -0
  114. package/dist/react/features/connections/login.js +35 -0
  115. package/dist/react/features/connections/places.d.ts +20 -0
  116. package/dist/react/features/connections/places.js +27 -0
  117. package/dist/react/features/connections/queries.d.ts +28 -0
  118. package/dist/react/features/connections/queries.js +8 -0
  119. package/dist/react/features/events/event-cache.d.ts +4 -0
  120. package/dist/react/features/events/event-cache.js +29 -0
  121. package/dist/react/features/events/event-catalog.d.ts +17 -0
  122. package/dist/react/features/events/event-catalog.js +261 -0
  123. package/dist/react/features/events/event-inspector.d.ts +7 -0
  124. package/dist/react/features/events/event-inspector.js +29 -0
  125. package/dist/react/features/events/event-row.d.ts +21 -0
  126. package/dist/react/features/events/event-row.js +34 -0
  127. package/dist/react/features/events/event-stream.d.ts +18 -0
  128. package/dist/react/features/events/event-stream.js +58 -0
  129. package/dist/react/features/events/global-events.d.ts +122 -0
  130. package/dist/react/features/events/global-events.js +329 -0
  131. package/dist/react/features/events/shuttle-events.d.ts +7 -0
  132. package/dist/react/features/events/shuttle-events.js +1 -0
  133. package/dist/react/features/playbook/playbook-page.d.ts +2 -0
  134. package/dist/react/features/playbook/playbook-page.js +36 -0
  135. package/dist/react/features/playbook/playbook-query.d.ts +111 -0
  136. package/dist/react/features/playbook/playbook-query.js +17 -0
  137. package/dist/react/features/pulls/linked-session.d.ts +12 -0
  138. package/dist/react/features/pulls/linked-session.js +22 -0
  139. package/dist/react/features/pulls/pull-detail-sheet.d.ts +10 -0
  140. package/dist/react/features/pulls/pull-detail-sheet.js +41 -0
  141. package/dist/react/features/pulls/pull-fixtures.d.ts +8 -0
  142. package/dist/react/features/pulls/pull-fixtures.js +258 -0
  143. package/dist/react/features/pulls/pull-glyphs.d.ts +24 -0
  144. package/dist/react/features/pulls/pull-glyphs.js +89 -0
  145. package/dist/react/features/pulls/pull-inbox-list.d.ts +13 -0
  146. package/dist/react/features/pulls/pull-inbox-list.js +230 -0
  147. package/dist/react/features/pulls/pull-inbox-pref.d.ts +2 -0
  148. package/dist/react/features/pulls/pull-inbox-pref.js +19 -0
  149. package/dist/react/features/pulls/pull-inbox.d.ts +30 -0
  150. package/dist/react/features/pulls/pull-inbox.js +110 -0
  151. package/dist/react/features/pulls/pull-threads.d.ts +39 -0
  152. package/dist/react/features/pulls/pull-threads.js +145 -0
  153. package/dist/react/features/pulls/pulls.d.ts +120 -0
  154. package/dist/react/features/pulls/pulls.js +414 -0
  155. package/dist/react/features/pulls/session-pull-groups.d.ts +14 -0
  156. package/dist/react/features/pulls/session-pull-groups.js +29 -0
  157. package/dist/react/features/pulls/stack-ladder.d.ts +9 -0
  158. package/dist/react/features/pulls/stack-ladder.js +32 -0
  159. package/dist/react/features/sessions/agent-tree.d.ts +16 -0
  160. package/dist/react/features/sessions/agent-tree.js +100 -0
  161. package/dist/react/features/sessions/agents.d.ts +34 -0
  162. package/dist/react/features/sessions/agents.js +146 -0
  163. package/dist/react/features/sessions/attention.d.ts +32 -0
  164. package/dist/react/features/sessions/attention.js +42 -0
  165. package/dist/react/features/sessions/composer-attachments.d.ts +33 -0
  166. package/dist/react/features/sessions/composer-attachments.js +126 -0
  167. package/dist/react/features/sessions/composer.d.ts +15 -0
  168. package/dist/react/features/sessions/composer.js +327 -0
  169. package/dist/react/features/sessions/context-usage-meter.d.ts +5 -0
  170. package/dist/react/features/sessions/context-usage-meter.js +122 -0
  171. package/dist/react/features/sessions/context-usage.d.ts +54 -0
  172. package/dist/react/features/sessions/context-usage.js +206 -0
  173. package/dist/react/features/sessions/conversation.d.ts +21 -0
  174. package/dist/react/features/sessions/conversation.js +549 -0
  175. package/dist/react/features/sessions/harness-switcher.d.ts +26 -0
  176. package/dist/react/features/sessions/harness-switcher.js +118 -0
  177. package/dist/react/features/sessions/intake-heuristic.d.ts +5 -0
  178. package/dist/react/features/sessions/intake-heuristic.js +28 -0
  179. package/dist/react/features/sessions/interjection-routes.d.ts +13 -0
  180. package/dist/react/features/sessions/interjection-routes.js +72 -0
  181. package/dist/react/features/sessions/llm-models.d.ts +128 -0
  182. package/dist/react/features/sessions/llm-models.js +174 -0
  183. package/dist/react/features/sessions/media-strip.d.ts +25 -0
  184. package/dist/react/features/sessions/media-strip.js +56 -0
  185. package/dist/react/features/sessions/media.d.ts +43 -0
  186. package/dist/react/features/sessions/media.js +115 -0
  187. package/dist/react/features/sessions/model-search.d.ts +6 -0
  188. package/dist/react/features/sessions/model-search.js +16 -0
  189. package/dist/react/features/sessions/model-switcher.d.ts +16 -0
  190. package/dist/react/features/sessions/model-switcher.js +262 -0
  191. package/dist/react/features/sessions/open-pull-request.d.ts +20 -0
  192. package/dist/react/features/sessions/open-pull-request.js +92 -0
  193. package/dist/react/features/sessions/pull-publish-card.d.ts +14 -0
  194. package/dist/react/features/sessions/pull-publish-card.js +88 -0
  195. package/dist/react/features/sessions/recent-sessions.d.ts +11 -0
  196. package/dist/react/features/sessions/recent-sessions.js +29 -0
  197. package/dist/react/features/sessions/seen-sessions.d.ts +16 -0
  198. package/dist/react/features/sessions/seen-sessions.js +108 -0
  199. package/dist/react/features/sessions/session-activity.d.ts +95 -0
  200. package/dist/react/features/sessions/session-activity.js +785 -0
  201. package/dist/react/features/sessions/session-context.d.ts +8 -0
  202. package/dist/react/features/sessions/session-context.js +98 -0
  203. package/dist/react/features/sessions/session-feed.d.ts +243 -0
  204. package/dist/react/features/sessions/session-feed.js +883 -0
  205. package/dist/react/features/sessions/session-header.d.ts +24 -0
  206. package/dist/react/features/sessions/session-header.js +97 -0
  207. package/dist/react/features/sessions/session-layout.d.ts +7 -0
  208. package/dist/react/features/sessions/session-layout.js +87 -0
  209. package/dist/react/features/sessions/session-panes.d.ts +49 -0
  210. package/dist/react/features/sessions/session-panes.js +142 -0
  211. package/dist/react/features/sessions/session-parts.d.ts +35 -0
  212. package/dist/react/features/sessions/session-parts.js +74 -0
  213. package/dist/react/features/sessions/session-place.d.ts +9 -0
  214. package/dist/react/features/sessions/session-place.js +109 -0
  215. package/dist/react/features/sessions/session-pr-pills.d.ts +7 -0
  216. package/dist/react/features/sessions/session-pr-pills.js +28 -0
  217. package/dist/react/features/sessions/session-queries.d.ts +172 -0
  218. package/dist/react/features/sessions/session-queries.js +90 -0
  219. package/dist/react/features/sessions/session-repos.d.ts +8 -0
  220. package/dist/react/features/sessions/session-repos.js +15 -0
  221. package/dist/react/features/sessions/session-share.d.ts +8 -0
  222. package/dist/react/features/sessions/session-share.js +112 -0
  223. package/dist/react/features/sessions/session-tabs.d.ts +38 -0
  224. package/dist/react/features/sessions/session-tabs.js +191 -0
  225. package/dist/react/features/sessions/session.d.ts +103 -0
  226. package/dist/react/features/sessions/session.js +216 -0
  227. package/dist/react/features/sessions/signals.d.ts +13 -0
  228. package/dist/react/features/sessions/signals.js +34 -0
  229. package/dist/react/features/sessions/tab-set.d.ts +20 -0
  230. package/dist/react/features/sessions/tab-set.js +58 -0
  231. package/dist/react/features/sessions/team.d.ts +16 -0
  232. package/dist/react/features/sessions/team.js +35 -0
  233. package/dist/react/features/sessions/timeline.d.ts +53 -0
  234. package/dist/react/features/sessions/timeline.js +153 -0
  235. package/dist/react/features/sessions/use-session-tabs.d.ts +18 -0
  236. package/dist/react/features/sessions/use-session-tabs.js +119 -0
  237. package/dist/react/features/sessions/vendor-models.d.ts +23 -0
  238. package/dist/react/features/sessions/vendor-models.js +61 -0
  239. package/dist/react/features/workspace/activity-dot.d.ts +15 -0
  240. package/dist/react/features/workspace/activity-dot.js +36 -0
  241. package/dist/react/features/workspace/app-sidebar.d.ts +16 -0
  242. package/dist/react/features/workspace/app-sidebar.js +227 -0
  243. package/dist/react/features/workspace/fixture-toggle.d.ts +2 -0
  244. package/dist/react/features/workspace/fixture-toggle.js +72 -0
  245. package/dist/react/features/workspace/folder-group.d.ts +18 -0
  246. package/dist/react/features/workspace/folder-group.js +83 -0
  247. package/dist/react/features/workspace/inline-name-input.d.ts +10 -0
  248. package/dist/react/features/workspace/inline-name-input.js +33 -0
  249. package/dist/react/features/workspace/link-repo-dialog.d.ts +9 -0
  250. package/dist/react/features/workspace/link-repo-dialog.js +76 -0
  251. package/dist/react/features/workspace/repo-chip.d.ts +13 -0
  252. package/dist/react/features/workspace/repo-chip.js +15 -0
  253. package/dist/react/features/workspace/session-row.d.ts +20 -0
  254. package/dist/react/features/workspace/session-row.js +23 -0
  255. package/dist/react/features/workspace/use-debounced.d.ts +2 -0
  256. package/dist/react/features/workspace/use-debounced.js +10 -0
  257. package/dist/react/features/workspace/workspace-context.d.ts +45 -0
  258. package/dist/react/features/workspace/workspace-context.js +245 -0
  259. package/dist/react/features/workspace/workspace-fixtures.d.ts +16 -0
  260. package/dist/react/features/workspace/workspace-fixtures.js +175 -0
  261. package/dist/react/features/workspace/workspace-tree.d.ts +30 -0
  262. package/dist/react/features/workspace/workspace-tree.js +69 -0
  263. package/dist/react/features/workspace/workspace.d.ts +107 -0
  264. package/dist/react/features/workspace/workspace.js +458 -0
  265. package/dist/react/index.d.ts +33 -0
  266. package/dist/react/index.js +35 -0
  267. package/dist/react/lib/cn.d.ts +6 -0
  268. package/dist/react/lib/cn.js +20 -0
  269. package/dist/react/lib/initials.d.ts +6 -0
  270. package/dist/react/lib/initials.js +32 -0
  271. package/dist/react/lib/json.d.ts +33 -0
  272. package/dist/react/lib/json.js +101 -0
  273. package/dist/react/lib/time.d.ts +8 -0
  274. package/dist/react/lib/time.js +57 -0
  275. package/dist/react/lib/use-media-query.d.ts +1 -0
  276. package/dist/react/lib/use-media-query.js +9 -0
  277. package/dist/react/lib/use-now.d.ts +2 -0
  278. package/dist/react/lib/use-now.js +10 -0
  279. package/dist/react/lib/use-width-bucket.d.ts +6 -0
  280. package/dist/react/lib/use-width-bucket.js +28 -0
  281. package/dist/react/parts/index.d.ts +43 -0
  282. package/dist/react/parts/index.js +43 -0
  283. package/dist/react/shuttle/device.d.ts +42 -0
  284. package/dist/react/shuttle/device.js +10 -0
  285. package/dist/react/shuttle/host.d.ts +1126 -0
  286. package/dist/react/shuttle/host.js +93 -0
  287. package/dist/react/shuttle/identity.d.ts +31 -0
  288. package/dist/react/shuttle/identity.js +20 -0
  289. package/dist/react/shuttle/index.d.ts +14 -0
  290. package/dist/react/shuttle/index.js +13 -0
  291. package/dist/react/shuttle/provider.d.ts +41 -0
  292. package/dist/react/shuttle/provider.js +59 -0
  293. package/dist/react/shuttle/router.d.ts +43 -0
  294. package/dist/react/shuttle/router.js +1 -0
  295. package/dist/react/theme.css +456 -0
  296. package/dist/react/ui.d.ts +19 -0
  297. package/dist/react/ui.js +19 -0
  298. package/package.json +100 -4
@@ -0,0 +1,43 @@
1
+ import type { JsonValue } from '@swirls/looms/core';
2
+ import { type ShuttleHost } from '../../shuttle/index.js';
3
+ /** A file in a session's media: one a person attached, or one an agent shared. */
4
+ export interface MediaAsset {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ readonly mediaType: string;
8
+ readonly size: number;
9
+ }
10
+ export type MediaKind = 'image' | 'video' | 'audio' | 'pdf' | 'file';
11
+ /** One entry in a session's media, with where it came from. */
12
+ export interface SessionMedia {
13
+ readonly asset: MediaAsset;
14
+ readonly source: 'upload' | 'agent';
15
+ readonly seq: number;
16
+ readonly ts: number;
17
+ /** The agent that shared it. */
18
+ readonly threadId?: string;
19
+ /** The person who attached it. */
20
+ readonly authorName?: string;
21
+ }
22
+ /** Largest file that can be attached, and most files on one message. The Worker enforces both. */
23
+ export declare const MAX_ATTACHMENT_BYTES: number;
24
+ export declare const MAX_ATTACHMENTS = 10;
25
+ export declare function mediaKind(mediaType: string): MediaKind;
26
+ export declare function mediaUrl(host: ShuttleHost, runId: string, assetId: string, download?: boolean): string;
27
+ export declare function formatBytes(size: number): string;
28
+ /** A media asset read from event JSON, or `undefined` when the value is not one. */
29
+ export declare function mediaAssetOf(value: JsonValue | undefined): MediaAsset | undefined;
30
+ export declare function mediaAssetsOf(value: JsonValue | undefined): MediaAsset[];
31
+ /**
32
+ * The file a `share_file` call shared. A worker's result is an object; a vendor agent's arrives
33
+ * as JSON text.
34
+ */
35
+ export declare function sharedAssetOf(result: JsonValue | undefined): MediaAsset | undefined;
36
+ /**
37
+ * Uploads one file to a session and reports progress from 0 to 1. Aborting `signal` cancels it.
38
+ * The file's bytes are the request body, so a large file is never held in memory twice.
39
+ */
40
+ export declare function uploadAsset(host: ShuttleHost, runId: string, file: File, options?: {
41
+ onProgress?: (fraction: number) => void;
42
+ signal?: AbortSignal;
43
+ }): Promise<MediaAsset>;
@@ -0,0 +1,115 @@
1
+ import { z } from 'zod';
2
+ import { jsonFields, jsonNumber, jsonText } from '../../lib/json.js';
3
+ import {} from '../../shuttle/index.js';
4
+ /** Largest file that can be attached, and most files on one message. The Worker enforces both. */
5
+ export const MAX_ATTACHMENT_BYTES = 50 * 1024 * 1024;
6
+ export const MAX_ATTACHMENTS = 10;
7
+ export function mediaKind(mediaType) {
8
+ const [top] = mediaType.split('/');
9
+ if (top === 'image' || top === 'video' || top === 'audio') {
10
+ return top;
11
+ }
12
+ return mediaType === 'application/pdf' ? 'pdf' : 'file';
13
+ }
14
+ export function mediaUrl(host, runId, assetId, download = false) {
15
+ const url = host.url(`/sessions/${encodeURIComponent(runId)}/assets/${encodeURIComponent(assetId)}`);
16
+ return download ? `${url}?download` : url;
17
+ }
18
+ export function formatBytes(size) {
19
+ if (size < 1024) {
20
+ return `${size} B`;
21
+ }
22
+ if (size < 1024 * 1024) {
23
+ return `${Math.round(size / 1024)} KB`;
24
+ }
25
+ return `${(size / (1024 * 1024)).toFixed(1)} MB`;
26
+ }
27
+ /** A media asset read from event JSON, or `undefined` when the value is not one. */
28
+ export function mediaAssetOf(value) {
29
+ const fields = jsonFields(value);
30
+ const id = jsonText(fields.id);
31
+ const mediaType = jsonText(fields.mediaType);
32
+ if (!id || !mediaType) {
33
+ return undefined;
34
+ }
35
+ return {
36
+ id,
37
+ name: jsonText(fields.name) ?? id,
38
+ mediaType,
39
+ size: jsonNumber(fields.size) ?? 0,
40
+ };
41
+ }
42
+ export function mediaAssetsOf(value) {
43
+ return Array.isArray(value)
44
+ ? value.flatMap((item) => {
45
+ const asset = mediaAssetOf(item);
46
+ return asset ? [asset] : [];
47
+ })
48
+ : [];
49
+ }
50
+ /**
51
+ * The file a `share_file` call shared. A worker's result is an object; a vendor agent's arrives
52
+ * as JSON text.
53
+ */
54
+ export function sharedAssetOf(result) {
55
+ let parsed = result;
56
+ if (typeof result === 'string') {
57
+ try {
58
+ parsed = JSON.parse(result);
59
+ }
60
+ catch {
61
+ return undefined;
62
+ }
63
+ }
64
+ const fields = jsonFields(parsed);
65
+ return fields.ok === true ? mediaAssetOf(fields.asset) : undefined;
66
+ }
67
+ /** What the Worker answers an upload with: the stored file, or why it was refused. */
68
+ const UploadAnswer = z.object({
69
+ asset: z
70
+ .object({
71
+ id: z.string().min(1),
72
+ name: z.string().optional(),
73
+ mediaType: z.string().min(1),
74
+ size: z.number().optional(),
75
+ })
76
+ .optional(),
77
+ error: z.string().optional(),
78
+ });
79
+ /**
80
+ * Uploads one file to a session and reports progress from 0 to 1. Aborting `signal` cancels it.
81
+ * The file's bytes are the request body, so a large file is never held in memory twice.
82
+ */
83
+ export function uploadAsset(host, runId, file, options = {}) {
84
+ return new Promise((resolve, reject) => {
85
+ const request = new XMLHttpRequest();
86
+ request.open('POST', host.url(`/sessions/${encodeURIComponent(runId)}/assets?name=${encodeURIComponent(file.name)}`));
87
+ request.setRequestHeader('content-type', file.type || 'application/octet-stream');
88
+ request.responseType = 'json';
89
+ request.upload.addEventListener('progress', (event) => {
90
+ if (event.lengthComputable) {
91
+ options.onProgress?.(event.loaded / event.total);
92
+ }
93
+ });
94
+ request.addEventListener('load', () => {
95
+ // Anything that is not the expected JSON reads as an answer with nothing in it.
96
+ const answer = UploadAnswer.safeParse(request.response).data ?? {};
97
+ const stored = request.status === 201 ? answer.asset : undefined;
98
+ if (stored) {
99
+ resolve({
100
+ id: stored.id,
101
+ name: stored.name ?? stored.id,
102
+ mediaType: stored.mediaType,
103
+ size: stored.size ?? 0,
104
+ });
105
+ }
106
+ else {
107
+ reject(new Error(answer.error ?? `${file.name} could not be uploaded (${request.status}).`));
108
+ }
109
+ });
110
+ request.addEventListener('error', () => reject(new Error(`${file.name} could not be uploaded. Check your connection.`)));
111
+ request.addEventListener('abort', () => reject(new DOMException('Upload cancelled', 'AbortError')));
112
+ options.signal?.addEventListener('abort', () => request.abort(), { once: true });
113
+ request.send(file);
114
+ });
115
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether a model matches what was typed into the picker's search. Every word must appear in one
3
+ * of the fields, in any order, so "opus max" finds "Claude Opus 4.8 1M Max Thinking" and
4
+ * "gpt5" finds "gpt-5.6-sol".
5
+ */
6
+ export declare function matchesModelQuery(query: string, fields: readonly (string | undefined)[]): boolean;
@@ -0,0 +1,16 @@
1
+ const WORD_BREAKS = /[\s\-_/:]+/;
2
+ const compact = (text) => text.replace(/[\s\-_/.:]+/g, '');
3
+ /**
4
+ * Whether a model matches what was typed into the picker's search. Every word must appear in one
5
+ * of the fields, in any order, so "opus max" finds "Claude Opus 4.8 1M Max Thinking" and
6
+ * "gpt5" finds "gpt-5.6-sol".
7
+ */
8
+ export function matchesModelQuery(query, fields) {
9
+ const words = query.toLowerCase().split(WORD_BREAKS).filter(Boolean);
10
+ if (words.length === 0) {
11
+ return true;
12
+ }
13
+ const text = fields.filter(Boolean).join(' ').toLowerCase();
14
+ const squeezed = compact(text);
15
+ return words.every((word) => text.includes(word) || squeezed.includes(compact(word)));
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { HarnessId, Team, VendorHarnessId, VendorModelChoice, VendorModelChoices } from '@swirls/shuttle/api';
2
+ import { type OpenRouterModelId } from './llm-models.js';
3
+ /**
4
+ * Picks the model for whoever does the work in a session. A session run by Codex, Claude Code,
5
+ * or Cursor offers that agent's models; a Shuttle session offers OpenRouter's for the conductor
6
+ * and workers, plus a section for each vendor agent on its team.
7
+ */
8
+ export declare function ModelSwitcher({ harness, team, value, onChange, vendorChoices, onVendorChoiceChange, disabled, }: {
9
+ harness: HarnessId;
10
+ team: Team;
11
+ value: OpenRouterModelId;
12
+ onChange: (model: OpenRouterModelId) => void;
13
+ vendorChoices: VendorModelChoices;
14
+ onVendorChoiceChange: (harness: VendorHarnessId, choice: VendorModelChoice) => void;
15
+ disabled?: boolean;
16
+ }): import("react").JSX.Element;
@@ -0,0 +1,262 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useQueries, useQueryClient } from '@tanstack/react-query';
3
+ import { Check, ChevronDown, Search, X } from 'lucide-react';
4
+ import { useEffect, useMemo, useRef, useState, } from 'react';
5
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '../../components/ui/dropdown-menu.js';
6
+ import { cn } from '../../lib/cn.js';
7
+ import { useApi } from '../../shuttle/index.js';
8
+ import { DEFAULT_OPENROUTER_MODEL, formatContextWindow, getOpenRouterModel, isOpenRouterModelId, MODEL_GROUP_LABELS, MODEL_TAG_LABELS, MODEL_TAG_TONES, modelsByGroup, } from './llm-models.js';
9
+ import { matchesModelQuery } from './model-search.js';
10
+ import { chosenVendorModel, effortLabel, modelSections, sectionLabel, vendorChoiceLabel, withVendorModel, } from './vendor-models.js';
11
+ const GROUPS = ['frontier', 'fast'];
12
+ /** What a section's models are used for, shown under its name in the rail. */
13
+ function sectionHint(section) {
14
+ return section === 'openrouter' ? 'Conductor and workers' : 'Your subscription';
15
+ }
16
+ /**
17
+ * The models each of `harnesses` offers. A list stays in the query cache, so the trigger can
18
+ * name a model without waiting each time it mounts. A list that cannot be read is left out: the
19
+ * picker still offers the agent's default without one.
20
+ */
21
+ function useVendorModels(harnesses) {
22
+ const api = useApi();
23
+ return useQueries({
24
+ queries: harnesses.map((harness) => api.connections.models.queryOptions({ input: { harness } })),
25
+ combine: (results) => new Map(results.map((result, index) => [
26
+ harnesses[index],
27
+ { models: result.data?.models, loading: result.isPending },
28
+ ])),
29
+ });
30
+ }
31
+ /**
32
+ * Which row the arrow keys or pointer are on. Until one moves it, that is the resting row (the
33
+ * current choice); a new search starts again from the first match.
34
+ */
35
+ function useActiveRow(query, count, resting) {
36
+ const [moved, setMoved] = useState(null);
37
+ const index = moved && moved.query === query ? moved.index : query ? 0 : Math.max(resting, 0);
38
+ const setActive = (next) => setMoved((previous) => next === null
39
+ ? null
40
+ : previous?.query === query && previous.index === next
41
+ ? previous
42
+ : { query, index: next });
43
+ return [count === 0 ? -1 : Math.min(index, count - 1), setActive];
44
+ }
45
+ /**
46
+ * Picks the model for whoever does the work in a session. A session run by Codex, Claude Code,
47
+ * or Cursor offers that agent's models; a Shuttle session offers OpenRouter's for the conductor
48
+ * and workers, plus a section for each vendor agent on its team.
49
+ */
50
+ export function ModelSwitcher({ harness, team, value, onChange, vendorChoices, onVendorChoiceChange, disabled = false, }) {
51
+ const api = useApi();
52
+ const queryClient = useQueryClient();
53
+ const [open, setOpen] = useState(false);
54
+ const [picked, setPicked] = useState(null);
55
+ const [query, setQuery] = useState('');
56
+ const sections = modelSections(harness, team);
57
+ const primary = sections[0] ?? 'openrouter';
58
+ const section = picked && sections.includes(picked) ? picked : primary;
59
+ const vendorSections = sections.filter((entry) => entry !== 'openrouter');
60
+ const vendorModels = useVendorModels(vendorSections);
61
+ const selected = getOpenRouterModel(value) ?? getOpenRouterModel(DEFAULT_OPENROUTER_MODEL);
62
+ const summary = (entry) => entry === 'openrouter'
63
+ ? selected.label
64
+ : vendorChoiceLabel(vendorChoices[entry], vendorModels.get(entry)?.models ?? []);
65
+ return (_jsxs(DropdownMenu, { open: open, onOpenChange: (next) => {
66
+ setOpen(next);
67
+ if (next) {
68
+ setPicked(null);
69
+ setQuery('');
70
+ // What an agent offers can change with the plan, so opening the picker asks again.
71
+ void queryClient.invalidateQueries({ queryKey: api.connections.models.key() });
72
+ }
73
+ }, children: [_jsxs(DropdownMenuTrigger, { disabled: disabled, "aria-label": `${sectionLabel(primary)} model`, className: "text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:ring-ring/50 data-[state=open]:bg-accent data-[state=open]:text-foreground ease-snappy flex h-7 max-w-40 min-w-0 shrink items-center gap-1 rounded-md px-2 text-xs whitespace-nowrap transition-[background-color,color,transform] duration-150 outline-none focus-visible:ring-[3px] active:scale-[0.97] disabled:opacity-50 sm:max-w-56", children: [_jsx("span", { className: "truncate", children: summary(primary) }), _jsx(ChevronDown, { className: "size-3 shrink-0 opacity-60" })] }), _jsxs(DropdownMenuContent, { align: "end", collisionPadding: 12, side: "top", sideOffset: 8, className: "flex w-auto max-w-[min(100vw-2rem,46rem)] gap-0 overflow-hidden p-0", onCloseAutoFocus: (event) => event.preventDefault(), onEscapeKeyDown: (event) => {
74
+ if (query) {
75
+ event.preventDefault();
76
+ setQuery('');
77
+ }
78
+ }, children: [sections.length > 1 ? (_jsx("div", { role: "tablist", "aria-label": "Models for", "aria-orientation": "vertical", className: "border-border flex w-36 shrink-0 flex-col gap-0.5 border-r p-1", children: sections.map((entry) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": entry === section, onClick: () => {
79
+ setPicked(entry);
80
+ setQuery('');
81
+ }, className: cn('flex w-full cursor-default flex-col rounded-sm px-2 py-1.5 text-left outline-none select-none', entry === section
82
+ ? 'bg-accent text-accent-foreground'
83
+ : 'text-popover-foreground hover:bg-accent/50'), children: [_jsx("span", { className: "text-xs font-medium", children: sectionLabel(entry) }), _jsx("span", { className: "text-muted-foreground truncate text-[10px]", children: sectionHint(entry) }), _jsx("span", { title: summary(entry), className: "text-muted-foreground/80 mt-0.5 truncate text-[10px]", children: summary(entry) })] }, entry))) })) : null, section === 'openrouter' ? (_jsx(OpenRouterPane, { value: value, selected: selected, query: query, onQueryChange: setQuery, onSelect: (model) => {
84
+ onChange(model);
85
+ setOpen(false);
86
+ } }, section)) : (_jsx(VendorPane, { harness: section, models: vendorModels.get(section)?.models, loading: vendorModels.get(section)?.loading ?? false, choice: vendorChoices[section], query: query, onQueryChange: setQuery, onChange: (choice) => onVendorChoiceChange(section, choice), onClose: () => setOpen(false) }, section))] })] }));
87
+ }
88
+ function OpenRouterPane({ value, selected, query, onQueryChange, onSelect, }) {
89
+ const groups = useMemo(() => GROUPS.map((group) => ({
90
+ group,
91
+ models: modelsByGroup(group).filter((model) => matchesModelQuery(query, [model.label, model.id, model.description])),
92
+ })).filter((entry) => entry.models.length > 0), [query]);
93
+ const rows = groups.flatMap((entry) => entry.models);
94
+ const [active, setActive] = useActiveRow(query, rows.length, rows.findIndex((model) => model.id === value));
95
+ const preview = rows[active] ?? selected;
96
+ return (_jsxs(_Fragment, { children: [_jsx(ModelList, { query: query, onQueryChange: onQueryChange, placeholder: "Search models", count: rows.length, active: active, onActiveChange: setActive, onPick: (index) => {
97
+ const model = rows[index];
98
+ if (model && isOpenRouterModelId(model.id)) {
99
+ onSelect(model.id);
100
+ }
101
+ }, children: groups.map(({ group, models }, groupIndex) => (_jsxs("div", { children: [groupIndex > 0 ? _jsx(DropdownMenuSeparator, {}) : null, _jsx(DropdownMenuLabel, { children: MODEL_GROUP_LABELS[group] }), models.map((model) => {
102
+ const index = rows.indexOf(model);
103
+ return (_jsx(OptionRow, { label: model.label, trailing: _jsx(ModelTags, { tags: model.tags, size: "row" }), selected: model.id === value, active: index === active, onActivate: () => setActive(index), onSelect: () => {
104
+ if (isOpenRouterModelId(model.id)) {
105
+ onSelect(model.id);
106
+ }
107
+ } }, model.id));
108
+ })] }, group))) }), _jsxs("aside", { className: "border-border hidden w-52 shrink-0 border-l p-3 sm:block", children: [_jsx("p", { className: "text-foreground text-xs font-medium", children: preview.label }), _jsx("p", { className: "text-muted-foreground mt-1.5 text-[11px] leading-relaxed", children: preview.description }), _jsx("p", { className: "text-muted-foreground/80 mt-2 text-[11px]", children: formatContextWindow(preview.context) }), preview.note ? (_jsx("p", { className: "text-muted-foreground/70 mt-1 text-[11px] italic", children: preview.note })) : null, _jsx("div", { className: "mt-2.5", children: _jsx(ModelTags, { tags: preview.tags, size: "detail" }) })] })] }));
109
+ }
110
+ /**
111
+ * A vendor agent's models on the left, and beside them the one under the pointer or keyboard,
112
+ * with reasoning efforts once a model that takes them is chosen.
113
+ */
114
+ function VendorPane({ harness, models, loading, choice, query, onQueryChange, onChange, onClose, }) {
115
+ const list = models ?? [];
116
+ const defaultModel = list.find((model) => model.isDefault);
117
+ const current = chosenVendorModel(choice, list);
118
+ const agent = sectionLabel(harness);
119
+ const all = [
120
+ {
121
+ key: ':default',
122
+ label: 'Default',
123
+ hint: defaultModel?.label,
124
+ keywords: ['default', agent, defaultModel?.label],
125
+ title: `${agent} default`,
126
+ description: defaultModel
127
+ ? `Whichever model ${agent} picks for your plan, currently ${defaultModel.label}.`
128
+ : `Whichever model ${agent} picks for your plan.`,
129
+ efforts: defaultModel?.efforts ?? [],
130
+ selected: !choice?.model,
131
+ choice: withVendorModel(choice, undefined, defaultModel),
132
+ },
133
+ ...list.map((model) => ({
134
+ key: model.id,
135
+ label: model.label,
136
+ keywords: [model.label, model.id, model.description],
137
+ title: model.label,
138
+ description: model.description,
139
+ id: model.id,
140
+ efforts: model.efforts,
141
+ selected: choice?.model === model.id,
142
+ choice: withVendorModel(choice, model, defaultModel),
143
+ })),
144
+ ...(choice?.model && !current
145
+ ? [
146
+ {
147
+ key: ':missing',
148
+ label: choice.model,
149
+ keywords: [choice.model],
150
+ title: choice.model,
151
+ description: `${agent} no longer lists this model.`,
152
+ efforts: [],
153
+ selected: true,
154
+ },
155
+ ]
156
+ : []),
157
+ ];
158
+ const rows = all.filter((row) => matchesModelQuery(query, row.keywords));
159
+ const [active, setActive] = useActiveRow(query, rows.length, rows.findIndex((row) => row.selected));
160
+ const preview = rows[active] ?? all.find((row) => row.selected);
161
+ const pick = (row) => {
162
+ if (row.choice) {
163
+ onChange(row.choice);
164
+ }
165
+ if (row.efforts.length === 0) {
166
+ onClose();
167
+ }
168
+ };
169
+ return (_jsxs(_Fragment, { children: [_jsx(ModelList, { query: query, onQueryChange: onQueryChange, placeholder: `Search ${agent} models`, count: rows.length, active: active, onActiveChange: setActive, onPick: (index) => {
170
+ const row = rows[index];
171
+ if (row) {
172
+ pick(row);
173
+ }
174
+ }, onPointerLeave: () => setActive(null), status: loading ? (_jsx("p", { className: "text-muted-foreground px-2 py-1.5 text-[11px]", children: "Loading models\u2026" })) : null, children: rows.map((row, index) => (_jsx(OptionRow, { label: row.label, trailing: row.hint ? (_jsx("span", { className: "text-muted-foreground text-[10px]", children: row.hint })) : null, selected: row.selected, active: index === active, onActivate: () => setActive(index), onSelect: () => pick(row) }, row.key))) }), _jsxs("aside", { className: "border-border flex max-h-80 w-52 shrink-0 flex-col overflow-y-auto border-l p-1", children: [preview ? (_jsxs("div", { className: "px-2 pt-2 pb-1.5", children: [_jsx("p", { className: "text-foreground text-xs font-medium break-words", children: preview.title }), preview.description ? (_jsx("p", { className: "text-muted-foreground mt-1 text-[11px] leading-relaxed", children: preview.description })) : null, preview.id ? (_jsx("p", { className: "text-muted-foreground/70 mt-1.5 font-mono text-[10px] break-all", children: preview.id })) : null] })) : null, preview && preview.efforts.length > 0 ? (preview.selected ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuLabel, { children: "Reasoning" }), _jsx(OptionRow, { label: "Default", trailing: current?.defaultEffort ? (_jsx("span", { className: "text-muted-foreground text-[10px]", children: effortLabel(current.defaultEffort) })) : null, selected: !choice?.effort, onSelect: () => {
175
+ onChange(choice?.model ? { model: choice.model } : {});
176
+ onClose();
177
+ } }), preview.efforts.map((effort) => (_jsx(OptionRow, { label: effortLabel(effort), selected: choice?.effort === effort, onSelect: () => {
178
+ onChange({ ...(choice?.model ? { model: choice.model } : {}), effort });
179
+ onClose();
180
+ } }, effort)))] })) : (_jsxs("p", { className: "text-muted-foreground px-2 pb-2 text-[11px] leading-relaxed", children: ["Reasoning: ", preview.efforts.map(effortLabel).join(', ')] }))) : null] })] }));
181
+ }
182
+ /** Scrolls the list just enough to show the row, keeping the first group's heading visible. */
183
+ function keepInView(list, row, isFirst) {
184
+ const top = row.offsetTop - 4;
185
+ const bottom = row.offsetTop + row.offsetHeight + 4;
186
+ if (isFirst) {
187
+ list.scrollTop = 0;
188
+ }
189
+ else if (top < list.scrollTop) {
190
+ list.scrollTop = top;
191
+ }
192
+ else if (bottom > list.scrollTop + list.clientHeight) {
193
+ list.scrollTop = bottom - list.clientHeight;
194
+ }
195
+ }
196
+ /** A search field over a list of models; the arrow keys and Enter work from the field. */
197
+ function ModelList({ query, onQueryChange, placeholder, count, active, onActiveChange, onPick, onPointerLeave, status, children, }) {
198
+ const columnRef = useRef(null);
199
+ const inputRef = useRef(null);
200
+ const listRef = useRef(null);
201
+ const [fullHeight, setFullHeight] = useState();
202
+ useEffect(() => {
203
+ // Focusing on touch screens would raise the keyboard over the list.
204
+ if (window.matchMedia('(pointer: fine)').matches) {
205
+ inputRef.current?.focus({ preventScroll: true });
206
+ }
207
+ }, []);
208
+ useEffect(() => {
209
+ const list = listRef.current;
210
+ const row = list?.querySelector('[data-active="true"]');
211
+ if (list && row) {
212
+ keepInView(list, row, active === 0);
213
+ }
214
+ }, [active]);
215
+ const changeQuery = (next) => {
216
+ // The menu grows up from the composer, so a shrinking list would pull the field down.
217
+ if (!query && next) {
218
+ setFullHeight(columnRef.current?.offsetHeight);
219
+ }
220
+ listRef.current?.scrollTo({ top: 0 });
221
+ onQueryChange(next);
222
+ };
223
+ const onKeyDown = (event) => {
224
+ if (event.key === 'Escape') {
225
+ return;
226
+ }
227
+ // The menu would otherwise take typed letters as typeahead and swallow Tab.
228
+ event.stopPropagation();
229
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
230
+ event.preventDefault();
231
+ if (count > 0) {
232
+ const step = event.key === 'ArrowDown' ? 1 : -1;
233
+ onActiveChange(Math.min(Math.max(active + step, 0), count - 1));
234
+ }
235
+ }
236
+ else if (event.key === 'Enter' && active >= 0) {
237
+ event.preventDefault();
238
+ onPick(active);
239
+ }
240
+ };
241
+ return (_jsxs("div", { ref: columnRef, style: query && fullHeight ? { minHeight: fullHeight } : undefined, className: "flex w-60 shrink-0 flex-col sm:w-72", children: [_jsxs("div", { className: "border-border flex h-9 shrink-0 items-center gap-2 border-b px-3", children: [_jsx(Search, { className: "text-muted-foreground size-3.5 shrink-0" }), _jsx("input", { ref: inputRef, type: "text", value: query, placeholder: placeholder, "aria-label": placeholder, autoComplete: "off", spellCheck: false, onChange: (event) => changeQuery(event.target.value), onKeyDown: onKeyDown, className: "text-foreground placeholder:text-muted-foreground/70 min-w-0 flex-1 bg-transparent text-xs outline-none" }), query ? (_jsx("button", { type: "button", "aria-label": "Clear search", onMouseDown: (event) => event.preventDefault(), onClick: () => changeQuery(''), className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 -mr-1 flex size-5 shrink-0 cursor-default items-center justify-center rounded-sm outline-none focus-visible:ring-[3px]", children: _jsx(X, { className: "size-3" }) })) : null] }), _jsxs("div", { ref: listRef, onPointerLeave: onPointerLeave, className: "relative flex max-h-80 min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain p-1", children: [count > 0 ? (children) : (_jsxs("p", { className: "text-muted-foreground px-2 py-6 text-center text-[11px] break-words", children: ["No models match \u201C", query, "\u201D"] })), status] })] }));
242
+ }
243
+ /**
244
+ * A pickable row. Rows in a searchable list are highlighted by the list (`active`), so the
245
+ * keyboard and pointer share one highlight; other rows highlight on hover.
246
+ */
247
+ function OptionRow({ label, trailing, selected, active, onActivate, onSelect, }) {
248
+ const onPointerMove = (event) => {
249
+ // Rows scrolling under a still pointer report no movement, and shouldn't steal the highlight.
250
+ if (event.movementX !== 0 || event.movementY !== 0) {
251
+ onActivate?.();
252
+ }
253
+ };
254
+ return (_jsxs("button", { type: "button", role: "menuitemradio", "aria-checked": selected, "data-active": active, onPointerMove: onActivate ? onPointerMove : undefined, onFocus: onActivate, onMouseDown: (event) => event.preventDefault(), onClick: onSelect, className: cn('relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-7 text-left text-xs outline-none select-none', active === undefined
255
+ ? 'text-popover-foreground hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent'
256
+ : active
257
+ ? 'bg-accent text-accent-foreground'
258
+ : 'text-popover-foreground'), children: [_jsx("span", { className: "absolute top-2 left-2 flex size-3.5 items-center justify-center", children: selected ? _jsx(Check, { className: "size-3.5" }) : null }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: label }), trailing ? _jsx("span", { className: "flex shrink-0 items-center gap-1", children: trailing }) : null] }));
259
+ }
260
+ function ModelTags({ tags, size }) {
261
+ return (_jsx("span", { className: "flex flex-wrap items-center gap-1", children: tags.map((tag) => (_jsx("span", { className: cn('inline-flex items-center font-medium', size === 'row' ? 'h-4 rounded px-1 text-[10px]' : 'h-5 rounded-md px-1.5 text-[10px]', MODEL_TAG_TONES[tag]), children: MODEL_TAG_LABELS[tag] }, tag))) }));
262
+ }
@@ -0,0 +1,20 @@
1
+ import type { SessionFeed } from './session-feed.js';
2
+ /** Where the session's pull request stands, from the publish cards in its feed. */
3
+ export declare function pullRequestState(feed: SessionFeed): {
4
+ /** A card waiting for someone to publish or discard it. */
5
+ readonly awaiting: string | null;
6
+ /** A card that was approved and is being published now. */
7
+ readonly publishing: boolean;
8
+ };
9
+ /**
10
+ * The session's PR button. It works whichever agent runs the session: it opens the publish card
11
+ * at once, titled from the commits, and Shuttle publishes once someone approves it there.
12
+ */
13
+ export declare function OpenPullRequestButton({ runId, feed, hasPulls, working, }: {
14
+ runId: string;
15
+ feed: SessionFeed;
16
+ /** The session already opened a pull request, so this one updates it. */
17
+ hasPulls: boolean;
18
+ /** The agents are mid-turn: a pull request now could catch half-written work. */
19
+ working: boolean;
20
+ }): import("react").JSX.Element;
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMutation } from '@tanstack/react-query';
3
+ import { GitPullRequestArrow, LoaderCircle } from 'lucide-react';
4
+ import { useEffect, useState } from 'react';
5
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../../components/ui/tooltip.js';
6
+ import { cn } from '../../lib/cn.js';
7
+ import { useApi } from '../../shuttle/index.js';
8
+ /** How long to wait for the card before saying something went wrong. */
9
+ const CARD_TIMEOUT_MS = 30_000;
10
+ /** Where the session's pull request stands, from the publish cards in its feed. */
11
+ export function pullRequestState(feed) {
12
+ let awaiting = null;
13
+ let publishing = false;
14
+ for (const item of feed.items) {
15
+ if (item.kind !== 'question' || !item.approvalId.startsWith('pr_publish_') || item.publish) {
16
+ continue;
17
+ }
18
+ if (!item.decision) {
19
+ awaiting = item.approvalId;
20
+ }
21
+ else if (item.decision.answer !== null && item.decision.answer !== 'discard') {
22
+ publishing = true;
23
+ }
24
+ }
25
+ return { awaiting, publishing };
26
+ }
27
+ function showCard(approvalId) {
28
+ const card = document.querySelector(`[data-approval-id="${CSS.escape(approvalId)}"]`);
29
+ card?.scrollIntoView({ behavior: 'smooth', block: 'center' });
30
+ }
31
+ /**
32
+ * The session's PR button. It works whichever agent runs the session: it opens the publish card
33
+ * at once, titled from the commits, and Shuttle publishes once someone approves it there.
34
+ */
35
+ export function OpenPullRequestButton({ runId, feed, hasPulls, working, }) {
36
+ const api = useApi();
37
+ // Asking answers with the id of the publish card, which then arrives on the session's feed.
38
+ const request = useMutation(api.sessions.pullRequest.mutationOptions());
39
+ const [requested, setRequested] = useState(null);
40
+ const [timedOut, setTimedOut] = useState(false);
41
+ const { awaiting, publishing } = pullRequestState(feed);
42
+ // The card the button asked for is in the feed, whatever has become of it since.
43
+ const arrived = requested !== null &&
44
+ feed.items.some((item) => item.kind === 'question' && item.approvalId === requested);
45
+ // The card the button asked for has arrived: take the person to it.
46
+ useEffect(() => {
47
+ if (arrived && requested) {
48
+ requestAnimationFrame(() => showCard(requested));
49
+ }
50
+ }, [arrived, requested]);
51
+ useEffect(() => {
52
+ if (!requested || arrived) {
53
+ return;
54
+ }
55
+ const timer = setTimeout(() => {
56
+ setRequested(null);
57
+ setTimedOut(true);
58
+ }, CARD_TIMEOUT_MS);
59
+ return () => clearTimeout(timer);
60
+ }, [requested, arrived]);
61
+ const opening = request.isPending || (requested !== null && !arrived);
62
+ const error = timedOut
63
+ ? 'The pull request card did not appear. Try again in a moment.'
64
+ : (request.error?.message ?? null);
65
+ const label = hasPulls ? 'Update PR' : 'Open PR';
66
+ const disabledReason = publishing
67
+ ? 'Publishing the pull request…'
68
+ : working && !awaiting
69
+ ? 'Available when the agents finish their turn'
70
+ : null;
71
+ const tip = error ??
72
+ disabledReason ??
73
+ (awaiting
74
+ ? 'A pull request is waiting for your approval. Show it.'
75
+ : hasPulls
76
+ ? 'Push the latest work to this session’s pull request. You review it before anything is published.'
77
+ : 'Open a pull request of this session’s work. You review the title and description before anything is published.');
78
+ function onClick() {
79
+ setTimedOut(false);
80
+ request.reset();
81
+ if (awaiting) {
82
+ showCard(awaiting);
83
+ return;
84
+ }
85
+ request.mutate({ id: runId }, { onSuccess: ({ approvalId }) => setRequested(approvalId) });
86
+ }
87
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs("button", { type: "button", onClick: onClick, disabled: opening || disabledReason !== null, "aria-label": awaiting ? 'Show the pull request waiting for approval' : label, className: cn('focus-visible:ring-ring/50 inline-flex h-6 shrink-0 items-center gap-1.5 rounded-full border px-2 text-[11px] transition-colors duration-100 outline-none focus-visible:ring-2 disabled:opacity-50', awaiting
88
+ ? 'border-brand/50 text-brand hover:bg-brand/10'
89
+ : error
90
+ ? 'border-status-failed/50 text-status-failed'
91
+ : 'text-muted-foreground hover:text-foreground'), children: [opening || publishing ? (_jsx(LoaderCircle, { className: "size-3 animate-spin" })) : (_jsx(GitPullRequestArrow, { className: "size-3" })), _jsx("span", { className: "hidden @lg:inline", children: opening ? 'Opening…' : publishing ? 'Publishing…' : awaiting ? 'Review PR' : label })] }) }), _jsx(TooltipContent, { side: "bottom", align: "end", className: "max-w-64", children: tip })] }));
92
+ }
@@ -0,0 +1,14 @@
1
+ import type { AgentIdentity } from './agents.js';
2
+ import type { FeedItem } from './session-feed.js';
3
+ export interface PullPublishCardContext {
4
+ readonly runId: string;
5
+ readonly identities: ReadonlyMap<string, AgentIdentity>;
6
+ readonly onInspect: (threadId: string, seq?: number) => void;
7
+ }
8
+ export declare function PullPublishCard({ item, context, className, }: {
9
+ item: Extract<FeedItem, {
10
+ kind: 'question';
11
+ }>;
12
+ context: PullPublishCardContext;
13
+ className?: string;
14
+ }): import("react").JSX.Element;