コンテンツにスキップ

ComputerUse

デスクトップ環境と対話するためのコンピュータ操作機能。

プロパティ:

  • display Display - ディスプレイ操作インターフェース
  • keyboard Keyboard - キーボード操作インターフェース
  • mouse Mouse - マウス操作インターフェース
  • screenshot Screenshot - スクリーンショット操作インターフェース

サンドボックス(Daytonaで管理される隔離された一時的な計算環境)内でのデスクトップ操作を自動化するために、マウス、キーボード、スクリーンショット、ディスプレイの各操作にアクセスできます。

コンストラクタ

new ComputerUse()

new ComputerUse(sandboxId: string, toolboxApi: ToolboxApi): ComputerUse

パラメータ:

  • sandboxId string
  • toolboxApi ToolboxApi

戻り値:

  • ComputerUse

メソッド

getProcessErrors()

getProcessErrors(processName: string): Promise<ProcessErrorsResponse>

特定のVNCプロセスのエラーログを取得します

パラメータ:

  • processName string - エラーログを取得するプロセス名

戻り値:

  • Promise<ProcessErrorsResponse> - プロセスのエラーログ

例:

const errorsResp = await sandbox.computerUse.getProcessErrors('x11vnc');
console.log('X11VNC errors:', errorsResp.errors);

getProcessLogs()

getProcessLogs(processName: string): Promise<ProcessLogsResponse>

特定のVNCプロセスのログを取得します

パラメータ:

  • processName string - ログを取得するプロセス名

戻り値:

  • Promise<ProcessLogsResponse> - プロセスのログ

例:

const logsResp = await sandbox.computerUse.getProcessLogs('novnc');
console.log('NoVNC logs:', logsResp.logs);

getProcessStatus()

getProcessStatus(processName: string): Promise<ProcessStatusResponse>

特定のVNCプロセスのステータスを取得します

パラメータ:

  • processName string - 確認するプロセス名

戻り値:

  • Promise<ProcessStatusResponse> - 特定のプロセスに関するステータス情報

例:

const xvfbStatus = await sandbox.computerUse.getProcessStatus('xvfb');
const noVncStatus = await sandbox.computerUse.getProcessStatus('novnc');

getStatus()

getStatus(): Promise<ComputerUseStatusResponse>

すべてのコンピュータ操作プロセスのステータスを取得します

戻り値:

  • Promise<ComputerUseStatusResponse> - すべてのVNCデスクトッププロセスに関するステータス情報

例:

const status = await sandbox.computerUse.getStatus();
console.log('Computer use status:', status.status);

restartProcess()

restartProcess(processName: string): Promise<ProcessRestartResponse>

特定のVNCプロセスを再起動します

パラメータ:

  • processName string - 再起動するプロセス名

戻り値:

  • Promise<ProcessRestartResponse> - プロセス再起動のレスポンス

例:

const result = await sandbox.computerUse.restartProcess('xfce4');
console.log('XFCE4 process restarted:', result.message);

start()

start(): Promise<ComputerUseStartResponse>

すべてのコンピュータ操作プロセス(Xvfb、xfce4、x11vnc、novnc)を開始します

戻り値:

  • Promise<ComputerUseStartResponse> - コンピュータ操作の開始レスポンス

例:

const result = await sandbox.computerUse.start();
console.log('Computer use processes started:', result.message);

stop()

stop(): Promise<ComputerUseStopResponse>

すべてのコンピュータ操作プロセスを停止します

戻り値:

  • Promise<ComputerUseStopResponse> - コンピュータ操作の停止レスポンス

例:

const result = await sandbox.computerUse.stop();
console.log('Computer use processes stopped:', result.message);

Display

コンピュータ操作機能のためのディスプレイ操作

コンストラクタ

new Display()

new Display(sandboxId: string, toolboxApi: ToolboxApi): Display

パラメータ:

  • sandboxId string
  • toolboxApi ToolboxApi

戻り値:

  • Display

メソッド

getInfo()

getInfo(): Promise<DisplayInfoResponse>

ディスプレイに関する情報を取得します

戻り値:

  • Promise<DisplayInfoResponse> - プライマリディスプレイおよび利用可能なすべてのディスプレイを含むディスプレイ情報

例:

const info = await sandbox.computerUse.display.getInfo();
console.log(`Primary display: ${info.primary_display.width}x${info.primary_display.height}`);
console.log(`Total displays: ${info.total_displays}`);
info.displays.forEach((display, index) => {
console.log(`Display ${index}: ${display.width}x${display.height} at ${display.x},${display.y}`);
});

getWindows()

getWindows(): Promise<WindowsResponse>

開いているウィンドウの一覧を取得します

