eigent/src/host
Tong Chen 97d7554438
Some checks failed
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Pre-commit / pre-commit (push) Has been cancelled
Test / Run Web + Local Brain Smoke (push) Has been cancelled
Test / Run Frontend Guardrails (push) Has been cancelled
Test / Run Python Tests (push) Has been cancelled
release: Eigent 1.0.0 (#1695)
Co-authored-by: Douglas <douglas.ym.lai@gmail.com>
Co-authored-by: Douglas Lai <115660088+Douglasymlai@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Tao Sun <168447269+fengju0213@users.noreply.github.com>
Co-authored-by: Weijie Bai <happy.regina.bai@gmail.com>
2026-06-17 00:29:35 +08:00
..
context.tsx release: Eigent 1.0.0 (#1695) 2026-06-17 00:29:35 +08:00
createHost.ts release: Eigent 1.0.0 (#1695) 2026-06-17 00:29:35 +08:00
index.ts release: Eigent 1.0.0 (#1695) 2026-06-17 00:29:35 +08:00
README.md release: Eigent 1.0.0 (#1695) 2026-06-17 00:29:35 +08:00
types.ts release: Eigent 1.0.0 (#1695) 2026-06-17 00:29:35 +08:00

Host 抽象层

统一桌面Electron与 Web 的能力注入,避免在业务代码中显式判断运行环境。

使用方式

import { useHost } from '@/host';

function MyComponent() {
  const host = useHost();
  // host.electronAPI / host.ipcRenderer 在 Web 下为 null
  if (host?.electronAPI?.someMethod) {
    host.electronAPI.someMethod();
  }
}

初始化

main.tsx 中通过 createHost() 创建 hostHostProvider 注入。createHost() 是唯一读取 window 的地方。

后续扩展

  • 桌面端若用其他技术栈Tauri、原生等重构只需提供新的 host 实现
  • CLI、Browser Extension 等可复用同一套 React 组件,注入不同的 host