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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/admin/extensions.controller.d.ts +2 -10
  2. package/dist/admin/extensions.controller.js +2 -24
  3. package/dist/admin/extensions.schemas.d.ts +21 -0
  4. package/dist/admin/extensions.schemas.js +37 -0
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/catalog/org-extension-switch.d.ts +3 -1
  7. package/dist/catalog/org-extension-switch.js +12 -5
  8. package/dist/catalog/org-extension.controller.d.ts +2 -21
  9. package/dist/catalog/org-extension.controller.js +1 -38
  10. package/dist/catalog/org-extension.schemas.d.ts +31 -0
  11. package/dist/catalog/org-extension.schemas.js +65 -0
  12. package/dist/channels/actions.js +2 -0
  13. package/dist/channels/cards.d.ts +8 -0
  14. package/dist/channels/cards.js +18 -0
  15. package/dist/channels/outbound.js +8 -1
  16. package/dist/channels/phrases.d.ts +10 -0
  17. package/dist/channels/phrases.js +10 -0
  18. package/dist/conversations/conversations.module.js +4 -0
  19. package/dist/conversations/events.d.ts +1 -0
  20. package/dist/conversations/events.js +5 -0
  21. package/dist/conversations/leak-check.d.ts +26 -0
  22. package/dist/conversations/leak-check.js +69 -0
  23. package/dist/ctx/secrets.d.ts +5 -0
  24. package/dist/ctx/secrets.js +5 -0
  25. package/dist/db/kernel-schema.d.ts +15 -0
  26. package/dist/errors.d.ts +9 -0
  27. package/dist/errors.js +9 -0
  28. package/dist/extensions/deployment-config.d.ts +6 -2
  29. package/dist/extensions/deployment-config.js +35 -23
  30. package/dist/extensions/org-config.d.ts +2 -0
  31. package/dist/extensions/org-config.js +1 -0
  32. package/dist/extensions/org-overrides.d.ts +2 -0
  33. package/dist/extensions/org-overrides.js +3 -2
  34. package/dist/identity/initial-passwords.job.d.ts +3 -2
  35. package/dist/identity/initial-passwords.job.js +9 -5
  36. package/dist/platform/exclusions.js +1 -41
  37. package/dist/platform/method.js +1 -0
  38. package/dist/platform/operation.d.ts +30 -2
  39. package/dist/platform/operation.js +1 -1
  40. package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
  41. package/dist/platform/ops/extensions-admin.ops.js +153 -5
  42. package/dist/platform/ops/extensions.ops.d.ts +19 -5
  43. package/dist/platform/ops/extensions.ops.js +285 -10
  44. package/dist/platform/ops/person-inputs.d.ts +35 -0
  45. package/dist/platform/ops/person-inputs.js +79 -0
  46. package/dist/platform/ops/plugins.ops.d.ts +2 -0
  47. package/dist/platform/ops/plugins.ops.js +30 -17
  48. package/dist/platform/parity.d.ts +6 -2
  49. package/dist/platform/parity.js +38 -1
  50. package/dist/platform/person-fields.d.ts +103 -0
  51. package/dist/platform/person-fields.js +381 -0
  52. package/dist/platform/platform.module.d.ts +3 -3
  53. package/dist/platform/platform.module.js +6 -5
  54. package/dist/platform/sealed-inputs.d.ts +44 -0
  55. package/dist/platform/sealed-inputs.js +116 -0
  56. package/dist/runtime/waits.js +8 -2
  57. package/dist/tools/approvals.controller.d.ts +1 -0
  58. package/dist/tools/approvals.controller.js +19 -0
  59. package/dist/tools/approvals.service.d.ts +50 -1
  60. package/dist/tools/approvals.service.js +118 -10
  61. package/dist/tools/builtins/builtin-tools.d.ts +3 -0
  62. package/dist/tools/builtins/builtin-tools.js +31 -9
  63. package/dist/tools/builtins/platform.d.ts +20 -0
  64. package/dist/tools/builtins/platform.js +174 -15
  65. package/dist/tools/pipeline.d.ts +24 -2
  66. package/dist/tools/pipeline.js +80 -17
  67. package/dist/tools/policy.d.ts +3 -0
  68. package/dist/tools/policy.js +6 -0
  69. package/dist/tools/registry.d.ts +22 -0
  70. package/dist/tools/tools.module.js +3 -0
  71. package/package.json +4 -4
  72. package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
