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
@@ -1,48 +0,0 @@
1
- import { parseArgs } from "../lib/args.js";
2
- import { resolveServer, request } from "../lib/client.js";
3
- import { out, die, dieWithError, color, json } from "../lib/output.js";
4
-
5
- import { errInfo } from "../../lib/errInfo.js";
6
- const SPEC = {
7
- flags: {
8
- json: { type: "boolean" },
9
- server: { type: "string" },
10
- help: { short: "h", type: "boolean" },
11
- },
12
- };
13
-
14
- const HELP = `
15
- ima2 cancel <requestId> [--json]
16
-
17
- Mark an in-flight job as canceled in the local ima2 server registry.
18
- `;
19
-
20
- export default async function cancelCmd(argv: string[]) {
21
- const args = parseArgs(argv, SPEC);
22
- if (args.help) { out(HELP); return; }
23
-
24
- const requestId = args.positional[0];
25
- if (!requestId) die(2, "requestId required");
26
-
27
- let server;
28
- try { server = await resolveServer({ serverFlag: args.server }); }
29
- catch (e) {
30
- const err = errInfo(e);
31
- if (args.json) json({ ok: false, requestId, error: err.message, code: err.code, status: err.status });
32
- dieWithError(e);
33
- }
34
-
35
- try {
36
- await request(server.base, `/api/inflight/${encodeURIComponent(requestId)}`, {
37
- method: "DELETE",
38
- timeoutMs: 30_000,
39
- });
40
- } catch (e) {
41
- const err = errInfo(e);
42
- if (args.json) json({ ok: false, requestId, error: err.message, code: err.code, status: err.status });
43
- dieWithError(e);
44
- }
45
-
46
- if (args.json) json({ ok: true, requestId });
47
- else out(color.green("✓ ") + `canceled ${requestId}`);
48
- }
@@ -1,80 +0,0 @@
1
- import { readFile } from "fs/promises";
2
- import { parseArgs, type ParsedArgs } from "../lib/args.js";
3
- import { resolveServer, request } from "../lib/client.js";
4
- import { out, die, color, json, exitCodeForError } from "../lib/output.js";
5
-
6
- const HELP = `
7
- ima2 canvas-versions <subcommand> [options]
8
-
9
- Subcommands:
10
- save <imagefile> [--source <filename>] [--prompt <text>]
11
- update <filename> <imagefile> [--source <filename>] [--prompt <text>]
12
-
13
- Notes: server only exposes POST /api/canvas-versions (collection) and
14
- PUT /api/canvas-versions/:filename. No GET, no DELETE.
15
- `;
16
-
17
- const FLAGS = {
18
- json: { type: "boolean" },
19
- server: { type: "string" },
20
- source: { type: "string" },
21
- prompt: { type: "string" },
22
- help: { short: "h", type: "boolean" },
23
- };
24
-
25
- async function getServer(args: ParsedArgs) {
26
- try { return await resolveServer({ serverFlag: args.server }); }
27
- catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
28
- }
29
-
30
- function buildHeaders(args: ParsedArgs) {
31
- const h: Record<string, string> = { "Content-Type": "image/png" };
32
- if (args.source) h["X-Ima2-Canvas-Source-Filename"] = String(args.source);
33
- if (args.prompt) h["X-Ima2-Canvas-Prompt"] = String(args.prompt);
34
- return h;
35
- }
36
-
37
- async function saveSub(argv: string[]) {
38
- const args = parseArgs(argv, { flags: FLAGS });
39
- const file = args.positional[0];
40
- if (!file) die(2, "image file required");
41
- const buf = await readFile(file);
42
- const server = await getServer(args);
43
- const resp = await request(server.base, "/api/canvas-versions", {
44
- method: "POST",
45
- body: buf,
46
- raw: true,
47
- headers: buildHeaders(args),
48
- }).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
49
- if (args.json) { json(resp); return; }
50
- out(color.green("✓ saved canvas version"));
51
- }
52
-
53
- async function updateSub(argv: string[]) {
54
- const args = parseArgs(argv, { flags: FLAGS });
55
- const [filename, file] = args.positional;
56
- if (!filename || !file) die(2, "usage: canvas-versions update <filename> <imagefile>");
57
- const buf = await readFile(file);
58
- const server = await getServer(args);
59
- const resp = await request(server.base, `/api/canvas-versions/${encodeURIComponent(filename)}`, {
60
- method: "PUT",
61
- body: buf,
62
- raw: true,
63
- headers: buildHeaders(args),
64
- }).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
65
- if (args.json) { json(resp); return; }
66
- out(color.green("✓ updated"));
67
- }
68
-
69
- const SUB: Record<string, (argv: any[]) => Promise<void>> = {
70
- save: saveSub,
71
- update: updateSub,
72
- };
73
-
74
- export default async function canvasVersionsCmd(argv: string[]) {
75
- const sub = argv[0];
76
- if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
77
- const handler = SUB[sub];
78
- if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
79
- return handler(argv.slice(1));
80
- }
@@ -1,110 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { dirname, join } from "path";
3
- import { fileURLToPath } from "url";
4
- import { config } from "../../config.js";
5
- import { buildIma2Capabilities } from "../../lib/capabilities.js";
6
- import { parseArgs } from "../lib/args.js";
7
- import { resolveServer, request } from "../lib/client.js";
8
- import { color, dieWithError, json, out } from "../lib/output.js";
9
-
10
- const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
11
- const PACKAGE_PATH = join(ROOT, "package.json");
12
-
13
- const HELP = `
14
- ima2 capabilities [--json] [--server <url>] [--require-server]
15
-
16
- Print agent-friendly capability metadata.
17
-
18
- Options:
19
- --json Print JSON
20
- --server <url> Query a specific running server
21
- --require-server Fail instead of falling back to local package metadata
22
- `;
23
-
24
- const FLAGS = {
25
- json: { type: "boolean" },
26
- server: { type: "string" },
27
- "require-server": { type: "boolean" },
28
- help: { short: "h", type: "boolean" },
29
- };
30
-
31
- function packageVersion(): string {
32
- try {
33
- const pkg = JSON.parse(readFileSync(PACKAGE_PATH, "utf-8")) as { version?: string };
34
- return pkg.version || "?";
35
- } catch {
36
- return "?";
37
- }
38
- }
39
-
40
- function localCapabilities() {
41
- return buildIma2Capabilities({
42
- appConfig: config,
43
- packageVersion: packageVersion(),
44
- source: "local",
45
- server: null,
46
- });
47
- }
48
-
49
- async function readCapabilities(args: ReturnType<typeof parseArgs>) {
50
- try {
51
- const server = await resolveServer({ serverFlag: args.server });
52
- return await request(server.base, "/api/capabilities", { timeoutMs: 5000 });
53
- } catch (error) {
54
- if (args.server || args["require-server"]) throw error;
55
- return localCapabilities();
56
- }
57
- }
58
-
59
- function printText(capabilities: any): void {
60
- out(`ima2 capabilities (${capabilities.source})`);
61
- out(`version: ${capabilities.version}`);
62
- out(`server: ${capabilities.server || "none"}`);
63
- out("");
64
- out("defaults:");
65
- out(` gpt-oauth model: ${capabilities.defaults?.oauth?.model}`);
66
- out(` gpt-oauth reasoning: ${capabilities.defaults?.oauth?.reasoningEffort}`);
67
- out(` api model: ${capabilities.defaults?.api?.model}`);
68
- out(` api reasoning: ${capabilities.defaults?.api?.reasoningEffort}`);
69
- out(` grok model: ${capabilities.defaults?.grok?.model}`);
70
- out(` grok planner: ${capabilities.defaults?.grok?.plannerModel}`);
71
- out("");
72
- out("valid:");
73
- out(` models: ${capabilities.valid?.imageModels?.supported?.join(", ")}`);
74
- if (capabilities.valid?.imageModels?.grokSupported?.length) {
75
- out(` grok models: ${capabilities.valid.imageModels.grokSupported.join(", ")}`);
76
- }
77
- if (capabilities.valid?.videoModels?.supported?.length) {
78
- out(` video models: ${capabilities.valid.videoModels.supported.join(", ")}`);
79
- out(` video resolutions: ${capabilities.valid.videoModels.resolutions?.join(", ")}`);
80
- out(` video aspect ratios: ${capabilities.valid.videoModels.aspectRatios?.join(", ")}`);
81
- out(` video duration: ${capabilities.valid.videoModels.durationRange?.[0]}-${capabilities.valid.videoModels.durationRange?.[1]}s`);
82
- }
83
- out(` reasoning: ${capabilities.valid?.reasoningEfforts?.join(", ")}`);
84
- out(` quality: ${capabilities.valid?.quality?.join(", ")}`);
85
- out(` modes: ${capabilities.valid?.modes?.join(", ")}`);
86
- out(` moderation: ${capabilities.valid?.moderation?.join(", ")}`);
87
- out(` providers: ${capabilities.valid?.providers?.join(", ")}`);
88
- out("");
89
- out(`config keys: ${capabilities.configKeys?.writable?.length ?? 0} writable`);
90
- out(color.dim("run: ima2 config keys --json"));
91
- out("");
92
- out(`limits: refs=${capabilities.limits?.maxRefCount}, images=${capabilities.limits?.maxGeneratedImages}`);
93
- out(color.dim(`maxParallel: ${capabilities.limits?.maxParallel?.value} (${capabilities.limits?.maxParallel?.note})`));
94
- }
95
-
96
- export default async function capabilitiesCmd(argv: string[]) {
97
- const args = parseArgs(argv, { flags: FLAGS });
98
- if (args.help) {
99
- out(HELP);
100
- return;
101
- }
102
-
103
- try {
104
- const capabilities = await readCapabilities(args);
105
- if (args.json) json(capabilities);
106
- else printText(capabilities);
107
- } catch (error) {
108
- dieWithError(error);
109
- }
110
- }
@@ -1,249 +0,0 @@
1
- import { parseArgs, type ParsedArgs } from "../lib/args.js";
2
- import { resolveServer, request } from "../lib/client.js";
3
- import { out, die, color, json, exitCodeForError } from "../lib/output.js";
4
- import { config as runtimeConfig } from "../../config.js";
5
-
6
- const HELP = `
7
- ima2 cardnews <subcommand> [options]
8
-
9
- Subcommands:
10
- templates List image-templates + role-templates
11
- template preview <templateId> Preview an image template
12
- sets List card news sets
13
- set show <setId> Show a set
14
- set manifest <setId> Show a set manifest
15
- draft [--data <json>] Create a draft
16
- generate [--data <json>] Run generation
17
- job create [--data <json>] Create and start a job
18
- job show <jobId> Show a job
19
- job retry <jobId> [--cards <id,...>] Retry a job (optionally specific cards)
20
- card regenerate <cardId> [--data <json>] Regenerate a single card
21
- export [--data <json>] Export a bundle
22
-
23
- Note: Card News must be enabled (IMA2_CARD_NEWS=1 or features.cardNews: true in config.json).
24
-
25
- Options:
26
- --data <json> JSON body to send (for draft/generate/job create/card regenerate/export)
27
- --cards <ids> Comma-separated card IDs for job retry
28
- --json Output raw JSON
29
- --server <url> Override server URL
30
- `;
31
-
32
- const FLAGS = {
33
- json: { type: "boolean" },
34
- server: { type: "string" },
35
- data: { type: "string" },
36
- cards: { type: "string" },
37
- help: { short: "h", type: "boolean" },
38
- };
39
-
40
- function ensureCardNewsEnabled() {
41
- if (!runtimeConfig.features?.cardNews) {
42
- die(2, "Card News feature is disabled. Set IMA2_CARD_NEWS=1 (or features.cardNews: true in config.json) and restart the server.");
43
- }
44
- }
45
-
46
- async function getServer(args: ParsedArgs) {
47
- try { return await resolveServer({ serverFlag: args.server }); }
48
- catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
49
- }
50
-
51
- function parseData(raw: unknown): any {
52
- if (!raw) return {};
53
- if (typeof raw !== "string") return {};
54
- try { return JSON.parse(raw); }
55
- catch { die(2, `--data must be valid JSON`); }
56
- }
57
-
58
- async function templatesSub(argv: string[]) {
59
- const args = parseArgs(argv, { flags: FLAGS });
60
- if (args.help) { out(HELP); return; }
61
- ensureCardNewsEnabled();
62
- const server = await getServer(args);
63
- const [imgTemplates, roleTemplates] = await Promise.all([
64
- request(server.base, "/api/cardnews/image-templates")
65
- .catch((e) => die(exitCodeForError(e), e.message)),
66
- request(server.base, "/api/cardnews/role-templates")
67
- .catch((e) => die(exitCodeForError(e), e.message)),
68
- ]);
69
- if (args.json) { json({ imageTemplates: imgTemplates, roleTemplates }); return; }
70
- out(color.bold("Image templates:"));
71
- out(JSON.stringify(imgTemplates, null, 2));
72
- out(color.bold("Role templates:"));
73
- out(JSON.stringify(roleTemplates, null, 2));
74
- }
75
-
76
- async function templatePreviewSub(argv: string[]) {
77
- const args = parseArgs(argv, { flags: FLAGS });
78
- const templateId = args.positional[0];
79
- if (!templateId) die(2, "templateId required");
80
- ensureCardNewsEnabled();
81
- const server = await getServer(args);
82
- const resp = await request(server.base, `/api/cardnews/image-templates/${encodeURIComponent(templateId)}/preview`)
83
- .catch((e) => die(exitCodeForError(e), e.message));
84
- if (args.json) { json(resp); return; }
85
- out(JSON.stringify(resp, null, 2));
86
- }
87
-
88
- async function setsSub(argv: string[]) {
89
- const args = parseArgs(argv, { flags: FLAGS });
90
- ensureCardNewsEnabled();
91
- const server = await getServer(args);
92
- const resp = await request(server.base, "/api/cardnews/sets")
93
- .catch((e) => die(exitCodeForError(e), e.message));
94
- if (args.json) { json(resp); return; }
95
- out(JSON.stringify(resp, null, 2));
96
- }
97
-
98
- async function setShowSub(argv: string[]) {
99
- const args = parseArgs(argv, { flags: FLAGS });
100
- const setId = args.positional[0];
101
- if (!setId) die(2, "setId required");
102
- ensureCardNewsEnabled();
103
- const server = await getServer(args);
104
- const resp = await request(server.base, `/api/cardnews/sets/${encodeURIComponent(setId)}`)
105
- .catch((e) => die(exitCodeForError(e), e.message));
106
- if (args.json) { json(resp); return; }
107
- out(JSON.stringify(resp, null, 2));
108
- }
109
-
110
- async function setManifestSub(argv: string[]) {
111
- const args = parseArgs(argv, { flags: FLAGS });
112
- const setId = args.positional[0];
113
- if (!setId) die(2, "setId required");
114
- ensureCardNewsEnabled();
115
- const server = await getServer(args);
116
- const resp = await request(server.base, `/api/cardnews/sets/${encodeURIComponent(setId)}/manifest`)
117
- .catch((e) => die(exitCodeForError(e), e.message));
118
- if (args.json) { json(resp); return; }
119
- out(JSON.stringify(resp, null, 2));
120
- }
121
-
122
- async function draftSub(argv: string[]) {
123
- const args = parseArgs(argv, { flags: FLAGS });
124
- ensureCardNewsEnabled();
125
- const server = await getServer(args);
126
- const body = parseData(args.data);
127
- const resp = await request(server.base, "/api/cardnews/draft", { method: "POST", body })
128
- .catch((e) => die(exitCodeForError(e), e.message));
129
- if (args.json) { json(resp); return; }
130
- out(JSON.stringify(resp, null, 2));
131
- }
132
-
133
- async function generateSub(argv: string[]) {
134
- const args = parseArgs(argv, { flags: FLAGS });
135
- ensureCardNewsEnabled();
136
- const server = await getServer(args);
137
- const body = parseData(args.data);
138
- const resp = await request(server.base, "/api/cardnews/generate", { method: "POST", body })
139
- .catch((e) => die(exitCodeForError(e), e.message));
140
- if (args.json) { json(resp); return; }
141
- out(JSON.stringify(resp, null, 2));
142
- }
143
-
144
- async function jobCreateSub(argv: string[]) {
145
- const args = parseArgs(argv, { flags: FLAGS });
146
- ensureCardNewsEnabled();
147
- const server = await getServer(args);
148
- const body = parseData(args.data);
149
- const resp = await request(server.base, "/api/cardnews/jobs", { method: "POST", body })
150
- .catch((e) => die(exitCodeForError(e), e.message));
151
- if (args.json) { json(resp); return; }
152
- out(JSON.stringify(resp, null, 2));
153
- }
154
-
155
- async function jobShowSub(argv: string[]) {
156
- const args = parseArgs(argv, { flags: FLAGS });
157
- const jobId = args.positional[0];
158
- if (!jobId) die(2, "jobId required");
159
- ensureCardNewsEnabled();
160
- const server = await getServer(args);
161
- const resp = await request(server.base, `/api/cardnews/jobs/${encodeURIComponent(jobId)}`)
162
- .catch((e) => die(exitCodeForError(e), e.message));
163
- if (args.json) { json(resp); return; }
164
- out(JSON.stringify(resp, null, 2));
165
- }
166
-
167
- async function jobRetrySub(argv: string[]) {
168
- const args = parseArgs(argv, { flags: FLAGS });
169
- const jobId = args.positional[0];
170
- if (!jobId) die(2, "jobId required");
171
- ensureCardNewsEnabled();
172
- const server = await getServer(args);
173
- const body: any = {};
174
- if (args.cards) body.cardIds = String(args.cards).split(",").map((s: string) => s.trim()).filter(Boolean);
175
- const resp = await request(server.base, `/api/cardnews/jobs/${encodeURIComponent(jobId)}/retry`, { method: "POST", body })
176
- .catch((e) => die(exitCodeForError(e), e.message));
177
- if (args.json) { json(resp); return; }
178
- out(color.green("✓ ") + "retry requested");
179
- if (resp && typeof resp === "object" && Object.keys(resp).length > 0) out(JSON.stringify(resp, null, 2));
180
- }
181
-
182
- async function cardRegenerateSub(argv: string[]) {
183
- const args = parseArgs(argv, { flags: FLAGS });
184
- const cardId = args.positional[0];
185
- if (!cardId) die(2, "cardId required");
186
- ensureCardNewsEnabled();
187
- const server = await getServer(args);
188
- const body = parseData(args.data);
189
- const resp = await request(server.base, `/api/cardnews/cards/${encodeURIComponent(cardId)}/regenerate`, { method: "POST", body })
190
- .catch((e) => die(exitCodeForError(e), e.message));
191
- if (args.json) { json(resp); return; }
192
- out(color.green("✓ ") + "regeneration started");
193
- if (resp && typeof resp === "object" && Object.keys(resp).length > 0) out(JSON.stringify(resp, null, 2));
194
- }
195
-
196
- async function exportSub(argv: string[]) {
197
- const args = parseArgs(argv, { flags: FLAGS });
198
- ensureCardNewsEnabled();
199
- const server = await getServer(args);
200
- const body = parseData(args.data);
201
- const resp = await request(server.base, "/api/cardnews/export", { method: "POST", body })
202
- .catch((e) => die(exitCodeForError(e), e.message));
203
- if (args.json) { json(resp); return; }
204
- out(color.green("✓ ") + "export requested");
205
- if (resp && typeof resp === "object" && Object.keys(resp).length > 0) out(JSON.stringify(resp, null, 2));
206
- }
207
-
208
- type Sub = (argv: any[]) => Promise<void>;
209
-
210
- export default async function cardnewsCmd(argv: string[]) {
211
- const sub = argv[0];
212
- if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
213
-
214
- if (sub === "template") {
215
- const s2 = argv[1];
216
- if (s2 === "preview") return templatePreviewSub(argv.slice(2));
217
- die(2, `unknown subcommand: template ${s2 || ""}\n${HELP}`);
218
- }
219
- if (sub === "set") {
220
- const s2 = argv[1];
221
- const SET_SUB: Record<string, Sub> = { show: setShowSub, manifest: setManifestSub };
222
- const handler = SET_SUB[s2];
223
- if (!handler) die(2, `unknown subcommand: set ${s2 || ""}\n${HELP}`);
224
- return handler(argv.slice(2));
225
- }
226
- if (sub === "job") {
227
- const s2 = argv[1];
228
- const JOB_SUB: Record<string, Sub> = { create: jobCreateSub, show: jobShowSub, retry: jobRetrySub };
229
- const handler = JOB_SUB[s2];
230
- if (!handler) die(2, `unknown subcommand: job ${s2 || ""}\n${HELP}`);
231
- return handler(argv.slice(2));
232
- }
233
- if (sub === "card") {
234
- const s2 = argv[1];
235
- if (s2 === "regenerate") return cardRegenerateSub(argv.slice(2));
236
- die(2, `unknown subcommand: card ${s2 || ""}\n${HELP}`);
237
- }
238
-
239
- const FLAT: Record<string, Sub> = {
240
- templates: templatesSub,
241
- sets: setsSub,
242
- draft: draftSub,
243
- generate: generateSub,
244
- export: exportSub,
245
- };
246
- const handler = FLAT[sub];
247
- if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
248
- return handler(argv.slice(1));
249
- }
@@ -1,54 +0,0 @@
1
- import { writeFile, access } from "fs/promises";
2
- import { parseArgs } from "../lib/args.js";
3
- import { resolveServer, request } from "../lib/client.js";
4
- import { out, die, color, json, exitCodeForError } from "../lib/output.js";
5
-
6
- const HELP = `
7
- ima2 comfy <subcommand> [options]
8
-
9
- Subcommands:
10
- export <filename> [-o <out>] [--force]
11
- `;
12
-
13
- const FLAGS = {
14
- json: { type: "boolean" },
15
- server: { type: "string" },
16
- out: { short: "o", type: "string" },
17
- force: { type: "boolean" },
18
- help: { short: "h", type: "boolean" },
19
- };
20
-
21
- async function exportSub(argv: string[]) {
22
- const args = parseArgs(argv, { flags: FLAGS });
23
- const filename = args.positional[0];
24
- if (!filename) die(2, "filename required");
25
- let server;
26
- try { server = await resolveServer({ serverFlag: args.server }); }
27
- catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
28
- const resp: any = await request(server.base, "/api/comfy/export-image", {
29
- method: "POST",
30
- body: { filename },
31
- }).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
32
- const target = String(args.out || `${filename}.workflow.json`);
33
- if (!args.force) {
34
- try {
35
- await access(target);
36
- die(2, `${target} already exists. Pass --force to overwrite.`);
37
- } catch { /* file does not exist — proceed */ }
38
- }
39
- await writeFile(target, JSON.stringify(resp, null, 2));
40
- if (args.json) { json({ path: target }); return; }
41
- out(color.green("✓ ") + target);
42
- }
43
-
44
- const SUB: Record<string, (argv: any[]) => Promise<void>> = {
45
- export: exportSub,
46
- };
47
-
48
- export default async function comfyCmd(argv: string[]) {
49
- const sub = argv[0];
50
- if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
51
- const handler = SUB[sub];
52
- if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
53
- return handler(argv.slice(1));
54
- }