@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
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { asNonArrayRecord, asOptionalObjectRecord, readNonEmptyStringPreservingWhitespace } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
2
|
+
import { sanitizeToolResult } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
3
|
+
import { parseDateStringTimestampMs, resolveOptionalIntegerOption } from "openclaw/plugin-sdk/number-runtime";
|
|
4
|
+
// extensions/copilot/src/usage-bridge.ts
|
|
5
|
+
function normalizeCopilotUsage(data) {
|
|
6
|
+
const source = asOptionalObjectRecord(data);
|
|
7
|
+
if (!source) return;
|
|
8
|
+
const input = resolveOptionalIntegerOption(source.inputTokens, { min: 0 });
|
|
9
|
+
const output = resolveOptionalIntegerOption(source.outputTokens, { min: 0 });
|
|
10
|
+
const cacheRead = resolveOptionalIntegerOption(source.cacheReadTokens, { min: 0 });
|
|
11
|
+
const cacheWrite = resolveOptionalIntegerOption(source.cacheWriteTokens, { min: 0 });
|
|
12
|
+
return {
|
|
13
|
+
cacheRead,
|
|
14
|
+
cacheWrite,
|
|
15
|
+
input,
|
|
16
|
+
output,
|
|
17
|
+
total: (input ?? 0) + (output ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// extensions/copilot/src/event-bridge-transcript.ts
|
|
21
|
+
function buildAssistantMessage(params) {
|
|
22
|
+
const event = params.event;
|
|
23
|
+
const text = event ? event.data.content || params.assistantTexts.at(-1) || "" : "";
|
|
24
|
+
const reasoningText = event?.data.reasoningText ?? params.reasoningText;
|
|
25
|
+
const toolRequests = event?.data.toolRequests ?? [];
|
|
26
|
+
const content = [];
|
|
27
|
+
if (reasoningText) content.push({
|
|
28
|
+
thinking: reasoningText,
|
|
29
|
+
type: "thinking"
|
|
30
|
+
});
|
|
31
|
+
if (text) content.push({
|
|
32
|
+
text,
|
|
33
|
+
type: "text"
|
|
34
|
+
});
|
|
35
|
+
for (const request of toolRequests) content.push({
|
|
36
|
+
arguments: asNonArrayRecord(request.arguments),
|
|
37
|
+
id: request.toolCallId,
|
|
38
|
+
name: request.name,
|
|
39
|
+
type: "toolCall"
|
|
40
|
+
});
|
|
41
|
+
const api = params.modelRef.api ?? "openai-responses";
|
|
42
|
+
const model = event?.data.model ?? params.modelRef.id;
|
|
43
|
+
const provider = params.modelRef.provider;
|
|
44
|
+
const stopReason = toolRequests.length > 0 ? "toolUse" : "stop";
|
|
45
|
+
const timestamp = params.now();
|
|
46
|
+
const fallbackOutputTokens = event?.data.outputTokens;
|
|
47
|
+
const usage = params.usage ?? normalizeCopilotUsage({ outputTokens: fallbackOutputTokens });
|
|
48
|
+
return {
|
|
49
|
+
api,
|
|
50
|
+
content,
|
|
51
|
+
model,
|
|
52
|
+
provider,
|
|
53
|
+
role: "assistant",
|
|
54
|
+
stopReason,
|
|
55
|
+
timestamp,
|
|
56
|
+
usage: {
|
|
57
|
+
cacheRead: usage?.cacheRead ?? 0,
|
|
58
|
+
cacheWrite: usage?.cacheWrite ?? 0,
|
|
59
|
+
cost: {
|
|
60
|
+
cacheRead: 0,
|
|
61
|
+
cacheWrite: 0,
|
|
62
|
+
input: 0,
|
|
63
|
+
output: 0,
|
|
64
|
+
total: 0
|
|
65
|
+
},
|
|
66
|
+
input: usage?.input ?? 0,
|
|
67
|
+
output: usage?.output ?? 0,
|
|
68
|
+
totalTokens: usage?.total ?? 0
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function buildAssistantProjectionGroup(group, modelRef, resolveTimestamp, usageByApiCallId, latestUsage, forTranscript) {
|
|
73
|
+
const messages = group.chunks.flatMap((chunk) => {
|
|
74
|
+
const message = buildAssistantMessage({
|
|
75
|
+
event: chunk.event,
|
|
76
|
+
modelRef,
|
|
77
|
+
now: () => resolveTimestamp(chunk.event),
|
|
78
|
+
reasoningText: forTranscript ? chunk.transcriptReasoningText : chunk.reasoningText,
|
|
79
|
+
usage: resolveAssistantUsage(chunk.event, latestUsage, usageByApiCallId),
|
|
80
|
+
assistantTexts: forTranscript ? chunk.transcriptAssistantTexts : chunk.assistantTexts
|
|
81
|
+
});
|
|
82
|
+
return message.content.length > 0 ? [message] : [];
|
|
83
|
+
});
|
|
84
|
+
const replayIncomplete = group.chunks.some(({ event }) => event.data.citations !== void 0 || event.data.serverTools !== void 0 || event.data.reasoningWireField !== void 0 || event.data.reasoningOpaque !== void 0 || event.data.encryptedContent !== void 0 || event.data.toolRequests?.some((request) => request.type === "custom") === true);
|
|
85
|
+
const last = messages.at(-1);
|
|
86
|
+
if (!last) return {
|
|
87
|
+
message: void 0,
|
|
88
|
+
replayIncomplete,
|
|
89
|
+
toolCallIds: []
|
|
90
|
+
};
|
|
91
|
+
const narrative = [];
|
|
92
|
+
let terminalThinking;
|
|
93
|
+
const toolCallsById = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const message of messages) for (const part of message.content) {
|
|
95
|
+
if (part.type === "toolCall") {
|
|
96
|
+
toolCallsById.set(part.id, part);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (part.type === "thinking") {
|
|
100
|
+
terminalThinking = part;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const previous = narrative.at(-1);
|
|
104
|
+
if (part.type === "text" && previous?.type === "text") narrative[narrative.length - 1] = {
|
|
105
|
+
...previous,
|
|
106
|
+
text: previous.text + part.text
|
|
107
|
+
};
|
|
108
|
+
else narrative.push(part);
|
|
109
|
+
}
|
|
110
|
+
const content = [
|
|
111
|
+
...terminalThinking ? [terminalThinking] : [],
|
|
112
|
+
...narrative,
|
|
113
|
+
...toolCallsById.values()
|
|
114
|
+
];
|
|
115
|
+
const toolCallIds = [...toolCallsById.keys()];
|
|
116
|
+
return {
|
|
117
|
+
message: {
|
|
118
|
+
...last,
|
|
119
|
+
content,
|
|
120
|
+
stopReason: toolCallIds.length > 0 ? "toolUse" : "stop"
|
|
121
|
+
},
|
|
122
|
+
replayIncomplete,
|
|
123
|
+
toolCallIds
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function resolveAssistantUsage(event, latest, byApiCallId) {
|
|
127
|
+
const apiCallId = readNonEmptyStringPreservingWhitespace(event?.data.apiCallId);
|
|
128
|
+
return apiCallId ? byApiCallId.get(apiCallId) ?? latest : latest;
|
|
129
|
+
}
|
|
130
|
+
function resolveEventTimestamp(timestamp, now) {
|
|
131
|
+
return parseDateStringTimestampMs(timestamp) ?? now();
|
|
132
|
+
}
|
|
133
|
+
function hasOwnKeys(value) {
|
|
134
|
+
return Boolean(value && typeof value === "object" && Object.keys(value).length > 0);
|
|
135
|
+
}
|
|
136
|
+
function projectSdkUserMetadata(attachments, source) {
|
|
137
|
+
const summaries = (attachments ?? []).map((attachment) => {
|
|
138
|
+
const { data: _data, payload: _payload, text: _text, ...summary } = attachment;
|
|
139
|
+
return summary;
|
|
140
|
+
});
|
|
141
|
+
const media = (attachments ?? []).flatMap((attachment) => {
|
|
142
|
+
if (attachment.type === "file") return [{
|
|
143
|
+
path: attachment.path,
|
|
144
|
+
contentType: attachment.mimeType
|
|
145
|
+
}];
|
|
146
|
+
return attachment.type === "selection" ? [{
|
|
147
|
+
path: attachment.filePath,
|
|
148
|
+
kind: "document"
|
|
149
|
+
}] : [];
|
|
150
|
+
});
|
|
151
|
+
if (!source && summaries.length === 0) return;
|
|
152
|
+
return {
|
|
153
|
+
...source ? { copilotSource: source } : {},
|
|
154
|
+
...summaries.length > 0 ? { copilotAttachments: summaries } : {},
|
|
155
|
+
...media.length > 0 ? { media } : {}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function projectToolResultDetails(data) {
|
|
159
|
+
const result = data.result;
|
|
160
|
+
const sanitizedContents = result?.contents ? sanitizeToolResult({ content: result.contents }).content : void 0;
|
|
161
|
+
const binaryResultsForLlm = result?.binaryResultsForLlm?.map((entry) => {
|
|
162
|
+
const { data: _data, ...descriptor } = entry;
|
|
163
|
+
return descriptor;
|
|
164
|
+
});
|
|
165
|
+
const citableSources = result?.citableSources?.map((source) => Object.assign({}, source, { content: sanitizeToolDetailText(source.content) }));
|
|
166
|
+
return sanitizeToolResult({
|
|
167
|
+
...result?.detailedContent ? { content: [{
|
|
168
|
+
type: "text",
|
|
169
|
+
text: result.detailedContent
|
|
170
|
+
}] } : {},
|
|
171
|
+
...result?.structuredContent ? { structuredContent: result.structuredContent } : {},
|
|
172
|
+
...sanitizedContents ? { contents: sanitizedContents } : {},
|
|
173
|
+
...binaryResultsForLlm?.length ? { binaryResultsForLlm } : {},
|
|
174
|
+
...citableSources?.length ? { citableSources } : {},
|
|
175
|
+
...data.mcpMeta || result?.mcpMeta ? { mcpMeta: data.mcpMeta ?? result?.mcpMeta } : {}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function sanitizeToolDetailText(text) {
|
|
179
|
+
const value = sanitizeToolResult({ content: [{
|
|
180
|
+
type: "text",
|
|
181
|
+
text
|
|
182
|
+
}] }).content?.[0]?.text;
|
|
183
|
+
return typeof value === "string" ? value : "";
|
|
184
|
+
}
|
|
185
|
+
// extensions/copilot/src/session-restrictions.ts
|
|
186
|
+
const COPILOT_ISOLATED_EXCLUDED_TOOLS = [
|
|
187
|
+
"builtin:*",
|
|
188
|
+
"mcp:*",
|
|
189
|
+
"custom:*"
|
|
190
|
+
];
|
|
191
|
+
/** Disable every ambient SDK capability for a prompt-only or settled final turn. */
|
|
192
|
+
function createCopilotIsolatedSessionRestrictions() {
|
|
193
|
+
return {
|
|
194
|
+
availableTools: [],
|
|
195
|
+
coauthorEnabled: false,
|
|
196
|
+
customAgents: [],
|
|
197
|
+
customAgentsLocalOnly: true,
|
|
198
|
+
embeddingCacheStorage: "in-memory",
|
|
199
|
+
enableConfigDiscovery: false,
|
|
200
|
+
enableFileHooks: false,
|
|
201
|
+
enableHostGitOperations: false,
|
|
202
|
+
enableOnDemandInstructionDiscovery: false,
|
|
203
|
+
enableSessionStore: false,
|
|
204
|
+
enableSkills: false,
|
|
205
|
+
excludedTools: [...COPILOT_ISOLATED_EXCLUDED_TOOLS],
|
|
206
|
+
includeSubAgentStreamingEvents: false,
|
|
207
|
+
infiniteSessions: { enabled: false },
|
|
208
|
+
instructionDirectories: [],
|
|
209
|
+
manageScheduleEnabled: false,
|
|
210
|
+
mcpOAuthTokenStorage: "in-memory",
|
|
211
|
+
mcpServers: {},
|
|
212
|
+
memory: { enabled: false },
|
|
213
|
+
pluginDirectories: [],
|
|
214
|
+
remoteSession: "off",
|
|
215
|
+
requestCanvasRenderer: false,
|
|
216
|
+
requestExtensions: false,
|
|
217
|
+
skillDirectories: [],
|
|
218
|
+
skipCustomInstructions: true,
|
|
219
|
+
skipEmbeddingRetrieval: true,
|
|
220
|
+
tools: []
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export { projectSdkUserMetadata as a, resolveEventTimestamp as c, hasOwnKeys as i, sanitizeToolDetailText as l, buildAssistantMessage as n, projectToolResultDetails as o, buildAssistantProjectionGroup as r, resolveAssistantUsage as s, createCopilotIsolatedSessionRestrictions as t, normalizeCopilotUsage as u };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"doctor-contract-api.js","source":"extensions/copilot/doctor-contract-api.ts"},{"output":"harness.js","source":"extensions/copilot/harness.ts"},{"output":"index.js","source":"extensions/copilot/index.ts"}],"chunks":[{"output":".setup/attempt-
|
|
1
|
+
{"version":3,"entries":[{"output":"doctor-contract-api.js","source":"extensions/copilot/doctor-contract-api.ts"},{"output":"harness.js","source":"extensions/copilot/harness.ts"},{"output":"index.js","source":"extensions/copilot/index.ts"}],"chunks":[{"output":".setup/attempt-BdJgfQV3.mjs","sha256":"dd8eba90fce03545c5b33eb9c5adc9c8cc7f014329fb8f3f3f03a3b400ab68e9","facadeSource":"extensions/copilot/src/attempt.ts","sources":["extensions/copilot/src/attempt-active-run.ts","extensions/copilot/src/attempt-cleanup.ts","extensions/copilot/src/attempt-config.ts","extensions/copilot/src/attempt-execution.ts","extensions/copilot/src/attempt-finalize.ts","extensions/copilot/src/attempt-mode.ts","extensions/copilot/src/attempt-prepare.ts","extensions/copilot/src/attempt-session-setup.ts","extensions/copilot/src/attempt-transcript-journal.ts","extensions/copilot/src/attempt-transcript-memory.ts","extensions/copilot/src/attempt-transcript-replay.ts","extensions/copilot/src/attempt-types.ts","extensions/copilot/src/attempt.ts","extensions/copilot/src/event-bridge.ts","extensions/copilot/src/hooks-bridge.ts","extensions/copilot/src/permission-bridge.ts","extensions/copilot/src/replay-shim.ts","extensions/copilot/src/tool-bridge.ts","extensions/copilot/src/user-input-bridge.ts","extensions/copilot/src/workspace-bootstrap.ts"]},{"output":".setup/harness-Djqx8viF.mjs","sha256":"2ab34c0d7df4306731c9bdb3129d8cc117e71b0645eca21914c272a815879f31","facadeSource":null,"sources":["extensions/copilot/harness.ts","extensions/copilot/src/auth-bridge.ts","extensions/copilot/src/byok-proxy.ts","extensions/copilot/src/history-compaction.ts","extensions/copilot/src/prompt-error.ts","extensions/copilot/src/provider-bridge.ts"]},{"output":".setup/isolated-completion-Dp_YaEKF.mjs","sha256":"aa698a1ae1602503f7373cb714313ddc8c9e16c5675cc5c6bd57a8bc6cbdd3c9","facadeSource":"extensions/copilot/src/isolated-completion.ts","sources":["extensions/copilot/src/isolated-completion.ts"]},{"output":".setup/runtime-artifact-D42RfCpG.mjs","sha256":"082946825c5318439ae36db5f4343ded3ba35cb4f9ecd892edee9aa58f6780ee","facadeSource":"extensions/copilot/src/runtime-artifact.ts","sources":["extensions/copilot/src/runtime-artifact.ts"]},{"output":".setup/runtime-CAM77uEc.mjs","sha256":"c7b639cff6cba9672516b486ff468d0903e3b84b992f96be6e5fab40824d9d54","facadeSource":"extensions/copilot/src/runtime.ts","sources":["extensions/copilot/src/runtime.ts"]},{"output":".setup/sdk-loader-BXVlNPFC.mjs","sha256":"dec0c9bf1eaf2752951a14e2c5af43f6451198db7b05b1916f5b7a5e9de2a951","facadeSource":null,"sources":["extensions/copilot/package.json","extensions/copilot/src/sdk-loader.ts"]},{"output":".setup/session-restrictions-BrC08l2U.mjs","sha256":"8bcede067598930f18a4e5c97aeaaaf30b494ec1897a2f328d10e6943fdb02fa","facadeSource":null,"sources":["extensions/copilot/src/event-bridge-transcript.ts","extensions/copilot/src/session-restrictions.ts","extensions/copilot/src/usage-bridge.ts"]},{"output":"doctor-contract-api.js","sha256":"a502f11264fe700a54e481914d9d56d8fb5b4d905cdd6f1c26238fc675c651fd","facadeSource":"extensions/copilot/doctor-contract-api.ts","sources":["extensions/copilot/doctor-contract-api.ts"]},{"output":"harness.js","sha256":"653939b2bc4b374f00d6e4e9dee6c13983206c7662d2476aa8014ed7299cf2c8","facadeSource":"extensions/copilot/harness.ts","sources":[]},{"output":"index.js","sha256":"5edb9823c0d1ebfc5e3f9eb9e495bfdfeaff304be10348bbe911a4dd96b498e8","facadeSource":"extensions/copilot/index.ts","sources":["extensions/copilot/index.ts"]}],"unrenderedSources":[]}
|
package/dist/harness.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createCopilotAgentHarness } from "./.setup/harness-
|
|
1
|
+
export { t as createCopilotAgentHarness } from "./.setup/harness-Djqx8viF.mjs";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createCopilotAgentHarness } from "./.setup/harness-
|
|
1
|
+
import { t as createCopilotAgentHarness } from "./.setup/harness-Djqx8viF.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
4
|
// extensions/copilot/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/copilot",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.11.5-beta.1",
|
|
4
4
|
"description": "OpenClaw GitHub Copilot agent runtime plugin (registers a `github-copilot` AgentHarness backed by @github/copilot-sdk over JSON-RPC to the GitHub Copilot CLI)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@github/copilot-sdk": "1.0.
|
|
11
|
+
"@github/copilot-sdk": "1.0.23"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@openclaw/plugin-sdk": "workspace:*"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"minHostVersion": ">=2026.5.28"
|
|
25
25
|
},
|
|
26
26
|
"compat": {
|
|
27
|
-
"pluginApi": ">=2026.
|
|
27
|
+
"pluginApi": ">=2026.11.5-beta.1"
|
|
28
28
|
},
|
|
29
29
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.
|
|
30
|
+
"openclawVersion": "2026.11.5-beta.1",
|
|
31
31
|
"bundledDist": false
|
|
32
32
|
},
|
|
33
33
|
"release": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"assets/activity.svg"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"openclaw": ">=2026.
|
|
50
|
+
"openclaw": ">=2026.11.5-beta.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"openclaw": {
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import path, { resolve, sep } from "node:path";
|
|
3
|
-
import { toStringifiedError } from "openclaw/plugin-sdk/error-runtime";
|
|
4
|
-
import { existsSync } from "node:fs";
|
|
5
|
-
import { pathToFileURL } from "node:url";
|
|
6
|
-
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
|
7
|
-
// extensions/copilot/package.json
|
|
8
|
-
var dependencies = { "@github/copilot-sdk": "1.0.16" };
|
|
9
|
-
// extensions/copilot/src/sdk-loader.ts
|
|
10
|
-
function resolveCopilotSdkFallbackDir(env = process.env) {
|
|
11
|
-
return path.join(resolveStateDir(env), "npm-runtime", "copilot");
|
|
12
|
-
}
|
|
13
|
-
const COPILOT_SDK_SPEC = `@github/copilot-sdk@${dependencies["@github/copilot-sdk"]}`;
|
|
14
|
-
let cached;
|
|
15
|
-
async function loadCopilotSdk(options = {}) {
|
|
16
|
-
const useCache = options.cache !== false;
|
|
17
|
-
if (useCache && cached) return cached;
|
|
18
|
-
const promise = doLoad(options);
|
|
19
|
-
if (useCache) {
|
|
20
|
-
cached = promise.catch((err) => {
|
|
21
|
-
cached = void 0;
|
|
22
|
-
throw err;
|
|
23
|
-
});
|
|
24
|
-
return cached;
|
|
25
|
-
}
|
|
26
|
-
return promise;
|
|
27
|
-
}
|
|
28
|
-
async function doLoad(options) {
|
|
29
|
-
const fallbackDir = options.fallbackDir ?? resolveCopilotSdkFallbackDir();
|
|
30
|
-
const primaryImport = options.primaryImport ?? (async () => await import("@github/copilot-sdk"));
|
|
31
|
-
let primaryErr;
|
|
32
|
-
try {
|
|
33
|
-
return await primaryImport();
|
|
34
|
-
} catch (err) {
|
|
35
|
-
primaryErr = err;
|
|
36
|
-
}
|
|
37
|
-
const fallbackPath = path.join(fallbackDir, "node_modules", "@github", "copilot-sdk");
|
|
38
|
-
if (!existsSync(fallbackPath)) throw createMissingSdkError(primaryErr, void 0, fallbackPath);
|
|
39
|
-
const fallbackImport = options.fallbackImport ?? (async () => {
|
|
40
|
-
const entry = createRequire(path.join(fallbackDir, "package.json")).resolve("@github/copilot-sdk");
|
|
41
|
-
return await import(pathToFileURL(entry).href);
|
|
42
|
-
});
|
|
43
|
-
try {
|
|
44
|
-
return await fallbackImport(fallbackPath);
|
|
45
|
-
} catch (fallbackErr) {
|
|
46
|
-
throw createMissingSdkError(primaryErr, fallbackErr, fallbackPath);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function createMissingSdkError(primaryErr, fallbackErr, fallbackPath) {
|
|
50
|
-
const lines = [
|
|
51
|
-
"[copilot] @github/copilot-sdk is not installed.",
|
|
52
|
-
"",
|
|
53
|
-
"The external @openclaw/copilot plugin depends on @github/copilot-sdk",
|
|
54
|
-
"including its platform-specific Copilot runtime package.",
|
|
55
|
-
"Reinstall the plugin once with:",
|
|
56
|
-
"",
|
|
57
|
-
" openclaw plugins install @openclaw/copilot",
|
|
58
|
-
"",
|
|
59
|
-
"For source checkouts or offline repair, install the SDK directly:",
|
|
60
|
-
"",
|
|
61
|
-
` npm install ${COPILOT_SDK_SPEC}`,
|
|
62
|
-
"",
|
|
63
|
-
`The legacy fallback location is still checked at\n ${fallbackPath}`,
|
|
64
|
-
"",
|
|
65
|
-
"Primary resolution error:",
|
|
66
|
-
` ${summarizeError(primaryErr)}`
|
|
67
|
-
];
|
|
68
|
-
if (fallbackErr !== void 0) lines.push("", "Fallback resolution error:", ` ${summarizeError(fallbackErr)}`);
|
|
69
|
-
const err = new Error(lines.join("\n"));
|
|
70
|
-
err.code = "COPILOT_SDK_MISSING";
|
|
71
|
-
return err;
|
|
72
|
-
}
|
|
73
|
-
function summarizeError(value) {
|
|
74
|
-
if (value === void 0 || value === null) return "(none)";
|
|
75
|
-
if (value instanceof Error) return value.message || String(value);
|
|
76
|
-
if (typeof value === "string") return value;
|
|
77
|
-
try {
|
|
78
|
-
return JSON.stringify(value);
|
|
79
|
-
} catch {
|
|
80
|
-
return Object.prototype.toString.call(value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// extensions/copilot/src/runtime.ts
|
|
84
|
-
const DEFAULT_IDLE_TTL_MS = 3e5;
|
|
85
|
-
const POOL_DISPOSED_MESSAGE = "[copilot-pool] pool disposed";
|
|
86
|
-
function createCopilotClientPool(options = {}) {
|
|
87
|
-
const sdkFactory = options.sdkFactory ?? (async (clientOptions) => {
|
|
88
|
-
return new (await (loadCopilotSdk())).CopilotClient(clientOptions);
|
|
89
|
-
});
|
|
90
|
-
const idleTtlMs = options.idleTtlMs ?? DEFAULT_IDLE_TTL_MS;
|
|
91
|
-
const entries = /* @__PURE__ */ new Map();
|
|
92
|
-
const releasedHandles = /* @__PURE__ */ new WeakSet();
|
|
93
|
-
let disposePromise;
|
|
94
|
-
const createDisposedError = () => /* @__PURE__ */ new Error(POOL_DISPOSED_MESSAGE);
|
|
95
|
-
const maybeDeleteEntry = (entry) => {
|
|
96
|
-
if (entries.get(entry.cacheKey) === entry) entries.delete(entry.cacheKey);
|
|
97
|
-
};
|
|
98
|
-
const stopEntry = (entry) => {
|
|
99
|
-
if (entry.stopping) return entry.stopping;
|
|
100
|
-
clearTimeout(entry.idleTimer);
|
|
101
|
-
entry.stopping = (async () => {
|
|
102
|
-
try {
|
|
103
|
-
return await (await entry.client).stop();
|
|
104
|
-
} catch (error) {
|
|
105
|
-
return [toStringifiedError(error)];
|
|
106
|
-
} finally {
|
|
107
|
-
maybeDeleteEntry(entry);
|
|
108
|
-
}
|
|
109
|
-
})();
|
|
110
|
-
return entry.stopping;
|
|
111
|
-
};
|
|
112
|
-
const createEntry = (key, cacheKey, clientOptions) => {
|
|
113
|
-
const entry = {
|
|
114
|
-
key,
|
|
115
|
-
cacheKey,
|
|
116
|
-
refCount: 0,
|
|
117
|
-
client: Promise.resolve().then(async () => {
|
|
118
|
-
try {
|
|
119
|
-
return await sdkFactory(clientOptions);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
maybeDeleteEntry(entry);
|
|
122
|
-
throw toStringifiedError(error);
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
};
|
|
126
|
-
entries.set(cacheKey, entry);
|
|
127
|
-
return entry;
|
|
128
|
-
};
|
|
129
|
-
const acquire = async (inputKey, optionsForCreate) => {
|
|
130
|
-
const key = normalizePoolKey(inputKey, optionsForCreate.copilotHome, optionsForCreate.mode);
|
|
131
|
-
const cacheKey = JSON.stringify(key);
|
|
132
|
-
const clientOptions = normalizeClientCreateOptions(optionsForCreate, key.copilotHome);
|
|
133
|
-
while (true) {
|
|
134
|
-
if (disposePromise) throw createDisposedError();
|
|
135
|
-
const entry = entries.get(cacheKey) ?? createEntry(key, cacheKey, clientOptions);
|
|
136
|
-
if (entry.stopping) {
|
|
137
|
-
await entry.stopping;
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
clearTimeout(entry.idleTimer);
|
|
141
|
-
entry.refCount += 1;
|
|
142
|
-
const client = await entry.client;
|
|
143
|
-
if (disposePromise) {
|
|
144
|
-
await stopEntry(entry);
|
|
145
|
-
throw createDisposedError();
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
key: entry.key,
|
|
149
|
-
client
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const release = async (handle) => {
|
|
154
|
-
if (releasedHandles.has(handle)) return;
|
|
155
|
-
releasedHandles.add(handle);
|
|
156
|
-
const entry = entries.get(JSON.stringify(handle.key));
|
|
157
|
-
if (!entry || entry.stopping || await entry.client !== handle.client) return;
|
|
158
|
-
entry.refCount -= 1;
|
|
159
|
-
if (entry.refCount > 0) return;
|
|
160
|
-
if (disposePromise) {
|
|
161
|
-
await stopEntry(entry);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
entry.idleTimer = setTimeout(() => {
|
|
165
|
-
stopEntry(entry);
|
|
166
|
-
}, idleTtlMs);
|
|
167
|
-
};
|
|
168
|
-
const dispose = async () => {
|
|
169
|
-
if (disposePromise) {
|
|
170
|
-
await disposePromise;
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
const snapshot = [...entries.values()];
|
|
174
|
-
for (const entry of snapshot) clearTimeout(entry.idleTimer);
|
|
175
|
-
disposePromise = (async () => {
|
|
176
|
-
const errors = [];
|
|
177
|
-
for (const entry of snapshot) {
|
|
178
|
-
const stopErrors = await stopEntry(entry);
|
|
179
|
-
errors.push(...stopErrors);
|
|
180
|
-
}
|
|
181
|
-
entries.clear();
|
|
182
|
-
return errors;
|
|
183
|
-
})();
|
|
184
|
-
return await disposePromise;
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
acquire,
|
|
188
|
-
release,
|
|
189
|
-
dispose,
|
|
190
|
-
size: () => entries.size
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function normalizePoolKey(key, rawCopilotHome, clientMode) {
|
|
194
|
-
return {
|
|
195
|
-
agentId: key.agentId,
|
|
196
|
-
copilotHome: normalizeCopilotHome(rawCopilotHome),
|
|
197
|
-
authMode: key.authMode,
|
|
198
|
-
authProfileId: key.authProfileId,
|
|
199
|
-
authProfileVersion: key.authProfileVersion,
|
|
200
|
-
...clientMode === "empty" ? { clientMode } : {}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function normalizeClientCreateOptions(options, normalizedCopilotHome) {
|
|
204
|
-
const { copilotHome: _copilotHome, ...clientOptions } = options;
|
|
205
|
-
return {
|
|
206
|
-
...clientOptions,
|
|
207
|
-
baseDirectory: normalizedCopilotHome
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function normalizeCopilotHome(copilotHome) {
|
|
211
|
-
let normalizedHome = resolve(copilotHome);
|
|
212
|
-
if (normalizedHome.endsWith(sep) && normalizedHome.length > 1) normalizedHome = normalizedHome.slice(0, -1);
|
|
213
|
-
if (process.platform === "win32") normalizedHome = normalizedHome.toLowerCase();
|
|
214
|
-
return normalizedHome;
|
|
215
|
-
}
|
|
216
|
-
export { createCopilotClientPool };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { asOptionalObjectRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
2
|
-
import { resolveOptionalIntegerOption } from "openclaw/plugin-sdk/number-runtime";
|
|
3
|
-
// extensions/copilot/src/session-restrictions.ts
|
|
4
|
-
const COPILOT_ISOLATED_EXCLUDED_TOOLS = [
|
|
5
|
-
"builtin:*",
|
|
6
|
-
"mcp:*",
|
|
7
|
-
"custom:*"
|
|
8
|
-
];
|
|
9
|
-
/** Disable every ambient SDK capability for a prompt-only or settled final turn. */
|
|
10
|
-
function createCopilotIsolatedSessionRestrictions() {
|
|
11
|
-
return {
|
|
12
|
-
availableTools: [],
|
|
13
|
-
coauthorEnabled: false,
|
|
14
|
-
customAgents: [],
|
|
15
|
-
customAgentsLocalOnly: true,
|
|
16
|
-
embeddingCacheStorage: "in-memory",
|
|
17
|
-
enableConfigDiscovery: false,
|
|
18
|
-
enableFileHooks: false,
|
|
19
|
-
enableHostGitOperations: false,
|
|
20
|
-
enableOnDemandInstructionDiscovery: false,
|
|
21
|
-
enableSessionStore: false,
|
|
22
|
-
enableSkills: false,
|
|
23
|
-
excludedTools: [...COPILOT_ISOLATED_EXCLUDED_TOOLS],
|
|
24
|
-
includeSubAgentStreamingEvents: false,
|
|
25
|
-
infiniteSessions: { enabled: false },
|
|
26
|
-
instructionDirectories: [],
|
|
27
|
-
manageScheduleEnabled: false,
|
|
28
|
-
mcpOAuthTokenStorage: "in-memory",
|
|
29
|
-
mcpServers: {},
|
|
30
|
-
memory: { enabled: false },
|
|
31
|
-
pluginDirectories: [],
|
|
32
|
-
remoteSession: "off",
|
|
33
|
-
requestCanvasRenderer: false,
|
|
34
|
-
requestExtensions: false,
|
|
35
|
-
skillDirectories: [],
|
|
36
|
-
skipCustomInstructions: true,
|
|
37
|
-
skipEmbeddingRetrieval: true,
|
|
38
|
-
tools: []
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// extensions/copilot/src/usage-bridge.ts
|
|
42
|
-
function normalizeCopilotUsage(data) {
|
|
43
|
-
const source = asOptionalObjectRecord(data);
|
|
44
|
-
if (!source) return;
|
|
45
|
-
const input = resolveOptionalIntegerOption(source.inputTokens, { min: 0 });
|
|
46
|
-
const output = resolveOptionalIntegerOption(source.outputTokens, { min: 0 });
|
|
47
|
-
const cacheRead = resolveOptionalIntegerOption(source.cacheReadTokens, { min: 0 });
|
|
48
|
-
const cacheWrite = resolveOptionalIntegerOption(source.cacheWriteTokens, { min: 0 });
|
|
49
|
-
return {
|
|
50
|
-
cacheRead,
|
|
51
|
-
cacheWrite,
|
|
52
|
-
input,
|
|
53
|
-
output,
|
|
54
|
-
total: (input ?? 0) + (output ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function buildCopilotAssistantUsage(params) {
|
|
58
|
-
const usage = params.usage ?? normalizeCopilotUsage({ outputTokens: params.fallbackOutputTokens });
|
|
59
|
-
return {
|
|
60
|
-
cacheRead: usage?.cacheRead ?? 0,
|
|
61
|
-
cacheWrite: usage?.cacheWrite ?? 0,
|
|
62
|
-
cost: {
|
|
63
|
-
cacheRead: 0,
|
|
64
|
-
cacheWrite: 0,
|
|
65
|
-
input: 0,
|
|
66
|
-
output: 0,
|
|
67
|
-
total: 0
|
|
68
|
-
},
|
|
69
|
-
input: usage?.input ?? 0,
|
|
70
|
-
output: usage?.output ?? 0,
|
|
71
|
-
totalTokens: usage?.total ?? 0
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export { normalizeCopilotUsage as n, createCopilotIsolatedSessionRestrictions as r, buildCopilotAssistantUsage as t };
|