@capybara-hq/kernel 0.1.0-rc.53 → 0.1.0-rc.55

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 (190) hide show
  1. package/dist/admin/admin.schemas.d.ts +11 -1
  2. package/dist/catalog/catalog.module.js +1 -1
  3. package/dist/catalog/marketplaces.service.d.ts +1 -1
  4. package/dist/catalog/requests.service.d.ts +5 -5
  5. package/dist/catalog/requests.service.js +9 -9
  6. package/dist/channels/cards.d.ts +4 -3
  7. package/dist/channels/cards.js +25 -16
  8. package/dist/channels/phrases.d.ts +15 -4
  9. package/dist/channels/phrases.js +15 -1
  10. package/dist/config/load.d.ts +26 -7
  11. package/dist/config/load.js +60 -9
  12. package/dist/config/permission-migration.d.ts +17 -9
  13. package/dist/config/permission-migration.js +60 -9
  14. package/dist/config/schema.d.ts +15 -1
  15. package/dist/config/schema.js +66 -11
  16. package/dist/conversations/events.d.ts +247 -5
  17. package/dist/conversations/events.js +127 -16
  18. package/dist/conversations/permission-profiles.controller.d.ts +12 -2
  19. package/dist/conversations/permission-profiles.service.d.ts +12 -2
  20. package/dist/conversations/permission-profiles.service.js +11 -4
  21. package/dist/db/kernel-schema.d.ts +18 -2
  22. package/dist/devices/device-projects.service.d.ts +1 -1
  23. package/dist/devices/device-projects.service.js +6 -6
  24. package/dist/devices/devices.controller.d.ts +10 -8
  25. package/dist/devices/devices.controller.js +14 -18
  26. package/dist/devices/devices.schemas.d.ts +5 -5
  27. package/dist/devices/devices.schemas.js +5 -5
  28. package/dist/devices/devices.service.d.ts +188 -175
  29. package/dist/devices/devices.service.js +284 -292
  30. package/dist/devices/dto.d.ts +43 -23
  31. package/dist/devices/dto.js +45 -49
  32. package/dist/devices/project-rules.d.ts +0 -10
  33. package/dist/devices/project-rules.js +0 -5
  34. package/dist/errors.d.ts +43 -19
  35. package/dist/errors.js +43 -19
  36. package/dist/evals/reconstruct.d.ts +12 -3
  37. package/dist/evals/reconstruct.js +10 -6
  38. package/dist/evals/recorded-permission-context.d.ts +6 -4
  39. package/dist/evals/recorded-permission-context.js +15 -9
  40. package/dist/evals/run-replay.d.ts +6 -1
  41. package/dist/evals/run-replay.js +7 -2
  42. package/dist/evals/worker.js +3 -1
  43. package/dist/http/api.module.js +8 -0
  44. package/dist/http/app.js +9 -0
  45. package/dist/http/meta.controller.d.ts +33 -0
  46. package/dist/http/meta.controller.js +72 -0
  47. package/dist/identity/app-auth.controller.d.ts +25 -0
  48. package/dist/identity/app-auth.controller.js +64 -0
  49. package/dist/identity/app-auth.d.ts +66 -0
  50. package/dist/identity/app-auth.js +203 -0
  51. package/dist/identity/app-auth.schemas.d.ts +47 -0
  52. package/dist/identity/app-auth.schemas.js +43 -0
  53. package/dist/identity/identity.module.d.ts +1 -1
  54. package/dist/identity/identity.module.js +4 -1
  55. package/dist/identity/settings.d.ts +45 -18
  56. package/dist/identity/settings.js +151 -51
  57. package/dist/infra/config/kernel-config.service.d.ts +1 -1
  58. package/dist/infra/config/kernel-config.service.js +19 -5
  59. package/dist/infra/outbox/registry.d.ts +14 -0
  60. package/dist/infra/outbox/registry.js +15 -0
  61. package/dist/infra/throttler/named-throttlers.d.ts +3 -2
  62. package/dist/infra/throttler/named-throttlers.js +14 -2
  63. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  64. package/dist/local-devices/device-auth.controller.js +1 -1
  65. package/dist/local-devices/device-auth.d.ts +4 -4
  66. package/dist/local-devices/device-auth.js +1 -1
  67. package/dist/local-devices/device-policy.service.d.ts +18 -9
  68. package/dist/local-devices/device-policy.service.js +21 -61
  69. package/dist/local-devices/device-routes.d.ts +3 -1
  70. package/dist/local-devices/device-routes.js +15 -4
  71. package/dist/local-devices/instance-bindings.js +5 -2
  72. package/dist/local-devices/local-device-gateway.d.ts +2 -2
  73. package/dist/local-devices/local-device-gateway.js +3 -3
  74. package/dist/local-devices/local-device-provider.d.ts +4 -4
  75. package/dist/local-devices/local-device-provider.js +23 -9
  76. package/dist/local-devices/local-devices.module.d.ts +1 -1
  77. package/dist/local-devices/local-devices.module.js +1 -1
  78. package/dist/local-devices/machines.d.ts +40 -16
  79. package/dist/local-devices/machines.js +89 -61
  80. package/dist/local-devices/owner-report.d.ts +16 -14
  81. package/dist/local-devices/owner-report.js +24 -30
  82. package/dist/local-devices/owner-reports.js +26 -8
  83. package/dist/local-devices/policy-summary.d.ts +25 -44
  84. package/dist/local-devices/policy-summary.js +26 -71
  85. package/dist/local-devices/relay.d.ts +6 -6
  86. package/dist/local-devices/relay.js +10 -8
  87. package/dist/net/public-address.d.ts +1 -1
  88. package/dist/net/public-address.js +5 -2
  89. package/dist/orgs/device-network-setting.d.ts +82 -0
  90. package/dist/orgs/device-network-setting.js +142 -0
  91. package/dist/orgs/settings.service.d.ts +103 -66
  92. package/dist/orgs/settings.service.js +201 -137
  93. package/dist/overrides.d.ts +5 -1
  94. package/dist/overrides.js +2 -0
  95. package/dist/platform/exclusions.js +24 -1
  96. package/dist/platform/operation.js +2 -2
  97. package/dist/platform/ops/admin.ops.js +20 -11
  98. package/dist/platform/ops/devices.ops.js +70 -5
  99. package/dist/platform/ops/org-settings.ops.js +10 -6
  100. package/dist/platform/ops/orgs.ops.js +2 -1
  101. package/dist/platform/ops/platform-icons.ops.d.ts +14 -0
  102. package/dist/platform/ops/platform-icons.ops.js +117 -0
  103. package/dist/platform/platform-ops.module.d.ts +2 -1
  104. package/dist/platform/platform-ops.module.js +3 -0
  105. package/dist/platform/route-schemas.js +3 -0
  106. package/dist/runtime/context/permission-profile.d.ts +17 -8
  107. package/dist/runtime/context/permission-profile.js +126 -45
  108. package/dist/runtime/maintenance.d.ts +5 -2
  109. package/dist/runtime/maintenance.js +15 -4
  110. package/dist/runtime/permission-context.service.d.ts +1 -1
  111. package/dist/runtime/permission-context.service.js +5 -3
  112. package/dist/runtime/project/knowledge.d.ts +5 -4
  113. package/dist/runtime/project/knowledge.js +2 -1
  114. package/dist/runtime/project/knowledge.service.js +16 -13
  115. package/dist/sandbox/cloud-permission-snapshot.js +22 -3
  116. package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
  117. package/dist/sandbox/device-sandbox-settings.js +470 -0
  118. package/dist/sandbox/device-sandbox.d.ts +187 -0
  119. package/dist/sandbox/device-sandbox.js +236 -0
  120. package/dist/sandbox/held-operations.js +15 -7
  121. package/dist/sandbox/modes.d.ts +49 -24
  122. package/dist/sandbox/modes.js +27 -19
  123. package/dist/sandbox/operation-authority-types.d.ts +6 -5
  124. package/dist/sandbox/operation-authority-types.js +7 -8
  125. package/dist/sandbox/operation-authority.d.ts +23 -9
  126. package/dist/sandbox/operation-authority.js +179 -97
  127. package/dist/sandbox/permission-auto-grants.d.ts +42 -0
  128. package/dist/sandbox/permission-auto-grants.js +145 -0
  129. package/dist/sandbox/permission-call-grants.d.ts +12 -4
  130. package/dist/sandbox/permission-call-grants.js +84 -35
  131. package/dist/sandbox/permission-call-grants.module.js +10 -3
  132. package/dist/sandbox/permission-call-types.d.ts +39 -5
  133. package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
  134. package/dist/sandbox/permission-ceiling-writes.js +38 -4
  135. package/dist/sandbox/permission-config-publication.d.ts +44 -2
  136. package/dist/sandbox/permission-config-publication.js +230 -59
  137. package/dist/sandbox/permission-context-types.d.ts +2 -2
  138. package/dist/sandbox/permission-facts.d.ts +144 -15
  139. package/dist/sandbox/permission-facts.js +258 -70
  140. package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
  141. package/dist/sandbox/permission-runtime-reports.js +19 -29
  142. package/dist/sandbox/review/classifier.d.ts +8 -0
  143. package/dist/sandbox/review/classifier.js +10 -0
  144. package/dist/sandbox/review/permission-candidate.d.ts +69 -5
  145. package/dist/sandbox/review/permission-candidate.js +153 -30
  146. package/dist/sandbox/review/review.service.d.ts +19 -3
  147. package/dist/sandbox/review/review.service.js +59 -11
  148. package/dist/sandbox/review/rules.js +23 -3
  149. package/dist/sandbox/sandbox.service.d.ts +29 -11
  150. package/dist/sandbox/sandbox.service.js +51 -26
  151. package/dist/skills/invoke.js +3 -2
  152. package/dist/themes/platform-icon-objects.d.ts +51 -0
  153. package/dist/themes/platform-icon-objects.js +113 -0
  154. package/dist/themes/platform-icon-public.controller.d.ts +17 -0
  155. package/dist/themes/platform-icon-public.controller.js +58 -0
  156. package/dist/themes/platform-icon.controller.d.ts +22 -0
  157. package/dist/themes/platform-icon.controller.js +65 -0
  158. package/dist/themes/platform-icon.schemas.d.ts +48 -0
  159. package/dist/themes/platform-icon.schemas.js +53 -0
  160. package/dist/themes/platform-icon.service.d.ts +83 -0
  161. package/dist/themes/platform-icon.service.js +301 -0
  162. package/dist/themes/themes.module.d.ts +4 -1
  163. package/dist/themes/themes.module.js +9 -4
  164. package/dist/tools/approvals.service.d.ts +26 -116
  165. package/dist/tools/approvals.service.js +42 -346
  166. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  167. package/dist/tools/builtins/sandbox/bash.js +80 -28
  168. package/dist/tools/builtins/sandbox/common.d.ts +39 -14
  169. package/dist/tools/builtins/sandbox/common.js +47 -24
  170. package/dist/tools/builtins/sandbox/deliver.js +7 -4
  171. package/dist/tools/builtins/skill-load.d.ts +2 -2
  172. package/dist/tools/builtins/skill-load.js +4 -3
  173. package/dist/tools/device-op-resolver.d.ts +4 -10
  174. package/dist/tools/device-op-resolver.js +8 -19
  175. package/dist/tools/network-asks.d.ts +52 -15
  176. package/dist/tools/network-asks.js +55 -25
  177. package/dist/tools/pipeline.d.ts +26 -14
  178. package/dist/tools/pipeline.js +144 -61
  179. package/dist/tools/registry.d.ts +6 -0
  180. package/dist/tools/tools.module.js +1 -1
  181. package/package.json +4 -4
  182. package/src/migrations/0164_platform_icons.sql +10 -0
  183. package/src/migrations/0165_device_network_columns.sql +50 -0
  184. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  185. package/src/migrations/0167_device_network_backfill.sql +32 -0
  186. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  187. package/dist/orgs/cloud-network-setting.d.ts +0 -33
  188. package/dist/orgs/cloud-network-setting.js +0 -47
  189. package/dist/sandbox/platform-full-access.d.ts +0 -110
  190. package/dist/sandbox/platform-full-access.js +0 -198
