ima2-gen 3.15.0 → 3.15.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 (52) hide show
  1. package/README.md +1 -1
  2. package/bin/commands/video.js +6 -4
  3. package/docs/API.md +1 -1
  4. package/docs/API.zh-CN.md +1 -1
  5. package/docs/API.zh-TW.md +1 -1
  6. package/docs/CLI.md +1 -1
  7. package/docs/CLI.zh-CN.md +1 -1
  8. package/docs/CLI.zh-TW.md +1 -1
  9. package/docs/README.ja.md +1 -1
  10. package/docs/README.ko.md +2 -2
  11. package/docs/README.zh-CN.md +1 -1
  12. package/docs/README.zh-TW.md +1 -1
  13. package/docs/grok-video-i2v-research.md +1 -1
  14. package/docs/grok-video-i2v-research.zh-CN.md +1 -1
  15. package/docs/grok-video-i2v-research.zh-TW.md +1 -1
  16. package/docs/migration/runtime-test-inventory.md +5 -1
  17. package/lib/capabilities.js +33 -7
  18. package/lib/grokVideoAdapter.js +9 -4
  19. package/lib/imageModels.js +81 -8
  20. package/lib/providers/registry.js +11 -4
  21. package/package.json +2 -2
  22. package/routes/video.js +30 -15
  23. package/routes/videoExtended.js +8 -3
  24. package/skills/ima2/SKILL.md +25 -14
  25. package/ui/dist/.vite/manifest.json +61 -61
  26. package/ui/dist/assets/{AgentWorkspace-BulKz33A.js → AgentWorkspace-CLJDCRMQ.js} +1 -1
  27. package/ui/dist/assets/App-DkvU6Sex.js +9 -0
  28. package/ui/dist/assets/{AssetGenWorkspace-8SYhS2Y2.js → AssetGenWorkspace-BepUrz23.js} +2 -2
  29. package/ui/dist/assets/{AssetsWorkspace-Dxz-Xksp.js → AssetsWorkspace-IipC1FdD.js} +1 -1
  30. package/ui/dist/assets/{CardNewsWorkspace-DV4hpvKf.js → CardNewsWorkspace-ZXDwYz4l.js} +1 -1
  31. package/ui/dist/assets/{GenerationRequestLogPanel-VFu4cAdd.js → GenerationRequestLogPanel-BL2C0DcW.js} +1 -1
  32. package/ui/dist/assets/{HomeWorkspace-D1UBgwRZ.js → HomeWorkspace-DFfrwS9a.js} +1 -1
  33. package/ui/dist/assets/{KeyingPanel-GdUcaaJR.js → KeyingPanel-BQkEMTe9.js} +1 -1
  34. package/ui/dist/assets/{NodeCanvas-B6zoJhHr.js → NodeCanvas-5u8IO1MA.js} +1 -1
  35. package/ui/dist/assets/{PromptBuilderPanel-CJ56MEk2.js → PromptBuilderPanel-DNt7LHMi.js} +1 -1
  36. package/ui/dist/assets/{PromptImportDialog-DMFnggIT.js → PromptImportDialog-Bl-SB4mK.js} +2 -2
  37. package/ui/dist/assets/{PromptImportDiscoverySection-4KCIWmZ8.js → PromptImportDiscoverySection-DdZAdRMW.js} +1 -1
  38. package/ui/dist/assets/{PromptImportFolderSection-BjqopFX5.js → PromptImportFolderSection-DLHQKl9T.js} +1 -1
  39. package/ui/dist/assets/{PromptLibraryPanel-DwFK4ALC.js → PromptLibraryPanel-PLWyvEz1.js} +2 -2
  40. package/ui/dist/assets/{SettingsWorkspace-BWcNnQ56.js → SettingsWorkspace-Etfeu2IF.js} +1 -1
  41. package/ui/dist/assets/{SpriteRecipeWorkspace-Bsl_NZ3A.js → SpriteRecipeWorkspace-D7H5seOM.js} +1 -1
  42. package/ui/dist/assets/{index-BWzT2RyM.js → index-BAkbTbUC.js} +3 -3
  43. package/ui/dist/assets/index-D0NhOovz.css +1 -0
  44. package/ui/dist/assets/index-DYtUJ4t0.js +22 -0
  45. package/ui/dist/assets/{pptxgen.es-BslswdiL.js → pptxgen.es-Apxh5DQ9.js} +1 -1
  46. package/ui/dist/assets/{promptBuilderStore-Cl2q0Oe6.js → promptBuilderStore-prvdLIUP.js} +1 -1
  47. package/ui/dist/assets/useAgentDialogFocus-B2snKbzK.js +1 -0
  48. package/ui/dist/index.html +2 -2
  49. package/ui/dist/assets/App-juOjrIgh.js +0 -9
  50. package/ui/dist/assets/index-C5zSMtGM.css +0 -1
  51. package/ui/dist/assets/index-Cl5SnWLL.js +0 -22
  52. package/ui/dist/assets/useAgentDialogFocus-B8niAv4W.js +0 -1
