@happyvertical/smrt-prompts 0.51.24 → 0.51.32
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 +34 -1
- package/README.md +148 -2
- package/dist/__smrt-register__.d.ts +2 -0
- package/dist/__smrt-register__.d.ts.map +1 -0
- package/dist/cache.d.ts +33 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/collections/PromptOverrideCollection.d.ts +45 -0
- package/dist/collections/PromptOverrideCollection.d.ts.map +1 -0
- package/dist/index.d.ts +12 -174
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +298 -30
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +117 -28
- package/dist/models/PromptOverride.d.ts +32 -0
- package/dist/models/PromptOverride.d.ts.map +1 -0
- package/dist/prompt-override-service.d.ts +56 -0
- package/dist/prompt-override-service.d.ts.map +1 -0
- package/dist/prompt-registry.d.ts +13 -0
- package/dist/prompt-registry.d.ts.map +1 -0
- package/dist/prompt-resolver.d.ts +3 -0
- package/dist/prompt-resolver.d.ts.map +1 -0
- package/dist/prompt-settings.d.ts +188 -0
- package/dist/prompt-settings.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +108 -248
- package/dist/svelte/components/PromptSettingsPanel.svelte +353 -0
- package/dist/svelte/components/PromptSettingsPanel.svelte.d.ts +52 -0
- package/dist/svelte/components/PromptSettingsPanel.svelte.d.ts.map +1 -0
- package/dist/svelte/index.d.ts +17 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +14 -0
- package/dist/svelte/types.d.ts +75 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +42 -0
- package/dist/types.d.ts +107 -110
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +29 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +27 -8
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,10 @@ SMRT prompt registry and tenant-aware prompt override package. Code defines defa
|
|
|
7
7
|
- `definePrompt()` registers code defaults in a global process registry (`globalThis.__smrtPromptRegistry`)
|
|
8
8
|
- `resolvePrompt()` merges code defaults, file/config overrides (via `@happyvertical/smrt-config`), stored app-level overrides, stored tenant-level overrides, and a runtime override
|
|
9
9
|
- `PromptOverride` (`_smrt_prompt_overrides` table) stores partial app-level and tenant-level overrides with write-time validation
|
|
10
|
-
- `PromptOverrideCollection`
|
|
10
|
+
- `PromptOverrideCollection` — collection API, plus `setTemplateOverride()` / `removeOverride()` / `findByScope()` / `getOverrideMapForKeys()` for the write and enumeration paths below
|
|
11
|
+
- `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
|
|
12
|
+
- `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)
|
|
13
|
+
- `./svelte` subpath — `PromptSettingsPanel`, the presentational management panel (#3053)
|
|
11
14
|
|
|
12
15
|
## Resolution layers (priority low → high)
|
|
13
16
|
|
|
@@ -26,6 +29,36 @@ Each layer can override any subset of fields (template, profile, model, params).
|
|
|
26
29
|
- **Provider selection is indirect** in v1: prompts select named profiles, and profiles resolve to provider/model in `smrt-config`
|
|
27
30
|
- **`editable` flags are enforced on `PromptOverride.save()`** — definitions can lock specific fields against tenant override
|
|
28
31
|
|
|
32
|
+
## Generated surfaces
|
|
33
|
+
|
|
34
|
+
`PromptOverride` ships with generated REST routes, MCP tools, and CLI commands
|
|
35
|
+
closed (`api: false`, `cli: false`, `mcp: false`, mirrors `FeatureOverride`,
|
|
36
|
+
#3013). Override rows are authorization state for every scope and `tenantId` is
|
|
37
|
+
an ordinary settable field, not request-derived tenant scoping — a generated
|
|
38
|
+
authentication-only surface would let any signed-in principal set another
|
|
39
|
+
tenant's prompt text. Hosts write overrides server-side with
|
|
40
|
+
`PromptOverrideService` (which requires an explicit authorizer for every
|
|
41
|
+
write) or `PromptOverrideCollection.setTemplateOverride()` /
|
|
42
|
+
`removeOverride()` only after their own authorization decision.
|
|
43
|
+
|
|
44
|
+
## Management UI (`./svelte`)
|
|
45
|
+
|
|
46
|
+
- 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.
|
|
47
|
+
- `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`.
|
|
48
|
+
- 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`.
|
|
49
|
+
- 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.
|
|
50
|
+
- **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.
|
|
51
|
+
- `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.
|
|
52
|
+
- `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.
|
|
53
|
+
|
|
54
|
+
## Prompt keys are persisted identifiers
|
|
55
|
+
|
|
56
|
+
Overrides are stored keyed by the exact `key` string and resolved by that
|
|
57
|
+
string at runtime. **Renaming a key orphans every existing override and
|
|
58
|
+
silently reverts every tenant to the registry default.** Treat a shipped key
|
|
59
|
+
as immutable; a rename needs a data migration over
|
|
60
|
+
`_smrt_prompt_overrides.key`, not an edit.
|
|
61
|
+
|
|
29
62
|
## Caching
|
|
30
63
|
|
|
31
64
|
`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.
|
package/README.md
CHANGED
|
@@ -36,14 +36,160 @@ const resolved = await resolvePrompt('projects.issue.incorporateFeedback', {
|
|
|
36
36
|
|
|
37
37
|
- **`definePrompt()`** — code-first prompt registration in a global process registry
|
|
38
38
|
- **`resolvePrompt()`** — layered resolution: code default → config override → stored app override → stored tenant override → runtime override
|
|
39
|
-
- **`PromptOverride`** —
|
|
39
|
+
- **`PromptOverride`** — model for app-level and tenant-level prompt settings, stored in `_smrt_prompt_overrides`
|
|
40
|
+
- **`PromptOverrideService`** / **`PromptSettingsService`** — the authorized write path and the read/write helper for a management screen (see "Management UI" below)
|
|
40
41
|
- **Named AI profiles** loaded from `packages.prompts` config — prompts select profile names, profiles resolve to provider/model in config
|
|
41
42
|
- **TTL cache** keyed by `(key, tenantId)`, invalidated on override save/delete
|
|
42
43
|
|
|
43
44
|
Stored overrides support partial fields, so applications can override only the template, profile, model, or AI params without forking the rest of a prompt.
|
|
44
45
|
|
|
46
|
+
## Generated surfaces
|
|
47
|
+
|
|
48
|
+
`PromptOverride` ships with generated REST routes, MCP tools, and CLI
|
|
49
|
+
commands closed (`api: false`, `cli: false`, `mcp: false`). Override rows are
|
|
50
|
+
authorization state for every scope, so write them only from server code
|
|
51
|
+
through `PromptOverrideService`, which asks an authorizer you bind to the
|
|
52
|
+
current caller before every write and fails closed:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const service = new PromptOverrideService(overrides, (request) =>
|
|
56
|
+
request.scopeType === 'tenant' && request.scopeId === session.tenantId &&
|
|
57
|
+
session.permissions.has('prompts.manage'),
|
|
58
|
+
);
|
|
59
|
+
await service.setTemplateOverride(key, 'tenant', session.tenantId, 'New text.');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Management UI
|
|
63
|
+
|
|
64
|
+
The package ships the settings screen so consuming apps do not each rebuild
|
|
65
|
+
it: `PromptSettingsService` (root export) produces the rows, and
|
|
66
|
+
`PromptSettingsPanel` (the `./svelte` subpath) renders them. The root export
|
|
67
|
+
stays Svelte-free, so a server-only consumer is unaffected; `svelte` is an
|
|
68
|
+
optional peer dependency.
|
|
69
|
+
|
|
70
|
+
### Consumer recipe
|
|
71
|
+
|
|
72
|
+
**1. Register the prompt in code** (see Quick start above), including
|
|
73
|
+
`editable` if you want tenants or the app-wide default to be overridable:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
definePrompt({
|
|
77
|
+
key: 'projects.issue.incorporateFeedback',
|
|
78
|
+
template: 'Rewrite the issue body incorporating this feedback: {feedback}',
|
|
79
|
+
description: 'Rewrites an issue body from reviewer feedback.',
|
|
80
|
+
editable: { template: true },
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**2. Load the rows in your server load.** The load is where *your* permission
|
|
85
|
+
check lives — the package makes no authorization decision:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// src/routes/settings/prompts/+page.server.ts
|
|
89
|
+
export async function load(event) {
|
|
90
|
+
const auth = requirePermission(event, APP_PERMISSIONS.tenantAdmin);
|
|
91
|
+
const settings = await PromptSettingsService.create({ db });
|
|
92
|
+
return {
|
|
93
|
+
tenantId: auth.tenantId,
|
|
94
|
+
prompts: await settings.listPromptSettings({ tenantId: auth.tenantId }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`listPromptSettings()` returns one `PromptSettingsRow` per registered
|
|
100
|
+
key — the effective template for the requested tenant, the raw override text
|
|
101
|
+
at each scope (`appTemplate`/`tenantTemplate`), what reverting each scope
|
|
102
|
+
produces (`appDefaultTemplate`/`inheritedTemplate`), and `supplyingLevel`. The
|
|
103
|
+
row is structurally assignable to the panel's `PromptSettingsView`, so no
|
|
104
|
+
mapping step is needed.
|
|
105
|
+
|
|
106
|
+
**3. Render the panel:**
|
|
107
|
+
|
|
108
|
+
```svelte
|
|
109
|
+
<script lang="ts">
|
|
110
|
+
import { PromptSettingsPanel } from '@happyvertical/smrt-prompts/svelte';
|
|
111
|
+
let { data, form } = $props();
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<PromptSettingsPanel
|
|
115
|
+
prompts={data.prompts}
|
|
116
|
+
contextKey={data.tenantId}
|
|
117
|
+
formAction="?/savePrompt"
|
|
118
|
+
message={form?.message}
|
|
119
|
+
error={form?.error}
|
|
120
|
+
/>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The panel is presentational: it takes rows and callbacks, fetches nothing and
|
|
124
|
+
authorizes nothing. Each row renders the key, description, effective text, and
|
|
125
|
+
which level supplied it, plus a checkbox + text editor for the tenant scope
|
|
126
|
+
(and, when `showApp`/`appEditable` are set, the app scope). Unchecking the box
|
|
127
|
+
reverts that scope — the preview text next to it shows exactly what reverting
|
|
128
|
+
produces. Supply `onSave` instead of `formAction` to drive it from a client
|
|
129
|
+
handler.
|
|
130
|
+
|
|
131
|
+
**4. Wire the write with your own permission check.** `setPromptOverride()`
|
|
132
|
+
refuses any key without a definition and any field the definition's
|
|
133
|
+
`editable` config disallows, then delegates to `PromptOverrideService`, which
|
|
134
|
+
asks your authorizer and fails closed:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
export const actions = {
|
|
138
|
+
savePrompt: async (event) => {
|
|
139
|
+
const auth = requirePermission(event, APP_PERMISSIONS.tenantAdmin);
|
|
140
|
+
const form = await event.request.formData();
|
|
141
|
+
const settings = await PromptSettingsService.create(
|
|
142
|
+
{ db },
|
|
143
|
+
{
|
|
144
|
+
// Your decision, bound to this caller. Returning anything but `true` denies.
|
|
145
|
+
authorize: (request) =>
|
|
146
|
+
request.scopeType === 'tenant' && request.scopeId === auth.tenantId,
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
await settings.setTenantPromptOverride(
|
|
152
|
+
String(form.get('key') ?? ''),
|
|
153
|
+
auth.tenantId,
|
|
154
|
+
form.has('tenantOverride') ? String(form.get('tenantTemplate') ?? '') : null,
|
|
155
|
+
);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (error instanceof UnknownPromptKeyError) return fail(400, { error: 'Unknown prompt.' });
|
|
158
|
+
if (error instanceof PromptFieldNotEditableError) return fail(400, { error: 'Not editable.' });
|
|
159
|
+
if (error instanceof InvalidPromptScopeError) return fail(400, { error: 'Invalid scope.' });
|
|
160
|
+
if (error instanceof PromptOverrideAuthorizationError) return fail(403, { error: 'Not permitted.' });
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
return { message: 'Prompt overrides saved.' };
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Constructing the service **without** an `authorize` option makes it
|
|
169
|
+
read-only: every write then fails closed with
|
|
170
|
+
`PromptOverrideAuthorizationError`. That is the right shape for a load
|
|
171
|
+
function.
|
|
172
|
+
|
|
173
|
+
### What the consumer still owns
|
|
174
|
+
|
|
175
|
+
- the route, its navigation entry, and the page shell;
|
|
176
|
+
- the permission check on both the load and the action;
|
|
177
|
+
- the `authorize` callback (this package never decides who may write);
|
|
178
|
+
- resolving the session's `tenantId` — a tenant id from the URL or a form
|
|
179
|
+
field is a selector, not authorization;
|
|
180
|
+
- registering prompts with `definePrompt()` at startup.
|
|
181
|
+
|
|
182
|
+
### Prompt keys are persisted identifiers
|
|
183
|
+
|
|
184
|
+
Overrides are stored keyed by the exact `key` string and resolved by that
|
|
185
|
+
string at runtime. **Renaming a key orphans every existing override**,
|
|
186
|
+
silently reverting all tenants to the registry default — the change looks
|
|
187
|
+
harmless in a diff and shows up as prompt text mysteriously resetting. Treat a
|
|
188
|
+
key as immutable once shipped. A rename needs a data migration that rewrites
|
|
189
|
+
`_smrt_prompt_overrides.key`, not an edit.
|
|
190
|
+
|
|
45
191
|
## Documentation
|
|
46
192
|
|
|
47
193
|
- See [`AGENTS.md`](./AGENTS.md) for package-internal patterns
|
|
48
194
|
- See [`docs/content/standards.md`](../../docs/content/standards.md) for monorepo conventions
|
|
49
|
-
- See related: [`@happyvertical/smrt-languages`](../languages) (mirrors this package for language strings), [`@happyvertical/smrt-features`](../features) (feature flags)
|
|
195
|
+
- See related: [`@happyvertical/smrt-languages`](../languages) (mirrors this package for language strings), [`@happyvertical/smrt-features`](../features) (feature flags — same management-UI treatment, #3052)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__smrt-register__.d.ts","sourceRoot":"","sources":["../src/__smrt-register__.ts"],"names":[],"mappings":""}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DatabaseInterface } from '@happyvertical/sql';
|
|
2
|
+
import { PromptCacheValue } from './types.js';
|
|
3
|
+
export declare function getPromptCacheTtlMs(): number;
|
|
4
|
+
export declare function getCachedPromptBase(key: string, tenantId: string | null | undefined, db: DatabaseInterface | unknown): PromptCacheValue | null;
|
|
5
|
+
/**
|
|
6
|
+
* Reads the current invalidation generation for a key.
|
|
7
|
+
*
|
|
8
|
+
* A resolution captures this *before* its asynchronous layer loads and hands
|
|
9
|
+
* it back to {@link setCachedPromptBase}. Any write that lands while those
|
|
10
|
+
* loads are in flight bumps the generation, so the in-flight resolution —
|
|
11
|
+
* which read the pre-write layers — is refused the cache write instead of
|
|
12
|
+
* repopulating the key it just invalidated. Without this, a read that raced a
|
|
13
|
+
* write served the pre-write value for the full TTL, and a raced `delete()`
|
|
14
|
+
* resurrected the deleted override.
|
|
15
|
+
*
|
|
16
|
+
* Tracked per `(db, key)` rather than per `(db, key, tenantId)`: an app-level
|
|
17
|
+
* row is inherited by every tenant, so a write to any scope of a key must
|
|
18
|
+
* invalidate every scope of it. This matches the coarsest fan-out of
|
|
19
|
+
* {@link invalidatePromptCache}.
|
|
20
|
+
*
|
|
21
|
+
* A key with no entry of its own reports the {@link clearPromptCache} floor
|
|
22
|
+
* rather than a bare 0, so a clear refuses in-flight writes for keys that have
|
|
23
|
+
* never been invalidated too.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getPromptCacheGeneration(key: string, db: DatabaseInterface | unknown): number;
|
|
26
|
+
export declare function setCachedPromptBase(key: string, tenantId: string | null | undefined, db: DatabaseInterface | unknown, value: PromptCacheValue, loadedAtGeneration: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* Invalidates a cached resolution. An app-level write (tenantId null) clears
|
|
29
|
+
* every tenant's entry for that key, because each tenant inherits from it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function invalidatePromptCache(key: string, tenantId: string | null | undefined, db: DatabaseInterface | unknown): void;
|
|
32
|
+
export declare function clearPromptCache(): void;
|
|
33
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAiFnD,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,EAAE,EAAE,iBAAiB,GAAG,OAAO,GAC9B,gBAAgB,GAAG,IAAI,CAczB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,iBAAiB,GAAG,OAAO,GAC9B,MAAM,CAGR;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,EAAE,EAAE,iBAAiB,GAAG,OAAO,EAC/B,KAAK,EAAE,gBAAgB,EACvB,kBAAkB,EAAE,MAAM,GACzB,IAAI,CAWN;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,EAAE,EAAE,iBAAiB,GAAG,OAAO,GAC9B,IAAI,CAeN;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAQvC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { PromptOverride } from '../models/PromptOverride.js';
|
|
3
|
+
import { PromptOverrideScopeType } from '../types.js';
|
|
4
|
+
export declare class PromptOverrideCollection extends SmrtCollection<PromptOverride> {
|
|
5
|
+
static readonly _itemClass: typeof PromptOverride;
|
|
6
|
+
private excludeOverrideId;
|
|
7
|
+
getAppOverride(key: string, options?: {
|
|
8
|
+
excludeId?: string;
|
|
9
|
+
}): Promise<PromptOverride | null>;
|
|
10
|
+
getTenantOverride(key: string, tenantId: string, options?: {
|
|
11
|
+
excludeId?: string;
|
|
12
|
+
}): Promise<PromptOverride | null>;
|
|
13
|
+
getResolutionLayers(key: string, tenantId?: string | null, options?: {
|
|
14
|
+
excludeId?: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
app: PromptOverride | null;
|
|
17
|
+
tenant: PromptOverride | null;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* The override row for every key in `keys` at one scope, in a single query.
|
|
21
|
+
*
|
|
22
|
+
* Used by `PromptSettingsService.listPromptSettings()` to enumerate the
|
|
23
|
+
* whole registry's override state without one round trip per key. Because
|
|
24
|
+
* this is an enumeration read — a host-configured
|
|
25
|
+
* `defaultListLimit`/`maxListLimit` on the collection's options would
|
|
26
|
+
* silently drop keys past the cap, changing which prompts a management
|
|
27
|
+
* screen reports as overridden, with no error (the #3056 hazard class in
|
|
28
|
+
* `@happyvertical/smrt-features`'s `getOverrideMap`) — callers that need the
|
|
29
|
+
* full map construct this collection through
|
|
30
|
+
* `PromptSettingsService.create()`, which strips those bounds.
|
|
31
|
+
*/
|
|
32
|
+
getOverrideMapForKeys(keys: string[], scopeType: PromptOverrideScopeType, scopeId: string): Promise<Map<string, PromptOverride>>;
|
|
33
|
+
/** The override row for a scope request, in the vocabulary used at the write boundary. */
|
|
34
|
+
findByScope(key: string, scopeType: PromptOverrideScopeType, scopeId: string): Promise<PromptOverride | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Set (or clear, with `template: null`) the `template` field of the override
|
|
37
|
+
* row for one scope, creating the row if it did not exist. Other fields
|
|
38
|
+
* (`profile`, `model`, `params`) on an existing row are left untouched, per
|
|
39
|
+
* this package's field-by-field inheritance model.
|
|
40
|
+
*/
|
|
41
|
+
setTemplateOverride(key: string, scopeType: PromptOverrideScopeType, scopeId: string, template: string | null): Promise<PromptOverride>;
|
|
42
|
+
/** Remove the override row for one scope entirely, if one exists. */
|
|
43
|
+
removeOverride(key: string, scopeType: PromptOverrideScopeType, scopeId: string): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=PromptOverrideCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptOverrideCollection.d.ts","sourceRoot":"","sources":["../../src/collections/PromptOverrideCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,qBAAa,wBAAyB,SAAQ,cAAc,CAAC,cAAc,CAAC;IAC1E,MAAM,CAAC,QAAQ,CAAC,UAAU,wBAAkB;IAE5C,OAAO,CAAC,iBAAiB;IAOnB,cAAc,CAClB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAK3B,iBAAiB,CACrB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAK3B,mBAAmB,CACvB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,EACxB,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC;QAAE,GAAG,EAAE,cAAc,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAA;KAAE,CAAC;IAczE;;;;;;;;;;;;OAYG;IACG,qBAAqB,CACzB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAevC,0FAA0F;IACpF,WAAW,CACf,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAMjC;;;;;OAKG;IACG,mBAAmB,CACvB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,cAAc,CAAC;IAkB1B,qEAAqE;IAC/D,cAAc,CAClB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;CASpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,174 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
profile?: string;
|
|
14
|
-
model?: string;
|
|
15
|
-
params: PromptParams;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* Excluded from this release type: PACKAGE_VERSION_INITIALIZED */
|
|
19
|
-
|
|
20
|
-
export declare interface PromptAIInput {
|
|
21
|
-
profile?: string | null;
|
|
22
|
-
model?: string | null;
|
|
23
|
-
params?: PromptParams | null;
|
|
24
|
-
temperature?: number;
|
|
25
|
-
maxTokens?: number;
|
|
26
|
-
[key: string]: unknown;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export declare interface PromptConfigOverrideInput {
|
|
30
|
-
template?: string | null;
|
|
31
|
-
profile?: string | null;
|
|
32
|
-
model?: string | null;
|
|
33
|
-
params?: PromptParams | null;
|
|
34
|
-
ai?: PromptAIInput | null;
|
|
35
|
-
temperature?: number;
|
|
36
|
-
maxTokens?: number;
|
|
37
|
-
[key: string]: unknown;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export declare interface PromptDefinition {
|
|
41
|
-
key: string;
|
|
42
|
-
template: string;
|
|
43
|
-
ai: NormalizedPromptAI;
|
|
44
|
-
editable: PromptEditableConfig;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export declare interface PromptDefinitionInput {
|
|
48
|
-
key: string;
|
|
49
|
-
template: string;
|
|
50
|
-
ai?: PromptAIInput;
|
|
51
|
-
editable?: Partial<PromptEditableConfig>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export declare interface PromptEditableConfig {
|
|
55
|
-
template: boolean;
|
|
56
|
-
profile: boolean;
|
|
57
|
-
model: boolean;
|
|
58
|
-
params: boolean;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export declare interface PromptLayer {
|
|
62
|
-
template?: string | null;
|
|
63
|
-
profile?: string | null;
|
|
64
|
-
model?: string | null;
|
|
65
|
-
params?: PromptParams | null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export declare class PromptOverride extends SmrtObject {
|
|
69
|
-
key: string;
|
|
70
|
-
tenantId: string | null;
|
|
71
|
-
template: string | null;
|
|
72
|
-
profile: string | null;
|
|
73
|
-
model: string | null;
|
|
74
|
-
params: string | null;
|
|
75
|
-
constructor(options?: PromptOverrideOptions);
|
|
76
|
-
getParams(): PromptParams;
|
|
77
|
-
setParams(params: PromptParams | null): void;
|
|
78
|
-
toPromptLayer(): PromptLayer;
|
|
79
|
-
save(): Promise<this>;
|
|
80
|
-
private saveAfterIdentityChange;
|
|
81
|
-
private saveAfterIdentityChangeInTransaction;
|
|
82
|
-
private saveAfterIdentityChangeWithDeferredDelete;
|
|
83
|
-
delete(): Promise<void>;
|
|
84
|
-
private validatePromptOverride;
|
|
85
|
-
private getLowerPrecedenceLayers;
|
|
86
|
-
private normalizeParamsForPersistence;
|
|
87
|
-
private getPersistedIdentity;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export declare class PromptOverrideCollection extends SmrtCollection<PromptOverride> {
|
|
91
|
-
static readonly _itemClass: typeof PromptOverride;
|
|
92
|
-
private excludeOverrideId;
|
|
93
|
-
getAppOverride(key: string, options?: {
|
|
94
|
-
excludeId?: string;
|
|
95
|
-
}): Promise<PromptOverride | null>;
|
|
96
|
-
getTenantOverride(key: string, tenantId: string, options?: {
|
|
97
|
-
excludeId?: string;
|
|
98
|
-
}): Promise<PromptOverride | null>;
|
|
99
|
-
getResolutionLayers(key: string, tenantId?: string | null, options?: {
|
|
100
|
-
excludeId?: string;
|
|
101
|
-
}): Promise<{
|
|
102
|
-
app: PromptOverride | null;
|
|
103
|
-
tenant: PromptOverride | null;
|
|
104
|
-
}>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export declare interface PromptOverrideOptions extends SmrtObjectOptions {
|
|
108
|
-
key?: string;
|
|
109
|
-
tenantId?: string | null;
|
|
110
|
-
template?: string | null;
|
|
111
|
-
profile?: string | null;
|
|
112
|
-
model?: string | null;
|
|
113
|
-
params?: string | PromptParams | null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export declare interface PromptPackageConfig {
|
|
117
|
-
profiles?: Record<string, PromptProfileConfig>;
|
|
118
|
-
prompts?: Record<string, PromptConfigOverrideInput>;
|
|
119
|
-
allowedProfileNames?: string[];
|
|
120
|
-
allowedModels?: string[];
|
|
121
|
-
[key: string]: unknown;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export declare type PromptParams = Record<string, unknown>;
|
|
125
|
-
|
|
126
|
-
export declare interface PromptProfileConfig {
|
|
127
|
-
provider: string;
|
|
128
|
-
model: string;
|
|
129
|
-
params?: PromptParams | null;
|
|
130
|
-
temperature?: number;
|
|
131
|
-
maxTokens?: number;
|
|
132
|
-
[key: string]: unknown;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export declare const PromptRegistry: {
|
|
136
|
-
register(input: PromptDefinitionInput): PromptDefinition;
|
|
137
|
-
get(key: string): PromptDefinition | undefined;
|
|
138
|
-
has(key: string): boolean;
|
|
139
|
-
getAll(): PromptDefinition[];
|
|
140
|
-
clear(): void;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export declare interface ResolvedPrompt {
|
|
144
|
-
key: string;
|
|
145
|
-
template: string;
|
|
146
|
-
text: string;
|
|
147
|
-
ai: ResolvedPromptAI;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export declare interface ResolvedPromptAI extends PromptParams {
|
|
151
|
-
profile?: string;
|
|
152
|
-
provider?: string;
|
|
153
|
-
model?: string;
|
|
154
|
-
allowedModels?: string[];
|
|
155
|
-
params: PromptParams;
|
|
156
|
-
temperature?: number;
|
|
157
|
-
maxTokens?: number;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export declare function resolvePrompt(key: string, options?: ResolvePromptOptions): Promise<ResolvedPrompt>;
|
|
161
|
-
|
|
162
|
-
export declare interface ResolvePromptOptions {
|
|
163
|
-
db?: SmrtClassOptions['db'];
|
|
164
|
-
tenantId?: string | null;
|
|
165
|
-
variables?: Record<string, unknown>;
|
|
166
|
-
override?: PromptConfigOverrideInput;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export { }
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
declare global {
|
|
173
|
-
var __smrtPromptRegistry: Map<string, PromptDefinition> | undefined;
|
|
174
|
-
}
|
|
1
|
+
export { clearPromptCache, getPromptCacheTtlMs } from './cache.js';
|
|
2
|
+
export { PromptOverrideCollection } from './collections/PromptOverrideCollection.js';
|
|
3
|
+
export { PromptOverride, type PromptOverrideOptions, } from './models/PromptOverride.js';
|
|
4
|
+
export { InvalidPromptScopeError, PromptOverrideAuthorizationError, type PromptOverrideAuthorizer, PromptOverrideService, type PromptOverrideWriteRequest, } from './prompt-override-service.js';
|
|
5
|
+
export { definePrompt, PromptRegistry } from './prompt-registry.js';
|
|
6
|
+
export { resolvePrompt } from './prompt-resolver.js';
|
|
7
|
+
export { type ListPromptSettingsOptions, PromptFieldNotEditableError, type PromptSettingsLevel, type PromptSettingsRow, PromptSettingsService, type PromptSettingsServiceOptions, type SetPromptOverrideRequest, UnknownPromptKeyError, } from './prompt-settings.js';
|
|
8
|
+
export type { NormalizedPromptAI, PromptAIInput, PromptConfigOverrideInput, PromptDefinition, PromptDefinitionInput, PromptEditableConfig, PromptLayer, PromptOverrideScopeType, PromptPackageConfig, PromptParams, PromptProfileConfig, ResolvedPrompt, ResolvedPromptAI, ResolvePromptOptions, } from './types.js';
|
|
9
|
+
export { APP_PROMPT_SCOPE_ID } from './types.js';
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare const PACKAGE_VERSION_INITIALIZED = true;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,KAAK,wBAAwB,EAC7B,qBAAqB,EACrB,KAAK,0BAA0B,GAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,KAAK,yBAAyB,EAC9B,2BAA2B,EAC3B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,qBAAqB,EACrB,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,OAAO,CAAC"}
|