@@ -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">, permissionLocks?: PermissionAuthorityLock | undefined, permissionGrants?: PermissionCallGrants | undefined);
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.
@@ -14,6 +14,7 @@ import { sql } from "kysely";
14
14
  import { normalizeStoredDefinition } from "../agents/definition.js";
15
15
  import { EventLog } from "../conversations/event-log.js";
16
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";
17
+ import { ConversationLeakCheck } from "../conversations/leak-check.js";
17
18
  import { conversationSourceOf } from "../conversations/source.js";
18
19
  import { ApiError } from "../errors.js";
19
20
  import { clipText } from "../extensions/hooks.js";
@@ -27,6 +28,8 @@ import { KernelEvents } from "../infra/events/kernel-events.js";
27
28
  import { LockService } from "../infra/lock/lock.service.js";
28
29
  import { WithLock } from "../infra/lock/with-lock.decorator.js";
29
30
  import { ORG_ROLES, roleAtLeast } from "../orgs/roles.js";
31
+ import { checkPersonValue } from "../platform/person-fields.js";
32
+ import { SealedInputs } from "../platform/sealed-inputs.js";
30
33
  import { RunResume } from "../runtime/run-jobs.js";
31
34
  import { rootConversationOf } from "../runtime/subagents/child.js";
32
35
  import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
@@ -69,6 +72,21 @@ export function publicRecord(r) {
69
72
  git: strip(r.git),
70
73
  };
71
74
  }
75
+ /** A tool ask's person fields from its stored `detail` (none: an ordinary tool ask). */
76
+ function personFieldsOf(detail) {
77
+ if (typeof detail !== "object" || detail === null)
78
+ return null;
79
+ const d = detail;
80
+ if (!Array.isArray(d.personFields) || d.personFields.length === 0 || d.target === undefined) {
81
+ return null;
82
+ }
83
+ return {
84
+ personFields: d.personFields,
85
+ personTarget: d.target,
86
+ ...(Array.isArray(d.leakedFields) &&
87
+ d.leakedFields.length > 0 && { leakedFields: d.leakedFields }),
88
+ };
89
+ }
72
90
  /** The tool key a network ask is recorded under (the command ran in `Bash`). */
73
91
  export const NETWORK_ASK_TOOL_KEY = "Bash";
74
92
  /** The spec hash of a network ask (no tool definition is approved). */
@@ -95,6 +113,7 @@ const commandAskToolKey = (kind) => kind === "write"
95
113
  ? COMMAND_READ_TOOL_KEY
96
114
  : COMMAND_ASK_TOOL_KEY;
97
115
  const notFound = () => new ApiError("approval.not_found", "Approval not found");
116
+ const inputsNotExpected = () => new ApiError("approval.inputs_not_expected", "The inputs name fields this approval does not ask for.");
98
117
  const iso = (v) => new Date(v).toISOString();
99
118
  const isRole = (v) => v !== null && ORG_ROLES.includes(v);
100
119
  /** The scopes of an approval without stored ones: a role escalation is approved only once. */
