@@ -49,7 +49,13 @@ const TurnCompleted = Schema.Struct({
4949 sessionId : Schema . String ,
5050 turnId : Schema . String ,
5151 terminal : Schema . String ,
52- error : Schema . optionalKey ( Schema . Struct ( { message : Schema . String } ) ) ,
52+ error : Schema . optionalKey (
53+ Schema . Struct ( {
54+ kind : Schema . optionalKey ( Schema . String ) ,
55+ message : Schema . String ,
56+ quota : Schema . optionalKey ( Schema . Unknown ) ,
57+ } ) ,
58+ ) ,
5359} ) ;
5460const ApprovalRequested = Schema . Struct ( {
5561 sessionId : Schema . String ,
@@ -72,7 +78,29 @@ const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
7278const decodeJson = Schema . decodeEffect ( Schema . fromJsonString ( Schema . Unknown ) ) ;
7379
7480type Operation = keyof ProviderTextGeneration ;
75- class MuseTurnFailure extends Error { }
81+ type TurnError = NonNullable < ( typeof TurnCompleted . Type ) [ "error" ] > ;
82+ class MuseTurnFailure extends Error {
83+ readonly turnError : TurnError ;
84+ constructor ( turnError : TurnError ) {
85+ super ( turnError . message ) ;
86+ this . turnError = turnError ;
87+ }
88+ }
89+
90+ function museFailureDetail ( cause : unknown ) : string {
91+ const error =
92+ Cause . isUnknownError ( cause ) && cause . cause instanceof MuseTurnFailure
93+ ? cause . cause . turnError
94+ : undefined ;
95+ // Muse sends `quota` only for quota exhaustion, which it still labels `modelError`.
96+ if ( error ?. quota !== undefined )
97+ return "Muse Code usage limit reached. Try again after it resets." ;
98+ if ( error ?. kind === "authRequired" )
99+ return "Muse Code is not signed in. Run `muse login` on this T3 server host." ;
100+ if ( error ?. kind === "modelError" )
101+ return "Muse Code's model request failed. Try again or choose another Muse model." ;
102+ return "Muse Code text generation failed. Check Muse login and availability on this T3 server host." ;
103+ }
76104
77105async function generateMuseText (
78106 host : MuseSdkHost ,
@@ -140,7 +168,7 @@ async function generateMuseText(
140168 } else {
141169 rejectCompletion (
142170 completed . error
143- ? new MuseTurnFailure ( completed . error . message )
171+ ? new MuseTurnFailure ( completed . error )
144172 : new Error ( `Muse turn ${ completed . terminal } .` ) ,
145173 ) ;
146174 }
@@ -270,10 +298,7 @@ export const makeMuseTextGeneration = Effect.fn("makeMuseTextGeneration")(functi
270298 ( cause ) =>
271299 new TextGenerationError ( {
272300 operation,
273- detail :
274- Cause . isUnknownError ( cause ) && cause . cause instanceof MuseTurnFailure
275- ? `Muse Code text generation failed: ${ cause . cause . message } `
276- : "Muse Code text generation failed. Check Muse login and availability on this T3 server host." ,
301+ detail : museFailureDetail ( cause ) ,
277302 cause,
278303 } ) ,
279304 ) ,
0 commit comments