@@ -21,6 +21,7 @@ const path = require("path");
2121const fs = require ( "fs" ) ;
2222const providers = require ( "./providers/index" ) ;
2323const catalog = require ( "./providers/catalog" ) ;
24+ const { SESSION_EXPIRED_MESSAGE } = require ( "./providers/session" ) ;
2425const { AGENT_GROUPS , AGENTS , AGENT_BY_ID } = require ( "./sketch/agentCatalog" ) ;
2526const graph = require ( "./sketch/graph" ) ;
2627const pricing = require ( "./sketch/pricing" ) ;
@@ -458,6 +459,24 @@ async function loadWorkspacePatchContext() {
458459 ) ;
459460}
460461
462+ /**
463+ * Why prepProviderRequest refused, as this panel says it. An ended LevelCode Cloud session is not a
464+ * missing key, and not a provider that is "not ready": it gets the sentence chat and the agent send
465+ * for it, so the user goes to sign in instead of hunting for a key they never needed. Any other
466+ * reason keeps the caller's wording (`otherwise`).
467+ * @param {{reason?:string, label?:string} } req
468+ * @param {string } otherwise
469+ */
470+ function notReadyMessage ( req , otherwise ) {
471+ if ( req . reason === "signedOut" ) {
472+ return SESSION_EXPIRED_MESSAGE ;
473+ }
474+ if ( req . reason === "key" ) {
475+ return "No API key set for " + req . label + "." ;
476+ }
477+ return otherwise ;
478+ }
479+
461480// ---- the runner -------------------------------------------------------------------------------
462481/** @param {{sketch:any, deps:any} } o deps = { prepProviderRequest } from extension.js */
463482async function runSketch ( o ) {
@@ -497,10 +516,10 @@ async function runSketch(o) {
497516 clearSlot ( ) ;
498517 post ( {
499518 type : "runError" ,
500- message :
501- req . reason === "key"
502- ? "No API key set for " + req . label + "."
503- : "Provider not ready (" + ( req . reason || "unknown" ) + ")." ,
519+ message : notReadyMessage (
520+ req ,
521+ "Provider not ready ( " + ( req . reason || "unknown" ) + ")." ,
522+ ) ,
504523 } ) ;
505524 return ;
506525 }
@@ -745,10 +764,7 @@ async function boardCommand(o) {
745764 if ( ! req . ok ) {
746765 post ( {
747766 type : "uiError" ,
748- message :
749- req . reason === "key"
750- ? "No API key set for " + req . label + "."
751- : "Provider not ready." ,
767+ message : notReadyMessage ( req , "Provider not ready." ) ,
752768 } ) ;
753769 return ;
754770 }
@@ -923,10 +939,7 @@ async function generateFlow(o) {
923939 if ( ! req . ok ) {
924940 post ( {
925941 type : "uiError" ,
926- message :
927- req . reason === "key"
928- ? "No API key set for " + req . label + "."
929- : "Provider not ready." ,
942+ message : notReadyMessage ( req , "Provider not ready." ) ,
930943 } ) ;
931944 return ;
932945 }
0 commit comments