UNPKG

@cogniformai/instructor-stream

Version:

Streaming-first structured data extraction from LLMs with real-time updates

52 lines (49 loc) 2.29 kB
import { Effect, Stream, Layer } from 'effect'; import { S as SchemaSource, C as CompletionMeta, a as SchemaValidationMode, b as SnapshotChunk, c as StreamingPipelineError, d as StreamingError } from './snapshots-uXGVbqtJ.js'; type ProviderMeta = Partial<CompletionMeta>; type ProviderStreamResult = { readonly stream: ReadableStream<Uint8Array>; readonly meta?: ProviderMeta | (() => ProviderMeta); readonly channelType?: string; }; type HydrationRequest<A> = { readonly schema: SchemaSource<A>; readonly provider: ProviderStreamResult; readonly validationMode?: SchemaValidationMode; }; type StubRequest<A> = { readonly schema: SchemaSource<A>; readonly defaultData?: Partial<A>; }; type SnapshotHydratorService = { readonly stream: <A>(request: HydrationRequest<A>) => Stream.Stream<SnapshotChunk<A>, StreamingPipelineError, never>; readonly stub: <A>(request: StubRequest<A>) => Effect.Effect<Partial<A>, StreamingPipelineError, never>; }; declare const SnapshotHydrator_base: Effect.Service.Class<SnapshotHydratorService, "instructor/streaming/SnapshotHydrator", { readonly effect: Effect.Effect<{ stream: <A>(request: HydrationRequest<A>) => Stream.Stream<SnapshotChunk<A>, StreamingPipelineError, never>; stub: <A>(request: StubRequest<A>) => Effect.Effect<Partial<A>, StreamingError, never>; }, never, never>; }>; /** * Service for hydrating and constructing streaming pipelines and schema stubs. * * Provides two main operations: * - `stream`: Creates a streaming pipeline from a hydration request by unwrapping and hydrating the data * - `stub`: Builds a schema stub from a stub request for type validation purposes * * @remarks * Both operations handle errors by wrapping them in a `StreamingError` with descriptive messages. * The service is registered under the identifier 'instructor/streaming/SnapshotHydrator'. * * @example * ```typescript * const hydrator = yield* SnapshotHydrator; * const dataStream = hydrator.stream(request); * const schemaStub = yield* hydrator.stub(stubRequest); * ``` */ declare class SnapshotHydrator extends SnapshotHydrator_base { } declare const SnapshotHydratorLayer: Layer.Layer<SnapshotHydrator>; export { SnapshotHydrator as S, SnapshotHydratorLayer as a };