蜂巢连接器
基于协议的连接器 蜂巢mcp。使hivemind代理能够通过外部渠道进行通信。
可用连接器
| 连接器 | 状态 | 描述 |
|---|---|---|
| GitHub | ✅ 完整 | 问题、PR、评论、通过IConnector协议的Webhook |
| Slack | ✅ MVP | 通过官方Java SDK将hivemind事件发送到Slack频道 |
| 线性 | 计划 | 任务同步和通知 |
| 通知 | 计划 | 文档同步 |
安装
添加到您的 deps.edn:
{:deps {io.github.hive-agi/hive-connectors {:git/tag "v0.2.0" :git/sha "..."}}}核心协议
IConnector
外部服务集成的主要协议:
(defprotocol IConnector
(connector-id [this]) ; :github, :slack, :linear
(authenticate [this creds]) ; Returns {:ok true :client ...}
(capabilities [this]) ; #{:read :write :subscribe :webhook}
(schema [this]) ; Data schema for validation
(query [this client params]) ; Query resources
(mutate [this client op data]) ; Create/update/delete
(subscribe [this client event-type callback])) ; Real-time eventsViewModel文件夹
外部数据和配置单元内存格式之间的双向映射:
(defprotocol IDataMapper
(to-memory [this data]) ; External → memory entry
(to-task [this data]) ; External → kanban task
(from-memory [this entry]) ; Memory → external
(from-task [this task])) ; Kanban → externalIWebhook处理程序
处理来自外部服务的传入webhooks:
(defprotocol IWebhookHandler
(validate-signature [this request secret])
(parse-event [this request])
(route-event [this event handlers]))用法
GitHub连接器(完整实现)
(require '[hive.connectors.github :as github]
'[hive.connectors.protocols :as proto])
;; === Using IConnector Protocol ===
(def connector (github/make-connector))
;; Authenticate
(def auth-result (proto/authenticate connector {:token "ghp_..."}))
(def client (:client auth-result))
;; Query issues
(proto/query connector client
{:resource :issues
:repo "hive-agi/hive-connectors"
:state :open
:limit 50})
;; Query pull requests
(proto/query connector client
{:resource :pull-requests
:repo "hive-agi/hive-connectors"})
;; Get single issue/PR
(proto/query connector client
{:resource :issue
:repo "hive-agi/hive-connectors"
:number 42})
(proto/query connector client
{:resource :pull-request
:repo "hive-agi/hive-connectors"
:number 10})
;; Get PR files and reviews
(proto/query connector client
{:resource :pr-files
:repo "hive-agi/hive-connectors"
:number 10})
(proto/query connector client
{:resource :pr-reviews
:repo "hive-agi/hive-connectors"
:number 10})
;; Create issue
(proto/mutate connector client :create-issue
{:repo "hive-agi/hive-connectors"
:title "Bug: something broken"
:body "Description..."
:labels ["bug" "hivemind"]})
;; Comment on issue/PR
(proto/mutate connector client :comment
{:repo "hive-agi/hive-connectors"
:number 42
:body "Automated update from hivemind"})
;; Post hivemind event notification
(proto/mutate connector client :notify
{:repo "hive-agi/hive-connectors"
:number 42
:event {:a "ling-1" :e "completed" :m "Task finished"}})
;; Close/reopen issues
(proto/mutate connector client :close-issue
{:repo "hive-agi/hive-connectors" :number 42})
(proto/mutate connector client :reopen-issue
{:repo "hive-agi/hive-connectors" :number 42})GitHub数据映射
(def mapper (github/make-data-mapper))
;; Convert GitHub issue to hive memory entry
(proto/to-memory mapper
{:number 42
:title "Bug: auth broken"
:body "Details..."
:url "https://github.com/..."
:labels ["bug" "priority:high"]})
;; => {:type :note
;; :content "# Bug: auth broken\n\nDetails..."
;; :tags ["github" "issue" "bug" "priority:high"]
;; :metadata {:external-ref {:system :github :type :issue :id "42"}
;; :external-url "https://github.com/..."}}
;; Convert to kanban task
(proto/to-task mapper issue)
;; => {:title "Bug: auth broken"
;; :status :todo
;; :priority :high
;; ...}
;; Convert memory back to GitHub format
(proto/from-memory mapper memory-entry)
;; => {:title "..." :body "..." :labels [...]}GitHub Webhooks
(def handler (github/make-webhook-handler))
;; In your webhook endpoint:
(defn handle-webhook [request]
;; Validate signature
(when (proto/validate-signature handler request webhook-secret)
;; Parse event
(let [event (proto/parse-event handler request)]
;; Route to handlers
(proto/route-event handler event
{:issue-opened (fn [e] (notify-hivemind! e))
:pr-merged (fn [e] (trigger-deploy! e))
:pr-review-submitted (fn [e] (update-status! e))}))))
;; Supported event types:
;; :issue-opened, :issue-closed, :issue-reopened
;; :issue-comment-created
;; :pr-opened, :pr-closed, :pr-merged, :pr-updated
;; :pr-review-submitted
;; :push松弛连接器
(require '[hive.connectors.slack :as slack])
;; Send a simple message
(slack/send-message! "xoxb-your-token" "#hivemind" "Hello from the hive!")
;; Format and send a hivemind event
(def event {:a "ling-1" :e "completed" :m "Finished refactoring auth module"})
(slack/notify-channel! "xoxb-your-token" "#hivemind" event)
;; => Posts: "🎉 *ling-1* completed: Finished refactoring auth module"环境变量
export GITHUB_TOKEN="ghp_your-token"
export SLACK_BOT_TOKEN="xoxb-your-bot-token"
export SLACK_CHANNEL="#hivemind"复制 .env.example 到 .env 并填写您的代币。
必需的权限
GitHub PAT范围
repo-完全控制私有存储库(或public_repo仅供公众使用)write:discussion-可选,用于讨论评论
Slack OAuth作用域
chat:write-将消息发布到频道chat:write.public-发布到机器人不是的频道
测试
# Run all tests
clj -M:test
# Run with coverage
clj -M:test:coverage测试包括:
- 格式化、解析、协议合规性的单元测试
- 集成测试(要求
GITHUB_TOKEN)
建筑
hive-connectors/
├── src/hive/connectors/
│ ├── protocols.clj # IConnector, IDataMapper, IWebhookHandler, etc.
│ ├── github.clj # Full GitHub implementation
│ └── slack.clj # Slack messaging
└── test/hive/connectors/
└── github_test.clj # Comprehensive test suite每个连接器实现:
- IConnector -主要CRUD操作
- ViewModel文件夹 -双向数据转换
- IWebhook处理程序 -实时事件处理(如适用)
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feat/linear-connector) - 实施中的协议
src/hive/connectors/ - 在中添加测试
test/hive/connectors/ - 运行测试:
clj -M:test - 提交PR
许可证
MIT许可证-请参阅 许可证
