@capybara-hq/kernel 0.1.0-rc.63 → 0.1.0-rc.64
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/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.js +1 -1
- package/dist/channels/actions.d.ts +2 -5
- package/dist/channels/actions.js +20 -8
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +6 -4
- package/dist/channels/outbound.js +3 -2
- package/dist/config/schema.js +1 -1
- package/dist/conversations/approval-profile.d.ts +30 -0
- package/dist/conversations/approval-profile.js +62 -0
- package/dist/conversations/conversations.service.js +0 -2
- package/dist/conversations/events.d.ts +43 -0
- package/dist/conversations/events.js +52 -0
- package/dist/conversations/permission-profiles.controller.d.ts +3 -2
- package/dist/conversations/permission-profiles.service.d.ts +3 -2
- package/dist/conversations/permission-profiles.service.js +12 -8
- package/dist/db/kernel-schema.d.ts +4 -2
- package/dist/identity/initial-passwords.controller.d.ts +8 -6
- package/dist/identity/initial-passwords.controller.js +13 -7
- package/dist/identity/initial-passwords.d.ts +22 -13
- package/dist/identity/initial-passwords.js +25 -29
- package/dist/local-devices/relay.js +3 -1
- package/dist/models/images.js +5 -4
- package/dist/platform/connector-person-fields.js +2 -2
- package/dist/platform/exclusions.js +4 -4
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +9 -7
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/accounts.ops.d.ts +1 -1
- package/dist/platform/ops/accounts.ops.js +3 -3
- package/dist/platform/ops/channels.ops.d.ts +1 -1
- package/dist/platform/ops/channels.ops.js +2 -2
- package/dist/platform/ops/connectors.ops.d.ts +2 -2
- package/dist/platform/ops/connectors.ops.js +8 -8
- package/dist/platform/ops/extensions-admin.ops.d.ts +1 -1
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/extensions.ops.d.ts +1 -1
- package/dist/platform/ops/extensions.ops.js +4 -4
- package/dist/platform/ops/org-plugins.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.d.ts +1 -1
- package/dist/platform/ops/orgs.ops.js +3 -3
- package/dist/platform/ops/plugins.ops.d.ts +1 -1
- package/dist/platform/ops/plugins.ops.js +2 -2
- package/dist/platform/person-fields.d.ts +4 -3
- package/dist/platform/person-fields.js +6 -5
- package/dist/platform/sealed-inputs.d.ts +2 -2
- package/dist/platform/sealed-inputs.js +2 -2
- package/dist/platform/sealed-reveals.controller.d.ts +5 -8
- package/dist/platform/sealed-reveals.controller.js +8 -8
- package/dist/platform/sealed-reveals.d.ts +19 -17
- package/dist/platform/sealed-reveals.js +30 -33
- package/dist/runtime/context/build.js +3 -0
- package/dist/runtime/context/compaction.js +2 -0
- package/dist/runtime/waits.js +3 -2
- package/dist/sandbox/operation-authority.js +16 -15
- package/dist/sandbox/operation-intents.js +2 -2
- package/dist/sandbox/permission-availability.d.ts +49 -3
- package/dist/sandbox/permission-availability.js +61 -6
- package/dist/sandbox/permission-call-types.d.ts +3 -0
- package/dist/sandbox/permission-facts.d.ts +29 -1
- package/dist/sandbox/permission-facts.js +29 -6
- package/dist/sandbox/review/classifier.d.ts +72 -2
- package/dist/sandbox/review/classifier.js +113 -38
- package/dist/sandbox/review/index.d.ts +2 -2
- package/dist/sandbox/review/index.js +1 -1
- package/dist/sandbox/review/review.service.d.ts +1 -4
- package/dist/sandbox/review/review.service.js +4 -33
- package/dist/setup/setup-guides.service.js +1 -1
- package/dist/tools/approvals.service.d.ts +71 -16
- package/dist/tools/approvals.service.js +139 -13
- package/dist/tools/builtins/builtin-tools.d.ts +1 -1
- package/dist/tools/builtins/builtin-tools.js +12 -6
- package/dist/tools/builtins/platform.d.ts +15 -11
- package/dist/tools/builtins/platform.js +49 -39
- package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
- package/dist/tools/builtins/sandbox/bash.js +32 -14
- package/dist/tools/builtins/sandbox/common.d.ts +12 -3
- package/dist/tools/builtins/sandbox/common.js +29 -5
- package/dist/tools/connectors.schemas.d.ts +1 -1
- package/dist/tools/connectors.schemas.js +1 -1
- package/dist/tools/pipeline.d.ts +70 -10
- package/dist/tools/pipeline.js +356 -48
- package/dist/tools/policy.d.ts +4 -3
- package/dist/tools/policy.js +6 -6
- package/dist/tools/registry.d.ts +25 -9
- package/dist/tools/tool-review.d.ts +113 -0
- package/dist/tools/tool-review.js +303 -0
- package/dist/tools/tools.module.js +6 -0
- package/package.json +4 -4
- package/src/migrations/0175_secure_input_kind.sql +8 -0
|
@@ -174,9 +174,6 @@ export declare class CommandReviewService implements CommandReview {
|
|
|
174
174
|
* whoever runs it (hardening spec R1).
|
|
175
175
|
*/
|
|
176
176
|
private writtenInTree;
|
|
177
|
-
/**
|
|
178
|
-
* The bounded text of the root conversation's last person messages: the `user_message` text blocks
|
|
179
|
-
* only, never an assistant message or a tool result. `sandbox.review.messageTokens` caps it.
|
|
180
|
-
*/
|
|
177
|
+
/** The bounded text of the root conversation's last person messages ({@link readPersonMessages}). */
|
|
181
178
|
private personMessages;
|
|
182
179
|
}
|
|
@@ -16,7 +16,7 @@ import { KERNEL_LOGGER } from "../../infra/tokens.js";
|
|
|
16
16
|
import { ModelPurposesService } from "../../models/purposes.js";
|
|
17
17
|
import { StepLog } from "../../runtime/step-log.js";
|
|
18
18
|
import { generateImagePaths } from "../../tools/builtins/image/paths.js";
|
|
19
|
-
import {
|
|
19
|
+
import { newReviewTag, REVIEW_ASK_REASON, REVIEW_PURPOSE, readPersonMessages, runClassifier, } from "./classifier.js";
|
|
20
20
|
import { approverForCrossing, crossingOfCandidate, ESCALATION_RETRY_HINT, escalationAskReason, isCredentialConsentRule, } from "./permission-candidate.js";
|
|
21
21
|
export { escalationAskReason, quotedJustification } from "./permission-candidate.js";
|
|
22
22
|
import { reviewRules, reviewWrite, writtenPaths } from "./rules.js";
|
|
@@ -56,8 +56,6 @@ const REVIEWED_TOOLS = new Set(["Bash", "Write", "Edit", "GenerateImage"]);
|
|
|
56
56
|
const WRITE_TOOLS = new Set(["Write", "Edit", "GenerateImage"]);
|
|
57
57
|
/** How many of a conversation tree's latest assistant messages the review reads for its writes. */
|
|
58
58
|
const WRITTEN_EVENTS_READ = 200;
|
|
59
|
-
/** How many of the root conversation's latest person messages are read before bounding the text. */
|
|
60
|
-
const PERSON_MESSAGES_READ = 20;
|
|
61
59
|
const allow = (reason, rule) => ({
|
|
62
60
|
decision: "allow",
|
|
63
61
|
by: "rule",
|
|
@@ -524,21 +522,9 @@ let CommandReviewService = class CommandReviewService {
|
|
|
524
522
|
}
|
|
525
523
|
return [...written];
|
|
526
524
|
}
|
|
527
|
-
/**
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
*/
|
|
531
|
-
async personMessages(conversationId) {
|
|
532
|
-
const rows = await this.db
|
|
533
|
-
.selectFrom("conversation_events")
|
|
534
|
-
.select("payload")
|
|
535
|
-
.where("conversation_id", "=", conversationId)
|
|
536
|
-
.where("type", "=", "user_message")
|
|
537
|
-
.orderBy("seq", "desc")
|
|
538
|
-
.limit(PERSON_MESSAGES_READ)
|
|
539
|
-
.execute();
|
|
540
|
-
const texts = rows.map((r) => textOfUserMessage(r.payload)).filter((t) => t !== "");
|
|
541
|
-
return boundMessages(texts, this.config.get().sandbox.review.messageTokens);
|
|
525
|
+
/** The bounded text of the root conversation's last person messages ({@link readPersonMessages}). */
|
|
526
|
+
personMessages(conversationId) {
|
|
527
|
+
return readPersonMessages(this.db, conversationId, this.config.get().sandbox.review.messageTokens);
|
|
542
528
|
}
|
|
543
529
|
};
|
|
544
530
|
CommandReviewService = __decorate([
|
|
@@ -567,21 +553,6 @@ function toolCallsOf(payload) {
|
|
|
567
553
|
return [{ name: block.name, input: block.input, command: input.command }];
|
|
568
554
|
});
|
|
569
555
|
}
|
|
570
|
-
/** The text blocks of a `user_message` payload (its images, documents and attachments are skipped). */
|
|
571
|
-
function textOfUserMessage(payload) {
|
|
572
|
-
const content = payload?.content;
|
|
573
|
-
if (!Array.isArray(content))
|
|
574
|
-
return "";
|
|
575
|
-
return content
|
|
576
|
-
.flatMap((b) => {
|
|
577
|
-
if (b === null || typeof b !== "object")
|
|
578
|
-
return [];
|
|
579
|
-
const block = b;
|
|
580
|
-
return block.type === "text" && typeof block.text === "string" ? [block.text] : [];
|
|
581
|
-
})
|
|
582
|
-
.join("\n")
|
|
583
|
-
.trim();
|
|
584
|
-
}
|
|
585
556
|
/** The command of a validated `Bash` input, or null when it has none (the tool will refuse it). */
|
|
586
557
|
function commandOf(input) {
|
|
587
558
|
const command = input?.command;
|
|
@@ -279,7 +279,7 @@ let SetupGuidesService = class SetupGuidesService {
|
|
|
279
279
|
target: g.target,
|
|
280
280
|
hash: g.hash,
|
|
281
281
|
webPath,
|
|
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
|
|
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 in the Platform tool's secure input request 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.`,
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
};
|
|
@@ -27,9 +27,10 @@ export type ApprovalStatus = "pending" | "approved" | "denied" | "expired" | "ca
|
|
|
27
27
|
export type ApprovalScope = "once" | "session" | "always";
|
|
28
28
|
/**
|
|
29
29
|
* What an approval asks: a tool call, the device owner about refused network hosts, the actor about
|
|
30
|
-
* a git push the gateway held,
|
|
30
|
+
* a git push the gateway held, a person about a command the review held (auto mode spec §5.4), or
|
|
31
|
+
* the person for a call's secret fields (`secure_input`; profiles govern every approval, R4).
|
|
31
32
|
*/
|
|
32
|
-
export type ApprovalKind = "tool" | "network" | "git" | "command";
|
|
33
|
+
export type ApprovalKind = "tool" | "network" | "git" | "command" | "secure_input";
|
|
33
34
|
/**
|
|
34
35
|
* The formatted `tool_result` of a command an ask kept (≤ 16 KB; larger output already archived),
|
|
35
36
|
* and the display-only fields the pipeline writes with it when the ask settles.
|
|
@@ -156,8 +157,9 @@ export interface ApprovalRecord {
|
|
|
156
157
|
/** A command review ask's facts; null for any other kind. */
|
|
157
158
|
command: CommandAskDetail | null;
|
|
158
159
|
/**
|
|
159
|
-
* A
|
|
160
|
-
*
|
|
160
|
+
* A secure input request (kind `secure_input`; platform web parity spec §4.2, profiles govern
|
|
161
|
+
* every approval R4): the secret fields the person enters, as specs (path, label, schema node),
|
|
162
|
+
* never values. Absent otherwise.
|
|
161
163
|
*/
|
|
162
164
|
personFields?: PersonFieldSpec[];
|
|
163
165
|
/** The card's target name with {@link personFields} ("Anthropic: deployment config"). */
|
|
@@ -175,6 +177,11 @@ export interface ApprovalRecord {
|
|
|
175
177
|
* then ends without running tells the agent to have them rotated.
|
|
176
178
|
*/
|
|
177
179
|
leakedFields?: string[];
|
|
180
|
+
/**
|
|
181
|
+
* A tool ask the review model could not decide under Approve for me (profiles govern every
|
|
182
|
+
* approval, R3): the card says it is the person's call. Absent otherwise.
|
|
183
|
+
*/
|
|
184
|
+
reviewUnsure?: true;
|
|
178
185
|
toolKey: string;
|
|
179
186
|
specHash: string;
|
|
180
187
|
connectorId: string | null;
|
|
@@ -226,7 +233,10 @@ export interface CommandAskInput {
|
|
|
226
233
|
/** The call's attempt (default: after its other approvals, as a network ask takes it). */
|
|
227
234
|
attempt?: number;
|
|
228
235
|
}
|
|
229
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* The record without an ask's kept command result (what routes and cards may show). A secure
|
|
238
|
+
* input request shows its fields and target, never the call's input it binds.
|
|
239
|
+
*/
|
|
230
240
|
export declare function publicRecord(r: ApprovalRecord): ApprovalPublicRecord;
|
|
231
241
|
/** 审批详情(列表与详情接口返回)。 */
|
|
232
242
|
export interface ApprovalView extends ApprovalPublicRecord {
|
|
@@ -285,14 +295,47 @@ export interface ApprovalRequestInput {
|
|
|
285
295
|
};
|
|
286
296
|
/** The scopes the decider may choose; unset: derived (see {@link ApprovalRecord.scopes}). */
|
|
287
297
|
scopes?: ApprovalScope[];
|
|
288
|
-
/**
|
|
289
|
-
|
|
290
|
-
* (stored in `detail`).
|
|
291
|
-
*/
|
|
292
|
-
detail?: Omit<ToolAskDetail, "personFields" | "target"> & Partial<Pick<ToolAskDetail, "personFields" | "target">>;
|
|
298
|
+
/** The file a tool ask's call takes and the review's unsure mark (stored in `detail`). */
|
|
299
|
+
detail?: ToolAskDetail;
|
|
293
300
|
}
|
|
294
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* A secure input request (profiles govern every approval, R4), made by the tool pipeline once the
|
|
303
|
+
* call's own consent is settled: the person enters the call's secret fields on the web.
|
|
304
|
+
*/
|
|
305
|
+
export interface SecureInputRequestInput {
|
|
306
|
+
/** The call's attempt (after its other approvals). */
|
|
307
|
+
attempt: number;
|
|
308
|
+
orgId: string;
|
|
309
|
+
conversationId: string;
|
|
310
|
+
runId: string;
|
|
311
|
+
/** The call's step (written to `approval_requested`). */
|
|
312
|
+
step: number;
|
|
313
|
+
callId: string;
|
|
314
|
+
/** The call's policy key. */
|
|
315
|
+
toolKey: string;
|
|
316
|
+
specHash: string;
|
|
317
|
+
connectorId: string | null;
|
|
318
|
+
/** The raw call input, stored for binding only (never shown). */
|
|
319
|
+
input: unknown;
|
|
320
|
+
/** The run's person: the only one who may submit or cancel. */
|
|
321
|
+
requestedFor: string;
|
|
322
|
+
/** What the values are for ("Anthropic: deployment config"). */
|
|
323
|
+
target: {
|
|
324
|
+
zh: string;
|
|
325
|
+
en: string;
|
|
326
|
+
};
|
|
327
|
+
/** The secret fields to enter (1 to {@link SECURE_INPUT_MAX_FIELDS}), specs only. */
|
|
328
|
+
personFields: PersonFieldSpec[];
|
|
329
|
+
}
|
|
330
|
+
/** A tool ask's `detail`: the file its call takes and whether the review was unsure. */
|
|
295
331
|
export interface ToolAskDetail {
|
|
332
|
+
/** The file the call takes in place of an upload (its sha256 is what the approval binds). */
|
|
333
|
+
file?: FileCardDetail;
|
|
334
|
+
/** The review model could not decide the ask under Approve for me (R3). */
|
|
335
|
+
reviewUnsure?: true;
|
|
336
|
+
}
|
|
337
|
+
/** A secure input request's `detail`: the fields the person enters and their target. */
|
|
338
|
+
export interface SecureInputDetail {
|
|
296
339
|
personFields: PersonFieldSpec[];
|
|
297
340
|
target: {
|
|
298
341
|
zh: string;
|
|
@@ -300,8 +343,6 @@ export interface ToolAskDetail {
|
|
|
300
343
|
};
|
|
301
344
|
/** The paths whose entered value the decision refused as leaked (written by the decision). */
|
|
302
345
|
leakedFields?: string[];
|
|
303
|
-
/** The file the call takes in place of an upload (its sha256 is what the approval binds). */
|
|
304
|
-
file?: FileCardDetail;
|
|
305
346
|
}
|
|
306
347
|
export interface DecisionInput {
|
|
307
348
|
decision: "approve" | "deny";
|
|
@@ -426,6 +467,17 @@ export declare class ApprovalsService {
|
|
|
426
467
|
*/
|
|
427
468
|
request(input: ApprovalRequestInput): Promise<ApprovalRecord>;
|
|
428
469
|
private requestIn;
|
|
470
|
+
/**
|
|
471
|
+
* A secure input request (profiles govern every approval, R4): a pending approval of kind
|
|
472
|
+
* `secure_input` asking `requestedFor` for the call's secret fields, expiring like a tool
|
|
473
|
+
* approval, and its `approval_requested` (the display-only `secureInput`: the target and the
|
|
474
|
+
* field paths), in one transaction. It carries no consent: scopes `["once"]`, and Submit is a
|
|
475
|
+
* decision `approve` with the values, Cancel a `deny`. The raw call input is stored for binding
|
|
476
|
+
* only and shown nowhere. Idempotent per (run, call, attempt); an attempt already held by
|
|
477
|
+
* another kind is refused.
|
|
478
|
+
*/
|
|
479
|
+
requestSecureInput(input: SecureInputRequestInput): Promise<ApprovalRecord>;
|
|
480
|
+
private requestSecureInputIn;
|
|
429
481
|
/**
|
|
430
482
|
* A network ask (network ask-to-allow spec §6.2): a pending approval of kind `network` for the
|
|
431
483
|
* device owner, expiring like a tool approval (`tools.approvalTimeoutHours`), and its
|
|
@@ -500,9 +552,10 @@ export declare class ApprovalsService {
|
|
|
500
552
|
private displayNameOf;
|
|
501
553
|
private decideIn;
|
|
502
554
|
/**
|
|
503
|
-
* A tool ask's decision in its own transaction.
|
|
504
|
-
* leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
505
|
-
* the
|
|
555
|
+
* A tool ask's or a secure input's decision in its own transaction. For a secure input, a leak
|
|
556
|
+
* refusal commits the leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
557
|
+
* after the commit, the request still pending); the same transaction cannot both keep that write
|
|
558
|
+
* and throw.
|
|
506
559
|
*/
|
|
507
560
|
private decideToolIn;
|
|
508
561
|
/**
|
|
@@ -549,6 +602,8 @@ export declare class ApprovalsService {
|
|
|
549
602
|
describe(id: string): Promise<ApprovalView | null>;
|
|
550
603
|
/** 某个工具调用最近一次的工具审批(attempt 最大者,网络询问除外);没有则返回 null。 */
|
|
551
604
|
forCall(runId: string, callId: string): Promise<ApprovalRecord | null>;
|
|
605
|
+
/** The latest secure input request of a tool call (highest attempt); null when it has none. */
|
|
606
|
+
secureInputForCall(runId: string, callId: string): Promise<ApprovalRecord | null>;
|
|
552
607
|
/** The network ask of a tool call (at most one per call); null when it has none. */
|
|
553
608
|
networkForCall(runId: string, callId: string): Promise<ApprovalRecord | null>;
|
|
554
609
|
/** The git push ask of a tool call (at most one per call); null when it has none. */
|
|
@@ -13,7 +13,7 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
15
15
|
import { EventLog } from "../conversations/event-log.js";
|
|
16
|
-
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, } from "../conversations/events.js";
|
|
16
|
+
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
17
17
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
18
18
|
import { conversationSourceOf } from "../conversations/source.js";
|
|
19
19
|
import { ApiError } from "../errors.js";
|
|
@@ -54,7 +54,10 @@ export const APPROVALS_LIST_MAX = 100;
|
|
|
54
54
|
export const NETWORK_ASK_CANCELLED_NOTE = "[network] The run was stopped before the user answered; access stays blocked.";
|
|
55
55
|
/** The model-visible note after a git ask's kept result when its run is stopped before the answer. */
|
|
56
56
|
export const GIT_ASK_CANCELLED_NOTE = "[git] The run was stopped before the user answered; the push was not made.";
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The record without an ask's kept command result (what routes and cards may show). A secure
|
|
59
|
+
* input request shows its fields and target, never the call's input it binds.
|
|
60
|
+
*/
|
|
58
61
|
export function publicRecord(r) {
|
|
59
62
|
const strip = (d) => {
|
|
60
63
|
if (d === null)
|
|
@@ -71,8 +74,17 @@ export function publicRecord(r) {
|
|
|
71
74
|
: r.scopes,
|
|
72
75
|
detail: strip(r.detail),
|
|
73
76
|
git: strip(r.git),
|
|
77
|
+
...(r.kind === "secure_input" && { input: null }),
|
|
74
78
|
};
|
|
75
79
|
}
|
|
80
|
+
/** Whether a tool ask's stored `detail` says the review model could not decide it. */
|
|
81
|
+
function reviewUnsureOf(detail) {
|
|
82
|
+
return typeof detail === "object" &&
|
|
83
|
+
detail !== null &&
|
|
84
|
+
detail.reviewUnsure === true
|
|
85
|
+
? { reviewUnsure: true }
|
|
86
|
+
: null;
|
|
87
|
+
}
|
|
76
88
|
/** A tool ask's file from its stored `detail` (none: the call takes no file). */
|
|
77
89
|
function fileOf(detail) {
|
|
78
90
|
if (typeof detail !== "object" || detail === null)
|
|
@@ -82,7 +94,7 @@ function fileOf(detail) {
|
|
|
82
94
|
return null;
|
|
83
95
|
return { file: f };
|
|
84
96
|
}
|
|
85
|
-
/**
|
|
97
|
+
/** The person fields of a secure input request from its stored `detail`. */
|
|
86
98
|
function personFieldsOf(detail) {
|
|
87
99
|
if (typeof detail !== "object" || detail === null)
|
|
88
100
|
return null;
|
|
@@ -140,8 +152,9 @@ function toRecord(r) {
|
|
|
140
152
|
detail: r.kind === "network" ? (r.detail ?? null) : null,
|
|
141
153
|
git: r.kind === "git" ? (r.detail ?? null) : null,
|
|
142
154
|
command: r.kind === "command" ? (r.detail ?? null) : null,
|
|
143
|
-
...(r.kind === "
|
|
155
|
+
...(r.kind === "secure_input" && personFieldsOf(r.detail)),
|
|
144
156
|
...(r.kind === "tool" && fileOf(r.detail)),
|
|
157
|
+
...(r.kind === "tool" && reviewUnsureOf(r.detail)),
|
|
145
158
|
toolKey: r.tool_key,
|
|
146
159
|
specHash: r.spec_hash,
|
|
147
160
|
connectorId: r.connector_id,
|
|
@@ -166,8 +179,11 @@ function toRecord(r) {
|
|
|
166
179
|
* - 指定了 `requested_for` → 只有那个人;
|
|
167
180
|
* - 按角色升级(`approver_role`)→ 当前角色不低于它、且不是该运行发起人的成员(发起人不能批准按角色升级到别人的请求)。
|
|
168
181
|
* agent / 服务令牌不能处理任何审批(路由动作 `approvals.decide` 仅限用户主体)。
|
|
182
|
+
* A secure input request is only ever its `requested_for` person's, never a role's.
|
|
169
183
|
*/
|
|
170
184
|
function canHandle(a, initiator, accountId, role) {
|
|
185
|
+
if (a.kind === "secure_input")
|
|
186
|
+
return a.requestedFor !== null && a.requestedFor === accountId;
|
|
171
187
|
if (a.requestedFor !== null)
|
|
172
188
|
return a.requestedFor === accountId;
|
|
173
189
|
return (a.approverRole !== null &&
|
|
@@ -304,6 +320,96 @@ let ApprovalsService = class ApprovalsService {
|
|
|
304
320
|
]);
|
|
305
321
|
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
306
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* A secure input request (profiles govern every approval, R4): a pending approval of kind
|
|
325
|
+
* `secure_input` asking `requestedFor` for the call's secret fields, expiring like a tool
|
|
326
|
+
* approval, and its `approval_requested` (the display-only `secureInput`: the target and the
|
|
327
|
+
* field paths), in one transaction. It carries no consent: scopes `["once"]`, and Submit is a
|
|
328
|
+
* decision `approve` with the values, Cancel a `deny`. The raw call input is stored for binding
|
|
329
|
+
* only and shown nowhere. Idempotent per (run, call, attempt); an attempt already held by
|
|
330
|
+
* another kind is refused.
|
|
331
|
+
*/
|
|
332
|
+
async requestSecureInput(input) {
|
|
333
|
+
const n = input.personFields.length;
|
|
334
|
+
if (n === 0 || n > SECURE_INPUT_MAX_FIELDS) {
|
|
335
|
+
throw new Error(`a secure input asks for 1 to ${SECURE_INPUT_MAX_FIELDS} fields`);
|
|
336
|
+
}
|
|
337
|
+
if (input.requestedFor.length === 0)
|
|
338
|
+
throw new Error("a secure input names its person");
|
|
339
|
+
const { record, toSeq } = await this.requestSecureInputIn(input);
|
|
340
|
+
if (toSeq !== null)
|
|
341
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
342
|
+
return record;
|
|
343
|
+
}
|
|
344
|
+
async requestSecureInputIn(input) {
|
|
345
|
+
const hours = this.config.get().tools.approvalTimeoutHours;
|
|
346
|
+
const t = this.db.db;
|
|
347
|
+
// the conversation row first (the append's lock), as `requestIn`
|
|
348
|
+
await t
|
|
349
|
+
.selectFrom("conversations")
|
|
350
|
+
.select("id")
|
|
351
|
+
.where("id", "=", input.conversationId)
|
|
352
|
+
.forUpdate()
|
|
353
|
+
.execute();
|
|
354
|
+
const detail = { personFields: input.personFields, target: input.target };
|
|
355
|
+
const inserted = await t
|
|
356
|
+
.insertInto("approvals")
|
|
357
|
+
.values({
|
|
358
|
+
id: randomUUID(),
|
|
359
|
+
org_id: input.orgId,
|
|
360
|
+
conversation_id: input.conversationId,
|
|
361
|
+
run_id: input.runId,
|
|
362
|
+
call_id: input.callId,
|
|
363
|
+
attempt: input.attempt,
|
|
364
|
+
kind: "secure_input",
|
|
365
|
+
detail: JSON.stringify(detail),
|
|
366
|
+
tool_key: input.toolKey,
|
|
367
|
+
spec_hash: input.specHash,
|
|
368
|
+
connector_id: input.connectorId,
|
|
369
|
+
input: JSON.stringify(input.input ?? {}),
|
|
370
|
+
requested_for: input.requestedFor,
|
|
371
|
+
approver_role: null,
|
|
372
|
+
scopes: ["once"],
|
|
373
|
+
scope: null,
|
|
374
|
+
decided_by: null,
|
|
375
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
376
|
+
})
|
|
377
|
+
.onConflict((oc) => oc.columns(["run_id", "call_id", "attempt"]).doNothing())
|
|
378
|
+
.returningAll()
|
|
379
|
+
.executeTakeFirst();
|
|
380
|
+
if (inserted === undefined) {
|
|
381
|
+
const row = await t
|
|
382
|
+
.selectFrom("approvals")
|
|
383
|
+
.selectAll()
|
|
384
|
+
.where("run_id", "=", input.runId)
|
|
385
|
+
.where("call_id", "=", input.callId)
|
|
386
|
+
.where("attempt", "=", input.attempt)
|
|
387
|
+
.executeTakeFirstOrThrow();
|
|
388
|
+
if (row.kind !== "secure_input") {
|
|
389
|
+
throw new Error(`attempt ${input.attempt} of call ${input.callId} is an approval of kind ${row.kind}`);
|
|
390
|
+
}
|
|
391
|
+
return { record: toRecord(row), toSeq: null };
|
|
392
|
+
}
|
|
393
|
+
const rec = toRecord(inserted);
|
|
394
|
+
const written = await this.eventLog.appendIn(rec.conversationId, [
|
|
395
|
+
{
|
|
396
|
+
type: "approval_requested",
|
|
397
|
+
runId: rec.runId,
|
|
398
|
+
idemKey: `approval_requested:${rec.id}`,
|
|
399
|
+
payload: {
|
|
400
|
+
step: input.step,
|
|
401
|
+
callId: rec.callId,
|
|
402
|
+
approvalId: rec.id,
|
|
403
|
+
toolKey: rec.toolKey,
|
|
404
|
+
expiresAt: rec.expiresAt,
|
|
405
|
+
secureInput: { target: input.target, fields: input.personFields.map((f) => f.path) },
|
|
406
|
+
requestedFor: rec.requestedFor,
|
|
407
|
+
approverRole: null,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
]);
|
|
411
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
412
|
+
}
|
|
307
413
|
/**
|
|
308
414
|
* A network ask (network ask-to-allow spec §6.2): a pending approval of kind `network` for the
|
|
309
415
|
* device owner, expiring like a tool approval (`tools.approvalTimeoutHours`), and its
|
|
@@ -964,16 +1070,18 @@ let ApprovalsService = class ApprovalsService {
|
|
|
964
1070
|
// decision committed, even when a caller has a transaction open
|
|
965
1071
|
decideIn(orgId, id, accountId, body, actorTokenId, network, git, command) {
|
|
966
1072
|
return this.decideTx(orgId, id, accountId, body, actorTokenId, network, git, command).then((o) => {
|
|
967
|
-
// only a
|
|
968
|
-
if ("leaked" in o)
|
|
969
|
-
throw new Error(`approval ${id}: a leak outcome outside a
|
|
1073
|
+
// only a secure input takes inputs (refused for every other kind before)
|
|
1074
|
+
if ("leaked" in o) {
|
|
1075
|
+
throw new Error(`approval ${id}: a leak outcome outside a secure input request`);
|
|
1076
|
+
}
|
|
970
1077
|
return o;
|
|
971
1078
|
});
|
|
972
1079
|
}
|
|
973
1080
|
/**
|
|
974
|
-
* A tool ask's decision in its own transaction.
|
|
975
|
-
* leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
976
|
-
* the
|
|
1081
|
+
* A tool ask's or a secure input's decision in its own transaction. For a secure input, a leak
|
|
1082
|
+
* refusal commits the leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
1083
|
+
* after the commit, the request still pending); the same transaction cannot both keep that write
|
|
1084
|
+
* and throw.
|
|
977
1085
|
*/
|
|
978
1086
|
decideToolIn(orgId, id, accountId, body, actorTokenId, via) {
|
|
979
1087
|
return this.decideTx(orgId, id, accountId, body, actorTokenId, undefined, undefined, undefined, via);
|
|
@@ -1030,12 +1138,13 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1030
1138
|
await this.permissionGrants.assertCurrent(before.command.permissionCandidate.binding);
|
|
1031
1139
|
}
|
|
1032
1140
|
const approved = body.decision === "approve";
|
|
1033
|
-
|
|
1141
|
+
// only a secure input request takes values
|
|
1142
|
+
const person = before.kind === "secure_input" ? before.personFields : undefined;
|
|
1034
1143
|
if (body.inputs !== undefined && (person === undefined || !approved)) {
|
|
1035
1144
|
throw inputsNotExpected();
|
|
1036
1145
|
}
|
|
1037
|
-
//
|
|
1038
|
-
// its person, in a web session, with every asked value, valid and never seen in the
|
|
1146
|
+
// a secure input (platform web parity spec §4.2, §4.3, R5; profiles govern every approval R4):
|
|
1147
|
+
// submitted only by its person, in a web session, with every asked value, valid and never seen in the
|
|
1039
1148
|
// conversation; the values are sealed before the status changes. A deny takes no values.
|
|
1040
1149
|
let inputsProvided;
|
|
1041
1150
|
if (person !== undefined && approved) {
|
|
@@ -1288,6 +1397,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1288
1397
|
action: "approval.decided",
|
|
1289
1398
|
target: id,
|
|
1290
1399
|
detail: {
|
|
1400
|
+
...(before.kind === "secure_input" && { kind: "secure_input" }),
|
|
1291
1401
|
...(git !== undefined &&
|
|
1292
1402
|
before.git !== null && {
|
|
1293
1403
|
kind: "git",
|
|
@@ -1491,6 +1601,19 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1491
1601
|
.executeTakeFirst();
|
|
1492
1602
|
return row ? toRecord(row) : null;
|
|
1493
1603
|
}
|
|
1604
|
+
/** The latest secure input request of a tool call (highest attempt); null when it has none. */
|
|
1605
|
+
async secureInputForCall(runId, callId) {
|
|
1606
|
+
const row = await this.db
|
|
1607
|
+
.selectFrom("approvals")
|
|
1608
|
+
.selectAll()
|
|
1609
|
+
.where("run_id", "=", runId)
|
|
1610
|
+
.where("call_id", "=", callId)
|
|
1611
|
+
.where("kind", "=", "secure_input")
|
|
1612
|
+
.orderBy("attempt", "desc")
|
|
1613
|
+
.limit(1)
|
|
1614
|
+
.executeTakeFirst();
|
|
1615
|
+
return row ? toRecord(row) : null;
|
|
1616
|
+
}
|
|
1494
1617
|
/** The network ask of a tool call (at most one per call); null when it has none. */
|
|
1495
1618
|
async networkForCall(runId, callId) {
|
|
1496
1619
|
const row = await this.db
|
|
@@ -1923,6 +2046,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1923
2046
|
__decorate([
|
|
1924
2047
|
Transactional()
|
|
1925
2048
|
], ApprovalsService.prototype, "requestIn", null);
|
|
2049
|
+
__decorate([
|
|
2050
|
+
Transactional()
|
|
2051
|
+
], ApprovalsService.prototype, "requestSecureInputIn", null);
|
|
1926
2052
|
__decorate([
|
|
1927
2053
|
Transactional()
|
|
1928
2054
|
], ApprovalsService.prototype, "requestNetworkIn", null);
|
|
@@ -40,7 +40,7 @@ export declare class BuiltinTools {
|
|
|
40
40
|
purposes: ModelPurposesService, host: {
|
|
41
41
|
readonly hooks?: HookRunner;
|
|
42
42
|
} | undefined, stepLog: StepLog, log: Logger, background: BackgroundTaskStore, finisher: BackgroundTaskFinisher, stopper: BackgroundTaskStopper, platformOps: PlatformOperations, platformActor: PlatformActor, agentDocs: AgentDocs,
|
|
43
|
-
/** The person's sealed
|
|
43
|
+
/** The person's sealed secure input values a Platform write with person fields reads. */
|
|
44
44
|
sealedInputs: SealedInputs,
|
|
45
45
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
46
46
|
fileRefs: FileRefs,
|
|
@@ -63,7 +63,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
63
63
|
constructor(db, config, outputs, storage, attachments, eventLog, sandbox, devices, points, webPages,
|
|
64
64
|
/** The WebFetch extraction call: the `web_fetch` purpose, its hooks, usage and denials. */
|
|
65
65
|
purposes, host, stepLog, log, background, finisher, stopper, platformOps, platformActor, agentDocs,
|
|
66
|
-
/** The person's sealed
|
|
66
|
+
/** The person's sealed secure input values a Platform write with person fields reads. */
|
|
67
67
|
sealedInputs,
|
|
68
68
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
69
69
|
fileRefs,
|
|
@@ -172,30 +172,36 @@ let BuiltinTools = class BuiltinTools {
|
|
|
172
172
|
setting: async (orgId) => (await readOrgSettings(db.db, orgId)).platformTool,
|
|
173
173
|
log,
|
|
174
174
|
sealed: sealedInputs,
|
|
175
|
-
|
|
176
|
-
// only this call's own
|
|
175
|
+
secureInputPaths: async (secureInputId, call) => {
|
|
176
|
+
// only this call's own submitted secure input in this org (anything else: none, fails
|
|
177
|
+
// closed)
|
|
177
178
|
const row = await db.db
|
|
178
179
|
.selectFrom("approvals")
|
|
179
180
|
.select(["kind", "detail"])
|
|
180
|
-
.where("id", "=",
|
|
181
|
+
.where("id", "=", secureInputId)
|
|
181
182
|
.where("org_id", "=", call.orgId)
|
|
182
183
|
.where("run_id", "=", call.runId)
|
|
183
184
|
.where("call_id", "=", call.callId)
|
|
185
|
+
.where("kind", "=", "secure_input")
|
|
184
186
|
.where("status", "=", "approved")
|
|
185
187
|
.executeTakeFirst();
|
|
186
188
|
const fields = row?.detail
|
|
187
189
|
?.personFields;
|
|
188
|
-
if (row?.kind !== "
|
|
190
|
+
if (row?.kind !== "secure_input" || !Array.isArray(fields) || fields.length === 0) {
|
|
189
191
|
return null;
|
|
192
|
+
}
|
|
190
193
|
return fields.map((f) => String(f.path));
|
|
191
194
|
},
|
|
192
195
|
files: fileRefs,
|
|
196
|
+
// a call no approval governs binds its file to the automatic decision instead (R7)
|
|
193
197
|
approvalFileSha256: async (approvalId, call) => {
|
|
194
|
-
// only this call's own approved approval in this org (anything else: none, fails
|
|
198
|
+
// only this call's own approved tool approval in this org (anything else: none, fails
|
|
199
|
+
// closed)
|
|
195
200
|
const row = await db.db
|
|
196
201
|
.selectFrom("approvals")
|
|
197
202
|
.select(["kind", "detail"])
|
|
198
203
|
.where("id", "=", approvalId)
|
|
204
|
+
.where("kind", "=", "tool")
|
|
199
205
|
.where("org_id", "=", call.orgId)
|
|
200
206
|
.where("run_id", "=", call.runId)
|
|
201
207
|
.where("call_id", "=", call.callId)
|
|
@@ -21,14 +21,18 @@ import type { BuiltinTool, CallPolicyContext } from "../registry.js";
|
|
|
21
21
|
* - An `ApiError` gets the next step the operation declares for its code and the actor's role.
|
|
22
22
|
* - The actor, the agent and the conversation come from the runtime context, never from input.
|
|
23
23
|
* - A write with person fields (platform web parity spec §4: `op.personFields`) is planned at the
|
|
24
|
-
* policy step: a secret in `values` is denied before
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* policy step: a secret in `values` is denied before any card, and the asked fields go to the
|
|
25
|
+
* pipeline through {@link CallPolicy.personFields}, which asks for them in a secure input request
|
|
26
|
+
* after the consent (profiles govern every approval, R4). The call reads the person's sealed
|
|
27
|
+
* values by that request (`BuiltinCallContext.secureInputId`) through `personInputs`, and its
|
|
28
|
+
* result names the request and each entered path, never a value.
|
|
28
29
|
* - A write that takes a file in place of an upload (spec §5: `op.fileRef`) resolves it at the
|
|
29
30
|
* policy step: a file over the limit or of another type is denied before the card; the card
|
|
30
|
-
* shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256
|
|
31
|
-
* `op.run` the file is read again, and
|
|
31
|
+
* shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256, or, with no
|
|
32
|
+
* approval, the automatic decision does (R7). Right before `op.run` the file is read again, and
|
|
33
|
+
* bytes with another sha256 are refused.
|
|
34
|
+
* - A write whose result is shown once to the run's person (`op.revealsOnce`) carries the
|
|
35
|
+
* reveal view, which the web reads by the call (R6).
|
|
32
36
|
* - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
|
|
33
37
|
*/
|
|
34
38
|
/** The most entries of a list in one result (operations that page return `next`). */
|
|
@@ -49,14 +53,14 @@ export interface PlatformToolDeps {
|
|
|
49
53
|
precheckTimeoutMs?: number;
|
|
50
54
|
/** A precheck that throws is logged (warn) and one that times out (debug), with the op id. */
|
|
51
55
|
log?: Pick<KernelLogger, "warn"> & Partial<Pick<KernelLogger, "debug">>;
|
|
52
|
-
/** The person's sealed
|
|
56
|
+
/** The person's sealed values (`personInputs`); absent: no write has person fields. */
|
|
53
57
|
sealed?: Pick<SealedInputs, "consume">;
|
|
54
58
|
/**
|
|
55
|
-
* The person field paths
|
|
56
|
-
* when it
|
|
57
|
-
*
|
|
59
|
+
* The person field paths a secure input request asked for (its stored `detail.personFields`), or
|
|
60
|
+
* null when it is not this call's submitted secure input in the org: what the call's values are
|
|
61
|
+
* bound to.
|
|
58
62
|
*/
|
|
59
|
-
|
|
63
|
+
secureInputPaths?(secureInputId: string, call: {
|
|
60
64
|
orgId: string;
|
|
61
65
|
runId: string;
|
|
62
66
|
callId: string;
|