Compare commits
3 Commits
vincentkoc
...
vincentkoc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60e8e0d3ee | ||
|
|
f62d62e237 | ||
|
|
2890c59337 |
@@ -1,7 +1,7 @@
|
||||
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import fs from "node:fs/promises";
|
||||
import type { ImageSanitizationLimits } from "../image-sanitization.js";
|
||||
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import { detectMime } from "../../media/mime.js";
|
||||
import type { ImageSanitizationLimits } from "../image-sanitization.js";
|
||||
import { sanitizeToolResultImages } from "../tool-images.js";
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import type { ChannelMessageActionContext } from "../../types.js";
|
||||
import {
|
||||
parseAvailableTags,
|
||||
readNumberParam,
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
readDiscordModerationCommand,
|
||||
} from "../../../../agents/tools/discord-actions-moderation-shared.js";
|
||||
import { handleDiscordAction } from "../../../../agents/tools/discord-actions.js";
|
||||
import type { ChannelMessageActionContext } from "../../types.js";
|
||||
|
||||
type Ctx = Pick<
|
||||
ChannelMessageActionContext,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { APIChannel } from "discord-api-types/v10";
|
||||
import { Routes } from "discord-api-types/v10";
|
||||
import { resolveDiscordRest } from "./send.shared.js";
|
||||
import type {
|
||||
DiscordChannelCreate,
|
||||
DiscordChannelEdit,
|
||||
@@ -7,7 +8,6 @@ import type {
|
||||
DiscordChannelPermissionSet,
|
||||
DiscordReactOpts,
|
||||
} from "./send.types.js";
|
||||
import { resolveDiscordRest } from "./send.shared.js";
|
||||
|
||||
export async function createChannelDiscord(
|
||||
payload: DiscordChannelCreate,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import {
|
||||
stripEnvelope,
|
||||
stripInboundMetadataBlocks,
|
||||
stripMessageIdHints,
|
||||
} from "../shared/chat-envelope.js";
|
||||
import { stripInboundMetadata } from "../auto-reply/reply/strip-inbound-meta.js";
|
||||
import { stripEnvelope, stripMessageIdHints } from "../shared/chat-envelope.js";
|
||||
|
||||
export { stripEnvelope };
|
||||
|
||||
@@ -16,7 +13,7 @@ function stripEnvelopeFromContent(content: unknown[]): { content: unknown[]; cha
|
||||
if (entry.type !== "text" || typeof entry.text !== "string") {
|
||||
return item;
|
||||
}
|
||||
const stripped = stripMessageIdHints(stripEnvelope(stripInboundMetadataBlocks(entry.text)));
|
||||
const stripped = stripMessageIdHints(stripEnvelope(stripInboundMetadata(entry.text)));
|
||||
if (stripped === entry.text) {
|
||||
return item;
|
||||
}
|
||||
@@ -43,7 +40,7 @@ export function stripEnvelopeFromMessage(message: unknown): unknown {
|
||||
const next: Record<string, unknown> = { ...entry };
|
||||
|
||||
if (typeof entry.content === "string") {
|
||||
const stripped = stripMessageIdHints(stripEnvelope(stripInboundMetadataBlocks(entry.content)));
|
||||
const stripped = stripMessageIdHints(stripEnvelope(stripInboundMetadata(entry.content)));
|
||||
if (stripped !== entry.content) {
|
||||
next.content = stripped;
|
||||
changed = true;
|
||||
@@ -55,7 +52,7 @@ export function stripEnvelopeFromMessage(message: unknown): unknown {
|
||||
changed = true;
|
||||
}
|
||||
} else if (typeof entry.text === "string") {
|
||||
const stripped = stripMessageIdHints(stripEnvelope(stripInboundMetadataBlocks(entry.text)));
|
||||
const stripped = stripMessageIdHints(stripEnvelope(stripInboundMetadata(entry.text)));
|
||||
if (stripped !== entry.text) {
|
||||
next.text = stripped;
|
||||
changed = true;
|
||||
|
||||
@@ -24,7 +24,9 @@ async function withAudioFixture(
|
||||
await fs.writeFile(tmpPath, Buffer.from("RIFF"));
|
||||
const ctx: MsgContext = { MediaPath: tmpPath, MediaType: "audio/wav" };
|
||||
const media = normalizeMediaAttachments(ctx);
|
||||
const cache = createMediaAttachmentCache(media);
|
||||
const cache = createMediaAttachmentCache(media, {
|
||||
localPathRoots: [path.dirname(tmpPath)],
|
||||
});
|
||||
|
||||
try {
|
||||
await run({ ctx, media, cache });
|
||||
|
||||
@@ -17,7 +17,9 @@ describe("runCapability deepgram provider options", () => {
|
||||
await fs.writeFile(tmpPath, Buffer.from("RIFF"));
|
||||
const ctx: MsgContext = { MediaPath: tmpPath, MediaType: "audio/wav" };
|
||||
const media = normalizeMediaAttachments(ctx);
|
||||
const cache = createMediaAttachmentCache(media);
|
||||
const cache = createMediaAttachmentCache(media, {
|
||||
localPathRoots: [path.dirname(tmpPath)],
|
||||
});
|
||||
|
||||
let seenQuery: Record<string, string | number | boolean> | undefined;
|
||||
let seenBaseUrl: string | undefined;
|
||||
|
||||
@@ -16,20 +16,6 @@ const ENVELOPE_CHANNELS = [
|
||||
];
|
||||
|
||||
const MESSAGE_ID_LINE = /^\s*\[message_id:\s*[^\]]+\]\s*$/i;
|
||||
const INBOUND_METADATA_HEADERS = [
|
||||
"Conversation info (untrusted metadata):",
|
||||
"Sender (untrusted metadata):",
|
||||
"Thread starter (untrusted, for context):",
|
||||
"Replied message (untrusted, for context):",
|
||||
"Forwarded message context (untrusted metadata):",
|
||||
"Chat history since last reply (untrusted, for context):",
|
||||
];
|
||||
const REGEX_ESCAPE_RE = /[.*+?^${}()|[\]\\-]/g;
|
||||
const INBOUND_METADATA_PREFIX_RE = new RegExp(
|
||||
"^\\s*(?:" +
|
||||
INBOUND_METADATA_HEADERS.map((header) => header.replace(REGEX_ESCAPE_RE, "\\$&")).join("|") +
|
||||
")\\r?\\n```json\\r?\\n[\\s\\S]*?\\r?\\n```(?:\\r?\\n)*",
|
||||
);
|
||||
|
||||
function looksLikeEnvelopeHeader(header: string): boolean {
|
||||
if (/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}Z\b/.test(header)) {
|
||||
@@ -61,15 +47,3 @@ export function stripMessageIdHints(text: string): string {
|
||||
const filtered = lines.filter((line) => !MESSAGE_ID_LINE.test(line));
|
||||
return filtered.length === lines.length ? text : filtered.join("\n");
|
||||
}
|
||||
|
||||
export function stripInboundMetadataBlocks(text: string): string {
|
||||
let remaining = text;
|
||||
for (;;) {
|
||||
const match = INBOUND_METADATA_PREFIX_RE.exec(remaining);
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
remaining = remaining.slice(match[0].length).replace(/^\r?\n+/, "");
|
||||
}
|
||||
return remaining.trim();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { formatRawAssistantErrorForUi } from "../agents/pi-embedded-helpers.js";
|
||||
import { stripInboundMetadataBlocks } from "../shared/chat-envelope.js";
|
||||
import { stripInboundMetadata } from "../auto-reply/reply/strip-inbound-meta.js";
|
||||
import { stripAnsi } from "../terminal/ansi.js";
|
||||
import { formatTokenCount } from "../utils/usage-format.js";
|
||||
|
||||
@@ -275,7 +275,7 @@ export function extractTextFromMessage(
|
||||
const text = extractTextBlocks(record.content, opts);
|
||||
if (text) {
|
||||
if (record.role === "user") {
|
||||
return stripInboundMetadataBlocks(text);
|
||||
return stripInboundMetadata(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user