refactor: move inbound config

This commit is contained in:
Peter Steinberger
2025-12-24 00:22:52 +00:00
parent 5e07400cd1
commit 93af424ce5
34 changed files with 283 additions and 243 deletions

View File

@@ -46,7 +46,7 @@ async function withTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
function mockConfig(
home: string,
storePath: string,
inboundOverrides?: Partial<NonNullable<ClawdisConfig["inbound"]>>,
routingOverrides?: Partial<NonNullable<ClawdisConfig["routing"]>>,
) {
configSpy.mockReturnValue({
agent: {
@@ -54,10 +54,8 @@ function mockConfig(
model: "claude-opus-4-5",
workspace: path.join(home, "clawd"),
},
inbound: {
session: { store: storePath, mainKey: "main" },
...inboundOverrides,
},
session: { store: storePath, mainKey: "main" },
routing: routingOverrides ? { ...routingOverrides } : undefined,
});
}

View File

@@ -68,7 +68,7 @@ function resolveSession(opts: {
to?: string;
sessionId?: string;
}): SessionResolution {
const sessionCfg = opts.cfg.inbound?.session;
const sessionCfg = opts.cfg.session;
const scope = sessionCfg?.scope ?? "per-sender";
const mainKey = sessionCfg?.mainKey ?? "main";
const idleMinutes = Math.max(
@@ -150,7 +150,7 @@ export async function agentCommand(
});
const workspaceDir = workspace.dir;
const allowFrom = (cfg.inbound?.allowFrom ?? [])
const allowFrom = (cfg.routing?.allowFrom ?? [])
.map((val) => normalizeE164(val))
.filter((val) => val.length > 1);
@@ -421,7 +421,7 @@ export async function agentCommand(
if (deliver) {
if (deliveryProvider === "whatsapp" && !whatsappTarget) {
const err = new Error(
"Delivering to WhatsApp requires --to <E.164> or inbound.allowFrom[0]",
"Delivering to WhatsApp requires --to <E.164> or routing.allowFrom[0]",
);
if (!bestEffortDeliver) throw err;
logDeliveryError(err);

View File

@@ -32,7 +32,7 @@ describe("getHealthSnapshot", () => {
});
it("skips telegram probe when not configured", async () => {
testConfig = { inbound: { reply: { session: { store: "/tmp/x" } } } };
testConfig = { session: { store: "/tmp/x" } };
testStore = {
global: { updatedAt: Date.now() },
unknown: { updatedAt: Date.now() },

View File

@@ -55,7 +55,7 @@ export async function getHealthSnapshot(
const linked = await webAuthExists();
const authAgeMs = getWebAuthAgeMs();
const heartbeatSeconds = resolveHeartbeatSeconds(cfg, undefined);
const storePath = resolveStorePath(cfg.inbound?.session?.store);
const storePath = resolveStorePath(cfg.session?.store);
const store = loadSessionStore(storePath);
const sessions = Object.entries(store)
.filter(([key]) => key !== "global" && key !== "unknown")

View File

@@ -156,7 +156,7 @@ export async function sessionsCommand(
lookupContextTokens(cfg.agent?.model) ??
DEFAULT_CONTEXT_TOKENS;
const configModel = cfg.agent?.model ?? DEFAULT_MODEL;
const storePath = resolveStorePath(opts.store ?? cfg.inbound?.session?.store);
const storePath = resolveStorePath(opts.store ?? cfg.session?.store);
const store = loadSessionStore(storePath);
let activeMinutes: number | undefined;

View File

@@ -45,7 +45,6 @@ export async function setupCommand(
const existingRaw = await readConfigFileRaw();
const cfg = existingRaw.parsed;
const inbound = cfg.inbound ?? {};
const agent = cfg.agent ?? {};
const workspace =

View File

@@ -32,7 +32,7 @@ vi.mock("../web/session.js", () => ({
logWebSelfId: mocks.logWebSelfId,
}));
vi.mock("../config/config.js", () => ({
loadConfig: () => ({ inbound: { reply: { session: {} } } }),
loadConfig: () => ({ session: {} }),
}));
import { statusCommand } from "./status.js";

View File

@@ -66,7 +66,7 @@ export async function getStatusSummary(): Promise<StatusSummary> {
lookupContextTokens(configModel) ??
DEFAULT_CONTEXT_TOKENS;
const storePath = resolveStorePath(cfg.inbound?.session?.store);
const storePath = resolveStorePath(cfg.session?.store);
const store = loadSessionStore(storePath);
const now = Date.now();
const sessions = Object.entries(store)