@camstack/addon-auth 1.2.151 → 1.2.153

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.
@@ -5546,7 +5546,7 @@ var ZodIssueCode = {
5546
5546
  var ZodFirstPartyTypeKind;
5547
5547
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5548
5548
  //#endregion
5549
- //#region ../types/dist/sleep-BxjU_fJM.mjs
5549
+ //#region ../types/dist/sleep-yKL5gfrH.mjs
5550
5550
  /**
5551
5551
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5552
5552
  * window to float samples (D455).
@@ -7928,6 +7928,12 @@ function normalizeAddonInitResult(result) {
7928
7928
  if (Array.isArray(result)) return { providers: result };
7929
7929
  return result;
7930
7930
  }
7931
+ /**
7932
+ * The share-view scope kinds a share-link token can carry. The hub mints
7933
+ * and validates them (`ShareViewGrantSchema` builds its
7934
+ * enum from this list); a data plane names the kinds it ACCEPTS in `share`.
7935
+ */
7936
+ var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
7931
7937
  /** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
7932
7938
  var PeerBytesTicketSchema = object({
7933
7939
  /** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
@@ -12892,6 +12898,280 @@ var ConvertResultSchema = object({
12892
12898
  })).readonly()
12893
12899
  });
12894
12900
  /**
12901
+ * Zod schemas for persisted record types.
12902
+ *
12903
+ * These schemas serve as the single source of truth for types that are
12904
+ * stored in the settings-store backend and retrieved via tRPC. They
12905
+ * replace the manual TypeScript interfaces with schema-derived types,
12906
+ * enabling runtime validation when reading from the backend.
12907
+ *
12908
+ * Convention: each schema is named `<Type>Schema`, the inferred TS type
12909
+ * keeps the original name for backward compatibility.
12910
+ */
12911
+ /**
12912
+ * Auth model (v2 — 2026-05-12 caps-only):
12913
+ *
12914
+ * Two principals:
12915
+ * - `isAdmin: true` — full bypass. Admin scope set is ignored.
12916
+ * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
12917
+ *
12918
+ * No role enum. There used to be `viewer / agent / scoped` and earlier
12919
+ * `super_admin` — collapsed onto the single boolean because every
12920
+ * non-admin caller is governed by the same scope-check rules; the
12921
+ * distinction was only ever used to route role-specific procedures
12922
+ * which we no longer have. CLI / webhook integrations are tokens (`auth.mintToken`)
12923
+ * with `isAdmin: false` + an explicit scope list.
12924
+ */
12925
+ /** Per-method access flavour. Materialised on every cap method via codegen. */
12926
+ var MethodAccessSchema = _enum([
12927
+ "view",
12928
+ "create",
12929
+ "delete"
12930
+ ]);
12931
+ /**
12932
+ * A single scope grant. Three forms — checked in matcher with OR
12933
+ * semantics; the first match decides whether the call passes:
12934
+ *
12935
+ * - `category` — broadest. `target: 'device' | 'system'` selects every
12936
+ * cap with the matching `scope` declaration. New caps inherit grants
12937
+ * automatically — adding a device cap to the codebase makes it
12938
+ * reachable to every user with `category:device [...]` without a
12939
+ * re-grant. Use this for "family viewer" / "operator" tiers.
12940
+ *
12941
+ * - `addon` — every cap that ships inside a given addon id. Niche;
12942
+ * useful when an integration needs to interact with one specific
12943
+ * addon's surface regardless of how many caps it exports.
12944
+ *
12945
+ * - `capability` — the most precise form. Single cap name. Use for
12946
+ * integration tokens where you want to grant `addons.installPackage`
12947
+ * and nothing else.
12948
+ *
12949
+ * `access` is REQUIRED with min 1 element. `admin` bypass is the
12950
+ * "give me everything" escape; there is no wildcard scope.
12951
+ */
12952
+ var AllowedProviderSchema = union([literal("*"), array(string())]);
12953
+ var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
12954
+ var CapScopeSchema = _enum(["device", "system"]);
12955
+ /**
12956
+ * DeviceSelector (scope model v3 — 2026-08-12).
12957
+ *
12958
+ * A `device` grant no longer carries a frozen list of deviceIds. It carries
12959
+ * a SELECTOR the matcher resolves against the live fleet, so the grant can be
12960
+ * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
12961
+ * AFTER the grant was minted — no re-grant, no re-login.
12962
+ *
12963
+ * - `all` — every device in the deployment. The broad viewer/operator
12964
+ * lever without a `category` grant (a `category` grant also covers device
12965
+ * caps that carry no deviceId; `all` is specifically the device set).
12966
+ * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
12967
+ * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
12968
+ * is NOT covered until the grant is edited.
12969
+ * - `types` — every device of a `DeviceType` (e.g. every `camera`).
12970
+ * DYNAMIC. A device that changes type, or a new device of the type,
12971
+ * re-resolves on the next request.
12972
+ * - `locations` — every device whose operator-assigned `location` label is
12973
+ * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
12974
+ * null/unset location matches NO `locations` selector.
12975
+ */
12976
+ var DeviceSelectorSchema = discriminatedUnion("kind", [
12977
+ object({ kind: literal("all") }),
12978
+ object({
12979
+ kind: literal("ids"),
12980
+ ids: array(number().int()).min(1)
12981
+ }),
12982
+ object({
12983
+ kind: literal("types"),
12984
+ types: array(_enum(DeviceType)).min(1)
12985
+ }),
12986
+ object({
12987
+ kind: literal("locations"),
12988
+ locations: array(string().min(1)).min(1)
12989
+ })
12990
+ ]);
12991
+ var DeviceTokenScopeSchema = object({
12992
+ type: literal("device"),
12993
+ /** The device SET this grant covers — resolved against the live fleet. */
12994
+ selector: DeviceSelectorSchema,
12995
+ access: array(MethodAccessSchema).min(1),
12996
+ /**
12997
+ * Whether a grant on a PARENT device transparently covers its accessory
12998
+ * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
12999
+ * Direction is parent → children ONLY.
13000
+ *
13001
+ * Absent → the matcher DERIVES it from the access flavour: `view`
13002
+ * inherits (a camera viewer sees the camera's accessories), `create` /
13003
+ * `delete` do NOT (actuating/removing a child is an explicit act the
13004
+ * operator must grant on the child, not inherit from the parent). Set it
13005
+ * explicitly to override that default per grant.
13006
+ */
13007
+ includeLinked: boolean().optional()
13008
+ });
13009
+ /**
13010
+ * v2 → v3 lazy migration. A pre-v3 `device` grant carried
13011
+ * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
13012
+ * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
13013
+ * EVERY parse path — stored records AND the JWT-carried scope arrays
13014
+ * normalised at the request boundary ({@link normalizeTokenScopes} in
13015
+ * `device-selector.ts`). Chosen over a one-time DB migration because a
13016
+ * migration cannot reach a JWT already in a client's hands; parse-time
13017
+ * migration covers both without a flag day. No cast — the raw object is read
13018
+ * through `Reflect.get` (its static type is `unknown`).
13019
+ */
13020
+ function migrateLegacyTokenScope(raw) {
13021
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
13022
+ if (Reflect.get(raw, "type") !== "device") return raw;
13023
+ if (Reflect.get(raw, "selector") !== void 0) return raw;
13024
+ const targets = Reflect.get(raw, "targets");
13025
+ if (!Array.isArray(targets)) return raw;
13026
+ return {
13027
+ type: "device",
13028
+ selector: {
13029
+ kind: "ids",
13030
+ ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
13031
+ },
13032
+ access: Reflect.get(raw, "access")
13033
+ };
13034
+ }
13035
+ var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
13036
+ object({
13037
+ type: literal("category"),
13038
+ target: CapScopeSchema,
13039
+ access: array(MethodAccessSchema).min(1)
13040
+ }),
13041
+ object({
13042
+ type: literal("capability"),
13043
+ target: string(),
13044
+ access: array(MethodAccessSchema).min(1)
13045
+ }),
13046
+ object({
13047
+ type: literal("addon"),
13048
+ target: string(),
13049
+ access: array(MethodAccessSchema).min(1)
13050
+ }),
13051
+ DeviceTokenScopeSchema
13052
+ ]));
13053
+ object({
13054
+ id: string(),
13055
+ username: string(),
13056
+ passwordHash: string(),
13057
+ /**
13058
+ * Admin bypass. When true, the middleware skips the scope-access
13059
+ * check entirely. There is no other axis of privilege; the legacy
13060
+ * role enum collapsed onto this boolean in v2.
13061
+ */
13062
+ isAdmin: boolean().default(false),
13063
+ allowedProviders: AllowedProviderSchema,
13064
+ allowedDevices: AllowedDevicesSchema,
13065
+ /**
13066
+ * Scopes granted to this user. Admins bypass; their `scopes` is
13067
+ * ignored. Non-admins without scopes are locked out of every
13068
+ * protected call.
13069
+ */
13070
+ scopes: array(TokenScopeSchema).default([]),
13071
+ createdAt: number(),
13072
+ updatedAt: number()
13073
+ });
13074
+ object({
13075
+ id: string(),
13076
+ label: string(),
13077
+ isAdmin: boolean().default(false),
13078
+ allowedProviders: AllowedProviderSchema,
13079
+ allowedDevices: AllowedDevicesSchema,
13080
+ tokenHash: string(),
13081
+ tokenPrefix: string(),
13082
+ createdAt: number(),
13083
+ lastUsedAt: number().optional()
13084
+ });
13085
+ object({
13086
+ id: string(),
13087
+ userId: string(),
13088
+ name: string(),
13089
+ tokenHash: string(),
13090
+ tokenPrefix: string(),
13091
+ scopes: array(TokenScopeSchema),
13092
+ expiresAt: number().nullish(),
13093
+ lastUsedAt: number().nullish(),
13094
+ createdAt: number()
13095
+ });
13096
+ /** What a share-view grant lets its holder see. */
13097
+ var ShareViewGrantSchema = object({
13098
+ kind: _enum(SHARE_VIEW_KINDS),
13099
+ deviceIds: array(number().int().nonnegative()).min(1).max(64),
13100
+ /** Talk-back, opt-in at mint time; absent means off. */
13101
+ talk: boolean().optional()
13102
+ });
13103
+ var ShareViewScopeSchema = object({
13104
+ type: literal("share-view"),
13105
+ grant: ShareViewGrantSchema
13106
+ });
13107
+ var AddonRoutesScopeSchema = object({
13108
+ type: literal("addon-routes"),
13109
+ access: array(MethodAccessSchema).min(1)
13110
+ });
13111
+ var PreferencesSelfScopeSchema = object({ type: literal("preferences-self") });
13112
+ var CredentialScopeSchema = union([
13113
+ literal("*"),
13114
+ ShareViewScopeSchema,
13115
+ AddonRoutesScopeSchema,
13116
+ PreferencesSelfScopeSchema,
13117
+ TokenScopeSchema
13118
+ ]);
13119
+ object({
13120
+ kind: literal("credential"),
13121
+ sub: string().min(1),
13122
+ jti: string().min(16),
13123
+ scopes: array(CredentialScopeSchema).min(1)
13124
+ });
13125
+ var PreferenceNamespaceSchema = string().regex(/^[a-z][a-z0-9.-]{0,63}$/);
13126
+ /** A namespace's value: a JSON object, opaque to the hub. */
13127
+ var PreferenceValueSchema = record(string(), unknown());
13128
+ var PreferenceDeviceIdSchema = string().min(1).max(64);
13129
+ /** A stored row, as the owner reads it. */
13130
+ var PreferenceRowSchema = object({
13131
+ namespace: PreferenceNamespaceSchema,
13132
+ value: PreferenceValueSchema,
13133
+ /** Starts at 1, +1 on every write of this namespace. A delete ends the row and its count. */
13134
+ revision: number().int().positive(),
13135
+ updatedAt: number().int(),
13136
+ /** The client id the last writer sent; `null` when it sent none. */
13137
+ updatedByDevice: PreferenceDeviceIdSchema.nullable()
13138
+ });
13139
+ object({
13140
+ /** Absent: every namespace the caller holds. */
13141
+ namespaces: array(PreferenceNamespaceSchema).max(32).optional() });
13142
+ object({ rows: array(PreferenceRowSchema) });
13143
+ object({
13144
+ namespace: PreferenceNamespaceSchema,
13145
+ value: PreferenceValueSchema,
13146
+ /**
13147
+ * The revision the edit was based on. Absent: last write wins. `0`: the
13148
+ * namespace must not exist yet. Any other value that is not the current
13149
+ * revision answers `conflict` and writes nothing.
13150
+ */
13151
+ baseRevision: number().int().nonnegative().optional(),
13152
+ deviceId: PreferenceDeviceIdSchema.optional()
13153
+ });
13154
+ discriminatedUnion("status", [object({
13155
+ status: literal("saved"),
13156
+ row: PreferenceRowSchema
13157
+ }), object({
13158
+ status: literal("conflict"),
13159
+ current: PreferenceRowSchema.nullable()
13160
+ })]);
13161
+ object({ namespace: PreferenceNamespaceSchema });
13162
+ object({
13163
+ /** `false` when the namespace did not exist. */
13164
+ deleted: boolean() });
13165
+ object({
13166
+ /** The revision the client holds per namespace; a namespace it does not list is new to it. */
13167
+ revisionByNamespace: record(PreferenceNamespaceSchema, number().int().nonnegative()).refine((map) => Object.keys(map).length <= 32, { message: `at most 32 namespaces` }) });
13168
+ object({
13169
+ /** Every row whose revision differs from the client's, and every row it did not list. */
13170
+ rows: array(PreferenceRowSchema),
13171
+ /** Namespaces the client listed that no longer exist. */
13172
+ deleted: array(PreferenceNamespaceSchema)
13173
+ });
13174
+ /**
12895
13175
  * The viewer app's custom-scheme callback — the ONE list of URLs a hub flow
12896
13176
  * may hand a browser back to the native app at.
12897
13177
  *
@@ -40046,38 +40326,37 @@ method(LlmRuntimeCompleteInputSchema, LlmGenerateResultSchema, {
40046
40326
  auth: "admin",
40047
40327
  timeoutMs: AI_CAP_TRANSPORT_TIMEOUT_MS
40048
40328
  });
40329
+ var LlmProfileKindSchema = string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/, "a kind id is lower-case letters, digits and dashes");
40330
+ /** What a model (or, by default, every model of a kind) can do. */
40331
+ var LlmModelFeaturesSchema = object({
40332
+ vision: boolean(),
40333
+ tools: boolean(),
40334
+ streaming: boolean()
40335
+ });
40336
+ /** One model a provider offers. `features` overrides the kind's defaults, per field. */
40337
+ var LlmModelInfoSchema = object({
40338
+ id: string(),
40339
+ label: string().optional(),
40340
+ contextLength: number().int().positive().optional(),
40341
+ features: LlmModelFeaturesSchema.partial().optional()
40342
+ });
40049
40343
  /**
40050
- * `llm` — consumer-facing LLM surface (spec §1-§3). Collection-mode: array
40051
- * methods concat-fan across providers; single-row methods route to ONE
40052
- * provider by the `addonId` in the call input (the notification-output
40053
- * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
40054
- * (hub-placed); the cap stays open for future providers.
40055
- *
40056
- * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
40057
- * `apiKey` is a password field — providers REDACT it on read and merge on
40058
- * write; a stored key NEVER round-trips to a client.
40344
+ * The provider-specific part of a profile, validated by the provider that owns
40345
+ * the kind (`upsertProfile` refuses what it does not accept). A field its
40346
+ * `connectionSchema` declares `type: 'password'` is a secret: it is held in the
40347
+ * keychain, never in the row, and reads back as the redaction marker.
40059
40348
  */
