@happyvertical/smrt-inference 0.0.0-stage → 0.60.15

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 (107) hide show
  1. package/AGENTS.md +201 -0
  2. package/CLAUDE.md +1 -0
  3. package/LICENSE +7 -0
  4. package/README.md +73 -2
  5. package/agents/fusions.md +92 -0
  6. package/agents/hosted.md +145 -0
  7. package/agents/resolver.md +65 -0
  8. package/agents/settings.md +84 -0
  9. package/dist/__smrt-register__.d.ts +2 -0
  10. package/dist/__smrt-register__.d.ts.map +1 -0
  11. package/dist/chunks/InferenceOverrideCollection-wl7sI-3C.js +398 -0
  12. package/dist/chunks/InferenceOverrideCollection-wl7sI-3C.js.map +1 -0
  13. package/dist/chunks/provider-config-4Bx8N52X.js +1847 -0
  14. package/dist/chunks/provider-config-4Bx8N52X.js.map +1 -0
  15. package/dist/classify.d.ts +32 -0
  16. package/dist/classify.d.ts.map +1 -0
  17. package/dist/config.d.ts +89 -0
  18. package/dist/config.d.ts.map +1 -0
  19. package/dist/errors.d.ts +51 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/executor.d.ts +45 -0
  22. package/dist/executor.d.ts.map +1 -0
  23. package/dist/fusion-store.d.ts +16 -0
  24. package/dist/fusion-store.d.ts.map +1 -0
  25. package/dist/fusion.d.ts +155 -0
  26. package/dist/fusion.d.ts.map +1 -0
  27. package/dist/gate.d.ts +143 -0
  28. package/dist/gate.d.ts.map +1 -0
  29. package/dist/gate.js +94 -0
  30. package/dist/gate.js.map +1 -0
  31. package/dist/hosted.d.ts +454 -0
  32. package/dist/hosted.d.ts.map +1 -0
  33. package/dist/index.d.ts +9 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +8 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/manifest.json +453 -0
  38. package/dist/models/InferenceOverride.d.ts +38 -0
  39. package/dist/models/InferenceOverride.d.ts.map +1 -0
  40. package/dist/models/InferenceOverrideCollection.d.ts +35 -0
  41. package/dist/models/InferenceOverrideCollection.d.ts.map +1 -0
  42. package/dist/models.d.ts +11 -0
  43. package/dist/models.d.ts.map +1 -0
  44. package/dist/models.js +2 -0
  45. package/dist/node.d.ts +110 -0
  46. package/dist/node.d.ts.map +1 -0
  47. package/dist/node.js +1361 -0
  48. package/dist/node.js.map +1 -0
  49. package/dist/provider-config.d.ts +113 -0
  50. package/dist/provider-config.d.ts.map +1 -0
  51. package/dist/register.d.ts +30 -0
  52. package/dist/register.d.ts.map +1 -0
  53. package/dist/resolver.d.ts +166 -0
  54. package/dist/resolver.d.ts.map +1 -0
  55. package/dist/resolver.js +288 -0
  56. package/dist/resolver.js.map +1 -0
  57. package/dist/server.d.ts +24 -0
  58. package/dist/server.d.ts.map +1 -0
  59. package/dist/server.js +985 -0
  60. package/dist/server.js.map +1 -0
  61. package/dist/settings/cache.d.ts +5 -0
  62. package/dist/settings/cache.d.ts.map +1 -0
  63. package/dist/settings/keys.d.ts +70 -0
  64. package/dist/settings/keys.d.ts.map +1 -0
  65. package/dist/settings/layers.d.ts +54 -0
  66. package/dist/settings/layers.d.ts.map +1 -0
  67. package/dist/settings/override-service.d.ts +119 -0
  68. package/dist/settings/override-service.d.ts.map +1 -0
  69. package/dist/settings/preferences.d.ts +137 -0
  70. package/dist/settings/preferences.d.ts.map +1 -0
  71. package/dist/settings/resolver.d.ts +34 -0
  72. package/dist/settings/resolver.d.ts.map +1 -0
  73. package/dist/settings/settings-service.d.ts +282 -0
  74. package/dist/settings/settings-service.d.ts.map +1 -0
  75. package/dist/settings/targets.d.ts +93 -0
  76. package/dist/settings/targets.d.ts.map +1 -0
  77. package/dist/smrt-knowledge.json +335 -0
  78. package/dist/smrt-knowledge.okf.md +80 -0
  79. package/dist/svelte/components/InferenceAliasEditor.svelte +210 -0
  80. package/dist/svelte/components/InferenceAliasEditor.svelte.d.ts +13 -0
  81. package/dist/svelte/components/InferenceAliasEditor.svelte.d.ts.map +1 -0
  82. package/dist/svelte/components/InferenceDefaultView.svelte +330 -0
  83. package/dist/svelte/components/InferenceDefaultView.svelte.d.ts +15 -0
  84. package/dist/svelte/components/InferenceDefaultView.svelte.d.ts.map +1 -0
  85. package/dist/svelte/components/InferenceFusionList.svelte +135 -0
  86. package/dist/svelte/components/InferenceFusionList.svelte.d.ts +16 -0
  87. package/dist/svelte/components/InferenceFusionList.svelte.d.ts.map +1 -0
  88. package/dist/svelte/components/InferenceSettingsPanel.svelte +345 -0
  89. package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts +65 -0
  90. package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts.map +1 -0
  91. package/dist/svelte/components/InferenceTierRow.svelte +199 -0
  92. package/dist/svelte/components/InferenceTierRow.svelte.d.ts +14 -0
  93. package/dist/svelte/components/InferenceTierRow.svelte.d.ts.map +1 -0
  94. package/dist/svelte/components/InferenceUsageTable.svelte +127 -0
  95. package/dist/svelte/components/InferenceUsageTable.svelte.d.ts +15 -0
  96. package/dist/svelte/components/InferenceUsageTable.svelte.d.ts.map +1 -0
  97. package/dist/svelte/index.d.ts +17 -0
  98. package/dist/svelte/index.d.ts.map +1 -0
  99. package/dist/svelte/index.js +14 -0
  100. package/dist/svelte/types.d.ts +197 -0
  101. package/dist/svelte/types.d.ts.map +1 -0
  102. package/dist/svelte/types.js +96 -0
  103. package/dist/types.d.ts +47 -0
  104. package/dist/types.d.ts.map +1 -0
  105. package/dist/types.js +13 -0
  106. package/dist/types.js.map +1 -0
  107. package/package.json +105 -3
