New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ai-sdk/amazon-bedrock

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/amazon-bedrock - npm Package Compare versions

Comparing version

to
0.0.32

162

./dist/index.js

@@ -36,2 +36,68 @@ "use strict";

// src/bedrock-prepare-tools.ts
function prepareTools(mode) {
var _a;
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
if (tools == null) {
return {
toolConfiguration: { tools: void 0, toolChoice: void 0 },
toolWarnings: []
};
}
const toolWarnings = [];
const bedrockTools = [];
for (const tool of tools) {
if (tool.type === "provider-defined") {
toolWarnings.push({ type: "unsupported-tool", tool });
} else {
bedrockTools.push({
toolSpec: {
name: tool.name,
description: tool.description,
inputSchema: {
json: tool.parameters
}
}
});
}
}
const toolChoice = mode.toolChoice;
if (toolChoice == null) {
return {
toolConfiguration: { tools: bedrockTools, toolChoice: void 0 },
toolWarnings
};
}
const type = toolChoice.type;
switch (type) {
case "auto":
return {
toolConfiguration: { tools: bedrockTools, toolChoice: { auto: {} } },
toolWarnings
};
case "required":
return {
toolConfiguration: { tools: bedrockTools, toolChoice: { any: {} } },
toolWarnings
};
case "none":
return {
toolConfiguration: { tools: void 0, toolChoice: void 0 },
toolWarnings
};
case "tool":
return {
toolConfiguration: {
tools: bedrockTools,
toolChoice: { tool: { name: toolChoice.toolName } }
},
toolWarnings
};
default: {
const _exhaustiveCheck = type;
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
}
}
}
// src/convert-to-bedrock-chat-messages.ts

