fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma strängvärde byggs med konkatenering i stället för att matcha mönstret.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import type { AgentTool } from './types'
|
||||
|
||||
// Process-singleton registry the chat agent reads from. Extensions register
|
||||
// tools at module load (lib/init.ts → extensionRegistry.register → side-effect
|
||||
// of mcp-server/index.ts calling registerAgentTools).
|
||||
//
|
||||
// Why a singleton: same lifetime story as the event bus and extension
|
||||
// registry: there's exactly one chat loop per process, it must see the same
|
||||
// tool set on every invocation, and tests can reset via clear().
|
||||
class AgentToolRegistry {
|
||||
private tools = new Map<string, AgentTool>()
|
||||
|
||||
register(tool: AgentTool): void {
|
||||
this.tools.set(tool.name, tool)
|
||||
}
|
||||
|
||||
registerMany(tools: AgentTool[]): void {
|
||||
for (const t of tools) this.register(t)
|
||||
}
|
||||
|
||||
get(name: string): AgentTool | undefined {
|
||||
return this.tools.get(name)
|
||||
}
|
||||
|
||||
getMany(names: string[]): AgentTool[] {
|
||||
const out: AgentTool[] = []
|
||||
for (const n of names) {
|
||||
const t = this.tools.get(n)
|
||||
if (t) out.push(t)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
getAll(): AgentTool[] {
|
||||
return Array.from(this.tools.values())
|
||||
}
|
||||
|
||||
has(name: string): boolean {
|
||||
return this.tools.has(name)
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.tools.clear()
|
||||
}
|
||||
|
||||
size(): number {
|
||||
return this.tools.size
|
||||
}
|
||||
}
|
||||
|
||||
export const agentToolRegistry = new AgentToolRegistry()
|
||||
|
||||
// Public registration entry point used by extensions. Stable name kept short
|
||||
// so extension side-effect modules read clean.
|
||||
export function registerAgentTools(tools: AgentTool[]): void {
|
||||
agentToolRegistry.registerMany(tools)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { SupabaseClient } from '@supabase/supabase-js'
|
||||
|
||||
// Actor context for the tool dispatch. Mirrors the shape the MCP server's
|
||||
// ActorContext type uses (extensions/general/mcp-server/server.ts:70) so a
|
||||
// registered handler receives the same actor object regardless of which
|
||||
// caller wired it. The chat agent always passes `type: 'agent_chat'` with
|
||||
// the conversation id as `id`.
|
||||
export interface AgentActorContext {
|
||||
type: 'user' | 'api_key' | 'mcp_oauth' | 'cron' | 'agent_chat'
|
||||
id?: string
|
||||
label?: string
|
||||
}
|
||||
|
||||
// Slim, core-defined tool contract. Extensions register tools that satisfy
|
||||
// this shape via registerAgentTools(); the chat agent dispatches against it
|
||||
// without importing @/extensions/* directly (CI rule).
|
||||
//
|
||||
// The shape intentionally mirrors the MCP McpTool definition so the
|
||||
// mcp-server extension can pass its tool array through verbatim, but is
|
||||
// declared in core so a build with extensions disabled still compiles.
|
||||
export interface AgentTool {
|
||||
name: string
|
||||
description: string
|
||||
inputSchema: Record<string, unknown>
|
||||
outputSchema?: Record<string, unknown>
|
||||
// Anthropic SDK tool blocks don't carry annotation hints: these stay in
|
||||
// the registry for our own scoping/policy logic.
|
||||
annotations?: {
|
||||
readOnlyHint?: boolean
|
||||
destructiveHint?: boolean
|
||||
idempotentHint?: boolean
|
||||
openWorldHint?: boolean
|
||||
}
|
||||
execute: (
|
||||
args: Record<string, unknown>,
|
||||
companyId: string,
|
||||
userId: string,
|
||||
supabase: SupabaseClient,
|
||||
actor?: AgentActorContext,
|
||||
) => Promise<unknown>
|
||||
}
|
||||
|
||||
// Shape of the staged-operation envelope returned by write tools. Copied from
|
||||
// the MCP server's STAGED_OPERATION_SCHEMA (server.ts:506) so the chat loop
|
||||
// can detect a staged result without depending on the extension's symbol.
|
||||
export interface StagedOperationResult {
|
||||
staged: true
|
||||
operation_id?: string
|
||||
risk_level: 'low' | 'medium' | 'high'
|
||||
actor: { type: string; id?: string; label?: string }
|
||||
message: string
|
||||
preview: unknown
|
||||
period_status?: {
|
||||
period_id?: string | null
|
||||
status: 'open' | 'locked' | 'closed'
|
||||
lock_date?: string | null
|
||||
}
|
||||
next?: unknown
|
||||
}
|
||||
|
||||
export function isStagedOperation(value: unknown): value is StagedOperationResult {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value !== null &&
|
||||
(value as { staged?: unknown }).staged === true &&
|
||||
typeof (value as { risk_level?: unknown }).risk_level === 'string'
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user