@vibedev-si/dsh-vibedev 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -82,6 +82,22 @@
82
82
  - 网关到上游模型服务的连接中途断开(例如 `upstream_http2_stream_error`、上游响应流被中断)属于可恢复的传输故障,会和超时、5xx、限流一样按退避自动重试,不再直接判定成一次不可重试的失败;重试会重新发起该次请求,已经输出的内容不会续写。
83
83
  - 0.3.7 起,网关新上架或下架的模型不用退出重新登录就能看到:指针停在侧边栏的 VibeDev 账号行上打开余额卡片、打开账号菜单(显示的余额超过 10 秒时),以及点「刷新」或打开「设置 → VibeDev 账号」时,插件在重新读取余额的同时也重新读取模型列表,最多每分钟一次;余额照常立刻显示,不等模型列表。模型有变化时,选择器里的「VibeDev」组和设置页的「N 个模型」随即更新。没人操作时,仍按原来的方式在启动、登录或切换账号时以及每 30 分钟(`catalogRefreshMinutes`)读取一次,不会定时轮询。
84
84
 
85
+ ## Claude 提示词缓存(0.3.10)
86
+
87
+ 在「插件 → VibeDev 账号与模型」设置页的「Claude 提示词缓存」一节选择保留时间,改完点「保存」:
88
+
89
+ | 选项 | 请求行为 |
90
+ | --- | --- |
91
+ | 默认 | 保持 0.3.9 的缓存行为:已有 `cache_control: {type: "ephemeral"}` 不显式指定 `ttl`。不是关闭缓存。 |
92
+ | 5分钟 | 给已有缓存标记显式指定 `ttl: "5m"`。 |
93
+ | 1小时 | 给已有缓存标记显式指定 `ttl: "1h"`。 |
94
+
95
+ 该设置对应实时配置 `claudeCacheTtl: default | 5m | 1h`,只作用于 VibeDev 和「中转」组中使用 Anthropic Messages 协议的 Claude;GPT、DeepSeek、其他协议的缓存参数和所有模型 ID 保持不变。它只改写原有缓存断点,不增加断点,也不修改工具输入、JSON schema、历史消息或思考签名。设置保存后用于后续请求;已准备或开始的请求及其凭据续期重试沿用开始时的时长。离开设置页但未保存的修改会丢弃。
96
+
97
+ 模型和网关必须支持标准 Anthropic `cache_control.ttl`,网关须正确转发并结算 5分钟和1小时缓存;不需要新增模型目录字段。选择时长只是请求保留时间,不保证命中缓存。1小时缓存写入可能费用更高,实际价格、用量和扣费以网关为准,插件不在本地修改价格。网关拒绝所选时长时会显示原请求错误,不自动缩短 TTL 或重发;可回到设置页改选默认或5分钟。
98
+
99
+ 这是独立账号插件更新,无需重新打包桌面版。首次从桌面内置的账号插件升级时,需要完全退出并重新启动 VibeDev 一次(包括托盘);之后修改并保存该 TTL 设置即时用于后续请求,不需要再重启。
100
+
85
101
  ## 网页搜索
86
102
 
87
103
  插件注册了一个网页搜索提供方 `vibedev-gateway`,用你的 VibeDev 登录调用网关的搜索。注册不等于启用:DeepSeek Harness 默认仍用自己的搜索;想改用 VibeDev 的,在配置文件里把 `web` 一行的 `searchProvider` 设为 `vibedev-gateway`(VibeDev 应用默认就是这样)。搜索本身不收费,但余额为零时网关会拒绝所有请求,包括搜索。
@@ -137,6 +153,7 @@
137
153
  | --- | --- | --- |
138
154
  | 每次付费生成前先询问 | 关 | 打开后,每次媒体生成前先确认费用。 |
139
155
  | 保存目录 | `media` | 相对于工作区。 |
156
+ | Claude 提示词缓存保留时间 | 默认 | 可选默认、5分钟、1小时;保存后用于后续 Claude Messages 请求,默认不是关闭缓存。 |
140
157
  | 默认生图 / 视频 / 音乐 / 播客 / 语音合成 / 转写模型 | 空 | 留空时由 Agent 按模型目录选择;可以填模型 id 或别名。 |
