@happyvertical/smrt-inference 0.71.0 → 0.73.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.
package/dist/server.js CHANGED
@@ -2,7 +2,7 @@ import { B as InferenceConfigError, I as findInferenceConfigIssues, N as findFus
2
2
  import { S as resolveAssistantSettings, _ as AGENT_TOOLS, a as concreteTier, b as ASSISTANT_SETTING_KEYS, c as engineTierModel, d as rankOpenAIModels, f as resolveEngineEffort, g as engineLabel, h as weakestModel, i as OPENAI_MODEL_RANKS, l as nextEngineModel, m as validateModelId, n as runWithModelFallback, o as engineModels, p as strongestModel, r as CLAUDE_MODEL_RANKS, s as engineReasoningEffort, t as MODEL_FALLBACK_MESSAGE, u as nextModel, v as AGENT_TOOL_INFO, x as isAssistantSettings, y as isAgentTool } from "./chunks/model-fallback-BVD3BzkG.js";
3
3
  import { createUserInferenceResolver, registerUserInferenceResolver } from "./resolver.js";
4
4
  import { checkInferenceBindings, inferenceProbeUrl, probeInferenceCandidate } from "./node.js";
5
- import { C as getInferenceOverrideGeneration, S as tierBinding, _ as normalizeFusionDefinition, a as INFERENCE_BINDING_NAME_PATTERN, b as parseInferenceBinding, c as TRANSCRIPTS_BINDING, d as inferenceTargetRef, f as isAllowedByList, g as normalizeDefaultTier, h as normalizeAllowList, i as DEFAULT_TIER_BINDING, l as describeInferenceTarget, m as normalizeAliasDefinition, n as APP_INFERENCE_SCOPE_ID, o as INFERENCE_MODES, p as matchesAllowPattern, r as InferenceOverride, s as InferenceBindingValueError, t as InferenceOverrideCollection, u as findKeyMember, v as normalizeTierTarget, x as stripKeyMembers, y as normalizeTranscriptSettings } from "./chunks/InferenceOverrideCollection-4CiHd31e.js";
5
+ import { C as getInferenceOverrideGeneration, S as tierBinding, _ as normalizeFusionDefinition, a as INFERENCE_BINDING_NAME_PATTERN, b as parseInferenceBinding, c as TRANSCRIPTS_BINDING, d as inferenceTargetRef, f as isAllowedByList, g as normalizeDefaultTier, h as normalizeAllowList, i as DEFAULT_TIER_BINDING, l as describeInferenceTarget, m as normalizeAliasDefinition, n as APP_INFERENCE_SCOPE_ID, o as INFERENCE_MODES, p as matchesAllowPattern, r as InferenceOverride, s as InferenceBindingValueError, t as InferenceOverrideCollection, u as findKeyMember, v as normalizeTierTarget, x as stripKeyMembers, y as normalizeTranscriptSettings } from "./chunks/InferenceOverrideCollection-BIxPVQrT.js";
6
6
  import { DEFAULT_RETENTION_POLICY, DEFAULT_TRANSCRIPT_MAX_BYTES, DEFAULT_TRANSCRIPT_SAMPLE, INFERENCE_PRESETS, INFERENCE_PRESET_IDS, INFERENCE_TIERS, config, getInferenceConfig, getInferenceTranscriptsConfig, inferenceTargetKind, isInferencePresetId, isInferenceTier, mergeInferenceConfigs, reportAiUsage, resolveAutoTier, setAiTranscriptAppSettings, setInferenceResolver } from "@happyvertical/smrt-core";
7
7
  import { AI_PROVIDER_TYPES } from "@happyvertical/ai/types";
8
8
  import { getDefaultAIKeyEnvName } from "@happyvertical/smrt-config";
@@ -3,16 +3,16 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-inference",
6
- "packageVersion": "0.71.0",
6
+ "packageVersion": "0.73.0",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "c090e832cace4c71ac690112ab4201016df66cc409d1c57f8c8409f1eb524f62",
11
- "packageJson": "cc8ff3fdef4c6e6c63f8140dca893497df5a207f14643deb235ac43ccfe450aa",
10
+ "manifest": "d499e10ae62bf248ca73d682fd9ea626b96975521cef4f9be846308b6ff32097",
11
+ "packageJson": "b942408bce60ca3a6f5d0870999f110a5829582edca1071100ba168d11b70f28",
12
12
  "agents": "9adc6d9cb776e9cc48473f14902dcb5805308bedf228631b59192ba55b678565",
13
13
  "moduleDoc:agents/engines.md": "1fee8176dc87fe963da1e7aeee49cfbb27500e20a3115734a3e05cc80133ab6b",
14
14
  "moduleDoc:agents/resolver.md": "71de7295b6988b27b3b27e2ae82fd71e525ef53613c7714a1deea6c45ba92ef6",
15
- "moduleDoc:agents/hosted.md": "563141ef3ff09c453de8cfe99db3500da77fa28efe6bc3990e3f84a6cf32653d",
15
+ "moduleDoc:agents/hosted.md": "ef6ca489e5c2960fb100a635d786ed26558b8612dfac20b65758d57aad7937a0",
16
16
  "moduleDoc:agents/fusions.md": "85cd95e209bcc70f8cdcac1bad702228e74ec59be9c7613d50bc4526afa17f5b",
17
17
  "moduleDoc:agents/settings.md": "1ba893ced5676ea41cd10f4454991db7de8c949d93d030ea1d1e78024e9f0cce"
18
18
  },
