stitchkit 0.124.5 → 0.126.0
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 +99 -1
- package/dist/agent-runtime/branch-contract.d.ts +5 -0
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +18 -0
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +9 -2
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-source.d.ts +1 -1
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-branch.d.ts.map +1 -1
- package/dist/application/watch-hub-core.d.ts +2 -1
- package/dist/application/watch-hub-core.d.ts.map +1 -1
- package/dist/application/watch-hub-source.d.ts +2 -0
- package/dist/application/watch-hub-source.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts +20 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/coding-tools.js +4 -4
- package/dist/entrypoints/agent-runtime/harness.js +4 -4
- package/dist/entrypoints/agent-runtime/sandbox.js +4 -4
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +33 -9
- package/dist/entrypoints/agent-runtime.js +12 -12
- package/dist/entrypoints/application.d.ts +1 -1
- package/dist/entrypoints/application.d.ts.map +1 -1
- package/dist/entrypoints/application.js +55 -8
- package/dist/entrypoints/bin/upgrade-cli.js +2 -0
- package/dist/entrypoints/cli.js +6 -6
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/node.js +2 -1
- package/dist/entrypoints/process.js +2 -2
- package/dist/entrypoints/server.d.ts +1 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +7 -7
- package/dist/entrypoints/testing.js +1 -1
- package/dist/entrypoints/tools/agent.js +6 -6
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +4 -4
- package/dist/entrypoints/tools/mcp.js +8 -6
- package/dist/entrypoints/tools/toolkit.js +10 -8
- package/dist/entrypoints/tools.js +11 -11
- package/dist/{index-gbj964dt.js → index-103dp7fz.js} +54 -31
- package/dist/{index-cm07qz01.js → index-1v3k5zgx.js} +1 -1
- package/dist/{index-3n8k175r.js → index-48acz7z0.js} +5 -5
- package/dist/{index-6fmg17bg.js → index-4efxzrht.js} +2 -2
- package/dist/{index-en2xqhty.js → index-57ppvpw0.js} +1 -1
- package/dist/{index-x68eyh6y.js → index-7cn66qdk.js} +2 -2
- package/dist/{index-7q05ag0z.js → index-7zksb1ty.js} +1 -1
- package/dist/{index-xaem29dc.js → index-a3z56mtn.js} +1 -1
- package/dist/{index-568w258r.js → index-a6w6mwda.js} +1 -1
- package/dist/{index-z2z67tnv.js → index-cvjddnvd.js} +3 -3
- package/dist/{index-afc3mtah.js → index-ft2wvst5.js} +101 -32
- package/dist/{index-gdqawggb.js → index-jjvr9f15.js} +14 -0
- package/dist/{index-q7s1yr9g.js → index-kxff9e9w.js} +3 -3
- package/dist/{index-r7v5xz0g.js → index-m0wsfmrc.js} +1 -1
- package/dist/{index-pq7rkwkk.js → index-m200b8hs.js} +65 -12
- package/dist/{index-2ds89z96.js → index-n6hvd1r2.js} +4 -4
- package/dist/{index-p9saezh1.js → index-pa9bhefy.js} +1 -1
- package/dist/{index-p1mwqkgh.js → index-v7rbjatr.js} +122 -113
- package/dist/{index-rk7m4j7r.js → index-x2d51zay.js} +9 -10
- package/dist/{index-1wz4y15d.js → index-x2rvpbtj.js} +1 -1
- package/dist/internal/coalesced-task.d.ts +14 -2
- package/dist/internal/coalesced-task.d.ts.map +1 -1
- package/dist/internal/upgrade-affects.d.ts.map +1 -1
- package/dist/process/group-settlement.d.ts +2 -0
- package/dist/process/group-settlement.d.ts.map +1 -1
- package/dist/server/context.d.ts +2 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/error-dispatch.d.ts +2 -0
- package/dist/server/error-dispatch.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +3 -0
- package/dist/server/handler-state.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +48 -3
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/types.d.ts +8 -2
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts +10 -1
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/command-shape.d.ts +4 -0
- package/dist/tools/cli/command-shape.d.ts.map +1 -1
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/session.d.ts +1 -1
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts +6 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/internal/surface-projector.d.ts +2 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/llms/agent-runtime.2.txt +30 -0
- package/llms/agent-runtime.4.txt +1 -1
- package/llms/application.3.txt +9 -3
- package/llms/cli.2.txt +1 -1
- package/llms/cli.txt +27 -0
- package/llms/live.txt +28 -1
- package/llms/server.3.txt +2 -1
- package/llms/server.5.txt +3 -1
- package/llms/server.txt +44 -1
- package/llms/stitchkit.txt +3 -3
- package/llms/{upgrading-0.106.0-0.124.0.txt → upgrading-0.106.0-0.126.0.txt} +65 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +210 -12
- package/llms.txt +6 -6
- package/package.json +4 -4
|
@@ -9,6 +9,13 @@ import {
|
|
|
9
9
|
readContractStreamItems,
|
|
10
10
|
contractStreamLifetimeExceeded
|
|
11
11
|
} from "./index-0v9xb8pz.js";
|
|
12
|
+
import {
|
|
13
|
+
resolveRequestCors,
|
|
14
|
+
deniedRequestCors,
|
|
15
|
+
assertCorsConfig,
|
|
16
|
+
requestCorsHeaders,
|
|
17
|
+
applyCors
|
|
18
|
+
} from "./index-m200b8hs.js";
|
|
12
19
|
import {
|
|
13
20
|
joinRoutePath,
|
|
14
21
|
parseTrailingWildcard
|
|
@@ -34,13 +41,6 @@ import {
|
|
|
34
41
|
import {
|
|
35
42
|
bindContract
|
|
36
43
|
} from "./index-tnnmekgb.js";
|
|
37
|
-
import {
|
|
38
|
-
assertCorsConfig,
|
|
39
|
-
isOriginAllowed,
|
|
40
|
-
corsPreflightResponse2,
|
|
41
|
-
requestCorsHeaders,
|
|
42
|
-
applyCors
|
|
43
|
-
} from "./index-pq7rkwkk.js";
|
|
44
44
|
import {
|
|
45
45
|
mediaTypeEssence
|
|
46
46
|
} from "./index-zs8cze4j.js";
|
|
@@ -676,12 +676,12 @@ function parseJsonBody(req, text, method, cors) {
|
|
|
676
676
|
badRequest2("Request body must be application/json");
|
|
677
677
|
}
|
|
678
678
|
const origin = req.headers.get("origin");
|
|
679
|
-
if (!cors || cors.
|
|
679
|
+
if (!cors || cors.safelistedBody === "no-allow-list") {
|
|
680
680
|
forbidden2("A text/plain body requires an explicit cors.origin allow-list on the server");
|
|
681
681
|
}
|
|
682
682
|
if (!origin)
|
|
683
683
|
forbidden2("A text/plain body requires an Origin header");
|
|
684
|
-
if (
|
|
684
|
+
if (cors.safelistedBody !== "allowed") {
|
|
685
685
|
forbidden2("A text/plain body is accepted only from an allowed origin");
|
|
686
686
|
}
|
|
687
687
|
}
|
|
@@ -1136,12 +1136,12 @@ function applyResponseMetadata(target, metadata, endpointIdentity) {
|
|
|
1136
1136
|
async function endpointResponse(state, request, outcome) {
|
|
1137
1137
|
const { method } = outcome.match;
|
|
1138
1138
|
if (method.rawResponse)
|
|
1139
|
-
return rawEndpointResponse(
|
|
1139
|
+
return rawEndpointResponse(request, outcome);
|
|
1140
1140
|
if (method.stream)
|
|
1141
|
-
return streamEndpointResponse(
|
|
1141
|
+
return streamEndpointResponse(request, outcome);
|
|
1142
1142
|
return dataEndpointResponse(state, request, outcome);
|
|
1143
1143
|
}
|
|
1144
|
-
function rawEndpointResponse(
|
|
1144
|
+
function rawEndpointResponse(request, { match: { method }, result }) {
|
|
1145
1145
|
if (!(result instanceof Response)) {
|
|
1146
1146
|
throw new AppError2("INTERNAL_SERVER_ERROR", {
|
|
1147
1147
|
message: `Raw endpoint ${method.serviceName}.${method.key} must return a Response`,
|
|
@@ -1153,11 +1153,11 @@ function rawEndpointResponse(state, request, { match: { method }, result }) {
|
|
|
1153
1153
|
statusText: result.statusText,
|
|
1154
1154
|
headers: result.headers
|
|
1155
1155
|
}) : result;
|
|
1156
|
-
const rawRes = applyCors(response,
|
|
1156
|
+
const rawRes = applyCors(response, request.cors);
|
|
1157
1157
|
request.complete(rawRes.status);
|
|
1158
1158
|
return rawRes;
|
|
1159
1159
|
}
|
|
1160
|
-
async function streamEndpointResponse(
|
|
1160
|
+
async function streamEndpointResponse(request, { match: { method, pathParams }, result, streamAbort }) {
|
|
1161
1161
|
const { req, server, clientIp } = request;
|
|
1162
1162
|
if (!method.stream || !streamAbort || !isAsyncIterable(result)) {
|
|
1163
1163
|
streamAbort?.abort();
|
|
@@ -1167,7 +1167,7 @@ async function streamEndpointResponse(state, request, { match: { method, pathPar
|
|
|
1167
1167
|
});
|
|
1168
1168
|
}
|
|
1169
1169
|
const response = await contractStreamResponse(req, { params: pathParams, server, ipAddress: clientIp.socketIp }, result, method.stream, streamAbort);
|
|
1170
|
-
const withCors = applyCors(response,
|
|
1170
|
+
const withCors = applyCors(response, request.cors);
|
|
1171
1171
|
request.complete(withCors.status);
|
|
1172
1172
|
return withCors;
|
|
1173
1173
|
}
|
|
@@ -1177,8 +1177,7 @@ async function dataEndpointResponse(state, request, {
|
|
|
1177
1177
|
result: handlerResult,
|
|
1178
1178
|
responseMetadata
|
|
1179
1179
|
}) {
|
|
1180
|
-
const { hooks, config,
|
|
1181
|
-
const { req } = request;
|
|
1180
|
+
const { hooks, config, warn } = state;
|
|
1182
1181
|
let result = handlerResult;
|
|
1183
1182
|
if (groupHooks?.afterHandle) {
|
|
1184
1183
|
const transformed = await groupHooks.afterHandle(ctx, result, method);
|
|
@@ -1210,7 +1209,7 @@ async function dataEndpointResponse(state, request, {
|
|
|
1210
1209
|
status: 500
|
|
1211
1210
|
});
|
|
1212
1211
|
}
|
|
1213
|
-
const responseHeaders = new Headers(requestCorsHeaders(cors
|
|
1212
|
+
const responseHeaders = new Headers(requestCorsHeaders(request.cors));
|
|
1214
1213
|
applyResponseMetadata(responseHeaders, responseMetadata, `${method.serviceName}.${method.key}`);
|
|
1215
1214
|
if (!method.outputSchema) {
|
|
1216
1215
|
const empty = new Response(null, { status: responseStatus, headers: responseHeaders });
|
|
@@ -1224,7 +1223,7 @@ async function dataEndpointResponse(state, request, {
|
|
|
1224
1223
|
|
|
1225
1224
|
// src/server/endpoint-dispatch.ts
|
|
1226
1225
|
async function dispatchEndpoint(state, request, match) {
|
|
1227
|
-
const { hooks, config
|
|
1226
|
+
const { hooks, config } = state;
|
|
1228
1227
|
const { req, url, traceId, clientIp } = request;
|
|
1229
1228
|
const { method, pathParams, groupHooks } = match;
|
|
1230
1229
|
const ctx = buildBaseContext(req, url, pathParams, traceId, clientIp);
|
|
@@ -1238,7 +1237,7 @@ async function dispatchEndpoint(state, request, match) {
|
|
|
1238
1237
|
if (groupHooks?.authorize) {
|
|
1239
1238
|
await groupHooks.authorize(ctx, method);
|
|
1240
1239
|
}
|
|
1241
|
-
multipartLifecycle = await parseRequestPayloadInto(ctx, req, url, method, config.maxJsonBodyBytes, cors);
|
|
1240
|
+
multipartLifecycle = await parseRequestPayloadInto(ctx, req, url, method, config.maxJsonBodyBytes, request.cors);
|
|
1242
1241
|
if (hooks?.beforeHandle) {
|
|
1243
1242
|
await hooks.beforeHandle(ctx, method);
|
|
1244
1243
|
}
|
|
@@ -1298,11 +1297,11 @@ function isClientClosedRequest(req, error) {
|
|
|
1298
1297
|
return req.signal.reason !== undefined && containsRequestAbortReason(error, req.signal.reason);
|
|
1299
1298
|
}
|
|
1300
1299
|
function createErrorResponder(state, request) {
|
|
1301
|
-
const {
|
|
1302
|
-
const { req, url, traceId, clientIp, complete } = request;
|
|
1300
|
+
const { hooks, customLogger } = state;
|
|
1301
|
+
const { req, url, traceId, clientIp, complete, cors } = request;
|
|
1303
1302
|
return async (err, errCtx, endpoint, group) => {
|
|
1304
1303
|
if (isClientClosedRequest(req, err)) {
|
|
1305
|
-
const response = applyCors(new Response(null, { status: 499, statusText: "Client Closed Request" }), cors
|
|
1304
|
+
const response = applyCors(new Response(null, { status: 499, statusText: "Client Closed Request" }), cors);
|
|
1306
1305
|
complete(response.status, undefined, "cancelled");
|
|
1307
1306
|
return response;
|
|
1308
1307
|
}
|
|
@@ -1326,7 +1325,7 @@ function createErrorResponder(state, request) {
|
|
|
1326
1325
|
logger: customLogger,
|
|
1327
1326
|
respond: (response) => {
|
|
1328
1327
|
recordFailure();
|
|
1329
|
-
const withCors = applyCors(response, cors
|
|
1328
|
+
const withCors = applyCors(response, cors);
|
|
1330
1329
|
complete(withCors.status, errorCode2(err));
|
|
1331
1330
|
return withCors;
|
|
1332
1331
|
}
|
|
@@ -1338,7 +1337,7 @@ function createErrorResponder(state, request) {
|
|
|
1338
1337
|
complete(appErr.status, appErr.code);
|
|
1339
1338
|
return Response.json(appErr.toJSON(), {
|
|
1340
1339
|
status: appErr.status,
|
|
1341
|
-
headers: requestCorsHeaders(cors
|
|
1340
|
+
headers: requestCorsHeaders(cors)
|
|
1342
1341
|
});
|
|
1343
1342
|
};
|
|
1344
1343
|
}
|
|
@@ -2045,10 +2044,33 @@ function createHandler2(config) {
|
|
|
2045
2044
|
};
|
|
2046
2045
|
}
|
|
2047
2046
|
async function dispatch(state, req, url, traceId, server, clientIp, startedAt) {
|
|
2048
|
-
const {
|
|
2047
|
+
const { hooks, config, routeMap } = state;
|
|
2049
2048
|
const ipAddress = extractIp2(req, clientIp) || undefined;
|
|
2050
2049
|
const complete = openRequestCompletion(state, { req, url, traceId, startedAt, ipAddress });
|
|
2051
|
-
|
|
2050
|
+
let cors;
|
|
2051
|
+
let corsFailed = false;
|
|
2052
|
+
let corsFailure;
|
|
2053
|
+
if (state.cors) {
|
|
2054
|
+
try {
|
|
2055
|
+
const decided = resolveRequestCors(state.cors, req.headers.get("origin"));
|
|
2056
|
+
cors = decided instanceof Promise ? await decided : decided;
|
|
2057
|
+
} catch (error) {
|
|
2058
|
+
corsFailed = true;
|
|
2059
|
+
corsFailure = error;
|
|
2060
|
+
cors = deniedRequestCors(state.cors);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
const respondError = createErrorResponder(state, {
|
|
2064
|
+
req,
|
|
2065
|
+
url,
|
|
2066
|
+
traceId,
|
|
2067
|
+
clientIp,
|
|
2068
|
+
complete,
|
|
2069
|
+
cors
|
|
2070
|
+
});
|
|
2071
|
+
if (corsFailed) {
|
|
2072
|
+
return respondError(new Error("The CORS origin resolver failed", { cause: corsFailure }));
|
|
2073
|
+
}
|
|
2052
2074
|
const request = {
|
|
2053
2075
|
req,
|
|
2054
2076
|
url,
|
|
@@ -2057,10 +2079,11 @@ async function dispatch(state, req, url, traceId, server, clientIp, startedAt) {
|
|
|
2057
2079
|
clientIp,
|
|
2058
2080
|
ipAddress,
|
|
2059
2081
|
complete,
|
|
2060
|
-
respondError
|
|
2082
|
+
respondError,
|
|
2083
|
+
cors
|
|
2061
2084
|
};
|
|
2062
2085
|
if (cors && req.method === "OPTIONS") {
|
|
2063
|
-
const response =
|
|
2086
|
+
const response = new Response(null, { status: 204, headers: cors.headers });
|
|
2064
2087
|
complete(response.status);
|
|
2065
2088
|
return response;
|
|
2066
2089
|
}
|
|
@@ -2068,7 +2091,7 @@ async function dispatch(state, req, url, traceId, server, clientIp, startedAt) {
|
|
|
2068
2091
|
if (hooks?.onRequest) {
|
|
2069
2092
|
const earlyResponse = await hooks.onRequest(req);
|
|
2070
2093
|
if (earlyResponse instanceof Response) {
|
|
2071
|
-
const withCors = applyCors(earlyResponse, cors
|
|
2094
|
+
const withCors = applyCors(earlyResponse, cors);
|
|
2072
2095
|
complete(withCors.status);
|
|
2073
2096
|
return withCors;
|
|
2074
2097
|
}
|
|
@@ -2088,7 +2111,7 @@ async function dispatch(state, req, url, traceId, server, clientIp, startedAt) {
|
|
|
2088
2111
|
server,
|
|
2089
2112
|
ipAddress
|
|
2090
2113
|
});
|
|
2091
|
-
const withCors = applyCors(res, cors
|
|
2114
|
+
const withCors = applyCors(res, cors);
|
|
2092
2115
|
complete(withCors.status);
|
|
2093
2116
|
return withCors;
|
|
2094
2117
|
} catch (err) {
|
|
@@ -8,17 +8,17 @@ import {
|
|
|
8
8
|
validateResolvedInputRounds,
|
|
9
9
|
presentationMetadata,
|
|
10
10
|
prepareProjectedMcpTools
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-x2d51zay.js";
|
|
12
12
|
import {
|
|
13
13
|
parseToolCallArguments,
|
|
14
14
|
toolResultFromError,
|
|
15
15
|
observed
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-x2rvpbtj.js";
|
|
17
17
|
import {
|
|
18
18
|
collectTools2,
|
|
19
19
|
createToolRunner,
|
|
20
20
|
formatToolError
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-7cn66qdk.js";
|
|
22
22
|
import {
|
|
23
23
|
publishedToolAnnotations
|
|
24
24
|
} from "./index-332d0m9g.js";
|
|
@@ -37,10 +37,10 @@ import {
|
|
|
37
37
|
wwwAuthenticateHeader2,
|
|
38
38
|
mcpProgressToken,
|
|
39
39
|
createMcpProgressReporter
|
|
40
|
-
} from "./index-
|
|
40
|
+
} from "./index-a6w6mwda.js";
|
|
41
41
|
import {
|
|
42
42
|
collectToolSurface
|
|
43
|
-
} from "./index-
|
|
43
|
+
} from "./index-kxff9e9w.js";
|
|
44
44
|
import {
|
|
45
45
|
runWithRequestContext2,
|
|
46
46
|
getRequestContext2
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
CommandStopped,
|
|
6
6
|
startNativeCommand
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-jjvr9f15.js";
|
|
8
8
|
import {
|
|
9
9
|
ScanStopped,
|
|
10
10
|
ContainedScanBudget,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
} from "./index-ww3gss55.js";
|
|
31
31
|
import {
|
|
32
32
|
defineRuntimeTool2
|
|
33
|
-
} from "./index-
|
|
33
|
+
} from "./index-m0wsfmrc.js";
|
|
34
34
|
import {
|
|
35
35
|
errnoOf
|
|
36
36
|
} from "./index-jj9228tt.js";
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
mergeSchemas,
|
|
4
4
|
assertToolExtensionCompatible,
|
|
5
5
|
projectToolSurface
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-x2d51zay.js";
|
|
7
7
|
import {
|
|
8
8
|
toolErrorFromResult,
|
|
9
9
|
executeToolMethod
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-x2rvpbtj.js";
|
|
11
11
|
import {
|
|
12
12
|
isRetryableStatus2
|
|
13
13
|
} from "./index-0w0hxp7n.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertUniqueToolName
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-x2d51zay.js";
|
|
4
4
|
import {
|
|
5
5
|
toolErrorFromResult
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-x2rvpbtj.js";
|
|
7
7
|
import {
|
|
8
8
|
collectTools2,
|
|
9
9
|
createToolRunner
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-7cn66qdk.js";
|
|
11
11
|
import {
|
|
12
12
|
AppError2
|
|
13
13
|
} from "./index-0w0hxp7n.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
AgentSandboxRestrictionSchema2,
|
|
5
5
|
AgentSandboxGradeSchema2,
|
|
6
6
|
AGENT_CODING_TOOL_NAMES
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-4efxzrht.js";
|
|
8
8
|
import {
|
|
9
9
|
AgentRecordIdSchema2,
|
|
10
10
|
AgentRecordVersionSchema2,
|
|
@@ -56,6 +56,20 @@ import {
|
|
|
56
56
|
// src/agent-runtime/branch-contract.ts
|
|
57
57
|
import { z } from "zod";
|
|
58
58
|
var Hash = z.string().regex(/^[a-f0-9]{64}$/);
|
|
59
|
+
var BranchApplicationFileSchema = z.object({
|
|
60
|
+
reference: z.string().min(1),
|
|
61
|
+
destinationReference: z.string().min(1)
|
|
62
|
+
}).strict();
|
|
63
|
+
var BranchApplicationFilesSchema = z.array(BranchApplicationFileSchema).superRefine((files, ctx) => {
|
|
64
|
+
for (const field of ["reference", "destinationReference"]) {
|
|
65
|
+
const values = files.map((file) => file[field]);
|
|
66
|
+
if (new Set(values).size !== values.length)
|
|
67
|
+
ctx.addIssue({
|
|
68
|
+
code: "custom",
|
|
69
|
+
message: `Branch application files repeat a ${field}`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
59
73
|
var BranchAgentConversationInputSchema2 = z.object({
|
|
60
74
|
requestKey: AgentRecordIdSchema2,
|
|
61
75
|
destinationConversationId: AgentRecordIdSchema2,
|
|
@@ -70,7 +84,9 @@ var BranchAgentConversationInputSchema2 = z.object({
|
|
|
70
84
|
bytes: z.custom((value) => value instanceof Uint8Array)
|
|
71
85
|
}).strict()
|
|
72
86
|
]),
|
|
73
|
-
artifactAuthorization: AgentCodingToolAuthorizationSchema2.optional()
|
|
87
|
+
artifactAuthorization: AgentCodingToolAuthorizationSchema2.optional(),
|
|
88
|
+
applicationFiles: BranchApplicationFilesSchema.optional(),
|
|
89
|
+
applicationKeys: z.array(z.string().min(1)).optional()
|
|
74
90
|
}).strict();
|
|
75
91
|
var AgentConversationBranchReceiptSchema2 = z.object({
|
|
76
92
|
schemaVersion: z.literal(1),
|
|
@@ -979,9 +995,9 @@ import { z as z8 } from "zod";
|
|
|
979
995
|
|
|
980
996
|
// src/agent-runtime/branch-messages.ts
|
|
981
997
|
import { z as z5 } from "zod";
|
|
982
|
-
function branchOpaqueJson(value) {
|
|
998
|
+
function branchOpaqueJson(ids, value) {
|
|
983
999
|
if (Array.isArray(value))
|
|
984
|
-
return value.map(branchOpaqueJson);
|
|
1000
|
+
return value.map((entry) => branchOpaqueJson(ids, entry));
|
|
985
1001
|
if (value !== null && typeof value === "object") {
|
|
986
1002
|
for (const key of [
|
|
987
1003
|
"reference",
|
|
@@ -994,11 +1010,16 @@ function branchOpaqueJson(value) {
|
|
|
994
1010
|
"operationId",
|
|
995
1011
|
"artifactId"
|
|
996
1012
|
]) {
|
|
997
|
-
if (key in value)
|
|
998
|
-
|
|
1013
|
+
if (!(key in value))
|
|
1014
|
+
continue;
|
|
1015
|
+
const entry = value[key];
|
|
1016
|
+
if (!ids.isApplicationKey(key))
|
|
1017
|
+
throw new TypeError(`Branch cannot rekey an opaque payload containing ${key}; declare it in applicationKeys if it is application data`);
|
|
1018
|
+
if (typeof entry === "string" && ids.isSourceIdentity(entry))
|
|
1019
|
+
throw new TypeError(`Branch cannot carry a source identity under the application key ${key}`);
|
|
999
1020
|
}
|
|
1000
1021
|
for (const entry of Object.values(value))
|
|
1001
|
-
branchOpaqueJson(entry);
|
|
1022
|
+
branchOpaqueJson(ids, entry);
|
|
1002
1023
|
}
|
|
1003
1024
|
return value;
|
|
1004
1025
|
}
|
|
@@ -1040,15 +1061,15 @@ function branchToolJson(ids, name, value, output) {
|
|
|
1040
1061
|
}
|
|
1041
1062
|
};
|
|
1042
1063
|
}
|
|
1043
|
-
return branchOpaqueJson(value);
|
|
1064
|
+
return branchOpaqueJson(ids, value);
|
|
1044
1065
|
}
|
|
1045
1066
|
function branchPart(ids, part) {
|
|
1046
1067
|
switch (part.type) {
|
|
1047
1068
|
case "file":
|
|
1048
|
-
return { ...part, reference: ids.
|
|
1069
|
+
return { ...part, reference: ids.fileReference(part.reference) };
|
|
1049
1070
|
case "tool-call": {
|
|
1050
1071
|
if (part.provider)
|
|
1051
|
-
branchOpaqueJson(part.provider.data);
|
|
1072
|
+
branchOpaqueJson(ids, part.provider.data);
|
|
1052
1073
|
return {
|
|
1053
1074
|
...part,
|
|
1054
1075
|
callId: ids.reference("call", part.callId),
|
|
@@ -1060,7 +1081,7 @@ function branchPart(ids, part) {
|
|
|
1060
1081
|
...part,
|
|
1061
1082
|
callId: ids.reference("call", part.callId),
|
|
1062
1083
|
...part.output !== undefined && {
|
|
1063
|
-
output: part.outcome === "success" ? branchToolJson(ids, part.toolName, part.output, true) : branchOpaqueJson(part.output)
|
|
1084
|
+
output: part.outcome === "success" ? branchToolJson(ids, part.toolName, part.output, true) : branchOpaqueJson(ids, part.output)
|
|
1064
1085
|
}
|
|
1065
1086
|
};
|
|
1066
1087
|
case "tool-approval-request":
|
|
@@ -1075,7 +1096,7 @@ function branchPart(ids, part) {
|
|
|
1075
1096
|
throw new TypeError("Branch cannot rekey an opaque provider part");
|
|
1076
1097
|
case "reasoning":
|
|
1077
1098
|
if (part.provider)
|
|
1078
|
-
branchOpaqueJson(part.provider.data);
|
|
1099
|
+
branchOpaqueJson(ids, part.provider.data);
|
|
1079
1100
|
return part;
|
|
1080
1101
|
default:
|
|
1081
1102
|
return part;
|
|
@@ -1091,7 +1112,7 @@ function branchMessage(ids, sourceConversationId, message) {
|
|
|
1091
1112
|
...message.runId && { runId: ids.reference("run", message.runId) },
|
|
1092
1113
|
parts: message.parts.map((part) => branchPart(ids, part)),
|
|
1093
1114
|
...message.metadata && {
|
|
1094
|
-
metadata: z5.record(z5.string(), z5.json()).parse(branchOpaqueJson(message.metadata))
|
|
1115
|
+
metadata: z5.record(z5.string(), z5.json()).parse(branchOpaqueJson(ids, message.metadata))
|
|
1095
1116
|
}
|
|
1096
1117
|
};
|
|
1097
1118
|
}
|
|
@@ -1174,7 +1195,7 @@ function branchObservation(ids, kind, raw) {
|
|
|
1174
1195
|
if (!value || canonicalAgentJson2(value) !== canonicalAgentJson2(raw))
|
|
1175
1196
|
throw new TypeError("Branch cannot rekey opaque durability payload");
|
|
1176
1197
|
if ("encoded" in value)
|
|
1177
|
-
branchOpaqueJson(z6.json().parse(JSON.parse(value.encoded)));
|
|
1198
|
+
branchOpaqueJson(ids, z6.json().parse(JSON.parse(value.encoded)));
|
|
1178
1199
|
return {
|
|
1179
1200
|
...value,
|
|
1180
1201
|
runId: ids.reference("run", value.runId),
|
|
@@ -1189,7 +1210,7 @@ function branchObservation(ids, kind, raw) {
|
|
|
1189
1210
|
}).strict().parse(raw);
|
|
1190
1211
|
if (kind === "state/set") {
|
|
1191
1212
|
const value = State.parse(raw);
|
|
1192
|
-
branchOpaqueJson(value.value);
|
|
1213
|
+
branchOpaqueJson(ids, value.value);
|
|
1193
1214
|
return value;
|
|
1194
1215
|
}
|
|
1195
1216
|
if (kind === "retry/scheduled" || kind === "retry/started")
|
|
@@ -1205,9 +1226,9 @@ function branchObservation(ids, kind, raw) {
|
|
|
1205
1226
|
if (kind.startsWith("child/")) {
|
|
1206
1227
|
const value = Child.parse(raw);
|
|
1207
1228
|
if (value.budget)
|
|
1208
|
-
branchOpaqueJson(value.budget);
|
|
1229
|
+
branchOpaqueJson(ids, value.budget);
|
|
1209
1230
|
if (value.input)
|
|
1210
|
-
branchOpaqueJson(value.input);
|
|
1231
|
+
branchOpaqueJson(ids, value.input);
|
|
1211
1232
|
return {
|
|
1212
1233
|
...value,
|
|
1213
1234
|
...value.childConversationId && {
|
|
@@ -1244,13 +1265,13 @@ import { createHash as createHash3 } from "node:crypto";
|
|
|
1244
1265
|
function hash(value) {
|
|
1245
1266
|
return createHash3("sha256").update(canonicalAgentJson2(value)).digest("hex");
|
|
1246
1267
|
}
|
|
1247
|
-
function checkFileData(value) {
|
|
1268
|
+
function checkFileData(ids, value) {
|
|
1248
1269
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
1249
1270
|
return;
|
|
1250
1271
|
if (value.type === "reference" && "reference" in value)
|
|
1251
|
-
branchOpaqueJson(value.reference);
|
|
1272
|
+
branchOpaqueJson(ids, value.reference);
|
|
1252
1273
|
else if (!("type" in value) && value.binary !== true)
|
|
1253
|
-
branchOpaqueJson(value);
|
|
1274
|
+
branchOpaqueJson(ids, value);
|
|
1254
1275
|
}
|
|
1255
1276
|
|
|
1256
1277
|
class BranchProvider {
|
|
@@ -1265,16 +1286,16 @@ class BranchProvider {
|
|
|
1265
1286
|
if (hash(value.message) !== value.sha256)
|
|
1266
1287
|
throw new TypeError("Branch provider message digest is inconsistent");
|
|
1267
1288
|
if (value.message.providerOptions)
|
|
1268
|
-
branchOpaqueJson(value.message.providerOptions);
|
|
1289
|
+
branchOpaqueJson(this.ids, value.message.providerOptions);
|
|
1269
1290
|
const message = {
|
|
1270
1291
|
...value.message,
|
|
1271
1292
|
content: typeof value.message.content === "string" ? value.message.content : value.message.content.map((part) => {
|
|
1272
1293
|
if ("providerOptions" in part && part.providerOptions)
|
|
1273
|
-
branchOpaqueJson(part.providerOptions);
|
|
1294
|
+
branchOpaqueJson(this.ids, part.providerOptions);
|
|
1274
1295
|
if (part.type === "file" || part.type === "reasoning-file")
|
|
1275
|
-
checkFileData(part.data);
|
|
1296
|
+
checkFileData(this.ids, part.data);
|
|
1276
1297
|
if (part.type === "image")
|
|
1277
|
-
checkFileData(part.image);
|
|
1298
|
+
checkFileData(this.ids, part.image);
|
|
1278
1299
|
if (part.type === "tool-call")
|
|
1279
1300
|
return {
|
|
1280
1301
|
...part,
|
|
@@ -1283,19 +1304,19 @@ class BranchProvider {
|
|
|
1283
1304
|
};
|
|
1284
1305
|
if (part.type === "tool-result") {
|
|
1285
1306
|
if ("providerOptions" in part.output && part.output.providerOptions)
|
|
1286
|
-
branchOpaqueJson(part.output.providerOptions);
|
|
1307
|
+
branchOpaqueJson(this.ids, part.output.providerOptions);
|
|
1287
1308
|
if (part.output.type === "error-json")
|
|
1288
|
-
branchOpaqueJson(part.output.value);
|
|
1309
|
+
branchOpaqueJson(this.ids, part.output.value);
|
|
1289
1310
|
if (part.output.type === "content")
|
|
1290
1311
|
for (const item of part.output.value) {
|
|
1291
1312
|
if (item.providerOptions)
|
|
1292
|
-
branchOpaqueJson(item.providerOptions);
|
|
1313
|
+
branchOpaqueJson(this.ids, item.providerOptions);
|
|
1293
1314
|
if (item.type === "file")
|
|
1294
|
-
checkFileData(item.data);
|
|
1315
|
+
checkFileData(this.ids, item.data);
|
|
1295
1316
|
if ("providerReference" in item)
|
|
1296
|
-
branchOpaqueJson(item.providerReference);
|
|
1317
|
+
branchOpaqueJson(this.ids, item.providerReference);
|
|
1297
1318
|
if ("fileId" in item && typeof item.fileId !== "string")
|
|
1298
|
-
branchOpaqueJson(item.fileId);
|
|
1319
|
+
branchOpaqueJson(this.ids, item.fileId);
|
|
1299
1320
|
}
|
|
1300
1321
|
return {
|
|
1301
1322
|
...part,
|
|
@@ -1567,6 +1588,8 @@ class BranchIdentities {
|
|
|
1567
1588
|
sourceConversationId;
|
|
1568
1589
|
definitions = new Map;
|
|
1569
1590
|
references = new Map;
|
|
1591
|
+
applicationFiles = new Map;
|
|
1592
|
+
applicationKeys = new Set;
|
|
1570
1593
|
constructor(conversationId, requestKey, sourceConversationId) {
|
|
1571
1594
|
this.conversationId = conversationId;
|
|
1572
1595
|
this.requestKey = requestKey;
|
|
@@ -1588,6 +1611,36 @@ class BranchIdentities {
|
|
|
1588
1611
|
this.references.set(kind, referenced);
|
|
1589
1612
|
return target;
|
|
1590
1613
|
}
|
|
1614
|
+
declareApplicationFiles(files) {
|
|
1615
|
+
for (const file of files) {
|
|
1616
|
+
if (this.definitions.get("spill")?.has(file.reference))
|
|
1617
|
+
throw new TypeError("Branch application file reference is also a spill reference");
|
|
1618
|
+
this.applicationFiles.set(file.reference, file.destinationReference);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
declareApplicationKeys(keys) {
|
|
1622
|
+
for (const key of keys)
|
|
1623
|
+
this.applicationKeys.add(key);
|
|
1624
|
+
}
|
|
1625
|
+
isApplicationKey(key) {
|
|
1626
|
+
return this.applicationKeys.has(key);
|
|
1627
|
+
}
|
|
1628
|
+
isSourceIdentity(value) {
|
|
1629
|
+
if (value === this.sourceConversationId)
|
|
1630
|
+
return true;
|
|
1631
|
+
for (const values of this.definitions.values())
|
|
1632
|
+
if (values.has(value))
|
|
1633
|
+
return true;
|
|
1634
|
+
return false;
|
|
1635
|
+
}
|
|
1636
|
+
fileReference(source) {
|
|
1637
|
+
if (this.definitions.get("spill")?.has(source))
|
|
1638
|
+
return this.reference("spill", source);
|
|
1639
|
+
const target = this.applicationFiles.get(source);
|
|
1640
|
+
if (target === undefined)
|
|
1641
|
+
throw new TypeError("Branch contains a foreign or missing file reference");
|
|
1642
|
+
return target;
|
|
1643
|
+
}
|
|
1591
1644
|
referenced(kind) {
|
|
1592
1645
|
return this.references.get(kind) ?? new Set;
|
|
1593
1646
|
}
|
|
@@ -1707,7 +1760,11 @@ function boundary(events, throughRunId) {
|
|
|
1707
1760
|
}
|
|
1708
1761
|
throw new TypeError("Branch boundary run has no exact settled event");
|
|
1709
1762
|
}
|
|
1710
|
-
function prepareBranchSource(bytes,
|
|
1763
|
+
function prepareBranchSource(bytes, {
|
|
1764
|
+
source,
|
|
1765
|
+
applicationFiles = [],
|
|
1766
|
+
applicationKeys = []
|
|
1767
|
+
}) {
|
|
1711
1768
|
const archive = decodeAgentConversationArchive2(bytes);
|
|
1712
1769
|
if (source.kind === "conversation" && source.conversationId !== archive.conversationId)
|
|
1713
1770
|
throw new TypeError("Branch source identity changed");
|
|
@@ -1739,6 +1796,8 @@ function prepareBranchSource(bytes, source) {
|
|
|
1739
1796
|
const validationIds = new BranchIdentities("branch-validation", "branch-validation", archive.conversationId);
|
|
1740
1797
|
for (const spill of allSpills)
|
|
1741
1798
|
validationIds.define("spill", spill.reference);
|
|
1799
|
+
validationIds.declareApplicationFiles(applicationFiles);
|
|
1800
|
+
validationIds.declareApplicationKeys(applicationKeys);
|
|
1742
1801
|
rekeyBranchEvents(validationIds, archive.conversationId, archive.events, full.retainedMessages);
|
|
1743
1802
|
for (const spill of allSpills) {
|
|
1744
1803
|
if (spill.runId)
|
|
@@ -1758,6 +1817,8 @@ function prepareBranchSource(bytes, source) {
|
|
|
1758
1817
|
const selectedIds = new BranchIdentities("branch-validation", "branch-validation", archive.conversationId);
|
|
1759
1818
|
for (const spill of allSpills)
|
|
1760
1819
|
selectedIds.define("spill", spill.reference);
|
|
1820
|
+
selectedIds.declareApplicationFiles(applicationFiles);
|
|
1821
|
+
selectedIds.declareApplicationKeys(applicationKeys);
|
|
1761
1822
|
rekeyBranchEvents(selectedIds, archive.conversationId, events, replay.retainedMessages);
|
|
1762
1823
|
const references = selectedIds.referenced("spill");
|
|
1763
1824
|
const spills = allSpills.filter((spill) => references.has(spill.reference));
|
|
@@ -1796,6 +1857,12 @@ async function branchConversation(driver, raw) {
|
|
|
1796
1857
|
};
|
|
1797
1858
|
const fingerprint = branchHash({
|
|
1798
1859
|
...input,
|
|
1860
|
+
...input.applicationFiles && {
|
|
1861
|
+
applicationFiles: input.applicationFiles.toSorted((left, right) => left.reference.localeCompare(right.reference))
|
|
1862
|
+
},
|
|
1863
|
+
...input.applicationKeys && {
|
|
1864
|
+
applicationKeys: [...new Set(input.applicationKeys)].sort()
|
|
1865
|
+
},
|
|
1799
1866
|
source: input.source.kind === "archive" ? {
|
|
1800
1867
|
kind: "archive",
|
|
1801
1868
|
digest: createHash7("sha256").update(input.source.bytes).digest("hex")
|
|
@@ -1819,7 +1886,7 @@ async function branchConversation(driver, raw) {
|
|
|
1819
1886
|
if (input.source.kind === "conversation" && !await driver.head.load(tx, input.source.conversationId) && (await driver.events.list(tx, { conversationId: input.source.conversationId, limit: 1 })).items.length === 0)
|
|
1820
1887
|
throw new TypeError("Branch source conversation was not found");
|
|
1821
1888
|
const bytes = input.source.kind === "archive" ? input.source.bytes : await exportConversationIn(driver, tx, input.source.conversationId);
|
|
1822
|
-
const source = prepareBranchSource(bytes, input
|
|
1889
|
+
const source = prepareBranchSource(bytes, input);
|
|
1823
1890
|
if (source.conversationId === input.destinationConversationId)
|
|
1824
1891
|
throw new TypeError("Branch requires a new conversation identity");
|
|
1825
1892
|
if (source.spills.length > 0 && (!input.artifactAuthorization || !driver.archive))
|
|
@@ -1827,6 +1894,8 @@ async function branchConversation(driver, raw) {
|
|
|
1827
1894
|
const ids = new BranchIdentities(input.destinationConversationId, input.requestKey, source.conversationId);
|
|
1828
1895
|
for (const spill of source.spills)
|
|
1829
1896
|
ids.define("spill", spill.reference);
|
|
1897
|
+
ids.declareApplicationFiles(input.applicationFiles ?? []);
|
|
1898
|
+
ids.declareApplicationKeys(input.applicationKeys ?? []);
|
|
1830
1899
|
const events = rekeyBranchEvents(ids, source.conversationId, source.events, source.replay.retainedMessages);
|
|
1831
1900
|
const replay = replayBranchEvents(input.destinationConversationId, events);
|
|
1832
1901
|
if (replay.baseline?.compacted?.length && !driver.history.restore)
|