Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

peerPairingCode.ts

24 lines1.0 KB

1import { createPeerPairingCodeCommand } from "@t3tools/client-runtime/state/peerPairingCode";
2import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
3import type { AuthMcpClientAccess, EnvironmentId } from "@t3tools/contracts";
4import * as Result from "effect/Result";
5​
6import { connectionAtomRuntime } from "../connection/runtime";
7import { appAtomRegistry } from "./atom-registry";
8​
9const mintPairingCode = createPeerPairingCodeCommand(connectionAtomRuntime);
10​
11/**
12 * A fresh pairing code minted on `environmentId` with this client's session
13 * there, for linking with `access`. Fails with `PeerPairingCodeError` when the
14 * session may not create one.
15 */
16export async function mintPairingCodeOn(
17 environmentId: EnvironmentId,
18 access: AuthMcpClientAccess,
19): Promise<Result.Result<string, unknown>> {
20 const result = await mintPairingCode.run(appAtomRegistry, { environmentId, input: access });
21 return result._tag === "Success"
22 ? Result.succeed(result.value)
23 : Result.fail(squashAtomCommandFailure(result));