@aigne/afs-github 1.11.0-beta.6

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/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ # Proprietary License
2
+
3
+ Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
4
+
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. Unauthorized copying, modification, distribution, or use of
7
+ this Software, via any medium, is strictly prohibited.
8
+
9
+ The Software is provided for internal use only within ArcBlock, Inc. and its
10
+ authorized affiliates.
11
+
12
+ ## No License Granted
13
+
14
+ No license, express or implied, is granted to any party for any purpose.
15
+ All rights are reserved by ArcBlock, Inc.
16
+
17
+ ## Public Artifact Distribution
18
+
19
+ Portions of this Software may be released publicly under separate open-source
20
+ licenses (such as MIT License) through designated public repositories. Such
21
+ public releases are governed by their respective licenses and do not affect
22
+ the proprietary nature of this repository.
23
+
24
+ ## Contact
25
+
26
+ For licensing inquiries, contact: legal@arcblock.io
package/README.md ADDED
@@ -0,0 +1,342 @@
1
+ # @aigne/afs-github
2
+
3
+ **@aigne/afs-github** is an AFS provider that enables access to GitHub Issues, Pull Requests, and Actions through the AFS virtual file system interface. It transforms GitHub's REST API into a familiar path-based structure.
4
+
5
+ ## Overview
6
+
7
+ AFSGitHub allows AI agents to interact with GitHub repositories using the same file-system-like API as other AFS modules. Browse issues like directories, read PR details like files, and navigate repository data through intuitive paths.
8
+
9
+ ## Features
10
+
11
+ - **GitHub API Integration**: Full access to Issues, Pull Requests, and more
12
+ - **Path-Based Access**: Navigate GitHub data using familiar paths
13
+ - **Single/Multi-Repo Modes**: Work with one repository or multiple
14
+ - **Built-in Caching**: Reduce API calls with configurable cache
15
+ - **Rate Limit Handling**: Automatic retry with exponential backoff
16
+ - **World Mapping Capable**: Supports dynamic mapping configuration
17
+ - **Enterprise Support**: Compatible with GitHub Enterprise
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @aigne/afs-github @aigne/afs
23
+ # or
24
+ yarn add @aigne/afs-github @aigne/afs
25
+ # or
26
+ pnpm add @aigne/afs-github @aigne/afs
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```typescript
32
+ import { AFS } from "@aigne/afs";
33
+ import { AFSGitHub } from "@aigne/afs-github";
34
+
35
+ // Create AFS instance
36
+ const afs = new AFS();
37
+
38
+ // Mount GitHub provider for a single repository
39
+ afs.mount(new AFSGitHub({
40
+ auth: { token: process.env.GITHUB_TOKEN },
41
+ owner: "aigne",
42
+ repo: "afs",
43
+ }));
44
+ // Accessible at /modules/github
45
+
46
+ // List issues
47
+ const { data: issues } = await afs.list("/modules/github/issues");
48
+
49
+ // Read a specific issue
50
+ const { data: issue } = await afs.read("/modules/github/issues/123");
51
+ console.log(issue.summary); // Issue title
52
+ console.log(issue.content); // Issue body
53
+
54
+ // List pull requests
55
+ const { data: prs } = await afs.list("/modules/github/pulls");
56
+
57
+ // Read a specific PR
58
+ const { data: pr } = await afs.read("/modules/github/pulls/456");
59
+ ```
60
+
61
+ ## Configuration
62
+
63
+ ### AFSGitHubOptions
64
+
65
+ ```typescript
66
+ interface AFSGitHubOptions {
67
+ // Module identification
68
+ name?: string; // Module name (default: "github")
69
+ description?: string; // Description for AI agents
70
+
71
+ // Authentication
72
+ auth?: {
73
+ token?: string; // Personal Access Token
74
+ };
75
+
76
+ // Repository settings
77
+ owner?: string; // Repository owner (required for single-repo mode)
78
+ repo?: string; // Repository name (required for single-repo mode)
79
+ mode?: "single-repo" | "multi-repo"; // Access mode (default: "single-repo")
80
+
81
+ // API settings
82
+ accessMode?: "readonly" | "readwrite"; // Access level (default: "readonly")
83
+ baseUrl?: string; // API base URL (default: "https://api.github.com")
84
+ mappingPath?: string; // Custom mapping configuration path
85
+
86
+ // Performance
87
+ cache?: {
88
+ enabled?: boolean; // Enable caching (default: true)
89
+ ttl?: number; // Cache TTL in ms (default: 60000)
90
+ };
91
+ rateLimit?: {
92
+ autoRetry?: boolean; // Auto-retry on rate limit (default: true)
93
+ maxRetries?: number; // Max retry attempts (default: 3)
94
+ };
95
+ }
96
+ ```
97
+
98
+ ### Single-Repo Mode (Default)
99
+
100
+ Access a specific repository without including owner/repo in paths:
101
+
102
+ ```typescript
103
+ const github = new AFSGitHub({
104
+ auth: { token: process.env.GITHUB_TOKEN },
105
+ owner: "aigne",
106
+ repo: "afs",
107
+ });
108
+
109
+ // Paths are relative to the repository
110
+ await afs.list("/modules/github/issues"); // Lists aigne/afs issues
111
+ await afs.read("/modules/github/issues/123"); // Reads aigne/afs#123
112
+ ```
113
+
114
+ ### Multi-Repo Mode
115
+
116
+ Access multiple repositories by including owner/repo in paths:
117
+
118
+ ```typescript
119
+ const github = new AFSGitHub({
120
+ auth: { token: process.env.GITHUB_TOKEN },
121
+ mode: "multi-repo",
122
+ });
123
+
124
+ // Include owner/repo in paths
125
+ await afs.list("/modules/github/aigne/afs/issues");
126
+ await afs.list("/modules/github/facebook/react/pulls");
127
+ ```
128
+
129
+ ## Path Structure
130
+
131
+ ### Issues
132
+
133
+ ```
134
+ /issues # List all issues
135
+ /issues?state=open # Filter by state
136
+ /issues?state=closed
137
+ /issues/{number} # Read specific issue
138
+ ```
139
+
140
+ ### Pull Requests
141
+
142
+ ```
143
+ /pulls # List all PRs
144
+ /pulls?state=open # Filter by state
145
+ /pulls?state=closed
146
+ /pulls?state=merged
147
+ /pulls/{number} # Read specific PR
148
+ ```
149
+
150
+ ## Operations
151
+
152
+ ### list(path, options?)
153
+
154
+ List issues or pull requests:
155
+
156
+ ```typescript
157
+ // List open issues (default)
158
+ const { data } = await afs.list("/modules/github/issues");
159
+
160
+ // List closed issues
161
+ const { data } = await afs.list("/modules/github/issues", {
162
+ filter: { state: "closed" },
163
+ });
164
+
165
+ // List open pull requests
166
+ const { data } = await afs.list("/modules/github/pulls");
167
+
168
+ // Each entry includes:
169
+ // - id: Issue/PR number
170
+ // - path: Full AFS path
171
+ // - summary: Title
172
+ // - content: Body text
173
+ // - metadata: { type, state, author }
174
+ ```
175
+
176
+ ### read(path)
177
+
178
+ Read a specific issue or PR:
179
+
180
+ ```typescript
181
+ const { data } = await afs.read("/modules/github/issues/123");
182
+
183
+ // Returns:
184
+ // {
185
+ // id: "123",
186
+ // path: "/issues/123",
187
+ // summary: "Issue title",
188
+ // content: "Issue body text...",
189
+ // metadata: {
190
+ // type: "issue",
191
+ // state: "open",
192
+ // author: "username"
193
+ // }
194
+ // }
195
+ ```
196
+
197
+ ## Integration with AI Agents
198
+
199
+ AFSGitHub integrates seamlessly with AIGNE agents:
200
+
201
+ ```typescript
202
+ import { AIAgent, AIGNE } from "@aigne/core";
203
+ import { AFS } from "@aigne/afs";
204
+ import { AFSGitHub } from "@aigne/afs-github";
205
+ import { OpenAIChatModel } from "@aigne/openai";
206
+
207
+ const aigne = new AIGNE({
208
+ model: new OpenAIChatModel({ apiKey: process.env.OPENAI_API_KEY }),
209
+ });
210
+
211
+ const afs = new AFS();
212
+ afs.mount(new AFSGitHub({
213
+ auth: { token: process.env.GITHUB_TOKEN },
214
+ owner: "aigne",
215
+ repo: "afs",
216
+ description: "AFS GitHub repository issues and PRs",
217
+ }));
218
+
219
+ const agent = AIAgent.from({
220
+ name: "github-assistant",
221
+ instructions: "You help users manage GitHub issues and pull requests",
222
+ afs: afs,
223
+ });
224
+
225
+ const context = aigne.newContext();
226
+ const result = await context.invoke(agent, {
227
+ message: "What are the open issues in this repository?",
228
+ });
229
+ ```
230
+
231
+ ## World Mapping
232
+
233
+ AFSGitHub implements the `AFSWorldMappingCapable` interface, allowing dynamic mapping configuration:
234
+
235
+ ```typescript
236
+ const github = new AFSGitHub({
237
+ auth: { token: process.env.GITHUB_TOKEN },
238
+ owner: "aigne",
239
+ repo: "afs",
240
+ });
241
+
242
+ // Get mapping status
243
+ const status = github.getMappingStatus();
244
+ // { loaded: true, routes: 4, operations: 4, ... }
245
+
246
+ // Load custom mapping
247
+ await github.loadMapping("/path/to/custom-mapping");
248
+
249
+ // Reload mapping
250
+ await github.reloadMapping();
251
+
252
+ // Resolve path to external reference
253
+ const ref = github.resolve("/issues/123");
254
+ // { type: "http", target: "https://api.github.com/repos/...", method: "GET", ... }
255
+ ```
256
+
257
+ ## GitHub Enterprise
258
+
259
+ For GitHub Enterprise installations:
260
+
261
+ ```typescript
262
+ const github = new AFSGitHub({
263
+ auth: { token: process.env.GHE_TOKEN },
264
+ owner: "my-org",
265
+ repo: "my-repo",
266
+ baseUrl: "https://github.mycompany.com/api/v3",
267
+ });
268
+ ```
269
+
270
+ ## Authentication
271
+
272
+ ### Personal Access Token
273
+
274
+ Create a token at https://github.com/settings/tokens with appropriate scopes:
275
+
276
+ - `repo` - Full control of private repositories
277
+ - `public_repo` - Access public repositories only
278
+
279
+ ```typescript
280
+ const github = new AFSGitHub({
281
+ auth: { token: process.env.GITHUB_TOKEN },
282
+ owner: "aigne",
283
+ repo: "afs",
284
+ });
285
+ ```
286
+
287
+ ### Without Authentication
288
+
289
+ Public repositories can be accessed without authentication (with lower rate limits):
290
+
291
+ ```typescript
292
+ const github = new AFSGitHub({
293
+ owner: "facebook",
294
+ repo: "react",
295
+ });
296
+ ```
297
+
298
+ ## Rate Limiting
299
+
300
+ GitHub API has rate limits. AFSGitHub handles this automatically:
301
+
302
+ ```typescript
303
+ const github = new AFSGitHub({
304
+ auth: { token: process.env.GITHUB_TOKEN },
305
+ owner: "aigne",
306
+ repo: "afs",
307
+ rateLimit: {
308
+ autoRetry: true, // Automatically retry on 429
309
+ maxRetries: 3, // Maximum retry attempts
310
+ },
311
+ });
312
+ ```
313
+
314
+ ## Caching
315
+
316
+ Reduce API calls with built-in caching:
317
+
318
+ ```typescript
319
+ const github = new AFSGitHub({
320
+ auth: { token: process.env.GITHUB_TOKEN },
321
+ owner: "aigne",
322
+ repo: "afs",
323
+ cache: {
324
+ enabled: true, // Enable caching
325
+ ttl: 60000, // 60 second TTL
326
+ },
327
+ });
328
+ ```
329
+
330
+ ## Related Packages
331
+
332
+ - [@aigne/afs](../../packages/core/README.md) - AFS core package
333
+ - [@aigne/afs-mapping](../../packages/mapping/README.md) - Mapping DSL compiler
334
+ - [@aigne/afs-git](../git/README.md) - Git repository provider (file access)
335
+
336
+ ## TypeScript Support
337
+
338
+ This package includes full TypeScript type definitions:
339
+
340
+ ```typescript
341
+ import type { AFSGitHub, AFSGitHubOptions, AuthOptions } from "@aigne/afs-github";
342
+ ```