@camstack/addon-matter-broker 0.2.130 → 0.2.132

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
@@ -5559,7 +5559,7 @@ var ZodIssueCode = {
5559
5559
  var ZodFirstPartyTypeKind;
5560
5560
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5561
5561
  //#endregion
5562
- //#region ../types/dist/sleep-BxjU_fJM.mjs
5562
+ //#region ../types/dist/sleep-yKL5gfrH.mjs
5563
5563
  /**
5564
5564
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5565
5565
  * window to float samples (D455).
@@ -7941,6 +7941,12 @@ function normalizeAddonInitResult(result) {
7941
7941
  if (Array.isArray(result)) return { providers: result };
7942
7942
  return result;
7943
7943
  }
7944
+ /**
7945
+ * The share-view scope kinds a share-link token can carry. The hub mints
7946
+ * and validates them (`ShareViewGrantSchema` builds its
7947
+ * enum from this list); a data plane names the kinds it ACCEPTS in `share`.
7948
+ */
7949
+ var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
7944
7950
  /** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
7945
7951
  var PeerBytesTicketSchema = object({
7946
7952
  /** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
@@ -12806,6 +12812,280 @@ var ConvertResultSchema = object({
12806
12812
  files: array(string$2()).readonly()
12807
12813
  })).readonly()
12808
12814
  });
12815
+ /**
12816
+ * Zod schemas for persisted record types.
12817
+ *
12818
+ * These schemas serve as the single source of truth for types that are
12819
+ * stored in the settings-store backend and retrieved via tRPC. They
12820
+ * replace the manual TypeScript interfaces with schema-derived types,
12821
+ * enabling runtime validation when reading from the backend.
12822
+ *
12823
+ * Convention: each schema is named `<Type>Schema`, the inferred TS type
12824
+ * keeps the original name for backward compatibility.
12825
+ */
12826
+ /**
12827
+ * Auth model (v2 — 2026-05-12 caps-only):
12828
+ *
12829
+ * Two principals:
12830
+ * - `isAdmin: true` — full bypass. Admin scope set is ignored.
12831
+ * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
12832
+ *
12833
+ * No role enum. There used to be `viewer / agent / scoped` and earlier
12834
+ * `super_admin` — collapsed onto the single boolean because every
12835
+ * non-admin caller is governed by the same scope-check rules; the
12836
+ * distinction was only ever used to route role-specific procedures
12837
+ * which we no longer have. CLI / webhook integrations are tokens (`auth.mintToken`)
12838
+ * with `isAdmin: false` + an explicit scope list.
12839
+ */
12840
+ /** Per-method access flavour. Materialised on every cap method via codegen. */
12841
+ var MethodAccessSchema = _enum([
12842
+ "view",
12843
+ "create",
12844
+ "delete"
12845
+ ]);
12846
+ /**
12847
+ * A single scope grant. Three forms — checked in matcher with OR
12848
+ * semantics; the first match decides whether the call passes:
12849
+ *
12850
+ * - `category` — broadest. `target: 'device' | 'system'` selects every
12851
+ * cap with the matching `scope` declaration. New caps inherit grants
12852
+ * automatically — adding a device cap to the codebase makes it
12853
+ * reachable to every user with `category:device [...]` without a
12854
+ * re-grant. Use this for "family viewer" / "operator" tiers.
12855
+ *
12856
+ * - `addon` — every cap that ships inside a given addon id. Niche;
12857
+ * useful when an integration needs to interact with one specific
12858
+ * addon's surface regardless of how many caps it exports.
12859
+ *
12860
+ * - `capability` — the most precise form. Single cap name. Use for
12861
+ * integration tokens where you want to grant `addons.installPackage`
12862
+ * and nothing else.
12863
+ *
12864
+ * `access` is REQUIRED with min 1 element. `admin` bypass is the
12865
+ * "give me everything" escape; there is no wildcard scope.
12866
+ */
12867
+ var AllowedProviderSchema = union([literal("*"), array(string$2())]);
12868
+ var AllowedDevicesSchema = record(string$2(), union([literal("*"), array(string$2())]));
12869
+ var CapScopeSchema = _enum(["device", "system"]);
12870
+ /**
12871
+ * DeviceSelector (scope model v3 — 2026-08-12).
12872
+ *
12873
+ * A `device` grant no longer carries a frozen list of deviceIds. It carries
12874
+ * a SELECTOR the matcher resolves against the live fleet, so the grant can be
12875
+ * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
12876
+ * AFTER the grant was minted — no re-grant, no re-login.
12877
+ *
12878
+ * - `all` — every device in the deployment. The broad viewer/operator
12879
+ * lever without a `category` grant (a `category` grant also covers device
12880
+ * caps that carry no deviceId; `all` is specifically the device set).
12881
+ * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
12882
+ * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
12883
+ * is NOT covered until the grant is edited.
12884
+ * - `types` — every device of a `DeviceType` (e.g. every `camera`).
12885
+ * DYNAMIC. A device that changes type, or a new device of the type,
12886
+ * re-resolves on the next request.
12887
+ * - `locations` — every device whose operator-assigned `location` label is
12888
+ * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
12889
+ * null/unset location matches NO `locations` selector.
12890
+ */
12891
+ var DeviceSelectorSchema = discriminatedUnion("kind", [
12892
+ object({ kind: literal("all") }),
12893
+ object({
12894
+ kind: literal("ids"),
12895
+ ids: array(number().int()).min(1)
12896
+ }),
12897
+ object({
12898
+ kind: literal("types"),
12899
+ types: array(_enum(DeviceType)).min(1)
12900
+ }),
12901
+ object({
12902
+ kind: literal("locations"),
12903
+ locations: array(string$2().min(1)).min(1)
12904
+ })
12905
+ ]);
12906
+ var DeviceTokenScopeSchema = object({
12907
+ type: literal("device"),
12908
+ /** The device SET this grant covers — resolved against the live fleet. */
12909
+ selector: DeviceSelectorSchema,
12910
+ access: array(MethodAccessSchema).min(1),
12911
+ /**
12912
+ * Whether a grant on a PARENT device transparently covers its accessory
12913
+ * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
12914
+ * Direction is parent → children ONLY.
12915
+ *
12916
+ * Absent → the matcher DERIVES it from the access flavour: `view`
12917
+ * inherits (a camera viewer sees the camera's accessories), `create` /
12918
+ * `delete` do NOT (actuating/removing a child is an explicit act the
12919
+ * operator must grant on the child, not inherit from the parent). Set it
12920
+ * explicitly to override that default per grant.
12921
+ */
12922
+ includeLinked: boolean().optional()
12923
+ });
12924
+ /**
12925
+ * v2 → v3 lazy migration. A pre-v3 `device` grant carried
12926
+ * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
12927
+ * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
12928
+ * EVERY parse path — stored records AND the JWT-carried scope arrays
12929
+ * normalised at the request boundary ({@link normalizeTokenScopes} in
12930
+ * `device-selector.ts`). Chosen over a one-time DB migration because a
12931
+ * migration cannot reach a JWT already in a client's hands; parse-time
12932
+ * migration covers both without a flag day. No cast — the raw object is read
12933
+ * through `Reflect.get` (its static type is `unknown`).
12934
+ */
12935
+ function migrateLegacyTokenScope(raw) {
12936
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
12937
+ if (Reflect.get(raw, "type") !== "device") return raw;
12938
+ if (Reflect.get(raw, "selector") !== void 0) return raw;
12939
+ const targets = Reflect.get(raw, "targets");
12940
+ if (!Array.isArray(targets)) return raw;
12941
+ return {
12942
+ type: "device",
12943
+ selector: {
12944
+ kind: "ids",
12945
+ ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
12946
+ },
12947
+ access: Reflect.get(raw, "access")
12948
+ };
12949
+ }
12950
+ var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
12951
+ object({
12952
+ type: literal("category"),
12953
+ target: CapScopeSchema,
12954
+ access: array(MethodAccessSchema).min(1)
12955
+ }),
12956
+ object({
12957
+ type: literal("capability"),
12958
+ target: string$2(),
12959
+ access: array(MethodAccessSchema).min(1)
12960
+ }),
12961
+ object({
12962
+ type: literal("addon"),
12963
+ target: string$2(),
12964
+ access: array(MethodAccessSchema).min(1)
12965
+ }),
12966
+ DeviceTokenScopeSchema
12967
+ ]));
12968
+ object({
12969
+ id: string$2(),
12970
+ username: string$2(),
12971
+ passwordHash: string$2(),
12972
+ /**
12973
+ * Admin bypass. When true, the middleware skips the scope-access
12974
+ * check entirely. There is no other axis of privilege; the legacy
12975
+ * role enum collapsed onto this boolean in v2.
12976
+ */
12977
+ isAdmin: boolean().default(false),
12978
+ allowedProviders: AllowedProviderSchema,
12979
+ allowedDevices: AllowedDevicesSchema,
12980
+ /**
12981
+ * Scopes granted to this user. Admins bypass; their `scopes` is
12982
+ * ignored. Non-admins without scopes are locked out of every
12983
+ * protected call.
12984
+ */
12985
+ scopes: array(TokenScopeSchema).default([]),
12986
+ createdAt: number(),
12987
+ updatedAt: number()
12988
+ });
12989
+ object({
12990
+ id: string$2(),
12991
+ label: string$2(),
12992
+ isAdmin: boolean().default(false),
12993
+ allowedProviders: AllowedProviderSchema,
12994
+ allowedDevices: AllowedDevicesSchema,
12995
+ tokenHash: string$2(),
12996
+ tokenPrefix: string$2(),
12997
+ createdAt: number(),
12998
+ lastUsedAt: number().optional()
12999
+ });
13000
+ object({
13001
+ id: string$2(),
13002
+ userId: string$2(),
13003
+ name: string$2(),
13004
+ tokenHash: string$2(),
13005
+ tokenPrefix: string$2(),
13006
+ scopes: array(TokenScopeSchema),
13007
+ expiresAt: number().nullish(),
13008
+ lastUsedAt: number().nullish(),
13009
+ createdAt: number()
13010
+ });
13011
+ /** What a share-view grant lets its holder see. */
13012
+ var ShareViewGrantSchema = object({
13013
+ kind: _enum(SHARE_VIEW_KINDS),
13014
+ deviceIds: array(number().int().nonnegative()).min(1).max(64),
13015
+ /** Talk-back, opt-in at mint time; absent means off. */
13016
+ talk: boolean().optional()
13017
+ });
13018
+ var ShareViewScopeSchema = object({
13019
+ type: literal("share-view"),
13020
+ grant: ShareViewGrantSchema
13021
+ });
13022
+ var AddonRoutesScopeSchema = object({
13023
+ type: literal("addon-routes"),
13024
+ access: array(MethodAccessSchema).min(1)
13025
+ });
13026
+ var PreferencesSelfScopeSchema = object({ type: literal("preferences-self") });
13027
+ var CredentialScopeSchema = union([
13028
+ literal("*"),
13029
+ ShareViewScopeSchema,
13030
+ AddonRoutesScopeSchema,
13031
+ PreferencesSelfScopeSchema,
13032
+ TokenScopeSchema
13033
+ ]);
13034
+ object({
13035
+ kind: literal("credential"),
13036
+ sub: string$2().min(1),
13037
+ jti: string$2().min(16),
13038
+ scopes: array(CredentialScopeSchema).min(1)
13039
+ });
13040
+ var PreferenceNamespaceSchema = string$2().regex(/^[a-z][a-z0-9.-]{0,63}$/);
13041
+ /** A namespace's value: a JSON object, opaque to the hub. */
13042
+ var PreferenceValueSchema = record(string$2(), unknown());
13043
+ var PreferenceDeviceIdSchema = string$2().min(1).max(64);
13044
+ /** A stored row, as the owner reads it. */
13045
+ var PreferenceRowSchema = object({
13046
+ namespace: PreferenceNamespaceSchema,
13047
+ value: PreferenceValueSchema,
13048
+ /** Starts at 1, +1 on every write of this namespace. A delete ends the row and its count. */
13049
+ revision: number().int().positive(),
13050
+ updatedAt: number().int(),
13051
+ /** The client id the last writer sent; `null` when it sent none. */
13052
+ updatedByDevice: PreferenceDeviceIdSchema.nullable()
13053
+ });
13054
+ object({
13055
+ /** Absent: every namespace the caller holds. */
13056
+ namespaces: array(PreferenceNamespaceSchema).max(32).optional() });
13057
+ object({ rows: array(PreferenceRowSchema) });
13058
+ object({
13059
+ namespace: PreferenceNamespaceSchema,
13060
+ value: PreferenceValueSchema,
13061
+ /**
13062
+ * The revision the edit was based on. Absent: last write wins. `0`: the
13063
+ * namespace must not exist yet. Any other value that is not the current
13064
+ * revision answers `conflict` and writes nothing.
13065
+ */
13066
+ baseRevision: number().int().nonnegative().optional(),
13067
+ deviceId: PreferenceDeviceIdSchema.optional()
13068
+ });
13069
+ discriminatedUnion("status", [object({
13070
+ status: literal("saved"),
13071
+ row: PreferenceRowSchema
13072
+ }), object({
13073
+ status: literal("conflict"),
13074
+ current: PreferenceRowSchema.nullable()
13075
+ })]);
13076
+ object({ namespace: PreferenceNamespaceSchema });
13077
+ object({
13078
+ /** `false` when the namespace did not exist. */
13079
+ deleted: boolean() });
13080
+ object({
13081
+ /** The revision the client holds per namespace; a namespace it does not list is new to it. */
13082
+ revisionByNamespace: record(PreferenceNamespaceSchema, number().int().nonnegative()).refine((map) => Object.keys(map).length <= 32, { message: `at most 32 namespaces` }) });
13083
+ object({
13084
+ /** Every row whose revision differs from the client's, and every row it did not list. */
13085
+ rows: array(PreferenceRowSchema),
13086
+ /** Namespaces the client listed that no longer exist. */
13087
+ deleted: array(PreferenceNamespaceSchema)
13088
+ });
12809
13089
  _enum(["new-session", "step-up"]);
