askexperts
Version:
AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol
87 lines (86 loc) • 2.46 kB
TypeScript
/**
* StreamReader implementation for NIP-173 (Streaming Over Nostr)
*/
import { SimplePool } from "nostr-tools";
import { Compression } from "./compression.js";
import { Encryption } from "./encryption.js";
import { StreamMetadata, StreamReaderConfig } from "./types.js";
/**
* Error thrown when a stream operation fails
*/
export declare class StreamReaderError extends Error {
code: string;
constructor(code: string, message: string);
}
/**
* StreamReader for NIP-173 streams
* Implements AsyncIterable to allow for iterating over chunks
*/
export declare class StreamReader implements AsyncIterable<string | Uint8Array> {
private metadata;
private pool;
private config;
private compression;
private encryption;
private buffer;
private resultBuffer;
private nextRef;
private totalSize;
private chunkCount;
private isDone;
private lastEventTime;
private subscription;
private waitingResolvers;
private waitingRejecters;
private error;
/**
* Creates a new StreamReader
*
* @param metadata - Stream metadata
* @param pool - SimplePool instance for relay communication
* @param config - Configuration options
* @param compression - Optional custom compression implementation
*/
constructor(metadata: StreamMetadata, pool: SimplePool, config?: StreamReaderConfig, compression?: Compression, encryption?: Encryption);
/**
* Starts the stream subscription
* This is called automatically when iteration begins
*/
private start;
/**
* Handles an incoming event
*
* @param event - The received event
*/
private handleEvent;
/**
* Processes events from the buffer in sequence
*/
private processBuffer;
/**
* Processes a chunk by decompressing and decrypting it
*
* @param content - The chunk content
* @returns Promise resolving to the processed chunk
*/
private processChunk;
/**
* Starts the TTL timer to detect stalled streams
*/
private startTtlTimer;
/**
* Sets an error and rejects any waiting promises
*
* @param err - The error
*/
private setError;
/**
* Closes the stream and releases resources
*/
private close;
/**
* Implements AsyncIterable interface
*/
[Symbol.asyncIterator](): AsyncIterator<string | Uint8Array>;
[Symbol.dispose](): void;
}