@capybara-hq/kernel 0.1.0-rc.77 → 0.1.0-rc.78
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/bootstrap.json +6 -6
- package/dist/admin/outbox-dead.service.js +4 -1
- package/dist/agents/admin-agents.js +2 -0
- package/dist/agents/agent-lookup.js +4 -0
- package/dist/agents/agent-profile.service.js +3 -0
- package/dist/agents/agents.service.js +7 -0
- package/dist/agents/org-templates.js +1 -0
- package/dist/agents/pending-connector-requests.js +6 -0
- package/dist/agents/pending-connectors.service.js +2 -0
- package/dist/agents/readiness.service.d.ts +9 -3
- package/dist/agents/readiness.service.js +3 -3
- package/dist/agents/templates.js +1 -0
- package/dist/background/finish.js +3 -0
- package/dist/background/stop.js +2 -0
- package/dist/background/store.js +44 -0
- package/dist/background/tasks.service.js +3 -2
- package/dist/background/wake-rules.js +1 -0
- package/dist/catalog/admin-catalog.controller.d.ts +6 -0
- package/dist/catalog/admin-catalog.controller.js +13 -0
- package/dist/catalog/catalog-content.d.ts +6 -0
- package/dist/catalog/catalog-content.js +1 -0
- package/dist/catalog/catalog-items.js +4 -0
- package/dist/catalog/catalog-scope.service.js +4 -1
- package/dist/catalog/component-promotion.js +2 -0
- package/dist/catalog/component-scope.controller.d.ts +9 -15
- package/dist/catalog/component-scope.controller.js +14 -9
- package/dist/catalog/component-scope.service.js +5 -0
- package/dist/catalog/component-state.js +2 -0
- package/dist/catalog/marketplaces.service.d.ts +6 -1
- package/dist/catalog/marketplaces.service.js +8 -3
- package/dist/catalog/org-catalog.controller.d.ts +9 -0
- package/dist/catalog/org-catalog.controller.js +18 -0
- package/dist/catalog/org-catalog.schemas.d.ts +2 -4
- package/dist/catalog/org-catalog.schemas.js +2 -3
- package/dist/catalog/org-catalog.service.d.ts +10 -1
- package/dist/catalog/org-catalog.service.js +34 -23
- package/dist/catalog/org-extension-switch.d.ts +3 -10
- package/dist/catalog/org-extension-switch.js +14 -60
- package/dist/catalog/org-extension.controller.d.ts +6 -7
- package/dist/catalog/org-extension.controller.js +4 -4
- package/dist/catalog/org-extension.schemas.d.ts +1 -2
- package/dist/catalog/org-extension.schemas.js +1 -3
- package/dist/catalog/owned-items.js +10 -1
- package/dist/catalog/ownership.js +2 -0
- package/dist/catalog/plugin-import.js +8 -0
- package/dist/catalog/plugin-install.d.ts +1 -4
- package/dist/catalog/plugin-install.js +11 -12
- package/dist/catalog/plugin-upgrade.js +4 -1
- package/dist/catalog/request-rules.js +6 -0
- package/dist/catalog/requests.service.js +4 -0
- package/dist/catalog/scope-orgs.js +1 -0
- package/dist/catalog/scope-sync.d.ts +8 -5
- package/dist/catalog/scope-sync.js +21 -23
- package/dist/catalog/unshare.js +3 -0
- package/dist/channels/connections.service.js +1 -0
- package/dist/channels/inbound.js +1 -0
- package/dist/channels/jobs.js +1 -0
- package/dist/channels/outbound.js +6 -0
- package/dist/channels/supervisor.js +1 -0
- package/dist/channels/threads.js +1 -0
- package/dist/client/client-reports.service.js +1 -0
- package/dist/config/fields.js +20 -4
- package/dist/conversations/access.js +1 -0
- package/dist/conversations/attachments.service.js +16 -4
- package/dist/conversations/conversations.service.js +17 -3
- package/dist/conversations/event-log.js +2 -0
- package/dist/conversations/events.d.ts +1 -0
- package/dist/conversations/events.js +3 -1
- package/dist/conversations/files.js +3 -2
- package/dist/conversations/permission-profiles.service.js +1 -0
- package/dist/conversations/prompt-suggestions.js +2 -0
- package/dist/conversations/queue.js +8 -0
- package/dist/conversations/queue.service.js +6 -2
- package/dist/conversations/source.js +2 -0
- package/dist/conversations/titles.js +10 -2
- package/dist/conversations/tree.js +6 -0
- package/dist/db/kernel-schema.d.ts +3 -1
- package/dist/devices/conversation-devices.js +3 -0
- package/dist/devices/device-projects.service.js +2 -0
- package/dist/devices/devices.service.js +5 -0
- package/dist/devices/legacy-cleanup.job.js +5 -2
- package/dist/dial-in/handlers.js +2 -0
- package/dist/dial-in/machines.js +11 -2
- package/dist/dial-in/targets.d.ts +0 -2
- package/dist/dial-in/targets.js +0 -10
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/evals/budget.js +14 -1
- package/dist/evals/run-replay.js +4 -0
- package/dist/evals/runs.service.js +13 -7
- package/dist/evals/sets.service.js +23 -8
- package/dist/evals/trajectory.service.d.ts +1 -1
- package/dist/evals/trajectory.service.js +1 -0
- package/dist/evals/worker.js +5 -1
- package/dist/extensions/admin-ops.js +1 -0
- package/dist/extensions/admin-view.js +3 -1
- package/dist/extensions/bootstrap-packages.d.ts +12 -1
- package/dist/extensions/bootstrap-packages.js +49 -9
- package/dist/extensions/bootstrap.d.ts +17 -2
- package/dist/extensions/bootstrap.js +41 -9
- package/dist/extensions/config-json-schema.d.ts +2 -2
- package/dist/extensions/config-json-schema.js +1 -3
- package/dist/extensions/deployment-config.d.ts +5 -3
- package/dist/extensions/deployment-config.js +3 -3
- package/dist/extensions/effective-config.d.ts +8 -7
- package/dist/extensions/effective-config.js +8 -7
- package/dist/extensions/enabled.js +1 -0
- package/dist/extensions/host.d.ts +4 -3
- package/dist/extensions/host.js +11 -12
- package/dist/extensions/instance.d.ts +1 -1
- package/dist/extensions/instance.js +17 -2
- package/dist/extensions/org-config.d.ts +35 -97
- package/dist/extensions/org-config.js +48 -315
- package/dist/extensions/org-levels.d.ts +22 -9
- package/dist/extensions/org-levels.js +100 -20
- package/dist/extensions/org-overrides.d.ts +14 -15
- package/dist/extensions/org-overrides.js +20 -20
- package/dist/extensions/package.js +1 -1
- package/dist/extensions/permission-set.d.ts +1 -3
- package/dist/extensions/permission-set.js +3 -7
- package/dist/extensions/permission-view.d.ts +3 -1
- package/dist/extensions/permission-view.js +5 -4
- package/dist/extensions/plugin-icons.d.ts +72 -1
- package/dist/extensions/plugin-icons.js +194 -2
- package/dist/extensions/point-defaults.d.ts +17 -18
- package/dist/extensions/point-defaults.js +25 -28
- package/dist/identity/accounts.js +6 -0
- package/dist/identity/api-tokens.js +8 -0
- package/dist/infra/outbox/outbox.dispatcher.js +4 -1
- package/dist/infra/outbox/outbox.service.js +2 -0
- package/dist/orgs/directory-sync.d.ts +9 -6
- package/dist/orgs/directory-sync.js +15 -12
- package/dist/orgs/invitations.service.js +2 -0
- package/dist/orgs/members.service.js +2 -0
- package/dist/orgs/offboarding.js +2 -0
- package/dist/packages/npm.d.ts +9 -1
- package/dist/packages/npm.js +37 -5
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin-items.ops.js +1 -0
- package/dist/platform/ops/agents.ops.js +1 -0
- package/dist/platform/ops/extensions.ops.d.ts +6 -8
- package/dist/platform/ops/extensions.ops.js +18 -97
- package/dist/platform/ops/org-plugins.ops.d.ts +3 -6
- package/dist/platform/ops/org-plugins.ops.js +14 -65
- package/dist/platform/ops/outbox.ops.js +1 -0
- package/dist/platform/ops/person-inputs.d.ts +0 -4
- package/dist/platform/ops/person-inputs.js +0 -8
- package/dist/platform/ops/plugins.ops.d.ts +4 -1
- package/dist/platform/ops/plugins.ops.js +27 -34
- package/dist/platform/person-fields.d.ts +1 -1
- package/dist/platform/person-fields.js +1 -1
- package/dist/platform/sealed-reveals.js +2 -0
- package/dist/push/recipients.js +9 -2
- package/dist/runtime/permission-context.service.js +1 -0
- package/dist/runtime/plugin-context.service.js +1 -0
- package/dist/runtime/project/knowledge.service.js +1 -0
- package/dist/runtime/run-context.service.js +1 -0
- package/dist/runtime/run-deletion.js +4 -0
- package/dist/runtime/run-execution.js +2 -0
- package/dist/runtime/run-finish.js +3 -0
- package/dist/runtime/run-jobs.js +3 -0
- package/dist/runtime/run-orphan-check.job.js +7 -0
- package/dist/runtime/run-queue.js +21 -2
- package/dist/runtime/run-worker.js +5 -0
- package/dist/runtime/step-log.js +1 -0
- package/dist/runtime/subagents/child.js +2 -0
- package/dist/runtime/subagents/deliveries.js +3 -0
- package/dist/runtime/subagents/dispatch.js +5 -1
- package/dist/runtime/subagents/messages.js +2 -0
- package/dist/runtime/subagents/org-agents.d.ts +1 -1
- package/dist/runtime/subagents/org-agents.js +2 -1
- package/dist/runtime/usage-report-jobs.js +1 -0
- package/dist/runtime/usage-report.js +3 -0
- package/dist/runtime/waits.js +5 -0
- package/dist/sandbox/cloud-permission-snapshot.js +9 -3
- package/dist/sandbox/device-reports.js +3 -0
- package/dist/sandbox/legacy-retirement.js +5 -1
- package/dist/sandbox/managed-device-context.js +1 -0
- package/dist/sandbox/modes.d.ts +5 -2
- package/dist/sandbox/modes.js +8 -4
- package/dist/sandbox/network-grants.js +2 -0
- package/dist/sandbox/operation-intents.js +58 -0
- package/dist/sandbox/operation-reconcile.job.js +2 -0
- package/dist/sandbox/permission-authority-lock.js +12 -6
- package/dist/sandbox/permission-call-grants.js +6 -0
- package/dist/sandbox/permission-ceiling-writes.js +5 -0
- package/dist/sandbox/permission-config-publication.js +5 -0
- package/dist/sandbox/permission-instance-writes.js +4 -0
- package/dist/sandbox/permission-runtime-reports.js +10 -1
- package/dist/sandbox/permission-transitions.js +3 -0
- package/dist/sandbox/review/review.service.js +8 -5
- package/dist/sandbox/sandbox.service.d.ts +14 -0
- package/dist/sandbox/sandbox.service.js +195 -29
- package/dist/sandbox/unreachable.js +4 -1
- package/dist/schedules/fire.js +9 -3
- package/dist/schedules/pause.js +2 -0
- package/dist/schedules/run-tracker.js +16 -1
- package/dist/schedules/scheduled-tasks.service.js +4 -2
- package/dist/schedules/store.js +8 -0
- package/dist/schedules/unattended.js +4 -0
- package/dist/setup/setup-checks.service.d.ts +1 -10
- package/dist/setup/setup-checks.service.js +19 -29
- package/dist/shares/share-open.service.js +1 -0
- package/dist/shares/shares.service.js +2 -0
- package/dist/skills/agent-skills.service.d.ts +1 -1
- package/dist/skills/agent-skills.service.js +13 -2
- package/dist/skills/catalog.js +3 -0
- package/dist/skills/changes.service.js +10 -2
- package/dist/skills/conversation-catalog.js +1 -0
- package/dist/skills/skills.service.js +4 -0
- package/dist/tools/approvals.service.js +40 -0
- package/dist/tools/builtins/schedules.js +11 -6
- package/dist/tools/builtins/web/fetch.js +1 -1
- package/dist/tools/builtins/web/search.js +1 -1
- package/dist/tools/connector-account-policies.js +3 -0
- package/dist/tools/connectors.controller.d.ts +20 -8
- package/dist/tools/connectors.controller.js +30 -12
- package/dist/tools/connectors.service.d.ts +8 -0
- package/dist/tools/connectors.service.js +21 -1
- package/dist/tools/drift.js +5 -0
- package/dist/tools/git-push-policy.js +3 -0
- package/dist/tools/oauth/flow.js +1 -0
- package/dist/tools/outputs.js +2 -0
- package/dist/tools/permission-approval-jobs.js +3 -0
- package/dist/tools/pipeline.js +2 -0
- package/dist/tools/policy.js +3 -0
- package/dist/tools/questions.service.js +13 -0
- package/package.json +3 -3
|
@@ -277,6 +277,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
277
277
|
.selectFrom("conversations")
|
|
278
278
|
.select("id")
|
|
279
279
|
.where("id", "=", input.conversationId)
|
|
280
|
+
.where("org_id", "=", input.orgId)
|
|
280
281
|
.forUpdate()
|
|
281
282
|
.execute();
|
|
282
283
|
await t
|
|
@@ -306,6 +307,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
306
307
|
const row = await t
|
|
307
308
|
.selectFrom("approvals")
|
|
308
309
|
.selectAll()
|
|
310
|
+
.where("org_id", "=", input.orgId)
|
|
309
311
|
.where("run_id", "=", input.runId)
|
|
310
312
|
.where("call_id", "=", input.callId)
|
|
311
313
|
.where("attempt", "=", input.attempt ?? 1)
|
|
@@ -359,6 +361,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
359
361
|
.selectFrom("conversations")
|
|
360
362
|
.select("id")
|
|
361
363
|
.where("id", "=", input.conversationId)
|
|
364
|
+
.where("org_id", "=", input.orgId)
|
|
362
365
|
.forUpdate()
|
|
363
366
|
.execute();
|
|
364
367
|
const detail = { personFields: input.personFields, target: input.target };
|
|
@@ -391,6 +394,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
391
394
|
const row = await t
|
|
392
395
|
.selectFrom("approvals")
|
|
393
396
|
.selectAll()
|
|
397
|
+
.where("org_id", "=", input.orgId)
|
|
394
398
|
.where("run_id", "=", input.runId)
|
|
395
399
|
.where("call_id", "=", input.callId)
|
|
396
400
|
.where("attempt", "=", input.attempt)
|
|
@@ -457,6 +461,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
457
461
|
.selectFrom("conversations")
|
|
458
462
|
.select("id")
|
|
459
463
|
.where("id", "=", input.conversationId)
|
|
464
|
+
.where("org_id", "=", input.orgId)
|
|
460
465
|
.forUpdate()
|
|
461
466
|
.execute();
|
|
462
467
|
// only the device's owner is ever asked: never another account the caller names
|
|
@@ -470,6 +475,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
470
475
|
const last = await t
|
|
471
476
|
.selectFrom("approvals")
|
|
472
477
|
.select(sql `max(attempt)`.as("attempt"))
|
|
478
|
+
.where("org_id", "=", input.orgId)
|
|
473
479
|
.where("run_id", "=", input.runId)
|
|
474
480
|
.where("call_id", "=", input.callId)
|
|
475
481
|
.executeTakeFirst();
|
|
@@ -552,6 +558,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
552
558
|
.selectFrom("conversations")
|
|
553
559
|
.select("id")
|
|
554
560
|
.where("id", "=", input.conversationId)
|
|
561
|
+
.where("org_id", "=", input.orgId)
|
|
555
562
|
.forUpdate()
|
|
556
563
|
.execute();
|
|
557
564
|
// only a member of the org is asked, and only about a live connector of the org
|
|
@@ -572,6 +579,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
572
579
|
const last = await t
|
|
573
580
|
.selectFrom("approvals")
|
|
574
581
|
.select(sql `max(attempt)`.as("attempt"))
|
|
582
|
+
.where("org_id", "=", input.orgId)
|
|
575
583
|
.where("run_id", "=", input.runId)
|
|
576
584
|
.where("call_id", "=", input.callId)
|
|
577
585
|
.executeTakeFirst();
|
|
@@ -668,6 +676,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
668
676
|
.selectFrom("conversations")
|
|
669
677
|
.select("id")
|
|
670
678
|
.where("id", "=", input.conversationId)
|
|
679
|
+
.where("org_id", "=", input.orgId)
|
|
671
680
|
.forUpdate()
|
|
672
681
|
.execute();
|
|
673
682
|
// only the device's owner is ever asked: never another account the caller names
|
|
@@ -685,6 +694,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
685
694
|
const last = await t
|
|
686
695
|
.selectFrom("approvals")
|
|
687
696
|
.select(sql `max(attempt)`.as("attempt"))
|
|
697
|
+
.where("org_id", "=", input.orgId)
|
|
688
698
|
.where("run_id", "=", input.runId)
|
|
689
699
|
.where("call_id", "=", input.callId)
|
|
690
700
|
.executeTakeFirst();
|
|
@@ -1216,6 +1226,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1216
1226
|
}),
|
|
1217
1227
|
})
|
|
1218
1228
|
.where("id", "=", id)
|
|
1229
|
+
.where("org_id", "=", orgId)
|
|
1219
1230
|
.execute();
|
|
1220
1231
|
return { leaked };
|
|
1221
1232
|
}
|
|
@@ -1277,6 +1288,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1277
1288
|
}),
|
|
1278
1289
|
})
|
|
1279
1290
|
.where("id", "=", id)
|
|
1291
|
+
.where("org_id", "=", orgId)
|
|
1280
1292
|
.returningAll()
|
|
1281
1293
|
.executeTakeFirstOrThrow();
|
|
1282
1294
|
if (approved && before.command?.permissionCandidate) {
|
|
@@ -1483,6 +1495,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1483
1495
|
.leftJoin("agent_versions as v", (j) => j.onRef("v.agent_id", "=", "ag.id").onRef("v.version", "=", "ag.current_version"))
|
|
1484
1496
|
.select(["s.account_id", "v.definition"])
|
|
1485
1497
|
.where("s.id", "=", served.taskId)
|
|
1498
|
+
.where("s.org_id", "=", a.orgId)
|
|
1486
1499
|
.where("s.deleted_at", "is", null)
|
|
1487
1500
|
.executeTakeFirst();
|
|
1488
1501
|
if (task?.account_id !== decidedBy)
|
|
@@ -1612,6 +1625,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1612
1625
|
* 详情,不做处理人校验(内核内部用:渠道出站投递组装 IM 审批卡片);不存在返回 null。
|
|
1613
1626
|
* 不得直接回给请求方——HTTP 接口用 {@link get}。
|
|
1614
1627
|
*/
|
|
1628
|
+
// org-filter: approvalId comes from an approval event payload in the conversation's own event
|
|
1629
|
+
// log (channel outbound cards), kernel-written, never caller input
|
|
1615
1630
|
async describe(id) {
|
|
1616
1631
|
const row = await this.db
|
|
1617
1632
|
.selectFrom("approvals")
|
|
@@ -1624,6 +1639,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1624
1639
|
return view ?? null;
|
|
1625
1640
|
}
|
|
1626
1641
|
/** 某个工具调用最近一次的工具审批(attempt 最大者,网络询问除外);没有则返回 null。 */
|
|
1642
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
1643
|
+
// never caller input
|
|
1627
1644
|
async forCall(runId, callId) {
|
|
1628
1645
|
const row = await this.db
|
|
1629
1646
|
.selectFrom("approvals")
|
|
@@ -1637,6 +1654,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1637
1654
|
return row ? toRecord(row) : null;
|
|
1638
1655
|
}
|
|
1639
1656
|
/** The latest secure input request of a tool call (highest attempt); null when it has none. */
|
|
1657
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
1658
|
+
// never caller input
|
|
1640
1659
|
async secureInputForCall(runId, callId) {
|
|
1641
1660
|
const row = await this.db
|
|
1642
1661
|
.selectFrom("approvals")
|
|
@@ -1650,6 +1669,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1650
1669
|
return row ? toRecord(row) : null;
|
|
1651
1670
|
}
|
|
1652
1671
|
/** The network ask of a tool call (at most one per call); null when it has none. */
|
|
1672
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
1673
|
+
// never caller input
|
|
1653
1674
|
async networkForCall(runId, callId) {
|
|
1654
1675
|
const row = await this.db
|
|
1655
1676
|
.selectFrom("approvals")
|
|
@@ -1663,6 +1684,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1663
1684
|
return row ? toRecord(row) : null;
|
|
1664
1685
|
}
|
|
1665
1686
|
/** The git push ask of a tool call (at most one per call); null when it has none. */
|
|
1687
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
1688
|
+
// never caller input
|
|
1666
1689
|
async gitForCall(runId, callId) {
|
|
1667
1690
|
const row = await this.db
|
|
1668
1691
|
.selectFrom("approvals")
|
|
@@ -1676,6 +1699,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1676
1699
|
return row ? toRecord(row) : null;
|
|
1677
1700
|
}
|
|
1678
1701
|
/** The command review ask of a tool call (at most one per call); null when it has none. */
|
|
1702
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
1703
|
+
// never caller input
|
|
1679
1704
|
async commandForCall(runId, callId) {
|
|
1680
1705
|
const row = await this.db
|
|
1681
1706
|
.selectFrom("approvals")
|
|
@@ -1700,6 +1725,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1700
1725
|
}
|
|
1701
1726
|
return r.record ? { outcome: r.outcome, record: r.record } : { outcome: r.outcome };
|
|
1702
1727
|
}
|
|
1728
|
+
// org-filter: id is the approval of the kernel-written timeout job payload (Waits), not caller input
|
|
1703
1729
|
async expireIn(id) {
|
|
1704
1730
|
const t = this.db.db;
|
|
1705
1731
|
if (!(await this.lockConversationOf(id)))
|
|
@@ -1731,6 +1757,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1731
1757
|
* 在调用方的事务内(`mandatory`)取消运行的全部 pending 审批(运行在等待中被中止),各写
|
|
1732
1758
|
* `approval_decided{cancelled}`(处理人为 null)。返回被取消的记录;调用方提交后发布事件。
|
|
1733
1759
|
*/
|
|
1760
|
+
// org-filter: runId is the run the kernel is stopping or finishing (Waits, RunFinish), not caller
|
|
1761
|
+
// input
|
|
1734
1762
|
async cancelPendingIn(runId) {
|
|
1735
1763
|
const t = this.db.db;
|
|
1736
1764
|
const rows = await t
|
|
@@ -1802,6 +1830,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1802
1830
|
.updateTable("approvals")
|
|
1803
1831
|
.set({ status: "cancelled", decided_at: sql `now()` })
|
|
1804
1832
|
.where("id", "=", row.id)
|
|
1833
|
+
.where("org_id", "=", orgId)
|
|
1805
1834
|
.returningAll()
|
|
1806
1835
|
.executeTakeFirstOrThrow();
|
|
1807
1836
|
const seq = await this.decidedEvent(toRecord(row), "cancelled");
|
|
@@ -1823,6 +1852,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1823
1852
|
* and emits the domain event `approval.decided{skipped}` after the commit (its IM card update is
|
|
1824
1853
|
* owed by the append, transactional outbox spec §8.1).
|
|
1825
1854
|
*/
|
|
1855
|
+
// org-filter: conversationId is the conversation the caller wrote the author's message in and
|
|
1856
|
+
// holds locked (ConversationsService, checked in its org); the tree is its sub-agents'
|
|
1857
|
+
// conversations, and every row below is read from that tree
|
|
1826
1858
|
async skipNetworkIn(conversationId, authorAccountId) {
|
|
1827
1859
|
const t = this.db.db;
|
|
1828
1860
|
const tree = await this.subtreeOf(conversationId);
|
|
@@ -1880,6 +1912,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1880
1912
|
const row = await q.executeTakeFirst();
|
|
1881
1913
|
if (!row)
|
|
1882
1914
|
return false;
|
|
1915
|
+
// org-filter: the conversation of the approval row read just above (org-filtered when the
|
|
1916
|
+
// caller passes orgId; otherwise a kernel-written approval id, see expireIn)
|
|
1883
1917
|
await t
|
|
1884
1918
|
.selectFrom("conversations")
|
|
1885
1919
|
.select("id")
|
|
@@ -1893,6 +1927,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1893
1927
|
const found = [...new Set((await ids.execute()).map((r) => r.conversation_id))];
|
|
1894
1928
|
if (found.length === 0)
|
|
1895
1929
|
return [];
|
|
1930
|
+
// org-filter: the ids come from the caller's query over approvals of a conversation tree it
|
|
1931
|
+
// already holds (skipNetworkIn)
|
|
1896
1932
|
const rows = await this.db.db
|
|
1897
1933
|
.selectFrom("conversations")
|
|
1898
1934
|
.select("id")
|
|
@@ -1903,6 +1939,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1903
1939
|
return rows.map((r) => r.id);
|
|
1904
1940
|
}
|
|
1905
1941
|
/** `conversationId` and its sub-agents' conversations at any depth (at most 16 levels). */
|
|
1942
|
+
// org-filter: sub-agent conversations live in their parent's org; the root is the caller's
|
|
1906
1943
|
async subtreeOf(conversationId) {
|
|
1907
1944
|
const all = [conversationId];
|
|
1908
1945
|
let level = [conversationId];
|
|
@@ -1984,6 +2021,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1984
2021
|
return m?.role ?? null;
|
|
1985
2022
|
}
|
|
1986
2023
|
/** agent id → 当前版本定义里的名字。 */
|
|
2024
|
+
// org-filter: the agent ids come from the conversations of approval rows the callers already
|
|
2025
|
+
// read in their org (views)
|
|
1987
2026
|
async agentNames(ids) {
|
|
1988
2027
|
if (ids.length === 0)
|
|
1989
2028
|
return new Map();
|
|
@@ -2027,6 +2066,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
2027
2066
|
const connectorIds = [
|
|
2028
2067
|
...new Set(recs.flatMap((r) => (r.connectorId === null ? [] : [r.connectorId]))),
|
|
2029
2068
|
];
|
|
2069
|
+
// org-filter: connector ids from approval rows the callers already read in their org
|
|
2030
2070
|
const apps = connectorIds.length === 0
|
|
2031
2071
|
? []
|
|
2032
2072
|
: await db
|
|
@@ -366,19 +366,23 @@ const normalizedChat = (chat) => ({
|
|
|
366
366
|
chatId: chat.chatId,
|
|
367
367
|
chatType: chat.chatType ?? "dm",
|
|
368
368
|
});
|
|
369
|
-
/**
|
|
370
|
-
|
|
369
|
+
/**
|
|
370
|
+
* A chat target with its connection's name for the words. The connection id may come from the
|
|
371
|
+
* model's tool input: only a connection of `orgId` lends its name (another org's id shows as is).
|
|
372
|
+
*/
|
|
373
|
+
async function chatTargetOf(db, orgId, chat) {
|
|
371
374
|
const c = await db
|
|
372
375
|
.selectFrom("channel_connections")
|
|
373
376
|
.select("name")
|
|
374
377
|
.where("id", "=", chat.connectionId)
|
|
378
|
+
.where("org_id", "=", orgId)
|
|
375
379
|
.executeTakeFirst();
|
|
376
380
|
return { mode: "chat", chat, connectionName: c?.name ?? chat.connectionId };
|
|
377
381
|
}
|
|
378
382
|
/** A stored task's target; a chat's connection name is read for the words. */
|
|
379
383
|
async function storedTarget(db, task) {
|
|
380
384
|
if (task.mode === "chat" && task.chat !== null)
|
|
381
|
-
return chatTargetOf(db, task.chat);
|
|
385
|
+
return chatTargetOf(db, task.orgId, task.chat);
|
|
382
386
|
if (task.mode === "conversation" && task.conversationId !== null) {
|
|
383
387
|
return { mode: "conversation", conversationId: task.conversationId };
|
|
384
388
|
}
|
|
@@ -552,6 +556,7 @@ export function scheduleTools(deps) {
|
|
|
552
556
|
.db()
|
|
553
557
|
.selectFrom("approvals")
|
|
554
558
|
.select("summary")
|
|
559
|
+
.where("org_id", "=", ctx.orgId)
|
|
555
560
|
.where("run_id", "=", ctx.runId)
|
|
556
561
|
.where("call_id", "=", ctx.callId)
|
|
557
562
|
.where("status", "=", "approved")
|
|
@@ -594,7 +599,7 @@ export function scheduleTools(deps) {
|
|
|
594
599
|
const target = input.mode === "here"
|
|
595
600
|
? await hereTarget(deps.db(), ctx.orgId, ctx.accountId, ctx.conversationId)
|
|
596
601
|
: input.mode === "chat"
|
|
597
|
-
? await chatTargetOf(deps.db(), normalizedChat(input.chat))
|
|
602
|
+
? await chatTargetOf(deps.db(), ctx.orgId, normalizedChat(input.chat))
|
|
598
603
|
: { mode: "new" };
|
|
599
604
|
return {
|
|
600
605
|
trigger,
|
|
@@ -709,7 +714,7 @@ export function scheduleTools(deps) {
|
|
|
709
714
|
const after = input.mode === "here"
|
|
710
715
|
? await hereTarget(db, ctx.orgId, ctx.accountId, ctx.conversationId)
|
|
711
716
|
: input.mode === "chat"
|
|
712
|
-
? await chatTargetOf(db, normalizedChat(input.chat))
|
|
717
|
+
? await chatTargetOf(db, ctx.orgId, normalizedChat(input.chat))
|
|
713
718
|
: { mode: "new" };
|
|
714
719
|
if (!sameTarget(before, after)) {
|
|
715
720
|
const b = targetWords(before, ctx.conversationId);
|
|
@@ -814,7 +819,7 @@ export function scheduleTools(deps) {
|
|
|
814
819
|
const target = input.mode === "here"
|
|
815
820
|
? await hereTarget(deps.db(), ctx.orgId, ctx.accountId, ctx.conversationId)
|
|
816
821
|
: input.mode === "chat"
|
|
817
|
-
? await chatTargetOf(deps.db(), normalizedChat(input.chat))
|
|
822
|
+
? await chatTargetOf(deps.db(), ctx.orgId, normalizedChat(input.chat))
|
|
818
823
|
: { mode: "new" };
|
|
819
824
|
const f = targetFields(target);
|
|
820
825
|
patch.mode = f.mode;
|
|
@@ -182,8 +182,8 @@ export function webSearchTool(deps) {
|
|
|
182
182
|
...(allowed !== undefined && allowed.length > 0 && { allowedDomains: allowed }),
|
|
183
183
|
...(blocked !== undefined && blocked.length > 0 && { blockedDomains: blocked }),
|
|
184
184
|
maxResults: max,
|
|
185
|
-
orgConfig: resolved.orgConfig,
|
|
186
185
|
config: resolved.config,
|
|
186
|
+
orgId: ctx.orgId,
|
|
187
187
|
signal: ctx.signal,
|
|
188
188
|
});
|
|
189
189
|
results = Array.isArray(out?.results) ? out.results : [];
|
|
@@ -67,6 +67,7 @@ let ConnectorAccountPolicies = class ConnectorAccountPolicies {
|
|
|
67
67
|
const mine = new Map((await this.db
|
|
68
68
|
.selectFrom("connector_tool_account_policies")
|
|
69
69
|
.select(["tool_name", "policy"])
|
|
70
|
+
.where("org_id", "=", orgId)
|
|
70
71
|
.where("connector_id", "=", connectorId)
|
|
71
72
|
.where("account_id", "=", accountId)
|
|
72
73
|
.execute()).map((r) => [r.tool_name, r.policy]));
|
|
@@ -98,6 +99,7 @@ let ConnectorAccountPolicies = class ConnectorAccountPolicies {
|
|
|
98
99
|
const rows = await this.db
|
|
99
100
|
.selectFrom("connector_tool_account_policies")
|
|
100
101
|
.select(["tool_name", "policy"])
|
|
102
|
+
.where("org_id", "=", orgId)
|
|
101
103
|
.where("connector_id", "=", connectorId)
|
|
102
104
|
.where("account_id", "=", accountId)
|
|
103
105
|
.where(sql `starts_with(tool_name, ${GIT_PUSH_PREFIX})`)
|
|
@@ -154,6 +156,7 @@ let ConnectorAccountPolicies = class ConnectorAccountPolicies {
|
|
|
154
156
|
if (cleared.length > 0) {
|
|
155
157
|
await this.db
|
|
156
158
|
.deleteFrom("connector_tool_account_policies")
|
|
159
|
+
.where("org_id", "=", orgId)
|
|
157
160
|
.where("connector_id", "=", connectorId)
|
|
158
161
|
.where("account_id", "=", accountId)
|
|
159
162
|
.where("tool_name", "in", cleared)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FastifyReply } from "fastify";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import type { ConnectionGuideState } from "../extensions/plugin-guides.js";
|
|
3
4
|
import { PluginIcons } from "../extensions/plugin-icons.js";
|
|
@@ -180,9 +181,9 @@ interface MemberPolicySheet {
|
|
|
180
181
|
gitPush: MemberGitPushView | null;
|
|
181
182
|
}
|
|
182
183
|
/**
|
|
183
|
-
* A connector as the org's pages show it: with its plugin's icon (`icon`, see
|
|
184
|
-
* template's setup guide and the drift since it was set up (`setupGuide`,
|
|
185
|
-
* 2026-11-09-setup-guides-v2-design.md §9.3, §11).
|
|
184
|
+
* A connector as the org's pages show it: with its template's or plugin's icon (`icon`, see
|
|
185
|
+
* `withIcons`), its template's setup guide and the drift since it was set up (`setupGuide`,
|
|
186
|
+
* `guideDrift`; spec 2026-11-09-setup-guides-v2-design.md §9.3, §11).
|
|
186
187
|
*/
|
|
187
188
|
export type ConnectorPage<T extends ConnectorSummary = ConnectorDetail> = T & ConnectionGuideState & {
|
|
188
189
|
icon: string | null;
|
|
@@ -190,8 +191,9 @@ export type ConnectorPage<T extends ConnectorSummary = ConnectorDetail> = T & Co
|
|
|
190
191
|
oauthCallbackUrl?: string | null;
|
|
191
192
|
};
|
|
192
193
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
194
|
+
* Connectors (`/api/v1/orgs/:orgId/connectors`): reads and personal credentials need
|
|
195
|
+
* `connectors.use` (guests and up); install / update / delete / refresh / org credentials need
|
|
196
|
+
* `connectors.manage` (admins and up); both are for user principals only.
|
|
195
197
|
*/
|
|
196
198
|
export declare class ConnectorsController {
|
|
197
199
|
private readonly connectors;
|
|
@@ -200,11 +202,21 @@ export declare class ConnectorsController {
|
|
|
200
202
|
private readonly config;
|
|
201
203
|
constructor(connectors: ConnectorsService, icons: PluginIcons, memberPolicies: ConnectorAccountPolicies, config: Pick<KernelConfigService, "get">);
|
|
202
204
|
/**
|
|
203
|
-
* Each connector with `icon
|
|
204
|
-
*
|
|
205
|
-
*
|
|
205
|
+
* Each connector with `icon`, on its own icon route (`GET …/connectors/:id/icon`, so guests can
|
|
206
|
+
* load it too): the own icon of the platform connector template it was made from (its current
|
|
207
|
+
* version, the platform's one version of the template), else the icon of the plugin its template
|
|
208
|
+
* came from, else null (a custom connector, no icon, or one the reader's catalog does not show:
|
|
209
|
+
* the share gate holds; maintainer decision 2026-11-09).
|
|
206
210
|
*/
|
|
207
211
|
private withIcons;
|
|
212
|
+
/**
|
|
213
|
+
* The icon the connector shows (svg or png, the catalog icon response headers): its template's
|
|
214
|
+
* own icon, else its plugin's, under the same visibility gate as the catalog icon routes. It is
|
|
215
|
+
* the connector pages' icon URL, so every role that reads connectors (`connectors.use`, guests
|
|
216
|
+
* included) may load it without reading the catalog. Unknown connector -> 404
|
|
217
|
+
* `connector.not_found`; no icon the reader may see -> 404 `catalog.icon_not_found`.
|
|
218
|
+
*/
|
|
219
|
+
icon(org: OrgContext, connectorId: string, reply: FastifyReply): Promise<void>;
|
|
208
220
|
list(org: OrgContext): Promise<{
|
|
209
221
|
connectors: ConnectorPage<ConnectorSummary>[];
|
|
210
222
|
}>;
|
|
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { Controller, Delete, Get, HttpCode, Inject, Param, Patch, Post, Put } from "@nestjs/common";
|
|
10
|
+
import { Controller, Delete, Get, HttpCode, Inject, Param, Patch, Post, Put, Res, } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
+
import { sendCatalogIcon } from "../catalog/org-catalog.controller.js";
|
|
12
13
|
import { orgIconScope, PluginIcons } from "../extensions/plugin-icons.js";
|
|
13
14
|
import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
|
|
14
15
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -59,8 +60,9 @@ class GitPushPolicyDto extends createZodDto(GitPushPolicyBody, "ConnectorGitPush
|
|
|
59
60
|
class ConnectorGuideAckBody extends createZodDto(ConnectorGuideAckSchema, "ConnectorGuideAckBody") {
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
63
|
+
* Connectors (`/api/v1/orgs/:orgId/connectors`): reads and personal credentials need
|
|
64
|
+
* `connectors.use` (guests and up); install / update / delete / refresh / org credentials need
|
|
65
|
+
* `connectors.manage` (admins and up); both are for user principals only.
|
|
64
66
|
*/
|
|
65
67
|
let ConnectorsController = class ConnectorsController {
|
|
66
68
|
connectors;
|
|
@@ -74,17 +76,26 @@ let ConnectorsController = class ConnectorsController {
|
|
|
74
76
|
this.config = config;
|
|
75
77
|
}
|
|
76
78
|
/**
|
|
77
|
-
* Each connector with `icon
|
|
78
|
-
*
|
|
79
|
-
*
|
|
79
|
+
* Each connector with `icon`, on its own icon route (`GET …/connectors/:id/icon`, so guests can
|
|
80
|
+
* load it too): the own icon of the platform connector template it was made from (its current
|
|
81
|
+
* version, the platform's one version of the template), else the icon of the plugin its template
|
|
82
|
+
* came from, else null (a custom connector, no icon, or one the reader's catalog does not show:
|
|
83
|
+
* the share gate holds; maintainer decision 2026-11-09).
|
|
80
84
|
*/
|
|
81
85
|
async withIcons(org, rows) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const urls = await this.icons.ofConnectors(rows.map((r) => ({ id: r.id, templateId: r.platformTemplateId, itemId: r.catalogItemId })), orgIconScope(org));
|
|
87
|
+
return rows.map((r, i) => ({ ...r, icon: urls[i] ?? null }));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The icon the connector shows (svg or png, the catalog icon response headers): its template's
|
|
91
|
+
* own icon, else its plugin's, under the same visibility gate as the catalog icon routes. It is
|
|
92
|
+
* the connector pages' icon URL, so every role that reads connectors (`connectors.use`, guests
|
|
93
|
+
* included) may load it without reading the catalog. Unknown connector -> 404
|
|
94
|
+
* `connector.not_found`; no icon the reader may see -> 404 `catalog.icon_not_found`.
|
|
95
|
+
*/
|
|
96
|
+
async icon(org, connectorId, reply) {
|
|
97
|
+
const ref = await this.connectors.iconRef(org.orgId, connectorId);
|
|
98
|
+
await sendCatalogIcon(reply, await this.icons.readConnectorIcon(ref, orgIconScope(org)));
|
|
88
99
|
}
|
|
89
100
|
async list(org) {
|
|
90
101
|
const list = (await this.connectors.list(org.orgId)).map((a) => forViewer(org, a));
|
|
@@ -221,6 +232,13 @@ let ConnectorsController = class ConnectorsController {
|
|
|
221
232
|
await this.connectors.clearMyCredential(org.orgId, connectorId, p.account.id, patTokenId(p));
|
|
222
233
|
}
|
|
223
234
|
};
|
|
235
|
+
__decorate([
|
|
236
|
+
Get(":connectorId/icon"),
|
|
237
|
+
OrgAction("connectors.use"),
|
|
238
|
+
__param(0, CurrentOrg()),
|
|
239
|
+
__param(1, Param("connectorId")),
|
|
240
|
+
__param(2, Res())
|
|
241
|
+
], ConnectorsController.prototype, "icon", null);
|
|
224
242
|
__decorate([
|
|
225
243
|
Get(),
|
|
226
244
|
OrgAction("connectors.use"),
|
|
@@ -381,6 +381,14 @@ export declare class ConnectorsService {
|
|
|
381
381
|
private ackIn;
|
|
382
382
|
/** The org's connectors that are not deleted (by creation time). */
|
|
383
383
|
list(orgId: string): Promise<ConnectorSummary[]>;
|
|
384
|
+
/**
|
|
385
|
+
* Where a live connector of the org takes its icon from: its platform template and its plugin
|
|
386
|
+
* (catalog item). Unknown -> `connector.not_found`.
|
|
387
|
+
*/
|
|
388
|
+
iconRef(orgId: string, connectorId: string): Promise<{
|
|
389
|
+
templateId: string | null;
|
|
390
|
+
itemId: string | null;
|
|
391
|
+
}>;
|
|
384
392
|
get(orgId: string, connectorId: string, viewerAccountId: string): Promise<ConnectorDetail>;
|
|
385
393
|
/** 改名、启停连接器、工具启停与默认策略、批量把无注解工具改为 allow(`connectors.manage`)。 */
|
|
386
394
|
update(orgId: string, connectorId: string, actorAccountId: string, patch: UpdateConnectorInput, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<ConnectorDetail>;
|
|
@@ -25,6 +25,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
25
25
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
26
26
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
27
27
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
28
|
+
import { UUID_RE } from "../ui/registry.js";
|
|
28
29
|
import { CredentialMissing, Credentials, isOAuth, } from "./credentials.js";
|
|
29
30
|
import { snapshot, ToolDrift, toolIssue, } from "./drift.js";
|
|
30
31
|
import { endpointCredentialIssues, endpointView } from "./endpoint.js";
|
|
@@ -577,6 +578,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
577
578
|
updated_at: sql `now()`,
|
|
578
579
|
})
|
|
579
580
|
.where("id", "=", connectorId)
|
|
581
|
+
.where("org_id", "=", orgId)
|
|
580
582
|
.execute();
|
|
581
583
|
// Tools at a default the org did not set (template or derived): a tool the new template names
|
|
582
584
|
// takes its policy (`template`); an unnamed `template` one returns to the derived policy;
|
|
@@ -981,6 +983,16 @@ let ConnectorsService = class ConnectorsService {
|
|
|
981
983
|
.execute();
|
|
982
984
|
return rows.map((r) => this.summary(r));
|
|
983
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* Where a live connector of the org takes its icon from: its platform template and its plugin
|
|
988
|
+
* (catalog item). Unknown -> `connector.not_found`.
|
|
989
|
+
*/
|
|
990
|
+
async iconRef(orgId, connectorId) {
|
|
991
|
+
if (!UUID_RE.test(connectorId))
|
|
992
|
+
throw notFound();
|
|
993
|
+
const r = await this.row(this.db, orgId, connectorId);
|
|
994
|
+
return { templateId: r.platform_template_id ?? null, itemId: r.catalog_item_id ?? null };
|
|
995
|
+
}
|
|
984
996
|
async get(orgId, connectorId, viewerAccountId) {
|
|
985
997
|
return this.detail(this.db, orgId, connectorId, viewerAccountId);
|
|
986
998
|
}
|
|
@@ -1070,6 +1082,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1070
1082
|
updated_at: sql `now()`,
|
|
1071
1083
|
})
|
|
1072
1084
|
.where("id", "=", connectorId)
|
|
1085
|
+
.where("org_id", "=", orgId)
|
|
1073
1086
|
.execute();
|
|
1074
1087
|
}
|
|
1075
1088
|
const allowed = [];
|
|
@@ -1149,6 +1162,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1149
1162
|
.updateTable("connectors")
|
|
1150
1163
|
.set({ git_push_policy: policy, updated_at: sql `now()` })
|
|
1151
1164
|
.where("id", "=", connectorId)
|
|
1165
|
+
.where("org_id", "=", orgId)
|
|
1152
1166
|
.execute();
|
|
1153
1167
|
await audit(t, {
|
|
1154
1168
|
actorAccountId,
|
|
@@ -1246,6 +1260,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1246
1260
|
// leaves the connector as the platform set it
|
|
1247
1261
|
.set({ status, disabled_by_plugin_id: null, updated_at: sql `now()` })
|
|
1248
1262
|
.where("id", "=", connectorId)
|
|
1263
|
+
.where("org_id", "=", orgId)
|
|
1249
1264
|
.execute();
|
|
1250
1265
|
await audit(t, {
|
|
1251
1266
|
actorAccountId: actor.accountId,
|
|
@@ -1289,10 +1304,15 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1289
1304
|
.updateTable("connectors")
|
|
1290
1305
|
.set({ deleted_at: sql `now()`, updated_at: sql `now()` })
|
|
1291
1306
|
.where("id", "=", connectorId)
|
|
1307
|
+
.where("org_id", "=", orgId)
|
|
1292
1308
|
.execute();
|
|
1293
1309
|
await this.credentials.clearConnector(orgId, connectorId);
|
|
1294
1310
|
// 授权绑定连接器 id(软删除不触发外键级联):一并删掉,不留给任何后来的连接器
|
|
1295
|
-
await t
|
|
1311
|
+
await t
|
|
1312
|
+
.deleteFrom("tool_grants")
|
|
1313
|
+
.where("org_id", "=", orgId)
|
|
1314
|
+
.where("connector_id", "=", connectorId)
|
|
1315
|
+
.execute();
|
|
1296
1316
|
await t
|
|
1297
1317
|
.deleteFrom("conversation_tool_grants")
|
|
1298
1318
|
.where("connector_id", "=", connectorId)
|
package/dist/tools/drift.js
CHANGED
|
@@ -260,6 +260,8 @@ let ToolDrift = class ToolDrift {
|
|
|
260
260
|
* 把新快照与当前工具行比对并写入(调用方已在事务内锁住连接器行:`mandatory`);返回按名排序的变化。
|
|
261
261
|
* 规则见文件头。待复核的新定义也写进 `tool_specs`(内容寻址,只增不改)。
|
|
262
262
|
*/
|
|
263
|
+
// org-filter: app is the connector row the caller read with its org filter and holds locked
|
|
264
|
+
// FOR UPDATE (applyChecked, ConnectorsService's refresh); connector_tools has no org column
|
|
263
265
|
async apply(app, rows) {
|
|
264
266
|
const t = this.db.db;
|
|
265
267
|
const current = await t
|
|
@@ -485,6 +487,7 @@ let ToolDrift = class ToolDrift {
|
|
|
485
487
|
.selectFrom("connectors")
|
|
486
488
|
.select(["id", "tools_synced_at"])
|
|
487
489
|
.where("id", "=", connectorId)
|
|
490
|
+
.where("org_id", "=", orgId)
|
|
488
491
|
.where("deleted_at", "is", null)
|
|
489
492
|
.where("status", "=", "active")
|
|
490
493
|
.forUpdate()
|
|
@@ -530,6 +533,8 @@ let ToolDrift = class ToolDrift {
|
|
|
530
533
|
* 周期扫描:给本周期内还没检查过的活动连接器(`tools_synced_at` 为空或早于半个周期)各投递一次检查,
|
|
531
534
|
* jobId 按周期桶去重——即使扫描在多个副本上重复执行,每个连接器每周期也只检查一次。返回投递数。
|
|
532
535
|
*/
|
|
536
|
+
// org-filter: deployment-wide sweep across all orgs (LockedInterval in ToolJobs); each job
|
|
537
|
+
// carries its connector's own org_id
|
|
533
538
|
async scan() {
|
|
534
539
|
const interval = this.intervalMs();
|
|
535
540
|
const bucket = Math.floor(Date.now() / interval);
|
|
@@ -64,6 +64,7 @@ export async function decideGitPush(db, config, input) {
|
|
|
64
64
|
const row = await db
|
|
65
65
|
.selectFrom("connector_tool_account_policies")
|
|
66
66
|
.select("policy")
|
|
67
|
+
.where("org_id", "=", input.orgId)
|
|
67
68
|
.where("connector_id", "=", input.connectorId)
|
|
68
69
|
.where("account_id", "=", input.accountId)
|
|
69
70
|
.where("tool_name", "=", gitPushPolicyName(host, repo))
|
|
@@ -150,6 +151,8 @@ async function hasRunGrant(db, input, host, repo) {
|
|
|
150
151
|
* repositories granted and refused in the tree (keyed `<host>/<owner>/<repo>`, {@link gitRepoKey}),
|
|
151
152
|
* this run's asks, a pending ask of the tree.
|
|
152
153
|
*/
|
|
154
|
+
// org-filter: takes a runtime run id (no HTTP or tool input reaches it; only kernel code and tests
|
|
155
|
+
// call it), and the rows are that run tree's
|
|
153
156
|
export async function gitRunState(db, runId) {
|
|
154
157
|
const root = await budgetRunOf(db, runId);
|
|
155
158
|
const rows = await db
|
package/dist/tools/oauth/flow.js
CHANGED
package/dist/tools/outputs.js
CHANGED
|
@@ -77,6 +77,8 @@ export const OUTPUT_CLEANUP_BATCH = 1000;
|
|
|
77
77
|
* 删除已过期(`expires_at < now()`)的输出存档,每批 `batch` 行,直到删完;返回删除的总行数。
|
|
78
78
|
* 每批一条独立语句(不开长事务);多个 worker 同时清理时 `SKIP LOCKED` 互不等待。
|
|
79
79
|
*/
|
|
80
|
+
// org-filter: deployment-wide cleanup of expired archives across all orgs (a worker job), by
|
|
81
|
+
// expiry only
|
|
80
82
|
export async function deleteExpiredOutputs(db, batch = OUTPUT_CLEANUP_BATCH) {
|
|
81
83
|
let total = 0;
|
|
82
84
|
for (;;) {
|
|
@@ -54,6 +54,7 @@ let PermissionApprovalJobs = class PermissionApprovalJobs {
|
|
|
54
54
|
.selectFrom("conversations")
|
|
55
55
|
.select("id")
|
|
56
56
|
.where("id", "=", root.id)
|
|
57
|
+
.where("org_id", "=", data.orgId)
|
|
57
58
|
.unionAll((q) => q
|
|
58
59
|
.selectFrom("conversations as c")
|
|
59
60
|
.innerJoin("tree", "tree.id", "c.parent_conversation_id")
|
|
@@ -62,12 +63,14 @@ let PermissionApprovalJobs = class PermissionApprovalJobs {
|
|
|
62
63
|
.selectFrom("conversations")
|
|
63
64
|
.select("id")
|
|
64
65
|
.where("id", "in", (q) => q.selectFrom("tree").select("id"))
|
|
66
|
+
.where("org_id", "=", data.orgId)
|
|
65
67
|
.orderBy("id")
|
|
66
68
|
.forUpdate()
|
|
67
69
|
.execute();
|
|
68
70
|
const cards = await this.db
|
|
69
71
|
.selectFrom("approvals")
|
|
70
72
|
.select(["run_id", "conversation_id"])
|
|
73
|
+
.where("org_id", "=", data.orgId)
|
|
71
74
|
.where("conversation_id", "in", tree.map((c) => c.id))
|
|
72
75
|
.where("kind", "=", "command")
|
|
73
76
|
.where("status", "=", "superseded")
|