@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.
@@ -0,0 +1,56 @@
1
+ // The last line of defence before the wire.
2
+ //
3
+ // Half a UTF-16 surrogate pair is not valid Unicode. Python's json.loads accepts the escape but
4
+ // rejects the string ("no low surrogate in string"), so a server that reads strict JSON answers
5
+ // 400 to the whole request - and the provider, seeing a failing call, retries the same broken
6
+ // body eight times before giving up. One stray half therefore costs a whole sample.
7
+ //
8
+ // Earlier layers fix what they can (`wellFormedMessage` in the agent, `windowOf` in the cache),
9
+ // but each of them has to know every string it touches. This one does not: it walks the finished
10
+ // request body and replaces every lone half with U+FFFD, and says where it found one so the next
11
+ // occurrence can be traced to the layer that made it.
12
+ /** A high half with no low half after it, or a low half with no high half before it. */
13
+ const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
14
+ /** `text` with every lone surrogate replaced by U+FFFD. */
15
+ export function wellFormedText(text) {
16
+ return text.replace(new RegExp(LONE_SURROGATE.source, 'g'), '\uFFFD');
17
+ }
18
+ function scrub(value, path, hits) {
19
+ if (typeof value === 'string') {
20
+ const match = LONE_SURROGATE.exec(value);
21
+ if (match === null)
22
+ return value;
23
+ const at = match.index;
24
+ hits.push({
25
+ path,
26
+ count: value.match(new RegExp(LONE_SURROGATE.source, 'g'))?.length ?? 1,
27
+ context: value.slice(Math.max(0, at - 80), at + 80),
28
+ });
29
+ return wellFormedText(value);
30
+ }
31
+ if (Array.isArray(value))
32
+ return value.map((item, index) => scrub(item, `${path}[${index}]`, hits));
33
+ if (typeof value === 'object' && value !== null) {
34
+ const out = {};
35
+ for (const [key, item] of Object.entries(value)) {
36
+ out[key] = scrub(item, `${path}.${key}`, hits);
37
+ }
38
+ return out;
39
+ }
40
+ return value;
41
+ }
42
+ /** `body` with every lone surrogate replaced, and one log line per place one was found.
43
+ *
44
+ * `warn` is the operator's channel: the default writes to stderr, which the runtime keeps in the
45
+ * node's log next to the request that would otherwise have failed. */
46
+ export function scrubSurrogates(body, warn = console.error) {
47
+ const hits = [];
48
+ const cleaned = scrub(body, 'body', hits);
49
+ for (const hit of hits.slice(0, 5)) {
50
+ warn(`[surrogate] ${hit.path} x${hit.count} near ${JSON.stringify(hit.context)}`);
51
+ }
52
+ if (hits.length > 5)
53
+ warn(`[surrogate] ... and ${hits.length - 5} more places`);
54
+ return cleaned;
55
+ }
56
+ //# sourceMappingURL=wellformed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wellformed.js","sourceRoot":"","sources":["../../src/providers/wellformed.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,gGAAgG;AAChG,gGAAgG;AAChG,8FAA8F;AAC9F,oFAAoF;AACpF,EAAE;AACF,gGAAgG;AAChG,iGAAiG;AACjG,iGAAiG;AACjG,sDAAsD;AAEtD,wFAAwF;AACxF,MAAM,cAAc,GAAG,wEAAwE,CAAC;AAShG,2DAA2D;AAC3D,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,KAAK,CAAC,KAAc,EAAE,IAAY,EAAE,IAAoB;IAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QACjC,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC;YACR,IAAI;YACJ,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,G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IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,IAAI,CAAC,uBAAuB,IAAI,CAAC,MAAM,GAAG,CAAC,cAAc,CAAC,CAAC;IAChF,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/dist/serve.d.ts CHANGED
@@ -1,2 +1,15 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ import { type LocalizedText, type ServeOptions } from '@node-agent/sdk';
3
+ import { type ProviderMode } from './mode.js';
4
+ import ProviderNode from './index.js';
5
+ export default ProviderNode;
6
+ /** What the directory writes under a node renamed to `local-provider`: local mode says so in both
7
+ * languages, because the node is not the package's shared one any more. */
8
+ export declare function localLabel(): LocalizedText;
9
+ /** The options `servePackage` takes for this mode.
10
+ *
11
+ * The id and the label travel together: the runner renames `name` and `packageId` from the id and
12
+ * writes the label into `labels.node`, so `--local` registers as `local-provider` *listed* as the
13
+ * local one. A shared start passes `{}` - no id, no label - and the manifest keeps the package's
14
+ * own name and its own words. */
15
+ export declare function serveOptions(mode: ProviderMode): ServeOptions;
package/dist/serve.js CHANGED
@@ -3,31 +3,73 @@
3
3
  //
