@j-o-r/hello-dave 0.0.10 → 0.1.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.
Files changed (76) hide show
  1. package/README.md +2 -0
  2. package/README.md.bak.1779452127 +240 -0
  3. package/TODO.md +30 -8
  4. package/agents/code_agent.js +6 -6
  5. package/agents/daisy_agent.js +10 -7
  6. package/agents/minimax.js +173 -0
  7. package/agents/stability.js +173 -0
  8. package/bin/codeDave +1 -1
  9. package/bin/dave.js +1 -1
  10. package/docs/music-toolsets.md +137 -0
  11. package/docs/plans/minimax-music-generation.md +80 -0
  12. package/docs/plans/unified-agent-architecture.md +146 -0
  13. package/docs/plans/websocket-streaming-plan.md.bak +317 -0
  14. package/docs/prompt/task_clarification_and_documentation.md +35 -0
  15. package/lib/API/minimax/ImageToolset.js +169 -0
  16. package/lib/API/minimax/MusicToolset.js +290 -0
  17. package/lib/API/minimax/VideoToolset.js +296 -0
  18. package/lib/API/minimax/image.generation.md +239 -0
  19. package/lib/API/minimax/image.js +219 -0
  20. package/lib/API/minimax/image.to.image.md +257 -0
  21. package/lib/API/minimax/index.js +16 -0
  22. package/lib/API/minimax/music.cover.preprocess.md +206 -0
  23. package/lib/API/minimax/music.generation.md +346 -0
  24. package/lib/API/minimax/music.js +257 -0
  25. package/lib/API/minimax/music.lyrics.generation.md +205 -0
  26. package/lib/API/minimax/video.download.md +133 -0
  27. package/lib/API/minimax/video.first.last.image.md +186 -0
  28. package/lib/API/minimax/video.from.image.md +206 -0
  29. package/lib/API/minimax/video.from.subject.md +164 -0
  30. package/lib/API/minimax/video.generation.md +192 -0
  31. package/lib/API/minimax/video.js +339 -0
  32. package/lib/API/minimax/video.query.md +128 -0
  33. package/lib/API/stability.ai/ImageToolset.js +357 -0
  34. package/lib/API/stability.ai/MusicToolset.js +302 -0
  35. package/lib/API/stability.ai/audio-3.md +205 -0
  36. package/lib/API/stability.ai/audio.js +679 -0
  37. package/lib/API/stability.ai/image.js +911 -0
  38. package/lib/API/stability.ai/image.md +271 -0
  39. package/lib/API/stability.ai/index.js +11 -0
  40. package/lib/API/stability.ai/openapi.json +17118 -0
  41. package/lib/API/x.ai/ImageToolset.js +165 -0
  42. package/lib/API/x.ai/image.editing.md +86 -0
  43. package/lib/API/x.ai/image.js +393 -0
  44. package/lib/API/x.ai/image.md +213 -0
  45. package/lib/API/x.ai/image.to.generation.md +494 -0
  46. package/lib/API/x.ai/image.to.video.md +23 -0
  47. package/lib/API/x.ai/index.js +9 -0
  48. package/lib/AgentManager.js +1 -1
  49. package/lib/CdnToolset.js +191 -0
  50. package/lib/ToolSet.js +19 -1
  51. package/lib/cdn.js +373 -0
  52. package/lib/fafs.js +3 -1
  53. package/lib/genericToolset.js +43 -166
  54. package/lib/index.js +9 -1
  55. package/package.json +2 -2
  56. package/types/API/minimax/ImageToolset.d.ts +3 -0
  57. package/types/API/minimax/MusicToolset.d.ts +3 -0
  58. package/types/API/minimax/VideoToolset.d.ts +3 -0
  59. package/types/API/minimax/image.d.ts +109 -0
  60. package/types/API/minimax/index.d.ts +15 -0
  61. package/types/API/minimax/music.d.ts +46 -0
  62. package/types/API/minimax/video.d.ts +165 -0
  63. package/types/API/stability.ai/ImageToolset.d.ts +3 -0
  64. package/types/API/stability.ai/MusicToolset.d.ts +3 -0
  65. package/types/API/stability.ai/audio.d.ts +193 -0
  66. package/types/API/stability.ai/image.d.ts +274 -0
  67. package/types/API/stability.ai/index.d.ts +11 -0
  68. package/types/API/x.ai/ImageToolset.d.ts +3 -0
  69. package/types/API/x.ai/image.d.ts +82 -0
  70. package/types/API/x.ai/index.d.ts +9 -0
  71. package/types/AgentManager.d.ts +1 -1
  72. package/types/CdnToolset.d.ts +20 -0
  73. package/types/ToolSet.d.ts +8 -0
  74. package/types/cdn.d.ts +141 -0
  75. package/types/index.d.ts +8 -2
  76. package/docs/multi-agent-clusters.md.bak +0 -229
