@wrenautomation/models 0.0.0-stage → 0.7.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/LICENSE.md +91 -0
- package/README.md +105 -2
- package/dist/command.d.ts +44 -0
- package/dist/command.js +151 -0
- package/dist/command.js.map +1 -0
- package/dist/errors.d.ts +62 -0
- package/dist/errors.js +95 -0
- package/dist/errors.js.map +1 -0
- package/dist/fake.d.ts +5 -0
- package/dist/fake.js +37 -0
- package/dist/fake.js.map +1 -0
- package/dist/hear.d.ts +65 -0
- package/dist/hear.js +106 -0
- package/dist/hear.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +36 -0
- package/dist/keys.js +110 -0
- package/dist/keys.js.map +1 -0
- package/dist/model.d.ts +21 -0
- package/dist/model.js +68 -0
- package/dist/model.js.map +1 -0
- package/dist/parse.d.ts +15 -0
- package/dist/parse.js +66 -0
- package/dist/parse.js.map +1 -0
- package/dist/prices.d.ts +50 -0
- package/dist/prices.js +153 -0
- package/dist/prices.js.map +1 -0
- package/dist/providers.d.ts +83 -0
- package/dist/providers.js +171 -0
- package/dist/providers.js.map +1 -0
- package/dist/sdk.d.ts +34 -0
- package/dist/sdk.js +170 -0
- package/dist/sdk.js.map +1 -0
- package/dist/spec.d.ts +11 -0
- package/dist/spec.js +70 -0
- package/dist/spec.js.map +1 -0
- package/dist/types.d.ts +97 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -3
package/dist/prices.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export const PRICES_AS_OF = "2026-10-27";
|
|
2
|
+
/** Anthropic's cache rates from its input and read rates. */
|
|
3
|
+
const claude = (input, output, cacheRead = input / 10) => ({
|
|
4
|
+
input,
|
|
5
|
+
output,
|
|
6
|
+
cacheRead,
|
|
7
|
+
cacheWrite5m: input * 1.25,
|
|
8
|
+
cacheWrite1h: input * 2,
|
|
9
|
+
});
|
|
10
|
+
export const MODEL_PRICES = [
|
|
11
|
+
{
|
|
12
|
+
model: "claude-opus-5-5",
|
|
13
|
+
name: "Opus 5.5",
|
|
14
|
+
vendor: "anthropic",
|
|
15
|
+
tiers: [{ upTo: null, rate: claude(4, 20, 0.2) }],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
model: "claude-sonnet-5-5",
|
|
19
|
+
name: "Sonnet 5.5",
|
|
20
|
+
vendor: "anthropic",
|
|
21
|
+
tiers: [{ upTo: null, rate: claude(2, 10) }],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
model: "claude-haiku-5-5",
|
|
25
|
+
name: "Haiku 5.5",
|
|
26
|
+
vendor: "anthropic",
|
|
27
|
+
tiers: [
|
|
28
|
+
{ upTo: 100_000, rate: claude(0.1, 0.5) },
|
|
29
|
+
{ upTo: null, rate: claude(0.5, 2.5) },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
model: "claude-haiku-4-5",
|
|
34
|
+
name: "Haiku 4.5",
|
|
35
|
+
vendor: "anthropic",
|
|
36
|
+
tiers: [{ upTo: null, rate: claude(1, 5) }],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
model: "command-a-03-2025",
|
|
40
|
+
name: "Command A",
|
|
41
|
+
vendor: "cohere",
|
|
42
|
+
tiers: [{ upTo: null, rate: { input: 2.5, output: 10 } }],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
model: "openai/gpt-oss-120b",
|
|
46
|
+
name: "gpt-oss-120b on Groq",
|
|
47
|
+
vendor: "groq",
|
|
48
|
+
tiers: [{ upTo: null, rate: { input: 0.15, output: 0.6, cacheRead: 0.075 } }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
// Introductory to 2026-12-31; from 2027-01-01 $1.50 in, $7.50 out.
|
|
52
|
+
model: "gemini-3.8-flash",
|
|
53
|
+
name: "Gemini 3.8 Flash",
|
|
54
|
+
vendor: "google",
|
|
55
|
+
tiers: [{ upTo: null, rate: { input: 0.75, output: 3.75 } }],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
model: "gemini-3.5-flash",
|
|
59
|
+
name: "Gemini 3.5 Flash",
|
|
60
|
+
vendor: "google",
|
|
61
|
+
tiers: [{ upTo: null, rate: { input: 1.5, output: 9 } }],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
model: "gemini-3.5-flash-lite",
|
|
65
|
+
name: "Gemini 3.5 Flash-Lite",
|
|
66
|
+
vendor: "google",
|
|
67
|
+
tiers: [{ upTo: null, rate: { input: 0.3, output: 2.5 } }],
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
/** Speech to text, USD per hour of audio. */
|
|
71
|
+
export const SPEECH_PRICES = {
|
|
72
|
+
"whisper-large-v3-turbo": 0.04,
|
|
73
|
+
"whisper-large-v3": 0.111,
|
|
74
|
+
};
|
|
75
|
+
/** The model id with its vendor prefix (`groq:`, `anthropic/`) off, when the bare id has a row. */
|
|
76
|
+
const bare = (model) => model.slice(model.indexOf(":") + 1);
|
|
77
|
+
/** The price row for a model id; a dated id takes its base's. */
|
|
78
|
+
export function priceOf(model) {
|
|
79
|
+
const find = (id) => MODEL_PRICES.find((p) => p.model === id) ??
|
|
80
|
+
MODEL_PRICES.find((p) => id.startsWith(`${p.model}-`) && /^\d+$/.test(id.slice(p.model.length + 1))) ??
|
|
81
|
+
null;
|
|
82
|
+
return find(model) ?? find(bare(model));
|
|
83
|
+
}
|
|
84
|
+
const n = (v) => (v && v > 0 ? v : 0);
|
|
85
|
+
/** The call's cost in USD, or undefined when the model has no row. Never throws. */
|
|
86
|
+
export function priceUsd(model, u) {
|
|
87
|
+
const p = priceOf(model);
|
|
88
|
+
if (!p)
|
|
89
|
+
return undefined;
|
|
90
|
+
const input = n(u.input);
|
|
91
|
+
const cacheRead = Math.min(n(u.cacheRead), input);
|
|
92
|
+
const cacheWrite = Math.min(n(u.cacheWrite), input - cacheRead);
|
|
93
|
+
const write1h = Math.min(n(u.cacheWrite1h), cacheWrite);
|
|
94
|
+
const plain = input - cacheRead - cacheWrite;
|
|
95
|
+
const tier = p.tiers.find((t) => t.upTo === null || input <= t.upTo) ?? p.tiers.at(-1);
|
|
96
|
+
if (!tier)
|
|
97
|
+
return undefined;
|
|
98
|
+
const r = tier.rate;
|
|
99
|
+
return ((plain * r.input +
|
|
100
|
+
cacheRead * (r.cacheRead ?? r.input) +
|
|
101
|
+
(cacheWrite - write1h) * (r.cacheWrite5m ?? r.input) +
|
|
102
|
+
write1h * (r.cacheWrite1h ?? r.input) +
|
|
103
|
+
n(u.output) * r.output) /
|
|
104
|
+
1_000_000);
|
|
105
|
+
}
|
|
106
|
+
/** The usage with its price. A free call says `usd: 0`, `free: true` and its list price. */
|
|
107
|
+
export function priced(model, usage, o = {}) {
|
|
108
|
+
const list = priceUsd(model, usage);
|
|
109
|
+
if (o.free)
|
|
110
|
+
return { ...usage, usd: 0, free: true, ...(list !== undefined ? { listUsd: list } : {}) };
|
|
111
|
+
return list === undefined ? { ...usage } : { ...usage, usd: list };
|
|
112
|
+
}
|
|
113
|
+
/** What `seconds` of speech cost on a speech model, or undefined with no row. */
|
|
114
|
+
export function speechUsd(model, seconds) {
|
|
115
|
+
const perHour = SPEECH_PRICES[bare(model)] ?? SPEECH_PRICES[model];
|
|
116
|
+
return perHour === undefined ? undefined : (perHour * seconds) / 3600;
|
|
117
|
+
}
|
|
118
|
+
/** Two usages added, each field summed where either side has it. */
|
|
119
|
+
export function addUsage(a, b) {
|
|
120
|
+
if (!a)
|
|
121
|
+
return b;
|
|
122
|
+
if (!b)
|
|
123
|
+
return a;
|
|
124
|
+
const out = {};
|
|
125
|
+
for (const k of [
|
|
126
|
+
"input",
|
|
127
|
+
"output",
|
|
128
|
+
"cacheRead",
|
|
129
|
+
"cacheWrite",
|
|
130
|
+
"cacheWrite1h",
|
|
131
|
+
"usd",
|
|
132
|
+
"listUsd",
|
|
133
|
+
]) {
|
|
134
|
+
const x = a[k];
|
|
135
|
+
const y = b[k];
|
|
136
|
+
if (x !== undefined || y !== undefined)
|
|
137
|
+
out[k] = (x ?? 0) + (y ?? 0);
|
|
138
|
+
}
|
|
139
|
+
if (a.free && b.free)
|
|
140
|
+
out.free = true;
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
const dollars = (v) => `$${v.toFixed(2)}`;
|
|
144
|
+
/** "Opus 5.5 $4.00 in, $20.00 out; ... per million tokens". */
|
|
145
|
+
export function pricesText(vendor) {
|
|
146
|
+
return `${MODEL_PRICES.filter((m) => !vendor || m.vendor === vendor)
|
|
147
|
+
.flatMap((m) => {
|
|
148
|
+
const r = m.tiers[0]?.rate;
|
|
149
|
+
return r ? [`${m.name} ${dollars(r.input)} in, ${dollars(r.output)} out`] : [];
|
|
150
|
+
})
|
|
151
|
+
.join("; ")}, per million tokens`;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=prices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prices.js","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CAAC;AAoBzC,6DAA6D;AAC7D,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,SAAS,GAAG,KAAK,GAAG,EAAE,EAAQ,EAAE,CAAC,CAAC;IAC/E,KAAK;IACL,MAAM;IACN,SAAS;IACT,YAAY,EAAE,KAAK,GAAG,IAAI;IAC1B,YAAY,EAAE,KAAK,GAAG,CAAC;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAA0B;IACjD;QACE,KAAK,EAAE,iBAAiB;QACxB,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EA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CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;QAC3B,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjF,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type RotateOptions } from "./keys.js";
|
|
2
|
+
import type { Clip, Model } from "./types.js";
|
|
3
|
+
/** Short names for the current Claude models. A full id passes through. */
|
|
4
|
+
export declare const ANTHROPIC_MODELS: Readonly<Record<string, string>>;
|
|
5
|
+
export declare const anthropicModelId: (name: string) => string;
|
|
6
|
+
export interface VendorOptions {
|
|
7
|
+
key: string | readonly string[];
|
|
8
|
+
/** A model id or, on Anthropic, a short name. */
|
|
9
|
+
model?: string;
|
|
10
|
+
rotate?: RotateOptions;
|
|
11
|
+
limitMs?: number;
|
|
12
|
+
/** The wire: a test's, or a proxy's (wren's gateway holds Gemini keys behind one). */
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
}
|
|
15
|
+
/** Claude on Wren's own key. Default Haiku 5.5. */
|
|
16
|
+
export declare function anthropic(o: VendorOptions): Model;
|
|
17
|
+
/**
|
|
18
|
+
* Gemini on the free key ring. It takes every part kind, YouTube URLs as video included. A video
|
|
19
|
+
* part with a `clip` goes to generateContent with `videoMetadata` (`withClips`). Gemini's
|
|
20
|
+
* Interactions API also reads a stretch, but on free keys its flash quota is spent at once.
|
|
21
|
+
*/
|
|
22
|
+
export declare function gemini(o: VendorOptions): Model;
|
|
23
|
+
/**
|
|
24
|
+
* A fetch that adds Gemini's `videoMetadata` to each video part of a generateContent body: one
|
|
25
|
+
* clip per video part, in prompt order (`undefined` leaves that part whole). The SDK builds the
|
|
26
|
+
* rest of the body and reads the reply.
|
|
27
|
+
*/
|
|
28
|
+
export declare function withClips(clips: readonly (Clip | undefined)[], go: typeof fetch): typeof fetch;
|
|
29
|
+
/**
|
|
30
|
+
* The Gemini keys the API still takes. A suspended key answers 403 and the ring passes it at once,
|
|
31
|
+
* but only after the call is sent: check first before a large inline body goes to each.
|
|
32
|
+
*/
|
|
33
|
+
export declare function geminiLiveKeys(keys: readonly string[], o?: {
|
|
34
|
+
fetch?: typeof fetch;
|
|
35
|
+
}): Promise<string[]>;
|
|
36
|
+
/** Cohere's own API on the free key ring: text and images. */
|
|
37
|
+
export declare function cohere(o: VendorOptions): Model;
|
|
38
|
+
/** OpenAI-compatible vendors: base URL, default model, and whether Wren's keys there are free. */
|
|
39
|
+
export declare const COMPATIBLE: {
|
|
40
|
+
readonly groq: {
|
|
41
|
+
readonly baseURL: "https://api.groq.com/openai/v1";
|
|
42
|
+
readonly model: "openai/gpt-oss-120b";
|
|
43
|
+
readonly free: () => boolean;
|
|
44
|
+
};
|
|
45
|
+
readonly openrouter: {
|
|
46
|
+
readonly baseURL: "https://openrouter.ai/api/v1";
|
|
47
|
+
readonly model: "google/gemma-4-31b-it:free";
|
|
48
|
+
readonly free: (m: string) => boolean;
|
|
49
|
+
};
|
|
50
|
+
readonly mistral: {
|
|
51
|
+
readonly baseURL: "https://api.mistral.ai/v1";
|
|
52
|
+
readonly model: "mistral-small-latest";
|
|
53
|
+
readonly free: () => boolean;
|
|
54
|
+
};
|
|
55
|
+
readonly cerebras: {
|
|
56
|
+
readonly baseURL: "https://api.cerebras.ai/v1";
|
|
57
|
+
readonly model: "gpt-oss-120b";
|
|
58
|
+
readonly free: () => boolean;
|
|
59
|
+
};
|
|
60
|
+
readonly openai: {
|
|
61
|
+
readonly baseURL: "https://api.openai.com/v1";
|
|
62
|
+
readonly model: "gpt-5-mini";
|
|
63
|
+
readonly free: () => boolean;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export type CompatibleVendor = keyof typeof COMPATIBLE;
|
|
67
|
+
export declare const isCompatible: (v: string) => v is CompatibleVendor;
|
|
68
|
+
export declare function compatible(vendor: CompatibleVendor, o: VendorOptions): Model;
|
|
69
|
+
/** The gateway's Gemini spends output tokens thinking first: 400 asked came back as 27 chars. */
|
|
70
|
+
export declare const GATEWAY_THINKING = 4096;
|
|
71
|
+
/** `<url>/v1`; a URL given with its `/v1` is not doubled. */
|
|
72
|
+
export declare const gatewayBase: (url: string) => string;
|
|
73
|
+
/**
|
|
74
|
+
* Wren's LLM gateway (llm.wrenautomation.com): it holds the free keys and one ledger. Its model is
|
|
75
|
+
* an alias (`free`, `cohere`) or `<vendor>/<model>`. `free` costs 0.
|
|
76
|
+
*/
|
|
77
|
+
export declare function gateway(o: {
|
|
78
|
+
url: string;
|
|
79
|
+
token: string;
|
|
80
|
+
model?: string;
|
|
81
|
+
limitMs?: number;
|
|
82
|
+
fetch?: typeof fetch;
|
|
83
|
+
}): Model;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vendors. Each maker returns a `Model`; a list of keys returns one rotating over them.
|
|
3
|
+
* Free key rings (Cohere, Gemini, Groq, OpenRouter's `:free` models, the gateway's `free` alias)
|
|
4
|
+
* cost 0 and keep their list price; the rest are priced from the table.
|
|
5
|
+
*/
|
|
6
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
7
|
+
import { createCohere } from "@ai-sdk/cohere";
|
|
8
|
+
import { createGoogle } from "@ai-sdk/google";
|
|
9
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
10
|
+
import { rotating } from "./keys.js";
|
|
11
|
+
import { TEXT_ONLY } from "./model.js";
|
|
12
|
+
import { sdkModel } from "./sdk.js";
|
|
13
|
+
const kinds = (...k) => new Set(k);
|
|
14
|
+
const keyList = (key) => (typeof key === "string" ? [key] : key);
|
|
15
|
+
const ring = (keys, make, o, vendor) => {
|
|
16
|
+
if (!keys.length)
|
|
17
|
+
throw new Error(`${vendor} needs at least one key`);
|
|
18
|
+
return rotating(keys.map(make), o);
|
|
19
|
+
};
|
|
20
|
+
/** Short names for the current Claude models. A full id passes through. */
|
|
21
|
+
export const ANTHROPIC_MODELS = {
|
|
22
|
+
haiku: "claude-haiku-5-5",
|
|
23
|
+
sonnet: "claude-sonnet-5-5",
|
|
24
|
+
opus: "claude-opus-5-5",
|
|
25
|
+
};
|
|
26
|
+
export const anthropicModelId = (name) => ANTHROPIC_MODELS[name] ?? name;
|
|
27
|
+
const wire = (o) => (o.fetch ? { fetch: o.fetch } : {});
|
|
28
|
+
/** Claude on Wren's own key. Default Haiku 5.5. */
|
|
29
|
+
export function anthropic(o) {
|
|
30
|
+
const modelId = anthropicModelId(o.model ?? "haiku");
|
|
31
|
+
return ring(keyList(o.key), (apiKey) => sdkModel({
|
|
32
|
+
provider: "anthropic",
|
|
33
|
+
secret: apiKey,
|
|
34
|
+
modelId,
|
|
35
|
+
model: createAnthropic({ apiKey, ...wire(o) })(modelId),
|
|
36
|
+
takes: kinds("text", "image", "pdf"),
|
|
37
|
+
...(o.limitMs ? { limitMs: o.limitMs } : {}),
|
|
38
|
+
}), o.rotate, "anthropic");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gemini on the free key ring. It takes every part kind, YouTube URLs as video included. A video
|
|
42
|
+
* part with a `clip` goes to generateContent with `videoMetadata` (`withClips`). Gemini's
|
|
43
|
+
* Interactions API also reads a stretch, but on free keys its flash quota is spent at once.
|
|
44
|
+
*/
|
|
45
|
+
export function gemini(o) {
|
|
46
|
+
const modelId = o.model ?? "gemini-3.5-flash";
|
|
47
|
+
return ring(keyList(o.key), (apiKey) => sdkModel({
|
|
48
|
+
provider: "google",
|
|
49
|
+
secret: apiKey,
|
|
50
|
+
modelId,
|
|
51
|
+
model: createGoogle({ apiKey, ...wire(o) })(modelId),
|
|
52
|
+
clipModel: (clips) => createGoogle({ apiKey, fetch: withClips(clips, o.fetch ?? fetch) })(modelId),
|
|
53
|
+
takes: kinds("text", "image", "video", "audio", "pdf"),
|
|
54
|
+
free: true,
|
|
55
|
+
...(o.limitMs ? { limitMs: o.limitMs } : {}),
|
|
56
|
+
}), o.rotate, "gemini");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A fetch that adds Gemini's `videoMetadata` to each video part of a generateContent body: one
|
|
60
|
+
* clip per video part, in prompt order (`undefined` leaves that part whole). The SDK builds the
|
|
61
|
+
* rest of the body and reads the reply.
|
|
62
|
+
*/
|
|
63
|
+
export function withClips(clips, go) {
|
|
64
|
+
return (url, init) => {
|
|
65
|
+
if (typeof init?.body !== "string")
|
|
66
|
+
return go(url, init);
|
|
67
|
+
const body = JSON.parse(init.body);
|
|
68
|
+
let n = 0;
|
|
69
|
+
for (const content of body.contents ?? [])
|
|
70
|
+
for (const part of content.parts ?? []) {
|
|
71
|
+
const file = (part.fileData ?? part.inlineData);
|
|
72
|
+
if (!file?.mimeType?.startsWith("video/"))
|
|
73
|
+
continue;
|
|
74
|
+
const clip = clips[n++];
|
|
75
|
+
if (clip)
|
|
76
|
+
part.videoMetadata = {
|
|
77
|
+
startOffset: `${clip.startS}s`,
|
|
78
|
+
endOffset: `${clip.endS}s`,
|
|
79
|
+
...(clip.fps ? { fps: clip.fps } : {}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return go(url, { ...init, body: JSON.stringify(body) });
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const GEMINI_MODELS = "https://generativelanguage.googleapis.com/v1beta/models?pageSize=1";
|
|
86
|
+
/**
|
|
87
|
+
* The Gemini keys the API still takes. A suspended key answers 403 and the ring passes it at once,
|
|
88
|
+
* but only after the call is sent: check first before a large inline body goes to each.
|
|
89
|
+
*/
|
|
90
|
+
export async function geminiLiveKeys(keys, o = {}) {
|
|
91
|
+
const fetchFn = o.fetch ?? fetch;
|
|
92
|
+
const ok = await Promise.all(keys.map((key) => fetchFn(GEMINI_MODELS, {
|
|
93
|
+
headers: { "x-goog-api-key": key },
|
|
94
|
+
signal: AbortSignal.timeout(15_000),
|
|
95
|
+
}).then((r) => r.ok, () => false)));
|
|
96
|
+
return keys.filter((_, i) => ok[i]);
|
|
97
|
+
}
|
|
98
|
+
/** Cohere's own API on the free key ring: text and images. */
|
|
99
|
+
export function cohere(o) {
|
|
100
|
+
const modelId = o.model ?? "command-a-03-2025";
|
|
101
|
+
return ring(keyList(o.key), (apiKey) => sdkModel({
|
|
102
|
+
provider: "cohere",
|
|
103
|
+
secret: apiKey,
|
|
104
|
+
modelId,
|
|
105
|
+
model: createCohere({ apiKey, ...wire(o) })(modelId),
|
|
106
|
+
takes: modelId.includes("vision") ? kinds("text", "image") : TEXT_ONLY,
|
|
107
|
+
free: true,
|
|
108
|
+
...(o.limitMs ? { limitMs: o.limitMs } : {}),
|
|
109
|
+
}), o.rotate, "cohere");
|
|
110
|
+
}
|
|
111
|
+
/** OpenAI-compatible vendors: base URL, default model, and whether Wren's keys there are free. */
|
|
112
|
+
export const COMPATIBLE = {
|
|
113
|
+
groq: {
|
|
114
|
+
baseURL: "https://api.groq.com/openai/v1",
|
|
115
|
+
model: "openai/gpt-oss-120b",
|
|
116
|
+
free: () => true,
|
|
117
|
+
},
|
|
118
|
+
openrouter: {
|
|
119
|
+
baseURL: "https://openrouter.ai/api/v1",
|
|
120
|
+
model: "google/gemma-4-31b-it:free",
|
|
121
|
+
free: (m) => m.endsWith(":free"),
|
|
122
|
+
},
|
|
123
|
+
mistral: {
|
|
124
|
+
baseURL: "https://api.mistral.ai/v1",
|
|
125
|
+
model: "mistral-small-latest",
|
|
126
|
+
free: () => false,
|
|
127
|
+
},
|
|
128
|
+
cerebras: { baseURL: "https://api.cerebras.ai/v1", model: "gpt-oss-120b", free: () => false },
|
|
129
|
+
openai: { baseURL: "https://api.openai.com/v1", model: "gpt-5-mini", free: () => false },
|
|
130
|
+
};
|
|
131
|
+
export const isCompatible = (v) => Object.hasOwn(COMPATIBLE, v);
|
|
132
|
+
export function compatible(vendor, o) {
|
|
133
|
+
const spec = COMPATIBLE[vendor];
|
|
134
|
+
const modelId = o.model ?? spec.model;
|
|
135
|
+
return ring(keyList(o.key), (apiKey) => sdkModel({
|
|
136
|
+
provider: vendor,
|
|
137
|
+
secret: apiKey,
|
|
138
|
+
modelId,
|
|
139
|
+
model: createOpenAICompatible({ name: vendor, baseURL: spec.baseURL, apiKey, ...wire(o) })(modelId),
|
|
140
|
+
takes: TEXT_ONLY,
|
|
141
|
+
free: spec.free(modelId),
|
|
142
|
+
...(o.limitMs ? { limitMs: o.limitMs } : {}),
|
|
143
|
+
}), o.rotate, vendor);
|
|
144
|
+
}
|
|
145
|
+
/** The gateway's Gemini spends output tokens thinking first: 400 asked came back as 27 chars. */
|
|
146
|
+
export const GATEWAY_THINKING = 4096;
|
|
147
|
+
/** `<url>/v1`; a URL given with its `/v1` is not doubled. */
|
|
148
|
+
export const gatewayBase = (url) => `${url.replace(/\/$/, "").replace(/\/v1$/, "")}/v1`;
|
|
149
|
+
/**
|
|
150
|
+
* Wren's LLM gateway (llm.wrenautomation.com): it holds the free keys and one ledger. Its model is
|
|
151
|
+
* an alias (`free`, `cohere`) or `<vendor>/<model>`. `free` costs 0.
|
|
152
|
+
*/
|
|
153
|
+
export function gateway(o) {
|
|
154
|
+
const modelId = o.model ?? "free";
|
|
155
|
+
return sdkModel({
|
|
156
|
+
provider: "gateway",
|
|
157
|
+
modelId,
|
|
158
|
+
model: createOpenAICompatible({
|
|
159
|
+
name: "gateway",
|
|
160
|
+
baseURL: gatewayBase(o.url),
|
|
161
|
+
apiKey: o.token,
|
|
162
|
+
...wire(o),
|
|
163
|
+
})(modelId),
|
|
164
|
+
takes: TEXT_ONLY,
|
|
165
|
+
thinking: GATEWAY_THINKING,
|
|
166
|
+
free: modelId === "free",
|
|
167
|
+
priceId: modelId.slice(modelId.indexOf("/") + 1),
|
|
168
|
+
...(o.limitMs ? { limitMs: o.limitMs } : {}),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//#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AAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC;AAEhG;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,CAMvB;IACC,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC;IAClC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,SAAS;QACnB,OAAO;QACP,KAAK,EAAE,sBAAsB,CAAC;YAC5B,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;YAC3B,MAAM,EAAE,CAAC,CAAC,KAAK;YACf,GAAG,IAAI,CAAC,CAAC,CAAC;SACX,CAAC,CAAC,OAAO,CAAC;QACX,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,gBAAgB;QAC1B,IAAI,EAAE,OAAO,KAAK,MAAM;QACxB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChD,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7C,CAAC,CAAC;AACL,CAAC"}
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One AI SDK language model as a `Model`. The SDK speaks each vendor's wire; this maps our
|
|
3
|
+
* request in and the reply, tokens, price and errors out. The SDK's own retries are off: the
|
|
4
|
+
* caller (a runner, a key ring) owns trying again.
|
|
5
|
+
*/
|
|
6
|
+
import { type LanguageModel } from "ai";
|
|
7
|
+
import type { Clip, Model, PartKind } from "./types.js";
|
|
8
|
+
/** The ceiling when a request names none. A long extract with quotes passed 4096 on a live run. */
|
|
9
|
+
export declare const DEFAULT_MAX_TOKENS = 8192;
|
|
10
|
+
/** One call, wall clock: a long draft takes a minute or two. */
|
|
11
|
+
export declare const CALL_LIMIT_MS: number;
|
|
12
|
+
export interface SdkModelOptions {
|
|
13
|
+
/** The vendor (`anthropic`, `groq`, `gateway`). */
|
|
14
|
+
provider: string;
|
|
15
|
+
/** The vendor's model id. */
|
|
16
|
+
modelId: string;
|
|
17
|
+
model: LanguageModel;
|
|
18
|
+
/**
|
|
19
|
+
* The model for a request with a clipped video, given each video part's clip in prompt order.
|
|
20
|
+
* Gemini's: generateContent with `videoMetadata`, a field the SDK does not send (`withClips`).
|
|
21
|
+
*/
|
|
22
|
+
clipModel?: (clips: readonly (Clip | undefined)[]) => LanguageModel;
|
|
23
|
+
takes: ReadonlySet<PartKind>;
|
|
24
|
+
/** Tokens added to every ceiling for a model that thinks inside its output budget. */
|
|
25
|
+
thinking?: number;
|
|
26
|
+
/** A free key: the reply costs 0 and keeps its list price. */
|
|
27
|
+
free?: boolean;
|
|
28
|
+
/** The id the price table knows, when it is not `modelId`. */
|
|
29
|
+
priceId?: string;
|
|
30
|
+
limitMs?: number;
|
|
31
|
+
/** The call's key, put out of every error message. */
|
|
32
|
+
secret?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function sdkModel(o: SdkModelOptions): Model;
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One AI SDK language model as a `Model`. The SDK speaks each vendor's wire; this maps our
|
|
3
|
+
* request in and the reply, tokens, price and errors out. The SDK's own retries are off: the
|
|
4
|
+
* caller (a runner, a key ring) owns trying again.
|
|
5
|
+
*/
|
|
6
|
+
import { APICallError, generateText, } from "ai";
|
|
7
|
+
import { Cut, Filtered, redact, statusError, Transient, transport } from "./errors.js";
|
|
8
|
+
import { modelOf } from "./model.js";
|
|
9
|
+
import { wellFormed } from "./parse.js";
|
|
10
|
+
import { priced } from "./prices.js";
|
|
11
|
+
/** The ceiling when a request names none. A long extract with quotes passed 4096 on a live run. */
|
|
12
|
+
export const DEFAULT_MAX_TOKENS = 8192;
|
|
13
|
+
/** The least a call may answer in: a lower cap only cuts an answer off. */
|
|
14
|
+
const FLOOR_TOKENS = 2048;
|
|
15
|
+
/** One call, wall clock: a long draft takes a minute or two. */
|
|
16
|
+
export const CALL_LIMIT_MS = 5 * 60_000;
|
|
17
|
+
const GEMINI_LEVEL = {
|
|
18
|
+
low: "low",
|
|
19
|
+
medium: "medium",
|
|
20
|
+
high: "high",
|
|
21
|
+
xhigh: "high",
|
|
22
|
+
max: "high",
|
|
23
|
+
};
|
|
24
|
+
const GEMINI_RESOLUTION = {
|
|
25
|
+
low: "MEDIA_RESOLUTION_LOW",
|
|
26
|
+
medium: "MEDIA_RESOLUTION_MEDIUM",
|
|
27
|
+
high: "MEDIA_RESOLUTION_HIGH",
|
|
28
|
+
};
|
|
29
|
+
/** Effort and resolution as the vendor's options. */
|
|
30
|
+
function vendorOptions(provider, req) {
|
|
31
|
+
if (provider === "anthropic")
|
|
32
|
+
return req.effort ? { providerOptions: { anthropic: { effort: req.effort } } } : {};
|
|
33
|
+
if (provider !== "google")
|
|
34
|
+
return {};
|
|
35
|
+
const level = req.effort ? GEMINI_LEVEL[req.effort] : undefined;
|
|
36
|
+
const google = {
|
|
37
|
+
...(level ? { thinkingConfig: { thinkingLevel: level } } : {}),
|
|
38
|
+
...(req.resolution ? { mediaResolution: GEMINI_RESOLUTION[req.resolution] } : {}),
|
|
39
|
+
};
|
|
40
|
+
return Object.keys(google).length ? { providerOptions: { google } } : {};
|
|
41
|
+
}
|
|
42
|
+
/** Each video part's clip, in prompt order; null when no part has one. */
|
|
43
|
+
function clipsOf(req) {
|
|
44
|
+
if (typeof req.prompt === "string")
|
|
45
|
+
return null;
|
|
46
|
+
const clips = req.prompt.flatMap((p) => (p.type === "video" ? [p.clip] : []));
|
|
47
|
+
return clips.some(Boolean) ? clips : null;
|
|
48
|
+
}
|
|
49
|
+
function contentOf(parts) {
|
|
50
|
+
return parts.map((p) => {
|
|
51
|
+
switch (p.type) {
|
|
52
|
+
case "text":
|
|
53
|
+
return { type: "text", text: wellFormed(p.text) };
|
|
54
|
+
case "image":
|
|
55
|
+
return { type: "file", data: p.data, mediaType: p.mediaType };
|
|
56
|
+
case "pdf":
|
|
57
|
+
return { type: "file", data: p.data, mediaType: "application/pdf" };
|
|
58
|
+
default:
|
|
59
|
+
return { type: "file", data: p.data, mediaType: p.mediaType };
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** System and prompt in the SDK's shape. On Anthropic the system carries a cache breakpoint. */
|
|
64
|
+
function input(provider, req) {
|
|
65
|
+
const body = typeof req.prompt === "string"
|
|
66
|
+
? { prompt: wellFormed(req.prompt) }
|
|
67
|
+
: { messages: [{ role: "user", content: contentOf(req.prompt) }] };
|
|
68
|
+
if (!req.system)
|
|
69
|
+
return body;
|
|
70
|
+
if (provider !== "anthropic")
|
|
71
|
+
return { system: wellFormed(req.system), ...body };
|
|
72
|
+
return {
|
|
73
|
+
system: {
|
|
74
|
+
role: "system",
|
|
75
|
+
content: wellFormed(req.system),
|
|
76
|
+
providerOptions: { anthropic: { cacheControl: { type: "ephemeral" } } },
|
|
77
|
+
},
|
|
78
|
+
...body,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function failure(what, err, signal, secrets) {
|
|
82
|
+
if (signal?.aborted)
|
|
83
|
+
return err;
|
|
84
|
+
if (APICallError.isInstance(err)) {
|
|
85
|
+
if (err.statusCode === undefined)
|
|
86
|
+
return transport(what, err);
|
|
87
|
+
const detail = redact(err.message, secrets).slice(0, 300);
|
|
88
|
+
return statusError(`${what}: HTTP ${err.statusCode} ${detail}`, err.statusCode, err.responseHeaders?.["retry-after"]);
|
|
89
|
+
}
|
|
90
|
+
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError"))
|
|
91
|
+
return new Transient(`${what}: no answer in time`, { cause: err });
|
|
92
|
+
if (err instanceof TypeError)
|
|
93
|
+
return transport(what, err);
|
|
94
|
+
return err;
|
|
95
|
+
}
|
|
96
|
+
export function sdkModel(o) {
|
|
97
|
+
const id = o.provider === "anthropic" ? o.modelId : `${o.provider}:${o.modelId}`;
|
|
98
|
+
const limitMs = o.limitMs ?? CALL_LIMIT_MS;
|
|
99
|
+
return modelOf({
|
|
100
|
+
id,
|
|
101
|
+
provider: o.provider,
|
|
102
|
+
takes: o.takes,
|
|
103
|
+
async complete(req) {
|
|
104
|
+
const started = performance.now();
|
|
105
|
+
const timeout = AbortSignal.timeout(limitMs);
|
|
106
|
+
const abortSignal = req.signal ? AbortSignal.any([req.signal, timeout]) : timeout;
|
|
107
|
+
const clips = o.clipModel ? clipsOf(req) : null;
|
|
108
|
+
let result;
|
|
109
|
+
try {
|
|
110
|
+
result = await generateText({
|
|
111
|
+
model: clips && o.clipModel ? o.clipModel(clips) : o.model,
|
|
112
|
+
...input(o.provider, req),
|
|
113
|
+
maxOutputTokens: Math.max(req.maxTokens ?? DEFAULT_MAX_TOKENS, FLOOR_TOKENS) + (o.thinking ?? 0),
|
|
114
|
+
...vendorOptions(o.provider, req),
|
|
115
|
+
maxRetries: 0,
|
|
116
|
+
abortSignal,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
throw failure(id, err, req.signal, o.secret ? [o.secret] : []);
|
|
121
|
+
}
|
|
122
|
+
const u = result.usage;
|
|
123
|
+
const tokens = {};
|
|
124
|
+
if (u.inputTokens !== undefined)
|
|
125
|
+
tokens.input = u.inputTokens;
|
|
126
|
+
if (u.outputTokens !== undefined)
|
|
127
|
+
tokens.output = u.outputTokens;
|
|
128
|
+
if (u.inputTokenDetails?.cacheReadTokens)
|
|
129
|
+
tokens.cacheRead = u.inputTokenDetails.cacheReadTokens;
|
|
130
|
+
if (u.inputTokenDetails?.cacheWriteTokens)
|
|
131
|
+
tokens.cacheWrite = u.inputTokenDetails.cacheWriteTokens;
|
|
132
|
+
const usage = priced(o.priceId ?? o.modelId, tokens, { free: o.free ?? false });
|
|
133
|
+
const stop = result.rawFinishReason ?? result.finishReason;
|
|
134
|
+
if (result.finishReason === "length")
|
|
135
|
+
throw new Cut(`${id} stopped at its output cap (${stop})`, result.text, usage);
|
|
136
|
+
if (result.finishReason === "content-filter")
|
|
137
|
+
throw new Filtered(`${id} stopped the answer itself (${stop})`, String(stop), result.text, usage);
|
|
138
|
+
if (!result.text)
|
|
139
|
+
throw new Error(`${id}: no text in the reply (stop ${stop})`);
|
|
140
|
+
return {
|
|
141
|
+
text: result.text,
|
|
142
|
+
usage,
|
|
143
|
+
model: result.response.modelId || o.modelId,
|
|
144
|
+
stop,
|
|
145
|
+
ms: Math.round(performance.now() - started),
|
|
146
|
+
raw: {
|
|
147
|
+
provider: o.provider,
|
|
148
|
+
model: o.modelId,
|
|
149
|
+
stop_reason: stop,
|
|
150
|
+
finish_reason_unified: result.finishReason,
|
|
151
|
+
usage: {
|
|
152
|
+
input_tokens: u.inputTokens ?? null,
|
|
153
|
+
output_tokens: u.outputTokens ?? null,
|
|
154
|
+
reasoning_tokens: u.outputTokenDetails?.reasoningTokens ?? null,
|
|
155
|
+
cache_read_tokens: u.inputTokenDetails?.cacheReadTokens ?? null,
|
|
156
|
+
cache_write_tokens: u.inputTokenDetails?.cacheWriteTokens ?? null,
|
|
157
|
+
},
|
|
158
|
+
response: {
|
|
159
|
+
id: result.response.id,
|
|
160
|
+
model_id: result.response.modelId,
|
|
161
|
+
timestamp: result.response.timestamp.toISOString(),
|
|
162
|
+
},
|
|
163
|
+
provider_metadata: result.providerMetadata ?? null,
|
|
164
|
+
warnings: result.warnings ?? [],
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=sdk.js.map
|
package/dist/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,YAAY,EACZ,YAAY,GAIb,MAAM,IAAI,CAA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