Files
waggle-os/apps/web/src/lib/install-store.ts
shumeiko.it fe2eb0f648 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.
2026-10-15 19:31:50 +02:00

74 lines
2.9 KiB
TypeScript

/**
* install-store — pure types + helpers for the PR4 shared install store
* (Warm-Hive Marketplace "sync"). The store (InstallProvider) is the single
* FE source of truth for "what is installed / connecting" that the grid
* (Variation A), agent-pick, and inline-in-chat (Variation B) all subscribe
* to, so installing in ANY view reflects in ALL.
*
* This module is React-free on purpose: the dispatch discriminator + the
* count-eligibility rule are unit-testable without rendering.
*/
import type { ExtensionType } from '@waggle/shared';
/**
* The minimal descriptor the store installs/uninstalls. `Extension`
* (lib/extension-catalog) is a structural superset, so the grid passes its
* Extensions verbatim; the inline-chat card (Phase D) builds one from a
* CapabilityRequest.
*/
export interface InstallTarget {
/** Namespaced catalog id — `pkg:<n>` | `connector:<id>` | `mcp:<id>` | `pack:<…>`. */
id: string;
type: ExtensionType;
kind: 'package' | 'pack' | 'federated';
name: string;
/** Numeric registry id — kind 'package' only. */
packageId?: number;
}
/** Why an install attempt did not succeed (drives the caller's follow-up UI). */
export type InstallReason =
| 'security' // SecurityGate blocked / requires approval
| 'error' // network / server / unknown failure (toast already shown)
| 'needs-credentials' // connector needs a token the caller did not supply (card collects it / OAuth → Hub)
| 'unsupported'; // browse-only (pack) or ambient (agent/model/template) — not installable via the store
export interface InstallOutcome {
ok: boolean;
reason?: InstallReason;
}
/** Credentials/options a caller may supply for a connector (token-paste) or MCP enable. */
export interface InstallCredentials {
token?: string;
apiKey?: string;
settings?: Record<string, string>;
force?: boolean;
forceInsecure?: boolean;
}
/** Strip the catalog namespace prefix: `connector:slack` → `slack`, `mcp:postgres` → `postgres`. */
export function rawId(namespacedId: string): string {
const i = namespacedId.indexOf(':');
return i === -1 ? namespacedId : namespacedId.slice(i + 1);
}
/**
* The togglable kinds the store can install/connect/enable AND that count
* toward the installed count (D1, honest global count). Ambient kinds
* (agent/model/template) are always present; packs are browse-only — neither
* flows through the store, so neither inflates the count.
*/
export function isTogglable(target: Pick<InstallTarget, 'type' | 'kind'>): boolean {
if (target.kind === 'package') return true; // marketplace skill / mcp package
if (target.kind === 'pack') return false; // browse-only (no install-pack route)
return target.type === 'connector' || target.type === 'mcp'; // federated connector / catalog mcp
}
/** Narrow an unknown thrown value to a human-readable message. */
export function describeError(e: unknown): string {
if (e instanceof Error && e.message) return e.message;
return 'Server unreachable';
}