@@ -0,0 +1,454 @@
1
+ /**
2
+ * Hosted inference provisioning (#4759), Node-only (`./node`).
3
+ *
4
+ * When a member gains `inference.hosted`, SMRT mints them a per-user virtual
5
+ * key on the operator's AI gateway (`bifrost` or `litellm`, through the
6
+ * `ai.admin` surface of `@happyvertical/ai`; SMRT never talks to a gateway's
7
+ * admin API itself) and stores it where the BYO path already looks: the
8
+ * user's `inference.provider-config` secret (#4756) with `source: 'hosted'`
9
+ * and `mode: 'hosted'` (#4757). Switching to hosted therefore changes only
10
+ * the stored provider config.
11
+ *
12
+ * Storage (all smrt-secrets rows under `context = tenantId`, every write and
13
+ * delete audited through `SecretAuditLog` with an `operation` detail):
14
+ * - `inference.provider-config:user:<userId>`: the hosted binding (holds the
15
+ * virtual key; the only place it lives).
16
+ * - `inference.hosted:user:<userId>`: provisioning state: status, lifecycle
17
+ * generation, the key's non-secret id and alias, the budget, and the
18
+ * user's prior provider config (restored on revoke).
19
+ * - `inference.hosted:project`: the tenant's gateway project id.
20
+ *
21
+ * Idempotency: provisioning runs under `runOnce()` per `(tenantId, userId,
22
+ * generation)`, so concurrent deliveries create one key; the generation
23
+ * advances on every revoke, so a later re-provision runs again. Lifecycle
24
+ * operations run one at a time per process and, on PostgreSQL, under a
25
+ * per-tenant advisory lock across processes. A revoke ends local
26
+ * use of the key whatever the gateway answers; deletions the gateway could
27
+ * not perform are kept as `pendingGatewayRevocations` and retried by
28
+ * `revoke()` / `reconcileTenant()`.
29
+ *
30
+ * The key never appears in returned objects, errors, logs, usage tags,
31
+ * audit details or `runOnce()` results: usage rows carry `source: hosted`
32
+ * and the key's alias (`gatewayKeyAlias`) only.
33
+ */
34
+ import type { AIAdminBudget, AIAdminInterface, AIVirtualKey } from '@happyvertical/ai';
35
+ import { type InferenceTier } from '@happyvertical/smrt-core';
36
+ import { SmrtError } from '@happyvertical/smrt-core/smrt-error';
37
+ import type { DatabaseInterface } from '@happyvertical/sql';
38
+ import { type InferenceProviderConfig } from './provider-config.js';
39
+ /** The feature key that entitles hosted inference (`smrt-features`' `FEATURE_INFERENCE_HOSTED`). */
40
+ export declare const HOSTED_INFERENCE_FEATURE_KEY = "inference.hosted";
41
+ /** smrt-secrets category of the hosted state and project rows. */
42
+ export declare const HOSTED_INFERENCE_SECRET_CATEGORY = "inference.hosted";
43
+ /** Gateway providers of `@happyvertical/ai` that expose `ai.admin`. */
44
+ export declare const HOSTED_GATEWAY_PROVIDERS: readonly ["bifrost", "litellm"];
45
+ export type HostedGatewayProvider = (typeof HOSTED_GATEWAY_PROVIDERS)[number];
46
+ /** Budget reset windows; mapped to the gateway's reset duration. */
47
+ export declare const HOSTED_BUDGET_WINDOWS: readonly ["day", "week", "month", "year"];
48
+ export type HostedBudgetWindow = (typeof HOSTED_BUDGET_WINDOWS)[number];
49
+ /**
50
+ * A hosted user's spend cap. Money is an integer: micro-dollars (USD ×
51
+ * 1,000,000), the unit #4760's spend gate meters. Converted to the gateway's
52
+ * USD `maxLimit` only at the admin call.
53
+ */
54
+ export interface HostedInferenceBudget {
55
+ limitMicros: number;
56
+ /** Reset window. Default `month`. */
57
+ window?: HostedBudgetWindow;
58
+ }
59
+ /** Error codes of {@link HostedInferenceError}. */
60
+ export type HostedInferenceErrorCode = 'HOSTED_INFERENCE_INVALID' | 'HOSTED_GATEWAY_NOT_CONFIGURED' | 'HOSTED_GATEWAY_UNSUPPORTED' | 'HOSTED_GATEWAY_FAILED' | 'HOSTED_STATE_INVALID' | 'HOSTED_NOT_ENTITLED';
61
+ /**
62
+ * A provisioning failure. Messages name fields and operations, never a key,
63
+ * an admin credential or a gateway response body.
64
+ */
65
+ export declare class HostedInferenceError extends SmrtError {
66
+ constructor(message: string, code: HostedInferenceErrorCode, details?: Record<string, unknown>);
67
+ }
68
+ /**
69
+ * The operator's gateway. Admin credentials stay in this object (built once
70
+ * from the host environment) and are only handed to `@happyvertical/ai`.
71
+ */
72
+ export interface HostedGatewayConfig {
73
+ provider: HostedGatewayProvider;
74
+ /** OpenAI-compatible inference endpoint the virtual keys are used against. */
75
+ baseUrl: string;
76
+ /** Admin API root, when it differs from `baseUrl`. */
77
+ adminUrl?: string;
78
+ /** LiteLLM master key, or a Bifrost admin virtual key. */
79
+ adminApiKey?: string;
80
+ /** Bifrost governance Basic-auth user. */
81
+ adminUser?: string;
82
+ /** Bifrost governance Basic-auth password. */
83
+ adminPassword?: string;
84
+ /** Default model of the stored binding. */
85
+ model?: string;
86
+ /** Per-tier models of the stored binding. */
87
+ tiers?: Partial<Record<InferenceTier, string>>;
88
+ /** Models the virtual key may use. Default: `model` plus the tier models. */
89
+ models?: string[];
90
+ /** Key lifetime (`30d`, `permanent`, ...), where the gateway supports it. */
91
+ keyDuration?: string;
92
+ /**
93
+ * Deadline for each admin call in ms (default
94
+ * {@link HOSTED_GATEWAY_ADMIN_TIMEOUT_MS}). A call past it counts as
95
+ * failed, so a stalled gateway never holds the lifecycle lock.
96
+ */
97
+ adminTimeoutMs?: number;
98
+ }
99
+ /** Default deadline of one gateway admin call. */
100
+ export declare const HOSTED_GATEWAY_ADMIN_TIMEOUT_MS = 30000;
101
+ /**
102
+ * The admin calls provisioning uses. `createProject` and `createVirtualKey`
103
+ * are `AIAdminInterface`; `updateVirtualKey` and `deleteVirtualKey` are
104
+ * feature-detected because `@happyvertical/ai` does not ship them yet
105
+ * (happyvertical/sdk#1494): without them budget sync and gateway revocation
106
+ * report `unsupported`.
107
+ */
108
+ export interface HostedGatewayAdmin extends Pick<AIAdminInterface, 'createProject' | 'createVirtualKey'> {
109
+ updateVirtualKey?(id: string, options: {
110
+ budget?: AIAdminBudget;
111
+ models?: string[];
112
+ isActive?: boolean;
113
+ }): Promise<AIVirtualKey>;
114
+ deleteVirtualKey?(id: string): Promise<boolean>;
115
+ }
116
+ /** Environment variables {@link hostedGatewayConfigFromEnv} reads. */
117
+ export declare const HOSTED_GATEWAY_ENV: {
118
+ readonly provider: "SMRT_INFERENCE_HOSTED_PROVIDER";
119
+ readonly baseUrl: "SMRT_INFERENCE_HOSTED_BASE_URL";
120
+ readonly adminUrl: "SMRT_INFERENCE_HOSTED_ADMIN_URL";
121
+ readonly adminApiKey: "SMRT_INFERENCE_HOSTED_ADMIN_KEY";
122
+ readonly adminUser: "SMRT_INFERENCE_HOSTED_ADMIN_USER";
123
+ readonly adminPassword: "SMRT_INFERENCE_HOSTED_ADMIN_PASSWORD";
124
+ readonly model: "SMRT_INFERENCE_HOSTED_MODEL";
125
+ readonly models: "SMRT_INFERENCE_HOSTED_MODELS";
126
+ readonly keyDuration: "SMRT_INFERENCE_HOSTED_KEY_DURATION";
127
+ readonly adminTimeoutMs: "SMRT_INFERENCE_HOSTED_ADMIN_TIMEOUT_MS";
128
+ };
129
+ /**
130
+ * Validate a gateway config. Throws `HOSTED_GATEWAY_NOT_CONFIGURED` naming
131
+ * the missing or invalid fields (never their values).
132
+ */
133
+ export declare function parseHostedGatewayConfig(value: Partial<HostedGatewayConfig>): HostedGatewayConfig;
134
+ /**
135
+ * Build the gateway config from environment variables
136
+ * ({@link HOSTED_GATEWAY_ENV}, plus `SMRT_INFERENCE_HOSTED_<TIER>_MODEL`).
137
+ * `undefined` when `SMRT_INFERENCE_HOSTED_PROVIDER` is unset (hosted
138
+ * inference off); throws when it is set but incomplete.
139
+ */
140
+ export declare function hostedGatewayConfigFromEnv(env?: Record<string, string | undefined>): HostedGatewayConfig | undefined;
141
+ /**
142
+ * The process gateway config, read from the environment once and cached.
143
+ * Throws `HOSTED_GATEWAY_NOT_CONFIGURED` when hosted inference is not set up.
144
+ */
145
+ export declare function getHostedGatewayConfig(): HostedGatewayConfig;
146
+ /** Forget the cached environment config (tests). */
147
+ export declare function resetHostedGatewayConfig(): void;
148
+ /**
149
+ * The `ai.admin` surface of the configured gateway provider, built through
150
+ * `getAI()` of `@happyvertical/ai`. Throws `HOSTED_GATEWAY_UNSUPPORTED` when
151
+ * the installed SDK's provider exposes no admin surface.
152
+ */
153
+ export declare function createHostedGatewayAdmin(config: HostedGatewayConfig): Promise<HostedGatewayAdmin>;
154
+ /** A gateway key SMRT no longer uses but could not delete yet. */
155
+ export interface HostedPendingGatewayRevocation {
156
+ keyId: string | null;
157
+ keyAlias: string;
158
+ /** Why it is pending: the SDK has no delete call, or the call failed. */
159
+ reason: 'unsupported' | 'failed' | 'orphaned';
160
+ since: string;
161
+ }
162
+ /** A user's provisioning state (`inference.hosted:user:<userId>`). */
163
+ export interface HostedInferenceState {
164
+ version: 1;
165
+ status: 'active' | 'revoked';
166
+ /** Lifecycle generation; advances on every revoke. */
167
+ generation: number;
168
+ provider?: HostedGatewayProvider;
169
+ projectId?: string;
170
+ /** The gateway's non-secret key id (update/delete handle), when returned. */
171
+ keyId: string | null;
172
+ /** Empty when no key was ever stored (only pending cleanups). */
173
+ keyAlias: string;
174
+ budget?: Required<HostedInferenceBudget>;
175
+ provisionedAt?: string;
176
+ revokedAt?: string;
177
+ /** The user's provider config before provisioning; dropped on revoke. */
178
+ prior: InferenceProviderConfig | null;
179
+ /**
180
+ * Keys SMRT stopped using whose gateway deletion is still owed (no SDK
181
+ * delete call, a failed call, or a key left by a failed provision).
182
+ * Retried by `revoke()` and `reconcileTenant()`; never holds a key value.
183
+ */
184
+ pendingGatewayRevocations?: HostedPendingGatewayRevocation[];
185
+ /**
186
+ * The member replaced the hosted binding with their own config: reconcile
187
+ * leaves them alone; only an explicit `provision()` re-provisions.
188
+ */
189
+ optedOut?: boolean;
190
+ /**
191
+ * Set when a budget update failed or timed out (it may still land on the
192
+ * gateway); budget syncs re-apply the stored budget while it is set.
193
+ */
194
+ budgetSyncUncertainAt?: string;
195
+ }
196
+ /**
197
+ * How long after an uncertain budget update a confirmed one must come
198
+ * before the uncertainty is cleared (a late landing is overwritten by the
199
+ * re-applies in between).
200
+ */
201
+ export declare const HOSTED_BUDGET_UNCERTAIN_WINDOW_MS: number;
202
+ /** What provisioning and revocation return: never the key. */
203
+ export interface HostedInferenceDescriptor {
204
+ tenantId: string;
205
+ userId: string;
206
+ status: 'active' | 'revoked' | 'none';
207
+ generation: number;
208
+ provider?: HostedGatewayProvider;
209
+ projectId?: string;
210
+ keyId?: string | null;
211
+ keyAlias?: string;
212
+ budget?: Required<HostedInferenceBudget>;
213
+ /** Non-secret handles of keys whose gateway deletion is still owed. */
214
+ pendingGatewayRevocations?: HostedPendingGatewayRevocation[];
215
+ }
216
+ /** Result of {@link HostedInferenceProvisioner.provision}. */
217
+ export interface ProvisionHostedInferenceResult extends HostedInferenceDescriptor {
218
+ /** True when this call created the key; false for an existing grant. */
219
+ created: boolean;
220
+ /** Budget sync outcome when an existing grant's budget differed. */
221
+ budgetSync?: HostedBudgetSyncStatus;
222
+ }
223
+ /** How a gateway key revocation went. */
224
+ export type HostedGatewayRevokeStatus = 'revoked' | 'missing' | 'unsupported' | 'failed' | 'none';
225
+ /** Result of {@link HostedInferenceProvisioner.revoke}. */
226
+ export interface RevokeHostedInferenceResult extends HostedInferenceDescriptor {
227
+ revoked: boolean;
228
+ /**
229
+ * `revoked`: the gateway deleted the key; `missing`: it no longer existed;
230
+ * `unsupported`: the SDK has no delete call (happyvertical/sdk#1494) or the
231
+ * gateway returned no key id; `failed`: the delete call failed. For
232
+ * `unsupported` and `failed` SMRT has already stopped using the key and
233
+ * records it in `pendingGatewayRevocations` (and the audit log) for a
234
+ * later retry or a manual revocation on the gateway; `none`: nothing to
235
+ * revoke.
236
+ */
237
+ gateway: HostedGatewayRevokeStatus;
238
+ /** What the user's provider config became. */
239
+ restored?: 'prior' | 'off' | 'kept';
240
+ }
241
+ /** Budget sync outcome. */
242
+ export type HostedBudgetSyncStatus = 'updated' | 'unchanged' | 'unsupported';
243
+ /** Result of {@link HostedInferenceProvisioner.syncBudget}. */
244
+ export interface SyncHostedBudgetResult extends HostedInferenceDescriptor {
245
+ sync: HostedBudgetSyncStatus | 'none';
246
+ }
247
+ /** What {@link HostedInferenceProvisioner.reconcileTenant} should converge to. */
248
+ export interface HostedReconcileTarget {
249
+ /** Whether the tenant's plan grants `inference.hosted` now. */
250
+ entitled: boolean;
251
+ /** The plan's budget (required to provision; syncs active grants). */
252
+ budget?: HostedInferenceBudget;
253
+ /** Users to hold an active grant while entitled (idempotent). */
254
+ users?: readonly string[];
255
+ }
256
+ /** Per-user outcome of a reconcile. */
257
+ export interface HostedReconcileResult {
258
+ tenantId: string;
259
+ provisioned: ProvisionHostedInferenceResult[];
260
+ revoked: RevokeHostedInferenceResult[];
261
+ synced: SyncHostedBudgetResult[];
262
+ /** Pending gateway deletions retried, and what is still pending. */
263
+ pending: Array<{
264
+ userId: string;
265
+ remaining: number;
266
+ }>;
267
+ failures: Array<{
268
+ userId: string;
269
+ error: unknown;
270
+ }>;
271
+ }
272
+ /** The secret store calls provisioning uses (`SecretService` satisfies it). */
273
+ export interface HostedSecretStore {
274
+ retrieve(name: string): Promise<{
275
+ value: string;
276
+ }>;
277
+ store(name: string, value: string, options?: {
278
+ category?: string;
279
+ description?: string;
280
+ auditDetails?: Record<string, unknown>;
281
+ }): Promise<unknown>;
282
+ delete(name: string, options?: {
283
+ auditDetails?: Record<string, unknown>;
284
+ }): Promise<boolean>;
285
+ list(options?: {
286
+ category?: string;
287
+ }): Promise<Array<{
288
+ name: string;
289
+ }>>;
290
+ }
291
+ /** Options for {@link createHostedInferenceProvisioner}. */
292
+ export interface HostedInferenceProvisionerOptions {
293
+ /** Database for `runOnce()` claims, the lifecycle lock and, without `secrets`, the secrets. */
294
+ db: DatabaseInterface;
295
+ /** Secret store; default `SecretService.create({ db })`. */
296
+ secrets?: HostedSecretStore;
297
+ /** Gateway config; default {@link getHostedGatewayConfig} (environment). */
298
+ gateway?: HostedGatewayConfig;
299
+ /** Admin client; default {@link createHostedGatewayAdmin}. Tests inject a fake. */
300
+ admin?: HostedGatewayAdmin;
301
+ /** Who acts, recorded as the audit user (default `system`). */
302
+ actor?: string;
303
+ /** Clock seam. */
304
+ now?: () => Date;
305
+ /** Alias/project nonce seam (tests). Default: random. */
306
+ nonce?: () => string;
307
+ /**
308
+ * Current entitlement check, run inside the tenant lock before a new key
309
+ * is minted (e.g. the host's `checkFeature('inference.hosted')`). With it,
310
+ * a provision that arrives after a downgrade (a stale event, a late
311
+ * retry) refuses with `HOSTED_NOT_ENTITLED` instead of activating.
312
+ */
313
+ entitled?: (tenantId: string) => Promise<boolean>;
314
+ }
315
+ /** Hosted provisioning bound to one database, store and gateway. */
316
+ export interface HostedInferenceProvisioner {
317
+ provision(options: {
318
+ tenantId: string;
319
+ userId: string;
320
+ budget: HostedInferenceBudget;
321
+ }): Promise<ProvisionHostedInferenceResult>;
322
+ /**
323
+ * Revoke the user's active grant; with none active, retry any pending
324
+ * gateway deletions. Idempotent.
325
+ */
326
+ revoke(options: {
327
+ tenantId: string;
328
+ userId: string;
329
+ reason?: string;
330
+ }): Promise<RevokeHostedInferenceResult>;
331
+ syncBudget(options: {
332
+ tenantId: string;
333
+ userId: string;
334
+ budget: HostedInferenceBudget;
335
+ }): Promise<SyncHostedBudgetResult>;
336
+ status(options: {
337
+ tenantId: string;
338
+ userId: string;
339
+ }): Promise<HostedInferenceDescriptor>;
340
+ /** Users of the tenant with an active hosted grant. */
341
+ listActive(tenantId: string): Promise<string[]>;
342
+ /** Users of the tenant with any hosted state (active, revoked, pending). */
343
+ listKnown(tenantId: string): Promise<string[]>;
344
+ revokeTenant(tenantId: string, options?: {
345
+ reason?: string;
346
+ }): Promise<RevokeHostedInferenceResult[]>;
347
+ syncTenantBudget(tenantId: string, budget: HostedInferenceBudget): Promise<SyncHostedBudgetResult[]>;
348
+ /**
349
+ * Converge the tenant to `target` (idempotent): not entitled revokes every
350
+ * active grant; entitled provisions `users` and syncs active budgets; both
351
+ * retry pending gateway deletions. Run it on webhook redelivery or on a
352
+ * schedule so a lost entitlement reaction is repaired.
353
+ */
354
+ reconcileTenant(tenantId: string, target: HostedReconcileTarget): Promise<HostedReconcileResult>;
355
+ /**
356
+ * Drop an owed gateway deletion after an operator revoked that key on the
357
+ * gateway by hand (audited). Returns whether an entry was removed.
358
+ */
359
+ acknowledgeGatewayRevocation(options: {
360
+ tenantId: string;
361
+ userId: string;
362
+ keyAlias: string;
363
+ }): Promise<boolean>;
364
+ }
365
+ /** Secret name of a user's hosted state. */
366
+ export declare function hostedInferenceStateSecretName(userId: string): string;
367
+ /** Validate a budget; fills the default window. */
368
+ export declare function normalizeHostedBudget(budget: HostedInferenceBudget | undefined): Required<HostedInferenceBudget>;
369
+ /** The gateway's budget shape for a hosted budget (USD at the boundary). */
370
+ export declare function toGatewayBudget(budget: Required<HostedInferenceBudget>): AIAdminBudget;
371
+ /**
372
+ * Create a provisioner. One per process (or per request) is fine: lifecycle
373
+ * operations run one at a time per process and, on PostgreSQL, hold a
374
+ * per-tenant transaction-scoped advisory lock (cross-process), so a
375
+ * tenant-wide revoke never misses an in-flight provision.
376
+ */
377
+ export declare function createHostedInferenceProvisioner(options: HostedInferenceProvisionerOptions): HostedInferenceProvisioner;
378
+ /**
379
+ * Provision hosted inference for one user (#4759): create the tenant's
380
+ * gateway project on first use, mint a per-user virtual key with `budget`,
381
+ * store it as the user's `inference.provider-config` (`source: 'hosted'`,
382
+ * `mode: 'hosted'`), keeping the prior config for revoke. Idempotent per
383
+ * `(tenantId, userId)`: an active grant is returned (its budget synced when
384
+ * it differs) and concurrent calls create one key.
385
+ */
386
+ export declare function provisionHostedInference(options: HostedInferenceProvisionerOptions & {
387
+ tenantId: string;
388
+ userId: string;
389
+ budget: HostedInferenceBudget;
390
+ }): Promise<ProvisionHostedInferenceResult>;
391
+ /**
392
+ * Revoke a user's hosted inference (downgrade, deletion): stop using the key
393
+ * (restore the user's prior provider config, or mode `off`), retire the
394
+ * state, and delete the gateway key when the SDK can (otherwise it is kept
395
+ * as an owed deletion and audited). Idempotent.
396
+ */
397
+ export declare function revokeHostedInference(options: HostedInferenceProvisionerOptions & {
398
+ tenantId: string;
399
+ userId: string;
400
+ reason?: string;
401
+ }): Promise<RevokeHostedInferenceResult>;
402
+ /** Read a hosted budget from an `inference.hosted` grant's `metadata.budget`. */
403
+ export declare function hostedBudgetFromGrantMetadata(metadata: Record<string, unknown> | undefined): HostedInferenceBudget | undefined;
404
+ /** Structural mirror of smrt-subscriptions' `EntitlementSnapshot` (grants). */
405
+ export interface HostedEntitlementSnapshot {
406
+ grants: ReadonlyArray<{
407
+ featureKey: string;
408
+ enabled?: boolean;
409
+ metadata?: Record<string, unknown>;
410
+ }>;
411
+ }
412
+ /** Structural mirror of smrt-subscriptions' `EntitlementChange`. */
413
+ export interface HostedEntitlementChange {
414
+ tenantId: string;
415
+ gained: readonly string[];
416
+ lost: readonly string[];
417
+ changed: readonly string[];
418
+ after: HostedEntitlementSnapshot;
419
+ }
420
+ /** Options for the entitlement listener and reconciler. */
421
+ export interface HostedInferenceEntitlementListenerOptions {
422
+ provisioner: HostedInferenceProvisioner;
423
+ /**
424
+ * Users who should hold a grant while the tenant is entitled (the
425
+ * tenant's members; membership is the host's). Users joining later are
426
+ * provisioned by the host calling `provision()` directly.
427
+ */
428
+ users(tenantId: string): Promise<readonly string[]>;
429
+ /**
430
+ * The budget for the tenant's plan. Default: the `inference.hosted`
431
+ * grant's `metadata.budget` ({@link hostedBudgetFromGrantMetadata}), else
432
+ * `defaultBudget`.
433
+ */
434
+ budgetFor?(tenantId: string, snapshot: HostedEntitlementSnapshot): HostedInferenceBudget | undefined;
435
+ defaultBudget?: HostedInferenceBudget;
436
+ }
437
+ /**
438
+ * Reconcile a tenant's hosted grants with its current entitlement snapshot
439
+ * (smrt-subscriptions' `snapshotEntitlements()`): entitled provisions
440
+ * `users()` and syncs budgets, not entitled revokes every grant, both retry
441
+ * owed gateway deletions. Idempotent: run it on webhook redelivery (a
442
+ * replayed write diffs to "no change") and on a schedule, so a reaction
443
+ * lost to a crash or a failed listener is repaired. Throws one error naming
444
+ * the users that failed, after trying all of them.
445
+ */
446
+ export declare function createHostedInferenceReconciler(options: HostedInferenceEntitlementListenerOptions): (tenantId: string, snapshot: HostedEntitlementSnapshot) => Promise<HostedReconcileResult>;
447
+ /**
448
+ * The smrt-subscriptions entitlement-change listener for hosted inference:
449
+ * register it with `registerEntitlementChangeListener()`. A change that
450
+ * gains, loses or changes `inference.hosted` reconciles the tenant to the
451
+ * change's `after` snapshot ({@link createHostedInferenceReconciler}).
452
+ */
453
+ export declare function createHostedInferenceEntitlementListener(options: HostedInferenceEntitlementListenerOptions): (change: HostedEntitlementChange) => Promise<void>;
454
+ //# sourceMappingURL=hosted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted.d.ts","s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AQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IACpD;;;;OAIG;IACH,SAAS,CAAC,CACR,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,yBAAyB,GAClC,qBAAqB,GAAG,SAAS,CAAC;IACrC,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACvC;AA6BD;;;;;;;;GAQG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,yCAAyC,GACjD,CACD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,yBAAyB,KAChC,OAAO,CAAC,qBAAqB,CAAC,CA6BlC;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,EAAE,yCAAyC,GACjD,CAAC,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CASpD"}
@@ -0,0 +1,9 @@
1
+ export { classifyInferenceFailure, isInferenceAbort, } from './classify.js';
2
+ export { CHAIN_KINDS, type ChainStep, candidateLabel, candidateToStep, EXECUTOR_KINDS, expandTarget, FUSION_GATE_CONTINUE, FUSION_SEAT_COUNTS, findFusionDefinitionIssues, findFusionPromptIssues, findInferenceConfigIssues, hasInferenceChains, validateInferenceConfig, } from './config.js';
3
+ export { InferenceConfigError, InferenceExhaustedError, InferenceFusionError, } from './errors.js';
4
+ export { type ChainExecutorOptions, createChainClient, } from './executor.js';
5
+ export { clearFusions, createChainExecutor, createFusionClient, type DefineFusionInput, defineFusion, type FusionCallOptions, type FusionGateResult, type FusionPromptResolver, type FusionRunResult, type FusionSeatPrompt, type FusionSeatResult, type FusionSeatStatus, type FusionSeatUsage, getFusion, listFusions, runFusion, setFusionPromptResolver, } from './fusion.js';
6
+ export { INFERENCE_PROVIDER_CONFIG_SECRET_TYPE, INFERENCE_PROVIDER_CONFIG_SOURCES, INFERENCE_PROVIDER_PARAM_KEYS, type InferenceProviderBinding, type InferenceProviderConfig, InferenceProviderConfigError, type InferenceProviderConfigSource, inferenceProviderBindingFor, inferenceProviderConfigSecretName, inferenceProviderSource, inferenceProviderTargets, parseInferenceProviderConfig, type RedactedInferenceProviderBinding, type RedactedInferenceProviderConfig, redactInferenceProviderConfig, redactInferenceTarget, } from './provider-config.js';
7
+ export { createInferenceResolver, isInferenceRegistered, type RegisterInferenceOptions, registerInference, } from './register.js';
8
+ export { INFERENCE_FAILURE_CLASSES, type InferenceConfigIssue, type InferenceFailureClass, type InferenceSubstitution, type InferenceSubstitutionReason, } from './types.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,WAAW,EACX,KAAK,SAAS,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,oBAAoB,EACzB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,SAAS,EACT,WAAW,EACX,SAAS,EACT,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qCAAqC,EACrC,iCAAiC,EACjC,6BAA6B,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,4BAA4B,EAC5B,KAAK,6BAA6B,EAClC,2BAA2B,EAC3B,iCAAiC,EACjC,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,EAC5B,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACpC,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,GACjC,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { A as candidateLabel, B as InferenceExhaustedError, C as createChainClient, D as EXECUTOR_KINDS, E as CHAIN_KINDS, F as findInferenceConfigIssues, I as hasInferenceChains, L as validateInferenceConfig, M as expandTarget, N as findFusionDefinitionIssues, O as FUSION_GATE_CONTINUE, P as findFusionPromptIssues, S as setFusionPromptResolver, T as isInferenceAbort, V as InferenceFusionError, _ as createFusionClient, a as inferenceProviderBindingFor, b as listFusions, c as inferenceProviderTargets, d as redactInferenceTarget, f as createInferenceResolver, g as createChainExecutor, h as clearFusions, i as InferenceProviderConfigError, j as candidateToStep, k as FUSION_SEAT_COUNTS, l as parseInferenceProviderConfig, m as registerInference, n as INFERENCE_PROVIDER_CONFIG_SOURCES, o as inferenceProviderConfigSecretName, p as isInferenceRegistered, r as INFERENCE_PROVIDER_PARAM_KEYS, s as inferenceProviderSource, t as INFERENCE_PROVIDER_CONFIG_SECRET_TYPE, u as redactInferenceProviderConfig, v as defineFusion, w as classifyInferenceFailure, x as runFusion, y as getFusion, z as InferenceConfigError } from "./chunks/provider-config-4Bx8N52X.js";
2
+ import { INFERENCE_FAILURE_CLASSES } from "./types.js";
3
+ //#region src/index.ts
4
+ registerInference();
5
+ //#endregion
6
+ export { CHAIN_KINDS, EXECUTOR_KINDS, FUSION_GATE_CONTINUE, FUSION_SEAT_COUNTS, INFERENCE_FAILURE_CLASSES, INFERENCE_PROVIDER_CONFIG_SECRET_TYPE, INFERENCE_PROVIDER_CONFIG_SOURCES, INFERENCE_PROVIDER_PARAM_KEYS, InferenceConfigError, InferenceExhaustedError, InferenceFusionError, InferenceProviderConfigError, candidateLabel, candidateToStep, classifyInferenceFailure, clearFusions, createChainClient, createChainExecutor, createFusionClient, createInferenceResolver, defineFusion, expandTarget, findFusionDefinitionIssues, findFusionPromptIssues, findInferenceConfigIssues, getFusion, hasInferenceChains, inferenceProviderBindingFor, inferenceProviderConfigSecretName, inferenceProviderSource, inferenceProviderTargets, isInferenceAbort, isInferenceRegistered, listFusions, parseInferenceProviderConfig, redactInferenceProviderConfig, redactInferenceTarget, registerInference, runFusion, setFusionPromptResolver, validateInferenceConfig };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @happyvertical/smrt-inference — inference binding behavior for SMRT tiers\n * (#4749). This entry is browser-safe; `./node` holds the doctor and\n * `./resolver` the per-user / per-tenant resolver over smrt-secrets (#4756).\n *\n * Importing it registers the executor (alias chains and fusions) and the\n * validating resolver into core's seam (`setInferenceExecutor()` /\n * `setInferenceResolver()`).\n */\nimport { registerInference } from './register.js';\n\nexport {\n classifyInferenceFailure,\n isInferenceAbort,\n} from './classify.js';\nexport {\n CHAIN_KINDS,\n type ChainStep,\n candidateLabel,\n candidateToStep,\n EXECUTOR_KINDS,\n expandTarget,\n FUSION_GATE_CONTINUE,\n FUSION_SEAT_COUNTS,\n findFusionDefinitionIssues,\n findFusionPromptIssues,\n findInferenceConfigIssues,\n hasInferenceChains,\n validateInferenceConfig,\n} from './config.js';\nexport {\n InferenceConfigError,\n InferenceExhaustedError,\n InferenceFusionError,\n} from './errors.js';\nexport {\n type ChainExecutorOptions,\n createChainClient,\n} from './executor.js';\nexport {\n clearFusions,\n createChainExecutor,\n createFusionClient,\n type DefineFusionInput,\n defineFusion,\n type FusionCallOptions,\n type FusionGateResult,\n type FusionPromptResolver,\n type FusionRunResult,\n type FusionSeatPrompt,\n type FusionSeatResult,\n type FusionSeatStatus,\n type FusionSeatUsage,\n getFusion,\n listFusions,\n runFusion,\n setFusionPromptResolver,\n} from './fusion.js';\nexport {\n INFERENCE_PROVIDER_CONFIG_SECRET_TYPE,\n INFERENCE_PROVIDER_CONFIG_SOURCES,\n INFERENCE_PROVIDER_PARAM_KEYS,\n type InferenceProviderBinding,\n type InferenceProviderConfig,\n InferenceProviderConfigError,\n type InferenceProviderConfigSource,\n inferenceProviderBindingFor,\n inferenceProviderConfigSecretName,\n inferenceProviderSource,\n inferenceProviderTargets,\n parseInferenceProviderConfig,\n type RedactedInferenceProviderBinding,\n type RedactedInferenceProviderConfig,\n redactInferenceProviderConfig,\n redactInferenceTarget,\n} from './provider-config.js';\nexport {\n createInferenceResolver,\n isInferenceRegistered,\n type RegisterInferenceOptions,\n registerInference,\n} from './register.js';\nexport {\n INFERENCE_FAILURE_CLASSES,\n type InferenceConfigIssue,\n type InferenceFailureClass,\n type InferenceSubstitution,\n type InferenceSubstitutionReason,\n} from './types.js';\n\nregisterInference();\n"],"mappings":";;;AA0FA,kBAAkB"}