@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.d.cts
CHANGED
|
@@ -33,8 +33,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
33
33
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
34
34
|
z.ZodEnum<[
|
|
35
35
|
"before_char",
|
|
36
|
-
"after_char"
|
|
37
|
-
"in_chat"
|
|
36
|
+
"after_char"
|
|
38
37
|
]>,
|
|
39
38
|
z.ZodNumber,
|
|
40
39
|
z.ZodLiteral<"">
|
|
@@ -77,8 +76,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
77
76
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
78
77
|
z.ZodEnum<[
|
|
79
78
|
"before_char",
|
|
80
|
-
"after_char"
|
|
81
|
-
"in_chat"
|
|
79
|
+
"after_char"
|
|
82
80
|
]>,
|
|
83
81
|
z.ZodNumber,
|
|
84
82
|
z.ZodLiteral<"">
|
|
@@ -121,8 +119,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
121
119
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
122
120
|
z.ZodEnum<[
|
|
123
121
|
"before_char",
|
|
124
|
-
"after_char"
|
|
125
|
-
"in_chat"
|
|
122
|
+
"after_char"
|
|
126
123
|
]>,
|
|
127
124
|
z.ZodNumber,
|
|
128
125
|
z.ZodLiteral<"">
|
|
@@ -167,8 +164,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
167
164
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
168
165
|
z.ZodEnum<[
|
|
169
166
|
"before_char",
|
|
170
|
-
"after_char"
|
|
171
|
-
"in_chat"
|
|
167
|
+
"after_char"
|
|
172
168
|
]>,
|
|
173
169
|
z.ZodNumber,
|
|
174
170
|
z.ZodLiteral<"">
|
|
@@ -219,8 +215,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
219
215
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
220
216
|
z.ZodEnum<[
|
|
221
217
|
"before_char",
|
|
222
|
-
"after_char"
|
|
223
|
-
"in_chat"
|
|
218
|
+
"after_char"
|
|
224
219
|
]>,
|
|
225
220
|
z.ZodNumber,
|
|
226
221
|
z.ZodLiteral<"">
|
|
@@ -296,8 +291,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
296
291
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
297
292
|
z.ZodEnum<[
|
|
298
293
|
"before_char",
|
|
299
|
-
"after_char"
|
|
300
|
-
"in_chat"
|
|
294
|
+
"after_char"
|
|
301
295
|
]>,
|
|
302
296
|
z.ZodNumber,
|
|
303
297
|
z.ZodLiteral<"">
|
|
@@ -340,8 +334,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
340
334
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
341
335
|
z.ZodEnum<[
|
|
342
336
|
"before_char",
|
|
343
|
-
"after_char"
|
|
344
|
-
"in_chat"
|
|
337
|
+
"after_char"
|
|
345
338
|
]>,
|
|
346
339
|
z.ZodNumber,
|
|
347
340
|
z.ZodLiteral<"">
|
|
@@ -384,8 +377,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
384
377
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
385
378
|
z.ZodEnum<[
|
|
386
379
|
"before_char",
|
|
387
|
-
"after_char"
|
|
388
|
-
"in_chat"
|
|
380
|
+
"after_char"
|
|
389
381
|
]>,
|
|
390
382
|
z.ZodNumber,
|
|
391
383
|
z.ZodLiteral<"">
|
|
@@ -430,8 +422,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
430
422
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
431
423
|
z.ZodEnum<[
|
|
432
424
|
"before_char",
|
|
433
|
-
"after_char"
|
|
434
|
-
"in_chat"
|
|
425
|
+
"after_char"
|
|
435
426
|
]>,
|
|
436
427
|
z.ZodNumber,
|
|
437
428
|
z.ZodLiteral<"">
|
|
@@ -482,8 +473,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
482
473
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
483
474
|
z.ZodEnum<[
|
|
484
475
|
"before_char",
|
|
485
|
-
"after_char"
|
|
486
|
-
"in_chat"
|
|
476
|
+
"after_char"
|
|
487
477
|
]>,
|
|
488
478
|
z.ZodNumber,
|
|
489
479
|
z.ZodLiteral<"">
|
|
@@ -582,8 +572,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
582
572
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
583
573
|
z.ZodEnum<[
|
|
584
574
|
"before_char",
|
|
585
|
-
"after_char"
|
|
586
|
-
"in_chat"
|
|
575
|
+
"after_char"
|
|
587
576
|
]>,
|
|
588
577
|
z.ZodNumber,
|
|
589
578
|
z.ZodLiteral<"">
|
|
@@ -658,8 +647,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
658
647
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
659
648
|
z.ZodEnum<[
|
|
660
649
|
"before_char",
|
|
661
|
-
"after_char"
|
|
662
|
-
"in_chat"
|
|
650
|
+
"after_char"
|
|
663
651
|
]>,
|
|
664
652
|
z.ZodNumber,
|
|
665
653
|
z.ZodLiteral<"">
|
|
@@ -744,8 +732,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
744
732
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
745
733
|
z.ZodEnum<[
|
|
746
734
|
"before_char",
|
|
747
|
-
"after_char"
|
|
748
|
-
"in_chat"
|
|
735
|
+
"after_char"
|
|
749
736
|
]>,
|
|
750
737
|
z.ZodNumber,
|
|
751
738
|
z.ZodLiteral<"">
|
|
@@ -824,8 +811,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
824
811
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
825
812
|
z.ZodEnum<[
|
|
826
813
|
"before_char",
|
|
827
|
-
"after_char"
|
|
828
|
-
"in_chat"
|
|
814
|
+
"after_char"
|
|
829
815
|
]>,
|
|
830
816
|
z.ZodNumber,
|
|
831
817
|
z.ZodLiteral<"">
|
|
@@ -1194,13 +1180,6 @@ export interface AuthoritativeMetadata {
|
|
|
1194
1180
|
tokens: TokenCounts;
|
|
1195
1181
|
/** Content hash computed server-side */
|
|
1196
1182
|
contentHash: string;
|
|
1197
|
-
/**
|
|
1198
|
-
* Content hash v2 computed server-side.
|
|
1199
|
-
*
|
|
1200
|
-
* @remarks
|
|
1201
|
-
* v1 is preserved for backwards compatibility. Prefer v2 for new storage/deduplication.
|
|
1202
|
-
*/
|
|
1203
|
-
contentHashV2?: string;
|
|
1204
1183
|
/** Whether the card has a lorebook */
|
|
1205
1184
|
hasLorebook: boolean;
|
|
1206
1185
|
/** Number of lorebook entries */
|
|
@@ -1300,13 +1279,6 @@ export declare function validateClientMetadata(clientMetadata: ClientMetadata, p
|
|
|
1300
1279
|
* @returns SHA-256 hash of canonical content
|
|
1301
1280
|
*/
|
|
1302
1281
|
export declare function computeContentHash(card: CCv3Data): Promise<string>;
|
|
1303
|
-
/**
|
|
1304
|
-
* Compute content hash v2 for a card (standalone utility)
|
|
1305
|
-
*
|
|
1306
|
-
* @param card - CCv3 card data
|
|
1307
|
-
* @returns SHA-256 hash of canonical content v2
|
|
1308
|
-
*/
|
|
1309
|
-
export declare function computeContentHashV2(card: CCv3Data): Promise<string>;
|
|
1310
1282
|
/**
|
|
1311
1283
|
* Options for synchronous metadata validation
|
|
1312
1284
|
*/
|
package/dist/loader.d.ts
CHANGED
|
@@ -33,8 +33,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
33
33
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
34
34
|
z.ZodEnum<[
|
|
35
35
|
"before_char",
|
|
36
|
-
"after_char"
|
|
37
|
-
"in_chat"
|
|
36
|
+
"after_char"
|
|
38
37
|
]>,
|
|
39
38
|
z.ZodNumber,
|
|
40
39
|
z.ZodLiteral<"">
|
|
@@ -77,8 +76,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
77
76
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
78
77
|
z.ZodEnum<[
|
|
79
78
|
"before_char",
|
|
80
|
-
"after_char"
|
|
81
|
-
"in_chat"
|
|
79
|
+
"after_char"
|
|
82
80
|
]>,
|
|
83
81
|
z.ZodNumber,
|
|
84
82
|
z.ZodLiteral<"">
|
|
@@ -121,8 +119,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
121
119
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
122
120
|
z.ZodEnum<[
|
|
123
121
|
"before_char",
|
|
124
|
-
"after_char"
|
|
125
|
-
"in_chat"
|
|
122
|
+
"after_char"
|
|
126
123
|
]>,
|
|
127
124
|
z.ZodNumber,
|
|
128
125
|
z.ZodLiteral<"">
|
|
@@ -167,8 +164,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
167
164
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
168
165
|
z.ZodEnum<[
|
|
169
166
|
"before_char",
|
|
170
|
-
"after_char"
|
|
171
|
-
"in_chat"
|
|
167
|
+
"after_char"
|
|
172
168
|
]>,
|
|
173
169
|
z.ZodNumber,
|
|
174
170
|
z.ZodLiteral<"">
|
|
@@ -219,8 +215,7 @@ declare const CCv3CharacterBookSchema: z.ZodObject<{
|
|
|
219
215
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
220
216
|
z.ZodEnum<[
|
|
221
217
|
"before_char",
|
|
222
|
-
"after_char"
|
|
223
|
-
"in_chat"
|
|
218
|
+
"after_char"
|
|
224
219
|
]>,
|
|
225
220
|
z.ZodNumber,
|
|
226
221
|
z.ZodLiteral<"">
|
|
@@ -296,8 +291,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
296
291
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
297
292
|
z.ZodEnum<[
|
|
298
293
|
"before_char",
|
|
299
|
-
"after_char"
|
|
300
|
-
"in_chat"
|
|
294
|
+
"after_char"
|
|
301
295
|
]>,
|
|
302
296
|
z.ZodNumber,
|
|
303
297
|
z.ZodLiteral<"">
|
|
@@ -340,8 +334,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
340
334
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
341
335
|
z.ZodEnum<[
|
|
342
336
|
"before_char",
|
|
343
|
-
"after_char"
|
|
344
|
-
"in_chat"
|
|
337
|
+
"after_char"
|
|
345
338
|
]>,
|
|
346
339
|
z.ZodNumber,
|
|
347
340
|
z.ZodLiteral<"">
|
|
@@ -384,8 +377,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
384
377
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
385
378
|
z.ZodEnum<[
|
|
386
379
|
"before_char",
|
|
387
|
-
"after_char"
|
|
388
|
-
"in_chat"
|
|
380
|
+
"after_char"
|
|
389
381
|
]>,
|
|
390
382
|
z.ZodNumber,
|
|
391
383
|
z.ZodLiteral<"">
|
|
@@ -430,8 +422,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
430
422
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
431
423
|
z.ZodEnum<[
|
|
432
424
|
"before_char",
|
|
433
|
-
"after_char"
|
|
434
|
-
"in_chat"
|
|
425
|
+
"after_char"
|
|
435
426
|
]>,
|
|
436
427
|
z.ZodNumber,
|
|
437
428
|
z.ZodLiteral<"">
|
|
@@ -482,8 +473,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
482
473
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
483
474
|
z.ZodEnum<[
|
|
484
475
|
"before_char",
|
|
485
|
-
"after_char"
|
|
486
|
-
"in_chat"
|
|
476
|
+
"after_char"
|
|
487
477
|
]>,
|
|
488
478
|
z.ZodNumber,
|
|
489
479
|
z.ZodLiteral<"">
|
|
@@ -582,8 +572,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
582
572
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
583
573
|
z.ZodEnum<[
|
|
584
574
|
"before_char",
|
|
585
|
-
"after_char"
|
|
586
|
-
"in_chat"
|
|
575
|
+
"after_char"
|
|
587
576
|
]>,
|
|
588
577
|
z.ZodNumber,
|
|
589
578
|
z.ZodLiteral<"">
|
|
@@ -658,8 +647,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
658
647
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
659
648
|
z.ZodEnum<[
|
|
660
649
|
"before_char",
|
|
661
|
-
"after_char"
|
|
662
|
-
"in_chat"
|
|
650
|
+
"after_char"
|
|
663
651
|
]>,
|
|
664
652
|
z.ZodNumber,
|
|
665
653
|
z.ZodLiteral<"">
|
|
@@ -744,8 +732,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
744
732
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
745
733
|
z.ZodEnum<[
|
|
746
734
|
"before_char",
|
|
747
|
-
"after_char"
|
|
748
|
-
"in_chat"
|
|
735
|
+
"after_char"
|
|
749
736
|
]>,
|
|
750
737
|
z.ZodNumber,
|
|
751
738
|
z.ZodLiteral<"">
|
|
@@ -824,8 +811,7 @@ declare const CCv3DataSchema: z.ZodObject<{
|
|
|
824
811
|
position: z.ZodOptional<z.ZodNullable<z.ZodUnion<[
|
|
825
812
|
z.ZodEnum<[
|
|
826
813
|
"before_char",
|
|
827
|
-
"after_char"
|
|
828
|
-
"in_chat"
|
|
814
|
+
"after_char"
|
|
829
815
|
]>,
|
|
830
816
|
z.ZodNumber,
|
|
831
817
|
z.ZodLiteral<"">
|
|
@@ -1194,13 +1180,6 @@ export interface AuthoritativeMetadata {
|
|
|
1194
1180
|
tokens: TokenCounts;
|
|
1195
1181
|
/** Content hash computed server-side */
|
|
1196
1182
|
contentHash: string;
|
|
1197
|
-
/**
|
|
1198
|
-
* Content hash v2 computed server-side.
|
|
1199
|
-
*
|
|
1200
|
-
* @remarks
|
|
1201
|
-
* v1 is preserved for backwards compatibility. Prefer v2 for new storage/deduplication.
|
|
1202
|
-
*/
|
|
1203
|
-
contentHashV2?: string;
|
|
1204
1183
|
/** Whether the card has a lorebook */
|
|
1205
1184
|
hasLorebook: boolean;
|
|
1206
1185
|
/** Number of lorebook entries */
|
|
@@ -1300,13 +1279,6 @@ export declare function validateClientMetadata(clientMetadata: ClientMetadata, p
|
|
|
1300
1279
|
* @returns SHA-256 hash of canonical content
|
|
1301
1280
|
*/
|
|
1302
1281
|
export declare function computeContentHash(card: CCv3Data): Promise<string>;
|
|
1303
|
-
/**
|
|
1304
|
-
* Compute content hash v2 for a card (standalone utility)
|
|
1305
|
-
*
|
|
1306
|
-
* @param card - CCv3 card data
|
|
1307
|
-
* @returns SHA-256 hash of canonical content v2
|
|
1308
|
-
*/
|
|
1309
|
-
export declare function computeContentHashV2(card: CCv3Data): Promise<string>;
|
|
1310
1282
|
/**
|
|
1311
1283
|
* Options for synchronous metadata validation
|
|
1312
1284
|
*/
|
package/dist/loader.js
CHANGED
|
@@ -473,7 +473,7 @@ var CCv2LorebookEntrySchema = z2.object({
|
|
|
473
473
|
selective: z2.boolean().nullable().optional(),
|
|
474
474
|
secondary_keys: z2.array(z2.string()).nullable().optional(),
|
|
475
475
|
constant: z2.boolean().nullable().optional(),
|
|
476
|
-
position: z2.union([z2.enum(["before_char", "after_char"
|
|
476
|
+
position: z2.union([z2.enum(["before_char", "after_char"]), z2.number().int(), z2.literal("")]).nullable().optional()
|
|
477
477
|
}).passthrough();
|
|
478
478
|
var CCv2CharacterBookSchema = z2.object({
|
|
479
479
|
name: z2.string().optional(),
|
|
@@ -537,7 +537,7 @@ var CCv3LorebookEntrySchema = z3.object({
|
|
|
537
537
|
selective: z3.boolean().nullable().optional(),
|
|
538
538
|
secondary_keys: z3.array(z3.string()).nullable().optional(),
|
|
539
539
|
constant: z3.boolean().nullable().optional(),
|
|
540
|
-
position: z3.union([z3.enum(["before_char", "after_char"
|
|
540
|
+
position: z3.union([z3.enum(["before_char", "after_char"]), z3.number().int(), z3.literal("")]).nullable().optional(),
|
|
541
541
|
extensions: z3.record(z3.unknown()).optional(),
|
|
542
542
|
// v3 specific - also lenient with types since SillyTavern uses numbers for enums
|
|
543
543
|
automation_id: z3.string().optional(),
|
|
@@ -8697,7 +8697,7 @@ function defaultTokenCounter(_card) {
|
|
|
8697
8697
|
total: 0
|
|
8698
8698
|
};
|
|
8699
8699
|
}
|
|
8700
|
-
function
|
|
8700
|
+
function getCanonicalContent(card) {
|
|
8701
8701
|
const normalized = {
|
|
8702
8702
|
name: card.data.name,
|
|
8703
8703
|
description: card.data.description || "",
|
|
@@ -8719,69 +8719,6 @@ function getCanonicalContentV1(card) {
|
|
|
8719
8719
|
};
|
|
8720
8720
|
return JSON.stringify(normalized, Object.keys(normalized).sort());
|
|
8721
8721
|
}
|
|
8722
|
-
function stableStringify(value) {
|
|
8723
|
-
if (value === null) return "null";
|
|
8724
|
-
switch (typeof value) {
|
|
8725
|
-
case "string":
|
|
8726
|
-
return JSON.stringify(value);
|
|
8727
|
-
case "number":
|
|
8728
|
-
return Number.isFinite(value) ? String(value) : "null";
|
|
8729
|
-
case "boolean":
|
|
8730
|
-
return value ? "true" : "false";
|
|
8731
|
-
case "bigint":
|
|
8732
|
-
return JSON.stringify(value.toString());
|
|
8733
|
-
case "undefined":
|
|
8734
|
-
case "function":
|
|
8735
|
-
case "symbol":
|
|
8736
|
-
return "null";
|
|
8737
|
-
case "object": {
|
|
8738
|
-
if (Array.isArray(value)) {
|
|
8739
|
-
const parts2 = value.map((item) => {
|
|
8740
|
-
if (item === void 0 || typeof item === "function" || typeof item === "symbol") {
|
|
8741
|
-
return "null";
|
|
8742
|
-
}
|
|
8743
|
-
return stableStringify(item);
|
|
8744
|
-
});
|
|
8745
|
-
return `[${parts2.join(",")}]`;
|
|
8746
|
-
}
|
|
8747
|
-
const obj = value;
|
|
8748
|
-
const keys = Object.keys(obj).sort();
|
|
8749
|
-
const parts = [];
|
|
8750
|
-
for (const key of keys) {
|
|
8751
|
-
const v = obj[key];
|
|
8752
|
-
if (v === void 0 || typeof v === "function" || typeof v === "symbol") {
|
|
8753
|
-
continue;
|
|
8754
|
-
}
|
|
8755
|
-
parts.push(`${JSON.stringify(key)}:${stableStringify(v)}`);
|
|
8756
|
-
}
|
|
8757
|
-
return `{${parts.join(",")}}`;
|
|
8758
|
-
}
|
|
8759
|
-
default:
|
|
8760
|
-
return "null";
|
|
8761
|
-
}
|
|
8762
|
-
}
|
|
8763
|
-
function getCanonicalContentV2(card) {
|
|
8764
|
-
const normalized = {
|
|
8765
|
-
name: card.data.name,
|
|
8766
|
-
description: card.data.description || "",
|
|
8767
|
-
personality: card.data.personality || "",
|
|
8768
|
-
scenario: card.data.scenario || "",
|
|
8769
|
-
first_mes: card.data.first_mes || "",
|
|
8770
|
-
mes_example: card.data.mes_example || "",
|
|
8771
|
-
system_prompt: card.data.system_prompt || "",
|
|
8772
|
-
post_history_instructions: card.data.post_history_instructions || "",
|
|
8773
|
-
alternate_greetings: card.data.alternate_greetings || [],
|
|
8774
|
-
character_book: card.data.character_book ? {
|
|
8775
|
-
entries: (card.data.character_book.entries || []).map((e) => ({
|
|
8776
|
-
keys: e.keys,
|
|
8777
|
-
content: e.content,
|
|
8778
|
-
enabled: e.enabled
|
|
8779
|
-
}))
|
|
8780
|
-
} : null,
|
|
8781
|
-
creator_notes: card.data.creator_notes || ""
|
|
8782
|
-
};
|
|
8783
|
-
return stableStringify(normalized);
|
|
8784
|
-
}
|
|
8785
8722
|
function isWithinTolerance(clientValue, computedValue, tolerance) {
|
|
8786
8723
|
if (clientValue === void 0) return false;
|
|
8787
8724
|
if (computedValue === 0) return clientValue === 0;
|
|
@@ -8802,18 +8739,15 @@ async function validateClientMetadata(clientMetadata, parseResult, options = {})
|
|
|
8802
8739
|
const warnings = [];
|
|
8803
8740
|
const errors = [];
|
|
8804
8741
|
const computedTokens = countTokens(card);
|
|
8805
|
-
const
|
|
8806
|
-
const
|
|
8807
|
-
const computedHashV1 = await computeHash(canonicalContentV1);
|
|
8808
|
-
const computedHashV2 = await computeHash(canonicalContentV2);
|
|
8742
|
+
const canonicalContent = getCanonicalContent(card);
|
|
8743
|
+
const computedHash = await computeHash(canonicalContent);
|
|
8809
8744
|
const entries = card.data.character_book?.entries || [];
|
|
8810
8745
|
const computedHasLorebook = entries.length > 0;
|
|
8811
8746
|
const computedLorebookCount = entries.length;
|
|
8812
8747
|
const authoritative = {
|
|
8813
8748
|
name: card.data.name,
|
|
8814
8749
|
tokens: computedTokens,
|
|
8815
|
-
contentHash:
|
|
8816
|
-
contentHashV2: computedHashV2,
|
|
8750
|
+
contentHash: computedHash,
|
|
8817
8751
|
hasLorebook: computedHasLorebook,
|
|
8818
8752
|
lorebookEntriesCount: computedLorebookCount
|
|
8819
8753
|
};
|
|
@@ -8825,27 +8759,21 @@ async function validateClientMetadata(clientMetadata, parseResult, options = {})
|
|
|
8825
8759
|
withinTolerance: false
|
|
8826
8760
|
});
|
|
8827
8761
|
}
|
|
8828
|
-
|
|
8829
|
-
const matchesV2 = clientMetadata.contentHash === computedHashV2;
|
|
8830
|
-
if (!matchesV1 && !matchesV2) {
|
|
8762
|
+
if (clientMetadata.contentHash !== computedHash) {
|
|
8831
8763
|
const disc = {
|
|
8832
8764
|
field: "contentHash",
|
|
8833
8765
|
clientValue: clientMetadata.contentHash,
|
|
8834
|
-
computedValue:
|
|
8766
|
+
computedValue: computedHash,
|
|
8835
8767
|
withinTolerance: false
|
|
8836
8768
|
};
|
|
8837
8769
|
discrepancies.push(disc);
|
|
8838
8770
|
if (allowHashMismatch) {
|
|
8839
8771
|
warnings.push(
|
|
8840
|
-
`Content hash mismatch: client=${clientMetadata.contentHash.substring(0, 8)}..., server
|
|
8772
|
+
`Content hash mismatch: client=${clientMetadata.contentHash.substring(0, 8)}..., server=${computedHash.substring(0, 8)}...`
|
|
8841
8773
|
);
|
|
8842
8774
|
} else {
|
|
8843
8775
|
errors.push("Content hash mismatch - possible tampering or encoding difference");
|
|
8844
8776
|
}
|
|
8845
|
-
} else if (matchesV1 && !matchesV2) {
|
|
8846
|
-
warnings.push(
|
|
8847
|
-
"Client contentHash matches legacy v1 canonicalization. Prefer authoritative.contentHashV2 for new storage."
|
|
8848
|
-
);
|
|
8849
8777
|
}
|
|
8850
8778
|
const tokenFields = [
|
|
8851
8779
|
"description",
|
|
@@ -8926,11 +8854,7 @@ async function validateClientMetadata(clientMetadata, parseResult, options = {})
|
|
|
8926
8854
|
};
|
|
8927
8855
|
}
|
|
8928
8856
|
async function computeContentHash(card) {
|
|
8929
|
-
const content =
|
|
8930
|
-
return sha256Hash(content);
|
|
8931
|
-
}
|
|
8932
|
-
async function computeContentHashV2(card) {
|
|
8933
|
-
const content = getCanonicalContentV2(card);
|
|
8857
|
+
const content = getCanonicalContent(card);
|
|
8934
8858
|
return sha256Hash(content);
|
|
8935
8859
|
}
|
|
8936
8860
|
function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
@@ -8946,18 +8870,15 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
8946
8870
|
const warnings = [];
|
|
8947
8871
|
const errors = [];
|
|
8948
8872
|
const computedTokens = countTokens(card);
|
|
8949
|
-
const
|
|
8950
|
-
const
|
|
8951
|
-
const computedHashV1 = computeHash(canonicalContentV1);
|
|
8952
|
-
const computedHashV2 = computeHash(canonicalContentV2);
|
|
8873
|
+
const canonicalContent = getCanonicalContent(card);
|
|
8874
|
+
const computedHash = computeHash(canonicalContent);
|
|
8953
8875
|
const entries = card.data.character_book?.entries || [];
|
|
8954
8876
|
const computedHasLorebook = entries.length > 0;
|
|
8955
8877
|
const computedLorebookCount = entries.length;
|
|
8956
8878
|
const authoritative = {
|
|
8957
8879
|
name: card.data.name,
|
|
8958
8880
|
tokens: computedTokens,
|
|
8959
|
-
contentHash:
|
|
8960
|
-
contentHashV2: computedHashV2,
|
|
8881
|
+
contentHash: computedHash,
|
|
8961
8882
|
hasLorebook: computedHasLorebook,
|
|
8962
8883
|
lorebookEntriesCount: computedLorebookCount
|
|
8963
8884
|
};
|
|
@@ -8969,13 +8890,11 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
8969
8890
|
withinTolerance: false
|
|
8970
8891
|
});
|
|
8971
8892
|
}
|
|
8972
|
-
|
|
8973
|
-
const matchesV2 = clientMetadata.contentHash === computedHashV2;
|
|
8974
|
-
if (!matchesV1 && !matchesV2) {
|
|
8893
|
+
if (clientMetadata.contentHash !== computedHash) {
|
|
8975
8894
|
discrepancies.push({
|
|
8976
8895
|
field: "contentHash",
|
|
8977
8896
|
clientValue: clientMetadata.contentHash,
|
|
8978
|
-
computedValue:
|
|
8897
|
+
computedValue: computedHash,
|
|
8979
8898
|
withinTolerance: false
|
|
8980
8899
|
});
|
|
8981
8900
|
if (allowHashMismatch) {
|
|
@@ -8983,10 +8902,6 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
8983
8902
|
} else {
|
|
8984
8903
|
errors.push("Content hash mismatch");
|
|
8985
8904
|
}
|
|
8986
|
-
} else if (matchesV1 && !matchesV2) {
|
|
8987
|
-
warnings.push(
|
|
8988
|
-
"Client contentHash matches legacy v1 canonicalization. Prefer authoritative.contentHashV2 for new storage."
|
|
8989
|
-
);
|
|
8990
8905
|
}
|
|
8991
8906
|
const tokenFields = [
|
|
8992
8907
|
"description",
|
|
@@ -9055,7 +8970,6 @@ function validateClientMetadataSync(clientMetadata, parseResult, options) {
|
|
|
9055
8970
|
}
|
|
9056
8971
|
export {
|
|
9057
8972
|
computeContentHash,
|
|
9058
|
-
computeContentHashV2,
|
|
9059
8973
|
detectFormat,
|
|
9060
8974
|
getContainerFormat,
|
|
9061
8975
|
mightBeCard,
|