stitchkit 0.68.10 → 0.69.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/README.md +30 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts +155 -0
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-files.d.ts +3 -0
- package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-paths.d.ts +19 -0
- package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-search-patch.d.ts +3 -0
- package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-shell.d.ts +3 -0
- package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tools.d.ts +17 -0
- package/dist/agent-runtime/coding-tools.d.ts.map +1 -0
- package/dist/agent-runtime/compaction.d.ts +2 -0
- package/dist/agent-runtime/compaction.d.ts.map +1 -1
- package/dist/agent-runtime/contained-files.d.ts +31 -0
- package/dist/agent-runtime/contained-files.d.ts.map +1 -0
- package/dist/agent-runtime/control-schema.d.ts +1074 -0
- package/dist/agent-runtime/control-schema.d.ts.map +1 -0
- package/dist/agent-runtime/conversations.d.ts +128 -0
- package/dist/agent-runtime/conversations.d.ts.map +1 -0
- package/dist/agent-runtime/event-schema.d.ts +96 -0
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/harness-contract.d.ts +169 -0
- package/dist/agent-runtime/harness-contract.d.ts.map +1 -0
- package/dist/agent-runtime/harness-control.d.ts +25 -0
- package/dist/agent-runtime/harness-control.d.ts.map +1 -0
- package/dist/agent-runtime/harness-file-resources.d.ts +33 -0
- package/dist/agent-runtime/harness-file-resources.d.ts.map +1 -0
- package/dist/agent-runtime/harness-resources.d.ts +5 -0
- package/dist/agent-runtime/harness-resources.d.ts.map +1 -0
- package/dist/agent-runtime/harness.d.ts +12 -0
- package/dist/agent-runtime/harness.d.ts.map +1 -0
- package/dist/agent-runtime/history.d.ts +2 -0
- package/dist/agent-runtime/history.d.ts.map +1 -1
- package/dist/agent-runtime/models.d.ts +199 -0
- package/dist/agent-runtime/models.d.ts.map +1 -1
- package/dist/agent-runtime/prompt.d.ts +2 -0
- package/dist/agent-runtime/prompt.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +11 -3
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/schemas.d.ts +49 -0
- package/dist/agent-runtime/schemas.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite.d.ts +2 -0
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver.d.ts +61 -212
- package/dist/agent-runtime/store-driver.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +368 -1
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +12 -1
- package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-status.d.ts +8 -0
- package/dist/agent-runtime/terminal-status.d.ts.map +1 -1
- package/dist/agent-runtime-browser.d.ts +1 -0
- package/dist/agent-runtime-browser.d.ts.map +1 -1
- package/dist/agent-runtime-browser.js +217 -1
- package/dist/agent-runtime-coding-tools.d.ts +2 -0
- package/dist/agent-runtime-coding-tools.d.ts.map +1 -0
- package/dist/agent-runtime-coding-tools.js +706 -0
- package/dist/agent-runtime-harness.d.ts +2 -0
- package/dist/agent-runtime-harness.d.ts.map +1 -0
- package/dist/agent-runtime-harness.js +700 -0
- package/dist/agent-runtime-openrouter.d.ts +14 -1
- package/dist/agent-runtime-openrouter.d.ts.map +1 -1
- package/dist/agent-runtime-openrouter.js +211 -0
- package/dist/agent-runtime-sqlite-bun.js +4 -3
- package/dist/agent-runtime-sqlite-node.js +4 -3
- package/dist/agent-runtime.d.ts +5 -3
- package/dist/agent-runtime.d.ts.map +1 -1
- package/dist/agent-runtime.js +106 -2580
- package/dist/application/diagnostic-journal-contract.d.ts +164 -0
- package/dist/application/diagnostic-journal-contract.d.ts.map +1 -0
- package/dist/application/diagnostic-journal-manager.d.ts +12 -0
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -0
- package/dist/application/diagnostic-journal-storage.d.ts +29 -0
- package/dist/application/diagnostic-journal-storage.d.ts.map +1 -0
- package/dist/application/diagnostic-journal.d.ts +11 -0
- package/dist/application/diagnostic-journal.d.ts.map +1 -0
- package/dist/application.d.ts +2 -0
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +561 -17
- package/dist/browser/socket-io.d.ts +8 -2
- package/dist/browser/socket-io.d.ts.map +1 -1
- package/dist/cli.js +8 -6
- package/dist/{index-8vpzxg55.js → index-10gbbbaa.js} +103 -2
- package/dist/index-3eqrkqhg.js +2565 -0
- package/dist/{index-hcx9yypn.js → index-444747ww.js} +7 -7
- package/dist/{index-557by2db.js → index-7b188kmz.js} +15 -0
- package/dist/{index-hxh98zbm.js → index-d1jsvkyk.js} +1 -1
- package/dist/index-es0h4w26.js +63 -0
- package/dist/{index-grgvpbch.js → index-gqdfpv4n.js} +4 -2
- package/dist/{index-bt5179zb.js → index-h7ctj1kp.js} +5 -3
- package/dist/{index-y2ctppmg.js → index-h8vn1jcr.js} +7 -73
- package/dist/{index-hqza5nde.js → index-hsabxjz0.js} +78 -77
- package/dist/index-kg9xx84n.js +73 -0
- package/dist/{index-hb0mncmj.js → index-kxxyvkka.js} +2 -2
- package/dist/{index-2t6zt5cg.js → index-mbxds404.js} +7 -5
- package/dist/{index-f24xg2cw.js → index-p1be103g.js} +1 -1
- package/dist/{index-xyvxez9r.js → index-q7gdep2c.js} +5 -5
- package/dist/{index-t23p2b68.js → index-t4dpby6e.js} +1 -1
- package/dist/index-tg3m2ec5.js +157 -0
- package/dist/index-v3dpzpjw.js +92 -0
- package/dist/{index-eqqyd9v8.js → index-wwst0td5.js} +2 -46
- package/dist/{index-ysphyxax.js → index-x1th9s8c.js} +23 -2
- package/dist/index-xxsq3ca1.js +51 -0
- package/dist/{index-22tjt2rk.js → index-zh459sfj.js} +1 -1
- package/dist/index.js +183 -11
- package/dist/internal/ai-sdk-typed.d.ts +14 -0
- package/dist/internal/ai-sdk-typed.d.ts.map +1 -0
- package/dist/node.js +6 -6
- package/dist/observability/index.js +4 -4
- package/dist/realtime/index.d.ts +1 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/request.d.ts +30 -0
- package/dist/realtime/request.d.ts.map +1 -1
- package/dist/remote.js +6 -6
- package/dist/server/index.js +10 -10
- package/dist/testing.js +6 -6
- package/dist/tool-invoker.js +6 -5
- package/dist/tools.js +21 -17
- package/llms-full.txt +385 -24
- package/package.json +10 -2
- package/dist/{index-pgsyp3xh.js → index-x18ndp4p.js} +3 -3
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
defaultSignalSource,
|
|
8
8
|
guardSignalCallback,
|
|
9
9
|
reportSignalError
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-d1jsvkyk.js";
|
|
11
11
|
import {
|
|
12
12
|
extractIp,
|
|
13
13
|
getClientInfo,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
runWithRequestContext,
|
|
19
19
|
setRequestEndpoint,
|
|
20
20
|
setRequestError
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-p1be103g.js";
|
|
22
22
|
import {
|
|
23
23
|
ShutdownOptionsSchema
|
|
24
24
|
} from "./index-dk6e56g0.js";
|
|
@@ -34,15 +34,15 @@ import {
|
|
|
34
34
|
safeJsonParse,
|
|
35
35
|
validateDeclaredOutput,
|
|
36
36
|
zodIssues
|
|
37
|
-
} from "./index-
|
|
38
|
-
import {
|
|
39
|
-
isRecord,
|
|
40
|
-
transportResult
|
|
41
|
-
} from "./index-qyrqwr4c.js";
|
|
37
|
+
} from "./index-x18ndp4p.js";
|
|
42
38
|
import {
|
|
43
39
|
AppError,
|
|
44
40
|
badRequest
|
|
45
41
|
} from "./index-0w9abg87.js";
|
|
42
|
+
import {
|
|
43
|
+
isRecord,
|
|
44
|
+
transportResult
|
|
45
|
+
} from "./index-qyrqwr4c.js";
|
|
46
46
|
|
|
47
47
|
// src/server/multipart.ts
|
|
48
48
|
var DEFAULT_MAX_REQUEST_BYTES = 25 * 1024 * 1024;
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
// src/realtime/request.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var RealtimeRequestPhaseSchema = z.enum([
|
|
4
|
+
"engine-handoff",
|
|
5
|
+
"engine-ack-received",
|
|
6
|
+
"settled",
|
|
7
|
+
"timeout",
|
|
8
|
+
"disconnected"
|
|
9
|
+
]);
|
|
10
|
+
var RealtimeRequestPhaseEventSchema = z.object({
|
|
11
|
+
requestId: z.string().min(1),
|
|
12
|
+
event: z.string().min(1),
|
|
13
|
+
phase: RealtimeRequestPhaseSchema,
|
|
14
|
+
elapsedMs: z.number().finite().nonnegative()
|
|
15
|
+
}).strict();
|
|
16
|
+
|
|
2
17
|
class RealtimeRequestTimeoutError extends Error {
|
|
3
18
|
code = "REALTIME_REQUEST_TIMEOUT";
|
|
4
19
|
event;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/agent-runtime/terminal-status.ts
|
|
2
|
+
function isSpeakableAssistantStatus(status) {
|
|
3
|
+
return status === "completed" || status === "interrupted" || status === "committed";
|
|
4
|
+
}
|
|
5
|
+
function isAssistantHistoryEvidence(status, policy) {
|
|
6
|
+
return isSpeakableAssistantStatus(status) || status === "failed" && policy?.failedAssistant === "assistant-marked";
|
|
7
|
+
}
|
|
8
|
+
function isCompleteAgentHistoryTurn(messages, policy) {
|
|
9
|
+
if (messages[0]?.role !== "user")
|
|
10
|
+
return false;
|
|
11
|
+
const calls = new Set;
|
|
12
|
+
const completed = new Set;
|
|
13
|
+
const approvals = new Map;
|
|
14
|
+
let assistantCount = 0;
|
|
15
|
+
for (const message of messages) {
|
|
16
|
+
if (message.role === "assistant") {
|
|
17
|
+
if (!isAssistantHistoryEvidence(message.status, policy))
|
|
18
|
+
return false;
|
|
19
|
+
assistantCount += 1;
|
|
20
|
+
}
|
|
21
|
+
for (const part of message.parts) {
|
|
22
|
+
if (part.type === "tool-call") {
|
|
23
|
+
if (calls.has(part.callId))
|
|
24
|
+
return false;
|
|
25
|
+
calls.add(part.callId);
|
|
26
|
+
} else if (part.type === "tool-approval-request") {
|
|
27
|
+
if (!calls.has(part.callId) || completed.has(part.callId) || approvals.has(part.approvalId))
|
|
28
|
+
return false;
|
|
29
|
+
if ([...approvals.values()].some((approval) => approval.callId === part.callId))
|
|
30
|
+
return false;
|
|
31
|
+
approvals.set(part.approvalId, { callId: part.callId, answered: false });
|
|
32
|
+
} else if (part.type === "tool-approval-response") {
|
|
33
|
+
const approval = approvals.get(part.approvalId);
|
|
34
|
+
if (!approval || approval.answered)
|
|
35
|
+
return false;
|
|
36
|
+
approval.answered = true;
|
|
37
|
+
} else if (part.type === "tool-result") {
|
|
38
|
+
if (!calls.has(part.callId) || completed.has(part.callId))
|
|
39
|
+
return false;
|
|
40
|
+
const approval = [...approvals.values()].find((entry) => entry.callId === part.callId);
|
|
41
|
+
if (approval && !approval.answered)
|
|
42
|
+
return false;
|
|
43
|
+
completed.add(part.callId);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return assistantCount > 0 && calls.size === completed.size && [...approvals.values()].every((approval) => approval.answered);
|
|
48
|
+
}
|
|
49
|
+
function assistantStatus(reason) {
|
|
50
|
+
if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
|
|
51
|
+
return "completed";
|
|
52
|
+
}
|
|
53
|
+
if (reason === "superseded")
|
|
54
|
+
return "superseded";
|
|
55
|
+
if (reason === "absorbed")
|
|
56
|
+
return "superseded";
|
|
57
|
+
if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
|
|
58
|
+
return "interrupted";
|
|
59
|
+
}
|
|
60
|
+
return "failed";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { isAssistantHistoryEvidence, isCompleteAgentHistoryTurn, assistantStatus };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectTools,
|
|
3
|
-
createToolRunner
|
|
3
|
+
createToolRunner
|
|
4
|
+
} from "./index-kg9xx84n.js";
|
|
5
|
+
import {
|
|
4
6
|
toolErrorFromResult
|
|
5
|
-
} from "./index-
|
|
7
|
+
} from "./index-h8vn1jcr.js";
|
|
6
8
|
import {
|
|
7
9
|
assertUniqueToolName
|
|
8
10
|
} from "./index-22by16v6.js";
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectToolSurface
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-xxsq3ca1.js";
|
|
4
4
|
import {
|
|
5
5
|
createToolRunner,
|
|
6
|
-
formatToolError
|
|
6
|
+
formatToolError
|
|
7
|
+
} from "./index-kg9xx84n.js";
|
|
8
|
+
import {
|
|
7
9
|
isToolExecutionControlError,
|
|
8
10
|
toolResultFromError
|
|
9
|
-
} from "./index-
|
|
11
|
+
} from "./index-h8vn1jcr.js";
|
|
10
12
|
import {
|
|
11
13
|
isRecord
|
|
12
14
|
} from "./index-qyrqwr4c.js";
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getRequestContext,
|
|
3
3
|
runWithRequestContext
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-p1be103g.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
mergeSchemas,
|
|
8
|
-
objectShapeKeys,
|
|
9
|
-
projectToolSurface,
|
|
10
|
-
rebuildObject
|
|
6
|
+
objectShapeKeys
|
|
11
7
|
} from "./index-22by16v6.js";
|
|
12
8
|
import {
|
|
13
9
|
formatZodError,
|
|
@@ -15,15 +11,15 @@ import {
|
|
|
15
11
|
normalizeError,
|
|
16
12
|
safeJsonParse,
|
|
17
13
|
validateDeclaredOutput
|
|
18
|
-
} from "./index-
|
|
19
|
-
import {
|
|
20
|
-
isRecord
|
|
21
|
-
} from "./index-qyrqwr4c.js";
|
|
14
|
+
} from "./index-x18ndp4p.js";
|
|
22
15
|
import {
|
|
23
16
|
AppError,
|
|
24
17
|
STITCH_ERROR_STATUS,
|
|
25
18
|
isStitchErrorCode
|
|
26
19
|
} from "./index-0w9abg87.js";
|
|
20
|
+
import {
|
|
21
|
+
isRecord
|
|
22
|
+
} from "./index-qyrqwr4c.js";
|
|
27
23
|
|
|
28
24
|
// src/tools/coerce.ts
|
|
29
25
|
import { z } from "zod";
|
|
@@ -339,66 +335,4 @@ async function runToolMethod(method, toolName, rawArgs, context, hooks, lifecycl
|
|
|
339
335
|
}
|
|
340
336
|
}
|
|
341
337
|
|
|
342
|
-
|
|
343
|
-
import { z as z2 } from "zod";
|
|
344
|
-
function applyExtend(base, extra) {
|
|
345
|
-
if (base instanceof z2.ZodObject) {
|
|
346
|
-
assertToolExtensionCompatible(base, extra);
|
|
347
|
-
return rebuildObject(base, { ...extra, ...base.shape });
|
|
348
|
-
}
|
|
349
|
-
return z2.intersection(z2.object(extra), base);
|
|
350
|
-
}
|
|
351
|
-
function contractToolMountable(projected, extend) {
|
|
352
|
-
const method = projected.source;
|
|
353
|
-
const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
|
|
354
|
-
const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
|
|
355
|
-
return {
|
|
356
|
-
method,
|
|
357
|
-
name: projected.name,
|
|
358
|
-
argumentSchema,
|
|
359
|
-
presentationSchema: projected.presentationSchema,
|
|
360
|
-
shouldExtend: projected.shouldExtend
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function collectTools(service, transport, config = {}) {
|
|
364
|
-
const { extend, flattenUnionInput = false, assertNames = true } = config;
|
|
365
|
-
const tools = [];
|
|
366
|
-
for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
|
|
367
|
-
extend,
|
|
368
|
-
flattenUnionInput,
|
|
369
|
-
assertNames,
|
|
370
|
-
assertUniqueNames: false
|
|
371
|
-
})) {
|
|
372
|
-
if (projected.kind !== "contract")
|
|
373
|
-
continue;
|
|
374
|
-
tools.push(contractToolMountable(projected, extend));
|
|
375
|
-
}
|
|
376
|
-
return tools;
|
|
377
|
-
}
|
|
378
|
-
function createToolRunner(config) {
|
|
379
|
-
const extension = config.extend ? {
|
|
380
|
-
schema: z2.object(config.extend.schema),
|
|
381
|
-
resolve: config.extend.resolve
|
|
382
|
-
} : undefined;
|
|
383
|
-
return async function runOneToolCall(tool, rawArgs, context) {
|
|
384
|
-
return executeToolMethod(tool.method, tool.name, rawArgs, { ...config.context, ...context, source: config.source }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined, tool.shouldExtend ? extension : undefined);
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
function formatToolError(result, toolName, errorHint) {
|
|
388
|
-
const err = { error: result.code };
|
|
389
|
-
if (result.details)
|
|
390
|
-
err.details = result.details;
|
|
391
|
-
const hints = [];
|
|
392
|
-
if (result.hint)
|
|
393
|
-
hints.push(result.hint);
|
|
394
|
-
if (errorHint && toolName) {
|
|
395
|
-
const global = errorHint(toolName, result.code);
|
|
396
|
-
if (global)
|
|
397
|
-
hints.push(global);
|
|
398
|
-
}
|
|
399
|
-
if (hints.length > 0)
|
|
400
|
-
err._hint = hints.join(" ");
|
|
401
|
-
return err;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod, contractToolMountable, collectTools, createToolRunner, formatToolError };
|
|
338
|
+
export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assistantStatus
|
|
3
|
+
} from "./index-es0h4w26.js";
|
|
1
4
|
import {
|
|
2
5
|
AgentMessageSchema,
|
|
3
6
|
AgentRecordIdSchema,
|
|
@@ -7,21 +10,39 @@ import {
|
|
|
7
10
|
AgentTerminalReasonSchema,
|
|
8
11
|
AgentUsageSchema,
|
|
9
12
|
runStateForTerminalReason
|
|
10
|
-
} from "./index-
|
|
13
|
+
} from "./index-x1th9s8c.js";
|
|
11
14
|
|
|
12
|
-
// src/agent-runtime/
|
|
15
|
+
// src/agent-runtime/conversations.ts
|
|
13
16
|
import { z } from "zod";
|
|
14
|
-
var
|
|
15
|
-
|
|
17
|
+
var AgentConversationSummarySchema = z.object({
|
|
18
|
+
conversationId: AgentRecordIdSchema,
|
|
19
|
+
version: AgentRecordVersionSchema,
|
|
20
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
21
|
+
preview: z.string(),
|
|
22
|
+
activeRuns: z.int().nonnegative()
|
|
23
|
+
}).strict();
|
|
24
|
+
var AgentConversationPageSchema = z.object({
|
|
25
|
+
items: z.array(AgentConversationSummarySchema),
|
|
26
|
+
nextCursor: z.string().min(1).optional()
|
|
27
|
+
}).strict();
|
|
28
|
+
var AgentConversationMessagePageSchema = z.object({
|
|
29
|
+
items: z.array(AgentMessageSchema),
|
|
30
|
+
nextCursor: z.string().min(1).optional()
|
|
31
|
+
}).strict();
|
|
32
|
+
|
|
33
|
+
// src/agent-runtime/store.ts
|
|
34
|
+
import { z as z2 } from "zod";
|
|
35
|
+
var AgentStoreConflictSchema = z2.object({
|
|
36
|
+
outcome: z2.literal("conflict"),
|
|
16
37
|
actualVersion: AgentRecordVersionSchema
|
|
17
38
|
});
|
|
18
|
-
var AgentStoreNotFoundSchema =
|
|
19
|
-
var AgentStoreAppliedSchema =
|
|
20
|
-
outcome:
|
|
39
|
+
var AgentStoreNotFoundSchema = z2.object({ outcome: z2.literal("not_found") });
|
|
40
|
+
var AgentStoreAppliedSchema = z2.object({
|
|
41
|
+
outcome: z2.literal("applied"),
|
|
21
42
|
snapshot: AgentSnapshotSchema
|
|
22
43
|
});
|
|
23
|
-
var AgentStoreDuplicateSchema =
|
|
24
|
-
outcome:
|
|
44
|
+
var AgentStoreDuplicateSchema = z2.object({
|
|
45
|
+
outcome: z2.literal("duplicate"),
|
|
25
46
|
input: AgentMessageSchema,
|
|
26
47
|
inputMessageId: AgentRecordIdSchema,
|
|
27
48
|
runId: AgentRecordIdSchema,
|
|
@@ -30,136 +51,116 @@ var AgentStoreDuplicateSchema = z.object({
|
|
|
30
51
|
assistant: AgentMessageSchema.optional(),
|
|
31
52
|
snapshot: AgentSnapshotSchema
|
|
32
53
|
});
|
|
33
|
-
var AgentStoreMutationResultSchema =
|
|
54
|
+
var AgentStoreMutationResultSchema = z2.discriminatedUnion("outcome", [
|
|
34
55
|
AgentStoreAppliedSchema,
|
|
35
56
|
AgentStoreDuplicateSchema,
|
|
36
57
|
AgentStoreConflictSchema,
|
|
37
58
|
AgentStoreNotFoundSchema
|
|
38
59
|
]);
|
|
39
|
-
var AgentRunViewSchema =
|
|
60
|
+
var AgentRunViewSchema = z2.object({
|
|
40
61
|
snapshotVersion: AgentRecordVersionSchema,
|
|
41
62
|
run: AgentRunSchema,
|
|
42
63
|
assistant: AgentMessageSchema.optional()
|
|
43
64
|
});
|
|
44
|
-
var AcceptInputAndAssignRunSchema =
|
|
45
|
-
idempotencyKey:
|
|
65
|
+
var AcceptInputAndAssignRunSchema = z2.object({
|
|
66
|
+
idempotencyKey: z2.string().min(1),
|
|
46
67
|
expectedVersion: AgentRecordVersionSchema.optional(),
|
|
47
68
|
input: AgentMessageSchema,
|
|
48
69
|
run: AgentRunSchema,
|
|
49
70
|
coalesceIntoRunId: AgentRecordIdSchema.optional()
|
|
50
71
|
});
|
|
51
|
-
var AcquireAgentRunSchema =
|
|
72
|
+
var AcquireAgentRunSchema = z2.object({
|
|
52
73
|
conversationId: AgentRecordIdSchema,
|
|
53
74
|
runId: AgentRecordIdSchema,
|
|
54
75
|
expectedRevision: AgentRecordVersionSchema,
|
|
55
|
-
ownerId:
|
|
76
|
+
ownerId: z2.string().min(1)
|
|
56
77
|
});
|
|
57
|
-
var CheckpointRunAssistantSchema =
|
|
78
|
+
var CheckpointRunAssistantSchema = z2.object({
|
|
58
79
|
conversationId: AgentRecordIdSchema,
|
|
59
80
|
runId: AgentRecordIdSchema,
|
|
60
81
|
expectedRevision: AgentRecordVersionSchema,
|
|
61
|
-
ownerId:
|
|
82
|
+
ownerId: z2.string().min(1),
|
|
62
83
|
fencingToken: AgentRecordVersionSchema.optional(),
|
|
63
84
|
assistant: AgentMessageSchema,
|
|
64
85
|
usage: AgentUsageSchema.optional()
|
|
65
86
|
});
|
|
66
|
-
var CommitRunTerminalSchema =
|
|
87
|
+
var CommitRunTerminalSchema = z2.object({
|
|
67
88
|
conversationId: AgentRecordIdSchema,
|
|
68
89
|
runId: AgentRecordIdSchema,
|
|
69
90
|
expectedRevision: AgentRecordVersionSchema,
|
|
70
|
-
ownerId:
|
|
91
|
+
ownerId: z2.string().min(1),
|
|
71
92
|
fencingToken: AgentRecordVersionSchema.optional(),
|
|
72
93
|
assistant: AgentMessageSchema,
|
|
73
94
|
reason: AgentTerminalReasonSchema,
|
|
74
|
-
policyName:
|
|
95
|
+
policyName: z2.string().min(1).optional(),
|
|
75
96
|
usage: AgentUsageSchema.optional(),
|
|
76
|
-
absorb:
|
|
97
|
+
absorb: z2.array(z2.object({
|
|
77
98
|
runId: AgentRecordIdSchema,
|
|
78
|
-
inputMessageIds:
|
|
99
|
+
inputMessageIds: z2.array(AgentRecordIdSchema).min(1)
|
|
79
100
|
})).min(1).optional()
|
|
80
101
|
});
|
|
81
|
-
var RequestRunInterruptSchema =
|
|
102
|
+
var RequestRunInterruptSchema = z2.object({
|
|
82
103
|
conversationId: AgentRecordIdSchema,
|
|
83
104
|
runId: AgentRecordIdSchema,
|
|
84
105
|
expectedRevision: AgentRecordVersionSchema
|
|
85
106
|
});
|
|
86
|
-
var RecoverAgentRunSchema =
|
|
107
|
+
var RecoverAgentRunSchema = z2.object({
|
|
87
108
|
conversationId: AgentRecordIdSchema,
|
|
88
109
|
runId: AgentRecordIdSchema,
|
|
89
110
|
expectedRevision: AgentRecordVersionSchema,
|
|
90
|
-
action:
|
|
91
|
-
replaySafe:
|
|
111
|
+
action: z2.enum(["requeue", "abandon"]),
|
|
112
|
+
replaySafe: z2.boolean().optional()
|
|
92
113
|
});
|
|
93
|
-
var ReplaceCompactedRangeSchema =
|
|
114
|
+
var ReplaceCompactedRangeSchema = z2.object({
|
|
94
115
|
conversationId: AgentRecordIdSchema,
|
|
95
116
|
expectedVersion: AgentRecordVersionSchema,
|
|
96
|
-
replacedMessageIds:
|
|
117
|
+
replacedMessageIds: z2.array(AgentRecordIdSchema).min(1),
|
|
97
118
|
summary: AgentMessageSchema
|
|
98
119
|
});
|
|
120
|
+
var AgentRecoverableDescriptorSchema = z2.object({
|
|
121
|
+
conversationId: AgentRecordIdSchema,
|
|
122
|
+
run: AgentRunSchema
|
|
123
|
+
});
|
|
124
|
+
var AgentRecoverablePageSchema = z2.object({
|
|
125
|
+
items: z2.array(AgentRecoverableDescriptorSchema),
|
|
126
|
+
nextCursor: z2.string().min(1).optional()
|
|
127
|
+
});
|
|
99
128
|
|
|
100
129
|
// src/agent-runtime/store-driver.ts
|
|
101
|
-
import { z as
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
function isSpeakableAssistantStatus(status) {
|
|
105
|
-
return status === "completed" || status === "interrupted" || status === "committed";
|
|
106
|
-
}
|
|
107
|
-
function assistantStatus(reason) {
|
|
108
|
-
if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
|
|
109
|
-
return "completed";
|
|
110
|
-
}
|
|
111
|
-
if (reason === "superseded")
|
|
112
|
-
return "superseded";
|
|
113
|
-
if (reason === "absorbed")
|
|
114
|
-
return "superseded";
|
|
115
|
-
if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
|
|
116
|
-
return "interrupted";
|
|
117
|
-
}
|
|
118
|
-
return "failed";
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// src/agent-runtime/store-driver.ts
|
|
122
|
-
var AgentRuntimeHeadSchema = z2.object({
|
|
123
|
-
schemaVersion: z2.literal(1),
|
|
130
|
+
import { z as z3 } from "zod";
|
|
131
|
+
var AgentRuntimeHeadSchema = z3.object({
|
|
132
|
+
schemaVersion: z3.literal(1),
|
|
124
133
|
conversationId: AgentRecordIdSchema,
|
|
125
134
|
version: AgentRecordVersionSchema
|
|
126
135
|
});
|
|
127
|
-
var AgentStoredRunSchema =
|
|
128
|
-
schemaVersion:
|
|
136
|
+
var AgentStoredRunSchema = z3.object({
|
|
137
|
+
schemaVersion: z3.literal(1),
|
|
129
138
|
run: AgentRunSchema,
|
|
130
139
|
terminalAssistant: AgentMessageSchema.optional()
|
|
131
140
|
});
|
|
132
|
-
var AgentAdmissionReceiptSchema =
|
|
133
|
-
schemaVersion:
|
|
141
|
+
var AgentAdmissionReceiptSchema = z3.object({
|
|
142
|
+
schemaVersion: z3.literal(1),
|
|
134
143
|
conversationId: AgentRecordIdSchema,
|
|
135
|
-
idempotencyKey:
|
|
144
|
+
idempotencyKey: z3.string().min(1),
|
|
136
145
|
input: AgentMessageSchema,
|
|
137
146
|
runId: AgentRecordIdSchema,
|
|
138
147
|
assistantMessageId: AgentRecordIdSchema
|
|
139
148
|
});
|
|
140
|
-
var AgentHistoryMutationSchema =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
type:
|
|
149
|
+
var AgentHistoryMutationSchema = z3.discriminatedUnion("type", [
|
|
150
|
+
z3.object({ type: z3.literal("admit"), input: AgentMessageSchema }),
|
|
151
|
+
z3.object({
|
|
152
|
+
type: z3.literal("upsert-assistant"),
|
|
144
153
|
message: AgentMessageSchema
|
|
145
154
|
}),
|
|
146
|
-
|
|
147
|
-
type:
|
|
148
|
-
replacedMessageIds:
|
|
155
|
+
z3.object({
|
|
156
|
+
type: z3.literal("replace-compacted-range"),
|
|
157
|
+
replacedMessageIds: z3.array(AgentRecordIdSchema).min(1),
|
|
149
158
|
summary: AgentMessageSchema
|
|
150
159
|
})
|
|
151
160
|
]);
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
var AgentRecoverablePageSchema = z2.object({
|
|
157
|
-
items: z2.array(AgentRecoverableDescriptorSchema),
|
|
158
|
-
nextCursor: z2.string().min(1).optional()
|
|
159
|
-
});
|
|
160
|
-
var AgentRecoverableScanInputSchema = z2.object({
|
|
161
|
-
cursor: z2.string().min(1).optional(),
|
|
162
|
-
limit: z2.number().int().min(1).max(1000)
|
|
161
|
+
var AgentRecoverableScanInputSchema = z3.object({
|
|
162
|
+
cursor: z3.string().min(1).optional(),
|
|
163
|
+
limit: z3.number().int().min(1).max(1000)
|
|
163
164
|
});
|
|
164
165
|
function emptyHead(conversationId) {
|
|
165
166
|
return AgentRuntimeHeadSchema.parse({
|
|
@@ -263,7 +264,7 @@ function validateSnapshot(head, messages, records) {
|
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
|
-
var RecoverableCursorSchema =
|
|
267
|
+
var RecoverableCursorSchema = z3.tuple([AgentRecordIdSchema, AgentRecordIdSchema]);
|
|
267
268
|
function recoverableCursor(input) {
|
|
268
269
|
return JSON.stringify([input.conversationId, input.run.id]);
|
|
269
270
|
}
|
|
@@ -313,7 +314,7 @@ function reduceStore(current, operation) {
|
|
|
313
314
|
if (input.coalesceIntoRunId !== undefined && (!coalescedRun || coalescedRun.conversationId !== input.input.conversationId || coalescedRun.state !== "queued" || coalescedRun.ownerId !== undefined || coalescedRun.terminalReason !== undefined)) {
|
|
314
315
|
return coalescedRun ? conflict(coalescedRun.revision) : { outcome: "not_found" };
|
|
315
316
|
}
|
|
316
|
-
if (input.run.conversationId !== input.input.conversationId || input.run.inputMessageIds.length !== 1 || input.run.inputMessageIds[0] !== input.input.id || input.run.state !== "queued" || input.run.revision !== 0 || input.run.executionSequence !== undefined || input.run.ownerId !== undefined || input.run.terminalReason !== undefined || input.run.terminalPolicyName !== undefined || input.input.role !== "user" || input.input.status !== "committed" || input.input.runId !== undefined || current.messages.some((message) => message.id === input.input.id) || coalescedRun !== undefined && input.input.id === coalescedRun.assistantMessageId || !coalescedRun && (input.run.assistantMessageId === input.input.id || current.runs.some((candidate) => candidate.id === input.run.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.run.assistantMessageId) || current.messages.some((message) => message.id === input.run.assistantMessageId))) {
|
|
317
|
+
if (input.run.conversationId !== input.input.conversationId || input.run.inputMessageIds.length !== 1 || input.run.inputMessageIds[0] !== input.input.id || input.run.state !== "queued" || input.run.revision !== 0 || input.run.executionSequence !== undefined || input.run.ownerId !== undefined || input.run.terminalReason !== undefined || input.run.terminalPolicyName !== undefined || input.input.role !== "user" && input.input.role !== "tool" || input.input.status !== "committed" || input.input.runId !== undefined || current.messages.some((message) => message.id === input.input.id) || coalescedRun !== undefined && input.input.id === coalescedRun.assistantMessageId || !coalescedRun && (input.run.assistantMessageId === input.input.id || current.runs.some((candidate) => candidate.id === input.run.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.run.assistantMessageId) || current.messages.some((message) => message.id === input.run.assistantMessageId))) {
|
|
317
318
|
throw new TypeError("Input and queued run do not form one valid assignment");
|
|
318
319
|
}
|
|
319
320
|
const assignedRun = coalescedRun ? AgentRunSchema.parse({
|
|
@@ -911,4 +912,4 @@ function createMemoryAgentRuntimeStore() {
|
|
|
911
912
|
return createAgentRuntimeStore(driver);
|
|
912
913
|
}
|
|
913
914
|
|
|
914
|
-
export {
|
|
915
|
+
export { AgentConversationSummarySchema, AgentConversationPageSchema, AgentConversationMessagePageSchema, AgentStoreConflictSchema, AgentStoreNotFoundSchema, AgentStoreAppliedSchema, AgentStoreDuplicateSchema, AgentStoreMutationResultSchema, AgentRunViewSchema, AcceptInputAndAssignRunSchema, AcquireAgentRunSchema, CheckpointRunAssistantSchema, CommitRunTerminalSchema, RequestRunInterruptSchema, RecoverAgentRunSchema, ReplaceCompactedRangeSchema, AgentRecoverableDescriptorSchema, AgentRecoverablePageSchema, AgentRuntimeHeadSchema, AgentStoredRunSchema, AgentAdmissionReceiptSchema, AgentHistoryMutationSchema, ACTIVE_AGENT_RUN_STATES, createAgentRuntimeStore, createMemoryAgentRuntimeStore };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeToolMethod
|
|
3
|
+
} from "./index-h8vn1jcr.js";
|
|
4
|
+
import {
|
|
5
|
+
assertToolExtensionCompatible,
|
|
6
|
+
mergeSchemas,
|
|
7
|
+
projectToolSurface,
|
|
8
|
+
rebuildObject
|
|
9
|
+
} from "./index-22by16v6.js";
|
|
10
|
+
|
|
11
|
+
// src/tools/mount.ts
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
function applyExtend(base, extra) {
|
|
14
|
+
if (base instanceof z.ZodObject) {
|
|
15
|
+
assertToolExtensionCompatible(base, extra);
|
|
16
|
+
return rebuildObject(base, { ...extra, ...base.shape });
|
|
17
|
+
}
|
|
18
|
+
return z.intersection(z.object(extra), base);
|
|
19
|
+
}
|
|
20
|
+
function contractToolMountable(projected, extend) {
|
|
21
|
+
const method = projected.source;
|
|
22
|
+
const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
|
|
23
|
+
const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
|
|
24
|
+
return {
|
|
25
|
+
method,
|
|
26
|
+
name: projected.name,
|
|
27
|
+
argumentSchema,
|
|
28
|
+
presentationSchema: projected.presentationSchema,
|
|
29
|
+
shouldExtend: projected.shouldExtend
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function collectTools(service, transport, config = {}) {
|
|
33
|
+
const { extend, flattenUnionInput = false, assertNames = true } = config;
|
|
34
|
+
const tools = [];
|
|
35
|
+
for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
|
|
36
|
+
extend,
|
|
37
|
+
flattenUnionInput,
|
|
38
|
+
assertNames,
|
|
39
|
+
assertUniqueNames: false
|
|
40
|
+
})) {
|
|
41
|
+
if (projected.kind !== "contract")
|
|
42
|
+
continue;
|
|
43
|
+
tools.push(contractToolMountable(projected, extend));
|
|
44
|
+
}
|
|
45
|
+
return tools;
|
|
46
|
+
}
|
|
47
|
+
function createToolRunner(config) {
|
|
48
|
+
const extension = config.extend ? {
|
|
49
|
+
schema: z.object(config.extend.schema),
|
|
50
|
+
resolve: config.extend.resolve
|
|
51
|
+
} : undefined;
|
|
52
|
+
return async function runOneToolCall(tool, rawArgs, context) {
|
|
53
|
+
return executeToolMethod(tool.method, tool.name, rawArgs, { ...config.context, ...context, source: config.source }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined, tool.shouldExtend ? extension : undefined);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function formatToolError(result, toolName, errorHint) {
|
|
57
|
+
const err = { error: result.code };
|
|
58
|
+
if (result.details)
|
|
59
|
+
err.details = result.details;
|
|
60
|
+
const hints = [];
|
|
61
|
+
if (result.hint)
|
|
62
|
+
hints.push(result.hint);
|
|
63
|
+
if (errorHint && toolName) {
|
|
64
|
+
const global = errorHint(toolName, result.code);
|
|
65
|
+
if (global)
|
|
66
|
+
hints.push(global);
|
|
67
|
+
}
|
|
68
|
+
if (hints.length > 0)
|
|
69
|
+
err._hint = hints.join(" ");
|
|
70
|
+
return err;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { contractToolMountable, collectTools, createToolRunner, formatToolError };
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
inputIsQuery,
|
|
4
4
|
parseSSE,
|
|
5
5
|
readBoundedUtf8Lines
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-t4dpby6e.js";
|
|
7
7
|
import {
|
|
8
8
|
ContractStreamFrameSchema,
|
|
9
9
|
DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
|
|
10
10
|
parseTrailingWildcard
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-x18ndp4p.js";
|
|
12
12
|
import {
|
|
13
13
|
isRecord,
|
|
14
14
|
mapObject,
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectToolSurface
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-xxsq3ca1.js";
|
|
4
4
|
import {
|
|
5
|
-
coerceJsonArgs,
|
|
6
5
|
createToolRunner,
|
|
7
|
-
formatToolError
|
|
6
|
+
formatToolError
|
|
7
|
+
} from "./index-kg9xx84n.js";
|
|
8
|
+
import {
|
|
9
|
+
coerceJsonArgs,
|
|
8
10
|
toolResultFromError
|
|
9
|
-
} from "./index-
|
|
11
|
+
} from "./index-h8vn1jcr.js";
|
|
10
12
|
import {
|
|
11
13
|
isWithinDir
|
|
12
14
|
} from "./index-sbdmyz75.js";
|
|
@@ -23,7 +25,7 @@ import {
|
|
|
23
25
|
isUnsafeKey,
|
|
24
26
|
safeJsonParse,
|
|
25
27
|
validateDeclaredOutput
|
|
26
|
-
} from "./index-
|
|
28
|
+
} from "./index-x18ndp4p.js";
|
|
27
29
|
import {
|
|
28
30
|
isRecord
|
|
29
31
|
} from "./index-qyrqwr4c.js";
|