@zhin.js/adapter-github 3.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +646 -0
  2. package/README.md +55 -203
  3. package/adapters/github.ts +51 -0
  4. package/agent/skills/github.md +2 -2
  5. package/agent/tools/bind.ts +2 -2
  6. package/agent/tools/create_pr.ts +2 -2
  7. package/agent/tools/install.ts +2 -2
  8. package/agent/tools/patch_file.ts +2 -2
  9. package/agent/tools/prepare_workspace.ts +2 -2
  10. package/agent/tools/push_branch.ts +2 -2
  11. package/agent/tools/star.ts +2 -2
  12. package/agent/tools/subscribe.ts +2 -2
  13. package/agent/tools/subscriptions.ts +2 -2
  14. package/agent/tools/unbind.ts +2 -2
  15. package/agent/tools/unsubscribe.ts +2 -2
  16. package/agent/tools/whoami.ts +2 -2
  17. package/lib/agent-prompt.d.ts +2 -0
  18. package/lib/{src/agent-prompt.js → agent-prompt.js} +0 -1
  19. package/lib/endpoint.d.ts +48 -0
  20. package/lib/endpoint.js +165 -0
  21. package/lib/gh-client.d.ts +300 -0
  22. package/lib/{src/gh-client.js → gh-client.js} +1 -2
  23. package/lib/github-agent-deps.d.ts +47 -0
  24. package/lib/github-agent-deps.js +43 -0
  25. package/lib/github-bot-handlers.d.ts +26 -0
  26. package/lib/{src/github-bot-handlers.js → github-bot-handlers.js} +0 -1
  27. package/lib/github-channel-context.d.ts +16 -0
  28. package/lib/{src/github-channel-context.js → github-channel-context.js} +0 -1
  29. package/lib/github-tool-handlers.d.ts +17 -0
  30. package/lib/{src/github-tool-handlers.js → github-tool-handlers.js} +14 -8
  31. package/lib/index.d.ts +9 -0
  32. package/lib/index.js +9 -0
  33. package/lib/oauth-users.d.ts +33 -0
  34. package/lib/oauth-users.js +38 -0
  35. package/lib/protocol.d.ts +87 -0
  36. package/lib/protocol.js +241 -0
  37. package/lib/types.d.ts +149 -0
  38. package/lib/{src/types.js → types.js} +0 -1
  39. package/lib/webhook.d.ts +13 -0
  40. package/lib/webhook.js +87 -0
  41. package/lib/workspace-manager.d.ts +21 -0
  42. package/lib/{src/workspace-manager.js → workspace-manager.js} +46 -1
  43. package/package.json +53 -26
  44. package/plugin.ts +52 -0
  45. package/schema.json +94 -0
  46. package/src/endpoint.ts +166 -175
  47. package/src/gh-client.ts +1 -1
  48. package/src/github-agent-deps.ts +66 -11
  49. package/src/github-tool-handlers.ts +20 -7
  50. package/src/index.ts +55 -137
  51. package/src/oauth-users.ts +47 -0
  52. package/src/protocol.ts +367 -0
  53. package/src/webhook.ts +125 -0
  54. package/src/workspace-manager.ts +54 -0
  55. package/lib/agent/tools/bind.js +0 -12
  56. package/lib/agent/tools/bind.js.map +0 -1
  57. package/lib/agent/tools/create_pr.js +0 -19
  58. package/lib/agent/tools/create_pr.js.map +0 -1
  59. package/lib/agent/tools/install.js +0 -12
  60. package/lib/agent/tools/install.js.map +0 -1
  61. package/lib/agent/tools/patch_file.js +0 -18
  62. package/lib/agent/tools/patch_file.js.map +0 -1
  63. package/lib/agent/tools/prepare_workspace.js +0 -14
  64. package/lib/agent/tools/prepare_workspace.js.map +0 -1
  65. package/lib/agent/tools/push_branch.js +0 -17
  66. package/lib/agent/tools/push_branch.js.map +0 -1
  67. package/lib/agent/tools/star.js +0 -15
  68. package/lib/agent/tools/star.js.map +0 -1
  69. package/lib/agent/tools/subscribe.js +0 -16
  70. package/lib/agent/tools/subscribe.js.map +0 -1
  71. package/lib/agent/tools/subscriptions.js +0 -13
  72. package/lib/agent/tools/subscriptions.js.map +0 -1
  73. package/lib/agent/tools/unbind.js +0 -12
  74. package/lib/agent/tools/unbind.js.map +0 -1
  75. package/lib/agent/tools/unsubscribe.js +0 -15
  76. package/lib/agent/tools/unsubscribe.js.map +0 -1
  77. package/lib/agent/tools/whoami.js +0 -12
  78. package/lib/agent/tools/whoami.js.map +0 -1
  79. package/lib/src/adapter.js +0 -423
  80. package/lib/src/adapter.js.map +0 -1
  81. package/lib/src/agent-prompt.js.map +0 -1
  82. package/lib/src/endpoint.js +0 -189
  83. package/lib/src/endpoint.js.map +0 -1
  84. package/lib/src/gh-client.js.map +0 -1
  85. package/lib/src/github-agent-deps.js +0 -13
  86. package/lib/src/github-agent-deps.js.map +0 -1
  87. package/lib/src/github-bot-handlers.js.map +0 -1
  88. package/lib/src/github-channel-context.js.map +0 -1
  89. package/lib/src/github-tool-handlers.js.map +0 -1
  90. package/lib/src/index.js +0 -104
  91. package/lib/src/index.js.map +0 -1
  92. package/lib/src/register-github-mcp.js +0 -41
  93. package/lib/src/register-github-mcp.js.map +0 -1
  94. package/lib/src/segment-mapper.js +0 -2
  95. package/lib/src/segment-mapper.js.map +0 -1
  96. package/lib/src/types.js.map +0 -1
  97. package/lib/src/workspace-manager.js.map +0 -1
  98. package/plugin.yml +0 -3
  99. package/src/adapter.ts +0 -454
  100. package/src/register-github-mcp.ts +0 -67
  101. package/src/segment-mapper.ts +0 -1
