@elizaos/plugin-github 2.0.0-alpha.6 → 2.0.0-beta.1

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.
@@ -0,0 +1,6 @@
1
+ // src/register-routes.ts
2
+ import { registerAppRoutePluginLoader } from "@elizaos/core";
3
+ registerAppRoutePluginLoader("@elizaos/plugin-github", async () => {
4
+ const { githubPlugin } = await import("./index.js");
5
+ return githubPlugin;
6
+ });
@@ -0,0 +1,294 @@
1
+ import { Action, IAgentRuntime, ConnectorAccountProvider, Service, Plugin } from '@elizaos/core';
2
+ import { Octokit } from '@octokit/rest';
3
+
4
+ /**
5
+ * @module issue-op
6
+ * @description Single router action covering GitHub issue lifecycle ops:
7
+ * create, assign, close, reopen, comment, label. Replaces the old
8
+ * CREATE_ISSUE / ASSIGN_ISSUE actions and absorbs the issue-management ops
9
+ * previously implemented in plugin-agent-orchestrator's MANAGE_ISSUES.
10
+ *
11
+ * All ops are write ops gated on `confirmed: true`.
12
+ */
13
+
14
+ declare const issueOpAction: Action;
15
+
16
+ declare const githubAction: Action;
17
+
18
+ /**
19
+ * @module notification-triage
20
+ * @description Fetches unread GitHub notifications and returns them sorted
21
+ * by a composite priority score derived from `reason`, subject type, and
22
+ * the notifying repo's `pushed_at` freshness.
23
+ *
24
+ * Read-only — no confirmation gate.
25
+ */
26
+
27
+ interface TriagedNotification {
28
+ id: string;
29
+ reason: string;
30
+ repo: string;
31
+ title: string;
32
+ subjectType: string;
33
+ url: string | null;
34
+ updatedAt: string;
35
+ score: number;
36
+ }
37
+ declare function scoreNotification(params: {
38
+ reason: string;
39
+ subjectType: string;
40
+ repoPushedAtMs: number | null;
41
+ nowMs: number;
42
+ }): number;
43
+
44
+ declare const notificationTriageAction: Action;
45
+
46
+ /**
47
+ * @module pr-op
48
+ * @description Single router action covering GitHub pull request ops:
49
+ * list and review.
50
+ */
51
+
52
+ declare const prOpAction: Action;
53
+
54
+ /**
55
+ * @module types
56
+ * @description Shared types for the GitHub plugin
57
+ */
58
+
59
+ type OctokitEndpoint<T, Data> = T extends (...args: infer Args) => unknown ? (...args: Args) => Promise<{
60
+ data: Data;
61
+ }> : never;
62
+ /**
63
+ * Identifies which configured token (user-acting or agent-acting) an action
64
+ * should execute under. The plugin loads two independent PATs so the user
65
+ * and agent personas can act separately on the same repo.
66
+ */
67
+ type GitHubIdentity = "user" | "agent";
68
+ type GitHubUserSummary = {
69
+ login?: string | null;
70
+ };
71
+ type GitHubPullRequestSummary = {
72
+ number: number;
73
+ title: string;
74
+ state: string;
75
+ html_url: string;
76
+ user?: GitHubUserSummary | null;
77
+ };
78
+ type GitHubSearchIssueSummary = {
79
+ repository_url: string;
80
+ number: number;
81
+ title: string;
82
+ state: string;
83
+ html_url: string;
84
+ user?: GitHubUserSummary | null;
85
+ };
86
+ type GitHubReviewResult = {
87
+ id: number;
88
+ };
89
+ type GitHubIssueResult = {
90
+ number: number;
91
+ html_url: string;
92
+ };
93
+ type GitHubAssigneesResult = {
94
+ assignees?: Array<GitHubUserSummary | null> | null;
95
+ };
96
+ type GitHubLabelSummary = string | {
97
+ name?: string | null;
98
+ };
99
+ type GitHubIssueDetail = {
100
+ number: number;
101
+ title: string;
102
+ state: string;
103
+ html_url: string;
104
+ body?: string | null;
105
+ labels?: Array<GitHubLabelSummary | null> | null;
106
+ user?: GitHubUserSummary | null;
107
+ };
108
+ type GitHubIssueCommentResult = {
109
+ id: number;
110
+ html_url: string;
111
+ };
112
+ type GitHubAddLabelsResult = Array<GitHubLabelSummary | null>;
113
+ type GitHubNotificationSummary = {
114
+ id: string;
115
+ reason?: string | null;
116
+ repository?: {
117
+ full_name?: string | null;
118
+ pushed_at?: string | null;
119
+ };
120
+ subject?: {
121
+ title?: string | null;
122
+ type?: string | null;
123
+ url?: string | null;
124
+ };
125
+ updated_at: string;
126
+ };
127
+ /**
128
+ * Narrow Octokit surface used by this plugin's actions. Keeping the service
129
+ * contract structural makes tests and local API mocks straightforward without
130
+ * depending on the full Octokit class shape.
131
+ */
132
+ interface GitHubOctokitClient {
133
+ activity: {
134
+ listNotificationsForAuthenticatedUser: OctokitEndpoint<Octokit["activity"]["listNotificationsForAuthenticatedUser"], GitHubNotificationSummary[]>;
135
+ };
136
+ issues: {
137
+ addAssignees: OctokitEndpoint<Octokit["issues"]["addAssignees"], GitHubAssigneesResult>;
138
+ addLabels: OctokitEndpoint<Octokit["issues"]["addLabels"], GitHubAddLabelsResult>;
139
+ create: OctokitEndpoint<Octokit["issues"]["create"], GitHubIssueResult>;
140
+ createComment: OctokitEndpoint<Octokit["issues"]["createComment"], GitHubIssueCommentResult>;
141
+ get: OctokitEndpoint<Octokit["issues"]["get"], GitHubIssueDetail>;
142
+ listForRepo: OctokitEndpoint<Octokit["issues"]["listForRepo"], GitHubIssueDetail[]>;
143
+ update: OctokitEndpoint<Octokit["issues"]["update"], GitHubIssueDetail>;
144
+ };
145
+ pulls: {
146
+ createReview: OctokitEndpoint<Octokit["pulls"]["createReview"], GitHubReviewResult>;
147
+ list: OctokitEndpoint<Octokit["pulls"]["list"], GitHubPullRequestSummary[]>;
148
+ };
149
+ search: {
150
+ issuesAndPullRequests: OctokitEndpoint<Octokit["search"]["issuesAndPullRequests"], {
151
+ items: GitHubSearchIssueSummary[];
152
+ }>;
153
+ };
154
+ }
155
+ /**
156
+ * Service contract exposed to actions. Actions resolve their Octokit client
157
+ * via this interface and never read environment variables directly.
158
+ */
159
+ interface IGitHubService {
160
+ getOctokit(selector: GitHubIdentity | {
161
+ as?: GitHubIdentity;
162
+ role?: GitHubIdentity;
163
+ accountId?: string;
164
+ }): GitHubOctokitClient | null;
165
+ }
166
+ declare const GITHUB_SERVICE_TYPE = "github";
167
+ declare const GitHubActions: {
168
+ readonly GITHUB_ISSUE_OP: "GITHUB_ISSUE";
169
+ readonly GITHUB_PR_OP: "GITHUB_PR";
170
+ readonly GITHUB_NOTIFICATION_TRIAGE: "GITHUB_NOTIFICATION_TRIAGE";
171
+ };
172
+ /** Issue ops accepted by GITHUB_ISSUE_OP. */
173
+ type GitHubIssueOp = "create" | "assign" | "close" | "reopen" | "comment" | "label";
174
+ /** PR ops accepted by GITHUB_PR_OP. */
175
+ type GitHubPrOp = "list" | "review";
176
+ /**
177
+ * Structured result returned by action handlers. Actions never throw —
178
+ * recoverable problems are surfaced as `{ success: false }` with a reason,
179
+ * and destructive actions surface a confirmation request distinctly.
180
+ */
181
+ type GitHubActionResult<T = unknown> = {
182
+ success: true;
183
+ data: T;
184
+ } | {
185
+ success: false;
186
+ error: string;
187
+ } | {
188
+ success: false;
189
+ requiresConfirmation: true;
190
+ preview: string;
191
+ };
192
+ interface RateLimitError {
193
+ kind: "rate-limit";
194
+ resetAtMs: number | null;
195
+ message: string;
196
+ }
197
+ /** Parameters shared by every action invocation. */
198
+ interface BaseActionOptions {
199
+ as?: GitHubIdentity;
200
+ accountId?: string;
201
+ confirmed?: boolean;
202
+ }
203
+
204
+ declare const DEFAULT_GITHUB_USER_ACCOUNT_ID = "user";
205
+ declare const DEFAULT_GITHUB_AGENT_ACCOUNT_ID = "agent";
206
+ interface GitHubAccountConfig {
207
+ accountId: string;
208
+ role: GitHubIdentity;
209
+ token: string;
210
+ label?: string;
211
+ }
212
+ interface GitHubAccountSelection {
213
+ accountId?: string;
214
+ role: GitHubIdentity;
215
+ }
216
+ declare function defaultGitHubAccountIdForRole(role: GitHubIdentity): string;
217
+ declare function normalizeGitHubAccountId(value: unknown): string | undefined;
218
+ declare function resolveGitHubAccountSelection(options: Record<string, unknown> | undefined, defaultRole: GitHubIdentity): GitHubAccountSelection;
219
+ declare function readGitHubAccounts(runtime: IAgentRuntime): GitHubAccountConfig[];
220
+ declare function readGitHubAccountsWithConnectorCredentials(runtime: IAgentRuntime): Promise<GitHubAccountConfig[]>;
221
+ declare function resolveGitHubAccount(accounts: readonly GitHubAccountConfig[], selection: GitHubAccountSelection): GitHubAccountConfig | null;
222
+
223
+ /**
224
+ * GitHub ConnectorAccountManager provider.
225
+ *
226
+ * Bridges plugin-github to the @elizaos/core ConnectorAccountManager so the
227
+ * generic HTTP CRUD + OAuth surface can list, create, patch, delete, and run
228
+ * the OAuth flow for GitHub accounts. PATs remain supported as a legacy code
229
+ * path; OAuth-app installations are exposed via startOAuth/completeOAuth.
230
+ *
231
+ * Account model:
232
+ * - role "OWNER" — the user persona acting on their own behalf (legacy GITHUB_USER_PAT)
233
+ * - role "AGENT" — the agent persona acting on its own behalf (legacy GITHUB_AGENT_PAT)
234
+ * accountKey = GitHub username (login).
235
+ */
236
+
237
+ /**
238
+ * Build the GitHub ConnectorAccountManager provider.
239
+ */
240
+ declare function createGitHubConnectorAccountProvider(runtime: IAgentRuntime): ConnectorAccountProvider;
241
+
242
+ /**
243
+ * @module github-service
244
+ * @description Service that owns GitHub REST clients for the plugin.
245
+ *
246
+ * Role-tagged account records are supported, with the legacy user/agent PAT
247
+ * split preserved as the default account set. Actions request an Octokit
248
+ * client by role and optionally by accountId; the service returns `null` when
249
+ * the requested account has no token configured.
250
+ */
251
+
252
+ declare class GitHubService extends Service implements IGitHubService {
253
+ private readonly createClient;
254
+ static serviceType: string;
255
+ capabilityDescription: string;
256
+ private clients;
257
+ constructor(runtime?: IAgentRuntime, createClient?: (auth: string) => GitHubOctokitClient);
258
+ static start(runtime: IAgentRuntime, createClient?: (auth: string) => GitHubOctokitClient): Promise<Service>;
259
+ private initialize;
260
+ getOctokit(selector: GitHubIdentity | {
261
+ as?: GitHubIdentity;
262
+ role?: GitHubIdentity;
263
+ accountId?: string;
264
+ }): GitHubOctokitClient | null;
265
+ /**
266
+ * Allows tests to inject an Octokit-shaped mock without going through
267
+ * environment variables. Not part of the public runtime contract.
268
+ */
269
+ setClientForTesting(as: GitHubIdentity, client: GitHubOctokitClient | null, accountId?: string): void;
270
+ stop(): Promise<void>;
271
+ }
272
+
273
+ /**
274
+ * @module plugin-github
275
+ * @description elizaOS plugin for GitHub integration.
276
+ *
277
+ * Actions:
278
+ * - GITHUB (PR, issue, and notification operations)
279
+ *
280
+ * Auth: role-tagged account records with legacy PAT fallback.
281
+ * - GITHUB_ACCOUNTS — JSON account records ({accountId, role, token})
282
+ * - GITHUB_USER_PAT — legacy user acting on their own behalf
283
+ * - GITHUB_AGENT_PAT — legacy agent acting on its own behalf
284
+ * E2E fallbacks: ELIZA_E2E_GITHUB_USER_PAT / ELIZA_E2E_GITHUB_AGENT_PAT.
285
+ *
286
+ * Each action takes an `as: "user" | "agent"` option and may take accountId
287
+ * to select a specific account. GITHUB_PR_OP review and
288
+ * GITHUB_NOTIFICATION_TRIAGE default to `"user"`; the other ops default to
289
+ * `"agent"`.
290
+ */
291
+
292
+ declare const githubPlugin: Plugin;
293
+
294
+ export { type BaseActionOptions, DEFAULT_GITHUB_AGENT_ACCOUNT_ID, DEFAULT_GITHUB_USER_ACCOUNT_ID, GITHUB_SERVICE_TYPE, type GitHubAccountConfig, type GitHubAccountSelection, type GitHubActionResult, GitHubActions, type GitHubIdentity, type GitHubIssueOp, type GitHubOctokitClient, type GitHubPrOp, GitHubService, type IGitHubService, type RateLimitError, type TriagedNotification, createGitHubConnectorAccountProvider, githubPlugin as default, defaultGitHubAccountIdForRole, githubAction, githubPlugin, issueOpAction, normalizeGitHubAccountId, notificationTriageAction, prOpAction, readGitHubAccounts, readGitHubAccountsWithConnectorCredentials, resolveGitHubAccount, resolveGitHubAccountSelection, scoreNotification };