# Conflicts: # apps/detail-agent-pi/src/agent.mjs # apps/detail-agent-pi/src/desktop-host.mjs # apps/detail-agent-pi/src/store.mjs # apps/detail-photocraft/apps/photocraft/src/jiansun_backend.rs # apps/detail-photocraft/apps/photocraft/src/jiansun_canvas_workspace.rs # apps/detail-photocraft/crates/ui-egui/src/jiansun.rs # apps/detail-photocraft/crates/ui-egui/src/jiansun/pi_bridge.rs # apps/detail-photocraft/crates/ui-egui/src/jiansun/product_production.rs
24 lines
1.5 KiB
JavaScript
24 lines
1.5 KiB
JavaScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
export async function requestPurpose(host, id) {
|
|
const text = await fs.readFile(path.join(host.store.dir, 'events.jsonl'), 'utf8').catch(error => {if (error.code === 'ENOENT') return ''; throw error;});
|
|
const events = text.split('\n').filter(Boolean).map(line => {try {return JSON.parse(line);} catch {return null;}}).filter(Boolean);
|
|
const index = events.findIndex(event => event.type === 'provider_prepared' && event.id === id && (!event.bindingHash || event.bindingHash === host.store.hash));
|
|
if (index < 0) throw Error('原请求没有当前会话归属记录');
|
|
const event = events[index];
|
|
if (events.some(row=>row.id===id && row.consumption==='discarded_after_cancel')) return {kind:'cancelled',event};
|
|
if (event.purpose === 'compaction') return {kind: 'compaction', event};
|
|
if (['whole-detail-review','whole-detail-worker','product-goal'].includes(event.purpose)) return {kind:event.purpose,event};
|
|
if (event.purpose === 'conversation') return {kind: 'conversation', event};
|
|
// Legacy automatic summaries lack a durable cut-point contract. Recognize
|
|
// their purpose, but never guess a checkpoint from the returned prose.
|
|
let started = -1, finished = -1;
|
|
for (let i = 0; i < index; i++) {
|
|
if (events[i].type === 'automatic_compaction_started') started = i;
|
|
if (events[i].type === 'automatic_compaction_completed') finished = i;
|
|
}
|
|
if (started > finished) return {kind: 'legacy-compaction', event};
|
|
return {kind: 'conversation', event};
|
|
}
|