mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
acf17d6170
100% JSX bot at feature parity with the PoC example: issue/page cards, tables, Chart.js charts, Mermaid diagrams, incident/status/links cards, a confirm_write HITL gate, and /agent + /triage slash commands. Registers examples/slack in the pnpm workspace.
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
/**
|
|
* `read_thread` — a frontend tool that hands the agent the full Slack
|
|
* thread it's replying in. This is what makes "write this incident
|
|
* thread up as a postmortem" possible: the agent calls `read_thread`,
|
|
* gets the actual messages, and summarizes those instead of inventing
|
|
* content.
|
|
*
|
|
* It's a worked example of a `BotTool` that reads conversation history
|
|
* via the platform-agnostic `ctx.thread.getMessages()` capability —
|
|
* the adapter targets the current thread, so no channel/ts plumbing is
|
|
* needed.
|
|
*/
|
|
import { z } from "zod";
|
|
import { defineBotTool } from "@copilotkit/bot";
|
|
|
|
export const readThreadTool = defineBotTool({
|
|
name: "read_thread",
|
|
description:
|
|
"Fetch the messages in the current Slack thread so you can summarize or " +
|
|
"act on them. Call this before turning a conversation into a Linear issue " +
|
|
"or a Notion postmortem — never guess what was said. Returns the messages " +
|
|
"in chronological order with author and timestamp.",
|
|
parameters: z.object({}),
|
|
async handler(_args, { thread }) {
|
|
const messages = await thread.getMessages();
|
|
return {
|
|
count: messages.length,
|
|
messages: messages.map((m) => ({
|
|
user: m.user?.name ?? m.user?.handle ?? (m.isBot ? "bot" : "unknown"),
|
|
text: m.text,
|
|
ts: m.ts,
|
|
})),
|
|
};
|
|
},
|
|
});
|