2026-04-05 21:09:33 -05:00
|
|
|
/**
|
|
|
|
|
* Dispatcher manager — routes requests to backend services via pub/sub.
|
|
|
|
|
*
|
2026-04-05 22:44:45 -05:00
|
|
|
* Maintains a service registry mapping service names to NATS topic pairs.
|
|
|
|
|
* Applies wire format translation on requests (client → internal) and
|
|
|
|
|
* reverse translation on responses (internal → client).
|
|
|
|
|
*
|
2026-04-05 21:09:33 -05:00
|
|
|
* Python reference: trustgraph-flow/trustgraph/gateway/dispatch/manager.py
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
import { Clock, Effect, Exit, Random, Scope, SynchronizedRef } from "effect";
|
2026-06-01 22:17:50 -05:00
|
|
|
import {
|
|
|
|
|
loadMessagingRuntimeConfig,
|
|
|
|
|
makeNatsBackend,
|
|
|
|
|
makePubSubService,
|
|
|
|
|
makeRequestResponseFactoryService,
|
|
|
|
|
messagingDeliveryError,
|
|
|
|
|
messagingLifecycleError,
|
|
|
|
|
type EffectRequestResponse,
|
|
|
|
|
type PubSubBackend,
|
|
|
|
|
type RequestResponseFactoryService,
|
|
|
|
|
} from "@trustgraph/base";
|
2026-04-05 21:09:33 -05:00
|
|
|
import type { GatewayConfig } from "../server.js";
|
2026-04-05 22:44:45 -05:00
|
|
|
import { translateRequest, translateResponse } from "./serialize.js";
|
2026-04-05 21:09:33 -05:00
|
|
|
|
|
|
|
|
export type Responder = (response: unknown, complete: boolean) => Promise<void>;
|
|
|
|
|
|
2026-04-05 22:44:45 -05:00
|
|
|
// ---------- Service registry ----------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Flow-scoped request/response services.
|
|
|
|
|
* These are resolved within a specific flow's interface definitions.
|
|
|
|
|
* Topic pattern: tg.flow.<name>-request / tg.flow.<name>-response
|
|
|
|
|
*/
|
|
|
|
|
const FLOW_SERVICES: ReadonlyMap<string, { request: string; response: string }> = new Map([
|
|
|
|
|
["agent", { request: "agent-request", response: "agent-response" }],
|
|
|
|
|
["text-completion", { request: "text-completion-request", response: "text-completion-response" }],
|
|
|
|
|
["prompt", { request: "prompt-request", response: "prompt-response" }],
|
|
|
|
|
["graph-rag", { request: "graph-rag-request", response: "graph-rag-response" }],
|
|
|
|
|
["document-rag", { request: "document-rag-request", response: "document-rag-response" }],
|
|
|
|
|
["embeddings", { request: "embeddings-request", response: "embeddings-response" }],
|
|
|
|
|
["graph-embeddings", { request: "graph-embeddings-request", response: "graph-embeddings-response" }],
|
|
|
|
|
["document-embeddings", { request: "doc-embeddings-request", response: "doc-embeddings-response" }],
|
|
|
|
|
["triples", { request: "triples-request", response: "triples-response" }],
|
2026-04-10 05:45:46 -05:00
|
|
|
["mcp-tool", { request: "mcp-tool-request", response: "mcp-tool-response" }],
|
2026-04-05 22:44:45 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Global services (not flow-scoped).
|
|
|
|
|
* These always use fixed topics regardless of which flow is active.
|
|
|
|
|
*/
|
|
|
|
|
const GLOBAL_SERVICES: ReadonlyMap<string, { request: string; response: string }> = new Map([
|
|
|
|
|
["config", { request: "config-request", response: "config-response" }],
|
|
|
|
|
["flow", { request: "flow-request", response: "flow-response" }],
|
|
|
|
|
["librarian", { request: "librarian-request", response: "librarian-response" }],
|
|
|
|
|
["knowledge", { request: "knowledge-request", response: "knowledge-response" }],
|
|
|
|
|
["collection-management", { request: "collection-management-request", response: "collection-management-response" }],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Services that support streaming responses (multiple messages per request).
|
|
|
|
|
* The completion flag is determined by checking for end-of-stream markers.
|
|
|
|
|
*/
|
|
|
|
|
const STREAMING_SERVICES = new Set([
|
|
|
|
|
"agent",
|
|
|
|
|
"text-completion",
|
|
|
|
|
"graph-rag",
|
|
|
|
|
"document-rag",
|
|
|
|
|
"triples",
|
|
|
|
|
"knowledge",
|
|
|
|
|
"librarian",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
function topicName(name: string): string {
|
|
|
|
|
return `tg.flow.${name}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- Manager ----------
|
|
|
|
|
|
2026-06-01 20:26:47 -05:00
|
|
|
export interface DispatcherManager {
|
|
|
|
|
readonly start: () => Promise<void>;
|
|
|
|
|
readonly stop: () => Promise<void>;
|
|
|
|
|
readonly dispatchGlobalService: (
|
|
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
|
|
|
|
) => Promise<unknown>;
|
|
|
|
|
readonly dispatchGlobalServiceStreaming: (
|
|
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
|
|
|
|
responder: Responder,
|
|
|
|
|
) => Promise<void>;
|
|
|
|
|
readonly dispatchFlowService: (
|
|
|
|
|
flow: string,
|
|
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
|
|
|
|
) => Promise<unknown>;
|
|
|
|
|
readonly dispatchFlowServiceStreaming: (
|
|
|
|
|
flow: string,
|
|
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
|
|
|
|
responder: Responder,
|
|
|
|
|
) => Promise<void>;
|
|
|
|
|
readonly publishToTopic: (
|
|
|
|
|
topic: string,
|
|
|
|
|
message: unknown,
|
|
|
|
|
id?: string,
|
|
|
|
|
) => Promise<void>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const dispatcherManagerFlowServiceNames = (): readonly string[] => [
|
|
|
|
|
...FLOW_SERVICES.keys(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const dispatcherManagerGlobalServiceNames = (): readonly string[] => [
|
|
|
|
|
...GLOBAL_SERVICES.keys(),
|
|
|
|
|
];
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-01 20:26:47 -05:00
|
|
|
export const dispatcherManagerIsStreamingService = (kind: string): boolean =>
|
|
|
|
|
STREAMING_SERVICES.has(kind);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-01 22:17:50 -05:00
|
|
|
export const dispatcherManagerIsCompleteResponse = (response: unknown): boolean => {
|
|
|
|
|
if (typeof response !== "object" || response === null) return true;
|
|
|
|
|
const res = response as Record<string, unknown>;
|
|
|
|
|
return (
|
|
|
|
|
res.complete === true ||
|
|
|
|
|
res.endOfStream === true ||
|
|
|
|
|
res.endOfSession === true ||
|
|
|
|
|
res.end_of_stream === true ||
|
|
|
|
|
res.end_of_session === true ||
|
|
|
|
|
res.end_of_dialog === true ||
|
|
|
|
|
res.eos === true ||
|
|
|
|
|
// error responses are always final
|
|
|
|
|
(res.error !== undefined && res.error !== null)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type RequestorMap = Map<string, EffectRequestResponse<unknown, unknown>>;
|
|
|
|
|
|
|
|
|
|
interface DispatcherRuntime {
|
|
|
|
|
readonly scope: Scope.Closeable;
|
|
|
|
|
readonly requestors: SynchronizedRef.SynchronizedRef<RequestorMap>;
|
|
|
|
|
readonly factory: RequestResponseFactoryService;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-01 20:26:47 -05:00
|
|
|
export function makeDispatcherManager(config: GatewayConfig): DispatcherManager {
|
2026-06-01 22:17:50 -05:00
|
|
|
const pubsub: PubSubBackend = config.pubsub ?? makeNatsBackend(config.natsUrl ?? "nats://localhost:4222");
|
|
|
|
|
let runtime: DispatcherRuntime | null = null;
|
2026-06-01 20:26:47 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const start = (): Promise<void> => {
|
|
|
|
|
if (runtime !== null) return Promise.resolve();
|
2026-06-01 22:17:50 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
return Effect.runPromise(
|
2026-06-01 22:17:50 -05:00
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const scope = yield* Scope.make();
|
2026-06-01 23:19:54 -05:00
|
|
|
const nextRuntime = yield* Effect.gen(function* () {
|
2026-06-01 22:17:50 -05:00
|
|
|
const messagingConfig = yield* loadMessagingRuntimeConfig();
|
|
|
|
|
const requestors = yield* SynchronizedRef.make<RequestorMap>(new Map());
|
|
|
|
|
return {
|
|
|
|
|
scope,
|
|
|
|
|
requestors,
|
|
|
|
|
factory: makeRequestResponseFactoryService(makePubSubService(pubsub), messagingConfig),
|
|
|
|
|
} satisfies DispatcherRuntime;
|
|
|
|
|
}).pipe(
|
|
|
|
|
Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause))),
|
|
|
|
|
);
|
2026-06-01 23:19:54 -05:00
|
|
|
runtime = nextRuntime;
|
2026-06-01 22:17:50 -05:00
|
|
|
}),
|
|
|
|
|
);
|
2026-06-01 20:26:47 -05:00
|
|
|
};
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const stop = (): Promise<void> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const current = runtime;
|
|
|
|
|
runtime = null;
|
2026-06-01 22:17:50 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
if (current !== null) {
|
|
|
|
|
yield* Scope.close(current.scope, Exit.void);
|
|
|
|
|
}
|
2026-06-01 22:17:50 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
yield* Effect.tryPromise({
|
|
|
|
|
try: () => pubsub.close(),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "close-pubsub", cause),
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-04-05 22:44:45 -05:00
|
|
|
// ---------- Internal helpers ----------
|
|
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const ensureRuntime = (): Promise<DispatcherRuntime> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
if (runtime === null) {
|
|
|
|
|
yield* Effect.tryPromise({
|
|
|
|
|
try: () => start(),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "start", cause),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (runtime === null) {
|
|
|
|
|
return yield* messagingLifecycleError("gateway-dispatcher", "start", "Dispatcher manager failed to start");
|
|
|
|
|
}
|
|
|
|
|
return runtime;
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-06-01 22:17:50 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const getRequestor = (
|
2026-04-05 21:09:33 -05:00
|
|
|
requestTopic: string,
|
|
|
|
|
responseTopic: string,
|
|
|
|
|
key: string,
|
2026-06-01 23:19:54 -05:00
|
|
|
): Promise<EffectRequestResponse<unknown, unknown>> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const current = yield* Effect.tryPromise({
|
|
|
|
|
try: () => ensureRuntime(),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "ensure-runtime", cause),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return yield* SynchronizedRef.modifyEffect(current.requestors, (requestors) => {
|
|
|
|
|
const cached = requestors.get(key);
|
|
|
|
|
if (cached !== undefined) {
|
|
|
|
|
return Effect.succeed([cached, requestors] as const);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return current.factory.make<unknown, unknown>({
|
|
|
|
|
requestTopic,
|
|
|
|
|
responseTopic,
|
|
|
|
|
subscription: `gateway-${key}`,
|
|
|
|
|
}).pipe(
|
|
|
|
|
Scope.provide(current.scope),
|
|
|
|
|
Effect.map((requestor) => {
|
|
|
|
|
const next = new Map(requestors);
|
|
|
|
|
next.set(key, requestor);
|
|
|
|
|
return [requestor, next] as const;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-06-01 22:17:50 -05:00
|
|
|
}),
|
|
|
|
|
);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-01 20:26:47 -05:00
|
|
|
const resolveGlobalTopics = (
|
2026-04-05 21:09:33 -05:00
|
|
|
kind: string,
|
2026-06-01 20:26:47 -05:00
|
|
|
): { requestTopic: string; responseTopic: string } => {
|
2026-04-05 22:44:45 -05:00
|
|
|
const entry = GLOBAL_SERVICES.get(kind);
|
2026-05-12 08:06:58 -05:00
|
|
|
if (entry !== undefined) {
|
2026-04-05 22:44:45 -05:00
|
|
|
return {
|
|
|
|
|
requestTopic: topicName(entry.request),
|
|
|
|
|
responseTopic: topicName(entry.response),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// Fallback: derive from kind name directly
|
|
|
|
|
return {
|
|
|
|
|
requestTopic: topicName(`${kind}-request`),
|
|
|
|
|
responseTopic: topicName(`${kind}-response`),
|
|
|
|
|
};
|
2026-06-01 20:26:47 -05:00
|
|
|
};
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-01 20:26:47 -05:00
|
|
|
const resolveFlowTopics = (
|
2026-04-05 22:44:45 -05:00
|
|
|
kind: string,
|
2026-06-01 20:26:47 -05:00
|
|
|
): { requestTopic: string; responseTopic: string } => {
|
2026-04-05 22:44:45 -05:00
|
|
|
const entry = FLOW_SERVICES.get(kind);
|
2026-05-12 08:06:58 -05:00
|
|
|
if (entry !== undefined) {
|
2026-04-05 22:44:45 -05:00
|
|
|
return {
|
|
|
|
|
requestTopic: topicName(entry.request),
|
|
|
|
|
responseTopic: topicName(entry.response),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// Fallback: derive from kind name directly
|
|
|
|
|
return {
|
|
|
|
|
requestTopic: topicName(`${kind}-request`),
|
|
|
|
|
responseTopic: topicName(`${kind}-response`),
|
|
|
|
|
};
|
2026-06-01 20:26:47 -05:00
|
|
|
};
|
2026-04-05 22:44:45 -05:00
|
|
|
|
|
|
|
|
// ---------- Global service dispatch ----------
|
|
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const dispatchGlobalService = (
|
2026-04-05 21:09:33 -05:00
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
2026-06-01 23:19:54 -05:00
|
|
|
): Promise<unknown> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const { requestTopic, responseTopic } = resolveGlobalTopics(kind);
|
|
|
|
|
const rr = yield* Effect.tryPromise({
|
|
|
|
|
try: () => getRequestor(requestTopic, responseTopic, `global:${kind}`),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "get-requestor", cause),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const translated = translateRequest(kind, request);
|
|
|
|
|
const response = yield* rr.request(translated);
|
|
|
|
|
return translateResponse(kind, response);
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const dispatchGlobalServiceStreaming = (
|
2026-04-05 21:09:33 -05:00
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
|
|
|
|
responder: Responder,
|
2026-06-01 23:19:54 -05:00
|
|
|
): Promise<void> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const { requestTopic, responseTopic } = resolveGlobalTopics(kind);
|
|
|
|
|
const rr = yield* Effect.tryPromise({
|
|
|
|
|
try: () => getRequestor(requestTopic, responseTopic, `global:${kind}`),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "get-requestor", cause),
|
|
|
|
|
});
|
|
|
|
|
const translated = translateRequest(kind, request);
|
|
|
|
|
|
|
|
|
|
yield* rr.request(translated, {
|
|
|
|
|
recipient: (response) => {
|
|
|
|
|
const translatedRes = translateResponse(kind, response);
|
|
|
|
|
const complete = dispatcherManagerIsCompleteResponse(translatedRes);
|
|
|
|
|
return Effect.tryPromise({
|
|
|
|
|
try: () => responder(translatedRes, complete).then(() => complete),
|
|
|
|
|
catch: (error) => messagingDeliveryError(responseTopic, "stream-responder", error),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-06-01 22:17:50 -05:00
|
|
|
}),
|
|
|
|
|
);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-04-05 22:44:45 -05:00
|
|
|
// ---------- Flow-scoped service dispatch ----------
|
|
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const dispatchFlowService = (
|
2026-04-05 22:44:45 -05:00
|
|
|
flow: string,
|
|
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
2026-06-01 23:19:54 -05:00
|
|
|
): Promise<unknown> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const { requestTopic, responseTopic } = resolveFlowTopics(kind);
|
|
|
|
|
const rr = yield* Effect.tryPromise({
|
|
|
|
|
try: () => getRequestor(
|
|
|
|
|
requestTopic,
|
|
|
|
|
responseTopic,
|
|
|
|
|
`flow:${flow}:${kind}`,
|
|
|
|
|
),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "get-requestor", cause),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const translated = translateRequest(kind, request);
|
|
|
|
|
const response = yield* rr.request(translated);
|
|
|
|
|
return translateResponse(kind, response);
|
|
|
|
|
}),
|
2026-04-05 22:44:45 -05:00
|
|
|
);
|
|
|
|
|
|
2026-06-01 23:19:54 -05:00
|
|
|
const dispatchFlowServiceStreaming = (
|
2026-04-05 21:09:33 -05:00
|
|
|
flow: string,
|
|
|
|
|
kind: string,
|
|
|
|
|
request: Record<string, unknown>,
|
|
|
|
|
responder: Responder,
|
2026-06-01 23:19:54 -05:00
|
|
|
): Promise<void> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const { requestTopic, responseTopic } = resolveFlowTopics(kind);
|
|
|
|
|
const rr = yield* Effect.tryPromise({
|
|
|
|
|
try: () => getRequestor(
|
|
|
|
|
requestTopic,
|
|
|
|
|
responseTopic,
|
|
|
|
|
`flow:${flow}:${kind}`,
|
|
|
|
|
),
|
|
|
|
|
catch: (cause) => messagingLifecycleError("gateway-dispatcher", "get-requestor", cause),
|
|
|
|
|
});
|
|
|
|
|
const translated = translateRequest(kind, request);
|
|
|
|
|
|
|
|
|
|
yield* rr.request(translated, {
|
|
|
|
|
recipient: (response) => {
|
|
|
|
|
const translatedRes = translateResponse(kind, response);
|
|
|
|
|
const complete = dispatcherManagerIsCompleteResponse(translatedRes);
|
|
|
|
|
return Effect.tryPromise({
|
|
|
|
|
try: () => responder(translatedRes, complete).then(() => complete),
|
|
|
|
|
catch: (error) => messagingDeliveryError(responseTopic, "stream-responder", error),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-06-01 22:17:50 -05:00
|
|
|
}),
|
|
|
|
|
);
|
2026-04-05 22:44:45 -05:00
|
|
|
|
2026-04-06 23:47:43 -05:00
|
|
|
// ---------- Fire-and-forget publish ----------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Publish a single message to an arbitrary topic (no request/response).
|
|
|
|
|
* Used for injecting documents into the processing pipeline.
|
|
|
|
|
*/
|
2026-06-01 23:19:54 -05:00
|
|
|
const publishToTopic = (topic: string, message: unknown, id?: string): Promise<void> =>
|
|
|
|
|
Effect.runPromise(
|
|
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const producer = yield* Effect.tryPromise({
|
|
|
|
|
try: () => pubsub.createProducer<unknown>({ topic }),
|
|
|
|
|
catch: (cause) => messagingDeliveryError(topic, "create-producer", cause),
|
|
|
|
|
});
|
|
|
|
|
const timestamp = yield* Clock.currentTimeMillis;
|
|
|
|
|
const suffix = yield* Random.nextIntBetween(0, 36 ** 6, { halfOpen: true });
|
|
|
|
|
const messageId = id ?? `pub-${timestamp}-${suffix.toString(36).padStart(6, "0")}`;
|
|
|
|
|
|
|
|
|
|
yield* Effect.tryPromise({
|
|
|
|
|
try: () => producer.send(message, { id: messageId }),
|
|
|
|
|
catch: (cause) => messagingDeliveryError(topic, "send", cause),
|
|
|
|
|
});
|
|
|
|
|
yield* Effect.tryPromise({
|
|
|
|
|
try: () => producer.close(),
|
|
|
|
|
catch: (cause) => messagingDeliveryError(topic, "close-producer", cause),
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-06-01 20:26:47 -05:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
start,
|
|
|
|
|
stop,
|
|
|
|
|
dispatchGlobalService,
|
|
|
|
|
dispatchGlobalServiceStreaming,
|
|
|
|
|
dispatchFlowService,
|
|
|
|
|
dispatchFlowServiceStreaming,
|
|
|
|
|
publishToTopic,
|
|
|
|
|
};
|
2026-04-05 21:09:33 -05:00
|
|
|
}
|