@opencode/ai 0.0.0-dev-21400 → 0.0.0-dev-21411
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/llm.d.ts +2 -4
- package/dist/llm.js +2 -2
- 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/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/zai-coding-plan.d.ts +3 -3
- package/dist/route/client.d.ts +0 -216
- package/dist/route/client.js +0 -3
- package/dist/route/transport/http.js +5 -8
- package/package.json +3 -3
- package/dist/protocols/utils/openai-options.d.ts +0 -16
- package/dist/protocols/utils/openai-options.js +0 -15
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/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,
|
|
@@ -108,13 +108,20 @@ const OutputStep = Schema.Struct({
|
|
|
108
108
|
summary: Schema.optional(Schema.Array(Text)),
|
|
109
109
|
content: Schema.optional(Schema.Array(Schema.Struct({ type: Schema.String, text: Schema.optional(Schema.String) }))),
|
|
110
110
|
});
|
|
111
|
+
const KNOWN_DELTA_TYPES = new Set(["text", "arguments_delta", "thought_signature", "thought_summary"]);
|
|
112
|
+
const UnknownDelta = Schema.Struct({
|
|
113
|
+
type: Schema.String.check(Schema.makeFilter((type) => !KNOWN_DELTA_TYPES.has(type))),
|
|
114
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
|
|
115
|
+
decode: SchemaGetter.transform((delta) => ({ type: "unknown", rawType: delta.type })),
|
|
116
|
+
encode: SchemaGetter.forbidden(() => "Unknown Google Interactions deltas are decode-only"),
|
|
117
|
+
}));
|
|
111
118
|
const Delta = Schema.Union([
|
|
112
119
|
Schema.Struct({ type: Schema.Literal("text"), text: Schema.String }),
|
|
113
120
|
Schema.Struct({ type: Schema.Literal("arguments_delta"), arguments: Schema.String }),
|
|
114
121
|
Schema.Struct({ type: Schema.Literal("thought_signature"), signature: Schema.String }),
|
|
115
122
|
Schema.Struct({ type: Schema.Literal("thought_summary"), content: Text }),
|
|
116
123
|
// Unknown output modalities must fail explicitly rather than disappearing from a successful response.
|
|
117
|
-
|
|
124
|
+
UnknownDelta,
|
|
118
125
|
]);
|
|
119
126
|
const Interaction = Schema.StructWithRest(Schema.Struct({
|
|
120
127
|
id: Schema.optional(Schema.String),
|
|
@@ -173,9 +180,7 @@ const mediaContent = Effect.fnUntraced(function* (asset) {
|
|
|
173
180
|
});
|
|
174
181
|
const signature = (metadata, key) => {
|
|
175
182
|
const value = metadata?.[key];
|
|
176
|
-
return
|
|
177
|
-
? value.interactionSignature
|
|
178
|
-
: undefined;
|
|
183
|
+
return typeof value?.interactionSignature === "string" ? value.interactionSignature : undefined;
|
|
179
184
|
};
|
|
180
185
|
const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
181
186
|
const steps = [];
|
|
@@ -362,17 +367,17 @@ const onDelta = Effect.fnUntraced(function* (state, index, delta) {
|
|
|
362
367
|
if (!step)
|
|
363
368
|
return yield* ProviderShared.eventError(ADAPTER, "Interactions delta without step.start", encodeJson(delta));
|
|
364
369
|
const events = [];
|
|
365
|
-
if (delta.type === "text" &&
|
|
370
|
+
if (delta.type === "text" && step.type === "model_output")
|
|
366
371
|
return [
|
|
367
372
|
{ ...state, lifecycle: Lifecycle.textDelta(state.lifecycle, events, String(index), delta.text) },
|
|
368
373
|
events,
|
|
369
374
|
];
|
|
370
|
-
if (delta.type === "thought_summary" &&
|
|
375
|
+
if (delta.type === "thought_summary" && step.type === "thought")
|
|
371
376
|
return [
|
|
372
377
|
{ ...state, lifecycle: Lifecycle.reasoningDelta(state.lifecycle, events, String(index), delta.content.text) },
|
|
373
378
|
events,
|
|
374
379
|
];
|
|
375
|
-
if (delta.type === "thought_signature"
|
|
380
|
+
if (delta.type === "thought_signature") {
|
|
376
381
|
const next = { ...step, signature: delta.signature };
|
|
377
382
|
const tool = state.tools[index];
|
|
378
383
|
return [
|
|
@@ -384,13 +389,13 @@ const onDelta = Effect.fnUntraced(function* (state, index, delta) {
|
|
|
384
389
|
events,
|
|
385
390
|
];
|
|
386
391
|
}
|
|
387
|
-
if (delta.type === "arguments_delta" &&
|
|
392
|
+
if (delta.type === "arguments_delta" && step.type === "function_call") {
|
|
388
393
|
const result = ToolStream.appendExisting(ADAPTER, state.tools, index, delta.arguments, "Interactions arguments without function call");
|
|
389
394
|
if (ToolStream.isError(result))
|
|
390
395
|
return yield* result;
|
|
391
396
|
return [{ ...state, tools: result.tools }, result.events];
|
|
392
397
|
}
|
|
393
|
-
return yield* ProviderShared.eventError(ADAPTER, `Unsupported Interactions delta: ${delta.type}`, encodeJson(delta));
|
|
398
|
+
return yield* ProviderShared.eventError(ADAPTER, `Unsupported Interactions delta: ${delta.type === "unknown" ? delta.rawType : delta.type}`, encodeJson(delta));
|
|
394
399
|
});
|
|
395
400
|
const onStop = Effect.fnUntraced(function* (state, index) {
|
|
396
401
|
const step = state.steps[index];
|
|
@@ -183,15 +183,15 @@ export declare const protocol: Protocol<{
|
|
|
183
183
|
} | undefined;
|
|
184
184
|
readonly top_logprobs?: number | undefined;
|
|
185
185
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
186
|
-
readonly service_tier?: import("
|
|
186
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
187
187
|
readonly prompt_cache_key?: string | undefined;
|
|
188
|
-
readonly include?: readonly import("
|
|
188
|
+
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;
|
|
189
189
|
readonly reasoning?: {
|
|
190
190
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
191
191
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
192
192
|
} | undefined;
|
|
193
193
|
readonly text?: {
|
|
194
|
-
readonly verbosity?: import("
|
|
194
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
195
195
|
} | undefined;
|
|
196
196
|
readonly max_output_tokens?: number | undefined;
|
|
197
197
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -419,15 +419,15 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
419
419
|
} | undefined;
|
|
420
420
|
readonly top_logprobs?: number | undefined;
|
|
421
421
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
422
|
-
readonly service_tier?: import("
|
|
422
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
423
423
|
readonly prompt_cache_key?: string | undefined;
|
|
424
|
-
readonly include?: readonly import("
|
|
424
|
+
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;
|
|
425
425
|
readonly reasoning?: {
|
|
426
426
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
427
427
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
428
428
|
} | undefined;
|
|
429
429
|
readonly text?: {
|
|
430
|
-
readonly verbosity?: import("
|
|
430
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
431
431
|
} | undefined;
|
|
432
432
|
readonly max_output_tokens?: number | undefined;
|
|
433
433
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -290,9 +290,6 @@ const lowerTool = (tool) => ({
|
|
|
290
290
|
});
|
|
291
291
|
export const fromRequest = Effect.fn("MistralChat.fromRequest")(function* (request) {
|
|
292
292
|
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(MistralOptions))(request.providerOptions ?? {});
|
|
293
|
-
const selected = request.toolChoice?.type === "tool" ? request.toolChoice.name : undefined;
|
|
294
|
-
if (request.toolChoice?.type === "tool" && !selected)
|
|
295
|
-
return yield* ProviderShared.invalidRequest("Mistral Chat tool choice requires a tool name");
|
|
296
293
|
if (options.reasoningEffort !== undefined && options.promptMode !== undefined)
|
|
297
294
|
return yield* ProviderShared.invalidRequest("Mistral Chat reasoningEffort and promptMode provider options are mutually exclusive");
|
|
298
295
|
const toolChoice = request.toolChoice
|
|
@@ -372,7 +369,7 @@ const thinkingUnits = (value) => {
|
|
|
372
369
|
return [];
|
|
373
370
|
return value.filter(Schema.is(MistralThinkingUnit));
|
|
374
371
|
};
|
|
375
|
-
const thinkingText = (thinking) => thinking.flatMap((unit) => (
|
|
372
|
+
const thinkingText = (thinking) => thinking.flatMap((unit) => (unit.text !== undefined ? [unit.text] : [])).join("");
|
|
376
373
|
const thinkingMetadata = (thinking) => ({ mistral: { thinking } });
|
|
377
374
|
const closeActive = (state, events) => {
|
|
378
375
|
if (!state.active)
|