qlogicagent 0.2.1 → 0.3.0
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/agent.js +1 -0
- package/dist/cli.js +9 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +5 -15
- package/dist/orchestration.js +118 -0
- package/package.json +56 -42
- package/dist/agent/agent.js +0 -113
- package/dist/agent/tool-loop.js +0 -575
- package/dist/agent/types.js +0 -14
- package/dist/cli/main.js +0 -23
- package/dist/cli/stdio-server.js +0 -463
- package/dist/config/config.js +0 -21
- package/dist/contracts/hooks.js +0 -7
- package/dist/contracts/index.js +0 -10
- package/dist/contracts/planner.js +0 -2
- package/dist/contracts/skill-candidate.js +0 -195
- package/dist/contracts/todo.js +0 -9
- package/dist/llm/builtin-providers.js +0 -531
- package/dist/llm/index.js +0 -14
- package/dist/llm/llm-client.js +0 -67
- package/dist/llm/model-catalog.js +0 -191
- package/dist/llm/provider-def.js +0 -12
- package/dist/llm/provider-registry.js +0 -147
- package/dist/llm/transport.js +0 -27
- package/dist/llm/transports/anthropic-messages.js +0 -293
- package/dist/llm/transports/openai-chat.js +0 -165
- package/dist/orchestration/agent-registry.js +0 -116
- package/dist/orchestration/approval-aware-tool-plan.js +0 -87
- package/dist/orchestration/context-compression.js +0 -583
- package/dist/orchestration/conversation-repair.js +0 -429
- package/dist/orchestration/curator-scheduler.js +0 -135
- package/dist/orchestration/embedded-failover-policy.js +0 -168
- package/dist/orchestration/error-classification.js +0 -77
- package/dist/orchestration/failover-classification.js +0 -381
- package/dist/orchestration/failover-error.js +0 -198
- package/dist/orchestration/fork-subagent.js +0 -98
- package/dist/orchestration/index.js +0 -267
- package/dist/orchestration/memory-flush-policy.js +0 -85
- package/dist/orchestration/memory-provider.js +0 -2
- package/dist/orchestration/parallel-tool-calls.js +0 -59
- package/dist/orchestration/prompt-cache-strategy.js +0 -228
- package/dist/orchestration/reactive-compact.js +0 -78
- package/dist/orchestration/retry-loop.js +0 -24
- package/dist/orchestration/skill-candidate.js +0 -141
- package/dist/orchestration/skill-consolidation.js +0 -220
- package/dist/orchestration/skill-improvement.js +0 -66
- package/dist/orchestration/skill-similarity.js +0 -131
- package/dist/orchestration/streaming-tool-executor.js +0 -96
- package/dist/orchestration/team-orchestration.js +0 -369
- package/dist/orchestration/team-tool-loop-wiring.js +0 -147
- package/dist/orchestration/tool-choice-policy.js +0 -164
- package/dist/orchestration/tool-loop-state.js +0 -133
- package/dist/orchestration/tool-schema.js +0 -297
- package/dist/orchestration/transcript-repair.js +0 -426
- package/dist/orchestration/turn-loop-guard.js +0 -92
- package/dist/orchestration/web-browser-policy.js +0 -39
- package/dist/runtime/context-compression.js +0 -274
- package/dist/runtime/hook-registry.js +0 -53
- package/dist/runtime/memory-hooks.js +0 -65
- package/dist/runtime/tool-eligibility.js +0 -111
- package/dist/skills/index.js +0 -82
- package/dist/skills/memory-extractor.js +0 -173
- package/dist/skills/memory-query-tool.js +0 -127
- package/dist/skills/memory-store.js +0 -228
- package/dist/skills/memory-tool.js +0 -192
- package/dist/skills/portable-tool.js +0 -14
- package/dist/skills/qmemory-adapter.js +0 -165
- package/dist/skills/skill-frontmatter.js +0 -344
- package/dist/skills/skill-guard.js +0 -229
- package/dist/skills/skill-loader.js +0 -303
- package/dist/skills/skill-source.js +0 -126
- package/dist/skills/skill-types.js +0 -6
- package/dist/skills/think-tool.js +0 -59
- package/dist/skills/todo-tool.js +0 -114
- package/dist/skills/tools/agent-tool.js +0 -142
- package/dist/skills/tools/apply-patch-tool.js +0 -184
- package/dist/skills/tools/ask-user-tool.js +0 -121
- package/dist/skills/tools/brief-tool.js +0 -95
- package/dist/skills/tools/browser-tool.js +0 -155
- package/dist/skills/tools/checkpoint-tool.js +0 -102
- package/dist/skills/tools/config-tool.js +0 -143
- package/dist/skills/tools/cron-tool.js +0 -175
- package/dist/skills/tools/edit-tool.js +0 -70
- package/dist/skills/tools/exec-tool.js +0 -133
- package/dist/skills/tools/image-generate-tool.js +0 -67
- package/dist/skills/tools/instructions-tool.js +0 -187
- package/dist/skills/tools/lsp-tool.js +0 -227
- package/dist/skills/tools/mcp-client-types.js +0 -53
- package/dist/skills/tools/mcp-tool.js +0 -503
- package/dist/skills/tools/memory-tool.js +0 -88
- package/dist/skills/tools/monitor-tool.js +0 -131
- package/dist/skills/tools/music-generate-tool.js +0 -62
- package/dist/skills/tools/notify-tool.js +0 -62
- package/dist/skills/tools/patch-tool.js +0 -505
- package/dist/skills/tools/pdf-tool.js +0 -88
- package/dist/skills/tools/plan-mode-tool.js +0 -122
- package/dist/skills/tools/read-tool.js +0 -84
- package/dist/skills/tools/repl-tool.js +0 -69
- package/dist/skills/tools/search-tool.js +0 -225
- package/dist/skills/tools/send-message-tool.js +0 -76
- package/dist/skills/tools/skill-list-tool.js +0 -54
- package/dist/skills/tools/skill-manage-tool.js +0 -153
- package/dist/skills/tools/skill-view-tool.js +0 -72
- package/dist/skills/tools/sleep-tool.js +0 -81
- package/dist/skills/tools/structured-output-tool.js +0 -176
- package/dist/skills/tools/task-tool.js +0 -161
- package/dist/skills/tools/team-tool.js +0 -105
- package/dist/skills/tools/tool-search-tool.js +0 -110
- package/dist/skills/tools/tts-tool.js +0 -45
- package/dist/skills/tools/video-edit-tool.js +0 -74
- package/dist/skills/tools/video-generate-tool.js +0 -66
- package/dist/skills/tools/video-merge-tool.js +0 -92
- package/dist/skills/tools/video-upscale-tool.js +0 -52
- package/dist/skills/tools/web-fetch-tool.js +0 -92
- package/dist/skills/tools/web-search-tool.js +0 -86
- package/dist/skills/tools/worktree-tool.js +0 -147
- package/dist/skills/tools/write-tool.js +0 -81
- /package/dist/{agent → types/agent}/agent.d.ts +0 -0
- /package/dist/{agent → types/agent}/tool-loop.d.ts +0 -0
- /package/dist/{agent → types/agent}/types.d.ts +0 -0
- /package/dist/{cli → types/cli}/main.d.ts +0 -0
- /package/dist/{cli → types/cli}/stdio-server.d.ts +0 -0
- /package/dist/{config → types/config}/config.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/hooks.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/index.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/planner.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/skill-candidate.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/todo.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{llm → types/llm}/builtin-providers.d.ts +0 -0
- /package/dist/{llm → types/llm}/index.d.ts +0 -0
- /package/dist/{llm → types/llm}/llm-client.d.ts +0 -0
- /package/dist/{llm → types/llm}/model-catalog.d.ts +0 -0
- /package/dist/{llm → types/llm}/provider-def.d.ts +0 -0
- /package/dist/{llm → types/llm}/provider-registry.d.ts +0 -0
- /package/dist/{llm → types/llm}/transport.d.ts +0 -0
- /package/dist/{llm → types/llm}/transports/anthropic-messages.d.ts +0 -0
- /package/dist/{llm → types/llm}/transports/openai-chat.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/agent-registry.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/approval-aware-tool-plan.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/context-compression.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/conversation-repair.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/curator-scheduler.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/embedded-failover-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/error-classification.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/failover-classification.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/failover-error.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/fork-subagent.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/index.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/memory-flush-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/memory-provider.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/parallel-tool-calls.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/prompt-cache-strategy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/reactive-compact.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/retry-loop.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-candidate.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-consolidation.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-improvement.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-similarity.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/streaming-tool-executor.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/team-orchestration.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/team-tool-loop-wiring.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-choice-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-loop-state.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-schema.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/transcript-repair.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/turn-loop-guard.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/web-browser-policy.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/context-compression.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/hook-registry.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/memory-hooks.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/tool-eligibility.d.ts +0 -0
- /package/dist/{skills → types/skills}/index.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-extractor.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-query-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-store.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/portable-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/qmemory-adapter.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-frontmatter.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-guard.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-loader.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-source.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-types.d.ts +0 -0
- /package/dist/{skills → types/skills}/think-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/todo-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/agent-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/apply-patch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/ask-user-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/brief-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/browser-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/checkpoint-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/config-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/cron-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/edit-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/exec-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/image-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/instructions-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/lsp-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/mcp-client-types.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/mcp-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/memory-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/monitor-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/music-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/notify-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/patch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/pdf-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/plan-mode-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/read-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/repl-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/send-message-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-list-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-manage-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-view-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/sleep-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/structured-output-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/task-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/team-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/tool-search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/tts-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-edit-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-merge-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-upscale-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/web-fetch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/web-search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/worktree-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/write-tool.d.ts +0 -0
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { classifyFailoverReason, classifyFailoverReasonFromHttpStatus, isTimeoutErrorMessage, } from "./failover-classification.js";
|
|
2
|
-
const ABORT_TIMEOUT_RE = /request was aborted|request aborted/i;
|
|
3
|
-
function readErrorName(err) {
|
|
4
|
-
if (!err || typeof err !== "object") {
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
const candidate = err.name;
|
|
8
|
-
return typeof candidate === "string" && candidate.trim() ? candidate.trim() : undefined;
|
|
9
|
-
}
|
|
10
|
-
function getStatusCode(err) {
|
|
11
|
-
if (!err || typeof err !== "object") {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const candidate = err.status ??
|
|
15
|
-
err.statusCode;
|
|
16
|
-
if (typeof candidate === "number") {
|
|
17
|
-
return candidate;
|
|
18
|
-
}
|
|
19
|
-
if (typeof candidate === "string" && /^\d+$/.test(candidate)) {
|
|
20
|
-
return Number(candidate);
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
function getErrorCode(err) {
|
|
25
|
-
if (!err || typeof err !== "object") {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const candidate = err.code;
|
|
29
|
-
if (typeof candidate !== "string") {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
const trimmed = candidate.trim();
|
|
33
|
-
return trimmed ? trimmed : undefined;
|
|
34
|
-
}
|
|
35
|
-
function getErrorMessage(err) {
|
|
36
|
-
if (err instanceof Error) {
|
|
37
|
-
return err.message;
|
|
38
|
-
}
|
|
39
|
-
if (typeof err === "string") {
|
|
40
|
-
return err;
|
|
41
|
-
}
|
|
42
|
-
if (typeof err === "number" || typeof err === "boolean" || typeof err === "bigint") {
|
|
43
|
-
return String(err);
|
|
44
|
-
}
|
|
45
|
-
if (typeof err === "symbol") {
|
|
46
|
-
return err.description ?? "";
|
|
47
|
-
}
|
|
48
|
-
if (err && typeof err === "object") {
|
|
49
|
-
const message = err.message;
|
|
50
|
-
if (typeof message === "string") {
|
|
51
|
-
return message;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return "";
|
|
55
|
-
}
|
|
56
|
-
function hasTimeoutHint(err) {
|
|
57
|
-
if (!err) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
if (readErrorName(err) === "TimeoutError") {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
const message = getErrorMessage(err);
|
|
64
|
-
return Boolean(message && isTimeoutErrorMessage(message));
|
|
65
|
-
}
|
|
66
|
-
export class FailoverError extends Error {
|
|
67
|
-
reason;
|
|
68
|
-
provider;
|
|
69
|
-
model;
|
|
70
|
-
profileId;
|
|
71
|
-
status;
|
|
72
|
-
code;
|
|
73
|
-
constructor(message, params) {
|
|
74
|
-
super(message, { cause: params.cause });
|
|
75
|
-
this.name = "FailoverError";
|
|
76
|
-
this.reason = params.reason;
|
|
77
|
-
this.provider = params.provider;
|
|
78
|
-
this.model = params.model;
|
|
79
|
-
this.profileId = params.profileId;
|
|
80
|
-
this.status = params.status;
|
|
81
|
-
this.code = params.code;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export function isFailoverError(err) {
|
|
85
|
-
return err instanceof FailoverError;
|
|
86
|
-
}
|
|
87
|
-
export function resolveFailoverStatus(reason) {
|
|
88
|
-
switch (reason) {
|
|
89
|
-
case "billing":
|
|
90
|
-
return 402;
|
|
91
|
-
case "rate_limit":
|
|
92
|
-
return 429;
|
|
93
|
-
case "overloaded":
|
|
94
|
-
return 503;
|
|
95
|
-
case "auth":
|
|
96
|
-
return 401;
|
|
97
|
-
case "auth_permanent":
|
|
98
|
-
return 403;
|
|
99
|
-
case "timeout":
|
|
100
|
-
return 408;
|
|
101
|
-
case "format":
|
|
102
|
-
return 400;
|
|
103
|
-
case "model_not_found":
|
|
104
|
-
return 404;
|
|
105
|
-
case "session_expired":
|
|
106
|
-
return 410;
|
|
107
|
-
default:
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
export function isTimeoutError(err) {
|
|
112
|
-
if (hasTimeoutHint(err)) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
if (!err || typeof err !== "object") {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if (readErrorName(err) !== "AbortError") {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const message = getErrorMessage(err);
|
|
122
|
-
if (message && ABORT_TIMEOUT_RE.test(message)) {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
const cause = "cause" in err ? err.cause : undefined;
|
|
126
|
-
const reason = "reason" in err ? err.reason : undefined;
|
|
127
|
-
return hasTimeoutHint(cause) || hasTimeoutHint(reason);
|
|
128
|
-
}
|
|
129
|
-
export function resolveFailoverReasonFromError(err) {
|
|
130
|
-
if (isFailoverError(err)) {
|
|
131
|
-
return err.reason;
|
|
132
|
-
}
|
|
133
|
-
const status = getStatusCode(err);
|
|
134
|
-
const message = getErrorMessage(err);
|
|
135
|
-
const statusReason = classifyFailoverReasonFromHttpStatus(status, message);
|
|
136
|
-
if (statusReason) {
|
|
137
|
-
return statusReason;
|
|
138
|
-
}
|
|
139
|
-
const code = (getErrorCode(err) ?? "").toUpperCase();
|
|
140
|
-
if ([
|
|
141
|
-
"ETIMEDOUT",
|
|
142
|
-
"ESOCKETTIMEDOUT",
|
|
143
|
-
"ECONNRESET",
|
|
144
|
-
"ECONNABORTED",
|
|
145
|
-
"ECONNREFUSED",
|
|
146
|
-
"ENETUNREACH",
|
|
147
|
-
"EHOSTUNREACH",
|
|
148
|
-
"ENETRESET",
|
|
149
|
-
"EAI_AGAIN",
|
|
150
|
-
].includes(code)) {
|
|
151
|
-
return "timeout";
|
|
152
|
-
}
|
|
153
|
-
if (isTimeoutError(err)) {
|
|
154
|
-
return "timeout";
|
|
155
|
-
}
|
|
156
|
-
if (!message) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
return classifyFailoverReason(message);
|
|
160
|
-
}
|
|
161
|
-
export function describeFailoverError(err) {
|
|
162
|
-
if (isFailoverError(err)) {
|
|
163
|
-
return {
|
|
164
|
-
message: err.message,
|
|
165
|
-
reason: err.reason,
|
|
166
|
-
status: err.status,
|
|
167
|
-
code: err.code,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const message = getErrorMessage(err) || String(err);
|
|
171
|
-
return {
|
|
172
|
-
message,
|
|
173
|
-
reason: resolveFailoverReasonFromError(err) ?? undefined,
|
|
174
|
-
status: getStatusCode(err),
|
|
175
|
-
code: getErrorCode(err),
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
export function coerceToFailoverError(err, context) {
|
|
179
|
-
if (isFailoverError(err)) {
|
|
180
|
-
return err;
|
|
181
|
-
}
|
|
182
|
-
const reason = resolveFailoverReasonFromError(err);
|
|
183
|
-
if (!reason) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
const message = getErrorMessage(err) || String(err);
|
|
187
|
-
const status = getStatusCode(err) ?? resolveFailoverStatus(reason);
|
|
188
|
-
const code = getErrorCode(err);
|
|
189
|
-
return new FailoverError(message, {
|
|
190
|
-
reason,
|
|
191
|
-
provider: context?.provider,
|
|
192
|
-
model: context?.model,
|
|
193
|
-
profileId: context?.profileId,
|
|
194
|
-
status,
|
|
195
|
-
code,
|
|
196
|
-
cause: err instanceof Error ? err : undefined,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fork Sub-Agent — CC-aligned fork mechanism for spawning child agents.
|
|
3
|
-
*
|
|
4
|
-
* Core design principles (aligned with Claude Code):
|
|
5
|
-
* 1. Child agent shares parent's message prefix (prompt cache hit)
|
|
6
|
-
* 2. Fork uses placeholder results to ensure byte-identical prefix across children
|
|
7
|
-
* 3. Child has independent tool context (doesn't pollute parent state)
|
|
8
|
-
* 4. Results flow back via AsyncGenerator (streaming backflow)
|
|
9
|
-
* 5. Depth control via in-memory counter (not DB-based)
|
|
10
|
-
*/
|
|
11
|
-
/** Sentinel tag injected into fork children to prevent recursive forking. */
|
|
12
|
-
export const FORK_SENTINEL_TAG = "<fork-child-context>";
|
|
13
|
-
/** Placeholder text used for all tool_results in shared prefix (ensures byte-identical prefix). */
|
|
14
|
-
export const FORK_PLACEHOLDER_RESULT = "Fork started \u2014 processing in background";
|
|
15
|
-
/** Maximum fork depth for in-memory agents (more permissive than DB sidechain). */
|
|
16
|
-
export const MAX_FORK_DEPTH = 4;
|
|
17
|
-
/** Maximum fork depth for DB-backed sidechains (more conservative). */
|
|
18
|
-
export const MAX_SIDECHAIN_DB_DEPTH = 2;
|
|
19
|
-
/**
|
|
20
|
-
* Check if current context is inside a fork child (prevents recursive forking).
|
|
21
|
-
*/
|
|
22
|
-
export function isInForkChild(messages) {
|
|
23
|
-
return JSON.stringify(messages).includes(FORK_SENTINEL_TAG);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Check if fork depth allows spawning another child.
|
|
27
|
-
*/
|
|
28
|
-
export function canForkAtDepth(currentDepth, mode = "in-memory") {
|
|
29
|
-
const maxDepth = mode === "in-memory" ? MAX_FORK_DEPTH : MAX_SIDECHAIN_DB_DEPTH;
|
|
30
|
-
return currentDepth < maxDepth;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Build forked messages that ensure byte-identical prefix across all fork children.
|
|
34
|
-
*
|
|
35
|
-
* Strategy (aligned with CC's buildForkedMessages):
|
|
36
|
-
* 1. Keep full parent message history (all tool_use blocks, thinking, text)
|
|
37
|
-
* 2. Replace all pending tool_results with FORK_PLACEHOLDER_RESULT
|
|
38
|
-
* 3. Append a single user message with the child-specific directive
|
|
39
|
-
* → All children share the same prefix up to the directive → maximum cache hits.
|
|
40
|
-
*/
|
|
41
|
-
export function buildForkedMessages(context, childConfig) {
|
|
42
|
-
const messages = [...context.parentMessages];
|
|
43
|
-
// Inject fork sentinel + child task as the unique tail
|
|
44
|
-
const childDirective = {
|
|
45
|
-
role: "user",
|
|
46
|
-
content: [
|
|
47
|
-
{ type: "text", text: `${FORK_SENTINEL_TAG}\n\nYou are the "${childConfig.agent.name}" agent.\n\n${childConfig.taskPrompt}` },
|
|
48
|
-
],
|
|
49
|
-
};
|
|
50
|
-
messages.push(childDirective);
|
|
51
|
-
return messages;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Build placeholder tool results for the shared prefix.
|
|
55
|
-
* When parent has pending tool_calls, replace them all with identical placeholder text
|
|
56
|
-
* so all fork children produce byte-identical API request prefix.
|
|
57
|
-
*/
|
|
58
|
-
export function buildForkPlaceholderResults(pendingToolCallIds) {
|
|
59
|
-
return pendingToolCallIds.map((id) => ({
|
|
60
|
-
role: "tool",
|
|
61
|
-
tool_call_id: id,
|
|
62
|
-
content: FORK_PLACEHOLDER_RESULT,
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Resolve the effective tool set for a fork child.
|
|
67
|
-
* CC pattern: useExactTools=true → child gets parent's full tool pool,
|
|
68
|
-
* then filtered by agent definition.
|
|
69
|
-
*/
|
|
70
|
-
export function resolveForkChildTools(parentTools, agent) {
|
|
71
|
-
if (agent.allowedTools && agent.allowedTools.length > 0) {
|
|
72
|
-
const allowed = new Set(agent.allowedTools);
|
|
73
|
-
return parentTools.filter((t) => allowed.has(t));
|
|
74
|
-
}
|
|
75
|
-
if (agent.toolAccessMode === "none")
|
|
76
|
-
return [];
|
|
77
|
-
if (agent.toolAccessMode === "read-only") {
|
|
78
|
-
const writeTools = new Set([
|
|
79
|
-
"file_edit", "create_file", "write_file", "replace_string_in_file",
|
|
80
|
-
"multi_replace_string_in_file", "create_directory", "delete_file",
|
|
81
|
-
"rename_file", "move_file", "exec", "run_in_terminal", "run_command",
|
|
82
|
-
"git_commit", "git_push", "patch",
|
|
83
|
-
]);
|
|
84
|
-
return parentTools.filter((t) => !writeTools.has(t));
|
|
85
|
-
}
|
|
86
|
-
// full access — remove agent_tool if canFork=false
|
|
87
|
-
if (!agent.canFork) {
|
|
88
|
-
return parentTools.filter((t) => t !== "agent_tool");
|
|
89
|
-
}
|
|
90
|
-
return [...parentTools];
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Generate a unique agent ID for a fork child.
|
|
94
|
-
*/
|
|
95
|
-
export function generateForkChildAgentId(parentAgentId, agentName, depth) {
|
|
96
|
-
const ts = Date.now().toString(36);
|
|
97
|
-
return `${parentAgentId}:fork:${agentName}:d${depth}:${ts}`;
|
|
98
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
export { buildAssistantToolCallMessage, buildToolResultMessage, cleanToolSchemaForGemini, convertCapabilityToolManifestsToFunctionTools, convertFunctionTools, isXaiProvider, normalizeMessageTextContent, normalizeFunctionToolParameters, parseOpenAiToolCallsFromChatResponse, } from "./tool-schema.js";
|
|
2
|
-
export { classifyError, classifyErrorFromReason, getRetryStrategy, } from "./error-classification.js";
|
|
3
|
-
export { composeStrategies, composeAsyncStrategies, SlidingWindowStrategy, SummarizeOldStrategy, ToolResultTrimStrategy, HeadTailProtectedStrategy, IncrementalCompactStrategy, CacheAwareCompressionStrategy, CompressionMetricsCollector, ContextEngineRegistry, buildStructuredSummaryPrompt, computeAdaptiveBudget, isAsyncCompressionStrategy, selectCompressionTier, DEFAULT_ADAPTIVE_BUDGET_CONFIG, } from "./context-compression.js";
|
|
4
|
-
export { buildSkillInstruction, shouldCreateSkill, shouldImproveSkill, } from "./skill-improvement.js";
|
|
5
|
-
export { buildSkillCandidateEffectivenessSummary, buildSkillCandidateEvidencePayload, buildSkillCandidateImprovementEvidenceBundle, buildSkillCandidateLatestReview, createDefaultSkillImprovementPolicy, normalizeSkillImprovementPolicy, } from "./skill-candidate.js";
|
|
6
|
-
export const SIDECHAIN_TYPE_VALUES = ["research", "planner", "plan-repair", "code-repair", "media-prep"];
|
|
7
|
-
const SIDECHAIN_TYPE_POLICY_MAP = {
|
|
8
|
-
research: {
|
|
9
|
-
type: "research",
|
|
10
|
-
label: "Research",
|
|
11
|
-
description: "Independent retrieval or evidence gathering branches.",
|
|
12
|
-
mergePolicy: "summary-only",
|
|
13
|
-
budgetTier: "medium",
|
|
14
|
-
budgetWeight: 2,
|
|
15
|
-
preferFullContext: false,
|
|
16
|
-
preserveConversationHistory: true,
|
|
17
|
-
toolAccessMode: "read-only",
|
|
18
|
-
},
|
|
19
|
-
planner: {
|
|
20
|
-
type: "planner",
|
|
21
|
-
label: "Planner",
|
|
22
|
-
description: "Planning and tool orchestration branches that may return structured context.",
|
|
23
|
-
mergePolicy: "append-messages",
|
|
24
|
-
budgetTier: "high",
|
|
25
|
-
budgetWeight: 3,
|
|
26
|
-
preferFullContext: true,
|
|
27
|
-
preserveConversationHistory: true,
|
|
28
|
-
toolAccessMode: "none",
|
|
29
|
-
},
|
|
30
|
-
"plan-repair": {
|
|
31
|
-
type: "plan-repair",
|
|
32
|
-
label: "Plan Repair",
|
|
33
|
-
description: "Failure repair or fallback branches that re-plan tool choice, ordering, or approval strategy.",
|
|
34
|
-
mergePolicy: "replace-context",
|
|
35
|
-
budgetTier: "medium",
|
|
36
|
-
budgetWeight: 2,
|
|
37
|
-
preferFullContext: true,
|
|
38
|
-
preserveConversationHistory: false,
|
|
39
|
-
toolAccessMode: "none",
|
|
40
|
-
},
|
|
41
|
-
"code-repair": {
|
|
42
|
-
type: "code-repair",
|
|
43
|
-
label: "Code Repair",
|
|
44
|
-
description: "Recovery branches focused on file edits, patch validation, or workspace mutation repair.",
|
|
45
|
-
mergePolicy: "replace-context",
|
|
46
|
-
budgetTier: "high",
|
|
47
|
-
budgetWeight: 3,
|
|
48
|
-
preferFullContext: true,
|
|
49
|
-
preserveConversationHistory: false,
|
|
50
|
-
toolAccessMode: "full",
|
|
51
|
-
},
|
|
52
|
-
"media-prep": {
|
|
53
|
-
type: "media-prep",
|
|
54
|
-
label: "Media Prep",
|
|
55
|
-
description: "Preparation branches for media generation, normalization, or staging.",
|
|
56
|
-
mergePolicy: "summary-only",
|
|
57
|
-
budgetTier: "low",
|
|
58
|
-
budgetWeight: 1,
|
|
59
|
-
preferFullContext: false,
|
|
60
|
-
preserveConversationHistory: false,
|
|
61
|
-
toolAccessMode: "read-only",
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
export const SIDECHAIN_TOOL_DENY_ALWAYS = [
|
|
65
|
-
"gateway",
|
|
66
|
-
"agents_list",
|
|
67
|
-
"whatsapp_login",
|
|
68
|
-
"session_status",
|
|
69
|
-
"cron",
|
|
70
|
-
"memory_query",
|
|
71
|
-
"sessions_send",
|
|
72
|
-
];
|
|
73
|
-
export const SIDECHAIN_TOOL_DENY_LEAF = [
|
|
74
|
-
"sessions_list",
|
|
75
|
-
"sessions_history",
|
|
76
|
-
"sessions_spawn",
|
|
77
|
-
];
|
|
78
|
-
/** Tools that perform write/mutation operations — denied in read-only sidechain types. */
|
|
79
|
-
export const SIDECHAIN_TOOL_DENY_WRITE = [
|
|
80
|
-
"file_edit",
|
|
81
|
-
"create_file",
|
|
82
|
-
"replace_string_in_file",
|
|
83
|
-
"multi_replace_string_in_file",
|
|
84
|
-
"create_directory",
|
|
85
|
-
"run_in_terminal",
|
|
86
|
-
"run_command",
|
|
87
|
-
"delete_file",
|
|
88
|
-
"rename_file",
|
|
89
|
-
"move_file",
|
|
90
|
-
"git_commit",
|
|
91
|
-
"git_push",
|
|
92
|
-
"manage_todo_list",
|
|
93
|
-
];
|
|
94
|
-
export function resolveSidechainToolAccessPolicy(params = {}) {
|
|
95
|
-
const maxDepth = Math.max(1, Math.floor(params.maxDepth ?? 2));
|
|
96
|
-
const depth = typeof params.depth === "number" && Number.isFinite(params.depth)
|
|
97
|
-
? Math.max(0, Math.floor(params.depth))
|
|
98
|
-
: maxDepth;
|
|
99
|
-
const isLeaf = params.role ? params.role === "leaf" : depth >= maxDepth;
|
|
100
|
-
const deniedTools = isLeaf
|
|
101
|
-
? [...SIDECHAIN_TOOL_DENY_ALWAYS, ...SIDECHAIN_TOOL_DENY_LEAF]
|
|
102
|
-
: [...SIDECHAIN_TOOL_DENY_ALWAYS];
|
|
103
|
-
const deniedSet = new Set(deniedTools);
|
|
104
|
-
const toolNames = Array.isArray(params.toolNames)
|
|
105
|
-
? params.toolNames
|
|
106
|
-
: params.toolNames
|
|
107
|
-
? Array.from(params.toolNames)
|
|
108
|
-
: [];
|
|
109
|
-
const tools = Array.from(new Set(toolNames.map((toolName) => toolName.trim()).filter(Boolean))).map((toolName) => {
|
|
110
|
-
const denied = deniedSet.has(toolName);
|
|
111
|
-
return {
|
|
112
|
-
toolName,
|
|
113
|
-
decision: denied ? "denied" : "allowed",
|
|
114
|
-
inheritance: denied ? "shrink" : "inherit",
|
|
115
|
-
reason: denied
|
|
116
|
-
? SIDECHAIN_TOOL_DENY_ALWAYS.includes(toolName)
|
|
117
|
-
? "always-deny"
|
|
118
|
-
: "leaf-deny"
|
|
119
|
-
: "default-allow",
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
return {
|
|
123
|
-
deniedTools,
|
|
124
|
-
canSpawnChildren: !isLeaf,
|
|
125
|
-
defaultDecision: "allowed",
|
|
126
|
-
defaultInheritance: "inherit",
|
|
127
|
-
tools,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Resolve tool access policy for a specific sidechain type.
|
|
132
|
-
* Combines depth-based deny lists with type-specific access mode:
|
|
133
|
-
* - "full": only depth-based denials apply
|
|
134
|
-
* - "read-only": depth-based + all write/mutation tools denied
|
|
135
|
-
* - "none": all tools denied
|
|
136
|
-
*/
|
|
137
|
-
export function resolveSidechainToolAccessByType(params) {
|
|
138
|
-
const policy = resolveSidechainTypePolicy(params.type);
|
|
139
|
-
const basePolicy = resolveSidechainToolAccessPolicy({
|
|
140
|
-
depth: params.depth,
|
|
141
|
-
maxDepth: params.maxDepth,
|
|
142
|
-
role: params.role,
|
|
143
|
-
toolNames: params.toolNames,
|
|
144
|
-
});
|
|
145
|
-
if (policy.toolAccessMode === "full") {
|
|
146
|
-
return basePolicy;
|
|
147
|
-
}
|
|
148
|
-
if (policy.toolAccessMode === "none") {
|
|
149
|
-
const allToolNames = Array.isArray(params.toolNames)
|
|
150
|
-
? params.toolNames
|
|
151
|
-
: params.toolNames ? Array.from(params.toolNames) : [];
|
|
152
|
-
const uniqueNames = [...new Set(allToolNames.map((n) => n.trim()).filter(Boolean))];
|
|
153
|
-
return {
|
|
154
|
-
deniedTools: uniqueNames,
|
|
155
|
-
canSpawnChildren: false,
|
|
156
|
-
defaultDecision: "allowed",
|
|
157
|
-
defaultInheritance: "inherit",
|
|
158
|
-
tools: uniqueNames.map((toolName) => ({
|
|
159
|
-
toolName,
|
|
160
|
-
decision: "denied",
|
|
161
|
-
inheritance: "shrink",
|
|
162
|
-
reason: "always-deny",
|
|
163
|
-
})),
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
// "read-only": add write tools to deny list
|
|
167
|
-
const writeSet = new Set(SIDECHAIN_TOOL_DENY_WRITE);
|
|
168
|
-
const combinedDenied = [...new Set([...basePolicy.deniedTools, ...SIDECHAIN_TOOL_DENY_WRITE])];
|
|
169
|
-
return {
|
|
170
|
-
...basePolicy,
|
|
171
|
-
deniedTools: combinedDenied,
|
|
172
|
-
tools: basePolicy.tools.map((rule) => {
|
|
173
|
-
if (rule.decision === "denied")
|
|
174
|
-
return rule;
|
|
175
|
-
if (writeSet.has(rule.toolName)) {
|
|
176
|
-
return { ...rule, decision: "denied", inheritance: "shrink", reason: "always-deny" };
|
|
177
|
-
}
|
|
178
|
-
return rule;
|
|
179
|
-
}),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Filter tool_calls against a resolved access policy.
|
|
184
|
-
* Returns allowed calls and denied calls with reasons.
|
|
185
|
-
* T must have at least { id: string; function: { name: string } }.
|
|
186
|
-
*/
|
|
187
|
-
export function filterToolCallsByAccessPolicy(toolCalls, policy) {
|
|
188
|
-
const deniedSet = new Set(policy.deniedTools);
|
|
189
|
-
const ruleMap = new Map(policy.tools.map((r) => [r.toolName, r]));
|
|
190
|
-
const allowed = [];
|
|
191
|
-
const denied = [];
|
|
192
|
-
for (const tc of toolCalls) {
|
|
193
|
-
const name = tc.function.name;
|
|
194
|
-
const rule = ruleMap.get(name);
|
|
195
|
-
if (rule?.decision === "denied") {
|
|
196
|
-
denied.push({ toolCall: tc, reason: `tool "${name}" denied by sidechain policy: ${rule.reason}` });
|
|
197
|
-
}
|
|
198
|
-
else if (deniedSet.has(name)) {
|
|
199
|
-
denied.push({ toolCall: tc, reason: `tool "${name}" is in sidechain deny list` });
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
allowed.push(tc);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return { allowed, denied };
|
|
206
|
-
}
|
|
207
|
-
export function listSidechainTypePolicies() {
|
|
208
|
-
return SIDECHAIN_TYPE_VALUES.map((type) => SIDECHAIN_TYPE_POLICY_MAP[type]);
|
|
209
|
-
}
|
|
210
|
-
export function resolveSidechainTypePolicy(type) {
|
|
211
|
-
return SIDECHAIN_TYPE_POLICY_MAP[type];
|
|
212
|
-
}
|
|
213
|
-
export function resolveRepairSidechainType(params = {}) {
|
|
214
|
-
if (params.preferCodeRepair) {
|
|
215
|
-
return "code-repair";
|
|
216
|
-
}
|
|
217
|
-
const trigger = typeof params.trigger === "string" ? params.trigger.trim().toLowerCase() : "";
|
|
218
|
-
if (trigger.includes("code") || trigger.includes("patch") || trigger.includes("workspace")) {
|
|
219
|
-
return "code-repair";
|
|
220
|
-
}
|
|
221
|
-
const toolNames = Array.from(params.toolNames ?? []).map((toolName) => toolName.trim().toLowerCase()).filter(Boolean);
|
|
222
|
-
const codeRepairHints = ["code", "edit", "patch", "diff", "file", "workspace", "git", "terminal"];
|
|
223
|
-
return toolNames.some((toolName) => codeRepairHints.some((hint) => toolName.includes(hint)))
|
|
224
|
-
? "code-repair"
|
|
225
|
-
: "plan-repair";
|
|
226
|
-
}
|
|
227
|
-
export function resolveSidechainMergePolicyByType(type, overrides = {}) {
|
|
228
|
-
const policy = resolveSidechainTypePolicy(type);
|
|
229
|
-
return resolveSidechainMergePolicy({
|
|
230
|
-
forceManualReview: overrides.forceManualReview,
|
|
231
|
-
preferFullContext: overrides.preferFullContext ?? policy.preferFullContext,
|
|
232
|
-
preserveConversationHistory: overrides.preserveConversationHistory ?? policy.preserveConversationHistory,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
export function resolveSidechainMergePolicy(params = {}) {
|
|
236
|
-
if (params.forceManualReview) {
|
|
237
|
-
return "manual";
|
|
238
|
-
}
|
|
239
|
-
if (params.preferFullContext) {
|
|
240
|
-
return params.preserveConversationHistory ? "append-messages" : "replace-context";
|
|
241
|
-
}
|
|
242
|
-
return "summary-only";
|
|
243
|
-
}
|
|
244
|
-
export { applyToolChoiceCompatibility, applyToolChoicePolicy, filterEligibleTools, normalizeAnthropicFunctionToolDefinition, normalizeAnthropicToolChoice, } from "./tool-choice-policy.js";
|
|
245
|
-
export { downgradeOpenAiFunctionCallReasoningPairs, downgradeOpenAiReasoningBlocks, ensureAssistantReasoningContent, injectDanglingToolCallPlaceholders, repairOpenAiChatConversation, repairOpenAiResponsesItems, sanitizeOpenAiChatMessages, stripForcedStopAssistantToolMetadata, } from "./conversation-repair.js";
|
|
246
|
-
export { classifyFailoverReason, classifyFailoverReasonFromHttpStatus, isCloudflareOrHtmlErrorPage, isFailoverErrorMessage, isModelNotFoundErrorMessage, isTimeoutErrorMessage, isTransientHttpError, } from "./failover-classification.js";
|
|
247
|
-
export { FailoverError, coerceToFailoverError, describeFailoverError, isFailoverError, isTimeoutError, resolveFailoverReasonFromError, resolveFailoverStatus, } from "./failover-error.js";
|
|
248
|
-
export { repairToolCallInputs, repairToolUseResultPairing, sanitizeToolCallInputs, sanitizeToolUseResultPairing, stripToolResultDetails, stripTransientErrorMessages, } from "./transcript-repair.js";
|
|
249
|
-
export { normalizeParallelToolCallsPreference, resolveParallelToolCallScheduling, } from "./parallel-tool-calls.js";
|
|
250
|
-
export { advanceToolLoopState, createToolLoopState, recoverToolLoopStateFromChatConversation, recoverToolLoopStateFromResponsesItems, settleToolLoopState, } from "./tool-loop-state.js";
|
|
251
|
-
export { MEMORY_OBSERVATION_HOOK_VALUES, MEMORY_OBSERVATION_SOURCE_VALUES, MEMORY_WRITE_ACCESS_VALUES, } from "./memory-provider.js";
|
|
252
|
-
export { hasAlreadyFlushedForCurrentCompaction, resolveMemoryFlushProjection, resolveMemoryFlushReadPlan, shouldRunMemoryFlush, } from "./memory-flush-policy.js";
|
|
253
|
-
export { executeBoundedRetryLoop, resolveScaledRetryIterations, } from "./retry-loop.js";
|
|
254
|
-
export { buildAssistantFailoverErrorDetails, pickFallbackThinkingLevel, resolveAssistantFailureActionDecision, resolveAuthProfileFailoverReason, resolveFallbackThinkingDecision, resolvePromptErrorPolicy, resolvePromptFailureActionDecision, resolveRetryableFailureReason, shouldAttemptAssistantFailureRotation, shouldAttemptPromptFailureRotation, } from "./embedded-failover-policy.js";
|
|
255
|
-
export { buildApprovalAwareReason, buildApprovalStepContext, summarizeApprovalAwareToolPlan, } from "./approval-aware-tool-plan.js";
|
|
256
|
-
export { resolveWebBrowserPolicy, } from "./web-browser-policy.js";
|
|
257
|
-
export { applyCacheMarkers, computeCacheBreakpoints, createCacheBreakDetectionState, DEFAULT_PROMPT_CACHE_POLICY, detectCacheBreaks, estimateCacheSavingsRatio, quickHash, resolveForkCacheMarkerIndex, } from "./prompt-cache-strategy.js";
|
|
258
|
-
export { computeLifecycleTransitions, DEFAULT_CURATOR_SCHEDULE_POLICY, INITIAL_CURATOR_STATE, selectReviewCandidates, shouldRunCurator, } from "./curator-scheduler.js";
|
|
259
|
-
export { buildConsolidationPrompt, buildCuratorRunSummary, detectPrefixClusters, parseConsolidationOutput, reconcileConsolidationPlan, } from "./skill-consolidation.js";
|
|
260
|
-
export { bigramSimilarity, computeSimilarity, decideSimilarityAction, DEFAULT_SKILL_SIMILARITY_POLICY, findSimilarSkills, stepCountProximity, toolSetJaccard, } from "./skill-similarity.js";
|
|
261
|
-
export { aggregateTeamResults, allocateTokenBudgets, buildAgentTaskPrompt, inferAggregationPolicy, inferExecutionMode, mapRoleToSidechainType, resolveAgentToolAccess, resolveExecutionOrder, resolveTeamPlan, shouldCancelTeam, TEAM_MAX_AGENTS, TEAM_MAX_DEPTH, validateTeamPlan, } from "./team-orchestration.js";
|
|
262
|
-
export { canDispatchDuringStreaming, createStreamingToolExecutor, } from "./streaming-tool-executor.js";
|
|
263
|
-
export { canForkAtDepth, buildForkedMessages, buildForkPlaceholderResults, FORK_PLACEHOLDER_RESULT, FORK_SENTINEL_TAG, generateForkChildAgentId, isInForkChild, MAX_FORK_DEPTH, MAX_SIDECHAIN_DB_DEPTH, resolveForkChildTools, } from "./fork-subagent.js";
|
|
264
|
-
export { getBuiltInAgent, getBuiltInAgents, isBuiltInAgent, resolveAgentToolSet, } from "./agent-registry.js";
|
|
265
|
-
export { calculateTokenWarningState, createTurnLoopGuardState, resolveApiErrorRecovery, resolveOutputTokenEscalation, shouldAbortTurn, } from "./turn-loop-guard.js";
|
|
266
|
-
export { buildPostCompactRestorationMessage, computeToolDelta, createReactiveCompactState, DEFAULT_REACTIVE_COMPACT_CONFIG, shouldAttemptReactiveCompact, } from "./reactive-compact.js";
|
|
267
|
-
export { aggregateTeamToolResults, mapTeamRequestToForkConfigs, resolveTeamExecutionPlan, } from "./team-tool-loop-wiring.js";
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export function hasAlreadyFlushedForCurrentCompaction(entry) {
|
|
2
|
-
const compactionCount = entry.compactionCount ?? 0;
|
|
3
|
-
const lastFlushAt = entry.memoryFlushCompactionCount;
|
|
4
|
-
return typeof lastFlushAt === "number" && lastFlushAt === compactionCount;
|
|
5
|
-
}
|
|
6
|
-
export function shouldRunMemoryFlush(params) {
|
|
7
|
-
if (!params.entry) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const override = params.tokenCount;
|
|
11
|
-
const overrideTokens = typeof override === "number" && Number.isFinite(override) && override > 0
|
|
12
|
-
? Math.floor(override)
|
|
13
|
-
: undefined;
|
|
14
|
-
const totalTokens = overrideTokens ?? params.resolveFreshSessionTotalTokens(params.entry);
|
|
15
|
-
if (!totalTokens || totalTokens <= 0) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
const contextWindow = Math.max(1, Math.floor(params.contextWindowTokens));
|
|
19
|
-
const reserveTokens = Math.max(0, Math.floor(params.reserveTokensFloor));
|
|
20
|
-
const softThreshold = Math.max(0, Math.floor(params.softThresholdTokens));
|
|
21
|
-
const threshold = Math.max(0, contextWindow - reserveTokens - softThreshold);
|
|
22
|
-
if (threshold <= 0 || totalTokens < threshold) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
if (hasAlreadyFlushedForCurrentCompaction(params.entry)) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
export function resolveMemoryFlushReadPlan(params) {
|
|
31
|
-
const canAttemptFlush = params.memoryFlushWritable && !params.isHeartbeat && !params.isCli;
|
|
32
|
-
const flushThreshold = params.contextWindowTokens - params.reserveTokensFloor - params.softThresholdTokens;
|
|
33
|
-
const shouldReadTranscriptForOutput = canAttemptFlush &&
|
|
34
|
-
params.hasSessionEntry &&
|
|
35
|
-
params.hasFreshPersistedPromptTokens &&
|
|
36
|
-
typeof params.promptTokenEstimate === "number" &&
|
|
37
|
-
Number.isFinite(params.promptTokenEstimate) &&
|
|
38
|
-
flushThreshold > 0 &&
|
|
39
|
-
(params.persistedPromptTokens ?? 0) + params.promptTokenEstimate >=
|
|
40
|
-
flushThreshold - params.transcriptOutputReadBufferTokens;
|
|
41
|
-
const shouldReadTranscript = Boolean(canAttemptFlush &&
|
|
42
|
-
params.hasSessionEntry &&
|
|
43
|
-
(!params.hasFreshPersistedPromptTokens || shouldReadTranscriptForOutput));
|
|
44
|
-
const shouldCheckTranscriptSizeForForcedFlush = Boolean(canAttemptFlush &&
|
|
45
|
-
params.hasSessionEntry &&
|
|
46
|
-
Number.isFinite(params.forceFlushTranscriptBytes) &&
|
|
47
|
-
params.forceFlushTranscriptBytes > 0);
|
|
48
|
-
return {
|
|
49
|
-
canAttemptFlush,
|
|
50
|
-
flushThreshold,
|
|
51
|
-
shouldReadTranscriptForOutput,
|
|
52
|
-
shouldReadTranscript,
|
|
53
|
-
shouldCheckTranscriptSizeForForcedFlush,
|
|
54
|
-
shouldReadSessionLog: shouldReadTranscript || shouldCheckTranscriptSizeForForcedFlush,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export function resolveMemoryFlushProjection(params) {
|
|
58
|
-
const shouldForceFlushByTranscriptSize = typeof params.transcriptByteSize === "number" &&
|
|
59
|
-
params.transcriptByteSize >= params.forceFlushTranscriptBytes;
|
|
60
|
-
const hasReliableTranscriptPromptTokens = typeof params.transcriptPromptTokens === "number" &&
|
|
61
|
-
Number.isFinite(params.transcriptPromptTokens) &&
|
|
62
|
-
params.transcriptPromptTokens > 0;
|
|
63
|
-
const shouldPersistTranscriptPromptTokens = hasReliableTranscriptPromptTokens &&
|
|
64
|
-
(!params.hasFreshPersistedPromptTokens ||
|
|
65
|
-
(params.transcriptPromptTokens ?? 0) > (params.persistedPromptTokens ?? 0));
|
|
66
|
-
const promptTokensSnapshot = Math.max(params.hasFreshPersistedPromptTokens ? (params.persistedPromptTokens ?? 0) : 0, hasReliableTranscriptPromptTokens ? (params.transcriptPromptTokens ?? 0) : 0);
|
|
67
|
-
const hasFreshPromptTokensSnapshot = promptTokensSnapshot > 0 &&
|
|
68
|
-
(params.hasFreshPersistedPromptTokens || hasReliableTranscriptPromptTokens);
|
|
69
|
-
const projectedTokenCount = hasFreshPromptTokensSnapshot
|
|
70
|
-
? params.resolveEffectivePromptTokens(promptTokensSnapshot, params.transcriptOutputTokens, params.promptTokenEstimate)
|
|
71
|
-
: undefined;
|
|
72
|
-
const tokenCountForFlush = typeof projectedTokenCount === "number" &&
|
|
73
|
-
Number.isFinite(projectedTokenCount) &&
|
|
74
|
-
projectedTokenCount > 0
|
|
75
|
-
? projectedTokenCount
|
|
76
|
-
: undefined;
|
|
77
|
-
return {
|
|
78
|
-
shouldForceFlushByTranscriptSize,
|
|
79
|
-
shouldPersistTranscriptPromptTokens,
|
|
80
|
-
promptTokensSnapshot,
|
|
81
|
-
hasFreshPromptTokensSnapshot,
|
|
82
|
-
projectedTokenCount,
|
|
83
|
-
tokenCountForFlush,
|
|
84
|
-
};
|
|
85
|
-
}
|