chore: apply lint fixes
This commit is contained in:
@@ -34,7 +34,8 @@ const DEFAULT_MAX_OUTPUT = clampNumber(
|
|||||||
1_000,
|
1_000,
|
||||||
150_000,
|
150_000,
|
||||||
);
|
);
|
||||||
const DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
const DEFAULT_PATH =
|
||||||
|
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
||||||
|
|
||||||
const stringEnum = (
|
const stringEnum = (
|
||||||
values: readonly string[],
|
values: readonly string[],
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ import { createClawdisTools } from "./clawdis-tools.js";
|
|||||||
|
|
||||||
describe("sessions tools", () => {
|
describe("sessions tools", () => {
|
||||||
it("sessions_list filters kinds and includes messages", async () => {
|
it("sessions_list filters kinds and includes messages", async () => {
|
||||||
callGatewayMock.mockImplementation(async (opts: any) => {
|
callGatewayMock.mockImplementation(async (opts: unknown) => {
|
||||||
if (opts.method === "sessions.list") {
|
const request = opts as { method?: string };
|
||||||
|
if (request.method === "sessions.list") {
|
||||||
return {
|
return {
|
||||||
path: "/tmp/sessions.json",
|
path: "/tmp/sessions.json",
|
||||||
sessions: [
|
sessions: [
|
||||||
@@ -48,7 +49,7 @@ describe("sessions tools", () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (opts.method === "chat.history") {
|
if (request.method === "chat.history") {
|
||||||
return {
|
return {
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "toolResult", content: [] },
|
{ role: "toolResult", content: [] },
|
||||||
@@ -69,7 +70,9 @@ describe("sessions tools", () => {
|
|||||||
if (!tool) throw new Error("missing sessions_list tool");
|
if (!tool) throw new Error("missing sessions_list tool");
|
||||||
|
|
||||||
const result = await tool.execute("call1", { messageLimit: 1 });
|
const result = await tool.execute("call1", { messageLimit: 1 });
|
||||||
const details = result.details as { sessions?: any[] };
|
const details = result.details as {
|
||||||
|
sessions?: Array<Record<string, unknown>>;
|
||||||
|
};
|
||||||
expect(details.sessions).toHaveLength(3);
|
expect(details.sessions).toHaveLength(3);
|
||||||
const main = details.sessions?.find((s) => s.key === "main");
|
const main = details.sessions?.find((s) => s.key === "main");
|
||||||
expect(main?.provider).toBe("whatsapp");
|
expect(main?.provider).toBe("whatsapp");
|
||||||
@@ -77,14 +80,17 @@ describe("sessions tools", () => {
|
|||||||
expect(main?.messages?.[0]?.role).toBe("assistant");
|
expect(main?.messages?.[0]?.role).toBe("assistant");
|
||||||
|
|
||||||
const cronOnly = await tool.execute("call2", { kinds: ["cron"] });
|
const cronOnly = await tool.execute("call2", { kinds: ["cron"] });
|
||||||
const cronDetails = cronOnly.details as { sessions?: any[] };
|
const cronDetails = cronOnly.details as {
|
||||||
|
sessions?: Array<Record<string, unknown>>;
|
||||||
|
};
|
||||||
expect(cronDetails.sessions).toHaveLength(1);
|
expect(cronDetails.sessions).toHaveLength(1);
|
||||||
expect(cronDetails.sessions?.[0]?.kind).toBe("cron");
|
expect(cronDetails.sessions?.[0]?.kind).toBe("cron");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sessions_history filters tool messages by default", async () => {
|
it("sessions_history filters tool messages by default", async () => {
|
||||||
callGatewayMock.mockImplementation(async (opts: any) => {
|
callGatewayMock.mockImplementation(async (opts: unknown) => {
|
||||||
if (opts.method === "chat.history") {
|
const request = opts as { method?: string };
|
||||||
|
if (request.method === "chat.history") {
|
||||||
return {
|
return {
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "toolResult", content: [] },
|
{ role: "toolResult", content: [] },
|
||||||
@@ -102,7 +108,7 @@ describe("sessions tools", () => {
|
|||||||
if (!tool) throw new Error("missing sessions_history tool");
|
if (!tool) throw new Error("missing sessions_history tool");
|
||||||
|
|
||||||
const result = await tool.execute("call3", { sessionKey: "main" });
|
const result = await tool.execute("call3", { sessionKey: "main" });
|
||||||
const details = result.details as { messages?: any[] };
|
const details = result.details as { messages?: unknown[] };
|
||||||
expect(details.messages).toHaveLength(1);
|
expect(details.messages).toHaveLength(1);
|
||||||
expect(details.messages?.[0]?.role).toBe("assistant");
|
expect(details.messages?.[0]?.role).toBe("assistant");
|
||||||
|
|
||||||
@@ -110,18 +116,19 @@ describe("sessions tools", () => {
|
|||||||
sessionKey: "main",
|
sessionKey: "main",
|
||||||
includeTools: true,
|
includeTools: true,
|
||||||
});
|
});
|
||||||
const withToolsDetails = withTools.details as { messages?: any[] };
|
const withToolsDetails = withTools.details as { messages?: unknown[] };
|
||||||
expect(withToolsDetails.messages).toHaveLength(2);
|
expect(withToolsDetails.messages).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sessions_send supports fire-and-forget and wait", async () => {
|
it("sessions_send supports fire-and-forget and wait", async () => {
|
||||||
callGatewayMock.mockImplementation(async (opts: any) => {
|
callGatewayMock.mockImplementation(async (opts: unknown) => {
|
||||||
if (opts.method === "agent") {
|
const request = opts as { method?: string; expectFinal?: boolean };
|
||||||
return opts.expectFinal
|
if (request.method === "agent") {
|
||||||
|
return request.expectFinal
|
||||||
? { runId: "run-1", status: "ok" }
|
? { runId: "run-1", status: "ok" }
|
||||||
: { runId: "run-1", status: "accepted" };
|
: { runId: "run-1", status: "accepted" };
|
||||||
}
|
}
|
||||||
if (opts.method === "chat.history") {
|
if (request.method === "chat.history") {
|
||||||
return {
|
return {
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "assistant", content: [{ type: "text", text: "done" }] },
|
{ role: "assistant", content: [{ type: "text", text: "done" }] },
|
||||||
|
|||||||
@@ -294,7 +294,11 @@ function deriveProvider(params: {
|
|||||||
surface?: string | null;
|
surface?: string | null;
|
||||||
lastChannel?: string | null;
|
lastChannel?: string | null;
|
||||||
}): string {
|
}): string {
|
||||||
if (params.kind === "cron" || params.kind === "hook" || params.kind === "node")
|
if (
|
||||||
|
params.kind === "cron" ||
|
||||||
|
params.kind === "hook" ||
|
||||||
|
params.kind === "node"
|
||||||
|
)
|
||||||
return "internal";
|
return "internal";
|
||||||
const surface = normalizeKey(params.surface ?? undefined);
|
const surface = normalizeKey(params.surface ?? undefined);
|
||||||
if (surface) return surface;
|
if (surface) return surface;
|
||||||
@@ -2503,8 +2507,7 @@ function createSessionsListTool(): AnyAgentTool {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const sessions = Array.isArray(list?.sessions) ? list.sessions : [];
|
const sessions = Array.isArray(list?.sessions) ? list.sessions : [];
|
||||||
const storePath =
|
const storePath = typeof list?.path === "string" ? list.path : undefined;
|
||||||
typeof list?.path === "string" ? list.path : undefined;
|
|
||||||
const rows: SessionListRow[] = [];
|
const rows: SessionListRow[] = [];
|
||||||
|
|
||||||
for (const entry of sessions) {
|
for (const entry of sessions) {
|
||||||
@@ -2572,7 +2575,9 @@ function createSessionsListTool(): AnyAgentTool {
|
|||||||
? entry.verboseLevel
|
? entry.verboseLevel
|
||||||
: undefined,
|
: undefined,
|
||||||
systemSent:
|
systemSent:
|
||||||
typeof entry.systemSent === "boolean" ? entry.systemSent : undefined,
|
typeof entry.systemSent === "boolean"
|
||||||
|
? entry.systemSent
|
||||||
|
: undefined,
|
||||||
abortedLastRun:
|
abortedLastRun:
|
||||||
typeof entry.abortedLastRun === "boolean"
|
typeof entry.abortedLastRun === "boolean"
|
||||||
? entry.abortedLastRun
|
? entry.abortedLastRun
|
||||||
|
|||||||
@@ -135,7 +135,10 @@ describe("trigger handling", () => {
|
|||||||
expect(text).toContain("Send policy set to off");
|
expect(text).toContain("Send policy set to off");
|
||||||
|
|
||||||
const storeRaw = await fs.readFile(cfg.session.store, "utf-8");
|
const storeRaw = await fs.readFile(cfg.session.store, "utf-8");
|
||||||
const store = JSON.parse(storeRaw) as Record<string, { sendPolicy?: string }>;
|
const store = JSON.parse(storeRaw) as Record<
|
||||||
|
string,
|
||||||
|
{ sendPolicy?: string }
|
||||||
|
>;
|
||||||
expect(store.main?.sendPolicy).toBe("deny");
|
expect(store.main?.sendPolicy).toBe("deny");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ import {
|
|||||||
normalizeGroupActivation,
|
normalizeGroupActivation,
|
||||||
parseActivationCommand,
|
parseActivationCommand,
|
||||||
} from "./group-activation.js";
|
} from "./group-activation.js";
|
||||||
import { parseSendPolicyCommand } from "./send-policy.js";
|
|
||||||
import { stripHeartbeatToken } from "./heartbeat.js";
|
import { stripHeartbeatToken } from "./heartbeat.js";
|
||||||
import { extractModelDirective } from "./model.js";
|
import { extractModelDirective } from "./model.js";
|
||||||
|
import { parseSendPolicyCommand } from "./send-policy.js";
|
||||||
import { buildStatusMessage } from "./status.js";
|
import { buildStatusMessage } from "./status.js";
|
||||||
import type { MsgContext, TemplateContext } from "./templating.js";
|
import type { MsgContext, TemplateContext } from "./templating.js";
|
||||||
import {
|
import {
|
||||||
@@ -1639,9 +1639,7 @@ export async function getReplyFromConfig(
|
|||||||
|
|
||||||
if (sendPolicyCommand.hasCommand) {
|
if (sendPolicyCommand.hasCommand) {
|
||||||
if (!isOwnerSender) {
|
if (!isOwnerSender) {
|
||||||
logVerbose(
|
logVerbose(`Ignoring /send from non-owner: ${senderE164 || "<unknown>"}`);
|
||||||
`Ignoring /send from non-owner: ${senderE164 || "<unknown>"}`,
|
|
||||||
);
|
|
||||||
cleanupTyping();
|
cleanupTyping();
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -1754,9 +1752,7 @@ export async function getReplyFromConfig(
|
|||||||
chatType: sessionEntry?.chatType,
|
chatType: sessionEntry?.chatType,
|
||||||
});
|
});
|
||||||
if (sendPolicy === "deny") {
|
if (sendPolicy === "deny") {
|
||||||
logVerbose(
|
logVerbose(`Send blocked by policy for session ${sessionKey ?? "unknown"}`);
|
||||||
`Send blocked by policy for session ${sessionKey ?? "unknown"}`,
|
|
||||||
);
|
|
||||||
cleanupTyping();
|
cleanupTyping();
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,11 +299,7 @@ export const SessionsPatchParamsSchema = Type.Object(
|
|||||||
verboseLevel: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
|
verboseLevel: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
|
||||||
model: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
|
model: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
|
||||||
sendPolicy: Type.Optional(
|
sendPolicy: Type.Optional(
|
||||||
Type.Union([
|
Type.Union([Type.Literal("allow"), Type.Literal("deny"), Type.Null()]),
|
||||||
Type.Literal("allow"),
|
|
||||||
Type.Literal("deny"),
|
|
||||||
Type.Null(),
|
|
||||||
]),
|
|
||||||
),
|
),
|
||||||
groupActivation: Type.Optional(
|
groupActivation: Type.Optional(
|
||||||
Type.Union([
|
Type.Union([
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ import {
|
|||||||
type SessionEntry,
|
type SessionEntry,
|
||||||
saveSessionStore,
|
saveSessionStore,
|
||||||
} from "../config/sessions.js";
|
} from "../config/sessions.js";
|
||||||
import { normalizeSendPolicy } from "../sessions/send-policy.js";
|
|
||||||
import {
|
import {
|
||||||
loadVoiceWakeConfig,
|
loadVoiceWakeConfig,
|
||||||
setVoiceWakeTriggers,
|
setVoiceWakeTriggers,
|
||||||
} from "../infra/voicewake.js";
|
} from "../infra/voicewake.js";
|
||||||
import { defaultRuntime } from "../runtime.js";
|
import { defaultRuntime } from "../runtime.js";
|
||||||
|
import { normalizeSendPolicy } from "../sessions/send-policy.js";
|
||||||
import { buildMessageWithAttachments } from "./chat-attachments.js";
|
import { buildMessageWithAttachments } from "./chat-attachments.js";
|
||||||
import {
|
import {
|
||||||
ErrorCodes,
|
ErrorCodes,
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ describe("resolveSendPolicy", () => {
|
|||||||
const cfg = {
|
const cfg = {
|
||||||
session: { sendPolicy: { default: "allow" } },
|
session: { sendPolicy: { default: "allow" } },
|
||||||
} as ClawdisConfig;
|
} as ClawdisConfig;
|
||||||
const entry: SessionEntry = { sessionId: "s", updatedAt: 0, sendPolicy: "deny" };
|
const entry: SessionEntry = {
|
||||||
|
sessionId: "s",
|
||||||
|
updatedAt: 0,
|
||||||
|
sendPolicy: "deny",
|
||||||
|
};
|
||||||
expect(resolveSendPolicy({ cfg, entry })).toBe("deny");
|
expect(resolveSendPolicy({ cfg, entry })).toBe("deny");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -23,7 +27,10 @@ describe("resolveSendPolicy", () => {
|
|||||||
sendPolicy: {
|
sendPolicy: {
|
||||||
default: "allow",
|
default: "allow",
|
||||||
rules: [
|
rules: [
|
||||||
{ action: "deny", match: { surface: "discord", chatType: "group" } },
|
{
|
||||||
|
action: "deny",
|
||||||
|
match: { surface: "discord", chatType: "group" },
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -34,9 +41,9 @@ describe("resolveSendPolicy", () => {
|
|||||||
surface: "discord",
|
surface: "discord",
|
||||||
chatType: "group",
|
chatType: "group",
|
||||||
};
|
};
|
||||||
expect(resolveSendPolicy({ cfg, entry, sessionKey: "discord:group:dev" })).toBe(
|
expect(
|
||||||
"deny",
|
resolveSendPolicy({ cfg, entry, sessionKey: "discord:group:dev" }),
|
||||||
);
|
).toBe("deny");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rule match by keyPrefix", () => {
|
it("rule match by keyPrefix", () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ClawdisConfig } from "../config/config.js";
|
import type { ClawdisConfig } from "../config/config.js";
|
||||||
import type { SessionEntry, SessionChatType } from "../config/sessions.js";
|
import type { SessionChatType, SessionEntry } from "../config/sessions.js";
|
||||||
|
|
||||||
export type SessionSendPolicyDecision = "allow" | "deny";
|
export type SessionSendPolicyDecision = "allow" | "deny";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user