Skip to content
Merged
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: 14 additions & 0 deletions drizzle/0002_perfect_sentinel.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TYPE "public"."outbound_action" AS ENUM('like', 'retweet', 'reply', 'follow');--> statement-breakpoint
CREATE TABLE "outbound_engagement_log" (
"id" serial PRIMARY KEY NOT NULL,
"tweet_id" text NOT NULL,
"author_id" text NOT NULL,
"author_handle" text NOT NULL,
"action" "outbound_action" NOT NULL,
"reply_tweet_id" text,
"error" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "engagement_log" ADD COLUMN "liked" boolean DEFAULT false NOT NULL;--> statement-breakpoint
CREATE UNIQUE INDEX "outbound_uniq" ON "outbound_engagement_log" USING btree ("tweet_id","action");
311 changes: 311 additions & 0 deletions drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
{
"id": "fc47e8c2-6c12-42ee-91b7-59317cbcb3d0",
"prevId": "610da8d0-fffc-4e8c-98d8-e0b7ce03436a",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.engagement_log": {
"name": "engagement_log",
"schema": "",
"columns": {
"tweet_id": {
"name": "tweet_id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"event_type": {
"name": "event_type",
"type": "text",
"primaryKey": false,
"notNull": true
},
"reply_tweet_id": {
"name": "reply_tweet_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "engagement_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'processing'"
},
"liked": {
"name": "liked",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"skip_reason": {
"name": "skip_reason",
"type": "text",
"primaryKey": false,
"notNull": false
},
"error": {
"name": "error",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.outbound_engagement_log": {
"name": "outbound_engagement_log",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"tweet_id": {
"name": "tweet_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"author_id": {
"name": "author_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"author_handle": {
"name": "author_handle",
"type": "text",
"primaryKey": false,
"notNull": true
},
"action": {
"name": "action",
"type": "outbound_action",
"typeSchema": "public",
"primaryKey": false,
"notNull": true
},
"reply_tweet_id": {
"name": "reply_tweet_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"error": {
"name": "error",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"outbound_uniq": {
"name": "outbound_uniq",
"columns": [
{
"expression": "tweet_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "action",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.scheduled_posts": {
"name": "scheduled_posts",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"content": {
"name": "content",
"type": "text",
"primaryKey": false,
"notNull": true
},
"type": {
"name": "type",
"type": "post_type",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'single'"
},
"scheduled_at": {
"name": "scheduled_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"slot": {
"name": "slot",
"type": "time_slot",
"typeSchema": "public",
"primaryKey": false,
"notNull": true
},
"rationale": {
"name": "rationale",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "''"
},
"status": {
"name": "status",
"type": "post_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'pending'"
},
"tweet_id": {
"name": "tweet_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"tweet_url": {
"name": "tweet_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"error": {
"name": "error",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"published_at": {
"name": "published_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {
"public.engagement_status": {
"name": "engagement_status",
"schema": "public",
"values": [
"processing",
"replied",
"skipped",
"failed"
]
},
"public.outbound_action": {
"name": "outbound_action",
"schema": "public",
"values": [
"like",
"retweet",
"reply",
"follow"
]
},
"public.post_status": {
"name": "post_status",
"schema": "public",
"values": [
"pending",
"processing",
"published",
"failed"
]
},
"public.post_type": {
"name": "post_type",
"schema": "public",
"values": [
"single",
"thread"
]
},
"public.time_slot": {
"name": "time_slot",
"schema": "public",
"values": [
"morning",
"lunch",
"afternoon",
"evening",
"night"
]
}
},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
7 changes: 7 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1777702532377,
"tag": "0001_futuristic_wendigo",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1778123408706,
"tag": "0002_perfect_sentinel",
"breakpoints": true
}
]
}
5 changes: 2 additions & 3 deletions src/agents/inbound-engagement.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 @@ -24,11 +25,9 @@ type Mention = {
};

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

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

describe("runInboundEngagementAgent", () => {
Expand Down
15 changes: 1 addition & 14 deletions src/agents/inbound-engagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -86,20 +87,6 @@ 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