@capybara-hq/kernel 0.1.0-rc.60 → 0.1.0-rc.61

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 (98) hide show
  1. package/dist/admin/admin.module.js +3 -0
  2. package/dist/admin/extensions.controller.d.ts +32 -1
  3. package/dist/admin/extensions.controller.js +72 -3
  4. package/dist/admin/health.service.d.ts +2 -2
  5. package/dist/admin/health.service.js +6 -2
  6. package/dist/catalog/marketplaces.service.d.ts +1 -1
  7. package/dist/config/schema.d.ts +6 -0
  8. package/dist/config/schema.js +12 -0
  9. package/dist/conversations/event-log.d.ts +12 -3
  10. package/dist/conversations/event-log.js +17 -5
  11. package/dist/ctx/secrets.d.ts +10 -5
  12. package/dist/ctx/secrets.js +16 -5
  13. package/dist/db/kernel-schema.d.ts +34 -2
  14. package/dist/errors.d.ts +7 -0
  15. package/dist/errors.js +7 -0
  16. package/dist/extensions/config-hash.d.ts +2 -0
  17. package/dist/extensions/config-hash.js +1 -1
  18. package/dist/extensions/guide-places.d.ts +5 -1
  19. package/dist/extensions/guide-places.js +9 -2
  20. package/dist/extensions/permission-view.d.ts +6 -4
  21. package/dist/extensions/permission-view.js +6 -3
  22. package/dist/extensions/plugin-guides.d.ts +20 -0
  23. package/dist/extensions/plugin-guides.js +49 -1
  24. package/dist/extensions/registry.js +1 -0
  25. package/dist/http/api.module.js +7 -0
  26. package/dist/http/meta.controller.d.ts +7 -1
  27. package/dist/http/meta.controller.js +14 -3
  28. package/dist/identity/accounts.js +5 -0
  29. package/dist/identity/sessions.d.ts +7 -0
  30. package/dist/identity/sessions.js +26 -4
  31. package/dist/inbox/platform-inbox.service.d.ts +21 -11
  32. package/dist/inbox/platform-inbox.service.js +27 -12
  33. package/dist/inbox/platform-notices.d.ts +15 -1
  34. package/dist/inbox/platform-notices.js +20 -0
  35. package/dist/infra/config/kernel-config.service.js +2 -0
  36. package/dist/infra/outbox/registry.d.ts +36 -0
  37. package/dist/infra/outbox/registry.js +30 -0
  38. package/dist/infra/queue/queue-names.d.ts +1 -1
  39. package/dist/infra/queue/queue-names.js +1 -0
  40. package/dist/orgs/offboarding.js +3 -0
  41. package/dist/overrides.d.ts +4 -0
  42. package/dist/overrides.js +2 -0
  43. package/dist/platform/exclusions.js +15 -0
  44. package/dist/platform/ops/extensions-admin.ops.d.ts +5 -1
  45. package/dist/platform/ops/extensions-admin.ops.js +97 -2
  46. package/dist/platform/ops/inbox.ops.d.ts +1 -1
  47. package/dist/platform/ops/inbox.ops.js +17 -7
  48. package/dist/platform/ops/platform.ops.d.ts +4 -2
  49. package/dist/platform/ops/platform.ops.js +55 -3
  50. package/dist/platform/platform-ops.module.js +2 -0
  51. package/dist/platform/route-schemas.js +3 -0
  52. package/dist/push/delivery.d.ts +88 -0
  53. package/dist/push/delivery.js +269 -0
  54. package/dist/push/fanout.d.ts +29 -0
  55. package/dist/push/fanout.js +95 -0
  56. package/dist/push/jobs.d.ts +43 -0
  57. package/dist/push/jobs.js +19 -0
  58. package/dist/push/preferences.service.d.ts +18 -0
  59. package/dist/push/preferences.service.js +82 -0
  60. package/dist/push/provider-host.d.ts +34 -0
  61. package/dist/push/provider-host.js +94 -0
  62. package/dist/push/push-owed.d.ts +33 -0
  63. package/dist/push/push-owed.js +93 -0
  64. package/dist/push/push-processor.d.ts +40 -0
  65. package/dist/push/push-processor.js +114 -0
  66. package/dist/push/push.controller.d.ts +28 -0
  67. package/dist/push/push.controller.js +92 -0
  68. package/dist/push/push.module.d.ts +6 -0
  69. package/dist/push/push.module.js +29 -0
  70. package/dist/push/push.schemas.d.ts +88 -0
  71. package/dist/push/push.schemas.js +53 -0
  72. package/dist/push/recipients.d.ts +29 -0
  73. package/dist/push/recipients.js +263 -0
  74. package/dist/push/registration-cleanup.d.ts +9 -0
  75. package/dist/push/registration-cleanup.js +16 -0
  76. package/dist/push/registrations.service.d.ts +55 -0
  77. package/dist/push/registrations.service.js +254 -0
  78. package/dist/push/stale.job.d.ts +25 -0
  79. package/dist/push/stale.job.js +76 -0
  80. package/dist/push/texts.d.ts +31 -0
  81. package/dist/push/texts.js +46 -0
  82. package/dist/push/token-store.d.ts +31 -0
  83. package/dist/push/token-store.js +52 -0
  84. package/dist/push/triggers.d.ts +19 -0
  85. package/dist/push/triggers.js +30 -0
  86. package/dist/roles/worker-role.d.ts +7 -4
  87. package/dist/roles/worker-role.js +12 -5
  88. package/dist/roles/worker.module.d.ts +1 -1
  89. package/dist/roles/worker.module.js +4 -1
  90. package/dist/schedules/run-tracker.d.ts +10 -2
  91. package/dist/schedules/run-tracker.js +18 -4
  92. package/dist/setup/setup-checks.schemas.d.ts +29 -0
  93. package/dist/setup/setup-checks.schemas.js +32 -0
  94. package/dist/setup/setup-checks.service.d.ts +36 -3
  95. package/dist/setup/setup-checks.service.js +137 -29
  96. package/package.json +4 -4
  97. package/src/migrations/0172_push.sql +40 -0
  98. package/src/migrations/0173_push_auth_notice.sql +10 -0
