@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
package/dist/tools/pipeline.js
CHANGED
|
@@ -48,7 +48,7 @@ import { isSessionGrantableRule, } from "../sandbox/review/index.js";
|
|
|
48
48
|
import { approverForCrossing, buildPermissionCandidate, crossingOfCandidate, ESCALATION_RETRY_HINT, ESCALATION_UNATTENDED_WHY, escalationRefusedText, isEscalatedCall, } from "../sandbox/review/permission-candidate.js";
|
|
49
49
|
import { CommandReviewService } from "../sandbox/review/review.service.js";
|
|
50
50
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
51
|
-
import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRunOf, } from "../schedules/unattended.js";
|
|
51
|
+
import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRules, unattendedRunOf, } from "../schedules/unattended.js";
|
|
52
52
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
53
53
|
import { ApprovalsService, } from "./approvals.service.js";
|
|
54
54
|
import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
@@ -85,6 +85,15 @@ export const approvalDeniedText = (reason) => reason === null ? APPROVAL_DENIED_
|
|
|
85
85
|
export const approvalExpiredText = (hours) => `Approval timed out after ${hours}h; treated as denied.`;
|
|
86
86
|
/** 等待审批期间 run 被中止。 */
|
|
87
87
|
export const APPROVAL_CANCELLED_TEXT = "The run was stopped while waiting for approval.";
|
|
88
|
+
/** A person field refused on the approval card as leaked, for a call that then did not run. */
|
|
89
|
+
export const leakedOnCardText = (path) => `The person's \`${path}\` appeared in the conversation earlier and was refused as leaked; ask them to rotate it.`;
|
|
90
|
+
/**
|
|
91
|
+
* A call that ended without running: its text, then the leaked-on-card line per person field the
|
|
92
|
+
* approval card refused as leaked (`detail.leakedFields`), so the agent has the key rotated.
|
|
93
|
+
*/
|
|
94
|
+
export const withLeakedOnCard = (text, leakedFields) => leakedFields === undefined || leakedFields.length === 0
|
|
95
|
+
? text
|
|
96
|
+
: [text, ...leakedFields.map(leakedOnCardText)].join("\n");
|
|
88
97
|
/**
|
|
89
98
|
* The command review's deny text (auto mode spec §5.4, P-D12): the model-visible reason and what it
|
|
90
99
|
* can do instead. `kind` says whether a shell command, a file write or a file read was held.
|
|
@@ -128,6 +137,23 @@ export const INPUT_SKIPPED_TEXT = "The user did not provide the requested input
|
|
|
128
137
|
export const TOO_MANY_INPUT_REQUESTS_TEXT = "Tool requested user input too many times.";
|
|
129
138
|
/** run 已被中止 / 到达截止时间,调用尚未开始执行。 */
|
|
130
139
|
export const RUN_STOPPED_TEXT = "The run was stopped before this tool call was executed.";
|
|
140
|
+
/**
|
|
141
|
+
* A call with person fields in an unattended run (ruling R6): no person is there to type the
|
|
142
|
+
* values on the card.
|
|
143
|
+
*/
|
|
144
|
+
export const PERSON_FIELDS_UNATTENDED_TEXT = "This write needs the person to enter values on the web; it cannot run unattended.";
|
|
145
|
+
/**
|
|
146
|
+
* A call with person fields whose ask would go to a role instead of the person (ruling R5): only the
|
|
147
|
+
* person the run works for may type the values, and they lack the role.
|
|
148
|
+
*/
|
|
149
|
+
export const PERSON_FIELDS_ROLE_TEXT = "This write needs the person you work for to enter values; they lack the role. Ask an admin to do it on the web.";
|
|
150
|
+
/**
|
|
151
|
+
* A call only the person may confirm (`CallPolicy.personOnly`: its result is shown once to the
|
|
152
|
+
* approver) in an unattended run: nobody is there to approve and read it.
|
|
153
|
+
*/
|
|
154
|
+
export const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person who approves it; it cannot run unattended.";
|
|
155
|
+
/** A call only the person may confirm whose ask would go to a role instead of the person. */
|
|
156
|
+
export const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for, who must approve it; they lack the role. Ask an admin to do it on the web.";
|
|
131
157
|
/** 调用执行中 run 被中止 / 到达截止时间。 */
|
|
132
158
|
export const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
133
159
|
/** The fixed result of a call whose input request was skipped by a message (spec §7.1). */
|
|
@@ -707,6 +733,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
707
733
|
agentId: ctx.agentId,
|
|
708
734
|
conversationId: ctx.conversationId,
|
|
709
735
|
runId: ctx.runId,
|
|
736
|
+
callId: call.id,
|
|
710
737
|
rawInput: call.input,
|
|
711
738
|
signal: ctx.signal,
|
|
712
739
|
})) ?? null;
|
|
@@ -715,7 +742,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
715
742
|
return fail(callPolicy.denyReason, outKey);
|
|
716
743
|
}
|
|
717
744
|
const policyKey = callPolicy?.key ?? tool.key;
|
|
718
|
-
|
|
745
|
+
// person fields (platform web parity spec §4.2, R6): the person types values on the card, so an
|
|
746
|
+
// unattended run (a trial run has its creator there) cannot make the call at all
|
|
747
|
+
const personFields = callPolicy?.personFields;
|
|
748
|
+
// a call whose result is shown once to its approver asks the person the same way
|
|
749
|
+
const personOnly = personFields !== undefined || callPolicy?.personOnly === true;
|
|
750
|
+
if (personOnly && unattendedRules(ctx.unattended)) {
|
|
751
|
+
return fail(personFields !== undefined ? PERSON_FIELDS_UNATTENDED_TEXT : PERSON_ONLY_UNATTENDED_TEXT, outKey);
|
|
752
|
+
}
|
|
753
|
+
let decision = await this.decide(tool, ctx.agent, {
|
|
719
754
|
orgId: ctx.orgId,
|
|
720
755
|
accountId: ctx.accountId,
|
|
721
756
|
agentId: ctx.agentId,
|
|
@@ -740,6 +775,26 @@ let ToolPipeline = class ToolPipeline {
|
|
|
740
775
|
if (typeof decision === "object" && "unavailable" in decision) {
|
|
741
776
|
return fail(unavailableText(tool.key, decision.unavailable), outKey);
|
|
742
777
|
}
|
|
778
|
+
if (personOnly) {
|
|
779
|
+
// R6: always the person's own card, never a grant or an `allow` (the default policy already
|
|
780
|
+
// asks for them; this holds for any decision)
|
|
781
|
+
if (decision === "allow" || "grant" in decision) {
|
|
782
|
+
decision = {
|
|
783
|
+
ask: {
|
|
784
|
+
toolKey: policyKey,
|
|
785
|
+
specHash: tool.specHash,
|
|
786
|
+
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
787
|
+
requestedFor: ctx.accountId,
|
|
788
|
+
approverRole: null,
|
|
789
|
+
policy: "fixed",
|
|
790
|
+
},
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
// R5: only the person the run works for types the values; a role escalation cannot ask them
|
|
794
|
+
if ("ask" in decision && decision.ask.requestedFor === null) {
|
|
795
|
+
return fail(personFields !== undefined ? PERSON_FIELDS_ROLE_TEXT : PERSON_ONLY_ROLE_TEXT, outKey);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
743
798
|
// 该调用已有审批(续跑)→ 按审批结果;没有且策略为 ask → 建审批并等待
|
|
744
799
|
// (不写 tool_call_started:此时尚未开始执行)。
|
|
745
800
|
let approval = await this.deps.approvals.forCall(ctx.runId, call.id);
|
|
@@ -766,7 +821,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
766
821
|
approverRole: decision.ask.approverRole,
|
|
767
822
|
policy: decision.ask.policy,
|
|
768
823
|
...(callPolicy?.summary !== undefined && { summary: callPolicy.summary }),
|
|
769
|
-
...(callPolicy !== null && !callPolicy.remember && {
|
|
824
|
+
...((personFields !== undefined || (callPolicy !== null && !callPolicy.remember)) && {
|
|
825
|
+
scopes: ["once"],
|
|
826
|
+
}),
|
|
827
|
+
// the specs of the asked fields, never a value (the card draws its inputs from them)
|
|
828
|
+
...(personFields !== undefined && {
|
|
829
|
+
detail: { personFields: personFields.fields, target: personFields.target },
|
|
830
|
+
}),
|
|
770
831
|
});
|
|
771
832
|
}
|
|
772
833
|
if (approval && approval.status !== "approved") {
|
|
@@ -949,7 +1010,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
949
1010
|
},
|
|
950
1011
|
]);
|
|
951
1012
|
const t0 = Date.now();
|
|
952
|
-
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedRoots
|
|
1013
|
+
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedRoots,
|
|
1014
|
+
// the approval the call runs under (a Platform write reads the person's values by it)
|
|
1015
|
+
approval?.status === "approved" && approvedHere ? approval.id : undefined);
|
|
953
1016
|
const durationMs = Date.now() - t0;
|
|
954
1017
|
await this.deps.hooks?.afterExecute?.(ctx.runId, call.id);
|
|
955
1018
|
// the record says a call ran outside the sandbox only when admission gave it that scope
|
|
@@ -1851,19 +1914,25 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1851
1914
|
}
|
|
1852
1915
|
return null;
|
|
1853
1916
|
}
|
|
1854
|
-
/**
|
|
1917
|
+
/**
|
|
1918
|
+
* A decided approval other than approved → the model's text; still pending → null (wait). A
|
|
1919
|
+
* person field refused on the card as leaked is named, so the agent has the key rotated.
|
|
1920
|
+
*/
|
|
1855
1921
|
refusalText(a) {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1922
|
+
const text = (() => {
|
|
1923
|
+
switch (a.status) {
|
|
1924
|
+
case "denied":
|
|
1925
|
+
return approvalDeniedText(a.denyReason);
|
|
1926
|
+
case "expired":
|
|
1927
|
+
// Use the approval's own wait (creation to expiry), not the current config: it can be hot-reloaded
|
|
1928
|
+
return approvalExpiredText(approvalHours(a));
|
|
1929
|
+
case "cancelled":
|
|
1930
|
+
return APPROVAL_CANCELLED_TEXT;
|
|
1931
|
+
default:
|
|
1932
|
+
return null;
|
|
1933
|
+
}
|
|
1934
|
+
})();
|
|
1935
|
+
return text === null ? null : withLeakedOnCard(text, a.leakedFields);
|
|
1867
1936
|
}
|
|
1868
1937
|
/**
|
|
1869
1938
|
* A handler returned `input_required`: past the round limit, an invalid form
|
|
@@ -1906,7 +1975,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1906
1975
|
* 带 `tools.timeoutMs` 超时与 run 的中止信号(合并后传给处理函数 / 连接器,不响应信号的也按时结束)。
|
|
1907
1976
|
* 熔断只作用于连接器工具(键为组织 × 连接器)。
|
|
1908
1977
|
*/
|
|
1909
|
-
async execute(tool, input, ctx, callId, resume, stepTools, reviewed
|
|
1978
|
+
async execute(tool, input, ctx, callId, resume, stepTools, reviewed,
|
|
1979
|
+
/** The approved approval of this call, matching its definition and input (builtins only). */
|
|
1980
|
+
approvalId) {
|
|
1910
1981
|
const reviewedWorkingRoot = reviewed?.workingRoot;
|
|
1911
1982
|
const reviewedAgainstRoot = reviewed?.against;
|
|
1912
1983
|
if (tool.source.kind === "connector") {
|
|
@@ -1934,6 +2005,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1934
2005
|
}),
|
|
1935
2006
|
...(tool.source.kind === "builtin" &&
|
|
1936
2007
|
ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
|
|
2008
|
+
...(tool.source.kind === "builtin" && approvalId !== undefined && { approvalId }),
|
|
1937
2009
|
// a reviewed call runs in the working root its review judged (project root spec §4.3)
|
|
1938
2010
|
...(tool.source.kind === "builtin" &&
|
|
1939
2011
|
reviewedWorkingRoot !== undefined && { reviewedWorkingRoot }),
|
package/dist/tools/policy.d.ts
CHANGED
|
@@ -78,6 +78,10 @@ export declare function connectorPolicy(input: {
|
|
|
78
78
|
* for a fixed ask, a role escalation or a connector tool whose definition changed;
|
|
79
79
|
* - in `fail` mode an ask still left is refused (`{ refused, missingGrant }`, no approval), and
|
|
80
80
|
* `AskUserQuestion` is refused; in `wait` mode both ask the creator as in an attended run.
|
|
81
|
+
*
|
|
82
|
+
* A call with person fields (`CallPolicy.personFields`) or one only the person may confirm
|
|
83
|
+
* (`CallPolicy.personOnly`) is a fixed ask: no grant or agent `allow` lets it through (ruling R6).
|
|
84
|
+
* The pipeline refuses it before this in an unattended run.
|
|
81
85
|
*/
|
|
82
86
|
export declare function createDecidePolicy(db: KernelSchemaDb,
|
|
83
87
|
/** Logs (debug: once per call) when an org's stored security setting is unreadable. */
|
package/dist/tools/policy.js
CHANGED
|
@@ -101,6 +101,10 @@ export function connectorPolicy(input) {
|
|
|
101
101
|
* for a fixed ask, a role escalation or a connector tool whose definition changed;
|
|
102
102
|
* - in `fail` mode an ask still left is refused (`{ refused, missingGrant }`, no approval), and
|
|
103
103
|
* `AskUserQuestion` is refused; in `wait` mode both ask the creator as in an attended run.
|
|
104
|
+
*
|
|
105
|
+
* A call with person fields (`CallPolicy.personFields`) or one only the person may confirm
|
|
106
|
+
* (`CallPolicy.personOnly`) is a fixed ask: no grant or agent `allow` lets it through (ruling R6).
|
|
107
|
+
* The pipeline refuses it before this in an unattended run.
|
|
104
108
|
*/
|
|
105
109
|
export function createDecidePolicy(db,
|
|
106
110
|
/** Logs (debug: once per call) when an org's stored security setting is unreadable. */
|
|
@@ -249,7 +253,11 @@ log) {
|
|
|
249
253
|
tool.source.kind === "builtin" &&
|
|
250
254
|
tool.key === BUILTIN.Platform &&
|
|
251
255
|
changesAgentSkills(policyKey);
|
|
256
|
+
// person fields (platform web parity spec §4.2, R6): the person types values on the card, so
|
|
257
|
+
// the call asks every time, outside every grant, and no agent `allow` lifts it
|
|
252
258
|
const fixedAsk = unattendedSkillChange ||
|
|
259
|
+
call?.personFields !== undefined ||
|
|
260
|
+
call?.personOnly === true ||
|
|
253
261
|
isFixedAsk(tool) ||
|
|
254
262
|
(call !== null && !call.remember && (call.policy !== "allow" || agentOverride !== undefined));
|
|
255
263
|
const input = {
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { ExtensionRegistry } from "../extensions/registry.js";
|
|
|
7
7
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
8
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
9
|
import type { OrgRole } from "../orgs/roles.js";
|
|
10
|
+
import type { PersonFieldSpec } from "../platform/person-fields.js";
|
|
10
11
|
import type { ConversationKindForHooks } from "../runtime/hook-calls.js";
|
|
11
12
|
import type { ExecutionClaim } from "../runtime/run-execution.js";
|
|
12
13
|
import { BuiltinTools } from "./builtins/builtin-tools.js";
|
|
@@ -95,6 +96,12 @@ export interface BuiltinCallContext extends ToolCallContext {
|
|
|
95
96
|
agentVersion?: number;
|
|
96
97
|
conversationKind?: ConversationKindForHooks;
|
|
97
98
|
parent?: HookParentScope;
|
|
99
|
+
/**
|
|
100
|
+
* The approval the call runs under: set only when an approved approval of this call, matching
|
|
101
|
+
* its definition and input, let it through (absent for a grant or a policy allow). A `Platform`
|
|
102
|
+
* call with person fields reads the person's sealed values by it.
|
|
103
|
+
*/
|
|
104
|
+
approvalId?: string;
|
|
98
105
|
}
|
|
99
106
|
/** One image the builtin `Read` stored for a call (`tool_result.media`, vision-read design §1.2). */
|
|
100
107
|
export type ToolResultMedia = NonNullable<EventPayload<"tool_result">["media"]>[number];
|
|
@@ -177,6 +184,8 @@ export interface CallPolicyContext {
|
|
|
177
184
|
conversationId: string;
|
|
178
185
|
/** Null outside a run (a builtin called directly). */
|
|
179
186
|
runId: string | null;
|
|
187
|
+
/** The tool call being decided (a call id is unique within its run). Absent outside the pipeline. */
|
|
188
|
+
callId?: string;
|
|
180
189
|
/**
|
|
181
190
|
* The call's input as the model sent it, before `{"$output": id}` references were resolved
|
|
182
191
|
* (the approval card shows this form). Absent outside the pipeline.
|
|
@@ -205,6 +214,26 @@ export interface CallPolicy {
|
|
|
205
214
|
};
|
|
206
215
|
/** With `policy: "deny"`: the actionable English reason returned as the tool error. */
|
|
207
216
|
denyReason?: string;
|
|
217
|
+
/**
|
|
218
|
+
* The secret fields the person enters on the approval card for this call (platform web parity
|
|
219
|
+
* spec §4.2): only the asked ones, specs without values. The pipeline always asks for such a
|
|
220
|
+
* call (never a grant or an `allow`; ruling R6), refuses it in an unattended run and when the ask
|
|
221
|
+
* would go to a role instead of the person, and stores the fields in the approval's `detail`.
|
|
222
|
+
*/
|
|
223
|
+
personFields?: {
|
|
224
|
+
target: {
|
|
225
|
+
zh: string;
|
|
226
|
+
en: string;
|
|
227
|
+
};
|
|
228
|
+
fields: PersonFieldSpec[];
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Only the person the run works for can confirm this call, on the card, because its result is
|
|
232
|
+
* shown once to whoever approves it (an invitation link, a generated initial password). Like a
|
|
233
|
+
* call with person fields (ruling R6): it always asks, never a grant or an `allow`; it is
|
|
234
|
+
* refused in an unattended run and when the ask would go to a role instead of the person.
|
|
235
|
+
*/
|
|
236
|
+
personOnly?: true;
|
|
208
237
|
}
|
|
209
238
|
export type ToolPolicy = "allow" | "ask" | "deny";
|
|
210
239
|
export interface ResolvedTool {
|
|
@@ -9,6 +9,7 @@ import { BackgroundModule } from "../background/background.module.js";
|
|
|
9
9
|
import { ConversationAccessModule } from "../conversations/access.js";
|
|
10
10
|
import { AttachmentsModule } from "../conversations/attachments.module.js";
|
|
11
11
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
12
|
+
import { ConversationLeakCheckModule } from "../conversations/leak-check.js";
|
|
12
13
|
import { DevicesModule } from "../devices/devices.module.js";
|
|
13
14
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
14
15
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
@@ -66,6 +67,8 @@ ToolsModule = __decorate([
|
|
|
66
67
|
PermissionAuthorityModule,
|
|
67
68
|
OperationAuthorityModule,
|
|
68
69
|
EventLogModule,
|
|
70
|
+
// the approval decision's leak check of a person's card values
|
|
71
|
+
ConversationLeakCheckModule,
|
|
69
72
|
AttachmentsModule,
|
|
70
73
|
ExtensionsModule,
|
|
71
74
|
StorageModule,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.59",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.43"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/ws": "^8.18.2",
|
|
76
76
|
"@types/yauzl": "3.4.0",
|
|
77
77
|
"ws": "^8.22.0",
|
|
78
|
-
"@capybara-hq/device": "0.1.0-rc.
|
|
78
|
+
"@capybara-hq/device": "0.1.0-rc.23",
|
|
79
79
|
"@capybara-hq/testing": "0.1.0-rc.29"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Platform web parity (spec 2026-11-19-platform-web-parity-design.md §4.3): values a person types on
|
|
2
|
+
-- an approval card for a Platform call's secret fields, sealed until the resumed call consumes them
|
|
3
|
+
-- once. Expand-only.
|
|
4
|
+
--
|
|
5
|
+
-- One row per approval, written in the decision's transaction. The values are one JSON object
|
|
6
|
+
-- sealed with the master keyring (AES-256-GCM, AAD = approval id plus the sorted field paths in
|
|
7
|
+
-- `paths`, so a row whose paths are altered fails to unwrap). Only the recipient (the person who
|
|
8
|
+
-- typed them) may consume the row; the resumed call deletes it in the transaction that applies the
|
|
9
|
+
-- write, and the hourly cleanup job drops rows past expires_at (15 minutes after the decision).
|
|
10
|
+
CREATE TABLE IF NOT EXISTS capybara.platform_sealed_inputs (
|
|
11
|
+
approval_id text PRIMARY KEY REFERENCES capybara.approvals(id) ON DELETE CASCADE,
|
|
12
|
+
recipient_account_id text NOT NULL REFERENCES capybara.accounts(id) ON DELETE CASCADE,
|
|
13
|
+
conversation_id text NOT NULL REFERENCES capybara.conversations(id) ON DELETE CASCADE,
|
|
14
|
+
run_id text NOT NULL,
|
|
15
|
+
call_id text NOT NULL,
|
|
16
|
+
paths text[] NOT NULL,
|
|
17
|
+
master_key_id text NOT NULL,
|
|
18
|
+
ciphertext bytea NOT NULL,
|
|
19
|
+
expires_at timestamptz NOT NULL,
|
|
20
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
21
|
+
);
|
|
22
|
+
CREATE INDEX IF NOT EXISTS platform_sealed_inputs_expires_idx
|
|
23
|
+
ON capybara.platform_sealed_inputs (expires_at);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Platform web parity (spec 2026-11-19-platform-web-parity-design.md §7.2, plan ruling R10): a
|
|
2
|
+
-- value a Platform call made that only the person who approved the call may read, once, on the
|
|
3
|
+
-- web, like the generated initial password (account_initial_passwords). The first kind is
|
|
4
|
+
-- `invitation_link`: the token of an invitation an org admin's agent created. Expand-only.
|
|
5
|
+
--
|
|
6
|
+
-- One row per value, keyed by the subject it belongs to (the invitation id). The value is sealed
|
|
7
|
+
-- with the master keyring (AES-256-GCM, AAD = the subject id, so a row moved to another subject
|
|
8
|
+
-- fails to unwrap). The tool call it came from (conversation_id, run_id, call_id: a call id is
|
|
9
|
+
-- unique only within its run) and its recipient decide who may read it. Read once (deleted as it
|
|
10
|
+
-- is read), dropped after expires_at (24 hours) by the hourly cleanup job.
|
|
11
|
+
CREATE TABLE IF NOT EXISTS capybara.platform_sealed_reveals (
|
|
12
|
+
id text PRIMARY KEY,
|
|
13
|
+
kind text NOT NULL,
|
|
14
|
+
org_id text NOT NULL REFERENCES capybara.orgs(id) ON DELETE CASCADE,
|
|
15
|
+
recipient_account_id text NOT NULL REFERENCES capybara.accounts(id) ON DELETE CASCADE,
|
|
16
|
+
conversation_id text NOT NULL REFERENCES capybara.conversations(id) ON DELETE CASCADE,
|
|
17
|
+
run_id text NOT NULL,
|
|
18
|
+
call_id text NOT NULL,
|
|
19
|
+
master_key_id text NOT NULL,
|
|
20
|
+
ciphertext bytea NOT NULL,
|
|
21
|
+
expires_at timestamptz NOT NULL,
|
|
22
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
23
|
+
);
|
|
24
|
+
CREATE INDEX IF NOT EXISTS platform_sealed_reveals_call_idx
|
|
25
|
+
ON capybara.platform_sealed_reveals (conversation_id, run_id, call_id);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS platform_sealed_reveals_expires_idx
|
|
27
|
+
ON capybara.platform_sealed_reveals (expires_at);
|