qing-client 0.0.13 → 0.0.14

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.
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // client/npm/src/client/BaseClient.ts
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
5
  };
@@ -4,9 +4,7 @@ import { ChatCompletionRequest, ChatCompletionResponse, ProviderListItem, Provid
4
4
  export declare class AiService extends BaseClient {
5
5
  constructor(config: ClientConfig);
6
6
  chatCompletion(request: ChatCompletionRequest, options?: RequestOptions): Promise<ChatCompletionResponse>;
7
- getChatModels(options?: RequestOptions): Promise<{
8
- models: ModelListItem[];
9
- }>;
7
+ chatCompletionStream(request: ChatCompletionRequest, options?: RequestOptions): Promise<ChatCompletionResponse>;
10
8
  createSession(request: CreateSessionRequest, options?: RequestOptions): Promise<SessionResponse>;
11
9
  getSessions(params?: {
12
10
  page?: number;
@@ -17,7 +15,7 @@ export declare class AiService extends BaseClient {
17
15
  updateSession(sessionId: string, request: any, options?: RequestOptions): Promise<SessionResponse>;
18
16
  endSession(sessionId: string, options?: RequestOptions): Promise<SessionResponse>;
19
17
  deleteSession(sessionId: string, options?: RequestOptions): Promise<void>;
20
- getSessionModel(sessionId: string, options?: RequestOptions): Promise<{
18
+ getSessionModelInfo(sessionId: string, options?: RequestOptions): Promise<{
21
19
  currentModel: string;
22
20
  availableModels: string[];
23
21
  providerName: string;
@@ -25,6 +23,14 @@ export declare class AiService extends BaseClient {
25
23
  getActiveSessions(options?: RequestOptions): Promise<{
26
24
  sessions: SessionResponse[];
27
25
  }>;
26
+ switchSessionModel(sessionId: string, modelName: string, options?: RequestOptions): Promise<SessionResponse>;
27
+ getSessionStatistics(timeRange?: 'today' | 'week' | 'month' | 'year', options?: RequestOptions): Promise<SessionStatistics>;
28
+ getSessionMessages(sessionId: string, params?: {
29
+ page?: number;
30
+ limit?: number;
31
+ }, options?: RequestOptions): Promise<PaginatedSessionMessageResponse>;
32
+ addMessageToSession(sessionId: string, request: AddMessageRequest, options?: RequestOptions): Promise<SessionResponse>;
33
+ deleteSessionsBatch(sessionIds: string[], options?: RequestOptions): Promise<BatchDeleteSessionsResponse>;
28
34
  createAssistant(request: CreateAssistantRequest, options?: RequestOptions): Promise<AssistantResponse>;
29
35
  getAssistants(params?: {
30
36
  page?: number;
@@ -41,6 +47,7 @@ export declare class AiService extends BaseClient {
41
47
  }>;
42
48
  incrementAssistantUsage(assistantId: string, options?: RequestOptions): Promise<AssistantResponse>;
43
49
  duplicateAssistant(assistantId: string, newName: string, options?: RequestOptions): Promise<AssistantResponse>;
50
+ getAssistantModels(assistantId: string, options?: RequestOptions): Promise<AssistantModelsResponse>;
44
51
  getProviders(options?: RequestOptions): Promise<{
45
52
  providers: ProviderListItem[];
46
53
  }>;
@@ -61,13 +68,4 @@ export declare class AiService extends BaseClient {
61
68
  getAccessibleModels(options?: RequestOptions): Promise<{
62
69
  models: ModelListItem[];
63
70
  }>;
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
71
  }
@@ -10,17 +10,18 @@ class AiService extends BaseClient_1.BaseClient {
10
10
  // ==================== Chat对话接口 ====================
11
11
  // 聊天补全(非流式)
12
12
  async chatCompletion(request, options) {
13
- return this.request('/chat/completion', {
13
+ return this.request('/chat', {
14
14
  ...options,
15
15
  method: 'POST',
16
16
  body: request
17
17
  });
18
18
  }
19
- // 获取聊天可用模型
20
- async getChatModels(options) {
21
- return this.request('/chat/models', {
19
+ // 流式对话
20
+ async chatCompletionStream(request, options) {
21
+ return this.request('/chat/stream', {
22
22
  ...options,
23
- method: 'GET'
23
+ method: 'POST',
24
+ body: request
24
25
  });
25
26
  }
26
27
  // ==================== Session管理接口 ====================
@@ -32,7 +33,7 @@ class AiService extends BaseClient_1.BaseClient {
32
33
  body: request
33
34
  });
34
35
  }
35
- // 获取用户会话列表
36
+ // 获取用户会话列表
36
37
  async getSessions(params, options) {
37
38
  return this.request('/session', {
38
39
  ...options,
@@ -47,7 +48,7 @@ class AiService extends BaseClient_1.BaseClient {
47
48
  method: 'GET'
48
49
  });
49
50
  }
50
- // 更新会话
51
+ // 更新会话
51
52
  async updateSession(sessionId, request, options) {
52
53
  return this.request(`/session/${sessionId}`, {
53
54
  ...options,
@@ -69,11 +70,11 @@ class AiService extends BaseClient_1.BaseClient {
69
70
  method: 'DELETE'
70
71
  });
71
72
  }
72
- // 获取会话模型信息
73
- async getSessionModel(sessionId, options) {
73
+ // 获取会话模型信息
74
+ async getSessionModelInfo(sessionId, options) {
74
75
  return this.request(`/session/${sessionId}/model`, {
75
76
  ...options,
76
- method: 'GET'
77
+ method: 'PUT' // 注意:后端这里是PUT方法
77
78
  });
78
79
  }
79
80
  // 获取用户活跃会话
@@ -83,6 +84,47 @@ class AiService extends BaseClient_1.BaseClient {
83
84
  method: 'GET'
84
85
  });
85
86
  }
87
+ // 切换会话模型
88
+ async switchSessionModel(sessionId, modelName, options) {
89
+ const request = { modelName };
90
+ return this.request(`/session/${sessionId}/switch-model`, {
91
+ ...options,
92
+ method: 'POST', // 修正方法
93
+ body: request
94
+ });
95
+ }
96
+ // 获取会话统计信息
97
+ async getSessionStatistics(timeRange, options) {
98
+ return this.request('/session/statistics', {
99
+ ...options,
100
+ method: 'GET',
101
+ params: timeRange ? { timeRange } : undefined
102
+ });
103
+ }
104
+ // 获取会话消息历史
105
+ async getSessionMessages(sessionId, params, options) {
106
+ return this.request(`/session/${sessionId}/messages`, {
107
+ ...options,
108
+ method: 'GET',
109
+ params
110
+ });
111
+ }
112
+ // 添加消息到会话
113
+ async addMessageToSession(sessionId, request, options) {
114
+ return this.request(`/session/${sessionId}/message`, {
115
+ ...options,
116
+ method: 'POST',
117
+ body: request
118
+ });
119
+ }
120
+ // 批量删除会话
121
+ async deleteSessionsBatch(sessionIds, options) {
122
+ return this.request('/session/batch', {
123
+ ...options,
124
+ method: 'DELETE',
125
+ body: { sessionIds }
126
+ });
127
+ }
86
128
  // ==================== Assistant管理接口 ====================
87
129
  // 创建助手
88
130
  async createAssistant(request, options) {
@@ -152,6 +194,13 @@ class AiService extends BaseClient_1.BaseClient {
152
194
  body: { newName }
153
195
  });
154
196
  }
197
+ // 获取助手可用模型
198
+ async getAssistantModels(assistantId, options) {
199
+ return this.request(`/assistant/${assistantId}/models`, {
200
+ ...options,
201
+ method: 'GET'
202
+ });
203
+ }
155
204
  // ==================== Provider管理接口 ====================
156
205
  // 获取服务商列表
157
206
  async getProviders(options) {
@@ -204,53 +253,5 @@ class AiService extends BaseClient_1.BaseClient {
204
253
  method: 'GET'
205
254
  });
206
255
  }
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
  }
256
257
  exports.AiService = AiService;
package/lib/types/ai.d.ts CHANGED
@@ -1,39 +1,21 @@
1
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';
2
+ sessionId: string;
3
+ message: string;
4
+ model?: string;
17
5
  }
18
6
  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;
7
+ success: boolean;
8
+ message: string;
9
+ data: {
10
+ message: string;
11
+ sessionId: string;
35
12
  };
36
13
  }
14
+ export interface ChatCompletionStreamResponse {
15
+ content: string;
16
+ done?: boolean;
17
+ error?: string;
18
+ }
37
19
  export interface ProviderListItem {
38
20
  key: string;
39
21
  name: string;
@@ -101,7 +83,7 @@ export interface CreateAssistantRequest {
101
83
  apiKey?: string;
102
84
  roleDefinition: string;
103
85
  initMessages?: Array<{
104
- role: string;
86
+ role: 'system' | 'user' | 'assistant';
105
87
  content: string;
106
88
  }>;
107
89
  strictRules?: string[];
@@ -120,7 +102,7 @@ export interface UpdateAssistantRequest {
120
102
  apiKey?: string;
121
103
  roleDefinition?: string;
122
104
  initMessages?: Array<{
123
- role: string;
105
+ role: 'system' | 'user' | 'assistant';
124
106
  content: string;
125
107
  }>;
126
108
  strictRules?: string[];
@@ -139,13 +121,13 @@ export interface AssistantResponse {
139
121
  defaultModel: string;
140
122
  baseUrl?: string;
141
123
  roleDefinition: string;
142
- initMessages?: Array<{
143
- role: string;
124
+ initMessages: Array<{
125
+ role: 'system' | 'user' | 'assistant';
144
126
  content: string;
145
127
  }>;
146
- strictRules?: string[];
128
+ strictRules: string[];
147
129
  config?: ModelConfig;
148
- visibleProjects?: string[];
130
+ visibleProjects: string[];
149
131
  isGlobal: boolean;
150
132
  usageCount: number;
151
133
  lastUsedAt?: string;
@@ -162,19 +144,27 @@ export interface AssistantListResponse {
162
144
  export interface CreateSessionRequest {
163
145
  assistantId: string;
164
146
  currentModel?: string;
147
+ initialMessages?: Array<{
148
+ sender: 'user' | 'assistant';
149
+ content: string;
150
+ files?: string[];
151
+ timestamp?: string;
152
+ }>;
165
153
  }
166
154
  export interface SessionResponse {
167
155
  id: string;
168
156
  assistantId: string;
169
- assistantName: string;
170
- title: string;
171
157
  status: 'active' | 'ended';
172
158
  currentModel: string;
173
- messageCount: number;
174
- lastMessage?: string;
175
- lastMessageTime?: string;
159
+ messages: Array<{
160
+ sender: 'user' | 'assistant';
161
+ content: string;
162
+ files?: string[];
163
+ timestamp: string;
164
+ }>;
176
165
  createdAt: string;
177
166
  updatedAt: string;
167
+ lastMessageAt?: string;
178
168
  }
179
169
  export interface SessionListResponse {
180
170
  data: SessionResponse[];
@@ -183,6 +173,11 @@ export interface SessionListResponse {
183
173
  limit: number;
184
174
  totalPages: number;
185
175
  }
176
+ export interface SessionDetailResponse {
177
+ session: SessionResponse;
178
+ assistant: any;
179
+ availableModels: string[];
180
+ }
186
181
  export interface AddMessageRequest {
187
182
  sender: 'user' | 'assistant';
188
183
  content: string;
@@ -190,23 +185,10 @@ export interface AddMessageRequest {
190
185
  }
191
186
  export interface SessionMessage {
192
187
  id: string;
193
- sender: 'user' | 'assistant' | 'system';
188
+ sender: 'user' | 'assistant';
194
189
  content: string;
195
- type: 'text' | 'image' | 'file' | 'function_call' | 'function_result';
196
190
  timestamp: string;
197
191
  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
192
  }
211
193
  export interface PaginatedSessionMessageResponse {
212
194
  messages: SessionMessage[];
@@ -217,6 +199,13 @@ export interface PaginatedSessionMessageResponse {
217
199
  totalPages: number;
218
200
  };
219
201
  }
202
+ export interface ModelConfig {
203
+ temperature?: number;
204
+ maxTokens?: number;
205
+ topP?: number;
206
+ frequencyPenalty?: number;
207
+ presencePenalty?: number;
208
+ }
220
209
  export interface SessionStatistics {
221
210
  totalSessions: number;
222
211
  activeSessions: number;
@@ -228,11 +217,37 @@ export interface BatchDeleteSessionsRequest {
228
217
  }
229
218
  export interface BatchDeleteSessionsResponse {
230
219
  message: string;
220
+ data: {
221
+ deletedCount: number;
222
+ };
231
223
  }
232
224
  export interface SwitchModelRequest {
233
225
  modelName: string;
234
226
  }
227
+ export interface ModelInfoResponse {
228
+ currentModel: string;
229
+ availableModels: string[];
230
+ providerName: string;
231
+ }
235
232
  export interface AssistantModelsResponse {
236
233
  assistantId: string;
237
234
  availableModels: string[];
238
235
  }
236
+ export interface ApiSuccessResponse<T = any> {
237
+ success: true;
238
+ message?: string;
239
+ data: T;
240
+ }
241
+ export interface ApiErrorResponse {
242
+ success: false;
243
+ message: string;
244
+ error?: string;
245
+ }
246
+ export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
247
+ export interface PaginatedResponse<T = any> {
248
+ data: T[];
249
+ total: number;
250
+ page: number;
251
+ limit: number;
252
+ totalPages: number;
253
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qing-client",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -1,3 +1,5 @@
1
+ // client/npm/src/client/BaseClient.ts
2
+
1
3
  import axios, { AxiosInstance, AxiosRequestConfig, AxiosError, RawAxiosRequestHeaders } from 'axios';
2
4
  import {
3
5
  UserContext,
@@ -33,18 +33,19 @@ export class AiService extends BaseClient {
33
33
 
34
34
  // 聊天补全(非流式)
35
35
  async chatCompletion(request: ChatCompletionRequest, options?: RequestOptions): Promise<ChatCompletionResponse> {
36
- return this.request<ChatCompletionResponse>('/chat/completion', {
36
+ return this.request<ChatCompletionResponse>('/chat', {
37
37
  ...options,
38
38
  method: 'POST',
39
39
  body: request
40
40
  });
41
41
  }
42
42
 
43
- // 获取聊天可用模型
44
- async getChatModels(options?: RequestOptions): Promise<{ models: ModelListItem[] }> {
45
- return this.request<{ models: ModelListItem[] }>('/chat/models', {
43
+ // 流式对话
44
+ async chatCompletionStream(request: ChatCompletionRequest, options?: RequestOptions): Promise<ChatCompletionResponse> {
45
+ return this.request<ChatCompletionResponse>('/chat/stream', {
46
46
  ...options,
47
- method: 'GET'
47
+ method: 'POST',
48
+ body: request
48
49
  });
49
50
  }
50
51
 
@@ -59,7 +60,7 @@ export class AiService extends BaseClient {
59
60
  });
60
61
  }
61
62
 
62
- // 获取用户会话列表
63
+ // 获取用户会话列表
63
64
  async getSessions(params?: {
64
65
  page?: number;
65
66
  limit?: number;
@@ -80,7 +81,7 @@ export class AiService extends BaseClient {
80
81
  });
81
82
  }
82
83
 
83
- // 更新会话
84
+ // 更新会话
84
85
  async updateSession(sessionId: string, request: any, options?: RequestOptions): Promise<SessionResponse> {
85
86
  return this.request<SessionResponse>(`/session/${sessionId}`, {
86
87
  ...options,
@@ -105,9 +106,8 @@ export class AiService extends BaseClient {
105
106
  });
106
107
  }
107
108
 
108
-
109
- // 获取会话模型信息
110
- async getSessionModel(sessionId: string, options?: RequestOptions): Promise<{
109
+ // 获取会话模型信息
110
+ async getSessionModelInfo(sessionId: string, options?: RequestOptions): Promise<{
111
111
  currentModel: string;
112
112
  availableModels: string[];
113
113
  providerName: string;
@@ -118,7 +118,7 @@ export class AiService extends BaseClient {
118
118
  providerName: string;
119
119
  }>(`/session/${sessionId}/model`, {
120
120
  ...options,
121
- method: 'GET'
121
+ method: 'PUT' // 注意:后端这里是PUT方法
122
122
  });
123
123
  }
124
124
 
@@ -130,6 +130,55 @@ export class AiService extends BaseClient {
130
130
  });
131
131
  }
132
132
 
133
+ // 切换会话模型
134
+ async switchSessionModel(sessionId: string, modelName: string, options?: RequestOptions): Promise<SessionResponse> {
135
+ const request: SwitchModelRequest = { modelName };
136
+ return this.request<SessionResponse>(`/session/${sessionId}/switch-model`, { // 修正路径
137
+ ...options,
138
+ method: 'POST', // 修正方法
139
+ body: request
140
+ });
141
+ }
142
+
143
+ // 获取会话统计信息
144
+ async getSessionStatistics(timeRange?: 'today' | 'week' | 'month' | 'year', options?: RequestOptions): Promise<SessionStatistics> {
145
+ return this.request<SessionStatistics>('/session/statistics', {
146
+ ...options,
147
+ method: 'GET',
148
+ params: timeRange ? { timeRange } : undefined
149
+ });
150
+ }
151
+
152
+ // 获取会话消息历史
153
+ async getSessionMessages(sessionId: string, params?: {
154
+ page?: number;
155
+ limit?: number;
156
+ }, options?: RequestOptions): Promise<PaginatedSessionMessageResponse> {
157
+ return this.request<PaginatedSessionMessageResponse>(`/session/${sessionId}/messages`, {
158
+ ...options,
159
+ method: 'GET',
160
+ params
161
+ });
162
+ }
163
+
164
+ // 添加消息到会话
165
+ async addMessageToSession(sessionId: string, request: AddMessageRequest, options?: RequestOptions): Promise<SessionResponse> {
166
+ return this.request<SessionResponse>(`/session/${sessionId}/message`, {
167
+ ...options,
168
+ method: 'POST',
169
+ body: request
170
+ });
171
+ }
172
+
173
+ // 批量删除会话
174
+ async deleteSessionsBatch(sessionIds: string[], options?: RequestOptions): Promise<BatchDeleteSessionsResponse> {
175
+ return this.request<BatchDeleteSessionsResponse>('/session/batch', {
176
+ ...options,
177
+ method: 'DELETE',
178
+ body: { sessionIds }
179
+ });
180
+ }
181
+
133
182
  // ==================== Assistant管理接口 ====================
134
183
 
135
184
  // 创建助手
@@ -212,6 +261,13 @@ export class AiService extends BaseClient {
212
261
  });
213
262
  }
214
263
 
264
+ // 获取助手可用模型
265
+ async getAssistantModels(assistantId: string, options?: RequestOptions): Promise<AssistantModelsResponse> {
266
+ return this.request<AssistantModelsResponse>(`/assistant/${assistantId}/models`, {
267
+ ...options,
268
+ method: 'GET'
269
+ });
270
+ }
215
271
 
216
272
  // ==================== Provider管理接口 ====================
217
273
 
@@ -276,61 +332,4 @@ export class AiService extends BaseClient {
276
332
  method: 'GET'
277
333
  });
278
334
  }
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
-
335
+ }
package/src/types/ai.ts CHANGED
@@ -1,44 +1,31 @@
1
1
  // src/types/ai.ts
2
2
 
3
+ // ==================== Chat对话相关类型 ====================
4
+
3
5
  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';
6
+ sessionId: string; // 后端需要sessionId
7
+ message: string; // 后端需要message,不是messages数组
8
+ model?: string; // 可选,会话中已有模型
19
9
  }
20
10
 
21
11
  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;
12
+ success: boolean;
13
+ message: string;
14
+ data: {
15
+ message: string;
16
+ sessionId: string;
38
17
  };
39
18
  }
40
19
 
41
- // Provider相关类型
20
+ // 流式对话响应类型
21
+ export interface ChatCompletionStreamResponse {
22
+ content: string;
23
+ done?: boolean;
24
+ error?: string;
25
+ }
26
+
27
+ // ==================== Provider相关类型 ====================
28
+
42
29
  export interface ProviderListItem {
43
30
  key: string;
44
31
  name: string;
@@ -65,9 +52,10 @@ export interface ProviderModel {
65
52
  description: string;
66
53
  }
67
54
 
68
- // Model相关类型
55
+ // ==================== Model相关类型 ====================
56
+
69
57
  export interface ModelListItem {
70
- id: string;
58
+ id: string; // 格式: provider.modelName
71
59
  name: string;
72
60
  displayName: string;
73
61
  description: string;
@@ -101,7 +89,8 @@ export interface ModelDetail {
101
89
  schemaDefinition: string;
102
90
  }
103
91
 
104
- // Assistant相关类型
92
+ // ==================== Assistant相关类型 ====================
93
+
105
94
  export interface CreateAssistantRequest {
106
95
  name: string;
107
96
  description?: string;
@@ -113,7 +102,7 @@ export interface CreateAssistantRequest {
113
102
  apiKey?: string;
114
103
  roleDefinition: string;
115
104
  initMessages?: Array<{
116
- role: string;
105
+ role: 'system' | 'user' | 'assistant';
117
106
  content: string;
118
107
  }>;
119
108
  strictRules?: string[];
@@ -133,7 +122,7 @@ export interface UpdateAssistantRequest {
133
122
  apiKey?: string;
134
123
  roleDefinition?: string;
135
124
  initMessages?: Array<{
136
- role: string;
125
+ role: 'system' | 'user' | 'assistant';
137
126
  content: string;
138
127
  }>;
139
128
  strictRules?: string[];
@@ -148,18 +137,18 @@ export interface AssistantResponse {
148
137
  description?: string;
149
138
  avatarUrl?: string;
150
139
  providerName: string;
151
- modelName: string;
140
+ modelName: string; // 注意:后端返回的是modelName
152
141
  availableModels: string[];
153
142
  defaultModel: string;
154
143
  baseUrl?: string;
155
144
  roleDefinition: string;
156
- initMessages?: Array<{
157
- role: string;
145
+ initMessages: Array<{ // 后端返回的是数组,不是可选
146
+ role: 'system' | 'user' | 'assistant';
158
147
  content: string;
159
148
  }>;
160
- strictRules?: string[];
149
+ strictRules: string[]; // 后端返回的是数组,不是可选
161
150
  config?: ModelConfig;
162
- visibleProjects?: string[];
151
+ visibleProjects: string[];
163
152
  isGlobal: boolean;
164
153
  usageCount: number;
165
154
  lastUsedAt?: string;
@@ -175,26 +164,36 @@ export interface AssistantListResponse {
175
164
  totalPages: number;
176
165
  }
177
166
 
178
- // Session相关类型
167
+ // ==================== Session相关类型 ====================
168
+
179
169
  export interface CreateSessionRequest {
180
170
  assistantId: string;
181
171
  currentModel?: string;
172
+ initialMessages?: Array<{ // 根据后端DTO添加
173
+ sender: 'user' | 'assistant';
174
+ content: string;
175
+ files?: string[];
176
+ timestamp?: string;
177
+ }>;
182
178
  }
183
179
 
184
180
  export interface SessionResponse {
185
181
  id: string;
186
182
  assistantId: string;
187
- assistantName: string;
188
- title: string;
189
183
  status: 'active' | 'ended';
190
184
  currentModel: string;
191
- messageCount: number;
192
- lastMessage?: string;
193
- lastMessageTime?: string;
185
+ messages: Array<{
186
+ sender: 'user' | 'assistant';
187
+ content: string;
188
+ files?: string[];
189
+ timestamp: string;
190
+ }>;
194
191
  createdAt: string;
195
192
  updatedAt: string;
193
+ lastMessageAt?: string;
196
194
  }
197
195
 
196
+ // 注意:后端返回的SessionListResponse结构不同
198
197
  export interface SessionListResponse {
199
198
  data: SessionResponse[];
200
199
  total: number;
@@ -203,38 +202,30 @@ export interface SessionListResponse {
203
202
  totalPages: number;
204
203
  }
205
204
 
206
- // 新增:AddMessageRequest类型(根据OpenAPI文档)
205
+ // 会话详情响应(包含助手信息)
206
+ export interface SessionDetailResponse {
207
+ session: SessionResponse;
208
+ assistant: any; // 助手详细信息
209
+ availableModels: string[];
210
+ }
211
+
212
+ // ==================== Message相关类型 ====================
213
+
207
214
  export interface AddMessageRequest {
208
215
  sender: 'user' | 'assistant';
209
216
  content: string;
210
217
  files?: string[];
211
218
  }
212
219
 
213
- // 新增:SessionMessage类型(根据OpenAPI文档)
214
220
  export interface SessionMessage {
215
221
  id: string;
216
- sender: 'user' | 'assistant' | 'system';
222
+ sender: 'user' | 'assistant';
217
223
  content: string;
218
- type: 'text' | 'image' | 'file' | 'function_call' | 'function_result';
219
224
  timestamp: string;
220
225
  files?: string[];
221
- metadata?: {
222
- tokens?: number;
223
- model?: string;
224
- [key: string]: any;
225
- };
226
226
  }
227
227
 
228
- // 通用类型
229
- export interface ModelConfig {
230
- temperature?: number;
231
- maxTokens?: number;
232
- topP?: number;
233
- frequencyPenalty?: number;
234
- presencePenalty?: number;
235
- }
236
-
237
- // 分页响应类型
228
+ // 分页消息响应
238
229
  export interface PaginatedSessionMessageResponse {
239
230
  messages: SessionMessage[];
240
231
  pagination: {
@@ -245,7 +236,18 @@ export interface PaginatedSessionMessageResponse {
245
236
  };
246
237
  }
247
238
 
248
- // 会话统计类型
239
+ // ==================== 通用配置类型 ====================
240
+
241
+ export interface ModelConfig {
242
+ temperature?: number;
243
+ maxTokens?: number;
244
+ topP?: number;
245
+ frequencyPenalty?: number;
246
+ presencePenalty?: number;
247
+ }
248
+
249
+ // ==================== 统计相关类型 ====================
250
+
249
251
  export interface SessionStatistics {
250
252
  totalSessions: number;
251
253
  activeSessions: number;
@@ -253,23 +255,60 @@ export interface SessionStatistics {
253
255
  averageSessionLength: number;
254
256
  }
255
257
 
256
- // 批量删除请求类型
258
+ // ==================== 批量操作类型 ====================
259
+
257
260
  export interface BatchDeleteSessionsRequest {
258
261
  sessionIds: string[];
259
262
  }
260
263
 
261
- // 批量删除响应类型
262
264
  export interface BatchDeleteSessionsResponse {
263
265
  message: string;
266
+ data: {
267
+ deletedCount: number;
268
+ };
264
269
  }
265
270
 
266
- // 切换模型请求类型
271
+ // ==================== 模型操作类型 ====================
272
+
267
273
  export interface SwitchModelRequest {
268
274
  modelName: string;
269
275
  }
270
276
 
271
- // 助手模型响应类型
277
+ export interface ModelInfoResponse {
278
+ currentModel: string;
279
+ availableModels: string[];
280
+ providerName: string;
281
+ }
282
+
272
283
  export interface AssistantModelsResponse {
273
284
  assistantId: string;
274
285
  availableModels: string[];
286
+ }
287
+
288
+ // ==================== 响应包装类型 ====================
289
+
290
+ // 通用成功响应
291
+ export interface ApiSuccessResponse<T = any> {
292
+ success: true;
293
+ message?: string;
294
+ data: T;
295
+ }
296
+
297
+ // 通用错误响应
298
+ export interface ApiErrorResponse {
299
+ success: false;
300
+ message: string;
301
+ error?: string;
302
+ }
303
+
304
+ // 通用API响应
305
+ export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
306
+
307
+ // 分页响应
308
+ export interface PaginatedResponse<T = any> {
309
+ data: T[];
310
+ total: number;
311
+ page: number;
312
+ limit: number;
313
+ totalPages: number;
275
314
  }