4
4
  // node dist/serve.js registers as `provider`
5
5
  // node dist/serve.js --local registers as `local-provider`
6
+ // npx @node-agent/provider --local (the bin is this file)
7
+ //
8
+ // This is the package's only process entry, and `node.entry` in package.json names it: the SDK asks a
9
+ // package's bin targets to include its entry, so the entry is the CLI. `index.ts` beside it is the
10
+ // Node class and nothing else - it used to carry a `provider-entry` bin that awaited
11
+ // `import('./serve.js')`, which the runner answered by importing `dist/index.js` back: the process
12
+ // printed `unsettled top-level await`, exited 13 and registered nothing at all.
6
13
  //
7
14
  // Local mode is this same package under the second name, for a stack that serves its own endpoint
8
15
  // beside the shared one: the capacities, the page and the stored rows are the package's, only the
9
- // address the agent dials changes. The topic a stream is published on does not change with it:
10
- // every stream has a `provider.stream.<stream_id>` of its own, whichever node serves it.
16
+ // address the agent dials changes - and the words under it. The topic a stream is published on does
17
+ // not change with it: every stream has a `provider.stream.<stream_id>` of its own, whichever node
18
+ // serves it.
19
+ import { realpathSync } from 'node:fs';
11
20
  import { fileURLToPath } from 'node:url';
12
21
  import { servePackage } from '@node-agent/sdk';
13
22
  import { providerMode } from './mode.js';
14
- const directory = fileURLToPath(new URL('..', import.meta.url));
15
- const mode = providerMode(process.argv.slice(2));
16
- // The host renames the manifest; the node reads that name from its context (`ctx.nodeId`) for the page
17
- // it draws, so the chosen id is passed here and nowhere else.
18
- const busUrl = process.env.NODE_AGENT_BUS_URL ?? 'ws://127.0.0.1:8788';
19
- const host = await servePackage(directory, mode.local ? { id: mode.id, label: mode.label } : {}).catch((error) => {
20
- const message = error instanceof Error ? error.message : String(error);
21
- console.error(`provider: cannot join ${busUrl}: ${message}`);
22
- process.exit(1);
23
- });
24
- console.log(`${host.manifest.name}: joined ${busUrl}`);
23
+ import ProviderNode from './index.js';
24
+ export default ProviderNode;
25
+ /** The package root: this file is `dist/serve.js` once it runs. */
26
+ const DIRECTORY = fileURLToPath(new URL('..', import.meta.url));
27
+ /** Where the bus is, when the environment does not say. */
28
+ const BUS_URL = process.env.NODE_AGENT_BUS_URL ?? 'ws://127.0.0.1:8788';
29
+ /** What the directory writes under a node renamed to `local-provider`: local mode says so in both
30
+ * languages, because the node is not the package's shared one any more. */
31
+ export function localLabel() {
32
+ return { 'zh-CN': '本地模型服务', en: 'Local provider' };
33
+ }
34
+ /** The options `servePackage` takes for this mode.
35
+ *
36
+ * The id and the label travel together: the runner renames `name` and `packageId` from the id and
37
+ * writes the label into `labels.node`, so `--local` registers as `local-provider` *listed* as the
38
+ * local one. A shared start passes `{}` - no id, no label - and the manifest keeps the package's
39
+ * own name and its own words. */
40
+ export function serveOptions(mode) {
41
+ return mode.local
42
+ ? { id: mode.id, label: mode.label ?? localLabel() }
43
+ : {};
44
+ }
45
+ /** Resolve when this process should stop -- on a signal, and on nothing else. */
25
46
  function untilStopped() {
26
47
  return new Promise((resolve) => {
27
48
  process.once('SIGINT', () => resolve());
28
49
  process.once('SIGTERM', () => resolve());
29
50
  });
30
51
  }
