@capybara-hq/kernel 0.1.0-rc.57 → 0.1.0-rc.59

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 (126) hide show
  1. package/dist/admin/extensions.controller.d.ts +2 -10
  2. package/dist/admin/extensions.controller.js +2 -24
  3. package/dist/admin/extensions.schemas.d.ts +21 -0
  4. package/dist/admin/extensions.schemas.js +37 -0
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/catalog/org-catalog.controller.d.ts +0 -5
  7. package/dist/catalog/org-catalog.controller.js +3 -17
  8. package/dist/catalog/org-catalog.schemas.d.ts +43 -0
  9. package/dist/catalog/org-catalog.schemas.js +43 -2
  10. package/dist/catalog/org-extension-switch.d.ts +3 -1
  11. package/dist/catalog/org-extension-switch.js +12 -5
  12. package/dist/catalog/org-extension.controller.d.ts +2 -21
  13. package/dist/catalog/org-extension.controller.js +1 -38
  14. package/dist/catalog/org-extension.schemas.d.ts +31 -0
  15. package/dist/catalog/org-extension.schemas.js +65 -0
  16. package/dist/catalog/plugin-install.d.ts +2 -0
  17. package/dist/catalog/plugin-install.js +3 -3
  18. package/dist/channels/actions.js +2 -0
  19. package/dist/channels/cards.d.ts +8 -0
  20. package/dist/channels/cards.js +18 -0
  21. package/dist/channels/channels.schemas.d.ts +3 -0
  22. package/dist/channels/channels.schemas.js +8 -0
  23. package/dist/channels/connections.service.d.ts +17 -2
  24. package/dist/channels/connections.service.js +30 -5
  25. package/dist/channels/outbound.js +25 -1
  26. package/dist/channels/phrases.d.ts +10 -0
  27. package/dist/channels/phrases.js +10 -0
  28. package/dist/conversations/conversations.module.js +4 -0
  29. package/dist/conversations/events.d.ts +35 -0
  30. package/dist/conversations/events.js +29 -0
  31. package/dist/conversations/leak-check.d.ts +26 -0
  32. package/dist/conversations/leak-check.js +69 -0
  33. package/dist/ctx/secrets.d.ts +13 -1
  34. package/dist/ctx/secrets.js +19 -1
  35. package/dist/db/kernel-schema.d.ts +34 -0
  36. package/dist/devices/working-root.d.ts +2 -3
  37. package/dist/errors.d.ts +19 -0
  38. package/dist/errors.js +19 -0
  39. package/dist/extensions/deployment-config.d.ts +6 -2
  40. package/dist/extensions/deployment-config.js +35 -23
  41. package/dist/extensions/org-config.d.ts +2 -0
  42. package/dist/extensions/org-config.js +1 -0
  43. package/dist/extensions/org-overrides.d.ts +2 -0
  44. package/dist/extensions/org-overrides.js +3 -2
  45. package/dist/http/api.module.js +6 -0
  46. package/dist/identity/initial-passwords.job.d.ts +3 -2
  47. package/dist/identity/initial-passwords.job.js +11 -5
  48. package/dist/orgs/invitations.controller.d.ts +3 -11
  49. package/dist/orgs/invitations.controller.js +9 -10
  50. package/dist/orgs/invitations.service.d.ts +12 -2
  51. package/dist/orgs/invitations.service.js +14 -7
  52. package/dist/orgs/members.service.d.ts +12 -2
  53. package/dist/orgs/members.service.js +10 -8
  54. package/dist/orgs/orgs.controller.d.ts +4 -12
  55. package/dist/orgs/orgs.controller.js +10 -10
  56. package/dist/orgs/orgs.schemas.d.ts +26 -0
  57. package/dist/orgs/orgs.schemas.js +22 -0
  58. package/dist/platform/connector-person-fields.d.ts +67 -0
  59. package/dist/platform/connector-person-fields.js +129 -0
  60. package/dist/platform/exclusions.js +6 -141
  61. package/dist/platform/method.js +1 -0
  62. package/dist/platform/operation.d.ts +61 -2
  63. package/dist/platform/operation.js +4 -4
  64. package/dist/platform/ops/accounts.ops.js +1 -0
  65. package/dist/platform/ops/channels.ops.d.ts +10 -3
  66. package/dist/platform/ops/channels.ops.js +223 -5
  67. package/dist/platform/ops/connectors.ops.d.ts +22 -4
  68. package/dist/platform/ops/connectors.ops.js +664 -13
  69. package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
  70. package/dist/platform/ops/extensions-admin.ops.js +153 -5
  71. package/dist/platform/ops/extensions.ops.d.ts +19 -5
  72. package/dist/platform/ops/extensions.ops.js +285 -10
  73. package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
  74. package/dist/platform/ops/org-plugins.ops.js +323 -4
  75. package/dist/platform/ops/orgs.ops.d.ts +40 -3
  76. package/dist/platform/ops/orgs.ops.js +293 -12
  77. package/dist/platform/ops/person-inputs.d.ts +65 -0
  78. package/dist/platform/ops/person-inputs.js +129 -0
  79. package/dist/platform/ops/plugins.ops.d.ts +3 -1
  80. package/dist/platform/ops/plugins.ops.js +33 -20
  81. package/dist/platform/parity.d.ts +7 -2
  82. package/dist/platform/parity.js +75 -13
  83. package/dist/platform/person-fields.d.ts +119 -0
  84. package/dist/platform/person-fields.js +403 -0
  85. package/dist/platform/platform.module.d.ts +4 -3
  86. package/dist/platform/platform.module.js +8 -5
  87. package/dist/platform/route-schemas.js +2 -0
  88. package/dist/platform/sealed-inputs.d.ts +44 -0
  89. package/dist/platform/sealed-inputs.js +116 -0
  90. package/dist/platform/sealed-reveals.controller.d.ts +20 -0
  91. package/dist/platform/sealed-reveals.controller.js +48 -0
  92. package/dist/platform/sealed-reveals.d.ts +52 -0
  93. package/dist/platform/sealed-reveals.js +153 -0
  94. package/dist/runtime/project/knowledge.js +24 -19
  95. package/dist/runtime/waits.js +8 -2
  96. package/dist/sandbox/permission-facts.d.ts +5 -1
  97. package/dist/sandbox/permission-facts.js +8 -2
  98. package/dist/setup/setup-guides.service.d.ts +5 -0
  99. package/dist/setup/setup-guides.service.js +2 -1
  100. package/dist/tools/approvals.controller.d.ts +1 -0
  101. package/dist/tools/approvals.controller.js +19 -0
  102. package/dist/tools/approvals.service.d.ts +50 -1
  103. package/dist/tools/approvals.service.js +118 -10
  104. package/dist/tools/builtins/builtin-tools.d.ts +3 -0
  105. package/dist/tools/builtins/builtin-tools.js +31 -9
  106. package/dist/tools/builtins/platform.d.ts +20 -0
  107. package/dist/tools/builtins/platform.js +214 -15
  108. package/dist/tools/connectors.controller.d.ts +6 -7
  109. package/dist/tools/connectors.controller.js +4 -44
  110. package/dist/tools/connectors.schemas.d.ts +170 -1
  111. package/dist/tools/connectors.schemas.js +82 -3
  112. package/dist/tools/connectors.service.d.ts +16 -6
  113. package/dist/tools/connectors.service.js +39 -24
  114. package/dist/tools/oauth/oauth.controller.d.ts +3 -6
  115. package/dist/tools/oauth/oauth.controller.js +3 -12
  116. package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
  117. package/dist/tools/oauth/oauth.schemas.js +27 -0
  118. package/dist/tools/pipeline.d.ts +31 -2
  119. package/dist/tools/pipeline.js +89 -17
  120. package/dist/tools/policy.d.ts +4 -0
  121. package/dist/tools/policy.js +8 -0
  122. package/dist/tools/registry.d.ts +29 -0
  123. package/dist/tools/tools.module.js +3 -0
  124. package/package.json +3 -3
  125. package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
  126. package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
