@gobing-ai/knowledge-kit 0.0.19 → 0.0.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.
Files changed (69) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +161 -142
  3. package/package.json +1 -1
  4. package/plugins/generations/content-gen/dist/index.js +20 -3
  5. package/plugins/generations/core-facts-gen/dist/index.js +20 -3
  6. package/plugins/generations/daily-article-gen/dist/index.js +20 -3
  7. package/plugins/generations/dailynews-gen/dist/index.js +29 -4
  8. package/plugins/generations/dailynews-gen/src/script-builder.ts +19 -1
  9. package/plugins/generations/episode-plan-gen/dist/index.js +20 -3
  10. package/plugins/generations/image-gen/dist/index.js +147 -69
  11. package/plugins/generations/image-gen/src/presets.ts +2 -2
  12. package/plugins/generations/image-gen/src/providers/agnes.ts +6 -2
  13. package/plugins/generations/image-gen/src/providers/azure.ts +6 -2
  14. package/plugins/generations/image-gen/src/providers/dashscope.ts +10 -3
  15. package/plugins/generations/image-gen/src/providers/google.ts +70 -29
  16. package/plugins/generations/image-gen/src/providers/huggingface.ts +3 -0
  17. package/plugins/generations/image-gen/src/providers/jimeng.ts +9 -2
  18. package/plugins/generations/image-gen/src/providers/minimax.ts +10 -2
  19. package/plugins/generations/image-gen/src/providers/openai.ts +9 -3
  20. package/plugins/generations/image-gen/src/providers/openrouter.ts +16 -4
  21. package/plugins/generations/image-gen/src/providers/replicate.ts +13 -3
  22. package/plugins/generations/image-gen/src/providers/seedream.ts +4 -1
  23. package/plugins/generations/image-gen/src/providers/timeouts.ts +14 -0
  24. package/plugins/generations/image-gen/src/providers/types.ts +10 -0
  25. package/plugins/generations/image-gen/src/providers/zai.ts +4 -1
  26. package/plugins/generations/news-report-gen/dist/index.js +20 -3
  27. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/pipeline.py +13 -5
  28. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/qc.py +23 -15
  29. package/plugins/generations/voice-gen/dist/index.js +36 -10
  30. package/plugins/generations/voice-gen/src/voicebox-client.ts +18 -4
  31. package/plugins/generations/voice-gen/src/voicebox-server.ts +2 -1
  32. package/plugins/ingestions/aihot-ingest/dist/index.js +26 -6
  33. package/plugins/ingestions/aihot-ingest/plugin.json +1 -1
  34. package/plugins/ingestions/aihot-ingest/src/client.ts +5 -0
  35. package/plugins/ingestions/aihot-ingest/src/rss.ts +12 -2
  36. package/plugins/ingestions/horizon-ingest/dist/index.js +20 -3
  37. package/plugins/ingestions/last30days-ingest/dist/index.js +20 -3
  38. package/plugins/ingestions/web-search/dist/index.js +22 -3
  39. package/plugins/ingestions/web-search/src/index.ts +4 -0
  40. package/plugins/kk/commands/workflow-run.md +20 -6
  41. package/plugins/kk/plugin.json +1 -1
  42. package/plugins/kk/scripts/itc-stages.ts +563 -0
  43. package/plugins/kk/scripts/kk-workflow-stages.ts +125 -18
  44. package/plugins/kk/scripts/render-md.ts +7 -1
  45. package/plugins/kk/skills/article-adapt/SKILL.md +85 -0
  46. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +26 -16
  47. package/plugins/kk/workflows/kk-itc.yaml +461 -12
  48. package/plugins/publishings/emdash-pub/dist/index.js +76 -19
  49. package/plugins/publishings/emdash-pub/src/index.ts +4 -0
  50. package/plugins/publishings/infoq-pub/dist/index.js +74 -21
  51. package/plugins/publishings/juejin-pub/dist/index.js +74 -21
  52. package/plugins/publishings/medium-pub/dist/index.js +77 -19
  53. package/plugins/publishings/medium-pub/src/index.ts +5 -0
  54. package/plugins/publishings/podcast-pub/dist/index.js +130 -34
  55. package/plugins/publishings/podcast-pub/src/index.ts +20 -5
  56. package/plugins/publishings/podcast-pub/src/map.ts +11 -0
  57. package/plugins/publishings/podcast-pub/src/show-notes.ts +66 -13
  58. package/plugins/publishings/qiita-pub/dist/index.js +75 -18
  59. package/plugins/publishings/qiita-pub/src/index.ts +4 -0
  60. package/plugins/publishings/substack-pub/dist/index.js +74 -21
  61. package/plugins/publishings/surfdash-pub/dist/index.js +99 -62
  62. package/plugins/publishings/surfdash-pub/src/index.ts +60 -19
  63. package/plugins/publishings/wechatmp-pub/dist/index.js +79 -22
  64. package/plugins/publishings/wechatmp-pub/src/index.ts +12 -3
  65. package/plugins/publishings/x-pub/dist/index.js +56 -37
  66. package/plugins/publishings/x-pub/src/index.ts +4 -0
  67. package/plugins/publishings/xhs-pub/dist/index.js +74 -21
  68. package/plugins/publishings/zenn-pub/dist/index.js +103 -25
  69. package/plugins/publishings/zenn-pub/src/index.ts +43 -9