141
158
 
142
159
  另有几项只能在配置文件(`cordis.patch.yml` 中 `dsh-vibedev` 一行)里改:`displayName`(普通模型分组名,默认 `VibeDev`)、`relayDisplayName`(中转模型分组名,默认「中转」)、`preferredModels`(排在最前的 VibeDev 模型)、`openBrowserOnSignIn`(登录时是否自动打开系统浏览器,默认开)、`catalogRefreshMinutes`(模型目录定时刷新间隔,默认 30 分钟;是没人打开余额卡片、账号菜单或设置时的兜底)、`client`(登录时报给网关的客户端名称,默认 `vibedev-plugin`)、`primary`(作为应用的主账号显示,默认关,VibeDev 应用里开)。
@@ -210,6 +227,8 @@ Everything is paid from your VibeDev balance; the DeepSeek account stays DeepSee
210
227
 
211
228
  **Image sizes and ratios for the film workbench (0.3.8)**: an image model in the gateway catalog may declare its size tiers and aspect ratios (`capabilities.image_sizes`, such as `["1K", "1.5K", "2K", "4K"]`, and `capabilities.image_ratios`, such as `["1:1", "16:9", "9:16"]`); `vibedevMedia.models()` now hands them over on that model as `imageSizes` and `imageRatios`, for the image node's pickers. Each model keeps its own lists exactly as the gateway writes them, in its order — nothing is invented, converted or sorted (`1.5K` and `3K` stay as they are) — with entries that are not text, are blank or repeat an earlier one left out. A model that declares nothing, an empty list or a malformed one carries neither field, and nothing else in the catalog is affected. The lists follow the catalog through its cache and every refresh, so options the gateway drops disappear. They are capabilities, never request parameters: an image request still sends only `model`, `prompt`, `n`, `size` (pixels) and `quality`, and video models keep their own `ratios` and `resolutions`.
212
229
 
230
+ **Claude prompt cache lifetime (0.3.10)**: on Plugins → VibeDev Account & Models, the separate Claude prompt caching section offers Default, 5 minutes and 1 hour. Save stages this as the live `claudeCacheTtl` setting (`default`, `5m`, `1h`). Default preserves the 0.3.9 request: existing ephemeral markers omit `ttl`; it does not disable caching. Explicit choices add `ttl: "5m"` or `ttl: "1h"` only to existing Anthropic cache breakpoints for Claude over Messages, in both the VibeDev and Relay groups. No new breakpoint is created. Tool inputs, JSON schemas, historical messages, thinking signatures, exact model IDs and non-Anthropic caching are unchanged. Saved changes apply to future requests; a prepared or started request and its credential-renewal retry keep the captured choice. Unsaved changes are discarded when the page closes. Model and gateway support for standard Anthropic `cache_control.ttl` is required, including correct forwarding and billing; no new catalog field is needed. The lifetime requests retention rather than guaranteeing a hit. One-hour writes may cost more; usage and actual charges come from the gateway, with no local repricing. A rejected lifetime keeps the original request error, with no silent fallback or resubmission at a shorter TTL; select Default or 5 minutes in settings. This is a plugin-only update. Upgrading the application's built-in account plugin requires one complete app restart (including the tray); subsequent TTL saves do not require a restart.
231
+
213
232
  **Web search**: the plugin registers the web search provider `vibedev-gateway`, signed in with your VibeDev account. Registering does not select it: DeepSeek Harness keeps its own search unless the profile sets `searchProvider: vibedev-gateway` on the `web` row (the VibeDev app does). Searching is free, but the gateway refuses every request, searches included, while the balance is zero.
214
233
 
215
234
  **Media tools**: `image_generate`, `video_generate` (runs as a background job), `audio_generate` (music, a podcast or speech), `audio_transcribe` (a multipart file upload; languages and limits as each model declares), `media_models`, `media_tasks` and `media_account`. Reference images, videos and audio, and first and last frames, can each be a workspace path, an http(s) link, or `chat:1` for the most recent matching file you attached. A request the model cannot serve is refused before anything is uploaded or charged.
