@procedures/llm 0.0.0-stage → 0.2.3

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/anthropic.d.ts +102 -0
  5. package/dist/anthropic.d.ts.map +1 -0
  6. package/dist/anthropic.js +195 -0
  7. package/dist/anthropic.js.map +1 -0
  8. package/dist/errors.d.ts +34 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +20 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +9 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/module.d.ts +48 -0
  17. package/dist/module.d.ts.map +1 -0
  18. package/dist/module.js +145 -0
  19. package/dist/module.js.map +1 -0
  20. package/dist/procedures/llm/complete.d.ts +13 -0
  21. package/dist/procedures/llm/complete.d.ts.map +1 -0
  22. package/dist/procedures/llm/complete.js +23 -0
  23. package/dist/procedures/llm/complete.js.map +1 -0
  24. package/dist/procedures/llm/index.d.ts +3 -0
  25. package/dist/procedures/llm/index.d.ts.map +1 -0
  26. package/dist/procedures/llm/index.js +3 -0
  27. package/dist/procedures/llm/index.js.map +1 -0
  28. package/dist/procedures/llm/structured.d.ts +16 -0
  29. package/dist/procedures/llm/structured.d.ts.map +1 -0
  30. package/dist/procedures/llm/structured.js +75 -0
  31. package/dist/procedures/llm/structured.js.map +1 -0
  32. package/dist/register.d.ts +6 -0
  33. package/dist/register.d.ts.map +1 -0
  34. package/dist/register.js +8 -0
  35. package/dist/register.js.map +1 -0
  36. package/dist/request.d.ts +10 -0
  37. package/dist/request.d.ts.map +1 -0
  38. package/dist/request.js +26 -0
  39. package/dist/request.js.map +1 -0
  40. package/dist/schema.d.ts +31 -0
  41. package/dist/schema.d.ts.map +1 -0
  42. package/dist/schema.js +86 -0
  43. package/dist/schema.js.map +1 -0
  44. package/dist/types.d.ts +76 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/types.js +8 -0
  47. package/dist/types.js.map +1 -0
  48. package/package.json +77 -3
  49. package/src/anthropic.ts +255 -0
  50. package/src/errors.ts +38 -0
  51. package/src/index.ts +20 -0
  52. package/src/module.ts +186 -0
  53. package/src/procedures/llm/complete.ts +26 -0
  54. package/src/procedures/llm/index.ts +2 -0
  55. package/src/procedures/llm/structured.ts +79 -0
  56. package/src/register.ts +10 -0
  57. package/src/request.ts +25 -0
  58. package/src/schema.ts +85 -0
  59. package/src/types.ts +90 -0
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The Anthropic Messages API over `fetch` (roadmap R46).
3
+ *
4
+ * The procedures send each request with the `fetch` of the module settings, not through
5
+ * `http.request`: the API key goes in a header, and the input of a nested call is visible to the
6
+ * interceptors and to the traces of the host. The key comes from an environment variable that the
7
+ * module names. An input cannot give a key.
8
+ *
9
+ * A call stops at the earliest of its time limit, the deadline of its capability and the abort of
10
+ * the caller. A stop is an `InvocationError` with the code `TIMEOUT` or `ABORTED`.
11
+ */
12
+ import { type ProcedureContext, type ProcedurePath } from "@procedures/client";
13
+ import type { LlmEffort, LlmUsage } from "./types.js";
14
+ /** The variables that the module reads: a name and a value, or undefined for a variable that is not set. */
15
+ export type EnvSource = Readonly<Record<string, string | undefined>>;
16
+ /** The `fetch` that the procedures use. A test gives a fake one. */
17
+ export type FetchFunction = (url: string, init: RequestInit) => Promise<Response>;
18
+ /** The default model of the module. */
19
+ export declare const DEFAULT_MODEL = "claude-sonnet-5-5";
20
+ /** The default environment variable of the API key. */
21
+ export declare const DEFAULT_API_KEY_ENV = "ANTHROPIC_API_KEY";
22
+ /** The default base URL of the API. */
23
+ export declare const DEFAULT_BASE_URL = "https://api.anthropic.com";
24
+ /** The default of `maxTokens`. */
25
+ export declare const DEFAULT_MAX_TOKENS = 16000;
26
+ /** The default time limit of a call: 10 minutes. */
27
+ export declare const DEFAULT_TIMEOUT_MS = 600000;
28
+ /** The version header of the Messages API. */
29
+ export declare const ANTHROPIC_VERSION = "2023-06-01";
30
+ /** The beta header of the server-side fallback with `fallbacks: "default"`. */
31
+ export declare const FALLBACK_BETA = "server-side-fallback-2026-07-01";
32
+ /** What the procedures of a module use. */
33
+ export interface LlmSettings {
34
+ readonly apiKeyEnv: string;
35
+ /** This function gives the variables at the time of a call. */
36
+ readonly env: () => EnvSource;
37
+ readonly fetch: FetchFunction;
38
+ readonly baseUrl: string;
39
+ readonly defaultModel: string;
40
+ /** The default of the `fallback` input. */
41
+ readonly fallback: boolean;
42
+ }
43
+ /** The settings of the default module. */
44
+ export declare const DEFAULT_LLM_SETTINGS: LlmSettings;
45
+ /** One content block of a message. The procedures read only the text blocks. */
46
+ export interface ContentBlock {
47
+ readonly type: string;
48
+ readonly text?: string;
49
+ readonly [key: string]: unknown;
50
+ }
51
+ /** One message of a request. The content of an assistant turn is the content of the answer, unchanged. */
52
+ export interface MessageParam {
53
+ readonly role: "user" | "assistant";
54
+ readonly content: string | readonly ContentBlock[];
55
+ }
56
+ /** The request body of the Messages API, as the procedures send it. */
57
+ export interface MessagesRequest {
58
+ model: string;
59
+ max_tokens: number;
60
+ messages: MessageParam[];
61
+ system?: string;
62
+ temperature?: number;
63
+ output_config?: {
64
+ effort?: LlmEffort;
65
+ format?: {
66
+ type: "json_schema";
67
+ schema: unknown;
68
+ };
69
+ };
70
+ fallbacks?: "default";
71
+ }
72
+ /** The parts of an answer that the procedures use. */
73
+ export interface MessagesResponse {
74
+ readonly model: string;
75
+ readonly content: readonly ContentBlock[];
76
+ readonly stopReason: string;
77
+ readonly stopDetails: {
78
+ readonly category?: string | null;
79
+ readonly explanation?: string | null;
80
+ } | undefined;
81
+ readonly usage: LlmUsage;
82
+ }
83
+ /** The time limit and the stop of one procedure call. */
84
+ export interface CallLimits {
85
+ readonly path: ProcedurePath;
86
+ readonly ctx: Pick<ProcedureContext, "signal" | "capability"> | undefined;
87
+ readonly timeoutMs: number;
88
+ }
89
+ /** The API key, or a `NO_API_KEY` error that names the variable. */
90
+ export declare function apiKey(settings: LlmSettings): string;
91
+ /** The text blocks of an answer, joined. */
92
+ export declare function textOf(content: readonly ContentBlock[]): string;
93
+ /** The sum of two usages. */
94
+ export declare function addUsage(a: LlmUsage, b: LlmUsage): LlmUsage;
95
+ /** A usage of zero tokens. */
96
+ export declare const NO_USAGE: LlmUsage;
97
+ /**
98
+ * This function sends one request to the Messages API and gives the checked answer. It throws a
99
+ * `REFUSAL` error when a safety classifier declined the request.
100
+ */
101
+ export declare function sendMessages(request: MessagesRequest, settings: LlmSettings, limits: CallLimits): Promise<MessagesResponse>;
102
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../src/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAmB,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEhG,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtD,4GAA4G;AAC5G,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAErE,oEAAoE;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAElF,uCAAuC;AACvC,eAAO,MAAM,aAAa,sBAAsB,CAAC;AACjD,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,uCAAuC;AACvC,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAC5D,kCAAkC;AAClC,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,S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+1,195 @@
1
+ /**
2
+ * The Anthropic Messages API over `fetch` (roadmap R46).
3
+ *
4
+ * The procedures send each request with the `fetch` of the module settings, not through
5
+ * `http.request`: the API key goes in a header, and the input of a nested call is visible to the
6
+ * interceptors and to the traces of the host. The key comes from an environment variable that the
7
+ * module names. An input cannot give a key.
8
+ *
9
+ * A call stops at the earliest of its time limit, the deadline of its capability and the abort of
10
+ * the caller. A stop is an `InvocationError` with the code `TIMEOUT` or `ABORTED`.
11
+ */
12
+ import { InvocationError } from "@procedures/client";
13
+ import { LlmError } from "./errors.js";
14
+ /** The default model of the module. */
15
+ export const DEFAULT_MODEL = "claude-sonnet-5-5";
16
+ /** The default environment variable of the API key. */
17
+ export const DEFAULT_API_KEY_ENV = "ANTHROPIC_API_KEY";
18
+ /** The default base URL of the API. */
19
+ export const DEFAULT_BASE_URL = "https://api.anthropic.com";
20
+ /** The default of `maxTokens`. */
21
+ export const DEFAULT_MAX_TOKENS = 16_000;
22
+ /** The default time limit of a call: 10 minutes. */
23
+ export const DEFAULT_TIMEOUT_MS = 600_000;
24
+ /** The version header of the Messages API. */
25
+ export const ANTHROPIC_VERSION = "2023-06-01";
26
+ /** The beta header of the server-side fallback with `fallbacks: "default"`. */
27
+ export const FALLBACK_BETA = "server-side-fallback-2026-07-01";
28
+ /** The largest answer that the procedures read, in bytes. */
29
+ const MAX_RESPONSE_BYTES = 32 * 1024 * 1024;
30
+ /** The settings of the default module. */
31
+ export const DEFAULT_LLM_SETTINGS = Object.freeze({
32
+ apiKeyEnv: DEFAULT_API_KEY_ENV,
33
+ env: () => process.env,
34
+ fetch: (url, init) => globalThis.fetch(url, init),
35
+ baseUrl: DEFAULT_BASE_URL,
36
+ defaultModel: DEFAULT_MODEL,
37
+ fallback: true,
38
+ });
39
+ /** The API key, or a `NO_API_KEY` error that names the variable. */
40
+ export function apiKey(settings) {
41
+ const value = settings.env()[settings.apiKeyEnv];
42
+ if (typeof value !== "string" || value.trim() === "") {
43
+ throw new LlmError("NO_API_KEY", `llm: the environment variable ${settings.apiKeyEnv} has no API key`);
44
+ }
45
+ return value.trim();
46
+ }
47
+ /** The text blocks of an answer, joined. */
48
+ export function textOf(content) {
49
+ return content
50
+ .filter((block) => block.type === "text" && typeof block.text === "string")
51
+ .map((block) => block.text)
52
+ .join("");
53
+ }
54
+ /** The sum of two usages. */
55
+ export function addUsage(a, b) {
56
+ return {
57
+ inputTokens: a.inputTokens + b.inputTokens,
58
+ outputTokens: a.outputTokens + b.outputTokens,
59
+ cacheReadInputTokens: a.cacheReadInputTokens + b.cacheReadInputTokens,
60
+ cacheCreationInputTokens: a.cacheCreationInputTokens + b.cacheCreationInputTokens,
61
+ };
62
+ }
63
+ /** A usage of zero tokens. */
64
+ export const NO_USAGE = Object.freeze({ inputTokens: 0, outputTokens: 0, cacheReadInputTokens: 0, cacheCreationInputTokens: 0 });
65
+ const count = (value) => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0);
66
+ /** The answer of the API, checked: an answer of another form is a `BAD_RESPONSE`. */
67
+ function parseResponse(text) {
68
+ let body;
69
+ try {
70
+ body = JSON.parse(text);
71
+ }
72
+ catch {
73
+ throw new LlmError("BAD_RESPONSE", `llm: the answer of the API is not JSON: ${text.slice(0, 200)}`);
74
+ }
75
+ const record = body;
76
+ if (record === null || typeof record !== "object" || !Array.isArray(record["content"]) || typeof record["stop_reason"] !== "string") {
77
+ throw new LlmError("BAD_RESPONSE", "llm: the answer of the API is not a message with content and stop_reason");
78
+ }
79
+ const usage = (record["usage"] ?? {});
80
+ const details = record["stop_details"];
81
+ return {
82
+ model: typeof record["model"] === "string" ? record["model"] : "",
83
+ content: record["content"].filter((block) => block !== null && typeof block === "object" && typeof block.type === "string"),
84
+ stopReason: record["stop_reason"],
85
+ stopDetails: details !== null && typeof details === "object" ? details : undefined,
86
+ usage: {
87
+ inputTokens: count(usage["input_tokens"]),
88
+ outputTokens: count(usage["output_tokens"]),
89
+ cacheReadInputTokens: count(usage["cache_read_input_tokens"]),
90
+ cacheCreationInputTokens: count(usage["cache_creation_input_tokens"]),
91
+ },
92
+ };
93
+ }
94
+ /** The error of an answer with an error status. The message has the type and the message of the API. */
95
+ function apiError(status, text, key) {
96
+ let detail = text.slice(0, 500);
97
+ try {
98
+ const error = JSON.parse(text).error;
99
+ if (error && typeof error.message === "string")
100
+ detail = `${typeof error.type === "string" ? `${error.type}: ` : ""}${error.message}`;
101
+ }
102
+ catch {
103
+ // The text of the answer stays the detail
104
+ }
105
+ // The API does not repeat the key, but the message must not carry it in any case
106
+ const safe = detail.split(key).join("[key]");
107
+ const retryable = status === 408 || status === 409 || status === 429 || status >= 500;
108
+ return new LlmError("API_ERROR", `llm: the API answered ${status}: ${safe}`, { status, retryable });
109
+ }
110
+ /** The time that is left before the deadline of the capability, or undefined. */
111
+ function deadlineLeft(ctx) {
112
+ const deadline = ctx?.capability?.deadline;
113
+ return typeof deadline === "number" ? deadline - Date.now() : undefined;
114
+ }
115
+ /** The body of an answer as text, with a size limit. */
116
+ async function readText(response) {
117
+ const declared = Number(response.headers.get("content-length") ?? "0");
118
+ if (declared > MAX_RESPONSE_BYTES)
119
+ throw new LlmError("BAD_RESPONSE", `llm: the answer of the API is larger than ${MAX_RESPONSE_BYTES} bytes`);
120
+ const text = await response.text();
121
+ if (text.length > MAX_RESPONSE_BYTES)
122
+ throw new LlmError("BAD_RESPONSE", `llm: the answer of the API is larger than ${MAX_RESPONSE_BYTES} bytes`);
123
+ return text;
124
+ }
125
+ /**
126
+ * This function sends one request to the Messages API and gives the checked answer. It throws a
127
+ * `REFUSAL` error when a safety classifier declined the request.
128
+ */
129
+ export async function sendMessages(request, settings, limits) {
130
+ const key = apiKey(settings);
131
+ const { path, ctx } = limits;
132
+ const left = deadlineLeft(ctx);
133
+ if (left !== undefined && left <= 0)
134
+ throw new InvocationError("TIMEOUT", `The deadline of ${path.join(".")} passed before the call`, path);
135
+ const timeoutMs = left === undefined ? limits.timeoutMs : Math.min(limits.timeoutMs, left);
136
+ if (ctx?.signal?.aborted)
137
+ throw new InvocationError("ABORTED", `Procedure was aborted: ${path.join(".")}`, path);
138
+ const controller = new AbortController();
139
+ let stop;
140
+ const timer = setTimeout(() => {
141
+ stop ??= "timeout";
142
+ controller.abort();
143
+ }, timeoutMs);
144
+ const onAbort = () => {
145
+ stop ??= "caller";
146
+ controller.abort();
147
+ };
148
+ ctx?.signal?.addEventListener("abort", onAbort, { once: true });
149
+ const headers = {
150
+ "content-type": "application/json",
151
+ "x-api-key": key,
152
+ "anthropic-version": ANTHROPIC_VERSION,
153
+ };
154
+ if (request.fallbacks !== undefined)
155
+ headers["anthropic-beta"] = FALLBACK_BETA;
156
+ try {
157
+ let response;
158
+ try {
159
+ response = await settings.fetch(`${settings.baseUrl.replace(/\/+$/, "")}/v1/messages`, {
160
+ method: "POST",
161
+ headers,
162
+ body: JSON.stringify(request),
163
+ signal: controller.signal,
164
+ });
165
+ }
166
+ catch (error) {
167
+ if (stop === undefined) {
168
+ const message = error instanceof Error ? error.message : String(error);
169
+ throw new LlmError("CONNECTION", `llm: the connection to the API failed: ${message.split(key).join("[key]")}`, { retryable: true });
170
+ }
171
+ throw error;
172
+ }
173
+ const text = await readText(response);
174
+ if (!response.ok)
175
+ throw apiError(response.status, text, key);
176
+ const answer = parseResponse(text);
177
+ if (answer.stopReason === "refusal") {
178
+ const category = answer.stopDetails?.category ?? "not given";
179
+ throw new LlmError("REFUSAL", `llm: a safety classifier declined the request (category: ${category})`);
180
+ }
181
+ return answer;
182
+ }
183
+ catch (error) {
184
+ if (stop === "timeout")
185
+ throw new InvocationError("TIMEOUT", `${path.join(".")} passed its time limit of ${timeoutMs} ms`, path);
186
+ if (stop === "caller")
187
+ throw new InvocationError("ABORTED", `Procedure was aborted: ${path.join(".")}`, path);
188
+ throw error;
189
+ }
190
+ finally {
191
+ clearTimeout(timer);
192
+ ctx?.signal?.removeEventListener("abort", onAbort);
193
+ }
194
+ }
195
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1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IAAI,IAAI,KAAK,QAAQ;YAAE,MAAM,IAAI,eAAe,CAAC,SAAS,EAAE,0BAA0B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9G,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,GAAG,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The errors of the llm procedures. A stop of the call (its time limit, its deadline, the abort of
3
+ * the caller) is an `InvocationError` with the code `TIMEOUT` or `ABORTED`.
4
+ */
5
+ /** The reason of an `LlmError`. */
6
+ export type LlmErrorCode =
7
+ /** The environment variable of the API key has no value. */
8
+ "NO_API_KEY"
9
+ /** The API answered with an error status. `status` has it. */
10
+ | "API_ERROR"
11
+ /** The connection to the API failed. */
12
+ | "CONNECTION"
13
+ /** The answer of the API does not have the form of a message. */
14
+ | "BAD_RESPONSE"
15
+ /** A safety classifier declined the request (`stop_reason: "refusal"`). */
16
+ | "REFUSAL"
17
+ /** `llm.structured`: the output stopped at `maxTokens`, so the JSON is not complete. */
18
+ | "MAX_TOKENS"
19
+ /** `llm.structured`: no answer gave a value that the schema accepts. */
20
+ | "INVALID_OUTPUT";
21
+ /** An error of a call to the model. */
22
+ export declare class LlmError extends Error {
23
+ readonly name = "LlmError";
24
+ readonly code: LlmErrorCode;
25
+ /** The HTTP status of an `API_ERROR`. */
26
+ readonly status: number | undefined;
27
+ /** True when the same call can succeed later: a rate limit, an overload, a server error or a connection error. */
28
+ readonly retryable: boolean;
29
+ constructor(code: LlmErrorCode, message: string, options?: {
30
+ status?: number | undefined;
31
+ retryable?: boolean | undefined;
32
+ });
33
+ }
34
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mCAAmC;AACnC,MAAM,MAAM,YAAY;AACtB,4DAA4D;AAC1D,YAAY;AACd,8DAA8D;GAC5D,WAAW;AACb,wCAAwC;GACtC,YAAY;AACd,iEAAiE;GAC/D,cAAc;AAChB,2EAA2E;GACzE,SAAS;AACX,wFAAwF;GACtF,YAAY;AACd,wEAAwE;GACtE,gBAAgB,CAAC;AAErB,uCAAuC;AACvC,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAkB,IAAI,cAAc;IACpC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,kHAAkH;IAClH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,YAAY,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAO,EAK9H;CACF"}
package/dist/errors.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The errors of the llm procedures. A stop of the call (its time limit, its deadline, the abort of
3
+ * the caller) is an `InvocationError` with the code `TIMEOUT` or `ABORTED`.
4
+ */
5
+ /** An error of a call to the model. */
6
+ export class LlmError extends Error {
7
+ name = "LlmError";
8
+ code;
9
+ /** The HTTP status of an `API_ERROR`. */
10
+ status;
11
+ /** True when the same call can succeed later: a rate limit, an overload, a server error or a connection error. */
12
+ retryable;
13
+ constructor(code, message, options = {}) {
14
+ super(message);
15
+ this.code = code;
16
+ this.status = options.status;
17
+ this.retryable = options.retryable ?? false;
18
+ }
19
+ }
20
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH,uCAAuC;AACvC,MAAM,OAAO,QAAS,SAAQ,KAAK;IACf,IAAI,GAAG,UAAU,CAAC;IAC3B,IAAI,CAAe;IAC5B,yCAAyC;IAChC,MAAM,CAAqB;IACpC,kHAAkH;IACzG,SAAS,CAAU;IAE5B,YAAY,IAAkB,EAAE,OAAe,EAAE,OAAO,GAAqE,EAAE;QAC7H,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export * from "./module.js";
2
+ export * from "./types.js";
3
+ export { llmComplete, llmStructured, MAX_RETRIES } from "./procedures/llm/index.js";
4
+ export { ANTHROPIC_VERSION, DEFAULT_API_KEY_ENV, DEFAULT_BASE_URL, DEFAULT_LLM_SETTINGS, DEFAULT_MAX_TOKENS, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, FALLBACK_BETA, type EnvSource, type FetchFunction, type LlmSettings, } from "./anthropic.js";
5
+ export { LlmError, type LlmErrorCode } from "./errors.js";
6
+ export { constrainedSchema, parseAnswer, UNSUPPORTED_KEYWORDS } from "./schema.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAEpF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // The root registers nothing: import "<package>/register", or give the module to createRegistry()
2
+ export * from "./module.js";
3
+ export * from "./types.js";
4
+ export { llmComplete, llmStructured, MAX_RETRIES } from "./procedures/llm/index.js";
5
+ // The provider (roadmap R46)
6
+ export { ANTHROPIC_VERSION, DEFAULT_API_KEY_ENV, DEFAULT_BASE_URL, DEFAULT_LLM_SETTINGS, DEFAULT_MAX_TOKENS, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, FALLBACK_BETA, } from "./anthropic.js";
7
+ export { LlmError } from "./errors.js";
8
+ export { constrainedSchema, parseAnswer, UNSUPPORTED_KEYWORDS } from "./schema.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpF,6BAA6B;AAC7B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,aAAa,GAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The procedures of @procedures/llm as data. Importing this file registers nothing.
3
+ *
4
+ * Scaffold a procedure with: mark procedure new <name> --path packages/llm
5
+ *
6
+ * `llmModule` sends each request to the Anthropic Messages API with the key of the environment
7
+ * variable `ANTHROPIC_API_KEY`. `createLlmModule()` gives the same procedures with another
8
+ * variable, another default model, another base URL or another `fetch` (roadmap R46).
9
+ */
10
+ import { type ProcedureModule, type ProcedureRegistry } from "@procedures/client";
11
+ import { type EnvSource, type FetchFunction } from "./anthropic.js";
12
+ /**
13
+ * The module of this package, for `createRegistry()`: its procedures as data. Each call reads the
14
+ * key from `ANTHROPIC_API_KEY`. Importing this file registers nothing.
15
+ */
16
+ export declare const llmModule: ProcedureModule;
17
+ export default llmModule;
18
+ /** The options of `createLlmModule()`. */
19
+ export interface LlmModuleOptions {
20
+ /** The environment variable of the API key. The default is `ANTHROPIC_API_KEY`. */
21
+ readonly apiKeyEnv?: string | undefined;
22
+ /** The model of an input without `model`. The default is `claude-sonnet-5-5`. */
23
+ readonly defaultModel?: string | undefined;
24
+ /** The base URL of the API. The default is `https://api.anthropic.com`. */
25
+ readonly baseUrl?: string | undefined;
26
+ /** The default of the `fallback` input. The default is true. */
27
+ readonly fallback?: boolean | undefined;
28
+ /** The `fetch` of the requests. The default is the global `fetch`. A test gives a fake one. */
29
+ readonly fetch?: FetchFunction | undefined;
30
+ /** The variables: a record, or a function that gives them at each call. The default is `process.env`. */
31
+ readonly env?: EnvSource | (() => EnvSource) | undefined;
32
+ }
33
+ /**
34
+ * This function gives the module of this package with other settings. Without options, it gives
35
+ * `llmModule`. A host gives it to `createRegistry()` before its bundles, so it replaces the
36
+ * `llmModule` that a bundle requires (the first module of a name counts). A bad option throws here.
37
+ *
38
+ * ```ts
39
+ * createRegistry(createLlmModule({ apiKeyEnv: "WORK_ANTHROPIC_KEY", defaultModel: "claude-haiku-5-5" }));
40
+ * ```
41
+ */
42
+ export declare function createLlmModule(options?: LlmModuleOptions): ProcedureModule;
43
+ /**
44
+ * This function registers the procedures of @procedures/llm in a registry. The default is the
45
+ * global registry. The options are the options of `createLlmModule()`.
46
+ */
47
+ export declare function registerLlmProcedures(registry?: ProcedureRegistry, options?: LlmModuleOptions): void;
48
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EASL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAwB,KAAK,SAAS,EAAE,KAAK,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AAuG5G;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,eAAsF,CAAC;eAEhG,SAAS;AAExB,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,iFAAiF;IACjF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,+FAA+F;IAC/F,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAC3C,yGAAyG;IACzG,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,GAAG,SAAS,CAAC;CAC1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAgB/E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,GAAE,iBAAsC,EAAE,OAAO,GAAE,gBAAqB,GAAG,IAAI,CAE5H"}
package/dist/module.js ADDED
@@ -0,0 +1,145 @@
1
+ /**
2
+ * The procedures of @procedures/llm as data. Importing this file registers nothing.
3
+ *
4
+ * Scaffold a procedure with: mark procedure new <name> --path packages/llm
5
+ *
6
+ * `llmModule` sends each request to the Anthropic Messages API with the key of the environment
7
+ * variable `ANTHROPIC_API_KEY`. `createLlmModule()` gives the same procedures with another
8
+ * variable, another default model, another base URL or another `fetch` (roadmap R46).
9
+ */
10
+ import { z } from "zod";
11
+ import { defineModule, registerModules, PROCEDURE_REGISTRY, createProcedure, zodAdapter, } from "@procedures/client";
12
+ import { llmComplete } from "./procedures/llm/complete.js";
13
+ import { llmStructured, MAX_RETRIES } from "./procedures/llm/structured.js";
14
+ import { DEFAULT_LLM_SETTINGS } from "./anthropic.js";
15
+ // =============================================================================
16
+ // Schemas
17
+ // =============================================================================
18
+ const requestFields = {
19
+ prompt: z.string().min(1).max(4_000_000).describe("The text of the user"),
20
+ system: z.string().max(4_000_000).optional().describe("The system text: the instructions to the model"),
21
+ model: z
22
+ .string()
23
+ .min(1)
24
+ .max(200)
25
+ .regex(/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/, "A model ID")
26
+ .optional()
27
+ .describe("The model (default: the model of the module, claude-sonnet-5-5)"),
28
+ maxTokens: z.number().int().min(1).max(64_000).optional().describe("The most tokens of the output, with the thinking (default 16000)"),
29
+ temperature: z.number().min(0).max(1).optional().describe("The temperature, 0 to 1. Some models accept only the default"),
30
+ effort: z.enum(["low", "medium", "high", "xhigh", "max"]).optional().describe("The effort of the model (default: the default of the model)"),
31
+ timeoutMs: z.number().int().positive().max(3_600_000).optional().describe("The time limit of the call, in milliseconds (default 600000)"),
32
+ fallback: z.boolean().optional().describe("True: the API runs a declined request again on its fallback model (default: the option of the module, true)"),
33
+ };
34
+ const usage = z
35
+ .object({
36
+ inputTokens: z.number().int().describe("The tokens of the input that the cache did not have"),
37
+ outputTokens: z.number().int().describe("The tokens of the output, with the thinking"),
38
+ cacheReadInputTokens: z.number().int().describe("The tokens of the input from the cache"),
39
+ cacheCreationInputTokens: z.number().int().describe("The tokens of the input that went into the cache"),
40
+ })
41
+ .describe("The tokens of the call");
42
+ const LlmCompleteInputSchema = z.object(requestFields);
43
+ const LlmCompleteOutputSchema = z.object({
44
+ text: z.string().describe("The text of the answer"),
45
+ model: z.string().describe("The model that answered"),
46
+ stopReason: z.string().describe("Why the model stopped: end_turn, max_tokens, stop_sequence or another reason"),
47
+ usage,
48
+ });
49
+ const LlmStructuredInputSchema = z.object({
50
+ ...requestFields,
51
+ schema: z.record(z.string(), z.unknown()).describe("The JSON Schema of the value"),
52
+ constrained: z.boolean().optional().describe("True (default): the API constrains the output to the schema. False: the system text gives the schema"),
53
+ retries: z.number().int().min(0).max(MAX_RETRIES).optional().describe("The new tries after an answer that is not valid, 0 to 2 (default 2)"),
54
+ });
55
+ const LlmStructuredOutputSchema = z.object({
56
+ value: z.unknown().describe("The value: the schema accepts it"),
57
+ model: z.string().describe("The model that gave the value"),
58
+ attempts: z.number().int().describe("The number of calls to the model"),
59
+ usage,
60
+ unchecked: z.array(z.string()).describe("The keywords of the schema that the check does not examine fully"),
61
+ });
62
+ // =============================================================================
63
+ // Procedures
64
+ // =============================================================================
65
+ /**
66
+ * The effects of each procedure: it sends data to a system outside the host and gets an answer.
67
+ * A call costs money and can change the state of an account, so it declares a write. It deletes
68
+ * nothing and a second call is a new call.
69
+ */
70
+ const SENDS_TO_MODEL = Object.freeze({ reads: Object.freeze(["network"]), writes: Object.freeze(["network"]), destructive: false, idempotent: false });
71
+ /** The two procedures, with handlers that use the settings. */
72
+ function llmProcedures(settings) {
73
+ const llmCompleteProcedure = createProcedure()
74
+ .path(["llm", "complete"])
75
+ .input(zodAdapter(LlmCompleteInputSchema))
76
+ .output(zodAdapter(LlmCompleteOutputSchema))
77
+ .meta({
78
+ description: "Send a prompt to a language model and give the text and the usage",
79
+ tags: ["llm", "anthropic"],
80
+ args: ["prompt"],
81
+ shorts: { model: "m", system: "s" },
82
+ output: "json",
83
+ effects: SENDS_TO_MODEL,
84
+ })
85
+ .handler(async (input, ctx) => llmComplete(input, ctx, settings))
86
+ .build();
87
+ const llmStructuredProcedure = createProcedure()
88
+ .path(["llm", "structured"])
89
+ .input(zodAdapter(LlmStructuredInputSchema))
90
+ .output(zodAdapter(LlmStructuredOutputSchema))
91
+ .meta({
92
+ description: "Send a prompt and a JSON Schema to a language model and give a value that the schema accepts",
93
+ tags: ["llm", "anthropic", "json-schema"],
94
+ args: ["prompt"],
95
+ shorts: { model: "m", system: "s" },
96
+ output: "json",
97
+ effects: SENDS_TO_MODEL,
98
+ })
99
+ .handler(async (input, ctx) => llmStructured(input, ctx, settings))
100
+ .build();
101
+ return [llmCompleteProcedure, llmStructuredProcedure];
102
+ }
103
+ /**
104
+ * The module of this package, for `createRegistry()`: its procedures as data. Each call reads the
105
+ * key from `ANTHROPIC_API_KEY`. Importing this file registers nothing.
106
+ */
107
+ export const llmModule = defineModule("@procedures/llm", llmProcedures(DEFAULT_LLM_SETTINGS));
108
+ export default llmModule;
109
+ /**
110
+ * This function gives the module of this package with other settings. Without options, it gives
111
+ * `llmModule`. A host gives it to `createRegistry()` before its bundles, so it replaces the
112
+ * `llmModule` that a bundle requires (the first module of a name counts). A bad option throws here.
113
+ *
114
+ * ```ts
115
+ * createRegistry(createLlmModule({ apiKeyEnv: "WORK_ANTHROPIC_KEY", defaultModel: "claude-haiku-5-5" }));
116
+ * ```
117
+ */
118
+ export function createLlmModule(options = {}) {
119
+ if (Object.values(options).every((value) => value === undefined))
120
+ return llmModule;
121
+ const apiKeyEnv = options.apiKeyEnv ?? DEFAULT_LLM_SETTINGS.apiKeyEnv;
122
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(apiKeyEnv))
123
+ throw new TypeError(`createLlmModule: apiKeyEnv must be the name of a variable, not ${JSON.stringify(apiKeyEnv)}`);
124
+ const baseUrl = options.baseUrl ?? DEFAULT_LLM_SETTINGS.baseUrl;
125
+ if (!/^https?:\/\//.test(baseUrl))
126
+ throw new TypeError("createLlmModule: baseUrl must be an http or https URL");
127
+ const env = options.env;
128
+ const settings = {
129
+ apiKeyEnv,
130
+ env: env === undefined ? DEFAULT_LLM_SETTINGS.env : typeof env === "function" ? env : () => env,
131
+ fetch: options.fetch ?? DEFAULT_LLM_SETTINGS.fetch,
132
+ baseUrl,
133
+ defaultModel: options.defaultModel ?? DEFAULT_LLM_SETTINGS.defaultModel,
134
+ fallback: options.fallback ?? DEFAULT_LLM_SETTINGS.fallback,
135
+ };
136
+ return defineModule("@procedures/llm", llmProcedures(settings));
137
+ }
138
+ /**
139
+ * This function registers the procedures of @procedures/llm in a registry. The default is the
140
+ * global registry. The options are the options of `createLlmModule()`.
141
+ */
142
+ export function registerLlmProcedures(registry = PROCEDURE_REGISTRY, options = {}) {
143
+ registerModules(registry, [createLlmModule(options)]);
144
+ }
145
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,UAAU,GAMX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAwD,MAAM,gBAAgB,CAAC;AAG5G,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,MAAM,aAAa,GAAG;IACpB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IACzE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,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AC,kEAAkE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACpK,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,oBAAoB,CAAC,OAAO,CAAC;IAChE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAC;IAChH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,MAAM,QAAQ,GAAgB;QAC5B,SAAS;QACT,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG;QAC/F,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,oBAAoB,CAAC,KAAK;QAClD,OAAO;QACP,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,oBAAoB,CAAC,YAAY;QACvE,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,oBAAoB,CAAC,QAAQ;KAC5D,CAAC;IACF,OAAO,YAAY,CAAC,iBAAiB,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAQ,GAAsB,kBAAkB,EAAE,OAAO,GAAqB,EAAE;IACpH,eAAe,CAAC,QAAQ,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * llm.complete procedure
3
+ *
4
+ * Send a prompt to a language model and give the text and the usage. The text is the text
5
+ * blocks of the answer, joined: the thinking blocks are not in it.
6
+ */
7
+ import { type CallLimits, type LlmSettings } from "../../anthropic.js";
8
+ import type { LlmCompleteInput, LlmCompleteOutput } from "../../types.js";
9
+ /**
10
+ * Send a prompt to a language model and give the text and the usage
11
+ */
12
+ export declare function llmComplete(input: LlmCompleteInput, ctx?: CallLimits["ctx"], settings?: LlmSettings): Promise<LlmCompleteOutput>;
13
+ //# sourceMappingURL=complete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/procedures/llm/complete.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA8C,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEnH,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAI1E;;GAEG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAE,WAAkC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAS5J"}