@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
@@ -3,7 +3,7 @@ import { type CatalogItemView, CatalogService } from "../catalog/catalog.service
3
3
  import { CatalogRequestsService, type CatalogRequestView } from "../catalog/requests.service.js";
4
4
  import type { ScopeSyncOp } from "../db/kernel-schema.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
- import type { PlatformNoticeDetails } from "./platform-notices.js";
6
+ import type { PlatformNoticeDetails, PlatformNoticeKind } from "./platform-notices.js";
7
7
  /** The most items one platform inbox read returns. */
8
8
  export declare const PLATFORM_INBOX_MAX_ITEMS = 100;
9
9
  /** The most open scope sync failures one read takes. */
@@ -64,7 +64,9 @@ export interface ExtensionDisabledView {
64
64
  * ({@link ExtensionDisabledView}), `id` = the item's; gone once the extension is enabled (or the
65
65
  * scope no longer turns it on);
66
66
  * - `ownership_transferred`: a deleted org's shared item now belongs to the platform, until a
67
- * super admin dismisses it (`POST admin/inbox/notices/:id/dismiss`).
67
+ * super admin dismisses it (`POST admin/inbox/notices/:id/dismiss`);
68
+ * - `push_auth_failed`: a push provider's credentials were refused on a delivery (at most one
69
+ * open per plugin), until a super admin dismisses it (same route).
68
70
  */
