ima2-gen 1.1.21 → 1.1.23

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 (214) hide show
  1. package/README.md +44 -7
  2. package/bin/commands/video.js +14 -0
  3. package/bin/ima2.js +14 -4
  4. package/bin/lib/platform.js +34 -5
  5. package/docs/README.ko.md +43 -2
  6. package/lib/agentQueueWorker.js +6 -0
  7. package/lib/agentRuntime.js +3 -2
  8. package/lib/atomicWrite.js +14 -0
  9. package/lib/grokImageAdapter.js +6 -0
  10. package/lib/grokProxyLauncher.js +5 -3
  11. package/lib/grokVideoAdapter.js +1 -1
  12. package/lib/grokVideoPlannerPrompt.js +10 -0
  13. package/lib/inflight.js +1 -1
  14. package/lib/oauthLauncher.js +5 -0
  15. package/lib/videoFrameExtract.js +3 -3
  16. package/package.json +5 -7
  17. package/routes/capabilities.js +13 -0
  18. package/routes/edit.js +2 -1
  19. package/routes/generate.js +32 -6
  20. package/routes/health.js +4 -3
  21. package/routes/multimode.js +2 -1
  22. package/routes/video.js +35 -3
  23. package/server.js +29 -2
  24. package/skills/ima2/SKILL.md +48 -6
  25. package/ui/dist/.vite/manifest.json +12 -12
  26. package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-C21zqdTZ.js} +1 -1
  27. package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-BN-ga1lG.js} +1 -1
  28. package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BbMa4IhI.js} +1 -1
  29. package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DRwBJRDQ.js} +1 -1
  30. package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-Dp85kHCq.js} +2 -2
  31. package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BE8Q8MLD.js} +1 -1
  32. package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-PtH5x0sc.js} +1 -1
  33. package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-FnM9tHI9.js} +2 -2
  34. package/ui/dist/assets/SettingsWorkspace-MARPGyBL.js +1 -0
  35. package/ui/dist/assets/index-BAFI6htx.js +42 -0
  36. package/ui/dist/assets/{index-31uVIdt4.js → index-BSXxr_Bt.js} +1 -1
  37. package/ui/dist/assets/index-DS-ADE7U.css +1 -0
  38. package/ui/dist/index.html +2 -2
  39. package/bin/commands/annotate.ts +0 -119
  40. package/bin/commands/cancel.ts +0 -48
  41. package/bin/commands/canvas-versions.ts +0 -80
  42. package/bin/commands/capabilities.ts +0 -110
  43. package/bin/commands/cardnews.ts +0 -249
  44. package/bin/commands/comfy.ts +0 -54
  45. package/bin/commands/config.ts +0 -186
  46. package/bin/commands/defaults.ts +0 -192
  47. package/bin/commands/doctor.ts +0 -202
  48. package/bin/commands/edit.ts +0 -150
  49. package/bin/commands/gen.ts +0 -214
  50. package/bin/commands/grok.ts +0 -90
  51. package/bin/commands/history.ts +0 -146
  52. package/bin/commands/ls.ts +0 -64
  53. package/bin/commands/metadata.ts +0 -39
  54. package/bin/commands/multimode.ts +0 -196
  55. package/bin/commands/node.ts +0 -166
  56. package/bin/commands/observability.ts +0 -176
  57. package/bin/commands/ping.ts +0 -31
  58. package/bin/commands/prompt-sub/build.ts +0 -101
  59. package/bin/commands/prompt.ts +0 -492
  60. package/bin/commands/ps.ts +0 -81
  61. package/bin/commands/session.ts +0 -266
  62. package/bin/commands/show.ts +0 -72
  63. package/bin/commands/skill.ts +0 -70
  64. package/bin/commands/video.ts +0 -442
  65. package/bin/ima2.ts +0 -430
  66. package/bin/lib/args.ts +0 -92
  67. package/bin/lib/browser-id.ts +0 -16
  68. package/bin/lib/client.ts +0 -122
  69. package/bin/lib/config-store.ts +0 -120
  70. package/bin/lib/destructive-confirm.ts +0 -19
  71. package/bin/lib/doctor-checks.ts +0 -91
  72. package/bin/lib/error-hints.ts +0 -23
  73. package/bin/lib/files.ts +0 -39
  74. package/bin/lib/output.ts +0 -73
  75. package/bin/lib/platform.ts +0 -99
  76. package/bin/lib/recover-output.ts +0 -139
  77. package/bin/lib/sse.ts +0 -73
  78. package/bin/lib/star-prompt.ts +0 -97
  79. package/bin/lib/storage-doctor.ts +0 -39
  80. package/bin/lib/ui-build.ts +0 -85
  81. package/config.ts +0 -354
  82. package/lib/agentCommandParser.ts +0 -69
  83. package/lib/agentGenerationPlanner.ts +0 -273
  84. package/lib/agentQuestionResponder.ts +0 -266
  85. package/lib/agentQueueStore.ts +0 -270
  86. package/lib/agentQueueWorker.ts +0 -89
  87. package/lib/agentRuntime.ts +0 -604
  88. package/lib/agentSettings.ts +0 -72
  89. package/lib/agentStore.ts +0 -422
  90. package/lib/agentStoreRows.ts +0 -136
  91. package/lib/agentTypes.ts +0 -154
  92. package/lib/apiCachePolicy.ts +0 -11
  93. package/lib/assetLifecycle.ts +0 -146
  94. package/lib/canvasVersionStore.ts +0 -223
  95. package/lib/capabilities.ts +0 -126
  96. package/lib/cardNewsGenerator.ts +0 -271
  97. package/lib/cardNewsJobStore.ts +0 -142
  98. package/lib/cardNewsManifestStore.ts +0 -154
  99. package/lib/cardNewsPlanner.ts +0 -236
  100. package/lib/cardNewsPlannerClient.ts +0 -155
  101. package/lib/cardNewsPlannerPrompt.ts +0 -62
  102. package/lib/cardNewsPlannerSchema.ts +0 -321
  103. package/lib/cardNewsRoleTemplateStore.ts +0 -47
  104. package/lib/cardNewsTemplateStore.ts +0 -252
  105. package/lib/codexDetect.ts +0 -71
  106. package/lib/comfyBridge.ts +0 -235
  107. package/lib/composerSnapshot.ts +0 -33
  108. package/lib/configKeys.ts +0 -62
  109. package/lib/db.ts +0 -295
  110. package/lib/errInfo.ts +0 -43
  111. package/lib/errorClassify.ts +0 -100
  112. package/lib/generationCancel.ts +0 -28
  113. package/lib/generationErrors.ts +0 -238
  114. package/lib/grokImageAdapter.ts +0 -513
  115. package/lib/grokMultimodeAdapter.ts +0 -84
  116. package/lib/grokProxyLauncher.ts +0 -153
  117. package/lib/grokRuntime.ts +0 -23
  118. package/lib/grokSizeMapper.ts +0 -71
  119. package/lib/grokVideoAdapter.ts +0 -458
  120. package/lib/grokVideoCanvas.ts +0 -26
  121. package/lib/grokVideoDownload.ts +0 -59
  122. package/lib/grokVideoPlannerPrompt.ts +0 -67
  123. package/lib/historyIndex.ts +0 -51
  124. package/lib/historyList.ts +0 -181
  125. package/lib/imageMetadata.ts +0 -113
  126. package/lib/imageMetadataStore.ts +0 -67
  127. package/lib/imageModels.ts +0 -165
  128. package/lib/inflight.ts +0 -281
  129. package/lib/localImportStore.ts +0 -114
  130. package/lib/logger.ts +0 -161
  131. package/lib/nodeStore.ts +0 -91
  132. package/lib/oauthLauncher.ts +0 -94
  133. package/lib/oauthNormalize.ts +0 -30
  134. package/lib/oauthProxy/errors.ts +0 -128
  135. package/lib/oauthProxy/generators.ts +0 -494
  136. package/lib/oauthProxy/index.ts +0 -28
  137. package/lib/oauthProxy/prompts.ts +0 -123
  138. package/lib/oauthProxy/references.ts +0 -45
  139. package/lib/oauthProxy/runtime.ts +0 -115
  140. package/lib/oauthProxy/streams.ts +0 -232
  141. package/lib/oauthProxy/types.ts +0 -9
  142. package/lib/oauthProxy.ts +0 -3
  143. package/lib/openDirectory.ts +0 -47
  144. package/lib/pngInfo.ts +0 -26
  145. package/lib/promptBuilder/attachments.ts +0 -74
  146. package/lib/promptBuilder/client.ts +0 -130
  147. package/lib/promptBuilder/constants.ts +0 -9
  148. package/lib/promptBuilder/context.ts +0 -36
  149. package/lib/promptBuilder/errors.ts +0 -12
  150. package/lib/promptBuilder/requestSchema.ts +0 -56
  151. package/lib/promptBuilder/responseParser.ts +0 -219
  152. package/lib/promptBuilder/systemPrompt.ts +0 -135
  153. package/lib/promptBuilder/transport.ts +0 -94
  154. package/lib/promptBuilder/types.ts +0 -109
  155. package/lib/promptImport/curatedSources.ts +0 -141
  156. package/lib/promptImport/discoveryRegistry.ts +0 -329
  157. package/lib/promptImport/errors.ts +0 -18
  158. package/lib/promptImport/githubDiscovery.ts +0 -309
  159. package/lib/promptImport/githubFolder.ts +0 -397
  160. package/lib/promptImport/githubSource.ts +0 -257
  161. package/lib/promptImport/gptImageHints.ts +0 -70
  162. package/lib/promptImport/parsePromptCandidates.ts +0 -179
  163. package/lib/promptImport/promptIndex.ts +0 -326
  164. package/lib/promptImport/rankPromptCandidates.ts +0 -65
  165. package/lib/promptImport/types.ts +0 -103
  166. package/lib/promptSafetyPolicy.ts +0 -5
  167. package/lib/providerOptions.ts +0 -56
  168. package/lib/referenceImageCompress.ts +0 -84
  169. package/lib/refs.ts +0 -133
  170. package/lib/requestLogger.ts +0 -49
  171. package/lib/responsesDoctor.ts +0 -456
  172. package/lib/responsesErrors.ts +0 -83
  173. package/lib/responsesFallback.ts +0 -114
  174. package/lib/responsesImageAdapter.ts +0 -466
  175. package/lib/responsesParse.ts +0 -452
  176. package/lib/responsesTools.ts +0 -28
  177. package/lib/runtimeContext.ts +0 -146
  178. package/lib/runtimePorts.ts +0 -105
  179. package/lib/sessionStore.ts +0 -308
  180. package/lib/storageMigration.ts +0 -310
  181. package/lib/styleSheet.ts +0 -139
  182. package/lib/systemTrash.ts +0 -20
  183. package/lib/videoContinuity.ts +0 -180
  184. package/lib/videoFrameExtract.ts +0 -78
  185. package/lib/videoSeriesChain.ts +0 -29
  186. package/lib/visibleTextLanguagePolicy.ts +0 -7
  187. package/routes/agent.ts +0 -308
  188. package/routes/annotations.ts +0 -118
  189. package/routes/canvasVersions.ts +0 -69
  190. package/routes/capabilities.ts +0 -18
  191. package/routes/cardNews.ts +0 -211
  192. package/routes/comfy.ts +0 -43
  193. package/routes/edit.ts +0 -352
  194. package/routes/generate.ts +0 -492
  195. package/routes/grok.ts +0 -24
  196. package/routes/health.ts +0 -123
  197. package/routes/history.ts +0 -221
  198. package/routes/imageImport.ts +0 -37
  199. package/routes/index.ts +0 -52
  200. package/routes/metadata.ts +0 -77
  201. package/routes/multimode.ts +0 -499
  202. package/routes/nodes.ts +0 -578
  203. package/routes/promptBuilder.ts +0 -37
  204. package/routes/promptImport.ts +0 -379
  205. package/routes/prompts.ts +0 -428
  206. package/routes/quota.ts +0 -89
  207. package/routes/sessions.ts +0 -317
  208. package/routes/storage.ts +0 -47
  209. package/routes/video.ts +0 -300
  210. package/routes/videoExtended.ts +0 -284
  211. package/server.ts +0 -293
  212. package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
  213. package/ui/dist/assets/index-CjgnNtgt.css +0 -1
  214. package/ui/dist/assets/index-Da2s4_-5.js +0 -36
