feat(core): add tool namespaces (#37529)
This commit is contained in:
parent
5d5b33f195
commit
4bc8faa01c
10 changed files with 98 additions and 39 deletions
|
|
@ -268,6 +268,7 @@ describe("MCP errors", () => {
|
|||
})
|
||||
|
||||
test("MCP tool names match V1 sanitization", () => {
|
||||
expect(McpTool.namespace("context 7")).toBe("context_7")
|
||||
expect(McpTool.name("context 7", "resolve.library/id")).toBe("context_7_resolve_library_id")
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ describe("PluginV2", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("groups tool names and routes codemode registrations through execute", () =>
|
||||
it.effect("namespaces tool names and routes codemode registrations through execute", () =>
|
||||
Effect.gen(function* () {
|
||||
const plugins = yield* PluginV2.Service
|
||||
const registry = yield* ToolRegistry.Service
|
||||
|
|
@ -291,8 +291,8 @@ describe("PluginV2", () => {
|
|||
ctx.tool
|
||||
.transform((draft) => {
|
||||
draft.add("plain", tool("Plain"), { codemode: false })
|
||||
draft.add("look/up", tool("Lookup"), { group: "context 7", codemode: false })
|
||||
draft.add("search", tool("Search"), { group: "context 7" })
|
||||
draft.add("look/up", tool("Lookup"), { namespace: "context7", codemode: false })
|
||||
draft.add("search", tool("Search"), { namespace: "context7" })
|
||||
})
|
||||
.pipe(Effect.orDie),
|
||||
})
|
||||
|
|
@ -301,7 +301,7 @@ describe("PluginV2", () => {
|
|||
|
||||
expect((yield* registry.materialize()).definitions.map((tool) => tool.name)).toEqual([
|
||||
"plain",
|
||||
"context_7_look_up",
|
||||
"context7_look_up",
|
||||
"execute",
|
||||
])
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -84,6 +84,17 @@ const constant = (text: string) =>
|
|||
})
|
||||
|
||||
describe("ToolRegistry", () => {
|
||||
it.effect("rejects invalid dotted namespaces", () =>
|
||||
Effect.gen(function* () {
|
||||
const service = yield* ToolRegistry.Service
|
||||
const error = yield* service.register({ echo: make() }, { namespace: "slack..admin" }).pipe(Effect.flip)
|
||||
|
||||
expect(error).toBeInstanceOf(Tool.RegistrationError)
|
||||
expect(error.message).toBe('Invalid tool namespace: "slack..admin"')
|
||||
expect((yield* service.materialize()).definitions).toEqual([])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("filters disabled tools with edit aliases and ordered wildcard precedence", () =>
|
||||
Effect.gen(function* () {
|
||||
const service = yield* ToolRegistry.Service
|
||||
|
|
|
|||
|
|
@ -46,3 +46,50 @@ test("execute preserves successful results with visible unhandled rejections", a
|
|||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("execute supports callable namespace tools", async () => {
|
||||
const callable = Tool.make({
|
||||
description: "Administer Slack",
|
||||
input: Schema.Struct({}),
|
||||
output: Schema.String,
|
||||
execute: () => Effect.succeed("admin"),
|
||||
})
|
||||
const child = Tool.make({
|
||||
description: "Create a Slack resource",
|
||||
input: Schema.Struct({}),
|
||||
output: Schema.String,
|
||||
execute: () => Effect.succeed("created"),
|
||||
})
|
||||
const execute = ExecuteTool.create(
|
||||
new Map([
|
||||
["slack_admin", { tool: callable, name: "admin", namespace: "slack" }],
|
||||
["slack_admin_create", { tool: child, name: "create", namespace: "slack.admin" }],
|
||||
]),
|
||||
)
|
||||
const result = await Effect.runPromise(
|
||||
Tool.settle(
|
||||
execute,
|
||||
{
|
||||
type: "tool-call",
|
||||
id: "call_execute",
|
||||
name: "execute",
|
||||
input: { code: "return [await tools.slack.admin({}), await tools.slack.admin.create({})]" },
|
||||
},
|
||||
{
|
||||
sessionID: Session.ID.make("ses_execute"),
|
||||
agent: Agent.ID.make("build"),
|
||||
messageID: SessionMessage.ID.make("msg_execute"),
|
||||
callID: "call_execute",
|
||||
progress: () => Effect.void,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
expect(result.structured).toEqual({
|
||||
toolCalls: [
|
||||
{ tool: "slack.admin", status: "completed" },
|
||||
{ tool: "slack.admin.create", status: "completed" },
|
||||
],
|
||||
})
|
||||
expect(result.content).toEqual([{ type: "text", text: '[\n "admin",\n "created"\n]' }])
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue