@rudra-js/core 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +425 -375
- package/dist/claim-screening.d.ts.map +1 -1
- package/dist/claim-screening.js +3 -9
- package/dist/claim-screening.js.map +1 -1
- package/dist/component-generator.d.ts +1 -1
- package/dist/component-generator.d.ts.map +1 -1
- package/dist/component-generator.js +28 -61
- package/dist/component-generator.js.map +1 -1
- package/dist/component-spec.d.ts +100 -11
- package/dist/component-spec.d.ts.map +1 -1
- package/dist/component-spec.js +3 -6
- package/dist/component-spec.js.map +1 -1
- package/dist/fallback-component.d.ts.map +1 -1
- package/dist/fallback-component.js +3 -3
- package/dist/fallback-component.js.map +1 -1
- package/dist/fit-to-shopper.d.ts +4 -1
- package/dist/fit-to-shopper.d.ts.map +1 -1
- package/dist/fit-to-shopper.js +8 -0
- package/dist/fit-to-shopper.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model-prompt.d.ts.map +1 -1
- package/dist/model-prompt.js +16 -3
- package/dist/model-prompt.js.map +1 -1
- package/dist/product-display.d.ts +6 -0
- package/dist/product-display.d.ts.map +1 -0
- package/dist/product-display.js +32 -0
- package/dist/product-display.js.map +1 -0
- package/dist/reconciliation.d.ts +2 -4
- package/dist/reconciliation.d.ts.map +1 -1
- package/dist/reconciliation.js +15 -21
- package/dist/reconciliation.js.map +1 -1
- package/dist/schemas.d.ts +1 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +1 -0
- package/dist/schemas.js.map +1 -1
- package/dist/signal-digest.d.ts.map +1 -1
- package/dist/signal-digest.js +2 -10
- package/dist/signal-digest.js.map +1 -1
- package/dist/spec-cache.d.ts +86 -7
- package/dist/spec-cache.d.ts.map +1 -1
- package/dist/spec-cache.js +14 -32
- package/dist/spec-cache.js.map +1 -1
- package/dist/tracking-input.d.ts.map +1 -1
- package/dist/tracking-input.js +8 -2
- package/dist/tracking-input.js.map +1 -1
- package/package.json +5 -4
- package/schemas/package.json +4 -0
- package/src/claim-screening.ts +3 -9
- package/src/component-generator.ts +33 -82
- package/src/component-spec.ts +5 -18
- package/src/fallback-component.ts +4 -3
- package/src/fit-to-shopper.ts +16 -1
- package/src/index.ts +1 -2
- package/src/model-prompt.ts +24 -3
- package/src/product-display.ts +43 -0
- package/src/reconciliation.ts +16 -23
- package/src/schemas.ts +6 -0
- package/src/signal-digest.ts +2 -8
- package/src/spec-cache.ts +17 -41
- package/src/tracking-input.ts +11 -2
package/src/spec-cache.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { SPEC_VERSION, generatedSpecSchema } from './component-spec.js';
|
|
4
|
+
import type { PromptPair } from './model-prompt.js';
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
spec:
|
|
8
|
-
generatedAt: number
|
|
9
|
-
}
|
|
6
|
+
export const cachedSpecSchema = z.object({
|
|
7
|
+
spec: generatedSpecSchema,
|
|
8
|
+
generatedAt: z.number(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export type CachedSpec = z.infer<typeof cachedSpecSchema>;
|
|
10
12
|
|
|
11
13
|
export interface SpecCache {
|
|
12
14
|
get(key: string): Promise<CachedSpec | undefined>;
|
|
@@ -79,43 +81,17 @@ export function createNullSpecCache(): SpecCache {
|
|
|
79
81
|
return { get: async () => undefined, set: async () => {} };
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
function canonicalise(value: unknown): string {
|
|
83
|
-
if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'null';
|
|
84
|
-
if (Array.isArray(value)) return `[${value.map(canonicalise).join(',')}]`;
|
|
85
|
-
|
|
86
|
-
const sorted = Object.entries(value as Record<string, unknown>).toSorted(([left], [right]) =>
|
|
87
|
-
left < right ? -1 : 1,
|
|
88
|
-
);
|
|
89
|
-
const fields: string[] = [];
|
|
90
|
-
for (const [name, fieldValue] of sorted) {
|
|
91
|
-
if (fieldValue === undefined) continue;
|
|
92
|
-
fields.push(`${JSON.stringify(name)}:${canonicalise(fieldValue)}`);
|
|
93
|
-
}
|
|
94
|
-
return `{${fields.join(',')}}`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const PROMPT_FINGERPRINT = createHash('sha256').update(SYSTEM_PROMPT).digest('hex').slice(0, 16);
|
|
98
|
-
|
|
99
|
-
function withoutDwellAndScores(digest: SignalDigest) {
|
|
100
|
-
return {
|
|
101
|
-
...digest,
|
|
102
|
-
topViewed: digest.topViewed.map(({ dwellMs: _dwellMs, ...view }) => view),
|
|
103
|
-
categoryAffinity: digest.categoryAffinity.map(({ score: _score, ...affinity }) => affinity),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
84
|
export function specCacheKey(
|
|
108
|
-
|
|
109
|
-
candidateSkus: readonly string[],
|
|
85
|
+
prompt: PromptPair,
|
|
110
86
|
provider: { name: string; model: string },
|
|
111
87
|
): string {
|
|
112
|
-
const material =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
provider,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
88
|
+
const material = JSON.stringify([
|
|
89
|
+
SPEC_VERSION,
|
|
90
|
+
provider.name,
|
|
91
|
+
provider.model,
|
|
92
|
+
prompt.system,
|
|
93
|
+
prompt.user,
|
|
94
|
+
]);
|
|
119
95
|
|
|
120
96
|
return createHash('sha256').update(material).digest('hex').slice(0, 32);
|
|
121
97
|
}
|
package/src/tracking-input.ts
CHANGED
|
@@ -23,6 +23,15 @@ const MAX_EPOCH_MS = Date.UTC(2100, 0, 1);
|
|
|
23
23
|
const identifier = () => z.string().min(1).max(FIELD_LIMITS.identifier);
|
|
24
24
|
const optionalIdentifier = () => identifier().optional();
|
|
25
25
|
|
|
26
|
+
// In u mode a surrogate pair reads as one code point, so this matches only an unpaired half.
|
|
27
|
+
const hasLoneSurrogate = (value: string) => /\p{Surrogate}/u.test(value);
|
|
28
|
+
|
|
29
|
+
// Product links run the SKU through encodeURIComponent, which throws on a lone surrogate.
|
|
30
|
+
const skuIdentifier = () =>
|
|
31
|
+
identifier().refine((value) => !hasLoneSurrogate(value), {
|
|
32
|
+
message: 'expected well-formed Unicode, with no unpaired surrogate',
|
|
33
|
+
});
|
|
34
|
+
|
|
26
35
|
const currencyCode = () =>
|
|
27
36
|
z
|
|
28
37
|
.string()
|
|
@@ -48,7 +57,7 @@ const imageReference = () =>
|
|
|
48
57
|
);
|
|
49
58
|
|
|
50
59
|
export const productSchema = z.strictObject({
|
|
51
|
-
sku:
|
|
60
|
+
sku: skuIdentifier(),
|
|
52
61
|
title: z.string().min(1).max(FIELD_LIMITS.shortText),
|
|
53
62
|
category: identifier(),
|
|
54
63
|
price: z.number().nonnegative(),
|
|
@@ -143,7 +152,7 @@ export type TrackingSignals = z.infer<typeof trackingSignalsSchema>;
|
|
|
143
152
|
export const bundleSchema = z.strictObject({
|
|
144
153
|
id: identifier(),
|
|
145
154
|
skus: z
|
|
146
|
-
.array(
|
|
155
|
+
.array(skuIdentifier())
|
|
147
156
|
.min(2)
|
|
148
157
|
.max(FIELD_LIMITS.productsPerBundle)
|
|
149
158
|
.refine(isUnique, { message: 'a bundle must not list the same product twice' }),
|