@euconform/core 1.3.0 → 1.4.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.
@@ -132,7 +132,12 @@ export async function createAutoInferenceClient(preferredModel?: string): Promis
132
132
  }
133
133
 
134
134
  // Re-export types and utilities
135
- export { detectOllama, listOllamaModels, OllamaClient } from "./ollama-client";
135
+ export {
136
+ detectOllama,
137
+ listOllamaModels,
138
+ OllamaClient,
139
+ type CapabilityCache,
140
+ } from "./ollama-client";
136
141
  export { BrowserInference, checkWebGPU, BROWSER_MODELS } from "./browser-inference";
137
142
  export {
138
143
  InferenceFactory,
@@ -54,6 +54,12 @@ export interface OllamaLogProbsResponse extends OllamaGenerateResponse {
54
54
  }>;
55
55
  }
56
56
 
57
+ /** Abstraction for capability caching — localStorage in browser, file-based in CLI */
58
+ export interface CapabilityCache {
59
+ get(key: string): string | null;
60
+ set(key: string, value: string): void;
61
+ }
62
+
57
63
  const OLLAMA_BASE_URL = "http://localhost:11434";
58
64
 
59
65
  /**
@@ -217,11 +223,13 @@ export class OllamaClient {
217
223
  private baseUrl: string;
218
224
  public readonly model: string;
219
225
  private capabilityCache: Map<string, ModelCapabilityCache>;
226
+ private externalCache: CapabilityCache | null;
220
227
 
221
- constructor(model: string, baseUrl = OLLAMA_BASE_URL) {
228
+ constructor(model: string, baseUrl = OLLAMA_BASE_URL, cache?: CapabilityCache) {
222
229
  this.baseUrl = baseUrl;
223
230
  this.model = model;
224
231
  this.capabilityCache = new Map();
232
+ this.externalCache = cache ?? null;
225
233
  }
226
234
 
227
235
  private isCloudModel(): boolean {
@@ -344,33 +352,36 @@ export class OllamaClient {
344
352
  }
345
353
 
346
354
  /**
347
- * Get cached capability result from localStorage
355
+ * Get cached capability result from localStorage or external cache
348
356
  */
349
357
  private getCachedCapability(): ModelCapabilityCache | null {
350
358
  try {
351
359
  const cacheKey = `ollama_supports_logprobs_${this.model}`;
352
- const cached = localStorage.getItem(cacheKey);
360
+ let cached: string | null = null;
361
+
362
+ if (this.externalCache) {
363
+ cached = this.externalCache.get(cacheKey);
364
+ } else if (typeof localStorage !== "undefined") {
365
+ cached = localStorage.getItem(cacheKey);
366
+ }
353
367
 
354
368
  if (cached) {
355
369
  const capability: ModelCapabilityCache = JSON.parse(cached);
356
-
357
- // Check if cache is still valid (24 hours)
358
370
  const cacheAge = Date.now() - new Date(capability.testedAt).getTime();
359
- const maxAge = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
360
-
361
- if (cacheAge < maxAge) {
371
+ const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours
372
+ if (cacheAge < CACHE_TTL) {
362
373
  return capability;
363
374
  }
364
375
  }
365
- } catch (error) {
366
- console.warn("Failed to read capability cache:", error);
367
- }
368
376
 
369
- return null;
377
+ return null;
378
+ } catch {
379
+ return null;
380
+ }
370
381
  }
371
382
 
372
383
  /**
373
- * Cache capability result in localStorage
384
+ * Cache capability result in localStorage or external cache
374
385
  */
375
386
  private setCachedCapability(supports: boolean): void {
376
387
  try {
@@ -381,7 +392,12 @@ export class OllamaClient {
381
392
  testedAt: new Date().toISOString(),
382
393
  };
383
394
 
384
- localStorage.setItem(cacheKey, JSON.stringify(capability));
395
+ if (this.externalCache) {
396
+ this.externalCache.set(cacheKey, JSON.stringify(capability));
397
+ } else if (typeof localStorage !== "undefined") {
398
+ localStorage.setItem(cacheKey, JSON.stringify(capability));
399
+ }
400
+
385
401
  this.capabilityCache.set(this.model, capability);
386
402
  } catch (error) {
387
403
  console.warn("Failed to cache capability result:", error);
@@ -18,8 +18,8 @@ type JsonSchema = {
18
18
  };
19
19
 
20
20
  const ROOT = resolve(__dirname, "../../../..");
21
- const SCHEMAS_DIR = resolve(ROOT, "docs/ecef/schemas");
22
- const EXAMPLES_DIR = resolve(ROOT, "docs/ecef/examples");
21
+ const SCHEMAS_DIR = resolve(ROOT, "docs/spec/schemas");
22
+ const EXAMPLES_DIR = resolve(ROOT, "docs/spec/examples");
23
23
 
24
24
  function readJson<T>(path: string): T {
25
25
  return JSON.parse(readFileSync(path, "utf8")) as T;
@@ -168,7 +168,7 @@ const EXAMPLE_FILES = {
168
168
  bundle: "euconform.bundle.json",
169
169
  } as const;
170
170
 
171
- describe("ECEF schemas", () => {
171
+ describe("EuConform Evidence Format schemas", () => {
172
172
  const schemaEntries = Object.entries(SCHEMA_FILES).map(([kind, path]) => [
173
173
  kind,
174
174
  readJson<JsonSchema>(path),