@newses/plugin-digest-summary 0.3.1 → 0.4.0

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/dist/prices.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type Say } from './messages.js';
1
2
  import type { InstanceSettings } from './settings.js';
2
3
  /**
3
4
  * What the settings' route costs, as a multiple of Anthropic's list prices: Bedrock's global
@@ -16,5 +17,5 @@ export interface RequestTokens {
16
17
  export declare function costOf(model: InstanceSettings['model'], requests: readonly RequestTokens[], premium?: number): number;
17
18
  /** Every token of some requests. */
18
19
  export declare const tokensIn: (requests: readonly RequestTokens[]) => number;
19
- /** US dollars for a message: `about $0.95`, or `less than $0.01`. */
20
- export declare const dollars: (amount: number) => string;
20
+ /** US dollars for a message, in the reader's language: `about $0.95`, or `less than $0.01`. */
21
+ export declare function dollars(amount: number, say?: Say, language?: string): string;
package/dist/prices.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { english } from './messages.js';
1
2
  /**
2
3
  * Anthropic's list prices for the models an admin can choose, standard tier, in US dollars per
3
4
  * million tokens (https://platform.claude.com/docs/en/about-claude/pricing, November 2026), which
@@ -40,5 +41,10 @@ export function costOf(model, requests, premium = 1) {
40
41
  }
41
42
  /** Every token of some requests. */
42
43
  export const tokensIn = (requests) => requests.reduce((sum, r) => sum + r.input + r.cacheWrite + r.cacheRead + r.output, 0);
43
- /** US dollars for a message: `about $0.95`, or `less than $0.01`. */
44
- export const dollars = (amount) => amount < 0.005 ? 'less than $0.01' : `about $${amount.toFixed(2)}`;
44
+ /** US dollars for a message, in the reader's language: `about $0.95`, or `less than $0.01`. */
45
+ export function dollars(amount, say = english, language = 'en') {
46
+ const usd = new Intl.NumberFormat(language, { style: 'currency', currency: 'USD' });
47
+ return amount < 0.005
48
+ ? say('text.cost.under', { amount: usd.format(0.01) })
49
+ : say('text.cost.about', { amount: usd.format(amount) });
50
+ }
@@ -1,4 +1,5 @@
1
1
  import Anthropic from '@anthropic-ai/sdk';
2
+ import { type Say } from '../messages.js';
2
3
  import type { InstanceSettings } from '../settings.js';
3
4
  import type { Provider } from './types.js';
4
5
  /** The API's host, which an admin approves for the plugin. */
@@ -23,8 +24,8 @@ export declare function finalText(content: readonly {
23
24
  type: string;
24
25
  text?: string;
25
26
  }[]): string;
26
- /** An API failure as people read it, without anything from the request. */
27
- export declare function failureText(error: unknown): string;
27
+ /** An API failure as people read it, in their language, without anything from the request. */
28
+ export declare function failureText(error: unknown, say?: Say): string;
28
29
  /**
29
30
  * Claude through a Messages API: the fixed prompt cached for every reader's digests, structured
30
31
  * outputs, and, where the API has it, the server's default fallback model when the model declines.
@@ -44,4 +45,4 @@ export declare function messagesProvider(options: {
44
45
  }>;
45
46
  }): Provider;
46
47
  /** Claude through the Anthropic API, with the server's default fallback model. */
47
- export declare function anthropicProvider(settings: Pick<InstanceSettings, 'apiKey' | 'model' | 'effort'>, fetch: typeof globalThis.fetch): Provider;
48
+ export declare function anthropicProvider(settings: Pick<InstanceSettings, 'apiKey' | 'model' | 'effort'>, fetch: typeof globalThis.fetch, say?: Say): Provider;
@@ -1,5 +1,7 @@
1
1
  import Anthropic from '@anthropic-ai/sdk';
2
+ import { english } from '../messages.js';
2
3
  import { tokensOf } from '../usage.js';
4
+ import { withDetail } from './http.js';
3
5
  /** The API's host, which an admin approves for the plugin. */
4
6
  export const API_HOST = 'api.anthropic.com';
5
7
  /** Server-side fallback when the model declines, on direct requests only. */
@@ -38,24 +40,22 @@ export function finalText(content) {
38
40
  .map((block) => (block.type === 'text' ? (block.text ?? '') : ''))
39
41
  .join('');
40
42
  }
