@@ -65,23 +65,26 @@ export function cursorUsageResponseToLimits(
6565
6666const ExchangedAccessToken = Schema . Struct ( { accessToken : Schema . NonEmptyString } ) ;
6767
68- const requestUsage = ( endpoint : string , token : string , clientType : "cli" | "sdk" ) =>
69- Effect . gen ( function * ( ) {
70- const client = yield * HttpClient . HttpClient ;
71- const response = yield * client . execute (
72- HttpClientRequest . post ( `${ endpoint } /aiserver.v1.DashboardService/GetCurrentPeriodUsage` ) . pipe (
73- HttpClientRequest . bearerToken ( token ) ,
74- HttpClientRequest . setHeaders ( {
75- "connect-protocol-version" : "1" ,
76- "x-cursor-client-type" : clientType ,
77- } ) ,
78- HttpClientRequest . bodyJsonUnsafe ( { } ) ,
79- ) ,
80- ) ;
81- return yield * HttpClientResponse . schemaBodyJson ( CursorUsageResponse ) (
82- yield * HttpClientResponse . filterStatusOk ( response ) ,
83- ) ;
84- } ) ;
68+ const requestUsage = Effect . fn ( "CursorUsageLimits.requestUsage" ) ( function * (
69+ endpoint : string ,
70+ token : string ,
71+ clientType : "cli" | "sdk" ,
72+ ) {
73+ const client = yield * HttpClient . HttpClient ;
74+ const response = yield * client . execute (
75+ HttpClientRequest . post ( `${ endpoint } /aiserver.v1.DashboardService/GetCurrentPeriodUsage` ) . pipe (
76+ HttpClientRequest . bearerToken ( token ) ,
77+ HttpClientRequest . setHeaders ( {
78+ "connect-protocol-version" : "1" ,
79+ "x-cursor-client-type" : clientType ,
80+ } ) ,
81+ HttpClientRequest . bodyJsonUnsafe ( { } ) ,
82+ ) ,
83+ ) ;
84+ return yield * HttpClientResponse . schemaBodyJson ( CursorUsageResponse ) (
85+ yield * HttpClientResponse . filterStatusOk ( response ) ,
86+ ) ;
87+ } ) ;
8588
8689const signInAgain = ( checkedAt : string ) =>
8790 makeUnavailableUsageLimits ( {
@@ -94,8 +97,8 @@ const signInAgain = (checkedAt: string) =>
9497 * The stored browser login is a user API key, which the dashboard rejects as a bearer. Like
9598 * `@cursor/sdk`, exchange it for a short-lived access token at the login's own backend first.
9699 */
97- const readStoredLoginUsage = ( login : CursorStoredLogin , checkedAt : string ) =>
98- Effect . gen ( function * ( ) {
100+ const readStoredLoginUsage = Effect . fn ( "CursorUsageLimits.readStoredLoginUsage" ) (
101+ function * ( login : CursorStoredLogin , checkedAt : string ) {
99102 if ( login . status === "expired" ) return signInAgain ( checkedAt ) ;
100103 const endpoint = yield * Effect . try ( ( ) => {
101104 const url = new URL ( login . backendUrl ) ;
@@ -119,10 +122,10 @@ const readStoredLoginUsage = (login: CursorStoredLogin, checkedAt: string) =>
119122 yield * requestUsage ( endpoint , accessToken , "sdk" ) ,
120123 checkedAt ,
121124 ) ;
122- } ) . pipe (
123- // A redirect would carry the user's key to another host.
124- Effect . provideService ( FetchHttpClient . RequestInit , { redirect : "error" } ) ,
125- ) ;
125+ } ,
126+ // A redirect would carry the user's key to another host.
127+ Effect . provideService ( FetchHttpClient . RequestInit , { redirect : "error" } ) ,
128+ ) ;
126129
127130export const readCursorUsageLimits = Effect . fn ( "readCursorUsageLimits" ) ( function * (
128131 settings : Pick < CursorSettings , "apiEndpoint" > ,
0 commit comments