Separate handler from spec in OperationRegistry, update pubsub API

- Split OperationRegistry into separate specs and handlers maps
- Add registerSpec(), registerHandler(), getHandler() methods
- register() still accepts IOperationDefinition (backward compatible)
- execute() now requires both spec and handler, throws if missing
- Update @alkdev/pubsub integration for v0.1.0 API:
  - subscribe(type, id) now requires id parameter (use  for all events)
  - publish(type, id, payload) now requires 3 args
  - Events unwrapped from EventEnvelope via .payload
- Update buildCallHandler to use getSpec() + getHandler() separately
- Update subscribe.ts to use getHandler()
- Update buildEnv to use getAllSpecs() instead of list()
- Update scanner to validate against OperationSpecSchema
- Update from_mcp and from_openapi to use OperationSpec & { handler } types
- Remove OperationDefinitionSchema from public exports
- Add 7 new registry tests for handler separation
This commit is contained in:
2026-05-09 08:25:59 +00:00
parent c5979ecd63
commit 4f11f8e7a0
9 changed files with 210 additions and 91 deletions

View File

@@ -1,4 +1,4 @@
import type { IOperationDefinition } from "./types.js";
import type { OperationSpec, OperationHandler, OperationContext } from "./types.js";
import { OperationType } from "./types.js";
import { Type, type TSchema } from "@alkdev/typebox";
import { FromSchema } from "./from_schema.js";
@@ -18,7 +18,7 @@ export interface MCPClientConfig {
export interface MCPClientWrapper {
name: string;
client: unknown;
tools: IOperationDefinition[];
tools: Array<OperationSpec & { handler: OperationHandler }>;
}
export async function createMCPClient(
@@ -54,7 +54,7 @@ export async function createMCPClient(
logger.info(`Connected to MCP server: ${name}`);
const toolsResult = await client.listTools();
const operations: IOperationDefinition[] = toolsResult.tools.map((tool: { name: string; description?: string; inputSchema: unknown }) => {
const operations: Array<OperationSpec & { handler: OperationHandler }> = toolsResult.tools.map((tool: { name: string; description?: string; inputSchema: unknown }) => {
return {
name: tool.name,
namespace: name,
@@ -78,7 +78,7 @@ export async function createMCPClient(
return result.content;
},
} satisfies IOperationDefinition;
} satisfies OperationSpec & { handler: OperationHandler };
});
return {
@@ -126,8 +126,8 @@ export class MCPClientLoader {
return Array.from(this.clients.values());
}
getAllOperations(): IOperationDefinition[] {
const allOps: IOperationDefinition[] = [];
getAllOperations(): Array<OperationSpec & { handler: OperationHandler }> {
const allOps: Array<OperationSpec & { handler: OperationHandler }> = [];
for (const wrapper of this.clients.values()) {
for (const op of wrapper.tools) {
allOps.push(op);