@namzu/openrouter 3.1.2 → 3.2.1
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/CHANGELOG.md +13 -0
- package/README.md +17 -0
- package/dist/client.d.ts +31 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +464 -50
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +542 -52
- package/src/types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- daa889c: An OpenRouter failure now says which upstream host refused the request and its code (for example `host AcmeCloud, code bad_param`), on an HTTP error and on an error that arrives mid-stream, so a person can tell a host's refusal from the router's. The host's raw echo of the request is still never shown. Cache writes are now counted for models with explicit caching (`prompt_tokens_details.cache_write_tokens`, used when the older field is absent; the prompt size is unchanged). A thinking budget is no longer sent at or above the request's output limit: with an output limit above 1024 it is brought under it, and a budget under 1024 is raised to 1024; effort-mode requests are untouched.
|
|
8
|
+
- f9ff8e8: Through OpenRouter, a DeepSeek V4 sub-agent no longer ends with the vendor's HTTP 400 "Thinking mode does not support this tool_choice", and choosing effort `max` or `ultra` no longer throws. The OpenRouter driver leaves a forced tool choice (`required` or a named function) off the request for the models that refuse it while they reason, and when a host answers a forced choice with a 400 that names `tool_choice` it sends the request once more without it (`auto` and `none` are untouched, and a host that accepts the choice still gets it). Effort `max` and `ultra` now send the highest level the model's OpenRouter listing names (`max` for DeepSeek V4.1 Flash), or `xhigh` when the listing cannot be read. `OpenRouterConfig` gains an optional `logger` for the driver's debug lines. In the SDK, a tool choice set by a step (`prepareStep`) is now asked of the provider with `acceptsForcedToolChoiceFor`, as the loop's own forced step already was, and is not sent when the provider says it refuses it. Nothing is removed; a request that used to fail now succeeds. One behaviour changes for any provider that answers `acceptsForcedToolChoiceFor` with `false` (the DeepSeek driver with thinking on, Anthropic models that refuse a forced choice): a `prepareStep` choice of `required` or a named function used to fail the step with the provider's refusal, and is now left off the request, with one line added in words that the reply must be a tool call. A caller that wants the hard failure back checks the choice itself before returning it from `prepareStep`.
|
|
9
|
+
|
|
10
|
+
## 3.2.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 0cd29d8: Through OpenRouter, the model now keeps its train of thought between the steps of a turn: the assistant message goes back with its `reasoning_details` exactly as the model produced them, for the steps after the turn's last user message (an earlier turn's reasoning is not resent), where each step used to start from its own tool calls alone. The ledger, `/cost` and a spend limit now see real money for a model your price table does not know (a model id with a revision suffix used to show `$0.00` with every token unpriced): the driver reads the charge OpenRouter reports on each response, and the SDK records it as the call's cost ahead of any price table, which stays the fallback for a call that reports nothing. New and additive: `TokenUsage.reportedCostUsd`, `ProviderCapabilities.reportsRequestCost`, and `accumulateReportedCost`; a `costLimitUsd` is now accepted for an unpriced model on a provider that declares it. The SDK's window table names the DeepSeek `v4.1-flash`, `v4.1-flash-1017`, `v4-flash-0731` and `v4-pro-0813` ids at their documented 1M tokens (they were compacted at 64k when the provider's own list was not consulted), and the OpenRouter driver finds a `:tag` variant's window from its base id. The OpenRouter driver also answers `acceptsForcedToolChoiceFor` for DeepSeek V4 and reasoner models, so a step that must call a tool is asked in words rather than forced while they think. An advisor on a model with no price row now reports the charge the provider reported instead of unpriced tokens. Nothing is removed or changes meaning.
|
|
15
|
+
|
|
3
16
|
## 3.1.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -94,6 +94,23 @@ the thinking share of the completion tokens OpenRouter already bills as output.
|
|
|
94
94
|
sends each fragment twice (a flat `reasoning` string and the indexed `reasoning_details`);
|
|
95
95
|
the driver emits it once.
|
|
96
96
|
|
|
97
|
+
Between the steps of one turn the model's reasoning goes back to it. OpenRouter's guide says
|
|
98
|
+
to send the assistant message with its `reasoning_details` unmodified, so the driver keeps the
|
|
99
|
+
entries as the wire sent them in the message's replay state (a `namzu-openrouter-reasoning`
|
|
100
|
+
envelope that names its route) and sends them on the assistant messages after the turn's last
|
|
101
|
+
user message. A route that sends only the flat string gets `reasoning` back instead. An earlier
|
|
102
|
+
turn's reasoning is not resent, and state that names another route or no longer matches the
|
|
103
|
+
stored reasoning is ignored.
|
|
104
|
+
|
|
105
|
+
## Cost and window
|
|
106
|
+
|
|
107
|
+
Every response states what the request was charged (`usage.cost`). The driver reports it as
|
|
108
|
+
`usage.reportedCostUsd`, and the kernel records it as the call's cost, ahead of any price table,
|
|
109
|
+
so a model with no price row still shows real money (and a cost limit works for it). A model's
|
|
110
|
+
context window comes from OpenRouter's model list (`context_length`) before the SDK's name table.
|
|
111
|
+
For the DeepSeek V4 and reasoner ids, `acceptsForcedToolChoiceFor` answers `false` while thinking
|
|
112
|
+
is on, so the kernel asks for a tool call in words instead of forcing one.
|
|
113
|
+
|
|
97
114
|
## Documentation
|
|
98
115
|
|
|
99
116
|
- [Namzu docs](https://github.com/cogitave/namzu/tree/main/docs)
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatCompletionParams, LLMProvider, ModelInfo, ProviderCapabilities, StreamChunk } from '@namzu/sdk';
|
|
1
|
+
import type { ChatCompletionParams, LLMProvider, ModelInfo, ProviderCapabilities, ReasoningEffort, StreamChunk, ThinkingConfig } from '@namzu/sdk';
|
|
2
2
|
import type { OpenRouterConfig } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* What this DRIVER does, not what OpenRouter could do: tools pass
|
|
@@ -13,7 +13,29 @@ export declare class OpenRouterProvider implements LLMProvider {
|
|
|
13
13
|
readonly capabilities: ProviderCapabilities;
|
|
14
14
|
private config;
|
|
15
15
|
private baseUrl;
|
|
16
|
+
private logger;
|
|
16
17
|
constructor(config: OpenRouterConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Whether a forced tool choice (`required` or a named function) is taken
|
|
20
|
+
* under the thinking configuration the request will carry. `false` only for
|
|
21
|
+
* the DeepSeek models whose own API refuses it while they reason, and
|
|
22
|
+
* reasoning is on for them unless thinking is disabled or effort is `none`
|
|
23
|
+
* (the same rule the DeepSeek driver applies). The kernel asks first and,
|
|
24
|
+
* on `false`, keeps the step at low effort and asks in words.
|
|
25
|
+
*
|
|
26
|
+
* The vendor's refusal is not what every route returns. On the live route a
|
|
27
|
+
* forced choice with reasoning on was served (HTTP 200) by five different
|
|
28
|
+
* upstream hosts, and when the request was pinned to the vendor's own host
|
|
29
|
+
* the router answered its own 404 "no endpoints" (its tool-compatibility
|
|
30
|
+
* filter drops that host for a forced choice). Yet a real session got the
|
|
31
|
+
* vendor's own 400 "Thinking mode does not support this tool_choice" from
|
|
32
|
+
* some host. So this driver acts on both facts: where this answer is
|
|
33
|
+
* `false` the forced choice is not put on the wire, and a request that did
|
|
34
|
+
* carry one and drew a 400 naming `tool_choice` is sent once more without
|
|
35
|
+
* it. A host that accepts the choice keeps getting it; only a host that
|
|
36
|
+
* rejects it costs a second request.
|
|
37
|
+
*/
|
|
38
|
+
acceptsForcedToolChoiceFor(model: string, thinking?: ThinkingConfig, effort?: ReasoningEffort): boolean;
|
|
17
39
|
private getHeaders;
|
|
18
40
|
private formatMessages;
|
|
19
41
|
private buildRequestBody;
|
|
@@ -57,6 +79,14 @@ export declare class OpenRouterProvider implements LLMProvider {
|
|
|
57
79
|
* one bad minute forever.
|
|
58
80
|
*/
|
|
59
81
|
resolveContextWindow(model: string, signal?: AbortSignal): Promise<number | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* The reasoning levels the listing names for `model` (`reasoning.supported_efforts`),
|
|
84
|
+
* or `undefined` when the listing cannot be read or names none. Read only
|
|
85
|
+
* for a `max` or `ultra` request, and kept for this driver once fulfilled; a
|
|
86
|
+
* failure is not kept. A caller abort still propagates.
|
|
87
|
+
*/
|
|
88
|
+
private resolveSupportedEfforts;
|
|
89
|
+
private supportedEfforts?;
|
|
60
90
|
/** First fulfilled listing; see the note on `resolveContextWindow`. */
|
|
61
91
|
private contextWindows?;
|
|
62
92
|
listModels(signal?: AbortSignal): Promise<ModelInfo[]>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,oBAAoB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,oBAAoB,EAGpB,eAAe,EACf,WAAW,EACX,cAAc,EAGd,MAAM,YAAY,CAAA;AAWnB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AA6oBlD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,oBAYrC,CAAA;AAED,qBAAa,kBAAmB,YAAW,WAAW;IACrD,QAAQ,CAAC,EAAE,gBAAe;IAC1B,QAAQ,CAAC,IAAI,gBAAe;IAC5B,QAAQ,CAAC,YAAY,uBAA0B;IAE/C,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,MAAM,CAAQ;gBAEV,MAAM,EAAE,gBAAgB;IASpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,0BAA0B,CACzB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,cAAc,EACzB,MAAM,CAAC,EAAE,eAAe,GACtB,OAAO;IAKV,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,cAAc;IA6CtB,OAAO,CAAC,gBAAgB;IAgEjB,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IAuO3E;;;;;;;;;;;;;OAaG;IACG,eAAe,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB1D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA4B5F;;;;;OAKG;YACW,uBAAuB;IAwCrC,OAAO,CAAC,gBAAgB,CAAC,CAAuB;IAEhD,uEAAuE;IACvE,OAAO,CAAC,cAAc,CAAC,CAAqB;IAEtC,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAsCtD,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAWrC"}
|