@@ -111,6 +130,7 @@ function toRecord(r) {
111
130
  detail: r.kind === "network" ? (r.detail ?? null) : null,
112
131
  git: r.kind === "git" ? (r.detail ?? null) : null,
113
132
  command: r.kind === "command" ? (r.detail ?? null) : null,
133
+ ...(r.kind === "tool" && personFieldsOf(r.detail)),
114
134
  toolKey: r.tool_key,
115
135
  specHash: r.spec_hash,
116
136
  connectorId: r.connector_id,
@@ -166,6 +186,8 @@ let ApprovalsService = class ApprovalsService {
166
186
  lockService;
167
187
  sandbox;
168
188
  resumes;
189
+ leakCheck;
190
+ sealed;
169
191
  permissionLocks;
170
192
  permissionGrants;
171
193
  constructor(db, config, eventLog, events, txHost, schedules,
@@ -176,7 +198,11 @@ let ApprovalsService = class ApprovalsService {
176
198
  /** A trial run's 「这次允许」 becomes a task grant only within the org's egress. */
177
199
  sandbox,
178
200
  /** A decision resumes its waiting run in the decision's transaction. */
179
- resumes, permissionLocks, permissionGrants) {
201
+ resumes,
202
+ /** An entered person value seen in the conversation is refused (§4.5). */
203
+ leakCheck,
204
+ /** A person's entered values are sealed in the decision's transaction (§4.3). */
205
+ sealed, permissionLocks, permissionGrants) {
180
206
  this.db = db;
181
207
  this.config = config;
182
208
  this.eventLog = eventLog;
@@ -187,6 +213,8 @@ let ApprovalsService = class ApprovalsService {
187
213
  this.lockService = lockService;
188
214
  this.sandbox = sandbox;
189
215
  this.resumes = resumes;
216
+ this.leakCheck = leakCheck;
217
+ this.sealed = sealed;
190
218
  this.permissionLocks = permissionLocks;
191
219
  this.permissionGrants = permissionGrants;
192
220
  }
@@ -231,6 +259,7 @@ let ApprovalsService = class ApprovalsService {
231
259
  approver_role: input.approverRole,
232
260
  summary: input.summary === undefined ? null : JSON.stringify(input.summary),
233
261
  scopes: input.scopes ?? null,
262
+ ...(input.detail !== undefined && { detail: JSON.stringify(input.detail) }),
234
263
  scope: null,
235
264
  decided_by: null,
236
265
  expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
@@ -692,9 +721,13 @@ let ApprovalsService = class ApprovalsService {
692
721
  if (kind.kind === "command") {
693
722
  return this.decideCommand(orgId, id, accountId, body, actorTokenId, via);
694
723
  }
695
- const { record, toSeq } = await this.decideIn(orgId, id, accountId, body, actorTokenId);
696
- await this.announceDecided(record, toSeq);
697
- return record;
724
+ const outcome = await this.decideToolIn(orgId, id, accountId, body, actorTokenId, via);
725
+ // a leak refusal committed only the leaked paths (the approval stays pending), then refuses
726
+ if ("leaked" in outcome) {
727
+ throw new ApiError("approval.input_leaked", "This value appeared in the conversation, so it counts as leaked. Create a new one at the provider and enter that.", [{ fields: outcome.leaked }]);
728
+ }
729
+ await this.announceDecided(outcome.record, outcome.toSeq);
730
+ return outcome.record;
698
731
  }
699
732
  /**
700
733
  * A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
@@ -919,13 +952,26 @@ let ApprovalsService = class ApprovalsService {
919
952
  // its own transaction (as the legacy one was): `approval.decided` is emitted only after the
920
953
  // decision committed, even when a caller has a transaction open
921
954
  decideIn(orgId, id, accountId, body, actorTokenId, network, git, command) {
922
- return this.decideTx(orgId, id, accountId, body, actorTokenId, network, git, command);
955
+ return this.decideTx(orgId, id, accountId, body, actorTokenId, network, git, command).then((o) => {
956
+ // only a tool ask takes inputs (refused for every other kind before)
957
+ if ("leaked" in o)
958
+ throw new Error(`approval ${id}: a leak outcome outside a tool ask`);
959
+ return o;
960
+ });
961
+ }
962
+ /**
963
+ * A tool ask's decision in its own transaction. With person fields, a leak refusal commits the
964
+ * leaked paths in `detail.leakedFields` and returns them (the caller refuses after the commit,
965
+ * the approval still pending); the same transaction cannot both keep that write and throw.
966
+ */
967
+ decideToolIn(orgId, id, accountId, body, actorTokenId, via) {
968
+ return this.decideTx(orgId, id, accountId, body, actorTokenId, undefined, undefined, undefined, via);
923
969
  }
924
970
  /**
925
971
  * A decision in the caller's transaction: lock order conversation → approval → run (the resume).
926
972
  * Refuses (`approval.already_decided`, `approval.not_found`, …) before any write.
927
973
  */
928
- async decideTx(orgId, id, accountId, body, actorTokenId, network, git, command) {
974
+ async decideTx(orgId, id, accountId, body, actorTokenId, network, git, command, via = "web") {
929
975
  const t = this.db.db;
930
976
  // lock order: the conversation, the approval, then the run (as a stop of the waiting run)
931
977
  if (!(await this.lockConversationOf(id, orgId)))
@@ -973,6 +1019,61 @@ let ApprovalsService = class ApprovalsService {
973
1019
  await this.permissionGrants.assertCurrent(before.command.permissionCandidate.binding);
974
1020
  }
975
1021
  const approved = body.decision === "approve";
1022
+ const person = before.kind === "tool" ? before.personFields : undefined;
1023
+ if (body.inputs !== undefined && (person === undefined || !approved)) {
1024
+ throw inputsNotExpected();
1025
+ }
1026
+ // an approval with person fields (platform web parity spec §4.2, §4.3, R5): approved only by
1027
+ // its person, in a web session, with every asked value, valid and never seen in the
1028
+ // conversation; the values are sealed before the status changes. A deny takes no values.
1029
+ let inputsProvided;
1030
+ if (person !== undefined && approved) {
1031
+ if (actorTokenId !== undefined) {
1032
+ throw new ApiError("auth.session_required", "Values for this approval are entered in a signed-in web session, not with a personal access token.");
1033
+ }
1034
+ if (via === "im") {
1035
+ throw new ApiError("auth.session_required", "This approval asks for values entered on the web; it cannot be approved from IM.");
1036
+ }
1037
+ if (before.requestedFor !== accountId)
1038
+ throw notFound();
1039
+ const inputs = body.inputs ?? {};
1040
+ const asked = new Set(person.map((f) => f.path));
1041
+ if (Object.keys(inputs).some((p) => !asked.has(p)))
1042
+ throw inputsNotExpected();
1043
+ const problems = person.flatMap((f) => {
1044
+ const v = Object.hasOwn(inputs, f.path) ? inputs[f.path] : undefined;
1045
+ const problem = v === undefined ? `${f.label} is required.` : checkPersonValue(f, v);
1046
+ return problem === null ? [] : [{ path: f.path, problem }];
1047
+ });
1048
+ if (problems.length > 0) {
1049
+ throw new ApiError("approval.inputs_invalid", "Some entered values are not valid.", [
1050
+ { fields: problems },
1051
+ ]);
1052
+ }
1053
+ // a read in the decision's transaction: one indexed scan of the conversation tree per value
1054
+ const leaked = await this.leakCheck.leaked(before.conversationId, inputs);
1055
+ if (leaked.length > 0) {
1056
+ await t
1057
+ .updateTable("approvals")
1058
+ .set({
1059
+ detail: JSON.stringify({
1060
+ ...locked.detail,
1061
+ leakedFields: [...new Set([...(before.leakedFields ?? []), ...leaked])],
1062
+ }),
1063
+ })
1064
+ .where("id", "=", id)
1065
+ .execute();
1066
+ return { leaked };
1067
+ }
1068
+ await this.sealed.sealIn({
1069
+ approvalId: id,
1070
+ recipientAccountId: accountId,
1071
+ conversationId: before.conversationId,
1072
+ runId: before.runId,
1073
+ callId: before.callId,
1074
+ }, inputs);
1075
+ inputsProvided = person.map((f) => f.path);
1076
+ }
976
1077
  const reason = approved ? undefined : body.reason?.trim() || undefined;
977
1078
  const scope = !approved
978
1079
  ? null
@@ -1111,6 +1212,7 @@ let ApprovalsService = class ApprovalsService {
1111
1212
  ...(scope !== null && { scope }),
1112
1213
  byAccountId: accountId,
1113
1214
  ...(reason !== undefined && { reason }),
1215
+ ...(inputsProvided !== undefined && { inputsProvided }),
1114
1216
  },
1115
1217
  },
1116
1218
  ]);
@@ -1192,6 +1294,7 @@ let ApprovalsService = class ApprovalsService {
1192
1294
  scope,
1193
1295
  ...(body.note !== undefined && { note: body.note }),
1194
1296
  ...(reason !== undefined && { reason }),
1297
+ ...(inputsProvided !== undefined && { inputsProvided }),
1195
1298
  },
1196
1299
  });
1197
1300
  // the run last (lock order: the decided row, then `runs`); a still-running run is resumed by
@@ -1822,6 +1925,9 @@ __decorate([
1822
1925
  __decorate([
1823
1926
  Transactional({ propagation: "requires_new" })
1824
1927
  ], ApprovalsService.prototype, "decideIn", null);
1928
+ __decorate([
1929
+ Transactional({ propagation: "requires_new" })
1930
+ ], ApprovalsService.prototype, "decideToolIn", null);
1825
1931
  __decorate([
1826
1932
  Transactional({ propagation: "mandatory" })
1827
1933
  ], ApprovalsService.prototype, "decideTx", null);
@@ -1864,9 +1970,11 @@ ApprovalsService = __decorate([
1864
1970
  __param(7, Inject(LockService)),
1865
1971
  __param(8, Inject(SandboxService)),
1866
1972
  __param(9, Inject(RunResume)),
1867
- __param(10, Optional()),
1868
- __param(10, Inject(PermissionAuthorityLock)),
1869
- __param(11, Optional()),
1870
- __param(11, Inject(PermissionCallGrants))
1973
+ __param(10, Inject(ConversationLeakCheck)),
1974
+ __param(11, Inject(SealedInputs)),
1975
+ __param(12, Optional()),
1976
+ __param(12, Inject(PermissionAuthorityLock)),
1977
+ __param(13, Optional()),
1978
+ __param(13, Inject(PermissionCallGrants))
1871
1979
  ], ApprovalsService);
1872
1980
  export { ApprovalsService };
@@ -13,6 +13,7 @@ import { ModelPurposesService } from "../../models/purposes.js";
13
13
  import { PlatformActor } from "../../platform/actor.js";
14
14
  import { AgentDocs } from "../../platform/agent-docs.js";
15
15
  import { PlatformOperations } from "../../platform/registry.js";
16
+ import { SealedInputs } from "../../platform/sealed-inputs.js";
16
17
  import type { HookRunner } from "../../runtime/hook-calls.js";
17
18
  import { ProviderRegistry } from "../../runtime/providers.js";
18
19
  import { StepLog } from "../../runtime/step-log.js";
@@ -38,6 +39,8 @@ export declare class BuiltinTools {
38
39
  purposes: ModelPurposesService, host: {
39
40
  readonly hooks?: HookRunner;
40
41
  } | undefined, stepLog: StepLog, log: Logger, background: BackgroundTaskStore, finisher: BackgroundTaskFinisher, stopper: BackgroundTaskStopper, platformOps: PlatformOperations, platformActor: PlatformActor, agentDocs: AgentDocs,
42
+ /** The person's sealed approval card values a Platform write with person fields reads. */
43
+ sealedInputs: SealedInputs,
41
44
  /** The schedule tools read tasks and grants; their writes go through the task service. */
42
45
  scheduleStore: ScheduledTaskStore,
43
46
  /** `ScheduleUpdate`'s write: its field change and grant changes in one transaction. */
@@ -28,6 +28,7 @@ import { readOrgSettings } from "../../orgs/settings.service.js";
28
28
  import { PlatformActor } from "../../platform/actor.js";
29
29
  import { AgentDocs } from "../../platform/agent-docs.js";
30
30
  import { PlatformOperations } from "../../platform/registry.js";
31
+ import { SealedInputs } from "../../platform/sealed-inputs.js";
31
32
  import { ProviderListError, ProviderRegistry } from "../../runtime/providers.js";
32
33
  import { conversationTimeZone, RUN_CONTEXT_CLOCK } from "../../runtime/run-context.service.js";
33
34
  import { StepLog } from "../../runtime/step-log.js";
@@ -61,6 +62,8 @@ let BuiltinTools = class BuiltinTools {
61
62
  constructor(db, config, outputs, storage, attachments, eventLog, sandbox, devices, points, webPages,
62
63
  /** The WebFetch extraction call: the `web_fetch` purpose, its hooks, usage and denials. */
63
64
  purposes, host, stepLog, log, background, finisher, stopper, platformOps, platformActor, agentDocs,
65
+ /** The person's sealed approval card values a Platform write with person fields reads. */
66
+ sealedInputs,
64
67
  /** The schedule tools read tasks and grants; their writes go through the task service. */
65
68
  scheduleStore,
66
69
  /** `ScheduleUpdate`'s write: its field change and grant changes in one transaction. */
@@ -165,6 +168,24 @@ let BuiltinTools = class BuiltinTools {
165
168
  docs: agentDocs,
166
169
  setting: async (orgId) => (await readOrgSettings(db.db, orgId)).platformTool,
167
170
  log,
171
+ sealed: sealedInputs,
172
+ approvalPersonPaths: async (approvalId, call) => {
173
+ // only this call's own approved approval in this org (anything else: none, fails closed)
174
+ const row = await db.db
175
+ .selectFrom("approvals")
176
+ .select(["kind", "detail"])
177
+ .where("id", "=", approvalId)
178
+ .where("org_id", "=", call.orgId)
179
+ .where("run_id", "=", call.runId)
180
+ .where("call_id", "=", call.callId)
181
+ .where("status", "=", "approved")
182
+ .executeTakeFirst();
183
+ const fields = row?.detail
184
+ ?.personFields;
185
+ if (row?.kind !== "tool" || !Array.isArray(fields) || fields.length === 0)
186
+ return null;
187
+ return fields.map((f) => String(f.path));
188
+ },
168
189
  }),
169
190
  // the clock in the run context's time zone (the run context carries only the date)
170
191
  currentTimeTool({
@@ -210,16 +231,17 @@ BuiltinTools = __decorate([
210
231
  __param(17, Inject(PlatformOperations)),
211
232
  __param(18, Inject(PlatformActor)),
212
233
  __param(19, Inject(AgentDocs)),
213
- __param(20, Inject(ScheduledTaskStore)),
214
- __param(21, Inject(ScheduleUpdates)),
215
- __param(22, Inject(ScheduleToolsPort)),
216
- __param(23, Inject(ModelImages)),
217
- __param(24, Inject(ProviderRegistry)),
218
- __param(25, Inject(ManagedDeviceContextRecorder)),
219
- __param(26, Optional()),
220
- __param(26, Inject(RUN_CONTEXT_CLOCK)),
234
+ __param(20, Inject(SealedInputs)),
235
+ __param(21, Inject(ScheduledTaskStore)),
236
+ __param(22, Inject(ScheduleUpdates)),
237
+ __param(23, Inject(ScheduleToolsPort)),
238
+ __param(24, Inject(ModelImages)),
239
+ __param(25, Inject(ProviderRegistry)),
240
+ __param(26, Inject(ManagedDeviceContextRecorder)),
221
241
  __param(27, Optional()),
222
- __param(27, Inject(PERMISSION_CONTEXT_ACTIVATION))
242
+ __param(27, Inject(RUN_CONTEXT_CLOCK)),
243
+ __param(28, Optional()),
244
+ __param(28, Inject(PERMISSION_CONTEXT_ACTIVATION))
223
245
  ], BuiltinTools);
224
246
  export { BuiltinTools };
225
247
  /**
@@ -4,6 +4,7 @@ import type { ActorFacts } from "../../platform/actor.js";
4
4
  import type { AgentDocTopic } from "../../platform/agent-docs.js";
5
5
  import { type PlatformOperation } from "../../platform/operation.js";
6
6
  import type { PlatformOperations } from "../../platform/registry.js";
7
+ import { type SealedInputs } from "../../platform/sealed-inputs.js";
7
8
  import type { BuiltinTool, CallPolicyContext } from "../registry.js";
8
9
  /**
9
10
  * The `Platform` builtin (Platform tool spec §3–§6): one tool through which an agent discovers and
@@ -18,6 +19,11 @@ import type { BuiltinTool, CallPolicyContext } from "../registry.js";
18
19
  * waited).
19
20
  * - An `ApiError` gets the next step the operation declares for its code and the actor's role.
20
21
  * - The actor, the agent and the conversation come from the runtime context, never from input.
22
+ * - A write with person fields (platform web parity spec §4: `op.personFields`) is planned at the
23
+ * policy step: a secret in `values` is denied before the card, and the asked fields go to the
24
+ * card through {@link CallPolicy.personFields} (never remembered). The approved call reads the
25
+ * person's sealed values through `personInputs` and its result names each entered path, never a
26
+ * value.
21
27
  * - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
22
28
  */
23
29
  /** The most entries of a list in one result (operations that page return `next`). */
@@ -38,6 +44,18 @@ export interface PlatformToolDeps {
38
44
  precheckTimeoutMs?: number;
39
45
  /** A precheck that throws is logged (warn) and one that times out (debug), with the op id. */
40
46
  log?: Pick<KernelLogger, "warn"> & Partial<Pick<KernelLogger, "debug">>;
47
+ /** The person's sealed card values (`personInputs`); absent: no write has person fields. */
48
+ sealed?: Pick<SealedInputs, "consume">;
49
+ /**
50
+ * The person field paths an approval's card showed (its stored `detail.personFields`), or null
51
+ * when it has none or is not this call's approved approval in the org: what an approved call's
52
+ * values are bound to.
53
+ */
54
+ approvalPersonPaths?(approvalId: string, call: {
55
+ orgId: string;
56
+ runId: string;
57
+ callId: string;
58
+ }): Promise<string[] | null>;
41
59
  }
42
60
  /**
43
61
  * An operation's input keys as `browse` and `search` show them, so a call needs no guess:
@@ -46,4 +64,6 @@ export interface PlatformToolDeps {
46
64
  * it. Types, bounds and an example stay in `describe`.
47
65
  */
48
66
  export declare function paramsLine(op: PlatformOperation): string;
67
+ /** Model-visible: the person's values expired before the approved call ran (spec §4.3). */
68
+ export declare const PERSON_INPUTS_EXPIRED_TEXT = "The values the person entered expired before they were applied; call the operation again.";
49
69
  export declare function platformTool(deps: PlatformToolDeps): BuiltinTool;