agentpaas-notify.ts 849 B

123456789101112131415161718192021222324
  1. import type { Plugin } from "@opencode-ai/plugin"
  2. import { loadAgentPaaSConfig } from "../lib/agentpaas"
  3. import { approvalMonitor } from "../lib/approval-monitor"
  4. const plugin: Plugin = async ({ client }) => {
  5. const config = await loadAgentPaaSConfig().catch(() => undefined)
  6. if (!config) return {}
  7. const monitor = approvalMonitor(config, async (message) => {
  8. const response = await client.tui.showToast({
  9. body: { title: "PaaS 待审批", message, variant: "warning", duration: 10000 },
  10. })
  11. if (response.error) throw new Error("提醒未投递")
  12. })
  13. void monitor.poll().catch(() => undefined)
  14. return {
  15. async dispose() {
  16. monitor.dispose()
  17. },
  18. async "tool.execute.after"(input) {
  19. if (input.tool.startsWith("agentpaas_")) void monitor.poll().catch(() => undefined)
  20. },
  21. }
  22. }
  23. export default plugin