stitchkit 0.68.9 → 0.68.10
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/dist/agent-runtime/deferred-tool-search.d.ts +8 -0
- package/dist/agent-runtime/deferred-tool-search.d.ts.map +1 -0
- package/dist/agent-runtime/deferred-tool-selection.d.ts +15 -0
- package/dist/agent-runtime/deferred-tool-selection.d.ts.map +1 -0
- package/dist/agent-runtime/deferred-tool-types.d.ts +131 -0
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -0
- package/dist/agent-runtime/deferred-tools-internal.d.ts +10 -0
- package/dist/agent-runtime/deferred-tools-internal.d.ts.map +1 -0
- package/dist/agent-runtime/deferred-tools.d.ts +4 -0
- package/dist/agent-runtime/deferred-tools.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime-openrouter.js +1 -1
- package/dist/agent-runtime.d.ts +1 -0
- package/dist/agent-runtime.d.ts.map +1 -1
- package/dist/agent-runtime.js +471 -73
- package/dist/cli.js +7 -8
- package/dist/contract/index.js +2 -2
- package/dist/{index-vkk06pv1.js → index-22by16v6.js} +57 -9
- package/dist/{index-hmfpjnh7.js → index-22tjt2rk.js} +2 -2
- package/dist/{index-1bmpkhj2.js → index-2t6zt5cg.js} +9 -134
- package/dist/index-bt5179zb.js +99 -0
- package/dist/index-eqqyd9v8.js +130 -0
- package/dist/{index-51a19y3v.js → index-f24xg2cw.js} +2 -2
- package/dist/{index-j2nq04z6.js → index-f6n5n7nz.js} +1 -1
- package/dist/{index-9t2tdk1x.js → index-grgvpbch.js} +3 -5
- package/dist/{index-n34x0q5e.js → index-hb0mncmj.js} +3 -3
- package/dist/{index-6tqys26z.js → index-hcx9yypn.js} +4 -4
- package/dist/{index-z575awm9.js → index-hxh98zbm.js} +2 -2
- package/dist/{index-bmmtz6r9.js → index-pgsyp3xh.js} +1 -1
- package/dist/index-qyrqwr4c.js +41 -0
- package/dist/{index-r5s4wqb5.js → index-t23p2b68.js} +1 -1
- package/dist/{index-3ydx9j01.js → index-xyvxez9r.js} +3 -3
- package/dist/{index-04agqrs8.js → index-y2ctppmg.js} +72 -6
- package/dist/index.js +2 -2
- package/dist/internal/typed.d.ts +8 -0
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/node.js +5 -5
- package/dist/observability/index.js +4 -4
- package/dist/react.js +1 -1
- package/dist/remote.js +4 -4
- package/dist/server/index.js +7 -7
- package/dist/testing.js +5 -6
- package/dist/tool-invoker.js +6 -8
- package/dist/tools/internal/surface-projector.d.ts +7 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools.js +34 -115
- package/llms-full.txt +80 -1
- package/package.json +1 -1
- package/dist/index-6djpbnda.js +0 -56
- package/dist/index-88yyydag.js +0 -75
- package/dist/index-smpbdg6k.js +0 -27
- /package/dist/{index-tss6bk5c.js → index-ksp6e2ye.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -5,16 +5,15 @@ import {
|
|
|
5
5
|
emitResult,
|
|
6
6
|
parseCliArgs,
|
|
7
7
|
pollUntilDone
|
|
8
|
-
} from "./index-
|
|
9
|
-
import"./index-
|
|
10
|
-
import"./index-
|
|
11
|
-
import"./index-
|
|
8
|
+
} from "./index-2t6zt5cg.js";
|
|
9
|
+
import"./index-eqqyd9v8.js";
|
|
10
|
+
import"./index-y2ctppmg.js";
|
|
11
|
+
import"./index-f24xg2cw.js";
|
|
12
12
|
import"./index-sbdmyz75.js";
|
|
13
|
-
import"./index-
|
|
14
|
-
import"./index-6djpbnda.js";
|
|
13
|
+
import"./index-22by16v6.js";
|
|
15
14
|
import"./index-cby4ar3v.js";
|
|
16
|
-
import"./index-
|
|
17
|
-
import"./index-
|
|
15
|
+
import"./index-pgsyp3xh.js";
|
|
16
|
+
import"./index-qyrqwr4c.js";
|
|
18
17
|
import"./index-0w9abg87.js";
|
|
19
18
|
import"./index-6k1937bx.js";
|
|
20
19
|
export {
|
package/dist/contract/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
mergeSchemas
|
|
3
|
-
} from "./index-6djpbnda.js";
|
|
4
1
|
import {
|
|
5
2
|
toJsonSchema
|
|
6
3
|
} from "./index-cby4ar3v.js";
|
|
7
4
|
import {
|
|
8
5
|
isRecord
|
|
9
|
-
} from "./index-
|
|
6
|
+
} from "./index-qyrqwr4c.js";
|
|
10
7
|
|
|
11
8
|
// src/tools/portable-formats.ts
|
|
12
9
|
var PORTABLE_JSON_SCHEMA_FORMATS = new Set([
|
|
@@ -552,6 +549,57 @@ function findUntypedProperties(schema, prefix = "") {
|
|
|
552
549
|
return found;
|
|
553
550
|
}
|
|
554
551
|
|
|
552
|
+
// src/tools/schema.ts
|
|
553
|
+
import { z } from "zod";
|
|
554
|
+
function objectShapeKeys(schema) {
|
|
555
|
+
return schema instanceof z.ZodObject ? Object.keys(schema.shape) : [];
|
|
556
|
+
}
|
|
557
|
+
function keyPolicyOf(schema) {
|
|
558
|
+
return schema.def.catchall;
|
|
559
|
+
}
|
|
560
|
+
function rebuildObject(source, shape) {
|
|
561
|
+
return withKeyPolicy(z.object(shape), keyPolicyOf(source));
|
|
562
|
+
}
|
|
563
|
+
function withKeyPolicy(object, policy) {
|
|
564
|
+
if (policy === undefined)
|
|
565
|
+
return object;
|
|
566
|
+
return object.catchall(representable(policy));
|
|
567
|
+
}
|
|
568
|
+
function representable(policy) {
|
|
569
|
+
if (policy instanceof z.ZodNever || policy instanceof z.ZodUnknown)
|
|
570
|
+
return policy;
|
|
571
|
+
if (!(policy instanceof z.ZodType))
|
|
572
|
+
return z.unknown();
|
|
573
|
+
try {
|
|
574
|
+
toJsonSchema(policy, "input");
|
|
575
|
+
return policy;
|
|
576
|
+
} catch {
|
|
577
|
+
return z.unknown();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
function mergeSchemas(paramsSchema, inputSchema) {
|
|
581
|
+
if (paramsSchema && !(paramsSchema instanceof z.ZodObject)) {
|
|
582
|
+
throw new Error("Tool params schema must be a z.object()");
|
|
583
|
+
}
|
|
584
|
+
const paramsObject = paramsSchema instanceof z.ZodObject ? paramsSchema : undefined;
|
|
585
|
+
if (!inputSchema) {
|
|
586
|
+
return paramsObject ?? z.object({});
|
|
587
|
+
}
|
|
588
|
+
if (inputSchema instanceof z.ZodObject) {
|
|
589
|
+
if (paramsObject) {
|
|
590
|
+
const conflicts = Object.keys(paramsObject.shape).filter((key) => (key in inputSchema.shape));
|
|
591
|
+
if (conflicts.length > 0) {
|
|
592
|
+
throw new Error(`Schema merge conflict: ${conflicts.join(", ")} appear in both params and input`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return rebuildObject(inputSchema, {
|
|
596
|
+
...paramsObject?.shape ?? {},
|
|
597
|
+
...inputSchema.shape
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
return paramsObject ? z.intersection(paramsObject, inputSchema) : inputSchema;
|
|
601
|
+
}
|
|
602
|
+
|
|
555
603
|
// src/tools/names.ts
|
|
556
604
|
var SINGULAR_EXCEPTIONS = new Set([
|
|
557
605
|
"analytics",
|
|
@@ -618,7 +666,7 @@ function assertUniqueToolName(name, taken, surface) {
|
|
|
618
666
|
}
|
|
619
667
|
|
|
620
668
|
// src/tools/presentation.ts
|
|
621
|
-
import { z } from "zod";
|
|
669
|
+
import { z as z2 } from "zod";
|
|
622
670
|
function withoutDialect(schema) {
|
|
623
671
|
const result = {};
|
|
624
672
|
for (const [key, value] of Object.entries(schema)) {
|
|
@@ -712,7 +760,7 @@ function buildToolPresentationSchema(config) {
|
|
|
712
760
|
};
|
|
713
761
|
}
|
|
714
762
|
if (config.extendSchema) {
|
|
715
|
-
const extra = namespaceLocalReferences(schemaFromZod(
|
|
763
|
+
const extra = namespaceLocalReferences(schemaFromZod(z2.object(config.extendSchema), unrepresentable, flatten), "extend");
|
|
716
764
|
if (extra) {
|
|
717
765
|
presentation = mergeObjectSchemas(withoutDialect(extra), withoutDialect(presentation), true);
|
|
718
766
|
}
|
|
@@ -733,7 +781,7 @@ function presentationMetadata(schema) {
|
|
|
733
781
|
}
|
|
734
782
|
|
|
735
783
|
// src/tools/internal/surface-projector.ts
|
|
736
|
-
import { z as
|
|
784
|
+
import { z as z3 } from "zod";
|
|
737
785
|
|
|
738
786
|
// src/tools/mcp-round-policy.ts
|
|
739
787
|
function validateMcpRoundPolicy(tool, policy, runtime) {
|
|
@@ -761,7 +809,7 @@ function validateMcpRoundPolicy(tool, policy, runtime) {
|
|
|
761
809
|
|
|
762
810
|
// src/tools/internal/surface-projector.ts
|
|
763
811
|
function assertToolExtensionCompatible(base, extra) {
|
|
764
|
-
if (!(base instanceof
|
|
812
|
+
if (!(base instanceof z3.ZodObject))
|
|
765
813
|
return;
|
|
766
814
|
const conflicts = Object.keys(extra).filter((key) => (key in base.shape));
|
|
767
815
|
if (conflicts.length > 0) {
|
|
@@ -972,4 +1020,4 @@ function prepareProjectedMcpTools(tools, config = {}) {
|
|
|
972
1020
|
return prepared;
|
|
973
1021
|
}
|
|
974
1022
|
|
|
975
|
-
export { validateMcpRoundPolicy, assertToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS, findNonPortableFormats, flattenToolJsonSchema, buildToolPresentationSchema, presentationMetadata, findUntypedProperties, assertToolExtensionCompatible, projectRuntimeTool, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
|
|
1023
|
+
export { objectShapeKeys, rebuildObject, mergeSchemas, validateMcpRoundPolicy, assertToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS, findNonPortableFormats, flattenToolJsonSchema, buildToolPresentationSchema, presentationMetadata, findUntypedProperties, assertToolExtensionCompatible, projectRuntimeTool, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
formatToolError
|
|
5
|
-
} from "./index-88yyydag.js";
|
|
2
|
+
collectToolSurface
|
|
3
|
+
} from "./index-eqqyd9v8.js";
|
|
6
4
|
import {
|
|
7
5
|
coerceJsonArgs,
|
|
6
|
+
createToolRunner,
|
|
7
|
+
formatToolError,
|
|
8
8
|
toolResultFromError
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-y2ctppmg.js";
|
|
10
10
|
import {
|
|
11
11
|
isWithinDir
|
|
12
12
|
} from "./index-sbdmyz75.js";
|
|
13
13
|
import {
|
|
14
14
|
assertUniqueToolName,
|
|
15
15
|
buildToolPresentationSchema,
|
|
16
|
-
projectRuntimeTool,
|
|
17
|
-
projectToolSurface
|
|
18
|
-
} from "./index-vkk06pv1.js";
|
|
19
|
-
import {
|
|
20
16
|
objectShapeKeys
|
|
21
|
-
} from "./index-
|
|
17
|
+
} from "./index-22by16v6.js";
|
|
22
18
|
import {
|
|
23
19
|
jsonSchemaFields
|
|
24
20
|
} from "./index-cby4ar3v.js";
|
|
@@ -27,91 +23,10 @@ import {
|
|
|
27
23
|
isUnsafeKey,
|
|
28
24
|
safeJsonParse,
|
|
29
25
|
validateDeclaredOutput
|
|
30
|
-
} from "./index-
|
|
26
|
+
} from "./index-pgsyp3xh.js";
|
|
31
27
|
import {
|
|
32
28
|
isRecord
|
|
33
|
-
} from "./index-
|
|
34
|
-
|
|
35
|
-
// src/tools/runtime-tool.ts
|
|
36
|
-
function defineRuntimeTool(definition) {
|
|
37
|
-
if (definition.transports?.length === 0) {
|
|
38
|
-
throw new Error(`Runtime tool "${definition.name}" must expose at least one transport`);
|
|
39
|
-
}
|
|
40
|
-
return definition;
|
|
41
|
-
}
|
|
42
|
-
function createRuntimeToolFactory(config) {
|
|
43
|
-
function parseContext(context) {
|
|
44
|
-
const parsed = config.context.parse(context);
|
|
45
|
-
return {
|
|
46
|
-
...context,
|
|
47
|
-
...parsed,
|
|
48
|
-
params: undefined,
|
|
49
|
-
input: context.input,
|
|
50
|
-
...context.mcp !== undefined && { mcp: context.mcp }
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function define(definition) {
|
|
54
|
-
if (definition.output !== undefined) {
|
|
55
|
-
const { action: action2, method: method2, meta: meta2, handler: handler2, ...tool2 } = definition;
|
|
56
|
-
const identity2 = {
|
|
57
|
-
serviceName: config.serviceName,
|
|
58
|
-
action: action2,
|
|
59
|
-
method: method2,
|
|
60
|
-
...config.scope !== undefined && { scope: config.scope },
|
|
61
|
-
...(meta2 ?? config.meta) !== undefined && { meta: meta2 ?? config.meta }
|
|
62
|
-
};
|
|
63
|
-
return defineRuntimeTool({
|
|
64
|
-
...tool2,
|
|
65
|
-
identity: identity2,
|
|
66
|
-
handler: (context) => handler2(parseContext(context))
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
const { action, method, meta, handler, ...tool } = definition;
|
|
70
|
-
const identity = {
|
|
71
|
-
serviceName: config.serviceName,
|
|
72
|
-
action,
|
|
73
|
-
method,
|
|
74
|
-
...config.scope !== undefined && { scope: config.scope },
|
|
75
|
-
...(meta ?? config.meta) !== undefined && { meta: meta ?? config.meta }
|
|
76
|
-
};
|
|
77
|
-
return defineRuntimeTool({
|
|
78
|
-
...tool,
|
|
79
|
-
identity,
|
|
80
|
-
handler: (context) => handler(parseContext(context))
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return { define };
|
|
84
|
-
}
|
|
85
|
-
function runtimeToolIdentity(definition) {
|
|
86
|
-
return {
|
|
87
|
-
method: definition.identity.method,
|
|
88
|
-
desc: definition.description,
|
|
89
|
-
serviceName: definition.identity.serviceName,
|
|
90
|
-
key: definition.identity.action,
|
|
91
|
-
toolName: definition.name,
|
|
92
|
-
scope: definition.identity.scope,
|
|
93
|
-
meta: definition.identity.meta,
|
|
94
|
-
annotations: definition.annotations,
|
|
95
|
-
ui: definition.ui,
|
|
96
|
-
mcp: definition.mcp
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function runtimeToolMountable(definition, assertName = true) {
|
|
100
|
-
const projected = projectRuntimeTool(definition, assertName);
|
|
101
|
-
const method = {
|
|
102
|
-
...runtimeToolIdentity(definition),
|
|
103
|
-
inputSchema: definition.input,
|
|
104
|
-
outputSchema: definition.output,
|
|
105
|
-
handler: definition.handler
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
method,
|
|
109
|
-
name: projected.name,
|
|
110
|
-
argumentSchema: definition.input,
|
|
111
|
-
presentationSchema: projected.presentationSchema,
|
|
112
|
-
shouldExtend: false
|
|
113
|
-
};
|
|
114
|
-
}
|
|
29
|
+
} from "./index-qyrqwr4c.js";
|
|
115
30
|
|
|
116
31
|
// src/tools/cli-args.ts
|
|
117
32
|
import { z } from "zod";
|
|
@@ -1193,46 +1108,6 @@ function assertCliPoliciesResolved(commands, config) {
|
|
|
1193
1108
|
}
|
|
1194
1109
|
}
|
|
1195
1110
|
|
|
1196
|
-
// src/tools/surface.ts
|
|
1197
|
-
function collectToolSurface({
|
|
1198
|
-
surface,
|
|
1199
|
-
transport,
|
|
1200
|
-
assertUniqueNames = true,
|
|
1201
|
-
...collectConfig
|
|
1202
|
-
}) {
|
|
1203
|
-
const entries = [];
|
|
1204
|
-
const append = (entry) => {
|
|
1205
|
-
entries.push(entry);
|
|
1206
|
-
};
|
|
1207
|
-
for (const projected of projectToolSurface(surface, transport, {
|
|
1208
|
-
extend: collectConfig.extend,
|
|
1209
|
-
flattenUnionInput: collectConfig.flattenUnionInput,
|
|
1210
|
-
assertNames: collectConfig.assertNames,
|
|
1211
|
-
assertUniqueNames
|
|
1212
|
-
})) {
|
|
1213
|
-
if (projected.kind === "contract") {
|
|
1214
|
-
const mountable = contractToolMountable(projected, collectConfig.extend);
|
|
1215
|
-
append({
|
|
1216
|
-
kind: "contract",
|
|
1217
|
-
service: projected.serviceName,
|
|
1218
|
-
action: mountable.method.key,
|
|
1219
|
-
mountable,
|
|
1220
|
-
projection: projected
|
|
1221
|
-
});
|
|
1222
|
-
} else {
|
|
1223
|
-
append({
|
|
1224
|
-
kind: "runtime",
|
|
1225
|
-
service: projected.serviceName,
|
|
1226
|
-
action: projected.action,
|
|
1227
|
-
mountable: runtimeToolMountable(projected.source, false),
|
|
1228
|
-
definition: projected.source,
|
|
1229
|
-
projection: projected
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
return entries;
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
1111
|
// src/tools/cli.ts
|
|
1237
1112
|
var GLOBAL_OPTIONS = [
|
|
1238
1113
|
["--json", "Emit compact success/error JSON records (for scripts)"],
|
|
@@ -1674,4 +1549,4 @@ async function createCli(config) {
|
|
|
1674
1549
|
return exit(downloadsOk ? exitCode : 1);
|
|
1675
1550
|
}
|
|
1676
1551
|
|
|
1677
|
-
export {
|
|
1552
|
+
export { WaitTimeoutError, runWaitOperation, fetchGuarded, fetchPinnedDocument, readCapped, parseCliArgs, defineCliCommand, DEFAULT_EXIT_CODES, emitResult, pollUntilDone, createCli };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectToolSurface
|
|
3
|
+
} from "./index-eqqyd9v8.js";
|
|
4
|
+
import {
|
|
5
|
+
createToolRunner,
|
|
6
|
+
formatToolError,
|
|
7
|
+
isToolExecutionControlError,
|
|
8
|
+
toolResultFromError
|
|
9
|
+
} from "./index-y2ctppmg.js";
|
|
10
|
+
import {
|
|
11
|
+
isRecord
|
|
12
|
+
} from "./index-qyrqwr4c.js";
|
|
13
|
+
|
|
14
|
+
// src/tools/agent.ts
|
|
15
|
+
import { jsonSchema, tool } from "ai";
|
|
16
|
+
function mountAgent(services, config = {}) {
|
|
17
|
+
const serviceList = Array.isArray(services) ? services : [services];
|
|
18
|
+
const tools = {};
|
|
19
|
+
const runTool = createToolRunner({
|
|
20
|
+
source: "agent",
|
|
21
|
+
extend: config.extend,
|
|
22
|
+
context: config.context,
|
|
23
|
+
hooks: config.hooks,
|
|
24
|
+
lifecycle: config.lifecycle,
|
|
25
|
+
errorHint: config.errorHint,
|
|
26
|
+
coerceJsonArgs: config.coerceJsonArgs,
|
|
27
|
+
onOutputStrip: config.onOutputStrip
|
|
28
|
+
});
|
|
29
|
+
for (const entry of collectToolSurface({
|
|
30
|
+
surface: { services: serviceList, runtimeTools: config.runtimeTools },
|
|
31
|
+
transport: "AGENT",
|
|
32
|
+
extend: config.extend,
|
|
33
|
+
flattenUnionInput: config.flattenUnionInput
|
|
34
|
+
})) {
|
|
35
|
+
const { mountable } = entry;
|
|
36
|
+
const inputSchema = jsonSchema(mountable.presentationSchema, {
|
|
37
|
+
validate: async (value) => isRecord(value) ? { success: true, value } : { success: false, error: new Error("Tool arguments must be an object") }
|
|
38
|
+
});
|
|
39
|
+
const execute = async (rawArgs, options) => {
|
|
40
|
+
const args = isRecord(rawArgs) ? rawArgs : {};
|
|
41
|
+
try {
|
|
42
|
+
const result = await runTool(mountable, args, { signal: options.abortSignal });
|
|
43
|
+
if (result.ok)
|
|
44
|
+
return result.data;
|
|
45
|
+
return formatToolError(result, mountable.name, config.errorHint);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (isToolExecutionControlError(err))
|
|
48
|
+
throw err;
|
|
49
|
+
return formatToolError(toolResultFromError(err), mountable.name, config.errorHint);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const presenter = entry.kind === "runtime" ? entry.definition.present?.agent : undefined;
|
|
53
|
+
if (entry.kind === "runtime" && presenter) {
|
|
54
|
+
const { definition } = entry;
|
|
55
|
+
const output = definition.output;
|
|
56
|
+
if (!output) {
|
|
57
|
+
throw new Error(`Runtime tool "${definition.name}" presenter requires an output schema`);
|
|
58
|
+
}
|
|
59
|
+
tools[definition.name] = tool({
|
|
60
|
+
description: definition.description,
|
|
61
|
+
inputSchema,
|
|
62
|
+
outputSchema: output,
|
|
63
|
+
execute,
|
|
64
|
+
toModelOutput: async ({ output: rawOutput }) => {
|
|
65
|
+
const parsed = output.safeParse(rawOutput);
|
|
66
|
+
if (!parsed.success) {
|
|
67
|
+
return { type: "text", value: JSON.stringify(rawOutput) };
|
|
68
|
+
}
|
|
69
|
+
return presenter(parsed.data);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
const output = entry.kind === "runtime" ? entry.definition.output : undefined;
|
|
74
|
+
tools[mountable.name] = tool({
|
|
75
|
+
description: mountable.method.desc,
|
|
76
|
+
inputSchema,
|
|
77
|
+
...output && { outputSchema: output },
|
|
78
|
+
execute
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return tools;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/tools/manifest.ts
|
|
86
|
+
function buildToolManifest(config) {
|
|
87
|
+
return collectToolSurface({
|
|
88
|
+
surface: config,
|
|
89
|
+
transport: config.transport,
|
|
90
|
+
extend: config.extend,
|
|
91
|
+
flattenUnionInput: config.flattenUnionInput
|
|
92
|
+
}).map(({ mountable }) => ({
|
|
93
|
+
name: mountable.name,
|
|
94
|
+
description: mountable.method.desc,
|
|
95
|
+
inputSchema: mountable.presentationSchema
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { mountAgent, buildToolManifest };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
contractToolMountable
|
|
3
|
+
} from "./index-y2ctppmg.js";
|
|
4
|
+
import {
|
|
5
|
+
projectRuntimeTool,
|
|
6
|
+
projectToolSurface
|
|
7
|
+
} from "./index-22by16v6.js";
|
|
8
|
+
|
|
9
|
+
// src/tools/runtime-tool.ts
|
|
10
|
+
function defineRuntimeTool(definition) {
|
|
11
|
+
if (definition.transports?.length === 0) {
|
|
12
|
+
throw new Error(`Runtime tool "${definition.name}" must expose at least one transport`);
|
|
13
|
+
}
|
|
14
|
+
return definition;
|
|
15
|
+
}
|
|
16
|
+
function createRuntimeToolFactory(config) {
|
|
17
|
+
function parseContext(context) {
|
|
18
|
+
const parsed = config.context.parse(context);
|
|
19
|
+
return {
|
|
20
|
+
...context,
|
|
21
|
+
...parsed,
|
|
22
|
+
params: undefined,
|
|
23
|
+
input: context.input,
|
|
24
|
+
...context.mcp !== undefined && { mcp: context.mcp }
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function define(definition) {
|
|
28
|
+
if (definition.output !== undefined) {
|
|
29
|
+
const { action: action2, method: method2, meta: meta2, handler: handler2, ...tool2 } = definition;
|
|
30
|
+
const identity2 = {
|
|
31
|
+
serviceName: config.serviceName,
|
|
32
|
+
action: action2,
|
|
33
|
+
method: method2,
|
|
34
|
+
...config.scope !== undefined && { scope: config.scope },
|
|
35
|
+
...(meta2 ?? config.meta) !== undefined && { meta: meta2 ?? config.meta }
|
|
36
|
+
};
|
|
37
|
+
return defineRuntimeTool({
|
|
38
|
+
...tool2,
|
|
39
|
+
identity: identity2,
|
|
40
|
+
handler: (context) => handler2(parseContext(context))
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const { action, method, meta, handler, ...tool } = definition;
|
|
44
|
+
const identity = {
|
|
45
|
+
serviceName: config.serviceName,
|
|
46
|
+
action,
|
|
47
|
+
method,
|
|
48
|
+
...config.scope !== undefined && { scope: config.scope },
|
|
49
|
+
...(meta ?? config.meta) !== undefined && { meta: meta ?? config.meta }
|
|
50
|
+
};
|
|
51
|
+
return defineRuntimeTool({
|
|
52
|
+
...tool,
|
|
53
|
+
identity,
|
|
54
|
+
handler: (context) => handler(parseContext(context))
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return { define };
|
|
58
|
+
}
|
|
59
|
+
function runtimeToolIdentity(definition) {
|
|
60
|
+
return {
|
|
61
|
+
method: definition.identity.method,
|
|
62
|
+
desc: definition.description,
|
|
63
|
+
serviceName: definition.identity.serviceName,
|
|
64
|
+
key: definition.identity.action,
|
|
65
|
+
toolName: definition.name,
|
|
66
|
+
scope: definition.identity.scope,
|
|
67
|
+
meta: definition.identity.meta,
|
|
68
|
+
annotations: definition.annotations,
|
|
69
|
+
ui: definition.ui,
|
|
70
|
+
mcp: definition.mcp
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function runtimeToolMountable(definition, assertName = true) {
|
|
74
|
+
const projected = projectRuntimeTool(definition, assertName);
|
|
75
|
+
const method = {
|
|
76
|
+
...runtimeToolIdentity(definition),
|
|
77
|
+
inputSchema: definition.input,
|
|
78
|
+
outputSchema: definition.output,
|
|
79
|
+
handler: definition.handler
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
method,
|
|
83
|
+
name: projected.name,
|
|
84
|
+
argumentSchema: definition.input,
|
|
85
|
+
presentationSchema: projected.presentationSchema,
|
|
86
|
+
shouldExtend: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/tools/surface.ts
|
|
91
|
+
function collectToolSurface({
|
|
92
|
+
surface,
|
|
93
|
+
transport,
|
|
94
|
+
assertUniqueNames = true,
|
|
95
|
+
...collectConfig
|
|
96
|
+
}) {
|
|
97
|
+
const entries = [];
|
|
98
|
+
const append = (entry) => {
|
|
99
|
+
entries.push(entry);
|
|
100
|
+
};
|
|
101
|
+
for (const projected of projectToolSurface(surface, transport, {
|
|
102
|
+
extend: collectConfig.extend,
|
|
103
|
+
flattenUnionInput: collectConfig.flattenUnionInput,
|
|
104
|
+
assertNames: collectConfig.assertNames,
|
|
105
|
+
assertUniqueNames
|
|
106
|
+
})) {
|
|
107
|
+
if (projected.kind === "contract") {
|
|
108
|
+
const mountable = contractToolMountable(projected, collectConfig.extend);
|
|
109
|
+
append({
|
|
110
|
+
kind: "contract",
|
|
111
|
+
service: projected.serviceName,
|
|
112
|
+
action: mountable.method.key,
|
|
113
|
+
mountable,
|
|
114
|
+
projection: projected
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
append({
|
|
118
|
+
kind: "runtime",
|
|
119
|
+
service: projected.serviceName,
|
|
120
|
+
action: projected.action,
|
|
121
|
+
mountable: runtimeToolMountable(projected.source, false),
|
|
122
|
+
definition: projected.source,
|
|
123
|
+
projection: projected
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return entries;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { defineRuntimeTool, createRuntimeToolFactory, collectToolSurface };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isUnsafeKey,
|
|
3
3
|
resolveTraceContext
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-pgsyp3xh.js";
|
|
5
5
|
import {
|
|
6
6
|
isRecord
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-qyrqwr4c.js";
|
|
8
8
|
|
|
9
9
|
// src/server/request.ts
|
|
10
10
|
function generateTraceId() {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectTools,
|
|
3
|
-
createToolRunner
|
|
4
|
-
} from "./index-88yyydag.js";
|
|
5
|
-
import {
|
|
3
|
+
createToolRunner,
|
|
6
4
|
toolErrorFromResult
|
|
7
|
-
} from "./index-
|
|
5
|
+
} from "./index-y2ctppmg.js";
|
|
8
6
|
import {
|
|
9
7
|
assertUniqueToolName
|
|
10
|
-
} from "./index-
|
|
8
|
+
} from "./index-22by16v6.js";
|
|
11
9
|
import {
|
|
12
10
|
AppError
|
|
13
11
|
} from "./index-0w9abg87.js";
|
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
inputIsQuery,
|
|
4
4
|
parseSSE,
|
|
5
5
|
readBoundedUtf8Lines
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-t23p2b68.js";
|
|
7
7
|
import {
|
|
8
8
|
ContractStreamFrameSchema,
|
|
9
9
|
DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
|
|
10
10
|
parseTrailingWildcard
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-pgsyp3xh.js";
|
|
12
12
|
import {
|
|
13
13
|
isRecord,
|
|
14
14
|
mapObject,
|
|
15
15
|
typedEntries
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-qyrqwr4c.js";
|
|
17
17
|
|
|
18
18
|
// src/browser/cancellation.ts
|
|
19
19
|
class RequestCancellationError extends Error {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
defaultSignalSource,
|
|
8
8
|
guardSignalCallback,
|
|
9
9
|
reportSignalError
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-hxh98zbm.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-f24xg2cw.js";
|
|
22
22
|
import {
|
|
23
23
|
ShutdownOptionsSchema
|
|
24
24
|
} from "./index-dk6e56g0.js";
|
|
@@ -34,11 +34,11 @@ import {
|
|
|
34
34
|
safeJsonParse,
|
|
35
35
|
validateDeclaredOutput,
|
|
36
36
|
zodIssues
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-pgsyp3xh.js";
|
|
38
38
|
import {
|
|
39
39
|
isRecord,
|
|
40
40
|
transportResult
|
|
41
|
-
} from "./index-
|
|
41
|
+
} from "./index-qyrqwr4c.js";
|
|
42
42
|
import {
|
|
43
43
|
AppError,
|
|
44
44
|
badRequest
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isUnsafeKey,
|
|
3
3
|
mergeMeta
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-pgsyp3xh.js";
|
|
5
5
|
import {
|
|
6
6
|
callRuntimeHandler,
|
|
7
7
|
isRecord,
|
|
8
8
|
transportResult,
|
|
9
9
|
typedEntries
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-qyrqwr4c.js";
|
|
11
11
|
|
|
12
12
|
// src/server/middleware/cors.ts
|
|
13
13
|
var DEFAULT_CORS_ALLOW_HEADERS = "Content-Type, Authorization, X-Trace-Id, traceparent, tracestate";
|