@@ -114,6 +114,38 @@ export interface AccountInitialPasswordsTable {
114
114
  expires_at: Date | string;
115
115
  created_at: Ts;
116
116
  }
117
+ /** A person's sealed card values for one approval (migration 0169). */
118
+ export interface PlatformSealedInputsTable {
119
+ approval_id: string;
120
+ recipient_account_id: string;
121
+ conversation_id: string;
122
+ run_id: string;
123
+ call_id: string;
124
+ /** The sorted field paths; part of the AAD. */
125
+ paths: string[];
126
+ master_key_id: string;
127
+ ciphertext: Buffer;
128
+ expires_at: Date | string;
129
+ created_at: Ts;
130
+ }
131
+ /**
132
+ * A value a Platform call made for the person who approved it, read once on the web (migration
133
+ * 0170; first kind: an invitation link).
134
+ */
135
+ export interface PlatformSealedRevealsTable {
136
+ /** The subject the value belongs to (the invitation id); part of the AAD. */
137
+ id: string;
138
+ kind: "invitation_link";
139
+ org_id: string;
140
+ recipient_account_id: string;
141
+ conversation_id: string;
142
+ run_id: string;
143
+ call_id: string;
144
+ master_key_id: string;
145
+ ciphertext: Buffer;
146
+ expires_at: Date | string;
147
+ created_at: Ts;
148
+ }
117
149
  export interface IdentitiesTable {
118
150
  source: string;
119
151
  external_id: string;
@@ -1610,6 +1642,8 @@ export interface KernelDatabase {
1610
1642
  permission_config_publication: PermissionConfigPublicationTable;
1611
1643
  org_data_keys: OrgDataKeysTable;
1612
1644
  account_initial_passwords: AccountInitialPasswordsTable;
1645
+ platform_sealed_inputs: PlatformSealedInputsTable;
1646
+ platform_sealed_reveals: PlatformSealedRevealsTable;
1613
1647
  identities: IdentitiesTable;
1614
1648
  local_passwords: LocalPasswordsTable;
1615
1649
  orgs: OrgsTable;
@@ -1,9 +1,8 @@
1
1
  import type { SandboxMode } from "../sandbox/modes.js";
2
2
  /**
3
3
  * What decides a conversation's working root (project root spec §4.3): the latest `project_root`
4
- * event of its root conversation (sub-agents inherit their root's binding). Null: the conversation
5
- * is free, or no run of it has recorded a snapshot yet (a bound conversation before its first run
6
- * start, an older log).
4
+ * event of its root conversation (sub-agents inherit their root's binding), or the bound root
5
+ * itself while no run has recorded one yet. Null: the conversation is free.
7
6
  */
8
7
  export interface WorkingProject {
9
8
  /** The project's root on the device, as the event recorded it. */
package/dist/errors.d.ts CHANGED
@@ -93,9 +93,19 @@ export declare const ERROR_CODES: {
93
93
  readonly "member.not_found": 404;
94
94
  readonly "member.already_exists": 409;
95
95
  readonly "member.anonymous_guest": 409;
96
+ /** A Platform member operation aimed at the actor's own membership (spec §7.2: never offered). */
97
+ readonly "member.self": 403;
98
+ /** A Platform member operation touching an owner or granting owner (spec §7.2). */
99
+ readonly "member.owner_untouchable": 403;
100
+ /** A Platform member operation raising someone above the actor's own role (spec §7.2). */
101
+ readonly "member.role_above_actor": 403;
96
102
  readonly "invitation.invalid": 404;
97
103
  readonly "invitation.expired": 410;
98
104
  readonly "invitation.used": 409;
105
+ /** `orgs.invite` outside an approved Platform call: its link could never be shown. */
106
+ readonly "invitation.create_needs_approval": 409;
107
+ /** No invitation link to show: read already, expired, or not a call the reader approved. */
108
+ readonly "invitation.link_unavailable": 404;
99
109
  readonly "extension.not_found": 404;
100
110
  /** The extension registers no tool of that name (org tool switches, layering spec A §7). */
101
111
  readonly "extension.tool_not_found": 404;
@@ -369,6 +379,15 @@ export declare const ERROR_CODES: {
369
379
  readonly "approval.already_decided": 409;
370
380
  readonly "approval.scope_not_allowed": 409;
371
381
  readonly "approval.not_yours": 403;
382
+ /**
383
+ * An approval with person fields (platform web parity spec §4.2): a value missing or not valid
384
+ * against its schema node (`details: [{ fields: { path, problem }[] }]`, never a value).
385
+ */
386
+ readonly "approval.inputs_invalid": 422;
387
+ /** An entered value appeared in the conversation (§4.5; `details: [{ fields: path[] }]`). */
388
+ readonly "approval.input_leaked": 422;
389
+ /** Inputs for an approval that asks for none, or for a path it does not ask for. */
390
+ readonly "approval.inputs_not_expected": 400;
372
391
  readonly "question.not_found": 404;
373
392
  readonly "question.already_answered": 409;
374
393
  readonly "tool_output.not_found": 404;
package/dist/errors.js CHANGED
@@ -93,9 +93,19 @@ export const ERROR_CODES = {
93
93
  "member.not_found": 404,
94
94
  "member.already_exists": 409,
95
95
  "member.anonymous_guest": 409,
96
+ /** A Platform member operation aimed at the actor's own membership (spec §7.2: never offered). */
97
+ "member.self": 403,
98
+ /** A Platform member operation touching an owner or granting owner (spec §7.2). */
99
+ "member.owner_untouchable": 403,
100
+ /** A Platform member operation raising someone above the actor's own role (spec §7.2). */
101
+ "member.role_above_actor": 403,
96
102
  "invitation.invalid": 404,
97
103
  "invitation.expired": 410,
98
104
  "invitation.used": 409,
105
+ /** `orgs.invite` outside an approved Platform call: its link could never be shown. */
106
+ "invitation.create_needs_approval": 409,
107
+ /** No invitation link to show: read already, expired, or not a call the reader approved. */
108
+ "invitation.link_unavailable": 404,
99
109
  "extension.not_found": 404,
100
110
  /** The extension registers no tool of that name (org tool switches, layering spec A §7). */
101
111
  "extension.tool_not_found": 404,
@@ -369,6 +379,15 @@ export const ERROR_CODES = {
369
379
  "approval.already_decided": 409,
370
380
  "approval.scope_not_allowed": 409,
371
381
  "approval.not_yours": 403,
382
+ /**
383
+ * An approval with person fields (platform web parity spec §4.2): a value missing or not valid
384
+ * against its schema node (`details: [{ fields: { path, problem }[] }]`, never a value).
385
+ */
386
+ "approval.inputs_invalid": 422,
387
+ /** An entered value appeared in the conversation (§4.5; `details: [{ fields: path[] }]`). */
388
+ "approval.input_leaked": 422,
389
+ /** Inputs for an approval that asks for none, or for a path it does not ask for. */
390
+ "approval.inputs_not_expected": 400,
372
391
  "question.not_found": 404,
373
392
  "question.already_answered": 409,
374
393
  "tool_output.not_found": 404,
@@ -158,7 +158,9 @@ export declare class ExtensionDeploymentConfigService {
158
158
  * (detail only `changedPaths`). After the commit publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} and
159
159
  * applies it on this replica right away.
160
160
  */
161
- put(plugin: string, values: Record<string, unknown>, actor: string, actorTokenId?: string, secretEntries?: readonly SecretEntry[]): Promise<DeploymentConfigView>;
161
+ put(plugin: string, values: Record<string, unknown>, actor: string, actorTokenId?: string, secretEntries?: readonly SecretEntry[],
162
+ /** Merged into the audit detail (a Platform operation's `via: "agent"`). */
163
+ auditDetail?: Record<string, unknown>): Promise<DeploymentConfigView>;
162
164
  /**
163
165
  * Clears the deployment config stored in PG: the `extension_deployment_configs` row and every
164
166
  * secret stored for the extension (any path, also ones an older version declared). Fields from
@@ -172,7 +174,9 @@ export declare class ExtensionDeploymentConfigService {
172
174
  * and the extension loads from what remains, or is unloaded and becomes pending configuration
173
175
  * when that is missing or invalid (`ExtensionHost.applyDeploymentConfig`), without a restart.
174
176
  */
175
- clear(plugin: string, actor: string, actorTokenId?: string): Promise<DeploymentConfigView>;
177
+ clear(plugin: string, actor: string, actorTokenId?: string,
178
+ /** Merged into the audit detail (a Platform operation's `via: "agent"`). */
179
+ auditDetail?: Record<string, unknown>): Promise<DeploymentConfigView>;
176
180
  private clearStored;
177
181
  /**
178
182
  * Secret entries name a secret record field some hint names (else 400 `validation_failed`, also
@@ -149,7 +149,9 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
149
149
  * (detail only `changedPaths`). After the commit publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} and
150
150
  * applies it on this replica right away.
151
151
  */
152
- async put(plugin, values, actor, actorTokenId, secretEntries = []) {
152
+ async put(plugin, values, actor, actorTokenId, secretEntries = [],
153
+ /** Merged into the audit detail (a Platform operation's `via: "agent"`). */
154
+ auditDetail) {
153
155
  const info = await this.info(plugin);
154
156
  if (info.fields.length === 0) {
155
157
  throw new ApiError("extension.config_invalid", `Extension ${plugin} has no deployment config`);
@@ -168,7 +170,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
168
170
  }
169
171
  const fileValue = this.fileConfig()[plugin];
170
172
  const fieldPaths = info.fields.map((f) => f.path);
171
- const { saved, changed } = await this.write(plugin, values, secretEntries, actor, actorTokenId, info, sources, fileValue);
173
+ const { saved, changed } = await this.write(plugin, values, secretEntries, actor, actorTokenId, info, sources, fileValue, auditDetail);
172
174
  const stored = saved ?? {};
173
175
  if (info.schema) {
174
176
  const secrets = secretValues(info.schema, mergeDeploymentConfig(stored, fileValue, fieldPaths));
@@ -176,21 +178,29 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
176
178
  this.log.addSecrets(secrets);
177
179
  }
178
180
  if (changed.length > 0) {
179
- try {
180
- await this.bus.publish(PLUGIN_DEPLOYMENT_CONFIG_TOPIC, { plugin });
181
- }
182
- catch (err) {
183
- this.log.warn("cannot publish plugin-deployment-config after saving", { plugin, err });
184
- }
185
- try {
186
- await this.lifecycle.applyConfig(plugin);
187
- }
188
- catch (err) {
189
- this.log.error("applying the plugin deployment config on this replica failed", {
190
- plugin,
191
- err,
192
- });
193
- }
181
+ const applyEverywhere = async () => {
182
+ try {
183
+ await this.bus.publish(PLUGIN_DEPLOYMENT_CONFIG_TOPIC, { plugin });
184
+ }
185
+ catch (err) {
186
+ this.log.warn("cannot publish plugin-deployment-config after saving", { plugin, err });
187
+ }
188
+ try {
189
+ await this.lifecycle.applyConfig(plugin);
190
+ }
191
+ catch (err) {
192
+ this.log.error("applying the plugin deployment config on this replica failed", {
193
+ plugin,
194
+ err,
195
+ });
196
+ }
197
+ };
198
+ // Inside a caller's transaction (a Platform write applying the person's sealed values) the
199
+ // save is not committed yet: replicas re-read only after the commit
200
+ if (this.txHost.current() !== undefined)
201
+ afterCommit(applyEverywhere);
202
+ else
203
+ await applyEverywhere();
194
204
  }
195
205
  return this.render(plugin, info, stored, await this.displayNames.get(plugin));
196
206
  }
@@ -207,12 +217,14 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
207
217
  * and the extension loads from what remains, or is unloaded and becomes pending configuration
208
218
  * when that is missing or invalid (`ExtensionHost.applyDeploymentConfig`), without a restart.
209
219
  */
210
- async clear(plugin, actor, actorTokenId) {
220
+ async clear(plugin, actor, actorTokenId,
221
+ /** Merged into the audit detail (a Platform operation's `via: "agent"`). */
222
+ auditDetail) {
211
223
  const info = await this.info(plugin);
212
- await this.clearStored(plugin, info.fields.map((f) => f.path), actor, actorTokenId);
224
+ await this.clearStored(plugin, info.fields.map((f) => f.path), actor, actorTokenId, auditDetail);
213
225
  return this.render(plugin, info, {}, await this.displayNames.get(plugin));
214
226
  }
215
- async clearStored(plugin, fieldPaths, actor, actorTokenId) {
227
+ async clearStored(plugin, fieldPaths, actor, actorTokenId, auditDetail) {
216
228
  const t = this.db;
217
229
  await this.adminLock.lockAndAuthorize(actor);
218
230
  await this.configLock.lock(plugin);
@@ -253,7 +265,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
253
265
  ...(actorTokenId !== undefined && { actorTokenId }),
254
266
  action: "extension.config_cleared",
255
267
  target: plugin,
256
- detail: { clearedPaths },
268
+ detail: { clearedPaths, ...auditDetail },
257
269
  });
258
270
  afterCommit(async () => {
259
271
  try {
@@ -302,7 +314,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
302
314
  throw new ApiError("validation_failed", `Invalid secret entries for the deployment config of extension ${plugin}`, problems);
303
315
  }
304
316
  }
305
- async write(plugin, values, secretEntries, actor, actorTokenId, info, sources, fileValue) {
317
+ async write(plugin, values, secretEntries, actor, actorTokenId, info, sources, fileValue, auditDetail) {
306
318
  const fieldPaths = info.fields.map((f) => f.path);
307
319
  let changed = [];
308
320
  const t = this.db;
@@ -366,7 +378,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
366
378
  ...(actorTokenId !== undefined && { actorTokenId }),
367
379
  action: "extension.deployment_config_updated",
368
380
  target: plugin,
369
- detail: { changedPaths: changed },
381
+ detail: { changedPaths: changed, ...auditDetail },
370
382
  });
371
383
  return { saved, changed };
372
384
  }
@@ -111,6 +111,8 @@ export interface OrgExtensionPutOptions {
111
111
  * dependencies) are left to that write: the plugin install that enables it checks them.
112
112
  */
113
113
  validateOnly?: boolean;
114
+ /** Merged into the audit detail (a Platform operation's `via: "agent"`). */
115
+ auditDetail?: Record<string, unknown>;
114
116
  }
115
117
  /**
116
118
  * An org's stored config of a plugin no longer matches its org schema (e.g. after a plugin upgrade):
@@ -418,6 +418,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
418
418
  enabled,
419
419
  changedPaths: changed,
420
420
  ...(opts.viaItem !== undefined && { catalogItemId: opts.viaItem }),
421
+ ...opts.auditDetail,
421
422
  },
422
423
  });
423
424
  // 在同一事务里读回,返回值就是刚提交的状态
@@ -62,6 +62,8 @@ export interface OrgOverrideSummary {
62
62
  interface Actor {
63
63
  accountId: string;
64
64
  tokenId?: string | undefined;
65
+ /** Merged into the audit detail (a Platform operation's `via: "agent"`). */
66
+ auditDetail?: Record<string, unknown> | undefined;
65
67
  }
66
68
  /**
67
69
  * Org copies of an extension's overridable deployment config (spec A §5.4, §5.5, §5.8): one row of
@@ -181,7 +181,7 @@ let OrgOverrides = class OrgOverrides {
181
181
  orgId,
182
182
  action: "extension.org_override_saved",
183
183
  target: plugin,
184
- detail: { changedPaths: changed },
184
+ detail: { changedPaths: changed, ...actor.auditDetail },
185
185
  });
186
186
  const secretValues = Object.values(copy.secrets);
187
187
  afterCommit(async () => {
@@ -245,7 +245,7 @@ let OrgOverrides = class OrgOverrides {
245
245
  orgId,
246
246
  action: "extension.org_override_taken",
247
247
  target: plugin,
248
- detail: { changedPaths: changed.sort() },
248
+ detail: { changedPaths: changed.sort(), ...actor.auditDetail },
249
249
  });
250
250
  afterCommit(() => this.effective.invalidate(orgId, plugin));
251
251
  return this.render(orgId, run);
@@ -277,6 +277,7 @@ let OrgOverrides = class OrgOverrides {
277
277
  orgId,
278
278
  action: "extension.org_override_reset",
279
279
  target: plugin,
280
+ ...(actor.auditDetail !== undefined && { detail: actor.auditDetail }),
280
281
  });
281
282
  afterCommit(() => this.effective.invalidate(orgId, plugin));
282
283
  return this.render(orgId, run);
@@ -73,6 +73,8 @@ import { InvitationsController } from "../orgs/invitations.controller.js";
73
73
  import { OrgsController } from "../orgs/orgs.controller.js";
74
74
  import { OrgsModule } from "../orgs/orgs.module.js";
75
75
  import { OrgSettingsController } from "../orgs/settings.controller.js";
76
+ import { PlatformModule } from "../platform/platform.module.js";
77
+ import { SealedRevealsController } from "../platform/sealed-reveals.controller.js";
76
78
  import { RuntimeModule } from "../runtime/runtime.module.js";
77
79
  import { ConversationStreamController } from "../runtime/stream.controller.js";
78
80
  import { SchedulesController } from "../schedules/schedules.controller.js";
@@ -114,6 +116,8 @@ const CONTROLLERS = [
114
116
  MetaController,
115
117
  MeController,
116
118
  InitialPasswordsController,
119
+ // the invitation link an org admin's agent created, read once by its approver (web parity §7.2)
120
+ SealedRevealsController,
117
121
  OrgsController,
118
122
  OrgSettingsController,
119
123
  InvitationsController,
@@ -213,6 +217,8 @@ ApiModule = __decorate([
213
217
  SkillsModule,
214
218
  IdentityModule,
215
219
  OrgsModule,
220
+ // the sealed reveals (SealedRevealsController)
221
+ PlatformModule,
216
222
  AdminModule,
217
223
  ExtensionsModule,
218
224
  CatalogModule,
@@ -1,11 +1,12 @@
1
1
  import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { LockService } from "../infra/lock/lock.service.js";
3
3
  import type { KernelLogger } from "../log.js";
4
- /** The hourly cleanup of expired sealed initial passwords (`@LockedCron`). */
4
+ /** The hourly cleanup of expired sealed initial passwords, person inputs and reveals (`@LockedCron`). */
5
5
  export declare const INITIAL_PASSWORD_CLEANUP_JOB = "initial-password-cleanup";
6
6
  /**
7
7
  * Deletes generated initial passwords nobody read before they expired (Platform tool spec §14.5
8
- * item 2), once per tick across replicas; the worker role's.
8
+ * item 2), sealed person inputs no resumed call consumed (platform web parity spec §4.3) and
9
+ * invitation links nobody revealed (§7.2), once per tick across replicas; the worker role's.
9
10
  */
10
11
  export declare class InitialPasswordCleanupJob {
11
12
  private readonly db;
@@ -12,12 +12,15 @@ import { KernelDb } from "../infra/database/kernel-db.js";
12
12
  import { LockService } from "../infra/lock/lock.service.js";
13
13
  import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
14
14
  import { KERNEL_LOGGER } from "../infra/tokens.js";
15
+ import { deleteExpiredSealedInputs } from "../platform/sealed-inputs.js";
16
+ import { deleteExpiredSealedReveals } from "../platform/sealed-reveals.js";
15
17
  import { deleteExpiredInitialPasswords } from "./initial-passwords.js";
16
- /** The hourly cleanup of expired sealed initial passwords (`@LockedCron`). */
18
+ /** The hourly cleanup of expired sealed initial passwords, person inputs and reveals (`@LockedCron`). */
17
19
  export const INITIAL_PASSWORD_CLEANUP_JOB = "initial-password-cleanup";
18
20
  /**
19
21
  * Deletes generated initial passwords nobody read before they expired (Platform tool spec §14.5
20
- * item 2), once per tick across replicas; the worker role's.
22
+ * item 2), sealed person inputs no resumed call consumed (platform web parity spec §4.3) and
23
+ * invitation links nobody revealed (§7.2), once per tick across replicas; the worker role's.
21
24
  */
22
25
  let InitialPasswordCleanupJob = class InitialPasswordCleanupJob {
23
26
  db;
@@ -29,9 +32,12 @@ let InitialPasswordCleanupJob = class InitialPasswordCleanupJob {
29
32
  this.log = log;
30
33
  }
31
34
  async cleanup() {
32
- const n = await deleteExpiredInitialPasswords(this.db.db);
33
- if (n > 0)
34
- this.log.info("expired initial passwords deleted", { count: n });
35
+ const passwords = await deleteExpiredInitialPasswords(this.db.db);
36
+ const sealedInputs = await deleteExpiredSealedInputs(this.db.db);
37
+ const sealedReveals = await deleteExpiredSealedReveals(this.db.db);
38
+ if (passwords > 0 || sealedInputs > 0 || sealedReveals > 0) {
39
+ this.log.info("expired sealed values deleted", { passwords, sealedInputs, sealedReveals });
40
+ }
35
41
  }
36
42
  };
37
43
  __decorate([
@@ -7,15 +7,8 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
7
7
  import { CredentialThrottler } from "../infra/throttler/credential-throttler.js";
8
8
  import { type InvitableRole, type Invitation, type InvitationStatus, InvitationsService } from "./invitations.service.js";
9
9
  import { type OrgContext } from "./org.guard.js";
10
+ import { InvitationCreateBody, InvitationIdParams } from "./orgs.schemas.js";
10
11
  import type { OrgRole } from "./roles.js";
11
- declare const CreateSchema: z.ZodObject<{
12
- role: z.ZodEnum<{
13
- admin: "admin";
14
- guest: "guest";
15
- member: "member";
16
- }>;
17
- expiresInHours: z.ZodOptional<z.ZodNumber>;
18
- }, z.core.$strip>;
19
12
  /** 组织邀请:组织内管理(`/api/v1/orgs/:orgId/invitations`)与凭令牌预览 / 接受(`/api/v1/invitations/:token`,公开)。 */
20
13
  export declare class InvitationsController {
21
14
  private readonly invitations;
@@ -24,7 +17,7 @@ export declare class InvitationsController {
24
17
  private readonly throttler;
25
18
  constructor(invitations: InvitationsService, sessions: SessionService, config: KernelConfigService, throttler: CredentialThrottler);
26
19
  /** 令牌只在此返回一次。 */
27
- create(principal: Principal, org: OrgContext, body: z.infer<typeof CreateSchema>): Promise<{
20
+ create(principal: Principal, org: OrgContext, body: z.infer<typeof InvitationCreateBody>): Promise<{
28
21
  invitation: Invitation;
29
22
  token: string;
30
23
  }>;
@@ -33,7 +26,7 @@ export declare class InvitationsController {
33
26
  status: InvitationStatus;
34
27
  })[];
35
28
  }>;
36
- revoke(principal: Principal, org: OrgContext, id: string): Promise<void>;
29
+ revoke(principal: Principal, org: OrgContext, { id }: z.infer<typeof InvitationIdParams>): Promise<void>;
37
30
  /** 公开预览:只给组织 id / 名称、角色与过期时间。 */
38
31
  preview(token: string): Promise<{
39
32
  org: {
@@ -55,4 +48,3 @@ export declare class InvitationsController {
55
48
  role: OrgRole;
56
49
  }>;
57
50
  }
58
- export {};
@@ -18,14 +18,13 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
18
18
  import { CredentialThrottler } from "../infra/throttler/credential-throttler.js";
19
19
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
20
20
  import { parseWithZod } from "../infra/validation/parse-with-zod.js";
21
- import { ZBody } from "../infra/validation/zod-params.js";
22
- import { INVITABLE_ROLES, InvitationsService, MAX_INVITATION_HOURS, } from "./invitations.service.js";
21
+ import { ZBody, ZParam } from "../infra/validation/zod-params.js";
22
+ import { InvitationsService, } from "./invitations.service.js";
23
23
  import { CurrentOrg, OrgAction } from "./org.guard.js";
24
- const CreateSchema = z.object({
25
- role: z.enum(INVITABLE_ROLES),
26
- expiresInHours: z.number().int().min(1).max(MAX_INVITATION_HOURS).optional(),
27
- });
28
- class InvitationCreateBody extends createZodDto(CreateSchema, "InvitationCreateBody") {
24
+ import { InvitationCreateBody, InvitationIdParams } from "./orgs.schemas.js";
25
+ class InvitationCreateBodyDto extends createZodDto(InvitationCreateBody, "InvitationCreateBody") {
26
+ }
27
+ class InvitationIdParamsDto extends createZodDto(InvitationIdParams, "InvitationIdParams") {
29
28
  }
30
29
  /** Validated inside the handler, after the attempt is reserved (a signed-in principal sends none). */
31
30
  const SignupBody = z.object({
@@ -55,7 +54,7 @@ let InvitationsController = class InvitationsController {
55
54
  async list(org) {
56
55
  return { invitations: await this.invitations.list(org.orgId) };
57
56
  }
58
- async revoke(principal, org, id) {
57
+ async revoke(principal, org, { id }) {
59
58
  const p = requireUser(principal);
60
59
  await this.invitations.revoke(org.orgId, id, p.account.id, patTokenId(p));
61
60
  }
@@ -98,7 +97,7 @@ __decorate([
98
97
  OrgAction("org.invitations.manage"),
99
98
  __param(0, CurrentPrincipal()),
100
99
  __param(1, CurrentOrg()),
101
- __param(2, ZBody(InvitationCreateBody))
100
+ __param(2, ZBody(InvitationCreateBodyDto))
102
101
  ], InvitationsController.prototype, "create", null);
103
102
  __decorate([
104
103
  Get("orgs/:orgId/invitations"),
@@ -111,7 +110,7 @@ __decorate([
111
110
  HttpCode(204),
112
111
  __param(0, CurrentPrincipal()),
113
112
  __param(1, CurrentOrg()),
114
- __param(2, Param("id"))
113
+ __param(2, ZParam(InvitationIdParamsDto))
115
114
  ], InvitationsController.prototype, "revoke", null);
116
115
  __decorate([
117
116
  Get("invitations/:token"),
@@ -19,6 +19,11 @@ export type Invitation = {
19
19
  acceptedAt: Date | null;
20
20
  revokedAt: Date | null;
21
21
  };
22
+ /** Extras of {@link InvitationsService.create}. */
23
+ export interface InvitationCreateOptions {
24
+ auditDetail?: Record<string, unknown>;
25
+ inTransaction?: (invitation: Invitation, token: string) => Promise<void>;
26
+ }
22
27
  export type InvitationStatus = "pending" | "accepted" | "expired" | "revoked";
23
28
  export type AcceptAs = {
24
29
  accountId: string;
@@ -41,10 +46,15 @@ export declare class InvitationsService {
41
46
  private readonly members;
42
47
  private readonly orgLock;
43
48
  constructor(db: KernelDb, txHost: TransactionHost, accounts: AccountsService, members: MembersService, orgLock: OrgLock);
49
+ /**
50
+ * `opts.auditDetail` goes into the audit event (a write through the Platform tool says so);
51
+ * `opts.inTransaction` runs in the creation's transaction with the new invitation and its token
52
+ * (the Platform tool seals the token there for the person who approved the call).
53
+ */
44
54
  create(orgId: string, input: {
45
55
  role: InvitableRole;
46
56
  expiresInHours?: number | undefined;
47
- }, actorAccountId: string, actorTokenId?: string): Promise<{
57
+ }, actorAccountId: string, actorTokenId?: string, opts?: InvitationCreateOptions): Promise<{
48
58
  invitation: Invitation;
49
59
  token: string;
50
60
  }>;
@@ -53,7 +63,7 @@ export declare class InvitationsService {
53
63
  status: InvitationStatus;
54
64
  })[]>;
55
65
  /** 撤销;不属于该组织 → `invitation.invalid`;已接受 → `invitation.used`;已撤销则无操作。 */
56
- revoke(orgId: string, id: string, actorAccountId: string, actorTokenId?: string): Promise<void>;
66
+ revoke(orgId: string, id: string, actorAccountId: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<void>;
57
67
  preview(token: string): Promise<{
58
68
  org: {
59
69
  id: string;
@@ -57,7 +57,12 @@ let InvitationsService = class InvitationsService {
57
57
  this.members = members;
58
58
  this.orgLock = orgLock;
59
59
  }
60
- async create(orgId, input, actorAccountId, actorTokenId) {
60
+ /**
61
+ * `opts.auditDetail` goes into the audit event (a write through the Platform tool says so);
62
+ * `opts.inTransaction` runs in the creation's transaction with the new invitation and its token
63
+ * (the Platform tool seals the token there for the person who approved the call).
64
+ */
65
+ async create(orgId, input, actorAccountId, actorTokenId, opts = {}) {
61
66
  if (!INVITABLE_ROLES.includes(input.role)) {
62
67
  throw new ApiError("validation_failed", "Role cannot be invited");
63
68
  }
@@ -66,9 +71,9 @@ let InvitationsService = class InvitationsService {
66
71
  throw new ApiError("validation_failed", `expiresInHours must be an integer between 1 and ${MAX_INVITATION_HOURS}`);
67
72
  }
68
73
  const token = TOKEN_PREFIX + randomBytes(32).toString("base64url");
69
- return this.createIn(orgId, input.role, hours, token, actorAccountId, actorTokenId);
74
+ return this.createIn(orgId, input.role, hours, token, actorAccountId, actorTokenId, opts);
70
75
  }
71
- async createIn(orgId, role, hours, token, actorAccountId, actorTokenId) {
76
+ async createIn(orgId, role, hours, token, actorAccountId, actorTokenId, opts) {
72
77
  const input = { role };
73
78
  const { role: actorRole } = await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.invitations.manage");
74
79
  if (!roleAtLeast(actorRole, input.role))
@@ -91,9 +96,11 @@ let InvitationsService = class InvitationsService {
91
96
  orgId,
92
97
  action: "org.invitation.created",
93
98
  target: row.id,
94
- detail: { role: input.role, expiresAt: row.expires_at.toISOString() },
99
+ detail: { role: input.role, expiresAt: row.expires_at.toISOString(), ...opts.auditDetail },
95
100
  });
96
- return { invitation: toInvitation(row), token };
101
+ const invitation = toInvitation(row);
102
+ await opts.inTransaction?.(invitation, token);
103
+ return { invitation, token };
97
104
  }
98
105
  async list(orgId) {
99
106
  const rows = await this.db
@@ -116,7 +123,7 @@ let InvitationsService = class InvitationsService {
116
123
  });
117
124
  }
118
125
  /** 撤销;不属于该组织 → `invitation.invalid`;已接受 → `invitation.used`;已撤销则无操作。 */
119
- async revoke(orgId, id, actorAccountId, actorTokenId) {
126
+ async revoke(orgId, id, actorAccountId, actorTokenId, auditDetail) {
120
127
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.invitations.manage");
121
128
  const row = await this.db
122
129
  .selectFrom("invitations")
@@ -142,7 +149,7 @@ let InvitationsService = class InvitationsService {
142
149
  orgId,
143
150
  action: "org.invitation.revoked",
144
151
  target: id,
145
- detail: { role: row.role },
152
+ detail: { role: row.role, ...auditDetail },
146
153
  });
147
154
  }
148
155
  async preview(token) {
@@ -19,6 +19,16 @@ export interface Member {
19
19
  export declare function isAnonymousGuest(db: KernelSchemaDb, accountId: string): Promise<boolean>;
20
20
  /** 目标是匿名访客 → `409 member.anonymous_guest`。 */
21
21
  export declare function rejectAnonymousGuest(db: KernelSchemaDb, accountId: string): Promise<void>;
22
+ /** Extras of {@link MembersService.changeRole} and {@link MembersService.remove}. */
23
+ export interface MemberWriteOptions {
24
+ /** Goes into the audit event (a write through the Platform tool says so). */
25
+ auditDetail?: Record<string, unknown>;
26
+ /**
27
+ * Runs under the org row lock with the roles read there, before the service's own checks; throws
28
+ * to refuse (the Platform tool's limits, platform web parity spec §7.2).
29
+ */
30
+ guard?: (actorRole: OrgRole, targetRole: OrgRole) => void;
31
+ }
22
32
  /**
23
33
  * 成员服务。发起人只传账号 id,角色由服务在组织行锁内实时读取,调用方无法传入过期角色。所有写操作在事务内先 `SELECT … FROM orgs WHERE id = $1 FOR NO KEY UPDATE`,
24
34
  * 把同一组织的成员变更串行化(多副本下两个 owner 并发互相降级也恰好剩一个 owner)。
@@ -45,14 +55,14 @@ export declare class MembersService {
45
55
  * 发起人的角色在组织行锁内实时重读(spec 3.6 R5):已不是成员或低于 admin → `forbidden`。
46
56
  * 目标是匿名访客 → `member.anonymous_guest`。
47
57
  */
48
- changeRole(orgId: string, targetId: string, role: OrgRole, actorAccountId: string, actorTokenId?: string): Promise<void>;
58
+ changeRole(orgId: string, targetId: string, role: OrgRole, actorAccountId: string, actorTokenId?: string, opts?: MemberWriteOptions): Promise<void>;
49
59
  private changeRoleIn;
50
60
  /**
51
61
  * 移出成员:权限规则同 changeRole(移除 owner 须发起人是 owner);移除最后一个 owner → `org.last_owner`。
52
62
  * 走离职处理({@link Offboarding.offboard},原因 `removed`),与之同一事务;提交后写吊销标记、发布事件。
53
63
  * 匿名访客不能移出(`member.anonymous_guest`;不再需要匿名访问时把渠道连接改回绑定策略)。
54
64
  */
55
- remove(orgId: string, targetId: string, actorAccountId: string, actorTokenId?: string): Promise<void>;
65
+ remove(orgId: string, targetId: string, actorAccountId: string, actorTokenId?: string, opts?: MemberWriteOptions): Promise<void>;
56
66
  private removeIn;
57
67
  /** 主动离开:走离职处理(原因 `left`);最后一个 owner → `org.last_owner`。 */
58
68
  leave(orgId: string, accountId: string, actorTokenId?: string): Promise<void>;