Locara

@locara/sdk reference

Strongly-typed wrappers around every IPC command exposed by locara-runtime.

llm

import { llm } from '@locara/sdk'

const r = await llm.chat({
  model: 'qwen2.5-3b-instruct-q4@sha256:abcdef...',
  messages: [{ role: 'user', content: 'hello' }],
})

Streaming:

for await (const delta of llm.chatStream({ model, messages }, abortSignal)) {
  // delta.content?: string
  // delta.finishReason?: 'stop' | 'length' | 'cancel'
}

embed

import { embed } from '@locara/sdk'
const r = await embed({ model: 'nomic@sha256:...', input: 'hello' })

transcribe

import { transcribe } from '@locara/sdk'

// File mode:
const r = await transcribe.fromFile({ file: blob })

// Streaming mode:
for await (const seg of transcribe.stream({ source }, abortSignal)) {
  // seg.start_ms / seg.end_ms / seg.text
}

vlm

import { vlm } from '@locara/sdk'
const r = await vlm.describe({ model, image: blob, prompt: 'caption this' })

ocr

import { ocr } from '@locara/sdk'
const r = await ocr.fromFile({ file: blob })

db

import { db } from '@locara/sdk'

await db.exec({ sql: 'INSERT INTO t VALUES (?)', params: [1] })
const { rows } = await db.query<{ id: number }>({ sql: 'SELECT id FROM t' })

fs

import { fs } from '@locara/sdk'

const path = await fs.pickFile({ filters: [{ name: 'Audio', extensions: ['mp3', 'wav'] }] })
const r = await fs.readFile({ path: path[0], scope: 'user-selected' })

await fs.writeFile({
  path: 'cache.bin',
  bytes: new Uint8Array([...]),
  scope: 'app-data',
})

tools

import { tools } from '@locara/sdk'
const r = await tools.invoke({ tool: 'ocr', args: { bytes } })

audio

import { audio } from '@locara/sdk'
const mic = await audio.openMicrophone({ sampleRate: 16000 })
for await (const frame of mic.frames) { /* ... */ }
mic.stop()

Errors

Every call may throw:

  • CapabilityDenied — manifest doesn’t grant the operation.
  • SdkError — generic runtime error.
import { CapabilityDenied } from '@locara/sdk'

try { /* ... */ }
catch (e) {
  if (e instanceof CapabilityDenied) {
    console.warn('denied:', e.op, e.reason)
  }
}