@ai-sdk/harness-github-copilot 1.0.28 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,655 +1,538 @@
1
- // src/github-copilot-harness.ts
2
- import { createHash } from "crypto";
3
- import {
4
- commonTool
5
- } from "@ai-sdk/harness";
6
- import {
7
- createCredentialRequestTransformation,
8
- isSandboxCredentialPlaceholder
9
- } from "@ai-sdk/harness/utils";
1
+ import { createHash } from "node:crypto";
2
+ import { commonTool } from "@ai-sdk/harness";
3
+ import { createCredentialRequestTransformation, isHarnessAuthenticationEnvironment, isLinux, isMacOS, isSandboxCredentialPlaceholder, isWindows, readLinuxSecretServicePassword, readMacOSKeychainPassword, readWindowsCredentialManagerPassword, shouldResolveNativeSubscription } from "@ai-sdk/harness/utils";
10
4
  import { createACP } from "@ai-sdk/harness-acp";
11
- import { tool } from "@ai-sdk/provider-utils";
5
+ import { isRecord, tool } from "@ai-sdk/provider-utils";
12
6
  import { z } from "zod/v4";
13
-
14
- // src/github-copilot-subscription.ts
15
- import { execFile } from "child_process";
16
- import { constants } from "fs";
17
- import { access, readFile } from "fs/promises";
18
- import { homedir } from "os";
19
- import { join, resolve } from "path";
20
- import { promisify } from "util";
21
- import {
22
- isHarnessAuthenticationEnvironment,
23
- isLinux,
24
- isMacOS,
25
- isWindows,
26
- readLinuxSecretServicePassword,
27
- readMacOSKeychainPassword,
28
- readWindowsCredentialManagerPassword,
29
- shouldResolveNativeSubscription
30
- } from "@ai-sdk/harness/utils";
31
- import { isRecord } from "@ai-sdk/provider-utils";
7
+ import { execFile } from "node:child_process";
8
+ import { constants } from "node:fs";
9
+ import { access, readFile } from "node:fs/promises";
10
+ import { homedir } from "node:os";
11
+ import { join, resolve } from "node:path";
12
+ import { promisify } from "node:util";
32
13
  import { parse } from "jsonc-parser";
