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,34 @@
|
||||
import { env } from 'cloudflare:workers';
|
||||
import { D1Store } from '@/core/store';
|
||||
import { execute } from '@/core/service';
|
||||
import { runLiveAutonomyTick } from '@/core/autonomy';
|
||||
import type { RuntimeConfig } from '@/core/types';
|
||||
function requestOriginAllowed(request:Request){
|
||||
const origin=request.headers.get('origin');
|
||||
if(!origin)return true;
|
||||
if(origin===new URL(request.url).origin)return true;
|
||||
const proto=(request.headers.get('x-forwarded-proto')??'').split(',')[0]?.trim().toLowerCase();
|
||||
const host=(request.headers.get('x-forwarded-host')??request.headers.get('host')??'').split(',')[0]?.trim();
|
||||
if((proto==='http'||proto==='https')&&host&&origin===`${proto}://${host}`)return true;
|
||||
return false;
|
||||
}
|
||||
export async function POST(request:Request){
|
||||
if(!requestOriginAllowed(request))return Response.json({error:'Cross-origin action rejected'},{status:403});
|
||||
try{
|
||||
const text=await request.text();
|
||||
if(text.length>16000)return Response.json({error:'Request too large'},{status:413});
|
||||
const body=JSON.parse(text);
|
||||
const store=new D1Store();
|
||||
if(body?.type==='think'&&typeof body.botId==='string'){
|
||||
const state=await store.load();
|
||||
const bot=state.bots.find(b=>b.id===body.botId);
|
||||
if(bot?.autonomy?.managed){
|
||||
const result=await runLiveAutonomyTick(store,env.DB!,env as unknown as RuntimeConfig,{forceBotId:bot.id});
|
||||
if(!result.ran)throw new Error(result.reason);
|
||||
return Response.json(result);
|
||||
}
|
||||
}
|
||||
return Response.json(await execute(store,body,env as unknown as RuntimeConfig));
|
||||
}
|
||||
catch(e){const message=e instanceof Error?e.message:'Action failed';return Response.json({error:message},{status:400});}
|
||||
}
|
||||
Reference in New Issue
Block a user