tell me about the threads!

This commit is contained in:
Corey Johnson 2025-07-15 14:54:07 -07:00
parent c0eb5b6bca
commit 80afaef542

View File

@ -3,6 +3,10 @@ import kv from "@workshop/shared/kv"
import { z } from "zod"
import { tool } from "@openai/agents"
import { type TodoJSON, type TodoList, todoListToString } from "@workshop/todo"
import { type UserContext } from "./ai"
import { User } from "discord.js"
import { ensure, zone } from "@workshop/shared/utils"
import { DateTime } from "luxon"
// Recursive Zod schema for TodoJSON
const todoJSONSchema: z.ZodType<TodoJSON> = z.lazy(() =>
@ -25,6 +29,33 @@ const todoListSchema: z.ZodType<TodoList> = z.array(
)
export const tools = [
tool<any, UserContext>({
name: "getDiscordThreadInformation",
description:
"Get information about all threads in the current discord grid, including when it will be archived.",
parameters: z.object({}),
execute: async (args, runContext) => {
try {
const guild = runContext?.context.msg.guild
ensure(guild, "Guild is required for getThreadInformation tool")
const threads = await guild.channels.fetchActiveThreads()
const threadInfo = Array.from(threads.threads.values()).map((thread) => ({
name: thread.name,
archived: thread.archived,
archiveTimestamp: DateTime.fromMillis(thread.archiveTimestamp || 0)
.setZone(zone)
.toISO(),
}))
return threadInfo
} catch (error) {
console.error(`Tool "getThreadInformation" failed for "${args.channelId}":`, error)
return `toolcall failed. ${error}`
}
},
}),
tool({
name: "addReminder",
description: "Add a new reminder to the list",