stitchkit 0.12.0 → 0.14.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/dist/cli.js +2 -2
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/{index-eyc38rgc.js → index-2adzh3ct.js} +37 -4
- package/dist/{index-kb7wxdq0.js → index-6k6y7wat.js} +1 -1
- package/dist/{index-fq89tdex.js → index-ktn76xz0.js} +4 -1
- package/dist/{index-msmy8ydw.js → index-yv93m4yr.js} +1 -1
- package/dist/{index-eq29zkrx.js → index-yzac2zbh.js} +4 -1
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/dist/server/index.js +3 -3
- package/dist/tools/flatten.d.ts +16 -0
- package/dist/tools/flatten.d.ts.map +1 -1
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +5 -3
- package/llms-full.txt +23 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
emitResult,
|
|
5
5
|
parseCliArgs,
|
|
6
6
|
pollUntilDone
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-2adzh3ct.js";
|
|
8
8
|
import"./index-0ed3bx43.js";
|
|
9
|
-
import"./index-
|
|
9
|
+
import"./index-ktn76xz0.js";
|
|
10
10
|
import"./index-tm7dqzxc.js";
|
|
11
11
|
export {
|
|
12
12
|
pollUntilDone,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/contract/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,2CAA2C;QAC3C,IAAI,EAAE,MAAM,CAAC;QACb,8BAA8B;QAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,gCAAgC;QA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AgB,SAAS,CAAC,OAAO,SAAc,GAAG,KAAK,CAEtD;AAED,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,OAAO,SAAa,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAEvF;AAED,wCAAwC;AACxC,wBAAgB,WAAW,CAAC,OAAO,SAAsB,GAAG,KAAK,CAEhE;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;CAUE,CAAC;AAEnC,mFAAmF;AACnF,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAE/D,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAEvE;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,KAAK,CAOP"}
|
package/dist/contract/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
isWithinDir,
|
|
8
8
|
normalizeError,
|
|
9
9
|
validateHandlerOutput
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-ktn76xz0.js";
|
|
11
11
|
import {
|
|
12
12
|
isRecord,
|
|
13
13
|
isUnsafeKey,
|
|
@@ -88,6 +88,39 @@ function flattenDiscriminatedUnion(union) {
|
|
|
88
88
|
}
|
|
89
89
|
return z2.object(shape);
|
|
90
90
|
}
|
|
91
|
+
function preserveDescription(from, to) {
|
|
92
|
+
return from.description === undefined ? to : to.describe(from.description);
|
|
93
|
+
}
|
|
94
|
+
function flattenUnionsDeep(schema) {
|
|
95
|
+
if (!(schema instanceof z2.ZodType))
|
|
96
|
+
return z2.unknown();
|
|
97
|
+
if (schema instanceof z2.ZodDiscriminatedUnion) {
|
|
98
|
+
return preserveDescription(schema, flattenUnionsDeep(flattenDiscriminatedUnion(schema)));
|
|
99
|
+
}
|
|
100
|
+
if (schema instanceof z2.ZodObject) {
|
|
101
|
+
const shape = {};
|
|
102
|
+
for (const [key, field] of Object.entries(schema.shape)) {
|
|
103
|
+
shape[key] = flattenUnionsDeep(field);
|
|
104
|
+
}
|
|
105
|
+
return preserveDescription(schema, z2.object(shape));
|
|
106
|
+
}
|
|
107
|
+
if (schema instanceof z2.ZodArray) {
|
|
108
|
+
return preserveDescription(schema, z2.array(flattenUnionsDeep(schema.element)));
|
|
109
|
+
}
|
|
110
|
+
if (schema instanceof z2.ZodOptional) {
|
|
111
|
+
return preserveDescription(schema, z2.optional(flattenUnionsDeep(schema.unwrap())));
|
|
112
|
+
}
|
|
113
|
+
if (schema instanceof z2.ZodNullable) {
|
|
114
|
+
return preserveDescription(schema, z2.nullable(flattenUnionsDeep(schema.unwrap())));
|
|
115
|
+
}
|
|
116
|
+
if (schema instanceof z2.ZodDefault) {
|
|
117
|
+
return preserveDescription(schema, flattenUnionsDeep(schema.unwrap()).default(schema.def.defaultValue));
|
|
118
|
+
}
|
|
119
|
+
if (schema instanceof z2.ZodIntersection) {
|
|
120
|
+
return preserveDescription(schema, z2.intersection(flattenUnionsDeep(schema.def.left), flattenUnionsDeep(schema.def.right)));
|
|
121
|
+
}
|
|
122
|
+
return schema;
|
|
123
|
+
}
|
|
91
124
|
|
|
92
125
|
// src/tools/mount.ts
|
|
93
126
|
import { z as z4 } from "zod";
|
|
@@ -269,8 +302,8 @@ function collectTools(service, transport, config = {}) {
|
|
|
269
302
|
continue;
|
|
270
303
|
const name = method.toolName ?? toToolName(service.name, methodName);
|
|
271
304
|
let baseSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
|
|
272
|
-
if (flattenUnionInput
|
|
273
|
-
baseSchema =
|
|
305
|
+
if (flattenUnionInput) {
|
|
306
|
+
baseSchema = flattenUnionsDeep(baseSchema);
|
|
274
307
|
}
|
|
275
308
|
const shouldExtend = !!extend && (!extend.filter || extend.filter(service, method));
|
|
276
309
|
const schema = shouldExtend && extend ? applyExtend(baseSchema, extend.schema) : baseSchema;
|
|
@@ -1000,4 +1033,4 @@ function safeInputSchema(tool) {
|
|
|
1000
1033
|
}
|
|
1001
1034
|
}
|
|
1002
1035
|
|
|
1003
|
-
export { coerceJsonArgs, toolResultFromError, flattenDiscriminatedUnion, collectTools, createToolRunner, formatToolError, fetchGuarded, readCapped, parseCliArgs, DEFAULT_EXIT_CODES, emitResult, pollUntil, pollUntilDone, createCli };
|
|
1036
|
+
export { coerceJsonArgs, toolResultFromError, flattenDiscriminatedUnion, flattenUnionsDeep, collectTools, createToolRunner, formatToolError, fetchGuarded, readCapped, parseCliArgs, DEFAULT_EXIT_CODES, emitResult, pollUntil, pollUntilDone, createCli };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// src/contract/errors.ts
|
|
2
|
+
var APP_ERROR_BRAND = Symbol.for("stitchkit.AppError");
|
|
3
|
+
|
|
2
4
|
class AppError extends Error {
|
|
3
5
|
code;
|
|
4
6
|
status;
|
|
@@ -11,9 +13,10 @@ class AppError extends Error {
|
|
|
11
13
|
this.details = details;
|
|
12
14
|
this.hint = hint;
|
|
13
15
|
this.name = "AppError";
|
|
16
|
+
Object.defineProperty(this, APP_ERROR_BRAND, { value: true });
|
|
14
17
|
}
|
|
15
18
|
static is(err) {
|
|
16
|
-
return err
|
|
19
|
+
return typeof err === "object" && err !== null && APP_ERROR_BRAND in err;
|
|
17
20
|
}
|
|
18
21
|
toJSON() {
|
|
19
22
|
return {
|
|
@@ -27,6 +27,8 @@ function defineContract(meta, endpoints) {
|
|
|
27
27
|
return { meta, endpoints };
|
|
28
28
|
}
|
|
29
29
|
// src/contract/errors.ts
|
|
30
|
+
var APP_ERROR_BRAND = Symbol.for("stitchkit.AppError");
|
|
31
|
+
|
|
30
32
|
class AppError extends Error {
|
|
31
33
|
code;
|
|
32
34
|
status;
|
|
@@ -39,9 +41,10 @@ class AppError extends Error {
|
|
|
39
41
|
this.details = details;
|
|
40
42
|
this.hint = hint;
|
|
41
43
|
this.name = "AppError";
|
|
44
|
+
Object.defineProperty(this, APP_ERROR_BRAND, { value: true });
|
|
42
45
|
}
|
|
43
46
|
static is(err) {
|
|
44
|
-
return err
|
|
47
|
+
return typeof err === "object" && err !== null && APP_ERROR_BRAND in err;
|
|
45
48
|
}
|
|
46
49
|
toJSON() {
|
|
47
50
|
return {
|
package/dist/index.js
CHANGED
package/dist/node.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
createImplement,
|
|
4
4
|
createSocketIOServer,
|
|
5
5
|
implement
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-6k6y7wat.js";
|
|
7
7
|
import {
|
|
8
8
|
AppError,
|
|
9
9
|
appError,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
notFound,
|
|
14
14
|
rateLimited,
|
|
15
15
|
unauthorized
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-ktn76xz0.js";
|
|
17
17
|
import"./index-fwqnkc90.js";
|
|
18
18
|
import"./index-tm7dqzxc.js";
|
|
19
19
|
// src/server/node.ts
|
package/dist/server/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
socketIoLane,
|
|
13
13
|
staticRoute,
|
|
14
14
|
webSocketLane
|
|
15
|
-
} from "../index-
|
|
15
|
+
} from "../index-6k6y7wat.js";
|
|
16
16
|
import {
|
|
17
17
|
createAuthHook,
|
|
18
18
|
createBearerResolver,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
signJwt,
|
|
26
26
|
verifyJwt,
|
|
27
27
|
verifyPkce
|
|
28
|
-
} from "../index-
|
|
28
|
+
} from "../index-yv93m4yr.js";
|
|
29
29
|
import {
|
|
30
30
|
jsonSchemaFields,
|
|
31
31
|
toJsonSchema
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
notFound,
|
|
43
43
|
rateLimited,
|
|
44
44
|
unauthorized
|
|
45
|
-
} from "../index-
|
|
45
|
+
} from "../index-ktn76xz0.js";
|
|
46
46
|
import {
|
|
47
47
|
extractIp,
|
|
48
48
|
generateTraceId,
|
package/dist/tools/flatten.d.ts
CHANGED
|
@@ -12,4 +12,20 @@ import { z } from 'zod';
|
|
|
12
12
|
* `executeToolMethod` — this is the advertised schema only.
|
|
13
13
|
*/
|
|
14
14
|
export declare function flattenDiscriminatedUnion(union: z.ZodDiscriminatedUnion): z.ZodObject<z.ZodRawShape>;
|
|
15
|
+
/**
|
|
16
|
+
* Recursively flatten **every** `ZodDiscriminatedUnion` in a schema — at the top
|
|
17
|
+
* level and nested inside object fields, array items and `optional` / `nullable`
|
|
18
|
+
* / `default` / intersection wrappers — so the advertised JSON Schema carries no
|
|
19
|
+
* `oneOf` / `anyOf` at any depth. `flattenDiscriminatedUnion` alone is shallow
|
|
20
|
+
* (it copies a variant's fields verbatim), so a nested union — e.g.
|
|
21
|
+
* `content.parts[]` being an array of a discriminated union — would otherwise
|
|
22
|
+
* still reach the transport as `oneOf`, which weaker models mishandle.
|
|
23
|
+
*
|
|
24
|
+
* Like the single-level flatten this is **lossy and advertised-only**: the
|
|
25
|
+
* original schemas remain the validation schemas in `executeToolMethod`. Schemas
|
|
26
|
+
* a transform cannot safely rebuild (refined / piped / lazy / plain non-
|
|
27
|
+
* discriminated unions) are left untouched — a discriminated union behind one of
|
|
28
|
+
* those keeps its `oneOf`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function flattenUnionsDeep(schema: z.core.$ZodType): z.ZodType;
|
|
15
31
|
//# sourceMappingURL=flatten.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,CAAC,CAAC,qBAAqB,GAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAkD5B"}
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,CAAC,CAAC,qBAAqB,GAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAkD5B;AAOD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,OAAO,CAwCpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/tools/mount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAKnB;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU,CACzB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAElE,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IAClC,qEAAqE;IACrE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,OA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AAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACnE,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,gBAAgB,GACvB,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAsBhF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,EAC1C,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GACjE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
|
package/dist/tools.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type { ExitCodeMap } from './tools/cli-format';
|
|
|
5
5
|
export type { CliWaitConfig } from './tools/cli-wait';
|
|
6
6
|
export { coerceJsonArgs } from './tools/coerce';
|
|
7
7
|
export type { ToolCallHooks, ToolLifecycle, ToolResult } from './tools/execute';
|
|
8
|
-
export { flattenDiscriminatedUnion } from './tools/flatten';
|
|
8
|
+
export { flattenDiscriminatedUnion, flattenUnionsDeep } from './tools/flatten';
|
|
9
9
|
export { buildToolManifest, type ToolManifestEntry } from './tools/manifest';
|
|
10
10
|
export { buildMcpServer, type IncompatibleSchemaPolicy, type McpMountConfig, type McpServerBuildConfig, mountMcp, mountMcpResource, validateMcpSchemas, } from './tools/mcp';
|
|
11
11
|
export { EXT_APPS_BUNDLE_PLACEHOLDER, inlineMcpAppBundle, type McpAppCsp, type McpAppResourceMeta, type McpResourceDef, RESOURCE_MIME_TYPE, } from './tools/mcp-app';
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAA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EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/tools.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
inputIsQuery,
|
|
3
3
|
signJwt,
|
|
4
4
|
verifyPkce
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-yv93m4yr.js";
|
|
6
6
|
import {
|
|
7
7
|
coerceJsonArgs,
|
|
8
8
|
collectTools,
|
|
@@ -10,18 +10,19 @@ import {
|
|
|
10
10
|
createToolRunner,
|
|
11
11
|
fetchGuarded,
|
|
12
12
|
flattenDiscriminatedUnion,
|
|
13
|
+
flattenUnionsDeep,
|
|
13
14
|
formatToolError,
|
|
14
15
|
pollUntil,
|
|
15
16
|
readCapped,
|
|
16
17
|
toolResultFromError
|
|
17
|
-
} from "./index-
|
|
18
|
+
} from "./index-2adzh3ct.js";
|
|
18
19
|
import {
|
|
19
20
|
toJsonSchema
|
|
20
21
|
} from "./index-0ed3bx43.js";
|
|
21
22
|
import {
|
|
22
23
|
AppError,
|
|
23
24
|
isWithinDir
|
|
24
|
-
} from "./index-
|
|
25
|
+
} from "./index-ktn76xz0.js";
|
|
25
26
|
import {
|
|
26
27
|
isRecord,
|
|
27
28
|
typedEntries
|
|
@@ -1282,6 +1283,7 @@ export {
|
|
|
1282
1283
|
mountAgent,
|
|
1283
1284
|
inlineMcpAppBundle,
|
|
1284
1285
|
implementRemote,
|
|
1286
|
+
flattenUnionsDeep,
|
|
1285
1287
|
flattenDiscriminatedUnion,
|
|
1286
1288
|
createToolkit,
|
|
1287
1289
|
createStdioMcpServer,
|
package/llms-full.txt
CHANGED
|
@@ -1148,6 +1148,23 @@ cannot become a tool. `onIncompatibleSchema` decides what happens:
|
|
|
1148
1148
|
`validateMcpSchemas(services)` runs the same check on its own — useful in a
|
|
1149
1149
|
startup assertion or a test.
|
|
1150
1150
|
|
|
1151
|
+
### Discriminated unions for weaker models — `flattenUnionInput`
|
|
1152
|
+
|
|
1153
|
+
A discriminated union in a tool's input becomes a JSON Schema `oneOf` / `anyOf`.
|
|
1154
|
+
Capable models (Claude, Gemini, GPT) handle that; weaker / cheaper ones can drop
|
|
1155
|
+
the field or mangle its strings. Set `flattenUnionInput: true` (on
|
|
1156
|
+
`createMcpHandler` / `mountMcp` / `mountAgent`) to advertise each discriminated
|
|
1157
|
+
union as a **single flat object** instead — the discriminator becomes an enum and
|
|
1158
|
+
each variant's fields become optional with a `Required if <disc> = …` hint.
|
|
1159
|
+
|
|
1160
|
+
It is **deep**: unions are flattened at every depth — top level, object fields,
|
|
1161
|
+
array items, and through `optional` / `nullable` / `default` / intersection
|
|
1162
|
+
wrappers — so no `oneOf` survives anywhere (e.g. a `content.parts[]` that is an
|
|
1163
|
+
array of a discriminated union). It is **advertised-only and lossy**: the original
|
|
1164
|
+
schemas stay the validation schemas in `executeToolMethod`, so requests are still
|
|
1165
|
+
validated against the real union. Schemas a transform cannot safely rebuild
|
|
1166
|
+
(refined / piped / lazy / plain non-discriminated unions) are left as-is.
|
|
1167
|
+
|
|
1151
1168
|
## `mountMcp`
|
|
1152
1169
|
|
|
1153
1170
|
If you already run an `McpServer` from the SDK, `mountMcp` adds contract tools
|
|
@@ -2125,6 +2142,12 @@ if (ctx.input.title.length > 200) badRequest('Title too long', { max: 200 })
|
|
|
2125
2142
|
Each helper has a `never` return type — TypeScript knows execution stops, so the
|
|
2126
2143
|
code after it is correctly narrowed.
|
|
2127
2144
|
|
|
2145
|
+
You can subclass `AppError` for a domain error model (`class FeatureLocked extends
|
|
2146
|
+
AppError`). `AppError.is(err)` identifies any instance — a direct one, a subclass,
|
|
2147
|
+
even a copy from another bundle chunk or realm — by a global brand rather than
|
|
2148
|
+
`instanceof`, so a domain error keeps its `code` / `details` / `hint` on every
|
|
2149
|
+
transport (HTTP, MCP, agent). → ADR 0032.
|
|
2150
|
+
|
|
2128
2151
|
### The error envelope
|
|
2129
2152
|
|
|
2130
2153
|
`AppError.toJSON()` renders the public envelope every transport returns:
|
package/package.json
CHANGED