refactor: move inbound config
This commit is contained in:
@@ -106,10 +106,10 @@ describe("directive parsing", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: path.join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: { store: path.join(home, "sessions.json") },
|
||||
},
|
||||
session: { store: path.join(home, "sessions.json") },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -134,9 +134,7 @@ describe("directive parsing", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: path.join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
session: { store: path.join(home, "sessions.json") },
|
||||
},
|
||||
session: { store: path.join(home, "sessions.json") },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -189,10 +187,10 @@ describe("directive parsing", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: path.join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: { store: storePath },
|
||||
},
|
||||
session: { store: storePath },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -251,10 +249,10 @@ describe("directive parsing", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: path.join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: { store: storePath },
|
||||
},
|
||||
session: { store: storePath },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -284,9 +282,7 @@ describe("directive parsing", () => {
|
||||
"openai/gpt-4.1-mini",
|
||||
],
|
||||
},
|
||||
inbound: {
|
||||
session: { store: storePath },
|
||||
},
|
||||
session: { store: storePath },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -313,9 +309,7 @@ describe("directive parsing", () => {
|
||||
workspace: path.join(home, "clawd"),
|
||||
allowedModels: ["openai/gpt-4.1-mini"],
|
||||
},
|
||||
inbound: {
|
||||
session: { store: storePath },
|
||||
},
|
||||
session: { store: storePath },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -354,10 +348,10 @@ describe("directive parsing", () => {
|
||||
workspace: path.join(home, "clawd"),
|
||||
allowedModels: ["openai/gpt-4.1-mini"],
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: { store: storePath },
|
||||
},
|
||||
session: { store: storePath },
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ function makeCfg(home: string) {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: { store: join(home, "sessions.json") },
|
||||
},
|
||||
session: { store: join(home, "sessions.json") },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Group activation set to always");
|
||||
const store = JSON.parse(
|
||||
await fs.readFile(cfg.inbound.session.store, "utf-8"),
|
||||
await fs.readFile(cfg.session.store, "utf-8"),
|
||||
) as Record<string, { groupActivation?: string }>;
|
||||
expect(store["group:123@g.us"]?.groupActivation).toBe("always");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
@@ -172,11 +172,11 @@ describe("trigger handling", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: { store: join(home, "sessions.json") },
|
||||
groupChat: { requireMention: false },
|
||||
},
|
||||
session: { store: join(home, "sessions.json") },
|
||||
},
|
||||
);
|
||||
|
||||
@@ -214,11 +214,11 @@ describe("trigger handling", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: {
|
||||
store: join(tmpdir(), `clawdis-session-test-${Date.now()}.json`),
|
||||
},
|
||||
},
|
||||
session: {
|
||||
store: join(tmpdir(), `clawdis-session-test-${Date.now()}.json`),
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -254,11 +254,11 @@ describe("trigger handling", () => {
|
||||
model: "claude-opus-4-5",
|
||||
workspace: join(home, "clawd"),
|
||||
},
|
||||
inbound: {
|
||||
routing: {
|
||||
allowFrom: ["*"],
|
||||
session: {
|
||||
store: join(tmpdir(), `clawdis-session-test-${Date.now()}.json`),
|
||||
},
|
||||
},
|
||||
session: {
|
||||
store: join(tmpdir(), `clawdis-session-test-${Date.now()}.json`),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -137,7 +137,7 @@ function stripMentions(
|
||||
cfg: ClawdisConfig | undefined,
|
||||
): string {
|
||||
let result = text;
|
||||
const patterns = cfg?.inbound?.groupChat?.mentionPatterns ?? [];
|
||||
const patterns = cfg?.routing?.groupChat?.mentionPatterns ?? [];
|
||||
for (const p of patterns) {
|
||||
try {
|
||||
const re = new RegExp(p, "gi");
|
||||
@@ -166,7 +166,7 @@ export async function getReplyFromConfig(
|
||||
const cfg = configOverride ?? loadConfig();
|
||||
const workspaceDirRaw = cfg.agent?.workspace ?? DEFAULT_AGENT_WORKSPACE_DIR;
|
||||
const agentCfg = cfg.agent;
|
||||
const sessionCfg = cfg.inbound?.session;
|
||||
const sessionCfg = cfg.session;
|
||||
|
||||
const defaultProvider = agentCfg?.provider?.trim() || DEFAULT_PROVIDER;
|
||||
const defaultModel = agentCfg?.model?.trim() || DEFAULT_MODEL;
|
||||
@@ -227,7 +227,7 @@ export async function getReplyFromConfig(
|
||||
let transcribedText: string | undefined;
|
||||
|
||||
// Optional audio transcription before templating/session handling.
|
||||
if (cfg.inbound?.transcribeAudio && isAudio(ctx.MediaType)) {
|
||||
if (cfg.routing?.transcribeAudio && isAudio(ctx.MediaType)) {
|
||||
const transcribed = await transcribeInboundAudio(cfg, ctx, defaultRuntime);
|
||||
if (transcribed?.text) {
|
||||
transcribedText = transcribed.text;
|
||||
@@ -361,7 +361,7 @@ export async function getReplyFromConfig(
|
||||
sessionCtx.BodyStripped = modelCleaned;
|
||||
|
||||
const defaultGroupActivation = () => {
|
||||
const requireMention = cfg.inbound?.groupChat?.requireMention;
|
||||
const requireMention = cfg.routing?.groupChat?.requireMention;
|
||||
return requireMention === false ? "always" : "mention";
|
||||
};
|
||||
|
||||
@@ -611,7 +611,7 @@ export async function getReplyFromConfig(
|
||||
}
|
||||
|
||||
// Optional allowlist by origin number (E.164 without whatsapp: prefix)
|
||||
const configuredAllowFrom = cfg.inbound?.allowFrom;
|
||||
const configuredAllowFrom = cfg.routing?.allowFrom;
|
||||
const from = (ctx.From ?? "").replace(/^whatsapp:/, "");
|
||||
const to = (ctx.To ?? "").replace(/^whatsapp:/, "");
|
||||
const isSamePhone = from && to && from === to;
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from "../config/sessions.js";
|
||||
import type { ThinkLevel, VerboseLevel } from "./thinking.js";
|
||||
|
||||
type AgentConfig = NonNullable<ClawdisConfig["inbound"]>["agent"];
|
||||
type AgentConfig = NonNullable<ClawdisConfig["agent"]>;
|
||||
|
||||
type StatusArgs = {
|
||||
agent: AgentConfig;
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("transcribeInboundAudio", () => {
|
||||
global.fetch = fetchMock;
|
||||
|
||||
const cfg = {
|
||||
inbound: {
|
||||
routing: {
|
||||
transcribeAudio: {
|
||||
command: ["echo", "{{MediaPath}}"],
|
||||
timeoutSeconds: 5,
|
||||
@@ -58,7 +58,7 @@ describe("transcribeInboundAudio", () => {
|
||||
|
||||
it("returns undefined when no transcription command", async () => {
|
||||
const res = await transcribeInboundAudio(
|
||||
{ inbound: {} } as never,
|
||||
{ routing: {} } as never,
|
||||
{} as never,
|
||||
runtime as never,
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function transcribeInboundAudio(
|
||||
ctx: MsgContext,
|
||||
runtime: RuntimeEnv,
|
||||
): Promise<{ text: string } | undefined> {
|
||||
const transcriber = cfg.inbound?.transcribeAudio;
|
||||
const transcriber = cfg.routing?.transcribeAudio;
|
||||
if (!transcriber?.command?.length) return undefined;
|
||||
|
||||
const timeoutMs = Math.max((transcriber.timeoutSeconds ?? 45) * 1000, 1_000);
|
||||
|
||||
Reference in New Issue
Block a user