@peer-agent/runtime-core 0.0.5-beta.3 → 0.0.5
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.
|
@@ -52,6 +52,20 @@ export declare function estimateContextToolsTokens(tools: readonly ToolLike[] |
|
|
|
52
52
|
* classification must stay single-sourced so both hosts retry under the same policy.
|
|
53
53
|
*/
|
|
54
54
|
export declare function isPromptTooLongError(status: number | null | undefined, text: string | null | undefined): boolean;
|
|
55
|
+
/** Stay this far below the compaction trigger before skipping exact count. */
|
|
56
|
+
export declare const EXACT_COUNT_SKIP_HEADROOM_RATIO = 0.1;
|
|
57
|
+
/**
|
|
58
|
+
* Inner-loop accounting: skip a provider exact count when the last observed
|
|
59
|
+
* percent plus this step's new tool text still sits clearly under the trigger.
|
|
60
|
+
* First requests, unknown windows, and near-threshold steps must still count.
|
|
61
|
+
*/
|
|
62
|
+
export declare function shouldSkipExactContextCount(options: {
|
|
63
|
+
readonly lastPercent?: number | null;
|
|
64
|
+
readonly contextWindow?: number | null;
|
|
65
|
+
readonly appendedText?: string | null;
|
|
66
|
+
readonly triggerRatio?: number;
|
|
67
|
+
readonly headroomRatio?: number;
|
|
68
|
+
}): boolean;
|
|
55
69
|
export declare function decideContextCompaction(options: {
|
|
56
70
|
pressureTokens: number | null | undefined;
|
|
57
71
|
contextWindow: number | null | undefined;
|
|
@@ -132,6 +132,29 @@ export function isPromptTooLongError(status, text) {
|
|
|
132
132
|
|| value.includes('too many tokens')
|
|
133
133
|
|| value.includes('token limit'));
|
|
134
134
|
}
|
|
135
|
+
/** Stay this far below the compaction trigger before skipping exact count. */
|
|
136
|
+
export const EXACT_COUNT_SKIP_HEADROOM_RATIO = 0.1;
|
|
137
|
+
/**
|
|
138
|
+
* Inner-loop accounting: skip a provider exact count when the last observed
|
|
139
|
+
* percent plus this step's new tool text still sits clearly under the trigger.
|
|
140
|
+
* First requests, unknown windows, and near-threshold steps must still count.
|
|
141
|
+
*/
|
|
142
|
+
export function shouldSkipExactContextCount(options) {
|
|
143
|
+
const lastPercent = options.lastPercent;
|
|
144
|
+
const contextWindow = finitePositive(options.contextWindow);
|
|
145
|
+
if (typeof lastPercent !== 'number' || !Number.isFinite(lastPercent) || lastPercent < 0) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (contextWindow == null)
|
|
149
|
+
return false;
|
|
150
|
+
const triggerRatio = options.triggerRatio ?? CONTEXT_PROJECTION_CONFIG.triggerRatio;
|
|
151
|
+
const headroomRatio = options.headroomRatio ?? EXACT_COUNT_SKIP_HEADROOM_RATIO;
|
|
152
|
+
const skipBelowPercent = (triggerRatio - headroomRatio) * 100;
|
|
153
|
+
if (skipBelowPercent <= 0)
|
|
154
|
+
return false;
|
|
155
|
+
const addedPercent = (estimateContextTextTokens(options.appendedText ?? '') / contextWindow) * 100;
|
|
156
|
+
return lastPercent + addedPercent < skipBelowPercent;
|
|
157
|
+
}
|
|
135
158
|
export function decideContextCompaction(options) {
|
|
136
159
|
const contextWindow = finitePositive(options.contextWindow);
|
|
137
160
|
const pressureTokens = finitePositive(options.pressureTokens) ?? 0;
|
|
@@ -28,6 +28,14 @@ export type SharedLocalToolContractKey = keyof typeof SHARED_LOCAL_TOOL_CONTRACT
|
|
|
28
28
|
export type SharedLocalToolName = (typeof SHARED_LOCAL_TOOL_CONTRACTS)[SharedLocalToolContractKey]['toolName'];
|
|
29
29
|
export type SharedLocalCapabilityId = (typeof SHARED_LOCAL_TOOL_CONTRACTS)[SharedLocalToolContractKey]['capabilityId'];
|
|
30
30
|
export declare const SHARED_LOCAL_TOOL_CONTRACT_LIST: readonly (Readonly<LocalToolContract<"read_file", "local.file.read">> | Readonly<LocalToolContract<"list_files", "local.file.list">> | Readonly<LocalToolContract<"search_files", "local.file.search">> | Readonly<LocalToolContract<"edit_file", "local.file.edit">> | Readonly<LocalToolContract<"write_file", "local.file.write">> | Readonly<LocalToolContract<"bash", "local.shell.exec">> | Readonly<LocalToolContract<"shell_stop", "local.shell.stop">> | Readonly<LocalToolContract<"batch_search", "local.search.aggregate">> | Readonly<LocalToolContract<"web_fetch", "local.web.fetch">> | Readonly<LocalToolContract<"request_user_input", "local.interaction.request_user_input">> | Readonly<LocalToolContract<"goal_create_plan", "local.goal.create_plan">> | Readonly<LocalToolContract<"goal_update_task", "local.goal.update_task">> | Readonly<LocalToolContract<"goal_get_plan", "local.goal.get_plan">> | Readonly<LocalToolContract<"request_explorer", "local.goal.explore">>)[];
|
|
31
|
+
/**
|
|
32
|
+
* Tool calls that may run concurrently inside one ModelStep.
|
|
33
|
+
* Writes, shell, MCP, and unknown capabilities stay serial.
|
|
34
|
+
*/
|
|
35
|
+
export declare const PARALLEL_SAFE_LOCAL_CAPABILITY_IDS: readonly ["local.file.read", "local.file.list", "local.file.search"];
|
|
36
|
+
export declare function isParallelSafeLocalToolBatch(calls: readonly {
|
|
37
|
+
readonly capabilityId?: string;
|
|
38
|
+
}[]): boolean;
|
|
31
39
|
/**
|
|
32
40
|
* Explicit Desktop-only capabilities. Parity assertions must exclude exactly
|
|
33
41
|
* these contracts instead of ignoring arbitrary browser-prefixed additions.
|
|
@@ -24,6 +24,22 @@ export const SHARED_LOCAL_TOOL_CONTRACTS = Object.freeze({
|
|
|
24
24
|
requestExplorer: defineToolContract('request_explorer', 'local.goal.explore'),
|
|
25
25
|
});
|
|
26
26
|
export const SHARED_LOCAL_TOOL_CONTRACT_LIST = Object.freeze(Object.values(SHARED_LOCAL_TOOL_CONTRACTS));
|
|
27
|
+
/**
|
|
28
|
+
* Tool calls that may run concurrently inside one ModelStep.
|
|
29
|
+
* Writes, shell, MCP, and unknown capabilities stay serial.
|
|
30
|
+
*/
|
|
31
|
+
export const PARALLEL_SAFE_LOCAL_CAPABILITY_IDS = Object.freeze([
|
|
32
|
+
SHARED_LOCAL_TOOL_CONTRACTS.readFile.capabilityId,
|
|
33
|
+
SHARED_LOCAL_TOOL_CONTRACTS.listFiles.capabilityId,
|
|
34
|
+
SHARED_LOCAL_TOOL_CONTRACTS.searchFiles.capabilityId,
|
|
35
|
+
]);
|
|
36
|
+
const PARALLEL_SAFE_LOCAL_CAPABILITY_ID_SET = new Set(PARALLEL_SAFE_LOCAL_CAPABILITY_IDS);
|
|
37
|
+
export function isParallelSafeLocalToolBatch(calls) {
|
|
38
|
+
if (calls.length <= 1)
|
|
39
|
+
return false;
|
|
40
|
+
return calls.every((call) => (typeof call.capabilityId === 'string'
|
|
41
|
+
&& PARALLEL_SAFE_LOCAL_CAPABILITY_ID_SET.has(call.capabilityId)));
|
|
42
|
+
}
|
|
27
43
|
/**
|
|
28
44
|
* Explicit Desktop-only capabilities. Parity assertions must exclude exactly
|
|
29
45
|
* these contracts instead of ignoring arbitrary browser-prefixed additions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peer-agent/runtime-core",
|
|
3
|
-
"version": "0.0.5
|
|
3
|
+
"version": "0.0.5",
|
|
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.0.5
|
|
41
|
+
"@peer-agent/protocol": "0.0.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "^5.9.3"
|