dsh-agy-link 0.6.14 → 0.6.16

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/dist/index.js CHANGED
@@ -140,7 +140,7 @@ function defaultConfig() {
140
140
  warmupModels: ["gemini-3.8-flash", "claude-sonnet-5-5"],
141
141
  autoTranslate: false,
142
142
  translateModel: "gemini-3.8-flash",
143
- translateEffort: "high",
143
+ translateEffort: "medium",
144
144
  translateTargetLanguage: "中文(简体)",
145
145
  translateMaxChars: 8e3,
146
146
  translateMaxTokens: 4096,
@@ -148,7 +148,13 @@ function defaultConfig() {
148
148
  translateRetries: 2,
149
149
  translateBindConversation: true,
150
150
  translateSkipSameModel: true,
151
- translateMinIntervalMs: 3e3
151
+ translateMinIntervalMs: 3e3,
152
+ imageModel: "",
153
+ imageEffort: "low",
154
+ imageTimeoutMs: 24e4,
155
+ imageMaxBytes: 20971520,
156
+ imageOutputDir: "",
157
+ imageRetries: 1
152
158
  };
153
159
  }
154
160
  /**
@@ -576,7 +582,13 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
576
582
  translateRetries: asNum(get("translateRetries")) ?? base.translateRetries,
577
583
  translateSkipSameModel: asBool(get("translateSkipSameModel")) ?? base.translateSkipSameModel,
578
584
  translateBindConversation: asBool(get("translateBindConversation")) ?? base.translateBindConversation,
579
- translateMinIntervalMs: asNum(get("translateMinIntervalMs")) ?? base.translateMinIntervalMs
585
+ translateMinIntervalMs: asNum(get("translateMinIntervalMs")) ?? base.translateMinIntervalMs,
586
+ imageModel: asString(get("imageModel")) ?? base.imageModel,
587
+ imageEffort: asString(get("imageEffort")) ?? base.imageEffort,
588
+ imageTimeoutMs: asNum(get("imageTimeoutMs")) ?? base.imageTimeoutMs,
589
+ imageMaxBytes: asNum(get("imageMaxBytes")) ?? base.imageMaxBytes,
590
+ imageOutputDir: asString(get("imageOutputDir")) ?? base.imageOutputDir,
591
+ imageRetries: asNum(get("imageRetries")) ?? base.imageRetries
580
592
  };
581
593
  if (env.DSH_AGY_ENABLED !== void 0) cfg.enabled = asBool(env.DSH_AGY_ENABLED) ?? cfg.enabled;
582
594
  if (env.DSH_AGY_BIN) cfg.agyBin = env.DSH_AGY_BIN;
@@ -675,6 +687,21 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
675
687
  if (env.DSH_AGY_TRANSLATE_MODEL) cfg.translateModel = env.DSH_AGY_TRANSLATE_MODEL;
676
688
  if (env.DSH_AGY_TRANSLATE_EFFORT) cfg.translateEffort = env.DSH_AGY_TRANSLATE_EFFORT;
677
689
  if (env.DSH_AGY_TRANSLATE_LANG) cfg.translateTargetLanguage = env.DSH_AGY_TRANSLATE_LANG;
690
+ if (env.DSH_AGY_IMAGE_MODEL) cfg.imageModel = env.DSH_AGY_IMAGE_MODEL;
691
+ if (env.DSH_AGY_IMAGE_EFFORT) cfg.imageEffort = env.DSH_AGY_IMAGE_EFFORT;
692
+ if (env.DSH_AGY_IMAGE_TIMEOUT_MS) {
693
+ const v = asNum(env.DSH_AGY_IMAGE_TIMEOUT_MS);
694
+ if (v !== void 0) cfg.imageTimeoutMs = v;
695
+ }
696
+ if (env.DSH_AGY_IMAGE_MAX_BYTES) {
697
+ const v = asNum(env.DSH_AGY_IMAGE_MAX_BYTES);
698
+ if (v !== void 0) cfg.imageMaxBytes = v;
699
+ }
700
+ if (env.DSH_AGY_IMAGE_OUTPUT_DIR) cfg.imageOutputDir = env.DSH_AGY_IMAGE_OUTPUT_DIR;
701
+ if (env.DSH_AGY_IMAGE_RETRIES) {
702
+ const v = asNum(env.DSH_AGY_IMAGE_RETRIES);
703
+ if (v !== void 0) cfg.imageRetries = v;
704
+ }
678
705
  return cfg;
679
706
  }
680
707
  //#endregion
@@ -31270,7 +31297,6 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31270
31297
  }
31271
31298
  async listModels(_provider) {
31272
31299
  const activeAcc = this.getActiveAccount();
31273
- this.deps.catalog.refreshIfNeeded(activeAcc?.id);
31274
31300
  const cfg = this.deps.getConfig();
31275
31301
  const cat = this.deps.catalog.get(activeAcc?.id);
31276
31302
  let models = cat.models;
@@ -31441,14 +31467,17 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31441
31467
  const isTitle = options.purpose === "session-title";
31442
31468
  const isCompaction = options.purpose === "compaction";
31443
31469
  const isTranslate = options.purpose === "translation";
31444
- const isAux = isCompaction || isTitle || isReview || isTranslate;
31470
+ const isImage = options.purpose === "image";
31471
+ const isAux = isCompaction || isTitle || isReview || isTranslate || isImage;
31472
+ const imageModeRaw = isImage ? options.agyPermissionMode : void 0;
31473
+ const effectivePermissionMode = imageModeRaw === "skip" || imageModeRaw === "plan" || imageModeRaw === "accept-edits" ? imageModeRaw : isAux && !isTitle && !isImage ? "plan" : cfg.permissionMode;
31445
31474
  const translateSessionRaw = options.agyTranslateSession;
31446
31475
  const translateSession = isTranslate && typeof translateSessionRaw === "object" && translateSessionRaw !== null ? {
31447
31476
  setup: String(translateSessionRaw.setup ?? ""),
31448
31477
  text: String(translateSessionRaw.text ?? "")
31449
31478
  } : null;
31450
31479
  const isTranslateSession = translateSession !== null;
31451
- if (isAux && !isReview && !isTranslate && !cfg.allowAuxiliary) throw new LlmError("auxiliary calls are disabled for the antigravity route (allowAuxiliary: false)", Err.AUX_DISABLED);
31480
+ if (isAux && !isReview && !isTranslate && !isImage && !cfg.allowAuxiliary) throw new LlmError("auxiliary calls are disabled for the antigravity route (allowAuxiliary: false)", Err.AUX_DISABLED);
31452
31481
  const toolNames = new Set((options.tools ?? []).map((t) => t.name));
31453
31482
  const isCodeMode = toolNames.has("run_code") && !toolNames.has("agy_tool");
31454
31483
  const hasToolSupport = options.tools === void 0 || toolNames.has("agy_tool") || toolNames.has("run_code");
@@ -31494,7 +31523,7 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31494
31523
  let effort;
31495
31524
  if (isGemini && !suppressEffort) {
31496
31525
  if (this.isEffortUnsupported(model)) effort = void 0;
31497
- else if (isAux && !isTranslate) effort = "low";
31526
+ else if (isAux && !isTranslate && !isImage) effort = "low";
31498
31527
  else if (options.reasoningEffort !== void 0) {
31499
31528
  const wanted = String(options.reasoningEffort);
31500
31529
  if (entry && entry.efforts === null) throw new LlmError("model " + model + " has no selectable reasoning efforts", Err.UNSUPPORTED_REASONING_EFFORT);
@@ -31616,6 +31645,13 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31616
31645
  }
31617
31646
  }
31618
31647
  if (account && !isAux) this.deps.pool?.markAccountActive(account.id);
31648
+ const onAccount = options.agyOnAccount;
31649
+ if (typeof onAccount === "function" && account) try {
31650
+ onAccount({
31651
+ id: account.id,
31652
+ home: account.dir || process.env.HOME || homedir()
31653
+ });
31654
+ } catch {}
31619
31655
  const bindingKey = isTranslateSession && sessionKey !== "" ? `${sessionKey}#tsl` : sessionKey;
31620
31656
  const persistBinding = !isAux || isTranslateSession;
31621
31657
  const sessionAccountKey = account ? `${bindingKey}:${account.id}` : bindingKey;
@@ -31682,7 +31718,9 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31682
31718
  }
31683
31719
  let stagedDirs = [];
31684
31720
  let prompt = "";
31685
- if (isTranslateSession) {
31721
+ const imagePromptRaw = options.agyImagePrompt;
31722
+ if (isImage) prompt = typeof imagePromptRaw === "string" ? imagePromptRaw : "";
31723
+ else if (isTranslateSession) {
31686
31724
  const lastMessage = messages[messages.length - 1] ?? messages[0];
31687
31725
  const text = translateSession.text !== "" ? translateSession.text : lastMessage === void 0 ? "" : textOf(lastMessage);
31688
31726
  prompt = binding === void 0 ? translateSession.setup + (translateSession.setup === "" ? "" : "\n\n=====\n\n") + text : text;
@@ -31889,7 +31927,7 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31889
31927
  model: activeModelForArgs,
31890
31928
  effort,
31891
31929
  conversationId: persistBinding && binding !== void 0 ? binding.conversationId : void 0,
31892
- permissionMode: isAux && !isTitle ? "plan" : cfg.permissionMode,
31930
+ permissionMode: effectivePermissionMode,
31893
31931
  timeoutMs: cfg.timeoutMs,
31894
31932
  printTimeoutMinutes,
31895
31933
  extraArgs: cfg.extraArgs,
@@ -31901,7 +31939,7 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
31901
31939
  model: activeModelForArgs,
31902
31940
  effort,
31903
31941
  conversationId: persistBinding && binding !== void 0 ? binding.conversationId : void 0,
31904
- permissionMode: isAux && !isTitle ? "plan" : cfg.permissionMode,
31942
+ permissionMode: effectivePermissionMode,
31905
31943
  timeoutMs: cfg.timeoutMs,
31906
31944
  printTimeoutMinutes,
31907
31945
  extraArgs: cfg.extraArgs,
@@ -32112,6 +32150,10 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
32112
32150
  }
32113
32151
  }
32114
32152
  rec.append(ev);
32153
+ const onEvent = options.agyOnEvent;
32154
+ if (typeof onEvent === "function") try {
32155
+ onEvent(ev);
32156
+ } catch {}
32115
32157
  }
32116
32158
  }
32117
32159
  });
@@ -32144,6 +32186,10 @@ var AgyAdapter = class AgyAdapter extends LlmAdapter {
32144
32186
  for (const ev of parser.flush()) {
32145
32187
  if (ev.kind === "result" && ev.conversationId !== "") streamCid = ev.conversationId;
32146
32188
  rec.append(ev);
32189
+ const onEvent = options.agyOnEvent;
32190
+ if (typeof onEvent === "function") try {
32191
+ onEvent(ev);
32192
+ } catch {}
32147
32193
  }
32148
32194
  const diffed = diffConversations(before, conversationsDir).conversationId;
32149
32195
  const conversationId = streamCid ?? diffed;
@@ -32627,6 +32673,10 @@ async function runAgyOnce(deps, req) {
32627
32673
  cwd: cfg.workspaceRoot !== "" ? cfg.workspaceRoot : void 0,
32628
32674
  timeoutMs,
32629
32675
  signal: req.signal,
32676
+ env: {
32677
+ ...process.env,
32678
+ ...proxyEnvFor(cfg.proxyUrl || detectSystemProxy())
32679
+ },
32630
32680
  stdinPayload,
32631
32681
  preemptAutoUpdate: cfg.suppressAgyAutoUpdate,
32632
32682
  onLine: (line) => {
@@ -33654,7 +33704,7 @@ function buildTranslationSetup(input) {
33654
33704
  if (input.cwd !== void 0 && input.cwd !== "") lines.push("- 该会话的工作目录:" + input.cwd);
33655
33705
  if (input.digest !== void 0 && input.digest.trim() !== "") lines.push("", "该会话到目前为止的摘要(供你理解上下文,不必翻译它):", "", "<digest>", input.digest.trim(), "</digest>");
33656
33706
  if (input.logPath !== void 0 && input.logPath !== "") lines.push("", "需要完整历史时可以自己读:原始日志在 " + input.logPath + "(zstd 压缩的 JSONL,每行一个事件)。读取示例:", " zstd -dc '" + input.logPath + "' | jq -c 'select(.type==\"assistant/message\") | {turn:.data.turn, text:([.data.message.content[]?.text] | join(\"\"))}' | tail -40", "没有 jq 就用 python3 逐行 json.loads 过滤;不要修改这些文件。");
33657
- lines.push("", "规则:", "1. 只讲「当前这一轮」的 AI 回复:我每次发来的是这一轮的原文,别去翻历史里的其它回答来顶替它。", "2. 说" + lang + "的大白话,像当面给同事解释:口语、短句、按原文顺序讲;不要标题,不要分点罗列,不要写成报告。", "3. 遇到术语、缩写、报错、函数名,先用日常说法讲清,再往下说;必要时补一句它大概是干什么的。", "4. 结论、条件、谁做了什么都要留着;别为了短把细节吞掉,也别替它下原文没有的结论。", "5. 只输出讲解本身,不要前言、不要复述我发的内容、不要反问我。");
33707
+ lines.push("", "规则:", "1. 每次我只发来「当前这一条」AI 回复的原文:只讲这一条,别去翻历史里的其它回答来顶替它。", "2. 说" + lang + "的大白话,像当面给同事解释:口语、短句、怎么顺口怎么来;不要标题,不要分点罗列,不要写成报告。", "3. 别用行话、缩写和「首先 / 其次 / 综上 / 因此 / 旨在 / 该方案」这类书面词;遇到术语先用日常说法讲清它大概是干什么的。", "4. 原文说了多少就讲多少:结论、条件、谁做了什么都要留着,别为了短把细节吞掉,也别替它下结论。", "5. 只输出讲解本身,不要前言、不要复述我发的内容、不要反问我。");
33658
33708
  return lines.join("\n");
33659
33709
  }
33660
33710
  /** Read the event log whichever shape the host exposes. */
