qing-client 0.0.11 → 0.0.12
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/lib/srvice/AiService.d.ts +73 -0
- package/lib/srvice/AiService.js +256 -0
- package/lib/types/ai.d.ts +238 -0
- package/lib/types/ai.js +3 -0
- package/package.json +1 -1
- package/src/srvice/AiService.ts +336 -0
- package/src/types/ai.ts +275 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BaseClient } from "../client/BaseClient";
|
|
2
|
+
import { ClientConfig, RequestOptions } from "../types";
|
|
3
|
+
import { ChatCompletionRequest, ChatCompletionResponse, ProviderListItem, ProviderDetail, ModelListItem, ModelDetail, CreateSessionRequest, SessionResponse, SessionListResponse, CreateAssistantRequest, AssistantResponse, AssistantListResponse, UpdateAssistantRequest, AddMessageRequest, BatchDeleteSessionsResponse, SessionStatistics, AssistantModelsResponse, PaginatedSessionMessageResponse } from "../types/ai";
|
|
4
|
+
export declare class AiService extends BaseClient {
|
|
5
|
+
constructor(config: ClientConfig);
|
|
6
|
+
chatCompletion(request: ChatCompletionRequest, options?: RequestOptions): Promise<ChatCompletionResponse>;
|
|
7
|
+
getChatModels(options?: RequestOptions): Promise<{
|
|
8
|
+
models: ModelListItem[];
|
|
9
|
+
}>;
|
|
10
|
+
createSession(request: CreateSessionRequest, options?: RequestOptions): Promise<SessionResponse>;
|
|
11
|
+
getSessions(params?: {
|
|
12
|
+
page?: number;
|
|
13
|
+
limit?: number;
|
|
14
|
+
status?: 'active' | 'ended';
|
|
15
|
+
}, options?: RequestOptions): Promise<SessionListResponse>;
|
|
16
|
+
getSession(sessionId: string, options?: RequestOptions): Promise<SessionResponse>;
|
|
17
|
+
updateSession(sessionId: string, request: any, options?: RequestOptions): Promise<SessionResponse>;
|
|
18
|
+
endSession(sessionId: string, options?: RequestOptions): Promise<SessionResponse>;
|
|
19
|
+
deleteSession(sessionId: string, options?: RequestOptions): Promise<void>;
|
|
20
|
+
getSessionModel(sessionId: string, options?: RequestOptions): Promise<{
|
|
21
|
+
currentModel: string;
|
|
22
|
+
availableModels: string[];
|
|
23
|
+
providerName: string;
|
|
24
|
+
}>;
|
|
25
|
+
getActiveSessions(options?: RequestOptions): Promise<{
|
|
26
|
+
sessions: SessionResponse[];
|
|
27
|
+
}>;
|
|
28
|
+
createAssistant(request: CreateAssistantRequest, options?: RequestOptions): Promise<AssistantResponse>;
|
|
29
|
+
getAssistants(params?: {
|
|
30
|
+
page?: number;
|
|
31
|
+
limit?: number;
|
|
32
|
+
}, options?: RequestOptions): Promise<AssistantListResponse>;
|
|
33
|
+
getAssistant(assistantId: string, options?: RequestOptions): Promise<AssistantResponse>;
|
|
34
|
+
updateAssistant(assistantId: string, request: UpdateAssistantRequest, options?: RequestOptions): Promise<AssistantResponse>;
|
|
35
|
+
deleteAssistant(assistantId: string, options?: RequestOptions): Promise<void>;
|
|
36
|
+
getAccessibleAssistants(options?: RequestOptions): Promise<{
|
|
37
|
+
assistants: AssistantResponse[];
|
|
38
|
+
}>;
|
|
39
|
+
getPopularAssistants(limit?: number, options?: RequestOptions): Promise<{
|
|
40
|
+
assistants: AssistantResponse[];
|
|
41
|
+
}>;
|
|
42
|
+
incrementAssistantUsage(assistantId: string, options?: RequestOptions): Promise<AssistantResponse>;
|
|
43
|
+
duplicateAssistant(assistantId: string, newName: string, options?: RequestOptions): Promise<AssistantResponse>;
|
|
44
|
+
getProviders(options?: RequestOptions): Promise<{
|
|
45
|
+
providers: ProviderListItem[];
|
|
46
|
+
}>;
|
|
47
|
+
getProvider(providerKey: string, options?: RequestOptions): Promise<ProviderDetail>;
|
|
48
|
+
getAccessibleProviders(options?: RequestOptions): Promise<{
|
|
49
|
+
providers: ProviderListItem[];
|
|
50
|
+
}>;
|
|
51
|
+
getModels(params?: {
|
|
52
|
+
provider?: string;
|
|
53
|
+
capability?: string;
|
|
54
|
+
}, options?: RequestOptions): Promise<{
|
|
55
|
+
models: ModelListItem[];
|
|
56
|
+
}>;
|
|
57
|
+
getModel(modelId: string, options?: RequestOptions): Promise<ModelDetail>;
|
|
58
|
+
getModelsByProvider(providerKey: string, options?: RequestOptions): Promise<{
|
|
59
|
+
models: ModelListItem[];
|
|
60
|
+
}>;
|
|
61
|
+
getAccessibleModels(options?: RequestOptions): Promise<{
|
|
62
|
+
models: ModelListItem[];
|
|
63
|
+
}>;
|
|
64
|
+
getSessionMessages(sessionId: string, params?: {
|
|
65
|
+
page?: number;
|
|
66
|
+
limit?: number;
|
|
67
|
+
}, options?: RequestOptions): Promise<PaginatedSessionMessageResponse>;
|
|
68
|
+
addMessageToSession(sessionId: string, request: AddMessageRequest, options?: RequestOptions): Promise<SessionResponse>;
|
|
69
|
+
deleteSessionsBatch(sessionIds: string[], options?: RequestOptions): Promise<BatchDeleteSessionsResponse>;
|
|
70
|
+
switchSessionModel(sessionId: string, modelName: string, options?: RequestOptions): Promise<SessionResponse>;
|
|
71
|
+
getSessionStatistics(timeRange?: 'today' | 'week' | 'month' | 'year', options?: RequestOptions): Promise<SessionStatistics>;
|
|
72
|
+
getAssistantModels(assistantId: string, options?: RequestOptions): Promise<AssistantModelsResponse>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AiService = void 0;
|
|
4
|
+
// src/srvice/AiService.ts
|
|
5
|
+
const BaseClient_1 = require("../client/BaseClient");
|
|
6
|
+
class AiService extends BaseClient_1.BaseClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config, 'ai');
|
|
9
|
+
}
|
|
10
|
+
// ==================== Chat对话接口 ====================
|
|
11
|
+
// 聊天补全(非流式)
|
|
12
|
+
async chatCompletion(request, options) {
|
|
13
|
+
return this.request('/chat/completion', {
|
|
14
|
+
...options,
|
|
15
|
+
method: 'POST',
|
|
16
|
+
body: request
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
// 获取聊天可用模型
|
|
20
|
+
async getChatModels(options) {
|
|
21
|
+
return this.request('/chat/models', {
|
|
22
|
+
...options,
|
|
23
|
+
method: 'GET'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// ==================== Session管理接口 ====================
|
|
27
|
+
// 创建会话
|
|
28
|
+
async createSession(request, options) {
|
|
29
|
+
return this.request('/session', {
|
|
30
|
+
...options,
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: request
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// 获取用户会话列表
|
|
36
|
+
async getSessions(params, options) {
|
|
37
|
+
return this.request('/session', {
|
|
38
|
+
...options,
|
|
39
|
+
method: 'GET',
|
|
40
|
+
params
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// 获取会话详情
|
|
44
|
+
async getSession(sessionId, options) {
|
|
45
|
+
return this.request(`/session/${sessionId}`, {
|
|
46
|
+
...options,
|
|
47
|
+
method: 'GET'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// 更新会话
|
|
51
|
+
async updateSession(sessionId, request, options) {
|
|
52
|
+
return this.request(`/session/${sessionId}`, {
|
|
53
|
+
...options,
|
|
54
|
+
method: 'PUT',
|
|
55
|
+
body: request
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// 结束会话
|
|
59
|
+
async endSession(sessionId, options) {
|
|
60
|
+
return this.request(`/session/${sessionId}/end`, {
|
|
61
|
+
...options,
|
|
62
|
+
method: 'POST'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// 删除会话
|
|
66
|
+
async deleteSession(sessionId, options) {
|
|
67
|
+
return this.request(`/session/${sessionId}`, {
|
|
68
|
+
...options,
|
|
69
|
+
method: 'DELETE'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// 获取会话模型信息
|
|
73
|
+
async getSessionModel(sessionId, options) {
|
|
74
|
+
return this.request(`/session/${sessionId}/model`, {
|
|
75
|
+
...options,
|
|
76
|
+
method: 'GET'
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// 获取用户活跃会话
|
|
80
|
+
async getActiveSessions(options) {
|
|
81
|
+
return this.request('/session/active', {
|
|
82
|
+
...options,
|
|
83
|
+
method: 'GET'
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// ==================== Assistant管理接口 ====================
|
|
87
|
+
// 创建助手
|
|
88
|
+
async createAssistant(request, options) {
|
|
89
|
+
return this.request('/assistant', {
|
|
90
|
+
...options,
|
|
91
|
+
method: 'POST',
|
|
92
|
+
body: request
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// 获取助手列表
|
|
96
|
+
async getAssistants(params, options) {
|
|
97
|
+
return this.request('/assistant', {
|
|
98
|
+
...options,
|
|
99
|
+
method: 'GET',
|
|
100
|
+
params
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// 获取助手详情
|
|
104
|
+
async getAssistant(assistantId, options) {
|
|
105
|
+
return this.request(`/assistant/${assistantId}`, {
|
|
106
|
+
...options,
|
|
107
|
+
method: 'GET'
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// 更新助手
|
|
111
|
+
async updateAssistant(assistantId, request, options) {
|
|
112
|
+
return this.request(`/assistant/${assistantId}`, {
|
|
113
|
+
...options,
|
|
114
|
+
method: 'PUT',
|
|
115
|
+
body: request
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// 删除助手
|
|
119
|
+
async deleteAssistant(assistantId, options) {
|
|
120
|
+
return this.request(`/assistant/${assistantId}`, {
|
|
121
|
+
...options,
|
|
122
|
+
method: 'DELETE'
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// 获取可访问的助手
|
|
126
|
+
async getAccessibleAssistants(options) {
|
|
127
|
+
return this.request('/assistant/accessible', {
|
|
128
|
+
...options,
|
|
129
|
+
method: 'GET'
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
// 获取热门助手
|
|
133
|
+
async getPopularAssistants(limit, options) {
|
|
134
|
+
return this.request('/assistant/popular', {
|
|
135
|
+
...options,
|
|
136
|
+
method: 'GET',
|
|
137
|
+
params: limit ? { limit } : undefined
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// 增加助手使用次数
|
|
141
|
+
async incrementAssistantUsage(assistantId, options) {
|
|
142
|
+
return this.request(`/assistant/${assistantId}/usage`, {
|
|
143
|
+
...options,
|
|
144
|
+
method: 'POST'
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// 复制助手
|
|
148
|
+
async duplicateAssistant(assistantId, newName, options) {
|
|
149
|
+
return this.request(`/assistant/${assistantId}/duplicate`, {
|
|
150
|
+
...options,
|
|
151
|
+
method: 'POST',
|
|
152
|
+
body: { newName }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// ==================== Provider管理接口 ====================
|
|
156
|
+
// 获取服务商列表
|
|
157
|
+
async getProviders(options) {
|
|
158
|
+
return this.request('/provider', {
|
|
159
|
+
...options,
|
|
160
|
+
method: 'GET'
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// 获取服务商详情
|
|
164
|
+
async getProvider(providerKey, options) {
|
|
165
|
+
return this.request(`/provider/${providerKey}`, {
|
|
166
|
+
...options,
|
|
167
|
+
method: 'GET'
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// 获取当前用户可访问的服务商
|
|
171
|
+
async getAccessibleProviders(options) {
|
|
172
|
+
return this.request('/provider/accessible/me', {
|
|
173
|
+
...options,
|
|
174
|
+
method: 'GET'
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// ==================== Model管理接口 ====================
|
|
178
|
+
// 获取模型列表
|
|
179
|
+
async getModels(params, options) {
|
|
180
|
+
return this.request('/model', {
|
|
181
|
+
...options,
|
|
182
|
+
method: 'GET',
|
|
183
|
+
params
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// 获取模型详情
|
|
187
|
+
async getModel(modelId, options) {
|
|
188
|
+
return this.request(`/model/${modelId}`, {
|
|
189
|
+
...options,
|
|
190
|
+
method: 'GET'
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// 按服务商获取模型列表
|
|
194
|
+
async getModelsByProvider(providerKey, options) {
|
|
195
|
+
return this.request(`/model/by-provider/${providerKey}`, {
|
|
196
|
+
...options,
|
|
197
|
+
method: 'GET'
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// 获取当前用户可访问的模型
|
|
201
|
+
async getAccessibleModels(options) {
|
|
202
|
+
return this.request('/model/accessible/me', {
|
|
203
|
+
...options,
|
|
204
|
+
method: 'GET'
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// 获取会话消息历史
|
|
208
|
+
async getSessionMessages(sessionId, params, options) {
|
|
209
|
+
return this.request(`/session/${sessionId}/messages`, {
|
|
210
|
+
...options,
|
|
211
|
+
method: 'GET',
|
|
212
|
+
params
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
// 添加消息到会话
|
|
216
|
+
async addMessageToSession(sessionId, request, options) {
|
|
217
|
+
return this.request(`/session/${sessionId}/message`, {
|
|
218
|
+
...options,
|
|
219
|
+
method: 'POST',
|
|
220
|
+
body: request
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// 批量删除会话
|
|
224
|
+
async deleteSessionsBatch(sessionIds, options) {
|
|
225
|
+
return this.request('/session/batch', {
|
|
226
|
+
...options,
|
|
227
|
+
method: 'DELETE',
|
|
228
|
+
body: { sessionIds }
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// 切换会话模型
|
|
232
|
+
async switchSessionModel(sessionId, modelName, options) {
|
|
233
|
+
const request = { modelName };
|
|
234
|
+
return this.request(`/session/${sessionId}/model`, {
|
|
235
|
+
...options,
|
|
236
|
+
method: 'PUT',
|
|
237
|
+
body: request
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// 获取会话统计信息
|
|
241
|
+
async getSessionStatistics(timeRange, options) {
|
|
242
|
+
return this.request('/session/statistics', {
|
|
243
|
+
...options,
|
|
244
|
+
method: 'GET',
|
|
245
|
+
params: timeRange ? { timeRange } : undefined
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// 获取助手可用模型
|
|
249
|
+
async getAssistantModels(assistantId, options) {
|
|
250
|
+
return this.request(`/assistant/${assistantId}/models`, {
|
|
251
|
+
...options,
|
|
252
|
+
method: 'GET'
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
exports.AiService = AiService;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
export interface ChatCompletionRequest {
|
|
2
|
+
messages: Array<{
|
|
3
|
+
role: 'system' | 'user' | 'assistant';
|
|
4
|
+
content: string;
|
|
5
|
+
}>;
|
|
6
|
+
model: string;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
topP?: number;
|
|
10
|
+
stream?: boolean;
|
|
11
|
+
functions?: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
parameters?: any;
|
|
15
|
+
}>;
|
|
16
|
+
functionCall?: 'none' | 'auto';
|
|
17
|
+
}
|
|
18
|
+
export interface ChatCompletionResponse {
|
|
19
|
+
id: string;
|
|
20
|
+
object: string;
|
|
21
|
+
created: number;
|
|
22
|
+
model: string;
|
|
23
|
+
choices: Array<{
|
|
24
|
+
index: number;
|
|
25
|
+
message: {
|
|
26
|
+
role: string;
|
|
27
|
+
content: string;
|
|
28
|
+
};
|
|
29
|
+
finishReason: string;
|
|
30
|
+
}>;
|
|
31
|
+
usage?: {
|
|
32
|
+
promptTokens: number;
|
|
33
|
+
completionTokens: number;
|
|
34
|
+
totalTokens: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface ProviderListItem {
|
|
38
|
+
key: string;
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
isGlobal: boolean;
|
|
42
|
+
callMode: string;
|
|
43
|
+
modelCount: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ProviderDetail {
|
|
46
|
+
key: string;
|
|
47
|
+
name: string;
|
|
48
|
+
description: string;
|
|
49
|
+
baseUrl: string;
|
|
50
|
+
isGlobal: boolean;
|
|
51
|
+
visibleProjects: string[];
|
|
52
|
+
callMode: string;
|
|
53
|
+
models: ProviderModel[];
|
|
54
|
+
}
|
|
55
|
+
export interface ProviderModel {
|
|
56
|
+
name: string;
|
|
57
|
+
displayName: string;
|
|
58
|
+
description: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ModelListItem {
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
displayName: string;
|
|
64
|
+
description: string;
|
|
65
|
+
provider: string;
|
|
66
|
+
providerName: string;
|
|
67
|
+
supportsStreaming: boolean;
|
|
68
|
+
supportsFunctionCalling: boolean;
|
|
69
|
+
maxTokens: number;
|
|
70
|
+
contextWindow: number;
|
|
71
|
+
capabilities: string[];
|
|
72
|
+
}
|
|
73
|
+
export interface ModelDetail {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
displayName: string;
|
|
77
|
+
description: string;
|
|
78
|
+
provider: string;
|
|
79
|
+
providerName: string;
|
|
80
|
+
inputTypes: string[];
|
|
81
|
+
outputFormats: string[];
|
|
82
|
+
supportsStreaming: boolean;
|
|
83
|
+
supportsFunctionCalling: boolean;
|
|
84
|
+
maxTokens: number;
|
|
85
|
+
contextWindow: number;
|
|
86
|
+
capabilities: string[];
|
|
87
|
+
pricing?: {
|
|
88
|
+
input: number;
|
|
89
|
+
output: number;
|
|
90
|
+
};
|
|
91
|
+
schemaDefinition: string;
|
|
92
|
+
}
|
|
93
|
+
export interface CreateAssistantRequest {
|
|
94
|
+
name: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
avatarUrl?: string;
|
|
97
|
+
providerName: string;
|
|
98
|
+
defaultModel: string;
|
|
99
|
+
availableModels?: string[];
|
|
100
|
+
baseUrl?: string;
|
|
101
|
+
apiKey?: string;
|
|
102
|
+
roleDefinition: string;
|
|
103
|
+
initMessages?: Array<{
|
|
104
|
+
role: string;
|
|
105
|
+
content: string;
|
|
106
|
+
}>;
|
|
107
|
+
strictRules?: string[];
|
|
108
|
+
config?: ModelConfig;
|
|
109
|
+
visibleProjects?: string[];
|
|
110
|
+
isGlobal?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface UpdateAssistantRequest {
|
|
113
|
+
name?: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
avatarUrl?: string;
|
|
116
|
+
providerName?: string;
|
|
117
|
+
defaultModel?: string;
|
|
118
|
+
availableModels?: string[];
|
|
119
|
+
baseUrl?: string;
|
|
120
|
+
apiKey?: string;
|
|
121
|
+
roleDefinition?: string;
|
|
122
|
+
initMessages?: Array<{
|
|
123
|
+
role: string;
|
|
124
|
+
content: string;
|
|
125
|
+
}>;
|
|
126
|
+
strictRules?: string[];
|
|
127
|
+
config?: ModelConfig;
|
|
128
|
+
visibleProjects?: string[];
|
|
129
|
+
isGlobal?: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface AssistantResponse {
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
avatarUrl?: string;
|
|
136
|
+
providerName: string;
|
|
137
|
+
modelName: string;
|
|
138
|
+
availableModels: string[];
|
|
139
|
+
defaultModel: string;
|
|
140
|
+
baseUrl?: string;
|
|
141
|
+
roleDefinition: string;
|
|
142
|
+
initMessages?: Array<{
|
|
143
|
+
role: string;
|
|
144
|
+
content: string;
|
|
145
|
+
}>;
|
|
146
|
+
strictRules?: string[];
|
|
147
|
+
config?: ModelConfig;
|
|
148
|
+
visibleProjects?: string[];
|
|
149
|
+
isGlobal: boolean;
|
|
150
|
+
usageCount: number;
|
|
151
|
+
lastUsedAt?: string;
|
|
152
|
+
createdAt: string;
|
|
153
|
+
updatedAt: string;
|
|
154
|
+
}
|
|
155
|
+
export interface AssistantListResponse {
|
|
156
|
+
data: AssistantResponse[];
|
|
157
|
+
total: number;
|
|
158
|
+
page: number;
|
|
159
|
+
limit: number;
|
|
160
|
+
totalPages: number;
|
|
161
|
+
}
|
|
162
|
+
export interface CreateSessionRequest {
|
|
163
|
+
assistantId: string;
|
|
164
|
+
currentModel?: string;
|
|
165
|
+
}
|
|
166
|
+
export interface SessionResponse {
|
|
167
|
+
id: string;
|
|
168
|
+
assistantId: string;
|
|
169
|
+
assistantName: string;
|
|
170
|
+
title: string;
|
|
171
|
+
status: 'active' | 'ended';
|
|
172
|
+
currentModel: string;
|
|
173
|
+
messageCount: number;
|
|
174
|
+
lastMessage?: string;
|
|
175
|
+
lastMessageTime?: string;
|
|
176
|
+
createdAt: string;
|
|
177
|
+
updatedAt: string;
|
|
178
|
+
}
|
|
179
|
+
export interface SessionListResponse {
|
|
180
|
+
data: SessionResponse[];
|
|
181
|
+
total: number;
|
|
182
|
+
page: number;
|
|
183
|
+
limit: number;
|
|
184
|
+
totalPages: number;
|
|
185
|
+
}
|
|
186
|
+
export interface AddMessageRequest {
|
|
187
|
+
sender: 'user' | 'assistant';
|
|
188
|
+
content: string;
|
|
189
|
+
files?: string[];
|
|
190
|
+
}
|
|
191
|
+
export interface SessionMessage {
|
|
192
|
+
id: string;
|
|
193
|
+
sender: 'user' | 'assistant' | 'system';
|
|
194
|
+
content: string;
|
|
195
|
+
type: 'text' | 'image' | 'file' | 'function_call' | 'function_result';
|
|
196
|
+
timestamp: string;
|
|
197
|
+
files?: string[];
|
|
198
|
+
metadata?: {
|
|
199
|
+
tokens?: number;
|
|
200
|
+
model?: string;
|
|
201
|
+
[key: string]: any;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export interface ModelConfig {
|
|
205
|
+
temperature?: number;
|
|
206
|
+
maxTokens?: number;
|
|
207
|
+
topP?: number;
|
|
208
|
+
frequencyPenalty?: number;
|
|
209
|
+
presencePenalty?: number;
|
|
210
|
+
}
|
|
211
|
+
export interface PaginatedSessionMessageResponse {
|
|
212
|
+
messages: SessionMessage[];
|
|
213
|
+
pagination: {
|
|
214
|
+
total: number;
|
|
215
|
+
page: number;
|
|
216
|
+
limit: number;
|
|
217
|
+
totalPages: number;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export interface SessionStatistics {
|
|
221
|
+
totalSessions: number;
|
|
222
|
+
activeSessions: number;
|
|
223
|
+
messagesCount: number;
|
|
224
|
+
averageSessionLength: number;
|
|
225
|
+
}
|
|
226
|
+
export interface BatchDeleteSessionsRequest {
|
|
227
|
+
sessionIds: string[];
|
|
228
|
+
}
|
|
229
|
+
export interface BatchDeleteSessionsResponse {
|
|
230
|
+
message: string;
|
|
231
|
+
}
|
|
232
|
+
export interface SwitchModelRequest {
|
|
233
|
+
modelName: string;
|
|
234
|
+
}
|
|
235
|
+
export interface AssistantModelsResponse {
|
|
236
|
+
assistantId: string;
|
|
237
|
+
availableModels: string[];
|
|
238
|
+
}
|
package/lib/types/ai.js
ADDED
package/package.json
CHANGED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// src/srvice/AiService.ts
|
|
2
|
+
import { BaseClient } from "../client/BaseClient";
|
|
3
|
+
import { ClientConfig, RequestOptions, PaginatedResponse } from "../types";
|
|
4
|
+
import {
|
|
5
|
+
ChatCompletionRequest,
|
|
6
|
+
ChatCompletionResponse,
|
|
7
|
+
ProviderListItem,
|
|
8
|
+
ProviderDetail,
|
|
9
|
+
ModelListItem,
|
|
10
|
+
ModelDetail,
|
|
11
|
+
CreateSessionRequest,
|
|
12
|
+
SessionResponse,
|
|
13
|
+
SessionListResponse,
|
|
14
|
+
CreateAssistantRequest,
|
|
15
|
+
AssistantResponse,
|
|
16
|
+
AssistantListResponse,
|
|
17
|
+
UpdateAssistantRequest,
|
|
18
|
+
AddMessageRequest,
|
|
19
|
+
SessionMessage,
|
|
20
|
+
BatchDeleteSessionsResponse,
|
|
21
|
+
SwitchModelRequest,
|
|
22
|
+
SessionStatistics,
|
|
23
|
+
AssistantModelsResponse,
|
|
24
|
+
PaginatedSessionMessageResponse
|
|
25
|
+
} from "../types/ai";
|
|
26
|
+
|
|
27
|
+
export class AiService extends BaseClient {
|
|
28
|
+
constructor(config: ClientConfig) {
|
|
29
|
+
super(config, 'ai');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ==================== Chat对话接口 ====================
|
|
33
|
+
|
|
34
|
+
// 聊天补全(非流式)
|
|
35
|
+
async chatCompletion(request: ChatCompletionRequest, options?: RequestOptions): Promise<ChatCompletionResponse> {
|
|
36
|
+
return this.request<ChatCompletionResponse>('/chat/completion', {
|
|
37
|
+
...options,
|
|
38
|
+
method: 'POST',
|
|
39
|
+
body: request
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 获取聊天可用模型
|
|
44
|
+
async getChatModels(options?: RequestOptions): Promise<{ models: ModelListItem[] }> {
|
|
45
|
+
return this.request<{ models: ModelListItem[] }>('/chat/models', {
|
|
46
|
+
...options,
|
|
47
|
+
method: 'GET'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ==================== Session管理接口 ====================
|
|
52
|
+
|
|
53
|
+
// 创建会话
|
|
54
|
+
async createSession(request: CreateSessionRequest, options?: RequestOptions): Promise<SessionResponse> {
|
|
55
|
+
return this.request<SessionResponse>('/session', {
|
|
56
|
+
...options,
|
|
57
|
+
method: 'POST',
|
|
58
|
+
body: request
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 获取用户会话列表
|
|
63
|
+
async getSessions(params?: {
|
|
64
|
+
page?: number;
|
|
65
|
+
limit?: number;
|
|
66
|
+
status?: 'active' | 'ended';
|
|
67
|
+
}, options?: RequestOptions): Promise<SessionListResponse> {
|
|
68
|
+
return this.request<SessionListResponse>('/session', {
|
|
69
|
+
...options,
|
|
70
|
+
method: 'GET',
|
|
71
|
+
params
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 获取会话详情
|
|
76
|
+
async getSession(sessionId: string, options?: RequestOptions): Promise<SessionResponse> {
|
|
77
|
+
return this.request<SessionResponse>(`/session/${sessionId}`, {
|
|
78
|
+
...options,
|
|
79
|
+
method: 'GET'
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 更新会话
|
|
84
|
+
async updateSession(sessionId: string, request: any, options?: RequestOptions): Promise<SessionResponse> {
|
|
85
|
+
return this.request<SessionResponse>(`/session/${sessionId}`, {
|
|
86
|
+
...options,
|
|
87
|
+
method: 'PUT',
|
|
88
|
+
body: request
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 结束会话
|
|
93
|
+
async endSession(sessionId: string, options?: RequestOptions): Promise<SessionResponse> {
|
|
94
|
+
return this.request<SessionResponse>(`/session/${sessionId}/end`, {
|
|
95
|
+
...options,
|
|
96
|
+
method: 'POST'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 删除会话
|
|
101
|
+
async deleteSession(sessionId: string, options?: RequestOptions): Promise<void> {
|
|
102
|
+
return this.request<void>(`/session/${sessionId}`, {
|
|
103
|
+
...options,
|
|
104
|
+
method: 'DELETE'
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
// 获取会话模型信息
|
|
110
|
+
async getSessionModel(sessionId: string, options?: RequestOptions): Promise<{
|
|
111
|
+
currentModel: string;
|
|
112
|
+
availableModels: string[];
|
|
113
|
+
providerName: string;
|
|
114
|
+
}> {
|
|
115
|
+
return this.request<{
|
|
116
|
+
currentModel: string;
|
|
117
|
+
availableModels: string[];
|
|
118
|
+
providerName: string;
|
|
119
|
+
}>(`/session/${sessionId}/model`, {
|
|
120
|
+
...options,
|
|
121
|
+
method: 'GET'
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 获取用户活跃会话
|
|
126
|
+
async getActiveSessions(options?: RequestOptions): Promise<{ sessions: SessionResponse[] }> {
|
|
127
|
+
return this.request<{ sessions: SessionResponse[] }>('/session/active', {
|
|
128
|
+
...options,
|
|
129
|
+
method: 'GET'
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ==================== Assistant管理接口 ====================
|
|
134
|
+
|
|
135
|
+
// 创建助手
|
|
136
|
+
async createAssistant(request: CreateAssistantRequest, options?: RequestOptions): Promise<AssistantResponse> {
|
|
137
|
+
return this.request<AssistantResponse>('/assistant', {
|
|
138
|
+
...options,
|
|
139
|
+
method: 'POST',
|
|
140
|
+
body: request
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 获取助手列表
|
|
145
|
+
async getAssistants(params?: {
|
|
146
|
+
page?: number;
|
|
147
|
+
limit?: number;
|
|
148
|
+
}, options?: RequestOptions): Promise<AssistantListResponse> {
|
|
149
|
+
return this.request<AssistantListResponse>('/assistant', {
|
|
150
|
+
...options,
|
|
151
|
+
method: 'GET',
|
|
152
|
+
params
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 获取助手详情
|
|
157
|
+
async getAssistant(assistantId: string, options?: RequestOptions): Promise<AssistantResponse> {
|
|
158
|
+
return this.request<AssistantResponse>(`/assistant/${assistantId}`, {
|
|
159
|
+
...options,
|
|
160
|
+
method: 'GET'
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 更新助手
|
|
165
|
+
async updateAssistant(assistantId: string, request: UpdateAssistantRequest, options?: RequestOptions): Promise<AssistantResponse> {
|
|
166
|
+
return this.request<AssistantResponse>(`/assistant/${assistantId}`, {
|
|
167
|
+
...options,
|
|
168
|
+
method: 'PUT',
|
|
169
|
+
body: request
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 删除助手
|
|
174
|
+
async deleteAssistant(assistantId: string, options?: RequestOptions): Promise<void> {
|
|
175
|
+
return this.request<void>(`/assistant/${assistantId}`, {
|
|
176
|
+
...options,
|
|
177
|
+
method: 'DELETE'
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 获取可访问的助手
|
|
182
|
+
async getAccessibleAssistants(options?: RequestOptions): Promise<{ assistants: AssistantResponse[] }> {
|
|
183
|
+
return this.request<{ assistants: AssistantResponse[] }>('/assistant/accessible', {
|
|
184
|
+
...options,
|
|
185
|
+
method: 'GET'
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 获取热门助手
|
|
190
|
+
async getPopularAssistants(limit?: number, options?: RequestOptions): Promise<{ assistants: AssistantResponse[] }> {
|
|
191
|
+
return this.request<{ assistants: AssistantResponse[] }>('/assistant/popular', {
|
|
192
|
+
...options,
|
|
193
|
+
method: 'GET',
|
|
194
|
+
params: limit ? { limit } : undefined
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 增加助手使用次数
|
|
199
|
+
async incrementAssistantUsage(assistantId: string, options?: RequestOptions): Promise<AssistantResponse> {
|
|
200
|
+
return this.request<AssistantResponse>(`/assistant/${assistantId}/usage`, {
|
|
201
|
+
...options,
|
|
202
|
+
method: 'POST'
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 复制助手
|
|
207
|
+
async duplicateAssistant(assistantId: string, newName: string, options?: RequestOptions): Promise<AssistantResponse> {
|
|
208
|
+
return this.request<AssistantResponse>(`/assistant/${assistantId}/duplicate`, {
|
|
209
|
+
...options,
|
|
210
|
+
method: 'POST',
|
|
211
|
+
body: { newName }
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
// ==================== Provider管理接口 ====================
|
|
217
|
+
|
|
218
|
+
// 获取服务商列表
|
|
219
|
+
async getProviders(options?: RequestOptions): Promise<{ providers: ProviderListItem[] }> {
|
|
220
|
+
return this.request<{ providers: ProviderListItem[] }>('/provider', {
|
|
221
|
+
...options,
|
|
222
|
+
method: 'GET'
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 获取服务商详情
|
|
227
|
+
async getProvider(providerKey: string, options?: RequestOptions): Promise<ProviderDetail> {
|
|
228
|
+
return this.request<ProviderDetail>(`/provider/${providerKey}`, {
|
|
229
|
+
...options,
|
|
230
|
+
method: 'GET'
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 获取当前用户可访问的服务商
|
|
235
|
+
async getAccessibleProviders(options?: RequestOptions): Promise<{ providers: ProviderListItem[] }> {
|
|
236
|
+
return this.request<{ providers: ProviderListItem[] }>('/provider/accessible/me', {
|
|
237
|
+
...options,
|
|
238
|
+
method: 'GET'
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ==================== Model管理接口 ====================
|
|
243
|
+
|
|
244
|
+
// 获取模型列表
|
|
245
|
+
async getModels(params?: {
|
|
246
|
+
provider?: string;
|
|
247
|
+
capability?: string;
|
|
248
|
+
}, options?: RequestOptions): Promise<{ models: ModelListItem[] }> {
|
|
249
|
+
return this.request<{ models: ModelListItem[] }>('/model', {
|
|
250
|
+
...options,
|
|
251
|
+
method: 'GET',
|
|
252
|
+
params
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 获取模型详情
|
|
257
|
+
async getModel(modelId: string, options?: RequestOptions): Promise<ModelDetail> {
|
|
258
|
+
return this.request<ModelDetail>(`/model/${modelId}`, {
|
|
259
|
+
...options,
|
|
260
|
+
method: 'GET'
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 按服务商获取模型列表
|
|
265
|
+
async getModelsByProvider(providerKey: string, options?: RequestOptions): Promise<{ models: ModelListItem[] }> {
|
|
266
|
+
return this.request<{ models: ModelListItem[] }>(`/model/by-provider/${providerKey}`, {
|
|
267
|
+
...options,
|
|
268
|
+
method: 'GET'
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 获取当前用户可访问的模型
|
|
273
|
+
async getAccessibleModels(options?: RequestOptions): Promise<{ models: ModelListItem[] }> {
|
|
274
|
+
return this.request<{ models: ModelListItem[] }>('/model/accessible/me', {
|
|
275
|
+
...options,
|
|
276
|
+
method: 'GET'
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
// 获取会话消息历史
|
|
280
|
+
async getSessionMessages(sessionId: string, params?: {
|
|
281
|
+
page?: number;
|
|
282
|
+
limit?: number;
|
|
283
|
+
}, options?: RequestOptions): Promise<PaginatedSessionMessageResponse> {
|
|
284
|
+
return this.request<PaginatedSessionMessageResponse>(`/session/${sessionId}/messages`, {
|
|
285
|
+
...options,
|
|
286
|
+
method: 'GET',
|
|
287
|
+
params
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 添加消息到会话
|
|
292
|
+
async addMessageToSession(sessionId: string, request: AddMessageRequest, options?: RequestOptions): Promise<SessionResponse> {
|
|
293
|
+
return this.request<SessionResponse>(`/session/${sessionId}/message`, {
|
|
294
|
+
...options,
|
|
295
|
+
method: 'POST',
|
|
296
|
+
body: request
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 批量删除会话
|
|
301
|
+
async deleteSessionsBatch(sessionIds: string[], options?: RequestOptions): Promise<BatchDeleteSessionsResponse> {
|
|
302
|
+
return this.request<BatchDeleteSessionsResponse>('/session/batch', {
|
|
303
|
+
...options,
|
|
304
|
+
method: 'DELETE',
|
|
305
|
+
body: { sessionIds }
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// 切换会话模型
|
|
310
|
+
async switchSessionModel(sessionId: string, modelName: string, options?: RequestOptions): Promise<SessionResponse> {
|
|
311
|
+
const request: SwitchModelRequest = { modelName };
|
|
312
|
+
return this.request<SessionResponse>(`/session/${sessionId}/model`, {
|
|
313
|
+
...options,
|
|
314
|
+
method: 'PUT',
|
|
315
|
+
body: request
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// 获取会话统计信息
|
|
320
|
+
async getSessionStatistics(timeRange?: 'today' | 'week' | 'month' | 'year', options?: RequestOptions): Promise<SessionStatistics> {
|
|
321
|
+
return this.request<SessionStatistics>('/session/statistics', {
|
|
322
|
+
...options,
|
|
323
|
+
method: 'GET',
|
|
324
|
+
params: timeRange ? { timeRange } : undefined
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// 获取助手可用模型
|
|
329
|
+
async getAssistantModels(assistantId: string, options?: RequestOptions): Promise<AssistantModelsResponse> {
|
|
330
|
+
return this.request<AssistantModelsResponse>(`/assistant/${assistantId}/models`, {
|
|
331
|
+
...options,
|
|
332
|
+
method: 'GET'
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
package/src/types/ai.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
// src/types/ai.ts
|
|
2
|
+
|
|
3
|
+
export interface ChatCompletionRequest {
|
|
4
|
+
messages: Array<{
|
|
5
|
+
role: 'system' | 'user' | 'assistant';
|
|
6
|
+
content: string;
|
|
7
|
+
}>;
|
|
8
|
+
model: string;
|
|
9
|
+
temperature?: number;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
topP?: number;
|
|
12
|
+
stream?: boolean;
|
|
13
|
+
functions?: Array<{
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
parameters?: any;
|
|
17
|
+
}>;
|
|
18
|
+
functionCall?: 'none' | 'auto';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ChatCompletionResponse {
|
|
22
|
+
id: string;
|
|
23
|
+
object: string;
|
|
24
|
+
created: number;
|
|
25
|
+
model: string;
|
|
26
|
+
choices: Array<{
|
|
27
|
+
index: number;
|
|
28
|
+
message: {
|
|
29
|
+
role: string;
|
|
30
|
+
content: string;
|
|
31
|
+
};
|
|
32
|
+
finishReason: string;
|
|
33
|
+
}>;
|
|
34
|
+
usage?: {
|
|
35
|
+
promptTokens: number;
|
|
36
|
+
completionTokens: number;
|
|
37
|
+
totalTokens: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Provider相关类型
|
|
42
|
+
export interface ProviderListItem {
|
|
43
|
+
key: string;
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
isGlobal: boolean;
|
|
47
|
+
callMode: string;
|
|
48
|
+
modelCount: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ProviderDetail {
|
|
52
|
+
key: string;
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
isGlobal: boolean;
|
|
57
|
+
visibleProjects: string[];
|
|
58
|
+
callMode: string;
|
|
59
|
+
models: ProviderModel[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ProviderModel {
|
|
63
|
+
name: string;
|
|
64
|
+
displayName: string;
|
|
65
|
+
description: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Model相关类型
|
|
69
|
+
export interface ModelListItem {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
displayName: string;
|
|
73
|
+
description: string;
|
|
74
|
+
provider: string;
|
|
75
|
+
providerName: string;
|
|
76
|
+
supportsStreaming: boolean;
|
|
77
|
+
supportsFunctionCalling: boolean;
|
|
78
|
+
maxTokens: number;
|
|
79
|
+
contextWindow: number;
|
|
80
|
+
capabilities: string[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ModelDetail {
|
|
84
|
+
id: string;
|
|
85
|
+
name: string;
|
|
86
|
+
displayName: string;
|
|
87
|
+
description: string;
|
|
88
|
+
provider: string;
|
|
89
|
+
providerName: string;
|
|
90
|
+
inputTypes: string[];
|
|
91
|
+
outputFormats: string[];
|
|
92
|
+
supportsStreaming: boolean;
|
|
93
|
+
supportsFunctionCalling: boolean;
|
|
94
|
+
maxTokens: number;
|
|
95
|
+
contextWindow: number;
|
|
96
|
+
capabilities: string[];
|
|
97
|
+
pricing?: {
|
|
98
|
+
input: number;
|
|
99
|
+
output: number;
|
|
100
|
+
};
|
|
101
|
+
schemaDefinition: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Assistant相关类型
|
|
105
|
+
export interface CreateAssistantRequest {
|
|
106
|
+
name: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
avatarUrl?: string;
|
|
109
|
+
providerName: string;
|
|
110
|
+
defaultModel: string;
|
|
111
|
+
availableModels?: string[];
|
|
112
|
+
baseUrl?: string;
|
|
113
|
+
apiKey?: string;
|
|
114
|
+
roleDefinition: string;
|
|
115
|
+
initMessages?: Array<{
|
|
116
|
+
role: string;
|
|
117
|
+
content: string;
|
|
118
|
+
}>;
|
|
119
|
+
strictRules?: string[];
|
|
120
|
+
config?: ModelConfig;
|
|
121
|
+
visibleProjects?: string[];
|
|
122
|
+
isGlobal?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface UpdateAssistantRequest {
|
|
126
|
+
name?: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
avatarUrl?: string;
|
|
129
|
+
providerName?: string;
|
|
130
|
+
defaultModel?: string;
|
|
131
|
+
availableModels?: string[];
|
|
132
|
+
baseUrl?: string;
|
|
133
|
+
apiKey?: string;
|
|
134
|
+
roleDefinition?: string;
|
|
135
|
+
initMessages?: Array<{
|
|
136
|
+
role: string;
|
|
137
|
+
content: string;
|
|
138
|
+
}>;
|
|
139
|
+
strictRules?: string[];
|
|
140
|
+
config?: ModelConfig;
|
|
141
|
+
visibleProjects?: string[];
|
|
142
|
+
isGlobal?: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface AssistantResponse {
|
|
146
|
+
id: string;
|
|
147
|
+
name: string;
|
|
148
|
+
description?: string;
|
|
149
|
+
avatarUrl?: string;
|
|
150
|
+
providerName: string;
|
|
151
|
+
modelName: string;
|
|
152
|
+
availableModels: string[];
|
|
153
|
+
defaultModel: string;
|
|
154
|
+
baseUrl?: string;
|
|
155
|
+
roleDefinition: string;
|
|
156
|
+
initMessages?: Array<{
|
|
157
|
+
role: string;
|
|
158
|
+
content: string;
|
|
159
|
+
}>;
|
|
160
|
+
strictRules?: string[];
|
|
161
|
+
config?: ModelConfig;
|
|
162
|
+
visibleProjects?: string[];
|
|
163
|
+
isGlobal: boolean;
|
|
164
|
+
usageCount: number;
|
|
165
|
+
lastUsedAt?: string;
|
|
166
|
+
createdAt: string;
|
|
167
|
+
updatedAt: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface AssistantListResponse {
|
|
171
|
+
data: AssistantResponse[];
|
|
172
|
+
total: number;
|
|
173
|
+
page: number;
|
|
174
|
+
limit: number;
|
|
175
|
+
totalPages: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Session相关类型
|
|
179
|
+
export interface CreateSessionRequest {
|
|
180
|
+
assistantId: string;
|
|
181
|
+
currentModel?: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface SessionResponse {
|
|
185
|
+
id: string;
|
|
186
|
+
assistantId: string;
|
|
187
|
+
assistantName: string;
|
|
188
|
+
title: string;
|
|
189
|
+
status: 'active' | 'ended';
|
|
190
|
+
currentModel: string;
|
|
191
|
+
messageCount: number;
|
|
192
|
+
lastMessage?: string;
|
|
193
|
+
lastMessageTime?: string;
|
|
194
|
+
createdAt: string;
|
|
195
|
+
updatedAt: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface SessionListResponse {
|
|
199
|
+
data: SessionResponse[];
|
|
200
|
+
total: number;
|
|
201
|
+
page: number;
|
|
202
|
+
limit: number;
|
|
203
|
+
totalPages: number;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 新增:AddMessageRequest类型(根据OpenAPI文档)
|
|
207
|
+
export interface AddMessageRequest {
|
|
208
|
+
sender: 'user' | 'assistant';
|
|
209
|
+
content: string;
|
|
210
|
+
files?: string[];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 新增:SessionMessage类型(根据OpenAPI文档)
|
|
214
|
+
export interface SessionMessage {
|
|
215
|
+
id: string;
|
|
216
|
+
sender: 'user' | 'assistant' | 'system';
|
|
217
|
+
content: string;
|
|
218
|
+
type: 'text' | 'image' | 'file' | 'function_call' | 'function_result';
|
|
219
|
+
timestamp: string;
|
|
220
|
+
files?: string[];
|
|
221
|
+
metadata?: {
|
|
222
|
+
tokens?: number;
|
|
223
|
+
model?: string;
|
|
224
|
+
[key: string]: any;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 通用类型
|
|
229
|
+
export interface ModelConfig {
|
|
230
|
+
temperature?: number;
|
|
231
|
+
maxTokens?: number;
|
|
232
|
+
topP?: number;
|
|
233
|
+
frequencyPenalty?: number;
|
|
234
|
+
presencePenalty?: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 分页响应类型
|
|
238
|
+
export interface PaginatedSessionMessageResponse {
|
|
239
|
+
messages: SessionMessage[];
|
|
240
|
+
pagination: {
|
|
241
|
+
total: number;
|
|
242
|
+
page: number;
|
|
243
|
+
limit: number;
|
|
244
|
+
totalPages: number;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// 会话统计类型
|
|
249
|
+
export interface SessionStatistics {
|
|
250
|
+
totalSessions: number;
|
|
251
|
+
activeSessions: number;
|
|
252
|
+
messagesCount: number;
|
|
253
|
+
averageSessionLength: number;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 批量删除请求类型
|
|
257
|
+
export interface BatchDeleteSessionsRequest {
|
|
258
|
+
sessionIds: string[];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 批量删除响应类型
|
|
262
|
+
export interface BatchDeleteSessionsResponse {
|
|
263
|
+
message: string;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 切换模型请求类型
|
|
267
|
+
export interface SwitchModelRequest {
|
|
268
|
+
modelName: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// 助手模型响应类型
|
|
272
|
+
export interface AssistantModelsResponse {
|
|
273
|
+
assistantId: string;
|
|
274
|
+
availableModels: string[];
|
|
275
|
+
}
|