@@ -1,4 +1,4 @@
1
- THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.3.9
1
+ THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.3.10
2
2
 
3
3
  This package bundles code from the projects below. Each is used under the licence that
4
4
  follows its name; the licence texts are reproduced as the projects ship them.
package/client/client.js CHANGED
@@ -739,6 +739,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
739
739
  confirmSpending: "每次付费生成前先询问",
740
740
  confirmSpendingHint: "开启后,生成图片、视频、音乐或播客之前会先请你确认,并显示模型和预估金额。默认关闭。",
741
741
  output: "保存位置",
742
+ claudeCache: "Claude 提示词缓存",
743
+ claudeCacheTtl: "缓存保留时间",
744
+ claudeCacheDefault: "默认",
745
+ claudeCache5m: "5分钟",
746
+ claudeCache1h: "1小时",
747
+ claudeCacheHint: "默认保持现有请求行为;5分钟或1小时只指定已有缓存标记的保留时间。适用于 VibeDev 和中转分组中走 Messages 协议的 Claude,需要模型和网关支持。保存后用于后续请求,不保证命中缓存。",
748
+ claudeCacheCostHint: "1小时缓存写入可能费用更高,实际以网关为准。若网关拒绝该时长,请改选默认或5分钟;插件不会自动缩短时长重试。",
742
749
  outputDir: "保存目录",
743
750
  outputDirHint: "相对当前工作区。图片、视频、音频和转写稿分别放在其中的 images、videos、audio、transcripts 子目录。清空后恢复为 media。",
744
751
  models: "默认媒体模型",
@@ -877,6 +884,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
877
884
  confirmSpending: "Ask before each paid generation",
878
885
  confirmSpendingHint: "When on, you are asked to confirm before an image, video, song or podcast is generated, with the model and the estimated price. Off by default.",
879
886
  output: "Where results go",
887
+ claudeCache: "Claude prompt caching",
888
+ claudeCacheTtl: "Cache lifetime",
889
+ claudeCacheDefault: "Default",
890
+ claudeCache5m: "5 minutes",
891
+ claudeCache1h: "1 hour",
892
+ claudeCacheHint: "Default preserves existing requests; 5 minutes or 1 hour sets the lifetime on existing cache markers only. Applies to Claude over Messages in the VibeDev and Relay groups; model and gateway support are required. Saved changes apply to future requests. This does not guarantee a cache hit.",
893
+ claudeCacheCostHint: "1-hour cache writes may cost more; actual charges come from the gateway. If the gateway rejects the lifetime, select Default or 5 minutes. The plugin never silently retries with a shorter lifetime.",
880
894
  outputDir: "Output folder",
881
895
  outputDirHint: "Relative to the workspace. Images, videos, audio and transcripts go into its images, videos, audio and transcripts folders. Clear it to go back to media.",
882
896
  models: "Default media models",
@@ -1286,6 +1300,14 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1286
1300
  });
1287
1301
  }
1288
1302
  //#endregion
1303
+ //#region src/llm/cache-ttl.ts
1304
+ /** Anthropic cache retention changes only existing cache-control markers in serialized content. */
1305
+ const CLAUDE_CACHE_TTLS = [
1306
+ "default",
1307
+ "5m",
1308
+ "1h"
1309
+ ];
1310
+ //#endregion
1289
1311
  //#region src/client/fields.ts
1290
1312
  /** The settings namespace: the plugin's profile entry id. */
1291
1313
  const SETTINGS_NAMESPACE = "dsh-vibedev";
@@ -1302,6 +1324,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1302
1324
  const FIELDS = [
1303
1325
  "confirmSpending",
1304
1326
  "outputDir",
1327
+ "claudeCacheTtl",
1305
1328
  ...MODEL_FIELDS
1306
1329
  ];
