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