@@ -16,6 +16,7 @@ import { IdentityModule } from "../identity/identity.module.js";
16
16
  import { InboxModule } from "../inbox/inbox.module.js";
17
17
  import { ModelsModule } from "../models/models.module.js";
18
18
  import { OrgsModule } from "../orgs/orgs.module.js";
19
+ import { PushModule } from "../push/push.module.js";
19
20
  import { ProvidersModule } from "../runtime/providers.js";
20
21
  import { RunJobsModule } from "../runtime/run-jobs.js";
21
22
  import { UsageReportModule } from "../runtime/usage-report.js";
@@ -54,6 +55,8 @@ AdminModule = __decorate([
54
55
  UsageReportModule,
55
56
  EvalsModule,
56
57
  LifecycleHooksModule,
58
+ // the push queue the overview counts
59
+ PushModule,
57
60
  // the price table of the usage aggregate
58
61
  ModelsModule,
59
62
  ],
@@ -5,8 +5,12 @@ import { type DeploymentConfigView, ExtensionDeploymentConfigService } from "../
5
5
  import { ExtensionInstalls, type PackageReview } from "../extensions/installs.js";
6
6
  import { type OrgOverrideSummary, OrgOverrides } from "../extensions/org-overrides.js";
7
7
  import type { AdminExtensionView } from "../extensions/permission-view.js";
8
+ import { PluginGuides, type RenderedSetupGuide } from "../extensions/plugin-guides.js";
8
9
  import { type Principal } from "../identity/principal.js";
9
10
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
11
+ import type { SetupCheckState } from "../setup/setup-check-registry.js";
12
+ import { DeploymentCheckPathParams, DeploymentCheckRunBody, DeploymentGuidePathParams, DeploymentGuidesPathParams, DeploymentGuidesQuery } from "../setup/setup-checks.schemas.js";
13
+ import { SetupChecksService } from "../setup/setup-checks.service.js";
10
14
  import { AdminExtensionConfigBody } from "./extensions.schemas.js";
11
15
  declare const ApproveSchema: z.ZodObject<{
12
16
  sha256: z.ZodNullable<z.ZodString>;
@@ -37,7 +41,9 @@ export declare class AdminExtensionsController {
37
41
  private readonly deploymentConfigs;
38
42
  private readonly kernelConfig;
39
43
  private readonly orgOverrides;
40
- constructor(installs: ExtensionInstalls, admin: ExtensionAdmin, ops: ExtensionAdminOps, deploymentConfigs: ExtensionDeploymentConfigService, kernelConfig: KernelConfigService, orgOverrides: OrgOverrides);
44
+ private readonly pluginGuides;
45
+ private readonly setupChecks;
46
+ constructor(installs: ExtensionInstalls, admin: ExtensionAdmin, ops: ExtensionAdminOps, deploymentConfigs: ExtensionDeploymentConfigService, kernelConfig: KernelConfigService, orgOverrides: OrgOverrides, pluginGuides: PluginGuides, setupChecks: SetupChecksService);
41
47
  /**
42
48
  * 部署上的全部插件(内置、配置声明、安装记录)及其状态、权限与快照;`drainSeconds` 为停用 / 升级时
43
49
  * 在途工具调用最多等待的秒数(`extensionHost.drainSeconds`,界面提示用)。
@@ -62,6 +68,31 @@ export declare class AdminExtensionsController {
62
68
  orgCopies({ name }: z.infer<typeof NameParams>): Promise<{
63
69
  overrides: OrgOverrideSummary[];
64
70
  }>;
71
+ /**
72
+ * The extension's `extension-deployment` setup guides (setup place of the push notifications
73
+ * plan, task C8), rendered for the platform in `locale`: the guides of that place in the latest
74
+ * version of its catalog item, admin audience, no org and no target. Empty without a catalog item
75
+ * or such a guide. Guide text never carries a config value.
76
+ */
77
+ guides({ name }: z.infer<typeof DeploymentGuidesPathParams>, q: z.infer<typeof DeploymentGuidesQuery>): Promise<{
78
+ guides: RenderedSetupGuide[];
79
+ }>;
80
+ /**
81
+ * The cached state of each check of a deployment guide (shared by every super admin); never
82
+ * runs anything. Only the fixed fields of {@link SetupCheckState} leave the kernel.
83
+ */
84
+ guideChecks(principal: Principal, params: z.infer<typeof DeploymentGuidePathParams>): Promise<{
85
+ results: Record<string, SetupCheckState>;
86
+ }>;
87
+ /**
88
+ * Runs one check of a deployment guide against the extension's platform deployment config
89
+ * unless a fresh result is cached (`force`: rerun, once per 10 s per check). The result is
90
+ * redacted by the config's secret values. 30 runs a minute per account (429 `rate_limited`),
91
+ * shared with the org check routes and the `Platform` tool.
92
+ */
93
+ runGuideCheck(principal: Principal, params: z.infer<typeof DeploymentCheckPathParams>, body: z.infer<typeof DeploymentCheckRunBody>): Promise<{
94
+ result: SetupCheckState;
95
+ }>;
65
96
  /**
66
97
  * Saves the deployment config (`values` keyed by field dot path; `null` clears, omitted keeps).
67
98
  * A field present in the startup config -> 409 `extension.config_readonly`; unknown or invalid
@@ -15,10 +15,14 @@ import { ExtensionAdmin } from "../extensions/admin-view.js";
15
15
  import { ExtensionDeploymentConfigService, } from "../extensions/deployment-config.js";
16
16
  import { ExtensionInstalls } from "../extensions/installs.js";
17
17
  import { OrgOverrides } from "../extensions/org-overrides.js";
18
+ import { PluginGuides } from "../extensions/plugin-guides.js";
18
19
  import { CurrentPrincipal, patTokenId, requireUser, SuperAdmin, } from "../identity/principal.js";
19
20
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
21
+ import { Throttled } from "../infra/throttler/throttler.guard.js";
20
22
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
21
- import { ZBody, ZParam } from "../infra/validation/zod-params.js";
23
+ import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
24
+ import { DeploymentCheckPathParams, DeploymentCheckRunBody, DeploymentGuidePathParams, DeploymentGuidesPathParams, DeploymentGuidesQuery, } from "../setup/setup-checks.schemas.js";
25
+ import { SetupChecksService } from "../setup/setup-checks.service.js";
22
26
  import { AdminExtensionConfigBody } from "./extensions.schemas.js";
23
27
  const ApproveSchema = z.object({
24
28
  /** 安装记录的包(审阅时的 sha256);配置声明的插件为 null。 */
@@ -48,6 +52,16 @@ class ExtensionNpmImportBody extends createZodDto(NpmSchema, "ExtensionNpmImport
48
52
  const NameParams = z.object({ name: z.string().min(1).max(64) });
49
53
  class AdminExtensionNameParamsDto extends createZodDto(NameParams, "AdminExtensionNameParams") {
50
54
  }
55
+ class DeploymentGuidesParamsDto extends createZodDto(DeploymentGuidesPathParams, "DeploymentGuidesPathParams") {
56
+ }
57
+ class DeploymentGuidesQueryDto extends createZodDto(DeploymentGuidesQuery, "DeploymentGuidesQuery") {
58
+ }
59
+ class DeploymentGuideParamsDto extends createZodDto(DeploymentGuidePathParams, "DeploymentGuidePathParams") {
60
+ }
61
+ class DeploymentCheckParamsDto extends createZodDto(DeploymentCheckPathParams, "DeploymentCheckPathParams") {
62
+ }
63
+ class DeploymentCheckRunBodyDto extends createZodDto(DeploymentCheckRunBody, "DeploymentCheckRunBody") {
64
+ }
51
65
  /**
52
66
  * Deployment-level extension management (`/api/v1/admin/extensions/*`, super admins): package
53
67
  * import (upload / npm, returns the review), the extension list and detail, web permission approval
@@ -62,15 +76,19 @@ let AdminExtensionsController = class AdminExtensionsController {
62
76
  deploymentConfigs;
63
77
  kernelConfig;
64
78
  orgOverrides;
79
+ pluginGuides;
80
+ setupChecks;
65
81
  constructor(installs, admin, ops, deploymentConfigs,
66
82
  // 字段名不能与路由方法同名(如 `config`):实例字段会遮住原型上的处理函数
67
- kernelConfig, orgOverrides) {
83
+ kernelConfig, orgOverrides, pluginGuides, setupChecks) {
68
84
  this.installs = installs;
69
85
  this.admin = admin;
70
86
  this.ops = ops;
71
87
  this.deploymentConfigs = deploymentConfigs;
72
88
  this.kernelConfig = kernelConfig;
73
89
  this.orgOverrides = orgOverrides;
90
+ this.pluginGuides = pluginGuides;
91
+ this.setupChecks = setupChecks;
74
92
  }
75
93
  /**
76
94
  * 部署上的全部插件(内置、配置声明、安装记录)及其状态、权限与快照;`drainSeconds` 为停用 / 升级时
@@ -102,6 +120,37 @@ let AdminExtensionsController = class AdminExtensionsController {
102
120
  async orgCopies({ name }) {
103
121
  return { overrides: await this.orgOverrides.listForPlugin(name) };
104
122
  }
123
+ /**
124
+ * The extension's `extension-deployment` setup guides (setup place of the push notifications
125
+ * plan, task C8), rendered for the platform in `locale`: the guides of that place in the latest
126
+ * version of its catalog item, admin audience, no org and no target. Empty without a catalog item
127
+ * or such a guide. Guide text never carries a config value.
128
+ */
129
+ async guides({ name }, q) {
130
+ return { guides: await this.pluginGuides.deploymentGuides(name, q) };
131
+ }
132
+ /**
133
+ * The cached state of each check of a deployment guide (shared by every super admin); never
134
+ * runs anything. Only the fixed fields of {@link SetupCheckState} leave the kernel.
135
+ */
136
+ async guideChecks(principal, params) {
137
+ const p = requireUser(principal);
138
+ return {
139
+ results: await this.setupChecks.deploymentStates(p.account.id, params.name, params.guideId),
140
+ };
141
+ }
142
+ /**
143
+ * Runs one check of a deployment guide against the extension's platform deployment config
144
+ * unless a fresh result is cached (`force`: rerun, once per 10 s per check). The result is
145
+ * redacted by the config's secret values. 30 runs a minute per account (429 `rate_limited`),
146
+ * shared with the org check routes and the `Platform` tool.
147
+ */
148
+ async runGuideCheck(principal, params, body) {
149
+ const p = requireUser(principal);
150
+ return {
151
+ result: await this.setupChecks.deploymentRun(p.account.id, params.name, params.guideId, params.checkId, body),
152
+ };
153
+ }
105
154
  /**
106
155
  * Saves the deployment config (`values` keyed by field dot path; `null` clears, omitted keeps).
107
156
  * A field present in the startup config -> 409 `extension.config_readonly`; unknown or invalid
@@ -207,6 +256,24 @@ __decorate([
207
256
  Get(":name/org-overrides"),
208
257
  __param(0, ZParam(AdminExtensionNameParamsDto))
209
258
  ], AdminExtensionsController.prototype, "orgCopies", null);
259
+ __decorate([
260
+ Get(":name/guides"),
261
+ __param(0, ZParam(DeploymentGuidesParamsDto)),
262
+ __param(1, ZQuery(DeploymentGuidesQueryDto))
263
+ ], AdminExtensionsController.prototype, "guides", null);
264
+ __decorate([
265
+ Get(":name/guides/:guideId/checks"),
266
+ __param(0, CurrentPrincipal()),
267
+ __param(1, ZParam(DeploymentGuideParamsDto))
268
+ ], AdminExtensionsController.prototype, "guideChecks", null);
269
+ __decorate([
270
+ Post(":name/guides/:guideId/checks/:checkId/run"),
271
+ HttpCode(200),
272
+ Throttled("setup-check"),
273
+ __param(0, CurrentPrincipal()),
274
+ __param(1, ZParam(DeploymentCheckParamsDto)),
275
+ __param(2, ZBody(DeploymentCheckRunBodyDto))
276
+ ], AdminExtensionsController.prototype, "runGuideCheck", null);
210
277
  __decorate([
211
278
  Put(":name/config"),
212
279
  __param(0, CurrentPrincipal()),
@@ -270,6 +337,8 @@ AdminExtensionsController = __decorate([
270
337
  __param(2, Inject(ExtensionAdminOps)),
271
338
  __param(3, Inject(ExtensionDeploymentConfigService)),
272
339
  __param(4, Inject(KernelConfigService)),
273
- __param(5, Inject(OrgOverrides))
340
+ __param(5, Inject(OrgOverrides)),
341
+ __param(6, Inject(PluginGuides)),
342
+ __param(7, Inject(SetupChecksService))
274
343
  ], AdminExtensionsController);
275
344
  export { AdminExtensionsController };
@@ -4,7 +4,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
4
4
  import { type LiveReplica, ReplicaPresence } from "../infra/presence/replica-presence.js";
5
5
  import type { KernelLogger } from "../log.js";
6
6
  /** The kernel's own queues, in the order the overview lists them (extension queues are not read). */
7
- export declare const KERNEL_QUEUE_NAMES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle"];
7
+ export declare const KERNEL_QUEUE_NAMES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver"];
8
8
  /** How long each source's reads may take before the answer marks it unavailable. */
9
9
  export declare const HEALTH_READ_TIMEOUT_MS = 3000;
10
10
  /** A live replica as the overview shows it. */
@@ -97,7 +97,7 @@ export declare class AdminHealthService {
97
97
  private readonly redis;
98
98
  private readonly log;
99
99
  private readonly queues;
100
- constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue);
100
+ constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue, push: Queue);
101
101
  read(): Promise<AdminHealth>;
102
102
  private readRedis;
103
103
  private readDb;
@@ -19,6 +19,7 @@ import { LIFECYCLE_QUEUE } from "../extensions/lifecycle-hooks.js";
19
19
  import { KernelDb } from "../infra/database/kernel-db.js";
20
20
  import { ReplicaPresence } from "../infra/presence/replica-presence.js";
21
21
  import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
22
+ import { PUSH_QUEUE } from "../push/jobs.js";
22
23
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
23
24
  import { RUN_QUEUE_NAME, SUBAGENT_RUN_QUEUE_NAME } from "../runtime/run-jobs.js";
24
25
  import { USAGE_REPORT_QUEUE } from "../runtime/usage-report-jobs.js";
@@ -35,6 +36,7 @@ export const KERNEL_QUEUE_NAMES = [
35
36
  USAGE_REPORT_QUEUE,
36
37
  EVAL_QUEUE_NAME,
37
38
  LIFECYCLE_QUEUE,
39
+ PUSH_QUEUE,
38
40
  ];
39
41
  /** How long each source's reads may take before the answer marks it unavailable. */
40
42
  export const HEALTH_READ_TIMEOUT_MS = 3_000;
@@ -62,7 +64,7 @@ let AdminHealthService = class AdminHealthService {
62
64
  redis;
63
65
  log;
64
66
  queues;
65
- constructor(presence, db, redis, log, runs, subagentRuns, channels, maintenance, pluginScope, titles, suggestions, usageReport, evals, lifecycle) {
67
+ constructor(presence, db, redis, log, runs, subagentRuns, channels, maintenance, pluginScope, titles, suggestions, usageReport, evals, lifecycle, push) {
66
68
  this.presence = presence;
67
69
  this.db = db;
68
70
  this.redis = redis;
@@ -79,6 +81,7 @@ let AdminHealthService = class AdminHealthService {
79
81
  usageReport,
80
82
  evals,
81
83
  lifecycle,
84
+ push,
82
85
  ];
83
86
  }
84
87
  async read() {
@@ -249,6 +252,7 @@ AdminHealthService = __decorate([
249
252
  __param(10, Inject(getQueueToken(PROMPT_SUGGESTION_QUEUE))),
250
253
  __param(11, Inject(getQueueToken(USAGE_REPORT_QUEUE))),
251
254
  __param(12, Inject(getQueueToken(EVAL_QUEUE_NAME))),
252
- __param(13, Inject(getQueueToken(LIFECYCLE_QUEUE)))
255
+ __param(13, Inject(getQueueToken(LIFECYCLE_QUEUE))),
256
+ __param(14, Inject(getQueueToken(PUSH_QUEUE)))
253
257
  ], AdminHealthService);
254
258
  export { AdminHealthService };
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
188
188
  /** The host versions (an entry's `minKernel` is judged against them). */
189
189
  export declare const HOST_VERSIONS: {
190
190
  readonly kernel: string;
191
- readonly sdk: "0.1.0-rc.44";
191
+ readonly sdk: "0.1.0-rc.46";
192
192
  };
193
193
  /** Whether this deployment satisfies the entry's `minKernel`. */
194
194
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -206,6 +206,12 @@ export declare const KernelConfigSchema: z.ZodObject<{
206
206
  }>>;
207
207
  maxExpiryDays: z.ZodOptional<z.ZodNumber>;
208
208
  }, z.core.$strict>>;
209
+ push: z.ZodPrefault<z.ZodObject<{
210
+ previews: z.ZodDefault<z.ZodEnum<{
211
+ off: "off";
212
+ titles: "titles";
213
+ }>>;
214
+ }, z.core.$strict>>;
209
215
  subagents: z.ZodPrefault<z.ZodObject<{
210
216
  maxDepth: z.ZodDefault<z.ZodNumber>;
211
217
  maxConcurrentPerConversation: z.ZodDefault<z.ZodNumber>;
@@ -1244,6 +1244,18 @@ export const KernelConfigSchema = z.strictObject({
1244
1244
  })),
1245
1245
  })
1246
1246
  .prefault({}),
1247
+ /** Push notifications to people's mobile apps (mobile app spec §9.5); platform only. */
1248
+ push: z
1249
+ .strictObject({
1250
+ previews: z
1251
+ .enum(["off", "titles"])
1252
+ .default("off")
1253
+ .meta(meta({
1254
+ hot: true,
1255
+ description: "What a push notification may carry beyond the agent's name and a fixed sentence: off sends no conversation content; titles adds the conversation title to the body. Message and tool text are never sent",
1256
+ })),
1257
+ })
1258
+ .prefault({}),
1247
1259
  subagents: z
1248
1260
  .strictObject({
1249
1261
  maxDepth: z
@@ -2,6 +2,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { TransactionHost } from "../infra/database/transaction-host.js";
3
3
  import { OutboxService } from "../infra/outbox/outbox.service.js";
4
4
  import type { KernelLogger } from "../log.js";
5
+ import { PushOwed } from "../push/push-owed.js";
5
6
  import type { DeliveryScope } from "./delivery-scope.js";
6
7
  import { type ConversationEvent, type ConversationEventType } from "./events.js";
7
8
  /** 事件日志依赖的总线:内核 bus(命名空间 `kernel`)。 */
@@ -99,7 +100,8 @@ export type ConversationChange = (typeof CONVERSATION_CHANGES)[number];
99
100
  *
100
101
  * An append to a conversation with a channel target (`channel_deliveries`, read with the row lock)
101
102
  * owes the conversation's IM delivery in the append's transaction (transactional outbox spec
102
- * §8.1); a conversation without one writes nothing more.
103
+ * §8.1); a conversation without one writes nothing more. A push trigger event (an approval, a
104
+ * run's end, ...: `push/triggers.ts`) owes its push fanout in the same transaction (`PushOwed`).
103
105
  */
104
106
  export declare class EventLog {
105
107
  private readonly db;
@@ -107,7 +109,11 @@ export declare class EventLog {
107
109
  private readonly log;
108
110
  private readonly outbox;
109
111
  readonly txHost: TransactionHost;
110
- constructor(db: KernelDb, bus: EventBus | undefined, log: Pick<KernelLogger, "warn">, outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
112
+ /** Owes the push fanout of a trigger event in the append's transaction. */
113
+ private readonly push;
114
+ constructor(db: KernelDb, bus: EventBus | undefined, log: Pick<KernelLogger, "warn">, outbox: Pick<OutboxService, "add">, txHost: TransactionHost,
115
+ /** Owes the push fanout of a trigger event in the append's transaction. */
116
+ push: Pick<PushOwed, "oweIn">);
111
117
  /**
112
118
  * 追加事件,返回与输入一一对应的事件(幂等命中的为已有事件)。
113
119
  * 自开一个独立事务(`requires_new`,与调用方的事务无关),提交后发布 `conv.<id>`。
@@ -199,6 +205,9 @@ export declare class EventLog {
199
205
  /** The append itself, in the context's transaction (both callers open or join one). */
200
206
  private write;
201
207
  }
202
- /** The one {@link EventLog} (infra dependencies only, so every domain can import it). */
208
+ /**
209
+ * The one {@link EventLog} (infra dependencies and the push owed module, which needs only the
210
+ * extension registry, so every domain can import it).
211
+ */
203
212
  export declare class EventLogModule {
204
213
  }
@@ -16,6 +16,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
16
16
  import { Transactional } from "../infra/database/transactional.decorator.js";
17
17
  import { OutboxService } from "../infra/outbox/outbox.service.js";
18
18
  import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
19
+ import { PushOwed, PushOwedModule } from "../push/push-owed.js";
19
20
  import { ConversationEventSchema, } from "./events.js";
20
21
  /**
21
22
  * The JSON stored for an event payload, with every NUL (U+0000) in a string or an object key
@@ -78,7 +79,8 @@ const EVENT_COLUMNS = [
78
79
  *
79
80
  * An append to a conversation with a channel target (`channel_deliveries`, read with the row lock)
80
81
  * owes the conversation's IM delivery in the append's transaction (transactional outbox spec
81
- * §8.1); a conversation without one writes nothing more.
82
+ * §8.1); a conversation without one writes nothing more. A push trigger event (an approval, a
83
+ * run's end, ...: `push/triggers.ts`) owes its push fanout in the same transaction (`PushOwed`).
82
84
  */
83
85
  let EventLog = class EventLog {
84
86
  db;
@@ -86,15 +88,19 @@ let EventLog = class EventLog {
86
88
  log;
87
89
  outbox;
88
90
  txHost;
91
+ push;
89
92
  constructor(db,
90
93
  // Optional: the Redis-free CLI (openKernelCli redis:false) has no bus; publishes are hints whose
91
94
  // loss is harmless (readers catch up by seq), so there they are skipped.
92
- bus, log, outbox, txHost) {
95
+ bus, log, outbox, txHost,
96
+ /** Owes the push fanout of a trigger event in the append's transaction. */
97
+ push) {
93
98
  this.db = db;
94
99
  this.bus = bus;
95
100
  this.log = log;
96
101
  this.outbox = outbox;
97
102
  this.txHost = txHost;
103
+ this.push = push;
98
104
  }
99
105
  /**
100
106
  * 追加事件,返回与输入一一对应的事件(幂等命中的为已有事件)。
@@ -385,6 +391,7 @@ let EventLog = class EventLog {
385
391
  .selectFrom("conversations")
386
392
  .select((eb) => [
387
393
  "org_id",
394
+ "kind",
388
395
  eb
389
396
  .exists(eb
390
397
  .selectFrom("channel_deliveries")
@@ -469,6 +476,7 @@ let EventLog = class EventLog {
469
476
  if (conv.im)
470
477
  await oweDelivery(this.outbox, { conversationId, orgId: conv.org_id, seq: toSeq });
471
478
  const bySeq = new Map(inserted.map((r) => [Number(r.seq), toEvent(r)]));
479
+ await this.push.oweIn(conversationId, conv.org_id, conv.kind, [...bySeq.values()]);
472
480
  return {
473
481
  events: plan.map((p) => p.kind === "old" ? p.event : bySeq.get(base + p.index + 1)),
474
482
  toSeq,
@@ -492,13 +500,17 @@ EventLog = __decorate([
492
500
  __param(1, Inject(KERNEL_BUS)),
493
501
  __param(2, Inject(KERNEL_LOGGER)),
494
502
  __param(3, Inject(OutboxService)),
495
- __param(4, Inject(TransactionHost))
503
+ __param(4, Inject(TransactionHost)),
504
+ __param(5, Inject(PushOwed))
496
505
  ], EventLog);
497
506
  export { EventLog };
498
- /** The one {@link EventLog} (infra dependencies only, so every domain can import it). */
507
+ /**
508
+ * The one {@link EventLog} (infra dependencies and the push owed module, which needs only the
509
+ * extension registry, so every domain can import it).
510
+ */
499
511
  let EventLogModule = class EventLogModule {
500
512
  };
501
513
  EventLogModule = __decorate([
502
- Module({ providers: [EventLog], exports: [EventLog] })
514
+ Module({ imports: [PushOwedModule], providers: [EventLog], exports: [EventLog] })
503
515
  ], EventLogModule);
504
516
  export { EventLogModule };
@@ -50,6 +50,8 @@ export interface RewrapResult {
50
50
  initialPasswords: number;
51
51
  /** Unexpired sealed Platform reveals (`platform_sealed_reveals`, invitation links) now sealed with it. */
52
52
  sealedReveals: number;
53
+ /** Mobile app push tokens (`push_registrations`) now sealed with it. */
54
+ pushTokens: number;
53
55
  }
54
56
  /** Rows rewrapped per transaction by default. */
55
57
  export declare const REWRAP_BATCH_SIZE = 500;
@@ -65,16 +67,19 @@ export declare const platformSealedInputAad: (approvalId: string, paths: readonl
65
67
  * another subject fails to unwrap.
66
68
  */
67
69
  export declare const platformSealedRevealAad: (id: string) => string;
70
+ /** The AAD binding a sealed push token to its registration (a row moved to another one fails). */
71
+ export declare const pushTokenAad: (registrationId: string) => string;
68
72
  type RewrapHandles = {
69
73
  db: Pick<KernelDb, "db">;
70
74
  txHost: Pick<TransactionHost, "run">;
71
75
  };
72
76
  /**
73
- * Rewraps everything sealed with a master key other than the keyring's current one (org data keys
74
- * and unexpired initial passwords and sealed reveals) with the current key, `batchSize` rows per transaction, until
75
- * none is left. Checks first that the keyring holds every master key in use and throws (naming row
76
- * ids and key ids, never key material) before writing anything when it does not. Idempotent: a
77
- * second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
77
+ * Rewraps everything sealed with a master key other than the keyring's current one (org data keys,
78
+ * unexpired initial passwords and sealed reveals, push tokens) with the current key, `batchSize` rows per
79
+ * transaction, until none is left. Checks first that the keyring holds every master key in use and
80
+ * throws (naming row ids and key ids, never key material) before writing anything when it does not.
81
+ * Idempotent: a second run finds nothing; concurrent runs lock the same rows and skip the ones
82
+ * already done.
78
83
  */
79
84
  export declare function rewrapToCurrentMasterKey(handles: RewrapHandles, keyring: Keyring, opts?: {
80
85
  batchSize?: number;
@@ -157,6 +157,8 @@ export const platformSealedInputAad = (approvalId, paths) => `capybara:platform-
157
157
  * another subject fails to unwrap.
158
158
  */
159
159
  export const platformSealedRevealAad = (id) => `capybara:platform-sealed-reveal:${id}`;
160
+ /** The AAD binding a sealed push token to its registration (a row moved to another one fails). */
161
+ export const pushTokenAad = (registrationId) => `capybara:push-token:${registrationId}`;
160
162
  const MASTER_KEYED = [
161
163
  {
162
164
  table: "org_data_keys",
@@ -179,6 +181,13 @@ const MASTER_KEYED = [
179
181
  aad: platformSealedRevealAad,
180
182
  hasExpiresAt: true,
181
183
  },
184
+ {
185
+ table: "push_registrations",
186
+ idColumn: "id",
187
+ dataColumn: "token_ciphertext",
188
+ aad: pushTokenAad,
189
+ hasExpiresAt: false,
190
+ },
182
191
  ];
183
192
  function staleRows(db, t, keyring) {
184
193
  let q = db
@@ -197,11 +206,12 @@ function assertKnown(t, keyring, rows) {
197
206
  throw new Error(`secrets: master key not in keyring for ${t.table}.${t.idColumn}: ${shown.join(", ")}`);
198
207
  }
199
208
  /**
200
- * Rewraps everything sealed with a master key other than the keyring's current one (org data keys
201
- * and unexpired initial passwords and sealed reveals) with the current key, `batchSize` rows per transaction, until
202
- * none is left. Checks first that the keyring holds every master key in use and throws (naming row
203
- * ids and key ids, never key material) before writing anything when it does not. Idempotent: a
204
- * second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
209
+ * Rewraps everything sealed with a master key other than the keyring's current one (org data keys,
210
+ * unexpired initial passwords and sealed reveals, push tokens) with the current key, `batchSize` rows per
211
+ * transaction, until none is left. Checks first that the keyring holds every master key in use and
212
+ * throws (naming row ids and key ids, never key material) before writing anything when it does not.
213
+ * Idempotent: a second run finds nothing; concurrent runs lock the same rows and skip the ones
214
+ * already done.
205
215
  */
206
216
  export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
207
217
  const batchSize = opts.batchSize ?? REWRAP_BATCH_SIZE;
@@ -260,5 +270,6 @@ export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
260
270
  dataKeys: counts.get("org_data_keys") ?? 0,
261
271
  initialPasswords: counts.get("account_initial_passwords") ?? 0,
262
272
  sealedReveals: counts.get("platform_sealed_reveals") ?? 0,
273
+ pushTokens: counts.get("push_registrations") ?? 0,
263
274
  };
264
275
  }
@@ -161,6 +161,33 @@ export interface PlatformSealedRevealsTable {
161
161
  expires_at: Date | string;
162
162
  created_at: Ts;
163
163
  }
164
+ /** A person's mobile app push registration (migration 0172); the token is sealed. */
165
+ export interface PushRegistrationsTable {
166
+ id: string;
167
+ account_id: string;
168
+ /** The session that posted it; revoking that session deletes the registration. */
169
+ session_id: string | null;
170
+ platform: "ios" | "android";
171
+ app_id: string;
172
+ /** The push-provider extension (plugin name) the registration is delivered through. */
173
+ provider: string;
174
+ /** sha256 hex of the token, unique per (provider, app_id). */
175
+ token_hash: string;
176
+ master_key_id: string;
177
+ /** AES-256-GCM with the master keyring, AAD `pushTokenAad(id)`. */
178
+ token_ciphertext: Buffer;
179
+ locale: "zh" | "en";
180
+ device_name: string;
181
+ created_at: Ts;
182
+ last_seen_at: Ts;
183
+ }
184
+ /** A person's switch for one push category (migration 0172); an absent row is on. */
185
+ export interface PushPreferencesTable {
186
+ account_id: string;
187
+ category: "waiting" | "replies" | "tasks" | "schedules";
188
+ enabled: boolean;
189
+ updated_at: Ts;
190
+ }
164
191
  export interface IdentitiesTable {
165
192
  source: string;
166
193
  external_id: string;
@@ -1662,6 +1689,8 @@ export interface KernelDatabase {
1662
1689
  account_initial_passwords: AccountInitialPasswordsTable;
1663
1690
  platform_sealed_inputs: PlatformSealedInputsTable;
1664
1691
  platform_sealed_reveals: PlatformSealedRevealsTable;
1692
+ push_registrations: PushRegistrationsTable;
1693
+ push_preferences: PushPreferencesTable;
1665
1694
  identities: IdentitiesTable;
1666
1695
  local_passwords: LocalPasswordsTable;
1667
1696
  orgs: OrgsTable;
@@ -1839,10 +1868,13 @@ export interface OrgNoticesTable {
1839
1868
  dismissed_at: TsNullable;
1840
1869
  dismissed_by: NullableCol<string>;
1841
1870
  }
1842
- /** 0084: a notice for the super admins (platform inbox), until one of them dismisses it. */
1871
+ /**
1872
+ * 0084: a notice for the super admins (platform inbox), until one of them dismisses it; 0173
1873
+ * added `push_auth_failed` (at most one open per plugin).
1874
+ */
1843
1875
  export interface PlatformNoticesTable {
1844
1876
  id: string;
1845
- kind: "ownership_transferred";
1877
+ kind: "ownership_transferred" | "push_auth_failed";
1846
1878
  detail: Json<Record<string, unknown>>;
1847
1879
  created_at: Ts;
1848
1880
  dismissed_at: TsNullable;
package/dist/errors.d.ts CHANGED
@@ -613,6 +613,13 @@ export declare const ERROR_CODES: {
613
613
  /** An extension's `ctx.models.embed` call was denied by a `model.request` policy hook. */
614
614
  readonly "model.hook_denied": 403;
615
615
  readonly "eval.result_not_found": 404;
616
+ /**
617
+ * A push registration names a provider that is not loaded or whose credentials do not cover
618
+ * its app id (mobile app spec §9.2).
619
+ */
620
+ readonly "push.provider_unavailable": 422;
621
+ /** No push registration of that id belongs to the caller. */
622
+ readonly "push.registration_not_found": 404;
616
623
  };
617
624
  export type ErrorCode = keyof typeof ERROR_CODES;
618
625
  /** 业务代码抛出的 API 错误;由 HTTP 层的错误过滤器转成错误信封。 */
package/dist/errors.js CHANGED
@@ -613,6 +613,13 @@ export const ERROR_CODES = {
613
613
  /** An extension's `ctx.models.embed` call was denied by a `model.request` policy hook. */
614
614
  "model.hook_denied": 403,
615
615
  "eval.result_not_found": 404,
616
+ /**
617
+ * A push registration names a provider that is not loaded or whose credentials do not cover
618
+ * its app id (mobile app spec §9.2).
619
+ */
620
+ "push.provider_unavailable": 422,
621
+ /** No push registration of that id belongs to the caller. */
622
+ "push.registration_not_found": 404,
616
623
  };
617
624
  /** 业务代码抛出的 API 错误;由 HTTP 层的错误过滤器转成错误信封。 */
618
625
  export class ApiError extends Error {
@@ -1,4 +1,6 @@
1
1
  import type { core } from "zod";
2
+ /** 键排序后的 JSON(对象键顺序不影响结果);undefined 字段与 JSON.stringify 一样省略。 */
3
+ export declare const canonicalJson: (v: unknown) => string;
2
4
  /**
3
5
  * 插件部署配置(校验后)中非密钥部分的摘要:先把 schema 里所有 secret 叶子(`configFields` 可达路径,
4
6
  * 加载时 `assertSecretsReachable` 已保证密钥都在这些路径上)换成固定占位值,再取 sha256(键排序 JSON) 前 16 位十六进制。
@@ -1,7 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { configFields, getPath, setPath } from "../config/fields.js";
3
3
  /** 键排序后的 JSON(对象键顺序不影响结果);undefined 字段与 JSON.stringify 一样省略。 */
4
- const canonicalJson = (v) => {
4
+ export const canonicalJson = (v) => {
5
5
  if (Array.isArray(v))
6
6
  return `[${v.map((x) => (x === undefined ? "null" : canonicalJson(x))).join(",")}]`;
7
7
  if (v !== null && typeof v === "object") {
@@ -16,7 +16,11 @@ export type UnresolvedReason =
16
16
  | "no_connector"
17
17
  /** Rendered for the platform (the super admin's preview), not for an org. */
18
18
  | "no_org";
19
- /** The org action each audience of a place needs besides `catalog.read` (spec §9.1). */
19
+ /**
20
+ * The org action each audience of a place needs besides `catalog.read` (spec §9.1).
21
+ * `extension-deployment` has none: its guides are the super admin's (the admin extension routes),
22
+ * so an org route refuses them (`forbidden`).
23
+ */
20
24
  export declare const PLACE_ACTIONS: Readonly<Record<SetupGuidePlace, Readonly<Partial<Record<SetupGuideAudience, OrgAction>>>>>;
21
25
  /** The object a guide is rendered for. */
22
26
  export interface GuideTarget {