@vargai/sdk 0.1.1

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 (67) hide show
  1. package/.env.example +24 -0
  2. package/CLAUDE.md +118 -0
  3. package/HIGGSFIELD_REWRITE_SUMMARY.md +300 -0
  4. package/README.md +231 -0
  5. package/SKILLS.md +157 -0
  6. package/STRUCTURE.md +92 -0
  7. package/TEST_RESULTS.md +122 -0
  8. package/action/captions/SKILL.md +170 -0
  9. package/action/captions/index.ts +169 -0
  10. package/action/edit/SKILL.md +235 -0
  11. package/action/edit/index.ts +437 -0
  12. package/action/image/SKILL.md +140 -0
  13. package/action/image/index.ts +105 -0
  14. package/action/sync/SKILL.md +136 -0
  15. package/action/sync/index.ts +145 -0
  16. package/action/transcribe/SKILL.md +179 -0
  17. package/action/transcribe/index.ts +210 -0
  18. package/action/video/SKILL.md +116 -0
  19. package/action/video/index.ts +125 -0
  20. package/action/voice/SKILL.md +125 -0
  21. package/action/voice/index.ts +136 -0
  22. package/biome.json +33 -0
  23. package/bun.lock +842 -0
  24. package/cli/commands/find.ts +58 -0
  25. package/cli/commands/help.ts +70 -0
  26. package/cli/commands/list.ts +49 -0
  27. package/cli/commands/run.ts +237 -0
  28. package/cli/commands/which.ts +66 -0
  29. package/cli/discover.ts +66 -0
  30. package/cli/index.ts +33 -0
  31. package/cli/runner.ts +65 -0
  32. package/cli/types.ts +49 -0
  33. package/cli/ui.ts +185 -0
  34. package/index.ts +75 -0
  35. package/lib/README.md +144 -0
  36. package/lib/ai-sdk/fal.ts +106 -0
  37. package/lib/ai-sdk/replicate.ts +107 -0
  38. package/lib/elevenlabs.ts +382 -0
  39. package/lib/fal.ts +467 -0
  40. package/lib/ffmpeg.ts +467 -0
  41. package/lib/fireworks.ts +235 -0
  42. package/lib/groq.ts +246 -0
  43. package/lib/higgsfield/MIGRATION.md +308 -0
  44. package/lib/higgsfield/README.md +273 -0
  45. package/lib/higgsfield/example.ts +228 -0
  46. package/lib/higgsfield/index.ts +241 -0
  47. package/lib/higgsfield/soul.ts +262 -0
  48. package/lib/higgsfield.ts +176 -0
  49. package/lib/remotion/SKILL.md +823 -0
  50. package/lib/remotion/cli.ts +115 -0
  51. package/lib/remotion/functions.ts +283 -0
  52. package/lib/remotion/index.ts +19 -0
  53. package/lib/remotion/templates.ts +73 -0
  54. package/lib/replicate.ts +304 -0
  55. package/output.txt +1 -0
  56. package/package.json +42 -0
  57. package/pipeline/cookbooks/SKILL.md +285 -0
  58. package/pipeline/cookbooks/remotion-video.md +585 -0
  59. package/pipeline/cookbooks/round-video-character.md +337 -0
  60. package/pipeline/cookbooks/talking-character.md +59 -0
  61. package/scripts/produce-menopause-campaign.sh +202 -0
  62. package/service/music/SKILL.md +229 -0
  63. package/service/music/index.ts +296 -0
  64. package/test-import.ts +7 -0
  65. package/test-services.ts +97 -0
  66. package/tsconfig.json +29 -0
  67. package/utilities/s3.ts +147 -0
