@bestdefense/bd-agent 0.1.0
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 +95 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/chat.d.ts +4 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +101 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/services/bedrock-client.d.ts +22 -0
- package/dist/services/bedrock-client.d.ts.map +1 -0
- package/dist/services/bedrock-client.js +65 -0
- package/dist/services/bedrock-client.js.map +1 -0
- package/dist/services/conversation-manager.d.ts +13 -0
- package/dist/services/conversation-manager.d.ts.map +1 -0
- package/dist/services/conversation-manager.js +41 -0
- package/dist/services/conversation-manager.js.map +1 -0
- package/dist/services/tool-executor.d.ts +11 -0
- package/dist/services/tool-executor.d.ts.map +1 -0
- package/dist/services/tool-executor.js +49 -0
- package/dist/services/tool-executor.js.map +1 -0
- package/dist/tools/file-system.d.ts +127 -0
- package/dist/tools/file-system.d.ts.map +1 -0
- package/dist/tools/file-system.js +173 -0
- package/dist/tools/file-system.js.map +1 -0
- package/dist/tools/git.d.ts +163 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +169 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/shell.d.ts +40 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +55 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/utils/config.d.ts +11 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +75 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/prompts.d.ts +2 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +34 -0
- package/dist/utils/prompts.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# BD Agent
|
2
|
+
|
3
|
+
An AI-powered coding assistant CLI that connects to AWS Bedrock. BD Agent helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install -g @bestdefense-io/bd-agent
|
9
|
+
```
|
10
|
+
|
11
|
+
## Setup
|
12
|
+
|
13
|
+
Before using BD Agent, you need to configure your AWS credentials:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bd-agent setup
|
17
|
+
```
|
18
|
+
|
19
|
+
You'll be prompted to enter:
|
20
|
+
- AWS Access Key ID
|
21
|
+
- AWS Secret Access Key
|
22
|
+
- AWS Session Token (optional)
|
23
|
+
- AWS Region (default: us-east-1)
|
24
|
+
- Bedrock Model ID (default: anthropic.claude-3-5-sonnet-20241022-v2:0)
|
25
|
+
|
26
|
+
Alternatively, you can set these as environment variables:
|
27
|
+
- `AWS_ACCESS_KEY_ID`
|
28
|
+
- `AWS_SECRET_ACCESS_KEY`
|
29
|
+
- `AWS_SESSION_TOKEN`
|
30
|
+
- `AWS_REGION`
|
31
|
+
- `BEDROCK_MODEL_ID`
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Start an interactive chat session:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
bd-agent chat
|
39
|
+
```
|
40
|
+
|
41
|
+
### Available Commands
|
42
|
+
|
43
|
+
BD Agent can help you with:
|
44
|
+
|
45
|
+
- **File Operations**: Read, write, and edit files
|
46
|
+
- **Git Workflows**: Check status, stage changes, commit, view logs
|
47
|
+
- **Shell Commands**: Execute any shell command
|
48
|
+
- **Code Assistance**: Write new code, debug issues, refactor, explain complex code
|
49
|
+
|
50
|
+
### Example Interactions
|
51
|
+
|
52
|
+
```
|
53
|
+
You: Can you help me create a new React component called UserProfile?
|
54
|
+
|
55
|
+
You: Show me the current git status and any uncommitted changes
|
56
|
+
|
57
|
+
You: Run the tests and fix any failing ones
|
58
|
+
|
59
|
+
You: Explain how this authentication middleware works
|
60
|
+
```
|
61
|
+
|
62
|
+
## Available Tools
|
63
|
+
|
64
|
+
### File System Tools
|
65
|
+
- `read_file` - Read file contents
|
66
|
+
- `write_file` - Write content to files
|
67
|
+
- `edit_file` - Replace content in files
|
68
|
+
- `list_directory` - List directory contents
|
69
|
+
|
70
|
+
### Git Tools
|
71
|
+
- `git_status` - Check repository status
|
72
|
+
- `git_diff` - Show changes
|
73
|
+
- `git_add` - Stage files
|
74
|
+
- `git_commit` - Create commits
|
75
|
+
- `git_log` - View commit history
|
76
|
+
|
77
|
+
### Shell Tools
|
78
|
+
- `run_command` - Execute shell commands
|
79
|
+
|
80
|
+
## Requirements
|
81
|
+
|
82
|
+
- Node.js >= 18.0.0
|
83
|
+
- AWS account with Bedrock access
|
84
|
+
- Valid AWS credentials with permissions to invoke Bedrock models
|
85
|
+
|
86
|
+
## Security
|
87
|
+
|
88
|
+
BD Agent stores your AWS credentials locally in `~/.bd-agent/.env`. Make sure to:
|
89
|
+
- Keep your credentials secure
|
90
|
+
- Use IAM roles with minimal required permissions
|
91
|
+
- Rotate your credentials regularly
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
MIT
|
package/dist/cli.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
+
};
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
const commander_1 = require("commander");
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
10
|
+
const config_1 = require("./utils/config");
|
11
|
+
const chat_1 = require("./commands/chat");
|
12
|
+
const package_json_1 = require("../package.json");
|
13
|
+
const program = new commander_1.Command();
|
14
|
+
program
|
15
|
+
.name('bd-agent')
|
16
|
+
.description('AI-powered coding assistant CLI connected to AWS Bedrock')
|
17
|
+
.version(package_json_1.version);
|
18
|
+
program
|
19
|
+
.command('chat')
|
20
|
+
.description('Start an interactive chat session')
|
21
|
+
.option('-m, --model <model>', 'Bedrock model ID to use')
|
22
|
+
.action(async (options) => {
|
23
|
+
if (!(0, config_1.validateConfig)()) {
|
24
|
+
console.log(chalk_1.default.yellow('AWS credentials not configured. Running setup...'));
|
25
|
+
await runSetup();
|
26
|
+
}
|
27
|
+
await (0, chat_1.startChat)(options);
|
28
|
+
});
|
29
|
+
program
|
30
|
+
.command('setup')
|
31
|
+
.description('Configure AWS credentials and settings')
|
32
|
+
.action(runSetup);
|
33
|
+
async function runSetup() {
|
34
|
+
console.log(chalk_1.default.blue('BD Agent Setup'));
|
35
|
+
console.log(chalk_1.default.gray('Configure your AWS credentials for Bedrock access\n'));
|
36
|
+
const answers = await inquirer_1.default.prompt([
|
37
|
+
{
|
38
|
+
type: 'input',
|
39
|
+
name: 'AWS_ACCESS_KEY_ID',
|
40
|
+
message: 'AWS Access Key ID:',
|
41
|
+
validate: (input) => input.length > 0 || 'Access Key ID is required'
|
42
|
+
},
|
43
|
+
{
|
44
|
+
type: 'password',
|
45
|
+
name: 'AWS_SECRET_ACCESS_KEY',
|
46
|
+
message: 'AWS Secret Access Key:',
|
47
|
+
validate: (input) => input.length > 0 || 'Secret Access Key is required'
|
48
|
+
},
|
49
|
+
{
|
50
|
+
type: 'input',
|
51
|
+
name: 'AWS_SESSION_TOKEN',
|
52
|
+
message: 'AWS Session Token (optional):'
|
53
|
+
},
|
54
|
+
{
|
55
|
+
type: 'input',
|
56
|
+
name: 'AWS_REGION',
|
57
|
+
message: 'AWS Region:',
|
58
|
+
default: 'us-east-1'
|
59
|
+
},
|
60
|
+
{
|
61
|
+
type: 'input',
|
62
|
+
name: 'BEDROCK_MODEL_ID',
|
63
|
+
message: 'Bedrock Model ID:',
|
64
|
+
default: 'anthropic.claude-3-5-sonnet-20241022-v2:0'
|
65
|
+
}
|
66
|
+
]);
|
67
|
+
(0, config_1.saveConfig)(answers);
|
68
|
+
console.log(chalk_1.default.green('\n✓ Configuration saved successfully!'));
|
69
|
+
console.log(chalk_1.default.gray('You can now use: bd-agent chat'));
|
70
|
+
}
|
71
|
+
program.parse(process.argv);
|
72
|
+
if (!process.argv.slice(2).length) {
|
73
|
+
program.outputHelp();
|
74
|
+
}
|
75
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,wDAAgC;AAChC,2CAA4D;AAC5D,0CAA4C;AAC5C,kDAA0C;AAE1C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,0DAA0D,CAAC;KACvE,OAAO,CAAC,sBAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,mCAAmC,CAAC;KAChD,MAAM,CAAC,qBAAqB,EAAE,yBAAyB,CAAC;KACxD,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,CAAC,IAAA,uBAAc,GAAE,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,kDAAkD,CAAC,CAAC,CAAC;QAC9E,MAAM,QAAQ,EAAE,CAAC;IACnB,CAAC;IACD,MAAM,IAAA,gBAAS,EAAC,OAAO,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,w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,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAYA,wBAAsB,SAAS,CAAC,OAAO,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,iBAyG1D"}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.startChat = startChat;
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
9
|
+
const ora_1 = __importDefault(require("ora"));
|
10
|
+
const marked_1 = require("marked");
|
11
|
+
const bedrock_client_1 = require("../services/bedrock-client");
|
12
|
+
const conversation_manager_1 = require("../services/conversation-manager");
|
13
|
+
const tool_executor_1 = require("../services/tool-executor");
|
14
|
+
const prompts_1 = require("../utils/prompts");
|
15
|
+
const markedTerminal = require('marked-terminal');
|
16
|
+
marked_1.marked.use(markedTerminal);
|
17
|
+
async function startChat(options) {
|
18
|
+
const client = new bedrock_client_1.BedrockClient();
|
19
|
+
const conversation = new conversation_manager_1.ConversationManager();
|
20
|
+
const toolExecutor = new tool_executor_1.ToolExecutor();
|
21
|
+
console.log(chalk_1.default.blue('BD Agent - AI Coding Assistant'));
|
22
|
+
console.log(chalk_1.default.gray('Type "exit" or "quit" to end the session\n'));
|
23
|
+
while (true) {
|
24
|
+
const { message } = await inquirer_1.default.prompt([
|
25
|
+
{
|
26
|
+
type: 'input',
|
27
|
+
name: 'message',
|
28
|
+
message: chalk_1.default.green('You:'),
|
29
|
+
validate: (input) => input.trim().length > 0 || 'Please enter a message'
|
30
|
+
}
|
31
|
+
]);
|
32
|
+
if (['exit', 'quit'].includes(message.toLowerCase())) {
|
33
|
+
console.log(chalk_1.default.yellow('\nGoodbye!'));
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
conversation.addMessage('user', message);
|
37
|
+
const spinner = (0, ora_1.default)('Thinking...').start();
|
38
|
+
try {
|
39
|
+
const messages = conversation.getMessages();
|
40
|
+
const tools = toolExecutor.getAvailableTools();
|
41
|
+
const systemPrompt = (0, prompts_1.getSystemPrompt)();
|
42
|
+
let assistantMessage = '';
|
43
|
+
let pendingToolCalls = [];
|
44
|
+
const stream = client.streamMessage(messages, tools, systemPrompt);
|
45
|
+
for await (const chunk of stream) {
|
46
|
+
if (typeof chunk === 'string') {
|
47
|
+
assistantMessage += chunk;
|
48
|
+
}
|
49
|
+
else if (chunk && 'toolUseId' in chunk) {
|
50
|
+
pendingToolCalls.push(chunk);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
spinner.stop();
|
54
|
+
if (assistantMessage) {
|
55
|
+
console.log(chalk_1.default.blue('\nAssistant:'));
|
56
|
+
console.log((0, marked_1.marked)(assistantMessage));
|
57
|
+
conversation.addMessage('assistant', assistantMessage);
|
58
|
+
}
|
59
|
+
if (pendingToolCalls.length > 0) {
|
60
|
+
for (const toolCall of pendingToolCalls) {
|
61
|
+
const toolSpinner = (0, ora_1.default)(`Executing ${toolCall.name}...`).start();
|
62
|
+
try {
|
63
|
+
const result = await toolExecutor.executeTool(toolCall.name, toolCall.input);
|
64
|
+
toolSpinner.succeed(`${toolCall.name} completed`);
|
65
|
+
conversation.addToolResult(toolCall.toolUseId, result);
|
66
|
+
if (result) {
|
67
|
+
console.log(chalk_1.default.gray(`\nTool Result (${toolCall.name}):`));
|
68
|
+
console.log((0, marked_1.marked)(typeof result === 'string' ? result : JSON.stringify(result, null, 2)));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
catch (error) {
|
72
|
+
toolSpinner.fail(`${toolCall.name} failed`);
|
73
|
+
console.error(chalk_1.default.red(`Error: ${error}`));
|
74
|
+
conversation.addToolResult(toolCall.toolUseId, `Error: ${error}`);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
const followUpSpinner = (0, ora_1.default)('Processing tool results...').start();
|
78
|
+
const followUpMessages = conversation.getMessages();
|
79
|
+
const followUpStream = client.streamMessage(followUpMessages, tools, systemPrompt);
|
80
|
+
let followUpMessage = '';
|
81
|
+
for await (const chunk of followUpStream) {
|
82
|
+
if (typeof chunk === 'string') {
|
83
|
+
followUpMessage += chunk;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
followUpSpinner.stop();
|
87
|
+
if (followUpMessage) {
|
88
|
+
console.log(chalk_1.default.blue('\nAssistant:'));
|
89
|
+
console.log((0, marked_1.marked)(followUpMessage));
|
90
|
+
conversation.addMessage('assistant', followUpMessage);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
catch (error) {
|
95
|
+
spinner.stop();
|
96
|
+
console.error(chalk_1.default.red(`\nError: ${error}`));
|
97
|
+
}
|
98
|
+
console.log('');
|
99
|
+
}
|
100
|
+
}
|
101
|
+
//# sourceMappingURL=chat.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":";;;;;AAYA,8BAyGC;AArHD,kDAA0B;AAC1B,wDAAgC;AAChC,8CAAsB;AACtB,mCAAgC;AAChC,+DAA2D;AAC3D,2EAAuE;AACvE,6DAAyD;AACzD,8CAAmD;AAEnD,MAAM,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAClD,eAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAEpB,KAAK,UAAU,SAAS,CAAC,OAA2B;IACzD,MAAM,MAAM,GAAG,IAAI,8BAAa,EAAE,CAAC;IACnC,MAAM,YAAY,G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C,CAAC;oBACrC,YAAY,CAAC,UAAU,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;gBACxD,CAAC;YACH,CAAC;QAEH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,YAAY,KAAK,EAAE,CAAC,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { ConverseCommandOutput, ContentBlock, ToolUseBlock } from '@aws-sdk/client-bedrock-runtime';
|
2
|
+
export interface BedrockMessage {
|
3
|
+
role: 'user' | 'assistant';
|
4
|
+
content: string | ContentBlock[];
|
5
|
+
}
|
6
|
+
export interface BedrockTool {
|
7
|
+
name: string;
|
8
|
+
description: string;
|
9
|
+
input_schema: {
|
10
|
+
type: 'object';
|
11
|
+
properties: Record<string, any>;
|
12
|
+
required?: string[];
|
13
|
+
};
|
14
|
+
}
|
15
|
+
export declare class BedrockClient {
|
16
|
+
private client;
|
17
|
+
private modelId;
|
18
|
+
constructor();
|
19
|
+
sendMessage(messages: BedrockMessage[], tools?: BedrockTool[], systemPrompt?: string): Promise<ConverseCommandOutput>;
|
20
|
+
streamMessage(messages: BedrockMessage[], tools?: BedrockTool[], systemPrompt?: string): AsyncGenerator<string | ToolUseBlock, void, unknown>;
|
21
|
+
}
|
22
|
+
//# sourceMappingURL=bedrock-client.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bedrock-client.d.ts","sourceRoot":"","sources":["../../src/services/bedrock-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EAErB,YAAY,EAEZ,YAAY,EAGb,MAAM,iCAAiC,CAAC;AAGzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,OAAO,CAAS;;IAclB,WAAW,CACf,QAAQ,EAAE,cAAc,EAAE,EAC1B,KAAK,CAAC,EAAE,WAAW,EAAE,EACrB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,qBAAqB,CAAC;IAiC1B,aAAa,CAClB,QAAQ,EAAE,cAAc,EAAE,EAC1B,KAAK,CAAC,EAAE,WAAW,EAAE,EACrB,YAAY,CAAC,EAAE,MAAM,GACpB,cAAc,CAAC,MAAM,GAAG,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC;CAaxD"}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BedrockClient = void 0;
|
4
|
+
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
5
|
+
const config_1 = require("../utils/config");
|
6
|
+
class BedrockClient {
|
7
|
+
client;
|
8
|
+
modelId;
|
9
|
+
constructor() {
|
10
|
+
this.client = new client_bedrock_runtime_1.BedrockRuntimeClient({
|
11
|
+
region: config_1.config.AWS_REGION || 'us-east-1',
|
12
|
+
credentials: {
|
13
|
+
accessKeyId: config_1.config.AWS_ACCESS_KEY_ID,
|
14
|
+
secretAccessKey: config_1.config.AWS_SECRET_ACCESS_KEY,
|
15
|
+
sessionToken: config_1.config.AWS_SESSION_TOKEN
|
16
|
+
}
|
17
|
+
});
|
18
|
+
this.modelId = config_1.config.BEDROCK_MODEL_ID || 'anthropic.claude-3-5-sonnet-20241022-v2:0';
|
19
|
+
}
|
20
|
+
async sendMessage(messages, tools, systemPrompt) {
|
21
|
+
const formattedMessages = messages.map(msg => ({
|
22
|
+
role: msg.role,
|
23
|
+
content: typeof msg.content === 'string'
|
24
|
+
? [{ text: msg.content }]
|
25
|
+
: msg.content
|
26
|
+
}));
|
27
|
+
const input = {
|
28
|
+
modelId: this.modelId,
|
29
|
+
messages: formattedMessages,
|
30
|
+
system: systemPrompt ? [{ text: systemPrompt }] : undefined,
|
31
|
+
toolConfig: tools ? {
|
32
|
+
tools: tools.map(tool => ({
|
33
|
+
toolSpec: {
|
34
|
+
name: tool.name,
|
35
|
+
description: tool.description,
|
36
|
+
inputSchema: {
|
37
|
+
json: tool.input_schema
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}))
|
41
|
+
} : undefined,
|
42
|
+
inferenceConfig: {
|
43
|
+
maxTokens: 4096,
|
44
|
+
temperature: 0.0
|
45
|
+
}
|
46
|
+
};
|
47
|
+
const command = new client_bedrock_runtime_1.ConverseCommand(input);
|
48
|
+
return await this.client.send(command);
|
49
|
+
}
|
50
|
+
async *streamMessage(messages, tools, systemPrompt) {
|
51
|
+
const response = await this.sendMessage(messages, tools, systemPrompt);
|
52
|
+
if (response.output?.message?.content) {
|
53
|
+
for (const block of response.output.message.content) {
|
54
|
+
if ('text' in block && block.text) {
|
55
|
+
yield block.text;
|
56
|
+
}
|
57
|
+
else if ('toolUse' in block && block.toolUse) {
|
58
|
+
yield block.toolUse;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
exports.BedrockClient = BedrockClient;
|
65
|
+
//# sourceMappingURL=bedrock-client.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bedrock-client.js","sourceRoot":"","sources":["../../src/services/bedrock-client.ts"],"names":[],"mappings":";;;AAAA,4EA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AAI,EAAE,IAAI,CAAC,YAAY;yBACxB;qBACF;iBACF,CAAC,CAAC;aACJ,CAAC,CAAC,CAAC,SAAS;YACb,eAAe,EAAE;gBACf,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,GAAG;aACjB;SACF,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,wCAAe,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAA,CAAE,aAAa,CAClB,QAA0B,EAC1B,KAAqB,EACrB,YAAqB;QAErB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;QAEvE,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;YACtC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpD,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;oBAClC,MAAM,KAAK,CAAC,IAAI,CAAC;gBACnB,CAAC;qBAAM,IAAI,SAAS,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;oBAC/C,MAAM,KAAK,CAAC,OAAO,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAtED,sCAsEC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { BedrockMessage } from './bedrock-client';
|
2
|
+
import { ContentBlock } from '@aws-sdk/client-bedrock-runtime';
|
3
|
+
export declare class ConversationManager {
|
4
|
+
private messages;
|
5
|
+
addMessage(role: 'user' | 'assistant', content: string | ContentBlock[]): void;
|
6
|
+
addToolResult(toolUseId: string, result: any): void;
|
7
|
+
getMessages(): BedrockMessage[];
|
8
|
+
clear(): void;
|
9
|
+
getLastMessage(): BedrockMessage | undefined;
|
10
|
+
getMessageCount(): number;
|
11
|
+
truncateToLastN(n: number): void;
|
12
|
+
}
|
13
|
+
//# sourceMappingURL=conversation-manager.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"conversation-manager.d.ts","sourceRoot":"","sources":["../../src/services/conversation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAwB;IAExC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,EAAE;IAIvE,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;IAe5C,WAAW,IAAI,cAAc,EAAE;IAI/B,KAAK;IAIL,cAAc,IAAI,cAAc,GAAG,SAAS;IAI5C,eAAe,IAAI,MAAM;IAIzB,eAAe,CAAC,CAAC,EAAE,MAAM;CAK1B"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ConversationManager = void 0;
|
4
|
+
class ConversationManager {
|
5
|
+
messages = [];
|
6
|
+
addMessage(role, content) {
|
7
|
+
this.messages.push({ role, content });
|
8
|
+
}
|
9
|
+
addToolResult(toolUseId, result) {
|
10
|
+
const toolResultContent = {
|
11
|
+
toolResult: {
|
12
|
+
toolUseId,
|
13
|
+
content: [
|
14
|
+
{
|
15
|
+
text: typeof result === 'string' ? result : JSON.stringify(result)
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
};
|
20
|
+
this.addMessage('user', [toolResultContent]);
|
21
|
+
}
|
22
|
+
getMessages() {
|
23
|
+
return [...this.messages];
|
24
|
+
}
|
25
|
+
clear() {
|
26
|
+
this.messages = [];
|
27
|
+
}
|
28
|
+
getLastMessage() {
|
29
|
+
return this.messages[this.messages.length - 1];
|
30
|
+
}
|
31
|
+
getMessageCount() {
|
32
|
+
return this.messages.length;
|
33
|
+
}
|
34
|
+
truncateToLastN(n) {
|
35
|
+
if (this.messages.length > n) {
|
36
|
+
this.messages = this.messages.slice(-n);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
exports.ConversationManager = ConversationManager;
|
41
|
+
//# sourceMappingURL=conversation-manager.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"conversation-manager.js","sourceRoot":"","sources":["../../src/services/conversation-manager.ts"],"names":[],"mappings":";;;AAGA,MAAa,mBAAmB;IACtB,QAAQ,GAAqB,EAAE,CAAC;IAExC,UAAU,CAAC,IAA0B,EAAE,OAAgC;QACrE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,aAAa,CAAC,SAAiB,EAAE,MAAW;QAC1C,MAAM,iBAAiB,GAAiB;YACtC,UAAU,EAAE;gBACV,SAAS;gBACT,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;qBACnE;iBACF;aACF;SACK,CAAC;QAET,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,WAAW;QACT,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,eAAe,CAAC,CAAS;QACvB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF;AA3CD,kDA2CC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { BedrockTool } from './bedrock-client';
|
2
|
+
export declare class ToolExecutor {
|
3
|
+
private tools;
|
4
|
+
constructor();
|
5
|
+
private registerTools;
|
6
|
+
getAvailableTools(): BedrockTool[];
|
7
|
+
executeTool(name: string, params: any): Promise<any>;
|
8
|
+
hasTool(name: string): boolean;
|
9
|
+
getToolDescription(name: string): string | undefined;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=tool-executor.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../../src/services/tool-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAS/C,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAgC;;IAM7C,OAAO,CAAC,aAAa;IAYrB,iBAAiB,IAAI,WAAW,EAAE;IAQ5B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAc1D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGrD"}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ToolExecutor = void 0;
|
4
|
+
const file_system_1 = require("../tools/file-system");
|
5
|
+
const git_1 = require("../tools/git");
|
6
|
+
const shell_1 = require("../tools/shell");
|
7
|
+
class ToolExecutor {
|
8
|
+
tools = new Map();
|
9
|
+
constructor() {
|
10
|
+
this.registerTools();
|
11
|
+
}
|
12
|
+
registerTools() {
|
13
|
+
const allTools = [
|
14
|
+
...file_system_1.fileSystemTools,
|
15
|
+
...git_1.gitTools,
|
16
|
+
...shell_1.shellTools
|
17
|
+
];
|
18
|
+
for (const tool of allTools) {
|
19
|
+
this.tools.set(tool.name, tool);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
getAvailableTools() {
|
23
|
+
return Array.from(this.tools.values()).map(({ name, description, input_schema }) => ({
|
24
|
+
name,
|
25
|
+
description,
|
26
|
+
input_schema
|
27
|
+
}));
|
28
|
+
}
|
29
|
+
async executeTool(name, params) {
|
30
|
+
const tool = this.tools.get(name);
|
31
|
+
if (!tool) {
|
32
|
+
throw new Error(`Tool '${name}' not found`);
|
33
|
+
}
|
34
|
+
try {
|
35
|
+
return await tool.execute(params);
|
36
|
+
}
|
37
|
+
catch (error) {
|
38
|
+
throw new Error(`Tool execution failed: ${error}`);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
hasTool(name) {
|
42
|
+
return this.tools.has(name);
|
43
|
+
}
|
44
|
+
getToolDescription(name) {
|
45
|
+
return this.tools.get(name)?.description;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
exports.ToolExecutor = ToolExecutor;
|
49
|
+
//# sourceMappingURL=tool-executor.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../../src/services/tool-executor.ts"],"names":[],"mappings":";;;AACA,sDAAuD;AACvD,sCAAwC;AACxC,0CAA4C;AAM5C,MAAa,YAAY;IACf,KAAK,GAAsB,IAAI,GAAG,EAAE,CAAC;IAE7C;QACE,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,MAAM,QAAQ,GAAG;YACf,GAAG,6BAAe;YAClB,GAAG,cAA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string;
|
6
|
+
properties: {
|
7
|
+
path: {
|
8
|
+
type: string;
|
9
|
+
description: string;
|
10
|
+
};
|
11
|
+
content?: undefined;
|
12
|
+
old_content?: undefined;
|
13
|
+
new_content?: undefined;
|
14
|
+
};
|
15
|
+
required: string[];
|
16
|
+
};
|
17
|
+
execute: ({ path: filePath }: {
|
18
|
+
path: string;
|
19
|
+
}) => Promise<{
|
20
|
+
success: boolean;
|
21
|
+
content: string;
|
22
|
+
error?: undefined;
|
23
|
+
} | {
|
24
|
+
success: boolean;
|
25
|
+
error: any;
|
26
|
+
content?: undefined;
|
27
|
+
}>;
|
28
|
+
} | {
|
29
|
+
name: string;
|
30
|
+
description: string;
|
31
|
+
input_schema: {
|
32
|
+
type: string;
|
33
|
+
properties: {
|
34
|
+
path: {
|
35
|
+
type: string;
|
36
|
+
description: string;
|
37
|
+
};
|
38
|
+
content: {
|
39
|
+
type: string;
|
40
|
+
description: string;
|
41
|
+
};
|
42
|
+
old_content?: undefined;
|
43
|
+
new_content?: undefined;
|
44
|
+
};
|
45
|
+
required: string[];
|
46
|
+
};
|
47
|
+
execute: ({ path: filePath, content }: {
|
48
|
+
path: string;
|
49
|
+
content: string;
|
50
|
+
}) => Promise<{
|
51
|
+
success: boolean;
|
52
|
+
message: string;
|
53
|
+
error?: undefined;
|
54
|
+
} | {
|
55
|
+
success: boolean;
|
56
|
+
error: any;
|
57
|
+
message?: undefined;
|
58
|
+
}>;
|
59
|
+
} | {
|
60
|
+
name: string;
|
61
|
+
description: string;
|
62
|
+
input_schema: {
|
63
|
+
type: string;
|
64
|
+
properties: {
|
65
|
+
path: {
|
66
|
+
type: string;
|
67
|
+
description: string;
|
68
|
+
};
|
69
|
+
old_content: {
|
70
|
+
type: string;
|
71
|
+
description: string;
|
72
|
+
};
|
73
|
+
new_content: {
|
74
|
+
type: string;
|
75
|
+
description: string;
|
76
|
+
};
|
77
|
+
content?: undefined;
|
78
|
+
};
|
79
|
+
required: string[];
|
80
|
+
};
|
81
|
+
execute: ({ path: filePath, old_content, new_content }: {
|
82
|
+
path: string;
|
83
|
+
old_content: string;
|
84
|
+
new_content: string;
|
85
|
+
}) => Promise<{
|
86
|
+
success: boolean;
|
87
|
+
message: string;
|
88
|
+
error?: undefined;
|
89
|
+
} | {
|
90
|
+
success: boolean;
|
91
|
+
error: any;
|
92
|
+
message?: undefined;
|
93
|
+
}>;
|
94
|
+
} | {
|
95
|
+
name: string;
|
96
|
+
description: string;
|
97
|
+
input_schema: {
|
98
|
+
type: string;
|
99
|
+
properties: {
|
100
|
+
path: {
|
101
|
+
type: string;
|
102
|
+
description: string;
|
103
|
+
};
|
104
|
+
content?: undefined;
|
105
|
+
old_content?: undefined;
|
106
|
+
new_content?: undefined;
|
107
|
+
};
|
108
|
+
required: string[];
|
109
|
+
};
|
110
|
+
execute: ({ path: dirPath }: {
|
111
|
+
path: string;
|
112
|
+
}) => Promise<{
|
113
|
+
success: boolean;
|
114
|
+
items: {
|
115
|
+
name: string;
|
116
|
+
type: string;
|
117
|
+
size: number;
|
118
|
+
modified: Date;
|
119
|
+
}[];
|
120
|
+
error?: undefined;
|
121
|
+
} | {
|
122
|
+
success: boolean;
|
123
|
+
error: any;
|
124
|
+
items?: undefined;
|
125
|
+
}>;
|
126
|
+
})[];
|
127
|
+
//# sourceMappingURL=file-system.d.ts.map
|