@devfellowship/sdk
v0.4.0
Published
DevFellowship SDK — Supabase-compatible client with workflow primitives, and the DFL client (/client) for the gateway REST front
Maintainers
Readme
@devfellowship/sdk
DevFellowship SDK v0 — Supabase-compatible client with workflow primitives.
Install
npm install @devfellowship/sdkUsage
import { createDflClient } from "@devfellowship/sdk";
const dfl = createDflClient({
supabaseUrl: "https://your-project.supabase.co",
supabaseAnonKey: "your-anon-key",
natsUrl: "nats://localhost:4222",
engineUrl: "http://localhost:3335",
});
// Raw Supabase client (same API as @supabase/supabase-js)
const { data } = await dfl.client.from("users").select("*");
// Fire an intent (publishes to NATS DFL_INTENTS stream)
await dfl.wf.fireIntent("onboarding.new_member", {
intentId: "unique-id-123",
payload: { userId: "abc", email: "[email protected]" },
});
// Subscribe to workflow instance progress events
const unsub = await dfl.wf.subscribeInstance("instance-uuid", (event) => {
console.log("Workflow event:", event);
});
// Call engine proxy endpoint
const result = await dfl.wf.proxy("my-service-node", { key: "value" });LLM proxy
All LLM calls in the DFL fleet should go through dfl-flows-engine so we get
unified OTEL spans, cost attribution, and provider-agnostic adoption.
wf.chat() is a thin typed wrapper around wf.proxy() for chat-completion
workflows.
Quickstart
import { createDflClient, type LlmChatResponse } from "@devfellowship/sdk";
const dfl = createDflClient({
supabaseUrl: process.env.SUPABASE_URL!,
supabaseAnonKey: process.env.SUPABASE_ANON_KEY!,
engineUrl: process.env.DFL_ENGINE_URL!, // required for wf.chat / wf.proxy
});
const res = await dfl.wf.chat(
"openrouter-chat",
{
model: "gpt-4.1-mini",
messages: [
{ role: "system", content: "You are concise." },
{ role: "user", content: "Title for a 3min video about RLS?" },
],
temperature: 0.4,
},
{ appName: "lesson-studio" }
);
console.log(res.choices[0].message.content);The appName is propagated as the X-DFL-App header so the engine can attribute
cost back to the right product. If omitted, process.env.DFL_APP_NAME is used as
a fallback (Node only — guarded for browser-safe usage).
Available workflow keys
These are the canonical LLM workflow definitions in dfl-flows-definitions
(see dfl-flows-definitions#13). Pass any of them as the first arg to
wf.chat() / wf.proxy():
| Key | Provider | Shape |
|---|---|---|
| openrouter-chat | OpenRouter (preferred default per DFL standard) | LlmChatRequest → LlmChatResponse |
| openai-chat | OpenAI direct | LlmChatRequest → LlmChatResponse |
| groq-chat | Groq | LlmChatRequest → LlmChatResponse |
| groq-whisper-transcribe | Groq Whisper | WhisperTranscribeRequest → WhisperTranscribeResponse (use wf.proxy() not wf.chat()) |
Cancellation
Pass an AbortSignal to cancel an in-flight call:
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5_000);
await dfl.wf.chat(
"openrouter-chat",
{ model: "gpt-4.1-mini", messages: [...] },
{ appName: "dfl-seo", signal: ctrl.signal }
);Environment variables
When using createDflClientFromEnv():
| Variable | Required | Description |
|---|---|---|
| SUPABASE_URL | Yes | Supabase project URL |
| SUPABASE_ANON_KEY | Yes | Supabase anonymous key |
| DFL_NATS_URL | No | NATS server URL for workflow ops |
| DFL_ENGINE_URL | No | Flows engine URL — required for wf.proxy() / wf.chat() |
| DFL_APP_NAME | No | Default X-DFL-App header value (overridden by opts.appName) |
DFL client — @devfellowship/sdk/client (since 0.3.0)
The browser client of the DFL gateway REST front. It is a supabase-js client:
the app keeps the same API. Only the address of the data calls changes.
Contract: plan 20261117-fleet-access-s7-rest-front-dfl-client, "REST front
contract" C2, C8–C11.
import { createClient } from "@devfellowship/sdk/client";
export const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_ANON_KEY,
{
gatewayUrl: import.meta.env.VITE_DFL_GATEWAY_URL ?? "", // https://gateway.devfellowship.com
app: "dfl-sheets",
// every other supabase-js option (auth, db, global, realtime) works as before
},
);| Call | Goes to |
|---|---|
| from(...), rpc(...) (/rest/v1/*) | gatewayUrl + the same path and query |
| functions.invoke(...) (/functions/v1/*) | gatewayUrl + the same path |
| auth.*, storage.*, realtime | the Supabase URL, unchanged (ADR-2) |
On each call to the front the client adds a W3C traceparent (it keeps a valid
one that the caller set) and X-DFL-Client: @devfellowship/sdk@<version>. It
adds no other header: the front's CORS list is GATEWAY_CORS_ALLOW_HEADERS.
Options.
| Option | Default | What it does |
|---|---|---|
| gatewayUrl | required | Base URL of the REST front. "" sends every call to Supabase direct (rollback switch). |
| app | required | App slug, sent in each error report. The front reads the app from the Origin. |
| fallbackDirectReads | false | On a network error or a 502/503/504 of the front on a GET or HEAD, send the same read once to Supabase direct (RLS holds), with no DFL header, and report it. A write never falls back. |
| report | reportToObservability | Gets one DflClientErrorReport per error. |
Errors. A refusal of the front uses the PostgREST error body, so it arrives
in error as usual: error.code === "DFL403", error.message, error.hint.
For functions.invoke the same JSON is the body of error.context
(FunctionsHttpError). The client reports:
- every answer with a
DFL…code (front_error); - every other 5xx (
upstream_5xx); - a network error (
network_error) and a direct read (fallback_read).
An upstream PostgREST 4xx (for example PGRST116 of .single()) passes
unchanged and is not reported: the app sees and handles it as today. A report
holds the trace id (from X-DFL-Trace-Id, else the sent one), the code, the
capability, the decision, the route kind (table, rpc, function), the object
name, the method and the app. It holds no query string, no body and no token.
The default reporter sends a Sentry error (captureError) and an OTel event
(trackEvent, name dfl.client.<kind>) through
@devfellowship/observability (optional peer, ^2.2.0; install it in the app,
and mount <ObservabilityProvider>, else both calls do nothing). Note:
observability 2.2.1 imports @tanstack/react-query at load, so an app without
it must add it.
Note: postgrest-js retries a GET on 503 by itself (db.retry, default on).
Trace (since 0.4.0)
Each call to the gateway starts one browser span (dfl.gateway <METHOD> <object>, kind CLIENT)
and sends its context as traceparent. The gateway continues it, so the browser span,
rest.request and rest.upstream share one trace id in Tempo, on success and on error.
The span goes through the tracer that the app registered (<ObservabilityProvider> of
@devfellowship/observability), with the sampler of that tracer (always on by default, the same
as the gateway). With no tracer the span is a no-op and the client sends a random traceparent,
as in 0.3.0. A traceparent that the caller sets is kept and no span starts.