1307
1330
  /**
@@ -1339,11 +1362,29 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1339
1362
  }
1340
1363
  };
1341
1364
  }
1365
+ /**
1366
+ * Stage the three supported Claude cache lifetimes without silently accepting arbitrary text.
1367
+ * @returns the TTL field's conversion spec.
1368
+ */
1369
+ function claudeCacheTtlField() {
1370
+ return {
1371
+ field: "claudeCacheTtl",
1372
+ format: (value) => CLAUDE_CACHE_TTLS.find((choice) => choice === value) ?? "default",
1373
+ parse: (text) => {
1374
+ const choice = CLAUDE_CACHE_TTLS.find((choice) => choice === text.trim());
1375
+ return choice === void 0 ? void 0 : {
1376
+ kind: "set",
1377
+ value: choice
1378
+ };
1379
+ }
1380
+ };
1381
+ }
1342
1382
  /** The specs of every field the page edits. */
1343
1383
  function fieldSpecs() {
1344
1384
  return [
1345
1385
  booleanField("confirmSpending"),
1346
1386
  textField("outputDir"),
1387
+ claudeCacheTtlField(),
1347
1388
  ...MODEL_FIELDS.map(textField)
1348
1389
  ];
1349
1390
  }
@@ -1386,6 +1427,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1386
1427
  flex: 1,
1387
1428
  minWidth: 0
1388
1429
  },
1430
+ cacheRow: {
1431
+ display: "flex",
1432
+ alignItems: "center",
1433
+ flexWrap: "wrap",
1434
+ gap: 8,
1435
+ padding: "8px 0"
1436
+ },
1389
1437
  label: {
1390
1438
  fontSize: 13,
1391
1439
  fontWeight: 500,
@@ -1436,6 +1484,21 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1436
1484
  function MediaSettingsPage({ t, store, actions, account }) {
1437
1485
  const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot);
1438
1486
  const site = (0, react.useSyncExternalStore)(account.subscribe, account.getSnapshot).view?.links.register;
1487
+ const [cacheOpen, setCacheOpen] = (0, react.useState)(false);
1488
+ const cacheOptions = [
1489
+ {
1490
+ id: "default",
1491
+ label: t("claudeCacheDefault")
1492
+ },
1493
+ {
1494
+ id: "5m",
1495
+ label: t("claudeCache5m")
1496
+ },
1497
+ {
1498
+ id: "1h",
1499
+ label: t("claudeCache1h")
1500
+ }
1501
+ ];
1439
1502
  if (state.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1440
1503
  style: styles$1.quiet,
1441
1504
  role: "status",
@@ -1503,6 +1566,66 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1503
1566
  ...textField("outputDir")
1504
1567
  })
1505
1568
  }),
