@fre4x/gemini 1.0.58 → 1.0.61
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 +5 -3
- package/dist/index.js +1640 -119
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -65754,10 +65754,1312 @@ function isTerminal(status) {
|
|
|
65754
65754
|
return status === "completed" || status === "failed" || status === "cancelled";
|
|
65755
65755
|
}
|
|
65756
65756
|
|
|
65757
|
+
// ../node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
65758
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
65759
|
+
var defaultOptions = {
|
|
65760
|
+
name: void 0,
|
|
65761
|
+
$refStrategy: "root",
|
|
65762
|
+
basePath: ["#"],
|
|
65763
|
+
effectStrategy: "input",
|
|
65764
|
+
pipeStrategy: "all",
|
|
65765
|
+
dateStrategy: "format:date-time",
|
|
65766
|
+
mapStrategy: "entries",
|
|
65767
|
+
removeAdditionalStrategy: "passthrough",
|
|
65768
|
+
allowedAdditionalProperties: true,
|
|
65769
|
+
rejectedAdditionalProperties: false,
|
|
65770
|
+
definitionPath: "definitions",
|
|
65771
|
+
target: "jsonSchema7",
|
|
65772
|
+
strictUnions: false,
|
|
65773
|
+
definitions: {},
|
|
65774
|
+
errorMessages: false,
|
|
65775
|
+
markdownDescription: false,
|
|
65776
|
+
patternStrategy: "escape",
|
|
65777
|
+
applyRegexFlags: false,
|
|
65778
|
+
emailStrategy: "format:email",
|
|
65779
|
+
base64Strategy: "contentEncoding:base64",
|
|
65780
|
+
nameStrategy: "ref",
|
|
65781
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
65782
|
+
};
|
|
65783
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
65784
|
+
...defaultOptions,
|
|
65785
|
+
name: options
|
|
65786
|
+
} : {
|
|
65787
|
+
...defaultOptions,
|
|
65788
|
+
...options
|
|
65789
|
+
};
|
|
65790
|
+
|
|
65791
|
+
// ../node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
65792
|
+
var getRefs = (options) => {
|
|
65793
|
+
const _options = getDefaultOptions(options);
|
|
65794
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
65795
|
+
return {
|
|
65796
|
+
..._options,
|
|
65797
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
65798
|
+
currentPath,
|
|
65799
|
+
propertyPath: void 0,
|
|
65800
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
65801
|
+
def._def,
|
|
65802
|
+
{
|
|
65803
|
+
def: def._def,
|
|
65804
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
65805
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
65806
|
+
jsonSchema: void 0
|
|
65807
|
+
}
|
|
65808
|
+
]))
|
|
65809
|
+
};
|
|
65810
|
+
};
|
|
65811
|
+
|
|
65812
|
+
// ../node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
65813
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
65814
|
+
if (!refs?.errorMessages)
|
|
65815
|
+
return;
|
|
65816
|
+
if (errorMessage) {
|
|
65817
|
+
res.errorMessage = {
|
|
65818
|
+
...res.errorMessage,
|
|
65819
|
+
[key]: errorMessage
|
|
65820
|
+
};
|
|
65821
|
+
}
|
|
65822
|
+
}
|
|
65823
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
65824
|
+
res[key] = value;
|
|
65825
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
65826
|
+
}
|
|
65827
|
+
|
|
65828
|
+
// ../node_modules/zod-to-json-schema/dist/esm/getRelativePath.js
|
|
65829
|
+
var getRelativePath = (pathA, pathB) => {
|
|
65830
|
+
let i2 = 0;
|
|
65831
|
+
for (; i2 < pathA.length && i2 < pathB.length; i2++) {
|
|
65832
|
+
if (pathA[i2] !== pathB[i2])
|
|
65833
|
+
break;
|
|
65834
|
+
}
|
|
65835
|
+
return [(pathA.length - i2).toString(), ...pathB.slice(i2)].join("/");
|
|
65836
|
+
};
|
|
65837
|
+
|
|
65838
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
65839
|
+
function parseAnyDef(refs) {
|
|
65840
|
+
if (refs.target !== "openAi") {
|
|
65841
|
+
return {};
|
|
65842
|
+
}
|
|
65843
|
+
const anyDefinitionPath = [
|
|
65844
|
+
...refs.basePath,
|
|
65845
|
+
refs.definitionPath,
|
|
65846
|
+
refs.openAiAnyTypeName
|
|
65847
|
+
];
|
|
65848
|
+
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
65849
|
+
return {
|
|
65850
|
+
$ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
65851
|
+
};
|
|
65852
|
+
}
|
|
65853
|
+
|
|
65854
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
65855
|
+
function parseArrayDef(def, refs) {
|
|
65856
|
+
const res = {
|
|
65857
|
+
type: "array"
|
|
65858
|
+
};
|
|
65859
|
+
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind2.ZodAny) {
|
|
65860
|
+
res.items = parseDef(def.type._def, {
|
|
65861
|
+
...refs,
|
|
65862
|
+
currentPath: [...refs.currentPath, "items"]
|
|
65863
|
+
});
|
|
65864
|
+
}
|
|
65865
|
+
if (def.minLength) {
|
|
65866
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
65867
|
+
}
|
|
65868
|
+
if (def.maxLength) {
|
|
65869
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
65870
|
+
}
|
|
65871
|
+
if (def.exactLength) {
|
|
65872
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
65873
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
65874
|
+
}
|
|
65875
|
+
return res;
|
|
65876
|
+
}
|
|
65877
|
+
|
|
65878
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
65879
|
+
function parseBigintDef(def, refs) {
|
|
65880
|
+
const res = {
|
|
65881
|
+
type: "integer",
|
|
65882
|
+
format: "int64"
|
|
65883
|
+
};
|
|
65884
|
+
if (!def.checks)
|
|
65885
|
+
return res;
|
|
65886
|
+
for (const check2 of def.checks) {
|
|
65887
|
+
switch (check2.kind) {
|
|
65888
|
+
case "min":
|
|
65889
|
+
if (refs.target === "jsonSchema7") {
|
|
65890
|
+
if (check2.inclusive) {
|
|
65891
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
65892
|
+
} else {
|
|
65893
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check2.value, check2.message, refs);
|
|
65894
|
+
}
|
|
65895
|
+
} else {
|
|
65896
|
+
if (!check2.inclusive) {
|
|
65897
|
+
res.exclusiveMinimum = true;
|
|
65898
|
+
}
|
|
65899
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
65900
|
+
}
|
|
65901
|
+
break;
|
|
65902
|
+
case "max":
|
|
65903
|
+
if (refs.target === "jsonSchema7") {
|
|
65904
|
+
if (check2.inclusive) {
|
|
65905
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
65906
|
+
} else {
|
|
65907
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check2.value, check2.message, refs);
|
|
65908
|
+
}
|
|
65909
|
+
} else {
|
|
65910
|
+
if (!check2.inclusive) {
|
|
65911
|
+
res.exclusiveMaximum = true;
|
|
65912
|
+
}
|
|
65913
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
65914
|
+
}
|
|
65915
|
+
break;
|
|
65916
|
+
case "multipleOf":
|
|
65917
|
+
setResponseValueAndErrors(res, "multipleOf", check2.value, check2.message, refs);
|
|
65918
|
+
break;
|
|
65919
|
+
}
|
|
65920
|
+
}
|
|
65921
|
+
return res;
|
|
65922
|
+
}
|
|
65923
|
+
|
|
65924
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
65925
|
+
function parseBooleanDef() {
|
|
65926
|
+
return {
|
|
65927
|
+
type: "boolean"
|
|
65928
|
+
};
|
|
65929
|
+
}
|
|
65930
|
+
|
|
65931
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
65932
|
+
function parseBrandedDef(_def, refs) {
|
|
65933
|
+
return parseDef(_def.type._def, refs);
|
|
65934
|
+
}
|
|
65935
|
+
|
|
65936
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
65937
|
+
var parseCatchDef = (def, refs) => {
|
|
65938
|
+
return parseDef(def.innerType._def, refs);
|
|
65939
|
+
};
|
|
65940
|
+
|
|
65941
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
65942
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
65943
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
65944
|
+
if (Array.isArray(strategy)) {
|
|
65945
|
+
return {
|
|
65946
|
+
anyOf: strategy.map((item, i2) => parseDateDef(def, refs, item))
|
|
65947
|
+
};
|
|
65948
|
+
}
|
|
65949
|
+
switch (strategy) {
|
|
65950
|
+
case "string":
|
|
65951
|
+
case "format:date-time":
|
|
65952
|
+
return {
|
|
65953
|
+
type: "string",
|
|
65954
|
+
format: "date-time"
|
|
65955
|
+
};
|
|
65956
|
+
case "format:date":
|
|
65957
|
+
return {
|
|
65958
|
+
type: "string",
|
|
65959
|
+
format: "date"
|
|
65960
|
+
};
|
|
65961
|
+
case "integer":
|
|
65962
|
+
return integerDateParser(def, refs);
|
|
65963
|
+
}
|
|
65964
|
+
}
|
|
65965
|
+
var integerDateParser = (def, refs) => {
|
|
65966
|
+
const res = {
|
|
65967
|
+
type: "integer",
|
|
65968
|
+
format: "unix-time"
|
|
65969
|
+
};
|
|
65970
|
+
if (refs.target === "openApi3") {
|
|
65971
|
+
return res;
|
|
65972
|
+
}
|
|
65973
|
+
for (const check2 of def.checks) {
|
|
65974
|
+
switch (check2.kind) {
|
|
65975
|
+
case "min":
|
|
65976
|
+
setResponseValueAndErrors(
|
|
65977
|
+
res,
|
|
65978
|
+
"minimum",
|
|
65979
|
+
check2.value,
|
|
65980
|
+
// This is in milliseconds
|
|
65981
|
+
check2.message,
|
|
65982
|
+
refs
|
|
65983
|
+
);
|
|
65984
|
+
break;
|
|
65985
|
+
case "max":
|
|
65986
|
+
setResponseValueAndErrors(
|
|
65987
|
+
res,
|
|
65988
|
+
"maximum",
|
|
65989
|
+
check2.value,
|
|
65990
|
+
// This is in milliseconds
|
|
65991
|
+
check2.message,
|
|
65992
|
+
refs
|
|
65993
|
+
);
|
|
65994
|
+
break;
|
|
65995
|
+
}
|
|
65996
|
+
}
|
|
65997
|
+
return res;
|
|
65998
|
+
};
|
|
65999
|
+
|
|
66000
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
66001
|
+
function parseDefaultDef(_def, refs) {
|
|
66002
|
+
return {
|
|
66003
|
+
...parseDef(_def.innerType._def, refs),
|
|
66004
|
+
default: _def.defaultValue()
|
|
66005
|
+
};
|
|
66006
|
+
}
|
|
66007
|
+
|
|
66008
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
66009
|
+
function parseEffectsDef(_def, refs) {
|
|
66010
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef(refs);
|
|
66011
|
+
}
|
|
66012
|
+
|
|
66013
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
66014
|
+
function parseEnumDef(def) {
|
|
66015
|
+
return {
|
|
66016
|
+
type: "string",
|
|
66017
|
+
enum: Array.from(def.values)
|
|
66018
|
+
};
|
|
66019
|
+
}
|
|
66020
|
+
|
|
66021
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
66022
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
66023
|
+
if ("type" in type && type.type === "string")
|
|
66024
|
+
return false;
|
|
66025
|
+
return "allOf" in type;
|
|
66026
|
+
};
|
|
66027
|
+
function parseIntersectionDef(def, refs) {
|
|
66028
|
+
const allOf = [
|
|
66029
|
+
parseDef(def.left._def, {
|
|
66030
|
+
...refs,
|
|
66031
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
66032
|
+
}),
|
|
66033
|
+
parseDef(def.right._def, {
|
|
66034
|
+
...refs,
|
|
66035
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
66036
|
+
})
|
|
66037
|
+
].filter((x2) => !!x2);
|
|
66038
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
66039
|
+
const mergedAllOf = [];
|
|
66040
|
+
allOf.forEach((schema) => {
|
|
66041
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
66042
|
+
mergedAllOf.push(...schema.allOf);
|
|
66043
|
+
if (schema.unevaluatedProperties === void 0) {
|
|
66044
|
+
unevaluatedProperties = void 0;
|
|
66045
|
+
}
|
|
66046
|
+
} else {
|
|
66047
|
+
let nestedSchema = schema;
|
|
66048
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
66049
|
+
const { additionalProperties, ...rest } = schema;
|
|
66050
|
+
nestedSchema = rest;
|
|
66051
|
+
} else {
|
|
66052
|
+
unevaluatedProperties = void 0;
|
|
66053
|
+
}
|
|
66054
|
+
mergedAllOf.push(nestedSchema);
|
|
66055
|
+
}
|
|
66056
|
+
});
|
|
66057
|
+
return mergedAllOf.length ? {
|
|
66058
|
+
allOf: mergedAllOf,
|
|
66059
|
+
...unevaluatedProperties
|
|
66060
|
+
} : void 0;
|
|
66061
|
+
}
|
|
66062
|
+
|
|
66063
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
66064
|
+
function parseLiteralDef(def, refs) {
|
|
66065
|
+
const parsedType2 = typeof def.value;
|
|
66066
|
+
if (parsedType2 !== "bigint" && parsedType2 !== "number" && parsedType2 !== "boolean" && parsedType2 !== "string") {
|
|
66067
|
+
return {
|
|
66068
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
66069
|
+
};
|
|
66070
|
+
}
|
|
66071
|
+
if (refs.target === "openApi3") {
|
|
66072
|
+
return {
|
|
66073
|
+
type: parsedType2 === "bigint" ? "integer" : parsedType2,
|
|
66074
|
+
enum: [def.value]
|
|
66075
|
+
};
|
|
66076
|
+
}
|
|
66077
|
+
return {
|
|
66078
|
+
type: parsedType2 === "bigint" ? "integer" : parsedType2,
|
|
66079
|
+
const: def.value
|
|
66080
|
+
};
|
|
66081
|
+
}
|
|
66082
|
+
|
|
65757
66083
|
// ../node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
66084
|
+
var emojiRegex2 = void 0;
|
|
66085
|
+
var zodPatterns = {
|
|
66086
|
+
/**
|
|
66087
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
66088
|
+
*/
|
|
66089
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
66090
|
+
cuid2: /^[0-9a-z]+$/,
|
|
66091
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
66092
|
+
/**
|
|
66093
|
+
* `a-z` was added to replicate /i flag
|
|
66094
|
+
*/
|
|
66095
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
66096
|
+
/**
|
|
66097
|
+
* Constructed a valid Unicode RegExp
|
|
66098
|
+
*
|
|
66099
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
66100
|
+
* in all envs (e.g. React Native).
|
|
66101
|
+
*
|
|
66102
|
+
* See:
|
|
66103
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
66104
|
+
* Fix in Zod:
|
|
66105
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
66106
|
+
*/
|
|
66107
|
+
emoji: () => {
|
|
66108
|
+
if (emojiRegex2 === void 0) {
|
|
66109
|
+
emojiRegex2 = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
66110
|
+
}
|
|
66111
|
+
return emojiRegex2;
|
|
66112
|
+
},
|
|
66113
|
+
/**
|
|
66114
|
+
* Unused
|
|
66115
|
+
*/
|
|
66116
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
66117
|
+
/**
|
|
66118
|
+
* Unused
|
|
66119
|
+
*/
|
|
66120
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
66121
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
66122
|
+
/**
|
|
66123
|
+
* Unused
|
|
66124
|
+
*/
|
|
66125
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
66126
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
66127
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
66128
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
66129
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
66130
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
66131
|
+
};
|
|
66132
|
+
function parseStringDef(def, refs) {
|
|
66133
|
+
const res = {
|
|
66134
|
+
type: "string"
|
|
66135
|
+
};
|
|
66136
|
+
if (def.checks) {
|
|
66137
|
+
for (const check2 of def.checks) {
|
|
66138
|
+
switch (check2.kind) {
|
|
66139
|
+
case "min":
|
|
66140
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value, check2.message, refs);
|
|
66141
|
+
break;
|
|
66142
|
+
case "max":
|
|
66143
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value, check2.message, refs);
|
|
66144
|
+
break;
|
|
66145
|
+
case "email":
|
|
66146
|
+
switch (refs.emailStrategy) {
|
|
66147
|
+
case "format:email":
|
|
66148
|
+
addFormat(res, "email", check2.message, refs);
|
|
66149
|
+
break;
|
|
66150
|
+
case "format:idn-email":
|
|
66151
|
+
addFormat(res, "idn-email", check2.message, refs);
|
|
66152
|
+
break;
|
|
66153
|
+
case "pattern:zod":
|
|
66154
|
+
addPattern(res, zodPatterns.email, check2.message, refs);
|
|
66155
|
+
break;
|
|
66156
|
+
}
|
|
66157
|
+
break;
|
|
66158
|
+
case "url":
|
|
66159
|
+
addFormat(res, "uri", check2.message, refs);
|
|
66160
|
+
break;
|
|
66161
|
+
case "uuid":
|
|
66162
|
+
addFormat(res, "uuid", check2.message, refs);
|
|
66163
|
+
break;
|
|
66164
|
+
case "regex":
|
|
66165
|
+
addPattern(res, check2.regex, check2.message, refs);
|
|
66166
|
+
break;
|
|
66167
|
+
case "cuid":
|
|
66168
|
+
addPattern(res, zodPatterns.cuid, check2.message, refs);
|
|
66169
|
+
break;
|
|
66170
|
+
case "cuid2":
|
|
66171
|
+
addPattern(res, zodPatterns.cuid2, check2.message, refs);
|
|
66172
|
+
break;
|
|
66173
|
+
case "startsWith":
|
|
66174
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check2.value, refs)}`), check2.message, refs);
|
|
66175
|
+
break;
|
|
66176
|
+
case "endsWith":
|
|
66177
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check2.value, refs)}$`), check2.message, refs);
|
|
66178
|
+
break;
|
|
66179
|
+
case "datetime":
|
|
66180
|
+
addFormat(res, "date-time", check2.message, refs);
|
|
66181
|
+
break;
|
|
66182
|
+
case "date":
|
|
66183
|
+
addFormat(res, "date", check2.message, refs);
|
|
66184
|
+
break;
|
|
66185
|
+
case "time":
|
|
66186
|
+
addFormat(res, "time", check2.message, refs);
|
|
66187
|
+
break;
|
|
66188
|
+
case "duration":
|
|
66189
|
+
addFormat(res, "duration", check2.message, refs);
|
|
66190
|
+
break;
|
|
66191
|
+
case "length":
|
|
66192
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value, check2.message, refs);
|
|
66193
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value, check2.message, refs);
|
|
66194
|
+
break;
|
|
66195
|
+
case "includes": {
|
|
66196
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check2.value, refs)), check2.message, refs);
|
|
66197
|
+
break;
|
|
66198
|
+
}
|
|
66199
|
+
case "ip": {
|
|
66200
|
+
if (check2.version !== "v6") {
|
|
66201
|
+
addFormat(res, "ipv4", check2.message, refs);
|
|
66202
|
+
}
|
|
66203
|
+
if (check2.version !== "v4") {
|
|
66204
|
+
addFormat(res, "ipv6", check2.message, refs);
|
|
66205
|
+
}
|
|
66206
|
+
break;
|
|
66207
|
+
}
|
|
66208
|
+
case "base64url":
|
|
66209
|
+
addPattern(res, zodPatterns.base64url, check2.message, refs);
|
|
66210
|
+
break;
|
|
66211
|
+
case "jwt":
|
|
66212
|
+
addPattern(res, zodPatterns.jwt, check2.message, refs);
|
|
66213
|
+
break;
|
|
66214
|
+
case "cidr": {
|
|
66215
|
+
if (check2.version !== "v6") {
|
|
66216
|
+
addPattern(res, zodPatterns.ipv4Cidr, check2.message, refs);
|
|
66217
|
+
}
|
|
66218
|
+
if (check2.version !== "v4") {
|
|
66219
|
+
addPattern(res, zodPatterns.ipv6Cidr, check2.message, refs);
|
|
66220
|
+
}
|
|
66221
|
+
break;
|
|
66222
|
+
}
|
|
66223
|
+
case "emoji":
|
|
66224
|
+
addPattern(res, zodPatterns.emoji(), check2.message, refs);
|
|
66225
|
+
break;
|
|
66226
|
+
case "ulid": {
|
|
66227
|
+
addPattern(res, zodPatterns.ulid, check2.message, refs);
|
|
66228
|
+
break;
|
|
66229
|
+
}
|
|
66230
|
+
case "base64": {
|
|
66231
|
+
switch (refs.base64Strategy) {
|
|
66232
|
+
case "format:binary": {
|
|
66233
|
+
addFormat(res, "binary", check2.message, refs);
|
|
66234
|
+
break;
|
|
66235
|
+
}
|
|
66236
|
+
case "contentEncoding:base64": {
|
|
66237
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check2.message, refs);
|
|
66238
|
+
break;
|
|
66239
|
+
}
|
|
66240
|
+
case "pattern:zod": {
|
|
66241
|
+
addPattern(res, zodPatterns.base64, check2.message, refs);
|
|
66242
|
+
break;
|
|
66243
|
+
}
|
|
66244
|
+
}
|
|
66245
|
+
break;
|
|
66246
|
+
}
|
|
66247
|
+
case "nanoid": {
|
|
66248
|
+
addPattern(res, zodPatterns.nanoid, check2.message, refs);
|
|
66249
|
+
}
|
|
66250
|
+
case "toLowerCase":
|
|
66251
|
+
case "toUpperCase":
|
|
66252
|
+
case "trim":
|
|
66253
|
+
break;
|
|
66254
|
+
default:
|
|
66255
|
+
/* @__PURE__ */ ((_) => {
|
|
66256
|
+
})(check2);
|
|
66257
|
+
}
|
|
66258
|
+
}
|
|
66259
|
+
}
|
|
66260
|
+
return res;
|
|
66261
|
+
}
|
|
66262
|
+
function escapeLiteralCheckValue(literal2, refs) {
|
|
66263
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal2) : literal2;
|
|
66264
|
+
}
|
|
65758
66265
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
66266
|
+
function escapeNonAlphaNumeric(source) {
|
|
66267
|
+
let result = "";
|
|
66268
|
+
for (let i2 = 0; i2 < source.length; i2++) {
|
|
66269
|
+
if (!ALPHA_NUMERIC.has(source[i2])) {
|
|
66270
|
+
result += "\\";
|
|
66271
|
+
}
|
|
66272
|
+
result += source[i2];
|
|
66273
|
+
}
|
|
66274
|
+
return result;
|
|
66275
|
+
}
|
|
66276
|
+
function addFormat(schema, value, message, refs) {
|
|
66277
|
+
if (schema.format || schema.anyOf?.some((x2) => x2.format)) {
|
|
66278
|
+
if (!schema.anyOf) {
|
|
66279
|
+
schema.anyOf = [];
|
|
66280
|
+
}
|
|
66281
|
+
if (schema.format) {
|
|
66282
|
+
schema.anyOf.push({
|
|
66283
|
+
format: schema.format,
|
|
66284
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
66285
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
66286
|
+
}
|
|
66287
|
+
});
|
|
66288
|
+
delete schema.format;
|
|
66289
|
+
if (schema.errorMessage) {
|
|
66290
|
+
delete schema.errorMessage.format;
|
|
66291
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
66292
|
+
delete schema.errorMessage;
|
|
66293
|
+
}
|
|
66294
|
+
}
|
|
66295
|
+
}
|
|
66296
|
+
schema.anyOf.push({
|
|
66297
|
+
format: value,
|
|
66298
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
66299
|
+
});
|
|
66300
|
+
} else {
|
|
66301
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
66302
|
+
}
|
|
66303
|
+
}
|
|
66304
|
+
function addPattern(schema, regex, message, refs) {
|
|
66305
|
+
if (schema.pattern || schema.allOf?.some((x2) => x2.pattern)) {
|
|
66306
|
+
if (!schema.allOf) {
|
|
66307
|
+
schema.allOf = [];
|
|
66308
|
+
}
|
|
66309
|
+
if (schema.pattern) {
|
|
66310
|
+
schema.allOf.push({
|
|
66311
|
+
pattern: schema.pattern,
|
|
66312
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
66313
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
66314
|
+
}
|
|
66315
|
+
});
|
|
66316
|
+
delete schema.pattern;
|
|
66317
|
+
if (schema.errorMessage) {
|
|
66318
|
+
delete schema.errorMessage.pattern;
|
|
66319
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
66320
|
+
delete schema.errorMessage;
|
|
66321
|
+
}
|
|
66322
|
+
}
|
|
66323
|
+
}
|
|
66324
|
+
schema.allOf.push({
|
|
66325
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
66326
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
66327
|
+
});
|
|
66328
|
+
} else {
|
|
66329
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
66330
|
+
}
|
|
66331
|
+
}
|
|
66332
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
66333
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
66334
|
+
return regex.source;
|
|
66335
|
+
}
|
|
66336
|
+
const flags = {
|
|
66337
|
+
i: regex.flags.includes("i"),
|
|
66338
|
+
m: regex.flags.includes("m"),
|
|
66339
|
+
s: regex.flags.includes("s")
|
|
66340
|
+
// `.` matches newlines
|
|
66341
|
+
};
|
|
66342
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
66343
|
+
let pattern = "";
|
|
66344
|
+
let isEscaped = false;
|
|
66345
|
+
let inCharGroup = false;
|
|
66346
|
+
let inCharRange = false;
|
|
66347
|
+
for (let i2 = 0; i2 < source.length; i2++) {
|
|
66348
|
+
if (isEscaped) {
|
|
66349
|
+
pattern += source[i2];
|
|
66350
|
+
isEscaped = false;
|
|
66351
|
+
continue;
|
|
66352
|
+
}
|
|
66353
|
+
if (flags.i) {
|
|
66354
|
+
if (inCharGroup) {
|
|
66355
|
+
if (source[i2].match(/[a-z]/)) {
|
|
66356
|
+
if (inCharRange) {
|
|
66357
|
+
pattern += source[i2];
|
|
66358
|
+
pattern += `${source[i2 - 2]}-${source[i2]}`.toUpperCase();
|
|
66359
|
+
inCharRange = false;
|
|
66360
|
+
} else if (source[i2 + 1] === "-" && source[i2 + 2]?.match(/[a-z]/)) {
|
|
66361
|
+
pattern += source[i2];
|
|
66362
|
+
inCharRange = true;
|
|
66363
|
+
} else {
|
|
66364
|
+
pattern += `${source[i2]}${source[i2].toUpperCase()}`;
|
|
66365
|
+
}
|
|
66366
|
+
continue;
|
|
66367
|
+
}
|
|
66368
|
+
} else if (source[i2].match(/[a-z]/)) {
|
|
66369
|
+
pattern += `[${source[i2]}${source[i2].toUpperCase()}]`;
|
|
66370
|
+
continue;
|
|
66371
|
+
}
|
|
66372
|
+
}
|
|
66373
|
+
if (flags.m) {
|
|
66374
|
+
if (source[i2] === "^") {
|
|
66375
|
+
pattern += `(^|(?<=[\r
|
|
66376
|
+
]))`;
|
|
66377
|
+
continue;
|
|
66378
|
+
} else if (source[i2] === "$") {
|
|
66379
|
+
pattern += `($|(?=[\r
|
|
66380
|
+
]))`;
|
|
66381
|
+
continue;
|
|
66382
|
+
}
|
|
66383
|
+
}
|
|
66384
|
+
if (flags.s && source[i2] === ".") {
|
|
66385
|
+
pattern += inCharGroup ? `${source[i2]}\r
|
|
66386
|
+
` : `[${source[i2]}\r
|
|
66387
|
+
]`;
|
|
66388
|
+
continue;
|
|
66389
|
+
}
|
|
66390
|
+
pattern += source[i2];
|
|
66391
|
+
if (source[i2] === "\\") {
|
|
66392
|
+
isEscaped = true;
|
|
66393
|
+
} else if (inCharGroup && source[i2] === "]") {
|
|
66394
|
+
inCharGroup = false;
|
|
66395
|
+
} else if (!inCharGroup && source[i2] === "[") {
|
|
66396
|
+
inCharGroup = true;
|
|
66397
|
+
}
|
|
66398
|
+
}
|
|
66399
|
+
try {
|
|
66400
|
+
new RegExp(pattern);
|
|
66401
|
+
} catch {
|
|
66402
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
66403
|
+
return regex.source;
|
|
66404
|
+
}
|
|
66405
|
+
return pattern;
|
|
66406
|
+
}
|
|
66407
|
+
|
|
66408
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
66409
|
+
function parseRecordDef(def, refs) {
|
|
66410
|
+
if (refs.target === "openAi") {
|
|
66411
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
66412
|
+
}
|
|
66413
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
66414
|
+
return {
|
|
66415
|
+
type: "object",
|
|
66416
|
+
required: def.keyType._def.values,
|
|
66417
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
66418
|
+
...acc,
|
|
66419
|
+
[key]: parseDef(def.valueType._def, {
|
|
66420
|
+
...refs,
|
|
66421
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
66422
|
+
}) ?? parseAnyDef(refs)
|
|
66423
|
+
}), {}),
|
|
66424
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
66425
|
+
};
|
|
66426
|
+
}
|
|
66427
|
+
const schema = {
|
|
66428
|
+
type: "object",
|
|
66429
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
66430
|
+
...refs,
|
|
66431
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
66432
|
+
}) ?? refs.allowedAdditionalProperties
|
|
66433
|
+
};
|
|
66434
|
+
if (refs.target === "openApi3") {
|
|
66435
|
+
return schema;
|
|
66436
|
+
}
|
|
66437
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
66438
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
66439
|
+
return {
|
|
66440
|
+
...schema,
|
|
66441
|
+
propertyNames: keyType
|
|
66442
|
+
};
|
|
66443
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
66444
|
+
return {
|
|
66445
|
+
...schema,
|
|
66446
|
+
propertyNames: {
|
|
66447
|
+
enum: def.keyType._def.values
|
|
66448
|
+
}
|
|
66449
|
+
};
|
|
66450
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
66451
|
+
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
66452
|
+
return {
|
|
66453
|
+
...schema,
|
|
66454
|
+
propertyNames: keyType
|
|
66455
|
+
};
|
|
66456
|
+
}
|
|
66457
|
+
return schema;
|
|
66458
|
+
}
|
|
66459
|
+
|
|
66460
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
66461
|
+
function parseMapDef(def, refs) {
|
|
66462
|
+
if (refs.mapStrategy === "record") {
|
|
66463
|
+
return parseRecordDef(def, refs);
|
|
66464
|
+
}
|
|
66465
|
+
const keys = parseDef(def.keyType._def, {
|
|
66466
|
+
...refs,
|
|
66467
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
66468
|
+
}) || parseAnyDef(refs);
|
|
66469
|
+
const values = parseDef(def.valueType._def, {
|
|
66470
|
+
...refs,
|
|
66471
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
66472
|
+
}) || parseAnyDef(refs);
|
|
66473
|
+
return {
|
|
66474
|
+
type: "array",
|
|
66475
|
+
maxItems: 125,
|
|
66476
|
+
items: {
|
|
66477
|
+
type: "array",
|
|
66478
|
+
items: [keys, values],
|
|
66479
|
+
minItems: 2,
|
|
66480
|
+
maxItems: 2
|
|
66481
|
+
}
|
|
66482
|
+
};
|
|
66483
|
+
}
|
|
66484
|
+
|
|
66485
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
66486
|
+
function parseNativeEnumDef(def) {
|
|
66487
|
+
const object3 = def.values;
|
|
66488
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
66489
|
+
return typeof object3[object3[key]] !== "number";
|
|
66490
|
+
});
|
|
66491
|
+
const actualValues = actualKeys.map((key) => object3[key]);
|
|
66492
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
66493
|
+
return {
|
|
66494
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
66495
|
+
enum: actualValues
|
|
66496
|
+
};
|
|
66497
|
+
}
|
|
66498
|
+
|
|
66499
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
66500
|
+
function parseNeverDef(refs) {
|
|
66501
|
+
return refs.target === "openAi" ? void 0 : {
|
|
66502
|
+
not: parseAnyDef({
|
|
66503
|
+
...refs,
|
|
66504
|
+
currentPath: [...refs.currentPath, "not"]
|
|
66505
|
+
})
|
|
66506
|
+
};
|
|
66507
|
+
}
|
|
66508
|
+
|
|
66509
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
66510
|
+
function parseNullDef(refs) {
|
|
66511
|
+
return refs.target === "openApi3" ? {
|
|
66512
|
+
enum: ["null"],
|
|
66513
|
+
nullable: true
|
|
66514
|
+
} : {
|
|
66515
|
+
type: "null"
|
|
66516
|
+
};
|
|
66517
|
+
}
|
|
66518
|
+
|
|
66519
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
66520
|
+
var primitiveMappings = {
|
|
66521
|
+
ZodString: "string",
|
|
66522
|
+
ZodNumber: "number",
|
|
66523
|
+
ZodBigInt: "integer",
|
|
66524
|
+
ZodBoolean: "boolean",
|
|
66525
|
+
ZodNull: "null"
|
|
66526
|
+
};
|
|
66527
|
+
function parseUnionDef(def, refs) {
|
|
66528
|
+
if (refs.target === "openApi3")
|
|
66529
|
+
return asAnyOf(def, refs);
|
|
66530
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
66531
|
+
if (options.every((x2) => x2._def.typeName in primitiveMappings && (!x2._def.checks || !x2._def.checks.length))) {
|
|
66532
|
+
const types3 = options.reduce((types4, x2) => {
|
|
66533
|
+
const type = primitiveMappings[x2._def.typeName];
|
|
66534
|
+
return type && !types4.includes(type) ? [...types4, type] : types4;
|
|
66535
|
+
}, []);
|
|
66536
|
+
return {
|
|
66537
|
+
type: types3.length > 1 ? types3 : types3[0]
|
|
66538
|
+
};
|
|
66539
|
+
} else if (options.every((x2) => x2._def.typeName === "ZodLiteral" && !x2.description)) {
|
|
66540
|
+
const types3 = options.reduce((acc, x2) => {
|
|
66541
|
+
const type = typeof x2._def.value;
|
|
66542
|
+
switch (type) {
|
|
66543
|
+
case "string":
|
|
66544
|
+
case "number":
|
|
66545
|
+
case "boolean":
|
|
66546
|
+
return [...acc, type];
|
|
66547
|
+
case "bigint":
|
|
66548
|
+
return [...acc, "integer"];
|
|
66549
|
+
case "object":
|
|
66550
|
+
if (x2._def.value === null)
|
|
66551
|
+
return [...acc, "null"];
|
|
66552
|
+
case "symbol":
|
|
66553
|
+
case "undefined":
|
|
66554
|
+
case "function":
|
|
66555
|
+
default:
|
|
66556
|
+
return acc;
|
|
66557
|
+
}
|
|
66558
|
+
}, []);
|
|
66559
|
+
if (types3.length === options.length) {
|
|
66560
|
+
const uniqueTypes = types3.filter((x2, i2, a) => a.indexOf(x2) === i2);
|
|
66561
|
+
return {
|
|
66562
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
66563
|
+
enum: options.reduce((acc, x2) => {
|
|
66564
|
+
return acc.includes(x2._def.value) ? acc : [...acc, x2._def.value];
|
|
66565
|
+
}, [])
|
|
66566
|
+
};
|
|
66567
|
+
}
|
|
66568
|
+
} else if (options.every((x2) => x2._def.typeName === "ZodEnum")) {
|
|
66569
|
+
return {
|
|
66570
|
+
type: "string",
|
|
66571
|
+
enum: options.reduce((acc, x2) => [
|
|
66572
|
+
...acc,
|
|
66573
|
+
...x2._def.values.filter((x3) => !acc.includes(x3))
|
|
66574
|
+
], [])
|
|
66575
|
+
};
|
|
66576
|
+
}
|
|
66577
|
+
return asAnyOf(def, refs);
|
|
66578
|
+
}
|
|
66579
|
+
var asAnyOf = (def, refs) => {
|
|
66580
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x2, i2) => parseDef(x2._def, {
|
|
66581
|
+
...refs,
|
|
66582
|
+
currentPath: [...refs.currentPath, "anyOf", `${i2}`]
|
|
66583
|
+
})).filter((x2) => !!x2 && (!refs.strictUnions || typeof x2 === "object" && Object.keys(x2).length > 0));
|
|
66584
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
66585
|
+
};
|
|
66586
|
+
|
|
66587
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
66588
|
+
function parseNullableDef(def, refs) {
|
|
66589
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
66590
|
+
if (refs.target === "openApi3") {
|
|
66591
|
+
return {
|
|
66592
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
66593
|
+
nullable: true
|
|
66594
|
+
};
|
|
66595
|
+
}
|
|
66596
|
+
return {
|
|
66597
|
+
type: [
|
|
66598
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
66599
|
+
"null"
|
|
66600
|
+
]
|
|
66601
|
+
};
|
|
66602
|
+
}
|
|
66603
|
+
if (refs.target === "openApi3") {
|
|
66604
|
+
const base2 = parseDef(def.innerType._def, {
|
|
66605
|
+
...refs,
|
|
66606
|
+
currentPath: [...refs.currentPath]
|
|
66607
|
+
});
|
|
66608
|
+
if (base2 && "$ref" in base2)
|
|
66609
|
+
return { allOf: [base2], nullable: true };
|
|
66610
|
+
return base2 && { ...base2, nullable: true };
|
|
66611
|
+
}
|
|
66612
|
+
const base = parseDef(def.innerType._def, {
|
|
66613
|
+
...refs,
|
|
66614
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
66615
|
+
});
|
|
66616
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
66617
|
+
}
|
|
66618
|
+
|
|
66619
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
66620
|
+
function parseNumberDef(def, refs) {
|
|
66621
|
+
const res = {
|
|
66622
|
+
type: "number"
|
|
66623
|
+
};
|
|
66624
|
+
if (!def.checks)
|
|
66625
|
+
return res;
|
|
66626
|
+
for (const check2 of def.checks) {
|
|
66627
|
+
switch (check2.kind) {
|
|
66628
|
+
case "int":
|
|
66629
|
+
res.type = "integer";
|
|
66630
|
+
addErrorMessage(res, "type", check2.message, refs);
|
|
66631
|
+
break;
|
|
66632
|
+
case "min":
|
|
66633
|
+
if (refs.target === "jsonSchema7") {
|
|
66634
|
+
if (check2.inclusive) {
|
|
66635
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
66636
|
+
} else {
|
|
66637
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check2.value, check2.message, refs);
|
|
66638
|
+
}
|
|
66639
|
+
} else {
|
|
66640
|
+
if (!check2.inclusive) {
|
|
66641
|
+
res.exclusiveMinimum = true;
|
|
66642
|
+
}
|
|
66643
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
66644
|
+
}
|
|
66645
|
+
break;
|
|
66646
|
+
case "max":
|
|
66647
|
+
if (refs.target === "jsonSchema7") {
|
|
66648
|
+
if (check2.inclusive) {
|
|
66649
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
66650
|
+
} else {
|
|
66651
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check2.value, check2.message, refs);
|
|
66652
|
+
}
|
|
66653
|
+
} else {
|
|
66654
|
+
if (!check2.inclusive) {
|
|
66655
|
+
res.exclusiveMaximum = true;
|
|
66656
|
+
}
|
|
66657
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
66658
|
+
}
|
|
66659
|
+
break;
|
|
66660
|
+
case "multipleOf":
|
|
66661
|
+
setResponseValueAndErrors(res, "multipleOf", check2.value, check2.message, refs);
|
|
66662
|
+
break;
|
|
66663
|
+
}
|
|
66664
|
+
}
|
|
66665
|
+
return res;
|
|
66666
|
+
}
|
|
66667
|
+
|
|
66668
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
66669
|
+
function parseObjectDef(def, refs) {
|
|
66670
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
66671
|
+
const result = {
|
|
66672
|
+
type: "object",
|
|
66673
|
+
properties: {}
|
|
66674
|
+
};
|
|
66675
|
+
const required2 = [];
|
|
66676
|
+
const shape = def.shape();
|
|
66677
|
+
for (const propName in shape) {
|
|
66678
|
+
let propDef = shape[propName];
|
|
66679
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
66680
|
+
continue;
|
|
66681
|
+
}
|
|
66682
|
+
let propOptional = safeIsOptional(propDef);
|
|
66683
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
66684
|
+
if (propDef._def.typeName === "ZodOptional") {
|
|
66685
|
+
propDef = propDef._def.innerType;
|
|
66686
|
+
}
|
|
66687
|
+
if (!propDef.isNullable()) {
|
|
66688
|
+
propDef = propDef.nullable();
|
|
66689
|
+
}
|
|
66690
|
+
propOptional = false;
|
|
66691
|
+
}
|
|
66692
|
+
const parsedDef = parseDef(propDef._def, {
|
|
66693
|
+
...refs,
|
|
66694
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
66695
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
66696
|
+
});
|
|
66697
|
+
if (parsedDef === void 0) {
|
|
66698
|
+
continue;
|
|
66699
|
+
}
|
|
66700
|
+
result.properties[propName] = parsedDef;
|
|
66701
|
+
if (!propOptional) {
|
|
66702
|
+
required2.push(propName);
|
|
66703
|
+
}
|
|
66704
|
+
}
|
|
66705
|
+
if (required2.length) {
|
|
66706
|
+
result.required = required2;
|
|
66707
|
+
}
|
|
66708
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
66709
|
+
if (additionalProperties !== void 0) {
|
|
66710
|
+
result.additionalProperties = additionalProperties;
|
|
66711
|
+
}
|
|
66712
|
+
return result;
|
|
66713
|
+
}
|
|
66714
|
+
function decideAdditionalProperties(def, refs) {
|
|
66715
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
66716
|
+
return parseDef(def.catchall._def, {
|
|
66717
|
+
...refs,
|
|
66718
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
66719
|
+
});
|
|
66720
|
+
}
|
|
66721
|
+
switch (def.unknownKeys) {
|
|
66722
|
+
case "passthrough":
|
|
66723
|
+
return refs.allowedAdditionalProperties;
|
|
66724
|
+
case "strict":
|
|
66725
|
+
return refs.rejectedAdditionalProperties;
|
|
66726
|
+
case "strip":
|
|
66727
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
66728
|
+
}
|
|
66729
|
+
}
|
|
66730
|
+
function safeIsOptional(schema) {
|
|
66731
|
+
try {
|
|
66732
|
+
return schema.isOptional();
|
|
66733
|
+
} catch {
|
|
66734
|
+
return true;
|
|
66735
|
+
}
|
|
66736
|
+
}
|
|
66737
|
+
|
|
66738
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
66739
|
+
var parseOptionalDef = (def, refs) => {
|
|
66740
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
66741
|
+
return parseDef(def.innerType._def, refs);
|
|
66742
|
+
}
|
|
66743
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
66744
|
+
...refs,
|
|
66745
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
66746
|
+
});
|
|
66747
|
+
return innerSchema ? {
|
|
66748
|
+
anyOf: [
|
|
66749
|
+
{
|
|
66750
|
+
not: parseAnyDef(refs)
|
|
66751
|
+
},
|
|
66752
|
+
innerSchema
|
|
66753
|
+
]
|
|
66754
|
+
} : parseAnyDef(refs);
|
|
66755
|
+
};
|
|
66756
|
+
|
|
66757
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
66758
|
+
var parsePipelineDef = (def, refs) => {
|
|
66759
|
+
if (refs.pipeStrategy === "input") {
|
|
66760
|
+
return parseDef(def.in._def, refs);
|
|
66761
|
+
} else if (refs.pipeStrategy === "output") {
|
|
66762
|
+
return parseDef(def.out._def, refs);
|
|
66763
|
+
}
|
|
66764
|
+
const a = parseDef(def.in._def, {
|
|
66765
|
+
...refs,
|
|
66766
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
66767
|
+
});
|
|
66768
|
+
const b = parseDef(def.out._def, {
|
|
66769
|
+
...refs,
|
|
66770
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
66771
|
+
});
|
|
66772
|
+
return {
|
|
66773
|
+
allOf: [a, b].filter((x2) => x2 !== void 0)
|
|
66774
|
+
};
|
|
66775
|
+
};
|
|
66776
|
+
|
|
66777
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
66778
|
+
function parsePromiseDef(def, refs) {
|
|
66779
|
+
return parseDef(def.type._def, refs);
|
|
66780
|
+
}
|
|
66781
|
+
|
|
66782
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
66783
|
+
function parseSetDef(def, refs) {
|
|
66784
|
+
const items = parseDef(def.valueType._def, {
|
|
66785
|
+
...refs,
|
|
66786
|
+
currentPath: [...refs.currentPath, "items"]
|
|
66787
|
+
});
|
|
66788
|
+
const schema = {
|
|
66789
|
+
type: "array",
|
|
66790
|
+
uniqueItems: true,
|
|
66791
|
+
items
|
|
66792
|
+
};
|
|
66793
|
+
if (def.minSize) {
|
|
66794
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
66795
|
+
}
|
|
66796
|
+
if (def.maxSize) {
|
|
66797
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
66798
|
+
}
|
|
66799
|
+
return schema;
|
|
66800
|
+
}
|
|
66801
|
+
|
|
66802
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
66803
|
+
function parseTupleDef(def, refs) {
|
|
66804
|
+
if (def.rest) {
|
|
66805
|
+
return {
|
|
66806
|
+
type: "array",
|
|
66807
|
+
minItems: def.items.length,
|
|
66808
|
+
items: def.items.map((x2, i2) => parseDef(x2._def, {
|
|
66809
|
+
...refs,
|
|
66810
|
+
currentPath: [...refs.currentPath, "items", `${i2}`]
|
|
66811
|
+
})).reduce((acc, x2) => x2 === void 0 ? acc : [...acc, x2], []),
|
|
66812
|
+
additionalItems: parseDef(def.rest._def, {
|
|
66813
|
+
...refs,
|
|
66814
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
66815
|
+
})
|
|
66816
|
+
};
|
|
66817
|
+
} else {
|
|
66818
|
+
return {
|
|
66819
|
+
type: "array",
|
|
66820
|
+
minItems: def.items.length,
|
|
66821
|
+
maxItems: def.items.length,
|
|
66822
|
+
items: def.items.map((x2, i2) => parseDef(x2._def, {
|
|
66823
|
+
...refs,
|
|
66824
|
+
currentPath: [...refs.currentPath, "items", `${i2}`]
|
|
66825
|
+
})).reduce((acc, x2) => x2 === void 0 ? acc : [...acc, x2], [])
|
|
66826
|
+
};
|
|
66827
|
+
}
|
|
66828
|
+
}
|
|
66829
|
+
|
|
66830
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
66831
|
+
function parseUndefinedDef(refs) {
|
|
66832
|
+
return {
|
|
66833
|
+
not: parseAnyDef(refs)
|
|
66834
|
+
};
|
|
66835
|
+
}
|
|
66836
|
+
|
|
66837
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
66838
|
+
function parseUnknownDef(refs) {
|
|
66839
|
+
return parseAnyDef(refs);
|
|
66840
|
+
}
|
|
66841
|
+
|
|
66842
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
66843
|
+
var parseReadonlyDef = (def, refs) => {
|
|
66844
|
+
return parseDef(def.innerType._def, refs);
|
|
66845
|
+
};
|
|
66846
|
+
|
|
66847
|
+
// ../node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
66848
|
+
var selectParser = (def, typeName, refs) => {
|
|
66849
|
+
switch (typeName) {
|
|
66850
|
+
case ZodFirstPartyTypeKind2.ZodString:
|
|
66851
|
+
return parseStringDef(def, refs);
|
|
66852
|
+
case ZodFirstPartyTypeKind2.ZodNumber:
|
|
66853
|
+
return parseNumberDef(def, refs);
|
|
66854
|
+
case ZodFirstPartyTypeKind2.ZodObject:
|
|
66855
|
+
return parseObjectDef(def, refs);
|
|
66856
|
+
case ZodFirstPartyTypeKind2.ZodBigInt:
|
|
66857
|
+
return parseBigintDef(def, refs);
|
|
66858
|
+
case ZodFirstPartyTypeKind2.ZodBoolean:
|
|
66859
|
+
return parseBooleanDef();
|
|
66860
|
+
case ZodFirstPartyTypeKind2.ZodDate:
|
|
66861
|
+
return parseDateDef(def, refs);
|
|
66862
|
+
case ZodFirstPartyTypeKind2.ZodUndefined:
|
|
66863
|
+
return parseUndefinedDef(refs);
|
|
66864
|
+
case ZodFirstPartyTypeKind2.ZodNull:
|
|
66865
|
+
return parseNullDef(refs);
|
|
66866
|
+
case ZodFirstPartyTypeKind2.ZodArray:
|
|
66867
|
+
return parseArrayDef(def, refs);
|
|
66868
|
+
case ZodFirstPartyTypeKind2.ZodUnion:
|
|
66869
|
+
case ZodFirstPartyTypeKind2.ZodDiscriminatedUnion:
|
|
66870
|
+
return parseUnionDef(def, refs);
|
|
66871
|
+
case ZodFirstPartyTypeKind2.ZodIntersection:
|
|
66872
|
+
return parseIntersectionDef(def, refs);
|
|
66873
|
+
case ZodFirstPartyTypeKind2.ZodTuple:
|
|
66874
|
+
return parseTupleDef(def, refs);
|
|
66875
|
+
case ZodFirstPartyTypeKind2.ZodRecord:
|
|
66876
|
+
return parseRecordDef(def, refs);
|
|
66877
|
+
case ZodFirstPartyTypeKind2.ZodLiteral:
|
|
66878
|
+
return parseLiteralDef(def, refs);
|
|
66879
|
+
case ZodFirstPartyTypeKind2.ZodEnum:
|
|
66880
|
+
return parseEnumDef(def);
|
|
66881
|
+
case ZodFirstPartyTypeKind2.ZodNativeEnum:
|
|
66882
|
+
return parseNativeEnumDef(def);
|
|
66883
|
+
case ZodFirstPartyTypeKind2.ZodNullable:
|
|
66884
|
+
return parseNullableDef(def, refs);
|
|
66885
|
+
case ZodFirstPartyTypeKind2.ZodOptional:
|
|
66886
|
+
return parseOptionalDef(def, refs);
|
|
66887
|
+
case ZodFirstPartyTypeKind2.ZodMap:
|
|
66888
|
+
return parseMapDef(def, refs);
|
|
66889
|
+
case ZodFirstPartyTypeKind2.ZodSet:
|
|
66890
|
+
return parseSetDef(def, refs);
|
|
66891
|
+
case ZodFirstPartyTypeKind2.ZodLazy:
|
|
66892
|
+
return () => def.getter()._def;
|
|
66893
|
+
case ZodFirstPartyTypeKind2.ZodPromise:
|
|
66894
|
+
return parsePromiseDef(def, refs);
|
|
66895
|
+
case ZodFirstPartyTypeKind2.ZodNaN:
|
|
66896
|
+
case ZodFirstPartyTypeKind2.ZodNever:
|
|
66897
|
+
return parseNeverDef(refs);
|
|
66898
|
+
case ZodFirstPartyTypeKind2.ZodEffects:
|
|
66899
|
+
return parseEffectsDef(def, refs);
|
|
66900
|
+
case ZodFirstPartyTypeKind2.ZodAny:
|
|
66901
|
+
return parseAnyDef(refs);
|
|
66902
|
+
case ZodFirstPartyTypeKind2.ZodUnknown:
|
|
66903
|
+
return parseUnknownDef(refs);
|
|
66904
|
+
case ZodFirstPartyTypeKind2.ZodDefault:
|
|
66905
|
+
return parseDefaultDef(def, refs);
|
|
66906
|
+
case ZodFirstPartyTypeKind2.ZodBranded:
|
|
66907
|
+
return parseBrandedDef(def, refs);
|
|
66908
|
+
case ZodFirstPartyTypeKind2.ZodReadonly:
|
|
66909
|
+
return parseReadonlyDef(def, refs);
|
|
66910
|
+
case ZodFirstPartyTypeKind2.ZodCatch:
|
|
66911
|
+
return parseCatchDef(def, refs);
|
|
66912
|
+
case ZodFirstPartyTypeKind2.ZodPipeline:
|
|
66913
|
+
return parsePipelineDef(def, refs);
|
|
66914
|
+
case ZodFirstPartyTypeKind2.ZodFunction:
|
|
66915
|
+
case ZodFirstPartyTypeKind2.ZodVoid:
|
|
66916
|
+
case ZodFirstPartyTypeKind2.ZodSymbol:
|
|
66917
|
+
return void 0;
|
|
66918
|
+
default:
|
|
66919
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
66920
|
+
}
|
|
66921
|
+
};
|
|
66922
|
+
|
|
66923
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
66924
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
66925
|
+
const seenItem = refs.seen.get(def);
|
|
66926
|
+
if (refs.override) {
|
|
66927
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
66928
|
+
if (overrideResult !== ignoreOverride) {
|
|
66929
|
+
return overrideResult;
|
|
66930
|
+
}
|
|
66931
|
+
}
|
|
66932
|
+
if (seenItem && !forceResolution) {
|
|
66933
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
66934
|
+
if (seenSchema !== void 0) {
|
|
66935
|
+
return seenSchema;
|
|
66936
|
+
}
|
|
66937
|
+
}
|
|
66938
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
66939
|
+
refs.seen.set(def, newItem);
|
|
66940
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
66941
|
+
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
66942
|
+
if (jsonSchema) {
|
|
66943
|
+
addMeta(def, refs, jsonSchema);
|
|
66944
|
+
}
|
|
66945
|
+
if (refs.postProcess) {
|
|
66946
|
+
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
66947
|
+
newItem.jsonSchema = jsonSchema;
|
|
66948
|
+
return postProcessResult;
|
|
66949
|
+
}
|
|
66950
|
+
newItem.jsonSchema = jsonSchema;
|
|
66951
|
+
return jsonSchema;
|
|
66952
|
+
}
|
|
66953
|
+
var get$ref = (item, refs) => {
|
|
66954
|
+
switch (refs.$refStrategy) {
|
|
66955
|
+
case "root":
|
|
66956
|
+
return { $ref: item.path.join("/") };
|
|
66957
|
+
case "relative":
|
|
66958
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
66959
|
+
case "none":
|
|
66960
|
+
case "seen": {
|
|
66961
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
66962
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
66963
|
+
return parseAnyDef(refs);
|
|
66964
|
+
}
|
|
66965
|
+
return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
|
|
66966
|
+
}
|
|
66967
|
+
}
|
|
66968
|
+
};
|
|
66969
|
+
var addMeta = (def, refs, jsonSchema) => {
|
|
66970
|
+
if (def.description) {
|
|
66971
|
+
jsonSchema.description = def.description;
|
|
66972
|
+
if (refs.markdownDescription) {
|
|
66973
|
+
jsonSchema.markdownDescription = def.description;
|
|
66974
|
+
}
|
|
66975
|
+
}
|
|
66976
|
+
return jsonSchema;
|
|
66977
|
+
};
|
|
66978
|
+
|
|
66979
|
+
// ../node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
66980
|
+
var zodToJsonSchema = (schema, options) => {
|
|
66981
|
+
const refs = getRefs(options);
|
|
66982
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
66983
|
+
...acc,
|
|
66984
|
+
[name2]: parseDef(schema2._def, {
|
|
66985
|
+
...refs,
|
|
66986
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
66987
|
+
}, true) ?? parseAnyDef(refs)
|
|
66988
|
+
}), {}) : void 0;
|
|
66989
|
+
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
66990
|
+
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
66991
|
+
...refs,
|
|
66992
|
+
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
66993
|
+
}, false) ?? parseAnyDef(refs);
|
|
66994
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
66995
|
+
if (title !== void 0) {
|
|
66996
|
+
main.title = title;
|
|
66997
|
+
}
|
|
66998
|
+
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
66999
|
+
if (!definitions) {
|
|
67000
|
+
definitions = {};
|
|
67001
|
+
}
|
|
67002
|
+
if (!definitions[refs.openAiAnyTypeName]) {
|
|
67003
|
+
definitions[refs.openAiAnyTypeName] = {
|
|
67004
|
+
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
67005
|
+
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
67006
|
+
items: {
|
|
67007
|
+
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
67008
|
+
...refs.basePath,
|
|
67009
|
+
refs.definitionPath,
|
|
67010
|
+
refs.openAiAnyTypeName
|
|
67011
|
+
].join("/")
|
|
67012
|
+
}
|
|
67013
|
+
};
|
|
67014
|
+
}
|
|
67015
|
+
}
|
|
67016
|
+
const combined = name === void 0 ? definitions ? {
|
|
67017
|
+
...main,
|
|
67018
|
+
[refs.definitionPath]: definitions
|
|
67019
|
+
} : main : {
|
|
67020
|
+
$ref: [
|
|
67021
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
67022
|
+
refs.definitionPath,
|
|
67023
|
+
name
|
|
67024
|
+
].join("/"),
|
|
67025
|
+
[refs.definitionPath]: {
|
|
67026
|
+
...definitions,
|
|
67027
|
+
[name]: main
|
|
67028
|
+
}
|
|
67029
|
+
};
|
|
67030
|
+
if (refs.target === "jsonSchema7") {
|
|
67031
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
67032
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
67033
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
67034
|
+
}
|
|
67035
|
+
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
67036
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
67037
|
+
}
|
|
67038
|
+
return combined;
|
|
67039
|
+
};
|
|
65759
67040
|
|
|
65760
67041
|
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
|
|
67042
|
+
function mapMiniTarget(t2) {
|
|
67043
|
+
if (!t2)
|
|
67044
|
+
return "draft-7";
|
|
67045
|
+
if (t2 === "jsonSchema7" || t2 === "draft-7")
|
|
67046
|
+
return "draft-7";
|
|
67047
|
+
if (t2 === "jsonSchema2019-09" || t2 === "draft-2020-12")
|
|
67048
|
+
return "draft-2020-12";
|
|
67049
|
+
return "draft-7";
|
|
67050
|
+
}
|
|
67051
|
+
function toJsonSchemaCompat(schema, opts) {
|
|
67052
|
+
if (isZ4Schema(schema)) {
|
|
67053
|
+
return toJSONSchema(schema, {
|
|
67054
|
+
target: mapMiniTarget(opts?.target),
|
|
67055
|
+
io: opts?.pipeStrategy ?? "input"
|
|
67056
|
+
});
|
|
67057
|
+
}
|
|
67058
|
+
return zodToJsonSchema(schema, {
|
|
67059
|
+
strictUnions: opts?.strictUnions ?? true,
|
|
67060
|
+
pipeStrategy: opts?.pipeStrategy ?? "input"
|
|
67061
|
+
});
|
|
67062
|
+
}
|
|
65761
67063
|
function getMethodLiteral(schema) {
|
|
65762
67064
|
const shape = getObjectShape(schema);
|
|
65763
67065
|
const methodSchema = shape?.method;
|
|
@@ -67519,9 +68821,24 @@ var zodCompat2 = zod_exports;
|
|
|
67519
68821
|
var z3 = zodCompat2.z ?? zodCompat2.default?.z ?? zodCompat2.default ?? zodCompat2;
|
|
67520
68822
|
var IS_MOCK = process.env.GEMINI_MOCK === "true" || process.env.MOCK === "true";
|
|
67521
68823
|
var PACKAGE_VERSION = getPackageVersion(import.meta.url);
|
|
67522
|
-
var DEFAULT_TEXT_MODEL = "gemini-2.
|
|
67523
|
-
var DEFAULT_IMAGE_MODEL = "imagen-
|
|
67524
|
-
var DEFAULT_VIDEO_MODEL = "veo-
|
|
68824
|
+
var DEFAULT_TEXT_MODEL = "gemini-2.5-flash";
|
|
68825
|
+
var DEFAULT_IMAGE_MODEL = "imagen-4.0-generate-001";
|
|
68826
|
+
var DEFAULT_VIDEO_MODEL = "veo-3.1-generate-preview";
|
|
68827
|
+
var FALLBACK_ANALYZE_MEDIA_MODELS = [
|
|
68828
|
+
DEFAULT_TEXT_MODEL,
|
|
68829
|
+
"gemini-2.5-pro",
|
|
68830
|
+
"gemini-2.5-flash-lite"
|
|
68831
|
+
];
|
|
68832
|
+
var FALLBACK_IMAGE_MODELS = [
|
|
68833
|
+
DEFAULT_IMAGE_MODEL,
|
|
68834
|
+
"imagen-4.0-ultra-generate-001",
|
|
68835
|
+
"imagen-4.0-fast-generate-001"
|
|
68836
|
+
];
|
|
68837
|
+
var FALLBACK_VIDEO_MODELS = [
|
|
68838
|
+
DEFAULT_VIDEO_MODEL,
|
|
68839
|
+
"veo-3.1-lite-generate-preview"
|
|
68840
|
+
];
|
|
68841
|
+
var MODEL_CATALOG_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
67525
68842
|
var ALLOWED_MEDIA_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
67526
68843
|
"image/png",
|
|
67527
68844
|
"image/jpeg",
|
|
@@ -67542,6 +68859,7 @@ var ALLOWED_MEDIA_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
|
67542
68859
|
"application/pdf"
|
|
67543
68860
|
]);
|
|
67544
68861
|
var ai = null;
|
|
68862
|
+
var modelCatalogCache = null;
|
|
67545
68863
|
function getApiKey() {
|
|
67546
68864
|
const apiKey = process.env.GEMINI_API_KEY;
|
|
67547
68865
|
if (!apiKey) {
|
|
@@ -67616,6 +68934,7 @@ var AnalyzeMediaOutputSchema = z3.object({
|
|
|
67616
68934
|
savedPath: z3.string().optional()
|
|
67617
68935
|
});
|
|
67618
68936
|
var ListModelsOutputSchema = z3.object({
|
|
68937
|
+
analyzeModels: z3.array(z3.string()),
|
|
67619
68938
|
imageModels: z3.array(z3.string()),
|
|
67620
68939
|
videoModels: z3.array(z3.string())
|
|
67621
68940
|
});
|
|
@@ -67644,48 +68963,14 @@ var VideoStatusOutputSchema = z3.object({
|
|
|
67644
68963
|
),
|
|
67645
68964
|
error: z3.string().optional()
|
|
67646
68965
|
});
|
|
67647
|
-
var ANALYZE_MEDIA_TOOL = {
|
|
67648
|
-
name: "analyze_media",
|
|
67649
|
-
description: "Analyze an image or audio file from a URL or file path.",
|
|
67650
|
-
inputSchema: z3.object({
|
|
67651
|
-
prompt: z3.string().min(1).default("Describe this media.").describe("Optional question or instruction for the media."),
|
|
67652
|
-
media_source: z3.string().min(1).describe("URL, file:// path, or local file path."),
|
|
67653
|
-
mime_type: z3.string().optional().describe("Optional MIME type override."),
|
|
67654
|
-
model: z3.string().optional().default(DEFAULT_TEXT_MODEL).describe("Gemini model to use for analysis."),
|
|
67655
|
-
output_dir: z3.string().optional().describe(
|
|
67656
|
-
"Optional directory to save the analysis result as a .txt file."
|
|
67657
|
-
)
|
|
67658
|
-
}).strict(),
|
|
67659
|
-
outputSchema: AnalyzeMediaOutputSchema
|
|
67660
|
-
};
|
|
67661
68966
|
var LIST_MODELS_TOOL = {
|
|
67662
68967
|
name: "list_models",
|
|
67663
|
-
description: "List available
|
|
68968
|
+
description: "List available models for Gemini media tools.",
|
|
67664
68969
|
inputSchema: z3.object({
|
|
67665
|
-
capability: z3.enum(["all", "image", "video"]).default("all").describe("Filter by
|
|
68970
|
+
capability: z3.enum(["all", "analyze", "image", "video"]).default("all").describe("Filter by analyze, image, video, or all.")
|
|
67666
68971
|
}).strict(),
|
|
67667
68972
|
outputSchema: ListModelsOutputSchema
|
|
67668
68973
|
};
|
|
67669
|
-
var GENERATE_IMAGE_TOOL = {
|
|
67670
|
-
name: "generate_image",
|
|
67671
|
-
description: "Generate an image using Imagen and optionally save it to disk.",
|
|
67672
|
-
inputSchema: z3.object({
|
|
67673
|
-
prompt: z3.string().min(1).describe("Description of the image to generate."),
|
|
67674
|
-
aspect_ratio: z3.enum(["1:1", "16:9", "9:16"]).default("1:1").describe("Aspect ratio for the image."),
|
|
67675
|
-
model: z3.string().default(DEFAULT_IMAGE_MODEL).describe("Imagen model to use."),
|
|
67676
|
-
output_dir: z3.string().optional().describe("Directory to save the image file.")
|
|
67677
|
-
}).strict(),
|
|
67678
|
-
outputSchema: GenerateImageOutputSchema
|
|
67679
|
-
};
|
|
67680
|
-
var GENERATE_VIDEO_TOOL = {
|
|
67681
|
-
name: "generate_video",
|
|
67682
|
-
description: "Start an async video generation request using Veo.",
|
|
67683
|
-
inputSchema: z3.object({
|
|
67684
|
-
prompt: z3.string().min(1).describe("Description of the video to generate."),
|
|
67685
|
-
model: z3.string().default(DEFAULT_VIDEO_MODEL).describe("Veo model to use.")
|
|
67686
|
-
}).strict(),
|
|
67687
|
-
outputSchema: GenerateVideoOutputSchema
|
|
67688
|
-
};
|
|
67689
68974
|
var GET_VIDEO_STATUS_TOOL = {
|
|
67690
68975
|
name: "get_video_status",
|
|
67691
68976
|
description: "Check the status of a video generation request.",
|
|
@@ -67695,16 +68980,9 @@ var GET_VIDEO_STATUS_TOOL = {
|
|
|
67695
68980
|
}).strict(),
|
|
67696
68981
|
outputSchema: VideoStatusOutputSchema
|
|
67697
68982
|
};
|
|
67698
|
-
var TOOL_DEFINITIONS = [
|
|
67699
|
-
ANALYZE_MEDIA_TOOL,
|
|
67700
|
-
LIST_MODELS_TOOL,
|
|
67701
|
-
GENERATE_IMAGE_TOOL,
|
|
67702
|
-
GENERATE_VIDEO_TOOL,
|
|
67703
|
-
GET_VIDEO_STATUS_TOOL
|
|
67704
|
-
];
|
|
67705
68983
|
var server = new Server(
|
|
67706
68984
|
{ name: "gemini-mcp", version: PACKAGE_VERSION },
|
|
67707
|
-
{ capabilities: { tools: {} } }
|
|
68985
|
+
{ capabilities: { tools: { listChanged: true } } }
|
|
67708
68986
|
);
|
|
67709
68987
|
function inferMimeTypeFromSource(source) {
|
|
67710
68988
|
const withoutQuery = source.split("?")[0].split("#")[0];
|
|
@@ -67769,8 +69047,226 @@ function textResult(text, structuredContent) {
|
|
|
67769
69047
|
function formatModelLines(models, title) {
|
|
67770
69048
|
return [title, ...models.map((model) => `- ${model}`), ""];
|
|
67771
69049
|
}
|
|
69050
|
+
function hasApiKey() {
|
|
69051
|
+
return typeof process.env.GEMINI_API_KEY === "string" && process.env.GEMINI_API_KEY.length > 0;
|
|
69052
|
+
}
|
|
69053
|
+
function dedupeModels(models) {
|
|
69054
|
+
return [...new Set(models.filter(Boolean))];
|
|
69055
|
+
}
|
|
69056
|
+
function normalizeModelOptions(models, defaultModel) {
|
|
69057
|
+
return dedupeModels([defaultModel, ...models]);
|
|
69058
|
+
}
|
|
69059
|
+
function getFallbackModelCatalog() {
|
|
69060
|
+
return {
|
|
69061
|
+
analyzeModels: [...FALLBACK_ANALYZE_MEDIA_MODELS],
|
|
69062
|
+
imageModels: [...FALLBACK_IMAGE_MODELS],
|
|
69063
|
+
videoModels: [...FALLBACK_VIDEO_MODELS]
|
|
69064
|
+
};
|
|
69065
|
+
}
|
|
69066
|
+
function isAnalyzeModel(model) {
|
|
69067
|
+
const name = (model.name ?? "").replace("models/", "");
|
|
69068
|
+
const methods = model.supportedGenerationMethods ?? [];
|
|
69069
|
+
return name.startsWith("gemini-") && methods.includes("generateContent") && !name.includes("image") && !name.includes("embedding") && !name.includes("tts") && !name.includes("live");
|
|
69070
|
+
}
|
|
69071
|
+
function isImageGenerationModel(model) {
|
|
69072
|
+
const name = (model.name ?? "").replace("models/", "");
|
|
69073
|
+
return name.startsWith("imagen-");
|
|
69074
|
+
}
|
|
69075
|
+
function isVideoGenerationModel(model) {
|
|
69076
|
+
const name = (model.name ?? "").replace("models/", "");
|
|
69077
|
+
return name.startsWith("veo-");
|
|
69078
|
+
}
|
|
69079
|
+
async function loadLiveModelCatalog() {
|
|
69080
|
+
if (modelCatalogCache && modelCatalogCache.expiresAt > Date.now()) {
|
|
69081
|
+
return modelCatalogCache.catalog;
|
|
69082
|
+
}
|
|
69083
|
+
const resp = await fetch(
|
|
69084
|
+
`https://generativelanguage.googleapis.com/v1beta/models?key=${getApiKey()}&pageSize=200`
|
|
69085
|
+
);
|
|
69086
|
+
if (!resp.ok) {
|
|
69087
|
+
throw withStatusCode(
|
|
69088
|
+
new Error("The model listing service is unavailable."),
|
|
69089
|
+
resp.status
|
|
69090
|
+
);
|
|
69091
|
+
}
|
|
69092
|
+
const data = await resp.json();
|
|
69093
|
+
const models = data.models ?? [];
|
|
69094
|
+
const catalog = {
|
|
69095
|
+
analyzeModels: normalizeModelOptions(
|
|
69096
|
+
models.filter(isAnalyzeModel).map((model) => model.name.replace("models/", "")),
|
|
69097
|
+
DEFAULT_TEXT_MODEL
|
|
69098
|
+
),
|
|
69099
|
+
imageModels: normalizeModelOptions(
|
|
69100
|
+
models.filter(isImageGenerationModel).map((model) => model.name.replace("models/", "")),
|
|
69101
|
+
DEFAULT_IMAGE_MODEL
|
|
69102
|
+
),
|
|
69103
|
+
videoModels: normalizeModelOptions(
|
|
69104
|
+
models.filter(isVideoGenerationModel).map((model) => model.name.replace("models/", "")),
|
|
69105
|
+
DEFAULT_VIDEO_MODEL
|
|
69106
|
+
)
|
|
69107
|
+
};
|
|
69108
|
+
modelCatalogCache = {
|
|
69109
|
+
expiresAt: Date.now() + MODEL_CATALOG_CACHE_TTL_MS,
|
|
69110
|
+
catalog
|
|
69111
|
+
};
|
|
69112
|
+
return catalog;
|
|
69113
|
+
}
|
|
69114
|
+
async function getToolModelCatalog() {
|
|
69115
|
+
if (IS_MOCK || !hasApiKey()) {
|
|
69116
|
+
return getFallbackModelCatalog();
|
|
69117
|
+
}
|
|
69118
|
+
try {
|
|
69119
|
+
return await loadLiveModelCatalog();
|
|
69120
|
+
} catch {
|
|
69121
|
+
return getFallbackModelCatalog();
|
|
69122
|
+
}
|
|
69123
|
+
}
|
|
69124
|
+
async function getValidationModelCatalog() {
|
|
69125
|
+
if (IS_MOCK) {
|
|
69126
|
+
return getFallbackModelCatalog();
|
|
69127
|
+
}
|
|
69128
|
+
if (!hasApiKey()) {
|
|
69129
|
+
return null;
|
|
69130
|
+
}
|
|
69131
|
+
try {
|
|
69132
|
+
return await loadLiveModelCatalog();
|
|
69133
|
+
} catch {
|
|
69134
|
+
return null;
|
|
69135
|
+
}
|
|
69136
|
+
}
|
|
69137
|
+
function createModelSchema(models, defaultModel, description) {
|
|
69138
|
+
const options = normalizeModelOptions(models, defaultModel);
|
|
69139
|
+
return z3.enum(options).default(defaultModel).describe(description);
|
|
69140
|
+
}
|
|
69141
|
+
function buildAnalyzeMediaTool(catalog) {
|
|
69142
|
+
return {
|
|
69143
|
+
name: "analyze_media",
|
|
69144
|
+
description: "Analyze an image or audio file from a URL or file path.",
|
|
69145
|
+
inputSchema: z3.object({
|
|
69146
|
+
prompt: z3.string().min(1).default("Describe this media.").describe(
|
|
69147
|
+
"Optional question or instruction for the media."
|
|
69148
|
+
),
|
|
69149
|
+
media_source: z3.string().min(1).describe("URL, file:// path, or local file path."),
|
|
69150
|
+
mime_type: z3.string().optional().describe("Optional MIME type override."),
|
|
69151
|
+
model: createModelSchema(
|
|
69152
|
+
catalog.analyzeModels,
|
|
69153
|
+
DEFAULT_TEXT_MODEL,
|
|
69154
|
+
"Supported analyze_media model."
|
|
69155
|
+
),
|
|
69156
|
+
output_dir: z3.string().optional().describe(
|
|
69157
|
+
"Optional directory to save the analysis result as a .txt file."
|
|
69158
|
+
)
|
|
69159
|
+
}).strict(),
|
|
69160
|
+
outputSchema: AnalyzeMediaOutputSchema
|
|
69161
|
+
};
|
|
69162
|
+
}
|
|
69163
|
+
function buildGenerateImageTool(catalog) {
|
|
69164
|
+
return {
|
|
69165
|
+
name: "generate_image",
|
|
69166
|
+
description: "Generate an image using Imagen and optionally save it to disk.",
|
|
69167
|
+
inputSchema: z3.object({
|
|
69168
|
+
prompt: z3.string().min(1).describe("Description of the image to generate."),
|
|
69169
|
+
aspect_ratio: z3.enum(["1:1", "16:9", "9:16"]).default("1:1").describe("Aspect ratio for the image."),
|
|
69170
|
+
model: createModelSchema(
|
|
69171
|
+
catalog.imageModels,
|
|
69172
|
+
DEFAULT_IMAGE_MODEL,
|
|
69173
|
+
"Supported generate_image model."
|
|
69174
|
+
),
|
|
69175
|
+
output_dir: z3.string().optional().describe("Directory to save the image file.")
|
|
69176
|
+
}).strict(),
|
|
69177
|
+
outputSchema: GenerateImageOutputSchema
|
|
69178
|
+
};
|
|
69179
|
+
}
|
|
69180
|
+
function buildGenerateVideoTool(catalog) {
|
|
69181
|
+
return {
|
|
69182
|
+
name: "generate_video",
|
|
69183
|
+
description: "Start an async video generation request using Veo.",
|
|
69184
|
+
inputSchema: z3.object({
|
|
69185
|
+
prompt: z3.string().min(1).describe("Description of the video to generate."),
|
|
69186
|
+
model: createModelSchema(
|
|
69187
|
+
catalog.videoModels,
|
|
69188
|
+
DEFAULT_VIDEO_MODEL,
|
|
69189
|
+
"Supported generate_video model."
|
|
69190
|
+
)
|
|
69191
|
+
}).strict(),
|
|
69192
|
+
outputSchema: GenerateVideoOutputSchema
|
|
69193
|
+
};
|
|
69194
|
+
}
|
|
69195
|
+
var TOOL_DEFINITIONS = [
|
|
69196
|
+
buildAnalyzeMediaTool(getFallbackModelCatalog()),
|
|
69197
|
+
LIST_MODELS_TOOL,
|
|
69198
|
+
buildGenerateImageTool(getFallbackModelCatalog()),
|
|
69199
|
+
buildGenerateVideoTool(getFallbackModelCatalog()),
|
|
69200
|
+
GET_VIDEO_STATUS_TOOL
|
|
69201
|
+
];
|
|
69202
|
+
async function getToolDefinitions() {
|
|
69203
|
+
const catalog = await getToolModelCatalog();
|
|
69204
|
+
return [
|
|
69205
|
+
buildAnalyzeMediaTool(catalog),
|
|
69206
|
+
LIST_MODELS_TOOL,
|
|
69207
|
+
buildGenerateImageTool(catalog),
|
|
69208
|
+
buildGenerateVideoTool(catalog),
|
|
69209
|
+
GET_VIDEO_STATUS_TOOL
|
|
69210
|
+
];
|
|
69211
|
+
}
|
|
69212
|
+
function toToolJsonSchema(schema, pipeStrategy) {
|
|
69213
|
+
return toJsonSchemaCompat(schema, { strictUnions: true, pipeStrategy });
|
|
69214
|
+
}
|
|
69215
|
+
function toListedToolDefinition(tool) {
|
|
69216
|
+
return {
|
|
69217
|
+
name: tool.name,
|
|
69218
|
+
description: tool.description,
|
|
69219
|
+
inputSchema: toToolJsonSchema(tool.inputSchema, "input"),
|
|
69220
|
+
outputSchema: toToolJsonSchema(tool.outputSchema, "output")
|
|
69221
|
+
};
|
|
69222
|
+
}
|
|
69223
|
+
async function getListedToolDefinitions() {
|
|
69224
|
+
return (await getToolDefinitions()).map(toListedToolDefinition);
|
|
69225
|
+
}
|
|
69226
|
+
function createModelValidationError(toolName, model, supportedModels) {
|
|
69227
|
+
return createValidationError(
|
|
69228
|
+
"model",
|
|
69229
|
+
`"${model}" is not supported by ${toolName}. Verify today's date first (for example: Get-Date -Format o), then use list_models to inspect current models for this tool. Supported values: ${supportedModels.join(", ")}`
|
|
69230
|
+
);
|
|
69231
|
+
}
|
|
69232
|
+
async function validateRequestedModel(toolName, requestedModel, supportedModels) {
|
|
69233
|
+
if (toolName === "analyze_media") {
|
|
69234
|
+
if (requestedModel.startsWith("gemini-1.5-") || requestedModel.startsWith("gemini-2.0-")) {
|
|
69235
|
+
return createModelValidationError(
|
|
69236
|
+
toolName,
|
|
69237
|
+
requestedModel,
|
|
69238
|
+
supportedModels
|
|
69239
|
+
);
|
|
69240
|
+
}
|
|
69241
|
+
}
|
|
69242
|
+
const catalog = await getValidationModelCatalog();
|
|
69243
|
+
if (!catalog) {
|
|
69244
|
+
return null;
|
|
69245
|
+
}
|
|
69246
|
+
if (!supportedModels.includes(requestedModel)) {
|
|
69247
|
+
return createModelValidationError(
|
|
69248
|
+
toolName,
|
|
69249
|
+
requestedModel,
|
|
69250
|
+
supportedModels
|
|
69251
|
+
);
|
|
69252
|
+
}
|
|
69253
|
+
return null;
|
|
69254
|
+
}
|
|
69255
|
+
function isMissingGenerateContentModelError(message, model) {
|
|
69256
|
+
return message.includes(`models/${model} is not found`) || message.includes("not supported for generateContent");
|
|
69257
|
+
}
|
|
67772
69258
|
async function analyzeMedia(args) {
|
|
67773
69259
|
const { prompt, media_source, mime_type, model, output_dir } = args;
|
|
69260
|
+
const catalog = await getToolModelCatalog();
|
|
69261
|
+
const requestedModel = model || DEFAULT_TEXT_MODEL;
|
|
69262
|
+
const validationError = await validateRequestedModel(
|
|
69263
|
+
"analyze_media",
|
|
69264
|
+
requestedModel,
|
|
69265
|
+
catalog.analyzeModels
|
|
69266
|
+
);
|
|
69267
|
+
if (validationError) {
|
|
69268
|
+
return validationError;
|
|
69269
|
+
}
|
|
67774
69270
|
let media;
|
|
67775
69271
|
try {
|
|
67776
69272
|
media = await resolveMediaSource(media_source, mime_type);
|
|
@@ -67785,28 +69281,43 @@ async function analyzeMedia(args) {
|
|
|
67785
69281
|
responseText = `[Mock] Analyzed media (${media.mimeType})
|
|
67786
69282
|
Source: ${media.label}
|
|
67787
69283
|
Prompt: "${prompt}"
|
|
67788
|
-
Model: ${
|
|
69284
|
+
Model: ${requestedModel}
|
|
67789
69285
|
|
|
67790
69286
|
Mock response \u2014 no API call made.`;
|
|
67791
69287
|
} else {
|
|
67792
|
-
|
|
67793
|
-
|
|
67794
|
-
|
|
67795
|
-
|
|
67796
|
-
|
|
67797
|
-
|
|
67798
|
-
|
|
67799
|
-
|
|
67800
|
-
|
|
67801
|
-
|
|
67802
|
-
|
|
69288
|
+
try {
|
|
69289
|
+
const response = await getAi().models.generateContent({
|
|
69290
|
+
model: requestedModel,
|
|
69291
|
+
contents: [
|
|
69292
|
+
{
|
|
69293
|
+
role: "user",
|
|
69294
|
+
parts: [
|
|
69295
|
+
{ text: prompt },
|
|
69296
|
+
{
|
|
69297
|
+
inlineData: {
|
|
69298
|
+
data: media.data,
|
|
69299
|
+
mimeType: media.mimeType
|
|
69300
|
+
}
|
|
67803
69301
|
}
|
|
67804
|
-
|
|
67805
|
-
|
|
67806
|
-
|
|
67807
|
-
|
|
67808
|
-
|
|
67809
|
-
|
|
69302
|
+
]
|
|
69303
|
+
}
|
|
69304
|
+
]
|
|
69305
|
+
});
|
|
69306
|
+
responseText = response.text || "No analysis generated.";
|
|
69307
|
+
} catch (error48) {
|
|
69308
|
+
const errorMessage = getErrorMessage(error48);
|
|
69309
|
+
if (isMissingGenerateContentModelError(errorMessage, requestedModel)) {
|
|
69310
|
+
return createModelValidationError(
|
|
69311
|
+
"analyze_media",
|
|
69312
|
+
requestedModel,
|
|
69313
|
+
catalog.analyzeModels
|
|
69314
|
+
);
|
|
69315
|
+
}
|
|
69316
|
+
if (isErrorWithStatusCode(error48)) {
|
|
69317
|
+
return createApiError(error48.message, error48.statusCode);
|
|
69318
|
+
}
|
|
69319
|
+
return createInternalError(error48);
|
|
69320
|
+
}
|
|
67810
69321
|
}
|
|
67811
69322
|
let savedPath;
|
|
67812
69323
|
if (output_dir) {
|
|
@@ -67842,59 +69353,53 @@ Mock response \u2014 no API call made.`;
|
|
|
67842
69353
|
}
|
|
67843
69354
|
async function listModels(args) {
|
|
67844
69355
|
const { capability } = args;
|
|
67845
|
-
|
|
67846
|
-
|
|
67847
|
-
|
|
67848
|
-
|
|
67849
|
-
|
|
67850
|
-
|
|
67851
|
-
|
|
67852
|
-
|
|
67853
|
-
|
|
67854
|
-
|
|
67855
|
-
|
|
67856
|
-
);
|
|
67857
|
-
}
|
|
67858
|
-
if (capability === "all" || capability === "video") {
|
|
67859
|
-
lines2.push(
|
|
67860
|
-
...formatModelLines(videoModels2, "### \u{1F3AC} Video Generation")
|
|
67861
|
-
);
|
|
67862
|
-
}
|
|
67863
|
-
return textResult(lines2.join("\n").trim(), {
|
|
67864
|
-
imageModels: capability === "video" ? [] : imageModels2,
|
|
67865
|
-
videoModels: capability === "image" ? [] : videoModels2
|
|
67866
|
-
});
|
|
67867
|
-
}
|
|
67868
|
-
const resp = await fetch(
|
|
67869
|
-
`https://generativelanguage.googleapis.com/v1beta/models?key=${getApiKey()}&pageSize=200`
|
|
67870
|
-
);
|
|
67871
|
-
if (!resp.ok) {
|
|
67872
|
-
return createApiError(
|
|
67873
|
-
"The model listing service is unavailable.",
|
|
67874
|
-
resp.status
|
|
69356
|
+
const catalog = await getToolModelCatalog();
|
|
69357
|
+
const analyzeModels = capability === "image" || capability === "video" ? [] : catalog.analyzeModels;
|
|
69358
|
+
const imageModels = capability === "analyze" || capability === "video" ? [] : catalog.imageModels;
|
|
69359
|
+
const videoModels = capability === "analyze" || capability === "image" ? [] : catalog.videoModels;
|
|
69360
|
+
const lines = ["## Available Gemini Models", ""];
|
|
69361
|
+
if (capability === "all" || capability === "analyze") {
|
|
69362
|
+
lines.push(
|
|
69363
|
+
...formatModelLines(
|
|
69364
|
+
analyzeModels,
|
|
69365
|
+
"### \u{1F3A7} analyze_media (`generateContent`)"
|
|
69366
|
+
)
|
|
67875
69367
|
);
|
|
67876
69368
|
}
|
|
67877
|
-
const data = await resp.json();
|
|
67878
|
-
const models = (data.models ?? []).map((model) => ({
|
|
67879
|
-
name: (model.name ?? "").replace("models/", ""),
|
|
67880
|
-
methods: model.supportedGenerationMethods ?? []
|
|
67881
|
-
}));
|
|
67882
|
-
const imageModels = models.filter((model) => model.methods.includes("predict")).map((model) => model.name).filter(Boolean);
|
|
67883
|
-
const videoModels = models.filter((model) => model.name.startsWith("veo")).map((model) => model.name).filter(Boolean);
|
|
67884
|
-
const lines = ["## Available Gemini Models", ""];
|
|
67885
69369
|
if (capability === "all" || capability === "image") {
|
|
67886
|
-
lines.push(
|
|
69370
|
+
lines.push(
|
|
69371
|
+
...formatModelLines(
|
|
69372
|
+
imageModels,
|
|
69373
|
+
"### \u{1F5BC}\uFE0F generate_image (`generateImages`)"
|
|
69374
|
+
)
|
|
69375
|
+
);
|
|
67887
69376
|
}
|
|
67888
69377
|
if (capability === "all" || capability === "video") {
|
|
67889
|
-
lines.push(
|
|
69378
|
+
lines.push(
|
|
69379
|
+
...formatModelLines(
|
|
69380
|
+
videoModels,
|
|
69381
|
+
"### \u{1F3AC} generate_video (`generateVideos`)"
|
|
69382
|
+
)
|
|
69383
|
+
);
|
|
67890
69384
|
}
|
|
67891
69385
|
return textResult(lines.join("\n").trim() || "No models found.", {
|
|
67892
|
-
|
|
67893
|
-
|
|
69386
|
+
analyzeModels,
|
|
69387
|
+
imageModels,
|
|
69388
|
+
videoModels
|
|
67894
69389
|
});
|
|
67895
69390
|
}
|
|
67896
69391
|
async function generateImage(args) {
|
|
67897
69392
|
const { prompt, aspect_ratio, model, output_dir } = args;
|
|
69393
|
+
const catalog = await getToolModelCatalog();
|
|
69394
|
+
const requestedModel = model || DEFAULT_IMAGE_MODEL;
|
|
69395
|
+
const validationError = await validateRequestedModel(
|
|
69396
|
+
"generate_image",
|
|
69397
|
+
requestedModel,
|
|
69398
|
+
catalog.imageModels
|
|
69399
|
+
);
|
|
69400
|
+
if (validationError) {
|
|
69401
|
+
return validationError;
|
|
69402
|
+
}
|
|
67898
69403
|
if (IS_MOCK) {
|
|
67899
69404
|
const mockBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
67900
69405
|
let savedPath;
|
|
@@ -67947,7 +69452,7 @@ Saved to: ${savedPath}` : ""}`
|
|
|
67947
69452
|
};
|
|
67948
69453
|
}
|
|
67949
69454
|
const response = await getAi().models.generateImages({
|
|
67950
|
-
model:
|
|
69455
|
+
model: requestedModel,
|
|
67951
69456
|
prompt,
|
|
67952
69457
|
config: { numberOfImages: 1, aspectRatio: aspect_ratio }
|
|
67953
69458
|
});
|
|
@@ -68001,6 +69506,16 @@ ${savedPaths.join("\n")}` : ""}`
|
|
|
68001
69506
|
}
|
|
68002
69507
|
async function generateVideo(args) {
|
|
68003
69508
|
const { prompt, model } = args;
|
|
69509
|
+
const catalog = await getToolModelCatalog();
|
|
69510
|
+
const requestedModel = model || DEFAULT_VIDEO_MODEL;
|
|
69511
|
+
const validationError = await validateRequestedModel(
|
|
69512
|
+
"generate_video",
|
|
69513
|
+
requestedModel,
|
|
69514
|
+
catalog.videoModels
|
|
69515
|
+
);
|
|
69516
|
+
if (validationError) {
|
|
69517
|
+
return validationError;
|
|
69518
|
+
}
|
|
68004
69519
|
if (IS_MOCK) {
|
|
68005
69520
|
const opName2 = "mock-operations/123456";
|
|
68006
69521
|
return textResult(
|
|
@@ -68013,7 +69528,7 @@ Call get_video_status to check progress.`,
|
|
|
68013
69528
|
);
|
|
68014
69529
|
}
|
|
68015
69530
|
const operation = await getAi().models.generateVideos({
|
|
68016
|
-
model:
|
|
69531
|
+
model: requestedModel,
|
|
68017
69532
|
prompt,
|
|
68018
69533
|
config: { numberOfVideos: 1 }
|
|
68019
69534
|
});
|
|
@@ -68140,26 +69655,30 @@ ${savedPaths.join("\n")}`);
|
|
|
68140
69655
|
}
|
|
68141
69656
|
async function handleToolCall(name, args) {
|
|
68142
69657
|
try {
|
|
69658
|
+
const toolDefinitions = await getToolDefinitions();
|
|
69659
|
+
const analyzeMediaTool = toolDefinitions[0];
|
|
69660
|
+
const listModelsTool = toolDefinitions[1];
|
|
69661
|
+
const generateImageTool = toolDefinitions[2];
|
|
69662
|
+
const generateVideoTool = toolDefinitions[3];
|
|
69663
|
+
const getVideoStatusTool = toolDefinitions[4];
|
|
68143
69664
|
switch (name) {
|
|
68144
69665
|
case "analyze_media":
|
|
68145
69666
|
return await analyzeMedia(
|
|
68146
|
-
|
|
69667
|
+
analyzeMediaTool.inputSchema.parse(args)
|
|
68147
69668
|
);
|
|
68148
69669
|
case "list_models":
|
|
68149
|
-
return await listModels(
|
|
68150
|
-
LIST_MODELS_TOOL.inputSchema.parse(args)
|
|
68151
|
-
);
|
|
69670
|
+
return await listModels(listModelsTool.inputSchema.parse(args));
|
|
68152
69671
|
case "generate_image":
|
|
68153
69672
|
return await generateImage(
|
|
68154
|
-
|
|
69673
|
+
generateImageTool.inputSchema.parse(args)
|
|
68155
69674
|
);
|
|
68156
69675
|
case "generate_video":
|
|
68157
69676
|
return await generateVideo(
|
|
68158
|
-
|
|
69677
|
+
generateVideoTool.inputSchema.parse(args)
|
|
68159
69678
|
);
|
|
68160
69679
|
case "get_video_status":
|
|
68161
69680
|
return await getVideoStatus(
|
|
68162
|
-
|
|
69681
|
+
getVideoStatusTool.inputSchema.parse(args)
|
|
68163
69682
|
);
|
|
68164
69683
|
default:
|
|
68165
69684
|
throw new Error(`Tool not found: ${name}`);
|
|
@@ -68177,9 +69696,9 @@ async function handleToolCall(name, args) {
|
|
|
68177
69696
|
return createInternalError(error48);
|
|
68178
69697
|
}
|
|
68179
69698
|
}
|
|
68180
|
-
server.setRequestHandler(ListToolsRequestSchema, async () =>
|
|
68181
|
-
tools:
|
|
68182
|
-
})
|
|
69699
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
69700
|
+
return { tools: await getListedToolDefinitions() };
|
|
69701
|
+
});
|
|
68183
69702
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
68184
69703
|
const { name, arguments: args } = request.params;
|
|
68185
69704
|
return handleToolCall(name, args);
|
|
@@ -68208,6 +69727,8 @@ if (isMainModule(import.meta.url)) {
|
|
|
68208
69727
|
}
|
|
68209
69728
|
export {
|
|
68210
69729
|
TOOL_DEFINITIONS,
|
|
69730
|
+
getListedToolDefinitions,
|
|
69731
|
+
getToolDefinitions,
|
|
68211
69732
|
handleToolCall,
|
|
68212
69733
|
runServer
|
|
68213
69734
|
};
|