copilot.ts 620 B

12345678910111213141516171819
  1. import { Global } from "../global"
  2. import { lazy } from "../util/lazy"
  3. import path from "path"
  4. export const AuthCopilot = lazy(async () => {
  5. const file = Bun.file(path.join(Global.Path.state, "plugin", "copilot.ts"))
  6. const exists = await file.exists()
  7. const response = fetch("https://raw.githubusercontent.com/sst/opencode-github-copilot/refs/heads/main/auth.ts")
  8. .then((x) => Bun.write(file, x))
  9. .catch(() => {})
  10. if (!exists) {
  11. const worked = await response
  12. if (!worked) return
  13. }
  14. const result = await import(file.name!).catch(() => {})
  15. if (!result) return
  16. return result.AuthCopilot
  17. })