"You were cut off at the token limit. Continue exactly where you left off — do NOT repeat any text you already produced, just carry on from the last character.",
});
if(onProgress){
onProgress({ turns,output: usage.output});
}
}
return{text: full, usage, stop, turns };
}
/** Resolve the model a node runs on: explicit per-node override → tier default → provider's active model. */
message: "Couldn't turn that into board changes — try rephrasing.",
});
return;
}
post({type: "commandResult", ops });
}
// ---- generate a WHOLE flow from a plain-English description ------------------------------------
constGENERATE_SYSTEM=
"You DESIGN a complete agentic workflow as a DAG for LevelCode Agent Sketch, from a plain-English "+
"description. Return ONLY JSON:\n"+
'{"goal":"<one sentence>","nodes":[{"agent":"<catalog id>","label":"<short unique>","task":"<what THIS agent does in the flow, concretely>"}],"edges":[["<from label>","<to label>"]]}\n\n'+
"Rules:\n"+
"- Use ONLY agent ids from the provided catalog; pick the closest role. For real-world actions use "+
"the CONNECTOR agents (telegram-publisher, email-sender, slack-publisher, webhook-caller, file-writer). "+
"If the flow is periodic/scheduled or event-driven, START with a TRIGGER (scheduler, webhook-trigger) "+
"as the root that feeds the rest.\n"+
"- It MUST be a DAG (acyclic), read left→right by dependency. Parallel work = several nodes in one "+
"stage that all feed a downstream node (e.g. 5 news-collectors → 1 editor).\n"+
"- Every node gets a concrete `task`. Node labels MUST be UNIQUE — if several nodes share a role, "+
"number them (news-1, news-2, …). edges reference these EXACT unique labels (or a node's 1-based index).\n"+
"- Model the user's intent faithfully (collectors → editor → copywriter → approver → publisher, etc.).\n"+
'Return {"goal":"","nodes":[],"edges":[]} only if the request is truly empty.';
/** Extract the flow object from a model reply (tolerates code fences / prose). */