@a1hvdy/cc-openclaw 0.7.1 → 0.9.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/command-router/cc-handler.js +11 -3
- package/dist/src/command-router/cc-handler.js.map +1 -1
- package/dist/src/engines/persistent-session.d.ts +1 -0
- package/dist/src/engines/persistent-session.js +35 -1
- package/dist/src/engines/persistent-session.js.map +1 -1
- package/dist/src/index.d.ts +10 -1
- package/dist/src/index.js +47 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/config-service.d.ts +106 -0
- package/dist/src/lib/config-service.js +217 -0
- package/dist/src/lib/config-service.js.map +1 -0
- package/dist/src/lib/config.d.ts +33 -14
- package/dist/src/lib/config.js +147 -34
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/index.d.ts +1 -1
- package/dist/src/lib/index.js +4 -1
- package/dist/src/lib/index.js.map +1 -1
- package/dist/src/openai-compat/message-extractor.d.ts +79 -0
- package/dist/src/openai-compat/message-extractor.js +134 -0
- package/dist/src/openai-compat/message-extractor.js.map +1 -0
- package/dist/src/openai-compat/mode-flags.d.ts +34 -0
- package/dist/src/openai-compat/mode-flags.js +44 -0
- package/dist/src/openai-compat/mode-flags.js.map +1 -0
- package/dist/src/openai-compat/non-streaming-handler.d.ts +26 -0
- package/dist/src/openai-compat/non-streaming-handler.js +108 -0
- package/dist/src/openai-compat/non-streaming-handler.js.map +1 -0
- package/dist/src/openai-compat/openai-compat.d.ts +15 -166
- package/dist/src/openai-compat/openai-compat.js +72 -817
- package/dist/src/openai-compat/openai-compat.js.map +1 -1
- package/dist/src/openai-compat/prompts.d.ts +47 -0
- package/dist/src/openai-compat/prompts.js +119 -0
- package/dist/src/openai-compat/prompts.js.map +1 -0
- package/dist/src/openai-compat/response-formatter.d.ts +33 -0
- package/dist/src/openai-compat/response-formatter.js +74 -0
- package/dist/src/openai-compat/response-formatter.js.map +1 -0
- package/dist/src/openai-compat/session-key-resolver.d.ts +41 -0
- package/dist/src/openai-compat/session-key-resolver.js +78 -0
- package/dist/src/openai-compat/session-key-resolver.js.map +1 -0
- package/dist/src/openai-compat/status-reporter.d.ts +30 -0
- package/dist/src/openai-compat/status-reporter.js +81 -0
- package/dist/src/openai-compat/status-reporter.js.map +1 -0
- package/dist/src/openai-compat/streaming-handler.d.ts +41 -0
- package/dist/src/openai-compat/streaming-handler.js +294 -0
- package/dist/src/openai-compat/streaming-handler.js.map +1 -0
- package/dist/src/openai-compat/tool-calls-parser.d.ts +34 -0
- package/dist/src/openai-compat/tool-calls-parser.js +93 -0
- package/dist/src/openai-compat/tool-calls-parser.js.map +1 -0
- package/dist/src/openai-compat/tool-results-serializer.d.ts +60 -0
- package/dist/src/openai-compat/tool-results-serializer.js +56 -0
- package/dist/src/openai-compat/tool-results-serializer.js.map +1 -0
- package/dist/src/session/session-manager.js +12 -0
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/src/session-bootstrap/cwd-patch.js +30 -13
- package/dist/src/session-bootstrap/cwd-patch.js.map +1 -1
- package/dist/src/types/index.d.ts +15 -0
- package/dist/src/types/index.js +16 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/route.d.ts +41 -0
- package/dist/src/types/route.js +12 -0
- package/dist/src/types/route.js.map +1 -0
- package/dist/src/types/runtime-config.d.ts +161 -0
- package/dist/src/types/runtime-config.js +118 -0
- package/dist/src/types/runtime-config.js.map +1 -0
- package/dist/src/types/session.d.ts +48 -0
- package/dist/src/types/session.js +20 -0
- package/dist/src/types/session.js.map +1 -0
- package/dist/src/types/sse.d.ts +38 -0
- package/dist/src/types/sse.js +12 -0
- package/dist/src/types/sse.js.map +1 -0
- package/dist/src/types/tool-bridge.d.ts +81 -0
- package/dist/src/types/tool-bridge.js +34 -0
- package/dist/src/types/tool-bridge.js.map +1 -0
- package/dist/src/types/upstream.d.ts +652 -0
- package/dist/src/types/upstream.js +145 -0
- package/dist/src/types/upstream.js.map +1 -0
- package/package.json +3 -2
- package/dist/src/lib/route-flag.d.ts +0 -49
- package/dist/src/lib/route-flag.js +0 -52
- package/dist/src/lib/route-flag.js.map +0 -1
package/dist/src/lib/config.js
CHANGED
|
@@ -1,43 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* config —
|
|
2
|
+
* config — env-reader source of truth.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* `src/lib/route-flag.ts`, and this module.
|
|
6
|
-
*
|
|
4
|
+
* Originally PRP_v3 §5: `process.env` reads only in `src/index.ts`,
|
|
5
|
+
* `src/lib/route-flag.ts`, and this module. Cluster A step 7 layered a
|
|
6
|
+
* compat shim on top: getters now delegate to `ConfigService.config.X`
|
|
7
|
+
* (the typed Cluster A boot config) when available, falling back to
|
|
8
|
+
* the original `process.env.X` read otherwise.
|
|
7
9
|
*
|
|
8
|
-
* Why
|
|
9
|
-
* `process.env.X = 'y'` and expect immediate effect.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Why the shim instead of pure delegation: tests flip env vars at
|
|
11
|
+
* runtime via `process.env.X = 'y'` and expect immediate effect. When
|
|
12
|
+
* `ConfigService` is unset (most tests), getters fall through to env
|
|
13
|
+
* — preserving test flippability bit-for-bit. When `ConfigService` is
|
|
14
|
+
* set (live gateway boot), the typed config wins, providing single-
|
|
15
|
+
* source-of-truth observability via `/health` and the boot log.
|
|
13
16
|
*
|
|
14
|
-
* Adding a new env var: add a getter here
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* Adding a new env var: add a getter here AND a field to
|
|
18
|
+
* `RuntimeConfigSchema` in `src/types/runtime-config.ts`. The shim line
|
|
19
|
+
* pattern is `getConfigService()?.config.X ?? legacyEnvRead`.
|
|
20
|
+
*
|
|
21
|
+
* Cluster A step 8 will collapse the activation getters (selectEngine,
|
|
22
|
+
* route-flag) into ConfigService escape hatches and delete
|
|
23
|
+
* `src/lib/route-flag.ts`. Cluster F (v1.0.0) will remove the legacy
|
|
24
|
+
* env-read fallback and hard-fail when ConfigService is missing.
|
|
17
25
|
*/
|
|
18
26
|
import { RATE_LIMIT_MAX_REQUESTS } from '../constants.js';
|
|
27
|
+
import { getConfigService } from './config-service.js';
|
|
19
28
|
// ── Sysprompt strip (PRP_v3 §10) ─────────────────────────────────────────
|
|
20
29
|
// Default ON. Opt-out via OPENCLAW_AGGRESSIVE_STRIP=0|false|off (exact-match,
|
|
21
30
|
// case-sensitive — preserved bit-for-bit from sysprompt-strip.ts:43-45 to
|
|
22
31
|
// avoid breaking the 18 existing strip tests).
|
|
23
32
|
export function getAggressiveStripEnabled() {
|
|
33
|
+
const cfg = getConfigService();
|
|
34
|
+
if (cfg)
|
|
35
|
+
return cfg.config.aggressiveStripEnabled;
|
|
24
36
|
const env = process.env.OPENCLAW_AGGRESSIVE_STRIP;
|
|
25
37
|
if (env === '0' || env === 'false' || env === 'off')
|
|
26
38
|
return false;
|
|
27
39
|
return true;
|
|
28
40
|
}
|
|
29
|
-
// ── Cache parity
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// strict opt-in via `=== '1'`). Both currently key on OPENCLAW_CACHE_PARITY,
|
|
37
|
-
// which is a latent bug — flipping the env var doesn't switch them in lock
|
|
38
|
-
// step. Tracked for B5-followup; B5-heavy preserves existing call-site
|
|
39
|
-
// semantics bit-for-bit.
|
|
41
|
+
// ── Cache parity (Cluster A: dual-default split resolved) ────────────────
|
|
42
|
+
// Pre-existing latent bug at config.ts:39-42 (now historical):
|
|
43
|
+
// getCacheParityEnabled → default ON → maps to cacheParityModuleEnabled
|
|
44
|
+
// isCacheParityTrackB → default OFF → maps to cacheParityTrackB
|
|
45
|
+
// Both currently key on OPENCLAW_CACHE_PARITY. The split resolves the
|
|
46
|
+
// documentation question — the bug is preserved as a feature per the
|
|
47
|
+
// behavior-identical mandate of Phase 4 (PRP §3 + §11 Decision Log).
|
|
40
48
|
export function getCacheParityEnabled() {
|
|
49
|
+
const cfg = getConfigService();
|
|
50
|
+
if (cfg)
|
|
51
|
+
return cfg.config.cacheParityModuleEnabled;
|
|
41
52
|
const env = process.env.OPENCLAW_CACHE_PARITY;
|
|
42
53
|
if (env === '0' || env === 'false' || env === 'off')
|
|
43
54
|
return false;
|
|
@@ -45,11 +56,17 @@ export function getCacheParityEnabled() {
|
|
|
45
56
|
}
|
|
46
57
|
/** Strict opt-in variant used by cwd-patch route patch (Track B append). */
|
|
47
58
|
export function isCacheParityTrackB() {
|
|
59
|
+
const cfg = getConfigService();
|
|
60
|
+
if (cfg)
|
|
61
|
+
return cfg.config.cacheParityTrackB;
|
|
48
62
|
return process.env.OPENCLAW_CACHE_PARITY === '1';
|
|
49
63
|
}
|
|
50
64
|
// ── Log level (PRP_v3 §10) ───────────────────────────────────────────────
|
|
51
65
|
// Returns raw string for the logger to parse. Empty/unset → undefined; the
|
|
52
66
|
// caller decides the default (logger.ts uses 'info').
|
|
67
|
+
//
|
|
68
|
+
// NOT in RuntimeConfig — log level is consumed by the logger module which
|
|
69
|
+
// has its own validation surface. Kept as a direct env reader.
|
|
53
70
|
export function getLogLevel() {
|
|
54
71
|
const v = process.env.OPENCLAW_LOG_LEVEL;
|
|
55
72
|
return v === undefined || v === null || v === '' ? undefined : v;
|
|
@@ -58,20 +75,35 @@ export function getLogLevel() {
|
|
|
58
75
|
export function isLogLevelDebug() {
|
|
59
76
|
return getLogLevel() === 'debug';
|
|
60
77
|
}
|
|
61
|
-
// ── Telemetry & diagnostics (
|
|
62
|
-
//
|
|
78
|
+
// ── Telemetry & diagnostics (Cluster A: dual-default split resolved) ─────
|
|
79
|
+
// Pre-existing latent bug at config.ts:195-197 (now historical):
|
|
80
|
+
// isTokenTelemetryEnabled → default OFF → tokenTelemetryRouteGate
|
|
81
|
+
// isTokenTelemetryWriterEnabled → default ON → tokenTelemetryWriter
|
|
82
|
+
// Same env var, opposite defaults. Preserved as features per Phase 4.
|
|
63
83
|
export function isTokenTelemetryEnabled() {
|
|
84
|
+
const cfg = getConfigService();
|
|
85
|
+
if (cfg)
|
|
86
|
+
return cfg.config.tokenTelemetryRouteGate;
|
|
64
87
|
return process.env.OPENCLAW_TOKEN_TELEMETRY === '1';
|
|
65
88
|
}
|
|
66
89
|
export function isSyspromptDumpEnabled() {
|
|
90
|
+
const cfg = getConfigService();
|
|
91
|
+
if (cfg)
|
|
92
|
+
return cfg.config.syspromptDump;
|
|
67
93
|
return process.env.OPENCLAW_SYSPROMPT_DUMP === '1';
|
|
68
94
|
}
|
|
69
95
|
// ── SessionManager bootstrap caps (cwd-patch eager-init) ─────────────────
|
|
70
96
|
// Defaults preserved from cwd-patch.ts:844-845.
|
|
71
97
|
export function getMaxConcurrentSessions() {
|
|
98
|
+
const cfg = getConfigService();
|
|
99
|
+
if (cfg)
|
|
100
|
+
return cfg.config.maxConcurrentSessions;
|
|
72
101
|
return parseInt(process.env.CLAUDE_CODE_MAX_SESSIONS || '', 10) || 32;
|
|
73
102
|
}
|
|
74
103
|
export function getSessionTtlMinutes() {
|
|
104
|
+
const cfg = getConfigService();
|
|
105
|
+
if (cfg)
|
|
106
|
+
return cfg.config.sessionTtlMinutes;
|
|
75
107
|
return parseInt(process.env.CLAUDE_CODE_SESSION_TTL || '', 10) || 1440;
|
|
76
108
|
}
|
|
77
109
|
// ── UX bridge bootstrap (cwd-patch register hook) ────────────────────────
|
|
@@ -79,6 +111,9 @@ export function getSessionTtlMinutes() {
|
|
|
79
111
|
// Returns { mutated, value } so the caller can log accurately. Centralized
|
|
80
112
|
// here because it's the one process.env *write* outside index/route-flag.
|
|
81
113
|
//
|
|
114
|
+
// NOT in RuntimeConfig — this getter MUTATES process.env, which violates
|
|
115
|
+
// the frozen-at-boot contract. Kept as a direct env reader/writer.
|
|
116
|
+
//
|
|
82
117
|
// Behavior preserved bit-for-bit from cwd-patch.ts:983-988.
|
|
83
118
|
export function ensureUxBridgeAllSessionsDefault() {
|
|
84
119
|
const current = process.env.UX_BRIDGE_ALL_SESSIONS;
|
|
@@ -90,22 +125,36 @@ export function ensureUxBridgeAllSessionsDefault() {
|
|
|
90
125
|
}
|
|
91
126
|
// ── Embedded HTTP server (src/session/embedded-server.ts) ────────────────
|
|
92
127
|
export function getServerHost() {
|
|
128
|
+
const cfg = getConfigService();
|
|
129
|
+
if (cfg)
|
|
130
|
+
return cfg.config.serverHost;
|
|
93
131
|
return process.env.OPENCLAW_SERVER_HOST || '127.0.0.1';
|
|
94
132
|
}
|
|
95
133
|
/** Per-IP rate limit; falls back to RATE_LIMIT_MAX_REQUESTS if unset/invalid. */
|
|
96
134
|
export function getRateLimit() {
|
|
135
|
+
const cfg = getConfigService();
|
|
136
|
+
if (cfg)
|
|
137
|
+
return cfg.config.rateLimit;
|
|
97
138
|
return parseInt(process.env.OPENCLAW_RATE_LIMIT || '', 10) || RATE_LIMIT_MAX_REQUESTS;
|
|
98
139
|
}
|
|
99
140
|
/** Bearer token for embedded server. Undefined → no auth (default). */
|
|
100
141
|
export function getServerToken() {
|
|
142
|
+
const cfg = getConfigService();
|
|
143
|
+
if (cfg)
|
|
144
|
+
return cfg.config.serverToken;
|
|
101
145
|
const t = process.env.OPENCLAW_SERVER_TOKEN;
|
|
102
146
|
return t === undefined || t === '' ? undefined : t;
|
|
103
147
|
}
|
|
104
148
|
/** True iff CORS is wildcarded via OPENCLAW_CORS_ORIGINS=*. */
|
|
105
149
|
export function isCorsAllowAll() {
|
|
150
|
+
const cfg = getConfigService();
|
|
151
|
+
if (cfg)
|
|
152
|
+
return cfg.config.corsAllowAll;
|
|
106
153
|
return process.env.OPENCLAW_CORS_ORIGINS === '*';
|
|
107
154
|
}
|
|
108
155
|
// ── Gateway proxy (src/session/session-manager.ts) ───────────────────────
|
|
156
|
+
// NOT in RuntimeConfig — gateway URL/key are reverse-proxy internals not
|
|
157
|
+
// surfaced through the activation flag matrix. Kept as direct env readers.
|
|
109
158
|
export function getGatewayUrl() {
|
|
110
159
|
const v = process.env.GATEWAY_URL;
|
|
111
160
|
return v === undefined || v === '' ? undefined : v;
|
|
@@ -115,8 +164,8 @@ export function getGatewayKey() {
|
|
|
115
164
|
return v === undefined || v === '' ? undefined : v;
|
|
116
165
|
}
|
|
117
166
|
// ── Provider API keys (session-manager → proxy handler) ──────────────────
|
|
118
|
-
//
|
|
119
|
-
//
|
|
167
|
+
// NOT in RuntimeConfig — secrets that must never appear in /health or boot
|
|
168
|
+
// telemetry. Kept as direct env readers for principle-of-least-disclosure.
|
|
120
169
|
export function getAnthropicApiKey() {
|
|
121
170
|
const v = process.env.ANTHROPIC_API_KEY;
|
|
122
171
|
return v === undefined || v === '' ? undefined : v;
|
|
@@ -133,18 +182,30 @@ export function getGeminiApiKey() {
|
|
|
133
182
|
// Returns undefined when unset so the persistent-*-session constructors
|
|
134
183
|
// fall back to their built-in default (e.g. 'gemini', 'agent').
|
|
135
184
|
export function getGeminiBin() {
|
|
185
|
+
const cfg = getConfigService();
|
|
186
|
+
if (cfg)
|
|
187
|
+
return cfg.config.geminiBin;
|
|
136
188
|
const v = process.env.GEMINI_BIN;
|
|
137
189
|
return v === undefined || v === '' ? undefined : v;
|
|
138
190
|
}
|
|
139
191
|
export function getCodexBin() {
|
|
192
|
+
const cfg = getConfigService();
|
|
193
|
+
if (cfg)
|
|
194
|
+
return cfg.config.codexBin;
|
|
140
195
|
const v = process.env.CODEX_BIN;
|
|
141
196
|
return v === undefined || v === '' ? undefined : v;
|
|
142
197
|
}
|
|
143
198
|
export function getCursorBin() {
|
|
199
|
+
const cfg = getConfigService();
|
|
200
|
+
if (cfg)
|
|
201
|
+
return cfg.config.cursorBin;
|
|
144
202
|
const v = process.env.CURSOR_BIN;
|
|
145
203
|
return v === undefined || v === '' ? undefined : v;
|
|
146
204
|
}
|
|
147
205
|
export function getClaudeBin() {
|
|
206
|
+
const cfg = getConfigService();
|
|
207
|
+
if (cfg)
|
|
208
|
+
return cfg.config.claudeBin;
|
|
148
209
|
const v = process.env.CLAUDE_BIN;
|
|
149
210
|
return v === undefined || v === '' ? undefined : v;
|
|
150
211
|
}
|
|
@@ -152,50 +213,75 @@ export function getClaudeBin() {
|
|
|
152
213
|
* PATH passed to spawned engine subprocesses. Falls back to the standard
|
|
153
214
|
* Unix path so binaries resolve even when the parent's PATH is unset
|
|
154
215
|
* (preserved from persistent-session.ts:257 + persistent-custom-session.ts:240).
|
|
216
|
+
*
|
|
217
|
+
* NOT in RuntimeConfig — PATH is process-environment, not plugin
|
|
218
|
+
* configuration. Kept as a direct env reader.
|
|
155
219
|
*/
|
|
156
220
|
export function getProcessPath() {
|
|
157
221
|
return process.env.PATH || '/usr/local/bin:/usr/bin:/bin';
|
|
158
222
|
}
|
|
159
|
-
// ── Telemetry
|
|
160
|
-
//
|
|
161
|
-
// NOTE the divergence from `isTokenTelemetryEnabled()` above (which is the
|
|
162
|
-
// cwd-patch route-patch gate, default-OFF, strict `=== '1'`). Same env var,
|
|
163
|
-
// opposite defaults — pre-existing latent bug. Tracked for unification.
|
|
223
|
+
// ── Telemetry writer (Cluster A: dual-default split resolved) ────────────
|
|
224
|
+
// See `isTokenTelemetryEnabled` above for the split rationale.
|
|
164
225
|
export function isTokenTelemetryWriterEnabled() {
|
|
226
|
+
const cfg = getConfigService();
|
|
227
|
+
if (cfg)
|
|
228
|
+
return cfg.config.tokenTelemetryWriter;
|
|
165
229
|
return process.env.OPENCLAW_TOKEN_TELEMETRY !== '0';
|
|
166
230
|
}
|
|
167
231
|
/** Strict opt-in — register-guard event logging via OPENCLAW_REGISTER_DEBUG=1. */
|
|
168
232
|
export function isRegisterDebugEnabled() {
|
|
233
|
+
const cfg = getConfigService();
|
|
234
|
+
if (cfg)
|
|
235
|
+
return cfg.config.registerDebug;
|
|
169
236
|
return process.env.OPENCLAW_REGISTER_DEBUG === '1';
|
|
170
237
|
}
|
|
171
238
|
// ── Heartbeat workaround kill-switch (src/lib/heartbeat-workaround.ts) ───
|
|
172
239
|
// Strict opt-in — set CC_OPENCLAW_DISABLE_HEARTBEAT_WORKAROUND=1 to bypass.
|
|
173
240
|
export function isHeartbeatWorkaroundDisabled() {
|
|
241
|
+
const cfg = getConfigService();
|
|
242
|
+
if (cfg)
|
|
243
|
+
return cfg.config.heartbeatWorkaroundDisabled;
|
|
174
244
|
return process.env.CC_OPENCLAW_DISABLE_HEARTBEAT_WORKAROUND === '1';
|
|
175
245
|
}
|
|
176
246
|
// ── Telegram quota auto-pause (src/channels/telegram/live-card.ts) ───────
|
|
177
247
|
// Returns parsed percent threshold (0-100). Default 95.
|
|
178
248
|
export function getQuotaPausePct() {
|
|
249
|
+
const cfg = getConfigService();
|
|
250
|
+
if (cfg)
|
|
251
|
+
return cfg.config.quotaPausePct;
|
|
179
252
|
const n = Number(process.env.OPENCLAW_QUOTA_PAUSE_PCT);
|
|
180
253
|
return Number.isFinite(n) ? n : 95;
|
|
181
254
|
}
|
|
182
255
|
// ── OpenAI-compat shim (src/openai-compat/openai-compat.ts) ──────────────
|
|
183
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* Raw value for `isToolsPerMessageModeEnabled()` parsing.
|
|
258
|
+
* NOT delegated — the consumer parses the raw string itself; the typed
|
|
259
|
+
* `toolsPerMessage` boolean field is for boot-time observability only.
|
|
260
|
+
*/
|
|
184
261
|
export function getOpenaiCompatToolsPerMessage() {
|
|
185
262
|
const v = process.env.OPENAI_COMPAT_TOOLS_PER_MESSAGE;
|
|
186
263
|
return v === undefined || v === '' ? undefined : v;
|
|
187
264
|
}
|
|
188
265
|
/** Strict opt-in — legacy new-conversation heuristic via env=1. */
|
|
189
266
|
export function isOpenaiCompatNewConvoHeuristic() {
|
|
267
|
+
const cfg = getConfigService();
|
|
268
|
+
if (cfg)
|
|
269
|
+
return cfg.config.newConvoHeuristic;
|
|
190
270
|
return process.env.OPENAI_COMPAT_NEW_CONVO_HEURISTIC === '1';
|
|
191
271
|
}
|
|
192
272
|
export function getOpenaiCompatStatusUrl() {
|
|
273
|
+
const cfg = getConfigService();
|
|
274
|
+
if (cfg)
|
|
275
|
+
return cfg.config.statusUrl;
|
|
193
276
|
const v = process.env.OPENAI_COMPAT_STATUS_URL;
|
|
194
277
|
return v === undefined || v === '' ? undefined : v;
|
|
195
278
|
}
|
|
196
279
|
// ── UX bridge sessions read-only check (src/channels/telegram/event-reducer.ts) ──
|
|
197
280
|
// Read-only counterpart to `ensureUxBridgeAllSessionsDefault()` — used in
|
|
198
281
|
// hot-path event handlers where the value is treated as a truthy gate.
|
|
282
|
+
//
|
|
283
|
+
// NOT in RuntimeConfig — its peer `ensureUxBridgeAllSessionsDefault` mutates
|
|
284
|
+
// env, so both must read live env to stay coherent.
|
|
199
285
|
export function getUxBridgeAllSessions() {
|
|
200
286
|
const v = process.env.UX_BRIDGE_ALL_SESSIONS;
|
|
201
287
|
return v === undefined || v === '' ? undefined : v;
|
|
@@ -203,24 +289,35 @@ export function getUxBridgeAllSessions() {
|
|
|
203
289
|
// ── Anthropic base URL (src/proxy/handler.ts layer 1) ────────────────────
|
|
204
290
|
// proxy/handler.ts owns the higher-level resolver
|
|
205
291
|
// (env → openclaw.json → default); this getter only exposes the raw env.
|
|
292
|
+
//
|
|
293
|
+
// NOT in RuntimeConfig — it's an upstream override resolved at request
|
|
294
|
+
// time, not boot time.
|
|
206
295
|
export function getAnthropicBaseUrlEnv() {
|
|
207
296
|
const v = process.env.ANTHROPIC_BASE_URL;
|
|
208
297
|
return v === undefined || v === '' ? undefined : v;
|
|
209
298
|
}
|
|
210
299
|
// ── Savvy live card gate (src/channels/telegram/tool-tracker.ts) ─────────
|
|
211
300
|
export function isSavvyLiveCardEnabled() {
|
|
301
|
+
const cfg = getConfigService();
|
|
302
|
+
if (cfg)
|
|
303
|
+
return cfg.config.savvyLiveCardEnabled;
|
|
212
304
|
const v = process.env.SAVVY_LIVE_CARD;
|
|
213
305
|
return !!(v && v !== '');
|
|
214
306
|
}
|
|
215
307
|
// ── Council transcript dir base (src/council/council.ts) ─────────────────
|
|
216
308
|
// Preserves bit-for-bit the original `process.env.HOME || '/tmp'` fallback.
|
|
217
309
|
// Note: differs from os.homedir() which never returns '/tmp' as fallback.
|
|
310
|
+
//
|
|
311
|
+
// NOT in RuntimeConfig — HOME is process-environment, not plugin config.
|
|
218
312
|
export function getHomeOrTmp() {
|
|
219
313
|
return process.env.HOME || '/tmp';
|
|
220
314
|
}
|
|
221
315
|
// ── Health port override (src/health/handler.ts) ─────────────────────────
|
|
222
316
|
// health/handler.ts owns the validation (range check 1-65535). This getter
|
|
223
317
|
// only exposes the raw env so the validator stays where it is.
|
|
318
|
+
//
|
|
319
|
+
// NOT in RuntimeConfig — the validator owns the typed surface; this getter
|
|
320
|
+
// is the raw boundary.
|
|
224
321
|
export function getHealthPortEnv() {
|
|
225
322
|
const v = process.env.CC_OPENCLAW_HEALTH_PORT;
|
|
226
323
|
return v === undefined || v === '' ? undefined : v;
|
|
@@ -228,9 +325,16 @@ export function getHealthPortEnv() {
|
|
|
228
325
|
// ── Drift detection (src/lib/drift-detector.ts) ───────────────────────────
|
|
229
326
|
// Default-ON. Opt-out via OPENCLAW_CC_OPENCLAW_DRIFT_ALERTS=0.
|
|
230
327
|
export function isDriftAlertsEnabled() {
|
|
328
|
+
const cfg = getConfigService();
|
|
329
|
+
if (cfg)
|
|
330
|
+
return cfg.config.driftAlertsEnabled;
|
|
231
331
|
return process.env.OPENCLAW_CC_OPENCLAW_DRIFT_ALERTS !== '0';
|
|
232
332
|
}
|
|
233
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* Dedup window for repeated drift Telegram alerts. Default 1h.
|
|
335
|
+
* NOT in RuntimeConfig — niche tunable not surfaced through the activation
|
|
336
|
+
* matrix. Kept as a direct env reader.
|
|
337
|
+
*/
|
|
234
338
|
export function getDriftDedupeWindowMs() {
|
|
235
339
|
const v = process.env.OPENCLAW_CC_OPENCLAW_DRIFT_DEDUPE_WINDOW_MS;
|
|
236
340
|
const n = v !== undefined ? parseInt(v, 10) : NaN;
|
|
@@ -239,6 +343,9 @@ export function getDriftDedupeWindowMs() {
|
|
|
239
343
|
// ── Auto-recovery (src/lib/auto-recovery.ts) ─────────────────────────────
|
|
240
344
|
// Default-ON. Opt-out via OPENCLAW_CC_OPENCLAW_AUTO_RECOVERY=0.
|
|
241
345
|
export function isAutoRecoveryEnabled() {
|
|
346
|
+
const cfg = getConfigService();
|
|
347
|
+
if (cfg)
|
|
348
|
+
return cfg.config.autoRecoveryEnabled;
|
|
242
349
|
return process.env.OPENCLAW_CC_OPENCLAW_AUTO_RECOVERY !== '0';
|
|
243
350
|
}
|
|
244
351
|
// ── Thinking-block surfacing (v0.7.0, src/openai-compat/sse-translator.ts) ─
|
|
@@ -250,6 +357,9 @@ export function isAutoRecoveryEnabled() {
|
|
|
250
357
|
// attaches `choices[0].message.reasoning` to the final response.
|
|
251
358
|
// `signature_delta` events are NEVER forwarded regardless of this flag.
|
|
252
359
|
export function getSurfaceThinkingEnabled() {
|
|
360
|
+
const cfg = getConfigService();
|
|
361
|
+
if (cfg)
|
|
362
|
+
return cfg.config.surfaceThinking;
|
|
253
363
|
return process.env.CC_OPENCLAW_SURFACE_THINKING === '1';
|
|
254
364
|
}
|
|
255
365
|
// ── Thinking excerpt → live-card preview (v0.7.0) ────────────────────────
|
|
@@ -258,6 +368,9 @@ export function getSurfaceThinkingEnabled() {
|
|
|
258
368
|
// twice for visibility there. Has no effect when CC_OPENCLAW_SURFACE_THINKING
|
|
259
369
|
// is unset.
|
|
260
370
|
export function getThinkingExcerptEnabled() {
|
|
371
|
+
const cfg = getConfigService();
|
|
372
|
+
if (cfg)
|
|
373
|
+
return cfg.config.thinkingExcerpt;
|
|
261
374
|
return process.env.CC_OPENCLAW_THINKING_EXCERPT === '1';
|
|
262
375
|
}
|
|
263
376
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/lib/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","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AAgB,EAAE,CAAC;IAC/B,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC;IAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAC;AAC1D,CAAC;AAED,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,8EAA8E;AAC9E,YAAY;AAEZ,MAAM,UAAU,yBAAyB;IACvC,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAC;IAC/B,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC;IAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAC;AAC1D,CAAC"}
|
package/dist/src/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export * from './register-guard.js';
|
|
|
2
2
|
export { registerOnce } from './register-guard.js';
|
|
3
3
|
export { stripSysprompt, isStripEnabled, type StripOptions, type StripResult } from './sysprompt-strip.js';
|
|
4
4
|
export { isCacheParityEnabled, hashPrompt, recordAttachment, readRegistry, REGISTRY_PATH, type RegistryEntry, } from './cache-parity.js';
|
|
5
|
-
export { selectEngine, isCcOpenclawEnabled, captureSessionRoute, ACTIVE_FLAG_ENV, ROUTE_FLAG_ENV, type Engine, type SessionRoute, } from './
|
|
5
|
+
export { selectEngine, isCcOpenclawEnabled, captureSessionRoute, ACTIVE_FLAG_ENV, ROUTE_FLAG_ENV, type Engine, type SessionRoute, } from './config-service.js';
|
|
6
6
|
export { isTestMode, TEST_MODE_ENV, _setTestModeForTests } from './test-mode.js';
|
|
7
7
|
export { getAggressiveStripEnabled, getCacheParityEnabled, getLogLevel, isLogLevelDebug, } from './config.js';
|
package/dist/src/lib/index.js
CHANGED
|
@@ -2,7 +2,10 @@ export * from './register-guard.js';
|
|
|
2
2
|
export { registerOnce } from './register-guard.js';
|
|
3
3
|
export { stripSysprompt, isStripEnabled } from './sysprompt-strip.js';
|
|
4
4
|
export { isCacheParityEnabled, hashPrompt, recordAttachment, readRegistry, REGISTRY_PATH, } from './cache-parity.js';
|
|
5
|
-
|
|
5
|
+
// Engine routing — originally `./route-flag.js`; collapsed into
|
|
6
|
+
// `./config-service.js` at Cluster A step 8. Same API, same semantics,
|
|
7
|
+
// single source of truth.
|
|
8
|
+
export { selectEngine, isCcOpenclawEnabled, captureSessionRoute, ACTIVE_FLAG_ENV, ROUTE_FLAG_ENV, } from './config-service.js';
|
|
6
9
|
export { isTestMode, TEST_MODE_ENV, _setTestModeForTests } from './test-mode.js';
|
|
7
10
|
export { getAggressiveStripEnabled, getCacheParityEnabled, getLogLevel, isLogLevelDebug, } from './config.js';
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAuC,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,cAAc,GAGf,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAuC,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAC3B,gEAAgE;AAChE,uEAAuE;AACvE,0BAA0B;AAC1B,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,cAAc,GAGf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,WAAW,EACX,eAAe,GAChB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B — Message extractor.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `openai-compat.ts:177-301` (Phase 4 Cluster B
|
|
5
|
+
* Module D). Single function that converts an OpenAI `messages[]` array
|
|
6
|
+
* into the inputs Claude CLI's bridge expects:
|
|
7
|
+
*
|
|
8
|
+
* - systemPrompt — joined `role:system` content, undefined if none
|
|
9
|
+
* - userMessage — last user message (with skill-inline applied)
|
|
10
|
+
* OR XML-wrapped tool-result block when the
|
|
11
|
+
* last non-system message is `role:tool`
|
|
12
|
+
* - userMessageBlocks — tool-stream mode only: native Anthropic
|
|
13
|
+
* content blocks (tool_result + text) for the
|
|
14
|
+
* stream-json input path
|
|
15
|
+
* - isNewConversation — drives session-create vs session-append
|
|
16
|
+
*
|
|
17
|
+
* Single call site in the orchestrator (handleChatCompletion line 482).
|
|
18
|
+
* The two types `UserMessageBlock` and `ExtractedMessage` are also re-
|
|
19
|
+
* exported from openai-compat.ts for callers across the orchestrator
|
|
20
|
+
* (formatCompletionResponse + helpers all consume them as parameters).
|
|
21
|
+
*
|
|
22
|
+
* Session-reset semantics:
|
|
23
|
+
* - X-Session-Reset: 1|true → always treated as new conversation
|
|
24
|
+
* - OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1 (env) → legacy
|
|
25
|
+
* "system + single user ⇒ new conversation" rule, opt-in for
|
|
26
|
+
* callers that re-send the full transcript every turn
|
|
27
|
+
* - Default (env unset) → only the explicit header creates a new
|
|
28
|
+
* conversation; persistent CLI sessions survive across turns and
|
|
29
|
+
* benefit from Anthropic prompt caching (PR #40)
|
|
30
|
+
*/
|
|
31
|
+
import type { OpenAIChatMessage } from './openai-compat.js';
|
|
32
|
+
import { type AnthropicToolResultBlock } from './tool-results-serializer.js';
|
|
33
|
+
/**
|
|
34
|
+
* Phase 2 R4 wire-up: optional structured content for tool-stream mode.
|
|
35
|
+
* When set, consumers should send this array to the subprocess instead of
|
|
36
|
+
* the legacy XML-wrapped `userMessage` string. Each element is either a
|
|
37
|
+
* native Anthropic `tool_result` block (for prior tool outputs) or a
|
|
38
|
+
* `text` block (for the user's follow-up message).
|
|
39
|
+
*/
|
|
40
|
+
export type UserMessageBlock = AnthropicToolResultBlock | {
|
|
41
|
+
type: 'text';
|
|
42
|
+
text: string;
|
|
43
|
+
};
|
|
44
|
+
export interface ExtractedMessage {
|
|
45
|
+
systemPrompt: string | undefined;
|
|
46
|
+
userMessage: string;
|
|
47
|
+
/**
|
|
48
|
+
* Populated only in tool-stream mode when the last non-system message
|
|
49
|
+
* is a tool-role result. Carries native Anthropic tool_result blocks
|
|
50
|
+
* + optional follow-up text. When undefined, consumers fall back to
|
|
51
|
+
* the string `userMessage` (legacy XML-wrapped path).
|
|
52
|
+
*/
|
|
53
|
+
userMessageBlocks?: UserMessageBlock[];
|
|
54
|
+
isNewConversation: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Extract the relevant parts from an OpenAI messages array.
|
|
58
|
+
*
|
|
59
|
+
* Sessions are stateful — we only need the last user message. The tricky
|
|
60
|
+
* question is whether to start a fresh session or append to the existing one.
|
|
61
|
+
*
|
|
62
|
+
* Default mode (no env var): only honor an explicit `X-Session-Reset: 1`
|
|
63
|
+
* header. This is correct for clients that maintain their own conversation
|
|
64
|
+
* transcript and forward only the latest user turn (OpenClaw main agent
|
|
65
|
+
* loop, cron jobs, subagents). The previous heuristic
|
|
66
|
+
* (`nonSystemMessages.length <= 1`) fired on every such request, killing the
|
|
67
|
+
* persistent CLI every turn and preventing Anthropic prompt caching from
|
|
68
|
+
* ever warming. Originally diagnosed in PR #40 by @megayounus786.
|
|
69
|
+
*
|
|
70
|
+
* Legacy mode (`OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1`): restore the old
|
|
71
|
+
* `system + single user ⇒ new conversation` rule, for clients that re-send
|
|
72
|
+
* the full transcript on every turn (ChatGPT-Next-Web, Open WebUI, data
|
|
73
|
+
* labeling tools, etc). They use the transcript shape itself as their only
|
|
74
|
+
* "start a new conversation" signal.
|
|
75
|
+
*
|
|
76
|
+
* The env var is read on every call so ops can flip it via launchctl setenv
|
|
77
|
+
* without restarting the server.
|
|
78
|
+
*/
|
|
79
|
+
export declare function extractUserMessage(messages: OpenAIChatMessage[], headers?: Record<string, string | string[] | undefined>): ExtractedMessage;
|