mechbench-models
v0.107.0
Published
Shared TypeScript types for mechbench platform objects (User, Org, Project, Workspace, ApiKey, etc.). Consumed by mechbench-ui and mechbench-api. Distinct from mechbench-schema, which covers wire-format data records.
Readme
mechbench-models
Shared TypeScript types for mechbench platform objects — User, Org, Project, Workspace, ApiKey, Membership, Invitation. Consumed by mechbench-ui and mechbench-api.
What's in here (and what isn't)
This package holds the types that describe who uses the platform and how they're organized — users, orgs, workspaces, projects, memberships, API keys, invitations. It does not hold types for data records produced by the compute engine (experiment outputs, cache entries, emission shapes) — those live in mechbench-schema.
| | mechbench-schema | mechbench-models (this package) |
|---|---|---|
| Source of truth | Pydantic models | Hand-written TypeScript + Zod |
| Content | Wire-format data records | Platform objects |
| Publications | PyPI + npm | npm only |
| Cross-language? | Yes — TS generated from Pydantic | TS-only today; Python bindings only if a real need arises |
| Update cadence | With the emission protocol | With platform features (auth, billing, admin) |
| Generated? | TS side generated from Pydantic | Hand-written |
If you're tempted to put a type in the wrong package, ask: does this shape describe a thing users/orgs/projects care about (→ models), or a shape that crosses the Python/TS boundary as experiment output (→ schema)?
Using it
import { UserSchema, type User, type Workspace, type ApiKey } from "mechbench-models";
// Validate an incoming payload at an API boundary:
const parsed: User = UserSchema.parse(request.body);
// Or use the inferred type for application-internal data:
function welcomeMessage(user: User): string {
return `Hello, ${user.displayName ?? user.handle}`;
}Every object is defined as a Zod schema with a derived TypeScript type via z.infer<typeof Schema>. Consumers pick whichever they need:
- The schema (runtime) for validation at boundaries (request parsing, database roundtrip verification, form submission).
- The type (compile-time) for application-internal code.
Both come from one definition, so they can't drift.
Current types
User— platform user.handleis authoritative as the owner segment ofMechbenchPaths.Org— organization. Owns workspaces; users become members viaMembership.Workspace— top-level organizational unit. Maps 1:1 to the<owner>segment of aMechbenchPath; either a user workspace or an org workspace.Project— second path segment under a workspace. Contains charts, articles, experiments, probes, corpuses, cached intermediates.Membership— user's access to an org or workspace with a role (owner|admin|editor|viewer).ApiKey— issued to a user, optionally scoped to an org. Plaintext shown once at creation; only hash stored at rest.Invitation— pending membership invitation. One-time-use token; transitions to an actualMembershipon acceptance.
Relationship to MechbenchPath
The identity scheme (docs) addresses every object in the platform by a MechbenchPath like <owner>/<project>/<folders>/<leaf>. Platform objects in this package provide the grounding for those paths:
- A
User.handleorOrg.handleis the<owner>segment. - A
Project.slugis the<project>segment. - Everything under
<owner>/<project>/…is a resource that (a) this package doesn't model directly and (b) permissions check against aMembershipfor the owning scope.
MechbenchPathSchema is re-exported from ./primitives as a Zod schema; it accepts any of the five categories from the identity doc (user-named, canonical, platform, global-hash, scoped-hash). The authoritative validator (deep structural checks) lives in mechbench-schema's Python identity module and its TS mirror in mechbench-ui/src/lib/mechbenchPath.ts; this package's schema is the lightweight version for platform-object boundary checks.
Status
v0.1.0. Scaffolded per task 000168 with an initial set of seven objects + three primitives. The next meaningful expansion is probably the auth/session types (token, refresh-token, session), which are close cousins to ApiKey but different enough to warrant their own file.
Open work tracked in the meta repo's tasks/mechbench-models/ directory.
License
MIT.
