API

configure()

The one place asset URLs, model hosts, auth, caching and execution providers are set.

import { configure, getConfig, resetConfig } from '@stabrise/scaledp'

configure({ cache: 'indexeddb', pdf: { workerSrc: '/pdf.worker.min.mjs' } })

Call it once, before any stage runs. It merges into the current config and returns the result; pdf, tesseract and hf merge per key rather than being replaced wholesale, so two calls can each set one field.

getConfig() returns the current config read-only. resetConfig() restores the defaults and exists for tests.

No app-owned paths

The library never guesses where your app puts things. A hardcoded /pdf.worker.min.mjs or /api/hf-token inside the library would be a bug — everything an app owns comes through here.

ScaleDpConfig

interface ScaleDpConfig {
    modelHost: string                      // 'https://huggingface.co'
    cache: 'indexeddb' | 'none'            // 'indexeddb'
    cacheDbName: string                    // 'scaledp-models'
    auth?: (repo: string) => Promise<string | undefined> | string | undefined
    onProgress?: (progress: ModelProgress) => void
    executionProviders: readonly string[]  // ['wasm']
    numThreads: number                     // 0 = auto
    ortWasmPaths?: string
    pdf: { workerSrc?; cMapUrl?; standardFontDataUrl?; wasmUrl? }
    tesseract: { workerUrl?; dataUrl?; osdWorkerPath?; osdCorePath?; osdLangPath?; osdGzip? }
    hf: { remoteHost?; remotePathTemplate? }
}
KeyMeaning
modelHostWhere repo-relative model files are fetched from. /models self-hosts. Absolute URLs in a catalogue bypass it.
cache'indexeddb' caches weights across visits; 'none' refetches every time.
cacheDbNameThe IndexedDB database name. Change it to isolate two apps on one origin.
authCalled with a repo id; return a bearer token. Used for private Hugging Face repos.
onProgressDownload and initialisation progress. See below.
executionProvidersPriority order, e.g. ['webgpu', 'wasm']. See Execution providers.
numThreads0 derives from hardwareConcurrency. Only has effect on a cross-origin-isolated page.
ortWasmPathsWhere onnxruntime-web's .wasm/.mjs live. Defaults to a version-matched CDN.
pdfpdf.js worker and data files.
tesseractTesseract worker and traineddata; the osd* keys locate tesseract.js for script detection and default to its CDN.
hf@huggingface/transformers host overrides, for proxying gated tokenizers.

ModelProgress

interface ModelProgress {
    repo: string
    file: string
    loaded: number
    total: number
    phase: 'downloading' | 'initializing' | 'ready'
}

total can be 0 when neither the catalogue nor a HEAD request could supply a size — render an indeterminate state rather than dividing by it.

PhaseWhen
downloadingBytes are arriving, from this realm's fetch or one another realm is running (one download per origin).
initializingFiles are in hand and an engine stage is building its ONNX session.
readyUsable. A plain ensureModelFiles or prefetchModels ends here once the files are cached; an engine stage reports it only after its session exists.

Every load ends with ready, cache hit or not, so a progress indicator can be cleared on it without a timer. Inside a run the same events also arrive as model:progress, attributed to a stage — see Streaming runs.

configure({
    onProgress: ({ repo, file, loaded, total, phase }) => {
        if (phase === 'ready') return clearProgress()
        const what = (file || repo).split('/').pop()
        setProgress(total > 0 ? `${phase} ${what} — ${Math.round((loaded / total) * 100)}%` : `${phase} ${what}…`)
    },
})

onProgress takes one callback, and it is set before React (or anything else) mounts. A common shape is to have it write into a module-level sink a component subscribes to, rather than rebuilding the config on every render.

In a worker

auth and onProgress are functions and do not survive postMessage, so the worker client's configure excludes them by type. Give auth to createScaleDpWorker({ auth }) (or the pool) instead: the worker asks the main thread for each token, and the entry file needs no token logic of its own. Progress comes back through the client's own onProgress. See @stabrise/scaledp/worker and Workers.

Threads

import { defaultNumThreads, resolveNumThreads } from '@stabrise/scaledp'

defaultNumThreads()   // max(1, min(4, hardwareConcurrency - 1)); 4 assumed if unknown
resolveNumThreads()   // config.numThreads > 0 ? it : defaultNumThreads()

On this page