@revealui/ai 0.10.1 → 1.0.1

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 (58) hide show
  1. package/README.md +10 -10
  2. package/dist/client/hooks/useAgentStream.d.ts +2 -0
  3. package/dist/client/hooks/useAgentStream.d.ts.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/llm/artifact-provenance.d.ts +73 -0
  8. package/dist/llm/artifact-provenance.d.ts.map +1 -0
  9. package/dist/llm/artifact-provenance.js +189 -0
  10. package/dist/llm/cache-utils.d.ts +0 -9
  11. package/dist/llm/cache-utils.d.ts.map +1 -1
  12. package/dist/llm/cache-utils.js +0 -17
  13. package/dist/llm/client.d.ts +16 -9
  14. package/dist/llm/client.d.ts.map +1 -1
  15. package/dist/llm/client.js +113 -61
  16. package/dist/llm/inference-route.d.ts +46 -0
  17. package/dist/llm/inference-route.d.ts.map +1 -0
  18. package/dist/llm/inference-route.js +154 -0
  19. package/dist/llm/local-ai-profile.d.ts.map +1 -1
  20. package/dist/llm/local-ai-profile.js +3 -3
  21. package/dist/llm/providers/groq.d.ts +1 -1
  22. package/dist/llm/providers/groq.d.ts.map +1 -1
  23. package/dist/llm/providers/groq.js +6 -3
  24. package/dist/llm/providers/inference-snaps.d.ts +6 -5
  25. package/dist/llm/providers/inference-snaps.d.ts.map +1 -1
  26. package/dist/llm/providers/inference-snaps.js +6 -5
  27. package/dist/llm/providers/ollama.d.ts +1 -1
  28. package/dist/llm/providers/ollama.d.ts.map +1 -1
  29. package/dist/llm/providers/ollama.js +3 -2
  30. package/dist/llm/providers/us-origin-snaps.d.ts +21 -11
  31. package/dist/llm/providers/us-origin-snaps.d.ts.map +1 -1
  32. package/dist/llm/providers/us-origin-snaps.js +23 -13
  33. package/dist/llm/resolve.d.ts.map +1 -1
  34. package/dist/llm/resolve.js +9 -2
  35. package/dist/llm/token-counter.d.ts.map +1 -1
  36. package/dist/llm/token-counter.js +4 -1
  37. package/dist/llm/tool-json-schema.d.ts +16 -0
  38. package/dist/llm/tool-json-schema.d.ts.map +1 -0
  39. package/dist/llm/tool-json-schema.js +64 -0
  40. package/dist/llm/workspace-provider-config.d.ts.map +1 -1
  41. package/dist/llm/workspace-provider-config.js +9 -2
  42. package/dist/orchestration/runtime.d.ts +3 -17
  43. package/dist/orchestration/runtime.d.ts.map +1 -1
  44. package/dist/orchestration/runtime.js +4 -15
  45. package/dist/orchestration/streaming-runtime.d.ts.map +1 -1
  46. package/dist/orchestration/streaming-runtime.js +2 -2
  47. package/dist/tools/admin/factory.d.ts +6 -0
  48. package/dist/tools/admin/factory.d.ts.map +1 -1
  49. package/dist/tools/admin/factory.js +6 -1
  50. package/dist/tools/admin/user-tools.js +2 -2
  51. package/dist/tools/mcp-adapter.d.ts +10 -94
  52. package/dist/tools/mcp-adapter.d.ts.map +1 -1
  53. package/dist/tools/mcp-adapter.js +10 -146
  54. package/dist/tools/mcp-sampling.d.ts +3 -3
  55. package/dist/tools/mcp-sampling.js +3 -3
  56. package/dist/tools/registry.d.ts.map +1 -1
  57. package/dist/tools/registry.js +2 -1
  58. package/package.json +29 -4
package/README.md CHANGED
@@ -54,9 +54,9 @@ rejected at provider construction. Operator escape (never seed):
54
54
  Quick setup:
