@opencode/ai 0.0.0-dev-21392 → 0.0.0-dev-21406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/experimental/evaluation.d.ts +7 -6
- package/dist/experimental/evaluation.js +2 -3
- package/dist/experimental/realtime.js +2 -2
- package/dist/experimental/system-one.js +8 -8
- package/dist/llm.d.ts +2 -4
- package/dist/llm.js +2 -2
- package/dist/media.js +3 -3
- package/dist/promise.d.ts +1 -1
- package/dist/promise.js +3 -5
- package/dist/protocols/alibaba-chat.d.ts +6 -6
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-messages.d.ts +1 -1
- package/dist/protocols/alibaba-messages.js +1 -1
- package/dist/protocols/alibaba-responses.d.ts +3 -3
- package/dist/protocols/anthropic-messages.js +10 -12
- package/dist/protocols/bedrock-converse.js +2 -2
- package/dist/protocols/cohere-chat.d.ts +6 -2
- package/dist/protocols/cohere-chat.js +2 -2
- package/dist/protocols/gemini.d.ts +12 -2
- package/dist/protocols/gemini.js +10 -13
- package/dist/protocols/google-interactions.d.ts +2 -1
- package/dist/protocols/google-interactions.js +14 -9
- package/dist/protocols/meta-responses.d.ts +6 -6
- package/dist/protocols/mistral-chat.js +1 -4
- package/dist/protocols/open-responses.d.ts +21 -21
- package/dist/protocols/open-responses.js +3 -3
- package/dist/protocols/openai-chat.d.ts +8 -7
- package/dist/protocols/openai-chat.js +4 -5
- package/dist/protocols/openai-compatible-responses.d.ts +3 -3
- package/dist/protocols/openai-responses.d.ts +18 -18
- package/dist/protocols/utils/open-responses-options.d.ts +8 -8
- package/dist/protocols/utils/open-responses-options.js +4 -6
- package/dist/protocols/utils/partial-json.js +5 -4
- package/dist/protocols/utils/tool-schema.d.ts +0 -3
- package/dist/protocols/utils/tool-schema.js +0 -4
- package/dist/protocols/venice-chat.js +6 -6
- package/dist/protocols/xai-images.js +3 -4
- package/dist/protocols/xai-responses.d.ts +3 -3
- package/dist/provider-error.js +3 -4
- package/dist/providers/alibaba.d.ts +30 -30
- package/dist/providers/amazon-bedrock-mantle.d.ts +3 -3
- package/dist/providers/amazon-bedrock.d.ts +7 -7
- package/dist/providers/azure.d.ts +6 -6
- package/dist/providers/cloudflare-ai-gateway.d.ts +7 -7
- package/dist/providers/cloudflare-ai-gateway.js +2 -4
- package/dist/providers/cohere.d.ts +6 -2
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +18 -18
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google.d.ts +66 -66
- package/dist/providers/meta.d.ts +21 -21
- package/dist/providers/minimax.d.ts +195 -195
- package/dist/providers/moonshot.d.ts +3 -3
- package/dist/providers/openai-compatible-responses.d.ts +3 -3
- package/dist/providers/openai-options.d.ts +3 -3
- package/dist/providers/openai.d.ts +3 -3
- package/dist/providers/vercel-ai-gateway.js +7 -6
- package/dist/providers/zai-coding-plan.d.ts +3 -3
- package/dist/route/client.d.ts +0 -216
- package/dist/route/client.js +1 -5
- package/dist/route/executor-service.d.ts +6 -2
- package/dist/route/executor-service.js +7 -0
- package/dist/route/executor.d.ts +2 -3
- package/dist/route/executor.js +2 -8
- package/dist/route/media-protocol.d.ts +1 -1
- package/dist/route/media-protocol.js +3 -3
- package/dist/route/transport/http.js +5 -8
- package/dist/route/transport/websocket.d.ts +0 -24
- package/dist/route/transport/websocket.js +0 -50
- package/package.json +3 -3
- package/dist/protocols/utils/openai-options.d.ts +0 -16
- package/dist/protocols/utils/openai-options.js +0 -15
|
@@ -174,15 +174,15 @@ export declare const routes: import("../route/client.js").Route<{
|
|
|
174
174
|
} | undefined;
|
|
175
175
|
readonly top_logprobs?: number | undefined;
|
|
176
176
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
177
|
-
readonly service_tier?: import("../
|
|
177
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
178
178
|
readonly prompt_cache_key?: string | undefined;
|
|
179
|
-
readonly include?: readonly import("../
|
|
179
|
+
readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
180
180
|
readonly reasoning?: {
|
|
181
181
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
182
182
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
183
183
|
} | undefined;
|
|
184
184
|
readonly text?: {
|
|
185
|
-
readonly verbosity?: import("../
|
|
185
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
186
186
|
} | undefined;
|
|
187
187
|
readonly max_output_tokens?: number | undefined;
|
|
188
188
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ProviderOptions } from "../schema/index.js";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Options } from "../protocols/utils/open-responses-options.js";
|
|
2
|
+
import type { Options, ResponseIncludable, ServiceTier } from "../protocols/utils/open-responses-options.js";
|
|
4
3
|
import type { ContextManagement } from "../protocols/openai-responses.js";
|
|
5
|
-
export type
|
|
4
|
+
export type OpenAIResponseIncludable = ResponseIncludable;
|
|
5
|
+
export type OpenAIServiceTier = ServiceTier | "scale" | "fast" | "ultrafast";
|
|
6
6
|
export type OpenAIOptionsInput = Omit<Options, "serviceTier"> & {
|
|
7
7
|
/** Advanced in-band compaction. The caller owns checkpoint persistence and recovery. */
|
|
8
8
|
readonly contextManagement?: ContextManagement;
|
|
@@ -266,15 +266,15 @@ export declare const routes: (Route<{
|
|
|
266
266
|
} | undefined;
|
|
267
267
|
readonly top_logprobs?: number | undefined;
|
|
268
268
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
269
|
-
readonly service_tier?:
|
|
269
|
+
readonly service_tier?: OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
270
270
|
readonly prompt_cache_key?: string | undefined;
|
|
271
|
-
readonly include?: readonly
|
|
271
|
+
readonly include?: readonly OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
272
272
|
readonly reasoning?: {
|
|
273
273
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
274
274
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
275
275
|
} | undefined;
|
|
276
276
|
readonly text?: {
|
|
277
|
-
readonly verbosity?:
|
|
277
|
+
readonly verbosity?: OpenString<"high" | "low" | "medium"> | undefined;
|
|
278
278
|
} | undefined;
|
|
279
279
|
readonly max_output_tokens?: number | undefined;
|
|
280
280
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -4,19 +4,20 @@ import { EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationQuestion,
|
|
|
4
4
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
5
5
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
6
6
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
7
|
-
import { optionalNull, ProviderShared } from "../protocols/shared.js";
|
|
7
|
+
import { JsonObject, optionalNull, ProviderShared } from "../protocols/shared.js";
|
|
8
8
|
import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js";
|
|
9
9
|
import { Auth } from "../route/auth.js";
|
|
10
10
|
import { AuthOptions } from "../route/auth-options.js";
|
|
11
11
|
import { Route } from "../route/client.js";
|
|
12
12
|
import { Endpoint } from "../route/endpoint.js";
|
|
13
|
+
import { RequestExecutor } from "../route/executor.js";
|
|
13
14
|
import { Framing } from "../route/framing.js";
|
|
14
|
-
import { AIError,
|
|
15
|
+
import { AIError, HttpOptions, InvalidProviderOutputError, InvalidRequestError, LLMRequest, ModelID, ProviderID, ProviderMetadata, ProviderOptions, ReasoningEffort, Usage, } from "../schema/index.js";
|
|
15
16
|
export const id = ProviderID.make("vercel-ai-gateway");
|
|
16
17
|
const baseURL = "https://ai-gateway.vercel.sh/v1";
|
|
17
18
|
const GatewayOptionsSchema = Schema.Struct({
|
|
18
19
|
gateway: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
19
|
-
upstream: Schema.optional(
|
|
20
|
+
upstream: Schema.optional(ProviderMetadata),
|
|
20
21
|
reasoningEffort: Schema.optional(ReasoningEffort),
|
|
21
22
|
thinking: Schema.optional(Schema.Struct({
|
|
22
23
|
type: Schema.String,
|
|
@@ -110,8 +111,8 @@ const Request = Schema.StructWithRest(Schema.Struct({
|
|
|
110
111
|
model: Schema.String,
|
|
111
112
|
state: EvaluationInput,
|
|
112
113
|
questions: Schema.Record(Schema.String, EvaluationQuestion),
|
|
113
|
-
providerOptions: Schema.optional(
|
|
114
|
-
}), [
|
|
114
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
115
|
+
}), [JsonObject]);
|
|
115
116
|
const Response = Schema.Struct({
|
|
116
117
|
model: optionalNull(Schema.String),
|
|
117
118
|
answers: Schema.Record(Schema.String, EvaluationAnswer),
|
|
@@ -170,7 +171,7 @@ export const configure = (input = {}) => {
|
|
|
170
171
|
headers: Headers.fromInput({ ...input.headers, ...req.http?.headers }),
|
|
171
172
|
});
|
|
172
173
|
const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
|
|
173
|
-
const http =
|
|
174
|
+
const http = RequestExecutor.responseHttp(res);
|
|
174
175
|
const fail = (message, cause, body) => new AIError({
|
|
175
176
|
reason: new InvalidProviderOutputError({
|
|
176
177
|
route: "vercel-evaluation",
|
|
@@ -178,15 +178,15 @@ export declare const routes: (Route<{
|
|
|
178
178
|
} | undefined;
|
|
179
179
|
readonly top_logprobs?: number | undefined;
|
|
180
180
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
181
|
-
readonly service_tier?: import("../
|
|
181
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
182
182
|
readonly prompt_cache_key?: string | undefined;
|
|
183
|
-
readonly include?: readonly import("../
|
|
183
|
+
readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
184
184
|
readonly reasoning?: {
|
|
185
185
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
186
186
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
187
187
|
} | undefined;
|
|
188
188
|
readonly text?: {
|
|
189
|
-
readonly verbosity?: import("../
|
|
189
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
190
190
|
} | undefined;
|
|
191
191
|
readonly max_output_tokens?: number | undefined;
|
|
192
192
|
readonly max_tool_calls?: number | undefined;
|
package/dist/route/client.d.ts
CHANGED
|
@@ -214,222 +214,6 @@ export declare function stream(request: LLMRequest, options?: StreamOptions): St
|
|
|
214
214
|
export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
|
|
215
215
|
export declare function compact(request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, Service>;
|
|
216
216
|
export declare function compact(request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, Service>;
|
|
217
|
-
export declare const streamRequest: (request: LLMRequest, options?: StreamOptions) => Stream.Stream<{
|
|
218
|
-
readonly type: "step-start";
|
|
219
|
-
readonly index: number;
|
|
220
|
-
} | {
|
|
221
|
-
readonly type: "text-start";
|
|
222
|
-
readonly id: string;
|
|
223
|
-
readonly providerMetadata?: {
|
|
224
|
-
readonly [x: string]: {
|
|
225
|
-
readonly [x: string]: unknown;
|
|
226
|
-
};
|
|
227
|
-
} | undefined;
|
|
228
|
-
} | {
|
|
229
|
-
readonly type: "text-delta";
|
|
230
|
-
readonly id: string;
|
|
231
|
-
readonly text: string;
|
|
232
|
-
readonly providerMetadata?: {
|
|
233
|
-
readonly [x: string]: {
|
|
234
|
-
readonly [x: string]: unknown;
|
|
235
|
-
};
|
|
236
|
-
} | undefined;
|
|
237
|
-
} | {
|
|
238
|
-
readonly type: "text-end";
|
|
239
|
-
readonly id: string;
|
|
240
|
-
readonly text?: string | undefined;
|
|
241
|
-
readonly providerMetadata?: {
|
|
242
|
-
readonly [x: string]: {
|
|
243
|
-
readonly [x: string]: unknown;
|
|
244
|
-
};
|
|
245
|
-
} | undefined;
|
|
246
|
-
} | {
|
|
247
|
-
readonly type: "reasoning-start";
|
|
248
|
-
readonly id: string;
|
|
249
|
-
readonly providerMetadata?: {
|
|
250
|
-
readonly [x: string]: {
|
|
251
|
-
readonly [x: string]: unknown;
|
|
252
|
-
};
|
|
253
|
-
} | undefined;
|
|
254
|
-
} | {
|
|
255
|
-
readonly type: "reasoning-delta";
|
|
256
|
-
readonly id: string;
|
|
257
|
-
readonly text: string;
|
|
258
|
-
readonly providerMetadata?: {
|
|
259
|
-
readonly [x: string]: {
|
|
260
|
-
readonly [x: string]: unknown;
|
|
261
|
-
};
|
|
262
|
-
} | undefined;
|
|
263
|
-
} | {
|
|
264
|
-
readonly type: "reasoning-end";
|
|
265
|
-
readonly id: string;
|
|
266
|
-
readonly text?: string | undefined;
|
|
267
|
-
readonly providerMetadata?: {
|
|
268
|
-
readonly [x: string]: {
|
|
269
|
-
readonly [x: string]: unknown;
|
|
270
|
-
};
|
|
271
|
-
} | undefined;
|
|
272
|
-
} | {
|
|
273
|
-
readonly type: "tool-input-start";
|
|
274
|
-
readonly id: string;
|
|
275
|
-
readonly name: string;
|
|
276
|
-
readonly namespace?: string | undefined;
|
|
277
|
-
readonly providerExecuted?: boolean | undefined;
|
|
278
|
-
readonly providerMetadata?: {
|
|
279
|
-
readonly [x: string]: {
|
|
280
|
-
readonly [x: string]: unknown;
|
|
281
|
-
};
|
|
282
|
-
} | undefined;
|
|
283
|
-
} | {
|
|
284
|
-
readonly type: "tool-input-delta";
|
|
285
|
-
readonly id: string;
|
|
286
|
-
readonly name: string;
|
|
287
|
-
readonly namespace?: string | undefined;
|
|
288
|
-
readonly text: string;
|
|
289
|
-
readonly input?: unknown;
|
|
290
|
-
} | {
|
|
291
|
-
readonly type: "tool-input-end";
|
|
292
|
-
readonly id: string;
|
|
293
|
-
readonly name: string;
|
|
294
|
-
readonly namespace?: string | undefined;
|
|
295
|
-
readonly providerMetadata?: {
|
|
296
|
-
readonly [x: string]: {
|
|
297
|
-
readonly [x: string]: unknown;
|
|
298
|
-
};
|
|
299
|
-
} | undefined;
|
|
300
|
-
} | {
|
|
301
|
-
readonly type: "tool-input-error";
|
|
302
|
-
readonly id: string;
|
|
303
|
-
readonly name: string;
|
|
304
|
-
readonly namespace?: string | undefined;
|
|
305
|
-
readonly raw: string;
|
|
306
|
-
} | {
|
|
307
|
-
readonly type: "tool-call";
|
|
308
|
-
readonly id: string;
|
|
309
|
-
readonly name: string;
|
|
310
|
-
readonly namespace?: string | undefined;
|
|
311
|
-
readonly input: unknown;
|
|
312
|
-
readonly providerExecuted?: boolean | undefined;
|
|
313
|
-
readonly providerMetadata?: {
|
|
314
|
-
readonly [x: string]: {
|
|
315
|
-
readonly [x: string]: unknown;
|
|
316
|
-
};
|
|
317
|
-
} | undefined;
|
|
318
|
-
} | {
|
|
319
|
-
readonly type: "tool-result";
|
|
320
|
-
readonly id: string;
|
|
321
|
-
readonly name: string;
|
|
322
|
-
readonly namespace?: string | undefined;
|
|
323
|
-
readonly result: {
|
|
324
|
-
readonly type: "json";
|
|
325
|
-
readonly value: unknown;
|
|
326
|
-
} | {
|
|
327
|
-
readonly type: "text";
|
|
328
|
-
readonly value: unknown;
|
|
329
|
-
} | {
|
|
330
|
-
readonly type: "error";
|
|
331
|
-
readonly value: unknown;
|
|
332
|
-
} | {
|
|
333
|
-
readonly type: "content";
|
|
334
|
-
readonly value: readonly ({
|
|
335
|
-
readonly type: "text";
|
|
336
|
-
readonly text: string;
|
|
337
|
-
} | {
|
|
338
|
-
readonly type: "file";
|
|
339
|
-
readonly uri: string;
|
|
340
|
-
readonly mime: string;
|
|
341
|
-
readonly name?: string | undefined;
|
|
342
|
-
})[];
|
|
343
|
-
};
|
|
344
|
-
readonly output?: {
|
|
345
|
-
readonly structured: unknown;
|
|
346
|
-
readonly content: readonly ({
|
|
347
|
-
readonly type: "text";
|
|
348
|
-
readonly text: string;
|
|
349
|
-
} | {
|
|
350
|
-
readonly type: "file";
|
|
351
|
-
readonly uri: string;
|
|
352
|
-
readonly mime: string;
|
|
353
|
-
readonly name?: string | undefined;
|
|
354
|
-
})[];
|
|
355
|
-
} | undefined;
|
|
356
|
-
readonly providerExecuted?: boolean | undefined;
|
|
357
|
-
readonly providerMetadata?: {
|
|
358
|
-
readonly [x: string]: {
|
|
359
|
-
readonly [x: string]: unknown;
|
|
360
|
-
};
|
|
361
|
-
} | undefined;
|
|
362
|
-
} | {
|
|
363
|
-
readonly type: "tool-error";
|
|
364
|
-
readonly id: string;
|
|
365
|
-
readonly name: string;
|
|
366
|
-
readonly namespace?: string | undefined;
|
|
367
|
-
readonly message: string;
|
|
368
|
-
readonly error?: unknown;
|
|
369
|
-
readonly providerMetadata?: {
|
|
370
|
-
readonly [x: string]: {
|
|
371
|
-
readonly [x: string]: unknown;
|
|
372
|
-
};
|
|
373
|
-
} | undefined;
|
|
374
|
-
} | {
|
|
375
|
-
readonly type: "step-finish";
|
|
376
|
-
readonly index: number;
|
|
377
|
-
readonly reason: {
|
|
378
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
379
|
-
readonly raw?: string | undefined;
|
|
380
|
-
readonly category?: string | undefined;
|
|
381
|
-
readonly explanation?: string | undefined;
|
|
382
|
-
};
|
|
383
|
-
readonly usage?: import("../schema/events.js").Usage | undefined;
|
|
384
|
-
readonly providerMetadata?: {
|
|
385
|
-
readonly [x: string]: {
|
|
386
|
-
readonly [x: string]: unknown;
|
|
387
|
-
};
|
|
388
|
-
} | undefined;
|
|
389
|
-
} | {
|
|
390
|
-
readonly type: "finish";
|
|
391
|
-
readonly reason: {
|
|
392
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
393
|
-
readonly raw?: string | undefined;
|
|
394
|
-
readonly category?: string | undefined;
|
|
395
|
-
readonly explanation?: string | undefined;
|
|
396
|
-
};
|
|
397
|
-
readonly usage?: import("../schema/events.js").Usage | undefined;
|
|
398
|
-
readonly providerMetadata?: {
|
|
399
|
-
readonly [x: string]: {
|
|
400
|
-
readonly [x: string]: unknown;
|
|
401
|
-
};
|
|
402
|
-
} | undefined;
|
|
403
|
-
} | {
|
|
404
|
-
readonly type: "media";
|
|
405
|
-
readonly media: import("../media.js").Asset;
|
|
406
|
-
readonly providerMetadata?: {
|
|
407
|
-
readonly [x: string]: {
|
|
408
|
-
readonly [x: string]: unknown;
|
|
409
|
-
};
|
|
410
|
-
} | undefined;
|
|
411
|
-
} | {
|
|
412
|
-
readonly type: "provider-error";
|
|
413
|
-
readonly message: string;
|
|
414
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
415
|
-
readonly providerMetadata?: {
|
|
416
|
-
readonly [x: string]: {
|
|
417
|
-
readonly [x: string]: unknown;
|
|
418
|
-
};
|
|
419
|
-
} | undefined;
|
|
420
|
-
} | ({
|
|
421
|
-
readonly type: "compaction";
|
|
422
|
-
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
423
|
-
readonly id?: string | undefined;
|
|
424
|
-
readonly encrypted?: string | undefined;
|
|
425
|
-
readonly text?: string | null | undefined;
|
|
426
|
-
} & ({
|
|
427
|
-
readonly encrypted: string;
|
|
428
|
-
readonly text?: never;
|
|
429
|
-
} | {
|
|
430
|
-
readonly text: string | null;
|
|
431
|
-
readonly encrypted?: never;
|
|
432
|
-
})), AIError, LLMClientService>;
|
|
433
217
|
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
434
218
|
export declare const Route: {
|
|
435
219
|
readonly make: typeof make;
|
package/dist/route/client.js
CHANGED
|
@@ -15,7 +15,7 @@ const makeRouteLanguageModel = (route, mapped) => {
|
|
|
15
15
|
const provider = route.provider ?? ("provider" in mapped ? mapped.provider : undefined);
|
|
16
16
|
if (!provider)
|
|
17
17
|
throw new Error(`Route.model(${route.id}) requires a provider`);
|
|
18
|
-
if (!
|
|
18
|
+
if (!route.endpoint.baseURL)
|
|
19
19
|
throw new ProviderConfigurationError({
|
|
20
20
|
provider: ProviderID.make(provider),
|
|
21
21
|
message: `Route.model(${route.id}) requires an endpoint baseURL — configure it on the route first`,
|
|
@@ -37,7 +37,6 @@ const mergeRouteDefaults = (base, patch) => {
|
|
|
37
37
|
http: mergeHttpOptions(base?.http, HttpOptions.make(patch.http), headers === undefined ? undefined : new HttpOptions({ headers })),
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
-
const endpointBaseURL = (endpoint) => typeof endpoint.baseURL === "string" ? endpoint.baseURL : undefined;
|
|
41
40
|
const mergeHeaders = (...items) => {
|
|
42
41
|
const entries = items.flatMap((item) => item === undefined ? [] : Object.entries(item).filter((entry) => entry[1] !== undefined));
|
|
43
42
|
if (entries.length === 0)
|
|
@@ -272,9 +271,6 @@ export function compact(request, options) {
|
|
|
272
271
|
return yield* unsupportedCompaction(request, options?.mechanism);
|
|
273
272
|
});
|
|
274
273
|
}
|
|
275
|
-
export const streamRequest = (request, options) => Stream.unwrap(Effect.gen(function* () {
|
|
276
|
-
return (yield* Service).stream(request, options);
|
|
277
|
-
}));
|
|
278
274
|
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
279
275
|
const executor = yield* RequestExecutor.Service;
|
|
280
276
|
const stream = streamRequestWith({ http: executor });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, type Effect } from "effect";
|
|
2
|
-
import type { HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
3
|
-
import type
|
|
2
|
+
import type { Headers, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
3
|
+
import { HttpContext, type AIError } from "../schema/errors.js";
|
|
4
4
|
export interface Interface {
|
|
5
5
|
readonly execute: (request: HttpClientRequest.HttpClientRequest, middleware?: HttpMiddleware) => Effect.Effect<HttpClientResponse.HttpClientResponse, AIError>;
|
|
6
6
|
}
|
|
@@ -11,4 +11,8 @@ export declare class RequestExecutorService extends RequestExecutorService_base
|
|
|
11
11
|
}
|
|
12
12
|
export declare const Service: typeof RequestExecutorService;
|
|
13
13
|
export type Service = RequestExecutorService;
|
|
14
|
+
export declare const headerDetails: (headers: Headers.Headers) => {
|
|
15
|
+
[k: string]: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const responseHttp: (response: HttpClientResponse.HttpClientResponse) => HttpContext;
|
|
14
18
|
export {};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
|
+
import { HttpContext } from "../schema/errors.js";
|
|
2
3
|
export class RequestExecutorService extends Context.Service()("@opencode/AI/RequestExecutor") {
|
|
3
4
|
}
|
|
4
5
|
export const Service = RequestExecutorService;
|
|
6
|
+
export const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)]));
|
|
7
|
+
export const responseHttp = (response) => new HttpContext({
|
|
8
|
+
url: response.request.url,
|
|
9
|
+
status: response.status,
|
|
10
|
+
headers: headerDetails(response.headers),
|
|
11
|
+
});
|
package/dist/route/executor.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Layer, Stream } from "effect";
|
|
2
2
|
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
3
|
-
import {
|
|
3
|
+
import { AIError } from "../schema/index.js";
|
|
4
4
|
import { Service, type HttpMiddleware, type Interface } from "./executor-service.js";
|
|
5
|
-
export { Service } from "./executor-service.js";
|
|
5
|
+
export { responseHttp, Service } from "./executor-service.js";
|
|
6
6
|
export type { HttpHandler, HttpMiddleware, Interface } from "./executor-service.js";
|
|
7
|
-
export declare const responseHttp: (response: HttpClientResponse.HttpClientResponse) => HttpContext;
|
|
8
7
|
/** Preserve HTTP diagnostics for executor and externally captured failures alike. */
|
|
9
8
|
export declare const httpFailure: (input: {
|
|
10
9
|
readonly message: string;
|
package/dist/route/executor.js
CHANGED
|
@@ -2,9 +2,8 @@ import { Cause, Effect, Layer, Option, Schema, Stream } from "effect";
|
|
|
2
2
|
import { FetchHttpClient, Headers, HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse, } from "effect/http";
|
|
3
3
|
import { HttpContext, HttpRateLimitDetails, AIError, TransportError } from "../schema/index.js";
|
|
4
4
|
import { classifyProviderFailure, providerErrorMessage } from "../provider-error.js";
|
|
5
|
-
import { Service } from "./executor-service.js";
|
|
6
|
-
export { Service } from "./executor-service.js";
|
|
7
|
-
const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)]));
|
|
5
|
+
import { headerDetails, responseHttp, Service } from "./executor-service.js";
|
|
6
|
+
export { responseHttp, Service } from "./executor-service.js";
|
|
8
7
|
const normalizedHeaders = (headers) => Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value]));
|
|
9
8
|
const clampRetryAfterMs = (millis) => Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, Math.ceil(millis)));
|
|
10
9
|
const retryAfterMs = (headers) => {
|
|
@@ -61,11 +60,6 @@ const rateLimitDetails = (headers, retryAfter) => {
|
|
|
61
60
|
reset: Object.keys(reset).length === 0 ? undefined : reset,
|
|
62
61
|
});
|
|
63
62
|
};
|
|
64
|
-
export const responseHttp = (response) => new HttpContext({
|
|
65
|
-
url: response.request.url,
|
|
66
|
-
status: response.status,
|
|
67
|
-
headers: headerDetails(response.headers),
|
|
68
|
-
});
|
|
69
63
|
const MAX_BODY_CHARS = 2000;
|
|
70
64
|
// Without a recognized message, show the raw body so the provider's explanation is never dropped.
|
|
71
65
|
const providerMessage = (status, body) => {
|
|
@@ -3,7 +3,7 @@ import { HttpClientResponse } from "effect/http";
|
|
|
3
3
|
import type { Snapshot, Status } from "../generation.js";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
5
|
import type { AuthInput } from "./auth.js";
|
|
6
|
-
import { AIError, AuthenticationError, HttpContext, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError } from "../schema/index.js";
|
|
6
|
+
import { AIError, AuthenticationError, type HttpContext, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError } from "../schema/index.js";
|
|
7
7
|
/** Array values become repeated parameters (`keyterm=a&keyterm=b`). */
|
|
8
8
|
export type Query = Readonly<Record<string, string | ReadonlyArray<string>>>;
|
|
9
9
|
/** `query` is appended to the endpoint URL before the route and caller `http.query` overlays. */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Clock, Duration, Effect, Schema } from "effect";
|
|
2
2
|
import { HttpClientResponse } from "effect/http";
|
|
3
3
|
import { Media } from "../media.js";
|
|
4
|
-
import {
|
|
4
|
+
import { RequestExecutor } from "./executor.js";
|
|
5
|
+
import { AIError, AuthenticationError, ContentPolicyError, InvalidProviderOutputError, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError, UnsupportedOperationError, } from "../schema/index.js";
|
|
5
6
|
export const json = (value, query) => ({
|
|
6
7
|
type: "json",
|
|
7
8
|
value,
|
|
@@ -27,7 +28,6 @@ const FAILURES = {
|
|
|
27
28
|
RateLimit: RateLimitError,
|
|
28
29
|
ProviderInternal: ProviderInternalError,
|
|
29
30
|
};
|
|
30
|
-
const context = (response) => new HttpContext({ url: response.request.url, status: response.status, headers: response.headers });
|
|
31
31
|
/** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
|
|
32
32
|
export const identity = (input) => {
|
|
33
33
|
const provider = ProviderID.make(input.provider);
|
|
@@ -40,7 +40,7 @@ export const identity = (input) => {
|
|
|
40
40
|
* `contentPolicy` is a moderated result.
|
|
41
41
|
*/
|
|
42
42
|
const text = Effect.fn("MediaProtocol.text")(function* (response) {
|
|
43
|
-
const http =
|
|
43
|
+
const http = RequestExecutor.responseHttp(response);
|
|
44
44
|
const body = yield* response.text.pipe(Effect.mapError((cause) => new AIError({
|
|
45
45
|
reason: new InvalidProviderOutputError({
|
|
46
46
|
route: input.id,
|
|
@@ -6,13 +6,6 @@ import { Framing } from "../framing.js";
|
|
|
6
6
|
import * as ProviderShared from "../../protocols/shared.js";
|
|
7
7
|
import { AIError, DEFAULT_CHUNK_TIMEOUT_MS, DEFAULT_HTTP_TIMEOUT_MS, mergeJsonRecords, TransportError, } from "../../schema/index.js";
|
|
8
8
|
import { RequestExecutor } from "../executor.js";
|
|
9
|
-
const applyQuery = (url, query) => {
|
|
10
|
-
if (!query)
|
|
11
|
-
return url;
|
|
12
|
-
const next = new URL(url);
|
|
13
|
-
Object.entries(query).forEach(([key, value]) => next.searchParams.set(key, value));
|
|
14
|
-
return next.toString();
|
|
15
|
-
};
|
|
16
9
|
const bodyWithOverlay = (body, request, encodeBody) => Effect.gen(function* () {
|
|
17
10
|
if (request.http?.body === undefined)
|
|
18
11
|
return { jsonBody: body, bodyText: encodeBody(body) };
|
|
@@ -23,7 +16,11 @@ const bodyWithOverlay = (body, request, encodeBody) => Effect.gen(function* () {
|
|
|
23
16
|
return yield* ProviderShared.invalidRequest("http.body can only overlay JSON object request bodies");
|
|
24
17
|
});
|
|
25
18
|
export const jsonRequestParts = (input) => Effect.gen(function* () {
|
|
26
|
-
const
|
|
19
|
+
const endpoint = renderEndpoint(input.endpoint, { request: input.request, body: input.body });
|
|
20
|
+
if (input.request.http?.query) {
|
|
21
|
+
Object.entries(input.request.http.query).forEach(([key, value]) => endpoint.searchParams.set(key, value));
|
|
22
|
+
}
|
|
23
|
+
const url = endpoint.toString();
|
|
27
24
|
const body = yield* bodyWithOverlay(input.body, input.request, input.encodeBody);
|
|
28
25
|
const headers = yield* Auth.toEffect(input.auth)({
|
|
29
26
|
request: input.request,
|
|
@@ -2,7 +2,6 @@ import { Effect, Stream } from "effect";
|
|
|
2
2
|
import { Headers } from "effect/http";
|
|
3
3
|
import { Socket } from "effect/socket";
|
|
4
4
|
import { AIError, type HttpContext } from "../../schema/index.js";
|
|
5
|
-
import type { Transport } from "./index.js";
|
|
6
5
|
import type { WebSocketChannelExecutor } from "./websocket-channel.js";
|
|
7
6
|
export interface WebSocketRequest {
|
|
8
7
|
readonly url: string;
|
|
@@ -23,30 +22,7 @@ export declare const fromWebSocket: (ws: Socket.WebSocketLike, input: WebSocketR
|
|
|
23
22
|
export declare const messageText: (message: string | Uint8Array, decoder: TextDecoder) => string;
|
|
24
23
|
export declare const makeDirect: (connector: WebSocketConnector) => WebSocketChannelExecutor;
|
|
25
24
|
export declare const direct: Effect.Effect<WebSocketChannelExecutor, never, Socket.WebSocketConstructor>;
|
|
26
|
-
export interface JsonPrepared {
|
|
27
|
-
readonly url: string;
|
|
28
|
-
readonly headers: Headers.Headers;
|
|
29
|
-
readonly message: string;
|
|
30
|
-
}
|
|
31
|
-
export interface JsonInput<Body, Message> {
|
|
32
|
-
readonly toMessage: (body: Body | Record<string, unknown>) => Effect.Effect<Message, AIError>;
|
|
33
|
-
readonly encodeMessage: (message: Message) => string;
|
|
34
|
-
}
|
|
35
|
-
export type JsonPatch<Body, Message> = Partial<JsonInput<Body, Message>>;
|
|
36
|
-
export interface JsonTransport<Body, Message> extends Transport<Body, JsonPrepared, string> {
|
|
37
|
-
readonly with: (patch: JsonPatch<Body, Message>) => JsonTransport<Body, Message>;
|
|
38
|
-
}
|
|
39
|
-
export declare const json: <Body, Message>(input: JsonInput<Body, Message>) => JsonTransport<Body, Message>;
|
|
40
|
-
export declare const jsonTransport: {
|
|
41
|
-
readonly id: "websocket-json";
|
|
42
|
-
readonly with: typeof json;
|
|
43
|
-
};
|
|
44
25
|
export declare const WebSocketTransport: {
|
|
45
|
-
readonly json: typeof json;
|
|
46
|
-
readonly jsonTransport: {
|
|
47
|
-
readonly id: "websocket-json";
|
|
48
|
-
readonly with: typeof json;
|
|
49
|
-
};
|
|
50
26
|
readonly direct: Effect.Effect<WebSocketChannelExecutor, never, Socket.WebSocketConstructor>;
|
|
51
27
|
readonly makeDirect: typeof makeDirect;
|
|
52
28
|
readonly open: typeof open;
|
|
@@ -2,7 +2,6 @@ import { Cause, Effect, Queue, Stream } from "effect";
|
|
|
2
2
|
import { Headers } from "effect/http";
|
|
3
3
|
import { Socket } from "effect/socket";
|
|
4
4
|
import { AIError, AIErrorReason, TransportError, } from "../../schema/index.js";
|
|
5
|
-
import * as HttpTransport from "./http.js";
|
|
6
5
|
const MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
7
6
|
const transportError = (message, input) => new AIError({
|
|
8
7
|
reason: new TransportError({
|
|
@@ -300,56 +299,7 @@ export const direct = Effect.gen(function* () {
|
|
|
300
299
|
open: (input) => open(input).pipe(Effect.provideService(Socket.WebSocketConstructor, constructor)),
|
|
301
300
|
});
|
|
302
301
|
});
|
|
303
|
-
export const json = (input) => ({
|
|
304
|
-
id: "websocket-json",
|
|
305
|
-
with: (patch) => json({ ...input, ...patch }),
|
|
306
|
-
prepare: (prepareInput) => Effect.gen(function* () {
|
|
307
|
-
const parts = yield* HttpTransport.jsonRequestParts({
|
|
308
|
-
...prepareInput,
|
|
309
|
-
});
|
|
310
|
-
return {
|
|
311
|
-
url: yield* toWebSocketUrl(parts.url),
|
|
312
|
-
headers: parts.headers,
|
|
313
|
-
message: input.encodeMessage(yield* input.toMessage(parts.jsonBody)),
|
|
314
|
-
};
|
|
315
|
-
}),
|
|
316
|
-
execute: (prepared, request, _runtime, options) => {
|
|
317
|
-
const webSocket = options?.webSocket;
|
|
318
|
-
if (!webSocket) {
|
|
319
|
-
return Effect.fail(transportError("WebSocket JSON transport requires StreamOptions.webSocket", {
|
|
320
|
-
url: prepared.url,
|
|
321
|
-
operation: "request",
|
|
322
|
-
code: "unavailable",
|
|
323
|
-
phase: "prepare",
|
|
324
|
-
delivery: "not-sent",
|
|
325
|
-
}));
|
|
326
|
-
}
|
|
327
|
-
const driver = {
|
|
328
|
-
create: () => Effect.succeed({ message: prepared.message, mode: "full" }),
|
|
329
|
-
observe: (_create, frame) => Effect.succeed({ type: "frame", frame }),
|
|
330
|
-
};
|
|
331
|
-
const exchange = {
|
|
332
|
-
id: request.id ?? "request",
|
|
333
|
-
connect: { url: prepared.url, headers: prepared.headers },
|
|
334
|
-
fallback: () => Stream.fail(transportError("WebSocket JSON transport does not provide HTTP fallback", {
|
|
335
|
-
url: prepared.url,
|
|
336
|
-
operation: "request",
|
|
337
|
-
code: "websocket",
|
|
338
|
-
phase: "fallback",
|
|
339
|
-
delivery: "not-sent",
|
|
340
|
-
})),
|
|
341
|
-
driver,
|
|
342
|
-
};
|
|
343
|
-
return webSocket.execute(exchange);
|
|
344
|
-
},
|
|
345
|
-
});
|
|
346
|
-
export const jsonTransport = {
|
|
347
|
-
id: "websocket-json",
|
|
348
|
-
with: json,
|
|
349
|
-
};
|
|
350
302
|
export const WebSocketTransport = {
|
|
351
|
-
json,
|
|
352
|
-
jsonTransport,
|
|
353
303
|
direct,
|
|
354
304
|
makeDirect,
|
|
355
305
|
open,
|
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-21406",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
36
36
|
"@effect/platform-node": "4.0.1",
|
|
37
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
37
|
+
"@opencode/http-recorder": "0.0.0-dev-21406",
|
|
38
38
|
"@tsconfig/bun": "1.0.9",
|
|
39
39
|
"@types/bun": "1.4.0",
|
|
40
40
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
45
45
|
"@smithy/eventstream-codec": "4.2.14",
|
|
46
46
|
"@smithy/util-utf8": "4.2.2",
|
|
47
|
-
"@opencode/schema": "0.0.0-dev-
|
|
47
|
+
"@opencode/schema": "0.0.0-dev-21406",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.1",
|
|
50
50
|
"google-auth-library": "10.5.0"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { OpenResponsesOptions } from "./open-responses-options.js";
|
|
2
|
-
export declare const OpenAIReasoningEfforts: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
3
|
-
export type OpenAIReasoningEffort = OpenResponsesOptions.ReasoningEffort;
|
|
4
|
-
export declare const OpenAITextVerbosities: readonly ["low", "medium", "high"];
|
|
5
|
-
export type OpenAITextVerbosity = OpenResponsesOptions.TextVerbosity;
|
|
6
|
-
export declare const OpenAIResponseIncludables: readonly ["file_search_call.results", "web_search_call.results", "web_search_call.action.sources", "message.input_image.image_url", "computer_call_output.output.image_url", "code_interpreter_call.outputs", "reasoning.encrypted_content", "message.output_text.logprobs"];
|
|
7
|
-
export type OpenAIResponseIncludable = OpenResponsesOptions.ResponseIncludable;
|
|
8
|
-
export declare const OpenAIServiceTiers: readonly ["auto", "default", "flex", "priority", "scale", "fast", "ultrafast"];
|
|
9
|
-
export type OpenAIServiceTier = (typeof OpenAIServiceTiers)[number] | (string & {});
|
|
10
|
-
export declare const OpenAIReasoningEffort: import("effect/Schema").declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
|
|
11
|
-
export declare const OpenAITextVerbosity: import("effect/Schema").declare<OpenResponsesOptions.TextVerbosity, OpenResponsesOptions.TextVerbosity>;
|
|
12
|
-
export declare const OpenAIResponseIncludable: import("effect/Schema").declare<OpenResponsesOptions.ResponseIncludable, OpenResponsesOptions.ResponseIncludable>;
|
|
13
|
-
export declare const OpenAIServiceTier: import("effect/Schema").declare<OpenResponsesOptions.ServiceTier, OpenResponsesOptions.ServiceTier>;
|
|
14
|
-
export declare const isReasoningEffort: (effort: unknown) => effort is OpenAIReasoningEffort;
|
|
15
|
-
export declare const resolve: typeof OpenResponsesOptions.resolve;
|
|
16
|
-
export * as OpenAIOptions from "./openai-options.js";
|