@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 29 lines 1.08 KB
Raw
1 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 import { Atom } from "effect/reactivity";
3 import { appAtomRegistry } from "./atom-registry";
4
5 export function questionAttachmentDraftPrefix(
6 environmentId: EnvironmentId,
7 threadId: ThreadId,
8 ): string {
9 return `${environmentId}:question-${encodeURIComponent(JSON.stringify(threadId))}-`;
10 }
11 export function questionAttachmentDraftKey(
12 environmentId: EnvironmentId,
13 threadId: ThreadId,
14 requestId: string,
15 questionId: string,
16 ): string {
17 return `${questionAttachmentDraftPrefix(environmentId, threadId)}${encodeURIComponent(JSON.stringify([requestId, questionId]))}`;
18 }
19 export const questionAttachmentPreparationAtom = Atom.make<Record<string, number>>({}).pipe(
20 Atom.keepAlive,
21 );
22 export function changeQuestionAttachmentPreparation(key: string, delta: number): void {
23 const counts = appAtomRegistry.get(questionAttachmentPreparationAtom);
24 if (delta < 0 && !(key in counts)) return;
25 appAtomRegistry.set(questionAttachmentPreparationAtom, {
26 ...counts,
27 [key]: Math.max(0, (counts[key] ?? 0) + delta),
28 });
29 }