12810
13090
  /** The languages the hub's app landing pages are written in (D858). */
12811
13091
  var AppPageLangSchema = _enum(["en", "it"]);
@@ -40048,38 +40328,37 @@ method(LlmRuntimeCompleteInputSchema, LlmGenerateResultSchema, {
40048
40328
  auth: "admin",
40049
40329
  timeoutMs: AI_CAP_TRANSPORT_TIMEOUT_MS
40050
40330
  });
40331
+ var LlmProfileKindSchema = string$2().regex(/^[a-z0-9][a-z0-9-]{0,63}$/, "a kind id is lower-case letters, digits and dashes");
40332
+ /** What a model (or, by default, every model of a kind) can do. */
40333
+ var LlmModelFeaturesSchema = object({
40334
+ vision: boolean(),
40335
+ tools: boolean(),
40336
+ streaming: boolean()
40337
+ });
40338
+ /** One model a provider offers. `features` overrides the kind's defaults, per field. */
40339
+ var LlmModelInfoSchema = object({
40340
+ id: string$2(),
40341
+ label: string$2().optional(),
40342
+ contextLength: number().int().positive().optional(),
40343
+ features: LlmModelFeaturesSchema.partial().optional()
40344
+ });
40051
40345
  /**
40052
- * `llm` — consumer-facing LLM surface (spec §1-§3). Collection-mode: array
40053
- * methods concat-fan across providers; single-row methods route to ONE
40054
- * provider by the `addonId` in the call input (the notification-output
40055
- * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
40056
- * (hub-placed); the cap stays open for future providers.
40057
- *
40058
- * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
40059
- * `apiKey` is a password field — providers REDACT it on read and merge on
40060
- * write; a stored key NEVER round-trips to a client.
40346
+ * The provider-specific part of a profile, validated by the provider that owns
40347
+ * the kind (`upsertProfile` refuses what it does not accept). A field its
40348
+ * `connectionSchema` declares `type: 'password'` is a secret: it is held in the
40349
+ * keychain, never in the row, and reads back as the redaction marker.
40061
40350
  */
