style: format linted files
This commit is contained in:
@@ -27,9 +27,9 @@ import {
|
|||||||
} from "../agents/workspace.js";
|
} from "../agents/workspace.js";
|
||||||
import { type ClawdisConfig, loadConfig } from "../config/config.js";
|
import { type ClawdisConfig, loadConfig } from "../config/config.js";
|
||||||
import {
|
import {
|
||||||
|
buildGroupDisplayName,
|
||||||
DEFAULT_IDLE_MINUTES,
|
DEFAULT_IDLE_MINUTES,
|
||||||
DEFAULT_RESET_TRIGGERS,
|
DEFAULT_RESET_TRIGGERS,
|
||||||
buildGroupDisplayName,
|
|
||||||
loadSessionStore,
|
loadSessionStore,
|
||||||
resolveGroupSessionKey,
|
resolveGroupSessionKey,
|
||||||
resolveSessionKey,
|
resolveSessionKey,
|
||||||
@@ -401,10 +401,7 @@ export async function getReplyFromConfig(
|
|||||||
|
|
||||||
sessionKey = resolveSessionKey(sessionScope, ctx, mainKey);
|
sessionKey = resolveSessionKey(sessionScope, ctx, mainKey);
|
||||||
sessionStore = loadSessionStore(storePath);
|
sessionStore = loadSessionStore(storePath);
|
||||||
if (
|
if (groupResolution?.legacyKey && groupResolution.legacyKey !== sessionKey) {
|
||||||
groupResolution?.legacyKey &&
|
|
||||||
groupResolution.legacyKey !== sessionKey
|
|
||||||
) {
|
|
||||||
const legacyEntry = sessionStore[groupResolution.legacyKey];
|
const legacyEntry = sessionStore[groupResolution.legacyKey];
|
||||||
if (legacyEntry && !sessionStore[sessionKey]) {
|
if (legacyEntry && !sessionStore[sessionKey]) {
|
||||||
sessionStore[sessionKey] = legacyEntry;
|
sessionStore[sessionKey] = legacyEntry;
|
||||||
|
|||||||
@@ -169,7 +169,10 @@ const formatContextUsage = (
|
|||||||
return `tokens: ${formatKTokens(used)} used, ${formatKTokens(left)} left of ${formatKTokens(contextTokens)} (${pctLabel})`;
|
return `tokens: ${formatKTokens(used)} used, ${formatKTokens(left)} left of ${formatKTokens(contextTokens)} (${pctLabel})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const classifyKey = (key: string, entry?: SessionEntry): SessionStatus["kind"] => {
|
const classifyKey = (
|
||||||
|
key: string,
|
||||||
|
entry?: SessionEntry,
|
||||||
|
): SessionStatus["kind"] => {
|
||||||
if (key === "global") return "global";
|
if (key === "global") return "global";
|
||||||
if (key === "unknown") return "unknown";
|
if (key === "unknown") return "unknown";
|
||||||
if (entry?.chatType === "group" || entry?.chatType === "room") return "group";
|
if (entry?.chatType === "group" || entry?.chatType === "room") return "group";
|
||||||
|
|||||||
@@ -143,7 +143,9 @@ export function buildGroupDisplayName(params: {
|
|||||||
return token ? `${surfaceKey}:${token}` : surfaceKey;
|
return token ? `${surfaceKey}:${token}` : surfaceKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | null {
|
export function resolveGroupSessionKey(
|
||||||
|
ctx: MsgContext,
|
||||||
|
): GroupKeyResolution | null {
|
||||||
const from = typeof ctx.From === "string" ? ctx.From.trim() : "";
|
const from = typeof ctx.From === "string" ? ctx.From.trim() : "";
|
||||||
if (!from) return null;
|
if (!from) return null;
|
||||||
const chatType = ctx.ChatType?.trim().toLowerCase();
|
const chatType = ctx.ChatType?.trim().toLowerCase();
|
||||||
@@ -157,7 +159,9 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu
|
|||||||
|
|
||||||
const surfaceHint = ctx.Surface?.trim().toLowerCase();
|
const surfaceHint = ctx.Surface?.trim().toLowerCase();
|
||||||
const hasLegacyGroupPrefix = from.startsWith("group:");
|
const hasLegacyGroupPrefix = from.startsWith("group:");
|
||||||
const raw = (hasLegacyGroupPrefix ? from.slice("group:".length) : from).trim();
|
const raw = (
|
||||||
|
hasLegacyGroupPrefix ? from.slice("group:".length) : from
|
||||||
|
).trim();
|
||||||
|
|
||||||
let surface: string | undefined;
|
let surface: string | undefined;
|
||||||
let kind: "group" | "channel" | undefined;
|
let kind: "group" | "channel" | undefined;
|
||||||
@@ -209,7 +213,12 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu
|
|||||||
const resolvedSurface = surface ?? surfaceHint;
|
const resolvedSurface = surface ?? surfaceHint;
|
||||||
if (!resolvedSurface) {
|
if (!resolvedSurface) {
|
||||||
const legacy = hasLegacyGroupPrefix ? `group:${raw}` : `group:${from}`;
|
const legacy = hasLegacyGroupPrefix ? `group:${raw}` : `group:${from}`;
|
||||||
return { key: legacy, id: raw || from, legacyKey: legacy, chatType: "group" };
|
return {
|
||||||
|
key: legacy,
|
||||||
|
id: raw || from,
|
||||||
|
legacyKey: legacy,
|
||||||
|
chatType: "group",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolvedKind = kind === "channel" ? "channel" : "group";
|
const resolvedKind = kind === "channel" ? "channel" : "group";
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDirectMessage && Array.isArray(allowFrom) && allowFrom.length > 0) {
|
if (isDirectMessage && Array.isArray(allowFrom) && allowFrom.length > 0) {
|
||||||
@@ -584,14 +583,16 @@ export function resolveDiscordChannelConfig(params: {
|
|||||||
const entry =
|
const entry =
|
||||||
channelEntries[channelId] ??
|
channelEntries[channelId] ??
|
||||||
(channelSlug
|
(channelSlug
|
||||||
? channelEntries[channelSlug] ??
|
? (channelEntries[channelSlug] ?? channelEntries[`#${channelSlug}`])
|
||||||
channelEntries[`#${channelSlug}`]
|
|
||||||
: undefined) ??
|
: undefined) ??
|
||||||
(channelName
|
(channelName
|
||||||
? channelEntries[normalizeDiscordSlug(channelName)]
|
? channelEntries[normalizeDiscordSlug(channelName)]
|
||||||
: undefined);
|
: undefined);
|
||||||
if (!entry) return { allowed: false };
|
if (!entry) return { allowed: false };
|
||||||
return { allowed: entry.allow !== false, requireMention: entry.requireMention };
|
return {
|
||||||
|
allowed: entry.allow !== false,
|
||||||
|
requireMention: entry.requireMention,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return { allowed: true };
|
return { allowed: true };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,12 +80,34 @@ describe("web media loading", () => {
|
|||||||
// Create a minimal valid GIF (1x1 pixel)
|
// Create a minimal valid GIF (1x1 pixel)
|
||||||
// GIF89a header + minimal image data
|
// GIF89a header + minimal image data
|
||||||
const gifBuffer = Buffer.from([
|
const gifBuffer = Buffer.from([
|
||||||
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, // GIF89a
|
0x47,
|
||||||
0x01, 0x00, 0x01, 0x00, // 1x1 dimensions
|
0x49,
|
||||||
0x00, 0x00, 0x00, // no global color table
|
0x46,
|
||||||
0x2c, 0x00, 0x00, 0x00, 0x00, // image descriptor
|
0x38,
|
||||||
0x01, 0x00, 0x01, 0x00, 0x00, // 1x1 image
|
0x39,
|
||||||
0x02, 0x01, 0x44, 0x00, 0x3b, // minimal LZW data + trailer
|
0x61, // GIF89a
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00, // 1x1 dimensions
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00, // no global color table
|
||||||
|
0x2c,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00, // image descriptor
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00, // 1x1 image
|
||||||
|
0x02,
|
||||||
|
0x01,
|
||||||
|
0x44,
|
||||||
|
0x00,
|
||||||
|
0x3b, // minimal LZW data + trailer
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const file = path.join(os.tmpdir(), `clawdis-media-${Date.now()}.gif`);
|
const file = path.join(os.tmpdir(), `clawdis-media-${Date.now()}.gif`);
|
||||||
@@ -102,18 +124,19 @@ describe("web media loading", () => {
|
|||||||
|
|
||||||
it("preserves GIF from URL without JPEG conversion", async () => {
|
it("preserves GIF from URL without JPEG conversion", async () => {
|
||||||
const gifBytes = new Uint8Array([
|
const gifBytes = new Uint8Array([
|
||||||
0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
|
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x01, 0x00,
|
0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||||
0x00, 0x00, 0x00,
|
0x01, 0x44, 0x00, 0x3b,
|
||||||
0x2c, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x01, 0x00, 0x01, 0x00, 0x00,
|
|
||||||
0x02, 0x01, 0x44, 0x00, 0x3b,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValueOnce({
|
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValueOnce({
|
||||||
ok: true,
|
ok: true,
|
||||||
body: true,
|
body: true,
|
||||||
arrayBuffer: async () => gifBytes.buffer.slice(gifBytes.byteOffset, gifBytes.byteOffset + gifBytes.byteLength),
|
arrayBuffer: async () =>
|
||||||
|
gifBytes.buffer.slice(
|
||||||
|
gifBytes.byteOffset,
|
||||||
|
gifBytes.byteOffset + gifBytes.byteLength,
|
||||||
|
),
|
||||||
headers: { get: () => "image/gif" },
|
headers: { get: () => "image/gif" },
|
||||||
status: 200,
|
status: 200,
|
||||||
} as Response);
|
} as Response);
|
||||||
|
|||||||
Reference in New Issue
Block a user