dsh-compact-pi 0.2.3-b2 → 0.2.3-b4
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/CHANGELOG.md +12 -0
- package/README.md +18 -5
- package/bin/dcp-session.ts +33 -14
- package/dist/codec.mjs +45 -9
- package/dist/dcp-session.mjs +969 -436
- package/dist/index.js +12 -4
- package/docs/compatibility.md +1 -1
- package/docs/help.md +25 -4
- package/docs/publishing.md +9 -9
- package/docs/testing.md +7 -4
- package/package.json +5 -3
- package/scripts/test-resume.mjs +96 -31
- package/skills/dcp-migrate-to-dsh/SKILL.md +16 -0
- package/skills/dcp-migrate-to-dsh/references/commands.md +29 -0
- package/src/codec.ts +40 -6
- package/src/dsh/convert.ts +11 -5
- package/src/dsh/import.ts +108 -0
- package/src/dsh/migration-cli.ts +129 -0
- package/src/dsh/migration-web.ts +44 -0
- package/src/dsh/migration.ts +216 -0
- package/src/dsh/sync.ts +9 -1
- package/test/convert.test.ts +63 -1
- package/test/migration.test.ts +72 -0
package/dist/dcp-session.mjs
CHANGED
|
@@ -47,29 +47,29 @@ var __runInitializers = (array2, flags, self, value) => {
|
|
|
47
47
|
for (var i = 0, fns = array2[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
48
48
|
return value;
|
|
49
49
|
};
|
|
50
|
-
var __decorateElement = (array2, flags, name2, decorators, target,
|
|
50
|
+
var __decorateElement = (array2, flags, name2, decorators, target, extra2) => {
|
|
51
51
|
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
52
52
|
var j = k > 3 ? array2.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
53
53
|
var initializers = k > 3 && (array2[j - 1] = []), extraInitializers = array2[j] || (array2[j] = []);
|
|
54
54
|
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name2]() {
|
|
55
|
-
return __privateGet(this,
|
|
55
|
+
return __privateGet(this, extra2);
|
|
56
56
|
}, set [name2](x) {
|
|
57
|
-
return __privateSet(this,
|
|
57
|
+
return __privateSet(this, extra2, x);
|
|
58
58
|
} }, name2));
|
|
59
|
-
k ? p && k < 4 && __name(
|
|
59
|
+
k ? p && k < 4 && __name(extra2, (k > 2 ? "set " : k > 1 ? "get " : "") + name2) : __name(target, name2);
|
|
60
60
|
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
61
61
|
ctx = __decoratorContext(k, name2, done = {}, array2[3], extraInitializers);
|
|
62
62
|
if (k) {
|
|
63
63
|
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name2 in x };
|
|
64
|
-
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ?
|
|
65
|
-
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ?
|
|
64
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra2 : desc.get) : (x) => x[name2];
|
|
65
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra2 : desc.set) : (x, y) => x[name2] = y;
|
|
66
66
|
}
|
|
67
|
-
it = (0, decorators[i])(k ? k < 4 ? p ?
|
|
68
|
-
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ?
|
|
67
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra2 : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
68
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra2 = it : desc[key] = it : target = it);
|
|
69
69
|
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
70
70
|
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
71
71
|
}
|
|
72
|
-
return k || __decoratorMetadata(array2, target), desc && __defProp(target, name2, desc), p ? k ^ 4 ?
|
|
72
|
+
return k || __decoratorMetadata(array2, target), desc && __defProp(target, name2, desc), p ? k ^ 4 ? extra2 : desc : target;
|
|
73
73
|
};
|
|
74
74
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
75
75
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
@@ -251,7 +251,7 @@ function deepEqual(a, b, strict) {
|
|
|
251
251
|
return compare(a, b);
|
|
252
252
|
}
|
|
253
253
|
function tokenize(source, delimiters, delimiter) {
|
|
254
|
-
const
|
|
254
|
+
const output2 = [];
|
|
255
255
|
let state = 0;
|
|
256
256
|
for (let i = 0; i < source.length; i++) {
|
|
257
257
|
const code = source.charCodeAt(i);
|
|
@@ -259,29 +259,29 @@ function tokenize(source, delimiters, delimiter) {
|
|
|
259
259
|
if (state === 1) {
|
|
260
260
|
const next = source.charCodeAt(i + 1);
|
|
261
261
|
if (next >= 97 && next <= 122) {
|
|
262
|
-
|
|
262
|
+
output2.push(delimiter);
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
output2.push(code + 32);
|
|
265
265
|
} else {
|
|
266
266
|
if (state !== 0) {
|
|
267
|
-
|
|
267
|
+
output2.push(delimiter);
|
|
268
268
|
}
|
|
269
|
-
|
|
269
|
+
output2.push(code + 32);
|
|
270
270
|
}
|
|
271
271
|
state = 1;
|
|
272
272
|
} else if (code >= 97 && code <= 122) {
|
|
273
|
-
|
|
273
|
+
output2.push(code);
|
|
274
274
|
state = 2;
|
|
275
275
|
} else if (delimiters.includes(code)) {
|
|
276
276
|
if (state !== 0) {
|
|
277
|
-
|
|
277
|
+
output2.push(delimiter);
|
|
278
278
|
}
|
|
279
279
|
state = 0;
|
|
280
280
|
} else {
|
|
281
|
-
|
|
281
|
+
output2.push(code);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
-
return String.fromCharCode(...
|
|
284
|
+
return String.fromCharCode(...output2);
|
|
285
285
|
}
|
|
286
286
|
function paramCase(source) {
|
|
287
287
|
return tokenize(source, [45, 95], 45);
|
|
@@ -629,8 +629,8 @@ var ValidationError = class _ValidationError extends TypeError {
|
|
|
629
629
|
* @param path — the standard-schema issue path; segments may be `{ key }` objects.
|
|
630
630
|
* @returns the property keys, or an empty array when the issue has no path.
|
|
631
631
|
*/
|
|
632
|
-
static normalizePath(
|
|
633
|
-
return
|
|
632
|
+
static normalizePath(path5 = []) {
|
|
633
|
+
return path5.map((segment) => typeof segment === "object" ? segment.key : segment);
|
|
634
634
|
}
|
|
635
635
|
/**
|
|
636
636
|
* Format an issue path as a dotted string.
|
|
@@ -638,8 +638,8 @@ var ValidationError = class _ValidationError extends TypeError {
|
|
|
638
638
|
* @param path — the standard-schema issue path.
|
|
639
639
|
* @returns the keys joined with `.`.
|
|
640
640
|
*/
|
|
641
|
-
static formatPath(
|
|
642
|
-
return _ValidationError.normalizePath(
|
|
641
|
+
static formatPath(path5) {
|
|
642
|
+
return _ValidationError.normalizePath(path5).map(String).join(".");
|
|
643
643
|
}
|
|
644
644
|
};
|
|
645
645
|
Object.defineProperty(ValidationError.prototype, kValidationError, {
|
|
@@ -3328,10 +3328,10 @@ var EXCEEDS_MODEL_CONTEXT = new RegExp(
|
|
|
3328
3328
|
"i"
|
|
3329
3329
|
);
|
|
3330
3330
|
function errorChain(value) {
|
|
3331
|
-
const
|
|
3331
|
+
const path5 = /* @__PURE__ */ new Set();
|
|
3332
3332
|
const render = (current) => {
|
|
3333
|
-
if (
|
|
3334
|
-
|
|
3333
|
+
if (path5.has(current)) return "<circular cause>";
|
|
3334
|
+
path5.add(current);
|
|
3335
3335
|
try {
|
|
3336
3336
|
if (!(current instanceof Error)) {
|
|
3337
3337
|
if (typeof current === "object" && current !== null) {
|
|
@@ -3350,7 +3350,7 @@ function errorChain(value) {
|
|
|
3350
3350
|
} catch {
|
|
3351
3351
|
return "<unrenderable value>";
|
|
3352
3352
|
} finally {
|
|
3353
|
-
|
|
3353
|
+
path5.delete(current);
|
|
3354
3354
|
}
|
|
3355
3355
|
};
|
|
3356
3356
|
return render(value);
|
|
@@ -3396,25 +3396,25 @@ function requiredImageOffload(messages, budget2, versionBytes) {
|
|
|
3396
3396
|
function freezeMessage(message) {
|
|
3397
3397
|
return deepFreeze(structuredClone(message));
|
|
3398
3398
|
}
|
|
3399
|
-
function createMessage(
|
|
3399
|
+
function createMessage(input2) {
|
|
3400
3400
|
return deepFreeze(structuredClone({
|
|
3401
|
-
...
|
|
3401
|
+
...input2,
|
|
3402
3402
|
id: brandString(randomUUID())
|
|
3403
3403
|
}));
|
|
3404
3404
|
}
|
|
3405
|
-
function createUserMessage(
|
|
3405
|
+
function createUserMessage(input2) {
|
|
3406
3406
|
return createMessage({
|
|
3407
|
-
...
|
|
3407
|
+
...input2,
|
|
3408
3408
|
role: "user"
|
|
3409
3409
|
});
|
|
3410
3410
|
}
|
|
3411
|
-
function createAssistantMessage(
|
|
3411
|
+
function createAssistantMessage(input2) {
|
|
3412
3412
|
return createMessage({
|
|
3413
3413
|
role: "assistant",
|
|
3414
|
-
content:
|
|
3414
|
+
content: input2.content,
|
|
3415
3415
|
source: {
|
|
3416
3416
|
kind: "model",
|
|
3417
|
-
...
|
|
3417
|
+
...input2.source
|
|
3418
3418
|
}
|
|
3419
3419
|
});
|
|
3420
3420
|
}
|
|
@@ -3636,9 +3636,9 @@ Schema.prototype.simplify = function simplify(value) {
|
|
|
3636
3636
|
Schema.prototype.toString = function toString(inline) {
|
|
3637
3637
|
return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
|
|
3638
3638
|
};
|
|
3639
|
-
Schema.prototype.role = function role(role,
|
|
3639
|
+
Schema.prototype.role = function role(role, extra2) {
|
|
3640
3640
|
const schema = Schema(this);
|
|
3641
|
-
schema.meta = { ...schema.meta, role, extra:
|
|
3641
|
+
schema.meta = { ...schema.meta, role, extra: extra2 };
|
|
3642
3642
|
return schema;
|
|
3643
3643
|
};
|
|
3644
3644
|
for (const key of ["default", "link", "comment", "description", "max", "min", "step"]) {
|
|
@@ -3656,25 +3656,25 @@ Schema.prototype.volatile = function volatile() {
|
|
|
3656
3656
|
};
|
|
3657
3657
|
var resolvers = {};
|
|
3658
3658
|
var checkedVolatile = /* @__PURE__ */ Symbol("checked-volatile-schema");
|
|
3659
|
-
function validateVolatileSchema(schema,
|
|
3659
|
+
function validateVolatileSchema(schema, path5 = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
|
|
3660
3660
|
const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
|
|
3661
3661
|
if (states.has(blocked)) return;
|
|
3662
3662
|
states.add(blocked);
|
|
3663
3663
|
seen.set(schema, states);
|
|
3664
3664
|
if (schema.meta?.volatile && blocked) {
|
|
3665
|
-
throw new ValidationError2("volatile fields require a fixed object path without an enclosing volatile field", { path:
|
|
3665
|
+
throw new ValidationError2("volatile fields require a fixed object path without an enclosing volatile field", { path: path5 });
|
|
3666
3666
|
}
|
|
3667
3667
|
const nested = blocked || !!schema.meta?.volatile;
|
|
3668
3668
|
if (schema.dict) {
|
|
3669
|
-
for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...
|
|
3669
|
+
for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path5, key], nested, seen);
|
|
3670
3670
|
}
|
|
3671
|
-
if (schema.sKey) validateVolatileSchema(schema.sKey, [...
|
|
3671
|
+
if (schema.sKey) validateVolatileSchema(schema.sKey, [...path5, "<key>"], true, seen);
|
|
3672
3672
|
if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) {
|
|
3673
|
-
validateVolatileSchema(schema.inner, [...
|
|
3673
|
+
validateVolatileSchema(schema.inner, [...path5, "*"], true, seen);
|
|
3674
3674
|
}
|
|
3675
3675
|
if (schema.list) {
|
|
3676
3676
|
for (let index = 0; index < schema.list.length; index++) {
|
|
3677
|
-
validateVolatileSchema(schema.list[index], [...
|
|
3677
|
+
validateVolatileSchema(schema.list[index], [...path5, String(index)], true, seen);
|
|
3678
3678
|
}
|
|
3679
3679
|
}
|
|
3680
3680
|
}
|
|
@@ -4137,71 +4137,71 @@ var ALWAYS_POLICY_KEYS = /* @__PURE__ */ new Set([
|
|
|
4137
4137
|
"backoff"
|
|
4138
4138
|
]);
|
|
4139
4139
|
var BACKOFF_KEYS = /* @__PURE__ */ new Set(["initialDelayMs", "maxDelayMs", "jitterRatio"]);
|
|
4140
|
-
function validateKeys(value, allowed,
|
|
4140
|
+
function validateKeys(value, allowed, path5) {
|
|
4141
4141
|
for (const key of Object.keys(value)) {
|
|
4142
|
-
if (!allowed.has(key)) throw new Error(`${
|
|
4142
|
+
if (!allowed.has(key)) throw new Error(`${path5}: unknown key "${key}"`);
|
|
4143
4143
|
}
|
|
4144
4144
|
}
|
|
4145
|
-
function resolveBackoff(config2,
|
|
4146
|
-
if (config2 !== void 0) validateKeys(config2, BACKOFF_KEYS,
|
|
4145
|
+
function resolveBackoff(config2, path5) {
|
|
4146
|
+
if (config2 !== void 0) validateKeys(config2, BACKOFF_KEYS, path5);
|
|
4147
4147
|
const initialDelayMs = config2?.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
|
|
4148
4148
|
const maxDelayMs = config2?.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
|
|
4149
4149
|
const jitterRatio = config2?.jitterRatio ?? DEFAULT_JITTER_RATIO;
|
|
4150
4150
|
if (!Number.isFinite(initialDelayMs) || initialDelayMs <= 0 || initialDelayMs > MAX_TIMER_DELAY_MS) {
|
|
4151
|
-
throw new Error(`${
|
|
4151
|
+
throw new Error(`${path5}.initialDelayMs must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
4152
4152
|
}
|
|
4153
4153
|
if (!Number.isFinite(maxDelayMs) || maxDelayMs <= 0 || maxDelayMs > MAX_TIMER_DELAY_MS) {
|
|
4154
|
-
throw new Error(`${
|
|
4154
|
+
throw new Error(`${path5}.maxDelayMs must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
4155
4155
|
}
|
|
4156
4156
|
if (initialDelayMs > maxDelayMs) {
|
|
4157
|
-
throw new Error(`${
|
|
4157
|
+
throw new Error(`${path5}.initialDelayMs must be less than or equal to maxDelayMs`);
|
|
4158
4158
|
}
|
|
4159
4159
|
if (!Number.isFinite(jitterRatio) || jitterRatio < 0 || jitterRatio > 1) {
|
|
4160
|
-
throw new Error(`${
|
|
4160
|
+
throw new Error(`${path5}.jitterRatio must be between 0 and 1`);
|
|
4161
4161
|
}
|
|
4162
4162
|
return Object.freeze({ initialDelayMs, maxDelayMs, jitterRatio });
|
|
4163
4163
|
}
|
|
4164
|
-
function resolveRetryPolicy(config2,
|
|
4164
|
+
function resolveRetryPolicy(config2, path5) {
|
|
4165
4165
|
if (config2 === void 0) {
|
|
4166
4166
|
return Object.freeze({
|
|
4167
4167
|
mode: "normal",
|
|
4168
4168
|
maxRetries: DEFAULT_MAX_RETRIES,
|
|
4169
4169
|
retryableCodes: DEFAULT_RETRYABLE_CODES,
|
|
4170
|
-
...resolveBackoff(void 0, `${
|
|
4170
|
+
...resolveBackoff(void 0, `${path5}.backoff`)
|
|
4171
4171
|
});
|
|
4172
4172
|
}
|
|
4173
4173
|
switch (config2.mode) {
|
|
4174
4174
|
case "normal": {
|
|
4175
|
-
validateKeys(config2, NORMAL_POLICY_KEYS,
|
|
4175
|
+
validateKeys(config2, NORMAL_POLICY_KEYS, path5);
|
|
4176
4176
|
const maxRetries = config2.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
4177
4177
|
const retryableCodes = config2.retryableCodes ?? [...DEFAULT_RETRYABLE_CODES];
|
|
4178
4178
|
if (!Number.isSafeInteger(maxRetries) || maxRetries < 0) {
|
|
4179
|
-
throw new Error(`${
|
|
4179
|
+
throw new Error(`${path5}.maxRetries must be a non-negative safe integer`);
|
|
4180
4180
|
}
|
|
4181
4181
|
if (retryableCodes.length === 0) {
|
|
4182
|
-
throw new Error(`${
|
|
4182
|
+
throw new Error(`${path5}.retryableCodes must not be empty`);
|
|
4183
4183
|
}
|
|
4184
4184
|
if (retryableCodes.some((code) => typeof code !== "string" || code.length === 0)) {
|
|
4185
|
-
throw new Error(`${
|
|
4185
|
+
throw new Error(`${path5}.retryableCodes must contain only non-empty strings`);
|
|
4186
4186
|
}
|
|
4187
4187
|
if (new Set(retryableCodes).size !== retryableCodes.length) {
|
|
4188
|
-
throw new Error(`${
|
|
4188
|
+
throw new Error(`${path5}.retryableCodes must not contain duplicates`);
|
|
4189
4189
|
}
|
|
4190
4190
|
return Object.freeze({
|
|
4191
4191
|
mode: "normal",
|
|
4192
4192
|
maxRetries,
|
|
4193
4193
|
retryableCodes: Object.freeze([...retryableCodes]),
|
|
4194
|
-
...resolveBackoff(config2.backoff, `${
|
|
4194
|
+
...resolveBackoff(config2.backoff, `${path5}.backoff`)
|
|
4195
4195
|
});
|
|
4196
4196
|
}
|
|
4197
4197
|
case "always":
|
|
4198
|
-
validateKeys(config2, ALWAYS_POLICY_KEYS,
|
|
4198
|
+
validateKeys(config2, ALWAYS_POLICY_KEYS, path5);
|
|
4199
4199
|
return Object.freeze({
|
|
4200
4200
|
mode: "always",
|
|
4201
|
-
...resolveBackoff(config2.backoff, `${
|
|
4201
|
+
...resolveBackoff(config2.backoff, `${path5}.backoff`)
|
|
4202
4202
|
});
|
|
4203
4203
|
default:
|
|
4204
|
-
throw new Error(`${
|
|
4204
|
+
throw new Error(`${path5}.mode must be "normal" or "always"`);
|
|
4205
4205
|
}
|
|
4206
4206
|
}
|
|
4207
4207
|
function callConfigEquals(a, b) {
|
|
@@ -4301,8 +4301,8 @@ function normalizedAccessText(ref, access) {
|
|
|
4301
4301
|
return ` Normalized copy (read-only; may be resized or re-encoded): ${quoted(access.readonlyPath)} (${ref.width}x${ref.height}px, ${ref.mediaType}). Source dimensions, format, and byte size may differ. Copy to a writable path ending in ${extension(ref.mediaType)} before editing.`;
|
|
4302
4302
|
}
|
|
4303
4303
|
function textOnlyImageText(ref) {
|
|
4304
|
-
const
|
|
4305
|
-
return `[image omitted because this model accepts text only; attachment sha256:${
|
|
4304
|
+
const digest32 = String(ref.attachmentId).slice("sha256:".length, "sha256:".length + 8);
|
|
4305
|
+
return `[image omitted because this model accepts text only; attachment sha256:${digest32}]`;
|
|
4306
4306
|
}
|
|
4307
4307
|
function requestImageHandleText(ref, version3, access) {
|
|
4308
4308
|
const preview = `Image ${imageIdentity(ref)}; request preview ${version3.width}x${version3.height}px.`;
|
|
@@ -4325,8 +4325,8 @@ function contentHasFile(content) {
|
|
|
4325
4325
|
return false;
|
|
4326
4326
|
}
|
|
4327
4327
|
function fileHandleText(ref, readonlyPath) {
|
|
4328
|
-
const
|
|
4329
|
-
const identity2 = `File ${quoted(ref.name)} (${ref.bytes} bytes, sha256:${
|
|
4328
|
+
const digest32 = String(ref.attachmentId).slice("sha256:".length, "sha256:".length + 8);
|
|
4329
|
+
const identity2 = `File ${quoted(ref.name)} (${ref.bytes} bytes, sha256:${digest32})`;
|
|
4330
4330
|
if (readonlyPath === void 0) {
|
|
4331
4331
|
return `[${identity2} was uploaded, but the current execution environment cannot access a readable path. Report that limitation if its contents are needed; do not claim to have read it.]`;
|
|
4332
4332
|
}
|
|
@@ -5245,8 +5245,8 @@ var LlmRuntime = class extends (_a = TypertRemoteService, _listProviders_dec = [
|
|
|
5245
5245
|
return void 0;
|
|
5246
5246
|
}
|
|
5247
5247
|
if (hostPath === void 0) return void 0;
|
|
5248
|
-
const
|
|
5249
|
-
return
|
|
5248
|
+
const fs7 = this.ctx.get("fs");
|
|
5249
|
+
return fs7?.processPathFromHostPath(hostPath);
|
|
5250
5250
|
}
|
|
5251
5251
|
/**
|
|
5252
5252
|
* Final adapter boundary. Adapter selection, dispatch, iterator construction,
|
|
@@ -5494,10 +5494,10 @@ var AttachmentStore = class extends Service {
|
|
|
5494
5494
|
*/
|
|
5495
5495
|
validateImageBatch(inputs) {
|
|
5496
5496
|
const limits = this.imageLimits;
|
|
5497
|
-
assertMessageImages(limits, inputs.length, inputs.reduce((sum,
|
|
5498
|
-
for (const
|
|
5499
|
-
if (!limits.mediaTypes.includes(
|
|
5500
|
-
throw new AttachmentError(`Image type ${
|
|
5497
|
+
assertMessageImages(limits, inputs.length, inputs.reduce((sum, input2) => sum + input2.data.byteLength, 0));
|
|
5498
|
+
for (const input2 of inputs) {
|
|
5499
|
+
if (!limits.mediaTypes.includes(input2.mediaType)) {
|
|
5500
|
+
throw new AttachmentError(`Image type ${input2.mediaType} is not accepted by this deployment.`, "UNSUPPORTED_IMAGE_TYPE");
|
|
5501
5501
|
}
|
|
5502
5502
|
}
|
|
5503
5503
|
}
|
|
@@ -5508,9 +5508,9 @@ var AttachmentStore = class extends Service {
|
|
|
5508
5508
|
*/
|
|
5509
5509
|
async saveImages(inputs) {
|
|
5510
5510
|
this.validateImageBatch(inputs);
|
|
5511
|
-
for (const
|
|
5511
|
+
for (const input2 of inputs) await this.validateImage(input2);
|
|
5512
5512
|
const refs = [];
|
|
5513
|
-
for (const
|
|
5513
|
+
for (const input2 of inputs) refs.push(await this.saveImage(input2));
|
|
5514
5514
|
return refs;
|
|
5515
5515
|
}
|
|
5516
5516
|
/**
|
|
@@ -5548,8 +5548,8 @@ var AttachmentStore = class extends Service {
|
|
|
5548
5548
|
* @returns the durable content-addressed file reference.
|
|
5549
5549
|
* @throws AttachmentError when the encoding or storage operation is refused.
|
|
5550
5550
|
*/
|
|
5551
|
-
admitEncodedFile(
|
|
5552
|
-
return admitEncodedFile(this,
|
|
5551
|
+
admitEncodedFile(input2) {
|
|
5552
|
+
return admitEncodedFile(this, input2);
|
|
5553
5553
|
}
|
|
5554
5554
|
/**
|
|
5555
5555
|
* Identify a failure emitted by this attachment capability by its stable code.
|
|
@@ -5577,8 +5577,8 @@ var AttachmentStore = class extends Service {
|
|
|
5577
5577
|
* @param input - exact bytes and optional display name.
|
|
5578
5578
|
* @returns the durable content-addressed file reference.
|
|
5579
5579
|
*/
|
|
5580
|
-
saveFile(
|
|
5581
|
-
void
|
|
5580
|
+
saveFile(input2) {
|
|
5581
|
+
void input2;
|
|
5582
5582
|
return Promise.reject(new AttachmentError(
|
|
5583
5583
|
"The mounted attachment provider cannot store verbatim files.",
|
|
5584
5584
|
"ATTACHMENT_FILES_UNSUPPORTED"
|
|
@@ -5591,8 +5591,8 @@ var AttachmentStore = class extends Service {
|
|
|
5591
5591
|
* @param input - ordered exact bytes, optional cancellation, and display name.
|
|
5592
5592
|
* @returns the durable content-addressed file reference.
|
|
5593
5593
|
*/
|
|
5594
|
-
saveFileStream(
|
|
5595
|
-
void
|
|
5594
|
+
saveFileStream(input2) {
|
|
5595
|
+
void input2;
|
|
5596
5596
|
return Promise.reject(new AttachmentError(
|
|
5597
5597
|
"The mounted attachment provider cannot stream verbatim files.",
|
|
5598
5598
|
"ATTACHMENT_FILES_UNSUPPORTED"
|
|
@@ -5649,10 +5649,10 @@ var DEFAULT_AGENTS_HOME_DISPLAY = `~/${AGENTS_HOME_DIR_NAME}`;
|
|
|
5649
5649
|
function defaultDshHome() {
|
|
5650
5650
|
return join(homedir(), DSH_HOME_DIR_NAME);
|
|
5651
5651
|
}
|
|
5652
|
-
function expandHomePath(
|
|
5653
|
-
if (
|
|
5654
|
-
if (
|
|
5655
|
-
return
|
|
5652
|
+
function expandHomePath(path5) {
|
|
5653
|
+
if (path5 === "~") return homedir();
|
|
5654
|
+
if (path5.startsWith("~/") || path5.startsWith("~\\")) return join(homedir(), path5.slice(2));
|
|
5655
|
+
return path5;
|
|
5656
5656
|
}
|
|
5657
5657
|
function resolveRoot(configured, env, envName, fallback) {
|
|
5658
5658
|
const fromEnv = env[envName];
|
|
@@ -5753,8 +5753,8 @@ function createLazyRequire(specifier, parentURL) {
|
|
|
5753
5753
|
};
|
|
5754
5754
|
}
|
|
5755
5755
|
var requireSharp = createLazyRequire("sharp", import.meta.url);
|
|
5756
|
-
function encodedAlphaIsCompatible(sourceHasAlpha,
|
|
5757
|
-
return sourceHasAlpha === void 0 ||
|
|
5756
|
+
function encodedAlphaIsCompatible(sourceHasAlpha, output2) {
|
|
5757
|
+
return sourceHasAlpha === void 0 || output2.hasAlpha === sourceHasAlpha || sourceHasAlpha && !output2.hasAlpha && output2.mediaType === "image/webp";
|
|
5758
5758
|
}
|
|
5759
5759
|
var MEDIA_TYPES = {
|
|
5760
5760
|
png: "image/png",
|
|
@@ -5885,17 +5885,17 @@ async function inspectMetadata(data, declaredMediaType, limits) {
|
|
|
5885
5885
|
if (detected.mediaType !== declaredMediaType) throw new AttachmentError("Declared image type does not match its bytes.", "IMAGE_TYPE_MISMATCH");
|
|
5886
5886
|
return detected;
|
|
5887
5887
|
}
|
|
5888
|
-
async function validateImageFile(
|
|
5889
|
-
await prepareImageFile(
|
|
5888
|
+
async function validateImageFile(input2, limits, policy) {
|
|
5889
|
+
await prepareImageFile(input2, limits, policy);
|
|
5890
5890
|
}
|
|
5891
|
-
async function prepareImageFile(
|
|
5892
|
-
if (
|
|
5891
|
+
async function prepareImageFile(input2, limits, policy) {
|
|
5892
|
+
if (input2.data.byteLength > limits.maxImageBytes) {
|
|
5893
5893
|
throw new AttachmentError("Image exceeds the configured byte limit.", "IMAGE_TOO_LARGE");
|
|
5894
5894
|
}
|
|
5895
|
-
const detected = await inspectMetadata(
|
|
5896
|
-
const normalized = await normalizeImage(
|
|
5895
|
+
const detected = await inspectMetadata(input2.data, input2.mediaType, limits);
|
|
5896
|
+
const normalized = await normalizeImage(input2.data, detected, policy);
|
|
5897
5897
|
const sha256 = digest(normalized.data);
|
|
5898
|
-
const name2 = displayName(
|
|
5898
|
+
const name2 = displayName(input2.name);
|
|
5899
5899
|
const downscaled = detected.width !== normalized.width || detected.height !== normalized.height;
|
|
5900
5900
|
return {
|
|
5901
5901
|
data: normalized.data,
|
|
@@ -5910,17 +5910,17 @@ async function prepareImageFile(input22, limits, policy) {
|
|
|
5910
5910
|
}
|
|
5911
5911
|
};
|
|
5912
5912
|
}
|
|
5913
|
-
async function syncDirectory(
|
|
5913
|
+
async function syncDirectory(path5) {
|
|
5914
5914
|
if (process.platform === "win32") return;
|
|
5915
|
-
const handle = await open(
|
|
5915
|
+
const handle = await open(path5, constants.O_RDONLY);
|
|
5916
5916
|
try {
|
|
5917
5917
|
await handle.sync();
|
|
5918
5918
|
} finally {
|
|
5919
5919
|
await handle.close();
|
|
5920
5920
|
}
|
|
5921
5921
|
}
|
|
5922
|
-
async function ensureDurableDirectory(
|
|
5923
|
-
const target = resolve3(
|
|
5922
|
+
async function ensureDurableDirectory(path5, boundary) {
|
|
5923
|
+
const target = resolve3(path5);
|
|
5924
5924
|
const stop = resolve3(boundary);
|
|
5925
5925
|
await mkdir(target, { recursive: true, mode: 448 });
|
|
5926
5926
|
await chmod(target, 448);
|
|
@@ -5932,8 +5932,8 @@ async function ensureDurableDirectory(path3, boundary) {
|
|
|
5932
5932
|
level = parent;
|
|
5933
5933
|
}
|
|
5934
5934
|
}
|
|
5935
|
-
async function ensureDurableHome(
|
|
5936
|
-
const home = resolve3(
|
|
5935
|
+
async function ensureDurableHome(path5) {
|
|
5936
|
+
const home = resolve3(path5);
|
|
5937
5937
|
if (!durableHomes.has(home)) {
|
|
5938
5938
|
await ensureDurableDirectory(home, parse(home).root);
|
|
5939
5939
|
durableHomes.add(home);
|
|
@@ -6053,13 +6053,13 @@ async function publishStagedObject(root, target, staged) {
|
|
|
6053
6053
|
throw new AttachmentError("Unable to persist attachment.", "ATTACHMENT_WRITE_FAILED", { cause: error62 });
|
|
6054
6054
|
}
|
|
6055
6055
|
}
|
|
6056
|
-
async function digestFile(
|
|
6056
|
+
async function digestFile(path5) {
|
|
6057
6057
|
const hash2 = createHash("sha256");
|
|
6058
|
-
for await (const chunk of createReadStream(
|
|
6058
|
+
for await (const chunk of createReadStream(path5)) hash2.update(chunk);
|
|
6059
6059
|
return hash2.digest("hex");
|
|
6060
6060
|
}
|
|
6061
|
-
async function removeTemporary(
|
|
6062
|
-
await unlink(
|
|
6061
|
+
async function removeTemporary(path5) {
|
|
6062
|
+
await unlink(path5).catch(
|
|
6063
6063
|
/* v8 ignore next -- Cleanup can observe a staging name already removed after successful linking. */
|
|
6064
6064
|
(cleanupError) => {
|
|
6065
6065
|
if (!(cleanupError instanceof Error && "code" in cleanupError && cleanupError.code === "ENOENT")) throw cleanupError;
|
|
@@ -6126,39 +6126,39 @@ function storedFilePath(root, ref) {
|
|
|
6126
6126
|
function storedFileObjectPath(root, sha256) {
|
|
6127
6127
|
return join3(root, "file-objects", sha256.slice(0, 2), sha256);
|
|
6128
6128
|
}
|
|
6129
|
-
async function saveFileVerbatim(root,
|
|
6130
|
-
const sha256 = createHash2("sha256").update(
|
|
6129
|
+
async function saveFileVerbatim(root, input2) {
|
|
6130
|
+
const sha256 = createHash2("sha256").update(input2.data).digest("hex");
|
|
6131
6131
|
const ref = {
|
|
6132
6132
|
attachmentId: brandString(`sha256:${sha256}`),
|
|
6133
|
-
name: fileLeafName(
|
|
6134
|
-
bytes:
|
|
6133
|
+
name: fileLeafName(input2.name),
|
|
6134
|
+
bytes: input2.data.byteLength
|
|
6135
6135
|
};
|
|
6136
6136
|
const objectPath = storedFileObjectPath(root, sha256);
|
|
6137
|
-
await publishImmutableObject(root, objectPath,
|
|
6137
|
+
await publishImmutableObject(root, objectPath, input2.data, sha256);
|
|
6138
6138
|
await publishImmutableAlias(root, objectPath, storedFilePath(root, ref), sha256);
|
|
6139
6139
|
return ref;
|
|
6140
6140
|
}
|
|
6141
|
-
async function saveFileStreamVerbatim(root,
|
|
6142
|
-
const name2 = fileLeafName(
|
|
6141
|
+
async function saveFileStreamVerbatim(root, input2) {
|
|
6142
|
+
const name2 = fileLeafName(input2.name);
|
|
6143
6143
|
const stored = await publishImmutableObjectStream(
|
|
6144
6144
|
root,
|
|
6145
|
-
|
|
6145
|
+
input2.data,
|
|
6146
6146
|
(sha256) => storedFileObjectPath(root, sha256),
|
|
6147
|
-
|
|
6147
|
+
input2.signal
|
|
6148
6148
|
);
|
|
6149
6149
|
const ref = {
|
|
6150
6150
|
attachmentId: brandString(`sha256:${stored.sha256}`),
|
|
6151
6151
|
name: name2,
|
|
6152
6152
|
bytes: stored.bytes
|
|
6153
6153
|
};
|
|
6154
|
-
|
|
6154
|
+
input2.signal?.throwIfAborted();
|
|
6155
6155
|
await publishImmutableAlias(
|
|
6156
6156
|
root,
|
|
6157
6157
|
storedFileObjectPath(root, stored.sha256),
|
|
6158
6158
|
storedFilePath(root, ref),
|
|
6159
6159
|
stored.sha256
|
|
6160
6160
|
);
|
|
6161
|
-
|
|
6161
|
+
input2.signal?.throwIfAborted();
|
|
6162
6162
|
return ref;
|
|
6163
6163
|
}
|
|
6164
6164
|
async function* readFileStreamVerbatim(root, ref, signal) {
|
|
@@ -6278,9 +6278,9 @@ async function createRequestImage(attachment, target, hasAlpha, policy, signal)
|
|
|
6278
6278
|
function cachePath(root, hash2) {
|
|
6279
6279
|
return join4(root, "request-images", hash2.slice(0, 2), hash2);
|
|
6280
6280
|
}
|
|
6281
|
-
async function readCached(
|
|
6281
|
+
async function readCached(path5, target, expectedAlpha, signal) {
|
|
6282
6282
|
try {
|
|
6283
|
-
const data = new Uint8Array(await readFile2(
|
|
6283
|
+
const data = new Uint8Array(await readFile2(path5, { signal }));
|
|
6284
6284
|
if (data.byteLength > target.maxImageBytes) return void 0;
|
|
6285
6285
|
const detected = await probeImage(data);
|
|
6286
6286
|
if (detected.depth !== "uchar" || detected.space !== "srgb" || detected.width > target.width || detected.height > target.height || !encodedAlphaIsCompatible(expectedAlpha, detected)) return void 0;
|
|
@@ -6301,12 +6301,12 @@ async function verifyRequestImage(image, expectedAlpha) {
|
|
|
6301
6301
|
}
|
|
6302
6302
|
return { ...image, hasAlpha: detected.hasAlpha };
|
|
6303
6303
|
}
|
|
6304
|
-
async function writeCached(
|
|
6305
|
-
await mkdir2(dirname3(
|
|
6306
|
-
const temporary = `${
|
|
6304
|
+
async function writeCached(path5, data) {
|
|
6305
|
+
await mkdir2(dirname3(path5), { recursive: true, mode: 448 });
|
|
6306
|
+
const temporary = `${path5}.${randomUUID3()}.tmp`;
|
|
6307
6307
|
try {
|
|
6308
6308
|
await writeFile(temporary, data, { mode: 384, flag: "wx" });
|
|
6309
|
-
await rename(temporary,
|
|
6309
|
+
await rename(temporary, path5);
|
|
6310
6310
|
} finally {
|
|
6311
6311
|
await rm(temporary, { force: true });
|
|
6312
6312
|
}
|
|
@@ -6317,12 +6317,12 @@ async function readRequestImageFile(root, attachment, target, policy, signal) {
|
|
|
6317
6317
|
const source = await probeImage(attachment.data);
|
|
6318
6318
|
const variantId = requestImageVariantId(attachment.ref, target, policy);
|
|
6319
6319
|
const hash2 = String(variantId).slice("sha256:".length);
|
|
6320
|
-
const
|
|
6321
|
-
const cached2 = await readCached(
|
|
6320
|
+
const path5 = cachePath(root, hash2);
|
|
6321
|
+
const cached2 = await readCached(path5, target, source.hasAlpha, signal);
|
|
6322
6322
|
const created = cached2 ?? await createRequestImage(attachment, target, source.hasAlpha, policy, signal);
|
|
6323
6323
|
const version3 = cached2 ?? (created.data === attachment.data ? { ...created, hasAlpha: source.hasAlpha } : await verifyRequestImage(created, source.hasAlpha));
|
|
6324
6324
|
signal?.throwIfAborted();
|
|
6325
|
-
if (cached2 === void 0 && version3.data !== attachment.data) await writeCached(
|
|
6325
|
+
if (cached2 === void 0 && version3.data !== attachment.data) await writeCached(path5, version3.data);
|
|
6326
6326
|
return {
|
|
6327
6327
|
variantId,
|
|
6328
6328
|
attachment: attachment.ref,
|
|
@@ -6462,21 +6462,21 @@ var LocalAttachmentStore = class extends AttachmentStore {
|
|
|
6462
6462
|
this.imageCompressionConcurrency = compressionConcurrency;
|
|
6463
6463
|
this.compression = new CompressionLimiter(compressionConcurrency);
|
|
6464
6464
|
}
|
|
6465
|
-
async validateImage(
|
|
6466
|
-
await this.compression.run(() => validateImageFile(
|
|
6465
|
+
async validateImage(input2) {
|
|
6466
|
+
await this.compression.run(() => validateImageFile(input2, this.imageLimits, this.normalizationPolicy));
|
|
6467
6467
|
}
|
|
6468
6468
|
async saveImages(inputs) {
|
|
6469
6469
|
this.validateImageBatch(inputs);
|
|
6470
|
-
const prepared = await Promise.all(inputs.map((
|
|
6471
|
-
() => prepareImageFile(
|
|
6470
|
+
const prepared = await Promise.all(inputs.map((input2) => this.compression.run(
|
|
6471
|
+
() => prepareImageFile(input2, this.imageLimits, this.normalizationPolicy)
|
|
6472
6472
|
)));
|
|
6473
6473
|
const refs = [];
|
|
6474
6474
|
for (const image of prepared) refs.push(await commitPreparedImageFile(this.root, image));
|
|
6475
6475
|
return refs;
|
|
6476
6476
|
}
|
|
6477
|
-
async saveImage(
|
|
6477
|
+
async saveImage(input2) {
|
|
6478
6478
|
const prepared = await this.compression.run(
|
|
6479
|
-
() => prepareImageFile(
|
|
6479
|
+
() => prepareImageFile(input2, this.imageLimits, this.normalizationPolicy)
|
|
6480
6480
|
);
|
|
6481
6481
|
return commitPreparedImageFile(this.root, prepared);
|
|
6482
6482
|
}
|
|
@@ -6486,11 +6486,11 @@ var LocalAttachmentStore = class extends AttachmentStore {
|
|
|
6486
6486
|
imageHostPath(ref) {
|
|
6487
6487
|
return normalizedImagePath(this.root, ref);
|
|
6488
6488
|
}
|
|
6489
|
-
async saveFile(
|
|
6490
|
-
return saveFileVerbatim(this.root,
|
|
6489
|
+
async saveFile(input2) {
|
|
6490
|
+
return saveFileVerbatim(this.root, input2);
|
|
6491
6491
|
}
|
|
6492
|
-
async saveFileStream(
|
|
6493
|
-
return saveFileStreamVerbatim(this.root,
|
|
6492
|
+
async saveFileStream(input2) {
|
|
6493
|
+
return saveFileStreamVerbatim(this.root, input2);
|
|
6494
6494
|
}
|
|
6495
6495
|
readFileStream(ref, signal) {
|
|
6496
6496
|
return readFileStreamVerbatim(this.root, ref, signal);
|
|
@@ -7436,8 +7436,8 @@ var Cached = class {
|
|
|
7436
7436
|
function cached(getter) {
|
|
7437
7437
|
return new Cached(getter);
|
|
7438
7438
|
}
|
|
7439
|
-
function nullish(
|
|
7440
|
-
return
|
|
7439
|
+
function nullish(input2) {
|
|
7440
|
+
return input2 === null || input2 === void 0;
|
|
7441
7441
|
}
|
|
7442
7442
|
function cleanRegex(source) {
|
|
7443
7443
|
const start = source.startsWith("^") ? 1 : 0;
|
|
@@ -7547,10 +7547,10 @@ function mergeDefs(...defs) {
|
|
|
7547
7547
|
function cloneDef(schema) {
|
|
7548
7548
|
return mergeDefs(schema._zod.def);
|
|
7549
7549
|
}
|
|
7550
|
-
function getElementAtPath(obj,
|
|
7551
|
-
if (!
|
|
7550
|
+
function getElementAtPath(obj, path5) {
|
|
7551
|
+
if (!path5)
|
|
7552
7552
|
return obj;
|
|
7553
|
-
return
|
|
7553
|
+
return path5.reduce((acc, key) => acc?.[key], obj);
|
|
7554
7554
|
}
|
|
7555
7555
|
function promiseAllObject(promisesObj) {
|
|
7556
7556
|
const keys = Object.keys(promisesObj);
|
|
@@ -7574,8 +7574,8 @@ function randomString(length = 10) {
|
|
|
7574
7574
|
function esc(str) {
|
|
7575
7575
|
return JSON.stringify(str);
|
|
7576
7576
|
}
|
|
7577
|
-
function slugify(
|
|
7578
|
-
return
|
|
7577
|
+
function slugify(input2) {
|
|
7578
|
+
return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
7579
7579
|
}
|
|
7580
7580
|
var captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
|
|
7581
7581
|
};
|
|
@@ -7890,11 +7890,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
7890
7890
|
}
|
|
7891
7891
|
return false;
|
|
7892
7892
|
}
|
|
7893
|
-
function prefixIssues(
|
|
7893
|
+
function prefixIssues(path5, issues) {
|
|
7894
7894
|
return issues.map((iss) => {
|
|
7895
7895
|
var _a4;
|
|
7896
7896
|
(_a4 = iss).path ?? (_a4.path = []);
|
|
7897
|
-
iss.path.unshift(
|
|
7897
|
+
iss.path.unshift(path5);
|
|
7898
7898
|
return iss;
|
|
7899
7899
|
});
|
|
7900
7900
|
}
|
|
@@ -7943,12 +7943,12 @@ function finalizeIssue(iss, ctx, config2) {
|
|
|
7943
7943
|
}
|
|
7944
7944
|
return full;
|
|
7945
7945
|
}
|
|
7946
|
-
function getSizableOrigin(
|
|
7947
|
-
if (
|
|
7946
|
+
function getSizableOrigin(input2) {
|
|
7947
|
+
if (input2 instanceof Set)
|
|
7948
7948
|
return "set";
|
|
7949
|
-
if (
|
|
7949
|
+
if (input2 instanceof Map)
|
|
7950
7950
|
return "map";
|
|
7951
|
-
if (
|
|
7951
|
+
if (input2 instanceof File)
|
|
7952
7952
|
return "file";
|
|
7953
7953
|
return "unknown";
|
|
7954
7954
|
}
|
|
@@ -7966,10 +7966,10 @@ function codePointLength(str) {
|
|
|
7966
7966
|
}
|
|
7967
7967
|
return count;
|
|
7968
7968
|
}
|
|
7969
|
-
function getLengthableOrigin(
|
|
7970
|
-
if (Array.isArray(
|
|
7969
|
+
function getLengthableOrigin(input2) {
|
|
7970
|
+
if (Array.isArray(input2))
|
|
7971
7971
|
return "array";
|
|
7972
|
-
if (typeof
|
|
7972
|
+
if (typeof input2 === "string")
|
|
7973
7973
|
return "string";
|
|
7974
7974
|
return "unknown";
|
|
7975
7975
|
}
|
|
@@ -7995,12 +7995,12 @@ function parsedType(data) {
|
|
|
7995
7995
|
return t;
|
|
7996
7996
|
}
|
|
7997
7997
|
function issue(...args) {
|
|
7998
|
-
const [iss,
|
|
7998
|
+
const [iss, input2, inst] = args;
|
|
7999
7999
|
if (typeof iss === "string") {
|
|
8000
8000
|
return {
|
|
8001
8001
|
message: iss,
|
|
8002
8002
|
code: "custom",
|
|
8003
|
-
input:
|
|
8003
|
+
input: input2,
|
|
8004
8004
|
inst
|
|
8005
8005
|
};
|
|
8006
8006
|
}
|
|
@@ -8352,16 +8352,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
8352
8352
|
}
|
|
8353
8353
|
function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
8354
8354
|
const fieldErrors = { _errors: [] };
|
|
8355
|
-
const processError = (error63,
|
|
8355
|
+
const processError = (error63, path5 = []) => {
|
|
8356
8356
|
for (const issue2 of error63.issues) {
|
|
8357
8357
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
8358
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
8358
|
+
issue2.errors.map((issues) => processError({ issues }, [...path5, ...issue2.path]));
|
|
8359
8359
|
} else if (issue2.code === "invalid_key") {
|
|
8360
|
-
processError({ issues: issue2.issues }, [...
|
|
8360
|
+
processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
|
|
8361
8361
|
} else if (issue2.code === "invalid_element") {
|
|
8362
|
-
processError({ issues: issue2.issues }, [...
|
|
8362
|
+
processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
|
|
8363
8363
|
} else {
|
|
8364
|
-
const fullpath = [...
|
|
8364
|
+
const fullpath = [...path5, ...issue2.path];
|
|
8365
8365
|
if (fullpath.length === 0) {
|
|
8366
8366
|
fieldErrors._errors.push(mapper(issue2));
|
|
8367
8367
|
} else {
|
|
@@ -8400,17 +8400,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
|
8400
8400
|
}
|
|
8401
8401
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
8402
8402
|
const result = { errors: [] };
|
|
8403
|
-
const processError = (error63,
|
|
8403
|
+
const processError = (error63, path5 = []) => {
|
|
8404
8404
|
var _a4;
|
|
8405
8405
|
for (const issue2 of error63.issues) {
|
|
8406
8406
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
8407
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
8407
|
+
issue2.errors.map((issues) => processError({ issues }, [...path5, ...issue2.path]));
|
|
8408
8408
|
} else if (issue2.code === "invalid_key") {
|
|
8409
|
-
processError({ issues: issue2.issues }, [...
|
|
8409
|
+
processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
|
|
8410
8410
|
} else if (issue2.code === "invalid_element") {
|
|
8411
|
-
processError({ issues: issue2.issues }, [...
|
|
8411
|
+
processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
|
|
8412
8412
|
} else {
|
|
8413
|
-
const fullpath = [...
|
|
8413
|
+
const fullpath = [...path5, ...issue2.path];
|
|
8414
8414
|
if (fullpath.length === 0) {
|
|
8415
8415
|
result.errors.push(mapper(issue2));
|
|
8416
8416
|
continue;
|
|
@@ -8449,8 +8449,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
8449
8449
|
}
|
|
8450
8450
|
function toDotPath(_path) {
|
|
8451
8451
|
const segs = [];
|
|
8452
|
-
const
|
|
8453
|
-
for (const seg of
|
|
8452
|
+
const path5 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
8453
|
+
for (const seg of path5) {
|
|
8454
8454
|
if (typeof seg === "number")
|
|
8455
8455
|
segs.push(`[${seg}]`);
|
|
8456
8456
|
else if (typeof seg === "symbol")
|
|
@@ -8886,23 +8886,23 @@ var $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat"
|
|
|
8886
8886
|
const origin = isInt ? "int" : "number";
|
|
8887
8887
|
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
|
|
8888
8888
|
inst._zod.check = (payload) => {
|
|
8889
|
-
const
|
|
8889
|
+
const input2 = payload.value;
|
|
8890
8890
|
if (isInt) {
|
|
8891
|
-
if (!Number.isInteger(
|
|
8891
|
+
if (!Number.isInteger(input2)) {
|
|
8892
8892
|
payload.issues.push({
|
|
8893
8893
|
expected: origin,
|
|
8894
8894
|
format: def.format,
|
|
8895
8895
|
code: "invalid_type",
|
|
8896
8896
|
continue: false,
|
|
8897
|
-
input:
|
|
8897
|
+
input: input2,
|
|
8898
8898
|
inst
|
|
8899
8899
|
});
|
|
8900
8900
|
return;
|
|
8901
8901
|
}
|
|
8902
|
-
if (!Number.isSafeInteger(
|
|
8903
|
-
if (
|
|
8902
|
+
if (!Number.isSafeInteger(input2)) {
|
|
8903
|
+
if (input2 > 0) {
|
|
8904
8904
|
payload.issues.push({
|
|
8905
|
-
input:
|
|
8905
|
+
input: input2,
|
|
8906
8906
|
code: "too_big",
|
|
8907
8907
|
maximum: Number.MAX_SAFE_INTEGER,
|
|
8908
8908
|
note: "Integers must be within the safe integer range.",
|
|
@@ -8913,7 +8913,7 @@ var $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat"
|
|
|
8913
8913
|
});
|
|
8914
8914
|
} else {
|
|
8915
8915
|
payload.issues.push({
|
|
8916
|
-
input:
|
|
8916
|
+
input: input2,
|
|
8917
8917
|
code: "too_small",
|
|
8918
8918
|
minimum: Number.MIN_SAFE_INTEGER,
|
|
8919
8919
|
note: "Integers must be within the safe integer range.",
|
|
@@ -8926,10 +8926,10 @@ var $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat"
|
|
|
8926
8926
|
return;
|
|
8927
8927
|
}
|
|
8928
8928
|
}
|
|
8929
|
-
if (
|
|
8929
|
+
if (input2 < minimum) {
|
|
8930
8930
|
payload.issues.push({
|
|
8931
8931
|
origin: "number",
|
|
8932
|
-
input:
|
|
8932
|
+
input: input2,
|
|
8933
8933
|
code: "too_small",
|
|
8934
8934
|
minimum,
|
|
8935
8935
|
inclusive: true,
|
|
@@ -8937,10 +8937,10 @@ var $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat"
|
|
|
8937
8937
|
continue: !def.abort
|
|
8938
8938
|
});
|
|
8939
8939
|
}
|
|
8940
|
-
if (
|
|
8940
|
+
if (input2 > maximum) {
|
|
8941
8941
|
payload.issues.push({
|
|
8942
8942
|
origin: "number",
|
|
8943
|
-
input:
|
|
8943
|
+
input: input2,
|
|
8944
8944
|
code: "too_big",
|
|
8945
8945
|
maximum,
|
|
8946
8946
|
inclusive: true,
|
|
@@ -8954,11 +8954,11 @@ var $ZodCheckBigIntFormat = /* @__PURE__ */ $constructor("$ZodCheckBigIntFormat"
|
|
|
8954
8954
|
$ZodCheck.init(inst, def);
|
|
8955
8955
|
const [minimum, maximum] = BIGINT_FORMAT_RANGES[def.format];
|
|
8956
8956
|
inst._zod.check = (payload) => {
|
|
8957
|
-
const
|
|
8958
|
-
if (
|
|
8957
|
+
const input2 = payload.value;
|
|
8958
|
+
if (input2 < minimum) {
|
|
8959
8959
|
payload.issues.push({
|
|
8960
8960
|
origin: "bigint",
|
|
8961
|
-
input:
|
|
8961
|
+
input: input2,
|
|
8962
8962
|
code: "too_small",
|
|
8963
8963
|
minimum,
|
|
8964
8964
|
inclusive: true,
|
|
@@ -8966,10 +8966,10 @@ var $ZodCheckBigIntFormat = /* @__PURE__ */ $constructor("$ZodCheckBigIntFormat"
|
|
|
8966
8966
|
continue: !def.abort
|
|
8967
8967
|
});
|
|
8968
8968
|
}
|
|
8969
|
-
if (
|
|
8969
|
+
if (input2 > maximum) {
|
|
8970
8970
|
payload.issues.push({
|
|
8971
8971
|
origin: "bigint",
|
|
8972
|
-
input:
|
|
8972
|
+
input: input2,
|
|
8973
8973
|
code: "too_big",
|
|
8974
8974
|
maximum,
|
|
8975
8975
|
inclusive: true,
|
|
@@ -8984,16 +8984,16 @@ var $ZodCheckMaxSize = /* @__PURE__ */ $constructor("$ZodCheckMaxSize", (inst, d
|
|
|
8984
8984
|
$ZodCheck.init(inst, def);
|
|
8985
8985
|
(_a4 = inst._zod.def).when ?? (_a4.when = _whenHasSize);
|
|
8986
8986
|
inst._zod.check = (payload) => {
|
|
8987
|
-
const
|
|
8988
|
-
const size =
|
|
8987
|
+
const input2 = payload.value;
|
|
8988
|
+
const size = input2.size;
|
|
8989
8989
|
if (size <= def.maximum)
|
|
8990
8990
|
return;
|
|
8991
8991
|
payload.issues.push({
|
|
8992
|
-
origin: getSizableOrigin(
|
|
8992
|
+
origin: getSizableOrigin(input2),
|
|
8993
8993
|
code: "too_big",
|
|
8994
8994
|
maximum: def.maximum,
|
|
8995
8995
|
inclusive: true,
|
|
8996
|
-
input:
|
|
8996
|
+
input: input2,
|
|
8997
8997
|
inst,
|
|
8998
8998
|
continue: !def.abort
|
|
8999
8999
|
});
|
|
@@ -9004,16 +9004,16 @@ var $ZodCheckMinSize = /* @__PURE__ */ $constructor("$ZodCheckMinSize", (inst, d
|
|
|
9004
9004
|
$ZodCheck.init(inst, def);
|
|
9005
9005
|
(_a4 = inst._zod.def).when ?? (_a4.when = _whenHasSize);
|
|
9006
9006
|
inst._zod.check = (payload) => {
|
|
9007
|
-
const
|
|
9008
|
-
const size =
|
|
9007
|
+
const input2 = payload.value;
|
|
9008
|
+
const size = input2.size;
|
|
9009
9009
|
if (size >= def.minimum)
|
|
9010
9010
|
return;
|
|
9011
9011
|
payload.issues.push({
|
|
9012
|
-
origin: getSizableOrigin(
|
|
9012
|
+
origin: getSizableOrigin(input2),
|
|
9013
9013
|
code: "too_small",
|
|
9014
9014
|
minimum: def.minimum,
|
|
9015
9015
|
inclusive: true,
|
|
9016
|
-
input:
|
|
9016
|
+
input: input2,
|
|
9017
9017
|
inst,
|
|
9018
9018
|
continue: !def.abort
|
|
9019
9019
|
});
|
|
@@ -9024,13 +9024,13 @@ var $ZodCheckSizeEquals = /* @__PURE__ */ $constructor("$ZodCheckSizeEquals", (i
|
|
|
9024
9024
|
$ZodCheck.init(inst, def);
|
|
9025
9025
|
(_a4 = inst._zod.def).when ?? (_a4.when = _whenHasSize);
|
|
9026
9026
|
inst._zod.check = (payload) => {
|
|
9027
|
-
const
|
|
9028
|
-
const size =
|
|
9027
|
+
const input2 = payload.value;
|
|
9028
|
+
const size = input2.size;
|
|
9029
9029
|
if (size === def.size)
|
|
9030
9030
|
return;
|
|
9031
9031
|
const tooBig = size > def.size;
|
|
9032
9032
|
payload.issues.push({
|
|
9033
|
-
origin: getSizableOrigin(
|
|
9033
|
+
origin: getSizableOrigin(input2),
|
|
9034
9034
|
...tooBig ? { code: "too_big", maximum: def.size } : { code: "too_small", minimum: def.size },
|
|
9035
9035
|
inclusive: true,
|
|
9036
9036
|
exact: true,
|
|
@@ -9045,18 +9045,18 @@ var $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (ins
|
|
|
9045
9045
|
$ZodCheck.init(inst, def);
|
|
9046
9046
|
(_a4 = inst._zod.def).when ?? (_a4.when = _whenHasLength);
|
|
9047
9047
|
inst._zod.check = (payload) => {
|
|
9048
|
-
const
|
|
9049
|
-
const units =
|
|
9050
|
-
const length = typeof
|
|
9048
|
+
const input2 = payload.value;
|
|
9049
|
+
const units = input2.length;
|
|
9050
|
+
const length = typeof input2 === "string" && units > def.maximum ? codePointLength(input2) : units;
|
|
9051
9051
|
if (length <= def.maximum)
|
|
9052
9052
|
return;
|
|
9053
|
-
const origin = getLengthableOrigin(
|
|
9053
|
+
const origin = getLengthableOrigin(input2);
|
|
9054
9054
|
payload.issues.push({
|
|
9055
9055
|
origin,
|
|
9056
9056
|
code: "too_big",
|
|
9057
9057
|
maximum: def.maximum,
|
|
9058
9058
|
inclusive: true,
|
|
9059
|
-
input:
|
|
9059
|
+
input: input2,
|
|
9060
9060
|
inst,
|
|
9061
9061
|
continue: !def.abort
|
|
9062
9062
|
});
|
|
@@ -9067,18 +9067,18 @@ var $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (ins
|
|
|
9067
9067
|
$ZodCheck.init(inst, def);
|
|
9068
9068
|
(_a4 = inst._zod.def).when ?? (_a4.when = _whenHasLength);
|
|
9069
9069
|
inst._zod.check = (payload) => {
|
|
9070
|
-
const
|
|
9071
|
-
const units =
|
|
9072
|
-
const length = typeof
|
|
9070
|
+
const input2 = payload.value;
|
|
9071
|
+
const units = input2.length;
|
|
9072
|
+
const length = typeof input2 === "string" && units >= def.minimum && units < def.minimum * 2 ? codePointLength(input2) : units;
|
|
9073
9073
|
if (length >= def.minimum)
|
|
9074
9074
|
return;
|
|
9075
|
-
const origin = getLengthableOrigin(
|
|
9075
|
+
const origin = getLengthableOrigin(input2);
|
|
9076
9076
|
payload.issues.push({
|
|
9077
9077
|
origin,
|
|
9078
9078
|
code: "too_small",
|
|
9079
9079
|
minimum: def.minimum,
|
|
9080
9080
|
inclusive: true,
|
|
9081
|
-
input:
|
|
9081
|
+
input: input2,
|
|
9082
9082
|
inst,
|
|
9083
9083
|
continue: !def.abort
|
|
9084
9084
|
});
|
|
@@ -9089,12 +9089,12 @@ var $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals"
|
|
|
9089
9089
|
$ZodCheck.init(inst, def);
|
|
9090
9090
|
(_a4 = inst._zod.def).when ?? (_a4.when = _whenHasLength);
|
|
9091
9091
|
inst._zod.check = (payload) => {
|
|
9092
|
-
const
|
|
9093
|
-
const units =
|
|
9094
|
-
const length = typeof
|
|
9092
|
+
const input2 = payload.value;
|
|
9093
|
+
const units = input2.length;
|
|
9094
|
+
const length = typeof input2 === "string" && units >= def.length && units <= def.length * 2 ? codePointLength(input2) : units;
|
|
9095
9095
|
if (length === def.length)
|
|
9096
9096
|
return;
|
|
9097
|
-
const origin = getLengthableOrigin(
|
|
9097
|
+
const origin = getLengthableOrigin(input2);
|
|
9098
9098
|
const tooBig = length > def.length;
|
|
9099
9099
|
payload.issues.push({
|
|
9100
9100
|
origin,
|
|
@@ -9240,10 +9240,10 @@ var $ZodCheckProperties = /* @__PURE__ */ $constructor("$ZodCheckProperties", (i
|
|
|
9240
9240
|
return void 0;
|
|
9241
9241
|
}
|
|
9242
9242
|
entries ?? (entries = Reflect.ownKeys(def.shape).map((key) => [key, def.shape[key]]));
|
|
9243
|
-
const
|
|
9243
|
+
const input2 = payload.value;
|
|
9244
9244
|
let proms;
|
|
9245
9245
|
for (const [key, schema] of entries) {
|
|
9246
|
-
const result = schema._zod.run({ value:
|
|
9246
|
+
const result = schema._zod.run({ value: input2[key], issues: [] }, {});
|
|
9247
9247
|
if (result instanceof Promise) {
|
|
9248
9248
|
proms ?? (proms = []);
|
|
9249
9249
|
proms.push(result.then((result2) => handleCheckPropertyResult(result2, payload, key)));
|
|
@@ -9505,11 +9505,11 @@ var $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
|
9505
9505
|
});
|
|
9506
9506
|
var URL_BAD_FORMAT = 1;
|
|
9507
9507
|
var URL_UNPARSEABLE = 2;
|
|
9508
|
-
function canParseURL(
|
|
9508
|
+
function canParseURL(input2) {
|
|
9509
9509
|
try {
|
|
9510
9510
|
if (typeof URL !== "undefined" && typeof URL.canParse === "function")
|
|
9511
|
-
return URL.canParse(
|
|
9512
|
-
new URL(
|
|
9511
|
+
return URL.canParse(input2);
|
|
9512
|
+
new URL(input2);
|
|
9513
9513
|
return true;
|
|
9514
9514
|
} catch {
|
|
9515
9515
|
return false;
|
|
@@ -9540,9 +9540,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
9540
9540
|
function stripTabAndNewline(value) {
|
|
9541
9541
|
return value.replace(asciiTabOrNewline, "");
|
|
9542
9542
|
}
|
|
9543
|
-
function urlHostnameOk(url2,
|
|
9544
|
-
|
|
9545
|
-
return
|
|
9543
|
+
function urlHostnameOk(url2, hostname32) {
|
|
9544
|
+
hostname32.lastIndex = 0;
|
|
9545
|
+
return hostname32.test(url2.hostname);
|
|
9546
9546
|
}
|
|
9547
9547
|
function urlProtocolOk(url2, protocol) {
|
|
9548
9548
|
protocol.lastIndex = 0;
|
|
@@ -9791,10 +9791,10 @@ function isLuhnAlgo(digits) {
|
|
|
9791
9791
|
}
|
|
9792
9792
|
return sum % 10 === 0;
|
|
9793
9793
|
}
|
|
9794
|
-
function isValidCreditCard(
|
|
9795
|
-
if (!creditCard.test(
|
|
9794
|
+
function isValidCreditCard(input2) {
|
|
9795
|
+
if (!creditCard.test(input2))
|
|
9796
9796
|
return false;
|
|
9797
|
-
return isLuhnAlgo(
|
|
9797
|
+
return isLuhnAlgo(input2.replace(CC_SANITIZE, ""));
|
|
9798
9798
|
}
|
|
9799
9799
|
var $ZodCreditCard = /* @__PURE__ */ $constructor("$ZodCreditCard", (inst, def) => {
|
|
9800
9800
|
def.pattern ?? (def.pattern = creditCard);
|
|
@@ -9824,10 +9824,10 @@ function isIso7064Mod97(iban3) {
|
|
|
9824
9824
|
}
|
|
9825
9825
|
return remainder === 1;
|
|
9826
9826
|
}
|
|
9827
|
-
function isValidIBAN(
|
|
9828
|
-
if (!iban.test(
|
|
9827
|
+
function isValidIBAN(input2) {
|
|
9828
|
+
if (!iban.test(input2))
|
|
9829
9829
|
return false;
|
|
9830
|
-
return isIso7064Mod97(
|
|
9830
|
+
return isIso7064Mod97(input2);
|
|
9831
9831
|
}
|
|
9832
9832
|
var $ZodIBAN = /* @__PURE__ */ $constructor("$ZodIBAN", (inst, def) => {
|
|
9833
9833
|
def.pattern ?? (def.pattern = iban);
|
|
@@ -9901,15 +9901,15 @@ var $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
|
9901
9901
|
payload.value = Number(payload.value);
|
|
9902
9902
|
} catch (_) {
|
|
9903
9903
|
}
|
|
9904
|
-
const
|
|
9905
|
-
if (typeof
|
|
9904
|
+
const input2 = payload.value;
|
|
9905
|
+
if (typeof input2 === "number" && !Number.isNaN(input2) && Number.isFinite(input2)) {
|
|
9906
9906
|
return payload;
|
|
9907
9907
|
}
|
|
9908
|
-
const received = typeof
|
|
9908
|
+
const received = typeof input2 === "number" ? Number.isNaN(input2) ? "NaN" : !Number.isFinite(input2) ? String(input2) : void 0 : void 0;
|
|
9909
9909
|
payload.issues.push({
|
|
9910
9910
|
expected: "number",
|
|
9911
9911
|
code: "invalid_type",
|
|
9912
|
-
input:
|
|
9912
|
+
input: input2,
|
|
9913
9913
|
inst,
|
|
9914
9914
|
...received ? { received } : {}
|
|
9915
9915
|
});
|
|
@@ -9929,13 +9929,13 @@ var $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
|
9929
9929
|
payload.value = Boolean(payload.value);
|
|
9930
9930
|
} catch (_) {
|
|
9931
9931
|
}
|
|
9932
|
-
const
|
|
9933
|
-
if (typeof
|
|
9932
|
+
const input2 = payload.value;
|
|
9933
|
+
if (typeof input2 === "boolean")
|
|
9934
9934
|
return payload;
|
|
9935
9935
|
payload.issues.push({
|
|
9936
9936
|
expected: "boolean",
|
|
9937
9937
|
code: "invalid_type",
|
|
9938
|
-
input:
|
|
9938
|
+
input: input2,
|
|
9939
9939
|
inst
|
|
9940
9940
|
});
|
|
9941
9941
|
return payload;
|
|
@@ -9968,13 +9968,13 @@ var $ZodBigIntFormat = /* @__PURE__ */ $constructor("$ZodBigIntFormat", (inst, d
|
|
|
9968
9968
|
var $ZodSymbol = /* @__PURE__ */ $constructor("$ZodSymbol", (inst, def) => {
|
|
9969
9969
|
$ZodType.init(inst, def);
|
|
9970
9970
|
inst._zod.parse = (payload, _ctx) => {
|
|
9971
|
-
const
|
|
9972
|
-
if (typeof
|
|
9971
|
+
const input2 = payload.value;
|
|
9972
|
+
if (typeof input2 === "symbol")
|
|
9973
9973
|
return payload;
|
|
9974
9974
|
payload.issues.push({
|
|
9975
9975
|
expected: "symbol",
|
|
9976
9976
|
code: "invalid_type",
|
|
9977
|
-
input:
|
|
9977
|
+
input: input2,
|
|
9978
9978
|
inst
|
|
9979
9979
|
});
|
|
9980
9980
|
return payload;
|
|
@@ -9985,13 +9985,13 @@ var $ZodUndefined = /* @__PURE__ */ $constructor("$ZodUndefined", (inst, def) =>
|
|
|
9985
9985
|
inst._zod.pattern = _undefined;
|
|
9986
9986
|
inst._zod.values = /* @__PURE__ */ new Set([void 0]);
|
|
9987
9987
|
inst._zod.parse = (payload, _ctx) => {
|
|
9988
|
-
const
|
|
9989
|
-
if (typeof
|
|
9988
|
+
const input2 = payload.value;
|
|
9989
|
+
if (typeof input2 === "undefined")
|
|
9990
9990
|
return payload;
|
|
9991
9991
|
payload.issues.push({
|
|
9992
9992
|
expected: "undefined",
|
|
9993
9993
|
code: "invalid_type",
|
|
9994
|
-
input:
|
|
9994
|
+
input: input2,
|
|
9995
9995
|
inst
|
|
9996
9996
|
});
|
|
9997
9997
|
return payload;
|
|
@@ -10002,13 +10002,13 @@ var $ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
|
10002
10002
|
inst._zod.pattern = _null;
|
|
10003
10003
|
inst._zod.values = /* @__PURE__ */ new Set([null]);
|
|
10004
10004
|
inst._zod.parse = (payload, _ctx) => {
|
|
10005
|
-
const
|
|
10006
|
-
if (
|
|
10005
|
+
const input2 = payload.value;
|
|
10006
|
+
if (input2 === null)
|
|
10007
10007
|
return payload;
|
|
10008
10008
|
payload.issues.push({
|
|
10009
10009
|
expected: "null",
|
|
10010
10010
|
code: "invalid_type",
|
|
10011
|
-
input:
|
|
10011
|
+
input: input2,
|
|
10012
10012
|
inst
|
|
10013
10013
|
});
|
|
10014
10014
|
return payload;
|
|
@@ -10037,13 +10037,13 @@ var $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
|
|
|
10037
10037
|
var $ZodVoid = /* @__PURE__ */ $constructor("$ZodVoid", (inst, def) => {
|
|
10038
10038
|
$ZodType.init(inst, def);
|
|
10039
10039
|
inst._zod.parse = (payload, _ctx) => {
|
|
10040
|
-
const
|
|
10041
|
-
if (typeof
|
|
10040
|
+
const input2 = payload.value;
|
|
10041
|
+
if (typeof input2 === "undefined")
|
|
10042
10042
|
return payload;
|
|
10043
10043
|
payload.issues.push({
|
|
10044
10044
|
expected: "void",
|
|
10045
10045
|
code: "invalid_type",
|
|
10046
|
-
input:
|
|
10046
|
+
input: input2,
|
|
10047
10047
|
inst
|
|
10048
10048
|
});
|
|
10049
10049
|
return payload;
|
|
@@ -10058,15 +10058,15 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
10058
10058
|
} catch (_err) {
|
|
10059
10059
|
}
|
|
10060
10060
|
}
|
|
10061
|
-
const
|
|
10062
|
-
const isDate =
|
|
10063
|
-
const isValidDate = isDate && !Number.isNaN(
|
|
10061
|
+
const input2 = payload.value;
|
|
10062
|
+
const isDate = input2 instanceof Date;
|
|
10063
|
+
const isValidDate = isDate && !Number.isNaN(input2.getTime());
|
|
10064
10064
|
if (isValidDate)
|
|
10065
10065
|
return payload;
|
|
10066
10066
|
payload.issues.push({
|
|
10067
10067
|
expected: "date",
|
|
10068
10068
|
code: "invalid_type",
|
|
10069
|
-
input:
|
|
10069
|
+
input: input2,
|
|
10070
10070
|
...isDate ? { received: "Invalid Date" } : {},
|
|
10071
10071
|
inst
|
|
10072
10072
|
});
|
|
@@ -10095,9 +10095,9 @@ function capSize(inst, size) {
|
|
|
10095
10095
|
return parse4(payload, ctx);
|
|
10096
10096
|
};
|
|
10097
10097
|
}
|
|
10098
|
-
var arraySize = (
|
|
10099
|
-
var mapSize = (
|
|
10100
|
-
var setSize = (
|
|
10098
|
+
var arraySize = (input2) => Array.isArray(input2) ? input2.length : -1;
|
|
10099
|
+
var mapSize = (input2) => input2 instanceof Map ? input2.size : -1;
|
|
10100
|
+
var setSize = (input2) => input2 instanceof Set ? input2.size : -1;
|
|
10101
10101
|
function handleArrayResult(result, final, index) {
|
|
10102
10102
|
if (result.issues.length) {
|
|
10103
10103
|
final.issues.push(...prefixIssues(index, result.issues));
|
|
@@ -10109,21 +10109,21 @@ var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
|
10109
10109
|
const memo2 = globalConfig.memoizer;
|
|
10110
10110
|
memo2?.attach(inst);
|
|
10111
10111
|
inst._zod.parse = (payload, ctx) => {
|
|
10112
|
-
const
|
|
10113
|
-
if (!Array.isArray(
|
|
10112
|
+
const input2 = payload.value;
|
|
10113
|
+
if (!Array.isArray(input2)) {
|
|
10114
10114
|
payload.issues.push({
|
|
10115
10115
|
expected: "array",
|
|
10116
10116
|
code: "invalid_type",
|
|
10117
|
-
input:
|
|
10117
|
+
input: input2,
|
|
10118
10118
|
inst
|
|
10119
10119
|
});
|
|
10120
10120
|
return payload;
|
|
10121
10121
|
}
|
|
10122
|
-
payload.value = memo2 ? memo2.alloc(inst, payload, Array(
|
|
10122
|
+
payload.value = memo2 ? memo2.alloc(inst, payload, Array(input2.length), ctx) : Array(input2.length);
|
|
10123
10123
|
const proms = [];
|
|
10124
10124
|
const abortEarly = ctx?.abortEarly;
|
|
10125
|
-
for (let i = 0; i <
|
|
10126
|
-
const item =
|
|
10125
|
+
for (let i = 0; i < input2.length; i++) {
|
|
10126
|
+
const item = input2[i];
|
|
10127
10127
|
const result = def.element._zod.run({
|
|
10128
10128
|
value: item,
|
|
10129
10129
|
issues: []
|
|
@@ -10143,8 +10143,8 @@ var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
|
10143
10143
|
};
|
|
10144
10144
|
capSize(inst, arraySize);
|
|
10145
10145
|
});
|
|
10146
|
-
function handlePropertyResult(result, final, key,
|
|
10147
|
-
const isPresent = key in
|
|
10146
|
+
function handlePropertyResult(result, final, key, input2, optin, optout) {
|
|
10147
|
+
const isPresent = key in input2;
|
|
10148
10148
|
const isOptionalOut = optout === "optional";
|
|
10149
10149
|
if (!isPresent && isOptionalOut && optin === "optional") {
|
|
10150
10150
|
return;
|
|
@@ -10196,7 +10196,7 @@ function normalizeDef(def) {
|
|
|
10196
10196
|
optionalKeys: new Set(okeys)
|
|
10197
10197
|
};
|
|
10198
10198
|
}
|
|
10199
|
-
function handleCatchall(proms,
|
|
10199
|
+
function handleCatchall(proms, input2, payload, ctx, def, inst, abortEarly) {
|
|
10200
10200
|
const unrecognized = [];
|
|
10201
10201
|
const keySet = def.keySet;
|
|
10202
10202
|
const _catchall = def.catchall._zod;
|
|
@@ -10204,7 +10204,7 @@ function handleCatchall(proms, input22, payload, ctx, def, inst, abortEarly) {
|
|
|
10204
10204
|
const optin = _catchall.optin;
|
|
10205
10205
|
const optout = _catchall.optout;
|
|
10206
10206
|
let seen = 0;
|
|
10207
|
-
for (const key in
|
|
10207
|
+
for (const key in input2) {
|
|
10208
10208
|
if (abortEarly && payload.issues.length !== seen) {
|
|
10209
10209
|
if (aborted(payload, seen))
|
|
10210
10210
|
break;
|
|
@@ -10221,18 +10221,18 @@ function handleCatchall(proms, input22, payload, ctx, def, inst, abortEarly) {
|
|
|
10221
10221
|
unrecognized.push(key);
|
|
10222
10222
|
continue;
|
|
10223
10223
|
}
|
|
10224
|
-
const r = _catchall.run({ value:
|
|
10224
|
+
const r = _catchall.run({ value: input2[key], issues: [] }, ctx);
|
|
10225
10225
|
if (r instanceof Promise) {
|
|
10226
|
-
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key,
|
|
10226
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input2, optin, optout)));
|
|
10227
10227
|
} else {
|
|
10228
|
-
handlePropertyResult(r, payload, key,
|
|
10228
|
+
handlePropertyResult(r, payload, key, input2, optin, optout);
|
|
10229
10229
|
}
|
|
10230
10230
|
}
|
|
10231
10231
|
if (unrecognized.length) {
|
|
10232
10232
|
payload.issues.push({
|
|
10233
10233
|
code: "unrecognized_keys",
|
|
10234
10234
|
keys: unrecognized,
|
|
10235
|
-
input:
|
|
10235
|
+
input: input2,
|
|
10236
10236
|
inst,
|
|
10237
10237
|
// Describes the shape of the input, not the validity of the parsed value, so it never aborts. The parse still fails; the schema's own checks just get to run first, and an enclosing intersection can reconcile the key against a sibling operand.
|
|
10238
10238
|
continue: true
|
|
@@ -10283,12 +10283,12 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
10283
10283
|
memo2?.attach(inst);
|
|
10284
10284
|
inst._zod.parse = (payload, ctx) => {
|
|
10285
10285
|
value ?? (value = _normalized.value);
|
|
10286
|
-
const
|
|
10287
|
-
if (!isObject3(
|
|
10286
|
+
const input2 = payload.value;
|
|
10287
|
+
if (!isObject3(input2)) {
|
|
10288
10288
|
payload.issues.push({
|
|
10289
10289
|
expected: "object",
|
|
10290
10290
|
code: "invalid_type",
|
|
10291
|
-
input:
|
|
10291
|
+
input: input2,
|
|
10292
10292
|
inst
|
|
10293
10293
|
});
|
|
10294
10294
|
return payload;
|
|
@@ -10309,17 +10309,17 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
10309
10309
|
const el = shape[key];
|
|
10310
10310
|
const optin = el._zod.optin;
|
|
10311
10311
|
const optout = el._zod.optout;
|
|
10312
|
-
const r = el._zod.run({ value:
|
|
10312
|
+
const r = el._zod.run({ value: input2[key], issues: [] }, ctx);
|
|
10313
10313
|
if (r instanceof Promise) {
|
|
10314
|
-
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key,
|
|
10314
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input2, optin, optout)));
|
|
10315
10315
|
} else {
|
|
10316
|
-
handlePropertyResult(r, payload, key,
|
|
10316
|
+
handlePropertyResult(r, payload, key, input2, optin, optout);
|
|
10317
10317
|
}
|
|
10318
10318
|
}
|
|
10319
10319
|
if (!catchall) {
|
|
10320
10320
|
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
10321
10321
|
}
|
|
10322
|
-
return handleCatchall(proms,
|
|
10322
|
+
return handleCatchall(proms, input2, payload, ctx, _normalized.value, inst, abortEarly === true);
|
|
10323
10323
|
};
|
|
10324
10324
|
});
|
|
10325
10325
|
var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
|
|
@@ -10428,12 +10428,12 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
10428
10428
|
let value;
|
|
10429
10429
|
inst._zod.parse = (payload, ctx) => {
|
|
10430
10430
|
value ?? (value = _normalized.value);
|
|
10431
|
-
const
|
|
10432
|
-
if (!isObject3(
|
|
10431
|
+
const input2 = payload.value;
|
|
10432
|
+
if (!isObject3(input2)) {
|
|
10433
10433
|
payload.issues.push({
|
|
10434
10434
|
expected: "object",
|
|
10435
10435
|
code: "invalid_type",
|
|
10436
|
-
input:
|
|
10436
|
+
input: input2,
|
|
10437
10437
|
inst
|
|
10438
10438
|
});
|
|
10439
10439
|
return payload;
|
|
@@ -10444,7 +10444,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
10444
10444
|
payload = fastpass(payload, ctx);
|
|
10445
10445
|
if (!catchall)
|
|
10446
10446
|
return payload;
|
|
10447
|
-
return handleCatchall([],
|
|
10447
|
+
return handleCatchall([], input2, payload, ctx, value, inst, ctx?.abortEarly === true);
|
|
10448
10448
|
}
|
|
10449
10449
|
return superParse(payload, ctx);
|
|
10450
10450
|
};
|
|
@@ -10636,17 +10636,17 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
10636
10636
|
});
|
|
10637
10637
|
const disc = cached(() => discriminatorMap(def));
|
|
10638
10638
|
inst._zod.parse = (payload, ctx) => {
|
|
10639
|
-
const
|
|
10640
|
-
if (!isObject2(
|
|
10639
|
+
const input2 = payload.value;
|
|
10640
|
+
if (!isObject2(input2)) {
|
|
10641
10641
|
payload.issues.push({
|
|
10642
10642
|
code: "invalid_type",
|
|
10643
10643
|
expected: "object",
|
|
10644
|
-
input:
|
|
10644
|
+
input: input2,
|
|
10645
10645
|
inst
|
|
10646
10646
|
});
|
|
10647
10647
|
return payload;
|
|
10648
10648
|
}
|
|
10649
|
-
const value =
|
|
10649
|
+
const value = input2?.[def.discriminator];
|
|
10650
10650
|
const opt = disc.value.get(value);
|
|
10651
10651
|
if (opt && (value !== void 0 || ctx.direction !== "backward")) {
|
|
10652
10652
|
return opt._zod.run(payload, ctx);
|
|
@@ -10660,7 +10660,7 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
10660
10660
|
note: "No matching discriminator",
|
|
10661
10661
|
discriminator: def.discriminator,
|
|
10662
10662
|
options: Array.from(disc.value.keys()).filter((value2) => disc.value.get(value2) !== null),
|
|
10663
|
-
input:
|
|
10663
|
+
input: input2,
|
|
10664
10664
|
path: [def.discriminator],
|
|
10665
10665
|
inst
|
|
10666
10666
|
});
|
|
@@ -10670,9 +10670,9 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
10670
10670
|
var $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
|
|
10671
10671
|
$ZodType.init(inst, def);
|
|
10672
10672
|
inst._zod.parse = (payload, ctx) => {
|
|
10673
|
-
const
|
|
10674
|
-
const left = def.left._zod.run({ value:
|
|
10675
|
-
const right = def.right._zod.run({ value:
|
|
10673
|
+
const input2 = payload.value;
|
|
10674
|
+
const left = def.left._zod.run({ value: input2, issues: [] }, ctx);
|
|
10675
|
+
const right = def.right._zod.run({ value: input2, issues: [] }, ctx);
|
|
10676
10676
|
const async = left instanceof Promise || right instanceof Promise;
|
|
10677
10677
|
if (async) {
|
|
10678
10678
|
return Promise.all([left, right]).then(([left2, right2]) => {
|
|
@@ -10787,10 +10787,10 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
10787
10787
|
const memo2 = globalConfig.memoizer;
|
|
10788
10788
|
memo2?.attach(inst);
|
|
10789
10789
|
inst._zod.parse = (payload, ctx) => {
|
|
10790
|
-
const
|
|
10791
|
-
if (!Array.isArray(
|
|
10790
|
+
const input2 = payload.value;
|
|
10791
|
+
if (!Array.isArray(input2)) {
|
|
10792
10792
|
payload.issues.push({
|
|
10793
|
-
input:
|
|
10793
|
+
input: input2,
|
|
10794
10794
|
inst,
|
|
10795
10795
|
expected: "tuple",
|
|
10796
10796
|
code: "invalid_type"
|
|
@@ -10802,23 +10802,23 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
10802
10802
|
const optinStart = getTupleOptStart(items, "optin");
|
|
10803
10803
|
const optoutStart = getTupleOptStart(items, "optout");
|
|
10804
10804
|
if (!def.rest) {
|
|
10805
|
-
if (
|
|
10805
|
+
if (input2.length < optinStart) {
|
|
10806
10806
|
payload.issues.push({
|
|
10807
10807
|
code: "too_small",
|
|
10808
10808
|
minimum: optinStart,
|
|
10809
10809
|
inclusive: true,
|
|
10810
|
-
input:
|
|
10810
|
+
input: input2,
|
|
10811
10811
|
inst,
|
|
10812
10812
|
origin: "array"
|
|
10813
10813
|
});
|
|
10814
10814
|
return payload;
|
|
10815
10815
|
}
|
|
10816
|
-
if (
|
|
10816
|
+
if (input2.length > items.length) {
|
|
10817
10817
|
payload.issues.push({
|
|
10818
10818
|
code: "too_big",
|
|
10819
10819
|
maximum: items.length,
|
|
10820
10820
|
inclusive: true,
|
|
10821
|
-
input:
|
|
10821
|
+
input: input2,
|
|
10822
10822
|
inst,
|
|
10823
10823
|
origin: "array"
|
|
10824
10824
|
});
|
|
@@ -10828,7 +10828,7 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
10828
10828
|
const abortEarly = def.rest ? ctx?.abortEarly : void 0;
|
|
10829
10829
|
let itemAborted = false;
|
|
10830
10830
|
for (let i = 0; i < items.length; i++) {
|
|
10831
|
-
const r = items[i]._zod.run({ value:
|
|
10831
|
+
const r = items[i]._zod.run({ value: input2[i], issues: [] }, ctx);
|
|
10832
10832
|
if (r instanceof Promise) {
|
|
10833
10833
|
proms.push(r.then((rr) => {
|
|
10834
10834
|
itemResults[i] = rr;
|
|
@@ -10841,7 +10841,7 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
10841
10841
|
}
|
|
10842
10842
|
if (def.rest && !itemAborted) {
|
|
10843
10843
|
let i = items.length - 1;
|
|
10844
|
-
const rest =
|
|
10844
|
+
const rest = input2.slice(items.length);
|
|
10845
10845
|
let seen = payload.issues.length;
|
|
10846
10846
|
for (const el of rest) {
|
|
10847
10847
|
if (abortEarly && payload.issues.length !== seen) {
|
|
@@ -10859,9 +10859,9 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
10859
10859
|
}
|
|
10860
10860
|
}
|
|
10861
10861
|
if (proms.length) {
|
|
10862
|
-
return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items,
|
|
10862
|
+
return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input2, optoutStart));
|
|
10863
10863
|
}
|
|
10864
|
-
return handleTupleResults(itemResults, payload, items,
|
|
10864
|
+
return handleTupleResults(itemResults, payload, items, input2, optoutStart);
|
|
10865
10865
|
};
|
|
10866
10866
|
});
|
|
10867
10867
|
function getTupleOptStart(items, key) {
|
|
@@ -10878,10 +10878,10 @@ function handleTupleResult(result, final, index) {
|
|
|
10878
10878
|
}
|
|
10879
10879
|
final.value[index] = result.value;
|
|
10880
10880
|
}
|
|
10881
|
-
function handleTupleResults(itemResults, final, items,
|
|
10881
|
+
function handleTupleResults(itemResults, final, items, input2, optoutStart) {
|
|
10882
10882
|
for (let i = 0; i < items.length; i++) {
|
|
10883
10883
|
const r = itemResults[i];
|
|
10884
|
-
const isPresent = i <
|
|
10884
|
+
const isPresent = i < input2.length;
|
|
10885
10885
|
if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
|
|
10886
10886
|
final.value.length = i;
|
|
10887
10887
|
break;
|
|
@@ -10895,7 +10895,7 @@ function handleTupleResults(itemResults, final, items, input22, optoutStart) {
|
|
|
10895
10895
|
}
|
|
10896
10896
|
final.value[i] = r.value;
|
|
10897
10897
|
}
|
|
10898
|
-
for (let i = final.value.length - 1; i >=
|
|
10898
|
+
for (let i = final.value.length - 1; i >= input2.length; i--) {
|
|
10899
10899
|
if (items[i]._zod.optout === "optional" && final.value[i] === void 0) {
|
|
10900
10900
|
final.value.length = i;
|
|
10901
10901
|
} else {
|
|
@@ -10909,12 +10909,12 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
10909
10909
|
const memo2 = globalConfig.memoizer;
|
|
10910
10910
|
memo2?.attach(inst);
|
|
10911
10911
|
inst._zod.parse = (payload, ctx) => {
|
|
10912
|
-
const
|
|
10913
|
-
if (!isPlainObject2(
|
|
10912
|
+
const input2 = payload.value;
|
|
10913
|
+
if (!isPlainObject2(input2)) {
|
|
10914
10914
|
payload.issues.push({
|
|
10915
10915
|
expected: "record",
|
|
10916
10916
|
code: "invalid_type",
|
|
10917
|
-
input:
|
|
10917
|
+
input: input2,
|
|
10918
10918
|
inst
|
|
10919
10919
|
});
|
|
10920
10920
|
return payload;
|
|
@@ -10947,7 +10947,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
10947
10947
|
const outKey = keyResult.value;
|
|
10948
10948
|
if (outKey === "__proto__")
|
|
10949
10949
|
continue;
|
|
10950
|
-
const result = def.valueType._zod.run({ value:
|
|
10950
|
+
const result = def.valueType._zod.run({ value: input2[key], issues: [] }, ctx);
|
|
10951
10951
|
if (result instanceof Promise) {
|
|
10952
10952
|
proms.push(result.then((result2) => {
|
|
10953
10953
|
if (result2.issues.length) {
|
|
@@ -10964,12 +10964,12 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
10964
10964
|
}
|
|
10965
10965
|
}
|
|
10966
10966
|
let unrecognized;
|
|
10967
|
-
for (const key in
|
|
10967
|
+
for (const key in input2) {
|
|
10968
10968
|
if (!recordKeys.has(key)) {
|
|
10969
10969
|
if (def.mode === "loose") {
|
|
10970
10970
|
if (key === "__proto__")
|
|
10971
10971
|
continue;
|
|
10972
|
-
payload.value[key] =
|
|
10972
|
+
payload.value[key] = input2[key];
|
|
10973
10973
|
} else {
|
|
10974
10974
|
unrecognized = unrecognized ?? [];
|
|
10975
10975
|
unrecognized.push(key);
|
|
@@ -10979,7 +10979,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
10979
10979
|
if (unrecognized && unrecognized.length > 0) {
|
|
10980
10980
|
payload.issues.push({
|
|
10981
10981
|
code: "unrecognized_keys",
|
|
10982
|
-
input:
|
|
10982
|
+
input: input2,
|
|
10983
10983
|
inst,
|
|
10984
10984
|
keys: unrecognized,
|
|
10985
10985
|
continue: true
|
|
@@ -10988,10 +10988,10 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
10988
10988
|
} else {
|
|
10989
10989
|
payload.value = memo2 ? memo2.alloc(inst, payload, {}, ctx) : {};
|
|
10990
10990
|
let unrecognized;
|
|
10991
|
-
for (const key of Reflect.ownKeys(
|
|
10991
|
+
for (const key of Reflect.ownKeys(input2)) {
|
|
10992
10992
|
if (key === "__proto__")
|
|
10993
10993
|
continue;
|
|
10994
|
-
if (!Object.prototype.propertyIsEnumerable.call(
|
|
10994
|
+
if (!Object.prototype.propertyIsEnumerable.call(input2, key))
|
|
10995
10995
|
continue;
|
|
10996
10996
|
let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
10997
10997
|
if (keyResult instanceof Promise) {
|
|
@@ -11009,7 +11009,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
11009
11009
|
}
|
|
11010
11010
|
if (keyResult.issues.length) {
|
|
11011
11011
|
if (def.mode === "loose") {
|
|
11012
|
-
payload.value[key] =
|
|
11012
|
+
payload.value[key] = input2[key];
|
|
11013
11013
|
} else if (values) {
|
|
11014
11014
|
unrecognized = unrecognized ?? [];
|
|
11015
11015
|
unrecognized.push(key);
|
|
@@ -11028,7 +11028,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
11028
11028
|
const outKey = keyResult.value;
|
|
11029
11029
|
if (outKey === "__proto__")
|
|
11030
11030
|
continue;
|
|
11031
|
-
const result = def.valueType._zod.run({ value:
|
|
11031
|
+
const result = def.valueType._zod.run({ value: input2[key], issues: [] }, ctx);
|
|
11032
11032
|
if (result instanceof Promise) {
|
|
11033
11033
|
proms.push(result.then((result2) => {
|
|
11034
11034
|
if (result2.issues.length) {
|
|
@@ -11046,7 +11046,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
11046
11046
|
if (unrecognized && unrecognized.length > 0) {
|
|
11047
11047
|
payload.issues.push({
|
|
11048
11048
|
code: "unrecognized_keys",
|
|
11049
|
-
input:
|
|
11049
|
+
input: input2,
|
|
11050
11050
|
inst,
|
|
11051
11051
|
keys: unrecognized,
|
|
11052
11052
|
continue: true
|
|
@@ -11064,12 +11064,12 @@ var $ZodMap = /* @__PURE__ */ $constructor("$ZodMap", (inst, def) => {
|
|
|
11064
11064
|
const memo2 = globalConfig.memoizer;
|
|
11065
11065
|
memo2?.attach(inst);
|
|
11066
11066
|
inst._zod.parse = (payload, ctx) => {
|
|
11067
|
-
const
|
|
11068
|
-
if (!(
|
|
11067
|
+
const input2 = payload.value;
|
|
11068
|
+
if (!(input2 instanceof Map)) {
|
|
11069
11069
|
payload.issues.push({
|
|
11070
11070
|
expected: "map",
|
|
11071
11071
|
code: "invalid_type",
|
|
11072
|
-
input:
|
|
11072
|
+
input: input2,
|
|
11073
11073
|
inst
|
|
11074
11074
|
});
|
|
11075
11075
|
return payload;
|
|
@@ -11078,7 +11078,7 @@ var $ZodMap = /* @__PURE__ */ $constructor("$ZodMap", (inst, def) => {
|
|
|
11078
11078
|
payload.value = memo2 ? memo2.alloc(inst, payload, /* @__PURE__ */ new Map(), ctx) : /* @__PURE__ */ new Map();
|
|
11079
11079
|
const abortEarly = ctx?.abortEarly;
|
|
11080
11080
|
let seen = payload.issues.length;
|
|
11081
|
-
for (const [key, value] of
|
|
11081
|
+
for (const [key, value] of input2) {
|
|
11082
11082
|
if (abortEarly && payload.issues.length !== seen) {
|
|
11083
11083
|
if (aborted(payload, seen))
|
|
11084
11084
|
break;
|
|
@@ -11088,10 +11088,10 @@ var $ZodMap = /* @__PURE__ */ $constructor("$ZodMap", (inst, def) => {
|
|
|
11088
11088
|
const valueResult = def.valueType._zod.run({ value, issues: [] }, ctx);
|
|
11089
11089
|
if (keyResult instanceof Promise || valueResult instanceof Promise) {
|
|
11090
11090
|
proms.push(Promise.all([keyResult, valueResult]).then(([keyResult2, valueResult2]) => {
|
|
11091
|
-
handleMapResult(keyResult2, valueResult2, payload, key,
|
|
11091
|
+
handleMapResult(keyResult2, valueResult2, payload, key, input2, inst, ctx);
|
|
11092
11092
|
}));
|
|
11093
11093
|
} else {
|
|
11094
|
-
handleMapResult(keyResult, valueResult, payload, key,
|
|
11094
|
+
handleMapResult(keyResult, valueResult, payload, key, input2, inst, ctx);
|
|
11095
11095
|
}
|
|
11096
11096
|
}
|
|
11097
11097
|
if (proms.length)
|
|
@@ -11100,7 +11100,7 @@ var $ZodMap = /* @__PURE__ */ $constructor("$ZodMap", (inst, def) => {
|
|
|
11100
11100
|
};
|
|
11101
11101
|
capSize(inst, mapSize);
|
|
11102
11102
|
});
|
|
11103
|
-
function handleMapResult(keyResult, valueResult, final, key,
|
|
11103
|
+
function handleMapResult(keyResult, valueResult, final, key, input2, inst, ctx) {
|
|
11104
11104
|
if (keyResult.issues.length) {
|
|
11105
11105
|
if (propertyKeyTypes.has(typeof key)) {
|
|
11106
11106
|
final.issues.push(...prefixIssues(key, keyResult.issues));
|
|
@@ -11108,7 +11108,7 @@ function handleMapResult(keyResult, valueResult, final, key, input22, inst, ctx)
|
|
|
11108
11108
|
final.issues.push({
|
|
11109
11109
|
code: "invalid_key",
|
|
11110
11110
|
origin: "map",
|
|
11111
|
-
input:
|
|
11111
|
+
input: input2,
|
|
11112
11112
|
inst,
|
|
11113
11113
|
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
11114
11114
|
});
|
|
@@ -11121,7 +11121,7 @@ function handleMapResult(keyResult, valueResult, final, key, input22, inst, ctx)
|
|
|
11121
11121
|
final.issues.push({
|
|
11122
11122
|
origin: "map",
|
|
11123
11123
|
code: "invalid_element",
|
|
11124
|
-
input:
|
|
11124
|
+
input: input2,
|
|
11125
11125
|
inst,
|
|
11126
11126
|
key,
|
|
11127
11127
|
issues: valueResult.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
@@ -11135,10 +11135,10 @@ var $ZodSet = /* @__PURE__ */ $constructor("$ZodSet", (inst, def) => {
|
|
|
11135
11135
|
const memo2 = globalConfig.memoizer;
|
|
11136
11136
|
memo2?.attach(inst);
|
|
11137
11137
|
inst._zod.parse = (payload, ctx) => {
|
|
11138
|
-
const
|
|
11139
|
-
if (!(
|
|
11138
|
+
const input2 = payload.value;
|
|
11139
|
+
if (!(input2 instanceof Set)) {
|
|
11140
11140
|
payload.issues.push({
|
|
11141
|
-
input:
|
|
11141
|
+
input: input2,
|
|
11142
11142
|
inst,
|
|
11143
11143
|
expected: "set",
|
|
11144
11144
|
code: "invalid_type"
|
|
@@ -11149,7 +11149,7 @@ var $ZodSet = /* @__PURE__ */ $constructor("$ZodSet", (inst, def) => {
|
|
|
11149
11149
|
payload.value = memo2 ? memo2.alloc(inst, payload, /* @__PURE__ */ new Set(), ctx) : /* @__PURE__ */ new Set();
|
|
11150
11150
|
const abortEarly = ctx?.abortEarly;
|
|
11151
11151
|
let seen = payload.issues.length;
|
|
11152
|
-
for (const item of
|
|
11152
|
+
for (const item of input2) {
|
|
11153
11153
|
if (abortEarly && payload.issues.length !== seen) {
|
|
11154
11154
|
if (aborted(payload, seen))
|
|
11155
11155
|
break;
|
|
@@ -11183,14 +11183,14 @@ var $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
|
11183
11183
|
return new RegExp(patternValues.length ? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
|
|
11184
11184
|
});
|
|
11185
11185
|
inst._zod.parse = (payload, _ctx) => {
|
|
11186
|
-
const
|
|
11187
|
-
if (valuesSet.has(
|
|
11186
|
+
const input2 = payload.value;
|
|
11187
|
+
if (valuesSet.has(input2)) {
|
|
11188
11188
|
return payload;
|
|
11189
11189
|
}
|
|
11190
11190
|
payload.issues.push({
|
|
11191
11191
|
code: "invalid_value",
|
|
11192
11192
|
values,
|
|
11193
|
-
input:
|
|
11193
|
+
input: input2,
|
|
11194
11194
|
inst
|
|
11195
11195
|
});
|
|
11196
11196
|
return payload;
|
|
@@ -11205,14 +11205,14 @@ var $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
|
11205
11205
|
return new RegExp(vals.length ? `^(${vals.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$` : "^[^\\s\\S]$");
|
|
11206
11206
|
});
|
|
11207
11207
|
inst._zod.parse = (payload, _ctx) => {
|
|
11208
|
-
const
|
|
11209
|
-
if (values.has(
|
|
11208
|
+
const input2 = payload.value;
|
|
11209
|
+
if (values.has(input2)) {
|
|
11210
11210
|
return payload;
|
|
11211
11211
|
}
|
|
11212
11212
|
payload.issues.push({
|
|
11213
11213
|
code: "invalid_value",
|
|
11214
11214
|
values: def.values,
|
|
11215
|
-
input:
|
|
11215
|
+
input: input2,
|
|
11216
11216
|
inst
|
|
11217
11217
|
});
|
|
11218
11218
|
return payload;
|
|
@@ -11221,13 +11221,13 @@ var $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
|
11221
11221
|
var $ZodFile = /* @__PURE__ */ $constructor("$ZodFile", (inst, def) => {
|
|
11222
11222
|
$ZodType.init(inst, def);
|
|
11223
11223
|
inst._zod.parse = (payload, _ctx) => {
|
|
11224
|
-
const
|
|
11225
|
-
if (
|
|
11224
|
+
const input2 = payload.value;
|
|
11225
|
+
if (input2 instanceof File)
|
|
11226
11226
|
return payload;
|
|
11227
11227
|
payload.issues.push({
|
|
11228
11228
|
expected: "file",
|
|
11229
11229
|
code: "invalid_type",
|
|
11230
|
-
input:
|
|
11230
|
+
input: input2,
|
|
11231
11231
|
inst
|
|
11232
11232
|
});
|
|
11233
11233
|
return payload;
|
|
@@ -11243,8 +11243,8 @@ var $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) =>
|
|
|
11243
11243
|
}
|
|
11244
11244
|
const _out = def.transform(payload.value, payload);
|
|
11245
11245
|
if (ctx.async) {
|
|
11246
|
-
const
|
|
11247
|
-
return
|
|
11246
|
+
const output2 = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
11247
|
+
return output2.then((output3) => {
|
|
11248
11248
|
payload.value = output3;
|
|
11249
11249
|
return payload;
|
|
11250
11250
|
});
|
|
@@ -11695,12 +11695,12 @@ var $ZodFunction = /* @__PURE__ */ $constructor("$ZodFunction", (inst, def) => {
|
|
|
11695
11695
|
output: inst._def.output
|
|
11696
11696
|
});
|
|
11697
11697
|
};
|
|
11698
|
-
inst.output = (
|
|
11698
|
+
inst.output = (output2) => {
|
|
11699
11699
|
const F = inst.constructor;
|
|
11700
11700
|
return new F({
|
|
11701
11701
|
type: "function",
|
|
11702
11702
|
input: inst._def.input,
|
|
11703
|
-
output:
|
|
11703
|
+
output: output2
|
|
11704
11704
|
});
|
|
11705
11705
|
};
|
|
11706
11706
|
return inst;
|
|
@@ -11735,20 +11735,20 @@ var $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
|
11735
11735
|
return payload;
|
|
11736
11736
|
};
|
|
11737
11737
|
inst._zod.check = (payload) => {
|
|
11738
|
-
const
|
|
11739
|
-
const r = def.fn(
|
|
11738
|
+
const input2 = payload.value;
|
|
11739
|
+
const r = def.fn(input2);
|
|
11740
11740
|
if (r instanceof Promise) {
|
|
11741
|
-
return r.then((r2) => handleRefineResult(r2, payload,
|
|
11741
|
+
return r.then((r2) => handleRefineResult(r2, payload, input2, inst));
|
|
11742
11742
|
}
|
|
11743
|
-
handleRefineResult(r, payload,
|
|
11743
|
+
handleRefineResult(r, payload, input2, inst);
|
|
11744
11744
|
return;
|
|
11745
11745
|
};
|
|
11746
11746
|
});
|
|
11747
|
-
function handleRefineResult(result, payload,
|
|
11747
|
+
function handleRefineResult(result, payload, input2, inst) {
|
|
11748
11748
|
if (!result) {
|
|
11749
11749
|
const _iss = {
|
|
11750
11750
|
code: "custom",
|
|
11751
|
-
input:
|
|
11751
|
+
input: input2,
|
|
11752
11752
|
inst,
|
|
11753
11753
|
// incorporates params.error into issue reporting
|
|
11754
11754
|
path: [...inst._zod.def.path ?? []],
|
|
@@ -11978,8 +11978,8 @@ var memo = {
|
|
|
11978
11978
|
else
|
|
11979
11979
|
rechecked = true;
|
|
11980
11980
|
}
|
|
11981
|
-
const
|
|
11982
|
-
if (!isRef(
|
|
11981
|
+
const input2 = payload.value;
|
|
11982
|
+
if (!isRef(input2))
|
|
11983
11983
|
return base(payload, ctx);
|
|
11984
11984
|
let state = ctx[STATE];
|
|
11985
11985
|
if (!state) {
|
|
@@ -11994,7 +11994,7 @@ var memo = {
|
|
|
11994
11994
|
lastCtx = ctx;
|
|
11995
11995
|
lastBucket = bucket;
|
|
11996
11996
|
}
|
|
11997
|
-
const hit = bucket.get(
|
|
11997
|
+
const hit = bucket.get(input2);
|
|
11998
11998
|
if (hit) {
|
|
11999
11999
|
payload.value = hit.value;
|
|
12000
12000
|
if (hit.issues) {
|
|
@@ -13474,9 +13474,9 @@ var error12 = () => {
|
|
|
13474
13474
|
nan: "NaN"
|
|
13475
13475
|
// All other type names omitted - they fall back to raw values via ?? operator
|
|
13476
13476
|
};
|
|
13477
|
-
function getTypeName(type,
|
|
13478
|
-
if (type === "number" && typeof
|
|
13479
|
-
return String(
|
|
13477
|
+
function getTypeName(type, input2) {
|
|
13478
|
+
if (type === "number" && typeof input2 === "number" && !Number.isFinite(input2)) {
|
|
13479
|
+
return String(input2);
|
|
13480
13480
|
}
|
|
13481
13481
|
return TypeDictionary[type] ?? type;
|
|
13482
13482
|
}
|
|
@@ -21816,23 +21816,23 @@ function _overwrite(tx) {
|
|
|
21816
21816
|
}
|
|
21817
21817
|
// @__NO_SIDE_EFFECTS__
|
|
21818
21818
|
function _normalize(form) {
|
|
21819
|
-
return /* @__PURE__ */ _overwrite((
|
|
21819
|
+
return /* @__PURE__ */ _overwrite((input2) => input2.normalize(form));
|
|
21820
21820
|
}
|
|
21821
21821
|
// @__NO_SIDE_EFFECTS__
|
|
21822
21822
|
function _trim() {
|
|
21823
|
-
return /* @__PURE__ */ _overwrite((
|
|
21823
|
+
return /* @__PURE__ */ _overwrite((input2) => input2.trim());
|
|
21824
21824
|
}
|
|
21825
21825
|
// @__NO_SIDE_EFFECTS__
|
|
21826
21826
|
function _toLowerCase() {
|
|
21827
|
-
return /* @__PURE__ */ _overwrite((
|
|
21827
|
+
return /* @__PURE__ */ _overwrite((input2) => input2.toLowerCase());
|
|
21828
21828
|
}
|
|
21829
21829
|
// @__NO_SIDE_EFFECTS__
|
|
21830
21830
|
function _toUpperCase() {
|
|
21831
|
-
return /* @__PURE__ */ _overwrite((
|
|
21831
|
+
return /* @__PURE__ */ _overwrite((input2) => input2.toUpperCase());
|
|
21832
21832
|
}
|
|
21833
21833
|
// @__NO_SIDE_EFFECTS__
|
|
21834
21834
|
function _slugify() {
|
|
21835
|
-
return /* @__PURE__ */ _overwrite((
|
|
21835
|
+
return /* @__PURE__ */ _overwrite((input2) => slugify(input2));
|
|
21836
21836
|
}
|
|
21837
21837
|
// @__NO_SIDE_EFFECTS__
|
|
21838
21838
|
function _array(Class2, element, params) {
|
|
@@ -22138,8 +22138,8 @@ function _stringbool(Classes, _params) {
|
|
|
22138
22138
|
type: "pipe",
|
|
22139
22139
|
in: stringSchema,
|
|
22140
22140
|
out: booleanSchema,
|
|
22141
|
-
transform: ((
|
|
22142
|
-
let data =
|
|
22141
|
+
transform: ((input2, payload) => {
|
|
22142
|
+
let data = input2;
|
|
22143
22143
|
if (params.case !== "sensitive")
|
|
22144
22144
|
data = data.toLowerCase();
|
|
22145
22145
|
if (truthySet.has(data)) {
|
|
@@ -22158,8 +22158,8 @@ function _stringbool(Classes, _params) {
|
|
|
22158
22158
|
return {};
|
|
22159
22159
|
}
|
|
22160
22160
|
}),
|
|
22161
|
-
reverseTransform: ((
|
|
22162
|
-
if (
|
|
22161
|
+
reverseTransform: ((input2, _payload) => {
|
|
22162
|
+
if (input2 === true) {
|
|
22163
22163
|
return truthyArray[0] || "true";
|
|
22164
22164
|
} else {
|
|
22165
22165
|
return falsyArray[0] || "false";
|
|
@@ -22410,10 +22410,10 @@ function compactTypeUnion(schema) {
|
|
|
22410
22410
|
var FOLDABLE_KEYS = /* @__PURE__ */ new Set(["type", "properties", "required", "additionalProperties"]);
|
|
22411
22411
|
var UNION_KEYS = ["oneOf", "anyOf"];
|
|
22412
22412
|
function undeclaredConstraint(member) {
|
|
22413
|
-
const
|
|
22414
|
-
if (
|
|
22413
|
+
const extra2 = member.additionalProperties;
|
|
22414
|
+
if (extra2 === void 0 || extra2 === false || typeof extra2 !== "object" || extra2 === null)
|
|
22415
22415
|
return null;
|
|
22416
|
-
return Object.keys(
|
|
22416
|
+
return Object.keys(extra2).length ? extra2 : null;
|
|
22417
22417
|
}
|
|
22418
22418
|
function foldObjects(members2) {
|
|
22419
22419
|
const objects = [];
|
|
@@ -23428,9 +23428,9 @@ var allProcessors = {
|
|
|
23428
23428
|
optional: optionalProcessor,
|
|
23429
23429
|
lazy: lazyProcessor
|
|
23430
23430
|
};
|
|
23431
|
-
function toJSONSchema(
|
|
23432
|
-
if ("_idmap" in
|
|
23433
|
-
const registry2 =
|
|
23431
|
+
function toJSONSchema(input2, params) {
|
|
23432
|
+
if ("_idmap" in input2) {
|
|
23433
|
+
const registry2 = input2;
|
|
23434
23434
|
const ctx2 = initializeContext({ ...params, processors: allProcessors });
|
|
23435
23435
|
const defs = {};
|
|
23436
23436
|
for (const entry of registry2._idmap.entries()) {
|
|
@@ -23458,9 +23458,9 @@ function toJSONSchema(input22, params) {
|
|
|
23458
23458
|
return { schemas };
|
|
23459
23459
|
}
|
|
23460
23460
|
const ctx = initializeContext({ ...params, processors: allProcessors });
|
|
23461
|
-
processSchema(
|
|
23462
|
-
extractDefs(ctx,
|
|
23463
|
-
return finalize(ctx,
|
|
23461
|
+
processSchema(input2, ctx);
|
|
23462
|
+
extractDefs(ctx, input2);
|
|
23463
|
+
return finalize(ctx, input2);
|
|
23464
23464
|
}
|
|
23465
23465
|
var JSONSchemaGenerator = class {
|
|
23466
23466
|
/** @deprecated Access via ctx instead */
|
|
@@ -24963,14 +24963,14 @@ var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
|
24963
24963
|
payload.issues.push(util_exports.issue(_issue));
|
|
24964
24964
|
}
|
|
24965
24965
|
};
|
|
24966
|
-
const
|
|
24967
|
-
if (
|
|
24968
|
-
return
|
|
24966
|
+
const output2 = def.transform(payload.value, payload);
|
|
24967
|
+
if (output2 instanceof Promise) {
|
|
24968
|
+
return output2.then((output3) => {
|
|
24969
24969
|
payload.value = output3;
|
|
24970
24970
|
return payload;
|
|
24971
24971
|
});
|
|
24972
24972
|
}
|
|
24973
|
-
payload.value =
|
|
24973
|
+
payload.value = output2;
|
|
24974
24974
|
return payload;
|
|
24975
24975
|
};
|
|
24976
24976
|
});
|
|
@@ -25416,13 +25416,13 @@ function resolveRef(ref, ctx) {
|
|
|
25416
25416
|
if (!ref.startsWith("#")) {
|
|
25417
25417
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
25418
25418
|
}
|
|
25419
|
-
const
|
|
25420
|
-
if (
|
|
25419
|
+
const path5 = ref.slice(1).split("/").filter(Boolean);
|
|
25420
|
+
if (path5.length === 0) {
|
|
25421
25421
|
return ctx.rootSchema;
|
|
25422
25422
|
}
|
|
25423
25423
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
25424
|
-
if (
|
|
25425
|
-
const key =
|
|
25424
|
+
if (path5[0] === defsKey) {
|
|
25425
|
+
const key = path5[1] === void 0 ? void 0 : decodeJSONPointerSegment(path5[1]);
|
|
25426
25426
|
if (!key || !ctx.defs[key]) {
|
|
25427
25427
|
throw new Error(`Reference not found: ${ref}`);
|
|
25428
25428
|
}
|
|
@@ -27161,11 +27161,11 @@ var ToolHistoryProjection = class {
|
|
|
27161
27161
|
return this.history;
|
|
27162
27162
|
}
|
|
27163
27163
|
};
|
|
27164
|
-
function validateSessionHeader(id,
|
|
27165
|
-
if (
|
|
27164
|
+
function validateSessionHeader(id, input2) {
|
|
27165
|
+
if (input2 === null || typeof input2 !== "object" || Array.isArray(input2)) {
|
|
27166
27166
|
throw new Error("session header is not a plain JSON record");
|
|
27167
27167
|
}
|
|
27168
|
-
const record2 =
|
|
27168
|
+
const record2 = input2;
|
|
27169
27169
|
if (Object.hasOwn(record2, "seedLength")) {
|
|
27170
27170
|
throw new Error('session header has invalid field "seedLength"');
|
|
27171
27171
|
}
|
|
@@ -27201,18 +27201,18 @@ function validateSessionHeader(id, input22) {
|
|
|
27201
27201
|
}
|
|
27202
27202
|
return deepFreeze(record2);
|
|
27203
27203
|
}
|
|
27204
|
-
function validateRestoredSessionHeader(id,
|
|
27205
|
-
if (
|
|
27206
|
-
const prototype = Reflect.getPrototypeOf(
|
|
27204
|
+
function validateRestoredSessionHeader(id, input2) {
|
|
27205
|
+
if (input2 !== null && typeof input2 === "object" && !Array.isArray(input2)) {
|
|
27206
|
+
const prototype = Reflect.getPrototypeOf(input2);
|
|
27207
27207
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
27208
27208
|
throw new Error("session header is not a plain JSON record");
|
|
27209
27209
|
}
|
|
27210
27210
|
}
|
|
27211
|
-
return validateSessionHeader(id,
|
|
27211
|
+
return validateSessionHeader(id, input2);
|
|
27212
27212
|
}
|
|
27213
27213
|
function snapshotSessionHeader(id, source) {
|
|
27214
|
-
const
|
|
27215
|
-
const snapshot2 = snapshotJsonValue(
|
|
27214
|
+
const input2 = source === void 0 ? { version: SESSION_FORMAT_VERSION, id, createdAt: Date.now(), isSeeded: false } : source;
|
|
27215
|
+
const snapshot2 = snapshotJsonValue(input2);
|
|
27216
27216
|
if (snapshot2 === void 0) throw new Error("session header is not losslessly JSON-serializable");
|
|
27217
27217
|
return validateSessionHeader(id, snapshot2);
|
|
27218
27218
|
}
|
|
@@ -27693,9 +27693,9 @@ var Session = class _Session {
|
|
|
27693
27693
|
this.publicationEntry();
|
|
27694
27694
|
if (inputs.length === 0) return [];
|
|
27695
27695
|
const snapshots = Array.from({ length: inputs.length }, (_, index) => {
|
|
27696
|
-
const
|
|
27697
|
-
if (
|
|
27698
|
-
const [type, data, surfaceOpts] =
|
|
27696
|
+
const input2 = inputs.at(index);
|
|
27697
|
+
if (input2 === void 0) throw new Error(`session batch has an empty member at index ${index}`);
|
|
27698
|
+
const [type, data, surfaceOpts] = input2;
|
|
27699
27699
|
return snapshotAppend(type, data, surfaceOpts, `session batch member ${index} ("${type}")`);
|
|
27700
27700
|
});
|
|
27701
27701
|
const entry = this.publicationEntry();
|
|
@@ -27934,7 +27934,7 @@ var COMPACTION_INSTRUCTION = [
|
|
|
27934
27934
|
`- If the conversation already contains a ${SUMMARY_OPEN_TAG} block, it is a PRIOR checkpoint. Do not copy it forward verbatim: preserve still-true facts, drop stale ones, and merge newer information into a single consolidated summary under the same structure.`
|
|
27935
27935
|
].join("\n");
|
|
27936
27936
|
var CHECKPOINT_PREAMBLE = "This is an automatically generated checkpoint condensing an earlier span of the conversation to free up context. Treat the captured context as established background and build on it without restating it. Continue the task directly from the messages that follow, without acknowledging this checkpoint.";
|
|
27937
|
-
async function summarizeWithLlm(ctx, config2,
|
|
27937
|
+
async function summarizeWithLlm(ctx, config2, input2, agent, conversation, signal) {
|
|
27938
27938
|
const configured = config2.summarizationProvider.length === 0 ? void 0 : { provider: config2.summarizationProvider, model: config2.summarizationModel };
|
|
27939
27939
|
const target = configured ?? conversation;
|
|
27940
27940
|
if (target === void 0) {
|
|
@@ -27944,7 +27944,7 @@ async function summarizeWithLlm(ctx, config2, input22, agent, conversation, sign
|
|
|
27944
27944
|
}
|
|
27945
27945
|
const assembler = new BlockAssembler();
|
|
27946
27946
|
const messages = [
|
|
27947
|
-
...
|
|
27947
|
+
...input2.messages,
|
|
27948
27948
|
deepFreeze({
|
|
27949
27949
|
role: "user",
|
|
27950
27950
|
content: [{ type: "text", text: COMPACTION_INSTRUCTION }]
|
|
@@ -27955,7 +27955,7 @@ async function summarizeWithLlm(ctx, config2, input22, agent, conversation, sign
|
|
|
27955
27955
|
model: target.model,
|
|
27956
27956
|
messages,
|
|
27957
27957
|
toolHistory: agent.session.toolHistory(),
|
|
27958
|
-
...
|
|
27958
|
+
...input2.tools === void 0 ? {} : { tools: [...input2.tools] },
|
|
27959
27959
|
maxTokens: config2.maxTokens,
|
|
27960
27960
|
sessionId: agent.session.id,
|
|
27961
27961
|
purpose: "compaction",
|
|
@@ -28517,10 +28517,10 @@ var BasicCompactionEngine = class extends CompactionEngine {
|
|
|
28517
28517
|
* @param signal - optional cancellation forwarded to the adapter.
|
|
28518
28518
|
* @returns safe text summary blocks and the exact auxiliary call envelope and output.
|
|
28519
28519
|
*/
|
|
28520
|
-
async summarize(
|
|
28520
|
+
async summarize(input2, agent, signal) {
|
|
28521
28521
|
const target = conversationTarget(agent, (await this.answeredRoute).stateOf(agent.session));
|
|
28522
28522
|
const config2 = target === void 0 ? this.config : resolveTargetPolicy(this.config, target);
|
|
28523
|
-
return summarizeWithLlm(this.ctx, config2,
|
|
28523
|
+
return summarizeWithLlm(this.ctx, config2, input2, agent, target, signal);
|
|
28524
28524
|
}
|
|
28525
28525
|
/**
|
|
28526
28526
|
* Compact for replayed step-boundary pressure or one provider-confirmed context
|
|
@@ -28675,7 +28675,7 @@ var BasicCompactionEngine = class extends CompactionEngine {
|
|
|
28675
28675
|
regionDependencies() {
|
|
28676
28676
|
return {
|
|
28677
28677
|
meter: this.ctx.tokenMeter,
|
|
28678
|
-
summarize: (
|
|
28678
|
+
summarize: (input2, owner, abort) => this.summarize(input2, owner, abort),
|
|
28679
28679
|
recover: (error62, agent, sourceEventSeqs, signal) => this.ctx.waterfall("compaction/summary-error", {
|
|
28680
28680
|
session: agent.session,
|
|
28681
28681
|
sourceEventSeqs,
|
|
@@ -29669,13 +29669,14 @@ function dshMessageToPi(message, time3, toolNames, imageToPi) {
|
|
|
29669
29669
|
}
|
|
29670
29670
|
|
|
29671
29671
|
// src/dsh/sync.ts
|
|
29672
|
-
function createSyncState() {
|
|
29672
|
+
function createSyncState({ persistent = false } = {}) {
|
|
29673
29673
|
return {
|
|
29674
29674
|
turn: 1,
|
|
29675
29675
|
step: 0,
|
|
29676
29676
|
turnStarted: false,
|
|
29677
29677
|
systemSeq: void 0,
|
|
29678
29678
|
stepOpen: false,
|
|
29679
|
+
persistent,
|
|
29679
29680
|
seen: /* @__PURE__ */ new Set(),
|
|
29680
29681
|
toolCalls: /* @__PURE__ */ new Map(),
|
|
29681
29682
|
appended: 0
|
|
@@ -29698,6 +29699,11 @@ function ensureTurn(session, state) {
|
|
|
29698
29699
|
function appendSystem(session, state, entry, message, systemPrompt) {
|
|
29699
29700
|
if (state.systemSeq !== void 0) return;
|
|
29700
29701
|
ensureTurn(session, state);
|
|
29702
|
+
if (state.persistent && !state.stepOpen) {
|
|
29703
|
+
state.step += 1;
|
|
29704
|
+
append(session, "step/start", { turn: state.turn, step: state.step });
|
|
29705
|
+
state.stepOpen = true;
|
|
29706
|
+
}
|
|
29701
29707
|
let content = piContentToDsh(
|
|
29702
29708
|
systemPrompt && systemPrompt.trim().length > 0 ? systemPrompt : typeof message.content === "string" ? message.content : []
|
|
29703
29709
|
);
|
|
@@ -30295,19 +30301,19 @@ function buildSessionPath(entries, leafId, byId) {
|
|
|
30295
30301
|
if (!leaf) {
|
|
30296
30302
|
return [];
|
|
30297
30303
|
}
|
|
30298
|
-
const
|
|
30304
|
+
const path5 = [];
|
|
30299
30305
|
let current = leaf;
|
|
30300
30306
|
while (current) {
|
|
30301
|
-
|
|
30307
|
+
path5.push(current);
|
|
30302
30308
|
current = current.parentId ? index.get(current.parentId) : void 0;
|
|
30303
30309
|
}
|
|
30304
|
-
|
|
30305
|
-
return
|
|
30310
|
+
path5.reverse();
|
|
30311
|
+
return path5;
|
|
30306
30312
|
}
|
|
30307
|
-
function getSessionContextSettings(
|
|
30313
|
+
function getSessionContextSettings(path5) {
|
|
30308
30314
|
let thinkingLevel = "off";
|
|
30309
30315
|
let model = null;
|
|
30310
|
-
for (const entry of
|
|
30316
|
+
for (const entry of path5) {
|
|
30311
30317
|
if (entry.type === "thinking_level_change") {
|
|
30312
30318
|
thinkingLevel = entry.thinkingLevel;
|
|
30313
30319
|
} else if (entry.type === "model_change") {
|
|
@@ -30343,24 +30349,24 @@ function sessionEntryToContextMessages(entry) {
|
|
|
30343
30349
|
return [];
|
|
30344
30350
|
}
|
|
30345
30351
|
function buildContextEntries(entries, leafId, byId) {
|
|
30346
|
-
const
|
|
30352
|
+
const path5 = buildSessionPath(entries, leafId, byId);
|
|
30347
30353
|
let compaction = null;
|
|
30348
|
-
for (const entry of
|
|
30354
|
+
for (const entry of path5) {
|
|
30349
30355
|
if (entry.type === "compaction") {
|
|
30350
30356
|
compaction = entry;
|
|
30351
30357
|
}
|
|
30352
30358
|
}
|
|
30353
30359
|
if (!compaction) {
|
|
30354
|
-
return
|
|
30360
|
+
return path5;
|
|
30355
30361
|
}
|
|
30356
|
-
const compactionIdx =
|
|
30362
|
+
const compactionIdx = path5.findIndex((entry) => entry.id === compaction.id);
|
|
30357
30363
|
if (compactionIdx < 0) {
|
|
30358
|
-
return
|
|
30364
|
+
return path5;
|
|
30359
30365
|
}
|
|
30360
30366
|
const contextEntries = [compaction];
|
|
30361
30367
|
let foundFirstKept = false;
|
|
30362
30368
|
for (let i = 0; i < compactionIdx; i++) {
|
|
30363
|
-
const entry =
|
|
30369
|
+
const entry = path5[i];
|
|
30364
30370
|
if (entry.id === compaction.firstKeptEntryId) {
|
|
30365
30371
|
foundFirstKept = true;
|
|
30366
30372
|
}
|
|
@@ -30368,7 +30374,7 @@ function buildContextEntries(entries, leafId, byId) {
|
|
|
30368
30374
|
contextEntries.push(entry);
|
|
30369
30375
|
}
|
|
30370
30376
|
}
|
|
30371
|
-
contextEntries.push(...
|
|
30377
|
+
contextEntries.push(...path5.slice(compactionIdx + 1));
|
|
30372
30378
|
return contextEntries;
|
|
30373
30379
|
}
|
|
30374
30380
|
function projectContextEntry(entry, edit) {
|
|
@@ -30387,8 +30393,8 @@ function projectContextEntry(entry, edit) {
|
|
|
30387
30393
|
});
|
|
30388
30394
|
}
|
|
30389
30395
|
function buildSessionProjection(entries, leafId, byId) {
|
|
30390
|
-
const
|
|
30391
|
-
const { thinkingLevel, model } = getSessionContextSettings(
|
|
30396
|
+
const path5 = buildSessionPath(entries, leafId, byId);
|
|
30397
|
+
const { thinkingLevel, model } = getSessionContextSettings(path5);
|
|
30392
30398
|
const contextEntries = buildContextEntries(entries, leafId, byId);
|
|
30393
30399
|
const edits = /* @__PURE__ */ new Map();
|
|
30394
30400
|
for (const entry of contextEntries) {
|
|
@@ -30487,6 +30493,36 @@ function projectPiForDsh(entries) {
|
|
|
30487
30493
|
);
|
|
30488
30494
|
return convertToLlm(system ? [system, ...conversation] : conversation).map((message, index) => ({ type: "message", id: `projected-${index}`, message }));
|
|
30489
30495
|
}
|
|
30496
|
+
function settledTools(projected) {
|
|
30497
|
+
const result = [];
|
|
30498
|
+
const pending = /* @__PURE__ */ new Set();
|
|
30499
|
+
for (const [index, entry] of projected.entries()) {
|
|
30500
|
+
const { message } = entry;
|
|
30501
|
+
if (message.role === "toolResult") {
|
|
30502
|
+
if (pending.delete(message.toolCallId)) result.push(entry);
|
|
30503
|
+
continue;
|
|
30504
|
+
}
|
|
30505
|
+
pending.clear();
|
|
30506
|
+
if (message.role !== "assistant" || message.stopReason === "error" || message.stopReason === "aborted") {
|
|
30507
|
+
result.push(entry);
|
|
30508
|
+
continue;
|
|
30509
|
+
}
|
|
30510
|
+
const followingResults = /* @__PURE__ */ new Set();
|
|
30511
|
+
for (let next = index + 1; next < projected.length; next++) {
|
|
30512
|
+
const following = projected[next].message;
|
|
30513
|
+
if (following.role !== "toolResult") break;
|
|
30514
|
+
followingResults.add(following.toolCallId);
|
|
30515
|
+
}
|
|
30516
|
+
const content = message.content.filter((block) => {
|
|
30517
|
+
if (block.type !== "toolCall") return true;
|
|
30518
|
+
if (!block.id || !followingResults.delete(block.id)) return false;
|
|
30519
|
+
pending.add(block.id);
|
|
30520
|
+
return true;
|
|
30521
|
+
});
|
|
30522
|
+
if (content.length) result.push({ ...entry, message: { ...message, content } });
|
|
30523
|
+
}
|
|
30524
|
+
return result;
|
|
30525
|
+
}
|
|
30490
30526
|
function piHeader(header) {
|
|
30491
30527
|
return {
|
|
30492
30528
|
type: "session",
|
|
@@ -30497,21 +30533,21 @@ function piHeader(header) {
|
|
|
30497
30533
|
...header.parentSession ? { parentSession: header.parentSession } : {}
|
|
30498
30534
|
};
|
|
30499
30535
|
}
|
|
30500
|
-
function dshRowsFromPi(pi, entries, _file2, imageToDsh, projected = projectPiForDsh(entries)) {
|
|
30536
|
+
function dshRowsFromPi(pi, entries, _file2, imageToDsh, projected = projectPiForDsh(entries), destination) {
|
|
30501
30537
|
const header = {
|
|
30502
30538
|
type: "session",
|
|
30503
30539
|
version: SESSION_FORMAT_VERSION,
|
|
30504
|
-
id: pi.id,
|
|
30540
|
+
id: destination?.id ?? pi.id,
|
|
30505
30541
|
createdAt: Date.parse(pi.timestamp),
|
|
30506
|
-
cwd: pi.cwd,
|
|
30542
|
+
cwd: destination?.cwd ?? pi.cwd,
|
|
30507
30543
|
isSeeded: false,
|
|
30508
30544
|
delegationDepth: 0,
|
|
30509
|
-
|
|
30545
|
+
...!destination && pi.parentSession ? { parentSession: pi.parentSession } : {}
|
|
30510
30546
|
};
|
|
30511
30547
|
const session = Session.create(header.id, [], headerForSession(header));
|
|
30512
30548
|
appendPluginRecord(session, PI_HEADER, JSON.parse(JSON.stringify(pi)));
|
|
30513
|
-
const state = createSyncState();
|
|
30514
|
-
syncPiEntries(session, projected, state, { imageToDsh });
|
|
30549
|
+
const state = createSyncState({ persistent: true });
|
|
30550
|
+
syncPiEntries(session, settledTools(projected), state, { imageToDsh });
|
|
30515
30551
|
closeTurn(session, state);
|
|
30516
30552
|
for (const entry of entries) {
|
|
30517
30553
|
appendPluginRecord(session, PI_ARCHIVE, JSON.parse(JSON.stringify(entry)));
|
|
@@ -30521,9 +30557,9 @@ function dshRowsFromPi(pi, entries, _file2, imageToDsh, projected = projectPiFor
|
|
|
30521
30557
|
...session.snapshotEvents().map((event) => JSON.stringify(event))
|
|
30522
30558
|
].join("\n") + "\n";
|
|
30523
30559
|
}
|
|
30524
|
-
function writeDshFromPi(file2, header, entries, imageToDsh, projected) {
|
|
30560
|
+
function writeDshFromPi(file2, header, entries, imageToDsh, projected, destination) {
|
|
30525
30561
|
mkdirSync(path.dirname(file2), { recursive: true });
|
|
30526
|
-
const body = dshRowsFromPi(header, entries, file2, imageToDsh, projected);
|
|
30562
|
+
const body = dshRowsFromPi(header, entries, file2, imageToDsh, projected, destination);
|
|
30527
30563
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
30528
30564
|
writeFileSync(tmp, body);
|
|
30529
30565
|
renameSync(tmp, file2);
|
|
@@ -30584,39 +30620,40 @@ function messageEntry(id, parentId, time3, message) {
|
|
|
30584
30620
|
}
|
|
30585
30621
|
return { ...base, message: { ...message, timestamp: time3 } };
|
|
30586
30622
|
}
|
|
30587
|
-
async function piToDsh(
|
|
30588
|
-
if (path2.resolve(
|
|
30623
|
+
async function piToDsh(input2, output2) {
|
|
30624
|
+
if (path2.resolve(input2) === path2.resolve(output2))
|
|
30589
30625
|
throw new Error("Choose a separate output file for session conversion");
|
|
30590
|
-
const pi = await readPiSession(
|
|
30626
|
+
const pi = await readPiSession(input2);
|
|
30627
|
+
return { input: input2, output: output2, ...await exportPiSession(pi, output2) };
|
|
30628
|
+
}
|
|
30629
|
+
async function exportPiSession(pi, output2, options = {}) {
|
|
30591
30630
|
const projected = projectPiForDsh(pi.entries);
|
|
30592
|
-
const carrier = await openImageBridge();
|
|
30631
|
+
const carrier = await openImageBridge(options.dshHome);
|
|
30593
30632
|
try {
|
|
30594
30633
|
await carrier.images.prepare(
|
|
30595
30634
|
projected.map((entry) => entry.message)
|
|
30596
30635
|
);
|
|
30597
|
-
writeDshFromPi(
|
|
30636
|
+
writeDshFromPi(output2, pi.header, pi.entries, carrier.images.toDsh, projected, options.destination);
|
|
30598
30637
|
} finally {
|
|
30599
30638
|
await carrier.close();
|
|
30600
30639
|
}
|
|
30601
|
-
const parsed = await readDshFile(
|
|
30640
|
+
const parsed = await readDshFile(output2);
|
|
30602
30641
|
return {
|
|
30603
|
-
input: input3,
|
|
30604
|
-
output: output3,
|
|
30605
30642
|
messages: pi.entries.filter((entry) => entry.type === "message").length,
|
|
30606
30643
|
events: parsed.events.length
|
|
30607
30644
|
};
|
|
30608
30645
|
}
|
|
30609
|
-
async function dshToPi(
|
|
30610
|
-
if (path2.resolve(
|
|
30646
|
+
async function dshToPi(input2, output2) {
|
|
30647
|
+
if (path2.resolve(input2) === path2.resolve(output2))
|
|
30611
30648
|
throw new Error("Choose a separate output file for session conversion");
|
|
30612
|
-
const dsh = await readDshFile(
|
|
30613
|
-
if (!dsh) throw new Error(`${
|
|
30649
|
+
const dsh = await readDshFile(input2);
|
|
30650
|
+
if (!dsh) throw new Error(`${input2}: not a DSH session file`);
|
|
30614
30651
|
const archived = archivedPi(dsh.header, dsh.events);
|
|
30615
30652
|
if (archived) {
|
|
30616
|
-
await writePiSession(
|
|
30653
|
+
await writePiSession(output2, archived.header, archived.entries);
|
|
30617
30654
|
return {
|
|
30618
|
-
input:
|
|
30619
|
-
output:
|
|
30655
|
+
input: input2,
|
|
30656
|
+
output: output2,
|
|
30620
30657
|
messages: archived.entries.filter((entry) => entry.type === "message").length,
|
|
30621
30658
|
events: dsh.events.length
|
|
30622
30659
|
};
|
|
@@ -30648,35 +30685,531 @@ async function dshToPi(input3, output3) {
|
|
|
30648
30685
|
);
|
|
30649
30686
|
parentId = id;
|
|
30650
30687
|
}
|
|
30651
|
-
await writePiSession(
|
|
30652
|
-
return { input:
|
|
30688
|
+
await writePiSession(output2, header, entries);
|
|
30689
|
+
return { input: input2, output: output2, messages: messages.length, events: dsh.events.length };
|
|
30653
30690
|
}
|
|
30654
30691
|
|
|
30655
|
-
//
|
|
30692
|
+
// src/dsh/import.ts
|
|
30693
|
+
import { promises as fs3 } from "node:fs";
|
|
30694
|
+
import { homedir as homedir2, tmpdir } from "node:os";
|
|
30695
|
+
import * as path3 from "node:path";
|
|
30696
|
+
import { promisify } from "node:util";
|
|
30697
|
+
import { constants as constants2, zstdCompress } from "node:zlib";
|
|
30698
|
+
var compress = promisify(zstdCompress);
|
|
30699
|
+
var zstdOptions = { params: { [constants2.ZSTD_c_checksumFlag]: 1 } };
|
|
30700
|
+
function escapeSegment(value) {
|
|
30701
|
+
return value.replace(
|
|
30702
|
+
/[^A-Za-z0-9._-]/g,
|
|
30703
|
+
(char) => "~" + char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")
|
|
30704
|
+
);
|
|
30705
|
+
}
|
|
30706
|
+
var DestinationConflict = class extends Error {
|
|
30707
|
+
};
|
|
30708
|
+
async function nativeDestination(root, sessionId, cwd, plaintext) {
|
|
30709
|
+
try {
|
|
30710
|
+
if (!(await fs3.stat(root)).isDirectory()) throw new Error(`DSH session root is not a directory: ${root}`);
|
|
30711
|
+
} catch (error62) {
|
|
30712
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
30713
|
+
}
|
|
30714
|
+
const id = sessionId === "." || sessionId === ".." ? sessionId.replaceAll(".", "~002E") : escapeSegment(sessionId);
|
|
30715
|
+
const project = path3.join(root, projectKey(cwd));
|
|
30716
|
+
const destination = path3.join(project, id);
|
|
30717
|
+
const output2 = path3.join(destination, `session.v${DSH_FORMAT_VERSION}.jsonl${plaintext ? "" : ".zstd"}`);
|
|
30718
|
+
let conflict;
|
|
30719
|
+
for await (const existing of fs3.glob("*/*/session{,.v*}.jsonl{,.zstd}", { cwd: root })) {
|
|
30720
|
+
const filename = path3.basename(existing);
|
|
30721
|
+
if (!/^session(?:\.v[1-9]\d*)?\.jsonl(?:\.zstd)?$/.test(filename)) continue;
|
|
30722
|
+
if (filename.endsWith(".zstd") === plaintext)
|
|
30723
|
+
throw new Error(`DSH session root uses a different encoding: ${root}`);
|
|
30724
|
+
if (path3.basename(path3.dirname(existing)) === id) conflict = path3.join(root, existing);
|
|
30725
|
+
}
|
|
30726
|
+
try {
|
|
30727
|
+
await fs3.lstat(destination);
|
|
30728
|
+
conflict ??= destination;
|
|
30729
|
+
} catch (error62) {
|
|
30730
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
30731
|
+
}
|
|
30732
|
+
if (conflict)
|
|
30733
|
+
throw new DestinationConflict(`DSH session already exists: ${sessionId} (${conflict})`);
|
|
30734
|
+
return output2;
|
|
30735
|
+
}
|
|
30736
|
+
function projectKey(cwd) {
|
|
30737
|
+
const readable = escapeSegment(cwd.replace(/[/\\:]+/g, "-")).replace(/^-+/, "");
|
|
30738
|
+
return `--${(readable || "root").slice(0, 251)}--`;
|
|
30739
|
+
}
|
|
30740
|
+
async function importPiToDsh(input2, root = path3.join(process.env.DSH_HOME || path3.join(homedir2(), ".dsh"), "sessions"), plaintext = false, options = {}) {
|
|
30741
|
+
root = path3.resolve(root);
|
|
30742
|
+
const pi = options.pi ?? await readPiSession(input2);
|
|
30743
|
+
const sessionId = options.sessionId ?? pi.header.id;
|
|
30744
|
+
const cwd = options.cwd ?? pi.header.cwd;
|
|
30745
|
+
if (!sessionId || !cwd || !path3.isAbsolute(cwd))
|
|
30746
|
+
throw new Error("Import requires a native pi session with an ID and an absolute local project path");
|
|
30747
|
+
const output2 = await nativeDestination(root, sessionId, cwd, plaintext);
|
|
30748
|
+
const destination = path3.dirname(output2);
|
|
30749
|
+
const stage = await fs3.mkdtemp(path3.join(tmpdir(), "dcp-import-"));
|
|
30750
|
+
try {
|
|
30751
|
+
const raw = path3.join(stage, "session.jsonl");
|
|
30752
|
+
const report = await exportPiSession(pi, raw, {
|
|
30753
|
+
dshHome: options.dshHome,
|
|
30754
|
+
destination: options.sessionId !== void 0 || options.cwd !== void 0 ? { id: sessionId, cwd } : void 0
|
|
30755
|
+
});
|
|
30756
|
+
const bytes = await fs3.readFile(raw);
|
|
30757
|
+
const headerEnd = bytes.indexOf(10) + 1;
|
|
30758
|
+
const stored = plaintext ? bytes : Buffer.concat(await Promise.all([
|
|
30759
|
+
compress(bytes.subarray(0, headerEnd), zstdOptions),
|
|
30760
|
+
compress(bytes.subarray(headerEnd), zstdOptions)
|
|
30761
|
+
]));
|
|
30762
|
+
await fs3.mkdir(path3.dirname(destination), { recursive: true, mode: 448 });
|
|
30763
|
+
try {
|
|
30764
|
+
await fs3.mkdir(destination, { mode: 448 });
|
|
30765
|
+
} catch (error62) {
|
|
30766
|
+
if (error62.code === "EEXIST")
|
|
30767
|
+
throw new DestinationConflict(`DSH session already exists: ${sessionId} (${destination})`);
|
|
30768
|
+
throw error62;
|
|
30769
|
+
}
|
|
30770
|
+
const pending = path3.join(destination, ".dcp-import.tmp");
|
|
30771
|
+
try {
|
|
30772
|
+
await fs3.writeFile(pending, stored, { flag: "wx", mode: 384 });
|
|
30773
|
+
await fs3.rename(pending, output2);
|
|
30774
|
+
} catch (error62) {
|
|
30775
|
+
await fs3.rm(pending, { force: true });
|
|
30776
|
+
await fs3.rmdir(destination);
|
|
30777
|
+
throw error62;
|
|
30778
|
+
}
|
|
30779
|
+
return { ...report, input: input2, output: output2, sessionId, cwd };
|
|
30780
|
+
} finally {
|
|
30781
|
+
await fs3.rm(stage, { recursive: true, force: true });
|
|
30782
|
+
}
|
|
30783
|
+
}
|
|
30784
|
+
|
|
30785
|
+
// src/dsh/migration-cli.ts
|
|
30786
|
+
import { promises as fs6 } from "node:fs";
|
|
30787
|
+
import { createInterface } from "node:readline/promises";
|
|
30788
|
+
import { parseArgs } from "node:util";
|
|
30789
|
+
|
|
30790
|
+
// src/dsh/migration.ts
|
|
30791
|
+
import { createHash as createHash6, randomUUID as randomUUID5 } from "node:crypto";
|
|
30792
|
+
import { promises as fs4 } from "node:fs";
|
|
30793
|
+
import { homedir as homedir3, hostname as hostname3 } from "node:os";
|
|
30794
|
+
import path4 from "node:path";
|
|
30795
|
+
var migrationTargets = ["portable", "windows-desktop", "linux-desktop", "web", "tui"];
|
|
30796
|
+
var dshVersions = ["0.2.2-rc.1", "0.2.2-rc.5", "0.2.3-alpha.2"];
|
|
30797
|
+
function migrationEnvironment() {
|
|
30798
|
+
const piHome = path4.resolve(process.env.PI_CODING_AGENT_DIR ?? path4.join(homedir3(), ".pi", "agent"));
|
|
30799
|
+
const dshHome = path4.resolve(process.env.DSH_HOME ?? path4.join(homedir3(), ".dsh"));
|
|
30800
|
+
return { host: hostname3(), platform: process.platform, piHome, suggestedDshHome: dshHome, suggestedSessionRoot: path4.join(dshHome, "sessions") };
|
|
30801
|
+
}
|
|
30802
|
+
var MixedSession = class extends Error {
|
|
30803
|
+
};
|
|
30804
|
+
var piEntryTypes = /* @__PURE__ */ new Set([
|
|
30805
|
+
"message",
|
|
30806
|
+
"model_change",
|
|
30807
|
+
"thinking_level_change",
|
|
30808
|
+
"custom",
|
|
30809
|
+
"custom_message",
|
|
30810
|
+
"context_edit",
|
|
30811
|
+
"compaction",
|
|
30812
|
+
"branch_summary",
|
|
30813
|
+
"session_info",
|
|
30814
|
+
"label"
|
|
30815
|
+
]);
|
|
30816
|
+
function absolute(value, label) {
|
|
30817
|
+
if (!value || !path4.isAbsolute(value)) throw new Error(`${label} must be an absolute path on this host`);
|
|
30818
|
+
return path4.resolve(value);
|
|
30819
|
+
}
|
|
30820
|
+
async function directory(value, label) {
|
|
30821
|
+
const dir = absolute(value, label);
|
|
30822
|
+
if (!(await fs4.stat(dir)).isDirectory()) throw new Error(`${label} must be a directory: ${dir}`);
|
|
30823
|
+
return fs4.realpath(dir);
|
|
30824
|
+
}
|
|
30825
|
+
async function targetRoot(value) {
|
|
30826
|
+
const root = absolute(value, "Target session root");
|
|
30827
|
+
const remaining = [];
|
|
30828
|
+
for (let current = root; ; current = path4.dirname(current)) {
|
|
30829
|
+
try {
|
|
30830
|
+
return path4.join(await directory(current, "Target session root"), ...remaining);
|
|
30831
|
+
} catch (error62) {
|
|
30832
|
+
if (error62.code !== "ENOENT" || current === path4.dirname(current)) throw error62;
|
|
30833
|
+
remaining.unshift(path4.basename(current));
|
|
30834
|
+
}
|
|
30835
|
+
}
|
|
30836
|
+
}
|
|
30837
|
+
function digest3(value) {
|
|
30838
|
+
return createHash6("sha256").update(value).digest("hex");
|
|
30839
|
+
}
|
|
30840
|
+
async function findPiSources({ piHome, cwd, id }) {
|
|
30841
|
+
if (!cwd && !id) throw new Error("Pass --cwd or --id to select Pi sessions");
|
|
30842
|
+
const root = path4.join(absolute(piHome ?? process.env.PI_CODING_AGENT_DIR ?? path4.join(homedir3(), ".pi", "agent"), "Pi agent directory"), "sessions");
|
|
30843
|
+
const matches = [];
|
|
30844
|
+
for await (const file2 of fs4.glob("*/*.jsonl", { cwd: root })) {
|
|
30845
|
+
const input2 = path4.join(root, file2);
|
|
30846
|
+
const handle = await fs4.open(input2, "r");
|
|
30847
|
+
try {
|
|
30848
|
+
const buffer = Buffer.alloc(65536);
|
|
30849
|
+
const { bytesRead } = await handle.read(buffer);
|
|
30850
|
+
const header = JSON.parse(buffer.subarray(0, bytesRead).toString("utf8").split("\n", 1)[0]);
|
|
30851
|
+
if (header.type !== "session" || !header.id || id && header.id !== id || cwd && header.cwd !== cwd) continue;
|
|
30852
|
+
matches.push({ path: input2, id: header.id, cwd: header.cwd, timestamp: header.timestamp ?? header.createdAt, updated: (await handle.stat()).mtimeMs });
|
|
30853
|
+
} catch (error62) {
|
|
30854
|
+
if (!(error62 instanceof SyntaxError)) throw error62;
|
|
30855
|
+
} finally {
|
|
30856
|
+
await handle.close();
|
|
30857
|
+
}
|
|
30858
|
+
}
|
|
30859
|
+
return matches.sort((a, b) => b.updated - a.updated);
|
|
30860
|
+
}
|
|
30861
|
+
async function loadSource(input2, recover) {
|
|
30862
|
+
const bytes = await fs4.readFile(input2);
|
|
30863
|
+
const [header, ...entries] = bytes.toString("utf8").split("\n").filter((line) => line.trim()).map((line) => JSON.parse(line));
|
|
30864
|
+
if (header?.type !== "session" || typeof header.id !== "string" || !header.id)
|
|
30865
|
+
throw new Error("Source must have a session header with an ID");
|
|
30866
|
+
if (entries.some((row) => !row || typeof row !== "object" || Array.isArray(row)))
|
|
30867
|
+
throw new Error("Source contains an invalid session row");
|
|
30868
|
+
const mirrors = entries.filter((row) => "seq" in row);
|
|
30869
|
+
if (mirrors.length && !recover) throw new MixedSession(
|
|
30870
|
+
`Source contains ${mirrors.length} DSH event rows. Choose a native Pi file or explicitly approve --recover-pi-entries.`
|
|
30871
|
+
);
|
|
30872
|
+
const native = entries.filter((row) => !("seq" in row));
|
|
30873
|
+
if (!mirrors.length && header.version !== 3)
|
|
30874
|
+
throw new Error("This workflow requires a Pi v3 header or a supported mixed log");
|
|
30875
|
+
if (mirrors.length && (header.version !== 4 || !mirrors.every(
|
|
30876
|
+
(row) => Number.isSafeInteger(row.seq) && row.seq >= 0 && typeof row.type === "string" && "data" in row
|
|
30877
|
+
))) throw new Error("Mixed source has an unsupported header or event shapes");
|
|
30878
|
+
const ids = /* @__PURE__ */ new Set();
|
|
30879
|
+
for (const row of native) {
|
|
30880
|
+
const legacyRoot = mirrors.length && ids.size === 0 && row.type === "model_change" && row.parentId === void 0;
|
|
30881
|
+
if (!piEntryTypes.has(row.type) || typeof row.id !== "string" || !row.id || ids.has(row.id) || !legacyRoot && row.parentId !== null && !ids.has(row.parentId))
|
|
30882
|
+
throw new Error("Source has ambiguous Pi entries or parent links");
|
|
30883
|
+
ids.add(row.id);
|
|
30884
|
+
}
|
|
30885
|
+
if (!native.some((row) => row.type === "message")) throw new Error("Source has no native Pi messages");
|
|
30886
|
+
const timestamp = header.timestamp ?? (mirrors.length && Number.isFinite(header.createdAt) ? new Date(header.createdAt).toISOString() : void 0);
|
|
30887
|
+
if (typeof timestamp !== "string" || !Number.isFinite(Date.parse(timestamp))) throw new Error("Source has no valid creation time");
|
|
30888
|
+
const pi = {
|
|
30889
|
+
header: mirrors.length ? { type: "session", version: 3, id: header.id, timestamp, cwd: header.cwd } : header,
|
|
30890
|
+
entries: native
|
|
30891
|
+
};
|
|
30892
|
+
return { pi, sha256: digest3(bytes), mirrorRows: mirrors.length };
|
|
30893
|
+
}
|
|
30894
|
+
async function portableOutput(dir, sessionId) {
|
|
30895
|
+
const folder = path4.join(dir, "dcp-" + escapeSegment(sessionId));
|
|
30896
|
+
try {
|
|
30897
|
+
await fs4.lstat(folder);
|
|
30898
|
+
throw new DestinationConflict(`Export directory already exists: ${folder}`);
|
|
30899
|
+
} catch (error62) {
|
|
30900
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
30901
|
+
}
|
|
30902
|
+
return path4.join(folder, "session.dsh.jsonl");
|
|
30903
|
+
}
|
|
30904
|
+
async function prepare(options, copyId) {
|
|
30905
|
+
const { target, dshVersion, profile, encoding } = options;
|
|
30906
|
+
if (!migrationTargets.includes(target)) throw new Error("Choose an explicit migration target");
|
|
30907
|
+
if (target === "windows-desktop" && process.platform !== "win32" || target === "linux-desktop" && process.platform !== "linux")
|
|
30908
|
+
throw new Error(`Run this migration on the native host for ${target}`);
|
|
30909
|
+
const source = await fs4.realpath(absolute(options.source, "Pi source"));
|
|
30910
|
+
const { pi, sha256, mirrorRows } = await loadSource(source, options.recoverPiEntries === true);
|
|
30911
|
+
const portable = target === "portable";
|
|
30912
|
+
if (portable && [dshVersion, profile, encoding, options.dshHome, options.sessionRoot, options.workspace].some(Boolean))
|
|
30913
|
+
throw new Error("A portable export only takes --export-dir for its target");
|
|
30914
|
+
if (!portable && options.exportDir) throw new Error("Use --session-root for a direct import");
|
|
30915
|
+
if (!portable && (!dshVersion || !dshVersions.includes(dshVersion)))
|
|
30916
|
+
throw new Error(`Confirm an exact tested DSH backend version: ${dshVersions.join(", ")}`);
|
|
30917
|
+
if (!portable && (!profile?.trim() || encoding !== "zstd" && encoding !== "plain"))
|
|
30918
|
+
throw new Error("Confirm the target profile or instance and its encoding (zstd or plain)");
|
|
30919
|
+
if (options.onConflict && options.onConflict !== "stop" && options.onConflict !== "copy")
|
|
30920
|
+
throw new Error("Choose a conflict policy of stop or copy");
|
|
30921
|
+
const cwd = portable ? pi.header.cwd : await directory(options.workspace, "Target workspace");
|
|
30922
|
+
if (typeof cwd !== "string" || !cwd) throw new Error("Source does not name a project directory");
|
|
30923
|
+
const dshHome = portable ? void 0 : await directory(options.dshHome, "Target DSH home");
|
|
30924
|
+
const sessionRoot = portable ? void 0 : await targetRoot(options.sessionRoot);
|
|
30925
|
+
const exportDir = portable ? await directory(options.exportDir, "Export directory") : void 0;
|
|
30926
|
+
const resolveOutput = (id) => portable ? portableOutput(exportDir, id) : nativeDestination(sessionRoot, id, cwd, encoding === "plain");
|
|
30927
|
+
let sessionId = pi.header.id;
|
|
30928
|
+
let output2;
|
|
30929
|
+
let conflict;
|
|
30930
|
+
try {
|
|
30931
|
+
output2 = await resolveOutput(sessionId);
|
|
30932
|
+
} catch (error62) {
|
|
30933
|
+
if (!(error62 instanceof DestinationConflict) || options.onConflict !== "copy") throw error62;
|
|
30934
|
+
conflict = error62.message;
|
|
30935
|
+
sessionId = copyId ?? randomUUID5();
|
|
30936
|
+
if (!/^[0-9a-f-]{36}$/i.test(sessionId) || sessionId === pi.header.id)
|
|
30937
|
+
throw new Error("Invalid new session ID in the migration plan");
|
|
30938
|
+
output2 = await resolveOutput(sessionId);
|
|
30939
|
+
}
|
|
30940
|
+
const plan = {
|
|
30941
|
+
host: hostname3(),
|
|
30942
|
+
platform: process.platform,
|
|
30943
|
+
source,
|
|
30944
|
+
sourceSessionId: pi.header.id,
|
|
30945
|
+
sourceCwd: pi.header.cwd,
|
|
30946
|
+
sha256,
|
|
30947
|
+
sourceMessages: pi.entries.filter((row) => row.type === "message").length,
|
|
30948
|
+
mirrorRows,
|
|
30949
|
+
target,
|
|
30950
|
+
dshVersion,
|
|
30951
|
+
profile,
|
|
30952
|
+
encoding,
|
|
30953
|
+
dshHome,
|
|
30954
|
+
sessionRoot,
|
|
30955
|
+
exportDir,
|
|
30956
|
+
sessionId,
|
|
30957
|
+
cwd,
|
|
30958
|
+
output: output2,
|
|
30959
|
+
conflict,
|
|
30960
|
+
attachmentHome: dshHome ?? path4.dirname(output2)
|
|
30961
|
+
};
|
|
30962
|
+
return { pi, plan };
|
|
30963
|
+
}
|
|
30964
|
+
async function planMigration(options) {
|
|
30965
|
+
const { plan } = await prepare(options);
|
|
30966
|
+
return { schema: 1, options, ...plan, confirmation: digest3(JSON.stringify(plan)).slice(0, 12) };
|
|
30967
|
+
}
|
|
30968
|
+
async function applyMigration(saved, confirmation) {
|
|
30969
|
+
if (saved.schema !== 1 || !confirmation || confirmation !== saved.confirmation)
|
|
30970
|
+
throw new Error("Apply requires the confirmation code from the approved plan");
|
|
30971
|
+
const { plan, pi } = await prepare(saved.options, saved.sessionId);
|
|
30972
|
+
if (digest3(JSON.stringify(plan)).slice(0, 12) !== confirmation)
|
|
30973
|
+
throw new Error("The source, target, or conflict changed. Generate and confirm a new plan.");
|
|
30974
|
+
const { source, sessionId, cwd, output: output2, dshHome, sessionRoot, encoding } = plan;
|
|
30975
|
+
const destination = { id: sessionId, cwd };
|
|
30976
|
+
if (sessionRoot && dshHome) {
|
|
30977
|
+
const report = await importPiToDsh(source, sessionRoot, encoding === "plain", { pi, sessionId, cwd, dshHome });
|
|
30978
|
+
return { ...report, target: plan.target, attachmentHome: plan.attachmentHome, status: "written", verification: "open-and-check-target-history" };
|
|
30979
|
+
}
|
|
30980
|
+
const folder = path4.dirname(output2);
|
|
30981
|
+
await fs4.mkdir(folder, { mode: 448 });
|
|
30982
|
+
try {
|
|
30983
|
+
const report = await exportPiSession(pi, output2, { dshHome: folder, destination });
|
|
30984
|
+
return { ...report, output: output2, sessionId, cwd, target: plan.target, attachmentHome: folder, status: "exported" };
|
|
30985
|
+
} catch (error62) {
|
|
30986
|
+
await fs4.rm(folder, { recursive: true, force: true });
|
|
30987
|
+
throw error62;
|
|
30988
|
+
}
|
|
30989
|
+
}
|
|
30990
|
+
|
|
30991
|
+
// src/dsh/migration-web.ts
|
|
30992
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
30993
|
+
import { promises as fs5 } from "node:fs";
|
|
30994
|
+
async function verifyWebSession(urlFile, sessionId, events) {
|
|
30995
|
+
if (!sessionId || !Number.isSafeInteger(events) || events < 1)
|
|
30996
|
+
throw new Error("Pass the sessionId and event count from the migration receipt");
|
|
30997
|
+
let url2;
|
|
30998
|
+
try {
|
|
30999
|
+
url2 = new URL((await fs5.readFile(urlFile, "utf8")).trim());
|
|
31000
|
+
} catch {
|
|
31001
|
+
throw new Error("The URL file must contain one DSH Web launch URL");
|
|
31002
|
+
}
|
|
31003
|
+
if (!["http:", "https:"].includes(url2.protocol) || url2.username || url2.password || !url2.searchParams.has("token"))
|
|
31004
|
+
throw new Error("The URL file must contain one DSH Web launch URL");
|
|
31005
|
+
const send = async (target, options) => {
|
|
31006
|
+
try {
|
|
31007
|
+
return await fetch(target, { ...options, redirect: "manual", signal: AbortSignal.timeout(2e4) });
|
|
31008
|
+
} catch {
|
|
31009
|
+
throw new Error("The confirmed DSH Web instance is unreachable");
|
|
31010
|
+
}
|
|
31011
|
+
};
|
|
31012
|
+
const auth = await send(url2, {});
|
|
31013
|
+
const cookie = auth.headers.get("set-cookie")?.split(";", 1)[0];
|
|
31014
|
+
if (!cookie || auth.status !== 303) throw new Error(`DSH Web authentication failed (HTTP ${auth.status})`);
|
|
31015
|
+
const headers = { "content-type": "application/json", cookie };
|
|
31016
|
+
async function rpc(method, args) {
|
|
31017
|
+
const response = await send(new URL(`./api/${method}`, url2), {
|
|
31018
|
+
method: "POST",
|
|
31019
|
+
headers,
|
|
31020
|
+
body: JSON.stringify({ type: "client-request", rpcId: randomUUID6(), method, payload: { args } })
|
|
31021
|
+
});
|
|
31022
|
+
const body = await response.json().catch(() => void 0);
|
|
31023
|
+
if (!body?.result?.ok) throw new Error(`DSH Web ${method} failed (HTTP ${response.status}, ${body?.result?.error?.code ?? "no result"})`);
|
|
31024
|
+
return body.result.value;
|
|
31025
|
+
}
|
|
31026
|
+
const list = await rpc("session/list", { _request: {} });
|
|
31027
|
+
if (!Array.isArray(list?.items) || !list.items.some((item) => item.sessionId === sessionId))
|
|
31028
|
+
throw new Error("The imported ID is missing from the target DSH session list");
|
|
31029
|
+
await rpc("session/page", {
|
|
31030
|
+
request: { address: { kind: "session", sessionId }, throughSeq: events - 1, maxMessages: 3 }
|
|
31031
|
+
});
|
|
31032
|
+
return { sessionId, origin: url2.origin, status: "verified", checks: ["session/list", "session/page"] };
|
|
31033
|
+
}
|
|
31034
|
+
|
|
31035
|
+
// src/dsh/migration-cli.ts
|
|
30656
31036
|
var help = `Usage:
|
|
31037
|
+
dcp-session migrate [<absolute-pi-session>] Interactive terminal
|
|
31038
|
+
dcp-session migrate environment
|
|
31039
|
+
dcp-session migrate sources [--pi-home <dir>] [--id <id>] [--cwd <dir>]
|
|
31040
|
+
dcp-session migrate plan --source <file> --target <target> --plan-file <file> [options]
|
|
31041
|
+
dcp-session migrate apply --plan-file <file> --confirm <code>
|
|
31042
|
+
dcp-session migrate verify-web --url-file <file> --session-id <id> --events <count>
|
|
31043
|
+
|
|
31044
|
+
Targets: ${migrationTargets.join(", ")}
|
|
31045
|
+
Portable target: --export-dir <directory>
|
|
31046
|
+
Direct targets: --profile <name> --dsh-version <version> --dsh-home <directory>
|
|
31047
|
+
--session-root <directory> --workspace <directory> --encoding <zstd|plain>
|
|
31048
|
+
Conflict options: --on-conflict <stop|copy>, --recover-pi-entries
|
|
31049
|
+
Tested DSH versions: ${dshVersions.join(", ")}
|
|
31050
|
+
Plans preview the exact host and paths. Apply rechecks the source and destination before writing.`;
|
|
31051
|
+
var print = (value) => console.log(JSON.stringify(value, null, 2));
|
|
31052
|
+
async function interactive(source) {
|
|
31053
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
31054
|
+
throw new Error("Interactive mode needs a terminal. Use migrate plan and apply from an agent.");
|
|
31055
|
+
const reader = createInterface({ input: process.stdin, output: process.stdout });
|
|
31056
|
+
const ask = async (prompt) => (await reader.question(prompt + " ")).trim();
|
|
31057
|
+
try {
|
|
31058
|
+
const target = await ask(`Target (${migrationTargets.join(", ")}):`);
|
|
31059
|
+
if (!migrationTargets.includes(target)) throw new Error("Choose a listed target");
|
|
31060
|
+
const options = { source: source ?? await ask("Absolute Pi session path:"), target };
|
|
31061
|
+
if (target === "portable") options.exportDir = await ask("Absolute export directory:");
|
|
31062
|
+
else {
|
|
31063
|
+
options.profile = await ask("Target profile or instance name:");
|
|
31064
|
+
options.dshVersion = await ask(`Target DSH backend version (${dshVersions.join(", ")}):`);
|
|
31065
|
+
options.dshHome = await ask("Absolute target DSH home (attachment store):");
|
|
31066
|
+
options.sessionRoot = await ask("Absolute target session directory:");
|
|
31067
|
+
options.workspace = await ask("Absolute target workspace:");
|
|
31068
|
+
options.encoding = await ask("Target session encoding (zstd or plain):");
|
|
31069
|
+
}
|
|
31070
|
+
let plan;
|
|
31071
|
+
for (; ; ) {
|
|
31072
|
+
try {
|
|
31073
|
+
plan = await planMigration(options);
|
|
31074
|
+
break;
|
|
31075
|
+
} catch (error62) {
|
|
31076
|
+
if (error62 instanceof MixedSession && !options.recoverPiEntries) {
|
|
31077
|
+
console.log(error62.message);
|
|
31078
|
+
if (await ask("Use only the native Pi entries and preserve the source file? Type recover or press Enter to cancel.") !== "recover") return;
|
|
31079
|
+
options.recoverPiEntries = true;
|
|
31080
|
+
} else if (error62 instanceof DestinationConflict && options.onConflict !== "copy") {
|
|
31081
|
+
console.log(error62.message);
|
|
31082
|
+
if (await ask("Keep the existing session and use a new ID? Type copy or press Enter to cancel.") !== "copy") return;
|
|
31083
|
+
options.onConflict = "copy";
|
|
31084
|
+
} else throw error62;
|
|
31085
|
+
}
|
|
31086
|
+
}
|
|
31087
|
+
print(plan);
|
|
31088
|
+
const code = await ask("Review the destination above and type the confirmation code to write:");
|
|
31089
|
+
if (!code) return;
|
|
31090
|
+
print(await applyMigration(plan, code));
|
|
31091
|
+
} finally {
|
|
31092
|
+
reader.close();
|
|
31093
|
+
}
|
|
31094
|
+
}
|
|
31095
|
+
async function runMigration(args) {
|
|
31096
|
+
const [mode, ...rest] = args;
|
|
31097
|
+
switch (mode) {
|
|
31098
|
+
case "--help":
|
|
31099
|
+
case "-h":
|
|
31100
|
+
console.log(help);
|
|
31101
|
+
return;
|
|
31102
|
+
case "environment":
|
|
31103
|
+
if (rest.length) throw new Error("migrate environment takes no arguments");
|
|
31104
|
+
print(migrationEnvironment());
|
|
31105
|
+
return;
|
|
31106
|
+
case "sources": {
|
|
31107
|
+
const { values } = parseArgs({ args: rest, options: {
|
|
31108
|
+
"pi-home": { type: "string" },
|
|
31109
|
+
id: { type: "string" },
|
|
31110
|
+
cwd: { type: "string" }
|
|
31111
|
+
} });
|
|
31112
|
+
print(await findPiSources({ piHome: values["pi-home"], id: values.id, cwd: values.cwd }));
|
|
31113
|
+
return;
|
|
31114
|
+
}
|
|
31115
|
+
case "plan": {
|
|
31116
|
+
const { values: v } = parseArgs({ args: rest, options: {
|
|
31117
|
+
source: { type: "string" },
|
|
31118
|
+
target: { type: "string" },
|
|
31119
|
+
"plan-file": { type: "string" },
|
|
31120
|
+
"export-dir": { type: "string" },
|
|
31121
|
+
profile: { type: "string" },
|
|
31122
|
+
"dsh-version": { type: "string" },
|
|
31123
|
+
"dsh-home": { type: "string" },
|
|
31124
|
+
"session-root": { type: "string" },
|
|
31125
|
+
workspace: { type: "string" },
|
|
31126
|
+
encoding: { type: "string" },
|
|
31127
|
+
"on-conflict": { type: "string" },
|
|
31128
|
+
"recover-pi-entries": { type: "boolean" }
|
|
31129
|
+
} });
|
|
31130
|
+
if (!v.source || !v.target || !v["plan-file"]) throw new Error("Pass --source, --target and --plan-file");
|
|
31131
|
+
const plan = await planMigration({
|
|
31132
|
+
source: v.source,
|
|
31133
|
+
target: v.target,
|
|
31134
|
+
workspace: v.workspace,
|
|
31135
|
+
profile: v.profile,
|
|
31136
|
+
dshVersion: v["dsh-version"],
|
|
31137
|
+
dshHome: v["dsh-home"],
|
|
31138
|
+
sessionRoot: v["session-root"],
|
|
31139
|
+
exportDir: v["export-dir"],
|
|
31140
|
+
encoding: v.encoding,
|
|
31141
|
+
onConflict: v["on-conflict"],
|
|
31142
|
+
recoverPiEntries: v["recover-pi-entries"]
|
|
31143
|
+
});
|
|
31144
|
+
await fs6.writeFile(v["plan-file"], JSON.stringify(plan, null, 2) + "\n", { mode: 384, flag: "wx" });
|
|
31145
|
+
print(plan);
|
|
31146
|
+
return;
|
|
31147
|
+
}
|
|
31148
|
+
case "apply": {
|
|
31149
|
+
const { values } = parseArgs({ args: rest, options: {
|
|
31150
|
+
"plan-file": { type: "string" },
|
|
31151
|
+
confirm: { type: "string" }
|
|
31152
|
+
} });
|
|
31153
|
+
if (!values["plan-file"] || !values.confirm) throw new Error("Pass --plan-file and the approved --confirm code");
|
|
31154
|
+
print(await applyMigration(JSON.parse(await fs6.readFile(values["plan-file"], "utf8")), values.confirm));
|
|
31155
|
+
return;
|
|
31156
|
+
}
|
|
31157
|
+
case "verify-web": {
|
|
31158
|
+
const { values } = parseArgs({ args: rest, options: {
|
|
31159
|
+
"url-file": { type: "string" },
|
|
31160
|
+
"session-id": { type: "string" },
|
|
31161
|
+
events: { type: "string" }
|
|
31162
|
+
} });
|
|
31163
|
+
if (!values["url-file"] || !values["session-id"] || !values.events)
|
|
31164
|
+
throw new Error("Pass --url-file, --session-id, and --events from the migration receipt");
|
|
31165
|
+
print(await verifyWebSession(values["url-file"], values["session-id"], Number(values.events)));
|
|
31166
|
+
return;
|
|
31167
|
+
}
|
|
31168
|
+
default:
|
|
31169
|
+
if (rest.length || mode?.startsWith("--")) throw new Error(help);
|
|
31170
|
+
await interactive(mode);
|
|
31171
|
+
}
|
|
31172
|
+
}
|
|
31173
|
+
|
|
31174
|
+
// bin/dcp-session.ts
|
|
31175
|
+
var help2 = `Usage:
|
|
31176
|
+
dcp-session migrate --help
|
|
30657
31177
|
dcp-session pi2dsh <pi-session.jsonl> <out.dsh.jsonl>
|
|
31178
|
+
dcp-session pi2dsh-import <pi-session.jsonl> [dsh-session-root] [--plain]
|
|
30658
31179
|
dcp-session dsh2pi <dsh-session.jsonl> <out.pi.jsonl>
|
|
30659
31180
|
dcp-session --help
|
|
30660
31181
|
|
|
30661
31182
|
pi2dsh exports the active pi context and archives the original pi entries.
|
|
31183
|
+
pi2dsh-import installs that export as a new DSH session. The default root is
|
|
31184
|
+
$DSH_HOME/sessions with Zstandard encoding. Use --plain only for a DSH profile
|
|
31185
|
+
configured with plaintext session storage.
|
|
30662
31186
|
dsh2pi restores those entries from an unchanged export. For a native or
|
|
30663
31187
|
continued DSH session it imports the active DSH context.
|
|
30664
31188
|
|
|
30665
31189
|
Use a separate output path. DSH input may be .jsonl or .zstd (requires zstd).
|
|
30666
31190
|
Image references are resolved under DSH_HOME (default ~/.dsh).`;
|
|
30667
|
-
|
|
30668
|
-
if (command === "--help" || command === "-h") {
|
|
30669
|
-
|
|
30670
|
-
|
|
30671
|
-
}
|
|
30672
|
-
if (command
|
|
30673
|
-
|
|
30674
|
-
|
|
31191
|
+
async function main([command, input2, ...args]) {
|
|
31192
|
+
if (command === "--help" || command === "-h") {
|
|
31193
|
+
console.log(help2);
|
|
31194
|
+
return;
|
|
31195
|
+
}
|
|
31196
|
+
if (command === "migrate") return runMigration(input2 === void 0 ? [] : [input2, ...args]);
|
|
31197
|
+
const importing = command === "pi2dsh-import";
|
|
31198
|
+
const plain = importing && args.at(-1) === "--plain";
|
|
31199
|
+
if (plain) args.pop();
|
|
31200
|
+
const [output2, ...extra2] = args;
|
|
31201
|
+
const valid = importing ? !output2?.startsWith("--") : (command === "pi2dsh" || command === "dsh2pi") && output2;
|
|
31202
|
+
if (!input2 || !valid || extra2.length) {
|
|
31203
|
+
console.error(help2);
|
|
31204
|
+
process.exitCode = 2;
|
|
31205
|
+
return;
|
|
31206
|
+
}
|
|
31207
|
+
const report = importing ? await importPiToDsh(input2, output2, plain) : command === "pi2dsh" ? await piToDsh(input2, output2) : await dshToPi(input2, output2);
|
|
31208
|
+
console.log(JSON.stringify(report, null, 2));
|
|
30675
31209
|
}
|
|
30676
31210
|
try {
|
|
30677
|
-
|
|
30678
|
-
console.log(JSON.stringify(report, null, 2));
|
|
31211
|
+
await main(process.argv.slice(2));
|
|
30679
31212
|
} catch (error62) {
|
|
30680
31213
|
console.error(error62 instanceof Error ? error62.message : String(error62));
|
|
30681
|
-
process.
|
|
31214
|
+
process.exitCode = 1;
|
|
30682
31215
|
}
|