Initial package implementation: operations registry, call protocol, and adapters
Extracted from alkhub_ts packages/core/operations/ and packages/core/mcp/. - Runtime-agnostic (injected fs/env deps, no Deno globals) - Direct @logtape/logtape import instead of logger wrapper - PendingRequestMap with pubsub-wired call protocol - Peer-dep isolation for MCP adapter (sub-path export) - Schema const naming convention (XSchema + X type alias) - 68 tests passing, build + lint + test all green
This commit is contained in:
28
src/subscribe.ts
Normal file
28
src/subscribe.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { IOperationDefinition, OperationContext } from "./types.js";
|
||||
import { OperationRegistry } from "./registry.js";
|
||||
|
||||
export async function* subscribe(
|
||||
registry: OperationRegistry,
|
||||
operationId: string,
|
||||
input: unknown,
|
||||
context: OperationContext,
|
||||
): AsyncGenerator<unknown, void, unknown> {
|
||||
const operation = registry.get(operationId);
|
||||
|
||||
if (!operation) {
|
||||
throw new Error(`Operation not found: ${operationId}`);
|
||||
}
|
||||
|
||||
const handler = operation.handler;
|
||||
const generator = handler(input, context) as AsyncGenerator<unknown, void, unknown>;
|
||||
|
||||
try {
|
||||
for await (const value of generator) {
|
||||
yield value;
|
||||
}
|
||||
} finally {
|
||||
if (generator.return) {
|
||||
await generator.return(undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user