genkitx-aws-bedrock
Version:
Genkit AI framework plugin for AWS Bedrock APIs.
192 lines • 18.2 kB
JavaScript
;
/**
* Copyright 2026 Xavier Portilla Edo
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.anthropicClaudeHaiku45V1 = exports.anthropicClaude35SonnetV1 = exports.anthropicClaudeInstantV1 = exports.anthropicClaude2V1 = exports.anthropicClaude21V1 = exports.anthropicClaude3SonnetV1 = exports.anthropicClaude3HaikuV1 = exports.anthropicClaude3OpusV1 = exports.anthropicClaude35SonnetV2 = exports.anthropicClaude37SonnetV1 = exports.anthropicClaude35HaikuV1 = exports.metaLlama4Scout17BInstruct = exports.metaLlama4Maverick17BInstruct = exports.metaLlama38BInstruct = exports.metaLlama370BInstruct = exports.metaLlama318BInstruct = exports.metaLlama3170BInstruct = exports.metaLlama3290BInstruct = exports.metaLlama323BInstruct = exports.metaLlama321BInstruct = exports.metaLlama3211BInstruct = exports.metaLlama3370BInstruct = exports.ai21Jurassic2UltraV1 = exports.ai21Jurassic2MidV1 = exports.ai21JambaInstructV1 = exports.ai21Jamba15MiniV1 = exports.ai21Jamba15LargeV1 = exports.pixtralLarge2502V1 = exports.mistralMinistral38BInstruct = exports.mistralMinistral33BInstruct = exports.mistralMinistral314BInstruct = exports.mistralMagistralSmall2509 = exports.mistralLarge3675BInstruct = exports.mistral8x7BInstructV01 = exports.mistral7BInstructV02 = exports.mistralSmall2402V1 = exports.mistralLarge2402V1 = exports.cohereRerank35V1 = exports.cohereCommandV14 = exports.cohereCommandLightV14 = exports.cohereCommandRPlusV1 = exports.cohereCommandRV1 = exports.amazonTitanTextG1LiteV1 = exports.amazonTitanTextG1ExpressV1 = exports.amazonTitanTextG1PremierV1 = exports.amazonNovaPremierV1 = exports.amazonNova2LiteV1 = exports.amazonNovaMicroV1 = exports.amazonNovaLiteV1 = exports.amazonNovaProV1 = void 0;
exports.anyOf = exports.allOf = exports.requireApiKey = exports.requireBearerToken = exports.requireHeader = exports.allowAll = exports.onCallGenkit = exports.cohereEmbedV4 = exports.cohereEmbedMultilingualV3 = exports.cohereEmbedEnglishV3 = exports.amazonNova2MultimodalEmbeddingsV1 = exports.amazonTitanEmbedTextG1V1 = exports.amazonTitanEmbedMultimodalV2 = exports.amazonTitanEmbedTextV2 = exports.googleGemma312BIt = exports.anthropicClaudeSonnet4V1 = exports.anthropicClaudeSonnet46V1 = exports.anthropicClaudeSonnet45V1 = exports.anthropicClaudeOpus4V1 = exports.anthropicClaudeOpus46V1 = exports.anthropicClaudeOpus45V1 = exports.anthropicClaudeOpus41V1 = void 0;
exports.defineAwsBedrockModel = defineAwsBedrockModel;
exports.awsBedrock = awsBedrock;
const plugin_1 = require("genkit/plugin");
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
const aws_bedrock_llms_js_1 = require("./aws_bedrock_llms.js");
Object.defineProperty(exports, "amazonNovaProV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonNovaProV1; } });
Object.defineProperty(exports, "amazonNovaLiteV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonNovaLiteV1; } });
Object.defineProperty(exports, "amazonNovaMicroV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonNovaMicroV1; } });
Object.defineProperty(exports, "amazonTitanTextG1PremierV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonTitanTextG1PremierV1; } });
Object.defineProperty(exports, "amazonTitanTextG1ExpressV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonTitanTextG1ExpressV1; } });
Object.defineProperty(exports, "amazonTitanTextG1LiteV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonTitanTextG1LiteV1; } });
Object.defineProperty(exports, "amazonNova2LiteV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonNova2LiteV1; } });
Object.defineProperty(exports, "amazonNovaPremierV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.amazonNovaPremierV1; } });
Object.defineProperty(exports, "cohereCommandRV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.cohereCommandRV1; } });
Object.defineProperty(exports, "cohereCommandRPlusV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.cohereCommandRPlusV1; } });
Object.defineProperty(exports, "cohereCommandLightV14", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.cohereCommandLightV14; } });
Object.defineProperty(exports, "cohereCommandV14", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.cohereCommandV14; } });
Object.defineProperty(exports, "cohereRerank35V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.cohereRerank35V1; } });
Object.defineProperty(exports, "mistralLarge2402V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralLarge2402V1; } });
Object.defineProperty(exports, "mistralSmall2402V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralSmall2402V1; } });
Object.defineProperty(exports, "mistral7BInstructV02", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistral7BInstructV02; } });
Object.defineProperty(exports, "mistral8x7BInstructV01", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistral8x7BInstructV01; } });
Object.defineProperty(exports, "mistralLarge3675BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralLarge3675BInstruct; } });
Object.defineProperty(exports, "mistralMagistralSmall2509", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralMagistralSmall2509; } });
Object.defineProperty(exports, "mistralMinistral314BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralMinistral314BInstruct; } });
Object.defineProperty(exports, "mistralMinistral33BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralMinistral33BInstruct; } });
Object.defineProperty(exports, "mistralMinistral38BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.mistralMinistral38BInstruct; } });
Object.defineProperty(exports, "pixtralLarge2502V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.pixtralLarge2502V1; } });
Object.defineProperty(exports, "anthropicClaude35HaikuV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude35HaikuV1; } });
Object.defineProperty(exports, "anthropicClaude37SonnetV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude37SonnetV1; } });
Object.defineProperty(exports, "anthropicClaude35SonnetV2", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude35SonnetV2; } });
Object.defineProperty(exports, "anthropicClaude3OpusV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude3OpusV1; } });
Object.defineProperty(exports, "anthropicClaude3HaikuV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude3HaikuV1; } });
Object.defineProperty(exports, "anthropicClaude3SonnetV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude3SonnetV1; } });
Object.defineProperty(exports, "anthropicClaude21V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude21V1; } });
Object.defineProperty(exports, "anthropicClaude2V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude2V1; } });
Object.defineProperty(exports, "anthropicClaudeInstantV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeInstantV1; } });
Object.defineProperty(exports, "anthropicClaude35SonnetV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaude35SonnetV1; } });
Object.defineProperty(exports, "anthropicClaudeHaiku45V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeHaiku45V1; } });
Object.defineProperty(exports, "anthropicClaudeOpus41V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeOpus41V1; } });
Object.defineProperty(exports, "anthropicClaudeOpus45V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeOpus45V1; } });
Object.defineProperty(exports, "anthropicClaudeOpus46V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeOpus46V1; } });
Object.defineProperty(exports, "anthropicClaudeOpus4V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeOpus4V1; } });
Object.defineProperty(exports, "anthropicClaudeSonnet45V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeSonnet45V1; } });
Object.defineProperty(exports, "anthropicClaudeSonnet46V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeSonnet46V1; } });
Object.defineProperty(exports, "anthropicClaudeSonnet4V1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.anthropicClaudeSonnet4V1; } });
Object.defineProperty(exports, "ai21Jamba15LargeV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.ai21Jamba15LargeV1; } });
Object.defineProperty(exports, "ai21Jamba15MiniV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.ai21Jamba15MiniV1; } });
Object.defineProperty(exports, "ai21JambaInstructV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.ai21JambaInstructV1; } });
Object.defineProperty(exports, "ai21Jurassic2MidV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.ai21Jurassic2MidV1; } });
Object.defineProperty(exports, "ai21Jurassic2UltraV1", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.ai21Jurassic2UltraV1; } });
Object.defineProperty(exports, "metaLlama3370BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama3370BInstruct; } });
Object.defineProperty(exports, "metaLlama3211BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama3211BInstruct; } });
Object.defineProperty(exports, "metaLlama321BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama321BInstruct; } });
Object.defineProperty(exports, "metaLlama323BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama323BInstruct; } });
Object.defineProperty(exports, "metaLlama3290BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama3290BInstruct; } });
Object.defineProperty(exports, "metaLlama3170BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama3170BInstruct; } });
Object.defineProperty(exports, "metaLlama318BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama318BInstruct; } });
Object.defineProperty(exports, "metaLlama370BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama370BInstruct; } });
Object.defineProperty(exports, "metaLlama38BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama38BInstruct; } });
Object.defineProperty(exports, "metaLlama4Maverick17BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama4Maverick17BInstruct; } });
Object.defineProperty(exports, "metaLlama4Scout17BInstruct", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.metaLlama4Scout17BInstruct; } });
Object.defineProperty(exports, "googleGemma312BIt", { enumerable: true, get: function () { return aws_bedrock_llms_js_1.googleGemma312BIt; } });
const aws_bedrock_embedders_js_1 = require("./aws_bedrock_embedders.js");
Object.defineProperty(exports, "amazonTitanEmbedTextV2", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.amazonTitanEmbedTextV2; } });
Object.defineProperty(exports, "amazonTitanEmbedMultimodalV2", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.amazonTitanEmbedMultimodalV2; } });
Object.defineProperty(exports, "amazonTitanEmbedTextG1V1", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.amazonTitanEmbedTextG1V1; } });
Object.defineProperty(exports, "amazonNova2MultimodalEmbeddingsV1", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.amazonNova2MultimodalEmbeddingsV1; } });
Object.defineProperty(exports, "cohereEmbedEnglishV3", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.cohereEmbedEnglishV3; } });
Object.defineProperty(exports, "cohereEmbedMultilingualV3", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.cohereEmbedMultilingualV3; } });
Object.defineProperty(exports, "cohereEmbedV4", { enumerable: true, get: function () { return aws_bedrock_embedders_js_1.cohereEmbedV4; } });
const aws_lambda_js_1 = require("./aws_lambda.js");
Object.defineProperty(exports, "onCallGenkit", { enumerable: true, get: function () { return aws_lambda_js_1.onCallGenkit; } });
Object.defineProperty(exports, "allowAll", { enumerable: true, get: function () { return aws_lambda_js_1.allowAll; } });
Object.defineProperty(exports, "requireHeader", { enumerable: true, get: function () { return aws_lambda_js_1.requireHeader; } });
Object.defineProperty(exports, "requireBearerToken", { enumerable: true, get: function () { return aws_lambda_js_1.requireBearerToken; } });
Object.defineProperty(exports, "requireApiKey", { enumerable: true, get: function () { return aws_lambda_js_1.requireApiKey; } });
Object.defineProperty(exports, "allOf", { enumerable: true, get: function () { return aws_lambda_js_1.allOf; } });
Object.defineProperty(exports, "anyOf", { enumerable: true, get: function () { return aws_lambda_js_1.anyOf; } });
/**
* Defines a custom AWS Bedrock model that is not exported by the plugin
* @param name - The name of the model (e.g., "custom.my-model-v1:0")
* @param options - Plugin options including AWS credentials and region
* @returns A ModelAction that can be used with Genkit
*
* @example
* ```typescript
* import { defineAwsBedrockModel } from 'genkitx-aws-bedrock';
*
* const customModel = defineAwsBedrockModel('custom.my-model-v1:0', {
* region: 'us-east-1'
* });
*
* const response = await ai.generate({
* model: customModel,
* prompt: 'Hello!'
* });
* ```
*/
function defineAwsBedrockModel(name, options) {
const client = new client_bedrock_runtime_1.BedrockRuntimeClient(options || {});
const region = typeof (options === null || options === void 0 ? void 0 : options.region) === "string" ? options.region : undefined;
let inferenceRegion = "";
if (!region) {
inferenceRegion = "us"; // default to us
}
else if (region.includes("us-gov")) {
inferenceRegion = "us-gov";
}
else if (region.includes("us")) {
inferenceRegion = "us";
}
else if (region.includes("eu-")) {
inferenceRegion = "eu";
}
else if (region.includes("ap-")) {
inferenceRegion = "apac";
}
return (0, aws_bedrock_llms_js_1.awsBedrockModel)(name, client, inferenceRegion);
}
function awsBedrock(options) {
const client = new client_bedrock_runtime_1.BedrockRuntimeClient(options || {});
const region = typeof (options === null || options === void 0 ? void 0 : options.region) === "string" ? options.region : undefined;
let inferenceRegion = "";
if (!region) {
inferenceRegion = "us"; // default to us
}
else if (region.includes("us-gov")) {
inferenceRegion = "us-gov";
}
else if (region.includes("us")) {
inferenceRegion = "us";
}
else if (region.includes("eu-")) {
inferenceRegion = "eu";
}
else if (region.includes("ap-")) {
inferenceRegion = "apac";
}
return (0, plugin_1.genkitPluginV2)({
name: "aws-bedrock",
init: () => __awaiter(this, void 0, void 0, function* () {
const actions = [];
// Register models
for (const name of Object.keys((0, aws_bedrock_llms_js_1.SUPPORTED_AWS_BEDROCK_MODELS)(inferenceRegion))) {
actions.push((0, aws_bedrock_llms_js_1.awsBedrockModel)(name, client, inferenceRegion));
}
// Register custom models if provided
if (options === null || options === void 0 ? void 0 : options.customModels) {
for (const name of options.customModels) {
actions.push((0, aws_bedrock_llms_js_1.awsBedrockModel)(name, client, inferenceRegion));
}
}
// Register embedders
for (const name of Object.keys(aws_bedrock_embedders_js_1.SUPPORTED_EMBEDDING_MODELS)) {
actions.push((0, aws_bedrock_embedders_js_1.awsBedrockEmbedder)(name, client));
}
return actions;
}),
});
}
exports.default = awsBedrock;
//# sourceMappingURL=index.js.map