aicodeswitch 5.2.10 → 5.2.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/bin/utils/managed-fields.js +2 -0
- package/dist/server/config-managed-fields.js +2 -0
- package/dist/server/conversions/pairs/responses-claude/response.js +5 -21
- package/dist/server/conversions/pairs/responses-claude/streaming.js +18 -20
- package/dist/server/conversions/pairs/responses-completions/response.js +2 -9
- package/dist/server/conversions/pairs/responses-completions/streaming.js +3 -10
- package/dist/server/conversions/utils/usage.js +28 -8
- package/dist/server/fs-database.js +3 -3
- package/dist/server/main.js +96 -4
- package/dist/server/performance-tracker.js +377 -0
- package/dist/server/proxy-server.js +82 -18
- package/dist/server/rules-status-service.js +21 -6
- package/dist/server/transformers/stream-timing-transform.js +63 -0
- package/dist/ui/assets/index-BFVjD9Y2.js +799 -0
- package/dist/ui/assets/index-Dm34-4zP.css +1 -0
- package/dist/ui/index.html +2 -2
- package/package.json +1 -1
- package/dist/ui/assets/index-MjMlew6J.css +0 -1
- package/dist/ui/assets/index-NlzYhf99.js +0 -799
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamTimingTransform = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
/**
|
|
6
|
+
* StreamTimingTransform - 流式打点 Transform(服务性能统计专用)
|
|
7
|
+
*
|
|
8
|
+
* 透传所有数据(对象模式 / Buffer / string 均可),仅记录:
|
|
9
|
+
* - firstEventAt:首个被解析出的 SSE 事件流经本 Transform 的时刻(≈ 首 Token 返回时刻)
|
|
10
|
+
* - lastEventAt:最后一个事件流经的时刻(≈ 整个返回结束时刻)
|
|
11
|
+
*
|
|
12
|
+
* 由调用方在转发开始前注入 startTime(请求发起时刻),即可派生:
|
|
13
|
+
* - ttftMs = firstEventAt - startTime
|
|
14
|
+
* - generationMs = lastEventAt - firstEventAt
|
|
15
|
+
*
|
|
16
|
+
* 该 Transform 仅做时间记录,不修改任何数据内容,对转发链路零影响。
|
|
17
|
+
*/
|
|
18
|
+
class StreamTimingTransform extends stream_1.Transform {
|
|
19
|
+
constructor(startTime) {
|
|
20
|
+
super({ writableObjectMode: true, readableObjectMode: true });
|
|
21
|
+
/** 请求发起时刻(由外部注入) */
|
|
22
|
+
Object.defineProperty(this, "startTime", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
/** 首个事件到达时刻(未收到则为 0) */
|
|
29
|
+
Object.defineProperty(this, "firstEventAt", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: 0
|
|
34
|
+
});
|
|
35
|
+
/** 最后一个事件到达时刻 */
|
|
36
|
+
Object.defineProperty(this, "lastEventAt", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: 0
|
|
41
|
+
});
|
|
42
|
+
this.startTime = startTime;
|
|
43
|
+
}
|
|
44
|
+
_transform(chunk, _encoding, callback) {
|
|
45
|
+
try {
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
if (this.firstEventAt === 0) {
|
|
48
|
+
this.firstEventAt = now;
|
|
49
|
+
}
|
|
50
|
+
this.lastEventAt = now;
|
|
51
|
+
this.push(chunk);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('[StreamTimingTransform] Error in _transform:', error);
|
|
55
|
+
}
|
|
56
|
+
callback();
|
|
57
|
+
}
|
|
58
|
+
/** 是否采集到至少一个事件(用于判定精确口径可用性) */
|
|
59
|
+
hasTiming() {
|
|
60
|
+
return this.firstEventAt > 0 && this.lastEventAt > 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.StreamTimingTransform = StreamTimingTransform;
|