@happyvertical/smrt-prompts 0.51.21 → 0.51.29
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
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
|
+
import { PromptOverrideCollection } from './collections/PromptOverrideCollection.js';
|
|
3
|
+
import { PromptOverride } from './models/PromptOverride.js';
|
|
4
|
+
import { PromptOverrideAuthorizer } from './prompt-override-service.js';
|
|
5
|
+
import { PromptEditableConfig, PromptOverrideScopeType } from './types.js';
|
|
6
|
+
/** The level that supplied a prompt's effective template. */
|
|
7
|
+
export type PromptSettingsLevel = 'default' | 'config' | 'app' | 'tenant';
|
|
8
|
+
/**
|
|
9
|
+
* One prompt, rendered for a management screen: the code-owned definition,
|
|
10
|
+
* the text actually in effect for the requested tenant, and the raw override
|
|
11
|
+
* state at each scope so the UI can show *why* it is in effect and what
|
|
12
|
+
* reverting a scope produces.
|
|
13
|
+
*/
|
|
14
|
+
export interface PromptSettingsRow {
|
|
15
|
+
/**
|
|
16
|
+
* The persisted identifier. Renaming it orphans every existing override —
|
|
17
|
+
* see the warning on {@link PromptSettingsService}.
|
|
18
|
+
*/
|
|
19
|
+
key: string;
|
|
20
|
+
/** Human description from the definition; may be empty. */
|
|
21
|
+
description: string;
|
|
22
|
+
/** Which fields a stored override may change, from the definition. */
|
|
23
|
+
editable: PromptEditableConfig;
|
|
24
|
+
/** The code-registered template, before the config layer or any override. */
|
|
25
|
+
defaultTemplate: string;
|
|
26
|
+
/**
|
|
27
|
+
* What {@link resolvePrompt} resolves the template to for the requested
|
|
28
|
+
* context — the text the application actually uses (unrendered: no
|
|
29
|
+
* `{variable}` substitution).
|
|
30
|
+
*/
|
|
31
|
+
effectiveTemplate: string;
|
|
32
|
+
/** The app-level override row's `template` field, or `null` when there is none. */
|
|
33
|
+
appTemplate: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* The tenant-level override row's `template` field, or `null` when there is
|
|
36
|
+
* none (or when no `tenantId` was requested).
|
|
37
|
+
*/
|
|
38
|
+
tenantTemplate: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* What the **app** scope's "revert to default" produces: the code default
|
|
41
|
+
* merged with the config-file layer. Always knowable — nothing sits above
|
|
42
|
+
* the app scope — unlike {@link inheritedTemplate}.
|
|
43
|
+
*/
|
|
44
|
+
appDefaultTemplate: string;
|
|
45
|
+
/**
|
|
46
|
+
* What the **tenant** scope's "revert to default" produces: the code
|
|
47
|
+
* default, the config-file layer, and the app-level override, merged with
|
|
48
|
+
* no tenant override of its own. `null` when no `tenantId` was requested.
|
|
49
|
+
*
|
|
50
|
+
* This is the value a "revert to default" control for the tenant scope must
|
|
51
|
+
* show or apply — never {@link defaultTemplate}, which ignores the config
|
|
52
|
+
* layer and any app-level override and would silently discard them.
|
|
53
|
+
*/
|
|
54
|
+
inheritedTemplate: string | null;
|
|
55
|
+
/** Which level supplied {@link effectiveTemplate}. */
|
|
56
|
+
supplyingLevel: PromptSettingsLevel;
|
|
57
|
+
}
|
|
58
|
+
/** Selection for {@link PromptSettingsService.listPromptSettings}. */
|
|
59
|
+
export interface ListPromptSettingsOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Tenant whose overrides and effective template to report. Omit for an
|
|
62
|
+
* app-only view.
|
|
63
|
+
*/
|
|
64
|
+
tenantId?: string | null;
|
|
65
|
+
/**
|
|
66
|
+
* Restrict to an explicit allowlist of keys. Keys with no definition are
|
|
67
|
+
* simply absent from the result — this filters, it does not validate.
|
|
68
|
+
*/
|
|
69
|
+
keys?: string[];
|
|
70
|
+
}
|
|
71
|
+
/** One override write requested through {@link PromptSettingsService}. */
|
|
72
|
+
export interface SetPromptOverrideRequest {
|
|
73
|
+
key: string;
|
|
74
|
+
scopeType: PromptOverrideScopeType;
|
|
75
|
+
scopeId: string;
|
|
76
|
+
/** `null` clears the override, returning the scope to whatever it inherits. */
|
|
77
|
+
template: string | null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when a write names a `key` that has no registered {@link PromptDefinition}.
|
|
81
|
+
* Nothing is written.
|
|
82
|
+
*
|
|
83
|
+
* This is the generalized form of the per-app "is this one of my keys?" guard
|
|
84
|
+
* every consumer would otherwise hand-roll to keep a form post from creating an
|
|
85
|
+
* override for an arbitrary string.
|
|
86
|
+
*/
|
|
87
|
+
export declare class UnknownPromptKeyError extends Error {
|
|
88
|
+
readonly key: string;
|
|
89
|
+
readonly status = 400;
|
|
90
|
+
constructor(key: string);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Thrown when a write would set a field the definition's `editable` config
|
|
94
|
+
* does not allow overriding. Nothing is written.
|
|
95
|
+
*/
|
|
96
|
+
export declare class PromptFieldNotEditableError extends Error {
|
|
97
|
+
readonly key: string;
|
|
98
|
+
readonly field: string;
|
|
99
|
+
readonly status = 400;
|
|
100
|
+
constructor(key: string, field: string);
|
|
101
|
+
}
|
|
102
|
+
/** Options for {@link PromptSettingsService.create}. */
|
|
103
|
+
export interface PromptSettingsServiceOptions {
|
|
104
|
+
/**
|
|
105
|
+
* The host's authorization decision for each override write, bound to the
|
|
106
|
+
* current caller. **Omitting it makes the service read-only**: every write
|
|
107
|
+
* then fails closed with `PromptOverrideAuthorizationError`. This package
|
|
108
|
+
* never decides who may write.
|
|
109
|
+
*/
|
|
110
|
+
authorize?: PromptOverrideAuthorizer;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Read and write side of a prompt management screen, so consumers do not
|
|
114
|
+
* re-derive the row shape or the unknown-key guard.
|
|
115
|
+
*
|
|
116
|
+
* **Authorization stays with the consumer.** This service makes no
|
|
117
|
+
* authorization decision of its own: reads are unfiltered, and every write is
|
|
118
|
+
* delegated to {@link PromptOverrideService}, which asks the host-supplied
|
|
119
|
+
* {@link PromptOverrideAuthorizer} first and fails closed. Call it only from
|
|
120
|
+
* server code that has already established who the caller is. See
|
|
121
|
+
* `packages/prompts/README.md` for the consumer recipe.
|
|
122
|
+
*
|
|
123
|
+
* **Prompt keys are persisted identifiers.** Overrides are stored keyed by the
|
|
124
|
+
* exact `key` string and resolved by that string at runtime. Renaming a key
|
|
125
|
+
* orphans every existing override, silently reverting all tenants to the
|
|
126
|
+
* registry default. Treat a key as immutable once shipped; a rename needs a
|
|
127
|
+
* data migration, not an edit.
|
|
128
|
+
*/
|
|
129
|
+
export declare class PromptSettingsService {
|
|
130
|
+
private readonly overrides;
|
|
131
|
+
private readonly writes;
|
|
132
|
+
constructor(overrides: PromptOverrideCollection, authorize?: PromptOverrideAuthorizer);
|
|
133
|
+
/**
|
|
134
|
+
* Build a service over the given database options.
|
|
135
|
+
*
|
|
136
|
+
* The internal bulk override-enumeration read {@link listPromptSettings}
|
|
137
|
+
* runs is always issued without the caller's
|
|
138
|
+
* `defaultListLimit`/`maxListLimit` — see {@link withoutListBounds}. Only
|
|
139
|
+
* that read is affected; a `db` option is still honored.
|
|
140
|
+
*
|
|
141
|
+
* @param options - SMRT database options, as passed to any collection.
|
|
142
|
+
* @param serviceOptions - Host authorizer. Omit for a read-only (load-function) service.
|
|
143
|
+
*/
|
|
144
|
+
static create(options?: SmrtClassOptions, serviceOptions?: PromptSettingsServiceOptions): Promise<PromptSettingsService>;
|
|
145
|
+
/**
|
|
146
|
+
* One {@link PromptSettingsRow} per matching registered prompt, ordered by
|
|
147
|
+
* key, so a rendered list is stable across loads.
|
|
148
|
+
*
|
|
149
|
+
* Makes no authorization decision — the caller has already decided that this
|
|
150
|
+
* principal may see this tenant's prompts.
|
|
151
|
+
*/
|
|
152
|
+
listPromptSettings(options?: ListPromptSettingsOptions): Promise<PromptSettingsRow[]>;
|
|
153
|
+
/** The single row for one key, or `null` when no definition owns that key. */
|
|
154
|
+
getPromptSetting(key: string, tenantId?: string | null): Promise<PromptSettingsRow | null>;
|
|
155
|
+
/**
|
|
156
|
+
* Apply one override change to the `template` field.
|
|
157
|
+
*
|
|
158
|
+
* Refuses any `key` without a registered {@link PromptDefinition}, any scope
|
|
159
|
+
* the resolver would never read back, and a non-`null` template when the
|
|
160
|
+
* definition's `editable.template` is `false`, then delegates to
|
|
161
|
+
* {@link PromptOverrideService} so the host authorizer decides whether this
|
|
162
|
+
* caller may write this scope. `template: null` clears the override.
|
|
163
|
+
*
|
|
164
|
+
* @throws {UnknownPromptKeyError} when the key has no definition.
|
|
165
|
+
* @throws {InvalidPromptScopeError} when the scope is not one the resolver reads.
|
|
166
|
+
* @throws {PromptFieldNotEditableError} when the definition disallows template overrides.
|
|
167
|
+
* @throws `PromptOverrideAuthorizationError` when the authorizer declines.
|
|
168
|
+
*/
|
|
169
|
+
setPromptOverride(request: SetPromptOverrideRequest): Promise<PromptOverride>;
|
|
170
|
+
/** {@link setPromptOverride} for the app-wide scope. */
|
|
171
|
+
setAppPromptOverride(key: string, template: string | null): Promise<PromptOverride>;
|
|
172
|
+
/** {@link setPromptOverride} for one tenant. */
|
|
173
|
+
setTenantPromptOverride(key: string, tenantId: string, template: string | null): Promise<PromptOverride>;
|
|
174
|
+
private assertKnownPromptKey;
|
|
175
|
+
private loadDefinitions;
|
|
176
|
+
private toRow;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Reject a scope the resolver would never read back.
|
|
180
|
+
*
|
|
181
|
+
* `PromptOverride` rows are looked up by the exact `(key, tenantId)` pair —
|
|
182
|
+
* `tenantId: null` for the app scope, a tenant id otherwise. A row written
|
|
183
|
+
* under a scope nothing queries is invisible state: it never takes effect,
|
|
184
|
+
* and the host authorizer cannot catch it, because `scopeType: 'app'` with
|
|
185
|
+
* someone else's tenant id looks like an ordinary app write to an authorizer
|
|
186
|
+
* that only gates the app scope.
|
|
187
|
+
*/
|
|
188
|
+
//# sourceMappingURL=prompt-settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-settings.d.ts","sourceRoot":"","sources":["../src/prompt-settings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;A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