69
71
  export type PlatformInboxItem = {
70
72
  type: "catalog_request";
@@ -95,19 +97,26 @@ export type PlatformInboxItem = {
95
97
  type: "ownership_transferred";
96
98
  id: string;
97
99
  createdAt: string;
98
- notice: PlatformNoticeView;
100
+ notice: PlatformNoticeView<"ownership_transferred">;
101
+ } | {
102
+ type: "push_auth_failed";
103
+ id: string;
104
+ createdAt: string;
105
+ notice: PlatformNoticeView<"push_auth_failed">;
99
106
  };
100
107
  /** Every {@link PlatformInboxItem} type, in the order the admin overview lists them. */
101
- export declare const PLATFORM_INBOX_TYPES: readonly ["catalog_request", "permission_confirmation", "org_upload_pending", "scope_sync_failed", "extension_disabled", "ownership_transferred"];
108
+ export declare const PLATFORM_INBOX_TYPES: readonly ["catalog_request", "permission_confirmation", "org_upload_pending", "scope_sync_failed", "extension_disabled", "ownership_transferred", "push_auth_failed"];
102
109
  /** How many items of each type wait: every type, zeros included. */
103
110
  export type PlatformInboxCounts = Record<PlatformInboxItem["type"], number>;
104
- /** An open platform notice (`platform_notices`, kind `ownership_transferred`). */
105
- export interface PlatformNoticeView {
106
- id: string;
107
- kind: "ownership_transferred";
108
- createdAt: string;
109
- detail: PlatformNoticeDetails["ownership_transferred"];
110
- }
111
+ /** An open platform notice (`platform_notices`) of one kind. */
112
+ export type PlatformNoticeView<K extends PlatformNoticeKind = PlatformNoticeKind> = {
113
+ [P in K]: {
114
+ id: string;
115
+ kind: P;
116
+ createdAt: string;
117
+ detail: PlatformNoticeDetails[P];
118
+ };
119
+ }[K];
111
120
  /**
112
121
  * `GET /admin/inbox`: newest first, at most {@link PLATFORM_INBOX_MAX_ITEMS}; `truncated`: more;
113
122
  * `total`: how many items wait in all (also `GET /admin/inbox/count`); `byType`: `total` per
@@ -136,6 +145,7 @@ export declare class PlatformInboxService {
136
145
  * requests and the failures; the permission confirmations are the catalog's pending list).
137
146
  */
138
147
  count(): Promise<number>;
148
+ /** The open platform notices of each kind. */
139
149
  private countNotices;
140
150
  /** The open platform notices, newest first, at most {@link PLATFORM_INBOX_MAX_ITEMS}. */
141
151
  private notices;
@@ -26,6 +26,7 @@ export const PLATFORM_INBOX_TYPES = [
26
26
  "scope_sync_failed",
27
27
  "extension_disabled",
28
28
  "ownership_transferred",
29
+ "push_auth_failed",
29
30
  ];
30
31
  /**
31
32
  * The super admin's inbox (plugin scope spec §5.1 rule 5, §13.5): what waits on the platform,
@@ -79,12 +80,12 @@ let PlatformInboxService = class PlatformInboxService {
79
80
  createdAt: d.since,
80
81
  disabled: d,
81
82
  })),
82
- ...notices.map((n) => ({
83
- type: "ownership_transferred",
84
- id: n.id,
85
- createdAt: n.createdAt,
86
- notice: n,
87
- })),
83
+ ...notices.map((n) =>
84
+ // the same object either way; the branches only narrow `n` so each item type pairs with
85
+ // its own notice kind (TypeScript does not distribute the union through one literal)
86
+ n.kind === "push_auth_failed"
87
+ ? { type: n.kind, id: n.id, createdAt: n.createdAt, notice: n }
88
+ : { type: n.kind, id: n.id, createdAt: n.createdAt, notice: n }),
88
89
  ];
89
90
  // newest first; equal times by id (a stable order)
90
91
  all.sort((a, b) => a.createdAt !== b.createdAt
@@ -103,7 +104,8 @@ let PlatformInboxService = class PlatformInboxService {
103
104
  org_upload_pending: orgUploads,
104
105
  scope_sync_failed: failureCount,
105
106
  extension_disabled: disabledCount,
106
- ownership_transferred: noticeCount,
107
+ ownership_transferred: noticeCount.ownership_transferred,
108
+ push_auth_failed: noticeCount.push_auth_failed,
107
109
  };
108
110
  const total = Object.values(byType).reduce((a, b) => a + b, 0);
109
111
  const items = all.slice(0, PLATFORM_INBOX_MAX_ITEMS);
@@ -121,15 +123,28 @@ let PlatformInboxService = class PlatformInboxService {
121
123
  this.countDisabledExtensions(),
122
124
  this.countNotices(),
123
125
  ]);
124
- return requests + pending.length + failures + disabled + notices;
126
+ return (requests +
127
+ pending.length +
128
+ failures +
129
+ disabled +
130
+ notices.ownership_transferred +
131
+ notices.push_auth_failed);
125
132
  }
133
+ /** The open platform notices of each kind. */
126
134
  async countNotices() {
127
- const r = await this.kdb.db
135
+ const rows = await this.kdb.db
128
136
  .selectFrom("platform_notices")
129
- .select(sql `count(*)`.as("n"))
137
+ .select(["kind", sql `count(*)`.as("n")])
130
138
  .where("dismissed_at", "is", null)
131
- .executeTakeFirstOrThrow();
132
- return Number(r.n);
139
+ .groupBy("kind")
140
+ .execute();
141
+ const counts = {
142
+ ownership_transferred: 0,
143
+ push_auth_failed: 0,
144
+ };
145
+ for (const r of rows)
146
+ counts[r.kind] = Number(r.n);
147
+ return counts;
133
148
  }
134
149
  /** The open platform notices, newest first, at most {@link PLATFORM_INBOX_MAX_ITEMS}. */
135
150
  async notices() {
@@ -1,6 +1,6 @@
1
1
  import type { OwnedRef } from "../catalog/ownership.js";
2
2
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
- export type PlatformNoticeKind = "ownership_transferred";
3
+ export type PlatformNoticeKind = "ownership_transferred" | "push_auth_failed";
4
4
  /** The `detail` of each platform notice kind. */
5
5
  export interface PlatformNoticeDetails {
6
6
  /** A deleted org's (or owner's) shared item now belongs to the platform. */
@@ -15,5 +15,19 @@ export interface PlatformNoticeDetails {
15
15
  /** How many other orgs use it. */
16
16
  usedBy: number;
17
17
  };
18
+ /**
19
+ * A push provider's credentials were refused on a delivery (mobile app spec §9.2); at most one
20
+ * open notice per plugin ({@link addPushAuthNotice}).
21
+ */
22
+ push_auth_failed: {
23
+ plugin: string;
24
+ };
18
25
  }
19
26
  export declare function addPlatformNotice<K extends PlatformNoticeKind>(db: KernelSchemaDb, kind: K, detail: PlatformNoticeDetails[K]): Promise<void>;
27
+ /**
28
+ * Tells the super admins that `plugin`'s push credentials were refused, unless a notice of that
29
+ * kind naming the plugin is still open. The partial unique index
30
+ * `platform_notices_push_auth_open_idx` (migration 0173) keeps it at one open notice per plugin
31
+ * even when deliveries on several replicas fail at once.
32
+ */
33
+ export declare function addPushAuthNotice(db: KernelSchemaDb, plugin: string): Promise<void>;
@@ -1,9 +1,29 @@
1
1
  // Platform notices (`platform_notices`, plugin scope phase 3, ruling P3-22): what the super admins
2
2
  // are told, until any one of them dismisses it. Written in the caller's transaction.
3
3
  import { randomUUID } from "node:crypto";
4
+ import { sql } from "kysely";
4
5
  export async function addPlatformNotice(db, kind, detail) {
5
6
  await db
6
7
  .insertInto("platform_notices")
7
8
  .values({ id: randomUUID(), kind, detail: JSON.stringify(detail) })
8
9
  .execute();
9
10
  }
11
+ /**
12
+ * Tells the super admins that `plugin`'s push credentials were refused, unless a notice of that
13
+ * kind naming the plugin is still open. The partial unique index
14
+ * `platform_notices_push_auth_open_idx` (migration 0173) keeps it at one open notice per plugin
15
+ * even when deliveries on several replicas fail at once.
16
+ */
17
+ export async function addPushAuthNotice(db, plugin) {
18
+ const detail = { plugin };
19
+ await db
20
+ .insertInto("platform_notices")
21
+ .values({ id: randomUUID(), kind: "push_auth_failed", detail: JSON.stringify(detail) })
22
+ .onConflict((oc) => oc
23
+ .expression(sql `(detail ->> 'plugin')`)
24
+ // literals, not parameters: PostgreSQL matches the partial index's predicate textually
25
+ .where("kind", "=", sql.lit("push_auth_failed"))
26
+ .where("dismissed_at", "is", null)
27
+ .doNothing())
28
+ .execute();
29
+ }
@@ -74,6 +74,8 @@ const HOT_APPLIERS = {
74
74
  "web.fetch.maxAnswerTokens": () => { },
75
75
  "web.fetch.cacheSeconds": () => { },
76
76
  "web.fetch.timeoutMs": () => { },
77
+ // The push fanout reads the preview setting at every fanout.
78
+ "push.previews": () => { },
77
79
  // Scheduled-task settings are clamped to these bounds on every read.
78
80
  "schedules.minIntervalFloorMinutes": () => { },
79
81
  "schedules.maxTasksPerMemberCap": () => { },
@@ -377,6 +377,42 @@ export declare const OUTBOX_JOBS: {
377
377
  readonly removeOnFail: 1000;
378
378
  };
379
379
  };
380
+ readonly "push-fanout": {
381
+ readonly queue: "cap-push-deliver";
382
+ readonly idempotent: "Owes delivery jobs under deterministic ids; a repeat owes nothing new";
383
+ readonly processedIn: "packages/kernel/src/push/push-processor.ts";
384
+ readonly opts: {
385
+ readonly attempts: 5;
386
+ readonly backoff: {
387
+ readonly type: "exponential";
388
+ readonly delay: 5000;
389
+ };
390
+ readonly removeOnComplete: {
391
+ readonly age: 86400;
392
+ };
393
+ readonly removeOnFail: {
394
+ readonly age: 86400;
395
+ };
396
+ };
397
+ };
398
+ readonly "push-deliver": {
399
+ readonly queue: "cap-push-deliver";
400
+ readonly idempotent: "Completed jobs are kept a day under the deterministic id, so a repeated add is swallowed; a missing registration ends the job";
401
+ readonly processedIn: "packages/kernel/src/push/push-processor.ts";
402
+ readonly opts: {
403
+ readonly attempts: 5;
404
+ readonly backoff: {
405
+ readonly type: "exponential";
406
+ readonly delay: 10000;
407
+ };
408
+ readonly removeOnComplete: {
409
+ readonly age: 86400;
410
+ };
411
+ readonly removeOnFail: {
412
+ readonly age: 86400;
413
+ };
414
+ };
415
+ };
380
416
  readonly lifecycle: {
381
417
  readonly queue: "cap-kernel-lifecycle";
382
418
  readonly idempotent: "lifecycle handlers must be idempotent (the SDK contract): they delete what the plugin holds for the removed member, agent or org, and deleting it again is a no-op";
@@ -343,6 +343,36 @@ export const OUTBOX_JOBS = {
343
343
  removeOnFail: 1000,
344
344
  },
345
345
  },
346
+ // `push/jobs.ts` PUSH_FANOUT_JOB: one per trigger event, owed in the event's transaction by
347
+ // `PushOwed` under `pushFanoutJobId` (`push-fanout-<eventId>`, mobile app spec §9.4)
348
+ "push-fanout": {
349
+ queue: "cap-push-deliver",
350
+ idempotent: "Owes delivery jobs under deterministic ids; a repeat owes nothing new",
351
+ processedIn: "packages/kernel/src/push/push-processor.ts",
352
+ // 5 attempts, 5 s doubling (PG briefly unavailable); finished and failed jobs kept a day, so
353
+ // an add of the same id within it is swallowed
354
+ opts: {
355
+ attempts: 5,
356
+ backoff: { type: "exponential", delay: 5_000 },
357
+ removeOnComplete: { age: 86_400 },
358
+ removeOnFail: { age: 86_400 },
359
+ },
360
+ },
361
+ // `push/jobs.ts` PUSH_DELIVER_JOB: one per event and registration, owed by the push fanout
362
+ // under `pushDeliverJobId` (`push-<eventId>-<registrationId>`, mobile app spec §9.4)
363
+ "push-deliver": {
364
+ queue: "cap-push-deliver",
365
+ idempotent: "Completed jobs are kept a day under the deterministic id, so a repeated add is swallowed; a missing registration ends the job",
366
+ processedIn: "packages/kernel/src/push/push-processor.ts",
367
+ // 5 attempts, 10 s doubling (transient and rate_limited answers, timeouts); finished and
368
+ // failed jobs kept a day, so an add of the same id within it is swallowed
369
+ opts: {
370
+ attempts: 5,
371
+ backoff: { type: "exponential", delay: 10_000 },
372
+ removeOnComplete: { age: 86_400 },
373
+ removeOnFail: { age: 86_400 },
374
+ },
375
+ },
346
376
  // `extensions/lifecycle-hooks.ts` LIFECYCLE_JOB: owed by the transaction that removes a member,
347
377
  // deletes an agent or deletes an org, once per subscribing plugin, under `lifecycleJobId`
348
378
  // (memory plugin spec §6.3)
@@ -4,5 +4,5 @@
4
4
  * (admin/health.service.ts) lists the same names from the feature constants;
5
5
  * test/infra/queue-names.test.ts keeps the two equal.
6
6
  */
7
- export declare const KERNEL_QUEUES: 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_QUEUES: 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
  export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
@@ -15,4 +15,5 @@ export const KERNEL_QUEUES = [
15
15
  "cap-kernel-usage-report",
16
16
  "cap-kernel-evals",
17
17
  "cap-kernel-lifecycle",
18
+ "cap-push-deliver",
18
19
  ];
@@ -24,6 +24,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
24
24
  import { Transactional } from "../infra/database/transactional.decorator.js";
25
25
  import { OutboxService } from "../infra/outbox/outbox.service.js";
26
26
  import { KERNEL_LOGGER } from "../infra/tokens.js";
27
+ import { deletePushRegistrationsForSessions } from "../push/registration-cleanup.js";
27
28
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
28
29
  import { RunControl } from "../runtime/run-control.js";
29
30
  import { oweDeviceDestroy } from "../sandbox/jobs.js";
@@ -208,6 +209,8 @@ let Offboarding = class Offboarding {
208
209
  .returning("id")
209
210
  .execute()
210
211
  : [];
212
+ // a registration follows its session (push plan decision 3)
213
+ await deletePushRegistrationsForSessions(this.db.db, sessions.map((r) => r.id));
211
214
  // in this transaction (the approvals and questions services join it: `mandatory`)
212
215
  const credentials = await this.credentials.clearAccount(orgId, accountId);
213
216
  // only in the conversations locked above (one asked meanwhile elsewhere waits for its run's stop)
@@ -19,6 +19,7 @@ import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
19
19
  import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
20
20
  import type { KernelQueueName } from "./infra/queue/queue-names.js";
21
21
  import { DEVICE_POLICY_AFTER_CALL } from "./local-devices/device-policy.service.js";
22
+ import { PUSH_SEND_TIMEOUT_MS } from "./push/delivery.js";
22
23
  import { PROJECT_KNOWLEDGE_TIMEOUT } from "./runtime/project/knowledge.service.js";
23
24
  import { LIST_MODELS_TIMEOUT } from "./runtime/providers.js";
24
25
  import { RUN_CONTEXT_CLOCK } from "./runtime/run-context.service.js";
@@ -61,6 +62,8 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
61
62
  * recorded (throwing stands for a crash between the call and the resolve transaction);
62
63
  * - `PROJECT_KNOWLEDGE_TIMEOUT`: the run-start read of a bound project's time limit, read at every
63
64
  * read (a test shortens it for one run);
65
+ * - `PUSH_SEND_TIMEOUT_MS`: one push send's time limit, read at every send (a test shortens it
66
+ * for a hanging provider);
64
67
  * - `PROMPT_SUGGESTION_TIMEOUT`: the prompt suggestion call's time limit, read at every call (a test
65
68
  * shortens it for one call);
66
69
  * - `PLUGIN_PUBLIC_WRITE_LIMIT`: a lower limit for unsafe methods on `public` extension routes;
@@ -100,6 +103,7 @@ interface KernelSeams {
100
103
  [SCOPE_ORG_CHUNK_SIZE]: number;
101
104
  [PROJECT_KNOWLEDGE_TIMEOUT]: () => number;
102
105
  [PROMPT_SUGGESTION_TIMEOUT]: () => number;
106
+ [PUSH_SEND_TIMEOUT_MS]: () => number;
103
107
  [PLUGIN_PUBLIC_WRITE_LIMIT]: number;
104
108
  [DEVICE_POLICY_AFTER_CALL]: (opId: string) => void;
105
109
  [EXTENSION_NET_SEAMS]: ExtensionNetSeams;
package/dist/overrides.js CHANGED
@@ -16,6 +16,7 @@ import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
16
16
  import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
17
17
  import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
18
18
  import { DEVICE_POLICY_AFTER_CALL } from "./local-devices/device-policy.service.js";
19
+ import { PUSH_SEND_TIMEOUT_MS } from "./push/delivery.js";
19
20
  import { PROJECT_KNOWLEDGE_TIMEOUT } from "./runtime/project/knowledge.service.js";
20
21
  import { LIST_MODELS_TIMEOUT } from "./runtime/providers.js";
21
22
  import { RUN_CONTEXT_CLOCK } from "./runtime/run-context.service.js";
@@ -55,6 +56,7 @@ const SEAM_TOKENS = [
55
56
  SCOPE_ORG_CHUNK_SIZE,
56
57
  PROJECT_KNOWLEDGE_TIMEOUT,
57
58
  PROMPT_SUGGESTION_TIMEOUT,
59
+ PUSH_SEND_TIMEOUT_MS,
58
60
  PLUGIN_PUBLIC_WRITE_LIMIT,
59
61
  DEVICE_POLICY_AFTER_CALL,
60
62
  EXTENSION_NET_SEAMS,
@@ -447,6 +447,21 @@ export const PLATFORM_EXCLUSIONS = [
447
447
  category: "human-only",
448
448
  reason: "Revokes a personal access token",
449
449
  },
450
+ {
451
+ route: "POST /api/v1/me/push-registrations",
452
+ category: "human-only",
453
+ reason: "Registers the person's own app install for push; a device action of the person's app",
454
+ },
455
+ {
456
+ route: "DELETE /api/v1/me/push-registrations/:id",
457
+ category: "human-only",
458
+ reason: "Removes one of the person's app installs from push (sign-out, profile removal, settings)",
459
+ },
460
+ {
461
+ route: "GET /api/v1/me/push-registrations",
462
+ category: "human-only",
463
+ reason: "Lists the person's own app installs that receive push, for the settings page",
464
+ },
450
465
  {
451
466
  route: "GET /api/v1/auth/sources",
452
467
  category: "internal",
@@ -4,8 +4,10 @@ import { ExtensionAdminOps } from "../../extensions/admin-ops.js";
4
4
  import { ExtensionAdmin } from "../../extensions/admin-view.js";
5
5
  import { type DeploymentConfigView, ExtensionDeploymentConfigService } from "../../extensions/deployment-config.js";
6
6
  import { ExtensionInstalls } from "../../extensions/installs.js";
7
+ import { PluginGuides } from "../../extensions/plugin-guides.js";
7
8
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
8
9
  import { KernelDb } from "../../infra/database/kernel-db.js";
10
+ import { SetupChecksService } from "../../setup/setup-checks.service.js";
9
11
  import { type PersonFieldTarget } from "../person-fields.js";
10
12
  import { PlatformOperations } from "../registry.js";
11
13
  /**
@@ -33,7 +35,9 @@ export declare class ExtensionsAdminOperations implements OnModuleInit {
33
35
  private readonly catalog;
34
36
  private readonly deploymentConfigs;
35
37
  private readonly installs;
36
- constructor(registry: PlatformOperations, admin: ExtensionAdmin, ops: ExtensionAdminOps, config: KernelConfigService, kdb: KernelDb, catalog: CatalogService, deploymentConfigs: ExtensionDeploymentConfigService, installs: ExtensionInstalls);
38
+ private readonly guides;
39
+ private readonly checks;
40
+ constructor(registry: PlatformOperations, admin: ExtensionAdmin, ops: ExtensionAdminOps, config: KernelConfigService, kdb: KernelDb, catalog: CatalogService, deploymentConfigs: ExtensionDeploymentConfigService, installs: ExtensionInstalls, guides: Pick<PluginGuides, "deploymentGuides">, checks: Pick<SetupChecksService, "deploymentStates" | "deploymentRun">);
37
41
  /** The view of `name` for a precheck, or the refusal (unknown, startup-declared). */
38
42
  private viewFor;
39
43
  onModuleInit(): void;
@@ -16,10 +16,13 @@ import { ExtensionAdminOps } from "../../extensions/admin-ops.js";
16
16
  import { ExtensionAdmin } from "../../extensions/admin-view.js";
17
17
  import { ExtensionDeploymentConfigService, } from "../../extensions/deployment-config.js";
18
18
  import { ExtensionInstalls } from "../../extensions/installs.js";
19
+ import { PluginGuides } from "../../extensions/plugin-guides.js";
19
20
  import { SINGLE_PROVIDER_ENABLED, SINGLE_PROVIDER_REQUIRED, singleProviderMessage, } from "../../extensions/single-provider.js";
20
21
  import { unavailableReason } from "../../extensions/unavailable.js";
21
22
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
22
23
  import { KernelDb } from "../../infra/database/kernel-db.js";
24
+ import { DeploymentCheckPathParams, DeploymentCheckRunBody, DeploymentGuidePathParams, DeploymentGuidesPathParams, DeploymentGuidesQuery, } from "../../setup/setup-checks.schemas.js";
25
+ import { SetupChecksService } from "../../setup/setup-checks.service.js";
23
26
  import { FileRefSchema } from "../file-ref.js";
24
27
  import { defineOperation } from "../operation.js";
25
28
  import { pathsTouched, personFieldParams, secretFieldsOf, } from "../person-fields.js";
@@ -143,7 +146,9 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
143
146
  catalog;
144
147
  deploymentConfigs;
145
148
  installs;
146
- constructor(registry, admin, ops, config, kdb, catalog, deploymentConfigs, installs) {
149
+ guides;
150
+ checks;
151
+ constructor(registry, admin, ops, config, kdb, catalog, deploymentConfigs, installs, guides, checks) {
147
152
  this.registry = registry;
148
153
  this.admin = admin;
149
154
  this.ops = ops;
@@ -152,6 +157,8 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
152
157
  this.catalog = catalog;
153
158
  this.deploymentConfigs = deploymentConfigs;
154
159
  this.installs = installs;
160
+ this.guides = guides;
161
+ this.checks = checks;
155
162
  }
156
163
  /** The view of `name` for a precheck, or the refusal (unknown, startup-declared). */
157
164
  async viewFor(name, orgId) {
@@ -606,6 +613,92 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
606
613
  return { config: view };
607
614
  },
608
615
  }),
616
+ defineOperation({
617
+ id: "extensions.platform-guides",
618
+ description: "Read an extension's platform setup guides (super admin): the guides it ships for its deployment config (for example a push provider's credentials), rendered with the steps and the checks as check rows (run them with extensions.platform-check). Secrets are never in a guide: the person types each one into the deployment config form in the admin console (Extensions → the extension), or on the confirmation card of extensions.platform-set-config. Empty when the extension ships none.",
619
+ input: DeploymentGuidesPathParams.extend(DeploymentGuidesQuery.shape).strict(),
620
+ example: { name: "push-apns" },
621
+ authz: { superAdmin: true },
622
+ mirrors: ["GET /api/v1/admin/extensions/:name/guides"],
623
+ confirm: "read",
624
+ errors: [
625
+ {
626
+ code: "extension.not_found",
627
+ next: "Check the extension name with extensions.platform-list.",
628
+ },
629
+ ],
630
+ run: async (input, ctx) => {
631
+ await assertExtensionNotOtherOrgs(this.kdb.db, input.name, ctx.orgId);
632
+ return { guides: await this.guides.deploymentGuides(input.name, input) };
633
+ },
634
+ handoff: (input) => ({
635
+ kind: "handoff",
636
+ title: {
637
+ zh: "在扩展页面填写部署配置",
638
+ en: "Fill in the deployment config on the extension page",
639
+ },
640
+ target: { type: "link", url: `/admin/extensions/${encodeURIComponent(input.name)}` },
641
+ }),
642
+ }),
643
+ defineOperation({
644
+ id: "extensions.platform-check-status",
645
+ description: "Read the cached state of every check of an extension's platform setup guide, by check id: ok, failing, unknown, running or not_run, with the reason and fix to show the person. Runs nothing; run a check with extensions.platform-check.",
646
+ input: DeploymentGuidePathParams.strict(),
647
+ example: { name: "push-apns", guideId: "apns-key" },
648
+ authz: { superAdmin: true },
649
+ mirrors: ["GET /api/v1/admin/extensions/:name/guides/:guideId/checks"],
650
+ confirm: "read",
651
+ errors: [
652
+ {
653
+ code: "extension.not_found",
654
+ next: "Check the extension name with extensions.platform-list.",
655
+ },
656
+ {
657
+ code: "catalog.guide_not_found",
658
+ next: "The extension has no platform setup guide with that id; list them with extensions.platform-guides.",
659
+ },
660
+ ],
661
+ run: async (input, ctx) => {
662
+ await assertExtensionNotOtherOrgs(this.kdb.db, input.name, ctx.orgId);
663
+ return {
664
+ results: await this.checks.deploymentStates(ctx.actorAccountId, input.name, input.guideId),
665
+ };
666
+ },
667
+ }),
668
+ defineOperation({
669
+ id: "extensions.platform-check",
670
+ description: "Run one check of an extension's platform setup guide against its deployment config and return its state: ok, failing (with a reason and a fix to explain), unknown, or running (try again in a moment). A fresh cached result is returned as is; force reruns it, at most once per 10 seconds per check. A check only reads; run it after the person says they saved the config. The result is shown to you: the kernel redacts exact matches of whole secret values of 8 characters or more, so a well-behaved check never echoes any part of a secret, and you never repeat a value that looks like one.",
671
+ input: DeploymentCheckPathParams.extend(DeploymentCheckRunBody.shape).strict(),
672
+ example: { name: "push-apns", guideId: "apns-key", checkId: "key-works" },
673
+ authz: { superAdmin: true },
674
+ mirrors: ["POST /api/v1/admin/extensions/:name/guides/:guideId/checks/:checkId/run"],
675
+ confirm: "read",
676
+ errors: [
677
+ {
678
+ code: "extension.not_found",
679
+ next: "Check the extension name with extensions.platform-list.",
680
+ },
681
+ {
682
+ code: "catalog.guide_not_found",
683
+ next: "The extension has no platform setup guide with that id; list them with extensions.platform-guides.",
684
+ },
685
+ {
686
+ code: "catalog.check_not_found",
687
+ next: "That check is not in the guide; read the check ids with extensions.platform-check-status.",
688
+ },
689
+ {
690
+ code: "rate_limited",
691
+ next: "This person ran 30 checks in the last minute; wait a minute before running another, and read the cached states with extensions.platform-check-status meanwhile.",
692
+ },
693
+ ],
694
+ run: async (input, ctx) => {
695
+ await assertExtensionNotOtherOrgs(this.kdb.db, input.name, ctx.orgId);
696
+ const { name, guideId, checkId, ...body } = input;
697
+ return {
698
+ result: await this.checks.deploymentRun(ctx.actorAccountId, name, guideId, checkId, body),
699
+ };
700
+ },
701
+ }),
609
702
  ]);
610
703
  }