31
- await untilStopped();
32
- await host.stop();
52
+ /** Register, say where, and serve until a signal arrives. */
53
+ async function main(argv = process.argv.slice(2)) {
54
+ const host = await servePackage(DIRECTORY, serveOptions(providerMode(argv))).catch((error) => {
55
+ const message = error instanceof Error ? error.message : String(error);
56
+ console.error(`provider: cannot join ${BUS_URL}: ${message}`);
57
+ process.exit(1);
58
+ });
59
+ // The registered name, not the package's: local mode answers as `local-provider`.
60
+ console.log(`${host.manifest.name}: joined ${BUS_URL}`);
61
+ await untilStopped();
62
+ await host.stop();
63
+ }
64
+ // This file is both the package's entry (the SDK imports it for `ProviderNode`) and its executable.
65
+ // Importing it must not start a host; running it must.
66
+ //
67
+ // Started, not awaited: `servePackage` loads this package, and the loader imports `node.entry` - the
68
+ // same file, which would then still be evaluating. Waiting here would wait for ourselves (exit 13,
69
+ // `unsettled top-level await`, nothing registered). Not awaiting lets the module finish first, and
70
+ // the runner's import then finds the finished module.
71
+ const invoked = process.argv[1];
72
+ const self = realpathSync(fileURLToPath(import.meta.url));
73
+ if (invoked !== undefined && realpathSync(invoked) === self)
74
+ void main();
33
75
  //# sourceMappingURL=serve.js.map
package/dist/serve.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":";AACA,iGAAiG;AACjG,EAAE;AACF,0DAA0D;AAC1D,gEAAgE;AAChE,EAAE;AACF,kGAAkG;AAClG,kGAAkG;AAClG,+FAA+F;AAC/F,yFAAyF;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,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CAAC,KAAK,IAAI;IAAE,KAAK,IAAI,EAAE,CAAC"}
package/dist/ui.html CHANGED
@@ -22,6 +22,12 @@
22
22
  /* `hidden` is a UA rule and loses to the grid above, so hiding a field needs a say here. */
23
23
  [hidden] { display:none !important; }
24
24
  input, select { width:100%; min-height:40px; padding:8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--soft); color:var(--text); font:inherit; }
25
+ /* The extra-body field is JSON somebody types by hand: monospace, and tall enough to read. */
26
+ textarea { width:100%; min-height:88px; padding:8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--soft); color:var(--text); font:12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize:vertical; }
27
+ /* Advanced settings fold away: the form is the everyday five fields, and the fold is the rest. */
28
+ details.advanced { display:grid; gap:10px; }
29
+ details.advanced > summary { cursor:pointer; color:var(--muted); font-size:12px; }
30
+ details.advanced[open] > summary { color:var(--text); }
25
31
  .actions { display:flex; flex-wrap:wrap; gap:8px; }
26
32
  button { min-height:36px; padding:0 13px; border:0; border-radius:9px; background:var(--accent-fill); color:white; cursor:pointer; }
27
33
  button.secondary { border:1px solid var(--line); background:var(--soft); color:var(--text); }
