seacloud-sdk 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seacloud-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "SeaCloud SDK for JavaScript/TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,6 +18,13 @@
18
18
  "files": [
19
19
  "dist"
20
20
  ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "test": "vitest",
25
+ "clean": "rm -rf dist",
26
+ "prepublishOnly": "npm run build"
27
+ },
21
28
  "keywords": [
22
29
  "seacloud",
23
30
  "sdk",
@@ -33,11 +40,5 @@
33
40
  "tsup": "^8.0.1",
34
41
  "typescript": "^5.3.3",
35
42
  "vitest": "^1.0.4"
36
- },
37
- "scripts": {
38
- "build": "tsup",
39
- "dev": "tsup --watch",
40
- "test": "vitest",
41
- "clean": "rm -rf dist"
42
43
  }
43
- }
44
+ }
package/README.md DELETED
@@ -1,327 +0,0 @@
1
- # SeaCloud SDK
2
-
3
- JavaScript/TypeScript SDK for SeaCloud AI Platform
4
-
5
- ## 特性
6
-
7
- ✨ **简单易用**:简洁的 API 设计,快速上手
8
- 🔒 **类型安全**:完整的 TypeScript 类型定义
9
- 🌐 **跨平台**:支持 Node.js 和浏览器环境
10
- ⚡ **现代化**:基于 ESM 模块,支持 tree-shaking
11
- 📦 **零依赖**:核心模块无外部依赖
12
-
13
- ## 安装
14
-
15
- ```bash
16
- npm install seacloud-sdk
17
- ```
18
-
19
- ## 快速开始
20
-
21
- ### 1. 设置环境变量
22
-
23
- ```bash
24
- export API_SERVICE_TOKEN=your-api-token-here
25
- ```
26
-
27
- ### 2. 使用方式一:直接使用 API 函数(推荐)
28
-
29
- ```typescript
30
- import { SeacloudClient, alibabaWanx3Turbo } from 'seacloud-sdk';
31
-
32
- // 创建客户端(API Key 自动从环境变量 API_SERVICE_TOKEN 读取)
33
- const client = new SeacloudClient({
34
- baseUrl: 'http://localhost:8080', // 代理服务器地址
35
- });
36
-
37
- // 调用图片生成 API
38
- const images = await alibabaWanx3Turbo(
39
- client,
40
- { prompt: 'A beautiful sunset over the ocean' },
41
- {
42
- onProgress: (attempt, status) => {
43
- console.log(`轮询第 ${attempt} 次,状态: ${status}`);
44
- },
45
- },
46
- );
47
-
48
- console.log('生成的图片 URL:', images[0].url);
49
- ```
50
-
51
- ### 3. 使用方式二:使用底层 API
52
-
53
- ```typescript
54
- import { SeacloudClient, createAndWaitTask } from 'seacloud-sdk';
55
-
56
- const client = new SeacloudClient();
57
-
58
- const result = await createAndWaitTask(
59
- client,
60
- '/model/tasks',
61
- {
62
- model: 'alibaba_wanx_3_turbo',
63
- input: {
64
- prompt: 'A beautiful sunset over the ocean',
65
- },
66
- },
67
- );
68
-
69
- console.log('任务结果:', result.output);
70
- ```
71
-
72
- ## 目录结构
73
-
74
- ```
75
- seacloud-sdk/
76
- ├── src/
77
- │ ├── core/ # 核心模块
78
- │ │ ├── client.ts # HTTP 客户端
79
- │ │ ├── config.ts # 配置管理
80
- │ │ ├── poller.ts # 任务轮询
81
- │ │ ├── types.ts # 类型定义
82
- │ │ └── index.ts
83
- │ ├── api/ # API 模型(即将添加)
84
- │ │ └── index.ts
85
- │ ├── utils/ # 工具函数
86
- │ │ └── index.ts
87
- │ └── index.ts # 主入口
88
- ├── examples/ # 使用示例
89
- │ ├── basic.ts
90
- │ └── manual-polling.ts
91
- └── dist/ # 构建输出
92
- ```
93
-
94
- 此结构完全参考 Rust 版本的 [seacloud-cli](https://github.com/seaverse/seacloud-cli),便于理解和维护。
95
-
96
- ## 可用的 API 模型
97
-
98
- SDK 包含 **195 个** AI 模型 API,覆盖以下类别:
99
-
100
- ### 图片生成
101
- - **Alibaba Wanx**: `alibabaWanx3Turbo`, `alibabaWanx21`, `alibabaWanxV2Turbo` 等 26 个模型
102
- - **Flux**: `blackforestlabsFlux11Pro`, `blackforestlabsFluxDev`, `blackforestlabsFluxPro` 等 9 个模型
103
- - **Google**: `googleImagen30`, `googleImagen30Fast`
104
- - **Stability AI**: `stabilityaiSd35Large`, `stabilityaiStableImageUltra` 等 5 个模型
105
- - **SeaArt**: `seaartFlux11Pro`, `seaartSdXl`, `seaartWan` 等 10 个模型
106
- - **其他**: `openaiDallE3`, `falRecraftV3`, `falKolors` 等
107
-
108
- ### 视频生成
109
- - **Kling**: `klingV1`, `klingV15`, `klingV16`, `klingV21Master`, `klingV25Turbo`, `klingV26` 等 25 个模型
110
- - **Vidu**: `vidu15`, `vidu20I2v`, `viduQ1`, `viduQ2`, `viduQ2Pro` 等 18 个模型
111
- - **Minimax**: `minimaxHailuo02`, `minimaxHailuo23I2v`, `minimaxT2v01` 等 7 个模型
112
- - **Pixverse**: `pixverseV2`, `pixverseV25`, `pixverseV3` 等 7 个模型
113
- - **Youchuan**: `youchuanDiffusion`, `youchuanVideoDiffusion`, `youchuanExtendVideo` 等 15 个模型
114
- - **Volces**: `volcesSeedance30`, `volcesSeedancePro` 等 21 个模型
115
- - **其他**: `runwayGen3aTurboI2v`, `googleVeo2`
116
-
117
- ### 音频生成
118
- - **Minimax**: `minimaxT2a`
119
- - **Mureka**: `murekaSongGenerator`, `murekaInstrumentalGenerator`, `murekaLyricsGenerator` 等 5 个模型
120
- - **ElevenLabs**: `elevenlabsTtsGenerator`
121
-
122
- ### 3D 模型
123
- - **Tencent Hunyuan**: `tencentHunyuan3d`, `tencentHunyuan3dPro`, `tencentHunyuan3dRapid`
124
- - **Tripo3D**: `tripo3dTextToModel`, `tripo3dImageToModel` 等 4 个模型
125
- - **Volces**: `volcesSeed3d`
126
-
127
- ### LLM 对话模型
128
- - **Google Gemini**: `googleGemini20FlashExp`, `googleGemini15Pro`, `googleGemini10Pro` 等 8 个模型
129
- - **Claude**: `googleClaude35Haiku`, `googleClaude35SonnetV2`
130
- - **Microsoft Phi**: `microsoftPhi4`, `microsoftPhi35MiniInstruct`, `microsoftPhi35MoeInstruct`
131
- - **SeaArt**: `seaartQwen2Vl72bInstruct`, `seaartKontext`
132
-
133
- ### 图片编辑
134
- - **Alibaba Wanx**: 背景生成、人像修复、图片上色、高清增强、智能抠图等 10+ 个功能
135
- - **SeaArt**: `seaartImageEdit`, `seaartSeededit20`
136
- - **Volces**: `volcesSeededit30`, `volcesSeededitPortrait` 等 9 个模型
137
- - **Youchuan**: 修图、扩图、去背景、变体等 8 个功能
138
-
139
- 完整的模型列表请查看 `src/api/index.ts`。
140
-
141
- ### 使用示例
142
-
143
- ```typescript
144
- import {
145
- SeacloudClient,
146
- alibabaWanx3Turbo, // 图片生成
147
- klingV26, // 视频生成
148
- googleGemini20FlashExp, // LLM 对话
149
- minimaxT2a, // 音频生成
150
- tencentHunyuan3d, // 3D 模型
151
- } from 'seacloud-sdk';
152
-
153
- const client = new SeacloudClient();
154
-
155
- // 生成图片
156
- const images = await alibabaWanx3Turbo(client, {
157
- prompt: 'A cat'
158
- });
159
-
160
- // 生成视频
161
- const videos = await klingV26(client, {
162
- prompt: 'A cat running'
163
- });
164
-
165
- // LLM 对话
166
- const response = await googleGemini20FlashExp(client, {
167
- prompt: 'Hello, how are you?'
168
- });
169
- ```
170
-
171
- ## API 文档
172
-
173
- ### SeacloudClient
174
-
175
- HTTP 客户端,用于与 SeaCloud 代理服务器通信。
176
-
177
- #### 构造函数
178
-
179
- ```typescript
180
- new SeacloudClient(config?: SeacloudConfig)
181
- ```
182
-
183
- **配置选项:**
184
- - `apiKey?: string` - API Token(默认从环境变量 `API_SERVICE_TOKEN` 读取)
185
- - `baseUrl?: string` - 代理服务器地址(默认 `http://localhost:8080`)
186
- - `fetch?: typeof fetch` - 自定义 fetch 实现(可选)
187
- - `timeout?: number` - 请求超时时间(毫秒,默认 30000)
188
-
189
- #### 方法
190
-
191
- **createTask(endpoint, body)**
192
-
193
- 创建新任务。
194
-
195
- ```typescript
196
- const task = await client.createTask('/model/tasks', {
197
- model: 'alibaba_wanx_3_turbo',
198
- input: { prompt: 'A sunset' },
199
- });
200
- ```
201
-
202
- **getTaskStatus(endpoint, taskId)**
203
-
204
- 查询任务状态。
205
-
206
- ```typescript
207
- const status = await client.getTaskStatus('/model/tasks', taskId);
208
- ```
209
-
210
- ### 轮询函数
211
-
212
- **pollTaskUntilComplete(client, endpoint, taskId, options?)**
213
-
214
- 轮询任务直到完成或失败。
215
-
216
- ```typescript
217
- const result = await pollTaskUntilComplete(
218
- client,
219
- '/model/tasks',
220
- taskId,
221
- {
222
- intervalMs: 3000, // 轮询间隔(毫秒)
223
- maxAttempts: 120, // 最大尝试次数
224
- onProgress: (attempt, status) => {
225
- console.log(`尝试 ${attempt}: ${status}`);
226
- },
227
- },
228
- );
229
- ```
230
-
231
- **createAndWaitTask(client, endpoint, body, options?)**
232
-
233
- 创建任务并自动轮询直到完成。
234
-
235
- ```typescript
236
- const result = await createAndWaitTask(
237
- client,
238
- '/model/tasks',
239
- { model: 'alibaba_wanx_3_turbo', input: { prompt: 'A sunset' } },
240
- { intervalMs: 2000 },
241
- );
242
- ```
243
-
244
- ## 类型定义
245
-
246
- ### TaskResult
247
-
248
- ```typescript
249
- interface TaskResult {
250
- id: string;
251
- created_at: number;
252
- status: 'pending' | 'processing' | 'in_progress' | 'completed' | 'failed';
253
- error?: TaskError | null;
254
- model: string;
255
- output?: Array<{
256
- content?: Array<{
257
- type?: string;
258
- url?: string;
259
- size?: number;
260
- jobId?: string;
261
- }>;
262
- }>;
263
- }
264
- ```
265
-
266
- ### SeacloudError
267
-
268
- 自定义错误类,包含状态码和响应信息。
269
-
270
- ```typescript
271
- class SeacloudError extends Error {
272
- statusCode?: number;
273
- response?: any;
274
- }
275
- ```
276
-
277
- ## 使用示例
278
-
279
- 查看 `examples/` 目录获取更多使用示例:
280
-
281
- - **basic.ts** - 基本使用示例,演示 `createAndWaitTask`
282
- - **manual-polling.ts** - 手动轮询示例,演示任务创建和状态查询
283
-
284
- 运行示例:
285
-
286
- ```bash
287
- # 设置环境变量
288
- export API_SERVICE_TOKEN=your-token
289
-
290
- # 运行示例(需要先启动代理服务器)
291
- node examples/basic.js
292
- ```
293
-
294
- ## 开发
295
-
296
- ```bash
297
- # 安装依赖
298
- npm install
299
-
300
- # 构建
301
- npm run build
302
-
303
- # 开发模式(监听文件变化)
304
- npm run dev
305
-
306
- # 清理构建
307
- npm run clean
308
- ```
309
-
310
- ## 路线图
311
-
312
- - [x] 核心 HTTP 客户端
313
- - [x] 任务轮询机制
314
- - [x] TypeScript 类型定义
315
- - [x] API 模型转换(195 个模型)✅
316
- - [ ] 浏览器环境测试
317
- - [ ] 单元测试
318
- - [ ] API 文档生成
319
-
320
- ## 相关项目
321
-
322
- - [seacloud-cli](https://github.com/seaverse/seacloud-cli) - Rust 版本的命令行工具
323
- - [seacloud-proxy](https://github.com/seaverse/seacloud-proxy) - Go 代理服务器
324
-
325
- ## License
326
-
327
- MIT