refactor: remove the billing tier model (P0.1)
The community edition has no monetization (ADR-0001). Remove the tier model (packages/shared/src/tiers.ts), the requireTier middleware and every tier gate, GET/PATCH /api/tier and the trial start, and the Stripe integration, which depends on the tier model. Personal features a tier used to limit are open to everyone: unlimited workspaces and connectors, every embedding provider including LiteLLM, per-workspace costs, Approvals. The workspace session cap is one constant (100). Team and enterprise surfaces are hidden instead of unlocked (team dock zone, Settings Team/Enterprise/Plan tabs, workspace Team tab); cloud sync reports unavailable, as it did for free users. The sidecar ignores the tier keys in config.json but does not delete them: both editions may still share ~/.waggle. Web billing UI is deleted: plan cards, upgrade and trial modals, payment success route, the KVARK sales block, tier 403 handling.
This commit is contained in:
@@ -180,11 +180,10 @@ function deadlined<T>(p: Promise<T>, ms: number, label: string): Promise<T> {
|
||||
* P1b D3 — thrown by `adapter.fetch()` on any non-2xx response (the
|
||||
* chokepoint conversion of ~145 silent-empty getters). Message precedence is
|
||||
* MESSAGE-FIRST (`body.message ?? body.error ?? HTTP <status>`) — matches the
|
||||
* incumbent eraseData/startTrial convention and surfaces the human-readable
|
||||
* reason for `{ error: 'TIER_INSUFFICIENT', message: '…' }`-shaped bodies.
|
||||
* incumbent eraseData convention and surfaces the human-readable reason for
|
||||
* `{ error: '…', message: '…' }`-shaped bodies.
|
||||
* `.status`/`.body` are field-compatible with the pre-existing rich errors
|
||||
* thrown by installSkill/installPack (consumers: CapabilitiesApp
|
||||
* handleInstallError, SkillBuilder onTierError).
|
||||
* thrown by installSkill/installPack.
|
||||
*/
|
||||
export class AdapterHttpError extends Error {
|
||||
readonly status: number;
|
||||
@@ -731,7 +730,7 @@ class LocalAdapter {
|
||||
|
||||
/**
|
||||
* P1b D3-2: the THROWING request path — rejects with AdapterHttpError on any
|
||||
* non-2xx response (after the 403 tier dispatch). This is the chokepoint
|
||||
* non-2xx response. This is the chokepoint
|
||||
* conversion of the failure-as-data class: ~145 getters that previously
|
||||
* parsed error bodies as data now surface failures to their callers.
|
||||
* Callers that need raw status/body semantics use `fetchRaw()`.
|
||||
@@ -747,8 +746,8 @@ class LocalAdapter {
|
||||
|
||||
/**
|
||||
* P1b D3: today's pre-conversion semantics — never throws on HTTP status
|
||||
* (still defers on the gate, attaches the token, runs the 401-refresh-retry
|
||||
* and dispatches the 403 tier event). For the two caller classes whose
|
||||
* (still defers on the gate, attaches the token and runs the 401-refresh-retry).
|
||||
* For the two caller classes whose
|
||||
* error-path payload is load-bearing: raw-Response consumers
|
||||
* (installMarketplacePackage) and body-envelope getters (installMcp et al,
|
||||
* whose 403/422 bodies drive the ApprovalModal security flow).
|
||||
@@ -757,8 +756,8 @@ class LocalAdapter {
|
||||
return this.request(path, init, timeoutMs);
|
||||
}
|
||||
|
||||
/** Shared request core: deferral gate → headers/token → fetch → 403 tier
|
||||
* dispatch → 401 refresh-retry (token-versioned, once per request). */
|
||||
/** Shared request core: deferral gate → headers/token → fetch → 401
|
||||
* refresh-retry (token-versioned, once per request). */
|
||||
private async request(
|
||||
path: string,
|
||||
init?: RequestInit,
|
||||
@@ -803,17 +802,6 @@ class LocalAdapter {
|
||||
headers['X-Waggle-Desktop-Bootstrap'] = this.desktopEndpoint.bootstrapToken;
|
||||
}
|
||||
const res = await fetchWithTimeout(`${this.baseUrl}${path}`, { ...init, headers }, timeoutMs);
|
||||
if (res.status === 403) {
|
||||
const clone = res.clone();
|
||||
try {
|
||||
const body = await clone.json();
|
||||
if (body.error === 'TIER_INSUFFICIENT') {
|
||||
window.dispatchEvent(new CustomEvent('waggle:tier-insufficient', {
|
||||
detail: { required: body.required, actual: body.actual, message: body.message },
|
||||
}));
|
||||
}
|
||||
} catch { /* not JSON — ignore */ }
|
||||
}
|
||||
// P1b D3-3: the session token is per-sidecar-process — it rotates on every
|
||||
// restart. One silent refresh + single retry per request recovers without
|
||||
// a page reload. Token-versioned: if another request's refresh already
|
||||
@@ -1729,8 +1717,7 @@ class LocalAdapter {
|
||||
// Phase-3 fix: this used to send only { name, description }, which the
|
||||
// route rejects (steps is mandatory) — the call could never succeed.
|
||||
// P1b D3: the chokepoint AdapterHttpError carries the same .status/.body
|
||||
// fields the bespoke rich error did (SkillBuilder routes a 403 to the
|
||||
// UpgradeModal tier event via onTierError) — the local !ok block is gone.
|
||||
// fields the bespoke rich error did — the local !ok block is gone.
|
||||
await this.fetch('/api/skills/create', { method: 'POST', body: JSON.stringify(data) });
|
||||
}
|
||||
|
||||
@@ -1743,10 +1730,9 @@ class LocalAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* §D2: run the run-and-grade skill-audit loop (PRO) to mint the "verified"
|
||||
* §D2: run the run-and-grade skill-audit loop to mint the "verified"
|
||||
* badge. Pass a names[] to scope the run to specific skills (keeps each POST
|
||||
* to a few LLM calls). A 403 (FREE/expired tier) throws AdapterHttpError and
|
||||
* is routed to the UpgradeModal by the fetch chokepoint, like createSkill.
|
||||
* to a few LLM calls). A failure throws AdapterHttpError, like createSkill.
|
||||
*/
|
||||
async auditSkills(names?: string[]): Promise<{
|
||||
ok: boolean;
|
||||
@@ -1861,8 +1847,8 @@ class LocalAdapter {
|
||||
* bearer token) — a raw fetch() returns 401 before the session token has
|
||||
* bootstrapped, and the UI was silently caching the empty 401 body as an
|
||||
* empty catalog. The INSTALL variant returns the raw Response (fetchRaw) so
|
||||
* the caller keeps its status-aware handling (403 → UpgradeModal, scan-
|
||||
* blocked toasts). P1b D3: uninstall moved to the THROWING fetch — its only
|
||||
* the caller keeps its status-aware handling (scan-blocked toasts). P1b D3:
|
||||
* uninstall moved to the THROWING fetch — its only
|
||||
* consumer ignored the Response and toasted success unconditionally, so a
|
||||
* failed uninstall rendered as success; throwing routes it to the catch.
|
||||
* search also throws now: its consumers parse the body with no ok check, so
|
||||
@@ -2674,8 +2660,8 @@ class LocalAdapter {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
/** Persist the embedding provider. Throws AdapterHttpError on 403 (tier) /
|
||||
* 409 (env override) / 400 (invalid) — the message carries the reason. */
|
||||
/** Persist the embedding provider. Throws AdapterHttpError on 409 (env
|
||||
* override) / 400 (invalid) — the message carries the reason. */
|
||||
async setEmbeddingProvider(provider: string): Promise<EmbeddingRoutingStatus> {
|
||||
const res = await this.fetch('/api/embedding/provider', {
|
||||
method: 'POST',
|
||||
@@ -2863,7 +2849,7 @@ class LocalAdapter {
|
||||
return unwrapArray(await res.json());
|
||||
}
|
||||
|
||||
/** PRO+ (B5); delegates to the marketplace installer (SecurityGate + audit).
|
||||
/** Delegates to the marketplace installer (SecurityGate + audit).
|
||||
* `force` = reinstall over an existing install; `forceInsecure` = the
|
||||
* audited override for an installer-level HIGH scan block (the block that
|
||||
* actually fires — `force` alone does NOT override it). */
|
||||
@@ -2871,9 +2857,9 @@ class LocalAdapter {
|
||||
installed: boolean; server?: string; status?: string; requiresApproval?: boolean;
|
||||
}> {
|
||||
// P1b D3: fetchRaw — the 403/422 ERROR body is load-bearing: it carries
|
||||
// { error: 'TIER_INSUFFICIENT' } AND the SecurityGate envelope
|
||||
// { requiresApproval, blocked, severity, scanResult } that drives
|
||||
// MCPHubApp's ApprovalModal HIGH-override / CRITICAL-non-overridable flow.
|
||||
// the SecurityGate envelope { requiresApproval, blocked, severity,
|
||||
// scanResult } that drives MCPHubApp's ApprovalModal HIGH-override /
|
||||
// CRITICAL-non-overridable flow.
|
||||
const res = await this.fetchRaw('/api/mcps/install', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ mcpId, ...opts }),
|
||||
@@ -2886,8 +2872,8 @@ class LocalAdapter {
|
||||
env?: Record<string, string>; workspaceId?: string;
|
||||
}): Promise<{ id: string; registered: boolean }> {
|
||||
// P1b D3: fetchRaw — body-envelope getter; AddCustomMcpForm branches on
|
||||
// res.error (incl. the deliberate TIER_INSUFFICIENT inline-suppression)
|
||||
// and renders 400-validation / injection-scan / 409-duplicate reasons.
|
||||
// res.error and renders 400-validation / injection-scan / 409-duplicate
|
||||
// reasons.
|
||||
const res = await this.fetchRaw('/api/mcps', { method: 'POST', body: JSON.stringify(config) });
|
||||
return res.json();
|
||||
}
|
||||
@@ -3012,19 +2998,6 @@ class LocalAdapter {
|
||||
}
|
||||
|
||||
// --- Team ---
|
||||
async teamConnect(serverUrl: string, token: string): Promise<void> {
|
||||
await this.fetch('/api/team/connect', { method: 'POST', body: JSON.stringify({ serverUrl, token }) });
|
||||
}
|
||||
|
||||
async teamDisconnect(): Promise<void> {
|
||||
await this.fetch('/api/team/disconnect', { method: 'POST' });
|
||||
}
|
||||
|
||||
async getTeamStatus(): Promise<{ connected: boolean; teamName?: string }> {
|
||||
const res = await this.fetch('/api/team/status');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async getTeamMembers(): Promise<{ id: string; name: string; status: string; avatar?: string }[]> {
|
||||
try {
|
||||
const res = await this.fetch('/api/team/members');
|
||||
@@ -3216,8 +3189,7 @@ class LocalAdapter {
|
||||
/**
|
||||
* Execute a server-derived ResolvedAction's endpoint (create / side-effect).
|
||||
* The endpoint + body are produced by the closed registry — the client only
|
||||
* dispatches what the server already validated. A 403 still flows through the
|
||||
* global tier handler in `fetch`.
|
||||
* dispatches what the server already validated.
|
||||
*/
|
||||
async commandDispatchAction(action: ResolvedAction): Promise<{ ok: boolean; status: number; result?: unknown }> {
|
||||
if (!action.endpoint) return { ok: false, status: 0 };
|
||||
@@ -3631,47 +3603,6 @@ class LocalAdapter {
|
||||
this.fetch('/api/telemetry/track', { method: 'POST', body: JSON.stringify({ event, properties }) }).catch(() => {});
|
||||
}
|
||||
|
||||
// --- Stripe Billing ---
|
||||
async syncStripeCheckout(sessionId: string): Promise<{ tier: string; customerId: string | null }> {
|
||||
const res = await this.fetch('/api/stripe/sync', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ sessionId }),
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async createCheckoutSession(
|
||||
tier: 'TEAMS',
|
||||
billingPeriod?: 'monthly' | 'annual',
|
||||
): Promise<{ url: string }> {
|
||||
// PR7a/D8: thread billingPeriod so the annual toggle resolves the real annual
|
||||
// Stripe price (priceIdForTier). Omitted → backend defaults to monthly.
|
||||
const res = await this.fetch('/api/stripe/create-checkout-session', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(billingPeriod ? { tier, billingPeriod } : { tier }),
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async createPortalSession(): Promise<{ url: string }> {
|
||||
const res = await this.fetch('/api/stripe/create-portal-session', {
|
||||
method: 'POST',
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
|
||||
/** PR7a/F8: secret-free probe of whether Stripe checkout is wired, so the
|
||||
* billing UI can render the honest disabled state before a click (not a 503 after). */
|
||||
async getStripeStatus(): Promise<{ configured: boolean }> {
|
||||
const res = await this.fetch('/api/stripe/status');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async getTier(): Promise<{ tier: string; trialDaysRemaining?: number; trialExpired?: boolean; capabilities: Record<string, unknown>; usage: Record<string, unknown> }> {
|
||||
const res = await this.fetch('/api/tier');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a complete erasure of this install's data dir (GDPR Art. 17).
|
||||
*
|
||||
@@ -3714,40 +3645,6 @@ class LocalAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the 15-day trial atomically. Server writes
|
||||
* `{ tier: 'TRIAL', trialStartedAt: now() }` in a single config.json
|
||||
* mutation. Throws on 409 (trial already started) — call sites can
|
||||
* .catch() and either ignore (idempotent UX, e.g. onboarding-complete) or
|
||||
* surface to the user (e.g. "Start trial" button after expiry).
|
||||
*
|
||||
* Replaces the previous broken path where Desktop.tsx called
|
||||
* `adapter.updateSettings({ tier: 'TRIAL', trialStartedAt: ... } as any)`
|
||||
* — `updateSettings` did not exist on the adapter (silently swallowed by
|
||||
* `.catch(() => {})`), and even if it had, `PATCH /api/tier` ignores
|
||||
* `trialStartedAt`, so the trial never actually started.
|
||||
*/
|
||||
async startTrial(): Promise<{
|
||||
tier: string;
|
||||
rawTier: string;
|
||||
trialStartedAt: string;
|
||||
trialDaysRemaining: number;
|
||||
trialExpired: boolean;
|
||||
capabilities: Record<string, unknown>;
|
||||
}> {
|
||||
// P1b D3: chokepoint throws first — rethrow in the test-pinned legacy format.
|
||||
try {
|
||||
const res = await this.fetch('/api/tier/start-trial', { method: 'POST' });
|
||||
return res.json();
|
||||
} catch (e) {
|
||||
if (e instanceof AdapterHttpError) {
|
||||
const b = e.body as { message?: string; error?: string } | undefined;
|
||||
throw new Error(`Start trial failed (${e.status}): ${b?.message ?? b?.error ?? e.statusText}`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Import ---
|
||||
async importPreview(data: unknown, source: string): Promise<{ knowledgeExtracted: unknown[] }> {
|
||||
const res = await this.fetch('/api/import/preview', { method: 'POST', body: JSON.stringify({ data, source }) });
|
||||
|
||||
Reference in New Issue
Block a user