mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-15 06:40:44 +00:00
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import type { callGateway } from "../gateway/call.js";
|
|
|
|
type DeliveryRuntimeMockOptions = {
|
|
callGateway: (request: unknown) => Promise<unknown>;
|
|
loadConfig: () => OpenClawConfig;
|
|
loadSessionStore: (storePath: string) => unknown;
|
|
resolveAgentIdFromSessionKey: (sessionKey: string) => string;
|
|
resolveMainSessionKey: (cfg: unknown) => string;
|
|
resolveStorePath: (store: unknown, options: unknown) => string;
|
|
isEmbeddedPiRunActive: (sessionId: string) => boolean;
|
|
queueEmbeddedPiMessage: (sessionId: string, text: string) => boolean;
|
|
hasHooks?: () => boolean;
|
|
};
|
|
|
|
function resolveExternalBestEffortDeliveryTarget(params: {
|
|
channel?: string;
|
|
to?: string;
|
|
accountId?: string;
|
|
threadId?: string;
|
|
}) {
|
|
return {
|
|
deliver: Boolean(params.channel && params.to),
|
|
channel: params.channel,
|
|
to: params.to,
|
|
accountId: params.accountId,
|
|
threadId: params.threadId,
|
|
};
|
|
}
|
|
|
|
function resolveQueueSettings(params: {
|
|
cfg?: {
|
|
messages?: {
|
|
queue?: {
|
|
byChannel?: Record<string, string>;
|
|
};
|
|
};
|
|
};
|
|
channel?: string;
|
|
}) {
|
|
return {
|
|
mode: (params.channel && params.cfg?.messages?.queue?.byChannel?.[params.channel]) ?? "none",
|
|
};
|
|
}
|
|
|
|
export function createSubagentAnnounceDeliveryRuntimeMock(options: DeliveryRuntimeMockOptions) {
|
|
return {
|
|
callGateway: (async <T = Record<string, unknown>>(request: Parameters<typeof callGateway>[0]) =>
|
|
(await options.callGateway(request)) as T) as typeof callGateway,
|
|
loadConfig: options.loadConfig,
|
|
loadSessionStore: options.loadSessionStore,
|
|
resolveAgentIdFromSessionKey: options.resolveAgentIdFromSessionKey,
|
|
resolveMainSessionKey: options.resolveMainSessionKey,
|
|
resolveStorePath: options.resolveStorePath,
|
|
isEmbeddedPiRunActive: options.isEmbeddedPiRunActive,
|
|
queueEmbeddedPiMessage: options.queueEmbeddedPiMessage,
|
|
getGlobalHookRunner: () => ({ hasHooks: () => options.hasHooks?.() ?? false }),
|
|
createBoundDeliveryRouter: () => ({
|
|
resolveDestination: () => ({ mode: "none" }),
|
|
}),
|
|
resolveConversationIdFromTargets: () => "",
|
|
resolveExternalBestEffortDeliveryTarget,
|
|
resolveQueueSettings,
|
|
};
|
|
}
|