import type { AdapterModule, InvokeInput, ModuleSetupContext, ServiceDefinition, ServiceState } from "@cyrnel/sdk";
class MyAdapter implements AdapterModule {
private state = new Map<string, ServiceState>();
private logger: ModuleSetupContext["logger"] | null = null;
async setup(context: ModuleSetupContext) {
// Configure reduction for yourself from your own config field, then scope
// a base phase. The host manages the rest of the correlation metadata.
const patterns = (context.config.redactionPatterns as string[] | undefined) ?? [];
this.logger = context.logger.redact(patterns).child({ phase: "setup" });
this.logger?.info({ event: "adapter-ready" }, "Adapter initialized");
}
async teardown() { this.state.clear(); }
async generateDefinition(input: string): Promise<ServiceDefinition> {
return {
name: "...",
summary: "Short plain-text description",
description: "...",
configSchema: { type: "object", properties: {} },
secretsSchema: { type: "object", properties: {} },
adapterDomain: { /* parsed metadata */ },
tools: [
{
id: "ping",
name: "ping",
summary: "Answers with a health status",
description: "Health check",
inputSchema: { type: "object" },
outputSchema: { type: "object" },
adapterDomain: { /* per-tool routing info */ },
},
],
};
}
async hydrateService(state: ServiceState): Promise<void> {
this.state.set(state.id, state);
}
async dehydrateService(id: string): Promise<void> {
this.state.delete(id);
}
async invoke(input: InvokeInput): Promise<unknown> {
const svc = this.state.get(input.serviceId);
if (!svc) throw new Error(`unknown service ${input.serviceId}`);
const logger = this.logger?.child({
serviceId: input.serviceId,
toolId: input.toolId,
phase: "invoke",
});
logger?.info({ event: "invoke-start", parameters: input.parameters }, "Invoking tool");
// ...use svc.adapterDomain / svc.config / svc.secrets to issue the call
return { ok: true };
}
}
const configSchema = {
type: "object",
properties: {
redactionPatterns: {
type: "array",
items: { type: "string" },
description:
"Path patterns (dot/bracket notation) merged additively with the host-enforced baseline for this module's logs.",
},
},
} as const;
const secretsSchema = { type: "null" } as const;
export default { configSchema, secretsSchema, instantiate: () => new MyAdapter() };