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.
- package/README.md +44 -7
- package/bin/commands/video.js +14 -0
- package/bin/ima2.js +14 -4
- package/bin/lib/platform.js +34 -5
- package/docs/README.ko.md +43 -2
- package/lib/agentQueueWorker.js +6 -0
- package/lib/agentRuntime.js +3 -2
- package/lib/atomicWrite.js +14 -0
- package/lib/grokImageAdapter.js +6 -0
- package/lib/grokProxyLauncher.js +5 -3
- package/lib/grokVideoAdapter.js +1 -1
- package/lib/grokVideoPlannerPrompt.js +10 -0
- 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/capabilities.js +13 -0
- package/routes/edit.js +2 -1
- package/routes/generate.js +32 -6
- package/routes/health.js +4 -3
- package/routes/multimode.js +2 -1
- package/routes/video.js +35 -3
- package/server.js +29 -2
- package/skills/ima2/SKILL.md +48 -6
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-C21zqdTZ.js} +1 -1
- package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-BN-ga1lG.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BbMa4IhI.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DRwBJRDQ.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-Dp85kHCq.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BE8Q8MLD.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-PtH5x0sc.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-FnM9tHI9.js} +2 -2
- package/ui/dist/assets/SettingsWorkspace-MARPGyBL.js +1 -0
- package/ui/dist/assets/index-BAFI6htx.js +42 -0
- package/ui/dist/assets/{index-31uVIdt4.js → index-BSXxr_Bt.js} +1 -1
- package/ui/dist/assets/index-DS-ADE7U.css +1 -0
- 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
package/bin/lib/star-prompt.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { createInterface } from "node:readline/promises";
|
|
6
|
-
import { config } from "../../config.js";
|
|
7
|
-
|
|
8
|
-
const REPO = "lidge-jun/ima2-gen";
|
|
9
|
-
|
|
10
|
-
export function starPromptStatePath() {
|
|
11
|
-
return join(config.storage.configDir, "state", "star-prompt.json");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function hasBeenPrompted() {
|
|
15
|
-
const path = starPromptStatePath();
|
|
16
|
-
if (!existsSync(path)) return false;
|
|
17
|
-
try {
|
|
18
|
-
const content = await readFile(path, "utf8");
|
|
19
|
-
const state = JSON.parse(content);
|
|
20
|
-
return typeof state.prompted_at === "string";
|
|
21
|
-
} catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function markPrompted() {
|
|
27
|
-
const path = starPromptStatePath();
|
|
28
|
-
await mkdir(dirname(path), { recursive: true });
|
|
29
|
-
await writeFile(path, JSON.stringify({ prompted_at: new Date().toISOString() }, null, 2));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function isGhInstalled() {
|
|
33
|
-
const result = spawnSync("gh", ["--version"], {
|
|
34
|
-
encoding: "utf8",
|
|
35
|
-
stdio: ["ignore", "ignore", "ignore"],
|
|
36
|
-
timeout: 3000,
|
|
37
|
-
windowsHide: true,
|
|
38
|
-
});
|
|
39
|
-
return !result.error && result.status === 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function starRepo(spawnSyncFn = spawnSync) {
|
|
43
|
-
const result = spawnSyncFn("gh", ["api", "-X", "PUT", `/user/starred/${REPO}`], {
|
|
44
|
-
encoding: "utf8",
|
|
45
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
46
|
-
timeout: 10000,
|
|
47
|
-
windowsHide: true,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
if (result.error) return { ok: false, error: result.error.message };
|
|
51
|
-
if (result.status !== 0) {
|
|
52
|
-
const stderr = (result.stderr || "").trim();
|
|
53
|
-
const stdout = (result.stdout || "").trim();
|
|
54
|
-
return { ok: false, error: stderr || stdout || `gh exited ${result.status}` };
|
|
55
|
-
}
|
|
56
|
-
return { ok: true };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function askYesNo(question: string) {
|
|
60
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
61
|
-
try {
|
|
62
|
-
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
63
|
-
return answer === "" || answer === "y" || answer === "yes";
|
|
64
|
-
} finally {
|
|
65
|
-
rl.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function maybePromptGithubStar(deps: any = {}) {
|
|
70
|
-
const stdinIsTTY = deps.stdinIsTTY ?? process.stdin.isTTY;
|
|
71
|
-
const stdoutIsTTY = deps.stdoutIsTTY ?? process.stdout.isTTY;
|
|
72
|
-
if (!stdinIsTTY || !stdoutIsTTY) return;
|
|
73
|
-
|
|
74
|
-
const hasBeenPromptedImpl = deps.hasBeenPromptedFn ?? hasBeenPrompted;
|
|
75
|
-
if (await hasBeenPromptedImpl()) return;
|
|
76
|
-
|
|
77
|
-
const isGhInstalledImpl = deps.isGhInstalledFn ?? isGhInstalled;
|
|
78
|
-
if (!isGhInstalledImpl()) return;
|
|
79
|
-
|
|
80
|
-
const markPromptedImpl = deps.markPromptedFn ?? markPrompted;
|
|
81
|
-
await markPromptedImpl();
|
|
82
|
-
|
|
83
|
-
const askYesNoImpl = deps.askYesNoFn ?? askYesNo;
|
|
84
|
-
const approved = await askYesNoImpl("[ima2] Enjoying ima2-gen? Star it on GitHub? [Y/n] ");
|
|
85
|
-
if (!approved) return;
|
|
86
|
-
|
|
87
|
-
const starRepoImpl = deps.starRepoFn ?? starRepo;
|
|
88
|
-
const star = starRepoImpl();
|
|
89
|
-
if (star.ok) {
|
|
90
|
-
const log = deps.logFn ?? console.log;
|
|
91
|
-
log("[ima2] Thanks for the star!");
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const warn = deps.warnFn ?? console.warn;
|
|
96
|
-
warn(`[ima2] Could not star repository automatically: ${star.error}`);
|
|
97
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { inspectGeneratedStorage } from "../../lib/storageMigration.js";
|
|
2
|
-
import type { RouteRuntimeContext } from "../../lib/runtimeContext.js";
|
|
3
|
-
|
|
4
|
-
export async function buildStorageDoctorLines(ctx: RouteRuntimeContext) {
|
|
5
|
-
const status = await inspectGeneratedStorage(ctx);
|
|
6
|
-
const lines = [
|
|
7
|
-
" Storage",
|
|
8
|
-
` Current gallery: ${status.generatedDirLabel}`,
|
|
9
|
-
` Source: ${status.overrides.generatedDir ? "IMA2_GENERATED_DIR" : "default"}`,
|
|
10
|
-
` Images in current gallery: ${status.targetFileCount}`,
|
|
11
|
-
` Legacy folders scanned: ${status.legacyCandidatesScanned}`,
|
|
12
|
-
` Legacy folders found: ${status.legacySourcesFound}`,
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
for (const source of status.legacySources.slice(0, 5) as Array<{ path: any; fileCount: number }>) {
|
|
16
|
-
lines.push(` - ${source.path} (${source.fileCount} files)`);
|
|
17
|
-
}
|
|
18
|
-
if (status.legacySources.length > 5) {
|
|
19
|
-
lines.push(` ...and ${status.legacySources.length - 5} more`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
lines.push("");
|
|
23
|
-
lines.push(" Next step");
|
|
24
|
-
if (status.state === "recoverable") {
|
|
25
|
-
lines.push(" Old images may still be recoverable. Restart ima2 or copy them manually.");
|
|
26
|
-
} else if (status.state === "not_found") {
|
|
27
|
-
lines.push(" No previous generated folder was found on this machine.");
|
|
28
|
-
lines.push(" If the old global install folder was replaced during update, backups may be required.");
|
|
29
|
-
} else if (status.state === "unknown") {
|
|
30
|
-
lines.push(" Storage status could not be fully checked.");
|
|
31
|
-
} else {
|
|
32
|
-
lines.push(" Current gallery storage looks available.");
|
|
33
|
-
}
|
|
34
|
-
lines.push(` See: ${status.recoveryDocsPath}`);
|
|
35
|
-
lines.push(" macOS/Linux: cp -n \"/old/ima2-gen/generated/\"* ~/.ima2/generated/");
|
|
36
|
-
lines.push(" Windows: Copy old generated files into %USERPROFILE%\\.ima2\\generated");
|
|
37
|
-
|
|
38
|
-
return lines;
|
|
39
|
-
}
|
package/bin/lib/ui-build.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import { existsSync, readdirSync, statSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { resolveBin } from "./platform.js";
|
|
5
|
-
|
|
6
|
-
export type UiDistBuildStatus =
|
|
7
|
-
| { needsBuild: false; reason: "fresh" | "source-missing" }
|
|
8
|
-
| { needsBuild: true; reason: "missing" | "stale" }
|
|
9
|
-
| { needsBuild: false; reason: "missing-source-and-dist"; error: string };
|
|
10
|
-
|
|
11
|
-
export type EnsureFreshUiDistResult =
|
|
12
|
-
| { ok: true; built: boolean; reason: UiDistBuildStatus["reason"] }
|
|
13
|
-
| { ok: false; reason: UiDistBuildStatus["reason"] | "build-failed"; error: string };
|
|
14
|
-
|
|
15
|
-
const SOURCE_DIRS = ["src", "public"];
|
|
16
|
-
const SOURCE_FILES = [
|
|
17
|
-
"index.html",
|
|
18
|
-
"package.json",
|
|
19
|
-
"package-lock.json",
|
|
20
|
-
"vite.config.js",
|
|
21
|
-
"vite.config.mjs",
|
|
22
|
-
"vite.config.ts",
|
|
23
|
-
"tsconfig.json",
|
|
24
|
-
"tsconfig.app.json",
|
|
25
|
-
"tsconfig.node.json",
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
function latestMtimeMs(path: string): number {
|
|
29
|
-
if (!existsSync(path)) return 0;
|
|
30
|
-
const stat = statSync(path);
|
|
31
|
-
if (!stat.isDirectory()) return stat.mtimeMs;
|
|
32
|
-
let latest = 0;
|
|
33
|
-
for (const entry of readdirSync(path)) {
|
|
34
|
-
if (entry === "node_modules" || entry === "dist" || entry === ".vite") continue;
|
|
35
|
-
latest = Math.max(latest, latestMtimeMs(join(path, entry)));
|
|
36
|
-
}
|
|
37
|
-
return latest;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function latestUiSourceMtimeMs(uiDir: string): number {
|
|
41
|
-
const sourceTimes = [
|
|
42
|
-
...SOURCE_DIRS.map((name) => latestMtimeMs(join(uiDir, name))),
|
|
43
|
-
...SOURCE_FILES.map((name) => latestMtimeMs(join(uiDir, name))),
|
|
44
|
-
];
|
|
45
|
-
return Math.max(0, ...sourceTimes);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getUiDistBuildStatus(root: string): UiDistBuildStatus {
|
|
49
|
-
const uiDir = join(root, "ui");
|
|
50
|
-
const distIndex = join(uiDir, "dist", "index.html");
|
|
51
|
-
const hasUiSource = existsSync(join(uiDir, "package.json"));
|
|
52
|
-
|
|
53
|
-
if (!existsSync(distIndex)) {
|
|
54
|
-
if (hasUiSource) return { needsBuild: true, reason: "missing" };
|
|
55
|
-
return {
|
|
56
|
-
needsBuild: false,
|
|
57
|
-
reason: "missing-source-and-dist",
|
|
58
|
-
error: "ui/dist not found and ui/ source is missing.",
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!hasUiSource) return { needsBuild: false, reason: "source-missing" };
|
|
63
|
-
|
|
64
|
-
const distMtime = statSync(distIndex).mtimeMs;
|
|
65
|
-
const sourceMtime = latestUiSourceMtimeMs(uiDir);
|
|
66
|
-
if (sourceMtime > distMtime + 1000) return { needsBuild: true, reason: "stale" };
|
|
67
|
-
return { needsBuild: false, reason: "fresh" };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function ensureFreshUiDist(root: string): EnsureFreshUiDistResult {
|
|
71
|
-
const status = getUiDistBuildStatus(root);
|
|
72
|
-
if (!status.needsBuild) {
|
|
73
|
-
if ("error" in status) return { ok: false, reason: status.reason, error: status.error };
|
|
74
|
-
return { ok: true, built: false, reason: status.reason };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const reason = status.reason === "missing" ? "missing" : "stale";
|
|
78
|
-
console.log(`\n ui/dist ${reason} — running 'npm run build' first...\n`);
|
|
79
|
-
try {
|
|
80
|
-
execSync(`${resolveBin("npm")} run build`, { stdio: "inherit", cwd: root });
|
|
81
|
-
return { ok: true, built: true, reason };
|
|
82
|
-
} catch {
|
|
83
|
-
return { ok: false, reason: "build-failed", error: "Build failed. Try: cd ui && npm install && npm run build" };
|
|
84
|
-
}
|
|
85
|
-
}
|
package/config.ts
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
// config.js — centralized runtime configuration (0.09.12).
|
|
2
|
-
//
|
|
3
|
-
// Single source of truth for ports, limits, paths, and tunables. All server,
|
|
4
|
-
// lib, and script code should import `config` (or named legacy constants) from
|
|
5
|
-
// here rather than reading `process.env` directly.
|
|
6
|
-
//
|
|
7
|
-
// Priority: env var > ${IMA2_CONFIG_DIR}/config.json > built-in default.
|
|
8
|
-
// `config.json` is loaded once at module import. Mutating the file at runtime
|
|
9
|
-
// requires a server restart (same as env vars).
|
|
10
|
-
//
|
|
11
|
-
// Keep this module dependency-free aside from node:* built-ins to avoid
|
|
12
|
-
// circular imports with lib/*.
|
|
13
|
-
|
|
14
|
-
import { homedir } from "node:os";
|
|
15
|
-
import { join, dirname } from "node:path";
|
|
16
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
18
|
-
|
|
19
|
-
const env = process.env;
|
|
20
|
-
const packageRoot = dirname(fileURLToPath(import.meta.url));
|
|
21
|
-
const configDir = env.IMA2_CONFIG_DIR || join(homedir(), ".ima2");
|
|
22
|
-
|
|
23
|
-
// ── Optional config.json layer ─────────────────────────────────────────
|
|
24
|
-
// Users can drop `${configDir}/config.json` to override defaults without
|
|
25
|
-
// setting env vars. Shape: same as the `config` object below (partial).
|
|
26
|
-
function loadConfigJson() {
|
|
27
|
-
const candidates = [
|
|
28
|
-
join(configDir, "config.json"),
|
|
29
|
-
join(packageRoot, ".ima2", "config.json"),
|
|
30
|
-
];
|
|
31
|
-
for (const p of candidates) {
|
|
32
|
-
if (!existsSync(p)) continue;
|
|
33
|
-
try {
|
|
34
|
-
const raw = readFileSync(p, "utf-8");
|
|
35
|
-
return JSON.parse(raw);
|
|
36
|
-
} catch {
|
|
37
|
-
// ignore malformed config.json; env+defaults still apply
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
const fileCfg = loadConfigJson();
|
|
43
|
-
|
|
44
|
-
type Pickable = string | number | boolean | undefined;
|
|
45
|
-
|
|
46
|
-
function firstDefined(...vals: Pickable[]): Pickable {
|
|
47
|
-
return vals.find((v) => v !== undefined && v !== "");
|
|
48
|
-
}
|
|
49
|
-
function pickInt(envVal: Pickable, fileVal: Pickable, fallback: number): number {
|
|
50
|
-
const candidate = firstDefined(envVal, fileVal);
|
|
51
|
-
if (candidate === undefined) return fallback;
|
|
52
|
-
const n = Number(candidate);
|
|
53
|
-
return Number.isFinite(n) ? n : fallback;
|
|
54
|
-
}
|
|
55
|
-
function pickPositiveInt(envVal: Pickable, fileVal: Pickable, fallback: number): number {
|
|
56
|
-
const n = pickInt(envVal, fileVal, fallback);
|
|
57
|
-
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
58
|
-
}
|
|
59
|
-
function pickStr(envVal: Pickable, fileVal: Pickable, fallback: string): string {
|
|
60
|
-
return (firstDefined(envVal, fileVal) ?? fallback) as string;
|
|
61
|
-
}
|
|
62
|
-
function pickBool(envVal: Pickable, fileVal: Pickable, fallback: boolean): boolean {
|
|
63
|
-
const v = firstDefined(envVal, fileVal);
|
|
64
|
-
if (v === undefined) return fallback;
|
|
65
|
-
if (typeof v === "boolean") return v;
|
|
66
|
-
const s = String(v).toLowerCase();
|
|
67
|
-
return s === "1" || s === "true" || s === "yes";
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function defaultLogLevelForEnv(runtimeEnv = env) {
|
|
71
|
-
return runtimeEnv.IMA2_DEV === "1" ? "debug" : "info";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const config = {
|
|
75
|
-
server: {
|
|
76
|
-
// Accept both IMA2_PORT and legacy PORT.
|
|
77
|
-
port: pickInt(firstDefined(env.IMA2_PORT, env.PORT), fileCfg.server?.port, 3333),
|
|
78
|
-
host: pickStr(env.IMA2_HOST, fileCfg.server?.host, "127.0.0.1"),
|
|
79
|
-
bodyLimit: pickStr(env.IMA2_BODY_LIMIT, fileCfg.server?.bodyLimit, "50mb"),
|
|
80
|
-
},
|
|
81
|
-
limits: {
|
|
82
|
-
maxRefB64Bytes: pickInt(env.IMA2_MAX_REF_B64_BYTES, fileCfg.limits?.maxRefB64Bytes, 7 * 1024 * 1024),
|
|
83
|
-
maxMetadataReadB64Bytes: pickInt(
|
|
84
|
-
env.IMA2_MAX_METADATA_READ_B64_BYTES,
|
|
85
|
-
fileCfg.limits?.maxMetadataReadB64Bytes,
|
|
86
|
-
12 * 1024 * 1024,
|
|
87
|
-
),
|
|
88
|
-
maxRefCount: pickInt(env.IMA2_MAX_REF_COUNT, fileCfg.limits?.maxRefCount, 5),
|
|
89
|
-
maxParallel: pickInt(env.IMA2_MAX_PARALLEL, fileCfg.limits?.maxParallel, 8),
|
|
90
|
-
graphMaxNodes: pickInt(env.IMA2_GRAPH_MAX_NODES, fileCfg.limits?.graphMaxNodes, 500),
|
|
91
|
-
graphMaxEdges: pickInt(env.IMA2_GRAPH_MAX_EDGES, fileCfg.limits?.graphMaxEdges, 1000),
|
|
92
|
-
promptImportMaxFileBytes: pickInt(
|
|
93
|
-
env.IMA2_PROMPT_IMPORT_MAX_FILE_BYTES,
|
|
94
|
-
fileCfg.limits?.promptImportMaxFileBytes,
|
|
95
|
-
512 * 1024,
|
|
96
|
-
),
|
|
97
|
-
promptImportMaxCandidatesPerFile: pickInt(
|
|
98
|
-
env.IMA2_PROMPT_IMPORT_MAX_CANDIDATES_PER_FILE,
|
|
99
|
-
fileCfg.limits?.promptImportMaxCandidatesPerFile,
|
|
100
|
-
100,
|
|
101
|
-
),
|
|
102
|
-
promptImportMaxCandidatesPerImport: pickInt(
|
|
103
|
-
env.IMA2_PROMPT_IMPORT_MAX_CANDIDATES_PER_IMPORT,
|
|
104
|
-
fileCfg.limits?.promptImportMaxCandidatesPerImport,
|
|
105
|
-
100,
|
|
106
|
-
),
|
|
107
|
-
promptImportFetchTimeoutMs: pickInt(
|
|
108
|
-
env.IMA2_PROMPT_IMPORT_FETCH_TIMEOUT_MS,
|
|
109
|
-
fileCfg.limits?.promptImportFetchTimeoutMs,
|
|
110
|
-
8000,
|
|
111
|
-
),
|
|
112
|
-
promptImportMaxCandidateChars: pickInt(
|
|
113
|
-
env.IMA2_PROMPT_IMPORT_MAX_CANDIDATE_CHARS,
|
|
114
|
-
fileCfg.limits?.promptImportMaxCandidateChars,
|
|
115
|
-
12000,
|
|
116
|
-
),
|
|
117
|
-
promptImportMinCandidateChars: pickInt(
|
|
118
|
-
env.IMA2_PROMPT_IMPORT_MIN_CANDIDATE_CHARS,
|
|
119
|
-
fileCfg.limits?.promptImportMinCandidateChars,
|
|
120
|
-
40,
|
|
121
|
-
),
|
|
122
|
-
promptImportMaxSourceCharsScanned: pickInt(
|
|
123
|
-
env.IMA2_PROMPT_IMPORT_MAX_SOURCE_CHARS_SCANNED,
|
|
124
|
-
fileCfg.limits?.promptImportMaxSourceCharsScanned,
|
|
125
|
-
512 * 1024,
|
|
126
|
-
),
|
|
127
|
-
promptImportMaxRepoIndexFiles: pickInt(
|
|
128
|
-
env.IMA2_PROMPT_IMPORT_MAX_REPO_INDEX_FILES,
|
|
129
|
-
fileCfg.limits?.promptImportMaxRepoIndexFiles,
|
|
130
|
-
500,
|
|
131
|
-
),
|
|
132
|
-
promptImportCuratedSearchLimit: pickInt(
|
|
133
|
-
env.IMA2_PROMPT_IMPORT_CURATED_SEARCH_LIMIT,
|
|
134
|
-
fileCfg.limits?.promptImportCuratedSearchLimit,
|
|
135
|
-
50,
|
|
136
|
-
),
|
|
137
|
-
promptImportIndexCacheTtlMs: pickInt(
|
|
138
|
-
env.IMA2_PROMPT_IMPORT_INDEX_CACHE_TTL_MS,
|
|
139
|
-
fileCfg.limits?.promptImportIndexCacheTtlMs,
|
|
140
|
-
24 * 60 * 60 * 1000,
|
|
141
|
-
),
|
|
142
|
-
promptImportMaxFolderFiles: pickInt(
|
|
143
|
-
env.IMA2_PROMPT_IMPORT_MAX_FOLDER_FILES,
|
|
144
|
-
fileCfg.limits?.promptImportMaxFolderFiles,
|
|
145
|
-
100,
|
|
146
|
-
),
|
|
147
|
-
promptImportMaxFolderPreviewFiles: pickInt(
|
|
148
|
-
env.IMA2_PROMPT_IMPORT_MAX_FOLDER_PREVIEW_FILES,
|
|
149
|
-
fileCfg.limits?.promptImportMaxFolderPreviewFiles,
|
|
150
|
-
20,
|
|
151
|
-
),
|
|
152
|
-
promptImportDiscoverySearchLimit: pickInt(
|
|
153
|
-
env.IMA2_PROMPT_IMPORT_DISCOVERY_SEARCH_LIMIT,
|
|
154
|
-
fileCfg.limits?.promptImportDiscoverySearchLimit,
|
|
155
|
-
20,
|
|
156
|
-
),
|
|
157
|
-
promptImportDiscoveryCacheTtlMs: pickInt(
|
|
158
|
-
env.IMA2_PROMPT_IMPORT_DISCOVERY_CACHE_TTL_MS,
|
|
159
|
-
fileCfg.limits?.promptImportDiscoveryCacheTtlMs,
|
|
160
|
-
60 * 60 * 1000,
|
|
161
|
-
),
|
|
162
|
-
promptImportDiscoveryMaxQueries: pickInt(
|
|
163
|
-
env.IMA2_PROMPT_IMPORT_DISCOVERY_MAX_QUERIES,
|
|
164
|
-
fileCfg.limits?.promptImportDiscoveryMaxQueries,
|
|
165
|
-
5,
|
|
166
|
-
),
|
|
167
|
-
},
|
|
168
|
-
history: {
|
|
169
|
-
defaultPageSize: pickInt(
|
|
170
|
-
env.IMA2_HISTORY_PAGE_SIZE,
|
|
171
|
-
fileCfg.history?.defaultPageSize ?? fileCfg.limits?.historyDefaultPageSize,
|
|
172
|
-
50,
|
|
173
|
-
),
|
|
174
|
-
maxPageCap: pickInt(
|
|
175
|
-
env.IMA2_HISTORY_MAX_PAGE,
|
|
176
|
-
fileCfg.history?.maxPageCap ?? fileCfg.limits?.historyMaxPageCap,
|
|
177
|
-
500,
|
|
178
|
-
),
|
|
179
|
-
},
|
|
180
|
-
oauth: {
|
|
181
|
-
// Accept both IMA2_OAUTH_PROXY_PORT and legacy OAUTH_PORT.
|
|
182
|
-
proxyPort: pickInt(firstDefined(env.IMA2_OAUTH_PROXY_PORT, env.OAUTH_PORT), fileCfg.oauth?.proxyPort, 10531),
|
|
183
|
-
// IMA2_NO_OAUTH_PROXY=1 disables auto-start; default is auto-start enabled.
|
|
184
|
-
autoStart: !pickBool(env.IMA2_NO_OAUTH_PROXY, fileCfg.oauth?.disableAutoStart, false),
|
|
185
|
-
statusTimeoutMs: pickInt(env.IMA2_OAUTH_STATUS_TIMEOUT_MS, fileCfg.oauth?.statusTimeoutMs, 3000),
|
|
186
|
-
generationTimeoutMs: pickInt(
|
|
187
|
-
env.IMA2_OAUTH_GENERATION_TIMEOUT_MS,
|
|
188
|
-
fileCfg.oauth?.generationTimeoutMs,
|
|
189
|
-
400 * 1000,
|
|
190
|
-
),
|
|
191
|
-
restartDelayMs: pickInt(env.IMA2_OAUTH_RESTART_DELAY_MS, fileCfg.oauth?.restartDelayMs, 5000),
|
|
192
|
-
// Provider-backed masked edit is off until upstream STEP-0 verification is recorded.
|
|
193
|
-
maskedEditEnabled: pickBool(
|
|
194
|
-
env.IMA2_OAUTH_MASKED_EDIT_ENABLED,
|
|
195
|
-
fileCfg.oauth?.maskedEditEnabled,
|
|
196
|
-
false,
|
|
197
|
-
),
|
|
198
|
-
forceImageToolChoice: pickBool(
|
|
199
|
-
env.IMA2_OAUTH_FORCE_IMAGE_TOOL_CHOICE,
|
|
200
|
-
fileCfg.oauth?.forceImageToolChoice,
|
|
201
|
-
true,
|
|
202
|
-
),
|
|
203
|
-
researchSuffix: pickStr(
|
|
204
|
-
env.IMA2_RESEARCH_SUFFIX,
|
|
205
|
-
fileCfg.oauth?.researchSuffix,
|
|
206
|
-
"\n\nIf factual visual accuracy is required and the user's prompt or attached visual context is not already sufficient, use at least one concise web_search call for references before generating. If the user's prompt is already visually sufficient, do not search, rewrite, translate, summarize, or add clarifiers; pass the user's prompt through as the image_generation prompt argument.",
|
|
207
|
-
),
|
|
208
|
-
validModeration: new Set(
|
|
209
|
-
Array.isArray(fileCfg.oauth?.validModeration) && fileCfg.oauth.validModeration.length
|
|
210
|
-
? fileCfg.oauth.validModeration
|
|
211
|
-
: ["auto", "low"],
|
|
212
|
-
),
|
|
213
|
-
},
|
|
214
|
-
github: {
|
|
215
|
-
token: pickStr(env.IMA2_GITHUB_TOKEN, fileCfg.github?.token, ""),
|
|
216
|
-
},
|
|
217
|
-
storage: {
|
|
218
|
-
configDir,
|
|
219
|
-
packageRoot,
|
|
220
|
-
generatedDir: pickStr(env.IMA2_GENERATED_DIR, fileCfg.storage?.generatedDir, join(configDir, "generated")),
|
|
221
|
-
trashDir: pickStr(env.IMA2_TRASH_DIR, fileCfg.storage?.trashDir, join(configDir, "generated", ".trash")),
|
|
222
|
-
generatedDirName: pickStr(env.IMA2_GENERATED_DIRNAME, fileCfg.storage?.generatedDirName, "generated"),
|
|
223
|
-
trashDirName: pickStr(env.IMA2_TRASH_DIRNAME, fileCfg.storage?.trashDirName, ".trash"),
|
|
224
|
-
dbPath: pickStr(env.IMA2_DB_PATH, fileCfg.storage?.dbPath, join(configDir, "sessions.db")),
|
|
225
|
-
promptImportIndexCacheFile: pickStr(
|
|
226
|
-
env.IMA2_PROMPT_IMPORT_INDEX_CACHE_FILE,
|
|
227
|
-
fileCfg.storage?.promptImportIndexCacheFile,
|
|
228
|
-
join(configDir, "prompt-import-index.json"),
|
|
229
|
-
),
|
|
230
|
-
promptImportDiscoveryRegistryFile: pickStr(
|
|
231
|
-
env.IMA2_PROMPT_IMPORT_DISCOVERY_REGISTRY_FILE,
|
|
232
|
-
fileCfg.storage?.promptImportDiscoveryRegistryFile,
|
|
233
|
-
join(configDir, "prompt-import-discovery.json"),
|
|
234
|
-
),
|
|
235
|
-
configFile: join(configDir, "config.json"),
|
|
236
|
-
advertiseFile: pickStr(env.IMA2_ADVERTISE_FILE, fileCfg.storage?.advertiseFile, join(configDir, "server.json")),
|
|
237
|
-
staticMaxAge: pickStr(env.IMA2_STATIC_MAX_AGE, fileCfg.storage?.staticMaxAge, "1y"),
|
|
238
|
-
},
|
|
239
|
-
ids: {
|
|
240
|
-
generatedHexBytes: pickInt(env.IMA2_GENERATED_HEX_BYTES, fileCfg.ids?.generatedHexBytes, 4),
|
|
241
|
-
nodeHexBytes: pickInt(env.IMA2_NODE_HEX_BYTES, fileCfg.ids?.nodeHexBytes, 5),
|
|
242
|
-
},
|
|
243
|
-
inflight: {
|
|
244
|
-
ttlMs: pickInt(env.IMA2_INFLIGHT_TTL_MS, fileCfg.inflight?.ttlMs, 10 * 60 * 1000),
|
|
245
|
-
reapMs: pickInt(env.IMA2_INFLIGHT_REAP_MS, fileCfg.inflight?.reapMs, 60 * 1000),
|
|
246
|
-
terminalTtlMs: pickInt(env.IMA2_INFLIGHT_TERMINAL_TTL_MS, fileCfg.inflight?.terminalTtlMs, 5 * 60 * 1000),
|
|
247
|
-
},
|
|
248
|
-
trash: {
|
|
249
|
-
ttlMs: pickInt(env.IMA2_TRASH_TTL_MS, fileCfg.trash?.ttlMs, 10_000),
|
|
250
|
-
},
|
|
251
|
-
styleSheet: {
|
|
252
|
-
maxPrefix: pickInt(env.IMA2_STYLE_SHEET_MAX_PREFIX, fileCfg.styleSheet?.maxPrefix, 4000),
|
|
253
|
-
model: pickStr(env.IMA2_STYLE_MODEL, fileCfg.styleSheet?.model, "gpt-5.4-mini"),
|
|
254
|
-
},
|
|
255
|
-
imageModels: {
|
|
256
|
-
default: pickStr(env.IMA2_IMAGE_MODEL_DEFAULT, fileCfg.imageModels?.default, "gpt-5.4-mini"),
|
|
257
|
-
valid: new Set(["gpt-5.5", "gpt-5.4", "gpt-5.4-mini"]),
|
|
258
|
-
unsupported: new Set(["gpt-5.3-codex-spark"]),
|
|
259
|
-
reasoningEffort: pickStr(
|
|
260
|
-
env.IMA2_REASONING_EFFORT,
|
|
261
|
-
fileCfg.imageModels?.reasoningEffort,
|
|
262
|
-
"medium",
|
|
263
|
-
),
|
|
264
|
-
validReasoningEfforts: new Set(["none", "low", "medium", "high", "xhigh"]),
|
|
265
|
-
},
|
|
266
|
-
apiProvider: {
|
|
267
|
-
defaultImageModel: pickStr(
|
|
268
|
-
env.IMA2_API_IMAGE_MODEL_DEFAULT,
|
|
269
|
-
fileCfg.apiProvider?.defaultImageModel,
|
|
270
|
-
"gpt-5.4-mini",
|
|
271
|
-
),
|
|
272
|
-
defaultReasoningEffort: pickStr(
|
|
273
|
-
env.IMA2_API_REASONING_EFFORT,
|
|
274
|
-
fileCfg.apiProvider?.defaultReasoningEffort,
|
|
275
|
-
"low",
|
|
276
|
-
),
|
|
277
|
-
defaultSize: pickStr(env.IMA2_API_IMAGE_SIZE, fileCfg.apiProvider?.defaultSize, "1024x1024"),
|
|
278
|
-
allowWebSearch: pickBool(env.IMA2_API_ALLOW_WEB_SEARCH, fileCfg.apiProvider?.allowWebSearch, true),
|
|
279
|
-
},
|
|
280
|
-
grokProvider: {
|
|
281
|
-
proxyPort: pickInt(env.IMA2_GROK_PROXY_PORT, fileCfg.grokProvider?.proxyPort, 18645),
|
|
282
|
-
proxyHost: pickStr(env.IMA2_GROK_PROXY_HOST, fileCfg.grokProvider?.proxyHost, "127.0.0.1"),
|
|
283
|
-
autoStart: !pickBool(env.IMA2_NO_GROK_PROXY, fileCfg.grokProvider?.disableAutoStart, false),
|
|
284
|
-
restartDelayMs: pickInt(env.IMA2_GROK_RESTART_DELAY_MS, fileCfg.grokProvider?.restartDelayMs, 2000),
|
|
285
|
-
plannerModel: pickStr(env.IMA2_GROK_PLANNER_MODEL, fileCfg.grokProvider?.plannerModel, "grok-4.3"),
|
|
286
|
-
plannerTimeoutMs: pickInt(env.IMA2_GROK_PLANNER_TIMEOUT_MS, fileCfg.grokProvider?.plannerTimeoutMs, 60_000),
|
|
287
|
-
defaultImageModel: pickStr(env.IMA2_GROK_IMAGE_MODEL_DEFAULT, fileCfg.grokProvider?.defaultImageModel, "grok-imagine-image"),
|
|
288
|
-
generationTimeoutMs: pickInt(env.IMA2_GROK_GENERATION_TIMEOUT_MS, fileCfg.grokProvider?.generationTimeoutMs, 120_000),
|
|
289
|
-
statusTimeoutMs: pickInt(env.IMA2_GROK_STATUS_TIMEOUT_MS, fileCfg.grokProvider?.statusTimeoutMs, 3000),
|
|
290
|
-
defaultVideoModel: pickStr(env.IMA2_GROK_VIDEO_MODEL_DEFAULT, fileCfg.grokProvider?.defaultVideoModel, "grok-imagine-video"),
|
|
291
|
-
videoStartTimeoutMs: pickInt(env.IMA2_GROK_VIDEO_START_TIMEOUT_MS, fileCfg.grokProvider?.videoStartTimeoutMs, 60_000),
|
|
292
|
-
videoPollIntervalMs: pickInt(env.IMA2_GROK_VIDEO_POLL_INTERVAL_MS, fileCfg.grokProvider?.videoPollIntervalMs, 5_000),
|
|
293
|
-
videoTimeoutMs: pickInt(env.IMA2_GROK_VIDEO_TIMEOUT_MS, fileCfg.grokProvider?.videoTimeoutMs, 900_000),
|
|
294
|
-
videoDownloadTimeoutMs: pickInt(env.IMA2_GROK_VIDEO_DOWNLOAD_TIMEOUT_MS, fileCfg.grokProvider?.videoDownloadTimeoutMs, 120_000),
|
|
295
|
-
},
|
|
296
|
-
log: {
|
|
297
|
-
level: pickStr(env.IMA2_LOG_LEVEL, fileCfg.log?.level, defaultLogLevelForEnv(env)),
|
|
298
|
-
pretty: env.NODE_ENV !== "production",
|
|
299
|
-
},
|
|
300
|
-
features: {
|
|
301
|
-
cardNews: pickBool(env.IMA2_CARD_NEWS, fileCfg.features?.cardNews, env.IMA2_DEV === "1"),
|
|
302
|
-
},
|
|
303
|
-
cardNewsPlanner: {
|
|
304
|
-
enabled: pickBool(env.IMA2_CARD_NEWS_PLANNER, fileCfg.cardNewsPlanner?.enabled, true),
|
|
305
|
-
model: pickStr(env.IMA2_CARD_NEWS_PLANNER_MODEL, fileCfg.cardNewsPlanner?.model, "gpt-5.4-mini"),
|
|
306
|
-
timeoutMs: pickInt(env.IMA2_CARD_NEWS_PLANNER_TIMEOUT_MS, fileCfg.cardNewsPlanner?.timeoutMs, 60_000),
|
|
307
|
-
deterministicFallback: pickBool(
|
|
308
|
-
env.IMA2_CARD_NEWS_PLANNER_FALLBACK,
|
|
309
|
-
fileCfg.cardNewsPlanner?.deterministicFallback,
|
|
310
|
-
false,
|
|
311
|
-
),
|
|
312
|
-
},
|
|
313
|
-
comfy: {
|
|
314
|
-
defaultUrl: pickStr(env.IMA2_COMFY_URL, fileCfg.comfy?.defaultUrl, "http://127.0.0.1:8188"),
|
|
315
|
-
uploadTimeoutMs: pickPositiveInt(
|
|
316
|
-
env.IMA2_COMFY_UPLOAD_TIMEOUT_MS,
|
|
317
|
-
fileCfg.comfy?.uploadTimeoutMs,
|
|
318
|
-
30_000,
|
|
319
|
-
),
|
|
320
|
-
maxUploadBytes: pickPositiveInt(
|
|
321
|
-
env.IMA2_COMFY_MAX_UPLOAD_BYTES,
|
|
322
|
-
fileCfg.comfy?.maxUploadBytes,
|
|
323
|
-
50 * 1024 * 1024,
|
|
324
|
-
),
|
|
325
|
-
},
|
|
326
|
-
dev: {
|
|
327
|
-
viteDevMode: pickBool(env.VITE_IMA2_DEV, fileCfg.dev?.viteDevMode, false),
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
export default config;
|
|
332
|
-
|
|
333
|
-
// ── Backward-compatible flat re-exports (used by lib/inflight.js & earlier
|
|
334
|
-
// call sites). Prefer `import { config } from "./config.js"` going forward.
|
|
335
|
-
export const PORT = config.server.port;
|
|
336
|
-
export const OAUTH_PORT = config.oauth.proxyPort;
|
|
337
|
-
export const OAUTH_URL = `http://127.0.0.1:${config.oauth.proxyPort}`;
|
|
338
|
-
export const CONFIG_DIR = config.storage.configDir;
|
|
339
|
-
export const CONFIG_FILE = config.storage.configFile;
|
|
340
|
-
export const ADVERTISE_FILE = config.storage.advertiseFile;
|
|
341
|
-
export const DB_FILE = config.storage.dbPath;
|
|
342
|
-
export const GENERATED_DIR = config.storage.generatedDir;
|
|
343
|
-
export const BODY_LIMIT = config.server.bodyLimit;
|
|
344
|
-
export const MAX_REF_B64_BYTES = config.limits.maxRefB64Bytes;
|
|
345
|
-
export const MAX_REFS = config.limits.maxRefCount;
|
|
346
|
-
export const MAX_N = config.limits.maxParallel;
|
|
347
|
-
export const INFLIGHT_TTL_MS = config.inflight.ttlMs;
|
|
348
|
-
export const INFLIGHT_REAP_MS = config.inflight.reapMs;
|
|
349
|
-
export const INFLIGHT_TERMINAL_TTL_MS = config.inflight.terminalTtlMs;
|
|
350
|
-
export const STYLE_SHEET_MAX_PREFIX = config.styleSheet.maxPrefix;
|
|
351
|
-
export const LOG_LEVEL = config.log.level;
|
|
352
|
-
export const NO_OAUTH_PROXY = !config.oauth.autoStart;
|
|
353
|
-
export const DEV_MODE = config.dev.viteDevMode;
|
|
354
|
-
export const CARD_NEWS_ENABLED = config.features.cardNews;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { AgentSlashCommand, AgentSlashCommandName } from "./agentTypes.js";
|
|
2
|
-
|
|
3
|
-
const COMMAND_ALIASES: Record<string, AgentSlashCommandName> = {
|
|
4
|
-
ask: "question",
|
|
5
|
-
q: "question",
|
|
6
|
-
question: "question",
|
|
7
|
-
help: "help",
|
|
8
|
-
h: "help",
|
|
9
|
-
variants: "variants",
|
|
10
|
-
variant: "variants",
|
|
11
|
-
v: "variants",
|
|
12
|
-
n: "variants",
|
|
13
|
-
generate: "generate",
|
|
14
|
-
gen: "generate",
|
|
15
|
-
g: "generate",
|
|
16
|
-
parallel: "parallelism",
|
|
17
|
-
parallelism: "parallelism",
|
|
18
|
-
p: "parallelism",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export function parseAgentSlashCommand(input: string): AgentSlashCommand | null {
|
|
22
|
-
const raw = input.trim();
|
|
23
|
-
if (!raw.startsWith("/")) return null;
|
|
24
|
-
|
|
25
|
-
const match = /^\/([a-z][\w-]*)(?:\s+([\s\S]*))?$/i.exec(raw);
|
|
26
|
-
if (!match) return null;
|
|
27
|
-
|
|
28
|
-
const rawName = match[1].toLowerCase();
|
|
29
|
-
const name = COMMAND_ALIASES[rawName];
|
|
30
|
-
if (!name) return null;
|
|
31
|
-
|
|
32
|
-
const rest = (match[2] ?? "").trim();
|
|
33
|
-
const countCommands: AgentSlashCommandName[] = ["variants", "generate", "parallelism"];
|
|
34
|
-
const parsed = countCommands.includes(name) ? parseLeadingCount(rest) : { prompt: rest };
|
|
35
|
-
return {
|
|
36
|
-
name,
|
|
37
|
-
rawName,
|
|
38
|
-
raw,
|
|
39
|
-
prompt: parsed.prompt,
|
|
40
|
-
...(parsed.value ? { value: parsed.value } : {}),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function formatAgentSlashHelp(): string {
|
|
45
|
-
return [
|
|
46
|
-
"Available Agent commands:",
|
|
47
|
-
"/question <topic> - ask a planning question without generating images.",
|
|
48
|
-
"/variants <1-8> <prompt> - force that many image variants.",
|
|
49
|
-
"/generate <1-8> <prompt> - generate a bounded fanout from one request.",
|
|
50
|
-
"/parallelism <1-8> <prompt> - cap concurrent tool calls for this turn.",
|
|
51
|
-
].join("\n");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function formatAgentQuestionReply(prompt: string): string {
|
|
55
|
-
const topic = prompt.trim();
|
|
56
|
-
if (!topic) {
|
|
57
|
-
return "What would you like to clarify before generating images?";
|
|
58
|
-
}
|
|
59
|
-
return topic;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function parseLeadingCount(value: string): { value?: number; prompt: string } {
|
|
63
|
-
const match = /^(\d+)(?:\s+([\s\S]*))?$/.exec(value);
|
|
64
|
-
if (!match) return { prompt: value };
|
|
65
|
-
return {
|
|
66
|
-
value: Math.max(1, Math.min(8, Number(match[1]))),
|
|
67
|
-
prompt: (match[2] ?? "").trim(),
|
|
68
|
-
};
|
|
69
|
-
}
|