@@ -14,10 +14,11 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
14
14
  import { KernelDb } from "../infra/database/kernel-db.js";
15
15
  import type { KernelLogger } from "../log.js";
16
16
  import { CloudPermissionSnapshots, type CloudSnapshotOutcome } from "./cloud-permission-snapshot.js";
17
+ import type { DeviceSandbox, HostGrantCeiling } from "./device-sandbox.js";
17
18
  import { type KernelReadInvocation } from "./kernel-read.js";
18
19
  import { SandboxLeases, type SandboxPathLease } from "./leases.js";
19
20
  import { LegacyRetirementStore } from "./legacy-retirement.js";
20
- import { type AppliedLimits, type EffectiveDevicePolicy } from "./modes.js";
21
+ import { type AppliedLimits, type DeviceLimits, type EffectiveDevicePolicy } from "./modes.js";
21
22
  import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
22
23
  import { PermissionFacts } from "./permission-facts.js";
23
24
  import { SandboxProviders } from "./providers.js";
@@ -273,7 +274,7 @@ export declare class SandboxService {
273
274
  /** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
274
275
  redis: Pick<Redis, "get" | "set" | "getdel">, leases: SandboxLeases,
275
276
  /** The providers (read at every call: providers are ready after the extension load). */
276
- providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
277
+ providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment" | "readDevice" | "deviceSandbox" | "deviceSandboxFacts" | "orgHostGrantCeiling">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
277
278
  /** The retirement obligations every lifecycle acquisition is gated on (8.5). */
278
279
  retirement: Pick<LegacyRetirementStore, "unresolved" | "hasUnresolved" | "settleRebooted" | "scanUntilStable" | "frozen" | "frozenAt" | "quarantine" | "noteFailure" | "resolveDestroyed" | "resolveCancelled" | "membersOf" | "recordDestruction" | "destructionRecorded">,
279
280
  /** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
@@ -307,15 +308,19 @@ export declare class SandboxService {
307
308
  orgId: string;
308
309
  deviceId?: string;
309
310
  }): Promise<EffectiveDevicePolicy>;
311
+ /** The device's per-call host grant ceiling (`PermissionFacts.readDevice`). */
312
+ hostGrantCeiling(device: {
313
+ orgId: string;
314
+ deviceId: string;
315
+ }): Promise<HostGrantCeiling>;
310
316
  /** The device's source (`local` for a connected machine, else `cloud`); cloud when unknown. */
311
317
  private deviceSource;
312
318
  /**
313
319
  * The device's effective sandbox limits (spec §8.4; auto mode spec §4.2): the deployment's
314
320
  * `sandbox.limits` resources, cpu / memory per the super admin's org override (C19 / Ruling
315
- * M16), the effective mode and the network ({@link devicePolicy}). A local device always gets the
316
- * sandbox-mode allowlist: its device intersects it with its own list in sandbox mode and ignores
317
- * it in auto mode. `opts.policy` / `opts.source`: what the caller already read (avoids the
318
- * policy and source queries).
321
+ * M16), the effective mode and the device sandbox network ({@link devicePolicy}), for a local
322
+ * device too: the machine intersects it with its owner's ceiling. `opts.policy` / `opts.source`:
323
+ * what the caller already read (avoids the policy and source queries).
319
324
  */
320
325
  deviceLimits(device: {
321
326
  orgId: string;
@@ -323,13 +328,26 @@ export declare class SandboxService {
323
328
  }, opts?: {
324
329
  policy?: EffectiveDevicePolicy;
325
330
  source?: "cloud" | "local";
326
- }): Promise<SandboxLimits>;
331
+ }): Promise<DeviceLimits>;
327
332
  /**
328
- * The org's sandbox-mode limits ({@link deviceLimits} with the sandbox-mode allowlist and mode
329
- * `sandbox`): what a local device's sandbox mode may reach at most, so what a network grant,
330
- * approval or request is checked against.
333
+ * The org's limits for a standing network grant (a scheduled task's grant, a network approval):
334
+ * {@link deviceLimits} with the org's per-call host ceiling as an allowlist (`hostGrantCeiling`
335
+ * with no device). Where that ceiling is bounded by the kernel only (`any`, which an allowlist
336
+ * cannot carry with its exclusions), the org's effective hosts: a standing grant never reaches
337
+ * past what the org lists. A device's own layers narrow it further at each exec.
331
338
  */