33
- var COPILOT_KEYRING_SERVICE = "copilot-cli";
34
- var execFileAsync = promisify(execFile);
35
- async function resolveGitHubCopilotSubscriptionEnvironment({
36
- auth,
37
- env,
38
- readSubscription = readGitHubCopilotSubscription
39
- }) {
40
- if (isHarnessAuthenticationEnvironment(auth)) return auth;
41
- if (!shouldResolveNativeSubscription({
42
- auth,
43
- env,
44
- hasDirectCredential: env.COPILOT_GITHUB_TOKEN != null || env.GH_TOKEN != null || env.GITHUB_TOKEN != null
45
- })) {
46
- return env;
47
- }
48
- const subscription = await readSubscription({ env });
49
- if (subscription == null) return env;
50
- return {
51
- ...env,
52
- COPILOT_GITHUB_TOKEN: subscription.token,
53
- COPILOT_GH_HOST: normalizeGitHubHost(subscription.host)
54
- };
14
+ //#region src/github-copilot-subscription.ts
15
+ const COPILOT_KEYRING_SERVICE = "copilot-cli";
16
+ const execFileAsync = promisify(execFile);
17
+ async function resolveGitHubCopilotSubscriptionEnvironment({ auth, env, readSubscription = readGitHubCopilotSubscription }) {
18
+ if (isHarnessAuthenticationEnvironment(auth)) return auth;
19
+ if (!shouldResolveNativeSubscription({
20
+ auth,
21
+ env,
22
+ hasDirectCredential: env.COPILOT_GITHUB_TOKEN != null || env.GH_TOKEN != null || env.GITHUB_TOKEN != null
23
+ })) return env;
24
+ const subscription = await readSubscription({ env });
25
+ if (subscription == null) return env;
26
+ return {
27
+ ...env,
28
+ COPILOT_GITHUB_TOKEN: subscription.token,
29
+ COPILOT_GH_HOST: normalizeGitHubHost(subscription.host)
30
+ };
55
31
  }
56
- async function readGitHubCopilotSubscription({
57
- env = process.env,
58
- homeDirectory = homedir(),
59
- platform = process.platform,
60
- readSecureCredential,
61
- findGitHubCliExecutable = findHostGitHubCliExecutable,
62
- readGitHubCliToken = readHostGitHubCliToken
63
- } = {}) {
64
- const copilotHome = resolve(
65
- env.COPILOT_HOME ?? join(homeDirectory, ".copilot")
66
- );
67
- const config = await readGitHubCopilotConfig({
68
- path: join(copilotHome, "config.json")
69
- });
70
- const account = selectGitHubCopilotAccount({ config });
71
- if (account != null) {
72
- const accountKey = `${account.host}:${account.login}`;
73
- const secureToken = await (readSecureCredential ?? ((options) => readGitHubCopilotSecureCredential({ ...options, platform })))({
74
- service: COPILOT_KEYRING_SERVICE,
75
- account: accountKey
76
- }).catch(() => void 0);
77
- if (isNonEmptyString(secureToken)) {
78
- return { token: secureToken, host: account.host };
79
- }
80
- const plaintextToken = getPlaintextToken({ config, accountKey });
81
- if (plaintextToken != null) {
82
- return { token: plaintextToken, host: account.host };
83
- }
84
- }
85
- const host = account?.host ?? normalizeGitHubOrigin(env.COPILOT_GH_HOST ?? env.GH_HOST ?? "github.com");
86
- if (host == null) return void 0;
87
- const executable = await findGitHubCliExecutable({ env, platform });
88
- if (executable == null) return void 0;
89
- const token = await readGitHubCliToken({
90
- executable,
91
- hostname: normalizeGitHubHost(host),
92
- env
93
- }).catch(() => void 0);
94
- return isNonEmptyString(token) ? { token: token.trim(), host } : void 0;
32
+ async function readGitHubCopilotSubscription({ env = process.env, homeDirectory = homedir(), platform = process.platform, readSecureCredential, findGitHubCliExecutable = findHostGitHubCliExecutable, readGitHubCliToken = readHostGitHubCliToken } = {}) {
33
+ const copilotHome = resolve(env.COPILOT_HOME ?? join(homeDirectory, ".copilot"));
34
+ const config = await readGitHubCopilotConfig({ path: join(copilotHome, "config.json") });
35
+ const account = selectGitHubCopilotAccount({ config });
36
+ if (account != null) {
37
+ const accountKey = `${account.host}:${account.login}`;
38
+ const secureToken = await (readSecureCredential ?? ((options) => readGitHubCopilotSecureCredential({
39
+ ...options,
40
+ platform
41
+ })))({
42
+ service: COPILOT_KEYRING_SERVICE,
43
+ account: accountKey
44
+ }).catch(() => void 0);
45
+ if (isNonEmptyString(secureToken)) return {
46
+ token: secureToken,
47
+ host: account.host
48
+ };
49
+ const plaintextToken = getPlaintextToken({
50
+ config,
51
+ accountKey
52
+ });
53
+ if (plaintextToken != null) return {
54
+ token: plaintextToken,
55
+ host: account.host
56
+ };
57
+ }
58
+ const host = account?.host ?? normalizeGitHubOrigin(env.COPILOT_GH_HOST ?? env.GH_HOST ?? "github.com");
59
+ if (host == null) return void 0;
60
+ const executable = await findGitHubCliExecutable({
61
+ env,
62
+ platform
63
+ });
64
+ if (executable == null) return void 0;
65
+ const token = await readGitHubCliToken({
66
+ executable,
67
+ hostname: normalizeGitHubHost(host),
68
+ env
69
+ }).catch(() => void 0);
70
+ return isNonEmptyString(token) ? {
71
+ token: token.trim(),
72
+ host
73
+ } : void 0;
95
74
  }
96
- async function findHostGitHubCliExecutable({
97
- env,
98
- platform
99
- }) {
100
- const path = env.PATH ?? env.Path ?? env.path;
101
- if (path == null) return void 0;
102
- const separator = isWindows(platform) ? ";" : ":";
103
- const names = isWindows(platform) ? getWindowsGitHubCliExecutableNames({ pathExt: env.PATHEXT }) : ["gh"];
104
- const mode = isWindows(platform) ? constants.F_OK : constants.X_OK;
105
- for (const directory of path.split(separator)) {
106
- const normalizedDirectory = directory.replace(/^"|"$/g, "");
107
- if (normalizedDirectory.length === 0) continue;
108
- for (const executableName of names) {
109
- const candidate = resolve(normalizedDirectory, executableName);
110
- try {
111
- await access(candidate, mode);
112
- return candidate;
113
- } catch {
114
- }
115
- }
116
- }
75
+ async function findHostGitHubCliExecutable({ env, platform }) {
76
+ const path = env.PATH ?? env.Path ?? env.path;
77
+ if (path == null) return void 0;
78
+ const separator = isWindows(platform) ? ";" : ":";
79
+ const names = isWindows(platform) ? getWindowsGitHubCliExecutableNames({ pathExt: env.PATHEXT }) : ["gh"];
80
+ const mode = isWindows(platform) ? constants.F_OK : constants.X_OK;
81
+ for (const directory of path.split(separator)) {
82
+ const normalizedDirectory = directory.replace(/^"|"$/g, "");
83
+ if (normalizedDirectory.length === 0) continue;
84
+ for (const executableName of names) {
85
+ const candidate = resolve(normalizedDirectory, executableName);
86
+ try {
87
+ await access(candidate, mode);
88
+ return candidate;
89
+ } catch {}
90
+ }
91
+ }
117
92
  }
118
- async function readGitHubCopilotConfig({
119
- path
120
- }) {
121
- const text = await readFile(path, "utf8").catch(() => void 0);
122
- if (text == null) return void 0;
123
- const errors = [];
124
- const value = parse(text, errors, { allowTrailingComma: true });
125
- return errors.length === 0 && isRecord(value) ? value : void 0;
93
+ async function readGitHubCopilotConfig({ path }) {
94
+ const text = await readFile(path, "utf8").catch(() => void 0);
95
+ if (text == null) return void 0;
96
+ const errors = [];
97
+ const value = parse(text, errors, { allowTrailingComma: true });
98
+ return errors.length === 0 && isRecord(value) ? value : void 0;
126
99
  }
127
- function selectGitHubCopilotAccount({
128
- config
129
- }) {
130
- if (config == null) return void 0;
131
- for (const value of [config.last_logged_in_user, config.lastLoggedInUser]) {
132
- const account = toGitHubCopilotAccount(value);
133
- if (account != null) return account;
134
- }
135
- for (const values of [config.logged_in_users, config.loggedInUsers]) {
136
- if (!Array.isArray(values)) continue;
137
- for (const value of values) {
138
- const account = toGitHubCopilotAccount(value);
139
- if (account != null) return account;
140
- }
141
- }
100
+ function selectGitHubCopilotAccount({ config }) {
101
+ if (config == null) return void 0;
102
+ for (const value of [config.last_logged_in_user, config.lastLoggedInUser]) {
103
+ const account = toGitHubCopilotAccount(value);
104
+ if (account != null) return account;
105
+ }
106
+ for (const values of [config.logged_in_users, config.loggedInUsers]) {
107
+ if (!Array.isArray(values)) continue;
108
+ for (const value of values) {
109
+ const account = toGitHubCopilotAccount(value);
110
+ if (account != null) return account;
111
+ }
112
+ }
142
113
  }
143
114
  function toGitHubCopilotAccount(value) {
144
- if (!isRecord(value) || !isNonEmptyString(value.host) || !isNonEmptyString(value.login)) {
145
- return void 0;
146
- }
147
- const host = normalizeGitHubOrigin(value.host);
148
- return host == null ? void 0 : { host, login: value.login };
115
+ if (!isRecord(value) || !isNonEmptyString(value.host) || !isNonEmptyString(value.login)) return;
116
+ const host = normalizeGitHubOrigin(value.host);
117
+ return host == null ? void 0 : {
118
+ host,
119
+ login: value.login
120
+ };
149
121
  }
150
- function getPlaintextToken({
151
- config,
152
- accountKey
153
- }) {
154
- if (config == null || !isRecord(config.copilotTokens)) return void 0;
155
- const token = config.copilotTokens[accountKey];
156
- return isNonEmptyString(token) ? token : void 0;
122
+ function getPlaintextToken({ config, accountKey }) {
123
+ if (config == null || !isRecord(config.copilotTokens)) return void 0;
124
+ const token = config.copilotTokens[accountKey];
125
+ return isNonEmptyString(token) ? token : void 0;
157
126
  }
158
- async function readGitHubCopilotSecureCredential({
159
- service,
160
- account,
161
- platform
162
- }) {
163
- if (isMacOS(platform)) {
164
- return readMacOSKeychainPassword({ service, account });
165
- }
166
- if (isLinux(platform)) {
167
- return readLinuxSecretServicePassword({
168
- attributes: { service, username: account }
169
- });
170
- }
171
- if (isWindows(platform)) {
172
- return readWindowsCredentialManagerPassword({
173
- targetName: `${account}.${service}`
174
- });
175
- }
127
+ async function readGitHubCopilotSecureCredential({ service, account, platform }) {
128
+ if (isMacOS(platform)) return readMacOSKeychainPassword({
129
+ service,
130
+ account
131
+ });
132
+ if (isLinux(platform)) return readLinuxSecretServicePassword({ attributes: {
133
+ service,
134
+ username: account
135
+ } });
136
+ if (isWindows(platform)) return readWindowsCredentialManagerPassword({ targetName: `${account}.${service}` });
176
137
  }
177
- async function readHostGitHubCliToken({
178
- executable,
179
- hostname,
180
- env
181
- }) {
182
- try {
183
- const result = await execFileAsync(
184
- executable,
185
- ["auth", "token", "--hostname", hostname],
186
- {
187
- env: { ...env },
188
- timeout: 1e4,
189
- windowsHide: true
190
- }
191
- );
192
- return isNonEmptyString(result.stdout) ? result.stdout.trim() : void 0;
193
- } catch {
194
- return void 0;
195
- }
138
+ async function readHostGitHubCliToken({ executable, hostname, env }) {
139
+ try {
140
+ const result = await execFileAsync(executable, [
141
+ "auth",
142
+ "token",
143
+ "--hostname",
144
+ hostname
145
+ ], {
146
+ env: { ...env },
147
+ timeout: 1e4,
148
+ windowsHide: true
149
+ });
150
+ return isNonEmptyString(result.stdout) ? result.stdout.trim() : void 0;
151
+ } catch {
152
+ return;
153
+ }
196
154
  }
197
- function getWindowsGitHubCliExecutableNames({
198
- pathExt
199
- }) {
200
- const extensions = (pathExt ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(isNonEmptyString);
201
- return ["gh", ...extensions.map((extension) => `gh${extension}`)];
155
+ function getWindowsGitHubCliExecutableNames({ pathExt }) {
156
+ return ["gh", ...(pathExt ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(isNonEmptyString).map((extension) => `gh${extension}`)];
202
157
  }
203
158
  function normalizeGitHubOrigin(host) {
204
- try {
205
- return new URL(host.includes("://") ? host : `https://${host}`).origin;
206
- } catch {
207
- return void 0;
208
- }
159
+ try {
160
+ return new URL(host.includes("://") ? host : `https://${host}`).origin;
161
+ } catch {
162
+ return;
163
+ }
209
164
  }
210
165
  function normalizeGitHubHost(host) {
211
- return new URL(host.includes("://") ? host : `https://${host}`).hostname;
166
+ return new URL(host.includes("://") ? host : `https://${host}`).hostname;
212
167
  }
213
168
  function isNonEmptyString(value) {
214
- return typeof value === "string" && value.trim().length > 0;
169
+ return typeof value === "string" && value.trim().length > 0;
215
170
  }
216
-
217
- // src/version.ts
218
- var VERSION = true ? "1.0.28" : "0.0.0-test";
219
-
220
- // src/github-copilot-harness.ts
221
- var GITHUB_COPILOT_CLIENT_APP = {
222
- name: "ai-sdk-harness-github-copilot",
223
- version: VERSION
171
+ //#endregion
172
+ //#region src/version.ts
173
+ const VERSION = "1.0.30";
174
+ //#endregion
175
+ //#region src/github-copilot-harness.ts
176
+ const GITHUB_COPILOT_CLIENT_APP = {
177
+ name: "ai-sdk-harness-github-copilot",
178
+ version: VERSION
224
179
  };
225
- var GITHUB_COPILOT_IMPLEMENTATION_PACKAGE_JSON = '{\n "name": "harness-github-copilot-bridge",\n "version": "0.0.0",\n "private": true,\n "type": "module",\n "dependencies": {\n "@github/copilot": "1.0.86"\n }\n}\n';
226
- var GITHUB_COPILOT_IMPLEMENTATION_PNPM_LOCK = "lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n excludeLinksFromLockfile: false\n\nimporters:\n\n .:\n dependencies:\n '@github/copilot':\n specifier: 1.0.86\n version: 1.0.86\n\npackages:\n\n '@github/copilot-darwin-arm64@1.0.86':\n resolution: {integrity: sha512-OinxattAYZqcVCQPPdlcgMga5a8BgVOXzz9F9qulUOIv+98fWE2mRX7R1s1W+LrqxmHQts6TKROXOBWtcRpdHA==}\n cpu: [arm64]\n os: [darwin]\n hasBin: true\n\n '@github/copilot-darwin-x64@1.0.86':\n resolution: {integrity: sha512-YXOsXwDvXa6nQDdw3GRukJ1mOPiw/lCnL4hjxhs7lSlcI6Eep/6qnKHrRtWE+pGjLgrgxGRa5grjpr1oq4HitA==}\n cpu: [x64]\n os: [darwin]\n hasBin: true\n\n '@github/copilot-linux-arm64@1.0.86':\n resolution: {integrity: sha512-HbzCTIsfr7XrX+A+PzdzPrTAahkycizof/7jD66yKlUlSiDK1aOtQSymK8vIViMZfEhSZrY9OUp4atBEmnfk+w==}\n cpu: [arm64]\n os: [linux]\n libc: [glibc]\n hasBin: true\n\n '@github/copilot-linux-x64@1.0.86':\n resolution: {integrity: sha512-ROyWMEP8nKFoa+7l2majzfgA5jaqid0qEYTClf9oooS+8S6CIhKYlW1VO6Lt3lDicoCI1S2RWbR7vJ6ZQy/TFw==}\n cpu: [x64]\n os: [linux]\n libc: [glibc]\n hasBin: true\n\n '@github/copilot-linuxmusl-arm64@1.0.86':\n resolution: {integrity: sha512-JcUBGRDgoIa97pudDCfNPUsKpLwpymWf0nWaVlDiKp4U7NW4BD6AGehlsYsOOcUL6b4IooApQ6XDwjOlg/PYvw==}\n cpu: [arm64]\n os: [linux]\n libc: [musl]\n hasBin: true\n\n '@github/copilot-linuxmusl-x64@1.0.86':\n resolution: {integrity: sha512-+BmL8Ud4A5OxHTqci6mR/twNbVQh6yho6yFGermaH73cRo0CLC17Hkxo2MU3HoH8BYmtJeiXiJ2YB7lsWax1mA==}\n cpu: [x64]\n os: [linux]\n libc: [musl]\n hasBin: true\n\n '@github/copilot-win32-arm64@1.0.86':\n resolution: {integrity: sha512-sFxcEv21/6r+HS6T3LIU40KMV80jIEIU4P3enqjqhTBH5wQiF1+TVsVNn+jlI5UIV7+P1jjP6JujuLAAwoC6UA==}\n cpu: [arm64]\n os: [win32]\n hasBin: true\n\n '@github/copilot-win32-x64@1.0.86':\n resolution: {integrity: sha512-U/O/eXe/Q8ndEgSFFscZxhbYpAJ9jFRvBclFW0zsoTX8h2nGxoC1seVxpeqXGQezOsKdMT/fIYWG2XfhPQ/gsg==}\n cpu: [x64]\n os: [win32]\n hasBin: true\n\n '@github/copilot@1.0.86':\n resolution: {integrity: sha512-ytl6vkox1l6Y+UqLhX0+SOuTkS84VCp8R2CJqzgJ8QfnOlWe3U6z1ZVRm/sYWGMLchWQpnC7d+wWZ1mTUTFuuQ==}\n hasBin: true\n\n detect-libc@2.1.2:\n resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==}\n engines: {node: '>=8'}\n\nsnapshots:\n\n '@github/copilot-darwin-arm64@1.0.86':\n optional: true\n\n '@github/copilot-darwin-x64@1.0.86':\n optional: true\n\n '@github/copilot-linux-arm64@1.0.86':\n optional: true\n\n '@github/copilot-linux-x64@1.0.86':\n optional: true\n\n '@github/copilot-linuxmusl-arm64@1.0.86':\n optional: true\n\n '@github/copilot-linuxmusl-x64@1.0.86':\n optional: true\n\n '@github/copilot-win32-arm64@1.0.86':\n optional: true\n\n '@github/copilot-win32-x64@1.0.86':\n optional: true\n\n '@github/copilot@1.0.86':\n dependencies:\n detect-libc: 2.1.2\n optionalDependencies:\n '@github/copilot-darwin-arm64': 1.0.86\n '@github/copilot-darwin-x64': 1.0.86\n '@github/copilot-linux-arm64': 1.0.86\n '@github/copilot-linux-x64': 1.0.86\n '@github/copilot-linuxmusl-arm64': 1.0.86\n '@github/copilot-linuxmusl-x64': 1.0.86\n '@github/copilot-win32-arm64': 1.0.86\n '@github/copilot-win32-x64': 1.0.86\n\n detect-libc@2.1.2: {}\n";
227
- var GITHUB_COPILOT_IMPLEMENTATION_PNPM_WORKSPACE = "allowBuilds:\n '@github/copilot@1.0.86': true\n";
228
- var GITHUB_COPILOT_TOKEN_ENVIRONMENT_VARIABLES = /* @__PURE__ */ new Set([
229
- "COPILOT_GITHUB_TOKEN",
230
- "GH_TOKEN",
231
- "GITHUB_TOKEN"
180
+ const GITHUB_COPILOT_IMPLEMENTATION_PACKAGE_JSON = "{\n \"name\": \"harness-github-copilot-bridge\",\n \"version\": \"0.0.0\",\n \"private\": true,\n \"type\": \"module\",\n \"dependencies\": {\n \"@github/copilot\": \"1.0.86\"\n }\n}\n";
181
+ const GITHUB_COPILOT_IMPLEMENTATION_PNPM_LOCK = "lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n excludeLinksFromLockfile: false\n\nimporters:\n\n .:\n dependencies:\n '@github/copilot':\n specifier: 1.0.86\n version: 1.0.86\n\npackages:\n\n '@github/copilot-darwin-arm64@1.0.86':\n resolution: {integrity: sha512-OinxattAYZqcVCQPPdlcgMga5a8BgVOXzz9F9qulUOIv+98fWE2mRX7R1s1W+LrqxmHQts6TKROXOBWtcRpdHA==}\n cpu: [arm64]\n os: [darwin]\n hasBin: true\n\n '@github/copilot-darwin-x64@1.0.86':\n resolution: {integrity: sha512-YXOsXwDvXa6nQDdw3GRukJ1mOPiw/lCnL4hjxhs7lSlcI6Eep/6qnKHrRtWE+pGjLgrgxGRa5grjpr1oq4HitA==}\n cpu: [x64]\n os: [darwin]\n hasBin: true\n\n '@github/copilot-linux-arm64@1.0.86':\n resolution: {integrity: sha512-HbzCTIsfr7XrX+A+PzdzPrTAahkycizof/7jD66yKlUlSiDK1aOtQSymK8vIViMZfEhSZrY9OUp4atBEmnfk+w==}\n cpu: [arm64]\n os: [linux]\n libc: [glibc]\n hasBin: true\n\n '@github/copilot-linux-x64@1.0.86':\n resolution: {integrity: sha512-ROyWMEP8nKFoa+7l2majzfgA5jaqid0qEYTClf9oooS+8S6CIhKYlW1VO6Lt3lDicoCI1S2RWbR7vJ6ZQy/TFw==}\n cpu: [x64]\n os: [linux]\n libc: [glibc]\n hasBin: true\n\n '@github/copilot-linuxmusl-arm64@1.0.86':\n resolution: {integrity: sha512-JcUBGRDgoIa97pudDCfNPUsKpLwpymWf0nWaVlDiKp4U7NW4BD6AGehlsYsOOcUL6b4IooApQ6XDwjOlg/PYvw==}\n cpu: [arm64]\n os: [linux]\n libc: [musl]\n hasBin: true\n\n '@github/copilot-linuxmusl-x64@1.0.86':\n resolution: {integrity: sha512-+BmL8Ud4A5OxHTqci6mR/twNbVQh6yho6yFGermaH73cRo0CLC17Hkxo2MU3HoH8BYmtJeiXiJ2YB7lsWax1mA==}\n cpu: [x64]\n os: [linux]\n libc: [musl]\n hasBin: true\n\n '@github/copilot-win32-arm64@1.0.86':\n resolution: {integrity: sha512-sFxcEv21/6r+HS6T3LIU40KMV80jIEIU4P3enqjqhTBH5wQiF1+TVsVNn+jlI5UIV7+P1jjP6JujuLAAwoC6UA==}\n cpu: [arm64]\n os: [win32]\n hasBin: true\n\n '@github/copilot-win32-x64@1.0.86':\n resolution: {integrity: sha512-U/O/eXe/Q8ndEgSFFscZxhbYpAJ9jFRvBclFW0zsoTX8h2nGxoC1seVxpeqXGQezOsKdMT/fIYWG2XfhPQ/gsg==}\n cpu: [x64]\n os: [win32]\n hasBin: true\n\n '@github/copilot@1.0.86':\n resolution: {integrity: sha512-ytl6vkox1l6Y+UqLhX0+SOuTkS84VCp8R2CJqzgJ8QfnOlWe3U6z1ZVRm/sYWGMLchWQpnC7d+wWZ1mTUTFuuQ==}\n hasBin: true\n\n detect-libc@2.1.2:\n resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==}\n engines: {node: '>=8'}\n\nsnapshots:\n\n '@github/copilot-darwin-arm64@1.0.86':\n optional: true\n\n '@github/copilot-darwin-x64@1.0.86':\n optional: true\n\n '@github/copilot-linux-arm64@1.0.86':\n optional: true\n\n '@github/copilot-linux-x64@1.0.86':\n optional: true\n\n '@github/copilot-linuxmusl-arm64@1.0.86':\n optional: true\n\n '@github/copilot-linuxmusl-x64@1.0.86':\n optional: true\n\n '@github/copilot-win32-arm64@1.0.86':\n optional: true\n\n '@github/copilot-win32-x64@1.0.86':\n optional: true\n\n '@github/copilot@1.0.86':\n dependencies:\n detect-libc: 2.1.2\n optionalDependencies:\n '@github/copilot-darwin-arm64': 1.0.86\n '@github/copilot-darwin-x64': 1.0.86\n '@github/copilot-linux-arm64': 1.0.86\n '@github/copilot-linux-x64': 1.0.86\n '@github/copilot-linuxmusl-arm64': 1.0.86\n '@github/copilot-linuxmusl-x64': 1.0.86\n '@github/copilot-win32-arm64': 1.0.86\n '@github/copilot-win32-x64': 1.0.86\n\n detect-libc@2.1.2: {}\n";
182
+ const GITHUB_COPILOT_IMPLEMENTATION_PNPM_WORKSPACE = "allowBuilds:\n '@github/copilot@1.0.86': true\n";
183
+ const GITHUB_COPILOT_TOKEN_ENVIRONMENT_VARIABLES = /* @__PURE__ */ new Set([
184
+ "COPILOT_GITHUB_TOKEN",
185
+ "GH_TOKEN",
186
+ "GITHUB_TOKEN"
232
187
  ]);
233
- var GITHUB_OAUTH_TOKEN_BODY_LENGTH = 36;
234
- var GITHUB_OAUTH_SANDBOX_CREDENTIAL_MARKER = "aisdkhc";
235
- var GITHUB_COPILOT_BUILTIN_TOOLS = {
236
- bash: {
237
- ...commonTool("bash", {
238
- nativeName: "bash",
239
- toolUseKind: "bash",
240
- inputSchema: z.looseObject({
241
- command: z.string(),
242
- description: z.string().optional(),
243
- shellId: z.string().optional(),
244
- mode: z.enum(["sync", "async"]).optional(),
245
- detach: z.boolean().optional(),
246
- initial_wait: z.number().optional()
247
- })
248
- })
249
- },
250
- read_bash: {
251
- ...tool({
252
- title: "Reading shell output",
253
- inputSchema: z.looseObject({
254
- shellId: z.string(),
255
- delay: z.number()
256
- })
257
- }),
258
- toolUseKind: "readonly"
259
- },
260
- stop_bash: {
261
- ...tool({
262
- title: "Stopping shell session",
263
- inputSchema: z.looseObject({ shellId: z.string() })
264
- }),
265
- toolUseKind: "bash"
266
- },
267
- list_bash: {
268
- ...tool({
269
- title: "list_bash",
270
- inputSchema: z.looseObject({})
271
- }),
272
- toolUseKind: "readonly"
273
- },
274
- view: {
275
- ...tool({
276
- title: "Viewing ",
277
- inputSchema: z.looseObject({
278
- path: z.string(),
279
- view_range: z.array(z.number()).optional(),
280
- forceReadLargeFiles: z.boolean().optional()
281
- })
282
- }),
283
- toolUseKind: "readonly"
284
- },
285
- create: {
286
- ...tool({
287
- title: "Creating ",
288
- inputSchema: z.looseObject({
289
- path: z.string(),
290
- file_text: z.string()
291
- })
292
- }),
293
- toolUseKind: "edit"
294
- },
295
- edit: {
296
- ...tool({
297
- title: "Editing ",
298
- inputSchema: z.looseObject({
299
- path: z.string(),
300
- old_str: z.string().optional(),
301
- new_str: z.string()
302
- })
303
- }),
304
- toolUseKind: "edit"
305
- },
306
- web_fetch: {
307
- ...tool({
308
- title: "Fetching ",
309
- inputSchema: z.looseObject({
310
- url: z.string(),
311
- max_length: z.number().optional(),
312
- start_index: z.number().optional(),
313
- raw: z.boolean().optional()
314
- })
315
- }),
316
- toolUseKind: "readonly"
317
- },
318
- skill: tool({
319
- title: "Using skill: ",
320
- inputSchema: z.looseObject({ skill: z.string() })
321
- }),
322
- sql: tool({
323
- inputSchema: z.looseObject({
324
- description: z.string(),
325
- query: z.string(),
326
- database: z.enum(["session", "session_store"]).optional()
327
- })
328
- }),
329
- read_agent: {
330
- ...tool({
331
- title: "read_agent",
332
- inputSchema: z.looseObject({
333
- agent_id: z.string(),
334
- wait: z.boolean().optional(),
335
- timeout: z.number().optional(),
336
- since_turn: z.number().int().nonnegative().optional()
337
- })
338
- }),
339
- toolUseKind: "readonly"
340
- },
341
- list_agents: {
342
- ...tool({
343
- title: "list_agents",
344
- inputSchema: z.looseObject({
345
- include_completed: z.boolean().optional(),
346
- scope: z.enum(["siblings", "children", "all"]).optional()
347
- })
348
- }),
349
- toolUseKind: "readonly"
350
- },
351
- write_agent: tool({
352
- title: "write_agent",
353
- inputSchema: z.looseObject({
354
- message: z.string(),
355
- agent_id: z.string().optional(),
356
- agent_ids: z.array(z.string()).optional(),
357
- scope: z.enum(["siblings", "children"]).optional()
358
- })
359
- }),
360
- grep: {
361
- ...commonTool("grep", {
362
- nativeName: "grep",
363
- toolUseKind: "readonly",
364
- inputSchema: z.looseObject({
365
- pattern: z.string(),
366
- path: z.string().optional(),
367
- paths: z.array(z.string()).optional(),
368
- glob: z.string().optional(),
369
- output_mode: z.enum(["content", "files_with_matches", "count"]).optional(),
370
- case_insensitive: z.boolean().optional(),
371
- multiline: z.boolean().optional(),
372
- head_limit: z.number().optional(),
373
- context: z.number().optional(),
374
- before_context: z.number().optional(),
375
- after_context: z.number().optional()
376
- })
377
- }),
378
- title: "Searching for "
379
- },
380
- glob: {
381
- ...commonTool("glob", {
382
- nativeName: "glob",
383
- toolUseKind: "readonly",
384
- inputSchema: z.looseObject({
385
- pattern: z.string(),
386
- paths: z.array(z.string()).optional()
387
- })
388
- }),
389
- title: "Finding files matching "
390
- },
391
- task: tool({
392
- inputSchema: z.looseObject({
393
- name: z.string(),
394
- prompt: z.string(),
395
- agent_type: z.enum([
396
- "explore",
397
- "task",
398
- "general-purpose",
399
- "code-review",
400
- "research",
401
- "security-review"
402
- ]),
403
- description: z.string(),
404
- model: z.string().optional(),
405
- context_tier: z.enum(["default", "long_context"]).optional(),
406
- mode: z.enum(["sync", "background"]).optional()
407
- })
408
- })
188
+ const GITHUB_OAUTH_SANDBOX_CREDENTIAL_MARKER = "aisdkhc";
189
+ const GITHUB_COPILOT_BUILTIN_TOOLS = {
190
+ bash: { ...commonTool("bash", {
191
+ nativeName: "bash",
192
+ toolUseKind: "bash",
193
+ inputSchema: z.looseObject({
194
+ command: z.string(),
195
+ description: z.string().optional(),
196
+ shellId: z.string().optional(),
197
+ mode: z.enum(["sync", "async"]).optional(),
198
+ detach: z.boolean().optional(),
199
+ initial_wait: z.number().optional()
200
+ })
201
+ }) },
202
+ read_bash: {
203
+ ...tool({
204
+ title: "Reading shell output",
205
+ inputSchema: z.looseObject({
206
+ shellId: z.string(),
207
+ delay: z.number()
208
+ })
209
+ }),
210
+ toolUseKind: "readonly"
211
+ },
212
+ stop_bash: {
213
+ ...tool({
214
+ title: "Stopping shell session",
215
+ inputSchema: z.looseObject({ shellId: z.string() })
216
+ }),
217
+ toolUseKind: "bash"
218
+ },
219
+ list_bash: {
220
+ ...tool({
221
+ title: "list_bash",
222
+ inputSchema: z.looseObject({})
223
+ }),
224
+ toolUseKind: "readonly"
225
+ },
226
+ view: {
227
+ ...tool({
228
+ title: "Viewing ",
229
+ inputSchema: z.looseObject({
230
+ path: z.string(),
231
+ view_range: z.array(z.number()).optional(),
232
+ forceReadLargeFiles: z.boolean().optional()
233
+ })
234
+ }),
235
+ toolUseKind: "readonly"
236
+ },
237
+ create: {
238
+ ...tool({
239
+ title: "Creating ",
240
+ inputSchema: z.looseObject({
241
+ path: z.string(),
242
+ file_text: z.string()
243
+ })
244
+ }),
245
+ toolUseKind: "edit"
246
+ },
247
+ edit: {
248
+ ...tool({
249
+ title: "Editing ",
250
+ inputSchema: z.looseObject({
251
+ path: z.string(),
252
+ old_str: z.string().optional(),
253
+ new_str: z.string()
254
+ })
255
+ }),
256
+ toolUseKind: "edit"
257
+ },
258
+ web_fetch: {
259
+ ...tool({
260
+ title: "Fetching ",
261
+ inputSchema: z.looseObject({
262
+ url: z.string(),
263
+ max_length: z.number().optional(),
264
+ start_index: z.number().optional(),
265
+ raw: z.boolean().optional()
266
+ })
267
+ }),
268
+ toolUseKind: "readonly"
269
+ },
270
+ skill: tool({
271
+ title: "Using skill: ",
272
+ inputSchema: z.looseObject({ skill: z.string() })
273
+ }),
274
+ sql: tool({ inputSchema: z.looseObject({
275
+ description: z.string(),
276
+ query: z.string(),
277
+ database: z.enum(["session", "session_store"]).optional()
278
+ }) }),
279
+ read_agent: {
280
+ ...tool({
281
+ title: "read_agent",
282
+ inputSchema: z.looseObject({
283
+ agent_id: z.string(),
284
+ wait: z.boolean().optional(),
285
+ timeout: z.number().optional(),
286
+ since_turn: z.number().int().nonnegative().optional()
287
+ })
288
+ }),
289
+ toolUseKind: "readonly"
290
+ },
291
+ list_agents: {
292
+ ...tool({
293
+ title: "list_agents",
294
+ inputSchema: z.looseObject({
295
+ include_completed: z.boolean().optional(),
296
+ scope: z.enum([
297
+ "siblings",
298
+ "children",
299
+ "all"
300
+ ]).optional()
301
+ })
302
+ }),
303
+ toolUseKind: "readonly"
304
+ },
305
+ write_agent: tool({
306
+ title: "write_agent",
307
+ inputSchema: z.looseObject({
308
+ message: z.string(),
309
+ agent_id: z.string().optional(),
310
+ agent_ids: z.array(z.string()).optional(),
311
+ scope: z.enum(["siblings", "children"]).optional()
312
+ })
313
+ }),
314
+ grep: {
315
+ ...commonTool("grep", {
316
+ nativeName: "grep",
317
+ toolUseKind: "readonly",
318
+ inputSchema: z.looseObject({
319
+ pattern: z.string(),
320
+ path: z.string().optional(),
321
+ paths: z.array(z.string()).optional(),
322
+ glob: z.string().optional(),
323
+ output_mode: z.enum([
324
+ "content",
325
+ "files_with_matches",
326
+ "count"
327
+ ]).optional(),
328
+ case_insensitive: z.boolean().optional(),
329
+ multiline: z.boolean().optional(),
330
+ head_limit: z.number().optional(),
331
+ context: z.number().optional(),
332
+ before_context: z.number().optional(),
333
+ after_context: z.number().optional()
334
+ })
335
+ }),
336
+ title: "Searching for "
337
+ },
338
+ glob: {
339
+ ...commonTool("glob", {
340
+ nativeName: "glob",
341
+ toolUseKind: "readonly",
342
+ inputSchema: z.looseObject({
343
+ pattern: z.string(),
344
+ paths: z.array(z.string()).optional()
345
+ })
346
+ }),
347
+ title: "Finding files matching "
348
+ },
349
+ task: tool({ inputSchema: z.looseObject({
350
+ name: z.string(),
351
+ prompt: z.string(),
352
+ agent_type: z.enum([
353
+ "explore",
354
+ "task",
355
+ "general-purpose",
356
+ "code-review",
357
+ "research",
358
+ "security-review"
359
+ ]),
360
+ description: z.string(),
361
+ model: z.string().optional(),
362
+ context_tier: z.enum(["default", "long_context"]).optional(),
363
+ mode: z.enum(["sync", "background"]).optional()
364
+ }) })
409
365
  };
410
366
  function createGitHubCopilot(settings = {}) {
411
- const mcpToolTitlePrefixes = [
412
- "github-mcp-server-",
413
- ...Object.keys(settings.mcpServers ?? {}).map((name) => `${name}-`)
414
- ];
415
- return createACP({
416
- version: "v1",
417
- harnessId: "github-copilot",
418
- clientApp: GITHUB_COPILOT_CLIENT_APP,
419
- source: {
420
- type: "npm-locked",
421
- packageJson: GITHUB_COPILOT_IMPLEMENTATION_PACKAGE_JSON,
422
- pnpmLockYaml: GITHUB_COPILOT_IMPLEMENTATION_PNPM_LOCK,
423
- pnpmWorkspaceYaml: GITHUB_COPILOT_IMPLEMENTATION_PNPM_WORKSPACE
424
- },
425
- executable: "copilot",
426
- args: [
427
- "--acp",
428
- "--stdio",
429
- "--no-auto-update",
430
- ...settings.reasoningEffort == null ? [] : [`--reasoning-effort=${settings.reasoningEffort}`]
431
- ],
432
- auth: settings.auth,
433
- resolveAuthenticationEnvironment: resolveGitHubCopilotSubscriptionEnvironment,
434
- /*
435
- * The Copilot CLI drops every MCP server that a client passes in ACP
436
- * `session/new` unless it is declared with the `http` or `sse` transport,
437
- * so host tools must be exposed over the bridge's HTTP MCP endpoint.
438
- */
439
- hostToolMcpTransport: "http",
440
- forwardEnv: ["COPILOT_GH_HOST", "GH_HOST"],
441
- credentialEnv: ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"],
442
- credentialBrokering: ({ env, sandboxEnv, headers }) => {
443
- const transformations = [];
444
- const githubHost = normalizeGitHubHost(
445
- env.COPILOT_GH_HOST ?? env.GH_HOST ?? "github.com"
446
- );
447
- const githubHosts = [
448
- githubHost,
449
- `*.${githubHost}`,
450
- ...githubHost === "github.com" ? ["githubcopilot.com", "*.githubcopilot.com"] : []
451
- ];
452
- for (const host of githubHosts) {
453
- if (env.COPILOT_GITHUB_TOKEN && sandboxEnv?.COPILOT_GITHUB_TOKEN) {
454
- transformations.push(
455
- {
456
- match: {
457
- host,
458
- headers: [
459
- {
460
- key: { exact: "Authorization" },
461
- value: {
462
- exact: `Bearer ${sandboxEnv.COPILOT_GITHUB_TOKEN}`
463
- }
464
- }
465
- ]
466
- },
467
- transform: {
468
- headers: {
469
- Authorization: `Bearer ${env.COPILOT_GITHUB_TOKEN}`
470
- }
471
- }
472
- },
473
- {
474
- match: {
475
- host,
476
- headers: [
477
- {
478
- key: { exact: "Authorization" },
479
- value: {
480
- exact: `token ${sandboxEnv.COPILOT_GITHUB_TOKEN}`
481
- }
482
- }
483
- ]
484
- },
485
- transform: {
486
- headers: {
487
- Authorization: `token ${env.COPILOT_GITHUB_TOKEN}`
488
- }
489
- }
490
- }
491
- );
492
- }
493
- if (env.GH_TOKEN && sandboxEnv?.GH_TOKEN) {
494
- transformations.push(
495
- {
496
- match: {
497
- host,
498
- headers: [
499
- {
500
- key: { exact: "Authorization" },
501
- value: { exact: `Bearer ${sandboxEnv.GH_TOKEN}` }
502
- }
503
- ]
504
- },
505
- transform: {
506
- headers: { Authorization: `Bearer ${env.GH_TOKEN}` }
507
- }
508
- },
509
- {
510
- match: {
511
- host,
512
- headers: [
513
- {
514
- key: { exact: "Authorization" },
515
- value: { exact: `token ${sandboxEnv.GH_TOKEN}` }
516
- }
517
- ]
518
- },
519
- transform: {
520
- headers: { Authorization: `token ${env.GH_TOKEN}` }
521
- }
522
- }
523
- );
524
- }
525
- if (env.GITHUB_TOKEN && sandboxEnv?.GITHUB_TOKEN) {
526
- transformations.push(
527
- {
528
- match: {
529
- host,
530
- headers: [
531
- {
532
- key: { exact: "Authorization" },
533
- value: { exact: `Bearer ${sandboxEnv.GITHUB_TOKEN}` }
534
- }
535
- ]
536
- },
537
- transform: {
538
- headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}` }
539
- }
540
- },
541
- {
542
- match: {
543
- host,
544
- headers: [
545
- {
546
- key: { exact: "Authorization" },
547
- value: { exact: `token ${sandboxEnv.GITHUB_TOKEN}` }
548
- }
549
- ]
550
- },
551
- transform: {
552
- headers: { Authorization: `token ${env.GITHUB_TOKEN}` }
553
- }
554
- }
555
- );
556
- }
557
- }
558
- const providerCredential = env.COPILOT_PROVIDER_API_KEY;
559
- const sandboxProviderCredential = sandboxEnv?.COPILOT_PROVIDER_API_KEY;
560
- const providerBaseUrl = env.COPILOT_PROVIDER_BASE_URL;
561
- if (providerCredential && sandboxProviderCredential && providerBaseUrl) {
562
- transformations.push(
563
- createCredentialRequestTransformation({
564
- matchUrl: providerBaseUrl,
565
- matchHeaders: {
566
- Authorization: `Bearer ${sandboxProviderCredential}`
567
- },
568
- transformHeaders: {
569
- ...headers,
570
- Authorization: `Bearer ${providerCredential}`
571
- }
572
- })
573
- );
574
- } else if (headers != null) {
575
- const copilotHosts = githubHost === "github.com" ? ["githubcopilot.com", "*.githubcopilot.com"] : [githubHost, `*.${githubHost}`];
576
- for (const host of copilotHosts) {
577
- transformations.push({
578
- match: { host },
579
- transform: { headers }
580
- });
581
- }
582
- }
583
- return transformations;
584
- },
585
- credentialForwarding: createGitHubCopilotCredentialForwarding({
586
- credentialForwarding: settings.credentialForwarding
587
- }),
588
- providerAuthentication: {
589
- gateway: {
590
- env: {
591
- COPILOT_PROVIDER_BASE_URL: {
592
- $source: "gateway-base-url",
593
- ensureSuffix: "/v1"
594
- },
595
- COPILOT_PROVIDER_TYPE: "openai",
596
- COPILOT_PROVIDER_API_KEY: {
597
- $source: "gateway-api-key"
598
- },
599
- COPILOT_PROVIDER_WIRE_API: "responses",
600
- COPILOT_MODEL: "openai/gpt-5.5",
601
- COPILOT_PROVIDER_HEADERS: {
602
- $source: "client-app",
603
- prefix: "x-client-app: "
604
- }
605
- }
606
- }
607
- },
608
- modelMapping: {
609
- type: "session-config-option",
610
- path: "model"
611
- },
612
- skillsDirectory: ".copilot/skills",
613
- instructionMapping: {
614
- type: "filesystem",
615
- path: ".copilot/copilot-instructions.md"
616
- },
617
- builtinTools: GITHUB_COPILOT_BUILTIN_TOOLS,
618
- mcpServers: settings.mcpServers,
619
- isMcpToolCall: (toolCall) => mcpToolTitlePrefixes.some((prefix) => toolCall.title.startsWith(prefix)),
620
- port: settings.port,
621
- portEndpoint: settings.portEndpoint,
622
- startupTimeoutMs: settings.startupTimeoutMs,
623
- reconnect: settings.reconnect,
624
- mintBridgeToken: settings.mintBridgeToken
625
- });
367
+ const mcpToolTitlePrefixes = ["github-mcp-server-", ...Object.keys(settings.mcpServers ?? {}).map((name) => `${name}-`)];
368
+ return createACP({
369
+ version: "v1",
370
+ harnessId: "github-copilot",
371
+ clientApp: GITHUB_COPILOT_CLIENT_APP,
372
+ source: {
373
+ type: "npm-locked",
374
+ packageJson: GITHUB_COPILOT_IMPLEMENTATION_PACKAGE_JSON,
375
+ pnpmLockYaml: GITHUB_COPILOT_IMPLEMENTATION_PNPM_LOCK,
376
+ pnpmWorkspaceYaml: GITHUB_COPILOT_IMPLEMENTATION_PNPM_WORKSPACE
377
+ },
378
+ executable: "copilot",
379
+ args: [
380
+ "--acp",
381
+ "--stdio",
382
+ "--no-auto-update",
383
+ ...settings.reasoningEffort == null ? [] : [`--reasoning-effort=${settings.reasoningEffort}`]
384
+ ],
385
+ auth: settings.auth,
386
+ resolveAuthenticationEnvironment: resolveGitHubCopilotSubscriptionEnvironment,
387
+ hostToolMcpTransport: "http",
388
+ forwardEnv: ["COPILOT_GH_HOST", "GH_HOST"],
389
+ credentialEnv: [
390
+ "COPILOT_GITHUB_TOKEN",
391
+ "GH_TOKEN",
392
+ "GITHUB_TOKEN"
393
+ ],
394
+ credentialBrokering: ({ env, sandboxEnv, headers }) => {
395
+ const transformations = [];
396
+ const githubHost = normalizeGitHubHost(env.COPILOT_GH_HOST ?? env.GH_HOST ?? "github.com");
397
+ const githubHosts = [
398
+ githubHost,
399
+ `*.${githubHost}`,
400
+ ...githubHost === "github.com" ? ["githubcopilot.com", "*.githubcopilot.com"] : []
401
+ ];
402
+ for (const host of githubHosts) {
403
+ if (env.COPILOT_GITHUB_TOKEN && sandboxEnv?.COPILOT_GITHUB_TOKEN) transformations.push({
404
+ match: {
405
+ host,
406
+ headers: [{
407
+ key: { exact: "Authorization" },
408
+ value: { exact: `Bearer ${sandboxEnv.COPILOT_GITHUB_TOKEN}` }
409
+ }]
410
+ },
411
+ transform: { headers: { Authorization: `Bearer ${env.COPILOT_GITHUB_TOKEN}` } }
412
+ }, {
413
+ match: {
414
+ host,
415
+ headers: [{
416
+ key: { exact: "Authorization" },
417
+ value: { exact: `token ${sandboxEnv.COPILOT_GITHUB_TOKEN}` }
418
+ }]
419
+ },
420
+ transform: { headers: { Authorization: `token ${env.COPILOT_GITHUB_TOKEN}` } }
421
+ });
422
+ if (env.GH_TOKEN && sandboxEnv?.GH_TOKEN) transformations.push({
423
+ match: {
424
+ host,
425
+ headers: [{
426
+ key: { exact: "Authorization" },
427
+ value: { exact: `Bearer ${sandboxEnv.GH_TOKEN}` }
428
+ }]
429
+ },
430
+ transform: { headers: { Authorization: `Bearer ${env.GH_TOKEN}` } }
431
+ }, {
432
+ match: {
433
+ host,
434
+ headers: [{
435
+ key: { exact: "Authorization" },
436
+ value: { exact: `token ${sandboxEnv.GH_TOKEN}` }
437
+ }]
438
+ },
439
+ transform: { headers: { Authorization: `token ${env.GH_TOKEN}` } }
440
+ });
441
+ if (env.GITHUB_TOKEN && sandboxEnv?.GITHUB_TOKEN) transformations.push({
442
+ match: {
443
+ host,
444
+ headers: [{
445
+ key: { exact: "Authorization" },
446
+ value: { exact: `Bearer ${sandboxEnv.GITHUB_TOKEN}` }
447
+ }]
448
+ },
449
+ transform: { headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}` } }
450
+ }, {
451
+ match: {
452
+ host,
453
+ headers: [{
454
+ key: { exact: "Authorization" },
455
+ value: { exact: `token ${sandboxEnv.GITHUB_TOKEN}` }
456
+ }]
457
+ },
458
+ transform: { headers: { Authorization: `token ${env.GITHUB_TOKEN}` } }
459
+ });
460
+ }
461
+ const providerCredential = env.COPILOT_PROVIDER_API_KEY;
462
+ const sandboxProviderCredential = sandboxEnv?.COPILOT_PROVIDER_API_KEY;
463
+ const providerBaseUrl = env.COPILOT_PROVIDER_BASE_URL;
464
+ if (providerCredential && sandboxProviderCredential && providerBaseUrl) transformations.push(createCredentialRequestTransformation({
465
+ matchUrl: providerBaseUrl,
466
+ matchHeaders: { Authorization: `Bearer ${sandboxProviderCredential}` },
467
+ transformHeaders: {
468
+ ...headers,
469
+ Authorization: `Bearer ${providerCredential}`
470
+ }
471
+ }));
472
+ else if (headers != null) {
473
+ const copilotHosts = githubHost === "github.com" ? ["githubcopilot.com", "*.githubcopilot.com"] : [githubHost, `*.${githubHost}`];
474
+ for (const host of copilotHosts) transformations.push({
475
+ match: { host },
476
+ transform: { headers }
477
+ });
478
+ }
479
+ return transformations;
480
+ },
481
+ credentialForwarding: createGitHubCopilotCredentialForwarding({ credentialForwarding: settings.credentialForwarding }),
482
+ providerAuthentication: { gateway: { env: {
483
+ COPILOT_PROVIDER_BASE_URL: {
484
+ $source: "gateway-base-url",
485
+ ensureSuffix: "/v1"
486
+ },
487
+ COPILOT_PROVIDER_TYPE: "openai",
488
+ COPILOT_PROVIDER_API_KEY: { $source: "gateway-api-key" },
489
+ COPILOT_PROVIDER_WIRE_API: "responses",
490
+ COPILOT_MODEL: "openai/gpt-5.5",
491
+ COPILOT_PROVIDER_HEADERS: {
492
+ $source: "client-app",
493
+ prefix: "x-client-app: "
494
+ }
495
+ } } },
496
+ modelMapping: {
497
+ type: "session-config-option",
498
+ path: "model"
499
+ },
500
+ skillsDirectory: ".copilot/skills",
501
+ instructionMapping: {
502
+ type: "filesystem",
503
+ path: ".copilot/copilot-instructions.md"
504
+ },
505
+ builtinTools: GITHUB_COPILOT_BUILTIN_TOOLS,
506
+ mcpServers: settings.mcpServers,
507
+ isMcpToolCall: (toolCall) => mcpToolTitlePrefixes.some((prefix) => toolCall.title.startsWith(prefix)),
508
+ port: settings.port,
509
+ portEndpoint: settings.portEndpoint,
510
+ startupTimeoutMs: settings.startupTimeoutMs,
511
+ reconnect: settings.reconnect,
512
+ mintBridgeToken: settings.mintBridgeToken
513
+ });
626
514
  }
627
- function createGitHubCopilotCredentialForwarding({
628
- credentialForwarding
629
- }) {
630
- return ({ credential, environmentVariableName }) => {
631
- const sandboxCredential = GITHUB_COPILOT_TOKEN_ENVIRONMENT_VARIABLES.has(environmentVariableName) && isSandboxCredentialPlaceholder(credential) ? createGitHubOAuthSandboxCredentialPlaceholder({ credential }) : credential;
632
- return credentialForwarding == null ? sandboxCredential : credentialForwarding({
633
- credential: sandboxCredential,
634
- environmentVariableName
635
- });
636
- };
515
+ function createGitHubCopilotCredentialForwarding({ credentialForwarding }) {
516
+ return ({ credential, environmentVariableName }) => {
517
+ const sandboxCredential = GITHUB_COPILOT_TOKEN_ENVIRONMENT_VARIABLES.has(environmentVariableName) && isSandboxCredentialPlaceholder(credential) ? createGitHubOAuthSandboxCredentialPlaceholder({ credential }) : credential;
518
+ return credentialForwarding == null ? sandboxCredential : credentialForwarding({
519
+ credential: sandboxCredential,
520
+ environmentVariableName
521
+ });
522
+ };
637
523
  }
638
- function createGitHubOAuthSandboxCredentialPlaceholder({
639
- credential
640
- }) {
641
- const tokenBody = createHash("sha256").update(credential).digest("hex").slice(
642
- 0,
643
- GITHUB_OAUTH_TOKEN_BODY_LENGTH - GITHUB_OAUTH_SANDBOX_CREDENTIAL_MARKER.length
644
- );
645
- return `gho_${GITHUB_OAUTH_SANDBOX_CREDENTIAL_MARKER}${tokenBody}`;
524
+ function createGitHubOAuthSandboxCredentialPlaceholder({ credential }) {
525
+ const tokenBody = createHash("sha256").update(credential).digest("hex").slice(0, 29);
526
+ return `gho_${GITHUB_OAUTH_SANDBOX_CREDENTIAL_MARKER}${tokenBody}`;
646
527
  }
528
+ //#endregion
529
+ //#region src/index.ts
530
+ /**
531
+ * Default GitHub Copilot harness instance. Equivalent to
532
+ * `createGitHubCopilot()`.
533
+ */
534
+ const githubCopilot = createGitHubCopilot();
535
+ //#endregion
536
+ export { VERSION, createGitHubCopilot, githubCopilot };
647
537
 
648
- // src/index.ts
649
- var githubCopilot = createGitHubCopilot();
650
- export {
651
- VERSION,
652
- createGitHubCopilot,
653
- githubCopilot
654
- };
655
538
  //# sourceMappingURL=index.js.map