add conditional type overload for streaming

This commit is contained in:
ProgrammerIn-wonderland
2025-10-03 16:35:26 -04:00
committed by Neal Shah
parent 1affbb4cc8
commit f60e02565f
2 changed files with 17 additions and 5 deletions
+1
View File
@@ -24,6 +24,7 @@ jobs:
- name: Build
run: |
rm package-lock.json
npm install
npm run test
+16 -5
View File
@@ -32,11 +32,19 @@ declare class Puter {
// AI Module
interface AI {
chat(prompt: string, options?: ChatOptions): Promise<ChatResponse> | AsyncIterable<ChatResponseChunk>;
chat(prompt: string, testMode?: boolean, options?: ChatOptions): Promise<ChatResponse> | AsyncIterable<ChatResponseChunk>;
chat(prompt: string, imageURL?: string, testMode?: boolean, options?: ChatOptions): Promise<ChatResponse> | AsyncIterable<ChatResponseChunk>;
chat(prompt: string, imageURLArray?: string[], testMode?: boolean, options?: ChatOptions): Promise<ChatResponse> | AsyncIterable<ChatResponseChunk>;
chat(messages: ChatMessage[], testMode?: boolean, options?: ChatOptions): Promise<ChatResponse> | AsyncIterable<ChatResponseChunk>;
// Streaming overloads
chat(prompt: string, options: StreamingChatOptions): AsyncIterable<ChatResponseChunk>;
chat(prompt: string, testMode: boolean, options: StreamingChatOptions): AsyncIterable<ChatResponseChunk>;
chat(prompt: string, imageURL: string, testMode: boolean, options: StreamingChatOptions): AsyncIterable<ChatResponseChunk>;
chat(prompt: string, imageURLArray: string[], testMode: boolean, options: StreamingChatOptions): AsyncIterable<ChatResponseChunk>;
chat(messages: ChatMessage[], testMode: boolean, options: StreamingChatOptions): AsyncIterable<ChatResponseChunk>;
// Non-streaming overloads
chat(prompt: string, options?: NonStreamingChatOptions): Promise<ChatResponse>;
chat(prompt: string, testMode?: boolean, options?: NonStreamingChatOptions): Promise<ChatResponse>;
chat(prompt: string, imageURL?: string, testMode?: boolean, options?: NonStreamingChatOptions): Promise<ChatResponse>;
chat(prompt: string, imageURLArray?: string[], testMode?: boolean, options?: NonStreamingChatOptions): Promise<ChatResponse>;
chat(messages: ChatMessage[], testMode?: boolean, options?: NonStreamingChatOptions): Promise<ChatResponse>;
img2txt(image: string | File | Blob, testMode?: boolean): Promise<string>;
@@ -50,6 +58,9 @@ interface AI {
txt2speech(text: string, language?: string, voice?: string, engine?: string): Promise<HTMLAudioElement>;
}
type StreamingChatOptions = Omit<ChatOptions, "stream"> & { stream: true };
type NonStreamingChatOptions = Omit<ChatOptions, "stream"> & { stream?: false | undefined };
interface ChatOptions {
model?: string;
stream?: boolean;