@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/spec.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type EnvMap, type RotateOptions } from "./keys.js";
|
|
2
|
+
import type { Model } from "./types.js";
|
|
3
|
+
export declare const SPEC_NAMES: readonly ["fake", "claude-code", "anthropic", "gateway", "gemini", "cohere", "command", ...string[]];
|
|
4
|
+
/**
|
|
5
|
+
* Keys come from the environment by vendor (`ANTHROPIC_API_KEY`, `GROQ_API_KEY_1`...); the
|
|
6
|
+
* gateway reads `WREN_LLM_GATEWAY_URL` and `WREN_LLM_GATEWAY_TOKEN`. `rotate` sets how a key ring
|
|
7
|
+
* waits when every key is busy.
|
|
8
|
+
*/
|
|
9
|
+
export declare function modelFromSpec(spec: string, env?: EnvMap, o?: {
|
|
10
|
+
rotate?: RotateOptions;
|
|
11
|
+
}): Model;
|
package/dist/spec.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A model from one string and the environment, for a CLI flag or a setting (Node only: it can
|
|
3
|
+
* start `claude -p`). Grammar: `fake` | `claude-code[:model]` | `anthropic[:haiku|sonnet|opus|id]` |
|
|
4
|
+
* `gateway[:alias]` | `gemini[:id]` | `cohere[:id]` | `<groq|openrouter|mistral|cerebras|openai>[:id]` |
|
|
5
|
+
* `command:<shell command>` (the prompt on stdin, the answer on stdout).
|
|
6
|
+
*/
|
|
7
|
+
import { claudeCode, commandModel } from "./command.js";
|
|
8
|
+
import { fakeModel } from "./fake.js";
|
|
9
|
+
import { fleetKeys } from "./keys.js";
|
|
10
|
+
import { anthropic, COMPATIBLE, cohere, compatible, gateway, gemini, isCompatible, } from "./providers.js";
|
|
11
|
+
export const SPEC_NAMES = [
|
|
12
|
+
"fake",
|
|
13
|
+
"claude-code",
|
|
14
|
+
"anthropic",
|
|
15
|
+
"gateway",
|
|
16
|
+
"gemini",
|
|
17
|
+
"cohere",
|
|
18
|
+
"command",
|
|
19
|
+
...Object.keys(COMPATIBLE),
|
|
20
|
+
];
|
|
21
|
+
const keysFor = (env, vendor) => {
|
|
22
|
+
const keys = fleetKeys(env, vendor);
|
|
23
|
+
if (keys.length)
|
|
24
|
+
return keys;
|
|
25
|
+
const upper = vendor.toUpperCase();
|
|
26
|
+
throw new Error(`${vendor} needs ${upper}_API_KEY, or NUM_${upper} and ${upper}_API_KEY_1..N`);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Keys come from the environment by vendor (`ANTHROPIC_API_KEY`, `GROQ_API_KEY_1`...); the
|
|
30
|
+
* gateway reads `WREN_LLM_GATEWAY_URL` and `WREN_LLM_GATEWAY_TOKEN`. `rotate` sets how a key ring
|
|
31
|
+
* waits when every key is busy.
|
|
32
|
+
*/
|
|
33
|
+
export function modelFromSpec(spec, env = process.env, o = {}) {
|
|
34
|
+
const at = spec.indexOf(":");
|
|
35
|
+
const name = at < 0 ? spec : spec.slice(0, at);
|
|
36
|
+
const rest = at < 0 ? undefined : spec.slice(at + 1) || undefined;
|
|
37
|
+
const vendor = (v) => ({
|
|
38
|
+
key: keysFor(env, v),
|
|
39
|
+
...(rest ? { model: rest } : {}),
|
|
40
|
+
...(o.rotate ? { rotate: o.rotate } : {}),
|
|
41
|
+
});
|
|
42
|
+
switch (name) {
|
|
43
|
+
case "fake":
|
|
44
|
+
return fakeModel();
|
|
45
|
+
case "command":
|
|
46
|
+
if (!rest)
|
|
47
|
+
throw new Error("command needs the command after `command:`");
|
|
48
|
+
return commandModel(rest);
|
|
49
|
+
case "claude-code":
|
|
50
|
+
return claudeCode(rest);
|
|
51
|
+
case "anthropic":
|
|
52
|
+
return anthropic(vendor("anthropic"));
|
|
53
|
+
case "gemini":
|
|
54
|
+
return gemini(vendor("gemini"));
|
|
55
|
+
case "cohere":
|
|
56
|
+
return cohere(vendor("cohere"));
|
|
57
|
+
case "gateway": {
|
|
58
|
+
const url = env.WREN_LLM_GATEWAY_URL;
|
|
59
|
+
const token = env.WREN_LLM_GATEWAY_TOKEN;
|
|
60
|
+
if (!url || !token)
|
|
61
|
+
throw new Error("gateway needs WREN_LLM_GATEWAY_URL and WREN_LLM_GATEWAY_TOKEN");
|
|
62
|
+
return gateway({ url, token, ...(rest ? { model: rest } : {}) });
|
|
63
|
+
}
|
|
64
|
+
default:
|
|
65
|
+
if (isCompatible(name))
|
|
66
|
+
return compatible(name, vendor(name));
|
|
67
|
+
throw new Error(`unknown model '${spec}'; expected one of ${SPEC_NAMES.join(", ")} [:model]`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=spec.js.map
|
package/dist/spec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../src/spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAe,SAAS,EAAsB,MAAM,WAAW,CAAC;AACvE,OAAO,EACL,SAAS,EACT,UAAU,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,MAAM,EACN,YAAY,GACb,MAAM,gBAAgB,CAAC;AAGxB,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM;IACN,aAAa;IACb,WAAW;IACX,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;CAClB,CAAC;AAEX,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,MAAc,EAAY,EAAE;IACxD,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACnC,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,UAAU,KAAK,oBAAoB,KAAK,QAAQ,KAAK,eAAe,CAAC,CAAC;AACjG,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,MAAc,OAAO,CAAC,GAAG,EACzB,IAAgC,EAAE;IAElC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,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AAC,sBAAsB,CAAC;YACzC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;gBAChB,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;YACnF,OAAO,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;QACD;YACE,IAAI,YAAY,CAAC,IAAI,CAAC;gBAAE,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,sBAAsB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClG,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one shape every model call has. A prompt is a string or a list of parts; a reply is text,
|
|
3
|
+
* tokens, USD and why it stopped. `ask` parses the reply to a zod shape. raven's and falcon's
|
|
4
|
+
* `Model` (`id` plus `ask(prompt, shape)`) are met by structure: a `Model` from here is one.
|
|
5
|
+
*/
|
|
6
|
+
import type { ZodType } from "zod";
|
|
7
|
+
/** What a part holds: bytes (base64 or raw) or a URL the vendor fetches itself. */
|
|
8
|
+
export type Source = Uint8Array | string | URL;
|
|
9
|
+
/** A stretch of a video, in seconds from its start; `fps` samples frames (Gemini's default is 1). */
|
|
10
|
+
export interface Clip {
|
|
11
|
+
startS: number;
|
|
12
|
+
endS: number;
|
|
13
|
+
fps?: number;
|
|
14
|
+
}
|
|
15
|
+
export type Part = {
|
|
16
|
+
type: "text";
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "image";
|
|
20
|
+
data: Source;
|
|
21
|
+
mediaType: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "video";
|
|
24
|
+
data: Source;
|
|
25
|
+
mediaType: string;
|
|
26
|
+
clip?: Clip;
|
|
27
|
+
} | {
|
|
28
|
+
type: "audio";
|
|
29
|
+
data: Source;
|
|
30
|
+
mediaType: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "pdf";
|
|
33
|
+
data: Source;
|
|
34
|
+
};
|
|
35
|
+
export type PartKind = Part["type"];
|
|
36
|
+
/** How hard a model thinks. Anthropic and Gemini read it; others ignore it. */
|
|
37
|
+
export type Effort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
38
|
+
export interface Request {
|
|
39
|
+
prompt: string | readonly Part[];
|
|
40
|
+
/** The standing instructions. On Anthropic it carries a cache breakpoint. */
|
|
41
|
+
system?: string;
|
|
42
|
+
/** A ceiling against a runaway answer, never the length: the prompt says how long. */
|
|
43
|
+
maxTokens?: number;
|
|
44
|
+
effort?: Effort;
|
|
45
|
+
/** How finely images and video are sampled. Gemini reads it (low is a quarter of the tokens); others ignore it. */
|
|
46
|
+
resolution?: "low" | "medium" | "high";
|
|
47
|
+
/** What the call is for (`triage`, `drafts`). No vendor sees it; meters group by it. */
|
|
48
|
+
purpose?: string;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
export interface Usage {
|
|
52
|
+
/** Every input token, cache reads and writes included. */
|
|
53
|
+
input?: number;
|
|
54
|
+
output?: number;
|
|
55
|
+
/** Of `input`: read from the vendor's prompt cache. */
|
|
56
|
+
cacheRead?: number;
|
|
57
|
+
/** Of `input`: written to the cache (5 minutes unless `cacheWrite1h` says). */
|
|
58
|
+
cacheWrite?: number;
|
|
59
|
+
/** Of `cacheWrite`: the share that lives 1 hour. */
|
|
60
|
+
cacheWrite1h?: number;
|
|
61
|
+
/** What the call cost. 0 on a free key; absent only when the model has no price. */
|
|
62
|
+
usd?: number;
|
|
63
|
+
/** The call ran on a free tier: `usd` is 0 and `listUsd` is what it would cost. */
|
|
64
|
+
free?: boolean;
|
|
65
|
+
listUsd?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface Reply {
|
|
68
|
+
text: string;
|
|
69
|
+
usage: Usage;
|
|
70
|
+
/** The model that answered, as the vendor names it. */
|
|
71
|
+
model: string;
|
|
72
|
+
/** The vendor's own stop reason (`end_turn`, `max_tokens`, `STOP`, `length`). */
|
|
73
|
+
stop: string | undefined;
|
|
74
|
+
/** Wall-clock milliseconds for the round trip. */
|
|
75
|
+
ms: number;
|
|
76
|
+
/** The vendor's response metadata, kept for the caller to store. */
|
|
77
|
+
raw: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
/** A parsed answer and what it cost. */
|
|
80
|
+
export interface Answer<T> {
|
|
81
|
+
value: T;
|
|
82
|
+
usage?: Usage;
|
|
83
|
+
}
|
|
84
|
+
export interface AskOptions extends Omit<Request, "prompt"> {
|
|
85
|
+
/** More calls after an answer that does not parse, each told why. Default 1. */
|
|
86
|
+
repairs?: number;
|
|
87
|
+
}
|
|
88
|
+
export interface Model {
|
|
89
|
+
/** The model id, as spends and records name it (`claude-haiku-5-5`, `groq:openai/gpt-oss-120b`). */
|
|
90
|
+
readonly id: string;
|
|
91
|
+
/** The vendor alone (`anthropic`, `groq`), for per-vendor sums. */
|
|
92
|
+
readonly provider: string;
|
|
93
|
+
/** The part kinds it takes. A part outside this set throws `Unsupported`, never dropped. */
|
|
94
|
+
readonly takes: ReadonlySet<PartKind>;
|
|
95
|
+
complete(request: Request | string): Promise<Reply>;
|
|
96
|
+
ask<T>(prompt: string | readonly Part[], shape: ZodType<T>, o?: AskOptions): Promise<Answer<T>>;
|
|
97
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrenautomation/models",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "One door to every model: a Model takes text, image, video, audio and PDF parts, answers with text, tokens and USD, and parses an answer to a zod shape. Adapters for Anthropic, Gemini, Cohere, any OpenAI-compatible server and a shell command (claude -p); ears for speech to text; one price table; one key ring.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/wrenautomation/engine.git",
|
|
8
|
+
"directory": "packages/models"
|
|
9
|
+
},
|
|
10
|
+
"license": "PolyForm-Shield-1.0.0",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"!dist/**/*.test.*",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE.md"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./prices": {
|
|
27
|
+
"types": "./dist/prices.d.ts",
|
|
28
|
+
"import": "./dist/prices.js"
|
|
29
|
+
},
|
|
30
|
+
"./hear": {
|
|
31
|
+
"types": "./dist/hear.d.ts",
|
|
32
|
+
"import": "./dist/hear.js"
|
|
33
|
+
},
|
|
34
|
+
"./command": {
|
|
35
|
+
"types": "./dist/command.d.ts",
|
|
36
|
+
"import": "./dist/command.js"
|
|
37
|
+
},
|
|
38
|
+
"./spec": {
|
|
39
|
+
"types": "./dist/spec.d.ts",
|
|
40
|
+
"import": "./dist/spec.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=24"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@ai-sdk/anthropic": "4.0.90",
|
|
48
|
+
"@ai-sdk/cohere": "4.0.71",
|
|
49
|
+
"@ai-sdk/google": "4.0.107",
|
|
50
|
+
"@ai-sdk/openai-compatible": "3.0.80",
|
|
51
|
+
"ai": "7.0.155",
|
|
52
|
+
"zod": "4.6.5"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"build": "rm -rf dist && tsc"
|
|
57
|
+
}
|
|
6
58
|
}
|