@github-tools/sdk 1.19.0 → 1.21.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 +97 -30
- package/dist/approval-policy-CEMMPq92.mjs +17 -0
- package/dist/approval-policy-CEMMPq92.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-meFAMt2D.mjs} +41 -2
- package/dist/cores-meFAMt2D.mjs.map +1 -0
- package/dist/{tool-types-CrC80SIL.d.mts → dry-run-DXckOam2.d.mts} +437 -54
- package/dist/dry-run-DXckOam2.d.mts.map +1 -0
- package/dist/evaluation-DJHINyAu.mjs +311 -0
- package/dist/evaluation-DJHINyAu.mjs.map +1 -0
- package/dist/{eve-runtime-DRh2QJI7.d.mts → eve-runtime-B_CJE9JV.d.mts} +21 -7
- package/dist/eve-runtime-B_CJE9JV.d.mts.map +1 -0
- package/dist/{eve-runtime-YTxfrWP-.mjs → eve-runtime-DPzMPCLt.mjs} +49 -15
- package/dist/eve-runtime-DPzMPCLt.mjs.map +1 -0
- package/dist/eve-runtime.d.mts +5 -5
- package/dist/eve-runtime.mjs +4 -4
- package/dist/eve.d.mts +95 -4
- package/dist/eve.d.mts.map +1 -1
- package/dist/eve.mjs +94 -3
- package/dist/eve.mjs.map +1 -1
- package/dist/{index-DkZvveZP.d.mts → index-CzzrtCVj.d.mts} +119 -348
- package/dist/index-CzzrtCVj.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-BlhrSieS.mjs} +491 -23
- package/dist/src-BlhrSieS.mjs.map +1 -0
- package/dist/tanstack/interrupts.d.mts +1 -1
- package/dist/tanstack.d.mts +1705 -204
- package/dist/tanstack.d.mts.map +1 -1
- package/dist/tanstack.mjs +53 -19
- package/dist/tanstack.mjs.map +1 -1
- package/dist/{token-Bh8nPj66.mjs → token-BLps09gm.mjs} +36 -116
- package/dist/token-BLps09gm.mjs.map +1 -0
- package/dist/{types-BmwOpI5-.d.mts → types-Bln8U42J.d.mts} +3 -3
- package/dist/{types-BmwOpI5-.d.mts.map → types-Bln8U42J.d.mts.map} +1 -1
- package/dist/{types-CPAsEMzx.d.mts → types-C7O2lwwz.d.mts} +14 -2
- package/dist/{types-CPAsEMzx.d.mts.map → types-C7O2lwwz.d.mts.map} +1 -1
- package/dist/workflow.d.mts +41 -40
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +20 -47
- package/dist/workflow.mjs.map +1 -1
- package/dist/{write-tools-BaoTUCg7.mjs → write-tools-w-8tjnDQ.mjs} +1360 -124
- package/dist/write-tools-w-8tjnDQ.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-DRh2QJI7.d.mts.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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dry-run-DXckOam2.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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;;;;;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"}
|
|
@@ -0,0 +1,311 @@
|
|
|
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-w-8tjnDQ.mjs";
|
|
2
|
+
import * as ai from "ai";
|
|
3
|
+
//#region src/core/model-output.ts
|
|
4
|
+
const MAX_PATCH_LENGTH = 4e3;
|
|
5
|
+
const MAX_CONTENT_LENGTH = 2e4;
|
|
6
|
+
const MAX_MODEL_TREE_ENTRIES = 200;
|
|
7
|
+
const MAX_MODEL_DIFF_FILES = 80;
|
|
8
|
+
function truncateText(text, maxLength) {
|
|
9
|
+
if (text.length <= maxLength) return text;
|
|
10
|
+
return `${text.slice(0, maxLength)}\n\n[truncated: ${text.length - maxLength} more characters]`;
|
|
11
|
+
}
|
|
12
|
+
function truncatePatchFields(files) {
|
|
13
|
+
return files.map((file) => ({
|
|
14
|
+
...file,
|
|
15
|
+
patch: file.patch ? truncateText(file.patch, MAX_PATCH_LENGTH) : file.patch
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
function capDiffFiles(files) {
|
|
19
|
+
if (!files) return {
|
|
20
|
+
files,
|
|
21
|
+
filesOmitted: 0
|
|
22
|
+
};
|
|
23
|
+
const truncated = truncatePatchFields(files);
|
|
24
|
+
if (truncated.length <= MAX_MODEL_DIFF_FILES) return {
|
|
25
|
+
files: truncated,
|
|
26
|
+
filesOmitted: 0
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
files: truncated.slice(0, MAX_MODEL_DIFF_FILES),
|
|
30
|
+
filesOmitted: truncated.length - MAX_MODEL_DIFF_FILES
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function listPullRequestFilesToModelOutput({ output }) {
|
|
34
|
+
const result = output;
|
|
35
|
+
return {
|
|
36
|
+
type: "json",
|
|
37
|
+
value: {
|
|
38
|
+
...result,
|
|
39
|
+
items: truncatePatchFields(result.items)
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getCommitToModelOutput({ output }) {
|
|
44
|
+
const commit = output;
|
|
45
|
+
const { files, filesOmitted } = capDiffFiles(commit.files);
|
|
46
|
+
return {
|
|
47
|
+
type: "json",
|
|
48
|
+
value: {
|
|
49
|
+
...commit,
|
|
50
|
+
files,
|
|
51
|
+
...filesOmitted > 0 ? { filesOmitted } : {}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function compareCommitsToModelOutput({ output }) {
|
|
56
|
+
const comparison = output;
|
|
57
|
+
const { files, filesOmitted } = capDiffFiles(comparison.files);
|
|
58
|
+
return {
|
|
59
|
+
type: "json",
|
|
60
|
+
value: {
|
|
61
|
+
...comparison,
|
|
62
|
+
files,
|
|
63
|
+
...filesOmitted > 0 ? { filesOmitted } : {}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getFileContentToModelOutput({ output }) {
|
|
68
|
+
const result = output;
|
|
69
|
+
if (result.type === "directory" && "entries" in result && result.entries.length > MAX_MODEL_TREE_ENTRIES) return {
|
|
70
|
+
type: "json",
|
|
71
|
+
value: {
|
|
72
|
+
...result,
|
|
73
|
+
truncated: true,
|
|
74
|
+
entries: result.entries.slice(0, MAX_MODEL_TREE_ENTRIES),
|
|
75
|
+
entriesOmitted: result.entries.length - MAX_MODEL_TREE_ENTRIES
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if ("content" in result && result.content.length > MAX_CONTENT_LENGTH) return {
|
|
79
|
+
type: "json",
|
|
80
|
+
value: {
|
|
81
|
+
...result,
|
|
82
|
+
content: truncateText(result.content, MAX_CONTENT_LENGTH)
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
type: "json",
|
|
87
|
+
value: result
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function getRepositoryTreeToModelOutput({ output }) {
|
|
91
|
+
const result = output;
|
|
92
|
+
if (result.entries.length <= MAX_MODEL_TREE_ENTRIES) return {
|
|
93
|
+
type: "json",
|
|
94
|
+
value: result
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
type: "json",
|
|
98
|
+
value: {
|
|
99
|
+
...result,
|
|
100
|
+
truncated: true,
|
|
101
|
+
entries: result.entries.slice(0, MAX_MODEL_TREE_ENTRIES),
|
|
102
|
+
entriesOmitted: result.entries.length - MAX_MODEL_TREE_ENTRIES
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function getPullRequestContextToModelOutput({ output }) {
|
|
107
|
+
const result = output;
|
|
108
|
+
const { files, filesOmitted } = capDiffFiles(result.files);
|
|
109
|
+
return {
|
|
110
|
+
type: "json",
|
|
111
|
+
value: {
|
|
112
|
+
...result,
|
|
113
|
+
files,
|
|
114
|
+
...filesOmitted > 0 ? { filesOmitted } : {}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/core/evaluation.ts
|
|
120
|
+
/**
|
|
121
|
+
* Throws `EVALUATION_UNAVAILABLE` when the installed `ai` has neither `experimental_decide`
|
|
122
|
+
* nor `experimental_evaluate`. Call it where `'auto'` is configured, so a too-old `ai` fails
|
|
123
|
+
* at setup instead of mid-conversation.
|
|
124
|
+
*/
|
|
125
|
+
function assertEvaluationAvailable() {
|
|
126
|
+
loadDecide();
|
|
127
|
+
}
|
|
128
|
+
function loadDecide() {
|
|
129
|
+
const exports = ai;
|
|
130
|
+
const decide = exports.experimental_decide ?? exports.experimental_evaluate;
|
|
131
|
+
if (!decide) throw githubToolsErrors.EVALUATION_UNAVAILABLE();
|
|
132
|
+
return decide;
|
|
133
|
+
}
|
|
134
|
+
function refusedQuestions(error) {
|
|
135
|
+
return ai.Experimental_DecisionRefusalError?.isInstance(error) ? error.questionIds : void 0;
|
|
136
|
+
}
|
|
137
|
+
function warnEvaluationFailed(model, fallback, error, abortSignal) {
|
|
138
|
+
abortSignal?.throwIfAborted();
|
|
139
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
140
|
+
console.warn("[github-tools]", githubToolsErrors.EVALUATION_FAILED({
|
|
141
|
+
model: typeof model === "string" ? model : model.modelId,
|
|
142
|
+
fallback,
|
|
143
|
+
detail: cause.message,
|
|
144
|
+
cause
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
const RISK_LABELS = RISK_QUESTION.criteria.map((criterion) => criterion.slice(0, criterion.indexOf(":")));
|
|
148
|
+
/**
|
|
149
|
+
* Asks the decision model how risky a GitHub write is and whether the user asked for it, and
|
|
150
|
+
* explains the outcome: `ask` is true when a person should approve the call. A failed or refused
|
|
151
|
+
* decision asks, since it gives no evidence that the call is safe.
|
|
152
|
+
*/
|
|
153
|
+
async function autoApprovalDecision(toolName, input, messages, { model = DEFAULT_EVALUATION_MODEL, maxRisk = 1, minIntent = .6, providerOptions } = {}, abortSignal) {
|
|
154
|
+
const decide = loadDecide();
|
|
155
|
+
let refused = false;
|
|
156
|
+
const result = await decide({
|
|
157
|
+
model,
|
|
158
|
+
providerOptions,
|
|
159
|
+
state: {
|
|
160
|
+
...conversationState(messages, messageText),
|
|
161
|
+
toolCall: {
|
|
162
|
+
tool: toolName,
|
|
163
|
+
description: GITHUB_TOOL_CATALOG[toolName].description,
|
|
164
|
+
input
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
questions: {
|
|
168
|
+
risk: {
|
|
169
|
+
type: "score",
|
|
170
|
+
...RISK_QUESTION
|
|
171
|
+
},
|
|
172
|
+
intent: {
|
|
173
|
+
type: "boolean",
|
|
174
|
+
...INTENT_QUESTION
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
abortSignal
|
|
178
|
+
}).catch((error) => {
|
|
179
|
+
refused = Boolean(refusedQuestions(error));
|
|
180
|
+
if (!refused) warnEvaluationFailed(model, `asking approval for ${toolName}`, error, abortSignal);
|
|
181
|
+
});
|
|
182
|
+
if (!result) return {
|
|
183
|
+
ask: true,
|
|
184
|
+
reason: refused ? "The decision model declined to rate this call." : "The decision model was unavailable."
|
|
185
|
+
};
|
|
186
|
+
const risk = result.answers.risk.score;
|
|
187
|
+
const intent = result.answers.intent.probability;
|
|
188
|
+
const verdict = `${RISK_LABELS[Math.round(risk)]} (risk ${Number(risk.toFixed(1))} of 2), ${Math.round(intent * 100)}% likely you asked for it`;
|
|
189
|
+
return requiresApproval(risk, intent, {
|
|
190
|
+
maxRisk,
|
|
191
|
+
minIntent
|
|
192
|
+
}) ? {
|
|
193
|
+
ask: true,
|
|
194
|
+
reason: `${verdict}.`
|
|
195
|
+
} : {
|
|
196
|
+
ask: false,
|
|
197
|
+
reason: `Approved automatically: ${verdict.charAt(0).toLowerCase()}${verdict.slice(1)}.`
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** Whether a GitHub write needs a person's approval; see {@link autoApprovalDecision}. */
|
|
201
|
+
async function needsAutoApproval(toolName, input, messages, options = {}, abortSignal) {
|
|
202
|
+
return (await autoApprovalDecision(toolName, input, messages, options, abortSignal)).ask;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Presets the latest user message needs, from one evaluation call with an independent
|
|
206
|
+
* yes/no question per preset. Returns up to `maxPresets` presets at or above
|
|
207
|
+
* `minPresetProbability`, most likely first, and read-only `repo-explorer` when none qualifies.
|
|
208
|
+
* `repo-explorer` is only combined with no other preset. Rejects when the evaluation call fails;
|
|
209
|
+
* {@link selectPresets} falls back instead. Never returns `maintainer`, so the full catalog is never exposed.
|
|
210
|
+
*/
|
|
211
|
+
async function evaluatePresets(messages, options = {}, abortSignal) {
|
|
212
|
+
const { minPresetProbability = .7, maxPresets = 2 } = options;
|
|
213
|
+
const probabilities = await decideEach(messages, Object.keys(PRESET_PURPOSES), (preset) => ({
|
|
214
|
+
instructions: "Does handling this GitHub request need the tools of this preset?",
|
|
215
|
+
criteria: { true: {
|
|
216
|
+
purpose: PRESET_PURPOSES[preset],
|
|
217
|
+
tools: [...PRESET_TOOLS[preset]]
|
|
218
|
+
} }
|
|
219
|
+
}), options, abortSignal);
|
|
220
|
+
return rankPresets(probabilities, {
|
|
221
|
+
minPresetProbability,
|
|
222
|
+
maxPresets
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Tools the latest user message needs, from one decision call with a yes/no question per tool:
|
|
227
|
+
* the core read tools, plus up to `maxTools` others at or above `minToolProbability`, most likely
|
|
228
|
+
* first. Rejects when the decision call fails; {@link selectTools} falls back instead.
|
|
229
|
+
*/
|
|
230
|
+
async function evaluateTools(messages, options = {}, abortSignal) {
|
|
231
|
+
const { minToolProbability = .5, maxTools = 8 } = options;
|
|
232
|
+
const core = CORE_READ_TOOLS;
|
|
233
|
+
const candidates = ALL_GITHUB_TOOL_NAMES.filter((name) => !core.includes(name));
|
|
234
|
+
const probabilities = await decideEach(messages, candidates, (name) => ({
|
|
235
|
+
instructions: "Does handling this GitHub request need this tool?",
|
|
236
|
+
criteria: { true: {
|
|
237
|
+
tool: name,
|
|
238
|
+
description: GITHUB_TOOL_CATALOG[name].description
|
|
239
|
+
} }
|
|
240
|
+
}), options, abortSignal);
|
|
241
|
+
const likely = candidates.filter((name) => probabilities[name] >= minToolProbability).toSorted((a, b) => probabilities[b] - probabilities[a]).slice(0, maxTools);
|
|
242
|
+
return [...core, ...likely];
|
|
243
|
+
}
|
|
244
|
+
async function decideEach(messages, keys, question, { model = DEFAULT_EVALUATION_MODEL, providerOptions }, abortSignal) {
|
|
245
|
+
const decide = loadDecide();
|
|
246
|
+
const state = conversationState(messages, messageText);
|
|
247
|
+
const ask = (asked) => decide({
|
|
248
|
+
model,
|
|
249
|
+
providerOptions,
|
|
250
|
+
state,
|
|
251
|
+
questions: Object.fromEntries(asked.map((key) => [key, {
|
|
252
|
+
type: "boolean",
|
|
253
|
+
...question(key)
|
|
254
|
+
}])),
|
|
255
|
+
abortSignal
|
|
256
|
+
});
|
|
257
|
+
const probabilities = Object.fromEntries(keys.map((key) => [key, 0]));
|
|
258
|
+
const { answers } = await ask(keys).catch((error) => {
|
|
259
|
+
const refused = refusedQuestions(error);
|
|
260
|
+
const remaining = keys.filter((key) => !refused?.includes(key));
|
|
261
|
+
if (!refused || remaining.length === 0) throw error;
|
|
262
|
+
return ask(remaining);
|
|
263
|
+
});
|
|
264
|
+
for (const [key, answer] of Object.entries(answers)) probabilities[key] = answer.probability;
|
|
265
|
+
return probabilities;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Logs `EVALUATION_FAILED` for a failed {@link evaluatePresets} call and returns the read-only
|
|
269
|
+
* `repo-explorer` fallback. Rethrows when `abortSignal` is aborted.
|
|
270
|
+
*/
|
|
271
|
+
function fallbackPresets(error, { model = DEFAULT_EVALUATION_MODEL } = {}, abortSignal) {
|
|
272
|
+
warnEvaluationFailed(model, "using the repo-explorer preset", error, abortSignal);
|
|
273
|
+
return ["repo-explorer"];
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Logs `EVALUATION_FAILED` for a failed {@link evaluateTools} call and returns the read-only
|
|
277
|
+
* `repo-explorer` tools. Rethrows when `abortSignal` is aborted.
|
|
278
|
+
*/
|
|
279
|
+
function fallbackTools(error, { model = DEFAULT_EVALUATION_MODEL } = {}, abortSignal) {
|
|
280
|
+
warnEvaluationFailed(model, "using the repo-explorer tools", error, abortSignal);
|
|
281
|
+
return [...PRESET_TOOLS["repo-explorer"]];
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* {@link evaluateTools}, falling back to the read-only `repo-explorer` tools (and logging
|
|
285
|
+
* `EVALUATION_FAILED`) when the decision call fails.
|
|
286
|
+
*/
|
|
287
|
+
async function selectTools(messages, options = {}, abortSignal) {
|
|
288
|
+
return evaluateTools(messages, options, abortSignal).catch((error) => fallbackTools(error, options, abortSignal));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* {@link evaluatePresets}, falling back to read-only `repo-explorer` (and logging
|
|
292
|
+
* `EVALUATION_FAILED`) when the evaluation call fails.
|
|
293
|
+
*/
|
|
294
|
+
async function selectPresets(messages, options = {}, abortSignal) {
|
|
295
|
+
return evaluatePresets(messages, options, abortSignal).catch((error) => fallbackPresets(error, options, abortSignal));
|
|
296
|
+
}
|
|
297
|
+
function latestUserText(messages) {
|
|
298
|
+
return conversationState(messages, messageText).request;
|
|
299
|
+
}
|
|
300
|
+
/** The `request` and `repliedTo` the evaluation model sees for these messages. */
|
|
301
|
+
function evaluationRequest(messages) {
|
|
302
|
+
return conversationState(messages, messageText);
|
|
303
|
+
}
|
|
304
|
+
function messageText(message) {
|
|
305
|
+
if (typeof message.content === "string") return message.content;
|
|
306
|
+
return message.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n");
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
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
|
+
|
|
311
|
+
//# sourceMappingURL=evaluation-DJHINyAu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation-DJHINyAu.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,SA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;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,10 +1,20 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { G as GithubWriteToolName, I as GithubGuardrails, N as GithubTokenInput, R as CombinedPresetToolNames, V as PresetToolName, W as GithubToolName, c as CommitIdentity, s as GithubToolsContext, t as GithubDryRunApproval, z as GithubToolPreset } from "./dry-run-DXckOam2.mjs";
|
|
2
|
+
import { i as EveToolFactoryOptions, n as EveApprovalValue, r as EveGithubToolsOptions, t as EveApprovalConfig } from "./types-C7O2lwwz.mjs";
|
|
3
|
+
import "./index-CzzrtCVj.mjs";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { ToolDefinition, ToolModelOutput } from "eve/tools";
|
|
6
6
|
import { Approval, ApprovalPolicy } from "eve/tools/approval";
|
|
7
7
|
//#region src/eve/registry.d.ts
|
|
8
|
+
type ToolBuildContext = {
|
|
9
|
+
token: GithubTokenInput;
|
|
10
|
+
context?: GithubToolsContext;
|
|
11
|
+
author?: CommitIdentity;
|
|
12
|
+
committer?: CommitIdentity;
|
|
13
|
+
coAuthors?: CommitIdentity[];
|
|
14
|
+
guardrails?: GithubGuardrails;
|
|
15
|
+
dryRun?: boolean;
|
|
16
|
+
dryRunApproval?: GithubDryRunApproval;
|
|
17
|
+
};
|
|
8
18
|
/** Whether a GitHub tool has a built-in eve `toModelOutput` projection. */
|
|
9
19
|
declare function hasGithubEveToolModelOutput(name: GithubToolName): boolean;
|
|
10
20
|
/**
|
|
@@ -22,7 +32,7 @@ type BuildOptions = EveGithubToolsOptions | (EveToolFactoryOptions & {
|
|
|
22
32
|
type EveToolMap = Partial<Record<GithubToolName, ToolDefinition>>;
|
|
23
33
|
declare function buildEveToolDefinition(name: GithubToolName, options?: BuildOptions): ToolDefinition;
|
|
24
34
|
declare function buildEveToolMap(options?: EveGithubToolsOptions): EveToolMap;
|
|
25
|
-
declare function createEveGithubToolsDynamic(options?: EveGithubToolsOptions): import("eve").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve").DynamicContext>;
|
|
35
|
+
declare function createEveGithubToolsDynamic(options?: EveGithubToolsOptions): import("eve/tools").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve/tools").DynamicContext>;
|
|
26
36
|
declare function listResolvedEveToolNames(options?: {
|
|
27
37
|
preset?: undefined;
|
|
28
38
|
include?: undefined;
|
|
@@ -44,7 +54,7 @@ declare function listResolvedEveToolNames(options: Pick<EveGithubToolsOptions, '
|
|
|
44
54
|
* Prefer this when registering tools outside the SDK package so durable transforms can hoist inline execute.
|
|
45
55
|
*/
|
|
46
56
|
declare function listEveToolDescriptors(options?: EveGithubToolsOptions): {
|
|
47
|
-
name: "
|
|
57
|
+
name: "getRepository" | "listBranches" | "getFileContent" | "getRepositoryTree" | "createBranch" | "deleteBranch" | "forkRepository" | "createRepository" | "createOrUpdateFile" | "getBranchRules" | "getCollaboratorPermission" | "editFiles" | "listPullRequests" | "getPullRequest" | "createPullRequest" | "mergePullRequest" | "enablePullRequestAutoMerge" | "disablePullRequestAutoMerge" | "updatePullRequest" | "updatePullRequestBranch" | "addPullRequestComment" | "updatePullRequestComment" | "deletePullRequestComment" | "listPullRequestFiles" | "listPullRequestReviews" | "createPullRequestReview" | "listPullRequestReviewThreads" | "replyToReviewComment" | "resolveReviewThread" | "requestReviewers" | "getPullRequestContext" | "getIssueContext" | "listIssues" | "getIssue" | "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" | "searchCode" | "searchRepositories" | "searchIssues" | "listCommits" | "getCommit" | "getBlame" | "compareCommits" | "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";
|
|
48
58
|
description: string;
|
|
49
59
|
inputSchema: import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
|
|
50
60
|
writeTool: GithubWriteToolName | undefined;
|
|
@@ -72,6 +82,10 @@ declare function resolveEveApproval(toolName: GithubWriteToolName, config: EveAp
|
|
|
72
82
|
*/
|
|
73
83
|
declare function resolveEveToolApproval(toolName: GithubWriteToolName, config: EveApprovalConfig | undefined, override?: EveApprovalValue): Approval | undefined;
|
|
74
84
|
//#endregion
|
|
85
|
+
//#region src/eve/steps.d.ts
|
|
86
|
+
/** Why `guardrails` block a call once `context` defaults are applied, or `undefined` when they allow it. */
|
|
87
|
+
declare function githubGuardrailViolation(name: GithubToolName, input: Record<string, unknown>, { context, guardrails }: Pick<ToolBuildContext, 'context' | 'guardrails'>): string | undefined;
|
|
88
|
+
//#endregion
|
|
75
89
|
//#region src/eve/load-eve.d.ts
|
|
76
90
|
/**
|
|
77
91
|
* @deprecated Never thrown since eve moved to static ESM imports — a missing
|
|
@@ -81,5 +95,5 @@ declare function resolveEveToolApproval(toolName: GithubWriteToolName, config: E
|
|
|
81
95
|
*/
|
|
82
96
|
declare const MISSING_EVE_MESSAGE = "The \"eve\" package is required to use @github-tools/sdk/eve. Install it with: pnpm add eve";
|
|
83
97
|
//#endregion
|
|
84
|
-
export {
|
|
85
|
-
//# sourceMappingURL=eve-runtime-
|
|
98
|
+
export { resolveEveApproval as a, buildEveToolMap as c, listEveToolDescriptors as d, listResolvedEveToolNames as f, mapEveApprovalValue as i, createEveGithubToolsDynamic as l, hasGithubEveToolModelOutput as m, githubGuardrailViolation as n, resolveEveToolApproval as o, formatGithubEveToolOutput as p, isEveApprovalDisabled as r, buildEveToolDefinition as s, MISSING_EVE_MESSAGE as t, executeGithubEveTool as u };
|
|
99
|
+
//# sourceMappingURL=eve-runtime-B_CJE9JV.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eve-runtime-B_CJE9JV.d.mts","names":[],"sources":["../src/eve/registry.ts","../src/eve/build.ts","../src/eve/approval.ts","../src/eve/steps.ts","../src/eve/load-eve.ts"],"mappings":";;;;;;;KAuBY;EACV,OAAO;EACP,UAAU;EACV,SAAS;EACT,YAAY;EACZ,YAAY;EACZ,aAAa;EACb;EACA,iBAAiB;;;iBA6CH,4BAA4B,MAAM;;;;;;;iBAUlC,0BAA0B,MAAM,gBAAgB,kBAAkB;;;KC7E7E,eAAe,yBAAyB;EAA0B,SAAS;;KAC3E,aAAa,QAAQ,OAAO,gBAAgB;iBA8CjC,uBACd,MAAM,gBACN,UAAS,eACR;iBAmCa,gBAAgB,UAAS,wBAA6B;iBAsCtD,4BAA4B,UAAS,4CAA0B,oCAAA,uCAAA;iBAQ/D,yBAAyB;EAAY;EAAoB;EAAqB;IAAwB;iBACtG,yBAAyB,UAAU,kBAAkB;EAAW,QAAQ;EAAG;EAAqB;IAAwB,eAAe;iBACvI,yBAAyB,mBAAmB,oBAAoB;EAAW,QAAQ;EAAG;EAAqB;IAAwB,wBAAwB;iBAC3J,yBAAyB,SAAS,KAAK,2DAA2D;;;;;iBAUlG,uBAAuB,UAAS;;;;aAAA;;;;;;;iBA6B1B,qBACpB,MAAM,gBACN,OAAO,yBACP,UAAS,wBAA0B;;;;;;;;iBC/KrB,sBAAsB,OAAO;iBAI7B,oBAAoB,OAAO,mBAAmB;iBAY9C,mBACd,UAAU,qBACV,QAAQ,gCACP;;;;;;iBAgBa,uBACd,UAAU,qBACV,QAAQ,+BACR,WAAW,mBACV;;;;iBC3Ba,yBACd,MAAM,gBACN,OAAO,2BACL,SAAS,cAAc,KAAK;;;;;;;;;cCRnB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as GITHUB_TOOL_CORES } from "./cores-
|
|
1
|
+
import { $a as stripRateLimit, E as isGithubWriteToolName, Qa as toModelErrorPayload, S as resolveGithubToken, T as GITHUB_TOOL_CATALOG, Xa as EvlogError, Za as githubToolsErrors, b as createGithubTokenResolver, i as dryRunWrite, o as mergeContextArgs, s as softenContextSchema, w as ALL_GITHUB_TOOL_NAMES, x as githubTokenCall, y as resolvePresetTools, zr as guardrailViolation } from "./write-tools-w-8tjnDQ.mjs";
|
|
2
|
+
import { _ as listPullRequestFilesToModelOutput, f as compareCommitsToModelOutput, g as getRepositoryTreeToModelOutput, h as getPullRequestContextToModelOutput, m as getFileContentToModelOutput, p as getCommitToModelOutput } from "./evaluation-DJHINyAu.mjs";
|
|
3
|
+
import { t as GITHUB_TOOL_CORES } from "./cores-meFAMt2D.mjs";
|
|
4
4
|
import * as eveTools from "eve/tools";
|
|
5
5
|
import * as eveApproval from "eve/tools/approval";
|
|
6
6
|
//#region src/eve/load-eve.ts
|
|
@@ -57,11 +57,12 @@ function resolveEveToolApproval(toolName, config, override) {
|
|
|
57
57
|
}
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region src/eve/registry.ts
|
|
60
|
-
function withToken(core, ctx, extra) {
|
|
60
|
+
function withToken(core, ctx, extra, guard) {
|
|
61
61
|
return async (input) => core({
|
|
62
62
|
token: await resolveGithubToken(ctx.token),
|
|
63
63
|
...extra,
|
|
64
|
-
...mergeContextArgs(input, ctx.context ?? {})
|
|
64
|
+
...mergeContextArgs(input, ctx.context ?? {}),
|
|
65
|
+
...guard
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
function modelOutputAdapter(fn) {
|
|
@@ -115,7 +116,21 @@ function createToolRegistry(ctx, names = ALL_GITHUB_TOOL_NAMES) {
|
|
|
115
116
|
committer: ctx.committer,
|
|
116
117
|
coAuthors: ctx.coAuthors
|
|
117
118
|
},
|
|
118
|
-
|
|
119
|
+
editFiles: {
|
|
120
|
+
author: ctx.author,
|
|
121
|
+
committer: ctx.committer,
|
|
122
|
+
coAuthors: ctx.coAuthors
|
|
123
|
+
},
|
|
124
|
+
mergePullRequest: { coAuthors: ctx.coAuthors },
|
|
125
|
+
enablePullRequestAutoMerge: { coAuthors: ctx.coAuthors }
|
|
126
|
+
};
|
|
127
|
+
const branches = ctx.guardrails?.branches;
|
|
128
|
+
const guardExtras = {
|
|
129
|
+
...branches && {
|
|
130
|
+
mergePullRequest: { branches },
|
|
131
|
+
enablePullRequestAutoMerge: { branches }
|
|
132
|
+
},
|
|
133
|
+
...ctx.guardrails && { updatePullRequestBranch: { guardrails: ctx.guardrails } }
|
|
119
134
|
};
|
|
120
135
|
const entries = names.map((name) => {
|
|
121
136
|
const descriptor = GITHUB_TOOL_CATALOG[name];
|
|
@@ -126,7 +141,7 @@ function createToolRegistry(ctx, names = ALL_GITHUB_TOOL_NAMES) {
|
|
|
126
141
|
...isGithubWriteToolName(name) && { writeTool: name },
|
|
127
142
|
description: descriptor.description,
|
|
128
143
|
inputSchema: descriptor.inputSchema,
|
|
129
|
-
execute: withToken(core, ctx, commitExtras[name]),
|
|
144
|
+
execute: withToken(core, ctx, commitExtras[name], guardExtras[name]),
|
|
130
145
|
...toModelOutput && { toModelOutput }
|
|
131
146
|
};
|
|
132
147
|
});
|
|
@@ -140,13 +155,20 @@ function createToolRegistry(ctx, names = ALL_GITHUB_TOOL_NAMES) {
|
|
|
140
155
|
//#region src/eve/steps.ts
|
|
141
156
|
async function executeGithubToolStep(name, input, ctx) {
|
|
142
157
|
"use step";
|
|
143
|
-
const entry = createToolRegistry(ctx
|
|
158
|
+
const [entry] = createToolRegistry(ctx, ALL_GITHUB_TOOL_NAMES.filter((tool) => tool === name));
|
|
144
159
|
if (!entry) throw new Error(`Unknown GitHub tool: ${name}`);
|
|
145
160
|
return entry.execute(input);
|
|
146
161
|
}
|
|
162
|
+
/** Why `guardrails` block a call once `context` defaults are applied, or `undefined` when they allow it. */
|
|
163
|
+
function githubGuardrailViolation(name, input, { context, guardrails }) {
|
|
164
|
+
return guardrailViolation(githubTokenCall(name, mergeContextArgs(input, context ?? {})), guardrails);
|
|
165
|
+
}
|
|
147
166
|
async function runGithubToolStep(name, input, ctx) {
|
|
148
167
|
try {
|
|
149
168
|
const call = githubTokenCall(name, mergeContextArgs(input, ctx.context ?? {}));
|
|
169
|
+
const reason = guardrailViolation(call, ctx.guardrails);
|
|
170
|
+
if (reason) throw githubToolsErrors.GUARDRAIL_BLOCKED({ reason });
|
|
171
|
+
if (ctx.dryRun && isGithubWriteToolName(name)) return dryRunWrite(name, call.input, ctx.guardrails, () => ctx.dryRunApproval);
|
|
150
172
|
const token = await resolveGithubToken(ctx.token, call);
|
|
151
173
|
return await executeGithubToolStep(name, input, {
|
|
152
174
|
...ctx,
|
|
@@ -194,9 +216,12 @@ function buildEveToolDefinition(name, options = {}) {
|
|
|
194
216
|
context: options.context,
|
|
195
217
|
author: options.author,
|
|
196
218
|
committer: options.committer,
|
|
197
|
-
coAuthors: options.coAuthors
|
|
219
|
+
coAuthors: options.coAuthors,
|
|
220
|
+
guardrails: options.guardrails,
|
|
221
|
+
dryRun: options.dryRun,
|
|
222
|
+
dryRunApproval: options.dryRunApproval
|
|
198
223
|
};
|
|
199
|
-
const entry = createToolRegistry(ctx
|
|
224
|
+
const [entry] = createToolRegistry(ctx, ALL_GITHUB_TOOL_NAMES.filter((tool) => tool === name));
|
|
200
225
|
if (!entry) throw new Error(`Unknown GitHub tool: ${name}`);
|
|
201
226
|
const approval = entry.writeTool ? resolveEveToolApproval(entry.writeTool, options.requireApproval) : void 0;
|
|
202
227
|
return applyOverrides(defineTool({
|
|
@@ -214,7 +239,10 @@ function buildEveToolMap(options = {}) {
|
|
|
214
239
|
context: options.context,
|
|
215
240
|
author: options.author,
|
|
216
241
|
committer: options.committer,
|
|
217
|
-
coAuthors: options.coAuthors
|
|
242
|
+
coAuthors: options.coAuthors,
|
|
243
|
+
guardrails: options.guardrails,
|
|
244
|
+
dryRun: options.dryRun,
|
|
245
|
+
dryRunApproval: options.dryRunApproval
|
|
218
246
|
};
|
|
219
247
|
const isAllowed = resolveAllowedToolNames(options);
|
|
220
248
|
const registry = createToolRegistry(ctx);
|
|
@@ -251,7 +279,10 @@ function listEveToolDescriptors(options = {}) {
|
|
|
251
279
|
context: options.context,
|
|
252
280
|
author: options.author,
|
|
253
281
|
committer: options.committer,
|
|
254
|
-
coAuthors: options.coAuthors
|
|
282
|
+
coAuthors: options.coAuthors,
|
|
283
|
+
guardrails: options.guardrails,
|
|
284
|
+
dryRun: options.dryRun,
|
|
285
|
+
dryRunApproval: options.dryRunApproval
|
|
255
286
|
}, listResolvedEveToolNames(options)).map((entry) => ({
|
|
256
287
|
name: entry.name,
|
|
257
288
|
description: entry.description,
|
|
@@ -270,10 +301,13 @@ async function executeGithubEveTool(name, input, options = {}) {
|
|
|
270
301
|
context: options.context,
|
|
271
302
|
author: options.author,
|
|
272
303
|
committer: options.committer,
|
|
273
|
-
coAuthors: options.coAuthors
|
|
304
|
+
coAuthors: options.coAuthors,
|
|
305
|
+
guardrails: options.guardrails,
|
|
306
|
+
dryRun: options.dryRun,
|
|
307
|
+
dryRunApproval: options.dryRunApproval
|
|
274
308
|
});
|
|
275
309
|
}
|
|
276
310
|
//#endregion
|
|
277
|
-
export { listEveToolDescriptors as a,
|
|
311
|
+
export { listEveToolDescriptors as a, formatGithubEveToolOutput as c, mapEveApprovalValue as d, resolveEveApproval as f, executeGithubEveTool as i, hasGithubEveToolModelOutput as l, MISSING_EVE_MESSAGE as m, buildEveToolMap as n, listResolvedEveToolNames as o, resolveEveToolApproval as p, createEveGithubToolsDynamic as r, githubGuardrailViolation as s, buildEveToolDefinition as t, isEveApprovalDisabled as u };
|
|
278
312
|
|
|
279
|
-
//# sourceMappingURL=eve-runtime-
|
|
313
|
+
//# sourceMappingURL=eve-runtime-DPzMPCLt.mjs.map
|