@galdor/provider-anthropic 0.3.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/convert.d.ts +156 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +303 -0
- package/dist/convert.js.map +1 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/dist/stream.d.ts +36 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +212 -0
- package/dist/stream.js.map +1 -0
- package/package.json +36 -0
- package/src/anthropic.test.ts +194 -0
- package/src/convert.ts +376 -0
- package/src/errors.ts +121 -0
- package/src/index.ts +179 -0
- package/src/stream.ts +263 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@galdor/provider-anthropic` — Anthropic (Claude Messages API) adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements the galdor {@link Provider} interface over the `/v1/messages`
|
|
5
|
+
* endpoint, supporting tool use, vision input, extended thinking, prompt
|
|
6
|
+
* caching, and structured output (expressed as a forced single tool call). Both
|
|
7
|
+
* a buffered {@link AnthropicProvider.generate} and an incremental
|
|
8
|
+
* {@link AnthropicProvider.stream} path are provided; construct an instance with
|
|
9
|
+
* {@link newAnthropic}.
|
|
10
|
+
*/
|
|
11
|
+
import { type Capabilities, type Event, type Provider, type Request, type Response, type RunContext } from "@galdor/core/provider";
|
|
12
|
+
/** Construction options for an {@link AnthropicProvider}. */
|
|
13
|
+
export interface Config {
|
|
14
|
+
/** Anthropic API key; required and must be non-empty. */
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/** Overrides the API endpoint. Defaults to `https://api.anthropic.com`; trailing slashes are trimmed. */
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
/** Value sent as the `anthropic-version` header. Defaults to `2023-06-01`. */
|
|
19
|
+
apiVersion?: string;
|
|
20
|
+
/** Suffix appended to the default user-agent when non-empty. */
|
|
21
|
+
userAgent?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Response-header timeout in milliseconds: abort if the server doesn't return
|
|
24
|
+
* headers in time. Streaming bodies are NOT cut off once headers arrive.
|
|
25
|
+
* Defaults to 60000 (60 s); `0` disables it. Also settable via
|
|
26
|
+
* `LLM_HTTP_TIMEOUT` through providerset.
|
|
27
|
+
*/
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* galdor {@link Provider} backed by the Anthropic Messages API.
|
|
32
|
+
*
|
|
33
|
+
* Holds connection settings and builds the per-request headers; the actual wire
|
|
34
|
+
* translation and SSE handling live in the conversion and streaming helpers.
|
|
35
|
+
* Prefer {@link newAnthropic} to construct one.
|
|
36
|
+
*/
|
|
37
|
+
export declare class AnthropicProvider implements Provider {
|
|
38
|
+
#private;
|
|
39
|
+
/**
|
|
40
|
+
* Create a provider from the given {@link Config}.
|
|
41
|
+
*
|
|
42
|
+
* @throws {Error} When `apiKey` is missing or blank.
|
|
43
|
+
*/
|
|
44
|
+
constructor(cfg: Config);
|
|
45
|
+
/** @returns The provider's stable identifier, `"anthropic"`. */
|
|
46
|
+
name(): string;
|
|
47
|
+
/** @returns The feature set this adapter supports, including the model context window. */
|
|
48
|
+
capabilities(): Capabilities;
|
|
49
|
+
/**
|
|
50
|
+
* Run a single buffered completion against `/v1/messages`.
|
|
51
|
+
*
|
|
52
|
+
* Lowers the request to the wire shape, POSTs it, decodes the full response,
|
|
53
|
+
* and applies structured-output extraction when a `json_schema` format was
|
|
54
|
+
* requested.
|
|
55
|
+
*
|
|
56
|
+
* @param req - The galdor request to run.
|
|
57
|
+
* @param ctx - Optional run context; its abort signal cancels the request.
|
|
58
|
+
* @returns The completed galdor {@link Response}.
|
|
59
|
+
* @throws {APIError} On a non-2xx status or when the response body cannot be decoded.
|
|
60
|
+
*/
|
|
61
|
+
generate(req: Request, ctx?: RunContext): Promise<Response>;
|
|
62
|
+
/**
|
|
63
|
+
* Run a streaming completion, yielding incremental provider events.
|
|
64
|
+
*
|
|
65
|
+
* @param req - The galdor request to run.
|
|
66
|
+
* @param ctx - Optional run context; its abort signal cancels the stream.
|
|
67
|
+
* @returns An async iterable of {@link Event}s ending with a message-stop event.
|
|
68
|
+
*/
|
|
69
|
+
stream(req: Request, ctx?: RunContext): AsyncIterable<Event>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Construct an {@link AnthropicProvider} from a {@link Config}.
|
|
73
|
+
*
|
|
74
|
+
* @param cfg - Connection options; `apiKey` is required.
|
|
75
|
+
* @returns A ready-to-use provider instance.
|
|
76
|
+
* @throws {Error} When `apiKey` is missing or blank.
|
|
77
|
+
* @example
|
|
78
|
+
* const provider = newAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY! });
|
|
79
|
+
* const resp = await provider.generate({
|
|
80
|
+
* model: "claude-haiku-4-5",
|
|
81
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
export declare function newAnthropic(cfg: Config): AnthropicProvider;
|
|
85
|
+
export { normalizeHTTPError } from "./errors.ts";
|
|
86
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,KAAK,EAEV,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EAEhB,MAAM,uBAAuB,CAAC;AAS/B,6DAA6D;AAC7D,MAAM,WAAW,MAAM;IACrB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,yGAAyG;IACzG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,QAAQ;;IAOhD;;;;OAIG;gBACS,GAAG,EAAE,MAAM;IASvB,gEAAgE;IAChE,IAAI,IAAI,MAAM;IAId,0FAA0F;IAC1F,YAAY,IAAI,YAAY;IAwB5B;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0BjE;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC;CAM7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAE3D;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@galdor/provider-anthropic` — Anthropic (Claude Messages API) adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements the galdor {@link Provider} interface over the `/v1/messages`
|
|
5
|
+
* endpoint, supporting tool use, vision input, extended thinking, prompt
|
|
6
|
+
* caching, and structured output (expressed as a forced single tool call). Both
|
|
7
|
+
* a buffered {@link AnthropicProvider.generate} and an incremental
|
|
8
|
+
* {@link AnthropicProvider.stream} path are provided; construct an instance with
|
|
9
|
+
* {@link newAnthropic}.
|
|
10
|
+
*/
|
|
11
|
+
import { APIError, classify, fetchWithHeaderTimeout, validateRequest, } from "@galdor/core/provider";
|
|
12
|
+
import { buildRequest, extractStructuredOutput, responseFromWire } from "./convert.js";
|
|
13
|
+
import { normalizeHTTPError } from "./errors.js";
|
|
14
|
+
import { streamMessages } from "./stream.js";
|
|
15
|
+
const PROVIDER_NAME = "anthropic";
|
|
16
|
+
const DEFAULT_BASE_URL = "https://api.anthropic.com";
|
|
17
|
+
const DEFAULT_API_VERSION = "2023-06-01";
|
|
18
|
+
/**
|
|
19
|
+
* galdor {@link Provider} backed by the Anthropic Messages API.
|
|
20
|
+
*
|
|
21
|
+
* Holds connection settings and builds the per-request headers; the actual wire
|
|
22
|
+
* translation and SSE handling live in the conversion and streaming helpers.
|
|
23
|
+
* Prefer {@link newAnthropic} to construct one.
|
|
24
|
+
*/
|
|
25
|
+
export class AnthropicProvider {
|
|
26
|
+
#apiKey;
|
|
27
|
+
#baseURL;
|
|
28
|
+
#apiVersion;
|
|
29
|
+
#userAgent;
|
|
30
|
+
#timeoutMs;
|
|
31
|
+
/**
|
|
32
|
+
* Create a provider from the given {@link Config}.
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} When `apiKey` is missing or blank.
|
|
35
|
+
*/
|
|
36
|
+
constructor(cfg) {
|
|
37
|
+
if (!cfg.apiKey || cfg.apiKey.trim() === "")
|
|
38
|
+
throw new Error("anthropic: apiKey is required");
|
|
39
|
+
this.#apiKey = cfg.apiKey;
|
|
40
|
+
this.#baseURL = (cfg.baseURL || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
41
|
+
this.#apiVersion = cfg.apiVersion || DEFAULT_API_VERSION;
|
|
42
|
+
this.#userAgent = cfg.userAgent ?? "";
|
|
43
|
+
this.#timeoutMs = cfg.timeoutMs ?? 60_000;
|
|
44
|
+
}
|
|
45
|
+
/** @returns The provider's stable identifier, `"anthropic"`. */
|
|
46
|
+
name() {
|
|
47
|
+
return PROVIDER_NAME;
|
|
48
|
+
}
|
|
49
|
+
/** @returns The feature set this adapter supports, including the model context window. */
|
|
50
|
+
capabilities() {
|
|
51
|
+
return {
|
|
52
|
+
streaming: true,
|
|
53
|
+
toolCalling: true,
|
|
54
|
+
structuredOutput: true,
|
|
55
|
+
promptCaching: true,
|
|
56
|
+
visionInput: true,
|
|
57
|
+
reasoning: true,
|
|
58
|
+
maxContextTokens: 200_000,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Build the request headers, folding in any configured user-agent suffix. */
|
|
62
|
+
#headers() {
|
|
63
|
+
let ua = "galdor-anthropic/0.1";
|
|
64
|
+
if (this.#userAgent)
|
|
65
|
+
ua += ` ${this.#userAgent}`;
|
|
66
|
+
return {
|
|
67
|
+
"x-api-key": this.#apiKey,
|
|
68
|
+
"anthropic-version": this.#apiVersion,
|
|
69
|
+
"content-type": "application/json",
|
|
70
|
+
"user-agent": ua,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Run a single buffered completion against `/v1/messages`.
|
|
75
|
+
*
|
|
76
|
+
* Lowers the request to the wire shape, POSTs it, decodes the full response,
|
|
77
|
+
* and applies structured-output extraction when a `json_schema` format was
|
|
78
|
+
* requested.
|
|
79
|
+
*
|
|
80
|
+
* @param req - The galdor request to run.
|
|
81
|
+
* @param ctx - Optional run context; its abort signal cancels the request.
|
|
82
|
+
* @returns The completed galdor {@link Response}.
|
|
83
|
+
* @throws {APIError} On a non-2xx status or when the response body cannot be decoded.
|
|
84
|
+
*/
|
|
85
|
+
async generate(req, ctx) {
|
|
86
|
+
const capErr = validateRequest(this.capabilities(), req);
|
|
87
|
+
if (capErr)
|
|
88
|
+
throw capErr;
|
|
89
|
+
const wire = buildRequest(req, false);
|
|
90
|
+
const res = await fetchWithHeaderTimeout(`${this.#baseURL}/v1/messages`, { method: "POST", headers: this.#headers(), body: JSON.stringify(wire) }, this.#timeoutMs, ctx?.signal);
|
|
91
|
+
if (Math.floor(res.status / 100) !== 2)
|
|
92
|
+
throw await normalizeHTTPError(res);
|
|
93
|
+
const rawBytes = new Uint8Array(await res.arrayBuffer());
|
|
94
|
+
let body;
|
|
95
|
+
try {
|
|
96
|
+
body = JSON.parse(new TextDecoder().decode(rawBytes));
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
throw classify(new APIError({ kind: "server", provider: PROVIDER_NAME, statusCode: res.status, message: `decode response: ${e.message}` }));
|
|
100
|
+
}
|
|
101
|
+
let out = responseFromWire(body, rawBytes);
|
|
102
|
+
if (req.responseFormat?.type === "json_schema")
|
|
103
|
+
out = extractStructuredOutput(out, req.responseFormat.name);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Run a streaming completion, yielding incremental provider events.
|
|
108
|
+
*
|
|
109
|
+
* @param req - The galdor request to run.
|
|
110
|
+
* @param ctx - Optional run context; its abort signal cancels the stream.
|
|
111
|
+
* @returns An async iterable of {@link Event}s ending with a message-stop event.
|
|
112
|
+
*/
|
|
113
|
+
stream(req, ctx) {
|
|
114
|
+
const capErr = validateRequest(this.capabilities(), req);
|
|
115
|
+
if (capErr)
|
|
116
|
+
throw capErr;
|
|
117
|
+
const wire = buildRequest(req, true);
|
|
118
|
+
return streamMessages(`${this.#baseURL}/v1/messages`, this.#headers(), wire, ctx?.signal, this.#timeoutMs);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Construct an {@link AnthropicProvider} from a {@link Config}.
|
|
123
|
+
*
|
|
124
|
+
* @param cfg - Connection options; `apiKey` is required.
|
|
125
|
+
* @returns A ready-to-use provider instance.
|
|
126
|
+
* @throws {Error} When `apiKey` is missing or blank.
|
|
127
|
+
* @example
|
|
128
|
+
* const provider = newAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY! });
|
|
129
|
+
* const resp = await provider.generate({
|
|
130
|
+
* model: "claude-haiku-4-5",
|
|
131
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
|
|
132
|
+
* });
|
|
133
|
+
*/
|
|
134
|
+
export function newAnthropic(cfg) {
|
|
135
|
+
return new AnthropicProvider(cfg);
|
|
136
|
+
}
|
|
137
|
+
export { normalizeHTTPError } from "./errors.js";
|
|
138
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,QAAQ,EAER,QAAQ,EAER,sBAAsB,EAKtB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAwB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AACrD,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAqBzC;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IACnB,OAAO,CAAS;IAChB,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,UAAU,CAAS;IACnB,UAAU,CAAS;IAE5B;;;;OAIG;IACH,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC9F,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,UAAU,IAAI,mBAAmB,CAAC;QACzD,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACtC,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,CAAC,UAAU,CAAC,CAAC;IAC7G,CAAC;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic streaming over Server-Sent Events.
|
|
3
|
+
*
|
|
4
|
+
* Translates Anthropic's SSE event sequence (`message_start`, `content_block_*`,
|
|
5
|
+
* `message_delta`, `message_stop`) into galdor's provider {@link Event} stream
|
|
6
|
+
* ({@link EventType.MessageStart}, {@link EventType.ContentDelta},
|
|
7
|
+
* {@link EventType.ToolCallDelta}, {@link EventType.MessageStop}). The bytes
|
|
8
|
+
* arrive in arbitrary chunks, so the reader buffers and splits on the blank-line
|
|
9
|
+
* delimiter that separates SSE messages. Consume the result with `for await`, or
|
|
10
|
+
* fold it back into a single Response with `collectStream`.
|
|
11
|
+
*/
|
|
12
|
+
import { type Event } from "@galdor/core/provider";
|
|
13
|
+
import type { MessageRequest } from "./convert.ts";
|
|
14
|
+
/**
|
|
15
|
+
* POST a streaming `/v1/messages` request and yield galdor provider events.
|
|
16
|
+
*
|
|
17
|
+
* Sends the request with `stream: true` already set on `body`, then reads the
|
|
18
|
+
* SSE response incrementally: each complete event block is parsed and converted
|
|
19
|
+
* into zero or more {@link Event}s. Running token usage, the model name, and the
|
|
20
|
+
* stop reason are accumulated across the stream and emitted as a final
|
|
21
|
+
* {@link EventType.MessageStop} once the body is exhausted.
|
|
22
|
+
*
|
|
23
|
+
* @param url - Full messages endpoint to POST to.
|
|
24
|
+
* @param headers - Request headers, including auth and content type.
|
|
25
|
+
* @param body - The wire request; its `stream` flag should already be true.
|
|
26
|
+
* @param signal - Optional abort signal to cancel the in-flight request.
|
|
27
|
+
* @returns An async generator of provider events, ending with a MessageStop.
|
|
28
|
+
* @throws {APIError} When the response status is not 2xx (see {@link normalizeHTTPError}).
|
|
29
|
+
* @throws {Error} When a 2xx response unexpectedly carries no body.
|
|
30
|
+
* @example
|
|
31
|
+
* for await (const ev of streamMessages(url, headers, wire, signal)) {
|
|
32
|
+
* if (ev.type === EventType.ContentDelta) process.stdout.write(ev.contentDelta);
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
export declare function streamMessages(url: string, headers: Record<string, string>, body: MessageRequest, signal: AbortSignal | undefined, timeoutMs?: number): AsyncGenerator<Event>;
|
|
36
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAqC,MAAM,uBAAuB,CAAC;AAGtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA0FnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAuB,cAAc,CACnC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,SAAS,SAAI,GACZ,cAAc,CAAC,KAAK,CAAC,CAwCvB"}
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic streaming over Server-Sent Events.
|
|
3
|
+
*
|
|
4
|
+
* Translates Anthropic's SSE event sequence (`message_start`, `content_block_*`,
|
|
5
|
+
* `message_delta`, `message_stop`) into galdor's provider {@link Event} stream
|
|
6
|
+
* ({@link EventType.MessageStart}, {@link EventType.ContentDelta},
|
|
7
|
+
* {@link EventType.ToolCallDelta}, {@link EventType.MessageStop}). The bytes
|
|
8
|
+
* arrive in arbitrary chunks, so the reader buffers and splits on the blank-line
|
|
9
|
+
* delimiter that separates SSE messages. Consume the result with `for await`, or
|
|
10
|
+
* fold it back into a single Response with `collectStream`.
|
|
11
|
+
*/
|
|
12
|
+
import { EventType, fetchWithHeaderTimeout } from "@galdor/core/provider";
|
|
13
|
+
import { ContentType, Role } from "@galdor/core/schema";
|
|
14
|
+
import { classifyStreamError, normalizeHTTPError } from "./errors.js";
|
|
15
|
+
/** A zero-valued usage accumulator to fill in as the stream reports token counts. */
|
|
16
|
+
function emptyUsage() {
|
|
17
|
+
return { inputTokens: 0, outputTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fold any cache token counts from a wire usage object into the running usage,
|
|
21
|
+
* so streamed usage matches the non-streaming path. Counts are reported only
|
|
22
|
+
* when present, so each is applied only when non-zero.
|
|
23
|
+
*/
|
|
24
|
+
function foldCacheUsage(usage, wire) {
|
|
25
|
+
if (wire?.cache_creation_input_tokens)
|
|
26
|
+
usage.cacheCreationTokens = wire.cache_creation_input_tokens;
|
|
27
|
+
if (wire?.cache_read_input_tokens)
|
|
28
|
+
usage.cacheReadTokens = wire.cache_read_input_tokens;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build the terminal assistant {@link Message} carrying any accumulated
|
|
32
|
+
* reasoning, or `undefined` when none was streamed. The assistant text rides the
|
|
33
|
+
* content deltas, so this message holds only the thinking part; downstream
|
|
34
|
+
* `collectStream` harvests the thinking block from here.
|
|
35
|
+
*/
|
|
36
|
+
function reasoningMessage(r) {
|
|
37
|
+
if (r.thinking === "" && r.signature === "")
|
|
38
|
+
return undefined;
|
|
39
|
+
return {
|
|
40
|
+
role: Role.Assistant,
|
|
41
|
+
content: [{ type: ContentType.Thinking, text: r.thinking, signature: r.signature }],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Map a raw Anthropic stop-reason string to a {@link StopReason}. Known reasons
|
|
46
|
+
* map to themselves; empty and unknown values pass through unchanged (matching
|
|
47
|
+
* the non-streaming path) rather than being coerced to `end_turn`.
|
|
48
|
+
*/
|
|
49
|
+
function normalizeStopReason(s) {
|
|
50
|
+
switch (s) {
|
|
51
|
+
case "end_turn":
|
|
52
|
+
case "max_tokens":
|
|
53
|
+
case "tool_use":
|
|
54
|
+
case "stop_sequence":
|
|
55
|
+
case "refusal":
|
|
56
|
+
return s;
|
|
57
|
+
default:
|
|
58
|
+
return (s ?? "");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* POST a streaming `/v1/messages` request and yield galdor provider events.
|
|
63
|
+
*
|
|
64
|
+
* Sends the request with `stream: true` already set on `body`, then reads the
|
|
65
|
+
* SSE response incrementally: each complete event block is parsed and converted
|
|
66
|
+
* into zero or more {@link Event}s. Running token usage, the model name, and the
|
|
67
|
+
* stop reason are accumulated across the stream and emitted as a final
|
|
68
|
+
* {@link EventType.MessageStop} once the body is exhausted.
|
|
69
|
+
*
|
|
70
|
+
* @param url - Full messages endpoint to POST to.
|
|
71
|
+
* @param headers - Request headers, including auth and content type.
|
|
72
|
+
* @param body - The wire request; its `stream` flag should already be true.
|
|
73
|
+
* @param signal - Optional abort signal to cancel the in-flight request.
|
|
74
|
+
* @returns An async generator of provider events, ending with a MessageStop.
|
|
75
|
+
* @throws {APIError} When the response status is not 2xx (see {@link normalizeHTTPError}).
|
|
76
|
+
* @throws {Error} When a 2xx response unexpectedly carries no body.
|
|
77
|
+
* @example
|
|
78
|
+
* for await (const ev of streamMessages(url, headers, wire, signal)) {
|
|
79
|
+
* if (ev.type === EventType.ContentDelta) process.stdout.write(ev.contentDelta);
|
|
80
|
+
* }
|
|
81
|
+
*/
|
|
82
|
+
export async function* streamMessages(url, headers, body, signal, timeoutMs = 0) {
|
|
83
|
+
const res = await fetchWithHeaderTimeout(url, { method: "POST", headers: { ...headers, accept: "text/event-stream" }, body: JSON.stringify(body) }, timeoutMs, signal);
|
|
84
|
+
if (Math.floor(res.status / 100) !== 2)
|
|
85
|
+
throw await normalizeHTTPError(res);
|
|
86
|
+
if (!res.body)
|
|
87
|
+
throw new Error("anthropic: streaming response had no body");
|
|
88
|
+
// Maps a content-block index to its tool-call id so later input_json_delta
|
|
89
|
+
// events (which carry only the index) can be attributed to the right call.
|
|
90
|
+
const toolIndex = new Map();
|
|
91
|
+
const usage = emptyUsage();
|
|
92
|
+
const reasoning = { thinking: "", signature: "" };
|
|
93
|
+
let model = "";
|
|
94
|
+
// Empty until a message_delta reports one; passed through as-is, matching the
|
|
95
|
+
// oracle (a stream that ends without a stop_reason emits an empty reason).
|
|
96
|
+
let stopReason = "";
|
|
97
|
+
const decoder = new TextDecoder();
|
|
98
|
+
let buffer = "";
|
|
99
|
+
for await (const chunk of res.body) {
|
|
100
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
101
|
+
// SSE messages are separated by a blank line.
|
|
102
|
+
let sep;
|
|
103
|
+
while ((sep = buffer.indexOf("\n\n")) !== -1) {
|
|
104
|
+
const rawEvent = buffer.slice(0, sep);
|
|
105
|
+
buffer = buffer.slice(sep + 2);
|
|
106
|
+
const data = parseDataLine(rawEvent);
|
|
107
|
+
if (data === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
// handleEvent throws on a mid-stream `error` frame; the throw propagates
|
|
110
|
+
// through `yield*` to the `for await` consumer.
|
|
111
|
+
yield* handleEvent(data, { toolIndex, usage, reasoning }, (m) => (model = m), (sr) => (stopReason = sr));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const message = reasoningMessage(reasoning);
|
|
115
|
+
yield { type: EventType.MessageStop, stopReason, usage, model, ...(message ? { message } : {}) };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Extract and JSON-parse the `data:` payload from one SSE event block.
|
|
119
|
+
*
|
|
120
|
+
* Concatenates multiple `data:` lines within the block, ignores the terminal
|
|
121
|
+
* `[DONE]` sentinel and empty payloads, and swallows parse failures.
|
|
122
|
+
*
|
|
123
|
+
* @returns The decoded event, or `undefined` when there is nothing to emit.
|
|
124
|
+
*/
|
|
125
|
+
function parseDataLine(rawEvent) {
|
|
126
|
+
const dataParts = [];
|
|
127
|
+
for (const line of rawEvent.split("\n")) {
|
|
128
|
+
if (line.startsWith("data:"))
|
|
129
|
+
dataParts.push(line.slice(5).trimStart());
|
|
130
|
+
}
|
|
131
|
+
if (dataParts.length === 0)
|
|
132
|
+
return undefined;
|
|
133
|
+
const payload = dataParts.join("\n");
|
|
134
|
+
if (payload === "" || payload === "[DONE]")
|
|
135
|
+
return undefined;
|
|
136
|
+
try {
|
|
137
|
+
return JSON.parse(payload);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Convert one decoded SSE event into galdor provider events, mutating the shared
|
|
145
|
+
* accumulator state (tool-index map, usage, and reasoning) and reporting the
|
|
146
|
+
* model and stop reason through the supplied setters. Block-stop, message-stop
|
|
147
|
+
* and ping events produce nothing mid-stream. Thinking and signature deltas are
|
|
148
|
+
* accumulated silently rather than forwarded. An `error` frame throws.
|
|
149
|
+
*
|
|
150
|
+
* @throws {APIError} When the frame is a mid-stream `error` event.
|
|
151
|
+
*/
|
|
152
|
+
function* handleEvent(ev, state, setModel, setStop) {
|
|
153
|
+
switch (ev.type) {
|
|
154
|
+
case "message_start": {
|
|
155
|
+
const model = ev.message?.model ?? "";
|
|
156
|
+
if (model)
|
|
157
|
+
setModel(model);
|
|
158
|
+
if (ev.message?.usage?.input_tokens)
|
|
159
|
+
state.usage.inputTokens = ev.message.usage.input_tokens;
|
|
160
|
+
foldCacheUsage(state.usage, ev.message?.usage);
|
|
161
|
+
yield { type: EventType.MessageStart, model, usage: { ...state.usage } };
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "content_block_start": {
|
|
165
|
+
const cb = ev.content_block;
|
|
166
|
+
if (cb?.type === "tool_use" && typeof ev.index === "number") {
|
|
167
|
+
const id = cb.id ?? "";
|
|
168
|
+
state.toolIndex.set(ev.index, id);
|
|
169
|
+
yield { type: EventType.ToolCallDelta, toolCallDelta: { id, name: cb.name ?? "", argumentsDelta: "" } };
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case "content_block_delta": {
|
|
174
|
+
const d = ev.delta;
|
|
175
|
+
if (d?.type === "text_delta" && d.text) {
|
|
176
|
+
yield { type: EventType.ContentDelta, contentDelta: d.text };
|
|
177
|
+
}
|
|
178
|
+
else if (d?.type === "input_json_delta" && typeof ev.index === "number") {
|
|
179
|
+
const id = state.toolIndex.get(ev.index) ?? "";
|
|
180
|
+
yield { type: EventType.ToolCallDelta, toolCallDelta: { id, name: "", argumentsDelta: d.partial_json ?? "" } };
|
|
181
|
+
}
|
|
182
|
+
else if (d?.type === "thinking_delta" && d.thinking) {
|
|
183
|
+
// Extended-thinking text; gather it for the terminal message, not live.
|
|
184
|
+
state.reasoning.thinking += d.thinking;
|
|
185
|
+
}
|
|
186
|
+
else if (d?.type === "signature_delta" && d.signature) {
|
|
187
|
+
// The provider-issued signature for the thinking block, gathered silently.
|
|
188
|
+
state.reasoning.signature += d.signature;
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case "message_delta": {
|
|
193
|
+
if (ev.delta?.stop_reason)
|
|
194
|
+
setStop(normalizeStopReason(ev.delta.stop_reason));
|
|
195
|
+
if (ev.usage?.output_tokens)
|
|
196
|
+
state.usage.outputTokens = ev.usage.output_tokens;
|
|
197
|
+
// Anthropic can also report input_tokens here (not just at message_start);
|
|
198
|
+
// track the latest so the terminal event carries them, matching the oracle.
|
|
199
|
+
if (ev.usage?.input_tokens)
|
|
200
|
+
state.usage.inputTokens = ev.usage.input_tokens;
|
|
201
|
+
foldCacheUsage(state.usage, ev.usage);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case "error": {
|
|
205
|
+
// A mid-stream failure: classify by error type and propagate by throwing,
|
|
206
|
+
// which surfaces to the `for await` consumer rather than being swallowed.
|
|
207
|
+
throw classifyStreamError(ev.error?.type, ev.error?.message ?? "anthropic: stream error");
|
|
208
|
+
}
|
|
209
|
+
// content_block_stop / message_stop / ping: nothing to emit mid-stream.
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAc,SAAS,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,WAAW,EAAgB,IAAI,EAA+B,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAkCtE,qFAAqF;AACrF,SAAS,UAAU;IACjB,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;AACzF,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,KAAY,EAAE,IAA2B;IAC/D,IAAI,IAAI,EAAE,2BAA2B;QAAE,KAAK,CAAC,mBAAmB,GAAG,IAAI,CAAC,2BAA2B,CAAC;IACpG,IAAI,IAAI,EAAE,uBAAuB;QAAE,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC,uBAAuB,CAAC;AAC1F,CAAC;AAYD;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,CAAY;IACpC,IAAI,CAAC,CAAC,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,SAAS,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAC9D,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,SAAS;QACpB,OAAO,EAAE,CAAC,EAAE,IAAI,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AAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,IAAI,yBAAyB,CAAC,CAAC;QAC5F,CAAC;QACD,wEAAwE;IAC1E,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galdor/provider-anthropic",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Anthropic (Claude Messages API) provider adapter for galdor-bun.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Yasser Rosas",
|
|
8
|
+
"email": "yassros16@gmail.com"
|
|
9
|
+
},
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"bun": "./src/index.ts",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.build.json"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.5",
|
|
31
|
+
"bun": ">=1.3"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@galdor/core": "0.3.0"
|
|
35
|
+
}
|
|
36
|
+
}
|