@@ -76,6 +82,11 @@
76
82
  <option value="custom" data-text-key="thinking.custom">Custom…</option>
77
83
  </select></label>
78
84
  <label id="provider-thinking-custom-field" hidden><span data-text-key="form.thinkingCustom">Custom effort</span><input id="provider-thinking-custom" autocomplete="off" /></label>
85
+ <details id="provider-advanced" class="advanced" hidden><summary data-text-key="form.advanced">Advanced configuration</summary>
86
+ <label><span data-text-key="form.extraBody">Extra request body (JSON)</span>
87
+ <textarea id="provider-extra-body" spellcheck="false" autocapitalize="off" autocomplete="off" placeholder='{ "top_k": -1 }'></textarea>
88
+ <span class="note" data-text-key="hint.extraBody">Merged into every request: model, messages, stream and stream_options cannot be set here. Leave it empty for none.</span></label>
89
+ </details>
79
90
  <div id="provider-error" class="feedback error" role="alert"></div>
80
91
  <div id="provider-status" class="feedback success" role="status" aria-live="polite"></div>
81
92
  <div class="actions">
@@ -120,6 +131,10 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
120
131
  const thinking = byId('provider-thinking');
121
132
  const thinkingCustom = byId('provider-thinking-custom');
122
133
  const thinkingCustomField = byId('provider-thinking-custom-field');
134
+ const extraBody = byId('provider-extra-body');
135
+ const advanced = byId('provider-advanced');
136
+ // The protocols whose wire is a chat-completions body, and so the only ones `extra_body` reaches.
137
+ const EXTRA_BODY_PROTOCOLS = ['openai', 'deepseek'];
123
138
  const THINKING_PRESETS = ['', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
124
139
  const CUSTOM_THINKING = 'custom';
125
140
  const error = byId('provider-error');
@@ -158,6 +173,9 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
158
173
 
159
174
  function applyType() {
160
175
  organizationField.hidden = protocol() !== 'openai';
176
+ // Only a chat-completions row has a body to add to: the node refuses `extra_body` on the other
177
+ // two wires, so the whole advanced section is not offered there rather than offered and rejected.
178
+ advanced.hidden = !EXTRA_BODY_PROTOCOLS.includes(protocol());
161
179
  url.placeholder = TYPES[protocol()].url;
162
180
  // The key travels on the element, so a language change redraws this sentence in place.
163
181
  const hintKey = TYPES[protocol()].hint;
@@ -206,6 +224,12 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
206
224
  thinkingCustom.value = effort;
207
225
  }
208
226
  applyThinking();
227
+ // One row's fields as text: an empty box is "send nothing extra", and a saved object is shown
228
+ // pretty-printed so it can be read and edited rather than guessed at.
229
+ extraBody.value = config.extra_body ? JSON.stringify(config.extra_body, null, 2) : '';
230
+ // Folded by default, and opened only when there is something in it: a saved object must not sit
231
+ // behind a fold nobody has a reason to open.
232
+ advanced.open = Object.keys(config.extra_body ?? {}).length > 0;
209
233
  remove.disabled = !provider || (state?.providers.length ?? 0) <= 1;
210
234
  applyType();
211
235
  render();
@@ -253,6 +277,24 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
253
277
  error.textContent = t('error.baseUrl');
254
278
  return;
255
279
  }
280
+ // The extra body is typed as JSON, so it is parsed here: a half-typed object is refused with
281
+ // the sentence that says why, instead of being saved as a string every later call would reject.
282
+ let savedExtraBody = null;
283
+ const extraText = extraBody.value.trim();
284
+ if (extraText !== '' && EXTRA_BODY_PROTOCOLS.includes(protocol())) {
285
+ let parsed;
286
+ try {
287
+ parsed = JSON.parse(extraText);
288
+ } catch {
289
+ error.textContent = t('error.extraBodyJson');
290
+ return;
291
+ }
292
+ if (parsed !== null && (typeof parsed !== 'object' || Array.isArray(parsed))) {
293
+ error.textContent = t('error.extraBodyObject');
294
+ return;
295
+ }
296
+ savedExtraBody = parsed;
297
+ }
256
298
  save.disabled = true;
