@blade-hq/agent-client 2610.0.2 → 2610.0.3-beta.1
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/dist/chunk-BSPBHCYP.js +19 -0
- package/dist/chunk-BSPBHCYP.js.map +1 -0
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +9 -0
- package/dist/internal.js.map +1 -0
- package/dist/server-clock.d.ts +2 -0
- package/dist/types/socket-events.d.ts +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/server-clock.ts
|
|
2
|
+
var clocks = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function syncServerTime(client, timestamp, receivedAt = performance.now()) {
|
|
4
|
+
if (typeof timestamp !== "string") return;
|
|
5
|
+
const serverTime = Date.parse(timestamp);
|
|
6
|
+
if (!Number.isFinite(serverTime)) return;
|
|
7
|
+
const current = getServerTime(client, receivedAt);
|
|
8
|
+
clocks.set(client, { serverTime: Math.max(serverTime, current ?? serverTime), receivedAt });
|
|
9
|
+
}
|
|
10
|
+
function getServerTime(client, now = performance.now()) {
|
|
11
|
+
const clock = client ? clocks.get(client) : void 0;
|
|
12
|
+
return clock ? clock.serverTime + Math.max(0, now - clock.receivedAt) : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
syncServerTime,
|
|
17
|
+
getServerTime
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-BSPBHCYP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server-clock.ts"],"sourcesContent":["// Clocks are scoped to the client, so connections to different servers stay independent.\nconst clocks = new WeakMap<object, { serverTime: number; receivedAt: number }>()\n\nexport function syncServerTime(client: object, timestamp: unknown, receivedAt = performance.now()) {\n if (typeof timestamp !== \"string\") return\n const serverTime = Date.parse(timestamp)\n if (!Number.isFinite(serverTime)) return\n // A delayed sample must not move the already calibrated display clock backward.\n const current = getServerTime(client, receivedAt)\n clocks.set(client, { serverTime: Math.max(serverTime, current ?? serverTime), receivedAt })\n}\n\nexport function getServerTime(client: object | null, now = performance.now()): number | null {\n const clock = client ? clocks.get(client) : undefined\n return clock ? clock.serverTime + Math.max(0, now - clock.receivedAt) : null\n}\n"],"mappings":";AACA,IAAM,SAAS,oBAAI,QAA4D;AAExE,SAAS,eAAe,QAAgB,WAAoB,aAAa,YAAY,IAAI,GAAG;AACjG,MAAI,OAAO,cAAc,SAAU;AACnC,QAAM,aAAa,KAAK,MAAM,SAAS;AACvC,MAAI,CAAC,OAAO,SAAS,UAAU,EAAG;AAElC,QAAM,UAAU,cAAc,QAAQ,UAAU;AAChD,SAAO,IAAI,QAAQ,EAAE,YAAY,KAAK,IAAI,YAAY,WAAW,UAAU,GAAG,WAAW,CAAC;AAC5F;AAEO,SAAS,cAAc,QAAuB,MAAM,YAAY,IAAI,GAAkB;AAC3F,QAAM,QAAQ,SAAS,OAAO,IAAI,MAAM,IAAI;AAC5C,SAAO,QAAQ,MAAM,aAAa,KAAK,IAAI,GAAG,MAAM,MAAM,UAAU,IAAI;AAC1E;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
syncServerTime
|
|
3
|
+
} from "./chunk-BSPBHCYP.js";
|
|
4
|
+
|
|
1
5
|
// src/version.ts
|
|
2
6
|
var SDK_NAME = "agent-client";
|
|
3
|
-
var SDK_VERSION = true ? "2610.0.
|
|
7
|
+
var SDK_VERSION = true ? "2610.0.3-beta.1" : "1.1.1";
|
|
4
8
|
|
|
5
9
|
// src/auth-login.ts
|
|
6
10
|
function isAuthCallbackMessage(value) {
|
|
@@ -1115,8 +1119,8 @@ function snapshot(state, sequence, status) {
|
|
|
1115
1119
|
first_token_ms: state.firstTokenMs,
|
|
1116
1120
|
stream_duration_ms: state.streamDurationMs,
|
|
1117
1121
|
first_token_delivery_ms: state.firstTokenDeliveryMs,
|
|
1118
|
-
started_at: state.modelStartedAt
|
|
1119
|
-
//
|
|
1122
|
+
started_at: state.modelStartedAt,
|
|
1123
|
+
// 未上报时不伪造服务器起点;浏览器时钟不能与服务器时钟混用。
|
|
1120
1124
|
has_reported_timing: state.modelStartedAtReported,
|
|
1121
1125
|
context_window: state.contextWindow,
|
|
1122
1126
|
memory_refs: state.memoryRefs,
|
|
@@ -1824,6 +1828,7 @@ var ClientProjectionBuilder = class {
|
|
|
1824
1828
|
return this.syncPatch(state);
|
|
1825
1829
|
}
|
|
1826
1830
|
applyFirstTokenDelivery(state, payload) {
|
|
1831
|
+
this.applyStreamTiming(state, payload);
|
|
1827
1832
|
const firstTokenMs = payload.first_token_ms;
|
|
1828
1833
|
if (state.firstTokenMs === null && typeof firstTokenMs === "number" && firstTokenMs >= 0) {
|
|
1829
1834
|
state.firstTokenMs = Math.round(firstTokenMs);
|
|
@@ -6262,6 +6267,7 @@ var SessionHub = class {
|
|
|
6262
6267
|
socket.on(
|
|
6263
6268
|
"turn:events",
|
|
6264
6269
|
(data, acknowledge) => {
|
|
6270
|
+
syncServerTime(this.client, data.server_time);
|
|
6265
6271
|
acknowledgeTurnEvents(acknowledge);
|
|
6266
6272
|
for (const session of this.route(data.session_id)) {
|
|
6267
6273
|
session._handleTurnEvents(data.events ?? [], data.replayed === true);
|