@happyvertical/smrt-preferences 0.60.18 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +3 -1
- package/agents/preference-kinds.md +45 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +230 -46
- package/dist/index.js.map +1 -1
- package/dist/kinds/builtin.d.ts.map +1 -1
- package/dist/kinds/prebuilt-components.d.ts +22 -0
- package/dist/kinds/prebuilt-components.d.ts.map +1 -0
- package/dist/kinds/work-profiles.d.ts +26 -0
- package/dist/kinds/work-profiles.d.ts.map +1 -0
- package/dist/manifest.json +4 -2
- package/dist/permissions.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +10 -8
- package/dist/smrt-knowledge.okf.md +2 -2
- package/package.json +8 -8
package/AGENTS.md
CHANGED
|
@@ -30,7 +30,9 @@ Svelte-free entries (`./overview/server`, `./workspace/server`).
|
|
|
30
30
|
| `src/store.ts` | `createPreferenceStore({ db })`: generic `load` / `save` / `reset(kind, surfaceId, ...)` |
|
|
31
31
|
| `src/kinds/overview.ts`, `src/overview.ts` | The `overview` kind and `createOverviewStore` (`load`, `save`, `reset`, `loadPage`, `loadWidget`, `withTenantDefaults`) |
|
|
32
32
|
| `src/kinds/shell-layout.ts` | The `shell-layout` kind and `createShellSettingsPreferences` (the server half of a `ShellSettingsAdapter`) |
|
|
33
|
-
| `src/kinds/
|
|
33
|
+
| `src/kinds/prebuilt-components.ts` | Tenant-wide pre-built components toggle, owner facade and exposure invalidation |
|
|
34
|
+
| `src/kinds/work-profiles.ts` | Owner work-profile overrides and revision-safe reset; inference owns resolution |
|
|
35
|
+
| `src/kinds/builtin.ts` | Registers the built-in kinds (imported by the entry and the store) |
|
|
34
36
|
| `src/context.ts` | The ambient principal and `PreferenceAccessError` |
|
|
35
37
|
| `src/permissions.ts` | `overviews.customize` / `overviews.personalize`, `shell.customize` / `shell.personalize` |
|
|
36
38
|
|
|
@@ -77,3 +77,48 @@ and `createShellSettingsPreferences` (the server half of the shell's
|
|
|
77
77
|
`ShellSettingsAdapter`: `read(surfaceId)` merges tenant and user with
|
|
78
78
|
`mergeShellSettingsDelta`; `write(surfaceId, delta, { scope?, revision? })`
|
|
79
79
|
is last-writer-wins only when the revision is omitted).
|
|
80
|
+
|
|
81
|
+
## Pre-built components
|
|
82
|
+
|
|
83
|
+
`createPrebuiltComponentsPreference({store,isOwner})` wraps the existing generic
|
|
84
|
+
store for the one tenant-wide `pre-built-components` / `app` preference,
|
|
85
|
+
`{enabled: boolean}`. The facade checks live owner membership on writes and the
|
|
86
|
+
store additionally requires `recipes.configure`. Personal tiers are invalid;
|
|
87
|
+
there is no user override. The default is enabled after a successful load with
|
|
88
|
+
no stored preference. Unknown tenants, malformed rows and unreadable storage
|
|
89
|
+
remain disabled. `write(enabled, revision)` uses the existing revision CAS.
|
|
90
|
+
|
|
91
|
+
Load/refresh before serving and after external changes. Connect its synchronous
|
|
92
|
+
`isEnabled(tenantId)` to the core cookbook runtime gate's host predicate. Writes
|
|
93
|
+
and `invalidate(tenantId)` call `notifyRuntimeExposureChanged`, so MCP hosts emit
|
|
94
|
+
`tools/list_changed`. Invalidation closes the cached value until the next good
|
|
95
|
+
read; multiple host processes must propagate invalidation. Hosts should expose
|
|
96
|
+
this facade to owner settings, not a generic kind/surface write endpoint.
|
|
97
|
+
The core [server tools](../../core/agents/cookbook-tools.md) use this same gate
|
|
98
|
+
for offering and execution, including retained tools and approval resume.
|
|
99
|
+
|
|
100
|
+
The permission registry reads the shared cookbook tool names from core's
|
|
101
|
+
browser-safe `./cookbook` entry. Do not import the server-only `./cookbook/tools`
|
|
102
|
+
adapter from this model package root: even a metadata import makes its
|
|
103
|
+
`node:crypto` dependency reachable to browser bundlers. The preferences suite
|
|
104
|
+
reuses bundle-gate's browser build and ownership attribution to guard this edge.
|
|
105
|
+
|
|
106
|
+
## Assistant work profiles
|
|
107
|
+
|
|
108
|
+
`createWorkProfilesPreference({store,isOwner})` owns the tenant-wide
|
|
109
|
+
`work-profiles` / `assistant` kind. Its sparse design, assist and background
|
|
110
|
+
settings contain engine, model, effort, budgets, automatic escalation and preview
|
|
111
|
+
preferences. Inference owns recommendations and resolution; this package imports
|
|
112
|
+
only its types, preserving the dependency direction. Missing settings resolve to
|
|
113
|
+
recommendations. `write(settings,revision)` and `reset(revision)` both check the
|
|
114
|
+
live owner plus `inference.customize`, and retain store CAS. User-tier overrides,
|
|
115
|
+
unknown fields (including approval/CLI authority), malformed budgets and models
|
|
116
|
+
are refused. Reads return validation issues without rewriting stored data.
|
|
117
|
+
|
|
118
|
+
Reuse inventory: MCP architecture context and name/purpose searches of the intent
|
|
119
|
+
index, preferences, inference, chat, core, smrt-ui and smrt-svelte found the generic
|
|
120
|
+
kind/store and the existing owner pre-built facade. This new kind reuses both;
|
|
121
|
+
no new table or preference persistence layer was added. Round-trip/reset and
|
|
122
|
+
owner/conflict/invalid-value assertions run in the existing SQLite/DuckDB suite.
|
|
123
|
+
|
|
124
|
+
S1 extends the existing owner `work-profiles` tenant preference with `safety.requireRemovalApproval` and `safety.protectLocalCli` booleans; absent means true. Unknown safety keys are invalid. Turning protection off requires the facade's explicit `confirmUnprotectedCli` acknowledgement unless already off; owner authorization and optimistic revision checks still apply. Reset removes the override and restores both defaults. Hosts must require an owner browser session, not just a scoped API principal, and must not register preference mutation as an assistant tool.
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ import './kinds/builtin.js';
|
|
|
14
14
|
export { getPreferencePrincipal, PreferenceAccessError, type PreferencePrincipal, } from './context.js';
|
|
15
15
|
export { ensureBuiltinPreferenceKinds } from './kinds/builtin.js';
|
|
16
16
|
export { OVERVIEW_PREFERENCE_KIND, type OverviewKindOptions, overviewPreferenceKind, withTenantDefaults, } from './kinds/overview.js';
|
|
17
|
+
export { createPrebuiltComponentsPreference, PREBUILT_COMPONENTS_PREFERENCE_KIND, } from './kinds/prebuilt-components.js';
|
|
17
18
|
export { createShellSettingsPreferences, SHELL_LAYOUT_PREFERENCE_KIND, type ShellSettingsPreferenceRead, type ShellSettingsPreferences, type ShellSettingsPreferenceWriteOptions, shellLayoutPreferenceKind, } from './kinds/shell-layout.js';
|
|
19
|
+
export { createWorkProfilesPreference, WORK_PROFILES_PREFERENCE_KIND, type WorkProfilePreferences, workProfilesPreferenceKind, } from './kinds/work-profiles.js';
|
|
18
20
|
export { getPreferenceKind, listPreferenceKinds, PREFERENCE_KIND_PATTERN, PREFERENCE_SCOPES, PREFERENCE_SURFACE_PATTERN, type PreferenceIssue, type PreferenceKindDefinition, type PreferenceScope, type PreferenceValidateContext, type PreferenceValidation, registerPreferenceKind, requirePreferenceKind, UnknownPreferenceKindError, } from './kinds.js';
|
|
19
21
|
export { TENANT_SCOPE_KEY, UiPreferenceRecord, } from './models/UiPreferenceRecord.js';
|
|
20
22
|
export { createOverviewStore, type OverviewPageOptions, type OverviewResetInput, type OverviewResetResult, type OverviewSaveInput, type OverviewSaveResult, type OverviewState, type OverviewStore, type OverviewStoreOptions, type OverviewTierState, type OverviewWidgetResult, type OverviewWriteFailure, } from './overview.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EACL,wBAAwB,EACxB,KAAK,mBAAmB,EACxB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7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pB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { GlobalInterceptors, ObjectRegistry, RuntimeError, SmrtCollection, SmrtObject, crossPackageRef, field, resolveGetStringFilter, smrt } from "@happyvertical/smrt-core";
|
|
2
|
+
import { COOKBOOK_TOOL_NAMES } from "@happyvertical/smrt-core/cookbook";
|
|
2
3
|
import { assertOperationPermission, checkOperationPermission, getCurrentSessionPermissionContext, registerPermissionDefinitions } from "@happyvertical/smrt-users";
|
|
3
4
|
import { checkOverviewOverride, diffOverview, loadOverview, optionsEqual, parseOverviewDocument, resolveOverview, sanitizeOverview } from "@happyvertical/smrt-svelte/overview/server";
|
|
4
|
-
import {
|
|
5
|
+
import { notifyRuntimeExposureChanged } from "@happyvertical/smrt-core/runtime-exposure";
|
|
5
6
|
import { TenantIsolationError, TenantScoped, getCurrentTenant, isSuperAdminBypass, tenantId, withTenant } from "@happyvertical/smrt-tenancy";
|
|
7
|
+
import { mergeShellSettingsDelta, sanitizeShellSettingsDelta } from "@happyvertical/smrt-svelte/workspace/server";
|
|
6
8
|
//#region src/__smrt-register__.ts
|
|
7
|
-
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-preferences","packageVersion":"0.
|
|
9
|
+
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-preferences","packageVersion":"0.61.0","objects":{"@happyvertical/smrt-preferences:UiPreferenceRecordCollection":{"name":"uipreferencerecordcollection","className":"UiPreferenceRecordCollection","qualifiedName":"@happyvertical/smrt-preferences:UiPreferenceRecordCollection","collection":"uipreferencerecords","description":"Reads of UiPreferenceRecord. Not decorated: the model has no generated surface, so a decorated collection would only add a second manifest schema for the same table.","filePath":"/home/runner/work/smrt/smrt/packages/preferences/src/collections/UiPreferenceRecordCollection.ts","packageName":"@happyvertical/smrt-preferences","fields":{},"methods":{"findTier":{"name":"findTier","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false},{"name":"kind","type":"string","optional":false},{"name":"surfaceId","type":"string","optional":false},{"name":"scope","type":"PreferenceScope","optional":false},{"name":"userId","type":"string","optional":true}],"returnType":"Promise<UiPreferenceRecord | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_ui_preferences","api":{"include":[]},"mcp":{"include":[]},"cli":false},"extends":"SmrtCollection","extendsTypeArg":"UiPreferenceRecord","exportName":"UiPreferenceRecordCollection","collectionExportName":"UiPreferenceRecordCollectionCollection","collectionOf":"@happyvertical/smrt-preferences:UiPreferenceRecord","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_ui_preferences","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_ui_preferences\\" (\\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 \\"tenant_id\\" UUID NOT NULL,\\n \\"kind\\" TEXT NOT NULL DEFAULT '',\\n \\"surface_id\\" TEXT NOT NULL DEFAULT '',\\n \\"scope_type\\" TEXT NOT NULL DEFAULT 'tenant',\\n \\"user_id\\" UUID,\\n \\"scope_key\\" TEXT NOT NULL,\\n \\"payload_json\\" TEXT NOT NULL,\\n \\"format_version\\" INTEGER,\\n \\"updated_by\\" UUID\\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"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"kind":{"type":"TEXT","notNull":true,"unique":false,"default":""},"surface_id":{"type":"TEXT","notNull":true,"unique":false,"default":""},"scope_type":{"type":"TEXT","notNull":true,"unique":false,"default":"tenant"},"user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"scope_key":{"type":"TEXT","notNull":true,"unique":false},"payload_json":{"type":"TEXT","notNull":true,"unique":false},"format_version":{"type":"INTEGER","notNull":false,"unique":false},"updated_by":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_ui_preferences_tenant_id_kind_idx","columns":["tenant_id","kind","surface_id","scope_type","scope_key"],"unique":true},{"name":"_smrt_ui_preferences_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_ui_preferences_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_ui_preferences_user_id_idx","columns":["user_id"]},{"name":"_smrt_ui_preferences_updated_by_idx","columns":["updated_by"]}],"version":"7db98e07"},"importPath":"@happyvertical/smrt-preferences"},"@happyvertical/smrt-preferences:UiPreferenceRecord":{"name":"uipreferencerecord","className":"UiPreferenceRecord","qualifiedName":"@happyvertical/smrt-preferences:UiPreferenceRecord","collection":"uipreferencerecords","description":"One stored user-interface preference (#3727): the canonical payload of a registered preference kind (overview, shell-layout, ...) for one surface at one tier of one tenant.","filePath":"/home/runner/work/smrt/smrt/packages/preferences/src/models/UiPreferenceRecord.ts","packageName":"@happyvertical/smrt-preferences","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"kind":{"type":"text","required":true,"default":"","_meta":{"required":true}},"surfaceId":{"type":"text","required":true,"default":"","_meta":{"required":true}},"scopeType":{"type":"text","required":true,"default":"tenant","_meta":{"required":true}},"userId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:User","_meta":{"nullable":true}},"scopeKey":{"type":"text","required":true,"_meta":{"required":true}},"payloadJson":{"type":"text","required":true,"_meta":{"required":true}},"formatVersion":{"type":"integer","required":false,"_meta":{}},"updatedBy":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:User","_meta":{"nullable":true}}},"methods":{"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getPayload":{"name":"getPayload","async":false,"parameters":[],"returnType":"unknown","isStatic":false,"isPublic":true},"setPayload":{"name":"setPayload","async":false,"parameters":[{"name":"value","type":"unknown","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"delete":{"name":"delete","async":true,"parameters":[{"name":"options","type":"DeleteOptions","optional":true}],"returnType":"Promise<void>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_ui_preferences","conflictColumns":["tenant_id","kind","surface_id","scope_type","scope_key"],"api":{"include":[]},"cli":false,"mcp":{"include":[]},"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"UiPreferenceRecord","collectionExportName":"UiPreferenceRecordCollection","validationRules":[{"field":"kind","rule":"required","fieldType":"text"},{"field":"surfaceId","rule":"required","fieldType":"text"},{"field":"scopeType","rule":"required","fieldType":"text"},{"field":"scopeKey","rule":"required","fieldType":"text"},{"field":"payloadJson","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_ui_preferences","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_ui_preferences\\" (\\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 \\"tenant_id\\" UUID NOT NULL,\\n \\"kind\\" TEXT NOT NULL DEFAULT '',\\n \\"surface_id\\" TEXT NOT NULL DEFAULT '',\\n \\"scope_type\\" TEXT NOT NULL DEFAULT 'tenant',\\n \\"user_id\\" UUID,\\n \\"scope_key\\" TEXT NOT NULL,\\n \\"payload_json\\" TEXT NOT NULL,\\n \\"format_version\\" INTEGER,\\n \\"updated_by\\" UUID\\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"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"kind":{"type":"TEXT","notNull":true,"unique":false,"default":""},"surface_id":{"type":"TEXT","notNull":true,"unique":false,"default":""},"scope_type":{"type":"TEXT","notNull":true,"unique":false,"default":"tenant"},"user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"scope_key":{"type":"TEXT","notNull":true,"unique":false},"payload_json":{"type":"TEXT","notNull":true,"unique":false},"format_version":{"type":"INTEGER","notNull":false,"unique":false},"updated_by":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_ui_preferences_tenant_id_kind_idx","columns":["tenant_id","kind","surface_id","scope_type","scope_key"],"unique":true},{"name":"_smrt_ui_preferences_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_ui_preferences_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_ui_preferences_user_id_idx","columns":["user_id"]},{"name":"_smrt_ui_preferences_updated_by_idx","columns":["updated_by"]}],"version":"7db98e07"},"importPath":"@happyvertical/smrt-preferences"}},"moduleType":"smrt","smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-inference","@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}`));
|
|
8
10
|
//#endregion
|
|
9
11
|
//#region src/permissions.ts
|
|
10
12
|
var CUSTOMIZE_OVERVIEW_PERMISSION = "overviews.customize";
|
|
@@ -12,6 +14,12 @@ var PERSONALIZE_OVERVIEW_PERMISSION = "overviews.personalize";
|
|
|
12
14
|
var CUSTOMIZE_SHELL_PERMISSION = "shell.customize";
|
|
13
15
|
var PERSONALIZE_SHELL_PERMISSION = "shell.personalize";
|
|
14
16
|
var PREFERENCE_PERMISSION_DEFINITIONS = [
|
|
17
|
+
...COOKBOOK_TOOL_NAMES.map((slug) => ({
|
|
18
|
+
slug,
|
|
19
|
+
category: "cookbook",
|
|
20
|
+
name: slug,
|
|
21
|
+
description: "Owner cookbook building-block tools"
|
|
22
|
+
})),
|
|
15
23
|
{
|
|
16
24
|
slug: CUSTOMIZE_OVERVIEW_PERMISSION,
|
|
17
25
|
category: "preferences",
|
|
@@ -171,6 +179,119 @@ var overviewPreferenceKind = {
|
|
|
171
179
|
}
|
|
172
180
|
};
|
|
173
181
|
//#endregion
|
|
182
|
+
//#region src/context.ts
|
|
183
|
+
function getPreferencePrincipal() {
|
|
184
|
+
const tenant = getCurrentTenant();
|
|
185
|
+
if (tenant?.tenantId) return {
|
|
186
|
+
tenantId: tenant.tenantId,
|
|
187
|
+
userId: tenant.userId,
|
|
188
|
+
permissions: tenant.permissions,
|
|
189
|
+
superAdminBypass: isSuperAdminBypass(),
|
|
190
|
+
fromTenancy: true
|
|
191
|
+
};
|
|
192
|
+
const session = getCurrentSessionPermissionContext();
|
|
193
|
+
if (!session?.tenantId) return void 0;
|
|
194
|
+
return {
|
|
195
|
+
tenantId: session.tenantId,
|
|
196
|
+
userId: session.userId ?? void 0,
|
|
197
|
+
permissions: session.permissionSet,
|
|
198
|
+
superAdminBypass: session.superAdminBypass,
|
|
199
|
+
fromTenancy: false
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
var PreferenceAccessError = class extends TenantIsolationError {
|
|
203
|
+
status = 403;
|
|
204
|
+
publicMessage;
|
|
205
|
+
constructor(message) {
|
|
206
|
+
super(message);
|
|
207
|
+
this.name = "PreferenceAccessError";
|
|
208
|
+
this.publicMessage = message;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
function requirePreferencePrincipal() {
|
|
212
|
+
const principal = getPreferencePrincipal();
|
|
213
|
+
if (!principal) throw new PreferenceAccessError("User-interface preferences need an authenticated tenant context");
|
|
214
|
+
return principal;
|
|
215
|
+
}
|
|
216
|
+
async function withPrincipal(principal, fn) {
|
|
217
|
+
if (principal.fromTenancy) return fn();
|
|
218
|
+
return withTenant({
|
|
219
|
+
tenantId: principal.tenantId,
|
|
220
|
+
userId: principal.userId,
|
|
221
|
+
permissions: new Set(principal.permissions)
|
|
222
|
+
}, fn);
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/kinds/prebuilt-components.ts
|
|
226
|
+
var PREBUILT_COMPONENTS_PREFERENCE_KIND = "pre-built-components";
|
|
227
|
+
var SURFACE$1 = "app";
|
|
228
|
+
var prebuiltComponentsPreferenceKind = {
|
|
229
|
+
kind: PREBUILT_COMPONENTS_PREFERENCE_KIND,
|
|
230
|
+
formatVersion: 1,
|
|
231
|
+
permissions: {
|
|
232
|
+
tenant: "recipes.configure",
|
|
233
|
+
user: "recipes.configure"
|
|
234
|
+
},
|
|
235
|
+
validate(payload, context) {
|
|
236
|
+
return context.scope === "tenant" && (payload === null || typeof payload === "object" && !Array.isArray(payload) && Object.keys(payload).length === 1 && typeof payload.enabled === "boolean") ? {
|
|
237
|
+
ok: true,
|
|
238
|
+
canonical: payload,
|
|
239
|
+
issues: []
|
|
240
|
+
} : {
|
|
241
|
+
ok: false,
|
|
242
|
+
canonical: null,
|
|
243
|
+
issues: [{
|
|
244
|
+
path: null,
|
|
245
|
+
code: "invalid_prebuilt_components",
|
|
246
|
+
message: "Pre-built components is one tenant preference: { enabled: boolean }."
|
|
247
|
+
}]
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
function createPrebuiltComponentsPreference(options) {
|
|
252
|
+
const enabled = /* @__PURE__ */ new Map();
|
|
253
|
+
const publish = (tenantId, value) => {
|
|
254
|
+
enabled.set(tenantId, value);
|
|
255
|
+
notifyRuntimeExposureChanged();
|
|
256
|
+
};
|
|
257
|
+
async function read() {
|
|
258
|
+
const principal = requirePreferencePrincipal();
|
|
259
|
+
try {
|
|
260
|
+
const state = await options.store.load(PREBUILT_COMPONENTS_PREFERENCE_KIND, SURFACE$1);
|
|
261
|
+
const value = state.issues.length === 0 && state.tenant.payload?.enabled !== false;
|
|
262
|
+
publish(principal.tenantId, value);
|
|
263
|
+
return {
|
|
264
|
+
enabled: value,
|
|
265
|
+
revision: state.tenant.revision
|
|
266
|
+
};
|
|
267
|
+
} catch (error) {
|
|
268
|
+
publish(principal.tenantId, false);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
read,
|
|
274
|
+
isEnabled(tenantId) {
|
|
275
|
+
return !!tenantId && enabled.get(tenantId) === true;
|
|
276
|
+
},
|
|
277
|
+
async write(value, revision) {
|
|
278
|
+
const principal = requirePreferencePrincipal();
|
|
279
|
+
if (!await options.isOwner(principal)) throw new PreferenceAccessError("Only the owner can change pre-built components");
|
|
280
|
+
const result = await options.store.save(PREBUILT_COMPONENTS_PREFERENCE_KIND, SURFACE$1, {
|
|
281
|
+
scope: "tenant",
|
|
282
|
+
payload: { enabled: value },
|
|
283
|
+
revision
|
|
284
|
+
});
|
|
285
|
+
if (result.ok) await read();
|
|
286
|
+
return result;
|
|
287
|
+
},
|
|
288
|
+
/** On store outage, owner logout or external preference invalidation. */
|
|
289
|
+
invalidate(tenantId) {
|
|
290
|
+
publish(tenantId, false);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
//#endregion
|
|
174
295
|
//#region src/kinds/shell-layout.ts
|
|
175
296
|
var SHELL_LAYOUT_PREFERENCE_KIND = "shell-layout";
|
|
176
297
|
function toPreferenceIssue(issue) {
|
|
@@ -240,54 +361,117 @@ function createShellSettingsPreferences(store) {
|
|
|
240
361
|
};
|
|
241
362
|
}
|
|
242
363
|
//#endregion
|
|
243
|
-
//#region src/kinds/
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
364
|
+
//#region src/kinds/work-profiles.ts
|
|
365
|
+
var WORK_PROFILES_PREFERENCE_KIND = "work-profiles";
|
|
366
|
+
var SURFACE = "assistant";
|
|
367
|
+
var profiles = /* @__PURE__ */ new Set([
|
|
368
|
+
"design",
|
|
369
|
+
"assist",
|
|
370
|
+
"background"
|
|
371
|
+
]);
|
|
372
|
+
var engines = /* @__PURE__ */ new Set([
|
|
373
|
+
"claude-code",
|
|
374
|
+
"codex",
|
|
375
|
+
"chatgpt",
|
|
376
|
+
"api"
|
|
377
|
+
]);
|
|
378
|
+
var budgets = /* @__PURE__ */ new Set([
|
|
379
|
+
"maxSteps",
|
|
380
|
+
"maxTokens",
|
|
381
|
+
"maxTurnTokens",
|
|
382
|
+
"requestTimeoutMs",
|
|
383
|
+
"turnTimeoutMs",
|
|
384
|
+
"maxRunTokens",
|
|
385
|
+
"runTimeoutMs",
|
|
386
|
+
"passes",
|
|
387
|
+
"repairRetries",
|
|
388
|
+
"toolResultChars"
|
|
389
|
+
]);
|
|
390
|
+
var record = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
391
|
+
function validSettings(value) {
|
|
392
|
+
if (!record(value)) return false;
|
|
393
|
+
return Object.entries(value).every(([key, v]) => {
|
|
394
|
+
if (key === "engine") return typeof v === "string" && engines.has(v);
|
|
395
|
+
if (key === "model") return typeof v === "string" && v.length > 0 && v.length <= 200 && !v.startsWith("-") && !/\s/.test(v) && [...v].every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127);
|
|
396
|
+
if (key === "effort") return typeof v === "string" && [
|
|
397
|
+
"low",
|
|
398
|
+
"medium",
|
|
399
|
+
"high",
|
|
400
|
+
"xhigh",
|
|
401
|
+
"max"
|
|
402
|
+
].includes(v);
|
|
403
|
+
if (key === "autoEscalate" || key === "previewBeforeApply") return typeof v === "boolean";
|
|
404
|
+
if (key === "budgets") return record(v) && Object.entries(v).every(([k, n]) => budgets.has(k) && Number.isSafeInteger(n) && n >= (k === "repairRetries" ? 0 : 1));
|
|
405
|
+
return false;
|
|
406
|
+
});
|
|
268
407
|
}
|
|
269
|
-
var
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
408
|
+
var workProfilesPreferenceKind = {
|
|
409
|
+
kind: WORK_PROFILES_PREFERENCE_KIND,
|
|
410
|
+
formatVersion: 1,
|
|
411
|
+
permissions: {
|
|
412
|
+
tenant: "inference.customize",
|
|
413
|
+
user: "inference.customize"
|
|
414
|
+
},
|
|
415
|
+
validate(payload, context) {
|
|
416
|
+
return context.scope === "tenant" && (payload === null || record(payload) && Object.entries(payload).every(([name, value]) => name === "safety" ? record(value) && Object.entries(value).every(([key, v]) => ["requireRemovalApproval", "protectLocalCli"].includes(key) && typeof v === "boolean") : profiles.has(name) && validSettings(value))) ? {
|
|
417
|
+
ok: true,
|
|
418
|
+
canonical: payload,
|
|
419
|
+
issues: []
|
|
420
|
+
} : {
|
|
421
|
+
ok: false,
|
|
422
|
+
canonical: null,
|
|
423
|
+
issues: [{
|
|
424
|
+
path: null,
|
|
425
|
+
code: "invalid_work_profiles",
|
|
426
|
+
message: "Work profiles must contain only supported engine, model, effort, budget, escalation and preview settings."
|
|
427
|
+
}]
|
|
428
|
+
};
|
|
276
429
|
}
|
|
277
430
|
};
|
|
278
|
-
function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
431
|
+
function createWorkProfilesPreference(options) {
|
|
432
|
+
async function owner() {
|
|
433
|
+
if (!await options.isOwner(requirePreferencePrincipal())) throw new PreferenceAccessError("Only the owner can change assistant quality");
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
async read() {
|
|
437
|
+
const state = await options.store.load(WORK_PROFILES_PREFERENCE_KIND, SURFACE);
|
|
438
|
+
return {
|
|
439
|
+
settings: state.tenant.payload ?? {},
|
|
440
|
+
revision: state.tenant.revision,
|
|
441
|
+
issues: state.issues
|
|
442
|
+
};
|
|
443
|
+
},
|
|
444
|
+
async write(settings, revision, confirmation) {
|
|
445
|
+
await owner();
|
|
446
|
+
if (settings?.safety?.protectLocalCli === false && confirmation?.confirmUnprotectedCli !== true) {
|
|
447
|
+
if ((await this.read()).settings.safety?.protectLocalCli !== false) throw new PreferenceAccessError("Confirm that chat can run commands and change files on this computer");
|
|
448
|
+
}
|
|
449
|
+
return options.store.save(WORK_PROFILES_PREFERENCE_KIND, SURFACE, {
|
|
450
|
+
scope: "tenant",
|
|
451
|
+
payload: settings,
|
|
452
|
+
revision
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
async reset(revision) {
|
|
456
|
+
await owner();
|
|
457
|
+
return options.store.reset(WORK_PROFILES_PREFERENCE_KIND, SURFACE, {
|
|
458
|
+
scope: "tenant",
|
|
459
|
+
revision
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
};
|
|
282
463
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/kinds/builtin.ts
|
|
466
|
+
function ensureBuiltinPreferenceKinds() {
|
|
467
|
+
for (const kind of [
|
|
468
|
+
workProfilesPreferenceKind,
|
|
469
|
+
overviewPreferenceKind,
|
|
470
|
+
shellLayoutPreferenceKind,
|
|
471
|
+
prebuiltComponentsPreferenceKind
|
|
472
|
+
]) if (!getPreferenceKind(kind.kind)) registerPreferenceKind(kind);
|
|
290
473
|
}
|
|
474
|
+
ensureBuiltinPreferenceKinds();
|
|
291
475
|
//#endregion
|
|
292
476
|
//#region src/read-guard.ts
|
|
293
477
|
var GUARD_NAME = "smrt-preferences:owner-reads";
|
|
@@ -985,6 +1169,6 @@ function createOverviewStore(options) {
|
|
|
985
1169
|
return store;
|
|
986
1170
|
}
|
|
987
1171
|
//#endregion
|
|
988
|
-
export { CUSTOMIZE_OVERVIEW_PERMISSION, CUSTOMIZE_SHELL_PERMISSION, OVERVIEW_PREFERENCE_KIND, PERSONALIZE_OVERVIEW_PERMISSION, PERSONALIZE_SHELL_PERMISSION, PREFERENCE_KIND_PATTERN, PREFERENCE_PERMISSION_DEFINITIONS, PREFERENCE_SCOPES, PREFERENCE_SURFACE_PATTERN, PreferenceAccessError, SHELL_LAYOUT_PREFERENCE_KIND, TENANT_SCOPE_KEY, UiPreferenceRecord, UnknownPreferenceKindError, createOverviewStore, createPreferenceStore, createShellSettingsPreferences, ensureBuiltinPreferenceKinds, ensurePreferencePermissionsRegistered, getPreferenceKind, getPreferencePrincipal, listPreferenceKinds, overviewPreferenceKind, registerPreferenceKind, requirePreferenceKind, shellLayoutPreferenceKind, splitPermissionSlug, withTenantDefaults };
|
|
1172
|
+
export { CUSTOMIZE_OVERVIEW_PERMISSION, CUSTOMIZE_SHELL_PERMISSION, OVERVIEW_PREFERENCE_KIND, PERSONALIZE_OVERVIEW_PERMISSION, PERSONALIZE_SHELL_PERMISSION, PREBUILT_COMPONENTS_PREFERENCE_KIND, PREFERENCE_KIND_PATTERN, PREFERENCE_PERMISSION_DEFINITIONS, PREFERENCE_SCOPES, PREFERENCE_SURFACE_PATTERN, PreferenceAccessError, SHELL_LAYOUT_PREFERENCE_KIND, TENANT_SCOPE_KEY, UiPreferenceRecord, UnknownPreferenceKindError, WORK_PROFILES_PREFERENCE_KIND, createOverviewStore, createPrebuiltComponentsPreference, createPreferenceStore, createShellSettingsPreferences, createWorkProfilesPreference, ensureBuiltinPreferenceKinds, ensurePreferencePermissionsRegistered, getPreferenceKind, getPreferencePrincipal, listPreferenceKinds, overviewPreferenceKind, registerPreferenceKind, requirePreferenceKind, shellLayoutPreferenceKind, splitPermissionSlug, withTenantDefaults, workProfilesPreferenceKind };
|
|
989
1173
|
|
|
990
1174
|
//# sourceMappingURL=index.js.map
|