Skip to content

Commit 2016acf

Browse files
ctePeterDaveHello
authored andcommitted
Custom tool calling (RooCodeInc#10083)
1 parent 1118178 commit 2016acf

14 files changed

Lines changed: 524 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { CustomToolContext, TaskLike } from "@roo-code/types"
2+
3+
import systemTime from "../system-time.js"
4+
5+
const mockContext: CustomToolContext = {
6+
mode: "code",
7+
task: { taskId: "test-task-id" } as unknown as TaskLike,
8+
}
9+
10+
describe("system-time tool", () => {
11+
describe("execute", () => {
12+
it("should return a formatted date/time string", async () => {
13+
const result = await systemTime.execute({}, mockContext)
14+
expect(result).toMatch(/^The current date and time is:/)
15+
expect(result).toMatch(/(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)/)
16+
expect(result).toMatch(
17+
/(January|February|March|April|May|June|July|August|September|October|November|December)/,
18+
)
19+
expect(result).toMatch(/\d{1,2}:\d{2}:\d{2}/)
20+
})
21+
})
22+
})

.roo/tools/eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { config } from "@roo-code/config-eslint/base"
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default [...config]

.roo/tools/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@roo-code/custom-tools",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"description": "Custom tools for the Roo Code project itself",
7+
"scripts": {
8+
"lint": "eslint . --ext=ts --max-warnings=0",
9+
"check-types": "tsc --noEmit",
10+
"test": "vitest run"
11+
},
12+
"devDependencies": {
13+
"@roo-code/config-eslint": "workspace:^",
14+
"@roo-code/config-typescript": "workspace:^",
15+
"@roo-code/types": "workspace:^",
16+
"vitest": "^3.2.3"
17+
}
18+
}

.roo/tools/system-time.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { parametersSchema, defineCustomTool } from "@roo-code/types"
2+
3+
export default defineCustomTool({
4+
name: "system_time",
5+
description: "Returns the current system date and time in a friendly, human-readable format.",
6+
parameters: parametersSchema.object({}),
7+
async execute() {
8+
const systemTime = new Date().toLocaleString("en-US", {
9+
weekday: "long",
10+
year: "numeric",
11+
month: "long",
12+
day: "numeric",
13+
hour: "2-digit",
14+
minute: "2-digit",
15+
second: "2-digit",
16+
timeZoneName: "short",
17+
timeZone: "America/Los_Angeles",
18+
})
19+
20+
return `The current date and time is: ${systemTime}`
21+
},
22+
})

.roo/tools/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@roo-code/config-typescript/base.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"types": ["vitest/globals"]
6+
},
7+
"include": ["*.ts", "__tests__/*.ts"],
8+
"exclude": ["node_modules"]
9+
}

.roo/tools/vitest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config"
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
environment: "node",
7+
watch: false,
8+
},
9+
})

packages/core/src/custom-tools/__tests__/__snapshots__/format-xml.spec.ts.snap

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

0 commit comments

Comments
 (0)