seacloud-sdk 0.11.0 → 0.11.2

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 ADDED
@@ -0,0 +1,168 @@
1
+ # SeaCloud SDK
2
+
3
+ Official SeaCloud SDK for JavaScript/TypeScript - Call SeaCloud AI services with ease.
4
+
5
+ ## Features
6
+
7
+ - 🤖 **Agent Chat API** - Multi-turn conversations, tool calling, streaming output
8
+ - 🎨 **Image Generation** - Support for multiple AI image generation models
9
+ - 🎬 **Video Generation** - Text-to-Video, Image-to-Video
10
+ - 🎵 **Music Generation** - Song and lyrics generation
11
+ - 🔄 **Streaming Response** - Real-time AI responses
12
+ - 📦 **TypeScript Support** - Complete type definitions
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pnpm install seacloud-sdk
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ### Initialize SDK
23
+
24
+ ```typescript
25
+ import { initSeacloud, agentChatCompletions, createTextMessage } from 'seacloud-sdk';
26
+
27
+ // Initialize SDK
28
+ initSeacloud({
29
+ apiKey: 'your-api-key',
30
+ baseUrl: 'https://proxy-rs.seaverse.ai',
31
+ xProject: 'SeaArt', // Optional, defaults to 'SeaVerse'
32
+ });
33
+ ```
34
+
35
+ ### Simple Chat
36
+
37
+ ```typescript
38
+ const response = await agentChatCompletions({
39
+ agent_id: 'seagen_agent',
40
+ messages: [
41
+ createTextMessage('user', 'Hello! How are you?')
42
+ ],
43
+ model: 'gpt-4o',
44
+ });
45
+
46
+ console.log(response.choices[0].message.content);
47
+ ```
48
+
49
+ ### Streaming Chat
50
+
51
+ ```typescript
52
+ const stream = await agentChatCompletions({
53
+ agent_id: 'seagen_agent',
54
+ messages: [
55
+ createTextMessage('user', 'Tell me a story')
56
+ ],
57
+ model: 'gpt-4o',
58
+ stream: true,
59
+ });
60
+
61
+ for await (const chunk of stream) {
62
+ const content = chunk.choices[0]?.delta?.content;
63
+ if (content) {
64
+ process.stdout.write(content);
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## Configuration Options
70
+
71
+ ### initSeacloud(options)
72
+
73
+ | Parameter | Type | Default | Description |
74
+ |-----------|------|---------|-------------|
75
+ | `apiKey` | `string` | - | API key, can also be set via `API_SERVICE_TOKEN` environment variable |
76
+ | `baseUrl` | `string` | `https://proxy-rs.seaverse.ai` | API server URL |
77
+ | `timeout` | `number` | `30000` | Request timeout in milliseconds |
78
+ | `intervalMs` | `number` | `3000` | Polling interval in milliseconds |
79
+ | `maxAttempts` | `number` | `100` | Maximum polling attempts |
80
+ | `xProject` | `string` | `'SeaVerse'` | X-Project header value for project identification |
81
+
82
+ ### xProject Parameter
83
+
84
+ The `xProject` parameter sets the `X-Project` request header to identify the source project. Different projects may have different quotas and permissions:
85
+
86
+ ```typescript
87
+ // SeaArt project
88
+ initSeacloud({
89
+ apiKey: 'your-api-key',
90
+ xProject: 'SeaArt',
91
+ });
92
+
93
+ // KIIRA project
94
+ initSeacloud({
95
+ apiKey: 'your-api-key',
96
+ xProject: 'KIIRA',
97
+ });
98
+
99
+ // Default: SeaVerse
100
+ initSeacloud({
101
+ apiKey: 'your-api-key',
102
+ // xProject defaults to 'SeaVerse'
103
+ });
104
+ ```
105
+
106
+ ## Token Priority
107
+
108
+ The SDK retrieves API tokens in the following priority order:
109
+
110
+ 1. `apiKey` passed to `initSeacloud({ apiKey: '...' })`
111
+ 2. Browser environment: `localStorage.getItem('auth_token')`
112
+ 3. Node.js environment: `process.env.API_SERVICE_TOKEN`
113
+
114
+ ## Environment Variables
115
+
116
+ | Variable | Description |
117
+ |----------|-------------|
118
+ | `API_SERVICE_TOKEN` | API key |
119
+ | `SEACLOUD_BASE_URL` | API server URL |
120
+
121
+ ## API Reference
122
+
123
+ ### Agent Chat API
124
+
125
+ ```typescript
126
+ import { agentChatCompletions, createTextMessage, createImageMessage, createTool } from 'seacloud-sdk';
127
+
128
+ // Text message
129
+ const textMessage = createTextMessage('user', 'Hello!');
130
+
131
+ // Image message
132
+ const imageMessage = createImageMessage('user', 'What is this?', 'https://example.com/image.jpg');
133
+
134
+ // Create tool
135
+ const tool = createTool('seagen_text2image_flux1d_artifact_tool');
136
+ ```
137
+
138
+ ### Available Tools
139
+
140
+ **Image Generation:**
141
+ - `seagen_text2image_flux1d_artifact_tool`
142
+ - `seagen_text2image_seedream40_artifact_tool`
143
+ - `seagen_text2image_google_gemini3_pro_image_artifact_tool`
144
+ - `seagen_blackforestlabs_flux_2_pro_tool`
145
+ - `mm_volces_seedream_4_5_gateway_tool`
146
+
147
+ **Image Editing:**
148
+ - `seagen_edit_image_google_artifact_tool`
149
+ - `seagen_blackforestlabs_flux_2_pro_edit_tool`
150
+
151
+ **Video Generation:**
152
+ - `seagen_image2video_wanx26_artifact_tool`
153
+ - `seagen_text2video_wanx26_artifact_tool`
154
+ - `seagen_image2video_seedance_pro_fast_artifact_tool`
155
+ - `mm_text2video_kling_v2_6_gateway_tool`
156
+ - `mm_image2video_kling_v2_6_i2v_gateway_tool`
157
+
158
+ **Music Generation:**
159
+ - `seagen_text2song_mureka_artifact_tool`
160
+ - `seagen_text2lyrics_mureka_artifact_tool`
161
+
162
+ ## Examples
163
+
164
+ For more examples, see [examples_agent.ts](./examples_agent.ts)
165
+
166
+ ## License
167
+
168
+ MIT
package/dist/cli.js CHANGED
@@ -93,7 +93,8 @@ function createConfig(options = {}) {
93
93
  // 提供默认空字符串,实际请求时会动态获取
94
94
  baseUrl,
95
95
  fetch: fetchImpl,
96
- timeout: options.timeout || 3e4
96
+ timeout: options.timeout || 3e4,
97
+ xProject: options.xProject || "SeaVerse"
97
98
  };
