@cogniformai/instructor-stream
Version:
Streaming-first structured data extraction from LLMs with real-time updates
92 lines (86 loc) • 3.85 kB
TypeScript
import * as effect_Types from 'effect/Types';
import { Schema } from 'effect/Schema';
import { z } from 'zod';
declare const ProviderError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
readonly _tag: "ProviderError";
};
declare class ProviderError extends ProviderError_base<{
readonly message: string;
readonly cause?: unknown;
}> {
}
declare const StreamingError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
readonly _tag: "StreamingError";
};
declare class StreamingError extends StreamingError_base<{
readonly message: string;
readonly cause?: unknown;
}> {
}
declare const SchemaResolutionError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
readonly _tag: "SchemaResolutionError";
};
declare class SchemaResolutionError extends SchemaResolutionError_base<{
readonly message: string;
}> {
}
declare const SnapshotValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
readonly _tag: "SnapshotValidationError";
};
declare class SnapshotValidationError extends SnapshotValidationError_base<{
readonly reason: string;
readonly issues?: unknown;
}> {
}
type StreamingPipelineError = ProviderError | StreamingError | SchemaResolutionError | SnapshotValidationError;
type SchemaValidationMode = 'none' | 'on-complete' | 'final';
type SchemaSource<A> = {
readonly name: string;
readonly effect?: Schema<A>;
readonly zod?: z.ZodType<A>;
};
type ResolvedSchema<A> = {
readonly name: string;
readonly effect?: Schema<A>;
readonly zod?: z.ZodType<A>;
};
/**
* Resolves a schema source into a resolved schema with validated effect and/or zod schemas.
*
* @template A - The type parameter representing the schema's inferred type
* @param {SchemaSource<A>} source - The schema source object containing optional effect/zod schemas and a name
* @returns {ResolvedSchema<A>} A resolved schema object containing the name and available schemas
* @throws {SchemaResolutionError} When neither an Effect schema nor a Zod schema is provided
*
* @example
* ```typescript
* const schema = resolveSchema({
* name: 'UserSchema',
* zod: z.object({ name: z.string() })
* });
* ```
*/
declare const resolveSchema: <A>(source: SchemaSource<A>) => ResolvedSchema<A>;
type ActivePath = (string | number | undefined)[];
type CompletedPaths = ActivePath[];
interface BaseCompletionMeta {
_activePath: ActivePath;
_completedPaths: CompletedPaths;
_isValid: boolean;
_type?: string;
}
type TokenUsage = {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
};
type CompletionMeta = Partial<BaseCompletionMeta> & {
usage?: TokenUsage;
thinking?: string;
};
type StreamingValidationMode = SchemaValidationMode;
type SnapshotChunk<A> = {
readonly data: ReadonlyArray<Partial<A>>;
readonly _meta: CompletionMeta;
};
export { type ActivePath as A, type BaseCompletionMeta as B, type CompletionMeta as C, ProviderError as P, type ResolvedSchema as R, type SchemaSource as S, type TokenUsage as T, type SchemaValidationMode as a, type SnapshotChunk as b, type StreamingPipelineError as c, StreamingError as d, SchemaResolutionError as e, SnapshotValidationError as f, type CompletedPaths as g, type StreamingValidationMode as h, resolveSchema as r };