@opencode/ai 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -185
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +11 -22
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +56 -89
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +54 -32
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +14 -20
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +9 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -24
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +11 -23
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { Config, Redacted } from "effect";
|
|
2
2
|
import type { ProviderPackage } from "../provider-package.js";
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
5
|
-
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
3
|
+
import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
6
5
|
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
7
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
8
7
|
export declare const authEnvVars: readonly ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
|
|
@@ -18,18 +17,18 @@ type GatewayOptions = {
|
|
|
18
17
|
readonly skipCache?: boolean;
|
|
19
18
|
readonly collectLog?: boolean;
|
|
20
19
|
};
|
|
21
|
-
export type Config = GatewayURL & GatewayOptions & Omit<
|
|
20
|
+
export type Config = GatewayURL & GatewayOptions & Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
22
21
|
readonly gatewayApiKey?: string | Redacted.Redacted | Config.Config<string | Redacted.Redacted>;
|
|
23
22
|
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
24
23
|
};
|
|
25
24
|
export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & GatewayURL & GatewayOptions & {
|
|
26
|
-
readonly apiKey?: string;
|
|
25
|
+
readonly apiKey?: string | false;
|
|
27
26
|
readonly gatewayApiKey?: string;
|
|
28
27
|
};
|
|
29
28
|
export declare const baseURL: (input: GatewayURL) => string;
|
|
30
29
|
/** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
|
|
31
30
|
export declare const runBaseURL: (input: GatewayURL) => string;
|
|
32
|
-
export declare const responsesRoute: import("../route
|
|
31
|
+
export declare const responsesRoute: import("../route.js").Route<{
|
|
33
32
|
readonly model: string;
|
|
34
33
|
readonly input: readonly ({
|
|
35
34
|
readonly type: "configuration_update";
|
|
@@ -262,7 +261,7 @@ export declare const responsesRoute: import("../route/client.js").Route<{
|
|
|
262
261
|
endpoint: import("../route/client.js").CompactOperation;
|
|
263
262
|
trigger: import("../route/client.js").TriggerCompactOperation;
|
|
264
263
|
}>;
|
|
265
|
-
export declare const messagesRoute: import("../route
|
|
264
|
+
export declare const messagesRoute: import("../route.js").Route<{
|
|
266
265
|
readonly context_management?: {
|
|
267
266
|
readonly edits: readonly {
|
|
268
267
|
readonly type: "compact_20260112";
|
|
@@ -569,8 +568,8 @@ export declare const messagesRoute: import("../route/client.js").Route<{
|
|
|
569
568
|
} | undefined;
|
|
570
569
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
571
570
|
readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
|
|
572
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
573
|
-
export declare const route: import("../route
|
|
571
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined>;
|
|
572
|
+
export declare const route: import("../route.js").Route<{
|
|
574
573
|
readonly model: string;
|
|
575
574
|
readonly messages: readonly ({
|
|
576
575
|
readonly role: "system";
|
|
@@ -743,8 +742,8 @@ export declare const route: import("../route/client.js").Route<{
|
|
|
743
742
|
readonly presence_penalty?: number | undefined;
|
|
744
743
|
readonly seed?: number | undefined;
|
|
745
744
|
readonly stop?: readonly string[] | undefined;
|
|
746
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
747
|
-
export declare const routes: (import("../route
|
|
745
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined>;
|
|
746
|
+
export declare const routes: (import("../route.js").Route<{
|
|
748
747
|
readonly context_management?: {
|
|
749
748
|
readonly edits: readonly {
|
|
750
749
|
readonly type: "compact_20260112";
|
|
@@ -1051,7 +1050,7 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
1051
1050
|
} | undefined;
|
|
1052
1051
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
1053
1052
|
readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
|
|
1054
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
1053
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined> | import("../route.js").Route<{
|
|
1055
1054
|
readonly model: string;
|
|
1056
1055
|
readonly messages: readonly ({
|
|
1057
1056
|
readonly role: "system";
|
|
@@ -1224,7 +1223,7 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
1224
1223
|
readonly presence_penalty?: number | undefined;
|
|
1225
1224
|
readonly seed?: number | undefined;
|
|
1226
1225
|
readonly stop?: readonly string[] | undefined;
|
|
1227
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
1226
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined> | import("../route.js").Route<{
|
|
1228
1227
|
readonly model: string;
|
|
1229
1228
|
readonly input: readonly ({
|
|
1230
1229
|
readonly type: "configuration_update";
|
|
@@ -1463,6 +1462,12 @@ export declare const configure: (input: Config) => {
|
|
|
1463
1462
|
endpoint: import("../route/client.js").CompactOperation;
|
|
1464
1463
|
trigger: import("../route/client.js").TriggerCompactOperation;
|
|
1465
1464
|
}>;
|
|
1465
|
+
chat: (value: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route.js").CompactionOperations | undefined>;
|
|
1466
|
+
responses: (value: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, {
|
|
1467
|
+
endpoint: import("../route/client.js").CompactOperation;
|
|
1468
|
+
trigger: import("../route/client.js").TriggerCompactOperation;
|
|
1469
|
+
}>;
|
|
1470
|
+
messages: (value: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route.js").CompactionOperations | undefined>;
|
|
1466
1471
|
decision: (value: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
1467
1472
|
configure: typeof configure;
|
|
1468
1473
|
};
|
|
@@ -1471,5 +1476,8 @@ export declare const provider: {
|
|
|
1471
1476
|
configure: typeof configure;
|
|
1472
1477
|
};
|
|
1473
1478
|
export declare const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1479
|
+
export declare const chat: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1480
|
+
export declare const responses: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1481
|
+
export declare const messages: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1474
1482
|
export declare const decisionModel: (modelID: string, settings: Settings) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
1475
1483
|
export * as CloudflareAIGateway from "./cloudflare-ai-gateway.js";
|
|
@@ -1,37 +1,18 @@
|
|
|
1
1
|
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
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
5
|
+
import { ProviderID } from "../schema/index.js";
|
|
6
6
|
import { encodeJson } from "../utils/json.js";
|
|
7
|
+
import { CloudflareShared } from "./cloudflare-shared.js";
|
|
7
8
|
export const id = ProviderID.make("cloudflare-ai-gateway");
|
|
8
9
|
export const authEnvVars = ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
|
|
9
|
-
export const baseURL = (input) =>
|
|
10
|
-
if (input.baseURL)
|
|
11
|
-
return input.baseURL;
|
|
12
|
-
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(requireAccountId(input))}/ai/v1`;
|
|
13
|
-
};
|
|
10
|
+
export const baseURL = (input) => CloudflareShared.baseURL(input, id, "CloudflareAIGateway");
|
|
14
11
|
/** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
|
|
15
|
-
export const runBaseURL = (input) =>
|
|
16
|
-
const url = Endpoint.trimBaseUrl(baseURL(input));
|
|
17
|
-
if (!url.endsWith("/ai/v1"))
|
|
18
|
-
throw new ProviderConfigurationError({
|
|
19
|
-
provider: id,
|
|
20
|
-
message: "CloudflareAIGateway needs accountId or a baseURL ending in /ai/v1 to derive the Run API base",
|
|
21
|
-
});
|
|
22
|
-
return `${url.slice(0, -"/v1".length)}/run`;
|
|
23
|
-
};
|
|
12
|
+
export const runBaseURL = (input) => CloudflareShared.runBaseURL(input, id, "CloudflareAIGateway");
|
|
24
13
|
// Cloudflare's REST API rejects parts of the Anthropic Messages and OpenAI Responses request shapes, such as
|
|
25
14
|
// system prompt blocks and `minimal` reasoning effort, so these models use the provider-native gateway endpoints.
|
|
26
|
-
const passthroughURL = (input, provider) => `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(requireAccountId(input))}/${encodeURIComponent(gatewayId(input))}/${provider}`;
|
|
27
|
-
const requireAccountId = (input) => {
|
|
28
|
-
if (input.accountId)
|
|
29
|
-
return input.accountId;
|
|
30
|
-
throw new ProviderConfigurationError({
|
|
31
|
-
provider: id,
|
|
32
|
-
message: "CloudflareAIGateway.configure requires accountId unless baseURL is supplied",
|
|
33
|
-
});
|
|
34
|
-
};
|
|
15
|
+
const passthroughURL = (input, provider) => `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(CloudflareShared.requireAccountId(input, id, "CloudflareAIGateway"))}/${encodeURIComponent(gatewayId(input))}/${provider}`;
|
|
35
16
|
const gatewayId = (input) => input.gatewayId?.trim() || "default";
|
|
36
17
|
export const responsesRoute = OpenAIResponses.route.with({
|
|
37
18
|
id: "cloudflare-ai-gateway-responses",
|
|
@@ -49,9 +30,7 @@ export const route = OpenAIChat.route.with({
|
|
|
49
30
|
endpoint: { baseURL: undefined },
|
|
50
31
|
});
|
|
51
32
|
export const routes = [responsesRoute, messagesRoute, route];
|
|
52
|
-
const credential = (input) =>
|
|
53
|
-
.orElse(Auth.config(authEnvVars[0]))
|
|
54
|
-
.orElse(Auth.config(authEnvVars[1]));
|
|
33
|
+
const credential = (input, apply) => AuthOptions.apiKey({ apiKey: input.gatewayApiKey ?? ("apiKey" in input ? input.apiKey : undefined) }, authEnvVars, apply);
|
|
55
34
|
const headers = (input) => ({
|
|
56
35
|
...(input.metadata === undefined ? {} : { "cf-aig-metadata": encodeJson(input.metadata) }),
|
|
57
36
|
...(input.cacheTtl === undefined ? {} : { "cf-aig-cache-ttl": String(input.cacheTtl) }),
|
|
@@ -64,7 +43,7 @@ export const configure = (input) => {
|
|
|
64
43
|
const custom = "auth" in input && input.auth ? input.auth : undefined;
|
|
65
44
|
const rest = {
|
|
66
45
|
endpoint: { baseURL: baseURL(input) },
|
|
67
|
-
auth: custom ?? credential(input).bearer(),
|
|
46
|
+
auth: custom ?? credential(input, (credential) => credential.bearer()),
|
|
68
47
|
headers: { "cf-aig-gateway-id": gatewayId(input), ...headers(input) },
|
|
69
48
|
http: input.http,
|
|
70
49
|
providerOptions: input.providerOptions,
|
|
@@ -75,13 +54,20 @@ export const configure = (input) => {
|
|
|
75
54
|
? {
|
|
76
55
|
...rest,
|
|
77
56
|
endpoint: { baseURL: passthroughURL(input, provider) },
|
|
78
|
-
auth: custom ?? Auth.bearerHeader("cf-aig-authorization"
|
|
57
|
+
auth: custom ?? credential(input, Auth.bearerHeader("cf-aig-authorization")),
|
|
79
58
|
headers: headers(input),
|
|
80
59
|
}
|
|
81
60
|
: rest;
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
61
|
+
const responsesConfigured = responsesRoute.with(passthrough("openai"));
|
|
62
|
+
const messagesConfigured = messagesRoute.with(passthrough("anthropic/v1"));
|
|
63
|
+
const chatConfigured = route.with(rest);
|
|
64
|
+
const responses = (value) => responsesConfigured.model({
|
|
65
|
+
id: native ? value.replace(/^openai\//, "") : value,
|
|
66
|
+
});
|
|
67
|
+
const messages = (value) => messagesConfigured.model({
|
|
68
|
+
id: native ? value.replace(/^anthropic\//, "").replaceAll(".", "-") : value,
|
|
69
|
+
});
|
|
70
|
+
const chat = (value) => chatConfigured.model({ id: value.replace(/^workers-ai\//, "") });
|
|
85
71
|
// The Run API base is derived per call so a chat-only configuration without an account still constructs.
|
|
86
72
|
const decision = (value, providerOptions) => CloudflareRunDecisions.route
|
|
87
73
|
.with({
|
|
@@ -96,21 +82,23 @@ export const configure = (input) => {
|
|
|
96
82
|
id,
|
|
97
83
|
model: (value) => {
|
|
98
84
|
if (value.startsWith("openai/"))
|
|
99
|
-
return responses
|
|
85
|
+
return responses(value);
|
|
100
86
|
if (value.startsWith("anthropic/"))
|
|
101
|
-
return messages
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
if (value.startsWith("workers-ai/"))
|
|
105
|
-
return chat.model({ id: value.slice("workers-ai/".length) });
|
|
106
|
-
return chat.model({ id: value });
|
|
87
|
+
return messages(value);
|
|
88
|
+
return chat(value);
|
|
107
89
|
},
|
|
90
|
+
chat,
|
|
91
|
+
responses,
|
|
92
|
+
messages,
|
|
108
93
|
decision,
|
|
109
94
|
configure,
|
|
110
95
|
};
|
|
111
96
|
};
|
|
112
97
|
export const provider = { id, configure };
|
|
113
98
|
export const model = (modelID, settings) => configure(config(settings)).model(modelID);
|
|
99
|
+
export const chat = (modelID, settings) => configure(config(settings)).chat(modelID);
|
|
100
|
+
export const responses = (modelID, settings) => configure(config(settings)).responses(modelID);
|
|
101
|
+
export const messages = (modelID, settings) => configure(config(settings)).messages(modelID);
|
|
114
102
|
export const decisionModel = (modelID, settings) => {
|
|
115
103
|
const input = config(settings);
|
|
116
104
|
return configure(input).decision(modelID, input.providerOptions);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ProviderID } from "../schema/index.js";
|
|
2
|
+
type AccountURL = {
|
|
3
|
+
readonly accountId?: string;
|
|
4
|
+
readonly baseURL?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const requireAccountId: (input: AccountURL, provider: ProviderID, name: string) => string;
|
|
7
|
+
export declare const baseURL: (input: AccountURL, provider: ProviderID, name: string) => string;
|
|
8
|
+
export declare const runBaseURL: (input: AccountURL, provider: ProviderID, name: string) => string;
|
|
9
|
+
export * as CloudflareShared from "./cloudflare-shared.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
2
|
+
import { ProviderConfigurationError } from "../schema/index.js";
|
|
3
|
+
export const requireAccountId = (input, provider, name) => {
|
|
4
|
+
if (input.accountId)
|
|
5
|
+
return input.accountId;
|
|
6
|
+
throw new ProviderConfigurationError({
|
|
7
|
+
provider,
|
|
8
|
+
message: `${name}.configure requires accountId unless baseURL is supplied`,
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export const baseURL = (input, provider, name) => {
|
|
12
|
+
if (input.baseURL)
|
|
13
|
+
return input.baseURL;
|
|
14
|
+
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(requireAccountId(input, provider, name))}/ai/v1`;
|
|
15
|
+
};
|
|
16
|
+
export const runBaseURL = (input, provider, name) => {
|
|
17
|
+
const url = Endpoint.trimBaseUrl(baseURL(input, provider, name));
|
|
18
|
+
if (!url.endsWith("/ai/v1"))
|
|
19
|
+
throw new ProviderConfigurationError({
|
|
20
|
+
provider,
|
|
21
|
+
message: `${name} needs accountId or a baseURL ending in /ai/v1 to derive the Run API base`,
|
|
22
|
+
});
|
|
23
|
+
return `${url.slice(0, -"/v1".length)}/run`;
|
|
24
|
+
};
|
|
25
|
+
export * as CloudflareShared from "./cloudflare-shared.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
-
import { Route
|
|
4
|
-
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
5
5
|
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
7
|
export declare const authEnvVars: readonly ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"];
|
|
@@ -9,11 +9,11 @@ type WorkersAIURL = AtLeastOne<{
|
|
|
9
9
|
readonly accountId: string;
|
|
10
10
|
readonly baseURL: string;
|
|
11
11
|
}>;
|
|
12
|
-
export type Config = WorkersAIURL & Omit<
|
|
12
|
+
export type Config = WorkersAIURL & Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
13
13
|
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
14
14
|
};
|
|
15
15
|
export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & WorkersAIURL & {
|
|
16
|
-
readonly apiKey?: string;
|
|
16
|
+
readonly apiKey?: string | false;
|
|
17
17
|
};
|
|
18
18
|
export type { CloudflareWorkersAIImageOptions } from "../protocols/cloudflare-workers-ai-images.js";
|
|
19
19
|
export declare const baseURL: (input: WorkersAIURL) => string;
|
|
@@ -6,29 +6,13 @@ 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 {
|
|
9
|
+
import { ProviderID } from "../schema/index.js";
|
|
10
|
+
import { CloudflareShared } from "./cloudflare-shared.js";
|
|
10
11
|
export const id = ProviderID.make("cloudflare-workers-ai");
|
|
11
12
|
export const authEnvVars = ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"];
|
|
12
|
-
export const baseURL = (input) =>
|
|
13
|
-
if (input.baseURL)
|
|
14
|
-
return input.baseURL;
|
|
15
|
-
if (!input.accountId)
|
|
16
|
-
throw new ProviderConfigurationError({
|
|
17
|
-
provider: id,
|
|
18
|
-
message: "CloudflareWorkersAI.configure requires accountId unless baseURL is supplied",
|
|
19
|
-
});
|
|
20
|
-
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(input.accountId)}/ai/v1`;
|
|
21
|
-
};
|
|
13
|
+
export const baseURL = (input) => CloudflareShared.baseURL(input, id, "CloudflareWorkersAI");
|
|
22
14
|
/** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
|
|
23
|
-
export const runBaseURL = (input) =>
|
|
24
|
-
const url = Endpoint.trimBaseUrl(baseURL(input));
|
|
25
|
-
if (!url.endsWith("/ai/v1"))
|
|
26
|
-
throw new ProviderConfigurationError({
|
|
27
|
-
provider: id,
|
|
28
|
-
message: "CloudflareWorkersAI needs accountId or a baseURL ending in /ai/v1 to derive the Run API base",
|
|
29
|
-
});
|
|
30
|
-
return `${url.slice(0, -"/v1".length)}/run`;
|
|
31
|
-
};
|
|
15
|
+
export const runBaseURL = (input) => CloudflareShared.runBaseURL(input, id, "CloudflareWorkersAI");
|
|
32
16
|
export const route = Route.make({
|
|
33
17
|
id: "cloudflare-workers-ai",
|
|
34
18
|
provider: id,
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { Cohere } from "../cohere.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
baseURL,
|
|
5
|
-
headers,
|
|
6
|
-
http: body === undefined ? undefined : { body },
|
|
7
|
-
providerOptions,
|
|
8
|
-
}).chat(modelID);
|
|
2
|
+
import { toConfig } from "../settings.js";
|
|
3
|
+
export const model = (modelID, settings) => Cohere.configure(toConfig(settings)).chat(modelID);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { CohereChat } from "../protocols/cohere-chat.js";
|
|
2
|
-
import { Route
|
|
3
|
-
import {
|
|
4
|
-
import { type ModelID, type OpenString } from "../schema/index.js";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { type ModelID, type OpenString, type RequestOptions } from "../schema/index.js";
|
|
5
5
|
import type { ProviderPackage } from "../provider-package.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
7
|
export type ChatOptionsInput = {
|
|
8
8
|
readonly reasoningEffort?: OpenString<"none" | "high">;
|
|
9
9
|
};
|
|
10
10
|
export type ProviderOptions = CohereChat.ProviderOptionsInput & ChatOptionsInput;
|
|
11
|
-
export type Config = Omit<
|
|
11
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
12
12
|
readonly baseURL?: string;
|
|
13
13
|
readonly providerOptions?: ProviderOptions;
|
|
14
14
|
};
|
|
15
15
|
export type Settings<Options = CohereChat.ProviderOptionsInput> = ProviderPackage.Settings & Options & {
|
|
16
|
-
readonly apiKey?: string;
|
|
16
|
+
readonly apiKey?: string | false;
|
|
17
17
|
readonly baseURL?: string;
|
|
18
18
|
};
|
|
19
19
|
export declare const route: Route<{
|
|
@@ -489,5 +489,6 @@ export declare const provider: {
|
|
|
489
489
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
490
490
|
configure: typeof configure;
|
|
491
491
|
};
|
|
492
|
+
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
492
493
|
export declare const model: ProviderPackage.Model<Settings, CohereChat.ProviderOptionsInput>;
|
|
493
494
|
export * as Cohere from "./cohere.js";
|
package/dist/providers/cohere.js
CHANGED
|
@@ -2,8 +2,8 @@ import { CohereChat } from "../protocols/cohere-chat.js";
|
|
|
2
2
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
3
3
|
import { Route } from "../route/client.js";
|
|
4
4
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
6
5
|
import { ProviderID } from "../schema/index.js";
|
|
6
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
7
7
|
export const id = ProviderID.make("cohere");
|
|
8
8
|
const COMPATIBILITY_BASE_URL = "https://api.cohere.ai/compatibility/v1";
|
|
9
9
|
export const route = CohereChat.route;
|
|
@@ -17,10 +17,9 @@ export const chatRoute = Route.make({
|
|
|
17
17
|
});
|
|
18
18
|
export const routes = [route, chatRoute];
|
|
19
19
|
export const configure = (input = {}) => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const chat = chatRoute.with({ ...defaults, auth, endpoint: { baseURL: baseURL ?? COMPATIBILITY_BASE_URL } });
|
|
20
|
+
const options = bearerRouteDefaults(input, "COHERE_API_KEY", CohereChat.DEFAULT_BASE_URL);
|
|
21
|
+
const native = route.with(options);
|
|
22
|
+
const chat = chatRoute.with({ ...options, endpoint: { baseURL: input.baseURL ?? COMPATIBILITY_BASE_URL } });
|
|
24
23
|
return {
|
|
25
24
|
id,
|
|
26
25
|
model: (modelID) => native.model({ id: modelID }),
|
|
@@ -29,18 +28,13 @@ export const configure = (input = {}) => {
|
|
|
29
28
|
compatibility: {
|
|
30
29
|
maxTokensField: "max_tokens",
|
|
31
30
|
reasoningField: "reasoning_content",
|
|
32
|
-
supportsStrictMode: false,
|
|
33
31
|
},
|
|
32
|
+
capabilities: { tools: { strict: false } },
|
|
34
33
|
}),
|
|
35
34
|
configure,
|
|
36
35
|
};
|
|
37
36
|
};
|
|
38
37
|
export const provider = configure();
|
|
39
|
-
export const
|
|
40
|
-
|
|
41
|
-
baseURL,
|
|
42
|
-
headers,
|
|
43
|
-
http: body === undefined ? undefined : { body },
|
|
44
|
-
providerOptions,
|
|
45
|
-
}).model(modelID);
|
|
38
|
+
export const chat = provider.chat;
|
|
39
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
46
40
|
export * as Cohere from "./cohere.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
2
|
import { type HttpOptions, type ModelID } 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";
|
|
@@ -6,7 +6,7 @@ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
|
6
6
|
export type Config = ProviderAuthOption<"optional"> & {
|
|
7
7
|
readonly baseURL?: string;
|
|
8
8
|
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions
|
|
9
|
+
readonly http?: HttpOptions;
|
|
10
10
|
};
|
|
11
11
|
export declare const configure: (input?: Config) => {
|
|
12
12
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { Auth } from "../route/auth.js";
|
|
2
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
2
3
|
import { MediaRoute } from "../route/media.js";
|
|
3
4
|
import { ProviderID } from "../schema/index.js";
|
|
4
5
|
import { DeepgramSpeech } from "../protocols/deepgram-speech.js";
|
|
5
6
|
import { DeepgramTranscription } from "../protocols/deepgram-transcription.js";
|
|
6
7
|
export const id = ProviderID.make("deepgram");
|
|
7
|
-
const auth = (options) =>
|
|
8
|
-
if ("auth" in options && options.auth)
|
|
9
|
-
return options.auth;
|
|
10
|
-
return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
|
|
11
|
-
.orElse(Auth.config("DEEPGRAM_API_KEY"))
|
|
12
|
-
.pipe(Auth.scheme("Token"));
|
|
13
|
-
};
|
|
8
|
+
const auth = (options) => AuthOptions.apiKey(options, "DEEPGRAM_API_KEY", Auth.scheme("Token"));
|
|
14
9
|
export const configure = (input = {}) => {
|
|
15
10
|
const media = MediaRoute.deployment(input, auth(input));
|
|
16
11
|
return {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Route
|
|
4
|
-
import { type ModelID } from "../schema/index.js";
|
|
2
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { type ModelID, type RequestOptions } from "../schema/index.js";
|
|
5
5
|
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
-
export type Config = Omit<
|
|
7
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
8
8
|
readonly baseURL?: string;
|
|
9
9
|
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
10
10
|
};
|
|
11
11
|
export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
|
|
12
|
-
readonly apiKey?: string;
|
|
12
|
+
readonly apiKey?: string | false;
|
|
13
13
|
readonly baseURL?: string;
|
|
14
14
|
};
|
|
15
15
|
export declare const route: Route<{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
2
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
3
2
|
import { Route } from "../route/client.js";
|
|
4
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
4
|
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
6
6
|
export const id = ProviderID.make("deepinfra");
|
|
7
7
|
const baseURL = "https://api.deepinfra.com/v1/openai";
|
|
8
8
|
export const route = Route.make({
|
|
@@ -15,14 +15,12 @@ export const route = Route.make({
|
|
|
15
15
|
});
|
|
16
16
|
export const routes = [route];
|
|
17
17
|
export const configure = (input = {}) => {
|
|
18
|
-
const
|
|
19
|
-
const root = endpoint?.replace(/\/+$/, "");
|
|
18
|
+
const root = input.baseURL?.replace(/\/+$/, "");
|
|
20
19
|
const configured = route.with({
|
|
21
|
-
...
|
|
20
|
+
...bearerRouteDefaults(input, "DEEPINFRA_API_KEY"),
|
|
22
21
|
endpoint: {
|
|
23
22
|
baseURL: root === undefined ? baseURL : root.endsWith("/openai") ? root : `${root}/openai`,
|
|
24
23
|
},
|
|
25
|
-
auth: AuthOptions.bearer(input, "DEEPINFRA_API_KEY"),
|
|
26
24
|
});
|
|
27
25
|
return {
|
|
28
26
|
id,
|
|
@@ -31,17 +29,11 @@ export const configure = (input = {}) => {
|
|
|
31
29
|
compatibility: {
|
|
32
30
|
maxTokensField: "max_tokens",
|
|
33
31
|
reasoningField: "reasoning_content",
|
|
34
|
-
supportsPromptCacheKey: true,
|
|
35
32
|
},
|
|
33
|
+
capabilities: { promptCacheKey: true },
|
|
36
34
|
}),
|
|
37
35
|
configure,
|
|
38
36
|
};
|
|
39
37
|
};
|
|
40
38
|
export const provider = configure();
|
|
41
|
-
export const model = (modelID,
|
|
42
|
-
apiKey,
|
|
43
|
-
baseURL,
|
|
44
|
-
headers,
|
|
45
|
-
http: body === undefined ? undefined : { body },
|
|
46
|
-
providerOptions,
|
|
47
|
-
}).model(modelID);
|
|
39
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Route
|
|
4
|
-
import { type ModelID } from "../schema/index.js";
|
|
2
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { type ModelID, type RequestOptions } from "../schema/index.js";
|
|
5
5
|
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
-
export type Config = Omit<
|
|
7
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
8
8
|
readonly baseURL?: string;
|
|
9
9
|
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
10
10
|
};
|
|
11
11
|
export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
|
|
12
|
-
readonly apiKey?: string;
|
|
12
|
+
readonly apiKey?: string | false;
|
|
13
13
|
readonly baseURL?: string;
|
|
14
14
|
};
|
|
15
15
|
export declare const route: Route<{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
2
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
3
2
|
import { Route } from "../route/client.js";
|
|
4
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
4
|
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
6
6
|
export const id = ProviderID.make("deepseek");
|
|
7
7
|
const baseURL = "https://api.deepseek.com/v1";
|
|
8
8
|
export const route = Route.make({
|
|
@@ -15,12 +15,7 @@ export const route = Route.make({
|
|
|
15
15
|
});
|
|
16
16
|
export const routes = [route];
|
|
17
17
|
export const configure = (input = {}) => {
|
|
18
|
-
const
|
|
19
|
-
const configured = route.with({
|
|
20
|
-
...defaults,
|
|
21
|
-
endpoint: { baseURL: endpoint ?? baseURL },
|
|
22
|
-
auth: AuthOptions.bearer(input, "DEEPSEEK_API_KEY"),
|
|
23
|
-
});
|
|
18
|
+
const configured = route.with(bearerRouteDefaults(input, "DEEPSEEK_API_KEY", baseURL));
|
|
24
19
|
return {
|
|
25
20
|
id,
|
|
26
21
|
model: (modelID) => configured.model({
|
|
@@ -31,11 +26,5 @@ export const configure = (input = {}) => {
|
|
|
31
26
|
};
|
|
32
27
|
};
|
|
33
28
|
export const provider = configure();
|
|
34
|
-
export const model = (modelID,
|
|
35
|
-
apiKey,
|
|
36
|
-
baseURL,
|
|
37
|
-
headers,
|
|
38
|
-
http: body === undefined ? undefined : { body },
|
|
39
|
-
providerOptions,
|
|
40
|
-
}).model(modelID);
|
|
29
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
41
30
|
export * as DeepSeek from "./deepseek.js";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
3
|
-
import {
|
|
4
|
-
import { Route
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { Route } from "../route/client.js";
|
|
5
5
|
import { Protocol } from "../route/protocol.js";
|
|
6
|
-
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
6
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
7
7
|
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
8
8
|
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js";
|
|
9
9
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
10
|
-
export type Config = Omit<
|
|
10
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
11
11
|
readonly baseURL?: string;
|
|
12
12
|
readonly providerOptions?: OpenAIProviderOptionsInput | OpenResponsesProviderOptionsInput;
|
|
13
13
|
};
|
|
14
14
|
export type Settings<Options = OpenAIProviderOptionsInput> = ProviderPackage.Settings & Options & {
|
|
15
|
-
readonly apiKey?: string;
|
|
15
|
+
readonly apiKey?: string | false;
|
|
16
16
|
};
|
|
17
17
|
export declare const protocol: Protocol<{
|
|
18
18
|
readonly model: string;
|
|
@@ -812,6 +812,7 @@ export declare const routes: (Route<{
|
|
|
812
812
|
export declare const configure: (input?: Config) => {
|
|
813
813
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
814
814
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
815
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
815
816
|
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
816
817
|
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
817
818
|
decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
@@ -820,6 +821,7 @@ export declare const configure: (input?: Config) => {
|
|
|
820
821
|
export declare const provider: {
|
|
821
822
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
822
823
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
824
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
823
825
|
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
824
826
|
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
825
827
|
decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
@@ -827,6 +829,7 @@ export declare const provider: {
|
|
|
827
829
|
};
|
|
828
830
|
export declare const decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
829
831
|
export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
832
|
+
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
830
833
|
export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
831
834
|
export declare const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
832
835
|
export declare const responsesModel: ProviderPackage.Model<Settings<OpenResponsesProviderOptionsInput>, OpenResponsesProviderOptionsInput>;
|