The best way to control Claude Code, Codex and more from any computer or phone

main
ts 43 lines 1.61 KB
Raw
1 import { thrownErrorMessage } from "@t3tools/client-runtime/errors";
2 import type { ThreadReferenceCopyTarget } from "@t3tools/client-runtime/thread-reference";
3 import {
4 COMPOSER_CONTEXT_CLIPBOARD_MIME,
5 encodeComposerContextFragment,
6 } from "@t3tools/shared/composerContextClipboard";
7 import { msg } from "gt-react";
8
9 import { stackedThreadToast, toastManager } from "../components/ui/toast";
10 import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
11 import { m } from "../i18n/messages";
12
13 export async function copyThreadReference(target: ThreadReferenceCopyTarget): Promise<void> {
14 const fragment = target.fragment ? encodeComposerContextFragment(target.fragment) : null;
15 try {
16 await writeTextToClipboard(
17 target.value,
18 target.kind === "pull-request"
19 ? {
20 target: target.clipboardTarget,
21 unavailableMessage: msg(
22 "Clipboard API is unavailable while copying pull request link.",
23 ),
24 failureMessage: msg("Failed to copy pull request link to the clipboard."),
25 }
26 : {
27 target: target.clipboardTarget,
28 unavailableMessage: msg("Clipboard API is unavailable while copying thread."),
29 failureMessage: msg("Failed to copy thread to the clipboard."),
30 },
31 fragment ? { [COMPOSER_CONTEXT_CLIPBOARD_MIME]: fragment } : undefined,
32 );
33 } catch (error) {
34 console.error(error);
35 toastManager.add(
36 stackedThreadToast({
37 type: "error",
38 title: target.failureTitle,
39 description: thrownErrorMessage(error, m) ?? m(msg("An error occurred.")),
40 }),
41 );
42 }
43 }