Files
Momento/memento-note/lib/ai/tools/registry.ts
Antigravity 1fcea6ed7d
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 7s
feat: brainstorm sessions, PDF document Q&A, embedding fixes, and UI improvements
- Add brainstorm feature with collaborative canvas, AI idea generation, live cursors, playback, and export
- Add PDF upload/extraction/ingestion pipeline with pgvector document search (RAG)
- Add document Q&A overlay with streaming chat and PDF preview
- Add note attachments UI with status polling, grid layout, and auto-scroll
- Add task extraction AI tool and agent executor improvements
- Fix NoteEmbedding missing updatedAt column, re-index 66 notes with 1536-dim embeddings
- Fix brainstorm 'Create Note' button: add success toast and redirect to created note
- Fix memory echo notification infinite polling
- Fix chat route to always include document_search tool
- Add brainstorm i18n keys across all 14 locales
- Add socket server for real-time brainstorm collaboration
- Add hierarchical notebook selector and organize notebook dialog improvements
- Add sidebar brainstorm section with session management
- Update prisma schema with brainstorm tables, attachments, and document chunks
2026-05-14 17:43:21 +00:00

84 lines
2.3 KiB
TypeScript

/**
* Tool Registry
* Central registry for all agent tools.
* Tools self-register on import via side-effect in index.ts.
*/
import { tool } from 'ai'
import { z } from 'zod'
export interface ToolContext {
userId: string
agentId?: string
actionId?: string
conversationId?: string
notebookId?: string
webSearch?: boolean
config: Record<string, string>
}
export interface RegisteredTool {
name: string
description: string
buildTool: (ctx: ToolContext) => any // Returns an AI SDK tool() synchronously
isInternal: boolean // true = no API key needed
}
class ToolRegistry {
private tools: Map<string, RegisteredTool> = new Map()
register(tool: RegisteredTool): void {
this.tools.set(tool.name, tool)
}
get(name: string): RegisteredTool | undefined {
return this.tools.get(name)
}
buildToolsForAgent(toolNames: string[], ctx: ToolContext): Record<string, any> {
const built: Record<string, any> = {}
for (const name of toolNames) {
const registered = this.tools.get(name)
if (registered) {
built[name] = registered.buildTool(ctx)
}
}
return built
}
/**
* Build tools for the chat endpoint.
* Includes internal tools (note_search, note_read) and web tools when configured.
* When webOnly is true, only web tools are included (no note access).
*/
buildToolsForChat(ctx: ToolContext & { webOnly?: boolean }): Record<string, any> {
const toolNames: string[] = ctx.webOnly ? [] : ['note_search', 'note_read', 'document_search', 'task_extract']
// Add web tools only when user toggled web search AND config is present
if (ctx.webSearch) {
const hasWebSearch = ctx.config.WEB_SEARCH_PROVIDER || ctx.config.BRAVE_SEARCH_API_KEY || ctx.config.SEARXNG_URL
if (hasWebSearch) {
toolNames.push('web_search')
}
const hasWebScrape = ctx.config.JINA_API_KEY
if (hasWebScrape) {
toolNames.push('web_scrape')
}
}
return this.buildToolsForAgent(toolNames, ctx)
}
getAvailableTools(): Array<{ name: string; description: string; isInternal: boolean }> {
return Array.from(this.tools.values()).map(t => ({
name: t.name,
description: t.description,
isInternal: t.isInternal,
}))
}
}
// Singleton
export const toolRegistry = new ToolRegistry()