@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.
- package/dist/admin/extensions.controller.d.ts +2 -10
- package/dist/admin/extensions.controller.js +2 -24
- package/dist/admin/extensions.schemas.d.ts +21 -0
- package/dist/admin/extensions.schemas.js +37 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.controller.d.ts +0 -5
- package/dist/catalog/org-catalog.controller.js +3 -17
- package/dist/catalog/org-catalog.schemas.d.ts +43 -0
- package/dist/catalog/org-catalog.schemas.js +43 -2
- package/dist/catalog/org-extension-switch.d.ts +3 -1
- package/dist/catalog/org-extension-switch.js +12 -5
- package/dist/catalog/org-extension.controller.d.ts +2 -21
- package/dist/catalog/org-extension.controller.js +1 -38
- package/dist/catalog/org-extension.schemas.d.ts +31 -0
- package/dist/catalog/org-extension.schemas.js +65 -0
- package/dist/catalog/plugin-install.d.ts +2 -0
- package/dist/catalog/plugin-install.js +3 -3
- package/dist/channels/actions.js +2 -0
- package/dist/channels/cards.d.ts +8 -0
- package/dist/channels/cards.js +18 -0
- package/dist/channels/channels.schemas.d.ts +3 -0
- package/dist/channels/channels.schemas.js +8 -0
- package/dist/channels/connections.service.d.ts +17 -2
- package/dist/channels/connections.service.js +30 -5
- package/dist/channels/outbound.js +25 -1
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +10 -0
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/events.d.ts +35 -0
- package/dist/conversations/events.js +29 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +69 -0
- package/dist/ctx/secrets.d.ts +13 -1
- package/dist/ctx/secrets.js +19 -1
- package/dist/db/kernel-schema.d.ts +34 -0
- package/dist/devices/working-root.d.ts +2 -3
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/extensions/deployment-config.d.ts +6 -2
- package/dist/extensions/deployment-config.js +35 -23
- package/dist/extensions/org-config.d.ts +2 -0
- package/dist/extensions/org-config.js +1 -0
- package/dist/extensions/org-overrides.d.ts +2 -0
- package/dist/extensions/org-overrides.js +3 -2
- package/dist/http/api.module.js +6 -0
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +11 -5
- package/dist/orgs/invitations.controller.d.ts +3 -11
- package/dist/orgs/invitations.controller.js +9 -10
- package/dist/orgs/invitations.service.d.ts +12 -2
- package/dist/orgs/invitations.service.js +14 -7
- package/dist/orgs/members.service.d.ts +12 -2
- package/dist/orgs/members.service.js +10 -8
- package/dist/orgs/orgs.controller.d.ts +4 -12
- package/dist/orgs/orgs.controller.js +10 -10
- package/dist/orgs/orgs.schemas.d.ts +26 -0
- package/dist/orgs/orgs.schemas.js +22 -0
- package/dist/platform/connector-person-fields.d.ts +67 -0
- package/dist/platform/connector-person-fields.js +129 -0
- package/dist/platform/exclusions.js +6 -141
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +61 -2
- package/dist/platform/operation.js +4 -4
- package/dist/platform/ops/accounts.ops.js +1 -0
- package/dist/platform/ops/channels.ops.d.ts +10 -3
- package/dist/platform/ops/channels.ops.js +223 -5
- package/dist/platform/ops/connectors.ops.d.ts +22 -4
- package/dist/platform/ops/connectors.ops.js +664 -13
- package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
- package/dist/platform/ops/extensions-admin.ops.js +153 -5
- package/dist/platform/ops/extensions.ops.d.ts +19 -5
- package/dist/platform/ops/extensions.ops.js +285 -10
- package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
- package/dist/platform/ops/org-plugins.ops.js +323 -4
- package/dist/platform/ops/orgs.ops.d.ts +40 -3
- package/dist/platform/ops/orgs.ops.js +293 -12
- package/dist/platform/ops/person-inputs.d.ts +65 -0
- package/dist/platform/ops/person-inputs.js +129 -0
- package/dist/platform/ops/plugins.ops.d.ts +3 -1
- package/dist/platform/ops/plugins.ops.js +33 -20
- package/dist/platform/parity.d.ts +7 -2
- package/dist/platform/parity.js +75 -13
- package/dist/platform/person-fields.d.ts +119 -0
- package/dist/platform/person-fields.js +403 -0
- package/dist/platform/platform.module.d.ts +4 -3
- package/dist/platform/platform.module.js +8 -5
- package/dist/platform/route-schemas.js +2 -0
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -0
- package/dist/platform/sealed-reveals.controller.d.ts +20 -0
- package/dist/platform/sealed-reveals.controller.js +48 -0
- package/dist/platform/sealed-reveals.d.ts +52 -0
- package/dist/platform/sealed-reveals.js +153 -0
- package/dist/runtime/project/knowledge.js +24 -19
- package/dist/runtime/waits.js +8 -2
- package/dist/sandbox/permission-facts.d.ts +5 -1
- package/dist/sandbox/permission-facts.js +8 -2
- package/dist/setup/setup-guides.service.d.ts +5 -0
- package/dist/setup/setup-guides.service.js +2 -1
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.controller.js +19 -0
- package/dist/tools/approvals.service.d.ts +50 -1
- package/dist/tools/approvals.service.js +118 -10
- package/dist/tools/builtins/builtin-tools.d.ts +3 -0
- package/dist/tools/builtins/builtin-tools.js +31 -9
- package/dist/tools/builtins/platform.d.ts +20 -0
- package/dist/tools/builtins/platform.js +214 -15
- package/dist/tools/connectors.controller.d.ts +6 -7
- package/dist/tools/connectors.controller.js +4 -44
- package/dist/tools/connectors.schemas.d.ts +170 -1
- package/dist/tools/connectors.schemas.js +82 -3
- package/dist/tools/connectors.service.d.ts +16 -6
- package/dist/tools/connectors.service.js +39 -24
- package/dist/tools/oauth/oauth.controller.d.ts +3 -6
- package/dist/tools/oauth/oauth.controller.js +3 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
- package/dist/tools/oauth/oauth.schemas.js +27 -0
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +89 -17
- package/dist/tools/policy.d.ts +4 -0
- package/dist/tools/policy.js +8 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/tools.module.js +3 -0
- package/package.json +3 -3
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
|
@@ -553,6 +553,7 @@ export declare class PluginInstaller {
|
|
|
553
553
|
*/
|
|
554
554
|
configureConnectors(orgId: string, actor: string, itemId: string, input: PluginInstallInput, opts?: {
|
|
555
555
|
actorTokenId?: string;
|
|
556
|
+
auditDetail?: AuditDetail;
|
|
556
557
|
}): Promise<{
|
|
557
558
|
templateId: string;
|
|
558
559
|
connectorId: string;
|
|
@@ -578,6 +579,7 @@ export declare class PluginInstaller {
|
|
|
578
579
|
config: Omit<ConnectorInstallInput, "name">;
|
|
579
580
|
}, opts?: {
|
|
580
581
|
actorTokenId?: string;
|
|
582
|
+
auditDetail?: AuditDetail;
|
|
581
583
|
}): Promise<{
|
|
582
584
|
connector: ConnectorDetail;
|
|
583
585
|
issues: ToolIssue[];
|
|
@@ -775,7 +775,7 @@ let PluginInstaller = class PluginInstaller {
|
|
|
775
775
|
}
|
|
776
776
|
if (actor === null)
|
|
777
777
|
throw systemNeedsInput(manifest.name);
|
|
778
|
-
const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId);
|
|
778
|
+
const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId, opts.auditDetail);
|
|
779
779
|
await record({
|
|
780
780
|
kind: "connector",
|
|
781
781
|
ref: r.connector.id,
|
|
@@ -1692,7 +1692,7 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1692
1692
|
}));
|
|
1693
1693
|
const out = [];
|
|
1694
1694
|
for (const p of plans) {
|
|
1695
|
-
const r = await this.connectors.create(orgId, actor, p.ci, opts.actorTokenId);
|
|
1695
|
+
const r = await this.connectors.create(orgId, actor, p.ci, opts.actorTokenId, opts.auditDetail);
|
|
1696
1696
|
await this.recordConnector(missing.installId, r.connector.id, p.id);
|
|
1697
1697
|
out.push({ templateId: p.id, connectorId: r.connector.id });
|
|
1698
1698
|
}
|
|
@@ -1795,7 +1795,7 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1795
1795
|
}),
|
|
1796
1796
|
};
|
|
1797
1797
|
try {
|
|
1798
|
-
const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId);
|
|
1798
|
+
const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId, opts.auditDetail);
|
|
1799
1799
|
await this.recordOnLiveInstall(orgId, row.catalog_item_id, r.connector.id, ct.id);
|
|
1800
1800
|
return r;
|
|
1801
1801
|
}
|
package/dist/channels/actions.js
CHANGED
|
@@ -14,6 +14,8 @@ const REPLY_FOR = {
|
|
|
14
14
|
"approval.scope_not_allowed": "invalidAction",
|
|
15
15
|
// a network ask clicked by someone other than the device's owner
|
|
16
16
|
"approval.not_yours": "cannotHandle",
|
|
17
|
+
// an approval with person fields is approved only on the web (platform web parity spec R5)
|
|
18
|
+
"auth.session_required": "cannotHandle",
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* IM 卡片上的按钮操作(Review Focus 2):点击者按入站同样的规则映射到账号(未绑定 → 私聊回绑定卡片、群里只提示去私聊),
|
package/dist/channels/cards.d.ts
CHANGED
|
@@ -81,6 +81,14 @@ export declare function commandCardText(detail: Pick<CommandAskDetail, "kind" |
|
|
|
81
81
|
escalation?: PermissionEscalation;
|
|
82
82
|
workingRoot?: string;
|
|
83
83
|
}, scopes: readonly string[], locale: ChannelLocale, redact?: (s: string) => string): NetworkCardText;
|
|
84
|
+
/**
|
|
85
|
+
* The `bind` card of an approval whose Platform call needs the person to type secrets: the values
|
|
86
|
+
* pass only through the web, never an IM vendor, so IM gets a link to the conversation instead of
|
|
87
|
+
* an approval card. Undefined when the approval does not exist or has no person fields.
|
|
88
|
+
*/
|
|
89
|
+
export declare function personFieldsCard(d: CardDeps, approvalId: string, base: string, locale: ChannelLocale): Promise<Extract<ChannelCard, {
|
|
90
|
+
kind: "bind";
|
|
91
|
+
}> | undefined>;
|
|
84
92
|
/**
|
|
85
93
|
* The approval card in the approval's current state; undefined when the approval does not exist.
|
|
86
94
|
* A role escalation offers only "once". A network ask names its hosts and command and labels its
|
package/dist/channels/cards.js
CHANGED
|
@@ -270,6 +270,24 @@ export function commandCardText(detail, scopes, locale, redact = (s) => s) {
|
|
|
270
270
|
},
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* The `bind` card of an approval whose Platform call needs the person to type secrets: the values
|
|
275
|
+
* pass only through the web, never an IM vendor, so IM gets a link to the conversation instead of
|
|
276
|
+
* an approval card. Undefined when the approval does not exist or has no person fields.
|
|
277
|
+
*/
|
|
278
|
+
export async function personFieldsCard(d, approvalId, base, locale) {
|
|
279
|
+
const v = await d.approvals.describe(approvalId);
|
|
280
|
+
const n = v?.personFields?.length ?? 0;
|
|
281
|
+
if (!v || n === 0)
|
|
282
|
+
return undefined;
|
|
283
|
+
return {
|
|
284
|
+
kind: "bind",
|
|
285
|
+
text: n === 1
|
|
286
|
+
? phrase("personFieldOnWeb", locale)
|
|
287
|
+
: phrase("personFieldsOnWeb", locale).replace("{count}", String(n)),
|
|
288
|
+
url: `${base}${v.conversationPath}`,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
273
291
|
/**
|
|
274
292
|
* The approval card in the approval's current state; undefined when the approval does not exist.
|
|
275
293
|
* A role escalation offers only "once". A network ask names its hosts and command and labels its
|
|
@@ -38,4 +38,7 @@ export declare const ChannelGuideAckSchema: z.ZodObject<{
|
|
|
38
38
|
export declare const ChannelPathParams: z.ZodObject<{
|
|
39
39
|
connectionId: z.ZodString;
|
|
40
40
|
}, z.core.$strip>;
|
|
41
|
+
export declare const ChannelSchemaParams: z.ZodObject<{
|
|
42
|
+
plugin: z.ZodString;
|
|
43
|
+
}, z.core.$strip>;
|
|
41
44
|
export declare const CHANNEL_ROUTES: readonly RouteSchemas[];
|
|
@@ -28,8 +28,16 @@ export const ChannelGuideAckSchema = z
|
|
|
28
28
|
.object({ hash: z.string().regex(/^[0-9a-f]{64}$/) })
|
|
29
29
|
.strict();
|
|
30
30
|
export const ChannelPathParams = z.object({ connectionId: z.string().min(1).max(100) });
|
|
31
|
+
export const ChannelSchemaParams = z.object({ plugin: z.string().min(1).max(214) });
|
|
31
32
|
export const CHANNEL_ROUTES = [
|
|
32
33
|
{ route: "GET /api/v1/orgs/:orgId/channels" },
|
|
34
|
+
{ route: "GET /api/v1/orgs/:orgId/channels/schema/:plugin", params: ChannelSchemaParams },
|
|
35
|
+
{ route: "POST /api/v1/orgs/:orgId/channels", body: ChannelCreateSchema },
|
|
36
|
+
{
|
|
37
|
+
route: "POST /api/v1/orgs/:orgId/channels/:connectionId/guide-ack",
|
|
38
|
+
params: ChannelPathParams,
|
|
39
|
+
body: ChannelGuideAckSchema,
|
|
40
|
+
},
|
|
33
41
|
{ route: "GET /api/v1/orgs/:orgId/channels/:connectionId", params: ChannelPathParams },
|
|
34
42
|
{
|
|
35
43
|
route: "PATCH /api/v1/orgs/:orgId/channels/:connectionId",
|
|
@@ -196,9 +196,22 @@ export declare class ChannelConnections implements OnApplicationShutdown {
|
|
|
196
196
|
list(orgId: string): Promise<ChannelConnectionView[]>;
|
|
197
197
|
get(orgId: string, id: string): Promise<ChannelConnectionView>;
|
|
198
198
|
/** 新建:插件须提供 channel@1 且在该组织启用;配置按 `connectionSchema` 校验;先 `verify`,失败不落库。 */
|
|
199
|
-
create(orgId: string, input: CreateChannelInput, actorAccountId: string, actorTokenId?: string
|
|
199
|
+
create(orgId: string, input: CreateChannelInput, actorAccountId: string, actorTokenId?: string,
|
|
200
|
+
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
201
|
+
auditDetail?: Record<string, unknown>): Promise<ChannelConnectionView>;
|
|
200
202
|
/** The rows of {@link create}, in their own transaction (the caller publishes after the commit). */
|
|
201
203
|
private insertIn;
|
|
204
|
+
/**
|
|
205
|
+
* The read-only refusals of {@link create} that need no write (the Platform tool's precheck): the
|
|
206
|
+
* plugin provides a channel and is on in the org, the agent exists, and webhook inbound is
|
|
207
|
+
* available when asked for.
|
|
208
|
+
*/
|
|
209
|
+
checkCreate(orgId: string, input: Pick<CreateChannelInput, "plugin" | "agentId" | "inboundMode">): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* The secret fields (dot paths) the inbound mode requires of the plugin's connection form
|
|
212
|
+
* (`x-ui.inboundModes`), for the Platform tool's person fields.
|
|
213
|
+
*/
|
|
214
|
+
modeRequiredFields(plugin: string, mode: InboundMode): string[];
|
|
202
215
|
/** The read-only refusals of {@link update} that need no write (the Platform tool's precheck). */
|
|
203
216
|
checkUpdate(orgId: string, id: string, patch: UpdateChannelInput): Promise<void>;
|
|
204
217
|
/**
|
|
@@ -223,7 +236,9 @@ export declare class ChannelConnections implements OnApplicationShutdown {
|
|
|
223
236
|
ackGuide(org: {
|
|
224
237
|
orgId: string;
|
|
225
238
|
role: OrgRole;
|
|
226
|
-
}, id: string, hash: string, actorAccountId: string, actorTokenId?: string
|
|
239
|
+
}, id: string, hash: string, actorAccountId: string, actorTokenId?: string,
|
|
240
|
+
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
241
|
+
auditDetail?: Record<string, unknown>): Promise<ChannelConnectionView>;
|
|
227
242
|
/** The row of {@link ackGuide}, in its own transaction. */
|
|
228
243
|
private ackIn;
|
|
229
244
|
/** 删除(软删除,同一事务删掉密钥);持有长连接的副本收到广播后断开。 */
|
|
@@ -385,7 +385,9 @@ let ChannelConnections = class ChannelConnections {
|
|
|
385
385
|
return this.viewOf(row);
|
|
386
386
|
}
|
|
387
387
|
/** 新建:插件须提供 channel@1 且在该组织启用;配置按 `connectionSchema` 校验;先 `verify`,失败不落库。 */
|
|
388
|
-
async create(orgId, input, actorAccountId, actorTokenId
|
|
388
|
+
async create(orgId, input, actorAccountId, actorTokenId,
|
|
389
|
+
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
390
|
+
auditDetail) {
|
|
389
391
|
const channel = this.channel(input.plugin);
|
|
390
392
|
await this.assertEnabled(orgId, input.plugin);
|
|
391
393
|
const schema = channel.connectionSchema;
|
|
@@ -410,6 +412,7 @@ let ChannelConnections = class ChannelConnections {
|
|
|
410
412
|
guideAck,
|
|
411
413
|
actorAccountId,
|
|
412
414
|
actorTokenId,
|
|
415
|
+
auditDetail,
|
|
413
416
|
});
|
|
414
417
|
this.reportSecrets(schema, full);
|
|
415
418
|
await this.changed(id, false);
|
|
@@ -451,10 +454,30 @@ let ChannelConnections = class ChannelConnections {
|
|
|
451
454
|
plugin: input.plugin,
|
|
452
455
|
agentId: input.agentId,
|
|
453
456
|
inboundMode: input.inboundMode ?? "long_connection",
|
|
457
|
+
...a.auditDetail,
|
|
454
458
|
},
|
|
455
459
|
});
|
|
456
460
|
return inserted;
|
|
457
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* The read-only refusals of {@link create} that need no write (the Platform tool's precheck): the
|
|
464
|
+
* plugin provides a channel and is on in the org, the agent exists, and webhook inbound is
|
|
465
|
+
* available when asked for.
|
|
466
|
+
*/
|
|
467
|
+
async checkCreate(orgId, input) {
|
|
468
|
+
this.channel(input.plugin);
|
|
469
|
+
await this.assertEnabled(orgId, input.plugin);
|
|
470
|
+
if (input.inboundMode === "webhook")
|
|
471
|
+
this.assertWebhookAvailable(input.plugin);
|
|
472
|
+
await this.assertAgent(orgId, input.agentId);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* The secret fields (dot paths) the inbound mode requires of the plugin's connection form
|
|
476
|
+
* (`x-ui.inboundModes`), for the Platform tool's person fields.
|
|
477
|
+
*/
|
|
478
|
+
modeRequiredFields(plugin, mode) {
|
|
479
|
+
return missingInboundModeFields(this.jsonSchema(plugin), mode, () => false);
|
|
480
|
+
}
|
|
458
481
|
/** The read-only refusals of {@link update} that need no write (the Platform tool's precheck). */
|
|
459
482
|
async checkUpdate(orgId, id, patch) {
|
|
460
483
|
const current = await this.live(orgId).where("id", "=", id).executeTakeFirst();
|
|
@@ -617,7 +640,9 @@ let ChannelConnections = class ChannelConnections {
|
|
|
617
640
|
* first). A plugin without a guide, or whose item the org's catalog does not show -> 404
|
|
618
641
|
* `catalog.guide_not_found`.
|
|
619
642
|
*/
|
|
620
|
-
async ackGuide(org, id, hash, actorAccountId, actorTokenId
|
|
643
|
+
async ackGuide(org, id, hash, actorAccountId, actorTokenId,
|
|
644
|
+
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
645
|
+
auditDetail) {
|
|
621
646
|
const { orgId } = org;
|
|
622
647
|
const current = await this.live(orgId).where("id", "=", id).executeTakeFirst();
|
|
623
648
|
if (!current)
|
|
@@ -633,11 +658,11 @@ let ChannelConnections = class ChannelConnections {
|
|
|
633
658
|
if (ack.hash !== hash) {
|
|
634
659
|
throw new ApiError("channel.guide_changed", "The plugin's setup guide changed since it was shown; review the new guide first");
|
|
635
660
|
}
|
|
636
|
-
const row = await this.ackIn(orgId, id, ack, actorAccountId, actorTokenId);
|
|
661
|
+
const row = await this.ackIn(orgId, id, ack, actorAccountId, actorTokenId, auditDetail);
|
|
637
662
|
return this.viewOf(row);
|
|
638
663
|
}
|
|
639
664
|
/** The row of {@link ackGuide}, in its own transaction. */
|
|
640
|
-
async ackIn(orgId, id, ack, actorAccountId, actorTokenId) {
|
|
665
|
+
async ackIn(orgId, id, ack, actorAccountId, actorTokenId, auditDetail) {
|
|
641
666
|
await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "channels.manage");
|
|
642
667
|
const row = await this.db
|
|
643
668
|
.updateTable("channel_connections")
|
|
@@ -655,7 +680,7 @@ let ChannelConnections = class ChannelConnections {
|
|
|
655
680
|
orgId,
|
|
656
681
|
action: "channel.guide_confirmed",
|
|
657
682
|
target: id,
|
|
658
|
-
detail: { guideId: ack.guideId, version: ack.version },
|
|
683
|
+
detail: { guideId: ack.guideId, version: ack.version, ...auditDetail },
|
|
659
684
|
});
|
|
660
685
|
return row;
|
|
661
686
|
}
|
|
@@ -26,7 +26,7 @@ import { StorageService } from "../storage/storage.service.js";
|
|
|
26
26
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
27
27
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
28
28
|
import { ToolRegistry } from "../tools/registry.js";
|
|
29
|
-
import { approvalCard, cardMessage, connectUrl, conversationUrl, questionCard, webBase, } from "./cards.js";
|
|
29
|
+
import { approvalCard, cardMessage, connectUrl, conversationUrl, personFieldsCard, questionCard, webBase, } from "./cards.js";
|
|
30
30
|
import { ChannelConnections, FILE_CALL_TIMEOUT_MS, } from "./connections.service.js";
|
|
31
31
|
import { FileSlots, fileKind, fileLinkText, fileRootText, planFileDelivery, pluginFileName, readArtifactCapped, } from "./file-delivery.js";
|
|
32
32
|
import { ChannelInbound } from "./inbound.js";
|
|
@@ -962,6 +962,23 @@ class Delivery {
|
|
|
962
962
|
}), this.key(e.seq));
|
|
963
963
|
return this.advance(e.seq);
|
|
964
964
|
}
|
|
965
|
+
case "tool_result": {
|
|
966
|
+
// a Platform operation's link card (platform web parity spec §6): a link to the web page
|
|
967
|
+
// where the person decides; an OAuth connect opens the conversation, whose card starts it
|
|
968
|
+
const v = e.payload.view;
|
|
969
|
+
if (v?.kind !== "handoff")
|
|
970
|
+
return;
|
|
971
|
+
await this.send(this.base === undefined
|
|
972
|
+
? { text: phrase("handleOnWeb", this.locale) }
|
|
973
|
+
: cardMessage(v.title[this.locale], {
|
|
974
|
+
kind: "bind",
|
|
975
|
+
text: v.title[this.locale],
|
|
976
|
+
url: v.target.type === "link"
|
|
977
|
+
? `${this.base}${v.target.url}`
|
|
978
|
+
: conversationUrl(this.base, this.conversationId),
|
|
979
|
+
}), this.key(e.seq));
|
|
980
|
+
return this.advance(e.seq);
|
|
981
|
+
}
|
|
965
982
|
case "approval_decided": {
|
|
966
983
|
const at = await this.cardMessageOf("approval", e.payload.approvalId);
|
|
967
984
|
if (!at || this.base === undefined)
|
|
@@ -1009,6 +1026,13 @@ class Delivery {
|
|
|
1009
1026
|
await this.send({ text: phrase("handleOnWeb", this.locale) }, this.key(seq));
|
|
1010
1027
|
return this.advance(seq);
|
|
1011
1028
|
}
|
|
1029
|
+
// secrets are typed on the web only: IM gets a link, never an approval card (no card is
|
|
1030
|
+
// recorded, so `approval_decided` has nothing to update)
|
|
1031
|
+
const bind = await personFieldsCard(this.d, approvalId, this.base, this.locale);
|
|
1032
|
+
if (bind) {
|
|
1033
|
+
await this.send(cardMessage(bind.text, bind), this.key(seq));
|
|
1034
|
+
return this.advance(seq);
|
|
1035
|
+
}
|
|
1012
1036
|
const card = await approvalCard(this.d, approvalId, this.base, this.locale, this.s.redact);
|
|
1013
1037
|
if (!card)
|
|
1014
1038
|
return;
|
|
@@ -207,6 +207,16 @@ export declare const CHANNEL_PHRASES: {
|
|
|
207
207
|
readonly zh: "需要先完成连接器授权";
|
|
208
208
|
readonly en: "A connector needs to be connected first";
|
|
209
209
|
};
|
|
210
|
+
/** A person-field approval (secrets typed on the web) with one field: the bind card's text. */
|
|
211
|
+
readonly personFieldOnWeb: {
|
|
212
|
+
readonly zh: "需要在网页填写 1 项";
|
|
213
|
+
readonly en: "1 field to fill in on the web";
|
|
214
|
+
};
|
|
215
|
+
/** A person-field approval with several fields: the bind card's text; `{count}` fields. */
|
|
216
|
+
readonly personFieldsOnWeb: {
|
|
217
|
+
readonly zh: "需要在网页填写 {count} 项";
|
|
218
|
+
readonly en: "{count} fields to fill in on the web";
|
|
219
|
+
};
|
|
210
220
|
/** 部署未配置 http.publicUrl,无法给出网页链接与卡片时的退回文本。 */
|
|
211
221
|
readonly handleOnWeb: {
|
|
212
222
|
readonly zh: "有一条请求需要你到 Capybara 网页上处理。";
|
package/dist/channels/phrases.js
CHANGED
|
@@ -169,6 +169,16 @@ export const CHANNEL_PHRASES = {
|
|
|
169
169
|
questionTitle: { zh: "需要你的回答", en: "Your input is needed" },
|
|
170
170
|
/** 连接卡片的随附文本。 */
|
|
171
171
|
connectTitle: { zh: "需要先完成连接器授权", en: "A connector needs to be connected first" },
|
|
172
|
+
/** A person-field approval (secrets typed on the web) with one field: the bind card's text. */
|
|
173
|
+
personFieldOnWeb: {
|
|
174
|
+
zh: "需要在网页填写 1 项",
|
|
175
|
+
en: "1 field to fill in on the web",
|
|
176
|
+
},
|
|
177
|
+
/** A person-field approval with several fields: the bind card's text; `{count}` fields. */
|
|
178
|
+
personFieldsOnWeb: {
|
|
179
|
+
zh: "需要在网页填写 {count} 项",
|
|
180
|
+
en: "{count} fields to fill in on the web",
|
|
181
|
+
},
|
|
172
182
|
/** 部署未配置 http.publicUrl,无法给出网页链接与卡片时的退回文本。 */
|
|
173
183
|
handleOnWeb: {
|
|
174
184
|
zh: "有一条请求需要你到 Capybara 网页上处理。",
|
|
@@ -23,6 +23,7 @@ import { ConversationsService } from "./conversations.service.js";
|
|
|
23
23
|
import { ConversationDeviceStatus } from "./device-status.js";
|
|
24
24
|
import { EventLogModule } from "./event-log.js";
|
|
25
25
|
import { ConversationFiles } from "./files.js";
|
|
26
|
+
import { ConversationLeakCheckModule } from "./leak-check.js";
|
|
26
27
|
import { ConversationOutputs } from "./outputs-read.js";
|
|
27
28
|
import { PermissionProfileStoreModule } from "./permission-profile-store.module.js";
|
|
28
29
|
import { PermissionProfilesService } from "./permission-profiles.service.js";
|
|
@@ -56,6 +57,8 @@ ConversationsModule = __decorate([
|
|
|
56
57
|
DevicesModule,
|
|
57
58
|
// the stop of a deleted conversation's background tasks
|
|
58
59
|
BackgroundModule,
|
|
60
|
+
// the leak check of a person's card values (its own module: the tools module uses it too)
|
|
61
|
+
ConversationLeakCheckModule,
|
|
59
62
|
],
|
|
60
63
|
providers: [
|
|
61
64
|
PermissionProfilesService,
|
|
@@ -78,6 +81,7 @@ ConversationsModule = __decorate([
|
|
|
78
81
|
ConversationArtifacts,
|
|
79
82
|
ConversationFiles,
|
|
80
83
|
ConversationDeviceStatus,
|
|
84
|
+
ConversationLeakCheckModule,
|
|
81
85
|
],
|
|
82
86
|
})
|
|
83
87
|
], ConversationsModule);
|
|
@@ -501,6 +501,10 @@ export type LogContentBlock = Exclude<ContentBlock, MediaBlock> | (MediaBlock ex
|
|
|
501
501
|
kind: "ref";
|
|
502
502
|
}>;
|
|
503
503
|
} : never : never);
|
|
504
|
+
/** The longest handoff card title (`ToolViewSchema` kind `handoff`), per language. */
|
|
505
|
+
export declare const HANDOFF_TITLE_MAX_CHARS = 200;
|
|
506
|
+
/** The longest handoff link (a relative web path). */
|
|
507
|
+
export declare const HANDOFF_URL_MAX_CHARS = 2000;
|
|
504
508
|
/**
|
|
505
509
|
* Structured view of a builtin tool's result (UI refresh B, spec §5.5 / §5.9): display only, like
|
|
506
510
|
* `display`. `command`: `Bash` (the model's `description`, the exit code, null when the
|
|
@@ -513,6 +517,10 @@ export type LogContentBlock = Exclude<ContentBlock, MediaBlock> | (MediaBlock ex
|
|
|
513
517
|
* `not_loaded`: a call to a tool the catalog holds but the step's request did not carry
|
|
514
518
|
* (ToolSearch mode, spec 5.5): expected behaviour, the model is told to load it first. The result
|
|
515
519
|
* stays `isError: true` for the model; the web shows it as a neutral outcome too.
|
|
520
|
+
* `handoff`: a `Platform` operation whose decision stays with a person on a web page (platform web
|
|
521
|
+
* parity spec §4.4, §6): the card's title and either a relative web path (`link`, also in the
|
|
522
|
+
* result text as `reviewUrl`) or a connector to connect (`connect`: the web's Connect button starts
|
|
523
|
+
* the OAuth flow from the person's session). IM forwards it as a `bind` card.
|
|
516
524
|
*/
|
|
517
525
|
export declare const ToolViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
518
526
|
kind: z.ZodLiteral<"command">;
|
|
@@ -561,6 +569,19 @@ export declare const ToolViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
561
569
|
}>;
|
|
562
570
|
}, z.core.$strip>, z.ZodObject<{
|
|
563
571
|
kind: z.ZodLiteral<"not_loaded">;
|
|
572
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
573
|
+
kind: z.ZodLiteral<"handoff">;
|
|
574
|
+
title: z.ZodObject<{
|
|
575
|
+
zh: z.ZodString;
|
|
576
|
+
en: z.ZodString;
|
|
577
|
+
}, z.core.$strip>;
|
|
578
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
579
|
+
type: z.ZodLiteral<"link">;
|
|
580
|
+
url: z.ZodString;
|
|
581
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
582
|
+
type: z.ZodLiteral<"connect">;
|
|
583
|
+
connectorId: z.ZodString;
|
|
584
|
+
}, z.core.$strip>], "type">;
|
|
564
585
|
}, z.core.$strip>], "kind">;
|
|
565
586
|
export type ToolView = z.infer<typeof ToolViewSchema>;
|
|
566
587
|
/**
|
|
@@ -1424,6 +1445,19 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1424
1445
|
}>;
|
|
1425
1446
|
}, z.core.$strip>, z.ZodObject<{
|
|
1426
1447
|
kind: z.ZodLiteral<"not_loaded">;
|
|
1448
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1449
|
+
kind: z.ZodLiteral<"handoff">;
|
|
1450
|
+
title: z.ZodObject<{
|
|
1451
|
+
zh: z.ZodString;
|
|
1452
|
+
en: z.ZodString;
|
|
1453
|
+
}, z.core.$strip>;
|
|
1454
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1455
|
+
type: z.ZodLiteral<"link">;
|
|
1456
|
+
url: z.ZodString;
|
|
1457
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1458
|
+
type: z.ZodLiteral<"connect">;
|
|
1459
|
+
connectorId: z.ZodString;
|
|
1460
|
+
}, z.core.$strip>], "type">;
|
|
1427
1461
|
}, z.core.$strip>], "kind">>;
|
|
1428
1462
|
card: z.ZodOptional<z.ZodObject<{
|
|
1429
1463
|
plugin: z.ZodString;
|
|
@@ -1531,6 +1565,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1531
1565
|
}>>;
|
|
1532
1566
|
byAccountId: z.ZodNullable<z.ZodString>;
|
|
1533
1567
|
reason: z.ZodOptional<z.ZodString>;
|
|
1568
|
+
inputsProvided: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1534
1569
|
}, z.core.$strip>;
|
|
1535
1570
|
}, z.core.$strip>, z.ZodObject<{
|
|
1536
1571
|
type: z.ZodLiteral<"approval_updated">;
|
|
@@ -516,6 +516,12 @@ const FileStateViewSchema = z.object({
|
|
|
516
516
|
size: count,
|
|
517
517
|
sha256: z.string().regex(/^[0-9a-f]{64}$/),
|
|
518
518
|
});
|
|
519
|
+
/** The longest handoff card title (`ToolViewSchema` kind `handoff`), per language. */
|
|
520
|
+
export const HANDOFF_TITLE_MAX_CHARS = 200;
|
|
521
|
+
/** The longest handoff link (a relative web path). */
|
|
522
|
+
export const HANDOFF_URL_MAX_CHARS = 2000;
|
|
523
|
+
/** A relative web path: one leading `/`, never `//` (another host) or a backslash. */
|
|
524
|
+
const HANDOFF_PATH = /^\/(?![/\\])[^\\\s]*$/;
|
|
519
525
|
/**
|
|
520
526
|
* Structured view of a builtin tool's result (UI refresh B, spec §5.5 / §5.9): display only, like
|
|
521
527
|
* `display`. `command`: `Bash` (the model's `description`, the exit code, null when the
|
|
@@ -528,6 +534,10 @@ const FileStateViewSchema = z.object({
|
|
|
528
534
|
* `not_loaded`: a call to a tool the catalog holds but the step's request did not carry
|
|
529
535
|
* (ToolSearch mode, spec 5.5): expected behaviour, the model is told to load it first. The result
|
|
530
536
|
* stays `isError: true` for the model; the web shows it as a neutral outcome too.
|
|
537
|
+
* `handoff`: a `Platform` operation whose decision stays with a person on a web page (platform web
|
|
538
|
+
* parity spec §4.4, §6): the card's title and either a relative web path (`link`, also in the
|
|
539
|
+
* result text as `reviewUrl`) or a connector to connect (`connect`: the web's Connect button starts
|
|
540
|
+
* the OAuth flow from the person's session). IM forwards it as a `bind` card.
|
|
531
541
|
*/
|
|
532
542
|
export const ToolViewSchema = z.discriminatedUnion("kind", [
|
|
533
543
|
z.object({
|
|
@@ -569,6 +579,20 @@ export const ToolViewSchema = z.discriminatedUnion("kind", [
|
|
|
569
579
|
reason: z.enum(["not_read", "modified"]),
|
|
570
580
|
}),
|
|
571
581
|
z.object({ kind: z.literal("not_loaded") }),
|
|
582
|
+
z.object({
|
|
583
|
+
kind: z.literal("handoff"),
|
|
584
|
+
title: z.object({
|
|
585
|
+
zh: z.string().min(1).max(HANDOFF_TITLE_MAX_CHARS),
|
|
586
|
+
en: z.string().min(1).max(HANDOFF_TITLE_MAX_CHARS),
|
|
587
|
+
}),
|
|
588
|
+
target: z.discriminatedUnion("type", [
|
|
589
|
+
z.object({
|
|
590
|
+
type: z.literal("link"),
|
|
591
|
+
url: z.string().max(HANDOFF_URL_MAX_CHARS).regex(HANDOFF_PATH, "a relative web path"),
|
|
592
|
+
}),
|
|
593
|
+
z.object({ type: z.literal("connect"), connectorId: z.string().min(1).max(100) }),
|
|
594
|
+
]),
|
|
595
|
+
}),
|
|
572
596
|
]);
|
|
573
597
|
const ModelUsageShape = {
|
|
574
598
|
inputTokens: count,
|
|
@@ -1278,6 +1302,11 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1278
1302
|
* denied call's `tool_result`).
|
|
1279
1303
|
*/
|
|
1280
1304
|
reason: z.string().max(APPROVAL_DENY_REASON_MAX_CHARS).optional(),
|
|
1305
|
+
/**
|
|
1306
|
+
* The person field paths whose values the person entered with the approval (platform web
|
|
1307
|
+
* parity spec §4.3; display only, never a value).
|
|
1308
|
+
*/
|
|
1309
|
+
inputsProvided: z.array(z.string().max(200)).max(32).optional(),
|
|
1281
1310
|
})),
|
|
1282
1311
|
/**
|
|
1283
1312
|
* A still-pending approval changed without a decision: a network ask's "always allow on this
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
/** Values shorter than this are never matched: a short value would match ordinary text. */
|
|
3
|
+
export declare const LEAK_CHECK_MIN_LENGTH = 8;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a value a person is about to seal (an approval card's secret field) already appeared in
|
|
6
|
+
* the conversation. The event payloads are searched in PG (`strpos` over the payload's JSON text,
|
|
7
|
+
* for the root conversation and every sub-agent below it, every event type), so the value is a
|
|
8
|
+
* bind parameter and never leaves the database; it is never logged.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConversationLeakCheck {
|
|
11
|
+
private readonly db;
|
|
12
|
+
constructor(db: KernelDb);
|
|
13
|
+
/**
|
|
14
|
+
* The keys of `values` (value paths) whose value, 8 characters or more, appears in the event
|
|
15
|
+
* log of `conversationId`'s root conversation tree. Runs inside the caller's transaction when
|
|
16
|
+
* there is one.
|
|
17
|
+
*/
|
|
18
|
+
leaked(conversationId: string, values: Readonly<Record<string, string>>): Promise<string[]>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The one {@link ConversationLeakCheck} (the database only), its own module so the tools module
|
|
22
|
+
* (the approval decision) imports it without importing the conversations module, which imports
|
|
23
|
+
* the tools module.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ConversationLeakCheckModule {
|
|
26
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
11
|
+
import { sql } from "kysely";
|
|
12
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
+
import { rootConversationOf } from "../runtime/subagents/child.js";
|
|
14
|
+
import { conversationTree } from "./tree.js";
|
|
15
|
+
/** Values shorter than this are never matched: a short value would match ordinary text. */
|
|
16
|
+
export const LEAK_CHECK_MIN_LENGTH = 8;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a value a person is about to seal (an approval card's secret field) already appeared in
|
|
19
|
+
* the conversation. The event payloads are searched in PG (`strpos` over the payload's JSON text,
|
|
20
|
+
* for the root conversation and every sub-agent below it, every event type), so the value is a
|
|
21
|
+
* bind parameter and never leaves the database; it is never logged.
|
|
22
|
+
*/
|
|
23
|
+
let ConversationLeakCheck = class ConversationLeakCheck {
|
|
24
|
+
db;
|
|
25
|
+
constructor(db) {
|
|
26
|
+
this.db = db;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The keys of `values` (value paths) whose value, 8 characters or more, appears in the event
|
|
30
|
+
* log of `conversationId`'s root conversation tree. Runs inside the caller's transaction when
|
|
31
|
+
* there is one.
|
|
32
|
+
*/
|
|
33
|
+
async leaked(conversationId, values) {
|
|
34
|
+
const candidates = Object.entries(values).filter(([, v]) => v.length >= LEAK_CHECK_MIN_LENGTH);
|
|
35
|
+
if (candidates.length === 0)
|
|
36
|
+
return [];
|
|
37
|
+
const root = await rootConversationOf(this.db.db, conversationId);
|
|
38
|
+
const ids = (await conversationTree(this.db.db, root)).map((c) => c.id);
|
|
39
|
+
const found = [];
|
|
40
|
+
for (const [path, value] of candidates) {
|
|
41
|
+
// the payload is stored as JSON text, so a value is searched in its JSON-escaped form
|
|
42
|
+
const needle = JSON.stringify(value).slice(1, -1);
|
|
43
|
+
const r = await sql `
|
|
44
|
+
SELECT EXISTS (
|
|
45
|
+
SELECT 1 FROM capybara.conversation_events
|
|
46
|
+
WHERE conversation_id = ANY(${ids}::text[]) AND strpos(payload::text, ${needle}) > 0
|
|
47
|
+
) AS hit`.execute(this.db.db);
|
|
48
|
+
if (r.rows[0]?.hit === true)
|
|
49
|
+
found.push(path);
|
|
50
|
+
}
|
|
51
|
+
return found;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
ConversationLeakCheck = __decorate([
|
|
55
|
+
Injectable(),
|
|
56
|
+
__param(0, Inject(KernelDb))
|
|
57
|
+
], ConversationLeakCheck);
|
|
58
|
+
export { ConversationLeakCheck };
|
|
59
|
+
/**
|
|
60
|
+
* The one {@link ConversationLeakCheck} (the database only), its own module so the tools module
|
|
61
|
+
* (the approval decision) imports it without importing the conversations module, which imports
|
|
62
|
+
* the tools module.
|
|
63
|
+
*/
|
|
64
|
+
let ConversationLeakCheckModule = class ConversationLeakCheckModule {
|
|
65
|
+
};
|
|
66
|
+
ConversationLeakCheckModule = __decorate([
|
|
67
|
+
Module({ providers: [ConversationLeakCheck], exports: [ConversationLeakCheck] })
|
|
68
|
+
], ConversationLeakCheckModule);
|
|
69
|
+
export { ConversationLeakCheckModule };
|
package/dist/ctx/secrets.d.ts
CHANGED
|
@@ -48,18 +48,30 @@ export interface RewrapResult {
|
|
|
48
48
|
dataKeys: number;
|
|
49
49
|
/** Unexpired one-time initial passwords (`account_initial_passwords`) now sealed with it. */
|
|
50
50
|
initialPasswords: number;
|
|
51
|
+
/** Unexpired sealed Platform reveals (`platform_sealed_reveals`, invitation links) now sealed with it. */
|
|
52
|
+
sealedReveals: number;
|
|
51
53
|
}
|
|
52
54
|
/** Rows rewrapped per transaction by default. */
|
|
53
55
|
export declare const REWRAP_BATCH_SIZE = 500;
|
|
54
56
|
/** The AAD binding a sealed initial password to its account (a row moved to another one fails). */
|
|
55
57
|
export declare const initialPasswordAad: (accountId: string) => string;
|
|
58
|
+
/**
|
|
59
|
+
* The AAD binding a person's sealed card values to their approval and field paths (sorted, joined
|
|
60
|
+
* by ","): a row moved to another approval, or whose paths are altered, fails to unwrap.
|
|
61
|
+
*/
|
|
62
|
+
export declare const platformSealedInputAad: (approvalId: string, paths: readonly string[]) => string;
|
|
63
|
+
/**
|
|
64
|
+
* The AAD binding a sealed Platform reveal (an invitation link) to its subject: a row moved to
|
|
65
|
+
* another subject fails to unwrap.
|
|
66
|
+
*/
|
|
67
|
+
export declare const platformSealedRevealAad: (id: string) => string;
|
|
56
68
|
type RewrapHandles = {
|
|
57
69
|
db: Pick<KernelDb, "db">;
|
|
58
70
|
txHost: Pick<TransactionHost, "run">;
|
|
59
71
|
};
|
|
60
72
|
/**
|
|
61
73
|
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys
|
|
62
|
-
* and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
|
|
74
|
+
* and unexpired initial passwords and sealed reveals) with the current key, `batchSize` rows per transaction, until
|
|
63
75
|
* none is left. Checks first that the keyring holds every master key in use and throws (naming row
|
|
64
76
|
* ids and key ids, never key material) before writing anything when it does not. Idempotent: a
|
|
65
77
|
* second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
|
package/dist/ctx/secrets.js
CHANGED
|
@@ -147,6 +147,16 @@ export function createSecrets(db, keyring, namespace) {
|
|
|
147
147
|
export const REWRAP_BATCH_SIZE = 500;
|
|
148
148
|
/** The AAD binding a sealed initial password to its account (a row moved to another one fails). */
|
|
149
149
|
export const initialPasswordAad = (accountId) => `capybara:initial-password:${accountId}`;
|
|
150
|
+
/**
|
|
151
|
+
* The AAD binding a person's sealed card values to their approval and field paths (sorted, joined
|
|
152
|
+
* by ","): a row moved to another approval, or whose paths are altered, fails to unwrap.
|
|
153
|
+
*/
|
|
154
|
+
export const platformSealedInputAad = (approvalId, paths) => `capybara:platform-sealed-input:${approvalId}:${[...paths].sort().join(",")}`;
|
|
155
|
+
/**
|
|
156
|
+
* The AAD binding a sealed Platform reveal (an invitation link) to its subject: a row moved to
|
|
157
|
+
* another subject fails to unwrap.
|
|
158
|
+
*/
|
|
159
|
+
export const platformSealedRevealAad = (id) => `capybara:platform-sealed-reveal:${id}`;
|
|
150
160
|
const MASTER_KEYED = [
|
|
151
161
|
{
|
|
152
162
|
table: "org_data_keys",
|
|
@@ -162,6 +172,13 @@ const MASTER_KEYED = [
|
|
|
162
172
|
aad: initialPasswordAad,
|
|
163
173
|
hasExpiresAt: true,
|
|
164
174
|
},
|
|
175
|
+
{
|
|
176
|
+
table: "platform_sealed_reveals",
|
|
177
|
+
idColumn: "id",
|
|
178
|
+
dataColumn: "ciphertext",
|
|
179
|
+
aad: platformSealedRevealAad,
|
|
180
|
+
hasExpiresAt: true,
|
|
181
|
+
},
|
|
165
182
|
];
|
|
166
183
|
function staleRows(db, t, keyring) {
|
|
167
184
|
let q = db
|
|
@@ -181,7 +198,7 @@ function assertKnown(t, keyring, rows) {
|
|
|
181
198
|
}
|
|
182
199
|
/**
|
|
183
200
|
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys
|
|
184
|
-
* and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
|
|
201
|
+
* and unexpired initial passwords and sealed reveals) with the current key, `batchSize` rows per transaction, until
|
|
185
202
|
* none is left. Checks first that the keyring holds every master key in use and throws (naming row
|
|
186
203
|
* ids and key ids, never key material) before writing anything when it does not. Idempotent: a
|
|
187
204
|
* second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
|
|
@@ -242,5 +259,6 @@ export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
|
|
|
242
259
|
return {
|
|
243
260
|
dataKeys: counts.get("org_data_keys") ?? 0,
|
|
244
261
|
initialPasswords: counts.get("account_initial_passwords") ?? 0,
|
|
262
|
+
sealedReveals: counts.get("platform_sealed_reveals") ?? 0,
|
|
245
263
|
};
|
|
246
264
|
}
|