@opencode/ai 2.3.2 → 2.4.0
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/decision.d.ts +4 -3
- package/dist/decision.js +3 -2
- package/dist/embedding.d.ts +4 -3
- package/dist/embedding.js +3 -2
- package/dist/experimental/cloudflare-run-extraction.js +1 -2
- package/dist/experimental/realtime.d.ts +12 -43
- package/dist/experimental/realtime.js +14 -30
- package/dist/experimental.d.ts +1 -1
- package/dist/image.js +1 -1
- package/dist/media-model.d.ts +5 -4
- package/dist/media-model.js +5 -4
- package/dist/media.js +4 -17
- package/dist/protocols/anthropic-messages.js +7 -11
- package/dist/protocols/bedrock-converse.js +6 -6
- package/dist/protocols/cohere-chat.js +3 -3
- package/dist/protocols/gemini.js +6 -10
- package/dist/protocols/google-interactions.d.ts +299 -6
- package/dist/protocols/google-interactions.js +251 -33
- package/dist/protocols/meta-messages.js +3 -3
- package/dist/protocols/minimax-video.js +7 -1
- package/dist/protocols/mistral-chat.d.ts +1 -0
- package/dist/protocols/mistral-chat.js +3 -3
- package/dist/protocols/open-responses-continuation.js +2 -0
- package/dist/protocols/open-responses.d.ts +2 -0
- package/dist/protocols/open-responses.js +5 -3
- package/dist/protocols/openai-chat.d.ts +1 -0
- package/dist/protocols/openai-chat.js +6 -5
- package/dist/protocols/openai-responses.js +1 -0
- package/dist/protocols/shared.d.ts +12 -1
- package/dist/protocols/shared.js +56 -9
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/gemini-generate-content.d.ts +4 -0
- package/dist/protocols/utils/gemini-generate-content.js +5 -1
- package/dist/protocols/utils/responses-compaction.js +3 -3
- package/dist/protocols/xai-responses.d.ts +2 -1
- package/dist/protocols/xai-responses.js +4 -1
- package/dist/provider-error.js +3 -1
- package/dist/providers/alibaba.js +2 -3
- package/dist/providers/assemblyai.d.ts +2 -4
- package/dist/providers/azure.js +5 -11
- package/dist/providers/baseten.js +2 -3
- package/dist/providers/byteplus.d.ts +2 -4
- package/dist/providers/cartesia.d.ts +2 -4
- package/dist/providers/cloudflare-ai-gateway.js +3 -3
- package/dist/providers/cloudflare-workers-ai.js +2 -3
- package/dist/providers/cohere.js +2 -3
- package/dist/providers/deepgram.d.ts +2 -4
- package/dist/providers/deepinfra.js +2 -3
- package/dist/providers/digitalocean.js +3 -5
- package/dist/providers/elevenlabs.d.ts +2 -4
- package/dist/providers/fireworks.js +2 -3
- package/dist/providers/google-vertex-interactions.d.ts +12 -3
- package/dist/providers/google-vertex-interactions.js +1 -2
- package/dist/providers/google-vertex.js +6 -2
- package/dist/providers/google.d.ts +20 -3
- package/dist/providers/google.js +7 -4
- package/dist/providers/openai-compatible.js +3 -5
- package/dist/providers/openai.js +4 -10
- package/dist/providers/opencode.d.ts +2 -4
- package/dist/providers/opencode.js +2 -3
- package/dist/providers/openrouter.js +3 -5
- package/dist/providers/typesafe-ai.d.ts +2 -4
- package/dist/providers/typesafe-ai.js +2 -3
- package/dist/providers/vercel-ai-gateway.js +3 -5
- package/dist/providers/volcengine.d.ts +2 -4
- package/dist/route/decision.d.ts +4 -7
- package/dist/route/decision.js +8 -10
- package/dist/route/embedding.d.ts +4 -7
- package/dist/route/embedding.js +4 -7
- package/dist/route/executor-service.d.ts +20 -3
- package/dist/route/executor-service.js +72 -2
- package/dist/route/executor.d.ts +5 -5
- package/dist/route/executor.js +68 -73
- package/dist/route/media-protocol.d.ts +2 -1
- package/dist/route/media-protocol.js +2 -10
- package/dist/route/media.d.ts +6 -8
- package/dist/route/media.js +8 -8
- package/dist/route/protocol.d.ts +2 -0
- package/dist/route/protocol.js +4 -1
- package/dist/route/transport/http.d.ts +1 -2
- package/dist/route/transport/http.js +5 -28
- package/dist/schema/errors.js +2 -1
- package/dist/schema/options.d.ts +1 -1
- package/dist/speech.js +1 -1
- package/dist/transcription.js +1 -1
- package/dist/video.js +1 -1
- package/package.json +3 -3
|
@@ -184,9 +184,20 @@ export declare const unsupportedOperation: (input: {
|
|
|
184
184
|
/**
|
|
185
185
|
* Lower namespaces to flat definitions for protocols without a native
|
|
186
186
|
* namespace construct. Leaf names join their namespace path with `_` because
|
|
187
|
-
* `.` is not broadly accepted in provider tool names.
|
|
187
|
+
* `.` is not broadly accepted in provider tool names. A no-op on tools `flattenRequest` already flattened; adapters call
|
|
188
|
+
* it to type their tools.
|
|
188
189
|
*/
|
|
189
190
|
export declare const flattenTools: (tools: ReadonlyArray<ToolEntry>, path?: ReadonlyArray<string>) => ToolDefinition[];
|
|
191
|
+
/**
|
|
192
|
+
* The request as a protocol without native namespaces sees it: tools, tool updates, past calls and a forced choice all
|
|
193
|
+
* use flattened names. `Protocol.make` applies it before `body.from` for such protocols, so adapters only see flat
|
|
194
|
+
* requests.
|
|
195
|
+
*/
|
|
196
|
+
export declare const flattenRequest: (request: LLMRequest) => LLMRequest;
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated Routes without native namespaces already receive flattened requests; use `flattenRequest`. Removed in
|
|
199
|
+
* the next minor.
|
|
200
|
+
*/
|
|
190
201
|
export declare const flattenToolRequest: (request: LLMRequest) => {
|
|
191
202
|
tools: ToolDefinition[];
|
|
192
203
|
request: LLMRequest<import("../schema/options.js").LanguageModel<{
|
package/dist/protocols/shared.js
CHANGED
|
@@ -2,9 +2,10 @@ import { Tool } from "@opencode/schema/tool";
|
|
|
2
2
|
import { Effect, Option, Predicate, Schema, SchemaGetter, SchemaTransformation } from "effect";
|
|
3
3
|
import { Headers, HttpClientRequest } from "effect/http";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
|
-
import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, AssistantMessage, Message, ToolDefinition, ToolMessage, } from "../schema/index.js";
|
|
5
|
+
import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, AssistantMessage, Message, SystemMessage, ToolChoice, ToolDefinition, ToolMessage, } from "../schema/index.js";
|
|
6
6
|
import { Json, decodeJson, encodeJson } from "../utils/json.js";
|
|
7
7
|
import { isRecord } from "../utils/record.js";
|
|
8
|
+
import { foldTools, toolsUpdate, withdrawnTools } from "../tool-updates.js";
|
|
8
9
|
export { Json, decodeJson, encodeJson, isRecord };
|
|
9
10
|
const isJson = Schema.is(Schema.Json);
|
|
10
11
|
export const JsonObject = Schema.Record(Schema.String, Schema.Unknown);
|
|
@@ -269,7 +270,8 @@ export const unsupportedOperation = (input) => new AIError({
|
|
|
269
270
|
/**
|
|
270
271
|
* Lower namespaces to flat definitions for protocols without a native
|
|
271
272
|
* namespace construct. Leaf names join their namespace path with `_` because
|
|
272
|
-
* `.` is not broadly accepted in provider tool names.
|
|
273
|
+
* `.` is not broadly accepted in provider tool names. A no-op on tools `flattenRequest` already flattened; adapters call
|
|
274
|
+
* it to type their tools.
|
|
273
275
|
*/
|
|
274
276
|
export const flattenTools = (tools, path = []) => {
|
|
275
277
|
const flat = tools.flatMap((tool) => {
|
|
@@ -281,25 +283,70 @@ export const flattenTools = (tools, path = []) => {
|
|
|
281
283
|
});
|
|
282
284
|
return [...new Map(flat.map((tool) => [tool.name, tool])).values()];
|
|
283
285
|
};
|
|
284
|
-
|
|
286
|
+
/**
|
|
287
|
+
* The request as a protocol without native namespaces sees it: tools, tool updates, past calls and a forced choice all
|
|
288
|
+
* use flattened names. `Protocol.make` applies it before `body.from` for such protocols, so adapters only see flat
|
|
289
|
+
* requests.
|
|
290
|
+
*/
|
|
291
|
+
export const flattenRequest = (request) => {
|
|
292
|
+
const all = [...request.tools, ...request.messages.flatMap((message) => toolsUpdate(message)?.add ?? [])];
|
|
293
|
+
const declared = new Set(flattenTools(all).map((tool) => tool.name));
|
|
294
|
+
const flatten = (part) => flattenToolName(part, declared);
|
|
295
|
+
// A tool update that redefines a namespace drops the tools it leaves out, which only the namespace shows, so name
|
|
296
|
+
// them as explicit removals.
|
|
297
|
+
let tools = request.tools;
|
|
285
298
|
const messages = request.messages.map((message) => {
|
|
299
|
+
if (message.role === "system" && message.tools !== undefined) {
|
|
300
|
+
const next = foldTools(tools, message.tools.add, message.tools.remove);
|
|
301
|
+
const remove = withdrawnTools(tools, next);
|
|
302
|
+
tools = next;
|
|
303
|
+
return new SystemMessage({ ...message, tools: { add: flattenTools(message.tools.add), remove } });
|
|
304
|
+
}
|
|
286
305
|
if (message.role === "assistant") {
|
|
287
|
-
const content = message.content.map((part) => part.type === "tool-call" || part.type === "tool-result" ?
|
|
306
|
+
const content = message.content.map((part) => part.type === "tool-call" || part.type === "tool-result" ? flatten(part) : part);
|
|
288
307
|
return sameParts(content, message.content) ? message : new AssistantMessage({ ...message, content });
|
|
289
308
|
}
|
|
290
309
|
if (message.role !== "tool")
|
|
291
310
|
return message;
|
|
292
|
-
const content = message.content.map(
|
|
311
|
+
const content = message.content.map(flatten);
|
|
293
312
|
return sameParts(content, message.content) ? message : new ToolMessage({ ...message, content });
|
|
294
313
|
});
|
|
295
314
|
return {
|
|
315
|
+
...request,
|
|
296
316
|
tools: flattenTools(request.tools),
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
: { ...request, messages },
|
|
317
|
+
messages,
|
|
318
|
+
toolChoice: flattenToolChoice(request.toolChoice, all, declared),
|
|
300
319
|
};
|
|
301
320
|
};
|
|
302
|
-
|
|
321
|
+
/**
|
|
322
|
+
* @deprecated Routes without native namespaces already receive flattened requests; use `flattenRequest`. Removed in
|
|
323
|
+
* the next minor.
|
|
324
|
+
*/
|
|
325
|
+
export const flattenToolRequest = (request) => {
|
|
326
|
+
const flat = flattenRequest(request);
|
|
327
|
+
return { tools: flattenTools(flat.tools), request: flat };
|
|
328
|
+
};
|
|
329
|
+
// A forced choice names a namespaced tool by its path (`crm.lookup`); point it at the flattened definition.
|
|
330
|
+
const flattenToolChoice = (choice, tools, declared) => {
|
|
331
|
+
if (choice?.type !== "tool" || choice.name === undefined || declared.has(choice.name))
|
|
332
|
+
return choice;
|
|
333
|
+
const name = new Map(namespacedPaths(tools)).get(choice.name);
|
|
334
|
+
return name === undefined ? choice : new ToolChoice({ ...choice, name });
|
|
335
|
+
};
|
|
336
|
+
// Each namespaced tool's path and the name flattenTools gives it.
|
|
337
|
+
const namespacedPaths = (tools, path = []) => tools.flatMap((tool) => {
|
|
338
|
+
if (tool.type === "namespace")
|
|
339
|
+
return namespacedPaths(tool.tools, [...path, tool.name]);
|
|
340
|
+
return path.length === 0 ? [] : [[[...path, tool.name].join("."), [...path, tool.name].join("_")]];
|
|
341
|
+
});
|
|
342
|
+
const flattenToolName = (part, declared) => {
|
|
343
|
+
const flat = part.namespace === undefined ? part.name : `${part.namespace}_${part.name}`;
|
|
344
|
+
// Models sometimes call names no tool declares, such as a Code Mode path like `a.b.c`. Several providers (OpenAI
|
|
345
|
+
// Chat Completions, Bedrock Converse) reject those characters when the call is replayed, so replace them. A
|
|
346
|
+
// declared name is kept as is, so a provider that accepts it sees calls under the tool's own name.
|
|
347
|
+
const name = declared.has(flat) ? flat : flat.replace(/[^a-zA-Z0-9_-]/g, "_") || "_";
|
|
348
|
+
return name === part.name && part.namespace === undefined ? part : { ...part, name, namespace: undefined };
|
|
349
|
+
};
|
|
303
350
|
const sameParts = (next, previous) => next.every((part, index) => part === previous[index]);
|
|
304
351
|
export const matchToolChoice = (route, toolChoice, cases) => Effect.gen(function* () {
|
|
305
352
|
if (toolChoice.type === "auto")
|
|
@@ -37,6 +37,7 @@ export function gatewayProtocol(protocol, input) {
|
|
|
37
37
|
},
|
|
38
38
|
supportsEffortUpdates: protocol.supportsEffortUpdates,
|
|
39
39
|
toolUpdates: protocol.toolUpdates,
|
|
40
|
+
namespaces: protocol.namespaces,
|
|
40
41
|
sanitizer: protocol.sanitizer,
|
|
41
42
|
stream: {
|
|
42
43
|
event: protocol.stream.event,
|
|
@@ -3,6 +3,10 @@ import type { Tool } from "@opencode/schema/tool";
|
|
|
3
3
|
import { Media } from "../../media.js";
|
|
4
4
|
import type { MediaProtocol } from "../../route/media-protocol.js";
|
|
5
5
|
import { AIError, type MediaUsage, type ProviderMetadata } from "../../schema/index.js";
|
|
6
|
+
export declare const SafetySetting: Schema.Struct<{
|
|
7
|
+
readonly category: Schema.declare<import("../../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">, import("../../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">>;
|
|
8
|
+
readonly threshold: Schema.declare<import("../../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">, import("../../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">>;
|
|
9
|
+
}>;
|
|
6
10
|
declare const UsageMetadata: Schema.Struct<{
|
|
7
11
|
readonly promptTokenCount: Schema.optional<Schema.Number>;
|
|
8
12
|
readonly candidatesTokenCount: Schema.optional<Schema.Number>;
|
|
@@ -2,9 +2,13 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { Media } from "../../media.js";
|
|
3
3
|
import { Framing } from "../../route/framing.js";
|
|
4
4
|
import { AIError, ContentPolicyError, ProviderID, tokenUsage, } from "../../schema/index.js";
|
|
5
|
-
import { ProviderShared } from "../shared.js";
|
|
5
|
+
import { knownString, ProviderShared } from "../shared.js";
|
|
6
6
|
import { MediaInput } from "./media-input.js";
|
|
7
7
|
const PROVIDER = ProviderID.make("google");
|
|
8
|
+
export const SafetySetting = Schema.Struct({
|
|
9
|
+
category: knownString(),
|
|
10
|
+
threshold: knownString(),
|
|
11
|
+
});
|
|
8
12
|
const UsageMetadata = Schema.Struct({
|
|
9
13
|
promptTokenCount: Schema.optional(Schema.Number),
|
|
10
14
|
candidatesTokenCount: Schema.optional(Schema.Number),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, Message, mergeJsonRecords, } from "../../schema/index.js";
|
|
3
3
|
import { stripEffortUpdates } from "../../effort-updates.js";
|
|
4
4
|
import { foldToolUpdates } from "../../tool-updates.js";
|
|
@@ -96,13 +96,13 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
96
96
|
auth: route.auth,
|
|
97
97
|
encodeBody: Schema.encodeSync(Schema.fromJsonString(Body)),
|
|
98
98
|
});
|
|
99
|
-
const response = yield* RequestExecutor.withTls(executor.execute, request.http?.tls)(ProviderShared.jsonPost({
|
|
99
|
+
const response = yield* RequestExecutor.withTimeout(RequestExecutor.withTls(executor.execute, request.http?.tls), request.timeout)(ProviderShared.jsonPost({
|
|
100
100
|
url: parts.url,
|
|
101
101
|
body: parts.bodyText,
|
|
102
102
|
headers: parts.headers,
|
|
103
103
|
encoding: request.http?.encoding,
|
|
104
104
|
}), RequestExecutor.withFetch(request.fetch, options?.http));
|
|
105
|
-
const text = yield* RequestExecutor.
|
|
105
|
+
const text = yield* RequestExecutor.responseText(response);
|
|
106
106
|
const invalid = (message, cause) => new AIError({
|
|
107
107
|
reason: new InvalidProviderOutputError({
|
|
108
108
|
route: route.id,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import type { CompactOperation } from "../route/client.js";
|
|
3
4
|
import { OpenResponses } from "./open-responses.js";
|
|
4
5
|
declare const Options: Schema.Struct<{
|
|
5
6
|
readonly minP: Schema.optional<Schema.Number>;
|
|
@@ -289,5 +290,5 @@ export declare const protocol: Protocol<{
|
|
|
289
290
|
readonly status?: unknown;
|
|
290
291
|
readonly status_code?: unknown;
|
|
291
292
|
}, OpenResponses.ParserState>;
|
|
292
|
-
export declare const compact:
|
|
293
|
+
export declare const compact: CompactOperation;
|
|
293
294
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -78,5 +78,8 @@ export const protocol = Protocol.make({
|
|
|
78
78
|
},
|
|
79
79
|
stream: ResponsesHostedTools.stream(adapter, HOSTED_TOOLS),
|
|
80
80
|
});
|
|
81
|
-
|
|
81
|
+
const compactFlat = ResponsesCompaction.make(adapter, (request) => OpenResponses.lowerTools(ProviderShared.flattenTools(request.tools), adapter, OpenAIFreeform.tools(request)));
|
|
82
|
+
// /compact lowers the history itself, so flatten the whole request as `Protocol.make` does before every step's body:
|
|
83
|
+
// past calls to namespaced tools then carry the same names as on those steps, and /compact reads the prefix they cached.
|
|
84
|
+
export const compact = (request, executor, options) => compactFlat(ProviderShared.flattenRequest(request), executor, options);
|
|
82
85
|
export * as XAIResponses from "./xai-responses.js";
|
package/dist/provider-error.js
CHANGED
|
@@ -107,6 +107,8 @@ const CONTENT_POLICY_CODES = new Set([
|
|
|
107
107
|
"responsibleaipolicyviolation",
|
|
108
108
|
"content_policy_violation",
|
|
109
109
|
"image_content_policy_violation",
|
|
110
|
+
// OpenAI's cybersecurity safeguard, as an HTTP 400 or a mid-stream error frame.
|
|
111
|
+
"cyber_policy",
|
|
110
112
|
"refusal",
|
|
111
113
|
"datainspectionfailed",
|
|
112
114
|
"moderation_blocked",
|
|
@@ -131,7 +133,7 @@ const QUOTA_TEXT = /insufficient[-_\s]?(?:quota|balance)|(?<!token_)quota[-_\s]?
|
|
|
131
133
|
// explanation only. OpenAI reuses `invalid_prompt` for usage-policy rejections while
|
|
132
134
|
// Bedrock Mantle reuses it for schema validation; Anthropic reports blocked output
|
|
133
135
|
// under `invalid_request_error`. The Vercel AI Gateway drops OpenAI's `moderation_blocked` code.
|
|
134
|
-
const CONTENT_POLICY_TEXT = /violating our usage policy|blocked by content filtering policy|content[-_\s]?policy|rejected (?:as a result of our|by the) safety system|detected potentially unsafe or sensitive content/i;
|
|
136
|
+
const CONTENT_POLICY_TEXT = /violating our usage policy|blocked by content filtering policy|content[-_\s]?policy|rejected (?:as a result of our|by the) safety system|detected potentially unsafe or sensitive content|rejected in accordance with our terms of use/i;
|
|
135
137
|
const SERVER_ERROR_TEXT = /\b(?:try again|(?:please |you can )?retry (?:the |this |your )?request|try (?:the |this |your )?request again|(?:currently |temporarily )?at capacity|overloaded|temporarily unavailable|service[-_\s]?unavailable|(?:server|internal)[-_\s]?error|server (?:is )?busy|provider returned (?:an )?error|resource[-_\s]?exhausted|upstream (?:connect|connection|request)|request buffer limit while retrying upstream)\b/i;
|
|
136
138
|
const Message = Schema.String.check(Schema.isPattern(/\S/));
|
|
137
139
|
const messageAt = (fields, message) => Schema.Struct(fields).pipe(Schema.decodeTo(Schema.String, {
|
|
@@ -9,7 +9,7 @@ import { Route } from "../route/client.js";
|
|
|
9
9
|
import { Endpoint } from "../route/endpoint.js";
|
|
10
10
|
import { Framing } from "../route/framing.js";
|
|
11
11
|
import { MediaRoute } from "../route/media.js";
|
|
12
|
-
import { ProviderConfigurationError, ProviderID, ToolDefinition, } from "../schema/index.js";
|
|
12
|
+
import { mergeTransport, ProviderConfigurationError, ProviderID, ToolDefinition, } from "../schema/index.js";
|
|
13
13
|
export const id = ProviderID.make("alibaba");
|
|
14
14
|
const hosts = new Map([
|
|
15
15
|
["ap-southeast-1", "dashscope-intl.aliyuncs.com"],
|
|
@@ -77,8 +77,7 @@ export const configure = (input) => {
|
|
|
77
77
|
provider: id,
|
|
78
78
|
endpoint: common.endpoint,
|
|
79
79
|
auth: opts.auth,
|
|
80
|
-
|
|
81
|
-
http: input.http,
|
|
80
|
+
...mergeTransport(input),
|
|
82
81
|
});
|
|
83
82
|
const embedding = (id, providerOptions) => embeddingRoute.model({ id, providerOptions });
|
|
84
83
|
return { id, model: chat, chat, messages, responses, image, embedding, configure };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ModelID, type TransportOptions } from "../schema/index.js";
|
|
3
3
|
export type { AssemblyAITranscriptionOptions } from "../protocols/assemblyai-transcription.js";
|
|
4
4
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
5
|
+
export type Config = TransportOptions & ProviderAuthOption<"optional"> & {
|
|
6
6
|
/** `https://api.eu.assemblyai.com` for the EU region. */
|
|
7
7
|
readonly baseURL?: string;
|
|
8
|
-
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions;
|
|
10
8
|
};
|
|
11
9
|
export declare const configure: (input?: Config) => {
|
|
12
10
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
package/dist/providers/azure.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Auth } from "../route/auth.js";
|
|
|
2
2
|
import { AuthOptions } from "../route/auth-options.js";
|
|
3
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
4
4
|
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { ProviderConfigurationError, ProviderID, } from "../schema/index.js";
|
|
5
|
+
import { mergeTransport, ProviderConfigurationError, ProviderID, } from "../schema/index.js";
|
|
6
6
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
7
7
|
import { OpenAIImages } from "../protocols/openai-images.js";
|
|
8
8
|
import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
|
|
@@ -92,22 +92,16 @@ export const configure = (input) => {
|
|
|
92
92
|
.model({ id: modelID });
|
|
93
93
|
const image = (modelID, providerOptions) => {
|
|
94
94
|
const target = endpoint(input, modelID);
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
id: modelID,
|
|
99
|
-
provider: id,
|
|
100
|
-
providerOptions,
|
|
101
|
-
http: { ...media.http, query: { ...media.http?.query, ...target.query } },
|
|
102
|
-
});
|
|
95
|
+
const transport = mergeTransport(input, { http: { query: target.query } });
|
|
96
|
+
const media = MediaRoute.deployment({ ...transport, baseURL: target.baseURL }, auth(input));
|
|
97
|
+
return OpenAIImages.model({ ...media, id: modelID, provider: id, providerOptions });
|
|
103
98
|
};
|
|
104
99
|
const embedding = (modelID, providerOptions) => OpenAIEmbeddings.route
|
|
105
100
|
.with({
|
|
106
101
|
provider: id,
|
|
107
102
|
endpoint: endpoint(input, modelID),
|
|
108
103
|
auth: auth(input),
|
|
109
|
-
|
|
110
|
-
http: input.http,
|
|
104
|
+
...mergeTransport(input),
|
|
111
105
|
})
|
|
112
106
|
.model({ id: modelID, providerOptions });
|
|
113
107
|
return {
|
|
@@ -4,7 +4,7 @@ import { SystemOne } from "../protocols/system-one.js";
|
|
|
4
4
|
import { Route } from "../route/client.js";
|
|
5
5
|
import { DecisionRoute } from "../route/decision.js";
|
|
6
6
|
import { Endpoint } from "../route/endpoint.js";
|
|
7
|
-
import { ProviderID } from "../schema/index.js";
|
|
7
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
8
8
|
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
9
9
|
export const id = ProviderID.make("baseten");
|
|
10
10
|
const baseURL = "https://inference.baseten.co/v1";
|
|
@@ -36,8 +36,7 @@ export const configure = (input = {}) => {
|
|
|
36
36
|
protocol: decisionProtocol,
|
|
37
37
|
endpoint: Endpoint.path("/systemone", { baseURL: options.endpoint.baseURL }),
|
|
38
38
|
auth: options.auth,
|
|
39
|
-
|
|
40
|
-
http: input.http,
|
|
39
|
+
...mergeTransport(input),
|
|
41
40
|
});
|
|
42
41
|
const decision = (modelID, providerOptions) => decisionRoute.model({ id: modelID, providerOptions });
|
|
43
42
|
return {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type ModelID, type ProviderOptions, type TransportOptions } from "../schema/index.js";
|
|
4
4
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
5
|
+
export type Config = TransportOptions & ProviderAuthOption<"optional"> & {
|
|
6
6
|
readonly baseURL?: string;
|
|
7
|
-
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions;
|
|
9
7
|
};
|
|
10
8
|
export type Settings = ProviderPackage.Settings & {
|
|
11
9
|
readonly apiKey?: string | false;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ModelID, type TransportOptions } from "../schema/index.js";
|
|
3
3
|
export type { CartesiaEncoding, CartesiaSpeechOptions } from "../protocols/cartesia-speech.js";
|
|
4
4
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
5
|
+
export type Config = TransportOptions & ProviderAuthOption<"optional"> & {
|
|
6
6
|
readonly baseURL?: string;
|
|
7
|
-
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions;
|
|
9
7
|
};
|
|
10
8
|
export declare const configure: (input?: Config) => {
|
|
11
9
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -2,7 +2,7 @@ import { CloudflareRunDecisions } from "../protocols/cloudflare-run-decisions.js
|
|
|
2
2
|
import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../protocols/index.js";
|
|
3
3
|
import { Auth } from "../route/auth.js";
|
|
4
4
|
import { AuthOptions } from "../route/auth-options.js";
|
|
5
|
-
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
6
6
|
import { encodeJson } from "../utils/json.js";
|
|
7
7
|
import { CloudflareShared } from "./cloudflare-shared.js";
|
|
8
8
|
export const id = ProviderID.make("cloudflare-ai-gateway");
|
|
@@ -45,6 +45,7 @@ export const configure = (input) => {
|
|
|
45
45
|
endpoint: { baseURL: baseURL(input) },
|
|
46
46
|
auth: custom ?? credential(input, (credential) => credential.bearer()),
|
|
47
47
|
headers: { "cf-aig-gateway-id": gatewayId(input), ...headers(input) },
|
|
48
|
+
timeout: input.timeout,
|
|
48
49
|
http: input.http,
|
|
49
50
|
providerOptions: input.providerOptions,
|
|
50
51
|
};
|
|
@@ -74,8 +75,7 @@ export const configure = (input) => {
|
|
|
74
75
|
provider: id,
|
|
75
76
|
endpoint: { baseURL: runBaseURL(input) },
|
|
76
77
|
auth: rest.auth,
|
|
77
|
-
headers: rest.headers,
|
|
78
|
-
http: input.http,
|
|
78
|
+
...mergeTransport(input, { headers: rest.headers }),
|
|
79
79
|
})
|
|
80
80
|
.model({ id: value, providerOptions });
|
|
81
81
|
return {
|
|
@@ -6,7 +6,7 @@ import { AuthOptions } from "../route/auth-options.js";
|
|
|
6
6
|
import { Route } from "../route/client.js";
|
|
7
7
|
import { Endpoint } from "../route/endpoint.js";
|
|
8
8
|
import { MediaRoute } from "../route/media.js";
|
|
9
|
-
import { ProviderID } from "../schema/index.js";
|
|
9
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
10
10
|
import { CloudflareShared } from "./cloudflare-shared.js";
|
|
11
11
|
export const id = ProviderID.make("cloudflare-workers-ai");
|
|
12
12
|
export const authEnvVars = ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"];
|
|
@@ -33,8 +33,7 @@ export const configure = (input) => {
|
|
|
33
33
|
provider: id,
|
|
34
34
|
endpoint: { baseURL: runBaseURL(input) },
|
|
35
35
|
auth: auth,
|
|
36
|
-
|
|
37
|
-
http: input.http,
|
|
36
|
+
...mergeTransport(input),
|
|
38
37
|
})
|
|
39
38
|
.model({ id: modelID, providerOptions });
|
|
40
39
|
return {
|
package/dist/providers/cohere.js
CHANGED
|
@@ -3,7 +3,7 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
|
3
3
|
import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
|
|
4
4
|
import { Route } from "../route/client.js";
|
|
5
5
|
import { Endpoint } from "../route/endpoint.js";
|
|
6
|
-
import { ProviderID } from "../schema/index.js";
|
|
6
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
7
7
|
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
8
8
|
export const id = ProviderID.make("cohere");
|
|
9
9
|
const COMPATIBILITY_BASE_URL = "https://api.cohere.ai/compatibility/v1";
|
|
@@ -26,8 +26,7 @@ export const configure = (input = {}) => {
|
|
|
26
26
|
provider: id,
|
|
27
27
|
endpoint: compatibility.endpoint,
|
|
28
28
|
auth: options.auth,
|
|
29
|
-
|
|
30
|
-
http: input.http,
|
|
29
|
+
...mergeTransport(input),
|
|
31
30
|
});
|
|
32
31
|
return {
|
|
33
32
|
id,
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ModelID, type TransportOptions } from "../schema/index.js";
|
|
3
3
|
export type { DeepgramEncoding, DeepgramSpeechOptions } from "../protocols/deepgram-speech.js";
|
|
4
4
|
export type { DeepgramTranscriptionOptions } from "../protocols/deepgram-transcription.js";
|
|
5
5
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
6
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
+
export type Config = TransportOptions & ProviderAuthOption<"optional"> & {
|
|
7
7
|
readonly baseURL?: string;
|
|
8
|
-
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions;
|
|
10
8
|
};
|
|
11
9
|
export declare const configure: (input?: Config) => {
|
|
12
10
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -2,7 +2,7 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
|
2
2
|
import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
|
|
3
3
|
import { Route } from "../route/client.js";
|
|
4
4
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
-
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
6
6
|
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
7
7
|
export const id = ProviderID.make("deepinfra");
|
|
8
8
|
const baseURL = "https://api.deepinfra.com/v1/openai";
|
|
@@ -28,8 +28,7 @@ export const configure = (input = {}) => {
|
|
|
28
28
|
provider: id,
|
|
29
29
|
endpoint: options.endpoint,
|
|
30
30
|
auth: options.auth,
|
|
31
|
-
|
|
32
|
-
http: input.http,
|
|
31
|
+
...mergeTransport(input),
|
|
33
32
|
});
|
|
34
33
|
return {
|
|
35
34
|
id,
|
|
@@ -8,7 +8,7 @@ import { Route } from "../route/client.js";
|
|
|
8
8
|
import { Endpoint } from "../route/endpoint.js";
|
|
9
9
|
import { MediaRoute } from "../route/media.js";
|
|
10
10
|
import { Protocol } from "../route/protocol.js";
|
|
11
|
-
import { ProviderID } from "../schema/index.js";
|
|
11
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
12
12
|
import { bearerRouteDefaults } from "./settings.js";
|
|
13
13
|
export const id = ProviderID.make("digitalocean");
|
|
14
14
|
const baseURL = "https://inference.do-ai.run/v1";
|
|
@@ -48,8 +48,7 @@ export const configure = (input = {}) => {
|
|
|
48
48
|
endpoint: options.endpoint,
|
|
49
49
|
auth: options.auth,
|
|
50
50
|
// DigitalOcean serves TypeSafe's Jev, which needs this header for images.
|
|
51
|
-
headers: { "TypeSafe-Danger-Zone-Images": "true"
|
|
52
|
-
http: input.http,
|
|
51
|
+
...mergeTransport({ headers: { "TypeSafe-Danger-Zone-Images": "true" } }, input),
|
|
53
52
|
});
|
|
54
53
|
const decision = (modelID, providerOptions) => decisionRoute.model({ id: modelID, providerOptions });
|
|
55
54
|
const media = MediaRoute.deployment({ ...input, baseURL: options.endpoint.baseURL }, options.auth);
|
|
@@ -58,8 +57,7 @@ export const configure = (input = {}) => {
|
|
|
58
57
|
provider: id,
|
|
59
58
|
endpoint: options.endpoint,
|
|
60
59
|
auth: options.auth,
|
|
61
|
-
|
|
62
|
-
http: input.http,
|
|
60
|
+
...mergeTransport(input),
|
|
63
61
|
});
|
|
64
62
|
const embedding = (modelID, providerOptions) => embeddingRoute.model({ id: modelID, providerOptions });
|
|
65
63
|
const chat = (modelID) => configured.model({
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ModelID, type TransportOptions } from "../schema/index.js";
|
|
3
3
|
export type { ElevenLabsOutputFormat, ElevenLabsSpeechOptions } from "../protocols/elevenlabs-speech.js";
|
|
4
4
|
export type { ElevenLabsTranscriptionOptions } from "../protocols/elevenlabs-transcription.js";
|
|
5
5
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
6
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
+
export type Config = TransportOptions & ProviderAuthOption<"optional"> & {
|
|
7
7
|
readonly baseURL?: string;
|
|
8
|
-
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions;
|
|
10
8
|
};
|
|
11
9
|
export declare const configure: (input?: Config) => {
|
|
12
10
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -2,7 +2,7 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
|
2
2
|
import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
|
|
3
3
|
import { Route } from "../route/client.js";
|
|
4
4
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
-
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
6
6
|
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
7
7
|
export const id = ProviderID.make("fireworks");
|
|
8
8
|
const baseURL = "https://api.fireworks.ai/inference/v1";
|
|
@@ -22,8 +22,7 @@ export const configure = (input = {}) => {
|
|
|
22
22
|
provider: id,
|
|
23
23
|
endpoint: options.endpoint,
|
|
24
24
|
auth: options.auth,
|
|
25
|
-
|
|
26
|
-
http: input.http,
|
|
25
|
+
...mergeTransport(input),
|
|
27
26
|
});
|
|
28
27
|
return {
|
|
29
28
|
id,
|
|
@@ -24,7 +24,7 @@ export type Settings = ProviderPackage.Settings & GoogleInteractions.ProviderOpt
|
|
|
24
24
|
};
|
|
25
25
|
export declare const routes: Route<{
|
|
26
26
|
readonly model: string;
|
|
27
|
-
readonly input
|
|
27
|
+
readonly input?: readonly ({
|
|
28
28
|
readonly type: "model_output" | "user_input";
|
|
29
29
|
readonly content: readonly ({
|
|
30
30
|
readonly type: "text";
|
|
@@ -54,12 +54,17 @@ export declare const routes: Route<{
|
|
|
54
54
|
readonly name: string;
|
|
55
55
|
readonly result: unknown;
|
|
56
56
|
readonly is_error?: boolean | undefined;
|
|
57
|
-
})[];
|
|
57
|
+
})[] | undefined;
|
|
58
58
|
readonly stream: true;
|
|
59
59
|
readonly store: boolean;
|
|
60
60
|
readonly previous_interaction_id?: string | undefined;
|
|
61
|
+
readonly continuation_token?: string | undefined;
|
|
61
62
|
readonly system_instruction?: string | undefined;
|
|
62
63
|
readonly service_tier?: string | undefined;
|
|
64
|
+
readonly safety_settings?: readonly {
|
|
65
|
+
readonly type: string;
|
|
66
|
+
readonly threshold: string;
|
|
67
|
+
}[] | undefined;
|
|
63
68
|
readonly tools?: readonly {
|
|
64
69
|
readonly type: "function";
|
|
65
70
|
readonly name: string;
|
|
@@ -83,7 +88,7 @@ export declare const routes: Route<{
|
|
|
83
88
|
};
|
|
84
89
|
} | undefined;
|
|
85
90
|
};
|
|
86
|
-
},
|
|
91
|
+
}, GoogleInteractions.Prepared, import("../route/client.js").CompactionOperations | undefined>[];
|
|
87
92
|
export declare const configure: (input?: Config) => {
|
|
88
93
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
89
94
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
@@ -92,6 +97,10 @@ export declare const configure: (input?: Config) => {
|
|
|
92
97
|
readonly thinkingLevel?: import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal"> | undefined;
|
|
93
98
|
readonly thinkingSummaries?: import("../schema/options.js").OpenString<"auto" | "none"> | undefined;
|
|
94
99
|
readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
|
|
100
|
+
readonly safetySettings?: readonly {
|
|
101
|
+
readonly category: import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">;
|
|
102
|
+
readonly threshold: import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">;
|
|
103
|
+
}[] | undefined;
|
|
95
104
|
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
96
105
|
configure: typeof configure;
|
|
97
106
|
};
|
|
@@ -2,7 +2,6 @@ import { GoogleInteractions } from "../protocols/google-interactions.js";
|
|
|
2
2
|
import { Auth } from "../route/auth.js";
|
|
3
3
|
import { Route } from "../route/client.js";
|
|
4
4
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
-
import { Framing } from "../route/framing.js";
|
|
6
5
|
import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
|
|
7
6
|
import { GoogleVertexShared } from "./google-vertex-shared.js";
|
|
8
7
|
export const id = ProviderID.make("google-vertex");
|
|
@@ -17,7 +16,7 @@ const route = Route.make({
|
|
|
17
16
|
const serviceTier = request.providerOptions?.serviceTier;
|
|
18
17
|
return typeof serviceTier === "string" ? { "x-vertex-ai-llm-shared-request-type": serviceTier } : {};
|
|
19
18
|
},
|
|
20
|
-
|
|
19
|
+
transport: GoogleInteractions.transport,
|
|
21
20
|
});
|
|
22
21
|
export const routes = [route];
|
|
23
22
|
const configuredRoute = (input) => {
|
|
@@ -9,7 +9,7 @@ import { Route } from "../route/client.js";
|
|
|
9
9
|
import { EmbeddingRoute } from "../route/embedding.js";
|
|
10
10
|
import { Endpoint } from "../route/endpoint.js";
|
|
11
11
|
import { MediaRoute } from "../route/media.js";
|
|
12
|
-
import { ProviderConfigurationError, ProviderID, } from "../schema/index.js";
|
|
12
|
+
import { mergeTransport, ProviderConfigurationError, ProviderID, } from "../schema/index.js";
|
|
13
13
|
import { GoogleVertexShared } from "./google-vertex-shared.js";
|
|
14
14
|
export const id = ProviderID.make("google-vertex");
|
|
15
15
|
const fromRequest = Effect.fn("GoogleVertex.fromRequest")(function* (request) {
|
|
@@ -121,7 +121,11 @@ export const configure = (input = {}) => {
|
|
|
121
121
|
message: "Google Vertex embedContent does not support Express Mode API keys; use project credentials",
|
|
122
122
|
});
|
|
123
123
|
return selected.route
|
|
124
|
-
.with({
|
|
124
|
+
.with({
|
|
125
|
+
endpoint: target.endpoint,
|
|
126
|
+
auth: target.auth,
|
|
127
|
+
...mergeTransport(input),
|
|
128
|
+
})
|
|
125
129
|
.model({ id: modelID, providerOptions });
|
|
126
130
|
},
|
|
127
131
|
configure,
|