@steve31415/baselib 3.71.0 → 3.72.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.js +16 -4
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/models.d.ts +8 -0
- package/dist/llm/models.js +5 -0
- package/dist/llm/providers/gemini.js +3 -1
- package/dist/llm/types.d.ts +21 -0
- package/package.json +1 -1
package/dist/llm/complete.js
CHANGED
|
@@ -5,6 +5,12 @@ const DEFAULT_MAX_TOKENS = 2048;
|
|
|
5
5
|
const DEFAULT_TEMPERATURE = 0.3;
|
|
6
6
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
7
7
|
const DEFAULT_THINKING_LEVELS = ['low', 'medium', 'high'];
|
|
8
|
+
/** Input media a model must accept to be tried: the requested model not
|
|
9
|
+
* taking one is rejected up front; a fallback not taking it is skipped. */
|
|
10
|
+
const MEDIA_GATES = [
|
|
11
|
+
{ kind: 'image', label: 'Image', accepts: (entry) => entry.supportsImages === true },
|
|
12
|
+
{ kind: 'audio', label: 'Audio', accepts: (entry) => entry.supportsAudio === true },
|
|
13
|
+
];
|
|
8
14
|
/**
|
|
9
15
|
* The effort level to send a model: none when the model has no effort
|
|
10
16
|
* control, otherwise the requested level clamped to the nearest one the
|
|
@@ -43,10 +49,14 @@ export async function llmComplete(request) {
|
|
|
43
49
|
// requested model not taking them is the caller's bug, so say so rather
|
|
44
50
|
// than silently answering from a fallback; fallbacks without image input
|
|
45
51
|
// are skipped in the loop below.
|
|
52
|
+
// Audio is gated the same way (only Gemini takes it).
|
|
46
53
|
const hasImages = (request.images?.length ?? 0) > 0;
|
|
47
|
-
|
|
54
|
+
const hasAudio = (request.audio?.length ?? 0) > 0;
|
|
55
|
+
for (const gate of MEDIA_GATES) {
|
|
56
|
+
if (!(gate.kind === 'image' ? hasImages : hasAudio) || gate.accepts(entry))
|
|
57
|
+
continue;
|
|
48
58
|
throw new LLMError({
|
|
49
|
-
message: `Model ${request.model} does not accept
|
|
59
|
+
message: `Model ${request.model} does not accept ${gate.kind} input. ${gate.label}-capable models: ${Object.keys(MODEL_REGISTRY).filter((m) => gate.accepts(MODEL_REGISTRY[m])).join(', ')}`,
|
|
50
60
|
provider: entry.provider,
|
|
51
61
|
model: entry.apiModelId,
|
|
52
62
|
isRetryable: false,
|
|
@@ -88,9 +98,10 @@ export async function llmComplete(request) {
|
|
|
88
98
|
const modelEntry = MODEL_REGISTRY[modelName];
|
|
89
99
|
if (!modelEntry)
|
|
90
100
|
continue;
|
|
91
|
-
|
|
101
|
+
const missing = MEDIA_GATES.find((gate) => (gate.kind === 'image' ? hasImages : hasAudio) && !gate.accepts(modelEntry));
|
|
102
|
+
if (missing) {
|
|
92
103
|
request.logger?.debug('llm.skip_provider', {
|
|
93
|
-
model: modelName, provider: modelEntry.provider, reason:
|
|
104
|
+
model: modelName, provider: modelEntry.provider, reason: `no ${missing.kind} input`,
|
|
94
105
|
});
|
|
95
106
|
continue;
|
|
96
107
|
}
|
|
@@ -108,6 +119,7 @@ export async function llmComplete(request) {
|
|
|
108
119
|
apiModelId: modelEntry.apiModelId,
|
|
109
120
|
prompt: request.prompt,
|
|
110
121
|
images: hasImages ? request.images : undefined,
|
|
122
|
+
audio: hasAudio ? request.audio : undefined,
|
|
111
123
|
systemPrompt: request.systemPrompt,
|
|
112
124
|
maxTokens,
|
|
113
125
|
temperature,
|
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, EFFORT_LEVELS, type Effort, type LLMRequest, type LLMResponse, type FailedAttempt, type FinishCategory, type ProviderName, type ApiKeys, type JsonSchema, type LLMImage, type LLMImageMediaType, } from './types.js';
|
|
4
|
+
export { LLMError, EFFORT_LEVELS, type Effort, type LLMRequest, type LLMResponse, type FailedAttempt, type FinishCategory, type ProviderName, type ApiKeys, type JsonSchema, type LLMImage, type LLMImageMediaType, type LLMAudio, type LLMAudioMediaType, } from './types.js';
|
package/dist/llm/models.d.ts
CHANGED
|
@@ -66,6 +66,14 @@ export interface ModelEntry {
|
|
|
66
66
|
* was verified live (test/helpers/llm.ts records the probe).
|
|
67
67
|
*/
|
|
68
68
|
supportsImages?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether this model accepts audio input (`LLMRequest.audio`). Defaults to
|
|
71
|
+
* `false`, gated exactly like `supportsImages`. Set only on models whose
|
|
72
|
+
* audio handling was verified live (test/helpers/llm.ts records the probe):
|
|
73
|
+
* the Gemini 3.x entries. No Anthropic or OpenAI model in the registry
|
|
74
|
+
* takes audio.
|
|
75
|
+
*/
|
|
76
|
+
supportsAudio?: boolean;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
71
79
|
* Output budget below which a `thinksByDefault` model is considered at risk of
|
package/dist/llm/models.js
CHANGED
|
@@ -35,6 +35,7 @@ export const MODEL_REGISTRY = {
|
|
|
35
35
|
provider: 'gemini',
|
|
36
36
|
apiModelId: 'gemini-3.5-flash-lite',
|
|
37
37
|
supportsImages: true,
|
|
38
|
+
supportsAudio: true,
|
|
38
39
|
fallbacks: ['gpt-5.6-luna', 'claude-haiku-4-5'],
|
|
39
40
|
// Default thinking_level is `minimal` — reasoning overhead is negligible,
|
|
40
41
|
// so no `thinksByDefault` headroom warning.
|
|
@@ -47,6 +48,7 @@ export const MODEL_REGISTRY = {
|
|
|
47
48
|
provider: 'gemini',
|
|
48
49
|
apiModelId: 'gemini-3.6-flash',
|
|
49
50
|
supportsImages: true,
|
|
51
|
+
supportsAudio: true,
|
|
50
52
|
fallbacks: ['gpt-5.6-luna', 'claude-haiku-4-5'],
|
|
51
53
|
// Thinks by default (thinking_level defaults to `medium`); reasoning
|
|
52
54
|
// tokens are billed as output and count against maxOutputTokens.
|
|
@@ -83,6 +85,7 @@ export const MODEL_REGISTRY = {
|
|
|
83
85
|
provider: 'gemini',
|
|
84
86
|
apiModelId: 'gemini-3.1-flash-lite',
|
|
85
87
|
supportsImages: true,
|
|
88
|
+
supportsAudio: true,
|
|
86
89
|
fallbacks: ['claude-sonnet-4-6'],
|
|
87
90
|
supportsEffort: true,
|
|
88
91
|
},
|
|
@@ -90,6 +93,7 @@ export const MODEL_REGISTRY = {
|
|
|
90
93
|
provider: 'gemini',
|
|
91
94
|
apiModelId: 'gemini-3-flash-preview',
|
|
92
95
|
supportsImages: true,
|
|
96
|
+
supportsAudio: true,
|
|
93
97
|
fallbacks: ['claude-haiku-4-5', 'gpt-5.6-luna'],
|
|
94
98
|
supportsEffort: true,
|
|
95
99
|
thinkingLevels: ['minimal', 'low', 'medium', 'high'],
|
|
@@ -214,6 +218,7 @@ export const MODEL_REGISTRY = {
|
|
|
214
218
|
provider: 'gemini',
|
|
215
219
|
apiModelId: 'gemini-3.1-pro-preview',
|
|
216
220
|
supportsImages: true,
|
|
221
|
+
supportsAudio: true,
|
|
217
222
|
fallbacks: ['claude-opus-5-5', 'gpt-5.6-sol'],
|
|
218
223
|
// Thinks by default (thinking_level defaults to `high`).
|
|
219
224
|
thinksByDefault: true,
|
|
@@ -65,6 +65,7 @@ export const geminiProvider = {
|
|
|
65
65
|
provider: 'gemini', model: request.apiModelId, endpoint,
|
|
66
66
|
...(request.callSite ? { callSite: request.callSite } : {}),
|
|
67
67
|
...(request.images ? { images: request.images.length } : {}),
|
|
68
|
+
...(request.audio ? { audio: request.audio.length } : {}),
|
|
68
69
|
});
|
|
69
70
|
const startTime = Date.now();
|
|
70
71
|
const generationConfig = {
|
|
@@ -96,10 +97,11 @@ export const geminiProvider = {
|
|
|
96
97
|
generationConfig.thinkingConfig = { thinkingBudget: request.thinkingBudget };
|
|
97
98
|
}
|
|
98
99
|
const body = {
|
|
99
|
-
// Images go as inline-data parts ahead of the prompt's text part.
|
|
100
|
+
// Images, then audio, go as inline-data parts ahead of the prompt's text part.
|
|
100
101
|
contents: [{
|
|
101
102
|
parts: [
|
|
102
103
|
...(request.images ?? []).map((image) => ({ inlineData: { mimeType: image.mediaType, data: image.data } })),
|
|
104
|
+
...(request.audio ?? []).map((clip) => ({ inlineData: { mimeType: clip.mediaType, data: clip.data } })),
|
|
103
105
|
{ text: request.prompt },
|
|
104
106
|
],
|
|
105
107
|
}],
|
package/dist/llm/types.d.ts
CHANGED
|
@@ -21,6 +21,17 @@ export interface LLMImage {
|
|
|
21
21
|
mediaType: LLMImageMediaType;
|
|
22
22
|
data: string;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Audio media types Gemini accepted in the live probe of 2026-11-21 (Ogg with
|
|
26
|
+
* or without a `codecs=opus` parameter, MP3, MP4/AAC, WAV): see
|
|
27
|
+
* test/helpers/llm.ts. Pass the bare type; parameters are not needed.
|
|
28
|
+
*/
|
|
29
|
+
export type LLMAudioMediaType = 'audio/ogg' | 'audio/mpeg' | 'audio/mp4' | 'audio/wav';
|
|
30
|
+
/** A sound recording sent beside the prompt: raw base64, no `data:` URL prefix. */
|
|
31
|
+
export interface LLMAudio {
|
|
32
|
+
mediaType: LLMAudioMediaType;
|
|
33
|
+
data: string;
|
|
34
|
+
}
|
|
24
35
|
/** Request to llmComplete(). */
|
|
25
36
|
export interface LLMRequest {
|
|
26
37
|
/** Model name from the registry (e.g. 'claude-sonnet-4-6', 'gemini-2.5-flash'). */
|
|
@@ -34,6 +45,14 @@ export interface LLMRequest {
|
|
|
34
45
|
* call is rejected up front), and failover skips fallbacks that are not.
|
|
35
46
|
*/
|
|
36
47
|
images?: LLMImage[];
|
|
48
|
+
/**
|
|
49
|
+
* Audio for the model to listen to beside the prompt (a voice message to
|
|
50
|
+
* transcribe), placed before the prompt text like `images`. Gated the same
|
|
51
|
+
* way, by the registry's `supportsAudio`: only Gemini models take it, so a
|
|
52
|
+
* request with audio has no cross-provider failover — a Gemini outage
|
|
53
|
+
* fails the call, and the caller retries later.
|
|
54
|
+
*/
|
|
55
|
+
audio?: LLMAudio[];
|
|
37
56
|
/** Optional system prompt. */
|
|
38
57
|
systemPrompt?: string;
|
|
39
58
|
/** Max output tokens. Default: 2048. */
|
|
@@ -211,6 +230,8 @@ export interface ProviderCallRequest {
|
|
|
211
230
|
prompt: string;
|
|
212
231
|
/** Present and non-empty only for a `supportsImages` model (gated in complete.ts). */
|
|
213
232
|
images?: LLMImage[];
|
|
233
|
+
/** Present and non-empty only for a `supportsAudio` model (gated in complete.ts). */
|
|
234
|
+
audio?: LLMAudio[];
|
|
214
235
|
systemPrompt?: string;
|
|
215
236
|
maxTokens: number;
|
|
216
237
|
temperature: number;
|
package/package.json
CHANGED