@@ -21781,6 +21781,22 @@ var ResultSchema = exports_external.object({
21781
21781
  error: exports_external.string().optional(),
21782
21782
  metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
21783
21783
  });
21784
+ var TargetOutcomeSchema = exports_external.object({
21785
+ target: exports_external.string(),
21786
+ ok: exports_external.boolean(),
21787
+ status: exports_external.enum(["published", "failed", "skipped"]),
21788
+ url: exports_external.string().optional(),
21789
+ id: exports_external.string().optional(),
21790
+ error: exports_external.string().optional(),
21791
+ durationMs: exports_external.number().optional(),
21792
+ metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
21793
+ });
21794
+ var AggregateResultSchema = exports_external.object({
21795
+ ok: exports_external.boolean(),
21796
+ summary: exports_external.object({ total: exports_external.number(), succeeded: exports_external.number(), failed: exports_external.number(), skipped: exports_external.number() }),
21797
+ targets: exports_external.array(TargetOutcomeSchema),
21798
+ metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
21799
+ });
21784
21800
  var DocListSchema = exports_external.array(DocSchema);
21785
21801
  var omniVoiceGenContentSchema = ContentSchema.extend({
21786
21802
  format: exports_external.literal("audio"),
@@ -21809,14 +21825,15 @@ var PluginKindSchema = exports_external.enum(PLUGIN_KINDS);
21809
21825
  // ../../packages/kk-core/src/manifest.ts
21810
21826
  init_zod();
21811
21827
  var OperationIOSchema = exports_external.enum(["doc-list", "markdown"]);
21812
- var PluginManifestSchema = exports_external.object({
21828
+ var PluginOperationSchema = exports_external.object({ input: OperationIOSchema, output: OperationIOSchema });
21829
+ var PluginManifestSchema = exports_external.looseObject({
21813
21830
  name: exports_external.string().min(1),
21814
21831
  kind: PluginKindSchema,
21815
21832
  entry: exports_external.string().min(1),
21816
21833
  version: exports_external.string().optional(),
21817
21834
  description: exports_external.string().optional(),
21818
- operations: exports_external.record(exports_external.string(), exports_external.object({ input: OperationIOSchema, output: OperationIOSchema })).optional()
21819
- }).passthrough();
21835
+ operations: exports_external.record(exports_external.string(), PluginOperationSchema).optional()
21836
+ });
21820
21837
  // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.4.39/node_modules/@gobing-ai/ts-runtime/dist/index.js
21821
21838
  init_file_system_node();
21822
21839
  init_config();
@@ -21915,7 +21932,7 @@ function artifactPath(outPath, stem, format, index, extension) {
21915
21932
 
21916
21933
  // ../../plugins/generations/image-gen/src/presets.ts
21917
21934
  import { homedir } from "os";
21918
- import { join } from "path";
21935
+ import { delimiter, join } from "path";
21919
21936
  init_zod();
21920
21937
  var PaletteEntrySchema = exports_external.object({ role: exports_external.string(), name: exports_external.string(), hex: exports_external.string() });
21921
21938
  var PresetSourceSchema = exports_external.object({
@@ -22031,7 +22048,7 @@ function resolvePresetRoots() {
22031
22048
  if (isDirectory(projectRoot)) {
22032
22049
  roots.push(projectRoot);
22033
22050
  }
22034
- for (const entry of process.env.KK_IMAGE_PRESET_PATH?.split(":") ?? []) {
22051
+ for (const entry of process.env.KK_IMAGE_PRESET_PATH?.split(delimiter).filter((p) => p !== "") ?? []) {
22035
22052
  if (entry !== "" && isDirectory(entry)) {
22036
22053
  roots.push(entry);
22037
22054
  }
@@ -22110,6 +22127,11 @@ async function refToDataUri(path2) {
22110
22127
 
22111
22128
  // ../../plugins/generations/image-gen/src/providers/seedream.ts
22112
22129
  import { Buffer as Buffer2 } from "buffer";
22130
+
22131
+ // ../../plugins/generations/image-gen/src/providers/timeouts.ts
22132
+ var PROVIDER_REQUEST_TIMEOUT_MS = 300000;
22133
+
22134
+ // ../../plugins/generations/image-gen/src/providers/seedream.ts
22113
22135
  var DEFAULT_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
22114
22136
  var DEFAULT_MODEL = "doubao-seedream-5-0-260128";
22115
22137
  var REF_MODEL_FRAGMENTS = ["doubao-seedream-5-0", "doubao-seedream-4-5-", "doubao-seedream-4-0-"];
@@ -22128,6 +22150,7 @@ function extensionFromUrl(url2) {
22128
22150
  }
22129
22151
  var createSeedream = (options) => {
22130
22152
  const fetchFn = options?.fetch ?? fetch;
22153
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
22131
22154
  const env = options?.env ?? process.env;
22132
22155
  const readEnv = (key) => env[key] ?? "";
22133
22156
  const supportsRef = (model) => REF_MODEL_FRAGMENTS.some((fragment) => model.includes(fragment));
@@ -22165,7 +22188,8 @@ var createSeedream = (options) => {
22165
22188
  const resp = await fetchFn(`${base}/images/generations`, {
22166
22189
  method: "POST",
22167
22190
  headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
22168
- body: JSON.stringify(body)
22191
+ body: JSON.stringify(body),
22192
+ signal: AbortSignal.timeout(timeoutMs)
22169
22193
  });
22170
22194
  const text = await resp.text();
22171
22195
  if (!resp.ok) {
@@ -22193,7 +22217,7 @@ var createSeedream = (options) => {
22193
22217
  };
22194
22218
  }
22195
22219
  if (image.url !== undefined) {
22196
- const r = await fetchFn(image.url);
22220
+ const r = await fetchFn(image.url, { signal: AbortSignal.timeout(timeoutMs) });
22197
22221
  if (!r.ok) {
22198
22222
  throw new Error(`seedream fetch URL HTTP ${r.status}`);
22199
22223
  }
@@ -22248,13 +22272,13 @@ function buildRequestBody(prompt, model, args) {
22248
22272
  body.extra_body = { response_format: "url" };
22249
22273
  return body;
22250
22274
  }
22251
- async function extractImageFromResponse(result, fetchFn = fetch) {
22275
+ async function extractImageFromResponse(result, fetchFn = fetch, timeoutMs = PROVIDER_REQUEST_TIMEOUT_MS) {
22252
22276
  const img = result.data[0];
22253
22277
  if (img?.b64_json !== undefined && img.b64_json !== "") {
22254
22278
  return Uint8Array.from(Buffer3.from(img.b64_json, "base64"));
22255
22279
  }
22256
22280
  if (img?.url !== undefined) {
22257
- const imgRes = await fetchFn(img.url);
22281
+ const imgRes = await fetchFn(img.url, { signal: AbortSignal.timeout(timeoutMs) });
22258
22282
  if (!imgRes.ok)
22259
22283
  throw new Error(`Failed to download image from Agnes: ${imgRes.status}`);
22260
22284
  return new Uint8Array(await imgRes.arrayBuffer());
@@ -22263,6 +22287,7 @@ async function extractImageFromResponse(result, fetchFn = fetch) {
22263
22287
  }
22264
22288
  var createAgnes = (options) => {
22265
22289
  const fetchFn = options?.fetch ?? fetch;
22290
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
22266
22291
  const env = options?.env ?? process.env;
22267
22292
  const readEnv = (key) => env[key] ?? "";
22268
22293
  return {
@@ -22280,12 +22305,13 @@ var createAgnes = (options) => {
22280
22305
  const res = await fetchFn(`${base}/images/generations`, {
22281
22306
  method: "POST",
22282
22307
  headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
22283
- body: JSON.stringify(body)
22308
+ body: JSON.stringify(body),
22309
+ signal: AbortSignal.timeout(timeoutMs)
22284
22310
  });
22285
22311
  if (!res.ok)
22286
22312
  throw new Error(`Agnes API error (${res.status}): ${await res.text()}`);
22287
22313
  const result = await res.json();
22288
- const bytes = await extractImageFromResponse(result, fetchFn);
22314
+ const bytes = await extractImageFromResponse(result, fetchFn, timeoutMs);
22289
22315
  const url2 = result.data[0]?.url;
22290
22316
  return {
22291
22317
  bytes,
@@ -22482,13 +22508,13 @@ function getMimeType(filename) {
22482
22508
  return "image/gif";
22483
22509
  return "image/png";
22484
22510
  }
22485
- async function extractImageFromResponse2(result, fetchFn = fetch) {
22511
+ async function extractImageFromResponse2(result, fetchFn = fetch, timeoutMs = PROVIDER_REQUEST_TIMEOUT_MS) {
22486
22512
  const img = result.data[0];
22487
22513
  if (img?.b64_json !== undefined && img.b64_json !== "") {
22488
22514
  return Uint8Array.from(Buffer4.from(img.b64_json, "base64"));
22489
22515
  }
22490
22516
  if (img?.url !== undefined) {
22491
- const imgRes = await fetchFn(img.url);
22517
+ const imgRes = await fetchFn(img.url, { signal: AbortSignal.timeout(timeoutMs) });
22492
22518
  if (!imgRes.ok)
22493
22519
  throw new Error("Failed to download image");
22494
22520
  return new Uint8Array(await imgRes.arrayBuffer());
@@ -22497,6 +22523,7 @@ async function extractImageFromResponse2(result, fetchFn = fetch) {
22497
22523
  }
22498
22524
  var createOpenai = (options) => {
22499
22525
  const fetchFn = options?.fetch ?? fetch;
22526
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
22500
22527
  const env = options?.env ?? process.env;
22501
22528
  const readEnv = (key) => env[key] ?? "";
22502
22529
  const supportsRef = (model) => model.includes("gpt-image");
@@ -22523,7 +22550,8 @@ var createOpenai = (options) => {
22523
22550
  const chatRes = await fetchFn(`${baseURL}/chat/completions`, {
22524
22551
  method: "POST",
22525
22552
  headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
22526
- body: JSON.stringify({ model: req.model, messages: [{ role: "user", content: req.prompt }] })
22553
+ body: JSON.stringify({ model: req.model, messages: [{ role: "user", content: req.prompt }] }),
22554
+ signal: AbortSignal.timeout(timeoutMs)
22527
22555
  });
22528
22556
  if (!chatRes.ok)
22529
22557
  throw new Error(`OpenAI API error: ${await chatRes.text()}`);
@@ -22566,20 +22594,22 @@ var createOpenai = (options) => {
22566
22594
  const res2 = await fetchFn(`${baseURL}/images/edits`, {
22567
22595
  method: "POST",
22568
22596
  headers: { authorization: `Bearer ${apiKey}` },
22569
- body: form
22597
+ body: form,
22598
+ signal: AbortSignal.timeout(timeoutMs)
22570
22599
  });
22571
22600
  if (!res2.ok)
22572
22601
  throw new Error(`OpenAI edits API error: ${await res2.text()}`);
22573
- return extractImageFromResponse2(await res2.json(), fetchFn);
22602
+ return extractImageFromResponse2(await res2.json(), fetchFn, timeoutMs);
22574
22603
  }
22575
22604
  const res = await fetchFn(`${baseURL}/images/generations`, {
22576
22605
  method: "POST",
22577
22606
  headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
22578
- body: JSON.stringify(buildOpenAIGenerationsBody(req.prompt, req.model, args))
22607
+ body: JSON.stringify(buildOpenAIGenerationsBody(req.prompt, req.model, args)),
22608
+ signal: AbortSignal.timeout(timeoutMs)
22579
22609
  });
22580
22610
  if (!res.ok)
22581
22611
  throw new Error(`OpenAI API error: ${await res.text()}`);
22582
- return extractImageFromResponse2(await res.json(), fetchFn);
22612
+ return extractImageFromResponse2(await res.json(), fetchFn, timeoutMs);
22583
22613
  })();
22584
22614
  return { bytes, extension: "png", provider: "openai", model: req.model };
22585
22615
  }
@@ -22633,6 +22663,7 @@ function validateReferenceImages(referenceImages) {
22633
22663
  }
22634
22664
  var createAzure = (options) => {
22635
22665
  const fetchFn = options?.fetch ?? fetch;
22666
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
22636
22667
  const env = options?.env ?? process.env;
22637
22668
  function defaultModel() {
22638
22669
  const explicit = env.AZURE_OPENAI_DEPLOYMENT?.trim();
@@ -22682,20 +22713,22 @@ var createAzure = (options) => {
22682
22713
  const res2 = await fetchFn(buildURL(endpoint, deployment, "/images/edits", env), {
22683
22714
  method: "POST",
22684
22715
  headers: { "api-key": apiKey },
22685
- body: form
22716
+ body: form,
22717
+ signal: AbortSignal.timeout(timeoutMs)
22686
22718
  });
22687
22719
  if (!res2.ok)
22688
22720
  throw new Error(`Azure OpenAI edits API error: ${await res2.text()}`);
22689
- return extractImageFromResponse2(await res2.json(), fetchFn);
22721
+ return extractImageFromResponse2(await res2.json(), fetchFn, timeoutMs);
22690
22722
  }
22691
22723
  const res = await fetchFn(buildURL(endpoint, deployment, "/images/generations", env), {
22692
22724
  method: "POST",
22693
22725
  headers: { "content-type": "application/json", "api-key": apiKey },
22694
- body: JSON.stringify({ prompt: req.prompt, size, n: 1, quality: getAzureQuality(req.quality) })
22726
+ body: JSON.stringify({ prompt: req.prompt, size, n: 1, quality: getAzureQuality(req.quality) }),
22727
+ signal: AbortSignal.timeout(timeoutMs)
22695
22728
  });
22696
22729
  if (!res.ok)
22697
22730
  throw new Error(`Azure OpenAI API error: ${await res.text()}`);
22698
- return extractImageFromResponse2(await res.json(), fetchFn);
22731
+ return extractImageFromResponse2(await res.json(), fetchFn, timeoutMs);
22699
22732
  })();
22700
22733
  return { bytes, extension: "png", provider: "azure", model: req.model };
22701
22734
  }
@@ -23132,7 +23165,7 @@ function buildParameters(family, size) {
23132
23165
  }
23133
23166
  return parameters;
23134
23167
  }
23135
- async function extractImageFromResponse3(result, fetchFn) {
23168
+ async function extractImageFromResponse3(result, fetchFn, timeoutMs = PROVIDER_REQUEST_TIMEOUT_MS) {
23136
23169
  let imageData = null;
23137
23170
  if (result.output?.result_image !== undefined) {
23138
23171
  imageData = result.output.result_image;
@@ -23147,7 +23180,7 @@ async function extractImageFromResponse3(result, fetchFn) {
23147
23180
  if (imageData === null)
23148
23181
  throw new Error("No image in response");
23149
23182
  if (imageData.startsWith("http://") || imageData.startsWith("https://")) {
23150
- const imgRes = await fetchFn(imageData);
23183
+ const imgRes = await fetchFn(imageData, { signal: AbortSignal.timeout(timeoutMs) });
23151
23184
  if (!imgRes.ok)
23152
23185
  throw new Error("Failed to download image");
23153
23186
  return new Uint8Array(await imgRes.arrayBuffer());
@@ -23156,6 +23189,7 @@ async function extractImageFromResponse3(result, fetchFn) {
23156
23189
  }
23157
23190
  var createDashscope = (options) => {
23158
23191
  const fetchFn = options?.fetch ?? fetch;
23192
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
23159
23193
  const env = options?.env ?? process.env;
23160
23194
  const readEnv = (key) => env[key] ?? "";
23161
23195
  const supportsRef = (model) => model.includes("wan2.7");
@@ -23208,11 +23242,12 @@ var createDashscope = (options) => {
23208
23242
  const res = await fetchFn(url2, {
23209
23243
  method: "POST",
23210
23244
  headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
23211
- body: JSON.stringify(body)
23245
+ body: JSON.stringify(body),
23246
+ signal: AbortSignal.timeout(timeoutMs)
23212
23247
  });
23213
23248
  if (!res.ok)
23214
23249
  throw new Error(`DashScope API error (${res.status}): ${await res.text()}`);
23215
- const bytes = await extractImageFromResponse3(await res.json(), fetchFn);
23250
+ const bytes = await extractImageFromResponse3(await res.json(), fetchFn, timeoutMs);
23216
23251
  return { bytes, extension: "png", provider: "dashscope", model: req.model };
23217
23252
  }
23218
23253
  };
@@ -23221,6 +23256,9 @@ var createDashscope = (options) => {
23221
23256
  // ../../plugins/generations/image-gen/src/providers/google.ts
23222
23257
  import { Buffer as Buffer6 } from "buffer";
23223
23258
  import { execFileSync } from "child_process";
23259
+ import { randomUUID } from "crypto";
23260
+ import { tmpdir as tmpdir2 } from "os";
23261
+ import { join as join2 } from "path";
23224
23262
  var GOOGLE_MULTIMODAL_MODELS = [
23225
23263
  "gemini-3-pro-image",
23226
23264
  "gemini-3.1-flash-image",
@@ -23293,8 +23331,18 @@ function resolveSize2(req) {
23293
23331
  function getHttpProxy(readEnv) {
23294
23332
  return readEnv("https_proxy") || readEnv("HTTPS_PROXY") || readEnv("http_proxy") || readEnv("HTTP_PROXY") || readEnv("ALL_PROXY") || null;
23295
23333
  }
23334
+ var curlQuote = (s) => `"${s.replace(/[\\"]/g, "\\$&")}"`;
23335
+ var redact = (s, secrets) => secrets.filter((x) => x !== "").reduce((acc, x) => acc.replaceAll(x, "***"), s);
23336
+ function proxyPassword(proxy) {
23337
+ try {
23338
+ return decodeURIComponent(new URL(proxy).password);
23339
+ } catch {
23340
+ return "";
23341
+ }
23342
+ }
23296
23343
  var createGoogle = (options) => {
23297
23344
  const fetchFn = options?.fetch ?? fetch;
23345
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
23298
23346
  const env = options?.env ?? process.env;
23299
23347
  const readEnv = (key) => env[key] ?? "";
23300
23348
  const refModels = [
@@ -23313,30 +23361,35 @@ var createGoogle = (options) => {
23313
23361
  const url2 = buildGoogleUrl(base, pathname);
23314
23362
  const proxy = getHttpProxy(readEnv);
23315
23363
  if (proxy !== null && options?.fetch === undefined) {
23316
- const result = (() => {
23317
- try {
23318
- return execFileSync("curl", [
23319
- "-s",
23320
- "--connect-timeout",
23321
- "30",
23322
- "--max-time",
23323
- "300",
23324
- "-x",
23325
- proxy,
23326
- url2,
23327
- "-H",
23328
- "Content-Type: application/json",
23329
- "-H",
23330
- `x-goog-api-key: ${apiKey}`,
23331
- "-d",
23332
- "@-"
23333
- ], { input: JSON.stringify(body), encoding: "utf8", timeout: 310000 });
23334
- } catch (error51) {
23335
- const e = error51;
23336
- const details = (typeof e.stderr === "string" ? e.stderr.trim() : "") || e.message || "curl request failed";
23337
- throw new Error(`Google API request failed via curl: ${details}`);
23338
- }
23339
- })();
23364
+ const configPath = join2(tmpdir2(), `kk-image-gen-${randomUUID()}.curlrc`);
23365
+ const config3 = `proxy = ${curlQuote(proxy)}
23366
+ header = ${curlQuote(`x-goog-api-key: ${apiKey}`)}
23367
+ `;
23368
+ const fileSystem = createNodeFileSystem();
23369
+ await fileSystem.writeFile(configPath, config3);
23370
+ let result;
23371
+ try {
23372
+ result = execFileSync("curl", [
23373
+ "-sS",
23374
+ "--connect-timeout",
23375
+ "30",
23376
+ "--max-time",
23377
+ "300",
23378
+ "-K",
23379
+ configPath,
23380
+ "-H",
23381
+ "Content-Type: application/json",
23382
+ "-d",
23383
+ "@-",
23384
+ url2
23385
+ ], { input: JSON.stringify(body), encoding: "utf8", timeout: 310000 });
23386
+ } catch (error51) {
23387
+ const e = error51;
23388
+ const details = (typeof e.stderr === "string" ? e.stderr.trim() : "") || e.message || "curl request failed";
23389
+ throw new Error(`Google API request failed via curl: ${redact(details, [apiKey, proxyPassword(proxy), proxy])}`);
23390
+ } finally {
23391
+ await fileSystem.deleteFile(configPath);
23392
+ }
23340
23393
  const parsed = JSON.parse(result);
23341
23394
  if (parsed.error !== undefined) {
23342
23395
  throw new Error(`Google API error (${parsed.error.code}): ${parsed.error.message}`);
@@ -23346,7 +23399,8 @@ var createGoogle = (options) => {
23346
23399
  const res = await fetchFn(url2, {
23347
23400
  method: "POST",
23348
23401
  headers: { "content-type": "application/json", "x-goog-api-key": apiKey },
23349
- body: JSON.stringify(body)
23402
+ body: JSON.stringify(body),
23403
+ signal: AbortSignal.timeout(timeoutMs)
23350
23404
  });
23351
23405
  if (!res.ok) {
23352
23406
  const err = await res.text();
@@ -23435,6 +23489,7 @@ var buildPayload = (req) => ({
23435
23489
  });
23436
23490
  var createHuggingface = (options) => {
23437
23491
  const fetchFn = options?.fetch ?? fetch;
23492
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
23438
23493
  const env = options?.env ?? process.env;
23439
23494
  const readEnv = (key) => env[key] ?? "";
23440
23495
  return {
@@ -23451,7 +23506,8 @@ var createHuggingface = (options) => {
23451
23506
  const res = await fetchFn(`${BASE_URL}/${model}`, {
23452
23507
  method: "POST",
23453
23508
  headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
23454
- body: JSON.stringify(buildPayload(req))
23509
+ body: JSON.stringify(buildPayload(req)),
23510
+ signal: AbortSignal.timeout(timeoutMs)
23455
23511
  });
23456
23512
  if (!res.ok) {
23457
23513
  const text = (await res.text()).slice(0, 200);
@@ -23562,6 +23618,7 @@ function timestampHeader() {
23562
23618
  }
23563
23619
  var createJimeng = (options) => {
23564
23620
  const fetchFn = options?.fetch ?? fetch;
23621
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
23565
23622
  const env = options?.env ?? process.env;
23566
23623
  const readEnv = (key) => env[key] ?? "";
23567
23624
  async function signedPost(query, body, accessKey, secretKey, region) {
@@ -23573,7 +23630,12 @@ var createJimeng = (options) => {
23573
23630
  Host: endpoint.host
23574
23631
  };
23575
23632
  const authorization = generateSignature("POST", query, headers, body, accessKey, secretKey, region, "cv", endpoint.canonicalUri);
23576
- return fetchFn(endpoint.url, { method: "POST", headers: { ...headers, authorization }, body });
23633
+ return fetchFn(endpoint.url, {
23634
+ method: "POST",
23635
+ headers: { ...headers, authorization },
23636
+ body,
23637
+ signal: AbortSignal.timeout(timeoutMs)
23638
+ });
23577
23639
  }
23578
23640
  async function submitTask(req, size, accessKey, secretKey, region) {
23579
23641
  const query = { Action: "CVSync2AsyncSubmitTask", Version: "2022-08-31" };
@@ -23605,7 +23667,7 @@ var createJimeng = (options) => {
23605
23667
  }
23606
23668
  if (status === "done" && image_urls !== undefined && image_urls.length > 0) {
23607
23669
  const url2 = image_urls[0];
23608
- const imgRes = await fetchFn(url2);
23670
+ const imgRes = await fetchFn(url2, { signal: AbortSignal.timeout(timeoutMs) });
23609
23671
  if (!imgRes.ok)
23610
23672
  throw new Error(`Failed to download image from ${url2}`);
23611
23673
  return new Uint8Array(await imgRes.arrayBuffer());
@@ -23709,7 +23771,7 @@ async function buildSubjectReference(referenceImages) {
23709
23771
  }
23710
23772
  return subjectReference;
23711
23773
  }
23712
- async function extractImageFromResponse4(result, fetchFn = fetch) {
23774
+ async function extractImageFromResponse4(result, fetchFn = fetch, timeoutMs = PROVIDER_REQUEST_TIMEOUT_MS) {
23713
23775
  const baseResp = result.base_resp;
23714
23776
  if (baseResp?.status_code !== undefined && baseResp.status_code !== 0) {
23715
23777
  throw new Error(baseResp.status_msg ?? `MiniMax API returned status_code=${baseResp.status_code}`);
@@ -23719,7 +23781,7 @@ async function extractImageFromResponse4(result, fetchFn = fetch) {
23719
23781
  return Uint8Array.from(Buffer7.from(base64Image, "base64"));
23720
23782
  const url2 = result.data?.image_urls?.[0];
23721
23783
  if (url2 !== undefined) {
23722
- const response = await fetchFn(url2);
23784
+ const response = await fetchFn(url2, { signal: AbortSignal.timeout(timeoutMs) });
23723
23785
  if (!response.ok)
23724
23786
  throw new Error(`Failed to download image from MiniMax: ${response.status}`);
23725
23787
  return new Uint8Array(await response.arrayBuffer());
@@ -23728,6 +23790,7 @@ async function extractImageFromResponse4(result, fetchFn = fetch) {
23728
23790
  }
23729
23791
  var createMinimax = (options) => {
23730
23792
  const fetchFn = options?.fetch ?? fetch;
23793
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
23731
23794
  const env = options?.env ?? process.env;
23732
23795
  const readEnv = (key) => env[key] ?? "";
23733
23796
  return {
@@ -23751,12 +23814,13 @@ var createMinimax = (options) => {
23751
23814
  const response = await fetchFn(url2, {
23752
23815
  method: "POST",
23753
23816
  headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
23754
- body: JSON.stringify(body)
23817
+ body: JSON.stringify(body),
23818
+ signal: AbortSignal.timeout(timeoutMs)
23755
23819
  });
23756
23820
  if (!response.ok) {
23757
23821
  throw new Error(`MiniMax API error (${response.status}): ${await response.text()}`);
23758
23822
  }
23759
- const bytes = await extractImageFromResponse4(await response.json(), fetchFn);
23823
+ const bytes = await extractImageFromResponse4(await response.json(), fetchFn, timeoutMs);
23760
23824
  return { bytes, extension: "jpg", provider: "minimax", model: req.model };
23761
23825
  }
23762
23826
  };
@@ -23877,25 +23941,25 @@ function decodeDataUrl(value) {
23877
23941
  return null;
23878
23942
  return Uint8Array.from(Buffer8.from(match[1], "base64"));
23879
23943
  }
23880
- async function downloadImage(value, fetchFn) {
23944
+ async function downloadImage(value, fetchFn, timeoutMs = PROVIDER_REQUEST_TIMEOUT_MS) {
23881
23945
  const inline = decodeDataUrl(value);
23882
23946
  if (inline !== null)
23883
23947
  return inline;
23884
23948
  if (value.startsWith("http://") || value.startsWith("https://")) {
23885
- const response = await fetchFn(value);
23949
+ const response = await fetchFn(value, { signal: AbortSignal.timeout(timeoutMs) });
23886
23950
  if (!response.ok)
23887
23951
  throw new Error(`Failed to download OpenRouter image: ${response.status}`);
23888
23952
  return new Uint8Array(await response.arrayBuffer());
23889
23953
  }
23890
23954
  return Uint8Array.from(Buffer8.from(value, "base64"));
23891
23955
  }
23892
- async function extractImageFromResponse5(result, fetchFn = fetch) {
23956
+ async function extractImageFromResponse5(result, fetchFn = fetch, timeoutMs = PROVIDER_REQUEST_TIMEOUT_MS) {
23893
23957
  const choice = result.choices?.[0];
23894
23958
  const message = choice?.message;
23895
23959
  for (const image of message?.images ?? []) {
23896
23960
  const imageUrl = extractImageUrl(image);
23897
23961
  if (imageUrl !== null)
23898
- return downloadImage(imageUrl, fetchFn);
23962
+ return downloadImage(imageUrl, fetchFn, timeoutMs);
23899
23963
  }
23900
23964
  if (Array.isArray(message?.content)) {
23901
23965
  for (const item of message.content) {
@@ -23938,6 +24002,7 @@ function buildRequestBody2(prompt, model, req, referenceImages) {
23938
24002
  }
23939
24003
  var createOpenrouter = (options) => {
23940
24004
  const fetchFn = options?.fetch ?? fetch;
24005
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
23941
24006
  const env = options?.env ?? process.env;
23942
24007
  const readEnv = (key) => env[key] ?? "";
23943
24008
  return {
@@ -23970,12 +24035,13 @@ var createOpenrouter = (options) => {
23970
24035
  const response = await fetchFn(`${base}/chat/completions`, {
23971
24036
  method: "POST",
23972
24037
  headers,
23973
- body: JSON.stringify(body)
24038
+ body: JSON.stringify(body),
24039
+ signal: AbortSignal.timeout(timeoutMs)
23974
24040
  });
23975
24041
  if (!response.ok) {
23976
24042
  throw new Error(`OpenRouter API error (${response.status}): ${await response.text()}`);
23977
24043
  }
23978
- const bytes = await extractImageFromResponse5(await response.json(), fetchFn);
24044
+ const bytes = await extractImageFromResponse5(await response.json(), fetchFn, timeoutMs);
23979
24045
  return { bytes, extension: "png", provider: "openrouter", model: req.model };
23980
24046
  }
23981
24047
  };
@@ -24146,9 +24212,10 @@ function extractOutputUrl(prediction) {
24146
24212
  var createReplicate = (options) => {
24147
24213
  const fetchFn = options?.fetch ?? fetch;
24148
24214
  const env = options?.env ?? process.env;
24215
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
24149
24216
  const readEnv = (key) => env[key] ?? "";
24150
24217
  async function downloadImage2(url2) {
24151
- const res = await fetchFn(url2);
24218
+ const res = await fetchFn(url2, { signal: AbortSignal.timeout(timeoutMs) });
24152
24219
  if (!res.ok)
24153
24220
  throw new Error(`Failed to download image from Replicate: ${res.status}`);
24154
24221
  return new Uint8Array(await res.arrayBuffer());
@@ -24156,7 +24223,10 @@ var createReplicate = (options) => {
24156
24223
  async function pollPrediction(apiToken, getUrl) {
24157
24224
  const start = Date.now();
24158
24225
  while (Date.now() - start < MAX_POLL_MS) {
24159
- const res = await fetchFn(getUrl, { headers: { authorization: `Bearer ${apiToken}` } });
24226
+ const res = await fetchFn(getUrl, {
24227
+ headers: { authorization: `Bearer ${apiToken}` },
24228
+ signal: AbortSignal.timeout(timeoutMs)
24229
+ });
24160
24230
  if (!res.ok)
24161
24231
  throw new Error(`Replicate poll error (${res.status}): ${await res.text()}`);
24162
24232
  const prediction = await res.json();
@@ -24195,7 +24265,12 @@ var createReplicate = (options) => {
24195
24265
  "content-type": "application/json",
24196
24266
  Prefer: `wait=${SYNC_WAIT_SECONDS}`
24197
24267
  };
24198
- let prediction = await (await fetchFn(url2, { method: "POST", headers, body: JSON.stringify(body) })).json();
24268
+ let prediction = await (await fetchFn(url2, {
24269
+ method: "POST",
24270
+ headers,
24271
+ body: JSON.stringify(body),
24272
+ signal: AbortSignal.timeout(timeoutMs)
24273
+ })).json();
24199
24274
  if (prediction.status !== "succeeded") {
24200
24275
  if (prediction.urls?.get === undefined)
24201
24276
  throw new Error("Replicate prediction did not return a poll URL");
@@ -24354,6 +24429,7 @@ function resolveSizeForModel2(model, args) {
24354
24429
  }
24355
24430
  var createZai = (options) => {
24356
24431
  const fetchFn = options?.fetch ?? fetch;
24432
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
24357
24433
  const env = options?.env ?? process.env;
24358
24434
  const readEnv = (key) => env[key] ?? "";
24359
24435
  return {
@@ -24388,14 +24464,15 @@ var createZai = (options) => {
24388
24464
  prompt: req.prompt,
24389
24465
  quality: req.quality === "normal" ? "standard" : "hd",
24390
24466
  size
24391
- })
24467
+ }),
24468
+ signal: AbortSignal.timeout(timeoutMs)
24392
24469
  });
24393
24470
  if (!response.ok)
24394
24471
  throw new Error(`Z.AI API error (${response.status}): ${await response.text()}`);
24395
24472
  const url2 = (await response.json()).data?.[0]?.url;
24396
24473
  if (url2 === undefined)
24397
24474
  throw new Error("No image URL in Z.AI response");
24398
- const imageResponse = await fetchFn(url2);
24475
+ const imageResponse = await fetchFn(url2, { signal: AbortSignal.timeout(timeoutMs) });
24399
24476
  if (!imageResponse.ok)
24400
24477
  throw new Error(`Failed to download image from Z.AI: ${imageResponse.status}`);
24401
24478
  return {
@@ -24801,6 +24878,7 @@ export {
24801
24878
  composePrompt,
24802
24879
  artifactPath,
24803
24880
  StylePresetSchema,
24881
+ PROVIDER_REQUEST_TIMEOUT_MS,
24804
24882
  PROVIDERS,
24805
24883
  ImageJobSpecSchema,
24806
24884
  IMAGE_JOBS,
@@ -1,5 +1,5 @@
1
1
  import { homedir } from 'node:os';
2
- import { join } from 'node:path';
2
+ import { delimiter, join } from 'node:path';
3
3
  import { createNodeFileSystem } from '@gobing-ai/ts-runtime';
4
4
  import { z } from 'zod';
5
5
 
@@ -266,7 +266,7 @@ export function resolvePresetRoots(): string[] {
266
266
  if (isDirectory(projectRoot)) {
267
267
  roots.push(projectRoot);
268
268
  }
269
- for (const entry of process.env.KK_IMAGE_PRESET_PATH?.split(':') ?? []) {
269
+ for (const entry of process.env.KK_IMAGE_PRESET_PATH?.split(delimiter).filter((p) => p !== '') ?? []) {
270
270
  if (entry !== '' && isDirectory(entry)) {
271
271
  roots.push(entry);
272
272
  }
@@ -1,6 +1,7 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { refToDataUri } from './refs';
3
3
  import { extensionFromUrl } from './seedream';
4
+ import { PROVIDER_REQUEST_TIMEOUT_MS } from './timeouts';
4
5
  import type { ImageProvider, ImageRequest, ImageResult, ProviderFactory, ProviderOptions } from './types';
5
6
 
6
7
  /**
@@ -61,13 +62,14 @@ export function buildRequestBody(
61
62
  export async function extractImageFromResponse(
62
63
  result: AgnesResponse,
63
64
  fetchFn: typeof fetch = fetch,
65
+ timeoutMs: number = PROVIDER_REQUEST_TIMEOUT_MS,
64
66
  ): Promise<Uint8Array> {
65
67
  const img = result.data[0];
66
68
  if (img?.b64_json !== undefined && img.b64_json !== '') {
67
69
  return Uint8Array.from(Buffer.from(img.b64_json, 'base64'));
68
70
  }
69
71
  if (img?.url !== undefined) {
70
- const imgRes = await fetchFn(img.url);
72
+ const imgRes = await fetchFn(img.url, { signal: AbortSignal.timeout(timeoutMs) });
71
73
  if (!imgRes.ok) throw new Error(`Failed to download image from Agnes: ${imgRes.status}`);
72
74
  return new Uint8Array(await imgRes.arrayBuffer());
73
75
  }
@@ -76,6 +78,7 @@ export async function extractImageFromResponse(
76
78
 
77
79
  export const createAgnes: ProviderFactory = (options?: ProviderOptions): ImageProvider => {
78
80
  const fetchFn = options?.fetch ?? fetch;
81
+ const timeoutMs = options?.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS;
79
82
  const env = options?.env ?? process.env;
80
83
  const readEnv = (key: string): string => env[key] ?? '';
81
84
 
@@ -94,10 +97,11 @@ export const createAgnes: ProviderFactory = (options?: ProviderOptions): ImagePr
94
97
  method: 'POST',
95
98
  headers: { 'content-type': 'application/json', authorization: `Bearer ${apiKey}` },
96
99
  body: JSON.stringify(body),
100
+ signal: AbortSignal.timeout(timeoutMs),
97
101
  });
98
102
  if (!res.ok) throw new Error(`Agnes API error (${res.status}): ${await res.text()}`);
99
103
  const result = (await res.json()) as AgnesResponse;
100
- const bytes = await extractImageFromResponse(result, fetchFn);
104
+ const bytes = await extractImageFromResponse(result, fetchFn, timeoutMs);
101
105
  const url = result.data[0]?.url;
102
106
  return {
103
107
  bytes,