feat: update desktop workflows and app center
This commit is contained in:
@@ -12,6 +12,11 @@ import {
|
||||
import { logger } from './logger';
|
||||
import { getOpenClawConfigDir, needsWinShell, quoteForCmd } from './paths';
|
||||
import { buildDotnetEnv, resolveDotnetExecutable } from './dotnet-runtime';
|
||||
import {
|
||||
buildPlaywrightRuntimeEnv,
|
||||
ensureYinianPlaywrightRuntimeDirs,
|
||||
resolveYinianPlaywrightBrowsersPath,
|
||||
} from './playwright-runtime';
|
||||
|
||||
export type OfficeRuntimeStatus = 'ok' | 'warning' | 'error';
|
||||
|
||||
@@ -45,6 +50,15 @@ export interface OfficeSkillRuntimeDiagnostics {
|
||||
available: boolean;
|
||||
version: string | null;
|
||||
};
|
||||
playwright: {
|
||||
moduleInstalled: boolean;
|
||||
moduleName: string | null;
|
||||
moduleResolvedPath: string | null;
|
||||
browsersPath: string;
|
||||
chromiumExecutablePath: string | null;
|
||||
chromiumInstalled: boolean;
|
||||
error: string | null;
|
||||
};
|
||||
checks: OfficeRuntimeCheck[];
|
||||
}
|
||||
|
||||
@@ -74,6 +88,8 @@ const NODE_MODULES = [
|
||||
'sharp',
|
||||
] as const;
|
||||
|
||||
const PLAYWRIGHT_MODULE_CANDIDATES = ['playwright', 'playwright-core'] as const;
|
||||
|
||||
const PYTHON_INSTALL_TIMEOUT_MS = 10 * 60_000;
|
||||
const COMMAND_TIMEOUT_MS = 20_000;
|
||||
|
||||
@@ -194,6 +210,66 @@ function resolveNodeModule(name: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
function checkPlaywrightRuntime(): OfficeSkillRuntimeDiagnostics['playwright'] {
|
||||
const runtimeEnv = buildPlaywrightRuntimeEnv();
|
||||
const browsersPath = runtimeEnv.PLAYWRIGHT_BROWSERS_PATH || resolveYinianPlaywrightBrowsersPath();
|
||||
const previousBrowsersPath = process.env.PLAYWRIGHT_BROWSERS_PATH;
|
||||
process.env.PLAYWRIGHT_BROWSERS_PATH = browsersPath;
|
||||
|
||||
try {
|
||||
for (const req of buildRequireCandidates()) {
|
||||
for (const moduleName of PLAYWRIGHT_MODULE_CANDIDATES) {
|
||||
try {
|
||||
const moduleResolvedPath = req.resolve(moduleName);
|
||||
const loaded = req(moduleName) as {
|
||||
chromium?: {
|
||||
executablePath?: () => string;
|
||||
};
|
||||
};
|
||||
const chromiumExecutablePath = loaded.chromium?.executablePath?.() ?? null;
|
||||
return {
|
||||
moduleInstalled: true,
|
||||
moduleName,
|
||||
moduleResolvedPath,
|
||||
browsersPath,
|
||||
chromiumExecutablePath,
|
||||
chromiumInstalled: Boolean(chromiumExecutablePath && existsSync(chromiumExecutablePath)),
|
||||
error: null,
|
||||
};
|
||||
} catch {
|
||||
// Try the next module/root.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
moduleInstalled: false,
|
||||
moduleName: null,
|
||||
moduleResolvedPath: null,
|
||||
browsersPath,
|
||||
chromiumExecutablePath: null,
|
||||
chromiumInstalled: false,
|
||||
error: 'Playwright runtime module not found',
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
moduleInstalled: false,
|
||||
moduleName: null,
|
||||
moduleResolvedPath: null,
|
||||
browsersPath,
|
||||
chromiumExecutablePath: null,
|
||||
chromiumInstalled: false,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
};
|
||||
} finally {
|
||||
if (previousBrowsersPath === undefined) {
|
||||
delete process.env.PLAYWRIGHT_BROWSERS_PATH;
|
||||
} else {
|
||||
process.env.PLAYWRIGHT_BROWSERS_PATH = previousBrowsersPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function checkPythonPackage(pythonPath: string | null, importName: string): Promise<boolean> {
|
||||
if (!pythonPath) return false;
|
||||
const result = await runCommand(pythonPath, ['-c', `__import__(${JSON.stringify(importName)})`]);
|
||||
@@ -245,6 +321,7 @@ export async function buildOfficeSkillRuntimeDiagnostics(options: {
|
||||
|
||||
if (repairAttempted) {
|
||||
await setupManagedPython();
|
||||
ensureYinianPlaywrightRuntimeDirs();
|
||||
}
|
||||
|
||||
let pythonPath = await findManagedPythonPath();
|
||||
@@ -281,6 +358,7 @@ export async function buildOfficeSkillRuntimeDiagnostics(options: {
|
||||
};
|
||||
});
|
||||
const dotnet = await checkDotnet();
|
||||
const playwright = checkPlaywrightRuntime();
|
||||
|
||||
const missingPythonPackages = packageResults.filter((pkg) => !pkg.installed);
|
||||
const missingNodeModules = nodeModules.filter((mod) => !mod.installed);
|
||||
@@ -315,6 +393,16 @@ export async function buildOfficeSkillRuntimeDiagnostics(options: {
|
||||
? `.NET ${dotnet.version}`
|
||||
: '未找到 .NET,docx 高级 OpenXML 生成可能受限',
|
||||
},
|
||||
{
|
||||
id: 'playwright-chromium',
|
||||
label: '幻灯片浏览器预览',
|
||||
status: playwright.moduleInstalled && playwright.chromiumInstalled ? 'ok' : 'warning',
|
||||
detail: playwright.moduleInstalled
|
||||
? (playwright.chromiumInstalled
|
||||
? `Chromium 可用:${playwright.chromiumExecutablePath}`
|
||||
: `未找到 Chromium 二进制文件;浏览器预览应跳过,不要在任务中运行 npx playwright install chromium。缓存路径:${playwright.browsersPath}`)
|
||||
: `未找到 Playwright 运行时;浏览器预览应跳过。${playwright.error ?? ''}`,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
@@ -329,6 +417,7 @@ export async function buildOfficeSkillRuntimeDiagnostics(options: {
|
||||
modules: nodeModules,
|
||||
},
|
||||
dotnet,
|
||||
playwright,
|
||||
checks,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user