@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,239 @@
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
+ # Text to Image Generation
6
+
7
+ > Use this API to generate images from text input.
8
+
9
+
10
+
11
+ ## OpenAPI
12
+
13
+ ````yaml /api-reference/image/generation/api/text-to-image.json POST /v1/image_generation
14
+ openapi: 3.1.0
15
+ info:
16
+ title: MiniMax Image Generation API
17
+ description: MiniMax image generation API for creating images from text prompts
18
+ license:
19
+ name: MIT
20
+ version: 1.0.0
21
+ servers:
22
+ - url: https://api.minimax.io
23
+ security:
24
+ - bearerAuth: []
25
+ paths:
26
+ /v1/image_generation:
27
+ post:
28
+ tags:
29
+ - Image
30
+ summary: Image Generation
31
+ operationId: imageGeneration
32
+ parameters:
33
+ - name: Content-Type
34
+ in: header
35
+ required: true
36
+ description: >-
37
+ The media type of the request body. Must be set to
38
+ `application/json` to ensure the data is sent in JSON format.
39
+ schema:
40
+ type: string
41
+ enum:
42
+ - application/json
43
+ default: application/json
44
+ requestBody:
45
+ description: ''
46
+ content:
47
+ application/json:
48
+ schema:
49
+ $ref: '#/components/schemas/ImageGenerationReq'
50
+ required: true
51
+ responses:
52
+ '200':
53
+ description: ''
54
+ content:
55
+ application/json:
56
+ schema:
57
+ $ref: '#/components/schemas/ImageGenerationResp'
58
+ components:
59
+ schemas:
60
+ ImageGenerationReq:
61
+ type: object
62
+ required:
63
+ - prompt
64
+ - model
65
+ properties:
66
+ model:
67
+ type: string
68
+ description: 'Model name. Options: `image-01`.'
69
+ enum:
70
+ - image-01
71
+ prompt:
72
+ type: string
73
+ description: Text description of the image, max length 1500 characters.
74
+ aspect_ratio:
75
+ type: string
76
+ description: |-
77
+ Image aspect ratio, default `1:1`. Options:
78
+ - `1:1` (1024x1024)
79
+ - `16:9` (1280x720)
80
+ - `4:3` (1152x864)
81
+ - `3:2` (1248x832)
82
+ - `2:3` (832x1248)
83
+ - `3:4` (864x1152)
84
+ - `9:16` (720x1280)
85
+ - `21:9` (1344x576)
86
+ enum:
87
+ - '1:1'
88
+ - '16:9'
89
+ - '4:3'
90
+ - '3:2'
91
+ - '2:3'
92
+ - '3:4'
93
+ - '9:16'
94
+ - '21:9'
95
+ width:
96
+ type: integer
97
+ description: >-
98
+ Image width (px). Only effective for `image-01`. Must be set
99
+ together with `height`. Range [512, 2048], must be divisible by 8.
100
+ If both `width/height` and `aspect_ratio` are provided,
101
+ `aspect_ratio` takes priority.
102
+ height:
103
+ type: integer
104
+ description: >-
105
+ Image height (px). Only effective for `image-01`. Must be set
106
+ together with `width`. Range [512, 2048], must be divisible by 8. If
107
+ both `width/height` and `aspect_ratio` are provided, `aspect_ratio`
108
+ takes priority.
109
+ response_format:
110
+ type: string
111
+ enum:
112
+ - url
113
+ - base64
114
+ default: url
115
+ description: |-
116
+ Response format for images. Default: url. Options: url, base64.
117
+ ⚠️ Note: url expires in 24 hours.
118
+ seed:
119
+ type: integer
120
+ format: int64
121
+ description: >-
122
+ Random seed. Using the same seed and parameters produces
123
+ reproducible images. If not provided, a random seed is generated for
124
+ each image.
125
+ 'n':
126
+ type: integer
127
+ default: 1
128
+ minimum: 1
129
+ maximum: 9
130
+ description: 'Number of images to generate per request. Range [1, 9]. Default: 1.'
131
+ prompt_optimizer:
132
+ type: boolean
133
+ default: false
134
+ description: 'Enable automatic optimization of prompt. Default: `false`.'
135
+ example:
136
+ model: image-01
137
+ prompt: >-
138
+ A man in a white t-shirt, full-body, standing front view, outdoors,
139
+ with the Venice Beach sign in the background, Los Angeles. Fashion
140
+ photography in 90s documentary style, film grain, photorealistic.
141
+ aspect_ratio: '16:9'
142
+ response_format: url
143
+ 'n': 3
144
+ prompt_optimizer: true
145
+ ImageGenerationResp:
146
+ type: object
147
+ properties:
148
+ data:
149
+ $ref: '#/components/schemas/DataObject'
150
+ metadata:
151
+ type: object
152
+ properties:
153
+ success_count:
154
+ type: integer
155
+ description: Number of successfully generated images.
156
+ failed_count:
157
+ type: integer
158
+ description: Number of images blocked due to content safety.
159
+ description: Additional metadata about the generation.
160
+ id:
161
+ type: string
162
+ description: Trace ID for request tracking
163
+ base_resp:
164
+ $ref: '#/components/schemas/BaseResp'
165
+ example:
166
+ id: 03ff3cd0820949eb8a410056b5f21d38
167
+ data:
168
+ image_urls:
169
+ - XXX
170
+ - XXX
171
+ - XXX
172
+ metadata:
173
+ failed_count: '0'
174
+ success_count: '3'
175
+ base_resp:
176
+ status_code: 0
177
+ status_msg: success
178
+ DataObject:
179
+ type: object
180
+ properties:
181
+ image_urls:
182
+ type: array
183
+ items:
184
+ type: string
185
+ description: >-
186
+ Returned when `response_format` = `url`, contains an array of image
187
+ links.
188
+ image_base64:
189
+ type: array
190
+ items:
191
+ type: string
192
+ description: >-
193
+ Returned when `response_format` = `base64`, contains an array of
194
+ base64-encoded images.
195
+ BaseResp:
196
+ type: object
197
+ properties:
198
+ status_code:
199
+ type: integer
200
+ description: >-
201
+ The status codes and their meanings are as follows:
202
+
203
+ - `0`, Request successful
204
+
205
+ - `1002`, Rate limit triggered, please try again later
206
+
207
+ - `1004`, Account authentication failed, please check if the API Key
208
+ is correct
209
+
210
+ - `1008`, Insufficient account balance
211
+
212
+ - `1026`, Sensitive content detected in prompt
213
+
214
+ - `2013`, Invalid input parameters, please check if the parameters
215
+ are filled in as required
216
+
217
+ - `2049`, Invalid API key
218
+
219
+
220
+ For more information, please refer to the [Error Code
221
+ Reference](/api-reference/errorcode).
222
+ status_msg:
223
+ type: string
224
+ description: Status details.
225
+ securitySchemes:
226
+ bearerAuth:
227
+ type: http
228
+ scheme: bearer
229
+ bearerFormat: JWT
230
+ description: >-
231
+ `HTTP: Bearer Auth`
232
+
233
+ - Security Scheme Type: http
234
+
235
+ - HTTP Authorization Scheme: `Bearer API_key`, can be found in [Account
236
+ Management>API
237
+ Keys](https://platform.minimax.io/user-center/basic-information/interface-key).
238
+
239
+ ````
@@ -0,0 +1,219 @@
1
+ /**
2
+ * @file lib/API/minimax/image.js
3
+ * @module minimax/image
4
+ * @description Pure HTTP wrapper for the Minimax Image Generation API.
5
+ * Fully aligned with the official documentation:
6
+ * - lib/API/minimax/image.generation.md
7
+ * - lib/API/minimax/image.to.image.md
8
+ *
9
+ * This is a **new library** — only the current response format is supported.
10
+ * No backward compatibility with legacy response structures.
11
+ *
12
+ * This module only handles communication with Minimax endpoints.
13
+ * It does NOT handle file publishing, SSH, or CDN logic.
14
+ *
15
+ * For publishing generated or reference files to a remote CDN,
16
+ * use the reusable `lib/cdn.js` module instead.
17
+ */
18
+
19
+ import { request as doRequest } from '@j-o-r/apiserver';
20
+ import fs from 'fs/promises';
21
+ import path from 'path';
22
+
23
+ const BASE_URL = 'https://api.minimax.io/v1';
24
+
25
+ // All temporary files (audio, images, video) are saved under this directory
26
+ const TMP_DIR = path.join(process.cwd(), '.cache', 'minimax');
27
+
28
+ /**
29
+ * Get authentication headers for Minimax API.
30
+ *
31
+ * @returns {Object} Headers object with Authorization Bearer token.
32
+ * @throws {Error} If MINIMAX_API_KEY environment variable is not set.
33
+ */
34
+ const getHeaders = () => {
35
+ if (!process.env.MINIMAX_API_KEY) {
36
+ throw new Error('Missing MINIMAX_API_KEY! Please export MINIMAX_API_KEY=your_key');
37
+ }
38
+ return {
39
+ 'Content-Type': 'application/json',
40
+ 'Authorization': `Bearer ${process.env.MINIMAX_API_KEY}`
41
+ };
42
+ };
43
+
44
+ /**
45
+ * Saves image data (either URL or base64) to a local temporary file.
46
+ * Handles both `response_format: 'url'` and `response_format: 'base64'`.
47
+ * Supports data URL prefix for base64.
48
+ *
49
+ * @param {string} imageData - Either a URL or a base64-encoded string (with or without data: prefix).
50
+ * @param {string} [filenamePrefix='minimax-image'] - Prefix for the local filename.
51
+ * @param {number} [index=0] - Index for multiple images to avoid filename collisions.
52
+ * @returns {Promise<string>} Absolute path to the saved local file.
53
+ */
54
+ async function saveImageToLocal(imageData, filenamePrefix = 'minimax-image', index = 0) {
55
+ const tmpDir = path.join(process.cwd(), '.cache', 'minimax');
56
+ await fs.mkdir(tmpDir, { recursive: true });
57
+
58
+ const filename = `${filenamePrefix}-${Date.now()}-${index}.png`;
59
+ const localPath = path.join(tmpDir, filename);
60
+
61
+ if (typeof imageData === 'string' && imageData.startsWith('http')) {
62
+ // URL case
63
+ const response = await fetch(imageData);
64
+ if (!response.ok) {
65
+ throw new Error(`Failed to download image: ${response.status} ${response.statusText}`);
66
+ }
67
+ const buffer = Buffer.from(await response.arrayBuffer());
68
+ await fs.writeFile(localPath, buffer);
69
+ } else if (typeof imageData === 'string') {
70
+ // Base64 case (with or without data: prefix)
71
+ let base64Data = imageData;
72
+ if (imageData.startsWith('data:')) {
73
+ base64Data = imageData.split(',')[1];
74
+ }
75
+ const buffer = Buffer.from(base64Data, 'base64');
76
+ await fs.writeFile(localPath, buffer);
77
+ } else {
78
+ throw new Error('Invalid image data provided to saveImageToLocal');
79
+ }
80
+
81
+ return localPath;
82
+ }
83
+
84
+ /**
85
+ * Core image generation request (supports both Text-to-Image and Image-to-Image).
86
+ *
87
+ * Fully implements the official Minimax Image Generation API
88
+ * as documented in `lib/API/minimax/image.generation.md` and `image.to.image.md`.
89
+ *
90
+ * Uses the single endpoint `/v1/image_generation`.
91
+ *
92
+ * Supports all models, parameters, and response formats.
93
+ *
94
+ * @param {string} prompt - Text description of the image, max 1500 characters.
95
+ * @param {Object} [options] - All available options from the official spec.
96
+ *
97
+ * @param {string} [options.model='image-01'] - Model to use.
98
+ * Supported values:
99
+ * - 'image-01' (default, text-to-image and img2img)
100
+ * - 'image-01-live' (for image-to-image)
101
+ *
102
+ * @param {string} [options.aspect_ratio='1:1'] - Image aspect ratio.
103
+ * Options: '1:1', '16:9', '4:3', '3:2', '2:3', '3:4', '9:16', '21:9'
104
+ *
105
+ * @param {number} [options.width] - Image width in px (512-2048, divisible by 8).
106
+ * Only effective for model 'image-01'. aspect_ratio takes priority if both provided.
107
+ *
108
+ * @param {number} [options.height] - Image height in px (same rules as width).
109
+ *
110
+ * @param {string} [options.response_format='url'] - 'url' or 'base64'.
111
+ * Default is `'url'` (user preference).
112
+ * ⚠️ `url` links expire after 24 hours.
113
+ *
114
+ * @param {number} [options.seed] - Random seed for reproducibility.
115
+ *
116
+ * @param {number} [options.n=1] - Number of images to generate (1-9).
117
+ *
118
+ * @param {boolean} [options.prompt_optimizer=false] - Enable automatic prompt optimization.
119
+ *
120
+ * @param {Array<Object>} [options.subject_reference] - For Image-to-Image.
121
+ * Array of subject references. Currently supports:
122
+ * - { type: 'character', image_file: 'https://...' or 'data:image/...;base64,...' }
123
+ *
124
+ * @param {Object} [options.extra] - Any additional parameters not yet documented.
125
+ *
126
+ * @returns {Promise<{
127
+ * image_urls: string[], // Array from data.image_urls (if url format)
128
+ * image_base64: string[], // Array from data.image_base64 (if base64 format)
129
+ * local_paths: string[], // Absolute paths to saved files
130
+ * metadata: Object, // { success_count, failed_count }
131
+ * id: string, // Trace ID
132
+ * duration: number, // API call duration in milliseconds
133
+ * raw: object // Full raw response
134
+ * }>}
135
+ *
136
+ * @example
137
+ * // Text-to-Image (basic)
138
+ * const result = await requestImage("A serene mountain landscape at sunset", {
139
+ * model: "image-01",
140
+ * aspect_ratio: "16:9",
141
+ * n: 2
142
+ * });
143
+ *
144
+ * @example
145
+ * // Image-to-Image
146
+ * const result = await requestImage("A girl looking into the distance", {
147
+ * model: "image-01",
148
+ * subject_reference: [{
149
+ * type: "character",
150
+ * image_file: "https://example.com/portrait.jpg"
151
+ * }],
152
+ * n: 1
153
+ * });
154
+ */
155
+ async function requestImage(prompt, options = {}) {
156
+ const headers = getHeaders();
157
+ const url = `${BASE_URL}/image_generation`;
158
+
159
+ const body = {
160
+ model: options.model || 'image-01',
161
+ prompt: prompt,
162
+ aspect_ratio: options.aspect_ratio || '1:1',
163
+ response_format: options.response_format || 'url', // User preference: URL as default
164
+ n: options.n ?? 1,
165
+ prompt_optimizer: options.prompt_optimizer ?? false,
166
+ ...options.extra
167
+ };
168
+
169
+ if (options.width !== undefined) body.width = options.width;
170
+ if (options.height !== undefined) body.height = options.height;
171
+ if (options.seed !== undefined) body.seed = options.seed;
172
+ if (options.subject_reference) body.subject_reference = options.subject_reference;
173
+
174
+ const start = Date.now();
175
+ const res = await doRequest(url, 'POST', headers, body);
176
+ const duration = Date.now() - start;
177
+
178
+ if (res.status !== 200) {
179
+ throw new Error(`Minimax API error ${res.status}: ${JSON.stringify(res.response)}`);
180
+ }
181
+
182
+ const respData = res.response?.data || {};
183
+ const metadata = res.response?.metadata || {};
184
+ const traceId = res.response?.id;
185
+
186
+ let imageDataArray = [];
187
+
188
+ if (respData.image_urls && Array.isArray(respData.image_urls) && respData.image_urls.length > 0) {
189
+ imageDataArray = respData.image_urls;
190
+ } else if (respData.image_base64 && Array.isArray(respData.image_base64) && respData.image_base64.length > 0) {
191
+ imageDataArray = respData.image_base64;
192
+ }
193
+
194
+ if (imageDataArray.length === 0) {
195
+ throw new Error('No image data found in data.image_urls or data.image_base64 of Minimax response');
196
+ }
197
+
198
+ const localPaths = [];
199
+ for (let i = 0; i < imageDataArray.length; i++) {
200
+ const localPath = await saveImageToLocal(imageDataArray[i], 'minimax-image', i);
201
+ localPaths.push(localPath);
202
+ }
203
+
204
+ return {
205
+ image_urls: respData.image_urls || [],
206
+ image_base64: respData.image_base64 || [],
207
+ local_paths: localPaths,
208
+ metadata,
209
+ id: traceId,
210
+ duration,
211
+ raw: res.response
212
+ };
213
+ }
214
+
215
+ export {
216
+ getHeaders,
217
+ saveImageToLocal,
218
+ requestImage
219
+ };