@@ -234,3 +300,3 @@ var import_provider = require("@ai-sdk/provider");

}
async getArgs({
getArgs({
mode,

@@ -306,6 +372,9 @@ prompt,

case "regular": {
const toolConfig = prepareToolsAndToolChoice(mode);
const { toolConfiguration, toolWarnings } = prepareTools(mode);
return {
...baseArgs,
...((_b = toolConfig.tools) == null ? void 0 : _b.length) ? { toolConfig } : {}
command: {
...baseArgs,
...((_b = toolConfiguration.tools) == null ? void 0 : _b.length) ? { toolConfiguration } : {}
},
warnings: [...warnings, ...toolWarnings]
};

@@ -320,17 +389,20 @@ }

return {
...baseArgs,
toolConfig: {
tools: [
{
toolSpec: {
name: mode.tool.name,
description: mode.tool.description,
inputSchema: {
json: mode.tool.parameters
command: {
...baseArgs,
toolConfig: {
tools: [
{
toolSpec: {
name: mode.tool.name,
description: mode.tool.description,
inputSchema: {
json: mode.tool.parameters
}
}
}
}
],
toolChoice: { tool: { name: mode.tool.name } }
}
],
toolChoice: { tool: { name: mode.tool.name } }
}
},
warnings
};

@@ -346,5 +418,7 @@ }

var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
const args = await this.getArgs(options);
const response = await this.config.client.send(new import_client_bedrock_runtime.ConverseCommand(args));
const { messages: rawPrompt, ...rawSettings } = args;
const { command, warnings } = this.getArgs(options);
const response = await this.config.client.send(
new import_client_bedrock_runtime.ConverseCommand(command)
);
const { messages: rawPrompt, ...rawSettings } = command;
const providerMetadata = response.trace ? { bedrock: { trace: response.trace } } : void 0;

@@ -371,3 +445,3 @@ return {

rawCall: { rawPrompt, rawSettings },
warnings: [],
warnings,
providerMetadata

@@ -377,7 +451,7 @@ };

async doStream(options) {
const args = await this.getArgs(options);
const { command, warnings } = this.getArgs(options);
const response = await this.config.client.send(
new import_client_bedrock_runtime.ConverseStreamCommand({ ...args })
new import_client_bedrock_runtime.ConverseStreamCommand(command)
);
const { messages: rawPrompt, ...rawSettings } = args;
const { messages: rawPrompt, ...rawSettings } = command;
let finishReason = "unknown";

@@ -504,44 +578,6 @@ let usage = {

rawCall: { rawPrompt, rawSettings },
warnings: []
warnings
};
}
};
function prepareToolsAndToolChoice(mode) {
var _a;
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
if (tools == null) {
return { tools: void 0, toolChoice: void 0 };
}
const mappedTools = tools.map((tool) => ({
toolSpec: {
name: tool.name,
description: tool.description,
inputSchema: {
json: tool.parameters
}
}
}));
const toolChoice = mode.toolChoice;
if (toolChoice == null) {
return { tools: mappedTools, toolChoice: void 0 };
}
const type = toolChoice.type;
switch (type) {
case "auto":
return { tools: mappedTools, toolChoice: { auto: {} } };
case "required":
return { tools: mappedTools, toolChoice: { any: {} } };
case "none":
return { tools: void 0, toolChoice: void 0 };
case "tool":
return {
tools: mappedTools,
toolChoice: { tool: { name: toolChoice.toolName } }
};
default: {
const _exhaustiveCheck = type;
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
}
}
}

@@ -548,0 +584,0 @@ // src/bedrock-embedding-model.ts

# @ai-sdk/amazon-bedrock
## 0.0.32
### Patch Changes
- 3b1b69a: feat: provider-defined tools
- Updated dependencies [aa98cdb]
- Updated dependencies [1486128]
- Updated dependencies [7b937c5]
- Updated dependencies [3b1b69a]
- Updated dependencies [811a317]
- @ai-sdk/provider-utils@1.0.22
- @ai-sdk/provider@0.0.26
## 0.0.31
### Patch Changes
- Updated dependencies [b9b0d7b]
- @ai-sdk/provider@0.0.25
- @ai-sdk/provider-utils@1.0.21
## 0.0.30

@@ -4,0 +25,0 @@

@@ -36,2 +36,68 @@ "use strict";

// src/bedrock-prepare-tools.ts
function prepareTools(mode) {
var _a;
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
if (tools == null) {
return {
toolConfiguration: { tools: void 0, toolChoice: void 0 },
toolWarnings: []
};
}
const toolWarnings = [];
const bedrockTools = [];
for (const tool of tools) {
if (tool.type === "provider-defined") {
toolWarnings.push({ type: "unsupported-tool", tool });
} else {
bedrockTools.push({
toolSpec: {
name: tool.name,
description: tool.description,
inputSchema: {
json: tool.parameters
}
}
});
}
}
const toolChoice = mode.toolChoice;
if (toolChoice == null) {
return {
toolConfiguration: { tools: bedrockTools, toolChoice: void 0 },
toolWarnings
};
}
const type = toolChoice.type;
switch (type) {
case "auto":
return {
toolConfiguration: { tools: bedrockTools, toolChoice: { auto: {} } },
toolWarnings
};
case "required":
return {
toolConfiguration: { tools: bedrockTools, toolChoice: { any: {} } },
toolWarnings
};
case "none":
return {
toolConfiguration: { tools: void 0, toolChoice: void 0 },
toolWarnings
};
case "tool":
return {
toolConfiguration: {
tools: bedrockTools,
toolChoice: { tool: { name: toolChoice.toolName } }
},
toolWarnings
};
default: {
const _exhaustiveCheck = type;
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
}
}
}
// src/convert-to-bedrock-chat-messages.ts

@@ -234,3 +300,3 @@ var import_provider = require("@ai-sdk/provider");

}
async getArgs({
getArgs({
mode,

@@ -306,6 +372,9 @@ prompt,

case "regular": {
const toolConfig = prepareToolsAndToolChoice(mode);
const { toolConfiguration, toolWarnings } = prepareTools(mode);
return {
...baseArgs,
...((_b = toolConfig.tools) == null ? void 0 : _b.length) ? { toolConfig } : {}
command: {
...baseArgs,
...((_b = toolConfiguration.tools) == null ? void 0 : _b.length) ? { toolConfiguration } : {}
},
warnings: [...warnings, ...toolWarnings]
};

@@ -320,17 +389,20 @@ }

return {
...baseArgs,
toolConfig: {
tools: [
{
toolSpec: {
name: mode.tool.name,
description: mode.tool.description,
inputSchema: {
json: mode.tool.parameters
command: {
...baseArgs,
toolConfig: {
tools: [
{
toolSpec: {
name: mode.tool.name,
description: mode.tool.description,
inputSchema: {
json: mode.tool.parameters
}
}
}
}
],
toolChoice: { tool: { name: mode.tool.name } }
}
],
toolChoice: { tool: { name: mode.tool.name } }
}
},
warnings
};

@@ -346,5 +418,7 @@ }

var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
const args = await this.getArgs(options);
const response = await this.config.client.send(new import_client_bedrock_runtime.ConverseCommand(args));
const { messages: rawPrompt, ...rawSettings } = args;
const { command, warnings } = this.getArgs(options);
const response = await this.config.client.send(
new import_client_bedrock_runtime.ConverseCommand(command)
);
const { messages: rawPrompt, ...rawSettings } = command;
const providerMetadata = response.trace ? { bedrock: { trace: response.trace } } : void 0;

@@ -371,3 +445,3 @@ return {

rawCall: { rawPrompt, rawSettings },
warnings: [],
warnings,
providerMetadata

@@ -377,7 +451,7 @@ };

async doStream(options) {
const args = await this.getArgs(options);
const { command, warnings } = this.getArgs(options);
const response = await this.config.client.send(
new import_client_bedrock_runtime.ConverseStreamCommand({ ...args })
new import_client_bedrock_runtime.ConverseStreamCommand(command)
);
const { messages: rawPrompt, ...rawSettings } = args;
const { messages: rawPrompt, ...rawSettings } = command;
let finishReason = "unknown";

@@ -504,44 +578,6 @@ let usage = {

rawCall: { rawPrompt, rawSettings },
warnings: []
warnings
};
}
};
function prepareToolsAndToolChoice(mode) {
var _a;
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
if (tools == null) {
return { tools: void 0, toolChoice: void 0 };
}
const mappedTools = tools.map((tool) => ({
toolSpec: {
name: tool.name,
description: tool.description,
inputSchema: {
json: tool.parameters
}
}
}));
const toolChoice = mode.toolChoice;
if (toolChoice == null) {
return { tools: mappedTools, toolChoice: void 0 };
}
const type = toolChoice.type;
switch (type) {
case "auto":
return { tools: mappedTools, toolChoice: { auto: {} } };
case "required":
return { tools: mappedTools, toolChoice: { any: {} } };
case "none":
return { tools: void 0, toolChoice: void 0 };
case "tool":
return {
tools: mappedTools,
toolChoice: { tool: { name: toolChoice.toolName } }
};
default: {
const _exhaustiveCheck = type;
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
}
}
}

@@ -548,0 +584,0 @@ // src/bedrock-embedding-model.ts

{
"name": "@ai-sdk/amazon-bedrock",
"version": "0.0.30",
"version": "0.0.32",
"license": "Apache-2.0",

@@ -22,4 +22,4 @@ "sideEffects": false,

"dependencies": {
"@ai-sdk/provider": "0.0.24",
"@ai-sdk/provider-utils": "1.0.20",
"@ai-sdk/provider": "0.0.26",
"@ai-sdk/provider-utils": "1.0.22",
"@aws-sdk/client-bedrock-runtime": "^3.663.0"

@@ -26,0 +26,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet