@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.
- package/README.md +2 -0
- package/README.md.bak.1779452127 +240 -0
- package/TODO.md +30 -8
- package/agents/code_agent.js +6 -6
- package/agents/daisy_agent.js +10 -7
- package/agents/minimax.js +173 -0
- package/agents/stability.js +173 -0
- package/bin/codeDave +1 -1
- package/bin/dave.js +1 -1
- package/docs/music-toolsets.md +137 -0
- package/docs/plans/minimax-music-generation.md +80 -0
- package/docs/plans/unified-agent-architecture.md +146 -0
- package/docs/plans/websocket-streaming-plan.md.bak +317 -0
- package/docs/prompt/task_clarification_and_documentation.md +35 -0
- package/lib/API/minimax/ImageToolset.js +169 -0
- package/lib/API/minimax/MusicToolset.js +290 -0
- package/lib/API/minimax/VideoToolset.js +296 -0
- package/lib/API/minimax/image.generation.md +239 -0
- package/lib/API/minimax/image.js +219 -0
- package/lib/API/minimax/image.to.image.md +257 -0
- package/lib/API/minimax/index.js +16 -0
- package/lib/API/minimax/music.cover.preprocess.md +206 -0
- package/lib/API/minimax/music.generation.md +346 -0
- package/lib/API/minimax/music.js +257 -0
- package/lib/API/minimax/music.lyrics.generation.md +205 -0
- package/lib/API/minimax/video.download.md +133 -0
- package/lib/API/minimax/video.first.last.image.md +186 -0
- package/lib/API/minimax/video.from.image.md +206 -0
- package/lib/API/minimax/video.from.subject.md +164 -0
- package/lib/API/minimax/video.generation.md +192 -0
- package/lib/API/minimax/video.js +339 -0
- package/lib/API/minimax/video.query.md +128 -0
- package/lib/API/stability.ai/ImageToolset.js +357 -0
- package/lib/API/stability.ai/MusicToolset.js +302 -0
- package/lib/API/stability.ai/audio-3.md +205 -0
- package/lib/API/stability.ai/audio.js +679 -0
- package/lib/API/stability.ai/image.js +911 -0
- package/lib/API/stability.ai/image.md +271 -0
- package/lib/API/stability.ai/index.js +11 -0
- package/lib/API/stability.ai/openapi.json +17118 -0
- package/lib/API/x.ai/ImageToolset.js +165 -0
- package/lib/API/x.ai/image.editing.md +86 -0
- package/lib/API/x.ai/image.js +393 -0
- package/lib/API/x.ai/image.md +213 -0
- package/lib/API/x.ai/image.to.generation.md +494 -0
- package/lib/API/x.ai/image.to.video.md +23 -0
- package/lib/API/x.ai/index.js +9 -0
- package/lib/AgentManager.js +1 -1
- package/lib/CdnToolset.js +191 -0
- package/lib/ToolSet.js +19 -1
- package/lib/cdn.js +373 -0
- package/lib/fafs.js +3 -1
- package/lib/genericToolset.js +43 -166
- package/lib/index.js +9 -1
- package/package.json +2 -2
- package/types/API/minimax/ImageToolset.d.ts +3 -0
- package/types/API/minimax/MusicToolset.d.ts +3 -0
- package/types/API/minimax/VideoToolset.d.ts +3 -0
- package/types/API/minimax/image.d.ts +109 -0
- package/types/API/minimax/index.d.ts +15 -0
- package/types/API/minimax/music.d.ts +46 -0
- package/types/API/minimax/video.d.ts +165 -0
- package/types/API/stability.ai/ImageToolset.d.ts +3 -0
- package/types/API/stability.ai/MusicToolset.d.ts +3 -0
- package/types/API/stability.ai/audio.d.ts +193 -0
- package/types/API/stability.ai/image.d.ts +274 -0
- package/types/API/stability.ai/index.d.ts +11 -0
- package/types/API/x.ai/ImageToolset.d.ts +3 -0
- package/types/API/x.ai/image.d.ts +82 -0
- package/types/API/x.ai/index.d.ts +9 -0
- package/types/AgentManager.d.ts +1 -1
- package/types/CdnToolset.d.ts +20 -0
- package/types/ToolSet.d.ts +8 -0
- package/types/cdn.d.ts +141 -0
- package/types/index.d.ts +8 -2
- package/docs/multi-agent-clusters.md.bak +0 -229
package/lib/genericToolset.js
CHANGED
|
@@ -13,6 +13,9 @@ const searchSessionsSh = path.join(utilsDir, 'search_sessions.sh');
|
|
|
13
13
|
const listSessionsSh = path.join(utilsDir, 'list_sessions.sh');
|
|
14
14
|
const syntaxCheckSh = path.join(utilsDir, 'syntax_check.sh');
|
|
15
15
|
|
|
16
|
+
// Do we have a SSH access point?
|
|
17
|
+
const SSH_EP = process.env.SSH_EP || '';
|
|
18
|
+
|
|
16
19
|
const user = await env();
|
|
17
20
|
const environment = `
|
|
18
21
|
Name: ${user.name}
|
|
@@ -27,8 +30,6 @@ const tools = new ToolSet('auto');
|
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* Single source of truth for cleaning over-escaped strings from LLMs.
|
|
30
|
-
* Basic cleaning only. Heavy repair (especially for JS template literals)
|
|
31
|
-
* is now centralized in utils/syntax_check.sh (repair_file logic).
|
|
32
33
|
*/
|
|
33
34
|
const guessOverEscaping = (s) => {
|
|
34
35
|
if (typeof s !== 'string') return s;
|
|
@@ -94,10 +95,6 @@ const getJSError = (errorStr) => {
|
|
|
94
95
|
/**
|
|
95
96
|
* @module lib/genericToolset
|
|
96
97
|
* Secure utility tools.
|
|
97
|
-
* write_file writes content, then runs syntax_check.sh WITHOUT --fix.
|
|
98
|
-
* On syntax error the error details are returned in the tool response
|
|
99
|
-
* (file is kept so LLM agents can read_file, inspect escaping issues,
|
|
100
|
-
* and submit a corrected version on the next write_file call).
|
|
101
98
|
*/
|
|
102
99
|
|
|
103
100
|
tools.add(
|
|
@@ -144,71 +141,39 @@ tools.add(
|
|
|
144
141
|
properties: {
|
|
145
142
|
bash_script: {
|
|
146
143
|
type: 'string',
|
|
147
|
-
description: `
|
|
148
|
-
**Write raw bash exactly** as it should appear in a .sh file. Use normal bash escaping only (\`'\\''\` for single quotes inside single quotes, \`\\$\` for literal dollar, etc.).
|
|
149
|
-
|
|
150
|
-
Do NOT add extra backslashes for JSON, JavaScript, or XML. The system parses the JSON then passes your exact text to bash via stdin.
|
|
151
|
-
|
|
152
|
-
Correct example you should output in the parameter:
|
|
153
|
-
|
|
154
|
-
\`\`\`bash
|
|
155
|
-
echo 'Single quotes: '\\''quoted'\\'''
|
|
156
|
-
echo "Double quotes: \\"quoted\\""
|
|
157
|
-
echo "Dollar: \\$HOME = $HOME"
|
|
158
|
-
echo \\\`date\\\`
|
|
159
|
-
echo -e 'Pipe test:\\n1\\n2' | cat
|
|
160
|
-
\`\`\`
|
|
161
|
-
Supports all syntax safely via stdin. System: ${user.system}`
|
|
144
|
+
description: `Write raw bash exactly...`
|
|
162
145
|
},
|
|
163
|
-
timeout: {
|
|
164
|
-
|
|
165
|
-
default: 360,
|
|
166
|
-
description: 'Max execution time in seconds (default 360).'
|
|
167
|
-
},
|
|
168
|
-
strict: {
|
|
169
|
-
type:'boolean' ,
|
|
170
|
-
default: false,
|
|
171
|
-
description: 'Validate bash script STRICT first before it is being executed.'
|
|
172
|
-
}
|
|
146
|
+
timeout: { type: 'number', default: 360 },
|
|
147
|
+
strict: { type: 'boolean', default: false }
|
|
173
148
|
},
|
|
174
149
|
required: ['bash_script']
|
|
175
150
|
},
|
|
176
151
|
async (params) => {
|
|
177
|
-
|
|
178
|
-
|
|
152
|
+
let bash_script = params.bash_script;
|
|
153
|
+
if (typeof bash_script !== 'string') bash_script = '';
|
|
154
|
+
// Check if the bash_script string has a shebang on the first line '#!'
|
|
155
|
+
// If not, add a bash shebang
|
|
156
|
+
const firstLine = bash_script.split('\n')[0] || '';
|
|
157
|
+
if (!firstLine.trim().startsWith('#!')) {
|
|
158
|
+
bash_script = '#!/bin/bash\n' + bash_script;
|
|
179
159
|
}
|
|
180
|
-
const timeoutSec = Number(params.timeout ??
|
|
181
|
-
const prams = params.strict? '' : '-S error';
|
|
182
|
-
const bash_script = escapeForBashTemplate(params.bash_script);
|
|
160
|
+
const timeoutSec = Number(params.timeout ?? 360);
|
|
161
|
+
const prams = params.strict ? '' : '-S error';
|
|
183
162
|
if (isNaN(timeoutSec) || timeoutSec < 0) throw new Error('Invalid timeout');
|
|
184
|
-
console.log(bash_script);
|
|
185
163
|
const timeout = timeoutSec * 1000;
|
|
186
164
|
const valid = SH`shellcheck ${prams} -`.runSync(bash_script).stdout.toString().trim();
|
|
187
|
-
if (valid !== '')
|
|
188
|
-
console.log(valid);
|
|
189
|
-
throw new Error(valid);
|
|
190
|
-
}
|
|
165
|
+
if (valid !== '') throw new Error(valid);
|
|
191
166
|
return await SH`bash`.options({ timeout }).run(bash_script);
|
|
192
167
|
}
|
|
193
168
|
);
|
|
194
169
|
|
|
195
170
|
tools.add(
|
|
196
|
-
'send_email',
|
|
197
|
-
'Send email via msmtp.',
|
|
198
|
-
{
|
|
199
|
-
type: 'object',
|
|
200
|
-
properties: {
|
|
201
|
-
to: { type: 'string', description: 'Recipient' },
|
|
202
|
-
subject: { type: 'string', description: 'Subject' },
|
|
203
|
-
body: { type: 'string', description: 'Body' }
|
|
204
|
-
},
|
|
205
|
-
required: ['to', 'subject', 'body']
|
|
206
|
-
},
|
|
171
|
+
'send_email', 'Send email via msmtp.', { type: 'object', properties: { to: { type: 'string' }, subject: { type: 'string' }, body: { type: 'string' } }, required: ['to', 'subject', 'body'] },
|
|
207
172
|
async (params) => {
|
|
208
173
|
const to = guessOverEscaping(params.to);
|
|
209
174
|
const subject = guessOverEscaping(params.subject);
|
|
210
175
|
const body = guessOverEscaping(params.body);
|
|
211
|
-
const delim = `END_EMAIL_${Date.now().toString(36)}
|
|
176
|
+
const delim = `END_EMAIL_${Date.now().toString(36)}`;
|
|
212
177
|
return await SH`msmtp ${params.to} <<'${delim}'
|
|
213
178
|
To: ${to}
|
|
214
179
|
Subject: ${subject}
|
|
@@ -220,168 +185,80 @@ ${delim}
|
|
|
220
185
|
);
|
|
221
186
|
|
|
222
187
|
tools.add(
|
|
223
|
-
'open_link',
|
|
224
|
-
|
|
225
|
-
{
|
|
226
|
-
type: 'object',
|
|
227
|
-
properties: {
|
|
228
|
-
url: { type: 'string', description: 'URL or file path' }
|
|
229
|
-
},
|
|
230
|
-
required: ['url']
|
|
231
|
-
},
|
|
232
|
-
async (params) => {
|
|
233
|
-
let url = guessOverEscaping(params.url?.trim());
|
|
234
|
-
return await SH`xdg-open ${[url]}`.run();
|
|
235
|
-
}
|
|
188
|
+
'open_link', 'Open URL/file with xdg-open.', { type: 'object', properties: { url: { type: 'string' } }, required: ['url'] },
|
|
189
|
+
async (params) => await SH`xdg-open ${[guessOverEscaping(params.url)]}`.run()
|
|
236
190
|
);
|
|
237
191
|
|
|
238
192
|
tools.add(
|
|
239
|
-
'execute_remote_script',
|
|
240
|
-
'Run bash on remote via SSH.',
|
|
193
|
+
'execute_remote_script', `Run bash on remote via SSH. ${SSH_EP}`,
|
|
241
194
|
{
|
|
242
195
|
type: 'object',
|
|
243
196
|
properties: {
|
|
244
|
-
url: { type: 'string', description:
|
|
245
|
-
script: { type: 'string'
|
|
246
|
-
timeout: {
|
|
247
|
-
type: 'number',
|
|
248
|
-
default: 30,
|
|
249
|
-
description: 'Max execution time in seconds (default 30).'
|
|
250
|
-
}
|
|
197
|
+
url: { type: 'string', description: `ssh://user@host[:port] default: ${SSH_EP}` },
|
|
198
|
+
script: { type: 'string' },
|
|
199
|
+
timeout: { type: 'number', default: 30 }
|
|
251
200
|
},
|
|
252
201
|
required: ['url', 'script']
|
|
253
202
|
},
|
|
254
203
|
async (params) => {
|
|
255
204
|
let { url, script } = params;
|
|
205
|
+
if (!url || url === '') url = SSH_EP;
|
|
256
206
|
url = guessOverEscaping(url);
|
|
257
207
|
script = guessOverEscaping(script);
|
|
258
|
-
|
|
259
|
-
const timeoutSec = Number(params.timeout ?? 30);
|
|
260
|
-
if (isNaN(timeoutSec) || timeoutSec <= 0) throw new Error('Invalid timeout');
|
|
261
|
-
const timeoutMs = timeoutSec * 1000;
|
|
208
|
+
const timeoutMs = (Number(params.timeout ?? 30)) * 1000;
|
|
262
209
|
if (!url.startsWith('ssh://')) throw new Error('ssh://user@host[:port]');
|
|
263
210
|
const withoutProto = url.slice(6);
|
|
264
211
|
const parts = withoutProto.split(':');
|
|
265
212
|
let port = 22, userHost = withoutProto;
|
|
266
213
|
if (parts.length > 1) { userHost = parts[0]; port = parseInt(parts[1]); }
|
|
267
214
|
const [user, host] = userHost.split('@');
|
|
268
|
-
if (!user || !host) throw new Error('Invalid SSH URL');
|
|
269
215
|
return await SH`ssh -p ${port} ${user}@${host} bash`.options({ timeout: timeoutMs }).run(script);
|
|
270
216
|
}
|
|
271
217
|
);
|
|
272
218
|
|
|
273
219
|
tools.add(
|
|
274
|
-
'history_search',
|
|
275
|
-
'
|
|
276
|
-
{
|
|
277
|
-
type: 'object',
|
|
278
|
-
properties: {
|
|
279
|
-
query: { type: 'string', description: 'Query/regex or empty to list' }
|
|
280
|
-
},
|
|
281
|
-
required: []
|
|
282
|
-
},
|
|
220
|
+
'history_search', 'Search/list chat sessions in .cache/.',
|
|
221
|
+
{ type: 'object', properties: { query: { type: 'string' } } },
|
|
283
222
|
async (params) => {
|
|
284
223
|
if (typeof params.query === 'string' && params.query.trim()) {
|
|
285
|
-
|
|
286
|
-
return await SH`${searchSessionsSh} "${bashEscape(q)}"`.run();
|
|
224
|
+
return await SH`${searchSessionsSh} "${bashEscape(guessOverEscaping(params.query))}"`.run();
|
|
287
225
|
}
|
|
288
226
|
return await SH`${listSessionsSh}`.run();
|
|
289
227
|
}
|
|
290
228
|
);
|
|
291
229
|
|
|
292
230
|
tools.add(
|
|
293
|
-
'read_file',
|
|
294
|
-
'
|
|
295
|
-
{
|
|
296
|
-
type: 'object',
|
|
297
|
-
properties: {
|
|
298
|
-
file: { type: 'string', description: `Relative path. cwd: ${user.cwd}` }
|
|
299
|
-
},
|
|
300
|
-
required: ['file']
|
|
301
|
-
},
|
|
231
|
+
'read_file', 'Read file from CWD (relative path only).',
|
|
232
|
+
{ type: 'object', properties: { file: { type: 'string' } }, required: ['file'] },
|
|
302
233
|
async (params) => {
|
|
303
234
|
let file = guessOverEscaping(params.file?.trim());
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
const resolved = path.resolve(process.cwd(), file);
|
|
308
|
-
if (!resolved.startsWith(process.cwd())) throw new Error('Escapes CWD.');
|
|
309
|
-
return await fs.readFile(resolved, 'utf8');
|
|
235
|
+
if (!file || file.startsWith('/') || file.includes('..')) throw new Error('Relative CWD path only');
|
|
236
|
+
return await fs.readFile(path.resolve(process.cwd(), file), 'utf8');
|
|
310
237
|
}
|
|
311
238
|
);
|
|
312
239
|
|
|
313
240
|
tools.add(
|
|
314
|
-
'write_file',
|
|
315
|
-
|
|
316
|
-
{
|
|
317
|
-
type: 'object',
|
|
318
|
-
properties: {
|
|
319
|
-
file: { type: 'string', description: `Relative path. cwd: ${user.cwd}` },
|
|
320
|
-
content: { type: 'string', description: 'Raw content verbatim (no escaping).' }
|
|
321
|
-
},
|
|
322
|
-
required: ['file', 'content']
|
|
323
|
-
},
|
|
241
|
+
'write_file', 'Write/validate file in CWD.',
|
|
242
|
+
{ type: 'object', properties: { file: { type: 'string' }, content: { type: 'string' } }, required: ['file', 'content'] },
|
|
324
243
|
async (params) => {
|
|
325
244
|
let fileParam = guessOverEscaping(params.file?.trim());
|
|
326
|
-
let content = guessOverEscaping(params.content
|
|
327
|
-
|
|
328
|
-
if (typeof fileParam !== 'string' || !fileParam || fileParam.startsWith('/') || fileParam.includes('..') || fileParam.includes('\\')) {
|
|
329
|
-
throw new Error('Relative CWD path only (no /, .., \\).');
|
|
330
|
-
}
|
|
245
|
+
let content = guessOverEscaping(params.content || '');
|
|
246
|
+
if (!fileParam || fileParam.startsWith('/') || fileParam.includes('..')) throw new Error('Relative CWD path only');
|
|
331
247
|
const resolved = path.resolve(process.cwd(), fileParam);
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const dir = path.dirname(resolved);
|
|
335
|
-
await fs.mkdir(dir, { recursive: true });
|
|
248
|
+
await fs.mkdir(path.dirname(resolved), { recursive: true });
|
|
336
249
|
await fs.writeFile(resolved, content, 'utf8');
|
|
337
|
-
|
|
338
|
-
let validationMsg = '';
|
|
339
|
-
try {
|
|
340
|
-
const checkOutput = await SH`${syntaxCheckSh} ${resolved}`.run();
|
|
341
|
-
validationMsg = checkOutput ? ` ${checkOutput.trim()}` : ' ✓ Syntax OK';
|
|
342
|
-
} catch (checkErr) {
|
|
343
|
-
const errText = checkErr?.toString() || 'Unknown syntax error';
|
|
344
|
-
validationMsg = ` [Syntax Error] ${getJSError(errText) || errText}`;
|
|
345
|
-
// File is intentionally kept so LLM can read_file and fix escaping
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
if (content.trim().startsWith('#!')) {
|
|
349
|
-
try {
|
|
350
|
-
await SH`chmod +x ${[resolved]}`.run();
|
|
351
|
-
validationMsg += ' ✓ +x';
|
|
352
|
-
} catch (e) {
|
|
353
|
-
validationMsg += ' (chmod failed)';
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return `Wrote ${fileParam} (${Buffer.byteLength(content, 'utf8')} bytes).${validationMsg}`;
|
|
250
|
+
return `Wrote ${fileParam} (${Buffer.byteLength(content, 'utf8')} bytes).`;
|
|
358
251
|
}
|
|
359
252
|
);
|
|
360
253
|
|
|
361
254
|
tools.add(
|
|
362
|
-
'syntax_check',
|
|
363
|
-
'
|
|
364
|
-
{
|
|
365
|
-
type: 'object',
|
|
366
|
-
properties: {
|
|
367
|
-
file: { type: 'string', description: 'Relative CWD path' }
|
|
368
|
-
},
|
|
369
|
-
required: ['file']
|
|
370
|
-
},
|
|
255
|
+
'syntax_check', 'Syntax validate file via utils/syntax_check.sh.',
|
|
256
|
+
{ type: 'object', properties: { file: { type: 'string' } }, required: ['file'] },
|
|
371
257
|
async (params) => {
|
|
372
258
|
const file = guessOverEscaping(params.file?.trim());
|
|
373
|
-
if (typeof file !== 'string' || !file) throw new Error('Relative path required.');
|
|
374
259
|
const resolved = path.resolve(process.cwd(), file);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const args = resolved;
|
|
378
|
-
try {
|
|
379
|
-
const out = await SH`${syntaxCheckSh} ${args}`.run();
|
|
380
|
-
return out || 'Syntax validation passed';
|
|
381
|
-
} catch (e) {
|
|
382
|
-
return `Syntax check failed: ${e.toString()}`;
|
|
383
|
-
}
|
|
260
|
+
return await SH`${syntaxCheckSh} ${resolved}`.run() || 'Syntax OK';
|
|
384
261
|
}
|
|
385
262
|
);
|
|
386
263
|
|
|
387
|
-
export default tools;
|
|
264
|
+
export default tools;
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,9 @@ import {request as gpt} from './API/openai.com/reponses/text.js';
|
|
|
2
2
|
import {request as xai} from './API/x.ai/responses.js';
|
|
3
3
|
import {request as claude} from './API/anthropic.com/text.js';
|
|
4
4
|
import {request as brave} from './API/brave.com/search.js';
|
|
5
|
-
|
|
5
|
+
import minimax from './API/minimax/index.js';
|
|
6
|
+
import stability from './API/stability.ai/index.js';
|
|
7
|
+
import xai from './API/x.ai/index.js';
|
|
6
8
|
import { env, GLOBAL } from './fafs.js';
|
|
7
9
|
import ToolSet from './ToolSet.js';
|
|
8
10
|
import AgentServer from './AgentServer.js';
|
|
@@ -23,6 +25,9 @@ const API = {
|
|
|
23
25
|
search: {
|
|
24
26
|
brave
|
|
25
27
|
},
|
|
28
|
+
minimax,
|
|
29
|
+
stability,
|
|
30
|
+
xai
|
|
26
31
|
}
|
|
27
32
|
export {
|
|
28
33
|
AgentManager,
|
|
@@ -38,3 +43,6 @@ export {
|
|
|
38
43
|
wsCli,
|
|
39
44
|
wsIO
|
|
40
45
|
};
|
|
46
|
+
|
|
47
|
+
// Export the dedicated CDN toolset
|
|
48
|
+
export { default as CdnToolset } from './CdnToolset.js';
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j-o-r/hello-dave",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"description": "ESM toolkit for building AI agents
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "ESM toolkit for building AI agents, CLI xai coding agent and unified access to Grok (XAI), OpenAI, and Anthropic endpoints, music, image and video creation toolsets from minimax, stability and x.ai.",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
8
8
|
"typesVersions": {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get authentication headers for Minimax API.
|
|
3
|
+
*
|
|
4
|
+
* @returns {Object} Headers object with Authorization Bearer token.
|
|
5
|
+
* @throws {Error} If MINIMAX_API_KEY environment variable is not set.
|
|
6
|
+
*/
|
|
7
|
+
export function getHeaders(): Object;
|
|
8
|
+
/**
|
|
9
|
+
* Saves image data (either URL or base64) to a local temporary file.
|
|
10
|
+
* Handles both `response_format: 'url'` and `response_format: 'base64'`.
|
|
11
|
+
* Supports data URL prefix for base64.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} imageData - Either a URL or a base64-encoded string (with or without data: prefix).
|
|
14
|
+
* @param {string} [filenamePrefix='minimax-image'] - Prefix for the local filename.
|
|
15
|
+
* @param {number} [index=0] - Index for multiple images to avoid filename collisions.
|
|
16
|
+
* @returns {Promise<string>} Absolute path to the saved local file.
|
|
17
|
+
*/
|
|
18
|
+
export function saveImageToLocal(imageData: string, filenamePrefix?: string, index?: number): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Core image generation request (supports both Text-to-Image and Image-to-Image).
|
|
21
|
+
*
|
|
22
|
+
* Fully implements the official Minimax Image Generation API
|
|
23
|
+
* as documented in `lib/API/minimax/image.generation.md` and `image.to.image.md`.
|
|
24
|
+
*
|
|
25
|
+
* Uses the single endpoint `/v1/image_generation`.
|
|
26
|
+
*
|
|
27
|
+
* Supports all models, parameters, and response formats.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} prompt - Text description of the image, max 1500 characters.
|
|
30
|
+
* @param {Object} [options] - All available options from the official spec.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} [options.model='image-01'] - Model to use.
|
|
33
|
+
* Supported values:
|
|
34
|
+
* - 'image-01' (default, text-to-image and img2img)
|
|
35
|
+
* - 'image-01-live' (for image-to-image)
|
|
36
|
+
*
|
|
37
|
+
* @param {string} [options.aspect_ratio='1:1'] - Image aspect ratio.
|
|
38
|
+
* Options: '1:1', '16:9', '4:3', '3:2', '2:3', '3:4', '9:16', '21:9'
|
|
39
|
+
*
|
|
40
|
+
* @param {number} [options.width] - Image width in px (512-2048, divisible by 8).
|
|
41
|
+
* Only effective for model 'image-01'. aspect_ratio takes priority if both provided.
|
|
42
|
+
*
|
|
43
|
+
* @param {number} [options.height] - Image height in px (same rules as width).
|
|
44
|
+
*
|
|
45
|
+
* @param {string} [options.response_format='url'] - 'url' or 'base64'.
|
|
46
|
+
* Default is `'url'` (user preference).
|
|
47
|
+
* ⚠️ `url` links expire after 24 hours.
|
|
48
|
+
*
|
|
49
|
+
* @param {number} [options.seed] - Random seed for reproducibility.
|
|
50
|
+
*
|
|
51
|
+
* @param {number} [options.n=1] - Number of images to generate (1-9).
|
|
52
|
+
*
|
|
53
|
+
* @param {boolean} [options.prompt_optimizer=false] - Enable automatic prompt optimization.
|
|
54
|
+
*
|
|
55
|
+
* @param {Array<Object>} [options.subject_reference] - For Image-to-Image.
|
|
56
|
+
* Array of subject references. Currently supports:
|
|
57
|
+
* - { type: 'character', image_file: 'https://...' or 'data:image/...;base64,...' }
|
|
58
|
+
*
|
|
59
|
+
* @param {Object} [options.extra] - Any additional parameters not yet documented.
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<{
|
|
62
|
+
* image_urls: string[], // Array from data.image_urls (if url format)
|
|
63
|
+
* image_base64: string[], // Array from data.image_base64 (if base64 format)
|
|
64
|
+
* local_paths: string[], // Absolute paths to saved files
|
|
65
|
+
* metadata: Object, // { success_count, failed_count }
|
|
66
|
+
* id: string, // Trace ID
|
|
67
|
+
* duration: number, // API call duration in milliseconds
|
|
68
|
+
* raw: object // Full raw response
|
|
69
|
+
* }>}
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Text-to-Image (basic)
|
|
73
|
+
* const result = await requestImage("A serene mountain landscape at sunset", {
|
|
74
|
+
* model: "image-01",
|
|
75
|
+
* aspect_ratio: "16:9",
|
|
76
|
+
* n: 2
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* // Image-to-Image
|
|
81
|
+
* const result = await requestImage("A girl looking into the distance", {
|
|
82
|
+
* model: "image-01",
|
|
83
|
+
* subject_reference: [{
|
|
84
|
+
* type: "character",
|
|
85
|
+
* image_file: "https://example.com/portrait.jpg"
|
|
86
|
+
* }],
|
|
87
|
+
* n: 1
|
|
88
|
+
* });
|
|
89
|
+
*/
|
|
90
|
+
export function requestImage(prompt: string, options?: {
|
|
91
|
+
model?: string | undefined;
|
|
92
|
+
aspect_ratio?: string | undefined;
|
|
93
|
+
width?: number | undefined;
|
|
94
|
+
height?: number | undefined;
|
|
95
|
+
response_format?: string | undefined;
|
|
96
|
+
seed?: number | undefined;
|
|
97
|
+
n?: number | undefined;
|
|
98
|
+
prompt_optimizer?: boolean | undefined;
|
|
99
|
+
subject_reference?: Object[] | undefined;
|
|
100
|
+
extra?: Object | undefined;
|
|
101
|
+
}): Promise<{
|
|
102
|
+
image_urls: string[];
|
|
103
|
+
image_base64: string[];
|
|
104
|
+
local_paths: string[];
|
|
105
|
+
metadata: Object;
|
|
106
|
+
id: string;
|
|
107
|
+
duration: number;
|
|
108
|
+
raw: object;
|
|
109
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { music };
|
|
3
|
+
export { musicToolset };
|
|
4
|
+
export { video };
|
|
5
|
+
export { videoToolset };
|
|
6
|
+
export { image };
|
|
7
|
+
export { imageToolset };
|
|
8
|
+
}
|
|
9
|
+
export default _default;
|
|
10
|
+
import * as music from './music.js';
|
|
11
|
+
import musicToolset from './MusicToolset.js';
|
|
12
|
+
import * as video from './video.js';
|
|
13
|
+
import videoToolset from './VideoToolset.js';
|
|
14
|
+
import * as image from './image.js';
|
|
15
|
+
import imageToolset from './ImageToolset.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function getHeaders(): {
|
|
2
|
+
'Content-Type': string;
|
|
3
|
+
Authorization: string;
|
|
4
|
+
};
|
|
5
|
+
export function saveAudioToLocal(audioData: any, filenamePrefix?: string): Promise<any>;
|
|
6
|
+
export function createMusic(prompt: any, options?: {}): Promise<{
|
|
7
|
+
audio_url: any;
|
|
8
|
+
local_path: any;
|
|
9
|
+
duration: number;
|
|
10
|
+
raw: any;
|
|
11
|
+
}>;
|
|
12
|
+
export function changeMusic(prompt: any, options?: {}): Promise<{
|
|
13
|
+
audio_url: any;
|
|
14
|
+
local_path: any;
|
|
15
|
+
duration: number;
|
|
16
|
+
raw: any;
|
|
17
|
+
}>;
|
|
18
|
+
export function analyzeMusic(audioUrl: any, options?: {}): Promise<{
|
|
19
|
+
cover_feature_id: any;
|
|
20
|
+
formatted_lyrics: any;
|
|
21
|
+
structure_result: any;
|
|
22
|
+
audio_duration: any;
|
|
23
|
+
trace_id: any;
|
|
24
|
+
raw: any;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Generate complete song lyrics or edit/continue existing lyrics.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} prompt - Theme, style, or editing instruction.
|
|
30
|
+
* @param {Object} [options]
|
|
31
|
+
* @param {'write_full_song'|'edit'} [options.mode='write_full_song']
|
|
32
|
+
* @param {string} [options.lyrics] - Existing lyrics (required for edit mode)
|
|
33
|
+
* @param {string} [options.title]
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<{song_title: string, style_tags: string, lyrics: string, raw: object}>}
|
|
36
|
+
*/
|
|
37
|
+
export function generateLyrics(prompt: string, options?: {
|
|
38
|
+
mode?: "write_full_song" | "edit" | undefined;
|
|
39
|
+
lyrics?: string | undefined;
|
|
40
|
+
title?: string | undefined;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
song_title: string;
|
|
43
|
+
style_tags: string;
|
|
44
|
+
lyrics: string;
|
|
45
|
+
raw: object;
|
|
46
|
+
}>;
|