package/README.md CHANGED
@@ -1,19 +1,14 @@
1
1
  # @zhin.js/adapter-github
2
2
 
3
- GitHub 当聊天通道 — Issue/PR 评论区即群聊,通过 GitHub App 认证,纯 REST API 对接,零 CLI 依赖。
4
-
5
- 查询 · 管理 · 通知 · OAuth 用户绑定 四合一。
3
+ GitHub Plugin Runtime 适配器 — Issue/PR 评论区即聊天通道,GitHub App 认证,Webhook 入站经 `httpHostToken`。
6
4
 
7
5
  ## 功能特性
8
6
 
9
- - **聊天通道**:Issue/PR 评论区映射为群聊,支持收发消息
10
- - **仓库管理**:PR 合并/创建/Review/关闭、Issue 创建/关闭/评论
11
- - **信息查询**:Star、Branch、Release、CI Workflow
12
- - **事件通知**:Webhook 订阅,跨平台推送到任意聊天
13
- - **GitHub App 认证**:JWT Installation Token,自动刷新
14
- - ✅ **OAuth 用户绑定**:用户可绑定自己的 GitHub 账号,star/fork 以个人身份执行
15
- - ✅ **Bot 开发工作流**:托管 git 工作区 + App 身份 push/开 PR(HITL 确认)
16
- - ✅ **无 router 也能运行**:核心功能不依赖 HTTP 服务,有 router 时自动注册 Webhook 和 OAuth 路由
7
+ - **聊天通道**:Issue/PR 评论区映射为群聊,支持收发消息
8
+ - **Webhook 入站**:HMAC-SHA256 验签 → `messageGatewayToken`
9
+ - **出站**:`send({ target, payload })` → Issue/PR comment(target 为 channel ID)
10
+ - **GitHub App 认证**:JWT → Installation Token
11
+ - **Agent 工具**:`agent/` star/bind/subscribe/workspace 等保留
17
12
 
18
13
  ## 安装
19
14
 
@@ -21,67 +16,52 @@
21
16
  pnpm add @zhin.js/adapter-github
