refactor: move inbound config
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() },
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user