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 { |
| 2 | createMcpApprovalCodeCommand, |
| 3 | createPeerPairingCodeCommand, |
| 4 | } from "@t3tools/client-runtime/state/peerPairingCode"; |
| 5 | import { runAtomCommand, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
| 6 | import type { |
| 7 | AuthMcpClientAccess, |
| 8 | AuthPairingCredentialResult, |
| 9 | EnvironmentId, |
| 10 | } from "@t3tools/contracts"; |
| 11 | import * as Result from "effect/Result"; |
| 12 | |
| 13 | import { connectionAtomRuntime } from "../connection/runtime"; |
| 14 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 15 | |
| 16 | const mintPairingCode = createPeerPairingCodeCommand(connectionAtomRuntime); |
| 17 | const mintMcpApprovalCode = createMcpApprovalCodeCommand(connectionAtomRuntime); |
| 18 | |
| 19 | /** |
| 20 | * A fresh pairing code minted on `environmentId` with this client's session |
| 21 | * there, for linking with `access`. Fails with `PeerPairingCodeError` when the |
| 22 | * session may not create one. |
| 23 | */ |
| 24 | export async function mintPairingCodeOn( |
| 25 | environmentId: EnvironmentId, |
| 26 | access: AuthMcpClientAccess, |
| 27 | ): Promise<Result.Result<string, unknown>> { |
| 28 | const result = await runAtomCommand( |
| 29 | appAtomRegistry, |
| 30 | mintPairingCode, |
| 31 | { environmentId, input: access }, |
| 32 | { reportFailure: false }, |
| 33 | ); |
| 34 | return result._tag === "Success" |
| 35 | ? Result.succeed(result.value) |
| 36 | : Result.fail(squashAtomCommandFailure(result)); |
| 37 | } |
| 38 | |
| 39 | /** A fresh code on `environmentId` that approves one app's sign-in at `access`. */ |
| 40 | export async function mintMcpApprovalCodeOn( |
| 41 | environmentId: EnvironmentId, |
| 42 | access: AuthMcpClientAccess, |
| 43 | ): Promise<Result.Result<AuthPairingCredentialResult, unknown>> { |
| 44 | const result = await runAtomCommand( |
| 45 | appAtomRegistry, |
| 46 | mintMcpApprovalCode, |
| 47 | { environmentId, input: access }, |
| 48 | { reportFailure: false }, |
| 49 | ); |
| 50 | return result._tag === "Success" |
| 51 | ? Result.succeed(result.value) |
| 52 | : Result.fail(squashAtomCommandFailure(result)); |
| 53 | } |