Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions drizzle/0002_perfect_sentinel.sql

This file was deleted.

311 changes: 0 additions & 311 deletions drizzle/meta/0002_snapshot.json

This file was deleted.

7 changes: 0 additions & 7 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
"when": 1777702532377,
"tag": "0001_futuristic_wendigo",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1778123408706,
"tag": "0002_perfect_sentinel",
"breakpoints": true
}
]
}
5 changes: 3 additions & 2 deletions src/agents/inbound-engagement.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, it, expect, mock, beforeAll } from "bun:test";
import { isReplySafe } from "./safety.js";

const mockXai = mock((modelId: string) => ({ id: modelId }));
const mockGenerateObject = mock(async () => ({
Expand All @@ -25,9 +24,11 @@ type Mention = {
};

let runInboundEngagementAgent: (mention: Mention) => Promise<unknown>;
let isReplySafe: (content: string) => boolean;

beforeAll(async () => {
({ runInboundEngagementAgent } = await import("./inbound-engagement.js"));
({ runInboundEngagementAgent, isReplySafe } =
await import("./inbound-engagement.js"));
});

describe("runInboundEngagementAgent", () => {
Expand Down
15 changes: 14 additions & 1 deletion src/agents/inbound-engagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { generateObject } from "ai";
import { xai } from "@ai-sdk/xai";
import { z } from "zod";
import type { ThreadNode } from "../x/index.js";
import { sanitizeUntrusted, isReplySafe } from "./safety.js";

const SYSTEM = `
You handle real-time engagement for an AI engineer's X account. When someone mentions the account, you make two independent decisions: whether to like, and whether to reply.
Expand Down Expand Up @@ -87,6 +86,20 @@ const inboundEngagementSchema = z.object({

type InboundEngagementDecision = z.infer<typeof inboundEngagementSchema>;

function sanitizeUntrusted(s: string): string {
return s.replace(/[\x00-\x1f\x7f]/g, " ").replace(/<\/?untrusted>/gi, "");
}

const AI_DISCLOSURE_PATTERNS: RegExp[] = [
/\bI(?:'m| am| was| have been| being)\s+(?:an?\s+)?(?:AI|bot|chatbot|language model|automated|assistant|LLM|machine|AGI)\b/i,
/\bI(?:'m| am)\s+(?:powered by|built (?:on|with)|running on|trained by)\b/i,
/\bas an?\s+(?:AI|language model|chatbot|machine learning|automated)\b/i,
];

export function isReplySafe(content: string): boolean {
return !AI_DISCLOSURE_PATTERNS.some((p) => p.test(content));
}

function buildUserMessage(mention: {
authorHandle: string;
text: string;
Expand Down
Loading
Loading