@camstack/addon-provider-tuya 0.2.128 → 0.2.130

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.
Files changed (3) hide show
  1. package/dist/addon.js +390 -294
  2. package/dist/addon.mjs +390 -294
  3. package/package.json +1 -1
package/dist/addon.mjs CHANGED
@@ -6233,7 +6233,7 @@ var ZodIssueCode = {
6233
6233
  var ZodFirstPartyTypeKind;
6234
6234
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6235
6235
  //#endregion
6236
- //#region ../types/dist/sleep-BxjU_fJM.mjs
6236
+ //#region ../types/dist/sleep-yKL5gfrH.mjs
6237
6237
  /**
6238
6238
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6239
6239
  * window to float samples (D455).
@@ -8615,6 +8615,12 @@ function normalizeAddonInitResult(result) {
8615
8615
  if (Array.isArray(result)) return { providers: result };
8616
8616
  return result;
8617
8617
  }
8618
+ /**
8619
+ * The share-view scope kinds a share-link token can carry. The hub mints
8620
+ * and validates them (`ShareViewGrantSchema` builds its
8621
+ * enum from this list); a data plane names the kinds it ACCEPTS in `share`.
8622
+ */
8623
+ var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
8618
8624
  /** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
8619
8625
  var PeerBytesTicketSchema = object({
8620
8626
  /** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
@@ -13280,6 +13286,280 @@ var ConvertResultSchema = object({
13280
13286
  files: array(string()).readonly()
13281
13287
  })).readonly()
13282
13288
  });
13289
+ /**
13290
+ * Zod schemas for persisted record types.
13291
+ *
13292
+ * These schemas serve as the single source of truth for types that are
13293
+ * stored in the settings-store backend and retrieved via tRPC. They
13294
+ * replace the manual TypeScript interfaces with schema-derived types,
13295
+ * enabling runtime validation when reading from the backend.
13296
+ *
13297
+ * Convention: each schema is named `<Type>Schema`, the inferred TS type
13298
+ * keeps the original name for backward compatibility.
13299
+ */
13300
+ /**
13301
+ * Auth model (v2 — 2026-05-12 caps-only):
13302
+ *
13303
+ * Two principals:
13304
+ * - `isAdmin: true` — full bypass. Admin scope set is ignored.
13305
+ * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
13306
+ *
13307
+ * No role enum. There used to be `viewer / agent / scoped` and earlier
13308
+ * `super_admin` — collapsed onto the single boolean because every
13309
+ * non-admin caller is governed by the same scope-check rules; the
13310
+ * distinction was only ever used to route role-specific procedures
13311
+ * which we no longer have. CLI / webhook integrations are tokens (`auth.mintToken`)
13312
+ * with `isAdmin: false` + an explicit scope list.
13313
+ */
13314
+ /** Per-method access flavour. Materialised on every cap method via codegen. */
13315
+ var MethodAccessSchema = _enum([
13316
+ "view",
13317
+ "create",
13318
+ "delete"
13319
+ ]);
13320
+ /**
13321
+ * A single scope grant. Three forms — checked in matcher with OR
13322
+ * semantics; the first match decides whether the call passes:
13323
+ *
13324
+ * - `category` — broadest. `target: 'device' | 'system'` selects every
13325
+ * cap with the matching `scope` declaration. New caps inherit grants
13326
+ * automatically — adding a device cap to the codebase makes it
13327
+ * reachable to every user with `category:device [...]` without a
13328
+ * re-grant. Use this for "family viewer" / "operator" tiers.
13329
+ *
13330
+ * - `addon` — every cap that ships inside a given addon id. Niche;
13331
+ * useful when an integration needs to interact with one specific
13332
+ * addon's surface regardless of how many caps it exports.
13333
+ *
13334
+ * - `capability` — the most precise form. Single cap name. Use for
13335
+ * integration tokens where you want to grant `addons.installPackage`
13336
+ * and nothing else.
13337
+ *
13338
+ * `access` is REQUIRED with min 1 element. `admin` bypass is the
13339
+ * "give me everything" escape; there is no wildcard scope.
13340
+ */
13341
+ var AllowedProviderSchema = union([literal("*"), array(string())]);
13342
+ var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
13343
+ var CapScopeSchema = _enum(["device", "system"]);
13344
+ /**
13345
+ * DeviceSelector (scope model v3 — 2026-08-12).
13346
+ *
13347
+ * A `device` grant no longer carries a frozen list of deviceIds. It carries
13348
+ * a SELECTOR the matcher resolves against the live fleet, so the grant can be
13349
+ * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
13350
+ * AFTER the grant was minted — no re-grant, no re-login.
13351
+ *
13352
+ * - `all` — every device in the deployment. The broad viewer/operator
13353
+ * lever without a `category` grant (a `category` grant also covers device
13354
+ * caps that carry no deviceId; `all` is specifically the device set).
13355
+ * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
13356
+ * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
13357
+ * is NOT covered until the grant is edited.
13358
+ * - `types` — every device of a `DeviceType` (e.g. every `camera`).
13359
+ * DYNAMIC. A device that changes type, or a new device of the type,
13360
+ * re-resolves on the next request.
13361
+ * - `locations` — every device whose operator-assigned `location` label is
13362
+ * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
13363
+ * null/unset location matches NO `locations` selector.
13364
+ */
13365
+ var DeviceSelectorSchema = discriminatedUnion("kind", [
13366
+ object({ kind: literal("all") }),
13367
+ object({
13368
+ kind: literal("ids"),
13369
+ ids: array(number().int()).min(1)
13370
+ }),
13371
+ object({
13372
+ kind: literal("types"),
13373
+ types: array(_enum(DeviceType)).min(1)
13374
+ }),
13375
+ object({
13376
+ kind: literal("locations"),
13377
+ locations: array(string().min(1)).min(1)
13378
+ })
13379
+ ]);
13380
+ var DeviceTokenScopeSchema = object({
13381
+ type: literal("device"),
13382
+ /** The device SET this grant covers — resolved against the live fleet. */
13383
+ selector: DeviceSelectorSchema,
13384
+ access: array(MethodAccessSchema).min(1),
13385
+ /**
13386
+ * Whether a grant on a PARENT device transparently covers its accessory
13387
+ * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
13388
+ * Direction is parent → children ONLY.
13389
+ *
13390
+ * Absent → the matcher DERIVES it from the access flavour: `view`
13391
+ * inherits (a camera viewer sees the camera's accessories), `create` /
13392
+ * `delete` do NOT (actuating/removing a child is an explicit act the
13393
+ * operator must grant on the child, not inherit from the parent). Set it
13394
+ * explicitly to override that default per grant.
13395
+ */
13396
+ includeLinked: boolean().optional()
13397
+ });
13398
+ /**
13399
+ * v2 → v3 lazy migration. A pre-v3 `device` grant carried
13400
+ * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
13401
+ * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
13402
+ * EVERY parse path — stored records AND the JWT-carried scope arrays
13403
+ * normalised at the request boundary ({@link normalizeTokenScopes} in
13404
+ * `device-selector.ts`). Chosen over a one-time DB migration because a
13405
+ * migration cannot reach a JWT already in a client's hands; parse-time
13406
+ * migration covers both without a flag day. No cast — the raw object is read
13407
+ * through `Reflect.get` (its static type is `unknown`).
13408
+ */
13409
+ function migrateLegacyTokenScope(raw) {
13410
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
13411
+ if (Reflect.get(raw, "type") !== "device") return raw;
13412
+ if (Reflect.get(raw, "selector") !== void 0) return raw;
13413
+ const targets = Reflect.get(raw, "targets");
13414
+ if (!Array.isArray(targets)) return raw;
13415
+ return {
13416
+ type: "device",
13417
+ selector: {
13418
+ kind: "ids",
13419
+ ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
13420
+ },
13421
+ access: Reflect.get(raw, "access")
13422
+ };
13423
+ }
13424
+ var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
13425
+ object({
13426
+ type: literal("category"),
13427
+ target: CapScopeSchema,
13428
+ access: array(MethodAccessSchema).min(1)
13429
+ }),
13430
+ object({
13431
+ type: literal("capability"),
13432
+ target: string(),
13433
+ access: array(MethodAccessSchema).min(1)
13434
+ }),
13435
+ object({
13436
+ type: literal("addon"),
13437
+ target: string(),
13438
+ access: array(MethodAccessSchema).min(1)
13439
+ }),
13440
+ DeviceTokenScopeSchema
13441
+ ]));
13442
+ object({
13443
+ id: string(),
13444
+ username: string(),
13445
+ passwordHash: string(),
13446
+ /**
13447
+ * Admin bypass. When true, the middleware skips the scope-access
13448
+ * check entirely. There is no other axis of privilege; the legacy
13449
+ * role enum collapsed onto this boolean in v2.
13450
+ */
13451
+ isAdmin: boolean().default(false),
13452
+ allowedProviders: AllowedProviderSchema,
13453
+ allowedDevices: AllowedDevicesSchema,
13454
+ /**
13455
+ * Scopes granted to this user. Admins bypass; their `scopes` is
13456
+ * ignored. Non-admins without scopes are locked out of every
13457
+ * protected call.
13458
+ */
13459
+ scopes: array(TokenScopeSchema).default([]),
13460
+ createdAt: number(),
13461
+ updatedAt: number()
13462
+ });
13463
+ object({
13464
+ id: string(),
13465
+ label: string(),
13466
+ isAdmin: boolean().default(false),
13467
+ allowedProviders: AllowedProviderSchema,
13468
+ allowedDevices: AllowedDevicesSchema,
13469
+ tokenHash: string(),
13470
+ tokenPrefix: string(),
13471
+ createdAt: number(),
13472
+ lastUsedAt: number().optional()
13473
+ });
13474
+ object({
13475
+ id: string(),
13476
+ userId: string(),
13477
+ name: string(),
13478
+ tokenHash: string(),
13479
+ tokenPrefix: string(),
13480
+ scopes: array(TokenScopeSchema),
13481
+ expiresAt: number().nullish(),
13482
+ lastUsedAt: number().nullish(),
13483
+ createdAt: number()
13484
+ });
13485
+ /** What a share-view grant lets its holder see. */
13486
+ var ShareViewGrantSchema = object({
13487
+ kind: _enum(SHARE_VIEW_KINDS),
13488
+ deviceIds: array(number().int().nonnegative()).min(1).max(64),
13489
+ /** Talk-back, opt-in at mint time; absent means off. */
13490
+ talk: boolean().optional()
13491
+ });
13492
+ var ShareViewScopeSchema = object({
13493
+ type: literal("share-view"),
13494
+ grant: ShareViewGrantSchema
13495
+ });
13496
+ var AddonRoutesScopeSchema = object({
13497
+ type: literal("addon-routes"),
13498
+ access: array(MethodAccessSchema).min(1)
13499
+ });
13500
+ var PreferencesSelfScopeSchema = object({ type: literal("preferences-self") });
13501
+ var CredentialScopeSchema = union([
13502
+ literal("*"),
13503
+ ShareViewScopeSchema,
13504
+ AddonRoutesScopeSchema,
13505
+ PreferencesSelfScopeSchema,
13506
+ TokenScopeSchema
13507
+ ]);
13508
+ object({
13509
+ kind: literal("credential"),
13510
+ sub: string().min(1),
13511
+ jti: string().min(16),
13512
+ scopes: array(CredentialScopeSchema).min(1)
13513
+ });
13514
+ var PreferenceNamespaceSchema = string().regex(/^[a-z][a-z0-9.-]{0,63}$/);
13515
+ /** A namespace's value: a JSON object, opaque to the hub. */
13516
+ var PreferenceValueSchema = record(string(), unknown());
13517
+ var PreferenceDeviceIdSchema = string().min(1).max(64);
13518
+ /** A stored row, as the owner reads it. */
13519
+ var PreferenceRowSchema = object({
13520
+ namespace: PreferenceNamespaceSchema,
13521
+ value: PreferenceValueSchema,
13522
+ /** Starts at 1, +1 on every write of this namespace. A delete ends the row and its count. */
13523
+ revision: number().int().positive(),
13524
+ updatedAt: number().int(),
13525
+ /** The client id the last writer sent; `null` when it sent none. */
13526
+ updatedByDevice: PreferenceDeviceIdSchema.nullable()
13527
+ });
13528
+ object({
13529
+ /** Absent: every namespace the caller holds. */
13530
+ namespaces: array(PreferenceNamespaceSchema).max(32).optional() });
13531
+ object({ rows: array(PreferenceRowSchema) });
13532
+ object({
13533
+ namespace: PreferenceNamespaceSchema,
13534
+ value: PreferenceValueSchema,
13535
+ /**
13536
+ * The revision the edit was based on. Absent: last write wins. `0`: the
13537
+ * namespace must not exist yet. Any other value that is not the current
13538
+ * revision answers `conflict` and writes nothing.
13539
+ */
13540
+ baseRevision: number().int().nonnegative().optional(),
13541
+ deviceId: PreferenceDeviceIdSchema.optional()
13542
+ });
13543
+ discriminatedUnion("status", [object({
13544
+ status: literal("saved"),
13545
+ row: PreferenceRowSchema
13546
+ }), object({
13547
+ status: literal("conflict"),
13548
+ current: PreferenceRowSchema.nullable()
13549
+ })]);
13550
+ object({ namespace: PreferenceNamespaceSchema });
13551
+ object({
13552
+ /** `false` when the namespace did not exist. */
13553
+ deleted: boolean() });
13554
+ object({
13555
+ /** The revision the client holds per namespace; a namespace it does not list is new to it. */
13556
+ revisionByNamespace: record(PreferenceNamespaceSchema, number().int().nonnegative()).refine((map) => Object.keys(map).length <= 32, { message: `at most 32 namespaces` }) });
13557
+ object({
13558
+ /** Every row whose revision differs from the client's, and every row it did not list. */
13559
+ rows: array(PreferenceRowSchema),
13560
+ /** Namespaces the client listed that no longer exist. */
13561
+ deleted: array(PreferenceNamespaceSchema)
13562
+ });
13283
13563
  _enum(["new-session", "step-up"]);
