@opencode/ai 2.2.5 → 2.2.7
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 +228 -72
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- 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 +30 -125
- package/dist/decision.js +27 -15
- package/dist/effect.d.ts +10 -15
- package/dist/effect.js +6 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/embedding-client.d.ts +21 -0
- package/dist/embedding-client.js +30 -0
- package/dist/embedding.d.ts +111 -0
- package/dist/embedding.js +75 -0
- 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 -465
- package/dist/image.js +17 -18
- package/dist/index.d.ts +35 -467
- package/dist/index.js +23 -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 +9 -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 -176
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- 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 +54 -72
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- 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 +7 -10
- 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 +2 -22
- package/dist/protocols/open-responses.js +41 -23
- package/dist/protocols/openai-chat.d.ts +27 -23
- package/dist/protocols/openai-chat.js +62 -57
- package/dist/protocols/openai-compatible-chat.d.ts +2 -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 +15 -2
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- 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 +14 -7
- package/dist/protocols/shared.js +40 -15
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/system-one.js +8 -1
- 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 +7 -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 +9 -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 +7 -80
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba.d.ts +70 -4
- package/dist/providers/alibaba.js +20 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +7 -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/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +325 -7
- package/dist/providers/azure.js +40 -9
- package/dist/providers/baseten.d.ts +7 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +7 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +23 -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 +6 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +14 -5
- package/dist/providers/cohere.js +23 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +10 -5
- package/dist/providers/deepinfra.js +20 -14
- package/dist/providers/deepseek.d.ts +7 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean.d.ts +18 -5
- package/dist/providers/digitalocean.js +28 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +10 -5
- package/dist/providers/fireworks.js +17 -14
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex/embeddings.d.ts +2 -0
- package/dist/providers/google-vertex/embeddings.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +4 -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 +10 -3
- package/dist/providers/google-vertex.js +52 -0
- package/dist/providers/google.d.ts +21 -13
- package/dist/providers/google.js +23 -19
- package/dist/providers/groq.d.ts +10 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +6 -5
- package/dist/providers/meta.js +10 -23
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +6 -5
- package/dist/providers/minimax.js +7 -22
- 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 +6 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
- package/dist/providers/openai-compatible/embeddings.js +1 -0
- 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 +10 -7
- package/dist/providers/openai-compatible.js +17 -10
- package/dist/providers/openai.d.ts +11 -4
- package/dist/providers/openai.js +17 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter.d.ts +24 -5
- package/dist/providers/openrouter.js +31 -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 +7 -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 +5 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +9 -5
- package/dist/providers/vercel-ai-gateway.js +30 -29
- package/dist/providers/xai.d.ts +5 -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 +6 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +6 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +14 -0
- package/dist/public.js +6 -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/embedding.d.ts +61 -0
- package/dist/route/embedding.js +88 -0
- 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 +309 -257
- 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,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<{
|
|
@@ -112,6 +112,7 @@ export declare const route: Route<{
|
|
|
112
112
|
readonly reasoning?: string | undefined;
|
|
113
113
|
readonly reasoning_text?: string | undefined;
|
|
114
114
|
readonly reasoning_details?: unknown;
|
|
115
|
+
readonly reasoning_opaque?: string | undefined;
|
|
115
116
|
})[];
|
|
116
117
|
readonly tools?: readonly ({
|
|
117
118
|
readonly type: "function";
|
|
@@ -286,6 +287,7 @@ export declare const routes: Route<{
|
|
|
286
287
|
readonly reasoning?: string | undefined;
|
|
287
288
|
readonly reasoning_text?: string | undefined;
|
|
288
289
|
readonly reasoning_details?: unknown;
|
|
290
|
+
readonly reasoning_opaque?: string | undefined;
|
|
289
291
|
})[];
|
|
290
292
|
readonly tools?: readonly ({
|
|
291
293
|
readonly type: "function";
|
|
@@ -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("cerebras");
|
|
7
7
|
const baseURL = "https://api.cerebras.ai/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, "CEREBRAS_API_KEY"),
|
|
23
|
-
});
|
|
18
|
+
const configured = route.with(bearerRouteDefaults(input, "CEREBRAS_API_KEY", baseURL));
|
|
24
19
|
return {
|
|
25
20
|
id,
|
|
26
21
|
model: (modelID) => configured.model({
|
|
@@ -28,17 +23,11 @@ export const configure = (input = {}) => {
|
|
|
28
23
|
compatibility: {
|
|
29
24
|
maxTokensField: "max_tokens",
|
|
30
25
|
reasoningField: "reasoning",
|
|
31
|
-
supportsPromptCacheKey: true,
|
|
32
26
|
},
|
|
27
|
+
capabilities: { promptCacheKey: true },
|
|
33
28
|
}),
|
|
34
29
|
configure,
|
|
35
30
|
};
|
|
36
31
|
};
|
|
37
32
|
export const provider = configure();
|
|
38
|
-
export const model = (modelID,
|
|
39
|
-
apiKey,
|
|
40
|
-
baseURL,
|
|
41
|
-
headers,
|
|
42
|
-
http: body === undefined ? undefined : { body },
|
|
43
|
-
providerOptions,
|
|
44
|
-
}).model(modelID);
|
|
33
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
@@ -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";
|
|
@@ -670,6 +669,7 @@ export declare const route: import("../route/client.js").Route<{
|
|
|
670
669
|
readonly reasoning?: string | undefined;
|
|
671
670
|
readonly reasoning_text?: string | undefined;
|
|
672
671
|
readonly reasoning_details?: unknown;
|
|
672
|
+
readonly reasoning_opaque?: string | undefined;
|
|
673
673
|
})[];
|
|
674
674
|
readonly tools?: readonly ({
|
|
675
675
|
readonly type: "function";
|
|
@@ -743,8 +743,8 @@ export declare const route: import("../route/client.js").Route<{
|
|
|
743
743
|
readonly presence_penalty?: number | undefined;
|
|
744
744
|
readonly seed?: number | undefined;
|
|
745
745
|
readonly stop?: readonly string[] | undefined;
|
|
746
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
747
|
-
export declare const routes: (import("../route
|
|
746
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined>;
|
|
747
|
+
export declare const routes: (import("../route.js").Route<{
|
|
748
748
|
readonly context_management?: {
|
|
749
749
|
readonly edits: readonly {
|
|
750
750
|
readonly type: "compact_20260112";
|
|
@@ -1051,7 +1051,7 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
1051
1051
|
} | undefined;
|
|
1052
1052
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
1053
1053
|
readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
|
|
1054
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
1054
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined> | import("../route.js").Route<{
|
|
1055
1055
|
readonly model: string;
|
|
1056
1056
|
readonly messages: readonly ({
|
|
1057
1057
|
readonly role: "system";
|
|
@@ -1151,6 +1151,7 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
1151
1151
|
readonly reasoning?: string | undefined;
|
|
1152
1152
|
readonly reasoning_text?: string | undefined;
|
|
1153
1153
|
readonly reasoning_details?: unknown;
|
|
1154
|
+
readonly reasoning_opaque?: string | undefined;
|
|
1154
1155
|
})[];
|
|
1155
1156
|
readonly tools?: readonly ({
|
|
1156
1157
|
readonly type: "function";
|
|
@@ -1224,7 +1225,7 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
1224
1225
|
readonly presence_penalty?: number | undefined;
|
|
1225
1226
|
readonly seed?: number | undefined;
|
|
1226
1227
|
readonly stop?: readonly string[] | undefined;
|
|
1227
|
-
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route
|
|
1228
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined> | import("../route.js").Route<{
|
|
1228
1229
|
readonly model: string;
|
|
1229
1230
|
readonly input: readonly ({
|
|
1230
1231
|
readonly type: "configuration_update";
|
|
@@ -1463,6 +1464,12 @@ export declare const configure: (input: Config) => {
|
|
|
1463
1464
|
endpoint: import("../route/client.js").CompactOperation;
|
|
1464
1465
|
trigger: import("../route/client.js").TriggerCompactOperation;
|
|
1465
1466
|
}>;
|
|
1467
|
+
chat: (value: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route.js").CompactionOperations | undefined>;
|
|
1468
|
+
responses: (value: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, {
|
|
1469
|
+
endpoint: import("../route/client.js").CompactOperation;
|
|
1470
|
+
trigger: import("../route/client.js").TriggerCompactOperation;
|
|
1471
|
+
}>;
|
|
1472
|
+
messages: (value: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route.js").CompactionOperations | undefined>;
|
|
1466
1473
|
decision: (value: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
1467
1474
|
configure: typeof configure;
|
|
1468
1475
|
};
|
|
@@ -1471,5 +1478,8 @@ export declare const provider: {
|
|
|
1471
1478
|
configure: typeof configure;
|
|
1472
1479
|
};
|
|
1473
1480
|
export declare const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1481
|
+
export declare const chat: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1482
|
+
export declare const responses: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1483
|
+
export declare const messages: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
1474
1484
|
export declare const decisionModel: (modelID: string, settings: Settings) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
1475
1485
|
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;
|
|
@@ -119,6 +119,7 @@ export declare const route: Route<{
|
|
|
119
119
|
readonly reasoning?: string | undefined;
|
|
120
120
|
readonly reasoning_text?: string | undefined;
|
|
121
121
|
readonly reasoning_details?: unknown;
|
|
122
|
+
readonly reasoning_opaque?: string | undefined;
|
|
122
123
|
})[];
|
|
123
124
|
readonly tools?: readonly ({
|
|
124
125
|
readonly type: "function";
|
|
@@ -293,6 +294,7 @@ export declare const routes: Route<{
|
|
|
293
294
|
readonly reasoning?: string | undefined;
|
|
294
295
|
readonly reasoning_text?: string | undefined;
|
|
295
296
|
readonly reasoning_details?: unknown;
|
|
297
|
+
readonly reasoning_opaque?: string | undefined;
|
|
296
298
|
})[];
|
|
297
299
|
readonly tools?: readonly ({
|
|
298
300
|
readonly type: "function";
|
|
@@ -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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { embeddingModel as model } from "../cohere.js";
|
|
@@ -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<{
|
|
@@ -168,6 +168,7 @@ export declare const chatRoute: Route<{
|
|
|
168
168
|
readonly reasoning?: string | undefined;
|
|
169
169
|
readonly reasoning_text?: string | undefined;
|
|
170
170
|
readonly reasoning_details?: unknown;
|
|
171
|
+
readonly reasoning_opaque?: string | undefined;
|
|
171
172
|
})[];
|
|
172
173
|
readonly tools?: readonly ({
|
|
173
174
|
readonly type: "function";
|
|
@@ -393,6 +394,7 @@ export declare const routes: (Route<{
|
|
|
393
394
|
readonly reasoning?: string | undefined;
|
|
394
395
|
readonly reasoning_text?: string | undefined;
|
|
395
396
|
readonly reasoning_details?: unknown;
|
|
397
|
+
readonly reasoning_opaque?: string | undefined;
|
|
396
398
|
})[];
|
|
397
399
|
readonly tools?: readonly ({
|
|
398
400
|
readonly type: "function";
|
|
@@ -476,6 +478,8 @@ export declare const configure: (input?: Config) => {
|
|
|
476
478
|
} | undefined;
|
|
477
479
|
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
478
480
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
481
|
+
/** Embeddings through the OpenAI-compatible API; the native `/v2/embed` API is not wired up. */
|
|
482
|
+
embedding: (modelID: string | ModelID, providerOptions?: Readonly<Record<string, unknown>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
|
|
479
483
|
configure: typeof configure;
|
|
480
484
|
};
|
|
481
485
|
export declare const provider: {
|
|
@@ -487,7 +491,12 @@ export declare const provider: {
|
|
|
487
491
|
} | undefined;
|
|
488
492
|
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
489
493
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
494
|
+
/** Embeddings through the OpenAI-compatible API; the native `/v2/embed` API is not wired up. */
|
|
495
|
+
embedding: (modelID: string | ModelID, providerOptions?: Readonly<Record<string, unknown>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
|
|
490
496
|
configure: typeof configure;
|
|
491
497
|
};
|
|
498
|
+
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
499
|
+
export declare const embedding: (modelID: string | ModelID, providerOptions?: Readonly<Record<string, unknown>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
|
|
492
500
|
export declare const model: ProviderPackage.Model<Settings, CohereChat.ProviderOptionsInput>;
|
|
501
|
+
export declare const embeddingModel: (modelID: string, settings?: Settings<Readonly<Record<string, unknown>>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
|
|
493
502
|
export * as Cohere from "./cohere.js";
|
package/dist/providers/cohere.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CohereChat } from "../protocols/cohere-chat.js";
|
|
2
2
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
3
|
+
import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
|
|
3
4
|
import { Route } from "../route/client.js";
|
|
4
5
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
6
6
|
import { ProviderID } from "../schema/index.js";
|
|
7
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
7
8
|
export const id = ProviderID.make("cohere");
|
|
8
9
|
const COMPATIBILITY_BASE_URL = "https://api.cohere.ai/compatibility/v1";
|
|
9
10
|
export const route = CohereChat.route;
|
|
@@ -17,10 +18,17 @@ export const chatRoute = Route.make({
|
|
|
17
18
|
});
|
|
18
19
|
export const routes = [route, chatRoute];
|
|
19
20
|
export const configure = (input = {}) => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const chat = chatRoute.with(
|
|
21
|
+
const options = bearerRouteDefaults(input, "COHERE_API_KEY", CohereChat.DEFAULT_BASE_URL);
|
|
22
|
+
const native = route.with(options);
|
|
23
|
+
const compatibility = { ...options, endpoint: { baseURL: input.baseURL ?? COMPATIBILITY_BASE_URL } };
|
|
24
|
+
const chat = chatRoute.with(compatibility);
|
|
25
|
+
const embeddingRoute = OpenAIEmbeddings.route.with({
|
|
26
|
+
provider: id,
|
|
27
|
+
endpoint: compatibility.endpoint,
|
|
28
|
+
auth: options.auth,
|
|
29
|
+
headers: input.headers,
|
|
30
|
+
http: input.http,
|
|
31
|
+
});
|
|
24
32
|
return {
|
|
25
33
|
id,
|
|
26
34
|
model: (modelID) => native.model({ id: modelID }),
|
|
@@ -29,18 +37,20 @@ export const configure = (input = {}) => {
|
|
|
29
37
|
compatibility: {
|
|
30
38
|
maxTokensField: "max_tokens",
|
|
31
39
|
reasoningField: "reasoning_content",
|
|
32
|
-
supportsStrictMode: false,
|
|
33
40
|
},
|
|
41
|
+
capabilities: { tools: { strict: false } },
|
|
34
42
|
}),
|
|
43
|
+
/** Embeddings through the OpenAI-compatible API; the native `/v2/embed` API is not wired up. */
|
|
44
|
+
embedding: (modelID, providerOptions) => embeddingRoute.model({ id: modelID, providerOptions }),
|
|
35
45
|
configure,
|
|
36
46
|
};
|
|
37
47
|
};
|
|
38
48
|
export const provider = configure();
|
|
39
|
-
export const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
providerOptions
|
|
45
|
-
}
|
|
49
|
+
export const chat = provider.chat;
|
|
50
|
+
export const embedding = provider.embedding;
|
|
51
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
52
|
+
export const embeddingModel = (modelID, settings) => {
|
|
53
|
+
const input = toConfig(settings);
|
|
54
|
+
return configure(input).embedding(modelID, input.providerOptions);
|
|
55
|
+
};
|
|
46
56
|
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 {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { embeddingModel as model } from "../deepinfra.js";
|