The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { mFallback, msg } from "gt-i18n"; |
| 2 | import type { MFunctionType } from "gt-i18n/types"; |
| 3 | |
| 4 | import { |
| 5 | type LinkedPrompt, |
| 6 | type NewThreadLink, |
| 7 | parseNewThreadLink as parseNewThreadLinkWith, |
| 8 | parseThreadLinkPrompt as parseThreadLinkPromptWith, |
| 9 | PROMPT_LINK_MAX_PROMPT_LENGTH, |
| 10 | type PromptLinkError, |
| 11 | type PromptLinkResult, |
| 12 | } from "./promptLinks.ts"; |
| 13 | |
| 14 | function promptLinkErrorMessage(error: PromptLinkError, resolve: MFunctionType): string { |
| 15 | switch (error) { |
| 16 | case "prompt-too-long": |
| 17 | return resolve( |
| 18 | msg("This prompt is longer than {maxLength} characters, so T3 Code did not open it.", { |
| 19 | maxLength: PROMPT_LINK_MAX_PROMPT_LENGTH.toLocaleString("en-US"), |
| 20 | }), |
| 21 | ); |
| 22 | case "prompt-only-hidden": |
| 23 | return resolve( |
| 24 | msg( |
| 25 | "This prompt had only hidden characters, so it may be malicious. T3 Code did not open it.", |
| 26 | ), |
| 27 | ); |
| 28 | case "unreadable-pull-request": |
| 29 | return resolve(msg("This link names a pull request T3 Code cannot read.")); |
| 30 | case "missing-prompt": |
| 31 | return resolve(msg("This link has no prompt.")); |
| 32 | case "unreadable-repository": |
| 33 | return resolve(msg("This link names a repository T3 Code cannot read.")); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** @public */ |
| 38 | export function parseNewThreadLink( |
| 39 | search: string, |
| 40 | resolve: MFunctionType = mFallback, |
| 41 | ): PromptLinkResult<NewThreadLink> { |
| 42 | return parseNewThreadLinkWith(search, (error) => promptLinkErrorMessage(error, resolve)); |
| 43 | } |
| 44 | |
| 45 | /** @public */ |
| 46 | export function parseThreadLinkPrompt( |
| 47 | search: string, |
| 48 | resolve: MFunctionType = mFallback, |
| 49 | ): PromptLinkResult<LinkedPrompt | null> { |
| 50 | return parseThreadLinkPromptWith(search, (error) => promptLinkErrorMessage(error, resolve)); |
| 51 | } |