@openclaw/copilot 2026.8.1-beta.3 → 2026.8.2
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/{attempt-DsIndF6T.js → attempt-5q0X0LCu.js} +145 -171
- package/dist/{harness-BJ_IcIJk.js → harness-Bmmbz3QS.js} +13 -15
- package/dist/harness.js +1 -1
- package/dist/index.js +10 -5
- package/dist/{isolated-completion-D9VIGPmy.js → isolated-completion-BYHkro0M.js} +1 -1
- package/dist/{runtime-C2t8Iz5R.js → runtime-LtZ5NAjV.js} +8 -6
- package/package.json +5 -5
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { a as resolveCopilotAuth, i as createCopilotByokAuth, n as resolveCopilotProvider, r as createCopilotByokProxy } from "./harness-
|
|
1
|
+
import { a as resolveCopilotAuth, i as createCopilotByokAuth, n as resolveCopilotProvider, r as createCopilotByokProxy } from "./harness-Bmmbz3QS.js";
|
|
2
2
|
import { n as normalizeCopilotUsage, r as createCopilotIsolatedSessionRestrictions, t as buildCopilotAssistantUsage } from "./usage-bridge-Cpa-ZYwL.js";
|
|
3
|
-
import { normalizeOptionalString, normalizeUniqueStringEntries, readNonBlankString, readNonEmptyStringPreservingWhitespace, readNonEmptyStringPreservingWhitespace as readNonEmptyString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
-
import { SKILL_WORKSHOP_TOOL_NAME,
|
|
3
|
+
import { asNonArrayRecord, normalizeOptionalString, normalizeUniqueStringEntries, readNonBlankString, readNonEmptyStringPreservingWhitespace, readNonEmptyStringPreservingWhitespace as readNonEmptyString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
+
import { SKILL_WORKSHOP_TOOL_NAME, applyEmbeddedAttemptToolsAllow, awaitAgentEndSideEffects, buildAgentHookContextChannelFields, buildCredentialSafetyPrompt, buildDelegationGuidanceSection, buildEmbeddedAttemptToolRunContext, buildEmbeddedForegroundPromptContext, buildHarnessVisibleReplyGuidance, buildSkillWorkshopPromptSection, callGatewayTool, cancelPendingAgentQuestionForSession, claimPendingAgentQuestionAnswer, clearActiveEmbeddedRun, detectAndLoadAgentHarnessPromptImages, embeddedAgentLog, extractToolErrorMessage, getModelProviderRequestTransport, getPluginToolMeta, getPluginToolSideEffectOwnerKey, isHostScopedAgentToolActive, isSubagentSessionKey, isToolResultError, projectAgentHarnessTranscriptMessageForDisplay, resolveAgentDir, resolveAgentHarnessBeforePromptBuildResult, resolveAttemptFsWorkspaceOnly, resolveAttemptSpawnWorkspaceDir, resolveBootstrapContextForRun, resolveCompactionTimeoutMs, resolveEmbeddedAttemptToolConstructionPlan, resolveMainSessionDelegationMode, resolveModelAuthMode, resolveSandboxContext, resolveUserPath, runAgentEndSideEffects, runAgentHarnessAfterCompactionHook, runAgentHarnessAfterToolCallHook, runAgentHarnessBeforeCompactionHook, runAgentHarnessBeforeMessageWriteHook, runAgentHarnessGatewayQuestion, runAgentHarnessLlmInputHook, runAgentHarnessLlmOutputHook, sanitizeToolResult, setActiveEmbeddedRun } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { formatErrorMessage, toErrorObject, toStringifiedError, toStringifiedError as toCopilotError } from "openclaw/plugin-sdk/error-runtime";
|
|
7
7
|
import { parseDateStringTimestampMs } from "openclaw/plugin-sdk/number-runtime";
|
|
8
8
|
import fsp from "node:fs/promises";
|
|
9
|
+
import { resolveSessionAgentIdsStrict } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
9
10
|
import { convertMcpCallToolResult } from "@github/copilot-sdk";
|
|
10
11
|
import { createAgentHarnessToolSurfaceRuntime } from "openclaw/plugin-sdk/agent-harness-tool-runtime";
|
|
11
12
|
import { isDeepStrictEqual } from "node:util";
|
|
13
|
+
import { createDeferred } from "openclaw/plugin-sdk/extension-shared";
|
|
12
14
|
import { appendSessionTranscriptMessageByIdentityStrict, appendSessionTranscriptMessagesByIdentity, publishSessionTranscriptUpdateByIdentity, readVisibleSessionTranscriptMessageEntries } from "openclaw/plugin-sdk/session-transcript-runtime";
|
|
13
15
|
import { createAgentHarnessTaskRuntime } from "openclaw/plugin-sdk/agent-harness-task-runtime";
|
|
14
16
|
//#region extensions/copilot/src/attempt-types.ts
|
|
@@ -351,7 +353,7 @@ function createResult(params, state) {
|
|
|
351
353
|
messagingToolSentTexts: [],
|
|
352
354
|
replayMetadata,
|
|
353
355
|
sessionFileUsed: readNonEmptyString(params.sessionFile),
|
|
354
|
-
sessionIdUsed:
|
|
356
|
+
sessionIdUsed: params.sessionId,
|
|
355
357
|
toolMetas,
|
|
356
358
|
yieldDetected: state.yieldDetected === true,
|
|
357
359
|
...state.yieldAcknowledgment ? { yieldAcknowledgment: state.yieldAcknowledgment } : {}
|
|
@@ -477,8 +479,9 @@ function resolveModelRef(params) {
|
|
|
477
479
|
};
|
|
478
480
|
}
|
|
479
481
|
function resolvePoolAcquire(params) {
|
|
482
|
+
const model = resolveModelRef(params);
|
|
480
483
|
const provider = resolveCopilotProvider({
|
|
481
|
-
model
|
|
484
|
+
model,
|
|
482
485
|
resolvedApiKey: readNonEmptyString(params.resolvedApiKey),
|
|
483
486
|
authProfileId: readNonEmptyString(params.authProfileId)
|
|
484
487
|
});
|
|
@@ -542,7 +545,7 @@ function buildAssistantMessage(params) {
|
|
|
542
545
|
type: "text"
|
|
543
546
|
});
|
|
544
547
|
for (const request of toolRequests) content.push({
|
|
545
|
-
arguments: request.arguments
|
|
548
|
+
arguments: asNonArrayRecord(request.arguments),
|
|
546
549
|
id: request.toolCallId,
|
|
547
550
|
name: request.name,
|
|
548
551
|
type: "toolCall"
|
|
@@ -1327,7 +1330,7 @@ function registerCopilotActiveRun(params) {
|
|
|
1327
1330
|
}
|
|
1328
1331
|
if (params.isSettled() || params.isAborted()) throw new Error("Copilot steering is unavailable after the active run ended");
|
|
1329
1332
|
if (!params.canAcceptSteering()) throw new Error("Copilot steering is unavailable before initial user validation");
|
|
1330
|
-
messageId = await params.session.send({ prompt: text });
|
|
1333
|
+
messageId = await params.transcriptJournal.sendSdkUser(() => params.session.send({ prompt: text }), options?.userTurnTranscriptRecorder);
|
|
1331
1334
|
reportAcceptance(true);
|
|
1332
1335
|
} catch (error) {
|
|
1333
1336
|
reportAcceptance(false);
|
|
@@ -1345,6 +1348,7 @@ function registerCopilotActiveRun(params) {
|
|
|
1345
1348
|
const activeRunHandle = {
|
|
1346
1349
|
kind: "embedded",
|
|
1347
1350
|
runId: params.input.runId,
|
|
1351
|
+
startedAtMs: params.startedAtMs,
|
|
1348
1352
|
toolAuthorityFingerprint: params.input.toolAuthorityFingerprint,
|
|
1349
1353
|
claimPendingUserInputAnswer,
|
|
1350
1354
|
cancelPendingUserInput,
|
|
@@ -1389,7 +1393,7 @@ async function waitForPersistenceReceipt(receipt, requestedTimeoutMs) {
|
|
|
1389
1393
|
//#endregion
|
|
1390
1394
|
//#region extensions/copilot/src/attempt-finalize.ts
|
|
1391
1395
|
async function completeCopilotAttempt(params) {
|
|
1392
|
-
const { aborted, attemptStartedAt, bridge, codeModeEngaged, downgradedFromResume, externalAbort, hookContext, hookContextWindowFields, input, lastToolError, messages, nativeSessionHistoryUnvalidated, transcriptJournal, modelRef, now, promptError, releaseError, resumeFailureRecovered, sdkSessionId, sentTurnStarted,
|
|
1396
|
+
const { aborted, attemptStartedAt, bridge, codeModeEngaged, downgradedFromResume, externalAbort, hookContext, hookContextWindowFields, input, lastToolError, messages, nativeSessionHistoryUnvalidated, transcriptJournal, modelRef, now, promptError, releaseError, resumeFailureRecovered, sdkSessionId, sentTurnStarted, settledFinalizationAssistantCompleted, settledToolFinalization, timedOut, timedOutDuringCompaction, yieldDetected, yieldAcknowledgment } = params;
|
|
1393
1397
|
const snap = bridge?.snapshot();
|
|
1394
1398
|
const assistantTexts = bridge?.finalizeAssistantTexts() ?? [];
|
|
1395
1399
|
const lastAssistant = bridge?.buildAssistantMessage({
|
|
@@ -1425,7 +1429,6 @@ async function completeCopilotAttempt(params) {
|
|
|
1425
1429
|
promptError,
|
|
1426
1430
|
resumeFailureRecovered,
|
|
1427
1431
|
sdkSessionId,
|
|
1428
|
-
sessionIdUsed,
|
|
1429
1432
|
timedOut,
|
|
1430
1433
|
timedOutDuringCompaction,
|
|
1431
1434
|
toolMetas: snap ? [...snap.toolMetas] : [],
|
|
@@ -1522,21 +1525,12 @@ async function createCopilotToolBridge(input) {
|
|
|
1522
1525
|
disableTools: attemptParams.disableTools,
|
|
1523
1526
|
forceMessageTool: shouldForceCopilotMessageTool(attemptParams),
|
|
1524
1527
|
isRawModelRun: isRawCopilotModelRun(attemptParams),
|
|
1525
|
-
toolsAllow:
|
|
1528
|
+
toolsAllow: buildEmbeddedAttemptToolRunContext({
|
|
1529
|
+
...attemptParams,
|
|
1530
|
+
forceMessageTool: shouldForceCopilotMessageTool(attemptParams)
|
|
1531
|
+
}).runtimeToolAllowlist
|
|
1526
1532
|
});
|
|
1527
|
-
|
|
1528
|
-
...toolPlan,
|
|
1529
|
-
codingToolConstructionPlan: {
|
|
1530
|
-
includeBaseCodingTools: true,
|
|
1531
|
-
includeChannelTools: true,
|
|
1532
|
-
includeOpenClawTools: true,
|
|
1533
|
-
includePluginTools: true,
|
|
1534
|
-
includeShellTools: true
|
|
1535
|
-
},
|
|
1536
|
-
constructTools: true,
|
|
1537
|
-
includeCoreTools: true
|
|
1538
|
-
} : toolPlan;
|
|
1539
|
-
if (!effectiveToolPlan.constructTools) return {
|
|
1533
|
+
if (!toolPlan.constructTools) return {
|
|
1540
1534
|
codeModeEngaged: false,
|
|
1541
1535
|
promptToolPolicy: EMPTY_PROMPT_TOOL_POLICY,
|
|
1542
1536
|
sourceTools: []
|
|
@@ -1544,28 +1538,29 @@ async function createCopilotToolBridge(input) {
|
|
|
1544
1538
|
const createOpenClawCodingTools = input.createOpenClawCodingTools ?? (await import("openclaw/plugin-sdk/agent-harness")).createOpenClawCodingTools;
|
|
1545
1539
|
const toolSurfaceRuntime = createAgentHarnessToolSurfaceRuntime({
|
|
1546
1540
|
abortSignal: input.abortSignal,
|
|
1547
|
-
agentId: input.agentId,
|
|
1541
|
+
agentId: attemptParams.sandboxAgentId ?? input.agentId,
|
|
1548
1542
|
config: attemptParams.config,
|
|
1543
|
+
codeModeOverride: attemptParams.codeModeOverride,
|
|
1549
1544
|
disableTools: attemptParams.disableTools,
|
|
1550
1545
|
executeTool: (toolParams) => executeCatalogTool(input, toolParams),
|
|
1551
1546
|
forceMessageTool: shouldForceCopilotMessageTool(attemptParams),
|
|
1552
1547
|
isRawModelRun: isRawCopilotModelRun(attemptParams),
|
|
1553
1548
|
model: attemptParams.model,
|
|
1549
|
+
contextTokenBudget: attemptParams.contextTokenBudget,
|
|
1554
1550
|
modelId: input.modelId,
|
|
1555
1551
|
modelProvider: input.modelProvider,
|
|
1556
1552
|
modelToolsEnabled: true,
|
|
1557
1553
|
prompt: attemptParams.prompt,
|
|
1558
1554
|
runId: attemptParams.runId,
|
|
1559
|
-
runtimeToolAllowlist:
|
|
1555
|
+
runtimeToolAllowlist: toolPlan.runtimeToolAllowlist,
|
|
1560
1556
|
sessionId: input.sessionId,
|
|
1561
1557
|
sessionKey: attemptParams.sandboxSessionKey ?? attemptParams.sessionKey ?? input.sessionKey,
|
|
1562
1558
|
scheduledToolPolicy: attemptParams.scheduledToolPolicy,
|
|
1563
|
-
skillWorkshopProposalOnly: attemptParams.skillWorkshopProposalOnly,
|
|
1564
1559
|
sourceReplyDeliveryMode: attemptParams.sourceReplyDeliveryMode,
|
|
1565
1560
|
toolsAllow: attemptParams.toolsAllow
|
|
1566
1561
|
});
|
|
1567
1562
|
const toolOptions = buildOpenClawCodingToolsOptions(input, {
|
|
1568
|
-
...
|
|
1563
|
+
...toolPlan,
|
|
1569
1564
|
runtimeToolAllowlist: toolSurfaceRuntime.runtimeToolAllowlist
|
|
1570
1565
|
}, toolSurfaceRuntime);
|
|
1571
1566
|
let sourceTools;
|
|
@@ -1583,7 +1578,7 @@ async function createCopilotToolBridge(input) {
|
|
|
1583
1578
|
} catch (error) {
|
|
1584
1579
|
throw createError(`[copilot-tool-bridge] createOpenClawCodingTools failed: ${toStringifiedError(error).message}`, error);
|
|
1585
1580
|
}
|
|
1586
|
-
const plannedSourceTools = filterCopilotToolsForConstructionPlan(applyEmbeddedAttemptToolsAllow(sourceTools, toolSurfaceRuntime.runtimeToolAllowlist, { toolMeta: (tool) => getPluginToolMeta(tool) ?? readInlinePluginToolMeta(tool) }),
|
|
1581
|
+
const plannedSourceTools = filterCopilotToolsForConstructionPlan(applyEmbeddedAttemptToolsAllow(sourceTools, toolSurfaceRuntime.runtimeToolAllowlist, { toolMeta: (tool) => getPluginToolMeta(tool) ?? readInlinePluginToolMeta(tool) }), toolPlan.codingToolConstructionPlan, { preserveToolNames: toolSurfaceRuntime.runtimeToolAllowlist });
|
|
1587
1582
|
const compactedTools = toolSurfaceRuntime.compactTools(plannedSourceTools, { localModelLeanApplied: true });
|
|
1588
1583
|
const newlyConstructedTools = compactedTools.tools.filter((tool) => !boundSourceTools.has(tool));
|
|
1589
1584
|
const boundNewlyConstructedTools = newlyConstructedTools.length > 0 ? hostCapabilities.bindToolSurface(newlyConstructedTools, bindingOptions) : newlyConstructedTools;
|
|
@@ -1604,7 +1599,14 @@ async function createCopilotToolBridge(input) {
|
|
|
1604
1599
|
cleanup: toolSurfaceRuntime.cleanup,
|
|
1605
1600
|
codeModeEngaged: toolSurfaceRuntime.codeModeControlsEnabled,
|
|
1606
1601
|
promptToolPolicy: { apply: (params = {}) => {
|
|
1607
|
-
const result = compactedTools.promptToolPolicy.apply(
|
|
1602
|
+
const result = compactedTools.promptToolPolicy.apply({
|
|
1603
|
+
...params,
|
|
1604
|
+
toolsAllow: buildEmbeddedAttemptToolRunContext({
|
|
1605
|
+
...attemptParams,
|
|
1606
|
+
toolsAllow: params.toolsAllow,
|
|
1607
|
+
forceMessageTool: shouldForceCopilotMessageTool(attemptParams)
|
|
1608
|
+
}).runtimeToolAllowlist
|
|
1609
|
+
});
|
|
1608
1610
|
const directToolNames = new Set(result.tools.map((tool) => tool.name));
|
|
1609
1611
|
return {
|
|
1610
1612
|
tools: sdkTools.filter((tool) => directToolNames.has(tool.name)),
|
|
@@ -1615,26 +1617,9 @@ async function createCopilotToolBridge(input) {
|
|
|
1615
1617
|
};
|
|
1616
1618
|
}
|
|
1617
1619
|
/**
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
1621
|
-
* Why PI parity matters: bridged OpenClaw tools register with the SDK
|
|
1622
|
-
* as `overridesBuiltInTool: true, skipPermission: true` (see
|
|
1623
|
-
* `convertOpenClawToolToSdkTool` below). That means the wrapped-tool
|
|
1624
|
-
* enforcement layer
|
|
1625
|
-
* (`src/agents/pi-tools.before-tool-call.ts → wrapToolWithBeforeToolCallHook`)
|
|
1626
|
-
* is the single gate for permission, owner-only allowlists, loop
|
|
1627
|
-
* detection, trusted-plugin policies, and two-phase plugin approvals.
|
|
1628
|
-
* That layer reads its context from the fields forwarded here; missing
|
|
1629
|
-
* fields silently degrade policy decisions. See docs/plugins/copilot.md.
|
|
1630
|
-
*
|
|
1631
|
-
* The shared embedded-runner tool plan is forwarded so the bridge does
|
|
1632
|
-
* not construct broad tool families only to filter them later. That
|
|
1633
|
-
* preserves PI allowlist semantics such as `write` not materializing
|
|
1634
|
-
* `apply_patch`.
|
|
1635
|
-
* Sandbox is forwarded via the explicit `sandbox` field on
|
|
1636
|
-
* {@link CopilotToolBridgeInput}; callers resolve it via
|
|
1637
|
-
* `resolveSandboxContext` before constructing the bridge.
|
|
1620
|
+
* Bridged tools skip SDK permission prompts, so host wrappers need the complete
|
|
1621
|
+
* attempt context and prepared sandbox/construction policy to enforce access.
|
|
1622
|
+
* Missing fields here silently weaken or misapply the native harness contract.
|
|
1638
1623
|
*/
|
|
1639
1624
|
function buildOpenClawCodingToolsOptions(input, toolPlan, toolSurfaceRuntime) {
|
|
1640
1625
|
const a = input.attemptParams;
|
|
@@ -1654,13 +1639,8 @@ function buildOpenClawCodingToolsOptions(input, toolPlan, toolSurfaceRuntime) {
|
|
|
1654
1639
|
const modelCompat = model && typeof model === "object" && "compat" in model && model.compat && typeof model.compat === "object" ? model.compat : void 0;
|
|
1655
1640
|
return {
|
|
1656
1641
|
agentId: input.agentId,
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
jobId: a.jobId,
|
|
1660
|
-
memoryFlushWritePath: a.memoryFlushWritePath,
|
|
1661
|
-
toolsAllow: a.toolsAllow,
|
|
1662
|
-
conversationToolPolicy: a.conversationToolPolicy
|
|
1663
|
-
}),
|
|
1642
|
+
policyAgentId: a.sandboxAgentId ?? input.agentId,
|
|
1643
|
+
...buildEmbeddedAttemptToolRunContext(a),
|
|
1664
1644
|
exec: {
|
|
1665
1645
|
...a.execOverrides,
|
|
1666
1646
|
elevated: a.bashElevated
|
|
@@ -1708,7 +1688,7 @@ function buildOpenClawCodingToolsOptions(input, toolPlan, toolSurfaceRuntime) {
|
|
|
1708
1688
|
toolConstructionPlan: toolPlan.codingToolConstructionPlan,
|
|
1709
1689
|
modelCompat,
|
|
1710
1690
|
modelApi: model?.api,
|
|
1711
|
-
modelContextWindowTokens: model?.contextWindow,
|
|
1691
|
+
modelContextWindowTokens: a.contextTokenBudget ?? model?.contextWindow,
|
|
1712
1692
|
delegationCapability: a.delegationCapability,
|
|
1713
1693
|
modelAuthMode: resolveModelAuthMode(input.modelProvider, a.config, void 0, { workspaceDir }),
|
|
1714
1694
|
currentChannelId: a.currentChannelId,
|
|
@@ -1857,6 +1837,7 @@ function convertOpenClawToolToSdkTool(sourceTool, ctx) {
|
|
|
1857
1837
|
} : executeOnce;
|
|
1858
1838
|
return {
|
|
1859
1839
|
description: sourceTool.description,
|
|
1840
|
+
defer: sourceTool.catalogMode === "direct-only" ? "never" : void 0,
|
|
1860
1841
|
handler,
|
|
1861
1842
|
name: sourceTool.name,
|
|
1862
1843
|
overridesBuiltInTool: true,
|
|
@@ -1977,12 +1958,6 @@ function filterCopilotToolsForConstructionPlan(tools, plan, options = {}) {
|
|
|
1977
1958
|
return true;
|
|
1978
1959
|
});
|
|
1979
1960
|
}
|
|
1980
|
-
function hasNonWildcardGlobAllowlist(toolsAllow) {
|
|
1981
|
-
return (toolsAllow ?? []).some((entry) => {
|
|
1982
|
-
const trimmed = entry.trim();
|
|
1983
|
-
return trimmed !== "*" && trimmed.includes("*");
|
|
1984
|
-
});
|
|
1985
|
-
}
|
|
1986
1961
|
function readInlinePluginToolMeta(tool) {
|
|
1987
1962
|
const pluginId = tool.pluginId;
|
|
1988
1963
|
return typeof pluginId === "string" && pluginId.trim() ? { pluginId } : void 0;
|
|
@@ -2026,7 +2001,7 @@ function prepareCopilotAttemptContext(params, deps) {
|
|
|
2026
2001
|
const modelRef = resolveModelRef(input);
|
|
2027
2002
|
const resolvedWorkspaceForSandbox = readResolvedAttemptPath(input.workspaceDir) ?? readResolvedAttemptPath(input.cwd);
|
|
2028
2003
|
const sandboxSessionKey = readNonEmptyString(input.sandboxSessionKey) ?? readNonEmptyString(input.sessionKey) ?? readNonEmptyString(input.sessionId);
|
|
2029
|
-
const { sessionAgentId } =
|
|
2004
|
+
const { sessionAgentId } = resolveSessionAgentIdsStrict({
|
|
2030
2005
|
sessionKey: readNonEmptyString(input.sessionKey),
|
|
2031
2006
|
config: input.config,
|
|
2032
2007
|
agentId: readNonEmptyString(params.agentId)
|
|
@@ -2051,12 +2026,16 @@ function prepareCopilotAttemptContext(params, deps) {
|
|
|
2051
2026
|
runId: input.runId,
|
|
2052
2027
|
jobId: input.jobId,
|
|
2053
2028
|
agentId: sessionAgentId,
|
|
2054
|
-
sessionKey: sandboxSessionKey,
|
|
2029
|
+
sessionKey: readNonEmptyString(input.sessionKey) ?? sandboxSessionKey,
|
|
2055
2030
|
sessionId: input.sessionId,
|
|
2056
2031
|
workspaceDir: resolvedWorkspaceForSandbox,
|
|
2057
2032
|
modelProviderId: modelRef.provider,
|
|
2058
2033
|
modelId: modelRef.id,
|
|
2059
2034
|
trigger: input.trigger,
|
|
2035
|
+
foregroundPromptContext: buildEmbeddedForegroundPromptContext({
|
|
2036
|
+
...input,
|
|
2037
|
+
agentId: sessionAgentId
|
|
2038
|
+
}, input.agentDir ?? resolveAgentDir(input.config ?? {}, sessionAgentId)),
|
|
2060
2039
|
...input.config ? { config: input.config } : {},
|
|
2061
2040
|
...hookContextWindowFields,
|
|
2062
2041
|
...buildAgentHookContextChannelFields(input)
|
|
@@ -2067,6 +2046,7 @@ async function resolveCopilotAttemptSandbox(params) {
|
|
|
2067
2046
|
const resolveSandbox = params.deps.resolveSandboxContextOverride ?? resolveSandboxContext;
|
|
2068
2047
|
const sandbox = params.input.sandbox !== void 0 ? params.input.sandbox : await resolveSandbox({
|
|
2069
2048
|
config: params.input.config,
|
|
2049
|
+
agentId: params.input.sandboxAgentId,
|
|
2070
2050
|
sessionKey: params.sandboxSessionKey,
|
|
2071
2051
|
workspaceDir: params.resolvedWorkspaceForSandbox
|
|
2072
2052
|
});
|
|
@@ -2107,7 +2087,7 @@ function buildCopilotPromptGuidance(params) {
|
|
|
2107
2087
|
sourceReplyDeliveryMode: params.attempt.sourceReplyDeliveryMode,
|
|
2108
2088
|
messageToolAvailable: callableTools.has("message")
|
|
2109
2089
|
}),
|
|
2110
|
-
|
|
2090
|
+
buildCredentialSafetyPrompt(params.attempt.disableTools !== true && callableTools.has("secrets") ? "secrets" : void 0),
|
|
2111
2091
|
params.workspaceBootstrapInstructions?.trim(),
|
|
2112
2092
|
extraSystemPrompt ? `${isMinimal ? "## Subagent Context" : "## Conversation Context"}\n${extraSystemPrompt}` : void 0
|
|
2113
2093
|
].filter((section) => section?.trim()).join("\n\n") || void 0;
|
|
@@ -2115,7 +2095,7 @@ function buildCopilotPromptGuidance(params) {
|
|
|
2115
2095
|
//#endregion
|
|
2116
2096
|
//#region extensions/copilot/src/user-input-bridge.ts
|
|
2117
2097
|
const COPILOT_USER_INPUT_QUESTION_ID = "answer";
|
|
2118
|
-
const DEFAULT_USER_INPUT_TIMEOUT_MS =
|
|
2098
|
+
const DEFAULT_USER_INPUT_TIMEOUT_MS = 9e5;
|
|
2119
2099
|
function createCopilotUserInputBridge(params) {
|
|
2120
2100
|
let pending;
|
|
2121
2101
|
const gatewayCall = params.gatewayCall ?? callGatewayTool;
|
|
@@ -2452,6 +2432,41 @@ async function createCopilotSessionSetup(params) {
|
|
|
2452
2432
|
};
|
|
2453
2433
|
}
|
|
2454
2434
|
//#endregion
|
|
2435
|
+
//#region extensions/copilot/src/attempt-transcript-replay.ts
|
|
2436
|
+
function readAssistantToolCallIds(message) {
|
|
2437
|
+
return message.role === "assistant" ? message.content.flatMap((part) => part.type === "toolCall" ? [part.id] : []) : [];
|
|
2438
|
+
}
|
|
2439
|
+
function isCompatibleSingletonRewrite(original, prepared) {
|
|
2440
|
+
return original.role === prepared.role && (original.role !== "assistant" || JSON.stringify(readAssistantToolCallIds(original)) === JSON.stringify(readAssistantToolCallIds(prepared)));
|
|
2441
|
+
}
|
|
2442
|
+
function projectReplayPayload(message) {
|
|
2443
|
+
switch (message.role) {
|
|
2444
|
+
case "user": return {
|
|
2445
|
+
role: message.role,
|
|
2446
|
+
content: message.content
|
|
2447
|
+
};
|
|
2448
|
+
case "assistant": return {
|
|
2449
|
+
role: message.role,
|
|
2450
|
+
content: message.content,
|
|
2451
|
+
api: message.api,
|
|
2452
|
+
model: message.model,
|
|
2453
|
+
provider: message.provider,
|
|
2454
|
+
stopReason: message.stopReason
|
|
2455
|
+
};
|
|
2456
|
+
case "toolResult": return {
|
|
2457
|
+
role: message.role,
|
|
2458
|
+
content: message.content,
|
|
2459
|
+
isError: message.isError,
|
|
2460
|
+
toolCallId: message.toolCallId,
|
|
2461
|
+
toolName: message.toolName
|
|
2462
|
+
};
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
function isCompleteToolGroup(messages, order) {
|
|
2466
|
+
const [assistant, ...results] = messages;
|
|
2467
|
+
return assistant?.role === "assistant" && JSON.stringify(readAssistantToolCallIds(assistant)) === JSON.stringify(order) && results.length === order.length && results.every((message, index) => message.role === "toolResult" && message.toolCallId === order[index]);
|
|
2468
|
+
}
|
|
2469
|
+
//#endregion
|
|
2455
2470
|
//#region extensions/copilot/src/attempt-transcript-journal.ts
|
|
2456
2471
|
function readTurnTaintMetadata(message) {
|
|
2457
2472
|
const metadata = message["__openclaw"];
|
|
@@ -2508,6 +2523,7 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2508
2523
|
let queue = Promise.resolve();
|
|
2509
2524
|
let firstFailure;
|
|
2510
2525
|
const sdkUserPersistenceReceipts = /* @__PURE__ */ new Map();
|
|
2526
|
+
const sdkUserRecorders = /* @__PURE__ */ new Map();
|
|
2511
2527
|
let abortPromise;
|
|
2512
2528
|
let replayInvalid = false;
|
|
2513
2529
|
let initialSdkUserObserved = false;
|
|
@@ -2528,7 +2544,8 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2528
2544
|
const sdkUserPersistenceReceipt = (eventId) => {
|
|
2529
2545
|
let receipt = sdkUserPersistenceReceipts.get(eventId);
|
|
2530
2546
|
if (!receipt) {
|
|
2531
|
-
receipt =
|
|
2547
|
+
receipt = createDeferred();
|
|
2548
|
+
receipt.promise.catch(() => void 0);
|
|
2532
2549
|
sdkUserPersistenceReceipts.set(eventId, receipt);
|
|
2533
2550
|
if (firstFailure) receipt.reject(firstFailure);
|
|
2534
2551
|
}
|
|
@@ -2545,7 +2562,8 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2545
2562
|
const hooked = runAgentHarnessBeforeMessageWriteHook({
|
|
2546
2563
|
message: structuredClone(message),
|
|
2547
2564
|
agentId: target.agentId,
|
|
2548
|
-
sessionKey: target.sessionKey
|
|
2565
|
+
sessionKey: target.sessionKey,
|
|
2566
|
+
prepareAssistantTranscriptMessage: options.singleton && !hiddenTurn ? params.attempt.prepareAssistantTranscriptMessage : void 0
|
|
2549
2567
|
});
|
|
2550
2568
|
if (!hooked) return;
|
|
2551
2569
|
if (!isDeepStrictEqual(originalReplayPayload, projectReplayPayload(hooked))) replayInvalid = true;
|
|
@@ -2563,6 +2581,7 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2563
2581
|
...taintMetadata
|
|
2564
2582
|
} } : {},
|
|
2565
2583
|
...idempotencyKey ? { idempotencyKey } : {},
|
|
2584
|
+
...message.role === "user" && message.provenance ? { provenance: message.provenance } : {},
|
|
2566
2585
|
...message.display === false ? { display: false } : {}
|
|
2567
2586
|
});
|
|
2568
2587
|
return options.singleton && !isCompatibleSingletonRewrite(message, prepared) ? void 0 : prepared;
|
|
@@ -2576,9 +2595,13 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2576
2595
|
message: write.message,
|
|
2577
2596
|
prepareMessageAfterIdempotencyCheck: () => prepare(write, { singleton: true })
|
|
2578
2597
|
});
|
|
2579
|
-
if (outcome.kind === "suppressed")
|
|
2598
|
+
if (outcome.kind === "suppressed") {
|
|
2599
|
+
write.recorder?.markBlocked();
|
|
2600
|
+
return;
|
|
2601
|
+
}
|
|
2580
2602
|
if (outcome.kind === "rejected") throw new Error("Transcript session changed before singleton append");
|
|
2581
2603
|
if (!isDeepStrictEqual(projectReplayPayload(write.message), projectReplayPayload(outcome.result.message))) replayInvalid = true;
|
|
2604
|
+
if (outcome.result.message.role === "user") write.recorder?.markRuntimePersisted(outcome.result.message, outcome.result.anchor);
|
|
2582
2605
|
return outcome.result;
|
|
2583
2606
|
};
|
|
2584
2607
|
const appendToolGroup = async (group) => {
|
|
@@ -2646,6 +2669,20 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2646
2669
|
}
|
|
2647
2670
|
};
|
|
2648
2671
|
return {
|
|
2672
|
+
async sendSdkUser(send, recorder) {
|
|
2673
|
+
if (!recorder) return await send();
|
|
2674
|
+
const registration = createDeferred();
|
|
2675
|
+
schedule(() => registration.promise);
|
|
2676
|
+
try {
|
|
2677
|
+
const messageId = await send();
|
|
2678
|
+
sdkUserRecorders.set(messageId, recorder);
|
|
2679
|
+
recorder.markSentToProvider?.();
|
|
2680
|
+
recorder.markRuntimePersistencePending(sdkUserPersistenceReceipt(messageId).promise);
|
|
2681
|
+
return messageId;
|
|
2682
|
+
} finally {
|
|
2683
|
+
registration.resolve();
|
|
2684
|
+
}
|
|
2685
|
+
},
|
|
2649
2686
|
markReplayIncomplete() {
|
|
2650
2687
|
replayInvalid = true;
|
|
2651
2688
|
},
|
|
@@ -2708,9 +2745,16 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2708
2745
|
}
|
|
2709
2746
|
initialSdkUserObserved = true;
|
|
2710
2747
|
schedule(async () => {
|
|
2748
|
+
const recorder = sdkUserRecorders.get(input.eventId);
|
|
2749
|
+
sdkUserRecorders.delete(input.eventId);
|
|
2750
|
+
const provenance = (await recorder?.resolveMessage())?.provenance;
|
|
2711
2751
|
const write = {
|
|
2712
2752
|
eventId: input.eventId,
|
|
2713
|
-
message:
|
|
2753
|
+
message: provenance ? {
|
|
2754
|
+
...input.message,
|
|
2755
|
+
provenance
|
|
2756
|
+
} : input.message,
|
|
2757
|
+
recorder
|
|
2714
2758
|
};
|
|
2715
2759
|
if (pendingTools) {
|
|
2716
2760
|
deferredUserWrites.push(write);
|
|
@@ -2780,10 +2824,7 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2780
2824
|
replayInvalid = true;
|
|
2781
2825
|
ownAssistant(group.assistantKey, false);
|
|
2782
2826
|
} else {
|
|
2783
|
-
for (const result of results)
|
|
2784
|
-
const didAppend = accept(result);
|
|
2785
|
-
appended ||= didAppend;
|
|
2786
|
-
}
|
|
2827
|
+
for (const result of results) appended = accept(result) || appended;
|
|
2787
2828
|
ownAssistant(group.assistantKey, true, results.at(-1)?.anchor);
|
|
2788
2829
|
}
|
|
2789
2830
|
pendingTools = void 0;
|
|
@@ -2795,8 +2836,7 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2795
2836
|
if (write.eventId) sdkUserPersistenceReceipt(write.eventId).reject(/* @__PURE__ */ new Error("Copilot steering user write was suppressed"));
|
|
2796
2837
|
continue;
|
|
2797
2838
|
}
|
|
2798
|
-
|
|
2799
|
-
appended ||= didAppend;
|
|
2839
|
+
appended = accept(outcome) || appended;
|
|
2800
2840
|
if (write.eventId) deferredReceipts.push(sdkUserPersistenceReceipt(write.eventId));
|
|
2801
2841
|
}
|
|
2802
2842
|
await publish(appended);
|
|
@@ -2818,31 +2858,6 @@ function createAttemptTranscriptJournal(params) {
|
|
|
2818
2858
|
})
|
|
2819
2859
|
};
|
|
2820
2860
|
}
|
|
2821
|
-
function createPersistenceReceipt() {
|
|
2822
|
-
let settled = false;
|
|
2823
|
-
let rejectPromise;
|
|
2824
|
-
let resolvePromise;
|
|
2825
|
-
const promise = new Promise((resolve, reject) => {
|
|
2826
|
-
resolvePromise = resolve;
|
|
2827
|
-
rejectPromise = reject;
|
|
2828
|
-
});
|
|
2829
|
-
promise.catch(() => void 0);
|
|
2830
|
-
return {
|
|
2831
|
-
promise,
|
|
2832
|
-
reject(error) {
|
|
2833
|
-
if (!settled) {
|
|
2834
|
-
settled = true;
|
|
2835
|
-
rejectPromise?.(error);
|
|
2836
|
-
}
|
|
2837
|
-
},
|
|
2838
|
-
resolve() {
|
|
2839
|
-
if (!settled) {
|
|
2840
|
-
settled = true;
|
|
2841
|
-
resolvePromise?.();
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
};
|
|
2845
|
-
}
|
|
2846
2861
|
function resolveTranscriptTarget(attempt) {
|
|
2847
2862
|
const sessionId = normalizeOptionalString(attempt.sessionTarget?.sessionId);
|
|
2848
2863
|
const sessionKey = normalizeOptionalString(attempt.sessionTarget?.sessionKey);
|
|
@@ -2860,35 +2875,6 @@ function resolveTranscriptTarget(attempt) {
|
|
|
2860
2875
|
...agentId ? { agentId } : {}
|
|
2861
2876
|
};
|
|
2862
2877
|
}
|
|
2863
|
-
function readAssistantToolCallIds(message) {
|
|
2864
|
-
return message.role === "assistant" ? message.content.flatMap((part) => part.type === "toolCall" ? [part.id] : []) : [];
|
|
2865
|
-
}
|
|
2866
|
-
function isCompatibleSingletonRewrite(original, prepared) {
|
|
2867
|
-
return original.role === prepared.role && (original.role !== "assistant" || JSON.stringify(readAssistantToolCallIds(original)) === JSON.stringify(readAssistantToolCallIds(prepared)));
|
|
2868
|
-
}
|
|
2869
|
-
function projectReplayPayload(message) {
|
|
2870
|
-
switch (message.role) {
|
|
2871
|
-
case "user": return {
|
|
2872
|
-
role: message.role,
|
|
2873
|
-
content: message.content
|
|
2874
|
-
};
|
|
2875
|
-
case "assistant": return {
|
|
2876
|
-
role: message.role,
|
|
2877
|
-
content: message.content,
|
|
2878
|
-
api: message.api,
|
|
2879
|
-
model: message.model,
|
|
2880
|
-
provider: message.provider,
|
|
2881
|
-
stopReason: message.stopReason
|
|
2882
|
-
};
|
|
2883
|
-
case "toolResult": return {
|
|
2884
|
-
role: message.role,
|
|
2885
|
-
content: message.content,
|
|
2886
|
-
isError: message.isError,
|
|
2887
|
-
toolCallId: message.toolCallId,
|
|
2888
|
-
toolName: message.toolName
|
|
2889
|
-
};
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
2878
|
function readIdempotencyKey(message) {
|
|
2893
2879
|
const key = message.idempotencyKey;
|
|
2894
2880
|
return typeof key === "string" && key ? key : void 0;
|
|
@@ -2896,10 +2882,6 @@ function readIdempotencyKey(message) {
|
|
|
2896
2882
|
function isCurrentJournalIdentity(key, params) {
|
|
2897
2883
|
return key === `${params.attempt.runId}:user` || key.startsWith(`copilot-sdk:${params.sdkSessionId}:`);
|
|
2898
2884
|
}
|
|
2899
|
-
function isCompleteToolGroup(messages, order) {
|
|
2900
|
-
const [assistant, ...results] = messages;
|
|
2901
|
-
return assistant?.role === "assistant" && JSON.stringify(readAssistantToolCallIds(assistant)) === JSON.stringify(order) && results.length === order.length && results.every((message, index) => message.role === "toolResult" && message.toolCallId === order[index]);
|
|
2902
|
-
}
|
|
2903
2885
|
function isSameUserTurn(candidate, current, currentRunUserKey) {
|
|
2904
2886
|
if (candidate?.role !== "user" || !current) return false;
|
|
2905
2887
|
if (candidate === current) return true;
|
|
@@ -3058,7 +3040,6 @@ async function runCopilotExecution(context) {
|
|
|
3058
3040
|
let timedOut = false;
|
|
3059
3041
|
let promptError;
|
|
3060
3042
|
let sdkSessionId;
|
|
3061
|
-
let sessionIdUsed = input.sessionId;
|
|
3062
3043
|
let nativeSessionCreatedFresh = false;
|
|
3063
3044
|
let nativeSessionHistoryValidated = false;
|
|
3064
3045
|
let disconnectError;
|
|
@@ -3119,15 +3100,13 @@ async function runCopilotExecution(context) {
|
|
|
3119
3100
|
messagesSnapshot: messages,
|
|
3120
3101
|
now,
|
|
3121
3102
|
promptError: void 0,
|
|
3122
|
-
sdkSessionId: void 0
|
|
3123
|
-
sessionIdUsed: input.sessionId
|
|
3103
|
+
sdkSessionId: void 0
|
|
3124
3104
|
}));
|
|
3125
3105
|
return finishAttempt(createResult(input, {
|
|
3126
3106
|
messagesSnapshot: messages,
|
|
3127
3107
|
now,
|
|
3128
3108
|
promptError: createPromptError$1("sandbox_resolution_failure", `[copilot-attempt] sandbox resolution failed: ${toCopilotError(error).message}`, error),
|
|
3129
|
-
sdkSessionId: void 0
|
|
3130
|
-
sessionIdUsed: input.sessionId
|
|
3109
|
+
sdkSessionId: void 0
|
|
3131
3110
|
}));
|
|
3132
3111
|
}
|
|
3133
3112
|
hookContext.workspaceDir = effectiveWorkspaceDir;
|
|
@@ -3139,8 +3118,7 @@ async function runCopilotExecution(context) {
|
|
|
3139
3118
|
messagesSnapshot: messages,
|
|
3140
3119
|
now,
|
|
3141
3120
|
promptError: createPromptError$1("sandbox_cwd_override_unsupported", "[copilot-attempt] cwd override is not supported for sandboxed Copilot runs; omit cwd or use the agent workspace as cwd"),
|
|
3142
|
-
sdkSessionId: void 0
|
|
3143
|
-
sessionIdUsed: input.sessionId
|
|
3121
|
+
sdkSessionId: void 0
|
|
3144
3122
|
}));
|
|
3145
3123
|
}
|
|
3146
3124
|
const effectiveCwd = sandbox?.enabled ? effectiveWorkspaceDir : requestedCwd ?? effectiveWorkspaceDir;
|
|
@@ -3168,8 +3146,7 @@ async function runCopilotExecution(context) {
|
|
|
3168
3146
|
messagesSnapshot: messages,
|
|
3169
3147
|
now,
|
|
3170
3148
|
promptError: createPromptError$1("model_not_supported", toCopilotError(error).message, error),
|
|
3171
|
-
sdkSessionId: void 0
|
|
3172
|
-
sessionIdUsed: input.sessionId
|
|
3149
|
+
sdkSessionId: void 0
|
|
3173
3150
|
}));
|
|
3174
3151
|
}
|
|
3175
3152
|
const cleanupByokProxy = byokProxy?.close;
|
|
@@ -3211,7 +3188,7 @@ async function runCopilotExecution(context) {
|
|
|
3211
3188
|
runId: input.runId,
|
|
3212
3189
|
agentId: sessionAgentId,
|
|
3213
3190
|
sessionId: input.sessionId,
|
|
3214
|
-
sessionKey:
|
|
3191
|
+
sessionKey: hookContext.sessionKey,
|
|
3215
3192
|
channelId: hookContext.channelId,
|
|
3216
3193
|
startArgs: args,
|
|
3217
3194
|
...result !== void 0 ? { result } : {},
|
|
@@ -3228,8 +3205,7 @@ async function runCopilotExecution(context) {
|
|
|
3228
3205
|
messagesSnapshot: messages,
|
|
3229
3206
|
now,
|
|
3230
3207
|
promptError: createPromptError$1("tool_bridge_failure", `[copilot-attempt] tool-bridge construction failed: ${toCopilotError(error).message}`, error),
|
|
3231
|
-
sdkSessionId: void 0
|
|
3232
|
-
sessionIdUsed: input.sessionId
|
|
3208
|
+
sdkSessionId: void 0
|
|
3233
3209
|
}));
|
|
3234
3210
|
}
|
|
3235
3211
|
handle = await deps.pool.acquire(poolAcquire.key, poolAcquire.options);
|
|
@@ -3281,7 +3257,6 @@ async function runCopilotExecution(context) {
|
|
|
3281
3257
|
sessionRef.current = session;
|
|
3282
3258
|
sdkSessionId = readNonEmptyString(session.sessionId) ?? readNonEmptyString(session.id) ?? (resumeFailureRecovered ? void 0 : resumeSessionId);
|
|
3283
3259
|
if (!sdkSessionId) throw createPromptError$1("transcript_persistence_failed", "[copilot-attempt] canonical transcript persistence requires the Copilot SDK session id");
|
|
3284
|
-
sessionIdUsed = sdkSessionId ?? input.sessionId;
|
|
3285
3260
|
if (sdkSessionId && deps.onSessionEstablished && !settledToolFinalization) try {
|
|
3286
3261
|
deps.onSessionEstablished({
|
|
3287
3262
|
compactionSessionConfig,
|
|
@@ -3343,6 +3318,7 @@ async function runCopilotExecution(context) {
|
|
|
3343
3318
|
abortActiveSession,
|
|
3344
3319
|
bridge,
|
|
3345
3320
|
canAcceptSteering: () => initialSdkUserValidated,
|
|
3321
|
+
startedAtMs: input.startedAtMs,
|
|
3346
3322
|
input,
|
|
3347
3323
|
isAborted: () => aborted,
|
|
3348
3324
|
isSettled: () => settled,
|
|
@@ -3381,25 +3357,27 @@ async function runCopilotExecution(context) {
|
|
|
3381
3357
|
if (!promptError && !timedOut && !aborted && snap.streamError) promptError = snap.streamError;
|
|
3382
3358
|
}
|
|
3383
3359
|
} catch (error) {
|
|
3384
|
-
if (!aborted)
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3360
|
+
if (!aborted) {
|
|
3361
|
+
if (isSdkSendAndWaitTimeoutError(error)) {
|
|
3362
|
+
timedOut = true;
|
|
3363
|
+
timedOutDuringCompaction = bridge?.isCompacting() === true;
|
|
3364
|
+
try {
|
|
3365
|
+
await bridge?.awaitDeltaChain();
|
|
3366
|
+
} catch {}
|
|
3367
|
+
await bridge?.awaitAgentEventChain();
|
|
3368
|
+
bridge?.flushTranscriptProjection();
|
|
3369
|
+
try {
|
|
3370
|
+
await transcriptJournal?.barrier("timeout");
|
|
3371
|
+
} catch (transcriptError) {
|
|
3372
|
+
promptError = toCopilotError(transcriptError);
|
|
3373
|
+
}
|
|
3374
|
+
} else try {
|
|
3375
|
+
bridge?.flushTranscriptProjection();
|
|
3376
|
+
await transcriptJournal?.barrier("attempt error");
|
|
3377
|
+
promptError = toCopilotError(error);
|
|
3394
3378
|
} catch (transcriptError) {
|
|
3395
3379
|
promptError = toCopilotError(transcriptError);
|
|
3396
3380
|
}
|
|
3397
|
-
} else try {
|
|
3398
|
-
bridge?.flushTranscriptProjection();
|
|
3399
|
-
await transcriptJournal?.barrier("attempt error");
|
|
3400
|
-
promptError = toCopilotError(error);
|
|
3401
|
-
} catch (transcriptError) {
|
|
3402
|
-
promptError = toCopilotError(transcriptError);
|
|
3403
3381
|
}
|
|
3404
3382
|
} finally {
|
|
3405
3383
|
settled = true;
|
|
@@ -3490,7 +3468,6 @@ async function runCopilotExecution(context) {
|
|
|
3490
3468
|
resumeFailureRecovered,
|
|
3491
3469
|
sdkSessionId,
|
|
3492
3470
|
sentTurnStarted,
|
|
3493
|
-
sessionIdUsed,
|
|
3494
3471
|
settledFinalizationAssistantCompleted,
|
|
3495
3472
|
settledToolFinalization,
|
|
3496
3473
|
timedOut,
|
|
@@ -3512,8 +3489,7 @@ async function runCopilotAttempt(params, deps) {
|
|
|
3512
3489
|
messagesSnapshot: messages,
|
|
3513
3490
|
now,
|
|
3514
3491
|
promptError: void 0,
|
|
3515
|
-
sdkSessionId: void 0
|
|
3516
|
-
sessionIdUsed: input.sessionId
|
|
3492
|
+
sdkSessionId: void 0
|
|
3517
3493
|
}));
|
|
3518
3494
|
try {
|
|
3519
3495
|
resolveCopilotProvider({
|
|
@@ -3526,8 +3502,7 @@ async function runCopilotAttempt(params, deps) {
|
|
|
3526
3502
|
messagesSnapshot: messages,
|
|
3527
3503
|
now,
|
|
3528
3504
|
promptError: createPromptError$1("model_not_supported", toCopilotError(error).message, error),
|
|
3529
|
-
sdkSessionId: void 0
|
|
3530
|
-
sessionIdUsed: input.sessionId
|
|
3505
|
+
sdkSessionId: void 0
|
|
3531
3506
|
}));
|
|
3532
3507
|
}
|
|
3533
3508
|
const settledFinalizationSessionId = settledToolFinalization ? readNonEmptyString(input.initialReplayState?.sdkSessionId) : void 0;
|
|
@@ -3535,8 +3510,7 @@ async function runCopilotAttempt(params, deps) {
|
|
|
3535
3510
|
messagesSnapshot: messages,
|
|
3536
3511
|
now,
|
|
3537
3512
|
promptError: createPromptError$1("settled_finalization_session_unavailable", "[copilot-attempt] settled tool finalization requires the existing Copilot SDK session"),
|
|
3538
|
-
sdkSessionId: void 0
|
|
3539
|
-
sessionIdUsed: input.sessionId
|
|
3513
|
+
sdkSessionId: void 0
|
|
3540
3514
|
}));
|
|
3541
3515
|
return await runCopilotExecution({
|
|
3542
3516
|
params,
|
|
@@ -5,7 +5,7 @@ import { homedir } from "node:os";
|
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import { createServer } from "node:http";
|
|
7
7
|
import { Readable } from "node:stream";
|
|
8
|
-
import {
|
|
8
|
+
import { pipeline } from "node:stream/promises";
|
|
9
9
|
import { fetchWithSsrFGuard, isBlockedHostnameOrIp } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
10
10
|
import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
|
|
11
11
|
//#region extensions/copilot/src/auth-bridge.ts
|
|
@@ -157,7 +157,8 @@ function resolveCopilotHome(args) {
|
|
|
157
157
|
if (args.explicit) return resolve(args.explicit);
|
|
158
158
|
if (args.agentDir) return resolve(join(args.agentDir, "copilot"));
|
|
159
159
|
const openClawHome = readNonEmptyStringPreservingWhitespace(args.env.OPENCLAW_HOME);
|
|
160
|
-
|
|
160
|
+
const rootHome = openClawHome ? resolve(openClawHome) : safeHomeDir(args.homeDir);
|
|
161
|
+
return resolve(join(rootHome, ".openclaw", "agents", args.agentId, "copilot"));
|
|
161
162
|
}
|
|
162
163
|
function safeHomeDir(homeDir) {
|
|
163
164
|
try {
|
|
@@ -281,7 +282,7 @@ async function handleProxyRequest(req, res, params) {
|
|
|
281
282
|
method: req.method,
|
|
282
283
|
headers: buildProxyRequestHeaders(req.headers, { upstreamBearerAuthorization: canInjectBearerAuthorization ? params.upstreamBearerAuthorization : void 0 }),
|
|
283
284
|
signal: upstreamAbort.signal,
|
|
284
|
-
...body ? { body
|
|
285
|
+
...body ? { body } : {}
|
|
285
286
|
},
|
|
286
287
|
auditContext: "copilot-byok-provider",
|
|
287
288
|
requireHttps: true
|
|
@@ -291,7 +292,7 @@ async function handleProxyRequest(req, res, params) {
|
|
|
291
292
|
res.end();
|
|
292
293
|
return;
|
|
293
294
|
}
|
|
294
|
-
await
|
|
295
|
+
await pipeline(Readable.fromWeb(guarded.response.body), res);
|
|
295
296
|
} catch (error) {
|
|
296
297
|
if (res.destroyed || res.writableEnded) return;
|
|
297
298
|
if (res.headersSent) {
|
|
@@ -333,11 +334,6 @@ async function readBody(req) {
|
|
|
333
334
|
for await (const chunk of req) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
334
335
|
return chunks.length > 0 ? Buffer.concat(chunks) : void 0;
|
|
335
336
|
}
|
|
336
|
-
function toFetchBody(body) {
|
|
337
|
-
const copy = new Uint8Array(body.byteLength);
|
|
338
|
-
copy.set(body);
|
|
339
|
-
return copy;
|
|
340
|
-
}
|
|
341
337
|
function normalizeProxyRequestHeaders(headers) {
|
|
342
338
|
const out = {};
|
|
343
339
|
for (const [key, value] of Object.entries(headers)) {
|
|
@@ -504,7 +500,8 @@ function assertByokEndpointHostAllowed(baseUrl) {
|
|
|
504
500
|
if (url.protocol !== "https:") throw new Error(COPILOT_BYOK_ENDPOINT_POLICY_ERROR);
|
|
505
501
|
if (url.username || url.password) throw new Error(COPILOT_BYOK_ENDPOINT_POLICY_ERROR);
|
|
506
502
|
for (const key of url.searchParams.keys()) if (CREDENTIAL_QUERY_PARAM_NAMES.has(normalizeCredentialQueryParamName(key))) throw new Error(COPILOT_BYOK_ENDPOINT_POLICY_ERROR);
|
|
507
|
-
|
|
503
|
+
const hostname = url.hostname.toLowerCase().replace(/\.+$/, "");
|
|
504
|
+
if (isBlockedHostnameOrIp(hostname)) throw new Error(COPILOT_BYOK_ENDPOINT_POLICY_ERROR);
|
|
508
505
|
}
|
|
509
506
|
function normalizeCredentialQueryParamName(name) {
|
|
510
507
|
const stripped = name.replace(QUERY_PARAM_NAME_SEPARATOR_RE, "");
|
|
@@ -827,7 +824,7 @@ function createCopilotAgentHarness(options) {
|
|
|
827
824
|
async function getPool() {
|
|
828
825
|
if (options?.pool) return options.pool;
|
|
829
826
|
if (!poolPromise) poolPromise = (async () => {
|
|
830
|
-
const { createCopilotClientPool } = await import("./runtime-
|
|
827
|
+
const { createCopilotClientPool } = await import("./runtime-LtZ5NAjV.js");
|
|
831
828
|
createdPool = createCopilotClientPool(options?.poolOptions);
|
|
832
829
|
return createdPool;
|
|
833
830
|
})();
|
|
@@ -864,7 +861,7 @@ function createCopilotAgentHarness(options) {
|
|
|
864
861
|
async function runHarnessAttempt(params, operation) {
|
|
865
862
|
const attemptPromise = (async () => {
|
|
866
863
|
if (disposed) throw new Error("[copilot] harness has been disposed; cannot start new attempts");
|
|
867
|
-
const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-
|
|
864
|
+
const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-5q0X0LCu.js");
|
|
868
865
|
if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
|
|
869
866
|
const pool = await getPool();
|
|
870
867
|
if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
|
|
@@ -995,7 +992,7 @@ function createCopilotAgentHarness(options) {
|
|
|
995
992
|
async function runIsolatedCompletionV2(params) {
|
|
996
993
|
const completionPromise = (async () => {
|
|
997
994
|
if (disposed) throw new Error("[copilot] harness has been disposed; cannot start isolated completion");
|
|
998
|
-
const { runCopilotIsolatedCompletion } = await import("./isolated-completion-
|
|
995
|
+
const { runCopilotIsolatedCompletion } = await import("./isolated-completion-BYHkro0M.js");
|
|
999
996
|
if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
|
|
1000
997
|
return await runCopilotIsolatedCompletion(params, async () => {
|
|
1001
998
|
const pool = await getPool();
|
|
@@ -1052,7 +1049,8 @@ function createCopilotAgentHarness(options) {
|
|
|
1052
1049
|
runAttempt: (params) => runHarnessAttempt(params, "attempt"),
|
|
1053
1050
|
runIsolatedCompletionV2,
|
|
1054
1051
|
finalizeSettledTurn: async ({ attempt }) => {
|
|
1055
|
-
|
|
1052
|
+
const result = await runHarnessAttempt(attempt, "settled-tool-finalization");
|
|
1053
|
+
return projectSettledTurnFinalizationAttemptResult(result);
|
|
1056
1054
|
},
|
|
1057
1055
|
async reset(params) {
|
|
1058
1056
|
const openclawSessionId = typeof params.sessionId === "string" ? params.sessionId : void 0;
|
|
@@ -1086,7 +1084,7 @@ function createCopilotAgentHarness(options) {
|
|
|
1086
1084
|
};
|
|
1087
1085
|
const tracked = trackedSessions.get(openclawSessionId);
|
|
1088
1086
|
const currentCompactKey = computeCompactRequestKey(params);
|
|
1089
|
-
const { resolvePoolAcquire } = await import("./attempt-
|
|
1087
|
+
const { resolvePoolAcquire } = await import("./attempt-5q0X0LCu.js");
|
|
1090
1088
|
let resolvedPoolAcquire;
|
|
1091
1089
|
let currentAuth;
|
|
1092
1090
|
try {
|
package/dist/harness.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createCopilotAgentHarness } from "./harness-
|
|
1
|
+
import { t as createCopilotAgentHarness } from "./harness-Bmmbz3QS.js";
|
|
2
2
|
export { createCopilotAgentHarness };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createCopilotAgentHarness } from "./harness-
|
|
1
|
+
import { t as createCopilotAgentHarness } from "./harness-Bmmbz3QS.js";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
4
|
//#region extensions/copilot/index.ts
|
|
@@ -15,16 +15,21 @@ var copilot_default = definePluginEntry({
|
|
|
15
15
|
name: "GitHub Copilot agent runtime",
|
|
16
16
|
description: "Registers the GitHub Copilot agent runtime.",
|
|
17
17
|
register(api) {
|
|
18
|
-
if (api.registrationMode !== "full") return;
|
|
18
|
+
if (api.registrationMode !== "full" && api.registrationMode !== "discovery" && api.registrationMode !== "tool-discovery") return;
|
|
19
19
|
const poolOptions = readPoolOptions(api.pluginConfig);
|
|
20
|
-
|
|
20
|
+
let sessionStore;
|
|
21
|
+
const getSessionStore = () => sessionStore ??= api.runtime.state.openSyncKeyedStore({
|
|
21
22
|
namespace: "sdk-sessions",
|
|
22
23
|
maxEntries: 5e3,
|
|
23
|
-
defaultTtlMs:
|
|
24
|
+
defaultTtlMs: 7776e6
|
|
24
25
|
});
|
|
25
26
|
api.registerAgentHarness(createCopilotAgentHarness({
|
|
26
27
|
...poolOptions ? { poolOptions } : {},
|
|
27
|
-
sessionStore
|
|
28
|
+
sessionStore: {
|
|
29
|
+
register: (key, value, options) => getSessionStore().register(key, value, options),
|
|
30
|
+
lookup: (key) => getSessionStore().lookup(key),
|
|
31
|
+
delete: (key) => getSessionStore().delete(key)
|
|
32
|
+
}
|
|
28
33
|
}));
|
|
29
34
|
}
|
|
30
35
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as resolveCopilotProvider, o as tokenFingerprint, r as createCopilotByokProxy } from "./harness-
|
|
1
|
+
import { n as resolveCopilotProvider, o as tokenFingerprint, r as createCopilotByokProxy } from "./harness-Bmmbz3QS.js";
|
|
2
2
|
import { r as createCopilotIsolatedSessionRestrictions, t as buildCopilotAssistantUsage } from "./usage-bridge-Cpa-ZYwL.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
//#region extensions/copilot/src/isolated-completion.ts
|
|
@@ -4,11 +4,14 @@ import { toStringifiedError } from "openclaw/plugin-sdk/error-runtime";
|
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
|
7
|
+
//#region extensions/copilot/package.json
|
|
8
|
+
var dependencies = { "@github/copilot-sdk": "1.0.11" };
|
|
9
|
+
//#endregion
|
|
7
10
|
//#region extensions/copilot/src/sdk-loader.ts
|
|
8
11
|
function resolveCopilotSdkFallbackDir(env = process.env) {
|
|
9
12
|
return path.join(resolveStateDir(env), "npm-runtime", "copilot");
|
|
10
13
|
}
|
|
11
|
-
const COPILOT_SDK_SPEC = "@github/copilot-sdk
|
|
14
|
+
const COPILOT_SDK_SPEC = `@github/copilot-sdk@${dependencies["@github/copilot-sdk"]}`;
|
|
12
15
|
let cached;
|
|
13
16
|
async function loadCopilotSdk(options = {}) {
|
|
14
17
|
const useCache = options.cache !== false;
|
|
@@ -35,7 +38,8 @@ async function doLoad(options) {
|
|
|
35
38
|
const fallbackPath = path.join(fallbackDir, "node_modules", "@github", "copilot-sdk");
|
|
36
39
|
if (!existsSync(fallbackPath)) throw createMissingSdkError(primaryErr, void 0, fallbackPath);
|
|
37
40
|
const fallbackImport = options.fallbackImport ?? (async () => {
|
|
38
|
-
|
|
41
|
+
const entry = createRequire(path.join(fallbackDir, "package.json")).resolve("@github/copilot-sdk");
|
|
42
|
+
return await import(pathToFileURL(entry).href);
|
|
39
43
|
});
|
|
40
44
|
try {
|
|
41
45
|
return await fallbackImport(fallbackPath);
|
|
@@ -79,7 +83,7 @@ function summarizeError(value) {
|
|
|
79
83
|
}
|
|
80
84
|
//#endregion
|
|
81
85
|
//#region extensions/copilot/src/runtime.ts
|
|
82
|
-
const DEFAULT_IDLE_TTL_MS =
|
|
86
|
+
const DEFAULT_IDLE_TTL_MS = 3e5;
|
|
83
87
|
const POOL_DISPOSED_MESSAGE = "[copilot-pool] pool disposed";
|
|
84
88
|
function createCopilotClientPool(options = {}) {
|
|
85
89
|
const sdkFactory = options.sdkFactory ?? (async (clientOptions) => {
|
|
@@ -259,9 +263,7 @@ function createCopilotClientPool(options = {}) {
|
|
|
259
263
|
case "stopping":
|
|
260
264
|
case "stopped": return;
|
|
261
265
|
case "ready":
|
|
262
|
-
case "idle":
|
|
263
|
-
if (entry.state.client !== handle.client) return;
|
|
264
|
-
break;
|
|
266
|
+
case "idle": if (entry.state.client !== handle.client) return;
|
|
265
267
|
}
|
|
266
268
|
if (entry.refCount <= 0) return;
|
|
267
269
|
entry.refCount -= 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/copilot",
|
|
3
|
-
"version": "2026.8.
|
|
3
|
+
"version": "2026.8.2",
|
|
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.11"
|
|
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.8.
|
|
27
|
+
"pluginApi": ">=2026.8.2"
|
|
28
28
|
},
|
|
29
29
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.8.
|
|
30
|
+
"openclawVersion": "2026.8.2",
|
|
31
31
|
"bundledDist": false
|
|
32
32
|
},
|
|
33
33
|
"release": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"README.md"
|
|
46
46
|
],
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"openclaw": ">=2026.8.
|
|
48
|
+
"openclaw": ">=2026.8.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"openclaw": {
|