@steve31415/baselib 3.27.0 → 3.28.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/llm/complete.d.ts +8 -1
- package/dist/llm/complete.js +28 -2
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/models.d.ts +15 -5
- package/dist/llm/models.js +18 -1
- package/dist/llm/providers/gemini.js +9 -4
- package/dist/llm/types.d.ts +28 -13
- package/dist/llm/types.js +7 -0
- package/package.json +1 -1
package/dist/llm/complete.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type { LLMRequest, LLMResponse } from './types.js';
|
|
1
|
+
import type { LLMRequest, LLMResponse, Effort } from './types.js';
|
|
2
|
+
import type { ModelEntry } from './models.js';
|
|
3
|
+
/**
|
|
4
|
+
* The effort level to send a model: none when the model has no effort
|
|
5
|
+
* control, otherwise the requested level clamped to the nearest one the
|
|
6
|
+
* model accepts (e.g. `minimal` → `low` on models without a `minimal`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveEffort(entry: ModelEntry, effort: Effort | undefined): Effort | undefined;
|
|
2
9
|
/**
|
|
3
10
|
* Call an LLM with automatic failover to alternative providers.
|
|
4
11
|
*
|
package/dist/llm/complete.js
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { LLMError } from './types.js';
|
|
1
|
+
import { LLMError, EFFORT_LEVELS } from './types.js';
|
|
2
2
|
import { MODEL_REGISTRY, THINKING_HEADROOM_WARN_TOKENS } from './models.js';
|
|
3
3
|
import { providers } from './providers/index.js';
|
|
4
4
|
const DEFAULT_MAX_TOKENS = 2048;
|
|
5
5
|
const DEFAULT_TEMPERATURE = 0.3;
|
|
6
6
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
7
|
+
const DEFAULT_THINKING_LEVELS = ['low', 'medium', 'high'];
|
|
8
|
+
/**
|
|
9
|
+
* The effort level to send a model: none when the model has no effort
|
|
10
|
+
* control, otherwise the requested level clamped to the nearest one the
|
|
11
|
+
* model accepts (e.g. `minimal` → `low` on models without a `minimal`).
|
|
12
|
+
*/
|
|
13
|
+
export function resolveEffort(entry, effort) {
|
|
14
|
+
if (!entry.supportsEffort || effort === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const levels = entry.thinkingLevels ?? DEFAULT_THINKING_LEVELS;
|
|
17
|
+
if (levels.includes(effort))
|
|
18
|
+
return effort;
|
|
19
|
+
const rank = (level) => EFFORT_LEVELS.indexOf(level);
|
|
20
|
+
const wanted = rank(effort);
|
|
21
|
+
return [...levels].sort((a, b) => Math.abs(rank(a) - wanted) - Math.abs(rank(b) - wanted))[0];
|
|
22
|
+
}
|
|
7
23
|
/**
|
|
8
24
|
* Call an LLM with automatic failover to alternative providers.
|
|
9
25
|
*
|
|
@@ -42,6 +58,16 @@ export async function llmComplete(request) {
|
|
|
42
58
|
...(request.callSite ? { callSite: request.callSite } : {}),
|
|
43
59
|
});
|
|
44
60
|
}
|
|
61
|
+
// Google is retiring the Gemini thinking budget in favor of levels (see
|
|
62
|
+
// LLMRequest.thinkingBudget). Flag every caller still passing one so the
|
|
63
|
+
// migration to `effort` is visible in the logs, not discovered by a 400.
|
|
64
|
+
if (request.thinkingBudget !== undefined) {
|
|
65
|
+
request.logger?.warn('llm.thinking_budget_deprecated', {
|
|
66
|
+
model: request.model,
|
|
67
|
+
thinkingBudget: request.thinkingBudget,
|
|
68
|
+
...(request.callSite ? { callSite: request.callSite } : {}),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
45
71
|
// Build the ordered list of models to try: primary + fallbacks
|
|
46
72
|
const modelsToTry = [request.model, ...entry.fallbacks];
|
|
47
73
|
const failedAttempts = [];
|
|
@@ -67,7 +93,7 @@ export async function llmComplete(request) {
|
|
|
67
93
|
supportsTemperature: modelEntry.supportsTemperature ?? true,
|
|
68
94
|
supportsThinkingBudgetZero: modelEntry.supportsThinkingBudgetZero ?? true,
|
|
69
95
|
supportsForcedToolChoice: modelEntry.supportsForcedToolChoice ?? true,
|
|
70
|
-
effort: modelEntry
|
|
96
|
+
effort: resolveEffort(modelEntry, request.effort),
|
|
71
97
|
jsonSchema: request.jsonSchema,
|
|
72
98
|
apiKey,
|
|
73
99
|
logger: request.logger,
|
package/dist/llm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { llmComplete } from './complete.js';
|
|
2
2
|
export { MODEL_REGISTRY } from './models.js';
|
|
3
3
|
export type { ModelEntry } from './models.js';
|
|
4
|
-
export { LLMError, type LLMRequest, type LLMResponse, type FailedAttempt, type FinishCategory, type ProviderName, type ApiKeys, type JsonSchema, } from './types.js';
|
|
4
|
+
export { LLMError, EFFORT_LEVELS, type Effort, type LLMRequest, type LLMResponse, type FailedAttempt, type FinishCategory, type ProviderName, type ApiKeys, type JsonSchema, } from './types.js';
|
package/dist/llm/index.js
CHANGED
package/dist/llm/models.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderName } from './types.js';
|
|
1
|
+
import type { ProviderName, Effort } from './types.js';
|
|
2
2
|
export interface ModelEntry {
|
|
3
3
|
/** Provider that serves this model. */
|
|
4
4
|
provider: ProviderName;
|
|
@@ -22,12 +22,22 @@ export interface ModelEntry {
|
|
|
22
22
|
*/
|
|
23
23
|
supportsThinkingBudgetZero?: boolean;
|
|
24
24
|
/**
|
|
25
|
-
* Whether this model accepts Anthropic's
|
|
26
|
-
* (verified on Sonnet 5 / Sonnet 4.6 2026-08-10;
|
|
27
|
-
* 4.6+/5)
|
|
28
|
-
*
|
|
25
|
+
* Whether this model accepts a reasoning-effort level: Anthropic's
|
|
26
|
+
* `output_config.effort` (verified on Sonnet 5 / Sonnet 4.6 2026-08-10;
|
|
27
|
+
* documented GA on Opus 4.6+/5) or Gemini's `thinkingConfig.thinkingLevel`
|
|
28
|
+
* (every Gemini 3.x model; verified live 2026-10-06). Defaults to `false`;
|
|
29
|
+
* the effort option is dropped for models without it.
|
|
29
30
|
*/
|
|
30
31
|
supportsEffort?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The effort levels this model accepts, for `supportsEffort` models whose
|
|
34
|
+
* set differs from the default `low | medium | high`. A requested level
|
|
35
|
+
* outside the set is clamped to the nearest one in it (`minimal` → `low`).
|
|
36
|
+
* Gemini 3.5 Flash-Lite, 3.6 Flash and 3 Flash preview also take `minimal`
|
|
37
|
+
* ("no hidden reasoning"); 3.1 Pro preview does not (Google's per-model
|
|
38
|
+
* table, 2026-10-06).
|
|
39
|
+
*/
|
|
40
|
+
thinkingLevels?: readonly Effort[];
|
|
31
41
|
/**
|
|
32
42
|
* Whether this model performs hidden reasoning when the request omits any
|
|
33
43
|
* thinking configuration (which this library always does). Defaults to
|
package/dist/llm/models.js
CHANGED
|
@@ -11,7 +11,12 @@ export const THINKING_HEADROOM_WARN_TOKENS = 4096;
|
|
|
11
11
|
export const MODEL_REGISTRY = {
|
|
12
12
|
// 2026-08 suite refresh: current models are claude-sonnet-5 / claude-opus-5
|
|
13
13
|
// (Anthropic; claude-opus-5-5 succeeded claude-opus-5 on 2026-09-22), the gpt-5.6 sol/terra/luna family (OpenAI), and the Gemini
|
|
14
|
-
// 3.5/3.6 GA line plus gemini-3.1-pro-preview (Google).
|
|
14
|
+
// 3.5/3.6 GA line plus gemini-3.1-pro-preview (Google). Google's 2026-10
|
|
15
|
+
// deprecation notice: `temperature`/`topP`/`topK` have had no effect since
|
|
16
|
+
// 3.6 Flash and, like `thinkingBudget`, will 400 on models after 3.8 Flash
|
|
17
|
+
// — hence `supportsTemperature: false` from 3.6 Flash on and `effort`
|
|
18
|
+
// (thinking level) as the reasoning control on every Gemini 3.x entry.
|
|
19
|
+
// Older names stay
|
|
15
20
|
// registered so existing callers keep working, but no fallback chain routes
|
|
16
21
|
// through a retiring model: gemini-2.5-pro and gemini-2.5-flash shut down
|
|
17
22
|
// 2026-10-16, and the gpt-4o snapshots retire from 2026-10 onward.
|
|
@@ -30,6 +35,8 @@ export const MODEL_REGISTRY = {
|
|
|
30
35
|
// so no `thinksByDefault` headroom warning.
|
|
31
36
|
// Rejects thinkingBudget 0 (400, verified 2026-08-09).
|
|
32
37
|
supportsThinkingBudgetZero: false,
|
|
38
|
+
supportsEffort: true,
|
|
39
|
+
thinkingLevels: ['minimal', 'low', 'medium', 'high'],
|
|
33
40
|
},
|
|
34
41
|
'gemini-3.6-flash': {
|
|
35
42
|
provider: 'gemini',
|
|
@@ -40,6 +47,11 @@ export const MODEL_REGISTRY = {
|
|
|
40
47
|
thinksByDefault: true,
|
|
41
48
|
// Rejects thinkingBudget 0 (400, verified 2026-08-09).
|
|
42
49
|
supportsThinkingBudgetZero: false,
|
|
50
|
+
supportsEffort: true,
|
|
51
|
+
thinkingLevels: ['minimal', 'low', 'medium', 'high'],
|
|
52
|
+
// Sampling parameters are fixed at their defaults from this model on
|
|
53
|
+
// (Google, 2026-10); still accepted today, so omitting changes nothing.
|
|
54
|
+
supportsTemperature: false,
|
|
43
55
|
},
|
|
44
56
|
'gpt-5.6-luna': {
|
|
45
57
|
provider: 'openai',
|
|
@@ -63,11 +75,14 @@ export const MODEL_REGISTRY = {
|
|
|
63
75
|
provider: 'gemini',
|
|
64
76
|
apiModelId: 'gemini-3.1-flash-lite',
|
|
65
77
|
fallbacks: ['claude-sonnet-4-6'],
|
|
78
|
+
supportsEffort: true,
|
|
66
79
|
},
|
|
67
80
|
'gemini-3-flash-preview': {
|
|
68
81
|
provider: 'gemini',
|
|
69
82
|
apiModelId: 'gemini-3-flash-preview',
|
|
70
83
|
fallbacks: ['claude-haiku-4-5', 'gpt-5.6-luna'],
|
|
84
|
+
supportsEffort: true,
|
|
85
|
+
thinkingLevels: ['minimal', 'low', 'medium', 'high'],
|
|
71
86
|
},
|
|
72
87
|
'gpt-4o-mini': {
|
|
73
88
|
provider: 'openai',
|
|
@@ -181,6 +196,8 @@ export const MODEL_REGISTRY = {
|
|
|
181
196
|
thinksByDefault: true,
|
|
182
197
|
// Rejects thinkingBudget 0 (400, verified 2026-08-09).
|
|
183
198
|
supportsThinkingBudgetZero: false,
|
|
199
|
+
// Levels low|medium|high only (no `minimal`) — the default set.
|
|
200
|
+
supportsEffort: true,
|
|
184
201
|
},
|
|
185
202
|
// Retiring 2026-10-16 — migrate callers to gemini-3.1-pro-preview.
|
|
186
203
|
'gemini-2.5-pro': {
|
|
@@ -53,13 +53,18 @@ export const geminiProvider = {
|
|
|
53
53
|
generationConfig.responseSchema = stripUnsupportedSchemaFields(request.jsonSchema.schema);
|
|
54
54
|
}
|
|
55
55
|
// Gemini thinking models reason before answering; the reasoning tokens
|
|
56
|
-
// count against maxOutputTokens.
|
|
57
|
-
//
|
|
58
|
-
//
|
|
56
|
+
// count against maxOutputTokens. `effort` (pre-gated and clamped in
|
|
57
|
+
// complete.ts) is the current control, sent as a thinking level — not a
|
|
58
|
+
// token cap, so callers size maxOutputTokens for it. The deprecated
|
|
59
|
+
// thinkingBudget is still forwarded when no level is set (the API rejects
|
|
60
|
+
// both together). Models with a thinking floor (registry
|
|
59
61
|
// `supportsThinkingBudgetZero: false`) reject an explicit 0 budget with a
|
|
60
62
|
// 400 — for those a 0 means "as little thinking as possible", which their
|
|
61
63
|
// default already is, so the config is omitted entirely.
|
|
62
|
-
if (request.
|
|
64
|
+
if (request.effort) {
|
|
65
|
+
generationConfig.thinkingConfig = { thinkingLevel: request.effort };
|
|
66
|
+
}
|
|
67
|
+
else if (request.thinkingBudget !== undefined
|
|
63
68
|
&& (request.thinkingBudget !== 0 || request.supportsThinkingBudgetZero)) {
|
|
64
69
|
generationConfig.thinkingConfig = { thinkingBudget: request.thinkingBudget };
|
|
65
70
|
}
|
package/dist/llm/types.d.ts
CHANGED
|
@@ -35,21 +35,25 @@ export interface LLMRequest {
|
|
|
35
35
|
/** Timeout per provider attempt, including response body download, in ms. Default: 60000. */
|
|
36
36
|
timeoutMs?: number;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
38
|
+
* @deprecated Use `effort`. Gemini's token cap on hidden reasoning. Gemini
|
|
39
|
+
* 3.x already remaps a budget to a thinking *level* (so it is no longer a
|
|
40
|
+
* cap), and Google has announced that models after 3.8 Flash reject it
|
|
41
|
+
* outright (400). Still forwarded to Gemini when `effort` is absent, with
|
|
42
|
+
* WARN `llm.thinking_budget_deprecated` per call; ignored by Anthropic and
|
|
43
|
+
* OpenAI, and ignored by Gemini when `effort` is also set.
|
|
44
44
|
*/
|
|
45
45
|
thinkingBudget?: number;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
47
|
+
* Reasoning-effort level for models that expose one (registry
|
|
48
|
+
* `supportsEffort`): Anthropic `output_config.effort`, Gemini
|
|
49
|
+
* `thinkingConfig.thinkingLevel`. Lower effort trades thoroughness for
|
|
50
|
+
* latency and cost. A level the target model lacks is clamped to its
|
|
51
|
+
* nearest supported level (registry `thinkingLevels`; `minimal` → `low` on
|
|
52
|
+
* Anthropic). Dropped for models without the control, so a failed-over
|
|
53
|
+
* call runs at the fallback's defaults. Levels are not token caps: size
|
|
54
|
+
* `maxTokens` for the reasoning the level will do.
|
|
51
55
|
*/
|
|
52
|
-
effort?:
|
|
56
|
+
effort?: Effort;
|
|
53
57
|
/**
|
|
54
58
|
* Optional short identifier for the calling feature (e.g. 'video_classify',
|
|
55
59
|
* 'message_prioritize', 'log_summary'). Included in llm.request and
|
|
@@ -80,6 +84,14 @@ export interface LLMRequest {
|
|
|
80
84
|
* provider-specific vocabulary local to the adapter that owns it.
|
|
81
85
|
*/
|
|
82
86
|
export type FinishCategory = 'complete' | 'truncated' | 'declined' | 'other';
|
|
87
|
+
/**
|
|
88
|
+
* Reasoning-effort levels, ordered from least to most. Each provider adapter
|
|
89
|
+
* maps a level to its native control (Anthropic `output_config.effort`,
|
|
90
|
+
* Gemini `thinkingConfig.thinkingLevel`); `minimal` exists only on some
|
|
91
|
+
* Gemini models and means "no hidden reasoning".
|
|
92
|
+
*/
|
|
93
|
+
export declare const EFFORT_LEVELS: readonly ["minimal", "low", "medium", "high"];
|
|
94
|
+
export type Effort = (typeof EFFORT_LEVELS)[number];
|
|
83
95
|
/** Successful response from llmComplete(). */
|
|
84
96
|
export interface LLMResponse {
|
|
85
97
|
/** The text output (or JSON stringified if jsonSchema was used). */
|
|
@@ -188,8 +200,11 @@ export interface ProviderCallRequest {
|
|
|
188
200
|
logger?: Logger;
|
|
189
201
|
timeoutMs: number;
|
|
190
202
|
thinkingBudget?: number;
|
|
191
|
-
/**
|
|
192
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Effort level, pre-gated by the registry's `supportsEffort` (absent when
|
|
205
|
+
* unsupported) and clamped to the model's `thinkingLevels`.
|
|
206
|
+
*/
|
|
207
|
+
effort?: Effort;
|
|
193
208
|
callSite?: string;
|
|
194
209
|
cacheSystemPrompt?: boolean;
|
|
195
210
|
}
|
package/dist/llm/types.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reasoning-effort levels, ordered from least to most. Each provider adapter
|
|
3
|
+
* maps a level to its native control (Anthropic `output_config.effort`,
|
|
4
|
+
* Gemini `thinkingConfig.thinkingLevel`); `minimal` exists only on some
|
|
5
|
+
* Gemini models and means "no hidden reasoning".
|
|
6
|
+
*/
|
|
7
|
+
export const EFFORT_LEVELS = ['minimal', 'low', 'medium', 'high'];
|
|
1
8
|
/** Error thrown when an LLM provider call fails. Its message may contain private input; do not log verbatim. */
|
|
2
9
|
export class LLMError extends Error {
|
|
3
10
|
provider;
|
package/package.json
CHANGED