Integrations
What this is for
An integration connects Spine to an external service (OpenAI, Resend, a generic HTTP endpoint, a database, ...). The record stores the provider, runtime config (including which adapter handles calls), and credentials. Pipelines and app code reference the integration by slug.
Why it exists
integrations
You need a central place to manage third-party connections and route incoming webhooks without hardcoding URLs in every function.
Why it exists (5-whys):
- Connections (provider endpoints, tokens, feature flags) are per-app per-account — hardcoded means redeploys and secrets in code.
config/metadataJSONB absorbs provider variance — every service's shape differs; a document per integration beats a column per possible field.UNIQUE(app_id, slug)+type_idmake integrations domain vocabulary — apps declare which services they connect; accounts bind instances.- Typed integrations mean a "Slack" connection and a "webhook" connection carry different schemas — same types-as-data pattern.
- Root: external connectivity is configuration the platform must govern —
integrationsmakes third-party connections declarable, scoped, and swappable instead of code-bound. (confirmed 2026-11-13)
webhook-handlers
Every new integration used to require a static import in integration-routes.ts. The registry lets apps register handlers at runtime.
Why it exists (5-whys):
- A static route table means platform edits per app handler —
integration_routeswas exactly that, and004dropped it for this registry. - Self-registration (
function_name+events[]via_shared/webhook-registration.ts) makes handlers discoverable at runtime — no central file, no import graph crossing the core/custom boundary. UNIQUE(app_id, account_id, name)+ a GIN index oneventsmake dispatch a data lookup —webhook-registry.tsresolveHandlerresolves by name/app/account, with caching.is_deletedsoft-delete keeps the audit of what was registered when deliveries arrived — unregistering shouldn't erase history.- Root: extensibility can't flow through core code —
webhook_handlersmakes inbound handlers discoverable data, so apps extend the integration surface without touching the framework. (confirmed 2026-11-13)
Companion ledger: webhook-deliveries.
Fields and settings
- Name (required) — display name. The slug is derived from it server-side (
OpenAI→openai); passslugin the body only to override. - Type (required) — select:
webhook,api,database,file,custom. Categorizes the integration; the create form pre-fills sensibleconfig/credentialstemplates per type. - Provider (required) — free-text provider name (e.g.
openai,resend,postgres). - Version — string, default
1.0.0. - Config (JSON) — adapter and runtime settings. The adapter is named here, not as a top-level field:
config.outbound_adapter(orconfig.inbound_adapterfor inbound webhooks) points at an adapter module such asadapters/openai-outbound. - Credentials (JSON) — secrets keyed by field name, each
{ "source": "env_var" | "value", "value": "..." }.source: "env_var"resolves the named env var inside the function runtime;source: "value"stores the literal secret in the DB. The credential field callers read defaults toapi_token. - Configured — computed, read-only.
is_configuredis re-derived on every save fromcredentials(all entries must resolve); the UI shows it as Configured/Pending. - App ID — select, optional. Owning app; blank = account-scoped.
- Active — boolean. Inactive integrations fail closed — callers get an error, not a fallback.
- Description / Metadata — optional notes and free-form data.
Downstream effects
env_varcredentials are resolved inside the function runtime — the variable must exist in the deployed env or calls fail at request time (credential_env_missing), not at save time.source: "value"persists the literal secret — preferenv_varfor anything real.- An absent or explicitly-empty (
source: "value",value: "") credential entry means "call without auth" — the outbound broker sends no credential and the adapter decides whether one is required (the seededgeneric-httpintegration works unauthenticated out of the box this way). - Built-in outbound adapters:
adapters/openai-outbound,adapters/generic-webhook-outbound,adapters/resend-outbound. Any other adapter path is dynamically imported — a typo saves fine but fails on first call. - Outbound calls create a
webhook_deliveriesrow (pending,max_attemptsdefault 3 orconfig.retry_policy.max_attempts) and show up under Deliveries. - Apps declare
integration_deps; installing an app without its integrations leaves features broken until the records exist. - The list/detail APIs use
adminDbfor system admins — integrations exist per account and per system scope.
Minimal configuration
{
"name": "OpenAI",
"integration_type": "api",
"provider": "openai",
"is_active": true,
"config": {
"outbound_adapter": "adapters/openai-outbound",
"model": "gpt-4o"
},
"credentials": { "api_token": { "source": "env_var", "value": "OPENAI_API_KEY" } }
}Full configuration
{
"name": "Outbound webhook",
"integration_type": "api",
"provider": "custom",
"version": "1.2.0",
"is_active": true,
"config": {
"outbound_adapter": "adapters/generic-webhook-outbound",
"base_url": "https://hooks.example.com",
"timeout_ms": 10000,
"retry_policy": { "max_attempts": 5 }
},
"credentials": { "api_token": { "source": "env_var", "value": "ACME_HOOK_TOKEN" } },
"metadata": { "owner": "platform" }
}Example
A support app lists integration_deps: ["openai"] — the AI agents resolve the openai integration by slug for model calls (credential field api_token), and a second integration (config.outbound_adapter: "adapters/generic-webhook-outbound") delivers outbound ticket events, each attempt logged under Deliveries.
Core files
.framework/functions/integrations.ts— API (list/get/create/update;is_configuredcomputed on write; non-admin reads are sanitized).framework/functions/integration-outbound.ts— outbound broker (adapter registry, delivery rows, retry math).framework/functions/integration-routes.ts— inbound webhook entry.framework/functions/_shared/resolve-credentials.ts—env_var/valuecredential resolution.framework/src/pages/admin/IntegrationsPage.tsx/IntegrationDetailPage.tsx— admin UI (per-type config templates on the detail form)- Table:
public.integrations
Agent notes
- Credentials shape is
{ "api_token": { "source": "env_var", "value": "OPENAI_API_KEY" } }— nestedsource/valueobjects, not{ "env_var": "..." }. The latter saves but never resolves. - Never put real secrets in
credentials.*.valuewithsource: "value"in seeds or docs — alwaysenv_var. - There is no top-level
adapterorconfigurationcolumn — the field isconfig, and the adapter lives atconfig.outbound_adapter/config.inbound_adapter. - After changing credentials, the broker picks them up on the next call — no cache flush needed.