611
704
  };
@@ -618,6 +711,8 @@ ExtensionsAdminOperations = __decorate([
618
711
  __param(4, Inject(KernelDb)),
619
712
  __param(5, Inject(CatalogService)),
620
713
  __param(6, Inject(ExtensionDeploymentConfigService)),
621
- __param(7, Inject(ExtensionInstalls))
714
+ __param(7, Inject(ExtensionInstalls)),
715
+ __param(8, Inject(PluginGuides)),
716
+ __param(9, Inject(SetupChecksService))
622
717
  ], ExtensionsAdminOperations);
623
718
  export { ExtensionsAdminOperations };
@@ -17,7 +17,7 @@ export declare class InboxOperations implements OnModuleInit {
17
17
  constructor(registry: PlatformOperations, inbox: InboxService, platformInbox: PlatformInboxService, kdb: KernelDb);
18
18
  /** The org's open notice `id` when the actor is an org admin (else null: not found). */
19
19
  private orgNotice;
20
- /** A platform notice by id (dismissed or not), or null. */
20
+ /** A platform notice's subject name by id (dismissed or not), or null. */
21
21
  private platformNotice;
22
22
  /** Org ids that own each of `itemIds` (platform items: absent). */
23
23
  private owners;
@@ -199,6 +199,14 @@ function platformRow(i) {
199
199
  summary: platformNoticeSummary(i.notice.detail),
200
200
  next: "Dismiss it with inbox.platform-dismiss-notice once read.",
201
201
  };
202
+ case "push_auth_failed":
203
+ return {
204
+ ...base,
205
+ name: i.notice.detail.plugin,
206
+ state: "open",
207
+ summary: `The push provider ${i.notice.detail.plugin} had its credentials refused on a delivery; pushes through it fail until its deployment config is fixed.`,
208
+ next: "Fix the extension's deployment config in the admin console, then dismiss it with inbox.platform-dismiss-notice.",
209
+ };
202
210
  }