package/routes/history.ts DELETED
@@ -1,221 +0,0 @@
1
- import type { Express, Request, Response } from "express";
2
- import { trashAsset, restoreAsset, deleteAssetPermanent } from "../lib/assetLifecycle.js";
3
- import {
4
- getHistoryIndex,
5
- invalidateFavoriteOverlay,
6
- invalidateHistoryIndex,
7
- type HistoryIndexRow,
8
- } from "../lib/historyIndex.js";
9
- import { getSessionTitleMap } from "../lib/sessionStore.js";
10
- import { logError, logEvent } from "../lib/logger.js";
11
- import { getDb } from "../lib/db.js";
12
-
13
- import { errInfo } from "../lib/errInfo.js";
14
- import { requireRuntimeContext, type RouteRuntimeContext } from "../lib/runtimeContext.js";
15
-
16
- function asStr(value: unknown): string {
17
- return typeof value === "string" ? value : "";
18
- }
19
-
20
- function matchesHistoryFilters(
21
- row: HistoryIndexRow,
22
- params: {
23
- sinceTs: number;
24
- beforeTs: number;
25
- beforeFn: string | null;
26
- sessionId: string | null;
27
- requestId: string | null;
28
- favoritesOnly: boolean;
29
- favoriteSet: Set<string>;
30
- },
31
- ): boolean {
32
- if (Number.isFinite(params.sinceTs) && row.createdAt <= params.sinceTs) return false;
33
- if (Number.isFinite(params.beforeTs)) {
34
- if (row.createdAt > params.beforeTs) return false;
35
- if (row.createdAt === params.beforeTs) {
36
- if (!params.beforeFn || row.filename >= params.beforeFn) return false;
37
- }
38
- }
39
- if (params.sessionId && row.sessionId !== params.sessionId) return false;
40
- if (params.requestId && row.requestId !== params.requestId) return false;
41
- if (params.favoritesOnly && !params.favoriteSet.has(row.filename)) return false;
42
- return true;
43
- }
44
-
45
- function selectHistoryPage(
46
- rows: HistoryIndexRow[],
47
- limit: number,
48
- params: Parameters<typeof matchesHistoryFilters>[1],
49
- ) {
50
- const selected: HistoryIndexRow[] = [];
51
- for (const row of rows) {
52
- if (!matchesHistoryFilters(row, params)) continue;
53
- selected.push(row);
54
- if (selected.length > limit) break;
55
- }
56
- const pageRows = selected.slice(0, limit);
57
- const page = pageRows.map((r) => ({ ...r, isFavorite: params.favoriteSet.has(r.filename) }));
58
- const last = page[page.length - 1];
59
- return {
60
- page,
61
- nextCursor: selected.length > limit && last
62
- ? { before: last.createdAt, beforeFilename: last.filename }
63
- : null,
64
- };
65
- }
66
-
67
- export function registerHistoryRoutes(app: Express, ctxRaw: RouteRuntimeContext) {
68
- const ctx = requireRuntimeContext(ctxRaw);
69
- app.get("/api/history", async (req: Request, res: Response) => {
70
- try {
71
- const limitRaw = parseInt(asStr(req.query.limit));
72
- const limit = Math.min(
73
- Number.isFinite(limitRaw) && limitRaw > 0 ? limitRaw : ctx.config.history.defaultPageSize,
74
- ctx.config.history.maxPageCap,
75
- );
76
- const beforeTs = parseInt(asStr(req.query.before));
77
- const beforeFn = typeof req.query.beforeFilename === "string" ? req.query.beforeFilename : null;
78
- const sinceTs = parseInt(asStr(req.query.since));
79
- const sessionId = typeof req.query.sessionId === "string" ? req.query.sessionId : null;
80
- const requestId = typeof req.query.requestId === "string" ? req.query.requestId : null;
81
- const groupBy = req.query.groupBy === "session" ? "session" : null;
82
- const favoritesOnly =
83
- req.query.favoritesOnly === "1" || req.query.favoritesOnly === "true";
84
- const browserId = typeof req.headers["x-ima2-browser-id"] === "string"
85
- ? req.headers["x-ima2-browser-id"]
86
- : null;
87
-
88
- const { rows } = await getHistoryIndex(ctx.config.storage.generatedDir);
89
-
90
- // Enrich with favorite status
91
- let favoriteSet = new Set<string>();
92
- if (browserId) {
93
- const db = getDb();
94
- const favRows = db.prepare("SELECT filename FROM gallery_favorites WHERE browser_id = ?").all(browserId) as Array<{ filename: string }>;
95
- favoriteSet = new Set(favRows.map((r) => r.filename));
96
- }
97
-
98
- const { page, nextCursor } = selectHistoryPage(rows, limit, {
99
- sinceTs,
100
- beforeTs,
101
- beforeFn,
102
- sessionId,
103
- requestId,
104
- favoritesOnly,
105
- favoriteSet,
106
- });
107
-
108
- if (groupBy === "session") {
109
- const groups = new Map<string, { sessionId: any; items: any[]; lastUsedAt: any }>();
110
- const loose: any[] = [];
111
- for (const row of page) {
112
- if (row.sessionId) {
113
- let group = groups.get(row.sessionId);
114
- if (!group) {
115
- group = { sessionId: row.sessionId, items: [], lastUsedAt: row.createdAt };
116
- groups.set(row.sessionId, group);
117
- }
118
- group.items.push(row);
119
- if (row.createdAt > group.lastUsedAt) group.lastUsedAt = row.createdAt;
120
- } else {
121
- loose.push(row);
122
- }
123
- }
124
- const titleMap = getSessionTitleMap(Array.from(groups.keys()));
125
- const sessions = Array.from(groups.values())
126
- .map((group) => ({
127
- ...group,
128
- title: titleMap.get(group.sessionId) || null,
129
- label: titleMap.get(group.sessionId) || group.sessionId.slice(0, 8),
130
- }))
131
- .sort((a, b) => b.lastUsedAt - a.lastUsedAt);
132
- logEvent("history", "grouped", {
133
- sessions: sessions.length,
134
- loose: loose.length,
135
- total: rows.length,
136
- });
137
- return res.json({ sessions, loose, total: rows.length, nextCursor });
138
- }
139
-
140
- res.json({ items: page, total: rows.length, nextCursor });
141
- } catch (e) {
142
- const err = errInfo(e);
143
- logError("history", "error", err.raw);
144
- res.status(500).json({ error: err.message });
145
- }
146
- });
147
-
148
- app.delete("/api/history/:filename/permanent", async (req: Request<{ filename: string }>, res: Response) => {
149
- try {
150
- const filename = decodeURIComponent(req.params.filename);
151
- const result = await deleteAssetPermanent(ctx.rootDir, filename);
152
- invalidateHistoryIndex();
153
- res.json(result);
154
- } catch (e) {
155
- const err = errInfo(e);
156
- res.status(err.status || 500).json({ error: err.message, code: err.code });
157
- }
158
- });
159
-
160
- app.delete("/api/history/:filename", async (req: Request<{ filename: string }>, res: Response) => {
161
- try {
162
- const filename = decodeURIComponent(req.params.filename);
163
- const result = await trashAsset(ctx.rootDir, filename);
164
- invalidateHistoryIndex();
165
- res.json(result);
166
- } catch (e) {
167
- const err = errInfo(e);
168
- res.status(err.status || 500).json({ error: err.message, code: err.code });
169
- }
170
- });
171
-
172
- app.post("/api/history/:filename/restore", async (req: Request<{ filename: string }>, res: Response) => {
173
- try {
174
- const filename = decodeURIComponent(req.params.filename);
175
- const body = (req.body ?? {}) as { trashId?: unknown };
176
- const trashId = typeof body.trashId === "string" ? body.trashId : null;
177
- if (!trashId) return res.status(400).json({ error: "trashId required" });
178
- const result = await restoreAsset(ctx.rootDir, trashId, filename);
179
- invalidateHistoryIndex();
180
- res.json(result);
181
- } catch (e) {
182
- const err = errInfo(e);
183
- res.status(err.status || 500).json({ error: err.message });
184
- }
185
- });
186
-
187
- app.post("/api/history/favorite", async (req: Request, res: Response) => {
188
- try {
189
- const db = getDb();
190
- const body = (req.body ?? {}) as { filename?: unknown };
191
- const { filename } = body;
192
- const browserId = req.headers["x-ima2-browser-id"];
193
-
194
- if (!filename || typeof filename !== "string") {
195
- return res.status(400).json({ error: "filename is required" });
196
- }
197
- if (!browserId || typeof browserId !== "string") {
198
- return res.status(400).json({ error: "X-Ima2-Browser-Id header is required" });
199
- }
200
-
201
- const existing = db.prepare("SELECT id FROM gallery_favorites WHERE browser_id = ? AND filename = ?").get(browserId, filename);
202
-
203
- if (existing) {
204
- db.prepare("DELETE FROM gallery_favorites WHERE browser_id = ? AND filename = ?").run(browserId, filename);
205
- invalidateFavoriteOverlay();
206
- res.json({ isFavorite: false });
207
- } else {
208
- const id = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
209
- db.prepare(
210
- "INSERT INTO gallery_favorites (id, browser_id, filename, favorited_at) VALUES (?, ?, ?, ?)"
211
- ).run(id, browserId, filename, Math.floor(Date.now() / 1000));
212
- invalidateFavoriteOverlay();
213
- res.json({ isFavorite: true });
214
- }
215
- } catch (e) {
216
- const err = errInfo(e);
217
- logError("history", "favorite_error", err.raw);
218
- res.status(500).json({ error: err.message });
219
- }
220
- });
221
- }
@@ -1,37 +0,0 @@
1
- import express, { type Express, type Request, type Response } from "express";
2
- import { createLocalImport } from "../lib/localImportStore.js";
3
-
4
- import { errInfo } from "../lib/errInfo.js";
5
- import { requireRuntimeContext, type RouteRuntimeContext } from "../lib/runtimeContext.js";
6
- function decodeHeader(value: unknown): string | null {
7
- if (typeof value !== "string" || !value) return null;
8
- try {
9
- return decodeURIComponent(value);
10
- } catch {
11
- return value;
12
- }
13
- }
14
-
15
- export function registerImageImportRoutes(app: Express, ctxRaw: RouteRuntimeContext) {
16
- const ctx = requireRuntimeContext(ctxRaw);
17
- const rawImage = express.raw({
18
- type: ["image/png", "image/jpeg", "image/webp"],
19
- limit: ctx.config.server.bodyLimit,
20
- });
21
-
22
- app.post("/api/history/import-local", rawImage, async (req: Request, res: Response) => {
23
- try {
24
- const item = await createLocalImport(ctx, {
25
- buffer: Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0),
26
- originalFilename: decodeHeader(req.headers["x-ima2-original-filename"]),
27
- });
28
- res.status(201).json({ item });
29
- } catch (e) {
30
- const err = errInfo(e);
31
- res.status(err.status || 500).json({
32
- error: err.message,
33
- code: err.code || "IMPORT_FAILED",
34
- });
35
- }
36
- });
37
- }
package/routes/index.ts DELETED
@@ -1,52 +0,0 @@
1
- import type { Express } from "express";
2
- import { registerCapabilitiesRoutes } from "./capabilities.js";
3
- import { registerHealthRoutes } from "./health.js";
4
- import { registerHistoryRoutes } from "./history.js";
5
- import { registerSessionRoutes } from "./sessions.js";
6
- import { registerEditRoutes } from "./edit.js";
7
- import { registerNodeRoutes } from "./nodes.js";
8
- import { registerGenerateRoutes } from "./generate.js";
9
- import { registerMultimodeRoutes } from "./multimode.js";
10
- import { registerStorageRoutes } from "./storage.js";
11
- import { registerCardNewsRoutes } from "./cardNews.js";
12
- import { registerMetadataRoutes } from "./metadata.js";
13
- import { registerPromptRoutes } from "./prompts.js";
14
- import { registerPromptImportRoutes } from "./promptImport.js";
15
- import { registerAnnotationRoutes } from "./annotations.js";
16
- import { registerCanvasVersionRoutes } from "./canvasVersions.js";
17
- import { registerComfyRoutes } from "./comfy.js";
18
- import { registerImageImportRoutes } from "./imageImport.js";
19
- import { registerPromptBuilderRoutes } from "./promptBuilder.js";
20
- import { registerAgentRoutes } from "./agent.js";
21
- import { registerGrokRoutes } from "./grok.js";
22
- import { registerVideoRoutes } from "./video.js";
23
- import { registerVideoExtendedRoutes } from "./videoExtended.js";
24
- import { registerQuotaRoutes } from "./quota.js";
25
- import { type RouteRuntimeContext, requireRuntimeContext } from "../lib/runtimeContext.js";
26
-
27
- export function configureRoutes(app: Express, ctxRaw: RouteRuntimeContext) {
28
- const ctx = requireRuntimeContext(ctxRaw);
29
- registerHealthRoutes(app, ctx);
30
- registerCapabilitiesRoutes(app, ctx);
31
- registerStorageRoutes(app, ctx);
32
- registerMetadataRoutes(app, ctx);
33
- registerHistoryRoutes(app, ctx);
34
- registerAnnotationRoutes(app, ctx);
35
- registerCanvasVersionRoutes(app, ctx);
36
- registerImageImportRoutes(app, ctx);
37
- registerComfyRoutes(app, ctx);
38
- registerSessionRoutes(app, ctx);
39
- registerEditRoutes(app, ctx);
40
- registerNodeRoutes(app, ctx);
41
- if (ctx.config.features.cardNews) registerCardNewsRoutes(app, ctx);
42
- registerMultimodeRoutes(app, ctx);
43
- registerGenerateRoutes(app, ctx);
44
- registerAgentRoutes(app, ctx);
45
- registerPromptBuilderRoutes(app, ctx);
46
- registerPromptRoutes(app, ctx);
47
- registerPromptImportRoutes(app, ctx);
48
- registerGrokRoutes(app, ctx);
49
- registerVideoRoutes(app, ctx);
50
- registerVideoExtendedRoutes(app, ctx);
51
- registerQuotaRoutes(app, ctx);
52
- }
@@ -1,77 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- import type { Express, Request, Response } from "express";
3
- import { errInfo } from "../lib/errInfo.js";
4
- import {
5
- isSupportedMetadataFormat,
6
- normalizeImageMetadataFormat,
7
- readEmbeddedImageMetadata,
8
- } from "../lib/imageMetadataStore.js";
9
- import { requireRuntimeContext, type RouteRuntimeContext } from "../lib/runtimeContext.js";
10
-
11
- const MIME_FORMATS: Record<string, string> = {
12
- "image/png": "png",
13
- "image/jpeg": "jpeg",
14
- "image/webp": "webp",
15
- };
16
-
17
- function parseDataUrl(dataUrl: unknown): { mime: string; rawB64: string } | null {
18
- if (typeof dataUrl !== "string") return null;
19
- const match = /^data:([^;,]+);base64,(.+)$/s.exec(dataUrl);
20
- if (!match) return null;
21
- return { mime: match[1].toLowerCase(), rawB64: match[2] };
22
- }
23
-
24
- export function registerMetadataRoutes(app: Express, ctxRaw: RouteRuntimeContext) {
25
- const ctx = requireRuntimeContext(ctxRaw);
26
- app.post("/api/metadata/read", async (req: Request, res: Response) => {
27
- try {
28
- const body = (req.body ?? {}) as { dataUrl?: unknown };
29
- const parsed = parseDataUrl(body.dataUrl);
30
- if (!parsed) {
31
- return res.status(400).json({
32
- ok: false,
33
- code: "IMAGE_METADATA_INVALID",
34
- error: "A base64 image data URL is required.",
35
- });
36
- }
37
- if (parsed.rawB64.length > ctx.config.limits.maxMetadataReadB64Bytes) {
38
- return res.status(413).json({
39
- ok: false,
40
- code: "IMAGE_METADATA_TOO_LARGE",
41
- error: "Image is too large to inspect for metadata.",
42
- });
43
- }
44
- const format = normalizeImageMetadataFormat(MIME_FORMATS[parsed.mime]);
45
- if (!isSupportedMetadataFormat(format)) {
46
- return res.status(400).json({
47
- ok: false,
48
- code: "IMAGE_METADATA_UNSUPPORTED_FORMAT",
49
- error: "Only PNG, JPEG, and WebP metadata can be inspected.",
50
- });
51
- }
52
- const result = await readEmbeddedImageMetadata(Buffer.from(parsed.rawB64, "base64"));
53
- if (!result.metadata) {
54
- return res.json({
55
- ok: true,
56
- metadata: null,
57
- source: null,
58
- code: "IMAGE_METADATA_NOT_FOUND",
59
- warnings: result.warnings,
60
- });
61
- }
62
- return res.json({
63
- ok: true,
64
- metadata: result.metadata,
65
- source: result.source,
66
- warnings: result.warnings,
67
- });
68
- } catch (error) {
69
- const err = errInfo(error);
70
- return res.status(400).json({
71
- ok: false,
72
- code: err.code || "IMAGE_METADATA_INVALID",
73
- error: err.message || "Could not read image metadata.",
74
- });
75
- }
76
- });
77
- }