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/lib/agentQueueStore.ts
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { ulid } from "ulid";
|
|
2
|
-
import { getDb } from "./db.js";
|
|
3
|
-
import {
|
|
4
|
-
type AgentGenerationSettings,
|
|
5
|
-
type AgentQueueItem,
|
|
6
|
-
type AgentQueueStatus,
|
|
7
|
-
type AgentSlashCommand,
|
|
8
|
-
type AgentSessionRunSummary,
|
|
9
|
-
} from "./agentTypes.js";
|
|
10
|
-
import { DEFAULT_AGENT_GENERATION_SETTINGS, normalizeAgentGenerationSettings } from "./agentSettings.js";
|
|
11
|
-
import { normalizeAgentGenerationPlan } from "./agentGenerationPlanner.js";
|
|
12
|
-
|
|
13
|
-
type AgentQueueRow = {
|
|
14
|
-
id: string;
|
|
15
|
-
sessionId: string;
|
|
16
|
-
requestId: string;
|
|
17
|
-
prompt: string;
|
|
18
|
-
options: string;
|
|
19
|
-
toolPlan: string;
|
|
20
|
-
status: AgentQueueStatus;
|
|
21
|
-
position: number;
|
|
22
|
-
resultImageIds: string;
|
|
23
|
-
errorCode: string | null;
|
|
24
|
-
errorMessage: string | null;
|
|
25
|
-
createdAt: number;
|
|
26
|
-
startedAt: number | null;
|
|
27
|
-
finishedAt: number | null;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type AgentQueueProjection = {
|
|
31
|
-
queueBySession: Record<string, AgentQueueItem[]>;
|
|
32
|
-
runSummaryBySession: Record<string, AgentSessionRunSummary>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type AgentQueueLimits = {
|
|
36
|
-
maxGlobalRunning: number;
|
|
37
|
-
maxSessionRunning: number;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export function createAgentQueueItem(input: {
|
|
41
|
-
sessionId: string;
|
|
42
|
-
prompt: string;
|
|
43
|
-
options?: unknown;
|
|
44
|
-
plan?: unknown;
|
|
45
|
-
command?: AgentSlashCommand | null;
|
|
46
|
-
}) {
|
|
47
|
-
const t = Date.now();
|
|
48
|
-
const id = `aq_${ulid()}`;
|
|
49
|
-
const requestId = `agent_queue_${ulid()}`;
|
|
50
|
-
const options = normalizeAgentGenerationSettings(input.options);
|
|
51
|
-
const plan = input.plan
|
|
52
|
-
? normalizeAgentGenerationPlan(input.prompt, input.plan, options)
|
|
53
|
-
: normalizeAgentGenerationPlan(input.prompt, { command: input.command }, options);
|
|
54
|
-
const position = getQueuedCount(input.sessionId) + 1;
|
|
55
|
-
getDb().prepare(`
|
|
56
|
-
INSERT INTO agent_queue_items
|
|
57
|
-
(id, session_id, request_id, prompt, options, tool_plan, status, position, result_image_ids, created_at)
|
|
58
|
-
VALUES (?, ?, ?, ?, ?, ?, 'queued', ?, '[]', ?)
|
|
59
|
-
`).run(id, input.sessionId, requestId, input.prompt, JSON.stringify(options), JSON.stringify(plan), position, t);
|
|
60
|
-
return getAgentQueueItem(id)!;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function getAgentQueueItem(id: string) {
|
|
64
|
-
const row = getDb().prepare(`
|
|
65
|
-
SELECT
|
|
66
|
-
id,
|
|
67
|
-
session_id AS sessionId,
|
|
68
|
-
request_id AS requestId,
|
|
69
|
-
prompt,
|
|
70
|
-
options,
|
|
71
|
-
tool_plan AS toolPlan,
|
|
72
|
-
status,
|
|
73
|
-
position,
|
|
74
|
-
result_image_ids AS resultImageIds,
|
|
75
|
-
error_code AS errorCode,
|
|
76
|
-
error_message AS errorMessage,
|
|
77
|
-
created_at AS createdAt,
|
|
78
|
-
started_at AS startedAt,
|
|
79
|
-
finished_at AS finishedAt
|
|
80
|
-
FROM agent_queue_items
|
|
81
|
-
WHERE id = ?
|
|
82
|
-
`).get(id) as AgentQueueRow | undefined;
|
|
83
|
-
return row ? queueItemFromRow(row) : null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function listAgentQueueItems(sessionId?: string | null) {
|
|
87
|
-
const where = sessionId ? "WHERE session_id = ?" : "";
|
|
88
|
-
const rows = getDb().prepare(`
|
|
89
|
-
SELECT
|
|
90
|
-
id,
|
|
91
|
-
session_id AS sessionId,
|
|
92
|
-
request_id AS requestId,
|
|
93
|
-
prompt,
|
|
94
|
-
options,
|
|
95
|
-
tool_plan AS toolPlan,
|
|
96
|
-
status,
|
|
97
|
-
position,
|
|
98
|
-
result_image_ids AS resultImageIds,
|
|
99
|
-
error_code AS errorCode,
|
|
100
|
-
error_message AS errorMessage,
|
|
101
|
-
created_at AS createdAt,
|
|
102
|
-
started_at AS startedAt,
|
|
103
|
-
finished_at AS finishedAt
|
|
104
|
-
FROM agent_queue_items
|
|
105
|
-
${where}
|
|
106
|
-
ORDER BY
|
|
107
|
-
CASE status WHEN 'running' THEN 0 WHEN 'queued' THEN 1 WHEN 'failed' THEN 2 ELSE 3 END,
|
|
108
|
-
created_at DESC
|
|
109
|
-
LIMIT 80
|
|
110
|
-
`).all(...(sessionId ? [sessionId] : [])) as AgentQueueRow[];
|
|
111
|
-
return rows.map(queueItemFromRow);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function getAgentQueueProjection(sessionIds: readonly string[]): AgentQueueProjection {
|
|
115
|
-
const queueBySession: Record<string, AgentQueueItem[]> = {};
|
|
116
|
-
const runSummaryBySession: Record<string, AgentSessionRunSummary> = {};
|
|
117
|
-
for (const sessionId of sessionIds) {
|
|
118
|
-
const items = listAgentQueueItems(sessionId);
|
|
119
|
-
queueBySession[sessionId] = items;
|
|
120
|
-
runSummaryBySession[sessionId] = summarizeQueue(items);
|
|
121
|
-
}
|
|
122
|
-
return { queueBySession, runSummaryBySession };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function claimNextAgentQueueItem(limits: AgentQueueLimits) {
|
|
126
|
-
if (countRunningItems() >= limits.maxGlobalRunning) return null;
|
|
127
|
-
const rows = getDb().prepare(`
|
|
128
|
-
SELECT
|
|
129
|
-
id,
|
|
130
|
-
session_id AS sessionId,
|
|
131
|
-
request_id AS requestId,
|
|
132
|
-
prompt,
|
|
133
|
-
options,
|
|
134
|
-
tool_plan AS toolPlan,
|
|
135
|
-
status,
|
|
136
|
-
position,
|
|
137
|
-
result_image_ids AS resultImageIds,
|
|
138
|
-
error_code AS errorCode,
|
|
139
|
-
error_message AS errorMessage,
|
|
140
|
-
created_at AS createdAt,
|
|
141
|
-
started_at AS startedAt,
|
|
142
|
-
finished_at AS finishedAt
|
|
143
|
-
FROM agent_queue_items
|
|
144
|
-
WHERE status = 'queued'
|
|
145
|
-
ORDER BY created_at ASC
|
|
146
|
-
LIMIT 20
|
|
147
|
-
`).all() as AgentQueueRow[];
|
|
148
|
-
|
|
149
|
-
for (const row of rows) {
|
|
150
|
-
if (countRunningItems(row.sessionId) >= limits.maxSessionRunning) continue;
|
|
151
|
-
const res = getDb().prepare(`
|
|
152
|
-
UPDATE agent_queue_items
|
|
153
|
-
SET status = 'running', started_at = ?, error_code = NULL, error_message = NULL
|
|
154
|
-
WHERE id = ? AND status = 'queued'
|
|
155
|
-
`).run(Date.now(), row.id);
|
|
156
|
-
if (res.changes > 0) return getAgentQueueItem(row.id);
|
|
157
|
-
}
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function completeAgentQueueItem(id: string, imageIds: readonly string[]) {
|
|
162
|
-
getDb().prepare(`
|
|
163
|
-
UPDATE agent_queue_items
|
|
164
|
-
SET status = 'succeeded',
|
|
165
|
-
result_image_ids = ?,
|
|
166
|
-
finished_at = ?,
|
|
167
|
-
error_code = NULL,
|
|
168
|
-
error_message = NULL
|
|
169
|
-
WHERE id = ?
|
|
170
|
-
`).run(JSON.stringify([...imageIds]), Date.now(), id);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function failAgentQueueItem(id: string, error: { code?: string | null; message: string }) {
|
|
174
|
-
getDb().prepare(`
|
|
175
|
-
UPDATE agent_queue_items
|
|
176
|
-
SET status = 'failed',
|
|
177
|
-
error_code = ?,
|
|
178
|
-
error_message = ?,
|
|
179
|
-
finished_at = ?
|
|
180
|
-
WHERE id = ?
|
|
181
|
-
`).run(error.code ?? "AGENT_QUEUE_FAILED", error.message, Date.now(), id);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function cancelAgentQueueItem(id: string) {
|
|
185
|
-
const res = getDb().prepare(`
|
|
186
|
-
UPDATE agent_queue_items
|
|
187
|
-
SET status = 'canceled', finished_at = ?
|
|
188
|
-
WHERE id = ? AND status = 'queued'
|
|
189
|
-
`).run(Date.now(), id);
|
|
190
|
-
return res.changes > 0;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function retryAgentQueueItem(id: string) {
|
|
194
|
-
const res = getDb().prepare(`
|
|
195
|
-
UPDATE agent_queue_items
|
|
196
|
-
SET status = 'queued',
|
|
197
|
-
position = ?,
|
|
198
|
-
result_image_ids = '[]',
|
|
199
|
-
error_code = NULL,
|
|
200
|
-
error_message = NULL,
|
|
201
|
-
started_at = NULL,
|
|
202
|
-
finished_at = NULL
|
|
203
|
-
WHERE id = ? AND status IN ('failed', 'canceled')
|
|
204
|
-
`).run(getQueuedCount(null) + 1, id);
|
|
205
|
-
return res.changes > 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function queueItemFromRow(row: AgentQueueRow): AgentQueueItem {
|
|
209
|
-
const options = normalizeAgentGenerationSettings(parseJson(row.options, {}));
|
|
210
|
-
return {
|
|
211
|
-
id: row.id,
|
|
212
|
-
sessionId: row.sessionId,
|
|
213
|
-
requestId: row.requestId,
|
|
214
|
-
prompt: row.prompt,
|
|
215
|
-
status: row.status,
|
|
216
|
-
position: row.position,
|
|
217
|
-
resultImageIds: parseStringArray(row.resultImageIds),
|
|
218
|
-
errorCode: row.errorCode,
|
|
219
|
-
errorMessage: row.errorMessage,
|
|
220
|
-
createdAt: row.createdAt,
|
|
221
|
-
startedAt: row.startedAt,
|
|
222
|
-
finishedAt: row.finishedAt,
|
|
223
|
-
options,
|
|
224
|
-
plan: normalizeAgentGenerationPlan(row.prompt, parseJson(row.toolPlan, {}), options),
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function summarizeQueue(items: readonly AgentQueueItem[]): AgentSessionRunSummary {
|
|
229
|
-
const queuedCount = items.filter((item) => item.status === "queued").length;
|
|
230
|
-
const runningCount = items.filter((item) => item.status === "running").length;
|
|
231
|
-
const failed = items.find((item) => item.status === "failed");
|
|
232
|
-
return {
|
|
233
|
-
status: runningCount > 0 ? "running" : queuedCount > 0 ? "queued" : failed ? "error" : "idle",
|
|
234
|
-
queuedCount,
|
|
235
|
-
runningCount,
|
|
236
|
-
lastQueueItemId: items[0]?.id ?? null,
|
|
237
|
-
lastError: failed?.errorMessage ?? null,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function getQueuedCount(sessionId: string | null) {
|
|
242
|
-
const row = sessionId
|
|
243
|
-
? getDb().prepare("SELECT COUNT(*) AS count FROM agent_queue_items WHERE session_id = ? AND status = 'queued'").get(sessionId)
|
|
244
|
-
: getDb().prepare("SELECT COUNT(*) AS count FROM agent_queue_items WHERE status = 'queued'").get();
|
|
245
|
-
return Number((row as { count?: number } | undefined)?.count ?? 0);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function countRunningItems(sessionId?: string) {
|
|
249
|
-
const row = sessionId
|
|
250
|
-
? getDb().prepare("SELECT COUNT(*) AS count FROM agent_queue_items WHERE session_id = ? AND status = 'running'").get(sessionId)
|
|
251
|
-
: getDb().prepare("SELECT COUNT(*) AS count FROM agent_queue_items WHERE status = 'running'").get();
|
|
252
|
-
return Number((row as { count?: number } | undefined)?.count ?? 0);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function parseJson(value: string, fallback: unknown) {
|
|
256
|
-
try {
|
|
257
|
-
return JSON.parse(value);
|
|
258
|
-
} catch {
|
|
259
|
-
return fallback;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function parseStringArray(value: string) {
|
|
264
|
-
const parsed = parseJson(value, []);
|
|
265
|
-
return Array.isArray(parsed) ? parsed.filter((item): item is string => typeof item === "string") : [];
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export function getDefaultAgentQueueOptions(): AgentGenerationSettings {
|
|
269
|
-
return DEFAULT_AGENT_GENERATION_SETTINGS;
|
|
270
|
-
}
|
package/lib/agentQueueWorker.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
claimNextAgentQueueItem,
|
|
3
|
-
completeAgentQueueItem,
|
|
4
|
-
failAgentQueueItem,
|
|
5
|
-
getAgentQueueItem,
|
|
6
|
-
type AgentQueueLimits,
|
|
7
|
-
} from "./agentQueueStore.js";
|
|
8
|
-
import { runAgentGenerationPlan } from "./agentRuntime.js";
|
|
9
|
-
import { errInfo } from "./errInfo.js";
|
|
10
|
-
import { finishJob, setJobPhase, startJob } from "./inflight.js";
|
|
11
|
-
import { logEvent } from "./logger.js";
|
|
12
|
-
import type { RuntimeContext } from "./runtimeContext.js";
|
|
13
|
-
|
|
14
|
-
const DEFAULT_LIMITS: AgentQueueLimits = {
|
|
15
|
-
maxGlobalRunning: 2,
|
|
16
|
-
maxSessionRunning: 1,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
let workerTimer: NodeJS.Timeout | null = null;
|
|
20
|
-
let ticking = false;
|
|
21
|
-
|
|
22
|
-
export function ensureAgentQueueWorker(ctx: RuntimeContext) {
|
|
23
|
-
if (workerTimer) return;
|
|
24
|
-
workerTimer = setInterval(() => {
|
|
25
|
-
void tickAgentQueueWorker(ctx);
|
|
26
|
-
}, 1_500);
|
|
27
|
-
workerTimer.unref?.();
|
|
28
|
-
void tickAgentQueueWorker(ctx);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function tickAgentQueueWorker(ctx: RuntimeContext) {
|
|
32
|
-
if (ticking) return;
|
|
33
|
-
ticking = true;
|
|
34
|
-
try {
|
|
35
|
-
while (true) {
|
|
36
|
-
const item = claimNextAgentQueueItem(DEFAULT_LIMITS);
|
|
37
|
-
if (!item) return;
|
|
38
|
-
void runClaimedQueueItem(ctx, item.id).finally(() => {
|
|
39
|
-
void tickAgentQueueWorker(ctx);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
} finally {
|
|
43
|
-
ticking = false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function runClaimedQueueItem(ctx: RuntimeContext, itemId: string) {
|
|
48
|
-
const item = getAgentQueueItem(itemId);
|
|
49
|
-
if (!item) return;
|
|
50
|
-
startJob({
|
|
51
|
-
requestId: item.requestId,
|
|
52
|
-
kind: "agent_queue",
|
|
53
|
-
prompt: item.prompt,
|
|
54
|
-
meta: {
|
|
55
|
-
sessionId: item.sessionId,
|
|
56
|
-
queueItemId: item.id,
|
|
57
|
-
variants: item.plan.plannedVariants,
|
|
58
|
-
parallelism: item.plan.plannedParallelism,
|
|
59
|
-
requestedVariants: item.plan.requestedVariants,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
try {
|
|
63
|
-
logEvent("agent_queue", "start", { itemId: item.id, sessionId: item.sessionId });
|
|
64
|
-
setJobPhase(item.requestId, "streaming");
|
|
65
|
-
const result = await runAgentGenerationPlan(ctx, item.sessionId, item.prompt, item.plan, {
|
|
66
|
-
...item.options,
|
|
67
|
-
requestId: item.requestId,
|
|
68
|
-
webSearchEnabled: item.options.webSearchEnabled,
|
|
69
|
-
parallelism: item.plan.plannedParallelism,
|
|
70
|
-
}, {
|
|
71
|
-
appendUserTurn: false,
|
|
72
|
-
});
|
|
73
|
-
completeAgentQueueItem(item.id, result.imageIds);
|
|
74
|
-
finishJob(item.requestId, {
|
|
75
|
-
status: "completed",
|
|
76
|
-
meta: { imageIds: result.imageIds },
|
|
77
|
-
});
|
|
78
|
-
logEvent("agent_queue", "finish", { itemId: item.id, imageCount: result.imageIds.length });
|
|
79
|
-
} catch (error) {
|
|
80
|
-
const err = errInfo(error);
|
|
81
|
-
failAgentQueueItem(item.id, { code: err.code, message: err.message });
|
|
82
|
-
finishJob(item.requestId, {
|
|
83
|
-
status: "failed",
|
|
84
|
-
errorCode: err.code,
|
|
85
|
-
meta: { queueItemId: item.id },
|
|
86
|
-
});
|
|
87
|
-
logEvent("agent_queue", "error", { itemId: item.id, code: err.code, message: err.message });
|
|
88
|
-
}
|
|
89
|
-
}
|