stitchkit 0.121.0 → 0.122.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 +41 -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 +1 -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/toolkit.js +2 -2
- package/dist/{index-7zwtbak8.js → index-1fyea34p.js} +9 -4
- package/dist/{index-4qnzda76.js → index-7qyv50r4.js} +1 -1
- package/dist/{index-qctbzmg9.js → index-am1h8c9v.js} +69 -27
- 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-0fra8xvy.js → index-v8yqk4w7.js} +20 -6
- 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/repeatable-read.d.ts +9 -0
- package/dist/tools/cli/repeatable-read.d.ts.map +1 -0
- 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/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 +21 -9
- package/llms/server.2.txt +48 -0
- package/llms/server.5.txt +2 -0
- package/llms/stitchkit.txt +3 -3
- package/llms/tools.txt +4 -1
- 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 +126 -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) {
|
|
@@ -8,10 +8,10 @@ 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-v8yqk4w7.js";
|
|
15
15
|
import"../../index-m5m9rmvt.js";
|
|
16
16
|
import {
|
|
17
17
|
mountMcp2,
|
|
@@ -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,
|
|
@@ -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,
|
|
@@ -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 };
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./index-8kzct1d6.js";
|
|
5
5
|
import {
|
|
6
6
|
AgentRuntimeEventSchema2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-hs76yzt7.js";
|
|
8
8
|
|
|
9
9
|
// src/agent-runtime/control-schema.ts
|
|
10
10
|
import { z } from "zod";
|
|
@@ -154,6 +154,43 @@ function advanceAgentMultiSessionCursor2(raw, event) {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
+
var EMPTY_TRANSIENT = { text: "", reasoning: "", tools: {} };
|
|
158
|
+
function nextRunTransient(transient, event) {
|
|
159
|
+
switch (event.type) {
|
|
160
|
+
case "assistant-delta":
|
|
161
|
+
return { ...transient, text: transient.text + event.textDelta };
|
|
162
|
+
case "reasoning-delta":
|
|
163
|
+
return { ...transient, reasoning: transient.reasoning + event.textDelta };
|
|
164
|
+
case "attempt-reset":
|
|
165
|
+
return EMPTY_TRANSIENT;
|
|
166
|
+
case "tool-progress": {
|
|
167
|
+
const { toolName, message, progress, total } = event;
|
|
168
|
+
return {
|
|
169
|
+
...transient,
|
|
170
|
+
tools: {
|
|
171
|
+
...transient.tools,
|
|
172
|
+
[event.callId]: {
|
|
173
|
+
toolName,
|
|
174
|
+
...message !== undefined && { message },
|
|
175
|
+
...progress !== undefined && { progress },
|
|
176
|
+
...total !== undefined && { total }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
case "tool-status": {
|
|
182
|
+
if (event.status === "started" || !Object.hasOwn(transient.tools, event.callId)) {
|
|
183
|
+
return transient;
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
...transient,
|
|
187
|
+
tools: Object.fromEntries(Object.entries(transient.tools).filter(([callId]) => callId !== event.callId))
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
default:
|
|
191
|
+
return transient;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
157
194
|
function createAgentControlView2() {
|
|
158
195
|
return { cursor: { conversations: {} }, conversations: {} };
|
|
159
196
|
}
|
|
@@ -199,8 +236,7 @@ function reduceAgentControlEvent2(view, rawEvent) {
|
|
|
199
236
|
}
|
|
200
237
|
};
|
|
201
238
|
}
|
|
202
|
-
const
|
|
203
|
-
const nextTransient = event.type === "assistant-delta" ? { ...transient, text: transient.text + event.textDelta } : event.type === "reasoning-delta" ? { ...transient, reasoning: transient.reasoning + event.textDelta } : event.type === "attempt-reset" ? { text: "", reasoning: "" } : transient;
|
|
239
|
+
const nextTransient = nextRunTransient(current.transientByRun[event.runId] ?? EMPTY_TRANSIENT, event);
|
|
204
240
|
const snapshotStale = durable(event) && current.snapshot?.version !== event.snapshotVersion;
|
|
205
241
|
const transientByRun = event.type === "terminal" ? Object.fromEntries(Object.entries(current.transientByRun).filter(([runId]) => runId !== event.runId)) : { ...current.transientByRun, [event.runId]: nextTransient };
|
|
206
242
|
return {
|
|
@@ -185,8 +185,16 @@ function emitResult2(result, writers, opts) {
|
|
|
185
185
|
`);
|
|
186
186
|
return cliExitCode2(result, opts.exitCodes);
|
|
187
187
|
}
|
|
188
|
+
function presentationFailureHint(repeatable, printed) {
|
|
189
|
+
if (repeatable) {
|
|
190
|
+
return "The result was not printed: this command only reads. Repeat it with a corrected view.";
|
|
191
|
+
}
|
|
192
|
+
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.";
|
|
193
|
+
}
|
|
188
194
|
function emitPresentationFailure(result, failure, writers, opts) {
|
|
189
|
-
|
|
195
|
+
const printed = !opts.repeatable && result.data !== undefined;
|
|
196
|
+
if (printed)
|
|
197
|
+
emitResult2(result, writers, opts);
|
|
190
198
|
return emitResult2({
|
|
191
199
|
ok: false,
|
|
192
200
|
code: "CLI_PRESENTATION_FAILED",
|
|
@@ -195,9 +203,10 @@ function emitPresentationFailure(result, failure, writers, opts) {
|
|
|
195
203
|
message: "The command completed successfully, but its result presentation failed.",
|
|
196
204
|
command: opts.toolName,
|
|
197
205
|
operationSucceeded: true,
|
|
206
|
+
resultOnStdout: printed,
|
|
198
207
|
cause: formatToolError(failure)
|
|
199
208
|
},
|
|
200
|
-
hint:
|
|
209
|
+
hint: presentationFailureHint(opts.repeatable, printed)
|
|
201
210
|
}, writers, { json: opts.json, toolName: opts.toolName, exitCodes: opts.exitCodes });
|
|
202
211
|
}
|
|
203
212
|
|
|
@@ -1773,6 +1782,11 @@ async function prepareInvocation(command, commandArgv, descriptor, config, readS
|
|
|
1773
1782
|
return { ok: true, toolArgs, options };
|
|
1774
1783
|
}
|
|
1775
1784
|
|
|
1785
|
+
// src/tools/cli/repeatable-read.ts
|
|
1786
|
+
function isRepeatableRead(operation) {
|
|
1787
|
+
return operation.annotations?.readOnlyHint ?? operation.method === "GET";
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1776
1790
|
// src/tools/cli/session.ts
|
|
1777
1791
|
function nativeDescriptor(definition) {
|
|
1778
1792
|
return {
|
|
@@ -2225,7 +2239,7 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2225
2239
|
toolArgs,
|
|
2226
2240
|
options
|
|
2227
2241
|
});
|
|
2228
|
-
return emitManagedResult(session, command, result, options);
|
|
2242
|
+
return emitManagedResult(session, command, result, options, isRepeatableRead(tool.method));
|
|
2229
2243
|
}
|
|
2230
2244
|
async function executeManagedTool(session, route, command, managed, tool, { toolArgs, options }) {
|
|
2231
2245
|
const { config } = session;
|
|
@@ -2271,7 +2285,7 @@ async function executeManagedTool(session, route, command, managed, tool, { tool
|
|
|
2271
2285
|
}
|
|
2272
2286
|
return result;
|
|
2273
2287
|
}
|
|
2274
|
-
async function emitManagedResult(session, command, initial, options) {
|
|
2288
|
+
async function emitManagedResult(session, command, initial, options, repeatable) {
|
|
2275
2289
|
const { config } = session;
|
|
2276
2290
|
const { stdout, stderr, exit } = session.io;
|
|
2277
2291
|
let result = initial;
|
|
@@ -2289,7 +2303,7 @@ async function emitManagedResult(session, command, initial, options) {
|
|
|
2289
2303
|
code: "BAD_REQUEST",
|
|
2290
2304
|
details: { message: error.message }
|
|
2291
2305
|
} : toolResultFromError(error);
|
|
2292
|
-
return exit(emitPresentationFailure(result, failure, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
|
|
2306
|
+
return exit(emitPresentationFailure(result, failure, { stdout, stderr }, { ...emitOptionsFor(config, options.json, command), repeatable }));
|
|
2293
2307
|
}
|
|
2294
2308
|
if (viewed.kind === "text") {
|
|
2295
2309
|
stdout(viewed.text);
|
|
@@ -2352,7 +2366,7 @@ async function runNativeCommand2(session, route, command, native) {
|
|
|
2352
2366
|
const result = await executeCliCommand(native, toolArgs, options, { stdout, stderr }, config.coerceJsonArgs ?? true, globals);
|
|
2353
2367
|
const emission = prepareCliCommandEmission(native, result, options);
|
|
2354
2368
|
if (emission.result.ok && emission.presentationFailure !== undefined) {
|
|
2355
|
-
return exit(emitPresentationFailure(emission.result, emission.presentationFailure, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
|
|
2369
|
+
return exit(emitPresentationFailure(emission.result, emission.presentationFailure, { stdout, stderr }, { ...emitOptionsFor(config, options.json, command), repeatable: false }));
|
|
2356
2370
|
}
|
|
2357
2371
|
let emittedExitCode;
|
|
2358
2372
|
if (emission.result.ok && emission.presentation !== undefined) {
|