@opencode-ai/ai
Advanced tools
| import type { Route as RouteDef, RouteDefaultsInput } from "../route/client"; | ||
| import type { ProviderPackage } from "../provider-package"; | ||
| import { type Credentials } from "../protocols/utils/bedrock-auth"; | ||
| import { type ModelID } from "../schema"; | ||
| import { type OpenAIProviderOptionsInput } from "./openai-options"; | ||
| export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">; | ||
| export type Config = RouteDefaultsInput & { | ||
| readonly apiKey?: string; | ||
| readonly baseURL?: string; | ||
| readonly credentials?: Credentials; | ||
| readonly region?: string; | ||
| readonly providerOptions?: OpenAIProviderOptionsInput; | ||
| }; | ||
| export interface Settings extends ProviderPackage.Settings { | ||
| readonly apiKey?: string; | ||
| readonly auth?: "bearer" | "sigv4"; | ||
| readonly baseURL?: string; | ||
| readonly credentials?: Credentials; | ||
| readonly region?: string; | ||
| readonly providerOptions?: OpenAIProviderOptionsInput; | ||
| } | ||
| export declare const routes: (RouteDef<{ | ||
| readonly model: string; | ||
| readonly messages: readonly ({ | ||
| readonly role: "system"; | ||
| readonly content: string | readonly ({ | ||
| readonly type: "text"; | ||
| readonly text: string; | ||
| readonly cache_control?: { | ||
| readonly type: "ephemeral"; | ||
| readonly ttl?: string | undefined; | ||
| } | undefined; | ||
| } | { | ||
| readonly type: "image_url"; | ||
| readonly image_url: { | ||
| readonly url: string; | ||
| }; | ||
| })[]; | ||
| } | { | ||
| readonly role: "user"; | ||
| readonly content: string | readonly ({ | ||
| readonly type: "text"; | ||
| readonly text: string; | ||
| readonly cache_control?: { | ||
| readonly type: "ephemeral"; | ||
| readonly ttl?: string | undefined; | ||
| } | undefined; | ||
| } | { | ||
| readonly type: "image_url"; | ||
| readonly image_url: { | ||
| readonly url: string; | ||
| }; | ||
| })[]; | ||
| } | { | ||
| readonly [x: string]: unknown; | ||
| readonly content: string | null; | ||
| readonly role: "assistant"; | ||
| readonly reasoning?: string | undefined; | ||
| readonly reasoning_content?: string | undefined; | ||
| readonly reasoning_text?: string | undefined; | ||
| readonly cache_control?: { | ||
| readonly type: "ephemeral"; | ||
| readonly ttl?: string | undefined; | ||
| } | undefined; | ||
| readonly tool_calls?: readonly { | ||
| readonly id: string; | ||
| readonly type: "function"; | ||
| readonly function: { | ||
| readonly name: string; | ||
| readonly arguments: string; | ||
| }; | ||
| }[] | undefined; | ||
| readonly reasoning_details?: unknown; | ||
| } | { | ||
| readonly content: string; | ||
| readonly role: "tool"; | ||
| readonly tool_call_id: string; | ||
| readonly cache_control?: { | ||
| readonly type: "ephemeral"; | ||
| readonly ttl?: string | undefined; | ||
| } | undefined; | ||
| })[]; | ||
| readonly stream: true; | ||
| readonly stop?: readonly string[] | undefined; | ||
| readonly tools?: readonly { | ||
| readonly function: { | ||
| readonly name: string; | ||
| readonly description: string; | ||
| readonly parameters: { | ||
| readonly [x: string]: unknown; | ||
| }; | ||
| }; | ||
| readonly type: "function"; | ||
| readonly cache_control?: { | ||
| readonly type: "ephemeral"; | ||
| readonly ttl?: string | undefined; | ||
| } | undefined; | ||
| }[] | undefined; | ||
| readonly temperature?: number | undefined; | ||
| readonly seed?: number | undefined; | ||
| readonly max_completion_tokens?: number | undefined; | ||
| readonly max_tokens?: number | undefined; | ||
| readonly tool_choice?: "required" | "none" | "auto" | { | ||
| readonly type: "function"; | ||
| readonly function: { | ||
| readonly name: string; | ||
| }; | ||
| } | undefined; | ||
| readonly top_p?: number | undefined; | ||
| readonly store?: boolean | undefined; | ||
| readonly stream_options?: { | ||
| readonly include_usage: boolean; | ||
| } | undefined; | ||
| readonly reasoning_effort?: string | undefined; | ||
| readonly frequency_penalty?: number | undefined; | ||
| readonly presence_penalty?: number | undefined; | ||
| }, import("../route/transport/http").HttpPrepared<string>> | RouteDef<{ | ||
| readonly input: readonly ({ | ||
| readonly type: "reasoning"; | ||
| readonly summary: readonly { | ||
| readonly type: "summary_text"; | ||
| readonly text: string; | ||
| }[]; | ||
| readonly id?: string | undefined; | ||
| readonly encrypted_content?: string | null | undefined; | ||
| } | { | ||
| readonly type: "item_reference"; | ||
| readonly id: string; | ||
| } | { | ||
| readonly role: "system"; | ||
| readonly content: string; | ||
| } | { | ||
| readonly role: "user"; | ||
| readonly content: readonly ({ | ||
| readonly type: "input_image"; | ||
| readonly image_url: string; | ||
| } | { | ||
| readonly type: "input_file"; | ||
| readonly filename: string; | ||
| readonly file_data: string; | ||
| readonly mime_type?: string | undefined; | ||
| } | { | ||
| readonly type: "input_text"; | ||
| readonly text: string; | ||
| })[]; | ||
| } | { | ||
| readonly content: readonly { | ||
| readonly type: "output_text"; | ||
| readonly text: string; | ||
| }[]; | ||
| readonly role: "assistant"; | ||
| readonly phase?: "commentary" | "final_answer" | undefined; | ||
| } | { | ||
| readonly type: "function_call"; | ||
| readonly call_id: string; | ||
| readonly name: string; | ||
| readonly arguments: string; | ||
| } | { | ||
| readonly type: "function_call_output"; | ||
| readonly call_id: string; | ||
| readonly output: string | readonly ({ | ||
| readonly type: "input_image"; | ||
| readonly image_url: string; | ||
| } | { | ||
| readonly type: "input_file"; | ||
| readonly filename: string; | ||
| readonly file_data: string; | ||
| readonly mime_type?: string | undefined; | ||
| } | { | ||
| readonly type: "input_text"; | ||
| readonly text: string; | ||
| })[]; | ||
| } | { | ||
| readonly content: readonly { | ||
| readonly type: "output_text"; | ||
| readonly text: string; | ||
| }[]; | ||
| readonly role: "assistant"; | ||
| readonly phase?: "commentary" | "final_answer" | null | undefined; | ||
| })[]; | ||
| readonly model: string; | ||
| readonly stream: true; | ||
| readonly text?: { | ||
| readonly verbosity?: "low" | "medium" | "high" | undefined; | ||
| } | undefined; | ||
| readonly instructions?: string | undefined; | ||
| readonly reasoning?: { | ||
| readonly summary?: "auto" | "concise" | "detailed" | undefined; | ||
| readonly effort?: string | undefined; | ||
| } | undefined; | ||
| readonly tools?: readonly ({ | ||
| readonly type: "function"; | ||
| readonly name: string; | ||
| readonly description: string; | ||
| readonly parameters: { | ||
| readonly [x: string]: unknown; | ||
| }; | ||
| readonly strict?: boolean | undefined; | ||
| } | { | ||
| readonly type: "image_generation"; | ||
| readonly size?: string | undefined; | ||
| readonly action?: "generate" | "auto" | "edit" | undefined; | ||
| readonly output_format?: "png" | "jpeg" | "webp" | undefined; | ||
| readonly quality?: "low" | "medium" | "high" | "auto" | undefined; | ||
| readonly background?: "auto" | "opaque" | "transparent" | undefined; | ||
| readonly output_compression?: number | undefined; | ||
| readonly input_fidelity?: "low" | "high" | undefined; | ||
| readonly partial_images?: number | undefined; | ||
| })[] | undefined; | ||
| readonly temperature?: number | undefined; | ||
| readonly tool_choice?: "required" | "none" | "auto" | { | ||
| readonly type: "function"; | ||
| readonly name: string; | ||
| } | { | ||
| readonly type: "image_generation"; | ||
| } | undefined; | ||
| readonly top_p?: number | undefined; | ||
| readonly include?: readonly ("file_search_call.results" | "web_search_call.results" | "web_search_call.action.sources" | "message.input_image.image_url" | "computer_call_output.output.image_url" | "code_interpreter_call.outputs" | "reasoning.encrypted_content" | "message.output_text.logprobs")[] | undefined; | ||
| readonly store?: boolean | undefined; | ||
| readonly service_tier?: "auto" | "default" | "flex" | "priority" | undefined; | ||
| readonly prompt_cache_key?: string | undefined; | ||
| readonly max_output_tokens?: number | undefined; | ||
| }, import("../route/transport/http").HttpPrepared<string>>)[]; | ||
| export declare const configure: (input?: Config) => { | ||
| id: string & import("effect/Brand").Brand<"AI.ProviderID">; | ||
| model: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| chat: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| responses: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| configure: (input?: Config) => /*elided*/ any; | ||
| }; | ||
| export declare const provider: { | ||
| id: string & import("effect/Brand").Brand<"AI.ProviderID">; | ||
| model: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| chat: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| responses: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| configure: (input?: Config) => { | ||
| id: string & import("effect/Brand").Brand<"AI.ProviderID">; | ||
| model: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| chat: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| responses: (modelID: string | ModelID) => import("..").LanguageModel<OpenAIProviderOptionsInput>; | ||
| configure: /*elided*/ any; | ||
| }; | ||
| }; | ||
| export declare const chatModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"]; | ||
| export declare const responsesModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"]; | ||
| export declare const model: (modelID: string, settings: Settings) => import("..").LanguageModel<OpenAIProviderOptionsInput>; |
| import { Auth } from "../route/auth"; | ||
| import { OpenAIChat } from "../protocols/openai-chat"; | ||
| import { OpenAIResponses } from "../protocols/openai-responses"; | ||
| import { BedrockAuth } from "../protocols/utils/bedrock-auth"; | ||
| import { ProviderID } from "../schema"; | ||
| import { withOpenAIOptions } from "./openai-options"; | ||
| export const id = ProviderID.make("amazon-bedrock"); | ||
| const responsesRoute = OpenAIResponses.route.with({ | ||
| id: "bedrock-mantle-responses", | ||
| provider: id, | ||
| }); | ||
| const chatRoute = OpenAIChat.route.with({ | ||
| id: "bedrock-mantle-chat", | ||
| provider: id, | ||
| }); | ||
| export const routes = [responsesRoute, chatRoute]; | ||
| const configuredRoute = (route, input) => { | ||
| const region = input.region ?? input.credentials?.region ?? "us-east-1"; | ||
| const credentials = input.credentials === undefined ? undefined : { ...input.credentials, region }; | ||
| return route.with({ | ||
| endpoint: { baseURL: input.baseURL ?? `https://bedrock-mantle.${region}.api.aws/v1` }, | ||
| auth: input.apiKey === undefined | ||
| ? BedrockAuth.sigV4(credentials, { service: "bedrock-mantle", name: "Bedrock Mantle" }) | ||
| : Auth.bearer(input.apiKey), | ||
| }); | ||
| }; | ||
| const defaults = (input) => { | ||
| const { apiKey: _, baseURL: _baseURL, credentials: _credentials, region: _region, ...rest } = input; | ||
| return rest; | ||
| }; | ||
| export const configure = (input = {}) => { | ||
| const configuredResponsesRoute = configuredRoute(responsesRoute, input); | ||
| const configuredChatRoute = configuredRoute(chatRoute, input); | ||
| const modelDefaults = defaults(input); | ||
| const responses = (modelID) => configuredResponsesRoute | ||
| .with(withOpenAIOptions(modelID, modelDefaults)) | ||
| .model({ id: modelID }); | ||
| const chat = (modelID) => configuredChatRoute | ||
| .with(withOpenAIOptions(modelID, modelDefaults)) | ||
| .model({ id: modelID }); | ||
| return { | ||
| id, | ||
| model: chat, | ||
| chat, | ||
| responses, | ||
| configure, | ||
| }; | ||
| }; | ||
| export const provider = configure(); | ||
| const config = (settings) => { | ||
| if (settings.auth === "bearer" && settings.apiKey === undefined) | ||
| throw new Error("Amazon Bedrock Mantle bearer auth requires apiKey"); | ||
| if (settings.auth === "sigv4" && settings.apiKey !== undefined) | ||
| throw new Error("Amazon Bedrock Mantle SigV4 auth does not accept apiKey"); | ||
| return { | ||
| apiKey: settings.auth === "sigv4" ? undefined : settings.apiKey, | ||
| baseURL: settings.baseURL, | ||
| credentials: settings.credentials, | ||
| headers: settings.headers === undefined ? undefined : { ...settings.headers }, | ||
| http: settings.body === undefined ? undefined : { body: { ...settings.body } }, | ||
| limits: settings.limits, | ||
| providerOptions: settings.providerOptions, | ||
| region: settings.region, | ||
| }; | ||
| }; | ||
| export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID); | ||
| export const responsesModel = (modelID, settings) => configure(config(settings)).responses(modelID); | ||
| export const model = chatModel; |
| export { chatModel as model } from "../amazon-bedrock-mantle"; | ||
| export type { Settings } from "../amazon-bedrock-mantle"; |
| export { chatModel as model } from "../amazon-bedrock-mantle"; |
| export { chatModel as model } from "../../amazon-bedrock-mantle"; | ||
| export type { Settings } from "../../amazon-bedrock-mantle"; |
| export { chatModel as model } from "../../amazon-bedrock-mantle"; |
| export { responsesModel as model } from "../../amazon-bedrock-mantle"; | ||
| export type { Settings } from "../../amazon-bedrock-mantle"; |
| export { responsesModel as model } from "../../amazon-bedrock-mantle"; |
@@ -529,3 +529,6 @@ import { Schema } from "effect"; | ||
| }, import("../route/transport/http").HttpPrepared<object>>; | ||
| export declare const sigV4Auth: (credentials: BedrockAuth.Credentials | undefined) => import("../route").AuthShape; | ||
| export declare const sigV4Auth: (credentials: BedrockAuth.Credentials | undefined, options?: { | ||
| readonly service?: string; | ||
| readonly name?: string; | ||
| }) => import("../route").AuthShape; | ||
| export * as BedrockConverse from "./bedrock-converse"; |
@@ -15,5 +15,8 @@ import { Auth } from "../../route/auth"; | ||
| /** Sign the exact JSON bytes with SigV4 using credentials configured on the route. */ | ||
| export declare const sigV4: (credentials: Credentials | undefined) => Auth.Definition; | ||
| export declare const sigV4: (credentials: Credentials | undefined, options?: { | ||
| readonly service?: string; | ||
| readonly name?: string; | ||
| }) => Auth.Definition; | ||
| /** Bedrock route auth defaults to SigV4 and expects credentials from route configuration. */ | ||
| export declare const auth: Auth.Definition; | ||
| export * as BedrockAuth from "./bedrock-auth"; |
@@ -17,13 +17,13 @@ import { AwsV4Signer } from "aws4fetch"; | ||
| sessionToken: input.credentials.sessionToken, | ||
| service: "bedrock", | ||
| service: input.service, | ||
| }).sign(); | ||
| return Object.fromEntries(signed.headers.entries()); | ||
| }, | ||
| catch: (error) => ProviderShared.invalidRequest(`Bedrock Converse SigV4 signing failed: ${error instanceof Error ? error.message : String(error)}`), | ||
| catch: (error) => ProviderShared.invalidRequest(`${input.name} SigV4 signing failed: ${error instanceof Error ? error.message : String(error)}`), | ||
| }); | ||
| /** Sign the exact JSON bytes with SigV4 using credentials configured on the route. */ | ||
| export const sigV4 = (credentials) => Auth.custom((input) => { | ||
| export const sigV4 = (credentials, options = {}) => Auth.custom((input) => { | ||
| return Effect.gen(function* () { | ||
| if (!credentials) { | ||
| return yield* ProviderShared.invalidRequest("Bedrock Converse requires either route bearer auth or AWS credentials configured on the route"); | ||
| return yield* ProviderShared.invalidRequest(`${options.name ?? "Bedrock Converse"} requires either route bearer auth or AWS credentials configured on the route`); | ||
| } | ||
@@ -36,2 +36,4 @@ const headersForSigning = Headers.set(input.headers, "content-type", "application/json"); | ||
| credentials, | ||
| service: options.service ?? "bedrock", | ||
| name: options.name ?? "Bedrock Converse", | ||
| }); | ||
@@ -38,0 +40,0 @@ return Headers.setAll(headersForSigning, signed); |
| export * as Anthropic from "./anthropic"; | ||
| export * as AnthropicCompatible from "./anthropic-compatible"; | ||
| export * as AmazonBedrock from "./amazon-bedrock"; | ||
| export * as AmazonBedrockMantle from "./amazon-bedrock-mantle"; | ||
| export * as Azure from "./azure"; | ||
@@ -5,0 +6,0 @@ export * as Cloudflare from "./cloudflare"; |
| export * as Anthropic from "./anthropic"; | ||
| export * as AnthropicCompatible from "./anthropic-compatible"; | ||
| export * as AmazonBedrock from "./amazon-bedrock"; | ||
| export * as AmazonBedrockMantle from "./amazon-bedrock-mantle"; | ||
| export * as Azure from "./azure"; | ||
@@ -5,0 +6,0 @@ export * as Cloudflare from "./cloudflare"; |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-next-16680", | ||
| "version": "0.0.0-next-16689", | ||
| "name": "@opencode-ai/ai", | ||
@@ -33,3 +33,3 @@ "type": "module", | ||
| "@effect/platform-node": "4.0.0-beta.101", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16680", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16689", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -43,3 +43,3 @@ "@types/bun": "1.3.13", | ||
| "@smithy/util-utf8": "4.2.2", | ||
| "@opencode-ai/schema": "0.0.0-next-16680", | ||
| "@opencode-ai/schema": "0.0.0-next-16689", | ||
| "aws4fetch": "1.0.20", | ||
@@ -46,0 +46,0 @@ "effect": "4.0.0-beta.101", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1132259
1.27%190
4.4%26450
1.28%+ Added
- Removed