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

@@ -18,34 +18,34 @@ export interface EnvOptions {
export function buildEnv(options: EnvOptions): OperationEnv {
const { registry, context, allowedNamespaces, callMap } = options;
const operations = registry.list();
const specs = registry.getAllSpecs();
const namespaces: OperationEnv = {};
for (const operation of operations) {
if (allowedNamespaces && !allowedNamespaces.includes(operation.namespace)) {
for (const spec of specs) {
if (allowedNamespaces && !allowedNamespaces.includes(spec.namespace)) {
continue;
}
if (operation.type === OperationType.SUBSCRIPTION) {
if (spec.type === OperationType.SUBSCRIPTION) {
continue;
}
if (!namespaces[operation.namespace]) {
namespaces[operation.namespace] = {};
if (!namespaces[spec.namespace]) {
namespaces[spec.namespace] = {};
}
const operationId = `${operation.namespace}.${operation.name}`;
const operationId = `${spec.namespace}.${spec.name}`;
if (callMap) {
namespaces[operation.namespace][operation.name] = async (input: unknown) => {
namespaces[spec.namespace][spec.name] = async (input: unknown) => {
logger.debug(`Call protocol: ${operationId}`);
return await callMap.call(operationId, input, {
parentRequestId: context.requestId,
});
};
} else {
namespaces[operation.namespace][operation.name] = async (input: unknown) => {
namespaces[spec.namespace][spec.name] = async (input: unknown) => {
logger.debug(`Executing: ${operationId}`);
return await registry.execute(operationId, input, context);
};