@flowdular/sdk 0.1.0 → 0.2.1

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 (175) hide show
  1. package/.ai/skills/test-hardening/SKILL.md +1 -1
  2. package/README.md +69 -12
  3. package/assets/flowdular-banner.png +0 -0
  4. package/modules/agents/package.json +1 -1
  5. package/modules/auth/package.json +1 -1
  6. package/modules/auth/src/client/AuthenticationCore.tsrx +3 -1
  7. package/modules/auth/src/server/endpoints.ts +3 -1
  8. package/modules/auth/src/server/runtime.ts +4 -0
  9. package/modules/automations/package.json +1 -1
  10. package/modules/automations-workflows-integration/package.json +1 -1
  11. package/modules/profile/package.json +1 -1
  12. package/modules/sandbox/package.json +1 -1
  13. package/modules/system/package.json +1 -1
  14. package/modules/users/package.json +1 -1
  15. package/modules/workflows/package.json +1 -1
  16. package/package.json +5 -13
  17. package/packages/ai-provider/package.json +1 -1
  18. package/packages/cli-protocol/package.json +1 -1
  19. package/packages/client/package.json +1 -1
  20. package/packages/client/src/routing.ts +39 -2
  21. package/packages/client/src/shell/BrandMark.tsrx +5 -1
  22. package/packages/client/src/shell/navigation.ts +3 -1
  23. package/packages/client/src/state.ts +6 -2
  24. package/packages/contracts/package.json +1 -1
  25. package/packages/contracts/schemas/project.schema.json +16 -42
  26. package/packages/database/package.json +1 -1
  27. package/packages/database-pglite/package.json +2 -2
  28. package/packages/database-pglite/src/driver.ts +21 -3
  29. package/packages/database-testing/package.json +1 -1
  30. package/packages/dev-console/package.json +1 -1
  31. package/packages/harness/package.json +1 -1
  32. package/packages/kernel/package.json +1 -1
  33. package/packages/server/package.json +1 -1
  34. package/packages/server/src/application-routes.ts +80 -8
  35. package/packages/server/src/index.ts +4 -1
  36. package/packages/server/src/web-html.ts +9 -5
  37. package/packages/server/src/web.ts +59 -7
  38. package/packages/ui/package.json +1 -1
  39. package/packages/coding-agent/package.json +0 -44
  40. package/packages/coding-agent/src/drivers/byok.ts +0 -322
  41. package/packages/coding-agent/src/drivers/claude-code.ts +0 -290
  42. package/packages/coding-agent/src/drivers/codex.ts +0 -281
  43. package/packages/coding-agent/src/index.ts +0 -56
  44. package/packages/coding-agent/src/registry.ts +0 -119
  45. package/packages/coding-agent/src/roles/contract.ts +0 -60
  46. package/packages/coding-agent/src/roles/defaults.ts +0 -134
  47. package/packages/coding-agent/src/roles/handoff.ts +0 -41
  48. package/packages/coding-agent/src/roles/registry.ts +0 -156
  49. package/packages/coding-agent/src/roles/skills.ts +0 -72
  50. package/packages/coding-agent/src/roles/sync.ts +0 -88
  51. package/packages/coding-agent/src/types.ts +0 -102
  52. package/packages/coding-agent/src/workspace.ts +0 -275
  53. package/packages/sandbox/README.md +0 -691
  54. package/packages/sandbox/bin/flowdular-sandbox.mjs +0 -393
  55. package/packages/sandbox/dist/client/assets/App-ClMOrpyg.js +0 -11
  56. package/packages/sandbox/dist/client/assets/PreviewHost-BHiHrfbQ.js +0 -1
  57. package/packages/sandbox/dist/client/assets/auto-buGEq6de.js +0 -3
  58. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  59. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  60. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  61. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  62. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  63. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  64. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  65. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  66. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  67. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  68. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  69. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  70. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  71. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  72. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  73. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  74. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  75. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  76. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  77. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  78. package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  79. package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  80. package/packages/sandbox/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  81. package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  82. package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  83. package/packages/sandbox/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  84. package/packages/sandbox/dist/client/assets/index-CvwhlQ87.js +0 -4
  85. package/packages/sandbox/dist/client/assets/styles-BPWaGf55.js +0 -3
  86. package/packages/sandbox/dist/client/assets/styles-Dx1_KOag.css +0 -1
  87. package/packages/sandbox/dist/client/favicon.svg +0 -1
  88. package/packages/sandbox/dist/server/assets/auto-CVGNYyb3.js +0 -12785
  89. package/packages/sandbox/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +0 -4125
  90. package/packages/sandbox/dist/server/assets/nodefs-DVSI7kG0.js +0 -24
  91. package/packages/sandbox/dist/server/assets/opfs-ahp-D56iokt1.js +0 -388
  92. package/packages/sandbox/dist/server/assets/token-Bvaq7Anz.js +0 -55
  93. package/packages/sandbox/dist/server/assets/token-util-BqSvdIPQ.js +0 -3
  94. package/packages/sandbox/dist/server/assets/token-util-CktFFT4z.js +0 -494
  95. package/packages/sandbox/dist/server/entry.js +0 -91671
  96. package/packages/sandbox/dist/server/favicon.svg +0 -1
  97. package/packages/sandbox/dist/server/index.html +0 -161
  98. package/packages/sandbox/index.html +0 -159
  99. package/packages/sandbox/octane.config.ts +0 -36
  100. package/packages/sandbox/package.json +0 -83
  101. package/packages/sandbox/public/favicon.svg +0 -1
  102. package/packages/sandbox/public/og.png +0 -0
  103. package/packages/sandbox/src/App.tsrx +0 -924
  104. package/packages/sandbox/src/client/ApprovalHandoff.tsrx +0 -39
  105. package/packages/sandbox/src/client/ChatPane.tsrx +0 -694
  106. package/packages/sandbox/src/client/ConnectView.tsrx +0 -86
  107. package/packages/sandbox/src/client/DiffPane.tsrx +0 -150
  108. package/packages/sandbox/src/client/EjectModal.tsrx +0 -571
  109. package/packages/sandbox/src/client/GateResults.tsrx +0 -60
  110. package/packages/sandbox/src/client/GitHubSettingsModal.tsrx +0 -219
  111. package/packages/sandbox/src/client/NewSessionForm.tsrx +0 -214
  112. package/packages/sandbox/src/client/SessionBar.tsrx +0 -151
  113. package/packages/sandbox/src/client/SessionPicker.tsrx +0 -472
  114. package/packages/sandbox/src/client/SpecEditor.tsrx +0 -109
  115. package/packages/sandbox/src/client/SpecReviewCard.tsrx +0 -321
  116. package/packages/sandbox/src/client/WorkCard.tsrx +0 -128
  117. package/packages/sandbox/src/client/WorkbenchModal.tsrx +0 -161
  118. package/packages/sandbox/src/client/WorkspaceMenu.tsrx +0 -100
  119. package/packages/sandbox/src/client/api.ts +0 -797
  120. package/packages/sandbox/src/client/attachments.ts +0 -73
  121. package/packages/sandbox/src/client/dashboard.ts +0 -46
  122. package/packages/sandbox/src/client/github-settings.ts +0 -48
  123. package/packages/sandbox/src/client/highlight.ts +0 -105
  124. package/packages/sandbox/src/client/i18n.ts +0 -32
  125. package/packages/sandbox/src/client/locales/en.json +0 -466
  126. package/packages/sandbox/src/client/locales/pl.json +0 -466
  127. package/packages/sandbox/src/client/session-labels.ts +0 -77
  128. package/packages/sandbox/src/client/state.ts +0 -108
  129. package/packages/sandbox/src/index.ts +0 -10
  130. package/packages/sandbox/src/preview/PreviewHost.tsrx +0 -373
  131. package/packages/sandbox/src/preview/load-module.ts +0 -16
  132. package/packages/sandbox/src/server/attachments.ts +0 -308
  133. package/packages/sandbox/src/server/auto-review.ts +0 -181
  134. package/packages/sandbox/src/server/checkpoints.ts +0 -90
  135. package/packages/sandbox/src/server/config.ts +0 -460
  136. package/packages/sandbox/src/server/dashboard.ts +0 -245
  137. package/packages/sandbox/src/server/delivery/configuration.ts +0 -193
  138. package/packages/sandbox/src/server/delivery/git-pr.ts +0 -1473
  139. package/packages/sandbox/src/server/delivery/index.ts +0 -83
  140. package/packages/sandbox/src/server/delivery/local.ts +0 -151
  141. package/packages/sandbox/src/server/delivery/official-modules.ts +0 -516
  142. package/packages/sandbox/src/server/delivery/plan.ts +0 -218
  143. package/packages/sandbox/src/server/delivery/policies.ts +0 -239
  144. package/packages/sandbox/src/server/delivery/record.ts +0 -41
  145. package/packages/sandbox/src/server/delivery/steps.ts +0 -464
  146. package/packages/sandbox/src/server/delivery/types.ts +0 -158
  147. package/packages/sandbox/src/server/dependencies.ts +0 -88
  148. package/packages/sandbox/src/server/diff.ts +0 -230
  149. package/packages/sandbox/src/server/gates.ts +0 -388
  150. package/packages/sandbox/src/server/index.ts +0 -139
  151. package/packages/sandbox/src/server/path-guard.ts +0 -282
  152. package/packages/sandbox/src/server/planning.ts +0 -749
  153. package/packages/sandbox/src/server/platform-client.ts +0 -189
  154. package/packages/sandbox/src/server/preview-database-host.ts +0 -340
  155. package/packages/sandbox/src/server/preview-database-protocol.ts +0 -163
  156. package/packages/sandbox/src/server/preview-database-proxy.ts +0 -356
  157. package/packages/sandbox/src/server/preview-database.ts +0 -109
  158. package/packages/sandbox/src/server/preview-ipc.ts +0 -15
  159. package/packages/sandbox/src/server/preview-modules.ts +0 -83
  160. package/packages/sandbox/src/server/preview-revision.ts +0 -44
  161. package/packages/sandbox/src/server/preview-runtime.ts +0 -467
  162. package/packages/sandbox/src/server/preview-worker-manager.ts +0 -436
  163. package/packages/sandbox/src/server/preview-worker.ts +0 -168
  164. package/packages/sandbox/src/server/reference.ts +0 -251
  165. package/packages/sandbox/src/server/routes.ts +0 -2258
  166. package/packages/sandbox/src/server/runtime.ts +0 -188
  167. package/packages/sandbox/src/server/session-owner.ts +0 -23
  168. package/packages/sandbox/src/server/sessions.ts +0 -849
  169. package/packages/sandbox/src/server/spec.ts +0 -471
  170. package/packages/sandbox/src/server/turn-lifecycle.ts +0 -56
  171. package/packages/sandbox/src/server/turns.ts +0 -993
  172. package/packages/sandbox/src/server/workspace-install.ts +0 -266
  173. package/packages/sandbox/src/server/workspace-root.ts +0 -73
  174. package/packages/sandbox/src/styles.css +0 -1573
  175. package/packages/sandbox/vite.config.ts +0 -133
