@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
|
@@ -0,0 +1,48 @@
|
|
|
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 { Controller, HttpCode, Inject, Post } from "@nestjs/common";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { CurrentPrincipal, requireUser, SessionOnly, } from "../identity/principal.js";
|
|
13
|
+
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
14
|
+
import { ZParam } from "../infra/validation/zod-params.js";
|
|
15
|
+
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
16
|
+
import { SealedReveals } from "./sealed-reveals.js";
|
|
17
|
+
const ApprovalParams = z.object({ approvalId: z.string().min(1).max(100) });
|
|
18
|
+
class ApprovalParamsDto extends createZodDto(ApprovalParams, "InvitationLinkParams") {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The link of an invitation an org admin's agent created (platform web parity spec §7.2): shown
|
|
22
|
+
* once, on the web, to the person who approved the `orgs.invite` call. A POST because reading
|
|
23
|
+
* consumes it.
|
|
24
|
+
*/
|
|
25
|
+
let SealedRevealsController = class SealedRevealsController {
|
|
26
|
+
reveals;
|
|
27
|
+
constructor(reveals) {
|
|
28
|
+
this.reveals = reveals;
|
|
29
|
+
}
|
|
30
|
+
async reveal(principal, org, params) {
|
|
31
|
+
const p = requireUser(principal);
|
|
32
|
+
return this.reveals.reveal(org.orgId, params.approvalId, p.account.id);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__decorate([
|
|
36
|
+
Post(),
|
|
37
|
+
HttpCode(200),
|
|
38
|
+
OrgAction("org.invitations.manage"),
|
|
39
|
+
SessionOnly(),
|
|
40
|
+
__param(0, CurrentPrincipal()),
|
|
41
|
+
__param(1, CurrentOrg()),
|
|
42
|
+
__param(2, ZParam(ApprovalParamsDto))
|
|
43
|
+
], SealedRevealsController.prototype, "reveal", null);
|
|
44
|
+
SealedRevealsController = __decorate([
|
|
45
|
+
Controller("api/v1/orgs/:orgId/approvals/:approvalId/invitation-link"),
|
|
46
|
+
__param(0, Inject(SealedReveals))
|
|
47
|
+
], SealedRevealsController);
|
|
48
|
+
export { SealedRevealsController };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Keyring } from "../ctx/secrets.js";
|
|
2
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
4
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
6
|
+
/**
|
|
7
|
+
* How long a sealed invitation link waits for its reader, like a generated initial password: the
|
|
8
|
+
* approving person reads it right after the call runs; one never read expires (revoke the
|
|
9
|
+
* invitation and invite again).
|
|
10
|
+
*/
|
|
11
|
+
export declare const SEALED_REVEAL_TTL_MS: number;
|
|
12
|
+
/** The tool key of the approval an invitation link belongs to. */
|
|
13
|
+
export declare const INVITE_TOOL_KEY = "Platform:orgs.invite";
|
|
14
|
+
/** Where a sealed value is delivered: the approved tool call and the person who approved. */
|
|
15
|
+
export interface SealedRevealDelivery {
|
|
16
|
+
conversationId: string;
|
|
17
|
+
/** The run of the call: a call id is unique only within its run. */
|
|
18
|
+
runId: string;
|
|
19
|
+
callId: string;
|
|
20
|
+
/** The account that may read it: the actor who confirmed the call. */
|
|
21
|
+
recipientAccountId: string;
|
|
22
|
+
}
|
|
23
|
+
/** The web path of an invitation link (apps/web `invitePath`). */
|
|
24
|
+
export declare const invitationPath: (token: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Values a Platform call makes that only the person who approved the call may read (platform web
|
|
27
|
+
* parity spec §7.2, plan ruling R10): the token of an invitation an org admin's agent created. The
|
|
28
|
+
* token never reaches the model, the tool result, the event log, the audit or a log line: it is
|
|
29
|
+
* sealed with the master keyring in the creation's transaction and read once, on the web, by the
|
|
30
|
+
* person who approved the call, like the generated initial password (`InitialPasswords`).
|
|
31
|
+
*/
|
|
32
|
+
export declare class SealedReveals {
|
|
33
|
+
private readonly db;
|
|
34
|
+
readonly txHost: TransactionHost;
|
|
35
|
+
private readonly keyring;
|
|
36
|
+
private readonly config;
|
|
37
|
+
constructor(db: KernelDb, txHost: TransactionHost, keyring: Keyring, config: KernelConfigService);
|
|
38
|
+
/** Seals an invitation's token for `to`, in the caller's (the creation's) transaction. */
|
|
39
|
+
sealIn(orgId: string, invitationId: string, token: string, to: SealedRevealDelivery): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* The link of the invitation an approved `orgs.invite` call created, read once by the person who
|
|
42
|
+
* approved it (`approvalId` in `orgId`, decided by `accountId`), then deleted. Anything else (not
|
|
43
|
+
* that person, not approved, not run yet, read already, expired, the invitation no longer
|
|
44
|
+
* pending) is `invitation.link_unavailable`, saying nothing about which. Audits the read
|
|
45
|
+
* (without the token). The URL is absolute under `http.publicUrl`, else the web path.
|
|
46
|
+
*/
|
|
47
|
+
reveal(orgId: string, approvalId: string, accountId: string): Promise<{
|
|
48
|
+
url: string;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
/** Deletes the sealed reveals past `expires_at`; returns how many. */
|
|
52
|
+
export declare function deleteExpiredSealedReveals(db: KernelSchemaDb): Promise<number>;
|
|
@@ -0,0 +1,153 @@
|
|
|
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 } from "@nestjs/common";
|
|
11
|
+
import { sql } from "kysely";
|
|
12
|
+
import { platformSealedRevealAad as aadOf } from "../ctx/secrets.js";
|
|
13
|
+
import { ApiError } from "../errors.js";
|
|
14
|
+
import { audit } from "../identity/audit.js";
|
|
15
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
16
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
17
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
18
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
19
|
+
import { KEYRING } from "../infra/tokens.js";
|
|
20
|
+
/**
|
|
21
|
+
* How long a sealed invitation link waits for its reader, like a generated initial password: the
|
|
22
|
+
* approving person reads it right after the call runs; one never read expires (revoke the
|
|
23
|
+
* invitation and invite again).
|
|
24
|
+
*/
|
|
25
|
+
export const SEALED_REVEAL_TTL_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
/** The tool key of the approval an invitation link belongs to. */
|
|
27
|
+
export const INVITE_TOOL_KEY = "Platform:orgs.invite";
|
|
28
|
+
/** The web path of an invitation link (apps/web `invitePath`). */
|
|
29
|
+
export const invitationPath = (token) => `/invite/${encodeURIComponent(token)}`;
|
|
30
|
+
/**
|
|
31
|
+
* Values a Platform call makes that only the person who approved the call may read (platform web
|
|
32
|
+
* parity spec §7.2, plan ruling R10): the token of an invitation an org admin's agent created. The
|
|
33
|
+
* token never reaches the model, the tool result, the event log, the audit or a log line: it is
|
|
34
|
+
* sealed with the master keyring in the creation's transaction and read once, on the web, by the
|
|
35
|
+
* person who approved the call, like the generated initial password (`InitialPasswords`).
|
|
36
|
+
*/
|
|
37
|
+
let SealedReveals = class SealedReveals {
|
|
38
|
+
db;
|
|
39
|
+
txHost;
|
|
40
|
+
keyring;
|
|
41
|
+
config;
|
|
42
|
+
constructor(db, txHost, keyring, config) {
|
|
43
|
+
this.db = db;
|
|
44
|
+
this.txHost = txHost;
|
|
45
|
+
this.keyring = keyring;
|
|
46
|
+
this.config = config;
|
|
47
|
+
}
|
|
48
|
+
/** Seals an invitation's token for `to`, in the caller's (the creation's) transaction. */
|
|
49
|
+
async sealIn(orgId, invitationId, token, to) {
|
|
50
|
+
const plain = Buffer.from(token, "utf8");
|
|
51
|
+
const { data, masterKeyId } = this.keyring.wrap(plain, aadOf(invitationId));
|
|
52
|
+
plain.fill(0);
|
|
53
|
+
await this.db
|
|
54
|
+
.insertInto("platform_sealed_reveals")
|
|
55
|
+
.values({
|
|
56
|
+
id: invitationId,
|
|
57
|
+
kind: "invitation_link",
|
|
58
|
+
org_id: orgId,
|
|
59
|
+
recipient_account_id: to.recipientAccountId,
|
|
60
|
+
conversation_id: to.conversationId,
|
|
61
|
+
run_id: to.runId,
|
|
62
|
+
call_id: to.callId,
|
|
63
|
+
master_key_id: masterKeyId,
|
|
64
|
+
ciphertext: data,
|
|
65
|
+
// the DB clock, the same one reveal and the cleanup compare against
|
|
66
|
+
expires_at: sql `now() + make_interval(secs => ${SEALED_REVEAL_TTL_MS / 1000})`,
|
|
67
|
+
})
|
|
68
|
+
.execute();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The link of the invitation an approved `orgs.invite` call created, read once by the person who
|
|
72
|
+
* approved it (`approvalId` in `orgId`, decided by `accountId`), then deleted. Anything else (not
|
|
73
|
+
* that person, not approved, not run yet, read already, expired, the invitation no longer
|
|
74
|
+
* pending) is `invitation.link_unavailable`, saying nothing about which. Audits the read
|
|
75
|
+
* (without the token). The URL is absolute under `http.publicUrl`, else the web path.
|
|
76
|
+
*/
|
|
77
|
+
async reveal(orgId, approvalId, accountId) {
|
|
78
|
+
const unavailable = () => new ApiError("invitation.link_unavailable", "No invitation link to show: it was shown already, has expired, the invitation is no longer pending, or it was not created by a call you approved");
|
|
79
|
+
const approval = await this.db
|
|
80
|
+
.selectFrom("approvals")
|
|
81
|
+
.select(["conversation_id", "run_id", "call_id", "tool_key", "status", "decided_by"])
|
|
82
|
+
.where("id", "=", approvalId)
|
|
83
|
+
.where("org_id", "=", orgId)
|
|
84
|
+
.executeTakeFirst();
|
|
85
|
+
if (approval === undefined ||
|
|
86
|
+
approval.tool_key !== INVITE_TOOL_KEY ||
|
|
87
|
+
approval.status !== "approved" ||
|
|
88
|
+
approval.decided_by !== accountId) {
|
|
89
|
+
throw unavailable();
|
|
90
|
+
}
|
|
91
|
+
// exactly the row of this approval's call, for a still pending invitation: deleted as read
|
|
92
|
+
const row = await this.db
|
|
93
|
+
.deleteFrom("platform_sealed_reveals")
|
|
94
|
+
.where("kind", "=", "invitation_link")
|
|
95
|
+
.where("org_id", "=", orgId)
|
|
96
|
+
.where("conversation_id", "=", approval.conversation_id)
|
|
97
|
+
.where("run_id", "=", approval.run_id)
|
|
98
|
+
.where("call_id", "=", approval.call_id)
|
|
99
|
+
.where("recipient_account_id", "=", accountId)
|
|
100
|
+
.where("expires_at", ">", sql `now()`)
|
|
101
|
+
.where((eb) => eb.exists(eb
|
|
102
|
+
.selectFrom("invitations")
|
|
103
|
+
.select("invitations.id")
|
|
104
|
+
.whereRef("invitations.id", "=", "platform_sealed_reveals.id")
|
|
105
|
+
.where("invitations.accepted_at", "is", null)
|
|
106
|
+
.where("invitations.revoked_at", "is", null)
|
|
107
|
+
.where(sql `invitations.expires_at > now()`)))
|
|
108
|
+
.returning(["id", "master_key_id", "ciphertext"])
|
|
109
|
+
.executeTakeFirst();
|
|
110
|
+
if (row === undefined)
|
|
111
|
+
throw unavailable();
|
|
112
|
+
let token;
|
|
113
|
+
try {
|
|
114
|
+
token = this.keyring
|
|
115
|
+
.unwrap(row.master_key_id, Buffer.from(row.ciphertext), aadOf(row.id))
|
|
116
|
+
.toString("utf8");
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
throw unavailable();
|
|
120
|
+
}
|
|
121
|
+
await audit(this.db.db, {
|
|
122
|
+
actorAccountId: accountId,
|
|
123
|
+
orgId,
|
|
124
|
+
action: "org.invitation.link_shown",
|
|
125
|
+
target: row.id,
|
|
126
|
+
detail: { approvalId },
|
|
127
|
+
});
|
|
128
|
+
const base = this.config.get().http.publicUrl?.replace(/\/+$/, "") ?? "";
|
|
129
|
+
return { url: `${base}${invitationPath(token)}` };
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
__decorate([
|
|
133
|
+
Transactional({ propagation: "mandatory" })
|
|
134
|
+
], SealedReveals.prototype, "sealIn", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
Transactional()
|
|
137
|
+
], SealedReveals.prototype, "reveal", null);
|
|
138
|
+
SealedReveals = __decorate([
|
|
139
|
+
Injectable(),
|
|
140
|
+
__param(0, Inject(KernelDb)),
|
|
141
|
+
__param(1, Inject(TransactionHost)),
|
|
142
|
+
__param(2, Inject(KEYRING)),
|
|
143
|
+
__param(3, Inject(KernelConfigService))
|
|
144
|
+
], SealedReveals);
|
|
145
|
+
export { SealedReveals };
|
|
146
|
+
/** Deletes the sealed reveals past `expires_at`; returns how many. */
|
|
147
|
+
export async function deleteExpiredSealedReveals(db) {
|
|
148
|
+
const r = await db
|
|
149
|
+
.deleteFrom("platform_sealed_reveals")
|
|
150
|
+
.where("expires_at", "<=", sql `now()`)
|
|
151
|
+
.executeTakeFirst();
|
|
152
|
+
return Number(r.numDeletedRows);
|
|
153
|
+
}
|
|
@@ -121,25 +121,30 @@ export async function readProjectKnowledge(files, target, opts = {}) {
|
|
|
121
121
|
return cannot(projectUnavailable.notDirectory(root));
|
|
122
122
|
const out = { project, root, skills: [] };
|
|
123
123
|
const agentsMd = `${root}/AGENTS.md`;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
124
|
+
// each read is a device round trip of its own: AGENTS.md and the skills go at the same time
|
|
125
|
+
const [, skills] = await Promise.all([
|
|
126
|
+
(async () => {
|
|
127
|
+
try {
|
|
128
|
+
const read = await files.readFile(agentsMd, AGENTS_MD_MAX_BYTES);
|
|
129
|
+
// none: a project with skills only, nothing to say (spec §4.7)
|
|
130
|
+
if (read !== null) {
|
|
131
|
+
const capped = capAgentsMd(decoder.decode(read.data), read.truncated);
|
|
132
|
+
out.agentsMd = capped.text;
|
|
133
|
+
if (capped.cut)
|
|
134
|
+
out.agentsMdTruncated = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
if (r.fatal(e))
|
|
139
|
+
throw e;
|
|
140
|
+
r.log("project AGENTS.md could not be read; left out this run", {
|
|
141
|
+
path: agentsMd,
|
|
142
|
+
reason: messageOf(e),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
})(),
|
|
146
|
+
readSkills(files, root, r),
|
|
147
|
+
]);
|
|
143
148
|
out.skills = skills.skills;
|
|
144
149
|
if (skills.truncated)
|
|
145
150
|
out.skillsTruncated = true;
|
package/dist/runtime/waits.js
CHANGED
|
@@ -20,7 +20,7 @@ import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
|
20
20
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
21
21
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
22
22
|
import { ApprovalsService, GIT_ASK_CANCELLED_NOTE, NETWORK_ASK_CANCELLED_NOTE, } from "../tools/approvals.service.js";
|
|
23
|
-
import { APPROVAL_CANCELLED_TEXT, INPUT_CANCELLED_TEXT, RUN_STOPPED_TEXT, ToolPipeline, } from "../tools/pipeline.js";
|
|
23
|
+
import { APPROVAL_CANCELLED_TEXT, INPUT_CANCELLED_TEXT, RUN_STOPPED_TEXT, ToolPipeline, withLeakedOnCard, } from "../tools/pipeline.js";
|
|
24
24
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
25
25
|
import { RunAbort } from "./abort.js";
|
|
26
26
|
import { KyselyCheckpointSaver } from "./checkpointer.js";
|
|
@@ -351,7 +351,13 @@ let Waits = class Waits {
|
|
|
351
351
|
text: `${kept.content}\n\n${a.kind === "git" ? GIT_ASK_CANCELLED_NOTE : NETWORK_ASK_CANCELLED_NOTE}`,
|
|
352
352
|
isError: kept.isError,
|
|
353
353
|
}
|
|
354
|
-
: {
|
|
354
|
+
: {
|
|
355
|
+
toolKey: a.tool_key,
|
|
356
|
+
// a tool ask whose card refused a person's value as leaked says so (§4.5)
|
|
357
|
+
text: withLeakedOnCard(APPROVAL_CANCELLED_TEXT, a.kind === "tool"
|
|
358
|
+
? a.detail?.leakedFields
|
|
359
|
+
: undefined),
|
|
360
|
+
});
|
|
355
361
|
const step = await this.approvalStep(t, conversationId, a.id);
|
|
356
362
|
if (step !== null)
|
|
357
363
|
steps.add(step);
|
|
@@ -152,7 +152,11 @@ export declare class PermissionFacts {
|
|
|
152
152
|
* The project snapshot that decides the working root of the conversation tree rooted at
|
|
153
153
|
* `rootConversationId` (project root spec §4.3): its latest `project_root` event, read only when
|
|
154
154
|
* the conversation is bound to a project (a free conversation reads one row by its key). Null:
|
|
155
|
-
* free
|
|
155
|
+
* free. A bound conversation with no snapshot recorded yet (its first run start could not ask
|
|
156
|
+
* the device: offline, or the read hit its time limit) works in the bound root: the binding was
|
|
157
|
+
* checked when the conversation was created and never changes, and `workingRootOf` still
|
|
158
|
+
* applies the mode, reach and home rules. Only a recorded `unavailable` snapshot (or one
|
|
159
|
+
* without a root) leaves the project for free mode (spec §4.3).
|
|
156
160
|
*/
|
|
157
161
|
workingProject(orgId: string, rootConversationId: string): Promise<WorkingProject | null>;
|
|
158
162
|
/** The workspace root of a conversation's latest `device_paths` event, or null. */
|
|
@@ -342,7 +342,11 @@ let PermissionFacts = class PermissionFacts {
|
|
|
342
342
|
* The project snapshot that decides the working root of the conversation tree rooted at
|
|
343
343
|
* `rootConversationId` (project root spec §4.3): its latest `project_root` event, read only when
|
|
344
344
|
* the conversation is bound to a project (a free conversation reads one row by its key). Null:
|
|
345
|
-
* free
|
|
345
|
+
* free. A bound conversation with no snapshot recorded yet (its first run start could not ask
|
|
346
|
+
* the device: offline, or the read hit its time limit) works in the bound root: the binding was
|
|
347
|
+
* checked when the conversation was created and never changes, and `workingRootOf` still
|
|
348
|
+
* applies the mode, reach and home rules. Only a recorded `unavailable` snapshot (or one
|
|
349
|
+
* without a root) leaves the project for free mode (spec §4.3).
|
|
346
350
|
*/
|
|
347
351
|
async workingProject(orgId, rootConversationId) {
|
|
348
352
|
const conv = await this.db
|
|
@@ -364,7 +368,9 @@ let PermissionFacts = class PermissionFacts {
|
|
|
364
368
|
.orderBy("seq", "desc")
|
|
365
369
|
.limit(1)
|
|
366
370
|
.executeTakeFirst();
|
|
367
|
-
if (row === undefined
|
|
371
|
+
if (row === undefined)
|
|
372
|
+
return { root: conv.project_path, unavailable: false };
|
|
373
|
+
if (typeof row.root !== "string")
|
|
368
374
|
return null;
|
|
369
375
|
return { root: row.root, unavailable: row.unavailable !== false };
|
|
370
376
|
}
|
|
@@ -66,6 +66,11 @@ export interface SetupGuideDocument {
|
|
|
66
66
|
kind: "channel-connection" | "connector";
|
|
67
67
|
id: string;
|
|
68
68
|
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* The drift hash of this mode and audience: what `channels.guide-ack` takes (admin audience, the
|
|
71
|
+
* connection's mode) once the person confirms the app is updated.
|
|
72
|
+
*/
|
|
73
|
+
hash: string;
|
|
69
74
|
webPath: string;
|
|
70
75
|
/** What stays with the person, and where they do it. */
|
|
71
76
|
handover: string;
|
|
@@ -277,8 +277,9 @@ let SetupGuidesService = class SetupGuidesService {
|
|
|
277
277
|
checks: g.checks.map((c) => ({ id: c.id, label: c.label })),
|
|
278
278
|
unresolved: g.unresolved,
|
|
279
279
|
target: g.target,
|
|
280
|
+
hash: g.hash,
|
|
280
281
|
webPath,
|
|
281
|
-
handover: `Secrets (tokens, signing secrets, client secrets) are typed by the person into their fields on ${webPath}; never ask for one in the conversation. Connecting a personal account
|
|
282
|
+
handover: `Secrets (tokens, signing secrets, client secrets) are typed by the person into their fields on ${webPath}; never ask for one in the conversation. A secret field a write takes as a person field is typed on the Platform confirmation card instead. Connecting a personal account is connectors.connect (a Connect button for the person); confirming the app was updated is the person's statement on the card of channels.guide-ack or connectors.guide-ack.`,
|
|
282
283
|
};
|
|
283
284
|
}
|
|
284
285
|
};
|
|
@@ -26,6 +26,7 @@ declare const DecisionBody: z.ZodObject<{
|
|
|
26
26
|
note: z.ZodOptional<z.ZodString>;
|
|
27
27
|
reason: z.ZodOptional<z.ZodString>;
|
|
28
28
|
hosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
29
|
+
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
29
30
|
}, z.core.$strict>;
|
|
30
31
|
/**
|
|
31
32
|
* 工具调用审批(`/api/v1/orgs/:orgId/approvals`,`approvals.decide`:访客起、仅限用户主体——agent 不能审批,R2)。
|
|
@@ -14,10 +14,13 @@ import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principa
|
|
|
14
14
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
15
15
|
import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
|
|
16
16
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
17
|
+
import { PERSON_FIELD_MAX_BYTES, PERSON_FIELDS_MAX } from "../platform/person-fields.js";
|
|
17
18
|
import { CONTROL_OR_HIDDEN_RE } from "../text.js";
|
|
18
19
|
import { ApprovalsListQuerySchema } from "./approvals.schemas.js";
|
|
19
20
|
import { APPROVAL_DENY_REASON_MAX_CHARS, ApprovalsService, publicRecord, } from "./approvals.service.js";
|
|
20
21
|
const ListQuery = ApprovalsListQuerySchema;
|
|
22
|
+
/** The longest input path: the person field paths' own limit (`askPerson`). */
|
|
23
|
+
const INPUT_PATH_MAX_CHARS = 200;
|
|
21
24
|
const DecisionBody = z
|
|
22
25
|
.object({
|
|
23
26
|
decision: z.enum(["approve", "deny"]),
|
|
@@ -42,8 +45,24 @@ const DecisionBody = z
|
|
|
42
45
|
.min(1)
|
|
43
46
|
.max(NETWORK_ASK_MAX_HOSTS)
|
|
44
47
|
.optional(),
|
|
48
|
+
/**
|
|
49
|
+
* An approval with person fields only: the values the person entered on the card, by field
|
|
50
|
+
* path (platform web parity spec §4.2). Never logged, never stored but sealed.
|
|
51
|
+
*/
|
|
52
|
+
inputs: z
|
|
53
|
+
// the value's max counts characters (a cheap upper bound); the 16 KiB byte limit is
|
|
54
|
+
// checkPersonValue's, in the decision
|
|
55
|
+
.record(z.string().min(1).max(INPUT_PATH_MAX_CHARS), z.string().max(PERSON_FIELD_MAX_BYTES))
|
|
56
|
+
.refine((r) => Object.keys(r).length <= PERSON_FIELDS_MAX, {
|
|
57
|
+
message: `At most ${PERSON_FIELDS_MAX} inputs`,
|
|
58
|
+
})
|
|
59
|
+
.optional(),
|
|
45
60
|
})
|
|
46
61
|
.strict()
|
|
62
|
+
.refine((b) => b.inputs === undefined || b.decision === "approve", {
|
|
63
|
+
path: ["inputs"],
|
|
64
|
+
message: "Inputs can only be given with approve",
|
|
65
|
+
})
|
|
47
66
|
.refine((b) => b.reason === undefined || b.decision === "deny", {
|
|
48
67
|
path: ["reason"],
|
|
49
68
|
message: "A reason can only be given with deny",
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { type LocalizedName, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { EventLog } from "../conversations/event-log.js";
|
|
3
3
|
import { type ReviewRecord, type ToolView } from "../conversations/events.js";
|
|
4
|
+
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
4
5
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
6
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
6
7
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
7
8
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
8
9
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
9
10
|
import { type OrgRole } from "../orgs/roles.js";
|
|
11
|
+
import { type PersonFieldSpec } from "../platform/person-fields.js";
|
|
12
|
+
import { SealedInputs } from "../platform/sealed-inputs.js";
|
|
10
13
|
import { RunResume } from "../runtime/run-jobs.js";
|
|
11
14
|
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
12
15
|
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
@@ -150,6 +153,21 @@ export interface ApprovalRecord {
|
|
|
150
153
|
git: GitAskDetail | null;
|
|
151
154
|
/** A command review ask's facts; null for any other kind. */
|
|
152
155
|
command: CommandAskDetail | null;
|
|
156
|
+
/**
|
|
157
|
+
* A tool ask with person fields (platform web parity spec §4.2): the secret fields the person
|
|
158
|
+
* enters on the card, as specs (path, label, schema node), never values. Absent otherwise.
|
|
159
|
+
*/
|
|
160
|
+
personFields?: PersonFieldSpec[];
|
|
161
|
+
/** The card's target name with {@link personFields} ("Anthropic: deployment config"). */
|
|
162
|
+
personTarget?: {
|
|
163
|
+
zh: string;
|
|
164
|
+
en: string;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The person fields whose entered value was refused as leaked (§4.5; paths only): a call that
|
|
168
|
+
* then ends without running tells the agent to have them rotated.
|
|
169
|
+
*/
|
|
170
|
+
leakedFields?: string[];
|
|
153
171
|
toolKey: string;
|
|
154
172
|
specHash: string;
|
|
155
173
|
connectorId: string | null;
|
|
@@ -258,6 +276,18 @@ export interface ApprovalRequestInput {
|
|
|
258
276
|
};
|
|
259
277
|
/** The scopes the decider may choose; unset: derived (see {@link ApprovalRecord.scopes}). */
|
|
260
278
|
scopes?: ApprovalScope[];
|
|
279
|
+
/** A tool ask's person fields and their target (stored in `detail`; specs only, no values). */
|
|
280
|
+
detail?: ToolAskDetail;
|
|
281
|
+
}
|
|
282
|
+
/** A tool ask's `detail`: the person fields the card asks for and the target they belong to. */
|
|
283
|
+
export interface ToolAskDetail {
|
|
284
|
+
personFields: PersonFieldSpec[];
|
|
285
|
+
target: {
|
|
286
|
+
zh: string;
|
|
287
|
+
en: string;
|
|
288
|
+
};
|
|
289
|
+
/** The paths whose entered value the decision refused as leaked (written by the decision). */
|
|
290
|
+
leakedFields?: string[];
|
|
261
291
|
}
|
|
262
292
|
export interface DecisionInput {
|
|
263
293
|
decision: "approve" | "deny";
|
|
@@ -271,6 +301,11 @@ export interface DecisionInput {
|
|
|
271
301
|
* unchecked ones count as denied (P-D5).
|
|
272
302
|
*/
|
|
273
303
|
hosts?: string[] | undefined;
|
|
304
|
+
/**
|
|
305
|
+
* An approval with person fields only, with `approve`: the values the person entered, by field
|
|
306
|
+
* path (platform web parity spec §4.2). Sealed in the decision; never logged or stored as text.
|
|
307
|
+
*/
|
|
308
|
+
inputs?: Record<string, string> | undefined;
|
|
274
309
|
}
|
|
275
310
|
/** Where a decision was made (the device's local audit line and `device.network_*`). */
|
|
276
311
|
export type DecisionVia = "web" | "im";
|
|
@@ -352,6 +387,10 @@ export declare class ApprovalsService {
|
|
|
352
387
|
private readonly sandbox;
|
|
353
388
|
/** A decision resumes its waiting run in the decision's transaction. */
|
|
354
389
|
private readonly resumes;
|
|
390
|
+
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
391
|
+
private readonly leakCheck;
|
|
392
|
+
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
393
|
+
private readonly sealed;
|
|
355
394
|
private readonly permissionLocks?;
|
|
356
395
|
private readonly permissionGrants?;
|
|
357
396
|
constructor(db: KernelDb, config: Pick<KernelConfigService, "get">, eventLog: Pick<EventLog, "appendIn" | "notify">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, schedules: Pick<ScheduledTaskStore, "addGrant">,
|
|
@@ -362,7 +401,11 @@ export declare class ApprovalsService {
|
|
|
362
401
|
/** A trial run's 「这次允许」 becomes a task grant only within the org's egress. */
|
|
363
402
|
sandbox: Pick<SandboxService, "ceilingLimits">,
|
|
364
403
|
/** A decision resumes its waiting run in the decision's transaction. */
|
|
365
|
-
resumes: Pick<RunResume, "resumeIn">,
|
|
404
|
+
resumes: Pick<RunResume, "resumeIn">,
|
|
405
|
+
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
406
|
+
leakCheck: Pick<ConversationLeakCheck, "leaked">,
|
|
407
|
+
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
408
|
+
sealed: Pick<SealedInputs, "sealIn">, permissionLocks?: PermissionAuthorityLock | undefined, permissionGrants?: PermissionCallGrants | undefined);
|
|
366
409
|
/**
|
|
367
410
|
* 新建 pending 审批(`expires_at` = 现在 + `tools.approvalTimeoutHours`)并写 `approval_requested`,同一事务。
|
|
368
411
|
* 按 (run_id, call_id, attempt) 幂等:已存在则返回已有记录(不覆盖),事件按 `approval_requested:<approvalId>` 幂等。
|
|
@@ -442,6 +485,12 @@ export declare class ApprovalsService {
|
|
|
442
485
|
/** An account's display name (null when unknown). */
|
|
443
486
|
private displayNameOf;
|
|
444
487
|
private decideIn;
|
|
488
|
+
/**
|
|
489
|
+
* A tool ask's decision in its own transaction. With person fields, a leak refusal commits the
|
|
490
|
+
* leaked paths in `detail.leakedFields` and returns them (the caller refuses after the commit,
|
|
491
|
+
* the approval still pending); the same transaction cannot both keep that write and throw.
|
|
492
|
+
*/
|
|
493
|
+
private decideToolIn;
|
|
445
494
|
/**
|
|
446
495
|
* A decision in the caller's transaction: lock order conversation → approval → run (the resume).
|
|
447
496
|
* Refuses (`approval.already_decided`, `approval.not_found`, …) before any write.
|