@opencode/ai 0.0.0-dev-537 → 0.0.0-dev-549
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/README.md +16 -2
- package/dist/cache-policy.js +15 -3
- package/dist/decision.d.ts +12 -10
- package/dist/decision.js +10 -4
- package/dist/experimental/extraction.d.ts +3 -7
- package/dist/experimental/extraction.js +2 -3
- package/dist/image.d.ts +5 -7
- package/dist/image.js +2 -3
- package/dist/llm.d.ts +3 -6
- package/dist/llm.js +5 -2
- package/dist/loop.js +5 -4
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +1 -1
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/anthropic-messages.js +3 -12
- package/dist/protocols/bedrock-converse.js +0 -4
- package/dist/protocols/gemini.js +0 -4
- package/dist/protocols/meta-responses.js +22 -20
- package/dist/protocols/mistral-chat.js +0 -3
- package/dist/protocols/open-responses.d.ts +1 -1
- package/dist/protocols/open-responses.js +4 -6
- package/dist/protocols/openai-chat.d.ts +3 -3
- package/dist/protocols/openai-chat.js +7 -25
- package/dist/protocols/shared.js +11 -9
- package/dist/protocols/utils/responses-compaction.js +3 -3
- package/dist/protocols/utils/tool-stream.d.ts +2 -2
- package/dist/providers/assemblyai.d.ts +1 -1
- package/dist/providers/azure.js +2 -2
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/deepgram.d.ts +1 -1
- package/dist/providers/elevenlabs.d.ts +1 -1
- package/dist/providers/openai.js +2 -2
- package/dist/providers/opencode.d.ts +2 -2
- package/dist/providers/opencode.js +1 -1
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/typesafe-ai.d.ts +2 -2
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/public.d.ts +3 -3
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +3 -7
- package/dist/route/client.js +11 -24
- package/dist/route/decision.d.ts +2 -2
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +1 -1
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/schema/events.d.ts +63 -40
- package/dist/schema/events.js +3 -3
- package/dist/schema/messages.d.ts +181 -32
- package/dist/schema/messages.js +65 -23
- package/dist/schema/options.d.ts +42 -30
- package/dist/schema/options.js +27 -56
- package/dist/speech.d.ts +3 -7
- package/dist/speech.js +1 -3
- package/dist/testing.d.ts +8 -8
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -9
- package/dist/transcription.d.ts +3 -8
- package/dist/transcription.js +1 -3
- package/dist/video.d.ts +3 -7
- package/dist/video.js +1 -3
- package/package.json +3 -3
|
@@ -1752,7 +1752,7 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1752
1752
|
readonly explanation?: string | undefined;
|
|
1753
1753
|
};
|
|
1754
1754
|
readonly usage?: Usage | undefined;
|
|
1755
|
-
readonly message?: import("../schema/messages.js").
|
|
1755
|
+
readonly message?: import("../schema/messages.js").AssistantMessage | undefined;
|
|
1756
1756
|
readonly providerMetadata?: {
|
|
1757
1757
|
readonly [x: string]: {
|
|
1758
1758
|
readonly [x: string]: unknown;
|
|
@@ -423,9 +423,7 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, adapter) {
|
|
|
423
423
|
const lowerUserContent = Effect.fnUntraced(function* (part, request, adapter) {
|
|
424
424
|
if (part.type === "text")
|
|
425
425
|
return { type: "input_text", text: part.text };
|
|
426
|
-
|
|
427
|
-
return yield* lowerMedia(part, request, adapter);
|
|
428
|
-
return yield* ProviderShared.unsupportedContent(adapter.name, "user", ["text", "media"]);
|
|
426
|
+
return yield* lowerMedia(part, request, adapter);
|
|
429
427
|
});
|
|
430
428
|
// Tool results may carry structured text, images, and files. Keep media as provider-native
|
|
431
429
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
@@ -450,7 +448,9 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
450
448
|
const custom = OpenAIFreeform.tools(request);
|
|
451
449
|
const customTool = (part) => part.namespace === undefined ? custom.get(part.name) : undefined;
|
|
452
450
|
for (const message of request.messages) {
|
|
453
|
-
const rawMetadata = message.
|
|
451
|
+
const rawMetadata = message.role === "user" || message.role === "assistant"
|
|
452
|
+
? message.providerMetadata?.[providerMetadataKey]
|
|
453
|
+
: undefined;
|
|
454
454
|
const metadata = rawMetadata === undefined ? undefined : yield* decodeMessageMetadata(rawMetadata);
|
|
455
455
|
if (message.role === "system") {
|
|
456
456
|
const update = effortUpdate(message);
|
|
@@ -588,8 +588,6 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
588
588
|
continue;
|
|
589
589
|
}
|
|
590
590
|
for (const part of message.content) {
|
|
591
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
592
|
-
return yield* ProviderShared.unsupportedContent(adapter.name, "tool", ["tool-result"]);
|
|
593
591
|
input.push({
|
|
594
592
|
type: customTool(part) ? "custom_tool_call_output" : "function_call_output",
|
|
595
593
|
call_id: part.id,
|
|
@@ -3,7 +3,7 @@ import { Route } from "../route/client.js";
|
|
|
3
3
|
import { Framing } from "../route/framing.js";
|
|
4
4
|
import { HttpTransport } from "../route/transport/index.js";
|
|
5
5
|
import { Protocol } from "../route/protocol.js";
|
|
6
|
-
import { AIError, LLMEvent, Usage, type FinishReasonDetails, type CacheHint, type LLMRequest } from "../schema/index.js";
|
|
6
|
+
import { AIError, LLMEvent, Usage, type FinishReasonDetails, type AssistantMessage, type CacheHint, type LLMRequest } from "../schema/index.js";
|
|
7
7
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
8
8
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
9
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
@@ -704,7 +704,7 @@ interface LoweringOptions {
|
|
|
704
704
|
readonly cacheControl?: (cache: CacheHint | undefined) => OpenAIChatCacheControl | undefined;
|
|
705
705
|
readonly toolCallID?: (id: string) => string;
|
|
706
706
|
/** Project provider-specific fields from the exact source, even when other messages are dropped during lowering. */
|
|
707
|
-
readonly assistant?: (source:
|
|
707
|
+
readonly assistant?: (source: AssistantMessage, message: OpenAIChatMessage) => OpenAIChatMessage;
|
|
708
708
|
}
|
|
709
709
|
export declare const fromRequest: (request: LLMRequest<import("../schema/options.js").LanguageModel<{
|
|
710
710
|
readonly [x: string]: unknown;
|
|
@@ -1917,7 +1917,7 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1917
1917
|
readonly explanation?: string | undefined;
|
|
1918
1918
|
};
|
|
1919
1919
|
readonly usage?: Usage | undefined;
|
|
1920
|
-
readonly message?:
|
|
1920
|
+
readonly message?: AssistantMessage | undefined;
|
|
1921
1921
|
readonly providerMetadata?: {
|
|
1922
1922
|
readonly [x: string]: {
|
|
1923
1923
|
readonly [x: string]: unknown;
|
|
@@ -8,7 +8,7 @@ import { HttpTransport } from "../route/transport/index.js";
|
|
|
8
8
|
import { Protocol } from "../route/protocol.js";
|
|
9
9
|
import { AIError, AIErrorReason, InvalidProviderOutputError, LLMEvent, ProviderInternalError, UnknownProviderError, Usage, } from "../schema/index.js";
|
|
10
10
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
11
|
-
import {
|
|
11
|
+
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
12
12
|
import { placesMarkers, requestTTL } from "../cache-policy.js";
|
|
13
13
|
import * as Cache from "./utils/cache.js";
|
|
14
14
|
import { resolveParallelToolCalls } from "./open-responses.js";
|
|
@@ -325,20 +325,17 @@ const lowerMedia = Effect.fnUntraced(function* (part) {
|
|
|
325
325
|
return { type: "video_url", video_url: { url } };
|
|
326
326
|
return { type: "image_url", image_url: { url } };
|
|
327
327
|
});
|
|
328
|
-
const openAICompatibleReasoningContent = (native) => isRecord(native) && typeof native.reasoning_content === "string" ? native.reasoning_content : undefined;
|
|
329
328
|
const reasoningField = (part, providerMetadataKey) => {
|
|
330
329
|
const field = part.providerMetadata?.[providerMetadataKey]?.reasoningField;
|
|
331
330
|
return typeof field === "string" ? field : undefined;
|
|
332
331
|
};
|
|
333
|
-
const reasoningDetails = (parts,
|
|
332
|
+
const reasoningDetails = (parts, providerMetadataKey) => {
|
|
334
333
|
const observed = parts.flatMap((part) => {
|
|
335
334
|
const details = part.providerMetadata?.[providerMetadataKey]?.reasoningDetails;
|
|
336
335
|
return Array.isArray(details) ? details : [];
|
|
337
336
|
});
|
|
338
337
|
if (parts.some((part) => Array.isArray(part.providerMetadata?.[providerMetadataKey]?.reasoningDetails)))
|
|
339
338
|
return knownReasoningDetails(observed).map(lowerReasoningDetail);
|
|
340
|
-
if (isRecord(native) && Array.isArray(native.reasoning_details))
|
|
341
|
-
return knownReasoningDetails(native.reasoning_details).map(lowerReasoningDetail);
|
|
342
339
|
};
|
|
343
340
|
// Kimi rejects its stream-only `index` on requests
|
|
344
341
|
// ("the reasoning_details ... must not contain streaming index").
|
|
@@ -361,7 +358,6 @@ const lowerUserMessage = Effect.fnUntraced(function* (message, options) {
|
|
|
361
358
|
content.push(yield* lowerMedia(part));
|
|
362
359
|
continue;
|
|
363
360
|
}
|
|
364
|
-
return yield* ProviderShared.unsupportedContent("OpenAI Chat", "user", ["text", "media"]);
|
|
365
361
|
}
|
|
366
362
|
if (content.every((part) => part.type === "text" && part.cache_control === undefined))
|
|
367
363
|
return {
|
|
@@ -391,21 +387,18 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
391
387
|
}
|
|
392
388
|
}
|
|
393
389
|
const text = reasoning.map((part) => part.text).join("");
|
|
394
|
-
const details = reasoningDetails(reasoning,
|
|
390
|
+
const details = reasoningDetails(reasoning, options.providerMetadataKey);
|
|
395
391
|
const observedField = reasoning
|
|
396
392
|
.map((part) => reasoningField(part, options.providerMetadataKey))
|
|
397
393
|
.find((value) => value !== undefined);
|
|
398
|
-
const nativeReasoning = openAICompatibleReasoningContent(message.native?.openaiCompatible);
|
|
399
394
|
const fullyStructured = reasoning.every((part) => Array.isArray(part.providerMetadata?.[options.providerMetadataKey]?.reasoningDetails));
|
|
400
395
|
const field = (() => {
|
|
401
|
-
if (configuredField !== undefined && (requireReasoning || reasoning.length > 0
|
|
396
|
+
if (configuredField !== undefined && (requireReasoning || reasoning.length > 0))
|
|
402
397
|
return configuredField;
|
|
403
398
|
if (reasoning.length === 0)
|
|
404
399
|
return requireReasoning ? "reasoning_content" : undefined;
|
|
405
400
|
if (observedField !== undefined)
|
|
406
401
|
return observedField;
|
|
407
|
-
if (nativeReasoning !== undefined)
|
|
408
|
-
return "reasoning_content";
|
|
409
402
|
if (!fullyStructured || requireReasoning)
|
|
410
403
|
return "reasoning_content";
|
|
411
404
|
// Kimi always expects `reasoning_content` on replayed assistant messages,
|
|
@@ -413,13 +406,7 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
413
406
|
if (details?.some(isKimiDetail))
|
|
414
407
|
return "reasoning_content";
|
|
415
408
|
})();
|
|
416
|
-
const reasoningText = (
|
|
417
|
-
if (configuredField !== undefined)
|
|
418
|
-
return reasoning.length === 0 ? (nativeReasoning ?? (requireReasoning ? "" : undefined)) : text;
|
|
419
|
-
if (reasoning.length === 0)
|
|
420
|
-
return nativeReasoning ?? (requireReasoning ? "" : undefined);
|
|
421
|
-
return text;
|
|
422
|
-
})();
|
|
409
|
+
const reasoningText = reasoning.length === 0 ? (requireReasoning ? "" : undefined) : text;
|
|
423
410
|
const result = {
|
|
424
411
|
role: "assistant",
|
|
425
412
|
content: (() => {
|
|
@@ -440,8 +427,6 @@ const lowerToolMessages = Effect.fnUntraced(function* (message, options) {
|
|
|
440
427
|
const messages = [];
|
|
441
428
|
const attachments = [];
|
|
442
429
|
for (const part of message.content) {
|
|
443
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
444
|
-
return yield* ProviderShared.unsupportedContent("OpenAI Chat", "tool", ["tool-result"]);
|
|
445
430
|
if (part.result.type !== "content") {
|
|
446
431
|
messages.push(toolMessage(options.toolCallID?.(part.id) ?? part.id, ProviderShared.toolResultText(part), options.cacheControl?.(part.cache)));
|
|
447
432
|
continue;
|
|
@@ -463,11 +448,8 @@ const toolMessage = (toolCallID, text, cacheControl) => ({
|
|
|
463
448
|
const lowerMessage = Effect.fnUntraced(function* (message, reasoningField, requireReasoning, options) {
|
|
464
449
|
if (message.role === "user")
|
|
465
450
|
return [yield* lowerUserMessage(message, options)];
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
return [options.assistant?.(message, lowered) ?? lowered];
|
|
469
|
-
}
|
|
470
|
-
return (yield* lowerToolMessages(message, options)).messages;
|
|
451
|
+
const lowered = yield* lowerAssistantMessage(message, reasoningField, requireReasoning, options);
|
|
452
|
+
return [options.assistant?.(message, lowered) ?? lowered];
|
|
471
453
|
});
|
|
472
454
|
const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
473
455
|
const system = request.system.length === 0
|
package/dist/protocols/shared.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool";
|
|
|
2
2
|
import { Effect, Option, Predicate, Schema, SchemaGetter, SchemaTransformation } from "effect";
|
|
3
3
|
import { Headers, HttpClientRequest } from "effect/http";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
|
-
import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, Message, ToolDefinition, } from "../schema/index.js";
|
|
5
|
+
import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, AssistantMessage, Message, ToolDefinition, ToolMessage, } from "../schema/index.js";
|
|
6
6
|
import { Json, decodeJson, encodeJson } from "../utils/json.js";
|
|
7
7
|
import { isRecord } from "../utils/record.js";
|
|
8
8
|
export { Json, decodeJson, encodeJson, isRecord };
|
|
@@ -260,14 +260,14 @@ export const flattenTools = (tools, path = []) => {
|
|
|
260
260
|
};
|
|
261
261
|
export const flattenToolRequest = (request) => {
|
|
262
262
|
const messages = request.messages.map((message) => {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
if (message.role === "assistant") {
|
|
264
|
+
const content = message.content.map((part) => part.type === "tool-call" || part.type === "tool-result" ? flattenToolName(part) : part);
|
|
265
|
+
return sameParts(content, message.content) ? message : new AssistantMessage({ ...message, content });
|
|
266
|
+
}
|
|
267
|
+
if (message.role !== "tool")
|
|
268
|
+
return message;
|
|
269
|
+
const content = message.content.map(flattenToolName);
|
|
270
|
+
return sameParts(content, message.content) ? message : new ToolMessage({ ...message, content });
|
|
271
271
|
});
|
|
272
272
|
return {
|
|
273
273
|
tools: flattenTools(request.tools),
|
|
@@ -276,6 +276,8 @@ export const flattenToolRequest = (request) => {
|
|
|
276
276
|
: { ...request, messages },
|
|
277
277
|
};
|
|
278
278
|
};
|
|
279
|
+
const flattenToolName = (part) => part.namespace === undefined ? part : { ...part, name: `${part.namespace}_${part.name}`, namespace: undefined };
|
|
280
|
+
const sameParts = (next, previous) => next.every((part, index) => part === previous[index]);
|
|
279
281
|
export const matchToolChoice = (route, toolChoice, cases) => Effect.gen(function* () {
|
|
280
282
|
if (toolChoice.type === "auto")
|
|
281
283
|
return cases.auto();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse,
|
|
2
|
+
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, Message, mergeJsonRecords, } from "../../schema/index.js";
|
|
3
3
|
import { stripEffortUpdates } from "../../effort-updates.js";
|
|
4
4
|
import { Endpoint } from "../../route/endpoint.js";
|
|
5
5
|
import { RequestExecutor } from "../../route/executor.js";
|
|
@@ -81,7 +81,7 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
81
81
|
const parts = yield* HttpTransport.jsonRequestParts({
|
|
82
82
|
request: {
|
|
83
83
|
...request,
|
|
84
|
-
http: request.http === undefined ? undefined :
|
|
84
|
+
http: request.http === undefined ? undefined : { ...request.http, body: undefined },
|
|
85
85
|
},
|
|
86
86
|
body,
|
|
87
87
|
endpoint: Endpoint.path(url.toString()),
|
|
@@ -93,7 +93,7 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
93
93
|
body: parts.bodyText,
|
|
94
94
|
headers: parts.headers,
|
|
95
95
|
encoding: request.http?.encoding,
|
|
96
|
-
}), options?.http);
|
|
96
|
+
}), RequestExecutor.withFetch(request.fetch, options?.http));
|
|
97
97
|
const text = yield* RequestExecutor.responseStream(response).pipe(Stream.decodeText(), Stream.runFold(() => "", (text, chunk) => text + chunk));
|
|
98
98
|
const invalid = (message, cause) => new AIError({
|
|
99
99
|
reason: new InvalidProviderOutputError({
|
|
@@ -252,7 +252,7 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
|
|
|
252
252
|
readonly explanation?: string | undefined;
|
|
253
253
|
};
|
|
254
254
|
readonly usage?: import("../../schema/events.js").Usage | undefined;
|
|
255
|
-
readonly message?: import("../../schema/messages.js").
|
|
255
|
+
readonly message?: import("../../schema/messages.js").AssistantMessage | undefined;
|
|
256
256
|
readonly providerMetadata?: {
|
|
257
257
|
readonly [x: string]: {
|
|
258
258
|
readonly [x: string]: unknown;
|
|
@@ -459,7 +459,7 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
|
|
|
459
459
|
readonly explanation?: string | undefined;
|
|
460
460
|
};
|
|
461
461
|
readonly usage?: import("../../schema/events.js").Usage | undefined;
|
|
462
|
-
readonly message?: import("../../schema/messages.js").
|
|
462
|
+
readonly message?: import("../../schema/messages.js").AssistantMessage | undefined;
|
|
463
463
|
readonly providerMetadata?: {
|
|
464
464
|
readonly [x: string]: {
|
|
465
465
|
readonly [x: string]: unknown;
|
|
@@ -6,7 +6,7 @@ export type Config = ProviderAuthOption<"optional"> & {
|
|
|
6
6
|
/** `https://api.eu.assemblyai.com` for the EU region. */
|
|
7
7
|
readonly baseURL?: string;
|
|
8
8
|
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions
|
|
9
|
+
readonly http?: HttpOptions;
|
|
10
10
|
};
|
|
11
11
|
export declare const configure: (input?: Config) => {
|
|
12
12
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
package/dist/providers/azure.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Auth } from "../route/auth.js";
|
|
|
2
2
|
import { AuthOptions } from "../route/auth-options.js";
|
|
3
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
4
4
|
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import {
|
|
5
|
+
import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
|
|
6
6
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
7
7
|
import { OpenAIImages } from "../protocols/openai-images.js";
|
|
8
8
|
import * as OpenAIChat from "../protocols/openai-chat.js";
|
|
@@ -97,7 +97,7 @@ export const configure = (input) => {
|
|
|
97
97
|
id: modelID,
|
|
98
98
|
provider: id,
|
|
99
99
|
providerOptions,
|
|
100
|
-
http:
|
|
100
|
+
http: { ...media.http, query: { ...media.http?.query, ...target.query } },
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
103
|
return {
|
|
@@ -5,7 +5,7 @@ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
|
5
5
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
6
|
readonly baseURL?: string;
|
|
7
7
|
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions
|
|
8
|
+
readonly http?: HttpOptions;
|
|
9
9
|
};
|
|
10
10
|
export declare const configure: (input?: Config) => {
|
|
11
11
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -6,7 +6,7 @@ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
|
6
6
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
7
7
|
readonly baseURL?: string;
|
|
8
8
|
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions
|
|
9
|
+
readonly http?: HttpOptions;
|
|
10
10
|
};
|
|
11
11
|
export declare const configure: (input?: Config) => {
|
|
12
12
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -6,7 +6,7 @@ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
|
6
6
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
7
7
|
readonly baseURL?: string;
|
|
8
8
|
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions
|
|
9
|
+
readonly http?: HttpOptions;
|
|
10
10
|
};
|
|
11
11
|
export declare const configure: (input?: Config) => {
|
|
12
12
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
package/dist/providers/openai.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthOptions } from "../route/auth-options.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ProviderID, ToolDefinition } from "../schema/index.js";
|
|
4
4
|
import * as OpenAIChat from "../protocols/openai-chat.js";
|
|
5
5
|
import * as OpenAIResponses from "../protocols/openai-responses.js";
|
|
6
6
|
import { withOpenAIOptions } from "./openai-options.js";
|
|
@@ -49,7 +49,7 @@ export const configure = (input = {}) => {
|
|
|
49
49
|
const deployment = MediaRoute.deployment(input, auth(input));
|
|
50
50
|
const media = {
|
|
51
51
|
...deployment,
|
|
52
|
-
http:
|
|
52
|
+
http: { ...deployment.http, query: { ...deployment.http?.query, ...input.queryParams } },
|
|
53
53
|
};
|
|
54
54
|
// The ChatGPT backend (ChatGPT sign-in) rejects multipart image edits with "Unsupported content type".
|
|
55
55
|
const imageInput = media.baseURL?.startsWith("https://chatgpt.com/") ? "json-edits" : undefined;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { HttpOptions, type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
1
|
+
import { type HttpOptions, type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
2
2
|
import type { ProviderPackage } from "../provider-package.js";
|
|
3
3
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
5
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
6
|
readonly baseURL?: string;
|
|
7
7
|
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions
|
|
8
|
+
readonly http?: HttpOptions;
|
|
9
9
|
};
|
|
10
10
|
export type Settings = ProviderPackage.Settings & {
|
|
11
11
|
readonly apiKey?: string | false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderID } from "../schema/index.js";
|
|
2
2
|
import { AuthOptions } from "../route/auth-options.js";
|
|
3
3
|
import { SystemOne } from "../protocols/system-one.js";
|
|
4
4
|
import { toConfig } from "./settings.js";
|
|
@@ -5,7 +5,7 @@ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
|
5
5
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
6
|
readonly baseURL?: string;
|
|
7
7
|
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions
|
|
8
|
+
readonly http?: HttpOptions;
|
|
9
9
|
};
|
|
10
10
|
export declare const configure: (input?: Config) => {
|
|
11
11
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { HttpOptions, type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
1
|
+
import { type HttpOptions, type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
2
2
|
import type { ProviderPackage } from "../provider-package.js";
|
|
3
3
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
5
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
6
|
readonly baseURL?: string;
|
|
7
7
|
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions
|
|
8
|
+
readonly http?: HttpOptions;
|
|
9
9
|
};
|
|
10
10
|
export type Settings = ProviderPackage.Settings & {
|
|
11
11
|
readonly apiKey?: string | false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderID } from "../schema/index.js";
|
|
2
2
|
import { AuthOptions } from "../route/auth-options.js";
|
|
3
3
|
import { SystemOne } from "../protocols/system-one.js";
|
|
4
4
|
import { toConfig } from "./settings.js";
|
package/dist/public.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
2
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding,
|
|
3
|
-
export type { GenerationOptionsFields, GenerationOptionsInput, LanguageModelInput, LanguageModelProviderOptions, LLMRequest, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, UsageInput, } from "./schema/index.js";
|
|
2
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishReasonDetails, StepFinish, Finish, MediaEvent, RawEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
|
+
export type { BaseRequest, ContentPartInput, GenerationOptionsFields, GenerationOptionsInput, HttpOptions, LanguageModelInput, LanguageModelProviderOptions, LLMRequest, MediaPartInput, RequestTimeout, TimeoutConfig, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, TransportOptions, UsageInput, } from "./schema/index.js";
|
|
4
4
|
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
5
5
|
export type { ImageModelOptions, ImageOptions, ImageRequest, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
|
6
6
|
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
7
|
-
export type { AnswerFor, AnswersFor, DecisionInput, DecisionModelOptions, DecisionOptions, DecisionQuestions, DecisionRequest, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
7
|
+
export type { AnswerFor, AnswersFor, DecisionInput, DecisionMediaPartInput, DecisionModelOptions, DecisionOptions, DecisionPartInput, DecisionQuestions, DecisionRequest, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
8
8
|
export { Media } from "./media.js";
|
|
9
9
|
export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
|
|
10
10
|
export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolModelOutputInput, ToolOptions, ToolSchema, ToolToModelOutput, } from "./tool.js";
|
package/dist/public.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
2
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding,
|
|
2
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishReasonDetails, StepFinish, Finish, MediaEvent, RawEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
3
|
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
4
4
|
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
5
5
|
export { Media } from "./media.js";
|
package/dist/route/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { HttpMiddleware, Transport, TransportRuntime, WebSocketChannelExecu
|
|
|
8
8
|
import type { Protocol } from "./protocol.js";
|
|
9
9
|
import type { LanguageModelSanitizerCompatibility, ProtocolID, ProviderOptions } from "../schema/index.js";
|
|
10
10
|
import type { LLMRequestInput } from "../llm.js";
|
|
11
|
-
import { AIError, CompactionResponse, CompactionCheckpointResponse, GenerationOptions,
|
|
11
|
+
import { AIError, CompactionResponse, CompactionCheckpointResponse, GenerationOptions, LLMResponse, LanguageModel, LLMEvent, ProviderID, type LLMRequest, type TransportOptions } from "../schema/index.js";
|
|
12
12
|
export interface RouteBody<Body> {
|
|
13
13
|
/** Schema for the validated provider-native body sent as the JSON request. */
|
|
14
14
|
readonly schema: Schema.Codec<Body, unknown>;
|
|
@@ -49,17 +49,13 @@ export interface Route<Body, Prepared = unknown, Compact extends CompactionOpera
|
|
|
49
49
|
export type AnyRoute<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Route<any, any, Compact>;
|
|
50
50
|
export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "route">;
|
|
51
51
|
export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">;
|
|
52
|
-
export interface RouteDefaults {
|
|
53
|
-
readonly headers?: Record<string, string>;
|
|
52
|
+
export interface RouteDefaults extends TransportOptions {
|
|
54
53
|
readonly generation?: GenerationOptions;
|
|
55
54
|
readonly providerOptions?: ProviderOptions;
|
|
56
|
-
readonly http?: HttpOptions;
|
|
57
55
|
}
|
|
58
|
-
export interface RouteDefaultsInput {
|
|
59
|
-
readonly headers?: Record<string, string>;
|
|
56
|
+
export interface RouteDefaultsInput extends TransportOptions {
|
|
60
57
|
readonly generation?: GenerationOptions.Input;
|
|
61
58
|
readonly providerOptions?: ProviderOptions;
|
|
62
|
-
readonly http?: HttpOptions.Input;
|
|
63
59
|
}
|
|
64
60
|
export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
|
|
65
61
|
readonly compact?: CompactionOperations;
|
package/dist/route/client.js
CHANGED
|
@@ -10,7 +10,7 @@ import { normalizeToolHistory } from "../tool-history.js";
|
|
|
10
10
|
import { sanitizeSurrogates } from "../utils/sanitize.js";
|
|
11
11
|
import * as ProviderShared from "../protocols/shared.js";
|
|
12
12
|
import { ToolSchemaProjection } from "../protocols/utils/tool-schema.js";
|
|
13
|
-
import { AIError, CompactionResponse, CompactionCheckpointResponse, AIErrorReason, GenerationOptions,
|
|
13
|
+
import { AIError, CompactionResponse, CompactionCheckpointResponse, AIErrorReason, GenerationOptions, LLMResponse, ResponseFold, LanguageModel, Message, LLMEvent, InvalidProviderOutputError, ProviderConfigurationError, ProviderID, ToolChoice, ToolEntry, mergeGenerationOptions, mergeProviderOptions, mergeTransport, withPartial, } from "../schema/index.js";
|
|
14
14
|
const makeRouteLanguageModel = (route, mapped) => {
|
|
15
15
|
const provider = route.provider ?? ("provider" in mapped ? mapped.provider : undefined);
|
|
16
16
|
if (!provider)
|
|
@@ -26,23 +26,13 @@ const makeRouteLanguageModel = (route, mapped) => {
|
|
|
26
26
|
route,
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
const mergeRouteDefaults = (base, patch) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
|
|
37
|
-
http: mergeHttpOptions(base?.http, HttpOptions.make(patch.http), headers === undefined ? undefined : new HttpOptions({ headers })),
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const mergeHeaders = (...items) => {
|
|
41
|
-
const entries = items.flatMap((item) => item === undefined ? [] : Object.entries(item).filter((entry) => entry[1] !== undefined));
|
|
42
|
-
if (entries.length === 0)
|
|
43
|
-
return undefined;
|
|
44
|
-
return Object.fromEntries(entries);
|
|
45
|
-
};
|
|
29
|
+
const mergeRouteDefaults = (base, patch) => ({
|
|
30
|
+
...base,
|
|
31
|
+
...patch,
|
|
32
|
+
...mergeTransport(base, patch),
|
|
33
|
+
generation: mergeGenerationOptions(base?.generation, patch.generation),
|
|
34
|
+
providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
|
|
35
|
+
});
|
|
46
36
|
export function canCompact(target, options) {
|
|
47
37
|
const model = target instanceof LanguageModel ? target : target.model;
|
|
48
38
|
if (options?.mechanism === "trigger")
|
|
@@ -74,7 +64,7 @@ const resolveRequestOptions = (request) => {
|
|
|
74
64
|
...normalized,
|
|
75
65
|
generation: generation ?? new GenerationOptions({}),
|
|
76
66
|
providerOptions: mergeProviderOptions(routeDefaults.providerOptions, modelDefaults?.providerOptions, normalized.providerOptions),
|
|
77
|
-
|
|
67
|
+
...mergeTransport(routeDefaults, modelDefaults, normalized),
|
|
78
68
|
};
|
|
79
69
|
};
|
|
80
70
|
const streamError = (route, message, cause) => {
|
|
@@ -150,7 +140,7 @@ function makeFromTransport(input) {
|
|
|
150
140
|
endpoint: routeInput.endpoint,
|
|
151
141
|
auth: routeInput.auth ?? Auth.none,
|
|
152
142
|
encodeBody: ProviderShared.encodeJson,
|
|
153
|
-
middleware: options?.http,
|
|
143
|
+
middleware: RequestExecutor.withFetch(request.fetch, options?.http),
|
|
154
144
|
webSocket: options?.webSocket,
|
|
155
145
|
}),
|
|
156
146
|
streamPrepared: (prepared, request, runtime, options) => {
|
|
@@ -222,9 +212,7 @@ const prepareRequest = (request) => {
|
|
|
222
212
|
const dedupe = (tools) => [...new Map(tools.map((tool) => [`${tool.type}:${tool.name}`, tool])).values()].map((tool) => tool.type === "tool" ? tool : { ...tool, tools: dedupe(tool.tools) });
|
|
223
213
|
const resolved = applyCachePolicy(applyEffortUpdates({ ...sanitized, tools: ToolSchemaProjection.tools(dedupe(sanitized.tools), sanitized.model) }));
|
|
224
214
|
const headers = resolved.model.route.headers?.({ request: resolved });
|
|
225
|
-
return headers === undefined
|
|
226
|
-
? resolved
|
|
227
|
-
: { ...resolved, http: mergeHttpOptions(new HttpOptions({ headers }), resolved.http) };
|
|
215
|
+
return headers === undefined ? resolved : { ...resolved, headers: { ...headers, ...resolved.headers } };
|
|
228
216
|
};
|
|
229
217
|
// Sanitizing copies changed class instances into plain records; rebuild them so protocols see the canonical classes.
|
|
230
218
|
const restoreClasses = (request) => ({
|
|
@@ -233,7 +221,6 @@ const restoreClasses = (request) => ({
|
|
|
233
221
|
tools: request.tools.map(ToolEntry.make),
|
|
234
222
|
toolChoice: request.toolChoice === undefined ? undefined : ToolChoice.make(request.toolChoice),
|
|
235
223
|
generation: request.generation === undefined ? undefined : GenerationOptions.make(request.generation),
|
|
236
|
-
http: HttpOptions.make(request.http),
|
|
237
224
|
});
|
|
238
225
|
const compile = Effect.fn("LLM.compile")(function* (request, options) {
|
|
239
226
|
const references = request.messages.flatMap((message) => message.content.flatMap((part) => {
|
package/dist/route/decision.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import type { HttpClientResponse } from "effect/http";
|
|
3
3
|
import { DecisionModel, DecisionModelCompatibility, type DecisionOptions, type DecisionRequest, type DecisionResponse } from "../decision.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ProviderID, type HttpOptions, type AIError, type ProviderOptions } from "../schema/index.js";
|
|
5
5
|
import { Auth } from "./auth.js";
|
|
6
6
|
import { Endpoint } from "./endpoint.js";
|
|
7
7
|
import { MediaProtocol } from "./media-protocol.js";
|
|
@@ -30,7 +30,7 @@ export interface Patch {
|
|
|
30
30
|
readonly endpoint?: Endpoint.EndpointPatch<MediaProtocol.Body, DecisionRequest>;
|
|
31
31
|
readonly auth?: Auth.Definition;
|
|
32
32
|
readonly headers?: Record<string, string>;
|
|
33
|
-
readonly http?: HttpOptions
|
|
33
|
+
readonly http?: HttpOptions;
|
|
34
34
|
}
|
|
35
35
|
export interface Route {
|
|
36
36
|
readonly id: string;
|
package/dist/route/decision.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { DecisionModel, DecisionModelCompatibility, } from "../decision.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ProviderID } from "../schema/index.js";
|
|
4
4
|
import { Auth } from "./auth.js";
|
|
5
5
|
import { Endpoint } from "./endpoint.js";
|
|
6
6
|
import { RequestExecutorService } from "./executor-service.js";
|
|
@@ -17,7 +17,7 @@ export const make = (input) => {
|
|
|
17
17
|
endpoint: input.endpoint,
|
|
18
18
|
auth: input.auth ?? Auth.none,
|
|
19
19
|
headers: input.headers,
|
|
20
|
-
http:
|
|
20
|
+
http: input.http,
|
|
21
21
|
};
|
|
22
22
|
return {
|
|
23
23
|
...route,
|
|
@@ -28,7 +28,7 @@ export const make = (input) => {
|
|
|
28
28
|
providerMetadataKey: patch.providerMetadataKey ?? (patch.provider === undefined ? route.providerMetadataKey : undefined),
|
|
29
29
|
endpoint: patch.endpoint === undefined ? route.endpoint : Endpoint.merge(route.endpoint, patch.endpoint),
|
|
30
30
|
headers: patch.headers === undefined ? route.headers : { ...route.headers, ...patch.headers },
|
|
31
|
-
http: patch.http
|
|
31
|
+
http: patch.http ?? route.http,
|
|
32
32
|
}),
|
|
33
33
|
model: (model) => {
|
|
34
34
|
const send = transport(route);
|
package/dist/route/executor.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ export declare const responseStream: (response: HttpClientResponse.HttpClientRes
|
|
|
18
18
|
export declare const stream: (executor: Interface, request: HttpClientRequest.HttpClientRequest, middleware?: HttpMiddleware) => Stream.Stream<Uint8Array, AIError>;
|
|
19
19
|
export declare const layer: Layer.Layer<Service, never, HttpClient.HttpClient>;
|
|
20
20
|
export declare const fetchLayer: Layer.Layer<import("./executor-service.js").RequestExecutorService, never, never>;
|
|
21
|
+
/**
|
|
22
|
+
* Per-call middleware that sends through `fetch` instead of the executor's HTTP client. Executor middleware and
|
|
23
|
+
* `middleware` still wrap the call, and status classification still applies.
|
|
24
|
+
*/
|
|
25
|
+
export declare const withFetch: (fetch: typeof globalThis.fetch | undefined, middleware?: HttpMiddleware) => HttpMiddleware | undefined;
|
|
21
26
|
/** Run `fn` on every request: it sees the raw response before status classification, inside middleware already on `executor`, and outside per-call middleware. */
|
|
22
27
|
export declare const middleware: (fn: HttpMiddleware, executor?: Layer.Layer<Service>) => Layer.Layer<Service>;
|
|
23
28
|
export * as RequestExecutor from "./executor.js";
|
package/dist/route/executor.js
CHANGED
|
@@ -186,6 +186,16 @@ export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
186
186
|
});
|
|
187
187
|
}));
|
|
188
188
|
export const fetchLayer = layer.pipe(Layer.provide(FetchHttpClient.layer));
|
|
189
|
+
/**
|
|
190
|
+
* Per-call middleware that sends through `fetch` instead of the executor's HTTP client. Executor middleware and
|
|
191
|
+
* `middleware` still wrap the call, and status classification still applies.
|
|
192
|
+
*/
|
|
193
|
+
export const withFetch = (fetch, middleware) => {
|
|
194
|
+
if (fetch === undefined)
|
|
195
|
+
return middleware;
|
|
196
|
+
const send = (request) => HttpClient.execute(request).pipe(Effect.provide(FetchHttpClient.layer), Effect.provideService(FetchHttpClient.Fetch, fetch));
|
|
197
|
+
return middleware === undefined ? send : (request) => middleware(request, send);
|
|
198
|
+
};
|
|
189
199
|
/** Run `fn` on every request: it sees the raw response before status classification, inside middleware already on `executor`, and outside per-call middleware. */
|
|
190
200
|
export const middleware = (fn, executor = fetchLayer) => Layer.effect(Service, Effect.gen(function* () {
|
|
191
201
|
const inner = yield* Service;
|
package/dist/route/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { HttpTransport, WebSocketTransport } from "./transport/index.js";
|
|
|
12
12
|
export * as Transport from "./transport/index.js";
|
|
13
13
|
export { ProviderShared } from "../protocols/shared.js";
|
|
14
14
|
export { classifyProviderFailure } from "../provider-error.js";
|
|
15
|
-
export {
|
|
15
|
+
export { mergeTransport } from "../schema/index.js";
|
|
16
16
|
export type { AuthInput, Credential, CredentialError } from "./auth.js";
|
|
17
17
|
export type { ApiKeyMode, AuthOverride, ProviderAuthOption } from "./auth-options.js";
|
|
18
18
|
export type { EndpointInput } from "./endpoint.js";
|