@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, 03:37 UTC

main
ts 39 lines 1.25 KB
Raw
1 import type { ScheduledTaskWebhookEndpoint } from "@t3tools/contracts";
2 import { isLocalLoopbackHost } from "@t3tools/shared/hostClassification";
3 import { mFallback, msg } from "gt-i18n";
4 import type { MFunctionType } from "gt-i18n/types";
5
6 export interface WebhookAddress {
7 readonly address: string;
8 readonly copyable: boolean;
9 readonly note: string | null;
10 }
11
12 export function webhookAddress(
13 endpoint: ScheduledTaskWebhookEndpoint,
14 httpBaseUrl: string | null,
15 resolve: MFunctionType = mFallback,
16 ): WebhookAddress {
17 if (endpoint.url !== null) {
18 return { address: endpoint.url, copyable: true, note: null };
19 }
20 if (httpBaseUrl === null) {
21 return {
22 address: endpoint.path,
23 copyable: false,
24 note: resolve(msg("Link this environment to T3 Connect for a public URL.")),
25 };
26 }
27 const url = new URL(endpoint.path, httpBaseUrl);
28 return {
29 address: url.href,
30 copyable: true,
31 note: isLocalLoopbackHost(url.hostname)
32 ? resolve(msg("Only this computer can call this address. Link T3 Connect for a public URL."))
33 : resolve(
34 msg(
35 "Works wherever this environment's address is reachable, for example over Tailscale or your own proxy. Link T3 Connect for a public URL.",
36 ),
37 ),
38 };
39 }