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

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 (104) 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/attachments.controller.d.ts +11 -3
  10. package/dist/conversations/attachments.controller.js +18 -5
  11. package/dist/conversations/conversations.controller.d.ts +11 -2
  12. package/dist/conversations/conversations.controller.js +17 -4
  13. package/dist/conversations/conversations.schemas.d.ts +8 -0
  14. package/dist/conversations/conversations.schemas.js +6 -0
  15. package/dist/conversations/event-log.d.ts +12 -3
  16. package/dist/conversations/event-log.js +17 -5
  17. package/dist/ctx/secrets.d.ts +10 -5
  18. package/dist/ctx/secrets.js +16 -5
  19. package/dist/db/kernel-schema.d.ts +34 -2
  20. package/dist/errors.d.ts +7 -0
  21. package/dist/errors.js +7 -0
  22. package/dist/extensions/config-hash.d.ts +2 -0
  23. package/dist/extensions/config-hash.js +1 -1
  24. package/dist/extensions/guide-places.d.ts +5 -1
  25. package/dist/extensions/guide-places.js +9 -2
  26. package/dist/extensions/permission-view.d.ts +6 -4
  27. package/dist/extensions/permission-view.js +6 -3
  28. package/dist/extensions/plugin-guides.d.ts +20 -0
  29. package/dist/extensions/plugin-guides.js +49 -1
  30. package/dist/extensions/registry.js +1 -0
  31. package/dist/http/api.module.js +7 -0
  32. package/dist/http/meta.controller.d.ts +7 -1
  33. package/dist/http/meta.controller.js +14 -3
  34. package/dist/identity/accounts.js +5 -0
  35. package/dist/identity/sessions.d.ts +7 -0
  36. package/dist/identity/sessions.js +26 -4
  37. package/dist/inbox/platform-inbox.service.d.ts +21 -11
  38. package/dist/inbox/platform-inbox.service.js +27 -12
  39. package/dist/inbox/platform-notices.d.ts +15 -1
  40. package/dist/inbox/platform-notices.js +20 -0
  41. package/dist/infra/config/kernel-config.service.js +2 -0
  42. package/dist/infra/outbox/registry.d.ts +36 -0
  43. package/dist/infra/outbox/registry.js +30 -0
  44. package/dist/infra/queue/queue-names.d.ts +1 -1
  45. package/dist/infra/queue/queue-names.js +1 -0
  46. package/dist/orgs/offboarding.js +3 -0
  47. package/dist/overrides.d.ts +4 -0
  48. package/dist/overrides.js +2 -0
  49. package/dist/platform/exclusions.js +15 -0
  50. package/dist/platform/ops/extensions-admin.ops.d.ts +5 -1
  51. package/dist/platform/ops/extensions-admin.ops.js +97 -2
  52. package/dist/platform/ops/inbox.ops.d.ts +1 -1
  53. package/dist/platform/ops/inbox.ops.js +17 -7
  54. package/dist/platform/ops/platform.ops.d.ts +4 -2
  55. package/dist/platform/ops/platform.ops.js +55 -3
  56. package/dist/platform/platform-ops.module.js +2 -0
  57. package/dist/platform/route-schemas.js +3 -0
  58. package/dist/push/delivery.d.ts +88 -0
  59. package/dist/push/delivery.js +269 -0
  60. package/dist/push/fanout.d.ts +29 -0
  61. package/dist/push/fanout.js +95 -0
  62. package/dist/push/jobs.d.ts +43 -0
  63. package/dist/push/jobs.js +19 -0
  64. package/dist/push/preferences.service.d.ts +18 -0
  65. package/dist/push/preferences.service.js +82 -0
  66. package/dist/push/provider-host.d.ts +34 -0
  67. package/dist/push/provider-host.js +94 -0
  68. package/dist/push/push-owed.d.ts +33 -0
  69. package/dist/push/push-owed.js +93 -0
  70. package/dist/push/push-processor.d.ts +40 -0
  71. package/dist/push/push-processor.js +114 -0
  72. package/dist/push/push.controller.d.ts +28 -0
  73. package/dist/push/push.controller.js +92 -0
  74. package/dist/push/push.module.d.ts +6 -0
  75. package/dist/push/push.module.js +29 -0
  76. package/dist/push/push.schemas.d.ts +88 -0
  77. package/dist/push/push.schemas.js +53 -0
  78. package/dist/push/recipients.d.ts +29 -0
  79. package/dist/push/recipients.js +263 -0
  80. package/dist/push/registration-cleanup.d.ts +9 -0
  81. package/dist/push/registration-cleanup.js +16 -0
  82. package/dist/push/registrations.service.d.ts +55 -0
  83. package/dist/push/registrations.service.js +254 -0
  84. package/dist/push/stale.job.d.ts +25 -0
  85. package/dist/push/stale.job.js +76 -0
  86. package/dist/push/texts.d.ts +31 -0
  87. package/dist/push/texts.js +46 -0
  88. package/dist/push/token-store.d.ts +31 -0
  89. package/dist/push/token-store.js +52 -0
  90. package/dist/push/triggers.d.ts +19 -0
  91. package/dist/push/triggers.js +30 -0
  92. package/dist/roles/worker-role.d.ts +7 -4
  93. package/dist/roles/worker-role.js +12 -5
  94. package/dist/roles/worker.module.d.ts +1 -1
  95. package/dist/roles/worker.module.js +4 -1
  96. package/dist/schedules/run-tracker.d.ts +10 -2
  97. package/dist/schedules/run-tracker.js +18 -4
  98. package/dist/setup/setup-checks.schemas.d.ts +29 -0
  99. package/dist/setup/setup-checks.schemas.js +32 -0
  100. package/dist/setup/setup-checks.service.d.ts +36 -3
  101. package/dist/setup/setup-checks.service.js +137 -29
  102. package/package.json +4 -4
  103. package/src/migrations/0172_push.sql +40 -0
  104. 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.47";
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
@@ -8,14 +8,22 @@ declare const CreateBody: z.ZodObject<{
8
8
  contentType: z.ZodString;
9
9
  size: z.ZodNumber;
10
10
  }, z.core.$strict>;