22
17
  ```
23
18
 
24
- ## 依赖
25
-
26
- - `@zhin.js/host-router`(可选)— 提供 Webhook 路由,用于接收 GitHub 事件推送
27
-
28
- ## GitHub App 创建
29
-
30
- 1. 访问 [GitHub Developer Settings](https://github.com/settings/apps)
31
- 2. 点击 **New GitHub App**
32
- 3. 填写基本信息:
33
- - **App name**: 你的 bot 名称
34
- - **Homepage URL**: 任意
35
- - **Webhook URL**: `http://your-server:port/pub/github/webhook`(有 HTTP 服务时)
36
- - **Webhook secret**: 自定义密钥
37
- 4. 权限设置(Permissions):
38
- - **Repository → Issues**: Read & Write
39
- - **Repository → Pull requests**: Read & Write
40
- - **Repository → Contents**: Read & Write(Bot 提交代码)
41
- - **Repository → Metadata**: Read
42
- - **Repository → Actions**: Read(查看 CI)
43
- 5. 订阅事件(Subscribe to events):
44
- - Issue comment、Pull request、Pull request review、Pull request review comment
45
- - Push、Star、Fork(用于通知)
46
- 6. 创建后记录 **App ID**,点击 **Generate a private key** 下载 `.pem` 文件
47
- 7. 安装 App 到目标仓库/组织
48
-
49
- ## 配置
19
+ Webhook 需要 Root 提供 `@zhin.js/host-http`(`zhin runtime start` 默认装配)。
20
+
21
+ ## 配置(Plugin Runtime)
50
22
 
51
23
  ```yaml
52
24
  # zhin.config.yml
53
- endpoints:
54
- - context: github
55
- name: my-github-bot
56
- app_id: 123456
57
- private_key: ./data/github-app.pem # PEM 文件路径或直接粘贴内容
58
- webhook_secret: your-secret # 可选;配置后启用 Webhook
59
- webhook_path: /pub/github/webhook # 可选
60
- auto_reply_repos: # 可选:这些 repo 的评论自动触发 AI
61
- - zhinjs/zhin
62
- workspace_root: ./data/github-workspaces # 可选:Bot git 工作区
63
-
64
25
  plugins:
65
- - database
66
- - "@zhin.js/adapter-github"
67
- - "@zhin.js/host-router" # Webhook 需要
26
+ github:
27
+ webhook_path: /github/webhook
28
+ auto_reply_repos:
29
+ - zhinjs/zhin
30
+ workspace_root: ./data/github-workspaces
31
+ endpoints:
32
+ - name: my-github-bot
33
+ app_id: 123456
34
+ private_key: ./data/github-app.pem
35
+ webhook_secret: your-secret
68
36
  ```
69
37
 
70
38
  ```env
71
39
  GITHUB_APP_ID=123456
72
40
  GITHUB_WEBHOOK_SECRET=your-secret
73
- # MCP server-github(可选;PAT = 人身份,默认关闭)
74
- # ai.githubMcp.enabled: true
75
- # GITHUB_PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxx
76
41
  ```
77
42
 
78
- `private_key` 支持两种写法:
79
- - 文件路径:`./data/github-app.pem`
80
- - 直接内容:`"-----BEGIN RSA PRIVATE KEY-----\n..."`
43
+ `private_key` 支持文件路径或 PEM 内容。未配置 `webhook_secret` 时仅 API 出站 / agent 工具可用(无入站)。
81
44
 
82
- ## Channel ID 格式
45
+ App:一个插件实例挂多个 endpoint(`endpoints` 数组逐项覆盖顶层字段,`name` 必填):
83
46
 
