@capybara-hq/kernel 0.1.0-rc.117 → 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/admin/usage.service.d.ts +4 -2
- package/dist/admin/usage.service.js +35 -15
- package/dist/automations/unattended.d.ts +2 -0
- package/dist/automations/unattended.js +10 -3
- package/dist/catalog/component-scope.service.js +2 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-install.d.ts +1 -0
- package/dist/catalog/plugin-install.js +11 -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.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.service.d.ts +4 -2
- package/dist/conversations/conversations.service.js +19 -3
- package/dist/conversations/events.d.ts +35 -1
- package/dist/conversations/events.js +29 -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 +31 -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.controller.d.ts +5 -0
- package/dist/devices/devices.controller.js +20 -2
- package/dist/devices/devices.service.d.ts +3 -1
- package/dist/devices/devices.service.js +6 -0
- package/dist/evals/plan.d.ts +3 -1
- package/dist/evals/plan.js +25 -5
- package/dist/evals/runs.service.js +3 -2
- package/dist/evals/trajectory.js +1 -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/files/blob-references.d.ts +8 -0
- package/dist/files/blob-references.js +19 -0
- package/dist/files/blob-sweep.job.js +5 -23
- package/dist/files/library-files.service.js +8 -4
- package/dist/models/cache-write-usage.d.ts +3 -0
- package/dist/models/cache-write-usage.js +26 -0
- package/dist/models/images.js +5 -1
- package/dist/models/prices.d.ts +8 -6
- package/dist/models/prices.js +28 -3
- package/dist/orgs/offboarding.js +2 -0
- package/dist/orgs/settings.controller.d.ts +4 -17
- package/dist/orgs/settings.controller.js +5 -9
- package/dist/orgs/settings.service.d.ts +12 -0
- package/dist/orgs/settings.service.js +24 -0
- package/dist/platform/exclusions.js +6 -0
- package/dist/platform/ops/admin.ops.js +2 -2
- package/dist/platform/ops/conversations.ops.js +1 -1
- package/dist/platform/ops/devices.ops.js +7 -0
- package/dist/platform/ops/org-settings.ops.d.ts +3 -1
- package/dist/platform/ops/org-settings.ops.js +10 -10
- package/dist/roles/worker.module.js +2 -0
- package/dist/runtime/context/build.d.ts +2 -0
- package/dist/runtime/context/build.js +9 -1
- package/dist/runtime/usage-report.js +3 -0
- package/dist/sandbox/legacy-retirement.d.ts +15 -0
- package/dist/sandbox/legacy-retirement.js +243 -3
- 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/permission-instance-writes.d.ts +4 -1
- package/dist/sandbox/permission-instance-writes.js +55 -1
- package/dist/sandbox/providers.d.ts +6 -1
- package/dist/sandbox/providers.js +15 -1
- 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/sandbox/sandbox.service.d.ts +6 -3
- package/dist/sandbox/sandbox.service.js +116 -5
- package/dist/tools/approvals.service.d.ts +30 -4
- package/dist/tools/approvals.service.js +143 -12
- package/dist/tools/builtins/sandbox/common.js +10 -6
- package/dist/tools/call-scope.d.ts +3 -0
- package/dist/tools/call-scope.js +1 -0
- package/dist/tools/connector-tools-jobs.d.ts +3 -2
- package/dist/tools/connectors.service.d.ts +3 -1
- package/dist/tools/connectors.service.js +64 -12
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +13 -13
- 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/0202_connector_endpoint_changed_at.sql +1 -0
- package/src/migrations/0203_model_cache_write_pricing.sql +5 -0
- package/src/migrations/0204_device_instance_retirement_identities.sql +46 -0
- package/src/migrations/0205_device_site_grants.sql +30 -0
|
@@ -29,6 +29,7 @@ import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
|
29
29
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
30
30
|
import { firstOrgOwner } from "../orgs/org-owner.js";
|
|
31
31
|
import { UUID_RE } from "../ui/registry.js";
|
|
32
|
+
import { canonicalJson } from "./canonical-json.js";
|
|
32
33
|
import { connectorSetup, connectorSetups } from "./connector-setup.js";
|
|
33
34
|
import { CONNECTOR_TOOLS_JOB, CONNECTOR_TOOLS_QUEUE, connectorToolsJobId, } from "./connector-tools-jobs.js";
|
|
34
35
|
import { CredentialMissing, Credentials, isOAuth, } from "./credentials.js";
|
|
@@ -530,6 +531,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
530
531
|
name,
|
|
531
532
|
connector: input.connector,
|
|
532
533
|
endpoint: JSON.stringify(endpoint),
|
|
534
|
+
endpoint_changed_at: sql `now()`,
|
|
533
535
|
auth: JSON.stringify(auth),
|
|
534
536
|
git_hosts: input.git !== undefined ? JSON.stringify(input.git.hosts) : null,
|
|
535
537
|
description: ownDescription(input.description),
|
|
@@ -659,6 +661,8 @@ let ConnectorsService = class ConnectorsService {
|
|
|
659
661
|
.updateTable("connectors")
|
|
660
662
|
.set({
|
|
661
663
|
endpoint: JSON.stringify(p.endpoint),
|
|
664
|
+
endpoint_changed_at: sql `case when endpoint is distinct from ${JSON.stringify(p.endpoint)}::jsonb
|
|
665
|
+
then clock_timestamp() else endpoint_changed_at end`,
|
|
662
666
|
auth: JSON.stringify(input.auth),
|
|
663
667
|
git_hosts: input.git !== undefined ? JSON.stringify(input.git.hosts) : null,
|
|
664
668
|
// "use for git" needs org ownership and git hosts: a template that drops either clears it
|
|
@@ -1190,6 +1194,9 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1190
1194
|
throw new ApiError("validation_failed", "Request validation failed", problems);
|
|
1191
1195
|
}
|
|
1192
1196
|
const ep = patch.endpoint !== undefined ? await this.endpointChange(t, app, patch.endpoint) : undefined;
|
|
1197
|
+
if (patch.status === "active" && app.status === "disabled" && ep === undefined) {
|
|
1198
|
+
await this.oweStaleEndpointList(orgId, app);
|
|
1199
|
+
}
|
|
1193
1200
|
const gitChanged = patch.useForGit !== undefined && patch.useForGit !== app.use_for_git;
|
|
1194
1201
|
const description = patch.description !== undefined ? ownDescription(patch.description) : undefined;
|
|
1195
1202
|
const descriptionChanged = description !== undefined && description !== app.description;
|
|
@@ -1210,7 +1217,10 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1210
1217
|
}),
|
|
1211
1218
|
...(gitChanged && { use_for_git: patch.useForGit === true }),
|
|
1212
1219
|
...(descriptionChanged && { description }),
|
|
1213
|
-
...(ep !== undefined && {
|
|
1220
|
+
...(ep !== undefined && {
|
|
1221
|
+
endpoint: JSON.stringify(ep.endpoint),
|
|
1222
|
+
endpoint_changed_at: sql `clock_timestamp()`,
|
|
1223
|
+
}),
|
|
1214
1224
|
updated_at: sql `now()`,
|
|
1215
1225
|
})
|
|
1216
1226
|
.where("id", "=", connectorId)
|
|
@@ -1411,6 +1421,27 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1411
1421
|
.where("deleted_at", "is", null)
|
|
1412
1422
|
.execute();
|
|
1413
1423
|
}
|
|
1424
|
+
/** Owe a listing before changing the row's status and legacy last-update timestamp. */
|
|
1425
|
+
async oweStaleEndpointList(orgId, app) {
|
|
1426
|
+
const auth = app.auth;
|
|
1427
|
+
if (app.platform_template_id === null ||
|
|
1428
|
+
(auth.type !== "none" && auth.ownership === "personal")) {
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
const stale = await this.db
|
|
1432
|
+
.selectFrom("connectors")
|
|
1433
|
+
.select("id")
|
|
1434
|
+
.where("org_id", "=", orgId)
|
|
1435
|
+
.where("id", "=", app.id)
|
|
1436
|
+
.where((eb) => eb.or([
|
|
1437
|
+
eb("tools_synced_at", "is", null),
|
|
1438
|
+
eb("tools_synced_at", "<", sql `coalesce(endpoint_changed_at, updated_at)`),
|
|
1439
|
+
]))
|
|
1440
|
+
.executeTakeFirst();
|
|
1441
|
+
if (stale && (await this.setupOf(orgId, app)) === "ready") {
|
|
1442
|
+
await this.oweToolList(orgId, app.id, "reactivated");
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1414
1445
|
/**
|
|
1415
1446
|
* Re-enables a connector the given plugin's switch-off disabled
|
|
1416
1447
|
* ({@link disableWithPluginIn}) when the plugin is switched back on and its install takes the
|
|
@@ -1418,17 +1449,27 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1418
1449
|
* or one another state left disabled stays disabled. Returns whether it switched it on.
|
|
1419
1450
|
*/
|
|
1420
1451
|
async enableIfPluginDisabledIn(orgId, connectorId, itemId) {
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
.
|
|
1452
|
+
await this.orgLock.lock(orgId);
|
|
1453
|
+
const app = await this.db
|
|
1454
|
+
.selectFrom("connectors")
|
|
1455
|
+
.select(["id", "auth", "platform_template_id"])
|
|
1424
1456
|
.where("id", "=", connectorId)
|
|
1425
1457
|
.where("org_id", "=", orgId)
|
|
1426
1458
|
.where("deleted_at", "is", null)
|
|
1427
1459
|
.where("status", "=", "disabled")
|
|
1428
1460
|
.where("disabled_by_plugin_id", "=", itemId)
|
|
1429
|
-
.
|
|
1461
|
+
.forUpdate()
|
|
1430
1462
|
.executeTakeFirst();
|
|
1431
|
-
|
|
1463
|
+
if (!app)
|
|
1464
|
+
return false;
|
|
1465
|
+
await this.oweStaleEndpointList(orgId, app);
|
|
1466
|
+
await this.db
|
|
1467
|
+
.updateTable("connectors")
|
|
1468
|
+
.set({ status: "active", disabled_by_plugin_id: null, updated_at: sql `now()` })
|
|
1469
|
+
.where("id", "=", connectorId)
|
|
1470
|
+
.where("org_id", "=", orgId)
|
|
1471
|
+
.execute();
|
|
1472
|
+
return true;
|
|
1432
1473
|
}
|
|
1433
1474
|
/**
|
|
1434
1475
|
* Disables or enables a connector on the platform's behalf (a super admin who need not be a
|
|
@@ -1441,6 +1482,9 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1441
1482
|
const orgId = await this.liveOrgOf(connectorId);
|
|
1442
1483
|
await this.orgLock.lock(orgId);
|
|
1443
1484
|
const app = await this.row(t, orgId, connectorId, true);
|
|
1485
|
+
if (status === "active" && app.status === "disabled") {
|
|
1486
|
+
await this.oweStaleEndpointList(orgId, app);
|
|
1487
|
+
}
|
|
1444
1488
|
await t
|
|
1445
1489
|
.updateTable("connectors")
|
|
1446
1490
|
// The platform's explicit choice replaces a plugin switch-off's: a later plugin switch-on
|
|
@@ -1525,13 +1569,17 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1525
1569
|
const auth = app.auth;
|
|
1526
1570
|
const { specs, resources } = await this.drift.listTools(orgId, app.connector, app.endpoint, () => this.credentials.injection(orgId, connectorId, auth, actorAccountId), { connectorId }, (last) => this.credentials.onUnauthorized(orgId, connectorId, auth, actorAccountId, last));
|
|
1527
1571
|
const { rows, issues } = snapshot(app.slug, specs, resources);
|
|
1528
|
-
return this.refreshIn(orgId, connectorId, actorAccountId, actorTokenId, opts, rows, issues);
|
|
1572
|
+
return this.refreshIn(orgId, connectorId, actorAccountId, actorTokenId, opts, app.endpoint, rows, issues);
|
|
1529
1573
|
}
|
|
1530
1574
|
/** The org-locked compare-and-write of {@link refresh} (the tool list was fetched before). */
|
|
1531
|
-
async refreshIn(orgId, connectorId, actorAccountId, actorTokenId, opts, rows, issues) {
|
|
1575
|
+
async refreshIn(orgId, connectorId, actorAccountId, actorTokenId, opts, listedEndpoint, rows, issues) {
|
|
1532
1576
|
const t = this.db;
|
|
1533
1577
|
await this.orgLock.lockAndAuthorize(orgId, actorAccountId, opts.trigger === "first_connect" ? "connectors.use" : "connectors.manage");
|
|
1534
|
-
const
|
|
1578
|
+
const app = await this.row(t, orgId, connectorId, true);
|
|
1579
|
+
if (canonicalJson(app.endpoint) !== canonicalJson(listedEndpoint)) {
|
|
1580
|
+
throw new ApiError("conflict", "The connector endpoint changed during the refresh. Retry the refresh.");
|
|
1581
|
+
}
|
|
1582
|
+
const changes = await this.drift.apply(app, rows);
|
|
1535
1583
|
await audit(t, {
|
|
1536
1584
|
actorAccountId,
|
|
1537
1585
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -1588,13 +1636,15 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1588
1636
|
throw e;
|
|
1589
1637
|
}
|
|
1590
1638
|
const { rows } = snapshot(app.slug, listed.specs, listed.resources);
|
|
1591
|
-
return (await this.storeListedIn(orgId, connectorId, rows, accountId))
|
|
1639
|
+
return (await this.storeListedIn(orgId, connectorId, app.endpoint, rows, accountId))
|
|
1640
|
+
? "listed"
|
|
1641
|
+
: "skipped";
|
|
1592
1642
|
}
|
|
1593
1643
|
/**
|
|
1594
1644
|
* The org-locked write of {@link listToolsForJob}; false (nothing written) when the org or the
|
|
1595
|
-
* connector is gone, disabled
|
|
1645
|
+
* connector is gone, disabled, `needs_config`, or the endpoint changed.
|
|
1596
1646
|
*/
|
|
1597
|
-
async storeListedIn(orgId, connectorId, rows, accountId) {
|
|
1647
|
+
async storeListedIn(orgId, connectorId, listedEndpoint, rows, accountId) {
|
|
1598
1648
|
const t = this.db;
|
|
1599
1649
|
if (!(await this.orgLock.tryLock(orgId)))
|
|
1600
1650
|
return false;
|
|
@@ -1609,6 +1659,8 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1609
1659
|
// switched off or lost its input since the listing: write nothing (a later save owes a job)
|
|
1610
1660
|
if (locked?.status !== "active")
|
|
1611
1661
|
return false;
|
|
1662
|
+
if (canonicalJson(locked.endpoint) !== canonicalJson(listedEndpoint))
|
|
1663
|
+
return false;
|
|
1612
1664
|
if ((await this.setupOf(orgId, locked)) !== "ready")
|
|
1613
1665
|
return false;
|
|
1614
1666
|
const changes = await this.drift.apply(locked, rows);
|
package/dist/tools/drift.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type DriftCheckResult = {
|
|
|
25
25
|
changes: DriftChanges;
|
|
26
26
|
} | {
|
|
27
27
|
status: "skipped";
|
|
28
|
-
reason: "not_found" | "inactive" | "no_connector" | "no_credential" | "connect_failed";
|
|
28
|
+
reason: "not_found" | "inactive" | "endpoint_changed" | "no_connector" | "no_credential" | "connect_failed";
|
|
29
29
|
};
|
|
30
30
|
type ToolSource = "connector" | "resources";
|
|
31
31
|
/** 快照中被停用 / 跳过的工具及英文原因。 */
|
package/dist/tools/drift.js
CHANGED
|
@@ -495,17 +495,14 @@ let ToolDrift = class ToolDrift {
|
|
|
495
495
|
return { status: "skipped", reason };
|
|
496
496
|
}
|
|
497
497
|
const { rows } = snapshot(app.slug, listed.specs, listed.resources);
|
|
498
|
-
|
|
499
|
-
if (!changes)
|
|
500
|
-
return { status: "skipped", reason: "inactive" };
|
|
501
|
-
return { status: "checked", changes };
|
|
498
|
+
return this.applyChecked(orgId, connectorId, trigger, app.endpoint, rows);
|
|
502
499
|
}
|
|
503
500
|
/** The locked compare-and-write of {@link check}, audited when something changed. */
|
|
504
|
-
async applyChecked(orgId, connectorId, trigger, rows) {
|
|
501
|
+
async applyChecked(orgId, connectorId, trigger, listedEndpoint, rows) {
|
|
505
502
|
const t = this.db.db;
|
|
506
503
|
const locked = await t
|
|
507
504
|
.selectFrom("connectors")
|
|
508
|
-
.select(["id", "tools_synced_at", "template_tool_policies"])
|
|
505
|
+
.select(["id", "endpoint", "tools_synced_at", "template_tool_policies"])
|
|
509
506
|
.where("id", "=", connectorId)
|
|
510
507
|
.where("org_id", "=", orgId)
|
|
511
508
|
.where("deleted_at", "is", null)
|
|
@@ -513,22 +510,25 @@ let ToolDrift = class ToolDrift {
|
|
|
513
510
|
.forUpdate()
|
|
514
511
|
.executeTakeFirst();
|
|
515
512
|
if (!locked)
|
|
516
|
-
return
|
|
517
|
-
|
|
518
|
-
|
|
513
|
+
return { status: "skipped", reason: "inactive" };
|
|
514
|
+
if (canonicalJson(locked.endpoint) !== canonicalJson(listedEndpoint)) {
|
|
515
|
+
return { status: "skipped", reason: "endpoint_changed" };
|
|
516
|
+
}
|
|
517
|
+
const changes = await this.apply(locked, rows);
|
|
518
|
+
if (changes.added.length + changes.changed.length + changes.removed.length > 0) {
|
|
519
519
|
await audit(t, {
|
|
520
520
|
orgId,
|
|
521
521
|
action: "connector.tools_drifted",
|
|
522
522
|
target: connectorId,
|
|
523
523
|
detail: {
|
|
524
|
-
added:
|
|
525
|
-
changed:
|
|
526
|
-
removed:
|
|
524
|
+
added: changes.added.length,
|
|
525
|
+
changed: changes.changed.length,
|
|
526
|
+
removed: changes.removed.length,
|
|
527
527
|
trigger,
|
|
528
528
|
},
|
|
529
529
|
});
|
|
530
530
|
}
|
|
531
|
-
return
|
|
531
|
+
return { status: "checked", changes };
|
|
532
532
|
}
|
|
533
533
|
/**
|
|
534
534
|
* 连接器在会话中报告工具清单变了:投递一次该连接器的检查(jobId 按分钟桶去重)。投递失败只记日志。
|
|
@@ -366,6 +366,13 @@ const NO_OFFER_WHY = "the device's owner changes the device's network on its pag
|
|
|
366
366
|
export function settledNetworkNotes(a, hours) {
|
|
367
367
|
if (a.detail?.kind === "loopback")
|
|
368
368
|
return settledLoopbackNotes(a, hours);
|
|
369
|
+
if (a.detail?.kind === "site") {
|
|
370
|
+
if (a.status === "pending")
|
|
371
|
+
return null;
|
|
372
|
+
if (a.status === "approved")
|
|
373
|
+
return [];
|
|
374
|
+
return [`The site action on ${a.detail.origin} was not approved. It did not run.`];
|
|
375
|
+
}
|
|
369
376
|
const detail = a.detail;
|
|
370
377
|
const asked = detail === null ? [] : networkAskHosts(detail);
|
|
371
378
|
switch (a.status) {
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ConversationSource, type FormAnswer, type InputForm, type Logger, type ServiceBlockedHost, type ToolCallContext, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type ConversationSource, type FormAnswer, type InputForm, type Logger, type ServiceBlockedHost, type SiteAccessApproval, type ToolCallContext, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { AgentDefinition } from "../agents/definition.js";
|
|
3
3
|
import { type UnattendedRun } from "../automations/unattended.js";
|
|
4
4
|
import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
|
|
@@ -6,9 +6,12 @@ import { AttachmentsService } from "../conversations/attachments.service.js";
|
|
|
6
6
|
import { EventLog } from "../conversations/event-log.js";
|
|
7
7
|
import { type ReviewRecord } from "../conversations/events.js";
|
|
8
8
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
9
|
+
import { type ReportedSiteAccess } from "../device-access/site-access-request.js";
|
|
10
|
+
import { DeviceSiteGrants } from "../device-access/site-grants.js";
|
|
9
11
|
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
10
12
|
import { EffectiveConfigs } from "../extensions/effective-config.js";
|
|
11
13
|
import { ExtensionHost } from "../extensions/host.js";
|
|
14
|
+
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
12
15
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
13
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
17
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -245,7 +248,7 @@ interface PipelineDeps {
|
|
|
245
248
|
readonly breaker: Pick<Breaker, "check" | "failure" | "success">;
|
|
246
249
|
readonly outputs: Pick<ToolOutputs, "save" | "load">;
|
|
247
250
|
/** 策略为 `ask` 时建审批;续跑时读该调用的审批结果。 A refused network host: a network ask. */
|
|
248
|
-
readonly approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "requestLoopback" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">;
|
|
251
|
+
readonly approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "requestLoopback" | "requestSiteAccess" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">;
|
|
249
252
|
/** 处理函数返回 `input_required` 时建输入请求;续跑时读该调用的各轮输入请求。 */
|
|
250
253
|
readonly questions: Pick<QuestionsService, "ask" | "forCall">;
|
|
251
254
|
readonly log: Logger;
|
|
@@ -402,6 +405,7 @@ export type ExecOutcome =
|
|
|
402
405
|
result: unknown;
|
|
403
406
|
blocked?: ServiceBlocked;
|
|
404
407
|
review?: ReviewRecord;
|
|
408
|
+
siteAccess?: ReportedSiteAccess;
|
|
405
409
|
}
|
|
406
410
|
/**
|
|
407
411
|
* The handler needs the user's input (the form is not validated yet). `review` and `blocked`:
|
|
@@ -424,6 +428,7 @@ export type ExecOutcome =
|
|
|
424
428
|
message: string;
|
|
425
429
|
blocked?: ServiceBlocked;
|
|
426
430
|
review?: ReviewRecord;
|
|
431
|
+
siteAccess?: ReportedSiteAccess;
|
|
427
432
|
}
|
|
428
433
|
/** 发起人未连接个人凭据:除错误结果外再写 `connection_required`。 */
|
|
429
434
|
| {
|
|
@@ -605,13 +610,15 @@ export declare class ToolPipeline {
|
|
|
605
610
|
private readonly loopbackGrants?;
|
|
606
611
|
/** The device's sandbox and its provider's support a loopback grant is checked against. */
|
|
607
612
|
private readonly permissionFacts?;
|
|
613
|
+
private readonly siteGrants?;
|
|
614
|
+
private readonly extensions?;
|
|
608
615
|
private readonly decide;
|
|
609
616
|
private readonly deps;
|
|
610
617
|
constructor(kdb: KernelDb, eventLog: EventLog,
|
|
611
618
|
/** The `Agent` tool's sub-agent dispatch; absent (tests): `Agent` calls are refused. */
|
|
612
619
|
subagents: Pick<SubagentsService, "dispatch"> | undefined,
|
|
613
620
|
/** The message tools between agents; absent (tests): their calls are refused. */
|
|
614
|
-
messages: Pick<SubagentMessages, "toChild" | "toParent"> | undefined, registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler" | "watcher">, credentials: Pick<Credentials, "injection" | "onUnauthorized">, breaker: Pick<Breaker, "check" | "failure" | "success">, outputs: Pick<ToolOutputs, "save" | "load">, approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "requestLoopback" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">, questions: Pick<QuestionsService, "ask" | "forCall">, config: Pick<KernelConfigService, "get">, log: Logger & Partial<Pick<KernelLogger, "debug">>,
|
|
621
|
+
messages: Pick<SubagentMessages, "toChild" | "toParent"> | undefined, registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler" | "watcher">, credentials: Pick<Credentials, "injection" | "onUnauthorized">, breaker: Pick<Breaker, "check" | "failure" | "success">, outputs: Pick<ToolOutputs, "save" | "load">, approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "requestLoopback" | "requestSiteAccess" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">, questions: Pick<QuestionsService, "ask" | "forCall">, config: Pick<KernelConfigService, "get">, log: Logger & Partial<Pick<KernelLogger, "debug">>,
|
|
615
622
|
/** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
|
|
616
623
|
host: Pick<ExtensionHost, "hooks" | "current"> | undefined, drift: Pick<ToolDrift, "onToolsChanged"> | undefined, effective: Pick<EffectiveConfigs, "get">, switches: Pick<OrgToolSwitches, "isToolOff">, txHost: TransactionHost, hooks?: ToolPipelineHooks, networkGrants?: {
|
|
617
624
|
runState(runId: string, deviceId?: string): Promise<NetworkRunState>;
|
|
@@ -642,7 +649,7 @@ export declare class ToolPipeline {
|
|
|
642
649
|
*/
|
|
643
650
|
loopbackGrants?: Pick<LoopbackGrants, "grantIn" | "forCall" | "liveForRoot"> | undefined,
|
|
644
651
|
/** The device's sandbox and its provider's support a loopback grant is checked against. */
|
|
645
|
-
permissionFacts?: Pick<PermissionFacts, "deviceSandboxFacts"> | undefined);
|
|
652
|
+
permissionFacts?: Pick<PermissionFacts, "deviceSandboxFacts"> | undefined, siteGrants?: DeviceSiteGrants | undefined, extensions?: Pick<ExtensionRegistry, "current"> | undefined);
|
|
646
653
|
/**
|
|
647
654
|
* tools 节点:按顺序处理本步 assistant 消息里的全部 `tool_call`,每个调用都以一条 `tool_result` 结束
|
|
648
655
|
* (之后才回到 prepare 构建下一次请求,保持「已记录调用、未记录结果之间不构建请求」的不变式)。
|
|
@@ -758,6 +765,10 @@ export declare class ToolPipeline {
|
|
|
758
765
|
* pipeline, no facts): the host stays an address host with its note.
|
|
759
766
|
*/
|
|
760
767
|
private loopbackBlocked;
|
|
768
|
+
private siteRetryAllowed;
|
|
769
|
+
private siteReviewFacts;
|
|
770
|
+
private siteRerunOf;
|
|
771
|
+
private handleSiteAccess;
|
|
761
772
|
/**
|
|
762
773
|
* A loopback port grant to this call's attempt and what goes with it, in one transaction: the
|
|
763
774
|
* grant first (it reads the root conversation `FOR SHARE`, before the conversation row the
|
|
@@ -831,7 +842,7 @@ export declare class ToolPipeline {
|
|
|
831
842
|
/** The automatic decision the call runs under instead of an approval (builtins only, R2). */
|
|
832
843
|
decision?: BuiltinCallContext["decision"],
|
|
833
844
|
/** The submitted secure input request of this call (builtins only, R4). */
|
|
834
|
-
secureInputId?: string): Promise<ExecOutcome>;
|
|
845
|
+
secureInputId?: string, siteAccess?: SiteAccessApproval): Promise<ExecOutcome>;
|
|
835
846
|
private executeConnector;
|
|
836
847
|
/** 抛出的错误 → 给模型的结果:ToolError 的消息原样(插件约定为英文、可操作),其他只给错误类名。 */
|
|
837
848
|
private thrown;
|