@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.
- package/README.md +72 -72
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# @seaverse/conversation-sdk
|
|
2
2
|
|
|
3
|
-
SeaVerse Conversation 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
|
-
###
|
|
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
|
-
###
|
|
26
|
+
### Get Apps with Conversations
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
|
-
//
|
|
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
|
-
//
|
|
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
|
-
|
|
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; //
|
|
72
|
-
timeout?: number; //
|
|
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
|
-
|
|
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; //
|
|
86
|
-
page?: number; //
|
|
87
|
-
pageSize?: number; //
|
|
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` -
|
|
105
|
-
- `options?`:
|
|
103
|
+
**Parameters**:
|
|
104
|
+
- `conversationId`: `string` - Conversation ID (required)
|
|
105
|
+
- `options?`: Optional query options
|
|
106
106
|
```typescript
|
|
107
107
|
{
|
|
108
|
-
page?: number; //
|
|
109
|
-
pageSize?: number; //
|
|
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
|
|
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; //
|
|
141
|
+
conversation_id: string; // Only tips messages have this field
|
|
142
142
|
timestamp: number;
|
|
143
143
|
type: "conversation_tips";
|
|
144
144
|
tips: string[];
|
|
145
|
-
//
|
|
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('
|
|
222
|
+
console.error('Authentication failed:', error.message);
|
|
223
223
|
} else if (error instanceof NetworkError) {
|
|
224
|
-
console.error('
|
|
224
|
+
console.error('Network error:', error.message);
|
|
225
225
|
} else if (error instanceof TimeoutError) {
|
|
226
|
-
console.error('
|
|
226
|
+
console.error('Request timeout:', error.message);
|
|
227
227
|
} else {
|
|
228
|
-
console.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
|
-
//
|
|
238
|
+
// Initialize SDK
|
|
239
239
|
const sdk = initConversationSdk({
|
|
240
240
|
environment: 'prod',
|
|
241
241
|
token: 'your-access-token'
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
-
// 1.
|
|
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('
|
|
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('
|
|
262
|
-
console.log('
|
|
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('
|
|
269
|
+
console.log('Message:', msg.content);
|
|
270
270
|
}
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
-
##
|
|
275
|
+
## Environment Configuration
|
|
276
276
|
|
|
277
|
-
SDK
|
|
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
|