···01import { migrate } from "drizzle-orm/bun-sqlite/migrator";
2import { drizzle } from "drizzle-orm/bun-sqlite";
3import { Database } from "bun:sqlite";
4import { env } from "../env";
5-import { memory_block_entries, memory_blocks } from "./schema";
67const sqlite = new Database(env.DB_PATH);
8const db = drizzle(sqlite);
···1+import { memory_block_entries, memory_blocks } from "./schema";
2import { migrate } from "drizzle-orm/bun-sqlite/migrator";
3import { drizzle } from "drizzle-orm/bun-sqlite";
4import { Database } from "bun:sqlite";
5import { env } from "../env";
067const sqlite = new Database(env.DB_PATH);
8const db = drizzle(sqlite);
+1-1
src/db/schema.ts
···1-import { sql } from "drizzle-orm";
2import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
034export const interactions = sqliteTable("interactions", {
5 id: integer().primaryKey({ autoIncrement: true }),
···01import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2+import { sql } from "drizzle-orm";
34export const interactions = sqliteTable("interactions", {
5 id: integer().primaryKey({ autoIncrement: true }),
+4-5
src/handlers/posts.ts
···1-import { interactions } from "../db/schema";
2-import { type Post } from "@skyware/bot";
3import * as threadUtils from "../utils/thread";
4import modelPrompt from "../model/prompt.txt";
5import { GoogleGenAI } from "@google/genai";
0006import * as tools from "../tools";
7import consola from "consola";
8import { env } from "../env";
9-import db from "../db";
10-import * as c from "../constants";
11-import { isAuthorizedUser, logInteraction } from "../utils/interactions";
1213const logger = consola.withTag("Post Handler");
14
···1+import { isAuthorizedUser, logInteraction } from "../utils/interactions";
02import * as threadUtils from "../utils/thread";
3import modelPrompt from "../model/prompt.txt";
4import { GoogleGenAI } from "@google/genai";
5+import { interactions } from "../db/schema";
6+import { type Post } from "@skyware/bot";
7+import * as c from "../constants";
8import * as tools from "../tools";
9import consola from "consola";
10import { env } from "../env";
0001112const logger = consola.withTag("Post Handler");
13
+21-8
src/index.ts
···1import * as posts from "./handlers/posts";
2import { env } from "./env";
3import bot from "./bot";
4-import { isThreadMuted } from "./utils/thread";
00000000000056-await bot.login({
7- identifier: env.HANDLE,
8- password: env.BSKY_PASSWORD,
9-});
1011-bot.on("reply", posts.handler);
12-bot.on("mention", posts.handler);
13-bot.on("quote", posts.handler);
00
···1import * as posts from "./handlers/posts";
2import { env } from "./env";
3import bot from "./bot";
4+import consola from "consola";
5+6+const logger = consola.withTag("Entrypoint");
7+8+logger.info("Logging in..");
9+10+try {
11+ await bot.login({
12+ identifier: env.HANDLE,
13+ password: env.BSKY_PASSWORD,
14+ });
15+16+ logger.success(`Logged in as @${env.HANDLE} (${env.DID})`);
1718+ bot.on("reply", posts.handler);
19+ bot.on("mention", posts.handler);
20+ bot.on("quote", posts.handler);
02122+ logger.success("Registered events (reply, mention, quote)");
23+} catch (e) {
24+ logger.error("Failure to log-in: ", e);
25+ process.exit(1);
26+}
+3-3
src/tools.ts
src/tools/index.ts
···1-import * as create_blog_post from "./tools/create_blog_post";
2-import * as mute_thread from "./tools/mute_thread";
3-import * as create_post from "./tools/create_post";
4import type { FunctionCall, GenerateContentConfig } from "@google/genai";
0005import type { infer as z_infer } from "zod";
67const validation_mappings = {
···0001import type { FunctionCall, GenerateContentConfig } from "@google/genai";
2+import * as create_blog_post from "./create_blog_post";
3+import * as create_post from "./create_post";
4+import * as mute_thread from "./mute_thread";
5import type { infer as z_infer } from "zod";
67const validation_mappings = {
+3-2
src/tools/create_post.ts
···01import { AtUri } from "@atproto/syntax";
2import { Type } from "@google/genai";
3import { env } from "../env";
4import bot from "../bot";
5import z from "zod";
6-import { exceedsGraphemes, multipartResponse } from "../utils/thread";
78export const definition = {
9 name: "create_post",
10- description: "Creates a new Bluesky post/thread and returns the URL.",
011 parameters: {
12 type: Type.OBJECT,
13 properties: {
···1+import { exceedsGraphemes, multipartResponse } from "../utils/thread";
2import { AtUri } from "@atproto/syntax";
3import { Type } from "@google/genai";
4import { env } from "../env";
5import bot from "../bot";
6import z from "zod";
078export const definition = {
9 name: "create_post",
10+ description:
11+ "Creates a new Bluesky post/thread and returns the URL. Only do this if the user specifically requests a new thread.",
12 parameters: {
13 type: Type.OBJECT,
14 properties: {
+3-3
src/tools/mute_thread.ts
···001import { Type } from "@google/genai";
2import bot from "../bot";
3-import z from "zod";
4import db from "../db";
5-import { muted_threads } from "../db/schema";
6-import { AtUri } from "@atproto/syntax";
78export const definition = {
9 name: "mute_thread",
···1+import { muted_threads } from "../db/schema";
2+import { AtUri } from "@atproto/syntax";
3import { Type } from "@google/genai";
4import bot from "../bot";
05import db from "../db";
6+import z from "zod";
078export const definition = {
9 name: "mute_thread",
+3-3
src/utils/thread.ts
···1import { graphemeLength, Post, PostReference } from "@skyware/bot";
2-import * as yaml from "js-yaml";
3-import bot from "../bot";
4import { muted_threads } from "../db/schema";
05import { eq } from "drizzle-orm";
006import db from "../db";
7-import * as c from "../constants";
89/*
10 Traversal
···1import { graphemeLength, Post, PostReference } from "@skyware/bot";
002import { muted_threads } from "../db/schema";
3+import * as c from "../constants";
4import { eq } from "drizzle-orm";
5+import * as yaml from "js-yaml";
6+import bot from "../bot";
7import db from "../db";
089/*
10 Traversal