11
+ declare const DownloadQuery: z.ZodObject<{
12
+ as: z.ZodOptional<z.ZodEnum<{
13
+ url: "url";
14
+ }>>;
15
+ }, z.core.$strip>;
11
16
  /**
12
17
  * 对话附件(`/api/v1/orgs/:orgId/attachments`,`agents.use`,只接受人类用户):
13
18
  * 1. `POST /` 登记并取预签名上传(`upload.method` 为 `POST` 时按 multipart 表单:先放 `fields`,最后放 `file`);
14
19
  * 2. 浏览器直传对象存储;
15
20
  * 3. `POST /:id/finalize` 核对大小与类型;
16
21
  * 4. 发消息时在 `files` 里引用 id。
17
- * 下载 `GET /:id/download` 302 到预签名地址(`Cache-Control: private, max-age=60`)。上限 `GET /limits`(类型、单个大小、
18
- * 每条条数、单次请求的媒体预算、存储是否可用,供网页预检;不需要对象存储)。没有对象存储时其余接口 503 `storage.unavailable`。
22
+ * Download: `GET /:id/download` redirects (302) to the presigned URL (`Cache-Control: private,
23
+ * max-age=60`); `?as=url` answers `{ url }` with that address instead. Limits: `GET /limits` (types,
24
+ * per-file size, files per message, the media budget per request, whether storage is available; for the
25
+ * web's pre-checks; needs no object store). Without an object store the other routes answer 503
26
+ * `storage.unavailable`.
19
27
  */