@@ -324,7 +324,7 @@
324
324
  {
325
325
  "path": "agents/hosted.md",
326
326
  "module": "hosted",
327
- "content": "# Hosted inference (#4759, #4760)\n\n## Provisioning (`src/hosted.ts`, #4759)\n\n`provisionHostedInference({ db, tenantId, userId, budget })`,\n`revokeHostedInference({ db, tenantId, userId })`, or one\n`createHostedInferenceProvisioner({ db, secrets?, gateway?, admin?, actor? })`\n(`provision`, `revoke`, `syncBudget`, `status`, `listActive`, `listKnown`,\n`revokeTenant`, `syncTenantBudget`, `reconcileTenant`,\n`acknowledgeGatewayRevocation` to drop an owed deletion an operator did by\nhand).\n\n- **Gateway.** Admin calls go through `ai.admin` (`AIAdminInterface`) of the\n `bifrost` / `litellm` provider of `@happyvertical/ai` >= 0.111.7\n (happyvertical/sdk#1494); never reimplement gateway administration here.\n `HostedGatewayAdmin` is `HOSTED_GATEWAY_ADMIN_METHODS` (`createProject`,\n `createVirtualKey`, `updateVirtualKey`, `deleteVirtualKey`,\n `listProjects`); a provider missing one is `HOSTED_GATEWAY_UNSUPPORTED`.\n SMRT persists only `AIVirtualKey.id`, the non-secret handle (Bifrost id,\n LiteLLM `token_id`); an id that equals or looks like a key value (`sk-…`)\n is dropped on create and when older state is read, so that key counts as\n having no id. Budget sync sends\n `updateVirtualKey(id, { budget })` only (Bifrost refuses `models` /\n `metadata`, LiteLLM `providerConfigs`: `ADMIN_UNSUPPORTED_FIELD`);\n `unsupported` now means the grant has no key id. Revoke ends local use\n before touching the gateway (config restored, state retired with the key\n owed, then `deleteVirtualKey`; `false` is `missing`, an already revoked\n key, nothing owed). A deletion the gateway did not perform (`failed`, a\n key a failed provision left, `unsupported`: no admin configured or no key\n id; entries from before 0.111.7 also read `unsupported`) goes to the\n state's `pendingGatewayRevocations` (id + alias, never the key), is\n audited with `manualGatewayRevocation`, and is retried by `revoke()` /\n `reconcileTenant()`; each retry that settles one writes\n `inference.hosted.revoke-retry` with `settled: [{ keyId, keyAlias,\n gateway }]`, closing those records. Entries without an id stay for an\n operator (`acknowledgeGatewayRevocation`).\n- **Config, read once from the environment** (`getHostedGatewayConfig()`;\n unset provider = hosted off): `SMRT_INFERENCE_HOSTED_PROVIDER`\n (`bifrost|litellm`), `_BASE_URL` (the OpenAI-compatible endpoint keys are\n used against), `_ADMIN_URL`, `_ADMIN_KEY` (LiteLLM master key, required for\n litellm; or a Bifrost admin key), `_ADMIN_USER` / `_ADMIN_PASSWORD`\n (Bifrost Basic auth), `_MODEL`, `_<TIER>_MODEL`, `_MODELS` (comma list the\n key may use; default the binding's models), `_KEY_DURATION`,\n `_ADMIN_TIMEOUT_MS` (deadline per admin call, default 30 s, also passed as\n the SDK `timeout`; a call past it is a failure, so a stalled gateway never\n holds the lifecycle lock). A create that fails ambiguously (timeout,\n transport reset, 5xx, unclassified; anything but a credential, quota,\n missing-model or refusal answer per `classifyInferenceFailure`) records\n its alias as owed, since the gateway may have minted the key.\n Errors name missing fields, never values.\n- **Storage** (smrt-secrets, `context = tenantId`): the key lives only in\n the user's `inference.provider-config:user:<id>` (`source: 'hosted'`,\n `mode: 'hosted'`, `gatewayKeyAlias`, a binding per configured tier);\n `inference.hosted:user:<id>` (category `inference.hosted`) holds status,\n generation, key id and alias, budget and the user's prior config;\n `inference.hosted:project` the tenant's gateway project (created once\n through `runOnce()`, name `smrt tenant <tenantId>`, LiteLLM id\n `smrt-<tenantId>-<nonce>`). Without a stored record, `listProjects({\n tenantId })` runs first and adopts the lowest-id project with that name\n (and id prefix on LiteLLM), audited `adopted: true`, so a crash between\n create and persist never makes a second project; a failed lookup fails\n the provision rather than create blind. Every write passes\n `auditDetails.operation` (`inference.hosted.provision|revoke|budget|project`)\n to `SecretAuditLog`.\n- **Idempotency and ordering.** An active grant whose binding is still the\n stored one is returned (`created: false`), its budget synced when it\n differs. The create path runs under `runOnce()` keyed by `(tenantId,\n userId, generation)`; revoke advances the generation. Aliases\n (`smrt-<tenant>-<user>-g<n>-<nonce>`) and LiteLLM project ids\n (`smrt-<tenant>-<nonce>`) are unique per attempt, so a failed attempt's\n leftovers never block the retry. Lifecycle operations run one at a time\n per process (a process-wide chain: rare operations, and it bounds the\n pooled connections held) and, on PostgreSQL, under a per-tenant\n `pg_advisory_xact_lock` held in a transaction for the whole operation\n (its writes use other pooled connections: at most three per process), so\n a tenant-wide revoke or reconcile never misses an in-flight provision.\n The optional `entitled(tenantId)` check runs inside that lock before a\n key is minted (`HOSTED_NOT_ENTITLED`) and before an entitled reconcile\n acts (a stale snapshot then revokes), so a stale gain or late retry after\n a downgrade does not activate. Hosts running the listener or reconciler\n across processes should set it. A failed binding write deletes or records the new\n key and restores the previous state after the claim rolls back (no delete\n inside the claim transaction: single-connection adapters would wait on\n it). A user who replaced the hosted binding keeps their config: an\n explicit `provision()` retires the stale key and mints anew; a reconcile\n only retires it and marks the state `optedOut`, which later reconciles\n respect until an explicit `provision()`. Writes through the #4756\n resolver (the settings panel) do not take this lock.\n- **Revoke** restores the prior config when it holds a binding or a mode,\n else writes `{ mode: 'off' }`; a config the user replaced is kept.\n- **Budget** is integer micro-dollars (`{ limitMicros, window? }`, `day |\n week | month | year`, default month), converted to the gateway's USD\n `maxLimit` and `1d|7d|30d|365d` only at the admin call. #4760's spend gate\n is the authoritative pre-call check; the gateway budget is defense in depth.\n An unchanged budget is never re-sent (a gateway update may restart the\n spend window); after a failed or timed-out update (`budgetSyncUncertainAt`,\n it may still land) syncs re-apply the stored budget until a confirmed\n update 15 minutes later.\n- **Entitlement hook.** `createHostedInferenceEntitlementListener({\n provisioner, users, budgetFor?, defaultBudget? })` structurally matches\n smrt-subscriptions' `EntitlementChangeListener` (register it with\n `registerEntitlementChangeListener()`; the host wraps its webhook write in\n `trackEntitlementChange()`). A change touching `inference.hosted`\n reconciles the tenant to the change's `after` snapshot through\n `createHostedInferenceReconciler()`: entitled provisions `users(tenantId)`\n (membership is the host's; exclude users an operator revoked) unless\n they opted out, and syncs budgets; not entitled revokes every grant; both\n retry owed deletions (also for active grants: they are old keys). The\n plan's budget is the grant's `metadata.budget` (`{ limitMicros, window }`).\n A replayed webhook diffs to \"no change\", so hosts also call the reconciler\n with `snapshotEntitlements()` on redelivery and on a schedule; that is\n what repairs a reaction lost to a crash. Per-user failures are thrown\n together after all users were tried.\n- **Keys.** Never in results, errors (gateway failures carry only the\n operation and error code), audit details, `runOnce()` results or logs.\n Usage rows carry `source: hosted` and `gatewayKeyAlias` (from\n `InferenceTarget.usageTags`). Other processes see a new binding after the\n resolver cache expires; this process is invalidated through\n `invalidateUserInferenceResolvers()`.\n\n## Spend gate and kill switch (`src/gate.ts`, #4760)\n\n`createHostedInferenceGate({ killSwitch, spend, principal?,\nrequireSubscription?, onWarning? })` is core's `InferenceGate` (seam:\n[core inference.md](../../core/agents/inference.md), \"Hosted gate\");\n`registerHostedInferenceGate(gate | options)` installs it and the\nprincipal's user as the `userId` usage tag. Host wiring:\n\n```ts\nregisterHostedInferenceGate({\n killSwitch: new KillSwitchService({ db }), // smrt-features\n spend: await HostedAiSpendEvaluator.create({ db }), // smrt-subscriptions\n});\n```\n\nBoth stores are structural: smrt-features and smrt-subscriptions build with\nthe CLI, which depends on this package, so a dependency on either is a turbo\ncycle. Checks, in order, on every `source: hosted` call:\n\n1. **Kill switch** `inference.hosted.enabled` (`HOSTED_INFERENCE_KILL_SWITCH`):\n global DISABLE, then the tenant's DISABLE, blocks (`policy:\n 'kill-switch'`, `disabledBy`). Uncached, no model call: **the incident\n lever** (`smrt inference:hosted disable [--tenant <id>]`; programmatic\n `setHostedInferenceEnabled(store, { enabled, tenantId? })`,\n `getHostedInferenceSwitch()`). Stored as smrt-features override rows\n with kill-switch semantics, not as a flag: a tenant ENABLE can never\n lift a global DISABLE, and `inference.hosted` (the plan key) stays a pure\n entitlement. Hosts with an admin UI write the same DISABLE rows through\n `FeatureOverrideService` and their authorizer.\n2. **Tenant**: request tenant, else the principal's; none blocks (`no-tenant`).\n3. **Entitlement**: no entitled subscription blocks (`subscription`) unless\n `requireSubscription: false`.\n4. **Spend**: the plan's tenant and per-user caps (smrt-subscriptions\n AGENTS, \"Hosted AI spend caps\"): `blocked` blocks with `cap`, `spend`\n (micro-dollars) and `resetsAt`; `warn` returns `warn` and calls\n `onWarning` (errors swallowed). The user is the principal's, only in its\n own tenant, and none for `userId: null` (agents).\n\nAny thrown error propagates and core blocks with `gate-error`. The plan\ncheck does not test the `inference.hosted` feature key: provisioning the\nhosted binding (#4759) is where entitlement to hosted is granted.\n"
327
+ "content": "# Hosted inference (#4759, #4760)\n\n## Provisioning (`src/hosted.ts`, #4759)\n\n`provisionHostedInference({ db, tenantId, userId, budget })`,\n`revokeHostedInference({ db, tenantId, userId })`, or one\n`createHostedInferenceProvisioner({ db, secrets?, gateway?, admin?, actor? })`\n(`provision`, `revoke`, `syncBudget`, `status`, `listActive`, `listKnown`,\n`revokeTenant`, `syncTenantBudget`, `reconcileTenant`,\n`acknowledgeGatewayRevocation` to drop an owed deletion an operator did by\nhand).\n\n- **Gateway.** Admin calls go through `ai.admin` (`AIAdminInterface`) of the\n `bifrost` / `litellm` provider of `@happyvertical/ai` >= 0.111.7\n (happyvertical/sdk#1494); never reimplement gateway administration here.\n `HostedGatewayAdmin` is `HOSTED_GATEWAY_ADMIN_METHODS` (`createProject`,\n `createVirtualKey`, `updateVirtualKey`, `deleteVirtualKey`,\n `listProjects`); a provider missing one is `HOSTED_GATEWAY_UNSUPPORTED`.\n SMRT persists only `AIVirtualKey.id`, the non-secret handle (Bifrost id,\n LiteLLM `token_id`); an id that equals or looks like a key value (`sk-…`)\n is dropped on create and when older state is read, so that key counts as\n having no id. Budget sync sends\n `updateVirtualKey(id, { budget })` only (Bifrost refuses `models` /\n `metadata`, LiteLLM `providerConfigs`: `ADMIN_UNSUPPORTED_FIELD`);\n `unsupported` now means the grant has no key id. Revoke ends local use\n before touching the gateway (config restored, state retired with the key\n owed, then `deleteVirtualKey`; `false` is `missing`, an already revoked\n key, nothing owed). A deletion the gateway did not perform (`failed`, a\n key a failed provision left, `unsupported`: no admin configured or no key\n id; entries from before 0.111.7 also read `unsupported`) goes to the\n state's `pendingGatewayRevocations` (id + alias, never the key), is\n audited with `manualGatewayRevocation`, and is retried by `revoke()` /\n `reconcileTenant()`; each retry that settles one writes\n `inference.hosted.revoke-retry` with `settled: [{ keyId, keyAlias,\n gateway }]`, closing those records. Entries without an id stay for an\n operator (`acknowledgeGatewayRevocation`).\n- **Re-checks under the lock.** `revoke({ onlyIf })` runs `onlyIf()` inside the\n tenant lock and leaves the grant alone (`revoked: false`, `gateway: 'none'`)\n when it returns false; `reconcileTenant(.., { stillWanted })` re-checks each\n user who is about to get a NEW key (a user already holding one is synced as\n before); `createHostedInferenceEntitlementListener` / `Reconciler` pass it\n through as `stillWanted(tenantId, userId)`. They let a host that decided on\n stale data (a member list read before the lock) confirm it atomically with\n the key change.\n- **Config, read once from the environment** (`getHostedGatewayConfig()`;\n unset provider = hosted off): `SMRT_INFERENCE_HOSTED_PROVIDER`\n (`bifrost|litellm`), `_BASE_URL` (the OpenAI-compatible endpoint keys are\n used against), `_ADMIN_URL`, `_ADMIN_KEY` (LiteLLM master key, required for\n litellm; or a Bifrost admin key), `_ADMIN_USER` / `_ADMIN_PASSWORD`\n (Bifrost Basic auth), `_MODEL`, `_<TIER>_MODEL`, `_MODELS` (comma list the\n key may use; default the binding's models), `_KEY_DURATION`,\n `_ADMIN_TIMEOUT_MS` (deadline per admin call, default 30 s, also passed as\n the SDK `timeout`; a call past it is a failure, so a stalled gateway never\n holds the lifecycle lock). A create that fails ambiguously (timeout,\n transport reset, 5xx, unclassified; anything but a credential, quota,\n missing-model or refusal answer per `classifyInferenceFailure`) records\n its alias as owed, since the gateway may have minted the key.\n Errors name missing fields, never values.\n- **Storage** (smrt-secrets, `context = tenantId`): the key lives only in\n the user's `inference.provider-config:user:<id>` (`source: 'hosted'`,\n `mode: 'hosted'`, `gatewayKeyAlias`, a binding per configured tier);\n `inference.hosted:user:<id>` (category `inference.hosted`) holds status,\n generation, key id and alias, budget and the user's prior config;\n `inference.hosted:project` the tenant's gateway project (created once\n through `runOnce()`, name `smrt tenant <tenantId>`, LiteLLM id\n `smrt-<tenantId>-<nonce>`). Without a stored record, `listProjects({\n tenantId })` runs first and adopts the lowest-id project with that name\n (and id prefix on LiteLLM), audited `adopted: true`, so a crash between\n create and persist never makes a second project; a failed lookup fails\n the provision rather than create blind. Every write passes\n `auditDetails.operation` (`inference.hosted.provision|revoke|budget|project`)\n to `SecretAuditLog`.\n- **Idempotency and ordering.** An active grant whose binding is still the\n stored one is returned (`created: false`), its budget synced when it\n differs. The create path runs under `runOnce()` keyed by `(tenantId,\n userId, generation)`; revoke advances the generation. Aliases\n (`smrt-<tenant>-<user>-g<n>-<nonce>`) and LiteLLM project ids\n (`smrt-<tenant>-<nonce>`) are unique per attempt, so a failed attempt's\n leftovers never block the retry. Lifecycle operations run one at a time\n per process (a process-wide chain: rare operations, and it bounds the\n pooled connections held) and, on PostgreSQL, under a per-tenant\n `pg_advisory_xact_lock` held in a transaction for the whole operation\n (its writes use other pooled connections: at most three per process), so\n a tenant-wide revoke or reconcile never misses an in-flight provision.\n The optional `entitled(tenantId)` check runs inside that lock before a\n key is minted (`HOSTED_NOT_ENTITLED`) and before an entitled reconcile\n acts (a stale snapshot then revokes), so a stale gain or late retry after\n a downgrade does not activate. Hosts running the listener or reconciler\n across processes should set it. A failed binding write deletes or records the new\n key and restores the previous state after the claim rolls back (no delete\n inside the claim transaction: single-connection adapters would wait on\n it). A user who replaced the hosted binding keeps their config: an\n explicit `provision()` retires the stale key and mints anew; a reconcile\n only retires it and marks the state `optedOut`, which later reconciles\n respect until an explicit `provision()`. Writes through the #4756\n resolver (the settings panel) do not take this lock.\n- **Revoke** restores the prior config when it holds a binding or a mode,\n else writes `{ mode: 'off' }`; a config the user replaced is kept.\n- **Budget** is integer micro-dollars (`{ limitMicros, window? }`, `day |\n week | month | year`, default month), converted to the gateway's USD\n `maxLimit` and `1d|7d|30d|365d` only at the admin call. #4760's spend gate\n is the authoritative pre-call check; the gateway budget is defense in depth.\n An unchanged budget is never re-sent (a gateway update may restart the\n spend window); after a failed or timed-out update (`budgetSyncUncertainAt`,\n it may still land) syncs re-apply the stored budget until a confirmed\n update 15 minutes later.\n- **Entitlement hook.** `createHostedInferenceEntitlementListener({\n provisioner, users, budgetFor?, defaultBudget? })` structurally matches\n smrt-subscriptions' `EntitlementChangeListener` (register it with\n `registerEntitlementChangeListener()`; the host wraps its webhook write in\n `trackEntitlementChange()`). A change touching `inference.hosted`\n reconciles the tenant to the change's `after` snapshot through\n `createHostedInferenceReconciler()`: entitled provisions `users(tenantId)`\n (membership is the host's; exclude users an operator revoked) unless\n they opted out, and syncs budgets; not entitled revokes every grant; both\n retry owed deletions (also for active grants: they are old keys). The\n plan's budget is the grant's `metadata.budget` (`{ limitMicros, window }`).\n A replayed webhook diffs to \"no change\", so hosts also call the reconciler\n with `snapshotEntitlements()` on redelivery and on a schedule; that is\n what repairs a reaction lost to a crash. Per-user failures are thrown\n together after all users were tried.\n- **Keys.** Never in results, errors (gateway failures carry only the\n operation and error code), audit details, `runOnce()` results or logs.\n Usage rows carry `source: hosted` and `gatewayKeyAlias` (from\n `InferenceTarget.usageTags`). Other processes see a new binding after the\n resolver cache expires; this process is invalidated through\n `invalidateUserInferenceResolvers()`.\n\n## Spend gate and kill switch (`src/gate.ts`, #4760)\n\n`createHostedInferenceGate({ killSwitch, spend, principal?,\nrequireSubscription?, onWarning? })` is core's `InferenceGate` (seam:\n[core inference.md](../../core/agents/inference.md), \"Hosted gate\");\n`registerHostedInferenceGate(gate | options)` installs it and the\nprincipal's user as the `userId` usage tag. Host wiring:\n\n```ts\nregisterHostedInferenceGate({\n killSwitch: new KillSwitchService({ db }), // smrt-features\n spend: await HostedAiSpendEvaluator.create({ db }), // smrt-subscriptions\n});\n```\n\nBoth stores are structural: smrt-features and smrt-subscriptions build with\nthe CLI, which depends on this package, so a dependency on either is a turbo\ncycle. Checks, in order, on every `source: hosted` call:\n\n1. **Kill switch** `inference.hosted.enabled` (`HOSTED_INFERENCE_KILL_SWITCH`):\n global DISABLE, then the tenant's DISABLE, blocks (`policy:\n 'kill-switch'`, `disabledBy`). Uncached, no model call: **the incident\n lever** (`smrt inference:hosted disable [--tenant <id>]`; programmatic\n `setHostedInferenceEnabled(store, { enabled, tenantId? })`,\n `getHostedInferenceSwitch()`). Stored as smrt-features override rows\n with kill-switch semantics, not as a flag: a tenant ENABLE can never\n lift a global DISABLE, and `inference.hosted` (the plan key) stays a pure\n entitlement. Hosts with an admin UI write the same DISABLE rows through\n `FeatureOverrideService` and their authorizer.\n2. **Tenant**: request tenant, else the principal's; none blocks (`no-tenant`).\n3. **Entitlement**: no entitled subscription blocks (`subscription`) unless\n `requireSubscription: false`.\n4. **Spend**: the plan's tenant and per-user caps (smrt-subscriptions\n AGENTS, \"Hosted AI spend caps\"): `blocked` blocks with `cap`, `spend`\n (micro-dollars) and `resetsAt`; `warn` returns `warn` and calls\n `onWarning` (errors swallowed). The user is the principal's, only in its\n own tenant, and none for `userId: null` (agents).\n\nAny thrown error propagates and core blocks with `gate-error`. The plan\ncheck does not test the `inference.hosted` feature key: provisioning the\nhosted binding (#4759) is where entitlement to hosted is granted.\n"
328
328
  },
