@github-tools/sdk 1.2.0 → 1.4.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.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <img src="https://github.com/vercel-labs/github-tools/blob/main/assets/banner.jpg" width="100%" alt="GitHub Tools banner" />
2
+
1
3
  # @github-tools/sdk
2
4
 
3
5
  [![npm version](https://img.shields.io/npm/v/@github-tools/sdk?color=black)](https://npmjs.com/package/@github-tools/sdk)
@@ -7,7 +9,7 @@
7
9
 
8
10
  GitHub tools for the [AI SDK](https://ai-sdk.dev) — wrap GitHub's REST API as ready-to-use tools for any agent or `generateText` / `streamText` call.
9
11
 
10
- 18 tools covering repositories, pull requests, issues, commits, and search. Write operations support granular approval control out of the box.
12
+ 42 tools covering repositories, branches, pull requests, issues, commits, search, gists, and workflows. Write operations support granular approval control out of the box.
11
13
 
12
14
  ## Installation
13
15
 
@@ -60,10 +62,11 @@ createGithubTools({ token, preset: ['code-review', 'issue-triage'] })
60
62
 
61
63
  | Preset | Tools included |
62
64
  |---|---|
63
- | `code-review` | `getPullRequest`, `listPullRequests`, `getFileContent`, `listCommits`, `getCommit`, `getRepository`, `listBranches`, `searchCode`, `addPullRequestComment` |
64
- | `issue-triage` | `listIssues`, `getIssue`, `createIssue`, `addIssueComment`, `closeIssue`, `getRepository`, `searchRepositories`, `searchCode` |
65
- | `repo-explorer` | All read-only tools (no write operations) |
66
- | `maintainer` | All 18 tools |
65
+ | `code-review` | `getPullRequest`, `listPullRequests`, `listPullRequestFiles`, `listPullRequestReviews`, `getFileContent`, `listCommits`, `getCommit`, `getBlame`, `getRepository`, `listBranches`, `searchCode`, `addPullRequestComment`, `createPullRequestReview` |
66
+ | `issue-triage` | `listIssues`, `getIssue`, `createIssue`, `addIssueComment`, `closeIssue`, `listLabels`, `addLabels`, `removeLabel`, `getRepository`, `searchRepositories`, `searchCode` |
67
+ | `repo-explorer` | All read-only tools including gists and workflows (no write operations) |
68
+ | `ci-ops` | `listWorkflows`, `listWorkflowRuns`, `getWorkflowRun`, `listWorkflowJobs`, `triggerWorkflow`, `cancelWorkflowRun`, `rerunWorkflowRun`, `getRepository`, `listBranches`, `listCommits`, `getCommit` |
69
+ | `maintainer` | All 42 tools |
67
70
 
68
71
  Omit `preset` to get all tools (same as `maintainer`).
69
72
 
@@ -72,16 +75,18 @@ Omit `preset` to get all tools (same as `maintainer`).
72
75
  You can also import individual tool factories for full control:
73
76
 
74
77
  ```ts
75
- import { createOctokit, listPullRequests, createIssue } from '@github-tools/sdk'
78
+ import { listPullRequests, createIssue } from '@github-tools/sdk'
76
79
 
77
- const octokit = createOctokit(process.env.GITHUB_TOKEN!)
80
+ const token = process.env.GITHUB_TOKEN!
78
81
 
79
82
  const tools = {
80
- listPullRequests: listPullRequests(octokit),
81
- createIssue: createIssue(octokit),
83
+ listPullRequests: listPullRequests(token),
84
+ createIssue: createIssue(token),
82
85
  }
83
86
  ```
84
87
 
88
+ Each tool factory accepts a `token` string. Tools use named module-level step functions with `"use step"` internally, ensuring proper step registration and full Node.js access when running inside a Vercel Workflow sandbox. See [Durable Agents](#durable-agents-vercel-workflow-sdk).
89
+
85
90
  ## Approval Control
86
91
 
87
92
  Write operations (creating issues, merging PRs, pushing files, …) require user approval by default. This is designed for human-in-the-loop agent workflows.
@@ -108,10 +113,81 @@ createGithubTools({
108
113
  })
109
114
  ```
110
115
 
111
- Write tools: `createOrUpdateFile`, `createPullRequest`, `mergePullRequest`, `addPullRequestComment`, `createIssue`, `addIssueComment`, `closeIssue`.
116
+ Write tools: `createOrUpdateFile`, `createPullRequest`, `mergePullRequest`, `addPullRequestComment`, `createPullRequestReview`, `createIssue`, `addIssueComment`, `closeIssue`, `addLabels`, `removeLabel`, `createGist`, `updateGist`, `deleteGist`, `createGistComment`, `triggerWorkflow`, `cancelWorkflowRun`, `rerunWorkflowRun`.
112
117
 
113
118
  All other tools are read-only and never require approval.
114
119
 
120
+ ### Tool overrides
121
+
122
+ The `overrides` option lets you customize any AI SDK [`tool()`](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) property on a per-tool basis, keyed by tool name.
123
+
124
+ ```ts
125
+ import type { ToolOverrides } from "@github-tools/sdk";
126
+ ```
127
+
128
+ Supported override properties:
129
+
130
+ | Property | Type | Description |
131
+ |----------|------|-------------|
132
+ | `description` | `string` | Custom tool description for the model |
133
+ | `title` | `string` | Human-readable title |
134
+ | `strict` | `boolean` | Strict mode for input generation |
135
+ | `needsApproval` | `boolean \| function` | Gate execution behind approval |
136
+ | `providerOptions` | `ProviderOptions` | Provider-specific metadata |
137
+ | `onInputStart` | `function` | Callback when argument streaming starts |
138
+ | `onInputDelta` | `function` | Callback on each streaming delta |
139
+ | `onInputAvailable` | `function` | Callback when full input is available |
140
+ | `toModelOutput` | `function` | Custom mapping of tool result to model output |
141
+
142
+ Core properties (`execute`, `inputSchema`, `outputSchema`) cannot be overridden.
143
+
144
+ ## Tool Selection with toolpick
145
+
146
+ With dozens of tools, context window usage adds up. [toolpick](https://github.com/pontusab/toolpick) selects only the most relevant tools per step so the model sees what it needs:
147
+
148
+ ```ts
149
+ import { createGithubTools } from '@github-tools/sdk'
150
+ import { createToolIndex } from 'toolpick'
151
+ import { generateText } from 'ai'
152
+ import { openai } from '@ai-sdk/openai'
153
+
154
+ const tools = createGithubTools()
155
+ const index = createToolIndex(tools, {
156
+ embeddingModel: openai.embeddingModel('text-embedding-3-small'),
157
+ })
158
+
159
+ const result = await generateText({
160
+ model: openai('gpt-4o'),
161
+ tools,
162
+ prepareStep: index.prepareStep(),
163
+ prompt: 'List open PRs on vercel/ai and summarize them.',
164
+ })
165
+ ```
166
+
167
+ Each step, toolpick picks the best ~5 tools using keyword + semantic search. All tools remain callable — only the visible set changes. See [toolpick docs](https://github.com/pontusab/toolpick) for LLM re-ranking, caching, and model-driven discovery options.
168
+
169
+ ## Durable Agents (Vercel Workflow SDK)
170
+
171
+ All tools include `"use step"` directives with named, module-level step functions, making them natively compatible with the Vercel Workflow SDK. Each tool execution runs as a properly registered durable step with full Node.js access in the workflow sandbox.
172
+
173
+ Use `DurableAgent` via the `@github-tools/sdk/workflow` subpath to make every LLM call and tool execution a retryable, crash-safe step:
174
+
175
+ ```ts
176
+ import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
177
+
178
+ const agent = createDurableGithubAgent({
179
+ model: 'anthropic/claude-sonnet-4.6',
180
+ token: process.env.GITHUB_TOKEN!,
181
+ preset: 'maintainer',
182
+ })
183
+ ```
184
+
185
+ All presets work with `createDurableGithubAgent`.
186
+
187
+ > **Approval control limitation**: `requireApproval` is accepted for forward-compatibility but is currently ignored by `DurableAgent`. The Workflow SDK does not yet support interactive tool approval — all tools execute immediately. Use `createGithubAgent` (standard `ToolLoopAgent`) when human-in-the-loop approval is required.
188
+
189
+ > `workflow` and `@workflow/ai` are optional peer dependencies — install them only when using the workflow subpath.
190
+
115
191
  ## Available Tools
116
192
 
117
193
  ### Repository
@@ -129,9 +205,12 @@ All other tools are read-only and never require approval.
129
205
  |---|---|
130
206
  | `listPullRequests` | List PRs filtered by state |
131
207
  | `getPullRequest` | Get a PR's full details (diff stats, body, merge status) |
208
+ | `listPullRequestFiles` | List files changed in a PR with diff status and patches |
209
+ | `listPullRequestReviews` | List reviews on a PR (approvals, change requests, comments) |
132
210
  | `createPullRequest` | Open a new PR |
133
211
  | `mergePullRequest` | Merge a PR (merge, squash, or rebase) |
134
212
  | `addPullRequestComment` | Post a comment on a PR |
213
+ | `createPullRequestReview` | Submit a formal review (approve, request changes, or comment) with inline comments |
135
214
 
136
215
  ### Issues
137
216
 
@@ -142,6 +221,33 @@ All other tools are read-only and never require approval.
142
221
  | `createIssue` | Open a new issue |
143
222
  | `addIssueComment` | Post a comment on an issue |
144
223
  | `closeIssue` | Close an issue (completed or not planned) |
224
+ | `listLabels` | List labels available in a repository |
225
+ | `addLabels` | Add labels to an issue or pull request |
226
+ | `removeLabel` | Remove a label from an issue or pull request |
227
+
228
+ ### Gists
229
+
230
+ | Tool | Description |
231
+ |---|---|
232
+ | `listGists` | List gists for the authenticated user or a specific user |
233
+ | `getGist` | Get a gist including file contents |
234
+ | `listGistComments` | List comments on a gist |
235
+ | `createGist` | Create a new gist with one or more files |
236
+ | `updateGist` | Update a gist's description or files |
237
+ | `deleteGist` | Delete a gist permanently |
238
+ | `createGistComment` | Post a comment on a gist |
239
+
240
+ ### Workflows
241
+
242
+ | Tool | Description |
243
+ |---|---|
244
+ | `listWorkflows` | List GitHub Actions workflows in a repository |
245
+ | `listWorkflowRuns` | List workflow runs filtered by workflow, branch, status, or event |
246
+ | `getWorkflowRun` | Get a workflow run's status, timing, and trigger info |
247
+ | `listWorkflowJobs` | List jobs in a workflow run with step-level status |
248
+ | `triggerWorkflow` | Trigger a workflow via workflow_dispatch event |
249
+ | `cancelWorkflowRun` | Cancel an in-progress workflow run |
250
+ | `rerunWorkflowRun` | Re-run a workflow run, optionally only failed jobs |
145
251
 
146
252
  ### Commits
147
253
 
@@ -149,6 +255,7 @@ All other tools are read-only and never require approval.
149
255
  |---|---|
150
256
  | `listCommits` | List commits, optionally filtered by file path, author, or date range |
151
257
  | `getCommit` | Get a commit's full details including changed files and diffs |
258
+ | `getBlame` | Line-level git blame for a file (GitHub GraphQL) |
152
259
 
153
260
  ### Search
154
261
 
@@ -168,12 +275,17 @@ Create one at **GitHub → Settings → Developer settings → Personal access t
168
275
  | Permission | Level | Required for |
169
276
  |---|---|---|
170
277
  | **Metadata** | Read-only | Always required (auto-included) |
171
- | **Contents** | Read-only | `getRepository`, `listBranches`, `getFileContent`, `listCommits`, `getCommit` |
278
+ | **Contents** | Read-only | `getRepository`, `listBranches`, `getFileContent`, `listCommits`, `getCommit`, `getBlame` |
172
279
  | **Contents** | Read and write | `createOrUpdateFile` |
173
- | **Pull requests** | Read-only | `listPullRequests`, `getPullRequest` |
174
- | **Pull requests** | Read and write | `createPullRequest`, `mergePullRequest`, `addPullRequestComment` |
175
- | **Issues** | Read-only | `listIssues`, `getIssue` |
176
- | **Issues** | Read and write | `createIssue`, `addIssueComment`, `closeIssue` |
280
+ | **Pull requests** | Read-only | `listPullRequests`, `getPullRequest`, `listPullRequestFiles`, `listPullRequestReviews` |
281
+ | **Pull requests** | Read and write | `createPullRequest`, `mergePullRequest`, `addPullRequestComment`, `createPullRequestReview` |
282
+ | **Issues** | Read-only | `listIssues`, `getIssue`, `listLabels` |
283
+ | **Issues** | Read and write | `createIssue`, `addIssueComment`, `closeIssue`, `addLabels`, `removeLabel` |
284
+
285
+ | **Gists** | Read-only | `listGists`, `getGist`, `listGistComments` |
286
+ | **Gists** | Read and write | `createGist`, `updateGist`, `deleteGist`, `createGistComment` |
287
+ | **Actions** | Read-only | `listWorkflows`, `listWorkflowRuns`, `getWorkflowRun`, `listWorkflowJobs` |
288
+ | **Actions** | Read and write | `triggerWorkflow`, `cancelWorkflowRun`, `rerunWorkflowRun` |
177
289
 
178
290
  Search tools (`searchCode`, `searchRepositories`) work with any token.
179
291
 
@@ -192,12 +304,12 @@ Returns an object of tools, ready to spread into `tools` of any AI SDK call.
192
304
 
193
305
  ```ts
194
306
  type GithubToolsOptions = {
195
- token: string
307
+ token?: string // defaults to process.env.GITHUB_TOKEN
196
308
  requireApproval?: boolean | Partial<Record<GithubWriteToolName, boolean>>
197
309
  preset?: GithubToolPreset | GithubToolPreset[]
198
310
  }
199
311
 
200
- type GithubToolPreset = 'code-review' | 'issue-triage' | 'repo-explorer' | 'maintainer'
312
+ type GithubToolPreset = 'code-review' | 'issue-triage' | 'repo-explorer' | 'ci-ops' | 'maintainer'
201
313
  ```
202
314
 
203
315
  ### `createGithubAgent(options)`
@@ -251,9 +363,40 @@ const stream = reviewer.stream({ prompt: 'Review PR #42 on vercel/ai' })
251
363
 
252
364
  All other `ToolLoopAgent` options (`stopWhen`, `toolChoice`, `onStepFinish`, etc.) are passed through.
253
365
 
366
+ ### `createDurableGithubAgent(options)`
367
+
368
+ Returns a `DurableAgent` instance for use inside Vercel Workflow SDK functions. Every LLM call and tool execution runs as a durable step with automatic retries and crash recovery.
369
+
370
+ Requires the optional peer dependencies `workflow` and `@workflow/ai`:
371
+
372
+ ```sh
373
+ pnpm add workflow @workflow/ai
374
+ ```
375
+
376
+ ```ts
377
+ import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
378
+ import { getWritable } from 'workflow'
379
+ import type { ModelMessage, UIMessageChunk } from 'ai'
380
+
381
+ async function chatWorkflow(messages: ModelMessage[], token: string) {
382
+ "use workflow"
383
+ const agent = createDurableGithubAgent({
384
+ model: 'anthropic/claude-sonnet-4.6',
385
+ token,
386
+ preset: 'code-review',
387
+ })
388
+ const writable = getWritable<UIMessageChunk>()
389
+ await agent.stream({ messages, writable })
390
+ }
391
+ ```
392
+
393
+ All presets (`code-review`, `issue-triage`, `ci-ops`, `repo-explorer`, `maintainer`) work with `createDurableGithubAgent`. The options are the same as `createGithubAgent` except it returns a `DurableAgent` instead of a `ToolLoopAgent`.
394
+
395
+ > **Note:** `requireApproval` is accepted but currently ignored by `DurableAgent` — the Workflow SDK does not yet support interactive tool approval.
396
+
254
397
  ### `createOctokit(token)`
255
398
 
256
- Returns a configured [`@octokit/rest`](https://github.com/octokit/rest.js) instance. Useful when cherry-picking individual tools or building custom ones.
399
+ Returns a configured [`octokit`](https://github.com/octokit/octokit.js) instance. Useful for building custom tools.
257
400
 
258
401
  ## License
259
402