@character-foundry/character-foundry 0.4.2-dev.1765997746 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charx.cjs +36 -15
- package/dist/charx.cjs.map +1 -1
- package/dist/charx.d.cts +9 -18
- package/dist/charx.d.ts +9 -18
- package/dist/charx.js +36 -15
- package/dist/charx.js.map +1 -1
- package/dist/exporter.cjs +38 -34
- package/dist/exporter.cjs.map +1 -1
- package/dist/exporter.d.cts +9 -18
- package/dist/exporter.d.ts +9 -18
- package/dist/exporter.js +38 -34
- package/dist/exporter.js.map +1 -1
- package/dist/federation.cjs +36 -104
- package/dist/federation.cjs.map +1 -1
- package/dist/federation.d.cts +9 -53
- package/dist/federation.d.ts +9 -53
- package/dist/federation.js +36 -104
- package/dist/federation.js.map +1 -1
- package/dist/index.cjs +38 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -42
- package/dist/index.d.ts +21 -42
- package/dist/index.js +38 -34
- package/dist/index.js.map +1 -1
- package/dist/loader.cjs +15 -101
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.d.cts +14 -42
- package/dist/loader.d.ts +14 -42
- package/dist/loader.js +15 -101
- package/dist/loader.js.map +1 -1
- package/dist/lorebook.d.cts +17 -34
- package/dist/lorebook.d.ts +17 -34
- package/dist/normalizer.cjs +2 -2
- package/dist/normalizer.cjs.map +1 -1
- package/dist/normalizer.d.cts +30 -60
- package/dist/normalizer.d.ts +30 -60
- package/dist/normalizer.js +2 -2
- package/dist/normalizer.js.map +1 -1
- package/dist/png.cjs +2 -2
- package/dist/png.cjs.map +1 -1
- package/dist/png.d.cts +16 -32
- package/dist/png.d.ts +16 -32
- package/dist/png.js +2 -2
- package/dist/png.js.map +1 -1
- package/dist/schemas.cjs +7 -7
- package/dist/schemas.cjs.map +1 -1
- package/dist/schemas.d.cts +48 -96
- package/dist/schemas.d.ts +48 -96
- package/dist/schemas.js +7 -7
- package/dist/schemas.js.map +1 -1
- package/dist/voxta.cjs +4 -21
- package/dist/voxta.cjs.map +1 -1
- package/dist/voxta.d.cts +14 -28
- package/dist/voxta.d.ts +14 -28
- package/dist/voxta.js +4 -21
- package/dist/voxta.js.map +1 -1
- package/package.json +6 -6
package/dist/loader.cjs
CHANGED
|
@@ -21,7 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var loader_exports = {};
|
|
22
22
|
__export(loader_exports, {
|
|
23
23
|
computeContentHash: () => computeContentHash,
|
|
24
|
-
computeContentHashV2: () => computeContentHashV2,
|
|
25
24
|
detectFormat: () => detectFormat,
|
|
26
25
|
getContainerFormat: () => getContainerFormat,
|
|
27
26
|
mightBeCard: () => mightBeCard,
|
|
@@ -504,7 +503,7 @@ var CCv2LorebookEntrySchema = import_zod2.z.object({
|
|
|
504
503
|
selective: import_zod2.z.boolean().nullable().optional(),
|
|
505
504
|
secondary_keys: import_zod2.z.array(import_zod2.z.string()).nullable().optional(),
|
|
506
505
|
constant: import_zod2.z.boolean().nullable().optional(),
|
|
507
|
-
position: import_zod2.z.union([import_zod2.z.enum(["before_char", "after_char"
|
|
506
|
+
position: import_zod2.z.union([import_zod2.z.enum(["before_char", "after_char"]), import_zod2.z.number().int(), import_zod2.z.literal("")]).nullable().optional()
|
|
508
507
|
}).passthrough();
|
|
509
508
|
var CCv2CharacterBookSchema = import_zod2.z.object({
|
|
510
509
|
name: import_zod2.z.string().optional(),
|
|
@@ -568,7 +567,7 @@ var CCv3LorebookEntrySchema = import_zod3.z.object({
|
|
|
568
567
|
selective: import_zod3.z.boolean().nullable().optional(),
|
|
569
568
|
secondary_keys: import_zod3.z.array(import_zod3.z.string()).nullable().optional(),
|
|
570
569
|
constant: import_zod3.z.boolean().nullable().optional(),
|
|
571
|
-
position: import_zod3.z.union([import_zod3.z.enum(["before_char", "after_char"
|
|
570
|
+
position: import_zod3.z.union([import_zod3.z.enum(["before_char", "after_char"]), import_zod3.z.number().int(), import_zod3.z.literal("")]).nullable().optional(),
|
|
572
571
|
extensions: import_zod3.z.record(import_zod3.z.unknown()).optional(),
|
|
573
572
|
// v3 specific - also lenient with types since SillyTavern uses numbers for enums
|
|
574
573
|
automation_id: import_zod3.z.string().optional(),
|
|
@@ -8728,7 +8727,7 @@ function defaultTokenCounter(_card) {
|
|
|
8728
8727
|
total: 0
|
|
8729
8728
|
};
|
|
8730
8729
|
}
|
|
8731
|
-
function
|
|
8730
|
+
function getCanonicalContent(card) {
|
|
8732
8731
|
const normalized = {
|
|
8733
8732
|
name: card.data.name,
|
|
8734
8733
|
description: card.data.description || "",
|
|
@@ -8750,69 +8749,6 @@ function getCanonicalContentV1(card) {
|
|
|
8750
8749
|
};
|
|
8751
8750
|
return JSON.stringify(normalized, Object.keys(normalized).sort());
|
|
8752
8751
|
}
|
|
8753
|
-
function stableStringify(value) {
|
|
8754
|
-
if (value === null) return "null";
|
|
8755
|
-
switch (typeof value) {
|
|
8756
|
-
case "string":
|
|
8757
|
-
return JSON.stringify(value);
|
|
8758
|
-
case "number":
|
|
8759
|
-
return Number.isFinite(value) ? String(value) : "null";
|
|
8760
|
-
case "boolean":
|
|
8761
|
-
return value ? "true" : "false";
|
|
8762
|
-
case "bigint":
|
|
8763
|
-
return JSON.stringify(value.toString());
|
|
8764
|
-
case "undefined":
|
|
8765
|
-
case "function":
|
|
8766
|
-
case "symbol":
|
|
8767
|
-
return "null";
|
|
8768
|
-
case "object": {
|
|
8769
|
-
if (Array.isArray(value)) {
|
|
8770
|
-
const parts2 = value.map((item) => {
|
|
8771
|
-
if (item === void 0 || typeof item === "function" || typeof item === "symbol") {
|
|
8772
|
-
return "null";
|
|
8773
|
-
}
|
|
8774
|
-
return stableStringify(item);
|
|
8775
|
-
});
|
|
8776
|
-
return `[${parts2.join(",")}]`;
|
|
8777
|
-
}
|
|
8778
|
-
const obj = value;
|
|
8779
|
-
const keys = Object.keys(obj).sort();
|
|
8780
|
-
const parts = [];
|
|
8781
|
-
for (const key of keys) {
|
|
8782
|
-
const v = obj[key];
|
|
8783
|
-
if (v === void 0 || typeof v === "function" || typeof v === "symbol") {
|
|
8784
|
-
continue;
|
|
8785
|
-
}
|
|
8786
|
-
parts.push(`${JSON.stringify(key)}:${stableStringify(v)}`);
|
|
8787
|
-
}
|
|
8788
|
-
return `{${parts.join(",")}}`;
|
|
8789
|
-
}
|
|
8790
|
-
default:
|
|
8791
|
-
return "null";
|
|
8792
|
-
}
|
|
8793
|
-
}
|
|
8794
|
-
function getCanonicalContentV2(card) {
|
|
8795
|
-
const normalized = {
|
|
8796
|
-
name: card.data.name,
|
|
8797
|
-
description: card.data.description || "",
|
|
8798
|
-
personality: card.data.personality || "",
|
|
8799
|
-
scenario: card.data.scenario || "",
|
|
8800
|
-
first_mes: card.data.first_mes || "",
|
|
8801
|
-
mes_example: card.data.mes_example || "",
|
|
8802
|
-
system_prompt: card.data.system_prompt || "",
|
|
8803
|
-
post_history_instructions: card.data.post_history_instructions || "",
|
|
8804
|
-
alternate_greetings: card.data.alternate_greetings || [],
|
|
8805
|
-
character_book: card.data.character_book ? {
|
|
8806
|
-
entries: (card.data.character_book.entries || []).map((e) => ({
|
|
8807
|
-
keys: e.keys,
|
|
8808
|
-
content: e.content,
|
|
8809
|
-
enabled: e.enabled
|
|
8810
|
-
}))
|
|
8811
|
-
} : null,
|
|
8812
|
-
creator_notes: card.data.creator_notes || ""
|
|
8813
|
-
};
|
|
8814
|
-
return stableStringify(normalized);
|
|
8815
|
-
}
|
|
8816
8752
|
function isWithinTolerance(clientValue, computedValue, tolerance) {
|
|
8817
8753
|
if (clientValue === void 0) return false;
|
|
8818
8754
|
if (computedValue === 0) return clientValue === 0;
|
|
@@ -8833,18 +8769,15 @@ async function validateClientMetadata(clientMetadata, parseResult, options = {})
|
|
|
8833
8769
|
const warnings = [];
|
|
8834
8770
|
const errors = [];
|
|
8835
8771
|
const computedTokens = countTokens(card);
|
|
8836
|
-
const
|
|
8837
|
-
const
|
|
8838
|
-
const computedHashV1 = await computeHash(canonicalContentV1);
|
|
8839
|
-
const computedHashV2 = await computeHash(canonicalContentV2);
|
|
8772
|
+
const canonicalContent = getCanonicalContent(card);
|
|
8773
|
+
const computedHash = await computeHash(canonicalContent);
|
|
8840
8774
|
const entries = card.data.character_book?.entries || [];
|
|
8841
8775
|
const computedHasLorebook = entries.length > 0;
|
|
8842
8776
|
const computedLorebookCount = entries.length;
|
|
8843
8777
|
const authoritative = {
|
|
8844
8778
|
name: card.data.name,
|
|
8845
8779
|
tokens: computedTokens,
|
|
8846
|
-
contentHash:
|
|
8847
|
-
contentHashV2: computedHashV2,
|
|
8780
|
+
contentHash: computedHash,
|
|
8848
8781
|
hasLorebook: computedHasLorebook,
|
|
8849
8782
|
lorebookEntriesCount: computedLorebookCount
|
|
8850
8783
|
};
|
|
@@ -8856,27 +8789,21 @@ async function validateClientMetadata(clientMetadata, parseResult, options = {})
|
|
|
8856
8789
|
withinTolerance: false
|
|
8857
8790
|
});
|
|
8858
8791
|
}
|
|
8859
|
-
|
|
8860
|
-
const matchesV2 = clientMetadata.contentHash === computedHashV2;
|
|
8861
|
-
if (!matchesV1 && !matchesV2) {
|
|
8792
|
+
if (clientMetadata.contentHash !== computedHash) {
|
|
8862
8793
|
const disc = {
|
|
8863
8794
|
field: "contentHash",
|
|
8864
8795
|
clientValue: clientMetadata.contentHash,
|
|
8865
|
-
computedValue:
|
|
8796
|
+
computedValue: computedHash,
|
|
8866
8797
|
withinTolerance: false
|
|
8867
8798
|
};
|
|
8868
8799
|
discrepancies.push(disc);
|
|
8869
8800
|
if (allowHashMismatch) {
|
|
8870
8801
|
warnings.push(
|
|
8871
|
-
`Content hash mismatch: client=${clientMetadata.contentHash.substring(0, 8)}..., server
|
|
8802
|
+
`Content hash mismatch: client=${clientMetadata.contentHash.substring(0, 8)}..., server=${computedHash.substring(0, 8)}...`
|
|
8872
8803
|
);
|
|
8873
8804
|
} else {
|
|
8874
8805
|
errors.push("Content hash mismatch - possible tampering or encoding difference");
|
|
8875
8806
|
}
|
|
8876
|
-
} else if (matchesV1 && !matchesV2) {
|
|
8877
|
-
warnings.push(
|
|
8878
|
-
"Client contentHash matches legacy v1 canonicalization. Prefer authoritative.contentHashV2 for new storage."
|
|
8879
|
-
);
|
|
8880
8807
|
}
|
|
8881
8808
|
const tokenFields = [
|
|
8882
8809
|
"description",
|
|
@@ -8957,11 +8884,7 @@ async function validateClientMetadata(clientMetadata, parseResult, options = {})
|
|
|
8957
8884
|
};
|
|
8958
8885
|
}
|
|
8959
8886
|
async function computeContentHash(card) {
|
|
8960
|
-
const content =
|
|
8961
|
-
return sha256Hash(content);
|
|
8962
|
-
}
|
|
8963
|
-
async function computeContentHashV2(card) {
|
|
8964
|
-
const content = getCanonicalContentV2(card);
|
|
8887
|
+
const content = getCanonicalContent(card);
|
|
8965
8888
|
return sha256Hash(content);
|
|
8966
8889
|
}
|
|
8967
8890
|
function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
@@ -8977,18 +8900,15 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
8977
8900
|
const warnings = [];
|
|
8978
8901
|
const errors = [];
|
|
8979
8902
|
const computedTokens = countTokens(card);
|
|
8980
|
-
const
|
|
8981
|
-
const
|
|
8982
|
-
const computedHashV1 = computeHash(canonicalContentV1);
|
|
8983
|
-
const computedHashV2 = computeHash(canonicalContentV2);
|
|
8903
|
+
const canonicalContent = getCanonicalContent(card);
|
|
8904
|
+
const computedHash = computeHash(canonicalContent);
|
|
8984
8905
|
const entries = card.data.character_book?.entries || [];
|
|
8985
8906
|
const computedHasLorebook = entries.length > 0;
|
|
8986
8907
|
const computedLorebookCount = entries.length;
|
|
8987
8908
|
const authoritative = {
|
|
8988
8909
|
name: card.data.name,
|
|
8989
8910
|
tokens: computedTokens,
|
|
8990
|
-
contentHash:
|
|
8991
|
-
contentHashV2: computedHashV2,
|
|
8911
|
+
contentHash: computedHash,
|
|
8992
8912
|
hasLorebook: computedHasLorebook,
|
|
8993
8913
|
lorebookEntriesCount: computedLorebookCount
|
|
8994
8914
|
};
|
|
@@ -9000,13 +8920,11 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
9000
8920
|
withinTolerance: false
|
|
9001
8921
|
});
|
|
9002
8922
|
}
|
|
9003
|
-
|
|
9004
|
-
const matchesV2 = clientMetadata.contentHash === computedHashV2;
|
|
9005
|
-
if (!matchesV1 && !matchesV2) {
|
|
8923
|
+
if (clientMetadata.contentHash !== computedHash) {
|
|
9006
8924
|
discrepancies.push({
|
|
9007
8925
|
field: "contentHash",
|
|
9008
8926
|
clientValue: clientMetadata.contentHash,
|
|
9009
|
-
computedValue:
|
|
8927
|
+
computedValue: computedHash,
|
|
9010
8928
|
withinTolerance: false
|
|
9011
8929
|
});
|
|
9012
8930
|
if (allowHashMismatch) {
|
|
@@ -9014,10 +8932,6 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
9014
8932
|
} else {
|
|
9015
8933
|
errors.push("Content hash mismatch");
|
|
9016
8934
|
}
|
|
9017
|
-
} else if (matchesV1 && !matchesV2) {
|
|
9018
|
-
warnings.push(
|
|
9019
|
-
"Client contentHash matches legacy v1 canonicalization. Prefer authoritative.contentHashV2 for new storage."
|
|
9020
|
-
);
|
|
9021
8935
|
}
|
|
9022
8936
|
const tokenFields = [
|
|
9023
8937
|
"description",
|