@openclaw/copilot 2026.10.10 → 2026.11.5-beta.1
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 +18 -0
- package/dist/.setup/{attempt-CEEb21Ox.mjs → attempt-BdJgfQV3.mjs} +452 -627
- package/dist/.setup/{harness-DgLcZThQ.mjs → harness-Djqx8viF.mjs} +184 -270
- package/dist/.setup/{isolated-completion-mqRIO1Uo.mjs → isolated-completion-Dp_YaEKF.mjs} +20 -40
- package/dist/.setup/runtime-CAM77uEc.mjs +152 -0
- package/dist/.setup/runtime-artifact-D42RfCpG.mjs +55 -0
- package/dist/.setup/sdk-loader-BXVlNPFC.mjs +144 -0
- package/dist/.setup/session-restrictions-BrC08l2U.mjs +223 -0
- package/dist/.source-module-urls/f7f35489a89dbc0fc6d0e80a0da5720af5de227b511e490a2415ffe55b1bc471.json +1 -1
- package/dist/harness.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/.setup/runtime-DO5cz1WW.mjs +0 -216
- package/dist/.setup/usage-bridge-B9LRA1-s.mjs +0 -74
|
@@ -4,6 +4,7 @@ import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue";
|
|
|
4
4
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
|
+
import { once } from "node:events";
|
|
7
8
|
import { createServer } from "node:http";
|
|
8
9
|
import { Readable } from "node:stream";
|
|
9
10
|
import { pipeline } from "node:stream/promises";
|
|
@@ -12,14 +13,24 @@ import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
|
|
|
12
13
|
// extensions/copilot/src/auth-bridge.ts
|
|
13
14
|
const COPILOT_TOKEN_PROFILE_ERROR = "[copilot-attempt] gitHubToken auth requires profileId+profileVersion (pool keying safety; per Q5/Q1 decisions)";
|
|
14
15
|
const COPILOT_DEFAULT_AGENT_ID = "copilot";
|
|
16
|
+
function sessionAuthFields(auth) {
|
|
17
|
+
return auth.authMode === "gitHubToken" || auth.authMode === "byok" ? {
|
|
18
|
+
authMode: auth.authMode,
|
|
19
|
+
authProfileId: auth.authProfileId,
|
|
20
|
+
authProfileVersion: auth.authProfileVersion
|
|
21
|
+
} : { authMode: "useLoggedInUser" };
|
|
22
|
+
}
|
|
23
|
+
function sessionAuthMatches(stored, current) {
|
|
24
|
+
if (stored.authMode !== current.authMode) return false;
|
|
25
|
+
if (stored.authMode === "useLoggedInUser") return true;
|
|
26
|
+
return stored.authProfileId === current.authProfileId && stored.authProfileVersion === current.authProfileVersion;
|
|
27
|
+
}
|
|
15
28
|
function createCopilotByokAuth(input) {
|
|
16
29
|
return {
|
|
17
30
|
...resolveCopilotAuth({
|
|
18
31
|
agentId: input.agentId,
|
|
19
32
|
agentDir: input.agentDir,
|
|
20
33
|
copilotHome: input.copilotHome,
|
|
21
|
-
env: input.env,
|
|
22
|
-
homeDir: input.homeDir,
|
|
23
34
|
auth: { useLoggedInUser: true }
|
|
24
35
|
}),
|
|
25
36
|
authMode: "byok",
|
|
@@ -28,16 +39,18 @@ function createCopilotByokAuth(input) {
|
|
|
28
39
|
};
|
|
29
40
|
}
|
|
30
41
|
function resolveCopilotAuth(input) {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const normalizedAgentId = (input.agentId ?? "").trim().toLowerCase();
|
|
43
|
+
const agentId = /^[a-z0-9][a-z0-9_-]{0,63}$/.test(normalizedAgentId) ? normalizedAgentId : COPILOT_DEFAULT_AGENT_ID;
|
|
44
|
+
const explicitHome = readNonEmptyStringPreservingWhitespace(input.copilotHome);
|
|
45
|
+
const agentDir = readNonEmptyStringPreservingWhitespace(input.agentDir);
|
|
46
|
+
let copilotHome;
|
|
47
|
+
if (explicitHome) copilotHome = resolve(explicitHome);
|
|
48
|
+
else if (agentDir) copilotHome = resolve(join(agentDir, "copilot"));
|
|
49
|
+
else {
|
|
50
|
+
const openClawHome = readNonEmptyStringPreservingWhitespace(process.env.OPENCLAW_HOME);
|
|
51
|
+
const rootHome = openClawHome ? resolve(openClawHome) : homedir();
|
|
52
|
+
copilotHome = resolve(join(rootHome, ".openclaw", "agents", agentId, "copilot"));
|
|
53
|
+
}
|
|
41
54
|
const explicitToken = readNonEmptyStringPreservingWhitespace(input.auth?.gitHubToken);
|
|
42
55
|
const explicitProfileId = readNonEmptyStringPreservingWhitespace(input.auth?.profileId) ?? readNonEmptyStringPreservingWhitespace(input.authProfileId);
|
|
43
56
|
const explicitProfileVersion = readNonEmptyStringPreservingWhitespace(input.auth?.profileVersion) ?? readNonEmptyStringPreservingWhitespace(input.profileVersion);
|
|
@@ -66,40 +79,7 @@ function resolveCopilotAuth(input) {
|
|
|
66
79
|
copilotHome,
|
|
67
80
|
agentId
|
|
68
81
|
};
|
|
69
|
-
const
|
|
70
|
-
if (envFallback) return {
|
|
71
|
-
authMode: "gitHubToken",
|
|
72
|
-
gitHubToken: envFallback.token,
|
|
73
|
-
authProfileId: envFallback.profileId,
|
|
74
|
-
authProfileVersion: envFallback.profileVersion,
|
|
75
|
-
copilotHome,
|
|
76
|
-
agentId
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
authMode: "useLoggedInUser",
|
|
80
|
-
copilotHome,
|
|
81
|
-
agentId
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function sanitizeAgentId(value) {
|
|
85
|
-
const trimmed = (value ?? "").trim().toLowerCase();
|
|
86
|
-
return /^[a-z0-9][a-z0-9_-]{0,63}$/.test(trimmed) ? trimmed : COPILOT_DEFAULT_AGENT_ID;
|
|
87
|
-
}
|
|
88
|
-
function resolveCopilotHome(args) {
|
|
89
|
-
if (args.explicit) return resolve(args.explicit);
|
|
90
|
-
if (args.agentDir) return resolve(join(args.agentDir, "copilot"));
|
|
91
|
-
const openClawHome = readNonEmptyStringPreservingWhitespace(args.env.OPENCLAW_HOME);
|
|
92
|
-
const rootHome = openClawHome ? resolve(openClawHome) : safeHomeDir(args.homeDir);
|
|
93
|
-
return resolve(join(rootHome, ".openclaw", "agents", args.agentId, "copilot"));
|
|
94
|
-
}
|
|
95
|
-
function safeHomeDir(homeDir) {
|
|
96
|
-
try {
|
|
97
|
-
const value = homeDir();
|
|
98
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
99
|
-
} catch {}
|
|
100
|
-
return process.cwd();
|
|
101
|
-
}
|
|
102
|
-
function readEnvTokenFallback(env) {
|
|
82
|
+
const env = process.env;
|
|
103
83
|
const candidates = [
|
|
104
84
|
{
|
|
105
85
|
name: "OPENCLAW_GITHUB_TOKEN",
|
|
@@ -119,9 +99,17 @@ function readEnvTokenFallback(env) {
|
|
|
119
99
|
}
|
|
120
100
|
];
|
|
121
101
|
for (const { name, value } of candidates) if (value) return {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
102
|
+
authMode: "gitHubToken",
|
|
103
|
+
gitHubToken: value,
|
|
104
|
+
authProfileId: `env:${name}`,
|
|
105
|
+
authProfileVersion: tokenFingerprint(value),
|
|
106
|
+
copilotHome,
|
|
107
|
+
agentId
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
authMode: "useLoggedInUser",
|
|
111
|
+
copilotHome,
|
|
112
|
+
agentId
|
|
125
113
|
};
|
|
126
114
|
}
|
|
127
115
|
/** Pool invalidation fingerprint; never log it alongside an account id. */
|
|
@@ -140,29 +128,77 @@ async function createCopilotByokProxy(resolvedProvider) {
|
|
|
140
128
|
const targetPathPrefix = targetBaseUrl.pathname.replace(/\/+$/, "");
|
|
141
129
|
const proxyPathPrefix = `/${nonce}${targetPathPrefix}`;
|
|
142
130
|
const acceptsAzureSdkPaths = providerConfig.type === "azure";
|
|
143
|
-
const proxyCredentialHeader = acceptsAzureSdkPaths ?
|
|
131
|
+
const proxyCredentialHeader = acceptsAzureSdkPaths ? `${PROXY_CREDENTIAL_HEADER_PREFIX}${randomBytes(12).toString("hex")}` : void 0;
|
|
144
132
|
const bearerToken = providerConfig.bearerToken?.trim();
|
|
145
133
|
const upstreamBearerAuthorization = bearerToken ? `Bearer ${bearerToken}` : void 0;
|
|
146
134
|
const activeFetches = /* @__PURE__ */ new Set();
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
targetPathPrefix,
|
|
156
|
-
upstreamBearerAuthorization
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
await new Promise((resolve, reject) => {
|
|
160
|
-
server.once("error", reject);
|
|
161
|
-
server.listen(0, LOOPBACK_HOST, () => {
|
|
162
|
-
server.off("error", reject);
|
|
163
|
-
resolve();
|
|
135
|
+
async function handleProxyRequest(req, res) {
|
|
136
|
+
let guarded;
|
|
137
|
+
const upstreamAbort = new AbortController();
|
|
138
|
+
activeFetches.add(upstreamAbort);
|
|
139
|
+
const abortUpstream = () => upstreamAbort.abort();
|
|
140
|
+
req.on("aborted", abortUpstream);
|
|
141
|
+
res.on("close", () => {
|
|
142
|
+
if (!res.writableEnded) abortUpstream();
|
|
164
143
|
});
|
|
144
|
+
try {
|
|
145
|
+
const target = resolveTargetUrl(req);
|
|
146
|
+
if (!target || !target.nonceProtected && (!proxyCredentialHeader || !hasValidProxyCredential(req, proxyCredentialHeader, nonce))) {
|
|
147
|
+
res.writeHead(404);
|
|
148
|
+
res.end("Not found");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : await readBody(req);
|
|
152
|
+
guarded = await fetchWithSsrFGuard({
|
|
153
|
+
url: target.url.toString(),
|
|
154
|
+
init: {
|
|
155
|
+
method: req.method,
|
|
156
|
+
headers: buildProxyRequestHeaders(req.headers, {
|
|
157
|
+
upstreamBearerAuthorization: target.nonceProtected ? upstreamBearerAuthorization : void 0,
|
|
158
|
+
proxyCredentialHeader
|
|
159
|
+
}),
|
|
160
|
+
signal: upstreamAbort.signal,
|
|
161
|
+
...body ? { body } : {}
|
|
162
|
+
},
|
|
163
|
+
auditContext: "copilot-byok-provider",
|
|
164
|
+
requireHttps: true
|
|
165
|
+
});
|
|
166
|
+
res.writeHead(guarded.response.status, guarded.response.statusText, normalizeProxyResponseHeaders(guarded.response.headers));
|
|
167
|
+
if (!guarded.response.body) {
|
|
168
|
+
res.end();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
await pipeline(Readable.fromWeb(guarded.response.body), res);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (res.destroyed || res.writableEnded) return;
|
|
174
|
+
if (res.headersSent) {
|
|
175
|
+
res.destroy(error instanceof Error ? error : void 0);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
res.writeHead(502);
|
|
179
|
+
res.end(error instanceof Error ? error.message : "BYOK provider proxy failed");
|
|
180
|
+
} finally {
|
|
181
|
+
req.off("aborted", abortUpstream);
|
|
182
|
+
activeFetches.delete(upstreamAbort);
|
|
183
|
+
await guarded?.release().catch(() => void 0);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function resolveTargetUrl(req) {
|
|
187
|
+
const incomingUrl = new URL(req.url ?? "/", `http://${LOOPBACK_HOST}`);
|
|
188
|
+
const nonceProtected = incomingUrl.pathname === proxyPathPrefix || incomingUrl.pathname.startsWith(`${proxyPathPrefix}/`);
|
|
189
|
+
if (!nonceProtected && !(acceptsAzureSdkPaths && (incomingUrl.pathname === "/openai" || incomingUrl.pathname.startsWith("/openai/")))) return;
|
|
190
|
+
const targetUrl = new URL(targetBaseUrl);
|
|
191
|
+
targetUrl.pathname = nonceProtected ? `${targetPathPrefix}${incomingUrl.pathname.slice(proxyPathPrefix.length)}` || "/" : incomingUrl.pathname;
|
|
192
|
+
for (const [key, value] of incomingUrl.searchParams) targetUrl.searchParams.append(key, value);
|
|
193
|
+
return {
|
|
194
|
+
url: targetUrl,
|
|
195
|
+
nonceProtected
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const server = createServer((req, res) => {
|
|
199
|
+
handleProxyRequest(req, res);
|
|
165
200
|
});
|
|
201
|
+
await once(server.listen(0, LOOPBACK_HOST), "listening");
|
|
166
202
|
const address = server.address();
|
|
167
203
|
if (!address || typeof address === "string") {
|
|
168
204
|
server.close();
|
|
@@ -191,72 +227,6 @@ async function createCopilotByokProxy(resolvedProvider) {
|
|
|
191
227
|
}
|
|
192
228
|
};
|
|
193
229
|
}
|
|
194
|
-
async function handleProxyRequest(req, res, params) {
|
|
195
|
-
let guarded;
|
|
196
|
-
const upstreamAbort = new AbortController();
|
|
197
|
-
params.activeFetches.add(upstreamAbort);
|
|
198
|
-
const abortUpstream = () => upstreamAbort.abort();
|
|
199
|
-
req.on("aborted", abortUpstream);
|
|
200
|
-
res.on("close", () => {
|
|
201
|
-
if (!res.writableEnded) abortUpstream();
|
|
202
|
-
});
|
|
203
|
-
try {
|
|
204
|
-
const target = resolveTargetUrl(req, params);
|
|
205
|
-
if (!target || !target.nonceProtected && (!params.proxyCredentialHeader || !hasValidProxyCredential(req, params.proxyCredentialHeader, params.proxyCredential))) {
|
|
206
|
-
res.writeHead(404);
|
|
207
|
-
res.end("Not found");
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : await readBody(req);
|
|
211
|
-
guarded = await fetchWithSsrFGuard({
|
|
212
|
-
url: target.url.toString(),
|
|
213
|
-
init: {
|
|
214
|
-
method: req.method,
|
|
215
|
-
headers: buildProxyRequestHeaders(req.headers, {
|
|
216
|
-
upstreamBearerAuthorization: target.nonceProtected ? params.upstreamBearerAuthorization : void 0,
|
|
217
|
-
proxyCredentialHeader: params.proxyCredentialHeader
|
|
218
|
-
}),
|
|
219
|
-
signal: upstreamAbort.signal,
|
|
220
|
-
...body ? { body } : {}
|
|
221
|
-
},
|
|
222
|
-
auditContext: "copilot-byok-provider",
|
|
223
|
-
requireHttps: true
|
|
224
|
-
});
|
|
225
|
-
res.writeHead(guarded.response.status, guarded.response.statusText, normalizeProxyResponseHeaders(guarded.response.headers));
|
|
226
|
-
if (!guarded.response.body) {
|
|
227
|
-
res.end();
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
await pipeline(Readable.fromWeb(guarded.response.body), res);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
if (res.destroyed || res.writableEnded) return;
|
|
233
|
-
if (res.headersSent) {
|
|
234
|
-
res.destroy(error instanceof Error ? error : void 0);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
res.writeHead(502);
|
|
238
|
-
res.end(error instanceof Error ? error.message : "BYOK provider proxy failed");
|
|
239
|
-
} finally {
|
|
240
|
-
req.off("aborted", abortUpstream);
|
|
241
|
-
params.activeFetches.delete(upstreamAbort);
|
|
242
|
-
await guarded?.release().catch(() => void 0);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function resolveTargetUrl(req, params) {
|
|
246
|
-
const incomingUrl = new URL(req.url ?? "/", `http://${LOOPBACK_HOST}`);
|
|
247
|
-
const nonceProtected = incomingUrl.pathname === params.proxyPathPrefix || incomingUrl.pathname.startsWith(`${params.proxyPathPrefix}/`);
|
|
248
|
-
if (!nonceProtected && !(params.acceptsAzureSdkPaths && isAzureSdkProxyPath(incomingUrl.pathname))) return;
|
|
249
|
-
const targetUrl = new URL(params.targetBaseUrl);
|
|
250
|
-
targetUrl.pathname = nonceProtected ? `${params.targetPathPrefix}${incomingUrl.pathname.slice(params.proxyPathPrefix.length)}` || "/" : incomingUrl.pathname;
|
|
251
|
-
for (const [key, value] of incomingUrl.searchParams) targetUrl.searchParams.append(key, value);
|
|
252
|
-
return {
|
|
253
|
-
url: targetUrl,
|
|
254
|
-
nonceProtected
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function isAzureSdkProxyPath(pathname) {
|
|
258
|
-
return pathname === "/openai" || pathname.startsWith("/openai/");
|
|
259
|
-
}
|
|
260
230
|
function hasValidProxyCredential(req, headerName, expected) {
|
|
261
231
|
const received = req.headers[headerName];
|
|
262
232
|
if (typeof received !== "string") return false;
|
|
@@ -269,38 +239,25 @@ async function readBody(req) {
|
|
|
269
239
|
for await (const chunk of req) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
270
240
|
return chunks.length > 0 ? Buffer.concat(chunks) : void 0;
|
|
271
241
|
}
|
|
272
|
-
function
|
|
242
|
+
function buildProxyRequestHeaders(headers, params) {
|
|
273
243
|
const out = {};
|
|
274
244
|
for (const [key, value] of Object.entries(headers)) {
|
|
275
|
-
if (isHopByHopHeader(key) || key.toLowerCase() === "accept-encoding" || key.toLowerCase() === proxyCredentialHeader) continue;
|
|
276
|
-
|
|
277
|
-
if (normalized !== void 0) out[key] = normalized;
|
|
245
|
+
if (isHopByHopHeader(key) || key.toLowerCase() === "accept-encoding" || key.toLowerCase() === params.proxyCredentialHeader) continue;
|
|
246
|
+
if (value !== void 0) out[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
278
247
|
}
|
|
279
248
|
out["accept-encoding"] = "identity";
|
|
280
|
-
return out;
|
|
281
|
-
}
|
|
282
|
-
function createProxyCredentialHeaderName(headers) {
|
|
283
|
-
for (;;) {
|
|
284
|
-
const name = `${PROXY_CREDENTIAL_HEADER_PREFIX}${randomBytes(12).toString("hex")}`;
|
|
285
|
-
if (!headers || !hasHeader(headers, name)) return name;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
function buildProxyRequestHeaders(headers, params) {
|
|
289
|
-
const out = normalizeProxyRequestHeaders(headers, params.proxyCredentialHeader);
|
|
290
249
|
if (params.upstreamBearerAuthorization && !hasHeader(out, "authorization")) out["authorization"] = params.upstreamBearerAuthorization;
|
|
291
250
|
return out;
|
|
292
251
|
}
|
|
293
252
|
function normalizeProxyResponseHeaders(headers) {
|
|
294
253
|
const out = {};
|
|
295
254
|
headers.forEach((value, key) => {
|
|
296
|
-
if (
|
|
255
|
+
if (isHopByHopHeader(key)) return;
|
|
256
|
+
const normalizedKey = key.toLowerCase();
|
|
257
|
+
if (normalizedKey !== "content-encoding" && normalizedKey !== "content-length") out[key] = value;
|
|
297
258
|
});
|
|
298
259
|
return out;
|
|
299
260
|
}
|
|
300
|
-
function normalizeHeaderValue(value) {
|
|
301
|
-
if (value === void 0) return;
|
|
302
|
-
return Array.isArray(value) ? value.join(", ") : String(value);
|
|
303
|
-
}
|
|
304
261
|
function hasHeader(headers, target) {
|
|
305
262
|
return Object.keys(headers).some((key) => key.toLowerCase() === target);
|
|
306
263
|
}
|
|
@@ -318,13 +275,6 @@ function isHopByHopHeader(key) {
|
|
|
318
275
|
default: return false;
|
|
319
276
|
}
|
|
320
277
|
}
|
|
321
|
-
function isContentEncodingHeader(key) {
|
|
322
|
-
switch (key.toLowerCase()) {
|
|
323
|
-
case "content-encoding":
|
|
324
|
-
case "content-length": return true;
|
|
325
|
-
default: return false;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
278
|
// extensions/copilot/src/prompt-error.ts
|
|
329
279
|
function createCopilotAbortError(reason) {
|
|
330
280
|
if (reason instanceof Error) return reason;
|
|
@@ -359,6 +309,27 @@ function buildCopilotCompactionHookContext(params) {
|
|
|
359
309
|
...buildAgentHookContextChannelFields(params)
|
|
360
310
|
};
|
|
361
311
|
}
|
|
312
|
+
async function compactTrackedSdkSession(params) {
|
|
313
|
+
params.assertCurrent();
|
|
314
|
+
throwIfAborted(params.abortSignal);
|
|
315
|
+
const session = await params.client.resumeSession(params.sdkSessionId, {
|
|
316
|
+
...params.sessionConfig,
|
|
317
|
+
continuePendingWork: false,
|
|
318
|
+
...params.gitHubToken ? { gitHubToken: params.gitHubToken } : {},
|
|
319
|
+
suppressResumeEvent: true
|
|
320
|
+
});
|
|
321
|
+
params.onSession?.(session);
|
|
322
|
+
const request = params.customInstructions?.trim() ? { customInstructions: params.customInstructions } : void 0;
|
|
323
|
+
try {
|
|
324
|
+
params.assertCurrent();
|
|
325
|
+
throwIfAborted(params.abortSignal);
|
|
326
|
+
return await session.rpc.history.compact(request);
|
|
327
|
+
} finally {
|
|
328
|
+
try {
|
|
329
|
+
await session.disconnect();
|
|
330
|
+
} catch {}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
362
333
|
// extensions/copilot/src/provider-bridge.ts
|
|
363
334
|
const COPILOT_BYOK_PROVIDER_ERROR = "[copilot-attempt] BYOK requires an OpenAI-compatible or Anthropic model api and a non-empty baseUrl";
|
|
364
335
|
const COPILOT_BYOK_TRANSPORT_POLICY_ERROR = "[copilot-attempt] BYOK does not support OpenClaw provider request proxy, TLS, or private-network policy overrides";
|
|
@@ -484,7 +455,30 @@ function resolveProviderType(api, baseUrl, azureApiVersion) {
|
|
|
484
455
|
type: "anthropic",
|
|
485
456
|
baseUrl
|
|
486
457
|
};
|
|
487
|
-
case "azure-openai-responses":
|
|
458
|
+
case "azure-openai-responses": {
|
|
459
|
+
let url;
|
|
460
|
+
try {
|
|
461
|
+
url = new URL(baseUrl);
|
|
462
|
+
} catch {
|
|
463
|
+
throw new Error(COPILOT_BYOK_PROVIDER_ERROR);
|
|
464
|
+
}
|
|
465
|
+
if (isOpenAICompatibleAzureResponsesBaseUrl(url)) return {
|
|
466
|
+
type: "openai",
|
|
467
|
+
wireApi: "responses",
|
|
468
|
+
baseUrl
|
|
469
|
+
};
|
|
470
|
+
if (!isTraditionalAzureOpenAIHost(url.hostname)) throw new Error(COPILOT_BYOK_PROVIDER_ERROR);
|
|
471
|
+
url.pathname = "";
|
|
472
|
+
url.search = "";
|
|
473
|
+
url.hash = "";
|
|
474
|
+
const resolvedApiVersion = normalizeOptionalString(azureApiVersion);
|
|
475
|
+
return {
|
|
476
|
+
type: "azure",
|
|
477
|
+
wireApi: "responses",
|
|
478
|
+
baseUrl: url.toString().replace(/\/+$/, ""),
|
|
479
|
+
...resolvedApiVersion ? { azure: { apiVersion: resolvedApiVersion } } : {}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
488
482
|
case "openai-responses": return {
|
|
489
483
|
type: "openai",
|
|
490
484
|
wireApi: "responses",
|
|
@@ -499,30 +493,6 @@ function resolveProviderType(api, baseUrl, azureApiVersion) {
|
|
|
499
493
|
default: throw new Error(COPILOT_BYOK_PROVIDER_ERROR);
|
|
500
494
|
}
|
|
501
495
|
}
|
|
502
|
-
function resolveAzureProviderType(baseUrl, apiVersion) {
|
|
503
|
-
let url;
|
|
504
|
-
try {
|
|
505
|
-
url = new URL(baseUrl);
|
|
506
|
-
} catch {
|
|
507
|
-
throw new Error(COPILOT_BYOK_PROVIDER_ERROR);
|
|
508
|
-
}
|
|
509
|
-
if (isOpenAICompatibleAzureResponsesBaseUrl(url)) return {
|
|
510
|
-
type: "openai",
|
|
511
|
-
wireApi: "responses",
|
|
512
|
-
baseUrl
|
|
513
|
-
};
|
|
514
|
-
if (!isTraditionalAzureOpenAIHost(url.hostname)) throw new Error(COPILOT_BYOK_PROVIDER_ERROR);
|
|
515
|
-
url.pathname = "";
|
|
516
|
-
url.search = "";
|
|
517
|
-
url.hash = "";
|
|
518
|
-
const resolvedApiVersion = normalizeOptionalString(apiVersion);
|
|
519
|
-
return {
|
|
520
|
-
type: "azure",
|
|
521
|
-
wireApi: "responses",
|
|
522
|
-
baseUrl: url.toString().replace(/\/+$/, ""),
|
|
523
|
-
...resolvedApiVersion ? { azure: { apiVersion: resolvedApiVersion } } : {}
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
496
|
function isTraditionalAzureOpenAIHost(hostname) {
|
|
527
497
|
return hostname.endsWith(".openai.azure.com") || hostname.endsWith(".cognitiveservices.azure.com");
|
|
528
498
|
}
|
|
@@ -544,18 +514,6 @@ function resolveProviderCredential(value) {
|
|
|
544
514
|
}
|
|
545
515
|
// extensions/copilot/harness.ts
|
|
546
516
|
const COPILOT_PROVIDER_IDS = /* @__PURE__ */ new Set(["github-copilot"]);
|
|
547
|
-
function sessionAuthFields(auth) {
|
|
548
|
-
return auth.authMode === "gitHubToken" || auth.authMode === "byok" ? {
|
|
549
|
-
authMode: auth.authMode,
|
|
550
|
-
authProfileId: auth.authProfileId,
|
|
551
|
-
authProfileVersion: auth.authProfileVersion
|
|
552
|
-
} : { authMode: "useLoggedInUser" };
|
|
553
|
-
}
|
|
554
|
-
function sessionAuthMatches(stored, current) {
|
|
555
|
-
if (stored.authMode !== current.authMode) return false;
|
|
556
|
-
if (stored.authMode === "useLoggedInUser") return true;
|
|
557
|
-
return stored.authProfileId === current.authProfileId && stored.authProfileVersion === current.authProfileVersion;
|
|
558
|
-
}
|
|
559
517
|
function normalizeBinding(value) {
|
|
560
518
|
if (!value || value.schemaVersion !== 2 || typeof value.sdkSessionId !== "string" || value.sdkSessionId.trim() === "" || typeof value.compatKey !== "string" || value.compatKey.trim() === "" || typeof value.compactKey !== "string" || value.compactKey.trim() === "" || value.journalVersion !== void 0 && value.journalVersion !== 1 || value.authMode !== "gitHubToken" && value.authMode !== "byok" && value.authMode !== "useLoggedInUser" || (value.authMode === "gitHubToken" || value.authMode === "byok") && (typeof value.authProfileId !== "string" || value.authProfileId.trim() === "" || typeof value.authProfileVersion !== "string" || value.authProfileVersion.trim() === "") || typeof value.updatedAt !== "number" || !Number.isFinite(value.updatedAt)) return;
|
|
561
519
|
return {
|
|
@@ -610,27 +568,6 @@ async function deleteStoredBinding(store, key) {
|
|
|
610
568
|
return false;
|
|
611
569
|
}
|
|
612
570
|
}
|
|
613
|
-
async function compactTrackedSdkSession(params) {
|
|
614
|
-
params.assertCurrent();
|
|
615
|
-
throwIfAborted(params.abortSignal);
|
|
616
|
-
const session = await params.client.resumeSession(params.sdkSessionId, {
|
|
617
|
-
...params.sessionConfig,
|
|
618
|
-
continuePendingWork: false,
|
|
619
|
-
...params.gitHubToken ? { gitHubToken: params.gitHubToken } : {},
|
|
620
|
-
suppressResumeEvent: true
|
|
621
|
-
});
|
|
622
|
-
params.onSession?.(session);
|
|
623
|
-
const request = params.customInstructions?.trim() ? { customInstructions: params.customInstructions } : void 0;
|
|
624
|
-
try {
|
|
625
|
-
params.assertCurrent();
|
|
626
|
-
throwIfAborted(params.abortSignal);
|
|
627
|
-
return await session.rpc.history.compact(request);
|
|
628
|
-
} finally {
|
|
629
|
-
try {
|
|
630
|
-
await session.disconnect();
|
|
631
|
-
} catch {}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
571
|
function readAgentIdFromSessionKey(sessionKey) {
|
|
635
572
|
if (typeof sessionKey !== "string") return;
|
|
636
573
|
const parts = sessionKey.trim().split(":");
|
|
@@ -779,21 +716,12 @@ function createCopilotAgentHarness(options) {
|
|
|
779
716
|
async function getPool() {
|
|
780
717
|
if (options?.pool) return options.pool;
|
|
781
718
|
if (!poolPromise) poolPromise = (async () => {
|
|
782
|
-
const { createCopilotClientPool } = await import("./runtime-
|
|
719
|
+
const { createCopilotClientPool } = await import("./runtime-CAM77uEc.mjs");
|
|
783
720
|
createdPool = createCopilotClientPool(options?.poolOptions);
|
|
784
721
|
return createdPool;
|
|
785
722
|
})();
|
|
786
723
|
return poolPromise;
|
|
787
724
|
}
|
|
788
|
-
function trackDeferredCompactionCleanup(params) {
|
|
789
|
-
const cleanups = deferredCompactionCleanups.get(params.sessionId) ?? /* @__PURE__ */ new Map();
|
|
790
|
-
cleanups.set(params.cleanup, {
|
|
791
|
-
abort: params.abort,
|
|
792
|
-
sdkSessionId: params.sdkSessionId
|
|
793
|
-
});
|
|
794
|
-
deferredCompactionCleanups.set(params.sessionId, cleanups);
|
|
795
|
-
params.cleanup.then(() => removeDeferredCompactionCleanup(params.sessionId, params.cleanup), () => removeDeferredCompactionCleanup(params.sessionId, params.cleanup));
|
|
796
|
-
}
|
|
797
725
|
function removeDeferredCompactionCleanup(sessionId, cleanup) {
|
|
798
726
|
const cleanups = deferredCompactionCleanups.get(sessionId);
|
|
799
727
|
if (!cleanups) return;
|
|
@@ -816,10 +744,8 @@ function createCopilotAgentHarness(options) {
|
|
|
816
744
|
async function runHarnessAttempt(params, operation) {
|
|
817
745
|
return trackOperation(async () => {
|
|
818
746
|
if (disposed) throw new Error("[copilot] harness has been disposed; cannot start new attempts");
|
|
819
|
-
const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-
|
|
820
|
-
if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
|
|
747
|
+
const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-BdJgfQV3.mjs");
|
|
821
748
|
const pool = await getPool();
|
|
822
|
-
if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
|
|
823
749
|
let poolAcquire;
|
|
824
750
|
try {
|
|
825
751
|
poolAcquire = resolvePoolAcquire(params);
|
|
@@ -827,7 +753,7 @@ function createCopilotAgentHarness(options) {
|
|
|
827
753
|
if (operation === "attempt" && isCopilotByokUnsupportedProviderError(error)) return runCopilotAttempt(params, { pool });
|
|
828
754
|
throw error;
|
|
829
755
|
}
|
|
830
|
-
const openclawSessionId = params.sessionPersistence === "detached"
|
|
756
|
+
const openclawSessionId = params.sessionPersistence === "detached" ? void 0 : params.sessionId;
|
|
831
757
|
const currentCompatKey = computeSessionCompatKey(params);
|
|
832
758
|
const currentCompactKey = computeAttemptCompactKey(params);
|
|
833
759
|
const resumableBinding = openclawSessionId ? await bindingQueue.enqueue(openclawSessionId, async () => {
|
|
@@ -837,25 +763,10 @@ function createCopilotAgentHarness(options) {
|
|
|
837
763
|
const binding = tracked ?? stored;
|
|
838
764
|
return binding?.compatKey === currentCompatKey ? binding : void 0;
|
|
839
765
|
}) : void 0;
|
|
840
|
-
if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
|
|
841
766
|
const resumableSessionId = resumableBinding?.sdkSessionId;
|
|
842
767
|
if (operation === "settled-tool-finalization" && !resumableSessionId) throw new Error("[copilot] cannot safely finalize a settled tool turn without its compatible SDK session");
|
|
843
768
|
const result = await runCopilotAttempt(resumableSessionId ? {
|
|
844
769
|
...params,
|
|
845
|
-
...operation === "settled-tool-finalization" ? {
|
|
846
|
-
disableTools: true,
|
|
847
|
-
onAgentEvent: void 0,
|
|
848
|
-
onAgentToolResult: void 0,
|
|
849
|
-
onAssistantDelta: void 0,
|
|
850
|
-
onAssistantMessageStart: void 0,
|
|
851
|
-
onBlockReply: void 0,
|
|
852
|
-
onBlockReplyFlush: void 0,
|
|
853
|
-
onPartialReply: void 0,
|
|
854
|
-
onReasoningEnd: void 0,
|
|
855
|
-
onReasoningStream: void 0,
|
|
856
|
-
onToolResult: void 0,
|
|
857
|
-
onToolStreamBoundary: void 0
|
|
858
|
-
} : {},
|
|
859
770
|
initialReplayState: {
|
|
860
771
|
...operation === "attempt" ? params.initialReplayState : void 0,
|
|
861
772
|
...resumableBinding?.journalVersion === 1 ? { journalValidated: true } : {},
|
|
@@ -886,25 +797,27 @@ function createCopilotAgentHarness(options) {
|
|
|
886
797
|
const ownsStoredSession = storedBinding?.sdkSessionId === sdkSessionId;
|
|
887
798
|
if (!ownsTrackedSession && !ownsStoredSession) return;
|
|
888
799
|
resetBlockedStoredSessions.add(openclawSessionId);
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (outcome === "completed") {
|
|
897
|
-
if (stillOwnsTrackedSession || stillOwnsStoredSession) resetBlockedStoredSessions.delete(openclawSessionId);
|
|
898
|
-
return outcome;
|
|
899
|
-
}
|
|
900
|
-
if (stillOwnsTrackedSession) trackedSessions.delete(openclawSessionId);
|
|
901
|
-
if (stillOwnsStoredSession) await deleteStoredBinding(options?.sessionStore, openclawSessionId);
|
|
902
|
-
if (stillOwnsTrackedSession || stillOwnsStoredSession) resetBlockedStoredSessions.add(openclawSessionId);
|
|
800
|
+
const bindingCleanup = cleanup.then((outcome) => bindingQueue.enqueue(openclawSessionId, async () => {
|
|
801
|
+
const currentTracked = trackedSessions.get(openclawSessionId);
|
|
802
|
+
const currentStored = await lookupStoredBinding(options?.sessionStore, openclawSessionId);
|
|
803
|
+
const stillOwnsTrackedSession = currentTracked?.sdkSessionId === sdkSessionId;
|
|
804
|
+
const stillOwnsStoredSession = currentStored?.sdkSessionId === sdkSessionId;
|
|
805
|
+
if (outcome === "completed") {
|
|
806
|
+
if (stillOwnsTrackedSession || stillOwnsStoredSession) resetBlockedStoredSessions.delete(openclawSessionId);
|
|
903
807
|
return outcome;
|
|
904
|
-
}
|
|
905
|
-
|
|
808
|
+
}
|
|
809
|
+
if (stillOwnsTrackedSession) trackedSessions.delete(openclawSessionId);
|
|
810
|
+
if (stillOwnsStoredSession) await deleteStoredBinding(options?.sessionStore, openclawSessionId);
|
|
811
|
+
if (stillOwnsTrackedSession || stillOwnsStoredSession) resetBlockedStoredSessions.add(openclawSessionId);
|
|
812
|
+
return outcome;
|
|
813
|
+
}));
|
|
814
|
+
const cleanups = deferredCompactionCleanups.get(openclawSessionId) ?? /* @__PURE__ */ new Map();
|
|
815
|
+
cleanups.set(bindingCleanup, {
|
|
816
|
+
abort,
|
|
906
817
|
sdkSessionId
|
|
907
818
|
});
|
|
819
|
+
deferredCompactionCleanups.set(openclawSessionId, cleanups);
|
|
820
|
+
bindingCleanup.then(() => removeDeferredCompactionCleanup(openclawSessionId, bindingCleanup), () => removeDeferredCompactionCleanup(openclawSessionId, bindingCleanup));
|
|
908
821
|
}) : void 0
|
|
909
822
|
});
|
|
910
823
|
if (operation === "attempt" && openclawSessionId) {
|
|
@@ -929,12 +842,9 @@ function createCopilotAgentHarness(options) {
|
|
|
929
842
|
async function runIsolatedCompletionV2(params) {
|
|
930
843
|
return trackOperation(async () => {
|
|
931
844
|
if (disposed) throw new Error("[copilot] harness has been disposed; cannot start isolated completion");
|
|
932
|
-
const { runCopilotIsolatedCompletion } = await import("./isolated-completion-
|
|
933
|
-
if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
|
|
845
|
+
const { runCopilotIsolatedCompletion } = await import("./isolated-completion-Dp_YaEKF.mjs");
|
|
934
846
|
return await runCopilotIsolatedCompletion(params, async () => {
|
|
935
|
-
|
|
936
|
-
if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
|
|
937
|
-
return pool;
|
|
847
|
+
return await getPool();
|
|
938
848
|
});
|
|
939
849
|
});
|
|
940
850
|
}
|
|
@@ -943,6 +853,10 @@ function createCopilotAgentHarness(options) {
|
|
|
943
853
|
label: options?.label ?? "GitHub Copilot agent runtime",
|
|
944
854
|
autoSelection: { providerIds: [] },
|
|
945
855
|
conversationToolPolicySupport: "exact",
|
|
856
|
+
runtimeArtifact: { async validate(binding) {
|
|
857
|
+
const { validateCopilotRuntimeArtifact } = await import("./runtime-artifact-D42RfCpG.mjs");
|
|
858
|
+
return await validateCopilotRuntimeArtifact(binding);
|
|
859
|
+
} },
|
|
946
860
|
supports(ctx) {
|
|
947
861
|
if (String(ctx.requestedRuntime ?? "").trim().toLowerCase() !== "copilot") return {
|
|
948
862
|
supported: false,
|
|
@@ -985,7 +899,7 @@ function createCopilotAgentHarness(options) {
|
|
|
985
899
|
},
|
|
986
900
|
reset: (params) => trackOperation(async () => {
|
|
987
901
|
if (disposed) return;
|
|
988
|
-
const openclawSessionId =
|
|
902
|
+
const openclawSessionId = params.sessionId;
|
|
989
903
|
if (!openclawSessionId) return;
|
|
990
904
|
const { tracked, stored } = await bindingQueue.enqueue(openclawSessionId, async () => {
|
|
991
905
|
const binding = await lookupStoredBinding(options?.sessionStore, openclawSessionId);
|
|
@@ -1013,7 +927,7 @@ function createCopilotAgentHarness(options) {
|
|
|
1013
927
|
const hostCapabilities = params.hostCapabilities;
|
|
1014
928
|
if (hostCapabilities?.kind !== "agent-harness-host-capability" || hostCapabilities.version !== 1 || typeof hostCapabilities.assertActive !== "function" || typeof hostCapabilities.retainSourceAuthority !== "function") throw new Error("This host did not provide compaction source authority. Update OpenClaw before compacting this session.");
|
|
1015
929
|
hostCapabilities.assertActive();
|
|
1016
|
-
const openclawSessionId =
|
|
930
|
+
const openclawSessionId = params.sessionId;
|
|
1017
931
|
if (!openclawSessionId) return {
|
|
1018
932
|
ok: false,
|
|
1019
933
|
compacted: false,
|
|
@@ -1022,7 +936,7 @@ function createCopilotAgentHarness(options) {
|
|
|
1022
936
|
if (await bindingQueue.enqueue(openclawSessionId, () => hasPendingDeferredCompactionCleanup(openclawSessionId))) return failedCompaction("background-compaction-pending");
|
|
1023
937
|
const tracked = trackedSessions.get(openclawSessionId);
|
|
1024
938
|
const currentCompactKey = computeCompactRequestKey(params);
|
|
1025
|
-
const { resolvePoolAcquire } = await import("./attempt-
|
|
939
|
+
const { resolvePoolAcquire } = await import("./attempt-BdJgfQV3.mjs");
|
|
1026
940
|
let resolvedPoolAcquire;
|
|
1027
941
|
try {
|
|
1028
942
|
resolvedPoolAcquire = resolvePoolAcquire(params);
|