@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
|
@@ -0,0 +1,165 @@
|
|
|
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 video data from a download URL to a local temporary file.
|
|
10
|
+
* Handles MP4 videos.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} videoUrl - Public download URL from retrieveVideoFile().
|
|
13
|
+
* @param {string} [filenamePrefix='minimax-video'] - Prefix for the local filename.
|
|
14
|
+
* @returns {Promise<string>} Absolute path to the saved local file.
|
|
15
|
+
*/
|
|
16
|
+
export function saveVideoToLocal(videoUrl: string, filenamePrefix?: string): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a video generation task (Text-to-Video, Image-to-Video, First-Last, Subject-Ref).
|
|
19
|
+
*
|
|
20
|
+
* Uses POST /v1/video_generation.
|
|
21
|
+
* Supports all documented models and input types via options.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} [prompt] - Text description (required for most modes).
|
|
24
|
+
* @param {Object} [options]
|
|
25
|
+
*
|
|
26
|
+
* @param {string} [options.model='MiniMax-Hailuo-2.3'] - Default model.
|
|
27
|
+
* Supported: MiniMax-Hailuo-2.3, MiniMax-Hailuo-02, T2V-01, I2V-01, S2V-01, etc.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} [options.first_frame_image] - URL or data: URL for image-to-video / first-last.
|
|
30
|
+
* @param {string} [options.last_frame_image] - For first & last frame mode.
|
|
31
|
+
* @param {Array<Object>} [options.subject_reference] - For subject-reference mode.
|
|
32
|
+
*
|
|
33
|
+
* @param {boolean} [options.prompt_optimizer=true]
|
|
34
|
+
* @param {boolean} [options.fast_pretreatment=false]
|
|
35
|
+
* @param {number} [options.duration=6]
|
|
36
|
+
* @param {string} [options.resolution] - e.g. '768P', '1080P'
|
|
37
|
+
* @param {string} [options.callback_url]
|
|
38
|
+
*
|
|
39
|
+
* @returns {Promise<{task_id: string, raw: object}>}
|
|
40
|
+
*/
|
|
41
|
+
export function createVideoGenerationTask(prompt?: string, options?: {
|
|
42
|
+
model?: string | undefined;
|
|
43
|
+
first_frame_image?: string | undefined;
|
|
44
|
+
last_frame_image?: string | undefined;
|
|
45
|
+
subject_reference?: Object[] | undefined;
|
|
46
|
+
prompt_optimizer?: boolean | undefined;
|
|
47
|
+
fast_pretreatment?: boolean | undefined;
|
|
48
|
+
duration?: number | undefined;
|
|
49
|
+
resolution?: string | undefined;
|
|
50
|
+
callback_url?: string | undefined;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
task_id: string;
|
|
53
|
+
raw: object;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Queries the status of a video generation task.
|
|
57
|
+
*
|
|
58
|
+
* GET /v1/query/video_generation?task_id=...
|
|
59
|
+
*
|
|
60
|
+
* @param {string} taskId
|
|
61
|
+
* @returns {Promise<{
|
|
62
|
+
* task_id: string,
|
|
63
|
+
* status: 'Preparing' | 'Queueing' | 'Processing' | 'Success' | 'Fail',
|
|
64
|
+
* file_id?: string,
|
|
65
|
+
* video_width?: number,
|
|
66
|
+
* video_height?: number,
|
|
67
|
+
* raw: object
|
|
68
|
+
* }>}
|
|
69
|
+
*/
|
|
70
|
+
export function queryVideoGenerationTask(taskId: string): Promise<{
|
|
71
|
+
task_id: string;
|
|
72
|
+
status: "Preparing" | "Queueing" | "Processing" | "Success" | "Fail";
|
|
73
|
+
file_id?: string;
|
|
74
|
+
video_width?: number;
|
|
75
|
+
video_height?: number;
|
|
76
|
+
raw: object;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves file metadata and download URL for a completed video.
|
|
80
|
+
*
|
|
81
|
+
* GET /v1/files/retrieve?file_id=...
|
|
82
|
+
*
|
|
83
|
+
* @param {string|number} fileId
|
|
84
|
+
* @returns {Promise<{
|
|
85
|
+
* file_id: string,
|
|
86
|
+
* filename: string,
|
|
87
|
+
* download_url: string,
|
|
88
|
+
* bytes: number,
|
|
89
|
+
* raw: object
|
|
90
|
+
* }>}
|
|
91
|
+
*/
|
|
92
|
+
export function retrieveVideoFile(fileId: string | number): Promise<{
|
|
93
|
+
file_id: string;
|
|
94
|
+
filename: string;
|
|
95
|
+
download_url: string;
|
|
96
|
+
bytes: number;
|
|
97
|
+
raw: object;
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* High-level video generation function.
|
|
101
|
+
* Handles the full async flow: create task → poll until ready → retrieve → download to .cache/minimax/
|
|
102
|
+
*
|
|
103
|
+
* Supports all video generation modes (text, image-to-video, first-last, subject-ref)
|
|
104
|
+
* by passing the appropriate options.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} prompt - Text prompt (can be empty for some modes).
|
|
107
|
+
* @param {Object} [options] - Same as createVideoGenerationTask + polling options.
|
|
108
|
+
*
|
|
109
|
+
* @param {number} [options.max_wait_ms=300000]
|
|
110
|
+
* @param {number} [options.poll_interval_ms=5000]
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<{
|
|
113
|
+
* task_id: string,
|
|
114
|
+
* file_id: string,
|
|
115
|
+
* video_url: string, // download_url
|
|
116
|
+
* local_path: string, // path in .cache/minimax/
|
|
117
|
+
* video_width: number,
|
|
118
|
+
* video_height: number,
|
|
119
|
+
* duration: number, // total time including polling
|
|
120
|
+
* raw: object
|
|
121
|
+
* }>}
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* // Text-to-Video
|
|
125
|
+
* const result = await generateVideo("A cat jumping on a table [Pan left]", {
|
|
126
|
+
* model: "MiniMax-Hailuo-2.3",
|
|
127
|
+
* duration: 6,
|
|
128
|
+
* resolution: "768P"
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // Image-to-Video
|
|
133
|
+
* const result = await generateVideo("The character walks forward", {
|
|
134
|
+
* model: "MiniMax-Hailuo-2.3",
|
|
135
|
+
* first_frame_image: "https://example.com/image.jpg"
|
|
136
|
+
* });
|
|
137
|
+
*/
|
|
138
|
+
export function generateVideo(prompt?: string, options?: {
|
|
139
|
+
max_wait_ms?: number | undefined;
|
|
140
|
+
poll_interval_ms?: number | undefined;
|
|
141
|
+
}): Promise<{
|
|
142
|
+
task_id: string;
|
|
143
|
+
file_id: string;
|
|
144
|
+
video_url: string;
|
|
145
|
+
local_path: string;
|
|
146
|
+
video_width: number;
|
|
147
|
+
video_height: number;
|
|
148
|
+
duration: number;
|
|
149
|
+
raw: object;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Internal helper: Waits for video generation task to complete by polling.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} taskId
|
|
155
|
+
* @param {number} [maxWaitMs=300000] - Max wait time (5 minutes default)
|
|
156
|
+
* @param {number} [pollIntervalMs=5000] - Poll every 5 seconds
|
|
157
|
+
* @returns {Promise<{status: string, file_id?: string, video_width?: number, video_height?: number, raw: object}>}
|
|
158
|
+
*/
|
|
159
|
+
export function waitForVideoReady(taskId: string, maxWaitMs?: number, pollIntervalMs?: number): Promise<{
|
|
160
|
+
status: string;
|
|
161
|
+
file_id?: string;
|
|
162
|
+
video_width?: number;
|
|
163
|
+
video_height?: number;
|
|
164
|
+
raw: object;
|
|
165
|
+
}>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds authenticated headers for Stability AI requests.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} [acceptHeader='audio/*'] - Accept header value.
|
|
5
|
+
* Use `'audio/*'` for binary audio response or `'application/json'` for base64 JSON.
|
|
6
|
+
* @returns {Object} Headers object containing Authorization (Bearer) and Accept.
|
|
7
|
+
* @throws {Error} If `STABILITY_API_KEY` environment variable is not set.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const headers = getHeaders('application/json');
|
|
11
|
+
*/
|
|
12
|
+
export function getHeaders(acceptHeader?: string): Object;
|
|
13
|
+
/**
|
|
14
|
+
* Saves audio data (Buffer, base64 string, URL, Blob, or ArrayBuffer) to a local file.
|
|
15
|
+
*
|
|
16
|
+
* @async
|
|
17
|
+
* @param {Buffer|string|Blob|ArrayBuffer} audioData - Audio content to save.
|
|
18
|
+
* - Buffer: raw bytes
|
|
19
|
+
* - string starting with 'http': remote URL (auto-downloaded)
|
|
20
|
+
* - base64 string: decoded
|
|
21
|
+
* - Blob/ArrayBuffer: converted
|
|
22
|
+
* @param {string} [filenamePrefix='stability-audio'] - Prefix for the generated filename.
|
|
23
|
+
* @param {string} [ext='mp3'] - File extension (`mp3` or `wav` recommended).
|
|
24
|
+
* @returns {Promise<string>} Absolute local file path of the saved audio.
|
|
25
|
+
* @throws {Error} For unsupported formats or download failures.
|
|
26
|
+
*/
|
|
27
|
+
export function saveAudioToLocal(audioData: Buffer | string | Blob | ArrayBuffer, filenamePrefix?: string, ext?: string): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Generates high-quality audio from a text prompt using Stable Audio 3.
|
|
30
|
+
*
|
|
31
|
+
* This is the primary text-to-audio endpoint. It submits a prompt and optional
|
|
32
|
+
* parameters, receives a generation ID (202), polls until ready, and returns
|
|
33
|
+
* the generated audio saved locally plus metadata.
|
|
34
|
+
*
|
|
35
|
+
* **Constraints** (from Stable Audio 3 spec):
|
|
36
|
+
* - Prompt: English only, max 10,000 characters, descriptive (instruments, mood, genre, style).
|
|
37
|
+
* - Duration: 1–380 seconds (default 190).
|
|
38
|
+
* - Steps: 4–8 (default 8).
|
|
39
|
+
* - CFG Scale: 1–25 (default 1).
|
|
40
|
+
* - Seed: 0 (random) or 0–4,294,967,294.
|
|
41
|
+
* - Output: mp3 (default) or wav at 44.1 kHz stereo.
|
|
42
|
+
* - Cost: Flat 26 credits per successful generation.
|
|
43
|
+
*
|
|
44
|
+
* @async
|
|
45
|
+
* @function textToAudio
|
|
46
|
+
* @param {string} prompt - Required descriptive text prompt. Must be non-empty English string.
|
|
47
|
+
* @param {Object} [options={}] - Optional generation parameters.
|
|
48
|
+
* @param {string} [options.model='stable-audio-3'] - Model identifier. Must be exactly `'stable-audio-3'`.
|
|
49
|
+
* @param {number} [options.duration=190] - Target duration in seconds (1 ≤ duration ≤ 380).
|
|
50
|
+
* @param {number} [options.seed=0] - Random seed for reproducibility (0 = random).
|
|
51
|
+
* @param {number} [options.steps=8] - Number of sampling steps (4–8).
|
|
52
|
+
* @param {number} [options.cfg_scale=1] - Prompt adherence strength (1–25).
|
|
53
|
+
* @param {string} [options.output_format='mp3'] - `'mp3'` or `'wav'`.
|
|
54
|
+
* @param {string} [options.accept='audio/*'] - Response format: `'audio/*'` (binary) or `'application/json'`.
|
|
55
|
+
* @param {string} [options.filenamePrefix='stability-text-to-audio'] - Prefix for saved file.
|
|
56
|
+
* @returns {Promise<Object>} Result object:
|
|
57
|
+
* ```js
|
|
58
|
+
* {
|
|
59
|
+
* local_path: '/path/to/.cache/stability/stability-text-to-audio-1234567890.mp3',
|
|
60
|
+
* finish_reason: 'SUCCESS',
|
|
61
|
+
* seed: 123456789,
|
|
62
|
+
* x_request_id: 'req_...',
|
|
63
|
+
* raw: { headers: {...} } // or full JSON if accept=application/json
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
* @throws {Error} - 'Missing STABILITY_API_KEY', invalid prompt, unsupported model,
|
|
67
|
+
* API errors (400/403/422/429/500), polling timeout, or download failures.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Basic usage
|
|
71
|
+
* const result = await textToAudio('upbeat electronic synthwave with driving bass');
|
|
72
|
+
* console.log('Saved to:', result.local_path);
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* // Advanced with options
|
|
76
|
+
* const result = await textToAudio(
|
|
77
|
+
* 'cinematic orchestral music, epic brass, strings, choir, 120 BPM',
|
|
78
|
+
* {
|
|
79
|
+
* duration: 240,
|
|
80
|
+
* seed: 42,
|
|
81
|
+
* steps: 8,
|
|
82
|
+
* cfg_scale: 7,
|
|
83
|
+
* output_format: 'wav',
|
|
84
|
+
* accept: 'application/json'
|
|
85
|
+
* }
|
|
86
|
+
* );
|
|
87
|
+
* if (result.audio_base64) {
|
|
88
|
+
* // handle base64
|
|
89
|
+
* }
|
|
90
|
+
*/
|
|
91
|
+
export function textToAudio(prompt: string, options?: {
|
|
92
|
+
model?: string | undefined;
|
|
93
|
+
duration?: number | undefined;
|
|
94
|
+
seed?: number | undefined;
|
|
95
|
+
steps?: number | undefined;
|
|
96
|
+
cfg_scale?: number | undefined;
|
|
97
|
+
output_format?: string | undefined;
|
|
98
|
+
accept?: string | undefined;
|
|
99
|
+
filenamePrefix?: string | undefined;
|
|
100
|
+
}): Promise<Object>;
|
|
101
|
+
/**
|
|
102
|
+
* Transforms an existing audio sample using a text prompt (audio-to-audio / style transfer).
|
|
103
|
+
*
|
|
104
|
+
* Uploads a reference audio file (or URL) and applies the prompt to generate a new
|
|
105
|
+
* composition that incorporates elements of the input while following the text description.
|
|
106
|
+
*
|
|
107
|
+
* **Additional Parameter**:
|
|
108
|
+
* - `strength`: Denoising strength (0.0 = identical to input, 1.0 = no influence from input).
|
|
109
|
+
*
|
|
110
|
+
* All other constraints and behavior are identical to `textToAudio`.
|
|
111
|
+
*
|
|
112
|
+
* @async
|
|
113
|
+
* @function audioToAudio
|
|
114
|
+
* @param {string} prompt - Descriptive text prompt (English, max 10k chars).
|
|
115
|
+
* @param {string|Buffer|Blob} audioInput - Reference audio:
|
|
116
|
+
* - Local file path (string)
|
|
117
|
+
* - Remote HTTP/HTTPS URL (string) – auto-downloaded with proper MIME
|
|
118
|
+
* - Buffer (raw bytes)
|
|
119
|
+
* - Blob (with optional name/type)
|
|
120
|
+
* @param {Object} [options={}] - Generation options (see textToAudio for common params).
|
|
121
|
+
* @param {number} [options.strength=1] - Denoising strength (0–1).
|
|
122
|
+
* @param {string} [options.filenamePrefix='stability-audio-to-audio']
|
|
123
|
+
* @returns {Promise<Object>} Same structure as textToAudio result.
|
|
124
|
+
* @throws {Error} Same as textToAudio plus audio input validation errors.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const result = await audioToAudio(
|
|
128
|
+
* 'transform into orchestral version with strings and choir',
|
|
129
|
+
* './reference-track.mp3',
|
|
130
|
+
* { strength: 0.75, duration: 180 }
|
|
131
|
+
* );
|
|
132
|
+
*/
|
|
133
|
+
export function audioToAudio(prompt: string, audioInput: string | Buffer | Blob, options?: {
|
|
134
|
+
strength?: number | undefined;
|
|
135
|
+
filenamePrefix?: string | undefined;
|
|
136
|
+
}): Promise<Object>;
|
|
137
|
+
/**
|
|
138
|
+
* Performs audio inpainting: replaces a specified time segment of an audio file
|
|
139
|
+
* with new content generated from a text prompt.
|
|
140
|
+
*
|
|
141
|
+
* Uses `mask_start` and `mask_end` to define the region to inpaint (in seconds).
|
|
142
|
+
* The model fills the masked section while preserving the rest of the audio.
|
|
143
|
+
*
|
|
144
|
+
* Default mask: 30s → 380s (inpaint most of a long track).
|
|
145
|
+
*
|
|
146
|
+
* @async
|
|
147
|
+
* @function inpaint
|
|
148
|
+
* @param {string} prompt - Text prompt describing the desired replacement content.
|
|
149
|
+
* @param {string|Buffer|Blob} audioInput - Reference audio (same as audioToAudio).
|
|
150
|
+
* @param {Object} [options={}] - Generation options.
|
|
151
|
+
* @param {number} [options.mask_start=30] - Start time (seconds) of the inpaint mask (0–380).
|
|
152
|
+
* @param {number} [options.mask_end=380] - End time (seconds) of the inpaint mask (0–380).
|
|
153
|
+
* @param {string} [options.filenamePrefix='stability-inpaint']
|
|
154
|
+
* @returns {Promise<Object>} Same result structure as other generation methods.
|
|
155
|
+
* @throws {Error} Validation errors for mask ranges, audio input, etc.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* // Inpaint the middle section
|
|
159
|
+
* const result = await inpaint(
|
|
160
|
+
* 'add a soaring guitar solo in this section',
|
|
161
|
+
* 'full-track.mp3',
|
|
162
|
+
* { mask_start: 60, mask_end: 120, duration: 180 }
|
|
163
|
+
* );
|
|
164
|
+
*/
|
|
165
|
+
export function inpaint(prompt: string, audioInput: string | Buffer | Blob, options?: {
|
|
166
|
+
mask_start?: number | undefined;
|
|
167
|
+
mask_end?: number | undefined;
|
|
168
|
+
filenamePrefix?: string | undefined;
|
|
169
|
+
}): Promise<Object>;
|
|
170
|
+
/**
|
|
171
|
+
* Manually fetches or checks the status of a generation using its ID.
|
|
172
|
+
* Useful for custom polling logic or resuming after a previous submission.
|
|
173
|
+
*
|
|
174
|
+
* @async
|
|
175
|
+
* @function fetchResult
|
|
176
|
+
* @param {string} id - Generation ID (from a previous 202 response).
|
|
177
|
+
* @param {string} [acceptHeader='audio/*'] - `'audio/*'` or `'application/json'`.
|
|
178
|
+
* @returns {Promise<Object>} Either:
|
|
179
|
+
* - Completed result (same as processResult)
|
|
180
|
+
* - `{ status: 'in-progress', id, raw }` if still 202
|
|
181
|
+
* @throws {Error} If ID missing, 404 (expired), or other API error.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* // Manual polling example
|
|
185
|
+
* const id = await submit...; // or from previous call
|
|
186
|
+
* let result;
|
|
187
|
+
* while (true) {
|
|
188
|
+
* result = await fetchResult(id);
|
|
189
|
+
* if (result.status !== 'in-progress') break;
|
|
190
|
+
* await new Promise(r => setTimeout(r, 5000));
|
|
191
|
+
* }
|
|
192
|
+
*/
|
|
193
|
+
export function fetchResult(id: string, acceptHeader?: string): Promise<Object>;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds authenticated headers for Stability AI requests.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} [acceptHeader='image/*'] - Accept header value.
|
|
5
|
+
* Use `'image/*'` for binary image response or `'application/json'` for base64 JSON.
|
|
6
|
+
* @returns {Object} Headers object containing Authorization (Bearer) and Accept.
|
|
7
|
+
* @throws {Error} If `STABILITY_API_KEY` environment variable is not set.
|
|
8
|
+
*/
|
|
9
|
+
export function getHeaders(acceptHeader?: string): Object;
|
|
10
|
+
/**
|
|
11
|
+
* Saves image data (Buffer, base64 string, URL, Blob, or ArrayBuffer) to a local file.
|
|
12
|
+
*
|
|
13
|
+
* @async
|
|
14
|
+
* @param {Buffer|string|Blob|ArrayBuffer} imageData - Image content to save.
|
|
15
|
+
* @param {string} [filenamePrefix='stability-image'] - Prefix for the generated filename.
|
|
16
|
+
* @param {string} [ext='png'] - File extension (`png`, `jpeg`, `webp`).
|
|
17
|
+
* @returns {Promise<string>} Absolute local file path of the saved image.
|
|
18
|
+
* @throws {Error} For unsupported formats or download failures.
|
|
19
|
+
*/
|
|
20
|
+
export function saveImageToLocal(imageData: Buffer | string | Blob | ArrayBuffer, filenamePrefix?: string, ext?: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Generates the highest quality photorealistic image using Stable Image Ultra.
|
|
23
|
+
*
|
|
24
|
+
* Our most advanced text-to-image model based on Stable Diffusion 3.5.
|
|
25
|
+
* Produces exceptional detail, realism, and prompt adherence — ideal for professional print and large-format applications.
|
|
26
|
+
*
|
|
27
|
+
* **Constraints** (from Stable Image Ultra spec):
|
|
28
|
+
* - Prompt: Max 10,000 characters. Strong descriptive prompt recommended.
|
|
29
|
+
* - Aspect ratio: One of `1:1` (default), `16:9`, `9:16`, `21:9`, `9:21`, `2:3`, `3:2`, `4:5`, `5:4`.
|
|
30
|
+
* - Image-to-image: Provide `image` + `strength` (0–1). Image must be 64px–16,384px per side.
|
|
31
|
+
* - Output resolution: 1 megapixel (default 1024×1024).
|
|
32
|
+
* - Cost: 8 credits per successful generation.
|
|
33
|
+
* - Output formats: `png` (default), `jpeg`, `webp`.
|
|
34
|
+
*
|
|
35
|
+
* @async
|
|
36
|
+
* @function generateUltra
|
|
37
|
+
* @param {string} prompt - Required descriptive prompt. Must be non-empty English string (max 10,000 chars).
|
|
38
|
+
* @param {Object} [options={}] - Optional generation parameters.
|
|
39
|
+
* @param {string} [options.negative_prompt] - Keywords describing what you do **not** want to see.
|
|
40
|
+
* @param {string} [options.aspect_ratio='1:1'] - Controls aspect ratio of the output image.
|
|
41
|
+
* @param {number} [options.seed=0] - Specific seed for reproducibility (0 = random, 0–4,294,967,294).
|
|
42
|
+
* @param {string} [options.output_format='png'] - `'png'`, `'jpeg'`, or `'webp'`.
|
|
43
|
+
* @param {string|Buffer|Blob} [options.image] - Optional reference image for image-to-image generation.
|
|
44
|
+
* @param {number} [options.strength] - Denoising strength (0–1). Required when `image` is provided.
|
|
45
|
+
* @param {string} [options.style_preset] - Guides the model toward a particular style (e.g. 'photographic', 'cinematic').
|
|
46
|
+
* @param {string} [options.accept='image/*'] - `'image/*'` (binary) or `'application/json'` (base64).
|
|
47
|
+
* @param {string} [options.filenamePrefix='stability-ultra'] - Prefix for saved local file.
|
|
48
|
+
* @returns {Promise<Object>} Standardized result:
|
|
49
|
+
* ```js
|
|
50
|
+
* {
|
|
51
|
+
* local_path: '/path/to/.cache/stability/stability-ultra-1234567890.png',
|
|
52
|
+
* finish_reason: 'SUCCESS',
|
|
53
|
+
* seed: 123456789,
|
|
54
|
+
* x_request_id: 'req_...',
|
|
55
|
+
* raw: { headers: {...} } // or full JSON if accept=application/json
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
* @throws {Error} - 'Missing STABILITY_API_KEY', invalid prompt, API errors (400/403/422/429/500), polling timeout, or download failures.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // Basic text-to-image
|
|
62
|
+
* const result = await generateUltra('majestic mountain landscape at sunset, cinematic lighting');
|
|
63
|
+
* console.log('Saved to:', result.local_path);
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Image-to-image with strength
|
|
67
|
+
* const result = await generateUltra(
|
|
68
|
+
* 'same scene but with dramatic storm clouds',
|
|
69
|
+
* {
|
|
70
|
+
* image: './reference.png',
|
|
71
|
+
* strength: 0.65,
|
|
72
|
+
* aspect_ratio: '16:9',
|
|
73
|
+
* output_format: 'webp'
|
|
74
|
+
* }
|
|
75
|
+
* );
|
|
76
|
+
*/
|
|
77
|
+
export function generateUltra(prompt: string, options?: {
|
|
78
|
+
negative_prompt?: string | undefined;
|
|
79
|
+
aspect_ratio?: string | undefined;
|
|
80
|
+
seed?: number | undefined;
|
|
81
|
+
output_format?: string | undefined;
|
|
82
|
+
image?: string | Buffer | Blob;
|
|
83
|
+
strength?: number | undefined;
|
|
84
|
+
style_preset?: string | undefined;
|
|
85
|
+
accept?: string | undefined;
|
|
86
|
+
filenamePrefix?: string | undefined;
|
|
87
|
+
}): Promise<Object>;
|
|
88
|
+
/**
|
|
89
|
+
* Generates fast and affordable images using Stable Image Core.
|
|
90
|
+
*
|
|
91
|
+
* Optimized for rapid iteration during ideation. Next-generation model following SDXL.
|
|
92
|
+
*
|
|
93
|
+
* **Constraints**:
|
|
94
|
+
* - Prompt: Max 10,000 characters.
|
|
95
|
+
* - Aspect ratio: Same options as Ultra.
|
|
96
|
+
* - Output resolution: 1.5 megapixels.
|
|
97
|
+
* - Cost: 3 credits per successful generation.
|
|
98
|
+
*
|
|
99
|
+
* @async
|
|
100
|
+
* @function generateCore
|
|
101
|
+
* @param {string} prompt - Required descriptive prompt.
|
|
102
|
+
* @param {Object} [options={}] - Optional parameters (negative_prompt, aspect_ratio, seed, output_format, style_preset, accept, filenamePrefix).
|
|
103
|
+
* @returns {Promise<Object>} Same result structure as generateUltra.
|
|
104
|
+
*/
|
|
105
|
+
export function generateCore(prompt: string, options?: Object): Promise<Object>;
|
|
106
|
+
/**
|
|
107
|
+
* Generates images using Stable Diffusion 3.5 models.
|
|
108
|
+
*
|
|
109
|
+
* Supports `sd3.5-large`, `sd3.5-large-turbo`, `sd3.5-medium`, `sd3.5-flash`.
|
|
110
|
+
*
|
|
111
|
+
* **Key Parameters**:
|
|
112
|
+
* - `mode`: `'text-to-image'` (default) or `'image-to-image'`.
|
|
113
|
+
* - For image-to-image: `image` + `strength` required.
|
|
114
|
+
* - `cfg_scale`: Prompt adherence (default 4 for Large/Medium, 1 for Turbo/Flash).
|
|
115
|
+
*
|
|
116
|
+
* @async
|
|
117
|
+
* @function generateSD3
|
|
118
|
+
* @param {string} prompt - Required prompt.
|
|
119
|
+
* @param {Object} [options={}] - Optional parameters including `mode`, `model`, `image`, `strength`, `cfg_scale`, etc.
|
|
120
|
+
* @returns {Promise<Object>} Same result structure.
|
|
121
|
+
*/
|
|
122
|
+
export function generateSD3(prompt: string, options?: Object): Promise<Object>;
|
|
123
|
+
/**
|
|
124
|
+
* Upscales an image conservatively while preserving original details.
|
|
125
|
+
*
|
|
126
|
+
* Takes images 64×64 to 1MP and upscales to 4MP with minimal alteration.
|
|
127
|
+
*
|
|
128
|
+
* **Constraints**:
|
|
129
|
+
* - Image: 64px–9,437,184 total pixels, aspect ratio 1:2.5 to 2.5:1.
|
|
130
|
+
* - Cost: 40 credits.
|
|
131
|
+
*
|
|
132
|
+
* @async
|
|
133
|
+
* @function upscaleConservative
|
|
134
|
+
* @param {string|Buffer|Blob} imageInput - Image to upscale.
|
|
135
|
+
* @param {string} prompt - Prompt describing desired output.
|
|
136
|
+
* @param {Object} [options={}] - Optional: negative_prompt, seed, output_format, creativity (0.2–0.5).
|
|
137
|
+
* @returns {Promise<Object>} Result with upscaled image.
|
|
138
|
+
*/
|
|
139
|
+
export function upscaleConservative(imageInput: string | Buffer | Blob, prompt: string, options?: Object): Promise<Object>;
|
|
140
|
+
/**
|
|
141
|
+
* Removes unwanted objects from an image using a mask or the alpha channel.
|
|
142
|
+
*
|
|
143
|
+
* The mask can be provided explicitly or derived from the alpha channel of the input image.
|
|
144
|
+
*
|
|
145
|
+
* **Constraints**:
|
|
146
|
+
* - Image: 64px–9,437,184 total pixels.
|
|
147
|
+
* - Cost: 5 credits.
|
|
148
|
+
*
|
|
149
|
+
* @async
|
|
150
|
+
* @function editErase
|
|
151
|
+
* @param {string|Buffer|Blob} imageInput - Image to edit.
|
|
152
|
+
* @param {Object} [options={}] - Optional parameters.
|
|
153
|
+
* @param {string|Buffer|Blob} [options.mask] - Optional mask image.
|
|
154
|
+
* @param {number} [options.grow_mask=5] - Grow mask edges by this many pixels.
|
|
155
|
+
* @param {number} [options.seed=0]
|
|
156
|
+
* @param {string} [options.output_format='png']
|
|
157
|
+
* @returns {Promise<Object>} Result with edited image.
|
|
158
|
+
*/
|
|
159
|
+
export function editErase(imageInput: string | Buffer | Blob, options?: {
|
|
160
|
+
mask?: string | Buffer | Blob;
|
|
161
|
+
grow_mask?: number | undefined;
|
|
162
|
+
seed?: number | undefined;
|
|
163
|
+
output_format?: string | undefined;
|
|
164
|
+
}): Promise<Object>;
|
|
165
|
+
/**
|
|
166
|
+
* Intelligently modifies images by filling or replacing areas based on a mask or search prompt.
|
|
167
|
+
*
|
|
168
|
+
* Supports two modes:
|
|
169
|
+
* - `mask` mode: Provide explicit `mask` or use alpha channel.
|
|
170
|
+
* - `search` mode: Provide `search_prompt` for automatic object segmentation.
|
|
171
|
+
*
|
|
172
|
+
* **Constraints**:
|
|
173
|
+
* - Image: 64px–9,437,184 total pixels.
|
|
174
|
+
* - Cost: 5 credits.
|
|
175
|
+
*
|
|
176
|
+
* @async
|
|
177
|
+
* @function editInpaint
|
|
178
|
+
* @param {string|Buffer|Blob} imageInput - Base image.
|
|
179
|
+
* @param {string} prompt - What the replaced area should become.
|
|
180
|
+
* @param {Object} [options={}] - Optional: negative_prompt, seed, output_format, style_preset, grow_mask, mask, mode, search_prompt.
|
|
181
|
+
* @returns {Promise<Object>} Result with edited image.
|
|
182
|
+
*/
|
|
183
|
+
export function editInpaint(imageInput: string | Buffer | Blob, prompt: string, options?: Object): Promise<Object>;
|
|
184
|
+
/**
|
|
185
|
+
* Expands an image by adding content in any direction (left, right, up, down).
|
|
186
|
+
*
|
|
187
|
+
* At least one direction must be non-zero.
|
|
188
|
+
*
|
|
189
|
+
* **Constraints**:
|
|
190
|
+
* - Image: 64px–9,437,184 total pixels, aspect ratio 1:2.5–2.5:1.
|
|
191
|
+
* - Cost: 4 credits.
|
|
192
|
+
*
|
|
193
|
+
* @async
|
|
194
|
+
* @function editOutpaint
|
|
195
|
+
* @param {string|Buffer|Blob} imageInput - Image to expand.
|
|
196
|
+
* @param {Object} [options={}] - Direction values in pixels (0–2000).
|
|
197
|
+
* @param {number} [options.left=0]
|
|
198
|
+
* @param {number} [options.right=0]
|
|
199
|
+
* @param {number} [options.up=0]
|
|
200
|
+
* @param {number} [options.down=0]
|
|
201
|
+
* @param {string} [options.prompt]
|
|
202
|
+
* @param {number} [options.creativity=0.5]
|
|
203
|
+
* @param {string} [options.style_preset]
|
|
204
|
+
* @returns {Promise<Object>} Result with expanded image.
|
|
205
|
+
*/
|
|
206
|
+
export function editOutpaint(imageInput: string | Buffer | Blob, options?: {
|
|
207
|
+
left?: number | undefined;
|
|
208
|
+
right?: number | undefined;
|
|
209
|
+
up?: number | undefined;
|
|
210
|
+
down?: number | undefined;
|
|
211
|
+
prompt?: string | undefined;
|
|
212
|
+
creativity?: number | undefined;
|
|
213
|
+
style_preset?: string | undefined;
|
|
214
|
+
}): Promise<Object>;
|
|
215
|
+
/**
|
|
216
|
+
* Automatically segments an object described by `search_prompt` and replaces it with new content from `prompt`.
|
|
217
|
+
*
|
|
218
|
+
* **Constraints**:
|
|
219
|
+
* - Image: 64px–9,437,184 total pixels.
|
|
220
|
+
* - Cost: 5 credits.
|
|
221
|
+
*
|
|
222
|
+
* @async
|
|
223
|
+
* @function editSearchAndReplace
|
|
224
|
+
* @param {string|Buffer|Blob} imageInput - Base image.
|
|
225
|
+
* @param {string} prompt - What to replace the object with.
|
|
226
|
+
* @param {string} search_prompt - Short description of the object to find.
|
|
227
|
+
* @param {Object} [options={}] - Optional: negative_prompt, seed, output_format, style_preset, grow_mask.
|
|
228
|
+
* @returns {Promise<Object>} Result with edited image.
|
|
229
|
+
*/
|
|
230
|
+
export function editSearchAndReplace(imageInput: string | Buffer | Blob, prompt: string, search_prompt: string, options?: Object): Promise<Object>;
|
|
231
|
+
/**
|
|
232
|
+
* Automatically segments an object and recolors it according to the prompt.
|
|
233
|
+
*
|
|
234
|
+
* @async
|
|
235
|
+
* @function editSearchAndRecolor
|
|
236
|
+
* @param {string|Buffer|Blob} imageInput - Base image.
|
|
237
|
+
* @param {string} prompt - Desired new color description.
|
|
238
|
+
* @param {string} select_prompt - Short description of the object to recolor.
|
|
239
|
+
* @param {Object} [options={}] - Optional parameters.
|
|
240
|
+
* @returns {Promise<Object>} Result with recolored image.
|
|
241
|
+
*/
|
|
242
|
+
export function editSearchAndRecolor(imageInput: string | Buffer | Blob, prompt: string, select_prompt: string, options?: Object): Promise<Object>;
|
|
243
|
+
/**
|
|
244
|
+
* Accurately segments the foreground and removes the background.
|
|
245
|
+
*
|
|
246
|
+
* @async
|
|
247
|
+
* @function editRemoveBackground
|
|
248
|
+
* @param {string|Buffer|Blob} imageInput - Image to process.
|
|
249
|
+
* @param {Object} [options={}] - Optional: output_format ('png' or 'webp').
|
|
250
|
+
* @returns {Promise<Object>} Result with background removed.
|
|
251
|
+
*/
|
|
252
|
+
export function editRemoveBackground(imageInput: string | Buffer | Blob, options?: Object): Promise<Object>;
|
|
253
|
+
/**
|
|
254
|
+
* Replaces the background and adjusts lighting to match the subject.
|
|
255
|
+
*
|
|
256
|
+
* Async endpoint — returns a generation ID for polling.
|
|
257
|
+
*
|
|
258
|
+
* @async
|
|
259
|
+
* @function editReplaceBackgroundAndRelight
|
|
260
|
+
* @param {string|Buffer|Blob} subjectImage - Main subject image.
|
|
261
|
+
* @param {Object} [options={}] - Optional parameters.
|
|
262
|
+
* @returns {Promise<string|Object>} Generation ID or processed result.
|
|
263
|
+
*/
|
|
264
|
+
export function editReplaceBackgroundAndRelight(subjectImage: string | Buffer | Blob, options?: Object): Promise<string | Object>;
|
|
265
|
+
/**
|
|
266
|
+
* Manually fetches or checks the status of an image generation using its ID.
|
|
267
|
+
*
|
|
268
|
+
* @async
|
|
269
|
+
* @function fetchImageResult
|
|
270
|
+
* @param {string} id - Generation ID.
|
|
271
|
+
* @param {string} [acceptHeader='image/*'] - `'image/*'` or `'application/json'`.
|
|
272
|
+
* @returns {Promise<Object>} Completed result or `{ status: 'in-progress', id }`.
|
|
273
|
+
*/
|
|
274
|
+
export function fetchImageResult(id: string, acceptHeader?: string): Promise<Object>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { music };
|
|
3
|
+
export { musicToolset };
|
|
4
|
+
export { image };
|
|
5
|
+
export { imageToolset };
|
|
6
|
+
}
|
|
7
|
+
export default _default;
|
|
8
|
+
import * as music from './audio.js';
|
|
9
|
+
import musicToolset from './MusicToolset.js';
|
|
10
|
+
import * as image from './image.js';
|
|
11
|
+
import imageToolset from './ImageToolset.js';
|