The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | import * as HttpClient from "effect/http/HttpClient"; |
| 4 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 5 | import * as HttpClientResponse from "effect/http/HttpClientResponse"; |
| 6 | |
| 7 | export const DEFAULT_CURSOR_API_ENDPOINT = "https://api2.cursor.sh"; |
| 8 | |
| 9 | const ApiKeyExchange = Schema.Struct({ accessToken: Schema.NonEmptyString }); |
| 10 | |
| 11 | /** Trades a user API key for the access token Cursor's RPCs accept, as `@cursor/sdk` does. */ |
| 12 | export const exchangeCursorApiKey = Effect.fn("exchangeCursorApiKey")(function* (apiKey: string) { |
| 13 | const client = yield* HttpClient.HttpClient; |
| 14 | const response = yield* client.execute( |
| 15 | HttpClientRequest.post(`${DEFAULT_CURSOR_API_ENDPOINT}/auth/exchange_user_api_key`).pipe( |
| 16 | HttpClientRequest.bearerToken(apiKey), |
| 17 | HttpClientRequest.bodyJsonUnsafe({}), |
| 18 | ), |
| 19 | ); |
| 20 | const { accessToken } = yield* HttpClientResponse.schemaBodyJson(ApiKeyExchange)( |
| 21 | yield* HttpClientResponse.filterStatusOk(response), |
| 22 | ); |
| 23 | return accessToken; |
| 24 | }, Effect.timeout("10 seconds")); |