332
339
  ceilingLimits(orgId: string): Promise<SandboxLimits>;
340
+ /**
341
+ * Why a per-call host grant for each host is unavailable on the device, naming who can add it
342
+ * (`hostGrantRefusal`; null: grantable): a network ask is made only for a grantable host.
343
+ */
344
+ hostRefusal(device: {
345
+ orgId: string;
346
+ deviceId: string;
347
+ }): Promise<{
348
+ refusal: (host: string) => string | null;
349
+ box: DeviceSandbox;
350
+ }>;
333
351
  /**
334
352
  * The limits state of a device's instance for its page (auto mode spec §4.2), read without a
335
353
  * lease: `applied` is what the instance or file system was made with or updated to (null:
@@ -354,7 +372,7 @@ export declare class SandboxService {
354
372
  private fsBound;
355
373
  /**
356
374
  * Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
357
- * cloud instance whose recorded mode or network kind differs, or whose recorded limits are more
375
+ * cloud instance whose recorded network kind differs (never the mode alone), or whose recorded limits are more
358
376
  * permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
359
377
  * widening still reaches instances created afterwards), unless only a file reset could apply it
360
378
  * ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { posix } from "node:path";
11
- import { DEFAULT_SANDBOX_ROOTS, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, parseSandboxBrowseScope, parseSandboxExecutionRef, parseSandboxOperationScope, parseSandboxPreparationScope, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
11
+ import { isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, parseSandboxBrowseScope, parseSandboxExecutionRef, parseSandboxOperationScope, parseSandboxPreparationScope, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
12
12
  import { runOutsideTransaction } from "../infra/database/transaction-host.js";
13
13
  import { createHeldOperations, createLegacyHeldProvider, withKernelGeneration, } from "./held-operations.js";
14
14
  import { SandboxOperationAuthority } from "./operation-authority.js";
@@ -43,7 +43,7 @@ import { readSandboxLimitOverride } from "../identity/settings.js";
43
43
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
44
44
  import { KernelDb } from "../infra/database/kernel-db.js";
45
45
  import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
46
- import { effectiveSandboxLimits } from "../orgs/settings.service.js";
46
+ import { effectiveSandboxLimits, readOrgSettings } from "../orgs/settings.service.js";
47
47
  import { isStorageError } from "../runtime/permission-context-errors.js";
48
48
  import { canonicalJson } from "../tools/canonical-json.js";
49
49
  import { attachmentsDir } from "./attachments-path.js";
@@ -52,8 +52,8 @@ import { isKernelReadMethod, KernelReadNotAdmitted, KernelReadUnsupported, } fro
52
52
  import { SandboxLeases, SandboxLockLostError, sandboxBusy, } from "./leases.js";
53
53
  import { isCloudProvider, LegacyRetirementStore } from "./legacy-retirement.js";
54
54
  import { ManagedDeviceContextFailed } from "./managed-device-context.js";
55
- import { appliedOf, appliedWider, instanceLimitsJson, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
56
- import { PermissionFacts } from "./permission-facts.js";
55
+ import { appliedOf, appliedWider, instanceLimitsJson, orgEffectiveHosts, providerLimits, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
56
+ import { networkOfSandbox, PermissionFacts } from "./permission-facts.js";
57
57
  import { cloudReportOwed, cloudSupportOf } from "./permission-runtime-reports.js";
58
58
  import { isInternalProvider, LOCAL_PROVIDER, providerForDevice, SandboxProviders, } from "./providers.js";
59
59
  import { isDeviceRequestNotSent } from "./request-not-sent.js";
@@ -202,16 +202,16 @@ export function sandboxConfigWarnings(cfg, providerPlugin) {
202
202
  if (pc?.refuseOpenNetwork === true) {
203
203
  out.push({
204
204
  level: "warn",
205
- message: `extensionConfig."${providerPlugin}".refuseOpenNetwork is true: the ${providerPlugin} plugin refuses cloud devices on the open public network, which every device in auto mode and every sandbox-mode device of an organization whose cloudNetwork is open (the default) uses; set refuseOpenNetwork to false, or turn Full permission off (devices.fullAccess) and have every organization switch its cloudNetwork to the allowlist`,
205
+ message: `extensionConfig."${providerPlugin}".refuseOpenNetwork is true: the ${providerPlugin} plugin refuses cloud devices on the open public network, which every device uses whose network is open (devices.network.default, open by default, and an organization's deviceNetwork); set refuseOpenNetwork to false, or set devices.network.ceiling to allowlist`,
206
206
  });
207
207
  }
208
208
  }
209
209
  if (cfg.sandbox.limits.orgHosts === "within" &&
210
210
  cfg.sandbox.limits.egress !== "none" &&
211
- cfg.devices?.fullAccess !== "off") {
211
+ cfg.devices?.network?.ceiling !== "allowlist") {
212
212
  out.push({
213
213
  level: "warn",
214
- message: "sandbox.limits.orgHosts is within but devices.fullAccess is not off: the platform allowlist limits restricted execution only; devices on Full permission (allowed by default) still reach the open public network. Set devices.fullAccess to off (or turn Full permission off in the admin console) for a hard ceiling",
214
+ message: "sandbox.limits.orgHosts is within but devices.network.ceiling is not allowlist: the platform allowlist limits the hosts of the allowlist only; devices on the open network (the default) still reach any public host. Set devices.network.ceiling to allowlist (or in the admin console) for a hard ceiling",
215
215
  });
216
216
  }
217
217
  const run = cfg.runtime.maxRunSeconds;
@@ -379,6 +379,10 @@ let SandboxService = class SandboxService {
379
379
  async devicePolicy(device) {
380
380
  return this.facts.devicePolicy(device);
381
381
  }
382
+ /** The device's per-call host grant ceiling (`PermissionFacts.readDevice`). */
383
+ async hostGrantCeiling(device) {
384
+ return (await this.facts.readDevice(device.orgId, device.deviceId)).hostCeiling;
385
+ }
382
386
  /** The device's source (`local` for a connected machine, else `cloud`); cloud when unknown. */
