@devvibex/aiflow 1.0.3 → 1.0.6

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.6",
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
 
@@ -62,6 +79,8 @@ export interface ImageRequest {
62
79
  model?: string;
63
80
  size?: '512x512' | '1024x1024' | '1024x1792' | string;
64
81
  n?: number;
82
+ image?: string;
83
+ images?: string[];
65
84
  signal?: AbortSignal;
66
85
  }
67
86
 
@@ -76,6 +95,45 @@ export interface ImageResponse {
76
95
  usage: { creditsUsed: number };
77
96
  }
78
97
 
98
+ // ─── Video ────────────────────────────────────────────────────────────────────
99
+
100
+ export interface VideoRequest {
101
+ prompt: string;
102
+ model?: string;
103
+ aspectRatio?: '16:9' | '9:16' | '1:1' | string;
104
+ image?: string;
105
+ signal?: AbortSignal;
106
+ }
107
+
108
+ export interface VideoResponse {
109
+ videoUrl: string;
110
+ usage: { creditsUsed: number };
111
+ }
112
+
113
+ // ─── Vision ───────────────────────────────────────────────────────────────────
114
+
115
+ export interface VisionRequest {
116
+ /** Publicly accessible image URL or base64 data-URI. */
117
+ imageUrl: string;
118
+ /** Instruction sent with the image. Defaults to text extraction. */
119
+ prompt?: string;
120
+ model?: string;
121
+ maxTokens?: number;
122
+ signal?: AbortSignal;
123
+ }
124
+
125
+ export interface VisionResponse {
126
+ text: string;
127
+ model: string;
128
+ usage: {
129
+ inputTokens: number;
130
+ outputTokens: number;
131
+ creditsUsed: number;
132
+ };
133
+ }
134
+
135
+ // ─── Embeddings ───────────────────────────────────────────────────────────────
136
+
79
137
  export interface EmbedRequest {
80
138
  input: string | string[];
81
139
  model?: string;
@@ -99,6 +157,7 @@ export interface AIFlowClientOptions {
99
157
  defaultModel?: string | null;
100
158
  defaultImageModel?: string | null;
101
159
  defaultEmbedModel?: string | null;
160
+ defaultVideoModel?: string | null;
102
161
  timeout?: number;
103
162
  maxRetries?: number;
104
163
  fetch?: typeof fetch;
@@ -110,11 +169,13 @@ export interface AiflowConfig {
110
169
  chat: string[];
111
170
  image: string[];
112
171
  embed: string[];
172
+ video: string[];
113
173
  };
114
174
  defaults: {
115
175
  chat: string;
116
176
  image: string;
117
177
  embed: string;
178
+ video: string;
118
179
  };
119
180
  limits: {
120
181
  maxTokens: number;
@@ -140,7 +201,9 @@ export class AIFlowClient {
140
201
  chat(request: ChatRequest): Promise<ChatResponse>;
141
202
  chatStream(request: ChatRequest): AsyncGenerator<ChatStreamChunk, void, void>;
142
203
  generateImage(request: ImageRequest): Promise<ImageResponse>;
204
+ generateVideo(request: VideoRequest): Promise<VideoResponse>;
143
205
  embed(request: EmbedRequest): Promise<EmbedResponse>;
206
+ vision(request: VisionRequest): Promise<VisionResponse>;
144
207
  }
145
208
 
146
209
  export default AIFlowClient;
package/src/index.js CHANGED
@@ -244,6 +244,8 @@ export class AIFlowClient {
244
244
  model,
245
245
  size = '1024x1024',
246
246
  n = 1,
247
+ image,
248
+ images,
247
249
  signal,
248
250
  } = {}) {
249
251
  if (!prompt || typeof prompt !== 'string') {
@@ -258,12 +260,69 @@ export class AIFlowClient {
258
260
  prompt,
259
261
  size,
260
262
  n,
263
+ image,
264
+ images,
261
265
  },
262
266
  { signal },
263
267
  );
264
268
  return await res.json();
265
269
  }
266
270
 
271
+ /**
272
+ * Generate a video from a text prompt.
273
+ * @returns {Promise<{videoUrl:string, usage:{creditsUsed:number}}>}
274
+ */
275
+ async generateVideo({
276
+ prompt,
277
+ model,
278
+ aspectRatio = '16:9',
279
+ image,
280
+ signal,
281
+ } = {}) {
282
+ if (!prompt || typeof prompt !== 'string') {
283
+ throw new AIFlowError('prompt is required');
284
+ }
285
+ const resolvedModel =
286
+ model || (await this._resolveDefaultModel('video'));
287
+ const res = await this._request(
288
+ '/video',
289
+ {
290
+ model: resolvedModel,
291
+ prompt,
292
+ aspectRatio,
293
+ image,
294
+ },
295
+ { signal },
296
+ );
297
+ return await res.json();
298
+ }
299
+
300
+ /**
301
+ * Extract text (or answer a question) from an image URL using vision models.
302
+ * Defaults to Claude when no model is specified.
303
+ *
304
+ * @param {object} options
305
+ * @param {string} options.imageUrl Publicly accessible image URL (or base64 data-URI).
306
+ * @param {string} [options.prompt] Instruction sent alongside the image.
307
+ * Defaults to "Extract all text visible in this image."
308
+ * @param {string} [options.model]
309
+ * @param {number} [options.maxTokens]
310
+ * @param {AbortSignal} [options.signal]
311
+ * @returns {Promise<{text:string, model:string, usage:{inputTokens:number,outputTokens:number,creditsUsed:number}}>}
312
+ */
313
+ async vision({ imageUrl, prompt, model, maxTokens, signal } = {}) {
314
+ if (!imageUrl || typeof imageUrl !== 'string') {
315
+ throw new AIFlowError('imageUrl is required');
316
+ }
317
+ const resolvedModel = model || (await this._resolveDefaultModel('chat'));
318
+ const res = await this._request(
319
+ '/vision',
320
+ { imageUrl, prompt, model: resolvedModel, maxTokens },
321
+ { signal },
322
+ );
323
+ return await res.json();
324
+ }
325
+
267
326
  /**
268
327
  * Compute embeddings for one or more input strings.
269
328
  * @returns {Promise<{data: Array<{embedding:number[], index:number}>, usage:{creditsUsed:number}}>}