@autumnsgrove/lyra 0.1.0 → 0.2.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.
Files changed (52) hide show
  1. package/dist/adapters/openai/errors.d.ts +36 -0
  2. package/dist/adapters/openai/errors.d.ts.map +1 -0
  3. package/dist/adapters/openai/errors.js +117 -0
  4. package/dist/adapters/openai/errors.js.map +1 -0
  5. package/dist/adapters/openai/index.d.ts +18 -0
  6. package/dist/adapters/openai/index.d.ts.map +1 -0
  7. package/dist/adapters/openai/index.js +18 -0
  8. package/dist/adapters/openai/index.js.map +1 -0
  9. package/dist/adapters/openai/model.d.ts +50 -0
  10. package/dist/adapters/openai/model.d.ts.map +1 -0
  11. package/dist/adapters/openai/model.js +169 -0
  12. package/dist/adapters/openai/model.js.map +1 -0
  13. package/dist/adapters/openai/presets.d.ts +36 -0
  14. package/dist/adapters/openai/presets.d.ts.map +1 -0
  15. package/dist/adapters/openai/presets.js +43 -0
  16. package/dist/adapters/openai/presets.js.map +1 -0
  17. package/dist/adapters/openai/request.d.ts +47 -0
  18. package/dist/adapters/openai/request.d.ts.map +1 -0
  19. package/dist/adapters/openai/request.js +93 -0
  20. package/dist/adapters/openai/request.js.map +1 -0
  21. package/dist/adapters/openai/sse.d.ts +44 -0
  22. package/dist/adapters/openai/sse.d.ts.map +1 -0
  23. package/dist/adapters/openai/sse.js +410 -0
  24. package/dist/adapters/openai/sse.js.map +1 -0
  25. package/dist/core/system-clock.d.ts.map +1 -1
  26. package/dist/core/system-clock.js +5 -1
  27. package/dist/core/system-clock.js.map +1 -1
  28. package/dist/testkit/cassette.d.ts +91 -0
  29. package/dist/testkit/cassette.d.ts.map +1 -0
  30. package/dist/testkit/cassette.js +250 -0
  31. package/dist/testkit/cassette.js.map +1 -0
  32. package/dist/testkit/fake-model-server.d.ts +87 -0
  33. package/dist/testkit/fake-model-server.d.ts.map +1 -0
  34. package/dist/testkit/fake-model-server.js +225 -0
  35. package/dist/testkit/fake-model-server.js.map +1 -0
  36. package/dist/testkit/index.d.ts +4 -1
  37. package/dist/testkit/index.d.ts.map +1 -1
  38. package/dist/testkit/index.js +4 -1
  39. package/dist/testkit/index.js.map +1 -1
  40. package/dist/testkit/misbehaving-model.d.ts +40 -0
  41. package/dist/testkit/misbehaving-model.d.ts.map +1 -0
  42. package/dist/testkit/misbehaving-model.js +134 -0
  43. package/dist/testkit/misbehaving-model.js.map +1 -0
  44. package/dist/testkit/model.d.ts +2 -0
  45. package/dist/testkit/model.d.ts.map +1 -1
  46. package/dist/testkit/model.js +3 -2
  47. package/dist/testkit/model.js.map +1 -1
  48. package/dist/testkit/scenario.d.ts +11 -1
  49. package/dist/testkit/scenario.d.ts.map +1 -1
  50. package/dist/testkit/scenario.js +4 -2
  51. package/dist/testkit/scenario.js.map +1 -1
  52. package/package.json +5 -1
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The request on the wire (docs/adapters.md, OAI14 to OAI19).
3
+ *
4
+ * The Model slot's request is generic — a system prompt, messages, tools, a
5
+ * signal — and chat completions wants the same things spelled its own way. This
6
+ * file is that translation and nothing else: it is pure, so a test can read the
7
+ * whole of what would be sent without a socket.
8
+ *
9
+ * Two properties matter more than the mapping. Nothing is sent that a model might
10
+ * reject: no `tool_choice`, no `stream_options`, no usage switch, no provider
11
+ * field, because the core has no way to ask for one and both endpoints answer
12
+ * without them. And the key exists in exactly one place, the `Authorization`
13
+ * header, built from what a host's Secrets slot gave rather than from anything
14
+ * that could be logged or recorded.
15
+ */
16
+ function wireMessage(message) {
17
+ switch (message.role) {
18
+ case "user":
19
+ return { role: "user", content: message.text };
20
+ case "assistant":
21
+ // A reply with no calls is text alone, which is what a provider sends back
22
+ // as its own last turn. Reasoning is kept in the record (decision 33) but is
23
+ // never sent back: chat completions has no field for it.
24
+ if (message.toolCalls.length === 0) {
25
+ return { role: "assistant", content: message.text };
26
+ }
27
+ return {
28
+ role: "assistant",
29
+ content: message.text,
30
+ tool_calls: message.toolCalls.map((call) => ({
31
+ id: call.id,
32
+ type: "function",
33
+ function: { name: call.name, arguments: call.arguments },
34
+ })),
35
+ };
36
+ case "tool":
37
+ // Chat completions has no error field, and the loop already said what went
38
+ // wrong in the content, so `isError` is not invented on the wire.
39
+ return { role: "tool", tool_call_id: message.toolCallId, content: message.content };
40
+ }
41
+ }
42
+ /**
43
+ * The body for one request. `configured` is the adapter's model, which a recipe's
44
+ * fallback model overrides (decision 58).
45
+ */
46
+ export function buildWireRequest(options) {
47
+ const { request } = options;
48
+ const messages = [];
49
+ if (request.system !== "") {
50
+ messages.push({ role: "system", content: request.system });
51
+ }
52
+ for (const message of request.messages) {
53
+ messages.push(wireMessage(message));
54
+ }
55
+ const body = {
56
+ model: request.model ?? options.model,
57
+ stream: true,
58
+ messages,
59
+ };
60
+ if (request.tools.length > 0) {
61
+ body.tools = request.tools.map((tool) => ({
62
+ type: "function",
63
+ function: {
64
+ name: tool.name,
65
+ description: tool.description,
66
+ parameters: tool.parameters,
67
+ },
68
+ }));
69
+ }
70
+ return body;
71
+ }
72
+ /**
73
+ * The headers for one request. A preset's own headers go on first and the
74
+ * computed ones last, so nothing can replace the key or the content type by
75
+ * accident.
76
+ */
77
+ export function buildHeaders(options) {
78
+ const headers = {};
79
+ // Header names are case-insensitive, so a preset's `Authorization` would otherwise
80
+ // sit beside the computed `authorization` and the runtime would merge the two into
81
+ // one header with two credentials. Lowercased here, the computed ones below win.
82
+ for (const [name, value] of Object.entries(options.extra ?? {})) {
83
+ headers[name.toLowerCase()] = value;
84
+ }
85
+ headers["content-type"] = "application/json";
86
+ headers["accept"] = "text/event-stream";
87
+ headers["authorization"] = `Bearer ${options.apiKey}`;
88
+ if (options.session !== undefined) {
89
+ headers["x-opencode-session"] = options.session;
90
+ }
91
+ return headers;
92
+ }
93
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/adapters/openai/request.ts"],"names":[],"mappings":"AAAA;;;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IACtD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IACjD,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The server-sent-event parser for chat completions (docs/adapters.md, OAI01 to
3
+ * OAI13).
4
+ *
5
+ * A model reply arrives as a stream of `data:` events, each holding one JSON
6
+ * chunk. This file turns that stream into one `ModelReply` without touching the
7
+ * network or the clock, so all of it is testable as a pure function, and the
8
+ * assembled reply goes through the core's `decodeReply` before it leaves. What
9
+ * comes out is a reply the loop already trusts.
10
+ *
11
+ * It is written to be tolerant of everything a provider may leave out and strict
12
+ * about anything that would make the reply a lie: a stream with no ending is an
13
+ * error rather than a short reply, two calls cannot share an id, and a stream
14
+ * that grows past the cap stops being assembled instead of being kept in memory.
15
+ */
16
+ import type { ModelError, ModelReply } from "../../core/model.js";
17
+ import { type Result } from "../../core/result.js";
18
+ /** One assembled reply is capped at 1 MiB, the same as a record entry (decision 90). */
19
+ export declare const DEFAULT_STREAM_CAP_BYTES = 1048576;
20
+ export interface SseOptions {
21
+ /** How many bytes of stream to accept before giving up. */
22
+ maxBytes?: number;
23
+ }
24
+ export interface SseReader {
25
+ /**
26
+ * Feed the next piece of decoded text. A reply means the stream ended, an error
27
+ * means it cannot be assembled; `undefined` means keep reading.
28
+ */
29
+ push(text: string): Result<ModelReply | undefined, ModelError>;
30
+ /** Finish the stream, which fails unless a finish reason or `[DONE]` arrived. */
31
+ end(): Result<ModelReply, ModelError>;
32
+ }
33
+ export declare function sseReader(options?: SseOptions): SseReader;
34
+ export interface ReadReplyOptions extends SseOptions {
35
+ /** The caller's signal, so a stop that arrives mid-read is not read as a network fault. */
36
+ signal?: AbortSignal;
37
+ }
38
+ /**
39
+ * Read a body to one reply, decoding bytes as they arrive. The stream is always
40
+ * closed when this returns, whether it ended, failed or was refused, so a
41
+ * provider is never left sending into a reader nobody holds.
42
+ */
43
+ export declare function readReply(body: ReadableStream<Uint8Array> | null, options?: ReadReplyOptions): Promise<Result<ModelReply, ModelError>>;
44
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/adapters/openai/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAM,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAGvD,wFAAwF;AACxF,eAAO,MAAM,wBAAwB,UAAY,CAAC;AAOlD,MAAM,WAAW,UAAU;IAC1B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACzB;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,GAAG,SAAS,EAAE,UAAU,CAAC,CAAC;IAC/D,iFAAiF;IACjF,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;CACtC;AAkDD,wBAAgB,SAAS,CAAC,OAAO,GAAE,UAAe,GAAG,SAAS,CA8T7D;AAED,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IACnD,2FAA2F;IAC3F,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAqBD;;;;GAIG;AACH,wBAAsB,SAAS,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,EACvC,OAAO,GAAE,gBAAqB,GAC5B,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAoDzC"}
@@ -0,0 +1,410 @@
1
+ /**
2
+ * The server-sent-event parser for chat completions (docs/adapters.md, OAI01 to
3
+ * OAI13).
4
+ *
5
+ * A model reply arrives as a stream of `data:` events, each holding one JSON
6
+ * chunk. This file turns that stream into one `ModelReply` without touching the
7
+ * network or the clock, so all of it is testable as a pure function, and the
8
+ * assembled reply goes through the core's `decodeReply` before it leaves. What
9
+ * comes out is a reply the loop already trusts.
10
+ *
11
+ * It is written to be tolerant of everything a provider may leave out and strict
12
+ * about anything that would make the reply a lie: a stream with no ending is an
13
+ * error rather than a short reply, two calls cannot share an id, and a stream
14
+ * that grows past the cap stops being assembled instead of being kept in memory.
15
+ */
16
+ import { decodeFinishReason, decodeReply } from "../../core/decode-reply.js";
17
+ import { isPlainObject } from "../../core/json.js";
18
+ import { ok } from "../../core/result.js";
19
+ import { utf8Length } from "../../record/truncate.js";
20
+ /** One assembled reply is capped at 1 MiB, the same as a record entry (decision 90). */
21
+ export const DEFAULT_STREAM_CAP_BYTES = 1_048_576;
22
+ const DONE_MARKER = "[DONE]";
23
+ /** Statuses where trying again cannot help, so an in-stream error is not retried. */
24
+ const PERMANENT_STATUSES = new Set([400, 401, 403, 404, 422]);
25
+ function providerError(message, retryable = true) {
26
+ return { code: "provider_error", message, retryable };
27
+ }
28
+ /** A token count, or nothing when the provider did not send one. */
29
+ function tokenCount(value) {
30
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0
31
+ ? value
32
+ : undefined;
33
+ }
34
+ /** A cost in credits, which OpenRouter reports in dollars. */
35
+ function costAmount(value) {
36
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
37
+ }
38
+ function truncate(text) {
39
+ return text.length > 300 ? `${text.slice(0, 300)}…` : text;
40
+ }
41
+ /** The next complete line, and how many characters it took, including its ending. */
42
+ function nextLine(text, atEnd) {
43
+ for (let index = 0; index < text.length; index += 1) {
44
+ const character = text[index];
45
+ if (character === "\n") {
46
+ return { line: text.slice(0, index), length: index + 1 };
47
+ }
48
+ if (character === "\r") {
49
+ // A carriage return at the very end of one chunk may be the first half of
50
+ // a CRLF that arrives in the next, so it waits unless the stream is over.
51
+ if (index + 1 < text.length) {
52
+ const width = text[index + 1] === "\n" ? 2 : 1;
53
+ return { line: text.slice(0, index), length: index + width };
54
+ }
55
+ return atEnd ? { line: text.slice(0, index), length: index + 1 } : undefined;
56
+ }
57
+ }
58
+ return undefined;
59
+ }
60
+ export function sseReader(options = {}) {
61
+ const maxBytes = options.maxBytes ?? DEFAULT_STREAM_CAP_BYTES;
62
+ let buffer = "";
63
+ /** The `data:` lines of the event being read. */
64
+ let dataLines = [];
65
+ let bytes = 0;
66
+ let text = "";
67
+ let reasoning = "";
68
+ const calls = new Map();
69
+ let inputTokens;
70
+ let outputTokens;
71
+ let cost;
72
+ let finish;
73
+ let model = "";
74
+ let outcome;
75
+ const asPushResult = (settled) => "reply" in settled ? ok(settled.reply) : { ok: false, error: settled.error };
76
+ const asEndResult = (settled) => "reply" in settled ? ok(settled.reply) : { ok: false, error: settled.error };
77
+ const settleError = (error) => {
78
+ const settled = { error };
79
+ outcome = settled;
80
+ return settled;
81
+ };
82
+ /** The reply, once it is complete. Everything it claims is checked by the core's decoder. */
83
+ const buildReply = () => {
84
+ const ordered = [...calls.entries()].sort(([left], [right]) => left - right);
85
+ // Ids must be unique within a reply, because the loop pairs a result to its
86
+ // call by id. An id a provider sent for exactly one call is reserved for it,
87
+ // so a synthetic id never takes a real one's place.
88
+ const counts = new Map();
89
+ for (const [, state] of ordered) {
90
+ if (state.id !== undefined && state.id !== "") {
91
+ counts.set(state.id, (counts.get(state.id) ?? 0) + 1);
92
+ }
93
+ }
94
+ const reserved = new Set([...counts.entries()].filter(([, count]) => count === 1).map(([id]) => id));
95
+ const used = new Set();
96
+ const toolCalls = ordered.map(([, state], position) => {
97
+ const preferred = state.id ?? "";
98
+ let id = preferred;
99
+ // A call with no id, or one repeating an id already taken, gets one from its
100
+ // position, which is stable for a resume. A repeat keeps the first call's.
101
+ if (id === "" || used.has(id)) {
102
+ id = `call_${position + 1}`;
103
+ while (used.has(id) || reserved.has(id)) {
104
+ id = `${id}_`;
105
+ }
106
+ }
107
+ used.add(id);
108
+ return { id, name: state.name, arguments: state.arguments };
109
+ });
110
+ const usage = { inputTokens: inputTokens ?? 0, outputTokens: outputTokens ?? 0 };
111
+ if (cost !== undefined) {
112
+ usage.cost = { amount: cost, currency: "USD", source: "provider" };
113
+ }
114
+ const reply = {
115
+ text,
116
+ toolCalls,
117
+ usage,
118
+ finishReason: decodeFinishReason(finish),
119
+ model,
120
+ };
121
+ if (reasoning !== "") {
122
+ reply.reasoning = reasoning;
123
+ }
124
+ return reply;
125
+ };
126
+ const settleReply = () => {
127
+ const decoded = decodeReply(buildReply());
128
+ if (!decoded.ok) {
129
+ // The assembled reply is not one the loop could act on. Trying again with
130
+ // the same model would send the same broken thing, so this is not retryable.
131
+ return settleError({
132
+ code: "provider_error",
133
+ message: decoded.error.message,
134
+ retryable: false,
135
+ });
136
+ }
137
+ const settled = { reply: decoded.value };
138
+ outcome = settled;
139
+ return settled;
140
+ };
141
+ const applyDelta = (delta) => {
142
+ const content = delta["content"];
143
+ if (typeof content === "string" && content !== "") {
144
+ text += content;
145
+ }
146
+ // OpenRouter calls it `reasoning`; other OpenAI-style endpoints use `reasoning_content`.
147
+ const reasoningPiece = delta["reasoning"] ?? delta["reasoning_content"];
148
+ if (typeof reasoningPiece === "string" && reasoningPiece !== "") {
149
+ reasoning += reasoningPiece;
150
+ }
151
+ const rawCalls = delta["tool_calls"];
152
+ if (rawCalls === undefined) {
153
+ return undefined;
154
+ }
155
+ if (!Array.isArray(rawCalls)) {
156
+ return providerError("the model's stream sent tool_calls that are not a list");
157
+ }
158
+ for (const [position, rawCall] of rawCalls.entries()) {
159
+ if (!isPlainObject(rawCall)) {
160
+ return providerError("the model's stream sent a tool call that is not an object");
161
+ }
162
+ const rawIndex = rawCall["index"];
163
+ const index = typeof rawIndex === "number" && Number.isSafeInteger(rawIndex) && rawIndex >= 0
164
+ ? rawIndex
165
+ : position;
166
+ const state = calls.get(index) ?? { name: "", arguments: "" };
167
+ const id = rawCall["id"];
168
+ if (typeof id === "string" && id !== "") {
169
+ state.id = id;
170
+ }
171
+ const name = rawCall["function"];
172
+ if (isPlainObject(name)) {
173
+ // The name arrives once; the arguments arrive in as many pieces as the
174
+ // provider likes, and their exact text is what the model meant to send.
175
+ const rawName = name["name"];
176
+ if (typeof rawName === "string" && rawName !== "" && state.name === "") {
177
+ state.name = rawName;
178
+ }
179
+ const rawArguments = name["arguments"];
180
+ if (typeof rawArguments === "string") {
181
+ state.arguments += rawArguments;
182
+ }
183
+ }
184
+ calls.set(index, state);
185
+ }
186
+ return undefined;
187
+ };
188
+ const applyUsage = (rawUsage) => {
189
+ const prompt = tokenCount(rawUsage["prompt_tokens"]);
190
+ if (prompt !== undefined) {
191
+ inputTokens = prompt;
192
+ }
193
+ const completion = tokenCount(rawUsage["completion_tokens"]);
194
+ if (completion !== undefined) {
195
+ outputTokens = completion;
196
+ }
197
+ const reported = costAmount(rawUsage["cost"]);
198
+ if (reported !== undefined) {
199
+ cost = reported;
200
+ }
201
+ };
202
+ const handlePayload = (payload) => {
203
+ if (payload.trim() === DONE_MARKER) {
204
+ // `[DONE]` is the provider saying the stream is over, so it is an ending in
205
+ // its own right: a compatible endpoint may send it without a finish reason,
206
+ // and the core already turns a reason it does not model into `other`.
207
+ settleReply();
208
+ return;
209
+ }
210
+ let parsed;
211
+ try {
212
+ parsed = JSON.parse(payload);
213
+ }
214
+ catch {
215
+ settleError(providerError("the model's stream sent a chunk that is not JSON"));
216
+ return;
217
+ }
218
+ if (!isPlainObject(parsed)) {
219
+ settleError(providerError("the model's stream sent a chunk that is not an object"));
220
+ return;
221
+ }
222
+ // A provider that fails in the middle of a stream sends the failure as a
223
+ // chunk with an HTTP status inside it, because the status line already went.
224
+ const rawError = parsed["error"];
225
+ if (isPlainObject(rawError)) {
226
+ const status = typeof rawError["code"] === "number" ? rawError["code"] : 0;
227
+ const message = typeof rawError["message"] === "string"
228
+ ? rawError["message"]
229
+ : "the model's provider reported an error";
230
+ settleError({
231
+ code: "provider_error",
232
+ message: truncate(message),
233
+ retryable: !PERMANENT_STATUSES.has(status),
234
+ });
235
+ return;
236
+ }
237
+ const rawModel = parsed["model"];
238
+ if (typeof rawModel === "string") {
239
+ model = rawModel;
240
+ }
241
+ const rawUsage = parsed["usage"];
242
+ if (isPlainObject(rawUsage)) {
243
+ applyUsage(rawUsage);
244
+ }
245
+ const choices = parsed["choices"];
246
+ if (choices === undefined) {
247
+ return;
248
+ }
249
+ if (!Array.isArray(choices)) {
250
+ settleError(providerError("the model's stream sent choices that are not a list"));
251
+ return;
252
+ }
253
+ for (const choice of choices) {
254
+ if (!isPlainObject(choice)) {
255
+ settleError(providerError("the model's stream sent a choice that is not an object"));
256
+ return;
257
+ }
258
+ // One completion was asked for, so a choice for another index says nothing.
259
+ const index = choice["index"];
260
+ if (typeof index === "number" && index !== 0) {
261
+ continue;
262
+ }
263
+ const rawFinish = choice["finish_reason"];
264
+ if (typeof rawFinish === "string" && rawFinish !== "" && rawFinish !== "error") {
265
+ finish = rawFinish;
266
+ }
267
+ const delta = choice["delta"];
268
+ if (isPlainObject(delta)) {
269
+ const problem = applyDelta(delta);
270
+ if (problem !== undefined) {
271
+ settleError(problem);
272
+ return;
273
+ }
274
+ }
275
+ }
276
+ };
277
+ const handleLine = (line) => {
278
+ if (line === "") {
279
+ // A blank line is the end of the event, which is where its data is read.
280
+ if (dataLines.length === 0) {
281
+ return;
282
+ }
283
+ const payload = dataLines.join("\n");
284
+ dataLines = [];
285
+ handlePayload(payload);
286
+ return;
287
+ }
288
+ if (line.startsWith(":")) {
289
+ // A comment, which OpenRouter sends as a keep-alive.
290
+ return;
291
+ }
292
+ const colon = line.indexOf(":");
293
+ const field = colon === -1 ? line : line.slice(0, colon);
294
+ if (field === "data") {
295
+ const value = colon === -1 ? "" : line.slice(colon + 1);
296
+ dataLines.push(value.startsWith(" ") ? value.slice(1) : value);
297
+ }
298
+ // `event:`, `id:` and `retry:` carry nothing a chat completion needs.
299
+ };
300
+ return {
301
+ push(chunk) {
302
+ if (outcome !== undefined) {
303
+ return asPushResult(outcome);
304
+ }
305
+ bytes += utf8Length(chunk);
306
+ if (bytes > maxBytes) {
307
+ return asPushResult(settleError(providerError(`the model's stream passed ${maxBytes} bytes, so it was given up on`, false)));
308
+ }
309
+ buffer += chunk;
310
+ for (;;) {
311
+ const found = nextLine(buffer, false);
312
+ if (found === undefined) {
313
+ return ok(undefined);
314
+ }
315
+ buffer = buffer.slice(found.length);
316
+ handleLine(found.line);
317
+ if (outcome !== undefined) {
318
+ return asPushResult(outcome);
319
+ }
320
+ }
321
+ },
322
+ end() {
323
+ if (outcome !== undefined) {
324
+ return asEndResult(outcome);
325
+ }
326
+ if (buffer.trim() !== "" || dataLines.length > 0) {
327
+ return asEndResult(settleError(providerError("the model's stream ended in the middle of an event")));
328
+ }
329
+ if (finish === undefined) {
330
+ return asEndResult(settleError(providerError("the model's stream ended without a finish reason")));
331
+ }
332
+ return asEndResult(settleReply());
333
+ },
334
+ };
335
+ }
336
+ /** A promise that rejects the moment a stop is signalled, so a read cannot hang through one. */
337
+ function abortPromise(signal) {
338
+ return new Promise((_, reject) => {
339
+ const stop = () => reject(providerError("the model's reply stopped", false));
340
+ if (signal.aborted) {
341
+ stop();
342
+ return;
343
+ }
344
+ signal.addEventListener("abort", stop, { once: true });
345
+ });
346
+ }
347
+ function reasonOf(error) {
348
+ if (error instanceof Error) {
349
+ return error.message;
350
+ }
351
+ return String(error);
352
+ }
353
+ /**
354
+ * Read a body to one reply, decoding bytes as they arrive. The stream is always
355
+ * closed when this returns, whether it ended, failed or was refused, so a
356
+ * provider is never left sending into a reader nobody holds.
357
+ */
358
+ export async function readReply(body, options = {}) {
359
+ if (body === null) {
360
+ return { ok: false, error: providerError("the model's response had no body") };
361
+ }
362
+ const stream = body.getReader();
363
+ const decoder = new TextDecoder();
364
+ const reader = sseReader(options);
365
+ const stop = options.signal === undefined ? undefined : abortPromise(options.signal);
366
+ const push = (text) => {
367
+ const pushed = reader.push(text);
368
+ if (!pushed.ok) {
369
+ return pushed;
370
+ }
371
+ return pushed.value === undefined ? undefined : ok(pushed.value);
372
+ };
373
+ try {
374
+ for (;;) {
375
+ const read = stop === undefined
376
+ ? await stream.read()
377
+ : await Promise.race([stream.read(), stop]);
378
+ if (read.done) {
379
+ break;
380
+ }
381
+ if (read.value === undefined) {
382
+ continue;
383
+ }
384
+ const settled = push(decoder.decode(read.value, { stream: true }));
385
+ if (settled !== undefined) {
386
+ return settled;
387
+ }
388
+ }
389
+ const tail = decoder.decode();
390
+ if (tail !== "") {
391
+ const settled = push(tail);
392
+ if (settled !== undefined) {
393
+ return settled;
394
+ }
395
+ }
396
+ return reader.end();
397
+ }
398
+ catch (error) {
399
+ return {
400
+ ok: false,
401
+ error: providerError(`the model's reply stopped: ${reasonOf(error)}`),
402
+ };
403
+ }
404
+ finally {
405
+ // Closing a stream that already ended is harmless, and it releases one that
406
+ // was given up on early.
407
+ void stream.cancel().catch(() => undefined);
408
+ }
409
+ }
410
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/adapters/openai/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,EAAE,EAAe,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAElD,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,qFAAqF;AACrF,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAyB9D,SAAS,aAAa,CAAC,OAAe,EAAE,SAAS,GAAG,IAAI;IACvD,OAA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,YAAY,CAAC;AAuC7C,wFAAwF;AACxF,wBAAgB,WAAW,IAAI,KAAK,CAMnC;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAW/B"}
1
+ {"version":3,"file":"system-clock.d.ts","sourceRoot":"","sources":["../../src/core/system-clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AA2C7C,wFAAwF;AACxF,wBAAgB,WAAW,IAAI,KAAK,CAMnC;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAW/B"}
@@ -8,7 +8,11 @@
8
8
  */
9
9
  /** Bytes in an id's random half. 128 bits is what decision 85 wants for an unguessable id. */
10
10
  const ID_BITS = 128;
11
- /** A clock over the host's own time. Takes the real ones as arguments so this file is testable. */
11
+ /**
12
+ * A clock over the host's own time. Takes the real ones as arguments so this file
13
+ * is testable. The handle is whatever the host's timer gives back — a number on
14
+ * Workers, an object on Node — so it is passed through rather than named.
15
+ */
12
16
  function clockFrom(nowMs, wait, cancelWait) {
13
17
  return {
14
18
  now: nowMs,
@@ -1 +1 @@
1
- {"version":3,"file":"system-clock.js","sourceRoot":"","sources":["../../src/core/system-clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,8FAA8F;AAC9F,MAAM,OAAO,GAAG,GAAG,CAAC;AAEpB,mGAAmG;AACnG,SAAS,SAAS,CACjB,KAAmB,EACnB,IAAkD,EAClD,UAAoC;IAEpC,OAAO;QACN,GAAG,EAAE,KAAK;QACV,KAAK,CAAC,EAAE,EAAE,MAAM;YACf,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC5C,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;oBAC9B,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;oBAClB,OAAO;gBACR,CAAC;gBACD,MAAM,MAAM,GAAG,I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