@seaverse/conversation-sdk 0.2.0 → 0.2.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 (2) hide show
  1. package/README.md +72 -72
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # @seaverse/conversation-sdk
2
2
 
3
- SeaVerse Conversation SDK - 用于对话(Conversations)和消息(Messages)管理的函数式 SDK
3
+ SeaVerse Conversation SDK - A functional SDK for managing conversations and messages.
4
4
 
5
- ## 安装
5
+ ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @seaverse/conversation-sdk
9
- #
9
+ # or
10
10
  pnpm add @seaverse/conversation-sdk
11
11
  ```
12
12
 
13
- ## 快速开始
13
+ ## Quick Start
14
14
 
15
- ### 初始化 SDK
15
+ ### Initialize SDK
16
16
 
17
17
  ```typescript
18
18
  import { initConversationSdk } from '@seaverse/conversation-sdk';
@@ -23,19 +23,19 @@ const sdk = initConversationSdk({
23
23
  });
24
24
  ```
25
25
 
26
- ### 获取 Apps 及其会话列表
26
+ ### Get Apps with Conversations
27
27
 
28
28
  ```typescript
29
- // 获取所有 apps,每个 app 返回消息数最多的一个会话
29
+ // Get all apps, each app returns the conversation with the most messages
30
30
  const result = await sdk.getAppsWithConversationsList({
31
31
  page: 1,
32
32
  pageSize: 20
33
33
  });
34
34
 
35
35
  console.log(result.apps); // AppWithConversations[]
36
- console.log(result.hasMore); // boolean - 是否有下一页
36
+ console.log(result.hasMore); // boolean - whether there's a next page
37
37
 
