dsh-agent-sdk-bridge 1.1.6 → 1.1.8

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/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { CONTEXT_WINDOW_EXCEEDED_CODE, EMPTY_RESPONSE_CODE, LlmAdapter, LlmError, QUOTA_EXCEEDED_CODE, ReasoningEffortId, ToolCallId, fileHandleText, isContextWindowExceededError, isQuotaExceededError, offloadedImageText, textOnlyImageText } from "@deepseek-ai/dsh-llm";
2
+ import { CONTEXT_WINDOW_EXCEEDED_CODE, EMPTY_RESPONSE_CODE, LlmAdapter, LlmError, QUOTA_EXCEEDED_CODE, ReasoningEffortId, ToolCallId, fileHandleText, isContextWindowExceededError, isQuotaExceededError, offloadedImageText, requestImageHandleText, textOnlyImageText } from "@deepseek-ai/dsh-llm";
3
3
  import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { homedir, tmpdir } from "node:os";
5
5
  import * as path from "node:path";
@@ -264,8 +264,8 @@ function readLive(value, fallback) {
264
264
  * Resolve one {@link Live} option that may legitimately be undefined.
265
265
  *
266
266
  * Separate from {@link readLive} because an option whose "unset" state is
267
- * itself meaningful (`defaultReasoningEffort`: empty means "follow upstream")
268
- * has no fallback to apply.
267
+ * itself meaningful (`defaultReasoningEffort`: empty means "use the model's
268
+ * strongest level") has no fallback to apply.
269
269
  *
270
270
  * @param value - the plain value or thunk, possibly undefined.
271
271
  * @returns the option's current value, or undefined when it is unset.
@@ -668,6 +668,19 @@ var QoderModelCatalog = class {
668
668
  return officialOnly((this.cached ?? sharedSnapshots.get(this.brand))?.models ?? []);
669
669
  }
670
670
  }
671
+ /**
672
+ * The last successful live list, without fetching.
673
+ *
674
+ * The model picker resolves a route on every switch, and a switch must not
675
+ * wait on a CLI cold start (up to the fetch timeout). Callers that need an
676
+ * immediate answer read this and let {@link liveModels} refresh behind them;
677
+ * `undefined` means nothing has been read yet, which only the first switch
678
+ * has to wait for.
679
+ */
680
+ snapshot() {
681
+ const cached = this.cached ?? sharedSnapshots.get(this.brand);
682
+ return cached === void 0 ? void 0 : officialOnly(cached.models);
683
+ }
671
684
  /** Why the last refresh failed, or undefined when it succeeded. */
672
685
  get error() {
673
686
  return this.failure;
@@ -765,6 +778,41 @@ function withTimeout$2(promise, ms) {
765
778
  });
766
779
  }
767
780
  //#endregion
781
+ //#region src/model-cache.ts
782
+ /**
783
+ * Cache-first catalogue reads for the model picker.
784
+ *
785
+ * The harness resolves a route every time the user switches model or reasoning
786
+ * level, and each of the three providers answers that resolution from a
787
+ * catalogue whose fetch is expensive: Qoder cold-starts its CLI (up to the
788
+ * fetch timeout), CodeBuddy boots a process, MiniMax probes over ACP. Awaiting
789
+ * that fetch inside a resolution made the picker freeze for seconds whenever
790
+ * the cache had just expired.
791
+ *
792
+ * So a resolution reads the last successful snapshot when there is one and lets
793
+ * the catalogue refresh behind it; only the very first resolution, where there
794
+ * is nothing to show, waits. A snapshot that is merely stale still describes
795
+ * the same account's models, so answering from it is no less correct than the
796
+ * previous behaviour of answering from a failed fetch's fallback.
797
+ *
798
+ * @module dsh-agent-sdk-bridge/model-cache
799
+ */
800
+ /**
801
+ * The cached list when one exists, otherwise the awaited fetch.
802
+ *
803
+ * @param snapshot - last successful catalogue, or undefined before the first.
804
+ * @param fetch - the catalogue's normal (TTL-aware, in-flight-sharing) read.
805
+ * @returns the entries to resolve against, never empty-by-surprise when a
806
+ * snapshot exists.
807
+ */
808
+ async function cachedModels(snapshot, fetch) {
809
+ if (snapshot !== void 0 && snapshot.length > 0) {
810
+ fetch().catch(() => void 0);
811
+ return snapshot;
812
+ }
813
+ return fetch();
814
+ }
815
+ //#endregion
768
816
  //#region src/tokens.ts
769
817
  /**
770
818
  * Script-aware text pricing, shared by the input and output estimators.
@@ -917,6 +965,22 @@ var TurnOutputAccounting = class {
917
965
  * @module dsh-llm-qoder/render
918
966
  */
919
967
  /**
968
+ * Model-facing handle for one image.
969
+ *
970
+ * The host's native adapters use the same text: it names the attachment, its
971
+ * pixel size and media type, and the read-only normalized copy on disk, and it
972
+ * tells the model to copy that file to a writable path before editing. Pixels
973
+ * alone let a model describe an image but not process it — without this path
974
+ * the model goes looking through the workspace for a file that was never there.
975
+ */
976
+ function imageRefText(ref, path) {
977
+ if (path === void 0) return `[图片附件 ${String(ref.attachmentId)}(${ref.width}×${ref.height}px,${ref.mediaType})]`;
978
+ return requestImageHandleText(ref, {
979
+ width: ref.width,
980
+ height: ref.height
981
+ }, { readonlyPath: path });
982
+ }
983
+ /**
920
984
  * Image references in block order, skipping occurrences the surface already
921
985
  * offloaded: an offload is a durable fact the harness renders as path-bearing
922
986
  * placeholder text on every route, so re-sending those pixels would undo it.
@@ -927,7 +991,7 @@ function imageRefs(blocks) {
927
991
  return refs;
928
992
  }
929
993
  /** Render one content-block list as plain text; non-text blocks get handles. */
