@happyvertical/smrt-prompts 0.60.13 → 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.
- package/AGENTS.md +36 -3
- package/README.md +4 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -21
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/prompt-resolver.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +14 -5
- package/dist/smrt-knowledge.okf.md +2 -2
- package/dist/types.d.ts +70 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +60 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/smrt-knowledge.json
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
"sensitiveFieldsExcluded": true,
|
|
4
4
|
"generatedAt": "1970-01-01T00:00:00.000Z",
|
|
5
5
|
"packageName": "@happyvertical/smrt-prompts",
|
|
6
|
-
"packageVersion": "0.60.
|
|
6
|
+
"packageVersion": "0.60.15",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
12
|
-
"agents": "
|
|
10
|
+
"manifest": "90e9c6e0ddd3f396be214f92dda3f103047e02c8cb4ebae9df9eac51bf211e9e",
|
|
11
|
+
"packageJson": "66a019c21323ec66ba2f83526e44619773d9161575963214b0bbb24355ec72b3",
|
|
12
|
+
"agents": "fb798c2b8642b3860effb0926297edde46293895705df1ac95cc5bfddc211577"
|
|
13
13
|
},
|
|
14
14
|
"exports": [
|
|
15
15
|
".",
|
|
@@ -360,8 +360,17 @@
|
|
|
360
360
|
{
|
|
361
361
|
"filePath": "src/prompt-settings.test.ts"
|
|
362
362
|
},
|
|
363
|
+
{
|
|
364
|
+
"filePath": "src/prompt-tiers.test.ts"
|
|
365
|
+
},
|
|
363
366
|
{
|
|
364
367
|
"filePath": "src/public-surface.test.ts"
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
"filePath": "src/usage-tags.test.ts"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
"filePath": "src/utils.ts"
|
|
365
374
|
}
|
|
366
375
|
],
|
|
367
376
|
"relationshipsV2": {
|
|
@@ -372,7 +381,7 @@
|
|
|
372
381
|
"polymorphicAssociations": 0,
|
|
373
382
|
"uuidColumns": 4
|
|
374
383
|
},
|
|
375
|
-
"agentDoc": "# smrt-prompts\n\nSMRT prompt registry and tenant-aware prompt override package. Code defines defaults; config layers and DB-stored overrides personalize at app and tenant levels.\n\n## Core pieces\n\n- `definePrompt()` registers code defaults in a global process registry (`globalThis.__smrtPromptRegistry`)\n- `resolvePrompt()` merges code defaults, file/config overrides (via `@happyvertical/smrt-config`), stored app-level overrides, stored tenant-level overrides, and a runtime override\n- `PromptOverride` (`_smrt_prompt_overrides` table) stores partial app-level and tenant-level overrides with write-time validation\n- `PromptOverrideCollection` — collection API, plus `setTemplateOverride()` / `removeOverride()` / `findByScope()` / `getOverrideMapForKeys()` for the write and enumeration paths below\n- `PromptOverrideService` — the only write path a host should use directly; asks a host-supplied authorizer before every write and fails closed (mirrors `FeatureOverrideService`, #3013); before authorizing it rejects any scope the resolver never reads (`InvalidPromptScopeError`: unknown type, app id other than `__app__`, blank/untrimmed/`__app__` tenant id), so a malformed tenant write cannot reach the app-wide row\n- `PromptSettingsService` — read/write helper for a management screen: `listPromptSettings()` returns one `PromptSettingsRow` per registered key (the effective template, `appTemplate`/`tenantTemplate` for the raw override at each scope, `appDefaultTemplate`/`inheritedTemplate` for what reverting each scope produces, and `supplyingLevel`); `setPromptOverride()` refuses unknown keys and fields the definition marks not editable, then delegates to `PromptOverrideService` (#3053)\n- `./svelte` subpath — `PromptSettingsPanel`, the presentational management panel (#3053)\n\n## Resolution layers (priority low → high)\n\n1. Code default — registered via `definePrompt({ key, template, ai })`\n2. File/config override — `getPackageConfig<PromptPackageConfig>('prompts', defaults)`\n3. App-level stored override — `PromptOverride` row with `tenantId = null`\n4. Tenant-level stored override — `PromptOverride` row with current tenant\n5. Runtime override — passed to `resolvePrompt({ overrides })`\n\nEach layer can override any subset of fields (template, profile, model, params). Inheritance is field-by-field.\n\n## Conventions\n\n- **Namespace prompt keys** by package or domain: `projects.issue.incorporateFeedback`, `content.summarize.headline`\n- **Stored overrides use nullable fields** so inheritance stays field-by-field — null means \"use the lower layer\"\n- **Provider selection is indirect** in v1: prompts select named profiles, and profiles resolve to provider/model in `smrt-config`\n- **`editable` flags are enforced on `PromptOverride.save()`** — definitions can lock specific fields against tenant override\n\n## Generated surfaces\n\n`PromptOverride` ships with generated REST routes, MCP tools, and CLI commands\nclosed (`api: false`, `cli: false`, `mcp: false`, mirrors `FeatureOverride`,\n#3013). Override rows are authorization state for every scope and `tenantId` is\nan ordinary settable field, not request-derived tenant scoping — a generated\nauthentication-only surface would let any signed-in principal set another\ntenant's prompt text. Hosts write overrides server-side with\n`PromptOverrideService` (which requires an explicit authorizer for every\nwrite) or `PromptOverrideCollection.setTemplateOverride()` /\n`removeOverride()` only after their own authorization decision.\n\n## Management UI (`./svelte`)\n\n- Built like every other Svelte-shipping package here (`smrt-features`/`smrt-tenancy` are the closest models): `vite build --mode library && svelte-package -i src/svelte -o dist/svelte`, an `./svelte` export with a `svelte` condition, `svelte` as an **optional** peer dependency, plus `scripts/prune-svelte-package-artifacts.js` so `svelte-package` does not copy `__tests__/` into the published `dist/svelte`. The root export stays Svelte-free so server-only consumers are unaffected.\n- `PromptSettingsPanel` is presentational: rows and callbacks in, no fetching, no authorization. `src/svelte/types.ts` deliberately imports nothing from `smrt-core` or the `@smrt()` models, so the browser bundle stays thin; `PromptSettingsRow` is structurally assignable to `PromptSettingsView`.\n- Each row is its own `<form>` with a checkbox + `<textarea>` pair per scope (`tenantOverride`/`tenantTemplate`, and `appOverride`/`appTemplate` when `showApp` is set). The checkbox's presence in the submitted `FormData` — not whether the textarea is disabled — decides override vs. revert, because a plain HTML submit cannot un-disable a field the browser already marked disabled. `onSave` reads the same `FormData` when driving the panel from a client handler instead of `formAction`.\n- Two invariants, both regression-tested. (1) The \"revert\" preview never claims the bare registry default: `tenantRevertPreview()` shows `inheritedTemplate` (registry + config + app override), falling back to `appDefaultTemplate` only when the row does not carry it, and `appRevertPreview()` shows `appDefaultTemplate` (registry + config, never the app override itself). `PromptSettingsService` computes both explicitly rather than deriving one from the other — an earlier draft reused the app-only merge as the \"no tenant requested\" effective value and broke both. (2) The rows remount on `contextKey ?? prompts`, so an unsaved edit cannot survive a reload or a tenant switch and be submitted against the new rows.\n- **Authorization stays with the consumer.** `PromptSettingsService` reads are unfiltered and every write goes through `PromptOverrideService`; constructing the settings service without an `authorize` option makes it read-only (writes fail closed). Never add an authorization decision to this package.\n- `vitest.config.ts` runs two projects (`server` node + `smrtVitestPlugin`, `svelte` jsdom + `@sveltejs/vite-plugin-svelte` with `conditions: ['browser']`) because the browser condition would send `smrt-core` to its browser build if applied globally.\n- `PromptSettingsService.create()` builds its `PromptOverrideCollection` with the caller's `defaultListLimit`/`maxListLimit` stripped before the bulk `getOverrideMapForKeys()` enumeration read that backs `listPromptSettings()` — the #3056 hazard class in `smrt-features`'s `FeatureOverrideCollection.getOverrideMap()`, applied here proactively rather than left for a follow-up issue. A host-configured list bound must never silently drop a key's override from a management screen.\n\n## Prompt keys are persisted identifiers\n\nOverrides are stored keyed by the exact `key` string and resolved by that\nstring at runtime. **Renaming a key orphans every existing override and\nsilently reverts every tenant to the registry default.** Treat a shipped key\nas immutable; a rename needs a data migration over\n`_smrt_prompt_overrides.key`, not an edit.\n\n## Caching\n\n`resolvePrompt()` results are cached per `(key, tenantId)` with a TTL. The cache is invalidated on `PromptOverride.save()` and `.delete()`. Use `clearPromptCache()` for manual invalidation in tests.\n\n**A monotonic per-`(db, key)` invalidation generation guards the cache write.**\nA resolution captures `getPromptCacheGeneration(key, db)` before its\nasynchronous layer loads and hands it back to `setCachedPromptBase()`; a\nconcurrent `save()` / `delete()` bumps the generation and the in-flight\nresolution is then refused the cache write instead of repopulating the key it\njust invalidated with the pre-write value. Without it, \"a stale entry is never\nserved after a write\" held only until a read raced a write, and then failed for\nthe full 30s TTL (a raced `delete()` resurrected the deleted override).\nGenerations are tracked per `(db, key)`, not per tenant, because an app-level\nrow is inherited by every tenant. `clearPromptCache()` raises a single floor\n(`clearedThrough`) rather than resetting or per-key bumping: a key that has\nnever been invalidated has no map entry and reads as generation 0, so a per-key\nbump cannot reach it and a resolution that started before the clear would write\nits pre-clear value back. `smrt-languages` carries the same mechanism, keyed\nadditionally by locale. `smrt-playbooks` has the generation but not the floor\n(#2716).\n\n## Related\n\n- `@happyvertical/smrt-languages` — parallel package for language strings (uses the same architecture pattern)\n- `@happyvertical/smrt-features` — parallel package for feature flags\n",
|
|
384
|
+
"agentDoc": "# smrt-prompts\n\nSMRT prompt registry and tenant-aware prompt override package. Code defines defaults; config layers and DB-stored overrides personalize at app and tenant levels.\n\n## Core pieces\n\n- `definePrompt()` registers code defaults in a global process registry (`globalThis.__smrtPromptRegistry`)\n- `resolvePrompt()` merges code defaults, file/config overrides (via `@happyvertical/smrt-config`), stored app-level overrides, stored tenant-level overrides, and a runtime override\n- `PromptOverride` (`_smrt_prompt_overrides` table) stores partial app-level and tenant-level overrides with write-time validation\n- `PromptOverrideCollection` — collection API, plus `setTemplateOverride()` / `removeOverride()` / `findByScope()` / `getOverrideMapForKeys()` for the write and enumeration paths below\n- `PromptOverrideService` — the only write path a host should use directly; asks a host-supplied authorizer before every write and fails closed (mirrors `FeatureOverrideService`, #3013); before authorizing it rejects any scope the resolver never reads (`InvalidPromptScopeError`: unknown type, app id other than `__app__`, blank/untrimmed/`__app__` tenant id), so a malformed tenant write cannot reach the app-wide row\n- `PromptSettingsService` — read/write helper for a management screen: `listPromptSettings()` returns one `PromptSettingsRow` per registered key (the effective template, `appTemplate`/`tenantTemplate` for the raw override at each scope, `appDefaultTemplate`/`inheritedTemplate` for what reverting each scope produces, and `supplyingLevel`); `setPromptOverride()` refuses unknown keys and fields the definition marks not editable, then delegates to `PromptOverrideService` (#3053)\n- `./svelte` subpath — `PromptSettingsPanel`, the presentational management panel (#3053)\n\n## Resolution layers (priority low → high)\n\n1. Code default — registered via `definePrompt({ key, template, ai })`\n2. File/config override — `getPackageConfig<PromptPackageConfig>('prompts', defaults)`\n3. App-level stored override — `PromptOverride` row with `tenantId = null`\n4. Tenant-level stored override — `PromptOverride` row with current tenant\n5. Runtime override — passed to `resolvePrompt({ overrides })`\n\nEach layer can override any subset of fields (template, profile, model, params). Inheritance is field-by-field.\n\n## Conventions\n\n- **Namespace prompt keys** by package or domain: `projects.issue.incorporateFeedback`, `content.summarize.headline`\n- **Stored overrides use nullable fields** so inheritance stays field-by-field — null means \"use the lower layer\"\n- **Provider selection is indirect** in v1: prompts select named profiles, and profiles resolve to provider/model in `smrt-config`\n- **`editable` flags are enforced on `PromptOverride.save()`** — definitions can lock specific fields against tenant override\n- **Tier names are reserved profile names** (#4750): `cheap`, `good`, `great`, `best` and `auto` need no `profiles` entry. `resolvePrompt()` only marks them (`ai.tier`, `ai.promptKey`, and the code default's `ai.latency`) and never copies a binding into `provider`/`model`/`params`: the tier binds once, at call time, through core's seam (`prepareAiOperation()` / `getAiClient(tier)`) with the prompt key, so prompt and call cannot disagree. `allowedProfileNames` applies to tier names chosen by config or an override, but not to the tier the code default itself declares when no config, stored or runtime layer sets a profile (#4755), so an allow-list never breaks framework prompts. An explicit prompt `model` stays validated by `allowedModels` and is sent per call on the tier client. **Footgun:** a same-named `profiles` entry wins and silently opts that name out of tiers. `definePrompt({ ai: { minimumTier } })` sets the ladder floor for a tier prompt (#4752); it is read from the code default only (stripped from params at every layer), so config and tenant overrides cannot lower it, and `promptMessageOptions()` forwards it with `tier`. `tier`, `latency` and `promptKey` never come from params. The canonical `promptMessageOptions()` forwards them; callers send the result through `prepareAiOperation()` (`SmrtClass`, so collections too), which strips them before the provider call. Sites holding their own client (content chat and thumbnails, facts' injected message-only client, the translation job, `Issue`'s explicit-provider path) pass `{ routeTier: false }` or drop the keys, so the prompt's tier does not route there and records no tier tags; the translation job and `Issue`'s path still apply a stored tenant or user binding through core's `resolveInferenceTarget({ appBindings: false })` (#4756), which adds tier and `source` tags only when a binding applied.\n\n## Generated surfaces\n\n`PromptOverride` ships with generated REST routes, MCP tools, and CLI commands\nclosed (`api: false`, `cli: false`, `mcp: false`, mirrors `FeatureOverride`,\n#3013). Override rows are authorization state for every scope and `tenantId` is\nan ordinary settable field, not request-derived tenant scoping — a generated\nauthentication-only surface would let any signed-in principal set another\ntenant's prompt text. Hosts write overrides server-side with\n`PromptOverrideService` (which requires an explicit authorizer for every\nwrite) or `PromptOverrideCollection.setTemplateOverride()` /\n`removeOverride()` only after their own authorization decision.\n\n## Management UI (`./svelte`)\n\n- Built like every other Svelte-shipping package here (`smrt-features`/`smrt-tenancy` are the closest models): `vite build --mode library && svelte-package -i src/svelte -o dist/svelte`, an `./svelte` export with a `svelte` condition, `svelte` as an **optional** peer dependency, plus `scripts/prune-svelte-package-artifacts.js` so `svelte-package` does not copy `__tests__/` into the published `dist/svelte`. The root export stays Svelte-free so server-only consumers are unaffected.\n- `PromptSettingsPanel` is presentational: rows and callbacks in, no fetching, no authorization. `src/svelte/types.ts` deliberately imports nothing from `smrt-core` or the `@smrt()` models, so the browser bundle stays thin; `PromptSettingsRow` is structurally assignable to `PromptSettingsView`.\n- Each row is its own `<form>` with a checkbox + `<textarea>` pair per scope (`tenantOverride`/`tenantTemplate`, and `appOverride`/`appTemplate` when `showApp` is set). The checkbox's presence in the submitted `FormData` — not whether the textarea is disabled — decides override vs. revert, because a plain HTML submit cannot un-disable a field the browser already marked disabled. `onSave` reads the same `FormData` when driving the panel from a client handler instead of `formAction`.\n- Two invariants, both regression-tested. (1) The \"revert\" preview never claims the bare registry default: `tenantRevertPreview()` shows `inheritedTemplate` (registry + config + app override), falling back to `appDefaultTemplate` only when the row does not carry it, and `appRevertPreview()` shows `appDefaultTemplate` (registry + config, never the app override itself). `PromptSettingsService` computes both explicitly rather than deriving one from the other — an earlier draft reused the app-only merge as the \"no tenant requested\" effective value and broke both. (2) The rows remount on `contextKey ?? prompts`, so an unsaved edit cannot survive a reload or a tenant switch and be submitted against the new rows.\n- **Authorization stays with the consumer.** `PromptSettingsService` reads are unfiltered and every write goes through `PromptOverrideService`; constructing the settings service without an `authorize` option makes it read-only (writes fail closed). Never add an authorization decision to this package.\n- `vitest.config.ts` runs two projects (`server` node + `smrtVitestPlugin`, `svelte` jsdom + `@sveltejs/vite-plugin-svelte` with `conditions: ['browser']`) because the browser condition would send `smrt-core` to its browser build if applied globally.\n- `PromptSettingsService.create()` builds its `PromptOverrideCollection` with the caller's `defaultListLimit`/`maxListLimit` stripped before the bulk `getOverrideMapForKeys()` enumeration read that backs `listPromptSettings()` — the #3056 hazard class in `smrt-features`'s `FeatureOverrideCollection.getOverrideMap()`, applied here proactively rather than left for a follow-up issue. A host-configured list bound must never silently drop a key's override from a management screen.\n\n## Usage tags (#4751)\n\n`resolvePrompt()` returns `ai.usageTags = { promptKey, promptLayer,\ntemplateHash }`: `promptLayer` is the highest layer that supplied the template\n(`default | config | app | tenant | runtime`; a params-only layer does not\ncount), `templateHash` the first 12 hex chars of the SHA-256 of the unrendered\neffective template (Web Crypto, so the root stays free of `node:crypto`).\n`promptMessageOptions(ai, { usageTags? })` is the one helper that turns a\nresolution into `ai.message()` options; package copies re-export it. Tag\nprecedence, low to high: a `usageTags` object in params (tenant-editable, so\nreserved tags — identity, `runId`, tier, `substitutions`, `fusionKey` — are\ndropped from it), the resolution's tags, the caller's. Params never carry\n`tier`, `latency` or `promptKey` either: tier routing comes only from the\nvalidated profile. Every consumer\ncall site must forward them (`promptMessageOptions()` or a spread of\n`resolved.ai`); core lifts `promptKey` into `_smrt_ai_usage.prompt_key`\n(`../core/agents/ai-usage.md`).\n\n## Framework prompt tiers (#4755)\n\nEvery framework `definePrompt()` declares `ai.profile` as a tier: closed-\nvocabulary classification and yes/no predicates → `cheap`; summaries,\ndescriptions, translations, headlines → `good`; synthesis over user content\nthat is persisted or applied (feedback incorporation, reviews, corrections,\nfact extraction and reconciliation) → `great`; nothing defaults to `best`.\n`ai.latency` is `interactive` on request paths (chat, editor) and `background`\nfor jobs, else unset; only the code default declares it. Prompts that make no model call (persona instructions,\nchat system prompts) or call a non-text model (image generation) declare no\ntier. An explicit model on the call path wins over the tier. Each package's\n`AGENTS.md` records its choices; one test per package pins the tag set.\n\n## Prompt keys are persisted identifiers\n\nOverrides are stored keyed by the exact `key` string and resolved by that\nstring at runtime. **Renaming a key orphans every existing override and\nsilently reverts every tenant to the registry default**, and it also orphans\nthe key's `_smrt_ai_usage` series: history stays under the old `prompt_key`\nand outcome labels never join the new one. Treat a shipped key as immutable;\na rename needs a data migration over `_smrt_prompt_overrides.key`, not an edit.\n\n## Caching\n\n`resolvePrompt()` results are cached per `(key, tenantId)` with a TTL. The cache is invalidated on `PromptOverride.save()` and `.delete()`. Use `clearPromptCache()` for manual invalidation in tests.\n\n**A monotonic per-`(db, key)` invalidation generation guards the cache write.**\nA resolution captures `getPromptCacheGeneration(key, db)` before its\nasynchronous layer loads and hands it back to `setCachedPromptBase()`; a\nconcurrent `save()` / `delete()` bumps the generation and the in-flight\nresolution is then refused the cache write instead of repopulating the key it\njust invalidated with the pre-write value. Without it, \"a stale entry is never\nserved after a write\" held only until a read raced a write, and then failed for\nthe full 30s TTL (a raced `delete()` resurrected the deleted override).\nGenerations are tracked per `(db, key)`, not per tenant, because an app-level\nrow is inherited by every tenant. `clearPromptCache()` raises a single floor\n(`clearedThrough`) rather than resetting or per-key bumping: a key that has\nnever been invalidated has no map entry and reads as generation 0, so a per-key\nbump cannot reach it and a resolution that started before the clear would write\nits pre-clear value back. `smrt-languages` carries the same mechanism, keyed\nadditionally by locale. `smrt-playbooks` has the generation but not the floor\n(#2716).\n\n## Related\n\n- `@happyvertical/smrt-languages` — parallel package for language strings (uses the same architecture pattern)\n- `@happyvertical/smrt-features` — parallel package for feature flags\n",
|
|
376
385
|
"browser": {
|
|
377
386
|
"status": "server-only",
|
|
378
387
|
"issues": [
|
|
@@ -5,10 +5,10 @@ description: "Typed prompt registry, override resolution, and tenant-aware promp
|
|
|
5
5
|
status: "stable"
|
|
6
6
|
generated:
|
|
7
7
|
by: "smrt/scripts/generate-knowledge-okf.ts"
|
|
8
|
-
at: "2026-11-
|
|
8
|
+
at: "2026-11-09T01:28:57Z"
|
|
9
9
|
audience: "internal"
|
|
10
10
|
evidence_level: "source-inspected"
|
|
11
|
-
source_revision: "sha256:
|
|
11
|
+
source_revision: "sha256:f65efe44bcddbc90b1ec0f98998bbd6489810a6b15212abf5ece8abb2e5fba5c"
|
|
12
12
|
sources:
|
|
13
13
|
- id: "manifest"
|
|
14
14
|
resource: "https://github.com/happyvertical/smrt/blob/main/packages/prompts/package.json"
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
1
|
+
import type { InferenceLatency, InferenceTier, InferenceTierRequest, SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
2
|
export type PromptParams = Record<string, unknown>;
|
|
3
3
|
export interface PromptEditableConfig {
|
|
4
4
|
template: boolean;
|
|
@@ -7,11 +7,27 @@ export interface PromptEditableConfig {
|
|
|
7
7
|
params: boolean;
|
|
8
8
|
}
|
|
9
9
|
export interface PromptAIInput {
|
|
10
|
+
/**
|
|
11
|
+
* A configured profile name or an inference tier (`cheap`…`best`, `auto`;
|
|
12
|
+
* #4750). Framework prompts declare a tier by the #4755 sweep rule.
|
|
13
|
+
*/
|
|
10
14
|
profile?: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Latency hint for a tier binding (`interactive` on request paths,
|
|
17
|
+
* `background` for jobs; #4755). Declared by the code default only: it is
|
|
18
|
+
* a property of the call site, so config and overrides cannot change it.
|
|
19
|
+
*/
|
|
20
|
+
latency?: InferenceLatency;
|
|
11
21
|
model?: string | null;
|
|
12
22
|
params?: PromptParams | null;
|
|
13
23
|
temperature?: number;
|
|
14
24
|
maxTokens?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Lowest tier a tier-profile prompt may degrade to when its tier's chain
|
|
27
|
+
* fails (#4752). Code default only: config and stored overrides cannot
|
|
28
|
+
* lower it.
|
|
29
|
+
*/
|
|
30
|
+
minimumTier?: InferenceTier;
|
|
15
31
|
[key: string]: unknown;
|
|
16
32
|
}
|
|
17
33
|
export interface PromptDefinitionInput {
|
|
@@ -77,12 +93,54 @@ export interface PromptLayer {
|
|
|
77
93
|
export interface NormalizedPromptAI {
|
|
78
94
|
profile?: string;
|
|
79
95
|
model?: string;
|
|
96
|
+
/** Code-declared latency hint; only a registered definition carries it. */
|
|
97
|
+
latency?: InferenceLatency;
|
|
98
|
+
/** From the code default only (#4752). */
|
|
99
|
+
minimumTier?: InferenceTier;
|
|
80
100
|
params: PromptParams;
|
|
81
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* The resolution layer that supplied a prompt's effective template, lowest to
|
|
104
|
+
* highest priority. Recorded on every AI call as the `promptLayer` usage tag.
|
|
105
|
+
*/
|
|
106
|
+
export type PromptSourceLayer = 'default' | 'config' | 'app' | 'tenant' | 'runtime';
|
|
107
|
+
/**
|
|
108
|
+
* Usage tags `resolvePrompt()` attaches to a resolution. They reach
|
|
109
|
+
* `_smrt_ai_usage` through the AI SDK's per-call `usageTags`; `promptKey` is
|
|
110
|
+
* also lifted into the indexed `prompt_key` column (#4751).
|
|
111
|
+
*/
|
|
112
|
+
export interface PromptUsageTags {
|
|
113
|
+
/** The registered prompt key, e.g. `content.summarize.headline`. */
|
|
114
|
+
promptKey: string;
|
|
115
|
+
/** The highest layer that supplied the effective template. */
|
|
116
|
+
promptLayer: PromptSourceLayer;
|
|
117
|
+
/** First 12 hex chars of the SHA-256 of the effective (unrendered) template. */
|
|
118
|
+
templateHash: string;
|
|
119
|
+
[key: string]: string;
|
|
120
|
+
}
|
|
82
121
|
export interface ResolvedPromptAI extends PromptParams {
|
|
122
|
+
/**
|
|
123
|
+
* Prompt-run observability tags (#4751). Always set by `resolvePrompt()`;
|
|
124
|
+
* optional here so hand-built AI option objects stay assignable.
|
|
125
|
+
*/
|
|
126
|
+
usageTags?: PromptUsageTags;
|
|
83
127
|
profile?: string;
|
|
84
128
|
provider?: string;
|
|
85
129
|
model?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Set when the effective profile is an inference tier name (or `auto`) with
|
|
132
|
+
* no same-named entry in `PromptPackageConfig.profiles` (#4750). The tier
|
|
133
|
+
* binds at call time through the core seam: forward `tier` and `promptKey`
|
|
134
|
+
* to object AI operations (`prepareAiOperation()`), which pick the tier
|
|
135
|
+
* client. `provider`/`model` stay unset unless the prompt names a model.
|
|
136
|
+
*/
|
|
137
|
+
tier?: InferenceTierRequest;
|
|
138
|
+
/** The prompt key, set with `tier` for the call-time resolver request. */
|
|
139
|
+
promptKey?: string;
|
|
140
|
+
/** Set with `tier`: the code default's latency hint (#4755). */
|
|
141
|
+
latency?: InferenceLatency;
|
|
142
|
+
/** The definition's `ai.minimumTier`, set with `tier` (#4752). */
|
|
143
|
+
minimumTier?: InferenceTier;
|
|
86
144
|
allowedModels?: string[];
|
|
87
145
|
params: PromptParams;
|
|
88
146
|
temperature?: number;
|
|
@@ -92,7 +150,9 @@ export interface ResolvedPrompt {
|
|
|
92
150
|
key: string;
|
|
93
151
|
template: string;
|
|
94
152
|
text: string;
|
|
95
|
-
ai: ResolvedPromptAI
|
|
153
|
+
ai: ResolvedPromptAI & {
|
|
154
|
+
usageTags: PromptUsageTags;
|
|
155
|
+
};
|
|
96
156
|
}
|
|
97
157
|
export interface ResolvePromptOptions {
|
|
98
158
|
db?: SmrtClassOptions['db'];
|
|
@@ -103,6 +163,14 @@ export interface ResolvePromptOptions {
|
|
|
103
163
|
export interface PromptCacheValue {
|
|
104
164
|
key: string;
|
|
105
165
|
template: string;
|
|
166
|
+
/** The highest stored/config layer that supplied `template`. */
|
|
167
|
+
templateLayer: Exclude<PromptSourceLayer, 'runtime'>;
|
|
168
|
+
/**
|
|
169
|
+
* The highest stored/config layer that supplied `ai.profile`. Only a
|
|
170
|
+
* profile the code default supplied is exempt from `allowedProfileNames`
|
|
171
|
+
* (#4755).
|
|
172
|
+
*/
|
|
173
|
+
profileLayer: Exclude<PromptSourceLayer, 'runtime'>;
|
|
106
174
|
ai: NormalizedPromptAI;
|
|
107
175
|
}
|
|
108
176
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB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C;CACxB"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n InferenceLatency,\n InferenceTier,\n InferenceTierRequest,\n SmrtClassOptions,\n} from '@happyvertical/smrt-core';\n\nexport type PromptParams = Record<string, unknown>;\n\nexport interface PromptEditableConfig {\n template: boolean;\n profile: boolean;\n model: boolean;\n params: boolean;\n}\n\nexport interface PromptAIInput {\n /**\n * A configured profile name or an inference tier (`cheap`…`best`, `auto`;\n * #4750). Framework prompts declare a tier by the #4755 sweep rule.\n */\n profile?: string | null;\n /**\n * Latency hint for a tier binding (`interactive` on request paths,\n * `background` for jobs; #4755). Declared by the code default only: it is\n * a property of the call site, so config and overrides cannot change it.\n */\n latency?: InferenceLatency;\n model?: string | null;\n params?: PromptParams | null;\n temperature?: number;\n maxTokens?: number;\n /**\n * Lowest tier a tier-profile prompt may degrade to when its tier's chain\n * fails (#4752). Code default only: config and stored overrides cannot\n * lower it.\n */\n minimumTier?: InferenceTier;\n [key: string]: unknown;\n}\n\nexport interface PromptDefinitionInput {\n key: string;\n template: string;\n /** Human-readable description shown by a management screen; defaults to `''`. */\n description?: string;\n ai?: PromptAIInput;\n editable?: Partial<PromptEditableConfig>;\n}\n\nexport interface PromptDefinition {\n key: string;\n template: string;\n description: string;\n ai: NormalizedPromptAI;\n editable: PromptEditableConfig;\n}\n\n/**\n * The two scopes a stored {@link PromptOverride} row may target: the\n * app-wide default (`tenantId` is `null`) or one tenant.\n */\nexport type PromptOverrideScopeType = 'app' | 'tenant';\n\n/**\n * Canonical scope id for the app-wide override scope, mirroring\n * `GLOBAL_FEATURE_SCOPE_ID` in `@happyvertical/smrt-features` (#3013). The\n * resolver and the write-authorization path both key off this exact value —\n * `PromptOverride` itself stores the app scope as `tenantId: null`, not this\n * string, so this constant only ever appears at the scope-request boundary\n * (`PromptOverrideService`, `PromptSettingsService`).\n */\nexport const APP_PROMPT_SCOPE_ID = '__app__';\n\nexport interface PromptProfileConfig {\n provider: string;\n model: string;\n params?: PromptParams | null;\n temperature?: number;\n maxTokens?: number;\n [key: string]: unknown;\n}\n\nexport interface PromptConfigOverrideInput {\n template?: string | null;\n profile?: string | null;\n model?: string | null;\n params?: PromptParams | null;\n ai?: PromptAIInput | null;\n temperature?: number;\n maxTokens?: number;\n [key: string]: unknown;\n}\n\nexport interface PromptPackageConfig {\n profiles?: Record<string, PromptProfileConfig>;\n prompts?: Record<string, PromptConfigOverrideInput>;\n allowedProfileNames?: string[];\n allowedModels?: string[];\n [key: string]: unknown;\n}\n\nexport interface PromptLayer {\n template?: string | null;\n profile?: string | null;\n model?: string | null;\n params?: PromptParams | null;\n}\n\nexport interface NormalizedPromptAI {\n profile?: string;\n model?: string;\n /** Code-declared latency hint; only a registered definition carries it. */\n latency?: InferenceLatency;\n /** From the code default only (#4752). */\n minimumTier?: InferenceTier;\n params: PromptParams;\n}\n\n/**\n * The resolution layer that supplied a prompt's effective template, lowest to\n * highest priority. Recorded on every AI call as the `promptLayer` usage tag.\n */\nexport type PromptSourceLayer =\n | 'default'\n | 'config'\n | 'app'\n | 'tenant'\n | 'runtime';\n\n/**\n * Usage tags `resolvePrompt()` attaches to a resolution. They reach\n * `_smrt_ai_usage` through the AI SDK's per-call `usageTags`; `promptKey` is\n * also lifted into the indexed `prompt_key` column (#4751).\n */\nexport interface PromptUsageTags {\n /** The registered prompt key, e.g. `content.summarize.headline`. */\n promptKey: string;\n /** The highest layer that supplied the effective template. */\n promptLayer: PromptSourceLayer;\n /** First 12 hex chars of the SHA-256 of the effective (unrendered) template. */\n templateHash: string;\n [key: string]: string;\n}\n\nexport interface ResolvedPromptAI extends PromptParams {\n /**\n * Prompt-run observability tags (#4751). Always set by `resolvePrompt()`;\n * optional here so hand-built AI option objects stay assignable.\n */\n usageTags?: PromptUsageTags;\n profile?: string;\n provider?: string;\n model?: string;\n /**\n * Set when the effective profile is an inference tier name (or `auto`) with\n * no same-named entry in `PromptPackageConfig.profiles` (#4750). The tier\n * binds at call time through the core seam: forward `tier` and `promptKey`\n * to object AI operations (`prepareAiOperation()`), which pick the tier\n * client. `provider`/`model` stay unset unless the prompt names a model.\n */\n tier?: InferenceTierRequest;\n /** The prompt key, set with `tier` for the call-time resolver request. */\n promptKey?: string;\n /** Set with `tier`: the code default's latency hint (#4755). */\n latency?: InferenceLatency;\n /** The definition's `ai.minimumTier`, set with `tier` (#4752). */\n minimumTier?: InferenceTier;\n allowedModels?: string[];\n params: PromptParams;\n temperature?: number;\n maxTokens?: number;\n}\n\nexport interface ResolvedPrompt {\n key: string;\n template: string;\n text: string;\n ai: ResolvedPromptAI & { usageTags: PromptUsageTags };\n}\n\nexport interface ResolvePromptOptions {\n db?: SmrtClassOptions['db'];\n tenantId?: string | null;\n variables?: Record<string, unknown>;\n override?: PromptConfigOverrideInput;\n}\n\nexport interface PromptCacheValue {\n key: string;\n template: string;\n /** The highest stored/config layer that supplied `template`. */\n templateLayer: Exclude<PromptSourceLayer, 'runtime'>;\n /**\n * The highest stored/config layer that supplied `ai.profile`. Only a\n * profile the code default supplied is exempt from `allowedProfileNames`\n * (#4755).\n */\n profileLayer: Exclude<PromptSourceLayer, 'runtime'>;\n ai: NormalizedPromptAI;\n}\n"],"mappings":";AAwEO,IAAM,sBAAsB"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type InferenceLatency, type InferenceTierRequest } from '@happyvertical/smrt-core';
|
|
1
2
|
import type { NormalizedPromptAI, PromptConfigOverrideInput, PromptDefinitionInput, PromptEditableConfig, PromptLayer, PromptPackageConfig, PromptParams, PromptProfileConfig, ResolvedPromptAI } from './types.js';
|
|
2
3
|
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
3
4
|
export declare function normalizeEditableConfig(editable?: Partial<PromptEditableConfig>): PromptEditableConfig;
|
|
@@ -22,7 +23,65 @@ export declare function normalizeProfileConfig(profile: PromptProfileConfig): {
|
|
|
22
23
|
};
|
|
23
24
|
export declare function validateProfileName(profileName: string, config: PromptPackageConfig): void;
|
|
24
25
|
export declare function validateModelName(modelName: string, config: PromptPackageConfig): void;
|
|
25
|
-
export declare function buildResolvedAI(ai: NormalizedPromptAI, config: PromptPackageConfig
|
|
26
|
+
export declare function buildResolvedAI(ai: NormalizedPromptAI, config: PromptPackageConfig, options?: {
|
|
27
|
+
/**
|
|
28
|
+
* The registered code default's profile (`definePrompt({ ai })`), passed
|
|
29
|
+
* only when no config, stored or runtime layer set a profile.
|
|
30
|
+
*/
|
|
31
|
+
defaultProfile?: string;
|
|
32
|
+
}): ResolvedPromptAI;
|
|
33
|
+
/**
|
|
34
|
+
* Short SHA-256 fingerprint of an effective (unrendered) prompt template: the
|
|
35
|
+
* first 12 lowercase hex characters. Recorded as the `templateHash` usage tag
|
|
36
|
+
* so an override edit starts a new usage series (#4751).
|
|
37
|
+
*
|
|
38
|
+
* Uses Web Crypto (`globalThis.crypto.subtle`), available in Node and every
|
|
39
|
+
* browser, so the package root stays free of `node:crypto`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function promptTemplateHash(template: string): Promise<string>;
|
|
42
|
+
/** The `ai.message()` options {@link promptMessageOptions} returns. */
|
|
43
|
+
export interface PromptMessageOptions extends PromptParams {
|
|
44
|
+
model?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Inference tier of a tier profile (#4750). Object call sites pass these
|
|
47
|
+
* options through `SmrtObject.prepareAiOperation()`, which picks the tier
|
|
48
|
+
* client and strips `tier`/`promptKey` before the provider sees them.
|
|
49
|
+
*/
|
|
50
|
+
tier?: InferenceTierRequest;
|
|
51
|
+
/** Set with `tier`: the prompt key for the call-time resolver request. */
|
|
52
|
+
promptKey?: string;
|
|
53
|
+
/** Set with `tier`: the code default's `ai.latency` hint (#4755). */
|
|
54
|
+
latency?: InferenceLatency;
|
|
55
|
+
temperature?: number;
|
|
56
|
+
maxTokens?: number;
|
|
57
|
+
/** Degradation floor sent with `tier` (#4752). */
|
|
58
|
+
minimumTier?: ResolvedPromptAI['minimumTier'];
|
|
59
|
+
usageTags?: Record<string, string>;
|
|
60
|
+
}
|
|
61
|
+
/** Extra call options merged by {@link promptMessageOptions}. */
|
|
62
|
+
export interface PromptMessageOptionsExtra {
|
|
63
|
+
/** The caller's own usage tags; they win over the resolution's tags. */
|
|
64
|
+
usageTags?: Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* `false` omits `tier`/`promptKey` for a call site that sends the options
|
|
67
|
+
* straight to a client it already holds (no `prepareAiOperation()`), so
|
|
68
|
+
* the tier keys never reach a provider; the call runs on that client.
|
|
69
|
+
* Default `true`.
|
|
70
|
+
*/
|
|
71
|
+
routeTier?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Turn a resolved prompt's AI settings into `ai.message()` call options:
|
|
75
|
+
* params, `model`, `temperature`, `maxTokens`, the resolution's
|
|
76
|
+
* `usageTags` (`promptKey`, `promptLayer`, `templateHash`) and, for a tier
|
|
77
|
+
* profile, `tier` + `promptKey` (#4750). Send them through
|
|
78
|
+
* `SmrtObject.prepareAiOperation()` so the tier keys never reach a provider.
|
|
79
|
+
*
|
|
80
|
+
* Tag precedence, low to high: a `usageTags` object carried in the prompt's
|
|
81
|
+
* params (tenant-editable: reserved tags such as runId or tier tags are
|
|
82
|
+
* dropped from it), the resolution's identity tags, then `extra.usageTags`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function promptMessageOptions(ai: ResolvedPromptAI, extra?: PromptMessageOptionsExtra): PromptMessageOptions;
|
|
26
85
|
export declare function renderPromptTemplate(template: string, variables?: Record<string, unknown>): string;
|
|
27
86
|
export declare function parsePromptParams(raw: string | null | undefined): PromptParams;
|
|
28
87
|
export declare function serializePromptParams(params: PromptParams | null | undefined): string | null;
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EAG1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,kBAAkB,EAElB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAiDpB,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElC;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GACvC,oBAAoB,CAOtB;AA0CD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GACtC,YAAY,CAYd;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,WAAW,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,GACrD,YAAY,CAcd;AAiCD,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,qBAAqB,GAAG;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,kBAAkB,CAAC;IACvB,QAAQ,EAAE,oBAAoB,CAAC;CAChC,CAQA;AAED,wBAAgB,oBAAoB,CAClC,KAAK,CAAC,EA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AAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,iEAAiE;AACjE,MAAM,WAAW,yBAAyB;IACxC,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,gBAAgB,EACpB,KAAK,GAAE,yBAA8B,GACpC,oBAAoB,CAiCtB;AA+BD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,MAAM,CA2BR;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC7B,YAAY,CAWd;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GACtC,MAAM,GAAG,IAAI,CAMf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-prompts",
|
|
3
|
-
"version": "0.60.
|
|
3
|
+
"version": "0.60.15",
|
|
4
4
|
"description": "Typed prompt registry, override resolution, and tenant-aware prompt settings for SMRT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"./manifest.json": "./dist/manifest.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@happyvertical/smrt-config": "0.60.
|
|
28
|
-
"@happyvertical/smrt-core": "0.60.
|
|
29
|
-
"@happyvertical/smrt-tenancy": "0.60.
|
|
30
|
-
"@happyvertical/smrt-ui": "0.60.
|
|
27
|
+
"@happyvertical/smrt-config": "0.60.15",
|
|
28
|
+
"@happyvertical/smrt-core": "0.60.15",
|
|
29
|
+
"@happyvertical/smrt-tenancy": "0.60.15",
|
|
30
|
+
"@happyvertical/smrt-ui": "0.60.15",
|
|
31
31
|
"@happyvertical/sql": "^0.111.6"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@happyvertical/smrt-vitest": "0.60.
|
|
34
|
+
"@happyvertical/smrt-vitest": "0.60.15",
|
|
35
35
|
"@sveltejs/package": "^2.5.8",
|
|
36
36
|
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
37
37
|
"@types/node": "24.13.6",
|