@vibedev-si/dsh-vibedev 0.7.0 → 0.7.2

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
@@ -10,6 +10,14 @@
10
10
 
11
11
  本插件由 `dsh-media` 改名而来,见下面的「从 dsh-media 升级」。
12
12
 
13
+ ## 0.7.2 用户可见更新
14
+
15
+ 上下文窗口现在就是网关下发的输入上限(`max_input_tokens`):1M 的模型显示 1M,不再显示 1.34M。宿主的自动压缩仍然落在窗口的 80%(宿主自己的 0.8 阈值),所以看到 80% 就是该压缩的时候,不会再出现「表上还剩四分之一、请求却被网关拒掉」的情况。
16
+
17
+ 阈值之所以能落在 80%,是因为插件现在把每次请求的输出预留也交给宿主了:网关按「消息 + 输出预留」计算同一个窗口(一次 655K 消息配 393K 预留就被判超窗),而之前宿主不知道这份预留,按消息独占全窗来算。现在预留收在窗口的 20% 以内(1M 窗口是 128K):压缩点是窗口的 80%,也就是 800K 消息,加上预留一共约 930K,仍在模型 1.05M 的合并上限之内;之前预留 393K,同一个压缩点合起来要 1.19M,根本发不出去。
18
+
19
+ 供应商返回「prompt is too long: N tokens > M maximum」这类超窗错误时,仍然会被识别成上下文超限:宿主会先压缩再重试一次这次请求,而不是把它判成不可重试的错误。
20
+
13
21
  ## 0.7.0 用户可见更新
14
22
 
15
23
  账户中心新增「消息」页:VibeDev 的版本更新、服务调整和账号通知都发在这里。有未读时,侧栏账号头像右上角出现红点,账号菜单里的「消息」一行带上未读数。`popup` 类型的公告一次启动最多弹一次:「知道了」发出已读回执,「稍后」和「查看全部消息」只关掉弹窗、不标为已读,红点和未读数会留着。网关还没上线这两个读取接口时,这一块安静地不出现,其它功能不受影响。见[消息读取契约](docs/announcements-read-contract.md)。
@@ -334,6 +342,14 @@ npm run build
334
342
 
335
343
  ## English
336
344
 
345
+ ### What changes in 0.7.2
346
+
347
+ The context window is now exactly the input cap the gateway states (`max_input_tokens`): a 1M model reads 1M, not 1.34M. The host still compacts at 80% of that window — its own 0.8 ratio — so 80% on the meter is where compaction happens, and a request no longer gets refused while the meter still shows a third of the window free.
348
+
349
+ That ratio only lands at 80% because the plugin now reports each request's completion reserve to the host as well: the gateway prices `messages + completion` against one window (655K of messages with a 393K reserve was refused), while the host, not knowing that reserve, priced the whole window as input. The reserve is now kept under 20% of the window (128K for a 1M window): the trigger is 80% of the window, 800K of messages, and the request released there is about 930K including the reserve — still inside the model's 1.05M combined limit. The old 393K reserve would have made the same trigger cost 1.19M, which could never be sent.
350
+
351
+ A provider overflow such as "prompt is too long: N tokens > M maximum" is still classified as a context-window failure, so the host compacts once and retries that request instead of treating the turn as a non-retryable error.
352
+
337
353
  ### What changes in 0.7.0
338
354
 
339
355
  The account center gains a Messages page for VibeDev's version updates, service changes and account notices. While something is unread, the sidebar avatar carries a red dot and the account menu's Messages row shows the count. A `popup` announcement interrupts at most once per launch: Got it sends the read receipt, while Later and See all messages only close it and mark nothing read, so the dot and the count stay. Until the gateway serves these reads the whole thing stays quiet. See the [messages read contract](docs/announcements-read-contract.md).