20
28
  export declare class AttachmentsController {
21
29
  private readonly attachments;
@@ -23,6 +31,6 @@ export declare class AttachmentsController {
23
31
  limits(principal: Principal): AttachmentLimits;
24
32
  create(principal: Principal, org: OrgContext, body: z.infer<typeof CreateBody>): Promise<CreatedAttachment>;
25
33
  finalize(principal: Principal, org: OrgContext, id: string): Promise<AttachmentView>;
26
- download(principal: Principal, org: OrgContext, id: string, reply: FastifyReply): Promise<void>;
34
+ download(principal: Principal, org: OrgContext, id: string, q: z.infer<typeof DownloadQuery>, reply: FastifyReply): Promise<void>;
27
35
  }
28
36
  export {};
@@ -12,9 +12,10 @@ import { Controller, Get, HttpCode, Inject, Param, Post, Res } from "@nestjs/com
12
12
  import { z } from "zod";
13
13
  import { CurrentPrincipal, requireUser } from "../identity/principal.js";
14
14
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
15
- import { ZBody } from "../infra/validation/zod-params.js";
15
+ import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
16
16
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
17
17
  import { ATTACHMENT_DOWNLOAD_CACHE_SECONDS, AttachmentsService, } from "./attachments.service.js";
18
+ import { DOWNLOAD_AS } from "./conversations.schemas.js";
18
19
  const CreateBody = z
19
20
  .object({
20
21
  name: z
@@ -28,14 +29,21 @@ const CreateBody = z
28
29
  .strict();
29
30
  class AttachmentCreateBodyDto extends createZodDto(CreateBody, "AttachmentCreateBody") {
30
31
  }
32
+ // Not strict: the web adds a cache-busting `retry=1` when it reloads a failed image.
33
+ const DownloadQuery = z.object({ as: DOWNLOAD_AS.optional() });
34
+ class AttachmentDownloadQueryDto extends createZodDto(DownloadQuery, "AttachmentDownloadQuery") {
35
+ }
31
36
  /**
32
37
  * 对话附件(`/api/v1/orgs/:orgId/attachments`,`agents.use`,只接受人类用户):
33
38
  * 1. `POST /` 登记并取预签名上传(`upload.method` 为 `POST` 时按 multipart 表单:先放 `fields`,最后放 `file`);
34
39
  * 2. 浏览器直传对象存储;
35
40
  * 3. `POST /:id/finalize` 核对大小与类型;
36
41
  * 4. 发消息时在 `files` 里引用 id。
37
- * 下载 `GET /:id/download` 302 到预签名地址(`Cache-Control: private, max-age=60`)。上限 `GET /limits`(类型、单个大小、
38
- * 每条条数、单次请求的媒体预算、存储是否可用,供网页预检;不需要对象存储)。没有对象存储时其余接口 503 `storage.unavailable`。
42
+ * Download: `GET /:id/download` redirects (302) to the presigned URL (`Cache-Control: private,
43
+ * max-age=60`); `?as=url` answers `{ url }` with that address instead. Limits: `GET /limits` (types,
44
+ * per-file size, files per message, the media budget per request, whether storage is available; for the
45
+ * web's pre-checks; needs no object store). Without an object store the other routes answer 503
46
+ * `storage.unavailable`.
39
47
  */
40
48
  let AttachmentsController = class AttachmentsController {
41
49
  attachments;
@@ -54,9 +62,13 @@ let AttachmentsController = class AttachmentsController {
54
62
  const p = requireUser(principal);
55
63
  return this.attachments.finalize(org.orgId, p.account.id, id);
56
64
  }
57
- async download(principal, org, id, reply) {
65
+ async download(principal, org, id, q, reply) {
58
66
  const p = requireUser(principal);
59
67
  const location = await this.attachments.downloadUrl(org.orgId, p.account.id, id);
68
+ if (q.as === "url") {
69
+ await reply.header("cache-control", "private, no-store").send({ url: location });
70
+ return;
71
+ }
60
72
  // 浏览器可在短时间内复用跳转(同一页面的缩略图);预签名有效期不短于这段时间
61
73
  await reply
62
74
  .header("cache-control", `private, max-age=${ATTACHMENT_DOWNLOAD_CACHE_SECONDS}`)
@@ -89,7 +101,8 @@ __decorate([
89
101
  __param(0, CurrentPrincipal()),
90
102
  __param(1, CurrentOrg()),
91
103
  __param(2, Param("id")),
92
- __param(3, Res())
104
+ __param(3, ZQuery(AttachmentDownloadQueryDto)),
105
+ __param(4, Res())
93
106
  ], AttachmentsController.prototype, "download", null);
94
107
  AttachmentsController = __decorate([
95
108
  Controller("api/v1/orgs/:orgId/attachments"),
@@ -39,12 +39,19 @@ declare const OutputQuery: z.ZodObject<{
39
39
  declare const FileContentQuery: z.ZodObject<{
40
40
  limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
41
41
  }, z.core.$strip>;
42
- /** `inline=1`:要求以 inline 打开(只对位图生效,见 ConversationArtifacts)。 */
42
+ /**
43
+ * `inline=1`: open inline (bitmaps only, see ConversationArtifacts). `as=url`: answer `{ url }`
44
+ * (the presigned location the 302 would send) instead of redirecting, so a page can hand a
45
+ * cookie-free URL to the system browser (a native shell's `openExternal@1`).
46
+ */
43
47
  declare const DownloadQuery: z.ZodObject<{
44
48
  inline: z.ZodOptional<z.ZodEnum<{
45
49
  0: "0";
46
50
  1: "1";
47
51
  }>>;
52
+ as: z.ZodOptional<z.ZodEnum<{
53
+ url: "url";
54
+ }>>;
48
55
  }, z.core.$strip>;
49
56
  declare const MessageBody: z.ZodObject<{
50
57
  text: z.ZodString;
@@ -215,7 +222,9 @@ export declare class ConversationsController {
215
222
  output: OutputPage;
216
223
  }>;
217
224
  /**
218
- * 下载 agent 交付的产物(`artifact_created`):302 到预签名地址(一律 `attachment`,带文件名)。
225
+ * Download an artifact the agent delivered (`artifact_created`): a 302 to the presigned URL (always
226
+ * `attachment`, with the file name);
227
+ * `as=url` answers `{ url }` with that address instead (never cached).
219
228
  * 会话可见性与会话流相同,不可见 → `conversation.not_found`;不是该会话的产物 → `conversation.artifact_not_found`。
220
229
  */
221
230
  downloadArtifact(principal: Principal, org: OrgContext, id: string, artifactId: string, q: z.infer<typeof DownloadQuery>, reply: FastifyReply): Promise<void>;
@@ -18,7 +18,7 @@ import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
18
18
  import { MAX_ATTACHMENTS } from "../tools/connector-content.js";
19
19
  import { ConversationToolInfo, TOOL_INFO_KEY_MAX, TOOL_INFO_MAX_KEYS, } from "../tools/info.js";
20
20
  import { ARTIFACT_DOWNLOAD_CACHE_SECONDS, ConversationArtifacts, } from "./artifacts.js";
21
- import { CompactBody, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
21
+ import { CompactBody, DOWNLOAD_AS, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
22
22
  import { ConversationsService, } from "./conversations.service.js";
23
23
  import { ConversationDeviceStatus } from "./device-status.js";
24
24
  import { ConversationFiles, FILE_CONTENT_MAX_BYTES } from "./files.js";
@@ -46,8 +46,15 @@ const OutputQuery = z.object({
46
46
  const FileContentQuery = z.object({
47
47
  limit: z.coerce.number().int().min(1).max(FILE_CONTENT_MAX_BYTES).default(FILE_CONTENT_MAX_BYTES),
48
48
  });
49
- /** `inline=1`:要求以 inline 打开(只对位图生效,见 ConversationArtifacts)。 */
50
- const DownloadQuery = z.object({ inline: z.enum(["0", "1"]).optional() });
49
+ /**
50
+ * `inline=1`: open inline (bitmaps only, see ConversationArtifacts). `as=url`: answer `{ url }`
51
+ * (the presigned location the 302 would send) instead of redirecting, so a page can hand a
52
+ * cookie-free URL to the system browser (a native shell's `openExternal@1`).
53
+ */
54
+ const DownloadQuery = z.object({
55
+ inline: z.enum(["0", "1"]).optional(),
56
+ as: DOWNLOAD_AS.optional(),
57
+ });
51
58
  const MessageFields = z.object({
52
59
  /** 用户输入的文本;只有带 `files` 且不带 `attachments` 时可以为空(只发图片 / 文件)。 */
53
60
  text: z.string().max(100_000),
@@ -333,7 +340,9 @@ let ConversationsController = class ConversationsController {
333
340
  return { output: await this.outputs.read(org.orgId, id, p.account.id, outputId, q) };
334
341
  }
335
342
  /**
336
- * 下载 agent 交付的产物(`artifact_created`):302 到预签名地址(一律 `attachment`,带文件名)。
343
+ * Download an artifact the agent delivered (`artifact_created`): a 302 to the presigned URL (always
344
+ * `attachment`, with the file name);
345
+ * `as=url` answers `{ url }` with that address instead (never cached).
337
346
  * 会话可见性与会话流相同,不可见 → `conversation.not_found`;不是该会话的产物 → `conversation.artifact_not_found`。
338
347
  */
339
348
  async downloadArtifact(principal, org, id, artifactId, q, reply) {
@@ -341,6 +350,10 @@ let ConversationsController = class ConversationsController {
341
350
  const { url } = await this.artifacts.downloadUrl(org.orgId, id, p.account.id, artifactId, {
342
351
  inline: q.inline === "1",
343
352
  });
353
+ if (q.as === "url") {
354
+ await reply.header("cache-control", "private, no-store").send({ url });
355
+ return;
356
+ }
344
357
  await reply
345
358
  .header("cache-control", `private, max-age=${ARTIFACT_DOWNLOAD_CACHE_SECONDS}`)
346
359
  .redirect(url, 302);
@@ -1,5 +1,13 @@
1
1
  import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
+ /**
4
+ * The download routes' answer form: `as=url` answers `{ url }` (the presigned location the 302
5
+ * would send, never cached) so a page can hand a cookie-free URL to the system browser (a native
6
+ * shell's `openExternal@1`). Shared by the attachment and the artifact download routes.
7
+ */
8
+ export declare const DOWNLOAD_AS: z.ZodEnum<{
9
+ url: "url";
10
+ }>;
3
11
  /** Shared by the list and groups queries: title search, run activity and the archived list. */
4
12
  export declare const searchFields: {
5
13
  q: z.ZodOptional<z.ZodString>;
@@ -2,6 +2,12 @@ import { z } from "zod";
2
2
  import { CONTROL_OR_HIDDEN_RE } from "../text.js";
3
3
  import { CONVERSATION_TITLE_MAX_CHARS } from "./conversations.service.js";
4
4
  import { FILES_PAGE_MAX } from "./files.js";
5
+ /**
6
+ * The download routes' answer form: `as=url` answers `{ url }` (the presigned location the 302
7
+ * would send, never cached) so a page can hand a cookie-free URL to the system browser (a native
8
+ * shell's `openExternal@1`). Shared by the attachment and the artifact download routes.
9
+ */
10
+ export const DOWNLOAD_AS = z.enum(["url"]);
5
11
  /** Shared by the list and groups queries: title search, run activity and the archived list. */
6
12
  export const searchFields = {
7
13
  q: z.string().min(1).max(100).optional(),
@@ -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 };