40062
- var LlmProfileKindSchema = _enum([
40063
- "openai-compatible",
40064
- "openai",
40065
- "anthropic",
40066
- "google",
40067
- "managed-local",
40068
- "apple-foundation"
40069
- ]);
40351
+ var LlmProviderConfigSchema = record(string$2(), unknown());
40070
40352
  var LlmProfileSchema = object({
40071
40353
  id: string$2(),
40072
40354
  name: string$2(),
40355
+ /** The provider-declared kind (`LlmProfileKindDescriptor.kind`). */
40073
40356
  kind: LlmProfileKindSchema,
40074
40357
  /** Stamped by the provider — keeps the fanned catalog routable. */
40075
40358
  addonId: string$2(),
40076
40359
  enabled: boolean(),
40077
40360
  /** Vendor model id, or the managed runtime's loaded model. */
40078
40361
  model: string$2(),
40079
- /** Required for openai-compatible; override for cloud kinds. */
40080
- baseUrl: string$2().optional(),
40081
- /** ConfigUISchema type:'password' — never round-trips (spec §5). */
40082
- apiKey: string$2().optional(),
40083
40362
  /** Vision on/off. A vision call against a `false` profile is REFUSED, never
40084
40363
  * degraded to text — that shipped once and produced a confident answer to a
40085
40364
  * question about a picture nobody sent. */
@@ -40087,15 +40366,11 @@ var LlmProfileSchema = object({
40087
40366
  temperature: number().min(0).max(2).optional(),
40088
40367
  /** Nucleus sampling. Every wire we speak has it. */
40089
40368
  topP: number().min(0).max(1).optional(),
40090
- /** Top-k sampling. Carried only by the wires that have it — NEITHER OpenAI
40091
- * wire does, and the client drops it there (measured: the request body gets
40092
- * `top_p` and no `top_k`). The profile editor hides the field wherever it
40093
- * would change nothing; `KINDS_WITH_TOP_K` is the single owner of that list. */
40369
+ /** Top-k sampling. Carried only by the wires that have it — a kind offers the
40370
+ * field in its editor only when its descriptor lists it in `profileFields`. */
40094
40371
  topK: number().int().positive().optional(),
40095
40372
  maxTokens: number().int().positive().optional(),
40096
- /** Prompt context window. Advisory for cloud kinds (they enforce their own);
40097
- * for `managed-local` it is the llama.cpp `--ctx-size` the runtime starts
40098
- * the model with, so it is the one field that changes a PROCESS. */
40373
+ /** Prompt context window. Advisory for cloud kinds (they enforce their own). */
40099
40374
  contextLength: number().int().positive().optional(),
40100
40375
  /** Default system prompt. A caller's `system` REPLACES it (never appends —
40101
40376
  * two system prompts fighting is worse than either alone). */
@@ -40121,16 +40396,37 @@ var LlmProfileSchema = object({
40121
40396
  * library; the REGISTRY of callable tools is ours and is empty in v1, so a
40122
40397
  * `true` here buys the wiring, not behaviour, until tools are registered. */
40123
40398
  toolsEnabled: boolean().default(false),
40124
- extraHeaders: record(string$2(), string$2()).optional(),
40125
- /** kind === 'managed-local' only (spec §4). */
40126
- runtime: ManagedRuntimeConfigSchema.optional(),
40127
- /**
40128
- * kind === 'apple-foundation' only: WHERE it runs — the only thing there is
40129
- * to configure (no key, no URL, no download; `model` is `apple-system`).
40130
- * `supportsVision` on such a row is stamped by the provider from the node's
40131
- * reported `imageInput`, never taken from the operator (D62).
40132
- */
40133
- appleFoundation: object({ nodeId: string$2() }).optional()
40399
+ /** Everything the kind's provider owns (endpoint, key, node, runtime…). */
40400
+ providerConfig: LlmProviderConfigSchema.default({})
40401
+ });
40402
+ /**
40403
+ * The common profile fields a kind's editor offers. The editor owns how each
40404
+ * one is drawn; the provider says which of them mean something on its wire.
40405
+ */
40406
+ var LlmProfileFieldSchema = _enum([
40407
+ "temperature",
40408
+ "topP",
40409
+ "topK",
40410
+ "maxTokens",
40411
+ "contextLength",
40412
+ "systemPrompt",
40413
+ "timeoutMs",
40414
+ "connectTimeoutMs",
40415
+ "firstTokenTimeoutMs",
40416
+ "idleTimeoutMs",
40417
+ "retry",
40418
+ "toolsEnabled"
40419
+ ]);
40420
+ /**
40421
+ * A provider-drawn part of the editor, by a generic widget id the admin UI
40422
+ * registers (`ai/apple-node`). `placement: 'model'` replaces the generic model
40423
+ * picker: that widget owns the model choice.
40424
+ */
40425
+ var LlmProviderWidgetSchema = object({
40426
+ id: string$2(),
40427
+ placement: _enum(["connection", "model"]),
40428
+ /** `providerConfig` keys this widget must fill before the profile can be saved. */
40429
+ requires: array(string$2()).optional()
40134
40430
  });
40135
40431
  /** ConfigUISchema tree passed through untyped on the wire (the
40136
40432
  * notification-output `ConfigSchemaPassthrough` precedent at
@@ -40139,11 +40435,56 @@ var ConfigSchemaPassthrough$3 = unknown();
40139
40435
  var LlmProfileKindDescriptorSchema = object({
40140
40436
  kind: LlmProfileKindSchema,
40141
40437
  label: string$2(),
40438
+ /** A generic icon name (`cloud`, `plug`, `cpu`) — never a glyph or a logo. */
40142
40439
  icon: string$2(),
40143
40440
  /** Stamped by each provider so the concat-fanned catalog stays routable. */
40144
40441
  addonId: string$2(),
40145
- configSchema: ConfigSchemaPassthrough$3
40442
+ /** The provider's own fields (`providerConfig`); `password` fields are keychain-held. */
40443
+ connectionSchema: ConfigSchemaPassthrough$3,
40444
+ /** Provider fields that belong under "Advanced" (extra headers, runtime tuning). */
40445
+ advancedSchema: ConfigSchemaPassthrough$3.optional(),
40446
+ /** The kind's defaults; a model from `listModels` may override any of them. */
40447
+ features: LlmModelFeaturesSchema,
40448
+ /** `false` = the provider stamps `supportsVision` itself (from what a node reports). */
40449
+ visionEditable: boolean(),
40450
+ /** Where the model list comes from: `listModels`, `staticModels`, or nowhere. */
40451
+ modelCatalog: _enum([
40452
+ "fetch",
40453
+ "static",
40454
+ "none"
40455
+ ]),
40456
+ staticModels: array(LlmModelInfoSchema).optional(),
40457
+ /** The common fields that mean something on this kind's wire. */
40458
+ profileFields: array(LlmProfileFieldSchema),
40459
+ providerWidgets: array(LlmProviderWidgetSchema).optional()
40460
+ });
40461
+ /**
40462
+ * `listModels` input. `connection` is an UNSAVED draft of `providerConfig`
40463
+ * (the editor's form); with `profileId` too, a secret the draft leaves
40464
+ * untouched (absent or the redaction marker) is resolved server-side from the
40465
+ * stored profile — the browser never receives it.
40466
+ */
40467
+ var LlmListModelsInputSchema = object({
40468
+ addonId: string$2(),
40469
+ kind: LlmProfileKindSchema,
40470
+ profileId: string$2().optional(),
40471
+ connection: LlmProviderConfigSchema.optional()
40146
40472
  });
40473
+ var LlmListModelsErrorCodeSchema = _enum([
40474
+ "auth",
40475
+ "network",
40476
+ "unsupported",
40477
+ "invalid"
40478
+ ]);
40479
+ /** A RESULT, never a throw: "wrong key" is an answer the editor renders inline. */
40480
+ var LlmListModelsResultSchema = discriminatedUnion("ok", [object({
40481
+ ok: literal(true),
40482
+ models: array(LlmModelInfoSchema)
40483
+ }), object({
40484
+ ok: literal(false),
40485
+ code: LlmListModelsErrorCodeSchema,
40486
+ message: string$2()
40487
+ })]);
40147
40488
  var LlmDefaultSelectorSchema = union([object({ consumer: string$2() }), object({ purpose: _enum(["text", "vision"]) })]);
40148
40489
  var LlmDefaultSchema = object({
40149
40490
  selector: LlmDefaultSelectorSchema,
@@ -40243,7 +40584,10 @@ method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, {
40243
40584
  kind: "mutation",
40244
40585
  auth: "admin",
40245
40586
  timeoutMs: AI_CAP_TRANSPORT_TIMEOUT_MS
40246
- }), method(ProfileRefInputSchema, array(string$2())), method(object({}), array(LlmDefaultSchema)), method(object({
40587
+ }), method(LlmListModelsInputSchema, LlmListModelsResultSchema, {
40588
+ kind: "mutation",
40589
+ auth: "admin"
40590
+ }), method(object({}), array(LlmDefaultSchema)), method(object({
40247
40591
  selector: LlmDefaultSelectorSchema,
40248
40592
  profileId: string$2().nullable()
40249
40593
  }), _void(), {
@@ -44349,202 +44693,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
44349
44693
  auth: "admin"
44350
44694
  }), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
44351
44695
  /**
44352
- * Zod schemas for persisted record types.
44353
- *
44354
- * These schemas serve as the single source of truth for types that are
44355
- * stored in the settings-store backend and retrieved via tRPC. They
44356
- * replace the manual TypeScript interfaces with schema-derived types,
44357
- * enabling runtime validation when reading from the backend.
44358
- *
44359
- * Convention: each schema is named `<Type>Schema`, the inferred TS type
44360
- * keeps the original name for backward compatibility.
44361
- */
44362
- /**
44363
- * Auth model (v2 — 2026-05-12 caps-only):
44364
- *
44365
- * Two principals:
44366
- * - `isAdmin: true` — full bypass. Admin scope set is ignored.
44367
- * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
44368
- *
44369
- * No role enum. There used to be `viewer / agent / scoped` and earlier
44370
- * `super_admin` — collapsed onto the single boolean because every
44371
- * non-admin caller is governed by the same scope-check rules; the
44372
- * distinction was only ever used to route role-specific procedures
44373
- * which we no longer have. CLI / webhook integrations are `cst_*` tokens
44374
- * with `isAdmin: false` + an explicit scope list.
44375
- */
44376
- /** Per-method access flavour. Materialised on every cap method via codegen. */
44377
- var MethodAccessSchema = _enum([
44378
- "view",
44379
- "create",
44380
- "delete"
44381
- ]);
44382
- /**
44383
- * A single scope grant. Three forms — checked in matcher with OR
44384
- * semantics; the first match decides whether the call passes:
44385
- *
44386
- * - `category` — broadest. `target: 'device' | 'system'` selects every
44387
- * cap with the matching `scope` declaration. New caps inherit grants
44388
- * automatically — adding a device cap to the codebase makes it
44389
- * reachable to every user with `category:device [...]` without a
44390
- * re-grant. Use this for "family viewer" / "operator" tiers.
44391
- *
44392
- * - `addon` — every cap that ships inside a given addon id. Niche;
44393
- * useful when an integration needs to interact with one specific
44394
- * addon's surface regardless of how many caps it exports.
44395
- *
44396
- * - `capability` — the most precise form. Single cap name. Use for
44397
- * integration tokens where you want to grant `addons.installPackage`
44398
- * and nothing else.
44399
- *
44400
- * `access` is REQUIRED with min 1 element. `admin` bypass is the
44401
- * "give me everything" escape; there is no wildcard scope.
44402
- */
44403
- var AllowedProviderSchema = union([literal("*"), array(string$2())]);
44404
- var AllowedDevicesSchema = record(string$2(), union([literal("*"), array(string$2())]));
44405
- var CapScopeSchema = _enum(["device", "system"]);
44406
- /**
44407
- * DeviceSelector (scope model v3 — 2026-08-12).
44408
- *
44409
- * A `device` grant no longer carries a frozen list of deviceIds. It carries
44410
- * a SELECTOR the matcher resolves against the live fleet, so the grant can be
44411
- * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
44412
- * AFTER the grant was minted — no re-grant, no re-login.
44413
- *
44414
- * - `all` — every device in the deployment. The broad viewer/operator
44415
- * lever without a `category` grant (a `category` grant also covers device
44416
- * caps that carry no deviceId; `all` is specifically the device set).
44417
- * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
44418
- * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
44419
- * is NOT covered until the grant is edited.
44420
- * - `types` — every device of a `DeviceType` (e.g. every `camera`).
44421
- * DYNAMIC. A device that changes type, or a new device of the type,
44422
- * re-resolves on the next request.
44423
- * - `locations` — every device whose operator-assigned `location` label is
44424
- * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
44425
- * null/unset location matches NO `locations` selector.
44426
- */
44427
- var DeviceSelectorSchema = discriminatedUnion("kind", [
44428
- object({ kind: literal("all") }),
44429
- object({
44430
- kind: literal("ids"),
44431
- ids: array(number().int()).min(1)
44432
- }),
44433
- object({
44434
- kind: literal("types"),
44435
- types: array(_enum(DeviceType)).min(1)
44436
- }),
44437
- object({
44438
- kind: literal("locations"),
44439
- locations: array(string$2().min(1)).min(1)
44440
- })
44441
- ]);
44442
- var DeviceTokenScopeSchema = object({
44443
- type: literal("device"),
44444
- /** The device SET this grant covers — resolved against the live fleet. */
44445
- selector: DeviceSelectorSchema,
44446
- access: array(MethodAccessSchema).min(1),
44447
- /**
44448
- * Whether a grant on a PARENT device transparently covers its accessory
44449
- * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
44450
- * Direction is parent → children ONLY.
44451
- *
44452
- * Absent → the matcher DERIVES it from the access flavour: `view`
44453
- * inherits (a camera viewer sees the camera's accessories), `create` /
44454
- * `delete` do NOT (actuating/removing a child is an explicit act the
44455
- * operator must grant on the child, not inherit from the parent). Set it
44456
- * explicitly to override that default per grant.
44457
- */
44458
- includeLinked: boolean().optional()
44459
- });
44460
- /**
44461
- * v2 → v3 lazy migration. A pre-v3 `device` grant carried
44462
- * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
44463
- * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
44464
- * EVERY parse path — stored records AND the JWT-carried scope arrays
44465
- * normalised at the request boundary ({@link normalizeTokenScopes} in
44466
- * `device-selector.ts`). Chosen over a one-time DB migration because a
44467
- * migration cannot reach a JWT already in a client's hands; parse-time
44468
- * migration covers both without a flag day. No cast — the raw object is read
44469
- * through `Reflect.get` (its static type is `unknown`).
44470
- */
44471
- function migrateLegacyTokenScope(raw) {
44472
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
44473
- if (Reflect.get(raw, "type") !== "device") return raw;
44474
- if (Reflect.get(raw, "selector") !== void 0) return raw;
44475
- const targets = Reflect.get(raw, "targets");
44476
- if (!Array.isArray(targets)) return raw;
44477
- return {
44478
- type: "device",
44479
- selector: {
44480
- kind: "ids",
44481
- ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
44482
- },
44483
- access: Reflect.get(raw, "access")
44484
- };
44485
- }
44486
- var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
44487
- object({
44488
- type: literal("category"),
44489
- target: CapScopeSchema,
44490
- access: array(MethodAccessSchema).min(1)
44491
- }),
44492
- object({
44493
- type: literal("capability"),
44494
- target: string$2(),
44495
- access: array(MethodAccessSchema).min(1)
44496
- }),
44497
- object({
44498
- type: literal("addon"),
44499
- target: string$2(),
44500
- access: array(MethodAccessSchema).min(1)
44501
- }),
44502
- DeviceTokenScopeSchema
44503
- ]));
44504
- object({
44505
- id: string$2(),
44506
- username: string$2(),
44507
- passwordHash: string$2(),
44508
- /**
44509
- * Admin bypass. When true, the middleware skips the scope-access
44510
- * check entirely. There is no other axis of privilege; the legacy
44511
- * role enum collapsed onto this boolean in v2.
44512
- */
44513
- isAdmin: boolean().default(false),
44514
- allowedProviders: AllowedProviderSchema,
44515
- allowedDevices: AllowedDevicesSchema,
44516
- /**
44517
- * Scopes granted to this user. Admins bypass; their `scopes` is
44518
- * ignored. Non-admins without scopes are locked out of every
44519
- * protected call.
44520
- */
44521
- scopes: array(TokenScopeSchema).default([]),
44522
- createdAt: number(),
44523
- updatedAt: number()
44524
- });
44525
- object({
44526
- id: string$2(),
44527
- label: string$2(),
44528
- isAdmin: boolean().default(false),
44529
- allowedProviders: AllowedProviderSchema,
44530
- allowedDevices: AllowedDevicesSchema,
44531
- tokenHash: string$2(),
44532
- tokenPrefix: string$2(),
44533
- createdAt: number(),
44534
- lastUsedAt: number().optional()
44535
- });
44536
- object({
44537
- id: string$2(),
44538
- userId: string$2(),
44539
- name: string$2(),
44540
- tokenHash: string$2(),
44541
- tokenPrefix: string$2(),
44542
- scopes: array(TokenScopeSchema),
44543
- expiresAt: number().nullish(),
44544
- lastUsedAt: number().nullish(),
44545
- createdAt: number()
44546
- });
44547
- /**
44548
44696
  * `oauth-integration` — a collection cap by which an addon declares
44549
44697
  * itself a linkable OAuth client of the hub's core `/oauth2/*` server.
44550
44698
  * Each provider returns a static descriptor; the core enumerates them
@@ -64344,26 +64492,6 @@ var ApiKeySummarySchema = object({
64344
64492
  createdAt: number(),
64345
64493
  lastUsedAt: number().optional()
64346
64494
  });
64347
- var ScopedTokenSummarySchema = object({
64348
- id: string$2(),
64349
- userId: string$2(),
64350
- name: string$2(),
64351
- tokenPrefix: string$2(),
64352
- scopes: array(TokenScopeSchema),
64353
- expiresAt: number().nullish(),
64354
- lastUsedAt: number().nullish(),
64355
- createdAt: number()
64356
- });
64357
- var CreateScopedTokenInputSchema = object({
64358
- userId: string$2(),
64359
- name: string$2(),
64360
- scopes: array(TokenScopeSchema),
64361
- expiresAt: number().optional()
64362
- });
64363
- var CreateScopedTokenResultSchema = object({
64364
- token: string$2(),
64365
- record: ScopedTokenSummarySchema
64366
- });
64367
64495
  var OauthSessionSummarySchema = object({
64368
64496
  id: string$2(),
64369
64497
  userId: string$2(),
@@ -64385,11 +64513,11 @@ var TotpStatusSchema = object({
64385
64513
  confirmedAt: number().nullable()
64386
64514
  });
64387
64515
  /**
64388
- * user-management — singleton capability for user accounts, API keys,
64389
- * and scoped tokens.
64516
+ * user-management — singleton capability for user accounts and the
64517
+ * legacy API-key rows.
64390
64518
  *
64391
64519
  * v2 model: every method gated by `auth: 'admin'`. Admin-only delegation
64392
- * — the subset check on `setUserScopes` / `createScopedToken` is moot
64520
+ * — the subset check on `setUserScopes` is moot
64393
64521
  * because non-admins never reach these. If/when we open non-admin
64394
64522
  * delegation, structural caller-scope subset check goes inside the
64395
64523
  * provider.
@@ -64446,15 +64574,7 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
64446
64574
  kind: "mutation",
64447
64575
  auth: "admin",
64448
64576
  access: "delete"
64449
- }), method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
64450
- kind: "mutation",
64451
- auth: "admin",
64452
- access: "create"
64453
- }), method(object({ id: string$2() }), object({ success: literal(true) }), {
64454
- kind: "mutation",
64455
- auth: "admin",
64456
- access: "delete"
64457
- }), method(object({ token: string$2() }), ScopedTokenSummarySchema.nullable(), { access: "view" }), method(object({ userId: string$2() }), array(ScopedTokenSummarySchema), { auth: "admin" }), method(object({ userId: string$2() }), TotpSetupResultSchema, {
64577
+ }), method(object({ userId: string$2() }), TotpSetupResultSchema, {
64458
64578
  kind: "mutation",
64459
64579
  auth: "admin",
64460
64580
  access: "create"
@@ -70544,7 +70664,7 @@ Object.freeze({
70544
70664
  capName: "llm",
70545
70665
  capScope: "system",
70546
70666
  addonId: null,
70547
- access: "view"
70667
+ access: "create"
70548
70668
  },
70549
70669
  "llm.listNodeModels": {
70550
70670
  capName: "llm",
@@ -75208,12 +75328,6 @@ Object.freeze({
75208
75328
  addonId: null,
75209
75329
  access: "create"
75210
75330
  },
75211
- "userManagement.createScopedToken": {
75212
- capName: "user-management",
75213
- capScope: "system",
75214
- addonId: null,
75215
- access: "create"
75216
- },
75217
75331
  "userManagement.createUser": {
75218
75332
  capName: "user-management",
75219
75333
  capScope: "system",
@@ -75262,12 +75376,6 @@ Object.freeze({
75262
75376
  addonId: null,
75263
75377
  access: "view"
75264
75378
  },
75265
- "userManagement.listScopedTokens": {
75266
- capName: "user-management",
75267
- capScope: "system",
75268
- addonId: null,
75269
- access: "view"
75270
- },
75271
75379
  "userManagement.listUsers": {
75272
75380
  capName: "user-management",
75273
75381
  capScope: "system",
@@ -75322,12 +75430,6 @@ Object.freeze({
75322
75430
  addonId: null,
75323
75431
  access: "delete"
75324
75432
  },
75325
- "userManagement.revokeScopedToken": {
75326
- capName: "user-management",
75327
- capScope: "system",
75328
- addonId: null,
75329
- access: "delete"
75330
- },
75331
75433
  "userManagement.setupTotp": {
75332
75434
  capName: "user-management",
75333
75435
  capScope: "system",
@@ -75358,12 +75460,6 @@ Object.freeze({
75358
75460
  addonId: null,
75359
75461
  access: "view"
75360
75462
  },
75361
- "userManagement.validateScopedToken": {
75362
- capName: "user-management",
75363
- capScope: "system",
75364
- addonId: null,
75365
- access: "view"
75366
- },
75367
75463
  "userManagement.verifyTotp": {
75368
75464
  capName: "user-management",
75369
75465
  capScope: "system",