@rudra-js/core 0.5.0 → 0.7.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.
Files changed (67) hide show
  1. package/README.md +64 -16
  2. package/dist/claim-screening.d.ts +10 -0
  3. package/dist/claim-screening.d.ts.map +1 -0
  4. package/dist/claim-screening.js +157 -0
  5. package/dist/claim-screening.js.map +1 -0
  6. package/dist/component-generator.d.ts +0 -70
  7. package/dist/component-generator.d.ts.map +1 -1
  8. package/dist/component-generator.js +27 -135
  9. package/dist/component-generator.js.map +1 -1
  10. package/dist/component-spec.d.ts +4 -159
  11. package/dist/component-spec.d.ts.map +1 -1
  12. package/dist/component-spec.js +0 -92
  13. package/dist/component-spec.js.map +1 -1
  14. package/dist/fallback-component.d.ts +0 -6
  15. package/dist/fallback-component.d.ts.map +1 -1
  16. package/dist/fallback-component.js +0 -21
  17. package/dist/fallback-component.js.map +1 -1
  18. package/dist/fit-to-shopper.d.ts +5 -1
  19. package/dist/fit-to-shopper.d.ts.map +1 -1
  20. package/dist/fit-to-shopper.js +5 -14
  21. package/dist/fit-to-shopper.js.map +1 -1
  22. package/dist/index.d.ts +1 -8
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +0 -7
  25. package/dist/index.js.map +1 -1
  26. package/dist/model-prompt.d.ts +1 -30
  27. package/dist/model-prompt.d.ts.map +1 -1
  28. package/dist/model-prompt.js +19 -78
  29. package/dist/model-prompt.js.map +1 -1
  30. package/dist/product-selection.d.ts +0 -29
  31. package/dist/product-selection.d.ts.map +1 -1
  32. package/dist/product-selection.js +1 -22
  33. package/dist/product-selection.js.map +1 -1
  34. package/dist/provider.d.ts +0 -55
  35. package/dist/provider.d.ts.map +1 -1
  36. package/dist/provider.js +0 -12
  37. package/dist/provider.js.map +1 -1
  38. package/dist/reconciliation.d.ts +6 -61
  39. package/dist/reconciliation.d.ts.map +1 -1
  40. package/dist/reconciliation.js +76 -466
  41. package/dist/reconciliation.js.map +1 -1
  42. package/dist/signal-digest.d.ts +1 -18
  43. package/dist/signal-digest.d.ts.map +1 -1
  44. package/dist/signal-digest.js +27 -66
  45. package/dist/signal-digest.js.map +1 -1
  46. package/dist/spec-cache.d.ts +8 -70
  47. package/dist/spec-cache.d.ts.map +1 -1
  48. package/dist/spec-cache.js +5 -68
  49. package/dist/spec-cache.js.map +1 -1
  50. package/dist/tracking-input.d.ts +0 -49
  51. package/dist/tracking-input.d.ts.map +1 -1
  52. package/dist/tracking-input.js +5 -105
  53. package/dist/tracking-input.js.map +1 -1
  54. package/package.json +7 -6
  55. package/src/claim-screening.ts +190 -0
  56. package/src/component-generator.ts +45 -240
  57. package/src/component-spec.ts +17 -118
  58. package/src/fallback-component.ts +0 -22
  59. package/src/fit-to-shopper.ts +12 -16
  60. package/src/index.ts +1 -8
  61. package/src/model-prompt.ts +25 -84
  62. package/src/product-selection.ts +6 -52
  63. package/src/provider.ts +4 -60
  64. package/src/reconciliation.ts +104 -499
  65. package/src/signal-digest.ts +34 -83
  66. package/src/spec-cache.ts +10 -97
  67. package/src/tracking-input.ts +17 -111
package/src/provider.ts CHANGED
@@ -1,16 +1,6 @@
1
1
  import type { z } from 'zod';
2
2
  import type { GeneratedSpec } from './component-spec.js';
3
3
 
