Skip to content

Commit 66c8cec

Browse files
t3dotggclaude
andcommitted
feat(relay): T3 Chat Pro links get 10 tunnels and Premier 100
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 61efbfd commit 66c8cec

6 files changed

Lines changed: 40 additions & 28 deletions

File tree

‎apps/web/src/components/clerk/T3ChatUserProfilePage.tsx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
isAtomCommandInterrupted,
44
squashAtomCommandFailure,
55
} from "@t3tools/client-runtime/state/runtime";
6-
import { T3CHAT_PREMIER_TUNNEL_LIMIT, type RelayT3ChatLink } from "@t3tools/contracts/relay";
6+
import { T3CHAT_PLAN_TUNNEL_LIMITS, type RelayT3ChatLink } from "@t3tools/contracts/relay";
77
import { MessageSquareIcon } from "lucide-react";
88
import { useState } from "react";
99

@@ -23,9 +23,14 @@ import {
2323
} from "./ClerkUserProfilePage";
2424

2525
function planLabel(link: RelayT3ChatLink): string {
26-
return link.plan === "premier"
27-
? `Premier · up to ${T3CHAT_PREMIER_TUNNEL_LIMIT} tunnels`
28-
: "Upgrade to Premier on T3 Chat for more tunnels";
26+
switch (link.plan) {
27+
case "premier":
28+
return `Premier · up to ${T3CHAT_PLAN_TUNNEL_LIMITS.premier} tunnels`;
29+
case "pro":
30+
return `Pro · up to ${T3CHAT_PLAN_TUNNEL_LIMITS.pro} tunnels, or ${T3CHAT_PLAN_TUNNEL_LIMITS.premier} with Premier`;
31+
case "free":
32+
return "Upgrade on T3 Chat for more tunnels";
33+
}
2934
}
3035

3136
function reportFailure(title: string, cause: unknown) {
@@ -45,7 +50,7 @@ function reportFailure(title: string, cause: unknown) {
4550
});
4651
}
4752