38
- // 获取指定 app
38
+ // Get a specific app
39
39
  const appResult = await sdk.getAppsWithConversationsList({
40
40
  appId: 'app-123',
41
41
  page: 1,
@@ -43,106 +43,106 @@ const appResult = await sdk.getAppsWithConversationsList({
43
43
  });
44
44
  ```
45
45
 
46
- ### 获取消息列表
46
+ ### Get Messages List
47
47
 
48
48
  ```typescript
49
- // 获取指定会话的消息列表(倒序,最新的在前)
49
+ // Get message list for a conversation (descending order, newest first)
50
50
  const result = await sdk.getMessagesList('conversation-id', {
51
51
  page: 1,
52
52
  pageSize: 50
53
53
  });
54
54
 
55
55
  console.log(result.messages); // Message[]
56
- console.log(result.hasMore); // boolean - 是否有下一页
56
+ console.log(result.hasMore); // boolean - whether there's a next page
57
57
  ```
58
58
 
59
- ## API 参考
59
+ ## API Reference
60
60
 
61
61
  ### initConversationSdk(config)
62
62
 
63
- 初始化 Conversation SDK 并返回函数式 API
63
+ Initialize the Conversation SDK and return functional API.
64
64
 
65
- **参数**:
65
+ **Parameters**:
66
66
  ```typescript
67
67
  {
68
- environment: 'dev' | 'prod'; // 环境配置
69
- token: string; // 访问令牌
70
- getToken?: () => Promise<string>; // 动态获取令牌(可选)
71
- fetch?: typeof fetch; // 自定义 fetch 实现(可选)
72
- timeout?: number; // 请求超时时间,默认 30000ms(可选)
68
+ environment: 'dev' | 'prod'; // Environment configuration
69
+ token: string; // Access token
70
+ getToken?: () => Promise<string>; // Dynamic token getter (optional)
71
+ fetch?: typeof fetch; // Custom fetch implementation (optional)
72
+ timeout?: number; // Request timeout, default 30000ms (optional)
73
73
  }
74
74
  ```
75
75
 
76
- **返回**: 包含以下方法的对象
76
+ **Returns**: Object containing the following methods
77
77
 
78
78
  ### getAppsWithConversationsList(options?)
79
79
 
80
- 获取 Apps 列表,每个 app 只返回消息数最多的那一个会话。
80
+ Get list of apps, each app returns only the conversation with the most messages.
81
81
 
82
- **参数**:
82
+ **Parameters**:
83
83
  ```typescript
84
84
  {
85
- appId?: string; // 可选,按应用 ID 过滤
86
- page?: number; // 页码,默认 1
87
- pageSize?: number; // 每页数量,默认 20
85
+ appId?: string; // Optional, filter by app ID
86
+ page?: number; // Page number, default 1
87
+ pageSize?: number; // Items per page, default 20
88
88
  }
89
89
  ```
90
90
 
91
- **返回**:
91
+ **Returns**:
92
92
  ```typescript
93
93
  Promise<{
94
94
  apps: AppWithConversations[];
95
- hasMore: boolean; // 是否有下一页
95
+ hasMore: boolean; // Whether there's a next page
96
96
  }>
97
97
  ```
98
98
 
99
99
  ### getMessagesList(conversationId, options?)
100
100
 
101
- 获取指定会话的消息列表(按时间倒序,最新消息在前)。
101
+ Get message list for a conversation (descending order by time, newest first).
102
102
 
103
- **参数**:
104
- - `conversationId`: `string` - 会话 ID(必需)
105
- - `options?`: 可选查询选项
103
+ **Parameters**:
104
+ - `conversationId`: `string` - Conversation ID (required)
105
+ - `options?`: Optional query options
106
106
  ```typescript
107
107
  {
108
- page?: number; // 页码,默认 1
109
- pageSize?: number; // 每页数量,默认 100
108
+ page?: number; // Page number, default 1
109
+ pageSize?: number; // Items per page, default 100
110
110
  }
111
111
  ```
112
112
 
113
- **返回**:
113
+ **Returns**:
114
114
  ```typescript
115
115
  Promise<{
116
116
  messages: Message[];
117
- hasMore: boolean; // 是否有下一页
117
+ hasMore: boolean; // Whether there's a next page
118
118
  }>
119
119
  ```
120
120
 
121
- ## 类型定义
121
+ ## Type Definitions
122
122
 
123
123
  ### Message
124
124
 
125
125
  ```typescript
126
126
  interface Message {
127
127
  id: string;
128
- role?: 'user' | 'assistant' | 'system'; // tips 消息无 role
129
- content?: string; // tips 消息不返回此字段
130
- timestamp: number; // 秒级时间戳
128
+ role?: 'user' | 'assistant' | 'system'; // tips messages don't have role
129
+ content?: string; // tips messages don't return this field
130
+ timestamp: number; // Unix timestamp in seconds
131
131
  type?: 'text' | 'conversation_tips' | string;
132
- tips?: string[]; // conversation_tips 类型专有
133
- toolCalls?: ToolCall[]; // 工具调用信息
132
+ tips?: string[]; // Specific to conversation_tips type
133
+ toolCalls?: ToolCall[]; // Tool call information
134
134
  }
135
135
  ```
136
136
 
137
- **Tips 消息格式**:
137
+ **Tips Message Format**:
138
138
  ```typescript
139
139
  {
140
140
  id: string;
141
- conversation_id: string; // tips 消息有此字段
141
+ conversation_id: string; // Only tips messages have this field
142
142
  timestamp: number;
143
143
  type: "conversation_tips";
144
144
  tips: string[];
145
- // 注意: tips 消息没有 content role 字段
145
+ // Note: tips messages don't have content and role fields
146
146
  }
147
147
  ```
148
148
 
@@ -165,10 +165,10 @@ interface Conversation {
165
165
  title: string;
166
166
  appId: string | null;
167
167
  userId: string;
168
- createdAt: number; // 毫秒时间戳
169
- updatedAt: number; // 毫秒时间戳
170
- lastActiveAt: number; // 毫秒时间戳
171
- messageCount?: number; // 消息计数
168
+ createdAt: number; // Unix timestamp in milliseconds
169
+ updatedAt: number; // Unix timestamp in milliseconds
170
+ lastActiveAt: number; // Unix timestamp in milliseconds
171
+ messageCount?: number; // Message count
172
172
  }
173
173
  ```
174
174
 
@@ -177,7 +177,7 @@ interface Conversation {
177
177
  ```typescript
178
178
  interface AppWithConversations {
179
179
  app: App;
180
- conversations: Conversation[]; // 只有一个元素(消息数最多的会话)
180
+ conversations: Conversation[]; // Only one element (conversation with most messages)
181
181
  }
182
182
  ```
183
183
 
@@ -197,14 +197,14 @@ interface App {
197
197
  positiveCount: number;
198
198
  forkCount: number;
199
199
  commentCount: number;
200
- createdAt: number; // 毫秒时间戳
201
- updatedAt: number; // 毫秒时间戳
200
+ createdAt: number; // Unix timestamp in milliseconds
201
+ updatedAt: number; // Unix timestamp in milliseconds
202
202
  }
203
203
  ```
204
204
 
205
- ## 错误处理
205
+ ## Error Handling
206
206
 
207
- SDK 提供了几种错误类型:
207
+ The SDK provides several error types:
208
208
 
209
209
  ```typescript
210
210
  import {
@@ -219,38 +219,38 @@ try {
219
219
  const result = await sdk.getAppsWithConversationsList();
220
220
  } catch (error) {
221
221
  if (error instanceof AuthError) {
222
- console.error('认证失败:', error.message);
222
+ console.error('Authentication failed:', error.message);
223
223
  } else if (error instanceof NetworkError) {
224
- console.error('网络错误:', error.message);
224
+ console.error('Network error:', error.message);
225
225
  } else if (error instanceof TimeoutError) {
226
- console.error('请求超时:', error.message);
226
+ console.error('Request timeout:', error.message);
227
227
  } else {
228
- console.error('未知错误:', error);
228
+ console.error('Unknown error:', error);
229
229
  }
230
230
  }
231
231
  ```
232
232
 
233
- ## 完整示例
233
+ ## Complete Example
234
234
 
235
235
  ```typescript
236
236
  import { initConversationSdk } from '@seaverse/conversation-sdk';
237
237
 
238
- // 初始化 SDK
238
+ // Initialize SDK
239
239
  const sdk = initConversationSdk({
240
240
  environment: 'prod',
241
241
  token: 'your-access-token'
242
242
  });
243
243
 
244
- // 1. 获取所有 apps 及其热门会话
244
+ // 1. Get all apps with their top conversations
245
245
  const appsResult = await sdk.getAppsWithConversationsList({
246
246
  page: 1,
247
247
  pageSize: 20
248
248
  });
249
249
 
250
250
  console.log('Apps:', appsResult.apps);
251
- console.log('有下一页:', appsResult.hasMore);
251
+ console.log('Has more:', appsResult.hasMore);
252
252
 
253
- // 2. 获取某个会话的消息
253
+ // 2. Get messages for a conversation
254
254
  const conversationId = appsResult.apps[0]?.conversations[0]?.id;
255
255
  if (conversationId) {
256
256
  const messagesResult = await sdk.getMessagesList(conversationId, {
@@ -258,27 +258,27 @@ if (conversationId) {
258
258
  pageSize: 50
259
259
  });
260
260
 
261
- console.log('消息列表:', messagesResult.messages);
262
- console.log('有更多消息:', messagesResult.hasMore);
261
+ console.log('Messages:', messagesResult.messages);
262
+ console.log('Has more messages:', messagesResult.hasMore);
263
263
 
264
- // 处理不同类型的消息
264
+ // Handle different message types
265
265
  messagesResult.messages.forEach(msg => {
266
266
  if (msg.type === 'conversation_tips') {
267
267
  console.log('Tips:', msg.tips);
268
268
  } else {
269
- console.log('消息:', msg.content);
269
+ console.log('Message:', msg.content);
270
270
  }
271
271
  });
272
272
  }
273
273
  ```
274
274
 
275
- ## 环境配置
275
+ ## Environment Configuration
276
276
 
277
- SDK 会根据 `environment` 参数自动选择对应的服务端点:
277
+ The SDK automatically selects the corresponding service endpoint based on the `environment` parameter:
278
278
 
279
- - `'dev'`: 开发环境
280
- - `'prod'`: 生产环境
279
+ - `'dev'`: Development environment
280
+ - `'prod'`: Production environment
281
281
 
282
- ## 许可证
282
+ ## License
283
283
 
284
284
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seaverse/conversation-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "SeaVerse Conversation SDK - SDK for conversations and messages management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",