@peer-agent/runtime-core 0.1.0-rc.37 → 0.1.0-rc.38
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.
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Desktop send, Desktop restore and CLI/TUI restore must all cross this seam.
|
|
5
5
|
* Provider adapters may lower the camelCase tool fields to their wire format,
|
|
6
6
|
* but must not reinterpret persisted segments.
|
|
7
|
+
* Oversized tool bodies stay intact here so the host can spill them to a
|
|
8
|
+
* local file before the provider request. This projector does not drop them.
|
|
7
9
|
*/
|
|
8
10
|
export declare const CANONICAL_HISTORY_PROJECTOR_VERSION = 2;
|
|
9
11
|
export type CanonicalHistoryContentPart = {
|
|
@@ -5,6 +5,8 @@ import { formatResourceFeedbackContext, projectResourceFeedbackTransport } from
|
|
|
5
5
|
* Desktop send, Desktop restore and CLI/TUI restore must all cross this seam.
|
|
6
6
|
* Provider adapters may lower the camelCase tool fields to their wire format,
|
|
7
7
|
* but must not reinterpret persisted segments.
|
|
8
|
+
* Oversized tool bodies stay intact here so the host can spill them to a
|
|
9
|
+
* local file before the provider request. This projector does not drop them.
|
|
8
10
|
*/
|
|
9
11
|
export const CANONICAL_HISTORY_PROJECTOR_VERSION = 2;
|
|
10
12
|
function recordOf(value) {
|
package/dist/microcompact.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ export declare const MICROCOMPACTION_CONFIG: Readonly<{
|
|
|
2
2
|
keepRecentCount: 8;
|
|
3
3
|
triggerChars: 6000;
|
|
4
4
|
previewChars: 800;
|
|
5
|
+
/**
|
|
6
|
+
* Hard cap for one tool-result body in a provider request.
|
|
7
|
+
* The recent window stays more complete than older history, but it cannot
|
|
8
|
+
* carry a multi-megabyte tool body. File reads under this cap stay inline.
|
|
9
|
+
*/
|
|
10
|
+
recentToolResultChars: 32000;
|
|
5
11
|
}>;
|
|
6
12
|
/** 宽松消息形状:兼容 Desktop apiMessages 与 TUI ModelMessage(无索引签名接口)。 */
|
|
7
13
|
export type MicrocompactMessage = {
|
|
@@ -31,6 +37,12 @@ export declare function extractRecoverableClues(text: unknown, { limit }?: {
|
|
|
31
37
|
paths: string[];
|
|
32
38
|
suggestedRetrieval: string[];
|
|
33
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Bound one tool-result body before it is serialized into a provider request.
|
|
42
|
+
* Small and already-structured results pass through. Oversized text keeps a
|
|
43
|
+
* retrieval skeleton or a short preview, including original size.
|
|
44
|
+
*/
|
|
45
|
+
export declare function boundProviderToolResultContent(content: string, maxChars?: number): string;
|
|
34
46
|
/**
|
|
35
47
|
* 对「最近 keepRecentCount 条非 system 消息之外」的历史消息做证据引用化/预览化。
|
|
36
48
|
* system 与 `_compaction` handoff 不参与;已是 local_*_ref 的结果保留骨架不重复截断。
|
package/dist/microcompact.js
CHANGED
|
@@ -11,6 +11,12 @@ export const MICROCOMPACTION_CONFIG = Object.freeze({
|
|
|
11
11
|
keepRecentCount: 8,
|
|
12
12
|
triggerChars: 6_000,
|
|
13
13
|
previewChars: 800,
|
|
14
|
+
/**
|
|
15
|
+
* Hard cap for one tool-result body in a provider request.
|
|
16
|
+
* The recent window stays more complete than older history, but it cannot
|
|
17
|
+
* carry a multi-megabyte tool body. File reads under this cap stay inline.
|
|
18
|
+
*/
|
|
19
|
+
recentToolResultChars: 32_000,
|
|
14
20
|
});
|
|
15
21
|
export function previewHistoricalText(text, maxChars = MICROCOMPACTION_CONFIG.previewChars) {
|
|
16
22
|
const value = String(text ?? '');
|
|
@@ -282,6 +288,82 @@ function microcompactBlockContent(block, config) {
|
|
|
282
288
|
}
|
|
283
289
|
return { block, compacted: false, beforeChars: 0, afterChars: 0 };
|
|
284
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Bound one tool-result body before it is serialized into a provider request.
|
|
293
|
+
* Small and already-structured results pass through. Oversized text keeps a
|
|
294
|
+
* retrieval skeleton or a short preview, including original size.
|
|
295
|
+
*/
|
|
296
|
+
export function boundProviderToolResultContent(content, maxChars = MICROCOMPACTION_CONFIG.recentToolResultChars) {
|
|
297
|
+
if (content.length <= maxChars)
|
|
298
|
+
return content;
|
|
299
|
+
const previewChars = Math.min(MICROCOMPACTION_CONFIG.previewChars, Math.max(200, maxChars));
|
|
300
|
+
const parsed = tryParseJsonObject(content);
|
|
301
|
+
if (parsed) {
|
|
302
|
+
const ref = compactLocalRefPayload(parsed, previewChars);
|
|
303
|
+
const shrunk = ref ?? shrinkOversizedToolRecord(parsed, previewChars, content.length);
|
|
304
|
+
const next = JSON.stringify(ref ? { ...shrunk, originalChars: content.length } : shrunk);
|
|
305
|
+
if (next.length <= maxChars && next.length < content.length)
|
|
306
|
+
return next;
|
|
307
|
+
}
|
|
308
|
+
const preview = compactLongHistoricalString(content, previewChars);
|
|
309
|
+
return preview.length <= maxChars ? preview : preview.slice(0, maxChars);
|
|
310
|
+
}
|
|
311
|
+
function shrinkOversizedToolRecord(value, previewChars, originalChars) {
|
|
312
|
+
const next = {
|
|
313
|
+
contextPreviewTruncated: true,
|
|
314
|
+
originalChars,
|
|
315
|
+
note: 'Tool result omitted from provider history; use artifact, path, or evidence refs for the full output.',
|
|
316
|
+
};
|
|
317
|
+
for (const [key, item] of Object.entries(value)) {
|
|
318
|
+
if (typeof item === 'string') {
|
|
319
|
+
next[key] = item.length > previewChars ? previewHistoricalText(item, previewChars) : item;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(item)) {
|
|
323
|
+
next[key] = item.length > 16 ? item.slice(0, 16) : item;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (item && typeof item === 'object') {
|
|
327
|
+
const nested = shrinkOversizedToolRecord(item, Math.min(previewChars, 400), originalChars);
|
|
328
|
+
delete nested.note;
|
|
329
|
+
delete nested.originalChars;
|
|
330
|
+
next[key] = nested;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
next[key] = item;
|
|
334
|
+
}
|
|
335
|
+
return next;
|
|
336
|
+
}
|
|
337
|
+
function boundToolMessageContent(content, maxChars) {
|
|
338
|
+
if (typeof content === 'string') {
|
|
339
|
+
const next = boundProviderToolResultContent(content, maxChars);
|
|
340
|
+
return {
|
|
341
|
+
content: next,
|
|
342
|
+
bounded: next !== content,
|
|
343
|
+
beforeChars: content.length,
|
|
344
|
+
afterChars: next.length,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (!Array.isArray(content)) {
|
|
348
|
+
return { content, bounded: false, beforeChars: 0, afterChars: 0 };
|
|
349
|
+
}
|
|
350
|
+
let bounded = false;
|
|
351
|
+
let beforeChars = 0;
|
|
352
|
+
let afterChars = 0;
|
|
353
|
+
const blocks = content.map((block) => {
|
|
354
|
+
const record = block;
|
|
355
|
+
if (record?.type !== 'tool_result' || typeof record.content !== 'string')
|
|
356
|
+
return block;
|
|
357
|
+
const next = boundProviderToolResultContent(record.content, maxChars);
|
|
358
|
+
if (next === record.content)
|
|
359
|
+
return block;
|
|
360
|
+
bounded = true;
|
|
361
|
+
beforeChars += record.content.length;
|
|
362
|
+
afterChars += next.length;
|
|
363
|
+
return { ...record, content: next };
|
|
364
|
+
});
|
|
365
|
+
return { content: blocks, bounded, beforeChars, afterChars };
|
|
366
|
+
}
|
|
285
367
|
function microcompactMessageContent(content, config) {
|
|
286
368
|
if (typeof content === 'string') {
|
|
287
369
|
const result = microcompactStringContent(content, config);
|
|
@@ -329,9 +411,27 @@ export function microcompactMessagesForContext(messages, options = {}) {
|
|
|
329
411
|
let compactedCount = 0;
|
|
330
412
|
let beforeChars = 0;
|
|
331
413
|
let afterChars = 0;
|
|
414
|
+
const recentCap = config.recentToolResultChars;
|
|
332
415
|
const nextMessages = messages.map((message, index) => {
|
|
333
|
-
if (!compactableIndexes.has(index))
|
|
334
|
-
|
|
416
|
+
if (!compactableIndexes.has(index)) {
|
|
417
|
+
if (message?.role !== 'tool' && !Array.isArray(message?.content))
|
|
418
|
+
return message;
|
|
419
|
+
const bounded = boundToolMessageContent(message?.content, recentCap);
|
|
420
|
+
if (!bounded.bounded)
|
|
421
|
+
return message;
|
|
422
|
+
compactedCount++;
|
|
423
|
+
beforeChars += bounded.beforeChars;
|
|
424
|
+
afterChars += bounded.afterChars;
|
|
425
|
+
return {
|
|
426
|
+
...message,
|
|
427
|
+
content: bounded.content,
|
|
428
|
+
_microCompaction: {
|
|
429
|
+
method: 'provider_tool_result_cap',
|
|
430
|
+
beforeChars: bounded.beforeChars,
|
|
431
|
+
afterChars: bounded.afterChars,
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
335
435
|
const result = microcompactMessageContent(message.content, config);
|
|
336
436
|
if (!result.compacted)
|
|
337
437
|
return message;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peer-agent/runtime-core",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.38",
|
|
4
4
|
"description": "Host-neutral capability, permission, projection, and Evidence primitives for Peer Agent runtimes.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@peer-agent/protocol": "0.1.0-rc.
|
|
41
|
+
"@peer-agent/protocol": "0.1.0-rc.38"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "^5.9.3"
|