jbc-dssi 1.1.159 → 1.1.160

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.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/lib/slim.js +33 -5
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -3168,7 +3168,7 @@ class BridgeConnection {
3168
3168
  ? Number(frame.cursor)
3169
3169
  : 0;
3170
3170
  // 裁剪:实测一个 80 条消息的快照原样是 1278 KB,裁完降到几十 KB
3171
- this.send(FRAME.SNAPSHOT, frame);
3171
+ this.send(FRAME.SNAPSHOT, slimSnapshot(frame, { maxEvents: 400 }));
3172
3172
  // 附着后的首个快照里已带最新投影:顺手刷新一次团队快照
3173
3173
  this.#scheduleBotsRefresh(60);
3174
3174
  break;
package/lib/slim.js CHANGED
@@ -69,6 +69,27 @@ function toEpochMs(value) {
69
69
  return Number.isFinite(ms) ? ms : 0;
70
70
  }
71
71
 
72
+ function trimDeep(value, depth = 0) {
73
+ if (depth > 6) return null;
74
+ if (typeof value === 'string') {
75
+ if (value.length <= MAX_TEXT_CHARS) return value;
76
+ return `${value.slice(0, MAX_TEXT_CHARS)}\n…(还有 ${value.length - MAX_TEXT_CHARS} 字,手机上不传了)`;
77
+ }
78
+ if (Array.isArray(value)) {
79
+ return value.slice(0, 200).map((item) => trimDeep(item, depth + 1));
80
+ }
81
+ if (value && typeof value === 'object') {
82
+ const out = {};
83
+ let keys = 0;
84
+ for (const [k, v] of Object.entries(value)) {
85
+ if (keys++ >= 80) break;
86
+ out[k] = trimDeep(v, depth + 1);
87
+ }
88
+ return out;
89
+ }
90
+ return value;
91
+ }
92
+
72
93
  function clip(text, limit = MAX_TEXT_CHARS) {
73
94
  if (typeof text !== 'string') return text;
74
95
  if (text.length <= limit) return text;
@@ -128,7 +149,7 @@ function userText(content) {
128
149
  }
129
150
 
130
151
  export function slimEvent(event) {
131
- if (!event || !KEEP_EVENT_TYPES.has(event.type)) return null;
152
+ if (!event || typeof event.type !== 'string' || event.type === '') return null;
132
153
 
133
154
  const d = event.data ?? {};
134
155
  let data;
@@ -203,7 +224,7 @@ export function slimEvent(event) {
203
224
 
204
225
  default:
205
226
 
206
- data = d;
227
+ data = trimDeep(d);
207
228
  }
208
229
 
209
230
  const out = { type: event.type, seq: event.seq, time: event.time, data };
@@ -211,7 +232,7 @@ export function slimEvent(event) {
211
232
  return out;
212
233
  }
213
234
 
214
- export function slimSnapshot(snapshot) {
235
+ export function slimSnapshot(snapshot, { maxEvents = 400 } = {}) {
215
236
  if (!snapshot || !Array.isArray(snapshot.records)) return snapshot;
216
237
 
217
238
  const records = [];
@@ -220,12 +241,19 @@ export function slimSnapshot(snapshot) {
220
241
  if (slim) records.push({ type: 'event', event: slim });
221
242
  }
222
243
 
244
+ let trimmed = records;
245
+ let hasMore = snapshot.hasMore === true;
246
+ if (records.length > maxEvents) {
247
+ trimmed = records.slice(records.length - maxEvents);
248
+ hasMore = true;
249
+ }
250
+
223
251
  return {
224
252
  type: 'snapshot',
225
253
  header: snapshot.header,
226
254
  cursor: snapshot.cursor,
227
- records,
228
- hasMore: snapshot.hasMore,
255
+ records: trimmed,
256
+ hasMore,
229
257
 
230
258
  projections: null,
231
259
  assistantStream: snapshot.assistantStream,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.159",
3
+ "version": "1.1.160",
4
4
  "type": "module",
5
5
  "description": "鲸聊 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [