@github-tools/sdk 1.19.0 → 1.20.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 +60 -26
- package/dist/approval-policy--kByBqhT.mjs +17 -0
- package/dist/approval-policy--kByBqhT.mjs.map +1 -0
- package/dist/connect/eve.d.mts +2 -2
- package/dist/connect/eve.d.mts.map +1 -1
- package/dist/connect/eve.mjs +1 -1
- package/dist/connect.d.mts +15 -24
- package/dist/connect.d.mts.map +1 -1
- package/dist/connect.mjs +2 -2
- package/dist/{cores-BeLZwcde.mjs → cores-FLzAv2tu.mjs} +23 -2
- package/dist/cores-FLzAv2tu.mjs.map +1 -0
- package/dist/evaluation-BtoHbxuQ.mjs +311 -0
- package/dist/evaluation-BtoHbxuQ.mjs.map +1 -0
- package/dist/{eve-runtime-YTxfrWP-.mjs → eve-runtime-C-0doyHq.mjs} +13 -7
- package/dist/eve-runtime-C-0doyHq.mjs.map +1 -0
- package/dist/{eve-runtime-DRh2QJI7.d.mts → eve-runtime-CflZNuXD.d.mts} +6 -6
- package/dist/{eve-runtime-DRh2QJI7.d.mts.map → eve-runtime-CflZNuXD.d.mts.map} +1 -1
- package/dist/eve-runtime.d.mts +5 -5
- package/dist/eve-runtime.mjs +4 -4
- package/dist/eve.d.mts +53 -4
- package/dist/eve.d.mts.map +1 -1
- package/dist/eve.mjs +52 -3
- package/dist/eve.mjs.map +1 -1
- package/dist/{index-DkZvveZP.d.mts → index-C3wlz660.d.mts} +91 -347
- package/dist/index-C3wlz660.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -3
- package/dist/{interrupts-C_lUXMdd.d.mts → interrupts-BSDPwdJ2.d.mts} +2 -2
- package/dist/interrupts-BSDPwdJ2.d.mts.map +1 -0
- package/dist/{src-Bx5p1Unc.mjs → src-DyiAVHKl.mjs} +338 -15
- package/dist/src-DyiAVHKl.mjs.map +1 -0
- package/dist/tanstack/interrupts.d.mts +1 -1
- package/dist/tanstack.d.mts +1214 -56
- package/dist/tanstack.d.mts.map +1 -1
- package/dist/tanstack.mjs +26 -13
- package/dist/tanstack.mjs.map +1 -1
- package/dist/{token-Bh8nPj66.mjs → token-DIwB-wtp.mjs} +35 -116
- package/dist/token-DIwB-wtp.mjs.map +1 -0
- package/dist/{tool-types-CrC80SIL.d.mts → tool-types-OFyE3z0C.d.mts} +283 -54
- package/dist/tool-types-OFyE3z0C.d.mts.map +1 -0
- package/dist/{types-BmwOpI5-.d.mts → types-CJqhvQwi.d.mts} +3 -3
- package/dist/{types-BmwOpI5-.d.mts.map → types-CJqhvQwi.d.mts.map} +1 -1
- package/dist/{types-CPAsEMzx.d.mts → types-ITYfXMtY.d.mts} +2 -2
- package/dist/{types-CPAsEMzx.d.mts.map → types-ITYfXMtY.d.mts.map} +1 -1
- package/dist/workflow.d.mts +34 -40
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +17 -46
- package/dist/workflow.mjs.map +1 -1
- package/dist/{write-tools-BaoTUCg7.mjs → write-tools-DnGZw-RD.mjs} +941 -112
- package/dist/write-tools-DnGZw-RD.mjs.map +1 -0
- package/package.json +4 -6
- package/dist/cores-BeLZwcde.mjs.map +0 -1
- package/dist/evaluation-f-2QwBid.mjs +0 -210
- package/dist/evaluation-f-2QwBid.mjs.map +0 -1
- package/dist/eve-runtime-YTxfrWP-.mjs.map +0 -1
- package/dist/index-DkZvveZP.d.mts.map +0 -1
- package/dist/instructions-BuypoY0x.mjs +0 -148
- package/dist/instructions-BuypoY0x.mjs.map +0 -1
- package/dist/interrupts-C_lUXMdd.d.mts.map +0 -1
- package/dist/src-Bx5p1Unc.mjs.map +0 -1
- package/dist/token-Bh8nPj66.mjs.map +0 -1
- package/dist/tool-types-CrC80SIL.d.mts.map +0 -1
- package/dist/write-tools-BaoTUCg7.mjs.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
4
|
-
import { ToolLoopAgent, tool } from "ai";
|
|
1
|
+
import { $ as listIssueReactionsDescription, $i as createOrUpdateFileDescription, $n as enablePullRequestAutoMergeDescription, $r as deleteIssueCommentDescription, $t as getWorkflowJobLogsDescription, A as listDependabotAlertsInputSchema, Aa as githubToolsErrors, Ai as updateLabelInputSchema, An as getReleaseInputSchema, Ar as updatePullRequestCommentInputSchema, At as addDiscussionCommentInputSchema, B as searchRepositoriesCore, Bi as listCommitsCore, Bn as createPullRequestCore, Br as addLabelsCore, Bt as getIssueContextCore, C as GITHUB_TOOL_CATALOG, Ca as getRepositoryTreeDescription, Ci as updateIssueCommentDescription, Cn as deleteReleaseDescription, Cr as requestReviewersDescription, Ct as listGistsDescription, D as listCodeScanningAlertsInputSchema, Da as listBranchesInputSchema, Di as updateIssueInputSchema, Dn as getLatestReleaseInputSchema, Dr as resolveReviewThreadInputSchema, Dt as updateGistInputSchema, E as listCodeScanningAlertsDescription, Ea as listBranchesDescription, Ei as updateIssueDescription, En as getLatestReleaseDescription, Er as resolveReviewThreadDescription, Et as updateGistDescription, F as searchCodeDescription, Fi as getBlameDescription, Fn as updateReleaseDescription, Fr as addAssigneesDescription, Ft as listDiscussionsDescription, G as addCommentReactionInputSchema, Gi as getCombinedStatusInputSchema, Gn as createPullRequestReviewInputSchema, Gr as closeIssueInputSchema, Gt as getPullRequestContextInputSchema, H as searchRepositoriesInputSchema, Hi as listCommitsInputSchema, Hn as createPullRequestInputSchema, Hr as addLabelsInputSchema, Ht as getIssueContextInputSchema, I as searchCodeInputSchema, Ii as getBlameInputSchema, In as updateReleaseInputSchema, Ir as addAssigneesInputSchema, It as listDiscussionsInputSchema, J as addIssueReactionInputSchema, Ji as listCheckRunsInputSchema, Jn as deletePullRequestCommentInputSchema, Jr as createIssueInputSchema, Jt as getReleaseContextInputSchema, K as addIssueReactionCore, Ki as listCheckRunsCore, Kn as deletePullRequestCommentCore, Kr as createIssueCore, Kt as getReleaseContextCore, L as searchIssuesCore, Li as getCommitCore, Ln as addPullRequestCommentCore, Lr as addIssueCommentCore, Lt as getCiFailureContextCore, M as listSecretScanningAlertsDescription, Ma as stripRateLimit, Mi as compareCommitsDescription, Mn as listReleasesDescription, Mr as updatePullRequestDescription, Mt as getDiscussionDescription, N as listSecretScanningAlertsInputSchema, Ni as compareCommitsInputSchema, Nn as listReleasesInputSchema, Nr as updatePullRequestInputSchema, Nt as getDiscussionInputSchema, O as listDependabotAlertsCore, Oi as updateLabelCore, On as getReleaseCore, Or as updatePullRequestCommentCore, Ot as addDiscussionCommentCore, P as searchCodeCore, Pi as getBlameCore, Pn as updateReleaseCore, Pr as addAssigneesCore, Pt as listDiscussionsCore, Q as listIssueReactionsCore, Qi as createOrUpdateFileCore, Qn as enablePullRequestAutoMergeCore, Qr as deleteIssueCommentCore, Qt as getWorkflowJobLogsCore, R as searchIssuesDescription, Ri as getCommitDescription, Rn as addPullRequestCommentDescription, Rr as addIssueCommentDescription, Rt as getCiFailureContextDescription, S as ALL_GITHUB_TOOL_NAMES, Sa as getRepositoryTreeCore, Si as updateIssueCommentCore, Sn as deleteReleaseCore, Sr as requestReviewersCore, St as listGistsCore, T as listCodeScanningAlertsCore, Ta as listBranchesCore, Ti as updateIssueCore, Tn as getLatestReleaseCore, Tr as resolveReviewThreadCore, Tt as updateGistCore, U as addCommentReactionCore, Ui as getCombinedStatusCore, Un as createPullRequestReviewCore, Ur as closeIssueCore, Ut as getPullRequestContextCore, V as searchRepositoriesDescription, Vi as listCommitsDescription, Vn as createPullRequestDescription, Vr as addLabelsDescription, Vt as getIssueContextDescription, W as addCommentReactionDescription, Wi as getCombinedStatusDescription, Wn as createPullRequestReviewDescription, Wr as closeIssueDescription, Wt as getPullRequestContextDescription, X as listCommentReactionsDescription, Xi as createBranchDescription, Xn as disablePullRequestAutoMergeDescription, Xr as createLabelDescription, Xt as cancelWorkflowRunDescription, Y as listCommentReactionsCore, Yi as createBranchCore, Yn as disablePullRequestAutoMergeCore, Yr as createLabelCore, Yt as cancelWorkflowRunCore, Z as listCommentReactionsInputSchema, Zi as createBranchInputSchema, Zn as disablePullRequestAutoMergeInputSchema, Zr as createLabelInputSchema, Zt as cancelWorkflowRunInputSchema, _a as getFileContentDescription, _i as removeAssigneesDescription, _n as triggerWorkflowDescription, _r as mergePullRequestDescription, _t as getGistDescription, aa as deleteBranchDescription, ai as getIssueDescription, an as listWorkflowJobsDescription, ar as listPullRequestFilesDescription, at as markNotificationReadDescription, b as githubTokenCall, ba as getRepositoryDescription, bi as removeLabelDescription, bn as createReleaseDescription, br as replyToReviewCommentDescription, bt as listGistCommentsDescription, c as DEFAULT_EVALUATION_MODEL, ca as editFilesDescription, ci as listIssueCommentsDescription, cn as listWorkflowRunsDescription, cr as listPullRequestReviewThreadsDescription, ct as createGistCommentDescription, da as forkRepositoryDescription, di as listIssuesDescription, dn as listWorkflowsDescription, dr as listPullRequestReviewsDescription, dt as createGistDescription, ea as createOrUpdateFileInputSchema, ei as deleteIssueCommentInputSchema, en as getWorkflowJobLogsInputSchema, er as enablePullRequestAutoMergeInputSchema, et as listIssueReactionsInputSchema, fa as forkRepositoryInputSchema, fi as listIssuesInputSchema, fn as listWorkflowsInputSchema, fr as listPullRequestReviewsInputSchema, ft as createGistInputSchema, ga as getFileContentCore, gi as removeAssigneesCore, gn as triggerWorkflowCore, gr as mergePullRequestCore, gt as getGistCore, ha as getBranchRulesInputSchema, hi as listLabelsInputSchema, hn as rerunWorkflowRunInputSchema, hr as listPullRequestsInputSchema, ht as deleteGistInputSchema, i as bindToolsContext, ia as deleteBranchCore, ii as getIssueCore, in as listWorkflowJobsCore, ir as listPullRequestFilesCore, it as markNotificationReadCore, j as listSecretScanningAlertsCore, ji as compareCommitsCore, jn as listReleasesCore, jr as updatePullRequestCore, jt as getDiscussionCore, k as listDependabotAlertsDescription, ki as updateLabelDescription, kn as getReleaseDescription, kr as updatePullRequestCommentDescription, kt as addDiscussionCommentDescription, la as editFilesInputSchema, li as listIssueCommentsInputSchema, ln as listWorkflowRunsInputSchema, lr as listPullRequestReviewThreadsInputSchema, lt as createGistCommentInputSchema, ma as getBranchRulesDescription, mi as listLabelsDescription, mn as rerunWorkflowRunDescription, mr as listPullRequestsDescription, mt as deleteGistDescription, n as resolveInstructions, na as createRepositoryDescription, ni as deleteLabelDescription, nn as getWorkflowRunDescription, nr as getPullRequestDescription, nt as listNotificationsDescription, oa as deleteBranchInputSchema, oi as getIssueInputSchema, on as listWorkflowJobsInputSchema, or as listPullRequestFilesInputSchema, ot as markNotificationReadInputSchema, pa as getBranchRulesCore, pi as listLabelsCore, pn as rerunWorkflowRunCore, pr as listPullRequestsCore, pt as deleteGistCore, q as addIssueReactionDescription, qi as listCheckRunsDescription, qn as deletePullRequestCommentDescription, qr as createIssueDescription, qt as getReleaseContextDescription, ra as createRepositoryInputSchema, ri as deleteLabelInputSchema, rn as getWorkflowRunInputSchema, rr as getPullRequestInputSchema, rt as listNotificationsInputSchema, sa as editFilesCore, si as listIssueCommentsCore, sn as listWorkflowRunsCore, sr as listPullRequestReviewThreadsCore, st as createGistCommentCore, ta as createRepositoryCore, ti as deleteLabelCore, tn as getWorkflowRunCore, tr as getPullRequestCore, tt as listNotificationsCore, ua as forkRepositoryCore, ui as listIssuesCore, un as listWorkflowsCore, ur as listPullRequestReviewsCore, ut as createGistCore, v as resolvePresetTools, va as getFileContentInputSchema, vi as removeAssigneesInputSchema, vn as triggerWorkflowInputSchema, vr as mergePullRequestInputSchema, vt as getGistInputSchema, w as isGithubWriteToolName, wa as getRepositoryTreeInputSchema, wi as updateIssueCommentInputSchema, wn as deleteReleaseInputSchema, wr as requestReviewersInputSchema, wt as listGistsInputSchema, x as resolveGithubToken, xa as getRepositoryInputSchema, xi as removeLabelInputSchema, xn as createReleaseInputSchema, xr as replyToReviewCommentInputSchema, xt as listGistCommentsInputSchema, y as createGithubTokenResolver, ya as getRepositoryCore, yi as removeLabelCore, yn as createReleaseCore, yr as replyToReviewCommentCore, yt as listGistCommentsCore, z as searchIssuesInputSchema, zi as getCommitInputSchema, zn as addPullRequestCommentInputSchema, zr as addIssueCommentInputSchema, zt as getCiFailureContextInputSchema } from "./write-tools-DnGZw-RD.mjs";
|
|
2
|
+
import { _ as listPullRequestFilesToModelOutput, a as evaluationRequest, f as compareCommitsToModelOutput, g as getRepositoryTreeToModelOutput, h as getPullRequestContextToModelOutput, i as evaluateTools, m as getFileContentToModelOutput, n as autoApprovalDecision, o as fallbackPresets, p as getCommitToModelOutput, r as evaluatePresets, s as fallbackTools, t as assertEvaluationAvailable } from "./evaluation-BtoHbxuQ.mjs";
|
|
3
|
+
import { t as resolveApprovalMode } from "./approval-policy--kByBqhT.mjs";
|
|
4
|
+
import { ToolLoopAgent, asSchema, tool } from "ai";
|
|
5
|
+
import { z } from "zod";
|
|
5
6
|
//#region src/tools/repository.ts
|
|
6
7
|
async function getRepositoryStep(args) {
|
|
7
8
|
"use step";
|
|
@@ -130,6 +131,36 @@ const createOrUpdateFile = (token, { needsApproval = true, author, committer, co
|
|
|
130
131
|
...args
|
|
131
132
|
})
|
|
132
133
|
});
|
|
134
|
+
async function editFilesStep(args) {
|
|
135
|
+
"use step";
|
|
136
|
+
return editFilesCore(args);
|
|
137
|
+
}
|
|
138
|
+
/** Edit files in one commit, by exact text replacement or whole contents, on a new or existing branch, and optionally open a pull request. Requires approval by default. */
|
|
139
|
+
const editFiles = (token, { needsApproval = true, author, committer, coAuthors } = {}) => tool({
|
|
140
|
+
description: editFilesDescription,
|
|
141
|
+
needsApproval,
|
|
142
|
+
inputSchema: editFilesInputSchema,
|
|
143
|
+
execute: async (args) => editFilesStep({
|
|
144
|
+
token: await resolveGithubToken(token, githubTokenCall("editFiles", args)),
|
|
145
|
+
author,
|
|
146
|
+
committer,
|
|
147
|
+
coAuthors,
|
|
148
|
+
...args
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
async function getBranchRulesStep(args) {
|
|
152
|
+
"use step";
|
|
153
|
+
return getBranchRulesCore(args);
|
|
154
|
+
}
|
|
155
|
+
/** List the required checks, required reviews and other rules that protect a branch. */
|
|
156
|
+
const getBranchRules = (token) => tool({
|
|
157
|
+
description: getBranchRulesDescription,
|
|
158
|
+
inputSchema: getBranchRulesInputSchema,
|
|
159
|
+
execute: async (args) => getBranchRulesStep({
|
|
160
|
+
token: await resolveGithubToken(token, githubTokenCall("getBranchRules", args)),
|
|
161
|
+
...args
|
|
162
|
+
})
|
|
163
|
+
});
|
|
133
164
|
//#endregion
|
|
134
165
|
//#region src/tools/pull-requests.ts
|
|
135
166
|
async function listPullRequestsStep(args) {
|
|
@@ -339,6 +370,35 @@ const requestReviewers = (token, { needsApproval = true } = {}) => tool({
|
|
|
339
370
|
...args
|
|
340
371
|
})
|
|
341
372
|
});
|
|
373
|
+
async function enablePullRequestAutoMergeStep(args) {
|
|
374
|
+
"use step";
|
|
375
|
+
return enablePullRequestAutoMergeCore(args);
|
|
376
|
+
}
|
|
377
|
+
/** Merge a pull request automatically once its required checks and reviews pass. Requires approval by default. */
|
|
378
|
+
const enablePullRequestAutoMerge = (token, { needsApproval = true, coAuthors } = {}) => tool({
|
|
379
|
+
description: enablePullRequestAutoMergeDescription,
|
|
380
|
+
needsApproval,
|
|
381
|
+
inputSchema: enablePullRequestAutoMergeInputSchema,
|
|
382
|
+
execute: async (args) => enablePullRequestAutoMergeStep({
|
|
383
|
+
token: await resolveGithubToken(token, githubTokenCall("enablePullRequestAutoMerge", args)),
|
|
384
|
+
coAuthors,
|
|
385
|
+
...args
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
async function disablePullRequestAutoMergeStep(args) {
|
|
389
|
+
"use step";
|
|
390
|
+
return disablePullRequestAutoMergeCore(args);
|
|
391
|
+
}
|
|
392
|
+
/** Cancel a pending auto-merge. Requires approval by default. */
|
|
393
|
+
const disablePullRequestAutoMerge = (token, { needsApproval = true } = {}) => tool({
|
|
394
|
+
description: disablePullRequestAutoMergeDescription,
|
|
395
|
+
needsApproval,
|
|
396
|
+
inputSchema: disablePullRequestAutoMergeInputSchema,
|
|
397
|
+
execute: async (args) => disablePullRequestAutoMergeStep({
|
|
398
|
+
token: await resolveGithubToken(token, githubTokenCall("disablePullRequestAutoMerge", args)),
|
|
399
|
+
...args
|
|
400
|
+
})
|
|
401
|
+
});
|
|
342
402
|
//#endregion
|
|
343
403
|
//#region src/tools/issues.ts
|
|
344
404
|
async function listIssuesStep(args) {
|
|
@@ -1034,6 +1094,47 @@ const getCombinedStatus = (token) => tool({
|
|
|
1034
1094
|
})
|
|
1035
1095
|
});
|
|
1036
1096
|
//#endregion
|
|
1097
|
+
//#region src/tools/security.ts
|
|
1098
|
+
async function listCodeScanningAlertsStep(args) {
|
|
1099
|
+
"use step";
|
|
1100
|
+
return listCodeScanningAlertsCore(args);
|
|
1101
|
+
}
|
|
1102
|
+
/** List code scanning alerts for a repository, with the rule, severity and location. */
|
|
1103
|
+
const listCodeScanningAlerts = (token) => tool({
|
|
1104
|
+
description: listCodeScanningAlertsDescription,
|
|
1105
|
+
inputSchema: listCodeScanningAlertsInputSchema,
|
|
1106
|
+
execute: async (args) => listCodeScanningAlertsStep({
|
|
1107
|
+
token: await resolveGithubToken(token, githubTokenCall("listCodeScanningAlerts", args)),
|
|
1108
|
+
...args
|
|
1109
|
+
})
|
|
1110
|
+
});
|
|
1111
|
+
async function listDependabotAlertsStep(args) {
|
|
1112
|
+
"use step";
|
|
1113
|
+
return listDependabotAlertsCore(args);
|
|
1114
|
+
}
|
|
1115
|
+
/** List Dependabot alerts for vulnerable dependencies, with the advisory and the first patched version. */
|
|
1116
|
+
const listDependabotAlerts = (token) => tool({
|
|
1117
|
+
description: listDependabotAlertsDescription,
|
|
1118
|
+
inputSchema: listDependabotAlertsInputSchema,
|
|
1119
|
+
execute: async (args) => listDependabotAlertsStep({
|
|
1120
|
+
token: await resolveGithubToken(token, githubTokenCall("listDependabotAlerts", args)),
|
|
1121
|
+
...args
|
|
1122
|
+
})
|
|
1123
|
+
});
|
|
1124
|
+
async function listSecretScanningAlertsStep(args) {
|
|
1125
|
+
"use step";
|
|
1126
|
+
return listSecretScanningAlertsCore(args);
|
|
1127
|
+
}
|
|
1128
|
+
/** List secret scanning alerts for a repository. The secret itself is never returned. */
|
|
1129
|
+
const listSecretScanningAlerts = (token) => tool({
|
|
1130
|
+
description: listSecretScanningAlertsDescription,
|
|
1131
|
+
inputSchema: listSecretScanningAlertsInputSchema,
|
|
1132
|
+
execute: async (args) => listSecretScanningAlertsStep({
|
|
1133
|
+
token: await resolveGithubToken(token, githubTokenCall("listSecretScanningAlerts", args)),
|
|
1134
|
+
...args
|
|
1135
|
+
})
|
|
1136
|
+
});
|
|
1137
|
+
//#endregion
|
|
1037
1138
|
//#region src/tools/releases.ts
|
|
1038
1139
|
async function listReleasesStep(args) {
|
|
1039
1140
|
"use step";
|
|
@@ -1173,17 +1274,192 @@ const getCiFailureContext = (token) => tool({
|
|
|
1173
1274
|
});
|
|
1174
1275
|
//#endregion
|
|
1175
1276
|
//#region src/core/approval.ts
|
|
1277
|
+
const MAX_CACHED_DECISIONS = 100;
|
|
1176
1278
|
/**
|
|
1177
1279
|
* Resolve the AI SDK `needsApproval` value for a write tool.
|
|
1178
1280
|
* `'auto'` becomes a function that evaluates each call with {@link needsAutoApproval}.
|
|
1281
|
+
* The AI SDK asks again once a person approves, so each decision is reused for the same
|
|
1282
|
+
* call, input and request (with the message it replies to) instead of calling the evaluation model twice.
|
|
1179
1283
|
*/
|
|
1180
1284
|
function resolveAiSdkApproval(toolName, config, evaluation) {
|
|
1181
1285
|
const mode = resolveApprovalMode(toolName, config);
|
|
1182
1286
|
if (mode !== "auto") return mode;
|
|
1183
|
-
|
|
1287
|
+
assertEvaluationAvailable();
|
|
1288
|
+
const decisions = /* @__PURE__ */ new Map();
|
|
1289
|
+
return (input, { toolCallId, messages }) => {
|
|
1290
|
+
const key = JSON.stringify([
|
|
1291
|
+
toolCallId,
|
|
1292
|
+
input,
|
|
1293
|
+
evaluationRequest(messages)
|
|
1294
|
+
]);
|
|
1295
|
+
const cached = decisions.get(key);
|
|
1296
|
+
if (cached) return cached;
|
|
1297
|
+
const decision = autoApprovalDecision(toolName, input, messages, evaluation).then(({ ask }) => ask);
|
|
1298
|
+
decisions.set(key, decision);
|
|
1299
|
+
if (decisions.size > MAX_CACHED_DECISIONS) decisions.delete(decisions.keys().next().value);
|
|
1300
|
+
return decision;
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
function resolveAiSdkToolApproval(toolName, config, evaluation) {
|
|
1304
|
+
const mode = resolveApprovalMode(toolName, config);
|
|
1305
|
+
if (mode !== "auto") return async () => mode ? "user-approval" : void 0;
|
|
1306
|
+
assertEvaluationAvailable();
|
|
1307
|
+
const decisions = /* @__PURE__ */ new Map();
|
|
1308
|
+
return async (input, { toolCallId, messages }) => {
|
|
1309
|
+
const key = JSON.stringify([
|
|
1310
|
+
toolCallId,
|
|
1311
|
+
input,
|
|
1312
|
+
evaluationRequest(messages)
|
|
1313
|
+
]);
|
|
1314
|
+
let decision = decisions.get(key);
|
|
1315
|
+
if (!decision) {
|
|
1316
|
+
decision = autoApprovalDecision(toolName, input, messages, evaluation);
|
|
1317
|
+
decisions.set(key, decision);
|
|
1318
|
+
if (decisions.size > MAX_CACHED_DECISIONS) decisions.delete(decisions.keys().next().value);
|
|
1319
|
+
}
|
|
1320
|
+
const { ask, reason } = await decision;
|
|
1321
|
+
return {
|
|
1322
|
+
type: ask ? "user-approval" : "approved",
|
|
1323
|
+
reason
|
|
1324
|
+
};
|
|
1325
|
+
};
|
|
1184
1326
|
}
|
|
1185
1327
|
//#endregion
|
|
1186
1328
|
//#region src/agents.ts
|
|
1329
|
+
const MAX_CACHED_ROUTES = 100;
|
|
1330
|
+
/** Name of the tool `preset: 'auto'` adds so the model can call GitHub tools that were not picked. */
|
|
1331
|
+
const CALL_GITHUB_TOOL = "callGithubTool";
|
|
1332
|
+
const callGithubToolInput = z.object({
|
|
1333
|
+
name: z.enum(ALL_GITHUB_TOOL_NAMES).describe("GitHub tool to call"),
|
|
1334
|
+
input: z.record(z.string(), z.unknown()).optional().describe("The tool's arguments. Omit to get its description and input schema without calling it.")
|
|
1335
|
+
});
|
|
1336
|
+
async function validateInput(tools, name, input) {
|
|
1337
|
+
return await asSchema(tools[name].inputSchema).validate?.(input) ?? {
|
|
1338
|
+
success: true,
|
|
1339
|
+
value: input
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
function callGithubTool(tools) {
|
|
1343
|
+
const validate = (name, input) => validateInput(tools, name, input);
|
|
1344
|
+
return tool({
|
|
1345
|
+
description: "Call a GitHub tool that is not in your tool list. Every GitHub tool is in the `name` enum. Pass its arguments as `input`; if you do not know them, omit `input` to get the tool's description and input schema first.",
|
|
1346
|
+
inputSchema: callGithubToolInput,
|
|
1347
|
+
needsApproval: async ({ name, input }, options) => {
|
|
1348
|
+
if (input === void 0) return false;
|
|
1349
|
+
const parsed = await validate(name, input);
|
|
1350
|
+
const needsApproval = tools[name].needsApproval;
|
|
1351
|
+
if (!parsed.success || needsApproval === void 0) return false;
|
|
1352
|
+
return typeof needsApproval === "function" ? needsApproval(parsed.value, options) : needsApproval;
|
|
1353
|
+
},
|
|
1354
|
+
execute: async ({ name, input }, options) => {
|
|
1355
|
+
if (input === void 0) return {
|
|
1356
|
+
name,
|
|
1357
|
+
description: tools[name].description,
|
|
1358
|
+
inputSchema: await asSchema(tools[name].inputSchema).jsonSchema
|
|
1359
|
+
};
|
|
1360
|
+
const parsed = await validate(name, input);
|
|
1361
|
+
if (!parsed.success) throw new Error(`Invalid input for ${name}: ${parsed.error.message}\nInput schema: ${JSON.stringify(await asSchema(tools[name].inputSchema).jsonSchema)}`);
|
|
1362
|
+
return tools[name].execute(parsed.value, options);
|
|
1363
|
+
},
|
|
1364
|
+
toModelOutput: async ({ toolCallId, input: { name, input }, output }) => {
|
|
1365
|
+
const toModelOutput = tools[name].toModelOutput;
|
|
1366
|
+
if (input === void 0 || !toModelOutput) return {
|
|
1367
|
+
type: "json",
|
|
1368
|
+
value: output
|
|
1369
|
+
};
|
|
1370
|
+
const parsed = await validate(name, input);
|
|
1371
|
+
return toModelOutput({
|
|
1372
|
+
toolCallId,
|
|
1373
|
+
input: parsed.success ? parsed.value : input,
|
|
1374
|
+
output
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Call-level approval for every GitHub tool, the AI SDK 7 replacement for tool-level `needsApproval`.
|
|
1381
|
+
* `requireApproval: 'auto'` puts the decision model's verdict on approval requests and records the
|
|
1382
|
+
* calls it lets through as automatic approvals. Calls through `callGithubTool` follow the named tool.
|
|
1383
|
+
*/
|
|
1384
|
+
function githubToolApproval({ tools, requireApproval, evaluation, overrides }) {
|
|
1385
|
+
const policies = /* @__PURE__ */ new Map();
|
|
1386
|
+
const policyFor = (name) => {
|
|
1387
|
+
let policy = policies.get(name);
|
|
1388
|
+
if (!policy) {
|
|
1389
|
+
const override = overrides?.[name]?.needsApproval;
|
|
1390
|
+
policy = override !== void 0 ? async (input, options) => (typeof override === "function" ? await override(input, {
|
|
1391
|
+
...options,
|
|
1392
|
+
context: void 0
|
|
1393
|
+
}) : override) ? "user-approval" : void 0 : isGithubWriteToolName(name) ? resolveAiSdkToolApproval(name, requireApproval ?? true, evaluation) : async () => void 0;
|
|
1394
|
+
policies.set(name, policy);
|
|
1395
|
+
}
|
|
1396
|
+
return policy;
|
|
1397
|
+
};
|
|
1398
|
+
return async ({ toolCall, messages, tools: available, toolsContext }) => {
|
|
1399
|
+
if (toolCall.toolName !== "callGithubTool" && !Object.hasOwn(GITHUB_TOOL_CATALOG, toolCall.toolName)) {
|
|
1400
|
+
const needsApproval = available?.[toolCall.toolName]?.needsApproval;
|
|
1401
|
+
return (typeof needsApproval === "function" ? await needsApproval(toolCall.input, {
|
|
1402
|
+
toolCallId: toolCall.toolCallId,
|
|
1403
|
+
messages,
|
|
1404
|
+
context: toolsContext?.[toolCall.toolName]
|
|
1405
|
+
}) : needsApproval) ? "user-approval" : void 0;
|
|
1406
|
+
}
|
|
1407
|
+
if (toolCall.toolName !== "callGithubTool") return policyFor(toolCall.toolName)(toolCall.input, {
|
|
1408
|
+
toolCallId: toolCall.toolCallId,
|
|
1409
|
+
messages
|
|
1410
|
+
});
|
|
1411
|
+
const { name, input } = toolCall.input;
|
|
1412
|
+
if (input === void 0) return void 0;
|
|
1413
|
+
const parsed = await validateInput(tools, name, input);
|
|
1414
|
+
return parsed.success ? policyFor(name)(parsed.value, {
|
|
1415
|
+
toolCallId: toolCall.toolCallId,
|
|
1416
|
+
messages
|
|
1417
|
+
}) : void 0;
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
function firstRequest(messages) {
|
|
1421
|
+
const index = messages.findIndex((message) => message.role === "user");
|
|
1422
|
+
return index === -1 ? messages : messages.slice(0, index + 1);
|
|
1423
|
+
}
|
|
1424
|
+
function callMessages(call) {
|
|
1425
|
+
if (typeof call.prompt === "string") return [{
|
|
1426
|
+
role: "user",
|
|
1427
|
+
content: call.prompt
|
|
1428
|
+
}];
|
|
1429
|
+
return call.prompt ?? call.messages ?? [];
|
|
1430
|
+
}
|
|
1431
|
+
function decisionModelId({ model = DEFAULT_EVALUATION_MODEL } = {}) {
|
|
1432
|
+
return typeof model === "string" ? model : `${model.provider}/${model.modelId}`;
|
|
1433
|
+
}
|
|
1434
|
+
async function storeKey(kind, settings, key) {
|
|
1435
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([settings, key])));
|
|
1436
|
+
return `github-tools:${kind}:${[...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Routing for a request, cached per request so an approval continuation keeps its tools, and in
|
|
1440
|
+
* `evaluation.store` when set. Only successful decisions are kept, so a request routed while the
|
|
1441
|
+
* evaluator was down is routed again.
|
|
1442
|
+
*/
|
|
1443
|
+
function cachedRouting(kind, settings, route, fallback, store) {
|
|
1444
|
+
const routing = /* @__PURE__ */ new Map();
|
|
1445
|
+
return async (messages) => {
|
|
1446
|
+
const key = JSON.stringify(evaluationRequest(messages));
|
|
1447
|
+
let routed = routing.get(key);
|
|
1448
|
+
if (!routed) {
|
|
1449
|
+
routed = store ? storeKey(kind, settings, key).then(async (stored) => {
|
|
1450
|
+
const saved = await store.get(stored);
|
|
1451
|
+
if (saved) return saved;
|
|
1452
|
+
const decided = await route(messages);
|
|
1453
|
+
await store.set(stored, decided);
|
|
1454
|
+
return decided;
|
|
1455
|
+
}) : route(messages);
|
|
1456
|
+
routing.set(key, routed);
|
|
1457
|
+
routed.catch(() => routing.delete(key));
|
|
1458
|
+
if (routing.size > MAX_CACHED_ROUTES) routing.delete(routing.keys().next().value);
|
|
1459
|
+
}
|
|
1460
|
+
return routed.catch(fallback);
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1187
1463
|
/**
|
|
1188
1464
|
* Create a pre-configured GitHub agent powered by the AI SDK's `ToolLoopAgent`.
|
|
1189
1465
|
*
|
|
@@ -1203,21 +1479,33 @@ function resolveAiSdkApproval(toolName, config, evaluation) {
|
|
|
1203
1479
|
* const result = await agent.generate({ prompt: 'Review this PR' })
|
|
1204
1480
|
* ```
|
|
1205
1481
|
*/
|
|
1206
|
-
function createGithubAgent({ token, preset, requireApproval, evaluation, context, instructions, additionalInstructions, author, committer, coAuthors, ...agentOptions }) {
|
|
1482
|
+
function createGithubAgent({ token, preset, requireApproval, evaluation, overrides, context, instructions, additionalInstructions, author, committer, coAuthors, ...agentOptions }) {
|
|
1207
1483
|
const staticPreset = preset === "auto" ? void 0 : preset;
|
|
1208
1484
|
const tools = createGithubTools({
|
|
1209
1485
|
token,
|
|
1210
1486
|
requireApproval,
|
|
1211
1487
|
evaluation,
|
|
1212
1488
|
preset: staticPreset,
|
|
1489
|
+
overrides,
|
|
1213
1490
|
context,
|
|
1214
1491
|
author,
|
|
1215
1492
|
committer,
|
|
1216
1493
|
coAuthors
|
|
1217
1494
|
});
|
|
1495
|
+
const byTool = preset === "auto" && evaluation?.selection !== "presets";
|
|
1496
|
+
const agentTools = byTool ? {
|
|
1497
|
+
...tools,
|
|
1498
|
+
[CALL_GITHUB_TOOL]: callGithubTool(tools)
|
|
1499
|
+
} : tools;
|
|
1218
1500
|
const settings = {
|
|
1501
|
+
toolApproval: githubToolApproval({
|
|
1502
|
+
tools,
|
|
1503
|
+
requireApproval,
|
|
1504
|
+
evaluation,
|
|
1505
|
+
overrides
|
|
1506
|
+
}),
|
|
1219
1507
|
...agentOptions,
|
|
1220
|
-
tools,
|
|
1508
|
+
tools: agentTools,
|
|
1221
1509
|
instructions: resolveInstructions({
|
|
1222
1510
|
preset: staticPreset,
|
|
1223
1511
|
instructions,
|
|
@@ -1225,14 +1513,34 @@ function createGithubAgent({ token, preset, requireApproval, evaluation, context
|
|
|
1225
1513
|
context
|
|
1226
1514
|
})
|
|
1227
1515
|
};
|
|
1228
|
-
if (preset === "auto")
|
|
1516
|
+
if (preset === "auto" && evaluation?.scope === "session" && !byTool) throw githubToolsErrors.SESSION_SCOPE_NEEDS_TOOL_SELECTION();
|
|
1517
|
+
if (byTool) {
|
|
1518
|
+
assertEvaluationAvailable();
|
|
1519
|
+
const prepareCall = agentOptions.prepareCall;
|
|
1520
|
+
const picks = cachedRouting("tools", [
|
|
1521
|
+
decisionModelId(evaluation),
|
|
1522
|
+
evaluation?.minToolProbability,
|
|
1523
|
+
evaluation?.maxTools
|
|
1524
|
+
], (messages) => evaluateTools(messages, evaluation), (error) => fallbackTools(error, evaluation), evaluation?.store);
|
|
1525
|
+
settings.prepareCall = async (call) => {
|
|
1526
|
+
const messages = callMessages(call);
|
|
1527
|
+
const picked = await picks(evaluation?.scope === "turn" ? messages : firstRequest(messages));
|
|
1528
|
+
const next = {
|
|
1529
|
+
...call,
|
|
1530
|
+
activeTools: [...picked, CALL_GITHUB_TOOL]
|
|
1531
|
+
};
|
|
1532
|
+
return prepareCall ? prepareCall(next) : next;
|
|
1533
|
+
};
|
|
1534
|
+
} else if (preset === "auto") {
|
|
1535
|
+
assertEvaluationAvailable();
|
|
1229
1536
|
const prepareCall = agentOptions.prepareCall;
|
|
1537
|
+
const routes = cachedRouting("presets", [
|
|
1538
|
+
decisionModelId(evaluation),
|
|
1539
|
+
evaluation?.minPresetProbability,
|
|
1540
|
+
evaluation?.maxPresets
|
|
1541
|
+
], (messages) => evaluatePresets(messages, evaluation), (error) => fallbackPresets(error, evaluation), evaluation?.store);
|
|
1230
1542
|
settings.prepareCall = async (call) => {
|
|
1231
|
-
const
|
|
1232
|
-
role: "user",
|
|
1233
|
-
content: call.prompt
|
|
1234
|
-
}] : call.prompt ?? call.messages ?? [];
|
|
1235
|
-
const selected = await selectPresets(messages, evaluation);
|
|
1543
|
+
const selected = await routes(callMessages(call));
|
|
1236
1544
|
const next = {
|
|
1237
1545
|
...call,
|
|
1238
1546
|
activeTools: [...resolvePresetTools(selected)],
|
|
@@ -1321,11 +1629,26 @@ function createGithubTools({ token, requireApproval = true, evaluation, preset,
|
|
|
1321
1629
|
committer,
|
|
1322
1630
|
coAuthors
|
|
1323
1631
|
}),
|
|
1632
|
+
editFiles: editFiles(resolveToken, {
|
|
1633
|
+
...approval("editFiles"),
|
|
1634
|
+
author,
|
|
1635
|
+
committer,
|
|
1636
|
+
coAuthors
|
|
1637
|
+
}),
|
|
1638
|
+
getBranchRules: getBranchRules(resolveToken),
|
|
1639
|
+
listCodeScanningAlerts: listCodeScanningAlerts(resolveToken),
|
|
1640
|
+
listDependabotAlerts: listDependabotAlerts(resolveToken),
|
|
1641
|
+
listSecretScanningAlerts: listSecretScanningAlerts(resolveToken),
|
|
1324
1642
|
createPullRequest: createPullRequest(resolveToken, approval("createPullRequest")),
|
|
1325
1643
|
mergePullRequest: mergePullRequest(resolveToken, {
|
|
1326
1644
|
...approval("mergePullRequest"),
|
|
1327
1645
|
coAuthors
|
|
1328
1646
|
}),
|
|
1647
|
+
enablePullRequestAutoMerge: enablePullRequestAutoMerge(resolveToken, {
|
|
1648
|
+
...approval("enablePullRequestAutoMerge"),
|
|
1649
|
+
coAuthors
|
|
1650
|
+
}),
|
|
1651
|
+
disablePullRequestAutoMerge: disablePullRequestAutoMerge(resolveToken, approval("disablePullRequestAutoMerge")),
|
|
1329
1652
|
updatePullRequest: updatePullRequest(resolveToken, approval("updatePullRequest")),
|
|
1330
1653
|
addPullRequestComment: addPullRequestComment(resolveToken, approval("addPullRequestComment")),
|
|
1331
1654
|
updatePullRequestComment: updatePullRequestComment(resolveToken, approval("updatePullRequestComment")),
|
|
@@ -1420,6 +1743,6 @@ function withStrippedRateLimit(tool) {
|
|
|
1420
1743
|
};
|
|
1421
1744
|
}
|
|
1422
1745
|
//#endregion
|
|
1423
|
-
export {
|
|
1746
|
+
export { closeIssue as $, getGist as A, createBranch as At, searchRepositories as B, listBranches as Bt, listWorkflowRuns as C, listPullRequests as Ct, createGist as D, resolveReviewThread as Dt, triggerWorkflow as E, requestReviewers as Et, getBlame as F, forkRepository as Ft, listDiscussions as G, markNotificationRead as H, getCommit as I, getBranchRules as It, listCommentReactions as J, addCommentReaction as K, listCommits as L, getFileContent as Lt, listGists as M, createRepository as Mt, updateGist as N, deleteBranch as Nt, createGistComment as O, updatePullRequest as Ot, compareCommits as P, editFiles as Pt, addLabels as Q, searchCode as R, getRepository as Rt, listWorkflowJobs as S, listPullRequestReviews as St, rerunWorkflowRun as T, replyToReviewComment as Tt, addDiscussionComment as U, listNotifications as V, getDiscussion as W, addAssignees as X, listIssueReactions as Y, addIssueComment as Z, getCombinedStatus as _, disablePullRequestAutoMerge as _t, getIssueContext as a, listIssueComments as at, getWorkflowJobLogs as b, listPullRequestFiles as bt, createRelease as c, removeAssignees as ct, getRelease as d, updateIssueComment as dt, createIssue as et, listReleases as f, updateLabel as ft, listSecretScanningAlerts as g, deletePullRequestComment as gt, listDependabotAlerts as h, createPullRequestReview as ht, getCiFailureContext as i, getIssue as it, listGistComments as j, createOrUpdateFile as jt, deleteGist as k, updatePullRequestComment as kt, deleteRelease as l, removeLabel as lt, listCodeScanningAlerts as m, createPullRequest as mt, CALL_GITHUB_TOOL as n, deleteIssueComment as nt, getPullRequestContext as o, listIssues as ot, updateRelease as p, addPullRequestComment as pt, addIssueReaction as q, createGithubAgent as r, deleteLabel as rt, getReleaseContext as s, listLabels as st, createGithubTools as t, createLabel as tt, getLatestRelease as u, updateIssue as ut, listCheckRuns as v, enablePullRequestAutoMerge as vt, listWorkflows as w, mergePullRequest as wt, getWorkflowRun as x, listPullRequestReviewThreads as xt, cancelWorkflowRun as y, getPullRequest as yt, searchIssues as z, getRepositoryTree as zt };
|
|
1424
1747
|
|
|
1425
|
-
//# sourceMappingURL=src-
|
|
1748
|
+
//# sourceMappingURL=src-DyiAVHKl.mjs.map
|