@marktiderman/genesis-ai
0.3.1Primitive · AIOne server-side pipeline for every AI call a Genesis app makes: consent, the feature gate, a bounded budget, server-side loading with a context manifest, safety routing, guardrails, the model call with rollouts, refusal and outage fallbacks, a usage row with no content and a trace. Tasks are versioned prompts with typed arguments and outputs, called by id; processors such as moderation and transcription are wrapped in place. Vendors are adapters (Anthropic and OpenAI ship), keys can be the platform's or a tenant's or person's own (BYOK, in Supabase Vault), and model records carry prices and capabilities that fail loudly on an unknown model. On the Vercel AI SDK, server only except /react. Part of the Genesis framework.
One server-side pipeline for every AI call a Genesis app makes. A task says **what** to ask (a versioned prompt, typed arguments, a loader and an output). The pipeline decides **whether and how** it runs:
1. the arguments match the task (clients send ids, never content); 2. the person has agreed to share with the model's vendor (to the current text, with `consentVersion`), unless the task's `consent` is `"terms"`; 3. the feature is on (your gate: `featureOn`, a kill switch, a tenant setting); 4. `can`, the task's own rule ("coaches only"); 5. `load` reads what the prompt needs **as the person** (their Supabase client, so row level security applies) and records a manifest: layer names, token counts and row ids; 6. your safety protocol runs on what the person wrote, before any model sees it; 7. input guardrails; 8. the key: the person's own, else their tenant's, else the platform's (BYOK); 9. the budget admits the call (platform spend plus open calls' estimates within the limit, and one person's share within `per_person_usd`; own-key calls don't spend it); 10. the model: the alias's, or its `rollout` when your flag says so; same-vendor fallbacks on 429/5xx/timeouts; Anthropic's server-side refusal fallback; structured output through `output_config.format` with one repair retry; 11. output guardrails; 12. a usage row (no prompt, no answer) and an OpenTelemetry GenAI span.
pnpm add @marktiderman/genesis-aiOther exports (11)
AI_SPEC · ANTHROPIC_API_VERSION · checkTasks · costOf · defineAi · defineTask · estimateCost · GuardrailError · MODEL_RECORDS · RUN_EVENT_TYPES · textStreamToRunEvents
And 41 types.
Other exports (8)
AiCallError · createAiHandler · evaluate · memoryStore · otelSink · runTask · streamTask · wrap
And 13 types.
Other exports (2)
anthropic · createGenesisAnthropic
Other exports (1)
openai
Other exports (2)
AiStoreError · supabaseStore
And 1 types.
Hooks (2)
- useAiStream
Streams a text task by id through `createAiHandler` (`stream: true`): text as it arrives, then the result. A stop before the model (no consent, over budget) comes back as the result at once.
- useAiTask
Calls a server task by id through `createAiHandler`. The client sends ids, never content: the task's `load` reads what the model sees, as the signed-in person.
And 3 types.