84
- GitHub adapter 将 Issue/PR 映射为聊天频道:
47
+ ```yaml
48
+ plugins:
49
+ github:
50
+ endpoints:
51
+ - name: app-a
52
+ app_id: 123456
53
+ private_key: ./data/app-a.pem
54
+ - name: app-b
55
+ app_id: 234567
56
+ private_key: ./data/app-b.pem
57
+ ```
58
+
59
+ ## 已移除的配置
60
+
61
+ - **`ai.githubMcp.enabled` / `ai.githubMcp.token`**:Plugin Runtime 迁移后 `register-github-mcp`(stdio `@modelcontextprotocol/server-github`,PAT 人身份)已移除,该配置不再生效。如需 MCP 工具,请按新运行时 `mcp/<name>.ts`(`@zhin.js/mcp-feature`)约定自行装配。
62
+ - **`poll_interval`**:轮询降级已删除,仅 webhook 入站;该字段目前解析但不生效(deferred)。
63
+
64
+ ## Channel ID
85
65
 
86
66
  | 类型 | Channel ID | 示例 |
87
67
  |------|-----------|------|
@@ -90,151 +70,23 @@ GitHub adapter 将 Issue/PR 映射为聊天频道:
90
70
 
91
71
  ## AI 工具
92
72
 
93
- ### 适配器内置(Zhin 专有)
94
-
95
- | 工具 | 说明 |
96
- |------|------|
97
- | `github_star` | Star / Unstar / 检查(per-user OAuth 或 Endpoint 默认) |
98
- | `github_bind` / `github_unbind` / `github_whoami` | 用户 GitHub 账号绑定 |
99
- | `github_install` | GitHub App 安装链接 |
100
- | `github_subscribe` / `github_unsubscribe` / `github_subscriptions` | 频道级 Webhook 订阅 |
101
- | `github_prepare_workspace` | Clone/fetch 托管工作区并 checkout 分支 |
102
- | `github_patch_file` | Contents API 单文件更新(Bot 身份) |
103
- | `github_push_branch` | git commit + push(**需 HITL**) |
104
- | `github_create_pr` | 创建 PR(**需 HITL**) |
105
-
106
- ### Bot 工作流(App 身份)
107
-
108
- - 评论回复:Webhook → `$reply`,Installation Token,UI 显示 `{slug}[bot]` + **Bot** 徽章
109
- - 开发提交:`github_prepare_workspace` → bash 改代码 → `github_push_branch`(确认)→ Issue 场景 `github_create_pr`
110
- - PR 线程:push 到现有 PR head 分支,不新开 PR
111
- - 工作区默认:`data/github-workspaces/{owner}/{repo}`
112
-
113
- ### MCP(`@modelcontextprotocol/server-github`,可选)
114
-
115
- 仅当 `ai.githubMcp.enabled: true` 且配置 PAT 时注册。`mcp_github_*` 以**用户 PAT** 操作,**不能**作为 Bot 写仓库。Bot 写操作请用上方 `github_*` 工具。
116
-
117
- ### 使用示例
118
-
119
- ```
120
- AI: 列出 zhinjs/zhin 的 PR
121
- AI: 合并 zhinjs/zhin 的 PR #108
122
- AI: 查看 zhinjs/zhin 的 star 数
123
- AI: 订阅 zhinjs/zhin 的 push 和 pr 事件
124
- AI: 搜索 zhinjs 相关的仓库
125
- AI: 给 zhinjs/zhin 的 issue #42 加上 bug 标签
126
- AI: 查看 zhinjs/zhin 的 README.md 文件
127
- AI: 对比 zhinjs/zhin 的 main 和 dev 分支
128
- AI: 编辑 zhinjs/zhin 的 issue #42 标题
129
- AI: 绑定我的 GitHub 账号
130
- AI: star zhinjs/zhin
131
- AI: fork zhinjs/zhin # 使用 mcp_github_fork_repository
132
- ```
133
-
134
- ## Webhook 事件通知
135
-
136
- 配置好 Webhook 后,支持以下事件的跨平台推送:
137
-
138
- | 事件 | 参数 | 说明 |
139
- |------|------|------|
140
- | Push | `push` | 代码推送 |
141
- | Issue | `issue` | Issue 创建/更新/关闭 |
142
- | Star | `star` | 仓库被 star |
143
- | Unstar | `unstar` | 仓库被 unstar |
144
- | Fork | `fork` | 仓库被 fork |
145
- | Pull Request | `pr` / `pull_request` | PR 创建/更新/合并 |
146
-
147
- ### Webhook 端点
73
+ `agent/tools/`:`github_star`、`github_bind`、`github_subscribe`、`github_prepare_workspace` 等。
148
74
 
