@dexto/core 1.6.2 → 1.6.3
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/tools/confirmation/allowed-tools-provider/types.d.ts +1 -1
- package/package.json +2 -2
- package/dist/utils/schema-metadata.cjs +0 -235
- package/dist/utils/schema-metadata.d.ts +0 -82
- package/dist/utils/schema-metadata.d.ts.map +0 -1
- package/dist/utils/schema-metadata.js +0 -208
- package/dist/utils/user-info.cjs +0 -30
- package/dist/utils/user-info.d.ts +0 -2
- package/dist/utils/user-info.d.ts.map +0 -1
- package/dist/utils/user-info.js +0 -7
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* AllowedToolsProvider.forUser(userId)
|
|
11
11
|
*
|
|
12
12
|
* AllowedToolsProvider supports both single-user and multi-user scenarios.
|
|
13
|
-
* - If `userId` is omitted, the implementation will use a default user
|
|
13
|
+
* - If `userId` is omitted, the implementation will use a configured default user id.
|
|
14
14
|
* - For multi-user/admin scenarios, always pass `userId` explicitly.
|
|
15
15
|
* - We can enforce this by having a separate env variable/feature-flag for multi-user and having
|
|
16
16
|
* strict check for the user id if the feature flag is set.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexto/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@ai-sdk/openai-compatible": "^1.0.30",
|
|
35
35
|
"@ai-sdk/provider": "^2.0.0",
|
|
36
36
|
"@ai-sdk/xai": "^2.0.0",
|
|
37
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
38
38
|
"@openrouter/ai-sdk-provider": "^1.5.4",
|
|
39
39
|
"@opentelemetry/api": "^1.9.0",
|
|
40
40
|
"ai": "^5.0.0",
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var schema_metadata_exports = {};
|
|
20
|
-
__export(schema_metadata_exports, {
|
|
21
|
-
extractCommonFields: () => extractCommonFields,
|
|
22
|
-
extractDiscriminatedUnionMetadata: () => extractDiscriminatedUnionMetadata,
|
|
23
|
-
extractSchemaMetadata: () => extractSchemaMetadata,
|
|
24
|
-
getFieldDefault: () => getFieldDefault,
|
|
25
|
-
isFieldRequiredInVariant: () => isFieldRequiredInVariant
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(schema_metadata_exports);
|
|
28
|
-
function extractDefault(def) {
|
|
29
|
-
if (def.defaultValue !== void 0) {
|
|
30
|
-
return typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
|
|
31
|
-
}
|
|
32
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
33
|
-
return extractDefault(def.type._def);
|
|
34
|
-
}
|
|
35
|
-
if (def.typeName === "ZodOptional" && def.innerType) {
|
|
36
|
-
return extractDefault(def.innerType._def);
|
|
37
|
-
}
|
|
38
|
-
if (def.typeName === "ZodNullable" && def.innerType) {
|
|
39
|
-
return extractDefault(def.innerType._def);
|
|
40
|
-
}
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
function extractEnumValues(def) {
|
|
44
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
45
|
-
return extractEnumValues(def.type._def);
|
|
46
|
-
}
|
|
47
|
-
if (def.typeName === "ZodOptional" && def.innerType) {
|
|
48
|
-
return extractEnumValues(def.innerType._def);
|
|
49
|
-
}
|
|
50
|
-
if (def.typeName === "ZodNullable" && def.innerType) {
|
|
51
|
-
return extractEnumValues(def.innerType._def);
|
|
52
|
-
}
|
|
53
|
-
if (def.typeName === "ZodEffects" && def.schema) {
|
|
54
|
-
return extractEnumValues(def.schema._def);
|
|
55
|
-
}
|
|
56
|
-
if (def.typeName === "ZodEnum") {
|
|
57
|
-
return def.values;
|
|
58
|
-
}
|
|
59
|
-
if (def.typeName === "ZodLiteral") {
|
|
60
|
-
return [String(def.value)];
|
|
61
|
-
}
|
|
62
|
-
return void 0;
|
|
63
|
-
}
|
|
64
|
-
function extractTypeName(def) {
|
|
65
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
66
|
-
return extractTypeName(def.type._def);
|
|
67
|
-
}
|
|
68
|
-
if (def.typeName === "ZodOptional" && def.innerType) {
|
|
69
|
-
return extractTypeName(def.innerType._def) + "?";
|
|
70
|
-
}
|
|
71
|
-
if (def.typeName === "ZodNullable" && def.innerType) {
|
|
72
|
-
return extractTypeName(def.innerType._def) + "?";
|
|
73
|
-
}
|
|
74
|
-
if (def.typeName === "ZodLiteral") {
|
|
75
|
-
return `literal(${JSON.stringify(def.value)})`;
|
|
76
|
-
}
|
|
77
|
-
if (def.typeName === "ZodEnum") {
|
|
78
|
-
return `enum(${def.values.join("|")})`;
|
|
79
|
-
}
|
|
80
|
-
if (def.typeName === "ZodArray") {
|
|
81
|
-
return `array<${extractTypeName(def.type._def)}>`;
|
|
82
|
-
}
|
|
83
|
-
if (def.typeName === "ZodRecord") {
|
|
84
|
-
return `record<${extractTypeName(def.valueType._def)}>`;
|
|
85
|
-
}
|
|
86
|
-
if (def.typeName === "ZodEffects" && def.schema) {
|
|
87
|
-
return extractTypeName(def.schema._def);
|
|
88
|
-
}
|
|
89
|
-
const typeMap = {
|
|
90
|
-
ZodString: "string",
|
|
91
|
-
ZodNumber: "number",
|
|
92
|
-
ZodBoolean: "boolean",
|
|
93
|
-
ZodObject: "object",
|
|
94
|
-
ZodArray: "array",
|
|
95
|
-
ZodRecord: "record",
|
|
96
|
-
ZodUnion: "union",
|
|
97
|
-
ZodDiscriminatedUnion: "discriminatedUnion"
|
|
98
|
-
};
|
|
99
|
-
return typeMap[def.typeName] || def.typeName?.replace("Zod", "").toLowerCase() || "unknown";
|
|
100
|
-
}
|
|
101
|
-
function isFieldRequired(def) {
|
|
102
|
-
if (def.defaultValue !== void 0) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
if (def.typeName === "ZodOptional") {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
if (def.typeName === "ZodNullable") {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
112
|
-
return isFieldRequired(def.type._def);
|
|
113
|
-
}
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
function extractSchemaMetadata(schema) {
|
|
117
|
-
const metadata = {
|
|
118
|
-
defaults: {},
|
|
119
|
-
requiredFields: [],
|
|
120
|
-
fieldTypes: {},
|
|
121
|
-
descriptions: {},
|
|
122
|
-
enumValues: {}
|
|
123
|
-
};
|
|
124
|
-
let def = schema._def;
|
|
125
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
126
|
-
def = def.type._def;
|
|
127
|
-
}
|
|
128
|
-
if (def.typeName !== "ZodObject") {
|
|
129
|
-
throw new Error(`Expected ZodObject, got ${def.typeName}`);
|
|
130
|
-
}
|
|
131
|
-
const shape = def.shape();
|
|
132
|
-
for (const [fieldName, fieldSchema] of Object.entries(shape)) {
|
|
133
|
-
const fieldDef = fieldSchema._def;
|
|
134
|
-
const defaultValue = extractDefault(fieldDef);
|
|
135
|
-
if (defaultValue !== void 0) {
|
|
136
|
-
metadata.defaults[fieldName] = defaultValue;
|
|
137
|
-
}
|
|
138
|
-
if (isFieldRequired(fieldDef)) {
|
|
139
|
-
metadata.requiredFields.push(fieldName);
|
|
140
|
-
}
|
|
141
|
-
metadata.fieldTypes[fieldName] = extractTypeName(fieldDef);
|
|
142
|
-
if (fieldDef.description) {
|
|
143
|
-
metadata.descriptions[fieldName] = fieldDef.description;
|
|
144
|
-
}
|
|
145
|
-
const enumVals = extractEnumValues(fieldDef);
|
|
146
|
-
if (enumVals) {
|
|
147
|
-
metadata.enumValues[fieldName] = enumVals;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return metadata;
|
|
151
|
-
}
|
|
152
|
-
function extractDiscriminatedUnionMetadata(schema) {
|
|
153
|
-
let def = schema._def;
|
|
154
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
155
|
-
def = def.type._def;
|
|
156
|
-
}
|
|
157
|
-
if (def.typeName === "ZodEffects" && def.schema) {
|
|
158
|
-
def = def.schema._def;
|
|
159
|
-
}
|
|
160
|
-
if (def.typeName !== "ZodDiscriminatedUnion") {
|
|
161
|
-
throw new Error(`Expected ZodDiscriminatedUnion, got ${def.typeName}`);
|
|
162
|
-
}
|
|
163
|
-
const discriminator = def.discriminator;
|
|
164
|
-
const optionsMap = def.optionsMap;
|
|
165
|
-
const metadata = {
|
|
166
|
-
discriminator,
|
|
167
|
-
options: Array.from(optionsMap.keys()),
|
|
168
|
-
schemas: {}
|
|
169
|
-
};
|
|
170
|
-
for (const [optionValue, optionSchema] of optionsMap.entries()) {
|
|
171
|
-
metadata.schemas[optionValue] = extractSchemaMetadata(optionSchema);
|
|
172
|
-
}
|
|
173
|
-
return metadata;
|
|
174
|
-
}
|
|
175
|
-
function extractCommonFields(metadata) {
|
|
176
|
-
const schemas = Object.values(metadata.schemas);
|
|
177
|
-
if (schemas.length === 0) {
|
|
178
|
-
return {
|
|
179
|
-
defaults: {},
|
|
180
|
-
requiredFields: [],
|
|
181
|
-
fieldTypes: {},
|
|
182
|
-
descriptions: {},
|
|
183
|
-
enumValues: {}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const first = schemas[0];
|
|
187
|
-
const rest = schemas.slice(1);
|
|
188
|
-
const common = {
|
|
189
|
-
defaults: { ...first.defaults },
|
|
190
|
-
requiredFields: [...first.requiredFields],
|
|
191
|
-
fieldTypes: { ...first.fieldTypes },
|
|
192
|
-
descriptions: { ...first.descriptions },
|
|
193
|
-
enumValues: { ...first.enumValues }
|
|
194
|
-
};
|
|
195
|
-
for (const schema of rest) {
|
|
196
|
-
for (const key of Object.keys(common.defaults)) {
|
|
197
|
-
if (!(key in schema.defaults) || schema.defaults[key] !== common.defaults[key]) {
|
|
198
|
-
delete common.defaults[key];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
common.requiredFields = common.requiredFields.filter(
|
|
202
|
-
(field) => schema.requiredFields.includes(field)
|
|
203
|
-
);
|
|
204
|
-
for (const key of Object.keys(common.fieldTypes)) {
|
|
205
|
-
if (!(key in schema.fieldTypes) || schema.fieldTypes[key] !== common.fieldTypes[key]) {
|
|
206
|
-
delete common.fieldTypes[key];
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
for (const key of Object.keys(common.descriptions)) {
|
|
210
|
-
if (!(key in schema.descriptions) || schema.descriptions[key] !== common.descriptions[key]) {
|
|
211
|
-
delete common.descriptions[key];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
for (const key of Object.keys(common.enumValues)) {
|
|
215
|
-
if (!(key in schema.enumValues) || JSON.stringify(schema.enumValues[key]) !== JSON.stringify(common.enumValues[key])) {
|
|
216
|
-
delete common.enumValues[key];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return common;
|
|
221
|
-
}
|
|
222
|
-
function getFieldDefault(metadata, discriminatorValue, fieldName) {
|
|
223
|
-
return metadata.schemas[discriminatorValue]?.defaults[fieldName];
|
|
224
|
-
}
|
|
225
|
-
function isFieldRequiredInVariant(metadata, discriminatorValue, fieldName) {
|
|
226
|
-
return metadata.schemas[discriminatorValue]?.requiredFields.includes(fieldName) ?? false;
|
|
227
|
-
}
|
|
228
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
-
0 && (module.exports = {
|
|
230
|
-
extractCommonFields,
|
|
231
|
-
extractDiscriminatedUnionMetadata,
|
|
232
|
-
extractSchemaMetadata,
|
|
233
|
-
getFieldDefault,
|
|
234
|
-
isFieldRequiredInVariant
|
|
235
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema metadata extraction utilities for Zod schemas
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities to extract metadata from Zod schemas at runtime.
|
|
5
|
-
*
|
|
6
|
-
* IMPORTANT: This uses Zod's private `._def` API which is not officially supported
|
|
7
|
-
* and may break in future Zod versions. We use this approach because:
|
|
8
|
-
* 1. No public Zod API exists for runtime schema introspection
|
|
9
|
-
* 2. Benefits of schema-driven UI metadata outweigh version risk
|
|
10
|
-
* 3. Changes would be caught by TypeScript/tests during upgrades
|
|
11
|
-
*
|
|
12
|
-
* TODO: Update web UI to use these helpers to reduce total code volume and improve maintainability. Also fix these helpers if needed.
|
|
13
|
-
* See packages/webui/components/AgentEditor/CustomizePanel.tsx for the UI side TODO tracking this same goal.
|
|
14
|
-
*
|
|
15
|
-
* If Zod provides official introspection APIs in the future, migrate to those.
|
|
16
|
-
*/
|
|
17
|
-
import { z } from 'zod';
|
|
18
|
-
/**
|
|
19
|
-
* Metadata extracted from a Zod schema
|
|
20
|
-
*/
|
|
21
|
-
export interface SchemaMetadata {
|
|
22
|
-
/** Default values for each field */
|
|
23
|
-
defaults: Record<string, unknown>;
|
|
24
|
-
/** Required fields (not optional, not with defaults) */
|
|
25
|
-
requiredFields: string[];
|
|
26
|
-
/** Field type information */
|
|
27
|
-
fieldTypes: Record<string, string>;
|
|
28
|
-
/** Field descriptions from .describe() calls */
|
|
29
|
-
descriptions: Record<string, string>;
|
|
30
|
-
/** Enum values for enum fields (e.g., provider: ['openai', 'anthropic']) */
|
|
31
|
-
enumValues: Record<string, string[]>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Extract metadata from a discriminated union schema
|
|
35
|
-
* Handles schemas like McpServerConfigSchema (stdio | sse | http)
|
|
36
|
-
*/
|
|
37
|
-
export interface DiscriminatedUnionMetadata {
|
|
38
|
-
/** The discriminator field name (e.g., "type") */
|
|
39
|
-
discriminator: string;
|
|
40
|
-
/** Possible discriminator values (e.g., ["stdio", "sse", "http"]) */
|
|
41
|
-
options: string[];
|
|
42
|
-
/** Metadata for each option */
|
|
43
|
-
schemas: Record<string, SchemaMetadata>;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Extract metadata from a Zod object schema
|
|
47
|
-
*
|
|
48
|
-
* @param schema - Zod schema to extract metadata from
|
|
49
|
-
* @returns SchemaMetadata object with defaults, required fields, types, and descriptions
|
|
50
|
-
*/
|
|
51
|
-
export declare function extractSchemaMetadata(schema: z.ZodTypeAny): SchemaMetadata;
|
|
52
|
-
/**
|
|
53
|
-
* Extract metadata from a discriminated union schema
|
|
54
|
-
*
|
|
55
|
-
* @param schema - Zod discriminated union schema
|
|
56
|
-
* @returns DiscriminatedUnionMetadata with info about each variant
|
|
57
|
-
*/
|
|
58
|
-
export declare function extractDiscriminatedUnionMetadata(schema: z.ZodTypeAny): DiscriminatedUnionMetadata;
|
|
59
|
-
/**
|
|
60
|
-
* Extract common fields from a discriminated union (fields present in all variants)
|
|
61
|
-
* Useful for extracting shared defaults like 'timeout' or 'connectionMode'
|
|
62
|
-
*/
|
|
63
|
-
export declare function extractCommonFields(metadata: DiscriminatedUnionMetadata): SchemaMetadata;
|
|
64
|
-
/**
|
|
65
|
-
* Get default value for a specific field in a discriminated union variant
|
|
66
|
-
*
|
|
67
|
-
* @param metadata - Discriminated union metadata
|
|
68
|
-
* @param discriminatorValue - The discriminator value (e.g., 'stdio', 'http')
|
|
69
|
-
* @param fieldName - The field to get default for
|
|
70
|
-
* @returns The default value or undefined
|
|
71
|
-
*/
|
|
72
|
-
export declare function getFieldDefault(metadata: DiscriminatedUnionMetadata, discriminatorValue: string, fieldName: string): unknown;
|
|
73
|
-
/**
|
|
74
|
-
* Check if a field is required in a specific discriminated union variant
|
|
75
|
-
*
|
|
76
|
-
* @param metadata - Discriminated union metadata
|
|
77
|
-
* @param discriminatorValue - The discriminator value (e.g., 'stdio', 'http')
|
|
78
|
-
* @param fieldName - The field to check
|
|
79
|
-
* @returns true if required, false otherwise
|
|
80
|
-
*/
|
|
81
|
-
export declare function isFieldRequiredInVariant(metadata: DiscriminatedUnionMetadata, discriminatorValue: string, fieldName: string): boolean;
|
|
82
|
-
//# sourceMappingURL=schema-metadata.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-metadata.d.ts","sourceRoot":"","sources":["../../src/utils/schema-metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,wDAAwD;IACxD,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACvC,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC3C;AA0JD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,cAAc,CAqD1E;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC7C,MAAM,EAAE,CAAC,CAAC,UAAU,GACrB,0BAA0B,CAgC5B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,0BAA0B,GAAG,cAAc,CAiExF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,0BAA0B,EACpC,kBAAkB,EAAE,MAAM,EAC1B,SAAS,EAAE,MAAM,GAClB,OAAO,CAET;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACpC,QAAQ,EAAE,0BAA0B,EACpC,kBAAkB,EAAE,MAAM,EAC1B,SAAS,EAAE,MAAM,GAClB,OAAO,CAET"}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import "../chunk-PTJYTZNU.js";
|
|
2
|
-
function extractDefault(def) {
|
|
3
|
-
if (def.defaultValue !== void 0) {
|
|
4
|
-
return typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
|
|
5
|
-
}
|
|
6
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
7
|
-
return extractDefault(def.type._def);
|
|
8
|
-
}
|
|
9
|
-
if (def.typeName === "ZodOptional" && def.innerType) {
|
|
10
|
-
return extractDefault(def.innerType._def);
|
|
11
|
-
}
|
|
12
|
-
if (def.typeName === "ZodNullable" && def.innerType) {
|
|
13
|
-
return extractDefault(def.innerType._def);
|
|
14
|
-
}
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
function extractEnumValues(def) {
|
|
18
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
19
|
-
return extractEnumValues(def.type._def);
|
|
20
|
-
}
|
|
21
|
-
if (def.typeName === "ZodOptional" && def.innerType) {
|
|
22
|
-
return extractEnumValues(def.innerType._def);
|
|
23
|
-
}
|
|
24
|
-
if (def.typeName === "ZodNullable" && def.innerType) {
|
|
25
|
-
return extractEnumValues(def.innerType._def);
|
|
26
|
-
}
|
|
27
|
-
if (def.typeName === "ZodEffects" && def.schema) {
|
|
28
|
-
return extractEnumValues(def.schema._def);
|
|
29
|
-
}
|
|
30
|
-
if (def.typeName === "ZodEnum") {
|
|
31
|
-
return def.values;
|
|
32
|
-
}
|
|
33
|
-
if (def.typeName === "ZodLiteral") {
|
|
34
|
-
return [String(def.value)];
|
|
35
|
-
}
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
function extractTypeName(def) {
|
|
39
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
40
|
-
return extractTypeName(def.type._def);
|
|
41
|
-
}
|
|
42
|
-
if (def.typeName === "ZodOptional" && def.innerType) {
|
|
43
|
-
return extractTypeName(def.innerType._def) + "?";
|
|
44
|
-
}
|
|
45
|
-
if (def.typeName === "ZodNullable" && def.innerType) {
|
|
46
|
-
return extractTypeName(def.innerType._def) + "?";
|
|
47
|
-
}
|
|
48
|
-
if (def.typeName === "ZodLiteral") {
|
|
49
|
-
return `literal(${JSON.stringify(def.value)})`;
|
|
50
|
-
}
|
|
51
|
-
if (def.typeName === "ZodEnum") {
|
|
52
|
-
return `enum(${def.values.join("|")})`;
|
|
53
|
-
}
|
|
54
|
-
if (def.typeName === "ZodArray") {
|
|
55
|
-
return `array<${extractTypeName(def.type._def)}>`;
|
|
56
|
-
}
|
|
57
|
-
if (def.typeName === "ZodRecord") {
|
|
58
|
-
return `record<${extractTypeName(def.valueType._def)}>`;
|
|
59
|
-
}
|
|
60
|
-
if (def.typeName === "ZodEffects" && def.schema) {
|
|
61
|
-
return extractTypeName(def.schema._def);
|
|
62
|
-
}
|
|
63
|
-
const typeMap = {
|
|
64
|
-
ZodString: "string",
|
|
65
|
-
ZodNumber: "number",
|
|
66
|
-
ZodBoolean: "boolean",
|
|
67
|
-
ZodObject: "object",
|
|
68
|
-
ZodArray: "array",
|
|
69
|
-
ZodRecord: "record",
|
|
70
|
-
ZodUnion: "union",
|
|
71
|
-
ZodDiscriminatedUnion: "discriminatedUnion"
|
|
72
|
-
};
|
|
73
|
-
return typeMap[def.typeName] || def.typeName?.replace("Zod", "").toLowerCase() || "unknown";
|
|
74
|
-
}
|
|
75
|
-
function isFieldRequired(def) {
|
|
76
|
-
if (def.defaultValue !== void 0) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
if (def.typeName === "ZodOptional") {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
if (def.typeName === "ZodNullable") {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
86
|
-
return isFieldRequired(def.type._def);
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
function extractSchemaMetadata(schema) {
|
|
91
|
-
const metadata = {
|
|
92
|
-
defaults: {},
|
|
93
|
-
requiredFields: [],
|
|
94
|
-
fieldTypes: {},
|
|
95
|
-
descriptions: {},
|
|
96
|
-
enumValues: {}
|
|
97
|
-
};
|
|
98
|
-
let def = schema._def;
|
|
99
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
100
|
-
def = def.type._def;
|
|
101
|
-
}
|
|
102
|
-
if (def.typeName !== "ZodObject") {
|
|
103
|
-
throw new Error(`Expected ZodObject, got ${def.typeName}`);
|
|
104
|
-
}
|
|
105
|
-
const shape = def.shape();
|
|
106
|
-
for (const [fieldName, fieldSchema] of Object.entries(shape)) {
|
|
107
|
-
const fieldDef = fieldSchema._def;
|
|
108
|
-
const defaultValue = extractDefault(fieldDef);
|
|
109
|
-
if (defaultValue !== void 0) {
|
|
110
|
-
metadata.defaults[fieldName] = defaultValue;
|
|
111
|
-
}
|
|
112
|
-
if (isFieldRequired(fieldDef)) {
|
|
113
|
-
metadata.requiredFields.push(fieldName);
|
|
114
|
-
}
|
|
115
|
-
metadata.fieldTypes[fieldName] = extractTypeName(fieldDef);
|
|
116
|
-
if (fieldDef.description) {
|
|
117
|
-
metadata.descriptions[fieldName] = fieldDef.description;
|
|
118
|
-
}
|
|
119
|
-
const enumVals = extractEnumValues(fieldDef);
|
|
120
|
-
if (enumVals) {
|
|
121
|
-
metadata.enumValues[fieldName] = enumVals;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return metadata;
|
|
125
|
-
}
|
|
126
|
-
function extractDiscriminatedUnionMetadata(schema) {
|
|
127
|
-
let def = schema._def;
|
|
128
|
-
if (def.typeName === "ZodBranded" && def.type) {
|
|
129
|
-
def = def.type._def;
|
|
130
|
-
}
|
|
131
|
-
if (def.typeName === "ZodEffects" && def.schema) {
|
|
132
|
-
def = def.schema._def;
|
|
133
|
-
}
|
|
134
|
-
if (def.typeName !== "ZodDiscriminatedUnion") {
|
|
135
|
-
throw new Error(`Expected ZodDiscriminatedUnion, got ${def.typeName}`);
|
|
136
|
-
}
|
|
137
|
-
const discriminator = def.discriminator;
|
|
138
|
-
const optionsMap = def.optionsMap;
|
|
139
|
-
const metadata = {
|
|
140
|
-
discriminator,
|
|
141
|
-
options: Array.from(optionsMap.keys()),
|
|
142
|
-
schemas: {}
|
|
143
|
-
};
|
|
144
|
-
for (const [optionValue, optionSchema] of optionsMap.entries()) {
|
|
145
|
-
metadata.schemas[optionValue] = extractSchemaMetadata(optionSchema);
|
|
146
|
-
}
|
|
147
|
-
return metadata;
|
|
148
|
-
}
|
|
149
|
-
function extractCommonFields(metadata) {
|
|
150
|
-
const schemas = Object.values(metadata.schemas);
|
|
151
|
-
if (schemas.length === 0) {
|
|
152
|
-
return {
|
|
153
|
-
defaults: {},
|
|
154
|
-
requiredFields: [],
|
|
155
|
-
fieldTypes: {},
|
|
156
|
-
descriptions: {},
|
|
157
|
-
enumValues: {}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
const first = schemas[0];
|
|
161
|
-
const rest = schemas.slice(1);
|
|
162
|
-
const common = {
|
|
163
|
-
defaults: { ...first.defaults },
|
|
164
|
-
requiredFields: [...first.requiredFields],
|
|
165
|
-
fieldTypes: { ...first.fieldTypes },
|
|
166
|
-
descriptions: { ...first.descriptions },
|
|
167
|
-
enumValues: { ...first.enumValues }
|
|
168
|
-
};
|
|
169
|
-
for (const schema of rest) {
|
|
170
|
-
for (const key of Object.keys(common.defaults)) {
|
|
171
|
-
if (!(key in schema.defaults) || schema.defaults[key] !== common.defaults[key]) {
|
|
172
|
-
delete common.defaults[key];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
common.requiredFields = common.requiredFields.filter(
|
|
176
|
-
(field) => schema.requiredFields.includes(field)
|
|
177
|
-
);
|
|
178
|
-
for (const key of Object.keys(common.fieldTypes)) {
|
|
179
|
-
if (!(key in schema.fieldTypes) || schema.fieldTypes[key] !== common.fieldTypes[key]) {
|
|
180
|
-
delete common.fieldTypes[key];
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
for (const key of Object.keys(common.descriptions)) {
|
|
184
|
-
if (!(key in schema.descriptions) || schema.descriptions[key] !== common.descriptions[key]) {
|
|
185
|
-
delete common.descriptions[key];
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
for (const key of Object.keys(common.enumValues)) {
|
|
189
|
-
if (!(key in schema.enumValues) || JSON.stringify(schema.enumValues[key]) !== JSON.stringify(common.enumValues[key])) {
|
|
190
|
-
delete common.enumValues[key];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return common;
|
|
195
|
-
}
|
|
196
|
-
function getFieldDefault(metadata, discriminatorValue, fieldName) {
|
|
197
|
-
return metadata.schemas[discriminatorValue]?.defaults[fieldName];
|
|
198
|
-
}
|
|
199
|
-
function isFieldRequiredInVariant(metadata, discriminatorValue, fieldName) {
|
|
200
|
-
return metadata.schemas[discriminatorValue]?.requiredFields.includes(fieldName) ?? false;
|
|
201
|
-
}
|
|
202
|
-
export {
|
|
203
|
-
extractCommonFields,
|
|
204
|
-
extractDiscriminatedUnionMetadata,
|
|
205
|
-
extractSchemaMetadata,
|
|
206
|
-
getFieldDefault,
|
|
207
|
-
isFieldRequiredInVariant
|
|
208
|
-
};
|
package/dist/utils/user-info.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var user_info_exports = {};
|
|
20
|
-
__export(user_info_exports, {
|
|
21
|
-
getUserId: () => getUserId
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(user_info_exports);
|
|
24
|
-
function getUserId() {
|
|
25
|
-
return "default-user";
|
|
26
|
-
}
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
getUserId
|
|
30
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-info.d.ts","sourceRoot":"","sources":["../../src/utils/user-info.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
|