Download src/utils/computerUse/preauthorizedConfig.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/chenbhao/codev/resolve/3aea50af8b8df3f7d61484532efafcf2f4da86cd/src/utils/computerUse/preauthorizedConfig.ts
- Command line
-
hf download hf://chenbhao/codev@3aea50af8b8df3f7d61484532efafcf2f4da86cd/src/utils/computerUse/preauthorizedConfig.ts
-
curl -L -o preauthorizedConfig.ts https://huggingface.co/chenbhao/codev/resolve/3aea50af8b8df3f7d61484532efafcf2f4da86cd/src/utils/computerUse/preauthorizedConfig.ts
2.13 kB
| import { mkdir, readFile, writeFile } from 'node:fs/promises' | |
| import { dirname, join } from 'node:path' | |
| import type { CuGrantFlags } from '../../vendor/computer-use-mcp/types.js' | |
| import { getClaudeConfigHomeDir } from '../envUtils.js' | |
| export type StoredAuthorizedApp = { | |
| bundleId: string | |
| displayName: string | |
| authorizedAt?: string | |
| } | |
| export type StoredComputerUseConfig = { | |
| enabled?: boolean | |
| authorizedApps?: StoredAuthorizedApp[] | |
| grantFlags?: Partial<CuGrantFlags> | |
| pythonPath?: string | null | |
| } | |
| export const DEFAULT_COMPUTER_USE_ENABLED = true | |
| export const DEFAULT_DESKTOP_GRANT_FLAGS: CuGrantFlags = { | |
| clipboardRead: true, | |
| clipboardWrite: true, | |
| systemKeyCombos: true, | |
| } | |
| export function getComputerUseConfigPath(): string { | |
| return join( | |
| getClaudeConfigHomeDir(), | |
| 'cc-haha', | |
| 'computer-use-config.json', | |
| ) | |
| } | |
| export function resolveStoredComputerUseConfig( | |
| config?: StoredComputerUseConfig, | |
| ): { | |
| enabled: boolean | |
| authorizedApps: StoredAuthorizedApp[] | |
| grantFlags: CuGrantFlags | |
| pythonPath: string | null | |
| } { | |
| return { | |
| enabled: config?.enabled ?? DEFAULT_COMPUTER_USE_ENABLED, | |
| authorizedApps: config?.authorizedApps ?? [], | |
| grantFlags: { | |
| ...DEFAULT_DESKTOP_GRANT_FLAGS, | |
| ...(config?.grantFlags ?? {}), | |
| }, | |
| pythonPath: normalizePythonPath(config?.pythonPath), | |
| } | |
| } | |
| export function normalizePythonPath(value: unknown): string | null { | |
| if (typeof value !== 'string') return null | |
| const trimmed = value.trim() | |
| return trimmed.length > 0 ? trimmed : null | |
| } | |
| export async function loadStoredComputerUseConfig(): Promise< | |
| ReturnType<typeof resolveStoredComputerUseConfig> | |
| > { | |
| try { | |
| const raw = await readFile(getComputerUseConfigPath(), 'utf8') | |
| return resolveStoredComputerUseConfig(JSON.parse(raw)) | |
| } catch { | |
| return resolveStoredComputerUseConfig() | |
| } | |
| } | |
| export async function saveStoredComputerUseConfig( | |
| config: StoredComputerUseConfig, | |
| ): Promise<void> { | |
| const configPath = getComputerUseConfigPath() | |
| await mkdir(dirname(configPath), { recursive: true }) | |
| await writeFile(configPath, JSON.stringify(config, null, 2), 'utf8') | |
| } | |