98
99
  }
99
100
  function validateConfig(config) {
@@ -253,7 +254,8 @@ function initSeacloud(apiKeyOrConfig, options) {
253
254
  globalConfig.client = new SeacloudClient({
254
255
  apiKey: apiKey || "",
255
256
  baseUrl: config.baseUrl,
256
- timeout: config.timeout
257
+ timeout: config.timeout,
258
+ xProject: config.xProject
257
259
  });
258
260
  if (config.intervalMs !== void 0) {
259
261
  globalConfig.defaultPollingOptions.intervalMs = config.intervalMs;
@@ -373,14 +375,16 @@ async function agentChatCompletions(params) {
373
375
  const controller = new AbortController();
374
376
  const timeoutId = setTimeout(() => controller.abort(), config.timeout);
375
377
  try {
378
+ const headers = {
379
+ "Content-Type": "application/json",
380
+ "Authorization": `Bearer ${config.apiKey}`
381
+ };
382
+ if (config.xProject) {
383
+ headers["X-Project"] = config.xProject;
384
+ }
376
385
  const response = await config.fetch(url, {
377
386
  method: "POST",
378
- headers: {
379
- "Content-Type": "application/json",
380
- "Authorization": `Bearer ${config.apiKey}`,
381
- "X-Project": "SeaArt"
382
- // Required header for agent API
383
- },
387
+ headers,
384
388
  body: JSON.stringify(requestBody),
385
389
  signal: controller.signal
386
390
  });
@@ -565,14 +569,17 @@ async function appSearch(params) {
565
569
  const timeoutId = setTimeout(() => controller.abort(), config.timeout);
566
570
  try {
567
571
  const requestId = `req-${Date.now()}-${Math.random().toString(36).substring(7)}`;
572
+ const headers = {
573
+ "Content-Type": "application/json",
574
+ "Authorization": `Bearer ${config.apiKey}`,
575
+ "X-Request-Id": requestId
576
+ };
577
+ if (config.xProject) {
578
+ headers["X-Project"] = config.xProject;
579
+ }
568
580
  const response = await config.fetch(url, {
569
581
  method: "POST",
570
- headers: {
571
- "Content-Type": "application/json",
572
- "Authorization": `Bearer ${config.apiKey}`,
573
- "X-Request-Id": requestId,
574
- "X-Project": "KIIRA"
575
- },
582
+ headers,
576
583
  body: JSON.stringify(params),
577
584
  signal: controller.signal
578
585
  });