dsh-xdpool 3.0.8 → 3.0.9

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.
@@ -31514,7 +31514,7 @@ function parseModelInfo(m, seen) {
31514
31514
  if (Number.isFinite(cw) && cw > 0) out.contextWindow = cw;
31515
31515
  const mt = Number(m["max_tokens"]);
31516
31516
  if (Number.isFinite(mt) && mt > 0) out.maxTokens = mt;
31517
- if (m["supports_images"] === true) out.supportsImages = true;
31517
+ if (typeof m["supports_images"] === "boolean") out.supportsImages = m["supports_images"];
31518
31518
  return out;
31519
31519
  }
31520
31520
  function extractJsonArray(text, path2) {
@@ -32969,6 +32969,7 @@ function contextWindowFor(model, remote) {
32969
32969
  }
32970
32970
  /** Input modalities for one id; text is the floor every model here meets. */
32971
32971
  function modalitiesFor(model, remoteSupportsImages) {
32972
+ if (remoteSupportsImages === false) return ["text"];
32972
32973
  if (remoteSupportsImages === true) return ["text", "image"];
32973
32974
  var key = String(model).toLowerCase();
32974
32975
  if (IMAGE_MODELS.has(key)) return ["text", "image"];
@@ -32981,41 +32982,7 @@ function contentToText(content) {
32981
32982
  if (!Array.isArray(content)) return "";
32982
32983
  return content.filter((block) => typeof block === "object" && block !== null && block.type === "text").map((block) => String(block.text)).join("");
32983
32984
  }
32984
- // [xdpool-local] issue #215: CodeArts 通道声明支持 image,但旧实现只序列化文本,
32985
- // 图片块被静默丢弃。给本地序列化函数补可选的 imageUrls 参数(与同文件其它
32986
- // openai-compat 适配器一致):不传时行为与原来完全相同。
32987
- function codeArtsContentParts(content, imageUrls) {
32988
- const parts = [];
32989
- let hasImage = false;
32990
- for (const raw of content) {
32991
- if (typeof raw !== "object" || raw === null) continue;
32992
- const block = raw;
32993
- if (block.type === "text") {
32994
- const text = String(block.text ?? "");
32995
- if (text.length > 0) parts.push({ type: "text", text });
32996
- continue;
32997
- }
32998
- if (block.type === "image") {
32999
- hasImage = true;
33000
- const url = block.attachment?.attachmentId === void 0 ? void 0 : imageUrls.get(String(block.attachment.attachmentId));
33001
- // 绝不静默丢图:读不到字节时也显式告知模型这里有张图。
33002
- parts.push(url === void 0 ? { type: "text", text: "[image unavailable]" } : { type: "image_url", image_url: { url } });
33003
- continue;
33004
- }
33005
- if (block.type === "tool-result" && Array.isArray(block.content)) {
33006
- const inner = codeArtsContentParts(block.content, imageUrls);
33007
- if (inner !== void 0) {
33008
- hasImage = true;
33009
- parts.push(...inner);
33010
- } else {
33011
- const text = contentToText(block.content);
33012
- if (text.length > 0) parts.push({ type: "text", text });
33013
- }
33014
- }
33015
- }
33016
- return hasImage && parts.length > 0 ? parts : void 0;
33017
- }
33018
- function serializeMessages(messages, imageUrls) {
32985
+ async function serializeMessages(messages, readImage) {
33019
32986
  const normalized = normalizeHarnessMessages(messages);
33020
32987
  const wire = [];
33021
32988
  const { keepCallIds, keepResultIds } = resolveToolPairing(normalized);
@@ -33050,14 +33017,24 @@ function serializeMessages(messages, imageUrls) {
33050
33017
  const content = Array.isArray(message2.content) ? message2.content : [];
33051
33018
  const toolResults = content.filter((block) => typeof block === "object" && block !== null && block.type === "tool-result");
33052
33019
  const text = contentToText(message2.content);
33053
- // [xdpool-local] issue #215: imageUrls 存在时优先发多模态 parts;老的文本路径不变。
33054
- const regular = content.filter((block) => !(typeof block === "object" && block !== null && block.type === "tool-result"));
33055
- const parts = imageUrls === void 0 ? void 0 : codeArtsContentParts(regular, imageUrls);
33056
- if (parts !== void 0) {
33020
+ const images = content.filter((block) => block?.type === "image");
33021
+ if (images.length > 0) {
33022
+ if (typeof readImage !== "function") throw new Error("codearts: image attachment bridge is unavailable");
33023
+ const parts = [];
33024
+ let imageBytes = 0;
33025
+ for (const block of content) {
33026
+ if (block.type === "text") parts.push({ type: "text", text: String(block.text) });
33027
+ if (block.type !== "image") continue;
33028
+ const image = await readImage(block.attachment);
33029
+ if (!image?.data?.length || !/^image\/(png|jpeg|webp|gif)$/.test(image.mediaType)) {
33030
+ throw new Error("codearts: invalid image attachment");
33031
+ }
33032
+ imageBytes += image.data.length;
33033
+ if (imageBytes > 20971520) throw new Error("codearts: image attachment budget exceeded");
33034
+ parts.push({ type: "image_url", image_url: { url: `data:${image.mediaType};base64,${Buffer.from(image.data).toString("base64")}` } });
33035
+ }
33057
33036
  wire.push({ role: "user", content: parts });
33058
- } else if (text.length > 0 || toolResults.length === 0) {
33059
- wire.push({ role: "user", content: text });
33060
- }
33037
+ } else if (text.length > 0 || toolResults.length === 0) wire.push({ role: "user", content: text });
33061
33038
  for (const result of toolResults) {
33062
33039
  if (!keepResultIds.has(String(result.toolCallId))) continue;
33063
33040
  let resultText = contentToText(result.content) || "(no output)";
@@ -33527,7 +33504,7 @@ var CodeArtsAdapter = class extends LlmAdapter {
33527
33504
  */
33528
33505
  listAllModels() {
33529
33506
  const source = this.remoteModels ?? DEFAULT_MODELS.map((id) => ({ id, name: id }));
33530
- return source.filter((m) => !/-VL-/i.test(m.id) && !/-VL$/i.test(m.id)).map((m) => ({ id: m.id, name: m.name }));
33507
+ return source.filter((m) => !/-VL-/i.test(m.id) && !/-VL$/i.test(m.id)).map((m) => ({ ...m }));
33531
33508
  }
33532
33509
  async listModels(_provider) {
33533
33510
  if (!await providerCatalogVisible(this.options.accountPool, PROVIDER)) return [];
@@ -33542,7 +33519,7 @@ var CodeArtsAdapter = class extends LlmAdapter {
33542
33519
  id: m.id,
33543
33520
  name: m.name,
33544
33521
  inputModalities: modalitiesFor(m.id, m.supportsImages),
33545
- maxTokens: CODEARTS_MAX_OUTPUT_TOKENS,
33522
+ maxTokens: Math.min(m.maxTokens ?? CODEARTS_MAX_OUTPUT_TOKENS, CODEARTS_MAX_OUTPUT_TOKENS),
33546
33523
  ...contextWindow === void 0 ? {} : { contextWindow }
33547
33524
  };
33548
33525
  });
@@ -33559,7 +33536,7 @@ var CodeArtsAdapter = class extends LlmAdapter {
33559
33536
  inputModalities: modalitiesFor(model, remoteModel?.supportsImages),
33560
33537
  // catalogFactsFor() forwards this as fact.maxTokens; without it the host
33561
33538
  // has no way to learn the ceiling and passes its own catalog value through.
33562
- defaultMaxTokens: remoteModel?.maxTokens ?? CODEARTS_MAX_OUTPUT_TOKENS
33539
+ defaultMaxTokens: Math.min(remoteModel?.maxTokens ?? CODEARTS_MAX_OUTPUT_TOKENS, CODEARTS_MAX_OUTPUT_TOKENS)
33563
33540
  };
33564
33541
  if (contextWindow !== void 0) resolved.context = { contextWindow };
33565
33542
  resolved.reasoning = {
@@ -33598,51 +33575,7 @@ var CodeArtsAdapter = class extends LlmAdapter {
33598
33575
  }
33599
33576
  if (currentAccountId) reportLedgerAccount(PROVIDER, currentAccountId);
33600
33577
  }
33601
- // [xdpool-local] issue #215: 照搬 loomy/gemini 的图片收集逻辑。
33602
- // 模型不支持图片 / readImage 缺失 / 字节读不到时都抛 LlmError,绝不静默丢图。
33603
- const imageRefs = /* @__PURE__ */ new Map();
33604
- for (const message2 of options.messages) {
33605
- if (Array.isArray(message2.content)) collectImages3(message2.content, imageRefs);
33606
- }
33607
- let imageUrls;
33608
- if (imageRefs.size > 0) {
33609
- if (!modalitiesFor(options.model).includes("image")) {
33610
- throw new LlmError2(
33611
- `codearts: \u6A21\u578B "${options.model}" \u4E0D\u652F\u6301\u56FE\u7247\u8F93\u5165`, "UNSUPPORTED_CONTENT"
33612
- );
33613
- }
33614
- if (this.options.readImage === void 0) {
33615
- throw new LlmError2(
33616
- "codearts: \u56FE\u7247\u8F93\u5165\u9700\u8981\u9644\u4EF6\u670D\u52A1\uFF08readImage \u672A\u63D0\u4F9B\uFF09",
33617
- "UNSUPPORTED_CONTENT"
33618
- ); }
33619
- imageUrls = /* @__PURE__ */ new Map();
33620
- const readImage = this.options.readImage;
33621
- for (const [id, ref] of imageRefs) {
33622
- let image;
33623
- try {
33624
- const projected = await projectRequestImage(ref, {
33625
- readImageRequest: this.options.readImageRequest,
33626
- pixelBudget: this.options.imagePixelBudget,
33627
- maxBytes: this.options.imageMaxBytes
33628
- });
33629
- image = projected ?? await readImage(ref);
33630
- } catch (error) {
33631
- throw new LlmError2(
33632
- "codearts: \u56FE\u7247\u9644\u4EF6\u8BFB\u53D6\u5931\u8D25\uFF1B\u9644\u4EF6\u670D\u52A1\u53EF\u80FD\u672A\u5C31\u7EEA\uFF0C\u6216\u8BE5\u5BF9\u8C61\u5DF2\u4E0D\u5B58\u5728\u3002",
33633
- "UNSUPPORTED_CONTENT",
33634
- { cause: error }
33635
- );
33636
- }
33637
- if (image === void 0) {
33638
- throw new LlmError2(
33639
- "codearts: \u56FE\u7247\u9644\u4EF6\u8BFB\u53D6\u4E0D\u5230\u5185\u5BB9\uFF1B\u9644\u4EF6\u670D\u52A1\u53EF\u80FD\u672A\u5C31\u7EEA\u3002",
33640
- "UNSUPPORTED_CONTENT"
33641
- );
33642
- } imageUrls.set(id, `data:${image.mediaType};base64,${Buffer.from(image.data).toString("base64")}`);
33643
- }
33644
- }
33645
- const messages = serializeMessages(options.messages, imageUrls);
33578
+ const messages = await serializeMessages(options.messages, this.options.readImage);
33646
33579
  if (options.system !== void 0 && options.system.length > 0) {
33647
33580
  messages.unshift({ role: "system", content: options.system });
33648
33581
  }
@@ -33690,7 +33623,7 @@ var CodeArtsAdapter = class extends LlmAdapter {
33690
33623
  // 因此这是上限而不只是默认值:调用方传来的更大值(宿主模型目录里别的
33691
33624
  // provider 带 384000)会被原样发出并触发 INVALID_REQUEST,必须收回;
33692
33625
  // 调用方主动设的较小值保留。
33693
- max_tokens: Math.min(options.maxTokens ?? CODEARTS_MAX_OUTPUT_TOKENS, CODEARTS_MAX_OUTPUT_TOKENS),
33626
+ max_tokens: Math.min(options.maxTokens ?? CODEARTS_MAX_OUTPUT_TOKENS, CODEARTS_MAX_OUTPUT_TOKENS, this.remoteModels?.find((m) => m.id === options.model)?.maxTokens ?? CODEARTS_MAX_OUTPUT_TOKENS),
33694
33627
  ...wireTools !== void 0 && wireTools.length > 0 ? { tools: wireTools } : {}
33695
33628
  });
33696
33629
  const url = `${CHAT_API_BASE}/chat/completions`;
@@ -68893,7 +68826,10 @@ var OPENCODE_CATALOG_TIMEOUT_MS = 8e3;
68893
68826
  var name = "codearts-auth";
68894
68827
  var inject = ["credentials", "commands", "llm"];
68895
68828
  var Config = Schema2.object({
68896
- providers: Schema2.dict(Schema2.any()).default({}).volatile()
68829
+ providers: (() => {
68830
+ const schema = Schema2.dict(Schema2.any()).default({});
68831
+ return typeof schema.volatile === "function" ? schema.volatile() : schema;
68832
+ })()
68897
68833
  });
68898
68834
  function registerProviderSettings(ctx, ...namespaces) {
68899
68835
  const settings = settingsOf(ctx);
@@ -69181,6 +69117,7 @@ function apply(ctx, config = {}) {
69181
69117
  ctx.logger.warn(`[channel-pack] \u6E05\u7406 WorkBuddy \u65E7\u7248\u8D26\u53F7\u5931\u8D25\uFF1A${String(error)}`);
69182
69118
  });
69183
69119
  const codearts = registerCodeArtsLlm(ctx, {
69120
+ readImage: makeReadImage(ctx),
69184
69121
  credentialRef: credentialRef16(CODEARTS_CREDENTIAL_REF),
69185
69122
  resolveCredential: async () => {
69186
69123
  const available2 = await pool.getAvailableAccount("codearts", "");