@opencode/ai 0.0.0-dev-21798 → 0.0.0-dev-21800
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 +55 -55
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +452 -0
- package/dist/decision.js +143 -0
- package/dist/experimental.d.ts +0 -3
- package/dist/experimental.js +0 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/promise.d.ts +10 -1
- package/dist/promise.js +5 -0
- package/dist/protocols/alibaba-messages.d.ts +34 -0
- package/dist/protocols/anthropic-messages.d.ts +102 -0
- package/dist/protocols/anthropic-messages.js +32 -8
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-messages.d.ts +34 -0
- package/dist/protocols/meta-messages.js +12 -0
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +108 -0
- package/dist/protocols/shared.d.ts +1 -1
- package/dist/protocols/shared.js +2 -2
- package/dist/protocols/system-one.d.ts +99 -0
- package/dist/protocols/system-one.js +228 -0
- package/dist/protocols/zai-messages.d.ts +34 -0
- package/dist/providers/alibaba.d.ts +34 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +34 -0
- package/dist/providers/anthropic-compatible.d.ts +34 -0
- package/dist/providers/anthropic.d.ts +34 -0
- package/dist/providers/baseten.d.ts +4 -10
- package/dist/providers/baseten.js +21 -8
- package/dist/providers/cloudflare-ai-gateway.d.ts +69 -3
- package/dist/providers/cloudflare-ai-gateway.js +10 -10
- package/dist/providers/cloudflare-workers-ai.d.ts +1 -3
- package/dist/providers/cloudflare-workers-ai.js +11 -12
- package/dist/providers/digitalocean.d.ts +3 -9
- package/dist/providers/digitalocean.js +10 -10
- package/dist/providers/google-vertex-messages.d.ts +34 -0
- package/dist/providers/meta.d.ts +34 -0
- package/dist/providers/minimax.d.ts +34 -0
- package/dist/providers/moonshot.d.ts +34 -0
- package/dist/providers/openai.d.ts +5 -10
- package/dist/providers/openai.js +11 -7
- package/dist/providers/opencode.d.ts +3 -9
- package/dist/providers/opencode.js +9 -9
- package/dist/providers/openrouter.d.ts +4 -10
- package/dist/providers/openrouter.js +8 -9
- package/dist/providers/typesafe-ai.d.ts +3 -9
- package/dist/providers/typesafe-ai.js +9 -9
- package/dist/providers/vercel-ai-gateway.d.ts +4 -15
- package/dist/providers/vercel-ai-gateway.js +13 -80
- package/dist/providers/zai-coding-plan.d.ts +34 -0
- package/dist/route/client.js +11 -0
- package/dist/route/decision.d.ts +57 -0
- package/dist/route/decision.js +74 -0
- package/package.json +3 -3
- package/dist/experimental/cloudflare-run-evaluation.d.ts +0 -15
- package/dist/experimental/cloudflare-run-evaluation.js +0 -43
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/openai-decisions.d.ts +0 -23
- package/dist/experimental/openai-decisions.js +0 -115
- package/dist/experimental/system-one.d.ts +0 -114
- package/dist/experimental/system-one.js +0 -140
|
@@ -72,7 +72,7 @@ export interface OpenRouterOptions {
|
|
|
72
72
|
}>;
|
|
73
73
|
}
|
|
74
74
|
export type OpenRouterProviderOptionsInput = OpenRouterOptions;
|
|
75
|
-
export interface
|
|
75
|
+
export interface OpenRouterDecisionOptions {
|
|
76
76
|
readonly [key: string]: unknown;
|
|
77
77
|
readonly provider?: OpenRouterProviderRouting;
|
|
78
78
|
readonly session_id?: string;
|
|
@@ -750,21 +750,15 @@ export declare const routes: Route<{
|
|
|
750
750
|
export declare const configure: (input?: LanguageModelOptions) => {
|
|
751
751
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
752
752
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
|
|
753
|
-
|
|
754
|
-
evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<OpenRouterEvaluationOptions>;
|
|
755
|
-
};
|
|
753
|
+
decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
756
754
|
configure: typeof configure;
|
|
757
755
|
};
|
|
758
756
|
export declare const provider: {
|
|
759
757
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
760
758
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
|
|
761
|
-
|
|
762
|
-
evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<OpenRouterEvaluationOptions>;
|
|
763
|
-
};
|
|
759
|
+
decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
764
760
|
configure: typeof configure;
|
|
765
761
|
};
|
|
766
|
-
export declare const
|
|
767
|
-
evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<OpenRouterEvaluationOptions>;
|
|
768
|
-
};
|
|
762
|
+
export declare const decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
769
763
|
export declare const model: ProviderPackage.Definition<Settings, OpenRouterProviderOptionsInput>["model"];
|
|
770
764
|
export {};
|
|
@@ -3,8 +3,8 @@ import { Route } from "../route/client.js";
|
|
|
3
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
4
4
|
import { Protocol } from "../route/protocol.js";
|
|
5
5
|
import { AuthOptions } from "../route/auth-options.js";
|
|
6
|
-
import {
|
|
7
|
-
import { SystemOne } from "../
|
|
6
|
+
import { ProviderID } from "../schema/index.js";
|
|
7
|
+
import { SystemOne } from "../protocols/system-one.js";
|
|
8
8
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
9
9
|
import { cacheControl } from "../protocols/utils/cache.js";
|
|
10
10
|
import { isRecord, JsonObject, lenient, ProviderShared } from "../protocols/shared.js";
|
|
@@ -99,25 +99,24 @@ const configuredRoute = (input) => {
|
|
|
99
99
|
};
|
|
100
100
|
export const configure = (input = {}) => {
|
|
101
101
|
const route = configuredRoute(input);
|
|
102
|
-
const
|
|
103
|
-
id: modelID,
|
|
102
|
+
const decisionRoute = SystemOne.route.with({
|
|
104
103
|
provider: id,
|
|
105
104
|
providerMetadataKey: "openrouter",
|
|
105
|
+
endpoint: { baseURL: input.baseURL ?? baseURL },
|
|
106
106
|
auth: AuthOptions.bearer(input, "OPENROUTER_API_KEY"),
|
|
107
|
-
baseURL: input.baseURL ?? baseURL,
|
|
108
107
|
headers: input.headers,
|
|
109
|
-
http:
|
|
110
|
-
rounding: SystemOne.jevRounding,
|
|
108
|
+
http: input.http,
|
|
111
109
|
});
|
|
110
|
+
const decision = (modelID) => decisionRoute.model({ id: modelID, compatibility: { imageInput: "state" } });
|
|
112
111
|
return {
|
|
113
112
|
id,
|
|
114
113
|
model: (modelID) => route.model({ id: modelID, compatibility: { supportsPromptCacheKey: true } }),
|
|
115
|
-
|
|
114
|
+
decision,
|
|
116
115
|
configure,
|
|
117
116
|
};
|
|
118
117
|
};
|
|
119
118
|
export const provider = configure();
|
|
120
|
-
export const
|
|
119
|
+
export const decision = provider.decision;
|
|
121
120
|
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
|
|
122
121
|
apiKey,
|
|
123
122
|
baseURL,
|
|
@@ -8,19 +8,13 @@ export type Options = ProviderAuthOption<"optional"> & {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const configure: (input?: Options) => {
|
|
10
10
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
11
|
-
|
|
12
|
-
evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
|
|
13
|
-
};
|
|
11
|
+
decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
14
12
|
configure: typeof configure;
|
|
15
13
|
};
|
|
16
14
|
export declare const provider: {
|
|
17
15
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
18
|
-
|
|
19
|
-
evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
|
|
20
|
-
};
|
|
16
|
+
decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
21
17
|
configure: typeof configure;
|
|
22
18
|
};
|
|
23
|
-
export declare const
|
|
24
|
-
evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
|
|
25
|
-
};
|
|
19
|
+
export declare const decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
26
20
|
export * as TypeSafeAI from "./typesafe-ai.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { HttpOptions, ProviderID } from "../schema/index.js";
|
|
2
2
|
import { AuthOptions } from "../route/auth-options.js";
|
|
3
|
-
import { SystemOne } from "../
|
|
3
|
+
import { SystemOne } from "../protocols/system-one.js";
|
|
4
4
|
export const id = ProviderID.make("typesafe-ai");
|
|
5
5
|
const baseURL = "https://api.typesafe.ai/v1";
|
|
6
6
|
export const configure = (input = {}) => {
|
|
7
|
-
const
|
|
8
|
-
id: modelID,
|
|
7
|
+
const route = SystemOne.route.with({
|
|
9
8
|
provider: id,
|
|
10
9
|
providerMetadataKey: "typesafe",
|
|
10
|
+
endpoint: { baseURL: input.baseURL ?? baseURL },
|
|
11
11
|
auth: AuthOptions.bearer(input, "TYPESAFE_API_KEY"),
|
|
12
|
-
|
|
13
|
-
headers: input.headers,
|
|
14
|
-
http:
|
|
15
|
-
rounding: SystemOne.jevRounding,
|
|
12
|
+
// Required for images; text-only requests are unchanged with it.
|
|
13
|
+
headers: { "TypeSafe-Danger-Zone-Images": "true", ...input.headers },
|
|
14
|
+
http: input.http,
|
|
16
15
|
});
|
|
17
|
-
|
|
16
|
+
const decision = (modelID) => route.model({ id: modelID });
|
|
17
|
+
return { id, decision, configure };
|
|
18
18
|
};
|
|
19
19
|
export const provider = configure();
|
|
20
|
-
export const
|
|
20
|
+
export const decision = provider.decision;
|
|
21
21
|
export * as TypeSafeAI from "./typesafe-ai.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EvaluationModel } from "../experimental/evaluation.js";
|
|
2
1
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
3
2
|
import type { ProviderPackage } from "../provider-package.js";
|
|
4
3
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
@@ -17,7 +16,7 @@ export interface GatewayOptions {
|
|
|
17
16
|
readonly order?: ReadonlyArray<string>;
|
|
18
17
|
/** Sort candidate providers by cost (`"cost"`), throughput (`"tps"`), or time-to-first-token (`"ttft"`). */
|
|
19
18
|
readonly sort?: "cost" | "tps" | "ttft" | (string & {});
|
|
20
|
-
/** Fallback models to try in order
|
|
19
|
+
/** Fallback models to try in order. */
|
|
21
20
|
readonly models?: ReadonlyArray<string | Readonly<Record<string, unknown>>>;
|
|
22
21
|
/** Restrict routing to providers with zero data retention agreements. */
|
|
23
22
|
readonly zeroDataRetention?: boolean;
|
|
@@ -64,10 +63,6 @@ export type ProviderOptionsInput = OpenResponsesProviderOptionsInput & Omit<Anth
|
|
|
64
63
|
/** Responses API count of stable input items to anchor for caching, sent as top-level `cache_anchor_items`. */
|
|
65
64
|
readonly cacheAnchorItems?: number;
|
|
66
65
|
};
|
|
67
|
-
export interface EvaluationOptions {
|
|
68
|
-
readonly [key: string]: unknown;
|
|
69
|
-
readonly gateway?: GatewayOptions;
|
|
70
|
-
}
|
|
71
66
|
export type Options = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
72
67
|
readonly baseURL?: string;
|
|
73
68
|
readonly providerOptions?: ProviderOptionsInput;
|
|
@@ -85,9 +80,7 @@ export declare const configure: (input?: Options) => {
|
|
|
85
80
|
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
86
81
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
87
82
|
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
88
|
-
|
|
89
|
-
evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
|
|
90
|
-
};
|
|
83
|
+
decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
91
84
|
configure: typeof configure;
|
|
92
85
|
};
|
|
93
86
|
export declare const provider: {
|
|
@@ -97,14 +90,10 @@ export declare const provider: {
|
|
|
97
90
|
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
98
91
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
99
92
|
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
100
|
-
|
|
101
|
-
evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
|
|
102
|
-
};
|
|
93
|
+
decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
103
94
|
configure: typeof configure;
|
|
104
95
|
};
|
|
105
|
-
export declare const
|
|
106
|
-
evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
|
|
107
|
-
};
|
|
96
|
+
export declare const decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
108
97
|
export declare const messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
109
98
|
export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
110
99
|
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { Headers, HttpClientRequest } from "effect/http";
|
|
3
|
-
import { EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationQuestion, EvaluationResponse, EvaluationRounding, } from "../experimental/evaluation.js";
|
|
4
2
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
5
3
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
6
4
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
5
|
+
import { OpenAIDecisions } from "../protocols/openai-decisions.js";
|
|
7
6
|
import { OpenAIImages } from "../protocols/openai-images.js";
|
|
8
|
-
import {
|
|
7
|
+
import { ProviderShared } from "../protocols/shared.js";
|
|
9
8
|
import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js";
|
|
10
|
-
import { Auth } from "../route/auth.js";
|
|
11
9
|
import { AuthOptions } from "../route/auth-options.js";
|
|
12
10
|
import { Route } from "../route/client.js";
|
|
13
11
|
import { Endpoint } from "../route/endpoint.js";
|
|
14
|
-
import { RequestExecutor } from "../route/executor.js";
|
|
15
12
|
import { Framing } from "../route/framing.js";
|
|
16
13
|
import { MediaRoute } from "../route/media.js";
|
|
17
|
-
import {
|
|
14
|
+
import { LLMRequest, ModelID, ProviderID, ProviderMetadata, ReasoningEffort } from "../schema/index.js";
|
|
18
15
|
export const id = ProviderID.make("vercel-ai-gateway");
|
|
19
16
|
const baseURL = "https://ai-gateway.vercel.sh/v1";
|
|
20
17
|
const GatewayOptionsSchema = Schema.Struct({
|
|
@@ -109,22 +106,6 @@ const chatRoute = route({
|
|
|
109
106
|
framing: OpenAIChat.framing,
|
|
110
107
|
});
|
|
111
108
|
export const routes = [messagesRoute, responsesRoute, chatRoute];
|
|
112
|
-
const Request = Schema.StructWithRest(Schema.Struct({
|
|
113
|
-
model: Schema.String,
|
|
114
|
-
state: EvaluationInput,
|
|
115
|
-
questions: Schema.Record(Schema.String, EvaluationQuestion),
|
|
116
|
-
providerOptions: Schema.optional(ProviderOptions),
|
|
117
|
-
}), [JsonObject]);
|
|
118
|
-
const Response = Schema.Struct({
|
|
119
|
-
model: optionalNull(Schema.String),
|
|
120
|
-
answers: Schema.Record(Schema.String, EvaluationAnswer),
|
|
121
|
-
usage: optionalNull(Schema.Struct({
|
|
122
|
-
inputTokens: optionalNull(Schema.Number),
|
|
123
|
-
outputTokens: optionalNull(Schema.Number),
|
|
124
|
-
})),
|
|
125
|
-
rounding: optionalNull(EvaluationRounding),
|
|
126
|
-
providerMetadata: optionalNull(ProviderMetadata),
|
|
127
|
-
});
|
|
128
109
|
export const configure = (input = {}) => {
|
|
129
110
|
const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
|
|
130
111
|
const configured = {
|
|
@@ -149,68 +130,20 @@ export const configure = (input = {}) => {
|
|
|
149
130
|
return chat(modelID);
|
|
150
131
|
return messages(modelID);
|
|
151
132
|
};
|
|
152
|
-
const evaluation = (modelID) => EvaluationModel.make({
|
|
153
|
-
id: modelID,
|
|
154
|
-
provider: id,
|
|
155
|
-
http: HttpOptions.make(input.http),
|
|
156
|
-
route: {
|
|
157
|
-
id: "vercel-evaluation",
|
|
158
|
-
evaluate: (req, send) => Effect.gen(function* () {
|
|
159
|
-
const url = new URL(`${(input.baseURL ?? baseURL).replace(/\/$/, "")}/evaluate`);
|
|
160
|
-
Object.entries(req.http?.query ?? {}).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
161
|
-
const body = yield* Schema.encodeUnknownEffect(Schema.fromJsonString(Request))({
|
|
162
|
-
...req.http?.body,
|
|
163
|
-
model: req.model.id,
|
|
164
|
-
state: req.state,
|
|
165
|
-
questions: req.questions,
|
|
166
|
-
providerOptions: req.options,
|
|
167
|
-
}).pipe(Effect.mapError((cause) => new AIError({ reason: new InvalidRequestError({ message: cause.message, cause }) })));
|
|
168
|
-
const headers = yield* Auth.toEffect(configured.auth)({
|
|
169
|
-
request: req,
|
|
170
|
-
method: "POST",
|
|
171
|
-
url: url.toString(),
|
|
172
|
-
body,
|
|
173
|
-
headers: Headers.fromInput({ ...input.headers, ...req.http?.headers }),
|
|
174
|
-
});
|
|
175
|
-
const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
|
|
176
|
-
const http = RequestExecutor.responseHttp(res);
|
|
177
|
-
const fail = (message, cause, body) => new AIError({
|
|
178
|
-
reason: new InvalidProviderOutputError({
|
|
179
|
-
route: "vercel-evaluation",
|
|
180
|
-
message,
|
|
181
|
-
body,
|
|
182
|
-
http,
|
|
183
|
-
cause,
|
|
184
|
-
}),
|
|
185
|
-
});
|
|
186
|
-
const text = yield* res.text.pipe(Effect.mapError((cause) => fail("Failed to read the Vercel AI Gateway evaluation response", cause)));
|
|
187
|
-
const data = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => fail("Vercel AI Gateway returned an invalid evaluation response", cause, text)));
|
|
188
|
-
const inputTokens = data.usage?.inputTokens ?? undefined;
|
|
189
|
-
const outputTokens = data.usage?.outputTokens ?? undefined;
|
|
190
|
-
const usage = data.usage
|
|
191
|
-
? new Usage({
|
|
192
|
-
inputTokens,
|
|
193
|
-
outputTokens,
|
|
194
|
-
totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
|
|
195
|
-
providerMetadata: { gateway: data.usage },
|
|
196
|
-
})
|
|
197
|
-
: undefined;
|
|
198
|
-
return new EvaluationResponse({
|
|
199
|
-
model: ModelID.make(data.model ?? req.model.id),
|
|
200
|
-
answers: data.answers,
|
|
201
|
-
usage,
|
|
202
|
-
rounding: data.rounding ?? undefined,
|
|
203
|
-
providerMetadata: data.providerMetadata ?? undefined,
|
|
204
|
-
});
|
|
205
|
-
}),
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
133
|
const media = MediaRoute.deployment({ ...input, baseURL: configured.endpoint.baseURL }, configured.auth);
|
|
209
134
|
const image = (modelID) => OpenAIImages.model({ ...media, id: modelID, provider: id });
|
|
210
|
-
|
|
135
|
+
const decisionRoute = OpenAIDecisions.route.with({
|
|
136
|
+
provider: id,
|
|
137
|
+
endpoint: { baseURL: configured.endpoint.baseURL },
|
|
138
|
+
auth: configured.auth,
|
|
139
|
+
headers: input.headers,
|
|
140
|
+
http: input.http,
|
|
141
|
+
});
|
|
142
|
+
const decision = (modelID) => decisionRoute.model({ id: modelID });
|
|
143
|
+
return { id, model, messages, responses, chat, image, decision, configure };
|
|
211
144
|
};
|
|
212
145
|
export const provider = configure();
|
|
213
|
-
export const
|
|
146
|
+
export const decision = provider.decision;
|
|
214
147
|
export const messages = provider.messages;
|
|
215
148
|
export const responses = provider.responses;
|
|
216
149
|
export const chat = provider.chat;
|
|
@@ -387,6 +387,23 @@ export declare const routes: (Route<{
|
|
|
387
387
|
readonly transformations?: {
|
|
388
388
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
389
389
|
} | undefined;
|
|
390
|
+
} | {
|
|
391
|
+
readonly type: "video";
|
|
392
|
+
readonly source: {
|
|
393
|
+
readonly type: "base64";
|
|
394
|
+
readonly media_type: string;
|
|
395
|
+
readonly data: string;
|
|
396
|
+
} | {
|
|
397
|
+
readonly type: "url";
|
|
398
|
+
readonly url: string;
|
|
399
|
+
} | {
|
|
400
|
+
readonly type: "file";
|
|
401
|
+
readonly file_id: string;
|
|
402
|
+
};
|
|
403
|
+
readonly cache_control?: {
|
|
404
|
+
readonly type: "ephemeral";
|
|
405
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
406
|
+
} | undefined;
|
|
390
407
|
} | {
|
|
391
408
|
readonly type: "document";
|
|
392
409
|
readonly source: {
|
|
@@ -443,6 +460,23 @@ export declare const routes: (Route<{
|
|
|
443
460
|
readonly transformations?: {
|
|
444
461
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
445
462
|
} | undefined;
|
|
463
|
+
} | {
|
|
464
|
+
readonly type: "video";
|
|
465
|
+
readonly source: {
|
|
466
|
+
readonly type: "base64";
|
|
467
|
+
readonly media_type: string;
|
|
468
|
+
readonly data: string;
|
|
469
|
+
} | {
|
|
470
|
+
readonly type: "url";
|
|
471
|
+
readonly url: string;
|
|
472
|
+
} | {
|
|
473
|
+
readonly type: "file";
|
|
474
|
+
readonly file_id: string;
|
|
475
|
+
};
|
|
476
|
+
readonly cache_control?: {
|
|
477
|
+
readonly type: "ephemeral";
|
|
478
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
479
|
+
} | undefined;
|
|
446
480
|
} | {
|
|
447
481
|
readonly type: "document";
|
|
448
482
|
readonly source: {
|
package/dist/route/client.js
CHANGED
|
@@ -216,6 +216,17 @@ const prepareRequest = (request) => {
|
|
|
216
216
|
: LLMRequest.update(resolved, { http: mergeHttpOptions(new HttpOptions({ headers }), resolved.http) });
|
|
217
217
|
};
|
|
218
218
|
const compile = Effect.fn("LLM.compile")(function* (request, options) {
|
|
219
|
+
const references = request.messages.flatMap((message) => message.content.flatMap((part) => {
|
|
220
|
+
if (part.type === "media") {
|
|
221
|
+
const source = part.media.source;
|
|
222
|
+
return source.type === "url" ? [source.url] : source.type === "ref" ? [source.id] : [];
|
|
223
|
+
}
|
|
224
|
+
if (part.type !== "tool-result" || part.result.type !== "content")
|
|
225
|
+
return [];
|
|
226
|
+
return part.result.value.flatMap((item) => (item.type === "file" ? [item.uri] : []));
|
|
227
|
+
}));
|
|
228
|
+
if (references.some((reference) => /^\s*file:/i.test(reference)))
|
|
229
|
+
return yield* ProviderShared.invalidRequest("Local file references must be read with Media.file(path) before sending");
|
|
219
230
|
const resolved = prepareRequest(request);
|
|
220
231
|
const route = resolved.model.route;
|
|
221
232
|
const body = yield* route.body.from(resolved);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { HttpClientResponse } from "effect/http";
|
|
3
|
+
import { DecisionModel, DecisionModelCompatibility, type DecisionOptions, type DecisionRequestFor, type DecisionResponse } from "../decision.js";
|
|
4
|
+
import { HttpOptions, ProviderID, type AIError } from "../schema/index.js";
|
|
5
|
+
import { Auth } from "./auth.js";
|
|
6
|
+
import { Endpoint } from "./endpoint.js";
|
|
7
|
+
import { MediaProtocol } from "./media-protocol.js";
|
|
8
|
+
/** One decision API: how a request becomes its JSON body and how its response becomes a `DecisionResponse`. */
|
|
9
|
+
export interface Protocol {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** The host only takes inline data, so URL media is downloaded before `body.from`. */
|
|
13
|
+
readonly inlineMedia?: boolean;
|
|
14
|
+
readonly body: {
|
|
15
|
+
readonly from: (request: DecisionRequestFor) => Effect.Effect<Record<string, unknown>, AIError>;
|
|
16
|
+
};
|
|
17
|
+
readonly response: {
|
|
18
|
+
readonly decode: (response: HttpClientResponse.HttpClientResponse, context: {
|
|
19
|
+
readonly request: DecisionRequestFor;
|
|
20
|
+
readonly providerMetadataKey: string;
|
|
21
|
+
}) => Effect.Effect<DecisionResponse, AIError>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare const protocol: (input: Protocol) => Protocol;
|
|
25
|
+
export interface Patch {
|
|
26
|
+
readonly id?: string;
|
|
27
|
+
readonly provider?: string | ProviderID;
|
|
28
|
+
/** ProviderMetadata namespace for responses; defaults to the provider. */
|
|
29
|
+
readonly providerMetadataKey?: string;
|
|
30
|
+
readonly endpoint?: Endpoint.EndpointPatch<MediaProtocol.Body, DecisionRequestFor>;
|
|
31
|
+
readonly auth?: Auth.Definition;
|
|
32
|
+
readonly headers?: Record<string, string>;
|
|
33
|
+
readonly http?: HttpOptions.Input;
|
|
34
|
+
}
|
|
35
|
+
export interface Route {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly provider: ProviderID;
|
|
38
|
+
readonly providerMetadataKey: string;
|
|
39
|
+
readonly protocol: Protocol;
|
|
40
|
+
readonly endpoint: Endpoint.Definition<MediaProtocol.Body, DecisionRequestFor>;
|
|
41
|
+
readonly auth: Auth.Definition;
|
|
42
|
+
readonly headers?: Record<string, string>;
|
|
43
|
+
readonly http?: HttpOptions;
|
|
44
|
+
readonly with: (patch: Patch) => Route;
|
|
45
|
+
readonly model: <Options extends DecisionOptions = DecisionOptions>(input: {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly compatibility?: DecisionModelCompatibility.Input;
|
|
48
|
+
}) => DecisionModel<Options>;
|
|
49
|
+
}
|
|
50
|
+
export interface MakeInput extends Omit<Patch, "endpoint"> {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly provider: string | ProviderID;
|
|
53
|
+
readonly protocol: Protocol;
|
|
54
|
+
readonly endpoint: Endpoint.Definition<MediaProtocol.Body, DecisionRequestFor>;
|
|
55
|
+
}
|
|
56
|
+
export declare const make: (input: MakeInput) => Route;
|
|
57
|
+
export * as DecisionRoute from "./decision.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { DecisionModel, DecisionModelCompatibility, } from "../decision.js";
|
|
3
|
+
import { HttpOptions, ProviderID } from "../schema/index.js";
|
|
4
|
+
import { Auth } from "./auth.js";
|
|
5
|
+
import { Endpoint } from "./endpoint.js";
|
|
6
|
+
import { RequestExecutorService } from "./executor-service.js";
|
|
7
|
+
import { MediaProtocol } from "./media-protocol.js";
|
|
8
|
+
import { MediaRoute } from "./media.js";
|
|
9
|
+
export const protocol = (input) => input;
|
|
10
|
+
export const make = (input) => {
|
|
11
|
+
const provider = ProviderID.make(input.provider);
|
|
12
|
+
const route = {
|
|
13
|
+
id: input.id,
|
|
14
|
+
provider,
|
|
15
|
+
providerMetadataKey: input.providerMetadataKey ?? provider,
|
|
16
|
+
protocol: input.protocol,
|
|
17
|
+
endpoint: input.endpoint,
|
|
18
|
+
auth: input.auth ?? Auth.none,
|
|
19
|
+
headers: input.headers,
|
|
20
|
+
http: HttpOptions.make(input.http),
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
...route,
|
|
24
|
+
with: (patch) => make({
|
|
25
|
+
...route,
|
|
26
|
+
...patch,
|
|
27
|
+
// A new provider gets its own metadata key unless the patch names one.
|
|
28
|
+
providerMetadataKey: patch.providerMetadataKey ?? (patch.provider === undefined ? route.providerMetadataKey : undefined),
|
|
29
|
+
endpoint: patch.endpoint === undefined ? route.endpoint : Endpoint.merge(route.endpoint, patch.endpoint),
|
|
30
|
+
headers: patch.headers === undefined ? route.headers : { ...route.headers, ...patch.headers },
|
|
31
|
+
http: patch.http === undefined ? route.http : HttpOptions.make(patch.http),
|
|
32
|
+
}),
|
|
33
|
+
model: (model) => {
|
|
34
|
+
const send = transport(route);
|
|
35
|
+
return DecisionModel.make({
|
|
36
|
+
id: model.id,
|
|
37
|
+
provider,
|
|
38
|
+
http: route.http,
|
|
39
|
+
compatibility: model.compatibility === undefined ? undefined : DecisionModelCompatibility.make(model.compatibility),
|
|
40
|
+
route: { id: route.id, generate: send },
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// The HTTP plumbing (URL, query, auth, headers, `http` overlays, surrogate sanitizing) is the one media routes use.
|
|
46
|
+
const transport = (route) => {
|
|
47
|
+
const identity = MediaProtocol.identity({ id: route.id, name: route.protocol.name, provider: route.provider });
|
|
48
|
+
const composed = MediaRoute.inline({
|
|
49
|
+
protocol: MediaProtocol.inline(identity, {
|
|
50
|
+
body: {
|
|
51
|
+
from: (request) => route.protocol.body.from(request).pipe(Effect.map((body) => MediaProtocol.json(body))),
|
|
52
|
+
},
|
|
53
|
+
response: {
|
|
54
|
+
decode: (response, context) => route.protocol.response.decode(response, {
|
|
55
|
+
request: context.request,
|
|
56
|
+
providerMetadataKey: route.providerMetadataKey,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
endpoint: route.endpoint,
|
|
61
|
+
auth: route.auth,
|
|
62
|
+
headers: route.headers,
|
|
63
|
+
});
|
|
64
|
+
return Effect.fnUntraced(function* (request, execute) {
|
|
65
|
+
if (!route.protocol.inlineMedia)
|
|
66
|
+
return yield* composed.generate(request, execute);
|
|
67
|
+
const input = yield* Effect.forEach(request.input, (part) => materialize(part, execute));
|
|
68
|
+
return yield* composed.generate({ ...request, input }, execute);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const materialize = (part, execute) => part.type === "media" && part.media.source.type === "url"
|
|
72
|
+
? part.media.materialize().pipe(Effect.provideService(RequestExecutorService, { execute }), Effect.map((media) => ({ ...part, media })))
|
|
73
|
+
: Effect.succeed(part);
|
|
74
|
+
export * as DecisionRoute from "./decision.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-21800",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
37
37
|
"@effect/platform-node": "4.0.1",
|
|
38
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
38
|
+
"@opencode/http-recorder": "0.0.0-dev-21800",
|
|
39
39
|
"@tsconfig/bun": "1.0.9",
|
|
40
40
|
"@types/bun": "1.4.3",
|
|
41
41
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
46
46
|
"@smithy/eventstream-codec": "4.2.14",
|
|
47
47
|
"@smithy/util-utf8": "4.2.2",
|
|
48
|
-
"@opencode/schema": "0.0.0-dev-
|
|
48
|
+
"@opencode/schema": "0.0.0-dev-21800",
|
|
49
49
|
"aws4fetch": "1.0.20",
|
|
50
50
|
"effect": "4.0.1",
|
|
51
51
|
"google-auth-library": "10.5.0"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EvaluationModel, type EvaluationRounding } from "./evaluation.js";
|
|
2
|
-
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import type { ProviderID } from "../schema/index.js";
|
|
4
|
-
export interface ModelInput extends MediaRoute.ModelInput {
|
|
5
|
-
/** Also the provider metadata key. */
|
|
6
|
-
readonly provider: ProviderID;
|
|
7
|
-
/** The Run API base, `.../client/v4/accounts/{account}/ai/run`. */
|
|
8
|
-
readonly baseURL: string;
|
|
9
|
-
readonly rounding?: EvaluationRounding;
|
|
10
|
-
}
|
|
11
|
-
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One request body as `input`. */
|
|
12
|
-
export declare const model: (input: ModelInput) => EvaluationModel<import("./evaluation.js").EvaluationOptions>;
|
|
13
|
-
export declare const CloudflareRunEvaluation: {
|
|
14
|
-
readonly model: typeof model;
|
|
15
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { EvaluationModel, } from "./evaluation.js";
|
|
3
|
-
import { SystemOne } from "./system-one.js";
|
|
4
|
-
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
6
|
-
import { MediaRoute } from "../route/media.js";
|
|
7
|
-
// Workers AI models answer with the System One response; third-party models such as TypeSafe Jev wrap it in a
|
|
8
|
-
// completed run record.
|
|
9
|
-
const Envelope = Schema.Struct({
|
|
10
|
-
result: Schema.Union([
|
|
11
|
-
SystemOne.Response,
|
|
12
|
-
Schema.Struct({ state: Schema.Literal("Completed"), result: SystemOne.Response }),
|
|
13
|
-
]),
|
|
14
|
-
});
|
|
15
|
-
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One request body as `input`. */
|
|
16
|
-
export const model = (input) => {
|
|
17
|
-
const route = MediaProtocol.identity({
|
|
18
|
-
id: "cloudflare-run-evaluation",
|
|
19
|
-
name: "Cloudflare Run",
|
|
20
|
-
provider: input.provider,
|
|
21
|
-
});
|
|
22
|
-
const decodeEnvelope = route.decodeJson(Envelope);
|
|
23
|
-
const composed = MediaRoute.inline({
|
|
24
|
-
protocol: MediaProtocol.inline(route, {
|
|
25
|
-
body: {
|
|
26
|
-
from: (request) => SystemOne.encodeInput(request).pipe(Effect.map((body) => MediaProtocol.json({ model: request.model.id, input: body }))),
|
|
27
|
-
},
|
|
28
|
-
response: {
|
|
29
|
-
decode: (response) => decodeEnvelope(response).pipe(Effect.map((output) => SystemOne.toResponse("answers" in output.value.result ? output.value.result : output.value.result.result, input.provider, input.rounding))),
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
endpoint: Endpoint.path("", { baseURL: input.baseURL }),
|
|
33
|
-
auth: input.auth,
|
|
34
|
-
headers: input.headers,
|
|
35
|
-
});
|
|
36
|
-
return EvaluationModel.make({
|
|
37
|
-
id: input.id,
|
|
38
|
-
provider: input.provider,
|
|
39
|
-
http: input.http,
|
|
40
|
-
route: { id: composed.id, evaluate: composed.generate },
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
export const CloudflareRunEvaluation = { model };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { RequestExecutor } from "../route/executor.js";
|
|
3
|
-
import { AIError } from "../schema/index.js";
|
|
4
|
-
import { type EvaluationOptions, type EvaluationQuestions, type EvaluationRequestFor, type EvaluationResponseFor } from "./evaluation.js";
|
|
5
|
-
export type Execute = RequestExecutor.Interface["execute"];
|
|
6
|
-
export interface Interface {
|
|
7
|
-
readonly evaluate: <Options extends EvaluationOptions, const Questions extends EvaluationQuestions>(request: EvaluationRequestFor<Options, Questions>) => Effect.Effect<EvaluationResponseFor<Questions>, AIError>;
|
|
8
|
-
}
|
|
9
|
-
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/Experimental/EvaluationClient", Interface>;
|
|
10
|
-
export declare class Service extends Service_base {
|
|
11
|
-
}
|
|
12
|
-
export declare const evaluate: <Options extends EvaluationOptions, const Questions extends EvaluationQuestions>(request: EvaluationRequestFor<Options, Questions>) => Effect.Effect<EvaluationResponseFor<Questions>, AIError, Service>;
|
|
13
|
-
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
14
|
-
export declare const fetchLayer: Layer.Layer<import("../route/executor-service.js").RequestExecutorService | Service, never, never>;
|
|
15
|
-
export declare const EvaluationClient: {
|
|
16
|
-
readonly Service: typeof Service;
|
|
17
|
-
readonly layer: Layer.Layer<Service, never, import("../route/executor-service.js").RequestExecutorService>;
|
|
18
|
-
readonly fetchLayer: Layer.Layer<import("../route/executor-service.js").RequestExecutorService | Service, never, never>;
|
|
19
|
-
readonly evaluate: typeof evaluate;
|
|
20
|
-
};
|
|
21
|
-
export {};
|