40060
- var LlmProfileKindSchema = _enum([
40061
- "openai-compatible",
40062
- "openai",
40063
- "anthropic",
40064
- "google",
40065
- "managed-local",
40066
- "apple-foundation"
40067
- ]);
40349
+ var LlmProviderConfigSchema = record(string(), unknown());
40068
40350
  var LlmProfileSchema = object({
40069
40351
  id: string(),
40070
40352
  name: string(),
40353
+ /** The provider-declared kind (`LlmProfileKindDescriptor.kind`). */
40071
40354
  kind: LlmProfileKindSchema,
40072
40355
  /** Stamped by the provider — keeps the fanned catalog routable. */
40073
40356
  addonId: string(),
40074
40357
  enabled: boolean(),
40075
40358
  /** Vendor model id, or the managed runtime's loaded model. */
40076
40359
  model: string(),
40077
- /** Required for openai-compatible; override for cloud kinds. */
40078
- baseUrl: string().optional(),
40079
- /** ConfigUISchema type:'password' — never round-trips (spec §5). */
40080
- apiKey: string().optional(),
40081
40360
  /** Vision on/off. A vision call against a `false` profile is REFUSED, never
40082
40361
  * degraded to text — that shipped once and produced a confident answer to a
40083
40362
  * question about a picture nobody sent. */
@@ -40085,15 +40364,11 @@ var LlmProfileSchema = object({
40085
40364
  temperature: number().min(0).max(2).optional(),
40086
40365
  /** Nucleus sampling. Every wire we speak has it. */
40087
40366
  topP: number().min(0).max(1).optional(),
40088
- /** Top-k sampling. Carried only by the wires that have it — NEITHER OpenAI
40089
- * wire does, and the client drops it there (measured: the request body gets
40090
- * `top_p` and no `top_k`). The profile editor hides the field wherever it
40091
- * would change nothing; `KINDS_WITH_TOP_K` is the single owner of that list. */
40367
+ /** Top-k sampling. Carried only by the wires that have it — a kind offers the
40368
+ * field in its editor only when its descriptor lists it in `profileFields`. */
40092
40369
  topK: number().int().positive().optional(),
40093
40370
  maxTokens: number().int().positive().optional(),
40094
- /** Prompt context window. Advisory for cloud kinds (they enforce their own);
40095
- * for `managed-local` it is the llama.cpp `--ctx-size` the runtime starts
40096
- * the model with, so it is the one field that changes a PROCESS. */
40371
+ /** Prompt context window. Advisory for cloud kinds (they enforce their own). */
40097
40372
  contextLength: number().int().positive().optional(),
40098
40373
  /** Default system prompt. A caller's `system` REPLACES it (never appends —
40099
40374
  * two system prompts fighting is worse than either alone). */
@@ -40119,16 +40394,37 @@ var LlmProfileSchema = object({
40119
40394
  * library; the REGISTRY of callable tools is ours and is empty in v1, so a
40120
40395
  * `true` here buys the wiring, not behaviour, until tools are registered. */
40121
40396
  toolsEnabled: boolean().default(false),
40122
- extraHeaders: record(string(), string()).optional(),
40123
- /** kind === 'managed-local' only (spec §4). */
40124
- runtime: ManagedRuntimeConfigSchema.optional(),
40125
- /**
40126
- * kind === 'apple-foundation' only: WHERE it runs — the only thing there is
40127
- * to configure (no key, no URL, no download; `model` is `apple-system`).
40128
- * `supportsVision` on such a row is stamped by the provider from the node's
40129
- * reported `imageInput`, never taken from the operator (D62).
40130
- */
40131
- appleFoundation: object({ nodeId: string() }).optional()
40397
+ /** Everything the kind's provider owns (endpoint, key, node, runtime…). */
40398
+ providerConfig: LlmProviderConfigSchema.default({})
40399
+ });
40400
+ /**
40401
+ * The common profile fields a kind's editor offers. The editor owns how each
40402
+ * one is drawn; the provider says which of them mean something on its wire.
40403
+ */
40404
+ var LlmProfileFieldSchema = _enum([
40405
+ "temperature",
40406
+ "topP",
40407
+ "topK",
40408
+ "maxTokens",
40409
+ "contextLength",
40410
+ "systemPrompt",
40411
+ "timeoutMs",
40412
+ "connectTimeoutMs",
40413
+ "firstTokenTimeoutMs",
40414
+ "idleTimeoutMs",
40415
+ "retry",
40416
+ "toolsEnabled"
40417
+ ]);
40418
+ /**
40419
+ * A provider-drawn part of the editor, by a generic widget id the admin UI
40420
+ * registers (`ai/apple-node`). `placement: 'model'` replaces the generic model
40421
+ * picker: that widget owns the model choice.
40422
+ */
40423
+ var LlmProviderWidgetSchema = object({
40424
+ id: string(),
40425
+ placement: _enum(["connection", "model"]),
40426
+ /** `providerConfig` keys this widget must fill before the profile can be saved. */
40427
+ requires: array(string()).optional()
40132
40428
  });
40133
40429
  /** ConfigUISchema tree passed through untyped on the wire (the
40134
40430
  * notification-output `ConfigSchemaPassthrough` precedent at
@@ -40137,11 +40433,56 @@ var ConfigSchemaPassthrough$3 = unknown();
40137
40433
  var LlmProfileKindDescriptorSchema = object({
40138
40434
  kind: LlmProfileKindSchema,
40139
40435
  label: string(),
40436
+ /** A generic icon name (`cloud`, `plug`, `cpu`) — never a glyph or a logo. */
40140
40437
  icon: string(),
40141
40438
  /** Stamped by each provider so the concat-fanned catalog stays routable. */
40142
40439
  addonId: string(),
40143
- configSchema: ConfigSchemaPassthrough$3
40440
+ /** The provider's own fields (`providerConfig`); `password` fields are keychain-held. */
40441
+ connectionSchema: ConfigSchemaPassthrough$3,
40442
+ /** Provider fields that belong under "Advanced" (extra headers, runtime tuning). */
40443
+ advancedSchema: ConfigSchemaPassthrough$3.optional(),
40444
+ /** The kind's defaults; a model from `listModels` may override any of them. */
40445
+ features: LlmModelFeaturesSchema,
40446
+ /** `false` = the provider stamps `supportsVision` itself (from what a node reports). */
40447
+ visionEditable: boolean(),
40448
+ /** Where the model list comes from: `listModels`, `staticModels`, or nowhere. */
40449
+ modelCatalog: _enum([
40450
+ "fetch",
40451
+ "static",
40452
+ "none"
40453
+ ]),
40454
+ staticModels: array(LlmModelInfoSchema).optional(),
40455
+ /** The common fields that mean something on this kind's wire. */
40456
+ profileFields: array(LlmProfileFieldSchema),
40457
+ providerWidgets: array(LlmProviderWidgetSchema).optional()
40458
+ });
40459
+ /**
40460
+ * `listModels` input. `connection` is an UNSAVED draft of `providerConfig`
40461
+ * (the editor's form); with `profileId` too, a secret the draft leaves
40462
+ * untouched (absent or the redaction marker) is resolved server-side from the
40463
+ * stored profile — the browser never receives it.
40464
+ */
40465
+ var LlmListModelsInputSchema = object({
40466
+ addonId: string(),
40467
+ kind: LlmProfileKindSchema,
40468
+ profileId: string().optional(),
40469
+ connection: LlmProviderConfigSchema.optional()
40144
40470
  });
40471
+ var LlmListModelsErrorCodeSchema = _enum([
40472
+ "auth",
40473
+ "network",
40474
+ "unsupported",
40475
+ "invalid"
40476
+ ]);
40477
+ /** A RESULT, never a throw: "wrong key" is an answer the editor renders inline. */
40478
+ var LlmListModelsResultSchema = discriminatedUnion("ok", [object({
40479
+ ok: literal(true),
40480
+ models: array(LlmModelInfoSchema)
40481
+ }), object({
40482
+ ok: literal(false),
40483
+ code: LlmListModelsErrorCodeSchema,
40484
+ message: string()
40485
+ })]);
40145
40486
  var LlmDefaultSelectorSchema = union([object({ consumer: string() }), object({ purpose: _enum(["text", "vision"]) })]);
40146
40487
  var LlmDefaultSchema = object({
40147
40488
  selector: LlmDefaultSelectorSchema,
@@ -40241,7 +40582,10 @@ method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, {
40241
40582
  kind: "mutation",
40242
40583
  auth: "admin",
40243
40584
  timeoutMs: AI_CAP_TRANSPORT_TIMEOUT_MS
40244
- }), method(ProfileRefInputSchema, array(string())), method(object({}), array(LlmDefaultSchema)), method(object({
40585
+ }), method(LlmListModelsInputSchema, LlmListModelsResultSchema, {
40586
+ kind: "mutation",
40587
+ auth: "admin"
40588
+ }), method(object({}), array(LlmDefaultSchema)), method(object({
40245
40589
  selector: LlmDefaultSelectorSchema,
40246
40590
  profileId: string().nullable()
40247
40591
  }), _void(), {
@@ -44313,202 +44657,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
44313
44657
  auth: "admin"
44314
44658
  }), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
44315
44659
  /**
44316
- * Zod schemas for persisted record types.
44317
- *
44318
- * These schemas serve as the single source of truth for types that are
44319
- * stored in the settings-store backend and retrieved via tRPC. They
44320
- * replace the manual TypeScript interfaces with schema-derived types,
44321
- * enabling runtime validation when reading from the backend.
44322
- *
44323
- * Convention: each schema is named `<Type>Schema`, the inferred TS type
44324
- * keeps the original name for backward compatibility.
44325
- */
44326
- /**
44327
- * Auth model (v2 — 2026-05-12 caps-only):
44328
- *
44329
- * Two principals:
44330
- * - `isAdmin: true` — full bypass. Admin scope set is ignored.
44331
- * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
44332
- *
44333
- * No role enum. There used to be `viewer / agent / scoped` and earlier
44334
- * `super_admin` — collapsed onto the single boolean because every
44335
- * non-admin caller is governed by the same scope-check rules; the
44336
- * distinction was only ever used to route role-specific procedures
44337
- * which we no longer have. CLI / webhook integrations are `cst_*` tokens
44338
- * with `isAdmin: false` + an explicit scope list.
44339
- */
44340
- /** Per-method access flavour. Materialised on every cap method via codegen. */
44341
- var MethodAccessSchema = _enum([
44342
- "view",
44343
- "create",
44344
- "delete"
44345
- ]);
44346
- /**
44347
- * A single scope grant. Three forms — checked in matcher with OR
44348
- * semantics; the first match decides whether the call passes:
44349
- *
44350
- * - `category` — broadest. `target: 'device' | 'system'` selects every
44351
- * cap with the matching `scope` declaration. New caps inherit grants
44352
- * automatically — adding a device cap to the codebase makes it
44353
- * reachable to every user with `category:device [...]` without a
44354
- * re-grant. Use this for "family viewer" / "operator" tiers.
44355
- *
44356
- * - `addon` — every cap that ships inside a given addon id. Niche;
44357
- * useful when an integration needs to interact with one specific
44358
- * addon's surface regardless of how many caps it exports.
44359
- *
44360
- * - `capability` — the most precise form. Single cap name. Use for
44361
- * integration tokens where you want to grant `addons.installPackage`
44362
- * and nothing else.
44363
- *
44364
- * `access` is REQUIRED with min 1 element. `admin` bypass is the
44365
- * "give me everything" escape; there is no wildcard scope.
44366
- */
44367
- var AllowedProviderSchema = union([literal("*"), array(string())]);
44368
- var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
44369
- var CapScopeSchema = _enum(["device", "system"]);
44370
- /**
44371
- * DeviceSelector (scope model v3 — 2026-08-12).
44372
- *
44373
- * A `device` grant no longer carries a frozen list of deviceIds. It carries
44374
- * a SELECTOR the matcher resolves against the live fleet, so the grant can be
44375
- * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
44376
- * AFTER the grant was minted — no re-grant, no re-login.
44377
- *
44378
- * - `all` — every device in the deployment. The broad viewer/operator
44379
- * lever without a `category` grant (a `category` grant also covers device
44380
- * caps that carry no deviceId; `all` is specifically the device set).
44381
- * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
44382
- * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
44383
- * is NOT covered until the grant is edited.
44384
- * - `types` — every device of a `DeviceType` (e.g. every `camera`).
44385
- * DYNAMIC. A device that changes type, or a new device of the type,
44386
- * re-resolves on the next request.
44387
- * - `locations` — every device whose operator-assigned `location` label is
44388
- * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
44389
- * null/unset location matches NO `locations` selector.
44390
- */
44391
- var DeviceSelectorSchema = discriminatedUnion("kind", [
44392
- object({ kind: literal("all") }),
44393
- object({
44394
- kind: literal("ids"),
44395
- ids: array(number().int()).min(1)
44396
- }),
44397
- object({
44398
- kind: literal("types"),
44399
- types: array(_enum(DeviceType)).min(1)
44400
- }),
44401
- object({
44402
- kind: literal("locations"),
44403
- locations: array(string().min(1)).min(1)
44404
- })
44405
- ]);
44406
- var DeviceTokenScopeSchema = object({
44407
- type: literal("device"),
44408
- /** The device SET this grant covers — resolved against the live fleet. */
44409
- selector: DeviceSelectorSchema,
44410
- access: array(MethodAccessSchema).min(1),
44411
- /**
44412
- * Whether a grant on a PARENT device transparently covers its accessory
44413
- * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
44414
- * Direction is parent → children ONLY.
44415
- *
44416
- * Absent → the matcher DERIVES it from the access flavour: `view`
44417
- * inherits (a camera viewer sees the camera's accessories), `create` /
44418
- * `delete` do NOT (actuating/removing a child is an explicit act the
44419
- * operator must grant on the child, not inherit from the parent). Set it
44420
- * explicitly to override that default per grant.
44421
- */
44422
- includeLinked: boolean().optional()
44423
- });
44424
- /**
44425
- * v2 → v3 lazy migration. A pre-v3 `device` grant carried
44426
- * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
44427
- * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
44428
- * EVERY parse path — stored records AND the JWT-carried scope arrays
44429
- * normalised at the request boundary ({@link normalizeTokenScopes} in
44430
- * `device-selector.ts`). Chosen over a one-time DB migration because a
44431
- * migration cannot reach a JWT already in a client's hands; parse-time
44432
- * migration covers both without a flag day. No cast — the raw object is read
44433
- * through `Reflect.get` (its static type is `unknown`).
44434
- */
44435
- function migrateLegacyTokenScope(raw) {
44436
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
44437
- if (Reflect.get(raw, "type") !== "device") return raw;
44438
- if (Reflect.get(raw, "selector") !== void 0) return raw;
44439
- const targets = Reflect.get(raw, "targets");
44440
- if (!Array.isArray(targets)) return raw;
44441
- return {
44442
- type: "device",
44443
- selector: {
44444
- kind: "ids",
44445
- ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
44446
- },
44447
- access: Reflect.get(raw, "access")
44448
- };
44449
- }
44450
- var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
44451
- object({
44452
- type: literal("category"),
44453
- target: CapScopeSchema,
44454
- access: array(MethodAccessSchema).min(1)
44455
- }),
44456
- object({
44457
- type: literal("capability"),
44458
- target: string(),
44459
- access: array(MethodAccessSchema).min(1)
44460
- }),
44461
- object({
44462
- type: literal("addon"),
44463
- target: string(),
44464
- access: array(MethodAccessSchema).min(1)
44465
- }),
44466
- DeviceTokenScopeSchema
44467
- ]));
44468
- object({
44469
- id: string(),
44470
- username: string(),
44471
- passwordHash: string(),
44472
- /**
44473
- * Admin bypass. When true, the middleware skips the scope-access
44474
- * check entirely. There is no other axis of privilege; the legacy
44475
- * role enum collapsed onto this boolean in v2.
44476
- */
44477
- isAdmin: boolean().default(false),
44478
- allowedProviders: AllowedProviderSchema,
44479
- allowedDevices: AllowedDevicesSchema,
44480
- /**
44481
- * Scopes granted to this user. Admins bypass; their `scopes` is
44482
- * ignored. Non-admins without scopes are locked out of every
44483
- * protected call.
44484
- */
44485
- scopes: array(TokenScopeSchema).default([]),
44486
- createdAt: number(),
44487
- updatedAt: number()
44488
- });
44489
- object({
44490
- id: string(),
44491
- label: string(),
44492
- isAdmin: boolean().default(false),
44493
- allowedProviders: AllowedProviderSchema,
44494
- allowedDevices: AllowedDevicesSchema,
44495
- tokenHash: string(),
44496
- tokenPrefix: string(),
44497
- createdAt: number(),
44498
- lastUsedAt: number().optional()
44499
- });
44500
- object({
44501
- id: string(),
44502
- userId: string(),
44503
- name: string(),
44504
- tokenHash: string(),
44505
- tokenPrefix: string(),
44506
- scopes: array(TokenScopeSchema),
44507
- expiresAt: number().nullish(),
44508
- lastUsedAt: number().nullish(),
44509
- createdAt: number()
44510
- });
44511
- /**
44512
44660
  * `oauth-integration` — a collection cap by which an addon declares
44513
44661
  * itself a linkable OAuth client of the hub's core `/oauth2/*` server.
44514
44662
  * Each provider returns a static descriptor; the core enumerates them
@@ -61491,26 +61639,6 @@ var ApiKeySummarySchema = object({
61491
61639
  createdAt: number(),
61492
61640
  lastUsedAt: number().optional()
61493
61641
  });
61494
- var ScopedTokenSummarySchema = object({
61495
- id: string(),
61496
- userId: string(),
61497
- name: string(),
61498
- tokenPrefix: string(),
61499
- scopes: array(TokenScopeSchema),
61500
- expiresAt: number().nullish(),
61501
- lastUsedAt: number().nullish(),
61502
- createdAt: number()
61503
- });
61504
- var CreateScopedTokenInputSchema = object({
61505
- userId: string(),
61506
- name: string(),
61507
- scopes: array(TokenScopeSchema),
61508
- expiresAt: number().optional()
61509
- });
61510
- var CreateScopedTokenResultSchema = object({
61511
- token: string(),
61512
- record: ScopedTokenSummarySchema
61513
- });
61514
61642
  var OauthSessionSummarySchema = object({
61515
61643
  id: string(),
61516
61644
  userId: string(),
@@ -61532,11 +61660,11 @@ var TotpStatusSchema = object({
61532
61660
  confirmedAt: number().nullable()
61533
61661
  });
61534
61662
  /**
61535
- * user-management — singleton capability for user accounts, API keys,
61536
- * and scoped tokens.
61663
+ * user-management — singleton capability for user accounts and the
61664
+ * legacy API-key rows.
61537
61665
  *
61538
61666
  * v2 model: every method gated by `auth: 'admin'`. Admin-only delegation
61539
- * — the subset check on `setUserScopes` / `createScopedToken` is moot
61667
+ * — the subset check on `setUserScopes` is moot
61540
61668
  * because non-admins never reach these. If/when we open non-admin
61541
61669
  * delegation, structural caller-scope subset check goes inside the
61542
61670
  * provider.
@@ -61593,15 +61721,7 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
61593
61721
  kind: "mutation",
61594
61722
  auth: "admin",
61595
61723
  access: "delete"
61596
- }), method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
61597
- kind: "mutation",
61598
- auth: "admin",
61599
- access: "create"
61600
- }), method(object({ id: string() }), object({ success: literal(true) }), {
61601
- kind: "mutation",
61602
- auth: "admin",
61603
- access: "delete"
61604
- }), method(object({ token: string() }), ScopedTokenSummarySchema.nullable(), { access: "view" }), method(object({ userId: string() }), array(ScopedTokenSummarySchema), { auth: "admin" }), method(object({ userId: string() }), TotpSetupResultSchema, {
61724
+ }), method(object({ userId: string() }), TotpSetupResultSchema, {
61605
61725
  kind: "mutation",
61606
61726
  auth: "admin",
61607
61727
  access: "create"
@@ -65757,7 +65877,7 @@ Object.freeze({
65757
65877
  capName: "llm",
65758
65878
  capScope: "system",
65759
65879
  addonId: null,
65760
- access: "view"
65880
+ access: "create"
65761
65881
  },
65762
65882
  "llm.listNodeModels": {
65763
65883
  capName: "llm",
@@ -70421,12 +70541,6 @@ Object.freeze({
70421
70541
  addonId: null,
70422
70542
  access: "create"
70423
70543
  },
70424
- "userManagement.createScopedToken": {
70425
- capName: "user-management",
70426
- capScope: "system",
70427
- addonId: null,
70428
- access: "create"
70429
- },
70430
70544
  "userManagement.createUser": {
70431
70545
  capName: "user-management",
70432
70546
  capScope: "system",
@@ -70475,12 +70589,6 @@ Object.freeze({
70475
70589
  addonId: null,
70476
70590
  access: "view"
70477
70591
  },
70478
- "userManagement.listScopedTokens": {
70479
- capName: "user-management",
70480
- capScope: "system",
70481
- addonId: null,
70482
- access: "view"
70483
- },
70484
70592
  "userManagement.listUsers": {
70485
70593
  capName: "user-management",
70486
70594
  capScope: "system",
@@ -70535,12 +70643,6 @@ Object.freeze({
70535
70643
  addonId: null,
70536
70644
  access: "delete"
70537
70645
  },
70538
- "userManagement.revokeScopedToken": {
70539
- capName: "user-management",
70540
- capScope: "system",
70541
- addonId: null,
70542
- access: "delete"
70543
- },
70544
70646
  "userManagement.setupTotp": {
70545
70647
  capName: "user-management",
70546
70648
  capScope: "system",
@@ -70571,12 +70673,6 @@ Object.freeze({
70571
70673
  addonId: null,
70572
70674
  access: "view"
70573
70675
  },
70574
- "userManagement.validateScopedToken": {
70575
- capName: "user-management",
70576
- capScope: "system",
70577
- addonId: null,
70578
- access: "view"
70579
- },
70580
70676
  "userManagement.verifyTotp": {
70581
70677
  capName: "user-management",
70582
70678
  capScope: "system",