@cloudbase/agent-adapter-adp 0.0.15 → 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 +53 -0
- package/dist/index.d.mts +39 -5
- package/dist/index.d.ts +39 -5
- package/dist/index.js +338 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -8
- package/CHANGELOG.md +0 -48
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ npm install @cloudbase/agent-agents @cloudbase/agent-adapter-adp
|
|
|
15
15
|
- **Thinking Events**: Support for thinking/reasoning process events from the model
|
|
16
16
|
- **Workflow Integration**: Support for ADP workflows with tool call events
|
|
17
17
|
- **Custom Variables**: Pass custom parameters to workflows and knowledge base
|
|
18
|
+
- **File Upload**: Upload images and documents to COS for multimodal conversations (**requires `enableUpload: true`**)
|
|
18
19
|
|
|
19
20
|
## Environment Variables
|
|
20
21
|
|
|
@@ -121,6 +122,55 @@ observable.subscribe({
|
|
|
121
122
|
});
|
|
122
123
|
```
|
|
123
124
|
|
|
125
|
+
### With File Upload (Images and Documents)
|
|
126
|
+
|
|
127
|
+
When `enableUpload` is **set to `true`**, you can send images and documents in messages. Files are automatically uploaded to Tencent Cloud COS and processed by ADP.
|
|
128
|
+
|
|
129
|
+
**Note:** File upload requires Tencent Cloud credentials (`TENCENTCLOUD_SECRETID` and `TENCENTCLOUD_SECRETKEY`).
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { AdpAgent } from "@cloudbase/agent-adapter-adp";
|
|
133
|
+
import { randomUUID } from "crypto";
|
|
134
|
+
import * as fs from "fs";
|
|
135
|
+
|
|
136
|
+
const agent = new AdpAgent({
|
|
137
|
+
name: "my-adp-agent",
|
|
138
|
+
adpConfig: {
|
|
139
|
+
appKey: "your-app-key",
|
|
140
|
+
enableUpload: true, // Enable file upload
|
|
141
|
+
credential: {
|
|
142
|
+
secretId: "your-secret-id",
|
|
143
|
+
secretKey: "your-secret-key",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const observable = agent.run({
|
|
149
|
+
runId: randomUUID(),
|
|
150
|
+
threadId: randomUUID(),
|
|
151
|
+
messages: [
|
|
152
|
+
{
|
|
153
|
+
id: randomUUID(),
|
|
154
|
+
role: "user",
|
|
155
|
+
content: [
|
|
156
|
+
{ type: "text", text: "What's in this image?" },
|
|
157
|
+
{
|
|
158
|
+
type: "binary",
|
|
159
|
+
mimeType: "image/png",
|
|
160
|
+
filename: "screenshot.png",
|
|
161
|
+
data: fs.readFileSync("./screenshot.png"),
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Supported file types:**
|
|
170
|
+
|
|
171
|
+
- **Images**: `image/png`, `image/jpeg`, `image/bmp`
|
|
172
|
+
- **Documents**: `application/pdf`, `application/msword`, `application/vnd.openxmlformats-officedocument.wordprocessingml.document`, `application/vnd.ms-powerpoint`, `application/vnd.openxmlformats-officedocument.presentationml.presentation`, `text/plain`
|
|
173
|
+
|
|
124
174
|
## API Reference
|
|
125
175
|
|
|
126
176
|
### AdpAgent
|
|
@@ -146,9 +196,11 @@ interface AdpConfig {
|
|
|
146
196
|
token?: string; // Session token (optional if TENCENTCLOUD_SESSIONTOKEN env is set)
|
|
147
197
|
};
|
|
148
198
|
historyCount?: number; // Number of history messages to retrieve (reserved)
|
|
199
|
+
enableUpload?: boolean; // Enable file upload for images and documents (default: false)
|
|
149
200
|
request?: {
|
|
150
201
|
baseUrl?: string; // Base URL for ADP API (default: https://wss.lke.cloud.tencent.com)
|
|
151
202
|
endpoint?: string; // API endpoint (default: /v1/qbot/chat/sse)
|
|
203
|
+
docParseEndpoint?: string; // Document parse API endpoint (default: /v1/qbot/chat/docParse)
|
|
152
204
|
body?: Partial<AdpChatRequest>; // Additional request body options
|
|
153
205
|
};
|
|
154
206
|
}
|
|
@@ -187,6 +239,7 @@ The adapter emits the following AG-UI events:
|
|
|
187
239
|
- `axios`: HTTP client for API requests
|
|
188
240
|
- `rxjs`: Reactive extensions for JavaScript
|
|
189
241
|
- `tencentcloud-sdk-nodejs-lke`: Tencent Cloud LKE SDK
|
|
242
|
+
- `cos-nodejs-sdk-v5`: Tencent Cloud COS SDK (for file upload)
|
|
190
243
|
|
|
191
244
|
## Related Resources
|
|
192
245
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractAgent, AgentConfig, RunAgentInput, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
import { lke } from 'tencentcloud-sdk-nodejs-lke';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 文件信息
|
|
@@ -58,8 +59,10 @@ type AdpConfig = {
|
|
|
58
59
|
baseUrl?: string;
|
|
59
60
|
endpoint?: string;
|
|
60
61
|
body?: Partial<AdpChatRequest>;
|
|
62
|
+
docParseEndpoint?: string;
|
|
61
63
|
};
|
|
62
64
|
historyCount?: number;
|
|
65
|
+
enableUpload?: boolean;
|
|
63
66
|
appKey?: string;
|
|
64
67
|
credential?: {
|
|
65
68
|
secretId?: string;
|
|
@@ -244,24 +247,51 @@ interface ThoughtProcedure {
|
|
|
244
247
|
interface Debugging {
|
|
245
248
|
content: string;
|
|
246
249
|
}
|
|
250
|
+
interface DocumentParseRequest {
|
|
251
|
+
sessionId: string;
|
|
252
|
+
botAppKey: string;
|
|
253
|
+
requestId: string;
|
|
254
|
+
cosBucket: string;
|
|
255
|
+
fileType: string;
|
|
256
|
+
fileName: string;
|
|
257
|
+
cosUrl: string;
|
|
258
|
+
cosHash: string;
|
|
259
|
+
eTag: string;
|
|
260
|
+
size: string;
|
|
261
|
+
}
|
|
262
|
+
interface DocumentParseChunk {
|
|
263
|
+
type: "parsing";
|
|
264
|
+
payload: ParsingEvent;
|
|
265
|
+
}
|
|
266
|
+
interface ParsingEvent {
|
|
267
|
+
session_id: string;
|
|
268
|
+
trace_id: string;
|
|
269
|
+
is_final: boolean;
|
|
270
|
+
doc_id: string;
|
|
271
|
+
process: number;
|
|
272
|
+
status: string;
|
|
273
|
+
timestamp: number;
|
|
274
|
+
error_message: string;
|
|
275
|
+
}
|
|
247
276
|
|
|
248
277
|
declare class AdpAgentError extends Error {
|
|
249
278
|
code?: string;
|
|
250
279
|
constructor(message: string, code?: string);
|
|
251
280
|
}
|
|
281
|
+
type CosParams = Awaited<ReturnType<typeof lke.v20231130.Client.prototype.DescribeStorageCredential>>;
|
|
252
282
|
declare class AdpAgent extends AbstractAgent {
|
|
253
283
|
private reqAppClient;
|
|
254
284
|
private reqLkeClient;
|
|
255
285
|
protected adpConfig: AdpConfig;
|
|
286
|
+
private finalAppKey;
|
|
287
|
+
private finalCloudCredential;
|
|
256
288
|
constructor(config: AgentConfig & {
|
|
257
289
|
adpConfig: AdpConfig;
|
|
258
290
|
});
|
|
259
|
-
generateRequestBody({ message, fileInfos,
|
|
291
|
+
generateRequestBody({ message, fileInfos, input, }: {
|
|
260
292
|
message: string;
|
|
261
293
|
fileInfos: FileInfo[];
|
|
262
|
-
|
|
263
|
-
threadId: string;
|
|
264
|
-
forwardedProps: Record<string, string>;
|
|
294
|
+
input: RunAgentInput;
|
|
265
295
|
}): AdpChatRequest;
|
|
266
296
|
run(input: RunAgentInput): Observable<{
|
|
267
297
|
type: EventType;
|
|
@@ -269,6 +299,10 @@ declare class AdpAgent extends AbstractAgent {
|
|
|
269
299
|
rawEvent?: any;
|
|
270
300
|
}>;
|
|
271
301
|
private _run;
|
|
302
|
+
private convertAGUIMessagesToAdpMessages;
|
|
303
|
+
private extractDocuments;
|
|
304
|
+
private getCosParams;
|
|
305
|
+
private uploadToCos;
|
|
272
306
|
}
|
|
273
307
|
|
|
274
|
-
export { AdpAgent, AdpAgentError, type AdpChatRequest, type AdpChunk, type AdpConfig, type CurrentNode, CurrentNodeStatus, type Debugging, type ErrorInfo, type FileInfo, type Knowledge, type QuoteInfo, type Reference, type ReferenceEvent, type ReplyEvent, ReplyMethod, type StatisticInfo, type TaskFlow, type ThoughtEvent, type ThoughtProcedure, type TokenStatEvent, type TokenStatProcedure, type WorkFlow };
|
|
308
|
+
export { AdpAgent, AdpAgentError, type AdpChatRequest, type AdpChunk, type AdpConfig, type CosParams, type CurrentNode, CurrentNodeStatus, type Debugging, type DocumentParseChunk, type DocumentParseRequest, type ErrorInfo, type FileInfo, type Knowledge, type ParsingEvent, type QuoteInfo, type Reference, type ReferenceEvent, type ReplyEvent, ReplyMethod, type StatisticInfo, type TaskFlow, type ThoughtEvent, type ThoughtProcedure, type TokenStatEvent, type TokenStatProcedure, type WorkFlow };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractAgent, AgentConfig, RunAgentInput, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
import { lke } from 'tencentcloud-sdk-nodejs-lke';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 文件信息
|
|
@@ -58,8 +59,10 @@ type AdpConfig = {
|
|
|
58
59
|
baseUrl?: string;
|
|
59
60
|
endpoint?: string;
|
|
60
61
|
body?: Partial<AdpChatRequest>;
|
|
62
|
+
docParseEndpoint?: string;
|
|
61
63
|
};
|
|
62
64
|
historyCount?: number;
|
|
65
|
+
enableUpload?: boolean;
|
|
63
66
|
appKey?: string;
|
|
64
67
|
credential?: {
|
|
65
68
|
secretId?: string;
|
|
@@ -244,24 +247,51 @@ interface ThoughtProcedure {
|
|
|
244
247
|
interface Debugging {
|
|
245
248
|
content: string;
|
|
246
249
|
}
|
|
250
|
+
interface DocumentParseRequest {
|
|
251
|
+
sessionId: string;
|
|
252
|
+
botAppKey: string;
|
|
253
|
+
requestId: string;
|
|
254
|
+
cosBucket: string;
|
|
255
|
+
fileType: string;
|
|
256
|
+
fileName: string;
|
|
257
|
+
cosUrl: string;
|
|
258
|
+
cosHash: string;
|
|
259
|
+
eTag: string;
|
|
260
|
+
size: string;
|
|
261
|
+
}
|
|
262
|
+
interface DocumentParseChunk {
|
|
263
|
+
type: "parsing";
|
|
264
|
+
payload: ParsingEvent;
|
|
265
|
+
}
|
|
266
|
+
interface ParsingEvent {
|
|
267
|
+
session_id: string;
|
|
268
|
+
trace_id: string;
|
|
269
|
+
is_final: boolean;
|
|
270
|
+
doc_id: string;
|
|
271
|
+
process: number;
|
|
272
|
+
status: string;
|
|
273
|
+
timestamp: number;
|
|
274
|
+
error_message: string;
|
|
275
|
+
}
|
|
247
276
|
|
|
248
277
|
declare class AdpAgentError extends Error {
|
|
249
278
|
code?: string;
|
|
250
279
|
constructor(message: string, code?: string);
|
|
251
280
|
}
|
|
281
|
+
type CosParams = Awaited<ReturnType<typeof lke.v20231130.Client.prototype.DescribeStorageCredential>>;
|
|
252
282
|
declare class AdpAgent extends AbstractAgent {
|
|
253
283
|
private reqAppClient;
|
|
254
284
|
private reqLkeClient;
|
|
255
285
|
protected adpConfig: AdpConfig;
|
|
286
|
+
private finalAppKey;
|
|
287
|
+
private finalCloudCredential;
|
|
256
288
|
constructor(config: AgentConfig & {
|
|
257
289
|
adpConfig: AdpConfig;
|
|
258
290
|
});
|
|
259
|
-
generateRequestBody({ message, fileInfos,
|
|
291
|
+
generateRequestBody({ message, fileInfos, input, }: {
|
|
260
292
|
message: string;
|
|
261
293
|
fileInfos: FileInfo[];
|
|
262
|
-
|
|
263
|
-
threadId: string;
|
|
264
|
-
forwardedProps: Record<string, string>;
|
|
294
|
+
input: RunAgentInput;
|
|
265
295
|
}): AdpChatRequest;
|
|
266
296
|
run(input: RunAgentInput): Observable<{
|
|
267
297
|
type: EventType;
|
|
@@ -269,6 +299,10 @@ declare class AdpAgent extends AbstractAgent {
|
|
|
269
299
|
rawEvent?: any;
|
|
270
300
|
}>;
|
|
271
301
|
private _run;
|
|
302
|
+
private convertAGUIMessagesToAdpMessages;
|
|
303
|
+
private extractDocuments;
|
|
304
|
+
private getCosParams;
|
|
305
|
+
private uploadToCos;
|
|
272
306
|
}
|
|
273
307
|
|
|
274
|
-
export { AdpAgent, AdpAgentError, type AdpChatRequest, type AdpChunk, type AdpConfig, type CurrentNode, CurrentNodeStatus, type Debugging, type ErrorInfo, type FileInfo, type Knowledge, type QuoteInfo, type Reference, type ReferenceEvent, type ReplyEvent, ReplyMethod, type StatisticInfo, type TaskFlow, type ThoughtEvent, type ThoughtProcedure, type TokenStatEvent, type TokenStatProcedure, type WorkFlow };
|
|
308
|
+
export { AdpAgent, AdpAgentError, type AdpChatRequest, type AdpChunk, type AdpConfig, type CosParams, type CurrentNode, CurrentNodeStatus, type Debugging, type DocumentParseChunk, type DocumentParseRequest, type ErrorInfo, type FileInfo, type Knowledge, type ParsingEvent, type QuoteInfo, type Reference, type ReferenceEvent, type ReplyEvent, ReplyMethod, type StatisticInfo, type TaskFlow, type ThoughtEvent, type ThoughtProcedure, type TokenStatEvent, type TokenStatProcedure, type WorkFlow };
|