@intlayer/ai 7.5.2-canary.1 → 7.5.2
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/assets/auditDictionaryMetadata/EXAMPLE_REQUEST.md +21 -0
- package/dist/assets/auditDictionaryMetadata/EXAMPLE_RESPONSE.md +1 -0
- package/dist/assets/auditDictionaryMetadata/PROMPT.md +0 -41
- package/dist/assets/translateJSON/PROMPT.md +25 -29
- package/dist/cjs/aiSdk.cjs +1 -1
- package/dist/cjs/aiSdk.cjs.map +1 -1
- package/dist/cjs/auditDictionaryMetadata/index.cjs +30 -15
- package/dist/cjs/auditDictionaryMetadata/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/errors.cjs +30 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/errors.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/iso.cjs +41 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/iso.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/parse.cjs +31 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/parse.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/schemas.cjs +577 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/schemas.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/api.cjs +535 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/api.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/checks.cjs +376 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/checks.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/core.cjs +67 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/core.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/doc.cjs +35 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/doc.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/errors.cjs +66 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/errors.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/json-schema-processors.cjs +239 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/json-schema-processors.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/parse.cjs +123 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/parse.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/regexes.cjs +88 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/regexes.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/registries.cjs +54 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/registries.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/schemas.cjs +1048 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/schemas.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/to-json-schema.cjs +263 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/to-json-schema.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/util.cjs +350 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/util.cjs.map +1 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/versions.cjs +11 -0
- package/dist/cjs/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/versions.cjs.map +1 -0
- package/dist/cjs/translateJSON/index.cjs +29 -6
- package/dist/cjs/translateJSON/index.cjs.map +1 -1
- package/dist/esm/aiSdk.mjs +1 -1
- package/dist/esm/aiSdk.mjs.map +1 -1
- package/dist/esm/auditDictionaryMetadata/index.mjs +31 -16
- package/dist/esm/auditDictionaryMetadata/index.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/errors.mjs +30 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/errors.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/iso.mjs +38 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/iso.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/parse.mjs +20 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/parse.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/schemas.mjs +571 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/schemas.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/api.mjs +478 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/api.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/checks.mjs +361 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/checks.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/core.mjs +62 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/core.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/doc.mjs +34 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/doc.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/errors.mjs +63 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/errors.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/json-schema-processors.mjs +219 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/json-schema-processors.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/parse.mjs +110 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/parse.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/regexes.mjs +61 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/regexes.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/registries.mjs +53 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/registries.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/schemas.mjs +1002 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/schemas.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/to-json-schema.mjs +261 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/to-json-schema.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/util.mjs +317 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/util.mjs.map +1 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/versions.mjs +10 -0
- package/dist/esm/node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/versions.mjs.map +1 -0
- package/dist/esm/translateJSON/index.mjs +30 -7
- package/dist/esm/translateJSON/index.mjs.map +1 -1
- package/dist/types/translateJSON/index.d.ts +7 -7
- package/dist/types/translateJSON/index.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
|
|
2
|
+
//#region ../../../node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/util.js
|
|
3
|
+
function getEnumValues(entries) {
|
|
4
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
5
|
+
return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
6
|
+
}
|
|
7
|
+
function jsonStringifyReplacer(_, value) {
|
|
8
|
+
if (typeof value === "bigint") return value.toString();
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function cached(getter) {
|
|
12
|
+
return { get value() {
|
|
13
|
+
{
|
|
14
|
+
const value = getter();
|
|
15
|
+
Object.defineProperty(this, "value", { value });
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
throw new Error("cached value already set");
|
|
19
|
+
} };
|
|
20
|
+
}
|
|
21
|
+
function nullish(input) {
|
|
22
|
+
return input === null || input === void 0;
|
|
23
|
+
}
|
|
24
|
+
function cleanRegex(source) {
|
|
25
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
26
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
27
|
+
return source.slice(start, end);
|
|
28
|
+
}
|
|
29
|
+
function floatSafeRemainder(val, step) {
|
|
30
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
31
|
+
const stepString = step.toString();
|
|
32
|
+
let stepDecCount = (stepString.split(".")[1] || "").length;
|
|
33
|
+
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
|
34
|
+
const match = stepString.match(/\d?e-(\d?)/);
|
|
35
|
+
if (match?.[1]) stepDecCount = Number.parseInt(match[1]);
|
|
36
|
+
}
|
|
37
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
38
|
+
return Number.parseInt(val.toFixed(decCount).replace(".", "")) % Number.parseInt(step.toFixed(decCount).replace(".", "")) / 10 ** decCount;
|
|
39
|
+
}
|
|
40
|
+
const EVALUATING = Symbol("evaluating");
|
|
41
|
+
function defineLazy(object, key, getter) {
|
|
42
|
+
let value = void 0;
|
|
43
|
+
Object.defineProperty(object, key, {
|
|
44
|
+
get() {
|
|
45
|
+
if (value === EVALUATING) return;
|
|
46
|
+
if (value === void 0) {
|
|
47
|
+
value = EVALUATING;
|
|
48
|
+
value = getter();
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
},
|
|
52
|
+
set(v) {
|
|
53
|
+
Object.defineProperty(object, key, { value: v });
|
|
54
|
+
},
|
|
55
|
+
configurable: true
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function assignProp(target, prop, value) {
|
|
59
|
+
Object.defineProperty(target, prop, {
|
|
60
|
+
value,
|
|
61
|
+
writable: true,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function mergeDefs(...defs) {
|
|
67
|
+
const mergedDescriptors = {};
|
|
68
|
+
for (const def of defs) {
|
|
69
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
70
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
71
|
+
}
|
|
72
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
73
|
+
}
|
|
74
|
+
function esc(str) {
|
|
75
|
+
return JSON.stringify(str);
|
|
76
|
+
}
|
|
77
|
+
function slugify(input) {
|
|
78
|
+
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
79
|
+
}
|
|
80
|
+
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
|
|
81
|
+
function isObject(data) {
|
|
82
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
83
|
+
}
|
|
84
|
+
const allowsEval = cached(() => {
|
|
85
|
+
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
86
|
+
try {
|
|
87
|
+
new Function("");
|
|
88
|
+
return true;
|
|
89
|
+
} catch (_) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
function isPlainObject(o) {
|
|
94
|
+
if (isObject(o) === false) return false;
|
|
95
|
+
const ctor = o.constructor;
|
|
96
|
+
if (ctor === void 0) return true;
|
|
97
|
+
if (typeof ctor !== "function") return true;
|
|
98
|
+
const prot = ctor.prototype;
|
|
99
|
+
if (isObject(prot) === false) return false;
|
|
100
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function shallowClone(o) {
|
|
104
|
+
if (isPlainObject(o)) return { ...o };
|
|
105
|
+
if (Array.isArray(o)) return [...o];
|
|
106
|
+
return o;
|
|
107
|
+
}
|
|
108
|
+
const propertyKeyTypes = new Set([
|
|
109
|
+
"string",
|
|
110
|
+
"number",
|
|
111
|
+
"symbol"
|
|
112
|
+
]);
|
|
113
|
+
function escapeRegex(str) {
|
|
114
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
115
|
+
}
|
|
116
|
+
function clone(inst, def, params) {
|
|
117
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
118
|
+
if (!def || params?.parent) cl._zod.parent = inst;
|
|
119
|
+
return cl;
|
|
120
|
+
}
|
|
121
|
+
function normalizeParams(_params) {
|
|
122
|
+
const params = _params;
|
|
123
|
+
if (!params) return {};
|
|
124
|
+
if (typeof params === "string") return { error: () => params };
|
|
125
|
+
if (params?.message !== void 0) {
|
|
126
|
+
if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
|
|
127
|
+
params.error = params.message;
|
|
128
|
+
}
|
|
129
|
+
delete params.message;
|
|
130
|
+
if (typeof params.error === "string") return {
|
|
131
|
+
...params,
|
|
132
|
+
error: () => params.error
|
|
133
|
+
};
|
|
134
|
+
return params;
|
|
135
|
+
}
|
|
136
|
+
function optionalKeys(shape) {
|
|
137
|
+
return Object.keys(shape).filter((k) => {
|
|
138
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const NUMBER_FORMAT_RANGES = {
|
|
142
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
143
|
+
int32: [-2147483648, 2147483647],
|
|
144
|
+
uint32: [0, 4294967295],
|
|
145
|
+
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
146
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
147
|
+
};
|
|
148
|
+
function pick(schema, mask) {
|
|
149
|
+
const currDef = schema._zod.def;
|
|
150
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
151
|
+
get shape() {
|
|
152
|
+
const newShape = {};
|
|
153
|
+
for (const key in mask) {
|
|
154
|
+
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
155
|
+
if (!mask[key]) continue;
|
|
156
|
+
newShape[key] = currDef.shape[key];
|
|
157
|
+
}
|
|
158
|
+
assignProp(this, "shape", newShape);
|
|
159
|
+
return newShape;
|
|
160
|
+
},
|
|
161
|
+
checks: []
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
function omit(schema, mask) {
|
|
165
|
+
const currDef = schema._zod.def;
|
|
166
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
167
|
+
get shape() {
|
|
168
|
+
const newShape = { ...schema._zod.def.shape };
|
|
169
|
+
for (const key in mask) {
|
|
170
|
+
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
171
|
+
if (!mask[key]) continue;
|
|
172
|
+
delete newShape[key];
|
|
173
|
+
}
|
|
174
|
+
assignProp(this, "shape", newShape);
|
|
175
|
+
return newShape;
|
|
176
|
+
},
|
|
177
|
+
checks: []
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
function extend(schema, shape) {
|
|
181
|
+
if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
|
|
182
|
+
const checks = schema._zod.def.checks;
|
|
183
|
+
if (checks && checks.length > 0) throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
|
|
184
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
185
|
+
get shape() {
|
|
186
|
+
const _shape = {
|
|
187
|
+
...schema._zod.def.shape,
|
|
188
|
+
...shape
|
|
189
|
+
};
|
|
190
|
+
assignProp(this, "shape", _shape);
|
|
191
|
+
return _shape;
|
|
192
|
+
},
|
|
193
|
+
checks: []
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
function safeExtend(schema, shape) {
|
|
197
|
+
if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
198
|
+
return clone(schema, {
|
|
199
|
+
...schema._zod.def,
|
|
200
|
+
get shape() {
|
|
201
|
+
const _shape = {
|
|
202
|
+
...schema._zod.def.shape,
|
|
203
|
+
...shape
|
|
204
|
+
};
|
|
205
|
+
assignProp(this, "shape", _shape);
|
|
206
|
+
return _shape;
|
|
207
|
+
},
|
|
208
|
+
checks: schema._zod.def.checks
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function merge(a, b) {
|
|
212
|
+
return clone(a, mergeDefs(a._zod.def, {
|
|
213
|
+
get shape() {
|
|
214
|
+
const _shape = {
|
|
215
|
+
...a._zod.def.shape,
|
|
216
|
+
...b._zod.def.shape
|
|
217
|
+
};
|
|
218
|
+
assignProp(this, "shape", _shape);
|
|
219
|
+
return _shape;
|
|
220
|
+
},
|
|
221
|
+
get catchall() {
|
|
222
|
+
return b._zod.def.catchall;
|
|
223
|
+
},
|
|
224
|
+
checks: []
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
function partial(Class, schema, mask) {
|
|
228
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
229
|
+
get shape() {
|
|
230
|
+
const oldShape = schema._zod.def.shape;
|
|
231
|
+
const shape = { ...oldShape };
|
|
232
|
+
if (mask) for (const key in mask) {
|
|
233
|
+
if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
234
|
+
if (!mask[key]) continue;
|
|
235
|
+
shape[key] = Class ? new Class({
|
|
236
|
+
type: "optional",
|
|
237
|
+
innerType: oldShape[key]
|
|
238
|
+
}) : oldShape[key];
|
|
239
|
+
}
|
|
240
|
+
else for (const key in oldShape) shape[key] = Class ? new Class({
|
|
241
|
+
type: "optional",
|
|
242
|
+
innerType: oldShape[key]
|
|
243
|
+
}) : oldShape[key];
|
|
244
|
+
assignProp(this, "shape", shape);
|
|
245
|
+
return shape;
|
|
246
|
+
},
|
|
247
|
+
checks: []
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
function required(Class, schema, mask) {
|
|
251
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
252
|
+
get shape() {
|
|
253
|
+
const oldShape = schema._zod.def.shape;
|
|
254
|
+
const shape = { ...oldShape };
|
|
255
|
+
if (mask) for (const key in mask) {
|
|
256
|
+
if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
257
|
+
if (!mask[key]) continue;
|
|
258
|
+
shape[key] = new Class({
|
|
259
|
+
type: "nonoptional",
|
|
260
|
+
innerType: oldShape[key]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else for (const key in oldShape) shape[key] = new Class({
|
|
264
|
+
type: "nonoptional",
|
|
265
|
+
innerType: oldShape[key]
|
|
266
|
+
});
|
|
267
|
+
assignProp(this, "shape", shape);
|
|
268
|
+
return shape;
|
|
269
|
+
},
|
|
270
|
+
checks: []
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
function aborted(x, startIndex = 0) {
|
|
274
|
+
if (x.aborted === true) return true;
|
|
275
|
+
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
function prefixIssues(path, issues) {
|
|
279
|
+
return issues.map((iss) => {
|
|
280
|
+
var _a;
|
|
281
|
+
(_a = iss).path ?? (_a.path = []);
|
|
282
|
+
iss.path.unshift(path);
|
|
283
|
+
return iss;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function unwrapMessage(message) {
|
|
287
|
+
return typeof message === "string" ? message : message?.message;
|
|
288
|
+
}
|
|
289
|
+
function finalizeIssue(iss, ctx, config) {
|
|
290
|
+
const full = {
|
|
291
|
+
...iss,
|
|
292
|
+
path: iss.path ?? []
|
|
293
|
+
};
|
|
294
|
+
if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
|
|
295
|
+
delete full.inst;
|
|
296
|
+
delete full.continue;
|
|
297
|
+
if (!ctx?.reportInput) delete full.input;
|
|
298
|
+
return full;
|
|
299
|
+
}
|
|
300
|
+
function getLengthableOrigin(input) {
|
|
301
|
+
if (Array.isArray(input)) return "array";
|
|
302
|
+
if (typeof input === "string") return "string";
|
|
303
|
+
return "unknown";
|
|
304
|
+
}
|
|
305
|
+
function issue(...args) {
|
|
306
|
+
const [iss, input, inst] = args;
|
|
307
|
+
if (typeof iss === "string") return {
|
|
308
|
+
message: iss,
|
|
309
|
+
code: "custom",
|
|
310
|
+
input,
|
|
311
|
+
inst
|
|
312
|
+
};
|
|
313
|
+
return { ...iss };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
//#endregion
|
|
317
|
+
exports.NUMBER_FORMAT_RANGES = NUMBER_FORMAT_RANGES;
|
|
318
|
+
exports.aborted = aborted;
|
|
319
|
+
exports.allowsEval = allowsEval;
|
|
320
|
+
exports.cached = cached;
|
|
321
|
+
exports.captureStackTrace = captureStackTrace;
|
|
322
|
+
exports.cleanRegex = cleanRegex;
|
|
323
|
+
exports.clone = clone;
|
|
324
|
+
exports.defineLazy = defineLazy;
|
|
325
|
+
exports.esc = esc;
|
|
326
|
+
exports.escapeRegex = escapeRegex;
|
|
327
|
+
exports.extend = extend;
|
|
328
|
+
exports.finalizeIssue = finalizeIssue;
|
|
329
|
+
exports.floatSafeRemainder = floatSafeRemainder;
|
|
330
|
+
exports.getEnumValues = getEnumValues;
|
|
331
|
+
exports.getLengthableOrigin = getLengthableOrigin;
|
|
332
|
+
exports.isObject = isObject;
|
|
333
|
+
exports.isPlainObject = isPlainObject;
|
|
334
|
+
exports.issue = issue;
|
|
335
|
+
exports.jsonStringifyReplacer = jsonStringifyReplacer;
|
|
336
|
+
exports.merge = merge;
|
|
337
|
+
exports.mergeDefs = mergeDefs;
|
|
338
|
+
exports.normalizeParams = normalizeParams;
|
|
339
|
+
exports.nullish = nullish;
|
|
340
|
+
exports.omit = omit;
|
|
341
|
+
exports.optionalKeys = optionalKeys;
|
|
342
|
+
exports.partial = partial;
|
|
343
|
+
exports.pick = pick;
|
|
344
|
+
exports.prefixIssues = prefixIssues;
|
|
345
|
+
exports.propertyKeyTypes = propertyKeyTypes;
|
|
346
|
+
exports.required = required;
|
|
347
|
+
exports.safeExtend = safeExtend;
|
|
348
|
+
exports.shallowClone = shallowClone;
|
|
349
|
+
exports.slugify = slugify;
|
|
350
|
+
//# sourceMappingURL=util.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.cjs","names":[],"sources":["../../../../../../../../../../../../node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/util.js"],"sourcesContent":["// functions\nexport function assertEqual(val) {\n return val;\n}\nexport function assertNotEqual(val) {\n return val;\n}\nexport function assertIs(_arg) { }\nexport function assertNever(_x) {\n throw new Error(\"Unexpected value in exhaustive check\");\n}\nexport function assert(_) { }\nexport function getEnumValues(entries) {\n const numericValues = Object.values(entries).filter((v) => typeof v === \"number\");\n const values = Object.entries(entries)\n .filter(([k, _]) => numericValues.indexOf(+k) === -1)\n .map(([_, v]) => v);\n return values;\n}\nexport function joinValues(array, separator = \"|\") {\n return array.map((val) => stringifyPrimitive(val)).join(separator);\n}\nexport function jsonStringifyReplacer(_, value) {\n if (typeof value === \"bigint\")\n return value.toString();\n return value;\n}\nexport function cached(getter) {\n const set = false;\n return {\n get value() {\n if (!set) {\n const value = getter();\n Object.defineProperty(this, \"value\", { value });\n return value;\n }\n throw new Error(\"cached value already set\");\n },\n };\n}\nexport function nullish(input) {\n return input === null || input === undefined;\n}\nexport function cleanRegex(source) {\n const start = source.startsWith(\"^\") ? 1 : 0;\n const end = source.endsWith(\"$\") ? source.length - 1 : source.length;\n return source.slice(start, end);\n}\nexport function floatSafeRemainder(val, step) {\n const valDecCount = (val.toString().split(\".\")[1] || \"\").length;\n const stepString = step.toString();\n let stepDecCount = (stepString.split(\".\")[1] || \"\").length;\n if (stepDecCount === 0 && /\\d?e-\\d?/.test(stepString)) {\n const match = stepString.match(/\\d?e-(\\d?)/);\n if (match?.[1]) {\n stepDecCount = Number.parseInt(match[1]);\n }\n }\n const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;\n const valInt = Number.parseInt(val.toFixed(decCount).replace(\".\", \"\"));\n const stepInt = Number.parseInt(step.toFixed(decCount).replace(\".\", \"\"));\n return (valInt % stepInt) / 10 ** decCount;\n}\nconst EVALUATING = Symbol(\"evaluating\");\nexport function defineLazy(object, key, getter) {\n let value = undefined;\n Object.defineProperty(object, key, {\n get() {\n if (value === EVALUATING) {\n // Circular reference detected, return undefined to break the cycle\n return undefined;\n }\n if (value === undefined) {\n value = EVALUATING;\n value = getter();\n }\n return value;\n },\n set(v) {\n Object.defineProperty(object, key, {\n value: v,\n // configurable: true,\n });\n // object[key] = v;\n },\n configurable: true,\n });\n}\nexport function objectClone(obj) {\n return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));\n}\nexport function assignProp(target, prop, value) {\n Object.defineProperty(target, prop, {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n}\nexport function mergeDefs(...defs) {\n const mergedDescriptors = {};\n for (const def of defs) {\n const descriptors = Object.getOwnPropertyDescriptors(def);\n Object.assign(mergedDescriptors, descriptors);\n }\n return Object.defineProperties({}, mergedDescriptors);\n}\nexport function cloneDef(schema) {\n return mergeDefs(schema._zod.def);\n}\nexport function getElementAtPath(obj, path) {\n if (!path)\n return obj;\n return path.reduce((acc, key) => acc?.[key], obj);\n}\nexport function promiseAllObject(promisesObj) {\n const keys = Object.keys(promisesObj);\n const promises = keys.map((key) => promisesObj[key]);\n return Promise.all(promises).then((results) => {\n const resolvedObj = {};\n for (let i = 0; i < keys.length; i++) {\n resolvedObj[keys[i]] = results[i];\n }\n return resolvedObj;\n });\n}\nexport function randomString(length = 10) {\n const chars = \"abcdefghijklmnopqrstuvwxyz\";\n let str = \"\";\n for (let i = 0; i < length; i++) {\n str += chars[Math.floor(Math.random() * chars.length)];\n }\n return str;\n}\nexport function esc(str) {\n return JSON.stringify(str);\n}\nexport function slugify(input) {\n return input\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, \"\")\n .replace(/[\\s_-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n}\nexport const captureStackTrace = (\"captureStackTrace\" in Error ? Error.captureStackTrace : (..._args) => { });\nexport function isObject(data) {\n return typeof data === \"object\" && data !== null && !Array.isArray(data);\n}\nexport const allowsEval = cached(() => {\n // @ts-ignore\n if (typeof navigator !== \"undefined\" && navigator?.userAgent?.includes(\"Cloudflare\")) {\n return false;\n }\n try {\n const F = Function;\n new F(\"\");\n return true;\n }\n catch (_) {\n return false;\n }\n});\nexport function isPlainObject(o) {\n if (isObject(o) === false)\n return false;\n // modified constructor\n const ctor = o.constructor;\n if (ctor === undefined)\n return true;\n if (typeof ctor !== \"function\")\n return true;\n // modified prototype\n const prot = ctor.prototype;\n if (isObject(prot) === false)\n return false;\n // ctor doesn't have static `isPrototypeOf`\n if (Object.prototype.hasOwnProperty.call(prot, \"isPrototypeOf\") === false) {\n return false;\n }\n return true;\n}\nexport function shallowClone(o) {\n if (isPlainObject(o))\n return { ...o };\n if (Array.isArray(o))\n return [...o];\n return o;\n}\nexport function numKeys(data) {\n let keyCount = 0;\n for (const key in data) {\n if (Object.prototype.hasOwnProperty.call(data, key)) {\n keyCount++;\n }\n }\n return keyCount;\n}\nexport const getParsedType = (data) => {\n const t = typeof data;\n switch (t) {\n case \"undefined\":\n return \"undefined\";\n case \"string\":\n return \"string\";\n case \"number\":\n return Number.isNaN(data) ? \"nan\" : \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"function\":\n return \"function\";\n case \"bigint\":\n return \"bigint\";\n case \"symbol\":\n return \"symbol\";\n case \"object\":\n if (Array.isArray(data)) {\n return \"array\";\n }\n if (data === null) {\n return \"null\";\n }\n if (data.then && typeof data.then === \"function\" && data.catch && typeof data.catch === \"function\") {\n return \"promise\";\n }\n if (typeof Map !== \"undefined\" && data instanceof Map) {\n return \"map\";\n }\n if (typeof Set !== \"undefined\" && data instanceof Set) {\n return \"set\";\n }\n if (typeof Date !== \"undefined\" && data instanceof Date) {\n return \"date\";\n }\n // @ts-ignore\n if (typeof File !== \"undefined\" && data instanceof File) {\n return \"file\";\n }\n return \"object\";\n default:\n throw new Error(`Unknown data type: ${t}`);\n }\n};\nexport const propertyKeyTypes = new Set([\"string\", \"number\", \"symbol\"]);\nexport const primitiveTypes = new Set([\"string\", \"number\", \"bigint\", \"boolean\", \"symbol\", \"undefined\"]);\nexport function escapeRegex(str) {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n// zod-specific utils\nexport function clone(inst, def, params) {\n const cl = new inst._zod.constr(def ?? inst._zod.def);\n if (!def || params?.parent)\n cl._zod.parent = inst;\n return cl;\n}\nexport function normalizeParams(_params) {\n const params = _params;\n if (!params)\n return {};\n if (typeof params === \"string\")\n return { error: () => params };\n if (params?.message !== undefined) {\n if (params?.error !== undefined)\n throw new Error(\"Cannot specify both `message` and `error` params\");\n params.error = params.message;\n }\n delete params.message;\n if (typeof params.error === \"string\")\n return { ...params, error: () => params.error };\n return params;\n}\nexport function createTransparentProxy(getter) {\n let target;\n return new Proxy({}, {\n get(_, prop, receiver) {\n target ?? (target = getter());\n return Reflect.get(target, prop, receiver);\n },\n set(_, prop, value, receiver) {\n target ?? (target = getter());\n return Reflect.set(target, prop, value, receiver);\n },\n has(_, prop) {\n target ?? (target = getter());\n return Reflect.has(target, prop);\n },\n deleteProperty(_, prop) {\n target ?? (target = getter());\n return Reflect.deleteProperty(target, prop);\n },\n ownKeys(_) {\n target ?? (target = getter());\n return Reflect.ownKeys(target);\n },\n getOwnPropertyDescriptor(_, prop) {\n target ?? (target = getter());\n return Reflect.getOwnPropertyDescriptor(target, prop);\n },\n defineProperty(_, prop, descriptor) {\n target ?? (target = getter());\n return Reflect.defineProperty(target, prop, descriptor);\n },\n });\n}\nexport function stringifyPrimitive(value) {\n if (typeof value === \"bigint\")\n return value.toString() + \"n\";\n if (typeof value === \"string\")\n return `\"${value}\"`;\n return `${value}`;\n}\nexport function optionalKeys(shape) {\n return Object.keys(shape).filter((k) => {\n return shape[k]._zod.optin === \"optional\" && shape[k]._zod.optout === \"optional\";\n });\n}\nexport const NUMBER_FORMAT_RANGES = {\n safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],\n int32: [-2147483648, 2147483647],\n uint32: [0, 4294967295],\n float32: [-3.4028234663852886e38, 3.4028234663852886e38],\n float64: [-Number.MAX_VALUE, Number.MAX_VALUE],\n};\nexport const BIGINT_FORMAT_RANGES = {\n int64: [/* @__PURE__*/ BigInt(\"-9223372036854775808\"), /* @__PURE__*/ BigInt(\"9223372036854775807\")],\n uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt(\"18446744073709551615\")],\n};\nexport function pick(schema, mask) {\n const currDef = schema._zod.def;\n const def = mergeDefs(schema._zod.def, {\n get shape() {\n const newShape = {};\n for (const key in mask) {\n if (!(key in currDef.shape)) {\n throw new Error(`Unrecognized key: \"${key}\"`);\n }\n if (!mask[key])\n continue;\n newShape[key] = currDef.shape[key];\n }\n assignProp(this, \"shape\", newShape); // self-caching\n return newShape;\n },\n checks: [],\n });\n return clone(schema, def);\n}\nexport function omit(schema, mask) {\n const currDef = schema._zod.def;\n const def = mergeDefs(schema._zod.def, {\n get shape() {\n const newShape = { ...schema._zod.def.shape };\n for (const key in mask) {\n if (!(key in currDef.shape)) {\n throw new Error(`Unrecognized key: \"${key}\"`);\n }\n if (!mask[key])\n continue;\n delete newShape[key];\n }\n assignProp(this, \"shape\", newShape); // self-caching\n return newShape;\n },\n checks: [],\n });\n return clone(schema, def);\n}\nexport function extend(schema, shape) {\n if (!isPlainObject(shape)) {\n throw new Error(\"Invalid input to extend: expected a plain object\");\n }\n const checks = schema._zod.def.checks;\n const hasChecks = checks && checks.length > 0;\n if (hasChecks) {\n throw new Error(\"Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.\");\n }\n const def = mergeDefs(schema._zod.def, {\n get shape() {\n const _shape = { ...schema._zod.def.shape, ...shape };\n assignProp(this, \"shape\", _shape); // self-caching\n return _shape;\n },\n checks: [],\n });\n return clone(schema, def);\n}\nexport function safeExtend(schema, shape) {\n if (!isPlainObject(shape)) {\n throw new Error(\"Invalid input to safeExtend: expected a plain object\");\n }\n const def = {\n ...schema._zod.def,\n get shape() {\n const _shape = { ...schema._zod.def.shape, ...shape };\n assignProp(this, \"shape\", _shape); // self-caching\n return _shape;\n },\n checks: schema._zod.def.checks,\n };\n return clone(schema, def);\n}\nexport function merge(a, b) {\n const def = mergeDefs(a._zod.def, {\n get shape() {\n const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };\n assignProp(this, \"shape\", _shape); // self-caching\n return _shape;\n },\n get catchall() {\n return b._zod.def.catchall;\n },\n checks: [], // delete existing checks\n });\n return clone(a, def);\n}\nexport function partial(Class, schema, mask) {\n const def = mergeDefs(schema._zod.def, {\n get shape() {\n const oldShape = schema._zod.def.shape;\n const shape = { ...oldShape };\n if (mask) {\n for (const key in mask) {\n if (!(key in oldShape)) {\n throw new Error(`Unrecognized key: \"${key}\"`);\n }\n if (!mask[key])\n continue;\n // if (oldShape[key]!._zod.optin === \"optional\") continue;\n shape[key] = Class\n ? new Class({\n type: \"optional\",\n innerType: oldShape[key],\n })\n : oldShape[key];\n }\n }\n else {\n for (const key in oldShape) {\n // if (oldShape[key]!._zod.optin === \"optional\") continue;\n shape[key] = Class\n ? new Class({\n type: \"optional\",\n innerType: oldShape[key],\n })\n : oldShape[key];\n }\n }\n assignProp(this, \"shape\", shape); // self-caching\n return shape;\n },\n checks: [],\n });\n return clone(schema, def);\n}\nexport function required(Class, schema, mask) {\n const def = mergeDefs(schema._zod.def, {\n get shape() {\n const oldShape = schema._zod.def.shape;\n const shape = { ...oldShape };\n if (mask) {\n for (const key in mask) {\n if (!(key in shape)) {\n throw new Error(`Unrecognized key: \"${key}\"`);\n }\n if (!mask[key])\n continue;\n // overwrite with non-optional\n shape[key] = new Class({\n type: \"nonoptional\",\n innerType: oldShape[key],\n });\n }\n }\n else {\n for (const key in oldShape) {\n // overwrite with non-optional\n shape[key] = new Class({\n type: \"nonoptional\",\n innerType: oldShape[key],\n });\n }\n }\n assignProp(this, \"shape\", shape); // self-caching\n return shape;\n },\n checks: [],\n });\n return clone(schema, def);\n}\n// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom\nexport function aborted(x, startIndex = 0) {\n if (x.aborted === true)\n return true;\n for (let i = startIndex; i < x.issues.length; i++) {\n if (x.issues[i]?.continue !== true) {\n return true;\n }\n }\n return false;\n}\nexport function prefixIssues(path, issues) {\n return issues.map((iss) => {\n var _a;\n (_a = iss).path ?? (_a.path = []);\n iss.path.unshift(path);\n return iss;\n });\n}\nexport function unwrapMessage(message) {\n return typeof message === \"string\" ? message : message?.message;\n}\nexport function finalizeIssue(iss, ctx, config) {\n const full = { ...iss, path: iss.path ?? [] };\n // for backwards compatibility\n if (!iss.message) {\n const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??\n unwrapMessage(ctx?.error?.(iss)) ??\n unwrapMessage(config.customError?.(iss)) ??\n unwrapMessage(config.localeError?.(iss)) ??\n \"Invalid input\";\n full.message = message;\n }\n // delete (full as any).def;\n delete full.inst;\n delete full.continue;\n if (!ctx?.reportInput) {\n delete full.input;\n }\n return full;\n}\nexport function getSizableOrigin(input) {\n if (input instanceof Set)\n return \"set\";\n if (input instanceof Map)\n return \"map\";\n // @ts-ignore\n if (input instanceof File)\n return \"file\";\n return \"unknown\";\n}\nexport function getLengthableOrigin(input) {\n if (Array.isArray(input))\n return \"array\";\n if (typeof input === \"string\")\n return \"string\";\n return \"unknown\";\n}\nexport function issue(...args) {\n const [iss, input, inst] = args;\n if (typeof iss === \"string\") {\n return {\n message: iss,\n code: \"custom\",\n input,\n inst,\n };\n }\n return { ...iss };\n}\nexport function cleanEnum(obj) {\n return Object.entries(obj)\n .filter(([k, _]) => {\n // return true if NaN, meaning it's not a number, thus a string key\n return Number.isNaN(Number.parseInt(k, 10));\n })\n .map((el) => el[1]);\n}\n// Codec utility functions\nexport function base64ToUint8Array(base64) {\n const binaryString = atob(base64);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n return bytes;\n}\nexport function uint8ArrayToBase64(bytes) {\n let binaryString = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binaryString += String.fromCharCode(bytes[i]);\n }\n return btoa(binaryString);\n}\nexport function base64urlToUint8Array(base64url) {\n const base64 = base64url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padding = \"=\".repeat((4 - (base64.length % 4)) % 4);\n return base64ToUint8Array(base64 + padding);\n}\nexport function uint8ArrayToBase64url(bytes) {\n return uint8ArrayToBase64(bytes).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=/g, \"\");\n}\nexport function hexToUint8Array(hex) {\n const cleanHex = hex.replace(/^0x/, \"\");\n if (cleanHex.length % 2 !== 0) {\n throw new Error(\"Invalid hex string length\");\n }\n const bytes = new Uint8Array(cleanHex.length / 2);\n for (let i = 0; i < cleanHex.length; i += 2) {\n bytes[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);\n }\n return bytes;\n}\nexport function uint8ArrayToHex(bytes) {\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n// instanceof\nexport class Class {\n constructor(..._args) { }\n}\n"],"x_google_ignoreList":[0],"mappings":";;AAYA,SAAgB,cAAc,SAAS;CACnC,MAAM,gBAAgB,OAAO,OAAO,QAAQ,CAAC,QAAQ,MAAM,OAAO,MAAM,SAAS;AAIjF,QAHe,OAAO,QAAQ,QAAQ,CACjC,QAAQ,CAAC,GAAG,OAAO,cAAc,QAAQ,CAAC,EAAE,KAAK,GAAG,CACpD,KAAK,CAAC,GAAG,OAAO,EAAE;;AAM3B,SAAgB,sBAAsB,GAAG,OAAO;AAC5C,KAAI,OAAO,UAAU,SACjB,QAAO,MAAM,UAAU;AAC3B,QAAO;;AAEX,SAAgB,OAAO,QAAQ;AAE3B,QAAO,EACH,IAAI,QAAQ;EACE;GACN,MAAM,QAAQ,QAAQ;AACtB,UAAO,eAAe,MAAM,SAAS,EAAE,OAAO,CAAC;AAC/C,UAAO;;AAEX,QAAM,IAAI,MAAM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AO;AACvC,KAAI,MAAM,QAAQ,MAAM,CACpB,QAAO;AACX,KAAI,OAAO,UAAU,SACjB,QAAO;AACX,QAAO;;AAEX,SAAgB,MAAM,GAAG,MAAM;CAC3B,MAAM,CAAC,KAAK,OAAO,QAAQ;AAC3B,KAAI,OAAO,QAAQ,SACf,QAAO;EACH,SAAS;EACT,MAAM;EACN;EACA;EACH;AAEL,QAAO,EAAE,GAAG,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.cjs","names":[],"sources":["../../../../../../../../../../../../node_modules/.bun/zod@4.2.1/node_modules/zod/v4/core/versions.js"],"sourcesContent":["export const version = {\n major: 4,\n minor: 2,\n patch: 1,\n};\n"],"x_google_ignoreList":[0],"mappings":";;AAAA,MAAa,UAAU;CACnB,OAAO;CACP,OAAO;CACP,OAAO;CACV"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_aiSdk = require('../aiSdk.cjs');
|
|
2
2
|
const require__utils_asset = require('../_virtual/_utils_asset.cjs');
|
|
3
|
-
const
|
|
3
|
+
const require_schemas = require('../node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/schemas.cjs');
|
|
4
4
|
let ai = require("ai");
|
|
5
5
|
let _intlayer_core = require("@intlayer/core");
|
|
6
6
|
let _intlayer_types = require("@intlayer/types");
|
|
@@ -34,29 +34,52 @@ const getModeInstructions = (mode) => {
|
|
|
34
34
|
if (mode === "complete") return "Mode: \"Complete\" - Enrich the preset content with the missing keys and values in the output locale. Do not update existing keys. Everything should be returned in the output.";
|
|
35
35
|
return "Mode: \"Review\" - Fill missing content and review existing keys from the preset content. If a key from the entry is missing in the output, it must be translated to the target language and added. If you detect misspelled content, or content that should be reformulated, correct it. If a translation is not coherent with the desired language, translate it.";
|
|
36
36
|
};
|
|
37
|
+
const jsonToZod = (content) => {
|
|
38
|
+
if (typeof content === "string") return require_schemas.string();
|
|
39
|
+
if (typeof content === "number") return require_schemas.number();
|
|
40
|
+
if (typeof content === "boolean") return require_schemas.boolean();
|
|
41
|
+
if (Array.isArray(content)) {
|
|
42
|
+
if (content.length === 0) return require_schemas.array(require_schemas.string());
|
|
43
|
+
return require_schemas.array(jsonToZod(content[0]));
|
|
44
|
+
}
|
|
45
|
+
if (typeof content === "object" && content !== null) {
|
|
46
|
+
const shape = {};
|
|
47
|
+
for (const key in content) shape[key] = jsonToZod(content[key]);
|
|
48
|
+
return require_schemas.object(shape);
|
|
49
|
+
}
|
|
50
|
+
return require_schemas.any();
|
|
51
|
+
};
|
|
37
52
|
/**
|
|
38
53
|
* TranslateJSONs a content declaration file by constructing a prompt for AI models.
|
|
39
54
|
* The prompt includes details about the project's locales, file paths of content declarations,
|
|
40
55
|
* and requests for identifying issues or inconsistencies.
|
|
41
56
|
*/
|
|
42
57
|
const translateJSON = async ({ entryFileContent, presetOutputContent, dictionaryDescription, aiConfig, entryLocale, outputLocale, tags, mode, applicationContext }) => {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
58
|
+
const promptFile = require__utils_asset.readAsset("./PROMPT.md");
|
|
59
|
+
const formattedEntryLocale = formatLocaleWithName(entryLocale);
|
|
60
|
+
const formattedOutputLocale = formatLocaleWithName(outputLocale);
|
|
61
|
+
const prompt = promptFile.replace("{{entryLocale}}", formattedEntryLocale).replace("{{outputLocale}}", formattedOutputLocale).replace("{{presetOutputContent}}", JSON.stringify(presetOutputContent)).replace("{{dictionaryDescription}}", dictionaryDescription ?? "").replace("{{applicationContext}}", applicationContext ?? "").replace("{{tagsInstructions}}", formatTagInstructions(tags ?? [])).replace("{{modeInstructions}}", getModeInstructions(mode));
|
|
62
|
+
const { object: object$1, usage } = await (0, ai.generateObject)({
|
|
45
63
|
...aiConfig,
|
|
64
|
+
schema: jsonToZod(entryFileContent),
|
|
46
65
|
messages: [{
|
|
47
66
|
role: "system",
|
|
48
67
|
content: prompt
|
|
49
68
|
}, {
|
|
50
69
|
role: "user",
|
|
51
70
|
content: [
|
|
52
|
-
|
|
53
|
-
|
|
71
|
+
`# Translation Request`,
|
|
72
|
+
`Please translate the following JSON content.`,
|
|
73
|
+
`- **From:** ${formattedEntryLocale}`,
|
|
74
|
+
`- **To:** ${formattedOutputLocale}`,
|
|
75
|
+
``,
|
|
76
|
+
`## Entry Content:`,
|
|
54
77
|
JSON.stringify(entryFileContent)
|
|
55
78
|
].join("\n")
|
|
56
79
|
}]
|
|
57
80
|
});
|
|
58
81
|
return {
|
|
59
|
-
fileContent:
|
|
82
|
+
fileContent: object$1,
|
|
60
83
|
tokenUsed: usage?.totalTokens ?? 0
|
|
61
84
|
};
|
|
62
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["aiDefaultOptions: AIOptions","AIProvider","Locales","readAsset","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["aiDefaultOptions: AIOptions","AIProvider","Locales","shape: Record<string, z.ZodTypeAny>","readAsset","object"],"sources":["../../../src/translateJSON/index.ts"],"sourcesContent":["import { readAsset } from 'utils:asset';\nimport { getLocaleName } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport { generateObject } from 'ai';\nimport { z } from 'zod';\nimport { type AIConfig, type AIOptions, AIProvider } from '../aiSdk';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type TranslateJSONOptions<T = JSON> = {\n entryFileContent: T;\n presetOutputContent: Partial<T>;\n dictionaryDescription?: string;\n entryLocale: Locale;\n outputLocale: Locale;\n tags?: Tag[];\n aiConfig: AIConfig;\n mode: 'complete' | 'review';\n applicationContext?: string;\n};\n\nexport type TranslateJSONResultData<T = JSON> = {\n fileContent: T;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n provider: AIProvider.OPENAI,\n model: 'gpt-5-mini',\n};\n\n/**\n * Format a locale with its name.\n *\n * @param locale - The locale to format.\n * @returns A string in the format \"locale: name\", e.g. \"en: English\".\n */\nconst formatLocaleWithName = (locale: Locale): string =>\n `${locale}: ${getLocaleName(locale, Locales.ENGLISH)}`;\n\n/**\n * Formats tag instructions for the AI prompt.\n * Creates a string with all available tags and their descriptions.\n *\n * @param tags - The list of tags to format.\n * @returns A formatted string with tag instructions.\n */\nconst formatTagInstructions = (tags: Tag[]): string => {\n if (!tags || tags.length === 0) {\n return '';\n }\n\n // Prepare the tag instructions.\n return `Based on the dictionary content, identify specific tags from the list below that would be relevant:\n \n${tags.map(({ key, description }) => `- ${key}: ${description}`).join('\\n\\n')}`;\n};\n\nconst getModeInstructions = (mode: 'complete' | 'review'): string => {\n if (mode === 'complete') {\n return 'Mode: \"Complete\" - Enrich the preset content with the missing keys and values in the output locale. Do not update existing keys. Everything should be returned in the output.';\n }\n\n return 'Mode: \"Review\" - Fill missing content and review existing keys from the preset content. If a key from the entry is missing in the output, it must be translated to the target language and added. If you detect misspelled content, or content that should be reformulated, correct it. If a translation is not coherent with the desired language, translate it.';\n};\n\nconst jsonToZod = (content: any): z.ZodTypeAny => {\n // Base case: content is a string (the translation target)\n if (typeof content === 'string') {\n return z.string();\n }\n\n // Base cases: primitives often preserved in i18n files (e.g. strict numbers/booleans)\n if (typeof content === 'number') {\n return z.number();\n }\n if (typeof content === 'boolean') {\n return z.boolean();\n }\n\n // Recursive case: Array\n if (Array.isArray(content)) {\n // If array is empty, we assume array of strings as default for i18n\n if (content.length === 0) {\n return z.array(z.string());\n }\n // We assume all items in the array share the structure of the first item\n return z.array(jsonToZod(content[0]));\n }\n\n // Recursive case: Object\n if (typeof content === 'object' && content !== null) {\n const shape: Record<string, z.ZodTypeAny> = {};\n for (const key in content) {\n shape[key] = jsonToZod(content[key]);\n }\n return z.object(shape);\n }\n\n // Fallback\n return z.any();\n};\n\n/**\n * TranslateJSONs a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const translateJSON = async <T>({\n entryFileContent,\n presetOutputContent,\n dictionaryDescription,\n aiConfig,\n entryLocale,\n outputLocale,\n tags,\n mode,\n applicationContext,\n}: TranslateJSONOptions<T>): Promise<\n TranslateJSONResultData<T> | undefined\n> => {\n const promptFile = readAsset('./PROMPT.md');\n\n const formattedEntryLocale = formatLocaleWithName(entryLocale);\n const formattedOutputLocale = formatLocaleWithName(outputLocale);\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = promptFile\n .replace('{{entryLocale}}', formattedEntryLocale)\n .replace('{{outputLocale}}', formattedOutputLocale)\n .replace('{{presetOutputContent}}', JSON.stringify(presetOutputContent))\n .replace('{{dictionaryDescription}}', dictionaryDescription ?? '')\n .replace('{{applicationContext}}', applicationContext ?? '')\n .replace('{{tagsInstructions}}', formatTagInstructions(tags ?? []))\n .replace('{{modeInstructions}}', getModeInstructions(mode));\n\n // Use the AI SDK to generate the completion\n const { object, usage } = await generateObject({\n ...aiConfig,\n schema: jsonToZod(entryFileContent),\n messages: [\n { role: 'system', content: prompt },\n {\n role: 'user',\n // KEY CHANGE: Explicitly repeating instructions in the user message\n content: [\n `# Translation Request`,\n `Please translate the following JSON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `## Entry Content:`,\n JSON.stringify(entryFileContent),\n ].join('\\n'),\n },\n ],\n });\n\n return {\n fileContent: object as T,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;;;;AA6BA,MAAaA,mBAA8B;CACzC,UAAUC,yBAAW;CACrB,OAAO;CACR;;;;;;;AAQD,MAAM,wBAAwB,WAC5B,GAAG,OAAO,sCAAkB,QAAQC,wBAAQ,QAAQ;;;;;;;;AAStD,MAAM,yBAAyB,SAAwB;AACrD,KAAI,CAAC,QAAQ,KAAK,WAAW,EAC3B,QAAO;AAIT,QAAO;;EAEP,KAAK,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,cAAc,CAAC,KAAK,OAAO;;AAG7E,MAAM,uBAAuB,SAAwC;AACnE,KAAI,SAAS,WACX,QAAO;AAGT,Q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EACb,WAAW,OAAO,eAAe;EAClC"}
|
package/dist/esm/aiSdk.mjs
CHANGED
|
@@ -66,7 +66,7 @@ const getLanguageModel = (aiOptions, apiKey, defaultModel) => {
|
|
|
66
66
|
})(selectedModel);
|
|
67
67
|
case AIProvider.OLLAMA: return createOpenAI({
|
|
68
68
|
baseURL: baseURL ?? "http://localhost:11434/v1",
|
|
69
|
-
apiKey: "ollama"
|
|
69
|
+
apiKey: apiKey ?? "ollama"
|
|
70
70
|
}).chat(selectedModel);
|
|
71
71
|
default: throw new Error(`Provider ${aiOptions.provider} not supported`);
|
|
72
72
|
}
|
package/dist/esm/aiSdk.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.mjs","names":["DEFAULT_PROVIDER: AIProvider","DEFAULT_TEMPERATURE: number"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import { type anthropic, createAnthropic } from '@ai-sdk/anthropic';\nimport { createDeepSeek, type deepseek } from '@ai-sdk/deepseek';\nimport { createGoogleGenerativeAI, type google } from '@ai-sdk/google';\nimport { createMistral, type mistral } from '@ai-sdk/mistral';\nimport { createOpenAI, type openai } from '@ai-sdk/openai';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\n\ntype AnthropicModel = Parameters<typeof anthropic>[0];\ntype DeepSeekModel = Parameters<typeof deepseek>[0];\ntype MistralModel = Parameters<typeof mistral>[0];\ntype OpenAIModel = Parameters<typeof openai>[0];\ntype GoogleModel = Parameters<typeof google>[0];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | GoogleModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\nexport enum AIProvider {\n OPENAI = 'openai',\n ANTHROPIC = 'anthropic',\n MISTRAL = 'mistral',\n DEEPSEEK = 'deepseek',\n GEMINI = 'gemini',\n OLLAMA = 'ollama',\n}\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\nexport type AIOptions = {\n provider?: AIProvider;\n model?: Model;\n temperature?: number;\n baseURL?: string;\n apiKey?: string;\n applicationContext?: string;\n};\n\n// Define the structure of messages used in chat completions\nexport type ChatCompletionRequestMessage = {\n role: 'system' | 'user' | 'assistant'; // The role of the message sender\n content: string; // The text content of the message\n timestamp?: Date; // The timestamp of the message\n};\n\ntype AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AIProvider,\n userApiKey: string,\n userModel?: Model,\n defaultModel: Model = 'gpt-5-mini'\n): Model => {\n // If the user uses their own API key, allow custom model selection\n if (userApiKey || provider === AIProvider.OLLAMA) {\n if (provider === AIProvider.OPENAI) {\n return userModel ?? defaultModel;\n }\n\n if (userModel) {\n return userModel;\n }\n\n switch (provider) {\n case AIProvider.ANTHROPIC:\n return 'claude-sonnet-4-5-20250929';\n case AIProvider.MISTRAL:\n return 'mistral-large-latest';\n case AIProvider.DEEPSEEK:\n return 'deepseek-coder';\n case AIProvider.GEMINI:\n return 'gemini-2.5-flash';\n case AIProvider.OLLAMA:\n return '';\n default:\n return defaultModel;\n }\n }\n\n // Guard: Prevent custom model usage without a user API key\n if (userModel || provider) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return defaultModel;\n};\n\nconst getLanguageModel = (\n aiOptions: AIOptions,\n apiKey: string,\n defaultModel?: Model\n) => {\n const selectedModel = getModelName(\n aiOptions.provider as AIProvider,\n apiKey,\n aiOptions.model,\n defaultModel\n );\n\n const baseURL = aiOptions.baseURL;\n\n switch (aiOptions.provider) {\n case AIProvider.OPENAI: {\n return createOpenAI({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.ANTHROPIC: {\n return createAnthropic({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.MISTRAL: {\n return createMistral({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.DEEPSEEK: {\n return createDeepSeek({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.GEMINI: {\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.OLLAMA: {\n // Ollama compatible mode:\n const ollama = createOpenAI({\n baseURL: baseURL ?? 'http://localhost:11434/v1',\n apiKey: 'ollama', // Required but unused by Ollama\n });\n\n return ollama.chat(selectedModel);\n }\n\n default: {\n throw new Error(`Provider ${aiOptions.provider} not supported`);\n }\n }\n};\n\nexport type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'> & {\n reasoningEffort?: ReasoningEffort;\n textVerbosity?: 'low' | 'medium' | 'high';\n};\n\nconst DEFAULT_PROVIDER: AIProvider = AIProvider.OPENAI as AIProvider;\nconst DEFAULT_TEMPERATURE: number = 1; // ChatGPT 5 accept only temperature 1\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n options: AIConfigOptions,\n isAuthenticated: boolean = false\n): Promise<AIConfig> => {\n const {\n userOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\n temperature: DEFAULT_TEMPERATURE,\n ...defaultOptions,\n ...userOptions,\n } satisfies AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (!apiKey) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = getLanguageModel(\n aiOptions,\n apiKey,\n defaultOptions?.model\n );\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n };\n};\n"],"mappings":";;;;;;;;;;AAwCA,IAAY,oDAAL;AACL;AACA;AACA;AACA;AACA;AACA;;;AA0BF,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,gBAAgB,QAAQ,IAAI;AAElC,KAAI,WAAW,SAAS,SAAS,CAC/B,QAAO,WAAW,UAAU;AAG9B,KAAI,WAAW,SAAS,SAAS,IAAI,WAAW,OAC9C,QAAO,WAAW;AAGpB,KAAI,WAAW,SAAS,kBAAkB,IAAI,gBAC5C,QAAO,WAAW,UAAU;AAI9B,KAAI,WAAW,SAAS,eAAe,IAAI,gBACzC,QAAO,WAAW,UAAU;;AAMhC,MAAM,gBACJ,UACA,YACA,WACA,eAAsB,iBACZ;AAEV,KAAI,cAAc,aAAa,WAAW,QAAQ;AAChD,MAAI,aAAa,WAAW,OAC1B,QAAO,aAAa;AAGtB,MAAI,UACF,QAAO;AAGT,UAAQ,UAAR;GACE,KAAK,WAAW,UACd,QAAO;GACT,KAAK,WAAW,QACd,QAAO;GACT,KAAK,WAAW,SACd,QAAO;GACT,KAAK,WAAW,OACd,QAAO;GACT,KAAK,WAAW,OACd,QAAO;GACT,QACE,QAAO;;;AAKb,KAAI,aAAa,SACf,OAAM,IAAI,MACR,4DACD;AAGH,QAAO;;AAGT,MAAM,oBACJ,WACA,QACA,iBACG;CACH,MAAM,gBAAgB,aACpB,UAAU,UACV,QACA,UAAU,OACV,aACD;CAED,MAAM,UAAU,UAAU;AAE1B,SAAQ,UAAU,UAAlB;EACE,KAAK,WAAW,OACd,QAAO,aAAa;GAClB;GACA;GACD,CAAC,CAAC,cAAc;EAGnB,KAAK,WAAW,UACd,QAAO,gBAAgB;GACrB;GACA;GACD,CAAC,CAAC,cAAc;EAGnB,KAAK,WAAW,QACd,QAAO,cAAc;GACnB;GACA;GACD,CAAC,CAAC,cAAc;EAGnB,KAAK,WAAW,SACd,QAAO,eAAe;GACpB;GACA;GACD,CAAC,CAAC,cAAc;EAGnB,KAAK,WAAW,OACd,QAAO,yBAAyB;GAC9B;GACA;GACD,CAAC,CAAC,cAAc;EAGnB,KAAK,WAAW,OAOd,QALe,aAAa;GAC1B,SAAS,WAAW;GACpB,QAAQ;
|
|
1
|
+
{"version":3,"file":"aiSdk.mjs","names":["DEFAULT_PROVIDER: AIProvider","DEFAULT_TEMPERATURE: number"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import { type anthropic, createAnthropic } from '@ai-sdk/anthropic';\nimport { createDeepSeek, type deepseek } from '@ai-sdk/deepseek';\nimport { createGoogleGenerativeAI, type google } from '@ai-sdk/google';\nimport { createMistral, type mistral } from '@ai-sdk/mistral';\nimport { createOpenAI, type openai } from '@ai-sdk/openai';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\n\ntype AnthropicModel = Parameters<typeof anthropic>[0];\ntype DeepSeekModel = Parameters<typeof deepseek>[0];\ntype MistralModel = Parameters<typeof mistral>[0];\ntype OpenAIModel = Parameters<typeof openai>[0];\ntype GoogleModel = Parameters<typeof google>[0];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | GoogleModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\nexport enum AIProvider {\n OPENAI = 'openai',\n ANTHROPIC = 'anthropic',\n MISTRAL = 'mistral',\n DEEPSEEK = 'deepseek',\n GEMINI = 'gemini',\n OLLAMA = 'ollama',\n}\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\nexport type AIOptions = {\n provider?: AIProvider;\n model?: Model;\n temperature?: number;\n baseURL?: string;\n apiKey?: string;\n applicationContext?: string;\n};\n\n// Define the structure of messages used in chat completions\nexport type ChatCompletionRequestMessage = {\n role: 'system' | 'user' | 'assistant'; // The role of the message sender\n content: string; // The text content of the message\n timestamp?: Date; // The timestamp of the message\n};\n\ntype AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AIProvider,\n userApiKey: string,\n userModel?: Model,\n defaultModel: Model = 'gpt-5-mini'\n): Model => {\n // If the user uses their own API key, allow custom model selection\n if (userApiKey || provider === AIProvider.OLLAMA) {\n if (provider === AIProvider.OPENAI) {\n return userModel ?? defaultModel;\n }\n\n if (userModel) {\n return userModel;\n }\n\n switch (provider) {\n case AIProvider.ANTHROPIC:\n return 'claude-sonnet-4-5-20250929';\n case AIProvider.MISTRAL:\n return 'mistral-large-latest';\n case AIProvider.DEEPSEEK:\n return 'deepseek-coder';\n case AIProvider.GEMINI:\n return 'gemini-2.5-flash';\n case AIProvider.OLLAMA:\n return '';\n default:\n return defaultModel;\n }\n }\n\n // Guard: Prevent custom model usage without a user API key\n if (userModel || provider) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return defaultModel;\n};\n\nconst getLanguageModel = (\n aiOptions: AIOptions,\n apiKey: string,\n defaultModel?: Model\n) => {\n const selectedModel = getModelName(\n aiOptions.provider as AIProvider,\n apiKey,\n aiOptions.model,\n defaultModel\n );\n\n const baseURL = aiOptions.baseURL;\n\n switch (aiOptions.provider) {\n case AIProvider.OPENAI: {\n return createOpenAI({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.ANTHROPIC: {\n return createAnthropic({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.MISTRAL: {\n return createMistral({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.DEEPSEEK: {\n return createDeepSeek({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.GEMINI: {\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n })(selectedModel);\n }\n\n case AIProvider.OLLAMA: {\n // Ollama compatible mode:\n const ollama = createOpenAI({\n baseURL: baseURL ?? 'http://localhost:11434/v1',\n apiKey: apiKey ?? 'ollama', // Required but unused by Ollama\n });\n\n return ollama.chat(selectedModel);\n }\n\n default: {\n throw new Error(`Provider ${aiOptions.provider} not supported`);\n }\n }\n};\n\nexport type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'> & {\n reasoningEffort?: ReasoningEffort;\n textVerbosity?: 'low' | 'medium' | 'high';\n};\n\nconst DEFAULT_PROVIDER: AIProvider = AIProvider.OPENAI as AIProvider;\nconst DEFAULT_TEMPERATURE: number = 1; // ChatGPT 5 accept only temperature 1\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n options: AIConfigOptions,\n isAuthenticated: boolean = false\n): Promise<AIConfig> => {\n const {\n userOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\n temperature: DEFAULT_TEMPERATURE,\n ...defaultOptions,\n ...userOptions,\n } satisfies AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (!apiKey) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = getLanguageModel(\n aiOptions,\n apiKey,\n defaultOptions?.model\n );\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n };\n};\n"],"mappings":";;;;;;;;;;AAwCA,IAAY,oDAAL;AACL;AACA;AACA;AACA;AACA;AACA;;;AA0BF,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,gBAAgB,QAAQ,IAAI;AAElC,KAAI,WAAW,SAAS,SAAS,CAC/B,QAAO,WAAW,UAAU;AAG9B,KAAI,WAAW,SAAS,SAAS,IAAI,WAAW,OAC9C,QAAO,WAAW;AAGpB,KAAI,WAAW,SAAS,kBAAkB,IAAI,gBAC5C,QAAO,WAAW,UAAU;AAI9B,KAAI,WAAW,SAAS,eAAe,IAAI,gBACzC,QAAO,WAAW,UAAU;;AAMhC,MAAM,gBACJ,UACA,YACA,WACA,eAAsB,iBACZ;AAEV,KAAI,cAAc,aAAa,WAAW,QAAQ;AAChD,MAAI,aAAa,WAAW,OAC1B,QAAO,aAAa;AAGtB,MAAI,UACF,QAAO;AAGT,UAAQ,UAAR;GACE,KAAK,WAAW,UACd,QAAO;GACT,KAAK,WAAW,QACd,QAAO;GACT,KAAK,WAAW,SACd,QAAO;GACT,KAAK,WAAW,OACd,QAAO;GACT,KAAK,WAAW,O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";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { array, object, string } from "../node_modules/.bun/zod@4.2.1/node_modules/zod/v4/classic/schemas.mjs";
|
|
3
|
+
import { generateObject } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/auditDictionaryMetadata/index.ts
|
|
6
6
|
const aiDefaultOptions = {};
|
|
@@ -10,23 +10,38 @@ const aiDefaultOptions = {};
|
|
|
10
10
|
* and requests for identifying issues or inconsistencies.
|
|
11
11
|
*/
|
|
12
12
|
const auditDictionaryMetadata = async ({ fileContent, tags, aiConfig, applicationContext }) => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const CHAT_GPT_PROMPT = readAsset("./PROMPT.md");
|
|
14
|
+
const EXAMPLE_REQUEST = readAsset("./EXAMPLE_REQUEST.md");
|
|
15
|
+
const EXAMPLE_RESPONSE = readAsset("./EXAMPLE_RESPONSE.md");
|
|
16
|
+
const prompt = CHAT_GPT_PROMPT.replace("{{applicationContext}}", applicationContext ?? "").replace("{{tags}}", tags ? JSON.stringify(tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n"), null, 2) : "");
|
|
17
|
+
const { object: object$1, usage } = await generateObject({
|
|
15
18
|
...aiConfig,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
schema: object({
|
|
20
|
+
title: string(),
|
|
21
|
+
description: string(),
|
|
22
|
+
tags: array(string())
|
|
23
|
+
}),
|
|
24
|
+
messages: [
|
|
25
|
+
{
|
|
26
|
+
role: "system",
|
|
27
|
+
content: prompt
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
role: "user",
|
|
31
|
+
content: EXAMPLE_REQUEST
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
role: "assistant",
|
|
35
|
+
content: EXAMPLE_RESPONSE
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
role: "user",
|
|
39
|
+
content: fileContent
|
|
40
|
+
}
|
|
41
|
+
]
|
|
27
42
|
});
|
|
28
43
|
return {
|
|
29
|
-
fileContent:
|
|
44
|
+
fileContent: object$1,
|
|
30
45
|
tokenUsed: usage?.totalTokens ?? 0
|
|
31
46
|
};
|
|
32
47
|
};
|