257
299
  try {
258
300
  const saved = await call({
@@ -263,7 +305,8 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
263
305
  timeout:timeoutValue === '' ? null : Number(timeoutValue),
264
306
  thinking_effort:(thinking.value === CUSTOM_THINKING
265
307
  ? thinkingCustom.value.trim()
266
- : thinking.value) || null},
308
+ : thinking.value) || null,
309
+ extra_body:savedExtraBody},
267
310
  });
268
311
  if (!saved) return;
269
312
  show(state.providers.find((item) => item.name === savedName));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-agent/provider",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "description": "Independent named LLM provider node (TypeScript)",
6
6
  "publisher": "node-agent",
@@ -8,6 +8,10 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "default": "./dist/index.js"
11
+ },
12
+ "./core": {
13
+ "types": "./dist/core.d.ts",
14
+ "default": "./dist/core.js"
11
15
  }
12
16
  },
13
17
  "files": [
@@ -63,6 +67,22 @@
63
67
  ],
64
68
  "allow_edit_permission": false
65
69
  },
70
+ "row": {
71
+ "type": "object",
72
+ "required": [
73
+ "name"
74
+ ],
75
+ "properties": {
76
+ "name": {
77
+ "type": "string"
78
+ }
79
+ },
80
+ "description": "one named provider row exactly as it is stored, for a caller that dials the model itself",
81
+ "callers": [
82
+ "agent"
83
+ ],
84
+ "allow_edit_permission": false
85
+ },
66
86
  "chat": {
67
87
  "type": "object",
68
88
  "required": [
package/src/ui.html CHANGED
@@ -22,6 +22,12 @@
22
22
  /* `hidden` is a UA rule and loses to the grid above, so hiding a field needs a say here. */
23
23
  [hidden] { display:none !important; }
24
24
  input, select { width:100%; min-height:40px; padding:8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--soft); color:var(--text); font:inherit; }
25
+ /* The extra-body field is JSON somebody types by hand: monospace, and tall enough to read. */
26
+ textarea { width:100%; min-height:88px; padding:8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--soft); color:var(--text); font:12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize:vertical; }
27
+ /* Advanced settings fold away: the form is the everyday five fields, and the fold is the rest. */
28
+ details.advanced { display:grid; gap:10px; }
29
+ details.advanced > summary { cursor:pointer; color:var(--muted); font-size:12px; }
30
+ details.advanced[open] > summary { color:var(--text); }
25
31
  .actions { display:flex; flex-wrap:wrap; gap:8px; }
26
32
  button { min-height:36px; padding:0 13px; border:0; border-radius:9px; background:var(--accent-fill); color:white; cursor:pointer; }
27
33
  button.secondary { border:1px solid var(--line); background:var(--soft); color:var(--text); }
@@ -76,6 +82,11 @@
76
82
  <option value="custom" data-text-key="thinking.custom">Custom…</option>
77
83
  </select></label>
78
84
  <label id="provider-thinking-custom-field" hidden><span data-text-key="form.thinkingCustom">Custom effort</span><input id="provider-thinking-custom" autocomplete="off" /></label>
85
+ <details id="provider-advanced" class="advanced" hidden><summary data-text-key="form.advanced">Advanced configuration</summary>
86
+ <label><span data-text-key="form.extraBody">Extra request body (JSON)</span>
87
+ <textarea id="provider-extra-body" spellcheck="false" autocapitalize="off" autocomplete="off" placeholder='{ "top_k": -1 }'></textarea>
88
+ <span class="note" data-text-key="hint.extraBody">Merged into every request: model, messages, stream and stream_options cannot be set here. Leave it empty for none.</span></label>
89
+ </details>
79
90
  <div id="provider-error" class="feedback error" role="alert"></div>
