ima2-gen 1.1.20 → 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 +42 -26
- package/bin/commands/capabilities.js +2 -2
- package/bin/commands/defaults.js +2 -2
- package/bin/commands/doctor.js +3 -3
- package/bin/commands/edit.js +1 -1
- package/bin/commands/gen.js +1 -1
- package/bin/commands/grok.js +16 -11
- package/bin/commands/multimode.js +1 -1
- package/bin/commands/observability.js +2 -2
- package/bin/commands/video.js +335 -13
- package/bin/ima2.js +23 -13
- package/bin/lib/error-hints.js +2 -2
- package/bin/lib/platform.js +34 -5
- package/docs/API.md +112 -3
- package/docs/CLI.md +61 -7
- package/docs/FAQ.ko.md +15 -20
- package/docs/FAQ.md +14 -19
- package/docs/NPX_QUICKSTART.md +40 -0
- package/docs/PROMPT_STUDIO.ko.md +1 -1
- package/docs/PROMPT_STUDIO.md +1 -1
- package/docs/README.ja.md +6 -16
- package/docs/README.ko.md +35 -14
- package/docs/README.zh-CN.md +7 -17
- package/docs/migration/runtime-test-inventory.md +8 -1
- package/lib/agentQueueWorker.js +6 -0
- package/lib/agentRuntime.js +20 -5
- package/lib/atomicWrite.js +14 -0
- package/lib/capabilities.js +1 -1
- package/lib/generationErrors.js +1 -1
- package/lib/grokProxyLauncher.js +31 -6
- package/lib/grokVideoAdapter.js +18 -89
- package/lib/grokVideoCanvas.js +25 -0
- package/lib/grokVideoDownload.js +58 -0
- package/lib/grokVideoPlannerPrompt.js +64 -0
- package/lib/historyList.js +7 -1
- package/lib/inflight.js +1 -1
- package/lib/oauthLauncher.js +26 -6
- package/lib/videoContinuity.js +149 -0
- package/lib/videoFrameExtract.js +80 -0
- package/node_modules/progrok/dist/index.js +187 -88
- package/node_modules/progrok/dist/index.js.map +1 -1
- package/node_modules/progrok/package.json +1 -1
- package/node_modules/progrok/skills/progrok/SKILL.md +33 -4
- package/package.json +6 -8
- package/routes/edit.js +2 -1
- package/routes/generate.js +4 -3
- package/routes/health.js +4 -3
- package/routes/index.js +4 -0
- package/routes/multimode.js +2 -1
- package/routes/quota.js +66 -0
- package/routes/video.js +80 -16
- package/routes/videoExtended.js +293 -0
- package/server.js +35 -4
- package/skills/ima2/SKILL.md +320 -7
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/{AgentWorkspace-DS8uvoLI.js → AgentWorkspace-COxQ5TjU.js} +2 -2
- package/ui/dist/assets/{CardNewsWorkspace-CYxMsE67.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-DccIc347.js → NodeCanvas-BSsclEBh.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-BvxxwSJp.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-u1_BFDRd.js → PromptImportDialog-CVwT0rLd.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-C5uvkVSz.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-D3E_O1SD.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-4gyf9CB9.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-DoKtXbod.js → index-Cxhzi3bs.js} +1 -1
- package/ui/dist/index.html +2 -2
- package/vendor/progrok-0.2.0.tgz +0 -0
- 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 -85
- 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 -205
- 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 -592
- 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 -129
- package/lib/grokRuntime.ts +0 -23
- package/lib/grokSizeMapper.ts +0 -71
- package/lib/grokVideoAdapter.ts +0 -519
- package/lib/historyIndex.ts +0 -51
- package/lib/historyList.ts +0 -177
- 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 -78
- 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/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 -48
- 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/sessions.ts +0 -317
- package/routes/storage.ts +0 -47
- package/routes/video.ts +0 -232
- package/server.ts +0 -290
- package/ui/dist/assets/SettingsWorkspace-F3eNu3mJ.js +0 -1
- package/ui/dist/assets/index-B6tcw_UF.css +0 -1
- package/ui/dist/assets/index-DYOh6gQD.js +0 -32
- package/vendor/progrok-0.1.1.tgz +0 -0
package/server.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import type { Response } from "express";
|
|
4
|
-
import { readFile } from "fs/promises";
|
|
5
|
-
import {
|
|
6
|
-
existsSync,
|
|
7
|
-
writeFileSync,
|
|
8
|
-
unlinkSync,
|
|
9
|
-
mkdirSync,
|
|
10
|
-
readFileSync as fsReadFileSync,
|
|
11
|
-
} from "fs";
|
|
12
|
-
import { dirname, join } from "path";
|
|
13
|
-
import { fileURLToPath, pathToFileURL } from "url";
|
|
14
|
-
import { onShutdown } from "./bin/lib/platform.js";
|
|
15
|
-
import { ensureDefaultSession } from "./lib/sessionStore.js";
|
|
16
|
-
import { startGrokProxy } from "./lib/grokProxyLauncher.js";
|
|
17
|
-
import { startOAuthProxy } from "./lib/oauthLauncher.js";
|
|
18
|
-
import { migrateGeneratedStorage } from "./lib/storageMigration.js";
|
|
19
|
-
import { purgeStaleJobs } from "./lib/inflight.js";
|
|
20
|
-
import { configureLogger } from "./lib/logger.js";
|
|
21
|
-
import { createRequestLogger } from "./lib/requestLogger.js";
|
|
22
|
-
import { configureApiCachePolicy } from "./lib/apiCachePolicy.js";
|
|
23
|
-
import { configureRoutes } from "./routes/index.js";
|
|
24
|
-
import { config } from "./config.js";
|
|
25
|
-
import { getServerPort, listenWithPortFallback } from "./lib/runtimePorts.js";
|
|
26
|
-
import type { RuntimeContext, RuntimeContextOverrides, ApiKeySource } from "./lib/runtimeContext.js";
|
|
27
|
-
|
|
28
|
-
import { errInfo } from "./lib/errInfo.js";
|
|
29
|
-
|
|
30
|
-
type BootRuntimeContext = RuntimeContext & {
|
|
31
|
-
markGrokProxyPort: (info?: { url?: string; port?: number }) => void;
|
|
32
|
-
markOAuthReady: (info?: { url?: string; port?: number }) => void;
|
|
33
|
-
markOAuthFailed: () => void;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
type ApiKeyLoadResult = { apiKey: string | null; apiKeySource: ApiKeySource };
|
|
37
|
-
|
|
38
|
-
const rootDir = dirname(fileURLToPath(import.meta.url));
|
|
39
|
-
|
|
40
|
-
async function loadApiKey(): Promise<ApiKeyLoadResult> {
|
|
41
|
-
if (process.env.OPENAI_API_KEY) {
|
|
42
|
-
return { apiKey: process.env.OPENAI_API_KEY, apiKeySource: "env" };
|
|
43
|
-
}
|
|
44
|
-
const candidates = [
|
|
45
|
-
config.storage.configFile,
|
|
46
|
-
join(rootDir, ".ima2", "config.json"),
|
|
47
|
-
];
|
|
48
|
-
for (const cfgPath of candidates) {
|
|
49
|
-
if (!existsSync(cfgPath)) continue;
|
|
50
|
-
try {
|
|
51
|
-
const cfg = JSON.parse(await readFile(cfgPath, "utf-8")) as { apiKey?: string };
|
|
52
|
-
if (cfg.apiKey) return { apiKey: cfg.apiKey, apiKeySource: "config" };
|
|
53
|
-
} catch {}
|
|
54
|
-
}
|
|
55
|
-
return { apiKey: null, apiKeySource: "none" };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function createOpenAI(apiKey: string | null | undefined) {
|
|
59
|
-
if (!apiKey) return null;
|
|
60
|
-
const OpenAI = (await import("openai")).default;
|
|
61
|
-
return new OpenAI({ apiKey });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function readPackageVersion(): string {
|
|
65
|
-
try {
|
|
66
|
-
return (JSON.parse(fsReadFileSync(join(rootDir, "package.json"), "utf-8")) as { version?: string }).version ?? "0.0.0";
|
|
67
|
-
} catch {
|
|
68
|
-
return "0.0.0";
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function setUiStaticHeaders(res: Response, filePath: string) {
|
|
73
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
74
|
-
if (normalized.endsWith("/index.html")) {
|
|
75
|
-
res.setHeader("Cache-Control", "no-store, max-age=0");
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (normalized.includes("/assets/")) {
|
|
79
|
-
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function buildApp(ctx: RuntimeContext) {
|
|
84
|
-
const app = express();
|
|
85
|
-
configureApiCachePolicy(app);
|
|
86
|
-
configureLogger({ level: ctx.config.log.level });
|
|
87
|
-
app.use(createRequestLogger());
|
|
88
|
-
app.use(express.json({ limit: ctx.config.server.bodyLimit }));
|
|
89
|
-
app.use(express.static(join(ctx.rootDir, "ui", "dist"), {
|
|
90
|
-
setHeaders: setUiStaticHeaders,
|
|
91
|
-
}));
|
|
92
|
-
app.use("/assets", (_req, res) => {
|
|
93
|
-
res.status(404).type("text/plain").send("Asset not found");
|
|
94
|
-
});
|
|
95
|
-
app.use("/generated", express.static(ctx.config.storage.generatedDir, {
|
|
96
|
-
maxAge: ctx.config.storage.staticMaxAge,
|
|
97
|
-
immutable: true,
|
|
98
|
-
}));
|
|
99
|
-
configureRoutes(app, ctx);
|
|
100
|
-
return app;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function runtimeHostUrl(host: string | undefined): string {
|
|
104
|
-
if (!host || host === "0.0.0.0" || host === "::") return "localhost";
|
|
105
|
-
return host;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function advertise(ctx: RuntimeContext) {
|
|
109
|
-
try {
|
|
110
|
-
mkdirSync(dirname(ctx.config.storage.advertiseFile), { recursive: true });
|
|
111
|
-
writeFileSync(
|
|
112
|
-
ctx.config.storage.advertiseFile,
|
|
113
|
-
JSON.stringify({
|
|
114
|
-
port: Number(ctx.serverActualPort || ctx.config.server.port),
|
|
115
|
-
url: ctx.serverUrl,
|
|
116
|
-
pid: process.pid,
|
|
117
|
-
startedAt: ctx.startedAt,
|
|
118
|
-
version: ctx.packageVersion,
|
|
119
|
-
backend: {
|
|
120
|
-
configuredPort: Number(ctx.serverConfiguredPort || ctx.config.server.port),
|
|
121
|
-
actualPort: Number(ctx.serverActualPort || ctx.config.server.port),
|
|
122
|
-
url: ctx.serverUrl,
|
|
123
|
-
},
|
|
124
|
-
oauth: {
|
|
125
|
-
configuredPort: Number(ctx.oauthPort),
|
|
126
|
-
actualPort: Number(ctx.oauthActualPort || ctx.oauthPort),
|
|
127
|
-
url: ctx.oauthUrl,
|
|
128
|
-
status: ctx.oauthReadyState,
|
|
129
|
-
},
|
|
130
|
-
grok: {
|
|
131
|
-
configuredPort: Number(ctx.grokPort),
|
|
132
|
-
actualPort: Number(ctx.grokActualPort || ctx.grokPort),
|
|
133
|
-
url: ctx.grokUrl,
|
|
134
|
-
},
|
|
135
|
-
}),
|
|
136
|
-
);
|
|
137
|
-
} catch (e) {
|
|
138
|
-
const err = errInfo(e);
|
|
139
|
-
console.warn("[advertise] skipped:", err.message);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function unadvertise(ctx: RuntimeContext) {
|
|
144
|
-
try {
|
|
145
|
-
if (!existsSync(ctx.config.storage.advertiseFile)) return;
|
|
146
|
-
const cur = JSON.parse(fsReadFileSync(ctx.config.storage.advertiseFile, "utf-8")) as { pid?: number };
|
|
147
|
-
if (cur.pid === process.pid) unlinkSync(ctx.config.storage.advertiseFile);
|
|
148
|
-
} catch {}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
type StartServerOverrides = RuntimeContextOverrides & {
|
|
152
|
-
startedAt?: number;
|
|
153
|
-
packageVersion?: string;
|
|
154
|
-
oauthChild?: { stop?: () => void; kill?: () => void } | null;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export async function createRuntimeContext(overrides: StartServerOverrides = {}): Promise<BootRuntimeContext> {
|
|
158
|
-
const loadedKey =
|
|
159
|
-
overrides.apiKey !== undefined
|
|
160
|
-
? {
|
|
161
|
-
apiKey: overrides.apiKey,
|
|
162
|
-
apiKeySource: overrides.apiKeySource ?? (overrides.apiKey ? "env" : "none"),
|
|
163
|
-
}
|
|
164
|
-
: await loadApiKey();
|
|
165
|
-
const apiKey = loadedKey.apiKey;
|
|
166
|
-
const openai = overrides.openai ?? await createOpenAI(apiKey);
|
|
167
|
-
const oauthPort = config.oauth.proxyPort;
|
|
168
|
-
const grokPort = config.grokProvider.proxyPort;
|
|
169
|
-
let resolveOAuthReady: (value: string | null) => void = () => {};
|
|
170
|
-
const oauthReadyPromise = new Promise<string | null>((resolve) => {
|
|
171
|
-
resolveOAuthReady = resolve;
|
|
172
|
-
});
|
|
173
|
-
const ctx: BootRuntimeContext = {
|
|
174
|
-
rootDir,
|
|
175
|
-
config,
|
|
176
|
-
serverConfiguredPort: config.server.port,
|
|
177
|
-
serverActualPort: undefined,
|
|
178
|
-
serverUrl: `http://${runtimeHostUrl(config.server.host)}:${config.server.port}`,
|
|
179
|
-
grokPort,
|
|
180
|
-
grokActualPort: grokPort,
|
|
181
|
-
grokUrl: `http://${config.grokProvider.proxyHost}:${grokPort}/v1`,
|
|
182
|
-
oauthPort,
|
|
183
|
-
oauthActualPort: oauthPort,
|
|
184
|
-
oauthUrl: `http://127.0.0.1:${oauthPort}`,
|
|
185
|
-
oauthReadyState: config.oauth.autoStart ? "starting" : "disabled",
|
|
186
|
-
hasApiKey: !!apiKey,
|
|
187
|
-
apiKey: apiKey ?? undefined,
|
|
188
|
-
apiKeySource: loadedKey.apiKeySource as ApiKeySource,
|
|
189
|
-
openai,
|
|
190
|
-
startedAt: overrides.startedAt ?? Date.now(),
|
|
191
|
-
packageVersion: overrides.packageVersion ?? readPackageVersion(),
|
|
192
|
-
oauthReadyPromise: oauthReadyPromise as unknown as Promise<void>,
|
|
193
|
-
markGrokProxyPort: ({ url, port }: { url?: string; port?: number } = {}) => {
|
|
194
|
-
if (port) ctx.grokActualPort = port;
|
|
195
|
-
if (url) ctx.grokUrl = url;
|
|
196
|
-
else if (port) ctx.grokUrl = `http://${ctx.config.grokProvider.proxyHost}:${port}/v1`;
|
|
197
|
-
},
|
|
198
|
-
markOAuthReady: ({ url, port }: { url?: string; port?: number } = {}) => {
|
|
199
|
-
if (url) ctx.oauthUrl = url;
|
|
200
|
-
if (port) ctx.oauthActualPort = port;
|
|
201
|
-
ctx.oauthReadyState = "ready";
|
|
202
|
-
resolveOAuthReady(ctx.oauthUrl);
|
|
203
|
-
},
|
|
204
|
-
markOAuthFailed: () => {
|
|
205
|
-
ctx.oauthReadyState = "failed";
|
|
206
|
-
resolveOAuthReady(null);
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
if (!config.oauth.autoStart) ctx.markOAuthReady({ url: ctx.oauthUrl, port: ctx.oauthPort });
|
|
210
|
-
return ctx;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export async function startServer(overrides: StartServerOverrides = {}) {
|
|
214
|
-
const ctx = await createRuntimeContext(overrides);
|
|
215
|
-
await migrateGeneratedStorage(ctx);
|
|
216
|
-
purgeStaleJobs();
|
|
217
|
-
const app = buildApp(ctx);
|
|
218
|
-
const oauthChild =
|
|
219
|
-
overrides.oauthChild !== undefined
|
|
220
|
-
? overrides.oauthChild
|
|
221
|
-
: !ctx.config.oauth.autoStart
|
|
222
|
-
? null
|
|
223
|
-
: startOAuthProxy({
|
|
224
|
-
oauthPort: ctx.oauthPort,
|
|
225
|
-
restartDelayMs: ctx.config.oauth.restartDelayMs,
|
|
226
|
-
onReady: ({ url, port }: { url: string; port: number }) => {
|
|
227
|
-
ctx.markOAuthReady({ url, port });
|
|
228
|
-
advertise(ctx);
|
|
229
|
-
},
|
|
230
|
-
onExit: () => ctx.markOAuthFailed(),
|
|
231
|
-
});
|
|
232
|
-
if (overrides.oauthChild !== undefined || !ctx.config.oauth.autoStart) {
|
|
233
|
-
ctx.markOAuthReady({ url: ctx.oauthUrl, port: ctx.oauthPort });
|
|
234
|
-
}
|
|
235
|
-
const grokChild = ctx.config.grokProvider.autoStart
|
|
236
|
-
? await startGrokProxy({
|
|
237
|
-
host: ctx.config.grokProvider.proxyHost,
|
|
238
|
-
port: ctx.config.grokProvider.proxyPort,
|
|
239
|
-
restartDelayMs: ctx.config.grokProvider.restartDelayMs,
|
|
240
|
-
onPortSelected: ({ url, port }: { url: string; port: number }) => {
|
|
241
|
-
ctx.markGrokProxyPort({ url, port });
|
|
242
|
-
advertise(ctx);
|
|
243
|
-
},
|
|
244
|
-
onReady: ({ url, port }: { url: string; port: number }) => {
|
|
245
|
-
ctx.markGrokProxyPort({ url, port });
|
|
246
|
-
advertise(ctx);
|
|
247
|
-
},
|
|
248
|
-
})
|
|
249
|
-
: null;
|
|
250
|
-
|
|
251
|
-
onShutdown(() => {
|
|
252
|
-
unadvertise(ctx);
|
|
253
|
-
try { oauthChild?.stop?.(); } catch {}
|
|
254
|
-
try { oauthChild?.kill?.(); } catch {}
|
|
255
|
-
try { grokChild?.stop?.(); } catch {}
|
|
256
|
-
try { grokChild?.kill?.(); } catch {}
|
|
257
|
-
});
|
|
258
|
-
process.on("exit", () => unadvertise(ctx));
|
|
259
|
-
|
|
260
|
-
const server = await listenWithPortFallback(app, ctx.config.server.port, {
|
|
261
|
-
host: ctx.config.server.host,
|
|
262
|
-
label: "server",
|
|
263
|
-
onFallback: ({ requestedPort, actualPort }: { requestedPort: number; actualPort: number }) => {
|
|
264
|
-
console.log(`[server.port] requested=${requestedPort} actual=${actualPort} reason=EADDRINUSE`);
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
ctx.serverActualPort = getServerPort(server) || ctx.config.server.port;
|
|
268
|
-
ctx.serverUrl = `http://${runtimeHostUrl(ctx.config.server.host)}:${ctx.serverActualPort}`;
|
|
269
|
-
console.log(`Image Gen running at ${ctx.serverUrl}`);
|
|
270
|
-
console.log(`Provider policy: OAuth, API-key Responses, and Grok Images providers. OAuth proxy port ${ctx.oauthPort}; Grok proxy port ${ctx.grokActualPort || ctx.grokPort}.`);
|
|
271
|
-
advertise(ctx);
|
|
272
|
-
try {
|
|
273
|
-
const s = ensureDefaultSession();
|
|
274
|
-
console.log(`[db] default session: ${s.id} (${s.title})`);
|
|
275
|
-
} catch (e) {
|
|
276
|
-
const err = errInfo(e);
|
|
277
|
-
console.error("[db] bootstrap failed:", err.message);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
server.on("error", (err: NodeJS.ErrnoException) => {
|
|
281
|
-
console.error("[server] Failed to start:", err?.message || err);
|
|
282
|
-
process.exit(1);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
return { app, server, oauthChild, ctx };
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
289
|
-
await startServer();
|
|
290
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as h,h as E,k as R,l as L,j as e,b as r,m as $,o as O,a as o,T as C,I,W as K}from"./index-DYOh6gQD.js";function k(s,a){return s(a==="ready"?"settings.account.status.ready":a==="auth_required"?"settings.account.status.authRequired":a==="starting"?"settings.account.status.starting":a==="offline"?"settings.account.status.offline":a==="no_image_model"?"settings.account.status.noImageModel":a==="error"?"settings.account.status.error":"settings.account.status.checking")}function A(){const{t:s}=h(),a=E(),l=R(),{data:t,error:c}=L(),d=t?.apiKeySource==="env"||t?.apiKeySource==="config"||t?.apiKeyValid===!0,g=a?.status==="ready",m=t?.apiKeySource==="config"?s("settings.account.apiSourceConfig"):s("settings.account.apiSourceEnv"),u=t?.apiKeyValid===!0,i=l?.status==="ready";return e.jsxs(e.Fragment,{children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.account.primaryEyebrow")}),e.jsx("h4",{children:s("settings.account.oauthTitle")}),e.jsx("p",{children:s("settings.account.oauthBody")})]}),e.jsxs("div",{className:`settings-status${g?" is-ok":""}`,children:[e.jsx("span",{"aria-hidden":"true"}),k(s,a?.status)]})]}),d?e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:m}),e.jsx("h4",{children:s("settings.account.apiTitle")}),e.jsx("p",{children:s("settings.account.apiBody")})]}),e.jsxs("div",{className:`settings-status${u?" is-ok":" is-muted"}`,children:[e.jsx("span",{"aria-hidden":"true"}),s(c?"settings.account.apiUnknown":u?"settings.account.apiReady":"settings.account.apiUnavailable")]})]}):null,e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.account.grokEyebrow")}),e.jsx("h4",{children:s("settings.account.grokTitle")}),e.jsx("p",{children:s("settings.account.grokBody")})]}),e.jsxs("div",{className:`settings-status${i?" is-ok":" is-muted"}`,children:[e.jsx("span",{"aria-hidden":"true"}),k(s,l?.status)]})]})]})}function P(){const{t:s}=h(),a=r(c=>c.reasoningEffort),l=r(c=>c.setReasoningEffort),t=c=>{l(c.target.value)};return e.jsx("div",{className:"image-model-select image-model-select--settings",children:e.jsx("select",{id:"settings-reasoning-effort",value:a,onChange:t,children:$.map(c=>e.jsx("option",{value:c.value,children:s(c.fullLabelKey)},c.value))})})}const B={ko:"KO",en:"EN"};function F(){const{t:s,locale:a}=h(),l=r(t=>t.setLocale);return e.jsx("div",{className:"lang-toggle",role:"group","aria-label":s("language.label"),children:O.map(t=>e.jsx("button",{type:"button",className:`lang-toggle__btn ${a===t?"is-active":""}`,onClick:()=>l(t),"aria-pressed":a===t,title:s(`language.${t}`),children:e.jsx("span",{className:"lang-toggle__label",children:B[t]})},t))})}const D=["system","dark","light"];function M(){const{t:s}=h(),a=r(i=>i.theme),l=r(i=>i.setTheme),t=r(i=>i.themeFamily),c=r(i=>i.setThemeFamily),[d,g]=o.useState(!1),m=o.useRef(null);o.useEffect(()=>{if(!d)return;const i=p=>{m.current&&(m.current.contains(p.target)||g(!1))},x=p=>{p.key==="Escape"&&g(!1)};return document.addEventListener("mousedown",i),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",x)}},[d]);const u=i=>s(`theme.family.${i}`);return e.jsxs("div",{className:"theme-toggle","aria-label":s("theme.label"),children:[e.jsxs("div",{className:"theme-toggle__row",children:[e.jsx("span",{className:"theme-toggle__label",id:"theme-style-label",children:s("theme.styleLabel")}),e.jsxs("div",{className:"theme-toggle__family",ref:m,children:[e.jsxs("button",{type:"button",className:"theme-toggle__family-trigger","aria-haspopup":"listbox","aria-expanded":d,"aria-labelledby":"theme-style-label",onClick:()=>g(i=>!i),children:[e.jsx("span",{className:`theme-toggle__family-dot theme-toggle__family-dot--${t}`,"aria-hidden":"true"}),e.jsx("span",{className:"theme-toggle__family-name",children:u(t)}),e.jsx("span",{className:"theme-toggle__family-caret","aria-hidden":"true",children:"▾"})]}),d?e.jsx("ul",{className:"theme-toggle__family-menu",role:"listbox","aria-labelledby":"theme-style-label",children:C.map(i=>e.jsx("li",{role:"none",children:e.jsxs("button",{type:"button",role:"option","aria-selected":t===i,className:`theme-toggle__family-option ${t===i?"is-active":""}`,onClick:()=>{c(i),g(!1)},children:[e.jsx("span",{className:`theme-toggle__family-dot theme-toggle__family-dot--${i}`,"aria-hidden":"true"}),e.jsx("span",{className:"theme-toggle__family-name",children:u(i)})]})},i))}):null]})]}),e.jsxs("div",{className:"theme-toggle__row",children:[e.jsx("span",{className:"theme-toggle__label",id:"theme-mode-label",children:s("theme.modeLabel")}),e.jsx("div",{className:"theme-toggle__mode",role:"group","aria-labelledby":"theme-mode-label",children:D.map(i=>e.jsx("button",{type:"button",className:`theme-toggle__btn ${a===i?"is-active":""}`,onClick:()=>l(i),"aria-pressed":a===i,title:s(`theme.${i}`),children:s(`theme.${i}`)},i))})]})]})}const G=["rail","horizontal","sidebar"];function W(){const{t:s}=h(),a=r(t=>t.historyStripLayout),l=r(t=>t.setHistoryStripLayout);return e.jsx("div",{className:"history-layout-toggle",role:"group","aria-label":s("settings.appearance.historyStripLayoutTitle"),children:G.map(t=>e.jsx("button",{type:"button",className:`history-layout-toggle__btn ${a===t?"is-active":""}`,onClick:()=>l(t),"aria-pressed":a===t,title:s(`settings.appearance.historyStripLayout.${t}`),children:s(`settings.appearance.historyStripLayout.${t}`)},t))})}const H=[{value:"default",labelKey:"workspace.defaultLabel",descKey:"workspace.defaultDesc"},{value:"prompt-studio",labelKey:"workspace.promptStudioLabel",descKey:"workspace.promptStudioDesc"}];function U(){const s=r(t=>t.workspaceProfile),a=r(t=>t.setWorkspaceProfile),{t:l}=h();return e.jsx("div",{className:"settings-field",children:e.jsx("select",{id:"workspace-profile-select",className:"settings-field__select",value:s,onChange:t=>a(t.target.value),"aria-label":l("workspace.profileLabel"),children:H.map(t=>e.jsx("option",{value:t.value,children:l(t.labelKey)},t.value))})})}const _=["account","generation","appearance","workspace","language","future"];function f({id:s,setRef:a,children:l}){const{t}=h();return e.jsxs("section",{id:s,ref:c=>a(s,c),className:"settings-section","aria-labelledby":`settings-section-${s}`,children:[e.jsx("header",{className:"settings-section__header",children:e.jsxs("div",{children:[e.jsx("h3",{id:`settings-section-${s}`,children:t(`settings.sections.${s}.title`)}),e.jsx("p",{children:t(`settings.sections.${s}.hint`)})]})}),e.jsx("div",{className:"settings-section__body",children:l})]})}function q(){const{t:s}=h(),a=r(n=>n.activeSettingsSection),l=r(n=>n.setActiveSettingsSection),t=r(n=>n.closeSettings),c=r(n=>n.openReadinessPopup),d=r(n=>n.galleryDefaultScope),g=r(n=>n.setGalleryDefaultScope),m=r(n=>n.provider),u=o.useRef(null),i=o.useRef(null),x=o.useRef(!1),p=o.useRef({account:null,generation:null,appearance:null,workspace:null,language:null,future:null}),j=(n,y)=>{p.current[n]=y},S=n=>{l(n),x.current=!0,p.current[n]?.scrollIntoView({behavior:"auto",block:"start"}),i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>{x.current=!1,i.current=null},120)};return o.useEffect(()=>{const n=y=>{y.key==="Escape"&&t()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[t]),o.useEffect(()=>{const n=u.current;if(!n||typeof IntersectionObserver!="function")return;const y=new IntersectionObserver(b=>{if(x.current)return;const N=b.filter(w=>w.isIntersecting).sort((w,T)=>T.intersectionRatio-w.intersectionRatio)[0]?.target.id;N&&_.includes(N)&&l(N)},{root:n,threshold:[.35,.6]});for(const b of _){const v=p.current[b];v&&y.observe(v)}return()=>y.disconnect()},[l]),o.useEffect(()=>()=>{i.current!==null&&window.clearTimeout(i.current)},[]),e.jsx("main",{ref:u,className:"settings-workspace","aria-labelledby":"settings-title",children:e.jsxs("div",{className:"settings-shell",children:[e.jsxs("header",{className:"settings-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.eyebrow")}),e.jsx("h2",{id:"settings-title",children:s("settings.title")}),e.jsx("p",{children:s("settings.subtitle")})]}),e.jsx("button",{type:"button",className:"settings-close",onClick:t,"aria-label":s("settings.closeAria"),title:s("settings.closeTitle"),children:"X"})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-nav settings-nav--mobile","aria-label":s("settings.navAria"),children:e.jsx("div",{className:"settings-mobile-nav",role:"list",children:_.map(n=>e.jsxs("button",{type:"button",className:`settings-mobile-nav__item${a===n?" is-active":""}`,onClick:()=>S(n),"aria-current":a===n?"true":void 0,children:[e.jsx("span",{children:s(`settings.sections.${n}.title`)}),e.jsx("small",{children:s(`settings.sections.${n}.hint`)})]},n))})}),e.jsx("nav",{className:"settings-nav","aria-label":s("settings.navAria"),children:_.map(n=>e.jsxs("button",{type:"button",className:`settings-nav__item${a===n?" is-active":""}`,onClick:()=>S(n),"aria-label":s("settings.jumpTo",{section:s(`settings.sections.${n}.title`)}),children:[e.jsx("span",{children:s(`settings.sections.${n}.title`)}),e.jsx("small",{children:s(`settings.sections.${n}.hint`)})]},n))}),e.jsxs("section",{className:"settings-content","aria-label":s("settings.contentAria"),children:[e.jsxs(f,{id:"account",setRef:j,children:[e.jsx(A,{}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("readiness.settingsTitle")}),e.jsx("p",{children:s("readiness.settingsBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx("button",{type:"button",className:"settings-action-btn",onClick:c,children:s("readiness.open")})})]})]}),e.jsxs(f,{id:"generation",setRef:j,children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.imageModel.title")}),e.jsx("p",{children:s("settings.imageModel.body")}),e.jsx("p",{className:"settings-row__microcopy",children:s("settings.imageModel.unsupportedHelp")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(I,{variant:"settings"})})]}),m==="grok"?e.jsx("article",{className:"settings-row",children:e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.grokCompatibility.title")}),e.jsx("p",{children:s("settings.grokCompatibility.body")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.reasoning.title")}),e.jsx("p",{children:s("settings.reasoning.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(P,{})})]}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.webSearch.title")}),e.jsx("p",{children:s("settings.webSearch.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(K,{})})]})]}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.gallery.defaultScopeTitle")}),e.jsx("p",{children:s("settings.gallery.defaultScopeBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsxs("select",{value:d,onChange:n=>g(n.target.value),"aria-label":s("settings.gallery.defaultScopeTitle"),children:[e.jsx("option",{value:"current-session",children:s("gallery.scope.current")}),e.jsx("option",{value:"all",children:s("gallery.scope.all")})]})})]})]}),e.jsxs(f,{id:"appearance",setRef:j,children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.appearance.themeTitle")}),e.jsx("p",{children:s("settings.appearance.themeBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(M,{})})]}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.appearance.historyStripLayoutTitle")}),e.jsx("p",{children:s("settings.appearance.historyStripLayoutBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(W,{})})]})]}),e.jsx(f,{id:"workspace",setRef:j,children:e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("workspace.sectionTitle")}),e.jsx("p",{children:s("workspace.sectionBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(U,{})})]})}),e.jsx(f,{id:"language",setRef:j,children:e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.language.title")}),e.jsx("p",{children:s("settings.language.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(F,{})})]})}),e.jsx(f,{id:"future",setRef:j,children:e.jsxs("article",{className:"settings-note",children:[e.jsx("h4",{children:s("settings.future.title")}),e.jsx("p",{children:s("settings.future.body")})]})})]})]})]})})}export{q as SettingsWorkspace};
|