@@ -1,4 +1,4 @@
1
- THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.7.0
1
+ THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.7.2
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/lib/index.js CHANGED
@@ -5244,12 +5244,14 @@ function parseCatalog(body) {
5244
5244
  const levels = reasoningLevelsOf(capabilities.reasoning_levels);
5245
5245
  const defaultReasoning = typeof capabilities.default_reasoning === "string" && levels?.includes(capabilities.default_reasoning) ? capabilities.default_reasoning : void 0;
5246
5246
  const inputs = strings$1(capabilities.input_modalities) ?? [];
5247
+ const maxInputTokens = positive$2(capabilities.max_input_tokens);
5247
5248
  seen.add(id);
5248
5249
  models.push({
5249
5250
  id,
5250
5251
  name: modelDisplayName(id, typeof entry.display_name === "string" && entry.display_name.trim() !== "" ? entry.display_name.trim() : void 0),
5251
5252
  api,
5252
5253
  contextWindow: positive$2(capabilities.context_window) ?? 2e5,
5254
+ ...maxInputTokens === void 0 ? {} : { maxInputTokens },
5253
5255
  maxTokens: positive$2(capabilities.max_output_tokens) ?? 32768,
5254
5256
  input: inputs.includes("image") ? ["text", "image"] : ["text"],
5255
5257
  ...levels === void 0 ? {} : { reasoningLevels: levels },
@@ -5877,6 +5879,64 @@ const openAICompletionsApi = () => lazyApi(() => import("./openai-completions-Dq
5877
5879
  //#region node_modules/@earendil-works/pi-ai/dist/api/openai-responses.lazy.js
5878
5880
  const openAIResponsesApi = () => lazyApi(() => import("./openai-responses-DygWnsye.js"));
5879
5881
  //#endregion
5882
+ //#region src/llm/context-budget.ts
5883
+ /** The host compaction default reserve below the message budget (`headroomTokens`). */
5884
+ const HOST_HEADROOM_TOKENS = 65536;
5885
+ /** A completion below this trades too much of the model's own output for compaction timing. */
5886
+ const MIN_COMPLETION_TOKENS = 32768;
5887
+ /** The trigger never falls below this share of the window, however tight the headroom gets. */
5888
+ const MIN_THRESHOLD_SHARE = .1;
5889
+ /** A derived completion is stated in whole blocks, so the reserve reads like a limit. */
5890
+ const COMPLETION_STEP = 4096;
5891
+ /**
5892
+ * The window to report to the host: the input the provider will actually take.
5893
+ *
5894
+ * This is deliberately *not* sized to move the host's trigger; the trigger is moved by the
5895
+ * completion reserve instead, so the number on screen keeps meaning "input left".
5896
+ * @param budget - the catalog's capacity and input cap.
5897
+ * @param fallback - window for a catalog that states no capacity at all.
5898
+ * @returns a positive token count to declare as the model's context window.
5899
+ */
5900
+ function declaredContextWindow(budget, fallback) {
5901
+ const window = budget.contextWindow;
5902
+ const cap = budget.maxInputTokens;
5903
+ if (window === void 0) return Math.max(1, cap ?? fallback);
5904
+ if (cap === void 0) return Math.max(1, window);
5905
+ return Math.max(1, Math.min(window, cap));
5906
+ }
5907
+ /**
5908
+ * The completion to report and to request per call.
5909
+ *
5910
+ * An output the catalog already keeps under the reserve is left alone. A larger one is capped at
5911
+ * the reserve, so the host's ratio decides the trigger and `messages + completion` stays inside
5912
+ * the provider's combined limit. A window too small for the ratio keeps a workable floor and lets
5913
+ * the trigger fall earlier, and never reports a completion that would leave no pressure budget.
5914
+ * @param budget - the catalog's output and capacity.
5915
+ * @param contextWindow - the window declared by {@link declaredContextWindow}.
5916
+ * @returns the completion tokens one request may reserve.
5917
+ */
5918
+ function declaredCompletionTokens(budget, contextWindow) {
5919
+ const room = Math.floor(contextWindow * .19999999999999996) - HOST_HEADROOM_TOKENS;
5920
+ const safe = contextWindow - HOST_HEADROOM_TOKENS - Math.max(1, Math.floor(contextWindow * MIN_THRESHOLD_SHARE));
5921
+ const limit = Math.max(1, Math.min(Math.max(room, MIN_COMPLETION_TOKENS), safe));
5922
+ if (budget.maxTokens <= limit) return Math.max(1, budget.maxTokens);
5923
+ return Math.max(1, Math.floor(limit / COMPLETION_STEP) * COMPLETION_STEP);
5924
+ }
5925
+ /**
5926
+ * Both numbers an adapter model reports, kept together so the window and its reserve never
5927
+ * disagree.
5928
+ * @param budget - the catalog's capacity, input cap and output.
5929
+ * @param fallback - window for a catalog that states no capacity at all.
5930
+ * @returns the window and the completion to declare.
5931
+ */
5932
+ function declaredBudget(budget, fallback) {
5933
+ const contextWindow = declaredContextWindow(budget, fallback);
5934
+ return {
5935
+ contextWindow,
5936
+ maxTokens: declaredCompletionTokens(budget, contextWindow)
5937
+ };
5938
+ }
5939
+ //#endregion
5880
5940
  //#region src/llm/models.ts
5881
5941
  /**
5882
5942
  * pi-ai model descriptors and the multi-protocol provider for the gateway.
@@ -5971,6 +6031,11 @@ function toPiModel(model, provider, origin) {
5971
6031
  const levels = model.reasoningLevels ?? [];
5972
6032
  const reasoning = levels.length > 0;
5973
6033
  const compat = compatOf(model);
6034
+ const budget = declaredBudget({
6035
+ contextWindow: model.contextWindow,
6036
+ ...model.maxInputTokens === void 0 ? {} : { maxInputTokens: model.maxInputTokens },
6037
+ maxTokens: model.maxTokens
6038
+ }, model.contextWindow);
5974
6039
  return {
5975
6040
  id: model.id,
5976
6041
  name: model.name,
@@ -5981,8 +6046,8 @@ function toPiModel(model, provider, origin) {
5981
6046
  ...reasoning ? { thinkingLevelMap: thinkingLevelMap(levels) } : {},
5982
6047
  input: [...model.input],
5983
6048
  cost: { ...model.cost },
5984
- contextWindow: model.contextWindow,
5985
- maxTokens: model.maxTokens,
6049
+ contextWindow: budget.contextWindow,
6050
+ maxTokens: budget.maxTokens,
5986
6051
  ...compat === void 0 ? {} : { compat }
5987
6052
  };
5988
6053
  }
@@ -6085,9 +6150,23 @@ function mapUsage(usage) {
6085
6150
  ...usage.cacheWrite > 0 ? { cacheWriteTokens: usage.cacheWrite } : {}
6086
6151
  };
6087
6152
  }
6153
+ /**
6154
+ * Provider wordings for a request that outgrew the model's context window and that
6155
+ * {@link isContextWindowExceededError} does not know. Anthropic's Messages API answers
6156
+ * `prompt is too long: 1025721 tokens > 1000000 maximum`, which matches none of its patterns;
6157
+ * classified as a generic 400 this failure is non-retryable, so the host never gets the chance to
6158
+ * compact and retry the request it could still serve.
6159
+ */
6160
+ const PROMPT_OVER_LIMIT = /\b(?:prompt|input|messages?|request)\b[^.]{0,40}\btoo\s+(?:long|large)\b|\b\d+\s*tokens?\s*>\s*\d+\s*(?:maximum|max)\b/i;
6161
+ /**
6162
+ * Classify one pi-ai error message into the harness failure code it should carry.
6163
+ * @param message - the flattened provider error text pi-ai hands over.
6164
+ * @returns the harness code for this failure.
6165
+ */
6088
6166
  function classifyPiAiError(message) {
6089
6167
  if (/\b(?:401|403)\b/.test(message)) return "AUTH";
6090
6168
  if (isQuotaExceededError(message)) return QUOTA_EXCEEDED_CODE;
6169
+ if (isContextWindowExceededError(message) || PROMPT_OVER_LIMIT.test(message)) return CONTEXT_WINDOW_EXCEEDED_CODE;
6091
6170
  if (/\b429\b|rate.?limit/i.test(message)) return "RATE_LIMIT";
6092
6171
  if (/\b413\b|failed to buffer the request body:\s*length limit exceeded|payload too large|request body too large/i.test(message)) return "INVALID_REQUEST";
6093
6172
  if (/\b400\b|invalid.?request/i.test(message)) return "INVALID_REQUEST";
@@ -6540,6 +6619,7 @@ var GatewayAdapter = class extends LlmAdapter {
6540
6619
  name: model.name,
6541
6620
  inputModalities: [...model.input],
6542
6621
  context: { contextWindow: model.contextWindow },
6622
+ defaultMaxTokens: model.maxTokens,
6543
6623
  ...reasoningInfo(model, catalog)
6544
6624
  };
6545
6625
  }
@@ -23,6 +23,8 @@ export interface GatewayModel {
23
23
  /** The protocol requests for this model use. */
24
24
  readonly api: GatewayApi;
25
25
  readonly contextWindow: number;
26
+ /** The provider input cap the gateway states (`max_input_tokens`), when it states one. */
27
+ readonly maxInputTokens?: number;
26
28
  readonly maxTokens: number;
27
29
  readonly input: readonly ('text' | 'image')[];
28
30
  /**
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The capacity and completion budget one catalog model reports to the host.
3
+ *
4
+ * The host's `basic-compaction` reads two numbers from the adapter model and charges both to the
5
+ * same window: the window itself, and the completion the route reserves per request (the request
6
+ * header's `maxTokens`, else the adapter's `defaultMaxTokens`). It compacts at
7
+ * `min(thresholdRatio × window, window − completion − headroomTokens)`, defaulting to `0.8` and
8
+ * `65,536`. The gateway prices a request the same way: `messages + completion` against the
9
+ * provider's own combined limit.
10
+ *
11
+ * Two rules follow:
12
+ *
13
+ * - The window is the input the provider really takes (`max_input_tokens`), because the context
14
+ * meter divides pressure by it. Declaring more — the previous `input + completion` sizing that
15
+ * moved the ratio alone — made a request already at the real input budget read as two thirds of
16
+ * the way through, and pushed the host's trigger above the cap it was meant to respect.
17
+ * - The completion must fit under `window × (1 − thresholdRatio) − headroomTokens`, or the host
18
+ * subtracts it from the pressure budget and compacts early, while a request near the trigger
19
+ * overshoots the provider's combined limit by the completion it asked for.
20
+ *
21
+ * Both cannot always hold: a small window with the fixed 65,536 headroom cannot reach the ratio.
22
+ * There the completion wins a floor and the trigger lands lower, which is safe but earlier.
23
+ *
24
+ * @module dsh-vibedev/llm/context-budget
25
+ */
26
+ /** The host compaction default this arithmetic is written against (`thresholdRatio`). */
27
+ export declare const HOST_THRESHOLD_RATIO = 0.8;
28
+ /** The host compaction default reserve below the message budget (`headroomTokens`). */
29
+ export declare const HOST_HEADROOM_TOKENS = 65536;
30
+ /** A completion below this trades too much of the model's own output for compaction timing. */
31
+ export declare const MIN_COMPLETION_TOKENS = 32768;
32
+ /** What the catalog says about one model's capacity. */
33
+ export interface CatalogBudget {
34
+ /** Catalog capacity, when it states one. */
35
+ readonly contextWindow?: number;
36
+ /** The provider input cap the gateway states (`max_input_tokens`), when it states one. */
37
+ readonly maxInputTokens?: number;
38
+ /** Output the catalog reserves per request. */
39
+ readonly maxTokens: number;
40
+ }
41
+ /** The two numbers one adapter model hands the host. */
42
+ export interface DeclaredBudget {
43
+ /** The window the context meter divides by and compaction starts from. */
44
+ readonly contextWindow: number;
45
+ /** The completion every request reserves inside that window. */
46
+ readonly maxTokens: number;
47
+ }
48
+ /**
49
+ * The window to report to the host: the input the provider will actually take.
50
+ *
51
+ * This is deliberately *not* sized to move the host's trigger; the trigger is moved by the
52
+ * completion reserve instead, so the number on screen keeps meaning "input left".
53
+ * @param budget - the catalog's capacity and input cap.
54
+ * @param fallback - window for a catalog that states no capacity at all.
55
+ * @returns a positive token count to declare as the model's context window.
56
+ */
57
+ export declare function declaredContextWindow(budget: CatalogBudget, fallback: number): number;
58
+ /**
59
+ * The completion to report and to request per call.
60
+ *
61
+ * An output the catalog already keeps under the reserve is left alone. A larger one is capped at
62
+ * the reserve, so the host's ratio decides the trigger and `messages + completion` stays inside
63
+ * the provider's combined limit. A window too small for the ratio keeps a workable floor and lets
64
+ * the trigger fall earlier, and never reports a completion that would leave no pressure budget.
65
+ * @param budget - the catalog's output and capacity.
66
+ * @param contextWindow - the window declared by {@link declaredContextWindow}.
67
+ * @returns the completion tokens one request may reserve.
68
+ */
69
+ export declare function declaredCompletionTokens(budget: CatalogBudget, contextWindow: number): number;
70
+ /**
71
+ * Both numbers an adapter model reports, kept together so the window and its reserve never
72
+ * disagree.
73
+ * @param budget - the catalog's capacity, input cap and output.
74
+ * @param fallback - window for a catalog that states no capacity at all.
75
+ * @returns the window and the completion to declare.
76
+ */
77
+ export declare function declaredBudget(budget: CatalogBudget, fallback: number): DeclaredBudget;
@@ -20,6 +20,12 @@ import type { AssistantMessage, AssistantMessageEvent, Usage as PiUsage } from '
20
20
  * when non-zero (pi-ai reports zeros, not absence).
21
21
  */
22
22
  export declare function mapUsage(usage: PiUsage): TokenUsage;
23
+ /**
24
+ * Classify one pi-ai error message into the harness failure code it should carry.
25
+ * @param message - the flattened provider error text pi-ai hands over.
26
+ * @returns the harness code for this failure.
27
+ */
28
+ export declare function classifyPiAiError(message: string): string;
23
29
  /**
24
30
  * Map a terminal pi-ai event to the harness finish reason.
25
31
  * @param message - the assistant message carried by the `done` or `error` event.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedev-si/dsh-vibedev",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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",