@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 38 lines 1.45 KB
Raw
1 import { createAttachmentEnvironmentAtoms } from "@t3tools/client-runtime/state/attachments";
2 import type { AtomCommand } from "@t3tools/client-runtime/state/runtime";
3 import {
4 AuthOrchestrationOperateScope,
5 EnvironmentAuthorizationError,
6 type EnvironmentId,
7 } from "@t3tools/contracts";
8 import * as Effect from "effect/Effect";
9 import { msg } from "gt-react-native";
10 import { m } from "../i18n/messages";
11
12 import { connectionAtomRuntime } from "../connection/runtime";
13 import { readEnvironmentScope } from "./session";
14
15 function requireAttachmentWriteAccess<W extends { readonly environmentId: EnvironmentId }, A, E>(
16 command: AtomCommand<W, A, E>,
17 ): AtomCommand<W, A, E | EnvironmentAuthorizationError> {
18 return {
19 ...command,
20 run: (registry, input) =>
21 Effect.suspend((): Effect.Effect<A, E | EnvironmentAuthorizationError> =>
22 readEnvironmentScope(input.environmentId, AuthOrchestrationOperateScope)
23 ? command.run(registry, input)
24 : Effect.fail(
25 new EnvironmentAuthorizationError({
26 message: m(msg("This connection cannot change attachments.")),
27 requiredScope: AuthOrchestrationOperateScope,
28 }),
29 ),
30 ),
31 };
32 }
33
34 const commands = createAttachmentEnvironmentAtoms(connectionAtomRuntime);
35 export const attachmentEnvironment = {
36 createUploadUrl: requireAttachmentWriteAccess(commands.createUploadUrl),
37 remove: requireAttachmentWriteAccess(commands.remove),
38 };