1569
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Section, {
1570
+ title: t("claudeCache"),
1571
+ hint: t("claudeCacheHint"),
1572
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1573
+ style: styles$1.cacheRow,
1574
+ children: [
1575
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1576
+ id: "dsh-vibedev-cache-ttl-label",
1577
+ style: styles$1.label,
1578
+ children: t("claudeCacheTtl")
1579
+ }),
1580
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1581
+ open: cacheOpen && !disabled,
1582
+ selectedId: state.fields.claudeCacheTtl.text,
1583
+ items: cacheOptions,
1584
+ portal: true,
1585
+ autoFocus: true,
1586
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1587
+ id: "dsh-vibedev-cache-ttl",
1588
+ type: "button",
1589
+ size: "sm",
1590
+ variant: "outline",
1591
+ disabled,
1592
+ "aria-labelledby": "dsh-vibedev-cache-ttl-label dsh-vibedev-cache-ttl-value",
1593
+ "aria-haspopup": "menu",
1594
+ "aria-expanded": cacheOpen && !disabled,
1595
+ onClick: () => {
1596
+ setCacheOpen((open) => !open);
1597
+ },
1598
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1599
+ id: "dsh-vibedev-cache-ttl-value",
1600
+ children: cacheOptions.find((choice) => choice.id === state.fields.claudeCacheTtl.text)?.label ?? t("claudeCacheDefault")
1601
+ })
1602
+ }),
1603
+ onClose: () => {
1604
+ setCacheOpen(false);
1605
+ },
1606
+ onSelect: (id) => {
1607
+ actions.edit("claudeCacheTtl", id);
1608
+ setCacheOpen(false);
1609
+ }
1610
+ }),
1611
+ state.fields.claudeCacheTtl.overridden && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1612
+ style: styles$1.quiet,
1613
+ children: t("overridden")
1614
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1615
+ type: "button",
1616
+ size: "sm",
1617
+ disabled,
1618
+ onClick: () => {
1619
+ actions.resetField("claudeCacheTtl");
1620
+ },
1621
+ children: t("reset")
1622
+ })] })
1623
+ ]
1624
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1625
+ style: styles$1.hint,
1626
+ children: state.fields.claudeCacheTtl.invalid ? t("invalid") : t("claudeCacheCostHint")
1627
+ })]
1628
+ }),
1506
1629
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Section, {
1507
1630
  title: t("models"),
1508
1631
  hint: t("modelsHint"),
package/lib/index.d.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  */
23
23
  import type { Context, Volatile } from '@deepseek-ai/cordis';
24
24
  import Schema from '@deepseek-ai/schemastery';
25
+ import { type ClaudeCacheTtl } from './llm/cache-ttl.js';
25
26
  export { MediaError } from './gateway/errors.js';
26
27
  export { MediaHostService } from './service.js';
27
28
  export type { HostTarget, MediaOutputView, MediaTaskView } from './service.js';
@@ -47,6 +48,8 @@ export interface Config {
47
48
  displayName: string;
48
49
  /** Name shown for relay chat models in model pickers. */
49
50
  relayDisplayName: string;
51
+ /** Requested cache lifetime for subsequent Claude Messages calls. */
52
+ claudeCacheTtl: Volatile<ClaudeCacheTtl>;
50
53
  /** VibeDev chat models listed first, in this order, when the catalog offers them. */
51
54
  preferredModels: string[];
52
55
  /** Open the system browser when a sign-in starts (off: the page opens the link itself). */
@@ -81,6 +84,7 @@ export interface Config {
81
84
  export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
82
85
  displayName: Schema<string, string, "defined">;
83
86
  relayDisplayName: Schema<string, string, "defined">;
87
+ claudeCacheTtl: Schema<"default" | "5m" | "1h", "default" | "5m" | "1h", "volatile-defined">;
84
88
  preferredModels: Schema<string[], string[], "defined">;
85
89
  openBrowserOnSignIn: Schema<boolean, boolean, "defined">;
86
90
  catalogRefreshMinutes: Schema<number, number, "defined">;
@@ -100,6 +104,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
100
104
  }>>, Schemastery.ObjectT<NoInfer<{
101
105
  displayName: Schema<string, string, "defined">;
102
106
  relayDisplayName: Schema<string, string, "defined">;
107
+ claudeCacheTtl: Schema<"default" | "5m" | "1h", "default" | "5m" | "1h", "volatile-defined">;
103
108
  preferredModels: Schema<string[], string[], "defined">;
104
109
  openBrowserOnSignIn: Schema<boolean, boolean, "defined">;
105
110
  catalogRefreshMinutes: Schema<number, number, "defined">;
package/lib/index.js CHANGED
@@ -4397,6 +4397,54 @@ async function* toStreamChunks(events, contextWindow, callerSignal, requestedMod
4397
4397
  throw new LlmError("pi-ai event stream ended without done/error", "STREAM_CLOSED");
4398
4398
  }
4399
4399
  //#endregion
4400
+ //#region src/llm/cache-ttl.ts
4401
+ /** Anthropic cache retention changes only existing cache-control markers in serialized content. */
4402
+ const CLAUDE_CACHE_TTLS = [
4403
+ "default",
4404
+ "5m",
4405
+ "1h"
4406
+ ];
4407
+ const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
4408
+ function cacheBlock(value, ttl, nested) {
4409
+ const block = object(value);
4410
+ if (block === void 0) return value;
4411
+ const marker = object(block.cache_control);
4412
+ const next = marker?.type === "ephemeral" ? {
4413
+ ...block,
4414
+ cache_control: {
4415
+ ...marker,
4416
+ ttl
4417
+ }
4418
+ } : { ...block };
4419
+ if (nested && Array.isArray(block.content)) next.content = block.content.map((child) => cacheBlock(child, ttl, true));
4420
+ const source = object(block.source);
4421
+ if (nested && block.type === "document" && source?.type === "content" && Array.isArray(source.content)) next.source = {
4422
+ ...source,
4423
+ content: source.content.map((child) => cacheBlock(child, ttl, true))
4424
+ };
4425
+ return next;
4426
+ }
4427
+ /**
4428
+ * Set an explicit TTL on the Anthropic payload's existing ephemeral cache breakpoints.
4429
+ * @param payload - serialized Anthropic request; borrowed, never mutated.
4430
+ * @param ttl - user preference captured for this request; default preserves the original payload.
4431
+ * @returns the original payload for default, or a copy with known cache-control slots updated.
4432
+ */
4433
+ function withClaudeCacheTtl(payload, ttl) {
4434
+ if (ttl === "default") return payload;
4435
+ const next = { ...payload };
4436
+ if (Array.isArray(payload.system)) next.system = payload.system.map((block) => cacheBlock(block, ttl, true));
4437
+ if (Array.isArray(payload.tools)) next.tools = payload.tools.map((tool) => cacheBlock(tool, ttl, false));
4438
+ if (Array.isArray(payload.messages)) next.messages = payload.messages.map((value) => {
4439
+ const message = object(value);
4440
+ return message !== void 0 && Array.isArray(message.content) ? {
4441
+ ...message,
4442
+ content: message.content.map((block) => cacheBlock(block, ttl, true))
4443
+ } : value;
4444
+ });
4445
+ return next;
4446
+ }
4447
+ //#endregion
4400
4448
  //#region \0@oxc-project+runtime@0.152.0/helpers/esm/usingCtx.js
4401
4449
  function _usingCtx() {
4402
4450
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
@@ -4601,19 +4649,24 @@ var GatewayAdapter = class extends LlmAdapter {
4601
4649
  }
4602
4650
  prepareCall(provider, model, _signal) {
4603
4651
  const snapshot = this.current();
4652
+ const claudeCacheTtl = this.cacheTtlFor(this.modelOf(snapshot, provider, model).model);
4604
4653
  return Promise.resolve({
4605
4654
  model: this.modelInfo(snapshot, provider, model),
4606
- stream: (options) => this.streamWithSnapshot(options, snapshot)
4655
+ stream: (options) => this.streamWithSnapshot(options, snapshot, claudeCacheTtl)
4607
4656
  });
4608
4657
  }
4609
4658
  stream(options) {
4610
4659
  return this.streamWithSnapshot(options, this.current());
4611
4660
  }
4612
- async *streamWithSnapshot(options, snapshot) {
4661
+ cacheTtlFor(model) {
4662
+ return model.api === "anthropic-messages" && relayIdentity(model.id).baseId.toLowerCase().startsWith("claude") ? this.config.claudeCacheTtl?.() ?? "default" : "default";
4663
+ }
4664
+ async *streamWithSnapshot(options, snapshot, preparedTtl) {
4613
4665
  try {
4614
4666
  var _usingCtx$1 = _usingCtx();
4615
4667
  if (options.stop !== void 0) throw new LlmError("the VibeDev gateway adapter does not support GenerateOptions.stop", "UNSUPPORTED_OPTION");
4616
4668
  const { model, catalog } = this.modelOf(snapshot, options.provider, options.model);
4669
+ const claudeCacheTtl = preparedTtl ?? this.cacheTtlFor(model);
4617
4670
  const starting = startingReasoning(catalog);
4618
4671
  const reasoning = resolveReasoningLevel(model, options.reasoningEffort ?? (starting === void 0 ? void 0 : effortOf(starting)));
4619
4672
  let credential = await this.config.resolveCredential();
@@ -4691,7 +4744,8 @@ var GatewayAdapter = class extends LlmAdapter {
4691
4744
  onPayload: (payload) => this.shapePayload(payload, model, {
4692
4745
  ...sessionId === void 0 ? {} : { sessionId },
4693
4746
  off: reasoning === "off" && offersNone,
4694
- reasoning: enabledReasoning !== void 0
4747
+ reasoning: enabledReasoning !== void 0,
4748
+ claudeCacheTtl
4695
4749
  }),
4696
4750
  fetch: observingFetch,
4697
4751
  onResponse: (received) => {
@@ -4780,6 +4834,8 @@ var GatewayAdapter = class extends LlmAdapter {
4780
4834
  effort: "none"
4781
4835
  };
4782
4836
  if (request.reasoning || request.off) delete shaped.temperature;
4837
+ break;
4838
+ case "anthropic-messages": return withClaudeCacheTtl(shaped, request.claudeCacheTtl);
4783
4839
  }
4784
4840
  return shaped;
4785
4841
  }
@@ -4904,6 +4960,7 @@ function installGatewayModels(ctx, options) {
4904
4960
  rejectCredential: options.rejectCredential,
4905
4961
  deviceId: options.deviceId,
4906
4962
  cacheRetention: options.cacheRetention ?? "short",
4963
+ claudeCacheTtl: options.claudeCacheTtl,
4907
4964
  resolveAttachments: () => ctx.get("attachments"),
4908
4965
  resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, (hostPath) => ctx.get("fs")?.processPathFromHostPath(hostPath), ref),
4909
4966
  onReplayDegrade: ({ provider, model, reason }) => {
@@ -10954,6 +11011,7 @@ const inject = ["tools"];
10954
11011
  const Config = Schema.object({
10955
11012
  displayName: Schema.string().default("VibeDev"),
10956
11013
  relayDisplayName: Schema.string().default("中转"),
11014
+ claudeCacheTtl: Schema.union(CLAUDE_CACHE_TTLS.map((value) => Schema.const(value))).default("default").volatile(),
10957
11015
  preferredModels: Schema.array(Schema.string()).default([]),
10958
11016
  openBrowserOnSignIn: Schema.boolean().default(true),
10959
11017
  catalogRefreshMinutes: Schema.number().min(1).max(1440).default(30),
@@ -10974,6 +11032,7 @@ const Config = Schema.object({
10974
11032
  "zh-CN": {
10975
11033
  displayName: "模型选择器里显示的名称",
10976
11034
  relayDisplayName: "中转模型分组名称",
11035
+ claudeCacheTtl: "Claude 提示词缓存保留时间(默认 / 5分钟 / 1小时)",
10977
11036
  preferredModels: "排在最前的 VibeDev 模型(按顺序,留空按网关顺序)",
10978
11037
  openBrowserOnSignIn: "登录时自动打开系统浏览器",
10979
11038
  catalogRefreshMinutes: "模型目录定时刷新间隔(分钟;没人打开余额卡片、账号菜单或设置时的兜底)",
@@ -10994,6 +11053,7 @@ const Config = Schema.object({
10994
11053
  "en-US": {
10995
11054
  displayName: "Name the model pickers show",
10996
11055
  relayDisplayName: "Relay model group name",
11056
+ claudeCacheTtl: "Claude prompt cache lifetime (default / 5 minutes / 1 hour)",
10997
11057
  preferredModels: "VibeDev models listed first, in this order (empty: the gateway's order)",
10998
11058
  openBrowserOnSignIn: "Open the system browser when signing in",
10999
11059
  catalogRefreshMinutes: "Model catalog refresh interval in minutes (the fallback when nobody opens the balance card, the account menu or Settings)",
@@ -11112,6 +11172,7 @@ function apply(ctx, config) {
11112
11172
  origin,
11113
11173
  displayName: config.displayName,
11114
11174
  relayDisplayName: config.relayDisplayName,
11175
+ claudeCacheTtl: () => config.claudeCacheTtl.get(),
11115
11176
  resolveCredential: () => chain.resolve(),
11116
11177
  rejectCredential: (credential) => chain.reject(credential),
11117
11178
  deviceId: () => storage.deviceId(),
@@ -28,6 +28,7 @@ import { LlmAdapter } from '@deepseek-ai/dsh-llm';
28
28
  import type { GenerateOptions, ImageAttachmentAccess, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, PreparedAdapterCall, ResolvedRetryPolicy, StreamChunk } from '@deepseek-ai/dsh-llm';
29
29
  import type { AttachmentStore, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
30
30
  import type { GatewayModel } from './catalog.js';
31
+ import { type ClaudeCacheTtl } from './cache-ttl.js';
31
32
  /** The credential for one request. */
32
33
  export interface GatewayCredential {
33
34
  readonly token: string;
@@ -85,6 +86,8 @@ export interface GatewayAdapterOptions {
85
86
  readonly retryPolicy?: () => ResolvedRetryPolicy | undefined;
86
87
  readonly streamIdleTimeoutMs?: number;
87
88
  readonly cacheRetention?: 'none' | 'short' | 'long';
89
+ /** Saved Claude Messages cache TTL, captured once before this request first awaits. */
90
+ readonly claudeCacheTtl?: () => ClaudeCacheTtl;
88
91
  readonly resolveAttachments?: () => AttachmentStore | undefined;
89
92
  readonly resolveImageAccess?: (attachments: AttachmentStore, ref: ImageAttachmentRef) => ImageAttachmentAccess | undefined;
90
93
  readonly onReplayDegrade?: (detail: {
@@ -114,6 +117,7 @@ export declare class GatewayAdapter extends LlmAdapter {
114
117
  private modelInfo;
115
118
  prepareCall(provider: string, model: string, _signal?: AbortSignal): Promise<PreparedAdapterCall>;
116
119
  stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
120
+ private cacheTtlFor;
117
121
  private streamWithSnapshot;
118
122
  /**
119
123
  * Fit pi-ai's payload to the gateway: Chat Completions gets the session's cache key (pi-ai sends it
@@ -0,0 +1,10 @@
1
+ /** Anthropic cache retention changes only existing cache-control markers in serialized content. */
2
+ export declare const CLAUDE_CACHE_TTLS: readonly ["default", "5m", "1h"];
3
+ export type ClaudeCacheTtl = typeof CLAUDE_CACHE_TTLS[number];
4
+ /**
5
+ * Set an explicit TTL on the Anthropic payload's existing ephemeral cache breakpoints.
6
+ * @param payload - serialized Anthropic request; borrowed, never mutated.
7
+ * @param ttl - user preference captured for this request; default preserves the original payload.
8
+ * @returns the original payload for default, or a copy with known cache-control slots updated.
9
+ */
10
+ export declare function withClaudeCacheTtl(payload: Record<string, unknown>, ttl: ClaudeCacheTtl): Record<string, unknown>;
@@ -22,6 +22,7 @@
22
22
  import type { Context } from '@deepseek-ai/cordis';
23
23
  import type { GatewayCredential } from './adapter.js';
24
24
  import type { GatewayModel } from './catalog.js';
25
+ import type { ClaudeCacheTtl } from './cache-ttl.js';
25
26
  export { GatewayAdapter, INSUFFICIENT_BALANCE_CODE, SIGN_IN_REQUIRED_CODE } from './adapter.js';
26
27
  export type { GatewayAdapterOptions, GatewayCredential } from './adapter.js';
27
28
  export { parseCatalog } from './catalog.js';
@@ -51,6 +52,8 @@ export interface GatewayModelsOptions {
51
52
  readonly catalogRefreshMinutes?: number;
52
53
  readonly catalogTimeoutMs?: number;
53
54
  readonly cacheRetention?: 'none' | 'short' | 'long';
55
+ /** Saved Claude Messages cache TTL; default leaves the SDK's markers unchanged. */
56
+ readonly claudeCacheTtl?: () => ClaudeCacheTtl;
54
57
  /** A model request that may have been charged ended (the account reads the balance again). */
55
58
  readonly onRequestEnded?: () => void;
56
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedev-si/dsh-vibedev",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "VibeDev 账号与模型:在 DeepSeek Harness 里登录 VibeDev,与 DeepSeek 账号并存,使用 VibeDev 网关的模型(Claude、GPT 等),并生成图片、视频、音乐和播客 · VibeDev account and models for DeepSeek Harness: sign in to VibeDev next to the DeepSeek account and use the VibeDev gateway's models (Claude, GPT and more), plus image, video, music and podcast generation",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",