戻り値:

  • Promise<WindowsResponse> - IDとタイトルを含む開いているウィンドウの一覧

例:

const windows = await sandbox.computerUse.display.getWindows();
console.log(`Found ${windows.count} open windows:`);
windows.windows.forEach(window => {
console.log(`- ${window.title} (ID: ${window.id})`);
});

キーボード

コンピュータ操作機能のためのキーボード操作

コンストラクター

new Keyboard()

new Keyboard(sandboxId: string, toolboxApi: ToolboxApi): Keyboard

パラメータ:

  • sandboxId string
  • toolboxApi ToolboxApi

戻り値:

  • Keyboard

メソッド

hotkey()

hotkey(keys: string): Promise<void>

ホットキーの組み合わせを送信します

パラメータ:

  • keys string - ホットキーの組み合わせ(例: ‘ctrl+c’, ‘alt+tab’, ‘cmd+shift+t’)

戻り値:

  • Promise<void>

スロー:

ホットキー操作に失敗した場合

例:

// Copy
try {
await sandbox.computerUse.keyboard.hotkey('ctrl+c');
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}
// Paste
try {
await sandbox.computerUse.keyboard.hotkey('ctrl+v');
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}
// Alt+Tab
try {
await sandbox.computerUse.keyboard.hotkey('alt+tab');
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}

press()

press(key: string, modifiers?: string[]): Promise<void>

必要に応じて修飾キーと併せてキーを押下します

パラメータ:

  • key string - 押下するキー(例: ‘Enter’, ‘Escape’, ‘Tab’, ‘a’, ‘A’)
  • modifiers? string[] = [] - 修飾キー(‘ctrl’, ‘alt’, ‘meta’, ‘shift’)

戻り値:

  • Promise<void>

スロー:

キー押下操作に失敗した場合

例:

// Press Enter
try {
await sandbox.computerUse.keyboard.press('Return');
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}
// Press Ctrl+C
try {
await sandbox.computerUse.keyboard.press('c', ['ctrl']);
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}
// Press Ctrl+Shift+T
try {
await sandbox.computerUse.keyboard.press('t', ['ctrl', 'shift']);
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}

type()

type(text: string, delay?: number): Promise<void>

指定したテキストを入力します

パラメータ:

  • text string - 入力するテキスト
  • delay? number - 文字間の遅延(ミリ秒)

戻り値:

  • Promise<void>

スロー:

入力操作に失敗した場合

例:

try {
await sandbox.computerUse.keyboard.type('Hello, World!');
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}
// With delay between characters
try {
await sandbox.computerUse.keyboard.type('Slow typing', 100);
console.log('Operation success');
} catch (e) {
console.log('Operation failed:', e);
}

Mouse

コンピュータ操作(Computer Use)機能におけるマウス操作

Constructors

new Mouse()

new Mouse(sandboxId: string, toolboxApi: ToolboxApi): Mouse

Parameters:

  • sandboxId string
  • toolboxApi ToolboxApi

Returns:

  • Mouse

Methods

click()

click(
x: number,
y: number,
button?: string,
double?: boolean): Promise<MouseClickResponse>

指定した座標でマウスクリックを実行します

Parameters:

  • x number - クリック先のx座標
  • y number - クリック先のy座標
  • button? string = ‘left’ - 使用するマウスボタン(‘left’、‘right’、‘middle’)
  • double? boolean = false - ダブルクリックを行うかどうか

Returns:

  • Promise<MouseClickResponse> - クリック操作の結果

Example:

// Single left click
const result = await sandbox.computerUse.mouse.click(100, 200);
// Double click
const doubleClick = await sandbox.computerUse.mouse.click(100, 200, 'left', true);
// Right click
const rightClick = await sandbox.computerUse.mouse.click(100, 200, 'right');

drag()

drag(
startX: number,
startY: number,
endX: number,
endY: number,
button?: string): Promise<MouseDragResponse>

開始座標から終了座標までドラッグします

Parameters:

  • startX number - 開始x座標
  • startY number - 開始y座標
  • endX number - 終了x座標
  • endY number - 終了y座標
  • button? string = ‘left’ - ドラッグに使用するマウスボタン

Returns:

  • Promise<MouseDragResponse> - ドラッグ操作の結果

Example:

const result = await sandbox.computerUse.mouse.drag(50, 50, 150, 150);
console.log(`Dragged from ${result.from.x},${result.from.y} to ${result.to.x},${result.to.y}`);

getPosition()

getPosition(): Promise<MousePosition>

現在のマウスカーソル位置を取得します

Returns:

  • Promise<MousePosition> - x座標とy座標を含む現在のマウス位置

Example:

const position = await sandbox.computerUse.mouse.getPosition();
console.log(`Mouse is at: ${position.x}, ${position.y}`);

