UNPKG

@tanstack/ai-sandbox

Version:

Provider-agnostic sandbox layer for TanStack AI — run harness adapters inside isolated sandboxes (defineSandbox, defineWorkspace, withSandbox) with a uniform SandboxHandle, workspace bootstrap, policy, and resumable lifecycle.

37 lines (36 loc) • 1.68 kB
import { EmitCustomEventOptions, StreamChunk, ToolExecutionContext } from '@tanstack/ai'; export interface BridgeEventChannel { /** Pass as the bridge's `emitCustomEvent`; buffers a CUSTOM chunk for the stream. */ emitCustomEvent: (eventName: string, value: Record<string, unknown>, options?: EmitCustomEventOptions) => void; /** * Pass as the bridge's `emitActivity`. Buffers the `ACTIVITY_SNAPSHOT` * chunk of `definition.snapshot(id, content)` for the stream. * * @throws TypeError when the content fails the schema check of `definition` */ emitActivity: NonNullable<ToolExecutionContext['emitActivity']>; /** * Live stream of CUSTOM and ACTIVITY_SNAPSHOT chunks; ends after * {@link close} once drained. */ stream: AsyncIterable<StreamChunk>; /** Stop the stream (call when the run's main output is done). */ close: () => void; } /** * Create a channel whose emitted events and activities become * {@link StreamChunk}s. */ export declare function createBridgeEventChannel(meta: { model: string; threadId?: string; runId?: string; }): BridgeEventChannel; /** * Merge a `side` chunk stream into a `base` chunk stream, yielding from whichever * settles first. Terminates when `base` ends (the run is over). If `side` came * from {@link createBridgeEventChannel}, closes that channel and drains * already-buffered side chunks before returning. Then releases the side * iterator — so a never-ending channel (until closed) doesn't hang the merge. */ export declare function mergeChunkStreams(base: AsyncIterable<StreamChunk>, side: AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;