203
211
  }
204
212
  /**
@@ -242,18 +250,20 @@ let InboxOperations = class InboxOperations {
242
250
  const base = { id: row.id, createdAt: row.created_at.toISOString() };
243
251
  return { ...base, kind: row.kind, detail: row.detail };
244
252
  }
245
- /** A platform notice by id (dismissed or not), or null. */
253
+ /** A platform notice's subject name by id (dismissed or not), or null. */
246
254
  async platformNotice(id) {
247
255
  if (!UUID_RE.test(id))
248
256
  return null;
249
257
  const row = await this.kdb.db
250
258
  .selectFrom("platform_notices")
251
- .select(["id", "detail"])
259
+ .select(["id", "kind", "detail"])
252
260
  .where("id", "=", id)
253
261
  .executeTakeFirst();
254
- return row === undefined
255
- ? null
256
- : row.detail;
262
+ if (row === undefined)
263
+ return null;
264
+ return row.kind === "push_auth_failed"
265
+ ? { name: row.detail.plugin }
266
+ : { name: row.detail.name };
257
267
  }
258
268
  /** Org ids that own each of `itemIds` (platform items: absent). */
259
269
  async owners(itemIds) {
@@ -368,7 +378,7 @@ let InboxOperations = class InboxOperations {
368
378
  }),
