@ooneex/ai 1.1.13 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,30 +2,12 @@ import { Exception } from "@ooneex/exception";
2
2
  declare class AiException extends Exception {
3
3
  constructor(message: string, key: string, data?: Record<string, unknown>);
4
4
  }
5
- import { AppEnv } from "@ooneex/app-env";
6
5
  import { ModelMessage } from "@tanstack/ai";
7
6
  import { LocaleType } from "@ooneex/translation";
8
7
  import { AssertType } from "@ooneex/validation";
9
- import { ImageGenerationResult, TTSResult } from "@tanstack/ai";
10
- import { anthropicText } from "@tanstack/ai-anthropic";
11
- import { GeminiAspectRatio, GeminiImageProviderOptions, GeminiTTSVoice, geminiText } from "@tanstack/ai-gemini";
12
- import { groqText } from "@tanstack/ai-groq";
13
- import { ollamaText } from "@tanstack/ai-ollama";
14
- import { OpenAITranscriptionProviderOptions, OpenAITTSFormat, OpenAITTSVoice, openaiText } from "@tanstack/ai-openai";
15
- import { TranscriptionResult, TranscriptionSegment, TranscriptionWord } from "@tanstack/ai";
8
+ import { createOpenRouterText } from "@tanstack/ai-openrouter";
16
9
  type AiClassType = new (...args: any[]) => IAiChat<any>;
