ima2-gen 1.1.21 → 1.1.22

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 (208) hide show
  1. package/README.md +30 -4
  2. package/bin/ima2.js +14 -4
  3. package/bin/lib/platform.js +34 -5
  4. package/docs/README.ko.md +31 -0
  5. package/lib/agentQueueWorker.js +6 -0
  6. package/lib/agentRuntime.js +3 -2
  7. package/lib/atomicWrite.js +14 -0
  8. package/lib/grokProxyLauncher.js +5 -3
  9. package/lib/inflight.js +1 -1
  10. package/lib/oauthLauncher.js +5 -0
  11. package/lib/videoFrameExtract.js +3 -3
  12. package/package.json +5 -7
  13. package/routes/edit.js +2 -1
  14. package/routes/generate.js +4 -3
  15. package/routes/health.js +4 -3
  16. package/routes/multimode.js +2 -1
  17. package/routes/video.js +4 -2
  18. package/server.js +29 -2
  19. package/ui/dist/.vite/manifest.json +12 -12
  20. package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-COxQ5TjU.js} +1 -1
  21. package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
  22. package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BSsclEBh.js} +1 -1
  23. package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
  24. package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-CVwT0rLd.js} +2 -2
  25. package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
  26. package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
  27. package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-BhFgeKnY.js} +2 -2
  28. package/ui/dist/assets/SettingsWorkspace-CfjrlH5R.js +1 -0
  29. package/ui/dist/assets/index-C-mur7pa.css +1 -0
  30. package/ui/dist/assets/index-CCP5nUOj.js +42 -0
  31. package/ui/dist/assets/{index-31uVIdt4.js → index-Cxhzi3bs.js} +1 -1
  32. package/ui/dist/index.html +2 -2
  33. package/bin/commands/annotate.ts +0 -119
  34. package/bin/commands/cancel.ts +0 -48
  35. package/bin/commands/canvas-versions.ts +0 -80
  36. package/bin/commands/capabilities.ts +0 -110
  37. package/bin/commands/cardnews.ts +0 -249
  38. package/bin/commands/comfy.ts +0 -54
  39. package/bin/commands/config.ts +0 -186
  40. package/bin/commands/defaults.ts +0 -192
  41. package/bin/commands/doctor.ts +0 -202
  42. package/bin/commands/edit.ts +0 -150
  43. package/bin/commands/gen.ts +0 -214
  44. package/bin/commands/grok.ts +0 -90
  45. package/bin/commands/history.ts +0 -146
  46. package/bin/commands/ls.ts +0 -64
  47. package/bin/commands/metadata.ts +0 -39
  48. package/bin/commands/multimode.ts +0 -196
  49. package/bin/commands/node.ts +0 -166
  50. package/bin/commands/observability.ts +0 -176
  51. package/bin/commands/ping.ts +0 -31
  52. package/bin/commands/prompt-sub/build.ts +0 -101
  53. package/bin/commands/prompt.ts +0 -492
  54. package/bin/commands/ps.ts +0 -81
  55. package/bin/commands/session.ts +0 -266
  56. package/bin/commands/show.ts +0 -72
  57. package/bin/commands/skill.ts +0 -70
  58. package/bin/commands/video.ts +0 -442
  59. package/bin/ima2.ts +0 -430
  60. package/bin/lib/args.ts +0 -92
  61. package/bin/lib/browser-id.ts +0 -16
  62. package/bin/lib/client.ts +0 -122
  63. package/bin/lib/config-store.ts +0 -120
  64. package/bin/lib/destructive-confirm.ts +0 -19
  65. package/bin/lib/doctor-checks.ts +0 -91
  66. package/bin/lib/error-hints.ts +0 -23
  67. package/bin/lib/files.ts +0 -39
  68. package/bin/lib/output.ts +0 -73
  69. package/bin/lib/platform.ts +0 -99
  70. package/bin/lib/recover-output.ts +0 -139
  71. package/bin/lib/sse.ts +0 -73
  72. package/bin/lib/star-prompt.ts +0 -97
  73. package/bin/lib/storage-doctor.ts +0 -39
  74. package/bin/lib/ui-build.ts +0 -85
  75. package/config.ts +0 -354
  76. package/lib/agentCommandParser.ts +0 -69
  77. package/lib/agentGenerationPlanner.ts +0 -273
  78. package/lib/agentQuestionResponder.ts +0 -266
  79. package/lib/agentQueueStore.ts +0 -270
  80. package/lib/agentQueueWorker.ts +0 -89
  81. package/lib/agentRuntime.ts +0 -604
  82. package/lib/agentSettings.ts +0 -72
  83. package/lib/agentStore.ts +0 -422
  84. package/lib/agentStoreRows.ts +0 -136
  85. package/lib/agentTypes.ts +0 -154
  86. package/lib/apiCachePolicy.ts +0 -11
  87. package/lib/assetLifecycle.ts +0 -146
  88. package/lib/canvasVersionStore.ts +0 -223
  89. package/lib/capabilities.ts +0 -126
  90. package/lib/cardNewsGenerator.ts +0 -271
  91. package/lib/cardNewsJobStore.ts +0 -142
  92. package/lib/cardNewsManifestStore.ts +0 -154
  93. package/lib/cardNewsPlanner.ts +0 -236
  94. package/lib/cardNewsPlannerClient.ts +0 -155
  95. package/lib/cardNewsPlannerPrompt.ts +0 -62
  96. package/lib/cardNewsPlannerSchema.ts +0 -321
  97. package/lib/cardNewsRoleTemplateStore.ts +0 -47
  98. package/lib/cardNewsTemplateStore.ts +0 -252
  99. package/lib/codexDetect.ts +0 -71
  100. package/lib/comfyBridge.ts +0 -235
  101. package/lib/composerSnapshot.ts +0 -33
  102. package/lib/configKeys.ts +0 -62
  103. package/lib/db.ts +0 -295
  104. package/lib/errInfo.ts +0 -43
  105. package/lib/errorClassify.ts +0 -100
  106. package/lib/generationCancel.ts +0 -28
  107. package/lib/generationErrors.ts +0 -238
  108. package/lib/grokImageAdapter.ts +0 -513
  109. package/lib/grokMultimodeAdapter.ts +0 -84
  110. package/lib/grokProxyLauncher.ts +0 -153
  111. package/lib/grokRuntime.ts +0 -23
  112. package/lib/grokSizeMapper.ts +0 -71
  113. package/lib/grokVideoAdapter.ts +0 -458
  114. package/lib/grokVideoCanvas.ts +0 -26
  115. package/lib/grokVideoDownload.ts +0 -59
  116. package/lib/grokVideoPlannerPrompt.ts +0 -67
  117. package/lib/historyIndex.ts +0 -51
  118. package/lib/historyList.ts +0 -181
  119. package/lib/imageMetadata.ts +0 -113
  120. package/lib/imageMetadataStore.ts +0 -67
  121. package/lib/imageModels.ts +0 -165
  122. package/lib/inflight.ts +0 -281
  123. package/lib/localImportStore.ts +0 -114
  124. package/lib/logger.ts +0 -161
  125. package/lib/nodeStore.ts +0 -91
  126. package/lib/oauthLauncher.ts +0 -94
  127. package/lib/oauthNormalize.ts +0 -30
  128. package/lib/oauthProxy/errors.ts +0 -128
  129. package/lib/oauthProxy/generators.ts +0 -494
  130. package/lib/oauthProxy/index.ts +0 -28
  131. package/lib/oauthProxy/prompts.ts +0 -123
  132. package/lib/oauthProxy/references.ts +0 -45
  133. package/lib/oauthProxy/runtime.ts +0 -115
  134. package/lib/oauthProxy/streams.ts +0 -232
  135. package/lib/oauthProxy/types.ts +0 -9
  136. package/lib/oauthProxy.ts +0 -3
  137. package/lib/openDirectory.ts +0 -47
  138. package/lib/pngInfo.ts +0 -26
  139. package/lib/promptBuilder/attachments.ts +0 -74
  140. package/lib/promptBuilder/client.ts +0 -130
  141. package/lib/promptBuilder/constants.ts +0 -9
  142. package/lib/promptBuilder/context.ts +0 -36
  143. package/lib/promptBuilder/errors.ts +0 -12
  144. package/lib/promptBuilder/requestSchema.ts +0 -56
  145. package/lib/promptBuilder/responseParser.ts +0 -219
  146. package/lib/promptBuilder/systemPrompt.ts +0 -135
  147. package/lib/promptBuilder/transport.ts +0 -94
  148. package/lib/promptBuilder/types.ts +0 -109
  149. package/lib/promptImport/curatedSources.ts +0 -141
  150. package/lib/promptImport/discoveryRegistry.ts +0 -329
  151. package/lib/promptImport/errors.ts +0 -18
  152. package/lib/promptImport/githubDiscovery.ts +0 -309
  153. package/lib/promptImport/githubFolder.ts +0 -397
  154. package/lib/promptImport/githubSource.ts +0 -257
  155. package/lib/promptImport/gptImageHints.ts +0 -70
  156. package/lib/promptImport/parsePromptCandidates.ts +0 -179
  157. package/lib/promptImport/promptIndex.ts +0 -326
  158. package/lib/promptImport/rankPromptCandidates.ts +0 -65
  159. package/lib/promptImport/types.ts +0 -103
  160. package/lib/promptSafetyPolicy.ts +0 -5
  161. package/lib/providerOptions.ts +0 -56
  162. package/lib/referenceImageCompress.ts +0 -84
  163. package/lib/refs.ts +0 -133
  164. package/lib/requestLogger.ts +0 -49
  165. package/lib/responsesDoctor.ts +0 -456
  166. package/lib/responsesErrors.ts +0 -83
  167. package/lib/responsesFallback.ts +0 -114
  168. package/lib/responsesImageAdapter.ts +0 -466
  169. package/lib/responsesParse.ts +0 -452
  170. package/lib/responsesTools.ts +0 -28
  171. package/lib/runtimeContext.ts +0 -146
  172. package/lib/runtimePorts.ts +0 -105
  173. package/lib/sessionStore.ts +0 -308
  174. package/lib/storageMigration.ts +0 -310
  175. package/lib/styleSheet.ts +0 -139
  176. package/lib/systemTrash.ts +0 -20
  177. package/lib/videoContinuity.ts +0 -180
  178. package/lib/videoFrameExtract.ts +0 -78
  179. package/lib/videoSeriesChain.ts +0 -29
  180. package/lib/visibleTextLanguagePolicy.ts +0 -7
  181. package/routes/agent.ts +0 -308
  182. package/routes/annotations.ts +0 -118
  183. package/routes/canvasVersions.ts +0 -69
  184. package/routes/capabilities.ts +0 -18
  185. package/routes/cardNews.ts +0 -211
  186. package/routes/comfy.ts +0 -43
  187. package/routes/edit.ts +0 -352
  188. package/routes/generate.ts +0 -492
  189. package/routes/grok.ts +0 -24
  190. package/routes/health.ts +0 -123
  191. package/routes/history.ts +0 -221
  192. package/routes/imageImport.ts +0 -37
  193. package/routes/index.ts +0 -52
  194. package/routes/metadata.ts +0 -77
  195. package/routes/multimode.ts +0 -499
  196. package/routes/nodes.ts +0 -578
  197. package/routes/promptBuilder.ts +0 -37
  198. package/routes/promptImport.ts +0 -379
  199. package/routes/prompts.ts +0 -428
  200. package/routes/quota.ts +0 -89
  201. package/routes/sessions.ts +0 -317
  202. package/routes/storage.ts +0 -47
  203. package/routes/video.ts +0 -300
  204. package/routes/videoExtended.ts +0 -284
  205. package/server.ts +0 -293
  206. package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
  207. package/ui/dist/assets/index-CjgnNtgt.css +0 -1
  208. 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
- }