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.
- package/README.md +30 -4
- package/bin/ima2.js +14 -4
- package/bin/lib/platform.js +34 -5
- package/docs/README.ko.md +31 -0
- package/lib/agentQueueWorker.js +6 -0
- package/lib/agentRuntime.js +3 -2
- package/lib/atomicWrite.js +14 -0
- package/lib/grokProxyLauncher.js +5 -3
- package/lib/inflight.js +1 -1
- package/lib/oauthLauncher.js +5 -0
- package/lib/videoFrameExtract.js +3 -3
- package/package.json +5 -7
- package/routes/edit.js +2 -1
- package/routes/generate.js +4 -3
- package/routes/health.js +4 -3
- package/routes/multimode.js +2 -1
- package/routes/video.js +4 -2
- package/server.js +29 -2
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-COxQ5TjU.js} +1 -1
- package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BSsclEBh.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-CVwT0rLd.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-BhFgeKnY.js} +2 -2
- package/ui/dist/assets/SettingsWorkspace-CfjrlH5R.js +1 -0
- package/ui/dist/assets/index-C-mur7pa.css +1 -0
- package/ui/dist/assets/index-CCP5nUOj.js +42 -0
- package/ui/dist/assets/{index-31uVIdt4.js → index-Cxhzi3bs.js} +1 -1
- package/ui/dist/index.html +2 -2
- package/bin/commands/annotate.ts +0 -119
- package/bin/commands/cancel.ts +0 -48
- package/bin/commands/canvas-versions.ts +0 -80
- package/bin/commands/capabilities.ts +0 -110
- package/bin/commands/cardnews.ts +0 -249
- package/bin/commands/comfy.ts +0 -54
- package/bin/commands/config.ts +0 -186
- package/bin/commands/defaults.ts +0 -192
- package/bin/commands/doctor.ts +0 -202
- package/bin/commands/edit.ts +0 -150
- package/bin/commands/gen.ts +0 -214
- package/bin/commands/grok.ts +0 -90
- package/bin/commands/history.ts +0 -146
- package/bin/commands/ls.ts +0 -64
- package/bin/commands/metadata.ts +0 -39
- package/bin/commands/multimode.ts +0 -196
- package/bin/commands/node.ts +0 -166
- package/bin/commands/observability.ts +0 -176
- package/bin/commands/ping.ts +0 -31
- package/bin/commands/prompt-sub/build.ts +0 -101
- package/bin/commands/prompt.ts +0 -492
- package/bin/commands/ps.ts +0 -81
- package/bin/commands/session.ts +0 -266
- package/bin/commands/show.ts +0 -72
- package/bin/commands/skill.ts +0 -70
- package/bin/commands/video.ts +0 -442
- package/bin/ima2.ts +0 -430
- package/bin/lib/args.ts +0 -92
- package/bin/lib/browser-id.ts +0 -16
- package/bin/lib/client.ts +0 -122
- package/bin/lib/config-store.ts +0 -120
- package/bin/lib/destructive-confirm.ts +0 -19
- package/bin/lib/doctor-checks.ts +0 -91
- package/bin/lib/error-hints.ts +0 -23
- package/bin/lib/files.ts +0 -39
- package/bin/lib/output.ts +0 -73
- package/bin/lib/platform.ts +0 -99
- package/bin/lib/recover-output.ts +0 -139
- package/bin/lib/sse.ts +0 -73
- package/bin/lib/star-prompt.ts +0 -97
- package/bin/lib/storage-doctor.ts +0 -39
- package/bin/lib/ui-build.ts +0 -85
- package/config.ts +0 -354
- package/lib/agentCommandParser.ts +0 -69
- package/lib/agentGenerationPlanner.ts +0 -273
- package/lib/agentQuestionResponder.ts +0 -266
- package/lib/agentQueueStore.ts +0 -270
- package/lib/agentQueueWorker.ts +0 -89
- package/lib/agentRuntime.ts +0 -604
- package/lib/agentSettings.ts +0 -72
- package/lib/agentStore.ts +0 -422
- package/lib/agentStoreRows.ts +0 -136
- package/lib/agentTypes.ts +0 -154
- package/lib/apiCachePolicy.ts +0 -11
- package/lib/assetLifecycle.ts +0 -146
- package/lib/canvasVersionStore.ts +0 -223
- package/lib/capabilities.ts +0 -126
- package/lib/cardNewsGenerator.ts +0 -271
- package/lib/cardNewsJobStore.ts +0 -142
- package/lib/cardNewsManifestStore.ts +0 -154
- package/lib/cardNewsPlanner.ts +0 -236
- package/lib/cardNewsPlannerClient.ts +0 -155
- package/lib/cardNewsPlannerPrompt.ts +0 -62
- package/lib/cardNewsPlannerSchema.ts +0 -321
- package/lib/cardNewsRoleTemplateStore.ts +0 -47
- package/lib/cardNewsTemplateStore.ts +0 -252
- package/lib/codexDetect.ts +0 -71
- package/lib/comfyBridge.ts +0 -235
- package/lib/composerSnapshot.ts +0 -33
- package/lib/configKeys.ts +0 -62
- package/lib/db.ts +0 -295
- package/lib/errInfo.ts +0 -43
- package/lib/errorClassify.ts +0 -100
- package/lib/generationCancel.ts +0 -28
- package/lib/generationErrors.ts +0 -238
- package/lib/grokImageAdapter.ts +0 -513
- package/lib/grokMultimodeAdapter.ts +0 -84
- package/lib/grokProxyLauncher.ts +0 -153
- package/lib/grokRuntime.ts +0 -23
- package/lib/grokSizeMapper.ts +0 -71
- package/lib/grokVideoAdapter.ts +0 -458
- package/lib/grokVideoCanvas.ts +0 -26
- package/lib/grokVideoDownload.ts +0 -59
- package/lib/grokVideoPlannerPrompt.ts +0 -67
- package/lib/historyIndex.ts +0 -51
- package/lib/historyList.ts +0 -181
- package/lib/imageMetadata.ts +0 -113
- package/lib/imageMetadataStore.ts +0 -67
- package/lib/imageModels.ts +0 -165
- package/lib/inflight.ts +0 -281
- package/lib/localImportStore.ts +0 -114
- package/lib/logger.ts +0 -161
- package/lib/nodeStore.ts +0 -91
- package/lib/oauthLauncher.ts +0 -94
- package/lib/oauthNormalize.ts +0 -30
- package/lib/oauthProxy/errors.ts +0 -128
- package/lib/oauthProxy/generators.ts +0 -494
- package/lib/oauthProxy/index.ts +0 -28
- package/lib/oauthProxy/prompts.ts +0 -123
- package/lib/oauthProxy/references.ts +0 -45
- package/lib/oauthProxy/runtime.ts +0 -115
- package/lib/oauthProxy/streams.ts +0 -232
- package/lib/oauthProxy/types.ts +0 -9
- package/lib/oauthProxy.ts +0 -3
- package/lib/openDirectory.ts +0 -47
- package/lib/pngInfo.ts +0 -26
- package/lib/promptBuilder/attachments.ts +0 -74
- package/lib/promptBuilder/client.ts +0 -130
- package/lib/promptBuilder/constants.ts +0 -9
- package/lib/promptBuilder/context.ts +0 -36
- package/lib/promptBuilder/errors.ts +0 -12
- package/lib/promptBuilder/requestSchema.ts +0 -56
- package/lib/promptBuilder/responseParser.ts +0 -219
- package/lib/promptBuilder/systemPrompt.ts +0 -135
- package/lib/promptBuilder/transport.ts +0 -94
- package/lib/promptBuilder/types.ts +0 -109
- package/lib/promptImport/curatedSources.ts +0 -141
- package/lib/promptImport/discoveryRegistry.ts +0 -329
- package/lib/promptImport/errors.ts +0 -18
- package/lib/promptImport/githubDiscovery.ts +0 -309
- package/lib/promptImport/githubFolder.ts +0 -397
- package/lib/promptImport/githubSource.ts +0 -257
- package/lib/promptImport/gptImageHints.ts +0 -70
- package/lib/promptImport/parsePromptCandidates.ts +0 -179
- package/lib/promptImport/promptIndex.ts +0 -326
- package/lib/promptImport/rankPromptCandidates.ts +0 -65
- package/lib/promptImport/types.ts +0 -103
- package/lib/promptSafetyPolicy.ts +0 -5
- package/lib/providerOptions.ts +0 -56
- package/lib/referenceImageCompress.ts +0 -84
- package/lib/refs.ts +0 -133
- package/lib/requestLogger.ts +0 -49
- package/lib/responsesDoctor.ts +0 -456
- package/lib/responsesErrors.ts +0 -83
- package/lib/responsesFallback.ts +0 -114
- package/lib/responsesImageAdapter.ts +0 -466
- package/lib/responsesParse.ts +0 -452
- package/lib/responsesTools.ts +0 -28
- package/lib/runtimeContext.ts +0 -146
- package/lib/runtimePorts.ts +0 -105
- package/lib/sessionStore.ts +0 -308
- package/lib/storageMigration.ts +0 -310
- package/lib/styleSheet.ts +0 -139
- package/lib/systemTrash.ts +0 -20
- package/lib/videoContinuity.ts +0 -180
- package/lib/videoFrameExtract.ts +0 -78
- package/lib/videoSeriesChain.ts +0 -29
- package/lib/visibleTextLanguagePolicy.ts +0 -7
- package/routes/agent.ts +0 -308
- package/routes/annotations.ts +0 -118
- package/routes/canvasVersions.ts +0 -69
- package/routes/capabilities.ts +0 -18
- package/routes/cardNews.ts +0 -211
- package/routes/comfy.ts +0 -43
- package/routes/edit.ts +0 -352
- package/routes/generate.ts +0 -492
- package/routes/grok.ts +0 -24
- package/routes/health.ts +0 -123
- package/routes/history.ts +0 -221
- package/routes/imageImport.ts +0 -37
- package/routes/index.ts +0 -52
- package/routes/metadata.ts +0 -77
- package/routes/multimode.ts +0 -499
- package/routes/nodes.ts +0 -578
- package/routes/promptBuilder.ts +0 -37
- package/routes/promptImport.ts +0 -379
- package/routes/prompts.ts +0 -428
- package/routes/quota.ts +0 -89
- package/routes/sessions.ts +0 -317
- package/routes/storage.ts +0 -47
- package/routes/video.ts +0 -300
- package/routes/videoExtended.ts +0 -284
- package/server.ts +0 -293
- package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
- package/ui/dist/assets/index-CjgnNtgt.css +0 -1
- package/ui/dist/assets/index-Da2s4_-5.js +0 -36
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from "../lib/args.js";
|
|
2
|
-
import { resolveServer } from "../lib/client.js";
|
|
3
|
-
import { streamSse } from "../lib/sse.js";
|
|
4
|
-
import { dataUriToFile, defaultOutName, fileToDataUri } from "../lib/files.js";
|
|
5
|
-
import { out, die, color, json, exitCodeForError } from "../lib/output.js";
|
|
6
|
-
import { config } from "../../config.js";
|
|
7
|
-
import { createCliRequestId, recoverGeneratedOutputs, formatRecoveryHint } from "../lib/recover-output.js";
|
|
8
|
-
|
|
9
|
-
const SPEC = {
|
|
10
|
-
flags: {
|
|
11
|
-
quality: { short: "q", type: "string", default: "low" },
|
|
12
|
-
size: { short: "s", type: "string", default: "1024x1024" },
|
|
13
|
-
"max-images": { type: "string", default: "4" },
|
|
14
|
-
out: { short: "o", type: "string" },
|
|
15
|
-
"out-dir": { short: "d", type: "string" },
|
|
16
|
-
json: { type: "boolean" },
|
|
17
|
-
timeout: { type: "string", default: "600" },
|
|
18
|
-
server: { type: "string" },
|
|
19
|
-
model: { type: "string" },
|
|
20
|
-
provider: { type: "string" },
|
|
21
|
-
mode: { type: "string", default: "auto" },
|
|
22
|
-
ref: { type: "string", repeatable: true },
|
|
23
|
-
"reasoning-effort": { type: "string" },
|
|
24
|
-
"web-search": { type: "boolean" },
|
|
25
|
-
"no-web-search": { type: "boolean" },
|
|
26
|
-
moderation: { type: "string", default: "low" },
|
|
27
|
-
session: { type: "string" },
|
|
28
|
-
"show-partial": { type: "boolean" },
|
|
29
|
-
help: { short: "h", type: "boolean" },
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const HELP = `
|
|
34
|
-
ima2 multimode <prompt...> [options]
|
|
35
|
-
|
|
36
|
-
Stream multi-image generation via SSE (phase / partial / image / done / error).
|
|
37
|
-
|
|
38
|
-
Options:
|
|
39
|
-
-q, --quality <low|medium|high> Default: low
|
|
40
|
-
-s, --size <WxH> Default: 1024x1024
|
|
41
|
-
--max-images <1..8> Default: 4
|
|
42
|
-
-o, --out <file> First image (implies --max-images 1)
|
|
43
|
-
-d, --out-dir <dir> Output dir for multiple images
|
|
44
|
-
--json
|
|
45
|
-
--model <gpt-5.5|gpt-5.4|gpt-5.4-mini>
|
|
46
|
-
--provider <auto|oauth|api|grok> Provider (oauth = GPT OAuth; grok = xAI Grok)
|
|
47
|
-
--mode <auto|direct> Prompt handling mode. Default: auto
|
|
48
|
-
--ref <file> Attach reference image (repeatable, max 5)
|
|
49
|
-
--reasoning-effort <none|low|medium|high|xhigh>
|
|
50
|
-
--web-search / --no-web-search
|
|
51
|
-
--moderation <auto|low>
|
|
52
|
-
--session <id>
|
|
53
|
-
--show-partial Print [partial #N received] notices
|
|
54
|
-
--timeout <sec> Default: 600
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
export default async function multimodeCmd(argv: string[]) {
|
|
58
|
-
const args = parseArgs(argv, SPEC);
|
|
59
|
-
if (args.help) { out(HELP); return; }
|
|
60
|
-
const prompt = args.positional.join(" ");
|
|
61
|
-
if (!prompt) die(2, "prompt required");
|
|
62
|
-
|
|
63
|
-
const VALID_PROVIDERS = new Set(["auto", "oauth", "api", "grok"]);
|
|
64
|
-
const VALID_MODES = new Set(["auto", "direct"]);
|
|
65
|
-
const VALID_REASONING = new Set(["none", "low", "medium", "high", "xhigh"]);
|
|
66
|
-
if (args.provider && !VALID_PROVIDERS.has(String(args.provider))) {
|
|
67
|
-
die(2, "--provider must be one of: auto, oauth, api, grok");
|
|
68
|
-
}
|
|
69
|
-
if (!VALID_MODES.has(String(args.mode))) die(2, "--mode must be one of: auto, direct");
|
|
70
|
-
if (args["reasoning-effort"] && !VALID_REASONING.has(String(args["reasoning-effort"]))) {
|
|
71
|
-
die(2, "--reasoning-effort must be one of: none, low, medium, high, xhigh");
|
|
72
|
-
}
|
|
73
|
-
if (args["web-search"] && args["no-web-search"]) {
|
|
74
|
-
die(2, "--web-search and --no-web-search are mutually exclusive");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let server;
|
|
78
|
-
try { server = await resolveServer({ serverFlag: args.server }); }
|
|
79
|
-
catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
|
|
80
|
-
|
|
81
|
-
const maxImages = Math.max(1, Math.min(8, parseInt(String(args["max-images"])) || 4));
|
|
82
|
-
const refs = (Array.isArray(args.ref) ? args.ref : []) as string[];
|
|
83
|
-
if (refs.length > 5) die(2, "max 5 --ref attachments");
|
|
84
|
-
const references = await Promise.all(refs.map((p: string) => fileToDataUri(p)));
|
|
85
|
-
const outDir = args["out-dir"] ? String(args["out-dir"]) : null;
|
|
86
|
-
const explicitOut = args.out ? String(args.out) : null;
|
|
87
|
-
const requestId = createCliRequestId("req_cli_multimode");
|
|
88
|
-
const timeoutMs = (parseInt(String(args.timeout)) || 600) * 1000;
|
|
89
|
-
|
|
90
|
-
const body: any = {
|
|
91
|
-
prompt,
|
|
92
|
-
quality: args.quality,
|
|
93
|
-
size: args.size,
|
|
94
|
-
maxImages,
|
|
95
|
-
mode: args.mode,
|
|
96
|
-
references,
|
|
97
|
-
moderation: args.moderation,
|
|
98
|
-
sessionId: args.session,
|
|
99
|
-
requestId,
|
|
100
|
-
};
|
|
101
|
-
if (args.model) body.model = args.model;
|
|
102
|
-
if (args.provider) body.provider = args.provider;
|
|
103
|
-
if (args["reasoning-effort"]) body.reasoningEffort = args["reasoning-effort"];
|
|
104
|
-
if (args["no-web-search"]) body.webSearchEnabled = false;
|
|
105
|
-
else if (args["web-search"]) body.webSearchEnabled = true;
|
|
106
|
-
|
|
107
|
-
const ac = new AbortController();
|
|
108
|
-
let timedOut = false;
|
|
109
|
-
const timeoutTimer = setTimeout(() => {
|
|
110
|
-
timedOut = true;
|
|
111
|
-
ac.abort();
|
|
112
|
-
}, timeoutMs);
|
|
113
|
-
const onSig = () => { ac.abort(); process.exit(130); };
|
|
114
|
-
process.once("SIGINT", onSig);
|
|
115
|
-
process.once("SIGTERM", onSig);
|
|
116
|
-
|
|
117
|
-
const url = `${server.base}/api/generate/multimode`;
|
|
118
|
-
const images: any[] = [];
|
|
119
|
-
let doneInfo: any = null;
|
|
120
|
-
try {
|
|
121
|
-
for await (const ev of streamSse(url, { body, signal: ac.signal, headers: { "X-Request-Id": requestId } })) {
|
|
122
|
-
switch (ev.event) {
|
|
123
|
-
case "phase":
|
|
124
|
-
if (!args.json) out(color.dim(`[phase] ${ev.data.phase} (max ${ev.data.maxImages ?? maxImages})`));
|
|
125
|
-
break;
|
|
126
|
-
case "partial":
|
|
127
|
-
if (args["show-partial"] && !args.json) {
|
|
128
|
-
const len = (ev.data.image || "").length;
|
|
129
|
-
out(color.dim(`[partial #${ev.data.index}] (${len}B preview)`));
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
case "image":
|
|
133
|
-
images.push(ev.data);
|
|
134
|
-
if (!args.json) out(color.green(`✓ image ${images.length}`));
|
|
135
|
-
break;
|
|
136
|
-
case "done":
|
|
137
|
-
doneInfo = ev.data;
|
|
138
|
-
break;
|
|
139
|
-
case "error":
|
|
140
|
-
die(1, `multimode error: ${ev.data.error || ev.data}${ev.data.code ? ` (${ev.data.code})` : ""}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
} catch (e: any) {
|
|
144
|
-
const isTimeout = e.name === "TimeoutError" || (e.name === "AbortError" && timedOut);
|
|
145
|
-
if (e.name === "AbortError" && !timedOut) return;
|
|
146
|
-
if (isTimeout && (explicitOut || outDir)) {
|
|
147
|
-
const result = await recoverGeneratedOutputs(server.base, requestId, {
|
|
148
|
-
explicitOut,
|
|
149
|
-
outDir,
|
|
150
|
-
expectedCount: maxImages,
|
|
151
|
-
json: Boolean(args.json),
|
|
152
|
-
});
|
|
153
|
-
if (result.recovered) {
|
|
154
|
-
if (args.json) {
|
|
155
|
-
json({ ok: true, requestId, recovered: true, paths: result.paths });
|
|
156
|
-
} else {
|
|
157
|
-
out(formatRecoveryHint(result));
|
|
158
|
-
for (const p of result.paths) out(color.green("✓ ") + p + color.dim(" (recovered)"));
|
|
159
|
-
}
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (!args.json) out(formatRecoveryHint(result));
|
|
163
|
-
}
|
|
164
|
-
die(exitCodeForError(e), `${e.message}${e.code ? ` (${e.code})` : ""}`);
|
|
165
|
-
} finally {
|
|
166
|
-
clearTimeout(timeoutTimer);
|
|
167
|
-
process.off("SIGINT", onSig);
|
|
168
|
-
process.off("SIGTERM", onSig);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Save images
|
|
172
|
-
if (explicitOut && images.length > 1) {
|
|
173
|
-
if (!args.json) out(color.yellow(`(received ${images.length} images, --out only saves first)`));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const savedPaths: string[] = [];
|
|
177
|
-
for (let i = 0; i < images.length; i++) {
|
|
178
|
-
const im = images[i];
|
|
179
|
-
if (!im.image) continue;
|
|
180
|
-
let target;
|
|
181
|
-
if (explicitOut && i === 0) target = explicitOut;
|
|
182
|
-
else if (outDir) target = `${outDir}/${defaultOutName(i, images.length)}`;
|
|
183
|
-
else target = `${config.storage.generatedDir}/${defaultOutName(i, images.length)}`;
|
|
184
|
-
if (target) {
|
|
185
|
-
await dataUriToFile(im.image, target);
|
|
186
|
-
savedPaths.push(target);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (args.json) {
|
|
191
|
-
json({ ok: true, requestId: doneInfo?.requestId, returned: doneInfo?.returned, paths: savedPaths });
|
|
192
|
-
} else {
|
|
193
|
-
for (const p of savedPaths) out(color.green("✓ ") + p);
|
|
194
|
-
if (doneInfo) out(color.dim(`done: ${doneInfo.returned}/${doneInfo.requested ?? maxImages}`));
|
|
195
|
-
}
|
|
196
|
-
}
|
package/bin/commands/node.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { parseArgs, type ParsedArgs } from "../lib/args.js";
|
|
2
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
3
|
-
import { streamSse } from "../lib/sse.js";
|
|
4
|
-
import { fileToDataUri, dataUriToFile, defaultOutName } from "../lib/files.js";
|
|
5
|
-
import { out, die, color, json, exitCodeForError } from "../lib/output.js";
|
|
6
|
-
import { config } from "../../config.js";
|
|
7
|
-
|
|
8
|
-
const HELP = `
|
|
9
|
-
ima2 node <subcommand> [options]
|
|
10
|
-
|
|
11
|
-
Subcommands:
|
|
12
|
-
generate <prompt...> [--parent <nodeId>] [--ref <file>...] [--provider <auto|oauth|api|grok>] [--no-stream] [...gen-style flags]
|
|
13
|
-
show <nodeId> [--json]
|
|
14
|
-
|
|
15
|
-
Generate options:
|
|
16
|
-
--provider <auto|oauth|api|grok> Provider for this request; grok uses progrok proxy
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
const GEN_FLAGS = {
|
|
20
|
-
quality: { short: "q", type: "string", default: "low" },
|
|
21
|
-
size: { short: "s", type: "string", default: "1024x1024" },
|
|
22
|
-
count: { short: "n", type: "string", default: "1" },
|
|
23
|
-
ref: { type: "string", repeatable: true },
|
|
24
|
-
out: { short: "o", type: "string" },
|
|
25
|
-
json: { type: "boolean" },
|
|
26
|
-
timeout: { type: "string", default: "600" },
|
|
27
|
-
server: { type: "string" },
|
|
28
|
-
model: { type: "string" },
|
|
29
|
-
provider: { type: "string" },
|
|
30
|
-
parent: { type: "string" },
|
|
31
|
-
"reasoning-effort": { type: "string" },
|
|
32
|
-
"web-search": { type: "boolean" },
|
|
33
|
-
"no-web-search": { type: "boolean" },
|
|
34
|
-
moderation: { type: "string", default: "low" },
|
|
35
|
-
session: { type: "string" },
|
|
36
|
-
"no-stream": { type: "boolean" },
|
|
37
|
-
help: { short: "h", type: "boolean" },
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const SHOW_FLAGS = {
|
|
41
|
-
json: { type: "boolean" },
|
|
42
|
-
server: { type: "string" },
|
|
43
|
-
help: { short: "h", type: "boolean" },
|
|
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
|
-
async function generateSub(argv: string[]) {
|
|
52
|
-
const args = parseArgs(argv, { flags: GEN_FLAGS });
|
|
53
|
-
if (args.help) { out(HELP); return; }
|
|
54
|
-
const prompt = args.positional.join(" ");
|
|
55
|
-
if (!prompt) die(2, "prompt required");
|
|
56
|
-
const refs = (Array.isArray(args.ref) ? args.ref : []) as string[];
|
|
57
|
-
const VALID_PROVIDERS = new Set(["auto", "oauth", "api", "grok"]);
|
|
58
|
-
const VALID_REASONING = new Set(["none", "low", "medium", "high", "xhigh"]);
|
|
59
|
-
if (args.provider && !VALID_PROVIDERS.has(String(args.provider))) {
|
|
60
|
-
die(2, "--provider must be one of: auto, oauth, api, grok");
|
|
61
|
-
}
|
|
62
|
-
if (args["reasoning-effort"] && !VALID_REASONING.has(String(args["reasoning-effort"]))) {
|
|
63
|
-
die(2, "--reasoning-effort must be one of: none, low, medium, high, xhigh");
|
|
64
|
-
}
|
|
65
|
-
if (args["web-search"] && args["no-web-search"]) {
|
|
66
|
-
die(2, "--web-search and --no-web-search are mutually exclusive");
|
|
67
|
-
}
|
|
68
|
-
const references = await Promise.all(refs.map((p: string) => fileToDataUri(p)));
|
|
69
|
-
const server = await getServer(args);
|
|
70
|
-
const body: any = {
|
|
71
|
-
prompt,
|
|
72
|
-
quality: args.quality,
|
|
73
|
-
size: args.size,
|
|
74
|
-
n: Math.max(1, Math.min(8, parseInt(String(args.count)) || 1)),
|
|
75
|
-
references,
|
|
76
|
-
moderation: args.moderation,
|
|
77
|
-
sessionId: args.session,
|
|
78
|
-
};
|
|
79
|
-
if (args.model) body.model = args.model;
|
|
80
|
-
if (args.provider) body.provider = args.provider;
|
|
81
|
-
if (args.parent) body.parentNodeId = args.parent;
|
|
82
|
-
if (args["reasoning-effort"]) body.reasoningEffort = args["reasoning-effort"];
|
|
83
|
-
if (args["no-web-search"]) body.webSearchEnabled = false;
|
|
84
|
-
else if (args["web-search"]) body.webSearchEnabled = true;
|
|
85
|
-
|
|
86
|
-
if (args["no-stream"]) {
|
|
87
|
-
const resp: any = await request(server.base, "/api/node/generate", {
|
|
88
|
-
method: "POST",
|
|
89
|
-
body,
|
|
90
|
-
timeoutMs: (parseInt(String(args.timeout)) || 600) * 1000,
|
|
91
|
-
}).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
|
|
92
|
-
if (args.json) { json(resp); return; }
|
|
93
|
-
out(color.green("✓ node ") + (resp?.node?.id || "(no id)"));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const ac = new AbortController();
|
|
98
|
-
const onSig = () => { ac.abort(); process.exit(130); };
|
|
99
|
-
process.once("SIGINT", onSig); process.once("SIGTERM", onSig);
|
|
100
|
-
|
|
101
|
-
const url = `${server.base}/api/node/generate`;
|
|
102
|
-
const images: any[] = [];
|
|
103
|
-
let doneInfo: any = null;
|
|
104
|
-
try {
|
|
105
|
-
for await (const ev of streamSse(url, { body, signal: ac.signal })) {
|
|
106
|
-
switch (ev.event) {
|
|
107
|
-
case "phase":
|
|
108
|
-
if (!args.json) out(color.dim(`[phase] ${ev.data.phase || ev.data}`));
|
|
109
|
-
break;
|
|
110
|
-
case "partial":
|
|
111
|
-
if (!args.json) out(color.dim(`[partial #${ev.data.index ?? "?"}]`));
|
|
112
|
-
break;
|
|
113
|
-
case "image":
|
|
114
|
-
images.push(ev.data);
|
|
115
|
-
if (!args.json) out(color.green(`✓ image ${images.length}`));
|
|
116
|
-
break;
|
|
117
|
-
case "done":
|
|
118
|
-
doneInfo = ev.data;
|
|
119
|
-
break;
|
|
120
|
-
case "error":
|
|
121
|
-
die(1, `node generate error: ${ev.data.error || ev.data}${ev.data.code ? ` (${ev.data.code})` : ""}`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch (e: any) {
|
|
125
|
-
if (e.name === "AbortError") return;
|
|
126
|
-
die(exitCodeForError(e), `${e.message}${e.code ? ` (${e.code})` : ""}`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const savedPaths: string[] = [];
|
|
130
|
-
for (let i = 0; i < images.length; i++) {
|
|
131
|
-
const im = images[i];
|
|
132
|
-
if (!im.image) continue;
|
|
133
|
-
const target: string = args.out && i === 0
|
|
134
|
-
? String(args.out)
|
|
135
|
-
: `${config.storage.generatedDir}/${defaultOutName(i, images.length)}`;
|
|
136
|
-
await dataUriToFile(im.image, target);
|
|
137
|
-
savedPaths.push(target);
|
|
138
|
-
}
|
|
139
|
-
if (args.json) {
|
|
140
|
-
json({ ok: true, paths: savedPaths, doneInfo });
|
|
141
|
-
} else {
|
|
142
|
-
for (const p of savedPaths) out(color.green("✓ ") + p);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async function showSub(argv: string[]) {
|
|
147
|
-
const args = parseArgs(argv, { flags: SHOW_FLAGS });
|
|
148
|
-
const id = args.positional[0];
|
|
149
|
-
if (!id) die(2, "nodeId required");
|
|
150
|
-
const server = await getServer(args);
|
|
151
|
-
const resp = await request(server.base, `/api/node/${encodeURIComponent(id)}`).catch((e: unknown) => { const err = e as { message?: string }; die(exitCodeForError(e), err.message); });
|
|
152
|
-
json(resp);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const SUB: Record<string, (argv: any[]) => Promise<void>> = {
|
|
156
|
-
generate: generateSub,
|
|
157
|
-
show: showSub,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export default async function nodeCmd(argv: string[]) {
|
|
161
|
-
const sub = argv[0];
|
|
162
|
-
if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
|
|
163
|
-
const handler = SUB[sub];
|
|
164
|
-
if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
|
|
165
|
-
return handler(argv.slice(1));
|
|
166
|
-
}
|
|
@@ -1,176 +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, table, exitCodeForError } from "../lib/output.js";
|
|
4
|
-
|
|
5
|
-
const HELP = `
|
|
6
|
-
ima2 <domain> <subcommand> [options]
|
|
7
|
-
|
|
8
|
-
Storage:
|
|
9
|
-
storage status [--json] Storage inspection
|
|
10
|
-
storage open Open generated-dir in OS file manager
|
|
11
|
-
|
|
12
|
-
Billing / Providers / GPT OAuth:
|
|
13
|
-
billing [--json] API usage / quota
|
|
14
|
-
providers [--json] Configured providers
|
|
15
|
-
oauth status [--json] GPT OAuth proxy state
|
|
16
|
-
|
|
17
|
-
Inflight jobs:
|
|
18
|
-
inflight ls [--kind classic|node|multimode] [--session <id>] [--terminal] [--json]
|
|
19
|
-
inflight rm <requestId> [--json] Force-remove a stuck job
|
|
20
|
-
|
|
21
|
-
Options:
|
|
22
|
-
--json Output raw JSON
|
|
23
|
-
--server <url> Override server URL
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
const FLAGS = {
|
|
27
|
-
json: { type: "boolean" },
|
|
28
|
-
server: { type: "string" },
|
|
29
|
-
kind: { type: "string" },
|
|
30
|
-
session: { type: "string" },
|
|
31
|
-
terminal: { type: "boolean" },
|
|
32
|
-
help: { short: "h", type: "boolean" },
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
async function getServer(args: ParsedArgs) {
|
|
36
|
-
try { return await resolveServer({ serverFlag: args.server }); }
|
|
37
|
-
catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function storageStatusSub(argv: string[]) {
|
|
41
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
42
|
-
const server = await getServer(args);
|
|
43
|
-
const resp = await request(server.base, "/api/storage/status")
|
|
44
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
45
|
-
if (args.json) { json(resp); return; }
|
|
46
|
-
out(JSON.stringify(resp, null, 2));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function storageOpenSub(argv: string[]) {
|
|
50
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
51
|
-
const server = await getServer(args);
|
|
52
|
-
await request(server.base, "/api/storage/open-generated-dir", { method: "POST" })
|
|
53
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
54
|
-
out(color.green("✓ ") + "opened generated directory");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function billingSub(argv: string[]) {
|
|
58
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
59
|
-
const server = await getServer(args);
|
|
60
|
-
const resp = await request(server.base, "/api/billing")
|
|
61
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
62
|
-
if (args.json) { json(resp); return; }
|
|
63
|
-
out(JSON.stringify(resp, null, 2));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function providersSub(argv: string[]) {
|
|
67
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
68
|
-
const server = await getServer(args);
|
|
69
|
-
const resp = await request(server.base, "/api/providers")
|
|
70
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
71
|
-
if (args.json) { json(resp); return; }
|
|
72
|
-
out(JSON.stringify(resp, null, 2));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function oauthStatusSub(argv: string[]) {
|
|
76
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
77
|
-
const server = await getServer(args);
|
|
78
|
-
const resp = await request(server.base, "/api/oauth/status")
|
|
79
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
80
|
-
if (args.json) { json(resp); return; }
|
|
81
|
-
out(JSON.stringify(resp, null, 2));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function inflightLsSub(argv: string[]) {
|
|
85
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
86
|
-
const server = await getServer(args);
|
|
87
|
-
const qs = new URLSearchParams();
|
|
88
|
-
if (args.kind) qs.set("kind", String(args.kind));
|
|
89
|
-
if (args.session) qs.set("sessionId", String(args.session));
|
|
90
|
-
if (args.terminal) qs.set("includeTerminal", "1");
|
|
91
|
-
const path = `/api/inflight${qs.toString() ? `?${qs}` : ""}`;
|
|
92
|
-
const resp = await request(server.base, path)
|
|
93
|
-
.catch((e: unknown) => { const err = e as { message?: string }; die(exitCodeForError(e), err.message); });
|
|
94
|
-
const jobs = resp.jobs || resp.items || [];
|
|
95
|
-
const terminalJobs = resp.terminalJobs || [];
|
|
96
|
-
if (args.json) {
|
|
97
|
-
json(args.terminal ? { jobs, terminalJobs } : { jobs });
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (jobs.length === 0 && terminalJobs.length === 0) {
|
|
101
|
-
out(color.dim(args.terminal ? "(no active or terminal jobs)" : "(no active jobs)"));
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const now = Date.now();
|
|
105
|
-
if (jobs.length > 0) {
|
|
106
|
-
out(color.bold("Active jobs"));
|
|
107
|
-
table(jobs, [
|
|
108
|
-
{ key: "requestId", label: "ID", format: (v: unknown) => String(v || "").slice(0, 10) },
|
|
109
|
-
{ key: "kind", label: "KIND" },
|
|
110
|
-
{ key: "phase", label: "PHASE" },
|
|
111
|
-
{ key: "startedAt", label: "AGE", format: (v: unknown) => v ? `${Math.round((now - Number(v)) / 1000)}s` : "" },
|
|
112
|
-
{ key: "prompt", label: "PROMPT", format: (v: unknown) => {
|
|
113
|
-
const s = String(v || "").replace(/\s+/g, " ");
|
|
114
|
-
return s.length > 40 ? s.slice(0, 37) + "…" : s;
|
|
115
|
-
} },
|
|
116
|
-
]);
|
|
117
|
-
}
|
|
118
|
-
if (terminalJobs.length > 0) {
|
|
119
|
-
if (jobs.length > 0) out("");
|
|
120
|
-
out(color.bold("Terminal jobs"));
|
|
121
|
-
table(terminalJobs, [
|
|
122
|
-
{ key: "requestId", label: "ID", format: (v: unknown) => String(v || "").slice(0, 10) },
|
|
123
|
-
{ key: "kind", label: "KIND" },
|
|
124
|
-
{ key: "status", label: "STATUS" },
|
|
125
|
-
{ key: "finishedAt", label: "AGE", format: (v: unknown) => v ? `${Math.round((now - Number(v)) / 1000)}s` : "" },
|
|
126
|
-
{ key: "prompt", label: "PROMPT", format: (v: unknown) => {
|
|
127
|
-
const s = String(v || "").replace(/\s+/g, " ");
|
|
128
|
-
return s.length > 40 ? s.slice(0, 37) + "…" : s;
|
|
129
|
-
} },
|
|
130
|
-
]);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async function inflightRmSub(argv: string[]) {
|
|
135
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
136
|
-
const requestId = args.positional[0];
|
|
137
|
-
if (!requestId) die(2, "requestId required");
|
|
138
|
-
const server = await getServer(args);
|
|
139
|
-
await request(server.base, `/api/inflight/${encodeURIComponent(requestId)}`, { method: "DELETE" })
|
|
140
|
-
.catch((e: unknown) => { const err = e as { message?: string }; die(exitCodeForError(e), err.message); });
|
|
141
|
-
if (args.json) { json({ ok: true, requestId }); return; }
|
|
142
|
-
out(color.green("✓ ") + `removed ${requestId}`);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export default async function observabilityCmd(argv: string[]) {
|
|
146
|
-
const domain = argv[0];
|
|
147
|
-
const rest = argv.slice(1);
|
|
148
|
-
if (!domain || domain === "--help" || domain === "-h") { out(HELP); return; }
|
|
149
|
-
if (rest[0] === "--help" || rest[0] === "-h") { out(HELP); return; }
|
|
150
|
-
|
|
151
|
-
if (domain === "storage") {
|
|
152
|
-
const sub = rest[0];
|
|
153
|
-
if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
|
|
154
|
-
if (sub === "status") return storageStatusSub(rest.slice(1));
|
|
155
|
-
if (sub === "open") return storageOpenSub(rest.slice(1));
|
|
156
|
-
die(2, `unknown subcommand: storage ${sub}\n${HELP}`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (domain === "billing") return billingSub(rest);
|
|
160
|
-
if (domain === "providers") return providersSub(rest);
|
|
161
|
-
|
|
162
|
-
if (domain === "oauth") {
|
|
163
|
-
const sub = rest[0];
|
|
164
|
-
if (!sub || sub === "status") return oauthStatusSub(rest.slice(sub === "status" ? 1 : 0));
|
|
165
|
-
die(2, `unknown subcommand: oauth ${sub}\n${HELP}`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (domain === "inflight") {
|
|
169
|
-
const sub = rest[0];
|
|
170
|
-
if (!sub || sub === "ls") return inflightLsSub(sub === "ls" ? rest.slice(1) : rest);
|
|
171
|
-
if (sub === "rm") return inflightRmSub(rest.slice(1));
|
|
172
|
-
die(2, `unknown subcommand: inflight ${sub}\n${HELP}`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
die(2, `unknown domain: ${domain}\n${HELP}`);
|
|
176
|
-
}
|
package/bin/commands/ping.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from "../lib/args.js";
|
|
2
|
-
import { resolveServer } from "../lib/client.js";
|
|
3
|
-
import { out, die, color, json, exitCodeForError } 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
|
-
export default async function pingCmd(argv: string[]) {
|
|
15
|
-
const args = parseArgs(argv, SPEC);
|
|
16
|
-
if (args.help) { out("ima2 ping [--json]"); return; }
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const { base, health } = await resolveServer({ serverFlag: args.server });
|
|
20
|
-
const h: any = health;
|
|
21
|
-
if (args.json) {
|
|
22
|
-
json({ ok: true, base, ...h });
|
|
23
|
-
} else {
|
|
24
|
-
out(color.green("✓ ") + `${base} v${h.version} uptime ${h.uptimeSec}s activeJobs ${h.activeJobs}`);
|
|
25
|
-
}
|
|
26
|
-
} catch (e) {
|
|
27
|
-
const err = errInfo(e);
|
|
28
|
-
if (args.json) { json({ ok: false, error: err.message }); process.exit(exitCodeForError(e)); }
|
|
29
|
-
die(exitCodeForError(e), err.message);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
2
|
-
import { parseArgs } from "../../lib/args.js";
|
|
3
|
-
import { resolveServer, request } from "../../lib/client.js";
|
|
4
|
-
import { readStdin } from "../../lib/files.js";
|
|
5
|
-
import { out, die, color, json, exitCodeForError } from "../../lib/output.js";
|
|
6
|
-
|
|
7
|
-
const BUILD_HELP = `
|
|
8
|
-
ima2 prompt build [options]
|
|
9
|
-
|
|
10
|
-
Refine prompt intent through the embedded prompt builder.
|
|
11
|
-
|
|
12
|
-
Options:
|
|
13
|
-
--message <text> User message (required unless --messages)
|
|
14
|
-
--messages <file|@file|-> Multi-turn conversation as JSON array
|
|
15
|
-
--ref <image> Image reference (repeatable)
|
|
16
|
-
--model <model> Builder model (gpt-5.5, gpt-5.4, gpt-5.4-mini)
|
|
17
|
-
--language <ko|en|both> Preferred output language hint
|
|
18
|
-
--server <url> Override server URL
|
|
19
|
-
--json Output raw JSON
|
|
20
|
-
-h, --help Show this help
|
|
21
|
-
|
|
22
|
-
Examples:
|
|
23
|
-
ima2 prompt build --message "make this prompt more cinematic" --json
|
|
24
|
-
ima2 prompt build --messages @conversation.json --model gpt-5.5
|
|
25
|
-
echo '{"role":"user","content":"hi"}' | ima2 prompt build --messages -
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
const FLAGS = {
|
|
29
|
-
message: { type: "string" },
|
|
30
|
-
messages: { type: "string" },
|
|
31
|
-
ref: { type: "string", repeatable: true },
|
|
32
|
-
model: { type: "string" },
|
|
33
|
-
language: { type: "string" },
|
|
34
|
-
server: { type: "string" },
|
|
35
|
-
json: { type: "boolean" },
|
|
36
|
-
help: { short: "h", type: "boolean" },
|
|
37
|
-
} as const;
|
|
38
|
-
|
|
39
|
-
async function resolveMessages(args: Record<string, unknown>): Promise<Array<{ role: string; content: string }>> {
|
|
40
|
-
if (args.messages) {
|
|
41
|
-
const raw = String(args.messages);
|
|
42
|
-
let text: string;
|
|
43
|
-
if (raw === "-") {
|
|
44
|
-
text = await readStdin();
|
|
45
|
-
} else if (raw.startsWith("@")) {
|
|
46
|
-
text = await readFile(raw.slice(1), "utf-8");
|
|
47
|
-
} else {
|
|
48
|
-
text = await readFile(raw, "utf-8");
|
|
49
|
-
}
|
|
50
|
-
const parsed = JSON.parse(text);
|
|
51
|
-
if (!Array.isArray(parsed)) die(2, "--messages must resolve to a JSON array");
|
|
52
|
-
return parsed;
|
|
53
|
-
}
|
|
54
|
-
if (args.message) {
|
|
55
|
-
return [{ role: "user", content: String(args.message) }];
|
|
56
|
-
}
|
|
57
|
-
die(2, "--message or --messages required");
|
|
58
|
-
throw new Error("unreachable");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default async function buildSub(argv: string[]) {
|
|
62
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
63
|
-
if (args.help) { out(BUILD_HELP); return; }
|
|
64
|
-
|
|
65
|
-
const messages = await resolveMessages(args);
|
|
66
|
-
const body: Record<string, unknown> = { messages };
|
|
67
|
-
if (args.model) body.model = args.model;
|
|
68
|
-
|
|
69
|
-
let server: { base: string };
|
|
70
|
-
try {
|
|
71
|
-
server = await resolveServer({ serverFlag: args.server as string | undefined });
|
|
72
|
-
} catch (e: unknown) {
|
|
73
|
-
die(exitCodeForError(e), (e as Error).message);
|
|
74
|
-
throw e;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let result: Record<string, unknown>;
|
|
78
|
-
try {
|
|
79
|
-
result = await request(server.base, "/api/prompt-builder/chat", {
|
|
80
|
-
method: "POST",
|
|
81
|
-
body,
|
|
82
|
-
}) as Record<string, unknown>;
|
|
83
|
-
} catch (e: unknown) {
|
|
84
|
-
const err = e as { message?: string; code?: string };
|
|
85
|
-
die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`);
|
|
86
|
-
throw e;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (args.json) {
|
|
90
|
-
json(result);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const message = result.message as { content?: string } | undefined;
|
|
95
|
-
const content = message?.content ?? "";
|
|
96
|
-
if (content) {
|
|
97
|
-
out(content);
|
|
98
|
-
} else {
|
|
99
|
-
out(color.dim("(empty response)"));
|
|
100
|
-
}
|
|
101
|
-
}
|