17
- type OpenAiModelType = Parameters<typeof openaiText>[0];
18
- type AnthropicModelType = Parameters<typeof anthropicText>[0];
19
- type GeminiModelType = Parameters<typeof geminiText>[0];
20
- type GroqModelType = Parameters<typeof groqText>[0];
21
- type OllamaModelType = Parameters<typeof ollamaText>[0];
22
- type OpenAiTTSModelType = "tts-1" | "tts-1-hd" | "gpt-4o-audio-preview";
23
- type OpenAiSTTModelType = "whisper-1" | "gpt-4o-transcribe" | "gpt-4o-mini-transcribe" | "gpt-4o-transcribe-diarize";
24
- type GeminiTTSModelType = "gemini-2.5-flash-preview-tts" | "gemini-2.5-pro-preview-tts";
25
- type OpenAiImageModelType = "gpt-image-1" | "gpt-image-1-mini" | "dall-e-3" | "dall-e-2";
26
- type OpenAiImageSizeType = "1024x1024" | "1536x1024" | "1024x1536" | "1792x1024" | "1024x1792" | "256x256" | "512x512" | "auto";
27
- type GeminiImageModelType = "gemini-2.5-flash-image" | "gemini-2.0-flash-preview-image-generation" | "imagen-3.0-generate-002" | "imagen-4.0-generate-001" | "imagen-4.0-fast-generate-001" | "imagen-4.0-ultra-generate-001";
28
- type GeminiImageSizeType = "1024x1024" | "512x512" | "1024x768" | "1536x1024" | "1792x1024" | "1920x1080" | "768x1024" | "1024x1536" | "1024x1792" | "1080x1920";
10
+ type OpenRouterModelType = Parameters<typeof createOpenRouterText>[0];
29
11
  type GenerateQuestionOptionsType = {
30
12
  choiceCount?: number;
31
13
  correctChoiceCount?: number;
@@ -77,13 +59,38 @@ type AiImageSourceType = {
77
59
  type: "url" | "data";
78
60
  value: string;
79
61
  };
62
+ type AiAudioSourceType = {
63
+ type: "url" | "data";
64
+ value: string;
65
+ };
66
+ type AiVideoResultType = {
67
+ jobId: string;
68
+ url?: string | undefined;
69
+ status: "pending" | "processing" | "completed" | "failed";
70
+ error?: string | undefined;
71
+ };
72
+ type AiSpeechFormatType = "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
73
+ type AiSpeechResultType = {
74
+ audio: string;
75
+ format: AiSpeechFormatType;
76
+ duration?: number | undefined;
77
+ contentType?: string | undefined;
78
+ };
79
+ type AiImageResultType = {
80
+ url: string;
81
+ revisedPrompt?: string | undefined;
82
+ };
83
+ type AiVideoSourceType = {
84
+ type: "url" | "data";
85
+ value: string;
86
+ };
80
87
  type AiMessageType = {
81
88
  role: "user" | "assistant" | "system" | "tool";
82
89
  content: string;
83
90
  };
84
91
  type AiConfigType = {
85
92
  apiKey?: string;
86
- model?: OpenAiModelType | AnthropicModelType | GeminiModelType | GroqModelType | OllamaModelType;
93
+ model?: OpenRouterModelType;
87
94
  wordCount?: number;
88
95
  stream?: boolean;
89
96
  language?: LocaleType;
@@ -94,80 +101,7 @@ type AiConfigType = {
94
101
  count?: number;
95
102
  output?: AssertType;
96
103
  };
97
- type OpenAiConfigType = Omit<AiConfigType, "model"> & {
98
- model?: OpenAiModelType;
99
- };
100
- type AnthropicConfigType = Omit<AiConfigType, "model"> & {
101
- model?: AnthropicModelType;
102
- };
103
- type GeminiConfigType = Omit<AiConfigType, "model"> & {
104
- model?: GeminiModelType;
105
- };
106
- type GroqConfigType = Omit<AiConfigType, "model"> & {
107
- model?: GroqModelType;
108
- };
109
- type OllamaConfigType = Omit<AiConfigType, "model" | "apiKey"> & {
110
- host?: string;
111
- model?: OllamaModelType;
112
- };
113
- type OpenAiTextToSpeechOptionsType = {
114
- apiKey?: string;
115
- model?: OpenAiTTSModelType;
116
- voice?: OpenAITTSVoice;
117
- format?: OpenAITTSFormat;
118
- speed?: number;
119
- language?: string;
120
- instructions?: string;
121
- };
122
- type OpenAiSpeechToTextOptionsType = {
123
- apiKey?: string;
124
- model?: OpenAiSTTModelType;
125
- language?: string;
126
- prompt?: string;
127
- responseFormat?: "json" | "text" | "srt" | "verbose_json" | "vtt";
128
- modelOptions?: OpenAITranscriptionProviderOptions;
129
- };
130
- type GroqTTSModelType = "canopylabs/orpheus-v1-english" | "canopylabs/orpheus-arabic-saudi";
131
- type GroqTTSVoiceType = "autumn" | "diana" | "hannah" | "austin" | "daniel" | "troy" | "fahad" | "sultan" | "lulwa" | "noura";
132
- type GroqTTSFormatType = "wav" | "mp3" | "flac" | "ogg" | "mulaw";
133
- type GroqTextToSpeechOptionsType = {
134
- apiKey?: string;
135
- model?: GroqTTSModelType;
136
- voice?: GroqTTSVoiceType;
137
- format?: GroqTTSFormatType;
138
- sampleRate?: number;
139
- };
140
- type GeminiTextToSpeechOptionsType = {
141
- apiKey?: string;
142
- model?: GeminiTTSModelType;
143
- voice?: GeminiTTSVoice;
144
- format?: "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
145
- speed?: number;
146
- instructions?: string;
147
- language?: string;
148
- };
149
- type OpenAiGenerateImageOptionsType = {
150
- apiKey?: string;
151
- model?: OpenAiImageModelType;
152
- numberOfImages?: number;
153
- size?: OpenAiImageSizeType;
154
- quality?: "high" | "medium" | "low" | "auto" | "hd" | "standard";
155
- background?: "transparent" | "opaque" | "auto";
156
- outputFormat?: "png" | "jpeg" | "webp";
157
- moderation?: "low" | "auto";
158
- style?: "vivid" | "natural";
159
- };
160
- type GeminiGenerateImageOptionsType = {
161
- apiKey?: string;
162
- model?: GeminiImageModelType;
163
- numberOfImages?: number;
164
- size?: GeminiImageSizeType;
165
- aspectRatio?: GeminiAspectRatio;
166
- personGeneration?: "DONT_ALLOW" | "ALLOW_ADULT" | "ALLOW_ALL";
167
- negativePrompt?: string;
168
- addWatermark?: boolean;
169
- outputMimeType?: "image/png" | "image/jpeg" | "image/webp";
170
- };
104
+ type OpenRouterConfigType = AiConfigType;
171
105
  interface IAiChat<TConfig extends AiConfigType = AiConfigType> {
172
106
  makeShorter?: (content: string, config?: TConfig) => Promise<string>;
173
107
  makeLonger?: (content: string, config?: TConfig) => Promise<string>;
@@ -190,16 +124,35 @@ interface IAiChat<TConfig extends AiConfigType = AiConfigType> {
190
124
  generateCaseQuestion?: (subject: string, options?: GenerateCaseQuestionOptionsType, config?: TConfig) => Promise<GenerateCaseQuestionResultType>;
191
125
  generateFlashcard?: (subject: string, options?: GenerateFlashcardOptionsType, config?: TConfig) => Promise<GenerateFlashcardResultType>;
192
126
  generateQuestion?: (subject: string, options?: GenerateQuestionOptionsType, config?: TConfig) => Promise<GenerateQuestionResultType>;
127
+ describeImage?: (source: AiImageSourceType, config?: Omit<TConfig, "output">) => Promise<string>;
193
128
  imageToMarkdown?: (source: AiImageSourceType, config?: Omit<TConfig, "output">) => Promise<string>;
129
+ imageToText?: (source: AiImageSourceType, config?: Omit<TConfig, "output">) => Promise<string>;
130
+ speechToText?: (source: AiAudioSourceType, config?: Omit<TConfig, "output">) => Promise<string>;
131
+ videoToText?: (source: AiVideoSourceType, config?: Omit<TConfig, "output">) => Promise<string>;
132
+ imageToImage?: (source: AiImageSourceType, prompt: string, config?: Omit<TConfig, "output"> & {
133
+ size?: string;
134
+ quality?: "standard" | "hd";
135
+ }) => Promise<AiImageResultType>;
136
+ textToImage?: (prompt: string, config?: Omit<TConfig, "output"> & {
137
+ size?: string;
138
+ quality?: "standard" | "hd";
139
+ }) => Promise<AiImageResultType>;
140
+ textToSpeech?: (text: string, config?: Omit<TConfig, "output"> & {
141
+ voice?: string;
142
+ format?: AiSpeechFormatType;
143
+ speed?: number;
144
+ }) => Promise<AiSpeechResultType>;
145
+ textToVideo?: (prompt: string, config?: Omit<TConfig, "output">) => Promise<AiVideoResultType>;
146
+ getVideoStatus?: (jobId: string, config?: Omit<TConfig, "output">) => Promise<AiVideoResultType>;
194
147
  run: <T>(content: string, config?: TConfig) => Promise<T>;
195
148
  runStream: (content: string, config?: TConfig) => AsyncGenerator<string, void, unknown>;
196
149
  }
197
150
  declare abstract class BaseAi<TConfig extends AiConfigType> implements IAiChat<TConfig> {
198
- protected abstract createChatAdapter(config?: TConfig): any;
199
- protected abstract createRunAdapter(config?: TConfig): any;
151
+ protected abstract createChatAdapter(config?: TConfig, task?: string): any;
152
+ protected abstract createRunAdapter(config?: TConfig, task?: string): any;
200
153
  protected buildPrompt(instruction: string, config?: TConfig): string;
201
154
  protected toMessages(messages: AiMessageType[]): ModelMessage[];
202
- protected executeChat(content: string, systemPrompt: string, config?: TConfig): Promise<string>;
155
+ protected executeChat(content: string, systemPrompt: string, config?: TConfig, task?: string): Promise<string>;
203
156
  makeShorter(content: string, config?: Omit<TConfig, "output">): Promise<string>;
204
157
  makeLonger(content: string, config?: Omit<TConfig, "output">): Promise<string>;
205
158
  summarize(content: string, config?: Omit<TConfig, "output">): Promise<string>;
@@ -221,60 +174,53 @@ declare abstract class BaseAi<TConfig extends AiConfigType> implements IAiChat<T
221
174
  generateCaseQuestion(subject: string, options?: GenerateCaseQuestionOptionsType, config?: TConfig): Promise<GenerateCaseQuestionResultType>;
222
175
  generateFlashcard(subject: string, options?: GenerateFlashcardOptionsType, config?: TConfig): Promise<GenerateFlashcardResultType>;
223
176
  generateQuestion(subject: string, options?: GenerateQuestionOptionsType, config?: TConfig): Promise<GenerateQuestionResultType>;
177
+ describeImage(source: AiImageSourceType, config?: Omit<TConfig, "output">): Promise<string>;
224
178
  imageToMarkdown(source: AiImageSourceType, config?: Omit<TConfig, "output">): Promise<string>;
179
+ imageToText(source: AiImageSourceType, config?: Omit<TConfig, "output">): Promise<string>;
180
+ speechToText(source: AiAudioSourceType, config?: Omit<TConfig, "output">): Promise<string>;
181
+ videoToText(source: AiVideoSourceType, config?: Omit<TConfig, "output">): Promise<string>;
182
+ abstract textToImage(prompt: string, config?: Omit<TConfig, "output"> & {
183
+ size?: string;
184
+ quality?: "standard" | "hd";
185
+ }): Promise<AiImageResultType>;
186
+ abstract textToSpeech(text: string, config?: Omit<TConfig, "output"> & {
187
+ voice?: string;
188
+ format?: AiSpeechFormatType;
189
+ speed?: number;
190
+ }): Promise<AiSpeechResultType>;
191
+ abstract textToVideo(prompt: string, config?: Omit<TConfig, "output">): Promise<AiVideoResultType>;
192
+ abstract getVideoStatus(jobId: string, config?: Omit<TConfig, "output">): Promise<AiVideoResultType>;
225
193
  run<T>(prompt: string, config?: Omit<TConfig, "prompt">): Promise<T>;
226
194
  runStream(prompt: string, config?: Omit<TConfig, "prompt" | "output">): AsyncGenerator<string, void, unknown>;
227
195
  }
228
- declare class AnthropicAi extends BaseAi<AnthropicConfigType> {
229
- private readonly env;
230
- constructor(env: AppEnv);
231
- private getApiKey;
232
- protected createChatAdapter(config?: AnthropicConfigType);
233
- protected createRunAdapter(config?: AnthropicConfigType);
234
- }
235
196
  import { EContainerScope } from "@ooneex/container";
236
197
  declare const decorator: {
237
198
  ai: (scope?: EContainerScope) => (target: AiClassType) => void;
238
199
  };
239
- import { AppEnv as AppEnv2 } from "@ooneex/app-env";
240
- import { ImageGenerationResult as ImageGenerationResult2, TTSResult as TTSResult2 } from "@tanstack/ai";
241
- declare class GeminiAi extends BaseAi<GeminiConfigType> {
242
- private readonly env;
243
- constructor(env: AppEnv2);
244
- private getApiKey;
245
- protected createChatAdapter(config?: GeminiConfigType);
246
- protected createRunAdapter(config?: GeminiConfigType);
247
- textToSpeech(text: string, options?: GeminiTextToSpeechOptionsType): Promise<TTSResult2>;
248
- generateImage(prompt: string, options?: GeminiGenerateImageOptionsType): Promise<ImageGenerationResult2>;
249
- }
250
- import { AppEnv as AppEnv3 } from "@ooneex/app-env";
251
- import { TTSResult as TTSResult3 } from "@tanstack/ai";
252
- declare class GroqAi extends BaseAi<GroqConfigType> {
253
- private readonly env;
254
- constructor(env: AppEnv3);
255
- private getApiKey;
256
- protected createChatAdapter(config?: GroqConfigType);
257
- protected createRunAdapter(config?: GroqConfigType);
258
- textToSpeech(text: string, options?: GroqTextToSpeechOptionsType): Promise<TTSResult3>;
259
- }
260
- import { AppEnv as AppEnv4 } from "@ooneex/app-env";
261
- declare class OllamaAi extends BaseAi<OllamaConfigType> {
262
- private readonly env;
263
- constructor(env: AppEnv4);
264
- private getHost;
265
- protected createChatAdapter(config?: OllamaConfigType);
266
- protected createRunAdapter(config?: OllamaConfigType);
267
- }
268
- import { AppEnv as AppEnv5 } from "@ooneex/app-env";
269
- import { ImageGenerationResult as ImageGenerationResult3, TranscriptionResult as TranscriptionResult2, TTSResult as TTSResult4 } from "@tanstack/ai";
270
- declare class OpenAi extends BaseAi<OpenAiConfigType> {
200
+ import { AppEnv } from "@ooneex/app-env";
201
+ declare class OpenRouterAi extends BaseAi<OpenRouterConfigType> {
271
202
  private readonly env;
272
- constructor(env: AppEnv5);
203
+ private static readonly DEFAULT_MODELS;
204
+ constructor(env: AppEnv);
273
205
  private getApiKey;
274
- protected createChatAdapter(config?: OpenAiConfigType);
275
- protected createRunAdapter(config?: OpenAiConfigType);
276
- textToSpeech(text: string, options?: OpenAiTextToSpeechOptionsType): Promise<TTSResult4>;
277
- speechToText(audio: string | File | Blob | ArrayBuffer, options?: OpenAiSpeechToTextOptionsType): Promise<TranscriptionResult2>;
278
- generateImage(prompt: string, options?: OpenAiGenerateImageOptionsType): Promise<ImageGenerationResult3>;
206
+ private fetchWithRetry;
207
+ private getDefaultModel;
208
+ textToImage(prompt: string, config?: Omit<OpenRouterConfigType, "output"> & {
209
+ size?: string;
210
+ quality?: "standard" | "hd";
211
+ }): Promise<AiImageResultType>;
212
+ imageToImage(source: AiImageSourceType, prompt: string, config?: Omit<OpenRouterConfigType, "output"> & {
213
+ size?: string;
214
+ quality?: "standard" | "hd";
215
+ }): Promise<AiImageResultType>;
216
+ textToSpeech(text: string, config?: Omit<OpenRouterConfigType, "output"> & {
217
+ voice?: string;
218
+ format?: AiSpeechFormatType;
219
+ speed?: number;
220
+ }): Promise<AiSpeechResultType>;
221
+ textToVideo(prompt: string, config?: Omit<OpenRouterConfigType, "output">): Promise<AiVideoResultType>;
222
+ getVideoStatus(jobId: string, config?: Omit<OpenRouterConfigType, "output">): Promise<AiVideoResultType>;
223
+ protected createChatAdapter(config?: OpenRouterConfigType, task?: string);
224
+ protected createRunAdapter(config?: OpenRouterConfigType, task?: string);
279
225
  }
280
- export { decorator, TranscriptionWord, TranscriptionSegment, TranscriptionResult, TTSResult, OpenAiTextToSpeechOptionsType, OpenAiTTSModelType, OpenAiSpeechToTextOptionsType, OpenAiSTTModelType, OpenAiModelType, OpenAiImageSizeType, OpenAiImageModelType, OpenAiGenerateImageOptionsType, OpenAiConfigType, OpenAi, OpenAITranscriptionProviderOptions, OpenAITTSVoice, OpenAITTSFormat, OllamaModelType, OllamaConfigType, OllamaAi, ImageGenerationResult, IAiChat, GroqTextToSpeechOptionsType, GroqTTSVoiceType, GroqTTSModelType, GroqTTSFormatType, GroqModelType, GroqConfigType, GroqAi, GenerateQuestionResultType, GenerateQuestionOptionsType, GenerateQuestionChoiceType, GenerateFlashcardResultType, GenerateFlashcardOptionsType, GenerateCaseQuestionResultType, GenerateCaseQuestionOptionsType, GeminiTextToSpeechOptionsType, GeminiTTSVoice, GeminiTTSModelType, GeminiModelType, GeminiImageSizeType, GeminiImageProviderOptions, GeminiImageModelType, GeminiGenerateImageOptionsType, GeminiConfigType, GeminiAspectRatio, GeminiAi, CaseQuestionType, CaseQuestionChoiceType, BaseAi, AnthropicModelType, AnthropicConfigType, AnthropicAi, AiToneType, AiMessageType, AiImageSourceType, AiException, AiConfigType, AiClassType };
226
+ export { decorator, OpenRouterModelType, OpenRouterConfigType, OpenRouterAi, IAiChat, GenerateQuestionResultType, GenerateQuestionOptionsType, GenerateQuestionChoiceType, GenerateFlashcardResultType, GenerateFlashcardOptionsType, GenerateCaseQuestionResultType, GenerateCaseQuestionOptionsType, CaseQuestionType, CaseQuestionChoiceType, BaseAi, AiVideoSourceType, AiVideoResultType, AiToneType, AiSpeechResultType, AiSpeechFormatType, AiMessageType, AiImageSourceType, AiImageResultType, AiException, AiConfigType, AiClassType, AiAudioSourceType };