mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-06-04 08:34:53 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
123 lines
3.6 KiB
TypeScript
123 lines
3.6 KiB
TypeScript
import path from "node:path";
|
|
import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
|
|
import {
|
|
resolveEffectiveToolFsRootExpansionAllowed,
|
|
resolveEffectiveToolFsWorkspaceOnly,
|
|
} from "../agents/tool-fs-policy.js";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { resolveStateDir } from "../config/paths.js";
|
|
import { safeFileURLToPath } from "../infra/local-file-access.js";
|
|
import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
|
|
import { resolveUserPath } from "../utils.js";
|
|
|
|
type BuildMediaLocalRootsOptions = {
|
|
preferredTmpDir?: string;
|
|
};
|
|
|
|
let cachedPreferredTmpDir: string | undefined;
|
|
const HTTP_URL_RE = /^https?:\/\//i;
|
|
const DATA_URL_RE = /^data:/i;
|
|
const WINDOWS_DRIVE_RE = /^[A-Za-z]:[\\/]/;
|
|
|
|
function resolveCachedPreferredTmpDir(): string {
|
|
if (!cachedPreferredTmpDir) {
|
|
cachedPreferredTmpDir = resolvePreferredOpenClawTmpDir();
|
|
}
|
|
return cachedPreferredTmpDir;
|
|
}
|
|
|
|
function buildMediaLocalRoots(
|
|
stateDir: string,
|
|
options: BuildMediaLocalRootsOptions = {},
|
|
): string[] {
|
|
const resolvedStateDir = path.resolve(stateDir);
|
|
const preferredTmpDir = options.preferredTmpDir ?? resolveCachedPreferredTmpDir();
|
|
return [
|
|
preferredTmpDir,
|
|
path.join(resolvedStateDir, "media"),
|
|
path.join(resolvedStateDir, "workspace"),
|
|
path.join(resolvedStateDir, "sandboxes"),
|
|
];
|
|
}
|
|
|
|
export function getDefaultMediaLocalRoots(): readonly string[] {
|
|
return buildMediaLocalRoots(resolveStateDir());
|
|
}
|
|
|
|
export function getAgentScopedMediaLocalRoots(
|
|
cfg: OpenClawConfig,
|
|
agentId?: string,
|
|
): readonly string[] {
|
|
const roots = buildMediaLocalRoots(resolveStateDir());
|
|
if (!agentId?.trim()) {
|
|
return roots;
|
|
}
|
|
const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
|
|
if (!workspaceDir) {
|
|
return roots;
|
|
}
|
|
const normalizedWorkspaceDir = path.resolve(workspaceDir);
|
|
if (!roots.includes(normalizedWorkspaceDir)) {
|
|
roots.push(normalizedWorkspaceDir);
|
|
}
|
|
return roots;
|
|
}
|
|
|
|
function resolveLocalMediaPath(source: string): string | undefined {
|
|
const trimmed = source.trim();
|
|
if (!trimmed || HTTP_URL_RE.test(trimmed) || DATA_URL_RE.test(trimmed)) {
|
|
return undefined;
|
|
}
|
|
if (trimmed.startsWith("file://")) {
|
|
try {
|
|
return safeFileURLToPath(trimmed);
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
if (trimmed.startsWith("~")) {
|
|
return resolveUserPath(trimmed);
|
|
}
|
|
if (path.isAbsolute(trimmed) || WINDOWS_DRIVE_RE.test(trimmed)) {
|
|
return path.resolve(trimmed);
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function appendLocalMediaParentRoots(
|
|
roots: readonly string[],
|
|
mediaSources?: readonly string[],
|
|
): string[] {
|
|
const appended = Array.from(new Set(roots.map((root) => path.resolve(root))));
|
|
for (const source of mediaSources ?? []) {
|
|
const localPath = resolveLocalMediaPath(source);
|
|
if (!localPath) {
|
|
continue;
|
|
}
|
|
const parentDir = path.dirname(localPath);
|
|
if (parentDir === path.parse(parentDir).root) {
|
|
continue;
|
|
}
|
|
const normalizedParent = path.resolve(parentDir);
|
|
if (!appended.includes(normalizedParent)) {
|
|
appended.push(normalizedParent);
|
|
}
|
|
}
|
|
return appended;
|
|
}
|
|
|
|
export function getAgentScopedMediaLocalRootsForSources(params: {
|
|
cfg: OpenClawConfig;
|
|
agentId?: string;
|
|
mediaSources?: readonly string[];
|
|
}): readonly string[] {
|
|
const roots = getAgentScopedMediaLocalRoots(params.cfg, params.agentId);
|
|
if (resolveEffectiveToolFsWorkspaceOnly({ cfg: params.cfg, agentId: params.agentId })) {
|
|
return roots;
|
|
}
|
|
if (!resolveEffectiveToolFsRootExpansionAllowed({ cfg: params.cfg, agentId: params.agentId })) {
|
|
return roots;
|
|
}
|
|
return appendLocalMediaParentRoots(roots, params.mediaSources);
|
|
}
|