369
379
  defineOperation({
370
380
  id: "inbox.platform-dismiss-notice",
371
- description: "Dismiss a platform notice (super admin) for every super admin: the id of an ownership_transferred row from inbox.platform-list. Other platform inbox items go away when they are dealt with in the admin console.",
381
+ description: "Dismiss a platform notice (super admin) for every super admin: the id of an ownership_transferred or push_auth_failed row from inbox.platform-list. Other platform inbox items go away when they are dealt with in the admin console.",
372
382
  input: NoticeInput,
373
383
  example: NOTICE_EXAMPLE,
374
384
  authz: { superAdmin: true },
@@ -377,7 +387,7 @@ let InboxOperations = class InboxOperations {
377
387
  errors: [
378
388
  {
379
389
  code: "inbox.notice_not_found",
380
- next: "No platform notice has that id; list them with inbox.platform-list (ownership_transferred rows).",
390
+ next: "No platform notice has that id; list them with inbox.platform-list (ownership_transferred and push_auth_failed rows).",
381
391
  },
382
392
  ],
383
393
  precheck: async (input) => (await this.platformNotice(input.id)) === null ? NOT_FOUND : { ok: true },
@@ -4,13 +4,14 @@ import { AccountsService } from "../../identity/accounts.js";
4
4
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
5
5
  import { KernelDb } from "../../infra/database/kernel-db.js";
6
6
  import { OrgSettingsService } from "../../orgs/settings.service.js";
7
+ import { PushPreferencesService } from "../../push/preferences.service.js";
7
8
  import { ThemesService } from "../../themes/themes.service.js";
8
9
  import { ToolRegistry } from "../../tools/registry.js";
9
10
  import { PlatformActor } from "../actor.js";
10
11
  import { PlatformOperations } from "../registry.js";
11
12
  /**
12
13
  * The `platform` domain: orientation and what this agent is (spec §7, synthetic), and the
13
- * person's own preferences (`/me/preferences`).
14
+ * person's own preferences (`/me/preferences`, `/me/push-preferences`).
14
15
  */
15
16
  export declare class PlatformOperationsProvider implements OnModuleInit {
16
17
  private readonly registry;
@@ -22,7 +23,8 @@ export declare class PlatformOperationsProvider implements OnModuleInit {
22
23
  private readonly themes;
23
24
  private readonly db;
24
25
  private readonly config;
25
- constructor(registry: PlatformOperations, actor: PlatformActor, agents: AgentsService, settings: OrgSettingsService, tools: ToolRegistry, accounts: AccountsService, themes: ThemesService, db: KernelDb, config: KernelConfigService);
26
+ private readonly push;
27
+ constructor(registry: PlatformOperations, actor: PlatformActor, agents: AgentsService, settings: OrgSettingsService, tools: ToolRegistry, accounts: AccountsService, themes: ThemesService, db: KernelDb, config: KernelConfigService, push: PushPreferencesService);
26
28
  /**
27
29
  * The skills in the agent's catalog now, by the names a run's catalog lists them, each with its
28
30
  * plugin (skills default-on spec §11): the resolver's result for this conversation, as the next