move()

move(x: number, y: number): Promise<MouseMoveResponse>

指定した座標にマウスカーソルを移動します

Parameters:

  • x number - 移動先のx座標
  • y number - 移動先のy座標

Returns:

  • Promise<MouseMoveResponse> - 移動操作の結果

Example:

const result = await sandbox.computerUse.mouse.move(100, 200);
console.log(`Mouse moved to: ${result.x}, ${result.y}`);

scroll()

scroll(
x: number,
y: number,
direction: "up" | "down",
amount?: number): Promise<boolean>

指定した座標でマウスホイールをスクロールします

Parameters:

  • x number - スクロール先のx座標
  • y number - スクロール先のy座標
  • direction スクロール方向 - "up" | "down"
  • amount? number = 1 - スクロール量

Returns:

  • Promise<boolean> - スクロール操作が成功したかどうか

Example:

// Scroll up
const scrollUp = await sandbox.computerUse.mouse.scroll(100, 200, 'up', 3);
// Scroll down
const scrollDown = await sandbox.computerUse.mouse.scroll(100, 200, 'down', 5);

スクリーンショット

コンピュータ操作機能におけるスクリーンショット操作

コンストラクタ

new Screenshot()

new Screenshot(sandboxId: string, toolboxApi: ToolboxApi): Screenshot

パラメータ:

  • sandboxId string
  • toolboxApi ToolboxApi

戻り値:

  • Screenshot

メソッド

takeCompressed()

takeCompressed(options?: ScreenshotOptions): Promise<CompressedScreenshotResponse>

画面全体の圧縮スクリーンショットを取得します

パラメータ:

  • options? ScreenshotOptions = - 圧縮および表示のオプション

戻り値:

  • Promise<CompressedScreenshotResponse> - 圧縮スクリーンショットのデータ

例:

// 既定の圧縮
const screenshot = await sandbox.computerUse.screenshot.takeCompressed();
// 高品質 JPEG
const jpeg = await sandbox.computerUse.screenshot.takeCompressed({
format: 'jpeg',
quality: 95,
showCursor: true
});
// 縮小した PNG
const scaled = await sandbox.computerUse.screenshot.takeCompressed({
format: 'png',
scale: 0.5
});

takeCompressedRegion()

takeCompressedRegion(region: ScreenshotRegion, options?: ScreenshotOptions): Promise<CompressedScreenshotResponse>

特定の領域の圧縮スクリーンショットを取得します

パラメータ:

  • region ScreenshotRegion - 取得対象の領域
  • options? ScreenshotOptions = - 圧縮および表示のオプション

戻り値:

  • Promise<CompressedScreenshotResponse> - 圧縮スクリーンショットのデータ

例:

const region = { x: 0, y: 0, width: 800, height: 600 };
const screenshot = await sandbox.computerUse.screenshot.takeCompressedRegion(region, {
format: 'webp',
quality: 80,
showCursor: true
});
console.log(`Compressed size: ${screenshot.size_bytes} bytes`);

takeFullScreen()

takeFullScreen(showCursor?: boolean): Promise<ScreenshotResponse>

画面全体のスクリーンショットを取得します

パラメータ:

  • showCursor? boolean = false - スクリーンショットにカーソルを表示するかどうか

戻り値:

  • Promise<ScreenshotResponse> - 画像を base64 でエンコードしたスクリーンショットデータ

例:

const screenshot = await sandbox.computerUse.screenshot.takeFullScreen();
console.log(`Screenshot size: ${screenshot.width}x${screenshot.height}`);
// カーソルを表示する場合
const withCursor = await sandbox.computerUse.screenshot.takeFullScreen(true);

takeRegion()

takeRegion(region: ScreenshotRegion, showCursor?: boolean): Promise<RegionScreenshotResponse>

特定の領域のスクリーンショットを取得します

パラメータ:

  • region ScreenshotRegion - 取得対象の領域
  • showCursor? boolean = false - スクリーンショットにカーソルを表示するかどうか

戻り値:

  • Promise<RegionScreenshotResponse> - 画像を base64 でエンコードしたスクリーンショットデータ

例:

const region = { x: 100, y: 100, width: 300, height: 200 };
const screenshot = await sandbox.computerUse.screenshot.takeRegion(region);
console.log(`Captured region: ${screenshot.region.width}x${screenshot.region.height}`);

ScreenshotOptions

スクリーンショット圧縮オプション用のインターフェース

プロパティ:

  • format? string
  • quality? number
  • scale? number
  • showCursor? boolean

ScreenshotRegion

スクリーンショット操作で使用される領域座標のインターフェース

プロパティ:

  • height number
  • width number
  • x number
  • y number