149
- ```
150
- POST /pub/github/webhook
151
- ```
152
-
153
- Headers:
154
- - `X-GitHub-Event`: 事件类型
155
- - `X-Hub-Signature-256`: 签名(配置了 secret 时)
156
-
157
- ## OAuth 用户绑定(Device Flow)
158
-
159
- 用户通过工具 **`github_bind`** 绑定 GitHub 账号([OAuth Device Flow](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow)),**不是**浏览器 OAuth 回调页面。
160
-
161
- ### 认证策略
162
-
163
- | 操作类型 | 使用的 Token | 原因 |
164
- |---------|------------|------|
165
- | 读取 issue/PR/repo 信息 | App JWT | 不涉及用户身份 |
166
- | 评论(bot 发言) | App Installation Token | 以 `{slug}[bot]` 机器人身份发言 |
167
- | push / 开 PR | App Installation Token + git author | UI **Bot** 徽章(非 Member) |
168
- | star / unstar | User OAuth | 个人行为 |
169
- | fork | User OAuth | 个人行为 |
170
-
171
- ### 绑定流程
172
-
173
- 1. 用户在聊天中触发 `github_bind`(或说「绑定 GitHub」)
174
- 2. Endpoint 返回 **verification URI** 与 **user code**(GitHub Device Flow)
175
- 3. 用户在浏览器打开链接并输入 code 完成授权
176
- 4. Token 写入 `github_oauth_users` 表;可用 `github_whoami` / `github_unbind` 管理
177
-
178
- **Client ID**:从 GitHub App 的 `/app` API 自动获取(`GhClient.getClientId()`),**无需**在 Endpoint 配置里写 `client_id` / `client_secret`。
179
-
180
- ### 前置条件
181
-
182
- - 需要 **`database`** 插件(`github_oauth_users` 模型)
183
- - Device Flow 在 IM 内完成,**不依赖** `/pub/github/oauth` HTTP 路由
184
-
185
- ## 数据库表
75
+ ## 架构
186
76
 
187
- ### github_subscriptions
188
-
189
- | 字段 | 类型 | 说明 |
190
- |------|------|------|
191
- | id | integer | 主键 |
192
- | repo | text | 仓库名 (owner/repo) |
193
- | events | json | 订阅的事件列表 |
194
- | target_id | text | 目标频道 ID |
195
- | target_type | text | 类型 (private/group/channel) |
196
- | adapter | text | 适配器名称 |
197
- | endpoint | text | 机器人名称 |
198
-
199
- ### github_events
200
-
201
- | 字段 | 类型 | 说明 |
202
- |------|------|------|
203
- | id | integer | 主键 |
204
- | repo | text | 仓库名 |
205
- | event_type | text | 事件类型 |
206
- | payload | json | 事件载荷 |
207
-
208
- ### github_oauth_users
209
-
210
- | 字段 | 类型 | 说明 |
211
- |------|------|------|
212
- | id | integer | 主键 |
213
- | platform | text | 聊天平台 |
214
- | platform_uid | text | 平台用户 ID |
215
- | github_login | text | GitHub 用户名 |
216
- | access_token | text | Device Flow 获得的 token |
217
- | created_at | integer | 创建时间戳 |
218
-
219
- ## 架构说明
220
-
221
- ```
222
- adapter-github/
223
- ├── src/
224
- │ ├── index.ts # 插件入口:provide、useContext、模型表
225
- │ ├── adapter.ts # GitHubAdapter
226
- │ ├── endpoint.ts # GitHubEndpoint(Issue/PR 频道)
227
- │ ├── gh-client.ts # GitHub REST(App JWT / Installation Token)
228
- │ ├── register-github-mcp.ts # orchestrator.addMcp(server-github)
229
- │ ├── agent-prompt.ts # 平台 prompt / deferred 工具筛选
230
- │ └── types.ts # EndpointConfig、Webhook payload、Channel ID
231
- ├── package.json
232
- └── README.md
233
- ```
234
-
235
- - **无 `@zhin.js/host-router` 时**:REST 工具与轮询仍可用,但无法注册 Webhook
236
- - **有 `@zhin.js/host-router` 时**:注册 Webhook;MCP 通过 `orchestrator.addMcp`(需 PAT 或 `ai.githubMcp.token`)
237
-
238
- ## 许可证
77
+ | 路径 | 职责 |
78
+ |------|------|
79
+ | `plugin.ts` | 插件元数据;有 DatabaseHost 时定义 `github_oauth_users` |
80
+ | `adapters/github.ts` | 薄 `defineAdapter` 入口(发现约定) |
81
+ | `src/endpoint.ts` | Endpoint 生命周期、出站、admit |
82
+ | `src/webhook.ts` | HMAC 验签与事件分发 |
83
+ | `src/oauth-users.ts` | OAuth SSOT + token 查找 |
84
+ | `src/protocol.ts` | 协议纯函数(channel / payload) |
85
+ | `src/gh-client.ts` | GitHub API 客户端 |
86
+
87
+ - 入站:`httpHostToken` POST `messageGatewayToken.receive`
88
+ - 出站:`send({ target, payload })`
89
+
90
+ ## License
239
91
 
