@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
|
@@ -101,10 +101,10 @@ export type AnswersFor<Questions extends EvaluationQuestions> = {
|
|
|
101
101
|
export type EvaluationOptions = Record<string, unknown>;
|
|
102
102
|
export interface EvaluationRoute<Options extends EvaluationOptions = EvaluationOptions> {
|
|
103
103
|
readonly id: string;
|
|
104
|
-
|
|
104
|
+
evaluate(request: EvaluationRequestFor<Options>, execute: Execute): Effect.Effect<EvaluationResponse, AIError>;
|
|
105
105
|
}
|
|
106
106
|
export declare class EvaluationModel<Options extends EvaluationOptions = EvaluationOptions> {
|
|
107
|
-
protected readonly _Options:
|
|
107
|
+
protected readonly _Options: Options;
|
|
108
108
|
readonly id: ModelID;
|
|
109
109
|
readonly provider: ProviderID;
|
|
110
110
|
readonly route: EvaluationRoute<Options>;
|
|
@@ -193,12 +193,12 @@ export type EvaluationRequestFor<Options extends EvaluationOptions = EvaluationO
|
|
|
193
193
|
readonly questions: Questions;
|
|
194
194
|
readonly options?: Options;
|
|
195
195
|
};
|
|
196
|
-
export type EvaluationRequestInput<Model extends
|
|
196
|
+
export type EvaluationRequestInput<Model extends EvaluationModel = EvaluationModel, Questions extends EvaluationQuestions = EvaluationQuestions> = Omit<ConstructorParameters<typeof EvaluationRequest>[0], "model" | "questions" | "options" | "http"> & {
|
|
197
197
|
readonly model: Model;
|
|
198
198
|
readonly questions: Questions;
|
|
199
199
|
readonly options?: NoInfer<EvaluationModelOptions<Model>>;
|
|
200
200
|
readonly http?: HttpOptions.Input;
|
|
201
|
-
}
|
|
201
|
+
};
|
|
202
202
|
declare const EvaluationRounding_base: Schema.Class<EvaluationRounding, Schema.Struct<{
|
|
203
203
|
readonly probabilityDecimals: Schema.optional<Schema.Int>;
|
|
204
204
|
readonly scoreDecimals: Schema.optional<Schema.Int>;
|
|
@@ -230,9 +230,10 @@ export declare class EvaluationResponse extends EvaluationResponse_base {
|
|
|
230
230
|
export type EvaluationResponseFor<Questions extends EvaluationQuestions> = Omit<EvaluationResponse, "answers"> & {
|
|
231
231
|
readonly answers: AnswersFor<Questions>;
|
|
232
232
|
};
|
|
233
|
-
export declare function request<const Model extends
|
|
233
|
+
export declare function request<const Model extends EvaluationModel, const Questions extends EvaluationQuestions>(input: EvaluationRequestInput<Model, Questions>): EvaluationRequestFor<EvaluationModelOptions<Model>, Questions>;
|
|
234
234
|
export declare function request(input: EvaluationRequest): EvaluationRequest;
|
|
235
|
-
export declare function
|
|
235
|
+
export declare function request(input: EvaluationRequest | EvaluationRequestInput): EvaluationRequest;
|
|
236
|
+
export declare function run<const Model extends EvaluationModel, const Questions extends EvaluationQuestions>(input: EvaluationRequestInput<Model, Questions>): Effect.Effect<EvaluationResponseFor<Questions>, AIError, Service>;
|
|
236
237
|
export declare function run(input: EvaluationRequest): Effect.Effect<EvaluationResponse, AIError, Service>;
|
|
237
238
|
export declare const Evaluation: {
|
|
238
239
|
readonly request: typeof request;
|
|
@@ -95,20 +95,19 @@ export function request(input) {
|
|
|
95
95
|
return input;
|
|
96
96
|
return new EvaluationRequest({
|
|
97
97
|
...input,
|
|
98
|
-
model: input.model,
|
|
99
98
|
http: HttpOptions.make(input.http),
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
export function run(input) {
|
|
103
102
|
return Effect.try({
|
|
104
|
-
try: () =>
|
|
103
|
+
try: () => request(input),
|
|
105
104
|
catch: (cause) => new AIError({
|
|
106
105
|
reason: new InvalidRequestError({
|
|
107
106
|
message: cause instanceof Error ? cause.message : String(cause),
|
|
108
107
|
cause,
|
|
109
108
|
}),
|
|
110
109
|
}),
|
|
111
|
-
}).pipe(Effect.flatMap(
|
|
110
|
+
}).pipe(Effect.flatMap(EvaluationClient.evaluate));
|
|
112
111
|
}
|
|
113
112
|
export const Evaluation = {
|
|
114
113
|
request,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Clock, Effect, Redacted, Schema } from "effect";
|
|
2
2
|
import { HttpClientRequest } from "effect/http";
|
|
3
3
|
import { RequestExecutor } from "../route/executor.js";
|
|
4
|
-
import { AIError,
|
|
4
|
+
import { AIError, InvalidProviderOutputError, InvalidRequestError } from "../schema/index.js";
|
|
5
5
|
import { encodeJson } from "../utils/json.js";
|
|
6
6
|
const OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
7
7
|
const XAI_BASE_URL = "https://api.x.ai/v1";
|
|
@@ -91,7 +91,7 @@ const post = (route, url, apiKey, body, response, authHeader) => Effect.gen(func
|
|
|
91
91
|
: HttpClientRequest.bearerToken(apiKey), body instanceof FormData
|
|
92
92
|
? HttpClientRequest.bodyFormData(body)
|
|
93
93
|
: HttpClientRequest.bodyText(encodeJson(body), "application/json")));
|
|
94
|
-
const http =
|
|
94
|
+
const http = RequestExecutor.responseHttp(res);
|
|
95
95
|
const fail = (message, cause, raw) => new AIError({ reason: new InvalidProviderOutputError({ route, message, body: raw, http, cause }) });
|
|
96
96
|
const text = yield* res.text.pipe(Effect.mapError((cause) => fail(`Failed to read ${route} response`, cause)));
|
|
97
97
|
return yield* Schema.decodeEffect(response)(text).pipe(Effect.mapError((cause) => fail(`${route} returned an invalid response`, cause, text)));
|
|
@@ -2,7 +2,9 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { Headers, HttpClientRequest } from "effect/http";
|
|
3
3
|
import { ChoiceQuestion, EvaluationInput, EvaluationModel, EvaluationResponse, EvaluationRounding, ScoreQuestion, } from "./evaluation.js";
|
|
4
4
|
import { Auth } from "../route/auth.js";
|
|
5
|
-
import {
|
|
5
|
+
import { RequestExecutor } from "../route/executor.js";
|
|
6
|
+
import { JsonObject, ProviderShared } from "../protocols/shared.js";
|
|
7
|
+
import { AIError, HttpOptions, InvalidProviderOutputError, InvalidRequestError, ModelID, ProviderMetadata, Usage, mergeJsonRecords, } from "../schema/index.js";
|
|
6
8
|
const Noul = Schema.Struct({
|
|
7
9
|
type: Schema.Literal("noul"),
|
|
8
10
|
instructions: EvaluationInput,
|
|
@@ -24,7 +26,7 @@ const Request = Schema.StructWithRest(Schema.Struct({
|
|
|
24
26
|
model: Schema.String,
|
|
25
27
|
state: EvaluationInput,
|
|
26
28
|
questions: Schema.Record(Schema.String, Question),
|
|
27
|
-
}), [
|
|
29
|
+
}), [JsonObject]);
|
|
28
30
|
const Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
|
|
29
31
|
const NoulAnswer = Schema.Struct({ type: Schema.Literal("noul"), noul: Probability });
|
|
30
32
|
const Choice = Schema.Struct({
|
|
@@ -44,14 +46,14 @@ const Answer = Schema.Union([NoulAnswer, Choice, Score]).pipe(Schema.toTaggedUni
|
|
|
44
46
|
const NativeUsage = Schema.StructWithRest(Schema.Struct({
|
|
45
47
|
input_tokens: Schema.optional(Schema.Number),
|
|
46
48
|
output_tokens: Schema.optional(Schema.Number),
|
|
47
|
-
}), [
|
|
49
|
+
}), [JsonObject]);
|
|
48
50
|
const Response = Schema.Struct({
|
|
49
51
|
model: Schema.String,
|
|
50
52
|
answers: Schema.Record(Schema.String, Answer),
|
|
51
53
|
usage: Schema.optional(NativeUsage),
|
|
52
54
|
id: Schema.optional(Schema.String),
|
|
53
55
|
provider: Schema.optional(Schema.String),
|
|
54
|
-
provider_metadata: Schema.optional(
|
|
56
|
+
provider_metadata: Schema.optional(ProviderMetadata),
|
|
55
57
|
});
|
|
56
58
|
export const model = (cfg) => EvaluationModel.make({
|
|
57
59
|
id: cfg.id,
|
|
@@ -76,7 +78,7 @@ export const model = (cfg) => EvaluationModel.make({
|
|
|
76
78
|
headers: Headers.fromInput({ ...cfg.headers, ...req.http?.headers }),
|
|
77
79
|
});
|
|
78
80
|
const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
|
|
79
|
-
const http =
|
|
81
|
+
const http = RequestExecutor.responseHttp(res);
|
|
80
82
|
const fail = (message, cause, body) => new AIError({ reason: new InvalidProviderOutputError({ route: "system-one", message, body, http, cause }) });
|
|
81
83
|
const text = yield* res.text.pipe(Effect.mapError((cause) => fail("Failed to read the System One response", cause)));
|
|
82
84
|
const data = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => fail("System One returned an invalid response", cause, text)));
|
|
@@ -120,9 +122,7 @@ export const model = (cfg) => EvaluationModel.make({
|
|
|
120
122
|
? new Usage({
|
|
121
123
|
inputTokens: data.usage.input_tokens,
|
|
122
124
|
outputTokens: data.usage.output_tokens,
|
|
123
|
-
totalTokens: data.usage.input_tokens
|
|
124
|
-
? undefined
|
|
125
|
-
: (data.usage.input_tokens ?? 0) + (data.usage.output_tokens ?? 0),
|
|
125
|
+
totalTokens: ProviderShared.totalTokens(data.usage.input_tokens, data.usage.output_tokens, undefined),
|
|
126
126
|
providerMetadata: { [cfg.providerMetadataKey]: data.usage },
|
|
127
127
|
})
|
|
128
128
|
: undefined,
|
package/dist/llm.d.ts
CHANGED
|
@@ -14,10 +14,8 @@ export type RequestInput<SelectedLanguageModel extends LanguageModel = LanguageM
|
|
|
14
14
|
readonly providerOptions?: NoInfer<LanguageModelProviderOptions<SelectedLanguageModel>>;
|
|
15
15
|
readonly http?: HttpOptions.Input;
|
|
16
16
|
};
|
|
17
|
-
export declare function generate<const Model extends LanguageModel>(input: RequestInput<Model
|
|
18
|
-
export declare function
|
|
19
|
-
export declare function stream<const Model extends LanguageModel>(input: RequestInput<Model>, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
|
|
20
|
-
export declare function stream(input: LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
|
|
17
|
+
export declare function generate<const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
|
|
18
|
+
export declare function stream<const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
|
|
21
19
|
export declare const request: <const SelectedLanguageModel extends LanguageModel>(input: RequestInput<SelectedLanguageModel>) => LLMRequest<SelectedLanguageModel>;
|
|
22
20
|
type GenerateObjectBase<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<RequestInput<SelectedLanguageModel>, "tools" | "toolChoice">;
|
|
23
21
|
export declare class GenerateObjectResponse<T> {
|
package/dist/llm.js
CHANGED
|
@@ -46,8 +46,8 @@ const runGenerateObject = Effect.fn("LLM.generateObject")(function* (options, to
|
|
|
46
46
|
toolChoice: ToolChoice.named(GENERATE_OBJECT_TOOL_NAME),
|
|
47
47
|
});
|
|
48
48
|
const response = yield* LLMClient.generate(generateRequest);
|
|
49
|
-
const call = response.toolCalls.find((event) =>
|
|
50
|
-
if (!call
|
|
49
|
+
const call = response.toolCalls.find((event) => event.name === GENERATE_OBJECT_TOOL_NAME);
|
|
50
|
+
if (!call)
|
|
51
51
|
return yield* new AIError({
|
|
52
52
|
reason: new InvalidProviderOutputError({
|
|
53
53
|
message: `generateObject: model did not call the forced \`${GENERATE_OBJECT_TOOL_NAME}\` tool`,
|
package/dist/media.js
CHANGED
|
@@ -3,9 +3,9 @@ import { Effect, FileSystem, Schema, SchemaGetter } from "effect";
|
|
|
3
3
|
import { Base64 } from "effect/encoding";
|
|
4
4
|
import { HttpClientRequest } from "effect/http";
|
|
5
5
|
import { ProviderID } from "./schema/ids.js";
|
|
6
|
-
import { AIError,
|
|
6
|
+
import { AIError, InvalidProviderOutputError, InvalidRequestError } from "./schema/errors.js";
|
|
7
7
|
import { ProviderMetadata } from "./schema/options.js";
|
|
8
|
-
import { Service } from "./route/executor-service.js";
|
|
8
|
+
import { responseHttp, Service } from "./route/executor-service.js";
|
|
9
9
|
import { detectMediaType, fileMediaType } from "./utils/media-type.js";
|
|
10
10
|
export { detectMediaType } from "./utils/media-type.js";
|
|
11
11
|
const OCTET_STREAM = "application/octet-stream";
|
|
@@ -183,7 +183,7 @@ const download = Effect.fn("Media.download")(function* (source, headers) {
|
|
|
183
183
|
const buffer = yield* response.arrayBuffer.pipe(Effect.mapError((cause) => new AIError({
|
|
184
184
|
reason: new InvalidProviderOutputError({
|
|
185
185
|
message: `Failed to read media from ${source.url}`,
|
|
186
|
-
http:
|
|
186
|
+
http: responseHttp(response),
|
|
187
187
|
cause,
|
|
188
188
|
}),
|
|
189
189
|
})));
|
package/dist/promise.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type ImageModel, type ImageRequest, type ImageRequestInput } from "./im
|
|
|
5
5
|
import { LLM } from "./index.js";
|
|
6
6
|
import { Media } from "./media.js";
|
|
7
7
|
import { RequestExecutor } from "./route/executor.js";
|
|
8
|
-
import { LanguageModel, LLMRequest } from "./schema/index.js";
|
|
8
|
+
import { LanguageModel, type LLMRequest } from "./schema/index.js";
|
|
9
9
|
import type { RequestInput } from "./llm.js";
|
|
10
10
|
import { type SpeechModel, type SpeechRequest, type SpeechRequestInput } from "./speech.js";
|
|
11
11
|
import { type TranscriptionModel, type TranscriptionRequest, type TranscriptionRequestInput } from "./transcription.js";
|
package/dist/promise.js
CHANGED
|
@@ -3,9 +3,8 @@ import { AIClient } from "./ai-client.js";
|
|
|
3
3
|
import { Image } from "./image.js";
|
|
4
4
|
import { LLM } from "./index.js";
|
|
5
5
|
import { Media } from "./media.js";
|
|
6
|
-
import { tryRequest } from "./media-model.js";
|
|
7
6
|
import { RequestExecutor } from "./route/executor.js";
|
|
8
|
-
import { AIError, InvalidRequestError, LanguageModel
|
|
7
|
+
import { AIError, InvalidRequestError, LanguageModel } from "./schema/index.js";
|
|
9
8
|
import { Speech } from "./speech.js";
|
|
10
9
|
import { Transcription, } from "./transcription.js";
|
|
11
10
|
import { fileMediaType } from "./utils/media-type.js";
|
|
@@ -36,7 +35,6 @@ export const make = (options = {}) => {
|
|
|
36
35
|
refresh: (options) => run(generation.refresh(), options).then(handle),
|
|
37
36
|
cancel: (options) => run(generation.cancel(), options),
|
|
38
37
|
});
|
|
39
|
-
const llmRequest = (input) => input instanceof LLMRequest ? Effect.succeed(input) : tryRequest(() => LLM.request(input));
|
|
40
38
|
return {
|
|
41
39
|
run,
|
|
42
40
|
/** Decoded asset bytes, downloading `url` sources through the executor. */
|
|
@@ -65,8 +63,8 @@ export const make = (options = {}) => {
|
|
|
65
63
|
},
|
|
66
64
|
llm: {
|
|
67
65
|
request: LLM.request,
|
|
68
|
-
generate: (input, options) => run(
|
|
69
|
-
stream: (input, options) => iterate(
|
|
66
|
+
generate: (input, options) => run(LLM.generate(input), options),
|
|
67
|
+
stream: (input, options) => iterate(LLM.stream(input), options),
|
|
70
68
|
},
|
|
71
69
|
image: {
|
|
72
70
|
request: Image.request,
|
|
@@ -10,19 +10,19 @@ declare const Options: Schema.Struct<{
|
|
|
10
10
|
readonly preserveThinking: Schema.optional<Schema.Boolean>;
|
|
11
11
|
readonly clearThinking: Schema.optional<Schema.Boolean>;
|
|
12
12
|
readonly thinking: Schema.optional<Schema.Struct<{
|
|
13
|
-
readonly type: Schema.declare<"adaptive" | "disabled"
|
|
13
|
+
readonly type: Schema.declare<import("../schema/options.js").OpenString<"adaptive" | "disabled">, import("../schema/options.js").OpenString<"adaptive" | "disabled">>;
|
|
14
14
|
}>>;
|
|
15
15
|
readonly toolStream: Schema.optional<Schema.Boolean>;
|
|
16
16
|
readonly parallelToolCalls: Schema.optional<Schema.Boolean>;
|
|
17
17
|
readonly repetitionPenalty: Schema.optional<Schema.Number>;
|
|
18
18
|
readonly responseFormat: Schema.optional<Schema.Struct<{
|
|
19
|
-
readonly type: Schema.declare<"json_object" | "json_schema" | "text"
|
|
19
|
+
readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_object" | "json_schema" | "text">, import("../schema/options.js").OpenString<"json_object" | "json_schema" | "text">>;
|
|
20
20
|
readonly json_schema: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
21
21
|
}>>;
|
|
22
22
|
readonly enableSearch: Schema.optional<Schema.Boolean>;
|
|
23
23
|
readonly searchOptions: Schema.optional<Schema.Struct<{
|
|
24
24
|
readonly forced_search: Schema.optional<Schema.Boolean>;
|
|
25
|
-
readonly search_strategy: Schema.optional<Schema.declare<"agent" | "agent_max" | "max" | "turbo"
|
|
25
|
+
readonly search_strategy: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"agent" | "agent_max" | "max" | "turbo">, import("../schema/options.js").OpenString<"agent" | "agent_max" | "max" | "turbo">>>;
|
|
26
26
|
readonly enable_search_extension: Schema.optional<Schema.Boolean>;
|
|
27
27
|
}>>;
|
|
28
28
|
}>;
|
|
@@ -159,13 +159,13 @@ export declare const protocol: Protocol<{
|
|
|
159
159
|
readonly preserve_thinking?: boolean | undefined;
|
|
160
160
|
readonly clear_thinking?: boolean | undefined;
|
|
161
161
|
readonly thinking?: {
|
|
162
|
-
readonly type: "adaptive" | "disabled"
|
|
162
|
+
readonly type: import("../schema/options.js").OpenString<"adaptive" | "disabled">;
|
|
163
163
|
} | undefined;
|
|
164
164
|
readonly parallel_tool_calls?: boolean | undefined;
|
|
165
165
|
readonly repetition_penalty?: number | undefined;
|
|
166
166
|
readonly top_k?: number | undefined;
|
|
167
167
|
readonly response_format?: {
|
|
168
|
-
readonly type: "json_object" | "json_schema" | "text"
|
|
168
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "json_schema" | "text">;
|
|
169
169
|
readonly json_schema?: {
|
|
170
170
|
readonly [x: string]: unknown;
|
|
171
171
|
} | undefined;
|
|
@@ -173,7 +173,7 @@ export declare const protocol: Protocol<{
|
|
|
173
173
|
readonly enable_search?: boolean | undefined;
|
|
174
174
|
readonly search_options?: {
|
|
175
175
|
readonly forced_search?: boolean | undefined;
|
|
176
|
-
readonly search_strategy?: "agent" | "agent_max" | "max" | "turbo" |
|
|
176
|
+
readonly search_strategy?: import("../schema/options.js").OpenString<"agent" | "agent_max" | "max" | "turbo"> | undefined;
|
|
177
177
|
readonly enable_search_extension?: boolean | undefined;
|
|
178
178
|
} | undefined;
|
|
179
179
|
}, string, "[DONE]" | {
|
|
@@ -11,19 +11,19 @@ const Options = Schema.Struct({
|
|
|
11
11
|
preserveThinking: Schema.optional(Schema.Boolean),
|
|
12
12
|
clearThinking: Schema.optional(Schema.Boolean),
|
|
13
13
|
thinking: Schema.optional(Schema.Struct({
|
|
14
|
-
type:
|
|
14
|
+
type: ProviderShared.knownString(),
|
|
15
15
|
})),
|
|
16
16
|
toolStream: Schema.optional(Schema.Boolean),
|
|
17
17
|
parallelToolCalls: Schema.optional(Schema.Boolean),
|
|
18
18
|
repetitionPenalty: Schema.optional(Schema.Number),
|
|
19
19
|
responseFormat: Schema.optional(Schema.Struct({
|
|
20
|
-
type:
|
|
20
|
+
type: ProviderShared.knownString(),
|
|
21
21
|
json_schema: Schema.optional(JsonObject),
|
|
22
22
|
})),
|
|
23
23
|
enableSearch: Schema.optional(Schema.Boolean),
|
|
24
24
|
searchOptions: Schema.optional(Schema.Struct({
|
|
25
25
|
forced_search: Schema.optional(Schema.Boolean),
|
|
26
|
-
search_strategy: Schema.optional(
|
|
26
|
+
search_strategy: Schema.optional(ProviderShared.knownString()),
|
|
27
27
|
enable_search_extension: Schema.optional(Schema.Boolean),
|
|
28
28
|
})),
|
|
29
29
|
});
|
|
@@ -5,7 +5,7 @@ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
|
5
5
|
declare const Options: Schema.Struct<{
|
|
6
6
|
readonly effort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
|
|
7
7
|
readonly thinking: Schema.optional<Schema.Struct<{
|
|
8
|
-
readonly type: Schema.declare<"disabled" | "enabled"
|
|
8
|
+
readonly type: Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled">, import("../schema/options.js").OpenString<"disabled" | "enabled">>;
|
|
9
9
|
readonly budgetTokens: Schema.optional<Schema.Int>;
|
|
10
10
|
readonly budget_tokens: Schema.optional<Schema.Int>;
|
|
11
11
|
}>>;
|
|
@@ -7,7 +7,7 @@ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
|
7
7
|
const Options = Schema.Struct({
|
|
8
8
|
effort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
|
|
9
9
|
thinking: Schema.optional(Schema.Struct({
|
|
10
|
-
type:
|
|
10
|
+
type: ProviderShared.knownString(),
|
|
11
11
|
budgetTokens: Schema.optional(Schema.Int),
|
|
12
12
|
budget_tokens: Schema.optional(Schema.Int),
|
|
13
13
|
})),
|
|
@@ -169,15 +169,15 @@ export declare const protocol: Protocol<{
|
|
|
169
169
|
} | undefined;
|
|
170
170
|
readonly top_logprobs?: number | undefined;
|
|
171
171
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
172
|
-
readonly service_tier?:
|
|
172
|
+
readonly service_tier?: import("../index.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
173
173
|
readonly prompt_cache_key?: string | undefined;
|
|
174
|
-
readonly include?: readonly
|
|
174
|
+
readonly include?: readonly import("../index.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;
|
|
175
175
|
readonly reasoning?: {
|
|
176
176
|
readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
|
|
177
177
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
178
178
|
} | undefined;
|
|
179
179
|
readonly text?: {
|
|
180
|
-
readonly verbosity?:
|
|
180
|
+
readonly verbosity?: import("../index.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
181
181
|
} | undefined;
|
|
182
182
|
readonly max_output_tokens?: number | undefined;
|
|
183
183
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -400,13 +400,13 @@ const cacheControl = (breakpoints, cache) => {
|
|
|
400
400
|
const providerMetadata = (key, metadata) => ({ [key]: metadata });
|
|
401
401
|
const signatureFromMetadata = (metadata, key) => {
|
|
402
402
|
const provider = metadata?.[key];
|
|
403
|
-
if (!
|
|
403
|
+
if (!provider)
|
|
404
404
|
return undefined;
|
|
405
405
|
return typeof provider.signature === "string" ? provider.signature : undefined;
|
|
406
406
|
};
|
|
407
407
|
const redactedDataFromMetadata = (metadata, key) => {
|
|
408
408
|
const provider = metadata?.[key];
|
|
409
|
-
if (!
|
|
409
|
+
if (!provider)
|
|
410
410
|
return undefined;
|
|
411
411
|
return typeof provider.redactedData === "string" ? provider.redactedData : undefined;
|
|
412
412
|
};
|
|
@@ -477,7 +477,7 @@ const lowerServerToolResult = Effect.fnUntraced(function* (part, providerMetadat
|
|
|
477
477
|
};
|
|
478
478
|
});
|
|
479
479
|
const fileIdFromMetadata = (metadata) => {
|
|
480
|
-
if (!
|
|
480
|
+
if (!metadata)
|
|
481
481
|
return undefined;
|
|
482
482
|
const anthropic = metadata.anthropic;
|
|
483
483
|
if (ProviderShared.isRecord(anthropic)) {
|
|
@@ -493,7 +493,7 @@ const fileIdFromMetadata = (metadata) => {
|
|
|
493
493
|
return undefined;
|
|
494
494
|
};
|
|
495
495
|
const transformationsFromMetadata = (metadata) => {
|
|
496
|
-
if (!
|
|
496
|
+
if (!metadata)
|
|
497
497
|
return undefined;
|
|
498
498
|
const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
|
|
499
499
|
const raw = anthropic?.transformations ?? metadata.transformations;
|
|
@@ -507,19 +507,19 @@ const transformationsFromMetadata = (metadata) => {
|
|
|
507
507
|
return undefined;
|
|
508
508
|
};
|
|
509
509
|
const documentTitleFromPart = (part) => {
|
|
510
|
-
if (
|
|
510
|
+
if (part.metadata !== undefined) {
|
|
511
511
|
const anthropic = part.metadata.anthropic;
|
|
512
512
|
if (ProviderShared.isRecord(anthropic) && typeof anthropic.title === "string")
|
|
513
513
|
return anthropic.title;
|
|
514
514
|
if (typeof part.metadata.title === "string")
|
|
515
515
|
return part.metadata.title;
|
|
516
516
|
}
|
|
517
|
-
if (
|
|
517
|
+
if (part.filename && part.filename.length > 0)
|
|
518
518
|
return part.filename;
|
|
519
519
|
return undefined;
|
|
520
520
|
};
|
|
521
521
|
const documentContextFromMetadata = (metadata) => {
|
|
522
|
-
if (!
|
|
522
|
+
if (!metadata)
|
|
523
523
|
return undefined;
|
|
524
524
|
const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
|
|
525
525
|
if (anthropic && typeof anthropic.context === "string")
|
|
@@ -529,7 +529,7 @@ const documentContextFromMetadata = (metadata) => {
|
|
|
529
529
|
return undefined;
|
|
530
530
|
};
|
|
531
531
|
const citationsFromMetadata = (metadata) => {
|
|
532
|
-
if (!
|
|
532
|
+
if (!metadata)
|
|
533
533
|
return undefined;
|
|
534
534
|
const raw = ProviderShared.isRecord(metadata.anthropic)
|
|
535
535
|
? (metadata.anthropic.citations ?? metadata.citations)
|
|
@@ -796,7 +796,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
796
796
|
content.push({ type: "redacted_thinking", data: redactedData });
|
|
797
797
|
continue;
|
|
798
798
|
}
|
|
799
|
-
if (
|
|
799
|
+
if (!signature || signature.trim().length === 0) {
|
|
800
800
|
if (part.text.trim().length === 0)
|
|
801
801
|
continue;
|
|
802
802
|
if (!requireThinkingSignature(request)) {
|
|
@@ -1044,9 +1044,7 @@ const isServerToolResultType = (type) => type in SERVER_TOOL_RESULT_NAMES;
|
|
|
1044
1044
|
const serverToolResultEvent = (block, providerMetadataKey) => {
|
|
1045
1045
|
if (!block.type || !isServerToolResultType(block.type))
|
|
1046
1046
|
return undefined;
|
|
1047
|
-
const errorPayload =
|
|
1048
|
-
? String(block.content.type)
|
|
1049
|
-
: "";
|
|
1047
|
+
const errorPayload = ProviderShared.isRecord(block.content) && "type" in block.content ? String(block.content.type) : "";
|
|
1050
1048
|
const isError = errorPayload.endsWith("_tool_result_error");
|
|
1051
1049
|
return LLMEvent.toolResult({
|
|
1052
1050
|
id: block.tool_use_id ?? "",
|
|
@@ -189,12 +189,12 @@ const reasoningSignature = (part, providerMetadataKey) => {
|
|
|
189
189
|
const metadata = part.providerMetadata?.[providerMetadataKey];
|
|
190
190
|
if (part.encrypted !== undefined)
|
|
191
191
|
return part.encrypted;
|
|
192
|
-
if (
|
|
192
|
+
if (typeof metadata?.signature === "string")
|
|
193
193
|
return metadata.signature;
|
|
194
194
|
};
|
|
195
195
|
const reasoningRedactedData = (part, providerMetadataKey) => {
|
|
196
196
|
const metadata = part.providerMetadata?.[providerMetadataKey];
|
|
197
|
-
if (
|
|
197
|
+
if (typeof metadata?.redactedData === "string")
|
|
198
198
|
return metadata.redactedData;
|
|
199
199
|
};
|
|
200
200
|
const removeEmptyToolInputKeys = (input) => {
|
|
@@ -49,7 +49,9 @@ export declare const protocol: Protocol<{
|
|
|
49
49
|
readonly function: {
|
|
50
50
|
readonly name: string;
|
|
51
51
|
readonly description?: string | undefined;
|
|
52
|
-
readonly parameters:
|
|
52
|
+
readonly parameters: {
|
|
53
|
+
readonly [x: string]: unknown;
|
|
54
|
+
};
|
|
53
55
|
};
|
|
54
56
|
}[] | undefined;
|
|
55
57
|
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
@@ -161,7 +163,9 @@ export declare const route: Route<{
|
|
|
161
163
|
readonly function: {
|
|
162
164
|
readonly name: string;
|
|
163
165
|
readonly description?: string | undefined;
|
|
164
|
-
readonly parameters:
|
|
166
|
+
readonly parameters: {
|
|
167
|
+
readonly [x: string]: unknown;
|
|
168
|
+
};
|
|
165
169
|
};
|
|
166
170
|
}[] | undefined;
|
|
167
171
|
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
@@ -4,7 +4,7 @@ import { Endpoint } from "../route/endpoint.js";
|
|
|
4
4
|
import { Framing } from "../route/framing.js";
|
|
5
5
|
import { Protocol } from "../route/protocol.js";
|
|
6
6
|
import { LLMEvent, Usage } from "../schema/index.js";
|
|
7
|
-
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { JsonObject, ProviderShared } from "./shared.js";
|
|
8
8
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
9
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
10
10
|
const ADAPTER = "cohere-chat";
|
|
@@ -41,7 +41,7 @@ const Body = Schema.Struct({
|
|
|
41
41
|
function: Schema.Struct({
|
|
42
42
|
name: Schema.String,
|
|
43
43
|
description: Schema.optional(Schema.String),
|
|
44
|
-
parameters:
|
|
44
|
+
parameters: JsonObject,
|
|
45
45
|
}),
|
|
46
46
|
}))),
|
|
47
47
|
tool_choice: Schema.optional(Schema.Literals(["NONE", "REQUIRED"])),
|
|
@@ -239,7 +239,12 @@ export declare const protocol: Protocol<{
|
|
|
239
239
|
} | undefined;
|
|
240
240
|
readonly continuationToken?: string | undefined;
|
|
241
241
|
}, NextRequest | {
|
|
242
|
-
readonly error?:
|
|
242
|
+
readonly error?: {
|
|
243
|
+
readonly [x: string]: unknown;
|
|
244
|
+
readonly code?: number | undefined;
|
|
245
|
+
readonly message?: string | undefined;
|
|
246
|
+
readonly status?: string | undefined;
|
|
247
|
+
} | undefined;
|
|
243
248
|
readonly candidates?: readonly {
|
|
244
249
|
readonly content?: {
|
|
245
250
|
readonly role?: "model" | "user" | null | undefined;
|
|
@@ -261,7 +266,12 @@ export declare const protocol: Protocol<{
|
|
|
261
266
|
readonly totalTokenCount?: number | null | undefined;
|
|
262
267
|
} | null | undefined;
|
|
263
268
|
}, NextRequest | {
|
|
264
|
-
readonly error?:
|
|
269
|
+
readonly error?: {
|
|
270
|
+
readonly [x: string]: unknown;
|
|
271
|
+
readonly code?: number | undefined;
|
|
272
|
+
readonly message?: string | undefined;
|
|
273
|
+
readonly status?: string | undefined;
|
|
274
|
+
} | undefined;
|
|
265
275
|
readonly candidates?: readonly {
|
|
266
276
|
readonly content?: {
|
|
267
277
|
readonly role?: "model" | "user" | null | undefined;
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -182,8 +182,13 @@ const GeminiPromptFeedback = Schema.StructWithRest(Schema.Struct({
|
|
|
182
182
|
blockReasonMessage: optionalNull(Schema.String),
|
|
183
183
|
safetyRatings: optionalNull(Schema.Unknown),
|
|
184
184
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
185
|
+
const GeminiError = Schema.StructWithRest(Schema.Struct({
|
|
186
|
+
code: lenient(Schema.Number),
|
|
187
|
+
message: lenient(Schema.String),
|
|
188
|
+
status: lenient(Schema.String),
|
|
189
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
185
190
|
const GeminiEvent = Schema.Struct({
|
|
186
|
-
error: Schema.optional(
|
|
191
|
+
error: Schema.optional(GeminiError),
|
|
187
192
|
candidates: optionalNull(Schema.Array(GeminiCandidate)),
|
|
188
193
|
promptFeedback: optionalNull(GeminiPromptFeedback),
|
|
189
194
|
usageMetadata: optionalNull(GeminiUsage),
|
|
@@ -211,9 +216,7 @@ const lowerContentPart = Effect.fnUntraced(function* (part) {
|
|
|
211
216
|
const providerMetadata = (key, metadata) => ({ [key]: metadata });
|
|
212
217
|
const thoughtSignature = (metadata, key) => {
|
|
213
218
|
const value = metadata?.[key];
|
|
214
|
-
return
|
|
215
|
-
? value.thoughtSignature
|
|
216
|
-
: undefined;
|
|
219
|
+
return typeof value?.thoughtSignature === "string" ? value.thoughtSignature : undefined;
|
|
217
220
|
};
|
|
218
221
|
const lowerToolCall = (part, omitIds, metadataKey) => ({
|
|
219
222
|
functionCall: { ...(omitIds ? {} : { id: part.id }), name: part.name, args: part.input },
|
|
@@ -511,22 +514,16 @@ const step = (state, event) => {
|
|
|
511
514
|
},
|
|
512
515
|
[],
|
|
513
516
|
]);
|
|
514
|
-
if (
|
|
517
|
+
if (event.error) {
|
|
515
518
|
const body = ProviderShared.encodeJson(event);
|
|
516
519
|
return Effect.fail(new AIError({
|
|
517
520
|
reason: classifyProviderFailure({
|
|
518
|
-
message:
|
|
519
|
-
|
|
520
|
-
: typeof event.error.status === "string" && event.error.status.length > 0
|
|
521
|
-
? event.error.status
|
|
522
|
-
: "Gemini provider error",
|
|
523
|
-
status: typeof event.error.code === "number" ? event.error.code : undefined,
|
|
521
|
+
message: event.error.message || event.error.status || "Gemini provider error",
|
|
522
|
+
status: event.error.code,
|
|
524
523
|
rawBody: body,
|
|
525
524
|
}),
|
|
526
525
|
}));
|
|
527
526
|
}
|
|
528
|
-
if ("error" in event)
|
|
529
|
-
return Effect.fail(ProviderShared.eventError(state.route, `Invalid ${state.route} stream event`, ProviderShared.encodeJson(event)));
|
|
530
527
|
const candidate = event.candidates?.[0];
|
|
531
528
|
const nextState = {
|
|
532
529
|
...state,
|