Skip to content

Commit 9f04f30

Browse files
Add tool configuration management and integrate with session handling
1 parent 0377ff1 commit 9f04f30

13 files changed

Lines changed: 255 additions & 33 deletions

File tree

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"imports": {
88
"@std/assert": "jsr:@std/assert@1",
99
"@db/sqlite": "jsr:@db/sqlite",
10-
"table": "jsr:@sauber/table"
10+
"table": "jsr:@sauber/table",
11+
"anthropic": "npm:@anthropic-ai/sdk"
1112
}
1213
}

deno.lock

Lines changed: 129 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/settings.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {parseFlagForHelp, getCommandHelp} from "../utils/functions.ts"
44

55
export async function handleSettings(args: string[]): Promise<void> {
66
const settingsFlags = {
7-
string: ["set-name", "add-command", "remove-command", "set-jina-key"],
7+
string: ["set-name", "add-command", "remove-command", "set-jina-key", "set-config"],
88
boolean: ["list"],
99
}
1010
const flags = parseArgs(args, settingsFlags)
@@ -15,7 +15,11 @@ export async function handleSettings(args: string[]): Promise<void> {
1515
}
1616
const settings = await loadUserSettings()
1717

18-
if (flags["set-name"]) {
18+
if (flags["set-config"]) {
19+
settings.toolConfigPath = flags["set-config"]
20+
console.log(`Tool configuration path set to: ${flags["set-config"]}`)
21+
}
22+
else if (flags["set-name"]) {
1923
settings.userName = flags["set-name"]
2024
}
2125
else if (flags["set-jina-key"]) {

src/config/constants.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {join} from "jsr:@std/path"
2-
import Anthropic from "npm:@anthropic-ai/sdk"
2+
import Anthropic from "anthropic"
33
import {homedir} from "node:os"
44
import {isJinaAvailable, loadUserSettings} from "./settings.ts"
55

66
export const EDITOR_DIR = join(homedir(), ".ComputerUseAgent", "editor_dir")
77
export const SESSIONS_DIR = join(homedir(), ".ComputerUseAgent", "sessions")
88
export const LOGS_DIR = join(homedir(), ".ComputerUseAgent", "logs")
9+
export const DEFAULT_TOOLS_CONFIG_PATH = join(homedir(), ".ComputerUseAgent", "settings.json")
910

1011
export const EDITOR_SYSTEM_PROMPT = Deno.env.get("EDITOR_SYSTEM_PROMPT") ??
1112
`You are a helpful assistant that helps users edit and work with text files.
@@ -216,11 +217,7 @@ export const JINA_TOOLS: Anthropic.Beta.BetaTool[] = [
216217
},
217218
]
218219

219-
export const ALL_TOOLS = [
220-
...MEMORY_TOOLS,
221-
...CLIPBOARD_TOOLS,
222-
...(isJinaAvailable() ? JINA_TOOLS : []),
223-
]
220+
// Remove ALL_TOOLS export and definition
224221

225222
export function getSystemContext(basePrompt: string): string {
226223
const settings = loadUserSettings()

src/config/settings.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {UserSettings} from "../types/interfaces.ts"
55
const DEFAULT_SETTINGS: UserSettings = {
66
userName: "User",
77
customCommands: [],
8-
jinaApiKey: undefined
8+
jinaApiKey: undefined,
9+
toolConfigPath: join(homedir(), ".ComputerUseAgent", "tools.json")
910
}
1011

1112
const SETTINGS_PATH = join(homedir(), ".ComputerUseAgent", "settings.json")
@@ -24,11 +25,16 @@ export function saveUserSettings(settings: UserSettings) {
2425
}
2526

2627
export function isJinaAvailable(): boolean {
27-
const settings = loadUserSettings();
28-
return Boolean(settings.jinaApiKey);
28+
const settings = loadUserSettings()
29+
return Boolean(settings.jinaApiKey)
2930
}
3031

3132
export function getJinaApiKey(): string {
32-
const settings = loadUserSettings();
33-
return settings.jinaApiKey || "";
33+
const settings = loadUserSettings()
34+
return settings.jinaApiKey || ""
35+
}
36+
37+
export function getConfigFileLocation(): string {
38+
const settings = loadUserSettings()
39+
return settings.toolConfigPath
3440
}

src/config/tool_config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {ToolConfig} from "../types/interfaces.ts"
2+
3+
export class ToolConfigManager {
4+
loadConfig(configPath: string): ToolConfig[] {
5+
try {
6+
const configText = Deno.readTextFileSync(configPath)
7+
const config = JSON.parse(configText)
8+
return Array.isArray(config) ? config : config.tools || []
9+
} catch (error) {
10+
console.warn(`Could not load config from ${configPath}: ${error}`)
11+
return []
12+
}
13+
}
14+
}

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ async function main() {
4949
const session = new BashSession(sessionId, flags["no-agi"])
5050
await session.processBashCommand(prompt)
5151
} else {
52-
// Default to hybrid mode for any other mode value
5352
const session = new HybridSession(sessionId, flags["no-agi"])
5453
await session.process(prompt)
5554
}

src/modules/hybrid/hybrid_session.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import {BaseSession} from "../../utils/session.ts"
2-
import {COMBINED_SYSTEM_PROMPT, API_CONFIG, MEMORY_TOOLS, CLIPBOARD_TOOLS, JINA_TOOLS} from "../../config/constants.ts"
2+
import {COMBINED_SYSTEM_PROMPT, API_CONFIG} from "../../config/constants.ts"
33
import {log} from "../../config/logging.ts"
44
import {ToolHandler} from "../../utils/tool_handler.ts"
5-
6-
5+
import {getConfigFileLocation} from "../../config/settings.ts"
6+
import {ToolConfigManager} from "../../config/tool_config.ts"
77

88
export class HybridSession extends BaseSession {
99
private toolHandler: ToolHandler
1010

1111
constructor(sessionId: string, noAgi = false) {
1212
super(sessionId)
13-
this.toolHandler = new ToolHandler(noAgi)
13+
const configPath = getConfigFileLocation()
14+
const toolConfig = new ToolConfigManager().loadConfig(configPath)
15+
this.toolHandler = new ToolHandler(noAgi, toolConfig)
1416
}
1517

1618
async process(prompt: string): Promise<void> {
@@ -39,9 +41,7 @@ export class HybridSession extends BaseSession {
3941
tools: [
4042
{type: "bash_20241022", name: "bash"},
4143
{type: "text_editor_20241022", name: "str_replace_editor"},
42-
...MEMORY_TOOLS,
43-
...CLIPBOARD_TOOLS,
44-
...JINA_TOOLS
44+
...this.toolHandler.getAllTools()
4545
],
4646
system: this.getSystemPrompt(`${COMBINED_SYSTEM_PROMPT}\nSystem Context: ${JSON.stringify(systemInfo)}`),
4747
betas: ["computer-use-2024-10-22"],

0 commit comments

Comments
 (0)