@seanhogg/builderforce-memory 2026.6.18

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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +582 -0
  3. package/dist/agent/SSMAgent.d.ts +146 -0
  4. package/dist/agent/SSMAgent.d.ts.map +1 -0
  5. package/dist/agent/SSMAgent.js +231 -0
  6. package/dist/agent/SSMAgent.js.map +1 -0
  7. package/dist/agent/index.d.ts +3 -0
  8. package/dist/agent/index.d.ts.map +1 -0
  9. package/dist/agent/index.js +2 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/bridges/AnthropicBridge.d.ts +47 -0
  12. package/dist/bridges/AnthropicBridge.d.ts.map +1 -0
  13. package/dist/bridges/AnthropicBridge.js +120 -0
  14. package/dist/bridges/AnthropicBridge.js.map +1 -0
  15. package/dist/bridges/CachingBridge.d.ts +44 -0
  16. package/dist/bridges/CachingBridge.d.ts.map +1 -0
  17. package/dist/bridges/CachingBridge.js +62 -0
  18. package/dist/bridges/CachingBridge.js.map +1 -0
  19. package/dist/bridges/FetchBridge.d.ts +30 -0
  20. package/dist/bridges/FetchBridge.d.ts.map +1 -0
  21. package/dist/bridges/FetchBridge.js +24 -0
  22. package/dist/bridges/FetchBridge.js.map +1 -0
  23. package/dist/bridges/OpenAIBridge.d.ts +33 -0
  24. package/dist/bridges/OpenAIBridge.d.ts.map +1 -0
  25. package/dist/bridges/OpenAIBridge.js +110 -0
  26. package/dist/bridges/OpenAIBridge.js.map +1 -0
  27. package/dist/bridges/ResponseCache.d.ts +65 -0
  28. package/dist/bridges/ResponseCache.d.ts.map +1 -0
  29. package/dist/bridges/ResponseCache.js +97 -0
  30. package/dist/bridges/ResponseCache.js.map +1 -0
  31. package/dist/bridges/SemanticCachingBridge.d.ts +31 -0
  32. package/dist/bridges/SemanticCachingBridge.d.ts.map +1 -0
  33. package/dist/bridges/SemanticCachingBridge.js +44 -0
  34. package/dist/bridges/SemanticCachingBridge.js.map +1 -0
  35. package/dist/bridges/TransformerBridge.d.ts +35 -0
  36. package/dist/bridges/TransformerBridge.d.ts.map +1 -0
  37. package/dist/bridges/TransformerBridge.js +10 -0
  38. package/dist/bridges/TransformerBridge.js.map +1 -0
  39. package/dist/bridges/index.d.ts +14 -0
  40. package/dist/bridges/index.d.ts.map +1 -0
  41. package/dist/bridges/index.js +7 -0
  42. package/dist/bridges/index.js.map +1 -0
  43. package/dist/cache/FetchSemanticCacheBackend.d.ts +40 -0
  44. package/dist/cache/FetchSemanticCacheBackend.d.ts.map +1 -0
  45. package/dist/cache/FetchSemanticCacheBackend.js +61 -0
  46. package/dist/cache/FetchSemanticCacheBackend.js.map +1 -0
  47. package/dist/cache/SemanticCache.d.ts +105 -0
  48. package/dist/cache/SemanticCache.d.ts.map +1 -0
  49. package/dist/cache/SemanticCache.js +130 -0
  50. package/dist/cache/SemanticCache.js.map +1 -0
  51. package/dist/cache/index.d.ts +5 -0
  52. package/dist/cache/index.d.ts.map +1 -0
  53. package/dist/cache/index.js +3 -0
  54. package/dist/cache/index.js.map +1 -0
  55. package/dist/distillation/DistillationEngine.d.ts +107 -0
  56. package/dist/distillation/DistillationEngine.d.ts.map +1 -0
  57. package/dist/distillation/DistillationEngine.js +152 -0
  58. package/dist/distillation/DistillationEngine.js.map +1 -0
  59. package/dist/distillation/index.d.ts +3 -0
  60. package/dist/distillation/index.d.ts.map +1 -0
  61. package/dist/distillation/index.js +2 -0
  62. package/dist/distillation/index.js.map +1 -0
  63. package/dist/errors/SSMError.d.ts +14 -0
  64. package/dist/errors/SSMError.d.ts.map +1 -0
  65. package/dist/errors/SSMError.js +18 -0
  66. package/dist/errors/SSMError.js.map +1 -0
  67. package/dist/errors/index.d.ts +3 -0
  68. package/dist/errors/index.d.ts.map +1 -0
  69. package/dist/errors/index.js +2 -0
  70. package/dist/errors/index.js.map +1 -0
  71. package/dist/index.d.ts +65 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +59 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/memory/MemoryStore.d.ts +152 -0
  76. package/dist/memory/MemoryStore.d.ts.map +1 -0
  77. package/dist/memory/MemoryStore.js +290 -0
  78. package/dist/memory/MemoryStore.js.map +1 -0
  79. package/dist/memory/index.d.ts +3 -0
  80. package/dist/memory/index.d.ts.map +1 -0
  81. package/dist/memory/index.js +2 -0
  82. package/dist/memory/index.js.map +1 -0
  83. package/dist/router/InferenceRouter.d.ts +92 -0
  84. package/dist/router/InferenceRouter.d.ts.map +1 -0
  85. package/dist/router/InferenceRouter.js +113 -0
  86. package/dist/router/InferenceRouter.js.map +1 -0
  87. package/dist/router/index.d.ts +3 -0
  88. package/dist/router/index.d.ts.map +1 -0
  89. package/dist/router/index.js +2 -0
  90. package/dist/router/index.js.map +1 -0
  91. package/dist/runtime/SSMRuntime.d.ts +167 -0
  92. package/dist/runtime/SSMRuntime.d.ts.map +1 -0
  93. package/dist/runtime/SSMRuntime.js +199 -0
  94. package/dist/runtime/SSMRuntime.js.map +1 -0
  95. package/dist/runtime/index.d.ts +3 -0
  96. package/dist/runtime/index.d.ts.map +1 -0
  97. package/dist/runtime/index.js +2 -0
  98. package/dist/runtime/index.js.map +1 -0
  99. package/dist/session/errors.d.ts +10 -0
  100. package/dist/session/errors.d.ts.map +1 -0
  101. package/dist/session/errors.js +14 -0
  102. package/dist/session/errors.js.map +1 -0
  103. package/dist/session/index.d.ts +11 -0
  104. package/dist/session/index.d.ts.map +1 -0
  105. package/dist/session/index.js +7 -0
  106. package/dist/session/index.js.map +1 -0
  107. package/dist/session/persistence.d.ts +14 -0
  108. package/dist/session/persistence.d.ts.map +1 -0
  109. package/dist/session/persistence.js +100 -0
  110. package/dist/session/persistence.js.map +1 -0
  111. package/dist/session/presets.d.ts +31 -0
  112. package/dist/session/presets.d.ts.map +1 -0
  113. package/dist/session/presets.js +91 -0
  114. package/dist/session/presets.js.map +1 -0
  115. package/dist/session/session.d.ts +186 -0
  116. package/dist/session/session.d.ts.map +1 -0
  117. package/dist/session/session.js +358 -0
  118. package/dist/session/session.js.map +1 -0
  119. package/dist/session/streaming.d.ts +13 -0
  120. package/dist/session/streaming.d.ts.map +1 -0
  121. package/dist/session/streaming.js +74 -0
  122. package/dist/session/streaming.js.map +1 -0
  123. package/dist/session/tokenizer.d.ts +18 -0
  124. package/dist/session/tokenizer.d.ts.map +1 -0
  125. package/dist/session/tokenizer.js +11 -0
  126. package/dist/session/tokenizer.js.map +1 -0
  127. package/dist/similarity/index.d.ts +19 -0
  128. package/dist/similarity/index.d.ts.map +1 -0
  129. package/dist/similarity/index.js +42 -0
  130. package/dist/similarity/index.js.map +1 -0
  131. package/package.json +120 -0
  132. package/src/agent/SSMAgent.ts +327 -0
  133. package/src/agent/index.ts +2 -0
  134. package/src/bridges/AnthropicBridge.ts +166 -0
  135. package/src/bridges/CachingBridge.ts +79 -0
  136. package/src/bridges/FetchBridge.ts +41 -0
  137. package/src/bridges/OpenAIBridge.ts +143 -0
  138. package/src/bridges/ResponseCache.ts +131 -0
  139. package/src/bridges/SemanticCachingBridge.ts +60 -0
  140. package/src/bridges/TransformerBridge.ts +38 -0
  141. package/src/bridges/index.ts +13 -0
  142. package/src/cache/FetchSemanticCacheBackend.ts +79 -0
  143. package/src/cache/SemanticCache.ts +196 -0
  144. package/src/cache/index.ts +9 -0
  145. package/src/distillation/DistillationEngine.ts +248 -0
  146. package/src/distillation/index.ts +2 -0
  147. package/src/errors/SSMError.ts +26 -0
  148. package/src/errors/index.ts +2 -0
  149. package/src/index.ts +128 -0
  150. package/src/memory/MemoryStore.ts +408 -0
  151. package/src/memory/index.ts +2 -0
  152. package/src/router/InferenceRouter.ts +201 -0
  153. package/src/router/index.ts +2 -0
  154. package/src/runtime/SSMRuntime.ts +309 -0
  155. package/src/runtime/index.ts +2 -0
  156. package/src/session/errors.ts +24 -0
  157. package/src/session/index.ts +25 -0
  158. package/src/session/persistence.ts +142 -0
  159. package/src/session/presets.ts +122 -0
  160. package/src/session/session.ts +657 -0
  161. package/src/session/streaming.ts +97 -0
  162. package/src/session/tokenizer.ts +18 -0
  163. package/src/similarity/index.ts +42 -0