@@ -1,694 +0,0 @@
1
- import { useEffect, useRef, useState } from 'octane';
2
- import { Button, Icon, Tag } from '@flowdular/sdk/ui';
3
- import type {
4
- ChatEntry,
5
- HandoffPlan,
6
- SessionAttachment,
7
- SessionCheckpoint,
8
- SessionModule,
9
- } from '../server/sessions.ts';
10
- import {
11
- attachmentUrl,
12
- deleteAttachment,
13
- loadSession,
14
- restoreCheckpoint,
15
- uploadAttachment,
16
- type DriverSummary,
17
- type ModuleSpecReview,
18
- type RoleSummary,
19
- } from './api.ts';
20
- import { ApprovalHandoff } from './ApprovalHandoff.tsrx';
21
- import { ATTACH_ACCEPT, attachmentKind, formatBytes } from './attachments.ts';
22
- import {
23
- sessionIdFromUrl,
24
- type PendingAttachment,
25
- type PreviewSelection,
26
- } from './state.ts';
27
- import { t, useTranslation } from './i18n.ts';
28
- import { roleLabel, handoffLabel } from './session-labels.ts';
29
-
30
- export interface ChatPaneProps {
31
- readonly entries: readonly ChatEntry[];
32
- readonly delivered: boolean;
33
- readonly roles: readonly RoleSummary[];
34
- readonly drivers: readonly DriverSummary[];
35
- readonly modules: readonly SessionModule[];
36
- /* One specification review per module, in session order. */
37
- readonly specs: readonly ModuleSpecReview[];
38
- readonly role: string;
39
- /* The module the next turn targets; empty lets the sandbox decide. */
40
- readonly module: string;
41
- readonly driver: string;
42
- readonly message: string;
43
- readonly running: boolean;
44
- readonly busy?: boolean;
45
- readonly selection: PreviewSelection | null;
46
- readonly autoContinue: boolean;
47
- /* Set when the session has never run a turn, so the brief can still start it. */
48
- readonly pendingBrief: string;
49
- readonly onStart: () => void;
50
- readonly onContinue: (handoff: HandoffPlan) => void;
51
- readonly onApprove: (handoff: HandoffPlan) => void;
52
- readonly onRequestChanges: (module: string, comment: string) => void;
53
- readonly onEditSpec: (module: string) => void;
54
- readonly onAutoContinue: (enabled: boolean) => void;
55
- readonly onRole: (role: string) => void;
56
- readonly onModule: (module: string) => void;
57
- readonly onDriver: (driver: string) => void;
58
- readonly onMessage: (message: string) => void;
59
- readonly onSend: () => void;
60
- readonly onStop: () => void;
61
- readonly onClearSelection: () => void;
62
- }
63
-
64
- function eventLabel(entry: ChatEntry): string {
65
- const event = entry.event;
66
- if (!event) return entry.text ?? '';
67
- switch (event.type) {
68
- case 'turn.started':
69
- return t('sandbox.chat.event.started', {
70
- driver: event.driver,
71
- role: roleLabel(event.role),
72
- });
73
- case 'reasoning':
74
- return event.text.slice(0, 160);
75
- case 'tool.started':
76
- return `${event.tool} ${event.detail}`;
77
- case 'tool.completed':
78
- return `${event.tool} ${event.detail} ${
79
- event.ok ? t('sandbox.chat.event.ok') : t('sandbox.chat.event.failed')
80
- }`;
81
- case 'file.changed':
82
- return `${event.change} ${event.path}`;
83
- case 'error':
84
- return `${event.code}: ${event.message}`;
85
- case 'turn.completed':
86
- return t('sandbox.chat.event.finished', {
87
- count: event.usage.totalTokens,
88
- });
89
- default:
90
- return event.type;
91
- }
92
- }
93
-
94
- function isError(entry: ChatEntry): boolean {
95
- return entry.event?.type === 'error';
96
- }
97
-
98
- const HANDOFF_LINE = /^handoff\s*:/i;
99
-
100
- /* The handoff line is protocol, not conversation: the card below the message
101
- already says who continues, so the transcript shows the words only. */
102
- function spoken(entry: ChatEntry): string {
103
- const lines = (entry.text ?? '').split('\n');
104
- while (lines.length > 0 &&
105
- lines[lines.length - 1]!.trim() === '') lines.pop();
106
- const last = lines[lines.length - 1]?.replace(/[`*_]/g, '').trim() ?? '';
107
- if (entry.kind === 'agent' && HANDOFF_LINE.test(last)) lines.pop();
108
- while (lines.length > 0 &&
109
- lines[lines.length - 1]!.trim() === '') lines.pop();
110
- return lines.join('\n');
111
- }
112
-
113
- interface StreamBlock {
114
- readonly key: number;
115
- readonly entry: ChatEntry | null;
116
- readonly events: readonly ChatEntry[] | null;
117
- }
118
-
119
- const EVENT_TAIL = 6;
120
-
121
- /* One stream in the order it happened: a message, then the tool activity that
122
- followed it, so the newest thing on screen is the newest thing that happened.
123
- A long run of tool events keeps only its tail, because the transcript is the
124
- conversation and the events are its footnotes. */
125
- function streamBlocks(entries: readonly ChatEntry[]): readonly StreamBlock[] {
126
- const blocks: {
127
- key: number;
128
- entry: ChatEntry | null;
129
- events: ChatEntry[] | null;
130
- }[] = [];
131
- for (const entry of entries) {
132
- const last = blocks[blocks.length - 1];
133
- if (entry.kind === 'event') {
134
- if (last?.events) {
135
- last.events.push(entry);
136
- continue;
137
- }
138
- blocks.push({ key: entry.sequence, entry: null, events: [entry] });
139
- continue;
140
- }
141
- blocks.push({ key: entry.sequence, entry, events: null });
142
- }
143
- return blocks.map(
144
- (block) => ({
145
- key: block.key,
146
- entry: block.entry,
147
- events: block.events ? block.events.slice(-EVENT_TAIL) : null,
148
- }),
149
- );
150
- }
151
-
152
- function blockKey(block: StreamBlock): number {
153
- return block.key;
154
- }
155
-
156
- function handoffIcon(kind: HandoffPlan['kind']): string {
157
- if (kind === 'approval') return 'check';
158
- if (kind === 'blocked') return 'alert';
159
- if (kind === 'question') return 'help';
160
- if (kind === 'review') return 'flask';
161
- return 'play';
162
- }
163
-
164
- export function ChatPane(props: ChatPaneProps) @{
165
- const { t } = useTranslation();
166
- const offered = props.drivers.filter((driver) => driver.offered);
167
- const stream = streamBlocks(props.entries);
168
- /* Which module an entry belongs to only matters once a session has several;
169
- with one module the transcript stays as quiet as it was. */
170
- const moduleLabel = (entry: ChatEntry) => props.modules.length > 1 &&
171
- entry.module
172
- ? <span class="ui-mono chat__module">{entry.module}</span>
173
- : null;
174
- /* Only the newest handoff can still be acted on. The older ones stay in the
175
- transcript as a record of who worked and why. */
176
- const open =
177
- props.entries.filter((entry) => entry.handoff).at(-1)?.sequence ?? -1;
178
- const scroller = useRef<HTMLDivElement | null>(null);
179
- const attachInput = useRef<HTMLInputElement | null>(null);
180
- /* The composer manages its own attachments: App owns the transcript, but the
181
- session id from the URL is enough to upload, list and remove them here. */
182
- const sessionId =
183
- typeof window === 'undefined'
184
- ? ''
185
- : sessionIdFromUrl(window.location.pathname);
186
- const [attachments, setAttachments] = useState<
187
- readonly SessionAttachment[]
188
- >([]);
189
- const [pending, setPending] = useState<readonly PendingAttachment[]>([]);
190
- const [attachError, setAttachError] = useState('');
191
- const [checkpoints, setCheckpoints] = useState<
192
- readonly SessionCheckpoint[]
193
- >([]);
194
- const [confirmRestore, setConfirmRestore] = useState<number | null>(null);
195
- const [restoring, setRestoring] = useState(false);
196
- const [restoreError, setRestoreError] = useState('');
197
- const firstKey =
198
- stream.length > 0 ? stream[0]!.key : -1;
199
- /* A block is a restore point when a checkpoint shares its sequence; the start
200
- checkpoint (sequence 0) has no block of its own, so it rides the first. */
201
- const checkpointFor = (key: number): SessionCheckpoint | undefined =>
202
- checkpoints.find((entry) => entry.sequence === key) ??
203
- (key === firstKey
204
- ? checkpoints.find((entry) => entry.sequence === 0)
205
- : undefined);
206
-
207
- /* The newest message is the one being written, so the transcript follows it. */
208
- useEffect(() => {
209
- const node = scroller.current;
210
- if (node) node.scrollTop = node.scrollHeight;
211
- }, [props.entries.length, props.running]);
212
-
213
- /* Seed the strip from the open session, and reset it when the session
214
- changes so one session's attachments never show under another. */
215
- useEffect(() => {
216
- if (!sessionId) {
217
- setAttachments([]);
218
- setPending([]);
219
- return;
220
- }
221
- let cancelled = false;
222
- void loadSession(sessionId).then((loaded) => {
223
- if (!cancelled) setAttachments(loaded.session.attachments ?? []);
224
- }).catch(() => undefined);
225
- return () => {
226
- cancelled = true;
227
- };
228
- }, [sessionId, props.running]);
229
-
230
- /* Restore points refresh when a turn ends, so the checkpoint a turn just wrote
231
- becomes offerable without leaving the session. */
232
- useEffect(() => {
233
- if (!sessionId) {
234
- setCheckpoints([]);
235
- return;
236
- }
237
- let cancelled = false;
238
- void loadSession(sessionId).then((loaded) => {
239
- if (!cancelled) setCheckpoints(loaded.session.checkpoints ?? []);
240
- }).catch(() => undefined);
241
- return () => {
242
- cancelled = true;
243
- };
244
- }, [sessionId, props.running]);
245
-
246
- const uploadFiles = (files: readonly File[]) => {
247
- if (!sessionId || files.length === 0) return;
248
- setAttachError('');
249
- for (const file of files) {
250
- const key = `${file.name}-${Date.now()}-${Math.random().toString(
251
- 36,
252
- ).slice(2, 8)}`;
253
- setPending(
254
- (current) => [
255
- ...current,
256
- {
257
- key,
258
- name: file.name,
259
- kind: attachmentKind(file),
260
- status: 'uploading',
261
- },
262
- ],
263
- );
264
- void uploadAttachment(sessionId, file).then((result) => {
265
- setAttachments((current) => [...current, result.attachment]);
266
- setPending((current) => current.filter((item) => item.key !== key));
267
- }).catch((error: unknown) => {
268
- const reason =
269
- error instanceof Error
270
- ? error.message
271
- : t('sandbox.attachments.uploadFailed');
272
- setPending(
273
- (current) => current.map(
274
- (item) => item.key === key
275
- ? { ...item, status: 'error', error: reason }
276
- : item,
277
- ),
278
- );
279
- });
280
- }
281
- };
282
-
283
- const onPaste = (event: ClipboardEvent) => {
284
- const files = event.clipboardData?.files;
285
- if (!files || files.length === 0) return;
286
- const images = Array.from(files).filter(
287
- (file) => file.type.startsWith('image/'),
288
- );
289
- if (images.length === 0) return;
290
- event.preventDefault();
291
- uploadFiles(images);
292
- };
293
-
294
- const onPick = (event: Event & { currentTarget: HTMLInputElement }) => {
295
- const chosen = event.currentTarget.files;
296
- if (chosen && chosen.length > 0) uploadFiles(Array.from(chosen));
297
- event.currentTarget.value = '';
298
- };
299
-
300
- const removeAttachment = (id: string) => {
301
- if (!sessionId) return;
302
- void deleteAttachment(sessionId, id).then(
303
- () => setAttachments(
304
- (current) => current.filter((item) => item.id !== id),
305
- ),
306
- ).catch(
307
- (error: unknown) => setAttachError(
308
- error instanceof Error
309
- ? error.message
310
- : t('sandbox.attachments.removeFailed'),
311
- ),
312
- );
313
- };
314
-
315
- const dismissPending = (key: string) => setPending(
316
- (current) => current.filter((item) => item.key !== key),
317
- );
318
-
319
- /* Restoring replaces the draft files, so a full reload lets the app re-open
320
- the session from the URL: the transcript picks up the marker and the
321
- preview nonce is bumped as the session mounts again. */
322
- const doRestore = (sequence: number) => {
323
- if (!sessionId || restoring) return;
324
- setRestoring(true);
325
- setRestoreError('');
326
- void restoreCheckpoint(sessionId, sequence).then(() => {
327
- window.location.reload();
328
- }).catch((error: unknown) => {
329
- setRestoring(false);
330
- setRestoreError(
331
- error instanceof Error
332
- ? error.message
333
- : t('sandbox.chat.restore.failed'),
334
- );
335
- });
336
- };
337
-
338
- const restoreRow = (key: number) => {
339
- const checkpoint = checkpointFor(key);
340
- if (!checkpoint || props.running) return null;
341
- return <div class="chat__restore">
342
- {confirmRestore === checkpoint.sequence
343
- ? <>
344
- <span class="chat__restore-ask">{t(
345
- 'sandbox.chat.restore.confirm',
346
- )}</span>
347
- <button
348
- class="chat__restore-go"
349
- type="button"
350
- disabled={restoring}
351
- onClick={() => doRestore(checkpoint.sequence)}
352
- >
353
- <Icon name="refresh" size={12} />
354
- {restoring
355
- ? t('sandbox.chat.restore.restoring')
356
- : t('sandbox.common.restore')}
357
- </button>
358
- <button
359
- class="chat__restore-cancel"
360
- type="button"
361
- disabled={restoring}
362
- onClick={() => setConfirmRestore(null)}
363
- >{t('sandbox.common.cancel')}</button>
364
- {restoreError
365
- ? <span class="chat__restore-error">{restoreError}</span>
366
- : null}
367
- </>
368
- : <button
369
- class="chat__restore-toggle"
370
- type="button"
371
- onClick={() => {
372
- setRestoreError('');
373
- setConfirmRestore(checkpoint.sequence);
374
- }}
375
- >
376
- <Icon name="refresh" size={12} />
377
- {checkpoint.sequence === 0
378
- ? t('sandbox.chat.restore.start')
379
- : t('sandbox.chat.restore.here')}
380
- </button>}
381
- </div>;
382
- };
383
-
384
- const submit = (event: SubmitEvent) => {
385
- event.preventDefault();
386
- props.onSend();
387
- };
388
-
389
- <section class="sandbox__chat">
390
- <div class="sandbox__scroll" ref={scroller}>
391
- <div class="chat sandbox__column">
392
- @for (const block of stream; key blockKey(block)) {
393
- @if (block.events) {
394
- <ul class="chat__events">
395
- @for (const entry of block.events; key entry.sequence) {
396
- <li
397
- class={[
398
- 'chat__event',
399
- isError(entry) && 'chat__event--error',
400
- ]}
401
- title={eventLabel(entry)}
402
- >
403
- <Icon name={isError(entry) ? 'alert' : 'check'} size={14} />
404
- <span class="chat__event-text">{eventLabel(entry)}</span>
405
- </li>
406
- }
407
- </ul>
408
- } @else if (block.entry!.handoff) {
409
- <article
410
- class={[
411
- 'chat__handoff',
412
- 'chat__handoff--' + block.entry!.handoff!.kind,
413
- ]}
414
- >
415
- <header class="chat__meta">
416
- <Icon
417
- name={handoffIcon(block.entry!.handoff!.kind)}
418
- size={14}
419
- />
420
- <span>{roleLabel(
421
- block.entry!.handoff!.role,
422
- block.entry!.handoff!.roleName,
423
- )}</span>
424
- <Tag>{handoffLabel(block.entry!.handoff!)}</Tag>
425
- {moduleLabel(block.entry!)}
426
- </header>
427
- <p class="chat__text">{t(
428
- 'sandbox.handoff.description.' + block.entry!.handoff!.kind,
429
- )}</p>
430
- @if (block.entry!.text) {
431
- <details
432
- open={block.entry!.handoff!.kind === 'question' ||
433
- block.entry!.handoff!.kind === 'blocked'}
434
- >
435
- <summary>{t('sandbox.handoff.details')}</summary>
436
- <p class="chat__text">{block.entry!.text}</p>
437
- </details>
438
- }
439
- @if (block.entry!.sequence === open && !props.running) {
440
- @if (block.entry!.handoff!.kind === 'approval') {
441
- <ApprovalHandoff
442
- handoff={block.entry!.handoff!}
443
- reviews={props.specs}
444
- busy={props.running || props.busy === true}
445
- onApprove={props.onApprove}
446
- onRequestChanges={props.onRequestChanges}
447
- onEdit={props.onEditSpec}
448
- />
449
- } @else if (block.entry!.handoff!.kind === 'continue') {
450
- <div class="ui-form__actions">
451
- <Button
452
- size="sm"
453
- variant="primary"
454
- disabled={props.busy === true}
455
- onClick={() => props.onContinue(block.entry!.handoff!)}
456
- >
457
- <Icon name="play" size={14} />
458
- {t('sandbox.chat.continueWith', {
459
- role: roleLabel(
460
- block.entry!.handoff!.role,
461
- block.entry!.handoff!.roleName,
462
- ),
463
- })}
464
- </Button>
465
- </div>
466
- }
467
- }
468
- {restoreRow(block.key)}
469
- </article>
470
- } @else {
471
- <article
472
- class={[
473
- 'chat__turn',
474
- block.entry!.kind === 'user' && 'chat__turn--user',
475
- ]}
476
- >
477
- <header class="chat__meta">
478
- <span>
479
- {block.entry!.kind === 'user'
480
- ? t('sandbox.chat.you')
481
- : roleLabel(block.entry!.role)}
482
- </span>
483
- {moduleLabel(block.entry!)}
484
- </header>
485
- <p class="chat__text">{spoken(block.entry!)}</p>
486
- {restoreRow(block.key)}
487
- </article>
488
- }
489
- }
490
- @if (props.pendingBrief && !props.running) {
491
- <article class="chat__handoff chat__handoff--continue">
492
- <header class="chat__meta">
493
- <Icon name="play" size={14} />
494
- <span>{t('sandbox.chat.notStarted')}</span>
495
- </header>
496
- <p class="chat__text">{t('sandbox.chat.pendingBrief', {
497
- brief: props.pendingBrief,
498
- })}</p>
499
- <div class="ui-form__actions">
500
- <Button size="sm" variant="primary" onClick={props.onStart}>
501
- <Icon name="play" size={14} />
502
- {t('sandbox.chat.startWork')}
503
- </Button>
504
- </div>
505
- </article>
506
- }
507
- </div>
508
- </div>
509
-
510
- <form class="chat__composer" onSubmit={submit}>
511
- @if (props.selection) {
512
- <div class="chat__selection">
513
- <b>{t('sandbox.chat.selection', {
514
- label: props.selection.label,
515
- })}</b>
516
- <span class="ui-mono">{props.selection.selector}</span>
517
- <div class="ui-form__actions">
518
- <Button
519
- size="sm"
520
- variant="ghost"
521
- onClick={props.onClearSelection}
522
- >{t('sandbox.chat.clearSelection')}</Button>
523
- </div>
524
- </div>
525
- }
526
- @if (attachments.length > 0 || pending.length > 0 || attachError) {
527
- <div class="chat__attachments">
528
- @for (const item of attachments; key item.id) {
529
- <div class="chat__attachment">
530
- @if (item.kind === 'image') {
531
- <img
532
- class="chat__attachment-thumb"
533
- src={attachmentUrl(sessionId, item.id)}
534
- alt={item.name}
535
- />
536
- } @else {
537
- <span
538
- class="chat__attachment-thumb chat__attachment-thumb--file"
539
- >
540
- <Icon name="file-text" size={18} />
541
- </span>
542
- }
543
- <span class="chat__attachment-info">
544
- <span class="chat__attachment-name">{item.name}</span>
545
- <span class="chat__attachment-size">{formatBytes(
546
- item.size,
547
- )}</span>
548
- </span>
549
- <button
550
- class="chat__attachment-remove"
551
- type="button"
552
- aria-label={t('sandbox.attachments.remove', {
553
- name: item.name,
554
- })}
555
- onClick={() => removeAttachment(item.id)}
556
- >
557
- <Icon name="x" size={12} />
558
- </button>
559
- </div>
560
- }
561
- @for (const item of pending; key item.key) {
562
- <div
563
- class={[
564
- 'chat__attachment',
565
- item.status === 'error' && 'chat__attachment--error',
566
- ]}
567
- >
568
- <span class="chat__attachment-thumb chat__attachment-thumb--file">
569
- <Icon
570
- name={item.status === 'error' ? 'alert' : 'file-text'}
571
- size={18}
572
- />
573
- </span>
574
- <span class="chat__attachment-info">
575
- <span class="chat__attachment-name">{item.name}</span>
576
- <span class="chat__attachment-size">
577
- {item.status === 'error'
578
- ? item.error ?? t('sandbox.attachments.uploadFailed')
579
- : t('sandbox.attachments.uploading')}
580
- </span>
581
- </span>
582
- <button
583
- class="chat__attachment-remove"
584
- type="button"
585
- aria-label={t('sandbox.common.dismiss')}
586
- onClick={() => dismissPending(item.key)}
587
- >
588
- <Icon name="x" size={12} />
589
- </button>
590
- </div>
591
- }
592
- @if (attachError) {
593
- <span class="chat__attachment-error">{attachError}</span>
594
- }
595
- </div>
596
- }
597
- <textarea
598
- class="ui-textarea"
599
- rows={3}
600
- placeholder={t('sandbox.chat.placeholder')}
601
- value={props.message}
602
- onInput={(event) => props.onMessage(event.currentTarget.value)}
603
- onPaste={onPaste}
604
- ></textarea>
605
- <div class="chat__composer-row">
606
- <button
607
- class="chat__attach"
608
- type="button"
609
- aria-label={t('sandbox.attachments.action')}
610
- title={t('sandbox.attachments.help')}
611
- disabled={!sessionId}
612
- onClick={() => attachInput.current?.click()}
613
- >
614
- <Icon name="plus" size={16} />
615
- </button>
616
- <input
617
- ref={attachInput}
618
- class="chat__attach-input"
619
- type="file"
620
- multiple
621
- accept={ATTACH_ACCEPT}
622
- onChange={onPick}
623
- />
624
- <select
625
- class="chat__picker"
626
- aria-label={t('sandbox.chat.role')}
627
- value={props.role}
628
- onChange={(event) => props.onRole(event.currentTarget.value)}
629
- >
630
- <option value="auto">{t('sandbox.chat.auto')}</option>
631
- @for (const role of props.roles; key role.id) {
632
- <option value={role.id}>{roleLabel(role.id, role.name)}</option>
633
- }
634
- </select>
635
- @if (props.modules.length > 1) {
636
- <select
637
- class="chat__picker"
638
- aria-label={t('sandbox.chat.targetModule')}
639
- value={props.module}
640
- onChange={(event) => props.onModule(event.currentTarget.value)}
641
- >
642
- <option value="">{t('sandbox.chat.auto')}</option>
643
- @for (const module of props.modules; key module.id) {
644
- <option value={module.directory}>{module.id}</option>
645
- }
646
- </select>
647
- }
648
- <select
649
- class="chat__picker"
650
- aria-label={t('sandbox.sessions.driver.label')}
651
- value={props.driver}
652
- onChange={(event) => props.onDriver(event.currentTarget.value)}
653
- >
654
- @for (const driver of offered; key driver.id) {
655
- <option value={driver.id}>{driver.label}</option>
656
- }
657
- </select>
658
- <label class="chat__auto">
659
- <input
660
- type="checkbox"
661
- checked={props.autoContinue}
662
- onInput={(event) => props.onAutoContinue(
663
- event.currentTarget.checked,
664
- )}
665
- />
666
- <span>{t('sandbox.chat.autoHandoff')}</span>
667
- </label>
668
- <span class="sandbox__spacer"></span>
669
- @if (props.running) {
670
- <Button size="sm" variant="danger" onClick={props.onStop}>{t(
671
- 'sandbox.chat.stop',
672
- )}</Button>
673
- } @else {
674
- <Button
675
- size="sm"
676
- variant="primary"
677
- type="submit"
678
- disabled={props.message.trim().length === 0}
679
- >
680
- <Icon name="play" size={14} />
681
- {t('sandbox.chat.send')}
682
- </Button>
683
- }
684
- </div>
685
- @if (props.running || props.delivered) {
686
- <p class="chat__composer-status">
687
- {props.running
688
- ? t('sandbox.chat.working')
689
- : t('sandbox.chat.delivered')}
690
- </p>
691
- }
692
- </form>
693
- </section>
694
- }