@vectorx/agent-runtime 0.0.0-beta-20251225064112 → 0.0.0-beta-20251227042256
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/agent.d.ts +6 -2
- package/lib/agent.js +104 -20
- package/package.json +3 -3
package/lib/agent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AI, type models } from "@vectorx/ai-sdk";
|
|
1
|
+
import { type AI, models as aiModels, type models } from "@vectorx/ai-sdk";
|
|
2
2
|
import { type RcbContext } from "@vectorx/functions-framework";
|
|
3
3
|
import type { CreateRecordPairResponse, GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesResponse, KnowledgeBaseRetrieveResponse, QueryTasksResponse, UploadFileResponse } from "./agent-types";
|
|
4
4
|
import { type CreateRecordPairParams, type GetHistoryMessagesParams, type KnowledgeSearchInput } from "./schema";
|
|
@@ -24,12 +24,16 @@ export declare class AgentRuntime {
|
|
|
24
24
|
protected ai: AI;
|
|
25
25
|
protected request: RcbContext["request"];
|
|
26
26
|
protected logger: RcbContext["logger"];
|
|
27
|
+
private currentModelName?;
|
|
27
28
|
get agentTag(): string;
|
|
28
29
|
get agentId(): string;
|
|
29
30
|
get version(): string;
|
|
30
31
|
constructor(context: RcbContext);
|
|
32
|
+
private isModelRequest;
|
|
33
|
+
private getModelNameFromUrl;
|
|
34
|
+
private updateModelApmData;
|
|
31
35
|
private createLoggedRequest;
|
|
32
|
-
protected createModel(modelName: models.ModelName):
|
|
36
|
+
protected createModel(modelName: models.ModelName): aiModels.ReActModel;
|
|
33
37
|
protected createRecordPair(params: CreateRecordPairParams): Promise<CreateRecordPairResponse>;
|
|
34
38
|
protected getHistoryMessages(params: GetHistoryMessagesParams): Promise<GetHistoryMessagesResponse>;
|
|
35
39
|
protected getConversations(): Promise<GetConversationsResponse>;
|
package/lib/agent.js
CHANGED
|
@@ -97,12 +97,65 @@ class AgentRuntime {
|
|
|
97
97
|
env: ai_sdk_1.AiSdkEnv.Cloud,
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
isModelRequest(url) {
|
|
101
|
+
if (!url)
|
|
102
|
+
return false;
|
|
103
|
+
return ai_sdk_1.models.isModelRequestUrl(url);
|
|
104
|
+
}
|
|
105
|
+
getModelNameFromUrl(url) {
|
|
106
|
+
if (!url)
|
|
107
|
+
return undefined;
|
|
108
|
+
try {
|
|
109
|
+
const urlObj = new URL(url);
|
|
110
|
+
const fullPath = urlObj.pathname;
|
|
111
|
+
for (const [modelName, { domain, paths }] of ai_sdk_1.models.MODEL_REQUEST_PATTERNS) {
|
|
112
|
+
if (domain !== "*" && urlObj.origin !== domain) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
for (const path of paths) {
|
|
116
|
+
if (fullPath.includes(path) || fullPath.endsWith(path)) {
|
|
117
|
+
return modelName;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
catch (_a) {
|
|
124
|
+
for (const [modelName, { paths }] of ai_sdk_1.models.MODEL_REQUEST_PATTERNS) {
|
|
125
|
+
for (const path of paths) {
|
|
126
|
+
if (url.includes(path)) {
|
|
127
|
+
return modelName;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
updateModelApmData(url, statusCode, rt) {
|
|
135
|
+
if (!this.isModelRequest(url))
|
|
136
|
+
return;
|
|
137
|
+
const modelName = this.currentModelName || this.getModelNameFromUrl(url);
|
|
138
|
+
const updates = {
|
|
139
|
+
kit_model_service_url: url,
|
|
140
|
+
};
|
|
141
|
+
if (modelName) {
|
|
142
|
+
updates.kit_model_name = modelName;
|
|
143
|
+
}
|
|
144
|
+
if (statusCode !== undefined) {
|
|
145
|
+
updates.kit_model_status_code = statusCode;
|
|
146
|
+
}
|
|
147
|
+
if (rt !== undefined && rt > 0) {
|
|
148
|
+
updates.kit_model_rt = rt;
|
|
149
|
+
}
|
|
150
|
+
(0, functions_framework_1.updateApmMeasurementData)(updates);
|
|
151
|
+
}
|
|
100
152
|
createLoggedRequest(originalRequest, logger) {
|
|
101
153
|
return {
|
|
102
154
|
get: (options) => __awaiter(this, void 0, void 0, function* () {
|
|
103
155
|
const startTime = Date.now();
|
|
104
156
|
const requestStartLog = safeJsonStringify({
|
|
105
|
-
type:
|
|
157
|
+
type: AgentEventType.FRAMEWORK_EVENT,
|
|
158
|
+
scene: AgentType.AI_SDK_REQUEST_START,
|
|
106
159
|
method: "GET",
|
|
107
160
|
url: options.url,
|
|
108
161
|
headers: options.headers,
|
|
@@ -113,12 +166,14 @@ class AgentRuntime {
|
|
|
113
166
|
logger.logAccesslog(functions_framework_1.LogLevel.INFO, requestStartLog);
|
|
114
167
|
try {
|
|
115
168
|
const response = yield originalRequest.get(options);
|
|
169
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
116
170
|
const requestSuccessLog = safeJsonStringify({
|
|
117
|
-
type:
|
|
171
|
+
type: AgentEventType.FRAMEWORK_EVENT,
|
|
172
|
+
scene: AgentType.AI_SDK_REQUEST_SUCCESS,
|
|
118
173
|
method: "GET",
|
|
119
174
|
url: options.url,
|
|
120
175
|
status: response.statusCode,
|
|
121
|
-
duration:
|
|
176
|
+
duration: duration,
|
|
122
177
|
eventId: this.context.eventID,
|
|
123
178
|
timestamp: new Date().toISOString(),
|
|
124
179
|
});
|
|
@@ -126,13 +181,15 @@ class AgentRuntime {
|
|
|
126
181
|
return response;
|
|
127
182
|
}
|
|
128
183
|
catch (error) {
|
|
184
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
129
185
|
const requestErrorLog = safeJsonStringify({
|
|
130
|
-
type:
|
|
186
|
+
type: AgentEventType.FRAMEWORK_EVENT,
|
|
187
|
+
scene: AgentType.AI_SDK_REQUEST_ERROR,
|
|
131
188
|
method: "GET",
|
|
132
189
|
url: options.url,
|
|
133
190
|
error: error instanceof Error ? error.message : "请求失败",
|
|
134
191
|
stack: error instanceof Error ? error.stack : undefined,
|
|
135
|
-
duration:
|
|
192
|
+
duration: duration,
|
|
136
193
|
eventId: this.context.eventID,
|
|
137
194
|
timestamp: new Date().toISOString(),
|
|
138
195
|
});
|
|
@@ -155,13 +212,14 @@ class AgentRuntime {
|
|
|
155
212
|
logger.logAccesslog(functions_framework_1.LogLevel.INFO, requestStartLog);
|
|
156
213
|
try {
|
|
157
214
|
const response = yield originalRequest.post(options);
|
|
215
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
158
216
|
const requestSuccessLog = safeJsonStringify({
|
|
159
217
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
160
218
|
scene: AgentType.AI_SDK_REQUEST_SUCCESS,
|
|
161
219
|
method: "POST",
|
|
162
220
|
url: options.url,
|
|
163
221
|
status: response.statusCode,
|
|
164
|
-
duration:
|
|
222
|
+
duration: duration,
|
|
165
223
|
eventId: this.context.eventID,
|
|
166
224
|
timestamp: new Date().toISOString(),
|
|
167
225
|
});
|
|
@@ -169,6 +227,7 @@ class AgentRuntime {
|
|
|
169
227
|
return response;
|
|
170
228
|
}
|
|
171
229
|
catch (error) {
|
|
230
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
172
231
|
const requestErrorLog = safeJsonStringify({
|
|
173
232
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
174
233
|
scene: AgentType.AI_SDK_REQUEST_ERROR,
|
|
@@ -176,7 +235,7 @@ class AgentRuntime {
|
|
|
176
235
|
url: options.url,
|
|
177
236
|
error: error instanceof Error ? error.message : "请求失败",
|
|
178
237
|
stack: error instanceof Error ? error.stack : undefined,
|
|
179
|
-
duration:
|
|
238
|
+
duration: duration,
|
|
180
239
|
eventId: this.context.eventID,
|
|
181
240
|
timestamp: new Date().toISOString(),
|
|
182
241
|
});
|
|
@@ -199,13 +258,14 @@ class AgentRuntime {
|
|
|
199
258
|
logger.logAccesslog(functions_framework_1.LogLevel.INFO, requestStartLog);
|
|
200
259
|
try {
|
|
201
260
|
const response = yield originalRequest.put(options);
|
|
261
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
202
262
|
const requestSuccessLog = safeJsonStringify({
|
|
203
263
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
204
264
|
scene: AgentType.AI_SDK_REQUEST_SUCCESS,
|
|
205
265
|
method: "PUT",
|
|
206
266
|
url: options.url,
|
|
207
267
|
status: response.statusCode,
|
|
208
|
-
duration:
|
|
268
|
+
duration: duration,
|
|
209
269
|
eventId: this.context.eventID,
|
|
210
270
|
timestamp: new Date().toISOString(),
|
|
211
271
|
});
|
|
@@ -213,6 +273,7 @@ class AgentRuntime {
|
|
|
213
273
|
return response;
|
|
214
274
|
}
|
|
215
275
|
catch (error) {
|
|
276
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
216
277
|
const requestErrorLog = safeJsonStringify({
|
|
217
278
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
218
279
|
scene: AgentType.AI_SDK_REQUEST_ERROR,
|
|
@@ -220,7 +281,7 @@ class AgentRuntime {
|
|
|
220
281
|
url: options.url,
|
|
221
282
|
error: error instanceof Error ? error.message : "请求失败",
|
|
222
283
|
stack: error instanceof Error ? error.stack : undefined,
|
|
223
|
-
duration:
|
|
284
|
+
duration: duration,
|
|
224
285
|
eventId: this.context.eventID,
|
|
225
286
|
timestamp: new Date().toISOString(),
|
|
226
287
|
});
|
|
@@ -242,13 +303,14 @@ class AgentRuntime {
|
|
|
242
303
|
logger.logAccesslog(functions_framework_1.LogLevel.INFO, requestStartLog);
|
|
243
304
|
try {
|
|
244
305
|
const response = yield originalRequest.upload(options);
|
|
306
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
245
307
|
const requestSuccessLog = safeJsonStringify({
|
|
246
308
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
247
309
|
scene: AgentType.AI_SDK_REQUEST_SUCCESS,
|
|
248
310
|
method: "UPLOAD",
|
|
249
311
|
url: options.url,
|
|
250
312
|
status: response.statusCode,
|
|
251
|
-
duration:
|
|
313
|
+
duration: duration,
|
|
252
314
|
eventId: this.context.eventID,
|
|
253
315
|
timestamp: new Date().toISOString(),
|
|
254
316
|
});
|
|
@@ -256,6 +318,7 @@ class AgentRuntime {
|
|
|
256
318
|
return response;
|
|
257
319
|
}
|
|
258
320
|
catch (error) {
|
|
321
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
259
322
|
const requestErrorLog = safeJsonStringify({
|
|
260
323
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
261
324
|
scene: AgentType.AI_SDK_REQUEST_ERROR,
|
|
@@ -263,7 +326,7 @@ class AgentRuntime {
|
|
|
263
326
|
url: options.url,
|
|
264
327
|
error: error instanceof Error ? error.message : "请求失败",
|
|
265
328
|
stack: error instanceof Error ? error.stack : undefined,
|
|
266
|
-
duration:
|
|
329
|
+
duration: duration,
|
|
267
330
|
eventId: this.context.eventID,
|
|
268
331
|
timestamp: new Date().toISOString(),
|
|
269
332
|
});
|
|
@@ -285,12 +348,15 @@ class AgentRuntime {
|
|
|
285
348
|
logger.logAccesslog(functions_framework_1.LogLevel.INFO, requestStartLog);
|
|
286
349
|
try {
|
|
287
350
|
const response = yield originalRequest.download(options);
|
|
351
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
352
|
+
const statusCode = response === null || response === void 0 ? void 0 : response.statusCode;
|
|
288
353
|
const requestSuccessLog = safeJsonStringify({
|
|
289
354
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
290
355
|
scene: AgentType.AI_SDK_REQUEST_SUCCESS,
|
|
291
356
|
method: "DOWNLOAD",
|
|
292
357
|
url: options.url,
|
|
293
|
-
|
|
358
|
+
status: statusCode,
|
|
359
|
+
duration: duration,
|
|
294
360
|
eventId: this.context.eventID,
|
|
295
361
|
timestamp: new Date().toISOString(),
|
|
296
362
|
});
|
|
@@ -298,6 +364,7 @@ class AgentRuntime {
|
|
|
298
364
|
return response;
|
|
299
365
|
}
|
|
300
366
|
catch (error) {
|
|
367
|
+
const duration = `${Date.now() - startTime}ms`;
|
|
301
368
|
const requestErrorLog = safeJsonStringify({
|
|
302
369
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
303
370
|
scene: AgentType.AI_SDK_REQUEST_ERROR,
|
|
@@ -305,7 +372,7 @@ class AgentRuntime {
|
|
|
305
372
|
url: options.url,
|
|
306
373
|
error: error instanceof Error ? error.message : "请求失败",
|
|
307
374
|
stack: error instanceof Error ? error.stack : undefined,
|
|
308
|
-
duration:
|
|
375
|
+
duration: duration,
|
|
309
376
|
eventId: this.context.eventID,
|
|
310
377
|
timestamp: new Date().toISOString(),
|
|
311
378
|
});
|
|
@@ -328,20 +395,33 @@ class AgentRuntime {
|
|
|
328
395
|
logger.logAccesslog(functions_framework_1.LogLevel.INFO, requestStartLog);
|
|
329
396
|
try {
|
|
330
397
|
const response = yield originalRequest.fetch(options);
|
|
331
|
-
const
|
|
398
|
+
const rt = Date.now() - startTime;
|
|
399
|
+
const duration = `${rt}ms`;
|
|
400
|
+
const isSuccess = (response === null || response === void 0 ? void 0 : response.statusCode) >= 200 && (response === null || response === void 0 ? void 0 : response.statusCode) < 300;
|
|
401
|
+
const logData = {
|
|
332
402
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
333
|
-
scene: AgentType.AI_SDK_REQUEST_SUCCESS,
|
|
403
|
+
scene: isSuccess ? AgentType.AI_SDK_REQUEST_SUCCESS : AgentType.AI_SDK_REQUEST_ERROR,
|
|
334
404
|
method: "FETCH",
|
|
335
405
|
url: options.url,
|
|
336
|
-
|
|
337
|
-
duration: `${Date.now() - startTime}ms`,
|
|
406
|
+
duration: duration,
|
|
338
407
|
eventId: this.context.eventID,
|
|
339
408
|
timestamp: new Date().toISOString(),
|
|
340
|
-
}
|
|
341
|
-
|
|
409
|
+
};
|
|
410
|
+
if (isSuccess) {
|
|
411
|
+
logData.status = response.statusCode;
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
logData.error = `Request failed with status code: ${response === null || response === void 0 ? void 0 : response.statusCode}`;
|
|
415
|
+
}
|
|
416
|
+
this.updateModelApmData(options.url, response === null || response === void 0 ? void 0 : response.statusCode, rt);
|
|
417
|
+
const requestLog = safeJsonStringify(logData);
|
|
418
|
+
logger.logAccesslog(isSuccess ? functions_framework_1.LogLevel.INFO : functions_framework_1.LogLevel.ERROR, requestLog);
|
|
342
419
|
return response;
|
|
343
420
|
}
|
|
344
421
|
catch (error) {
|
|
422
|
+
const rt = Date.now() - startTime;
|
|
423
|
+
const duration = `${rt}ms`;
|
|
424
|
+
this.updateModelApmData(options.url, undefined, rt);
|
|
345
425
|
const requestErrorLog = safeJsonStringify({
|
|
346
426
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
347
427
|
scene: AgentType.AI_SDK_REQUEST_ERROR,
|
|
@@ -349,7 +429,7 @@ class AgentRuntime {
|
|
|
349
429
|
url: options.url,
|
|
350
430
|
error: error instanceof Error ? error.message : "请求失败",
|
|
351
431
|
stack: error instanceof Error ? error.stack : undefined,
|
|
352
|
-
duration:
|
|
432
|
+
duration: duration,
|
|
353
433
|
eventId: this.context.eventID,
|
|
354
434
|
timestamp: new Date().toISOString(),
|
|
355
435
|
});
|
|
@@ -360,6 +440,10 @@ class AgentRuntime {
|
|
|
360
440
|
};
|
|
361
441
|
}
|
|
362
442
|
createModel(modelName) {
|
|
443
|
+
this.currentModelName = modelName;
|
|
444
|
+
(0, functions_framework_1.updateApmMeasurementData)({
|
|
445
|
+
kit_model_name: modelName,
|
|
446
|
+
});
|
|
363
447
|
const createModelLog = safeJsonStringify({
|
|
364
448
|
type: AgentEventType.FRAMEWORK_EVENT,
|
|
365
449
|
scene: AgentType.AI_SDK_CREATE_MODEL,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorx/agent-runtime",
|
|
3
|
-
"version": "0.0.0-beta-
|
|
3
|
+
"version": "0.0.0-beta-20251227042256",
|
|
4
4
|
"description": "Cloud AI agent runtime",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"node": ">=18.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@vectorx/ai-sdk": "0.0.0-beta-
|
|
24
|
-
"@vectorx/functions-framework": "0.0.0-beta-
|
|
23
|
+
"@vectorx/ai-sdk": "0.0.0-beta-20251227042256",
|
|
24
|
+
"@vectorx/functions-framework": "0.0.0-beta-20251227042256",
|
|
25
25
|
"form-data": "^4.0.0",
|
|
26
26
|
"langfuse": "^3.38.4",
|
|
27
27
|
"query-string": "^6.14.1",
|