ima2-gen 1.1.13 → 1.1.14
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 +10 -1
- package/bin/commands/doctor.js +195 -0
- package/bin/commands/doctor.ts +202 -0
- package/bin/ima2.js +3 -105
- package/bin/ima2.ts +3 -109
- package/config.js +1 -0
- package/config.ts +5 -0
- package/docs/CLI.md +36 -0
- package/docs/FAQ.ko.md +82 -2
- package/docs/FAQ.md +85 -2
- package/docs/PROMPT_STUDIO.ko.md +111 -0
- package/docs/PROMPT_STUDIO.md +115 -0
- package/docs/README.ko.md +8 -1
- package/docs/migration/runtime-test-inventory.md +6 -1
- package/lib/agentRuntime.js +9 -2
- package/lib/agentRuntime.ts +8 -2
- package/lib/errorClassify.js +1 -1
- package/lib/errorClassify.ts +1 -1
- package/lib/generationErrors.js +121 -23
- package/lib/generationErrors.ts +100 -13
- package/lib/responsesDoctor.js +386 -0
- package/lib/responsesDoctor.ts +456 -0
- package/lib/responsesErrors.js +57 -0
- package/lib/responsesErrors.ts +83 -0
- package/lib/responsesFallback.js +72 -0
- package/lib/responsesFallback.ts +114 -0
- package/lib/responsesImageAdapter.js +121 -174
- package/lib/responsesImageAdapter.ts +136 -211
- package/lib/responsesParse.js +324 -0
- package/lib/responsesParse.ts +452 -0
- package/lib/responsesTools.js +15 -0
- package/lib/responsesTools.ts +28 -0
- package/package.json +1 -1
- package/routes/edit.js +26 -1
- package/routes/edit.ts +26 -1
- package/routes/generate.js +40 -0
- package/routes/generate.ts +47 -0
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/{AgentWorkspace-BJe9yxPA.js → AgentWorkspace-B6YNOZHi.js} +1 -1
- package/ui/dist/assets/{CardNewsWorkspace-BBLdwzYU.js → CardNewsWorkspace-EFVeg4l_.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-BSZ527J4.js → NodeCanvas-iM6yjHvO.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-Y2VygFc0.js → PromptBuilderPanel-C3GdLDCl.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-C6lFV-LL.js → PromptImportDialog-DS9vrc_w.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-D8YJFhND.js → PromptImportDiscoverySection-DHFEt_FA.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-ywfcQolW.js → PromptImportFolderSection-BQxb1zs5.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-fk4KmrGy.js → PromptLibraryPanel-NhMKVGfU.js} +2 -2
- package/ui/dist/assets/{SettingsWorkspace-DL5vhAHQ.js → SettingsWorkspace-FjKjaDqj.js} +1 -1
- package/ui/dist/assets/index-BAN6lKgf.js +28 -0
- package/ui/dist/assets/{index-BLx55BOg.js → index-BbFZyM92.js} +1 -1
- package/ui/dist/assets/index-DK1faG9Z.css +1 -0
- package/ui/dist/index.html +2 -2
- package/ui/dist/assets/index-ByViUJfx.css +0 -1
- package/ui/dist/assets/index-Ci36vcFD.js +0 -28
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { config as defaultConfig } from "../config.js";
|
|
2
|
+
import { errInfo } from "./errInfo.js";
|
|
3
|
+
import { parseJson, parseStream, safeDiagnosticLabel } from "./responsesParse.js";
|
|
4
|
+
import { GENERATE_DEVELOPER_PROMPT, GENERATE_NO_SEARCH_DEVELOPER_PROMPT, buildUserTextPrompt, waitForOAuthReady, } from "./oauthProxy.js";
|
|
5
|
+
const BUILTIN_PROMPT_ID = "builtin_cat";
|
|
6
|
+
const BUILTIN_CAT_PROMPT = "고양이";
|
|
7
|
+
const TEXT_OK_PROMPT = "Reply with exactly OK.";
|
|
8
|
+
function imageTool(size, quality, moderation) {
|
|
9
|
+
return { type: "image_generation", size, quality, moderation, action: "generate" };
|
|
10
|
+
}
|
|
11
|
+
function createProbeSpecs({ model, size, quality, moderation, prompt, matrix, }) {
|
|
12
|
+
const imageOnlyTools = [imageTool(size, quality, moderation)];
|
|
13
|
+
const webSearchImageTools = [{ type: "web_search" }, imageTool(size, quality, moderation)];
|
|
14
|
+
const specs = [
|
|
15
|
+
{
|
|
16
|
+
id: "text_sanity",
|
|
17
|
+
expectation: "text",
|
|
18
|
+
promptId: "builtin_text_ok",
|
|
19
|
+
promptChars: TEXT_OK_PROMPT.length,
|
|
20
|
+
stream: false,
|
|
21
|
+
toolTypes: [],
|
|
22
|
+
toolChoiceKind: "none",
|
|
23
|
+
payload: {
|
|
24
|
+
model,
|
|
25
|
+
input: [{ role: "user", content: TEXT_OK_PROMPT }],
|
|
26
|
+
stream: false,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "minimal_image_non_stream",
|
|
31
|
+
expectation: "image",
|
|
32
|
+
promptId: BUILTIN_PROMPT_ID,
|
|
33
|
+
promptChars: prompt.length,
|
|
34
|
+
stream: false,
|
|
35
|
+
toolTypes: ["image_generation"],
|
|
36
|
+
toolChoiceKind: "image_generation",
|
|
37
|
+
payload: {
|
|
38
|
+
model,
|
|
39
|
+
input: [{ role: "user", content: prompt }],
|
|
40
|
+
tools: imageOnlyTools,
|
|
41
|
+
tool_choice: { type: "image_generation" },
|
|
42
|
+
stream: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "minimal_image_stream",
|
|
47
|
+
expectation: "image",
|
|
48
|
+
promptId: BUILTIN_PROMPT_ID,
|
|
49
|
+
promptChars: prompt.length,
|
|
50
|
+
stream: true,
|
|
51
|
+
toolTypes: ["image_generation"],
|
|
52
|
+
toolChoiceKind: "image_generation",
|
|
53
|
+
payload: {
|
|
54
|
+
model,
|
|
55
|
+
input: [{ role: "user", content: prompt }],
|
|
56
|
+
tools: imageOnlyTools,
|
|
57
|
+
tool_choice: { type: "image_generation" },
|
|
58
|
+
stream: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
if (!matrix)
|
|
63
|
+
return specs;
|
|
64
|
+
return [
|
|
65
|
+
...specs,
|
|
66
|
+
{
|
|
67
|
+
id: "current_payload_no_search_required",
|
|
68
|
+
expectation: "image",
|
|
69
|
+
promptId: BUILTIN_PROMPT_ID,
|
|
70
|
+
promptChars: prompt.length,
|
|
71
|
+
stream: true,
|
|
72
|
+
toolTypes: ["image_generation"],
|
|
73
|
+
toolChoiceKind: "required",
|
|
74
|
+
payload: {
|
|
75
|
+
model,
|
|
76
|
+
input: [
|
|
77
|
+
{ role: "developer", content: GENERATE_NO_SEARCH_DEVELOPER_PROMPT },
|
|
78
|
+
{ role: "user", content: buildUserTextPrompt(prompt, "auto", { webSearchEnabled: false }) },
|
|
79
|
+
],
|
|
80
|
+
tools: imageOnlyTools,
|
|
81
|
+
tool_choice: "required",
|
|
82
|
+
reasoning: { effort: "low" },
|
|
83
|
+
stream: true,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "current_payload_web_search_required",
|
|
88
|
+
expectation: "image",
|
|
89
|
+
promptId: BUILTIN_PROMPT_ID,
|
|
90
|
+
promptChars: prompt.length,
|
|
91
|
+
stream: true,
|
|
92
|
+
toolTypes: ["web_search", "image_generation"],
|
|
93
|
+
toolChoiceKind: "required",
|
|
94
|
+
payload: {
|
|
95
|
+
model,
|
|
96
|
+
input: [
|
|
97
|
+
{ role: "developer", content: GENERATE_DEVELOPER_PROMPT },
|
|
98
|
+
{ role: "user", content: buildUserTextPrompt(prompt, "auto", { webSearchEnabled: true }) },
|
|
99
|
+
],
|
|
100
|
+
tools: webSearchImageTools,
|
|
101
|
+
tool_choice: "required",
|
|
102
|
+
reasoning: { effort: "low" },
|
|
103
|
+
stream: true,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "current_payload_web_search_forced_image",
|
|
108
|
+
expectation: "image",
|
|
109
|
+
promptId: BUILTIN_PROMPT_ID,
|
|
110
|
+
promptChars: prompt.length,
|
|
111
|
+
stream: true,
|
|
112
|
+
toolTypes: ["web_search", "image_generation"],
|
|
113
|
+
toolChoiceKind: "image_generation",
|
|
114
|
+
payload: {
|
|
115
|
+
model,
|
|
116
|
+
input: [
|
|
117
|
+
{ role: "developer", content: GENERATE_DEVELOPER_PROMPT },
|
|
118
|
+
{ role: "user", content: buildUserTextPrompt(prompt, "auto", { webSearchEnabled: true }) },
|
|
119
|
+
],
|
|
120
|
+
tools: webSearchImageTools,
|
|
121
|
+
tool_choice: { type: "image_generation" },
|
|
122
|
+
reasoning: { effort: "low" },
|
|
123
|
+
stream: true,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
async function endpointFor(provider, options) {
|
|
129
|
+
const ctx = options.ctx || { config: defaultConfig };
|
|
130
|
+
if (provider === "api") {
|
|
131
|
+
const headers = {
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
Accept: "text/event-stream, application/json",
|
|
134
|
+
Authorization: apiAuthorizationHeader(options.apiKey),
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
url: "https://api.openai.com/v1/responses",
|
|
138
|
+
headers,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
await waitForOAuthReady(ctx);
|
|
142
|
+
const port = ctx.config?.oauth?.proxyPort || defaultConfig.oauth.proxyPort;
|
|
143
|
+
const baseUrl = safeOAuthBaseUrl(options.oauthUrl || `http://127.0.0.1:${port}`);
|
|
144
|
+
const headers = {
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
Accept: "text/event-stream, application/json",
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
url: `${baseUrl}/v1/responses`,
|
|
150
|
+
headers,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function apiAuthorizationHeader(apiKey) {
|
|
154
|
+
const key = typeof apiKey === "string" ? apiKey.trim() : "";
|
|
155
|
+
if (!key) {
|
|
156
|
+
throw Object.assign(new Error("API key is required for API provider image probe"), {
|
|
157
|
+
code: "API_KEY_REQUIRED",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (/[\u0000-\u001f\u007f]/.test(key)) {
|
|
161
|
+
throw Object.assign(new Error("API key contains invalid characters."), {
|
|
162
|
+
code: "AUTH_API_KEY_INVALID",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return `Bearer ${key}`;
|
|
166
|
+
}
|
|
167
|
+
function safeOAuthBaseUrl(value) {
|
|
168
|
+
try {
|
|
169
|
+
const parsed = new URL(value);
|
|
170
|
+
parsed.username = "";
|
|
171
|
+
parsed.password = "";
|
|
172
|
+
return parsed.toString().replace(/\/$/, "");
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return value.replace(/\/$/, "");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function sanitizeProbeErrorMessage(value) {
|
|
179
|
+
return value
|
|
180
|
+
.replace(/([a-z][a-z0-9+.-]*:\/\/)([^/\s@]+)@/gi, "$1[redacted]@")
|
|
181
|
+
.replace(/([?&](?:access_token|api_key|key|secret|token)=)[^&\s]+/gi, "$1[redacted]")
|
|
182
|
+
.replace(/Bearer\s+[^"'\s]+/gi, "Bearer [redacted]")
|
|
183
|
+
.replace(/sk-[A-Za-z0-9_-]+/g, "sk-[redacted]");
|
|
184
|
+
}
|
|
185
|
+
function safeUpstreamError(text) {
|
|
186
|
+
try {
|
|
187
|
+
const parsed = JSON.parse(text);
|
|
188
|
+
const error = parsed?.error || {};
|
|
189
|
+
return {
|
|
190
|
+
code: safeDiagnosticLabel(error.code),
|
|
191
|
+
type: safeDiagnosticLabel(error.type),
|
|
192
|
+
param: safeDiagnosticLabel(error.param),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return { code: null, type: null, param: null };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function reasonFrom(result) {
|
|
200
|
+
const diagnostics = result.response.diagnostics;
|
|
201
|
+
if (!result.error && result.ok)
|
|
202
|
+
return null;
|
|
203
|
+
if (result.error?.code)
|
|
204
|
+
return result.error.code;
|
|
205
|
+
if (!diagnostics)
|
|
206
|
+
return "probe_failed";
|
|
207
|
+
if (diagnostics.streamStats.bytesRead > 0 && result.response.eventCount === 0)
|
|
208
|
+
return "stream_parse_failed";
|
|
209
|
+
if (diagnostics.imageCallFailed)
|
|
210
|
+
return "image_tool_failed";
|
|
211
|
+
if (diagnostics.imageCallCompleted && diagnostics.imageResultCount === 0)
|
|
212
|
+
return "image_tool_completed_without_result";
|
|
213
|
+
if (!diagnostics.imageCallSeen && result.response.webSearchCalls > 0)
|
|
214
|
+
return "web_search_only_response";
|
|
215
|
+
if (!diagnostics.imageCallSeen && diagnostics.messageOutputSeen)
|
|
216
|
+
return "image_tool_not_called";
|
|
217
|
+
if (result.expectation === "text" && result.response.textOutputChars === 0)
|
|
218
|
+
return "text_output_missing";
|
|
219
|
+
if (result.expectation === "image" && result.response.imageResultCount === 0)
|
|
220
|
+
return "image_output_missing";
|
|
221
|
+
return "probe_failed";
|
|
222
|
+
}
|
|
223
|
+
async function runSingleProbe(provider, options, spec) {
|
|
224
|
+
const start = Date.now();
|
|
225
|
+
let httpStatus = null;
|
|
226
|
+
let contentType = null;
|
|
227
|
+
let upstreamRequestId = null;
|
|
228
|
+
try {
|
|
229
|
+
const endpoint = await endpointFor(provider, options);
|
|
230
|
+
const controller = new AbortController();
|
|
231
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs || defaultConfig.oauth.generationTimeoutMs);
|
|
232
|
+
try {
|
|
233
|
+
const res = await fetch(endpoint.url, {
|
|
234
|
+
method: "POST",
|
|
235
|
+
headers: endpoint.headers,
|
|
236
|
+
signal: controller.signal,
|
|
237
|
+
body: JSON.stringify(spec.payload),
|
|
238
|
+
});
|
|
239
|
+
httpStatus = res.status;
|
|
240
|
+
contentType = res.headers.get("content-type");
|
|
241
|
+
upstreamRequestId = res.headers.get("x-request-id") || res.headers.get("openai-request-id");
|
|
242
|
+
if (!res.ok) {
|
|
243
|
+
const body = await res.text();
|
|
244
|
+
const upstream = safeUpstreamError(body);
|
|
245
|
+
const partial = {
|
|
246
|
+
id: spec.id,
|
|
247
|
+
ok: false,
|
|
248
|
+
expectation: spec.expectation,
|
|
249
|
+
request: {
|
|
250
|
+
stream: spec.stream,
|
|
251
|
+
toolTypes: spec.toolTypes,
|
|
252
|
+
toolChoiceKind: spec.toolChoiceKind,
|
|
253
|
+
promptId: spec.promptId,
|
|
254
|
+
promptChars: spec.promptChars,
|
|
255
|
+
},
|
|
256
|
+
response: {
|
|
257
|
+
httpStatus,
|
|
258
|
+
contentType,
|
|
259
|
+
upstreamRequestId,
|
|
260
|
+
durationMs: Date.now() - start,
|
|
261
|
+
eventCount: 0,
|
|
262
|
+
eventTypes: {},
|
|
263
|
+
webSearchCalls: 0,
|
|
264
|
+
textOutputChars: 0,
|
|
265
|
+
imageResultCount: 0,
|
|
266
|
+
firstImageChars: 0,
|
|
267
|
+
diagnostics: null,
|
|
268
|
+
},
|
|
269
|
+
error: {
|
|
270
|
+
...upstream,
|
|
271
|
+
message: "Upstream returned a non-2xx response",
|
|
272
|
+
upstreamBodyChars: body.length,
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
return { ...partial, diagnosticReason: reasonFrom(partial) };
|
|
276
|
+
}
|
|
277
|
+
const parsed = contentType?.includes("text/event-stream")
|
|
278
|
+
? await parseStream(res, { scope: "doctor-image-probe", maxImages: 1 })
|
|
279
|
+
: await parseJson(res, 1);
|
|
280
|
+
const ok = spec.expectation === "image"
|
|
281
|
+
? Boolean(parsed.images[0]?.b64)
|
|
282
|
+
: Boolean(parsed.text && parsed.text.trim());
|
|
283
|
+
const partial = {
|
|
284
|
+
id: spec.id,
|
|
285
|
+
ok,
|
|
286
|
+
expectation: spec.expectation,
|
|
287
|
+
request: {
|
|
288
|
+
stream: spec.stream,
|
|
289
|
+
toolTypes: spec.toolTypes,
|
|
290
|
+
toolChoiceKind: spec.toolChoiceKind,
|
|
291
|
+
promptId: spec.promptId,
|
|
292
|
+
promptChars: spec.promptChars,
|
|
293
|
+
},
|
|
294
|
+
response: {
|
|
295
|
+
httpStatus,
|
|
296
|
+
contentType,
|
|
297
|
+
upstreamRequestId,
|
|
298
|
+
durationMs: Date.now() - start,
|
|
299
|
+
eventCount: parsed.eventCount,
|
|
300
|
+
eventTypes: parsed.eventTypes,
|
|
301
|
+
webSearchCalls: parsed.webSearchCalls,
|
|
302
|
+
textOutputChars: parsed.text?.length || 0,
|
|
303
|
+
imageResultCount: parsed.images.length,
|
|
304
|
+
firstImageChars: parsed.images[0]?.b64.length || 0,
|
|
305
|
+
diagnostics: parsed.diagnostics,
|
|
306
|
+
},
|
|
307
|
+
error: null,
|
|
308
|
+
};
|
|
309
|
+
return { ...partial, diagnosticReason: reasonFrom(partial) };
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
clearTimeout(timer);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
const err = errInfo(e);
|
|
317
|
+
const partial = {
|
|
318
|
+
id: spec.id,
|
|
319
|
+
ok: false,
|
|
320
|
+
expectation: spec.expectation,
|
|
321
|
+
request: {
|
|
322
|
+
stream: spec.stream,
|
|
323
|
+
toolTypes: spec.toolTypes,
|
|
324
|
+
toolChoiceKind: spec.toolChoiceKind,
|
|
325
|
+
promptId: spec.promptId,
|
|
326
|
+
promptChars: spec.promptChars,
|
|
327
|
+
},
|
|
328
|
+
response: {
|
|
329
|
+
httpStatus,
|
|
330
|
+
contentType,
|
|
331
|
+
upstreamRequestId,
|
|
332
|
+
durationMs: Date.now() - start,
|
|
333
|
+
eventCount: Number(err.raw?.eventCount) || 0,
|
|
334
|
+
eventTypes: {},
|
|
335
|
+
webSearchCalls: 0,
|
|
336
|
+
textOutputChars: 0,
|
|
337
|
+
imageResultCount: 0,
|
|
338
|
+
firstImageChars: 0,
|
|
339
|
+
diagnostics: null,
|
|
340
|
+
},
|
|
341
|
+
error: {
|
|
342
|
+
code: safeDiagnosticLabel(err.code),
|
|
343
|
+
type: null,
|
|
344
|
+
param: null,
|
|
345
|
+
message: err.name === "AbortError" ? "Probe timed out" : sanitizeProbeErrorMessage(err.message),
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
return { ...partial, diagnosticReason: reasonFrom(partial) };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
export async function runImageDoctorProbe(options = {}) {
|
|
352
|
+
const provider = options.provider || "oauth";
|
|
353
|
+
const model = options.model || defaultConfig.imageModels?.default || "gpt-5.4-mini";
|
|
354
|
+
const size = options.size || "1024x1024";
|
|
355
|
+
const quality = options.quality || "low";
|
|
356
|
+
const moderation = options.moderation || "low";
|
|
357
|
+
const prompt = options.prompt || BUILTIN_CAT_PROMPT;
|
|
358
|
+
const specs = createProbeSpecs({
|
|
359
|
+
model,
|
|
360
|
+
size,
|
|
361
|
+
quality,
|
|
362
|
+
moderation,
|
|
363
|
+
prompt,
|
|
364
|
+
matrix: options.matrix === true,
|
|
365
|
+
});
|
|
366
|
+
const probes = [];
|
|
367
|
+
for (const spec of specs)
|
|
368
|
+
probes.push(await runSingleProbe(provider, options, spec));
|
|
369
|
+
return {
|
|
370
|
+
provider,
|
|
371
|
+
endpointKind: provider === "api" ? "api" : "oauth",
|
|
372
|
+
model,
|
|
373
|
+
size,
|
|
374
|
+
quality,
|
|
375
|
+
moderation,
|
|
376
|
+
promptId: options.prompt ? "custom" : BUILTIN_PROMPT_ID,
|
|
377
|
+
promptChars: prompt.length,
|
|
378
|
+
matrix: options.matrix === true,
|
|
379
|
+
probes,
|
|
380
|
+
summary: {
|
|
381
|
+
ok: probes.every((probe) => probe.ok),
|
|
382
|
+
passed: probes.filter((probe) => probe.ok).length,
|
|
383
|
+
failed: probes.filter((probe) => !probe.ok).length,
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|