329
329
  {
330
330
  "path": "agents/fusions.md",
@@ -5,10 +5,10 @@ description: "Inference alias chains with classified failures, recorded fallback
5
5
  status: "stable"
6
6
  generated:
7
7
  by: "smrt/scripts/generate-knowledge-okf.ts"
8
- at: "2026-11-20T08:08:49Z"
8
+ at: "2026-11-26T19:55:18Z"
9
9
  audience: "internal"
10
10
  evidence_level: "source-inspected"
11
- source_revision: "sha256:0dc29ac63d082b219e0de21dbe5633be474c74666912b6ec88aa71b5d82ece7a"
11
+ source_revision: "sha256:04e82fc83baec4d9abe1d6732cbb0db0793fb59f8024a91002561291276afd9a"
12
12
  sources:
13
13
  - id: "manifest"
14
14
  resource: "https://github.com/happyvertical/smrt/blob/main/packages/inference/package.json"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-inference",
3
- "version": "0.71.0",
3
+ "version": "0.73.0",
4
4
  "description": "Inference alias chains with classified failures, recorded fallback and ladder degradation, consumer-defined fusions, per-user and per-tenant bindings, the InferenceSettingsPanel, hosted provisioning and spend gate, and the smrt doctor --ai binding check, for SMRT inference tiers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,16 +51,16 @@
51
51
  "dependencies": {
52
52
  "@happyvertical/ai": "^0.116.6",
53
53
  "@happyvertical/auth": "^0.116.6",
54
- "@happyvertical/smrt-config": "0.71.0",
55
- "@happyvertical/smrt-core": "0.71.0",
56
- "@happyvertical/smrt-prompts": "0.71.0",
57
- "@happyvertical/smrt-secrets": "0.71.0",
58
- "@happyvertical/smrt-tenancy": "0.71.0",
59
- "@happyvertical/smrt-users": "0.71.0",
54
+ "@happyvertical/smrt-config": "0.73.0",
55
+ "@happyvertical/smrt-core": "0.73.0",
56
+ "@happyvertical/smrt-prompts": "0.73.0",
57
+ "@happyvertical/smrt-secrets": "0.73.0",
58
+ "@happyvertical/smrt-tenancy": "0.73.0",
59
+ "@happyvertical/smrt-users": "0.73.0",
60
60
  "@happyvertical/sql": "^0.116.6"
61
61
  },
62
62
  "devDependencies": {
63
- "@happyvertical/smrt-vitest": "0.71.0",
63
+ "@happyvertical/smrt-vitest": "0.73.0",
64
64
  "@sveltejs/package": "^2.5.8",
65
65
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
66
66
  "@types/node": "24.13.6",