@happyvertical/smrt-inference 0.61.6 → 0.62.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.
- package/AGENTS.md +3 -1
- package/README.md +4 -0
- package/agents/engines.md +87 -90
- package/agents/fusions.md +13 -5
- package/dist/agent-cli/session.d.ts +8 -2
- package/dist/agent-cli/session.d.ts.map +1 -1
- package/dist/agent-cli/stream.d.ts +5 -0
- package/dist/agent-cli/stream.d.ts.map +1 -1
- package/dist/agent-cli/test-support.d.ts.map +1 -1
- package/dist/agent-cli/test-support.js +1 -1
- package/dist/agent-cli/test-support.js.map +1 -1
- package/dist/agent-cli/turn.d.ts +12 -5
- package/dist/agent-cli/turn.d.ts.map +1 -1
- package/dist/assistant-settings.d.ts +26 -0
- package/dist/assistant-settings.d.ts.map +1 -0
- package/dist/chatgpt/model.d.ts +14 -6
- package/dist/chatgpt/model.d.ts.map +1 -1
- package/dist/chunks/{InferenceOverrideCollection-Bd-FsdB1.js → InferenceOverrideCollection-DKtFQ5gd.js} +3 -66
- package/dist/chunks/InferenceOverrideCollection-DKtFQ5gd.js.map +1 -0
- package/dist/chunks/model-fallback-BVD3BzkG.js +171 -0
- package/dist/chunks/model-fallback-BVD3BzkG.js.map +1 -0
- package/dist/chunks/{provider-config-BSpIQRVM.js → provider-config-Q1WaQKfo.js} +164 -31
- package/dist/chunks/provider-config-Q1WaQKfo.js.map +1 -0
- package/dist/classify.d.ts +9 -0
- package/dist/classify.d.ts.map +1 -1
- package/dist/engine-tiers.d.ts +100 -0
- package/dist/engine-tiers.d.ts.map +1 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/fusion.d.ts +7 -1
- package/dist/fusion.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +92 -205
- package/dist/model-fallback.d.ts +63 -0
- package/dist/model-fallback.d.ts.map +1 -0
- package/dist/models.d.ts +0 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +2 -2
- package/dist/node.js +1 -1
- package/dist/resolver.js +1 -1
- package/dist/server.d.ts +3 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +79 -130
- package/dist/server.js.map +1 -1
- package/dist/smrt-knowledge.json +16 -88
- package/dist/smrt-knowledge.okf.md +6 -11
- package/dist/svelte/components/InferenceAssistantSettings.svelte +98 -0
- package/dist/svelte/components/InferenceAssistantSettings.svelte.d.ts +19 -0
- package/dist/svelte/components/InferenceAssistantSettings.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InferenceSettingsPanel.svelte +22 -1
- package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts +10 -2
- package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts.map +1 -1
- package/dist/svelte/components/InferenceUsageTable.svelte +7 -7
- package/dist/svelte/components/InferenceUsageTable.svelte.d.ts +1 -1
- package/dist/svelte/index.d.ts +1 -1
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/types.d.ts +27 -4
- package/dist/svelte/types.d.ts.map +1 -1
- package/dist/svelte/types.js +4 -4
- package/package.json +100 -9
- package/agents/design-runs.md +0 -110
- package/dist/chunks/InferenceOverrideCollection-Bd-FsdB1.js.map +0 -1
- package/dist/chunks/provider-config-BSpIQRVM.js.map +0 -1
- package/dist/chunks/work-profiles-DCgIbilc.js +0 -484
- package/dist/chunks/work-profiles-DCgIbilc.js.map +0 -1
- package/dist/design-run-store.d.ts +0 -26
- package/dist/design-run-store.d.ts.map +0 -1
- package/dist/design-run.d.ts +0 -146
- package/dist/design-run.d.ts.map +0 -1
- package/dist/models/DesignRunRecord.d.ts +0 -22
- package/dist/models/DesignRunRecord.d.ts.map +0 -1
- package/dist/work-profiles.d.ts +0 -127
- package/dist/work-profiles.d.ts.map +0 -1
package/agents/design-runs.md
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# Durable design runs
|
|
2
|
-
|
|
3
|
-
`createDesignRunDriver` is an engine-neutral ordered pass executor. A run is a
|
|
4
|
-
workflow record in `_smrt_inference_design_runs`, not a second queue. Run normal
|
|
5
|
-
application migrations before starting it. The host admits work through existing
|
|
6
|
-
`SmrtJobCollection.enqueueJob` and executes it through `TaskRunner`; browser
|
|
7
|
-
connection lifetime must never own its cancellation signal.
|
|
8
|
-
|
|
9
|
-
The host binds `createDesignRunStore` to the authenticated owner and tenant. Its
|
|
10
|
-
`enqueue(transaction, state)` callback enqueues the existing job in that same
|
|
11
|
-
transaction, using the stable run id as `dedupeKey`. Start and resume either save
|
|
12
|
-
the checkpoint and admit the job together, or neither commits. Run ids are UUIDs.
|
|
13
|
-
All generated REST, CLI, and MCP surfaces on `DesignRunRecord` are disabled.
|
|
14
|
-
|
|
15
|
-
Install `installDesignRunExecutor(db, handler)` once when booting the host. Its
|
|
16
|
-
handler receives the hydrated record, arguments and runner context. Verify
|
|
17
|
-
`isRunnerExecutionContext`, the job target, tenant and current owner authority;
|
|
18
|
-
then build a worker store whose `authorizeWrite(transaction, state)` verifies the
|
|
19
|
-
live job claim on every checkpoint. Pass the runner's `signal` to `driver.run`.
|
|
20
|
-
Supply `ownsExecution` with that same live claim proof so a recovered job can
|
|
21
|
-
replace the crashed pass's stale lease immediately. Only `execute` is background-eligible. The installer returns teardown; reinstall
|
|
22
|
-
it after process restart before starting the runner.
|
|
23
|
-
|
|
24
|
-
A host definition pins a version string and an ordered list of plain-text pass
|
|
25
|
-
names and JSON schemas. Every engine, including CLI engines, returns an object
|
|
26
|
-
through `executePass`; the mandatory host `validate(schema, output)` callback
|
|
27
|
-
must use a full JSON Schema implementation such as Ajv, not a partial handwritten
|
|
28
|
-
validator. Invalid outputs and validation errors are checkpointed and supplied to
|
|
29
|
-
the next repair attempt. Repairs stop at `repairRetries`. Accepted outputs are
|
|
30
|
-
checkpointed before deterministic `check` code runs. Checks receive their own
|
|
31
|
-
abort signal, may feed facts to the next pass, request a bounded repeat, or pause
|
|
32
|
-
for owner approval. Checks must be read-only or idempotent because a crash may
|
|
33
|
-
replay them. A profile supplies quality and budgets, never permission or approval.
|
|
34
|
-
|
|
35
|
-
An approval hold retains the accepted output, current pass index and `check`
|
|
36
|
-
phase, clears repair state and releases the settled check lease. Resume reruns
|
|
37
|
-
that same check, including for the final pass; only a cleared check can advance
|
|
38
|
-
or finish the run. It never calls the model again for that accepted output or
|
|
39
|
-
duplicates its attempts/token usage. A denied check may fail terminally. Hosts
|
|
40
|
-
must give effects stable identities and recover their exact recorded result
|
|
41
|
-
when replay follows a crash after apply but before the completion checkpoint.
|
|
42
|
-
Recover a running/checking job by calling `run` under its legitimate replacement
|
|
43
|
-
TaskRunner claim (`ownsExecution`), without clearing leases through frontend
|
|
44
|
-
`resume`, weakening liveness proof or enabling generic failed-run retries.
|
|
45
|
-
For a definitive check rejection, the trusted host may return `failure` with
|
|
46
|
-
its own safe, static explanation. This ends the run as `failed`, retaining the
|
|
47
|
-
validated output, input, usage and attempts; it takes precedence over an approval
|
|
48
|
-
hold or repeat. Never copy model output or caught exception text into `failure`.
|
|
49
|
-
Ordinary thrown errors still receive the driver's generic failure explanation.
|
|
50
|
-
|
|
51
|
-
A trusted host check may return `complete: true` after mechanically validating
|
|
52
|
-
and applying its accepted proposal. This ends the run at its actual pass index,
|
|
53
|
-
retaining the `check` phase, input, outputs, attempts and accumulated usage. It
|
|
54
|
-
does not manufacture later passes or their usage. Failure, approval hold and
|
|
55
|
-
bounded repeat take precedence over completion, in that order. An approval hold
|
|
56
|
-
therefore resumes the same check before completion, without another model call.
|
|
57
|
-
Model output fields cannot select completion. Done runs remain terminal for
|
|
58
|
-
`run`, `stop` and `resume` even when their index is below the configured count.
|
|
59
|
-
The host owns versioned adaptive eligibility and exact owner-selected pass-count
|
|
60
|
-
semantics; the inference driver does not reinterpret work-profile budgets.
|
|
61
|
-
The existing design-run tests cover first/later completion, conflicting check
|
|
62
|
-
results, approval resume, lost completion CAS with same-action recovery under a
|
|
63
|
-
replacement claim, and stale completion after Stop.
|
|
64
|
-
|
|
65
|
-
Inputs carry resource ids. `readResource` rejects ids outside the host's pinned
|
|
66
|
-
list; the host checks current owner access and supplies summary-first pages with
|
|
67
|
-
opaque cursors. A page exceeding `toolResultChars`, including its envelope, is
|
|
68
|
-
rejected before it enters model context. Files and credentials are never inlined
|
|
69
|
-
into checkpoints.
|
|
70
|
-
|
|
71
|
-
Token and elapsed-time allowances accumulate across model calls, repair calls,
|
|
72
|
-
and mechanical checks. Before each call, the driver durably reserves its entire
|
|
73
|
-
allowed token and time budget. Successful calls reconcile to reported actual
|
|
74
|
-
usage; unknown token usage or a crash retains the reservation conservatively.
|
|
75
|
-
Checks reserve time too. A timeout or exhausted cumulative budget produces a
|
|
76
|
-
resumable `stopped` run with a plain explanation. Raise total budgets on resume;
|
|
77
|
-
usage never resets. Stop is cooperative: cancel the existing job as well, and
|
|
78
|
-
forward its signal into engine requests. A still-active pass lease prevents
|
|
79
|
-
immediate overlapping resume. The worker store's `authorizeRelease` must lock
|
|
80
|
-
and prove the captured job id, worker id and attempt (running or its terminal
|
|
81
|
-
Stop outcome, never a pending/recovered claim). `releaseLease` freshly reads a
|
|
82
|
-
stopped checkpoint with the same `leaseRevision` and atomically clears that
|
|
83
|
-
lease with a revision CAS. The driver calls it only after the original engine
|
|
84
|
-
or check promise truly settles; winning an abort/timeout race alone cannot
|
|
85
|
-
release a lease. A retained `leaseRevision` blocks frontend resume even after
|
|
86
|
-
its deadline. Crash recovery of a running job requires `ownsExecution` from a
|
|
87
|
-
replacement TaskRunner claim; a stopped run whose original process died needs
|
|
88
|
-
an explicit host liveness recovery path, never an inference from elapsed time
|
|
89
|
-
or missing jobs. A cooperative stopped call can therefore resume immediately
|
|
90
|
-
when its backing job has also settled. Delayed release cannot clear a newer
|
|
91
|
-
running/resumed claim. CAS revisions prevent stale workers overwriting
|
|
92
|
-
Stop or newer progress. Definitive schema/check failures end as `failed`.
|
|
93
|
-
|
|
94
|
-
Progress uses exactly `{ runId, pass: { index, count, name }, status, note? }`.
|
|
95
|
-
Indices are one-based. Statuses are `running`, `checking`, `waiting-approval`,
|
|
96
|
-
`stopped`, `failed`, and `done`. Publish this on the existing event stream;
|
|
97
|
-
subscriber failures cannot interrupt durable work. Each attempt stores its
|
|
98
|
-
`WorkRunMetadata`, including actual provider usage when available. Host tool
|
|
99
|
-
policy, durable approvals and history apply throughout all passes.
|
|
100
|
-
|
|
101
|
-
## Reuse audit
|
|
102
|
-
|
|
103
|
-
The intent index, `review_smrt_project` and `build_context` were consulted before
|
|
104
|
-
implementation. Searches across smrt-ui, smrt-svelte, chat, core, jobs and inference
|
|
105
|
-
found no existing ordered schema-repair driver. Existing `SmrtJob`, `TaskRunner`,
|
|
106
|
-
`McpTaskStore` and durable MCP continuations remain the queue, liveness,
|
|
107
|
-
cancellation and input primitives. Job events have independent retention and do
|
|
108
|
-
not provide atomic workflow CAS, so a dedicated inference workflow checkpoint
|
|
109
|
-
holds pass inputs/outputs and cumulative budgets. Inference depends on no jobs
|
|
110
|
-
runtime; the authenticated host supplies the transaction admission callback.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InferenceOverrideCollection-Bd-FsdB1.js","names":[],"sources":["../../src/__smrt-register__.ts","../../src/models/DesignRunRecord.ts","../../src/settings/cache.ts","../../src/settings/targets.ts","../../src/models/InferenceOverride.ts","../../src/models/InferenceOverrideCollection.ts"],"sourcesContent":["// Generated by @happyvertical/smrt-core smrtPlugin at library build time.\n// The package manifest is inlined so self-registration cannot miss when a\n// downstream bundler relocates this module away from dist/manifest.json\n// (https://github.com/happyvertical/smrt/issues/1506,\n// https://github.com/happyvertical/smrt/issues/1507).\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\nObjectRegistry.registerPackageManifest(JSON.parse(\"{\\\"version\\\":\\\"1.0.0\\\",\\\"timestamp\\\":0,\\\"packageName\\\":\\\"@happyvertical/smrt-inference\\\",\\\"packageVersion\\\":\\\"0.61.6\\\",\\\"objects\\\":{\\\"@happyvertical/smrt-inference:DesignRunRecord\\\":{\\\"name\\\":\\\"designrunrecord\\\",\\\"className\\\":\\\"DesignRunRecord\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-inference:DesignRunRecord\\\",\\\"collection\\\":\\\"designrunrecords\\\",\\\"description\\\":\\\"Domain checkpoint, not a queue: SmrtJob owns admission, worker liveness and cancellation. Generated mutations are closed; the host's authenticated store binds owner and tenant on every operation.\\\",\\\"filePath\\\":\\\"src/models/DesignRunRecord.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-inference\\\",\\\"fields\\\":{\\\"ownerId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\",\\\"default\\\"],\\\"required\\\":true,\\\"requiredFor\\\":\\\"identity\\\"},\\\"required\\\":true,\\\"default\\\":\\\"\\\"},\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"nullable\\\",\\\"required\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"revision\\\":{\\\"type\\\":\\\"integer\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"default\\\"]},\\\"required\\\":false,\\\"default\\\":0},\\\"payload\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\"],\\\"required\\\":true,\\\"requiredFor\\\":\\\"workflow-state\\\"},\\\"required\\\":true}},\\\"methods\\\":{\\\"execute\\\":{\\\"name\\\":\\\"execute\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"args\\\",\\\"type\\\":\\\"unknown\\\",\\\"optional\\\":false},{\\\"name\\\":\\\"context\\\",\\\"type\\\":\\\"unknown\\\",\\\"optional\\\":true}],\\\"returnType\\\":\\\"Promise<unknown>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_inference_design_runs\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"indexes\\\":[{\\\"name\\\":\\\"idx_inference_design_runs_owner\\\",\\\"columns\\\":[\\\"ownerId\\\",\\\"tenantId\\\"]}],\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"DesignRunRecord\\\",\\\"collectionExportName\\\":\\\"DesignRunRecordCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"ownerId\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"payload\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_inference_design_runs\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_inference_design_runs\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"owner_id\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"revision\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"payload\\\\\\\" TEXT NOT NULL\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"owner_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"revision\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"payload\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_inference_design_runs_tenant_id_slug_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true,\\\"nullsNotDistinct\\\":true},{\\\"name\\\":\\\"idx_inference_design_runs_owner\\\",\\\"columns\\\":[\\\"owner_id\\\",\\\"tenant_id\\\"]},{\\\"name\\\":\\\"_smrt_inference_design_runs_created_at_idx\\\",\\\"columns\\\":[\\\"created_at\\\"]}],\\\"version\\\":\\\"ab953d0b\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-inference/models\\\"},\\\"@happyvertical/smrt-inference:InferenceOverride\\\":{\\\"name\\\":\\\"inferenceoverride\\\",\\\"className\\\":\\\"InferenceOverride\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-inference:InferenceOverride\\\",\\\"collection\\\":\\\"inferenceoverrides\\\",\\\"filePath\\\":\\\"src/models/InferenceOverride.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-inference\\\",\\\"fields\\\":{\\\"binding\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\",\\\"default\\\"],\\\"required\\\":true,\\\"requiredFor\\\":\\\"identity\\\"},\\\"required\\\":true,\\\"default\\\":\\\"\\\"},\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"nullable\\\",\\\"required\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"target\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"tenantAllowList\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false}},\\\"methods\\\":{\\\"getValue\\\":{\\\"name\\\":\\\"getValue\\\",\\\"async\\\":false,\\\"parameters\\\":[],\\\"returnType\\\":\\\"unknown\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"getTenantAllowList\\\":{\\\"name\\\":\\\"getTenantAllowList\\\",\\\"async\\\":false,\\\"parameters\\\":[],\\\"returnType\\\":\\\"string[] | null\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"save\\\":{\\\"name\\\":\\\"save\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"options\\\",\\\"type\\\":\\\"SmrtSaveOptions\\\",\\\"optional\\\":true}],\\\"returnType\\\":\\\"Promise<this>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"delete\\\":{\\\"name\\\":\\\"delete\\\",\\\"async\\\":true,\\\"parameters\\\":[],\\\"returnType\\\":\\\"Promise<void>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_inference_overrides\\\",\\\"conflictColumns\\\":[\\\"binding\\\",\\\"context\\\"],\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"indexes\\\":[{\\\"name\\\":\\\"idx_smrt_inference_overrides_tenant\\\",\\\"columns\\\":[\\\"tenantId\\\",\\\"binding\\\"]}]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"InferenceOverride\\\",\\\"collectionExportName\\\":\\\"InferenceOverrideCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"binding\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_inference_overrides\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_inference_overrides\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"binding\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"target\\\\\\\" TEXT,\\\\n \\\\\\\"tenant_allow_list\\\\\\\" TEXT\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"binding\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"target\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"tenant_allow_list\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_inference_overrides_binding_context_idx\\\",\\\"columns\\\":[\\\"binding\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_inference_overrides_slug_context_idx\\\",\\\"columns\\\":[\\\"slug\\\",\\\"context\\\"]},{\\\"name\\\":\\\"idx_smrt_inference_overrides_tenant\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"binding\\\"]},{\\\"name\\\":\\\"_smrt_inference_overrides_created_at_idx\\\",\\\"columns\\\":[\\\"created_at\\\"]}],\\\"version\\\":\\\"4868b81b\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-inference/models\\\"},\\\"@happyvertical/smrt-inference:InferenceOverrideCollection\\\":{\\\"name\\\":\\\"inferenceoverridecollection\\\",\\\"className\\\":\\\"InferenceOverrideCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-inference:InferenceOverrideCollection\\\",\\\"collection\\\":\\\"inferenceoverrides\\\",\\\"description\\\":\\\"Reads and unauthorized writes of _smrt_inference_overrides.\\\",\\\"filePath\\\":\\\"src/models/InferenceOverrideCollection.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-inference\\\",\\\"fields\\\":{},\\\"methods\\\":{\\\"getScopeMap\\\":{\\\"name\\\":\\\"getScopeMap\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"scopeType\\\",\\\"type\\\":\\\"InferenceOverrideScopeType\\\",\\\"optional\\\":false,\\\"resolvedType\\\":\\\"'app' | 'tenant'\\\"},{\\\"name\\\":\\\"scopeId\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false}],\\\"returnType\\\":\\\"Promise<Map<string, InferenceOverride>>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"findByScope\\\":{\\\"name\\\":\\\"findByScope\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"binding\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false},{\\\"name\\\":\\\"scopeType\\\",\\\"type\\\":\\\"InferenceOverrideScopeType\\\",\\\"optional\\\":false,\\\"resolvedType\\\":\\\"'app' | 'tenant'\\\"},{\\\"name\\\":\\\"scopeId\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false}],\\\"returnType\\\":\\\"Promise<InferenceOverride | null>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"setOverride\\\":{\\\"name\\\":\\\"setOverride\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"binding\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false},{\\\"name\\\":\\\"scopeType\\\",\\\"type\\\":\\\"InferenceOverrideScopeType\\\",\\\"optional\\\":false,\\\"resolvedType\\\":\\\"'app' | 'tenant'\\\"},{\\\"name\\\":\\\"scopeId\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false},{\\\"name\\\":\\\"change\\\",\\\"type\\\":\\\"object\\\",\\\"optional\\\":false,\\\"memberTypes\\\":[\\\"unknown\\\",\\\"string[] | null\\\"]}],\\\"returnType\\\":\\\"Promise<InferenceOverride | null>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"removeOverride\\\":{\\\"name\\\":\\\"removeOverride\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"binding\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false},{\\\"name\\\":\\\"scopeType\\\",\\\"type\\\":\\\"InferenceOverrideScopeType\\\",\\\"optional\\\":false,\\\"resolvedType\\\":\\\"'app' | 'tenant'\\\"},{\\\"name\\\":\\\"scopeId\\\",\\\"type\\\":\\\"string\\\",\\\"optional\\\":false}],\\\"returnType\\\":\\\"Promise<boolean>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_inference_overrides\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"InferenceOverride\\\",\\\"exportName\\\":\\\"InferenceOverrideCollection\\\",\\\"collectionExportName\\\":\\\"InferenceOverrideCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-inference:InferenceOverride\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_inference_overrides\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_inference_overrides\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"binding\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"target\\\\\\\" TEXT,\\\\n \\\\\\\"tenant_allow_list\\\\\\\" TEXT\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"binding\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"target\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"tenant_allow_list\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_inference_overrides_binding_context_idx\\\",\\\"columns\\\":[\\\"binding\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_inference_overrides_slug_context_idx\\\",\\\"columns\\\":[\\\"slug\\\",\\\"context\\\"]},{\\\"name\\\":\\\"idx_smrt_inference_overrides_tenant\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"binding\\\"]},{\\\"name\\\":\\\"_smrt_inference_overrides_created_at_idx\\\",\\\"columns\\\":[\\\"created_at\\\"]}],\\\"version\\\":\\\"4868b81b\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-inference/models\\\"}},\\\"moduleType\\\":\\\"smrt\\\",\\\"smrtDependencies\\\":[\\\"@happyvertical/smrt-core\\\",\\\"@happyvertical/smrt-prompts\\\",\\\"@happyvertical/smrt-secrets\\\",\\\"@happyvertical/smrt-tenancy\\\",\\\"@happyvertical/smrt-users\\\"],\\\"browser\\\":{\\\"status\\\":\\\"server-only\\\",\\\"issues\\\":[\\\"#3617\\\",\\\"#3624\\\",\\\"#3626\\\",\\\"#3627\\\"],\\\"via\\\":[\\\"@happyvertical/smrt-profiles\\\",\\\"@happyvertical/smrt-secrets\\\",\\\"@happyvertical/smrt-tenancy\\\",\\\"@happyvertical/smrt-users\\\"]},\\\"stampsConstructors\\\":true}\"));\n","import { field, SmrtObject, smrt } from '@happyvertical/smrt-core';\nimport type { DatabaseInterface } from '@happyvertical/sql';\n\n/** Host installation is process-local; queued work remains durable in SmrtJob. */\nexport type DesignRunExecutor = (\n record: DesignRunRecord,\n args: unknown,\n context: unknown,\n) => Promise<unknown>;\nconst executors = new WeakMap<DatabaseInterface, DesignRunExecutor>();\n/** Install the authenticated TaskRunner bridge for this database; returns teardown. */\nexport function installDesignRunExecutor(\n db: DatabaseInterface,\n execute: DesignRunExecutor,\n): () => void {\n if (executors.has(db))\n throw new Error('A design run executor is already installed');\n executors.set(db, execute);\n return () => {\n if (executors.get(db) === execute) executors.delete(db);\n };\n}\n\n/**\n * Domain checkpoint, not a queue: SmrtJob owns admission, worker liveness and\n * cancellation. Generated mutations are closed; the host's authenticated store\n * binds owner and tenant on every operation. Migrate before using the driver.\n */\n@smrt({\n tableName: '_smrt_inference_design_runs',\n api: false,\n cli: false,\n mcp: false,\n indexes: [\n {\n name: 'idx_inference_design_runs_owner',\n columns: ['ownerId', 'tenantId'],\n },\n ],\n})\nexport class DesignRunRecord extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-inference\";\n static readonly backgroundEligibleMethods = ['execute'];\n\n /** Internal job target, never exposed as an API, CLI or MCP action. */\n async execute(args: unknown, context?: unknown): Promise<unknown> {\n const execute = executors.get(this.db);\n if (!execute) throw new Error('No host design run executor is installed');\n return execute(this, args, context);\n }\n\n @field({ required: true, requiredFor: 'identity' })\n ownerId: string = '';\n\n @field({ sqlType: 'UUID', nullable: true })\n tenantId: string | null = null;\n\n @field()\n revision: number = 0;\n\n /** JSON text avoids driver-specific JSON materialization on read/CAS. */\n @field({ type: 'text', required: true, requiredFor: 'workflow-state' })\n payload: string = '';\n}\n","/**\n * Process-wide write generation for `_smrt_inference_overrides` (#4754).\n * Every save or delete of an override row bumps it, so the override\n * resolver's short-lived layer cache never serves a value read before a\n * write in the same process. Kept on `globalThis` so duplicate module copies\n * (HMR, two bundles) share it, like core's resolver registration.\n */\nconst GENERATION_KEY = Symbol.for('smrt.inference.overrideGeneration');\n\ntype GenerationHolder = { [GENERATION_KEY]?: number };\n\n/** The current write generation. */\nexport function getInferenceOverrideGeneration(): number {\n return (globalThis as GenerationHolder)[GENERATION_KEY] ?? 0;\n}\n\n/** Record a write: cached layers read before it are stale. */\nexport function bumpInferenceOverrideGeneration(): void {\n const holder = globalThis as GenerationHolder;\n holder[GENERATION_KEY] = (holder[GENERATION_KEY] ?? 0) + 1;\n}\n","/**\n * The vocabulary of stored inference bindings (#4754): binding ids, the\n * target shapes a settings write may store, the allow-list references a\n * tenant write is checked against, and key-free labels.\n *\n * Pure and browser-safe: no `node:`, no SDK, no smrt-config.\n */\nimport {\n assertInferenceTranscriptsConfig,\n INFERENCE_TIERS,\n type InferenceAlias,\n type InferenceCandidate,\n type InferenceTarget,\n type InferenceTier,\n inferenceTargetKind,\n isInferenceTier,\n} from '@happyvertical/smrt-core';\n\n/** How a user or app gets inference. Stored as a user choice, never a binding. */\nexport const INFERENCE_MODES = ['byo', 'local', 'hosted', 'off'] as const;\nexport type InferenceMode = (typeof INFERENCE_MODES)[number];\n\n/** Binding id of `auto`'s default tier. */\nexport const DEFAULT_TIER_BINDING = 'default-tier';\n\n/**\n * Binding id of the app's transcript setting (#4781). App scope only:\n * tenants cannot override transcripts (owner decision 2026-11-08).\n */\nexport const TRANSCRIPTS_BINDING = 'transcripts';\n\n/** A binding id stored in `_smrt_inference_overrides.binding`. */\nexport type InferenceBindingId =\n | `tier:${InferenceTier}`\n | typeof DEFAULT_TIER_BINDING\n | typeof TRANSCRIPTS_BINDING\n | `alias:${string}`\n | `fusion:${string}`;\n\n/** `inference.aliases` / fusion names: what a binding id may carry after its prefix. */\nexport const INFERENCE_BINDING_NAME_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/i;\n\nexport type InferenceBindingKind =\n | 'tier'\n | 'default-tier'\n | 'transcripts'\n | 'alias'\n | 'fusion';\n\n/** A parsed binding id. */\nexport interface ParsedInferenceBinding {\n kind: InferenceBindingKind;\n /** The tier, alias or fusion name (absent for `default-tier`). */\n name?: string;\n}\n\n/** Thrown for a malformed binding id or an invalid stored value. Nothing is written. */\nexport class InferenceBindingValueError extends Error {\n readonly status = 400;\n constructor(\n readonly binding: string,\n reason: string,\n ) {\n super(`Invalid inference binding \"${binding}\": ${reason}`);\n this.name = 'InferenceBindingValueError';\n }\n}\n\n/** Parse a binding id, or `null` when it is not one this package stores. */\nexport function parseInferenceBinding(\n binding: unknown,\n): ParsedInferenceBinding | null {\n if (typeof binding !== 'string') return null;\n if (binding === DEFAULT_TIER_BINDING) return { kind: 'default-tier' };\n if (binding === TRANSCRIPTS_BINDING) return { kind: 'transcripts' };\n const match = /^(tier|alias|fusion):(.+)$/.exec(binding);\n if (!match) return null;\n const [, kind, name] = match as unknown as [string, string, string];\n if (kind === 'tier') {\n return isInferenceTier(name) ? { kind: 'tier', name } : null;\n }\n if (!INFERENCE_BINDING_NAME_PATTERN.test(name)) return null;\n return { kind: kind as 'alias' | 'fusion', name };\n}\n\n/** The binding id of one tier. */\nexport function tierBinding(tier: InferenceTier): `tier:${InferenceTier}` {\n return `tier:${tier}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction text(value: unknown): string | undefined {\n return typeof value === 'string' && value.trim() !== ''\n ? value.trim()\n : undefined;\n}\n\n/**\n * Key-shaped members are never stored in a binding row: keys live only in\n * smrt-secrets, written by the host (#4754 storage split). `apiKeyEnv` (the\n * name of a variable) is allowed, and so is `key`: #4753 fusion\n * definitions carry one as their identifier.\n */\nconst KEY_MEMBERS = new Set([\n 'apikey',\n 'api_key',\n 'apikeys',\n 'secret',\n 'token',\n 'password',\n 'authorization',\n 'bearer',\n]);\n\n/**\n * A deep copy of `value` with every credential-shaped member removed. Used\n * on every config-backed value a settings screen receives: config tiers and\n * alias candidates may legitimately carry a literal `apiKey` (resolvers and\n * endpoint-bound config), and none of it may reach a browser.\n */\nexport function stripKeyMembers<T>(value: T): T {\n if (Array.isArray(value)) return value.map(stripKeyMembers) as T;\n if (!isRecord(value)) return value;\n const out: Record<string, unknown> = {};\n for (const [member, inner] of Object.entries(value)) {\n if (KEY_MEMBERS.has(member.toLowerCase())) continue;\n out[member] = stripKeyMembers(inner);\n }\n return out as T;\n}\n\n/** Dotted path of the first key-shaped member anywhere in `value`, or `null`. */\nexport function findKeyMember(value: unknown, path = ''): string | null {\n if (Array.isArray(value)) {\n for (const [index, item] of value.entries()) {\n const found = findKeyMember(item, `${path}[${index}]`);\n if (found) return found;\n }\n return null;\n }\n if (!isRecord(value)) return null;\n for (const [member, inner] of Object.entries(value)) {\n const here = path ? `${path}.${member}` : member;\n if (KEY_MEMBERS.has(member.toLowerCase())) return here;\n const found = findKeyMember(inner, here);\n if (found) return found;\n }\n return null;\n}\n\n/**\n * The tier target a settings write may store. A tier binds exactly one of:\n *\n * - a model: `{ provider?, model }` (no `baseUrl`: an endpoint needs its own\n * key, and keys are never stored here; bind an alias whose candidate names\n * `baseUrl` + `apiKeyEnv` or a preset instead);\n * - an alias: `{ alias }`;\n * - a fusion (#4753): `{ kind: 'fusion', fusion }`.\n *\n * `null` means \"same as default\" (inherit the lower layer).\n */\nexport function normalizeTierTarget(\n binding: string,\n value: unknown,\n): InferenceTarget | null {\n if (value === null || value === undefined) return null;\n if (!isRecord(value)) {\n throw new InferenceBindingValueError(binding, 'a tier target is an object');\n }\n const keyMember = findKeyMember(value);\n if (keyMember) {\n throw new InferenceBindingValueError(\n binding,\n `\"${keyMember}\" looks like a credential; keys are stored only through smrt-secrets`,\n );\n }\n const fusion = text(value.fusion);\n const alias = text(value.alias);\n const model = text(value.model);\n const provider = text(value.provider);\n const kind = value.kind;\n const allowed = new Set(['kind', 'fusion', 'alias', 'model', 'provider']);\n const extra = Object.keys(value).filter((member) => !allowed.has(member));\n if (extra.length > 0) {\n throw new InferenceBindingValueError(\n binding,\n `unsupported member(s) ${extra.join(', ')} (endpoints and inline candidates belong in an alias)`,\n );\n }\n const shapes = [fusion, alias, model].filter(Boolean).length;\n if (shapes !== 1) {\n throw new InferenceBindingValueError(\n binding,\n 'a tier target is exactly one of { model, provider? }, { alias } or { kind: \"fusion\", fusion }',\n );\n }\n if (fusion) {\n if (kind !== undefined && kind !== 'fusion') {\n throw new InferenceBindingValueError(binding, 'fusion kind mismatch');\n }\n if (!INFERENCE_BINDING_NAME_PATTERN.test(fusion)) {\n throw new InferenceBindingValueError(binding, 'invalid fusion name');\n }\n return { kind: 'fusion', fusion } as unknown as InferenceTarget;\n }\n if (alias) {\n if (kind !== undefined && kind !== 'alias') {\n throw new InferenceBindingValueError(binding, 'alias kind mismatch');\n }\n if (!INFERENCE_BINDING_NAME_PATTERN.test(alias)) {\n throw new InferenceBindingValueError(binding, 'invalid alias name');\n }\n return { alias };\n }\n if (kind !== undefined && kind !== 'single') {\n throw new InferenceBindingValueError(binding, 'model kind mismatch');\n }\n return provider ? { provider, model } : { model };\n}\n\n/**\n * An alias definition a settings write may store: `{ candidates, description? }`,\n * every candidate exactly one of provider/model, preset/model or alias, and\n * never a literal key (`apiKeyEnv` names a variable and needs `baseUrl`).\n * Structural checks only; cross-references are checked against the layered\n * config by the settings service.\n */\nexport function normalizeAliasDefinition(\n binding: string,\n value: unknown,\n): InferenceAlias | null {\n if (value === null || value === undefined) return null;\n if (!isRecord(value) || !Array.isArray(value.candidates)) {\n throw new InferenceBindingValueError(\n binding,\n 'an alias is { candidates: [...], description? }',\n );\n }\n const keyMember = findKeyMember(value);\n if (keyMember) {\n throw new InferenceBindingValueError(\n binding,\n `\"${keyMember}\" looks like a credential; keys are stored only through smrt-secrets`,\n );\n }\n if (value.candidates.length === 0) {\n throw new InferenceBindingValueError(binding, 'an alias needs candidates');\n }\n const allowed = new Set([\n 'provider',\n 'model',\n 'baseUrl',\n 'apiKeyEnv',\n 'preset',\n 'alias',\n 'params',\n ]);\n const candidates: InferenceCandidate[] = value.candidates.map(\n (candidate: unknown, index: number) => {\n if (!isRecord(candidate)) {\n throw new InferenceBindingValueError(\n binding,\n `candidates[${index}] must be an object`,\n );\n }\n const extra = Object.keys(candidate).filter(\n (member) => !allowed.has(member),\n );\n if (extra.length > 0) {\n throw new InferenceBindingValueError(\n binding,\n `candidates[${index}] has unsupported member(s) ${extra.join(', ')}`,\n );\n }\n const out: InferenceCandidate = {};\n for (const member of allowed) {\n if (member === 'params') continue;\n const inner = text(candidate[member]);\n if (inner) (out as Record<string, string>)[member] = inner;\n }\n if (candidate.params !== undefined) {\n if (!isRecord(candidate.params)) {\n throw new InferenceBindingValueError(\n binding,\n `candidates[${index}].params must be an object`,\n );\n }\n out.params = { ...candidate.params };\n }\n return out;\n },\n );\n const description = text(value.description);\n return description ? { candidates, description } : { candidates };\n}\n\n/**\n * A fusion config entry (#4753) a settings write may store: a JSON object\n * with no credential members. Its meaning belongs to the fusion interpreter;\n * this package only stores it (app scope only).\n */\nexport function normalizeFusionDefinition(\n binding: string,\n value: unknown,\n): Record<string, unknown> | null {\n if (value === null || value === undefined) return null;\n if (!isRecord(value)) {\n throw new InferenceBindingValueError(binding, 'a fusion is a JSON object');\n }\n const keyMember = findKeyMember(value);\n if (keyMember) {\n throw new InferenceBindingValueError(\n binding,\n `\"${keyMember}\" looks like a credential; keys are stored only through smrt-secrets`,\n );\n }\n return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;\n}\n\n/** `default-tier` stores `{ tier }`. */\nexport function normalizeDefaultTier(\n binding: string,\n value: unknown,\n): InferenceTier | null {\n if (value === null || value === undefined) return null;\n const tier = isRecord(value) ? value.tier : value;\n if (!isInferenceTier(tier)) {\n throw new InferenceBindingValueError(\n binding,\n `the default tier must be one of ${INFERENCE_TIERS.join(', ')}`,\n );\n }\n return tier;\n}\n\n/** The stored transcript setting (#4781): core's app settings layer. */\nexport interface InferenceTranscriptSettingsValue {\n enabled?: boolean;\n /** Success capture rate, 0..1. */\n sample?: number;\n /** Per-row byte cap. */\n maxBytes?: number;\n}\n\nconst TRANSCRIPT_SETTING_MEMBERS = new Set(['enabled', 'sample', 'maxBytes']);\n\n/**\n * `transcripts` stores `{ enabled?, sample?, maxBytes? }`, validated by\n * core's `assertInferenceTranscriptsConfig()`. Per-prompt sampling stays in\n * config; any other member is refused.\n */\nexport function normalizeTranscriptSettings(\n binding: string,\n value: unknown,\n): InferenceTranscriptSettingsValue | null {\n if (value === null || value === undefined) return null;\n if (!isRecord(value)) {\n throw new InferenceBindingValueError(\n binding,\n 'the transcript setting must be an object',\n );\n }\n const extra = Object.keys(value).filter(\n (member) => !TRANSCRIPT_SETTING_MEMBERS.has(member),\n );\n if (extra.length > 0) {\n throw new InferenceBindingValueError(\n binding,\n `the transcript setting carries enabled, sample and maxBytes only (got ${extra.join(', ')})`,\n );\n }\n try {\n assertInferenceTranscriptsConfig(value);\n } catch (error) {\n throw new InferenceBindingValueError(\n binding,\n error instanceof Error ? error.message : String(error),\n );\n }\n const out: InferenceTranscriptSettingsValue = {};\n if (value.enabled !== undefined) out.enabled = value.enabled as boolean;\n if (value.sample !== undefined) out.sample = value.sample as number;\n if (value.maxBytes !== undefined) out.maxBytes = value.maxBytes as number;\n return Object.keys(out).length > 0 ? out : null;\n}\n\n/**\n * The allow-list reference of a tier target: `model:<provider>/<model>`\n * (`model:default/<model>` without a provider), `alias:<name>` or\n * `fusion:<name>`; for the default tier, `tier:<name>`. Key-free.\n */\nexport function inferenceTargetRef(target: InferenceTarget): string {\n const kind = inferenceTargetKind(target);\n const record = target as InferenceTarget & { fusion?: string };\n if (kind === 'fusion') return `fusion:${record.fusion ?? ''}`;\n if (kind === 'alias') return `alias:${target.alias ?? ''}`;\n if (kind === 'candidates') return 'candidates';\n return `model:${target.provider ?? 'default'}/${target.model ?? 'default'}`;\n}\n\n/**\n * Whether `ref` matches one allow-list pattern. A pattern is an exact\n * reference, a prefix ending in `*` (`model:openai/*`, `alias:*`), or `*`.\n */\nexport function matchesAllowPattern(ref: string, pattern: string): boolean {\n if (pattern === '*') return true;\n if (pattern.endsWith('*')) return ref.startsWith(pattern.slice(0, -1));\n return ref === pattern;\n}\n\n/**\n * The tenant allow-list check: a tenant may bind only a reference the app\n * row's list matches. No list (or an empty one) allows nothing, so a tenant\n * cannot bind a tier the operator has not opened.\n */\nexport function isAllowedByList(\n ref: string,\n allowList: readonly string[] | null | undefined,\n): boolean {\n return (allowList ?? []).some((pattern) => matchesAllowPattern(ref, pattern));\n}\n\n/** Validate and normalize an allow-list (patterns are short, key-free references). */\nexport function normalizeAllowList(\n binding: string,\n value: unknown,\n): string[] | null {\n if (value === null || value === undefined) return null;\n if (!Array.isArray(value)) {\n throw new InferenceBindingValueError(\n binding,\n 'an allow-list is an array of references',\n );\n }\n const out: string[] = [];\n for (const entry of value) {\n if (\n typeof entry !== 'string' ||\n !/^(\\*|(model|alias|fusion|tier):[A-Za-z0-9._/:*-]{1,160})$/.test(entry)\n ) {\n throw new InferenceBindingValueError(\n binding,\n `invalid allow-list entry ${JSON.stringify(entry)}`,\n );\n }\n if (!out.includes(entry)) out.push(entry);\n }\n return out;\n}\n\n/** Key-free description of a tier target for screens and reports. */\nexport function describeInferenceTarget(\n target: InferenceTarget | null | undefined,\n): string {\n if (!target || Object.keys(target).length === 0) {\n return 'Same as default (configured client)';\n }\n const kind = inferenceTargetKind(target);\n const record = target as InferenceTarget & { fusion?: string };\n if (kind === 'fusion') return `Fusion ${record.fusion ?? '?'}`;\n if (kind === 'alias') return `Alias ${target.alias ?? '?'}`;\n if (kind === 'candidates') {\n return `${target.candidates?.length ?? 0} inline candidate(s)`;\n }\n return `${target.provider ?? 'default'}/${target.model ?? 'default model'}`;\n}\n","import {\n field,\n SmrtObject,\n type SmrtObjectOptions,\n type SmrtSaveOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { bumpInferenceOverrideGeneration } from '../settings/cache.js';\nimport {\n InferenceBindingValueError,\n normalizeAliasDefinition,\n normalizeAllowList,\n normalizeDefaultTier,\n normalizeFusionDefinition,\n normalizeTierTarget,\n normalizeTranscriptSettings,\n parseInferenceBinding,\n} from '../settings/targets.js';\n\n/** `context` (and `scopeId`) of the app-wide row. */\nexport const APP_INFERENCE_SCOPE_ID = '__app__';\n\nexport interface InferenceOverrideOptions extends SmrtObjectOptions {\n binding?: string;\n tenantId?: string | null;\n target?: string | null;\n tenantAllowList?: string | null;\n}\n\nfunction parseJson(binding: string, raw: string | null, what: string): unknown {\n if (raw === null) return null;\n try {\n return JSON.parse(raw);\n } catch {\n throw new InferenceBindingValueError(binding, `${what} is not valid JSON`);\n }\n}\n\n// One row per (binding, scope): `tier:<tier>`, `default-tier`,\n// `alias:<name>` or `fusion:<name>`, at the app scope (`tenantId = null`) or\n// one tenant's. Rows are authorization state for every scope and `tenantId`\n// is an ordinary settable field, not request-derived tenant scoping, so the\n// generated REST, CLI and MCP surfaces are closed (mirrors\n// `_smrt_prompt_overrides`, #3013). Hosts write through\n// `InferenceOverrideService`, which asks a host authorizer before every write\n// and fails closed. Keys never live here: `save()` refuses any credential-\n// shaped member; keys go to smrt-secrets through the host.\n@smrt({\n tableName: '_smrt_inference_overrides',\n conflictColumns: ['binding', 'context'],\n api: false,\n cli: false,\n mcp: false,\n indexes: [\n {\n name: 'idx_smrt_inference_overrides_tenant',\n columns: ['tenantId', 'binding'],\n },\n ],\n})\nexport class InferenceOverride extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-inference\";\n @field({ required: true, requiredFor: 'identity' })\n binding: string = '';\n\n // Not tenant-scoped (any scope is writable through the authorized service),\n // but the value is a tenant id: uuid on PostgreSQL, like every tenant_id.\n @field({ sqlType: 'UUID', nullable: true })\n tenantId: string | null = null;\n\n /**\n * JSON of the bound value; `null` inherits the lower layer. Tier rows hold\n * a tier target, `default-tier` holds `{ tier }`, alias rows an alias, and\n * fusion rows a fusion config entry.\n */\n @field({ type: 'text', nullable: true })\n target: string | null = null;\n\n /**\n * App rows of `tier:*` and `default-tier` only: JSON array of the target\n * references a tenant may bind (`model:openai/*`, `alias:local`,\n * `fusion:review-pair`, `tier:good`, `*`). No list allows nothing. This is\n * the stored half of the tenant allow-list; the service's\n * `tenantTargetPolicy` hook is the code half (#4667 caps the maximum\n * hosted tier there).\n */\n @field({ type: 'text', nullable: true })\n tenantAllowList: string | null = null;\n\n constructor(options: InferenceOverrideOptions = {}) {\n super(options);\n if (options.binding !== undefined) this.binding = options.binding;\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.target !== undefined) this.target = options.target;\n if (options.tenantAllowList !== undefined) {\n this.tenantAllowList = options.tenantAllowList;\n }\n }\n\n /** The parsed, validated stored value (`null` inherits). */\n getValue(): unknown {\n return this.normalizedValue();\n }\n\n /** The parsed allow-list (`null` when the row carries none). */\n getTenantAllowList(): string[] | null {\n return normalizeAllowList(\n this.binding,\n parseJson(this.binding, this.tenantAllowList, 'tenantAllowList'),\n );\n }\n\n override async save(options?: SmrtSaveOptions): Promise<this> {\n this.validateOverride();\n // `context` is the uniqueness scope so the app row stays unique even\n // though `tenantId` is nullable (as in `_smrt_prompt_overrides`).\n this.context = this.tenantId ?? APP_INFERENCE_SCOPE_ID;\n const result = await super.save(options);\n bumpInferenceOverrideGeneration();\n return result;\n }\n\n override async delete(): Promise<void> {\n await super.delete();\n bumpInferenceOverrideGeneration();\n }\n\n private normalizedValue(): unknown {\n const parsed = parseInferenceBinding(this.binding);\n if (!parsed) {\n throw new InferenceBindingValueError(\n String(this.binding),\n 'unknown binding id',\n );\n }\n const raw = parseJson(this.binding, this.target, 'target');\n switch (parsed.kind) {\n case 'tier':\n return normalizeTierTarget(this.binding, raw);\n case 'default-tier':\n return normalizeDefaultTier(this.binding, raw);\n case 'transcripts':\n return normalizeTranscriptSettings(this.binding, raw);\n case 'alias':\n return normalizeAliasDefinition(this.binding, raw);\n case 'fusion':\n return normalizeFusionDefinition(this.binding, raw);\n }\n }\n\n private validateOverride(): void {\n const parsed = parseInferenceBinding(this.binding);\n if (!parsed) {\n throw new InferenceBindingValueError(\n String(this.binding),\n 'unknown binding id',\n );\n }\n if (this.tenantId !== null) {\n if (\n typeof this.tenantId !== 'string' ||\n !this.tenantId.trim() ||\n this.tenantId !== this.tenantId.trim() ||\n this.tenantId === APP_INFERENCE_SCOPE_ID\n ) {\n throw new InferenceBindingValueError(this.binding, 'invalid tenant id');\n }\n // Tenants bind tiers to allow-listed targets; they never define what a\n // name means. A tenant alias or fusion could redefine an allow-listed\n // name and bypass the list.\n if (parsed.kind === 'alias' || parsed.kind === 'fusion') {\n throw new InferenceBindingValueError(\n this.binding,\n 'aliases and fusions are defined at the app scope only',\n );\n }\n // Tenants cannot override transcripts (owner decision, #4781).\n if (parsed.kind === 'transcripts') {\n throw new InferenceBindingValueError(\n this.binding,\n 'the transcript setting is app scope only',\n );\n }\n if (this.tenantAllowList !== null) {\n throw new InferenceBindingValueError(\n this.binding,\n 'the tenant allow-list lives on the app row',\n );\n }\n }\n if (\n this.tenantAllowList !== null &&\n parsed.kind !== 'tier' &&\n parsed.kind !== 'default-tier'\n ) {\n throw new InferenceBindingValueError(\n this.binding,\n 'only tier and default-tier bindings carry a tenant allow-list',\n );\n }\n const value = this.normalizedValue();\n this.target = value === null ? null : JSON.stringify(value);\n const allowList = this.getTenantAllowList();\n this.tenantAllowList =\n allowList === null ? null : JSON.stringify(allowList);\n }\n}\n","import { SmrtCollection } from '@happyvertical/smrt-core';\nimport {\n APP_INFERENCE_SCOPE_ID,\n InferenceOverride,\n} from './InferenceOverride.js';\n\n/** `app` (the `__app__` row) or one tenant. */\nexport type InferenceOverrideScopeType = 'app' | 'tenant';\n\n/**\n * Reads and unauthorized writes of `_smrt_inference_overrides`. Hosts write\n * through `InferenceOverrideService` (authorizer-gated, fails closed); call\n * {@link setOverride} / {@link removeOverride} directly only after your own\n * authorization decision.\n */\nexport class InferenceOverrideCollection extends SmrtCollection<InferenceOverride> {\n static readonly _itemClass = InferenceOverride;\n\n /**\n * Every row of one scope, keyed by binding id: one bounded read. An\n * enumeration read: build the collection without list bounds (the\n * settings service does) so a host-wide `maxListLimit` cannot drop a row.\n */\n async getScopeMap(\n scopeType: InferenceOverrideScopeType,\n scopeId: string,\n ): Promise<Map<string, InferenceOverride>> {\n const tenantId = scopeType === 'app' ? null : scopeId;\n const rows = await this.list({ where: { tenantId } });\n const result = new Map<string, InferenceOverride>();\n for (const row of rows) result.set(row.binding, row);\n return result;\n }\n\n /** The row for one binding at one scope. */\n async findByScope(\n binding: string,\n scopeType: InferenceOverrideScopeType,\n scopeId: string,\n ): Promise<InferenceOverride | null> {\n const tenantId = scopeType === 'app' ? null : scopeId;\n const rows = await this.list({ where: { binding, tenantId }, limit: 1 });\n return rows[0] ?? null;\n }\n\n /**\n * Set the stored value (and, for app rows, optionally the tenant\n * allow-list) of one binding at one scope, creating the row when needed.\n * `undefined` leaves a column untouched; `null` clears it. A row left with\n * neither a value nor an allow-list is deleted.\n */\n async setOverride(\n binding: string,\n scopeType: InferenceOverrideScopeType,\n scopeId: string,\n change: { target?: unknown; tenantAllowList?: string[] | null },\n ): Promise<InferenceOverride | null> {\n const existing = await this.findByScope(binding, scopeType, scopeId);\n const target =\n change.target === undefined\n ? (existing?.target ?? null)\n : change.target === null\n ? null\n : JSON.stringify(change.target);\n const tenantAllowList =\n change.tenantAllowList === undefined\n ? (existing?.tenantAllowList ?? null)\n : change.tenantAllowList === null\n ? null\n : JSON.stringify(change.tenantAllowList);\n\n if (target === null && tenantAllowList === null) {\n if (existing) await existing.delete();\n return null;\n }\n if (existing) {\n existing.target = target;\n existing.tenantAllowList = tenantAllowList;\n await existing.save();\n return existing;\n }\n const created = await this.create({\n binding,\n tenantId: scopeType === 'app' ? null : scopeId,\n target,\n tenantAllowList,\n });\n await created.save();\n return created;\n }\n\n /** Delete the row for one binding at one scope, if any. */\n async removeOverride(\n binding: string,\n scopeType: InferenceOverrideScopeType,\n scopeId: string,\n ): Promise<boolean> {\n const existing = await this.findByScope(binding, scopeType, scopeId);\n if (!existing) return false;\n await existing.delete();\n return true;\n }\n}\n\nexport { APP_INFERENCE_SCOPE_ID };\n"],"mappings":";;AAOA,eAAe,wBAAwB,KAAK,MAAM,ssWAAsmZ,CAAC;;;;;;;;;;;;;;;;;;ACEzpZ,IAAM,4BAAY,IAAI,QAA8C;AAE7D,SAAS,yBACd,IACA,SACY;CACZ,IAAI,UAAU,IAAI,EAAE,GAClB,MAAM,IAAI,MAAM,4CAA4C;CAC9D,UAAU,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