@cloudbase/agent-adapter-yuanqi 0.0.16 → 0.0.18
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 +243 -9
- package/dist/index.d.mts +187 -8
- package/dist/index.d.ts +187 -8
- package/dist/index.js +476 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +467 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AbstractAgent, AgentConfig, RunAgentInput, BaseEvent, Message } from '@ag-ui/client';
|
|
1
|
+
import { AbstractAgent, AgentConfig, RunAgentInput, BaseEvent, Message, EventType } from '@ag-ui/client';
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
3
|
+
import { Observable, Subscriber } from 'rxjs';
|
|
4
|
+
import tcb from '@cloudbase/node-sdk';
|
|
4
5
|
|
|
5
6
|
interface YuanqiConfig {
|
|
6
7
|
request?: {
|
|
@@ -10,6 +11,13 @@ interface YuanqiConfig {
|
|
|
10
11
|
};
|
|
11
12
|
appId?: string;
|
|
12
13
|
appKey?: string;
|
|
14
|
+
envId?: string;
|
|
15
|
+
credential?: {
|
|
16
|
+
secretId?: string;
|
|
17
|
+
secretKey?: string;
|
|
18
|
+
token?: string;
|
|
19
|
+
};
|
|
20
|
+
historyCount?: number;
|
|
13
21
|
}
|
|
14
22
|
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
15
23
|
interface YuanqiChatRequest {
|
|
@@ -22,9 +30,15 @@ interface YuanqiChatRequest {
|
|
|
22
30
|
chatType?: "published" | "preview";
|
|
23
31
|
[key: string]: any;
|
|
24
32
|
}
|
|
33
|
+
|
|
34
|
+
declare class YuanqiAgentError extends Error {
|
|
35
|
+
code?: string;
|
|
36
|
+
constructor(message: string, code?: string);
|
|
37
|
+
}
|
|
25
38
|
declare class YuanqiAgent extends AbstractAgent {
|
|
26
39
|
protected yuanqiConfig: YuanqiConfig;
|
|
27
40
|
private finalAppId;
|
|
41
|
+
private finalCloudCredential;
|
|
28
42
|
private model;
|
|
29
43
|
constructor(config: AgentConfig & {
|
|
30
44
|
yuanqiConfig: YuanqiConfig;
|
|
@@ -35,15 +49,180 @@ declare class YuanqiAgent extends AbstractAgent {
|
|
|
35
49
|
}): YuanqiChatRequest;
|
|
36
50
|
run(input: RunAgentInput): Observable<BaseEvent>;
|
|
37
51
|
private _run;
|
|
52
|
+
protected getChatHistory(subscriber: Subscriber<BaseEvent>, latestUserMessage: Message): Promise<OpenAI.Chat.Completions.ChatCompletionMessageParam[]>;
|
|
53
|
+
protected saveChatHistory(subscriber: Subscriber<BaseEvent>, input: RunAgentInput, userRecordId: string, assistantRecordId: string, userContent: string, assistantContent: string): Promise<void>;
|
|
54
|
+
private getTcbClient;
|
|
55
|
+
private checkIsDatabaseReady;
|
|
38
56
|
}
|
|
39
57
|
/**
|
|
40
58
|
* Convert AGUI messages to OpenAI chat completion format
|
|
41
59
|
*/
|
|
42
|
-
declare function convertMessagesToOpenAI(messages: Message[], systemPrompt?: string):
|
|
60
|
+
declare function convertMessagesToOpenAI(messages: Message[], systemPrompt?: string): ChatMessage[];
|
|
43
61
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
62
|
+
interface StreamContext {
|
|
63
|
+
threadId: string;
|
|
64
|
+
runId: string;
|
|
65
|
+
messageId: string;
|
|
66
|
+
}
|
|
67
|
+
interface StreamState {
|
|
68
|
+
hasStarted: boolean;
|
|
69
|
+
fullContent: string;
|
|
70
|
+
toolCallsMap: Map<string, {
|
|
71
|
+
name: string;
|
|
72
|
+
args: string;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
type Delta = OpenAI.Chat.Completions.ChatCompletionChunk["choices"][number]["delta"] & {
|
|
76
|
+
reasoning_content?: string;
|
|
77
|
+
};
|
|
78
|
+
declare function processYuanqiStream(stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>, context: StreamContext): AsyncGenerator<{
|
|
79
|
+
type: EventType;
|
|
80
|
+
threadId: string;
|
|
81
|
+
runId: string;
|
|
82
|
+
toolCallId: any;
|
|
83
|
+
content?: undefined;
|
|
84
|
+
messageId?: undefined;
|
|
85
|
+
role?: undefined;
|
|
86
|
+
delta?: undefined;
|
|
87
|
+
toolCallName?: undefined;
|
|
88
|
+
} | {
|
|
89
|
+
type: EventType;
|
|
90
|
+
threadId: string;
|
|
91
|
+
runId: string;
|
|
92
|
+
toolCallId: any;
|
|
93
|
+
content: string;
|
|
94
|
+
messageId?: undefined;
|
|
95
|
+
role?: undefined;
|
|
96
|
+
delta?: undefined;
|
|
97
|
+
toolCallName?: undefined;
|
|
98
|
+
} | {
|
|
99
|
+
type: EventType;
|
|
100
|
+
threadId: string;
|
|
101
|
+
runId: string;
|
|
102
|
+
messageId: string;
|
|
103
|
+
toolCallId?: undefined;
|
|
104
|
+
content?: undefined;
|
|
105
|
+
role?: undefined;
|
|
106
|
+
delta?: undefined;
|
|
107
|
+
toolCallName?: undefined;
|
|
108
|
+
} | {
|
|
109
|
+
type: EventType;
|
|
110
|
+
threadId: string;
|
|
111
|
+
runId: string;
|
|
112
|
+
messageId: string;
|
|
113
|
+
role: string;
|
|
114
|
+
toolCallId?: undefined;
|
|
115
|
+
content?: undefined;
|
|
116
|
+
delta?: undefined;
|
|
117
|
+
toolCallName?: undefined;
|
|
118
|
+
} | {
|
|
119
|
+
type: EventType;
|
|
120
|
+
threadId: string;
|
|
121
|
+
runId: string;
|
|
122
|
+
messageId: string;
|
|
123
|
+
delta: string;
|
|
124
|
+
toolCallId?: undefined;
|
|
125
|
+
content?: undefined;
|
|
126
|
+
role?: undefined;
|
|
127
|
+
toolCallName?: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
type: EventType;
|
|
130
|
+
threadId: string;
|
|
131
|
+
runId: string;
|
|
132
|
+
toolCallId: string;
|
|
133
|
+
toolCallName: string;
|
|
134
|
+
content?: undefined;
|
|
135
|
+
messageId?: undefined;
|
|
136
|
+
role?: undefined;
|
|
137
|
+
delta?: undefined;
|
|
138
|
+
} | {
|
|
139
|
+
type: EventType;
|
|
140
|
+
threadId: string;
|
|
141
|
+
runId: string;
|
|
142
|
+
toolCallId: string;
|
|
143
|
+
delta: string;
|
|
144
|
+
content?: undefined;
|
|
145
|
+
messageId?: undefined;
|
|
146
|
+
role?: undefined;
|
|
147
|
+
toolCallName?: undefined;
|
|
148
|
+
}, void, unknown>;
|
|
149
|
+
|
|
150
|
+
declare function createChatHistory({ tcbClient, chatHistoryEntity, }: {
|
|
151
|
+
tcbClient: tcb.CloudBase;
|
|
152
|
+
chatHistoryEntity: ChatHistoryEntity;
|
|
153
|
+
}): Promise<string | undefined>;
|
|
154
|
+
declare function updateChatHistoryByRecordId({ tcbClient, recordId, chatHistoryEntity, }: {
|
|
155
|
+
tcbClient: tcb.CloudBase;
|
|
156
|
+
recordId: string;
|
|
157
|
+
chatHistoryEntity: ChatHistoryEntity;
|
|
158
|
+
}): Promise<string | undefined>;
|
|
159
|
+
declare function describeChatHistory({ tcbClient, botId, sort, pageSize, pageNumber, conversation, startCreatedAt, triggerSrc, }: {
|
|
160
|
+
tcbClient: tcb.CloudBase;
|
|
161
|
+
botId: string;
|
|
162
|
+
sort: "asc" | "desc";
|
|
163
|
+
pageSize?: number;
|
|
164
|
+
pageNumber?: number;
|
|
165
|
+
conversation?: string;
|
|
166
|
+
startCreatedAt?: number;
|
|
167
|
+
triggerSrc?: string;
|
|
168
|
+
}): Promise<[ChatHistoryEntity[], number]>;
|
|
169
|
+
declare function transDataToChatEntity(item: ChatHistoryData): ChatHistoryEntity;
|
|
170
|
+
declare function queryForLLM({ tcbClient, botId, pageSize, startCreatedAt, triggerSrc, }: {
|
|
171
|
+
tcbClient: tcb.CloudBase;
|
|
172
|
+
botId: string;
|
|
173
|
+
pageSize?: number;
|
|
174
|
+
startCreatedAt?: number;
|
|
175
|
+
triggerSrc?: string;
|
|
176
|
+
}): Promise<{
|
|
177
|
+
role: string;
|
|
178
|
+
content: string;
|
|
179
|
+
}[]>;
|
|
180
|
+
interface ChatHistoryData {
|
|
181
|
+
bot_id: string;
|
|
182
|
+
record_id: string;
|
|
183
|
+
role: string;
|
|
184
|
+
status: string;
|
|
185
|
+
content: string;
|
|
186
|
+
sender: string;
|
|
187
|
+
conversation: string;
|
|
188
|
+
type: string;
|
|
189
|
+
trigger_src: string;
|
|
190
|
+
origin_msg: string;
|
|
191
|
+
reply_to: string;
|
|
192
|
+
reply: string;
|
|
193
|
+
trace_id: string;
|
|
194
|
+
need_async_reply: boolean;
|
|
195
|
+
async_reply: string;
|
|
196
|
+
createdAt: number;
|
|
197
|
+
updatedAt: number;
|
|
198
|
+
}
|
|
199
|
+
declare class ChatHistoryEntity {
|
|
200
|
+
id: number;
|
|
201
|
+
botId: string;
|
|
202
|
+
recordId: string;
|
|
203
|
+
role: string;
|
|
204
|
+
content: string;
|
|
205
|
+
recommendQuestions: string[];
|
|
206
|
+
sender: string;
|
|
207
|
+
conversation: string;
|
|
208
|
+
type: string;
|
|
209
|
+
/**
|
|
210
|
+
* 消息状态,pending done error cancel
|
|
211
|
+
*/
|
|
212
|
+
status: string;
|
|
213
|
+
image: string;
|
|
214
|
+
triggerSrc: string;
|
|
215
|
+
originMsg: string;
|
|
216
|
+
replyTo: string;
|
|
217
|
+
reply: string;
|
|
218
|
+
traceId: string;
|
|
219
|
+
needAsyncReply: boolean;
|
|
220
|
+
asyncReply: string;
|
|
221
|
+
createTime: string;
|
|
222
|
+
updateTime: string;
|
|
223
|
+
createdAt: number;
|
|
224
|
+
updatedAt: number;
|
|
225
|
+
event: string;
|
|
226
|
+
}
|
|
48
227
|
|
|
49
|
-
export { type ChatMessage, YuanqiAgent, type YuanqiChatRequest, type YuanqiConfig,
|
|
228
|
+
export { type ChatHistoryData, ChatHistoryEntity, type ChatMessage, type Delta, type StreamContext, type StreamState, YuanqiAgent, YuanqiAgentError, type YuanqiChatRequest, type YuanqiConfig, convertMessagesToOpenAI, createChatHistory, describeChatHistory, processYuanqiStream, queryForLLM, transDataToChatEntity, updateChatHistoryByRecordId };
|