55
55
 
56
56
  ```bash
57
- sudo snap install nemotron-3-nano # default; or gemma4 / nemotron-3-nano-omni
58
- nemotron-3-nano set http.port=9090
59
- nemotron-3-nano status # confirms base URL
57
+ sudo snap install gemma3 # default; or gemma4 / nemotron-3-nano
58
+ gemma3 set http.port=9090 --assume-yes
59
+ gemma3 status # confirms base URL
60
60
  ```
61
61
 
62
62
  ```typescript
@@ -66,7 +66,7 @@ const client = new LLMClient({
66
66
  provider: 'inference-snaps',
67
67
  apiKey: 'inference-snaps',
68
68
  baseURL: 'http://localhost:9090/v1',
69
- model: 'nemotron-3-nano', // default when omitted
69
+ model: 'gemma3', // default when omitted
70
70
  })
71
71
 
72
72
  // Or the provider alone:
@@ -201,7 +201,7 @@ import { InferenceSnapsProvider, createSamplingHandler } from '@revealui/ai'
201
201
 
202
202
  const llm = new InferenceSnapsProvider({
203
203
  baseURL: 'http://localhost:9090/v1',
204
- model: 'nemotron-3-nano',
204
+ model: 'gemma3',
205
205
  })
206
206
 
207
207
  const client = new McpClient({
@@ -209,9 +209,9 @@ const client = new McpClient({
209
209
  transport: { kind: 'streamable-http', url: 'https://example.com/mcp' },
210
210
  samplingHandler: createSamplingHandler({
211
211
  llm,
212
- defaultModel: 'nemotron-3-nano',
212
+ defaultModel: 'gemma3',
213
213
  // Keep sampling hints on the US-origin allowlist (provider also enforces).
214
- allowedModels: ['nemotron-3-nano', 'gemma4', 'gemma3'],
214
+ allowedModels: ['gemma3', 'gemma4', 'nemotron-3-nano'],
215
215
  onSamplingRequest: (info) => {
216
216
  // metering / audit trail
217
217
  metrics.incr('mcp.sampling', { model: info.model })
@@ -231,9 +231,9 @@ parts extension. `stopSequences` aren't forwarded to the LLM yet (the
231
231
  current `LLMChatOptions` doesn't expose that field); this is advisory per
232
232
  spec, so omission is compliant.
233
233
 
234
- The legacy `mcpToolSource` path (hypervisor-backed) still works and is
235
- kept for backwards compatibility, but new integrations should prefer the
236
- `mcpClients` path.
234
+ Mount MCP tools with `createToolsFromMcpClient` / `AgentRuntime.mcpClients`.
235
+ Process-local spawn and tenant scoping stay on `MCPHypervisor` in
236
+ `@revealui/mcp` — connect those processes with a real `McpClient`.
237
237
 
238
238
  ## Installation
239
239
 
@@ -68,6 +68,8 @@ export interface AgentStreamRequest {
68
68
  * request schema.
69
69
  */
70
70
  mode?: 'admin' | 'coding';
71
+ /** Built-in agent id. Scopes admin tools on /api/agent-stream. */
72
+ agentId?: string;
71
73
  }
72
74
  /**
73
75
  * Outstanding elicitation request awaiting a UI response. The hook keeps
@@ -1 +1 @@
1
- {"version":3,"file":"useAgentStream.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useAgentStream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kB,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAWD,wBAAgB,cAAc,IAAI,oBAAoB,CAwIrD;AAED;;;;;;GAMG;AACH,iBAAS,UAAU,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CA8CxF;AAMD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,mBAAa,CAAC;AAChD,eAAO,MAAM,uBAAuB,EAAE,mBAAmC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -54,6 +54,7 @@ export * from './a2a/index.js';
54
54
  export * from './audit/index.js';
55
55
  export * from './embeddings/index.js';
56
56
  export * from './ingestion/index.js';
57
+ export * from './llm/artifact-provenance.js';
57
58
  export * from './llm/client.js';
58
59
  export * from './llm/local-ai-profile.js';
59
60
  export * from './llm/provider-health.js';
@@ -63,6 +64,7 @@ export * from './llm/providers/openai-compat.js';
63
64
  export * from './llm/providers/us-origin-snaps.js';
64
65
  export * from './llm/resolve.js';
65
66
  export * from './llm/token-counter.js';
67
+ export { sanitizeProviderToolSchema, toolParametersToJsonSchema } from './llm/tool-json-schema.js';
66
68
  export * from './llm/workspace-provider-config.js';
67
69
  export * from './memory/index.js';
68
70
  export * from './orchestration/agent.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAGH,cAAc,gBAAgB,CAAC;AAE/B,cAAc,kBAAkB,CAAC;AAIjC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,sBAAsB,CAAC;AAErC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD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0B,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACnG,cAAc,oCAAoC,CAAC;AAEnD,cAAc,mBAAmB,CAAC;AAElC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,iCAAiC,CAAC;AAEhD,cAAc,mBAAmB,CAAC;AAElC,cAAc,sBAAsB,CAAC;AAErC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ export * from './audit/index.js';
60
60
  export * from './embeddings/index.js';
61
61
  // Re-export ingestion pipeline (RAG document indexing + hybrid search)
62
62
  export * from './ingestion/index.js';
63
+ export * from './llm/artifact-provenance.js';
63
64
  // Re-export LLM providers and client
64
65
  export * from './llm/client.js';
65
66
  export * from './llm/local-ai-profile.js';
@@ -70,6 +71,7 @@ export * from './llm/providers/openai-compat.js';
70
71
  export * from './llm/providers/us-origin-snaps.js';
71
72
  export * from './llm/resolve.js';
72
73
  export * from './llm/token-counter.js';
74
+ export { sanitizeProviderToolSchema, toolParametersToJsonSchema } from './llm/tool-json-schema.js';
73
75
  export * from './llm/workspace-provider-config.js';
74
76
  // Re-export memory system
75
77
  export * from './memory/index.js';
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Model/data artifact C-SCRM door (GAP-484).
3
+ *
4
+ * NIST C-SCRM + AI 100-2 (Vassilev, SSCA 2024): hash + URL provenance, refuse
5
+ * pickle-class deserialize-to-ACE formats. Do not scan weights for behavior.
6
+ *
7
+ * This is the only supported fetch path for fleet-fetched weight artifacts.
8
+ * Inference Snaps stay on the US-origin snap allowlist (us-origin-snaps.ts).
9
+ * Snap store / Ollama registry names are not weight files.
10
+ */
11
+ /** Formats that deserialize to arbitrary code (pickle protocol family). */
12
+ export declare const ACE_MODEL_SUFFIXES: readonly [".pickle", ".pkl", ".joblib", ".dill", ".pth", ".pt", ".ckpt", ".bin"];
13
+ /** Formats that do not use pickle deserialize. */
14
+ export declare const SAFE_MODEL_SUFFIXES: readonly [".safetensors", ".gguf", ".onnx"];
15
+ export declare class AceModelArtifactError extends Error {
16
+ readonly code: "ACE_MODEL_ARTIFACT";
17
+ readonly filename: string;
18
+ constructor(filename: string);
19
+ }
20
+ export declare class ArtifactProvenanceError extends Error {
21
+ readonly code: "ARTIFACT_PROVENANCE";
22
+ constructor(message: string);
23
+ }
24
+ export declare class ArtifactHashMismatchError extends Error {
25
+ readonly code: "ARTIFACT_HASH_MISMATCH";
26
+ readonly expected: string;
27
+ readonly actual: string;
28
+ constructor(expected: string, actual: string);
29
+ }
30
+ export interface ArtifactProvenance {
31
+ readonly url: string;
32
+ readonly sha256: string;
33
+ readonly filename: string;
34
+ }
35
+ /** True when the path looks like a pickle-class deserialize format. */
36
+ export declare function isAceDeserializeArtifact(name: string): boolean;
37
+ /** True when the path is an allowlisted non-pickle weight format. */
38
+ export declare function isSafeModelArtifactName(name: string): boolean;
39
+ /**
40
+ * Refuse pickle-class filenames. Allow only safetensors / gguf / onnx.
41
+ */
42
+ export declare function assertSafeModelArtifactName(name: string): string;
43
+ /**
44
+ * Validate URL + sha256 + safe filename. Does not fetch and does not scan weights.
45
+ */
46
+ export declare function assertArtifactProvenance(spec: {
47
+ readonly url: string;
48
+ readonly sha256: string;
49
+ readonly filename?: string;
50
+ }): ArtifactProvenance;
51
+ export declare function sha256Hex(bytes: Uint8Array): string;
52
+ /** Integrity check only. Not a capability or safety scan of the weights. */
53
+ export declare function verifyBytesSha256(bytes: Uint8Array, expectedHex: string): void;
54
+ export interface FetchProvenancedArtifactOptions {
55
+ readonly fetch?: typeof fetch;
56
+ }
57
+ /**
58
+ * The fleet fetch door for weight artifacts: URL + sha256, then hash-verify.
59
+ * Fails closed on ACE formats, bad URLs, missing hash, or mismatch.
60
+ */
61
+ export declare function fetchProvenancedArtifact(spec: {
62
+ readonly url: string;
63
+ readonly sha256: string;
64
+ readonly filename?: string;
65
+ }, options?: FetchProvenancedArtifactOptions): Promise<Uint8Array>;
66
+ /**
67
+ * Ollama pull refs are registry names (`gemma3:latest`), not files.
68
+ * Refuse refs that look like local pickle/ACE paths.
69
+ */
70
+ export declare function assertOllamaPullRef(modelName: string): string;
71
+ /** Snap install names stay on the US-origin product allowlist. */
72
+ export declare function assertSnapInstallName(snapName: string): string;
73
+ //# sourceMappingURL=artifact-provenance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-provenance.d.ts","sourceRoot":"","sources":["../../src/llm/artifact-provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,kFASrB,CAAC;AAEX,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,6CAA8C,CAAC;AAE/E,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAG,oBAAoB,CAAU;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM;CAS7B;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAG,qBAAqB,CAAU;gBAEnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,IAAI,EAAG,wBAAwB,CAAU;IAClD,QAAQ,CAAC,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AA+B,GACxC,OAAO,CAAC,UAAU,CAAC,CAerB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAY7D;AAED,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE9D"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Model/data artifact C-SCRM door (GAP-484).
3
+ *
4
+ * NIST C-SCRM + AI 100-2 (Vassilev, SSCA 2024): hash + URL provenance, refuse
5
+ * pickle-class deserialize-to-ACE formats. Do not scan weights for behavior.
6
+ *
7
+ * This is the only supported fetch path for fleet-fetched weight artifacts.
8
+ * Inference Snaps stay on the US-origin snap allowlist (us-origin-snaps.ts).
9
+ * Snap store / Ollama registry names are not weight files.
10
+ */
11
+ import { createHash } from 'node:crypto';
12
+ import { assertUsOriginInferenceSnap } from './providers/us-origin-snaps.js';
13
+ /** Formats that deserialize to arbitrary code (pickle protocol family). */
14
+ export const ACE_MODEL_SUFFIXES = [
15
+ '.pickle',
16
+ '.pkl',
17
+ '.joblib',
18
+ '.dill',
19
+ '.pth',
20
+ '.pt',
21
+ '.ckpt',
22
+ '.bin',
23
+ ];
24
+ /** Formats that do not use pickle deserialize. */
25
+ export const SAFE_MODEL_SUFFIXES = ['.safetensors', '.gguf', '.onnx'];
26
+ export class AceModelArtifactError extends Error {
27
+ code = 'ACE_MODEL_ARTIFACT';
28
+ filename;
29
+ constructor(filename) {
30
+ super(`Refusing model artifact "${filename}": pickle-class formats can deserialize ` +
31
+ 'to arbitrary code (NIST AI 100-2 / GAP-484). Use .safetensors, .gguf, or .onnx. ' +
32
+ 'We do not scan weights for behavior.');
33
+ this.name = 'AceModelArtifactError';
34
+ this.filename = filename;
35
+ }
36
+ }
37
+ export class ArtifactProvenanceError extends Error {
38
+ code = 'ARTIFACT_PROVENANCE';
39
+ constructor(message) {
40
+ super(message);
41
+ this.name = 'ArtifactProvenanceError';
42
+ }
43
+ }
44
+ export class ArtifactHashMismatchError extends Error {
45
+ code = 'ARTIFACT_HASH_MISMATCH';
46
+ expected;
47
+ actual;
48
+ constructor(expected, actual) {
49
+ super(`Artifact sha256 mismatch (GAP-484). expected=${expected} actual=${actual}. ` +
50
+ 'This is an integrity check, not a capability scan of the weights.');
51
+ this.name = 'ArtifactHashMismatchError';
52
+ this.expected = expected;
53
+ this.actual = actual;
54
+ }
55
+ }
56
+ function lastPathSegment(value) {
57
+ const trimmed = value.trim();
58
+ const slash = trimmed.lastIndexOf('/');
59
+ const raw = slash === -1 ? trimmed : trimmed.slice(slash + 1);
60
+ const query = raw.indexOf('?');
61
+ return query === -1 ? raw : raw.slice(0, query);
62
+ }
63
+ function lowerName(value) {
64
+ return lastPathSegment(value).toLowerCase();
65
+ }
66
+ function hasSuffix(name, suffix) {
67
+ return name.length > suffix.length && name.endsWith(suffix);
68
+ }
69
+ /** True when the path looks like a pickle-class deserialize format. */
70
+ export function isAceDeserializeArtifact(name) {
71
+ const n = lowerName(name);
72
+ return ACE_MODEL_SUFFIXES.some((suffix) => hasSuffix(n, suffix));
73
+ }
74
+ /** True when the path is an allowlisted non-pickle weight format. */
75
+ export function isSafeModelArtifactName(name) {
76
+ const n = lowerName(name);
77
+ if (n.length === 0)
78
+ return false;
79
+ return SAFE_MODEL_SUFFIXES.some((suffix) => hasSuffix(n, suffix));
80
+ }
81
+ /**
82
+ * Refuse pickle-class filenames. Allow only safetensors / gguf / onnx.
83
+ */
84
+ export function assertSafeModelArtifactName(name) {
85
+ const filename = lastPathSegment(name);
86
+ if (filename.length === 0) {
87
+ throw new AceModelArtifactError(name);
88
+ }
89
+ if (isAceDeserializeArtifact(filename) || !isSafeModelArtifactName(filename)) {
90
+ throw new AceModelArtifactError(filename);
91
+ }
92
+ return filename;
93
+ }
94
+ function isSha256Hex(value) {
95
+ if (value.length !== 64)
96
+ return false;
97
+ for (let i = 0; i < value.length; i++) {
98
+ const c = value.charCodeAt(i);
99
+ const isDigit = c >= 48 && c <= 57;
100
+ const isAf = c >= 97 && c <= 102;
101
+ const isAF = c >= 65 && c <= 70;
102
+ if (!(isDigit || isAf || isAF))
103
+ return false;
104
+ }
105
+ return true;
106
+ }
107
+ function isAllowedProvenanceUrl(url) {
108
+ if (url.protocol === 'https:')
109
+ return true;
110
+ if (url.protocol !== 'http:')
111
+ return false;
112
+ const host = url.hostname.toLowerCase();
113
+ return host === 'localhost' || host === '127.0.0.1';
114
+ }
115
+ /**
116
+ * Validate URL + sha256 + safe filename. Does not fetch and does not scan weights.
117
+ */
118
+ export function assertArtifactProvenance(spec) {
119
+ let parsed;
120
+ try {
121
+ parsed = new URL(spec.url);
122
+ }
123
+ catch {
124
+ throw new ArtifactProvenanceError(`Invalid artifact URL: ${spec.url}`);
125
+ }
126
+ if (!isAllowedProvenanceUrl(parsed)) {
127
+ throw new ArtifactProvenanceError(`Artifact URL must be https (or http localhost for operator/dev): ${spec.url}`);
128
+ }
129
+ if (!isSha256Hex(spec.sha256)) {
130
+ throw new ArtifactProvenanceError('Artifact sha256 must be 64 hex characters (GAP-484).');
131
+ }
132
+ const filename = assertSafeModelArtifactName(spec.filename ?? lastPathSegment(parsed.pathname));
133
+ return {
134
+ url: parsed.href,
135
+ sha256: spec.sha256.toLowerCase(),
136
+ filename,
137
+ };
138
+ }
139
+ export function sha256Hex(bytes) {
140
+ return createHash('sha256').update(bytes).digest('hex');
141
+ }
142
+ /** Integrity check only. Not a capability or safety scan of the weights. */
143
+ export function verifyBytesSha256(bytes, expectedHex) {
144
+ if (!isSha256Hex(expectedHex)) {
145
+ throw new ArtifactProvenanceError('Artifact sha256 must be 64 hex characters (GAP-484).');
146
+ }
147
+ const actual = sha256Hex(bytes);
148
+ const expected = expectedHex.toLowerCase();
149
+ if (actual !== expected) {
150
+ throw new ArtifactHashMismatchError(expected, actual);
151
+ }
152
+ }
153
+ /**
154
+ * The fleet fetch door for weight artifacts: URL + sha256, then hash-verify.
155
+ * Fails closed on ACE formats, bad URLs, missing hash, or mismatch.
156
+ */
157
+ export async function fetchProvenancedArtifact(spec, options) {
158
+ const provenanced = assertArtifactProvenance(spec);
159
+ const fetchImpl = options?.fetch ?? globalThis.fetch;
160
+ if (typeof fetchImpl !== 'function') {
161
+ throw new ArtifactProvenanceError('fetch is not available');
162
+ }
163
+ const response = await fetchImpl(provenanced.url);
164
+ if (!response.ok) {
165
+ throw new ArtifactProvenanceError(`Artifact fetch failed: ${response.status} ${response.statusText}`);
166
+ }
167
+ const bytes = new Uint8Array(await response.arrayBuffer());
168
+ verifyBytesSha256(bytes, provenanced.sha256);
169
+ return bytes;
170
+ }
171
+ /**
172
+ * Ollama pull refs are registry names (`gemma3:latest`), not files.
173
+ * Refuse refs that look like local pickle/ACE paths.
174
+ */
175
+ export function assertOllamaPullRef(modelName) {
176
+ const name = modelName.trim();
177
+ if (name.length === 0) {
178
+ throw new ArtifactProvenanceError('Ollama pull ref is empty');
179
+ }
180
+ if (isAceDeserializeArtifact(name) || isSafeModelArtifactName(name)) {
181
+ throw new ArtifactProvenanceError(`Ollama pull ref "${name}" looks like a weight file. Pull a registry name, ` +
182
+ 'not a pickle or local artifact path (GAP-484).');
183
+ }
184
+ return name;
185
+ }
186
+ /** Snap install names stay on the US-origin product allowlist. */
187
+ export function assertSnapInstallName(snapName) {
188
+ return assertUsOriginInferenceSnap(snapName);
189
+ }
@@ -91,15 +91,6 @@ export declare function createCachedConversation(config: {
91
91
  contextDocs?: string[];
92
92
  messages: Message[];
93
93
  }): Message[];
94
- /**
95
- * @deprecated Use `MODEL_PRICING` from `./token-counter.js`. Retained as a thin derived
96
- * view (the Anthropic-with-cache subset) so existing importers keep one source of truth.
97
- */
98
- export declare const ANTHROPIC_PRICING: {
99
- readonly 'claude-3-5-sonnet-20241022': import("./token-counter.js").ModelPricing;
100
- readonly 'claude-3-5-haiku-20241022': import("./token-counter.js").ModelPricing;
101
- readonly 'claude-3-opus-20240229': import("./token-counter.js").ModelPricing;
102
- };
103
94
  /**
104
95
  * Calculate actual cost of a request with caching, using the unified MODEL_PRICING table.
105
96
  * Unknown models price at zero (matching `estimateCost`).
@@ -1 +1 @@
1
- {"version":3,"file":"cache-utils.d.ts","sourceRoot":"","sources":["../../src/llm/cache-utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAKnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAK9D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,qBAAqB,EAAE,MAAM,GAC5B,MAAM,CAeR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,GAAG,IAAI,CAqBhB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,OAAO,CAItE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,GAAG,OAAO,EAAE,CAwBZ;AAWD;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;CAIpB,CAAC;AAEX;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,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C;CACrB,GAAG,OAAO,EAAE,CAwBZ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA6BxE"}
@@ -127,23 +127,6 @@ export function createCachedConversation(config) {
127
127
  result.push(...config.messages);
128
128
  return result;
129
129
  }
130
- /** Look up a model's pricing, asserting presence (used only for known-present keys). */
131
- function requirePricing(model) {
132
- const pricing = MODEL_PRICING[model];
133
- if (!pricing) {
134
- throw new Error(`No pricing entry for model: ${model}`);
135
- }
136
- return pricing;
137
- }
138
- /**
139
- * @deprecated Use `MODEL_PRICING` from `./token-counter.js`. Retained as a thin derived
140
- * view (the Anthropic-with-cache subset) so existing importers keep one source of truth.
141
- */
142
- export const ANTHROPIC_PRICING = {
143
- 'claude-3-5-sonnet-20241022': requirePricing('claude-3-5-sonnet-20241022'),
144
- 'claude-3-5-haiku-20241022': requirePricing('claude-3-5-haiku-20241022'),
145
- 'claude-3-opus-20240229': requirePricing('claude-3-opus-20240229'),
146
- };
147
130
  /**
148
131
  * Calculate actual cost of a request with caching, using the unified MODEL_PRICING table.
149
132
  * Unknown models price at zero (matching `estimateCost`).
@@ -6,11 +6,13 @@
6
6
  import type { Database } from '@revealui/db/client';
7
7
  import { CircuitBreaker } from '@revealui/resilience';
8
8
  import type { AuditStore } from '../audit/store.js';
9
+ import { type LLMProviderType } from './inference-route.js';
9
10
  import type { ProviderHealthMonitor } from './provider-health.js';
10
11
  import type { Embedding, LLMChatOptions, LLMChunk, LLMEmbedOptions, LLMProvider, LLMResponse, LLMStreamOptions, Message } from './providers/base.js';
11
12
  import { type CacheStats, type ResponseCacheOptions } from './response-cache.js';
12
- import { type SemanticCacheOptions, type SemanticCacheStats } from './semantic-cache.js';
13
- export type LLMProviderType = 'anthropic' | 'openai' | 'groq' | 'huggingface' | 'ollama' | 'inference-snaps' | 'xai';
13
+ import type { SemanticCacheOptions, SemanticCacheStats } from './semantic-cache.js';
14
+ export type { InferenceRoute, InferenceRouteInput, LLMProviderType } from './inference-route.js';
15
+ export { defaultBaseURLForProvider, defaultModelForProvider, GROQ_DEFAULT_BASE_URL, GROQ_DEFAULT_MODEL, groqAcceptedModel, isGroqCatalogModel, resolveInferenceRoute, resolveModelForProvider, } from './inference-route.js';
14
16
  /**
15
17
  * Providers reachable from a hosted (serverless) deployment. Localhost-only
16
18
  * providers are false. Consumed by PR-2/PR-3 (resolver + settings UI) to pick
@@ -68,6 +70,7 @@ export declare class LLMClient {
68
70
  private rateLimitState;
69
71
  private responseCache?;
70
72
  private semanticCache?;
73
+ private semanticCacheLoading?;
71
74
  private healthMonitor?;
72
75
  private circuitBreaker;
73
76
  private fallbackCircuitBreaker?;
@@ -82,6 +85,7 @@ export declare class LLMClient {
82
85
  private refreshProviderIfNeeded;
83
86
  private checkRateLimit;
84
87
  private recordRequest;
88
+ private ensureSemanticCache;
85
89
  chat(messages: Message[], options?: LLMChatOptions): Promise<LLMResponse>;
86
90
  embed(text: string | string[], options?: LLMEmbedOptions): Promise<Embedding | Embedding[]>;
87
91
  stream(messages: Message[], options?: LLMStreamOptions): AsyncIterable<LLMChunk>;
@@ -147,13 +151,13 @@ export declare class LLMClient {
147
151
  *
148
152
  * Canonical Inference Snaps is the reference local provider on Ubuntu — offline,
149
153
  * silicon-optimized, no API key required. Product usage is **US-origin snaps
150
- * only** (nemotron-3-nano default; gemma3/4 also allowlisted). See
154
+ * only** (gemma3 default; gemma4 and nemotron also allowlisted). See
151
155
  * `providers/us-origin-snaps.ts` and `providers/inference-snaps.ts`.
152
156
  *
153
157
  * Provider defaults:
154
- * inference-snaps → nemotron-3-nano (base URL defaults to http://localhost:9090/v1)
155
- * groq → qwen/qwen3-32b
156
- * ollama → gemma4:e2b (base URL defaults to http://localhost:11434)
158
+ * inference-snaps → gemma3 (base URL defaults to http://localhost:9090/v1)
159
+ * groq → openai/gpt-oss-120b (Groq-accepted default; retired llama ids remap)
160
+ * ollama → DEFAULT_DAILY_OLLAMA_MODEL (qwen2.5:3b; base URL http://localhost:11434)
157
161
  * anthropic → claude-sonnet-4-6 (base URL defaults to https://api.anthropic.com/v1)
158
162
  * openai → gpt-4o (base URL defaults to https://api.openai.com/v1)
159
163
  * xai → grok-4.5 (base URL defaults to https://api.x.ai/v1)
@@ -162,9 +166,12 @@ export declare function createLLMClientFromEnv(): LLMClient;
162
166
  /**
163
167
  * Create an LLM client using a user's stored BYOK API key.
164
168
  *
165
- * Looks up the user's preferred provider from `tenant_provider_configs`
166
- * (falling back to the first key in `user_api_keys`), decrypts the key
167
- * with AES-256-GCM, and returns a configured LLMClient.
169
+ * Looks up the user's preferred provider from `tenant_provider_configs`.
170
+ * If that provider has no saved key, uses another saved key (hosted-viable
171
+ * when `opts.hostedViableOnly` is set — e.g. a saved Groq key). Decrypts
172
+ * with AES-256-GCM and returns a configured LLMClient whose model and
173
+ * base URL match the **key's** provider, never a stale preferred-provider
174
+ * model (a Groq id must not be sent to OpenAI).
168
175
  *
169
176
  * Returns `null` if the user has no stored keys (callers should fall back
170
177
  * to `createLLMClientFromEnv()` or return a 402/feature-unavailable error).
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/llm/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EACL,cAAc,EAGf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CA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