@github-tools/eve-extension 0.10.0 → 0.12.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 +10 -6
- package/dist/extension/_manifest.json +1 -1
- package/dist/extension/extension.d.ts +84 -6
- package/dist/extension/extension.d.ts.map +1 -1
- package/dist/extension/extension.mjs +39 -16
- package/dist/extension/instructions.d.ts +3 -0
- package/dist/extension/instructions.d.ts.map +1 -0
- package/dist/extension/instructions.mjs +19 -0
- package/dist/extension/lib/context.d.ts +12 -0
- package/dist/extension/lib/context.d.ts.map +1 -0
- package/dist/extension/lib/context.mjs +24 -0
- package/dist/extension/tools/github.d.ts +1 -1
- package/dist/extension/tools/github.d.ts.map +1 -1
- package/dist/extension/tools/github.mjs +219 -29
- package/dist/index.mjs +1 -2
- package/dist/tools/index.mjs +1 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ This is **the recommended way** to add GitHub tools to an eve agent. The legacy
|
|
|
19
19
|
pnpm add @github-tools/eve-extension
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`eve` is a required peer dependency, declared as `*`: the consuming agent provides the runtime copy and eve checks the extension's generated capability metadata rather than an npm range. This release is built against eve 1.0.0-rc.
|
|
22
|
+
`eve` is a required peer dependency, declared as `*`: the consuming agent provides the runtime copy and eve checks the extension's generated capability metadata rather than an npm range. This release is built against eve 1.0.0-rc.6 and mounts on eve 1.0.0-rc.6 or later. `@vercel/connect` is optional (install it only when using `connector`):
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
25
|
pnpm add eve
|
|
@@ -43,7 +43,9 @@ export default githubExtension({
|
|
|
43
43
|
|
|
44
44
|
> `code-review` pairs cleanly with a Connect `connector`. `maintainer` and `repo-explorer` include gist tools, and GitHub only grants gist access to user access tokens, never the installation tokens Connect mints, so gist calls 403 over Connect. Write tools already require approval via `always()` by default, so a plain `{ someTool: true }` is a no-op, use a predicate (as above) when you actually want to narrow or loosen the default.
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
`extension/instructions.ts` adds a system instruction on how to use the GitHub tools: the preset's tool rules without its "You are …" opener (`resolveToolGuidance` from `@github-tools/sdk/eve-runtime`), the shared rules, and the working `context`. It depends only on the config, so the prompt cache holds. Write tools also set `label.complete`, so channels show "Created issue on owner/repo#123" once a write succeeds.
|
|
47
|
+
|
|
48
|
+
The tool file is a `defineDynamic` function that eve runs before every model call, so tools, approval policies, and schema overrides are rebuilt from the extension config in every process, including after Workflow replay and redeploys. With `preset: 'auto'`, the routing is kept for the session with `ctx.memo`, or for the turn with `evaluation.scope: 'turn'`. `toModelOutput` strips `rateLimit` from the model-facing payload; the execute result still carries it for hooks and channels. Do not use the deprecated `@github-tools/sdk/connect/eve` one-liner for durable Slack/multi-turn agents.
|
|
47
49
|
|
|
48
50
|
`connector` also accepts a `() => string | Promise<string>` resolver, so the same config can pick a connector dynamically (e.g. by environment):
|
|
49
51
|
|
|
@@ -94,14 +96,16 @@ extension/
|
|
|
94
96
|
|---|---|---|
|
|
95
97
|
| `token` | `string \| (() => Promise<string>)` (optional) | PAT string, or an async provider for rotating tokens (e.g. a GitHub App installation token) — the same `GithubTokenInput` the SDK accepts; falls back to `GITHUB_TOKEN` when omitted and `connector` is not set |
|
|
96
98
|
| `connector` | `string \| (() => string \| Promise<string>)` (optional) | Vercel Connect connector name, or a resolver to pick one dynamically (e.g. per environment/tenant); takes priority over `token` |
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
99
|
+
| `actAs` | `'app' \| 'user' \| 'caller' \| { read, write }` (optional) | Whose GitHub access the tools use when `connector` is set. `'app'` (default) uses the GitHub App installation. `'user'` runs each call with the signed-in eve user's own GitHub token, so the agent can do what that user can do on GitHub and nothing more; sessions without a signed-in user fail. `'caller'` uses the user when one drives the turn and the App otherwise (schedules, bots). Users who have not authorized the App get a sign-in prompt and never fall back to the App. `{ read, write }` picks per tool kind, `overrides.<tool>.actAs` per tool. The default may change to `'caller'` in a future major version |
|
|
100
|
+
| `approvers` | `'requester' \| 'anyone'` (optional) | Who may answer an approval. `'requester'` (default) is only the person who asked, so a colleague cannot approve your request. `'anyone'` is an opt-in that lets any signed-in user approve and anyone deny; for `'user'` and `'caller'` tools the approved call runs with the approver's GitHub token, after they sign in |
|
|
101
|
+
| `connect` | `record \| ((ctx, call) => record)` (optional) | Passed through to `getToken` when `connector` is set. `connect.subject` defaults to `{ type: 'app' }` (the project's GitHub App installation); for per-user tokens, use `actAs`. App tokens target the installation owning each call's repository unless `installationId`, `authorizationDetails` or `repositories` pins one; pass a `(ctx, call) => record` resolver for other per-call rules |
|
|
102
|
+
| `preset` | preset name, array, or `'auto'` | `code-review`, `issue-triage`, `ci-ops`, `repo-explorer`, `security-audit`, `release-manager`, `discussion-moderator`, `notification-inbox`, `pr-author`, `maintainer`; `'auto'` lists the tools the session's first request needs and defers the rest |
|
|
99
103
|
| `include` | `string[]?` | Tool names to add on top of `preset` (union), or the full set standalone |
|
|
100
104
|
| `exclude` | `string[]?` | Tool names to remove from the resolved `preset` + `include` set |
|
|
101
105
|
| `context` | `{ owner?, repo?, pullNumber?, issueNumber?, ref? }?` | Default working context for tool inputs and schemas |
|
|
102
106
|
| `requireApproval` | `boolean \| 'auto' \| record` | Global or per-tool; per-tool values may be `'auto'` or predicate functions. `'auto'` runs low-risk writes the user asked for without a prompt |
|
|
103
|
-
| `evaluation` | `record?` | Tunes the `'auto'` modes: `model`, `maxRisk`, `minIntent`, `minPresetProbability`, `maxPresets` |
|
|
104
|
-
| `overrides` | `record` | Per-tool `description` / `approval` / `toModelOutput` / `outputSchema` |
|
|
107
|
+
| `evaluation` | `record?` | Tunes the `'auto'` modes: `model`, `maxRisk`, `minIntent`, `selection`, `scope`, `minToolProbability`, `maxTools`, `minPresetProbability`, `maxPresets`, `providerOptions` |
|
|
108
|
+
| `overrides` | `record` | Per-tool `description` / `approval` / `actAs` / `toModelOutput` / `outputSchema` |
|
|
105
109
|
| `author` / `committer` / `coAuthors` | commit identity | Attribution for commit-creating tools |
|
|
106
110
|
|
|
107
111
|
## Build (contributors)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GithubTokenCall, GithubTokenInput } from '@github-tools/sdk';
|
|
2
2
|
import type { ConnectTokenSubject, GithubConnectorInput, GithubConnectParams } from '@github-tools/sdk/connect';
|
|
3
3
|
import type { ToolContext } from 'eve/tools';
|
|
4
|
-
import { type CommitIdentity, type EveApprovalValue, type EveToolOverrides, type GithubEvaluationOptions, type GithubToolName, type GithubToolPreset, type GithubWriteToolName } from '@github-tools/sdk/eve-runtime';
|
|
4
|
+
import { type CommitIdentity, type EveApprovalValue, type EveToolOverrides, type GithubEvaluationOptions, type GithubGuardrails, type GithubToolName, type GithubToolPreset, type GithubWriteToolName } from '@github-tools/sdk/eve-runtime';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
/**
|
|
7
7
|
* Default owner / repo / PR / issue / ref for tool inputs.
|
|
@@ -51,6 +51,25 @@ export type GithubExtensionApprovalValue = EveApprovalValue | 'auto';
|
|
|
51
51
|
* low-risk write tools (`AUTO_APPROVAL_TOOLS`) and keeps approval on the rest.
|
|
52
52
|
*/
|
|
53
53
|
export type GithubExtensionApprovalConfig = boolean | 'auto' | Partial<Record<GithubWriteToolName, GithubExtensionApprovalValue>>;
|
|
54
|
+
/**
|
|
55
|
+
* Whose GitHub access a tool call uses: the GitHub App installation
|
|
56
|
+
* (`'app'`), the signed-in user (`'user'`), or the user when one drives the
|
|
57
|
+
* turn and the App otherwise (`'caller'`).
|
|
58
|
+
*/
|
|
59
|
+
export type GithubActAs = 'app' | 'user' | 'caller';
|
|
60
|
+
/** One identity for every tool, or one for read tools and one for write tools. */
|
|
61
|
+
export type GithubExtensionActAs = GithubActAs | {
|
|
62
|
+
read?: GithubActAs;
|
|
63
|
+
write?: GithubActAs;
|
|
64
|
+
};
|
|
65
|
+
/** Who may answer an approval: only the requester, or any signed-in user. */
|
|
66
|
+
export type GithubExtensionApprovers = 'requester' | 'anyone';
|
|
67
|
+
/** Per-tool overrides, including the tool's own `actAs`. */
|
|
68
|
+
export type GithubExtensionToolOverrides = {
|
|
69
|
+
[K in GithubToolName]?: NonNullable<EveToolOverrides[K]> & {
|
|
70
|
+
actAs?: GithubActAs;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
54
73
|
/**
|
|
55
74
|
* Config passed to `githubExtension({ ... })` at the agent mount site.
|
|
56
75
|
* Declared as an interface (not only a Zod schema) so IDE hovers show JSDoc.
|
|
@@ -69,11 +88,51 @@ export interface GithubExtensionConfig {
|
|
|
69
88
|
* (e.g. per environment or tenant). Takes priority over `token`.
|
|
70
89
|
*/
|
|
71
90
|
connector?: GithubConnectorInput;
|
|
91
|
+
/**
|
|
92
|
+
* Whose GitHub access the tools use when `connector` is set.
|
|
93
|
+
*
|
|
94
|
+
* - `'app'` (default): the connector's GitHub App installation. Every
|
|
95
|
+
* caller shares the App's permissions.
|
|
96
|
+
* - `'user'`: the signed-in user of the eve session. Each user authorizes
|
|
97
|
+
* the GitHub App once, through eve's sign-in prompt, and every call then
|
|
98
|
+
* runs with their own GitHub token. Sessions without a signed-in user
|
|
99
|
+
* (schedules, `localDev()`) fail instead of falling back to the App.
|
|
100
|
+
* - `'caller'`: `'user'` when a signed-in user drives the turn, the App when
|
|
101
|
+
* nobody does (schedules, automations, bots). A user who has not
|
|
102
|
+
* authorized the App is asked to sign in; the call never falls back to
|
|
103
|
+
* the App for them.
|
|
104
|
+
*
|
|
105
|
+
* GitHub allows a user-token call only when both the user and the App have
|
|
106
|
+
* access, so a maintainer can do what a maintainer can, and a reader can
|
|
107
|
+
* only read. An approved call runs with the approver's token: see
|
|
108
|
+
* `approvers`.
|
|
109
|
+
*
|
|
110
|
+
* Pass `{ read, write }` to pick per tool kind (each defaults to `'app'`),
|
|
111
|
+
* and `overrides.<tool>.actAs` for a single tool. The default may change to
|
|
112
|
+
* `'caller'` in a future major version.
|
|
113
|
+
*/
|
|
114
|
+
actAs?: GithubExtensionActAs;
|
|
115
|
+
/**
|
|
116
|
+
* Who may answer an approval.
|
|
117
|
+
*
|
|
118
|
+
* - `'requester'` (default): only the person who asked for the call. A
|
|
119
|
+
* colleague in a shared thread cannot approve it for them.
|
|
120
|
+
* - `'anyone'`: opt-in for simple shared agents. Any signed-in user can
|
|
121
|
+
* approve, and anyone can deny. For
|
|
122
|
+
* tools that act as `'user'` or `'caller'`, the approved call runs with
|
|
123
|
+
* the approver's GitHub token, so GitHub records the approver and checks
|
|
124
|
+
* their permissions, and an approver who has not authorized the App signs
|
|
125
|
+
* in before the approval counts. For `'app'` tools the approval is a gate
|
|
126
|
+
* only: the call still runs as the App.
|
|
127
|
+
*/
|
|
128
|
+
approvers?: GithubExtensionApprovers;
|
|
72
129
|
/**
|
|
73
130
|
* Vercel Connect token params passed through to `getToken` when `connector`
|
|
74
131
|
* is set. `subject` defaults to `{ type: 'app' }` (the project's GitHub App
|
|
75
|
-
* installation, shared by every caller)
|
|
76
|
-
*
|
|
132
|
+
* installation, shared by every caller). For per-user tokens, prefer
|
|
133
|
+
* `actAs: 'user'` or `'caller'`, which also let eve prompt users who have
|
|
134
|
+
* not connected GitHub yet. With `'caller'`, these params apply to the
|
|
135
|
+
* calls that run as the App.
|
|
77
136
|
*
|
|
78
137
|
* App tokens target the GitHub App installation owning each call's
|
|
79
138
|
* repository, so an App installed on several accounts needs nothing here;
|
|
@@ -84,7 +143,9 @@ export interface GithubExtensionConfig {
|
|
|
84
143
|
connect?: GithubExtensionConnectParams | GithubExtensionConnectResolver;
|
|
85
144
|
/**
|
|
86
145
|
* Restrict tools to a preset (or array of presets). Prefer a focused preset; omit or use `maintainer` for the full catalog.
|
|
87
|
-
* `'auto'`
|
|
146
|
+
* `'auto'` lists the tools an evaluation model picks for the session's first request, plus the core read tools,
|
|
147
|
+
* and defers every other tool: the model can still find it with `eve__search`. Set `evaluation.selection: 'presets'`
|
|
148
|
+
* to list up to two routed presets instead.
|
|
88
149
|
*/
|
|
89
150
|
preset?: GithubToolPreset | GithubToolPreset[] | 'auto';
|
|
90
151
|
/**
|
|
@@ -106,14 +167,31 @@ export interface GithubExtensionConfig {
|
|
|
106
167
|
requireApproval?: GithubExtensionApprovalConfig;
|
|
107
168
|
/** Tuning for `preset: 'auto'` and `'auto'` approval. The evaluation model defaults to TypeSafe Jev. */
|
|
108
169
|
evaluation?: GithubEvaluationOptions;
|
|
109
|
-
/** Per-tool overrides (`description`, `approval`, `toModelOutput`, `outputSchema`). */
|
|
110
|
-
overrides?:
|
|
170
|
+
/** Per-tool overrides (`description`, `approval`, `actAs`, `toModelOutput`, `outputSchema`). */
|
|
171
|
+
overrides?: GithubExtensionToolOverrides;
|
|
111
172
|
/** Default author for commit-creating tools. */
|
|
112
173
|
author?: CommitIdentity;
|
|
113
174
|
/** Default committer for commit-creating tools. */
|
|
114
175
|
committer?: CommitIdentity;
|
|
115
176
|
/** Co-authors to attribute on commits created by tools. */
|
|
116
177
|
coAuthors?: CommitIdentity[];
|
|
178
|
+
/**
|
|
179
|
+
* Repositories and branches the tools may act on, checked before each call reaches GitHub.
|
|
180
|
+
* `repositories` takes `owner/repo` or `owner/*`; `branches` takes names or patterns such as
|
|
181
|
+
* `agent/*` and covers commits, branch creation and deletion, merges into a pull request's base,
|
|
182
|
+
* and updates of a pull request's branch. A call whose input contains what looks like a
|
|
183
|
+
* credential is blocked too, unless `secrets: 'allow'`. A blocked write is denied with the reason
|
|
184
|
+
* instead of asking anyone to approve it.
|
|
185
|
+
*/
|
|
186
|
+
guardrails?: GithubGuardrails;
|
|
187
|
+
/**
|
|
188
|
+
* Shadow mode: run reads as usual but send no write to GitHub, and ask nobody to approve one.
|
|
189
|
+
* Each write still goes through `guardrails`, then returns a dry-run result that says whether
|
|
190
|
+
* approval would have asked a person (with the evaluation model's verdict under `'auto'`), and
|
|
191
|
+
* its label reads "Would create issue on owner/repo". Use it to try the agent on real
|
|
192
|
+
* repositories, for example a scheduled bot, before letting it write.
|
|
193
|
+
*/
|
|
194
|
+
dryRun?: boolean;
|
|
117
195
|
}
|
|
118
196
|
declare const _default: import("eve/extension").ExtensionHandle<z.ZodType<GithubExtensionConfig, GithubExtensionConfig, z.core.$ZodTypeInternals<GithubExtensionConfig, GithubExtensionConfig>>>;
|
|
119
197
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../extension/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../extension/extension.ts"],"names":[],"mappings":"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"}
|
|
@@ -4,23 +4,17 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { GITHUB_TOOL_NAMES, GITHUB_WRITE_TOOLS } from "@github-tools/sdk/eve-runtime";
|
|
7
|
+
import { GITHUB_TOOL_NAMES, GITHUB_WRITE_TOOLS, PRESET_TOOLS } from "@github-tools/sdk/eve-runtime";
|
|
8
8
|
import { defineExtension } from "eve/extension";
|
|
9
9
|
import { z } from "zod";
|
|
10
|
-
const presetNameSchema = z.enum(
|
|
11
|
-
"code-review",
|
|
12
|
-
"issue-triage",
|
|
13
|
-
"ci-ops",
|
|
14
|
-
"repo-explorer",
|
|
15
|
-
"security-audit",
|
|
16
|
-
"release-manager",
|
|
17
|
-
"discussion-moderator",
|
|
18
|
-
"notification-inbox",
|
|
19
|
-
"pr-author",
|
|
20
|
-
"maintainer"
|
|
21
|
-
]);
|
|
10
|
+
const presetNameSchema = z.enum(Object.keys(PRESET_TOOLS));
|
|
22
11
|
const toolNameSchema = z.enum(Object.values(GITHUB_TOOL_NAMES));
|
|
23
12
|
const writeToolNameSchema = z.enum(Object.values(GITHUB_WRITE_TOOLS));
|
|
13
|
+
const actAsSchema = z.enum([
|
|
14
|
+
"app",
|
|
15
|
+
"user",
|
|
16
|
+
"caller"
|
|
17
|
+
]);
|
|
24
18
|
const commitIdentitySchema = z.object({
|
|
25
19
|
name: z.string(),
|
|
26
20
|
email: z.string()
|
|
@@ -28,6 +22,11 @@ const commitIdentitySchema = z.object({
|
|
|
28
22
|
const configSchema = z.object({
|
|
29
23
|
token: z.custom((value) => typeof value === "string" || typeof value === "function").optional(),
|
|
30
24
|
connector: z.custom((value) => typeof value === "string" || typeof value === "function").optional(),
|
|
25
|
+
actAs: z.union([actAsSchema, z.object({
|
|
26
|
+
read: actAsSchema.optional(),
|
|
27
|
+
write: actAsSchema.optional()
|
|
28
|
+
})]).optional(),
|
|
29
|
+
approvers: z.enum(["requester", "anyone"]).optional(),
|
|
31
30
|
connect: z.union([z.record(z.string(), z.unknown()), z.custom((value) => typeof value === "function")]).optional(),
|
|
32
31
|
preset: z.union([
|
|
33
32
|
presetNameSchema,
|
|
@@ -53,12 +52,36 @@ const configSchema = z.object({
|
|
|
53
52
|
maxRisk: z.number().optional(),
|
|
54
53
|
minIntent: z.number().optional(),
|
|
55
54
|
minPresetProbability: z.number().optional(),
|
|
56
|
-
maxPresets: z.number().optional()
|
|
55
|
+
maxPresets: z.number().optional(),
|
|
56
|
+
selection: z.enum(["presets", "tools"]).optional(),
|
|
57
|
+
scope: z.enum(["turn", "session"]).optional(),
|
|
58
|
+
minToolProbability: z.number().optional(),
|
|
59
|
+
maxTools: z.number().optional(),
|
|
60
|
+
providerOptions: z.record(z.string(), z.record(z.string(), z.unknown())).optional()
|
|
57
61
|
}).optional(),
|
|
58
|
-
overrides: z.partialRecord(toolNameSchema, z.
|
|
62
|
+
overrides: z.partialRecord(toolNameSchema, z.looseObject({ actAs: actAsSchema.optional() })).optional(),
|
|
59
63
|
author: commitIdentitySchema.optional(),
|
|
60
64
|
committer: commitIdentitySchema.optional(),
|
|
61
|
-
coAuthors: z.array(commitIdentitySchema).optional()
|
|
65
|
+
coAuthors: z.array(commitIdentitySchema).optional(),
|
|
66
|
+
guardrails: z.object({
|
|
67
|
+
repositories: z.array(z.string()).optional(),
|
|
68
|
+
branches: z.array(z.string()).optional(),
|
|
69
|
+
secrets: z.enum(["block", "allow"]).optional()
|
|
70
|
+
}).optional(),
|
|
71
|
+
dryRun: z.boolean().optional()
|
|
72
|
+
}).superRefine((config, ctx) => {
|
|
73
|
+
const { actAs } = config;
|
|
74
|
+
const identities = [...typeof actAs === "object" ? [actAs.read, actAs.write] : [actAs], ...Object.values(config.overrides ?? {}).map((override) => override?.actAs)];
|
|
75
|
+
if (config.connector === void 0 && identities.some((identity) => identity !== void 0 && identity !== "app")) ctx.addIssue({
|
|
76
|
+
code: "custom",
|
|
77
|
+
path: ["actAs"],
|
|
78
|
+
message: "`actAs: 'user'` and `'caller'` need a Vercel Connect `connector`."
|
|
79
|
+
});
|
|
80
|
+
if (actAs === "user" && config.connect !== void 0) ctx.addIssue({
|
|
81
|
+
code: "custom",
|
|
82
|
+
path: ["connect"],
|
|
83
|
+
message: "`connect` configures App tokens and cannot be combined with `actAs: 'user'`."
|
|
84
|
+
});
|
|
62
85
|
});
|
|
63
86
|
var extension_default = defineExtension({ config: configSchema });
|
|
64
87
|
export { extension_default as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../extension/instructions.ts"],"names":[],"mappings":";AAOA,wBAQE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import extension_default from "./extension.mjs";
|
|
8
|
+
import { sessionContext } from "./lib/context.mjs";
|
|
9
|
+
import { resolveToolGuidance } from "@github-tools/sdk/eve-runtime";
|
|
10
|
+
import { defineDynamic, defineInstructions } from "eve/instructions";
|
|
11
|
+
var instructions_default = defineDynamic((ctx) => {
|
|
12
|
+
const { preset } = extension_default.config;
|
|
13
|
+
const guidance = resolveToolGuidance({
|
|
14
|
+
preset: preset === "auto" ? void 0 : preset,
|
|
15
|
+
context: sessionContext(ctx.session.auth.current)
|
|
16
|
+
});
|
|
17
|
+
return defineInstructions({ content: `GitHub tools: the tool names below leave out this extension's prefix, such as \`github__\`.${preset === "auto" ? " A GitHub tool that is not in your tool list can be found with `eve__search`." : ""}\n\n${guidance}` });
|
|
18
|
+
});
|
|
19
|
+
export { instructions_default as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type GithubExtensionContext } from '../extension';
|
|
2
|
+
type SessionAuth = {
|
|
3
|
+
readonly authenticator?: string;
|
|
4
|
+
readonly attributes?: Readonly<Record<string, string | readonly string[]>>;
|
|
5
|
+
} | null | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The extension's `context`, with the fields it leaves out filled from the GitHub channel's thread:
|
|
8
|
+
* the repository, and the issue or pull request number. Other channels add nothing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sessionContext(auth: SessionAuth): GithubExtensionContext | undefined;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../extension/lib/context.ts"],"names":[],"mappings":"AAAA,OAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAErE,KAAK,WAAW,GAAG;IAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,CAAA;AAErJ;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,sBAAsB,GAAG,SAAS,CAUpF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import extension_default from "../extension.mjs";
|
|
8
|
+
function sessionContext(auth) {
|
|
9
|
+
const configured = extension_default.config.context;
|
|
10
|
+
if (auth?.authenticator !== "github-webhook") return configured;
|
|
11
|
+
const { repository, issue_number: issue, pull_request_number: pull } = auth.attributes ?? {};
|
|
12
|
+
const [owner, repo] = typeof repository === "string" ? repository.split("/") : [];
|
|
13
|
+
if (!owner || !repo) return configured;
|
|
14
|
+
const pullNumber = Number(pull) || void 0;
|
|
15
|
+
const issueNumber = Number(issue) || pullNumber;
|
|
16
|
+
return {
|
|
17
|
+
owner,
|
|
18
|
+
repo,
|
|
19
|
+
...pullNumber && { pullNumber },
|
|
20
|
+
...issueNumber && { issueNumber },
|
|
21
|
+
...configured
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { sessionContext };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const _default: import("eve").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve").DynamicContext>;
|
|
1
|
+
declare const _default: import("eve/tools").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve/tools").DynamicContext>;
|
|
2
2
|
export default _default;
|
|
3
3
|
//# sourceMappingURL=github.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../../../extension/tools/github.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../../../extension/tools/github.ts"],"names":[],"mappings":";AAuXA,wBAsDE"}
|
|
@@ -4,12 +4,16 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { sessionContext } from "../lib/context.mjs";
|
|
7
8
|
import extension_default from "../extension.mjs";
|
|
8
|
-
import { AUTO_APPROVAL_TOOLS, GITHUB_TOOL_NAMES, GITHUB_WRITE_TOOLS, executeGithubEveTool, formatGithubEveToolOutput, githubToolsErrors, isEveApprovalDisabled, latestUserText, listEveToolDescriptors, mapEveApprovalValue
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import { AUTO_APPROVAL_TOOLS, GITHUB_TOOL_NAMES, GITHUB_WRITE_TOOLS, autoApprovalDecision, evaluatePresets, evaluateTools, executeGithubEveTool, fallbackPresets, fallbackTools, formatGithubEveToolOutput, githubGuardrailViolation, githubToolsErrors, isEveApprovalDisabled, latestUserText, listEveToolDescriptors, mapEveApprovalValue } from "@github-tools/sdk/eve-runtime";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { connectGithubScopesForTools, connectGithubToken, resolveGithubConnector } from "@github-tools/sdk/connect";
|
|
12
|
+
import { connect } from "@vercel/connect/eve";
|
|
13
|
+
import { defineDynamic, defineTool, toolOutput } from "eve/tools";
|
|
14
|
+
function buildSessionOptions(ctx, auth = ctx?.session.auth.current) {
|
|
15
|
+
const { token, connector, connect, preset, include, exclude, overrides, author, committer, coAuthors, guardrails, dryRun } = extension_default.config;
|
|
16
|
+
const context = sessionContext(auth);
|
|
13
17
|
const includeNames = include;
|
|
14
18
|
const excludeNames = exclude;
|
|
15
19
|
return {
|
|
@@ -21,6 +25,7 @@ function buildSessionOptions(ctx) {
|
|
|
21
25
|
const { subject, ...params } = typeof connect === "function" ? await connect(requireToolContext(ctx), requireToolCall(call)) : connect ?? {};
|
|
22
26
|
const resolvedSubject = typeof subject === "function" ? await subject(requireToolContext(ctx)) : subject;
|
|
23
27
|
return {
|
|
28
|
+
...preset === "auto" && call && { scopes: connectGithubScopesForTools([call.toolName]) },
|
|
24
29
|
...params,
|
|
25
30
|
...resolvedSubject && { subject: resolvedSubject }
|
|
26
31
|
};
|
|
@@ -33,7 +38,9 @@ function buildSessionOptions(ctx) {
|
|
|
33
38
|
context,
|
|
34
39
|
author,
|
|
35
40
|
committer,
|
|
36
|
-
coAuthors
|
|
41
|
+
coAuthors,
|
|
42
|
+
guardrails,
|
|
43
|
+
dryRun
|
|
37
44
|
};
|
|
38
45
|
}
|
|
39
46
|
const autoApprovalTools = new Set(AUTO_APPROVAL_TOOLS);
|
|
@@ -43,10 +50,6 @@ function approvalValue(writeTool, requireApproval, override) {
|
|
|
43
50
|
if (typeof requireApproval === "object") return requireApproval[writeTool] ?? true;
|
|
44
51
|
return requireApproval ?? true;
|
|
45
52
|
}
|
|
46
|
-
const PENDING_APPROVALS_LABEL = "[Pending approvals]";
|
|
47
|
-
function withoutPendingApprovals(messages) {
|
|
48
|
-
return messages.filter((m) => m.role !== "user" || !latestUserText([m]).startsWith(PENDING_APPROVALS_LABEL));
|
|
49
|
-
}
|
|
50
53
|
function calledGithubTools(messages) {
|
|
51
54
|
return messages.flatMap((message) => message.role === "assistant" && Array.isArray(message.content) ? message.content.flatMap((part) => {
|
|
52
55
|
if (part.type !== "tool-call") return [];
|
|
@@ -66,60 +69,247 @@ function requireToolCall(call) {
|
|
|
66
69
|
if (!call) throw githubToolsErrors.SUBJECT_CONTEXT_REQUIRED();
|
|
67
70
|
return call;
|
|
68
71
|
}
|
|
72
|
+
function actAsFor(name) {
|
|
73
|
+
const { actAs, overrides } = extension_default.config;
|
|
74
|
+
const override = overrides?.[name]?.actAs;
|
|
75
|
+
if (override) return override;
|
|
76
|
+
if (typeof actAs === "object") return (writeToolName(name) ? actAs.write : actAs.read) ?? "app";
|
|
77
|
+
return actAs ?? "app";
|
|
78
|
+
}
|
|
79
|
+
function isUser(principal) {
|
|
80
|
+
return principal?.principalType === "user";
|
|
81
|
+
}
|
|
82
|
+
function samePrincipal(a, b) {
|
|
83
|
+
return b != null && a.authenticator === b.authenticator && a.issuer === b.issuer && a.principalType === b.principalType && a.principalId === b.principalId;
|
|
84
|
+
}
|
|
85
|
+
async function githubUserAuth() {
|
|
86
|
+
return connect(await resolveGithubConnector(extension_default.config.connector));
|
|
87
|
+
}
|
|
69
88
|
async function runGithubEveTool(name, input, ctx) {
|
|
70
|
-
|
|
89
|
+
const args = input;
|
|
90
|
+
if (extension_default.config.dryRun && writeToolName(name)) {
|
|
91
|
+
const key = decisionKey(ctx.session.id, ctx.callId);
|
|
92
|
+
const dryRunApproval = dryRunApprovals.get(key);
|
|
93
|
+
dryRunApprovals.delete(key);
|
|
94
|
+
return executeGithubEveTool(name, args, {
|
|
95
|
+
...buildSessionOptions(ctx),
|
|
96
|
+
dryRunApproval
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const actAs = actAsFor(name);
|
|
100
|
+
if (actAs === "app") return executeGithubEveTool(name, args, buildSessionOptions(ctx));
|
|
101
|
+
const requester = ctx.session.auth.current;
|
|
102
|
+
const approver = ctx.approval?.responder;
|
|
103
|
+
const auth = await githubUserAuth();
|
|
104
|
+
if (isUser(approver) && !samePrincipal(approver, requester)) {
|
|
105
|
+
const { token } = await approver.getToken(auth);
|
|
106
|
+
return executeGithubEveTool(name, args, {
|
|
107
|
+
...buildSessionOptions(ctx),
|
|
108
|
+
token
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (actAs === "caller" && !isUser(requester)) return executeGithubEveTool(name, args, buildSessionOptions(ctx));
|
|
112
|
+
const { token } = await ctx.getToken(auth);
|
|
113
|
+
const result = await executeGithubEveTool(name, args, {
|
|
114
|
+
...buildSessionOptions(ctx),
|
|
115
|
+
token
|
|
116
|
+
});
|
|
117
|
+
if (isUnauthorized(result)) ctx.requireAuth(auth);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
async function runGithubEveApprovalResponse(name, { request, response, auth }) {
|
|
121
|
+
if (response.decision === "deny") return { status: "allowed" };
|
|
122
|
+
if (!isUser(response.principal)) return samePrincipal(response.principal, request.principal) ? { status: "allowed" } : {
|
|
123
|
+
status: "rejected",
|
|
124
|
+
reason: "Sign in to approve this GitHub action."
|
|
125
|
+
};
|
|
126
|
+
if (actAsFor(name) === "app") return { status: "allowed" };
|
|
127
|
+
await auth.getToken(await githubUserAuth());
|
|
128
|
+
return { status: "allowed" };
|
|
129
|
+
}
|
|
130
|
+
async function runConfiguredApprovalResponse(name, policy, ctx) {
|
|
131
|
+
const decision = await policy(ctx);
|
|
132
|
+
if (decision.status !== "allowed") return decision;
|
|
133
|
+
return runGithubEveApprovalResponse(name, ctx);
|
|
134
|
+
}
|
|
135
|
+
function configuredApprovalResponse(name) {
|
|
136
|
+
const value = configuredApprovalValue(name);
|
|
137
|
+
return typeof value === "object" ? value.response : void 0;
|
|
138
|
+
}
|
|
139
|
+
function isUnauthorized(result) {
|
|
140
|
+
if (!isErrorResult(result)) return false;
|
|
141
|
+
const { error } = result;
|
|
142
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === githubToolsErrors.UNAUTHORIZED.code;
|
|
71
143
|
}
|
|
72
144
|
function runGithubEveToModelOutput(name, output) {
|
|
73
145
|
const custom = buildSessionOptions().overrides?.[name]?.toModelOutput;
|
|
74
|
-
|
|
146
|
+
if (custom) return custom(output);
|
|
147
|
+
if (isErrorResult(output)) return toolOutput.errorText(JSON.stringify({ error: output.error }));
|
|
148
|
+
return formatGithubEveToolOutput(name, output);
|
|
75
149
|
}
|
|
150
|
+
function isErrorResult(output) {
|
|
151
|
+
return output != null && typeof output === "object" && !Array.isArray(output) && "error" in output && output.error != null;
|
|
152
|
+
}
|
|
153
|
+
function isPersonRequest(ctx) {
|
|
154
|
+
return ctx.session.parent === void 0 && ctx.session.auth.current?.principalType !== "service";
|
|
155
|
+
}
|
|
156
|
+
const autoDecisions = new Map();
|
|
157
|
+
const MAX_CACHED_DECISIONS = 100;
|
|
158
|
+
function decisionKey(sessionId, callId) {
|
|
159
|
+
return `${sessionId}:${callId}`;
|
|
160
|
+
}
|
|
161
|
+
function cachedAutoApproval(writeTool, request, ctx) {
|
|
162
|
+
const key = decisionKey(ctx.session.id, ctx.callId);
|
|
163
|
+
const cached = autoDecisions.get(key);
|
|
164
|
+
if (cached) return cached.pending;
|
|
165
|
+
const messages = [{
|
|
166
|
+
role: "user",
|
|
167
|
+
content: request
|
|
168
|
+
}];
|
|
169
|
+
const entry = { pending: autoApprovalDecision(writeTool, ctx.toolInput, messages, extension_default.config.evaluation, ctx.abortSignal).then((decision) => {
|
|
170
|
+
entry.settled = decision;
|
|
171
|
+
return decision;
|
|
172
|
+
}) };
|
|
173
|
+
autoDecisions.set(key, entry);
|
|
174
|
+
entry.pending.catch(() => autoDecisions.delete(key));
|
|
175
|
+
if (autoDecisions.size > MAX_CACHED_DECISIONS) autoDecisions.delete(autoDecisions.keys().next().value);
|
|
176
|
+
return entry.pending;
|
|
177
|
+
}
|
|
178
|
+
function approvalPrompt(label, sessionId, callId) {
|
|
179
|
+
const decision = autoDecisions.get(decisionKey(sessionId, callId))?.settled;
|
|
180
|
+
return decision?.ask ? `${label}? ${decision.reason}` : `${label}?`;
|
|
181
|
+
}
|
|
182
|
+
function configuredApprovalValue(name) {
|
|
183
|
+
const writeTool = writeToolName(name);
|
|
184
|
+
if (!writeTool) return void 0;
|
|
185
|
+
const { requireApproval, overrides } = extension_default.config;
|
|
186
|
+
return approvalValue(writeTool, requireApproval, overrides?.[name]?.approval);
|
|
187
|
+
}
|
|
188
|
+
const dryRunApprovals = new Map();
|
|
76
189
|
async function runGithubEveApproval(name, request, ctx) {
|
|
77
190
|
const writeTool = writeToolName(name);
|
|
78
191
|
if (!writeTool) return "not-applicable";
|
|
79
|
-
const
|
|
80
|
-
|
|
192
|
+
const reason = githubGuardrailViolation(name, ctx.toolInput, {
|
|
193
|
+
context: sessionContext(ctx.session.auth.current),
|
|
194
|
+
guardrails: extension_default.config.guardrails
|
|
195
|
+
});
|
|
196
|
+
if (reason) return {
|
|
197
|
+
type: "denied",
|
|
198
|
+
reason
|
|
199
|
+
};
|
|
200
|
+
if (!extension_default.config.dryRun) return githubApprovalStatus(name, writeTool, request, ctx);
|
|
201
|
+
const auto = configuredApprovalValue(name) === "auto" && isPersonRequest(ctx) && await cachedAutoApproval(writeTool, request, ctx);
|
|
202
|
+
const status = auto ? void 0 : await githubApprovalStatus(name, writeTool, request, ctx);
|
|
203
|
+
if (status === "denied" || typeof status === "object" && status?.type === "denied") return status;
|
|
204
|
+
dryRunApprovals.set(decisionKey(ctx.session.id, ctx.callId), auto ? {
|
|
205
|
+
required: auto.ask,
|
|
206
|
+
reason: auto.reason
|
|
207
|
+
} : { required: status === true || status === "user-approval" || typeof status === "object" && status?.type === "user-approval" });
|
|
208
|
+
if (dryRunApprovals.size > MAX_CACHED_DECISIONS) dryRunApprovals.delete(dryRunApprovals.keys().next().value);
|
|
209
|
+
return "not-applicable";
|
|
210
|
+
}
|
|
211
|
+
async function githubApprovalStatus(name, writeTool, request, ctx) {
|
|
212
|
+
const value = configuredApprovalValue(name);
|
|
81
213
|
if (value === "auto") {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
214
|
+
if (!isPersonRequest(ctx)) return "user-approval";
|
|
215
|
+
const { ask, reason } = await cachedAutoApproval(writeTool, request, ctx);
|
|
216
|
+
return ask ? "user-approval" : {
|
|
217
|
+
type: "approved",
|
|
218
|
+
reason
|
|
219
|
+
};
|
|
87
220
|
}
|
|
88
221
|
if (isEveApprovalDisabled(value)) return "not-applicable";
|
|
89
222
|
return mapEveApprovalValue(value)(ctx);
|
|
90
223
|
}
|
|
91
|
-
function
|
|
224
|
+
function describeGithubCall(name, inputSchema, input, sessionContext) {
|
|
225
|
+
const fields = inputSchema instanceof z.ZodObject ? inputSchema.shape : {};
|
|
92
226
|
const { owner, repo, pullNumber, issueNumber, discussionNumber } = {
|
|
93
|
-
...
|
|
227
|
+
...Object.fromEntries(Object.entries(sessionContext ?? {}).filter(([key]) => key in fields)),
|
|
94
228
|
...input
|
|
95
229
|
};
|
|
96
230
|
const action = name.replace(/[A-Z]/g, (letter) => ` ${letter.toLowerCase()}`);
|
|
97
231
|
const number = pullNumber ?? issueNumber ?? discussionNumber;
|
|
98
232
|
const target = owner && repo ? ` on ${owner}/${repo}${number ? `#${number}` : ""}` : "";
|
|
99
|
-
return `${action[0].toUpperCase()}${action.slice(1)}${target}
|
|
233
|
+
return `${action[0].toUpperCase()}${action.slice(1)}${target}`;
|
|
234
|
+
}
|
|
235
|
+
const PAST_TENSE = {
|
|
236
|
+
add: "Added",
|
|
237
|
+
cancel: "Cancelled",
|
|
238
|
+
close: "Closed",
|
|
239
|
+
create: "Created",
|
|
240
|
+
delete: "Deleted",
|
|
241
|
+
disable: "Disabled",
|
|
242
|
+
edit: "Edited",
|
|
243
|
+
enable: "Enabled",
|
|
244
|
+
fork: "Forked",
|
|
245
|
+
mark: "Marked",
|
|
246
|
+
merge: "Merged",
|
|
247
|
+
remove: "Removed",
|
|
248
|
+
reply: "Replied",
|
|
249
|
+
request: "Requested",
|
|
250
|
+
rerun: "Reran",
|
|
251
|
+
resolve: "Resolved",
|
|
252
|
+
trigger: "Triggered",
|
|
253
|
+
update: "Updated"
|
|
254
|
+
};
|
|
255
|
+
function describeGithubResult(name, inputSchema, input, output, context) {
|
|
256
|
+
if (output !== null && typeof output === "object" && "error" in output) {
|
|
257
|
+
const label = describeGithubCall(name, inputSchema, input, context);
|
|
258
|
+
return `Couldn't ${label[0].toLowerCase()}${label.slice(1)}`;
|
|
259
|
+
}
|
|
260
|
+
if (!writeToolName(name)) return "";
|
|
261
|
+
if (output !== null && typeof output === "object" && "dryRun" in output) {
|
|
262
|
+
const label = describeGithubCall(name, inputSchema, input, context);
|
|
263
|
+
return `Would ${label[0].toLowerCase()}${label.slice(1)}`;
|
|
264
|
+
}
|
|
265
|
+
const created = output !== null && typeof output === "object" && "number" in output && typeof output.number === "number" ? output.number : void 0;
|
|
266
|
+
const [verb, ...rest] = describeGithubCall(name, inputSchema, created !== void 0 && input.pullNumber === void 0 && input.issueNumber === void 0 && input.discussionNumber === void 0 ? {
|
|
267
|
+
...input,
|
|
268
|
+
issueNumber: created
|
|
269
|
+
} : input, context).split(" ");
|
|
270
|
+
const past = PAST_TENSE[verb.toLowerCase()];
|
|
271
|
+
return past ? [past, ...rest].join(" ") : "";
|
|
100
272
|
}
|
|
101
273
|
var github_default = defineDynamic(async (ctx) => {
|
|
102
|
-
const sessionOptions = buildSessionOptions();
|
|
274
|
+
const sessionOptions = buildSessionOptions(void 0, ctx.session.auth.current);
|
|
275
|
+
const { context } = sessionOptions;
|
|
103
276
|
const { preset, evaluation } = extension_default.config;
|
|
104
|
-
const
|
|
105
|
-
const messages = withoutPendingApprovals(history);
|
|
277
|
+
const messages = await ctx.messages();
|
|
106
278
|
const request = latestUserText(messages);
|
|
107
|
-
const
|
|
279
|
+
const routingKey = evaluation?.scope === "turn" ? ctx.turn?.id ?? null : null;
|
|
280
|
+
const routed = preset !== "auto" ? void 0 : evaluation?.selection !== "presets" ? { include: await ctx.memo(["tools", routingKey], ({ abortSignal }) => evaluateTools(messages, evaluation, abortSignal)).catch((error) => fallbackTools(error, evaluation)) } : { preset: await ctx.memo(["presets", routingKey], ({ abortSignal }) => evaluatePresets(messages, evaluation, abortSignal)).catch((error) => fallbackPresets(error, evaluation)) };
|
|
281
|
+
const listed = routed && new Set(listEveToolDescriptors({
|
|
282
|
+
...sessionOptions,
|
|
283
|
+
preset: routed.preset,
|
|
284
|
+
include: [
|
|
285
|
+
...routed.include ?? [],
|
|
286
|
+
...sessionOptions.include ?? [],
|
|
287
|
+
...calledGithubTools(messages)
|
|
288
|
+
]
|
|
289
|
+
}).map((entry) => entry.name));
|
|
290
|
+
const descriptors = listEveToolDescriptors(listed ? {
|
|
108
291
|
...sessionOptions,
|
|
109
|
-
preset:
|
|
110
|
-
include:
|
|
292
|
+
preset: void 0,
|
|
293
|
+
include: void 0
|
|
111
294
|
} : sessionOptions);
|
|
112
295
|
const tools = {};
|
|
113
296
|
const toolOverrides = sessionOptions.overrides;
|
|
114
297
|
for (const entry of descriptors) {
|
|
115
298
|
const name = entry.name;
|
|
116
299
|
const override = toolOverrides?.[name];
|
|
300
|
+
const configuredResponse = configuredApprovalResponse(name);
|
|
117
301
|
tools[name] = defineTool({
|
|
302
|
+
...listed && !listed.has(name) && { deferred: true },
|
|
118
303
|
description: override?.description ?? entry.description,
|
|
119
304
|
inputSchema: entry.inputSchema,
|
|
120
305
|
approval: {
|
|
121
306
|
request: (approvalCtx) => runGithubEveApproval(name, request, approvalCtx),
|
|
122
|
-
prompt: ({ input }) =>
|
|
307
|
+
prompt: ({ callId, input }) => approvalPrompt(describeGithubCall(name, entry.inputSchema, input, context), ctx.session.id, callId),
|
|
308
|
+
...configuredResponse ? { response: (responseCtx) => runConfiguredApprovalResponse(name, configuredResponse, responseCtx) } : extension_default.config.approvers === "anyone" && { response: (responseCtx) => runGithubEveApprovalResponse(name, responseCtx) }
|
|
309
|
+
},
|
|
310
|
+
label: {
|
|
311
|
+
start: (input) => describeGithubCall(name, entry.inputSchema, input, context),
|
|
312
|
+
complete: (input, output) => describeGithubResult(name, entry.inputSchema, input, output, context)
|
|
123
313
|
},
|
|
124
314
|
toModelOutput: (output) => runGithubEveToModelOutput(name, output),
|
|
125
315
|
...override?.outputSchema !== void 0 && { outputSchema: override.outputSchema },
|
package/dist/index.mjs
CHANGED
|
@@ -4,5 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
|
|
8
|
-
export { extension_default as default, extension_default as eve_extension };
|
|
7
|
+
export { default, default as eve_extension } from "./extension/extension.mjs";
|
package/dist/tools/index.mjs
CHANGED
|
@@ -4,5 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
|
|
8
|
-
export { github_default as github };
|
|
7
|
+
export { default as github } from "../extension/tools/github.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@github-tools/eve-extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "GitHub tools for eve, distributed as a mountable eve extension (https://eve.dev/docs/extensions)",
|
|
5
5
|
"author": "HugoRCD <hugo.richard@vercel.com>",
|
|
6
6
|
"repository": {
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"zod": "^4.5.4",
|
|
49
|
-
"@github-tools/sdk": "1.
|
|
49
|
+
"@github-tools/sdk": "1.21.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@vercel/connect": ">=
|
|
52
|
+
"@vercel/connect": ">=2.7.0",
|
|
53
53
|
"eve": "*"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@types/node": "^26.5.0",
|
|
62
62
|
"@vercel/connect": "^2.7.0",
|
|
63
63
|
"eslint": "^10.10.0",
|
|
64
|
-
"eve": "1.0.0-rc.
|
|
64
|
+
"eve": "1.0.0-rc.6",
|
|
65
65
|
"typescript": "^6.0.3",
|
|
66
66
|
"typescript-eslint": "^8.70.0"
|
|
67
67
|
},
|