Files
DemonGatanjieu-Anomalous_Mo…/web/modules/ai_call_lines.js
T
DemonGatanjieuandClaude Opus 5.5 72e0132c14 Keep lines for the AI's chat over the message box
When the AI is not in a call, a run or a question, the AI workbench offers a
line to copy into the AI's chat, picked by what waits for it: the run that
ended, a reply in Anomalous it has not got yet, else "Go on", and a line
that picks the task up in a new chat. The lines under a finished run's step
move there. The Hand to AI sentence no longer names show_panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 17:01:45 +08:00

30 lines
1.8 KiB
JavaScript

/**
* The lines the user can paste into the AI's chat for a task (ui_ai_call.js draws them over the
* message box). Anomalous cannot wake an AI app, so when the AI has stopped the user tells it in a
* word, picked by what waits: a run it was not told has ended (`call_ai`, api/ai_task_runs.py),
* something the user gave it that it has not got yet, or nothing (go on). The last line picks the
* task up in a new chat. None for a task that ended, or one still waiting for its first AI
* (ui_ai_connect.js waitingCard has the line that starts it).
*/
const REPLIES = new Set(['user_message', 'user_marks', 'user_pictures', 'user_toolbox']);
export const NEW_CHAT = 'aiCallNewChat';
/** Whether the user gave the AI something it has not got: words, marks, pictures, materials, an answer, a late gate decision. */
export function unseenReply(task) {
return (task?.steps || []).some(step => (step.kind === 'user' && REPLIES.has(step.tool) && !step.delivered)
|| (step.gate?.timed_out && step.gate.decision && !step.gate.delivered)
|| Object.values(step.answers || {}).some(given => !given.delivered));
}
/** {lead, lines} as locale keys for `task` (the first line is the one to send), or null. */
export function callLines(task) {
const steps = task?.steps || [];
if (!task || task.ended || (task.waiting && steps.every(step => step.kind === 'user'))) return null;
const run = steps.findLast(step => step.tool === 'run_workflow' && step.call_ai);
if (run?.state === 'done') return { lead: 'aiCallDoneLead', lines: ['aiCallDone', 'aiCallAgain', NEW_CHAT] };
if (run?.state === 'error') return { lead: 'aiCallFailedLead', lines: ['aiCallFailed', NEW_CHAT] };
if (unseenReply(task)) return { lead: 'aiCallRepliedLead', lines: ['aiCallReplied', NEW_CHAT] };
return { lead: 'aiCallLead', lines: ['aiCallGoOn', NEW_CHAT] };
}