@qingchencloud/openclaw-zh 2026.2.1-zh.2 → 2026.2.1-zh.3
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/CHANGELOG.md +19 -1
- package/dist/agents/auth-profiles/oauth.js +11 -2
- package/dist/agents/bash-tools.exec.js +45 -0
- package/dist/agents/context-window-guard.js +10 -11
- package/dist/agents/openclaw-tools.js +1 -0
- package/dist/agents/pi-embedded-runner/compact.js +5 -14
- package/dist/agents/pi-embedded-runner/extensions.js +8 -0
- package/dist/agents/pi-embedded-runner/extra-params.d.ts +1 -0
- package/dist/agents/pi-embedded-runner/extra-params.js +50 -12
- package/dist/agents/pi-embedded-runner/run/attempt.js +10 -15
- package/dist/agents/pi-embedded-runner/system-prompt.d.ts +2 -0
- package/dist/agents/pi-embedded-runner/system-prompt.js +7 -0
- package/dist/agents/pi-extensions/compaction-safeguard-runtime.d.ts +1 -0
- package/dist/agents/pi-extensions/compaction-safeguard.js +3 -2
- package/dist/agents/pi-tool-definition-adapter.d.ts +4 -1
- package/dist/agents/pi-tool-definition-adapter.js +17 -2
- package/dist/agents/pi-tools.before-tool-call.d.ts +25 -0
- package/dist/agents/pi-tools.before-tool-call.js +69 -0
- package/dist/agents/pi-tools.js +7 -2
- package/dist/agents/tool-policy.conformance.d.ts +11 -0
- package/dist/agents/tool-policy.conformance.js +14 -0
- package/dist/agents/tools/message-tool.d.ts +1 -0
- package/dist/agents/tools/message-tool.js +11 -0
- package/dist/agents/tools/web-fetch.js +100 -29
- package/dist/agents/tools/web-search.js +15 -8
- package/dist/browser/cdp.helpers.d.ts +3 -1
- package/dist/browser/cdp.helpers.js +7 -4
- package/dist/browser/extension-relay.d.ts +1 -0
- package/dist/browser/extension-relay.js +64 -0
- package/dist/browser/pw-session.js +2 -1
- package/dist/build-info.json +3 -3
- package/dist/canvas-host/a2ui/.bundle.hash +1 -1
- package/dist/cli/program/register.status-health-sessions.js +1 -1
- package/dist/commands/onboard.js +3 -2
- package/dist/config/defaults.js +4 -4
- package/dist/config/types.agent-defaults.d.ts +1 -1
- package/dist/config/zod-schema.providers-core.js +32 -0
- package/dist/control-ui/assets/index-BZkju1RS.css +1 -0
- package/dist/control-ui/assets/{index-BebBTKqz.js → index-BgR4pesr.js} +24 -24
- package/dist/control-ui/assets/index-BgR4pesr.js.map +1 -0
- package/dist/control-ui/index.html +2 -2
- package/dist/infra/tls/gateway.js +1 -1
- package/dist/media-understanding/apply.js +142 -34
- package/dist/security/external-content.d.ts +7 -2
- package/dist/security/external-content.js +81 -3
- package/dist/telegram/bot-handlers.js +5 -5
- package/dist/telegram/bot-message-context.js +9 -6
- package/dist/telegram/bot-native-commands.js +2 -2
- package/dist/tui/components/searchable-select-list.js +3 -3
- package/dist/web/accounts.js +2 -2
- package/docs/.i18n/README.md +31 -0
- package/docs/.i18n/glossary.zh-CN.json +82 -0
- package/docs/.i18n/zh-CN.tm.jsonl +1371 -0
- package/docs/channels/discord.md +6 -0
- package/docs/channels/grammy.md +1 -1
- package/docs/channels/telegram.md +5 -5
- package/docs/concepts/model-providers.md +3 -3
- package/docs/concepts/session-pruning.md +6 -6
- package/docs/docs.json +320 -301
- package/docs/gateway/configuration.md +1 -1
- package/docs/gateway/security/index.md +1 -0
- package/docs/install/index.md +5 -1
- package/docs/pi.md +20 -8
- package/docs/platforms/exe-dev.md +2 -2
- package/docs/platforms/windows.md +2 -1
- package/docs/providers/anthropic.md +24 -4
- package/docs/providers/moonshot.md +3 -3
- package/docs/start/onboarding.md +10 -6
- package/docs/token-use.md +1 -1
- package/docs/tools/chrome-extension.md +1 -0
- package/docs/tools/exec.md +7 -5
- package/docs/tools/skills.md +1 -1
- package/docs/web/control-ui.md +30 -0
- package/docs/zh-CN/index.md +263 -0
- package/docs/zh-CN/start/getting-started.md +212 -0
- package/docs/zh-CN/start/wizard.md +331 -0
- package/extensions/googlechat/src/accounts.ts +1 -1
- package/extensions/line/src/channel.ts +4 -3
- package/extensions/tlon/src/urbit/sse-client.ts +16 -0
- package/package.json +24 -6
- package/skills/canvas/SKILL.md +9 -9
- package/skills/session-logs/SKILL.md +1 -1
- package/dist/control-ui/assets/index-BKPyesll.css +0 -1
- package/dist/control-ui/assets/index-BebBTKqz.js.map +0 -1
- package/dist/telegram/pairing-store.d.ts +0 -43
- package/dist/telegram/pairing-store.js +0 -78
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conformance snapshot for tool policy.
|
|
3
|
+
*
|
|
4
|
+
* Security note:
|
|
5
|
+
* - This is static, build-time information (no runtime I/O, no network exposure).
|
|
6
|
+
* - Intended for CI/tools to detect drift between the implementation policy and
|
|
7
|
+
* the formal models/extractors.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TOOL_POLICY_CONFORMANCE: {
|
|
10
|
+
readonly toolGroups: Record<string, string[]>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conformance snapshot for tool policy.
|
|
3
|
+
*
|
|
4
|
+
* Security note:
|
|
5
|
+
* - This is static, build-time information (no runtime I/O, no network exposure).
|
|
6
|
+
* - Intended for CI/tools to detect drift between the implementation policy and
|
|
7
|
+
* the formal models/extractors.
|
|
8
|
+
*/
|
|
9
|
+
import { TOOL_GROUPS } from "./tool-policy.js";
|
|
10
|
+
// Tool name aliases are intentionally not exported from tool-policy today.
|
|
11
|
+
// Keep the conformance snapshot focused on exported policy constants.
|
|
12
|
+
export const TOOL_POLICY_CONFORMANCE = {
|
|
13
|
+
toolGroups: TOOL_GROUPS,
|
|
14
|
+
};
|
|
@@ -10,6 +10,7 @@ import { normalizeAccountId } from "../../routing/session-key.js";
|
|
|
10
10
|
import { normalizeMessageChannel } from "../../utils/message-channel.js";
|
|
11
11
|
import { resolveSessionAgentId } from "../agent-scope.js";
|
|
12
12
|
import { listChannelSupportedActions } from "../channel-tools.js";
|
|
13
|
+
import { assertSandboxPath } from "../sandbox-paths.js";
|
|
13
14
|
import { channelTargetSchema, channelTargetsSchema, stringEnum } from "../schema/typebox.js";
|
|
14
15
|
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
|
|
15
16
|
const AllMessageActions = CHANNEL_MESSAGE_ACTION_NAMES;
|
|
@@ -278,6 +279,16 @@ export function createMessageTool(options) {
|
|
|
278
279
|
const action = readStringParam(params, "action", {
|
|
279
280
|
required: true,
|
|
280
281
|
});
|
|
282
|
+
// Validate file paths against sandbox root to prevent host file access.
|
|
283
|
+
const sandboxRoot = options?.sandboxRoot;
|
|
284
|
+
if (sandboxRoot) {
|
|
285
|
+
for (const key of ["filePath", "path"]) {
|
|
286
|
+
const raw = readStringParam(params, key, { trim: false });
|
|
287
|
+
if (raw) {
|
|
288
|
+
await assertSandboxPath({ filePath: raw, cwd: sandboxRoot, root: sandboxRoot });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
281
292
|
const accountId = readStringParam(params, "accountId") ?? agentAccountId;
|
|
282
293
|
if (accountId) {
|
|
283
294
|
params.accountId = accountId;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
import { closeDispatcher, createPinnedDispatcher, resolvePinnedHostname, SsrFBlockedError, } from "../../infra/net/ssrf.js";
|
|
3
|
+
import { wrapExternalContent, wrapWebContent } from "../../security/external-content.js";
|
|
3
4
|
import { stringEnum } from "../schema/typebox.js";
|
|
4
5
|
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
|
|
5
6
|
import { extractReadableContent, htmlToMarkdown, markdownToText, truncateText, } from "./web-fetch-utils.js";
|
|
@@ -190,6 +191,65 @@ function formatWebFetchErrorDetail(params) {
|
|
|
190
191
|
const truncated = truncateText(text.trim(), maxChars);
|
|
191
192
|
return truncated.text;
|
|
192
193
|
}
|
|
194
|
+
const WEB_FETCH_WRAPPER_WITH_WARNING_OVERHEAD = wrapWebContent("", "web_fetch").length;
|
|
195
|
+
const WEB_FETCH_WRAPPER_NO_WARNING_OVERHEAD = wrapExternalContent("", {
|
|
196
|
+
source: "web_fetch",
|
|
197
|
+
includeWarning: false,
|
|
198
|
+
}).length;
|
|
199
|
+
function wrapWebFetchContent(value, maxChars) {
|
|
200
|
+
if (maxChars <= 0) {
|
|
201
|
+
return { text: "", truncated: true, rawLength: 0, wrappedLength: 0 };
|
|
202
|
+
}
|
|
203
|
+
const includeWarning = maxChars >= WEB_FETCH_WRAPPER_WITH_WARNING_OVERHEAD;
|
|
204
|
+
const wrapperOverhead = includeWarning
|
|
205
|
+
? WEB_FETCH_WRAPPER_WITH_WARNING_OVERHEAD
|
|
206
|
+
: WEB_FETCH_WRAPPER_NO_WARNING_OVERHEAD;
|
|
207
|
+
if (wrapperOverhead > maxChars) {
|
|
208
|
+
const minimal = includeWarning
|
|
209
|
+
? wrapWebContent("", "web_fetch")
|
|
210
|
+
: wrapExternalContent("", { source: "web_fetch", includeWarning: false });
|
|
211
|
+
const truncatedWrapper = truncateText(minimal, maxChars);
|
|
212
|
+
return {
|
|
213
|
+
text: truncatedWrapper.text,
|
|
214
|
+
truncated: true,
|
|
215
|
+
rawLength: 0,
|
|
216
|
+
wrappedLength: truncatedWrapper.text.length,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const maxInner = Math.max(0, maxChars - wrapperOverhead);
|
|
220
|
+
let truncated = truncateText(value, maxInner);
|
|
221
|
+
let wrappedText = includeWarning
|
|
222
|
+
? wrapWebContent(truncated.text, "web_fetch")
|
|
223
|
+
: wrapExternalContent(truncated.text, { source: "web_fetch", includeWarning: false });
|
|
224
|
+
if (wrappedText.length > maxChars) {
|
|
225
|
+
const excess = wrappedText.length - maxChars;
|
|
226
|
+
const adjustedMaxInner = Math.max(0, maxInner - excess);
|
|
227
|
+
truncated = truncateText(value, adjustedMaxInner);
|
|
228
|
+
wrappedText = includeWarning
|
|
229
|
+
? wrapWebContent(truncated.text, "web_fetch")
|
|
230
|
+
: wrapExternalContent(truncated.text, { source: "web_fetch", includeWarning: false });
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
text: wrappedText,
|
|
234
|
+
truncated: truncated.truncated,
|
|
235
|
+
rawLength: truncated.text.length,
|
|
236
|
+
wrappedLength: wrappedText.length,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function wrapWebFetchField(value) {
|
|
240
|
+
if (!value) {
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
return wrapExternalContent(value, { source: "web_fetch", includeWarning: false });
|
|
244
|
+
}
|
|
245
|
+
function normalizeContentType(value) {
|
|
246
|
+
if (!value) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
const [raw] = value.split(";");
|
|
250
|
+
const trimmed = raw?.trim();
|
|
251
|
+
return trimmed || undefined;
|
|
252
|
+
}
|
|
193
253
|
export async function fetchFirecrawlContent(params) {
|
|
194
254
|
const endpoint = resolveFirecrawlEndpoint(params.baseUrl);
|
|
195
255
|
const body = {
|
|
@@ -212,8 +272,8 @@ export async function fetchFirecrawlContent(params) {
|
|
|
212
272
|
});
|
|
213
273
|
const payload = (await res.json());
|
|
214
274
|
if (!res.ok || payload?.success === false) {
|
|
215
|
-
const detail = payload?.error
|
|
216
|
-
throw new Error(`Firecrawl fetch failed (${res.status}): ${detail}`.trim());
|
|
275
|
+
const detail = payload?.error ?? "";
|
|
276
|
+
throw new Error(`Firecrawl fetch failed (${res.status}): ${wrapWebContent(detail || res.statusText, "web_fetch")}`.trim());
|
|
217
277
|
}
|
|
218
278
|
const data = payload?.data ?? {};
|
|
219
279
|
const rawText = typeof data.markdown === "string"
|
|
@@ -277,21 +337,24 @@ async function runWebFetch(params) {
|
|
|
277
337
|
storeInCache: params.firecrawlStoreInCache,
|
|
278
338
|
timeoutSeconds: params.firecrawlTimeoutSeconds,
|
|
279
339
|
});
|
|
280
|
-
const
|
|
340
|
+
const wrapped = wrapWebFetchContent(firecrawl.text, params.maxChars);
|
|
341
|
+
const wrappedTitle = firecrawl.title ? wrapWebFetchField(firecrawl.title) : undefined;
|
|
281
342
|
const payload = {
|
|
282
|
-
url: params.url,
|
|
283
|
-
finalUrl: firecrawl.finalUrl || finalUrl,
|
|
343
|
+
url: params.url, // Keep raw for tool chaining
|
|
344
|
+
finalUrl: firecrawl.finalUrl || finalUrl, // Keep raw
|
|
284
345
|
status: firecrawl.status ?? 200,
|
|
285
|
-
contentType: "text/markdown",
|
|
286
|
-
title:
|
|
346
|
+
contentType: "text/markdown", // Protocol metadata, don't wrap
|
|
347
|
+
title: wrappedTitle,
|
|
287
348
|
extractMode: params.extractMode,
|
|
288
349
|
extractor: "firecrawl",
|
|
289
|
-
truncated:
|
|
290
|
-
length:
|
|
350
|
+
truncated: wrapped.truncated,
|
|
351
|
+
length: wrapped.wrappedLength,
|
|
352
|
+
rawLength: wrapped.rawLength, // Actual content length, not wrapped
|
|
353
|
+
wrappedLength: wrapped.wrappedLength,
|
|
291
354
|
fetchedAt: new Date().toISOString(),
|
|
292
355
|
tookMs: Date.now() - start,
|
|
293
|
-
text:
|
|
294
|
-
warning: firecrawl.warning,
|
|
356
|
+
text: wrapped.text,
|
|
357
|
+
warning: wrapWebFetchField(firecrawl.warning),
|
|
295
358
|
};
|
|
296
359
|
writeCache(FETCH_CACHE, cacheKey, payload, params.cacheTtlMs);
|
|
297
360
|
return payload;
|
|
@@ -312,21 +375,24 @@ async function runWebFetch(params) {
|
|
|
312
375
|
storeInCache: params.firecrawlStoreInCache,
|
|
313
376
|
timeoutSeconds: params.firecrawlTimeoutSeconds,
|
|
314
377
|
});
|
|
315
|
-
const
|
|
378
|
+
const wrapped = wrapWebFetchContent(firecrawl.text, params.maxChars);
|
|
379
|
+
const wrappedTitle = firecrawl.title ? wrapWebFetchField(firecrawl.title) : undefined;
|
|
316
380
|
const payload = {
|
|
317
|
-
url: params.url,
|
|
318
|
-
finalUrl: firecrawl.finalUrl || finalUrl,
|
|
381
|
+
url: params.url, // Keep raw for tool chaining
|
|
382
|
+
finalUrl: firecrawl.finalUrl || finalUrl, // Keep raw
|
|
319
383
|
status: firecrawl.status ?? res.status,
|
|
320
|
-
contentType: "text/markdown",
|
|
321
|
-
title:
|
|
384
|
+
contentType: "text/markdown", // Protocol metadata, don't wrap
|
|
385
|
+
title: wrappedTitle,
|
|
322
386
|
extractMode: params.extractMode,
|
|
323
387
|
extractor: "firecrawl",
|
|
324
|
-
truncated:
|
|
325
|
-
length:
|
|
388
|
+
truncated: wrapped.truncated,
|
|
389
|
+
length: wrapped.wrappedLength,
|
|
390
|
+
rawLength: wrapped.rawLength, // Actual content length, not wrapped
|
|
391
|
+
wrappedLength: wrapped.wrappedLength,
|
|
326
392
|
fetchedAt: new Date().toISOString(),
|
|
327
393
|
tookMs: Date.now() - start,
|
|
328
|
-
text:
|
|
329
|
-
warning: firecrawl.warning,
|
|
394
|
+
text: wrapped.text,
|
|
395
|
+
warning: wrapWebFetchField(firecrawl.warning),
|
|
330
396
|
};
|
|
331
397
|
writeCache(FETCH_CACHE, cacheKey, payload, params.cacheTtlMs);
|
|
332
398
|
return payload;
|
|
@@ -337,9 +403,11 @@ async function runWebFetch(params) {
|
|
|
337
403
|
contentType: res.headers.get("content-type"),
|
|
338
404
|
maxChars: DEFAULT_ERROR_MAX_CHARS,
|
|
339
405
|
});
|
|
340
|
-
|
|
406
|
+
const wrappedDetail = wrapWebFetchContent(detail || res.statusText, DEFAULT_ERROR_MAX_CHARS);
|
|
407
|
+
throw new Error(`Web fetch failed (${res.status}): ${wrappedDetail.text}`);
|
|
341
408
|
}
|
|
342
409
|
const contentType = res.headers.get("content-type") ?? "application/octet-stream";
|
|
410
|
+
const normalizedContentType = normalizeContentType(contentType) ?? "application/octet-stream";
|
|
343
411
|
const body = await readResponseText(res);
|
|
344
412
|
let title;
|
|
345
413
|
let extractor = "raw";
|
|
@@ -382,20 +450,23 @@ async function runWebFetch(params) {
|
|
|
382
450
|
extractor = "raw";
|
|
383
451
|
}
|
|
384
452
|
}
|
|
385
|
-
const
|
|
453
|
+
const wrapped = wrapWebFetchContent(text, params.maxChars);
|
|
454
|
+
const wrappedTitle = title ? wrapWebFetchField(title) : undefined;
|
|
386
455
|
const payload = {
|
|
387
|
-
url: params.url,
|
|
388
|
-
finalUrl,
|
|
456
|
+
url: params.url, // Keep raw for tool chaining
|
|
457
|
+
finalUrl, // Keep raw
|
|
389
458
|
status: res.status,
|
|
390
|
-
contentType,
|
|
391
|
-
title,
|
|
459
|
+
contentType: normalizedContentType, // Protocol metadata, don't wrap
|
|
460
|
+
title: wrappedTitle,
|
|
392
461
|
extractMode: params.extractMode,
|
|
393
462
|
extractor,
|
|
394
|
-
truncated:
|
|
395
|
-
length:
|
|
463
|
+
truncated: wrapped.truncated,
|
|
464
|
+
length: wrapped.wrappedLength,
|
|
465
|
+
rawLength: wrapped.rawLength, // Actual content length, not wrapped
|
|
466
|
+
wrappedLength: wrapped.wrappedLength,
|
|
396
467
|
fetchedAt: new Date().toISOString(),
|
|
397
468
|
tookMs: Date.now() - start,
|
|
398
|
-
text:
|
|
469
|
+
text: wrapped.text,
|
|
399
470
|
};
|
|
400
471
|
writeCache(FETCH_CACHE, cacheKey, payload, params.cacheTtlMs);
|
|
401
472
|
return payload;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
import { formatCliCommand } from "../../cli/command-format.js";
|
|
3
|
+
import { wrapWebContent } from "../../security/external-content.js";
|
|
3
4
|
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
|
|
4
5
|
import { DEFAULT_CACHE_TTL_MINUTES, DEFAULT_TIMEOUT_SECONDS, normalizeCacheKey, readCache, readResponseText, resolveCacheTtlMs, resolveTimeoutSeconds, withTimeout, writeCache, } from "./web-shared.js";
|
|
5
6
|
const SEARCH_PROVIDERS = ["brave", "perplexity"];
|
|
@@ -256,7 +257,7 @@ async function runWebSearch(params) {
|
|
|
256
257
|
provider: params.provider,
|
|
257
258
|
model: params.perplexityModel ?? DEFAULT_PERPLEXITY_MODEL,
|
|
258
259
|
tookMs: Date.now() - start,
|
|
259
|
-
content,
|
|
260
|
+
content: wrapWebContent(content),
|
|
260
261
|
citations,
|
|
261
262
|
};
|
|
262
263
|
writeCache(SEARCH_CACHE, cacheKey, payload, params.cacheTtlMs);
|
|
@@ -294,13 +295,19 @@ async function runWebSearch(params) {
|
|
|
294
295
|
}
|
|
295
296
|
const data = (await res.json());
|
|
296
297
|
const results = Array.isArray(data.web?.results) ? (data.web?.results ?? []) : [];
|
|
297
|
-
const mapped = results.map((entry) =>
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
298
|
+
const mapped = results.map((entry) => {
|
|
299
|
+
const description = entry.description ?? "";
|
|
300
|
+
const title = entry.title ?? "";
|
|
301
|
+
const url = entry.url ?? "";
|
|
302
|
+
const rawSiteName = resolveSiteName(url);
|
|
303
|
+
return {
|
|
304
|
+
title: title ? wrapWebContent(title, "web_search") : "",
|
|
305
|
+
url, // Keep raw for tool chaining
|
|
306
|
+
description: description ? wrapWebContent(description, "web_search") : "",
|
|
307
|
+
published: entry.age || undefined,
|
|
308
|
+
siteName: rawSiteName || undefined,
|
|
309
|
+
};
|
|
310
|
+
});
|
|
304
311
|
const payload = {
|
|
305
312
|
query: params.query,
|
|
306
313
|
provider: params.provider,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type CdpSendFn = (method: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
2
2
|
export declare function isLoopbackHost(host: string): boolean;
|
|
3
|
-
export declare function getHeadersWithAuth(url: string, headers?: Record<string, string>):
|
|
3
|
+
export declare function getHeadersWithAuth(url: string, headers?: Record<string, string>): {
|
|
4
|
+
[x: string]: string;
|
|
5
|
+
};
|
|
4
6
|
export declare function appendCdpPath(cdpUrl: string, path: string): string;
|
|
5
7
|
export declare function fetchJson<T>(url: string, timeoutMs?: number, init?: RequestInit): Promise<T>;
|
|
6
8
|
export declare function fetchOk(url: string, timeoutMs?: number, init?: RequestInit): Promise<void>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
2
|
import { rawDataToString } from "../infra/ws.js";
|
|
3
|
+
import { getChromeExtensionRelayAuthHeaders } from "./extension-relay.js";
|
|
3
4
|
export function isLoopbackHost(host) {
|
|
4
5
|
const h = host.trim().toLowerCase();
|
|
5
6
|
return (h === "localhost" ||
|
|
@@ -11,21 +12,23 @@ export function isLoopbackHost(host) {
|
|
|
11
12
|
h === "::");
|
|
12
13
|
}
|
|
13
14
|
export function getHeadersWithAuth(url, headers = {}) {
|
|
15
|
+
const relayHeaders = getChromeExtensionRelayAuthHeaders(url);
|
|
16
|
+
const mergedHeaders = { ...relayHeaders, ...headers };
|
|
14
17
|
try {
|
|
15
18
|
const parsed = new URL(url);
|
|
16
|
-
const hasAuthHeader = Object.keys(
|
|
19
|
+
const hasAuthHeader = Object.keys(mergedHeaders).some((key) => key.toLowerCase() === "authorization");
|
|
17
20
|
if (hasAuthHeader) {
|
|
18
|
-
return
|
|
21
|
+
return mergedHeaders;
|
|
19
22
|
}
|
|
20
23
|
if (parsed.username || parsed.password) {
|
|
21
24
|
const auth = Buffer.from(`${parsed.username}:${parsed.password}`).toString("base64");
|
|
22
|
-
return { ...
|
|
25
|
+
return { ...mergedHeaders, Authorization: `Basic ${auth}` };
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
catch {
|
|
26
29
|
// ignore
|
|
27
30
|
}
|
|
28
|
-
return
|
|
31
|
+
return mergedHeaders;
|
|
29
32
|
}
|
|
30
33
|
export function appendCdpPath(cdpUrl, path) {
|
|
31
34
|
const url = new URL(cdpUrl);
|
|
@@ -6,6 +6,7 @@ export type ChromeExtensionRelayServer = {
|
|
|
6
6
|
extensionConnected: () => boolean;
|
|
7
7
|
stop: () => Promise<void>;
|
|
8
8
|
};
|
|
9
|
+
export declare function getChromeExtensionRelayAuthHeaders(url: string): Record<string, string>;
|
|
9
10
|
export declare function ensureChromeExtensionRelayServer(opts: {
|
|
10
11
|
cdpUrl: string;
|
|
11
12
|
}): Promise<ChromeExtensionRelayServer>;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
1
2
|
import { createServer } from "node:http";
|
|
2
3
|
import WebSocket, { WebSocketServer } from "ws";
|
|
3
4
|
import { rawDataToString } from "../infra/ws.js";
|
|
5
|
+
const RELAY_AUTH_HEADER = "x-openclaw-relay-token";
|
|
6
|
+
function headerValue(value) {
|
|
7
|
+
if (!value) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
return value[0];
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function getHeader(req, name) {
|
|
16
|
+
return headerValue(req.headers[name.toLowerCase()]);
|
|
17
|
+
}
|
|
4
18
|
function isLoopbackHost(host) {
|
|
5
19
|
const h = host.trim().toLowerCase();
|
|
6
20
|
return (h === "localhost" ||
|
|
@@ -61,6 +75,34 @@ function rejectUpgrade(socket, status, bodyText) {
|
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
const serversByPort = new Map();
|
|
78
|
+
const relayAuthByPort = new Map();
|
|
79
|
+
function relayAuthTokenForUrl(url) {
|
|
80
|
+
try {
|
|
81
|
+
const parsed = new URL(url);
|
|
82
|
+
if (!isLoopbackHost(parsed.hostname)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const port = parsed.port?.trim() !== ""
|
|
86
|
+
? Number(parsed.port)
|
|
87
|
+
: parsed.protocol === "https:" || parsed.protocol === "wss:"
|
|
88
|
+
? 443
|
|
89
|
+
: 80;
|
|
90
|
+
if (!Number.isFinite(port)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return relayAuthByPort.get(port) ?? null;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function getChromeExtensionRelayAuthHeaders(url) {
|
|
100
|
+
const token = relayAuthTokenForUrl(url);
|
|
101
|
+
if (!token) {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
return { [RELAY_AUTH_HEADER]: token };
|
|
105
|
+
}
|
|
64
106
|
export async function ensureChromeExtensionRelayServer(opts) {
|
|
65
107
|
const info = parseBaseUrl(opts.cdpUrl);
|
|
66
108
|
if (!isLoopbackHost(info.host)) {
|
|
@@ -192,9 +234,18 @@ export async function ensureChromeExtensionRelayServer(opts) {
|
|
|
192
234
|
}
|
|
193
235
|
}
|
|
194
236
|
};
|
|
237
|
+
const relayAuthToken = randomBytes(32).toString("base64url");
|
|
195
238
|
const server = createServer((req, res) => {
|
|
196
239
|
const url = new URL(req.url ?? "/", info.baseUrl);
|
|
197
240
|
const path = url.pathname;
|
|
241
|
+
if (path.startsWith("/json")) {
|
|
242
|
+
const token = getHeader(req, RELAY_AUTH_HEADER);
|
|
243
|
+
if (!token || token !== relayAuthToken) {
|
|
244
|
+
res.writeHead(401);
|
|
245
|
+
res.end("Unauthorized");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
198
249
|
if (req.method === "HEAD" && path === "/") {
|
|
199
250
|
res.writeHead(200);
|
|
200
251
|
res.end();
|
|
@@ -303,6 +354,11 @@ export async function ensureChromeExtensionRelayServer(opts) {
|
|
|
303
354
|
rejectUpgrade(socket, 403, "Forbidden");
|
|
304
355
|
return;
|
|
305
356
|
}
|
|
357
|
+
const origin = headerValue(req.headers.origin);
|
|
358
|
+
if (origin && !origin.startsWith("chrome-extension://")) {
|
|
359
|
+
rejectUpgrade(socket, 403, "Forbidden: invalid origin");
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
306
362
|
if (pathname === "/extension") {
|
|
307
363
|
if (extensionWs) {
|
|
308
364
|
rejectUpgrade(socket, 409, "Extension already connected");
|
|
@@ -314,6 +370,11 @@ export async function ensureChromeExtensionRelayServer(opts) {
|
|
|
314
370
|
return;
|
|
315
371
|
}
|
|
316
372
|
if (pathname === "/cdp") {
|
|
373
|
+
const token = getHeader(req, RELAY_AUTH_HEADER);
|
|
374
|
+
if (!token || token !== relayAuthToken) {
|
|
375
|
+
rejectUpgrade(socket, 401, "Unauthorized");
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
317
378
|
if (!extensionWs) {
|
|
318
379
|
rejectUpgrade(socket, 503, "Extension not connected");
|
|
319
380
|
return;
|
|
@@ -530,6 +591,7 @@ export async function ensureChromeExtensionRelayServer(opts) {
|
|
|
530
591
|
extensionConnected: () => Boolean(extensionWs),
|
|
531
592
|
stop: async () => {
|
|
532
593
|
serversByPort.delete(port);
|
|
594
|
+
relayAuthByPort.delete(port);
|
|
533
595
|
try {
|
|
534
596
|
extensionWs?.close(1001, "server stopping");
|
|
535
597
|
}
|
|
@@ -551,6 +613,7 @@ export async function ensureChromeExtensionRelayServer(opts) {
|
|
|
551
613
|
wssCdp.close();
|
|
552
614
|
},
|
|
553
615
|
};
|
|
616
|
+
relayAuthByPort.set(port, relayAuthToken);
|
|
554
617
|
serversByPort.set(port, relay);
|
|
555
618
|
return relay;
|
|
556
619
|
}
|
|
@@ -561,5 +624,6 @@ export async function stopChromeExtensionRelayServer(opts) {
|
|
|
561
624
|
return false;
|
|
562
625
|
}
|
|
563
626
|
await existing.stop();
|
|
627
|
+
relayAuthByPort.delete(info.port);
|
|
564
628
|
return true;
|
|
565
629
|
}
|
|
@@ -276,7 +276,8 @@ async function findPageByTargetId(browser, targetId, cdpUrl) {
|
|
|
276
276
|
.replace(/\/+$/, "")
|
|
277
277
|
.replace(/^ws:/, "http:")
|
|
278
278
|
.replace(/\/cdp$/, "");
|
|
279
|
-
const
|
|
279
|
+
const listUrl = `${baseUrl}/json/list`;
|
|
280
|
+
const response = await fetch(listUrl, { headers: getHeadersWithAuth(listUrl) });
|
|
280
281
|
if (response.ok) {
|
|
281
282
|
const targets = (await response.json());
|
|
282
283
|
const target = targets.find((t) => t.id === targetId);
|
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
b82ba6191cafe2197cc77c9547d174b3afa6ed62e30f933295eddb9c0d1af792
|
|
@@ -96,7 +96,7 @@ export function registerStatusHealthSessionsCommands(program) {
|
|
|
96
96
|
["openclaw sessions --active 120", "Only last 2 hours."],
|
|
97
97
|
["openclaw sessions --json", "Machine-readable output."],
|
|
98
98
|
["openclaw sessions --store ./tmp/sessions.json", "Use a specific session store."],
|
|
99
|
-
])}\n\n${theme.muted("Shows token usage per session when the agent reports it; set agents.defaults.contextTokens to
|
|
99
|
+
])}\n\n${theme.muted("Shows token usage per session when the agent reports it; set agents.defaults.contextTokens to cap the window and show %.")}`)
|
|
100
100
|
.addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/sessions", "docs.openclaw.ai/cli/sessions")}\n`)
|
|
101
101
|
.action(async (opts) => {
|
|
102
102
|
setVerbose(Boolean(opts.verbose));
|
package/dist/commands/onboard.js
CHANGED
|
@@ -49,8 +49,9 @@ export async function onboardCommand(opts, runtime = defaultRuntime) {
|
|
|
49
49
|
}
|
|
50
50
|
if (process.platform === "win32") {
|
|
51
51
|
runtime.log([
|
|
52
|
-
"Windows detected
|
|
53
|
-
"
|
|
52
|
+
"Windows detected — OpenClaw runs great on WSL2!",
|
|
53
|
+
"Native Windows might be trickier.",
|
|
54
|
+
"Quick setup: wsl --install (one command, one reboot)",
|
|
54
55
|
"Guide: https://docs.openclaw.ai/windows",
|
|
55
56
|
].join("\n"));
|
|
56
57
|
}
|
package/dist/config/defaults.js
CHANGED
|
@@ -317,12 +317,12 @@ export function applyContextPruningDefaults(cfg) {
|
|
|
317
317
|
}
|
|
318
318
|
const current = entry ?? {};
|
|
319
319
|
const params = current.params ?? {};
|
|
320
|
-
if (typeof params.
|
|
320
|
+
if (typeof params.cacheRetention === "string") {
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
323
|
nextModels[key] = {
|
|
324
324
|
...current,
|
|
325
|
-
params: { ...params,
|
|
325
|
+
params: { ...params, cacheRetention: "short" },
|
|
326
326
|
};
|
|
327
327
|
modelsMutated = true;
|
|
328
328
|
}
|
|
@@ -334,10 +334,10 @@ export function applyContextPruningDefaults(cfg) {
|
|
|
334
334
|
const entry = nextModels[key];
|
|
335
335
|
const current = entry ?? {};
|
|
336
336
|
const params = current.params ?? {};
|
|
337
|
-
if (typeof params.
|
|
337
|
+
if (typeof params.cacheRetention !== "string") {
|
|
338
338
|
nextModels[key] = {
|
|
339
339
|
...current,
|
|
340
|
-
params: { ...params,
|
|
340
|
+
params: { ...params, cacheRetention: "short" },
|
|
341
341
|
};
|
|
342
342
|
modelsMutated = true;
|
|
343
343
|
}
|
|
@@ -108,7 +108,7 @@ export type AgentDefaultsConfig = {
|
|
|
108
108
|
* Include elapsed time in message envelopes ("on" | "off", default: "on").
|
|
109
109
|
*/
|
|
110
110
|
envelopeElapsed?: "on" | "off";
|
|
111
|
-
/** Optional
|
|
111
|
+
/** Optional context window cap (used for runtime estimates + status %). */
|
|
112
112
|
contextTokens?: number;
|
|
113
113
|
/** Optional CLI backends for text-only fallback (claude-cli, etc.). */
|
|
114
114
|
cliBackends?: Record<string, CliBackendConfig>;
|
|
@@ -132,6 +132,38 @@ export const TelegramConfigSchema = TelegramAccountSchemaBase.extend({
|
|
|
132
132
|
message: 'channels.telegram.dmPolicy="open" requires channels.telegram.allowFrom to include "*"',
|
|
133
133
|
});
|
|
134
134
|
validateTelegramCustomCommands(value, ctx);
|
|
135
|
+
const baseWebhookUrl = typeof value.webhookUrl === "string" ? value.webhookUrl.trim() : "";
|
|
136
|
+
const baseWebhookSecret = typeof value.webhookSecret === "string" ? value.webhookSecret.trim() : "";
|
|
137
|
+
if (baseWebhookUrl && !baseWebhookSecret) {
|
|
138
|
+
ctx.addIssue({
|
|
139
|
+
code: z.ZodIssueCode.custom,
|
|
140
|
+
message: "channels.telegram.webhookUrl requires channels.telegram.webhookSecret",
|
|
141
|
+
path: ["webhookSecret"],
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (!value.accounts) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
for (const [accountId, account] of Object.entries(value.accounts)) {
|
|
148
|
+
if (!account) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (account.enabled === false) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const accountWebhookUrl = typeof account.webhookUrl === "string" ? account.webhookUrl.trim() : "";
|
|
155
|
+
if (!accountWebhookUrl) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const accountSecret = typeof account.webhookSecret === "string" ? account.webhookSecret.trim() : "";
|
|
159
|
+
if (!accountSecret && !baseWebhookSecret) {
|
|
160
|
+
ctx.addIssue({
|
|
161
|
+
code: z.ZodIssueCode.custom,
|
|
162
|
+
message: "channels.telegram.accounts.*.webhookUrl requires channels.telegram.webhookSecret or channels.telegram.accounts.*.webhookSecret",
|
|
163
|
+
path: ["accounts", accountId, "webhookSecret"],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
135
167
|
});
|
|
136
168
|
export const DiscordDmSchema = z
|
|
137
169
|
.object({
|