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