@genspark/cli 1.0.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.
- package/README.md +474 -0
- package/dist/client.d.ts +35 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +202 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +116 -0
- package/dist/config.js.map +1 -0
- package/dist/formatter.d.ts +13 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +68 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +613 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +63 -0
- package/dist/logger.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/updater.d.ts +15 -0
- package/dist/updater.d.ts.map +1 -0
- package/dist/updater.js +130 -0
- package/dist/updater.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
# Genspark Tool CLI (gsk)
|
|
2
|
+
|
|
3
|
+
Command-line interface for Genspark AI services. Provides web search, content crawling, image/video/audio generation, file management, and service URL creation.
|
|
4
|
+
|
|
5
|
+
Designed for integration with AI agents (e.g., OpenCode) — results go to stdout as JSON, progress/debug info goes to stderr.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Pre-installed in the Genspark Desktop sandbox container. The binary is available as `gsk` (or `genspark`).
|
|
10
|
+
|
|
11
|
+
For manual setup:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cd resources/genspark-tool-cli
|
|
15
|
+
npm install
|
|
16
|
+
npm run build
|
|
17
|
+
# Binary: dist/index.js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Node.js >= 18.
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
Config is loaded from three sources (highest priority first):
|
|
25
|
+
|
|
26
|
+
1. **CLI options** — `--api-key`, `--base-url`, etc.
|
|
27
|
+
2. **Environment variables** — `GSK_API_KEY`, `GSK_BASE_URL`, `GSK_PROJECT_ID`
|
|
28
|
+
3. **Config file** — `~/.genspark-tool-cli/config.json`
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"api_key": "gsk_...",
|
|
33
|
+
"base_url": "http://host.containers.internal:3000",
|
|
34
|
+
"project_id": "project_abc123",
|
|
35
|
+
"debug": false,
|
|
36
|
+
"timeout": 300000
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
In the Genspark Desktop container, this config file is auto-generated on container start.
|
|
41
|
+
|
|
42
|
+
## Global Options
|
|
43
|
+
|
|
44
|
+
| Option | Env Var | Default | Description |
|
|
45
|
+
|--------|---------|---------|-------------|
|
|
46
|
+
| `--api-key <key>` | `GSK_API_KEY` | — | API key (required) |
|
|
47
|
+
| `--base-url <url>` | `GSK_BASE_URL` | `http://localhost:8582` | Backend API base URL |
|
|
48
|
+
| `--project-id <id>` | `GSK_PROJECT_ID` | — | Project ID for access control |
|
|
49
|
+
| `--debug` | — | `false` | Enable debug output |
|
|
50
|
+
| `--timeout <ms>` | — | `300000` (5 min) | Request timeout |
|
|
51
|
+
| `--output <format>` | — | `json` | Output format: `json` or `text` |
|
|
52
|
+
|
|
53
|
+
## Commands
|
|
54
|
+
|
|
55
|
+
### list-tools (alias: `ls`)
|
|
56
|
+
|
|
57
|
+
List all available tools from the backend.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
gsk list-tools
|
|
61
|
+
gsk ls
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### web_search (alias: `search`)
|
|
65
|
+
|
|
66
|
+
Search the web.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
gsk search "latest AI news"
|
|
70
|
+
gsk search "latest AI news" -n 5
|
|
71
|
+
gsk search "最新のAIニュース" -l ja
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Option | Default | Description |
|
|
75
|
+
|--------|---------|-------------|
|
|
76
|
+
| `-n, --num <count>` | `10` | Number of results (1-50) |
|
|
77
|
+
| `-l, --language <code>` | — | Language code (e.g., `en`, `zh`, `ja`) |
|
|
78
|
+
|
|
79
|
+
### crawler (alias: `crawl`)
|
|
80
|
+
|
|
81
|
+
Extract content from a web page or document.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
gsk crawl "https://example.com/article"
|
|
85
|
+
gsk crawl "https://example.com/gallery" --images
|
|
86
|
+
gsk crawl "https://example.com/page" --no-text --images
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Option | Default | Description |
|
|
90
|
+
|--------|---------|-------------|
|
|
91
|
+
| `--no-text` | extract text | Skip text content extraction |
|
|
92
|
+
| `-i, --images` | `false` | Include image URLs in response |
|
|
93
|
+
|
|
94
|
+
### summarize_large_document (alias: `summarize`)
|
|
95
|
+
|
|
96
|
+
Analyze a document and answer questions about it.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
gsk summarize "https://example.com/report.pdf" "What are the key findings?"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Arguments: `<url>` `<question>`
|
|
103
|
+
|
|
104
|
+
### image_search (alias: `img-search`)
|
|
105
|
+
|
|
106
|
+
Search for images on the web.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
gsk img-search "modern architecture"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### understand_images (alias: `analyze`)
|
|
113
|
+
|
|
114
|
+
Analyze images with AI vision model.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
gsk analyze "Describe this image" -i "https://example.com/image.jpg"
|
|
118
|
+
gsk analyze "Extract all text" -i "https://img1.jpg" "https://img2.jpg"
|
|
119
|
+
gsk analyze "What's in this photo?" -i "https://example.com/photo.jpg"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
| Option | Default | Description |
|
|
123
|
+
|--------|---------|-------------|
|
|
124
|
+
| `-i, --image_urls <url...>` | — | Image URL(s) to analyze (**required**, can specify multiple) |
|
|
125
|
+
| `-r, --instruction <text>` | — | Custom analysis instruction |
|
|
126
|
+
|
|
127
|
+
### image_generation (alias: `img`)
|
|
128
|
+
|
|
129
|
+
Generate images using AI. Supports text-to-image and image-to-image.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Text-to-image
|
|
133
|
+
gsk img "A beautiful sunset over mountains" -r "16:9" -o ./sunset.png
|
|
134
|
+
gsk img "Modern office at night" -s "4k" -r "1:1"
|
|
135
|
+
|
|
136
|
+
# Image-to-image (reference-based)
|
|
137
|
+
gsk upload "./reference.png"
|
|
138
|
+
# Output: { "data": { "file_wrapper_url": "https://www.genspark.ai/api/files/s/abc123", ... } }
|
|
139
|
+
gsk img "A portrait in similar style" -i "https://www.genspark.ai/api/files/s/abc123"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
| Option | Default | Description |
|
|
143
|
+
|--------|---------|-------------|
|
|
144
|
+
| `-r, --aspect_ratio <ratio>` | `1:1` | Aspect ratio (`1:1`, `16:9`, `9:16`) |
|
|
145
|
+
| `-s, --image_size <size>` | `auto` | Image size: `auto`, `2k`, `4k` |
|
|
146
|
+
| `-m, --model <name>` | — | Model to use (optional) |
|
|
147
|
+
| `-i, --image_urls <url...>` | — | Reference image URL(s) for image-to-image |
|
|
148
|
+
| `-o, --output-file <path>` | — | Download the generated file to a local path |
|
|
149
|
+
|
|
150
|
+
### video_generation (alias: `video`)
|
|
151
|
+
|
|
152
|
+
Generate videos using AI.
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
gsk video "A cat playing with yarn" -m "kling/v1.6/standard" -d 5 -o ./cat.mp4
|
|
156
|
+
gsk video "Sunrise over a beach" -m "minimax/hailuo-02/standard" -r "16:9" -d 8
|
|
157
|
+
|
|
158
|
+
# Image-to-video
|
|
159
|
+
gsk upload "./photo.jpg"
|
|
160
|
+
gsk video "Camera pan around the subject" -m "kling/v1.6/standard" -i "https://www.genspark.ai/api/files/s/abc123"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
| Option | Default | Description |
|
|
164
|
+
|--------|---------|-------------|
|
|
165
|
+
| `-m, --model <name>` | — | Model (**required**). e.g., `kling/v1.6/standard`, `minimax/hailuo-02/standard` |
|
|
166
|
+
| `-r, --aspect_ratio <ratio>` | `16:9` | Aspect ratio |
|
|
167
|
+
| `-d, --duration <sec>` | `5` | Duration in seconds (2-15) |
|
|
168
|
+
| `-i, --image_urls <url...>` | — | Reference image URL(s) |
|
|
169
|
+
| `-a, --audio_url <url>` | — | Audio URL for soundtrack |
|
|
170
|
+
| `-o, --output-file <path>` | — | Download the generated file to a local path |
|
|
171
|
+
|
|
172
|
+
### audio_generation (alias: `audio`)
|
|
173
|
+
|
|
174
|
+
Generate audio: TTS, music, or sound effects.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Text-to-speech
|
|
178
|
+
gsk audio "Hello, welcome to Genspark!" -m "google/gemini-2.5-pro-preview-tts" -r "professional female voice"
|
|
179
|
+
gsk audio "Hello, welcome to Genspark!" -m "google/gemini-2.5-pro-preview-tts" -o ./hello.mp3
|
|
180
|
+
|
|
181
|
+
# Music with lyrics
|
|
182
|
+
gsk audio "A pop song" -m "fal-ai/minimax/speech-2.6-hd" -l "Verse 1: ..." -d 120
|
|
183
|
+
|
|
184
|
+
# Sound effect
|
|
185
|
+
gsk audio "Door creaking slowly open" -m "sfx-model"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
| Option | Default | Description |
|
|
189
|
+
|--------|---------|-------------|
|
|
190
|
+
| `-m, --model <name>` | — | Model (**required**). e.g., `elevenlabs/v3-tts`, `fal-ai/minimax/speech-2.6-hd` |
|
|
191
|
+
| `-d, --duration <sec>` | `0` (auto) | Duration in seconds |
|
|
192
|
+
| `-r, --requirements <text>` | — | Voice requirements for TTS |
|
|
193
|
+
| `-l, --lyrics <text>` | — | Lyrics for song generation |
|
|
194
|
+
| `-o, --output-file <path>` | — | Download the generated file to a local path |
|
|
195
|
+
|
|
196
|
+
### upload
|
|
197
|
+
|
|
198
|
+
Upload a local file and get a file wrapper URL.
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
gsk upload "./image.png"
|
|
202
|
+
gsk upload "/home/user/workspace/document.pdf"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Supported file types** (auto-detected from extension):
|
|
206
|
+
- Images: `.jpg`, `.jpeg`, `.png`, `.gif`, `.webp`
|
|
207
|
+
- Documents: `.pdf`, `.txt`, `.md`, `.html`, `.xml`, `.csv`
|
|
208
|
+
- Code: `.js`, `.ts`, `.css`
|
|
209
|
+
- Media: `.mp3`, `.mp4`, `.wav`, `.webm`
|
|
210
|
+
- Archives: `.zip`
|
|
211
|
+
- Data: `.json`
|
|
212
|
+
- Other: `application/octet-stream`
|
|
213
|
+
|
|
214
|
+
**Process:**
|
|
215
|
+
1. Requests a pre-signed upload URL from the backend
|
|
216
|
+
2. Uploads file to Azure Blob Storage via PUT
|
|
217
|
+
3. Returns a file wrapper URL for use in other commands
|
|
218
|
+
|
|
219
|
+
**Output:**
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"status": "ok",
|
|
223
|
+
"message": "File uploaded successfully",
|
|
224
|
+
"data": {
|
|
225
|
+
"file_wrapper_url": "https://www.genspark.ai/api/files/s/abc123",
|
|
226
|
+
"file_name": "image.png",
|
|
227
|
+
"content_type": "image/png",
|
|
228
|
+
"size_bytes": 123456
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### download
|
|
234
|
+
|
|
235
|
+
Download a file from a file wrapper URL.
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Get download URL only
|
|
239
|
+
gsk download "https://www.genspark.ai/api/files/s/abc123"
|
|
240
|
+
|
|
241
|
+
# Download and save to local file
|
|
242
|
+
gsk download "https://www.genspark.ai/api/files/s/abc123" -s "./downloaded.png"
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
| Option | Description |
|
|
246
|
+
|--------|-------------|
|
|
247
|
+
| `-s, --save <path>` | Download and save to local file path |
|
|
248
|
+
|
|
249
|
+
### analyze_media (alias: `media-analyze`)
|
|
250
|
+
|
|
251
|
+
Analyze various types of media content including images, audio, and video.
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
gsk media-analyze -i "https://example.com/image.jpg" -r "Describe the content"
|
|
255
|
+
gsk media-analyze -i "https://example.com/video.mp4" -r "Summarize the video"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
| Option | Default | Description |
|
|
259
|
+
|--------|---------|-------------|
|
|
260
|
+
| `-i, --media_urls <urls>` | — | Media URL(s) to analyze (**required**) |
|
|
261
|
+
| `-r, --requirements <text>` | — | Analysis instructions |
|
|
262
|
+
|
|
263
|
+
### audio_transcribe (alias: `transcribe`)
|
|
264
|
+
|
|
265
|
+
Transcribe audio files to text. Supports multiple audio formats.
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
gsk transcribe -i "https://example.com/audio.mp3"
|
|
269
|
+
gsk transcribe -i "https://example.com/meeting.wav" -m "whisper-large-v3"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
| Option | Default | Description |
|
|
273
|
+
|--------|---------|-------------|
|
|
274
|
+
| `-i, --audio_urls <url...>` | — | Audio URL(s) to transcribe (**required**) |
|
|
275
|
+
| `-m, --model <name>` | — | Transcription model to use |
|
|
276
|
+
|
|
277
|
+
### get_service_url (alias: `service-url`)
|
|
278
|
+
|
|
279
|
+
Get a public HTTPS URL for a service running in the sandbox.
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
gsk service-url --port 3000
|
|
283
|
+
gsk service-url --port 8080 -n "My API" --health-check "/health"
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
| Option | Default | Description |
|
|
287
|
+
|--------|---------|-------------|
|
|
288
|
+
| `--port <number>` | — | Port where service is running (**required**) |
|
|
289
|
+
| `-s, --sandbox <id>` | — | Sandbox ID (optional, auto-detected from project_id) |
|
|
290
|
+
| `-n, --name <name>` | — | Service name for logging |
|
|
291
|
+
| `--health-check <path>` | — | Health check endpoint path |
|
|
292
|
+
|
|
293
|
+
### aidrive (alias: `drive`)
|
|
294
|
+
|
|
295
|
+
AI-Drive file storage and management. List, create, delete, move files and directories. Download videos, audio, and files from URLs directly to AI-Drive.
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# List files in root directory
|
|
299
|
+
gsk drive ls
|
|
300
|
+
gsk drive ls -p "/documents" -f file
|
|
301
|
+
|
|
302
|
+
# Create directory
|
|
303
|
+
gsk drive mkdir -p "/my-folder"
|
|
304
|
+
|
|
305
|
+
# Move file
|
|
306
|
+
gsk drive move -p "/old-path/file.txt" --target_path "/new-path/file.txt"
|
|
307
|
+
|
|
308
|
+
# Download video/audio/file to AI-Drive
|
|
309
|
+
gsk drive download_video --video_url "https://example.com/video.mp4" --target_folder "/videos"
|
|
310
|
+
gsk drive download_file --file_url "https://example.com/doc.pdf" --target_folder "/docs"
|
|
311
|
+
|
|
312
|
+
# Upload content to AI-Drive
|
|
313
|
+
gsk drive upload --file_content "Hello World" --upload_path "/notes/hello.txt"
|
|
314
|
+
|
|
315
|
+
# Get readable URL for a file
|
|
316
|
+
gsk drive get_readable_url -p "/documents/report.pdf"
|
|
317
|
+
|
|
318
|
+
# Compress/decompress
|
|
319
|
+
gsk drive compress -p "/my-folder"
|
|
320
|
+
gsk drive decompress -p "/archive.zip"
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
| Option | Default | Description |
|
|
324
|
+
|--------|---------|-------------|
|
|
325
|
+
| `-p, --path <path>` | — | File or directory path in AI-Drive |
|
|
326
|
+
| `-f, --filter_type <type>` | `all` | Filter: `all`, `file`, `directory` |
|
|
327
|
+
| `--file_type <type>` | `all` | File type filter: `all`, `audio`, `video`, `image` |
|
|
328
|
+
| `--target_path <path>` | — | Target path for move operations |
|
|
329
|
+
| `--target_folder <path>` | — | Target folder for downloads |
|
|
330
|
+
| `--video_url <url>` | — | Video URL for download_video action |
|
|
331
|
+
| `--audio_url <url>` | — | Audio URL for download_audio action |
|
|
332
|
+
| `--file_url <url>` | — | File URL for download_file action |
|
|
333
|
+
| `--file_name <name>` | — | Custom file name for downloads |
|
|
334
|
+
| `--file_content <text>` | — | Content to upload |
|
|
335
|
+
| `--upload_path <path>` | — | Destination path for upload |
|
|
336
|
+
|
|
337
|
+
### create_task (alias: `task`)
|
|
338
|
+
|
|
339
|
+
Create and execute tasks using specialized AI agents. Supports multiple agent types for content generation.
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
# Create a podcast
|
|
343
|
+
gsk task podcasts --task_name "AI Trends" --query "Create a podcast about AI trends in 2025" --instructions "Focus on practical applications"
|
|
344
|
+
|
|
345
|
+
# Create a document
|
|
346
|
+
gsk task docs --task_name "Quantum Report" --query "Write a technical report on quantum computing" --instructions "Include recent breakthroughs"
|
|
347
|
+
|
|
348
|
+
# Create slides
|
|
349
|
+
gsk task slides --task_name "Q4 Results" --query "Create a presentation about our Q4 results" --instructions "Use charts and data visualizations"
|
|
350
|
+
|
|
351
|
+
# Deep research
|
|
352
|
+
gsk task deep_research --task_name "Fusion Energy" --query "Research the latest advances in fusion energy" --instructions "Cover both public and private sector"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
| Option | Default | Description |
|
|
356
|
+
|--------|---------|-------------|
|
|
357
|
+
| `--task_name <name>` | — | Name for the task/project (**required**) |
|
|
358
|
+
| `--query <text>` | — | Query describing what to create (**required**) |
|
|
359
|
+
| `--instructions <text>` | — | Detailed instructions for the agent (**required**) |
|
|
360
|
+
|
|
361
|
+
**Supported task types:** `super_agent`, `podcasts`, `docs`, `slides`, `deep_research`, `website`, `video_generation`, `audio_generation`
|
|
362
|
+
|
|
363
|
+
### stock_price (alias: `stock`)
|
|
364
|
+
|
|
365
|
+
Retrieve current stock price information, company profile, financial metrics, and ratios.
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
gsk stock AAPL
|
|
369
|
+
gsk stock MSFT
|
|
370
|
+
gsk stock GOOGL
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Returns stock data including 5-year historical prices, daily prices, company profile, financial metrics, and ratios.
|
|
374
|
+
|
|
375
|
+
## File Wrapper URLs
|
|
376
|
+
|
|
377
|
+
URLs in format `https://www.genspark.ai/api/files/s/...` are file wrapper URLs that require authentication.
|
|
378
|
+
|
|
379
|
+
- **Cannot** be accessed directly with `wget`, `curl`, or browsers (401/403)
|
|
380
|
+
- **Download**: `gsk download <url> -s <local_path>`
|
|
381
|
+
- **Upload**: `gsk upload <local_path>` to get a file wrapper URL
|
|
382
|
+
|
|
383
|
+
**In most cases you don't need to handle these manually** — `gsk analyze`, `gsk img`, `gsk video`, and `gsk summarize` accept local file paths directly via `-i` and auto-upload them. Use `-o` to save generated results locally.
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
# Direct local file workflow (preferred):
|
|
387
|
+
gsk img "Enhance this" -i ./photo.png -o ./result.png
|
|
388
|
+
|
|
389
|
+
# Manual upload/download (rarely needed):
|
|
390
|
+
gsk upload "./photo.png"
|
|
391
|
+
gsk download "https://www.genspark.ai/api/files/s/abc123" -s "./result.png"
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## API Protocol
|
|
395
|
+
|
|
396
|
+
The CLI communicates with the backend via streaming NDJSON (newline-delimited JSON) over HTTP POST to `/api/tool_cli/<tool_name>`.
|
|
397
|
+
|
|
398
|
+
### Request Headers
|
|
399
|
+
|
|
400
|
+
```
|
|
401
|
+
Content-Type: application/json
|
|
402
|
+
X-Api-Key: <api_key>
|
|
403
|
+
X-Project-ID: <project_id> (if configured)
|
|
404
|
+
X-Debug: true (if --debug enabled)
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Response Format
|
|
408
|
+
|
|
409
|
+
Server streams multiple JSON lines:
|
|
410
|
+
|
|
411
|
+
```jsonl
|
|
412
|
+
{"version": 1, "debug": true, "message": "Starting search..."}
|
|
413
|
+
{"version": 1, "debug": true, "message": "Found 5 results", "elapsed_seconds": 1.2}
|
|
414
|
+
{"version": 1, "status": "ok", "message": "Search complete", "data": {...}}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
- **Debug lines** (`"debug": true`): Progress messages, only shown to stderr when `--debug` is enabled
|
|
418
|
+
- **Final result**: Has `"status": "ok"` or `"status": "error"` with `"data"` field
|
|
419
|
+
- **Protocol versioning**: Messages with `version > 1` are silently ignored (forward compatibility)
|
|
420
|
+
|
|
421
|
+
## Output Conventions
|
|
422
|
+
|
|
423
|
+
| Stream | Content | Consumer |
|
|
424
|
+
|--------|---------|----------|
|
|
425
|
+
| **stdout** | JSON result | AI agent (parsed into context) |
|
|
426
|
+
| **stderr** | `[INFO]`, `[DEBUG]`, `[WARN]`, `[ERROR]` messages | Human / logs |
|
|
427
|
+
|
|
428
|
+
This separation allows AI agents to parse clean JSON from stdout while humans can follow progress on stderr.
|
|
429
|
+
|
|
430
|
+
## Project Structure
|
|
431
|
+
|
|
432
|
+
```
|
|
433
|
+
genspark-tool-cli/
|
|
434
|
+
├── src/
|
|
435
|
+
│ ├── index.ts # CLI entry point, command definitions (Commander.js)
|
|
436
|
+
│ ├── client.ts # ApiClient class, HTTP requests, NDJSON parsing
|
|
437
|
+
│ ├── config.ts # Config file loader (~/.genspark-tool-cli/config.json)
|
|
438
|
+
│ ├── types.ts # TypeScript interfaces for all requests/responses
|
|
439
|
+
│ └── logger.ts # Logger (stdout for results, stderr for debug/info)
|
|
440
|
+
├── dist/ # Compiled JavaScript (built output)
|
|
441
|
+
├── package.json
|
|
442
|
+
└── tsconfig.json
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## Development
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
# Install dependencies
|
|
449
|
+
npm install
|
|
450
|
+
|
|
451
|
+
# Build
|
|
452
|
+
npm run build
|
|
453
|
+
|
|
454
|
+
# Run in development (ts-node)
|
|
455
|
+
npm run dev -- search "test query"
|
|
456
|
+
|
|
457
|
+
# Run built version
|
|
458
|
+
npm start -- search "test query"
|
|
459
|
+
|
|
460
|
+
# Lint
|
|
461
|
+
npm run lint
|
|
462
|
+
|
|
463
|
+
# Clean build output
|
|
464
|
+
npm run clean
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Adding a New Command
|
|
468
|
+
|
|
469
|
+
1. Add request/response types in `src/types.ts`
|
|
470
|
+
2. Add API method in `src/client.ts`
|
|
471
|
+
3. Add command definition in `src/index.ts` (command name MUST match backend tool name)
|
|
472
|
+
4. Rebuild: `npm run build`
|
|
473
|
+
5. Rebuild sandbox image: `npm run build-sandbox` (from GensparkDesktop root)
|
|
474
|
+
6. Update `AGENTS.md.template` with the new command documentation
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client for Genspark Tool CLI
|
|
3
|
+
*/
|
|
4
|
+
import type { GlobalOptions, ApiResponse, ToolListResponse, FileUploadUrlRequest, FileUploadUrlResponse, FileDownloadRequest, FileDownloadResponse } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Make an unauthenticated request to the backend.
|
|
7
|
+
* Used for device-flow auth endpoints that don't require an API key.
|
|
8
|
+
*/
|
|
9
|
+
export declare function unauthenticatedRequest<T>(baseUrl: string, endpoint: string, method?: "GET" | "POST", body?: unknown): Promise<T>;
|
|
10
|
+
export declare class ApiClient {
|
|
11
|
+
private baseUrl;
|
|
12
|
+
private apiKey;
|
|
13
|
+
private timeout;
|
|
14
|
+
private debugMode;
|
|
15
|
+
private projectId?;
|
|
16
|
+
constructor(options: GlobalOptions);
|
|
17
|
+
private request;
|
|
18
|
+
/**
|
|
19
|
+
* List available tools with full schemas
|
|
20
|
+
*/
|
|
21
|
+
listTools(): Promise<ToolListResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Execute any tool by name with arguments
|
|
24
|
+
*/
|
|
25
|
+
executeTool(toolName: string, args: Record<string, unknown>): Promise<ApiResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Get a pre-signed URL for uploading a file
|
|
28
|
+
*/
|
|
29
|
+
getUploadUrl(params: FileUploadUrlRequest): Promise<ApiResponse<FileUploadUrlResponse>>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a downloadable URL for a file wrapper URL
|
|
32
|
+
*/
|
|
33
|
+
getDownloadUrl(params: FileDownloadRequest): Promise<ApiResponse<FileDownloadResponse>>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,KAAK,GAAG,MAAc,EAC9B,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAAC,CAAC,CAAC,CAoBZ;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,OAAO,EAAE,aAAa;YAQpB,OAAO;IA+JrB;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAS5C;;OAEG;IACG,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,WAAW,CAAC;IAIvB;;OAEG;IACG,YAAY,CAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAQ9C;;OAEG;IACG,cAAc,CAClB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;CAG9C"}
|