|
@@ -39,7 +39,7 @@ type CollectedFiles = {
|
|
|
interface Registration {
|
|
interface Registration {
|
|
|
readonly tool: AnyTool
|
|
readonly tool: AnyTool
|
|
|
readonly name: string
|
|
readonly name: string
|
|
|
- readonly group?: string
|
|
|
|
|
|
|
+ readonly namespace?: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const create = (registrations: ReadonlyMap<string, Registration>) => {
|
|
export const create = (registrations: ReadonlyMap<string, Registration>) => {
|
|
@@ -47,7 +47,7 @@ export const create = (registrations: ReadonlyMap<string, Registration>) => {
|
|
|
invoke: (name: string, registration: Registration, input: unknown) => Effect.Effect<unknown, unknown>,
|
|
invoke: (name: string, registration: Registration, input: unknown) => Effect.Effect<unknown, unknown>,
|
|
|
hooks?: CodeMode.ToolCallHooks,
|
|
hooks?: CodeMode.ToolCallHooks,
|
|
|
) => {
|
|
) => {
|
|
|
- const tools: Record<string, Tool.Definition<never> | Record<string, Tool.Definition<never>>> = {}
|
|
|
|
|
|
|
+ const tools: Record<string, Tool.Definition<never>> = {}
|
|
|
for (const [name, registration] of registrations) {
|
|
for (const [name, registration] of registrations) {
|
|
|
const child = definition(name, registration.tool)
|
|
const child = definition(name, registration.tool)
|
|
|
const value = Tool.make({
|
|
const value = Tool.make({
|
|
@@ -56,24 +56,8 @@ export const create = (registrations: ReadonlyMap<string, Registration>) => {
|
|
|
output: child.outputSchema,
|
|
output: child.outputSchema,
|
|
|
run: (input) => invoke(name, registration, input),
|
|
run: (input) => invoke(name, registration, input),
|
|
|
})
|
|
})
|
|
|
- if (registration.group === undefined) {
|
|
|
|
|
- const path = registration.name
|
|
|
|
|
- if (Object.hasOwn(tools, path)) throw new TypeError(`CodeMode tool namespace conflict: ${path}`)
|
|
|
|
|
- tools[path] = value
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- const path = registration.name
|
|
|
|
|
- const namespace = registration.group
|
|
|
|
|
- const group = tools[namespace]
|
|
|
|
|
- if (group && Tool.isDefinition(group)) throw new TypeError(`CodeMode tool namespace conflict: ${namespace}`)
|
|
|
|
|
- if (group) {
|
|
|
|
|
- if (Object.hasOwn(group, path)) throw new TypeError(`CodeMode tool namespace conflict: ${namespace}.${path}`)
|
|
|
|
|
- group[path] = value
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- const entries: Record<string, Tool.Definition<never>> = {}
|
|
|
|
|
- entries[path] = value
|
|
|
|
|
- tools[namespace] = entries
|
|
|
|
|
|
|
+ const path = registration.namespace === undefined ? registration.name : `${registration.namespace}.${registration.name}`
|
|
|
|
|
+ tools[path] = value
|
|
|
}
|
|
}
|
|
|
return CodeMode.make<typeof tools>({ tools, ...hooks })
|
|
return CodeMode.make<typeof tools>({ tools, ...hooks })
|
|
|
}
|
|
}
|