119
1201. When a new message is posted in a configured Slack channel (ie. #bugs, or #support), Slack sends an event to this Val
1212. The val makes an OpenAI call to determine if the message is a bug
1223. If it is, then it searches GitHub for semantically related open issues with a separate OpenAI call
1234. It posts a comment in the Slack thread with links to related GitHub issues, with a "Relevance Score"
124
856
857export default async function(req: Request) {
858 const { OpenAI } = await import("https://esm.town/v/std/openai");
859 const { PDFExtract } = await import("npm:pdf.js-extract");
860
870 const action = url.searchParams.get("action");
871 const sourceUrl = import.meta.url.replace("esm.town", "val.town");
872 const openai = new OpenAI();
873 const MAX_TEXT_SUGGEST = 20000;
874 const MAX_TEXT_ANALYZE = 30000;
899 agentName: string,
900 ): Promise<object> {
901 log.push({ agent: agentName, type: "step", message: `Calling OpenAI gpt-4o...` });
902 try {
903 const response = await openai.chat.completions.create({
904 model: "gpt-4o",
905 messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3// --- Agent Communication Protocol (ACP) & Types --- //
122
123/**
124 * Agent 6: Synthesizes the first draft. (REAL OpenAI Call)
125 */
126async function leadWriterAgent(
131 revisionFeedback?: string,
132): Promise<ACP> {
133 console.log("AGENT: Lead Writer Agent running (calling OpenAI)...");
134 const openai = new OpenAI();
135
136 let userMessage = `
149
150 try {
151 const response = await openai.chat.completions.create({
152 model: "gpt-4o",
153 messages: [
162 });
163 const draft = response.choices?.[0]?.message?.content;
164 if (!draft) throw new Error("OpenAI returned empty content.");
165 return createAcp("lead_writer_agent", "SUCCESS", draft, "text/plain");
166 } catch (e) {
167 console.error("OpenAI API Error:", e);
168 return {
169 ...createAcp("lead_writer_agent", "FAILURE", null),
93Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
94
95### OpenAI
96
97```ts
98import { OpenAI } from "https://esm.town/v/std/openai";
99const openai = new OpenAI();
100const completion = await openai.chat.completions.create({
101 messages: [
102 { role: "user", content: "Say hello in a creative way" },