@capybara-hq/kernel 0.1.0-rc.118 → 0.1.0-rc.119
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/automations/unattended.d.ts +2 -0
- package/dist/automations/unattended.js +10 -3
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.d.ts +2 -4
- package/dist/channels/cards.js +11 -6
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +1 -0
- package/dist/conversations/conversations.service.js +2 -0
- package/dist/conversations/events.d.ts +26 -0
- package/dist/conversations/events.js +27 -4
- package/dist/ctx/create-ctx.d.ts +1 -1
- package/dist/ctx/create-ctx.js +4 -0
- package/dist/db/kernel-schema.d.ts +17 -1
- package/dist/device-access/device-access.module.js +2 -0
- package/dist/device-access/device-access.service.d.ts +16 -2
- package/dist/device-access/device-access.service.js +59 -2
- package/dist/device-access/site-access-request.d.ts +14 -0
- package/dist/device-access/site-access-request.js +35 -0
- package/dist/device-access/site-grants.d.ts +53 -0
- package/dist/device-access/site-grants.js +268 -0
- package/dist/device-access/site-grants.module.d.ts +2 -0
- package/dist/device-access/site-grants.module.js +14 -0
- package/dist/devices/devices.service.js +2 -0
- package/dist/extensions/admin-ops.js +7 -0
- package/dist/extensions/org-config.js +4 -0
- package/dist/extensions/permission-set.d.ts +3 -0
- package/dist/extensions/permission-set.js +5 -0
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +7 -1
- package/dist/orgs/offboarding.js +2 -0
- package/dist/roles/worker.module.js +2 -0
- package/dist/sandbox/loopback-expiry.job.d.ts +3 -1
- package/dist/sandbox/loopback-expiry.job.js +9 -3
- package/dist/sandbox/operation-authority.d.ts +1 -1
- package/dist/sandbox/operation-authority.js +14 -6
- package/dist/sandbox/permission-call-types.d.ts +2 -2
- package/dist/sandbox/review/classifier.d.ts +13 -4
- package/dist/sandbox/review/classifier.js +73 -22
- package/dist/sandbox/review/permission-candidate.d.ts +3 -3
- package/dist/sandbox/review/permission-candidate.js +10 -8
- package/dist/sandbox/review/review.service.d.ts +26 -19
- package/dist/sandbox/review/review.service.js +69 -15
- package/dist/tools/approvals.service.d.ts +30 -4
- package/dist/tools/approvals.service.js +143 -12
- package/dist/tools/call-scope.d.ts +3 -0
- package/dist/tools/call-scope.js +1 -0
- package/dist/tools/network-asks.js +7 -0
- package/dist/tools/pipeline.d.ts +16 -5
- package/dist/tools/pipeline.js +314 -11
- package/dist/tools/tools.module.js +2 -0
- package/package.json +2 -2
- package/src/migrations/0205_device_site_grants.sql +30 -0
package/dist/tools/pipeline.js
CHANGED
|
@@ -16,13 +16,17 @@ import { ConversationApprovalProfile } from "../conversations/approval-profile.j
|
|
|
16
16
|
import { AttachmentsService } from "../conversations/attachments.service.js";
|
|
17
17
|
import { EventLog } from "../conversations/event-log.js";
|
|
18
18
|
import { COMMAND_ASK_MAX_CHARS, COMMAND_ASK_TEXT_MAX_CHARS, ToolViewSchema, } from "../conversations/events.js";
|
|
19
|
+
import { siteAccessDetailHash, siteAccessInstallActive, } from "../device-access/site-access-request.js";
|
|
20
|
+
import { DeviceSiteGrants } from "../device-access/site-grants.js";
|
|
19
21
|
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
20
22
|
import { pathAgainstWorkingRoot } from "../devices/working-root.js";
|
|
21
23
|
import { ApiError } from "../errors.js";
|
|
22
24
|
import { EffectiveConfigs, NEEDS_CONFIG_REASON } from "../extensions/effective-config.js";
|
|
25
|
+
import { isExtensionEnabled } from "../extensions/enabled.js";
|
|
23
26
|
import { clipText } from "../extensions/hooks.js";
|
|
24
27
|
import { ExtensionHost } from "../extensions/host.js";
|
|
25
28
|
import { ExtensionUnloadedError, PLUGIN_UNLOADED_TOOL_ERROR } from "../extensions/inflight.js";
|
|
29
|
+
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
26
30
|
import { audit } from "../identity/audit.js";
|
|
27
31
|
import { sha256Hex } from "../identity/hash.js";
|
|
28
32
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -507,6 +511,8 @@ function withBlocked(outcome, scope) {
|
|
|
507
511
|
}),
|
|
508
512
|
// a device service launch's review (ctx.deviceAccess), recorded with the call's result
|
|
509
513
|
...(review !== null && { review }),
|
|
514
|
+
...((outcome.kind === "result" || outcome.kind === "error") &&
|
|
515
|
+
scope?.siteAccess != null && { siteAccess: scope.siteAccess }),
|
|
510
516
|
};
|
|
511
517
|
}
|
|
512
518
|
/**
|
|
@@ -609,6 +615,24 @@ function loopbackAskRerunAfter(ask) {
|
|
|
609
615
|
const d = ask?.detail;
|
|
610
616
|
return ask?.status === "approved" && d?.kind === "loopback" ? d.attempt : null;
|
|
611
617
|
}
|
|
618
|
+
function approvedSiteAsk(ask) {
|
|
619
|
+
const detail = ask?.detail;
|
|
620
|
+
if (ask?.status !== "approved" || detail?.kind !== "site")
|
|
621
|
+
return null;
|
|
622
|
+
return {
|
|
623
|
+
attempt: detail.attempt,
|
|
624
|
+
toolSpecHash: detail.toolSpecHash,
|
|
625
|
+
callInputHash: detail.callInputHash,
|
|
626
|
+
deviceId: detail.deviceId,
|
|
627
|
+
approval: {
|
|
628
|
+
action: detail.action,
|
|
629
|
+
origin: detail.origin,
|
|
630
|
+
detailSha256: siteAccessDetailHash(detail.detail),
|
|
631
|
+
source: "human",
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
const siteReviewIdemKey = (runId, callId) => `permission_reviewed:site_access:${runId}:${callId}`;
|
|
612
636
|
/**
|
|
613
637
|
* Every attempt after which the call ran again: a device service's approved network ask
|
|
614
638
|
* ({@link serviceRerunAfter}), an approved loopback port ask ({@link loopbackAskRerunAfter}), or
|
|
@@ -617,17 +641,18 @@ function loopbackAskRerunAfter(ask) {
|
|
|
617
641
|
*/
|
|
618
642
|
/** The idempotency key of the `permission_reviewed` event tying a ready-grant rerun to a call. */
|
|
619
643
|
const loopbackReadyRerunIdemKey = (runId, callId) => `permission_reviewed:loopback_ready:${runId}:${callId}`;
|
|
620
|
-
function rerunPoints(ask, grant, readyRerun = null) {
|
|
644
|
+
function rerunPoints(ask, grant, readyRerun = null, site = null) {
|
|
621
645
|
const points = [
|
|
622
646
|
serviceRerunAfter(ask),
|
|
623
647
|
loopbackAskRerunAfter(ask),
|
|
624
648
|
grant?.attempt ?? null,
|
|
625
649
|
readyRerun,
|
|
650
|
+
site?.attempt ?? null,
|
|
626
651
|
];
|
|
627
652
|
return new Set(points.filter((p) => p !== null));
|
|
628
653
|
}
|
|
629
654
|
/** An ask whose approval runs the call again: it belongs to the attempt that asked. */
|
|
630
|
-
const asksPerAttempt = (ask) => ask.detail?.kind === "service" || ask.detail?.kind === "loopback";
|
|
655
|
+
const asksPerAttempt = (ask) => ask.detail?.kind === "service" || ask.detail?.kind === "loopback" || ask.detail?.kind === "site";
|
|
631
656
|
/** A builtin result's kernel-internal network report (see `BuiltinResult.networkReport`). */
|
|
632
657
|
function networkReportOf(result) {
|
|
633
658
|
const r = result?.networkReport;
|
|
@@ -715,6 +740,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
715
740
|
resultImages;
|
|
716
741
|
loopbackGrants;
|
|
717
742
|
permissionFacts;
|
|
743
|
+
siteGrants;
|
|
744
|
+
extensions;
|
|
718
745
|
decide;
|
|
719
746
|
deps;
|
|
720
747
|
constructor(kdb, eventLog,
|
|
@@ -750,7 +777,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
750
777
|
*/
|
|
751
778
|
loopbackGrants,
|
|
752
779
|
/** The device's sandbox and its provider's support a loopback grant is checked against. */
|
|
753
|
-
permissionFacts) {
|
|
780
|
+
permissionFacts, siteGrants, extensions) {
|
|
754
781
|
this.config = config;
|
|
755
782
|
this.txHost = txHost;
|
|
756
783
|
this.permissionAuthority = permissionAuthority;
|
|
@@ -763,6 +790,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
763
790
|
this.resultImages = resultImages;
|
|
764
791
|
this.loopbackGrants = loopbackGrants;
|
|
765
792
|
this.permissionFacts = permissionFacts;
|
|
793
|
+
this.siteGrants = siteGrants;
|
|
794
|
+
this.extensions = extensions;
|
|
766
795
|
this.deps = {
|
|
767
796
|
// the builtins that enter a device on the managed operation route (common.ts
|
|
768
797
|
// `inToolSandbox`, `inSandboxPreparation`): their review is the permission review, whose
|
|
@@ -913,11 +942,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
913
942
|
const ask = await this.deps.approvals.networkForCall(ctx.runId, call.id);
|
|
914
943
|
const grant = await this.loopbackGrantOf(ctx.runId, call.id);
|
|
915
944
|
const readyRerun = await this.readyLoopbackRerunOf(ctx.conversationId, ctx.runId, call.id);
|
|
945
|
+
const site = approvedSiteAsk(ask) ?? (await this.siteRerunOf(ctx, call.id));
|
|
916
946
|
let attempt = rounds.length + 1;
|
|
917
947
|
// each time the call ran again (after its network ask, browser use spec §7.1, or a loopback
|
|
918
948
|
// grant or ask) took one attempt more: input rounds asked after a re-run come after it, so
|
|
919
949
|
// every re-run point the count has passed adds one, in order
|
|
920
|
-
const reruns = rerunPoints(ask, grant, readyRerun);
|
|
950
|
+
const reruns = rerunPoints(ask, grant, readyRerun, site);
|
|
921
951
|
if (rounds.length > 0) {
|
|
922
952
|
for (const p of [...reruns].sort((a, b) => a - b))
|
|
923
953
|
if (attempt > p)
|
|
@@ -954,7 +984,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
954
984
|
ask.detail?.attempt === attempt);
|
|
955
985
|
const grantedHere = !askedHere && grant !== null && grant.attempt === attempt;
|
|
956
986
|
const readyRerunHere = !askedHere && !grantedHere && readyRerun === attempt;
|
|
957
|
-
|
|
987
|
+
const siteRerunHere = site !== null && site.attempt === attempt;
|
|
988
|
+
if (askedHere || grantedHere || readyRerunHere || siteRerunHere) {
|
|
958
989
|
const notes = askedHere && ask !== null
|
|
959
990
|
? settledNetworkNotes(ask, approvalHours(ask))
|
|
960
991
|
: grantedHere
|
|
@@ -965,6 +996,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
965
996
|
const rerunsHere = !askedHere ||
|
|
966
997
|
serviceRerunAfter(ask) !== null ||
|
|
967
998
|
loopbackAskRerunAfter(ask) !== null ||
|
|
999
|
+
siteRerunHere ||
|
|
968
1000
|
grant?.attempt === attempt;
|
|
969
1001
|
if (askedHere && ask !== null && !rerunsHere) {
|
|
970
1002
|
const kept = ask.detail?.result;
|
|
@@ -989,8 +1021,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
989
1021
|
// the asked hosts are settled: only an earlier round's launch review is carried; a
|
|
990
1022
|
// granted loopback port's note goes with the re-run's result
|
|
991
1023
|
const { review: carriedReview } = carriedOf(rounds);
|
|
992
|
-
const loopback = !askedHere || ask?.detail?.kind === "loopback";
|
|
993
|
-
return this.runCall(ctx, call, await resolve(), attempt + 1, resume, { ...(carriedReview !== undefined && { review: carriedReview }) }, loopback ? { notes, loopbackRerun: true } : {});
|
|
1024
|
+
const loopback = !siteRerunHere && (!askedHere || ask?.detail?.kind === "loopback");
|
|
1025
|
+
return this.runCall(ctx, call, await resolve(), attempt + 1, resume, { ...(carriedReview !== undefined && { review: carriedReview }) }, siteRerunHere ? { site } : loopback ? { notes, loopbackRerun: true } : {});
|
|
994
1026
|
}
|
|
995
1027
|
// the re-run started and its result was lost: the result is unknown, as below
|
|
996
1028
|
started = rerun;
|
|
@@ -1402,6 +1434,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1402
1434
|
}
|
|
1403
1435
|
return undefined;
|
|
1404
1436
|
}
|
|
1437
|
+
if (rerun.site !== undefined &&
|
|
1438
|
+
(rerun.site.toolSpecHash !== tool.specHash ||
|
|
1439
|
+
rerun.site.callInputHash !== permissionScopeHash(call.input) ||
|
|
1440
|
+
!(await this.siteRetryAllowed(ctx, call.id, tool, input, rerun.site)))) {
|
|
1441
|
+
return fail("This site approval is no longer valid. The action did not run.", outKey);
|
|
1442
|
+
}
|
|
1405
1443
|
await this.deps.eventLog.append(ctx.conversationId, [
|
|
1406
1444
|
{
|
|
1407
1445
|
type: "tool_call_started",
|
|
@@ -1436,7 +1474,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1436
1474
|
...(auto.fileSha256 !== undefined && { fileSha256: auto.fileSha256 }),
|
|
1437
1475
|
},
|
|
1438
1476
|
// and the submitted secure input holding the person's values
|
|
1439
|
-
secureInputId);
|
|
1477
|
+
secureInputId, rerun.site?.approval);
|
|
1440
1478
|
const durationMs = Date.now() - t0;
|
|
1441
1479
|
await this.deps.hooks?.afterExecute?.(ctx.runId, call.id);
|
|
1442
1480
|
// what earlier input rounds collected: a launch reviewed in a round that asked, the hosts a
|
|
@@ -1601,6 +1639,23 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1601
1639
|
...(loginCode !== undefined && { loginCode }),
|
|
1602
1640
|
...(denialHint !== undefined && { denialHint }),
|
|
1603
1641
|
};
|
|
1642
|
+
const site = outcome.kind === "result" || outcome.kind === "error" ? outcome.siteAccess : undefined;
|
|
1643
|
+
if (site !== undefined) {
|
|
1644
|
+
const handled = await this.handleSiteAccess(ctx, call, tool, input, site, attempt, keptResult, pre, callAudit, rerun.site);
|
|
1645
|
+
if (handled.kind === "wait")
|
|
1646
|
+
return handled.wait;
|
|
1647
|
+
if (handled.kind === "rerun") {
|
|
1648
|
+
return this.runCall(ctx, call, resolved, attempt + 1, resume, carried, {
|
|
1649
|
+
site: handled.site,
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
await this.writeResult(ctx, call.id, outKey, {
|
|
1653
|
+
...keptResult,
|
|
1654
|
+
content: withNetworkNotes(keptResult.content, [handled.note]),
|
|
1655
|
+
isError: true,
|
|
1656
|
+
}, pre, callAudit);
|
|
1657
|
+
return undefined;
|
|
1658
|
+
}
|
|
1604
1659
|
// a device service's loopback refusal (browser loopback port grants), decided before the other
|
|
1605
1660
|
// hosts: the conversation's permission profile grants the port (the call runs again now),
|
|
1606
1661
|
// the run waits for the device owner, or a note says why the port stays closed; its host is
|
|
@@ -2864,6 +2919,236 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2864
2919
|
});
|
|
2865
2920
|
return { kind: "wait", wait: approvalWait(ask), content: loopbackPendingNote(host, port) };
|
|
2866
2921
|
}
|
|
2922
|
+
async siteRetryAllowed(ctx, callId, tool, input, site) {
|
|
2923
|
+
if (tool.source.kind !== "plugin" ||
|
|
2924
|
+
ctx.ownerAccountId !== ctx.accountId ||
|
|
2925
|
+
unattendedRules(ctx.unattended))
|
|
2926
|
+
return false;
|
|
2927
|
+
const plugin = tool.source.plugin;
|
|
2928
|
+
const instance = this.extensions?.current(plugin);
|
|
2929
|
+
if (instance?.manifest.permissions?.deviceAccess?.siteAccess !== true ||
|
|
2930
|
+
!(await siteAccessInstallActive(this.deps.db, plugin, instance.sha256)))
|
|
2931
|
+
return false;
|
|
2932
|
+
const device = await this.deps.devices?.reviewFacts(ctx.orgId, ctx.parent?.rootConversationId ?? ctx.conversationId, ctx.conversationId);
|
|
2933
|
+
if (device?.deviceId !== site.deviceId || device.ownerAccountId !== ctx.accountId)
|
|
2934
|
+
return false;
|
|
2935
|
+
const facts = await this.siteReviewFacts(ctx, callId, site.deviceId);
|
|
2936
|
+
if (facts === null || facts.unattended)
|
|
2937
|
+
return false;
|
|
2938
|
+
const binding = site.binding;
|
|
2939
|
+
if (binding === undefined)
|
|
2940
|
+
return site.approval.source === "human";
|
|
2941
|
+
return (binding.resolvedInputHash === permissionScopeHash(input) &&
|
|
2942
|
+
facts.rootConversationId === binding.rootConversationId &&
|
|
2943
|
+
facts.profile === binding.profile &&
|
|
2944
|
+
facts.profileRevision === binding.profileRevision &&
|
|
2945
|
+
facts.scopeRevision === binding.scopeRevision &&
|
|
2946
|
+
facts.authorityRevision === binding.authorityRevision);
|
|
2947
|
+
}
|
|
2948
|
+
async siteReviewFacts(ctx, callId, deviceId) {
|
|
2949
|
+
const authority = this.permissionAuthority;
|
|
2950
|
+
if (!authority)
|
|
2951
|
+
return null;
|
|
2952
|
+
return authority
|
|
2953
|
+
.previewCall({
|
|
2954
|
+
orgId: ctx.orgId,
|
|
2955
|
+
deviceId,
|
|
2956
|
+
holderConversationId: ctx.conversationId,
|
|
2957
|
+
actor: { accountId: ctx.accountId, conversationId: ctx.conversationId, runId: ctx.runId },
|
|
2958
|
+
}, { runId: ctx.runId, callId }, ctx.signal, "site-access")
|
|
2959
|
+
.catch((err) => {
|
|
2960
|
+
ctx.signal.throwIfAborted();
|
|
2961
|
+
this.deps.log.warn("Site access facts unavailable", { runId: ctx.runId, callId, err });
|
|
2962
|
+
return null;
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2965
|
+
async siteRerunOf(ctx, callId) {
|
|
2966
|
+
const event = await this.deps.eventLog.findByIdem(ctx.conversationId, siteReviewIdemKey(ctx.runId, callId));
|
|
2967
|
+
if (event?.type !== "permission_reviewed")
|
|
2968
|
+
return null;
|
|
2969
|
+
const { site, outcome, decisionSource, binding } = event.payload;
|
|
2970
|
+
if (outcome !== "allow" || site === undefined || decisionSource === "rule")
|
|
2971
|
+
return null;
|
|
2972
|
+
return {
|
|
2973
|
+
attempt: site.attempt,
|
|
2974
|
+
toolSpecHash: binding.specHash,
|
|
2975
|
+
callInputHash: binding.callInputHash,
|
|
2976
|
+
deviceId: binding.deviceId,
|
|
2977
|
+
binding,
|
|
2978
|
+
approval: {
|
|
2979
|
+
action: site.action,
|
|
2980
|
+
origin: site.origin,
|
|
2981
|
+
detailSha256: site.detailSha256,
|
|
2982
|
+
source: decisionSource,
|
|
2983
|
+
},
|
|
2984
|
+
};
|
|
2985
|
+
}
|
|
2986
|
+
async handleSiteAccess(ctx, call, tool, input, report, attempt, kept, pre, callAudit, rerunning) {
|
|
2987
|
+
const write = (note) => ({ kind: "write", note });
|
|
2988
|
+
if (rerunning !== undefined ||
|
|
2989
|
+
(await this.deps.eventLog.findByIdem(ctx.conversationId, siteReviewIdemKey(ctx.runId, call.id))))
|
|
2990
|
+
return write("The approved site action no longer matches the active page. It did not run. Call the tool again to review the current page.");
|
|
2991
|
+
if (ctx.ownerAccountId !== ctx.accountId ||
|
|
2992
|
+
tool.source.kind !== "plugin" ||
|
|
2993
|
+
tool.source.plugin !== report.extension ||
|
|
2994
|
+
!this.siteGrants) {
|
|
2995
|
+
return write("Site access is available only to the conversation's owner on their device.");
|
|
2996
|
+
}
|
|
2997
|
+
const facts = await this.siteReviewFacts(ctx, call.id, report.deviceId);
|
|
2998
|
+
if (facts === null)
|
|
2999
|
+
return write("Site access could not be verified. It did not run.");
|
|
3000
|
+
if (facts.unattended) {
|
|
3001
|
+
return write("This site action needs the user's approval, which an unattended run cannot get. It did not run. Use browser_snapshot or browser_network to read the page.");
|
|
3002
|
+
}
|
|
3003
|
+
const verdict = await this.deps.review?.reviewSiteAccess?.({
|
|
3004
|
+
orgId: ctx.orgId,
|
|
3005
|
+
conversationId: ctx.conversationId,
|
|
3006
|
+
runId: ctx.runId,
|
|
3007
|
+
step: ctx.step,
|
|
3008
|
+
callId: call.id,
|
|
3009
|
+
signal: ctx.signal,
|
|
3010
|
+
accountId: ctx.accountId,
|
|
3011
|
+
agentId: ctx.agentId,
|
|
3012
|
+
agentVersion: ctx.agentVersion,
|
|
3013
|
+
conversationKind: ctx.conversationKind,
|
|
3014
|
+
...reviewParentOf(ctx.parent),
|
|
3015
|
+
profile: facts.profile,
|
|
3016
|
+
attended: true,
|
|
3017
|
+
refusal: null,
|
|
3018
|
+
service: report.serviceId,
|
|
3019
|
+
origin: report.origin,
|
|
3020
|
+
action: report.action,
|
|
3021
|
+
detail: report.detail,
|
|
3022
|
+
});
|
|
3023
|
+
if (!verdict)
|
|
3024
|
+
return write("Site approval is unavailable. The action did not run.");
|
|
3025
|
+
const detailSha256 = siteAccessDetailHash(report.detail);
|
|
3026
|
+
const source = verdict.approver === "none"
|
|
3027
|
+
? "full-access"
|
|
3028
|
+
: verdict.by === "classifier"
|
|
3029
|
+
? "review-model"
|
|
3030
|
+
: "rule";
|
|
3031
|
+
const candidate = {
|
|
3032
|
+
binding: {
|
|
3033
|
+
orgId: facts.orgId,
|
|
3034
|
+
rootConversationId: facts.rootConversationId,
|
|
3035
|
+
conversationId: facts.conversationId,
|
|
3036
|
+
deviceId: facts.deviceId,
|
|
3037
|
+
accountId: facts.accountId,
|
|
3038
|
+
runId: facts.runId,
|
|
3039
|
+
callId: facts.callId,
|
|
3040
|
+
toolKey: tool.key,
|
|
3041
|
+
specHash: tool.specHash,
|
|
3042
|
+
callInputHash: permissionScopeHash(call.input),
|
|
3043
|
+
resolvedInputHash: permissionScopeHash(input),
|
|
3044
|
+
profile: facts.profile,
|
|
3045
|
+
profileRevision: facts.profileRevision,
|
|
3046
|
+
scopeRevision: facts.scopeRevision,
|
|
3047
|
+
authorityRevision: facts.authorityRevision,
|
|
3048
|
+
},
|
|
3049
|
+
permissionScope: { writeDirectories: [], hosts: [] },
|
|
3050
|
+
scopeKind: "site-access",
|
|
3051
|
+
site: {
|
|
3052
|
+
service: report.serviceId,
|
|
3053
|
+
action: report.action,
|
|
3054
|
+
origin: report.origin,
|
|
3055
|
+
detailSha256,
|
|
3056
|
+
attempt,
|
|
3057
|
+
},
|
|
3058
|
+
};
|
|
3059
|
+
const review = {
|
|
3060
|
+
type: "permission_reviewed",
|
|
3061
|
+
runId: ctx.runId,
|
|
3062
|
+
idemKey: siteReviewIdemKey(ctx.runId, call.id),
|
|
3063
|
+
payload: {
|
|
3064
|
+
...candidate,
|
|
3065
|
+
candidateHash: permissionScopeHash(candidate),
|
|
3066
|
+
outcome: verdict.decision,
|
|
3067
|
+
reason: verdict.reason,
|
|
3068
|
+
decisionSource: source,
|
|
3069
|
+
crossing: "site-access",
|
|
3070
|
+
},
|
|
3071
|
+
};
|
|
3072
|
+
if (verdict.decision === "deny") {
|
|
3073
|
+
await this.recordLoopbackReview(ctx, review);
|
|
3074
|
+
return write(`The site action on ${report.origin} was denied. ${verdict.reason}`);
|
|
3075
|
+
}
|
|
3076
|
+
if (verdict.decision === "allow" && source !== "rule") {
|
|
3077
|
+
await this.writeResultIn(ctx, call.id, tool.key, kept, [review, ...pre], callAudit, [
|
|
3078
|
+
{
|
|
3079
|
+
orgId: ctx.orgId,
|
|
3080
|
+
actorAccountId: ctx.accountId,
|
|
3081
|
+
action: "device.site_access_decided",
|
|
3082
|
+
target: report.deviceId,
|
|
3083
|
+
detail: {
|
|
3084
|
+
action: report.action,
|
|
3085
|
+
origin: report.origin,
|
|
3086
|
+
detailSha256,
|
|
3087
|
+
source,
|
|
3088
|
+
outcome: "once",
|
|
3089
|
+
},
|
|
3090
|
+
},
|
|
3091
|
+
]);
|
|
3092
|
+
return {
|
|
3093
|
+
kind: "rerun",
|
|
3094
|
+
site: {
|
|
3095
|
+
attempt,
|
|
3096
|
+
toolSpecHash: tool.specHash,
|
|
3097
|
+
callInputHash: permissionScopeHash(call.input),
|
|
3098
|
+
deviceId: report.deviceId,
|
|
3099
|
+
binding: candidate.binding,
|
|
3100
|
+
approval: { action: report.action, origin: report.origin, detailSha256, source },
|
|
3101
|
+
},
|
|
3102
|
+
};
|
|
3103
|
+
}
|
|
3104
|
+
const prior = await this.deps.approvals.networkForCall(ctx.runId, call.id);
|
|
3105
|
+
const run = await this.deps.network?.grants.runState(ctx.runId, report.deviceId);
|
|
3106
|
+
if (prior !== null || run?.pending || (run?.asks ?? 0) >= MAX_NETWORK_ASKS_PER_RUN)
|
|
3107
|
+
return write("The action did not run. This call cannot request another approval.");
|
|
3108
|
+
const canRemember = verdict.approver === "person" &&
|
|
3109
|
+
ctx.parent === undefined &&
|
|
3110
|
+
(await this.siteGrants.canGrant({
|
|
3111
|
+
orgId: ctx.orgId,
|
|
3112
|
+
deviceId: report.deviceId,
|
|
3113
|
+
serviceId: report.serviceId,
|
|
3114
|
+
rootConversationId: facts.rootConversationId,
|
|
3115
|
+
origin: report.origin,
|
|
3116
|
+
action: report.action,
|
|
3117
|
+
}));
|
|
3118
|
+
const { content, outputId } = await this.keptContent(ctx, call.id, kept);
|
|
3119
|
+
const { text: _text, ...result } = kept;
|
|
3120
|
+
const ask = await this.deps.approvals.requestSiteAccess({
|
|
3121
|
+
orgId: ctx.orgId,
|
|
3122
|
+
conversationId: ctx.conversationId,
|
|
3123
|
+
runId: ctx.runId,
|
|
3124
|
+
step: ctx.step,
|
|
3125
|
+
callId: call.id,
|
|
3126
|
+
requestedFor: ctx.accountId,
|
|
3127
|
+
toolKey: tool.key,
|
|
3128
|
+
scopes: canRemember ? ["once", "session"] : ["once"],
|
|
3129
|
+
detail: {
|
|
3130
|
+
kind: "site",
|
|
3131
|
+
deviceId: report.deviceId,
|
|
3132
|
+
extension: report.extension,
|
|
3133
|
+
service: report.serviceId,
|
|
3134
|
+
rootConversationId: facts.rootConversationId,
|
|
3135
|
+
origin: report.origin,
|
|
3136
|
+
action: report.action,
|
|
3137
|
+
detail: report.detail,
|
|
3138
|
+
attempt,
|
|
3139
|
+
toolSpecHash: tool.specHash,
|
|
3140
|
+
callInputHash: permissionScopeHash(call.input),
|
|
3141
|
+
result: {
|
|
3142
|
+
...result,
|
|
3143
|
+
content: clipKept(content),
|
|
3144
|
+
...(outputId !== undefined && { outputId }),
|
|
3145
|
+
},
|
|
3146
|
+
},
|
|
3147
|
+
}, async () => {
|
|
3148
|
+
await this.writeResultIn(ctx, call.id, tool.key, kept, [review, ...pre], callAudit, []);
|
|
3149
|
+
});
|
|
3150
|
+
return { kind: "wait", wait: approvalWait(ask) };
|
|
3151
|
+
}
|
|
2867
3152
|
/**
|
|
2868
3153
|
* A loopback port grant to this call's attempt and what goes with it, in one transaction: the
|
|
2869
3154
|
* grant first (it reads the root conversation `FOR SHARE`, before the conversation row the
|
|
@@ -3139,7 +3424,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
3139
3424
|
/** The automatic decision the call runs under instead of an approval (builtins only, R2). */
|
|
3140
3425
|
decision,
|
|
3141
3426
|
/** The submitted secure input request of this call (builtins only, R4). */
|
|
3142
|
-
secureInputId) {
|
|
3427
|
+
secureInputId, siteAccess) {
|
|
3143
3428
|
const reviewedWorkingRoot = reviewed?.workingRoot;
|
|
3144
3429
|
const reviewedAgainstRoot = reviewed?.against;
|
|
3145
3430
|
if (tool.source.kind === "connector") {
|
|
@@ -3148,6 +3433,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
3148
3433
|
const handler = this.deps.registry.handler(tool.source);
|
|
3149
3434
|
if (!handler)
|
|
3150
3435
|
return { kind: "error", message: `Tool ${tool.key} is no longer available.` };
|
|
3436
|
+
if (siteAccess !== undefined &&
|
|
3437
|
+
(tool.source.kind !== "plugin" ||
|
|
3438
|
+
this.extensions?.current(tool.source.plugin)?.manifest.permissions?.deviceAccess
|
|
3439
|
+
?.siteAccess !== true)) {
|
|
3440
|
+
return {
|
|
3441
|
+
kind: "error",
|
|
3442
|
+
message: "This site approval is no longer valid. The action did not run.",
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3151
3445
|
// an extension handler gets only the SDK ToolCallContext; a builtin also gets the step's resolved
|
|
3152
3446
|
// tools (ToolSearch)
|
|
3153
3447
|
// the tree root the person looks at; every sub-agent run carries it from its start
|
|
@@ -3166,6 +3460,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
3166
3460
|
role: ctx.role,
|
|
3167
3461
|
}),
|
|
3168
3462
|
...(resume !== undefined && { resume }),
|
|
3463
|
+
...(siteAccess !== undefined && { siteAccess }),
|
|
3169
3464
|
...(tool.source.kind === "builtin" && stepTools !== undefined && { tools: stepTools }),
|
|
3170
3465
|
...(tool.source.kind === "builtin" && {
|
|
3171
3466
|
runId: ctx.runId,
|
|
@@ -3222,7 +3517,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
3222
3517
|
let config = {};
|
|
3223
3518
|
if (tool.source.kind === "plugin") {
|
|
3224
3519
|
// the step resolved its tools with the org's enablement; the rest is checked per call
|
|
3225
|
-
const gate = await extensionCallGate(this.deps, ctx.orgId, tool.key, tool.source
|
|
3520
|
+
const gate = await extensionCallGate(this.deps, ctx.orgId, tool.key, tool.source, {
|
|
3521
|
+
...(siteAccess !== undefined && {
|
|
3522
|
+
checkEnabled: (orgId, plugin) => isExtensionEnabled(this.deps.db, orgId, plugin),
|
|
3523
|
+
}),
|
|
3524
|
+
});
|
|
3226
3525
|
if (!gate.ok)
|
|
3227
3526
|
return { kind: "error", message: gate.message };
|
|
3228
3527
|
config = { config: gate.config };
|
|
@@ -3778,6 +4077,10 @@ ToolPipeline = __decorate([
|
|
|
3778
4077
|
__param(29, Optional()),
|
|
3779
4078
|
__param(29, Inject(LoopbackGrants)),
|
|
3780
4079
|
__param(30, Optional()),
|
|
3781
|
-
__param(30, Inject(PermissionFacts))
|
|
4080
|
+
__param(30, Inject(PermissionFacts)),
|
|
4081
|
+
__param(31, Optional()),
|
|
4082
|
+
__param(31, Inject(DeviceSiteGrants)),
|
|
4083
|
+
__param(32, Optional()),
|
|
4084
|
+
__param(32, Inject(ExtensionRegistry))
|
|
3782
4085
|
], ToolPipeline);
|
|
3783
4086
|
export { ToolPipeline };
|
|
@@ -13,6 +13,7 @@ import { ConversationApprovalProfileModule } from "../conversations/approval-pro
|
|
|
13
13
|
import { AttachmentsModule } from "../conversations/attachments.module.js";
|
|
14
14
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
15
15
|
import { ConversationLeakCheckModule } from "../conversations/leak-check.js";
|
|
16
|
+
import { DeviceSiteGrantsModule } from "../device-access/site-grants.module.js";
|
|
16
17
|
import { DevicesModule } from "../devices/devices.module.js";
|
|
17
18
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
18
19
|
import { FileDeliveriesModule } from "../files/deliveries.module.js";
|
|
@@ -92,6 +93,7 @@ ToolsModule = __decorate([
|
|
|
92
93
|
FileDeliveriesModule,
|
|
93
94
|
SkillsModule,
|
|
94
95
|
OrgLockModule,
|
|
96
|
+
DeviceSiteGrantsModule,
|
|
95
97
|
// the `Agent` tool's dispatch
|
|
96
98
|
SubagentsModule,
|
|
97
99
|
// the builtin sandbox and skill tools run in the conversation's device
|
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.119",
|
|
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.94"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Consent from a person's approval card for one origin and action of their device service.
|
|
2
|
+
-- The conversation is the tree's root. Only an unrevoked row whose expiry is in the future
|
|
3
|
+
-- authorizes a call. Issuance retires any expired row of the same key before replacing it.
|
|
4
|
+
CREATE TABLE IF NOT EXISTS device_site_grants (
|
|
5
|
+
id text PRIMARY KEY,
|
|
6
|
+
org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
|
|
7
|
+
device_id text NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
|
|
8
|
+
service_id text NOT NULL,
|
|
9
|
+
conversation_id text NOT NULL REFERENCES conversations(id) ON DELETE CASCADE,
|
|
10
|
+
origin text NOT NULL,
|
|
11
|
+
action text NOT NULL CHECK (action IN ('evaluate', 'storage-read', 'storage-clear', 'permission-grant')),
|
|
12
|
+
approval_id text UNIQUE REFERENCES approvals(id) ON DELETE SET NULL,
|
|
13
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
14
|
+
expires_at timestamptz NOT NULL,
|
|
15
|
+
revoked_at timestamptz
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
CREATE UNIQUE INDEX IF NOT EXISTS device_site_grants_live_uidx
|
|
19
|
+
ON device_site_grants (org_id, conversation_id, device_id, service_id, origin, action)
|
|
20
|
+
WHERE revoked_at IS NULL;
|
|
21
|
+
|
|
22
|
+
CREATE INDEX IF NOT EXISTS device_site_grants_device_idx
|
|
23
|
+
ON device_site_grants (org_id, device_id)
|
|
24
|
+
WHERE revoked_at IS NULL;
|
|
25
|
+
|
|
26
|
+
CREATE INDEX IF NOT EXISTS device_site_grants_retention_idx
|
|
27
|
+
ON device_site_grants (LEAST(expires_at, revoked_at), id);
|
|
28
|
+
|
|
29
|
+
DROP POLICY IF EXISTS org_scope ON device_site_grants;
|
|
30
|
+
CREATE POLICY org_scope ON device_site_grants USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
|