@opencode-ai/ai 0.0.0-next-16671 → 0.0.0-next-16680
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 +1 -1
- package/dist/image-client.d.ts +4 -4
- package/dist/image.d.ts +4 -4
- package/dist/image.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/llm.d.ts +11 -11
- package/dist/llm.js +3 -3
- package/dist/protocols/anthropic-messages.js +8 -4
- package/dist/protocols/bedrock-converse.js +3 -5
- package/dist/protocols/google-images.js +2 -2
- package/dist/protocols/open-responses.d.ts +8 -8
- package/dist/protocols/open-responses.js +4 -9
- package/dist/protocols/openai-chat.d.ts +4 -4
- package/dist/protocols/openai-chat.js +3 -3
- package/dist/protocols/openai-compatible-chat.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-images.js +2 -2
- package/dist/protocols/shared.d.ts +16 -16
- package/dist/protocols/shared.js +6 -6
- package/dist/protocols/utils/bedrock-media.d.ts +1 -1
- package/dist/protocols/utils/image-input.d.ts +5 -5
- package/dist/protocols/utils/image-input.js +2 -2
- package/dist/protocols/utils/tool-schema.d.ts +2 -2
- package/dist/protocols/utils/tool-stream.d.ts +7 -7
- package/dist/protocols/utils/tool-stream.js +2 -2
- package/dist/protocols/xai-images.js +2 -2
- package/dist/protocols/zai-images.js +2 -2
- package/dist/provider-error.d.ts +2 -2
- package/dist/provider-error.js +2 -2
- package/dist/provider-package.d.ts +2 -2
- package/dist/provider.d.ts +8 -8
- package/dist/providers/amazon-bedrock.d.ts +7 -7
- package/dist/providers/anthropic-compatible.d.ts +6 -6
- package/dist/providers/anthropic.d.ts +7 -7
- package/dist/providers/azure.d.ts +13 -13
- package/dist/providers/cloudflare.d.ts +8 -8
- package/dist/providers/github-copilot.d.ts +15 -15
- package/dist/providers/google-vertex-chat.d.ts +6 -6
- package/dist/providers/google-vertex-messages.d.ts +6 -6
- package/dist/providers/google-vertex-responses.d.ts +6 -6
- package/dist/providers/google-vertex.d.ts +6 -6
- package/dist/providers/google.d.ts +7 -7
- package/dist/providers/openai-compatible-responses.d.ts +6 -6
- package/dist/providers/openai-compatible.d.ts +20 -20
- package/dist/providers/openai.d.ts +19 -19
- package/dist/providers/openrouter.d.ts +11 -11
- package/dist/providers/xai.d.ts +19 -19
- package/dist/providers/zai.d.ts +4 -4
- package/dist/route/auth-options.d.ts +3 -3
- package/dist/route/auth.d.ts +4 -4
- package/dist/route/auth.js +4 -4
- package/dist/route/client.d.ts +18 -18
- package/dist/route/client.js +6 -6
- package/dist/route/executor.d.ts +3 -3
- package/dist/route/executor.js +4 -4
- package/dist/route/framing.d.ts +2 -2
- package/dist/route/index.d.ts +1 -1
- package/dist/route/protocol.d.ts +3 -3
- package/dist/route/transport/http.d.ts +1 -1
- package/dist/route/transport/index.d.ts +3 -3
- package/dist/route/transport/websocket.d.ts +10 -10
- package/dist/route/transport/websocket.js +3 -3
- package/dist/schema/errors.d.ts +6 -6
- package/dist/schema/errors.js +18 -18
- package/dist/schema/events.js +1 -1
- package/dist/schema/ids.d.ts +3 -3
- package/dist/schema/ids.js +4 -3
- package/dist/schema/messages.d.ts +2 -2
- package/dist/schema/messages.js +2 -2
- package/dist/schema/options.d.ts +38 -38
- package/dist/schema/options.js +31 -29
- package/dist/testing.d.ts +4 -4
- package/package.json +3 -3
package/dist/route/client.js
CHANGED
|
@@ -8,14 +8,14 @@ import { HttpTransport } from "./transport";
|
|
|
8
8
|
import { WebSocketExecutor } from "./transport";
|
|
9
9
|
import { applyCachePolicy } from "../cache-policy";
|
|
10
10
|
import * as ProviderShared from "../protocols/shared";
|
|
11
|
-
import { GenerationOptions, HttpOptions, LLMRequest, LLMResponse,
|
|
12
|
-
const
|
|
11
|
+
import { AIError, GenerationOptions, HttpOptions, LLMRequest, LLMResponse, LanguageModel, LanguageModelLimits, LLMEvent, ProviderID, mergeGenerationOptions, mergeHttpOptions, mergeProviderOptions, } from "../schema";
|
|
12
|
+
const makeRouteLanguageModel = (route, mapped) => {
|
|
13
13
|
const provider = route.provider ?? ("provider" in mapped ? mapped.provider : undefined);
|
|
14
14
|
if (!provider)
|
|
15
15
|
throw new Error(`Route.model(${route.id}) requires a provider`);
|
|
16
16
|
if (!endpointBaseURL(route.endpoint))
|
|
17
17
|
throw new Error(`Route.model(${route.id}) requires an endpoint baseURL — configure it on the route first`);
|
|
18
|
-
return
|
|
18
|
+
return LanguageModel.make({
|
|
19
19
|
...mapped,
|
|
20
20
|
provider,
|
|
21
21
|
route,
|
|
@@ -27,7 +27,7 @@ const mergeRouteDefaults = (base, patch) => {
|
|
|
27
27
|
...base,
|
|
28
28
|
...patch,
|
|
29
29
|
headers,
|
|
30
|
-
limits: patch.limits === undefined ? base?.limits :
|
|
30
|
+
limits: patch.limits === undefined ? base?.limits : LanguageModelLimits.make(patch.limits),
|
|
31
31
|
generation: mergeGenerationOptions(generationOptions(base?.generation), generationOptions(patch.generation)),
|
|
32
32
|
providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
|
|
33
33
|
http: mergeHttpOptions(base?.http, httpOptions(patch.http), headers === undefined ? undefined : new HttpOptions({ headers })),
|
|
@@ -60,7 +60,7 @@ const resolveRequestOptions = (request) => {
|
|
|
60
60
|
};
|
|
61
61
|
const streamError = (route, message, cause) => {
|
|
62
62
|
const failed = cause.reasons.find(Cause.isFailReason)?.error;
|
|
63
|
-
if (failed instanceof
|
|
63
|
+
if (failed instanceof AIError)
|
|
64
64
|
return failed;
|
|
65
65
|
return ProviderShared.eventError(route, message, Cause.pretty(cause));
|
|
66
66
|
};
|
|
@@ -104,7 +104,7 @@ function makeFromTransport(input) {
|
|
|
104
104
|
defaults: mergeRouteDefaults(route.defaults, defaults),
|
|
105
105
|
});
|
|
106
106
|
},
|
|
107
|
-
model: (input) =>
|
|
107
|
+
model: (input) => makeRouteLanguageModel(route, input),
|
|
108
108
|
prepareTransport: (body, request, options) => routeInput.transport.prepare({
|
|
109
109
|
body,
|
|
110
110
|
request,
|
package/dist/route/executor.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from "effect";
|
|
2
2
|
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
|
|
3
|
-
import {
|
|
3
|
+
import { AIError } from "../schema";
|
|
4
4
|
export interface Interface {
|
|
5
|
-
readonly execute: (request: HttpClientRequest.HttpClientRequest) => Effect.Effect<HttpClientResponse.HttpClientResponse,
|
|
5
|
+
readonly execute: (request: HttpClientRequest.HttpClientRequest) => Effect.Effect<HttpClientResponse.HttpClientResponse, AIError>;
|
|
6
6
|
}
|
|
7
|
-
declare const Service_base: Context.ServiceClass<Service, "@opencode/
|
|
7
|
+
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/RequestExecutor", Interface>;
|
|
8
8
|
export declare class Service extends Service_base {
|
|
9
9
|
}
|
|
10
10
|
export declare const layer: Layer.Layer<Service, never, HttpClient.HttpClient>;
|
package/dist/route/executor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Cause, Context, Effect, Layer } from "effect";
|
|
2
2
|
import { FetchHttpClient, Headers, HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse, } from "effect/unstable/http";
|
|
3
|
-
import { HttpContext, HttpRateLimitDetails, HttpRequestDetails, HttpResponseDetails,
|
|
3
|
+
import { HttpContext, HttpRateLimitDetails, HttpRequestDetails, HttpResponseDetails, AIError, TransportReason, } from "../schema";
|
|
4
4
|
import { classifyProviderFailure } from "../provider-error";
|
|
5
|
-
export class Service extends Context.Service()("@opencode/
|
|
5
|
+
export class Service extends Context.Service()("@opencode/AI/RequestExecutor") {
|
|
6
6
|
}
|
|
7
7
|
const BODY_LIMIT = 16_384;
|
|
8
8
|
const REDACTED = "<redacted>";
|
|
@@ -163,7 +163,7 @@ const statusError = (request, redactedNames) => (response) => Effect.gen(functio
|
|
|
163
163
|
const retryAfter = retryAfterMs(headers);
|
|
164
164
|
const rateLimit = rateLimitDetails(headers, retryAfter);
|
|
165
165
|
const details = responseBody(body, request);
|
|
166
|
-
return yield* new
|
|
166
|
+
return yield* new AIError({
|
|
167
167
|
module: "RequestExecutor",
|
|
168
168
|
method: "execute",
|
|
169
169
|
reason: classifyProviderFailure({
|
|
@@ -183,7 +183,7 @@ const statusError = (request, redactedNames) => (response) => Effect.gen(functio
|
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
185
|
const toHttpError = (redactedNames) => (error) => {
|
|
186
|
-
const transportError = (input) => new
|
|
186
|
+
const transportError = (input) => new AIError({
|
|
187
187
|
module: "RequestExecutor",
|
|
188
188
|
method: "execute",
|
|
189
189
|
reason: new TransportReason({
|
package/dist/route/framing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Stream } from "effect";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AIError } from "../schema";
|
|
3
3
|
/**
|
|
4
4
|
* Decode a streaming HTTP response body into provider-protocol frames.
|
|
5
5
|
*
|
|
@@ -16,7 +16,7 @@ import type { LLMError } from "../schema";
|
|
|
16
16
|
*/
|
|
17
17
|
export interface Definition<Frame> {
|
|
18
18
|
readonly id: string;
|
|
19
|
-
readonly frame: (bytes: Stream.Stream<Uint8Array,
|
|
19
|
+
readonly frame: (bytes: Stream.Stream<Uint8Array, AIError>) => Stream.Stream<Frame, AIError>;
|
|
20
20
|
}
|
|
21
21
|
/** Server-Sent Events framing. Used by every JSON-streaming HTTP provider. */
|
|
22
22
|
export declare const sse: Definition<string>;
|
package/dist/route/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Route, LLMClient } from "./client";
|
|
2
|
-
export type { Route as RouteShape,
|
|
2
|
+
export type { Route as RouteShape, RouteLanguageModelInput, RouteRoutedLanguageModelInput, RouteDefaults, RouteDefaultsInput, AnyRoute, Interface as LLMClientShape, Service as LLMClientService, StreamOptions, } from "./client";
|
|
3
3
|
export * from "./executor";
|
|
4
4
|
export { Auth } from "./auth";
|
|
5
5
|
export { AuthOptions } from "./auth-options";
|
package/dist/route/protocol.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema, type Effect } from "effect";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AIError, LLMEvent, LLMRequest, ProtocolID } from "../schema";
|
|
3
3
|
/**
|
|
4
4
|
* The semantic API contract of one model server family.
|
|
5
5
|
*
|
|
@@ -45,7 +45,7 @@ export interface ProtocolBody<Body> {
|
|
|
45
45
|
/** Schema for the validated provider-native body sent as the JSON request. */
|
|
46
46
|
readonly schema: Schema.Codec<Body, unknown>;
|
|
47
47
|
/** Build the provider-native body from a common `LLMRequest`. */
|
|
48
|
-
readonly from: (request: LLMRequest) => Effect.Effect<Body,
|
|
48
|
+
readonly from: (request: LLMRequest) => Effect.Effect<Body, AIError>;
|
|
49
49
|
}
|
|
50
50
|
export interface ProtocolStream<Frame, Event, State> {
|
|
51
51
|
/** Schema for one decoded streaming event, decoded from a transport frame. */
|
|
@@ -53,7 +53,7 @@ export interface ProtocolStream<Frame, Event, State> {
|
|
|
53
53
|
/** Initial parser state. Called once per response with the resolved request. */
|
|
54
54
|
readonly initial: (request: LLMRequest) => State;
|
|
55
55
|
/** Translate one event into emitted `LLMEvent`s plus the next state. */
|
|
56
|
-
readonly step: (state: State, event: Event) => Effect.Effect<readonly [State, ReadonlyArray<LLMEvent>],
|
|
56
|
+
readonly step: (state: State, event: Event) => Effect.Effect<readonly [State, ReadonlyArray<LLMEvent>], AIError>;
|
|
57
57
|
/** Optional request-completion signal for transports that do not end naturally. */
|
|
58
58
|
readonly terminal?: (event: Event) => boolean;
|
|
59
59
|
/** Optional flush emitted when the framed stream ends. */
|
|
@@ -18,7 +18,7 @@ export declare const jsonRequestParts: <Body>(input: JsonRequestInput<Body>) =>
|
|
|
18
18
|
jsonBody: Record<string, unknown> | Body;
|
|
19
19
|
bodyText: string;
|
|
20
20
|
headers: Headers.Headers;
|
|
21
|
-
}, import("../..").
|
|
21
|
+
}, import("../..").AIError, never>;
|
|
22
22
|
export interface HttpJsonInput<_Body, Frame> {
|
|
23
23
|
readonly framing: Framing.Definition<Frame>;
|
|
24
24
|
}
|
|
@@ -3,7 +3,7 @@ import { Endpoint } from "../endpoint";
|
|
|
3
3
|
import { Auth } from "../auth";
|
|
4
4
|
import type { Interface as RequestExecutorInterface } from "../executor";
|
|
5
5
|
import type { Interface as WebSocketExecutorInterface } from "./websocket";
|
|
6
|
-
import type {
|
|
6
|
+
import type { AIError, LLMRequest } from "../../schema";
|
|
7
7
|
export interface TransportRuntime {
|
|
8
8
|
readonly http: RequestExecutorInterface;
|
|
9
9
|
readonly webSocket?: WebSocketExecutorInterface;
|
|
@@ -17,8 +17,8 @@ export interface HttpRequest {
|
|
|
17
17
|
export type HttpRequestTransform = (request: HttpRequest) => Effect.Effect<void>;
|
|
18
18
|
export interface Transport<Body, Prepared, Frame> {
|
|
19
19
|
readonly id: string;
|
|
20
|
-
readonly prepare: (input: TransportPrepareInput<Body>) => Effect.Effect<Prepared,
|
|
21
|
-
readonly frames: (prepared: Prepared, request: LLMRequest, runtime: TransportRuntime) => Stream.Stream<Frame,
|
|
20
|
+
readonly prepare: (input: TransportPrepareInput<Body>) => Effect.Effect<Prepared, AIError>;
|
|
21
|
+
readonly frames: (prepared: Prepared, request: LLMRequest, runtime: TransportRuntime) => Stream.Stream<Frame, AIError>;
|
|
22
22
|
}
|
|
23
23
|
export interface TransportPrepareInput<Body> {
|
|
24
24
|
readonly body: Body;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { Context, Effect, Layer, Stream } from "effect";
|
|
2
2
|
import { Headers } from "effect/unstable/http";
|
|
3
|
-
import {
|
|
3
|
+
import { AIError } from "../../schema";
|
|
4
4
|
import type { Transport } from "./index";
|
|
5
5
|
export interface WebSocketRequest {
|
|
6
6
|
readonly url: string;
|
|
7
7
|
readonly headers: Headers.Headers;
|
|
8
8
|
}
|
|
9
9
|
export interface WebSocketConnection {
|
|
10
|
-
readonly sendText: (message: string) => Effect.Effect<void,
|
|
11
|
-
readonly messages: Stream.Stream<string | Uint8Array,
|
|
10
|
+
readonly sendText: (message: string) => Effect.Effect<void, AIError>;
|
|
11
|
+
readonly messages: Stream.Stream<string | Uint8Array, AIError>;
|
|
12
12
|
readonly close: Effect.Effect<void, never>;
|
|
13
13
|
}
|
|
14
14
|
export interface Interface {
|
|
15
|
-
readonly open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection,
|
|
15
|
+
readonly open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection, AIError>;
|
|
16
16
|
}
|
|
17
|
-
declare const Service_base: Context.ServiceClass<Service, "@opencode/
|
|
17
|
+
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/WebSocketExecutor", Interface>;
|
|
18
18
|
export declare class Service extends Service_base {
|
|
19
19
|
}
|
|
20
|
-
export declare const open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection,
|
|
20
|
+
export declare const open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection, AIError, never>;
|
|
21
21
|
export declare const layer: Layer.Layer<Service>;
|
|
22
|
-
export declare const fromWebSocket: (ws: globalThis.WebSocket, input: WebSocketRequest) => Effect.Effect<WebSocketConnection,
|
|
22
|
+
export declare const fromWebSocket: (ws: globalThis.WebSocket, input: WebSocketRequest) => Effect.Effect<WebSocketConnection, AIError>;
|
|
23
23
|
export declare const messageText: (message: string | Uint8Array, decoder: TextDecoder) => string;
|
|
24
24
|
export interface JsonPrepared {
|
|
25
25
|
readonly url: string;
|
|
@@ -27,7 +27,7 @@ export interface JsonPrepared {
|
|
|
27
27
|
readonly message: string;
|
|
28
28
|
}
|
|
29
29
|
export interface JsonInput<Body, Message> {
|
|
30
|
-
readonly toMessage: (body: Body | Record<string, unknown>) => Effect.Effect<Message,
|
|
30
|
+
readonly toMessage: (body: Body | Record<string, unknown>) => Effect.Effect<Message, AIError>;
|
|
31
31
|
readonly encodeMessage: (message: Message) => string;
|
|
32
32
|
}
|
|
33
33
|
export type JsonPatch<Body, Message> = Partial<JsonInput<Body, Message>>;
|
|
@@ -42,8 +42,8 @@ export declare const jsonTransport: {
|
|
|
42
42
|
export declare const WebSocketExecutor: {
|
|
43
43
|
readonly Service: typeof Service;
|
|
44
44
|
readonly layer: Layer.Layer<Service, never, never>;
|
|
45
|
-
readonly open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection,
|
|
46
|
-
readonly fromWebSocket: (ws: globalThis.WebSocket, input: WebSocketRequest) => Effect.Effect<WebSocketConnection,
|
|
45
|
+
readonly open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection, AIError, never>;
|
|
46
|
+
readonly fromWebSocket: (ws: globalThis.WebSocket, input: WebSocketRequest) => Effect.Effect<WebSocketConnection, AIError>;
|
|
47
47
|
readonly messageText: (message: string | Uint8Array, decoder: TextDecoder) => string;
|
|
48
48
|
};
|
|
49
49
|
export declare const WebSocketTransport: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Cause, Context, Effect, Layer, Queue, Stream } from "effect";
|
|
2
2
|
import { Headers } from "effect/unstable/http";
|
|
3
|
-
import {
|
|
3
|
+
import { AIError, TransportReason } from "../../schema";
|
|
4
4
|
import * as HttpTransport from "./http";
|
|
5
|
-
export class Service extends Context.Service()("@opencode/
|
|
5
|
+
export class Service extends Context.Service()("@opencode/AI/WebSocketExecutor") {
|
|
6
6
|
}
|
|
7
|
-
const transportError = (method, message, input = {}) => new
|
|
7
|
+
const transportError = (method, message, input = {}) => new AIError({
|
|
8
8
|
module: "WebSocketExecutor",
|
|
9
9
|
method,
|
|
10
10
|
reason: new TransportReason({ message, url: input.url, kind: input.kind }),
|
package/dist/schema/errors.d.ts
CHANGED
|
@@ -46,8 +46,8 @@ export declare class InvalidRequestReason extends InvalidRequestReason_base {
|
|
|
46
46
|
declare const NoRouteReason_base: Schema.Class<NoRouteReason, Schema.Struct<{
|
|
47
47
|
readonly _tag: Schema.tag<"NoRoute">;
|
|
48
48
|
readonly route: Schema.String;
|
|
49
|
-
readonly provider: Schema.brand<Schema.String, "
|
|
50
|
-
readonly model: Schema.brand<Schema.String, "
|
|
49
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
50
|
+
readonly model: Schema.brand<Schema.String, "AI.ModelID">;
|
|
51
51
|
}>, {}>;
|
|
52
52
|
export declare class NoRouteReason extends NoRouteReason_base {
|
|
53
53
|
get message(): string;
|
|
@@ -124,14 +124,14 @@ declare const UnknownProviderReason_base: Schema.Class<UnknownProviderReason, Sc
|
|
|
124
124
|
}>, {}>;
|
|
125
125
|
export declare class UnknownProviderReason extends UnknownProviderReason_base {
|
|
126
126
|
}
|
|
127
|
-
export declare const
|
|
128
|
-
export type
|
|
129
|
-
declare const
|
|
127
|
+
export declare const AIErrorReason: Schema.toTaggedUnion<"_tag", readonly [typeof InvalidRequestReason, typeof NoRouteReason, typeof AuthenticationReason, typeof RateLimitReason, typeof QuotaExceededReason, typeof ContentPolicyReason, typeof ProviderInternalReason, typeof TransportReason, typeof InvalidProviderOutputReason, typeof UnknownProviderReason]>;
|
|
128
|
+
export type AIErrorReason = Schema.Schema.Type<typeof AIErrorReason>;
|
|
129
|
+
declare const AIError_base: Schema.Class<AIError, Schema.TaggedStruct<"AI.Error", {
|
|
130
130
|
readonly module: Schema.String;
|
|
131
131
|
readonly method: Schema.String;
|
|
132
132
|
readonly reason: Schema.toTaggedUnion<"_tag", readonly [typeof InvalidRequestReason, typeof NoRouteReason, typeof AuthenticationReason, typeof RateLimitReason, typeof QuotaExceededReason, typeof ContentPolicyReason, typeof ProviderInternalReason, typeof TransportReason, typeof InvalidProviderOutputReason, typeof UnknownProviderReason]>;
|
|
133
133
|
}>, import("effect/Cause").YieldableError>;
|
|
134
|
-
export declare class
|
|
134
|
+
export declare class AIError extends AIError_base {
|
|
135
135
|
readonly cause: InvalidRequestReason | NoRouteReason | AuthenticationReason | RateLimitReason | QuotaExceededReason | ContentPolicyReason | ProviderInternalReason | TransportReason | InvalidProviderOutputReason | UnknownProviderReason;
|
|
136
136
|
get message(): string;
|
|
137
137
|
}
|
package/dist/schema/errors.js
CHANGED
|
@@ -2,25 +2,25 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { Tool } from "@opencode-ai/schema/tool";
|
|
3
3
|
import { ModelID, ProviderID, ProviderMetadata, RouteID } from "./ids";
|
|
4
4
|
export const ProviderFailureClassification = Schema.Literals(["context-overflow", "payload-too-large"]);
|
|
5
|
-
export class HttpRequestDetails extends Schema.Class("
|
|
5
|
+
export class HttpRequestDetails extends Schema.Class("AI.HttpRequestDetails")({
|
|
6
6
|
method: Schema.String,
|
|
7
7
|
url: Schema.String,
|
|
8
8
|
headers: Schema.Record(Schema.String, Schema.String),
|
|
9
9
|
}) {
|
|
10
10
|
}
|
|
11
|
-
export class HttpResponseDetails extends Schema.Class("
|
|
11
|
+
export class HttpResponseDetails extends Schema.Class("AI.HttpResponseDetails")({
|
|
12
12
|
status: Schema.Number,
|
|
13
13
|
headers: Schema.Record(Schema.String, Schema.String),
|
|
14
14
|
}) {
|
|
15
15
|
}
|
|
16
|
-
export class HttpRateLimitDetails extends Schema.Class("
|
|
16
|
+
export class HttpRateLimitDetails extends Schema.Class("AI.HttpRateLimitDetails")({
|
|
17
17
|
retryAfterMs: Schema.optional(Schema.Number),
|
|
18
18
|
limit: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
19
19
|
remaining: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
20
20
|
reset: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
21
21
|
}) {
|
|
22
22
|
}
|
|
23
|
-
export class HttpContext extends Schema.Class("
|
|
23
|
+
export class HttpContext extends Schema.Class("AI.HttpContext")({
|
|
24
24
|
request: HttpRequestDetails,
|
|
25
25
|
response: Schema.optional(HttpResponseDetails),
|
|
26
26
|
body: Schema.optional(Schema.String),
|
|
@@ -29,7 +29,7 @@ export class HttpContext extends Schema.Class("LLM.HttpContext")({
|
|
|
29
29
|
rateLimit: Schema.optional(HttpRateLimitDetails),
|
|
30
30
|
}) {
|
|
31
31
|
}
|
|
32
|
-
export class InvalidRequestReason extends Schema.Class("
|
|
32
|
+
export class InvalidRequestReason extends Schema.Class("AI.Error.InvalidRequest")({
|
|
33
33
|
_tag: Schema.tag("InvalidRequest"),
|
|
34
34
|
message: Schema.String,
|
|
35
35
|
parameter: Schema.optional(Schema.String),
|
|
@@ -38,17 +38,17 @@ export class InvalidRequestReason extends Schema.Class("LLM.Error.InvalidRequest
|
|
|
38
38
|
http: Schema.optional(HttpContext),
|
|
39
39
|
}) {
|
|
40
40
|
}
|
|
41
|
-
export class NoRouteReason extends Schema.Class("
|
|
41
|
+
export class NoRouteReason extends Schema.Class("AI.Error.NoRoute")({
|
|
42
42
|
_tag: Schema.tag("NoRoute"),
|
|
43
43
|
route: RouteID,
|
|
44
44
|
provider: ProviderID,
|
|
45
45
|
model: ModelID,
|
|
46
46
|
}) {
|
|
47
47
|
get message() {
|
|
48
|
-
return `No
|
|
48
|
+
return `No AI route for ${this.provider}/${this.model} using ${this.route}`;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
export class AuthenticationReason extends Schema.Class("
|
|
51
|
+
export class AuthenticationReason extends Schema.Class("AI.Error.Authentication")({
|
|
52
52
|
_tag: Schema.tag("Authentication"),
|
|
53
53
|
message: Schema.String,
|
|
54
54
|
kind: Schema.Literals(["missing", "invalid", "expired", "insufficient-permissions", "unknown"]),
|
|
@@ -56,7 +56,7 @@ export class AuthenticationReason extends Schema.Class("LLM.Error.Authentication
|
|
|
56
56
|
http: Schema.optional(HttpContext),
|
|
57
57
|
}) {
|
|
58
58
|
}
|
|
59
|
-
export class RateLimitReason extends Schema.Class("
|
|
59
|
+
export class RateLimitReason extends Schema.Class("AI.Error.RateLimit")({
|
|
60
60
|
_tag: Schema.tag("RateLimit"),
|
|
61
61
|
message: Schema.String,
|
|
62
62
|
retryAfterMs: Schema.optional(Schema.Number),
|
|
@@ -65,21 +65,21 @@ export class RateLimitReason extends Schema.Class("LLM.Error.RateLimit")({
|
|
|
65
65
|
http: Schema.optional(HttpContext),
|
|
66
66
|
}) {
|
|
67
67
|
}
|
|
68
|
-
export class QuotaExceededReason extends Schema.Class("
|
|
68
|
+
export class QuotaExceededReason extends Schema.Class("AI.Error.QuotaExceeded")({
|
|
69
69
|
_tag: Schema.tag("QuotaExceeded"),
|
|
70
70
|
message: Schema.String,
|
|
71
71
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
72
72
|
http: Schema.optional(HttpContext),
|
|
73
73
|
}) {
|
|
74
74
|
}
|
|
75
|
-
export class ContentPolicyReason extends Schema.Class("
|
|
75
|
+
export class ContentPolicyReason extends Schema.Class("AI.Error.ContentPolicy")({
|
|
76
76
|
_tag: Schema.tag("ContentPolicy"),
|
|
77
77
|
message: Schema.String,
|
|
78
78
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
79
79
|
http: Schema.optional(HttpContext),
|
|
80
80
|
}) {
|
|
81
81
|
}
|
|
82
|
-
export class ProviderInternalReason extends Schema.Class("
|
|
82
|
+
export class ProviderInternalReason extends Schema.Class("AI.Error.ProviderInternal")({
|
|
83
83
|
_tag: Schema.tag("ProviderInternal"),
|
|
84
84
|
message: Schema.String,
|
|
85
85
|
status: Schema.optional(Schema.Number),
|
|
@@ -88,7 +88,7 @@ export class ProviderInternalReason extends Schema.Class("LLM.Error.ProviderInte
|
|
|
88
88
|
http: Schema.optional(HttpContext),
|
|
89
89
|
}) {
|
|
90
90
|
}
|
|
91
|
-
export class TransportReason extends Schema.Class("
|
|
91
|
+
export class TransportReason extends Schema.Class("AI.Error.Transport")({
|
|
92
92
|
_tag: Schema.tag("Transport"),
|
|
93
93
|
message: Schema.String,
|
|
94
94
|
kind: Schema.optional(Schema.String),
|
|
@@ -96,7 +96,7 @@ export class TransportReason extends Schema.Class("LLM.Error.Transport")({
|
|
|
96
96
|
http: Schema.optional(HttpContext),
|
|
97
97
|
}) {
|
|
98
98
|
}
|
|
99
|
-
export class InvalidProviderOutputReason extends Schema.Class("
|
|
99
|
+
export class InvalidProviderOutputReason extends Schema.Class("AI.Error.InvalidProviderOutput")({
|
|
100
100
|
_tag: Schema.tag("InvalidProviderOutput"),
|
|
101
101
|
message: Schema.String,
|
|
102
102
|
route: Schema.optional(Schema.String),
|
|
@@ -104,7 +104,7 @@ export class InvalidProviderOutputReason extends Schema.Class("LLM.Error.Invalid
|
|
|
104
104
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
105
105
|
}) {
|
|
106
106
|
}
|
|
107
|
-
export class UnknownProviderReason extends Schema.Class("
|
|
107
|
+
export class UnknownProviderReason extends Schema.Class("AI.Error.UnknownProvider")({
|
|
108
108
|
_tag: Schema.tag("UnknownProvider"),
|
|
109
109
|
message: Schema.String,
|
|
110
110
|
status: Schema.optional(Schema.Number),
|
|
@@ -112,7 +112,7 @@ export class UnknownProviderReason extends Schema.Class("LLM.Error.UnknownProvid
|
|
|
112
112
|
http: Schema.optional(HttpContext),
|
|
113
113
|
}) {
|
|
114
114
|
}
|
|
115
|
-
export const
|
|
115
|
+
export const AIErrorReason = Schema.Union([
|
|
116
116
|
InvalidRequestReason,
|
|
117
117
|
NoRouteReason,
|
|
118
118
|
AuthenticationReason,
|
|
@@ -124,10 +124,10 @@ export const LLMErrorReason = Schema.Union([
|
|
|
124
124
|
InvalidProviderOutputReason,
|
|
125
125
|
UnknownProviderReason,
|
|
126
126
|
]).pipe(Schema.toTaggedUnion("_tag"));
|
|
127
|
-
export class
|
|
127
|
+
export class AIError extends Schema.TaggedErrorClass()("AI.Error", {
|
|
128
128
|
module: Schema.String,
|
|
129
129
|
method: Schema.String,
|
|
130
|
-
reason:
|
|
130
|
+
reason: AIErrorReason,
|
|
131
131
|
}) {
|
|
132
132
|
cause = this.reason;
|
|
133
133
|
get message() {
|
package/dist/schema/events.js
CHANGED
|
@@ -47,7 +47,7 @@ import { ProviderFailureClassification } from "./errors";
|
|
|
47
47
|
* — for fields we don't normalize and for billing-level audit trails.
|
|
48
48
|
* Matches the same escape-hatch field on `LLMEvent`.
|
|
49
49
|
*/
|
|
50
|
-
export class Usage extends Schema.Class("
|
|
50
|
+
export class Usage extends Schema.Class("AI.Usage")({
|
|
51
51
|
inputTokens: Schema.optional(Schema.Number),
|
|
52
52
|
outputTokens: Schema.optional(Schema.Number),
|
|
53
53
|
nonCachedInputTokens: Schema.optional(Schema.Number),
|
package/dist/schema/ids.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { ProviderMetadata } from "@opencode-ai/schema/
|
|
2
|
+
import { ProviderMetadata } from "@opencode-ai/schema/ai";
|
|
3
3
|
export { ProviderMetadata };
|
|
4
4
|
/** Stable string identifier for a protocol implementation. */
|
|
5
5
|
export declare const ProtocolID: Schema.String;
|
|
@@ -7,9 +7,9 @@ export type ProtocolID = Schema.Schema.Type<typeof ProtocolID>;
|
|
|
7
7
|
/** Stable string identifier for the runnable route. */
|
|
8
8
|
export declare const RouteID: Schema.String;
|
|
9
9
|
export type RouteID = Schema.Schema.Type<typeof RouteID>;
|
|
10
|
-
export declare const ModelID: Schema.brand<Schema.String, "
|
|
10
|
+
export declare const ModelID: Schema.brand<Schema.String, "AI.ModelID">;
|
|
11
11
|
export type ModelID = typeof ModelID.Type;
|
|
12
|
-
export declare const ProviderID: Schema.brand<Schema.String, "
|
|
12
|
+
export declare const ProviderID: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
13
13
|
export type ProviderID = typeof ProviderID.Type;
|
|
14
14
|
export declare const ResponseID: Schema.String;
|
|
15
15
|
export type ResponseID = Schema.Schema.Type<typeof ResponseID>;
|
package/dist/schema/ids.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderMetadata } from "@opencode-ai/schema/ai";
|
|
3
|
+
import { LLM } from "@opencode-ai/schema/llm";
|
|
3
4
|
export { ProviderMetadata };
|
|
4
5
|
/** Stable string identifier for a protocol implementation. */
|
|
5
6
|
export const ProtocolID = Schema.String;
|
|
6
7
|
/** Stable string identifier for the runnable route. */
|
|
7
8
|
export const RouteID = Schema.String;
|
|
8
|
-
export const ModelID = Schema.String.pipe(Schema.brand("
|
|
9
|
-
export const ProviderID = Schema.String.pipe(Schema.brand("
|
|
9
|
+
export const ModelID = Schema.String.pipe(Schema.brand("AI.ModelID"));
|
|
10
|
+
export const ProviderID = Schema.String.pipe(Schema.brand("AI.ProviderID"));
|
|
10
11
|
export const ResponseID = Schema.String;
|
|
11
12
|
export const ContentBlockID = Schema.String;
|
|
12
13
|
export const ToolCallID = Schema.String;
|
|
@@ -336,11 +336,11 @@ export declare namespace ToolChoice {
|
|
|
336
336
|
}
|
|
337
337
|
declare const LLMRequest_base: Schema.Class<LLMRequest, Schema.Struct<{
|
|
338
338
|
readonly id: Schema.optional<Schema.String>;
|
|
339
|
-
readonly model: Schema.declare<import("./options").
|
|
339
|
+
readonly model: Schema.declare<import("./options").LanguageModel<{
|
|
340
340
|
readonly [x: string]: {
|
|
341
341
|
readonly [x: string]: unknown;
|
|
342
342
|
};
|
|
343
|
-
}>, import("./options").
|
|
343
|
+
}>, import("./options").LanguageModel<{
|
|
344
344
|
readonly [x: string]: {
|
|
345
345
|
readonly [x: string]: unknown;
|
|
346
346
|
};
|
package/dist/schema/messages.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Tool } from "@opencode-ai/schema/tool";
|
|
3
3
|
import { JsonSchema, MessageRole, ProviderMetadata } from "./ids";
|
|
4
|
-
import { CacheHint, CachePolicy, GenerationOptions, HttpOptions,
|
|
4
|
+
import { CacheHint, CachePolicy, GenerationOptions, HttpOptions, LanguageModelSchema, ProviderOptions } from "./options";
|
|
5
5
|
import { isRecord } from "../utils/record";
|
|
6
6
|
const systemPartSchema = Schema.Struct({
|
|
7
7
|
type: Schema.Literal("text"),
|
|
@@ -202,7 +202,7 @@ export class ToolChoice extends Schema.Class("LLM.ToolChoice")({
|
|
|
202
202
|
})(ToolChoice || (ToolChoice = {}));
|
|
203
203
|
export class LLMRequest extends Schema.Class("LLM.Request")({
|
|
204
204
|
id: Schema.optional(Schema.String),
|
|
205
|
-
model:
|
|
205
|
+
model: LanguageModelSchema,
|
|
206
206
|
system: Schema.Array(SystemPart),
|
|
207
207
|
messages: Schema.Array(Message),
|
|
208
208
|
tools: Schema.Array(ToolDefinition),
|
package/dist/schema/options.d.ts
CHANGED
|
@@ -47,86 +47,86 @@ export type GenerationOptionsFields = {
|
|
|
47
47
|
};
|
|
48
48
|
export type GenerationOptionsInput = GenerationOptions | GenerationOptionsFields;
|
|
49
49
|
export declare const mergeGenerationOptions: (...items: ReadonlyArray<GenerationOptionsInput | undefined>) => GenerationOptions | undefined;
|
|
50
|
-
declare const
|
|
50
|
+
declare const LanguageModelLimits_base: Schema.Class<LanguageModelLimits, Schema.Struct<{
|
|
51
51
|
readonly context: Schema.optional<Schema.Number>;
|
|
52
52
|
readonly input: Schema.optional<Schema.Number>;
|
|
53
53
|
readonly output: Schema.optional<Schema.Number>;
|
|
54
54
|
}>, {}>;
|
|
55
|
-
export declare class
|
|
55
|
+
export declare class LanguageModelLimits extends LanguageModelLimits_base {
|
|
56
56
|
}
|
|
57
|
-
export declare namespace
|
|
58
|
-
type Input =
|
|
59
|
-
/** Normalize model limit input into the canonical `
|
|
60
|
-
const make: (input: Input | undefined) =>
|
|
57
|
+
export declare namespace LanguageModelLimits {
|
|
58
|
+
type Input = LanguageModelLimits | ConstructorParameters<typeof LanguageModelLimits>[0];
|
|
59
|
+
/** Normalize model limit input into the canonical `LanguageModelLimits` class. */
|
|
60
|
+
const make: (input: Input | undefined) => LanguageModelLimits;
|
|
61
61
|
}
|
|
62
|
-
declare const
|
|
63
|
-
readonly limits: Schema.optional<typeof
|
|
62
|
+
declare const LanguageModelDefaults_base: Schema.Class<LanguageModelDefaults, Schema.Struct<{
|
|
63
|
+
readonly limits: Schema.optional<typeof LanguageModelLimits>;
|
|
64
64
|
readonly generation: Schema.optional<typeof GenerationOptions>;
|
|
65
65
|
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
66
66
|
readonly http: Schema.optional<typeof HttpOptions>;
|
|
67
67
|
}>, {}>;
|
|
68
|
-
export declare class
|
|
68
|
+
export declare class LanguageModelDefaults extends LanguageModelDefaults_base {
|
|
69
69
|
}
|
|
70
|
-
export declare namespace
|
|
71
|
-
type Input =
|
|
72
|
-
readonly limits?:
|
|
70
|
+
export declare namespace LanguageModelDefaults {
|
|
71
|
+
type Input = LanguageModelDefaults | {
|
|
72
|
+
readonly limits?: LanguageModelLimits.Input;
|
|
73
73
|
readonly generation?: GenerationOptions.Input;
|
|
74
74
|
readonly providerOptions?: ProviderOptions;
|
|
75
75
|
readonly http?: HttpOptions.Input;
|
|
76
76
|
};
|
|
77
77
|
/** Normalize selected-model request defaults without applying precedence. */
|
|
78
|
-
const make: (input: Input) =>
|
|
78
|
+
const make: (input: Input) => LanguageModelDefaults;
|
|
79
79
|
}
|
|
80
|
-
export declare const
|
|
81
|
-
export type
|
|
82
|
-
export declare const
|
|
83
|
-
export type
|
|
84
|
-
declare const
|
|
80
|
+
export declare const LanguageModelToolSchemaCompatibility: Schema.Literals<readonly ["gemini", "moonshot"]>;
|
|
81
|
+
export type LanguageModelToolSchemaCompatibility = Schema.Schema.Type<typeof LanguageModelToolSchemaCompatibility>;
|
|
82
|
+
export declare const LanguageModelMaxTokensFieldCompatibility: Schema.Literals<readonly ["max_completion_tokens", "max_tokens"]>;
|
|
83
|
+
export type LanguageModelMaxTokensFieldCompatibility = Schema.Schema.Type<typeof LanguageModelMaxTokensFieldCompatibility>;
|
|
84
|
+
declare const LanguageModelCompatibility_base: Schema.Class<LanguageModelCompatibility, Schema.Struct<{
|
|
85
85
|
readonly toolSchema: Schema.optional<Schema.Literals<readonly ["gemini", "moonshot"]>>;
|
|
86
86
|
readonly reasoningField: Schema.optional<Schema.String>;
|
|
87
87
|
readonly maxTokensField: Schema.optional<Schema.Literals<readonly ["max_completion_tokens", "max_tokens"]>>;
|
|
88
88
|
}>, {}>;
|
|
89
|
-
export declare class
|
|
89
|
+
export declare class LanguageModelCompatibility extends LanguageModelCompatibility_base {
|
|
90
90
|
}
|
|
91
|
-
export declare namespace
|
|
92
|
-
type Input =
|
|
91
|
+
export declare namespace LanguageModelCompatibility {
|
|
92
|
+
type Input = LanguageModelCompatibility | ConstructorParameters<typeof LanguageModelCompatibility>[0];
|
|
93
93
|
/** Normalize model/upstream compatibility metadata without projecting requests. */
|
|
94
|
-
const make: (input: Input) =>
|
|
94
|
+
const make: (input: Input) => LanguageModelCompatibility;
|
|
95
95
|
}
|
|
96
|
-
export declare class
|
|
96
|
+
export declare class LanguageModel<Options extends ProviderOptions = ProviderOptions> {
|
|
97
97
|
protected readonly _ProviderOptions: Options;
|
|
98
98
|
readonly id: ModelID;
|
|
99
99
|
readonly provider: ProviderID;
|
|
100
100
|
readonly route: AnyRoute;
|
|
101
|
-
readonly defaults?:
|
|
102
|
-
readonly compatibility?:
|
|
103
|
-
constructor(input:
|
|
104
|
-
static make<Options extends ProviderOptions = ProviderOptions>(input:
|
|
105
|
-
static input<Options extends ProviderOptions>(model:
|
|
106
|
-
static update<Options extends ProviderOptions>(model:
|
|
101
|
+
readonly defaults?: LanguageModelDefaults;
|
|
102
|
+
readonly compatibility?: LanguageModelCompatibility;
|
|
103
|
+
constructor(input: LanguageModel.ConstructorInput);
|
|
104
|
+
static make<Options extends ProviderOptions = ProviderOptions>(input: LanguageModel.Input): LanguageModel<Options>;
|
|
105
|
+
static input<Options extends ProviderOptions>(model: LanguageModel<Options>): LanguageModel.ConstructorInput;
|
|
106
|
+
static update<Options extends ProviderOptions>(model: LanguageModel<Options>, patch: Partial<LanguageModel.Input>): LanguageModel<Options>;
|
|
107
107
|
}
|
|
108
|
-
export declare namespace
|
|
108
|
+
export declare namespace LanguageModel {
|
|
109
109
|
type ConstructorInput = {
|
|
110
110
|
readonly id: ModelID;
|
|
111
111
|
readonly provider: ProviderID;
|
|
112
112
|
readonly route: AnyRoute;
|
|
113
|
-
readonly defaults?:
|
|
114
|
-
readonly compatibility?:
|
|
113
|
+
readonly defaults?: LanguageModelDefaults;
|
|
114
|
+
readonly compatibility?: LanguageModelCompatibility;
|
|
115
115
|
};
|
|
116
116
|
type Input = Omit<ConstructorInput, "id" | "provider" | "defaults" | "compatibility"> & {
|
|
117
117
|
readonly id: string | ModelID;
|
|
118
118
|
readonly provider: string | ProviderID;
|
|
119
|
-
readonly defaults?:
|
|
120
|
-
readonly compatibility?:
|
|
119
|
+
readonly defaults?: LanguageModelDefaults.Input;
|
|
120
|
+
readonly compatibility?: LanguageModelCompatibility.Input;
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
export type
|
|
124
|
-
export type
|
|
125
|
-
export declare const
|
|
123
|
+
export type LanguageModelInput = LanguageModel.Input;
|
|
124
|
+
export type LanguageModelProviderOptions<SelectedModel> = SelectedModel extends LanguageModel<infer Options> ? Options : never;
|
|
125
|
+
export declare const LanguageModelSchema: Schema.declare<LanguageModel<{
|
|
126
126
|
readonly [x: string]: {
|
|
127
127
|
readonly [x: string]: unknown;
|
|
128
128
|
};
|
|
129
|
-
}>,
|
|
129
|
+
}>, LanguageModel<{
|
|
130
130
|
readonly [x: string]: {
|
|
131
131
|
readonly [x: string]: unknown;
|
|
132
132
|
};
|