feat(core): add tool namespaces (#37529)

This commit is contained in:
Aiden Cline 2026-07-17 13:14:06 -05:00 committed by GitHub
commit 4bc8faa01c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 98 additions and 39 deletions

View file

@ -150,18 +150,24 @@ export const validateName = (name: string) =>
? Effect.void
: Effect.fail(new RegistrationError({ name, message: `Invalid tool name: ${name}` }))
export const registrationEntries = (tools: Readonly<Record<string, AnyTool>>, group?: string) =>
export const registrationEntries = (tools: Readonly<Record<string, AnyTool>>, namespace?: string) =>
Object.entries(tools).map(([name, tool]) => {
const normalized = name.replace(/[^a-zA-Z0-9_-]/g, "_")
const parent = group?.replace(/[^a-zA-Z0-9_-]/g, "_")
return {
key: parent === undefined ? normalized : `${parent}_${normalized}`,
key: namespace === undefined ? normalized : `${namespace.replaceAll(".", "_")}_${normalized}`,
name: normalized,
group: parent,
namespace,
tool,
}
})
export const validateNamespace = (namespace: string) =>
namespace.split(".").every((segment) => /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(segment))
? Effect.void
: Effect.fail(
new RegistrationError({ name: namespace, message: `Invalid tool namespace: ${JSON.stringify(namespace)}` }),
)
export const withPermission = <T extends AnyTool>(
tool: T,
permission: string,
@ -288,7 +294,7 @@ export interface ToolExecuteAfterEvent {
}
export interface RegisterOptions {
readonly group?: string
readonly namespace?: string
/** Defaults to true. False exposes the tool directly to the provider. */
readonly codemode?: boolean
}