UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

62 lines (61 loc) 2.28 kB
//#region src/plugin-sdk/inbound-envelope.ts /** Create an envelope formatter bound to one resolved route and session store. */ function createInboundEnvelopeBuilder(params) { const storePath = params.resolveStorePath(params.sessionStore, { agentId: params.route.agentId }); const envelopeOptions = params.resolveEnvelopeFormatOptions(params.cfg); return (input) => { const previousTimestamp = params.readSessionUpdatedAt({ storePath, sessionKey: params.route.sessionKey }); return { storePath, body: params.formatAgentEnvelope({ channel: input.channel, from: input.from, timestamp: input.timestamp, previousTimestamp, envelope: envelopeOptions, body: input.body }) }; }; } /** Resolve a route first, then return both the route and a formatter for future inbound messages. */ function resolveInboundRouteEnvelopeBuilder(params) { const route = params.resolveAgentRoute({ cfg: params.cfg, channel: params.channel, accountId: params.accountId, peer: params.peer }); return { route, buildEnvelope: createInboundEnvelopeBuilder({ cfg: params.cfg, route, sessionStore: params.sessionStore, resolveStorePath: params.resolveStorePath, readSessionUpdatedAt: params.readSessionUpdatedAt, resolveEnvelopeFormatOptions: params.resolveEnvelopeFormatOptions, formatAgentEnvelope: params.formatAgentEnvelope }) }; } /** Runtime-driven variant of inbound envelope resolution for plugins that already expose grouped helpers. */ function resolveInboundRouteEnvelopeBuilderWithRuntime(params) { return resolveInboundRouteEnvelopeBuilder({ cfg: params.cfg, channel: params.channel, accountId: params.accountId, peer: params.peer, resolveAgentRoute: (routeParams) => params.runtime.routing.resolveAgentRoute(routeParams), sessionStore: params.sessionStore, resolveStorePath: params.runtime.session.resolveStorePath, readSessionUpdatedAt: params.runtime.session.readSessionUpdatedAt, resolveEnvelopeFormatOptions: params.runtime.reply.resolveEnvelopeFormatOptions, formatAgentEnvelope: params.runtime.reply.formatAgentEnvelope }); } //#endregion export { resolveInboundRouteEnvelopeBuilder as n, resolveInboundRouteEnvelopeBuilderWithRuntime as r, createInboundEnvelopeBuilder as t };