383
387
  async deviceSource(device) {
384
388
  if (device.deviceId === undefined)
@@ -394,10 +398,9 @@ let SandboxService = class SandboxService {
394
398
  /**
395
399
  * The device's effective sandbox limits (spec §8.4; auto mode spec §4.2): the deployment's
396
400
  * `sandbox.limits` resources, cpu / memory per the super admin's org override (C19 / Ruling
397
- * M16), the effective mode and the network ({@link devicePolicy}). A local device always gets the
398
- * sandbox-mode allowlist: its device intersects it with its own list in sandbox mode and ignores
399
- * it in auto mode. `opts.policy` / `opts.source`: what the caller already read (avoids the
400
- * policy and source queries).
401
+ * M16), the effective mode and the device sandbox network ({@link devicePolicy}), for a local
402
+ * device too: the machine intersects it with its owner's ceiling. `opts.policy` / `opts.source`:
403
+ * what the caller already read (avoids the policy and source queries).
401
404
  */
402
405
  async deviceLimits(device, opts = {}) {
403
406
  const cfg = this.config.get().sandbox;
@@ -407,8 +410,10 @@ let SandboxService = class SandboxService {
407
410
  opts.source ?? this.deviceSource(device),
408
411
  ]);
409
412
  const local = source === "local";
410
- const network = local
411
- ? { kind: "allowlist", hosts: [...policy.localAllowedDomains] }
413
+ // a local device's commands carry its device sandbox network (under the machine's current
414
+ // runtime report, as admission reads it); the machine intersects it with its owner's ceiling
415
+ const network = local && device.deviceId !== undefined
416
+ ? networkOfSandbox(await this.facts.deviceSandbox(device.orgId, device.deviceId))
412
417
  : policy.network;
413
418
  return effectiveSandboxLimits({
414
419
  cpu: cfg.limits.cpu,
@@ -421,24 +426,37 @@ let SandboxService = class SandboxService {
421
426
  }, override);
422
427
  }
423
428
  /**
424
- * The org's sandbox-mode limits ({@link deviceLimits} with the sandbox-mode allowlist and mode
425
- * `sandbox`): what a local device's sandbox mode may reach at most, so what a network grant,
426
- * approval or request is checked against.
429
+ * The org's limits for a standing network grant (a scheduled task's grant, a network approval):
430
+ * {@link deviceLimits} with the org's per-call host ceiling as an allowlist (`hostGrantCeiling`
431
+ * with no device). Where that ceiling is bounded by the kernel only (`any`, which an allowlist
432
+ * cannot carry with its exclusions), the org's effective hosts: a standing grant never reaches
433
+ * past what the org lists. A device's own layers narrow it further at each exec.
427
434
  */
428
435
  async ceilingLimits(orgId) {
429
- const [policy, override] = await Promise.all([
430
- this.devicePolicy({ orgId }),
436
+ const [ceiling, override, { deviceNetwork: org }] = await Promise.all([
437
+ this.facts.orgHostGrantCeiling(orgId),
431
438
  readSandboxLimitOverride(this.db.db, orgId),
439
+ readOrgSettings(this.db.db, orgId),
432
440
  ]);
433
441
  const cfg = this.config.get().sandbox;
434
442
  return effectiveSandboxLimits({
435
443
  cpu: cfg.limits.cpu,
436
444
  memoryMb: cfg.limits.memoryMb,
437
445
  diskMb: cfg.limits.diskMb,
438
- mode: "sandbox",
439
- network: { kind: "allowlist", hosts: [...policy.localAllowedDomains] },
446
+ network: {
447
+ kind: "allowlist",
448
+ hosts: ceiling.kind === "any" ? orgEffectiveHosts(cfg.limits, org) : [...ceiling.hosts],
449
+ },
440
450
  }, override);
441
451
  }
452
+ /**
453
+ * Why a per-call host grant for each host is unavailable on the device, naming who can add it
454
+ * (`hostGrantRefusal`; null: grantable): a network ask is made only for a grantable host.
455
+ */
456
+ async hostRefusal(device) {
457
+ const facts = await this.facts.deviceSandboxFacts(device.orgId, device.deviceId);
458
+ return { refusal: facts.refusal, box: facts.box };
459
+ }
442
460
  /**
443
461
  * The limits state of a device's instance for its page (auto mode spec §4.2), read without a
444
462
  * lease: `applied` is what the instance or file system was made with or updated to (null:
@@ -490,7 +508,7 @@ let SandboxService = class SandboxService {
490
508
  }
491
509
  /**
492
510
  * Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
493
- * cloud instance whose recorded mode or network kind differs, or whose recorded limits are more
511
+ * cloud instance whose recorded network kind differs (never the mode alone), or whose recorded limits are more
494
512
  * permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
495
513
  * widening still reaches instances created afterwards), unless only a file reset could apply it
496
514
  * ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
@@ -1983,7 +2001,7 @@ let SandboxService = class SandboxService {
1983
2001
  // suspended: a failure is revoked again on the next resume)
1984
2002
  if (suspended)
1985
2003
  await this.revokeIncarnation(deviceId, { provider: p.plugin, generation: String(row.created_at.getTime()) }, handle, p, sig, false);
1986
- answer = await update(handle, want, sig);
2004
+ answer = await update(handle, providerLimits(want), sig);
1987
2005
  }
1988
2006
  }
1989
2007
  catch (err) {
@@ -2721,11 +2739,16 @@ let SandboxService = class SandboxService {
2721
2739
  async create(ctx, p, held, row, fence, signal, want) {
2722
2740
  const id = ctx.deviceId;
2723
2741
  const name = deviceResourceName(id);
2742
+ // the roots the device's authority was last committed with; a device that never had an
2743
+ // instance has none yet (NULL), so the first commit compares the new instance's roots with
2744
+ // what the device displayed (a local machine's reported roots), not with placeholder defaults
2745
+ // a local machine never uses: its first start is no roots change (no consent reset, no revoke)
2746
+ const committedRoots = row.permission_roots ?? (row.handle ? rootsOf(row.handle) : null);
2724
2747
  await this.fenced(held, id, fence, {
2725
2748
  org_id: ctx.orgId,
2726
2749
  provider: p.plugin,
2727
2750
  handle: null,
2728
- permission_roots: JSON.stringify(row.permission_roots ?? (row.handle ? rootsOf(row.handle) : DEFAULT_SANDBOX_ROOTS)),
2751
+ permission_roots: committedRoots === null ? null : JSON.stringify(committedRoots),
2729
2752
  status: "creating",
2730
2753
  last_used_at: sql `now()`,
2731
2754
  running_since: null,
@@ -2735,13 +2758,15 @@ let SandboxService = class SandboxService {
2735
2758
  });
2736
2759
  // the device's effective limits apply at creation (a changed mode or network kind is applied
2737
2760
  // on use, see applyLimits; other changes reach only instances created afterwards)
2738
- const limits = want ??
2761
+ const wanted = want ??
2739
2762
  (await this.deviceLimits(ctx, {
2740
2763
  source: p.plugin === LOCAL_PROVIDER ? "local" : "cloud",
2741
2764
  }));
2742
2765
  // the record says what is in force: a provider whose limits are fixed at its file system
2743
2766
  // records them with the file system, any other with the instance (spec §7.1)
2744
- const record = instanceLimitsJson(appliedOf(limits));
2767
+ const record = instanceLimitsJson(appliedOf(wanted));
2768
+ // the provider gets resources and the outer network only
2769
+ const limits = providerLimits(wanted);
2745
2770
  const atFileSystem = p.impl.limitsApplyAt === "fileSystem";
2746
2771
  const cfg = this.config.get().sandbox;
2747
2772
  let fs = row.fs_status === "ready" && (row.provider === null || row.provider === p.plugin)
@@ -2841,7 +2866,7 @@ let SandboxService = class SandboxService {
2841
2866
  let gone = false;
2842
2867
  if (p.impl.update) {
2843
2868
  try {
2844
- if ((await p.impl.update(handle, want, signal)) === "updated") {
2869
+ if ((await p.impl.update(handle, providerLimits(want), signal)) === "updated") {
2845
2870
  await this.fenced(held, id, fence, { instance_limits: instanceLimitsJson(target) });
2846
2871
  this.log.info("sandbox instance limits updated", facts);
2847
2872
  return null;
@@ -25,7 +25,7 @@ import { SandboxService } from "../sandbox/sandbox.service.js";
25
25
  import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
26
26
  import { StorageService } from "../storage/storage.service.js";
27
27
  import { BUILTIN } from "../tools/builtin-names.js";
28
- import { sessionWorkingRoot } from "../tools/builtins/sandbox/common.js";
28
+ import { sessionPathBound, sessionWorkingRoot } from "../tools/builtins/sandbox/common.js";
29
29
  import { findSkillVersion, PROJECT_DIR_DIGEST, ProjectSkillReadError, readProjectSkill, readSkillFile, SkillIntegrityError, } from "../tools/builtins/skill-load.js";
30
30
  import { invocationOf, resolveSkills } from "./catalog.js";
31
31
  import { skillFileStore } from "./usable.js";
@@ -429,7 +429,8 @@ let SkillInvoker = class SkillInvoker {
429
429
  actor: { accountId: a.accountId, conversationId: a.conversationId },
430
430
  }, (h, p, info, signal) => readProjectSkill({
431
431
  deviceId,
432
- mode,
432
+ // the legacy route (gate off): the fixed roots unless the device runs in auto mode
433
+ pathBound: sessionPathBound(false, mode),
433
434
  h,
434
435
  roots: info.roots,
435
436
  // the working root a tool call of this conversation would get (one rule)
@@ -0,0 +1,51 @@
1
+ import { KernelDb } from "../infra/database/kernel-db.js";
2
+ import { LockService } from "../infra/lock/lock.service.js";
3
+ import type { OutboxService } from "../infra/outbox/outbox.service.js";
4
+ import { StorageService } from "../storage/storage.service.js";
5
+ import type { PlatformIconPurpose } from "./platform-icon.schemas.js";
6
+ /** The object key of an icon, relative to the kernel's `deployment/` prefix. */
7
+ export declare const platformIconKey: (purpose: PlatformIconPurpose, sha256: string) => string;
8
+ /** The `LockService` key of a purpose's icon writes and deletions (no `:`). */
9
+ export declare const platformIconLockKey: (purpose: PlatformIconPurpose) => string;
10
+ /** How long a write or the deletion job holds the purpose's lock without renewal, and waits for it. */
11
+ export declare const PLATFORM_ICON_LOCK: {
12
+ readonly ttlMs: 30000;
13
+ readonly waitMs: 10000;
14
+ };
15
+ /** The maintenance job that deletes one icon object no row names. */
16
+ export declare const PLATFORM_ICON_DELETE_JOB = "platform-icon-delete";
17
+ /** Outbox id of the deletion a replace or clear owes for the object the row stopped naming. */
18
+ export declare const platformIconDeleteJobId: (purpose: PlatformIconPurpose, sha256: string) => string;
19
+ /** Outbox id of the delayed check an upload owes for its own object before writing it. */
20
+ export declare const platformIconOrphanJobId: (purpose: PlatformIconPurpose, sha256: string) => string;
21
+ /** How long after an upload starts its orphan check runs (the upload is long done by then). */
22
+ export declare const PLATFORM_ICON_ORPHAN_DELAY_MS: number;
23
+ /** The data of a {@link PLATFORM_ICON_DELETE_JOB}. */
24
+ export interface PlatformIconDeleteData {
25
+ purpose: PlatformIconPurpose;
26
+ objectKey: string;
27
+ }
28
+ /**
29
+ * Owes the deletion of a purpose's object in the caller's transaction: at once (`runAt` absent,
30
+ * a replace or clear) or later (an upload's orphan check, under its own id).
31
+ */
32
+ export declare function owePlatformIconDelete(outbox: Pick<OutboxService, "add">, purpose: PlatformIconPurpose, sha256: string, opts?: {
33
+ orphanCheck?: boolean;
34
+ }): Promise<void>;
35
+ /**
36
+ * Runs a {@link PLATFORM_ICON_DELETE_JOB} (the maintenance processor dispatches it here). Under
37
+ * the purpose's lock it deletes the object unless the purpose's row names it; delivered twice it
38
+ * is harmless (deleting a missing object is a no-op). A lock it cannot take in time throws, and
39
+ * BullMQ retries the job.
40
+ */
41
+ export declare class PlatformIconObjects {
42
+ private readonly db;
43
+ private readonly locks;
44
+ private readonly storage;
45
+ constructor(db: KernelDb, locks: LockService, storage: Pick<StorageService, "deployment">);
46
+ /** Deletes the object unless the row names it; see the class comment. */
47
+ deleteObject(data: PlatformIconDeleteData): Promise<void>;
48
+ }
49
+ /** {@link PlatformIconObjects} for the maintenance worker (storage, the database and locks only). */
50
+ export declare class PlatformIconObjectsModule {
51
+ }
@@ -0,0 +1,113 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable, Module } from "@nestjs/common";
11
+ import { KernelDb } from "../infra/database/kernel-db.js";
12
+ import { LockService } from "../infra/lock/lock.service.js";
13
+ import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
14
+ import { StorageModule } from "../storage/storage.module.js";
15
+ import { StorageService } from "../storage/storage.service.js";
16
+ /**
17
+ * Platform icon objects in object storage (mobile layout spec §10.2.1): the icon of a purpose with
18
+ * SHA-256 `h` is `platform-icons/<purpose>-<h>.<png|svg>` under the kernel's `deployment/` prefix,
19
+ * so the same bytes always land on the same key. An upload writes its object before the row that
20
+ * names it; an object no row names is deleted through the outbox ({@link PLATFORM_ICON_DELETE_JOB}):
21
+ * the upload owes a delayed check of its own object first (an upload that never commits leaves no
22
+ * orphan), and a replace or clear owes the deletion of the object the row stops naming.
23
+ *
24
+ * Because keys are content addressed, a later upload of the same bytes may name a key again after
25
+ * its deletion was owed: uploads, clears and the job hold {@link platformIconLockKey} for the
26
+ * purpose, so the job's "no row names it" check and its delete never interleave with an upload
27
+ * between its object write and its commit.
28
+ */
29
+ /** The file extension of a purpose's object (its type is fixed by the purpose). */
30
+ const extensionOf = (purpose) => purpose === "favicon" ? "svg" : "png";
31
+ /** The object key of an icon, relative to the kernel's `deployment/` prefix. */
32
+ export const platformIconKey = (purpose, sha256) => `platform-icons/${purpose}-${sha256}.${extensionOf(purpose)}`;
33
+ /** True when `key` is one {@link platformIconKey} makes for `purpose`. */
34
+ const isIconKeyOf = (purpose, key) => new RegExp(`^platform-icons/${purpose}-[0-9a-f]{64}\\.${extensionOf(purpose)}$`).test(key);
35
+ /** The `LockService` key of a purpose's icon writes and deletions (no `:`). */
36
+ export const platformIconLockKey = (purpose) => `platform-icon-${purpose}`;
37
+ /** How long a write or the deletion job holds the purpose's lock without renewal, and waits for it. */
38
+ export const PLATFORM_ICON_LOCK = { ttlMs: 30_000, waitMs: 10_000 };
39
+ /** The maintenance job that deletes one icon object no row names. */
40
+ export const PLATFORM_ICON_DELETE_JOB = "platform-icon-delete";
41
+ /** Outbox id of the deletion a replace or clear owes for the object the row stopped naming. */
42
+ export const platformIconDeleteJobId = (purpose, sha256) => `platform-icon-delete-${purpose}-${sha256}`;
43
+ /** Outbox id of the delayed check an upload owes for its own object before writing it. */
44
+ export const platformIconOrphanJobId = (purpose, sha256) => `platform-icon-orphan-${purpose}-${sha256}`;
45
+ /** How long after an upload starts its orphan check runs (the upload is long done by then). */
46
+ export const PLATFORM_ICON_ORPHAN_DELAY_MS = 10 * 60 * 1000;
47
+ /**
48
+ * Owes the deletion of a purpose's object in the caller's transaction: at once (`runAt` absent,
49
+ * a replace or clear) or later (an upload's orphan check, under its own id).
50
+ */
51
+ export async function owePlatformIconDelete(outbox, purpose, sha256, opts = {}) {
52
+ const data = { purpose, objectKey: platformIconKey(purpose, sha256) };
53
+ await outbox.add({
54
+ queue: MAINTENANCE_QUEUE_NAME,
55
+ name: PLATFORM_ICON_DELETE_JOB,
56
+ jobId: opts.orphanCheck
57
+ ? platformIconOrphanJobId(purpose, sha256)
58
+ : platformIconDeleteJobId(purpose, sha256),
59
+ data,
60
+ ...(opts.orphanCheck && { runAt: new Date(Date.now() + PLATFORM_ICON_ORPHAN_DELAY_MS) }),
61
+ });
62
+ }
63
+ /**
64
+ * Runs a {@link PLATFORM_ICON_DELETE_JOB} (the maintenance processor dispatches it here). Under
65
+ * the purpose's lock it deletes the object unless the purpose's row names it; delivered twice it
66
+ * is harmless (deleting a missing object is a no-op). A lock it cannot take in time throws, and
67
+ * BullMQ retries the job.
68
+ */
69
+ let PlatformIconObjects = class PlatformIconObjects {
70
+ db;
71
+ locks;
72
+ storage;
73
+ constructor(db, locks, storage) {
74
+ this.db = db;
75
+ this.locks = locks;
76
+ this.storage = storage;
77
+ }
78
+ /** Deletes the object unless the row names it; see the class comment. */
79
+ async deleteObject(data) {
80
+ if (!isIconKeyOf(data.purpose, data.objectKey)) {
81
+ // never delete anything outside the purpose's own icon keys, whatever the job data says
82
+ throw new Error(`platform-icon-delete: unexpected object key for ${data.purpose}`);
83
+ }
84
+ await this.locks.run(platformIconLockKey(data.purpose), PLATFORM_ICON_LOCK, async () => {
85
+ const row = await this.db
86
+ .selectFrom("platform_icons")
87
+ .select("object_key")
88
+ .where("purpose", "=", data.purpose)
89
+ .executeTakeFirst();
90
+ if (row?.object_key === data.objectKey)
91
+ return;
92
+ await this.storage.deployment().delete(data.objectKey);
93
+ });
94
+ }
95
+ };
96
+ PlatformIconObjects = __decorate([
97
+ Injectable(),
98
+ __param(0, Inject(KernelDb)),
99
+ __param(1, Inject(LockService)),
100
+ __param(2, Inject(StorageService))
101
+ ], PlatformIconObjects);
102
+ export { PlatformIconObjects };
103
+ /** {@link PlatformIconObjects} for the maintenance worker (storage, the database and locks only). */
104
+ let PlatformIconObjectsModule = class PlatformIconObjectsModule {
105
+ };
106
+ PlatformIconObjectsModule = __decorate([
107
+ Module({
108
+ imports: [StorageModule],
109
+ providers: [PlatformIconObjects],
110
+ exports: [PlatformIconObjects],
111
+ })
112
+ ], PlatformIconObjectsModule);
113
+ export { PlatformIconObjectsModule };
@@ -0,0 +1,17 @@
1
+ import type { FastifyReply } from "fastify";
2
+ import type { z } from "zod";
3
+ import { PlatformIconParams, PlatformIconQuery } from "./platform-icon.schemas.js";
4
+ import { PlatformIconService } from "./platform-icon.service.js";
5
+ /**
6
+ * The platform icon's bytes (mobile layout spec §10.2.1), public: the PWA manifest, the favicons
7
+ * and native clients read it before sign-in, and an icon is not sensitive. `?v=<sha256>` (the URL
8
+ * the settings list) is cached as immutable; without `v` the response is revalidated; a `v` that is
9
+ * not the current hash, or a purpose with no upload, is 404 `platform_icon.not_found` (the web then
10
+ * uses its built-in icon). The type is fixed by the purpose, with `nosniff`; the SVG favicon also
11
+ * gets a sandbox CSP, so opened directly it runs nothing and loads nothing.
12
+ */
13
+ export declare class PlatformIconPublicController {
14
+ private readonly icons;
15
+ constructor(icons: PlatformIconService);
16
+ icon({ purpose }: z.infer<typeof PlatformIconParams>, { v }: z.infer<typeof PlatformIconQuery>, reply: FastifyReply): Promise<void>;
17
+ }
@@ -0,0 +1,58 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Controller, Get, Inject, Res } from "@nestjs/common";
11
+ import { Public } from "../identity/principal.js";
12
+ import { createZodDto } from "../infra/validation/create-zod-dto.js";
13
+ import { ZParam, ZQuery } from "../infra/validation/zod-params.js";
14
+ import { PlatformIconParams, PlatformIconQuery } from "./platform-icon.schemas.js";
15
+ import { PlatformIconService } from "./platform-icon.service.js";
16
+ class PlatformIconPublicParamsDto extends createZodDto(PlatformIconParams, "PlatformIconPublicParams") {
17
+ }
18
+ class PlatformIconQueryDto extends createZodDto(PlatformIconQuery, "PlatformIconQuery") {
19
+ }
20
+ /** With the current hash in `v` the URL's bytes never change. */
21
+ const IMMUTABLE = "public, max-age=31536000, immutable";
22
+ /**
23
+ * The platform icon's bytes (mobile layout spec §10.2.1), public: the PWA manifest, the favicons
24
+ * and native clients read it before sign-in, and an icon is not sensitive. `?v=<sha256>` (the URL
25
+ * the settings list) is cached as immutable; without `v` the response is revalidated; a `v` that is
26
+ * not the current hash, or a purpose with no upload, is 404 `platform_icon.not_found` (the web then
27
+ * uses its built-in icon). The type is fixed by the purpose, with `nosniff`; the SVG favicon also
28
+ * gets a sandbox CSP, so opened directly it runs nothing and loads nothing.
29
+ */
30
+ let PlatformIconPublicController = class PlatformIconPublicController {
31
+ icons;
32
+ constructor(icons) {
33
+ this.icons = icons;
34
+ }
35
+ async icon({ purpose }, { v }, reply) {
36
+ const icon = await this.icons.read(purpose, v);
37
+ reply
38
+ .header("content-type", icon.contentType)
39
+ .header("x-content-type-options", "nosniff")
40
+ .header("cache-control", icon.immutable ? IMMUTABLE : "no-cache");
41
+ if (icon.contentType === "image/svg+xml") {
42
+ reply.header("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox");
43
+ }
44
+ await reply.send(Buffer.from(icon.bytes.buffer, icon.bytes.byteOffset, icon.bytes.byteLength));
45
+ }
46
+ };
47
+ __decorate([
48
+ Public(),
49
+ Get(":purpose"),
50
+ __param(0, ZParam(PlatformIconPublicParamsDto)),
51
+ __param(1, ZQuery(PlatformIconQueryDto)),
52
+ __param(2, Res())
53
+ ], PlatformIconPublicController.prototype, "icon", null);
54
+ PlatformIconPublicController = __decorate([
55
+ Controller("api/v1/platform/icon"),
56
+ __param(0, Inject(PlatformIconService))
57
+ ], PlatformIconPublicController);
58
+ export { PlatformIconPublicController };
@@ -0,0 +1,22 @@
1
+ import type { z } from "zod";
2
+ import { type Principal } from "../identity/principal.js";
3
+ import { PlatformIconBody, PlatformIconParams, type PlatformIconView } from "./platform-icon.schemas.js";
4
+ import { PlatformIconService } from "./platform-icon.service.js";
5
+ /**
6
+ * The platform icon setting (`/api/v1/admin/platform/icons*`, mobile layout spec §10.2.1): the
7
+ * app icon, its maskable variant and the SVG favicon the PWA manifest, the favicons and native
8
+ * clients use. Super admins only (one installed app per deployment); service tokens 403. The
9
+ * upload is JSON base64 so the Platform tool mirrors it (`admin.set-icon`).
10
+ */
11
+ export declare class PlatformIconController {
12
+ private readonly icons;
13
+ constructor(icons: PlatformIconService);
14
+ /** `{ icons }`: every uploaded icon with its public URL; a purpose not listed uses the default. */
15
+ list(): Promise<{
16
+ icons: PlatformIconView[];
17
+ }>;
18
+ /** Uploads the icon of a purpose (PNG 512 × 512 for app / maskable, SVG for favicon, ≤ 1 MiB). */
19
+ set(principal: Principal, { purpose }: z.infer<typeof PlatformIconParams>, body: z.infer<typeof PlatformIconBody>): Promise<PlatformIconView>;
20
+ /** Restores the built-in icon of a purpose; 204 also when none was uploaded. */
21
+ clear(principal: Principal, { purpose }: z.infer<typeof PlatformIconParams>): Promise<void>;
22
+ }
@@ -0,0 +1,65 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Controller, Delete, Get, HttpCode, Inject, Put } from "@nestjs/common";
11
+ import { CurrentPrincipal, SuperAdmin } from "../identity/principal.js";
12
+ import { writeActorOf } from "../identity/write-actor.js";
13
+ import { createZodDto } from "../infra/validation/create-zod-dto.js";
14
+ import { ZBody, ZParam } from "../infra/validation/zod-params.js";
15
+ import { PlatformIconBody, PlatformIconParams, } from "./platform-icon.schemas.js";
16
+ import { PlatformIconService } from "./platform-icon.service.js";
17
+ class PlatformIconParamsDto extends createZodDto(PlatformIconParams, "PlatformIconParams") {
18
+ }
19
+ class PlatformIconBodyDto extends createZodDto(PlatformIconBody, "PlatformIconBody") {
20
+ }
21
+ /**
22
+ * The platform icon setting (`/api/v1/admin/platform/icons*`, mobile layout spec §10.2.1): the
23
+ * app icon, its maskable variant and the SVG favicon the PWA manifest, the favicons and native
24
+ * clients use. Super admins only (one installed app per deployment); service tokens 403. The
25
+ * upload is JSON base64 so the Platform tool mirrors it (`admin.set-icon`).
26
+ */
27
+ let PlatformIconController = class PlatformIconController {
28
+ icons;
29
+ constructor(icons) {
30
+ this.icons = icons;
31
+ }
32
+ /** `{ icons }`: every uploaded icon with its public URL; a purpose not listed uses the default. */
33
+ list() {
34
+ return this.icons.list();
35
+ }
36
+ /** Uploads the icon of a purpose (PNG 512 × 512 for app / maskable, SVG for favicon, ≤ 1 MiB). */
37
+ set(principal, { purpose }, body) {
38
+ return this.icons.set(purpose, body.contentType, body.dataBase64, writeActorOf(principal));
39
+ }
40
+ /** Restores the built-in icon of a purpose; 204 also when none was uploaded. */
41
+ async clear(principal, { purpose }) {
42
+ await this.icons.clear(purpose, writeActorOf(principal));
43
+ }
44
+ };
45
+ __decorate([
46
+ Get()
47
+ ], PlatformIconController.prototype, "list", null);
48
+ __decorate([
49
+ Put(":purpose"),
50
+ __param(0, CurrentPrincipal()),
51
+ __param(1, ZParam(PlatformIconParamsDto)),
52
+ __param(2, ZBody(PlatformIconBodyDto))
53
+ ], PlatformIconController.prototype, "set", null);
54
+ __decorate([
55
+ Delete(":purpose"),
56
+ HttpCode(204),
57
+ __param(0, CurrentPrincipal()),
58
+ __param(1, ZParam(PlatformIconParamsDto))
59
+ ], PlatformIconController.prototype, "clear", null);
60
+ PlatformIconController = __decorate([
61
+ Controller("api/v1/admin/platform/icons"),
62
+ SuperAdmin(),
63
+ __param(0, Inject(PlatformIconService))
64
+ ], PlatformIconController);
65
+ export { PlatformIconController };