package/lib/groq.ts ADDED
@@ -0,0 +1,246 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * groq api wrapper for ultra-fast llm inference
5
+ * supports llama, mixtral, gemma models with blazing fast speeds
6
+ */
7
+
8
+ import Groq from "groq-sdk";
9
+ import type { Uploadable } from "groq-sdk/uploads";
10
+
11
+ const groq = new Groq({
12
+ apiKey: process.env.GROQ_API_KEY || "",
13
+ });
14
+
15
+ // types
16
+ export interface ChatCompletionOptions {
17
+ model?: string;
18
+ messages: Array<{
19
+ role: "system" | "user" | "assistant";
20
+ content: string;
21
+ }>;
22
+ temperature?: number;
23
+ maxTokens?: number;
24
+ stream?: boolean;
25
+ }
26
+
27
+ export interface TranscriptionOptions {
28
+ file: Uploadable;
29
+ model?: string;
30
+ language?: string;
31
+ prompt?: string;
32
+ temperature?: number;
33
+ }
34
+
35
+ // popular models
36
+ export const GROQ_MODELS = {
37
+ // llama models (meta)
38
+ LLAMA_90B: "llama-3.3-70b-versatile",
39
+ LLAMA_8B: "llama-3.1-8b-instant",
40
+ LLAMA_70B: "llama-3.1-70b-versatile",
41
+
42
+ // mixtral models (mistral)
43
+ MIXTRAL_8X7B: "mixtral-8x7b-32768",
44
+
45
+ // gemma models (google)
46
+ GEMMA_7B: "gemma-7b-it",
47
+ GEMMA_2_9B: "gemma2-9b-it",
48
+
49
+ // whisper for audio transcription
50
+ WHISPER_LARGE: "whisper-large-v3",
51
+ };
52
+
53
+ // core functions
54
+ export async function chatCompletion(options: ChatCompletionOptions) {
55
+ const {
56
+ model = GROQ_MODELS.LLAMA_90B,
57
+ messages,
58
+ temperature = 1,
59
+ maxTokens = 1024,
60
+ stream = false,
61
+ } = options;
62
+
63
+ if (!messages || messages.length === 0) {
64
+ throw new Error("messages array is required");
65
+ }
66
+
67
+ console.log(`[groq] chat completion with ${model}...`);
68
+
69
+ try {
70
+ if (stream) {
71
+ const streamResponse = await groq.chat.completions.create({
72
+ model,
73
+ messages,
74
+ temperature,
75
+ max_tokens: maxTokens,
76
+ stream: true,
77
+ });
78
+ console.log(`[groq] streaming response...`);
79
+ return streamResponse;
80
+ }
81
+
82
+ const response = await groq.chat.completions.create({
83
+ model,
84
+ messages,
85
+ temperature,
86
+ max_tokens: maxTokens,
87
+ stream: false,
88
+ });
89
+
90
+ const content = response.choices[0]?.message?.content || "";
91
+ console.log(`[groq] completed (${response.usage?.total_tokens} tokens)`);
92
+ return content;
93
+ } catch (error) {
94
+ console.error(`[groq] error:`, error);
95
+ throw error;
96
+ }
97
+ }
98
+
99
+ export async function transcribeAudio(options: TranscriptionOptions) {
100
+ const {
101
+ file,
102
+ model = GROQ_MODELS.WHISPER_LARGE,
103
+ language,
104
+ prompt,
105
+ temperature,
106
+ } = options;
107
+
108
+ if (!file) {
109
+ throw new Error("file is required");
110
+ }
111
+
112
+ console.log(`[groq] transcribing audio with ${model}...`);
113
+
114
+ try {
115
+ const response = await groq.audio.transcriptions.create({
116
+ file,
117
+ model,
118
+ language,
119
+ prompt,
120
+ temperature,
121
+ });
122
+
123
+ console.log(`[groq] transcription completed`);
124
+ return response.text;
125
+ } catch (error) {
126
+ console.error(`[groq] error:`, error);
127
+ throw error;
128
+ }
129
+ }
130
+
131
+ export async function listModels() {
132
+ console.log(`[groq] fetching available models...`);
133
+
134
+ try {
135
+ const response = await groq.models.list();
136
+ const models = Array.from(response.data);
137
+ console.log(`[groq] found ${models.length} models`);
138
+ return models;
139
+ } catch (error) {
140
+ console.error(`[groq] error:`, error);
141
+ throw error;
142
+ }
143
+ }
144
+
145
+ // cli
146
+ async function cli() {
147
+ const args = process.argv.slice(2);
148
+ const command = args[0];
149
+
150
+ if (!command || command === "help") {
151
+ console.log(`
152
+ usage:
153
+ bun run lib/groq.ts <command> [args]
154
+
155
+ commands:
156
+ chat <prompt> [model] chat completion
157
+ stream <prompt> [model] streaming chat completion
158
+ models list available models
159
+ help show this help
160
+
161
+ examples:
162
+ bun run lib/groq.ts chat "explain quantum computing"
163
+ bun run lib/groq.ts chat "write a haiku about cats" llama-3.1-8b-instant
164
+ bun run lib/groq.ts stream "tell me a story"
165
+ bun run lib/groq.ts models
166
+
167
+ popular models:
168
+ llama-3.3-70b-versatile - meta llama 3.3 70b (best quality)
169
+ llama-3.1-8b-instant - meta llama 3.1 8b (fastest)
170
+ llama-3.1-70b-versatile - meta llama 3.1 70b
171
+ mixtral-8x7b-32768 - mistral mixtral 8x7b
172
+ gemma2-9b-it - google gemma 2 9b
173
+ whisper-large-v3 - openai whisper (audio transcription)
174
+
175
+ environment:
176
+ GROQ_API_KEY - your groq api key
177
+ `);
178
+ process.exit(0);
179
+ }
180
+
181
+ try {
182
+ switch (command) {
183
+ case "chat": {
184
+ const prompt = args[1];
185
+ const model = args[2];
186
+
187
+ if (!prompt) {
188
+ throw new Error("prompt is required");
189
+ }
190
+
191
+ const response = await chatCompletion({
192
+ model: model || GROQ_MODELS.LLAMA_90B,
193
+ messages: [{ role: "user", content: prompt }],
194
+ });
195
+
196
+ console.log(`\n${response}\n`);
197
+ break;
198
+ }
199
+
200
+ case "stream": {
201
+ const prompt = args[1];
202
+ const model = args[2];
203
+
204
+ if (!prompt) {
205
+ throw new Error("prompt is required");
206
+ }
207
+
208
+ const stream = await chatCompletion({
209
+ model: model || GROQ_MODELS.LLAMA_90B,
210
+ messages: [{ role: "user", content: prompt }],
211
+ stream: true,
212
+ });
213
+
214
+ console.log("");
215
+ for await (const chunk of stream as AsyncIterable<{
216
+ choices: Array<{ delta: { content?: string } }>;
217
+ }>) {
218
+ const content = chunk.choices[0]?.delta?.content || "";
219
+ process.stdout.write(content);
220
+ }
221
+ console.log("\n");
222
+ break;
223
+ }
224
+
225
+ case "models": {
226
+ const models = await listModels();
227
+ console.log(
228
+ `\navailable models:\n${models.map((m) => ` ${m.id} - ${m.owned_by}`).join("\n")}\n`,
229
+ );
230
+ break;
231
+ }
232
+
233
+ default:
234
+ console.error(`unknown command: ${command}`);
235
+ console.log(`run 'bun run lib/groq.ts help' for usage`);
236
+ process.exit(1);
237
+ }
238
+ } catch (error) {
239
+ console.error(`[groq] error:`, error);
240
+ process.exit(1);
241
+ }
242
+ }
243
+
244
+ if (import.meta.main) {
245
+ cli();
246
+ }
@@ -0,0 +1,308 @@
1
+ # Migration Guide: @higgsfield/client to HTTP API
2
+
3
+ This guide helps you migrate from the old `@higgsfield/client` library to the new HTTP-based implementation.
4
+
5
+ ## Summary of Changes
6
+
7
+ ### What Changed
8
+
9
+ 1. **No external client library** - Now uses native `fetch()` for HTTP requests
10
+ 2. **Response structure** - New structure matching the official API
11
+ 3. **Parameter naming** - Uses snake_case (API convention) instead of camelCase
12
+ 4. **Queue management** - Direct access to status checking and cancellation
13
+ 5. **Webhook support** - Built-in webhook functionality
14
+
15
+ ### What Stayed the Same
16
+
17
+ - Authentication via environment variables
18
+ - Core functionality (generate, list styles)
19
+ - CLI commands (backward compatible)
20
+ - Async/await patterns
21
+
22
+ ## API Changes
23
+
24
+ ### Before (Old Client)
25
+
26
+ ```typescript
27
+ import { HiggsfieldClient, SoulSize, SoulQuality } from "@higgsfield/client";
28
+
29
+ const client = new HiggsfieldClient({
30
+ apiKey: process.env.HF_API_KEY,
31
+ apiSecret: process.env.HF_API_SECRET,
32
+ });
33
+
34
+ const jobSet = await client.generate("/v1/text2image/soul", {
35
+ prompt: "beautiful sunset",
36
+ width_and_height: SoulSize.PORTRAIT_1152x2048,
37
+ quality: SoulQuality.HD,
38
+ style_id: "some-style-id",
39
+ batch_size: 1,
40
+ enhance_prompt: false,
41
+ });
42
+
43
+ // Access results
44
+ const imageUrl = jobSet.jobs[0].results.raw.url;
45
+ console.log(jobSet.id);
46
+ console.log(jobSet.isCompleted);
47
+ ```
48
+
49
+ ### After (New HTTP API)
50
+
51
+ ```typescript
52
+ import { generateSoul, SoulSize, SoulQuality } from "./lib/higgsfield/soul";
53
+
54
+ const result = await generateSoul({
55
+ prompt: "beautiful sunset",
56
+ width_and_height: SoulSize.PORTRAIT_1152x2048,
57
+ quality: SoulQuality.HD,
58
+ style_id: "some-style-id",
59
+ batch_size: 1,
60
+ enhance_prompt: false,
61
+ });
62
+
63
+ // Access results
64
+ const imageUrl = result.images[0].url;
65
+ console.log(result.request_id);
66
+ console.log(result.status === "completed");
67
+ ```
68
+
69
+ ## Response Structure Changes
70
+
71
+ ### Old Structure
72
+
73
+ ```typescript
74
+ {
75
+ id: string;
76
+ isCompleted: boolean;
77
+ isFailed: boolean;
78
+ jobs: Array<{
79
+ results: {
80
+ raw: { url: string };
81
+ };
82
+ }>;
83
+ }
84
+ ```
85
+
86
+ ### New Structure
87
+
88
+ ```typescript
89
+ {
90
+ status: "queued" | "in_progress" | "completed" | "failed" | "nsfw" | "canceled";
91
+ request_id: string;
92
+ status_url: string;
93
+ cancel_url: string;
94
+ images?: Array<{ url: string }>;
95
+ video?: { url: string };
96
+ error?: string;
97
+ }
98
+ ```
99
+
100
+ ## Common Migration Patterns
101
+
102
+ ### Pattern 1: Simple Generation
103
+
104
+ **Before:**
105
+ ```typescript
106
+ const jobSet = await client.generate("/v1/text2image/soul", {
107
+ prompt: "test",
108
+ width_and_height: SoulSize.PORTRAIT_1152x2048,
109
+ });
110
+
111
+ if (jobSet.isCompleted && jobSet.jobs.length > 0) {
112
+ const url = jobSet.jobs[0].results.raw.url;
113
+ }
114
+ ```
115
+
116
+ **After:**
117
+ ```typescript
118
+ const result = await generateSoul({
119
+ prompt: "test",
120
+ width_and_height: SoulSize.PORTRAIT_1152x2048,
121
+ });
122
+
123
+ if (result.status === "completed" && result.images) {
124
+ const url = result.images[0].url;
125
+ }
126
+ ```
127
+
128
+ ### Pattern 2: Error Handling
129
+
130
+ **Before:**
131
+ ```typescript
132
+ if (jobSet.isFailed) {
133
+ console.error("Generation failed");
134
+ }
135
+ ```
136
+
137
+ **After:**
138
+ ```typescript
139
+ if (result.status === "failed") {
140
+ console.error(`Generation failed: ${result.error}`);
141
+ } else if (result.status === "nsfw") {
142
+ console.error("Content flagged as NSFW");
143
+ }
144
+ ```
145
+
146
+ ### Pattern 3: List Styles
147
+
148
+ **Before:**
149
+ ```typescript
150
+ const styles = await client.getSoulStyles();
151
+ ```
152
+
153
+ **After:**
154
+ ```typescript
155
+ import { listSoulStyles } from "./lib/higgsfield/soul";
156
+
157
+ const styles = await listSoulStyles();
158
+ ```
159
+
160
+ ## New Features
161
+
162
+ ### 1. Manual Queue Management
163
+
164
+ ```typescript
165
+ import { SoulClient } from "./lib/higgsfield/soul";
166
+
167
+ const client = new SoulClient();
168
+
169
+ // Submit request
170
+ const request = await client.submitRequest("soul", {
171
+ prompt: "test",
172
+ });
173
+
174
+ // Check status later
175
+ const status = await client.getStatus(request.request_id);
176
+
177
+ // Cancel if needed
178
+ if (status.status === "queued") {
179
+ await client.cancelRequest(request.request_id);
180
+ }
181
+ ```
182
+
183
+ ### 2. Webhook Support
184
+
185
+ ```typescript
186
+ const result = await generateSoul(
187
+ {
188
+ prompt: "test",
189
+ },
190
+ {
191
+ webhook: "https://your-webhook.url/endpoint",
192
+ },
193
+ );
194
+
195
+ // Returns immediately with request info
196
+ // Your webhook receives the result when ready
197
+ ```
198
+
199
+ ### 3. Status Updates During Generation
200
+
201
+ ```typescript
202
+ const result = await generateSoul(
203
+ {
204
+ prompt: "test",
205
+ },
206
+ {
207
+ onUpdate: (status) => {
208
+ console.log(`Current status: ${status.status}`);
209
+ },
210
+ },
211
+ );
212
+ ```
213
+
214
+ ## Breaking Changes Checklist
215
+
216
+ - [ ] Update imports from `@higgsfield/client` to `./lib/higgsfield/soul`
217
+ - [ ] Change `jobSet.jobs[0].results.raw.url` to `result.images[0].url`
218
+ - [ ] Change `jobSet.id` to `result.request_id`
219
+ - [ ] Change `jobSet.isCompleted` to `result.status === "completed"`
220
+ - [ ] Change `jobSet.isFailed` to `result.status === "failed"`
221
+ - [ ] Remove `@higgsfield/client` from package.json
222
+ - [ ] Run `bun install` to clean up dependencies
223
+ - [ ] Update parameter names to snake_case if using object literals
224
+
225
+ ## Environment Variables
226
+
227
+ No changes needed - same variables work:
228
+
229
+ ```bash
230
+ export HIGGSFIELD_API_KEY="your-key"
231
+ export HIGGSFIELD_SECRET="your-secret"
232
+
233
+ # or
234
+
235
+ export HF_API_KEY="your-key"
236
+ export HF_API_SECRET="your-secret"
237
+ ```
238
+
239
+ ## CLI Commands
240
+
241
+ ### Backward Compatible
242
+
243
+ ```bash
244
+ # Old commands still work
245
+ bun run lib/higgsfield.ts generate_soul "prompt"
246
+ bun run lib/higgsfield.ts list_styles
247
+ ```
248
+
249
+ ### New Commands (More Features)
250
+
251
+ ```bash
252
+ # Generate
253
+ bun run lib/higgsfield/soul.ts generate "prompt" "style-id"
254
+
255
+ # List styles
256
+ bun run lib/higgsfield/soul.ts list_styles
257
+
258
+ # Check status
259
+ bun run lib/higgsfield/soul.ts status "request-id"
260
+
261
+ # Cancel request
262
+ bun run lib/higgsfield/soul.ts cancel "request-id"
263
+ ```
264
+
265
+ ## Testing Your Migration
266
+
267
+ ```bash
268
+ # Run examples to verify everything works
269
+ bun run lib/higgsfield/example.ts simple
270
+ bun run lib/higgsfield/example.ts style
271
+ bun run lib/higgsfield/example.ts all
272
+ ```
273
+
274
+ ## Rollback Plan
275
+
276
+ If you need to temporarily rollback:
277
+
278
+ 1. Reinstall the old client:
279
+ ```bash
280
+ bun add @higgsfield/client@^0.1.2
281
+ ```
282
+
283
+ 2. Restore old imports in your code
284
+
285
+ 3. The old implementation is still available in git history if needed
286
+
287
+ ## Getting Help
288
+
289
+ - See `lib/higgsfield/README.md` for full documentation
290
+ - See `lib/higgsfield/example.ts` for usage examples
291
+ - Check the official API docs at https://platform.higgsfield.ai
292
+
293
+ ## Benefits of Migration
294
+
295
+ ✅ No external client library dependency
296
+ ✅ Full control over HTTP requests
297
+ ✅ Webhook support for production workflows
298
+ ✅ Better error messages
299
+ ✅ Cancel pending requests
300
+ ✅ Direct API compatibility
301
+ ✅ Smaller bundle size
302
+ ✅ More TypeScript types
303
+
304
+ ## Questions?
305
+
306
+ Open an issue or check the examples in `lib/higgsfield/example.ts` for common use cases.
307
+
308
+