@a1hvdy/cc-openclaw 0.6.0 → 0.7.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/src/lib/config.d.ts +2 -0
- package/dist/src/lib/config.js +19 -0
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/trajectory.d.ts +1 -1
- package/dist/src/lib/trajectory.js.map +1 -1
- package/dist/src/lib/vendor-paths.d.ts +6 -4
- package/dist/src/lib/vendor-paths.js +21 -14
- package/dist/src/lib/vendor-paths.js.map +1 -1
- package/dist/src/openai-compat/openai-compat.d.ts +7 -1
- package/dist/src/openai-compat/openai-compat.js +8 -1
- package/dist/src/openai-compat/openai-compat.js.map +1 -1
- package/dist/src/openai-compat/sse-translator.d.ts +23 -3
- package/dist/src/openai-compat/sse-translator.js +45 -6
- package/dist/src/openai-compat/sse-translator.js.map +1 -1
- package/package.json +2 -3
- package/vendor/base-oneshot-session.d.ts +0 -87
- package/vendor/base-oneshot-session.js +0 -227
- package/vendor/base-oneshot-session.js.map +0 -1
- package/vendor/circuit-breaker.d.ts +0 -21
- package/vendor/circuit-breaker.js +0 -47
- package/vendor/circuit-breaker.js.map +0 -1
- package/vendor/consensus.d.ts +0 -20
- package/vendor/consensus.js +0 -52
- package/vendor/consensus.js.map +0 -1
- package/vendor/constants.d.ts +0 -130
- package/vendor/constants.js +0 -139
- package/vendor/constants.js.map +0 -1
- package/vendor/council.d.ts +0 -67
- package/vendor/council.js +0 -913
- package/vendor/council.js.map +0 -1
- package/vendor/embedded-server.d.ts +0 -25
- package/vendor/embedded-server.js +0 -373
- package/vendor/embedded-server.js.map +0 -1
- package/vendor/inbox-manager.d.ts +0 -38
- package/vendor/inbox-manager.js +0 -111
- package/vendor/inbox-manager.js.map +0 -1
- package/vendor/index.d.ts +0 -63
- package/vendor/index.js +0 -705
- package/vendor/index.js.map +0 -1
- package/vendor/logger.d.ts +0 -16
- package/vendor/logger.js +0 -44
- package/vendor/logger.js.map +0 -1
- package/vendor/models.d.ts +0 -69
- package/vendor/models.js +0 -289
- package/vendor/models.js.map +0 -1
- package/vendor/openai-compat.d.ts +0 -197
- package/vendor/openai-compat.js +0 -765
- package/vendor/openai-compat.js.map +0 -1
- package/vendor/persistent-codex-session.d.ts +0 -16
- package/vendor/persistent-codex-session.js +0 -105
- package/vendor/persistent-codex-session.js.map +0 -1
- package/vendor/persistent-cursor-session.d.ts +0 -21
- package/vendor/persistent-cursor-session.js +0 -241
- package/vendor/persistent-cursor-session.js.map +0 -1
- package/vendor/persistent-custom-session.d.ts +0 -78
- package/vendor/persistent-custom-session.js +0 -937
- package/vendor/persistent-custom-session.js.map +0 -1
- package/vendor/persistent-gemini-session.d.ts +0 -21
- package/vendor/persistent-gemini-session.js +0 -216
- package/vendor/persistent-gemini-session.js.map +0 -1
- package/vendor/persistent-session.d.ts +0 -74
- package/vendor/persistent-session.js +0 -698
- package/vendor/persistent-session.js.map +0 -1
- package/vendor/proxy/anthropic-adapter.d.ts +0 -136
- package/vendor/proxy/anthropic-adapter.js +0 -392
- package/vendor/proxy/anthropic-adapter.js.map +0 -1
- package/vendor/proxy/handler.d.ts +0 -39
- package/vendor/proxy/handler.js +0 -323
- package/vendor/proxy/handler.js.map +0 -1
- package/vendor/proxy/schema-cleaner.d.ts +0 -11
- package/vendor/proxy/schema-cleaner.js +0 -34
- package/vendor/proxy/schema-cleaner.js.map +0 -1
- package/vendor/proxy/thought-cache.d.ts +0 -19
- package/vendor/proxy/thought-cache.js +0 -53
- package/vendor/proxy/thought-cache.js.map +0 -1
- package/vendor/session-manager.d.ts +0 -211
- package/vendor/session-manager.js +0 -1345
- package/vendor/session-manager.js.map +0 -1
- package/vendor/skill-resolver.js +0 -107
- package/vendor/types.d.ts +0 -466
- package/vendor/types.js +0 -8
- package/vendor/types.js.map +0 -1
- package/vendor/validation.d.ts +0 -31
- package/vendor/validation.js +0 -104
- package/vendor/validation.js.map +0 -1
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for one-shot (process-per-send) session engines.
|
|
3
|
-
*
|
|
4
|
-
* Shared by Codex, Gemini, and Cursor — eliminates ~200 LOC of duplication
|
|
5
|
-
* per engine. Subclasses only implement _run() (engine-specific CLI invocation)
|
|
6
|
-
* and optionally override _cleanupProc() for extra cleanup (readline, streams).
|
|
7
|
-
*/
|
|
8
|
-
import { ChildProcess } from 'node:child_process';
|
|
9
|
-
import { EventEmitter } from 'node:events';
|
|
10
|
-
import { type SessionConfig, type SessionStats, type EffortLevel, type ISession, type SessionSendOptions, type TurnResult, type CostBreakdown } from './types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Parameterizes engine-specific behavior without requiring method overrides.
|
|
13
|
-
* Passed to the BaseOneShotSession constructor by each subclass.
|
|
14
|
-
*/
|
|
15
|
-
export interface OneShotEngineConfig {
|
|
16
|
-
/** Prefix for session ID generation, e.g. 'codex', 'gemini', 'cursor' */
|
|
17
|
-
enginePrefix: string;
|
|
18
|
-
/** Fallback model for pricing lookups when session has no explicit model */
|
|
19
|
-
defaultModel: string;
|
|
20
|
-
/** Model name shown in getCost() output; defaults to defaultModel if omitted */
|
|
21
|
-
defaultModelDisplay?: string;
|
|
22
|
-
/** Whether this engine tracks cached token pricing (Codex=false, Gemini/Cursor=true) */
|
|
23
|
-
supportsCachedTokens: boolean;
|
|
24
|
-
/** Human-readable engine name for compact() no-op message */
|
|
25
|
-
engineDisplayName: string;
|
|
26
|
-
}
|
|
27
|
-
export declare abstract class BaseOneShotSession extends EventEmitter implements ISession {
|
|
28
|
-
protected options: SessionConfig;
|
|
29
|
-
protected engineBin: string;
|
|
30
|
-
protected engineCfg: OneShotEngineConfig;
|
|
31
|
-
private _isReady;
|
|
32
|
-
private _isPaused;
|
|
33
|
-
private _isBusy;
|
|
34
|
-
protected currentProc: ChildProcess | null;
|
|
35
|
-
private currentRequestId;
|
|
36
|
-
private _startTime;
|
|
37
|
-
private _history;
|
|
38
|
-
sessionId?: string;
|
|
39
|
-
protected _stats: {
|
|
40
|
-
turns: number;
|
|
41
|
-
toolCalls: number;
|
|
42
|
-
toolErrors: number;
|
|
43
|
-
tokensIn: number;
|
|
44
|
-
tokensOut: number;
|
|
45
|
-
cachedTokens: number;
|
|
46
|
-
costUsd: number;
|
|
47
|
-
lastActivity: string | null;
|
|
48
|
-
};
|
|
49
|
-
constructor(config: SessionConfig, bin: string, engineCfg: OneShotEngineConfig);
|
|
50
|
-
get pid(): number | undefined;
|
|
51
|
-
get isReady(): boolean;
|
|
52
|
-
get isPaused(): boolean;
|
|
53
|
-
get isBusy(): boolean;
|
|
54
|
-
start(): Promise<this>;
|
|
55
|
-
send(message: string | unknown[], options?: SessionSendOptions): Promise<TurnResult | {
|
|
56
|
-
requestId: number;
|
|
57
|
-
sent: boolean;
|
|
58
|
-
}>;
|
|
59
|
-
/** Engine-specific: spawn the CLI and return a TurnResult. */
|
|
60
|
-
protected abstract _run(message: string, options: SessionSendOptions): Promise<TurnResult>;
|
|
61
|
-
getStats(): SessionStats & {
|
|
62
|
-
sessionId?: string;
|
|
63
|
-
uptime: number;
|
|
64
|
-
};
|
|
65
|
-
getHistory(limit?: number): Array<{
|
|
66
|
-
time: string;
|
|
67
|
-
type: string;
|
|
68
|
-
event: unknown;
|
|
69
|
-
}>;
|
|
70
|
-
compact(_summary?: string): Promise<TurnResult>;
|
|
71
|
-
getEffort(): EffortLevel;
|
|
72
|
-
setEffort(level: EffortLevel): void;
|
|
73
|
-
getCost(): CostBreakdown;
|
|
74
|
-
resolveModel(alias: string): string;
|
|
75
|
-
pause(): void;
|
|
76
|
-
resume(): void;
|
|
77
|
-
stop(): void;
|
|
78
|
-
/** Override in subclasses that need extra cleanup (readline, stream destroy). */
|
|
79
|
-
protected _cleanupProc(): void;
|
|
80
|
-
protected _getModelPricing(): import("./models.js").ModelPricing;
|
|
81
|
-
protected _recordTurnComplete(): void;
|
|
82
|
-
protected _addHistory(event: {
|
|
83
|
-
text: string;
|
|
84
|
-
code: number | null;
|
|
85
|
-
}): void;
|
|
86
|
-
protected _updateCost(): void;
|
|
87
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for one-shot (process-per-send) session engines.
|
|
3
|
-
*
|
|
4
|
-
* Shared by Codex, Gemini, and Cursor — eliminates ~200 LOC of duplication
|
|
5
|
-
* per engine. Subclasses only implement _run() (engine-specific CLI invocation)
|
|
6
|
-
* and optionally override _cleanupProc() for extra cleanup (readline, streams).
|
|
7
|
-
*/
|
|
8
|
-
import { EventEmitter } from 'node:events';
|
|
9
|
-
import * as fs from 'node:fs';
|
|
10
|
-
import * as path from 'node:path';
|
|
11
|
-
import { getModelPricing as _getModelPricingBase, } from './types.js';
|
|
12
|
-
import { resolveAlias } from './models.js';
|
|
13
|
-
import { MAX_HISTORY_ITEMS, DEFAULT_HISTORY_LIMIT, SESSION_EVENT } from './constants.js';
|
|
14
|
-
// ─── BaseOneShotSession ────────────────────────────────────────────────────
|
|
15
|
-
export class BaseOneShotSession extends EventEmitter {
|
|
16
|
-
options;
|
|
17
|
-
engineBin;
|
|
18
|
-
engineCfg;
|
|
19
|
-
_isReady = false;
|
|
20
|
-
_isPaused = false;
|
|
21
|
-
_isBusy = false;
|
|
22
|
-
currentProc = null;
|
|
23
|
-
currentRequestId = 0;
|
|
24
|
-
_startTime = null;
|
|
25
|
-
_history = [];
|
|
26
|
-
sessionId;
|
|
27
|
-
_stats = {
|
|
28
|
-
turns: 0,
|
|
29
|
-
toolCalls: 0,
|
|
30
|
-
toolErrors: 0,
|
|
31
|
-
tokensIn: 0,
|
|
32
|
-
tokensOut: 0,
|
|
33
|
-
cachedTokens: 0,
|
|
34
|
-
costUsd: 0,
|
|
35
|
-
lastActivity: null,
|
|
36
|
-
};
|
|
37
|
-
constructor(config, bin, engineCfg) {
|
|
38
|
-
super();
|
|
39
|
-
this.engineBin = bin;
|
|
40
|
-
this.engineCfg = engineCfg;
|
|
41
|
-
this.options = {
|
|
42
|
-
...config,
|
|
43
|
-
permissionMode: config.permissionMode || 'bypassPermissions',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// ── Property Accessors ─────────────────────────────────────────────────
|
|
47
|
-
get pid() {
|
|
48
|
-
return this.currentProc?.pid ?? undefined;
|
|
49
|
-
}
|
|
50
|
-
get isReady() {
|
|
51
|
-
return this._isReady;
|
|
52
|
-
}
|
|
53
|
-
get isPaused() {
|
|
54
|
-
return this._isPaused;
|
|
55
|
-
}
|
|
56
|
-
get isBusy() {
|
|
57
|
-
return this._isBusy;
|
|
58
|
-
}
|
|
59
|
-
// ── start() ────────────────────────────────────────────────────────────
|
|
60
|
-
async start() {
|
|
61
|
-
if (this.options.cwd) {
|
|
62
|
-
this.options.cwd = path.resolve(this.options.cwd);
|
|
63
|
-
if (!fs.existsSync(this.options.cwd)) {
|
|
64
|
-
fs.mkdirSync(this.options.cwd, { recursive: true });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
this.sessionId = `${this.engineCfg.enginePrefix}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
|
68
|
-
this._startTime = new Date().toISOString();
|
|
69
|
-
this._isReady = true;
|
|
70
|
-
this.emit(SESSION_EVENT.READY);
|
|
71
|
-
this.emit(SESSION_EVENT.INIT, { type: 'system', subtype: 'init', session_id: this.sessionId });
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
// ── send() ─────────────────────────────────────────────────────────────
|
|
75
|
-
async send(message, options = {}) {
|
|
76
|
-
if (!this._isReady)
|
|
77
|
-
throw new Error('Session not ready. Call start() first.');
|
|
78
|
-
const requestId = ++this.currentRequestId;
|
|
79
|
-
const textMessage = typeof message === 'string' ? message : JSON.stringify(message);
|
|
80
|
-
if (!options.waitForComplete) {
|
|
81
|
-
this._run(textMessage, options).catch((err) => this.emit(SESSION_EVENT.ERROR, err));
|
|
82
|
-
return { requestId, sent: true };
|
|
83
|
-
}
|
|
84
|
-
this._isBusy = true;
|
|
85
|
-
try {
|
|
86
|
-
return await this._run(textMessage, options);
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
89
|
-
this._isBusy = false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// ── getStats() ─────────────────────────────────────────────────────────
|
|
93
|
-
getStats() {
|
|
94
|
-
return {
|
|
95
|
-
turns: this._stats.turns,
|
|
96
|
-
toolCalls: this._stats.toolCalls,
|
|
97
|
-
toolErrors: this._stats.toolErrors,
|
|
98
|
-
tokensIn: this._stats.tokensIn,
|
|
99
|
-
tokensOut: this._stats.tokensOut,
|
|
100
|
-
cachedTokens: this._stats.cachedTokens,
|
|
101
|
-
costUsd: Math.round(this._stats.costUsd * 10000) / 10000,
|
|
102
|
-
isReady: this._isReady,
|
|
103
|
-
startTime: this._startTime,
|
|
104
|
-
lastActivity: this._stats.lastActivity,
|
|
105
|
-
contextPercent: 0,
|
|
106
|
-
sessionId: this.sessionId,
|
|
107
|
-
uptime: this._startTime ? Math.round((Date.now() - new Date(this._startTime).getTime()) / 1000) : 0,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
// ── getHistory() ───────────────────────────────────────────────────────
|
|
111
|
-
getHistory(limit = DEFAULT_HISTORY_LIMIT) {
|
|
112
|
-
return this._history.slice(-limit);
|
|
113
|
-
}
|
|
114
|
-
// ── compact() ──────────────────────────────────────────────────────────
|
|
115
|
-
async compact(_summary) {
|
|
116
|
-
const event = {
|
|
117
|
-
type: 'result',
|
|
118
|
-
result: `${this.engineCfg.engineDisplayName} engine does not support compaction`,
|
|
119
|
-
};
|
|
120
|
-
return { text: event.result, event };
|
|
121
|
-
}
|
|
122
|
-
// ── Effort ─────────────────────────────────────────────────────────────
|
|
123
|
-
getEffort() {
|
|
124
|
-
return this.options.effort || 'auto';
|
|
125
|
-
}
|
|
126
|
-
setEffort(level) {
|
|
127
|
-
this.options.effort = level;
|
|
128
|
-
}
|
|
129
|
-
// ── getCost() ──────────────────────────────────────────────────────────
|
|
130
|
-
getCost() {
|
|
131
|
-
const pricing = this._getModelPricing();
|
|
132
|
-
const displayModel = this.options.model || this.engineCfg.defaultModelDisplay || this.engineCfg.defaultModel;
|
|
133
|
-
if (this.engineCfg.supportsCachedTokens) {
|
|
134
|
-
const cachedPrice = pricing.cached ?? 0;
|
|
135
|
-
const nonCachedIn = Math.max(0, this._stats.tokensIn - this._stats.cachedTokens);
|
|
136
|
-
return {
|
|
137
|
-
model: displayModel,
|
|
138
|
-
tokensIn: this._stats.tokensIn,
|
|
139
|
-
tokensOut: this._stats.tokensOut,
|
|
140
|
-
cachedTokens: this._stats.cachedTokens,
|
|
141
|
-
pricing: { inputPer1M: pricing.input, outputPer1M: pricing.output, cachedPer1M: cachedPrice || undefined },
|
|
142
|
-
breakdown: {
|
|
143
|
-
inputCost: (nonCachedIn / 1_000_000) * pricing.input,
|
|
144
|
-
cachedCost: (this._stats.cachedTokens / 1_000_000) * cachedPrice,
|
|
145
|
-
outputCost: (this._stats.tokensOut / 1_000_000) * pricing.output,
|
|
146
|
-
},
|
|
147
|
-
totalUsd: this._stats.costUsd,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
// Non-cached path (e.g. Codex)
|
|
151
|
-
return {
|
|
152
|
-
model: displayModel,
|
|
153
|
-
tokensIn: this._stats.tokensIn,
|
|
154
|
-
tokensOut: this._stats.tokensOut,
|
|
155
|
-
cachedTokens: 0,
|
|
156
|
-
pricing: { inputPer1M: pricing.input, outputPer1M: pricing.output, cachedPer1M: undefined },
|
|
157
|
-
breakdown: {
|
|
158
|
-
inputCost: (this._stats.tokensIn / 1_000_000) * pricing.input,
|
|
159
|
-
cachedCost: 0,
|
|
160
|
-
outputCost: (this._stats.tokensOut / 1_000_000) * pricing.output,
|
|
161
|
-
},
|
|
162
|
-
totalUsd: this._stats.costUsd,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
// ── resolveModel() ─────────────────────────────────────────────────────
|
|
166
|
-
resolveModel(alias) {
|
|
167
|
-
return resolveAlias(alias);
|
|
168
|
-
}
|
|
169
|
-
// ── pause / resume ─────────────────────────────────────────────────────
|
|
170
|
-
pause() {
|
|
171
|
-
this._isPaused = true;
|
|
172
|
-
this.emit(SESSION_EVENT.PAUSED, { sessionId: this.sessionId });
|
|
173
|
-
}
|
|
174
|
-
resume() {
|
|
175
|
-
this._isPaused = false;
|
|
176
|
-
this.emit(SESSION_EVENT.RESUMED, { sessionId: this.sessionId });
|
|
177
|
-
}
|
|
178
|
-
// ── stop() ─────────────────────────────────────────────────────────────
|
|
179
|
-
stop() {
|
|
180
|
-
this._cleanupProc();
|
|
181
|
-
this._isReady = false;
|
|
182
|
-
this._isPaused = false;
|
|
183
|
-
this.emit(SESSION_EVENT.CLOSE, 143);
|
|
184
|
-
}
|
|
185
|
-
/** Override in subclasses that need extra cleanup (readline, stream destroy). */
|
|
186
|
-
_cleanupProc() {
|
|
187
|
-
if (this.currentProc) {
|
|
188
|
-
try {
|
|
189
|
-
this.currentProc.kill('SIGTERM');
|
|
190
|
-
}
|
|
191
|
-
catch {
|
|
192
|
-
// Process may have already exited
|
|
193
|
-
}
|
|
194
|
-
this.currentProc = null;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
// ── Protected Helpers (for subclass _run() implementations) ────────────
|
|
198
|
-
_getModelPricing() {
|
|
199
|
-
return _getModelPricingBase(this.options.model, this.engineCfg.defaultModel);
|
|
200
|
-
}
|
|
201
|
-
_recordTurnComplete() {
|
|
202
|
-
this._stats.turns++;
|
|
203
|
-
this._stats.lastActivity = new Date().toISOString();
|
|
204
|
-
}
|
|
205
|
-
_addHistory(event) {
|
|
206
|
-
const now = this._stats.lastActivity || new Date().toISOString();
|
|
207
|
-
this._history.push({ time: now, type: 'result', event });
|
|
208
|
-
if (this._history.length > MAX_HISTORY_ITEMS)
|
|
209
|
-
this._history.shift();
|
|
210
|
-
}
|
|
211
|
-
_updateCost() {
|
|
212
|
-
const pricing = this._getModelPricing();
|
|
213
|
-
if (this.engineCfg.supportsCachedTokens) {
|
|
214
|
-
const cachedPrice = pricing.cached ?? 0;
|
|
215
|
-
const nonCachedIn = Math.max(0, this._stats.tokensIn - this._stats.cachedTokens);
|
|
216
|
-
this._stats.costUsd =
|
|
217
|
-
(nonCachedIn / 1_000_000) * pricing.input +
|
|
218
|
-
(this._stats.cachedTokens / 1_000_000) * cachedPrice +
|
|
219
|
-
(this._stats.tokensOut / 1_000_000) * pricing.output;
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
this._stats.costUsd =
|
|
223
|
-
(this._stats.tokensIn / 1_000_000) * pricing.input + (this._stats.tokensOut / 1_000_000) * pricing.output;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
//# sourceMappingURL=base-oneshot-session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-oneshot-session.js","sourceRoot":"","sources":["../../src/base-oneshot-session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EASL,eAAe,IAAI,oBAAoB,GACxC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAqBzF,8EAA8E;AAE9E,MAAM,OAAgB,kBAAmB,SAAQ,YAAY;IACjD,OAAO,CAAgB;IACvB,SAAS,CAAS;IAClB,SAAS,CAAsB;IAEjC,QAAQ,GAAG,KAAK,CAAC;IACjB,SAAS,GAAG,KAAK,CAAC;IAClB,OAAO,GAAG,KAAK,CAAC;IACd,WAAW,GAAwB,IAAI,CAAC;IAC1C,gBAAgB,GAAG,CAAC,CAAC;IACrB,UAAU,GAAkB,IA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E,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,iBAAiB;YAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACtE,CAAC;IAES,WAAW;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;YACxC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACjF,IAAI,CAAC,MAAM,CAAC,OAAO;gBACjB,CAAC,WAAW,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,KAAK;oBACzC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC,GAAG,WAAW;oBACpD,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,OAAO;gBACjB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9G,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Circuit breaker for engine failure tracking.
|
|
3
|
-
*
|
|
4
|
-
* Opens after CIRCUIT_BREAKER_THRESHOLD consecutive failures per engine,
|
|
5
|
-
* with exponential backoff capped at CIRCUIT_BREAKER_MAX_BACKOFF_MS.
|
|
6
|
-
* Resets on a successful engine start.
|
|
7
|
-
*/
|
|
8
|
-
export declare class CircuitBreaker {
|
|
9
|
-
private breakers;
|
|
10
|
-
/** Throws if the engine circuit is open and backoff has not yet expired. */
|
|
11
|
-
check(engine: string): void;
|
|
12
|
-
/** Record a failure — increments count and sets exponential backoff. */
|
|
13
|
-
recordFailure(engine: string): void;
|
|
14
|
-
/** Reset (clear) the breaker for an engine after a successful start. */
|
|
15
|
-
reset(engine: string): void;
|
|
16
|
-
/** Get status snapshot for health() reporting. */
|
|
17
|
-
getStatus(): Record<string, {
|
|
18
|
-
failures: number;
|
|
19
|
-
backoffUntil: string | null;
|
|
20
|
-
}>;
|
|
21
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Circuit breaker for engine failure tracking.
|
|
3
|
-
*
|
|
4
|
-
* Opens after CIRCUIT_BREAKER_THRESHOLD consecutive failures per engine,
|
|
5
|
-
* with exponential backoff capped at CIRCUIT_BREAKER_MAX_BACKOFF_MS.
|
|
6
|
-
* Resets on a successful engine start.
|
|
7
|
-
*/
|
|
8
|
-
import { CIRCUIT_BREAKER_THRESHOLD, CIRCUIT_BREAKER_BACKOFF_BASE_MS, CIRCUIT_BREAKER_MAX_BACKOFF_MS, } from './constants.js';
|
|
9
|
-
export class CircuitBreaker {
|
|
10
|
-
breakers = new Map();
|
|
11
|
-
/** Throws if the engine circuit is open and backoff has not yet expired. */
|
|
12
|
-
check(engine) {
|
|
13
|
-
const breaker = this.breakers.get(engine);
|
|
14
|
-
if (!breaker)
|
|
15
|
-
return;
|
|
16
|
-
if (breaker.count >= CIRCUIT_BREAKER_THRESHOLD && Date.now() < breaker.backoffUntil) {
|
|
17
|
-
const remaining = Math.ceil((breaker.backoffUntil - Date.now()) / 1000);
|
|
18
|
-
throw new Error(`Engine '${engine}' circuit breaker open after ${breaker.count} consecutive failures. ` +
|
|
19
|
-
`Retry in ${remaining}s.`);
|
|
20
|
-
}
|
|
21
|
-
// If backoff has expired, allow the attempt (will reset on success)
|
|
22
|
-
}
|
|
23
|
-
/** Record a failure — increments count and sets exponential backoff. */
|
|
24
|
-
recordFailure(engine) {
|
|
25
|
-
const existing = this.breakers.get(engine) || { count: 0, lastFailure: 0, backoffUntil: 0 };
|
|
26
|
-
existing.count++;
|
|
27
|
-
existing.lastFailure = Date.now();
|
|
28
|
-
const backoff = Math.min(CIRCUIT_BREAKER_BACKOFF_BASE_MS * Math.pow(2, existing.count - 1), CIRCUIT_BREAKER_MAX_BACKOFF_MS);
|
|
29
|
-
existing.backoffUntil = Date.now() + backoff;
|
|
30
|
-
this.breakers.set(engine, existing);
|
|
31
|
-
}
|
|
32
|
-
/** Reset (clear) the breaker for an engine after a successful start. */
|
|
33
|
-
reset(engine) {
|
|
34
|
-
this.breakers.delete(engine);
|
|
35
|
-
}
|
|
36
|
-
/** Get status snapshot for health() reporting. */
|
|
37
|
-
getStatus() {
|
|
38
|
-
return Object.fromEntries([...this.breakers].map(([engine, state]) => [
|
|
39
|
-
engine,
|
|
40
|
-
{
|
|
41
|
-
failures: state.count,
|
|
42
|
-
backoffUntil: state.backoffUntil > Date.now() ? new Date(state.backoffUntil).toISOString() : null,
|
|
43
|
-
},
|
|
44
|
-
]));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../src/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,gBAAgB,CAAC;AAQxB,MAAM,OAAO,cAAc;IACjB,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEnD,4EAA4E;IAC5E,KAAK,CAAC,MAAc;QAClB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CA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M,CAAC,WAAW,CACvB,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM;YACN;gBACE,QAAQ,EAAE,KAAK,CAAC,KAAK;gBACrB,YAAY,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;aAClG;SACF,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
|
package/vendor/consensus.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Consensus vote parsing utilities
|
|
3
|
-
*
|
|
4
|
-
* Ported from three-minds — detects [CONSENSUS: YES/NO] tags in agent
|
|
5
|
-
* responses with multiple fallback patterns for variant formats.
|
|
6
|
-
*/
|
|
7
|
-
/** Remove all [CONSENSUS: YES/NO] tags from text */
|
|
8
|
-
export declare function stripConsensusTags(text: string): string;
|
|
9
|
-
/** Check whether text contains any consensus vote marker */
|
|
10
|
-
export declare function hasConsensusMarker(text: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Parse a consensus vote from agent response text.
|
|
13
|
-
*
|
|
14
|
-
* Priority chain:
|
|
15
|
-
* 1. Strict format: [CONSENSUS: YES] / [CONSENSUS: NO]
|
|
16
|
-
* 2. Common variants: consensus: yes, **consensus**: no, CONSENSUS=YES, etc.
|
|
17
|
-
* 3. Tail fallback: analyse last 8 lines for positive/negative signals
|
|
18
|
-
* 4. Default: false (no consensus)
|
|
19
|
-
*/
|
|
20
|
-
export declare function parseConsensus(content: string): boolean;
|
package/vendor/consensus.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Consensus vote parsing utilities
|
|
3
|
-
*
|
|
4
|
-
* Ported from three-minds — detects [CONSENSUS: YES/NO] tags in agent
|
|
5
|
-
* responses with multiple fallback patterns for variant formats.
|
|
6
|
-
*/
|
|
7
|
-
/** Remove all [CONSENSUS: YES/NO] tags from text */
|
|
8
|
-
export function stripConsensusTags(text) {
|
|
9
|
-
return text.replace(/\[\s*CONSENSUS\s*[::]\s*(?:YES|NO)\s*\]/gi, '').trim();
|
|
10
|
-
}
|
|
11
|
-
/** Check whether text contains any consensus vote marker */
|
|
12
|
-
export function hasConsensusMarker(text) {
|
|
13
|
-
return (/\[\s*CONSENSUS\s*[::]\s*(?:YES|NO)\s*\]/i.test(text) ||
|
|
14
|
-
/consensus[:\s]+(yes|no)/i.test(text) ||
|
|
15
|
-
/共识投票[::\s]+(YES|NO)/i.test(text));
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Parse a consensus vote from agent response text.
|
|
19
|
-
*
|
|
20
|
-
* Priority chain:
|
|
21
|
-
* 1. Strict format: [CONSENSUS: YES] / [CONSENSUS: NO]
|
|
22
|
-
* 2. Common variants: consensus: yes, **consensus**: no, CONSENSUS=YES, etc.
|
|
23
|
-
* 3. Tail fallback: analyse last 8 lines for positive/negative signals
|
|
24
|
-
* 4. Default: false (no consensus)
|
|
25
|
-
*/
|
|
26
|
-
export function parseConsensus(content) {
|
|
27
|
-
// Strict format (supports Chinese colon) — take the LAST match
|
|
28
|
-
const strictMatches = [...content.matchAll(/\[\s*CONSENSUS\s*[::]\s*(YES|NO)\s*\]/gi)];
|
|
29
|
-
if (strictMatches.length > 0) {
|
|
30
|
-
return strictMatches[strictMatches.length - 1][1].toUpperCase() === 'YES';
|
|
31
|
-
}
|
|
32
|
-
// Fallback: common variants — also take the last match
|
|
33
|
-
const variantPatterns = [
|
|
34
|
-
/consensus[:\s]+(yes|no)/gi,
|
|
35
|
-
/\*\*consensus\*\*[:\s]+(yes|no)/gi,
|
|
36
|
-
/CONSENSUS=(YES|NO)/gi,
|
|
37
|
-
/共识投票[::\s]+(YES|NO)/gi,
|
|
38
|
-
/\[CONSENSUS\][:\s]+(YES|NO)/gi,
|
|
39
|
-
];
|
|
40
|
-
for (const pattern of variantPatterns) {
|
|
41
|
-
const matches = [...content.matchAll(pattern)];
|
|
42
|
-
if (matches.length > 0) {
|
|
43
|
-
return matches[matches.length - 1][1].toUpperCase() === 'YES';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// No explicit consensus tag found — default to NO.
|
|
47
|
-
// The previous tail-fallback heuristic was removed because it caused false
|
|
48
|
-
// positives when agents echoed back prompt instructions containing consensus
|
|
49
|
-
// keywords without actually voting.
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=consensus.js.map
|
package/vendor/consensus.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consensus.js","sourceRoot":"","sources":["../../src/consensus.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oDAAoD;AACpD,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,2CAA2C,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9E,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,CACL,0CAA0C,CAAC,IAAI,CAAC,IAAI,CAAC;QACrD,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC;QACrC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,+DAA+D;IAC/D,MAAM,aAAa,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,yCAAyC,CAAC,CAAC,CAAC;IACvF,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;IAC5E,CAAC;IAED,uDAAuD;IACvD,MAAM,eAAe,GAAG;QACtB,2BAA2B;QAC3B,mCAAmC;QACnC,sBAAsB;QACtB,uBAAuB;QACvB,+BAA+B;KAChC,CAAC;IACF,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/C,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;QAChE,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,2EAA2E;IAC3E,6EAA6E;IAC7E,oCAAoC;IACpC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/vendor/constants.d.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared constants — consolidates magic numbers scattered across the codebase.
|
|
3
|
-
*
|
|
4
|
-
* Grouped by domain. Import what you need rather than using inline numbers.
|
|
5
|
-
*/
|
|
6
|
-
/** Token threshold that triggers the onContextHigh hook */
|
|
7
|
-
export declare const CONTEXT_HIGH_THRESHOLD = 140000;
|
|
8
|
-
/** Max history entries kept in memory per session (oldest evicted via shift) */
|
|
9
|
-
export declare const MAX_HISTORY_ITEMS = 100;
|
|
10
|
-
/** Default number of history entries returned by getHistory() */
|
|
11
|
-
export declare const DEFAULT_HISTORY_LIMIT = 50;
|
|
12
|
-
/** Number of history entries fetched for grep operations */
|
|
13
|
-
export declare const GREP_HISTORY_FETCH = 500;
|
|
14
|
-
/** Wait for session init/ready event after spawn */
|
|
15
|
-
export declare const SESSION_READY_TIMEOUT_MS = 30000;
|
|
16
|
-
/** Fallback delay before checking if proc is alive (resume path) */
|
|
17
|
-
export declare const SESSION_READY_FALLBACK_MS = 2000;
|
|
18
|
-
/** Default timeout for a send() / turn completion */
|
|
19
|
-
export declare const TURN_TIMEOUT_MS = 300000;
|
|
20
|
-
/** Timeout for compact / context summary operations */
|
|
21
|
-
export declare const COMPACT_TIMEOUT_MS = 60000;
|
|
22
|
-
/** Delay before SIGKILL after initial SIGTERM on stop() */
|
|
23
|
-
export declare const STOP_SIGKILL_DELAY_MS = 3000;
|
|
24
|
-
/** Timeout for most git CLI operations (branch, checkout, log, diff) */
|
|
25
|
-
export declare const GIT_CMD_TIMEOUT_MS = 5000;
|
|
26
|
-
/** Timeout for git worktree add/remove (heavier operations) */
|
|
27
|
-
export declare const WORKTREE_CMD_TIMEOUT_MS = 10000;
|
|
28
|
-
/** Default per-agent timeout in council */
|
|
29
|
-
export declare const DEFAULT_AGENT_TIMEOUT_MS = 1800000;
|
|
30
|
-
/** Delay between council rounds */
|
|
31
|
-
export declare const INTER_ROUND_DELAY_MS = 3000;
|
|
32
|
-
/** Delay before retrying on empty agent response */
|
|
33
|
-
export declare const EMPTY_RESPONSE_RETRY_DELAY_MS = 5000;
|
|
34
|
-
/** Timeout for council follow-up prompts */
|
|
35
|
-
export declare const FOLLOWUP_TIMEOUT_MS = 60000;
|
|
36
|
-
/** Timeout for team list operations */
|
|
37
|
-
export declare const TEAM_LIST_TIMEOUT_MS = 30000;
|
|
38
|
-
/** Timeout for team send operations */
|
|
39
|
-
export declare const TEAM_SEND_TIMEOUT_MS = 120000;
|
|
40
|
-
/** Timeout for ultraplan sessions */
|
|
41
|
-
export declare const ULTRAPLAN_TIMEOUT_MS = 1800000;
|
|
42
|
-
/** How long completed results remain queryable */
|
|
43
|
-
export declare const RESULT_TTL_MS = 1800000;
|
|
44
|
-
/** Session TTL cleanup check interval */
|
|
45
|
-
export declare const CLEANUP_INTERVAL_MS = 60000;
|
|
46
|
-
/** Debounce delay for persisted session writes */
|
|
47
|
-
export declare const DEBOUNCED_SAVE_MS = 5000;
|
|
48
|
-
/** Persisted sessions disk TTL (7 days) */
|
|
49
|
-
export declare const PERSIST_DISK_TTL_MS: number;
|
|
50
|
-
/** Fetch timeout for proxy forward requests */
|
|
51
|
-
export declare const FETCH_TIMEOUT_MS = 600000;
|
|
52
|
-
/** Ultrareview polling interval */
|
|
53
|
-
export declare const ULTRAREVIEW_POLL_INTERVAL_MS = 5000;
|
|
54
|
-
/** Default port for the embedded HTTP server */
|
|
55
|
-
export declare const DEFAULT_SERVER_PORT = 18796;
|
|
56
|
-
/** Maximum request body size (5 MB) */
|
|
57
|
-
export declare const MAX_BODY_SIZE = 5242880;
|
|
58
|
-
/** Rate limit: max requests per window per IP */
|
|
59
|
-
export declare const RATE_LIMIT_MAX_REQUESTS = 300;
|
|
60
|
-
/** Rate limit: sliding window duration */
|
|
61
|
-
export declare const RATE_LIMIT_WINDOW_MS = 60000;
|
|
62
|
-
/** Minimum task description length */
|
|
63
|
-
export declare const MIN_TASK_LENGTH = 5;
|
|
64
|
-
/** Max retries for empty agent responses */
|
|
65
|
-
export declare const EMPTY_RESPONSE_MAX_RETRIES = 2;
|
|
66
|
-
/** Minimum response length to consider complete */
|
|
67
|
-
export declare const MIN_COMPLETE_RESPONSE_LENGTH = 100;
|
|
68
|
-
/** Max follow-up retries per agent */
|
|
69
|
-
export declare const FOLLOWUP_MAX_RETRIES = 2;
|
|
70
|
-
/** Character limit for history preview in council prompts */
|
|
71
|
-
export declare const HISTORY_PREVIEW_CHARS = 1500;
|
|
72
|
-
/** Character limit for agent summary in review */
|
|
73
|
-
export declare const SUMMARY_PREVIEW_CHARS = 500;
|
|
74
|
-
/** Character limit for short summary in transcript */
|
|
75
|
-
export declare const SUMMARY_SHORT_CHARS = 400;
|
|
76
|
-
/** Character limit for compact context */
|
|
77
|
-
export declare const COMPACT_CONTEXT_CHARS = 300;
|
|
78
|
-
/** Default max rounds in council collaboration */
|
|
79
|
-
export declare const DEFAULT_MAX_ROUNDS = 15;
|
|
80
|
-
/** Default max turns per agent */
|
|
81
|
-
export declare const DEFAULT_MAX_TURNS_PER_AGENT = 50;
|
|
82
|
-
/** Git log depth for council review */
|
|
83
|
-
export declare const GIT_LOG_DEPTH = 50;
|
|
84
|
-
/** Max messages per session inbox */
|
|
85
|
-
export declare const MAX_INBOX_SIZE = 200;
|
|
86
|
-
/** Consecutive failures before circuit opens */
|
|
87
|
-
export declare const CIRCUIT_BREAKER_THRESHOLD = 3;
|
|
88
|
-
/** Base backoff delay (doubles each failure) */
|
|
89
|
-
export declare const CIRCUIT_BREAKER_BACKOFF_BASE_MS = 1000;
|
|
90
|
-
/** Maximum backoff duration cap */
|
|
91
|
-
export declare const CIRCUIT_BREAKER_MAX_BACKOFF_MS = 300000;
|
|
92
|
-
export declare const SESSION_EVENT: {
|
|
93
|
-
readonly READY: "ready";
|
|
94
|
-
readonly INIT: "init";
|
|
95
|
-
readonly TEXT: "text";
|
|
96
|
-
readonly TOOL_USE: "tool_use";
|
|
97
|
-
readonly TOOL_RESULT: "tool_result";
|
|
98
|
-
readonly RESULT: "result";
|
|
99
|
-
readonly TURN_COMPLETE: "turn_complete";
|
|
100
|
-
readonly ERROR: "error";
|
|
101
|
-
readonly LOG: "log";
|
|
102
|
-
readonly CLOSE: "close";
|
|
103
|
-
readonly PAUSED: "paused";
|
|
104
|
-
readonly RESUMED: "resumed";
|
|
105
|
-
readonly SYSTEM: "system";
|
|
106
|
-
readonly STREAM_EVENT: "stream_event";
|
|
107
|
-
readonly USER_ECHO: "user_echo";
|
|
108
|
-
readonly ASSISTANT: "assistant";
|
|
109
|
-
readonly EVENT: "event";
|
|
110
|
-
};
|
|
111
|
-
export type SessionEventName = (typeof SESSION_EVENT)[keyof typeof SESSION_EVENT];
|
|
112
|
-
/** Default model when the OpenAI-compat request omits `model` */
|
|
113
|
-
export declare const OPENAI_COMPAT_DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
114
|
-
/** Context utilization % threshold for auto-compact */
|
|
115
|
-
export declare const OPENAI_COMPAT_AUTO_COMPACT_THRESHOLD = 80;
|
|
116
|
-
/** Session name prefix for OpenAI-compat sessions */
|
|
117
|
-
export declare const OPENAI_COMPAT_SESSION_PREFIX = "openai-";
|
|
118
|
-
/**
|
|
119
|
-
* Default for the legacy new-conversation heuristic gate.
|
|
120
|
-
*
|
|
121
|
-
* When env var `OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1` is set, the old
|
|
122
|
-
* "system + single user ⇒ new conversation" rule is restored for webchat
|
|
123
|
-
* frontends (ChatGPT-Next-Web, Open WebUI, etc) that re-send the full
|
|
124
|
-
* transcript every turn. Default off: assumes upstream clients forward
|
|
125
|
-
* only the latest turn (OpenClaw main agent loop, cron jobs, subagents).
|
|
126
|
-
*
|
|
127
|
-
* The constant exists as a documentation anchor; openai-compat.ts reads
|
|
128
|
-
* the env var directly so the value can be flipped without restart.
|
|
129
|
-
*/
|
|
130
|
-
export declare const OPENAI_COMPAT_NEW_CONVO_HEURISTIC_DEFAULT = false;
|