@github-tools/sdk 1.20.0 → 1.22.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 +50 -17
- package/dist/{approval-policy--kByBqhT.mjs → approval-policy-C2rcAY77.mjs} +3 -4
- package/dist/{approval-policy--kByBqhT.mjs.map → approval-policy-C2rcAY77.mjs.map} +1 -1
- package/dist/connect/eve.d.mts +2 -4
- package/dist/connect/eve.d.mts.map +1 -1
- package/dist/connect/eve.mjs +3 -4
- package/dist/connect/eve.mjs.map +1 -1
- package/dist/connect.d.mts +5 -11
- package/dist/connect.d.mts.map +1 -1
- package/dist/connect.mjs +3 -4
- package/dist/{cores-FLzAv2tu.mjs → cores-CMUr_SEv.mjs} +21 -4
- package/dist/cores-CMUr_SEv.mjs.map +1 -0
- package/dist/{tool-types-OFyE3z0C.d.mts → dry-run-BAbes7Mv.d.mts} +168 -40
- package/dist/dry-run-BAbes7Mv.d.mts.map +1 -0
- package/dist/{evaluation-BtoHbxuQ.mjs → evaluation-DskA4Lzk.mjs} +4 -6
- package/dist/{evaluation-BtoHbxuQ.mjs.map → evaluation-DskA4Lzk.mjs.map} +1 -1
- package/dist/eve-runtime-Bmdw1C-K.d.mts +127 -0
- package/dist/eve-runtime-Bmdw1C-K.d.mts.map +1 -0
- package/dist/{eve-runtime-C-0doyHq.mjs → eve-runtime-DM9yjOsG.mjs} +193 -22
- package/dist/eve-runtime-DM9yjOsG.mjs.map +1 -0
- package/dist/eve-runtime.d.mts +5 -5
- package/dist/eve-runtime.mjs +4 -4
- package/dist/eve.d.mts +103 -63
- package/dist/eve.d.mts.map +1 -1
- package/dist/eve.mjs +104 -63
- package/dist/eve.mjs.map +1 -1
- package/dist/{index-C3wlz660.d.mts → index-DgCZi9Ns.d.mts} +52 -56
- package/dist/index-DgCZi9Ns.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/{interrupts-BSDPwdJ2.d.mts → interrupts-MwQ_v_PF.d.mts} +1 -3
- package/dist/interrupts-MwQ_v_PF.d.mts.map +1 -0
- package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
- package/dist/{src-DyiAVHKl.mjs → src-Djn_FFj1.mjs} +183 -55
- package/dist/src-Djn_FFj1.mjs.map +1 -0
- package/dist/tanstack/interrupts.d.mts +1 -1
- package/dist/tanstack/interrupts.mjs +1 -2
- package/dist/tanstack.d.mts +534 -208
- package/dist/tanstack.d.mts.map +1 -1
- package/dist/tanstack.mjs +37 -21
- package/dist/tanstack.mjs.map +1 -1
- package/dist/{token-DIwB-wtp.mjs → token-HpJhSRkl.mjs} +7 -10
- package/dist/token-HpJhSRkl.mjs.map +1 -0
- package/dist/{types-CJqhvQwi.d.mts → types-8KtcPTao.d.mts} +3 -7
- package/dist/types-8KtcPTao.d.mts.map +1 -0
- package/dist/{types-ITYfXMtY.d.mts → types-C-BIKmas.d.mts} +14 -4
- package/dist/types-C-BIKmas.d.mts.map +1 -0
- package/dist/workflow.d.mts +9 -4
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +7 -6
- package/dist/workflow.mjs.map +1 -1
- package/dist/{write-tools-DnGZw-RD.mjs → write-tools-BR29EOoM.mjs} +483 -113
- package/dist/write-tools-BR29EOoM.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/cores-FLzAv2tu.mjs.map +0 -1
- package/dist/eve-runtime-C-0doyHq.mjs.map +0 -1
- package/dist/eve-runtime-CflZNuXD.d.mts +0 -85
- package/dist/eve-runtime-CflZNuXD.d.mts.map +0 -1
- package/dist/index-C3wlz660.d.mts.map +0 -1
- package/dist/interrupts-BSDPwdJ2.d.mts.map +0 -1
- package/dist/src-DyiAVHKl.mjs.map +0 -1
- package/dist/token-DIwB-wtp.mjs.map +0 -1
- package/dist/tool-types-OFyE3z0C.d.mts.map +0 -1
- package/dist/types-CJqhvQwi.d.mts.map +0 -1
- package/dist/types-ITYfXMtY.d.mts.map +0 -1
- package/dist/write-tools-DnGZw-RD.mjs.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Experimental_EvaluationModel, JSONValue, ModelMessage, Tool } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { Octokit as Octokit$1 } from "octokit";
|
|
4
|
-
//#region src/core/catalog.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Single source of truth for every GitHub tool.
|
|
7
6
|
*
|
|
@@ -133,6 +132,16 @@ declare const GITHUB_TOOL_CATALOG: {
|
|
|
133
132
|
}, z.core.$strip>;
|
|
134
133
|
connectScopes: readonly ["contents:read", "metadata:read"];
|
|
135
134
|
};
|
|
135
|
+
/** Get a user's permission and role on a repository, to check whether they may trigger the bot or approve an action. */
|
|
136
|
+
getCollaboratorPermission: {
|
|
137
|
+
description: string;
|
|
138
|
+
inputSchema: z.ZodObject<{
|
|
139
|
+
owner: z.ZodString;
|
|
140
|
+
repo: z.ZodString;
|
|
141
|
+
username: z.ZodString;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
connectScopes: readonly ["metadata:read"];
|
|
144
|
+
};
|
|
136
145
|
/** Edit files in one commit on a new or existing branch, and optionally open a pull request. Requires approval by default. */
|
|
137
146
|
editFiles: {
|
|
138
147
|
description: string;
|
|
@@ -269,6 +278,18 @@ declare const GITHUB_TOOL_CATALOG: {
|
|
|
269
278
|
write: true;
|
|
270
279
|
connectScopes: readonly ["contents:read", "metadata:read", "pull_requests:read", "pull_requests:write"];
|
|
271
280
|
};
|
|
281
|
+
/** Bring a pull request branch up to date by merging its base branch into it. Requires approval by default. */
|
|
282
|
+
updatePullRequestBranch: {
|
|
283
|
+
description: string;
|
|
284
|
+
inputSchema: z.ZodObject<{
|
|
285
|
+
owner: z.ZodString;
|
|
286
|
+
repo: z.ZodString;
|
|
287
|
+
pullNumber: z.ZodNumber;
|
|
288
|
+
expectedHeadSha: z.ZodOptional<z.ZodString>;
|
|
289
|
+
}, z.core.$strip>;
|
|
290
|
+
write: true;
|
|
291
|
+
connectScopes: readonly ["contents:read", "contents:write", "metadata:read", "pull_requests:read", "pull_requests:write"];
|
|
292
|
+
};
|
|
272
293
|
/** Add a comment to a pull request. Requires approval by default. */
|
|
273
294
|
addPullRequestComment: {
|
|
274
295
|
description: string;
|
|
@@ -511,6 +532,7 @@ declare const GITHUB_TOOL_CATALOG: {
|
|
|
511
532
|
body: z.ZodOptional<z.ZodString>;
|
|
512
533
|
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
513
534
|
assignees: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
535
|
+
milestone: z.ZodOptional<z.ZodNumber>;
|
|
514
536
|
}, z.core.$strip>;
|
|
515
537
|
write: true;
|
|
516
538
|
connectScopes: readonly ["contents:read", "metadata:read", "issues:read", "issues:write"];
|
|
@@ -687,6 +709,48 @@ declare const GITHUB_TOOL_CATALOG: {
|
|
|
687
709
|
write: true;
|
|
688
710
|
connectScopes: readonly ["contents:read", "metadata:read", "issues:read", "issues:write"];
|
|
689
711
|
};
|
|
712
|
+
/** List milestones in a GitHub repository with their due dates and issue counts. */
|
|
713
|
+
listMilestones: {
|
|
714
|
+
description: string;
|
|
715
|
+
inputSchema: z.ZodObject<{
|
|
716
|
+
owner: z.ZodString;
|
|
717
|
+
repo: z.ZodString;
|
|
718
|
+
state: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
719
|
+
open: "open";
|
|
720
|
+
closed: "closed";
|
|
721
|
+
all: "all";
|
|
722
|
+
}>>>;
|
|
723
|
+
perPage: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
724
|
+
page: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
725
|
+
}, z.core.$strip>;
|
|
726
|
+
connectScopes: readonly ["contents:read", "metadata:read", "issues:read"];
|
|
727
|
+
};
|
|
728
|
+
/** List the sub-issues of an issue. */
|
|
729
|
+
listSubIssues: {
|
|
730
|
+
description: string;
|
|
731
|
+
inputSchema: z.ZodObject<{
|
|
732
|
+
owner: z.ZodString;
|
|
733
|
+
repo: z.ZodString;
|
|
734
|
+
issueNumber: z.ZodNumber;
|
|
735
|
+
perPage: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
736
|
+
page: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
737
|
+
}, z.core.$strip>;
|
|
738
|
+
connectScopes: readonly ["contents:read", "metadata:read", "issues:read"];
|
|
739
|
+
};
|
|
740
|
+
/** Add an existing issue as a sub-issue of another issue. Requires approval by default. */
|
|
741
|
+
addSubIssue: {
|
|
742
|
+
description: string;
|
|
743
|
+
inputSchema: z.ZodObject<{
|
|
744
|
+
owner: z.ZodString;
|
|
745
|
+
repo: z.ZodString;
|
|
746
|
+
issueNumber: z.ZodNumber;
|
|
747
|
+
subIssueNumber: z.ZodNumber;
|
|
748
|
+
subIssueRepo: z.ZodOptional<z.ZodString>;
|
|
749
|
+
replaceParent: z.ZodOptional<z.ZodBoolean>;
|
|
750
|
+
}, z.core.$strip>;
|
|
751
|
+
write: true;
|
|
752
|
+
connectScopes: readonly ["contents:read", "metadata:read", "issues:read", "issues:write"];
|
|
753
|
+
};
|
|
690
754
|
/** List reactions on an issue or pull request conversation, with per-emoji counts. */
|
|
691
755
|
listIssueReactions: {
|
|
692
756
|
description: string;
|
|
@@ -1145,6 +1209,26 @@ declare const GITHUB_TOOL_CATALOG: {
|
|
|
1145
1209
|
}, z.core.$strip>;
|
|
1146
1210
|
connectScopes: readonly ["contents:read", "metadata:read", "checks:read", "statuses:read"];
|
|
1147
1211
|
};
|
|
1212
|
+
/** Report a result on a commit as a commit status. Works with personal access tokens and GitHub Apps. Requires approval by default. */
|
|
1213
|
+
createCommitStatus: {
|
|
1214
|
+
description: string;
|
|
1215
|
+
inputSchema: z.ZodObject<{
|
|
1216
|
+
owner: z.ZodString;
|
|
1217
|
+
repo: z.ZodString;
|
|
1218
|
+
sha: z.ZodString;
|
|
1219
|
+
state: z.ZodEnum<{
|
|
1220
|
+
error: "error";
|
|
1221
|
+
success: "success";
|
|
1222
|
+
failure: "failure";
|
|
1223
|
+
pending: "pending";
|
|
1224
|
+
}>;
|
|
1225
|
+
context: z.ZodString;
|
|
1226
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1227
|
+
targetUrl: z.ZodOptional<z.ZodString>;
|
|
1228
|
+
}, z.core.$strip>;
|
|
1229
|
+
write: true;
|
|
1230
|
+
connectScopes: readonly ["contents:read", "metadata:read", "statuses:read", "statuses:write"];
|
|
1231
|
+
};
|
|
1148
1232
|
/** Diagnose CI failures for a ref — combined status, failing checks, and failed workflow jobs in one call. */
|
|
1149
1233
|
getCiFailureContext: {
|
|
1150
1234
|
description: string;
|
|
@@ -1340,15 +1424,11 @@ type GithubToolName = keyof typeof GITHUB_TOOL_CATALOG;
|
|
|
1340
1424
|
type GithubWriteToolName = { [K in GithubToolName]: (typeof GITHUB_TOOL_CATALOG)[K] extends {
|
|
1341
1425
|
write: true;
|
|
1342
1426
|
} ? K : never; }[GithubToolName];
|
|
1343
|
-
//#endregion
|
|
1344
|
-
//#region src/core/tool-names.d.ts
|
|
1345
1427
|
/**
|
|
1346
1428
|
* All GitHub tool names available via {@link createGithubTools}, keyed by name.
|
|
1347
1429
|
* Derived from `GITHUB_TOOL_CATALOG` — the single source of truth for tools.
|
|
1348
1430
|
*/
|
|
1349
1431
|
declare const GITHUB_TOOL_NAMES: { [K in GithubToolName]: K; };
|
|
1350
|
-
//#endregion
|
|
1351
|
-
//#region src/core/presets.d.ts
|
|
1352
1432
|
/**
|
|
1353
1433
|
* Predefined tool presets for common use cases.
|
|
1354
1434
|
* Pass to {@link createGithubTools}, {@link createGithubAgent}, or {@link createDurableGithubAgent}.
|
|
@@ -1362,21 +1442,22 @@ declare const PRESET_TOOLS: {
|
|
|
1362
1442
|
*
|
|
1363
1443
|
* Tools: `getPullRequest`, `listPullRequests`, `listPullRequestFiles`, `listPullRequestReviews`,
|
|
1364
1444
|
* `listPullRequestReviewThreads`, `getPullRequestContext`, `getCommit`, `getBlame`, `compareCommits`, `getRepository`,
|
|
1365
|
-
* `getFileContent`, `getRepositoryTree`, `searchCode`, `listCommits`, `listBranches`, `getBranchRules`, `
|
|
1366
|
-
* `updatePullRequest`, `addPullRequestComment`, `updatePullRequestComment`,
|
|
1367
|
-
* `createPullRequestReview`, `replyToReviewComment`, `resolveReviewThread`, `requestReviewers
|
|
1445
|
+
* `getFileContent`, `getRepositoryTree`, `searchCode`, `listCommits`, `listBranches`, `getBranchRules`, `getCollaboratorPermission`,
|
|
1446
|
+
* `listCheckRuns`, `getCombinedStatus`, `updatePullRequest`, `addPullRequestComment`, `updatePullRequestComment`,
|
|
1447
|
+
* `deletePullRequestComment`, `createPullRequestReview`, `replyToReviewComment`, `resolveReviewThread`, `requestReviewers`,
|
|
1448
|
+
* `createCommitStatus`.
|
|
1368
1449
|
*
|
|
1369
1450
|
* Agent prompt: optimized for thorough PR review with inline feedback.
|
|
1370
1451
|
*/
|
|
1371
|
-
readonly 'code-review': readonly ["getPullRequest", "listPullRequests", "listPullRequestFiles", "listPullRequestReviews", "listPullRequestReviewThreads", "getPullRequestContext", "getCommit", "getBlame", "compareCommits", "getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "listBranches", "getBranchRules", "listCheckRuns", "getCombinedStatus", "updatePullRequest", "addPullRequestComment", "updatePullRequestComment", "deletePullRequestComment", "createPullRequestReview", "replyToReviewComment", "resolveReviewThread", "requestReviewers"];
|
|
1452
|
+
readonly 'code-review': readonly ["getPullRequest", "listPullRequests", "listPullRequestFiles", "listPullRequestReviews", "listPullRequestReviewThreads", "getPullRequestContext", "getCommit", "getBlame", "compareCommits", "getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "listBranches", "getBranchRules", "getCollaboratorPermission", "listCheckRuns", "getCombinedStatus", "updatePullRequest", "addPullRequestComment", "updatePullRequestComment", "deletePullRequestComment", "createPullRequestReview", "replyToReviewComment", "resolveReviewThread", "requestReviewers", "createCommitStatus"];
|
|
1372
1453
|
/**
|
|
1373
1454
|
* **Issue triage** — manage and organize GitHub issues.
|
|
1374
1455
|
*
|
|
1375
1456
|
* Tools: `listIssues`, `getIssueContext`, `listIssueComments`, `createIssue`, `addIssueComment`, `updateIssueComment`,
|
|
1376
1457
|
* `deleteIssueComment`, `closeIssue`, `updateIssue`, `addLabels`, `removeLabel`, `createLabel`, `updateLabel`, `deleteLabel`,
|
|
1377
|
-
* `addAssignees`, `removeAssignees`, `
|
|
1378
|
-
* `
|
|
1379
|
-
* `getPullRequest`.
|
|
1458
|
+
* `addAssignees`, `removeAssignees`, `listMilestones`, `listSubIssues`, `addSubIssue`, `listIssueReactions`, `addIssueReaction`,
|
|
1459
|
+
* `listCommentReactions`, `addCommentReaction`, `getRepository`, `getFileContent`, `getRepositoryTree`, `searchCode`, `listCommits`,
|
|
1460
|
+
* `searchRepositories`, `searchIssues`, `getPullRequest`, `getCollaboratorPermission`.
|
|
1380
1461
|
*
|
|
1381
1462
|
* Prefer `getIssueContext` (issue + `labelNames` + recent comments) over separate get/list calls.
|
|
1382
1463
|
* Use `listIssueComments` to paginate beyond the comments returned by `getIssueContext`.
|
|
@@ -1384,18 +1465,19 @@ declare const PRESET_TOOLS: {
|
|
|
1384
1465
|
* Acknowledge a report with `addIssueReaction` / `addCommentReaction` instead of a comment when no reply is needed.
|
|
1385
1466
|
* Agent prompt: optimized for categorizing, labeling, and responding to issues.
|
|
1386
1467
|
*/
|
|
1387
|
-
readonly 'issue-triage': readonly ["listIssues", "getIssueContext", "listIssueComments", "createIssue", "addIssueComment", "updateIssueComment", "deleteIssueComment", "closeIssue", "updateIssue", "addLabels", "removeLabel", "createLabel", "updateLabel", "deleteLabel", "addAssignees", "removeAssignees", "listIssueReactions", "addIssueReaction", "listCommentReactions", "addCommentReaction", "getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "searchRepositories", "searchIssues", "getPullRequest"];
|
|
1468
|
+
readonly 'issue-triage': readonly ["listIssues", "getIssueContext", "listIssueComments", "createIssue", "addIssueComment", "updateIssueComment", "deleteIssueComment", "closeIssue", "updateIssue", "addLabels", "removeLabel", "createLabel", "updateLabel", "deleteLabel", "addAssignees", "removeAssignees", "listMilestones", "listSubIssues", "addSubIssue", "listIssueReactions", "addIssueReaction", "listCommentReactions", "addCommentReaction", "getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "searchRepositories", "searchIssues", "getPullRequest", "getCollaboratorPermission"];
|
|
1388
1469
|
/**
|
|
1389
1470
|
* **CI operations** — monitor and manage GitHub Actions workflows.
|
|
1390
1471
|
*
|
|
1391
1472
|
* Tools: `getRepository`, `getFileContent`, `getRepositoryTree`, `searchCode`, `listCommits`, `listBranches`, `getBranchRules`, `getCommit`,
|
|
1392
1473
|
* `getPullRequest`, `listWorkflows`, `listWorkflowRuns`, `getWorkflowRun`, `listWorkflowJobs`, `getWorkflowJobLogs`,
|
|
1393
|
-
* `listCheckRuns`, `getCombinedStatus`, `getCiFailureContext`, `triggerWorkflow`, `cancelWorkflowRun`, `rerunWorkflowRun
|
|
1474
|
+
* `listCheckRuns`, `getCombinedStatus`, `getCiFailureContext`, `triggerWorkflow`, `cancelWorkflowRun`, `rerunWorkflowRun`,
|
|
1475
|
+
* `createCommitStatus`.
|
|
1394
1476
|
*
|
|
1395
1477
|
* Diagnose a failure with `getCiFailureContext` first, then read the failing job's output with `getWorkflowJobLogs`.
|
|
1396
1478
|
* Agent prompt: optimized for diagnosing CI failures and managing workflow runs.
|
|
1397
1479
|
*/
|
|
1398
|
-
readonly 'ci-ops': readonly ["getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "listBranches", "getBranchRules", "getCommit", "getPullRequest", "listWorkflows", "listWorkflowRuns", "getWorkflowRun", "listWorkflowJobs", "getWorkflowJobLogs", "listCheckRuns", "getCombinedStatus", "getCiFailureContext", "triggerWorkflow", "cancelWorkflowRun", "rerunWorkflowRun"];
|
|
1480
|
+
readonly 'ci-ops': readonly ["getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "listBranches", "getBranchRules", "getCommit", "getPullRequest", "listWorkflows", "listWorkflowRuns", "getWorkflowRun", "listWorkflowJobs", "getWorkflowJobLogs", "listCheckRuns", "getCombinedStatus", "getCiFailureContext", "triggerWorkflow", "cancelWorkflowRun", "rerunWorkflowRun", "createCommitStatus"];
|
|
1399
1481
|
/**
|
|
1400
1482
|
* **Repository explorer** — read-only access to browse codebases.
|
|
1401
1483
|
*
|
|
@@ -1453,15 +1535,15 @@ declare const PRESET_TOOLS: {
|
|
|
1453
1535
|
/**
|
|
1454
1536
|
* **PR author** — open pull requests without the full write surface.
|
|
1455
1537
|
*
|
|
1456
|
-
* Tools: `getRepository`, `getFileContent`, `getRepositoryTree`, `searchCode`, `listCommits`, `listBranches`, `getBranchRules`,
|
|
1457
|
-
* `
|
|
1458
|
-
* `
|
|
1459
|
-
* `getCommit`.
|
|
1538
|
+
* Tools: `getRepository`, `getFileContent`, `getRepositoryTree`, `searchCode`, `listCommits`, `listBranches`, `getBranchRules`,
|
|
1539
|
+
* `getCollaboratorPermission`, `createBranch`, `deleteBranch`, `createOrUpdateFile`, `editFiles`, `createPullRequest`,
|
|
1540
|
+
* `updatePullRequest`, `updatePullRequestBranch`, `listPullRequests`, `getPullRequest`, `listPullRequestFiles`,
|
|
1541
|
+
* `listPullRequestReviewThreads`, `replyToReviewComment`, `resolveReviewThread`, `compareCommits`, `getCommit`.
|
|
1460
1542
|
*
|
|
1461
1543
|
* Respond to review feedback with `listPullRequestReviewThreads` → `replyToReviewComment` → `resolveReviewThread`.
|
|
1462
1544
|
* Agent prompt: optimized for branching, editing files, and opening focused PRs.
|
|
1463
1545
|
*/
|
|
1464
|
-
readonly 'pr-author': readonly ["getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "listBranches", "getBranchRules", "createBranch", "deleteBranch", "createOrUpdateFile", "editFiles", "createPullRequest", "updatePullRequest", "listPullRequests", "getPullRequest", "listPullRequestFiles", "listPullRequestReviewThreads", "replyToReviewComment", "resolveReviewThread", "compareCommits", "getCommit"];
|
|
1546
|
+
readonly 'pr-author': readonly ["getRepository", "getFileContent", "getRepositoryTree", "searchCode", "listCommits", "listBranches", "getBranchRules", "getCollaboratorPermission", "createBranch", "deleteBranch", "createOrUpdateFile", "editFiles", "createPullRequest", "updatePullRequest", "updatePullRequestBranch", "listPullRequests", "getPullRequest", "listPullRequestFiles", "listPullRequestReviewThreads", "replyToReviewComment", "resolveReviewThread", "compareCommits", "getCommit"];
|
|
1465
1547
|
/**
|
|
1466
1548
|
* **Maintainer** — full repository maintenance with all read and write tools.
|
|
1467
1549
|
*
|
|
@@ -1469,15 +1551,40 @@ declare const PRESET_TOOLS: {
|
|
|
1469
1551
|
*
|
|
1470
1552
|
* Agent prompt: optimized for day-to-day repo maintenance with careful write operations.
|
|
1471
1553
|
*/
|
|
1472
|
-
readonly maintainer: readonly ["getRepository", "listBranches", "getBranchRules", "getFileContent", "getRepositoryTree", "createBranch", "deleteBranch", "forkRepository", "createRepository", "createOrUpdateFile", "editFiles", "listPullRequests", "getPullRequest", "listPullRequestFiles", "listPullRequestReviews", "listPullRequestReviewThreads", "getPullRequestContext", "createPullRequest", "mergePullRequest", "enablePullRequestAutoMerge", "disablePullRequestAutoMerge", "updatePullRequest", "addPullRequestComment", "updatePullRequestComment", "deletePullRequestComment", "createPullRequestReview", "replyToReviewComment", "resolveReviewThread", "requestReviewers", "listIssues", "getIssue", "getIssueContext", "listIssueComments", "createIssue", "addIssueComment", "updateIssueComment", "deleteIssueComment", "closeIssue", "updateIssue", "listLabels", "addLabels", "removeLabel", "createLabel", "updateLabel", "deleteLabel", "addAssignees", "removeAssignees", "listIssueReactions", "addIssueReaction", "listCommentReactions", "addCommentReaction", "listDiscussions", "getDiscussion", "addDiscussionComment", "listNotifications", "markNotificationRead", "listCommits", "getCommit", "getBlame", "compareCommits", "searchCode", "searchRepositories", "searchIssues", "listGists", "getGist", "listGistComments", "createGist", "updateGist", "deleteGist", "createGistComment", "listWorkflows", "listWorkflowRuns", "getWorkflowRun", "listWorkflowJobs", "getWorkflowJobLogs", "triggerWorkflow", "cancelWorkflowRun", "rerunWorkflowRun", "listCheckRuns", "getCombinedStatus", "getCiFailureContext", "listReleases", "getLatestRelease", "getRelease", "getReleaseContext", "createRelease", "updateRelease", "deleteRelease", "listCodeScanningAlerts", "listDependabotAlerts", "listSecretScanningAlerts"];
|
|
1554
|
+
readonly maintainer: readonly ["getRepository", "listBranches", "getBranchRules", "getCollaboratorPermission", "getFileContent", "getRepositoryTree", "createBranch", "deleteBranch", "forkRepository", "createRepository", "createOrUpdateFile", "editFiles", "listPullRequests", "getPullRequest", "listPullRequestFiles", "listPullRequestReviews", "listPullRequestReviewThreads", "getPullRequestContext", "createPullRequest", "mergePullRequest", "enablePullRequestAutoMerge", "disablePullRequestAutoMerge", "updatePullRequest", "updatePullRequestBranch", "addPullRequestComment", "updatePullRequestComment", "deletePullRequestComment", "createPullRequestReview", "replyToReviewComment", "resolveReviewThread", "requestReviewers", "listIssues", "getIssue", "getIssueContext", "listIssueComments", "createIssue", "addIssueComment", "updateIssueComment", "deleteIssueComment", "closeIssue", "updateIssue", "listLabels", "addLabels", "removeLabel", "createLabel", "updateLabel", "deleteLabel", "addAssignees", "removeAssignees", "listMilestones", "listSubIssues", "addSubIssue", "listIssueReactions", "addIssueReaction", "listCommentReactions", "addCommentReaction", "listDiscussions", "getDiscussion", "addDiscussionComment", "listNotifications", "markNotificationRead", "listCommits", "getCommit", "getBlame", "compareCommits", "searchCode", "searchRepositories", "searchIssues", "listGists", "getGist", "listGistComments", "createGist", "updateGist", "deleteGist", "createGistComment", "listWorkflows", "listWorkflowRuns", "getWorkflowRun", "listWorkflowJobs", "getWorkflowJobLogs", "triggerWorkflow", "cancelWorkflowRun", "rerunWorkflowRun", "listCheckRuns", "getCombinedStatus", "createCommitStatus", "getCiFailureContext", "listReleases", "getLatestRelease", "getRelease", "getReleaseContext", "createRelease", "updateRelease", "deleteRelease", "listCodeScanningAlerts", "listDependabotAlerts", "listSecretScanningAlerts"];
|
|
1473
1555
|
};
|
|
1474
1556
|
type GithubToolPreset = keyof typeof PRESET_TOOLS;
|
|
1475
1557
|
/** Tool names included in a single preset. */
|
|
1476
1558
|
type PresetToolName<P extends GithubToolPreset> = Extract<(typeof PRESET_TOOLS)[P][number], GithubToolName>;
|
|
1477
1559
|
/** Tool names included when combining multiple presets. */
|
|
1478
1560
|
type CombinedPresetToolNames<P extends readonly GithubToolPreset[]> = PresetToolName<P[number]>;
|
|
1479
|
-
|
|
1480
|
-
|
|
1561
|
+
/**
|
|
1562
|
+
* Limits on where GitHub tools can act, checked on every call before it reaches GitHub.
|
|
1563
|
+
* Unlike approval, they hold whoever approves a call and whatever the model asks for.
|
|
1564
|
+
*/
|
|
1565
|
+
type GithubGuardrails = {
|
|
1566
|
+
/**
|
|
1567
|
+
* Repositories the tools may act on, as `owner/repo` or `owner/*`, matched case-insensitively.
|
|
1568
|
+
* A call to any other repository fails. Tools without a repository target (search, gists,
|
|
1569
|
+
* notifications) are not restricted. `createRepository` and `forkRepository` run only when the
|
|
1570
|
+
* new repository's full name matches, so they need `org` or `organization`. `addSubIssue` also
|
|
1571
|
+
* checks the sub-issue's repository, and `updatePullRequestBranch` the head's repository, which can be a fork.
|
|
1572
|
+
*/
|
|
1573
|
+
repositories?: string[];
|
|
1574
|
+
/**
|
|
1575
|
+
* Branches the tools may write to, as names or patterns where `*` matches any characters,
|
|
1576
|
+
* such as `agent/*`. Covers creating, deleting and committing to a branch, merging or enabling
|
|
1577
|
+
* auto-merge into a pull request's base branch, and updating a pull request's head branch.
|
|
1578
|
+
* A commit that doesn't name its branch fails.
|
|
1579
|
+
*/
|
|
1580
|
+
branches?: string[];
|
|
1581
|
+
/**
|
|
1582
|
+
* `'block'` (default) fails any call whose input contains what looks like a credential, such as a
|
|
1583
|
+
* GitHub token, a private key or a cloud API key, so the agent can't post one to GitHub. `'allow'`
|
|
1584
|
+
* turns the check off, for example when a repository's fixtures contain fake keys.
|
|
1585
|
+
*/
|
|
1586
|
+
secrets?: 'block' | 'allow';
|
|
1587
|
+
};
|
|
1481
1588
|
/**
|
|
1482
1589
|
* The tool call a token is requested for. Passed to token providers so they
|
|
1483
1590
|
* can mint a token for the call's target — e.g. the GitHub App installation
|
|
@@ -1498,10 +1605,16 @@ type GithubTokenCall = {
|
|
|
1498
1605
|
* outside a tool call.
|
|
1499
1606
|
*/
|
|
1500
1607
|
type GithubTokenInput = string | ((call?: GithubTokenCall) => Promise<string>);
|
|
1608
|
+
type GithubTokenResolver = (call?: GithubTokenCall) => Promise<string>;
|
|
1501
1609
|
/** Resolves a {@link GithubTokenInput} to a token string for an optional tool call. */
|
|
1502
1610
|
declare function resolveGithubToken(token?: GithubTokenInput, call?: GithubTokenCall): Promise<string>;
|
|
1503
|
-
|
|
1504
|
-
|
|
1611
|
+
/**
|
|
1612
|
+
* Wrap a token so every call it resolves for is checked against `guardrails` first, including the
|
|
1613
|
+
* default check for credentials in the input. A blocked call
|
|
1614
|
+
* throws `github_tools.GUARDRAIL_BLOCKED` before any request reaches GitHub. Use it when you build
|
|
1615
|
+
* tools from individual factories; `createGithubTools({ guardrails })` applies it for you.
|
|
1616
|
+
*/
|
|
1617
|
+
declare function withGithubGuardrails(token: GithubTokenInput | undefined, guardrails: GithubGuardrails | undefined): GithubTokenResolver;
|
|
1505
1618
|
/**
|
|
1506
1619
|
* Decision model used by `'auto'` approval and `preset: 'auto'` unless `evaluation.model` is set.
|
|
1507
1620
|
* Pinned to a Jev release so the default thresholds keep matching the model they were set for;
|
|
@@ -1515,15 +1628,11 @@ declare const DEFAULT_EVALUATION_MODEL = "typesafe-ai/jev-1.14.0";
|
|
|
1515
1628
|
*/
|
|
1516
1629
|
declare const AUTO_APPROVAL_TOOLS: readonly ["addLabels", "removeLabel", "addAssignees", "removeAssignees", "addIssueReaction", "addCommentReaction", "addIssueComment", "addPullRequestComment", "addDiscussionComment", "createGistComment", "replyToReviewComment", "resolveReviewThread", "requestReviewers", "markNotificationRead"];
|
|
1517
1630
|
type RoutablePreset = Exclude<GithubToolPreset, 'maintainer'>;
|
|
1518
|
-
//#endregion
|
|
1519
|
-
//#region src/core/write-tools.d.ts
|
|
1520
1631
|
/**
|
|
1521
1632
|
* GitHub tools that perform write operations and require approval by default.
|
|
1522
1633
|
* Derived from the `write: true` entries of `GITHUB_TOOL_CATALOG`.
|
|
1523
1634
|
*/
|
|
1524
1635
|
declare const GITHUB_WRITE_TOOLS: { [K in GithubWriteToolName]: K; };
|
|
1525
|
-
//#endregion
|
|
1526
|
-
//#region src/core/evaluation.d.ts
|
|
1527
1636
|
/**
|
|
1528
1637
|
* Tuning for `requireApproval: 'auto'` and `preset: 'auto'`. Every field is optional.
|
|
1529
1638
|
*/
|
|
@@ -1650,8 +1759,6 @@ declare function selectTools(messages: readonly ModelMessage[], options?: Github
|
|
|
1650
1759
|
*/
|
|
1651
1760
|
declare function selectPresets(messages: readonly ModelMessage[], options?: GithubEvaluationOptions, abortSignal?: AbortSignal): Promise<RoutablePreset[]>;
|
|
1652
1761
|
declare function latestUserText(messages: readonly ModelMessage[]): string;
|
|
1653
|
-
//#endregion
|
|
1654
|
-
//#region src/core/approval-policy.d.ts
|
|
1655
1762
|
/**
|
|
1656
1763
|
* Approval for a single write tool.
|
|
1657
1764
|
*
|
|
@@ -1695,8 +1802,6 @@ type ToolApprovalMode = boolean | 'auto';
|
|
|
1695
1802
|
type ApprovalConfig = ToolApprovalMode | Partial<Record<GithubWriteToolName, ToolApprovalMode>>;
|
|
1696
1803
|
/** {@link ApprovalConfig} without `'auto'`, for runtimes that cannot run the evaluation model. */
|
|
1697
1804
|
type StaticApprovalConfig = boolean | Partial<Record<GithubWriteToolName, boolean>>;
|
|
1698
|
-
//#endregion
|
|
1699
|
-
//#region src/types.d.ts
|
|
1700
1805
|
type GithubTool = Tool<any, any>;
|
|
1701
1806
|
type ToolOptions = {
|
|
1702
1807
|
needsApproval?: GithubTool['needsApproval'];
|
|
@@ -1750,8 +1855,6 @@ type CommitToolOptions = ToolOptions & {
|
|
|
1750
1855
|
* ```
|
|
1751
1856
|
*/
|
|
1752
1857
|
type ToolOverrides = Partial<Pick<Tool, 'description' | 'needsApproval' | 'onInputAvailable' | 'onInputDelta' | 'onInputStart' | 'providerOptions' | 'strict' | 'title' | 'toModelOutput'>>;
|
|
1753
|
-
//#endregion
|
|
1754
|
-
//#region src/core/context.d.ts
|
|
1755
1858
|
/**
|
|
1756
1859
|
* Default repository / issue / PR / ref values applied to tool inputs and
|
|
1757
1860
|
* injected into agent system prompts.
|
|
@@ -1766,8 +1869,6 @@ type GithubToolsContext = {
|
|
|
1766
1869
|
issueNumber?: number;
|
|
1767
1870
|
ref?: string;
|
|
1768
1871
|
};
|
|
1769
|
-
//#endregion
|
|
1770
|
-
//#region src/core/tool-types.d.ts
|
|
1771
1872
|
/** Full tool set returned when no `preset` is specified. */
|
|
1772
1873
|
type AllGithubTools = Record<GithubToolName, GithubTool>;
|
|
1773
1874
|
/** Base options shared by all {@link createGithubTools} overloads. */
|
|
@@ -1792,11 +1893,38 @@ type GithubToolsBaseOptions = {
|
|
|
1792
1893
|
committer?: CommitIdentity;
|
|
1793
1894
|
/** Co-authors to attribute on all commits created by tools. */
|
|
1794
1895
|
coAuthors?: CommitIdentity[];
|
|
1896
|
+
/**
|
|
1897
|
+
* Repositories and branches the tools may act on, checked before each call reaches GitHub.
|
|
1898
|
+
* A blocked call fails with `github_tools.GUARDRAIL_BLOCKED`, whoever approves it.
|
|
1899
|
+
* @see {@link GithubGuardrails}
|
|
1900
|
+
*/
|
|
1901
|
+
guardrails?: GithubGuardrails;
|
|
1902
|
+
/**
|
|
1903
|
+
* Run reads as usual but send no write to GitHub: each write tool returns a
|
|
1904
|
+
* `GithubDryRunResult` instead, after the approval and guardrail checks. Use it to try an
|
|
1905
|
+
* agent on real repositories without changing them.
|
|
1906
|
+
*/
|
|
1907
|
+
dryRun?: boolean;
|
|
1795
1908
|
};
|
|
1796
1909
|
/** Tool set shape for a given preset option (single, combined, or all tools). */
|
|
1797
1910
|
type GithubToolsForPreset<P extends GithubToolPreset | readonly GithubToolPreset[] | undefined> = P extends GithubToolPreset ? Pick<AllGithubTools, PresetToolName<P> & GithubToolName> : P extends readonly GithubToolPreset[] ? Pick<AllGithubTools, CombinedPresetToolNames<P> & GithubToolName> : AllGithubTools;
|
|
1798
1911
|
/** Pick a subset of GitHub tools by tool name. */
|
|
1799
1912
|
type PickGithubTools<T extends GithubToolName> = Pick<AllGithubTools, T>;
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1913
|
+
/** What approval would have decided for a write, had it run for real. */
|
|
1914
|
+
type GithubDryRunApproval = {
|
|
1915
|
+
/** `true` when a person would have been asked to approve the call. */
|
|
1916
|
+
required: boolean;
|
|
1917
|
+
/** The evaluation model's verdict, with `requireApproval: 'auto'`. */
|
|
1918
|
+
reason?: string;
|
|
1919
|
+
};
|
|
1920
|
+
/** What a write tool returns under `dryRun`: nothing is sent to GitHub, and nobody is asked to approve it. */
|
|
1921
|
+
type GithubDryRunResult = {
|
|
1922
|
+
dryRun: true;
|
|
1923
|
+
tool: GithubWriteToolName;
|
|
1924
|
+
input: Record<string, unknown>;
|
|
1925
|
+
/** What approval would have decided, when the integration can tell. */
|
|
1926
|
+
approval?: GithubDryRunApproval;
|
|
1927
|
+
message: string;
|
|
1928
|
+
};
|
|
1929
|
+
export { DEFAULT_EVALUATION_MODEL as A, GithubToolPreset as B, fallbackTools as C, selectTools as D, selectPresets as E, resolveGithubToken as F, GithubToolName as G, PresetToolName as H, withGithubGuardrails as I, GithubWriteToolName as K, GithubGuardrails as L, GithubTokenCall as M, GithubTokenInput as N, GITHUB_WRITE_TOOLS as O, GithubTokenResolver as P, CORE_READ_TOOLS as R, fallbackPresets as S, needsAutoApproval as T, GITHUB_TOOL_NAMES as U, PRESET_TOOLS as V, GITHUB_TOOL_CATALOG as W, AutoApprovalDecision as _, GithubToolsForPreset as a, evaluatePresets as b, CommitIdentity as c, Octokit$1 as d, ToolOptions as f, ToolApprovalMode as g, StaticApprovalConfig as h, GithubToolsBaseOptions as i, RoutablePreset as j, AUTO_APPROVAL_TOOLS as k, CommitToolOptions as l, ApprovalConfig as m, GithubDryRunResult as n, PickGithubTools as o, ToolOverrides as p, AllGithubTools as r, GithubToolsContext as s, GithubDryRunApproval as t, GithubTool as u, GithubEvaluationOptions as v, latestUserText as w, evaluateTools as x, autoApprovalDecision as y, CombinedPresetToolNames as z };
|
|
1930
|
+
//# sourceMappingURL=dry-run-BAbes7Mv.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dry-run-BAbes7Mv.d.mts","names":[],"sources":["../src/core/catalog.ts","../src/core/tool-names.ts","../src/core/presets.ts","../src/core/guardrails.ts","../src/core/token.ts","../src/core/evaluation-policy.ts","../src/core/write-tools.ts","../src/core/evaluation.ts","../src/core/approval-policy.ts","../src/types.ts","../src/core/context.ts","../src/core/tool-types.ts","../src/core/dry-run.ts"],"mappings":";;;;;;;;;;;;cA0Ea;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;iBAShI,cAAc,kBAAkB,UAAoC,yBAA8B,cAAc,cAAc;;;;;iBASxH,YACpB,mBAAmB,gBACnB,UAAS,yBACT,cAAc,cACb,QAAQ;;;;;iBAQW,cACpB,mBAAmB,gBACnB,UAAS,yBACT,cAAc,cACb,QAAQ;iBAIK,eAAe,mBAAmB;;;;;;;;;KCpStC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiCA,iBAAiB,mBAAmB,QAAQ,OAAO,qBAAqB;;KAGxE,iCAAiC,QAAQ,OAAO;KCzChD,aAAa;KAEb;EAAgB,gBAAgB;;;;;;;;KAQhC;EACV;EACA;;;;;KAMU,oBAAoB;;;;;EAK9B,SAAS;;;;;EAKT,YAAY;;;;;EAKZ,YAAY;;;;;;;;;;;;;;;;;;;;KAqBF,gBAAgB,QAC1B,KACE;;;;;;;;KCpDQ;EACV;EACA;EACA;EACA;EACA;;;KCLU,iBAAiB,OAAO,gBAAgB;;KAGxC;;EAEV,QAAQ;;EAER,kBAAkB;;EAElB,aAAa;;;;;;EAMb,UAAU;;EAEV,YAAY,QAAQ,OAAO,gBAAgB;;EAE3C,SAAS;;EAET,YAAY;;EAEZ,YAAY;;;;;;EAMZ,aAAa;;;;;;EAMb;;;KAIU,qBAAqB,UAAU,4BAA4B,kCACrE,UAAU,mBACN,KAAK,gBAAgB,eAAe,KAAK,kBACzC,mBAAmB,qBACjB,KAAK,gBAAgB,wBAAwB,KAAK,kBAClD;;KAGI,gBAAgB,UAAU,kBAAkB,KAAK,gBAAgB;;KCnDjE;;EAEV;;EAEA;;;KAIU;EACV;EACA,MAAM;EACN,OAAO;;EAEP,WAAW;EACX"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as GITHUB_TOOL_CATALOG, Za as githubToolsErrors, _ as CORE_READ_TOOLS, d as PRESET_PURPOSES, f as RISK_QUESTION, h as requiresApproval, l as DEFAULT_EVALUATION_MODEL, m as rankPresets, p as conversationState, u as INTENT_QUESTION, v as PRESET_TOOLS, w as ALL_GITHUB_TOOL_NAMES } from "./write-tools-BR29EOoM.mjs";
|
|
2
2
|
import * as ai from "ai";
|
|
3
|
-
|
|
3
|
+
// src/core/model-output.ts
|
|
4
4
|
const MAX_PATCH_LENGTH = 4e3;
|
|
5
5
|
const MAX_CONTENT_LENGTH = 2e4;
|
|
6
6
|
const MAX_MODEL_TREE_ENTRIES = 200;
|
|
@@ -115,8 +115,7 @@ function getPullRequestContextToModelOutput({ output }) {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
//#region src/core/evaluation.ts
|
|
118
|
+
// src/core/evaluation.ts
|
|
120
119
|
/**
|
|
121
120
|
* Throws `EVALUATION_UNAVAILABLE` when the installed `ai` has neither `experimental_decide`
|
|
122
121
|
* nor `experimental_evaluate`. Call it where `'auto'` is configured, so a too-old `ai` fails
|
|
@@ -305,7 +304,6 @@ function messageText(message) {
|
|
|
305
304
|
if (typeof message.content === "string") return message.content;
|
|
306
305
|
return message.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n");
|
|
307
306
|
}
|
|
308
|
-
//#endregion
|
|
309
307
|
export { listPullRequestFilesToModelOutput as _, evaluationRequest as a, latestUserText as c, selectTools as d, compareCommitsToModelOutput as f, getRepositoryTreeToModelOutput as g, getPullRequestContextToModelOutput as h, evaluateTools as i, needsAutoApproval as l, getFileContentToModelOutput as m, autoApprovalDecision as n, fallbackPresets as o, getCommitToModelOutput as p, evaluatePresets as r, fallbackTools as s, assertEvaluationAvailable as t, selectPresets as u };
|
|
310
308
|
|
|
311
|
-
//# sourceMappingURL=evaluation-
|
|
309
|
+
//# sourceMappingURL=evaluation-DskA4Lzk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation-BtoHbxuQ.mjs","names":["exports"],"sources":["../src/core/model-output.ts","../src/core/evaluation.ts"],"sourcesContent":["const MAX_PATCH_LENGTH = 4000\nconst MAX_CONTENT_LENGTH = 20000\nconst MAX_MODEL_TREE_ENTRIES = 200\nconst MAX_MODEL_DIFF_FILES = 80\n\nfunction truncateText(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text\n return `${text.slice(0, maxLength)}\\n\\n[truncated: ${text.length - maxLength} more characters]`\n}\n\nfunction truncatePatchFields<T extends { patch?: string }>(files: T[]): T[] {\n return files.map(file => ({\n ...file,\n patch: file.patch ? truncateText(file.patch, MAX_PATCH_LENGTH) : file.patch,\n }))\n}\n\nfunction capDiffFiles<T extends { patch?: string }>(files: T[] | undefined) {\n if (!files) return { files, filesOmitted: 0 }\n const truncated = truncatePatchFields(files)\n if (truncated.length <= MAX_MODEL_DIFF_FILES) return { files: truncated, filesOmitted: 0 }\n return {\n files: truncated.slice(0, MAX_MODEL_DIFF_FILES),\n filesOmitted: truncated.length - MAX_MODEL_DIFF_FILES,\n }\n}\n\ntype ToModelOutputOptions = {\n toolCallId: string\n input: unknown\n output: unknown\n}\n\ntype ListPullRequestFile = {\n filename: string\n status: string\n additions: number\n deletions: number\n changes: number\n patch?: string\n}\n\ntype ListPullRequestFilesOutput = {\n items: ListPullRequestFile[]\n hasMore: boolean\n page: number\n perPage: number\n nextPage?: number\n}\n\ntype GetCommitOutput = {\n sha: string\n message: string\n author?: string\n authorLogin?: string\n date?: string\n url: string\n stats: { additions: number, deletions: number, total: number } | null\n files?: Array<{\n filename: string\n status: string\n additions: number\n deletions: number\n patch?: string\n }>\n}\n\ntype GetFileContentOutput =\n | { type: 'directory', entries: Array<{ name: string, type: string, path: string }> }\n | { type: string, path: string }\n | {\n type: 'file'\n path: string\n sha: string\n size: number\n content: string\n totalLines?: number\n startLine?: number\n endLine?: number\n truncated?: boolean\n }\n\nexport function listPullRequestFilesToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as ListPullRequestFilesOutput\n return {\n type: 'json' as const,\n value: {\n ...result,\n items: truncatePatchFields(result.items),\n },\n }\n}\n\nexport function getCommitToModelOutput({ output }: ToModelOutputOptions) {\n const commit = output as GetCommitOutput\n const { files, filesOmitted } = capDiffFiles(commit.files)\n return {\n type: 'json' as const,\n value: {\n ...commit,\n files,\n ...filesOmitted > 0 ? { filesOmitted } : {},\n },\n }\n}\n\ntype CompareCommitsOutput = {\n status: string\n aheadBy: number\n behindBy: number\n totalCommits: number\n url: string\n commits: Array<{ sha: string, message: string, author?: string, authorLogin?: string }>\n files?: Array<{\n filename: string\n status: string\n additions: number\n deletions: number\n patch?: string\n }>\n}\n\nexport function compareCommitsToModelOutput({ output }: ToModelOutputOptions) {\n const comparison = output as CompareCommitsOutput\n const { files, filesOmitted } = capDiffFiles(comparison.files)\n return {\n type: 'json' as const,\n value: {\n ...comparison,\n files,\n ...filesOmitted > 0 ? { filesOmitted } : {},\n },\n }\n}\n\nexport function getFileContentToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as GetFileContentOutput\n if (result.type === 'directory' && 'entries' in result && result.entries.length > MAX_MODEL_TREE_ENTRIES) {\n return {\n type: 'json' as const,\n value: {\n ...result,\n truncated: true,\n entries: result.entries.slice(0, MAX_MODEL_TREE_ENTRIES),\n entriesOmitted: result.entries.length - MAX_MODEL_TREE_ENTRIES,\n },\n }\n }\n if ('content' in result && result.content.length > MAX_CONTENT_LENGTH) {\n return {\n type: 'json' as const,\n value: {\n ...result,\n content: truncateText(result.content, MAX_CONTENT_LENGTH),\n },\n }\n }\n return { type: 'json' as const, value: result }\n}\n\ntype GetRepositoryTreeOutput = {\n sha: string\n truncated: boolean\n path?: string\n entries: Array<{ path?: string, type?: string, size?: number, sha?: string }>\n}\n\nexport function getRepositoryTreeToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as GetRepositoryTreeOutput\n if (result.entries.length <= MAX_MODEL_TREE_ENTRIES) {\n return { type: 'json' as const, value: result }\n }\n return {\n type: 'json' as const,\n value: {\n ...result,\n truncated: true,\n entries: result.entries.slice(0, MAX_MODEL_TREE_ENTRIES),\n entriesOmitted: result.entries.length - MAX_MODEL_TREE_ENTRIES,\n },\n }\n}\n\ntype GetPullRequestContextOutput = {\n pullRequest: {\n number: number\n title: string\n body: string | null\n state: string\n url: string\n author?: string\n branch: string\n headSha: string\n base: string\n draft?: boolean\n merged: boolean\n mergeable: boolean | null\n additions: number\n deletions: number\n changedFiles: number\n createdAt: string\n updatedAt: string\n mergedAt: string | null\n }\n files?: ListPullRequestFile[]\n filesHasMore?: boolean\n reviews?: Array<{\n id: number\n state: string\n body: string\n author?: string\n url: string\n submittedAt?: string | null\n }>\n checks?: {\n checkRuns: {\n totalCount: number\n checkRuns: Array<{\n id: number\n name: string\n status: string\n conclusion: string | null\n url: string | null\n startedAt: string | null\n completedAt: string | null\n }>\n }\n combinedStatus: {\n state: string\n totalCount: number\n statuses: Array<{\n context: string\n state: string\n description: string | null\n url: string | null\n }>\n }\n }\n}\n\nexport function getPullRequestContextToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as GetPullRequestContextOutput\n const { files, filesOmitted } = capDiffFiles(result.files)\n return {\n type: 'json' as const,\n value: {\n ...result,\n files,\n ...filesOmitted > 0 ? { filesOmitted } : {},\n },\n }\n}\n","import * as ai from 'ai'\nimport type { Experimental_EvaluationModel, JSONValue, ModelMessage } from 'ai'\nimport { GITHUB_TOOL_CATALOG } from './catalog'\nimport { githubToolsErrors } from './errors'\nimport { CORE_READ_TOOLS, PRESET_TOOLS } from './presets'\nimport { ALL_GITHUB_TOOL_NAMES, type GithubToolName } from './tool-names'\nimport { DEFAULT_EVALUATION_MODEL, RISK_QUESTION, INTENT_QUESTION, PRESET_PURPOSES, conversationState, rankPresets, requiresApproval, type RoutablePreset } from './evaluation-policy'\nexport { DEFAULT_EVALUATION_MODEL, AUTO_APPROVAL_TOOLS } from './evaluation-policy'\nimport type { GithubWriteToolName } from './write-tools'\n\n/**\n * Tuning for `requireApproval: 'auto'` and `preset: 'auto'`. Every field is optional.\n */\nexport type GithubEvaluationOptions = {\n /**\n * Decision model for AI SDK `experimental_decide`: an AI Gateway ID or a model instance.\n * @default 'typesafe-ai/jev-1.14.0'\n */\n model?: Experimental_EvaluationModel\n /**\n * Provider options passed to every decision call, for example AI Gateway settings such as\n * `{ gateway: { zeroDataRetention: true } }`.\n */\n providerOptions?: Record<string, Record<string, JSONValue>>\n /**\n * Highest risk an `'auto'` tool call can have and still run without approval, on a 0–2 scale\n * (0 negligible, 1 visible but reversible, 2 hard to undo).\n * @default 1\n */\n maxRisk?: number\n /**\n * Lowest probability that the latest user message asked for the call, for it to run without approval.\n * @default 0.6\n */\n minIntent?: number\n /**\n * Lowest probability for `preset: 'auto'` to select a preset. When no preset reaches it,\n * read-only `repo-explorer` is used.\n * @default 0.7\n */\n minPresetProbability?: number\n /**\n * Most presets `preset: 'auto'` combines in one call, keeping the most likely ones.\n * @default 2\n */\n maxPresets?: number\n /**\n * What `preset: 'auto'` picks. `'tools'` asks the decision model about each tool and lists only\n * the likely ones plus the core read tools (`CORE_READ_TOOLS`), so the model sees far fewer tool\n * definitions. The rest stays reachable: eve defers it, and `createGithubAgent` adds a\n * `callGithubTool` tool. `'presets'` lists the tools of up to `maxPresets` presets and, on\n * `createGithubAgent`, uses their system prompts.\n * @default 'tools'\n */\n selection?: 'presets' | 'tools'\n /**\n * How long a `preset: 'auto'` decision lasts. `'session'` decides once, on the conversation's\n * first request, so the listed tools, and the provider's cached prompt prefix they start, stay\n * the same for the rest of the conversation; later needs go through deferred tools (eve) or\n * `callGithubTool` (`createGithubAgent`, which doesn't support it with `selection: 'presets'`).\n * `'turn'` decides again for each new request, which changes the tool list and makes the\n * provider write the whole conversation to its prompt cache again.\n * @default 'session', except `'turn'` for presets on `createGithubAgent`\n */\n scope?: 'turn' | 'session'\n /**\n * Keeps `createGithubAgent`'s `preset: 'auto'` decisions across processes, such as serverless\n * instances, under keys derived from the request and the routing settings (decision model,\n * thresholds and caps), so agents configured differently don't share decisions. Without it, a decision\n * lives in this process's memory, and another process decides again: that costs a decision\n * call, and a different pick changes the tool list and invalidates the provider's prompt cache.\n * The eve extension keeps decisions in the session and ignores this option.\n */\n store?: {\n get: (key: string) => Promise<readonly string[] | undefined>\n set: (key: string, value: readonly string[]) => Promise<void>\n }\n /**\n * Lowest probability for `selection: 'tools'` to list a tool beyond the core read tools.\n * @default 0.5\n */\n minToolProbability?: number\n /**\n * Most tools `selection: 'tools'` lists beyond the core read tools, keeping the most likely ones.\n * @default 8\n */\n maxTools?: number\n}\n\n/**\n * Throws `EVALUATION_UNAVAILABLE` when the installed `ai` has neither `experimental_decide`\n * nor `experimental_evaluate`. Call it where `'auto'` is configured, so a too-old `ai` fails\n * at setup instead of mid-conversation.\n */\nexport function assertEvaluationAvailable() {\n loadDecide()\n}\n\n// `experimental_decide` replaced `experimental_evaluate` in ai 7.0.128; the old name stays an alias.\nfunction loadDecide(): typeof ai.experimental_decide {\n const exports: Partial<Pick<typeof ai, 'experimental_decide' | 'experimental_evaluate'>> = ai\n const decide = exports.experimental_decide ?? exports.experimental_evaluate\n if (!decide) throw githubToolsErrors.EVALUATION_UNAVAILABLE()\n return decide\n}\n\n// `decide` throws when the model refuses any question; the error names the refused questions.\nfunction refusedQuestions(error: unknown): readonly string[] | undefined {\n const exports: Partial<Pick<typeof ai, 'Experimental_DecisionRefusalError'>> = ai\n return exports.Experimental_DecisionRefusalError?.isInstance(error) ? error.questionIds : undefined\n}\n\nfunction warnEvaluationFailed(model: Experimental_EvaluationModel, fallback: string, error: unknown, abortSignal?: AbortSignal) {\n abortSignal?.throwIfAborted()\n const cause = error instanceof Error ? error : new Error(String(error))\n console.warn('[github-tools]', githubToolsErrors.EVALUATION_FAILED({\n model: typeof model === 'string' ? model : model.modelId,\n fallback,\n detail: cause.message,\n cause,\n }))\n}\n\n/** Whether a person should approve a GitHub write, and why, as a short sentence for the approval request. */\nexport type AutoApprovalDecision = { ask: boolean, reason: string }\n\nconst RISK_LABELS = RISK_QUESTION.criteria.map(criterion => criterion.slice(0, criterion.indexOf(':')))\n\n/**\n * Asks the decision model how risky a GitHub write is and whether the user asked for it, and\n * explains the outcome: `ask` is true when a person should approve the call. A failed or refused\n * decision asks, since it gives no evidence that the call is safe.\n */\nexport async function autoApprovalDecision(\n toolName: GithubWriteToolName,\n input: unknown,\n messages: readonly ModelMessage[],\n { model = DEFAULT_EVALUATION_MODEL, maxRisk = 1, minIntent = 0.6, providerOptions }: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<AutoApprovalDecision> {\n const decide = loadDecide()\n let refused = false\n const result = await decide({\n model,\n providerOptions,\n state: {\n ...conversationState(messages, messageText),\n toolCall: {\n tool: toolName,\n description: GITHUB_TOOL_CATALOG[toolName].description,\n input: input as JSONValue,\n },\n },\n questions: {\n risk: { type: 'score', ...RISK_QUESTION },\n intent: { type: 'boolean', ...INTENT_QUESTION },\n },\n abortSignal,\n }).catch((error: unknown) => {\n // A refusal is an answer, not an outage: it gives no evidence the call is safe, so a person decides.\n refused = Boolean(refusedQuestions(error))\n if (!refused) warnEvaluationFailed(model, `asking approval for ${toolName}`, error, abortSignal)\n return undefined\n })\n if (!result) return { ask: true, reason: refused ? 'The decision model declined to rate this call.' : 'The decision model was unavailable.' }\n const risk = result.answers.risk.score\n const intent = result.answers.intent.probability\n // Jev scores risk on a continuous 0–2 scale, so the label is the nearest rubric level.\n const verdict = `${RISK_LABELS[Math.round(risk)]} (risk ${Number(risk.toFixed(1))} of 2), ${Math.round(intent * 100)}% likely you asked for it`\n return requiresApproval(risk, intent, { maxRisk, minIntent })\n ? { ask: true, reason: `${verdict}.` }\n : { ask: false, reason: `Approved automatically: ${verdict.charAt(0).toLowerCase()}${verdict.slice(1)}.` }\n}\n\n/** Whether a GitHub write needs a person's approval; see {@link autoApprovalDecision}. */\nexport async function needsAutoApproval(\n toolName: GithubWriteToolName,\n input: unknown,\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<boolean> {\n return (await autoApprovalDecision(toolName, input, messages, options, abortSignal)).ask\n}\n\n/**\n * Presets the latest user message needs, from one evaluation call with an independent\n * yes/no question per preset. Returns up to `maxPresets` presets at or above\n * `minPresetProbability`, most likely first, and read-only `repo-explorer` when none qualifies.\n * `repo-explorer` is only combined with no other preset. Rejects when the evaluation call fails;\n * {@link selectPresets} falls back instead. Never returns `maintainer`, so the full catalog is never exposed.\n */\nexport async function evaluatePresets(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<RoutablePreset[]> {\n const { minPresetProbability = 0.7, maxPresets = 2 } = options\n const presets = Object.keys(PRESET_PURPOSES) as RoutablePreset[]\n const probabilities = await decideEach(messages, presets, preset => ({\n instructions: 'Does handling this GitHub request need the tools of this preset?',\n criteria: { true: { purpose: PRESET_PURPOSES[preset], tools: [...PRESET_TOOLS[preset]] } },\n }), options, abortSignal)\n return rankPresets(probabilities, { minPresetProbability, maxPresets })\n}\n\n/**\n * Tools the latest user message needs, from one decision call with a yes/no question per tool:\n * the core read tools, plus up to `maxTools` others at or above `minToolProbability`, most likely\n * first. Rejects when the decision call fails; {@link selectTools} falls back instead.\n */\nexport async function evaluateTools(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<GithubToolName[]> {\n const { minToolProbability = 0.5, maxTools = 8 } = options\n const core: readonly GithubToolName[] = CORE_READ_TOOLS\n const candidates = ALL_GITHUB_TOOL_NAMES.filter(name => !core.includes(name))\n const probabilities = await decideEach(messages, candidates, name => ({\n instructions: 'Does handling this GitHub request need this tool?',\n criteria: { true: { tool: name, description: GITHUB_TOOL_CATALOG[name].description } },\n }), options, abortSignal)\n const likely = candidates\n .filter(name => probabilities[name] >= minToolProbability)\n .toSorted((a, b) => probabilities[b] - probabilities[a])\n .slice(0, maxTools)\n return [...core, ...likely]\n}\n\ntype BooleanQuestion = { instructions: string, criteria: { true: Record<string, JSONValue> } }\n\n// One boolean question per key against the conversation. A refused question counts as a no:\n// ask once more without it instead of losing every answer.\nasync function decideEach<K extends string>(\n messages: readonly ModelMessage[],\n keys: readonly K[],\n question: (key: K) => BooleanQuestion,\n { model = DEFAULT_EVALUATION_MODEL, providerOptions }: GithubEvaluationOptions,\n abortSignal?: AbortSignal,\n): Promise<Record<K, number>> {\n const decide = loadDecide()\n const state = conversationState(messages, messageText)\n const ask = (asked: readonly K[]) => decide({\n model,\n providerOptions,\n state,\n questions: Object.fromEntries(asked.map(key => [key, { type: 'boolean' as const, ...question(key) }])),\n abortSignal,\n })\n const probabilities = Object.fromEntries(keys.map(key => [key, 0])) as Record<K, number>\n const { answers } = await ask(keys).catch((error: unknown) => {\n const refused = refusedQuestions(error)\n const remaining = keys.filter(key => !refused?.includes(key))\n if (!refused || remaining.length === 0) throw error\n return ask(remaining)\n })\n for (const [key, answer] of Object.entries(answers)) probabilities[key as K] = answer.probability\n return probabilities\n}\n\n/**\n * Logs `EVALUATION_FAILED` for a failed {@link evaluatePresets} call and returns the read-only\n * `repo-explorer` fallback. Rethrows when `abortSignal` is aborted.\n */\nexport function fallbackPresets(error: unknown, { model = DEFAULT_EVALUATION_MODEL }: GithubEvaluationOptions = {}, abortSignal?: AbortSignal): RoutablePreset[] {\n warnEvaluationFailed(model, 'using the repo-explorer preset', error, abortSignal)\n return ['repo-explorer']\n}\n\n/**\n * Logs `EVALUATION_FAILED` for a failed {@link evaluateTools} call and returns the read-only\n * `repo-explorer` tools. Rethrows when `abortSignal` is aborted.\n */\nexport function fallbackTools(error: unknown, { model = DEFAULT_EVALUATION_MODEL }: GithubEvaluationOptions = {}, abortSignal?: AbortSignal): GithubToolName[] {\n warnEvaluationFailed(model, 'using the repo-explorer tools', error, abortSignal)\n return [...PRESET_TOOLS['repo-explorer']]\n}\n\n/**\n * {@link evaluateTools}, falling back to the read-only `repo-explorer` tools (and logging\n * `EVALUATION_FAILED`) when the decision call fails.\n */\nexport async function selectTools(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<GithubToolName[]> {\n return evaluateTools(messages, options, abortSignal).catch(error => fallbackTools(error, options, abortSignal))\n}\n\n/**\n * {@link evaluatePresets}, falling back to read-only `repo-explorer` (and logging\n * `EVALUATION_FAILED`) when the evaluation call fails.\n */\nexport async function selectPresets(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<RoutablePreset[]> {\n return evaluatePresets(messages, options, abortSignal).catch(error => fallbackPresets(error, options, abortSignal))\n}\n\nexport function latestUserText(messages: readonly ModelMessage[]): string {\n return conversationState(messages, messageText).request\n}\n\n/** The `request` and `repliedTo` the evaluation model sees for these messages. */\nexport function evaluationRequest(messages: readonly ModelMessage[]) {\n return conversationState(messages, messageText)\n}\n\nfunction messageText(message: ModelMessage): string {\n if (typeof message.content === 'string') return message.content\n return message.content.flatMap(part => part.type === 'text' ? [part.text] : []).join('\\n')\n}\n"],"mappings":";;;AAAA,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAC3B,MAAM,yBAAyB;AAC/B,MAAM,uBAAuB;AAE7B,SAAS,aAAa,MAAc,WAA2B;CAC7D,IAAI,KAAK,UAAU,WAAW,OAAO;CACrC,OAAO,GAAG,KAAK,MAAM,GAAG,SAAS,EAAE,kBAAkB,KAAK,SAAS,UAAU;AAC/E;AAEA,SAAS,oBAAkD,OAAiB;CAC1E,OAAO,MAAM,KAAI,UAAS;EACxB,GAAG;EACH,OAAO,KAAK,QAAQ,aAAa,KAAK,OAAO,gBAAgB,IAAI,KAAK;CACxE,EAAE;AACJ;AAEA,SAAS,aAA2C,OAAwB;CAC1E,IAAI,CAAC,OAAO,OAAO;EAAE;EAAO,cAAc;CAAE;CAC5C,MAAM,YAAY,oBAAoB,KAAK;CAC3C,IAAI,UAAU,UAAU,sBAAsB,OAAO;EAAE,OAAO;EAAW,cAAc;CAAE;CACzF,OAAO;EACL,OAAO,UAAU,MAAM,GAAG,oBAAoB;EAC9C,cAAc,UAAU,SAAS;CACnC;AACF;AAyDA,SAAgB,kCAAkC,EAAE,U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IAAI,SAAS;CACtB,CAAC;CACD,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,OAAO,GAAG,cAAc,OAAY,OAAO;CACtF,OAAO;AACT;;;;;AAMA,SAAgB,gBAAgB,OAAgB,EAAE,QAAQ,6BAAsD,CAAC,GAAG,aAA6C;CAC/J,qBAAqB,OAAO,kCAAkC,OAAO,WAAW;CAChF,OAAO,CAAC,eAAe;AACzB;;;;;AAMA,SAAgB,cAAc,OAAgB,EAAE,QAAQ,6BAAsD,CAAC,GAAG,aAA6C;CAC7J,qBAAqB,OAAO,iCAAiC,OAAO,WAAW;CAC/E,OAAO,CAAC,GAAG,aAAa,gBAAgB;AAC1C;;;;;AAMA,eAAsB,YACpB,UACA,UAAmC,CAAC,GACpC,aAC2B;CAC3B,OAAO,cAAc,UAAU,SAAS,WAAW,CAAC,CAAC,OAAM,UAAS,cAAc,OAAO,SAAS,WAAW,CAAC;AAChH;;;;;AAMA,eAAsB,cACpB,UACA,UAAmC,CAAC,GACpC,aAC2B;CAC3B,OAAO,gBAAgB,UAAU,SAAS,WAAW,CAAC,CAAC,OAAM,UAAS,gBAAgB,OAAO,SAAS,WAAW,CAAC;AACpH;AAEA,SAAgB,eAAe,UAA2C;CACxE,OAAO,kBAAkB,UAAU,WAAW,CAAC,CAAC;AAClD;;AAGA,SAAgB,kBAAkB,UAAmC;CACnE,OAAO,kBAAkB,UAAU,WAAW;AAChD;AAEA,SAAS,YAAY,SAA+B;CAClD,IAAI,OAAO,QAAQ,YAAY,UAAU,OAAO,QAAQ;CACxD,OAAO,QAAQ,QAAQ,SAAQ,SAAQ,KAAK,SAAS,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;AAC3F"}
|
|
1
|
+
{"version":3,"file":"evaluation-DskA4Lzk.mjs","names":["exports"],"sources":["../src/core/model-output.ts","../src/core/evaluation.ts"],"sourcesContent":["const MAX_PATCH_LENGTH = 4000\nconst MAX_CONTENT_LENGTH = 20000\nconst MAX_MODEL_TREE_ENTRIES = 200\nconst MAX_MODEL_DIFF_FILES = 80\n\nfunction truncateText(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text\n return `${text.slice(0, maxLength)}\\n\\n[truncated: ${text.length - maxLength} more characters]`\n}\n\nfunction truncatePatchFields<T extends { patch?: string }>(files: T[]): T[] {\n return files.map(file => ({\n ...file,\n patch: file.patch ? truncateText(file.patch, MAX_PATCH_LENGTH) : file.patch,\n }))\n}\n\nfunction capDiffFiles<T extends { patch?: string }>(files: T[] | undefined) {\n if (!files) return { files, filesOmitted: 0 }\n const truncated = truncatePatchFields(files)\n if (truncated.length <= MAX_MODEL_DIFF_FILES) return { files: truncated, filesOmitted: 0 }\n return {\n files: truncated.slice(0, MAX_MODEL_DIFF_FILES),\n filesOmitted: truncated.length - MAX_MODEL_DIFF_FILES,\n }\n}\n\ntype ToModelOutputOptions = {\n toolCallId: string\n input: unknown\n output: unknown\n}\n\ntype ListPullRequestFile = {\n filename: string\n status: string\n additions: number\n deletions: number\n changes: number\n patch?: string\n}\n\ntype ListPullRequestFilesOutput = {\n items: ListPullRequestFile[]\n hasMore: boolean\n page: number\n perPage: number\n nextPage?: number\n}\n\ntype GetCommitOutput = {\n sha: string\n message: string\n author?: string\n authorLogin?: string\n date?: string\n url: string\n stats: { additions: number, deletions: number, total: number } | null\n files?: Array<{\n filename: string\n status: string\n additions: number\n deletions: number\n patch?: string\n }>\n}\n\ntype GetFileContentOutput =\n | { type: 'directory', entries: Array<{ name: string, type: string, path: string }> }\n | { type: string, path: string }\n | {\n type: 'file'\n path: string\n sha: string\n size: number\n content: string\n totalLines?: number\n startLine?: number\n endLine?: number\n truncated?: boolean\n }\n\nexport function listPullRequestFilesToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as ListPullRequestFilesOutput\n return {\n type: 'json' as const,\n value: {\n ...result,\n items: truncatePatchFields(result.items),\n },\n }\n}\n\nexport function getCommitToModelOutput({ output }: ToModelOutputOptions) {\n const commit = output as GetCommitOutput\n const { files, filesOmitted } = capDiffFiles(commit.files)\n return {\n type: 'json' as const,\n value: {\n ...commit,\n files,\n ...filesOmitted > 0 ? { filesOmitted } : {},\n },\n }\n}\n\ntype CompareCommitsOutput = {\n status: string\n aheadBy: number\n behindBy: number\n totalCommits: number\n url: string\n commits: Array<{ sha: string, message: string, author?: string, authorLogin?: string }>\n files?: Array<{\n filename: string\n status: string\n additions: number\n deletions: number\n patch?: string\n }>\n}\n\nexport function compareCommitsToModelOutput({ output }: ToModelOutputOptions) {\n const comparison = output as CompareCommitsOutput\n const { files, filesOmitted } = capDiffFiles(comparison.files)\n return {\n type: 'json' as const,\n value: {\n ...comparison,\n files,\n ...filesOmitted > 0 ? { filesOmitted } : {},\n },\n }\n}\n\nexport function getFileContentToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as GetFileContentOutput\n if (result.type === 'directory' && 'entries' in result && result.entries.length > MAX_MODEL_TREE_ENTRIES) {\n return {\n type: 'json' as const,\n value: {\n ...result,\n truncated: true,\n entries: result.entries.slice(0, MAX_MODEL_TREE_ENTRIES),\n entriesOmitted: result.entries.length - MAX_MODEL_TREE_ENTRIES,\n },\n }\n }\n if ('content' in result && result.content.length > MAX_CONTENT_LENGTH) {\n return {\n type: 'json' as const,\n value: {\n ...result,\n content: truncateText(result.content, MAX_CONTENT_LENGTH),\n },\n }\n }\n return { type: 'json' as const, value: result }\n}\n\ntype GetRepositoryTreeOutput = {\n sha: string\n truncated: boolean\n path?: string\n entries: Array<{ path?: string, type?: string, size?: number, sha?: string }>\n}\n\nexport function getRepositoryTreeToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as GetRepositoryTreeOutput\n if (result.entries.length <= MAX_MODEL_TREE_ENTRIES) {\n return { type: 'json' as const, value: result }\n }\n return {\n type: 'json' as const,\n value: {\n ...result,\n truncated: true,\n entries: result.entries.slice(0, MAX_MODEL_TREE_ENTRIES),\n entriesOmitted: result.entries.length - MAX_MODEL_TREE_ENTRIES,\n },\n }\n}\n\ntype GetPullRequestContextOutput = {\n pullRequest: {\n number: number\n title: string\n body: string | null\n state: string\n url: string\n author?: string\n branch: string\n headSha: string\n base: string\n draft?: boolean\n merged: boolean\n mergeable: boolean | null\n additions: number\n deletions: number\n changedFiles: number\n createdAt: string\n updatedAt: string\n mergedAt: string | null\n }\n files?: ListPullRequestFile[]\n filesHasMore?: boolean\n reviews?: Array<{\n id: number\n state: string\n body: string\n author?: string\n url: string\n submittedAt?: string | null\n }>\n checks?: {\n checkRuns: {\n totalCount: number\n checkRuns: Array<{\n id: number\n name: string\n status: string\n conclusion: string | null\n url: string | null\n startedAt: string | null\n completedAt: string | null\n }>\n }\n combinedStatus: {\n state: string\n totalCount: number\n statuses: Array<{\n context: string\n state: string\n description: string | null\n url: string | null\n }>\n }\n }\n}\n\nexport function getPullRequestContextToModelOutput({ output }: ToModelOutputOptions) {\n const result = output as GetPullRequestContextOutput\n const { files, filesOmitted } = capDiffFiles(result.files)\n return {\n type: 'json' as const,\n value: {\n ...result,\n files,\n ...filesOmitted > 0 ? { filesOmitted } : {},\n },\n }\n}\n","import * as ai from 'ai'\nimport type { Experimental_EvaluationModel, JSONValue, ModelMessage } from 'ai'\nimport { GITHUB_TOOL_CATALOG } from './catalog'\nimport { githubToolsErrors } from './errors'\nimport { CORE_READ_TOOLS, PRESET_TOOLS } from './presets'\nimport { ALL_GITHUB_TOOL_NAMES, type GithubToolName } from './tool-names'\nimport { DEFAULT_EVALUATION_MODEL, RISK_QUESTION, INTENT_QUESTION, PRESET_PURPOSES, conversationState, rankPresets, requiresApproval, type RoutablePreset } from './evaluation-policy'\nexport { DEFAULT_EVALUATION_MODEL, AUTO_APPROVAL_TOOLS } from './evaluation-policy'\nimport type { GithubWriteToolName } from './write-tools'\n\n/**\n * Tuning for `requireApproval: 'auto'` and `preset: 'auto'`. Every field is optional.\n */\nexport type GithubEvaluationOptions = {\n /**\n * Decision model for AI SDK `experimental_decide`: an AI Gateway ID or a model instance.\n * @default 'typesafe-ai/jev-1.14.0'\n */\n model?: Experimental_EvaluationModel\n /**\n * Provider options passed to every decision call, for example AI Gateway settings such as\n * `{ gateway: { zeroDataRetention: true } }`.\n */\n providerOptions?: Record<string, Record<string, JSONValue>>\n /**\n * Highest risk an `'auto'` tool call can have and still run without approval, on a 0–2 scale\n * (0 negligible, 1 visible but reversible, 2 hard to undo).\n * @default 1\n */\n maxRisk?: number\n /**\n * Lowest probability that the latest user message asked for the call, for it to run without approval.\n * @default 0.6\n */\n minIntent?: number\n /**\n * Lowest probability for `preset: 'auto'` to select a preset. When no preset reaches it,\n * read-only `repo-explorer` is used.\n * @default 0.7\n */\n minPresetProbability?: number\n /**\n * Most presets `preset: 'auto'` combines in one call, keeping the most likely ones.\n * @default 2\n */\n maxPresets?: number\n /**\n * What `preset: 'auto'` picks. `'tools'` asks the decision model about each tool and lists only\n * the likely ones plus the core read tools (`CORE_READ_TOOLS`), so the model sees far fewer tool\n * definitions. The rest stays reachable: eve defers it, and `createGithubAgent` adds a\n * `callGithubTool` tool. `'presets'` lists the tools of up to `maxPresets` presets and, on\n * `createGithubAgent`, uses their system prompts.\n * @default 'tools'\n */\n selection?: 'presets' | 'tools'\n /**\n * How long a `preset: 'auto'` decision lasts. `'session'` decides once, on the conversation's\n * first request, so the listed tools, and the provider's cached prompt prefix they start, stay\n * the same for the rest of the conversation; later needs go through deferred tools (eve) or\n * `callGithubTool` (`createGithubAgent`, which doesn't support it with `selection: 'presets'`).\n * `'turn'` decides again for each new request, which changes the tool list and makes the\n * provider write the whole conversation to its prompt cache again.\n * @default 'session', except `'turn'` for presets on `createGithubAgent`\n */\n scope?: 'turn' | 'session'\n /**\n * Keeps `createGithubAgent`'s `preset: 'auto'` decisions across processes, such as serverless\n * instances, under keys derived from the request and the routing settings (decision model,\n * thresholds and caps), so agents configured differently don't share decisions. Without it, a decision\n * lives in this process's memory, and another process decides again: that costs a decision\n * call, and a different pick changes the tool list and invalidates the provider's prompt cache.\n * The eve extension keeps decisions in the session and ignores this option.\n */\n store?: {\n get: (key: string) => Promise<readonly string[] | undefined>\n set: (key: string, value: readonly string[]) => Promise<void>\n }\n /**\n * Lowest probability for `selection: 'tools'` to list a tool beyond the core read tools.\n * @default 0.5\n */\n minToolProbability?: number\n /**\n * Most tools `selection: 'tools'` lists beyond the core read tools, keeping the most likely ones.\n * @default 8\n */\n maxTools?: number\n}\n\n/**\n * Throws `EVALUATION_UNAVAILABLE` when the installed `ai` has neither `experimental_decide`\n * nor `experimental_evaluate`. Call it where `'auto'` is configured, so a too-old `ai` fails\n * at setup instead of mid-conversation.\n */\nexport function assertEvaluationAvailable() {\n loadDecide()\n}\n\n// `experimental_decide` replaced `experimental_evaluate` in ai 7.0.128; the old name stays an alias.\nfunction loadDecide(): typeof ai.experimental_decide {\n const exports: Partial<Pick<typeof ai, 'experimental_decide' | 'experimental_evaluate'>> = ai\n const decide = exports.experimental_decide ?? exports.experimental_evaluate\n if (!decide) throw githubToolsErrors.EVALUATION_UNAVAILABLE()\n return decide\n}\n\n// `decide` throws when the model refuses any question; the error names the refused questions.\nfunction refusedQuestions(error: unknown): readonly string[] | undefined {\n const exports: Partial<Pick<typeof ai, 'Experimental_DecisionRefusalError'>> = ai\n return exports.Experimental_DecisionRefusalError?.isInstance(error) ? error.questionIds : undefined\n}\n\nfunction warnEvaluationFailed(model: Experimental_EvaluationModel, fallback: string, error: unknown, abortSignal?: AbortSignal) {\n abortSignal?.throwIfAborted()\n const cause = error instanceof Error ? error : new Error(String(error))\n console.warn('[github-tools]', githubToolsErrors.EVALUATION_FAILED({\n model: typeof model === 'string' ? model : model.modelId,\n fallback,\n detail: cause.message,\n cause,\n }))\n}\n\n/** Whether a person should approve a GitHub write, and why, as a short sentence for the approval request. */\nexport type AutoApprovalDecision = { ask: boolean, reason: string }\n\nconst RISK_LABELS = RISK_QUESTION.criteria.map(criterion => criterion.slice(0, criterion.indexOf(':')))\n\n/**\n * Asks the decision model how risky a GitHub write is and whether the user asked for it, and\n * explains the outcome: `ask` is true when a person should approve the call. A failed or refused\n * decision asks, since it gives no evidence that the call is safe.\n */\nexport async function autoApprovalDecision(\n toolName: GithubWriteToolName,\n input: unknown,\n messages: readonly ModelMessage[],\n { model = DEFAULT_EVALUATION_MODEL, maxRisk = 1, minIntent = 0.6, providerOptions }: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<AutoApprovalDecision> {\n const decide = loadDecide()\n let refused = false\n const result = await decide({\n model,\n providerOptions,\n state: {\n ...conversationState(messages, messageText),\n toolCall: {\n tool: toolName,\n description: GITHUB_TOOL_CATALOG[toolName].description,\n input: input as JSONValue,\n },\n },\n questions: {\n risk: { type: 'score', ...RISK_QUESTION },\n intent: { type: 'boolean', ...INTENT_QUESTION },\n },\n abortSignal,\n }).catch((error: unknown) => {\n // A refusal is an answer, not an outage: it gives no evidence the call is safe, so a person decides.\n refused = Boolean(refusedQuestions(error))\n if (!refused) warnEvaluationFailed(model, `asking approval for ${toolName}`, error, abortSignal)\n return undefined\n })\n if (!result) return { ask: true, reason: refused ? 'The decision model declined to rate this call.' : 'The decision model was unavailable.' }\n const risk = result.answers.risk.score\n const intent = result.answers.intent.probability\n // Jev scores risk on a continuous 0–2 scale, so the label is the nearest rubric level.\n const verdict = `${RISK_LABELS[Math.round(risk)]} (risk ${Number(risk.toFixed(1))} of 2), ${Math.round(intent * 100)}% likely you asked for it`\n return requiresApproval(risk, intent, { maxRisk, minIntent })\n ? { ask: true, reason: `${verdict}.` }\n : { ask: false, reason: `Approved automatically: ${verdict.charAt(0).toLowerCase()}${verdict.slice(1)}.` }\n}\n\n/** Whether a GitHub write needs a person's approval; see {@link autoApprovalDecision}. */\nexport async function needsAutoApproval(\n toolName: GithubWriteToolName,\n input: unknown,\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<boolean> {\n return (await autoApprovalDecision(toolName, input, messages, options, abortSignal)).ask\n}\n\n/**\n * Presets the latest user message needs, from one evaluation call with an independent\n * yes/no question per preset. Returns up to `maxPresets` presets at or above\n * `minPresetProbability`, most likely first, and read-only `repo-explorer` when none qualifies.\n * `repo-explorer` is only combined with no other preset. Rejects when the evaluation call fails;\n * {@link selectPresets} falls back instead. Never returns `maintainer`, so the full catalog is never exposed.\n */\nexport async function evaluatePresets(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<RoutablePreset[]> {\n const { minPresetProbability = 0.7, maxPresets = 2 } = options\n const presets = Object.keys(PRESET_PURPOSES) as RoutablePreset[]\n const probabilities = await decideEach(messages, presets, preset => ({\n instructions: 'Does handling this GitHub request need the tools of this preset?',\n criteria: { true: { purpose: PRESET_PURPOSES[preset], tools: [...PRESET_TOOLS[preset]] } },\n }), options, abortSignal)\n return rankPresets(probabilities, { minPresetProbability, maxPresets })\n}\n\n/**\n * Tools the latest user message needs, from one decision call with a yes/no question per tool:\n * the core read tools, plus up to `maxTools` others at or above `minToolProbability`, most likely\n * first. Rejects when the decision call fails; {@link selectTools} falls back instead.\n */\nexport async function evaluateTools(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<GithubToolName[]> {\n const { minToolProbability = 0.5, maxTools = 8 } = options\n const core: readonly GithubToolName[] = CORE_READ_TOOLS\n const candidates = ALL_GITHUB_TOOL_NAMES.filter(name => !core.includes(name))\n const probabilities = await decideEach(messages, candidates, name => ({\n instructions: 'Does handling this GitHub request need this tool?',\n criteria: { true: { tool: name, description: GITHUB_TOOL_CATALOG[name].description } },\n }), options, abortSignal)\n const likely = candidates\n .filter(name => probabilities[name] >= minToolProbability)\n .toSorted((a, b) => probabilities[b] - probabilities[a])\n .slice(0, maxTools)\n return [...core, ...likely]\n}\n\ntype BooleanQuestion = { instructions: string, criteria: { true: Record<string, JSONValue> } }\n\n// One boolean question per key against the conversation. A refused question counts as a no:\n// ask once more without it instead of losing every answer.\nasync function decideEach<K extends string>(\n messages: readonly ModelMessage[],\n keys: readonly K[],\n question: (key: K) => BooleanQuestion,\n { model = DEFAULT_EVALUATION_MODEL, providerOptions }: GithubEvaluationOptions,\n abortSignal?: AbortSignal,\n): Promise<Record<K, number>> {\n const decide = loadDecide()\n const state = conversationState(messages, messageText)\n const ask = (asked: readonly K[]) => decide({\n model,\n providerOptions,\n state,\n questions: Object.fromEntries(asked.map(key => [key, { type: 'boolean' as const, ...question(key) }])),\n abortSignal,\n })\n const probabilities = Object.fromEntries(keys.map(key => [key, 0])) as Record<K, number>\n const { answers } = await ask(keys).catch((error: unknown) => {\n const refused = refusedQuestions(error)\n const remaining = keys.filter(key => !refused?.includes(key))\n if (!refused || remaining.length === 0) throw error\n return ask(remaining)\n })\n for (const [key, answer] of Object.entries(answers)) probabilities[key as K] = answer.probability\n return probabilities\n}\n\n/**\n * Logs `EVALUATION_FAILED` for a failed {@link evaluatePresets} call and returns the read-only\n * `repo-explorer` fallback. Rethrows when `abortSignal` is aborted.\n */\nexport function fallbackPresets(error: unknown, { model = DEFAULT_EVALUATION_MODEL }: GithubEvaluationOptions = {}, abortSignal?: AbortSignal): RoutablePreset[] {\n warnEvaluationFailed(model, 'using the repo-explorer preset', error, abortSignal)\n return ['repo-explorer']\n}\n\n/**\n * Logs `EVALUATION_FAILED` for a failed {@link evaluateTools} call and returns the read-only\n * `repo-explorer` tools. Rethrows when `abortSignal` is aborted.\n */\nexport function fallbackTools(error: unknown, { model = DEFAULT_EVALUATION_MODEL }: GithubEvaluationOptions = {}, abortSignal?: AbortSignal): GithubToolName[] {\n warnEvaluationFailed(model, 'using the repo-explorer tools', error, abortSignal)\n return [...PRESET_TOOLS['repo-explorer']]\n}\n\n/**\n * {@link evaluateTools}, falling back to the read-only `repo-explorer` tools (and logging\n * `EVALUATION_FAILED`) when the decision call fails.\n */\nexport async function selectTools(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<GithubToolName[]> {\n return evaluateTools(messages, options, abortSignal).catch(error => fallbackTools(error, options, abortSignal))\n}\n\n/**\n * {@link evaluatePresets}, falling back to read-only `repo-explorer` (and logging\n * `EVALUATION_FAILED`) when the evaluation call fails.\n */\nexport async function selectPresets(\n messages: readonly ModelMessage[],\n options: GithubEvaluationOptions = {},\n abortSignal?: AbortSignal,\n): Promise<RoutablePreset[]> {\n return evaluatePresets(messages, options, abortSignal).catch(error => fallbackPresets(error, options, abortSignal))\n}\n\nexport function latestUserText(messages: readonly ModelMessage[]): string {\n return conversationState(messages, messageText).request\n}\n\n/** The `request` and `repliedTo` the evaluation model sees for these messages. */\nexport function evaluationRequest(messages: readonly ModelMessage[]) {\n return conversationState(messages, messageText)\n}\n\nfunction messageText(message: ModelMessage): string {\n if (typeof message.content === 'string') return message.content\n return message.content.flatMap(part => part.type === 'text' ? [part.text] : []).join('\\n')\n}\n"],"mappings":";;;AAAA,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAC3B,MAAM,yBAAyB;AAC/B,MAAM,uBAAuB;AAE7B,SAAS,aAAa,MAAc,WAA2B;CAC7D,IAAI,KAAK,UAAU,WAAW,OAAO;CACrC,OAAO,GAAG,KAAK,MAAM,GAAG,SAAS,EAAE,kBAAkB,KAAK,SAAS,UAAU;AAC/E;AAEA,SAAS,oBAAkD,OAAiB;CAC1E,OAAO,MAAM,KAAI,UAAS;EACxB,GAAG;EACH,OAAO,KAAK,QAAQ,aAAa,KAAK,OAAO,gBAAgB,IAAI,KAAK;CACxE,EAAE;AACJ;AAEA,SAAS,aAA2C,OAAwB;CAC1E,IAAI,CAAC,OAAO,OAAO;EAAE;EAAO,cAAc;CAAE;CAC5C,MAAM,YAAY,oBAAoB,KAAK;CAC3C,IAAI,UAAU,UAAU,sBAAsB,OAAO;EAAE,OAAO;EAAW,cAAc;CAAE;CACzF,OAAO;EACL,OAAO,UAAU,MAAM,GAAG,oBAAoB;EAC9C,cAAc,UAAU,SAAS;CACnC;AACF;AAyDA,SAAgB,kCAAkC,EAAE,UAAgC;CA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