@devvibex/aiflow 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvibex/aiflow",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image generation and embeddings without shipping any third-party API key.",
5
5
  "keywords": [
6
6
  "ai",
package/src/index.d.ts CHANGED
@@ -16,9 +16,26 @@ export class AIFlowError extends Error {
16
16
 
17
17
  export type ChatRole = 'system' | 'user' | 'assistant';
18
18
 
19
+ // ─── Multimodal content blocks ───────────────────────────────────────────────
20
+
21
+ export interface ContentBlockText {
22
+ type: 'text';
23
+ text: string;
24
+ }
25
+
26
+ export interface ContentBlockImageUrl {
27
+ type: 'image_url';
28
+ image_url: { url: string };
29
+ }
30
+
31
+ export type ContentBlock = ContentBlockText | ContentBlockImageUrl;
32
+
33
+ // ─── Chat ─────────────────────────────────────────────────────────────────────
34
+
19
35
  export interface ChatMessage {
20
36
  role: ChatRole;
21
- content: string;
37
+ /** Plain string OR multimodal array of content blocks. */
38
+ content: string | ContentBlock[];
22
39
  name?: string;
23
40
  }
24
41
 
@@ -76,6 +93,44 @@ export interface ImageResponse {
76
93
  usage: { creditsUsed: number };
77
94
  }
78
95
 
96
+ // ─── Video ────────────────────────────────────────────────────────────────────
97
+
98
+ export interface VideoRequest {
99
+ prompt: string;
100
+ model?: string;
101
+ aspectRatio?: '16:9' | '9:16' | '1:1' | string;
102
+ signal?: AbortSignal;
103
+ }
104
+
105
+ export interface VideoResponse {
106
+ videoUrl: string;
107
+ usage: { creditsUsed: number };
108
+ }
109
+
110
+ // ─── Vision ───────────────────────────────────────────────────────────────────
111
+
112
+ export interface VisionRequest {
113
+ /** Publicly accessible image URL or base64 data-URI. */
114
+ imageUrl: string;
115
+ /** Instruction sent with the image. Defaults to text extraction. */
116
+ prompt?: string;
117
+ model?: string;
118
+ maxTokens?: number;
119
+ signal?: AbortSignal;
120
+ }
121
+
122
+ export interface VisionResponse {
123
+ text: string;
124
+ model: string;
125
+ usage: {
126
+ inputTokens: number;
127
+ outputTokens: number;
128
+ creditsUsed: number;
129
+ };
130
+ }
131
+
132
+ // ─── Embeddings ───────────────────────────────────────────────────────────────
133
+
79
134
  export interface EmbedRequest {
80
135
  input: string | string[];
81
136
  model?: string;
@@ -99,6 +154,7 @@ export interface AIFlowClientOptions {
99
154
  defaultModel?: string | null;
100
155
  defaultImageModel?: string | null;
101
156
  defaultEmbedModel?: string | null;
157
+ defaultVideoModel?: string | null;
102
158
  timeout?: number;
103
159
  maxRetries?: number;
104
160
  fetch?: typeof fetch;
@@ -110,11 +166,13 @@ export interface AiflowConfig {
110
166
  chat: string[];
111
167
  image: string[];
112
168
  embed: string[];
169
+ video: string[];
113
170
  };
114
171
  defaults: {
115
172
  chat: string;
116
173
  image: string;
117
174
  embed: string;
175
+ video: string;
118
176
  };
119
177
  limits: {
120
178
  maxTokens: number;
@@ -140,7 +198,9 @@ export class AIFlowClient {
140
198
  chat(request: ChatRequest): Promise<ChatResponse>;
141
199
  chatStream(request: ChatRequest): AsyncGenerator<ChatStreamChunk, void, void>;
142
200
  generateImage(request: ImageRequest): Promise<ImageResponse>;
201
+ generateVideo(request: VideoRequest): Promise<VideoResponse>;
143
202
  embed(request: EmbedRequest): Promise<EmbedResponse>;
203
+ vision(request: VisionRequest): Promise<VisionResponse>;
144
204
  }
145
205
 
146
206
  export default AIFlowClient;
package/src/index.js CHANGED
@@ -264,6 +264,59 @@ export class AIFlowClient {
264
264
  return await res.json();
265
265
  }
266
266
 
267
+ /**
268
+ * Generate a video from a text prompt.
269
+ * @returns {Promise<{videoUrl:string, usage:{creditsUsed:number}}>}
270
+ */
271
+ async generateVideo({
272
+ prompt,
273
+ model,
274
+ aspectRatio = '16:9',
275
+ signal,
276
+ } = {}) {
277
+ if (!prompt || typeof prompt !== 'string') {
278
+ throw new AIFlowError('prompt is required');
279
+ }
280
+ const resolvedModel =
281
+ model || (await this._resolveDefaultModel('video'));
282
+ const res = await this._request(
283
+ '/video',
284
+ {
285
+ model: resolvedModel,
286
+ prompt,
287
+ aspectRatio,
288
+ },
289
+ { signal },
290
+ );
291
+ return await res.json();
292
+ }
293
+
294
+ /**
295
+ * Extract text (or answer a question) from an image URL using vision models.
296
+ * Defaults to Claude when no model is specified.
297
+ *
298
+ * @param {object} options
299
+ * @param {string} options.imageUrl Publicly accessible image URL (or base64 data-URI).
300
+ * @param {string} [options.prompt] Instruction sent alongside the image.
301
+ * Defaults to "Extract all text visible in this image."
302
+ * @param {string} [options.model]
303
+ * @param {number} [options.maxTokens]
304
+ * @param {AbortSignal} [options.signal]
305
+ * @returns {Promise<{text:string, model:string, usage:{inputTokens:number,outputTokens:number,creditsUsed:number}}>}
306
+ */
307
+ async vision({ imageUrl, prompt, model, maxTokens, signal } = {}) {
308
+ if (!imageUrl || typeof imageUrl !== 'string') {
309
+ throw new AIFlowError('imageUrl is required');
310
+ }
311
+ const resolvedModel = model || (await this._resolveDefaultModel('chat'));
312
+ const res = await this._request(
313
+ '/vision',
314
+ { imageUrl, prompt, model: resolvedModel, maxTokens },
315
+ { signal },
316
+ );
317
+ return await res.json();
318
+ }
319
+
267
320
  /**
268
321
  * Compute embeddings for one or more input strings.
269
322
  * @returns {Promise<{data: Array<{embedding:number[], index:number}>, usage:{creditsUsed:number}}>}