4
- /**
5
- * The language-model port.
6
- *
7
- * `@rudra-js/core` depends on no vendor SDK. Adapters live in their own packages,
8
- * so a host installs exactly one and the rest never reach its dependency tree.
9
- * Anything satisfying this interface works — a hosted API, a self-hosted model,
10
- * an in-tenancy deployment, or a recorded fixture.
11
- */
12
-
13
- /** Reported by an adapter for cost accounting. Never used for control flow. */
14
4
  export interface TokenUsage {
15
5
  inputTokens?: number;
16
6
  outputTokens?: number;
@@ -19,21 +9,12 @@ export interface TokenUsage {
19
9
  }
20
10
 
21
11
  export interface ProviderRequest {
22
- /**
23
- * Stable across every request in a deployment. Adapters that support prompt
24
- * caching should mark this as the cached prefix; interpolating anything
25
- * per-shopper into it would silently destroy the cache hit rate.
26
- */
27
12
  system: string;
28
- /** Per-request content. Must not be merged into the cached prefix. */
13
+
29
14
  user: string;
30
- /**
31
- * The schema the response must satisfy. Adapters convert it with their own
32
- * SDK helper, so there is no hand-maintained JSON Schema to drift out of
33
- * sync with the one `component-spec` defines.
34
- */
15
+
35
16
  schema: z.ZodType<GeneratedSpec>;
36
- /** Fires when the caller's budget elapses. An adapter must stop work. */
17
+
37
18
  signal: AbortSignal;
38
19
  }
39
20
 
@@ -42,55 +23,18 @@ export interface ProviderResult {
42
23
  usage?: TokenUsage;
43
24
  }
44
25
 
45
- /**
46
- * What an adapter promises.
47
- *
48
- * Three obligations, none of which the caller can verify from the outside, so
49
- * they are stated here rather than assumed:
50
- *
51
- * 1. Return a parsed object, not a string. Turning model output into a
52
- * `GeneratedSpec` is the adapter's job, because only it knows what its
53
- * structured-output mode returns.
54
- * 2. Throw on failure — a refusal, a transport error, an unparseable
55
- * response. Never return a partial or invented spec. The caller treats a
56
- * throw as "use the deterministic component", which is always safe; a
57
- * fabricated spec is not.
58
- * 3. Respect `signal`, in both directions: do not start work when it is
59
- * already aborted, and stop when it aborts mid-flight. The caller races
60
- * the call against its own timeout regardless, so ignoring it does not
61
- * hold a page open — but it does leave work running and billing after
62
- * nobody is waiting, and it answers a caller that has already given up.
63
- *
64
- * `AbortSignal.throwIfAborted()` is the whole of the first half.
65
- *
66
- * The caller re-validates whatever comes back. An adapter that returns
67
- * something malformed is a bug, not a security hole.
68
- */
69
26
  export interface ComponentProvider {
70
- /** Short identifier recorded on every generated spec, e.g. 'anthropic'. */
71
27
  readonly name: string;
72
- /** Concrete model identifier, e.g. 'claude-opus-5'. */
28
+
73
29
  readonly model: string;
74
30
  generate(request: ProviderRequest): Promise<ProviderResult>;
75
31
  }
76
32
 
77
- /**
78
- * A provider that returns a fixed spec and never touches the network.
79
- *
80
- * This is the benchmark's control: it isolates the cost of the framework from
81
- * the latency of a model, which is the only way to report what server-side
82
- * rendering itself costs. It is also what the generator's tests run against,
83
- * since a test that needs an API key is a test nobody runs.
84
- */
85
33
  export function createFixedSpecProvider(spec: GeneratedSpec): ComponentProvider {
86
34
  return {
87
35
  name: 'fixed',
88
36
  model: 'none',
89
37
  generate: async ({ signal }) => {
90
- // Nothing here is slow enough to need cancelling, which is exactly why it
91
- // is worth checking: the obligation is not "cancel your work", it is "do
92
- // not answer a caller that has already given up". A reference
93
- // implementation that skips the cheap half teaches the wrong lesson.
94
38
  signal.throwIfAborted();
95
39
  return { spec };
96
40
  },