240
92
  MIT
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Convention entry: discover `adapters/github.ts` → defineAdapter.
3
+ * Implementation lives under `src/` (endpoint / webhook / oauth / protocol).
4
+ */
5
+ import { defineAdapter, type AdapterContext } from '@zhin.js/adapter';
6
+ import { messageGatewayToken } from '@zhin.js/core/runtime';
7
+ import { httpHostToken } from '@zhin.js/host-http';
8
+ import {
9
+ databaseHostToken,
10
+ type DatabaseHost,
11
+ } from '@zhin.js/plugin-runtime';
12
+ import { GithubEndpoint } from '../src/endpoint.js';
13
+ import {
14
+ resolveGithubConfig,
15
+ type GithubAdapterConfig,
16
+ } from '../src/protocol.js';
17
+
18
+ export { GithubEndpoint } from '../src/endpoint.js';
19
+ export type { GithubEndpointOptions } from '../src/endpoint.js';
20
+
21
+ function optionalDatabase(context: AdapterContext): DatabaseHost | undefined {
22
+ try {
23
+ return context.use(databaseHostToken);
24
+ } catch {
25
+ return undefined;
26
+ }
27
+ }
28
+
29
+ export default defineAdapter<GithubAdapterConfig>({
30
+ capabilities: ['inbound', 'outbound'],
31
+ create(context) {
32
+ const config = resolveGithubConfig(context.config);
33
+ const database = optionalDatabase(context);
34
+ if (config.webhookSecret) {
35
+ return new GithubEndpoint({
36
+ id: context.id,
37
+ gateway: context.use(messageGatewayToken),
38
+ http: context.use(httpHostToken),
39
+ database,
40
+ config,
41
+ });
42
+ }
43
+ // API-only: Issue/PR send + agent tools without webhook.
44
+ return new GithubEndpoint({
45
+ id: context.id,
46
+ gateway: context.use(messageGatewayToken),
47
+ database,
48
+ config,
49
+ });
50
+ },
51
+ });
@@ -77,7 +77,7 @@ requires:
77
77
  本技能提供三种操作方式:
78
78
  - **适配器内置工具**(`github_*`):用户交互类操作,具备账号绑定、Device Flow 授权、频道级订阅等适配器专有逻辑
79
79
  - **Bot 写仓库工具**(`github_prepare_workspace` / `github_patch_file` / `github_push_branch` / `github_create_pr`):Installation Token,UI 显示 **Bot** 身份;push/开 PR 需 HITL
80
- - **MCP server-github**(`mcp_github_*`,可选):需 `ai.githubMcp.enabled: true` + PAT,**人身份**,勿用于 Bot 写仓库
80
+ - **MCP server-github**(`mcp_github_*`,可选):`ai.githubMcp.*` 配置已随 Plugin Runtime 迁移移除;如需 MCP 工具,按 `mcp/<name>.ts` 约定自行装配(PAT 为**人身份**,勿用于 Bot 写仓库)
81
81
  - **bash + gh CLI**:仓库自动化操作,灵活覆盖 GitHub API 全场景
