@@ -2,7 +2,7 @@ import { db } from "@/lib/db";
22import { mainConfig } from "@/lib/config" ;
33import { eventsTable , type InsertEvent } from "@/lib/schema" ;
44import { createLumaClient } from "@/lib/luma" ;
5- import { and , eq } from "drizzle-orm" ;
5+ import { eq } from "drizzle-orm" ;
66import { createGateway , generateText , tool } from "ai" ;
77import { z } from "zod" ;
88
@@ -71,25 +71,32 @@ function normalizeUpdateData(
7171 if ( typeof eventData . attendeeLimit === "number" ) {
7272 normalized . attendeeLimit = eventData . attendeeLimit ;
7373 }
74- if ( typeof eventData . tagline === "string" ) normalized . tagline = eventData . tagline ;
74+ if ( typeof eventData . tagline === "string" )
75+ normalized . tagline = eventData . tagline ;
7576 if ( typeof eventData . startDate === "string" ) {
7677 normalized . startDate = toDate ( eventData . startDate ) ;
7778 }
7879 if ( typeof eventData . endDate === "string" ) {
7980 normalized . endDate = toDate ( eventData . endDate ) ;
8081 }
81- if ( "lumaEventId" in eventData ) normalized . lumaEventId = eventData . lumaEventId ;
82- if ( typeof eventData . isDraft === "boolean" ) normalized . isDraft = eventData . isDraft ;
82+ if ( "lumaEventId" in eventData )
83+ normalized . lumaEventId = eventData . lumaEventId ;
84+ if ( typeof eventData . isDraft === "boolean" )
85+ normalized . isDraft = eventData . isDraft ;
8386 if ( typeof eventData . isHackathon === "boolean" ) {
8487 normalized . isHackathon = eventData . isHackathon ;
8588 }
8689 if ( typeof eventData . highlightOnLandingPage === "boolean" ) {
8790 normalized . highlightOnLandingPage = eventData . highlightOnLandingPage ;
8891 }
89- if ( "fullAddress" in eventData ) normalized . fullAddress = eventData . fullAddress ;
90- if ( "shortLocation" in eventData ) normalized . shortLocation = eventData . shortLocation ;
91- if ( "streetAddress" in eventData ) normalized . streetAddress = eventData . streetAddress ;
92- if ( "recordingUrl" in eventData ) normalized . recordingUrl = eventData . recordingUrl ;
92+ if ( "fullAddress" in eventData )
93+ normalized . fullAddress = eventData . fullAddress ;
94+ if ( "shortLocation" in eventData )
95+ normalized . shortLocation = eventData . shortLocation ;
96+ if ( "streetAddress" in eventData )
97+ normalized . streetAddress = eventData . streetAddress ;
98+ if ( "recordingUrl" in eventData )
99+ normalized . recordingUrl = eventData . recordingUrl ;
93100
94101 return normalized ;
95102}
@@ -104,17 +111,23 @@ async function getEventBySlug(slug: string) {
104111 return event ?? null ;
105112}
106113
107- async function updateEventBySlug ( input : z . infer < typeof updateEventInputSchema > ) {
114+ async function updateEventBySlug (
115+ input : z . infer < typeof updateEventInputSchema > ,
116+ ) {
108117 const existingEvent = await getEventBySlug ( input . slug ) ;
109118 if ( ! existingEvent ) {
110119 throw new Error ( `Event not found for slug: ${ input . slug } ` ) ;
111120 }
112121
113122 const normalized = normalizeUpdateData ( input . eventData ) ;
123+ if ( Object . keys ( normalized ) . length === 0 ) {
124+ throw new Error ( "No valid fields were provided for update" ) ;
125+ }
126+
114127 const [ updated ] = await db
115128 . update ( eventsTable )
116129 . set ( normalized )
117- . where ( and ( eq ( eventsTable . id , existingEvent . id ) ) )
130+ . where ( eq ( eventsTable . id , existingEvent . id ) )
118131 . returning ( ) ;
119132
120133 return updated ?? null ;
@@ -152,15 +165,21 @@ function buildTools() {
152165export async function runDiscordPromptAgent ( input : {
153166 prompt : string ;
154167} ) : Promise < string > {
168+ const prompt = input . prompt . trim ( ) ;
169+ if ( ! prompt ) {
170+ return "Please provide a prompt." ;
171+ }
172+
155173 const { text } = await generateText ( {
156174 model : getGatewayModel ( ) ,
157175 tools : buildTools ( ) ,
158176 system : `You are the AllThingsWeb Discord ops assistant.
159177You can inspect and update AllThingsWeb event data and fetch Luma event payloads.
160178Use tools whenever the answer depends on current data.
161179Before updating event data, confirm intent from the user message and summarize what changed.
180+ If user intent is ambiguous, ask a clarifying question instead of calling update tools.
162181Be concise and action-oriented.` ,
163- prompt : input . prompt ,
182+ prompt,
164183 } ) ;
165184
166185 return text . trim ( ) ;
0 commit comments