41
- /** An API failure as people read it, without anything from the request. */
42
- export function failureText(error) {
43
+ /** An API failure as people read it, in their language, without anything from the request. */
44
+ export function failureText(error, say = english) {
43
45
  if (error instanceof Anthropic.AuthenticationError)
44
- return 'The API key was refused (HTTP 401): check it in the server’s settings';
46
+ return say('text.anthropic.unauthorized');
45
47
  if (error instanceof Anthropic.PermissionDeniedError)
46
- return 'The API key may not use this model (HTTP 403)';
48
+ return say('text.anthropic.forbidden');
47
49
  if (error instanceof Anthropic.NotFoundError)
48
- return 'The model was not found (HTTP 404)';
50
+ return say('text.anthropic.notFound');
49
51
  if (error instanceof Anthropic.RateLimitError)
50
- return 'Rate limited by the API (HTTP 429)';
52
+ return say('text.anthropic.rateLimited');
51
53
  if (error instanceof Anthropic.APIConnectionTimeoutError)
52
- return 'The API did not answer in time';
54
+ return say('text.anthropic.timeout');
53
55
  if (error instanceof Anthropic.APIConnectionError)
54
- return error.cause instanceof Error
55
- ? `The API could not be reached: ${error.cause.message}`
56
- : 'The API could not be reached';
56
+ return withDetail(say('text.anthropic.unreachable'), error.cause instanceof Error ? error.cause.message : null);
57
57
  if (error instanceof Anthropic.APIError && error.status !== undefined)
58
- return `The API answered HTTP ${String(error.status)}`;
58
+ return say('text.anthropic.status', { status: String(error.status) });
59
59
  return error instanceof Error ? error.message : String(error);
60
60
  }
61
61
  /**
@@ -104,11 +104,11 @@ export function messagesProvider(options) {
104
104
  };
105
105
  }
106
106
  /** Claude through the Anthropic API, with the server's default fallback model. */
107
- export function anthropicProvider(settings, fetch) {
107
+ export function anthropicProvider(settings, fetch, say = english) {
108
108
  const client = clientFor({ baseURL: `https://${API_HOST}`, apiKey: settings.apiKey }, fetch);
109
109
  return messagesProvider({
110
110
  name: 'anthropic',
111
- label: `${settings.model} at ${settings.effort} effort`,
111
+ label: say(`text.label.claude.${settings.effort}`, { model: settings.model }),
112
112
  client,
113
113
  model: settings.model,
114
114
  effort: settings.effort,
@@ -118,9 +118,9 @@ export function anthropicProvider(settings, fetch) {
118
118
  await client.models.retrieve(settings.model, null, { signal });
119
119
  }
120
120
  catch (error) {
121
- return { ok: false, message: failureText(error) };
121
+ return { ok: false, message: failureText(error, say) };
122
122
  }
123
- return { ok: true, message: `The API key works with ${settings.model}.` };
123
+ return { ok: true, message: say('text.anthropic.works', { model: settings.model }) };
124
124
  },
125
125
  });
126
126
  }
@@ -1,3 +1,4 @@
1
+ import { type Say } from '../messages.js';
1
2
  import { type InstanceSettings } from '../settings.js';
2
3
  import type { Provider } from './types.js';
3
4
  /**
@@ -14,12 +15,15 @@ type BedrockSettings = Pick<InstanceSettings, 'bedrockApiKey' | 'bedrockRegion'
14
15
  * region or model does not have.
15
16
  */
16
17
  export declare function bedrockModel(settings: BedrockSettings): string;
17
- /** A Bedrock failure as people read it, saying what to change, without anything from the request. */
18
- export declare function bedrockFailureText(error: unknown, settings: BedrockSettings): string;
18
+ /**
19
+ * A Bedrock failure as people read it, in their language, saying what to change, without
20
+ * anything from the request; what Bedrock said stays as it said it.
21
+ */
22
+ export declare function bedrockFailureText(error: unknown, settings: BedrockSettings, say?: Say): string;
19
23
  /**
20
24
  * Claude through Amazon Bedrock's Messages API, at its runtime in the region set, with the server's
21
25
  * Bedrock API key in `x-api-key`. As with Anthropic, the fixed prompt is cached and answers are
22
26
  * held to the format; Bedrock has no server-side fallback, so a refusal is the answer.
23
27
  */
24
- export declare function bedrockProvider(settings: BedrockSettings, fetch: typeof globalThis.fetch): Provider;
28
+ export declare function bedrockProvider(settings: BedrockSettings, fetch: typeof globalThis.fetch, say?: Say): Provider;
25
29
  export {};
@@ -1,7 +1,8 @@
1
1
  import Anthropic from '@anthropic-ai/sdk';
2
- import { BEDROCK_GEOGRAPHIES, geographyOf } from '../settings.js';
2
+ import { english } from '../messages.js';
3
+ import { geographyOf } from '../settings.js';
3
4
  import { clientFor, messagesProvider } from './anthropic.js';
4
- import { reachText } from './http.js';
5
+ import { reachText, withDetail } from './http.js';
5
6
  /**
6
7
  * The regions whose hosts the plugin asks for, the most used with Claude, so an admin can pick
7
8
  * theirs among them; an admin may approve any other region's host too.
@@ -30,11 +31,9 @@ export function bedrockModel(settings) {
30
31
  return `${geography ?? 'global'}.anthropic.${settings.model}`;
31
32
  }
32
33
  /** Where requests may run, for the messages: `in us-east-1`, `in eu-west-1, within the EU`. */
33
- function whereOf(settings) {
34
+ function whereOf(settings, say) {
34
35
  const geography = settings.bedrockRouting === 'geography' ? geographyOf(settings.bedrockRegion) : null;
35
- return geography
36
- ? `in ${settings.bedrockRegion}, within ${BEDROCK_GEOGRAPHIES[geography].name}`
37
- : `in ${settings.bedrockRegion}`;
36
+ return say(`text.where.${geography ?? 'region'}`, { region: settings.bedrockRegion });
38
37
  }
39
38
  /** The message in an error's body: AWS's `{message}`, or the Messages API's `{error: {message}}`. */
40
39
  function detailOf(body) {
@@ -49,26 +48,44 @@ function detailOf(body) {
49
48
  : null);
50
49
  return typeof message === 'string' && message ? message.slice(0, 200) : null;
51
50
  }
52
- /** A Bedrock failure as people read it, saying what to change, without anything from the request. */
53
- export function bedrockFailureText(error, settings) {
51
+ /**
52
+ * Why Bedrock denied a request (HTTP 403), from its message: AWS holds the model back from the
53
+ * account, which only AWS can change; the account has not subscribed to the model, which the key's
54
+ * user may not do; or the user's policy does not allow it, such as one written for another region.
55
+ */
56
+ function deniedText(detail, settings, where, say) {
57
+ const params = { model: settings.model, where, region: settings.bedrockRegion };
58
+ if (/not available for this account/i.test(detail ?? ''))
59
+ return say('text.bedrock.unavailable', params);
60
+ if (/marketplace/i.test(detail ?? ''))
61
+ return withDetail(say('text.bedrock.marketplace', params), detail);
62
+ if (/not authorized to perform/i.test(detail ?? ''))
63
+ return withDetail(say('text.bedrock.notAuthorized', params), detail);
64
+ return withDetail(say('text.bedrock.denied', params), detail);
65
+ }
66
+ /**
67
+ * A Bedrock failure as people read it, in their language, saying what to change, without
68
+ * anything from the request; what Bedrock said stays as it said it.
69
+ */
70
+ export function bedrockFailureText(error, settings, say = english) {
54
71
  const host = bedrockHost(settings.bedrockRegion);
55
- const where = whereOf(settings);
72
+ const where = whereOf(settings, say);
56
73
  if (error instanceof Anthropic.APIConnectionTimeoutError)
57
- return `${host} did not answer in time`;
74
+ return say('text.reach.timeout', { host });
58
75
  if (error instanceof Anthropic.APIConnectionError)
59
- return reachText(error.cause ?? error, host);
76
+ return reachText(error.cause ?? error, host, say);
60
77
  if (error instanceof Anthropic.APIError && error.status !== undefined) {
61
78
  const detail = detailOf(error.error);
62
- const said = detail ? `: ${detail}` : '';
79
+ const params = { model: settings.model, where };
63
80
  if (error.status === 401)
64
- return 'Bedrock refused the API key (HTTP 401): check it in the server’s settings';
81
+ return say('text.bedrock.unauthorized');
65
82
  if (error.status === 403)
66
- return `The Bedrock API key may not use ${settings.model} ${where} (HTTP 403): its IAM user needs bedrock:InvokeModel and bedrock:CallWithBearerToken, and the AWS account access to the model${said}`;
83
+ return deniedText(detail, settings, where, say);
67
84
  if (error.status === 404)
68
- return `Bedrock has no ${settings.model} ${where} (HTTP 404)${said}`;
85
+ return withDetail(say('text.bedrock.notFound', params), detail);
69
86
  if (error.status === 429)
70
- return `Rate limited by Bedrock (HTTP 429): the account’s quota for ${settings.model} ${where} is used up for now`;
71
- return `Bedrock answered HTTP ${String(error.status)}${said}`;
87
+ return say('text.bedrock.rateLimited', params);
88
+ return withDetail(say('text.bedrock.status', { status: String(error.status) }), detail);
72
89
  }
73
90
  return error instanceof Error ? error.message : String(error);
74
91
  }
@@ -77,17 +94,17 @@ export function bedrockFailureText(error, settings) {
77
94
  * Bedrock API key in `x-api-key`. As with Anthropic, the fixed prompt is cached and answers are
78
95
  * held to the format; Bedrock has no server-side fallback, so a refusal is the answer.
79
96
  */
80
- export function bedrockProvider(settings, fetch) {
97
+ export function bedrockProvider(settings, fetch, say = english) {
81
98
  const client = clientFor({
82
99
  baseURL: `https://${bedrockHost(settings.bedrockRegion)}/anthropic`,
83
100
  apiKey: settings.bedrockApiKey,
84
101
  header: 'x-api-key',
85
102
  }, fetch);
86
103
  const model = bedrockModel(settings);
87
- const where = whereOf(settings);
104
+ const where = whereOf(settings, say);
88
105
  return messagesProvider({
89
106
  name: 'bedrock',
90
- label: `${settings.model} at ${settings.effort} effort on Bedrock ${where}`,
107
+ label: say(`text.label.bedrock.${settings.effort}`, { model: settings.model, where }),
91
108
  client,
92
109
  model,
93
110
  effort: settings.effort,
@@ -104,9 +121,9 @@ export function bedrockProvider(settings, fetch) {
104
121
  }, { signal, timeout: 20_000, maxRetries: 0 });
105
122
  }
106
123
  catch (error) {
107
- return { ok: false, message: bedrockFailureText(error, settings) };
124
+ return { ok: false, message: bedrockFailureText(error, settings, say) };
108
125
  }
109
- return { ok: true, message: `The Bedrock API key works with ${model} ${where}.` };
126
+ return { ok: true, message: say('text.bedrock.works', { model, where }) };
110
127
  },
111
128
  });
112
129
  }
@@ -1,3 +1,4 @@
1
+ import { type Say } from '../messages.js';
1
2
  /** A server's answer: its status, and its body as JSON when it is JSON. */
2
3
  export interface JsonAnswer {
3
4
  status: number;
@@ -6,8 +7,12 @@ export interface JsonAnswer {
6
7
  /** A model server's answer that was not a success, for the log and the test. */
7
8
  export declare class ServerError extends Error {
8
9
  readonly status: number;
10
+ /** What the server said, if anything. */
11
+ readonly detail: string | null;
9
12
  constructor(status: number, detail: string | null);
10
13
  }
14
+ /** A message, then what the other side said after a colon, if anything. */
15
+ export declare const withDetail: (text: string, detail: string | null | undefined) => string;
11
16
  /** A URL without its trailing slashes, to append paths to. */
12
17
  export declare const trimmed: (base: string) => string;
13
18
  /** Sends JSON (or nothing, for GET) and reads JSON back; throws as `fetch` does, and on bad JSON. */
@@ -20,5 +25,8 @@ export declare function requestJson(fetch: typeof globalThis.fetch, url: string,
20
25
  export declare function errorDetail(body: unknown): string | null;
21
26
  /** Whether a failure was the request's own time running out. */
22
27
  export declare const isTimeout: (error: unknown) => boolean;
23
- /** A failure reaching `host` as people read it, saying what to change where they can. */
24
- export declare function reachText(error: unknown, host: string): string;
28
+ /**
29
+ * A failure reaching `host` as people read it, in their language, saying what to change where
30
+ * they can; what the other side said stays as it said it.
31
+ */
32
+ export declare function reachText(error: unknown, host: string, say?: Say): string;
@@ -1,19 +1,20 @@
1
- /*
2
- * Requests to a self-hosted model server through the hook's `fetch`, and their failures as
3
- * people read them. The server's `fetch` refuses hosts an admin has not approved, and private
4
- * addresses unless the operator trusts the host (`PLUGIN_TRUSTED_HOSTS`), with a `TypeError`.
5
- */
1
+ import { english } from '../messages.js';
6
2
  /** A model server's answer that was not a success, for the log and the test. */
7
3
  export class ServerError extends Error {
8
4
  status;
5
+ /** What the server said, if anything. */
6
+ detail;
9
7
  constructor(status, detail) {
10
8
  super(detail
11
9
  ? `The server answered HTTP ${String(status)}: ${detail}`
12
10
  : `The server answered HTTP ${String(status)}`);
13
11
  this.name = 'ServerError';
14
12
  this.status = status;
13
+ this.detail = detail;
15
14
  }
16
15
  }
16
+ /** A message, then what the other side said after a colon, if anything. */
17
+ export const withDetail = (text, detail) => detail ? `${text}: ${detail}` : text;
17
18
  /** A URL without its trailing slashes, to append paths to. */
18
19
  export const trimmed = (base) => base.replace(/\/+$/, '');
19
20
  /** Sends JSON (or nothing, for GET) and reads JSON back; throws as `fetch` does, and on bad JSON. */
@@ -56,22 +57,23 @@ export function errorDetail(body) {
56
57
  }
57
58
  /** Whether a failure was the request's own time running out. */
58
59
  export const isTimeout = (error) => error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError');
59
- /** A failure reaching `host` as people read it, saying what to change where they can. */
60
- export function reachText(error, host) {
60
+ /**
61
+ * A failure reaching `host` as people read it, in their language, saying what to change where
62
+ * they can; what the other side said stays as it said it.
63
+ */
64
+ export function reachText(error, host, say = english) {
61
65
  if (error instanceof ServerError)
62
- return error.message;
66
+ return withDetail(say('text.reach.status', { status: error.status }), error.detail);
63
67
  if (isTimeout(error))
64
- return `${host} did not answer in time`;
68
+ return say('text.reach.timeout', { host });
65
69
  if (error instanceof TypeError) {
66
70
  if (/not (an )?approved/.test(error.message))
67
- return `${host} is not approved for this plugin: add it under Approved hosts`;
71
+ return say('text.reach.notApproved', { host });
68
72
  const cause = error.cause;
69
73
  const code = typeof cause === 'object' && cause !== null && 'code' in cause ? String(cause.code) : null;
70
74
  if (/private address/.test(error.message) || code === 'blocked_address')
71
- return `${host} is on a private network: the server's operator must add it to PLUGIN_TRUSTED_HOSTS`;
72
- if (cause instanceof Error)
73
- return `${host} could not be reached: ${cause.message}`;
74
- return `${host} could not be reached: ${error.message}`;
75
+ return say('text.reach.private', { host });
76
+ return withDetail(say('text.reach.unreachable', { host }), cause instanceof Error ? cause.message : error.message);
75
77
  }
76
78
  return error instanceof Error ? error.message : String(error);
77
79
  }
@@ -1,5 +1,9 @@
1
+ import { type Say } from '../messages.js';
1
2
  import type { InstanceSettings } from '../settings.js';
2
3
  import type { Provider } from './types.js';
3
4
  export type { Asked, AskOutcome, AskRequest, Capacity, Provider, Timing } from './types.js';
4
- /** The model the settings choose, sending its requests through the hook's `fetch`. */
5
- export declare function providerFor(settings: InstanceSettings, fetch: typeof globalThis.fetch): Provider;
5
+ /**
6
+ * The model the settings choose, sending its requests through the hook's `fetch`, and saying
7
+ * what it says with `say` in `language` (English by default, as outside a hook).
8
+ */
9
+ export declare function providerFor(settings: InstanceSettings, fetch: typeof globalThis.fetch, say?: Say, language?: string): Provider;
@@ -1,14 +1,18 @@
1
+ import { english } from '../messages.js';
1
2
  import { anthropicProvider } from './anthropic.js';
2
3
  import { bedrockProvider } from './bedrock.js';
3
4
  import { ollamaProvider } from './ollama.js';
4
5
  import { openaiProvider } from './openai.js';
5
- /** The model the settings choose, sending its requests through the hook's `fetch`. */
6
- export function providerFor(settings, fetch) {
6
+ /**
7
+ * The model the settings choose, sending its requests through the hook's `fetch`, and saying
8
+ * what it says with `say` in `language` (English by default, as outside a hook).
9
+ */
10
+ export function providerFor(settings, fetch, say = english, language = 'en') {
7
11
  if (settings.provider === 'bedrock')
8
- return bedrockProvider(settings, fetch);
12
+ return bedrockProvider(settings, fetch, say);
9
13
  if (settings.provider === 'ollama')
10
- return ollamaProvider(settings, fetch);
14
+ return ollamaProvider(settings, fetch, say, language);
11
15
  if (settings.provider === 'openai')
12
- return openaiProvider(settings, fetch);
13
- return anthropicProvider(settings, fetch);
16
+ return openaiProvider(settings, fetch, say);
17
+ return anthropicProvider(settings, fetch, say);
14
18
  }
@@ -1,3 +1,4 @@
1
+ import { type Say } from '../messages.js';
1
2
  import type { InstanceSettings } from '../settings.js';
2
3
  import type { Provider } from './types.js';
3
4
  /**
@@ -6,4 +7,4 @@ import type { Provider } from './types.js';
6
7
  * format's JSON schema; thinking on or off as the admin chose. The key, when set, is sent as a
7
8
  * bearer token, for an Ollama behind a proxy that asks for one (Ollama itself has no keys).
8
9
  */
9
- export declare function ollamaProvider(settings: Pick<InstanceSettings, 'baseUrl' | 'localApiKey' | 'localModel' | 'contextTokens' | 'parallelRequests' | 'thinking'>, fetch: typeof globalThis.fetch): Provider;
10
+ export declare function ollamaProvider(settings: Pick<InstanceSettings, 'baseUrl' | 'localApiKey' | 'localModel' | 'contextTokens' | 'parallelRequests' | 'thinking'>, fetch: typeof globalThis.fetch, say?: Say, language?: string): Provider;
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { english, numbers } from '../messages.js';
2
3
  import { errorDetail, isTimeout, reachText, requestJson, ServerError, trimmed } from './http.js';
3
4
  /** Low, so the overview keeps to the articles; not zero, which repeats itself on small models. */
4
5
  const TEMPERATURE = 0.2;
@@ -14,7 +15,6 @@ const showAnswer = z.object({
14
15
  model_info: z.record(z.string(), z.unknown()).optional(),
15
16
  capabilities: z.array(z.string()).optional(),
16
17
  });
17
- const formatted = (n) => new Intl.NumberFormat('en').format(n);
18
18
  /** The longest context a model was trained for, from `/api/show`'s `<architecture>.context_length`. */
19
19
  function trainedContext(info) {
20
20
  const entry = Object.entries(info ?? {}).find(([key]) => key.endsWith('.context_length'));
@@ -26,7 +26,8 @@ function trainedContext(info) {
26
26
  * format's JSON schema; thinking on or off as the admin chose. The key, when set, is sent as a
27
27
  * bearer token, for an Ollama behind a proxy that asks for one (Ollama itself has no keys).
28
28
  */
29
- export function ollamaProvider(settings, fetch) {
29
+ export function ollamaProvider(settings, fetch, say = english, language = 'en') {
30
+ const formatted = (n) => numbers(language).format(n);
30
31
  const base = trimmed(settings.baseUrl ?? '');
31
32
  const host = base ? new URL(base).host : 'the Ollama server';
32
33
  const model = settings.localModel;
@@ -35,7 +36,7 @@ export function ollamaProvider(settings, fetch) {
35
36
  : {};
36
37
  return {
37
38
  name: 'ollama',
38
- label: `${model} on Ollama`,
39
+ label: say('text.label.ollama', { model }),
39
40
  capacity: {
40
41
  kind: 'context',
41
42
  contextTokens: settings.contextTokens,
@@ -100,7 +101,7 @@ export function ollamaProvider(settings, fetch) {
100
101
  },
101
102
  async check(signal) {
102
103
  if (!base)
103
- return { ok: false, message: 'Set the URL of the Ollama server.' };
104
+ return { ok: false, message: say('text.ollama.noUrl') };
104
105
  let shown;
105
106
  try {
106
107
  const { status, body } = await requestJson(fetch, `${base}/api/show`, {
@@ -111,26 +112,34 @@ export function ollamaProvider(settings, fetch) {
111
112
  if (status === 404)
112
113
  return {
113
114
  ok: false,
114
- message: `${model} is not on the Ollama server at ${host}: pull it there with \`ollama pull ${model}\`.`,
115
+ message: say('text.ollama.missingModel', { model, host }),
115
116
  };
116
117
  if (status !== 200)
117
118
  throw new ServerError(status, errorDetail(body));
118
119
  shown = showAnswer.parse(body);
119
120
  }
120
121
  catch (error) {
121
- return { ok: false, message: reachText(error, host) };
122
+ return { ok: false, message: reachText(error, host, say) };
122
123
  }
123
124
  const trained = trainedContext(shown.model_info);
124
125
  if (trained !== null && settings.contextTokens > trained)
125
126
  return {
126
127
  ok: false,
127
- message: `${model} takes at most ${formatted(trained)} tokens of context, fewer than the ${formatted(settings.contextTokens)} set: lower Context.`,
128
+ message: say('text.ollama.contextTooLarge', {
129
+ model,
130
+ trained: formatted(trained),
131
+ context: formatted(settings.contextTokens),
132
+ }),
128
133
  };
129
134
  if (settings.thinking && shown.capabilities && !shown.capabilities.includes('thinking'))
130
- return { ok: false, message: `${model} does not think: turn Thinking off.` };
135
+ return { ok: false, message: say('text.ollama.noThinking', { model }) };
131
136
  return {
132
137
  ok: true,
133
- message: `Ollama at ${host} has ${model}, with ${formatted(settings.contextTokens)} tokens of context.`,
138
+ message: say('text.ollama.works', {
139
+ host,
140
+ model,
141
+ context: formatted(settings.contextTokens),
142
+ }),
134
143
  };
135
144
  },
136
145
  };
@@ -1,3 +1,4 @@
1
+ import { type Say } from '../messages.js';
1
2
  import type { InstanceSettings } from '../settings.js';
2
3
  import type { Provider } from './types.js';
3
4
  /**
@@ -6,4 +7,4 @@ import type { Provider } from './types.js';
6
7
  * The answer is held to the format's JSON schema (`response_format`); the key, when set, is
7
8
  * sent as a bearer token. The server's own context must be at least `contextTokens`.
8
9
  */
9
- export declare function openaiProvider(settings: Pick<InstanceSettings, 'baseUrl' | 'localApiKey' | 'localModel' | 'contextTokens' | 'parallelRequests'>, fetch: typeof globalThis.fetch): Provider;
10
+ export declare function openaiProvider(settings: Pick<InstanceSettings, 'baseUrl' | 'localApiKey' | 'localModel' | 'contextTokens' | 'parallelRequests'>, fetch: typeof globalThis.fetch, say?: Say): Provider;
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { estimateTokens } from '../tokens.js';
3
+ import { english } from '../messages.js';
3
4
  import { errorDetail, isTimeout, reachText, requestJson, ServerError, trimmed } from './http.js';
4
5
  /** Low, so the overview keeps to the articles; not zero, which repeats itself on small models. */
5
6
  const TEMPERATURE = 0.2;
@@ -25,7 +26,7 @@ const models = z.object({ data: z.array(z.object({ id: z.string() })) });
25
26
  * The answer is held to the format's JSON schema (`response_format`); the key, when set, is
26
27
  * sent as a bearer token. The server's own context must be at least `contextTokens`.
27
28
  */
28
- export function openaiProvider(settings, fetch) {
29
+ export function openaiProvider(settings, fetch, say = english) {
29
30
  const base = trimmed(settings.baseUrl ?? '');
30
31
  const host = base ? new URL(base).host : 'the server';
31
32
  const model = settings.localModel;
@@ -34,7 +35,7 @@ export function openaiProvider(settings, fetch) {
34
35
  : {};
35
36
  return {
36
37
  name: 'openai',
37
- label: `${model} at ${host}`,
38
+ label: say('text.label.openai', { model, host }),
38
39
  capacity: { kind: 'context', contextTokens: settings.contextTokens, thinking: false },
39
40
  parallel: settings.parallelRequests,
40
41
  async ask(request) {
@@ -82,14 +83,14 @@ export function openaiProvider(settings, fetch) {
82
83
  },
83
84
  async check(signal) {
84
85
  if (!base)
85
- return { ok: false, message: 'Set the URL of the server, ending in /v1.' };
86
+ return { ok: false, message: say('text.openai.noUrl') };
86
87
  let listed;
87
88
  try {
88
89
  const { status, body } = await requestJson(fetch, `${base}/models`, { headers, signal });
89
90
  if (status === 401 || status === 403)
90
91
  return {
91
92
  ok: false,
92
- message: `${host} refused the API key (HTTP ${String(status)}): check it in the server’s settings.`,
93
+ message: say('text.openai.refusedKey', { host, status }),
93
94
  };
94
95
  if (status !== 200)
95
96
  throw new ServerError(status, errorDetail(body));
@@ -97,20 +98,22 @@ export function openaiProvider(settings, fetch) {
97
98
  if (!parsed.success)
98
99
  return {
99
100
  ok: false,
100
- message: `${host} did not list its models: check that the URL ends in /v1.`,
101
+ message: say('text.openai.noList', { host }),
101
102
  };
102
103
  listed = parsed.data;
103
104
  }
104
105
  catch (error) {
105
- return { ok: false, message: reachText(error, host) };
106
+ return { ok: false, message: reachText(error, host, say) };
106
107
  }
107
108
  const ids = listed.data.map((entry) => entry.id);
108
109
  if (!ids.includes(model))
109
110
  return {
110
111
  ok: false,
111
- message: `${host} has no model ${model}${ids.length ? `; it has ${ids.slice(0, 5).join(', ')}` : ''}.`,
112
+ message: ids.length
113
+ ? say('text.openai.noModelHas', { host, model, models: ids.slice(0, 5).join(', ') })
114
+ : say('text.openai.noModel', { host, model }),
112
115
  };
113
- return { ok: true, message: `${host} has ${model}.` };
116
+ return { ok: true, message: say('text.openai.works', { host, model }) };
114
117
  },
115
118
  };
116
119
  }
@@ -88,7 +88,7 @@ export declare const DEFAULT_CONTEXT_TOKENS = 16384;
88
88
  /**
89
89
  * What an admin sets for the server: who writes the overview and how it is reached, the model,
90
90
  * the budgets, and what users may add. Anthropic needs the API key; Bedrock, its own API key; a
91
- * self-hosted server, its URL.
91
+ * self-hosted server, its URL. Issues are message keys, shown in the admin's language.
92
92
  */
93
93
  export declare const instanceSettings: z.ZodObject<{
94
94
  provider: z.ZodDefault<z.ZodEnum<{
package/dist/settings.js CHANGED
@@ -97,7 +97,7 @@ const ollamaOnly = { provider: ['ollama'] };
97
97
  /**
98
98
  * What an admin sets for the server: who writes the overview and how it is reached, the model,
99
99
  * the budgets, and what users may add. Anthropic needs the API key; Bedrock, its own API key; a
100
- * self-hosted server, its URL.
100
+ * self-hosted server, its URL. Issues are message keys, shown in the admin's language.
101
101
  */
102
102
  export const instanceSettings = z
103
103
  .object({
@@ -125,14 +125,14 @@ export const instanceSettings = z
125
125
  context.addIssue({
126
126
  code: 'custom',
127
127
  path: ['apiKey'],
128
- message: 'Anthropic needs an API key',
128
+ message: 'text.settings.apiKey',
129
129
  });
130
130
  if (settings.provider === 'bedrock') {
131
131
  if (!settings.bedrockApiKey)
132
132
  context.addIssue({
133
133
  code: 'custom',
134
134
  path: ['bedrockApiKey'],
135
- message: 'Bedrock needs an API key',
135
+ message: 'text.settings.bedrockApiKey',
136
136
  });
137
137
  if (settings.bedrockRouting === 'geography') {
138
138
  const geography = geographyOf(settings.bedrockRegion);
@@ -140,13 +140,15 @@ export const instanceSettings = z
140
140
  context.addIssue({
141
141
  code: 'custom',
142
142
  path: ['bedrockRouting'],
143
- message: `Bedrock routes requests from ${settings.bedrockRegion} only globally`,
143
+ message: 'text.settings.regionGlobal',
144
+ params: { region: settings.bedrockRegion },
144
145
  });
145
146
  else if (!BEDROCK_GEOGRAPHIES[geography].models.includes(settings.model))
146
147
  context.addIssue({
147
148
  code: 'custom',
148
149
  path: ['bedrockRouting'],
149
- message: `Bedrock has ${settings.model} within ${BEDROCK_GEOGRAPHIES[geography].name} only globally`,
150
+ message: `text.settings.modelGlobal.${geography}`,
151
+ params: { model: settings.model },
150
152
  });
151
153
  }
152
154
  }
@@ -154,7 +156,7 @@ export const instanceSettings = z
154
156
  context.addIssue({
155
157
  code: 'custom',
156
158
  path: ['baseUrl'],
157
- message: 'A self-hosted model needs its server’s URL',
159
+ message: 'text.settings.baseUrl',
158
160
  });
159
161
  });
160
162
  /** A section of the overview, by name, with what goes in it. */