@rudra-js/core 0.9.1 → 0.11.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 +175 -46
- 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 +4 -1
- package/dist/component-generator.d.ts.map +1 -1
- package/dist/component-generator.js +95 -63
- package/dist/component-generator.js.map +1 -1
- package/dist/component-spec.d.ts +102 -12
- package/dist/component-spec.d.ts.map +1 -1
- package/dist/component-spec.js +4 -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 +87 -7
- package/dist/spec-cache.d.ts.map +1 -1
- package/dist/spec-cache.js +20 -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 +126 -84
- package/src/component-spec.ts +6 -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 +24 -40
- 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>;
|
|
@@ -75,47 +77,29 @@ export function createMemorySpecCache(options: MemorySpecCacheOptions = {}): Spe
|
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
return { get: async () => undefined, set: async () => {} };
|
|
80
|
-
}
|
|
80
|
+
const nullStores = new WeakSet<SpecCache>();
|
|
81
81
|
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
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(',')}}`;
|
|
82
|
+
export function createNullSpecCache(): SpecCache {
|
|
83
|
+
const store: SpecCache = { get: async () => undefined, set: async () => {} };
|
|
84
|
+
nullStores.add(store);
|
|
85
|
+
return store;
|
|
95
86
|
}
|
|
96
87
|
|
|
97
|
-
|
|
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
|
-
};
|
|
88
|
+
export function isNullSpecCache(cache: SpecCache): boolean {
|
|
89
|
+
return nullStores.has(cache);
|
|
105
90
|
}
|
|
106
91
|
|
|
107
92
|
export function specCacheKey(
|
|
108
|
-
|
|
109
|
-
candidateSkus: readonly string[],
|
|
93
|
+
prompt: PromptPair,
|
|
110
94
|
provider: { name: string; model: string },
|
|
111
95
|
): string {
|
|
112
|
-
const material =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
provider,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
96
|
+
const material = JSON.stringify([
|
|
97
|
+
SPEC_VERSION,
|
|
98
|
+
provider.name,
|
|
99
|
+
provider.model,
|
|
100
|
+
prompt.system,
|
|
101
|
+
prompt.user,
|
|
102
|
+
]);
|
|
119
103
|
|
|
120
104
|
return createHash('sha256').update(material).digest('hex').slice(0, 32);
|
|
121
105
|
}
|
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' }),
|