48-
/** Experimental: links a T3 Chat account so Premier subscribers get more tunnels. */
53+
/** Experimental: links a T3 Chat account so paid subscribers get more tunnels. */
4954
export function T3ChatUserProfilePage() {
5055
const linkState = useManagedRelayT3ChatLink();
5156
const createLinkRequest = useAtomCommand(createManagedRelayT3ChatLinkRequestCommand, {
@@ -92,7 +97,7 @@ export function T3ChatUserProfilePage() {
9297
return (
9398
<ClerkUserProfilePage
9499
title="T3 Chat"
95-
description={`Experimental. Link a T3 Chat Premier account to use up to ${T3CHAT_PREMIER_TUNNEL_LIMIT} T3 Connect tunnels.`}
100+
description={`Experimental. Link a paid T3 Chat account for more T3 Connect tunnels: up to ${T3CHAT_PLAN_TUNNEL_LIMITS.pro} with Pro, ${T3CHAT_PLAN_TUNNEL_LIMITS.premier} with Premier.`}
96101
action={
97102
<ClerkUserProfileRefreshButton
98103
disabled={pending !== null}

‎docs/internals/t3-connect.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ and clients keep their bindings. Every mutation on an allocation bumps its
131131
`generation`, and deletion locks the row at the generation it claimed, so a
132132
host that reconnects mid-sweep wins.
133133

134-
## T3 Chat Premier raises the tunnel cap (experimental)
134+
## A paid T3 Chat plan raises the tunnel cap (experimental)
135135

136136
T3 Chat uses WorkOS, not Clerk, so the two accounts are linked by consent
137137
rather than by a shared identity. The relay and T3 Chat share one secret
@@ -142,7 +142,8 @@ plan, so the relay keeps no copy. It asks T3 Chat only when an account reaches
142142
its normal cap for a new environment, and any failure keeps the normal cap.
143143
An environment that already holds a counted slot restarts without asking, so a
144144
downgrade or a T3 Chat outage only blocks new environments. A manual override
145-
row replaces the default for new environments, and Premier does not raise it
145+
row replaces the default for new environments, and a T3 Chat plan does not
146+
raise it
146147
([limits](../../infra/relay/src/environments/ManagedTunnelLimits.ts)).
147148

148149
## The relay client follows the server's pin

‎infra/relay/src/environments/ManagedTunnelLimits.test.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,22 @@ describe("ManagedTunnelLimits", () => {
8484
}),
8585
);
8686

87-
it.effect("raises the cap for a linked T3 Chat Premier account", () =>
87+
it.effect("raises the cap to the linked T3 Chat plan's limit", () =>
8888
Effect.gen(function* () {
89-
yield* ensureCapacity({ activeTunnels: 3, plan: "premier" });
90-
yield* ensureCapacity({ activeTunnels: 99, plan: "premier" });
91-
const error = yield* Effect.flip(ensureCapacity({ activeTunnels: 100, plan: "premier" }));
92-
expect(error).toMatchObject({ _tag: "ManagedTunnelLimitExceeded", maxTunnels: 100 });
89+
for (const [plan, limit] of [
90+
["pro", 10],
91+
["premier", 100],
92+
] as const) {
93+
yield* ensureCapacity({ activeTunnels: limit - 1, plan });
94+
const error = yield* Effect.flip(ensureCapacity({ activeTunnels: limit, plan }));
95+
expect(error).toMatchObject({ _tag: "ManagedTunnelLimitExceeded", maxTunnels: limit });
96+
}
9397
}),
9498
);
9599

96-
it.effect("keeps the default cap for other plans and failed lookups", () =>
100+
it.effect("keeps the default cap for free plans and failed lookups", () =>
97101
Effect.gen(function* () {
98-
for (const plan of ["pro", "lookup-fails"] as const) {
102+
for (const plan of ["free", "lookup-fails"] as const) {
99103
const error = yield* Effect.flip(ensureCapacity({ activeTunnels: 3, plan }));
100104
expect(error).toMatchObject({ _tag: "ManagedTunnelLimitExceeded", maxTunnels: 3 });
101105
}

‎infra/relay/src/environments/ManagedTunnelLimits.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Context from "effect/Context";
33
import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
55
import * as Schema from "effect/Schema";
6-
import { T3CHAT_PREMIER_TUNNEL_LIMIT } from "@t3tools/contracts/relay";
6+
import { T3CHAT_PLAN_TUNNEL_LIMITS } from "@t3tools/contracts/relay";
77

88
import * as RelayDb from "../db.ts";
99
import {
@@ -57,12 +57,14 @@ const make = Effect.gen(function* () {
5757
const t3Chat = yield* T3ChatAccounts.T3ChatAccounts;
5858

5959
// Asked only at the cap, so most links never call T3 Chat. Any failure keeps the lower cap.
60-
const hasT3ChatPremier = (userId: string) =>
60+
const t3ChatTunnelLimit = (userId: string) =>
6161
t3Chat.getLink({ userId }).pipe(
62-
Effect.map((link) => link?.plan === "premier"),
62+
Effect.map((link) =>
63+
link && link.plan !== "free" ? T3CHAT_PLAN_TUNNEL_LIMITS[link.plan] : 0,
64+
),
6365
Effect.catch((error) =>
6466
Effect.logWarning("T3 Chat plan check failed", { userId, error: error.message }).pipe(
65-
Effect.as(false),
67+
Effect.as(0),
6668
),
6769
),
6870
);
@@ -151,10 +153,10 @@ const make = Effect.gen(function* () {
151153
);
152154
if (existing.length > 0) return;
153155

154-
// A manual override is the exact cap; Premier raises only the default.
156+
// A manual override is the exact cap; a T3 Chat plan raises only the default.
155157
const maxTunnels =
156-
t3Chat.available && overrides.length === 0 && (yield* hasT3ChatPremier(input.userId))
157-
? T3CHAT_PREMIER_TUNNEL_LIMIT
158+
t3Chat.available && overrides.length === 0
159+
? Math.max(baseMaxTunnels, yield* t3ChatTunnelLimit(input.userId))
158160
: baseMaxTunnels;
159161
if (activeTunnels >= maxTunnels) {
160162
return yield* new ManagedTunnelLimitExceeded({

‎packages/client-runtime/src/relay/errorPresentation.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DpopFailureReason } from "@t3tools/contracts";
22
import {
3-
T3CHAT_PREMIER_TUNNEL_LIMIT,
3+
T3CHAT_PLAN_TUNNEL_LIMITS,
44
type RelayEnvironmentStatusResponse,
55
type RelayProtectedError,
66
} from "@t3tools/contracts/relay";
@@ -67,8 +67,8 @@ export function relayProtectedErrorMessage(error: RelayProtectedError): string {
6767
error.provisioningStage ? ` Failed stage: ${error.provisioningStage}.` : ""
6868
}`;
6969
case "RelayEnvironmentLinkLimitExceededError":
70-
return error.maxTunnels < T3CHAT_PREMIER_TUNNEL_LIMIT
71-
? `Relay refused the link: this account already has its maximum of ${error.maxTunnels} managed tunnels. Unlink an environment, or link a T3 Chat Premier account in your T3 Connect account settings on web or desktop to raise the default limit to ${T3CHAT_PREMIER_TUNNEL_LIMIT}.`
70+
return error.maxTunnels < T3CHAT_PLAN_TUNNEL_LIMITS.premier
71+
? `Relay refused the link: this account already has its maximum of ${error.maxTunnels} managed tunnels. Unlink an environment, or link a paid T3 Chat account in your T3 Connect account settings on web or desktop. Pro raises the default limit to ${T3CHAT_PLAN_TUNNEL_LIMITS.pro} and Premier to ${T3CHAT_PLAN_TUNNEL_LIMITS.premier}.`
7272
: `Relay refused the link: this account already has its maximum of ${error.maxTunnels} managed tunnels. Unlink an environment to free one up.`;
7373
case "RelayAgentActivityPublishProofExpiredError":
7474
return "Relay rejected an expired agent activity publish proof.";

‎packages/contracts/src/relay.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,12 +963,12 @@ export const RelayOkResponse = Schema.Struct({
963963
});
964964
export type RelayOkResponse = typeof RelayOkResponse.Type;
965965

966-
// Experimental: a linked T3 Chat Premier account raises the managed tunnel cap.
967-
export const T3CHAT_PREMIER_TUNNEL_LIMIT = 100;
968-
969966
export const RelayT3ChatPlan = Schema.Literals(["free", "pro", "premier"]);
970967
export type RelayT3ChatPlan = typeof RelayT3ChatPlan.Type;
971968

969+
// Experimental: a linked paid T3 Chat plan raises the default managed tunnel cap.
970+
export const T3CHAT_PLAN_TUNNEL_LIMITS = { pro: 10, premier: 100 } as const;
971+
972972
export const RelayT3ChatLink = Schema.Struct({
973973
email: Schema.String,
974974
plan: RelayT3ChatPlan,

0 commit comments

Comments
 (0)