80
91
  <div id="provider-status" class="feedback success" role="status" aria-live="polite"></div>
81
92
  <div class="actions">
@@ -120,6 +131,10 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
120
131
  const thinking = byId('provider-thinking');
121
132
  const thinkingCustom = byId('provider-thinking-custom');
122
133
  const thinkingCustomField = byId('provider-thinking-custom-field');
134
+ const extraBody = byId('provider-extra-body');
135
+ const advanced = byId('provider-advanced');
136
+ // The protocols whose wire is a chat-completions body, and so the only ones `extra_body` reaches.
137
+ const EXTRA_BODY_PROTOCOLS = ['openai', 'deepseek'];
123
138
  const THINKING_PRESETS = ['', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
124
139
  const CUSTOM_THINKING = 'custom';
125
140
  const error = byId('provider-error');
@@ -158,6 +173,9 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
158
173
 
159
174
  function applyType() {
160
175
  organizationField.hidden = protocol() !== 'openai';
176
+ // Only a chat-completions row has a body to add to: the node refuses `extra_body` on the other
177
+ // two wires, so the whole advanced section is not offered there rather than offered and rejected.
178
+ advanced.hidden = !EXTRA_BODY_PROTOCOLS.includes(protocol());
161
179
  url.placeholder = TYPES[protocol()].url;
162
180
  // The key travels on the element, so a language change redraws this sentence in place.
163
181
  const hintKey = TYPES[protocol()].hint;
@@ -206,6 +224,12 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
206
224
  thinkingCustom.value = effort;
207
225
  }
208
226
  applyThinking();
227
+ // One row's fields as text: an empty box is "send nothing extra", and a saved object is shown
228
+ // pretty-printed so it can be read and edited rather than guessed at.
229
+ extraBody.value = config.extra_body ? JSON.stringify(config.extra_body, null, 2) : '';
230
+ // Folded by default, and opened only when there is something in it: a saved object must not sit
231
+ // behind a fold nobody has a reason to open.
232
+ advanced.open = Object.keys(config.extra_body ?? {}).length > 0;
209
233
  remove.disabled = !provider || (state?.providers.length ?? 0) <= 1;
210
234
  applyType();
211
235
  render();
@@ -253,6 +277,24 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
253
277
  error.textContent = t('error.baseUrl');
254
278
  return;
255
279
  }
280
+ // The extra body is typed as JSON, so it is parsed here: a half-typed object is refused with
281
+ // the sentence that says why, instead of being saved as a string every later call would reject.
282
+ let savedExtraBody = null;
283
+ const extraText = extraBody.value.trim();
284
+ if (extraText !== '' && EXTRA_BODY_PROTOCOLS.includes(protocol())) {
285
+ let parsed;
286
+ try {
287
+ parsed = JSON.parse(extraText);
288
+ } catch {
289
+ error.textContent = t('error.extraBodyJson');
290
+ return;
291
+ }
292
+ if (parsed !== null && (typeof parsed !== 'object' || Array.isArray(parsed))) {
293
+ error.textContent = t('error.extraBodyObject');
294
+ return;
295
+ }
296
+ savedExtraBody = parsed;
297
+ }
256
298
  save.disabled = true;
257
299
  try {
258
300
  const saved = await call({
@@ -263,7 +305,8 @@ const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
263
305
  timeout:timeoutValue === '' ? null : Number(timeoutValue),
264
306
  thinking_effort:(thinking.value === CUSTOM_THINKING
265
307
  ? thinkingCustom.value.trim()
266
- : thinking.value) || null},
308
+ : thinking.value) || null,
309
+ extra_body:savedExtraBody},
267
310
  });
268
311
  if (!saved) return;
269
312
  show(state.providers.find((item) => item.name === savedName));