@@ -12,7 +12,7 @@ import { finishJob, INFLIGHT_RETRY_AFTER_SECONDS, isJobCanceled, isStartJobFailu
12
12
  import { makeGenerationCanceledError } from "../lib/generationCancel.js";
13
13
  import { publishJobEvent } from "../lib/ssePublish.js";
14
14
  import { normalizeBodyRequestId } from "../lib/generationInputValidation.js";
15
- import { normalizeGrokVideoModel, normalizeVideoAspectRatio, normalizeVideoDuration, normalizeVideoResolution, validateVideoResolutionForRequest } from "../lib/imageModels.js";
15
+ import { MAX_VIDEO_DURATION, MIN_VIDEO_DURATION, normalizeGrokVideoModel, normalizeVideoAspectRatio, normalizeVideoDuration, normalizeVideoResolution, validateVideoResolutionForRequest } from "../lib/imageModels.js";
16
16
  import { persistVideoArtifact } from "../lib/videoArtifactPersistence.js";
17
17
  import { normalizeVideoLineage } from "../lib/videoLineage.js";
18
18
  import { getMotionFragment, MOTION_PRESETS } from "../lib/videoMotionPresets.js";
@@ -329,8 +329,13 @@ export function registerVideoExtendedRoutes(app, ctxRaw, dependencies = {}) {
329
329
  return res.status(400).json({ error: "videoUrl required" });
330
330
  const validModel = validateEditModel(model);
331
331
  const dur = Number(duration);
332
- if (!Number.isInteger(dur) || dur < 2 || dur > 10)
333
- return res.status(400).json({ error: "duration must be an integer between 2 and 10" });
332
+ // xAI documents 2-10 for extensions, but the endpoint accepts 1 and 11 and refuses
333
+ // only 0 and 16 — the same 1-15 bound as generation. Enforcing the documented range
334
+ // would refuse extensions the API would have produced.
335
+ // devlog/_plan/260908_xai_imagine_spec_resync/000_research.md (D11)
336
+ if (!Number.isInteger(dur) || dur < MIN_VIDEO_DURATION || dur > MAX_VIDEO_DURATION) {
337
+ return res.status(400).json({ error: `duration must be an integer between ${MIN_VIDEO_DURATION} and ${MAX_VIDEO_DURATION}` });
338
+ }
334
339
  const signal = requestSignal(req, res, envDeadline("IMA2_VIDEO_EXTEND_TIMEOUT_MS", 10 * 60_000));
335
340
  const { url, headers } = videoProxyUrl(ctx, "/v1/videos/extensions");
336
341
  const video = await resolveVideoInput(ctx, videoUrl);
@@ -905,7 +905,10 @@ what was asked for.
905
905
  | 0 | text-to-video | 15s |
906
906
  | 1 | image-to-video (default) | 15s |
907
907
  | 1 + `--as-reference` | reference-to-video | 15s |
908
- | 2-7 | reference-to-video | 15s |
908
+ | 2-14 | reference-to-video | 15s |
909
+
910
+ Reference-to-video's ceiling depends on the model: 15s on `grok-imagine-video-1.5`,
911
+ 10s on `grok-imagine-video`. The rows above assume 1.5, which is the default.
909
912
 
910
913
  One image is ambiguous and only the caller knows the intent, so it is a choice rather
911
914
  than a deduction. **image-to-video** locks that image as the opening frame and animates
@@ -1045,7 +1048,7 @@ Generate a high-quality still image first, then animate it. This produces better
1045
1048
 
1046
1049
  | Scenario | Use | Why |
1047
1050
  |----------|-----|-----|
1048
- | Need 2+ character identity lock from separate refs | ref2v (`grok-imagine-video-1.5`, max 7 refs, up to 15s, 720p) | Refs lock character appearance |
1051
+ | Need 2+ character identity lock from separate refs | ref2v (`grok-imagine-video-1.5`, max 14 refs, up to 15s, 720p) | Refs lock character appearance |
1049
1052
  | Single composed scene with all elements | i2v (`grok-imagine-video-1.5`, 1 ref) | Better motion quality from composed start |
1050
1053
  | One subject, but a brand new setting | ref2v with one ref (`--as-reference`) | Keeps the subject without reproducing the source shot |
1051
1054
  | Continue from previous video | `video continue` (last frame as i2v ref) | Lineage metadata preserved |
@@ -1236,13 +1239,18 @@ done
1236
1239
 
1237
1240
  ### Limitations
1238
1241
 
1239
- - Max 15 seconds per clip (extend adds 2-10s more)
1240
- - Reference-to-video: 1-7 refs, up to 15 seconds, 720p ceiling. The 10-second clamp this
1241
- section used to describe was ours, not xAI's, and was removed in v3.8.0 (issue #155)
1242
+ - Max 15 seconds per clip (extend adds 1-15s more)
1243
+ - Reference-to-video: 1-14 refs, 720p ceiling. Duration is 15 seconds on
1244
+ `grok-imagine-video-1.5` and 10 seconds on `grok-imagine-video` — xAI's own rule,
1245
+ measured 2026-09-08. Do not confuse it with the mode-wide 10-second clamp removed in
1246
+ v3.8.0 (issue #155): that one was ours and applied to every model
1247
+ - A preset voice with no reference image also selects reference-to-video
1242
1248
  - 1080p resolution is available for `grok-imagine-video-1.5` prompt-only text-to-video via the white-canvas I2V shim, and for image-to-video with a single image/frame source
1243
1249
  - Video edit/extend: grok-imagine-video only (1.5 is not supported)
1244
- - Video edit input: max 8.7 seconds
1245
- - Video extend input: 2-15 seconds; extension duration: 2-10 seconds
1250
+ - Video edit input: ~8.7 seconds is our own measured practical ceiling, not a limit xAI enforces
1251
+ - Video extend: extension duration 1-15 seconds, and it is the length of the ADDED
1252
+ segment, not the total. xAI's docs say 2-10; live probing accepts 1 and 11 and
1253
+ rejects 0 and 16
1246
1254
 
1247
1255
  #### Provenance of the limits above
1248
1256
 
@@ -1263,10 +1271,13 @@ mixed in this section, and they age differently.
1263
1271
  | `grok-imagine-video-1.5` + `/v1/videos/extensions` | `400 "Video extension is not supported for this model."` |
1264
1272
  | `grok-imagine-video` (base) + edit / extend | `200` → `done` (both work) |
1265
1273
  | Edit `duration` / `resolution` overrides | Accepted with `200` but **silently ignored** — output inherits the source video's properties, capped at 720p |
1266
- | Extension `duration` outside 2-10 | Returns `200` with a `request_id`, then **fails asynchronously** on poll: `"Duration must be between 2 and 10 seconds"`. Validate before sending; a 200 here does not mean accepted. |
1267
- | R2V reference count | 7 max; 8 → `400 "Too many reference images: 8. Maximum allowed is 7."` |
1274
+ | Extension `duration` | 1-15 accepted (1, 2, 10 and 11 all return `200`); 0 and 16 return `400 "Duration must be between 1 and 15 seconds"`. xAI's docs say 2-10 — the docs are narrower than the endpoint (re-measured 2026-09-08). |
1275
+ | R2V reference count | 14 max; 15 → `400 "Too many reference images: 15. Maximum allowed is 14."` on both models. Was 7 until xAI doubled it; @imagine announced 14 on 2026-09-02 and the API guide still says 7. |
1276
+ | R2V duration on `grok-imagine-video` | 10s max; 11 → `400 "Duration 11s exceeds the maximum allowed for reference-to-video, which is 10s."` |
1277
+ | `reference_audios` on `grok-imagine-video` | `400 "reference_audios is not supported for this model."` — voices need 1.5 |
1278
+ | Audio-only R2V (voice, no images) | Accepted; a voice alone selects reference-to-video and the r2v duration ceiling applies |
1268
1279
  | R2V + 1080p | `400 "1080p video resolution is not supported for reference-to-video requests."` |
1269
- | R2V duration 15 | `200` → `done`, `video.duration=15` (this is why the old 10s clamp was removed) |
1280
+ | R2V duration 15 on 1.5 | `200` → `done`, `video.duration=15`. The mode-wide 10s clamp removed in v3.8.0 was ours; the base model's 10s above is xAI's |
1270
1281
  | R2V with a single reference image | Accepted (`200`) — 2+ is an ima2 convention, not an API requirement |
1271
1282
  | `reference_audios: [{"voice_id": "eve"}]` on 1.5 | `200` → `done` (preset voices work; up to 3) |
1272
1283
  | Rate limit | 2 requests/second per team; exceeding it returns `429` |
@@ -1303,11 +1314,11 @@ outside the generated directory.
1303
1314
 
1304
1315
  Extend a video from its last frame using xAI's video extension endpoint. The output combines the source video and extension, but continuity quality is provider-dependent.
1305
1316
 
1306
- Constraints: grok-imagine-video only, extension duration 2-10s. `grok-imagine-video-1.5`
1307
- returns `400 "Video extension is not supported for this model."` (verified 2026-08-20).
1317
+ Constraints: grok-imagine-video only, extension duration 1-15s. `grok-imagine-video-1.5`
1318
+ returns `400 "Video extension is not supported for this model."` (re-verified 2026-09-08).
1308
1319
  `duration` is the length of the **appended segment**, not the total: a 10s source with
1309
- `duration: 5` returns a 15s video. Out-of-range durations return `200` and then fail
1310
- asynchronously on poll, so validate before sending.
1320
+ `duration: 5` returns a 15s video. xAI's docs say the range is 2-10; live probing accepts
1321
+ 1 and 11 and refuses only 0 and 16, so the range above is the measured one.
1311
1322
 
1312
1323
  ```bash
1313
1324
  # Generate initial clip
@@ -1,6 +1,6 @@
1
1
  {
2
- "_App-juOjrIgh.js": {
3
- "file": "assets/App-juOjrIgh.js",
2
+ "_App-DkvU6Sex.js": {
3
+ "file": "assets/App-DkvU6Sex.js",
4
4
  "name": "App",
5
5
  "isDynamicEntry": true,
6
6
  "imports": [
@@ -17,19 +17,23 @@
17
17
  "src/components/card-news/CardNewsWorkspace.tsx",
18
18
  "src/components/agent/AgentWorkspace.tsx",
19
19
  "src/components/assets/AssetsWorkspace.tsx",
20
- "_AssetGenWorkspace-8SYhS2Y2.js",
20
+ "_AssetGenWorkspace-BepUrz23.js",
21
21
  "src/components/home/HomeWorkspace.tsx",
22
22
  "src/components/PromptLibraryPanel.tsx"
23
23
  ]
24
24
  },
25
- "_AssetGenWorkspace-8SYhS2Y2.js": {
26
- "file": "assets/AssetGenWorkspace-8SYhS2Y2.js",
25
+ "_AssetGenWorkspace-B7tTK0Sx.css": {
26
+ "file": "assets/AssetGenWorkspace-B7tTK0Sx.css",
27
+ "src": "_AssetGenWorkspace-B7tTK0Sx.css"
28
+ },
29
+ "_AssetGenWorkspace-BepUrz23.js": {
30
+ "file": "assets/AssetGenWorkspace-BepUrz23.js",
27
31
  "name": "AssetGenWorkspace",
28
32
  "isDynamicEntry": true,
29
33
  "imports": [
30
34
  "index.html",
31
- "_App-juOjrIgh.js",
32
- "_KeyingPanel-GdUcaaJR.js"
35
+ "_App-DkvU6Sex.js",
36
+ "_KeyingPanel-BQkEMTe9.js"
33
37
  ],
34
38
  "dynamicImports": [
35
39
  "src/components/assetgen/SpriteRecipeWorkspace.tsx"
@@ -38,17 +42,13 @@
38
42
  "assets/AssetGenWorkspace-B7tTK0Sx.css"
39
43
  ]
40
44
  },
41
- "_AssetGenWorkspace-B7tTK0Sx.css": {
42
- "file": "assets/AssetGenWorkspace-B7tTK0Sx.css",
43
- "src": "_AssetGenWorkspace-B7tTK0Sx.css"
44
- },
45
- "_KeyingPanel-GdUcaaJR.js": {
46
- "file": "assets/KeyingPanel-GdUcaaJR.js",
45
+ "_KeyingPanel-BQkEMTe9.js": {
46
+ "file": "assets/KeyingPanel-BQkEMTe9.js",
47
47
  "name": "KeyingPanel",
48
48
  "imports": [
49
49
  "index.html",
50
- "_App-juOjrIgh.js",
51
- "_useAgentDialogFocus-B8niAv4W.js"
50
+ "_App-DkvU6Sex.js",
51
+ "_useAgentDialogFocus-B2snKbzK.js"
52
52
  ]
53
53
  },
54
54
  "__vite-browser-external": {
@@ -57,34 +57,34 @@
57
57
  "src": "__vite-browser-external",
58
58
  "isDynamicEntry": true
59
59
  },
60
- "_promptBuilderStore-Cl2q0Oe6.js": {
61
- "file": "assets/promptBuilderStore-Cl2q0Oe6.js",
60
+ "_promptBuilderStore-prvdLIUP.js": {
61
+ "file": "assets/promptBuilderStore-prvdLIUP.js",
62
62
  "name": "promptBuilderStore",
63
63
  "imports": [
64
- "_App-juOjrIgh.js"
64
+ "_App-DkvU6Sex.js"
65
65
  ]
66
66
  },
67
- "_useAgentDialogFocus-B8niAv4W.js": {
68
- "file": "assets/useAgentDialogFocus-B8niAv4W.js",
67
+ "_useAgentDialogFocus-B2snKbzK.js": {
68
+ "file": "assets/useAgentDialogFocus-B2snKbzK.js",
69
69
  "name": "useAgentDialogFocus",
70
70
  "imports": [
71
- "_App-juOjrIgh.js"
71
+ "_App-DkvU6Sex.js"
72
72
  ]
73
73
  },
74
74
  "index.html": {
75
- "file": "assets/index-Cl5SnWLL.js",
75
+ "file": "assets/index-DYtUJ4t0.js",
76
76
  "name": "index",
77
77
  "src": "index.html",
78
78
  "isEntry": true,
79
79
  "dynamicImports": [
80
- "_App-juOjrIgh.js"
80
+ "_App-DkvU6Sex.js"
81
81
  ],
82
82
  "css": [
83
- "assets/index-C5zSMtGM.css"
83
+ "assets/index-D0NhOovz.css"
84
84
  ]
85
85
  },
86
86
  "node_modules/pptxgenjs/dist/pptxgen.es.js": {
87
- "file": "assets/pptxgen.es-BslswdiL.js",
87
+ "file": "assets/pptxgen.es-Apxh5DQ9.js",
88
88
  "name": "pptxgen.es",
89
89
  "src": "node_modules/pptxgenjs/dist/pptxgen.es.js",
90
90
  "isDynamicEntry": true,
@@ -98,36 +98,36 @@
98
98
  ]
99
99
  },
100
100
  "src/components/GenerationRequestLogPanel.tsx": {
101
- "file": "assets/GenerationRequestLogPanel-VFu4cAdd.js",
101
+ "file": "assets/GenerationRequestLogPanel-BL2C0DcW.js",
102
102
  "name": "GenerationRequestLogPanel",
103
103
  "src": "src/components/GenerationRequestLogPanel.tsx",
104
104
  "isDynamicEntry": true,
105
105
  "imports": [
106
106
  "index.html",
107
- "_App-juOjrIgh.js"
107
+ "_App-DkvU6Sex.js"
108
108
  ]
109
109
  },
110
110
  "src/components/NodeCanvas.tsx": {
111
- "file": "assets/NodeCanvas-B6zoJhHr.js",
111
+ "file": "assets/NodeCanvas-5u8IO1MA.js",
112
112
  "name": "NodeCanvas",
113
113
  "src": "src/components/NodeCanvas.tsx",
114
114
  "isDynamicEntry": true,
115
115
  "imports": [
116
116
  "index.html",
117
- "_App-juOjrIgh.js"
117
+ "_App-DkvU6Sex.js"
118
118
  ],
119
119
  "css": [
120
120
  "assets/NodeCanvas-BnuhLJ6X.css"
121
121
  ]
122
122
  },
123
123
  "src/components/PromptImportDialog.tsx": {
124
- "file": "assets/PromptImportDialog-DMFnggIT.js",
124
+ "file": "assets/PromptImportDialog-Bl-SB4mK.js",
125
125
  "name": "PromptImportDialog",
126
126
  "src": "src/components/PromptImportDialog.tsx",
127
127
  "isDynamicEntry": true,
128
128
  "imports": [
129
129
  "index.html",
130
- "_App-juOjrIgh.js"
130
+ "_App-DkvU6Sex.js"
131
131
  ],
132
132
  "dynamicImports": [
133
133
  "src/components/PromptImportDiscoverySection.tsx",
@@ -135,130 +135,130 @@
135
135
  ]
136
136
  },
137
137
  "src/components/PromptImportDiscoverySection.tsx": {
138
- "file": "assets/PromptImportDiscoverySection-4KCIWmZ8.js",
138
+ "file": "assets/PromptImportDiscoverySection-DdZAdRMW.js",
139
139
  "name": "PromptImportDiscoverySection",
140
140
  "src": "src/components/PromptImportDiscoverySection.tsx",
141
141
  "isDynamicEntry": true,
142
142
  "imports": [
143
143
  "index.html",
144
- "_App-juOjrIgh.js"
144
+ "_App-DkvU6Sex.js"
145
145
  ]
146
146
  },
147
147
  "src/components/PromptImportFolderSection.tsx": {
148
- "file": "assets/PromptImportFolderSection-BjqopFX5.js",
148
+ "file": "assets/PromptImportFolderSection-DLHQKl9T.js",
149
149
  "name": "PromptImportFolderSection",
150
150
  "src": "src/components/PromptImportFolderSection.tsx",
151
151
  "isDynamicEntry": true,
152
152
  "imports": [
153
153
  "index.html",
154
- "_App-juOjrIgh.js"
154
+ "_App-DkvU6Sex.js"
155
155
  ]
156
156
  },
157
157
  "src/components/PromptLibraryPanel.tsx": {
158
- "file": "assets/PromptLibraryPanel-DwFK4ALC.js",
158
+ "file": "assets/PromptLibraryPanel-PLWyvEz1.js",
159
159
  "name": "PromptLibraryPanel",
160
160
  "src": "src/components/PromptLibraryPanel.tsx",
161
161
  "isDynamicEntry": true,
162
162
  "imports": [
163
163
  "index.html",
164
- "_App-juOjrIgh.js"
164
+ "_App-DkvU6Sex.js"
165
165
  ],
166
166
  "dynamicImports": [
167
167
  "src/components/PromptImportDialog.tsx"
168
168
  ]
169
169
  },
170
170
  "src/components/SettingsWorkspace.tsx": {
171
- "file": "assets/SettingsWorkspace-BWcNnQ56.js",
171
+ "file": "assets/SettingsWorkspace-Etfeu2IF.js",
172
172
  "name": "SettingsWorkspace",
173
173
  "src": "src/components/SettingsWorkspace.tsx",
174
174
  "isDynamicEntry": true,
175
175
  "imports": [
176
176
  "index.html",
177
- "_App-juOjrIgh.js",
178
- "_promptBuilderStore-Cl2q0Oe6.js"
177
+ "_App-DkvU6Sex.js",
178
+ "_promptBuilderStore-prvdLIUP.js"
179
179
  ]
180
180
  },
181
181
  "src/components/agent/AgentWorkspace.tsx": {
182
- "file": "assets/AgentWorkspace-BulKz33A.js",
182
+ "file": "assets/AgentWorkspace-CLJDCRMQ.js",
183
183
  "name": "AgentWorkspace",
184
184
  "src": "src/components/agent/AgentWorkspace.tsx",
185
185
  "isDynamicEntry": true,
186
186
  "imports": [
187
187
  "index.html",
188
- "_App-juOjrIgh.js",
189
- "_useAgentDialogFocus-B8niAv4W.js"
188
+ "_App-DkvU6Sex.js",
189
+ "_useAgentDialogFocus-B2snKbzK.js"
190
190
  ]
191
191
  },
192
192
  "src/components/assetgen/SpriteRecipeWorkspace.tsx": {
193
- "file": "assets/SpriteRecipeWorkspace-Bsl_NZ3A.js",
193
+ "file": "assets/SpriteRecipeWorkspace-D7H5seOM.js",
194
194
  "name": "SpriteRecipeWorkspace",
195
195
  "src": "src/components/assetgen/SpriteRecipeWorkspace.tsx",
196
196
  "isDynamicEntry": true,
197
197
  "imports": [
198
198
  "index.html",
199
- "_App-juOjrIgh.js",
200
- "_AssetGenWorkspace-8SYhS2Y2.js",
201
- "_KeyingPanel-GdUcaaJR.js",
202
- "_useAgentDialogFocus-B8niAv4W.js"
199
+ "_App-DkvU6Sex.js",
200
+ "_AssetGenWorkspace-BepUrz23.js",
201
+ "_KeyingPanel-BQkEMTe9.js",
202
+ "_useAgentDialogFocus-B2snKbzK.js"
203
203
  ]
204
204
  },
205
205
  "src/components/assets/AssetsWorkspace.tsx": {
206
- "file": "assets/AssetsWorkspace-Dxz-Xksp.js",
206
+ "file": "assets/AssetsWorkspace-IipC1FdD.js",
207
207
  "name": "AssetsWorkspace",
208
208
  "src": "src/components/assets/AssetsWorkspace.tsx",
209
209
  "isDynamicEntry": true,
210
210
  "imports": [
211
211
  "index.html",
212
- "_App-juOjrIgh.js",
213
- "_KeyingPanel-GdUcaaJR.js",
214
- "_useAgentDialogFocus-B8niAv4W.js"
212
+ "_App-DkvU6Sex.js",
213
+ "_KeyingPanel-BQkEMTe9.js",
214
+ "_useAgentDialogFocus-B2snKbzK.js"
215
215
  ],
216
216
  "css": [
217
217
  "assets/AssetsWorkspace-BdptASFf.css"
218
218
  ]
219
219
  },
220
220
  "src/components/canvas-mode/index.ts": {
221
- "file": "assets/index-BWzT2RyM.js",
221
+ "file": "assets/index-BAkbTbUC.js",
222
222
  "name": "index",
223
223
  "src": "src/components/canvas-mode/index.ts",
224
224
  "isDynamicEntry": true,
225
225
  "imports": [
226
226
  "index.html",
227
- "_App-juOjrIgh.js"
227
+ "_App-DkvU6Sex.js"
228
228
  ],
229
229
  "dynamicImports": [
230
230
  "node_modules/pptxgenjs/dist/pptxgen.es.js"
231
231
  ]
232
232
  },
233
233
  "src/components/card-news/CardNewsWorkspace.tsx": {
234
- "file": "assets/CardNewsWorkspace-DV4hpvKf.js",
234
+ "file": "assets/CardNewsWorkspace-ZXDwYz4l.js",
235
235
  "name": "CardNewsWorkspace",
236
236
  "src": "src/components/card-news/CardNewsWorkspace.tsx",
237
237
  "isDynamicEntry": true,
238
238
  "imports": [
239
239
  "index.html",
240
- "_App-juOjrIgh.js"
240
+ "_App-DkvU6Sex.js"
241
241
  ]
242
242
  },
243
243
  "src/components/home/HomeWorkspace.tsx": {
244
- "file": "assets/HomeWorkspace-D1UBgwRZ.js",
244
+ "file": "assets/HomeWorkspace-DFfrwS9a.js",
245
245
  "name": "HomeWorkspace",
246
246
  "src": "src/components/home/HomeWorkspace.tsx",
247
247
  "isDynamicEntry": true,
248
248
  "imports": [
249
249
  "index.html",
250
- "_App-juOjrIgh.js"
250
+ "_App-DkvU6Sex.js"
251
251
  ]
252
252
  },
253
253
  "src/components/prompt-builder/PromptBuilderPanel.tsx": {
254
- "file": "assets/PromptBuilderPanel-CJ56MEk2.js",
254
+ "file": "assets/PromptBuilderPanel-DNt7LHMi.js",
255
255
  "name": "PromptBuilderPanel",
256
256
  "src": "src/components/prompt-builder/PromptBuilderPanel.tsx",
257
257
  "isDynamicEntry": true,
258
258
  "imports": [
259
259
  "index.html",
260
- "_App-juOjrIgh.js",
261
- "_promptBuilderStore-Cl2q0Oe6.js"
260
+ "_App-DkvU6Sex.js",
261
+ "_promptBuilderStore-prvdLIUP.js"
262
262
  ]
263
263
  }
264
264
  }
@@ -1,3 +1,3 @@
1
- import{f as m,j as t}from"./index-Cl5SnWLL.js";import{q as Nt,T as Fe,u as x,i as we,R as ye,X as Ct,a as E}from"./App-juOjrIgh.js";import{u as de}from"./useAgentDialogFocus-B8niAv4W.js";async function B(e,n){const a=await Nt(e,n);if(!a.ok){const s=await a.json().catch(()=>({})),r=s.error,l=typeof r=="string"?r:r?.message??`Request failed: ${a.status}`,o=new Error(l);throw o.status=a.status,o.code=typeof r=="object"?r?.code:s.code,o}return await a.json()}function kt(e){return e.filename?`/generated/${e.filename}`:typeof e.url=="string"&&e.url?e.url:typeof e.thumb=="string"&&e.thumb?e.thumb:null}function Ge(e){const n=kt(e);if(!n)return null;const a=e.filename??e.canvasEditableFilename??"current-image.png";return{id:`current-${a}`,filename:a,url:n,thumbUrl:e.thumb??n,prompt:e.prompt??e.userPrompt??null,revisedPrompt:e.revisedPrompt??null,createdAt:e.createdAt??Date.now()}}async function Re(e){const n=e?`?selectedSessionId=${encodeURIComponent(e)}`:"";return B(`/api/agent/sessions${n}`)}async function $e(e){const n=e.currentImage?Ge(e.currentImage):null;return B("/api/agent/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e.title,currentImage:n,webSearchEnabled:e.webSearchEnabled??!0})})}async function ce(e,n){return B(`/api/agent/sessions/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})}async function It(e){return B(`/api/agent/sessions/${encodeURIComponent(e)}`,{method:"DELETE"})}async function At(e,n,a){return B(`/api/agent/sessions/${encodeURIComponent(e)}/queue`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:n,options:a})})}async function Tt(e){return B(`/api/agent/queue/${encodeURIComponent(e)}/cancel`,{method:"POST"})}async function Lt(e){return B(`/api/agent/queue/${encodeURIComponent(e)}/retry`,{method:"POST"})}const _e=Fe,Mt=Fe,Et={provider:"oauth",model:"gpt-5.6-luna",quality:"medium",size:"1024x1024",format:"png",moderation:"low",reasoningEffort:"none",webSearchEnabled:!0,generationStrategy:"auto",variants:1,maxAutoVariants:_e,parallelism:2};function Pe(e){return{...Et,...e??{}}}function De(e){const{width:n,height:a}=e;return n>=1280?"desktop-three-pane":a<560&&n<1280?n>=768?"tablet-stacked":"mobile-chat-image-sheet":n>=960&&a>=560?"desktop-rail":n>=768&&a>=700?"tablet-stacked":"mobile-chat-image-sheet"}function qt(){return typeof window>"u"?1440:window.innerWidth}function Be(){return typeof window>"u"?900:window.innerHeight}function Rt(){if(typeof window>"u"||typeof document>"u")return 1440;const e=document.querySelector('.app[data-ui-mode="agent"] .sidebar');if(!e)return window.innerWidth;const n=window.getComputedStyle(e);if(n.display==="none"||n.visibility==="hidden")return window.innerWidth;const a=e.getBoundingClientRect().width;return Math.max(0,window.innerWidth-a)}function $t(){const[e,n]=m.useState(()=>De({width:qt(),height:Be()}));return m.useEffect(()=>{const a=()=>n(De({width:Rt(),height:Be()}));return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),e}function C({size:e=16,children:n}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:n})}function Ue(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M12 5v14"}),t.jsx("path",{d:"M5 12h14"})]})}function Pt(e){return t.jsxs(C,{...e,children:[t.jsx("circle",{cx:"11",cy:"11",r:"7"}),t.jsx("path",{d:"M21 21l-4.3-4.3"})]})}function O(e){return t.jsxs(C,{...e,children:[t.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),t.jsx("circle",{cx:"8",cy:"10",r:"1.5"}),t.jsx("path",{d:"M21 16l-5-5L5 19"})]})}function ge(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M18 6L6 18"}),t.jsx("path",{d:"M6 6l12 12"})]})}function Dt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M22 2L11 13"}),t.jsx("path",{d:"M22 2l-7 20-4-9-9-4 20-7z"})]})}function Bt(e){return t.jsx(C,{...e,children:t.jsx("path",{d:"M21.4 11.1l-9.2 9.1a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5"})})}function Ot(e){return t.jsxs(C,{...e,children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("path",{d:"M2 12h20"}),t.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 0 20"}),t.jsx("path",{d:"M12 2a15.3 15.3 0 0 0 0 20"})]})}function He(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M4 6h16"}),t.jsx("path",{d:"M4 12h16"}),t.jsx("path",{d:"M4 18h16"})]})}function zt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M19 12H5"}),t.jsx("path",{d:"M12 19l-7-7 7-7"})]})}function Wt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M8 6h13"}),t.jsx("path",{d:"M8 12h13"}),t.jsx("path",{d:"M8 18h13"}),t.jsx("circle",{cx:"3",cy:"6",r:"1"}),t.jsx("circle",{cx:"3",cy:"12",r:"1"}),t.jsx("circle",{cx:"3",cy:"18",r:"1"})]})}function Kt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M3 6h18"}),t.jsx("path",{d:"M8 6V4h8v2"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"})]})}function Qt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M12 20h9"}),t.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]})}function Ve(e){return t.jsx(C,{...e,children:t.jsx("path",{d:"M6 9l6 6 6-6"})})}function Ne(e){return t.jsx(C,{...e,children:t.jsx("path",{d:"M9 6l6 6-6 6"})})}function Ft(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M4 8h16"}),t.jsx("circle",{cx:"9",cy:"8",r:"2.5"}),t.jsx("path",{d:"M4 16h16"}),t.jsx("circle",{cx:"15",cy:"16",r:"2.5"})]})}const Oe=[{name:"question",display:"/question",aliases:["question","ask","q"],descriptionKey:"agent.slashDesc_question"},{name:"variants",display:"/variants <N>",aliases:["variants","variant","v","n"],descriptionKey:"agent.slashDesc_variants",hasValue:!0},{name:"generate",display:"/generate <N>",aliases:["generate","gen","g"],descriptionKey:"agent.slashDesc_generate",hasValue:!0},{name:"parallelism",display:"/parallelism <N>",aliases:["parallelism","parallel","p"],descriptionKey:"agent.slashDesc_parallelism",hasValue:!0},{name:"help",display:"/help",aliases:["help","h"],descriptionKey:"agent.slashDesc_help"}];function Je(e){const n=e.toLowerCase();return n?Oe.filter(a=>a.aliases.some(s=>s.startsWith(n))):Oe}function Gt({listboxId:e,query:n,highlightIndex:a,onSelect:s,onHighlightChange:r}){const{t:l}=x(),o=Je(n);return o.length===0?null:t.jsx("ul",{id:e,className:"slash-command-menu",role:"listbox","aria-label":l("agent.slashCommands"),children:o.map((d,c)=>t.jsxs("li",{id:`${e}-opt-${c}`,role:"option","aria-selected":c===a,className:`slash-command-menu__item${c===a?" is-highlighted":""}`,onMouseDown:i=>i.preventDefault(),onClick:()=>s(d),onMouseEnter:()=>r(c),children:[t.jsx("span",{className:"slash-command-menu__name",children:d.display}),t.jsx("span",{className:"slash-command-menu__desc",children:l(d.descriptionKey)})]},d.name))})}function Ut(e){return Array.from(e).filter(n=>n.type.startsWith("image/"))}function Ht(e){return Array.from(e.clipboardData?.items??[]).filter(n=>n.kind==="file"&&n.type.startsWith("image/")).map(n=>n.getAsFile()).filter(n=>!!n)}function Vt({webSearchEnabled:e,insertedPrompt:n,onWebSearchChange:a,onAttachFiles:s,onSend:r}){const{t:l}=x(),[o,d]=m.useState(""),[c,i]=m.useState(0),[g,u]=m.useState(!1),p=m.useRef(null),f=m.useRef(null),b=m.useId(),v=o.trim().length>0,w=o.trimStart().match(/^\/([a-z]*)$/i),q=w!==null,G=q&&!g,U=w?.[1]??"",T=Je(U),z=G&&T.length>0,A=T.length>0?Math.min(c,T.length-1):0,he=z?`${b}-opt-${A}`:void 0;m.useEffect(()=>{i(0),u(!1)},[U]),m.useEffect(()=>{q&&u(!1)},[q]),m.useEffect(()=>{n?.text&&d(j=>j.trim()?`${j.trim()}
1
+ import{f as m,j as t}from"./index-DYtUJ4t0.js";import{q as Nt,T as Fe,u as x,i as we,R as ye,X as Ct,a as E}from"./App-DkvU6Sex.js";import{u as de}from"./useAgentDialogFocus-B2snKbzK.js";async function B(e,n){const a=await Nt(e,n);if(!a.ok){const s=await a.json().catch(()=>({})),r=s.error,l=typeof r=="string"?r:r?.message??`Request failed: ${a.status}`,o=new Error(l);throw o.status=a.status,o.code=typeof r=="object"?r?.code:s.code,o}return await a.json()}function kt(e){return e.filename?`/generated/${e.filename}`:typeof e.url=="string"&&e.url?e.url:typeof e.thumb=="string"&&e.thumb?e.thumb:null}function Ge(e){const n=kt(e);if(!n)return null;const a=e.filename??e.canvasEditableFilename??"current-image.png";return{id:`current-${a}`,filename:a,url:n,thumbUrl:e.thumb??n,prompt:e.prompt??e.userPrompt??null,revisedPrompt:e.revisedPrompt??null,createdAt:e.createdAt??Date.now()}}async function Re(e){const n=e?`?selectedSessionId=${encodeURIComponent(e)}`:"";return B(`/api/agent/sessions${n}`)}async function $e(e){const n=e.currentImage?Ge(e.currentImage):null;return B("/api/agent/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e.title,currentImage:n,webSearchEnabled:e.webSearchEnabled??!0})})}async function ce(e,n){return B(`/api/agent/sessions/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})}async function It(e){return B(`/api/agent/sessions/${encodeURIComponent(e)}`,{method:"DELETE"})}async function At(e,n,a){return B(`/api/agent/sessions/${encodeURIComponent(e)}/queue`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:n,options:a})})}async function Tt(e){return B(`/api/agent/queue/${encodeURIComponent(e)}/cancel`,{method:"POST"})}async function Lt(e){return B(`/api/agent/queue/${encodeURIComponent(e)}/retry`,{method:"POST"})}const _e=Fe,Mt=Fe,Et={provider:"oauth",model:"gpt-5.6-luna",quality:"medium",size:"1024x1024",format:"png",moderation:"low",reasoningEffort:"none",webSearchEnabled:!0,generationStrategy:"auto",variants:1,maxAutoVariants:_e,parallelism:2};function Pe(e){return{...Et,...e??{}}}function De(e){const{width:n,height:a}=e;return n>=1280?"desktop-three-pane":a<560&&n<1280?n>=768?"tablet-stacked":"mobile-chat-image-sheet":n>=960&&a>=560?"desktop-rail":n>=768&&a>=700?"tablet-stacked":"mobile-chat-image-sheet"}function qt(){return typeof window>"u"?1440:window.innerWidth}function Be(){return typeof window>"u"?900:window.innerHeight}function Rt(){if(typeof window>"u"||typeof document>"u")return 1440;const e=document.querySelector('.app[data-ui-mode="agent"] .sidebar');if(!e)return window.innerWidth;const n=window.getComputedStyle(e);if(n.display==="none"||n.visibility==="hidden")return window.innerWidth;const a=e.getBoundingClientRect().width;return Math.max(0,window.innerWidth-a)}function $t(){const[e,n]=m.useState(()=>De({width:qt(),height:Be()}));return m.useEffect(()=>{const a=()=>n(De({width:Rt(),height:Be()}));return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),e}function C({size:e=16,children:n}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:n})}function Ue(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M12 5v14"}),t.jsx("path",{d:"M5 12h14"})]})}function Pt(e){return t.jsxs(C,{...e,children:[t.jsx("circle",{cx:"11",cy:"11",r:"7"}),t.jsx("path",{d:"M21 21l-4.3-4.3"})]})}function O(e){return t.jsxs(C,{...e,children:[t.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),t.jsx("circle",{cx:"8",cy:"10",r:"1.5"}),t.jsx("path",{d:"M21 16l-5-5L5 19"})]})}function ge(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M18 6L6 18"}),t.jsx("path",{d:"M6 6l12 12"})]})}function Dt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M22 2L11 13"}),t.jsx("path",{d:"M22 2l-7 20-4-9-9-4 20-7z"})]})}function Bt(e){return t.jsx(C,{...e,children:t.jsx("path",{d:"M21.4 11.1l-9.2 9.1a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5"})})}function Ot(e){return t.jsxs(C,{...e,children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("path",{d:"M2 12h20"}),t.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 0 20"}),t.jsx("path",{d:"M12 2a15.3 15.3 0 0 0 0 20"})]})}function He(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M4 6h16"}),t.jsx("path",{d:"M4 12h16"}),t.jsx("path",{d:"M4 18h16"})]})}function zt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M19 12H5"}),t.jsx("path",{d:"M12 19l-7-7 7-7"})]})}function Wt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M8 6h13"}),t.jsx("path",{d:"M8 12h13"}),t.jsx("path",{d:"M8 18h13"}),t.jsx("circle",{cx:"3",cy:"6",r:"1"}),t.jsx("circle",{cx:"3",cy:"12",r:"1"}),t.jsx("circle",{cx:"3",cy:"18",r:"1"})]})}function Kt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M3 6h18"}),t.jsx("path",{d:"M8 6V4h8v2"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"})]})}function Qt(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M12 20h9"}),t.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]})}function Ve(e){return t.jsx(C,{...e,children:t.jsx("path",{d:"M6 9l6 6 6-6"})})}function Ne(e){return t.jsx(C,{...e,children:t.jsx("path",{d:"M9 6l6 6-6 6"})})}function Ft(e){return t.jsxs(C,{...e,children:[t.jsx("path",{d:"M4 8h16"}),t.jsx("circle",{cx:"9",cy:"8",r:"2.5"}),t.jsx("path",{d:"M4 16h16"}),t.jsx("circle",{cx:"15",cy:"16",r:"2.5"})]})}const Oe=[{name:"question",display:"/question",aliases:["question","ask","q"],descriptionKey:"agent.slashDesc_question"},{name:"variants",display:"/variants <N>",aliases:["variants","variant","v","n"],descriptionKey:"agent.slashDesc_variants",hasValue:!0},{name:"generate",display:"/generate <N>",aliases:["generate","gen","g"],descriptionKey:"agent.slashDesc_generate",hasValue:!0},{name:"parallelism",display:"/parallelism <N>",aliases:["parallelism","parallel","p"],descriptionKey:"agent.slashDesc_parallelism",hasValue:!0},{name:"help",display:"/help",aliases:["help","h"],descriptionKey:"agent.slashDesc_help"}];function Je(e){const n=e.toLowerCase();return n?Oe.filter(a=>a.aliases.some(s=>s.startsWith(n))):Oe}function Gt({listboxId:e,query:n,highlightIndex:a,onSelect:s,onHighlightChange:r}){const{t:l}=x(),o=Je(n);return o.length===0?null:t.jsx("ul",{id:e,className:"slash-command-menu",role:"listbox","aria-label":l("agent.slashCommands"),children:o.map((d,c)=>t.jsxs("li",{id:`${e}-opt-${c}`,role:"option","aria-selected":c===a,className:`slash-command-menu__item${c===a?" is-highlighted":""}`,onMouseDown:i=>i.preventDefault(),onClick:()=>s(d),onMouseEnter:()=>r(c),children:[t.jsx("span",{className:"slash-command-menu__name",children:d.display}),t.jsx("span",{className:"slash-command-menu__desc",children:l(d.descriptionKey)})]},d.name))})}function Ut(e){return Array.from(e).filter(n=>n.type.startsWith("image/"))}function Ht(e){return Array.from(e.clipboardData?.items??[]).filter(n=>n.kind==="file"&&n.type.startsWith("image/")).map(n=>n.getAsFile()).filter(n=>!!n)}function Vt({webSearchEnabled:e,insertedPrompt:n,onWebSearchChange:a,onAttachFiles:s,onSend:r}){const{t:l}=x(),[o,d]=m.useState(""),[c,i]=m.useState(0),[g,u]=m.useState(!1),p=m.useRef(null),f=m.useRef(null),b=m.useId(),v=o.trim().length>0,w=o.trimStart().match(/^\/([a-z]*)$/i),q=w!==null,G=q&&!g,U=w?.[1]??"",T=Je(U),z=G&&T.length>0,A=T.length>0?Math.min(c,T.length-1):0,he=z?`${b}-opt-${A}`:void 0;m.useEffect(()=>{i(0),u(!1)},[U]),m.useEffect(()=>{q&&u(!1)},[q]),m.useEffect(()=>{n?.text&&d(j=>j.trim()?`${j.trim()}
2
2
 
3
3
  ${n.text}`:n.text)},[n]);const H=()=>{const j=o.trim();j&&(r(j),d(""))},V=j=>{d(`/${j.name} `),p.current?.focus()},J=j=>{const M=Ht(j);M.length!==0&&(j.preventDefault(),s(M))};return t.jsxs("div",{className:"agent-composer",children:[z&&t.jsx(Gt,{listboxId:b,query:U,highlightIndex:A,onSelect:V,onHighlightChange:i}),t.jsx("textarea",{ref:p,value:o,"aria-autocomplete":"list","aria-haspopup":"listbox","aria-label":l("agent.composerPlaceholder"),...z?{"aria-controls":b}:{},"aria-activedescendant":he,autoCapitalize:"off",autoCorrect:"off",placeholder:l("agent.composerPlaceholder"),onChange:j=>d(j.target.value),onPaste:J,onKeyDown:j=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),H();return}if(z)switch(j.key){case"Tab":{j.preventDefault(),V(T[A]);return}case"ArrowDown":{j.preventDefault(),i((A+1)%T.length);return}case"ArrowUp":{j.preventDefault(),i((A-1+T.length)%T.length);return}case"Enter":{j.preventDefault(),V(T[A]);return}case"Escape":{j.preventDefault(),u(!0);return}}}}),t.jsx("input",{ref:f,type:"file",accept:"image/png,image/jpeg,image/webp",multiple:!0,hidden:!0,onChange:j=>{const M=Ut(j.target.files??[]);M.length>0&&s(M),j.target.value=""}}),t.jsxs("div",{className:"agent-composer__actions",children:[t.jsx("button",{type:"button",onClick:()=>f.current?.click(),"aria-label":l("agent.attachReference"),title:l("agent.attachReference"),children:t.jsx(Bt,{size:16})}),t.jsx("button",{type:"button",className:e?"is-active":"","aria-pressed":e,onClick:()=>a(!e),"aria-label":l("agent.webSearch"),title:l("agent.webSearch"),children:t.jsx(Ot,{size:16})}),t.jsxs("button",{type:"button",className:"agent-composer__send",onClick:H,disabled:!v,"aria-label":l("agent.send"),children:[t.jsx(Dt,{size:16}),t.jsx("span",{children:l("agent.send")})]})]})]})}function Q({src:e,alt:n,className:a,fallbackClassName:s,iconSize:r=18}){const[l,o]=m.useState(!1);return!e||l?t.jsx("span",{className:s??"agent-image-fallback","aria-label":n,role:"img",children:t.jsx(O,{size:r})}):we(e)?t.jsx("video",{className:a,src:e,preload:"metadata",playsInline:!0,muted:!0,onError:()=>o(!0),"aria-label":n}):t.jsx("img",{className:a,src:e,alt:n,onError:()=>o(!0)})}const F=m.forwardRef(function({image:n,selected:a=!1,compact:s=!1,onSelect:r},l){const{t:o}=x(),d=`${o("agent.mediaSelect")}: ${n.prompt??n.filename}`,c=`${s?"agent-result-thumb agent-result-thumb--compact":"agent-result-thumb"}${a?" is-selected":""}`;return t.jsx("button",{ref:l,type:"button",className:c,"aria-label":d,"aria-current":a?"true":void 0,onClick:()=>r(n.id),title:o("agent.mediaSelect"),children:t.jsx(Q,{src:n.thumbUrl??n.url,alt:n.prompt??o("agent.imageAlt"),iconSize:s?14:18})})});function Jt({turn:e,imagesById:n,currentImageId:a,onImageSelect:s}){const{t:r}=x(),l=e.role==="user"?r("agent.user"):e.status==="error"?r("agent.errorRole"):r("agent.assistant"),o=e.imageIds??[],d=e.status==="streaming"?" is-streaming":e.status==="error"?" is-error":"",c=`agent-message agent-message--${e.role}${d}`;return t.jsxs("article",{className:c,"aria-busy":e.status==="streaming"?"true":void 0,children:[t.jsx("div",{className:"agent-message__role",children:l}),t.jsx("p",{children:e.text}),o.length>0?t.jsx("div",{className:"agent-message__images",children:o.map(i=>{const g=n[i];return g?t.jsx(F,{image:g,selected:i===a,compact:!1,onSelect:s},i):null})}):null]})}const Xt=["ima2.get_image_context","ima2.web_search","ima2.generate_image","ima2.generate_video","ima2.get_generation_errors"];function Yt(e){return e.replace(/\s+/g," ").trim()||"tool"}function Zt(e){if(e.toolCalls?.length)return e.toolCalls;const n=Yt(e.text);return Xt.filter(a=>n.includes(a)).map((a,s)=>({id:`${e.id}-fallback-${s}`,name:a,status:e.status==="error"?"error":e.status==="streaming"?"running":"complete",outputSummary:n,imageIds:a==="ima2.generate_image"||a==="ima2.generate_video"?e.imageIds??[]:[],webFindingIds:a==="ima2.web_search"?e.webFindingIds??[]:[]}))}function Xe(e){return!e||e<0?null:e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}const en={"ima2.get_image_context":"agent.toolLabel.getImageContext","ima2.web_search":"agent.toolLabel.webSearch","ima2.generate_image":"agent.toolLabel.generateImage","ima2.generate_video":"agent.toolLabel.generateVideo","ima2.get_generation_errors":"agent.toolLabel.getGenerationErrors"};function Ye(e){return en[e]??null}const tn=72;function nn(e,n=tn){const a=(e??"").replace(/\s+/g," ").trim();if(!a)return null;if(a.length<=n)return a;const s=a.slice(0,n),r=s.lastIndexOf(" ");return`${(r>n*.6?s.slice(0,r):s).trimEnd()}…`}function an({call:e,imagesById:n,currentImageId:a,onImageSelect:s}){const{t:r}=x(),l=e.imageIds??[],o=Xe(e.durationMs),[d,c]=m.useState({input:!1,output:!1}),i=(g,u)=>t.jsxs("dd",{className:d[g]?"is-expanded":void 0,children:[t.jsx("span",{children:u}),t.jsx("button",{type:"button",onClick:()=>c(p=>({...p,[g]:!p[g]})),children:r(d[g]?"agent.toolsShowLess":"agent.toolsShowMore")})]});return t.jsxs("div",{className:"agent-tool-call-details",children:[t.jsxs("dl",{children:[t.jsxs("div",{children:[t.jsx("dt",{children:r("agent.toolInput")}),i("input",e.inputSummary??"-")]}),t.jsxs("div",{children:[t.jsx("dt",{children:r("agent.toolOutput")}),i("output",e.errorMessage??e.outputSummary??"-")]}),e.requestId?t.jsxs("div",{children:[t.jsx("dt",{children:r("agent.requestId")}),t.jsx("dd",{children:e.requestId})]}):null,o?t.jsxs("div",{children:[t.jsx("dt",{children:r("agent.duration")}),t.jsx("dd",{children:o})]}):null]}),l.length>0?t.jsx("div",{className:"agent-tool-call-details__artifacts","aria-label":r("agent.toolArtifacts"),children:l.map(g=>{const u=n[g];return u?t.jsx(F,{image:u,selected:g===a,compact:!0,onSelect:s},g):null})}):null]})}function sn({call:e,imagesById:n,currentImageId:a,onImageSelect:s}){const{t:r}=x(),l=m.useId(),[o,d]=m.useState(!1),c=Xe(e.durationMs),i=Ye(e.name),g=i?r(i):e.name,u=nn(e.status==="error"?e.errorMessage??e.inputSummary:e.inputSummary),p=r(`agent.toolStatus.${e.status}`);return t.jsxs("li",{className:`agent-tool-call-row agent-tool-call-row--${e.status}`,children:[t.jsxs("button",{type:"button",className:"agent-tool-call-row__toggle","aria-expanded":o,"aria-controls":l,"aria-busy":e.status==="running"?"true":void 0,onClick:()=>d(f=>!f),children:[t.jsx("span",{className:"agent-tool-call-row__status","aria-hidden":"true"}),t.jsx("span",{className:"agent-tool-call-row__name",children:g}),t.jsx("span",{className:"agent-sr-only",children:p}),e.imageIds?.length?t.jsx("span",{className:"agent-tool-call-row__meta",children:r("agent.toolImageCount",{count:e.imageIds.length})}):null,c?t.jsx("span",{className:"agent-tool-call-row__meta agent-tool-call-row__meta--duration",children:c}):null,o?t.jsx(Ve,{size:13}):t.jsx(Ne,{size:13}),u?t.jsx("span",{className:"agent-tool-call-row__preview",title:u,children:u}):null]}),t.jsx("div",{id:l,hidden:!o,children:t.jsx(an,{call:e,imagesById:n,currentImageId:a,onImageSelect:s})})]})}function rn(e){const n=[],a=new Set;let s=!1;const r=[];for(const l of e){const o=Zt(l);n.push(...o);for(const d of l.imageIds??[])a.add(d);for(const d of o)for(const c of d.imageIds??[])a.add(c);l.status==="streaming"&&(s=!0);for(const d of o)r.includes(d.name)||r.push(d.name)}return{toolCalls:n,imageIds:[...a],isStreaming:s,names:r}}function ln({turns:e,imagesById:n,currentImageId:a,onImageSelect:s}){const{t:r}=x(),l=m.useId(),[o,d]=m.useState(!1),{toolCalls:c,imageIds:i,isStreaming:g,names:u}=m.useMemo(()=>rn(e),[e]),p=r(o?"agent.toolCollapse":"agent.toolExpand"),f=m.useMemo(()=>u.map(v=>{const w=Ye(v);return w?r(w):v}).join(" · ")||r("agent.toolGroup"),[u,r]);return t.jsxs("article",{className:`agent-message agent-message--tool is-collapsible${g?" is-streaming":""}`,"aria-busy":g?"true":void 0,children:[t.jsx("div",{className:"agent-message__tool-summary",children:t.jsx("button",{type:"button",className:"agent-message__tool-toggle","aria-expanded":o,"aria-controls":l,"aria-label":`${p}: ${f}`,onClick:()=>d(b=>!b),children:t.jsxs("span",{className:"agent-message__tool-summary-line",children:[t.jsx("span",{className:"agent-message__tool-dot","aria-hidden":"true"}),t.jsx("span",{className:"agent-message__role",children:r("agent.toolGroup")}),t.jsx("span",{className:"agent-message__tool-label",children:f}),i.length>0?t.jsx("span",{className:"agent-message__tool-count",children:r("agent.toolImageCount",{count:i.length})}):null,c.length>0?t.jsx("span",{className:"agent-message__tool-count",children:r("agent.toolCallCount",{count:c.length})}):null,o?t.jsx(Ve,{size:14}):t.jsx(Ne,{size:14})]})})}),t.jsxs("div",{id:l,className:"agent-message__tool-details",hidden:!o,children:[c.length>0?t.jsx("ul",{className:"agent-tool-call-list",children:c.map(b=>t.jsx(sn,{call:b,imagesById:n,currentImageId:a,onImageSelect:s},b.id))}):null,i.length>0?t.jsx("div",{className:"agent-message__tool-thumbs",children:i.map(b=>{const v=n[b];return v?t.jsx(F,{image:v,selected:b===a,compact:!0,onSelect:s},b):null})}):null]})]})}function on(e){return e.role!=="tool"&&(e.text.trim().length>0||(e.imageIds?.length??0)>0)}function cn({turns:e,imagesById:n,currentImageId:a,onImageSelect:s}){const{t:r}=x(),l=e.filter(u=>u.role==="tool"),o=e.filter(on),d=e.some(u=>u.status==="streaming"),c=e.some(u=>u.status==="error"),i=d?" is-streaming":c?" is-error":"",g=r(c?"agent.errorRole":"agent.assistant");return t.jsxs("article",{className:`agent-message agent-message--assistant-run${i}`,"aria-busy":d?"true":void 0,children:[t.jsxs("div",{className:"agent-run__header",children:[t.jsx("div",{className:"agent-message__role",children:g}),l.length>0?t.jsx("div",{className:"agent-run__header-tool",children:t.jsx(ln,{turns:l,imagesById:n,currentImageId:a,onImageSelect:s})}):null]}),o.length>0?t.jsx("ol",{className:"agent-run__steps","aria-label":g,children:o.map(u=>{const p=u.imageIds??[],f=u.status==="streaming"?" is-streaming":u.status==="error"?" is-error":"";return t.jsxs("li",{className:`agent-run__step${f}`,children:[t.jsx("span",{className:"agent-run__step-marker","aria-hidden":"true"}),t.jsxs("div",{className:"agent-run__step-body",children:[u.text.trim().length>0?t.jsx("p",{children:u.text}):null,p.length>0?t.jsx("div",{className:"agent-message__images",children:p.map(b=>{const v=n[b];return v?t.jsx(F,{image:v,selected:b===a,compact:!1,onSelect:s},b):null})}):null]})]},u.id)})}):null]})}function un(e){const n=[];let a=[];const s=()=>{a.length!==0&&(n.push({kind:"run",turns:a,key:`run-${a[0].id}`}),a=[])};for(const r of e)r.role==="user"?(s(),n.push({kind:"single",turn:r})):a.push(r);return s(),n}function dn({turns:e,imagesById:n,currentImageId:a,onImageSelect:s}){const{t:r}=x(),l=m.useRef(null),o=m.useRef(!0),[d,c]=m.useState(!1),i=m.useMemo(()=>un(e),[e]),g=m.useCallback(()=>{const p=l.current;p&&(o.current=p.scrollHeight-p.scrollTop-p.clientHeight<=120,o.current&&c(!1))},[]),u=m.useCallback(()=>{const p=l.current;p&&(p.scrollTo({top:p.scrollHeight,behavior:"smooth"}),o.current=!0,c(!1))},[]);return m.useEffect(()=>{const p=l.current;p&&(o.current?p.scrollTop=p.scrollHeight:c(!0))},[e.length]),t.jsxs("div",{className:"agent-message-list-wrap",children:[t.jsxs("div",{ref:l,className:"agent-message-list",role:"log","aria-label":r("agent.workspace"),onScroll:g,children:[e.length===0?t.jsx("div",{className:"agent-message-list__empty",children:r("agent.emptyChat")}):null,i.map(p=>p.kind==="run"?t.jsx(cn,{turns:p.turns,imagesById:n,currentImageId:a,onImageSelect:s},p.key):t.jsx(Jt,{turn:p.turn,imagesById:n,currentImageId:a,onImageSelect:s},p.turn.id))]}),d?t.jsx("button",{type:"button",className:"agent-message-list__jump",onClick:u,children:r("agent.emptyJumpLatest")}):null]})}const ue=[{value:"gpt-5.6-luna",shortLabel:"5.6l",fullLabel:"GPT-5.6 Luna",provider:"oauth"},{value:"gpt-5.6-terra",shortLabel:"5.6t",fullLabel:"GPT-5.6 Terra",provider:"oauth"},{value:"gpt-5.6-sol",shortLabel:"5.6s",fullLabel:"GPT-5.6 Sol",provider:"oauth"},{value:"gpt-5.5",shortLabel:"5.5",fullLabel:"GPT-5.5",provider:"oauth"},{value:"gpt-5.4",shortLabel:"5.4",fullLabel:"GPT-5.4",provider:"oauth"},{value:"gpt-5.4-mini",shortLabel:"5.4m",fullLabel:"GPT-5.4 mini",provider:"oauth"},{value:"grok-4.6",shortLabel:"4.6",fullLabel:"Grok 4.6",provider:"grok"},{value:"grok-4.5",shortLabel:"4.5",fullLabel:"Grok 4.5",provider:"grok"},{value:"grok-4.3",shortLabel:"4.3",fullLabel:"Grok 4.3",provider:"grok"}];function gn(e){return ue.find(n=>n.value===e.model)??ue.find(n=>n.provider===e.provider)??ue[0]}function Ze({settings:e,onChange:n,onOpenModelTab:a}){const{t:s}=x(),[r,l]=m.useState(!1),o=m.useRef(null),d=gn(e),c=ye.find(i=>i.value===e.reasoningEffort)??ye[0];return m.useEffect(()=>{if(!r)return;const i=u=>{o.current?.contains(u.target)||l(!1)},g=u=>{u.key==="Escape"&&l(!1)};return window.addEventListener("pointerdown",i),window.addEventListener("keydown",g),()=>{window.removeEventListener("pointerdown",i),window.removeEventListener("keydown",g)}},[r]),t.jsxs("div",{ref:o,className:"image-model-select image-model-select--sidebar agent-model-select",children:[t.jsxs("button",{type:"button",className:"image-model-select__trigger image-model-select__trigger--pill","aria-haspopup":"menu","aria-expanded":r,"aria-label":s("sidebar.quickSettingsAria",{model:d.shortLabel,effort:c.shortLabel}),onClick:()=>l(i=>!i),children:[t.jsxs("span",{className:"image-model-select__trigger-top",children:[t.jsx("span",{className:"image-model-select__trigger-model",children:d.shortLabel}),t.jsx("span",{className:"image-model-select__trigger-chevron","aria-hidden":"true",children:"▾"})]}),t.jsx("span",{className:"image-model-select__trigger-effort",children:c.shortLabel})]}),a?t.jsx("button",{type:"button",className:"agent-model-select__open-tab",onClick:a,"aria-label":s("agent.modelTabView"),title:s("agent.modelTabView"),children:t.jsx(Ne,{size:13})}):null,r?t.jsxs("div",{className:"image-model-select__menu agent-model-select__menu",role:"menu","aria-label":s("sidebar.quickSettingsMenu"),children:[t.jsxs("div",{className:"image-model-select__section",role:"group","aria-label":s("agent.model"),children:[t.jsx("div",{className:"image-model-select__section-title",children:s("agent.model")}),ue.map(i=>t.jsxs("button",{type:"button",className:`image-model-select__item${i.value===d.value?" is-active":""}`,role:"menuitemradio","aria-checked":i.value===d.value,onClick:()=>{n({model:i.value,provider:i.provider}),l(!1)},children:[t.jsx("span",{children:i.shortLabel}),t.jsx("small",{children:i.fullLabel})]},i.value))]}),t.jsxs("div",{className:"image-model-select__section",role:"group","aria-label":s("sidebar.reasoningLabel"),children:[t.jsx("div",{className:"image-model-select__section-title",children:s("sidebar.reasoningLabel")}),ye.map(i=>t.jsxs("button",{type:"button",className:`image-model-select__item${i.value===e.reasoningEffort?" is-active":""}`,role:"menuitemradio","aria-checked":i.value===e.reasoningEffort,onClick:()=>{n({reasoningEffort:i.value}),l(!1)},children:[t.jsx("span",{children:i.shortLabel}),t.jsx("small",{children:s(i.fullLabelKey)})]},i.value))]})]}):null]})}function hn(e,n){if(!e)return null;const a=Math.max(0,Math.floor((n-e)/1e3));return`${String(Math.floor(a/60)).padStart(2,"0")}:${String(a%60).padStart(2,"0")}`}function mn({progress:e,queueSummary:n,onQueueOpen:a,onRetry:s}){const{t:r}=x(),[l,o]=m.useState(Date.now());m.useEffect(()=>{if(!e?.startedAt)return;o(Date.now());const p=window.setInterval(()=>o(Date.now()),1e3);return()=>window.clearInterval(p)},[e?.startedAt]);const d=n?.activeCount??(e?.queuedCount??0)+(e?.runningCount??0),c=n?.failedCount??e?.failedCount??0;if(!e?.active&&!n)return null;const i=e?.status==="queued"?"agent.progressQueued":e?.progressStage==="downloading"?"agent.progressDownloading":e?.status==="running"||e?.progressStage==="requesting"||e?.progressStage==="polling"?"agent.progressGenerating":e?.status==="error"?"agent.progressFailed":"agent.progressPlanning",g=hn(e?.startedAt,l),u=e?.jobKind?r("agent.progressJob",{kind:r(`agent.mediaKind.${e.jobKind}`),count:e.variantCount??1}):null;return t.jsxs("div",{className:`agent-run-status agent-run-status--${e?.status??"idle"}`,role:"status","aria-live":"polite",children:[e?.active?t.jsx("span",{className:"agent-run-status__indicator","aria-hidden":"true"}):null,e?.active?t.jsx("span",{className:"agent-run-status__label",children:r(i)}):null,u?t.jsx("span",{className:"agent-run-status__meta",children:u}):null,g?t.jsx("time",{className:"agent-run-status__elapsed",dateTime:`PT${Math.floor((l-(e?.startedAt??l))/1e3)}S`,children:g}):null,e?.status==="error"&&e.lastError?t.jsx("span",{className:"agent-run-status__meta",children:e.lastError}):null,e?.status==="error"&&s?t.jsx("button",{type:"button",className:"agent-run-status__retry",onClick:s,children:r("agent.retryQueue")}):null,t.jsx("button",{type:"button",className:"agent-run-status__queue",onClick:a,disabled:!a,children:r("agent.queueSummary",{active:d,failed:c})})]})}function pn({status:e,compacted:n=!1}){const{t:a}=x(),s=a(e==="generating"?"agent.statusGenerating":e==="reconnecting"?"agent.statusReconnecting":"agent.statusReady");return t.jsxs("span",{className:`agent-status agent-status--${e}`,"aria-live":e==="ready"?void 0:"polite",children:[e==="generating"?t.jsx("span",{className:"agent-status__dot","aria-hidden":"true"}):null,t.jsx("span",{children:s}),n?t.jsx("em",{children:a("agent.compacted")}):null]})}function fn({session:e,turns:n,imagesById:a,currentImageId:s,runtimeStatus:r,runProgress:l,settings:o,insertedPrompt:d,onSettingsChange:c,onOpenModelTab:i,onWebSearchChange:g,onAttachFiles:u,onImageSelect:p,onSend:f,onRetryRun:b}){const{t:v}=x();return t.jsxs("section",{className:"agent-chat","aria-label":v("agent.chat"),children:[t.jsxs("header",{className:"agent-pane-header",children:[t.jsxs("div",{className:"agent-pane-header__title",children:[t.jsx("span",{children:v("agent.chat")}),t.jsx("strong",{children:e?.title??v("agent.newSession")})]}),t.jsxs("div",{className:"agent-pane-header__actions",children:[o&&c?t.jsx(Ze,{settings:o,onChange:c,onOpenModelTab:i}):null,t.jsx(pn,{status:r,compacted:e?.compacted})]})]}),t.jsx(dn,{turns:n,imagesById:a,currentImageId:s,onImageSelect:p}),t.jsx(mn,{progress:l,onRetry:b}),t.jsx(Vt,{webSearchEnabled:e?.webSearchEnabled??!1,insertedPrompt:d,onWebSearchChange:g,onAttachFiles:u,onSend:f})]})}const xn=["image","refs","web","memory"];function bn({activeTab:e,onChange:n}){const{t:a}=x(),s={image:a("agent.imageTab"),refs:a("agent.refsTab"),web:a("agent.webTab"),memory:a("agent.memoryTab")};return t.jsx("div",{className:"agent-context-tabs",role:"tablist","aria-label":a("agent.contextTabs"),children:xn.map(r=>t.jsx("button",{type:"button",role:"tab","aria-selected":e===r,className:e===r?"active":"",onClick:()=>n(r),children:s[r]},r))})}function jn({activeTab:e,currentImage:n}){const{t:a}=x();return e==="refs"?t.jsx("div",{className:"agent-tab-empty",children:a("agent.noRefs")}):e==="web"?t.jsx("div",{className:"agent-tab-empty",children:a("agent.noWeb")}):e==="memory"?t.jsxs("ul",{className:"agent-memory-list",children:[t.jsx("li",{children:a("agent.memoryItemStyle")}),t.jsx("li",{children:a("agent.memoryItemSubject")})]}):t.jsxs("dl",{className:"agent-image-meta",children:[t.jsxs("div",{children:[t.jsx("dt",{children:a("agent.filename")}),t.jsx("dd",{children:n?.filename??"-"})]}),t.jsxs("div",{children:[t.jsx("dt",{children:a("agent.prompt")}),t.jsx("dd",{children:n?.prompt??n?.revisedPrompt??"-"})]})]})}function yn(e){const n=Math.max(0,Math.round(e));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function et({image:e}){const{t:n}=x(),[a,s]=m.useState("loading"),[r,l]=m.useState(null),[o,d]=m.useState(0),c=g=>{const u=g.currentTarget.duration;l(Number.isFinite(u)?u:null),s("ready")},i=()=>{s("loading"),l(null),d(g=>g+1)};return t.jsxs("div",{className:"agent-video-preview",children:[a==="loading"?t.jsx("div",{className:"agent-video-preview__skeleton",role:"status",children:n("agent.mediaLoading")}):null,a==="error"?t.jsxs("div",{className:"agent-video-preview__error",role:"alert",children:[t.jsx(O,{size:34}),t.jsx("span",{children:n("agent.mediaLoadFailed")}),t.jsx("button",{type:"button",onClick:i,children:n("agent.mediaRetry")})]}):t.jsx("video",{src:e.url,controls:!0,playsInline:!0,preload:"metadata","aria-label":e.prompt??n("agent.mediaVideoLabel"),onLoadedMetadata:c,onError:()=>s("error")},o),t.jsxs("div",{className:"agent-video-preview__toolbar",children:[t.jsx("span",{children:r==null?n("agent.mediaDurationUnknown"):n("agent.mediaDuration",{duration:yn(r)})}),t.jsx("a",{href:e.url,download:e.filename,children:n("agent.mediaDownload")})]})]})}function tt({currentImage:e,images:n,activeTab:a,onTabChange:s,onImageSelect:r,headerAction:l}){const{t:o}=x(),d=m.useRef({}),c=m.useMemo(()=>n.findIndex(u=>u.id===e?.id),[e?.id,n]);m.useEffect(()=>{e?.id&&d.current[e.id]?.scrollIntoView({block:"nearest",inline:"nearest"})},[e?.id]);const i=m.useCallback(u=>{const p=n[u];p&&r(p.id)},[n,r]),g=m.useCallback(u=>{if(n.length===0)return;const p=c>=0?c:0;let f=null;(u.key==="ArrowLeft"||u.key==="ArrowUp")&&(f=Math.max(0,p-1)),(u.key==="ArrowRight"||u.key==="ArrowDown")&&(f=Math.min(n.length-1,p+1)),u.key==="Home"&&(f=0),u.key==="End"&&(f=n.length-1),!(f===null||f===p)&&(u.preventDefault(),i(f))},[c,n.length,i]);return t.jsxs("section",{className:"agent-image","aria-label":o("agent.imagePane"),children:[t.jsxs("header",{className:"agent-pane-header",children:[t.jsxs("div",{className:"agent-pane-header__title",children:[t.jsx("span",{children:o("agent.imagePane")}),t.jsx("strong",{children:o("agent.currentImage")})]}),l]}),t.jsx("div",{className:"agent-image__preview",tabIndex:n.length>1?0:void 0,onKeyDown:g,"aria-label":n.length>1?o("agent.variants"):void 0,children:e?we(e.url)?t.jsx(et,{image:e},e.id):t.jsx(Q,{src:e.url,alt:e.prompt??o("agent.imageAlt"),fallbackClassName:"agent-image__empty",iconSize:34}):t.jsxs("div",{className:"agent-image__empty",children:[t.jsx(O,{size:34}),t.jsx("span",{children:o("agent.noImage")})]})}),t.jsx("div",{className:"agent-image__variants","aria-label":o("agent.variants"),onKeyDown:g,children:n.map(u=>t.jsx(F,{ref:p=>{d.current[u.id]=p},image:u,selected:u.id===e?.id,onSelect:r},u.id))}),t.jsx(bn,{activeTab:a,onChange:s}),t.jsx(jn,{activeTab:a,currentImage:e})]})}function vn({open:e,currentImage:n,images:a,activeTab:s,onTabChange:r,onImageSelect:l,onClose:o}){const{t:d}=x(),c=m.useCallback(()=>o(),[o]),i=de(e,c);return e?t.jsxs("div",{className:"agent-dialog agent-dialog--image",role:"presentation",children:[t.jsx("button",{type:"button",className:"agent-dialog__backdrop",onClick:o,"aria-label":d("agent.closeImage")}),t.jsx("section",{ref:i,className:"agent-image-sheet",role:"dialog","aria-modal":"true","aria-label":d("agent.imagePane"),children:t.jsx(tt,{currentImage:n,images:a,activeTab:s,onTabChange:r,onImageSelect:l,headerAction:t.jsx("button",{type:"button",onClick:o,"aria-label":d("agent.closeImage"),children:t.jsx(ge,{size:17})})})})]}):null}function Sn(e){return e.status==="queued"?`#${e.position}`:e.status==="succeeded"?String(e.resultImageIds.length):""}function _n(e,n){if(!e)return"-";const a=Math.max(1,Math.round((Date.now()-e)/1e3));if(a<60)return n(a,"second");const s=Math.round(a/60);return s<60?n(s,"minute"):n(Math.round(s/60),"hour")}function wn(e){return!e.errorCode&&!e.errorClass&&!e.errorMessage?null:Ct({code:e.errorCode,errorClass:e.errorClass,rawCode:e.errorRawCode,message:e.errorMessage})}function Nn(e,n){return e?.errorClass?e.spec.cardKey?n(`${e.spec.cardKey}.title`):e.spec.toastKey?n(e.spec.toastKey):null:null}function Cn({item:e,onCancel:n,onRetry:a}){const{t:s}=x(),r=e.status==="queued"||e.status==="running",l=e.status==="failed"||e.status==="canceled",o=e.plan.plannedVariants||e.plan.prompts.length||1,d=e.plan.plannedParallelism||e.options.parallelism,c=Sn(e),i=_n(e.createdAt,(u,p)=>s("agent.queueTimeAgo",{value:u,unit:s(`agent.queueTimeUnit.${p}`)})),g=Nn(wn(e),s);return t.jsxs("div",{className:`agent-queue-row agent-queue-row--${e.status}`,children:[t.jsxs("div",{className:"agent-queue-row__main",children:[t.jsx("strong",{children:e.prompt}),t.jsx("span",{className:`agent-queue-row__badge agent-queue-row__badge--${e.status}`,children:s(`agent.queueStatus.${e.status}`)}),t.jsx("span",{children:[c,g,s("agent.queuePlanSummary",{variants:o,parallel:d}),i].filter(Boolean).join(" · ")}),e.plan.reason||e.errorCode||e.errorMessage?t.jsxs("details",{className:"agent-queue-row__details",children:[t.jsx("summary",{children:s("agent.queueDetails")}),e.plan.reason?t.jsx("small",{children:e.plan.reason}):null,e.errorCode?t.jsx("small",{children:e.errorCode}):null,e.errorMessage?t.jsx("small",{children:e.errorMessage}):null]}):null]}),t.jsxs("div",{className:"agent-queue-row__actions",children:[r?t.jsx("button",{type:"button",onClick:()=>n(e.id),children:s("agent.cancelQueue")}):null,l?t.jsx("button",{type:"button",onClick:()=>a(e.id),children:s("agent.retryQueue")}):null]})]})}function nt({items:e,summary:n,onCancel:a,onRetry:s}){const{t:r}=x(),l=r("agent.queueAnnouncement",{running:n?.runningCount??0,queued:n?.queuedCount??0,failed:e.filter(o=>o.status==="failed").length});return t.jsxs("section",{className:"agent-sidebar-section","aria-label":r("agent.queue"),children:[t.jsx("header",{children:t.jsxs("div",{children:[t.jsx("span",{children:r("agent.queue")}),t.jsxs("strong",{children:[n?.runningCount??0," ",r("agent.runningShort")," · ",n?.queuedCount??0," ",r("agent.queuedShort")]})]})}),t.jsxs("div",{className:"agent-queue-list",children:[t.jsx("span",{className:"agent-sr-only","aria-live":"polite","aria-atomic":"true",children:l}),e.length===0?t.jsx("div",{className:"agent-tab-empty",children:r("agent.queueEmpty")}):e.map(o=>t.jsx(Cn,{item:o,onCancel:a,onRetry:s},o.id))]})]})}function kn({open:e,items:n,summary:a,onCancel:s,onRetry:r,onClose:l}){const{t:o}=x(),d=m.useCallback(()=>l(),[l]),c=de(e,d);return e?t.jsxs("div",{className:"agent-dialog agent-dialog--queue",role:"presentation",children:[t.jsx("button",{type:"button",className:"agent-dialog__backdrop",onClick:l,"aria-label":o("agent.topbarCloseQueue")}),t.jsxs("section",{ref:c,className:"agent-queue-sheet",role:"dialog","aria-modal":"true","aria-label":o("agent.topbarQueueSheet"),children:[t.jsxs("header",{children:[t.jsx("strong",{children:o("agent.topbarQueueSheet")}),t.jsx("button",{type:"button",onClick:l,"aria-label":o("agent.topbarCloseQueue"),children:t.jsx(ge,{size:17})})]}),t.jsx(nt,{items:n,summary:a,onCancel:s,onRetry:r})]})]}):null}function at({mode:e,onInsert:n}){const{t:a}=x(),s=E(i=>i.promptLibrary),r=E(i=>i.promptLibraryLoading),l=E(i=>i.loadPromptLibrary),[o,d]=m.useState("");m.useEffect(()=>{l()},[l]);const c=m.useMemo(()=>{const i=o.trim().toLowerCase();return s.prompts.filter(g=>{const u=g.tags.map(p=>p.toLowerCase());return e==="forms"&&!u.includes("agent:form")?!1:i?g.name.toLowerCase().includes(i)||g.text.toLowerCase().includes(i)||u.some(p=>p.includes(i)):!0})},[s.prompts,e,o]);return t.jsxs("section",{className:"agent-sidebar-section","aria-label":a(e==="forms"?"agent.forms":"agent.promptLibrary"),children:[t.jsx("header",{children:t.jsxs("div",{children:[t.jsx("span",{children:a(e==="forms"?"agent.forms":"agent.promptLibrary")}),t.jsx("strong",{children:c.length})]})}),t.jsxs("label",{className:"agent-sidebar-search",children:[t.jsx("span",{children:a("promptLibrary.search")}),t.jsx("input",{value:o,onChange:i=>d(i.target.value),placeholder:a("promptLibrary.search")})]}),t.jsxs("div",{className:"agent-prompt-library-list",children:[r?t.jsx("div",{className:"agent-tab-empty",children:a("common.loading")}):null,!r&&c.length===0?t.jsx("div",{className:"agent-tab-empty",children:a(e==="forms"?"agent.noForms":"promptLibrary.empty")}):null,c.map(i=>t.jsxs("article",{className:"agent-prompt-library-row",children:[t.jsx("strong",{children:i.name||a("promptLibrary.untitled")}),t.jsx("p",{children:i.text}),t.jsx("button",{type:"button",onClick:()=>n(i.text),children:a("agent.insertPrompt")})]},i.id))]})]})}function In({onInsert:e}){return t.jsx(at,{mode:"forms",onInsert:e})}function ne({label:e,value:n,options:a,onChange:s}){return t.jsxs("div",{className:"agent-settings-grid__field",children:[t.jsx("span",{children:e}),t.jsx("div",{className:"agent-segment-control",role:"group","aria-label":e,children:a.map(r=>t.jsx("button",{type:"button","aria-pressed":r.value===n,onClick:()=>s(r.value),children:r.label},r.value))})]})}function ve({label:e,value:n,max:a,onChange:s}){return t.jsxs("div",{className:"agent-settings-grid__field",children:[t.jsx("span",{children:e}),t.jsxs("div",{className:"agent-stepper",role:"group","aria-label":e,children:[t.jsx("button",{type:"button","aria-label":`${e} -`,disabled:n<=1,onClick:()=>s(Math.max(1,n-1)),children:"-"}),t.jsx("output",{"aria-live":"polite",children:n}),t.jsx("button",{type:"button","aria-label":`${e} +`,disabled:n>=a,onClick:()=>s(Math.min(a,n+1)),children:"+"})]})]})}function An({settings:e,onChange:n}){const{t:a}=x();return t.jsxs("section",{className:"agent-settings-grid","aria-label":a("agent.quality"),children:[t.jsx(ne,{label:a("agent.generationStrategy"),value:e.generationStrategy,options:[{value:"auto",label:a("agent.generationStrategyAuto")},{value:"manual",label:a("agent.generationStrategyManual")}],onChange:s=>n({generationStrategy:s})}),t.jsx(ne,{label:a("agent.quality"),value:e.quality,options:[{value:"low",label:"low"},{value:"medium",label:"medium"},{value:"high",label:"high"}],onChange:s=>n({quality:s})}),t.jsx(ne,{label:a("agent.size"),value:e.size,options:[{value:"1024x1024",label:"1:1"},{value:"1536x1024",label:"3:2"},{value:"1024x1536",label:"2:3"},{value:"2048x2048",label:"2K"}],onChange:s=>n({size:s})}),t.jsx(ne,{label:a("agent.format"),value:e.format,options:[{value:"png",label:"PNG"},{value:"jpeg",label:"JPEG"},{value:"webp",label:"WebP"}],onChange:s=>n({format:s})}),t.jsx(ne,{label:a("agent.moderation"),value:e.moderation,options:[{value:"auto",label:"auto"},{value:"low",label:"low"}],onChange:s=>n({moderation:s})}),e.generationStrategy==="manual"?t.jsx(ve,{label:a("agent.variantsCount"),value:e.variants,max:_e,onChange:s=>n({variants:s})}):t.jsx(ve,{label:a("agent.maxAutoVariants"),value:e.maxAutoVariants,max:_e,onChange:s=>n({maxAutoVariants:s})}),t.jsx(ve,{label:a("agent.parallelism"),value:e.parallelism,max:Mt,onChange:s=>n({parallelism:s})})]})}const D=["image","library","forms","quality","model","queue"];function Tn({activeTab:e,onChange:n}){const{t:a}=x(),s=m.useRef({}),r=m.useCallback(l=>{const o=D.indexOf(e),d=o>=0?o:0;let c=null;if((l.key==="ArrowRight"||l.key==="ArrowDown")&&(c=(d+1)%D.length),(l.key==="ArrowLeft"||l.key==="ArrowUp")&&(c=(d-1+D.length)%D.length),l.key==="Home"&&(c=0),l.key==="End"&&(c=D.length-1),c===null)return;l.preventDefault();const i=D[c];n(i),s.current[i]?.focus()},[e,n]);return t.jsx("div",{className:"agent-sidebar-tabs",role:"tablist","aria-label":a("agent.rightSidebar"),children:D.map(l=>t.jsx("button",{type:"button",role:"tab",id:`agent-sidebar-tab-${l}`,ref:o=>{s.current[l]=o},"aria-controls":`agent-sidebar-panel-${l}`,className:e===l?"active":"","aria-selected":e===l,tabIndex:e===l?0:-1,onKeyDown:r,onClick:()=>n(l),children:a(`agent.sidebarTabs.${l}`)},l))})}function ze({currentImage:e,images:n,contextTab:a,sidebarTab:s,queueItems:r,runSummary:l,settings:o,onContextTabChange:d,onSidebarTabChange:c,onImageSelect:i,onSettingsChange:g,onInsertPrompt:u,onCancelQueue:p,onRetryQueue:f}){const{t:b}=x(),v=w=>({id:`agent-sidebar-panel-${w}`,role:"tabpanel","aria-labelledby":`agent-sidebar-tab-${w}`});return t.jsxs(t.Fragment,{children:[t.jsx(Tn,{activeTab:s,onChange:c}),s==="image"?t.jsx("div",{...v("image"),className:"agent-sidebar-panel",children:t.jsx(tt,{currentImage:e,images:n,activeTab:a,onTabChange:d,onImageSelect:i})}):null,s==="library"?t.jsx("div",{...v("library"),className:"agent-sidebar-panel",children:t.jsx(at,{mode:"library",onInsert:u})}):null,s==="forms"?t.jsx("div",{...v("forms"),className:"agent-sidebar-panel",children:t.jsx(In,{onInsert:u})}):null,s==="quality"?t.jsxs("section",{...v("quality"),className:"agent-sidebar-panel agent-sidebar-section","aria-label":b("agent.quality"),children:[t.jsx("header",{children:t.jsxs("div",{children:[t.jsx("span",{children:b("agent.quality")}),t.jsx("strong",{children:o.generationStrategy==="auto"?b("agent.generationStrategyAuto"):b("agent.generationStrategyManual")})]})}),t.jsx(An,{settings:o,onChange:g})]}):null,s==="model"?t.jsxs("section",{...v("model"),className:"agent-sidebar-panel agent-sidebar-section","aria-label":b("agent.modelSettings"),children:[t.jsx("header",{children:t.jsxs("div",{children:[t.jsx("span",{children:b("agent.modelSettings")}),t.jsx("strong",{children:o.model})]})}),t.jsx(Ze,{settings:o,onChange:g})]}):null,s==="queue"?t.jsx("div",{...v("queue"),className:"agent-sidebar-panel",children:t.jsx(nt,{items:r,summary:l,onCancel:p,onRetry:f})}):null]})}const Ln=()=>{};function We({overlay:e,onClose:n,...a}){const{t:s}=x(),r=de(e===!0,n??Ln,{modal:!1});return e?t.jsxs("section",{ref:r,id:"agent-tools-panel",className:"agent-right-sidebar agent-right-sidebar--overlay",role:"dialog","aria-labelledby":"agent-tools-panel-title",children:[t.jsxs("header",{className:"agent-right-sidebar__overlay-header",children:[t.jsx("h2",{id:"agent-tools-panel-title",tabIndex:-1,"data-autofocus":!0,children:s("agent.toolsPanel")}),t.jsx("button",{type:"button",onClick:n,"aria-label":s("agent.closeTools"),children:t.jsx(ge,{size:17})})]}),t.jsx(ze,{...a})]}):t.jsx("aside",{className:"agent-right-sidebar",children:t.jsx(ze,{...a})})}function st({summary:e}){const{t:n}=x();if(!e||e.status==="idle")return null;const a=e.status==="running"?n("agent.sessionRunning"):e.status==="queued"?n("agent.sessionQueued",{count:e.queuedCount}):n("agent.sessionError");return t.jsxs("span",{className:`agent-session-spinner agent-session-spinner--${e.status}`,"data-motion-essential":!0,"aria-label":a,title:a,children:[t.jsx("span",{"aria-hidden":"true"}),e.queuedCount>0?t.jsx("em",{children:e.queuedCount}):null]})}function Mn(e){const n=Math.max(1,Math.round((Date.now()-e)/6e4));if(n<60)return`${n}m`;const a=Math.round(n/60);return a<24?`${a}h`:`${Math.round(a/24)}d`}function En({sessions:e,selectedId:n,imagesById:a,runSummaryBySession:s={},onSelect:r,onRename:l,onDelete:o}){const{t:d}=x();return t.jsx("div",{className:"agent-session-list",children:e.map(c=>{const i=c.lastImageId?a[c.lastImageId]:null;return t.jsxs("div",{className:`agent-session-row${c.id===n?" is-active":""}`,children:[t.jsxs("button",{type:"button","aria-current":c.id===n?"page":void 0,onClick:()=>r(c.id),children:[t.jsx("span",{className:"agent-session-row__thumb",children:i?t.jsx(Q,{src:i.thumbUrl??i.url,alt:"",iconSize:17}):t.jsx(O,{size:17})}),t.jsxs("span",{className:"agent-session-row__body",children:[t.jsx("strong",{children:c.title}),t.jsxs("span",{children:[d("agent.imageCount",{count:c.imageCount})," · ",Mn(c.updatedAt)]})]}),t.jsxs("span",{className:"agent-session-row__badges",children:[t.jsx(st,{summary:s[c.id]}),c.webSearchEnabled?t.jsx("em",{title:d("agent.web"),children:"W"}):null,c.compacted?t.jsx("em",{title:d("agent.compacted"),children:"C"}):null]})]}),t.jsxs("div",{className:"agent-session-row__actions",children:[t.jsx("button",{type:"button",onClick:()=>l(c.id),"aria-label":d("agent.renameSession"),title:d("agent.renameSession"),children:t.jsx(Qt,{size:14})}),t.jsx("button",{type:"button",onClick:()=>o(c.id),"aria-label":d("agent.deleteSession"),title:d("agent.deleteSession"),children:t.jsx(Kt,{size:14})})]})]},c.id)})})}function qn({open:e,sessions:n,selectedId:a,imagesById:s,runSummaryBySession:r,onClose:l,onCreate:o,onSelect:d,onRename:c,onDelete:i}){const{t:g}=x(),[u,p]=m.useState(""),f=m.useCallback(()=>l(),[l]),b=de(e,f),v=m.useMemo(()=>{const w=u.trim().toLowerCase();return w?n.filter(q=>q.title.toLowerCase().includes(w)):n},[u,n]);return e?t.jsxs("div",{className:"agent-dialog agent-dialog--drawer",role:"presentation",children:[t.jsx("button",{type:"button",className:"agent-dialog__backdrop",onClick:l,"aria-label":g("agent.closeSessions")}),t.jsxs("section",{ref:b,className:"agent-session-drawer",role:"dialog","aria-modal":"true","aria-label":g("agent.sessions"),children:[t.jsxs("header",{children:[t.jsx("strong",{children:g("agent.sessions")}),t.jsx("button",{type:"button",onClick:l,"aria-label":g("agent.closeSessions"),children:t.jsx(ge,{size:17})})]}),t.jsxs("button",{type:"button",className:"agent-sessions__create",onClick:o,children:[t.jsx(Ue,{size:16}),t.jsx("span",{children:g("agent.newSession")})]}),t.jsxs("label",{className:"agent-sessions__search",children:[t.jsx(Pt,{size:15}),t.jsx("input",{value:u,onChange:w=>p(w.target.value),placeholder:g("agent.sessionSearch")})]}),t.jsx(En,{sessions:v,selectedId:a,imagesById:s,runSummaryBySession:r,onSelect:d,onRename:c,onDelete:i})]})]}):null}function Rn({sessions:e,selectedId:n,imagesById:a,runSummaryBySession:s={},onCreate:r,onSelect:l,onOpenDrawer:o}){const{t:d}=x();return t.jsxs("aside",{className:"agent-rail","aria-label":d("agent.sessions"),children:[t.jsx("button",{type:"button",onClick:o,"aria-label":d("agent.openSessions"),title:d("agent.openSessions"),children:t.jsx(He,{size:17})}),t.jsx("button",{type:"button",onClick:r,"aria-label":d("agent.newSession"),title:d("agent.newSession"),children:t.jsx(Ue,{size:17})}),t.jsx("div",{className:"agent-rail__sessions",children:e.map(c=>{const i=c.lastImageId?a[c.lastImageId]:null,g=`${c.title} — ${d("agent.imageCount",{count:c.imageCount})}`;return t.jsxs("button",{type:"button",className:c.id===n?"is-active":"",onClick:()=>l(c.id),title:g,"aria-label":g,"aria-current":c.id===n?"true":void 0,children:[i?t.jsx(Q,{src:i.thumbUrl??i.url,alt:"",iconSize:17}):t.jsx(O,{size:17}),t.jsx(st,{summary:s[c.id]}),c.compacted?t.jsx("span",{"aria-label":d("agent.compacted")}):null]},c.id)})})]})}function $n({currentImage:e,images:n,onImageSelect:a,onOpenPanel:s,toolsPanelOpen:r}){const{t:l}=x(),o=m.useRef({}),d=m.useMemo(()=>n.findIndex(g=>g.id===e?.id),[e?.id,n]);m.useEffect(()=>{e?.id&&o.current[e.id]?.scrollIntoView({block:"nearest",inline:"nearest"})},[e?.id]);const c=m.useCallback(g=>{const u=n[g];u&&a(u.id)},[n,a]),i=m.useCallback(g=>{if(n.length===0)return;const u=d>=0?d:0;let p=null;(g.key==="ArrowLeft"||g.key==="ArrowUp")&&(p=Math.max(0,u-1)),(g.key==="ArrowRight"||g.key==="ArrowDown")&&(p=Math.min(n.length-1,u+1)),g.key==="Home"&&(p=0),g.key==="End"&&(p=n.length-1),!(p===null||p===u)&&(g.preventDefault(),c(p))},[d,n.length,c]);return t.jsxs("section",{className:"agent-stage","aria-label":l("agent.imagePane"),children:[t.jsxs("header",{className:"agent-pane-header",children:[t.jsxs("div",{className:"agent-pane-header__title",children:[t.jsx("span",{children:l("agent.imagePane")}),t.jsx("strong",{children:l("agent.currentImage")})]}),t.jsx("button",{type:"button",className:"agent-stage__tools",onClick:s,"aria-expanded":r===!0,"aria-controls":"agent-tools-panel","aria-label":l(r?"agent.closeTools":"agent.openTools"),title:l(r?"agent.closeTools":"agent.openTools"),children:t.jsx(Ft,{size:16})})]}),t.jsx("div",{className:"agent-stage__viewport",tabIndex:n.length>1?0:void 0,onKeyDown:i,"aria-label":n.length>1?l("agent.variants"):void 0,children:e?we(e.url)?t.jsx(et,{image:e},e.id):t.jsx(Q,{src:e.url,alt:e.prompt??l("agent.imageAlt"),fallbackClassName:"agent-stage__empty",iconSize:34}):t.jsxs("div",{className:"agent-stage__empty",children:[t.jsx(O,{size:34}),t.jsx("span",{children:l("agent.noImage")}),t.jsx("small",{children:l("agent.stageEmptyHint")})]})}),t.jsxs("div",{className:"agent-stage__caption",children:[t.jsx("strong",{children:e?.filename??"-"}),t.jsx("span",{children:e?.prompt??e?.revisedPrompt??""})]}),t.jsx("div",{className:"agent-stage__filmstrip","aria-label":l("agent.variants"),onKeyDown:i,children:n.map(g=>t.jsx(F,{ref:u=>{o.current[g.id]=u},image:g,selected:g.id===e?.id,onSelect:a},g.id))})]})}function Ke({layoutMode:e,session:n,currentImage:a,activeJobCount:s,onOpenSessions:r,onOpenImage:l,onOpenQueue:o}){const{t:d}=x(),c=E(g=>g.setUIMode),i=e==="mobile-chat-image-sheet";return t.jsxs("header",{className:"agent-topbar",children:[t.jsxs("button",{type:"button",className:"agent-topbar__back",onClick:()=>c("classic"),"aria-label":d("agent.topbarBackToStudio"),title:d("agent.topbarBackToStudio"),children:[t.jsx(zt,{size:18}),t.jsx("span",{children:d("agent.topbarStudio")})]}),t.jsx("button",{type:"button",className:"agent-topbar__icon",onClick:r,"aria-label":d("agent.openSessions"),title:d("agent.openSessions"),children:t.jsx(He,{size:18})}),t.jsxs("div",{className:"agent-topbar__title",children:[t.jsx("span",{children:d("agent.title")}),t.jsx("strong",{children:n?.title??d("agent.newSession")})]}),i?t.jsxs("div",{className:"agent-topbar__actions",children:[t.jsxs("button",{type:"button",className:"agent-topbar__queue",onClick:o,"aria-label":d("agent.topbarOpenQueue",{count:s}),title:d("agent.topbarOpenQueue",{count:s}),children:[t.jsx(Wt,{size:17}),t.jsx("span",{children:s})]}),t.jsx("button",{type:"button",className:"agent-topbar__image",onClick:l,"aria-label":d("agent.openImage"),title:d("agent.openImage"),children:a?t.jsx(Q,{src:a.thumbUrl??a.url,alt:"",iconSize:18}):t.jsx(O,{size:18})})]}):null]})}async function Pn({sessionId:e,files:n,importLocalImageToHistory:a,applyWorkspace:s}){for(const r of n){const l=await a(r),o=l?Ge(l):null;if(!o)continue;const d=await ce(e,{currentImage:o});s(d)}}const Ce="agent-local-",Dn=`${Ce}pending-`;let Qe=0;function ke(e){return Qe+=1,`${Ce}${e}-${Date.now()}-${Qe}`}function rt(e){return e.id.startsWith(Ce)}function ie(e){return e.id.startsWith(Dn)}function Bn(e,n){return{id:ke("user"),role:"user",text:e,imageIds:[],webFindingIds:[],status:"complete",createdAt:n}}function On(e,n){return{id:ke("pending"),role:"assistant",text:e,imageIds:[],webFindingIds:[],status:"streaming",createdAt:n}}function zn(e){return{id:ke("error"),role:"assistant",text:e,imageIds:[],webFindingIds:[],status:"error",createdAt:Date.now()}}function Wn({turns:e,queueItems:n,runSummary:a,localPendingCount:s}){const r=n.filter(d=>d.status==="failed").length,l=Kn(n),o=l?Qn(l):{};if(a?.status==="error"&&a.lastError)return{active:!0,status:"error",labelKey:"runError",queuedCount:a.queuedCount,runningCount:a.runningCount,failedCount:r,lastError:a.lastError};if(a?.status==="queued")return{active:!0,status:"queued",labelKey:"pendingQueued",queuedCount:a.queuedCount,runningCount:a.runningCount,failedCount:r,...o};if(a?.status==="running"){const d=l?.startedAt??l?.createdAt??null,c=e.some(i=>!rt(i)&&i.role==="tool"&&(!d||(i.createdAt??0)>=d));return{active:!0,status:c?"running":"planning",labelKey:c?"pendingGenerating":"pendingPlanning",queuedCount:a.queuedCount,runningCount:a.runningCount,failedCount:r,...o}}return s>0?{active:!0,status:"planning",labelKey:"pendingPlanning",queuedCount:a?.queuedCount??0,runningCount:a?.runningCount??0,failedCount:r}:null}function Kn(e){return[...e].filter(n=>n.status==="running"||n.status==="queued").sort((n,a)=>n.status!==a.status?n.status==="running"?-1:1:(n.startedAt??n.createdAt)-(a.startedAt??a.createdAt))[0]??null}function Qn(e){return{startedAt:e.startedAt??null,progressStage:e.progressStage??null,jobKind:e.plan.mode==="video"||e.plan.videoParams?"video":"image",variantCount:e.plan.plannedVariants||e.plan.prompts.length||1}}function Se(){return{sessions:[],turnsBySession:{},imagesById:{},imageIdsBySession:{},selectedSessionId:null,currentImageId:null,allowedTools:["ima2.get_image_context","ima2.web_search","ima2.generate_image","ima2.generate_video","ima2.get_generation_errors"],manifest:null,queueBySession:{},runSummaryBySession:{}}}function Fn(e){const n=e.filename.endsWith(".mp4");return{image:e.url,url:e.url,filename:e.filename,thumb:e.thumbUrl??void 0,prompt:e.prompt??void 0,revisedPrompt:e.revisedPrompt??null,createdAt:e.createdAt,mediaType:n?"video":"image",kind:"agent"}}function Gn(e,n,a){return{...e,turnsBySession:{...e.turnsBySession,[n]:[...e.turnsBySession[n]??[],...a]}}}function Un(e,n,a,s){const r=e.turnsBySession[n]??[];return{...e,turnsBySession:{...e.turnsBySession,[n]:[...r.filter(l=>l.id!==a),zn(s)]}}}function Hn(e,n,a){const s={...n.turnsBySession};for(const[r,l]of Object.entries(e.turnsBySession)){const o=s[r]??[],d=new Set(o.map(g=>g.id)),c=Math.max(0,...o.map(g=>g.createdAt??0)),i=l.filter(g=>a.has(g.id)||d.has(g.id)?!1:rt(g)||g.status==="streaming"?!0:(g.createdAt??0)>=c);i.length>0&&(s[r]=[...o,...i])}return{...n,turnsBySession:s}}function Yn(){const{t:e}=x(),n=$t(),a=E(h=>h.currentImage),s=E(h=>h.importLocalImageToHistory),r=E(h=>h.addHistoryItem),l=E(h=>h.selectHistory),o=E(h=>h.showToast),d=m.useRef(!1),c=m.useRef(0),i=m.useRef(0),g=m.useRef(null),[u,p]=m.useState(()=>Se()),[f,b]=m.useState(null),[v,w]=m.useState("image"),[q,G]=m.useState("image"),[U,T]=m.useState(null),[z,A]=m.useState(!1),[he,H]=m.useState(!1),[V,J]=m.useState(!1),[j,M]=m.useState(!1),[lt,R]=m.useState("reconnecting"),[me,pe]=m.useState(null),W=m.useCallback(h=>h instanceof Error?h.message:String(h),[]),ot=m.useCallback(()=>M(!1),[]),it=m.useCallback(()=>M(h=>!h),[]),L=m.useCallback(h=>{o(e("agent.workspaceActionFailed",{reason:W(h)}),!0)},[W,o,e]),X=m.useCallback(h=>{p({...Se(),...h}),b(h.selectedSessionId??null)},[]),ae=m.useCallback((h,y)=>{const S={...Se(),...h};p(_=>Hn(_,S,y)),b(h.selectedSessionId??null)},[]),$=m.useCallback(h=>{c.current+=1,X(h)},[X]),ct=m.useCallback((h,y)=>{c.current+=1,ae(h,y)},[ae]),ut=()=>{i.current+=1,R("generating")},dt=()=>{i.current=Math.max(0,i.current-1),i.current===0&&R("ready")},se=m.useCallback(async h=>{const y=++c.current;R("reconnecting"),pe(null);const S=await Re(h);if(y!==c.current)return;if(S.sessions.length>0){X(S),R("ready");return}const _=await $e({title:e("agent.newSession"),currentImage:a});y===c.current&&(X(_),R("ready"))},[X,a,e]),Ie=m.useCallback(async h=>{const y=++c.current,S=await Re(h);y===c.current&&(ae(S,new Set),R("ready"))},[ae]);m.useEffect(()=>{d.current||(d.current=!0,se().catch(h=>{pe(W(h)),R("reconnecting")}))},[W,se]);const Y=u.sessions.find(h=>h.id===f)??null,Z=u.currentImageId?u.imagesById[u.currentImageId]??null:null,re=f?(u.imageIdsBySession[f]??[]).map(h=>u.imagesById[h]).filter(h=>!!h):[],fe=Y?u.turnsBySession[Y.id]??[]:[],gt=fe.filter(ie).length,ht=fe.filter(h=>!ie(h)),K=f?u.queueBySession[f]??[]:[],k=f?u.runSummaryBySession[f]:void 0,mt=K.filter(h=>h.status==="queued"||h.status==="running").length,pt=Wn({turns:fe,queueItems:K,runSummary:k,localPendingCount:gt}),ee=Pe(Y?.generationSettings),ft=lt==="reconnecting"?"reconnecting":i.current>0||k?.status==="queued"||k?.status==="running"?"generating":"ready",xt=n!=="mobile-chat-image-sheet",xe=n==="desktop-three-pane"||n==="desktop-rail",Ae=n==="tablet-stacked"||n==="mobile-chat-image-sheet",bt=n==="desktop-three-pane"||n==="desktop-rail";m.useEffect(()=>{const h=Object.keys(u.imagesById);if(!g.current){(h.length>0||u.sessions.length>0)&&(g.current=new Set(h));return}const y=g.current,S=h.filter(N=>!y.has(N)).map(N=>u.imagesById[N]).filter(N=>!!N);if(S.length===0)return;for(const N of h)y.add(N);const _=S.map(Fn);for(const N of _)r(N);const P=_.reduce((N,I)=>(I.createdAt??0)>(N.createdAt??0)?I:N);l(P)},[u.imagesById,u.sessions.length,r,l]),m.useEffect(()=>{p(h=>{if(i.current>0)return h;let y=!1;const S={...h.turnsBySession};for(const[_,P]of Object.entries(S)){if(P.filter(ie).length===0)continue;const I=h.runSummaryBySession[_];I?.status==="queued"||I?.status==="running"||(S[_]=P.filter(je=>!ie(je)),y=!0)}return y?{...h,turnsBySession:S}:h})},[u.turnsBySession,u.runSummaryBySession]),m.useEffect(()=>{if(!f)return;const h=k?.status==="queued"||k?.status==="running",y=window.setInterval(()=>{Ie(f).catch(()=>R("reconnecting"))},h?1500:4e3);return()=>window.clearInterval(y)},[Ie,f,k?.queuedCount,k?.runningCount,k?.status]);const Te=h=>{A(!1),J(!1),se(h).catch(L)},Le=()=>{$e({title:e("agent.newSession"),currentImage:null}).then($).catch(L)},jt=h=>{const y=u.sessions.find(_=>_.id===h),S=window.prompt(e("agent.renameSession"),y?.title??"");S?.trim()&&ce(h,{title:S.trim()}).then($).catch(L)},yt=h=>{const y=u.sessions.find(S=>S.id===h);!y||!window.confirm(e("agent.deleteConfirm",{title:y.title}))||It(h).then($).catch(L)},le=h=>{if(!f)return;const y=Pe({...ee,...h});p(S=>({...S,sessions:S.sessions.map(_=>_.id===f?{..._,generationSettings:y,webSearchEnabled:y.webSearchEnabled}:_)})),ce(f,{generationSettings:h}).then($).catch(L)},vt=h=>{le({webSearchEnabled:h})},te=h=>{if(!f||u.currentImageId===h)return;const y=f;p(S=>({...S,currentImageId:h})),ce(y,{currentImageId:h}).then($).catch(L)},Me=h=>{T({id:Date.now(),text:h})},be=h=>{Tt(h).then($).catch(L)},oe=h=>{Lt(h).then($).catch(L)},Ee=k?.status==="error"?K.find(h=>h.status==="failed")?.id:void 0,St=Ee?()=>oe(Ee):void 0,_t=h=>{!f||h.length===0||Pn({sessionId:f,files:h,importLocalImageToHistory:s,applyWorkspace:$}).catch(L)},wt=h=>{if(!f)return;const y=f,S=Date.now(),_=Bn(h,S),P=On(e("agent.pending"),S+1),N=new Set([_.id]);ut(),p(I=>Gn(I,y,[_,P])),At(y,h,ee).then(I=>ct(I.workspace,N)).catch(I=>{const qe=W(I);p(je=>Un(je,y,P.id,qe)),L(I)}).finally(dt)};return me?t.jsxs("main",{className:`agent-workspace agent-workspace--${n} agent-workspace--boot-error`,"data-layout":n,"aria-label":e("agent.workspace"),children:[Ae?t.jsx(Ke,{layoutMode:n,session:null,currentImage:null,activeJobCount:0,onOpenSessions:()=>{},onOpenImage:()=>{},onOpenQueue:()=>{}}):null,t.jsxs("section",{className:"agent-workspace__boot-error",role:"alert",children:[t.jsx("strong",{children:e("agent.bootFailed")}),t.jsx("span",{title:me,children:me}),t.jsx("button",{type:"button",onClick:()=>{se().catch(h=>pe(W(h)))},children:e("agent.bootRetry")})]})]}):t.jsxs("main",{className:`agent-workspace agent-workspace--${n}${xe&&j?" agent-workspace--tools-docked":""}`,"data-layout":n,"aria-label":e("agent.workspace"),children:[bt?t.jsx("div",{className:"agent-session-rail-wrap",children:t.jsx(Rn,{sessions:u.sessions,selectedId:f??"",imagesById:u.imagesById,runSummaryBySession:u.runSummaryBySession,onCreate:Le,onSelect:Te,onOpenDrawer:()=>A(!0)})}):null,Ae?t.jsx(Ke,{layoutMode:n,session:Y,currentImage:Z,activeJobCount:mt,onOpenSessions:()=>A(!0),onOpenImage:()=>H(!0),onOpenQueue:()=>J(!0)}):null,t.jsxs("div",{className:"agent-workspace__body",children:[t.jsx(fn,{session:Y,turns:ht,imagesById:u.imagesById,currentImageId:u.currentImageId,runtimeStatus:ft,runProgress:pt,settings:ee,insertedPrompt:U,onSettingsChange:le,onOpenModelTab:()=>{G("model"),M(!0)},onWebSearchChange:vt,onAttachFiles:_t,onImageSelect:te,onSend:wt,onRetryRun:St}),xe?t.jsx($n,{currentImage:Z,images:re,onImageSelect:te,onOpenPanel:it,toolsPanelOpen:j}):xt?t.jsx(We,{currentImage:Z,images:re,contextTab:v,sidebarTab:q,queueItems:K,runSummary:k,settings:ee,onContextTabChange:w,onSidebarTabChange:G,onImageSelect:te,onSettingsChange:le,onInsertPrompt:Me,onCancelQueue:be,onRetryQueue:oe}):null,xe&&j?t.jsx(We,{overlay:!0,onClose:ot,currentImage:Z,images:re,contextTab:v,sidebarTab:q,queueItems:K,runSummary:k,settings:ee,onContextTabChange:w,onSidebarTabChange:G,onImageSelect:te,onSettingsChange:le,onInsertPrompt:Me,onCancelQueue:be,onRetryQueue:oe}):null]}),t.jsx(qn,{open:z,sessions:u.sessions,selectedId:f??"",imagesById:u.imagesById,runSummaryBySession:u.runSummaryBySession,onClose:()=>A(!1),onCreate:Le,onSelect:Te,onRename:jt,onDelete:yt}),t.jsx(vn,{open:he,currentImage:Z,images:re,activeTab:v,onTabChange:w,onImageSelect:te,onClose:()=>H(!1)}),t.jsx(kn,{open:V,items:K,summary:k,onCancel:be,onRetry:oe,onClose:()=>J(!1)})]})}export{Yn as AgentWorkspace};