Format: apply oxfmt fixes
This commit is contained in:
committed by
Peter Steinberger
parent
8c1e6a82b2
commit
232c512502
@@ -2,15 +2,12 @@ import { completeSimple, getModel } from "@mariozechner/pi-ai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const GEMINI_KEY = process.env.GEMINI_API_KEY ?? "";
|
||||
const LIVE =
|
||||
process.env.GEMINI_LIVE_TEST === "1" || process.env.LIVE === "1";
|
||||
const LIVE = process.env.GEMINI_LIVE_TEST === "1" || process.env.LIVE === "1";
|
||||
|
||||
const describeLive = LIVE && GEMINI_KEY ? describe : describe.skip;
|
||||
|
||||
describeLive("gemini live switch", () => {
|
||||
it(
|
||||
"handles unsigned tool calls from Antigravity when switching to Gemini 3",
|
||||
async () => {
|
||||
it("handles unsigned tool calls from Antigravity when switching to Gemini 3", async () => {
|
||||
const now = Date.now();
|
||||
const model = getModel("google", "gemini-3-pro-preview");
|
||||
|
||||
@@ -77,7 +74,5 @@ describeLive("gemini live switch", () => {
|
||||
);
|
||||
|
||||
expect(res.stopReason).not.toBe("error");
|
||||
},
|
||||
20000,
|
||||
);
|
||||
}, 20000);
|
||||
});
|
||||
|
||||
@@ -116,7 +116,12 @@ export function resolveCommandAuthorization(params: {
|
||||
|
||||
const ownerCandidates = allowAll ? [] : allowFromList.filter((entry) => entry !== "*");
|
||||
if (!allowAll && ownerCandidates.length === 0 && to) {
|
||||
const normalizedTo = normalizeAllowFromEntry({ dock, cfg, accountId: ctx.AccountId, value: to });
|
||||
const normalizedTo = normalizeAllowFromEntry({
|
||||
dock,
|
||||
cfg,
|
||||
accountId: ctx.AccountId,
|
||||
value: to,
|
||||
});
|
||||
if (normalizedTo) ownerCandidates.push(normalizedTo);
|
||||
}
|
||||
const ownerList = ownerCandidates;
|
||||
|
||||
@@ -26,7 +26,7 @@ export function buildThreadingToolContext(params: {
|
||||
const dock = getChannelDock(provider);
|
||||
if (!dock?.threading?.buildToolContext) return {};
|
||||
// WhatsApp context isolation keys off conversation id, not the bot's own number.
|
||||
const threadingTo = provider === "whatsapp" ? sessionCtx.From ?? sessionCtx.To : sessionCtx.To;
|
||||
const threadingTo = provider === "whatsapp" ? (sessionCtx.From ?? sessionCtx.To) : sessionCtx.To;
|
||||
return (
|
||||
dock.threading.buildToolContext({
|
||||
cfg: config,
|
||||
|
||||
@@ -9,9 +9,7 @@ import { initSessionState } from "./session.js";
|
||||
|
||||
describe("initSessionState reset triggers in WhatsApp groups", () => {
|
||||
async function createStorePath(prefix: string): Promise<string> {
|
||||
const root = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), prefix),
|
||||
);
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
return path.join(root, "sessions.json");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,7 @@ import {
|
||||
} from "./message-utils.js";
|
||||
import { buildDirectLabel, buildGuildLabel, resolveReplyContext } from "./reply-context.js";
|
||||
import { deliverDiscordReply } from "./reply-delivery.js";
|
||||
import {
|
||||
resolveDiscordAutoThreadReplyPlan,
|
||||
resolveDiscordThreadStarter,
|
||||
} from "./threading.js";
|
||||
import { resolveDiscordAutoThreadReplyPlan, resolveDiscordThreadStarter } from "./threading.js";
|
||||
import { sendTyping } from "./typing.js";
|
||||
|
||||
export async function processDiscordMessage(ctx: DiscordMessagePreflightContext) {
|
||||
|
||||
@@ -93,9 +93,14 @@ describe("resolveDiscordAutoThreadReplyPlan", () => {
|
||||
} as unknown as Client;
|
||||
const plan = await resolveDiscordAutoThreadReplyPlan({
|
||||
client,
|
||||
message: { id: "m1", channelId: "parent" } as unknown as import("./listeners.js").DiscordMessageEvent["message"],
|
||||
message: {
|
||||
id: "m1",
|
||||
channelId: "parent",
|
||||
} as unknown as import("./listeners.js").DiscordMessageEvent["message"],
|
||||
isGuildMessage: true,
|
||||
channelConfig: { autoThread: true } as unknown as import("./allow-list.js").DiscordChannelConfigResolved,
|
||||
channelConfig: {
|
||||
autoThread: true,
|
||||
} as unknown as import("./allow-list.js").DiscordChannelConfigResolved,
|
||||
threadChannel: null,
|
||||
baseText: "hello",
|
||||
combinedBody: "hello",
|
||||
@@ -118,9 +123,14 @@ describe("resolveDiscordAutoThreadReplyPlan", () => {
|
||||
const client = { rest: { post: async () => ({ id: "thread" }) } } as unknown as Client;
|
||||
const plan = await resolveDiscordAutoThreadReplyPlan({
|
||||
client,
|
||||
message: { id: "m1", channelId: "parent" } as unknown as import("./listeners.js").DiscordMessageEvent["message"],
|
||||
message: {
|
||||
id: "m1",
|
||||
channelId: "parent",
|
||||
} as unknown as import("./listeners.js").DiscordMessageEvent["message"],
|
||||
isGuildMessage: true,
|
||||
channelConfig: { autoThread: false } as unknown as import("./allow-list.js").DiscordChannelConfigResolved,
|
||||
channelConfig: {
|
||||
autoThread: false,
|
||||
} as unknown as import("./allow-list.js").DiscordChannelConfigResolved,
|
||||
threadChannel: null,
|
||||
baseText: "hello",
|
||||
combinedBody: "hello",
|
||||
|
||||
@@ -86,9 +86,7 @@ describe("deliverOutboundPayloads", () => {
|
||||
});
|
||||
|
||||
it("chunks Signal markdown using the format-first chunker", async () => {
|
||||
const sendSignal = vi
|
||||
.fn()
|
||||
.mockResolvedValue({ messageId: "s1", timestamp: 123 });
|
||||
const sendSignal = vi.fn().mockResolvedValue({ messageId: "s1", timestamp: 123 });
|
||||
const cfg: ClawdbotConfig = {
|
||||
channels: { signal: { textChunkLimit: 20 } },
|
||||
};
|
||||
|
||||
@@ -25,13 +25,7 @@ type MarkdownToken = {
|
||||
attrGet?: (name: string) => string | null;
|
||||
};
|
||||
|
||||
export type MarkdownStyle =
|
||||
| "bold"
|
||||
| "italic"
|
||||
| "strikethrough"
|
||||
| "code"
|
||||
| "code_block"
|
||||
| "spoiler";
|
||||
export type MarkdownStyle = "bold" | "italic" | "strikethrough" | "code" | "code_block" | "spoiler";
|
||||
|
||||
export type MarkdownStyleSpan = {
|
||||
start: number;
|
||||
@@ -414,11 +408,7 @@ function sliceStyleSpans(
|
||||
return mergeStyleSpans(sliced);
|
||||
}
|
||||
|
||||
function sliceLinkSpans(
|
||||
spans: MarkdownLinkSpan[],
|
||||
start: number,
|
||||
end: number,
|
||||
): MarkdownLinkSpan[] {
|
||||
function sliceLinkSpans(spans: MarkdownLinkSpan[], start: number, end: number): MarkdownLinkSpan[] {
|
||||
if (spans.length === 0) return [];
|
||||
const sliced: MarkdownLinkSpan[] = [];
|
||||
for (const span of spans) {
|
||||
@@ -465,7 +455,8 @@ export function markdownToIR(markdown: string, options: MarkdownParseOptions = {
|
||||
if (span.end > codeBlockEnd) codeBlockEnd = span.end;
|
||||
}
|
||||
const finalLength = Math.max(trimmedLength, codeBlockEnd);
|
||||
const finalText = finalLength === state.text.length ? state.text : state.text.slice(0, finalLength);
|
||||
const finalText =
|
||||
finalLength === state.text.length ? state.text : state.text.slice(0, finalLength);
|
||||
|
||||
return {
|
||||
text: finalText,
|
||||
|
||||
@@ -46,9 +46,7 @@ export function renderMarkdownWithMarkers(ir: MarkdownIR, options: RenderOptions
|
||||
if (!text) return "";
|
||||
|
||||
const styleMarkers = options.styleMarkers;
|
||||
const styled = sortStyleSpans(
|
||||
ir.styles.filter((span) => Boolean(styleMarkers[span.style])),
|
||||
);
|
||||
const styled = sortStyleSpans(ir.styles.filter((span) => Boolean(styleMarkers[span.style])));
|
||||
|
||||
const boundaries = new Set<number>();
|
||||
boundaries.add(0);
|
||||
|
||||
@@ -16,13 +16,9 @@ describe("markdownToSignalText", () => {
|
||||
});
|
||||
|
||||
it("renders links as label plus url when needed", () => {
|
||||
const res = markdownToSignalText(
|
||||
"see [docs](https://example.com) and https://example.com",
|
||||
);
|
||||
const res = markdownToSignalText("see [docs](https://example.com) and https://example.com");
|
||||
|
||||
expect(res.text).toBe(
|
||||
"see docs (https://example.com) and https://example.com",
|
||||
);
|
||||
expect(res.text).toBe("see docs (https://example.com) and https://example.com");
|
||||
expect(res.styles).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -34,18 +30,14 @@ describe("markdownToSignalText", () => {
|
||||
});
|
||||
|
||||
it("renders fenced code blocks with monospaced styles", () => {
|
||||
const res = markdownToSignalText(
|
||||
"before\n\n```\nconst x = 1;\n```\n\nafter",
|
||||
);
|
||||
const res = markdownToSignalText("before\n\n```\nconst x = 1;\n```\n\nafter");
|
||||
|
||||
const prefix = "before\n\n";
|
||||
const code = "const x = 1;\n";
|
||||
const suffix = "\nafter";
|
||||
|
||||
expect(res.text).toBe(`${prefix}${code}${suffix}`);
|
||||
expect(res.styles).toEqual([
|
||||
{ start: prefix.length, length: code.length, style: "MONOSPACE" },
|
||||
]);
|
||||
expect(res.styles).toEqual([{ start: prefix.length, length: code.length, style: "MONOSPACE" }]);
|
||||
});
|
||||
|
||||
it("renders lists without extra block markup", () => {
|
||||
@@ -60,8 +52,6 @@ describe("markdownToSignalText", () => {
|
||||
|
||||
const prefix = "😀 ";
|
||||
expect(res.text).toBe(`${prefix}bold`);
|
||||
expect(res.styles).toEqual([
|
||||
{ start: prefix.length, length: 4, style: "BOLD" },
|
||||
]);
|
||||
expect(res.styles).toEqual([{ start: prefix.length, length: 4, style: "BOLD" }]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { chunkMarkdownIR, markdownToIR, type MarkdownIR, type MarkdownStyle } from "../markdown/ir.js";
|
||||
import {
|
||||
chunkMarkdownIR,
|
||||
markdownToIR,
|
||||
type MarkdownIR,
|
||||
type MarkdownStyle,
|
||||
} from "../markdown/ir.js";
|
||||
|
||||
type SignalTextStyle =
|
||||
| "BOLD"
|
||||
| "ITALIC"
|
||||
| "STRIKETHROUGH"
|
||||
| "MONOSPACE"
|
||||
| "SPOILER";
|
||||
type SignalTextStyle = "BOLD" | "ITALIC" | "STRIKETHROUGH" | "MONOSPACE" | "SPOILER";
|
||||
|
||||
export type SignalTextStyleRange = {
|
||||
start: number;
|
||||
@@ -57,11 +57,7 @@ function mergeStyles(styles: SignalTextStyleRange[]): SignalTextStyleRange[] {
|
||||
const merged: SignalTextStyleRange[] = [];
|
||||
for (const style of sorted) {
|
||||
const prev = merged[merged.length - 1];
|
||||
if (
|
||||
prev &&
|
||||
prev.style === style.style &&
|
||||
style.start <= prev.start + prev.length
|
||||
) {
|
||||
if (prev && prev.style === style.style && style.start <= prev.start + prev.length) {
|
||||
const prevEnd = prev.start + prev.length;
|
||||
const nextEnd = Math.max(prevEnd, style.start + style.length);
|
||||
prev.length = nextEnd - prev.start;
|
||||
@@ -73,10 +69,7 @@ function mergeStyles(styles: SignalTextStyleRange[]): SignalTextStyleRange[] {
|
||||
return merged;
|
||||
}
|
||||
|
||||
function clampStyles(
|
||||
styles: SignalTextStyleRange[],
|
||||
maxLength: number,
|
||||
): SignalTextStyleRange[] {
|
||||
function clampStyles(styles: SignalTextStyleRange[], maxLength: number): SignalTextStyleRange[] {
|
||||
const clamped: SignalTextStyleRange[] = [];
|
||||
for (const style of styles) {
|
||||
const start = Math.max(0, Math.min(style.start, maxLength));
|
||||
@@ -205,10 +198,7 @@ export function markdownToSignalText(markdown: string): SignalFormattedText {
|
||||
return renderSignalText(ir);
|
||||
}
|
||||
|
||||
export function markdownToSignalTextChunks(
|
||||
markdown: string,
|
||||
limit: number,
|
||||
): SignalFormattedText[] {
|
||||
export function markdownToSignalTextChunks(markdown: string, limit: number): SignalFormattedText[] {
|
||||
const ir = markdownToIR(markdown ?? "", {
|
||||
linkify: true,
|
||||
enableSpoilers: true,
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { chunkMarkdownIR, markdownToIR, type MarkdownLinkSpan, type MarkdownIR } from "../markdown/ir.js";
|
||||
import {
|
||||
chunkMarkdownIR,
|
||||
markdownToIR,
|
||||
type MarkdownLinkSpan,
|
||||
type MarkdownIR,
|
||||
} from "../markdown/ir.js";
|
||||
import { renderMarkdownWithMarkers } from "../markdown/render.js";
|
||||
|
||||
export type TelegramFormattedChunk = {
|
||||
@@ -50,7 +55,10 @@ export function markdownToTelegramHtml(markdown: string): string {
|
||||
return renderTelegramHtml(ir);
|
||||
}
|
||||
|
||||
export function markdownToTelegramChunks(markdown: string, limit: number): TelegramFormattedChunk[] {
|
||||
export function markdownToTelegramChunks(
|
||||
markdown: string,
|
||||
limit: number,
|
||||
): TelegramFormattedChunk[] {
|
||||
const ir = markdownToIR(markdown ?? "", {
|
||||
linkify: true,
|
||||
headingStyle: "none",
|
||||
|
||||
@@ -432,9 +432,7 @@ export async function deleteMessageTelegram(
|
||||
verbose: opts.verbose,
|
||||
});
|
||||
await request(() => api.deleteMessage(chatId, messageId), "deleteMessage");
|
||||
logVerbose(
|
||||
`[telegram] Deleted message ${messageId} from chat ${chatId}`,
|
||||
);
|
||||
logVerbose(`[telegram] Deleted message ${messageId} from chat ${chatId}`);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
isWhatsAppGroupJid,
|
||||
isWhatsAppUserTarget,
|
||||
normalizeWhatsAppTarget,
|
||||
} from "./normalize.js";
|
||||
import { isWhatsAppGroupJid, isWhatsAppUserTarget, normalizeWhatsAppTarget } from "./normalize.js";
|
||||
|
||||
describe("normalizeWhatsAppTarget", () => {
|
||||
it("preserves group JIDs", () => {
|
||||
@@ -31,16 +27,10 @@ describe("normalizeWhatsAppTarget", () => {
|
||||
it("normalizes user JIDs with device suffix to E.164", () => {
|
||||
// This is the bug fix: JIDs like "41796666864:0@s.whatsapp.net" should
|
||||
// normalize to "+41796666864", not "+417966668640" (extra digit from ":0")
|
||||
expect(normalizeWhatsAppTarget("41796666864:0@s.whatsapp.net")).toBe(
|
||||
"+41796666864",
|
||||
);
|
||||
expect(normalizeWhatsAppTarget("1234567890:123@s.whatsapp.net")).toBe(
|
||||
"+1234567890",
|
||||
);
|
||||
expect(normalizeWhatsAppTarget("41796666864:0@s.whatsapp.net")).toBe("+41796666864");
|
||||
expect(normalizeWhatsAppTarget("1234567890:123@s.whatsapp.net")).toBe("+1234567890");
|
||||
// Without device suffix still works
|
||||
expect(normalizeWhatsAppTarget("41796666864@s.whatsapp.net")).toBe(
|
||||
"+41796666864",
|
||||
);
|
||||
expect(normalizeWhatsAppTarget("41796666864@s.whatsapp.net")).toBe("+41796666864");
|
||||
});
|
||||
|
||||
it("normalizes LID JIDs to E.164", () => {
|
||||
|
||||
Reference in New Issue
Block a user