fix: address LLM square bracket mapping format and resolve Biome import formatting
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
cc2c247311
commit
1085d7909c
@@ -1,7 +1,7 @@
|
|||||||
import { existsSync, statSync } from "node:fs";
|
import { existsSync, statSync } from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { AppError } from "../errors";
|
import { AppError } from "../errors";
|
||||||
import type { ResolvedMediaSource, MediaMode } from "./mediaTypes";
|
import type { MediaMode, ResolvedMediaSource } from "./mediaTypes";
|
||||||
import { createPlayDlResolver } from "./playDlResolver";
|
import { createPlayDlResolver } from "./playDlResolver";
|
||||||
import { createYtDlp, type YtDlpClient } from "./ytdlp";
|
import { createYtDlp, type YtDlpClient } from "./ytdlp";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Streamer, playPreparedStream } from "../streaming";
|
|
||||||
import { AppError } from "../errors";
|
import { AppError } from "../errors";
|
||||||
import { createChildLogger } from "../logger";
|
import { createChildLogger } from "../logger";
|
||||||
import { discordPlayer } from "../player";
|
import { discordPlayer } from "../player";
|
||||||
|
import { playPreparedStream, Streamer } from "../streaming";
|
||||||
|
|
||||||
const logger = createChildLogger("screen-share");
|
const logger = createChildLogger("screen-share");
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,10 @@ export function parseModerationResponse(
|
|||||||
throw new Error("Result missing 'message_id'");
|
throw new Error("Result missing 'message_id'");
|
||||||
}
|
}
|
||||||
|
|
||||||
let finalId = String(message_id);
|
let finalId = String(message_id).trim();
|
||||||
|
if (finalId.startsWith("[") && finalId.endsWith("]")) {
|
||||||
|
finalId = finalId.slice(1, -1).trim();
|
||||||
|
}
|
||||||
|
|
||||||
// Precision loss fix: If the ID from LLM is not found,
|
// Precision loss fix: If the ID from LLM is not found,
|
||||||
// try to find the closest match in targets if it looks rounded (ends in 000)
|
// try to find the closest match in targets if it looks rounded (ends in 000)
|
||||||
|
|||||||
+1
-1
@@ -9,8 +9,8 @@ import {
|
|||||||
VoiceConnection,
|
VoiceConnection,
|
||||||
} from "@discordjs/voice";
|
} from "@discordjs/voice";
|
||||||
import type {
|
import type {
|
||||||
DiscordPlayOptions,
|
|
||||||
DiscordPlayerOwner,
|
DiscordPlayerOwner,
|
||||||
|
DiscordPlayOptions,
|
||||||
} from "./media/mediaTypes";
|
} from "./media/mediaTypes";
|
||||||
|
|
||||||
export class DiscordPlayer {
|
export class DiscordPlayer {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { EventEmitter } from "node:events";
|
|
||||||
import { PassThrough } from "node:stream";
|
|
||||||
import type { Readable } from "node:stream";
|
|
||||||
import type { ChildProcess } from "node:child_process";
|
import type { ChildProcess } from "node:child_process";
|
||||||
import type { Client } from "discord.js-selfbot-v13";
|
import { EventEmitter } from "node:events";
|
||||||
|
import type { Readable } from "node:stream";
|
||||||
|
import { PassThrough } from "node:stream";
|
||||||
import {
|
import {
|
||||||
Streamer as DankStreamer,
|
Streamer as DankStreamer,
|
||||||
prepareStream as dankPrepareStream,
|
|
||||||
playStream as dankPlayStream,
|
playStream as dankPlayStream,
|
||||||
Utils,
|
prepareStream as dankPrepareStream,
|
||||||
Encoders,
|
Encoders,
|
||||||
|
Utils,
|
||||||
} from "@dank074/discord-video-stream";
|
} from "@dank074/discord-video-stream";
|
||||||
|
import type { Client } from "discord.js-selfbot-v13";
|
||||||
|
|
||||||
type VoiceConnectionLike = any;
|
type VoiceConnectionLike = any;
|
||||||
type StreamConnectionLike = any;
|
type StreamConnectionLike = any;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { spawn, ChildProcess } from "node:child_process";
|
import { ChildProcess, spawn } from "node:child_process";
|
||||||
import { PassThrough } from "node:stream";
|
|
||||||
import type { Readable } from "node:stream";
|
import type { Readable } from "node:stream";
|
||||||
import { retryWithBackoff } from "../retry";
|
import { PassThrough } from "node:stream";
|
||||||
import { createChildLogger } from "../logger";
|
import { createChildLogger } from "../logger";
|
||||||
import { transcoderRestartsCounter, transcoderRunningGauge } from "../metrics";
|
import { transcoderRestartsCounter, transcoderRunningGauge } from "../metrics";
|
||||||
|
import { retryWithBackoff } from "../retry";
|
||||||
|
|
||||||
const logger = createChildLogger("transcoder");
|
const logger = createChildLogger("transcoder");
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,6 @@ import fs from "node:fs";
|
|||||||
import http from "node:http";
|
import http from "node:http";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { Streamer } from "./streaming";
|
|
||||||
import { AudioPlayerStatus } from "@discordjs/voice";
|
import { AudioPlayerStatus } from "@discordjs/voice";
|
||||||
import type { Client } from "discord.js-selfbot-v13";
|
import type { Client } from "discord.js-selfbot-v13";
|
||||||
import express, {
|
import express, {
|
||||||
@@ -29,6 +28,7 @@ import { createMessageRoutes } from "./routes/messageRoutes";
|
|||||||
import { createSyncRoutes } from "./routes/syncRoutes";
|
import { createSyncRoutes } from "./routes/syncRoutes";
|
||||||
import { createUIStateRoutes } from "./routes/uiStateRoutes";
|
import { createUIStateRoutes } from "./routes/uiStateRoutes";
|
||||||
import { createVoiceRoutes } from "./routes/voiceRoutes";
|
import { createVoiceRoutes } from "./routes/voiceRoutes";
|
||||||
|
import { Streamer } from "./streaming";
|
||||||
import type { VoiceController } from "./voiceController";
|
import type { VoiceController } from "./voiceController";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { prepareStream, Encoders } from "@dank074/discord-video-stream";
|
import { Encoders, prepareStream } from "@dank074/discord-video-stream";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { prepareStream, Encoders } from "@dank074/discord-video-stream";
|
import { Encoders, prepareStream } from "@dank074/discord-video-stream";
|
||||||
import { demux } from "@dank074/discord-video-stream/dist/media/LibavDemuxer.js";
|
import { demux } from "@dank074/discord-video-stream/dist/media/LibavDemuxer.js";
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { prepareStream } from "@dank074/discord-video-stream";
|
import { prepareStream } from "@dank074/discord-video-stream";
|
||||||
import { demux } from "@dank074/discord-video-stream/dist/media/LibavDemuxer.js";
|
|
||||||
import { Encoders } from "@dank074/discord-video-stream/dist/media/encoders/index.js";
|
import { Encoders } from "@dank074/discord-video-stream/dist/media/encoders/index.js";
|
||||||
|
import { demux } from "@dank074/discord-video-stream/dist/media/LibavDemuxer.js";
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const { command, output } = prepareStream(
|
const { command, output } = prepareStream(
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ type Spawn = typeof nodeSpawn;
|
|||||||
|
|
||||||
import { EventEmitter } from "node:events";
|
import { EventEmitter } from "node:events";
|
||||||
import { PassThrough } from "node:stream";
|
import { PassThrough } from "node:stream";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { StreamType } from "@discordjs/voice";
|
import { StreamType } from "@discordjs/voice";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import type {
|
import type {
|
||||||
DiscordAudioPlayer,
|
DiscordAudioPlayer,
|
||||||
DiscordPlayerOwner,
|
DiscordPlayerOwner,
|
||||||
|
|||||||
@@ -298,6 +298,23 @@ describe("parseModerationResponse", () => {
|
|||||||
expect(result).toHaveLength(1);
|
expect(result).toHaveLength(1);
|
||||||
expect(result[0].messageId).toBe("m1");
|
expect(result[0].messageId).toBe("m1");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("handles message_id returned with square brackets", () => {
|
||||||
|
const content = JSON.stringify({
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
message_id: "[m1]",
|
||||||
|
status: "clean",
|
||||||
|
flags: [],
|
||||||
|
score: 0.1,
|
||||||
|
analysis: "OK",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const result = parseModerationResponse(content, ["m1"]);
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].messageId).toBe("m1");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("runModerationAnalysis", () => {
|
describe("runModerationAnalysis", () => {
|
||||||
@@ -519,7 +536,11 @@ describe("runModerationAnalysis", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const createAttachment = (id: string, msgId: string, createdAt: number) => ({
|
const createAttachment = (
|
||||||
|
id: string,
|
||||||
|
msgId: string,
|
||||||
|
createdAt: number,
|
||||||
|
) => ({
|
||||||
id,
|
id,
|
||||||
message_id: msgId,
|
message_id: msgId,
|
||||||
guild_id: "guild123",
|
guild_id: "guild123",
|
||||||
@@ -564,9 +585,7 @@ describe("runModerationAnalysis", () => {
|
|||||||
// Target attachments (t3, t2, t1) must be fetched, then context in descending order of created_at:
|
// Target attachments (t3, t2, t1) must be fetched, then context in descending order of created_at:
|
||||||
// Sorted order: t3 (800), t2 (500), t1 (300), c7 (1000), c6 (900), c5 (700), c4 (600), c3 (400)
|
// Sorted order: t3 (800), t2 (500), t1 (300), c7 (1000), c6 (900), c5 (700), c4 (600), c3 (400)
|
||||||
// Excluded: c2 (200), c1 (100)
|
// Excluded: c2 (200), c1 (100)
|
||||||
const downloadedUrls = fetchCalls
|
const downloadedUrls = fetchCalls.slice(0, 8).map((call: any) => call[0]);
|
||||||
.slice(0, 8)
|
|
||||||
.map((call: any) => call[0]);
|
|
||||||
|
|
||||||
expect(downloadedUrls).toContain("https://picser.tech/t3.png");
|
expect(downloadedUrls).toContain("https://picser.tech/t3.png");
|
||||||
expect(downloadedUrls).toContain("https://picser.tech/t2.png");
|
expect(downloadedUrls).toContain("https://picser.tech/t2.png");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect, vi } from "vitest";
|
|
||||||
import { PassThrough } from "node:stream";
|
import { PassThrough } from "node:stream";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
vi.mock("node:child_process", async () => {
|
vi.mock("node:child_process", async () => {
|
||||||
const actual = await vi.importActual("node:child_process");
|
const actual = await vi.importActual("node:child_process");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect, vi } from "vitest";
|
|
||||||
import { PassThrough } from "node:stream";
|
import { PassThrough } from "node:stream";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
// Mock spawn to avoid calling real ffmpeg
|
// Mock spawn to avoid calling real ffmpeg
|
||||||
vi.mock("node:child_process", async () => {
|
vi.mock("node:child_process", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user