Skip to main content

Computer Control API

ควบคุม computer ที่ลงทะเบียนจากระยะไกล — จัดคิวคำสั่ง, จับภาพ screenshot, รันสคริปต์บนเครื่องระยะไกล


Computer Control API

Computer Control API ช่วยให้คุณควบคุม computer ที่ลงทะเบียนจากระยะไกล agent ตัวเล็ก ๆ (screen-remote-agent) รันบนเครื่องเป้าหมาย, poll หาคำสั่ง, ปฏิบัติตามคำสั่ง, และส่งผลลัพธ์กลับ ทำให้สามารถทำ GUI automation ที่ขับเคลื่อนด้วย LLM ได้

Architecture

┌─────────────┐  queue cmd   ┌──────────┐  poll   ┌─────────────────┐
│ LLM Agent   │ ───────────▶ │ Synapse  │ ◀───── │ screen-remote   │
│ (user-side) │              │  Server  │ ──────▶│ (on target PC)  │
└─────────────┘              └──────────┘ result  └─────────────────┘
                                     ▲
                                     │
                              ┌─────────────┐
                              │  Human UI   │
                              │ (browser)   │
                              └─────────────┘

User-Facing Endpoints (Mind Key or JWT)

GET /computers/list

รายการ computer ที่ลงทะเบียนทั้งหมด

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/computers/list

GET /computers/:id

ดึงรายละเอียดของ computer เครื่องเดียว

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/computers/comp_001

POST /computers/install-code

สร้าง install code สำหรับลงทะเบียน computer เครื่องใหม่

curl -X POST https://synapse.schaefer.zone/computers/install-code \
  -H "Authorization: Bearer YOUR_MIND_KEY" \
  -H "Content-Type: application/json" \
  -d '{"computer_name": "office-mac"}'

Response: { "install_code": "ic_xyz789", "expires_at": "..." }

POST /computers/:id/commands

จัดคิวคำสั่งให้ remote agent ปฏิบัติ

curl -X POST https://synapse.schaefer.zone/computers/comp_001/commands \
  -H "Authorization: Bearer YOUR_MIND_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "screenshot",
    "payload": {}
  }'

Response: { "command_id": "cmd_001", "status": "queued" }

GET /computers/:id/command (via query)

จัดคิวคำสั่งผ่าน GET (สำหรับกรณีง่าย ๆ)

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/computers/comp_001/command?type=screenshot"

GET /computers/:id/commands

รายการคำสั่งล่าสุดของ computer

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/computers/comp_001/commands?limit=50"

GET /computers/:id/commands/:cid

ดึงสถานะ + ผลลัพธ์ของคำสั่งเฉพาะ

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/computers/comp_001/commands/cmd_001

GET /computers/:id/screenshot

แบบ one-shot: จัดคิวคำสั่ง screenshot และรอผลลัพธ์สูงสุด 30 วินาที

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/computers/comp_001/screenshot > screenshot.png

POST /computers/:id/disable

ปิดใช้งาน computer (เพิกถอน token แต่เก็บ record ไว้เพื่อ audit)

curl -X POST -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/computers/comp_001/disable

DELETE /computers/:id

ลบ computer อย่างถาวร

curl -X DELETE -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/computers/comp_001

Agent-Facing Endpoints (Computer Token)

endpoint เหล่านี้ใช้โดย screen-remote-agent ที่รันอยู่บนเครื่องเป้าหมาย ใช้ Computer Token (ส่งกลับโดย /computers/register) ไม่ใช่ Mind Key

POST /computers/register

แลกรับ install code เพื่อรับ Computer Token

curl -X POST https://synapse.schaefer.zone/computers/register \
  -H "Content-Type: application/json" \
  -d '{
    "code": "ic_xyz789",
    "computer_name": "office-mac",
    "platform": "darwin",
    "platform_release": "14.5.0",
    "python": "3.12.4"
  }'

Response: { "computer_id": "comp_001", "computer_token": "ct_..." }

บันทึก `computer_token` ไว้ — แสดงเพียงครั้งเดียวและต้องใช้สำหรับ endpoint ฝั่ง agent ทั้งหมด

GET /computers/me/poll

Long-poll หาคำสั่งใหม่ agent เรียกสิ่งนี้ในลูป

curl -H "Authorization: Bearer ct_YOUR_COMPUTER_TOKEN" \
     "https://synapse.schaefer.zone/computers/me/poll?wait=30"

ส่งกลับทันทีหากมีคำสั่งรออยู่ หรือหลังจาก wait วินาที หากไม่มี

POST /computers/me/commands/:cid/result

ส่งผลลัพธ์การปฏิบัติคำสั่ง

curl -X POST https://synapse.schaefer.zone/computers/me/commands/cmd_001/result \
  -H "Authorization: Bearer ct_YOUR_COMPUTER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "done",
    "result": { "screenshot_b64": "iVBORw0KG..." }
  }'

ประเภทคำสั่ง

Type Payload คำอธิบาย
screenshot {} จับภาพหน้าจอเป็น PNG (base64)
click {x, y} คลิกที่พิกัด
move {x, y} เลื่อนเมาส์ไปยังพิกัด
type {text} พิมพ์ข้อความที่ตำแหน่งเคอร์เซอร์
key {keys: ["Ctrl","c"]} กดปุ่มผสม
scroll {deltaX, deltaY} เลื่อน scroll wheel
drag {fromX, fromY, toX, toY} ลากและวาง

รูปแบบทั่วไป: LLM-Driven GUI Automation

# LLM agent workflow
1. List computers: GET /computers/list
2. Take screenshot: GET /computers/:id/screenshot
3. Analyze screenshot (vision model)
4. Queue click: POST /computers/:id/commands {type:"click", payload:{x,y}}
5. Wait for result: GET /computers/:id/commands/:cid
6. Take new screenshot to verify
7. Repeat until task done

ขั้นตอนถัดไป