Files
workdsh/workdsh-web/scripts/probe-computer-use-native.mjs
techflag 748234a317 Add 'workdsh-web/' from commit '03b63ea143747b6c75e1f60bace0d9f338918455'
git-subtree-dir: workdsh-web
git-subtree-mainline: d3a7b2143d
git-subtree-split: 03b63ea143
2026-09-26 10:26:35 +08:00

33 lines
1.5 KiB
JavaScript

import { createRequire } from 'node:module';
import { dirname, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const require = createRequire(import.meta.url);
const providerManifest = require.resolve('@deepseek-ai/dsh-experimental-computer-use-cua-driver-native/package.json', {
paths: [fileURLToPath(new URL('../packages/bundle', import.meta.url))],
});
const sdkPath = resolve(dirname(providerManifest), '../../@trycua/cua-driver/dist/index.js');
const { CuaDriver } = await import(pathToFileURL(sdkPath).href);
const driver = CuaDriver.create(undefined);
try {
const catalog = JSON.parse(await driver.listToolsJson());
const names = catalog.tools?.map((tool) => tool.name) ?? [];
if (!names.includes('check_permissions')) throw new Error('Cua Driver did not publish check_permissions.');
const result = await driver.callTool('check_permissions', JSON.stringify({ prompt: false }));
const permission = JSON.parse(result.rawJson);
const state = permission.structuredContent;
if (!state || typeof state.accessibility !== 'boolean' || typeof state.screen_recording !== 'boolean') {
throw new Error('Cua Driver returned an invalid permission result.');
}
console.log(JSON.stringify({
provider: 'cua-driver-native',
toolCount: names.length,
accessibility: state.accessibility,
screenRecording: state.screen_recording,
directCaptureStatus: state.direct_capture_status ?? null,
}, null, 2));
} finally {
await driver.shutdown();
driver.uniffiDestroy();
}