/** * @octomil/browser — Main SDK entry point * * The `OctomilClient` class is the primary public interface. It orchestrates * model loading, caching, inference, and optional telemetry. * * @example * ```ts * import { OctomilClient } from '@octomil/browser'; * * const ml = new OctomilClient({ * model: 'https://models.octomil.com/sentiment-v1.onnx', * backend: 'webgpu', * }); * * await ml.load(); * const result = await ml.predict({ raw: inputData, dims: [1, 3, 224, 224] }); * console.log(result.label, result.score); * ml.close(); * ``` */ import { OctomilAudio } from "./audio/octomil-audio.js"; import { CapabilitiesClient } from "./capabilities.js"; import { ChatClient } from "./chat.js"; import { ControlClient } from "./control.js"; import type { ModelRuntime } from "./runtime/index.js"; import { ModelsClient } from "./models.js"; import { ResponsesClient } from "./responses.js"; import { OctomilText } from "./text/octomil-text.js"; import type { Backend, CacheInfo, ChatChunk, ChatMessage, ChatOptions, ChatResponse, EmbeddingResult, OctomilOptions, PredictInput, PredictOutput, StreamToken } from "./types.js"; export declare class OctomilClient { private readonly options; private readonly cache; private readonly loader; private readonly engine; private readonly inferenceEngine; private readonly routingClient; private readonly deviceContext; private telemetry; private deviceCaps; private _responses; private _chat; private _control; private _capabilities; private _models; private _audio; private _text; private loaded; private closed; private _warmedUp; constructor(options: OctomilOptions & { runtime?: ModelRuntime; }); /** * Download (or load from cache) the ONNX model and create the * inference session. Must be called before `predict()` or `chat()`. */ load(): Promise; /** * Explicitly warm up the ONNX runtime by running a minimal dummy inference. * * This pre-allocates internal buffers, compiles GPU shaders, and triggers * any lazy initialisation that would otherwise happen on the first real * `predict()` call. Useful for latency-sensitive applications that want * predictable first-inference timing. * * Idempotent: calling `warmup()` after it has already completed is a no-op. * Requires `load()` to have been called first. */ warmup(): Promise; /** Whether `warmup()` has been called and completed successfully. */ get isWarmedUp(): boolean; /** * Run a single inference pass. * * Accepts either raw named tensors or convenience payloads * (`{ text }`, `{ image }`, `{ raw, dims }`). */ predict(input: PredictInput): Promise; /** * Run inference on multiple inputs sequentially. * ONNX Runtime Web doesn't handle concurrent sessions well, * so we process one at a time. */ predictBatch(inputs: PredictInput[]): Promise; /** * OpenAI-compatible chat completion. * * @deprecated Use `client.chat.create()` instead. This method will be * removed in the next major version. */ createChat(messages: ChatMessage[], options?: ChatOptions): Promise; /** * Streaming chat — yields chunks as they arrive. * * @deprecated Use `client.chat.stream()` instead. This method will be * removed in the next major version. */ createChatStream(messages: ChatMessage[], options?: ChatOptions): AsyncGenerator; /** * Stream tokens from the cloud inference endpoint via SSE. * * Consumes `POST /api/v1/inference/stream` and yields `StreamToken` * objects as they arrive. Requires `serverUrl` and `apiKey` to be * configured. * * @param modelId - Model identifier (e.g. `"phi-4-mini"`). * @param input - Plain string prompt or chat-style messages. * @param parameters - Generation parameters (temperature, max_tokens, etc.). * @param signal - Optional AbortSignal for cancellation. */ predictStream(modelId: string, input: string | { role: string; content: string; }[], parameters?: Record, signal?: AbortSignal): AsyncGenerator; /** * Generate embeddings via the Octomil cloud endpoint. * * Requires `serverUrl` and `apiKey` to be configured. * * @param modelId - Embedding model identifier (e.g. `"nomic-embed-text"`). * @param input - A single string or array of strings to embed. * @param signal - Optional AbortSignal for cancellation. */ embed(modelId: string, input: string | string[], signal?: AbortSignal): Promise; /** Check whether the model binary is currently cached locally. */ isCached(): Promise; /** Remove the cached model binary. */ clearCache(): Promise; /** Get cache metadata for the model. */ cacheInfo(): Promise; /** The inference backend currently in use (after `load()`). */ get activeBackend(): Backend | null; /** Input tensor names defined by the loaded model. */ get inputNames(): readonly string[]; /** Output tensor names defined by the loaded model. */ get outputNames(): readonly string[]; /** Whether `load()` has been called successfully. */ get isLoaded(): boolean; /** * Lazily-created `ChatClient` providing `chat.create()` and * `chat.stream()` methods for OpenAI-compatible chat completions. * * Uses a local responses runtime when configured, otherwise falls back to * the configured server-backed responses client. * * @example * ```ts * const response = await client.chat.create([ * { role: 'user', content: 'Hello!' }, * ]); * ``` */ get chat(): ChatClient; /** * Lazily-created `ResponsesClient` providing `responses.create()` and * `responses.stream()` methods for the structured response API. * * Uses a configured local responses runtime when available; otherwise uses * the server-backed responses API. `apiKey` is optional but recommended for * server-backed usage. */ get responses(): ResponsesClient; /** * Lazily-created `ControlClient` providing `control.register()`, * `control.heartbeat()`, and `control.refresh()` methods. * * Uses the configured `serverUrl`, `apiKey`, and any `orgId` * inferred from the options. */ get control(): ControlClient; /** * Lazily-created `CapabilitiesClient` providing `capabilities.current()` * to detect the full device capability profile. */ get capabilities(): CapabilitiesClient; /** * Lazily-created `ModelsClient` providing `models.status()`, * `models.load()`, `models.unload()`, `models.list()`, and * `models.clearCache()`. */ get models(): ModelsClient; /** * Lazily-created `OctomilAudio` providing * `audio.transcriptions.create()` for speech-to-text. * * Requires `serverUrl` and `apiKey` to be configured. * * @example * ```ts * const result = await client.audio.transcriptions.create({ * file: audioBlob, * model: 'whisper-large-v3', * }); * console.log(result.text); * ``` */ get audio(): OctomilAudio; /** * Lazily-created `OctomilText` providing `text.predictions.create()` * for browser-local text inference via the loaded model. */ get text(): OctomilText; /** Release all resources (WASM memory, WebGPU device, telemetry). */ close(): void; private ensureNotClosed; private ensureReady; /** * Normalise the various `PredictInput` shapes into a flat * `NamedTensors` map suitable for the inference engine. */ private prepareTensors; /** Type guard for NamedTensors. */ private isNamedTensors; /** * Convert an image source to a Float32Array in NCHW format * (batch=1, channels=3, H, W) normalised to [0, 1]. */ private imageToTensors; /** * Attempt routing + cloud inference. Returns a PredictOutput if the * routing decision is "cloud" and the cloud call succeeds, or `null` * to fall back to local inference. */ private tryCloudInference; } //# sourceMappingURL=octomil.d.ts.map