@ai-sdk/harness-acp 1.0.37 → 1.0.39
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/CHANGELOG.md +17 -0
- package/dist/bridge/host-tool-mcp.mjs +1 -1
- package/dist/bridge/index.mjs +149 -12
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts +30 -5
- package/dist/index.js +241 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/acp-harness.ts +43 -9
- package/src/index.ts +1 -0
- package/src/v1/acp-v1-bridge-protocol.ts +15 -0
- package/src/v1/acp-v1-harness.ts +275 -5
- package/src/v1/acp-v1-settings.ts +22 -0
- package/src/v1/bridge/acp-v1-bridge-environment.ts +6 -0
- package/src/v1/bridge/create-emit-stream-event.ts +6 -0
- package/src/v1/bridge/host-tool-correlation.ts +34 -0
- package/src/v1/bridge/index.ts +97 -3
- package/src/v1/bridge/stream-translator.ts +6 -1
- package/src/v1/index.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HarnessV1Authentication, HarnessV1RequestTransformation, HarnessV1CredentialForwarding, HarnessV1PermissionMode, HarnessV1PortEndpoint, HarnessV1 } from '@ai-sdk/harness';
|
|
2
|
-
import { ToolSet } from '@ai-sdk/provider-utils';
|
|
1
|
+
import { HarnessV1StreamPart, HarnessV1Authentication, HarnessV1RequestTransformation, HarnessV1CredentialForwarding, HarnessV1PermissionMode, HarnessV1PortEndpoint, HarnessV1, HARNESS_V1_BUILTIN_TOOLS } from '@ai-sdk/harness';
|
|
2
|
+
import { ToolResultPart, ToolSet } from '@ai-sdk/provider-utils';
|
|
3
3
|
|
|
4
4
|
type ACPMetadata = Record<string, unknown>;
|
|
5
5
|
type ACPRole = 'assistant' | 'user';
|
|
@@ -182,6 +182,26 @@ type ACPOutputSchemaMapping = {
|
|
|
182
182
|
readonly type: 'session-prompt-meta';
|
|
183
183
|
readonly path: ReadonlyArray<string>;
|
|
184
184
|
};
|
|
185
|
+
type ACPAskUserQuestionsSettings = {
|
|
186
|
+
readonly requestMethod: string;
|
|
187
|
+
readonly isNativeToolCall?: (options: {
|
|
188
|
+
nativeToolCall: ACPToolCall;
|
|
189
|
+
}) => boolean;
|
|
190
|
+
readonly fromNativeRequest: (options: {
|
|
191
|
+
nativeRequest: unknown;
|
|
192
|
+
nativeToolCall?: ACPToolCall;
|
|
193
|
+
}) => Extract<HarnessV1StreamPart, {
|
|
194
|
+
type: 'tool-call';
|
|
195
|
+
}> | null;
|
|
196
|
+
readonly toNativeResponse: (options: {
|
|
197
|
+
nativeRequest: unknown;
|
|
198
|
+
toolResult: ToolResultPart;
|
|
199
|
+
}) => unknown;
|
|
200
|
+
readonly matchesNativeRequest?: (options: {
|
|
201
|
+
previousNativeRequest: unknown;
|
|
202
|
+
nativeRequest: unknown;
|
|
203
|
+
}) => boolean;
|
|
204
|
+
};
|
|
185
205
|
type ACPV1Settings = {
|
|
186
206
|
readonly version?: 'v1';
|
|
187
207
|
readonly harnessId: string;
|
|
@@ -232,6 +252,7 @@ type ACPV1Settings = {
|
|
|
232
252
|
* below the ACP session prompt's `_meta` field.
|
|
233
253
|
*/
|
|
234
254
|
readonly outputSchemaMapping?: ACPOutputSchemaMapping;
|
|
255
|
+
readonly askUserQuestions?: ACPAskUserQuestionsSettings;
|
|
235
256
|
readonly permissionModeMapping?: ACPPermissionModeMapping;
|
|
236
257
|
readonly session?: {
|
|
237
258
|
readonly meta?: Readonly<Record<string, ACPSerializableValue>>;
|
|
@@ -249,7 +270,7 @@ type ACPClientApp = {
|
|
|
249
270
|
readonly version: string;
|
|
250
271
|
};
|
|
251
272
|
|
|
252
|
-
type ACPHarnessSettings<TBuiltinTools extends ToolSet = {}> = {
|
|
273
|
+
type ACPHarnessSettings<TBuiltinTools extends ToolSet = {}, TAskUserQuestions extends ACPAskUserQuestionsSettings | undefined = ACPAskUserQuestionsSettings | undefined> = {
|
|
253
274
|
readonly builtinTools?: TBuiltinTools;
|
|
254
275
|
/**
|
|
255
276
|
* MCP server definitions keyed by server name. Each definition uses the
|
|
@@ -295,12 +316,16 @@ type ACPHarnessSettings<TBuiltinTools extends ToolSet = {}> = {
|
|
|
295
316
|
readonly skillsDirectory?: ACPV1Settings['skillsDirectory'];
|
|
296
317
|
readonly instructionMapping?: ACPV1Settings['instructionMapping'];
|
|
297
318
|
readonly outputSchemaMapping?: ACPV1Settings['outputSchemaMapping'];
|
|
319
|
+
readonly askUserQuestions?: TAskUserQuestions;
|
|
298
320
|
readonly permissionModeMapping?: ACPV1Settings['permissionModeMapping'];
|
|
299
321
|
readonly session?: ACPV1Settings['session'];
|
|
300
322
|
readonly mintBridgeToken?: ACPV1Settings['mintBridgeToken'];
|
|
301
323
|
};
|
|
302
|
-
|
|
324
|
+
type ACPHarnessTools<TBuiltinTools extends ToolSet, TAskUserQuestions> = TBuiltinTools & ([TAskUserQuestions] extends [undefined] ? {} : {
|
|
325
|
+
askUserQuestions: typeof HARNESS_V1_BUILTIN_TOOLS.askUserQuestions;
|
|
326
|
+
});
|
|
327
|
+
declare function createACP<TBuiltinTools extends ToolSet = {}, TAskUserQuestions extends ACPAskUserQuestionsSettings | undefined = undefined>(settings: ACPHarnessSettings<TBuiltinTools, TAskUserQuestions>): HarnessV1<ACPHarnessTools<TBuiltinTools, TAskUserQuestions>>;
|
|
303
328
|
|
|
304
329
|
declare const VERSION: string;
|
|
305
330
|
|
|
306
|
-
export { type ACPAnnotations, type ACPAudioContent, type ACPAuthentication, type ACPAuthenticationMode, type ACPBlobResourceContents, type ACPClientApp, type ACPContentBlock, type ACPCredentialBrokering, type ACPEmbeddedResource, type ACPHarnessSettings, type ACPImageContent, type ACPInstallCommandSource, type ACPInstructionMapping, type ACPMetadata, type ACPModelMapping, type ACPNpmLockedSource, type ACPNpmSimpleSource, type ACPOutputSchemaMapping, type ACPPermissionModeMapping, type ACPPermissionModeTarget, type ACPProfileValue, type ACPProviderAuthentication, type ACPResourceLink, type ACPRole, type ACPSerializablePrimitive, type ACPSerializableValue, type ACPSource, type ACPTextContent, type ACPTextResourceContents, type ACPToolCall, type ACPToolCallContent, type ACPToolCallLocation, type ACPToolCallStatus, type ACPToolKind, type ACPV1Settings, type ACPValueSource, VERSION, createACP };
|
|
331
|
+
export { type ACPAnnotations, type ACPAskUserQuestionsSettings, type ACPAudioContent, type ACPAuthentication, type ACPAuthenticationMode, type ACPBlobResourceContents, type ACPClientApp, type ACPContentBlock, type ACPCredentialBrokering, type ACPEmbeddedResource, type ACPHarnessSettings, type ACPImageContent, type ACPInstallCommandSource, type ACPInstructionMapping, type ACPMetadata, type ACPModelMapping, type ACPNpmLockedSource, type ACPNpmSimpleSource, type ACPOutputSchemaMapping, type ACPPermissionModeMapping, type ACPPermissionModeTarget, type ACPProfileValue, type ACPProviderAuthentication, type ACPResourceLink, type ACPRole, type ACPSerializablePrimitive, type ACPSerializableValue, type ACPSource, type ACPTextContent, type ACPTextResourceContents, type ACPToolCall, type ACPToolCallContent, type ACPToolCallLocation, type ACPToolCallStatus, type ACPToolKind, type ACPV1Settings, type ACPValueSource, VERSION, createACP };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/acp-harness.ts
|
|
2
|
+
import {
|
|
3
|
+
HARNESS_V1_BUILTIN_TOOLS
|
|
4
|
+
} from "@ai-sdk/harness";
|
|
2
5
|
import { z as z4 } from "zod/v4";
|
|
3
6
|
|
|
4
7
|
// src/v1/acp-v1-harness.ts
|
|
@@ -756,13 +759,26 @@ var coldRestoreSchema = z2.object({
|
|
|
756
759
|
});
|
|
757
760
|
var acpToolCallCandidateSchema = z2.object({
|
|
758
761
|
type: z2.literal("acp-tool-call-candidate"),
|
|
762
|
+
requestId: z2.string(),
|
|
759
763
|
toolCall: z2.custom(
|
|
760
764
|
(value) => value != null && typeof value === "object" && typeof value.toolCallId === "string" && typeof value.title === "string"
|
|
761
765
|
)
|
|
762
766
|
});
|
|
767
|
+
var acpQuestionRequestSchema = z2.object({
|
|
768
|
+
type: z2.literal("acp-question-request"),
|
|
769
|
+
requestId: z2.string(),
|
|
770
|
+
nativeRequest: z2.unknown(),
|
|
771
|
+
nativeToolCall: acpToolCallCandidateSchema.shape.toolCall.optional()
|
|
772
|
+
});
|
|
773
|
+
var acpQuestionResolvedSchema = z2.object({
|
|
774
|
+
type: z2.literal("acp-question-resolved"),
|
|
775
|
+
requestId: z2.string()
|
|
776
|
+
});
|
|
763
777
|
var outboundMessageSchema = z2.union([
|
|
764
778
|
harnessV1BridgeOutboundMessageSchema,
|
|
765
|
-
acpToolCallCandidateSchema
|
|
779
|
+
acpToolCallCandidateSchema,
|
|
780
|
+
acpQuestionRequestSchema,
|
|
781
|
+
acpQuestionResolvedSchema
|
|
766
782
|
]);
|
|
767
783
|
var startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
|
|
768
784
|
prompt: z2.array(acpTextContentBlockSchema),
|
|
@@ -828,14 +844,16 @@ var bridgeConfigurationSchema = z3.object({
|
|
|
828
844
|
providerAuthentication: providerAuthenticationSchema.optional(),
|
|
829
845
|
providerEnvironment: z3.record(z3.string(), z3.string()).optional(),
|
|
830
846
|
sessionMeta: serializableRecordSchema.optional(),
|
|
831
|
-
clientCapabilities: serializableRecordSchema.optional()
|
|
847
|
+
clientCapabilities: serializableRecordSchema.optional(),
|
|
848
|
+
askUserQuestionsRequestMethod: z3.string().optional()
|
|
832
849
|
});
|
|
833
850
|
function createACPBridgeEnvironment({
|
|
834
851
|
authentication,
|
|
835
852
|
providerAuthentication,
|
|
836
853
|
providerEnvironment,
|
|
837
854
|
sessionMeta,
|
|
838
|
-
clientCapabilities
|
|
855
|
+
clientCapabilities,
|
|
856
|
+
askUserQuestionsRequestMethod
|
|
839
857
|
}) {
|
|
840
858
|
return {
|
|
841
859
|
[ACP_BRIDGE_CONFIGURATION_ENV]: JSON.stringify({
|
|
@@ -843,7 +861,8 @@ function createACPBridgeEnvironment({
|
|
|
843
861
|
...providerAuthentication == null ? {} : { providerAuthentication },
|
|
844
862
|
...providerEnvironment == null ? {} : { providerEnvironment },
|
|
845
863
|
...sessionMeta == null ? {} : { sessionMeta },
|
|
846
|
-
...clientCapabilities == null ? {} : { clientCapabilities }
|
|
864
|
+
...clientCapabilities == null ? {} : { clientCapabilities },
|
|
865
|
+
...askUserQuestionsRequestMethod == null ? {} : { askUserQuestionsRequestMethod }
|
|
847
866
|
})
|
|
848
867
|
};
|
|
849
868
|
}
|
|
@@ -1367,8 +1386,6 @@ function createACPV1({
|
|
|
1367
1386
|
);
|
|
1368
1387
|
}
|
|
1369
1388
|
sandboxProviderEnvironment = resolvedProviderAuthentication.providerAuthentication?.type === "ai-gateway" ? {} : void 0;
|
|
1370
|
-
} else if (settings.credentialBrokering != null) {
|
|
1371
|
-
warnCredentialBrokeringUnavailable();
|
|
1372
1389
|
}
|
|
1373
1390
|
if (settings.credentialForwarding != null && sandboxProviderEnvironment == null && resolvedProviderAuthentication.providerAuthentication?.type === "ai-gateway") {
|
|
1374
1391
|
sandboxProviderEnvironment = resolveProviderEnvironment({
|
|
@@ -1463,6 +1480,7 @@ function createACPV1({
|
|
|
1463
1480
|
sessionMeta: settings.session?.meta,
|
|
1464
1481
|
instructionMapping: settings.instructionMapping,
|
|
1465
1482
|
outputSchemaMapping: settings.outputSchemaMapping,
|
|
1483
|
+
askUserQuestions: settings.askUserQuestions,
|
|
1466
1484
|
debug: startOptions.observability?.debug,
|
|
1467
1485
|
implementationIdentity,
|
|
1468
1486
|
authenticationProfile,
|
|
@@ -1573,6 +1591,22 @@ function createACPV1({
|
|
|
1573
1591
|
credentialEnvironmentVariables: credentialForwardingEnvironmentVariables,
|
|
1574
1592
|
credentialForwarding: settings.credentialForwarding
|
|
1575
1593
|
}) : sandboxImplementationEnvironment;
|
|
1594
|
+
if (settings.credentialBrokering != null && sandboxCredentialEnvironment == null) {
|
|
1595
|
+
warnCredentialBrokeringUnavailable({
|
|
1596
|
+
environment: {
|
|
1597
|
+
...sandboxImplementationEnvironment,
|
|
1598
|
+
...resolvedProviderAuthentication.env
|
|
1599
|
+
},
|
|
1600
|
+
forwardedEnvironment: {
|
|
1601
|
+
...forwardedImplementationEnvironment,
|
|
1602
|
+
...sandboxProviderAuthenticationEnvironment
|
|
1603
|
+
},
|
|
1604
|
+
credentialEnvironmentVariables: [
|
|
1605
|
+
...credentialForwardingEnvironmentVariables,
|
|
1606
|
+
"AI_SDK_ACP_GATEWAY_API_KEY"
|
|
1607
|
+
]
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1576
1610
|
const port = resolveBridgePort({
|
|
1577
1611
|
sandboxSession,
|
|
1578
1612
|
override: portOverride,
|
|
@@ -1598,7 +1632,8 @@ function createACPV1({
|
|
|
1598
1632
|
providerAuthentication: resolvedProviderAuthentication.providerAuthentication,
|
|
1599
1633
|
providerEnvironment: sandboxProviderEnvironment == null ? void 0 : {},
|
|
1600
1634
|
sessionMeta: settings.session?.meta,
|
|
1601
|
-
clientCapabilities: settings.clientCapabilities
|
|
1635
|
+
clientCapabilities: settings.clientCapabilities,
|
|
1636
|
+
askUserQuestionsRequestMethod: settings.askUserQuestions?.requestMethod
|
|
1602
1637
|
}),
|
|
1603
1638
|
...sandboxProviderAuthenticationEnvironment,
|
|
1604
1639
|
BRIDGE_CHANNEL_TOKEN: token,
|
|
@@ -1706,6 +1741,7 @@ function createACPV1({
|
|
|
1706
1741
|
sessionMeta: settings.session?.meta,
|
|
1707
1742
|
instructionMapping: settings.instructionMapping,
|
|
1708
1743
|
outputSchemaMapping: settings.outputSchemaMapping,
|
|
1744
|
+
askUserQuestions: settings.askUserQuestions,
|
|
1709
1745
|
debug: startOptions.observability?.debug,
|
|
1710
1746
|
implementationIdentity,
|
|
1711
1747
|
authenticationProfile,
|
|
@@ -1943,6 +1979,7 @@ function createSession({
|
|
|
1943
1979
|
sessionMeta,
|
|
1944
1980
|
instructionMapping,
|
|
1945
1981
|
outputSchemaMapping,
|
|
1982
|
+
askUserQuestions,
|
|
1946
1983
|
debug,
|
|
1947
1984
|
implementationIdentity,
|
|
1948
1985
|
authenticationProfile,
|
|
@@ -1976,15 +2013,18 @@ function createSession({
|
|
|
1976
2013
|
let instructionsFingerprint = instructionsFingerprintAtStart;
|
|
1977
2014
|
let latestACPSessionId = acpSessionIdAtStart;
|
|
1978
2015
|
let latestTurnStartConfig = turnStartConfigAtStart;
|
|
2016
|
+
const bufferedQuestionResults = /* @__PURE__ */ new Map();
|
|
1979
2017
|
const markTurnFinished = () => {
|
|
1980
2018
|
turnInFlight = false;
|
|
1981
2019
|
};
|
|
1982
2020
|
channel.on("bridge-thread", (event) => {
|
|
1983
2021
|
latestACPSessionId = event.threadId;
|
|
1984
2022
|
});
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2023
|
+
if (!turnInFlightAtStart) {
|
|
2024
|
+
channel.on("finish", markTurnFinished);
|
|
2025
|
+
channel.on("error", markTurnFinished);
|
|
2026
|
+
channel.onClose(markTurnFinished);
|
|
2027
|
+
}
|
|
1988
2028
|
const wireTurn = ({
|
|
1989
2029
|
emit,
|
|
1990
2030
|
abortSignal,
|
|
@@ -2003,6 +2043,8 @@ function createSession({
|
|
|
2003
2043
|
let openBlock;
|
|
2004
2044
|
const dynamicToolCalls = /* @__PURE__ */ new Map();
|
|
2005
2045
|
const toolCallClassificationErrors = /* @__PURE__ */ new Map();
|
|
2046
|
+
const activeQuestionRequests = /* @__PURE__ */ new Map();
|
|
2047
|
+
const questionToolCallIdsByRequestId = /* @__PURE__ */ new Map();
|
|
2006
2048
|
const subscriptions = [];
|
|
2007
2049
|
const forward = (event) => {
|
|
2008
2050
|
if (event.type === "text-start" || event.type === "reasoning-start") {
|
|
@@ -2066,12 +2108,115 @@ function createSession({
|
|
|
2066
2108
|
subscriptions.push(
|
|
2067
2109
|
channel.on("acp-tool-call-candidate", (event) => {
|
|
2068
2110
|
try {
|
|
2111
|
+
const suppress = askUserQuestions?.isNativeToolCall?.({
|
|
2112
|
+
nativeToolCall: event.toolCall
|
|
2113
|
+
}) === true;
|
|
2069
2114
|
dynamicToolCalls.set(
|
|
2070
2115
|
event.toolCall.toolCallId,
|
|
2071
2116
|
isMcpToolCall?.(event.toolCall) === true
|
|
2072
2117
|
);
|
|
2118
|
+
channel.send({
|
|
2119
|
+
type: "tool-result",
|
|
2120
|
+
toolCallId: event.requestId,
|
|
2121
|
+
output: { suppress }
|
|
2122
|
+
});
|
|
2073
2123
|
} catch (error) {
|
|
2074
2124
|
toolCallClassificationErrors.set(event.toolCall.toolCallId, error);
|
|
2125
|
+
channel.send({
|
|
2126
|
+
type: "tool-result",
|
|
2127
|
+
toolCallId: event.requestId,
|
|
2128
|
+
output: { suppress: false }
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
})
|
|
2132
|
+
);
|
|
2133
|
+
subscriptions.push(
|
|
2134
|
+
channel.on("acp-question-request", (event) => {
|
|
2135
|
+
if (askUserQuestions == null) {
|
|
2136
|
+
channel.send({
|
|
2137
|
+
type: "tool-result",
|
|
2138
|
+
toolCallId: event.requestId,
|
|
2139
|
+
output: { type: "unhandled" }
|
|
2140
|
+
});
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
try {
|
|
2144
|
+
const nativeToolCall = askUserQuestions.fromNativeRequest({
|
|
2145
|
+
nativeRequest: event.nativeRequest,
|
|
2146
|
+
nativeToolCall: event.nativeToolCall
|
|
2147
|
+
});
|
|
2148
|
+
if (nativeToolCall == null) {
|
|
2149
|
+
channel.send({
|
|
2150
|
+
type: "tool-result",
|
|
2151
|
+
toolCallId: event.requestId,
|
|
2152
|
+
output: { type: "unhandled" }
|
|
2153
|
+
});
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
if (nativeToolCall.toolName !== "askUserQuestions" || nativeToolCall.providerExecuted !== false) {
|
|
2157
|
+
throw new Error(
|
|
2158
|
+
`${harnessId} ACP askUserQuestions.fromNativeRequest must return a client-executed askUserQuestions tool call.`
|
|
2159
|
+
);
|
|
2160
|
+
}
|
|
2161
|
+
const toolCall = withNativeQuestionRequest({
|
|
2162
|
+
harnessId,
|
|
2163
|
+
nativeRequest: event.nativeRequest,
|
|
2164
|
+
toolCall: nativeToolCall
|
|
2165
|
+
});
|
|
2166
|
+
const bufferedResult = takeBufferedQuestionResult({
|
|
2167
|
+
bufferedQuestionResults,
|
|
2168
|
+
toolCallId: toolCall.toolCallId,
|
|
2169
|
+
nativeRequest: event.nativeRequest,
|
|
2170
|
+
matchesNativeRequest: askUserQuestions.matchesNativeRequest,
|
|
2171
|
+
harnessId
|
|
2172
|
+
});
|
|
2173
|
+
activeQuestionRequests.set(toolCall.toolCallId, {
|
|
2174
|
+
requestId: event.requestId,
|
|
2175
|
+
nativeRequest: event.nativeRequest
|
|
2176
|
+
});
|
|
2177
|
+
questionToolCallIdsByRequestId.set(
|
|
2178
|
+
event.requestId,
|
|
2179
|
+
toolCall.toolCallId
|
|
2180
|
+
);
|
|
2181
|
+
channel.send({
|
|
2182
|
+
type: "tool-result",
|
|
2183
|
+
toolCallId: event.requestId,
|
|
2184
|
+
output: {
|
|
2185
|
+
type: "handled",
|
|
2186
|
+
toolCallId: toolCall.toolCallId
|
|
2187
|
+
}
|
|
2188
|
+
});
|
|
2189
|
+
if (bufferedResult == null) {
|
|
2190
|
+
forward(toolCall);
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
channel.send({
|
|
2194
|
+
type: "tool-result",
|
|
2195
|
+
toolCallId: toolCall.toolCallId,
|
|
2196
|
+
output: askUserQuestions.toNativeResponse({
|
|
2197
|
+
nativeRequest: event.nativeRequest,
|
|
2198
|
+
toolResult: bufferedResult.toolResult
|
|
2199
|
+
}),
|
|
2200
|
+
isError: bufferedResult.isError,
|
|
2201
|
+
toolResult: bufferedResult.toolResult
|
|
2202
|
+
});
|
|
2203
|
+
} catch (error) {
|
|
2204
|
+
closeForwardedBlock();
|
|
2205
|
+
forward({ type: "error", error });
|
|
2206
|
+
try {
|
|
2207
|
+
channel.send({ type: "abort" });
|
|
2208
|
+
} catch {
|
|
2209
|
+
}
|
|
2210
|
+
settle({ error });
|
|
2211
|
+
}
|
|
2212
|
+
})
|
|
2213
|
+
);
|
|
2214
|
+
subscriptions.push(
|
|
2215
|
+
channel.on("acp-question-resolved", (event) => {
|
|
2216
|
+
const toolCallId = questionToolCallIdsByRequestId.get(event.requestId);
|
|
2217
|
+
if (toolCallId != null) {
|
|
2218
|
+
activeQuestionRequests.delete(toolCallId);
|
|
2219
|
+
questionToolCallIdsByRequestId.delete(event.requestId);
|
|
2075
2220
|
}
|
|
2076
2221
|
})
|
|
2077
2222
|
);
|
|
@@ -2106,6 +2251,7 @@ function createSession({
|
|
|
2106
2251
|
}
|
|
2107
2252
|
subscriptions.push(
|
|
2108
2253
|
channel.on("finish", (event) => {
|
|
2254
|
+
markTurnFinished();
|
|
2109
2255
|
closeForwardedBlock();
|
|
2110
2256
|
forward(event);
|
|
2111
2257
|
settle(abortRequested ? { error: abortError } : {});
|
|
@@ -2113,6 +2259,7 @@ function createSession({
|
|
|
2113
2259
|
);
|
|
2114
2260
|
subscriptions.push(
|
|
2115
2261
|
channel.on("error", (event) => {
|
|
2262
|
+
markTurnFinished();
|
|
2116
2263
|
closeForwardedBlock();
|
|
2117
2264
|
const error = deserializeBridgeError({
|
|
2118
2265
|
error: event.error,
|
|
@@ -2123,6 +2270,7 @@ function createSession({
|
|
|
2123
2270
|
})
|
|
2124
2271
|
);
|
|
2125
2272
|
channel.onClose((_code, reason) => {
|
|
2273
|
+
markTurnFinished();
|
|
2126
2274
|
if (reason === "suspended") {
|
|
2127
2275
|
settle({});
|
|
2128
2276
|
return;
|
|
@@ -2154,11 +2302,48 @@ function createSession({
|
|
|
2154
2302
|
});
|
|
2155
2303
|
},
|
|
2156
2304
|
submitToolResult: async (input) => {
|
|
2305
|
+
if (askUserQuestions != null && input.toolResult?.toolName === "askUserQuestions") {
|
|
2306
|
+
const activeRequest = activeQuestionRequests.get(input.toolCallId);
|
|
2307
|
+
if (activeRequest == null) {
|
|
2308
|
+
const previousNativeRequest = input.toolResult.providerOptions?.[harnessId]?.nativeRequest;
|
|
2309
|
+
if (!lossyRerun && previousNativeRequest !== void 0) {
|
|
2310
|
+
channel.send({
|
|
2311
|
+
type: "tool-result",
|
|
2312
|
+
toolCallId: input.toolCallId,
|
|
2313
|
+
output: askUserQuestions.toNativeResponse({
|
|
2314
|
+
nativeRequest: previousNativeRequest,
|
|
2315
|
+
toolResult: input.toolResult
|
|
2316
|
+
}),
|
|
2317
|
+
isError: input.isError,
|
|
2318
|
+
toolResult: input.toolResult
|
|
2319
|
+
});
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
bufferedQuestionResults.set(input.toolCallId, {
|
|
2323
|
+
output: input.output,
|
|
2324
|
+
...input.isError == null ? {} : { isError: input.isError },
|
|
2325
|
+
toolResult: input.toolResult
|
|
2326
|
+
});
|
|
2327
|
+
return;
|
|
2328
|
+
}
|
|
2329
|
+
channel.send({
|
|
2330
|
+
type: "tool-result",
|
|
2331
|
+
toolCallId: input.toolCallId,
|
|
2332
|
+
output: askUserQuestions.toNativeResponse({
|
|
2333
|
+
nativeRequest: activeRequest.nativeRequest,
|
|
2334
|
+
toolResult: input.toolResult
|
|
2335
|
+
}),
|
|
2336
|
+
isError: input.isError,
|
|
2337
|
+
toolResult: input.toolResult
|
|
2338
|
+
});
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2157
2341
|
channel.send({
|
|
2158
2342
|
type: "tool-result",
|
|
2159
2343
|
toolCallId: input.toolCallId,
|
|
2160
2344
|
output: input.output,
|
|
2161
|
-
isError: input.isError
|
|
2345
|
+
isError: input.isError,
|
|
2346
|
+
toolResult: input.toolResult
|
|
2162
2347
|
});
|
|
2163
2348
|
},
|
|
2164
2349
|
done
|
|
@@ -2472,6 +2657,45 @@ function isCompletePermissionModeMapping({
|
|
|
2472
2657
|
}) {
|
|
2473
2658
|
return isPermissionModeMappingValue({ value: value?.["allow-reads"] }) && isPermissionModeMappingValue({ value: value?.["allow-edits"] }) && isPermissionModeMappingValue({ value: value?.["allow-all"] });
|
|
2474
2659
|
}
|
|
2660
|
+
function withNativeQuestionRequest({
|
|
2661
|
+
harnessId,
|
|
2662
|
+
nativeRequest,
|
|
2663
|
+
toolCall
|
|
2664
|
+
}) {
|
|
2665
|
+
const harnessMetadata = toolCall.providerMetadata?.[harnessId];
|
|
2666
|
+
return {
|
|
2667
|
+
...toolCall,
|
|
2668
|
+
providerMetadata: {
|
|
2669
|
+
...toolCall.providerMetadata,
|
|
2670
|
+
[harnessId]: {
|
|
2671
|
+
...harnessMetadata ?? {},
|
|
2672
|
+
nativeRequest
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
function takeBufferedQuestionResult({
|
|
2678
|
+
bufferedQuestionResults,
|
|
2679
|
+
toolCallId,
|
|
2680
|
+
nativeRequest,
|
|
2681
|
+
matchesNativeRequest,
|
|
2682
|
+
harnessId
|
|
2683
|
+
}) {
|
|
2684
|
+
const exact = bufferedQuestionResults.get(toolCallId);
|
|
2685
|
+
if (exact != null) {
|
|
2686
|
+
bufferedQuestionResults.delete(toolCallId);
|
|
2687
|
+
return exact;
|
|
2688
|
+
}
|
|
2689
|
+
if (matchesNativeRequest == null) return void 0;
|
|
2690
|
+
for (const [bufferedToolCallId, buffered] of bufferedQuestionResults) {
|
|
2691
|
+
const previousNativeRequest = buffered.toolResult.providerOptions?.[harnessId]?.nativeRequest;
|
|
2692
|
+
if (previousNativeRequest !== void 0 && matchesNativeRequest({ previousNativeRequest, nativeRequest })) {
|
|
2693
|
+
bufferedQuestionResults.delete(bufferedToolCallId);
|
|
2694
|
+
return buffered;
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
return void 0;
|
|
2698
|
+
}
|
|
2475
2699
|
function isPermissionModeMappingValue({
|
|
2476
2700
|
value
|
|
2477
2701
|
}) {
|
|
@@ -2617,7 +2841,7 @@ function deserializeBridgeError({
|
|
|
2617
2841
|
}
|
|
2618
2842
|
|
|
2619
2843
|
// src/version.ts
|
|
2620
|
-
var VERSION = true ? "1.0.
|
|
2844
|
+
var VERSION = true ? "1.0.39" : "0.0.0-test";
|
|
2621
2845
|
|
|
2622
2846
|
// src/acp-harness.ts
|
|
2623
2847
|
var ACP_CLIENT_APP = {
|
|
@@ -2677,9 +2901,13 @@ function createACP(settings) {
|
|
|
2677
2901
|
switch (version) {
|
|
2678
2902
|
case "v1": {
|
|
2679
2903
|
const clientApp = settings.clientApp ?? ACP_CLIENT_APP;
|
|
2904
|
+
const builtinTools = settings.askUserQuestions == null ? settings.builtinTools ?? ACP_BUILTIN_TOOLS : {
|
|
2905
|
+
...settings.builtinTools ?? ACP_BUILTIN_TOOLS,
|
|
2906
|
+
askUserQuestions: HARNESS_V1_BUILTIN_TOOLS.askUserQuestions
|
|
2907
|
+
};
|
|
2680
2908
|
return createACPV1({
|
|
2681
2909
|
settings,
|
|
2682
|
-
builtinTools
|
|
2910
|
+
builtinTools,
|
|
2683
2911
|
port: settings.port,
|
|
2684
2912
|
portEndpoint: settings.portEndpoint,
|
|
2685
2913
|
startupTimeoutMs: settings.startupTimeoutMs,
|