@@ -0,0 +1,339 @@
1
+ /**
2
+ * @file lib/API/minimax/video.js
3
+ * @module minimax/video
4
+ * @description Pure HTTP wrapper for the Minimax Video Generation API.
5
+ * Fully aligned with the official documentation:
6
+ * - lib/API/minimax/video.generation.md
7
+ * - lib/API/minimax/video.query.md
8
+ * - lib/API/minimax/video.download.md
9
+ * - lib/API/minimax/video.from.image.md
10
+ * - lib/API/minimax/video.first.last.image.md
11
+ * - lib/API/minimax/video.from.subject.md
12
+ *
13
+ * This is a **new library** — only the current response format is supported.
14
+ * No backward compatibility with legacy response structures.
15
+ *
16
+ * This module only handles communication with Minimax endpoints.
17
+ * It does NOT handle file publishing, SSH, or CDN logic.
18
+ *
19
+ * For publishing generated or reference files to a remote CDN,
20
+ * use the reusable `lib/cdn.js` module instead.
21
+ *
22
+ * Video generation is asynchronous:
23
+ * 1. Create task → returns task_id
24
+ * 2. Poll query until status === 'Success' (or Fail)
25
+ * 3. Retrieve file_id → get download_url
26
+ * 4. Download video to local .cache/minimax/
27
+ */
28
+
29
+ import { request as doRequest } from '@j-o-r/apiserver';
30
+ import fs from 'fs/promises';
31
+ import path from 'path';
32
+
33
+ const BASE_URL = 'https://api.minimax.io/v1';
34
+
35
+ // All temporary files (audio, images, video) are saved under this directory
36
+ const TMP_DIR = path.join(process.cwd(), '.cache', 'minimax');
37
+
38
+ /**
39
+ * Get authentication headers for Minimax API.
40
+ *
41
+ * @returns {Object} Headers object with Authorization Bearer token.
42
+ * @throws {Error} If MINIMAX_API_KEY environment variable is not set.
43
+ */
44
+ const getHeaders = () => {
45
+ if (!process.env.MINIMAX_API_KEY) {
46
+ throw new Error('Missing MINIMAX_API_KEY! Please export MINIMAX_API_KEY=your_key');
47
+ }
48
+ return {
49
+ 'Content-Type': 'application/json',
50
+ 'Authorization': `Bearer ${process.env.MINIMAX_API_KEY}`
51
+ };
52
+ };
53
+
54
+ /**
55
+ * Saves video data from a download URL to a local temporary file.
56
+ * Handles MP4 videos.
57
+ *
58
+ * @param {string} videoUrl - Public download URL from retrieveVideoFile().
59
+ * @param {string} [filenamePrefix='minimax-video'] - Prefix for the local filename.
60
+ * @returns {Promise<string>} Absolute path to the saved local file.
61
+ */
62
+ async function saveVideoToLocal(videoUrl, filenamePrefix = 'minimax-video') {
63
+ const tmpDir = path.join(process.cwd(), '.cache', 'minimax');
64
+ await fs.mkdir(tmpDir, { recursive: true });
65
+
66
+ const filename = `${filenamePrefix}-${Date.now()}.mp4`;
67
+ const localPath = path.join(tmpDir, filename);
68
+
69
+ if (typeof videoUrl === 'string' && videoUrl.startsWith('http')) {
70
+ const response = await fetch(videoUrl);
71
+ if (!response.ok) {
72
+ throw new Error(`Failed to download video: ${response.status} ${response.statusText}`);
73
+ }
74
+ const buffer = Buffer.from(await response.arrayBuffer());
75
+ await fs.writeFile(localPath, buffer);
76
+ } else {
77
+ throw new Error('Invalid video URL provided to saveVideoToLocal');
78
+ }
79
+
80
+ return localPath;
81
+ }
82
+
83
+ /**
84
+ * Internal helper: Waits for video generation task to complete by polling.
85
+ *
86
+ * @param {string} taskId
87
+ * @param {number} [maxWaitMs=300000] - Max wait time (5 minutes default)
88
+ * @param {number} [pollIntervalMs=5000] - Poll every 5 seconds
89
+ * @returns {Promise<{status: string, file_id?: string, video_width?: number, video_height?: number, raw: object}>}
90
+ */
91
+ async function waitForVideoReady(taskId, maxWaitMs = 300000, pollIntervalMs = 5000) {
92
+ const startTime = Date.now();
93
+ let lastStatus = '';
94
+
95
+ while (Date.now() - startTime < maxWaitMs) {
96
+ const result = await queryVideoGenerationTask(taskId);
97
+ const status = result.status;
98
+
99
+ if (status !== lastStatus) {
100
+ console.log(`[Minimax Video] Task ${taskId} status: ${status}`);
101
+ lastStatus = status;
102
+ }
103
+
104
+ if (status === 'Success') {
105
+ return result;
106
+ }
107
+ if (status === 'Fail') {
108
+ throw new Error(`Video generation failed: ${JSON.stringify(result.raw)}`);
109
+ }
110
+
111
+ await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
112
+ }
113
+
114
+ throw new Error(`Video generation timed out after ${maxWaitMs / 1000}s. Last status: ${lastStatus}`);
115
+ }
116
+
117
+ /**
118
+ * Creates a video generation task (Text-to-Video, Image-to-Video, First-Last, Subject-Ref).
119
+ *
120
+ * Uses POST /v1/video_generation.
121
+ * Supports all documented models and input types via options.
122
+ *
123
+ * @param {string} [prompt] - Text description (required for most modes).
124
+ * @param {Object} [options]
125
+ *
126
+ * @param {string} [options.model='MiniMax-Hailuo-2.3'] - Default model.
127
+ * Supported: MiniMax-Hailuo-2.3, MiniMax-Hailuo-02, T2V-01, I2V-01, S2V-01, etc.
128
+ *
129
+ * @param {string} [options.first_frame_image] - URL or data: URL for image-to-video / first-last.
130
+ * @param {string} [options.last_frame_image] - For first & last frame mode.
131
+ * @param {Array<Object>} [options.subject_reference] - For subject-reference mode.
132
+ *
133
+ * @param {boolean} [options.prompt_optimizer=true]
134
+ * @param {boolean} [options.fast_pretreatment=false]
135
+ * @param {number} [options.duration=6]
136
+ * @param {string} [options.resolution] - e.g. '768P', '1080P'
137
+ * @param {string} [options.callback_url]
138
+ *
139
+ * @returns {Promise<{task_id: string, raw: object}>}
140
+ */
141
+ async function createVideoGenerationTask(prompt = '', options = {}) {
142
+ const headers = getHeaders();
143
+ const url = `${BASE_URL}/video_generation`;
144
+
145
+ const body = {
146
+ model: options.model || 'MiniMax-Hailuo-2.3',
147
+ prompt: prompt,
148
+ prompt_optimizer: options.prompt_optimizer ?? true,
149
+ fast_pretreatment: options.fast_pretreatment ?? false,
150
+ duration: options.duration ?? 6,
151
+ ...options.extra
152
+ };
153
+
154
+ if (options.resolution) body.resolution = options.resolution;
155
+ if (options.callback_url) body.callback_url = options.callback_url;
156
+ if (options.first_frame_image) body.first_frame_image = options.first_frame_image;
157
+ if (options.last_frame_image) body.last_frame_image = options.last_frame_image;
158
+ if (options.subject_reference) body.subject_reference = options.subject_reference;
159
+
160
+ const start = Date.now();
161
+ const res = await doRequest(url, 'POST', headers, body);
162
+ const duration = Date.now() - start;
163
+
164
+ if (res.status !== 200) {
165
+ throw new Error(`Minimax video generation error ${res.status}: ${JSON.stringify(res.response)}`);
166
+ }
167
+
168
+ return {
169
+ task_id: res.response?.task_id,
170
+ duration,
171
+ raw: res.response
172
+ };
173
+ }
174
+
175
+ /**
176
+ * Queries the status of a video generation task.
177
+ *
178
+ * GET /v1/query/video_generation?task_id=...
179
+ *
180
+ * @param {string} taskId
181
+ * @returns {Promise<{
182
+ * task_id: string,
183
+ * status: 'Preparing' | 'Queueing' | 'Processing' | 'Success' | 'Fail',
184
+ * file_id?: string,
185
+ * video_width?: number,
186
+ * video_height?: number,
187
+ * raw: object
188
+ * }>}
189
+ */
190
+ async function queryVideoGenerationTask(taskId) {
191
+ const headers = getHeaders();
192
+ const url = `${BASE_URL}/query/video_generation?task_id=${encodeURIComponent(taskId)}`;
193
+
194
+ const res = await doRequest(url, 'GET', headers);
195
+
196
+ if (res.status !== 200) {
197
+ throw new Error(`Minimax query error ${res.status}: ${JSON.stringify(res.response)}`);
198
+ }
199
+
200
+ return {
201
+ task_id: res.response?.task_id,
202
+ status: res.response?.status,
203
+ file_id: res.response?.file_id,
204
+ video_width: res.response?.video_width,
205
+ video_height: res.response?.video_height,
206
+ raw: res.response
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Retrieves file metadata and download URL for a completed video.
212
+ *
213
+ * GET /v1/files/retrieve?file_id=...
214
+ *
215
+ * @param {string|number} fileId
216
+ * @returns {Promise<{
217
+ * file_id: string,
218
+ * filename: string,
219
+ * download_url: string,
220
+ * bytes: number,
221
+ * raw: object
222
+ * }>}
223
+ */
224
+ async function retrieveVideoFile(fileId) {
225
+ const headers = getHeaders();
226
+ const url = `${BASE_URL}/files/retrieve?file_id=${encodeURIComponent(fileId)}`;
227
+
228
+ const res = await doRequest(url, 'GET', headers);
229
+
230
+ if (res.status !== 200) {
231
+ throw new Error(`Minimax retrieve file error ${res.status}: ${JSON.stringify(res.response)}`);
232
+ }
233
+
234
+ const file = res.response?.file || {};
235
+
236
+ return {
237
+ file_id: file.file_id,
238
+ filename: file.filename,
239
+ download_url: file.download_url,
240
+ bytes: file.bytes,
241
+ raw: res.response
242
+ };
243
+ }
244
+
245
+ /**
246
+ * High-level video generation function.
247
+ * Handles the full async flow: create task → poll until ready → retrieve → download to .cache/minimax/
248
+ *
249
+ * Supports all video generation modes (text, image-to-video, first-last, subject-ref)
250
+ * by passing the appropriate options.
251
+ *
252
+ * @param {string} prompt - Text prompt (can be empty for some modes).
253
+ * @param {Object} [options] - Same as createVideoGenerationTask + polling options.
254
+ *
255
+ * @param {number} [options.max_wait_ms=300000]
256
+ * @param {number} [options.poll_interval_ms=5000]
257
+ *
258
+ * @returns {Promise<{
259
+ * task_id: string,
260
+ * file_id: string,
261
+ * video_url: string, // download_url
262
+ * local_path: string, // path in .cache/minimax/
263
+ * video_width: number,
264
+ * video_height: number,
265
+ * duration: number, // total time including polling
266
+ * raw: object
267
+ * }>}
268
+ *
269
+ * @example
270
+ * // Text-to-Video
271
+ * const result = await generateVideo("A cat jumping on a table [Pan left]", {
272
+ * model: "MiniMax-Hailuo-2.3",
273
+ * duration: 6,
274
+ * resolution: "768P"
275
+ * });
276
+ *
277
+ * @example
278
+ * // Image-to-Video
279
+ * const result = await generateVideo("The character walks forward", {
280
+ * model: "MiniMax-Hailuo-2.3",
281
+ * first_frame_image: "https://example.com/image.jpg"
282
+ * });
283
+ */
284
+ async function generateVideo(prompt = '', options = {}) {
285
+ const start = Date.now();
286
+
287
+ // Step 1: Create task
288
+ const createResult = await createVideoGenerationTask(prompt, options);
289
+ const taskId = createResult.task_id;
290
+
291
+ if (!taskId) {
292
+ throw new Error('No task_id returned from video generation');
293
+ }
294
+
295
+ // Step 2: Wait for completion
296
+ const readyResult = await waitForVideoReady(
297
+ taskId,
298
+ options.max_wait_ms ?? 300000,
299
+ options.poll_interval_ms ?? 5000
300
+ );
301
+
302
+ const fileId = readyResult.file_id;
303
+ if (!fileId) {
304
+ throw new Error('No file_id in successful video response');
305
+ }
306
+
307
+ // Step 3: Retrieve download URL
308
+ const fileResult = await retrieveVideoFile(fileId);
309
+
310
+ // Step 4: Download to local
311
+ const localPath = await saveVideoToLocal(fileResult.download_url, 'minimax-video');
312
+
313
+ const totalDuration = Date.now() - start;
314
+
315
+ return {
316
+ task_id: taskId,
317
+ file_id: fileId,
318
+ video_url: fileResult.download_url,
319
+ local_path: localPath,
320
+ video_width: readyResult.video_width,
321
+ video_height: readyResult.video_height,
322
+ duration: totalDuration,
323
+ raw: {
324
+ create: createResult.raw,
325
+ query: readyResult.raw,
326
+ retrieve: fileResult.raw
327
+ }
328
+ };
329
+ }
330
+
331
+ export {
332
+ getHeaders,
333
+ saveVideoToLocal,
334
+ createVideoGenerationTask,
335
+ queryVideoGenerationTask,
336
+ retrieveVideoFile,
337
+ generateVideo,
338
+ waitForVideoReady
339
+ };
@@ -0,0 +1,128 @@
1
+ > ## Documentation Index
2
+ > Fetch the complete documentation index at: https://platform.minimax.io/docs/llms.txt
3
+ > Use this file to discover all available pages before exploring further.
4
+
5
+ # Query Video Generation Task Status
6
+
7
+
8
+
9
+ ## OpenAPI
10
+
11
+ ````yaml /api-reference/video/generation/api/openapi.json GET /v1/query/video_generation
12
+ openapi: 3.1.0
13
+ info:
14
+ title: MiniMax API
15
+ description: MiniMax video generation and file management API
16
+ license:
17
+ name: MIT
18
+ version: 1.0.0
19
+ servers:
20
+ - url: https://api.minimax.io
21
+ security:
22
+ - bearerAuth: []
23
+ paths:
24
+ /v1/query/video_generation:
25
+ get:
26
+ tags:
27
+ - Video
28
+ summary: Query Video Generation Task
29
+ operationId: queryVideoGenerationTask
30
+ parameters:
31
+ - name: task_id
32
+ in: query
33
+ required: true
34
+ description: >-
35
+ The task ID to query. Only tasks created under the current account
36
+ can be queried.
37
+ schema:
38
+ type: string
39
+ responses:
40
+ '200':
41
+ description: ''
42
+ content:
43
+ application/json:
44
+ schema:
45
+ $ref: '#/components/schemas/QueryVideoGenerationTaskResp'
46
+ components:
47
+ schemas:
48
+ QueryVideoGenerationTaskResp:
49
+ type: object
50
+ properties:
51
+ task_id:
52
+ type: string
53
+ description: The queried task ID.
54
+ status:
55
+ $ref: '#/components/schemas/VideoProcessStatus'
56
+ file_id:
57
+ type: string
58
+ description: >-
59
+ Returned when the task succeeds. Represents the file ID of the
60
+ generated video.
61
+ video_width:
62
+ type: integer
63
+ description: >-
64
+ Returned when the task succeeds. The width of the generated video
65
+ (in pixels).
66
+ video_height:
67
+ type: integer
68
+ description: >-
69
+ Returned when the task succeeds. The height of the generated video
70
+ (in pixels).
71
+ base_resp:
72
+ $ref: '#/components/schemas/QueryVideoGenerationTaskBaseResp'
73
+ example:
74
+ task_id: '176843862716480'
75
+ status: Success
76
+ file_id: '176844028768320'
77
+ video_width: 1920
78
+ video_height: 1080
79
+ base_resp:
80
+ status_code: 0
81
+ status_msg: success
82
+ VideoProcessStatus:
83
+ type: string
84
+ enum:
85
+ - Preparing
86
+ - Queueing
87
+ - Processing
88
+ - Success
89
+ - Fail
90
+ description: |-
91
+ The current status of the task. Possible values:
92
+ - `Preparing` – Preparing
93
+ - `Queueing` – In queue
94
+ - `Processing` – Generating
95
+ - `Success` – Completed successfully
96
+ - `Fail` – Failed
97
+ QueryVideoGenerationTaskBaseResp:
98
+ type: object
99
+ properties:
100
+ status_code:
101
+ type: integer
102
+ description: |-
103
+ The status codes are as follows:
104
+ - `0`, Request successful;
105
+ - `1002`, Rate limit triggered, retry later
106
+ - `1004`, Authentication failed, check API Key
107
+ - `1026`, Contains sensitive content in the input
108
+ - `1027`, Contains sensitive content in the generated video
109
+
110
+ For more information, please refer to the [Error Code Reference](/api-reference/errorcode).
111
+ status_msg:
112
+ type: string
113
+ description: Status message. Returns `success` when successful.
114
+ securitySchemes:
115
+ bearerAuth:
116
+ type: http
117
+ scheme: bearer
118
+ bearerFormat: JWT
119
+ description: >-
120
+ `HTTP: Bearer Auth`
121
+
122
+ - Security Scheme Type: http
123
+
124
+ - HTTP Authorization Scheme: `Bearer API_key`, can be found in [Account
125
+ Management>API
126
+ Keys](https://platform.minimax.io/user-center/basic-information/interface-key).
127
+
128
+ ````