Import verified AzerothAI snapshot from GitHub
Core tests / core (push) Successful in 9m57s
Full verification / application (push) Failing after 5m16s
Full verification / local-brain (push) Failing after 6m15s
Realm simulation / simulated-live-world (push) Failing after 5m32s
WoW integration lab / real-worldserver (push) Canceled after 17m23s
Core tests / core (push) Successful in 9m57s
Full verification / application (push) Failing after 5m16s
Full verification / local-brain (push) Failing after 6m15s
Realm simulation / simulated-live-world (push) Failing after 5m32s
WoW integration lab / real-worldserver (push) Canceled after 17m23s
Source branch: feature/ai-brain-router Source commit: c2a09e0460465201a58aaab56c71424e9a96405e
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { env } from 'cloudflare:workers';
|
||||
import { z } from 'zod';
|
||||
import { requireAleBridge } from '@/core/ale-auth';
|
||||
import { recordAleEvent } from '@/core/ale-store';
|
||||
import { queueConversationEvent } from '@/core/conversation-store';
|
||||
import { D1Store } from '@/core/store';
|
||||
import { applyAuthoritativeAleEvent,execute } from '@/core/service';
|
||||
import type { RuntimeConfig } from '@/core/types';
|
||||
|
||||
const schema=z.object({
|
||||
kind:z.string().min(1).max(100),
|
||||
payload:z.record(z.unknown()).default({})
|
||||
}).strict();
|
||||
|
||||
const STATEFUL_EVENTS=new Set([
|
||||
'bridge.ready',
|
||||
'player.login',
|
||||
'player.logout',
|
||||
'player.snapshot',
|
||||
'player.first-login',
|
||||
'player.zone',
|
||||
'player.map',
|
||||
'player.level',
|
||||
'player.quest.accept',
|
||||
'player.achievement',
|
||||
'player.close-call',
|
||||
'player.killed-by-creature',
|
||||
'player.repop',
|
||||
'player.resurrect'
|
||||
]);
|
||||
|
||||
export async function POST(request:Request){
|
||||
const config=env as unknown as RuntimeConfig;
|
||||
try{
|
||||
requireAleBridge(request,config);
|
||||
const text=await request.text();if(text.length>40000)return Response.json({error:'Event too large'},{status:413});
|
||||
const body=schema.parse(JSON.parse(text));
|
||||
await recordAleEvent(env.DB!,body.kind,body.payload);
|
||||
|
||||
if((body.kind==='player.chat'||body.kind==='player.whisper')&&body.payload.isBot!==true){
|
||||
await queueConversationEvent(env.DB!,body.kind,body.payload);
|
||||
}
|
||||
|
||||
const store=new D1Store();
|
||||
if(STATEFUL_EVENTS.has(body.kind)){
|
||||
await applyAuthoritativeAleEvent(store,body.kind,body.payload);
|
||||
}
|
||||
|
||||
if(body.kind==='player.zone'&&body.payload.isBot!==true){
|
||||
const zone=String(body.payload.zoneName??body.payload.zone??'').slice(0,120);
|
||||
if(zone)await execute(store,{type:'worldTrigger',kind:'zone-change',zone,playerName:String(body.payload.name??'').slice(0,40),detail:'Authoritative ALE human-player zone event'},config);
|
||||
}
|
||||
|
||||
return Response.json({ok:true});
|
||||
}catch(e){
|
||||
const message=e instanceof Error?e.message:'ALE event failure';
|
||||
return Response.json({error:message},{status:message.startsWith('Unauthorized')?401:400});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user