@@ -33798,11 +33848,22 @@ function turnOfMessage(events, messageId) {
33798
33848
  }
33799
33849
  /**
33800
33850
  * The newest durable translation record for one turn (optionally narrowed to an
33801
- * exact model/effort recipe). Used to dedupe repeated requests so clicking the
33802
- * per-turn affordance twice can never stack two identical cards.
33851
+ * exact model/effort recipe and to ONE assistant message). Used to dedupe
33852
+ * repeated requests so clicking the per-turn affordance twice can never stack
33853
+ * two identical cards.
33854
+ *
33855
+ * `messageId` is what makes the per-reply button correct: a turn can contain
33856
+ * several text messages (a preamble, then the real answer), and a turn-level
33857
+ * record must never be handed back for a sibling message — that is exactly the
33858
+ * "I clicked message A but got the translation of message B" bug. Records
33859
+ * written by older builds carry no `messageId`; they are honoured as a legacy
33860
+ * turn-level fallback only while the turn has no message-scoped record at all.
33803
33861
  */
33804
- function findTranslationRecord(events, turn, model, effort) {
33805
- let found = null;
33862
+ function findTranslationRecord(events, turn, model, effort, messageId) {
33863
+ const scoped = messageId !== void 0 && messageId !== "";
33864
+ let exact = null;
33865
+ let legacy = null;
33866
+ let sawScoped = false;
33806
33867
  for (const ev of events) {
33807
33868
  if (ev.type !== "plugin:agy-link/translation") continue;
33808
33869
  const d = dataOf(ev);
@@ -33813,14 +33874,23 @@ function findTranslationRecord(events, turn, model, effort) {
33813
33874
  if (effort !== void 0 && recordEffort !== effort) continue;
33814
33875
  const text = typeof d.text === "string" ? d.text : "";
33815
33876
  if (text.trim() === "") continue;
33816
- found = {
33877
+ const hit = {
33817
33878
  seq: num$1(ev.seq) ?? 0,
33818
33879
  text,
33819
33880
  model: recordModel,
33820
33881
  effort: recordEffort
33821
33882
  };
33883
+ const recordMessage = typeof d.messageId === "string" && d.messageId !== "" ? d.messageId : null;
33884
+ if (recordMessage !== null) sawScoped = true;
33885
+ if (!scoped) {
33886
+ exact = hit;
33887
+ continue;
33888
+ }
33889
+ if (recordMessage === messageId) exact = hit;
33890
+ else if (recordMessage === null) legacy = hit;
33822
33891
  }
33823
- return found;
33892
+ if (exact !== null) return exact;
33893
+ return scoped && !sawScoped ? legacy : null;
33824
33894
  }
33825
33895
  /** Text of one `user/message` event (the asks that carry the thread). */
33826
33896
  function userTextOf(ev) {
@@ -33835,6 +33905,14 @@ function userTextOf(ev) {
33835
33905
  */
33836
33906
  function sessionDigest(events, maxChars) {
33837
33907
  const cap = Math.max(200, Math.round(maxChars / 4));
33908
+ const answers = /* @__PURE__ */ new Map();
33909
+ for (const ev of events) {
33910
+ if (ev.type !== "assistant/message") continue;
33911
+ const turn = num$1(dataOf(ev).turn);
33912
+ if (turn === void 0) continue;
33913
+ const text = textOfAssistant(ev);
33914
+ if (text !== "") answers.set(turn, text);
33915
+ }
33838
33916
  const parts = [];
33839
33917
  const done = /* @__PURE__ */ new Set();
33840
33918
  for (const ev of events) {
@@ -33846,10 +33924,10 @@ function sessionDigest(events, maxChars) {
33846
33924
  if (ev.type !== "assistant/message") continue;
33847
33925
  const turn = num$1(dataOf(ev).turn);
33848
33926
  if (turn === void 0 || done.has(turn)) continue;
33849
- const answer = finalAnswerOfTurn(events, turn);
33850
- if (answer === null || answer.text.trim() === "") continue;
33927
+ const answer = answers.get(turn);
33928
+ if (answer === void 0 || answer.trim() === "") continue;
33851
33929
  done.add(turn);
33852
- parts.push("回复:" + clip(answer.text, 900));
33930
+ parts.push("回复:" + clip(answer, 900));
33853
33931
  }
33854
33932
  let kept = "";
33855
33933
  for (let i = parts.length - 1; i >= 0; i--) {
@@ -33868,16 +33946,18 @@ function clip(text, max) {
33868
33946
  * explicit about "never invent facts": a cheerful paraphrase that adds a
33869
33947
  * promise the agent never made is worse than no translation at all.
33870
33948
  */
33871
- function buildTranslationPrompt(text, targetLanguage, maxChars) {
33949
+ function buildTranslationPrompt(text, targetLanguage, maxChars, sessionId) {
33872
33950
  const lang = targetLanguage.trim() === "" ? "中文(简体)" : targetLanguage.trim();
33873
33951
  const limit = Math.max(MIN_TEXT_LIMIT, Math.round(maxChars));
33874
33952
  const long = text.length > Math.min(2e3, Math.floor(limit / 4));
33953
+ const where = sessionId === void 0 || sessionId.trim() === "" ? "" : "(DSH 会话 " + sessionId.trim() + ")";
33875
33954
  return [
33876
- "把下面这段「当前这一轮 AI 回复」的原文,用" + lang + "通俗易懂地讲一遍,就像当面跟同事解释:",
33877
- "说大白话、短句,按原文的顺序讲;别用行话和缩写,遇到术语先换成日常说法(必要时补一句它是干什么的);别写标题或分点列表,别写成报告。",
33878
- "结论、条件、谁做了什么都要留着,别为了短把细节吞掉;别改原意,别加原文没有的内容,别替它下结论。",
33879
- ...long ? ["原文有点长,挑重点讲清楚就行,按它自己的顺序讲,别压成几句结论。"] : [],
33880
- "只输出这段讲解本身,不要复述我发的内容,不要提问。",
33955
+ "把下面这段「当前这一条 AI 回复」的原文,用" + lang + "讲成大白话,就像当面跟同事解释:",
33956
+ "说人话、用短句,怎么顺口怎么来;别用行话、缩写和「首先 / 其次 / 综上 / 因此」这类书面词,遇到术语先用日常说法讲清它大概是干什么的。",
33957
+ "原文说了多少就讲多少,该长就长、该短就短,别压成几句结论,也别写成标题或分点报告。",
33958
+ "只讲这一条回复" + where + "本身,别把历史里别的回复混进来;别改原意,别加原文没有的内容,别替它下结论。",
33959
+ ...long ? ["原文比较长,按它自己的顺序一步步讲完,别漏掉关键条件。"] : [],
33960
+ "只输出讲解本身,不要复述我发的内容,不要提问。",
33881
33961
  "",
33882
33962
  "<content>",
33883
33963
  text,
@@ -33896,9 +33976,10 @@ function buildTranslationRequest(text, targetLanguage, maxChars) {
33896
33976
  const lang = targetLanguage.trim() === "" ? "中文(简体)" : targetLanguage.trim();
33897
33977
  const long = text.length > Math.min(2e3, Math.floor(Math.max(MIN_TEXT_LIMIT, Math.round(maxChars)) / 4));
33898
33978
  return [
33899
- "把「当前这一轮 AI 回复」的下面这段原文,用" + lang + "通俗易懂地讲一遍:说大白话、短句,按原文顺序,术语先换成日常说法,别写成报告,别为了短丢信息,别加原文没有的内容。",
33900
- ...long ? ["原文有点长,挑重点讲清楚就行,别压成几句结论。"] : [],
33901
- "只输出讲解本身。",
33979
+ "把「当前这一条 AI 回复」的下面这段原文,用" + lang + "讲成大白话:说人话、短句,别用行话和书面腔(不要「首先 / 其次 / 综上 / 因此」),术语先用日常说法解释。",
33980
+ "原文说了多少就讲多少,按它自己的顺序讲,该长就长,别压成几句结论,也别写成标题或分点报告;别改原意,别加原文没有的内容。",
33981
+ ...long ? ["原文比较长,一步步讲完,别漏掉关键条件。"] : [],
33982
+ "只讲这一条,别把前面几轮的内容混进来;只输出讲解本身。",
33902
33983
  "",
33903
33984
  "<content>",
33904
33985
  text,
@@ -34130,7 +34211,7 @@ var TranslationService = class {
34130
34211
  const setupEvents = sessionId === void 0 ? [] : sessionEvents(this.deps.getSession(sessionId));
34131
34212
  for (const chunk of chunks) {
34132
34213
  const res = await this.withRetry({
34133
- prompt: buildTranslationPrompt(chunk, language, cfg.translateMaxChars),
34214
+ prompt: buildTranslationPrompt(chunk, language, cfg.translateMaxChars, sessionId),
34134
34215
  text: buildTranslationRequest(chunk, language, cfg.translateMaxChars),
34135
34216
  setup: sessionId === void 0 ? void 0 : this.setupFor(sessionId, language, setupEvents),
34136
34217
  ...sessionId === void 0 ? {} : { sessionId },
@@ -34143,7 +34224,7 @@ var TranslationService = class {
34143
34224
  if (!res.ok) {
34144
34225
  const result = {
34145
34226
  ok: false,
34146
- text: out.join("\n\n---\n\n"),
34227
+ text: out.join("\n\n"),
34147
34228
  model: target.model,
34148
34229
  effort: target.effort,
34149
34230
  cached: false,
@@ -34159,7 +34240,7 @@ var TranslationService = class {
34159
34240
  }
34160
34241
  const result = {
34161
34242
  ok: true,
34162
- text: out.join("\n\n---\n\n"),
34243
+ text: out.join("\n\n"),
34163
34244
  model: target.model,
34164
34245
  effort: target.effort,
34165
34246
  cached: false,
@@ -34235,25 +34316,37 @@ var TranslationService = class {
34235
34316
  async translateTurn(sessionId, turn, opts = {}, signal) {
34236
34317
  const session = this.deps.getSession(sessionId);
34237
34318
  const events = sessionEvents(session);
34238
- if (session === void 0 || events.length === 0) {
34239
- const target = this.target(opts);
34240
- return {
34241
- ...emptyResult(target.model, target.effort),
34242
- error: "session is not available",
34243
- code: "SESSION_UNAVAILABLE"
34244
- };
34245
- }
34246
- if (isTurnRunning(events, turn)) {
34247
- const target = this.target(opts);
34248
- return {
34249
- ...emptyResult(target.model, target.effort),
34250
- error: "the current turn is still running",
34251
- code: "TRANSIENT"
34252
- };
34253
- }
34254
34319
  const target = this.target(opts);
34320
+ if (session === void 0 || events.length === 0) return {
34321
+ ...emptyResult(target.model, target.effort),
34322
+ error: "session is not available",
34323
+ code: "SESSION_UNAVAILABLE"
34324
+ };
34325
+ if (isTurnRunning(events, turn)) return {
34326
+ ...emptyResult(target.model, target.effort),
34327
+ error: "the current turn is still running",
34328
+ code: "TRANSIENT"
34329
+ };
34330
+ const answer = opts.full === true ? allTextOfTurn(events, turn) : finalAnswerOfTurn(events, turn);
34331
+ if (answer === null || answer.text.trim() === "") return {
34332
+ ...emptyResult(target.model, target.effort),
34333
+ error: "no assistant text in turn " + turn,
34334
+ code: "TURN_NOT_FOUND"
34335
+ };
34336
+ return this.translateAnswer(sessionId, turn, answer, opts, signal);
34337
+ }
34338
+ /**
34339
+ * Translate exactly ONE assistant message (the shared body of the turn command
34340
+ * and the per-reply button). The button passes the message the reader clicked:
34341
+ * a turn can hold several text messages (a preamble, tool narration, then the
34342
+ * real answer), and resolving them through "the turn's last answer" made the
34343
+ * card show a *different* message than the one that was clicked.
34344
+ */
34345
+ async translateAnswer(sessionId, turn, answer, opts, signal) {
34346
+ const target = this.target(opts);
34347
+ const events = sessionEvents(this.deps.getSession(sessionId));
34255
34348
  if (opts.force !== true) {
34256
- const existing = findTranslationRecord(events, turn, target.model, target.effort);
34349
+ const existing = findTranslationRecord(events, turn, target.model, target.effort, answer.messageId);
34257
34350
  if (existing !== null) return {
34258
34351
  ok: true,
34259
34352
  text: existing.text,
@@ -34265,12 +34358,6 @@ var TranslationService = class {
34265
34358
  turn
34266
34359
  };
34267
34360
  }
34268
- const answer = opts.full === true ? allTextOfTurn(events, turn) : finalAnswerOfTurn(events, turn);
34269
- if (answer === null || answer.text.trim() === "") return {
34270
- ...emptyResult(target.model, target.effort),
34271
- error: "no assistant text in turn " + turn,
34272
- code: "TURN_NOT_FOUND"
34273
- };
34274
34361
  const res = await this.translate({
34275
34362
  text: answer.text,
34276
34363
  sessionId,
@@ -34311,7 +34398,7 @@ var TranslationService = class {
34311
34398
  }
34312
34399
  const located = turnOfMessage(events, messageId);
34313
34400
  if (located === null) return null;
34314
- return findTranslationRecord(events, located.turn);
34401
+ return findTranslationRecord(events, located.turn, void 0, void 0, messageId);
34315
34402
  }
34316
34403
  /** True while a translation is running for this session. */
34317
34404
  isPending(sessionId) {
@@ -34330,17 +34417,15 @@ var TranslationService = class {
34330
34417
  }
34331
34418
  return this.translateTurn(sessionId, turn, opts, signal);
34332
34419
  }
34333
- /** Translate the turn that owns one assistant message (history button). */
34420
+ /** Translate exactly the assistant message the reader clicked. */
34334
34421
  async translateMessage(sessionId, messageId, opts = {}, signal) {
34335
34422
  const events = sessionEvents(this.deps.getSession(sessionId));
34336
- if (events.length === 0) {
34337
- const target = this.target(opts);
34338
- return {
34339
- ...emptyResult(target.model, target.effort),
34340
- error: "session is not available",
34341
- code: "SESSION_UNAVAILABLE"
34342
- };
34343
- }
34423
+ const target = this.target(opts);
34424
+ if (events.length === 0) return {
34425
+ ...emptyResult(target.model, target.effort),
34426
+ error: "session is not available",
34427
+ code: "SESSION_UNAVAILABLE"
34428
+ };
34344
34429
  const located = turnOfMessage(events, messageId);
34345
34430
  if (located === null) {
34346
34431
  const last = lastCompletedTurn(events);
@@ -34348,14 +34433,25 @@ var TranslationService = class {
34348
34433
  ...opts,
34349
34434
  full: false
34350
34435
  }, signal);
34351
- const target = this.target(opts);
34352
34436
  return {
34353
34437
  ...emptyResult(target.model, target.effort),
34354
34438
  error: "message not found in this session",
34355
34439
  code: "MESSAGE_NOT_FOUND"
34356
34440
  };
34357
34441
  }
34358
- return this.translateTurn(sessionId, located.turn, {
34442
+ const answer = located.text.trim() === "" ? finalAnswerOfTurn(events, located.turn) : located;
34443
+ if (answer === null || answer.text.trim() === "") return {
34444
+ ...emptyResult(target.model, target.effort),
34445
+ error: "that message carries no text to translate",
34446
+ code: "MESSAGE_NOT_FOUND"
34447
+ };
34448
+ const scoped = {
34449
+ text: answer.text,
34450
+ anchorSeq: located.anchorSeq !== 0 ? located.anchorSeq : answer.anchorSeq,
34451
+ messageId,
34452
+ ...answer.sourceModel === void 0 ? {} : { sourceModel: answer.sourceModel }
34453
+ };
34454
+ return this.translateAnswer(sessionId, located.turn, scoped, {
34359
34455
  ...opts,
34360
34456
  full: false
34361
34457
  }, signal);
@@ -34430,7 +34526,7 @@ function sameModel(a, b) {
34430
34526
  //#endregion
34431
34527
  //#region src/host/tsl-command.ts
34432
34528
  const HELP = [
34433
- "**/tsl** — 用 Gemini 把当前会话的输出翻成人话(默认 `gemini-3.8-flash` · high)",
34529
+ "**/tsl** — 用 Gemini 把当前会话的输出翻成人话(默认 `gemini-3.8-flash` · medium;`--effort low` 更快)",
34434
34530
  "- `/tsl` — 翻译当前会话**最后一个已完成回合**,并在该回复下方生成译文卡片",
34435
34531
  "- `/tsl 3` — 翻译第 3 回合(卡片锚在那条回复下方)",
34436
34532
  "- `/tsl --full` — 连本回合的中间解释一起翻(默认只翻最终答复)",
@@ -37365,6 +37461,11 @@ function apply(ctx, entryConfig = {}) {
37365
37461
  }, 4e3);
37366
37462
  bootProbeTimer.unref?.();
37367
37463
  ctx.effect(() => () => clearTimeout(bootProbeTimer));
37464
+ const catalogPollTimer = setInterval(() => {
37465
+ catalog.refreshIfNeeded().catch(() => void 0);
37466
+ }, 18e5);
37467
+ catalogPollTimer.unref?.();
37468
+ ctx.effect(() => () => clearInterval(catalogPollTimer));
37368
37469
  if (getConfig().enabled) try {
37369
37470
  ctx.llm.registerAdapter([PROVIDER_ID], adapter);
37370
37471
  log("registered provider route: antigravity");
@@ -37545,6 +37646,9 @@ function apply(ctx, entryConfig = {}) {
37545
37646
  translateModel: cfg.translateModel,
37546
37647
  translateEffort: cfg.translateEffort,
37547
37648
  translateTargetLanguage: cfg.translateTargetLanguage,
37649
+ imageModel: cfg.imageModel,
37650
+ imageEffort: cfg.imageEffort,
37651
+ imageOutputDir: cfg.imageOutputDir,
37548
37652
  translateState: {
37549
37653
  pending: translation.pendingFor(),
37550
37654
  stats: translation.stats()
@@ -38037,7 +38141,13 @@ function apply(ctx, entryConfig = {}) {
38037
38141
  "translateMaxChars",
38038
38142
  "translateSkipSameModel",
38039
38143
  "translateBindConversation",
38040
- "translateMinIntervalMs"
38144
+ "translateMinIntervalMs",
38145
+ "imageModel",
38146
+ "imageEffort",
38147
+ "imageTimeoutMs",
38148
+ "imageMaxBytes",
38149
+ "imageOutputDir",
38150
+ "imageRetries"
38041
38151
  ].includes(key)) {
38042
38152
  sendJson(res, 400, { error: "key not settable" });
38043
38153
  return;
@@ -91,18 +91,46 @@ Resolution order (highest first): `DSH_AGY_*` environment variable → runtime o
91
91
  | --- | --- | --- | --- |
92
92
  | `autoTranslate` | `DSH_AGY_AUTO_TRANSLATE` | `false` | Translate every completed turn |
93
93
  | `translateModel` | `DSH_AGY_TRANSLATE_MODEL` | `gemini-3.8-flash` | Translate model, with catalog fallback |
94
- | `translateEffort` | `DSH_AGY_TRANSLATE_EFFORT` | `high` | Reasoning effort for the translate model |
94
+ | `translateEffort` | `DSH_AGY_TRANSLATE_EFFORT` | `medium` | Reasoning effort for the translate model (`low` faster, `high` more rigorous) |
95
95
  | `translateTargetLanguage` | `DSH_AGY_TRANSLATE_LANG` | `中文(简体)` | Target language wording in the prompt |
96
96
  | `translateMaxChars` | `—` | `8000` | Source truncation limit |
97
97
  | `translateMaxTokens` | `—` | `4096` | Output token cap |
98
98
  | `translateTimeoutMs` | `—` | `120000` | Per-translation timeout |
99
99
  | `translateRetries` | `—` | `2` | Retries on retryable failures (account stall, empty answer) |
100
100
 
101
- `translateModel` and `translateEffort` are also editable in **DSH Settings → Antigravity**, on the auto-translate row (two dropdowns next to the on/off control). Leaving them on their default option hands the choice back to the fallback chain above.
102
101
  | `translateSkipSameModel` | `—` | `true` | Skip translation when the reply already came from the translate model |
103
102
  | `translateBindConversation` | `—` | `true` | One agy conversation per DSH session, persona sent once |
104
103
  | `translateMinIntervalMs` | `—` | `3000` | Minimum spacing between automatic translations |
105
104
 
105
+ `translateModel` and `translateEffort` are also editable in **DSH Settings → Antigravity**, on the auto-translate row (two dropdowns next to the on/off control). Leaving them on their default option hands the choice back to the fallback chain above.
106
+
107
+ ## Image generation (`dsh-agy-image`)
108
+
109
+ | Key | Environment | Default | Description |
110
+ | --- | --- | --- | --- |
111
+ | `imageModel` | `DSH_AGY_IMAGE_MODEL` | (empty) | Chat model that drives the `generate_image` call; empty → `defaultModel` → `gemini-3.8-flash` |
112
+ | `imageEffort` | `DSH_AGY_IMAGE_EFFORT` | `low` | Reasoning effort for that hop (the image model does the real work) |
113
+ | `imageTimeoutMs` | `DSH_AGY_IMAGE_TIMEOUT_MS` | `240000` | Wall-clock cap for one image generation |
114
+ | `imageMaxBytes` | `DSH_AGY_IMAGE_MAX_BYTES` | `20971520` | Largest artifact the plugin accepts (20 MiB) |
115
+ | `imageOutputDir` | `DSH_AGY_IMAGE_OUTPUT_DIR` | (empty) | Default directory to copy finished images into |
116
+ | `imageRetries` | `DSH_AGY_IMAGE_RETRIES` | `1` | Extra attempts after a retryable failure (each may pick another account) |
117
+
118
+ The CLI is installed with the plugin as `dsh-agy-image`:
119
+
120
+ ```bash
121
+ dsh-agy-image -p "一只柴犬,扁平插画风" -a 16:9 -o ./dog.jpg
122
+ dsh-agy-image -p "把背景换成夜晚" -i ./day.png --json
123
+ ```
124
+
125
+ There is no HTTP endpoint. Settings → Antigravity exposes `imageModel` / `imageEffort` and a copyable
126
+ `dsh-agy-image` command next to the translation row.
127
+
128
+ The CLI instantiates the plugin's real `AgyAdapter` with
129
+ `purpose:'image'`, so account selection, quota cooldown/rotation, proxy, failure
130
+ classification and the retry-on-effort-refusal all come from the same code path a
131
+ normal turn uses. `--json` returns the validated artifact (`path`, `mime`,
132
+ `width`, `height`, `bytes`, `aspectRatio`, `accountId`) or a stable failure `code`.
133
+
106
134
  ## Diagnostics
107
135
 
108
136
  | Key | Environment | Default | Description |