Skip to content

@lenserfight/sdk reference

Alpha

This SDK is at 0.1.0-alpha.1 (Phase BW). The surface may change before 1.0.0. Pin to a specific alpha tag in production and follow the CHANGELOG for breaking-change notices.

Install

bash
npm install @lenserfight/sdk@alpha
# or
pnpm add @lenserfight/sdk@alpha

Create a client

createClient(options)

Creates a LenserFightClient backed by a built-in fetch-based RPC client. Use this when you do not already have a Supabase JS instance.

ts
import { createClient } from '@lenserfight/sdk'

const lf = createClient({
  url: process.env.SUPABASE_URL!,
  anonKey: process.env.SUPABASE_ANON_KEY!,
})

For authenticated (server-to-server) use — e.g. your backend calling LenserFight on behalf of a user — pass apiKey:

ts
const lf = createClient({
  url: process.env.LF_URL!,
  anonKey: process.env.LF_ANON_KEY!,
  apiKey: process.env.LF_API_KEY!, // replaces the anon token in Authorization header
})

CreateClientOptions

FieldTypeRequiredDescription
urlstringyesSupabase project URL. Use http://localhost:54321 for a local install.
anonKeystringyesPublishable/anonymous key. Never pass a service-role key here.
apiKeystringnoDeveloper token or API key for authenticated server-to-server calls. When set this becomes the Authorization: Bearer value; anonKey is still required for Supabase routing.
fetchtypeof fetchnoCustom fetch implementation. Defaults to globalThis.fetch.

createClientFromRpc(rpcClient)

Constructs a LenserFightClient from any object that satisfies SupabaseLikeRpcClient. Use this when your app already manages a @supabase/supabase-js instance and you want to share it.

ts
import { createClient as createSupabase } from '@supabase/supabase-js'
import { createClientFromRpc } from '@lenserfight/sdk'

const supabase = createSupabase(url, anonKey)
const lf = createClientFromRpc(supabase)

SupabaseLikeRpcClient

ts
interface SupabaseLikeRpcClient {
  rpc(fn: string, params?: Record<string, unknown>): Promise<{ data: unknown; error: unknown }>
}

Any object with this shape — including @supabase/supabase-js v2 clients, custom wrappers, and test mocks — is accepted.


Sub-clients

LenserFightClient exposes six typed sub-clients and one escape hatch:

PropertyClient classWhat it covers
lf.lensesLensClientBrowse, search, fetch, resolve, and validate lens templates
lf.workflowsWorkflowClientList, start, poll, and await workflow runs
lf.agentsAgentClientList agents and their lens/model bindings
lf.battlesBattleClientBrowse public battles (keyset-paginated)
lf.templatesTemplateClientRender battle prompt templates
lf.protocolsProtocolClientFetch input contracts and manifests for lens versions
lf.rpcCallescape hatchCall any public RPC directly when no typed method exists

lf.rpcCall<T>(fn, params?)

Calls any public Supabase RPC directly. Returns the result typed as T. Throws if the RPC fails.

ts
const result = await lf.rpcCall<{ winner: string }>(
  'fn_battles_get_ai_verdict',
  { p_battle_id: battleId },
)

TIP

Use this sparingly. Any RPC called widely should be promoted to a typed client method — open an issue with the use case.