@@ -0,0 +1,248 @@
1
+ /**
2
+ * DistillationEngine – JS-only online knowledge distillation.
3
+ *
4
+ * The core insight: use a transformer as a *teacher* to generate high-quality
5
+ * responses, then adapt the SSM *student* on those responses using WSLA.
6
+ * This runs entirely in the browser with no Python or full-retraining required.
7
+ *
8
+ * Distillation flow:
9
+ * 1. bridge.generate(input) → teacher output
10
+ * 2. runtime.adapt(teacherOutput, opts.adapt) → SSM trains on it
11
+ * 3. Return both results for inspection
12
+ */
13
+
14
+ import type { AdaptOptions, AdaptResult } from '../session/index.js';
15
+ import type { SSMRuntime } from '../runtime/SSMRuntime.js';
16
+ import type { TransformerBridge, BridgeGenerateOptions } from '../bridges/TransformerBridge.js';
17
+ import { SSMError } from '../errors/SSMError.js';
18
+
19
+ // ── Types ─────────────────────────────────────────────────────────────────────
20
+
21
+ export interface QualityGate {
22
+ /**
23
+ * Minimum character length of the teacher output.
24
+ * Outputs shorter than this are considered low quality and are skipped.
25
+ */
26
+ minLength? : number;
27
+ /**
28
+ * Maximum SSM perplexity threshold.
29
+ * When the SSM already achieves perplexity below this value on the teacher
30
+ * output, the content is considered already learned and adaptation is skipped.
31
+ */
32
+ maxPerplexity? : number;
33
+ }
34
+
35
+ export interface DistillOptions {
36
+ /**
37
+ * Options forwarded to `runtime.adapt()`.
38
+ * Default: { wsla: true, epochs: 3 }
39
+ * WSLA is preferred because it is fast and targets the selective
40
+ * projection rows — exactly the parameters that encode token routing.
41
+ */
42
+ adapt? : AdaptOptions;
43
+
44
+ /**
45
+ * Options forwarded to `bridge.generate()`.
46
+ */
47
+ generate? : BridgeGenerateOptions;
48
+
49
+ /**
50
+ * Quality gate filters that can skip adaptation for low-quality or
51
+ * already-learned inputs.
52
+ */
53
+ qualityGate? : QualityGate;
54
+ }
55
+
56
+ export interface DistillResult {
57
+ /** The input prompt that was distilled. */
58
+ input : string;
59
+ /** The teacher's (transformer bridge) response to the input. */
60
+ teacherOutput: string;
61
+ /** The adapt() result from training the SSM on the teacher output. */
62
+ adaptResult : AdaptResult;
63
+ /** Whether adaptation was skipped by the quality gate. */
64
+ skipped? : boolean;
65
+ /** Reason adaptation was skipped, if applicable. */
66
+ skipReason? : string;
67
+ }
68
+
69
+ export interface DistillBatchResult {
70
+ results : DistillResult[];
71
+ /** Total number of adapt epochs run across all inputs. */
72
+ totalEpochs: number;
73
+ /** Wall-clock time for the entire batch in milliseconds. */
74
+ totalMs : number;
75
+ }
76
+
77
+ export interface DistillationLog {
78
+ timestamp : number;
79
+ input : string;
80
+ teacherOutputLength: number;
81
+ skipped : boolean;
82
+ skipReason? : string;
83
+ finalLoss? : number;
84
+ epochs : number;
85
+ }
86
+
87
+ /** Maximum number of distillation log entries to retain in memory. */
88
+ const MAX_LOG_ENTRIES = 200;
89
+
90
+ // ── DistillationEngine ────────────────────────────────────────────────────────
91
+
92
+ export class DistillationEngine {
93
+ private readonly _runtime : SSMRuntime;
94
+ private readonly _bridge : TransformerBridge;
95
+ private readonly _log : DistillationLog[] = [];
96
+
97
+ /**
98
+ * @param runtime The SSMRuntime whose SSM will be trained as the student.
99
+ * @param bridge The transformer bridge acting as teacher.
100
+ * A bridge must be provided — distillation requires one.
101
+ */
102
+ constructor(runtime: SSMRuntime, bridge: TransformerBridge) {
103
+ this._runtime = runtime;
104
+ this._bridge = bridge;
105
+ }
106
+
107
+ /**
108
+ * Runs a single distillation pass:
109
+ * 1. Teacher generates a response for `input`
110
+ * 2. Quality gate is evaluated (if configured)
111
+ * 3. SSM is adapted on the teacher's output (WSLA by default)
112
+ *
113
+ * The training signal is the teacher's full response — this teaches the
114
+ * SSM what a good response to that prompt looks like, without requiring
115
+ * labelled data or a loss function beyond the standard LM objective.
116
+ */
117
+ async distill(input: string, opts: DistillOptions = {}): Promise<DistillResult> {
118
+ const adaptOpts: AdaptOptions = {
119
+ wsla : true,
120
+ epochs : 3,
121
+ ...opts.adapt,
122
+ };
123
+
124
+ let teacherOutput: string;
125
+ try {
126
+ teacherOutput = await this._bridge.generate(input, opts.generate);
127
+ } catch (err) {
128
+ throw new SSMError(
129
+ 'DISTILL_FAILED',
130
+ `Teacher bridge failed to generate for distillation: ${err instanceof Error ? err.message : String(err)}`,
131
+ err,
132
+ );
133
+ }
134
+
135
+ // ── Quality gate ──────────────────────────────────────────────────────
136
+
137
+ if (opts.qualityGate) {
138
+ const gate = opts.qualityGate;
139
+
140
+ if (gate.minLength != null && teacherOutput.length < gate.minLength) {
141
+ const result: DistillResult = {
142
+ input,
143
+ teacherOutput,
144
+ adaptResult : { losses: [], epochCount: 0, durationMs: 0 },
145
+ skipped : true,
146
+ skipReason : 'low_quality',
147
+ };
148
+ this._appendLog({
149
+ input,
150
+ teacherOutputLength: teacherOutput.length,
151
+ skipped : true,
152
+ skipReason : 'low_quality',
153
+ epochs : 0,
154
+ });
155
+ return result;
156
+ }
157
+
158
+ if (gate.maxPerplexity != null) {
159
+ let perplexity: number | undefined;
160
+ try {
161
+ perplexity = await this._runtime.evaluate(teacherOutput);
162
+ } catch {
163
+ // Evaluation failure is non-fatal — proceed with adaptation
164
+ }
165
+ if (perplexity != null && perplexity < gate.maxPerplexity) {
166
+ const result: DistillResult = {
167
+ input,
168
+ teacherOutput,
169
+ adaptResult : { losses: [], epochCount: 0, durationMs: 0 },
170
+ skipped : true,
171
+ skipReason : 'already_learned',
172
+ };
173
+ this._appendLog({
174
+ input,
175
+ teacherOutputLength: teacherOutput.length,
176
+ skipped : true,
177
+ skipReason : 'already_learned',
178
+ epochs : 0,
179
+ });
180
+ return result;
181
+ }
182
+ }
183
+ }
184
+
185
+ // Train the SSM on the teacher's output.
186
+ // Prepend the input so the model learns the (prompt → response) mapping.
187
+ const trainingText = `${input}\n${teacherOutput}`;
188
+
189
+ let adaptResult: AdaptResult;
190
+ try {
191
+ adaptResult = await this._runtime.adapt(trainingText, adaptOpts);
192
+ } catch (err) {
193
+ throw new SSMError(
194
+ 'DISTILL_FAILED',
195
+ `SSM adaptation failed during distillation: ${err instanceof Error ? err.message : String(err)}`,
196
+ err,
197
+ );
198
+ }
199
+
200
+ this._appendLog({
201
+ input,
202
+ teacherOutputLength: teacherOutput.length,
203
+ skipped : false,
204
+ finalLoss : adaptResult.losses.at(-1),
205
+ epochs : adaptResult.epochCount,
206
+ });
207
+
208
+ return { input, teacherOutput, adaptResult, skipped: false };
209
+ }
210
+
211
+ /**
212
+ * Runs distillation for each input in sequence.
213
+ * Aggregate statistics are returned alongside individual results.
214
+ */
215
+ async distillBatch(inputs: string[], opts: DistillOptions = {}): Promise<DistillBatchResult> {
216
+ const startMs = Date.now();
217
+ const results: DistillResult[] = [];
218
+ let totalEpochs = 0;
219
+
220
+ for (const input of inputs) {
221
+ const result = await this.distill(input, opts);
222
+ results.push(result);
223
+ totalEpochs += result.adaptResult.epochCount;
224
+ }
225
+
226
+ return {
227
+ results,
228
+ totalEpochs,
229
+ totalMs: Date.now() - startMs,
230
+ };
231
+ }
232
+
233
+ /**
234
+ * Returns a copy of the in-memory distillation log (last 200 entries).
235
+ */
236
+ getLog(): DistillationLog[] {
237
+ return this._log.slice();
238
+ }
239
+
240
+ // ── Private helpers ───────────────────────────────────────────────────────
241
+
242
+ private _appendLog(entry: Omit<DistillationLog, 'timestamp'>): void {
243
+ this._log.push({ timestamp: Date.now(), ...entry });
244
+ if (this._log.length > MAX_LOG_ENTRIES) {
245
+ this._log.shift();
246
+ }
247
+ }
248
+ }
@@ -0,0 +1,2 @@
1
+ export { DistillationEngine } from './DistillationEngine.js';
2
+ export type { DistillOptions, DistillResult, DistillBatchResult, DistillationLog, QualityGate } from './DistillationEngine.js';
@@ -0,0 +1,26 @@
1
+ /**
2
+ * SSMError – typed error class for SSM.js runtime-level failures.
3
+ *
4
+ * Session-layer failures (GPU init, tokenizer, checkpoint) throw SessionError.
5
+ * Runtime-level failures (bridge, distillation, memory) throw SSMError.
6
+ * Both carry a typed `code` discriminant for programmatic handling.
7
+ */
8
+
9
+ export type SSMErrorCode =
10
+ | 'RUNTIME_DESTROYED' // method called after destroy()
11
+ | 'BRIDGE_REQUEST_FAILED' // fetch to transformer API returned non-OK
12
+ | 'BRIDGE_RESPONSE_INVALID' // unexpected shape in transformer API response
13
+ | 'MEMORY_UNAVAILABLE' // IndexedDB unavailable or operation called without a MemoryStore
14
+ | 'DISTILL_FAILED' // distillation pipeline threw an unexpected error
15
+ | 'UNKNOWN'; // unexpected error (original in .cause)
16
+
17
+ export class SSMError extends Error {
18
+ constructor(
19
+ public readonly code: SSMErrorCode,
20
+ message: string,
21
+ public readonly cause?: unknown,
22
+ ) {
23
+ super(message);
24
+ this.name = 'SSMError';
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ export { SSMError } from './SSMError.js';
2
+ export type { SSMErrorCode } from './SSMError.js';
package/src/index.ts ADDED
@@ -0,0 +1,128 @@
1
+ /**
2
+ * SSM.js – JavaScript-native AI runtime.
3
+ *
4
+ * Layer stack:
5
+ * MambaCode.js → WebGPU kernels (WGSL, Mamba-1/2/3 SSM math)
6
+ * SSM.js → Session layer + Runtime orchestration (this package)
7
+ *
8
+ * Quick start:
9
+ * import { SSM, AnthropicBridge } from 'ssmjs';
10
+ *
11
+ * const ai = await SSM.create({
12
+ * session : { modelSize: 'small' },
13
+ * bridge : new AnthropicBridge({ apiKey: '...' }),
14
+ * });
15
+ *
16
+ * await ai.adapt(myDocs);
17
+ * const answer = await ai.generate('How does MambaKit work?');
18
+ */
19
+
20
+ // ── Session layer ─────────────────────────────────────────────────────────────
21
+ export { MambaSession } from './session/index.js';
22
+ export { SessionError } from './session/index.js';
23
+ export { MODEL_PRESETS, resolveLayerSchedule, resolveModelConfig } from './session/index.js';
24
+
25
+ export type { SessionErrorCode } from './session/index.js';
26
+ export type { LayerSchedulePreset } from './session/index.js';
27
+ export type {
28
+ MambaSessionOptions,
29
+ CompleteOptions,
30
+ AdaptOptions,
31
+ AdaptResult,
32
+ SaveOptions,
33
+ LoadOptions,
34
+ StorageTarget,
35
+ CreateProgressEvent,
36
+ CreateStage,
37
+ CreateCallbacks,
38
+ SessionInternals,
39
+ GpuMode,
40
+ Tokenizer,
41
+ } from './session/index.js';
42
+
43
+ // ── Runtime ───────────────────────────────────────────────────────────────────
44
+ export { SSMRuntime } from './runtime/SSMRuntime.js';
45
+ export type { SSMRuntimeOptions, GenerateOptions } from './runtime/SSMRuntime.js';
46
+
47
+ // ── Bridges ───────────────────────────────────────────────────────────────────
48
+ export type { TransformerBridge, BridgeGenerateOptions } from './bridges/TransformerBridge.js';
49
+ export { OpenAIBridge } from './bridges/OpenAIBridge.js';
50
+ export { AnthropicBridge } from './bridges/AnthropicBridge.js';
51
+ export { FetchBridge } from './bridges/FetchBridge.js';
52
+ export { CachingBridge } from './bridges/CachingBridge.js';
53
+ export { SemanticCachingBridge } from './bridges/SemanticCachingBridge.js';
54
+ export { ResponseCache, buildCacheKey } from './bridges/ResponseCache.js';
55
+ export type { OpenAIBridgeOptions } from './bridges/OpenAIBridge.js';
56
+ export type { AnthropicBridgeOptions } from './bridges/AnthropicBridge.js';
57
+ export type { FetchBridgeOptions } from './bridges/FetchBridge.js';
58
+ export type { CachingBridgeOptions } from './bridges/CachingBridge.js';
59
+ export type { SemanticCachingBridgeOptions } from './bridges/SemanticCachingBridge.js';
60
+ export type { ResponseCacheOptions } from './bridges/ResponseCache.js';
61
+
62
+ // ── Semantic cache (embedding-keyed, L1 local + L2 shared) ─────────────────────
63
+ export { SemanticCache } from './cache/SemanticCache.js';
64
+ export { FetchSemanticCacheBackend } from './cache/FetchSemanticCacheBackend.js';
65
+ export type {
66
+ Embedder,
67
+ SemanticCacheBackend,
68
+ SemanticCacheHit,
69
+ SemanticCacheOptions,
70
+ FetchSemanticCacheBackendOptions,
71
+ } from './cache/index.js';
72
+
73
+ // ── Similarity primitives ──────────────────────────────────────────────────────
74
+ export { cosineSimilarity, jaccardSimilarity, tokenize } from './similarity/index.js';
75
+
76
+ // ── Router ────────────────────────────────────────────────────────────────────
77
+ export { InferenceRouter } from './router/InferenceRouter.js';
78
+ export type {
79
+ RoutingStrategy,
80
+ RoutingDecision,
81
+ RouterContext,
82
+ InferenceRouterOptions,
83
+ RoutingAuditEntry,
84
+ } from './router/InferenceRouter.js';
85
+
86
+ // ── Memory ────────────────────────────────────────────────────────────────────
87
+ export { MemoryStore } from './memory/MemoryStore.js';
88
+ export type {
89
+ MemoryEntry,
90
+ MemoryStoreOptions,
91
+ RememberOptions,
92
+ FactType,
93
+ } from './memory/MemoryStore.js';
94
+
95
+ // ── Distillation ──────────────────────────────────────────────────────────────
96
+ export { DistillationEngine } from './distillation/DistillationEngine.js';
97
+ export type {
98
+ DistillOptions,
99
+ DistillResult,
100
+ DistillBatchResult,
101
+ DistillationLog,
102
+ QualityGate,
103
+ } from './distillation/DistillationEngine.js';
104
+
105
+ // ── Agent ─────────────────────────────────────────────────────────────────────
106
+ export { SSMAgent } from './agent/SSMAgent.js';
107
+ export type { SSMAgentOptions, ThinkOptions, AgentMessage, MessageRole } from './agent/SSMAgent.js';
108
+
109
+ // ── Errors ────────────────────────────────────────────────────────────────────
110
+ export { SSMError } from './errors/SSMError.js';
111
+ export type { SSMErrorCode } from './errors/SSMError.js';
112
+
113
+ // ── Top-level SSM namespace ───────────────────────────────────────────────────
114
+ // Allows the `SSM.create()` pattern from the spec:
115
+ // const ai = await SSM.create({ session: { modelSize: 'nano' } });
116
+
117
+ import { SSMRuntime } from './runtime/SSMRuntime.js';
118
+ import type { SSMRuntimeOptions } from './runtime/SSMRuntime.js';
119
+
120
+ export const SSM = {
121
+ /**
122
+ * Creates a new SSMRuntime.
123
+ *
124
+ * Shorthand for `SSMRuntime.create(opts)`.
125
+ * Can throw `SessionError` for GPU / tokenizer failures during init.
126
+ */
127
+ create: (opts: SSMRuntimeOptions) => SSMRuntime.create(opts),
128
+ } as const;