stitchkit 0.121.0 → 0.122.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/dist/agent-runtime/browser-control-contract.d.ts +12 -0
- package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -1
- package/dist/agent-runtime/control-schema.d.ts +27 -4
- package/dist/agent-runtime/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/event-schema.d.ts +33 -0
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution-state.d.ts +6 -0
- package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
- package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
- package/dist/agent-runtime/run-stream-parts.d.ts +11 -0
- package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/tool-progress.d.ts +21 -0
- package/dist/agent-runtime/tool-progress.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/browser.js +7 -3
- package/dist/entrypoints/agent-runtime/harness.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +5 -5
- package/dist/entrypoints/agent-runtime.d.ts +1 -1
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +6 -4
- package/dist/entrypoints/cli.js +2 -1
- package/dist/entrypoints/server.d.ts +1 -0
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +107 -42
- package/dist/entrypoints/tools/agent.js +1 -1
- package/dist/entrypoints/tools/connections.js +7 -1
- package/dist/entrypoints/tools/mcp.js +2 -1
- package/dist/entrypoints/tools/toolkit.js +4 -3
- package/dist/{index-7zwtbak8.js → index-1fyea34p.js} +9 -4
- package/dist/index-332d0m9g.js +37 -0
- package/dist/{index-4qnzda76.js → index-7qyv50r4.js} +1 -1
- package/dist/{index-qctbzmg9.js → index-am1h8c9v.js} +69 -27
- package/dist/{index-0fra8xvy.js → index-aswegq1r.js} +18 -6
- package/dist/{index-yt7gyg5x.js → index-b51tzcgh.js} +1 -1
- package/dist/{index-aw6zahv1.js → index-dqpesdck.js} +2 -2
- package/dist/{index-sb9dr3tq.js → index-eh71zr32.js} +4 -4
- package/dist/{index-mnkk1ffz.js → index-hs76yzt7.js} +13 -1
- package/dist/{index-b0w7rbpt.js → index-t05a2ry4.js} +39 -3
- package/dist/{index-knmnj11j.js → index-y6ye582c.js} +7 -5
- package/dist/server/openapi-security.d.ts +73 -0
- package/dist/server/openapi-security.d.ts.map +1 -0
- package/dist/server/openapi.d.ts +12 -0
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts +11 -2
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-native.d.ts.map +1 -1
- package/dist/tools/connections/mcp.d.ts.map +1 -1
- package/dist/tools/mcp/catalog.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +1 -2
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/read-operation.d.ts +21 -0
- package/dist/tools/read-operation.d.ts.map +1 -0
- package/dist/tools/runtime-call-context.d.ts +15 -0
- package/dist/tools/runtime-call-context.d.ts.map +1 -0
- package/llms/agent-runtime-browser.txt +4 -1
- package/llms/agent-runtime.2.txt +13 -108
- package/llms/agent-runtime.3.txt +111 -1
- package/llms/cli.txt +30 -9
- package/llms/server.2.txt +48 -0
- package/llms/server.5.txt +2 -0
- package/llms/stitchkit.txt +3 -3
- package/llms/tools.2.txt +109 -0
- package/llms/tools.txt +34 -110
- package/llms/{upgrading-0.106.0-0.121.0.txt → upgrading-0.106.0-0.122.0.txt} +31 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +165 -15
- package/llms.txt +6 -6
- package/package.json +2 -1
- package/dist/tools/durability-context.d.ts +0 -7
- package/dist/tools/durability-context.d.ts.map +0 -1
|
@@ -1449,6 +1449,66 @@ function createTrustFence(config) {
|
|
|
1449
1449
|
check
|
|
1450
1450
|
};
|
|
1451
1451
|
}
|
|
1452
|
+
// src/server/openapi-security.ts
|
|
1453
|
+
import { z as z2 } from "zod";
|
|
1454
|
+
var SchemeNameSchema = z2.string().regex(/^[a-zA-Z0-9._-]+$/, 'a scheme name may hold only letters, digits, ".", "_" and "-"');
|
|
1455
|
+
var described = { description: z2.string().min(1).optional() };
|
|
1456
|
+
var OpenApiSecuritySchemeSchema = z2.union([
|
|
1457
|
+
z2.strictObject({
|
|
1458
|
+
type: z2.literal("http"),
|
|
1459
|
+
scheme: z2.literal("bearer"),
|
|
1460
|
+
bearerFormat: z2.string().min(1).optional(),
|
|
1461
|
+
...described
|
|
1462
|
+
}),
|
|
1463
|
+
z2.strictObject({ type: z2.literal("http"), scheme: z2.literal("basic"), ...described }),
|
|
1464
|
+
z2.strictObject({
|
|
1465
|
+
type: z2.literal("apiKey"),
|
|
1466
|
+
in: z2.enum(["header", "query", "cookie"]),
|
|
1467
|
+
name: z2.string().min(1),
|
|
1468
|
+
...described
|
|
1469
|
+
})
|
|
1470
|
+
]);
|
|
1471
|
+
var OpenApiSecuritySchema = z2.strictObject({
|
|
1472
|
+
schemes: z2.record(SchemeNameSchema, OpenApiSecuritySchemeSchema),
|
|
1473
|
+
scopes: z2.record(z2.string().min(1), z2.array(SchemeNameSchema).readonly()),
|
|
1474
|
+
defaultScope: z2.string().min(1).optional()
|
|
1475
|
+
});
|
|
1476
|
+
var PUBLIC_SCOPE = "public";
|
|
1477
|
+
function refuse(message) {
|
|
1478
|
+
throw new Error(`[stitchkit] openapi: ${message}`);
|
|
1479
|
+
}
|
|
1480
|
+
function planOpenApiSecurity(input) {
|
|
1481
|
+
const parsed = OpenApiSecuritySchema.safeParse(input);
|
|
1482
|
+
if (!parsed.success) {
|
|
1483
|
+
const issue = parsed.error.issues[0];
|
|
1484
|
+
refuse(`security.${issue?.path.join(".") ?? ""}: ${issue?.message ?? "invalid"}`);
|
|
1485
|
+
}
|
|
1486
|
+
const { schemes, scopes, defaultScope } = parsed.data;
|
|
1487
|
+
if (Object.hasOwn(scopes, PUBLIC_SCOPE)) {
|
|
1488
|
+
refuse(`security.scopes lists "${PUBLIC_SCOPE}", which is open by definition — remove it, or give the protected endpoints their own scope`);
|
|
1489
|
+
}
|
|
1490
|
+
for (const [scope, names] of Object.entries(scopes)) {
|
|
1491
|
+
for (const name of names) {
|
|
1492
|
+
if (!Object.hasOwn(schemes, name)) {
|
|
1493
|
+
refuse(`security.scopes.${scope} names the scheme "${name}", which security.schemes does not declare`);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
schemes,
|
|
1499
|
+
requirement(scope, operation) {
|
|
1500
|
+
const effective = scope ?? defaultScope;
|
|
1501
|
+
if (effective === undefined || effective === PUBLIC_SCOPE)
|
|
1502
|
+
return;
|
|
1503
|
+
const names = Object.hasOwn(scopes, effective) ? scopes[effective] : undefined;
|
|
1504
|
+
if (names === undefined) {
|
|
1505
|
+
refuse(`${operation} has scope "${effective}", but security.scopes names no scheme for it — a protected operation cannot be advertised as open`);
|
|
1506
|
+
}
|
|
1507
|
+
return names.length === 0 ? undefined : names.map((name) => ({ [name]: [] }));
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1452
1512
|
// src/server/openapi.ts
|
|
1453
1513
|
var ERROR_ENVELOPE_SCHEMA = {
|
|
1454
1514
|
type: "object",
|
|
@@ -1484,18 +1544,56 @@ function errorResponse(description) {
|
|
|
1484
1544
|
content: { "application/json": { schema: ERROR_ENVELOPE_SCHEMA } }
|
|
1485
1545
|
};
|
|
1486
1546
|
}
|
|
1487
|
-
function errorResponses(
|
|
1547
|
+
function errorResponses(guarded) {
|
|
1488
1548
|
const responses = {
|
|
1489
1549
|
"400": errorResponse("Validation error"),
|
|
1490
1550
|
"500": errorResponse("Server error")
|
|
1491
1551
|
};
|
|
1492
|
-
if (
|
|
1552
|
+
if (guarded) {
|
|
1493
1553
|
responses["401"] = errorResponse("Unauthorized");
|
|
1494
1554
|
responses["403"] = errorResponse("Forbidden");
|
|
1495
1555
|
}
|
|
1496
1556
|
return responses;
|
|
1497
1557
|
}
|
|
1558
|
+
function multipartRequestBody(inputSchema, multipart) {
|
|
1559
|
+
const inputJson = safeJson(inputSchema, "input");
|
|
1560
|
+
const baseProps = isRecord(inputJson.properties) ? inputJson.properties : {};
|
|
1561
|
+
const baseRequired = Array.isArray(inputJson.required) ? inputJson.required : [];
|
|
1562
|
+
const fileProperties = {};
|
|
1563
|
+
const requiredFiles = [];
|
|
1564
|
+
for (const [field, policy] of Object.entries(multipart.files)) {
|
|
1565
|
+
const binary = {
|
|
1566
|
+
type: "string",
|
|
1567
|
+
format: "binary",
|
|
1568
|
+
...policy.maxBytes !== undefined && { maxLength: policy.maxBytes },
|
|
1569
|
+
...policy.contentTypes !== undefined && {
|
|
1570
|
+
"x-accepted-content-types": policy.contentTypes
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
fileProperties[field] = policy.multiple === true ? {
|
|
1574
|
+
type: "array",
|
|
1575
|
+
items: binary,
|
|
1576
|
+
minItems: policy.required === false ? 0 : 1,
|
|
1577
|
+
...policy.maxFiles !== undefined && { maxItems: policy.maxFiles }
|
|
1578
|
+
} : binary;
|
|
1579
|
+
if (policy.required !== false)
|
|
1580
|
+
requiredFiles.push(field);
|
|
1581
|
+
}
|
|
1582
|
+
return {
|
|
1583
|
+
required: baseRequired.length > 0 || requiredFiles.length > 0,
|
|
1584
|
+
content: {
|
|
1585
|
+
"multipart/form-data": {
|
|
1586
|
+
schema: {
|
|
1587
|
+
type: "object",
|
|
1588
|
+
properties: { ...baseProps, ...fileProperties },
|
|
1589
|
+
required: [...baseRequired, ...requiredFiles]
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1498
1595
|
function generateOpenApiDocument(config) {
|
|
1596
|
+
const security = config.security ? planOpenApiSecurity(config.security) : undefined;
|
|
1499
1597
|
const groups = [
|
|
1500
1598
|
...(config.services ?? []).map((service) => ({ pathPrefix: undefined, service })),
|
|
1501
1599
|
...(config.groups ?? []).flatMap((group) => group.services.map((service) => ({ pathPrefix: group.pathPrefix, service })))
|
|
@@ -1537,7 +1635,9 @@ function generateOpenApiDocument(config) {
|
|
|
1537
1635
|
});
|
|
1538
1636
|
}
|
|
1539
1637
|
}
|
|
1540
|
-
const
|
|
1638
|
+
const requirement = security?.requirement(method.scope, `${method.method} ${fullPath}`);
|
|
1639
|
+
const guarded = security ? requirement !== undefined : method.scope !== undefined && method.scope !== PUBLIC_SCOPE;
|
|
1640
|
+
const responses = { ...errorResponses(guarded) };
|
|
1541
1641
|
if (method.rawResponse) {
|
|
1542
1642
|
responses["200"] = method.method === "HEAD" ? { description: "Headers only" } : {
|
|
1543
1643
|
description: "Success",
|
|
@@ -1579,6 +1679,7 @@ function generateOpenApiDocument(config) {
|
|
|
1579
1679
|
"x-stitchkit-has-output": Boolean(method.outputSchema || method.stream),
|
|
1580
1680
|
...method.stream && { "x-stitchkit-stream": true },
|
|
1581
1681
|
...parameters.length > 0 && { parameters },
|
|
1682
|
+
...requirement && { security: requirement },
|
|
1582
1683
|
responses
|
|
1583
1684
|
};
|
|
1584
1685
|
if (trailingWildcard) {
|
|
@@ -1591,44 +1692,7 @@ function generateOpenApiDocument(config) {
|
|
|
1591
1692
|
}
|
|
1592
1693
|
if (!inputInQuery && (method.inputSchema || method.multipart)) {
|
|
1593
1694
|
if (method.multipart) {
|
|
1594
|
-
|
|
1595
|
-
const baseProps = isRecord(inputJson.properties) ? inputJson.properties : {};
|
|
1596
|
-
const baseRequired = Array.isArray(inputJson.required) ? inputJson.required : [];
|
|
1597
|
-
const fileProperties = {};
|
|
1598
|
-
const requiredFiles = [];
|
|
1599
|
-
for (const [field, policy] of Object.entries(method.multipart.files)) {
|
|
1600
|
-
const binary = {
|
|
1601
|
-
type: "string",
|
|
1602
|
-
format: "binary",
|
|
1603
|
-
...policy.maxBytes !== undefined && { maxLength: policy.maxBytes },
|
|
1604
|
-
...policy.contentTypes !== undefined && {
|
|
1605
|
-
"x-accepted-content-types": policy.contentTypes
|
|
1606
|
-
}
|
|
1607
|
-
};
|
|
1608
|
-
fileProperties[field] = policy.multiple === true ? {
|
|
1609
|
-
type: "array",
|
|
1610
|
-
items: binary,
|
|
1611
|
-
minItems: policy.required === false ? 0 : 1,
|
|
1612
|
-
...policy.maxFiles !== undefined && { maxItems: policy.maxFiles }
|
|
1613
|
-
} : binary;
|
|
1614
|
-
if (policy.required !== false)
|
|
1615
|
-
requiredFiles.push(field);
|
|
1616
|
-
}
|
|
1617
|
-
operation.requestBody = {
|
|
1618
|
-
required: baseRequired.length > 0 || requiredFiles.length > 0,
|
|
1619
|
-
content: {
|
|
1620
|
-
"multipart/form-data": {
|
|
1621
|
-
schema: {
|
|
1622
|
-
type: "object",
|
|
1623
|
-
properties: {
|
|
1624
|
-
...baseProps,
|
|
1625
|
-
...fileProperties
|
|
1626
|
-
},
|
|
1627
|
-
required: [...baseRequired, ...requiredFiles]
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1695
|
+
operation.requestBody = multipartRequestBody(method.inputSchema, method.multipart);
|
|
1632
1696
|
} else if (method.inputSchema) {
|
|
1633
1697
|
const required = jsonSchemaFields(safeJson(method.inputSchema, "input")).some((f) => f.required);
|
|
1634
1698
|
const schema = safeJson(method.inputSchema, "input");
|
|
@@ -1647,7 +1711,8 @@ function generateOpenApiDocument(config) {
|
|
|
1647
1711
|
openapi: "3.1.0",
|
|
1648
1712
|
info: config.info,
|
|
1649
1713
|
...config.servers && { servers: config.servers },
|
|
1650
|
-
paths
|
|
1714
|
+
paths,
|
|
1715
|
+
...security && { components: { securitySchemes: { ...security.schemes } } }
|
|
1651
1716
|
};
|
|
1652
1717
|
}
|
|
1653
1718
|
function openApiRoute(path, document) {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readDiscoveredToolAnnotations
|
|
3
|
+
} from "../../index-332d0m9g.js";
|
|
1
4
|
import"../../index-69t14s4a.js";
|
|
2
5
|
import"../../index-ct75c3at.js";
|
|
3
6
|
import {
|
|
@@ -919,6 +922,7 @@ async function mountMcpConnection(connection, instanceId, onSkipped) {
|
|
|
919
922
|
name,
|
|
920
923
|
description,
|
|
921
924
|
identity: { serviceName: connection.name, action: name, method: "POST" },
|
|
925
|
+
...tool.annotations && { annotations: tool.annotations },
|
|
922
926
|
...connection.transports && { transports: connection.transports },
|
|
923
927
|
input,
|
|
924
928
|
output: z2.unknown(),
|
|
@@ -945,10 +949,12 @@ function readDiscoveredTools(listed, connectionName) {
|
|
|
945
949
|
for (const raw of listed.tools) {
|
|
946
950
|
if (!isRecord(raw) || typeof raw.name !== "string")
|
|
947
951
|
continue;
|
|
952
|
+
const annotations = readDiscoveredToolAnnotations(raw.annotations);
|
|
948
953
|
tools.push({
|
|
949
954
|
name: raw.name,
|
|
950
955
|
...typeof raw.description === "string" && { description: raw.description },
|
|
951
|
-
...isRecord(raw.inputSchema) && { inputSchema: raw.inputSchema }
|
|
956
|
+
...isRecord(raw.inputSchema) && { inputSchema: raw.inputSchema },
|
|
957
|
+
...annotations && { annotations }
|
|
952
958
|
});
|
|
953
959
|
}
|
|
954
960
|
return tools;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import"../../index-ct75c3at.js";
|
|
2
|
+
import"../../index-332d0m9g.js";
|
|
2
3
|
import"../../index-k42ckyzx.js";
|
|
3
4
|
import"../../index-dsa676h8.js";
|
|
4
5
|
import"../../index-rbzq0q16.js";
|
|
@@ -20,7 +21,7 @@ import {
|
|
|
20
21
|
createMcpHandler2,
|
|
21
22
|
createMcpHttpRoute2,
|
|
22
23
|
createStdioMcpServer2
|
|
23
|
-
} from "../../index-
|
|
24
|
+
} from "../../index-y6ye582c.js";
|
|
24
25
|
import {
|
|
25
26
|
DEFAULT_PROCESS_SIGNALS,
|
|
26
27
|
defaultSignalSource,
|
|
@@ -8,17 +8,18 @@ import"../../index-69t14s4a.js";
|
|
|
8
8
|
import"../../index-ycqhyars.js";
|
|
9
9
|
import {
|
|
10
10
|
mountAgent2
|
|
11
|
-
} from "../../index-
|
|
11
|
+
} from "../../index-1fyea34p.js";
|
|
12
12
|
import {
|
|
13
13
|
createCli2
|
|
14
|
-
} from "../../index-
|
|
14
|
+
} from "../../index-aswegq1r.js";
|
|
15
|
+
import"../../index-332d0m9g.js";
|
|
15
16
|
import"../../index-m5m9rmvt.js";
|
|
16
17
|
import {
|
|
17
18
|
mountMcp2,
|
|
18
19
|
buildMcpServer2,
|
|
19
20
|
createMcpHandler2,
|
|
20
21
|
createStdioMcpServer2
|
|
21
|
-
} from "../../index-
|
|
22
|
+
} from "../../index-y6ye582c.js";
|
|
22
23
|
import"../../index-aqmadanx.js";
|
|
23
24
|
import"../../index-eeahxwvg.js";
|
|
24
25
|
import"../../index-ff39f9dr.js";
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
formatToolError
|
|
9
9
|
} from "./index-ycqhyars.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./index-
|
|
11
|
+
resolveRuntimeToolCall
|
|
12
|
+
} from "./index-eh71zr32.js";
|
|
13
13
|
import {
|
|
14
14
|
AgentToolError2
|
|
15
15
|
} from "./index-1psbyyhj.js";
|
|
@@ -54,8 +54,13 @@ function mountAgent2(services, config = {}) {
|
|
|
54
54
|
});
|
|
55
55
|
const execute = async (rawArgs, options) => {
|
|
56
56
|
const args = isRecord(rawArgs) ? rawArgs : {};
|
|
57
|
-
const
|
|
58
|
-
const
|
|
57
|
+
const runtimeCall = resolveRuntimeToolCall(options.context, options.toolCallId, options.abortSignal);
|
|
58
|
+
const durability = runtimeCall?.durability ?? config.durability?.(options.toolCallId, options.abortSignal);
|
|
59
|
+
const callContext = {
|
|
60
|
+
signal: options.abortSignal,
|
|
61
|
+
toolCallId: options.toolCallId,
|
|
62
|
+
...runtimeCall && { reportProgress: runtimeCall.reportProgress }
|
|
63
|
+
};
|
|
59
64
|
const executeTool = durability ? createToolRunner({
|
|
60
65
|
source: "agent",
|
|
61
66
|
toolSurface: true,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/tools/read-operation.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
function isRepeatableRead(operation) {
|
|
4
|
+
const declared = operation.annotations;
|
|
5
|
+
if (declared?.readOnlyHint !== undefined)
|
|
6
|
+
return declared.readOnlyHint;
|
|
7
|
+
return operation.method === "GET" && declared?.destructiveHint !== true;
|
|
8
|
+
}
|
|
9
|
+
function publishedToolAnnotations(operation) {
|
|
10
|
+
const declared = operation.annotations;
|
|
11
|
+
if (declared?.readOnlyHint !== undefined || !isRepeatableRead(operation))
|
|
12
|
+
return declared;
|
|
13
|
+
return { ...declared, readOnlyHint: true };
|
|
14
|
+
}
|
|
15
|
+
var DiscoveredToolAnnotationsSchema = z.object({
|
|
16
|
+
title: z.string().optional().catch(undefined),
|
|
17
|
+
readOnlyHint: z.boolean().optional().catch(undefined),
|
|
18
|
+
destructiveHint: z.boolean().optional().catch(undefined),
|
|
19
|
+
idempotentHint: z.boolean().optional().catch(undefined),
|
|
20
|
+
openWorldHint: z.boolean().optional().catch(undefined)
|
|
21
|
+
});
|
|
22
|
+
function readDiscoveredToolAnnotations(raw) {
|
|
23
|
+
const parsed = DiscoveredToolAnnotationsSchema.safeParse(raw);
|
|
24
|
+
if (!parsed.success)
|
|
25
|
+
return;
|
|
26
|
+
const { title, readOnlyHint, destructiveHint, idempotentHint, openWorldHint } = parsed.data;
|
|
27
|
+
const annotations = {
|
|
28
|
+
...title !== undefined && { title },
|
|
29
|
+
...readOnlyHint !== undefined && { readOnlyHint },
|
|
30
|
+
...destructiveHint !== undefined && { destructiveHint },
|
|
31
|
+
...idempotentHint !== undefined && { idempotentHint },
|
|
32
|
+
...openWorldHint !== undefined && { openWorldHint }
|
|
33
|
+
};
|
|
34
|
+
return Object.keys(annotations).length > 0 ? annotations : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { isRepeatableRead, publishedToolAnnotations, readDiscoveredToolAnnotations };
|
|
@@ -16,8 +16,9 @@ import {
|
|
|
16
16
|
isToolExecutionControlError2
|
|
17
17
|
} from "./index-s3yxw6kt.js";
|
|
18
18
|
import {
|
|
19
|
+
AGENT_TOOL_PROGRESS_MESSAGE_MAX2,
|
|
19
20
|
agentDurableEventId2
|
|
20
|
-
} from "./index-
|
|
21
|
+
} from "./index-hs76yzt7.js";
|
|
21
22
|
import {
|
|
22
23
|
createLocalStepDurability2
|
|
23
24
|
} from "./index-zyc64nbh.js";
|
|
@@ -38,8 +39,8 @@ import {
|
|
|
38
39
|
messageOf
|
|
39
40
|
} from "./index-g149e9pk.js";
|
|
40
41
|
import {
|
|
41
|
-
|
|
42
|
-
} from "./index-
|
|
42
|
+
createRuntimeToolContext
|
|
43
|
+
} from "./index-eh71zr32.js";
|
|
43
44
|
import {
|
|
44
45
|
createMutationQueue
|
|
45
46
|
} from "./index-sykb5ag7.js";
|
|
@@ -2597,6 +2598,7 @@ async function acquireRun(dependencies, input) {
|
|
|
2597
2598
|
absorbed: new Map,
|
|
2598
2599
|
eventsSinceCheckpoint: 0,
|
|
2599
2600
|
sequence: 0,
|
|
2601
|
+
settledToolCalls: new Set,
|
|
2600
2602
|
terminalReason: "success",
|
|
2601
2603
|
nonModelUsage: input.acceptedRun.usage,
|
|
2602
2604
|
modelUsage: undefined,
|
|
@@ -2976,6 +2978,7 @@ async function applyToolPart(execution, part) {
|
|
|
2976
2978
|
emittedAt: now().toISOString()
|
|
2977
2979
|
});
|
|
2978
2980
|
} else if (part.type === "tool-result") {
|
|
2981
|
+
state.settledToolCalls.add(part.toolCallId);
|
|
2979
2982
|
state.parts.push(AgentMessagePartSchema2.parse({
|
|
2980
2983
|
type: "tool-result",
|
|
2981
2984
|
callId: part.toolCallId,
|
|
@@ -2993,6 +2996,7 @@ async function applyToolPart(execution, part) {
|
|
|
2993
2996
|
emittedAt: now().toISOString()
|
|
2994
2997
|
});
|
|
2995
2998
|
} else if (part.type === "tool-error") {
|
|
2999
|
+
state.settledToolCalls.add(part.toolCallId);
|
|
2996
3000
|
state.internalCause = part.error;
|
|
2997
3001
|
if (isToolExecutionControlError2(part.error)) {
|
|
2998
3002
|
await publish({
|
|
@@ -3024,6 +3028,7 @@ async function applyToolPart(execution, part) {
|
|
|
3024
3028
|
emittedAt: now().toISOString()
|
|
3025
3029
|
});
|
|
3026
3030
|
} else if (part.type === "tool-output-denied") {
|
|
3031
|
+
state.settledToolCalls.add(part.toolCallId);
|
|
3027
3032
|
state.parts.push(AgentMessagePartSchema2.parse({
|
|
3028
3033
|
type: "tool-result",
|
|
3029
3034
|
callId: part.toolCallId,
|
|
@@ -3194,6 +3199,37 @@ async function applyStreamPart(execution, scope, part) {
|
|
|
3194
3199
|
}
|
|
3195
3200
|
}
|
|
3196
3201
|
|
|
3202
|
+
// src/agent-runtime/tool-progress.ts
|
|
3203
|
+
var TOOL_PROGRESS_MIN_INTERVAL_MS = 250;
|
|
3204
|
+
function finite(value) {
|
|
3205
|
+
return value !== undefined && Number.isFinite(value) ? value : undefined;
|
|
3206
|
+
}
|
|
3207
|
+
function createToolProgressReporter(execution, toolName, callId, signal) {
|
|
3208
|
+
let lastPublishedAt;
|
|
3209
|
+
return async (update) => {
|
|
3210
|
+
if (signal?.aborted || execution.state.settledToolCalls.has(callId))
|
|
3211
|
+
return;
|
|
3212
|
+
const now = execution.dependencies.now();
|
|
3213
|
+
if (lastPublishedAt !== undefined && now.getTime() - lastPublishedAt < TOOL_PROGRESS_MIN_INTERVAL_MS) {
|
|
3214
|
+
return;
|
|
3215
|
+
}
|
|
3216
|
+
lastPublishedAt = now.getTime();
|
|
3217
|
+
const message = update.message?.slice(0, AGENT_TOOL_PROGRESS_MESSAGE_MAX2);
|
|
3218
|
+
const progress = finite(update.progress);
|
|
3219
|
+
const total = finite(update.total);
|
|
3220
|
+
await execution.dependencies.publish({
|
|
3221
|
+
type: "tool-progress",
|
|
3222
|
+
...transientHead(execution),
|
|
3223
|
+
callId,
|
|
3224
|
+
toolName,
|
|
3225
|
+
...message !== undefined && { message },
|
|
3226
|
+
...progress !== undefined && { progress },
|
|
3227
|
+
...total !== undefined && { total },
|
|
3228
|
+
emittedAt: now.toISOString()
|
|
3229
|
+
});
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3197
3233
|
// src/agent-runtime/run-model-attempts.ts
|
|
3198
3234
|
function createStopConditions(execution, turn) {
|
|
3199
3235
|
const { config, maxSteps } = execution.dependencies;
|
|
@@ -3268,10 +3304,30 @@ async function prepareAttemptStep(context, attempt, options) {
|
|
|
3268
3304
|
});
|
|
3269
3305
|
return { ...preparedStep, model };
|
|
3270
3306
|
}
|
|
3307
|
+
function runToolDurability(context, toolName, toolCallId, signal) {
|
|
3308
|
+
const { config } = context.execution.dependencies;
|
|
3309
|
+
const { state } = context.execution;
|
|
3310
|
+
const port = config.durability;
|
|
3311
|
+
if (typeof port === "function")
|
|
3312
|
+
return port({
|
|
3313
|
+
store: config.store,
|
|
3314
|
+
conversationId: state.run.conversationId,
|
|
3315
|
+
runId: state.run.id,
|
|
3316
|
+
toolName,
|
|
3317
|
+
toolCallId,
|
|
3318
|
+
signal
|
|
3319
|
+
});
|
|
3320
|
+
return createLocalStepDurability2({
|
|
3321
|
+
store: config.store,
|
|
3322
|
+
conversationId: state.run.conversationId,
|
|
3323
|
+
runId: JSON.stringify([state.run.id, toolName, toolCallId]),
|
|
3324
|
+
signal
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3271
3327
|
function startAttemptStream(context, attempt, stopConditions) {
|
|
3272
3328
|
const { execution, turn } = context;
|
|
3273
3329
|
const { config } = execution.dependencies;
|
|
3274
|
-
const {
|
|
3330
|
+
const { idleDeadline, operationLifecycle } = execution;
|
|
3275
3331
|
const { tools } = turn;
|
|
3276
3332
|
const attemptSignal = AbortSignal.any([
|
|
3277
3333
|
execution.executionSignal,
|
|
@@ -3280,29 +3336,15 @@ function startAttemptStream(context, attempt, stopConditions) {
|
|
|
3280
3336
|
return streamAgentTextBoundary({
|
|
3281
3337
|
model: turn.selectedModel.model,
|
|
3282
3338
|
tools,
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
runId: state.run.id,
|
|
3293
|
-
toolName,
|
|
3294
|
-
toolCallId,
|
|
3295
|
-
signal
|
|
3296
|
-
});
|
|
3297
|
-
return createLocalStepDurability2({
|
|
3298
|
-
store: config.store,
|
|
3299
|
-
conversationId: state.run.conversationId,
|
|
3300
|
-
runId: JSON.stringify([state.run.id, toolName, toolCallId]),
|
|
3301
|
-
signal
|
|
3302
|
-
});
|
|
3303
|
-
})
|
|
3304
|
-
]))
|
|
3305
|
-
},
|
|
3339
|
+
toolsContext: Object.fromEntries(Object.entries(tools).filter(([, tool]) => tool.contextSchema === undefined).map(([toolName]) => [
|
|
3340
|
+
toolName,
|
|
3341
|
+
createRuntimeToolContext((toolCallId, signal) => ({
|
|
3342
|
+
...config.durability && {
|
|
3343
|
+
durability: runToolDurability(context, toolName, toolCallId, signal)
|
|
3344
|
+
},
|
|
3345
|
+
reportProgress: createToolProgressReporter(execution, toolName, toolCallId, signal)
|
|
3346
|
+
}))
|
|
3347
|
+
])),
|
|
3306
3348
|
instructions: turn.projection.withCarriedSystem(turn.prompt.instructions),
|
|
3307
3349
|
messages: turn.history,
|
|
3308
3350
|
abortSignal: attemptSignal,
|
|
@@ -23,6 +23,9 @@ import {
|
|
|
23
23
|
createToolRunner,
|
|
24
24
|
formatToolError
|
|
25
25
|
} from "./index-ycqhyars.js";
|
|
26
|
+
import {
|
|
27
|
+
isRepeatableRead
|
|
28
|
+
} from "./index-332d0m9g.js";
|
|
26
29
|
import {
|
|
27
30
|
writeContainedFile
|
|
28
31
|
} from "./index-aqmadanx.js";
|
|
@@ -185,8 +188,16 @@ function emitResult2(result, writers, opts) {
|
|
|
185
188
|
`);
|
|
186
189
|
return cliExitCode2(result, opts.exitCodes);
|
|
187
190
|
}
|
|
191
|
+
function presentationFailureHint(repeatable, printed) {
|
|
192
|
+
if (repeatable) {
|
|
193
|
+
return "The result was not printed: this command only reads. Repeat it with a corrected view.";
|
|
194
|
+
}
|
|
195
|
+
return printed ? "The complete, unformatted result is on stdout. Do not repeat the command to recover its result." : "The command returned no result. Do not repeat it.";
|
|
196
|
+
}
|
|
188
197
|
function emitPresentationFailure(result, failure, writers, opts) {
|
|
189
|
-
|
|
198
|
+
const printed = !opts.repeatable && result.data !== undefined;
|
|
199
|
+
if (printed)
|
|
200
|
+
emitResult2(result, writers, opts);
|
|
190
201
|
return emitResult2({
|
|
191
202
|
ok: false,
|
|
192
203
|
code: "CLI_PRESENTATION_FAILED",
|
|
@@ -195,9 +206,10 @@ function emitPresentationFailure(result, failure, writers, opts) {
|
|
|
195
206
|
message: "The command completed successfully, but its result presentation failed.",
|
|
196
207
|
command: opts.toolName,
|
|
197
208
|
operationSucceeded: true,
|
|
209
|
+
resultOnStdout: printed,
|
|
198
210
|
cause: formatToolError(failure)
|
|
199
211
|
},
|
|
200
|
-
hint:
|
|
212
|
+
hint: presentationFailureHint(opts.repeatable, printed)
|
|
201
213
|
}, writers, { json: opts.json, toolName: opts.toolName, exitCodes: opts.exitCodes });
|
|
202
214
|
}
|
|
203
215
|
|
|
@@ -2225,7 +2237,7 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2225
2237
|
toolArgs,
|
|
2226
2238
|
options
|
|
2227
2239
|
});
|
|
2228
|
-
return emitManagedResult(session, command, result, options);
|
|
2240
|
+
return emitManagedResult(session, command, result, options, isRepeatableRead(tool.method));
|
|
2229
2241
|
}
|
|
2230
2242
|
async function executeManagedTool(session, route, command, managed, tool, { toolArgs, options }) {
|
|
2231
2243
|
const { config } = session;
|
|
@@ -2271,7 +2283,7 @@ async function executeManagedTool(session, route, command, managed, tool, { tool
|
|
|
2271
2283
|
}
|
|
2272
2284
|
return result;
|
|
2273
2285
|
}
|
|
2274
|
-
async function emitManagedResult(session, command, initial, options) {
|
|
2286
|
+
async function emitManagedResult(session, command, initial, options, repeatable) {
|
|
2275
2287
|
const { config } = session;
|
|
2276
2288
|
const { stdout, stderr, exit } = session.io;
|
|
2277
2289
|
let result = initial;
|
|
@@ -2289,7 +2301,7 @@ async function emitManagedResult(session, command, initial, options) {
|
|
|
2289
2301
|
code: "BAD_REQUEST",
|
|
2290
2302
|
details: { message: error.message }
|
|
2291
2303
|
} : toolResultFromError(error);
|
|
2292
|
-
return exit(emitPresentationFailure(result, failure, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
|
|
2304
|
+
return exit(emitPresentationFailure(result, failure, { stdout, stderr }, { ...emitOptionsFor(config, options.json, command), repeatable }));
|
|
2293
2305
|
}
|
|
2294
2306
|
if (viewed.kind === "text") {
|
|
2295
2307
|
stdout(viewed.text);
|
|
@@ -2352,7 +2364,7 @@ async function runNativeCommand2(session, route, command, native) {
|
|
|
2352
2364
|
const result = await executeCliCommand(native, toolArgs, options, { stdout, stderr }, config.coerceJsonArgs ?? true, globals);
|
|
2353
2365
|
const emission = prepareCliCommandEmission(native, result, options);
|
|
2354
2366
|
if (emission.result.ok && emission.presentationFailure !== undefined) {
|
|
2355
|
-
return exit(emitPresentationFailure(emission.result, emission.presentationFailure, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
|
|
2367
|
+
return exit(emitPresentationFailure(emission.result, emission.presentationFailure, { stdout, stderr }, { ...emitOptionsFor(config, options.json, command), repeatable: false }));
|
|
2356
2368
|
}
|
|
2357
2369
|
let emittedExitCode;
|
|
2358
2370
|
if (emission.result.ok && emission.presentation !== undefined) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentControlRequestSchema2,
|
|
3
3
|
AgentControlResponseSchema2
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-t05a2ry4.js";
|
|
5
5
|
import {
|
|
6
6
|
createAgentRuntimeEventSink2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-7qyv50r4.js";
|
|
8
8
|
import {
|
|
9
9
|
assertPositiveSafeInteger
|
|
10
10
|
} from "./index-0s4xebbg.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// src/tools/
|
|
1
|
+
// src/tools/runtime-call-context.ts
|
|
2
2
|
var contexts = new WeakMap;
|
|
3
|
-
function
|
|
3
|
+
function createRuntimeToolContext(factory) {
|
|
4
4
|
const context = {};
|
|
5
5
|
contexts.set(context, factory);
|
|
6
6
|
return context;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function resolveRuntimeToolCall(context, callId, signal) {
|
|
9
9
|
if (typeof context !== "object" || context === null)
|
|
10
10
|
return;
|
|
11
11
|
return contexts.get(context)?.(callId, signal);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export {
|
|
14
|
+
export { createRuntimeToolContext, resolveRuntimeToolCall };
|
|
@@ -86,6 +86,17 @@ var AgentToolStatusEventSchema2 = EventIdentitySchema.extend({
|
|
|
86
86
|
input: z.json().optional(),
|
|
87
87
|
output: z.json().optional()
|
|
88
88
|
});
|
|
89
|
+
var AGENT_TOOL_PROGRESS_MESSAGE_MAX2 = 280;
|
|
90
|
+
var AgentToolProgressEventSchema2 = EventIdentitySchema.extend({
|
|
91
|
+
type: z.literal("tool-progress"),
|
|
92
|
+
runtimeEpoch: z.string().min(1),
|
|
93
|
+
sequence: z.int().nonnegative(),
|
|
94
|
+
callId: AgentRecordIdSchema2,
|
|
95
|
+
toolName: z.string().min(1),
|
|
96
|
+
message: z.string().max(AGENT_TOOL_PROGRESS_MESSAGE_MAX2).optional(),
|
|
97
|
+
progress: z.number().finite().optional(),
|
|
98
|
+
total: z.number().finite().optional()
|
|
99
|
+
});
|
|
89
100
|
var AgentTerminalEventSchema2 = EventIdentitySchema.extend({
|
|
90
101
|
type: z.literal("terminal"),
|
|
91
102
|
eventId: AgentRecordIdSchema2,
|
|
@@ -106,6 +117,7 @@ var AgentRuntimeEventSchema2 = z.discriminatedUnion("type", [
|
|
|
106
117
|
AgentRunStateEventSchema2,
|
|
107
118
|
AgentRunOperationEventSchema2,
|
|
108
119
|
AgentToolStatusEventSchema2,
|
|
120
|
+
AgentToolProgressEventSchema2,
|
|
109
121
|
AgentTerminalEventSchema2
|
|
110
122
|
]);
|
|
111
123
|
var AgentRuntimeEventCursorSchema2 = z.object({
|
|
@@ -147,4 +159,4 @@ function agentDurableEventId2(type, runId, snapshotVersion) {
|
|
|
147
159
|
return `${runId}:${type}:${snapshotVersion}`;
|
|
148
160
|
}
|
|
149
161
|
|
|
150
|
-
export { AgentAdmissionEventSchema2, AgentTransientDeltaEventSchema2, AgentReasoningStartEventSchema2, AgentReasoningDeltaEventSchema2, AgentReasoningEndEventSchema2, AgentAttemptResetEventSchema2, AgentCheckpointEventSchema2, AgentRunStateEventSchema2, AgentRunOperationEventSchema2, AgentToolStatusEventSchema2, AgentTerminalEventSchema2, AgentRuntimeEventSchema2, AgentRuntimeEventCursorSchema2, advanceAgentRuntimeEventCursor2, agentDurableEventId2 };
|
|
162
|
+
export { AgentAdmissionEventSchema2, AgentTransientDeltaEventSchema2, AgentReasoningStartEventSchema2, AgentReasoningDeltaEventSchema2, AgentReasoningEndEventSchema2, AgentAttemptResetEventSchema2, AgentCheckpointEventSchema2, AgentRunStateEventSchema2, AgentRunOperationEventSchema2, AgentToolStatusEventSchema2, AGENT_TOOL_PROGRESS_MESSAGE_MAX2, AgentToolProgressEventSchema2, AgentTerminalEventSchema2, AgentRuntimeEventSchema2, AgentRuntimeEventCursorSchema2, advanceAgentRuntimeEventCursor2, agentDurableEventId2 };
|