82
82
 
83
83
  ## 一、适配器内置工具
@@ -129,7 +129,7 @@ Issue 线程:新分支 → 开发 → push → 开 PR。PR 线程:push 到
129
129
 
130
130
  1. `github_star` 优先使用用户绑定的 GitHub 账号,未绑定则降级为 Endpoint 默认账号
131
131
  2. Bot 写仓库用 `github_*` 工具,不用 `mcp_github_*` 写操作
132
- 3. MCP opt-in(`ai.githubMcp.enabled: true`),PAT 为人身份
132
+ 3. MCP(`mcp_github_*`)仅在你按 `mcp/<name>.ts` 约定装配后可用(旧 `ai.githubMcp.enabled` 已移除),PAT 为人身份
133
133
  4. 当用户想操作自己的 GitHub 账号进行 Star 时,先引导用户使用 `github_bind` 绑定
134
134
  5. Webhook 订阅关联到当前聊天通道,仅在该通道接收事件通知
135
135
 
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubBind } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool({
5
+ export default defineAgentTool({
6
6
  description: '绑定你的 GitHub 账号 — 使用 Device Flow 授权,无需输入密码',
7
7
  inputSchema: z.object({}),
8
8
  tags: ['github'],
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubCreatePr } from '../../src/github-bot-handlers.js';
4
4
 
5
- export default defineTool<{ repo?: string; title: string; body?: string; head?: string; base?: string }>({
5
+ export default defineAgentTool<{ repo?: string; title: string; body?: string; head?: string; base?: string }>({
6
6
  description: '以 GitHub App Bot 身份创建 Pull Request(需 HITL 确认;Issue 场景常用)',
7
7
  inputSchema: z.object({
8
8
  repo: z.string().optional().describe('owner/repo'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubInstall } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool({
5
+ export default defineAgentTool({
6
6
  description: '获取安装 GitHub App 的链接 — 安装后 Endpoint 可以访问你的仓库,你也可以使用更多功能',
7
7
  inputSchema: z.object({}),
8
8
  tags: ['github'],
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubPatchFile } from '../../src/github-bot-handlers.js';
4
4
 
5
- export default defineTool<{ repo?: string; path: string; content: string; message: string; branch?: string }>({
5
+ export default defineAgentTool<{ repo?: string; path: string; content: string; message: string; branch?: string }>({
6
6
  description: '通过 Contents API 单文件更新(小改;Bot Installation Token 身份)',
7
7
  inputSchema: z.object({
8
8
  repo: z.string().optional().describe('owner/repo'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubPrepareWorkspace } from '../../src/github-bot-handlers.js';
4
4
 
5
- export default defineTool<{ repo?: string }>({
5
+ export default defineAgentTool<{ repo?: string }>({
6
6
  description: 'Clone/fetch 托管工作区并 checkout 到 Issue/PR 对应分支(GitHub App Bot 身份)',
7
7
  inputSchema: z.object({
8
8
  repo: z.string().optional().describe('owner/repo,缺省从当前 Issue/PR 频道推断'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubPushBranch } from '../../src/github-bot-handlers.js';
4
4
 
5
- export default defineTool<{ repo?: string; branch?: string; message: string }>({
5
+ export default defineAgentTool<{ repo?: string; branch?: string; message: string }>({
6
6
  description: '在托管工作区 git commit 并 push 到远程分支(需 HITL 确认;Bot 身份)',
7
7
  inputSchema: z.object({
8
8
  repo: z.string().optional().describe('owner/repo'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubStar } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool<{ action: 'star' | 'unstar' | 'check'; repo: string }>({
5
+ export default defineAgentTool<{ action: 'star' | 'unstar' | 'check'; repo: string }>({
6
6
  description: 'Star 或取消 Star 一个 GitHub 仓库(使用你绑定的 GitHub 账号,未绑定则用 Endpoint 默认账号)',
7
7
  inputSchema: z.object({
8
8
  action: z.enum(['star', 'unstar', 'check']),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubSubscribe } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool<{ repo: string; events?: string }>({
5
+ export default defineAgentTool<{ repo: string; events?: string }>({
6
6
  description: '订阅 GitHub 仓库的 Webhook 事件,事件将推送到当前聊天通道',
7
7
  inputSchema: z.object({
8
8
  repo: z.string().min(1),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubSubscriptions } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool({
5
+ export default defineAgentTool({
6
6
  description: '查看当前聊天通道的 GitHub 仓库订阅列表',
7
7
  inputSchema: z.object({}),
8
8
  platforms: ['github'],
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubUnbind } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool({
5
+ export default defineAgentTool({
6
6
  description: '解除你绑定的 GitHub 账号',
7
7
  inputSchema: z.object({}),
8
8
  tags: ['github'],
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubUnsubscribe } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool<{ repo: string }>({
5
+ export default defineAgentTool<{ repo: string }>({
6
6
  description: '取消订阅 GitHub 仓库的 Webhook 事件',
7
7
  inputSchema: z.object({
8
8
  repo: z.string().min(1),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { executeGithubWhoami } from '../../src/github-tool-handlers.js';
4
4
 
5
- export default defineTool({
5
+ export default defineAgentTool({
6
6
  description: '查看你绑定的 GitHub 账号信息',
7
7
  inputSchema: z.object({}),
8
8
  tags: ['github'],
@@ -0,0 +1,2 @@
1
+ import type { AgentPromptContributor } from 'zhin.js';
2
+ export declare function createGithubAgentPromptContributor(): AgentPromptContributor;
@@ -82,4 +82,3 @@ export function createGithubAgentPromptContributor() {
82
82
  },
83
83
  };
84
84
  }
85
- //# sourceMappingURL=agent-prompt.js.map
@@ -0,0 +1,48 @@
1
+ import type { EndpointInstance } from '@zhin.js/adapter';
2
+ import type { MessageGateway } from '@zhin.js/core/runtime';
3
+ import type { HttpHost } from '@zhin.js/host-http';
4
+ import type { CapabilityId, DatabaseHost } from '@zhin.js/plugin-runtime';
5
+ import { GhClient } from './gh-client.js';
6
+ import { type GithubInboundComment, type ResolvedGithubConfig } from './protocol.js';
7
+ import { WorkspaceManager } from './workspace-manager.js';
8
+ export interface GithubEndpointOptions {
9
+ readonly id: CapabilityId;
10
+ readonly gateway: MessageGateway;
11
+ readonly http?: HttpHost;
12
+ readonly database?: DatabaseHost;
13
+ readonly config: ResolvedGithubConfig;
14
+ readonly createClient?: (config: ResolvedGithubConfig) => GhClient;
15
+ }
16
+ export declare class GithubEndpoint implements EndpointInstance {
17
+ #private;
18
+ readonly gh: GhClient;
19
+ readonly config: ResolvedGithubConfig;
20
+ readonly name: string;
21
+ constructor(options: GithubEndpointOptions);
22
+ getAPI(): GhClient;
23
+ getUserOrDefaultAPI(platform?: string, platformUid?: string): Promise<GhClient | null>;
24
+ getClientId(): string | null;
25
+ getHost(): string | undefined;
26
+ getAppSlug(): string | null;
27
+ getInstallations(): {
28
+ id: number;
29
+ account: {
30
+ login: string;
31
+ type: string;
32
+ };
33
+ target_type: string;
34
+ }[];
35
+ getWorkspaceManager(): WorkspaceManager;
36
+ getDatabase(): DatabaseHost | undefined;
37
+ start(): Promise<void>;
38
+ open(): void;
39
+ close(): void;
40
+ stop(): Promise<void>;
41
+ send({ target, payload }: {
42
+ readonly target: string;
43
+ readonly payload: unknown;
44
+ }): Promise<string>;
45
+ /** Test / internal: admit a parsed comment when open. */
46
+ admit(comment: GithubInboundComment): void;
47
+ }
48
+ export declare function defaultCreateClient(config: ResolvedGithubConfig): GhClient;