feature: try to get chat to actually work

This commit is contained in:
Andy Burke 2025-07-11 18:33:32 -07:00
parent 51acbef35f
commit 013e30264f
13 changed files with 1203 additions and 631 deletions

View file

@ -78,7 +78,9 @@ export async function GET(request: Request, meta: Record<string, any>): Promise<
'Cache-Control': 'no-cache, must-revalidate'
};
const results = (await events.all(options)).map((entry) => entry.load());
const results = (await events.all(options))
.map((entry) => entry.load())
.sort((lhs_item, rhs_item) => rhs_item.timestamps.created.localeCompare(lhs_item.timestamps.created));
// long-polling support
if (results.length === 0 && meta.query.wait) {
@ -104,6 +106,7 @@ export async function GET(request: Request, meta: Record<string, any>): Promise<
events.on('create', on_create);
request.signal.addEventListener('abort', () => {
events.off('create', on_create);
reject(new Error('request aborted'));
});
Deno.addSignalListener('SIGINT', () => {
events.off('create', on_create);