@node-agent/provider 0.1.10 → 0.1.11

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
@@ -11,6 +11,9 @@ npm start runs it against the bus.
11
11
  Capabilities:
12
12
 
13
13
  - `provider.providers({ action: list | save | delete, name, config })` — the named rows, never the keys
14
+ - `provider.row({ name })` — one row exactly as it is stored, key included, for a caller that dials the
15
+ model in its own process (declared for `agent` alone; the rows are filed in history under this
16
+ node's name, so this is the one way to them)
14
17
  - `provider.chat({ name, messages, tools?, max_completion_tokens? })` — one finished answer
15
18
  - `provider.start_stream({ name, messages, tools?, max_completion_tokens? })` → `{ stream_id, topic }` —
16
19
  an id for one stream; the model is not dialled yet
@@ -24,10 +27,15 @@ it was published: the id comes back first, the caller subscribes to it, and only
24
27
  `stream_ready` let the model speak. No first delta can be published into an empty room, and the id
25
28
  is forgotten when the stream ends, fails, is cancelled, or waits more than a minute for a ready.
26
29
 
27
- A row is `{ type, model_name, base_url, timeout, api_key, organization?, thinking_effort? }`, saved in
28
- history and handed
29
- back by `dump`/`build`. Three protocols sit behind that one shape, which is the whole point of the node:
30
- the agent, the page and a transcript never learn which wire an answer came from.
30
+ The node is the address, not the model call: `@node-agent/provider/core` exports the same rows, the
31
+ same `buildProvider` wires, `providerRequest` / `runChat` and the row stores, so a caller that holds a
32
+ row can dial it in its own process with exactly this package's behaviour and failure sentences. The
33
+ node itself is built on that module, so there is one implementation of a model request, not two.
34
+
35
+ A row is `{ type, model_name, base_url, timeout, api_key, organization?, thinking_effort?, extra_body? }`,
36
+ saved in history and handed back by `dump`/`build`. Three protocols sit behind that one shape, which
37
+ is the whole point of the node: the agent, the page and a transcript never learn which wire an answer
38
+ came from.
31
39
 
32
40
  ## The three protocols
33
41
 
@@ -100,6 +108,66 @@ reopens on `Custom…` with the text field filled in.
100
108
 
101
109
  Only `minimal` needs a name of its own: the Messages API has no such level, so it is sent as `low`.
102
110
 
111
+ ## Extra request body
112
+
113
+ Some endpoints want fields of their own in a chat request — a vLLM `top_k`, a `chat_template_kwargs`
114
+ that turns thinking off on a Qwen template, a flag a gateway invented. A row may carry them as
115
+ `extra_body`, a JSON object merged into the body the node already builds:
116
+
117
+ ```json
118
+ {
119
+ "type": "openai",
120
+ "model_name": "qwen3-32b",
121
+ "base_url": "https://api.llm.example.cn/v1",
122
+ "api_key": "sk-…",
123
+ "extra_body": {
124
+ "top_k": -1,
125
+ "for_training": false,
126
+ "chat_template_kwargs": { "thinking": false }
127
+ }
128
+ }
129
+ ```
130
+
131
+ Both the finished answer and a stream post it, so `chat` and `chatStream` send:
132
+
133
+ ```json
134
+ {
135
+ "model": "qwen3-32b",
136
+ "messages": [ … ],
137
+ "top_k": -1,
138
+ "for_training": false,
139
+ "chat_template_kwargs": { "thinking": false }
140
+ }
141
+ ```
142
+
143
+ and a stream additionally sends `stream: true` and `stream_options: { "include_usage": true }`.
144
+
145
+ How the merge works, and where it stops:
146
+
147
+ - the body is built first and `extra_body` is merged on top of it, so its fields are the last word —
148
+ a nested object is sent exactly as written, and nothing of it is flattened or renamed;
149
+ - `model`, `messages`, `stream` and `stream_options` may never appear in it. They are refused when the
150
+ row is built (`extraBodyOf`), so a request can never be sent with somebody else's transcript, a
151
+ replaced model, or a `stream: false` under a caller that is waiting for deltas; a stream keeps
152
+ `stream: true` and `stream_options.include_usage: true` whichever extra fields the row adds;
153
+ - `null`, a missing field and `{}` all mean "send nothing extra": a row saved before this field
154
+ existed builds the very same request it did before;
155
+ - the value is a JSON object, not JSON text. A string, an array or a number is refused with a sentence
156
+ naming the field — the page parses its box before saving, so what reaches the node is already an object;
157
+ - it is stored like every other field (`dump` writes `extra_body` back, both stores persist it, and
158
+ `providers list` returns it), so it survives a restart and clears by clearing the box;
159
+ - **OpenAI-compatible only.** `openai` and `deepseek` rows send it; an `anthropic` or `responses` row
160
+ that carries it is refused when the row is built, with a message naming `extra_body` — never
161
+ dropped silently. The page does not even offer the box for those two protocols.
162
+
163
+ On the page the box lives in a folded **Advanced configuration** section: the form stays the five
164
+ everyday fields, the fold starts closed for a row with nothing extra, opens by itself for a row that
165
+ has some, and is not drawn at all for the two protocols above.
166
+
167
+ On a `deepseek` row the `thinking_effort` select is written by `deepseek.ts` before the merge, so an
168
+ `extra_body` of `{ "thinking": … }` wins over the select; the same holds for `reasoning_effort` on a
169
+ plain `openai` row. The escape hatch is the last word by design — except for the four reserved keys.
170
+
103
171
  ## State: the agent chooses full context or a delta
104
172
 
105
173
  The Responses API stores each response and can continue from it with `previous_response_id` (the
@@ -126,6 +194,9 @@ therefore sends the active transcript in full.
126
194
  - `type` that is not one of `openai`, `anthropic`, `responses`;
127
195
  - a timeout that is not a number, and a base URL the page can see is missing `http(s)://`;
128
196
  - a `tool_calls` entry whose arguments are not a JSON object, named before a request leaves;
197
+ - an `extra_body` that is not a JSON object, that is a string/array/number, or that names `model`,
198
+ `messages`, `stream` or `stream_options`; and any `extra_body` at all on an `anthropic` or
199
+ `responses` row (the field is OpenAI-compatible only);
129
200
  - a content part neither protocol can carry (`image_url` is translated; anything else is an error);
130
201
  - an Anthropic classifier refusal (`stop_reason: "refusal"`): it is raised as an error carrying
131
202
  `stop_details.category` and `stop_details.explanation`, never returned as an empty assistant
@@ -165,4 +236,6 @@ cd node_agent/nodes/provider
165
236
  npm test
166
237
  ```
167
238
 
168
- Tests use a fake provider client, so no real API key is needed and no network call is made.
239
+ Tests use a fake provider client, so no real API key is needed. The `extra_body` suites go one step
240
+ further: a throwaway HTTP server on `127.0.0.1` reads the bytes a chat and a stream really post, so a
241
+ body is asserted on the wire and not only in a mock — and nothing leaves the machine.
package/dist/core.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import type { ToolArgs } from '@node-agent/sdk';
2
+ import type { ChatOutput, Fetcher, JsonObject, Message, Provider, ToolSpec } from './providers/base.js';
3
+ import { type ProviderRows } from './persistency/index.js';
4
+ export * from './providers/index.js';
5
+ export * from './persistency/index.js';
6
+ export { HistoryStore } from './persistency/history.js';
7
+ export { LocalStore } from './persistency/local.js';
8
+ export * from './mode.js';
9
+ /** What a caller is told when it names a row no store holds: which rows there were. */
10
+ export declare function missingProvider(name: string, known: string[]): string;
11
+ /** How long one model request may take when the environment's row names no time of its own. */
12
+ export declare const MODEL_TIMEOUT = 120;
13
+ /** The row the environment describes: the three model variables, when all three are set.
14
+ *
15
+ * A stack is often configured before anybody opened the provider page, so the row this makes is
16
+ * what "nothing has been saved yet" falls back to. It is read from the process, so the agent and
17
+ * the node read the same variables and reach the same row. */
18
+ export declare function environmentProvider(): JsonObject | null;
19
+ /** The rows a process starts with when nothing has been saved: the environment's row, or one blank
20
+ * row the page can fill in. The node shows these and the agent dials them, so they must agree. */
21
+ export declare function seededRows(): ProviderRows;
22
+ /** One row, checked and named: the config a caller dials and the name it is known by.
23
+ *
24
+ * The node's `row` capability and its own `chat` both come through here, so "which row" is answered
25
+ * once - and a caller that dials the model itself is handed exactly what the node would have used. */
26
+ export declare function providerRow(rows: ProviderRows, args: ToolArgs): {
27
+ name: string;
28
+ config: JsonObject;
29
+ };
30
+ /** One request that has already been checked and dialled: everything a provider needs, and the wire
31
+ * that will carry it. Building it is the validation step both callers share, so a malformed call is
32
+ * refused with the same sentence whether it came over the bus or out of the agent's own process. */
33
+ export type ProviderRequest = {
34
+ readonly provider: Provider;
35
+ readonly messages: Message[];
36
+ readonly tools: ToolSpec[] | null;
37
+ readonly limit: number | null;
38
+ readonly previous: string | null;
39
+ };
40
+ /** Check one `chat` / `start_stream` argument set against the rows, and build the wire it names.
41
+ *
42
+ * `name` is the row; the failure sentences name the row and the host rather than the SDK's own
43
+ * "Connection error." so an operator can tell two rows apart in one log. */
44
+ export declare function providerRequest(rows: ProviderRows, args: ToolArgs, fetcher: Fetcher, build?: (data: JsonObject, fetcher: Fetcher, name: string) => Provider): ProviderRequest;
45
+ /** One non-streamed answer, with the wire closed whichever way it ended. */
46
+ export declare function runChat(request: ProviderRequest): Promise<ChatOutput>;
package/dist/core.js ADDED
@@ -0,0 +1,91 @@
1
+ import { buildProvider } from './providers/index.js';
2
+ import { validateName } from './persistency/index.js';
3
+ export * from './providers/index.js';
4
+ export * from './persistency/index.js';
5
+ export { HistoryStore } from './persistency/history.js';
6
+ export { LocalStore } from './persistency/local.js';
7
+ export * from './mode.js';
8
+ /** What a caller is told when it names a row no store holds: which rows there were. */
9
+ export function missingProvider(name, known) {
10
+ const others = [...known].sort().join(', ');
11
+ return `no provider "${name}" yet — open the provider page and add one${others ? ` (configured: ${others})` : ''}`;
12
+ }
13
+ /** How long one model request may take when the environment's row names no time of its own. */
14
+ export const MODEL_TIMEOUT = 120;
15
+ /** The row the environment describes: the three model variables, when all three are set.
16
+ *
17
+ * A stack is often configured before anybody opened the provider page, so the row this makes is
18
+ * what "nothing has been saved yet" falls back to. It is read from the process, so the agent and
19
+ * the node read the same variables and reach the same row. */
20
+ export function environmentProvider() {
21
+ const url = (process.env.NODE_AGENT_MODEL_URL ?? '').trim();
22
+ const key = (process.env.NODE_AGENT_MODEL_KEY ?? '').trim();
23
+ const model = (process.env.NODE_AGENT_MODEL_NAME ?? '').trim();
24
+ if (!url || !key || !model)
25
+ return null;
26
+ return {
27
+ type: 'openai',
28
+ api_key: key,
29
+ model_name: model,
30
+ base_url: url.replace(/\/$/, '').replace(/\/chat\/completions$/, ''),
31
+ timeout: MODEL_TIMEOUT,
32
+ thinking_effort: null,
33
+ };
34
+ }
35
+ /** The rows a process starts with when nothing has been saved: the environment's row, or one blank
36
+ * row the page can fill in. The node shows these and the agent dials them, so they must agree. */
37
+ export function seededRows() {
38
+ const env = environmentProvider();
39
+ return env ? { default: env } : { default: { type: 'openai' } };
40
+ }
41
+ /** One row, checked and named: the config a caller dials and the name it is known by.
42
+ *
43
+ * The node's `row` capability and its own `chat` both come through here, so "which row" is answered
44
+ * once - and a caller that dials the model itself is handed exactly what the node would have used. */
45
+ export function providerRow(rows, args) {
46
+ const name = validateName(args.name);
47
+ const config = rows[name];
48
+ if (!config)
49
+ throw new Error(missingProvider(name, Object.keys(rows)));
50
+ return { name, config };
51
+ }
52
+ /** Check one `chat` / `start_stream` argument set against the rows, and build the wire it names.
53
+ *
54
+ * `name` is the row; the failure sentences name the row and the host rather than the SDK's own
55
+ * "Connection error." so an operator can tell two rows apart in one log. */
56
+ export function providerRequest(rows, args, fetcher, build = buildProvider) {
57
+ const { name, config } = providerRow(rows, args);
58
+ const messages = args.messages;
59
+ if (!Array.isArray(messages))
60
+ throw new Error('provider chat needs a messages array');
61
+ const tools = args.tools;
62
+ if (tools !== undefined && tools !== null && !Array.isArray(tools))
63
+ throw new Error('provider chat tools must be an array or null');
64
+ const limit = args.max_completion_tokens;
65
+ if (limit !== undefined &&
66
+ limit !== null &&
67
+ (!Number.isInteger(limit) || typeof limit === 'boolean'))
68
+ throw new Error('max_completion_tokens must be an integer or null');
69
+ const previous = args.previous_response_id;
70
+ if (previous !== undefined && previous !== null && typeof previous !== 'string')
71
+ throw new Error('previous_response_id must be a string or null');
72
+ return {
73
+ // The row's name travels with the provider: a connection that fails says which row and which
74
+ // host, instead of the SDK's bare "Connection error."
75
+ provider: build(config, fetcher, name),
76
+ messages: messages,
77
+ tools: tools ?? null,
78
+ limit: limit ?? null,
79
+ previous: previous ?? null,
80
+ };
81
+ }
82
+ /** One non-streamed answer, with the wire closed whichever way it ended. */
83
+ export async function runChat(request) {
84
+ try {
85
+ return await request.provider.chat(request.messages, request.tools, request.limit, request.previous);
86
+ }
87
+ finally {
88
+ await request.provider.close();
89
+ }
90
+ }
91
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAqB,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEzE,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MA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AM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,SAAS,CAAC;QAExD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAC7E,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,OAAO;QACL,6FAA6F;QAC7F,sDAAsD;QACtD,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;QACtC,QAAQ,EAAE,QAAqB;QAC/B,KAAK,EAAG,KAAgC,IAAI,IAAI;QAChD,KAAK,EAAG,KAA4B,IAAI,IAAI;QAC5C,QAAQ,EAAG,QAA+B,IAAI,IAAI;KACnD,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAwB;IACpD,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAChC,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,QAAQ,CACjB,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;AACH,CAAC"}
package/dist/i18n/en.json CHANGED
@@ -11,6 +11,8 @@
11
11
  "timeout": "Timeout (seconds)",
12
12
  "thinking": "Thinking effort",
13
13
  "thinkingCustom": "Custom effort",
14
+ "extraBody": "Extra request body (JSON)",
15
+ "advanced": "Advanced configuration",
14
16
  "keyNew": "API key",
15
17
  "keyKeep": "Leave blank to keep the current key",
16
18
  "save": "Save",
@@ -27,7 +29,8 @@
27
29
  "openai": "OpenAI-compatible: any server that speaks /v1/chat/completions, a gateway included.",
28
30
  "deepseek": "DeepSeek: the native chat-completions API, with its thinking switch handled for you. Leave the base URL blank to use api.deepseek.com; a gateway in front of DeepSeek takes its own address.",
29
31
  "anthropic": "Anthropic (Claude): the native Messages API. A gateway that routes Claude only there needs its own address (what comes before /v1/messages) and a model id as that gateway lists it.",
30
- "responses": "OpenAI (Responses API): posts to /responses instead of /chat/completions, for a deployment or gateway that serves a model there (e.g. MIOFFICE azure_openai/gpt-5.6-sol). The base URL is what comes before /responses."
32
+ "responses": "OpenAI (Responses API): posts to /responses instead of /chat/completions, for a deployment or gateway that serves a model there (e.g. MIOFFICE azure_openai/gpt-5.6-sol). The base URL is what comes before /responses.",
33
+ "extraBody": "Extra request body (JSON): merged into every chat request — top-level fields and nested ones alike, e.g. {\"top_k\": -1, \"chat_template_kwargs\": {\"thinking\": false}}. model, messages, stream and stream_options cannot be set here, and this field is not offered on the Anthropic and Responses wires. Leave it empty for none."
31
34
  },
32
35
  "thinking": {
33
36
  "default": "Provider default",
@@ -49,6 +52,8 @@
49
52
  "callFailed": "Provider call failed",
50
53
  "required": "A name and a model are both required.",
51
54
  "baseUrl": "The base URL starts with http:// or https://.",
55
+ "extraBodyJson": "The extra request body is not valid JSON.",
56
+ "extraBodyObject": "The extra request body must be a JSON object, such as {\"top_k\": -1}.",
52
57
  "selectFirst": "Save or select a provider first."
53
58
  },
54
59
  "status": {
@@ -11,6 +11,8 @@
11
11
  "timeout": "超时(秒)",
12
12
  "thinking": "思考强度",
13
13
  "thinkingCustom": "自定义强度",
14
+ "extraBody": "额外请求体(JSON)",
15
+ "advanced": "高级配置",
14
16
  "keyNew": "API 密钥",
15
17
  "keyKeep": "留空则保留现有密钥",
16
18
  "save": "保存",
@@ -27,7 +29,8 @@
27
29
  "openai": "OpenAI 兼容:任何支持 /v1/chat/completions 的服务端,网关也包括在内。",
28
30
  "deepseek": "DeepSeek:原生 chat-completions API,思考开关由本节点处理。基础 URL 留空即使用 api.deepseek.com;如果 DeepSeek 前面有网关,则填网关自己的地址。",
29
31
  "anthropic": "Anthropic(Claude):原生 Messages API。只在它上面转发 Claude 的网关需要自己的地址(/v1/messages 之前的部分),以及该网关列出的模型 id。",
30
- "responses": "OpenAI(Responses API):向 /responses 而不是 /chat/completions 提交请求,用于在 /responses 上提供某个模型的部署或网关(例如 MIOFFICE azure_openai/gpt-5.6-sol)。基础 URL 是 /responses 之前的部分。"
32
+ "responses": "OpenAI(Responses API):向 /responses 而不是 /chat/completions 提交请求,用于在 /responses 上提供某个模型的部署或网关(例如 MIOFFICE azure_openai/gpt-5.6-sol)。基础 URL 是 /responses 之前的部分。",
33
+ "extraBody": "额外请求体(JSON):合并进每一个对话请求,顶层字段和嵌套字段一视同仁,例如 {\"top_k\": -1, \"chat_template_kwargs\": {\"thinking\": false}}。这里不能设置 model、messages、stream 和 stream_options;Anthropic 与 Responses 协议不提供这个输入框。留空表示不传。"
31
34
  },
32
35
  "thinking": {
33
36
  "default": "服务商默认",
@@ -49,6 +52,8 @@
49
52
  "callFailed": "服务商调用失败",
50
53
  "required": "名称和模型都必须填写。",
51
54
  "baseUrl": "基础 URL 要以 http:// 或 https:// 开头。",
55
+ "extraBodyJson": "额外请求体不是合法的 JSON。",
56
+ "extraBodyObject": "额外请求体必须是一个 JSON 对象,例如 {\"top_k\": -1}。",
52
57
  "selectFirst": "请先保存或选择一个服务商。"
53
58
  },
54
59
  "status": {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { Node, type NodeContext, type NodeHandlers } from '@node-agent/sdk';
3
- import type { JsonObject } from './providers/base.js';
3
+ import type { JsonObject } from './core.js';
4
4
  export type ProviderConfig = JsonObject;
5
5
  export type InstalledProvider = {
6
6
  name: string;
package/dist/index.js CHANGED
@@ -20,15 +20,10 @@
20
20
  // whole address - never the caller's name, which would mix two agents' deltas and outlive the
21
21
  // request - and it is forgotten as soon as the stream ends, fails or is cancelled.
22
22
  import { randomUUID } from 'node:crypto';
23
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
24
- import { fileURLToPath } from 'node:url';
23
+ import { readFileSync } from 'node:fs';
25
24
  import { Node, loadResource, paintPage, } from '@node-agent/sdk';
26
- import {} from './providers/base.js';
27
- import { buildProvider } from './providers/index.js';
28
- import { localConfigPath } from './mode.js';
29
- import { providerStore, validateName } from './persistency/index.js';
25
+ import { buildProvider, localConfigPath, providerRequest, providerRow, providerStore, runChat, seededRows, validateName, } from './core.js';
30
26
  const PANEL = 'ui';
31
- const MODEL_TIMEOUT = 120;
32
27
  const PAGE = readFileSync(new URL('./ui.html', import.meta.url), 'utf8');
33
28
  /** The page's words, read from beside the compiled JS (`npm run build` copies src/i18n there). */
34
29
  const RESOURCE = loadResource(new URL('./i18n/', import.meta.url));
@@ -53,25 +48,6 @@ async function withMutation(work) {
53
48
  export const STREAM_PENDING_MS = 60_000;
54
49
  /** The streams this node is serving, keyed by the id it handed out for each one. */
55
50
  const activeStreams = new Map();
56
- function missingProvider(name, known) {
57
- const others = [...known].sort().join(', ');
58
- return `no provider "${name}" yet — open the provider page and add one${others ? ` (configured: ${others})` : ''}`;
59
- }
60
- function environmentProvider() {
61
- const url = (process.env.NODE_AGENT_MODEL_URL ?? '').trim();
62
- const key = (process.env.NODE_AGENT_MODEL_KEY ?? '').trim();
63
- const model = (process.env.NODE_AGENT_MODEL_NAME ?? '').trim();
64
- if (!url || !key || !model)
65
- return null;
66
- return {
67
- type: 'openai',
68
- api_key: key,
69
- model_name: model,
70
- base_url: url.replace(/\/$/, '').replace(/\/chat\/completions$/, ''),
71
- timeout: MODEL_TIMEOUT,
72
- thinking_effort: null,
73
- };
74
- }
75
51
  class ProviderManager {
76
52
  ctx;
77
53
  /** Where the rows live: this bus's history, or this machine's file (see `persistency/`). */
@@ -102,12 +78,7 @@ class ProviderManager {
102
78
  async load() {
103
79
  const saved = await this.store.read();
104
80
  this.persistence = this.store.persistent;
105
- this.providers = saved ?? this.seeded();
106
- }
107
- /** What a stack nobody configured starts with: the three model variables, else one blank row. */
108
- seeded() {
109
- const env = environmentProvider();
110
- return env ? { default: env } : { default: { type: 'openai' } };
81
+ this.providers = saved ?? seededRows();
111
82
  }
112
83
  /** The rows as the provider's own `dump()`, which is the shape both stores hold. */
113
84
  dumped() {
@@ -159,44 +130,24 @@ class ProviderManager {
159
130
  return this.state();
160
131
  });
161
132
  }
133
+ /** One row, credentials and all, for a caller that dials the model in its own process.
134
+ *
135
+ * The rows are filed in history under *this* node's name, so no other node can read them; and a
136
+ * caller that is told only the row's name and base URL cannot sign a request. This is the one
137
+ * capability that hands a row over, it is declared for `agent` alone (`callers`), and the reply
138
+ * is the same document the page saves - never logged, and never published on a topic. */
139
+ async row(args) {
140
+ await this.load();
141
+ return providerRow(this.providers, args);
142
+ }
143
+ /** The row and the request it names, checked and dialled by the core both this node and an agent
144
+ * that talks to a `provider` row in its own process use. */
162
145
  chatRequest(args) {
163
- const name = validateName(args.name);
164
- const config = this.providers[name];
165
- if (!config)
166
- throw new Error(missingProvider(name, Object.keys(this.providers)));
167
- const messages = args.messages;
168
- if (!Array.isArray(messages))
169
- throw new Error('provider chat needs a messages array');
170
- const tools = args.tools;
171
- if (tools !== undefined && tools !== null && !Array.isArray(tools))
172
- throw new Error('provider chat tools must be an array or null');
173
- const limit = args.max_completion_tokens;
174
- if (limit !== undefined &&
175
- limit !== null &&
176
- (!Number.isInteger(limit) || typeof limit === 'boolean'))
177
- throw new Error('max_completion_tokens must be an integer or null');
178
- const previous = args.previous_response_id;
179
- if (previous !== undefined && previous !== null && typeof previous !== 'string')
180
- throw new Error('previous_response_id must be a string or null');
181
- return {
182
- // The row's name travels with the provider: a connection that fails says which row and which
183
- // host, instead of the SDK's bare "Connection error."
184
- provider: buildProvider(config, this.ctx.fetch, name),
185
- messages: messages,
186
- tools: tools ?? null,
187
- limit: limit ?? null,
188
- previous: previous ?? null,
189
- };
146
+ return providerRequest(this.providers, args, this.ctx.fetch);
190
147
  }
191
148
  async chat(args) {
192
149
  await this.load();
193
- const request = this.chatRequest(args);
194
- try {
195
- return await request.provider.chat(request.messages, request.tools, request.limit, request.previous);
196
- }
197
- finally {
198
- await request.provider.close();
199
- }
150
+ return await runChat(this.chatRequest(args));
200
151
  }
201
152
  /** Ask for a stream: answer with its id, and dial nothing yet.
202
153
  *
@@ -351,6 +302,7 @@ export class ProviderNode extends Node {
351
302
  const manager = new ProviderManager(ctx, providerStore(ctx, localConfigPath(ctx.nodeId, process.env, ctx.home)));
352
303
  this.handlers = {
353
304
  providers: (args) => manager.handle(args),
305
+ row: (args) => manager.row(args),
354
306
  chat: (args) => manager.chat(args),
355
307
  start_stream: (args) => manager.startStream(args),
356
308
  stream_ready: (args) => manager.streamReady(args),
@@ -363,10 +315,4 @@ export class ProviderNode extends Node {
363
315
  }
364
316
  }
365
317
  export default ProviderNode;
366
- // `npx @node-agent/provider` runs this file. Keep the library import side-effect free: only a direct
367
- // invocation hands over to the process entry, and `--local` is read there from the same argv.
368
- const invoked = process.argv[1];
369
- if (invoked && existsSync(invoked) && realpathSync(invoked) === fileURLToPath(import.meta.url)) {
370
- await import('./serve.js');
371
- }
372
318
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,iEAAiE;AACjE,EAAE;AACF,oGAAoG;AACpG,kGAAkG;AAClG,qGAAqG;AACrG,8EAA8E;AAC9E,EAAE;AACF,6DAA6D;AAC7D,iFAAiF;AACjF,+GAA+G;AAC/G,0CAA0C;AAC1C,4CAA4C;AAC5C,OAAO;AACP,EAAE;AACF,qGAAqG;AACrG,mGAAmG;AACnG,8FAA8F;AAC9F,gGAAgG;AAChG,8FAA8F;AAC9F,mFAAmF;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,aAAa,EA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AC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;SAC1F,CAAC;IACJ,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
@@ -4,7 +4,7 @@
4
4
  // text, tool calls are content blocks, max_tokens is always sent, and a stream is named events.
5
5
  import { createHash } from 'node:crypto';
6
6
  import Anthropic from '@anthropic-ai/sdk';
7
- import { blankProviderMessage, endpointHost, optionalString, Provider as BaseProvider, thinkingEffort, timeoutOf, } from './base.js';
7
+ import { blankProviderMessage, endpointHost, optionalString, Provider as BaseProvider, refuseExtraBody, thinkingEffort, timeoutOf, } from './base.js';
8
8
  export const DEFAULT_BASE_URL = 'https://api.anthropic.com';
9
9
  export const DEFAULT_MAX_TOKENS = 8192;
10
10
  export const DEFAULT_TIMEOUT = 120;
@@ -408,7 +408,13 @@ function streamChunks(payload) {
408
408
  const stop = payload.stop_reason ?? payload.delta?.stop_reason;
409
409
  if (stop === 'refusal')
410
410
  throw new Error(refusalMessage(payload));
411
- return [{ delta: {}, usage: usageOf(payload) }];
411
+ return [
412
+ {
413
+ delta: {},
414
+ usage: usageOf(payload),
415
+ ...(typeof stop === 'string' && stop !== '' ? { finish_reason: stop } : {}),
416
+ },
417
+ ];
412
418
  }
413
419
  if (kind === 'error') {
414
420
  const error = payload.error ?? {};
@@ -426,6 +432,9 @@ export class AnthropicProvider extends BaseProvider {
426
432
  client;
427
433
  host;
428
434
  static build(data, fetcher) {
435
+ // The Messages wire is not a chat-completions body: a row that carries `extra_body` is refused
436
+ // here rather than dropped silently on every request.
437
+ refuseExtraBody(data, 'Anthropic');
429
438
  return new AnthropicProvider({
430
439
  apiKey: optionalString(data, 'api_key'),
431
440
  modelName: optionalString(data, 'model_name') ?? '',