13284
13564
  /** The languages the hub's app landing pages are written in (D858). */
13285
13565
  var AppPageLangSchema = _enum(["en", "it"]);
@@ -40473,38 +40753,37 @@ method(LlmRuntimeCompleteInputSchema, LlmGenerateResultSchema, {
40473
40753
  auth: "admin",
40474
40754
  timeoutMs: AI_CAP_TRANSPORT_TIMEOUT_MS
40475
40755
  });
40756
+ var LlmProfileKindSchema = string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/, "a kind id is lower-case letters, digits and dashes");
40757
+ /** What a model (or, by default, every model of a kind) can do. */
40758
+ var LlmModelFeaturesSchema = object({
40759
+ vision: boolean(),
40760
+ tools: boolean(),
40761
+ streaming: boolean()
40762
+ });
40763
+ /** One model a provider offers. `features` overrides the kind's defaults, per field. */
40764
+ var LlmModelInfoSchema = object({
40765
+ id: string(),
40766
+ label: string().optional(),
40767
+ contextLength: number().int().positive().optional(),
40768
+ features: LlmModelFeaturesSchema.partial().optional()
40769
+ });
40476
40770
  /**
40477
- * `llm` — consumer-facing LLM surface (spec §1-§3). Collection-mode: array
40478
- * methods concat-fan across providers; single-row methods route to ONE
40479
- * provider by the `addonId` in the call input (the notification-output
40480
- * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
40481
- * (hub-placed); the cap stays open for future providers.
40482
- *
40483
- * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
40484
- * `apiKey` is a password field — providers REDACT it on read and merge on
40485
- * write; a stored key NEVER round-trips to a client.
40771
+ * The provider-specific part of a profile, validated by the provider that owns
40772
+ * the kind (`upsertProfile` refuses what it does not accept). A field its
40773
+ * `connectionSchema` declares `type: 'password'` is a secret: it is held in the
40774
+ * keychain, never in the row, and reads back as the redaction marker.
40486
40775
  */
