diff --git a/packages/spike/src/tools.ts b/packages/spike/src/tools.ts index e9a3083..a70ae01 100644 --- a/packages/spike/src/tools.ts +++ b/packages/spike/src/tools.ts @@ -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 = z.lazy(() => @@ -25,6 +29,33 @@ const todoListSchema: z.ZodType = z.array( ) export const tools = [ + tool({ + 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",