930
- function renderBlocks(blocks) {
994
+ function renderBlocks(blocks, imagePath) {
931
995
  const parts = [];
932
996
  for (const block of blocks) switch (block.type) {
933
997
  case "text":
@@ -935,7 +999,7 @@ function renderBlocks(blocks) {
935
999
  break;
936
1000
  case "reasoning": break;
937
1001
  case "image":
938
- parts.push(block.offloaded === true ? offloadedImageText(block.attachment) : textOnlyImageText(block.attachment));
1002
+ parts.push(block.offloaded === true ? offloadedImageText(block.attachment) : imageRefText(block.attachment, imagePath?.(block.attachment)));
939
1003
  break;
940
1004
  case "file":
941
1005
  parts.push(fileHandleText(block.attachment, void 0));
@@ -967,8 +1031,8 @@ function roleTag(message) {
967
1031
  * Render one request message with its role tag. A request-only user input has
968
1032
  * no durable identity or source, so it reads exactly like a user message.
969
1033
  */
970
- function renderMessage(message) {
971
- return `[${roleTag(message)}] ${renderBlocks(message.content)}`;
1034
+ function renderMessage(message, imagePath) {
1035
+ return `[${roleTag(message)}] ${renderBlocks(message.content, imagePath)}`;
972
1036
  }
973
1037
  /** Preamble establishing the inner model's role as this agent's LLM backend. */
974
1038
  const BACKEND_ROLE = [
@@ -1066,9 +1130,13 @@ function feedImageRefs(feed) {
1066
1130
  return feed.filter((part) => part.type === "image").map((part) => part.attachment);
1067
1131
  }
1068
1132
  /** Flatten a feed back to text, replacing images with the harness handle text. */
1069
- function feedToText(feed) {
1133
+ function feedToText(feed, imagePath) {
1070
1134
  if (typeof feed === "string") return feed;
1071
- return feed.map((part) => part.type === "text" ? part.text : textOnlyImageText(part.attachment)).filter((text) => text.length > 0).join("\n\n");
1135
+ return feed.map((part) => {
1136
+ if (part.type === "text") return part.text;
1137
+ const path = imagePath?.(part.attachment);
1138
+ return path === void 0 ? textOnlyImageText(part.attachment) : imageRefText(part.attachment, path);
1139
+ }).filter((text) => text.length > 0).join("\n\n");
1072
1140
  }
1073
1141
  /**
1074
1142
  * Split a feed into text and resolved images for providers with a vision API.
@@ -1102,6 +1170,7 @@ function resolvedFeedParts(feed, images) {
1102
1170
  attachment: part.attachment
1103
1171
  } : {
1104
1172
  type: "image",
1173
+ attachment: part.attachment,
1105
1174
  data: resolved.data,
1106
1175
  mediaType: resolved.mediaType
1107
1176
  });
@@ -1128,12 +1197,12 @@ function feedWideCharCount(feed) {
1128
1197
  * prompt, and the existing conversation as compact context. Messages of the
1129
1198
  * current turn keep their image references; earlier ones are handles.
1130
1199
  */
1131
- function renderInitialFeed(system, messages) {
1200
+ function renderInitialFeed(system, messages, imagePath) {
1132
1201
  const from = currentTurnStart(messages);
1133
1202
  const history = [];
1134
1203
  for (const [index, message] of messages.entries()) {
1135
- const entry = index >= from && imageRefs(message.content).length > 0 ? label(`[${roleTag(message)}] `, blockParts(message.content)) : renderMessage(message);
1136
- if (feedToText(entry).length > 0) history.push(entry);
1204
+ const entry = index >= from && imageRefs(message.content).length > 0 ? label(`[${roleTag(message)}] `, blockParts(message.content)) : renderMessage(message, imagePath);
1205
+ if (feedToText(entry, imagePath).length > 0) history.push(entry);
1137
1206
  }
1138
1207
  const sections = [BACKEND_ROLE];
1139
1208
  if (system !== void 0 && system.length > 0) sections.push(`---- 宿主系统提示(作为你的行为准则) ----\n${system}`);
@@ -2762,6 +2831,8 @@ const QODER_INTL_PROVIDER = "qoder-intl";
2762
2831
  * actually runs with. `maxInputTokens` is NOT a substitute — it is the ceiling
2763
2832
  * for a single request and is often lower than the session window (e.g. 180 000
2764
2833
  * against a 200 000 session), so falling back to it would understate capacity.
2834
+ * Callers that accept a user override should validate it against
2835
+ * `availableContextWindows` first — see {@link resolveDeclaredWindow}.
2765
2836
  *
2766
2837
  * @param live - the live catalog entry, when the CLI answered.
2767
2838
  * @param override - the user's chosen window for this model, if any.
@@ -2800,6 +2871,24 @@ function cliContextWindow(live, declared) {
2800
2871
  if (available !== void 0 && available.includes(declared)) return declared;
2801
2872
  return live.defaultContextWindow ?? largestWindow(available) ?? live.maxInputTokens;
2802
2873
  }
2874
+ /**
2875
+ * The window to publish for one route, which is also the one the CLI is told
2876
+ * to run with.
2877
+ *
2878
+ * A live entry is authoritative: the user's override counts only when the
2879
+ * model advertises it. The CLI silently ignores anything else (a 1M choice on
2880
+ * a 200K-only route), and dividing by it would understate every reading
2881
+ * fivefold. When the catalog is momentarily unavailable, the last successful
2882
+ * answer is reused instead of the static 200K default — that fallback used to
2883
+ * change the denominator, and the compaction budget, mid-session: a 1M
2884
+ * conversation read 1M one turn and 200K the next, and then compacted at what
2885
+ * looked like 10%.
2886
+ */
2887
+ function resolveDeclaredWindow(live, override, remembered, fallback) {
2888
+ if (live === void 0) return remembered ?? override ?? fallback;
2889
+ const available = live.availableContextWindows;
2890
+ return pickContextWindow(live, override !== void 0 && (available === void 0 || available.length === 0 || available.includes(override)) ? override : void 0, remembered ?? fallback);
2891
+ }
2803
2892
  function modelInfo$2(provider, entry) {
2804
2893
  return {
2805
2894
  provider,
@@ -2828,22 +2917,72 @@ const EFFORT_NAMES = {
2828
2917
  max: "Max"
2829
2918
  };
2830
2919
  /**
2920
+ * Strength order used to pick a model's starting level.
2921
+ *
2922
+ * The three providers spell their levels differently (Qoder publishes
2923
+ * `low|medium|high|max`, MiniMax `low|high`, CodeBuddy whatever its catalog
2924
+ * declares), so the ranking is by name rather than by position in any one
2925
+ * upstream list. An id outside this table ranks below every known one, which is
2926
+ * what several sources agreeing on an unfamiliar spelling should do.
2927
+ */
2928
+ const EFFORT_ORDER = [
2929
+ "none",
2930
+ "minimal",
2931
+ "low",
2932
+ "medium",
2933
+ "high",
2934
+ "xhigh",
2935
+ "max"
2936
+ ];
2937
+ /**
2938
+ * The strongest level a model offers.
2939
+ *
2940
+ * Switching model or level must start at the most capable setting the route
2941
+ * accepts, the same rule the sibling adapter plugin uses; the previous
2942
+ * behaviour of following upstream's own default meant some models silently
2943
+ * started one or two steps down (`CodeBuddy` advertises `high` as its default
2944
+ * even when `max` is selectable).
2945
+ *
2946
+ * @param efforts - the levels the route accepts, in upstream order.
2947
+ * @returns the strongest id, or undefined for a non-reasoning model.
2948
+ */
2949
+ function strongestEffort(efforts) {
2950
+ if (efforts.length === 0) return void 0;
2951
+ let best;
2952
+ let bestRank = -1;
2953
+ for (const effort of efforts) {
2954
+ const rank = EFFORT_ORDER.indexOf(effort);
2955
+ if (best === void 0 || rank > bestRank) {
2956
+ best = effort;
2957
+ bestRank = rank;
2958
+ }
2959
+ }
2960
+ return best;
2961
+ }
2962
+ /**
2831
2963
  * Build the `reasoning` metadata block for a resolved model, or undefined
2832
2964
  * when the model does not support reasoning.
2965
+ *
2966
+ * The starting level is the strongest one the model accepts, not the level
2967
+ * upstream happens to name as its default: the user's explicit choice in the
2968
+ * sibling plugin, applied here too. An explicit configuration value still wins
2969
+ * when the model accepts it.
2970
+ *
2833
2971
  * @param efforts - CLI-reported effort ids (absent for reasoning-less models).
2834
- * @param defaultEffort - CLI-reported default effort id.
2972
+ * @param configuredEffort - user-configured starting level, when any.
2835
2973
  * @param isReasoning - whether the model supports reasoning per the CLI.
2836
2974
  * @returns the harness reasoning metadata, or undefined to omit it.
2837
2975
  */
2838
- function reasoningInfo(efforts, defaultEffort, isReasoning) {
2976
+ function reasoningInfo(efforts, configuredEffort, isReasoning) {
2839
2977
  if (efforts === void 0 && isReasoning === false) return void 0;
2840
2978
  const ids = efforts !== void 0 && efforts.length > 0 ? efforts : DEFAULT_REASONING_EFFORTS;
2979
+ const defaultEffort = configuredEffort !== void 0 && ids.includes(configuredEffort) ? configuredEffort : strongestEffort(ids);
2841
2980
  return {
2842
2981
  efforts: ids.map((id) => ({
2843
2982
  id: ReasoningEffortId(id),
2844
2983
  name: EFFORT_NAMES[id] ?? id
2845
2984
  })),
2846
- ...defaultEffort !== void 0 && ids.includes(defaultEffort) ? { defaultEffort: ReasoningEffortId(defaultEffort) } : {}
2985
+ ...defaultEffort === void 0 ? {} : { defaultEffort: ReasoningEffortId(defaultEffort) }
2847
2986
  };
2848
2987
  }
2849
2988
  /**
@@ -2863,6 +3002,7 @@ var QoderAdapter = class extends LlmAdapter {
2863
3002
  catalog;
2864
3003
  usage;
2865
3004
  readImage;
3005
+ imagePath;
2866
3006
  brand;
2867
3007
  /**
2868
3008
  * Memoized `Set` view of the disabled-model list.
@@ -2872,6 +3012,24 @@ var QoderAdapter = class extends LlmAdapter {
2872
3012
  * hash probe instead of rebuilding a set per call, with no staleness.
2873
3013
  */
2874
3014
  disabledCache;
3015
+ /**
3016
+ * The last window each route resolved to, plus what the model advertised.
3017
+ *
3018
+ * Reused only when a live entry is missing. Without it a failed refresh fell
3019
+ * back to the static 200K, so a 1M session suddenly declared 200K: the ring
3020
+ * denominator changed and the compaction engine budgeted against 200K,
3021
+ * compacting a history that was still only ~10% of the real window.
3022
+ */
3023
+ knownWindows = /* @__PURE__ */ new Map();
3024
+ /**
3025
+ * Last verified image capability per route.
3026
+ *
3027
+ * A missed catalog refresh used to fall back to text-only, and DSH then
3028
+ * stripped the pixels before this adapter ran: a vision model silently lost
3029
+ * the image for that turn. Remembering the last answer keeps the declared
3030
+ * capability stable across a transient miss.
3031
+ */
3032
+ knownVision = /* @__PURE__ */ new Map();
2875
3033
  constructor(options = {}) {
2876
3034
  super();
2877
3035
  this.options = options;
@@ -2885,6 +3043,7 @@ var QoderAdapter = class extends LlmAdapter {
2885
3043
  this.catalog = new QoderModelCatalog(this.brand, options.modelCacheTtlMs ?? 3e5, options.catalogFetchTimeoutMs ?? 2e4);
2886
3044
  this.usage = new QoderUsage(this.brand, options.usageCacheTtlMs);
2887
3045
  this.readImage = options.readImage;
3046
+ this.imagePath = options.imagePath;
2888
3047
  }
2889
3048
  get defaultMaxTokens() {
2890
3049
  return readLive(this.options.defaultMaxTokens, DEFAULT_MAX_TOKENS);
@@ -2948,7 +3107,12 @@ var QoderAdapter = class extends LlmAdapter {
2948
3107
  * @returns live catalog entries in upstream order.
2949
3108
  */
2950
3109
  async describeCatalog() {
2951
- return this.catalog.liveModels();
3110
+ const live = await this.catalog.liveModels();
3111
+ for (const entry of live) {
3112
+ this.declaredWindow(entry.value, entry);
3113
+ this.knownVision.set(entry.value, entry.isVl === true);
3114
+ }
3115
+ return live;
2952
3116
  }
2953
3117
  /** Forget the cached catalog; the next read asks the CLI again. */
2954
3118
  invalidateCatalog() {
@@ -2978,9 +3142,30 @@ var QoderAdapter = class extends LlmAdapter {
2978
3142
  disabledModelIds() {
2979
3143
  return [...this.disabledModels];
2980
3144
  }
2981
- /** The user's window for one model, or undefined when following upstream. */
3145
+ /**
3146
+ * The user's window for one model, when the provider accepts it.
3147
+ *
3148
+ * A stored choice the model does not advertise is not a real choice: the CLI
3149
+ * ignores it and keeps its own window, so publishing it would only make the
3150
+ * meter divide by a capacity the route never runs with. Until the catalog
3151
+ * has answered once the choice is trusted (there is nothing to check yet).
3152
+ */
2982
3153
  contextWindowFor(id) {
2983
- return this.windowOverride(id);
3154
+ const override = this.windowOverride(id);
3155
+ if (override === void 0) return void 0;
3156
+ const target = resolveQoderModelId(id, this.modelAliases);
3157
+ const available = this.knownWindows.get(target)?.available;
3158
+ if (available === void 0 || available.length === 0) return override;
3159
+ return available.includes(override) ? override : void 0;
3160
+ }
3161
+ /** The window this route publishes, remembering it for catalog misses. */
3162
+ declaredWindow(id, live) {
3163
+ const window = resolveDeclaredWindow(live, this.windowOverride(id), this.knownWindows.get(id)?.window, DEFAULT_CONTEXT_WINDOW);
3164
+ if (live !== void 0) this.knownWindows.set(id, {
3165
+ window,
3166
+ available: live.availableContextWindows
3167
+ });
3168
+ return window;
2984
3169
  }
2985
3170
  /** The stored per-model window map, for rewriting the field. */
2986
3171
  modelWindowChoices() {
@@ -2991,33 +3176,36 @@ var QoderAdapter = class extends LlmAdapter {
2991
3176
  }
2992
3177
  async resolveModel(provider, model, _signal) {
2993
3178
  const target = resolveQoderModelId(model, this.modelAliases);
2994
- const live = (await this.catalog.liveModels()).find((entry) => entry.value === target);
3179
+ const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels())).find((entry) => entry.value === target);
2995
3180
  if (live !== void 0) {
2996
- const reasoning = reasoningInfo(live.efforts, live.defaultEffort ?? this.defaultReasoningEffort, live.isReasoning);
3181
+ const vision = live.isVl === true;
3182
+ this.knownVision.set(target, vision);
3183
+ const reasoning = reasoningInfo(live.efforts, this.defaultReasoningEffort, live.isReasoning);
2997
3184
  return {
2998
3185
  provider,
2999
3186
  id: model,
3000
3187
  name: live.displayName.length > 0 ? live.displayName : live.value,
3001
3188
  ...live.description.length > 0 ? { description: live.description } : {},
3002
- inputModalities: live.isVl === true ? ["text", "image"] : ["text"],
3003
- context: { contextWindow: pickContextWindow(live, this.windowOverride(target), DEFAULT_CONTEXT_WINDOW) },
3189
+ inputModalities: vision ? ["text", "image"] : ["text"],
3190
+ context: { contextWindow: this.declaredWindow(target, live) },
3004
3191
  defaultMaxTokens: live.maxOutputTokens ?? this.defaultMaxTokens,
3005
3192
  ...reasoning === void 0 ? {} : { reasoning }
3006
3193
  };
3007
3194
  }
3008
3195
  const configured = brandProfile(this.brand).staticCatalog ? QODER_MODELS.find((entry) => entry.id === target) : void 0;
3009
3196
  const reasoning = reasoningInfo(void 0, this.defaultReasoningEffort, true);
3197
+ const rememberedVision = this.knownVision.get(target) === true;
3010
3198
  return Promise.resolve({
3011
3199
  ...configured === void 0 ? {
3012
3200
  provider,
3013
3201
  id: model,
3014
- name: model,
3015
- inputModalities: ["text"]
3202
+ name: model
3016
3203
  } : {
3017
3204
  ...modelInfo$2(provider, configured),
3018
3205
  id: model
3019
3206
  },
3020
- context: { contextWindow: this.windowOverride(target) ?? 2e5 },
3207
+ inputModalities: rememberedVision ? ["text", "image"] : ["text"],
3208
+ context: { contextWindow: this.declaredWindow(target, void 0) },
3021
3209
  defaultMaxTokens: this.defaultMaxTokens,
3022
3210
  ...reasoning === void 0 ? {} : { reasoning }
3023
3211
  });
@@ -3042,7 +3230,7 @@ var QoderAdapter = class extends LlmAdapter {
3042
3230
  async capture(provider, model, signal) {
3043
3231
  const info = await this.resolveModel(provider, model, signal);
3044
3232
  const target = resolveQoderModelId(model, this.modelAliases);
3045
- const live = (await this.catalog.liveModels()).find((entry) => entry.value === target);
3233
+ const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels())).find((entry) => entry.value === target);
3046
3234
  const declared = info.context?.contextWindow;
3047
3235
  return {
3048
3236
  info,
@@ -3053,7 +3241,7 @@ var QoderAdapter = class extends LlmAdapter {
3053
3241
  async *dispatch(options, generation) {
3054
3242
  const model = resolveQoderModelId(options.model, this.modelAliases);
3055
3243
  if (options.sessionId === void 0 || options.purpose !== void 0) {
3056
- const prompt = feedToText(renderInitialFeed(options.system, options.messages)) + "\n(这是一次性旁路请求,直接输出下一条助手回复。)";
3244
+ const prompt = feedToText(renderInitialFeed(options.system, options.messages, this.imagePath), this.imagePath) + "\n(这是一次性旁路请求,直接输出下一条助手回复。)";
3057
3245
  yield* this.sessions.coldStream(options, prompt, model);
3058
3246
  return;
3059
3247
  }
@@ -3085,7 +3273,7 @@ var QoderAdapter = class extends LlmAdapter {
3085
3273
  session.fedMessages = options.messages;
3086
3274
  session.fedSystem = options.system;
3087
3275
  const feed = plan.feed === null ? null : await this.buildFeed(plan.feed, generation.vision, images);
3088
- yield* session.stream(options, feed, plan.feed === null ? void 0 : feedToText(plan.feed));
3276
+ yield* session.stream(options, feed, plan.feed === null ? void 0 : feedToText(plan.feed, this.imagePath));
3089
3277
  }
3090
3278
  async *firstTurn(session, options, model, policy, vision) {
3091
3279
  session.setModel(model, policy);
@@ -3096,9 +3284,9 @@ var QoderAdapter = class extends LlmAdapter {
3096
3284
  session.recordRequestInput(options.system, options.messages);
3097
3285
  session.fedMessages = options.messages;
3098
3286
  session.fedSystem = options.system;
3099
- const feed = renderInitialFeed(options.system, options.messages);
3287
+ const feed = renderInitialFeed(options.system, options.messages, this.imagePath);
3100
3288
  const images = await this.resolveImages(feedImageRefs(feed), vision, options.signal);
3101
- yield* session.stream(options, await this.buildFeed(feed, vision, images), feedToText(feed));
3289
+ yield* session.stream(options, await this.buildFeed(feed, vision, images), feedToText(feed, this.imagePath));
3102
3290
  }
3103
3291
  /** Image references carried by a message tail, skipping assistant content. */
3104
3292
  async resolveTurnImages(tail, vision, signal) {
@@ -3130,7 +3318,7 @@ var QoderAdapter = class extends LlmAdapter {
3130
3318
  */
3131
3319
  async buildFeed(feed, vision, images) {
3132
3320
  if (typeof feed === "string") return feed;
3133
- if (!vision) return feedToText(feed);
3321
+ if (!vision) return feedToText(feed, this.imagePath);
3134
3322
  const content = [];
3135
3323
  let pixels = 0;
3136
3324
  for (const part of feed) {
@@ -3141,14 +3329,20 @@ var QoderAdapter = class extends LlmAdapter {
3141
3329
  });
3142
3330
  continue;
3143
3331
  }
3144
- const resolved = images.get(String(part.attachment.attachmentId));
3332
+ const key = String(part.attachment.attachmentId);
3333
+ const resolved = images.get(key);
3334
+ const path = this.imagePath?.(part.attachment);
3145
3335
  if (resolved === void 0) {
3146
3336
  content.push({
3147
3337
  type: "text",
3148
- text: `[图片附件 ${String(part.attachment.attachmentId)} 本次未能读取,请基于文字内容继续]`
3338
+ text: `[图片附件 ${key} 本次未能读取${path === void 0 ? "" : `;本机文件:${path}`},请基于文字内容继续]`
3149
3339
  });
3150
3340
  continue;
3151
3341
  }
3342
+ content.push({
3343
+ type: "text",
3344
+ text: imageRefText(part.attachment, path)
3345
+ });
3152
3346
  pixels += 1;
3153
3347
  content.push({
3154
3348
  type: "image",
@@ -3564,7 +3758,7 @@ var CodeBuddyCatalog = class {
3564
3758
  * context-budget choice) use this instead of awaiting a refresh.
3565
3759
  */
3566
3760
  snapshot(requested) {
3567
- return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models ?? [];
3761
+ return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models;
3568
3762
  }
3569
3763
  /** Models for one region; a failed refresh keeps the last good list. */
3570
3764
  async models(requested) {
@@ -4092,6 +4286,10 @@ var CodeBuddySession = class {
4092
4286
  effort;
4093
4287
  systemPrompt;
4094
4288
  cwd;
4289
+ /** Context budget the host shows for this session, when a model offers one. */
4290
+ contextWindow;
4291
+ /** Budget already pushed to the CLI, keyed by model and value. */
4292
+ appliedWindow;
4095
4293
  /** Host messages already fed to the inner session, for continuation planning. */
4096
4294
  fedMessages;
4097
4295
  /** Host system prompt last applied; informational for the adapter. */
@@ -4109,6 +4307,34 @@ var CodeBuddySession = class {
4109
4307
  this.effort = options.effort;
4110
4308
  this.systemPrompt = options.system;
4111
4309
  if (options.cwd !== void 0) this.cwd = options.cwd;
4310
+ if (options.contextWindow !== void 0) this.contextWindow = options.contextWindow;
4311
+ }
4312
+ /**
4313
+ * Push the host-visible context window into the inner session.
4314
+ *
4315
+ * The CLI resolves its own budget (`override > model default > physical
4316
+ * limit`) and both its compaction trigger and the upstream gateway enforce
4317
+ * that budget. A global-catalog model such as `deepseek-v4.1-flash` declares
4318
+ * `supportedLengths [300K, 1M]` with a 300K default, so a session left alone
4319
+ * compacts (and the gateway rejects) anything past 276K — while the host,
4320
+ * told 1M, keeps showing and feeding a larger history. Replaying that history
4321
+ * then collapses to a summary. Applying the same number the host divides by
4322
+ * keeps the two in step; models that expose no choice reject it and keep
4323
+ * their default.
4324
+ *
4325
+ * The CLI refuses to clear the override (`contextWindow must be a positive
4326
+ * safe integer`), so the adapter sends the model's default instead when the
4327
+ * page returns to "default".
4328
+ */
4329
+ async applyContextWindow(session) {
4330
+ const window = this.contextWindow;
4331
+ if (window === void 0) return;
4332
+ const key = `${this.model}:${window}`;
4333
+ if (this.appliedWindow === key) return;
4334
+ this.appliedWindow = key;
4335
+ try {
4336
+ await session.setConfig({ contextWindow: window });
4337
+ } catch {}
4112
4338
  }
4113
4339
  /**
4114
4340
  * Remember the host tools and register them with this session's MCP server.
@@ -4187,6 +4413,7 @@ var CodeBuddySession = class {
4187
4413
  signal?.addEventListener("abort", onAbort, { once: true });
4188
4414
  try {
4189
4415
  await session.setModel(this.model);
4416
+ await this.applyContextWindow(session);
4190
4417
  if (feed !== null && feed.length > 0) {
4191
4418
  const content = typeof feed === "string" ? feed : feed.filter((block) => block.type !== "text" || block.text.length > 0);
4192
4419
  if (content.length > 0) {
@@ -4778,6 +5005,8 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4778
5005
  accounts;
4779
5006
  auth = new CodeBuddyAuth();
4780
5007
  disabledCache = /* @__PURE__ */ new Map();
5008
+ /** Last verified image capability, keyed `${region}:${model}`. */
5009
+ knownVision = /* @__PURE__ */ new Map();
4781
5010
  constructor(options = {}) {
4782
5011
  super();
4783
5012
  this.options = options;
@@ -4818,7 +5047,9 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4818
5047
  /** The live catalog, unfiltered (the page must show switched-off models). */
4819
5048
  async describeCatalog(region = this.region) {
4820
5049
  if (!this.isSignedIn(region)) return [];
4821
- return this.catalog.models(region);
5050
+ const models = await this.catalog.models(region);
5051
+ for (const model of models) this.knownVision.set(`${region}:${model.id}`, model.vision);
5052
+ return models;
4822
5053
  }
4823
5054
  /** Whether the selected (or given) region has a stored login. */
4824
5055
  isSignedIn(region = this.region) {
@@ -4864,7 +5095,13 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4864
5095
  /** Whether the resolved model accepts images (drives whether pixels are sent). */
4865
5096
  async modelVision(model) {
4866
5097
  const target = resolveCodeBuddyModelId(model, this.aliases);
4867
- return (await this.catalog.models().catch(() => [])).find((entry) => entry.id === target)?.vision === true;
5098
+ const key = `${this.region}:${target}`;
5099
+ const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models())).find((entry) => entry.id === target);
5100
+ if (live !== void 0) {
5101
+ this.knownVision.set(key, live.vision);
5102
+ return live.vision;
5103
+ }
5104
+ return this.knownVision.get(key) === true;
4868
5105
  }
4869
5106
  /**
4870
5107
  * Resolve a feed's images into base64 for the CLI's vision blocks.
@@ -4899,7 +5136,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4899
5136
  */
4900
5137
  async buildFeed(feed, vision, signal) {
4901
5138
  if (typeof feed === "string") return feed;
4902
- if (!vision) return feedToText(feed);
5139
+ if (!vision) return feedToText(feed, this.options.imagePath);
4903
5140
  const parts = resolvedFeedParts(feed, await this.resolveFeedImages(feed, vision, signal));
4904
5141
  if (!parts.some((part) => part.type !== "text")) return parts.map((part) => part.type === "text" ? part.text : "").join("\n\n");
4905
5142
  const content = [];
@@ -4911,13 +5148,12 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4911
5148
  });
4912
5149
  continue;
4913
5150
  }
4914
- if (part.type === "image-unreadable") {
4915
- content.push({
4916
- type: "text",
4917
- text: textOnlyImageText(part.attachment)
4918
- });
4919
- continue;
4920
- }
5151
+ const path = this.options.imagePath?.(part.attachment);
5152
+ content.push({
5153
+ type: "text",
5154
+ text: part.type === "image-unreadable" && path === void 0 ? `[图片附件 ${String(part.attachment.attachmentId)} 本次未能读取,请基于文字内容继续]` : imageRefText(part.attachment, path)
5155
+ });
5156
+ if (part.type === "image-unreadable") continue;
4921
5157
  content.push({
4922
5158
  type: "image",
4923
5159
  source: {
@@ -4947,7 +5183,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4947
5183
  }
4948
5184
  /** The catalog snapshot the adapter last read (empty before the first read). */
4949
5185
  models(region) {
4950
- return this.catalog.snapshot(region);
5186
+ return this.catalog.snapshot(region) ?? [];
4951
5187
  }
4952
5188
  /** Whether this model lets the user pick a context budget at all. */
4953
5189
  supportsContextWindowChoice(id, region = this.region) {
@@ -4963,9 +5199,11 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4963
5199
  }
4964
5200
  async resolveModel(provider, model) {
4965
5201
  const target = resolveCodeBuddyModelId(model, this.aliases);
4966
- const live = (await this.catalog.models()).find((entry) => entry.id === target);
5202
+ const key = `${this.region}:${target}`;
5203
+ const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models())).find((entry) => entry.id === target);
4967
5204
  if (live !== void 0) {
4968
- const reasoning = reasoningInfo(live.reasoningEfforts, live.defaultEffort, (live.reasoningEfforts?.length ?? 0) > 0);
5205
+ this.knownVision.set(key, live.vision);
5206
+ const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), (live.reasoningEfforts?.length ?? 0) > 0);
4969
5207
  return {
4970
5208
  provider,
4971
5209
  id: model,
@@ -4982,7 +5220,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4982
5220
  provider,
4983
5221
  id: model,
4984
5222
  name: model,
4985
- inputModalities: ["text"],
5223
+ inputModalities: this.knownVision.get(key) === true ? ["text", "image"] : ["text"],
4986
5224
  context: { contextWindow: this.contextWindowFor(target) ?? 2e5 },
4987
5225
  defaultMaxTokens: readLive(this.options.defaultMaxTokens, CODEBUDDY_DEFAULT_MAX_TOKENS),
4988
5226
  ...reasoning === void 0 ? {} : { reasoning }
@@ -5002,7 +5240,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
5002
5240
  if (!this.isSignedIn(region)) throw new Error(`${region === "cn" ? "CodeBuddy 国内版" : "CodeBuddy 国际版"}尚未登录,请先在设置 → CodeBuddy 中登录。`);
5003
5241
  const model = resolveCodeBuddyModelId(options.model, this.aliases);
5004
5242
  if (options.sessionId === void 0 || options.purpose !== void 0) {
5005
- const prompt = feedToText(renderInitialFeed(options.system, options.messages)) + "\n(这是一次性旁路请求,直接输出下一条助手回复。)";
5243
+ const prompt = feedToText(renderInitialFeed(options.system, options.messages, this.options.imagePath), this.options.imagePath) + "\n(这是一次性旁路请求,直接输出下一条助手回复。)";
5006
5244
  for (const chunk of await codeBuddyColdStream(region, prompt, model, options)) yield chunk;
5007
5245
  return;
5008
5246
  }
@@ -5025,7 +5263,8 @@ var CodeBuddyAdapter = class extends LlmAdapter {
5025
5263
  session.configure(region, model, {
5026
5264
  effort,
5027
5265
  system: options.system,
5028
- cwd: this.cwdOf(options)
5266
+ cwd: this.cwdOf(options),
5267
+ ...await this.windowOption(model)
5029
5268
  });
5030
5269
  session.ensureTools(options.tools ?? []);
5031
5270
  session.fedMessages = options.messages;
@@ -5038,15 +5277,33 @@ var CodeBuddyAdapter = class extends LlmAdapter {
5038
5277
  session.configure(region, model, {
5039
5278
  effort,
5040
5279
  system: options.system,
5041
- cwd: this.cwdOf(options)
5280
+ cwd: this.cwdOf(options),
5281
+ ...await this.windowOption(model)
5042
5282
  });
5043
5283
  session.ensureTools(options.tools ?? []);
5044
5284
  session.fedMessages = options.messages;
5045
5285
  session.fedSystem = options.system;
5046
5286
  const vision = await this.modelVision(options.model);
5047
- const feed = await this.buildFeed(renderInitialFeed(void 0, options.messages), vision, options.signal);
5287
+ const feed = await this.buildFeed(renderInitialFeed(void 0, options.messages, this.options.imagePath), vision, options.signal);
5048
5288
  yield* session.stream(options, feed);
5049
5289
  }
5290
+ /**
5291
+ * The context window the host and the inner session must agree on.
5292
+ *
5293
+ * Only a model that offers selectable budgets is configured: one fixed
5294
+ * window rejects every value, so the CLI's own default already matches what
5295
+ * the host shows. For a model with choices the adapter sends the picked
5296
+ * value; returning to "default" sends the model's own default budget, since
5297
+ * the CLI rejects a null clear (`contextWindow must be a positive safe
5298
+ * integer`). The override lives for the life of the CLI process, so the
5299
+ * default has to be sent explicitly to drop a previous choice.
5300
+ */
5301
+ async windowOption(model) {
5302
+ const live = (await this.catalog.models(this.region)).find((entry) => entry.id === model);
5303
+ if (live === void 0 || live.contextWindows.length === 0) return {};
5304
+ const chosen = this.options.modelContextWindows?.(this.region)[model];
5305
+ return { contextWindow: chosen !== void 0 && live.contextWindows.includes(chosen) ? chosen : live.defaultContextWindow };
5306
+ }
5050
5307
  cwdOf(options) {
5051
5308
  return options.cwd;
5052
5309
  }
@@ -6487,6 +6744,15 @@ var MinimaxCatalog = class {
6487
6744
  return cached?.models ?? [];
6488
6745
  }
6489
6746
  }
6747
+ /**
6748
+ * The last successful list for a region, without probing.
6749
+ *
6750
+ * The picker resolves a route on every switch; awaiting an ACP probe there
6751
+ * cost a process round-trip whenever the TTL had just expired.
6752
+ */
6753
+ snapshot(requested) {
6754
+ return this.snapshots.get(requested ?? readLive(this.region, "cn"))?.models;
6755
+ }
6490
6756
  /** Why the last refresh failed, or undefined when it succeeded. */
6491
6757
  error(requested) {
6492
6758
  return this.failures.get(requested ?? readLive(this.region, "cn"));
@@ -7532,6 +7798,8 @@ var MinimaxAdapter = class extends LlmAdapter {
7532
7798
  auth = new MinimaxAuth();
7533
7799
  mcpServer = new MinimaxMcpServer();
7534
7800
  disabledCache = /* @__PURE__ */ new Map();
7801
+ /** Last verified image capability, keyed `${region}:${model}`. */
7802
+ knownVision = /* @__PURE__ */ new Map();
7535
7803
  constructor(options = {}) {
7536
7804
  super();
7537
7805
  this.options = options;
@@ -7572,7 +7840,9 @@ var MinimaxAdapter = class extends LlmAdapter {
7572
7840
  async describeCatalog(region = this.region) {
7573
7841
  if (!this.isSignedIn(region)) return [];
7574
7842
  if (await minimaxRegionBlocked(region)) return [];
7575
- return this.catalog.models(region);
7843
+ const models = await this.catalog.models(region);
7844
+ for (const model of models) this.knownVision.set(`${region}:${model.id}`, model.vision);
7845
+ return models;
7576
7846
  }
7577
7847
  /** Whether the region's endpoints are refusing this machine's network. */
7578
7848
  regionBlocked(region = this.region) {
@@ -7664,9 +7934,11 @@ var MinimaxAdapter = class extends LlmAdapter {
7664
7934
  async resolveModel(provider, model) {
7665
7935
  const region = this.region;
7666
7936
  const target = resolveMinimaxModelId(model, this.aliases);
7667
- const live = (await this.catalog.models(region)).find((entry) => entry.id === target);
7937
+ const key = `${region}:${target}`;
7938
+ const live = (await cachedModels(this.catalog.snapshot(region), () => this.catalog.models(region))).find((entry) => entry.id === target);
7668
7939
  if (live !== void 0) {
7669
- const reasoning = reasoningInfo(live.reasoningEfforts, live.defaultEffort, live.reasoning);
7940
+ this.knownVision.set(key, live.vision);
7941
+ const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), live.reasoning);
7670
7942
  return {
7671
7943
  provider,
7672
7944
  id: model,
@@ -7683,7 +7955,7 @@ var MinimaxAdapter = class extends LlmAdapter {
7683
7955
  provider,
7684
7956
  id: model,
7685
7957
  name: model,
7686
- inputModalities: ["text"],
7958
+ inputModalities: this.knownVision.get(key) === true ? ["text", "image"] : ["text"],
7687
7959
  context: { contextWindow: this.contextWindowFor(target, region) ?? 512e3 },
7688
7960
  defaultMaxTokens: readLive(this.options.defaultMaxTokens, MINIMAX_DEFAULT_MAX_TOKENS),
7689
7961
  ...reasoning === void 0 ? {} : { reasoning }
@@ -7704,7 +7976,7 @@ var MinimaxAdapter = class extends LlmAdapter {
7704
7976
  if (await minimaxRegionBlocked(region)) throw new Error(minimaxRegionBlockMessage(region));
7705
7977
  const model = resolveMinimaxModelId(options.model, this.aliases);
7706
7978
  if (options.sessionId === void 0 || options.purpose !== void 0) {
7707
- const prompt = feedToText(renderInitialFeed(options.system, options.messages)) + "\n(这是一次性旁路请求,直接输出下一条助手回复。)";
7979
+ const prompt = feedToText(renderInitialFeed(options.system, options.messages, this.options.imagePath), this.options.imagePath) + "\n(这是一次性旁路请求,直接输出下一条助手回复。)";
7708
7980
  for (const chunk of await minimaxColdStream(region, prompt, model, options)) yield chunk;
7709
7981
  return;
7710
7982
  }
@@ -7757,13 +8029,19 @@ var MinimaxAdapter = class extends LlmAdapter {
7757
8029
  session.fedMessages = options.messages;
7758
8030
  session.fedSystem = options.system;
7759
8031
  const vision = await this.modelVision(model, region);
7760
- const feed = await this.buildFeed(renderInitialFeed(void 0, options.messages), vision, options.signal);
8032
+ const feed = await this.buildFeed(renderInitialFeed(void 0, options.messages, this.options.imagePath), vision, options.signal);
7761
8033
  yield* session.stream(options, feed);
7762
8034
  }
7763
8035
  /** Whether the resolved model accepts images (drives whether pixels are sent). */
7764
8036
  async modelVision(model, region) {
7765
8037
  const target = resolveMinimaxModelId(model, this.aliases);
7766
- return (await this.catalog.models(region).catch(() => [])).find((entry) => entry.id === target)?.vision === true;
8038
+ const key = `${region}:${target}`;
8039
+ const live = (await this.catalog.models(region).catch(() => [])).find((entry) => entry.id === target);
8040
+ if (live !== void 0) {
8041
+ this.knownVision.set(key, live.vision);
8042
+ return live.vision;
8043
+ }
8044
+ return this.knownVision.get(key) === true;
7767
8045
  }
7768
8046
  /**
7769
8047
  * Turn a feed into what one ACP prompt carries.
@@ -7775,7 +8053,7 @@ var MinimaxAdapter = class extends LlmAdapter {
7775
8053
  */
7776
8054
  async buildFeed(feed, vision, signal) {
7777
8055
  if (typeof feed === "string") return feed;
7778
- if (!vision) return feedToText(feed);
8056
+ if (!vision) return feedToText(feed, this.options.imagePath);
7779
8057
  const images = /* @__PURE__ */ new Map();
7780
8058
  const readImage = this.options.readImage;
7781
8059
  if (readImage !== void 0) for (const ref of feedImageRefs(feed)) {
@@ -7800,13 +8078,12 @@ var MinimaxAdapter = class extends LlmAdapter {
7800
8078
  });
7801
8079
  continue;
7802
8080
  }
7803
- if (part.type === "image-unreadable") {
7804
- content.push({
7805
- type: "text",
7806
- text: textOnlyImageText(part.attachment)
7807
- });
7808
- continue;
7809
- }
8081
+ const path = this.options.imagePath?.(part.attachment);
8082
+ content.push({
8083
+ type: "text",
8084
+ text: part.type === "image-unreadable" && path === void 0 ? `[图片附件 ${String(part.attachment.attachmentId)} 本次未能读取,请基于文字内容继续]` : imageRefText(part.attachment, path)
8085
+ });
8086
+ if (part.type === "image-unreadable") continue;
7810
8087
  content.push({
7811
8088
  type: "image",
7812
8089
  data: part.data,
@@ -8039,7 +8316,8 @@ async function buildRows(adapter) {
8039
8316
  defaultContextWindow: upstream,
8040
8317
  ...override === void 0 ? {} : { override },
8041
8318
  ...priceFactor === void 0 ? {} : { priceFactor },
8042
- reasoning: entry.isReasoning !== false
8319
+ reasoning: entry.isReasoning !== false,
8320
+ contextWindowSelectable: (entry.availableContextWindows?.length ?? 0) > 1
8043
8321
  };
8044
8322
  });
8045
8323
  }
@@ -8404,7 +8682,7 @@ const Config$1 = z$1.object({
8404
8682
  maxSessions: z$1.number().step(1).min(1).max(64).default(8).description("同时保持的内层会话数上限,超出后按最久未使用关闭。每个会话是一个子进程。").volatile(),
8405
8683
  modelCacheTtlSeconds: z$1.number().step(1).min(10).max(86400).default(300).description("模型列表缓存时长(秒)。调小可更快看到账号侧变化。").volatile(),
8406
8684
  modelAliases: z$1.dict(z$1.string()).default({}).description("额外的模型别名映射:DSH 侧名称 → Qoder 模型 ID。内置 deepseek-v4-* 别名仍然生效。").volatile(),
8407
- defaultReasoningEffort: z$1.string().default("").description("请求未指定思考档位时使用的默认档位;留空则用上游默认。").volatile(),
8685
+ defaultReasoningEffort: z$1.string().default("").description("默认选用的思考档位;留空则用该模型支持的最强档位。").volatile(),
8408
8686
  defaultMaxTokens: z$1.number().step(1).min(1).default(32e3).description("模型未声明输出上限时使用的输出上限。").volatile(),
8409
8687
  toolResultTimeoutSeconds: z$1.number().step(1).min(5).max(3600).default(120).description("仅用于未配对 handler 的兜底时限(秒):正常工具调用会等宿主下一次请求携带结果,不按此超时。").volatile(),
8410
8688
  catalogFetchTimeoutSeconds: z$1.number().step(1).min(1).max(300).default(20).description("拉取模型列表的时限(秒),超时后回退到内置列表。").volatile(),
@@ -8642,6 +8920,7 @@ const Config = Config$1;
8642
8920
  function apply(ctx, config) {
8643
8921
  const live = liveConfig(config);
8644
8922
  let attachments;
8923
+ let filesystem;
8645
8924
  /**
8646
8925
  * Everything both editions share.
8647
8926
  *
@@ -8671,6 +8950,18 @@ function apply(ctx, config) {
8671
8950
  bytes: image.data,
8672
8951
  mediaType: image.mediaType
8673
8952
  }));
8953
+ },
8954
+ /**
8955
+ * Where the model can find the image on disk. Pixels let it describe the
8956
+ * picture; this path lets a "modify and save it" turn act on the file
8957
+ * instead of searching the workspace for something that was never there.
8958
+ */
8959
+ imagePath: (ref) => {
8960
+ const store = attachments;
8961
+ if (store === void 0) return void 0;
8962
+ const hostPath = store.imageHostPath(ref);
8963
+ if (hostPath === void 0) return void 0;
8964
+ return filesystem?.processPathFromHostPath?.(hostPath) ?? hostPath;
8674
8965
  }
8675
8966
  };
8676
8967
  /**
@@ -8710,7 +9001,8 @@ function apply(ctx, config) {
8710
9001
  disabledModels: (region) => region === "cn" ? live.codebuddyCnDisabledModels() : live.codebuddyGlobalDisabledModels(),
8711
9002
  modelContextWindows: (region) => region === "cn" ? live.codebuddyCnModelContextWindows() : live.codebuddyGlobalModelContextWindows(),
8712
9003
  modelAliases: live.codebuddyModelAliases,
8713
- readImage: shared.readImage
9004
+ readImage: shared.readImage,
9005
+ imagePath: shared.imagePath
8714
9006
  }),
8715
9007
  minimax: new MinimaxAdapter({
8716
9008
  maxSessions: live.maxSessions,
@@ -8725,7 +9017,8 @@ function apply(ctx, config) {
8725
9017
  disabledModels: (region) => region === "cn" ? live.minimaxCnDisabledModels() : live.minimaxGlobalDisabledModels(),
8726
9018
  modelContextWindows: (region) => region === "cn" ? live.minimaxCnModelContextWindows() : live.minimaxGlobalModelContextWindows(),
8727
9019
  modelAliases: live.minimaxModelAliases,
8728
- readImage: shared.readImage
9020
+ readImage: shared.readImage,
9021
+ imagePath: shared.imagePath
8729
9022
  })
8730
9023
  };
8731
9024
  ctx.inject(["attachments"], (scope) => {
@@ -8734,6 +9027,12 @@ function apply(ctx, config) {
8734
9027
  attachments = void 0;
8735
9028
  }, "llm-qoder-cn.attachments");
8736
9029
  });
9030
+ ctx.inject(["fs"], (scope) => {
9031
+ filesystem = scope.fs;
9032
+ scope.effect(() => () => {
9033
+ filesystem = void 0;
9034
+ }, "llm-qoder-cn.fs");
9035
+ });
8737
9036
  const routes = {};
8738
9037
  let directory;
8739
9038
  const enabled = (id) => {