40487
- var LlmProfileKindSchema = _enum([
40488
- "openai-compatible",
40489
- "openai",
40490
- "anthropic",
40491
- "google",
40492
- "managed-local",
40493
- "apple-foundation"
40494
- ]);
40776
+ var LlmProviderConfigSchema = record(string(), unknown());
40495
40777
  var LlmProfileSchema = object({
40496
40778
  id: string(),
40497
40779
  name: string(),
40780
+ /** The provider-declared kind (`LlmProfileKindDescriptor.kind`). */
40498
40781
  kind: LlmProfileKindSchema,
40499
40782
  /** Stamped by the provider — keeps the fanned catalog routable. */
40500
40783
  addonId: string(),
40501
40784
  enabled: boolean(),
40502
40785
  /** Vendor model id, or the managed runtime's loaded model. */
40503
40786
  model: string(),
40504
- /** Required for openai-compatible; override for cloud kinds. */
40505
- baseUrl: string().optional(),
40506
- /** ConfigUISchema type:'password' — never round-trips (spec §5). */
40507
- apiKey: string().optional(),
40508
40787
  /** Vision on/off. A vision call against a `false` profile is REFUSED, never
40509
40788
  * degraded to text — that shipped once and produced a confident answer to a
40510
40789
  * question about a picture nobody sent. */
@@ -40512,15 +40791,11 @@ var LlmProfileSchema = object({
40512
40791
  temperature: number().min(0).max(2).optional(),
40513
40792
  /** Nucleus sampling. Every wire we speak has it. */
40514
40793
  topP: number().min(0).max(1).optional(),
40515
- /** Top-k sampling. Carried only by the wires that have it — NEITHER OpenAI
40516
- * wire does, and the client drops it there (measured: the request body gets
40517
- * `top_p` and no `top_k`). The profile editor hides the field wherever it
40518
- * would change nothing; `KINDS_WITH_TOP_K` is the single owner of that list. */
40794
+ /** Top-k sampling. Carried only by the wires that have it — a kind offers the
40795
+ * field in its editor only when its descriptor lists it in `profileFields`. */
40519
40796
  topK: number().int().positive().optional(),
40520
40797
  maxTokens: number().int().positive().optional(),
40521
- /** Prompt context window. Advisory for cloud kinds (they enforce their own);
40522
- * for `managed-local` it is the llama.cpp `--ctx-size` the runtime starts
40523
- * the model with, so it is the one field that changes a PROCESS. */
40798
+ /** Prompt context window. Advisory for cloud kinds (they enforce their own). */
40524
40799
  contextLength: number().int().positive().optional(),
40525
40800
  /** Default system prompt. A caller's `system` REPLACES it (never appends —
40526
40801
  * two system prompts fighting is worse than either alone). */
@@ -40546,16 +40821,37 @@ var LlmProfileSchema = object({
40546
40821
  * library; the REGISTRY of callable tools is ours and is empty in v1, so a
40547
40822
  * `true` here buys the wiring, not behaviour, until tools are registered. */
40548
40823
  toolsEnabled: boolean().default(false),
40549
- extraHeaders: record(string(), string()).optional(),
40550
- /** kind === 'managed-local' only (spec §4). */
40551
- runtime: ManagedRuntimeConfigSchema.optional(),
40552
- /**
40553
- * kind === 'apple-foundation' only: WHERE it runs — the only thing there is
40554
- * to configure (no key, no URL, no download; `model` is `apple-system`).
40555
- * `supportsVision` on such a row is stamped by the provider from the node's
40556
- * reported `imageInput`, never taken from the operator (D62).
40557
- */
40558
- appleFoundation: object({ nodeId: string() }).optional()
40824
+ /** Everything the kind's provider owns (endpoint, key, node, runtime…). */
40825
+ providerConfig: LlmProviderConfigSchema.default({})
40826
+ });
40827
+ /**
40828
+ * The common profile fields a kind's editor offers. The editor owns how each
40829
+ * one is drawn; the provider says which of them mean something on its wire.
40830
+ */
40831
+ var LlmProfileFieldSchema = _enum([
40832
+ "temperature",
40833
+ "topP",
40834
+ "topK",
40835
+ "maxTokens",
40836
+ "contextLength",
40837
+ "systemPrompt",
40838
+ "timeoutMs",
40839
+ "connectTimeoutMs",
40840
+ "firstTokenTimeoutMs",
40841
+ "idleTimeoutMs",
40842
+ "retry",
40843
+ "toolsEnabled"
40844
+ ]);
40845
+ /**
40846
+ * A provider-drawn part of the editor, by a generic widget id the admin UI
40847
+ * registers (`ai/apple-node`). `placement: 'model'` replaces the generic model
40848
+ * picker: that widget owns the model choice.
40849
+ */
40850
+ var LlmProviderWidgetSchema = object({
40851
+ id: string(),
40852
+ placement: _enum(["connection", "model"]),
40853
+ /** `providerConfig` keys this widget must fill before the profile can be saved. */
40854
+ requires: array(string()).optional()
40559
40855
  });
40560
40856
  /** ConfigUISchema tree passed through untyped on the wire (the
40561
40857
  * notification-output `ConfigSchemaPassthrough` precedent at
@@ -40564,11 +40860,56 @@ var ConfigSchemaPassthrough$3 = unknown();
40564
40860
  var LlmProfileKindDescriptorSchema = object({
40565
40861
  kind: LlmProfileKindSchema,
40566
40862
  label: string(),
40863
+ /** A generic icon name (`cloud`, `plug`, `cpu`) — never a glyph or a logo. */
40567
40864
  icon: string(),
40568
40865
  /** Stamped by each provider so the concat-fanned catalog stays routable. */
40569
40866
  addonId: string(),
40570
- configSchema: ConfigSchemaPassthrough$3
40867
+ /** The provider's own fields (`providerConfig`); `password` fields are keychain-held. */
40868
+ connectionSchema: ConfigSchemaPassthrough$3,
40869
+ /** Provider fields that belong under "Advanced" (extra headers, runtime tuning). */
40870
+ advancedSchema: ConfigSchemaPassthrough$3.optional(),
40871
+ /** The kind's defaults; a model from `listModels` may override any of them. */
40872
+ features: LlmModelFeaturesSchema,
40873
+ /** `false` = the provider stamps `supportsVision` itself (from what a node reports). */
40874
+ visionEditable: boolean(),
40875
+ /** Where the model list comes from: `listModels`, `staticModels`, or nowhere. */
40876
+ modelCatalog: _enum([
40877
+ "fetch",
40878
+ "static",
40879
+ "none"
40880
+ ]),
40881
+ staticModels: array(LlmModelInfoSchema).optional(),
40882
+ /** The common fields that mean something on this kind's wire. */
40883
+ profileFields: array(LlmProfileFieldSchema),
40884
+ providerWidgets: array(LlmProviderWidgetSchema).optional()
40885
+ });
40886
+ /**
40887
+ * `listModels` input. `connection` is an UNSAVED draft of `providerConfig`
40888
+ * (the editor's form); with `profileId` too, a secret the draft leaves
40889
+ * untouched (absent or the redaction marker) is resolved server-side from the
40890
+ * stored profile — the browser never receives it.
40891
+ */
40892
+ var LlmListModelsInputSchema = object({
40893
+ addonId: string(),
40894
+ kind: LlmProfileKindSchema,
40895
+ profileId: string().optional(),
40896
+ connection: LlmProviderConfigSchema.optional()
40571
40897
  });
40898
+ var LlmListModelsErrorCodeSchema = _enum([
40899
+ "auth",
40900
+ "network",
40901
+ "unsupported",
40902
+ "invalid"
40903
+ ]);
40904
+ /** A RESULT, never a throw: "wrong key" is an answer the editor renders inline. */
40905
+ var LlmListModelsResultSchema = discriminatedUnion("ok", [object({
40906
+ ok: literal(true),
40907
+ models: array(LlmModelInfoSchema)
40908
+ }), object({
40909
+ ok: literal(false),
40910
+ code: LlmListModelsErrorCodeSchema,
40911
+ message: string()
40912
+ })]);
40572
40913
  var LlmDefaultSelectorSchema = union([object({ consumer: string() }), object({ purpose: _enum(["text", "vision"]) })]);
40573
40914
  var LlmDefaultSchema = object({
40574
40915
  selector: LlmDefaultSelectorSchema,
@@ -40668,7 +41009,10 @@ method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, {
40668
41009
  kind: "mutation",
40669
41010
  auth: "admin",
40670
41011
  timeoutMs: AI_CAP_TRANSPORT_TIMEOUT_MS
40671
- }), method(ProfileRefInputSchema, array(string())), method(object({}), array(LlmDefaultSchema)), method(object({
41012
+ }), method(LlmListModelsInputSchema, LlmListModelsResultSchema, {
41013
+ kind: "mutation",
41014
+ auth: "admin"
41015
+ }), method(object({}), array(LlmDefaultSchema)), method(object({
40672
41016
  selector: LlmDefaultSelectorSchema,
40673
41017
  profileId: string().nullable()
40674
41018
  }), _void(), {
@@ -44774,202 +45118,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
44774
45118
  auth: "admin"
44775
45119
  }), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
44776
45120
  /**
44777
- * Zod schemas for persisted record types.
44778
- *
44779
- * These schemas serve as the single source of truth for types that are
44780
- * stored in the settings-store backend and retrieved via tRPC. They
44781
- * replace the manual TypeScript interfaces with schema-derived types,
44782
- * enabling runtime validation when reading from the backend.
44783
- *
44784
- * Convention: each schema is named `<Type>Schema`, the inferred TS type
44785
- * keeps the original name for backward compatibility.
44786
- */
44787
- /**
44788
- * Auth model (v2 — 2026-05-12 caps-only):
44789
- *
44790
- * Two principals:
44791
- * - `isAdmin: true` — full bypass. Admin scope set is ignored.
44792
- * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
44793
- *
44794
- * No role enum. There used to be `viewer / agent / scoped` and earlier
44795
- * `super_admin` — collapsed onto the single boolean because every
44796
- * non-admin caller is governed by the same scope-check rules; the
44797
- * distinction was only ever used to route role-specific procedures
44798
- * which we no longer have. CLI / webhook integrations are `cst_*` tokens
44799
- * with `isAdmin: false` + an explicit scope list.
44800
- */
44801
- /** Per-method access flavour. Materialised on every cap method via codegen. */
44802
- var MethodAccessSchema = _enum([
44803
- "view",
44804
- "create",
44805
- "delete"
44806
- ]);
44807
- /**
44808
- * A single scope grant. Three forms — checked in matcher with OR
44809
- * semantics; the first match decides whether the call passes:
44810
- *
44811
- * - `category` — broadest. `target: 'device' | 'system'` selects every
44812
- * cap with the matching `scope` declaration. New caps inherit grants
44813
- * automatically — adding a device cap to the codebase makes it
44814
- * reachable to every user with `category:device [...]` without a
44815
- * re-grant. Use this for "family viewer" / "operator" tiers.
44816
- *
44817
- * - `addon` — every cap that ships inside a given addon id. Niche;
44818
- * useful when an integration needs to interact with one specific
44819
- * addon's surface regardless of how many caps it exports.
44820
- *
44821
- * - `capability` — the most precise form. Single cap name. Use for
44822
- * integration tokens where you want to grant `addons.installPackage`
44823
- * and nothing else.
44824
- *
44825
- * `access` is REQUIRED with min 1 element. `admin` bypass is the
44826
- * "give me everything" escape; there is no wildcard scope.
44827
- */
44828
- var AllowedProviderSchema = union([literal("*"), array(string())]);
44829
- var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
44830
- var CapScopeSchema = _enum(["device", "system"]);
44831
- /**
44832
- * DeviceSelector (scope model v3 — 2026-08-12).
44833
- *
44834
- * A `device` grant no longer carries a frozen list of deviceIds. It carries
44835
- * a SELECTOR the matcher resolves against the live fleet, so the grant can be
44836
- * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
44837
- * AFTER the grant was minted — no re-grant, no re-login.
44838
- *
44839
- * - `all` — every device in the deployment. The broad viewer/operator
44840
- * lever without a `category` grant (a `category` grant also covers device
44841
- * caps that carry no deviceId; `all` is specifically the device set).
44842
- * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
44843
- * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
44844
- * is NOT covered until the grant is edited.
44845
- * - `types` — every device of a `DeviceType` (e.g. every `camera`).
44846
- * DYNAMIC. A device that changes type, or a new device of the type,
44847
- * re-resolves on the next request.
44848
- * - `locations` — every device whose operator-assigned `location` label is
44849
- * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
44850
- * null/unset location matches NO `locations` selector.
44851
- */
44852
- var DeviceSelectorSchema = discriminatedUnion("kind", [
44853
- object({ kind: literal("all") }),
44854
- object({
44855
- kind: literal("ids"),
44856
- ids: array(number().int()).min(1)
44857
- }),
44858
- object({
44859
- kind: literal("types"),
44860
- types: array(_enum(DeviceType)).min(1)
44861
- }),
44862
- object({
44863
- kind: literal("locations"),
44864
- locations: array(string().min(1)).min(1)
44865
- })
44866
- ]);
44867
- var DeviceTokenScopeSchema = object({
44868
- type: literal("device"),
44869
- /** The device SET this grant covers — resolved against the live fleet. */
44870
- selector: DeviceSelectorSchema,
44871
- access: array(MethodAccessSchema).min(1),
44872
- /**
44873
- * Whether a grant on a PARENT device transparently covers its accessory
44874
- * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
44875
- * Direction is parent → children ONLY.
44876
- *
44877
- * Absent → the matcher DERIVES it from the access flavour: `view`
44878
- * inherits (a camera viewer sees the camera's accessories), `create` /
44879
- * `delete` do NOT (actuating/removing a child is an explicit act the
44880
- * operator must grant on the child, not inherit from the parent). Set it
44881
- * explicitly to override that default per grant.
44882
- */
44883
- includeLinked: boolean().optional()
44884
- });
44885
- /**
44886
- * v2 → v3 lazy migration. A pre-v3 `device` grant carried
44887
- * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
44888
- * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
44889
- * EVERY parse path — stored records AND the JWT-carried scope arrays
44890
- * normalised at the request boundary ({@link normalizeTokenScopes} in
44891
- * `device-selector.ts`). Chosen over a one-time DB migration because a
44892
- * migration cannot reach a JWT already in a client's hands; parse-time
44893
- * migration covers both without a flag day. No cast — the raw object is read
44894
- * through `Reflect.get` (its static type is `unknown`).
44895
- */
44896
- function migrateLegacyTokenScope(raw) {
44897
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
44898
- if (Reflect.get(raw, "type") !== "device") return raw;
44899
- if (Reflect.get(raw, "selector") !== void 0) return raw;
44900
- const targets = Reflect.get(raw, "targets");
44901
- if (!Array.isArray(targets)) return raw;
44902
- return {
44903
- type: "device",
44904
- selector: {
44905
- kind: "ids",
44906
- ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
44907
- },
44908
- access: Reflect.get(raw, "access")
44909
- };
44910
- }
44911
- var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
44912
- object({
44913
- type: literal("category"),
44914
- target: CapScopeSchema,
44915
- access: array(MethodAccessSchema).min(1)
44916
- }),
44917
- object({
44918
- type: literal("capability"),
44919
- target: string(),
44920
- access: array(MethodAccessSchema).min(1)
44921
- }),
44922
- object({
44923
- type: literal("addon"),
44924
- target: string(),
44925
- access: array(MethodAccessSchema).min(1)
44926
- }),
44927
- DeviceTokenScopeSchema
44928
- ]));
44929
- object({
44930
- id: string(),
44931
- username: string(),
44932
- passwordHash: string(),
44933
- /**
44934
- * Admin bypass. When true, the middleware skips the scope-access
44935
- * check entirely. There is no other axis of privilege; the legacy
44936
- * role enum collapsed onto this boolean in v2.
44937
- */
44938
- isAdmin: boolean().default(false),
44939
- allowedProviders: AllowedProviderSchema,
44940
- allowedDevices: AllowedDevicesSchema,
44941
- /**
44942
- * Scopes granted to this user. Admins bypass; their `scopes` is
44943
- * ignored. Non-admins without scopes are locked out of every
44944
- * protected call.
44945
- */
44946
- scopes: array(TokenScopeSchema).default([]),
44947
- createdAt: number(),
44948
- updatedAt: number()
44949
- });
44950
- object({
44951
- id: string(),
44952
- label: string(),
44953
- isAdmin: boolean().default(false),
44954
- allowedProviders: AllowedProviderSchema,
44955
- allowedDevices: AllowedDevicesSchema,
44956
- tokenHash: string(),
44957
- tokenPrefix: string(),
44958
- createdAt: number(),
44959
- lastUsedAt: number().optional()
44960
- });
44961
- object({
44962
- id: string(),
44963
- userId: string(),
44964
- name: string(),
44965
- tokenHash: string(),
44966
- tokenPrefix: string(),
44967
- scopes: array(TokenScopeSchema),
44968
- expiresAt: number().nullish(),
44969
- lastUsedAt: number().nullish(),
44970
- createdAt: number()
44971
- });
44972
- /**
44973
45121
  * `oauth-integration` — a collection cap by which an addon declares
44974
45122
  * itself a linkable OAuth client of the hub's core `/oauth2/*` server.
44975
45123
  * Each provider returns a static descriptor; the core enumerates them
@@ -64760,26 +64908,6 @@ var ApiKeySummarySchema = object({
64760
64908
  createdAt: number(),
64761
64909
  lastUsedAt: number().optional()
64762
64910
  });
64763
- var ScopedTokenSummarySchema = object({
64764
- id: string(),
64765
- userId: string(),
64766
- name: string(),
64767
- tokenPrefix: string(),
64768
- scopes: array(TokenScopeSchema),
64769
- expiresAt: number().nullish(),
64770
- lastUsedAt: number().nullish(),
64771
- createdAt: number()
64772
- });
64773
- var CreateScopedTokenInputSchema = object({
64774
- userId: string(),
64775
- name: string(),
64776
- scopes: array(TokenScopeSchema),
64777
- expiresAt: number().optional()
64778
- });
64779
- var CreateScopedTokenResultSchema = object({
64780
- token: string(),
64781
- record: ScopedTokenSummarySchema
64782
- });
64783
64911
  var OauthSessionSummarySchema = object({
64784
64912
  id: string(),
64785
64913
  userId: string(),
@@ -64801,11 +64929,11 @@ var TotpStatusSchema = object({
64801
64929
  confirmedAt: number().nullable()
64802
64930
  });
64803
64931
  /**
64804
- * user-management — singleton capability for user accounts, API keys,
64805
- * and scoped tokens.
64932
+ * user-management — singleton capability for user accounts and the
64933
+ * legacy API-key rows.
64806
64934
  *
64807
64935
  * v2 model: every method gated by `auth: 'admin'`. Admin-only delegation
64808
- * — the subset check on `setUserScopes` / `createScopedToken` is moot
64936
+ * — the subset check on `setUserScopes` is moot
64809
64937
  * because non-admins never reach these. If/when we open non-admin
64810
64938
  * delegation, structural caller-scope subset check goes inside the
64811
64939
  * provider.
@@ -64862,15 +64990,7 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
64862
64990
  kind: "mutation",
64863
64991
  auth: "admin",
64864
64992
  access: "delete"
64865
- }), method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
64866
- kind: "mutation",
64867
- auth: "admin",
64868
- access: "create"
64869
- }), method(object({ id: string() }), object({ success: literal(true) }), {
64870
- kind: "mutation",
64871
- auth: "admin",
64872
- access: "delete"
64873
- }), method(object({ token: string() }), ScopedTokenSummarySchema.nullable(), { access: "view" }), method(object({ userId: string() }), array(ScopedTokenSummarySchema), { auth: "admin" }), method(object({ userId: string() }), TotpSetupResultSchema, {
64993
+ }), method(object({ userId: string() }), TotpSetupResultSchema, {
64874
64994
  kind: "mutation",
64875
64995
  auth: "admin",
64876
64996
  access: "create"
@@ -70960,7 +71080,7 @@ Object.freeze({
70960
71080
  capName: "llm",
70961
71081
  capScope: "system",
70962
71082
  addonId: null,
70963
- access: "view"
71083
+ access: "create"
70964
71084
  },
70965
71085
  "llm.listNodeModels": {
70966
71086
  capName: "llm",
@@ -75624,12 +75744,6 @@ Object.freeze({
75624
75744
  addonId: null,
75625
75745
  access: "create"
75626
75746
  },
75627
- "userManagement.createScopedToken": {
75628
- capName: "user-management",
75629
- capScope: "system",
75630
- addonId: null,
75631
- access: "create"
75632
- },
75633
75747
  "userManagement.createUser": {
75634
75748
  capName: "user-management",
75635
75749
  capScope: "system",
@@ -75678,12 +75792,6 @@ Object.freeze({
75678
75792
  addonId: null,
75679
75793
  access: "view"
75680
75794
  },
75681
- "userManagement.listScopedTokens": {
75682
- capName: "user-management",
75683
- capScope: "system",
75684
- addonId: null,
75685
- access: "view"
75686
- },
75687
75795
  "userManagement.listUsers": {
75688
75796
  capName: "user-management",
75689
75797
  capScope: "system",
@@ -75738,12 +75846,6 @@ Object.freeze({
75738
75846
  addonId: null,
75739
75847
  access: "delete"
75740
75848
  },
75741
- "userManagement.revokeScopedToken": {
75742
- capName: "user-management",
75743
- capScope: "system",
75744
- addonId: null,
75745
- access: "delete"
75746
- },
75747
75849
  "userManagement.setupTotp": {
75748
75850
  capName: "user-management",
75749
75851
  capScope: "system",
@@ -75774,12 +75876,6 @@ Object.freeze({
75774
75876
  addonId: null,
75775
75877
  access: "view"
75776
75878
  },
75777
- "userManagement.validateScopedToken": {
75778
- capName: "user-management",
75779
- capScope: "system",
75780
- addonId: null,
75781
- access: "view"
75782
- },
75783
75879
  "userManagement.verifyTotp": {
75784
75880
  capName: "user-management",
75785
75881
  capScope: "system",