@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
package/dist/channels/threads.js
CHANGED
|
@@ -163,6 +163,7 @@ export async function findOrBindThread(db, k, target, create) {
|
|
|
163
163
|
const id = await create();
|
|
164
164
|
const winner = await insertThread(db, k, id);
|
|
165
165
|
if (winner !== id) {
|
|
166
|
+
// org-filter: id is the empty conversation create() just made in this transaction
|
|
166
167
|
await db.deleteFrom("conversations").where("id", "=", id).where("last_seq", "=", "0").execute();
|
|
167
168
|
return { conversationId: winner, created: false };
|
|
168
169
|
}
|
|
@@ -82,6 +82,7 @@ let ClientReports = class ClientReports {
|
|
|
82
82
|
}
|
|
83
83
|
/** Deletes the reports last seen more than {@link REPORT_RETENTION_DAYS} days ago; the count. */
|
|
84
84
|
async prune() {
|
|
85
|
+
// org-filter: deployment-wide retention sweep over every org's reports (maintenance job)
|
|
85
86
|
const r = await this.db.db
|
|
86
87
|
.deleteFrom("extension_client_reports")
|
|
87
88
|
.where("last_at", "<", sql `now() - make_interval(days => ${REPORT_RETENTION_DAYS})`)
|
package/dist/config/fields.js
CHANGED
|
@@ -46,15 +46,31 @@ export function describeSchema(schema) {
|
|
|
46
46
|
return { type, hasDefault, defaultValue, optional };
|
|
47
47
|
}
|
|
48
48
|
const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Strips default / optional and the other wrappers: the inner schema and the meta merged across the
|
|
51
|
+
* chain (an outer key wins over an inner one), except `secret`, which holds when any node carries
|
|
52
|
+
* it, so a wrapper's meta (`platformOnly(secret(x).optional())`) never hides a secret.
|
|
53
|
+
*/
|
|
50
54
|
function unwrap(schema) {
|
|
55
|
+
const chain = [schema];
|
|
51
56
|
let node = schema;
|
|
52
|
-
let found = z.globalRegistry.get(node);
|
|
53
57
|
while (WRAPPERS.has(node._zod.def.type)) {
|
|
54
58
|
node = node._zod.def.innerType;
|
|
55
|
-
|
|
59
|
+
chain.push(node);
|
|
60
|
+
}
|
|
61
|
+
let merged;
|
|
62
|
+
let secret = false;
|
|
63
|
+
for (const n of chain.reverse()) {
|
|
64
|
+
const m = z.globalRegistry.get(n);
|
|
65
|
+
if (!m)
|
|
66
|
+
continue;
|
|
67
|
+
if (m.secret === true)
|
|
68
|
+
secret = true;
|
|
69
|
+
merged = { ...merged, ...m };
|
|
56
70
|
}
|
|
57
|
-
|
|
71
|
+
if (merged && secret)
|
|
72
|
+
merged.secret = true;
|
|
73
|
+
return { inner: node, meta: merged };
|
|
58
74
|
}
|
|
59
75
|
/** 列出 schema 的所有叶子字段(对象递归展开;数组、record 等视作叶子)。 */
|
|
60
76
|
export function configFields(schema, prefix = "", inheritedSecret = false) {
|
|
@@ -76,6 +76,7 @@ export const accessibleTo = (viewer) => (eb) => eb.and([
|
|
|
76
76
|
.selectFrom("agents")
|
|
77
77
|
.select(sql `1`.as("one"))
|
|
78
78
|
.whereRef("agents.id", "=", "conversations.agent_id")
|
|
79
|
+
.whereRef("agents.org_id", "=", "conversations.org_id")
|
|
79
80
|
.where("agents.deleted_at", "is", null)
|
|
80
81
|
.where(visibleTo(viewer))),
|
|
81
82
|
]);
|
|
@@ -307,7 +307,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
307
307
|
ttlHours,
|
|
308
308
|
});
|
|
309
309
|
const head = await this.storage.kernel(orgId).put(key, file.bytes, { contentType, size });
|
|
310
|
-
await this.markStored(id, head.size, head.etag ?? null);
|
|
310
|
+
await this.markStored(orgId, id, head.size, head.etag ?? null);
|
|
311
311
|
return { id };
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
@@ -329,11 +329,12 @@ let AttachmentsService = class AttachmentsService {
|
|
|
329
329
|
.execute();
|
|
330
330
|
}
|
|
331
331
|
/** The last step of {@link createFromBytes}: the stored object's size and etag, `ready`. */
|
|
332
|
-
async markStored(id, size, etag) {
|
|
332
|
+
async markStored(orgId, id, size, etag) {
|
|
333
333
|
await this.db.db
|
|
334
334
|
.updateTable("attachments")
|
|
335
335
|
.set({ status: "ready", size, etag })
|
|
336
336
|
.where("id", "=", id)
|
|
337
|
+
.where("org_id", "=", orgId)
|
|
337
338
|
.where("status", "=", "pending")
|
|
338
339
|
.execute();
|
|
339
340
|
}
|
|
@@ -412,6 +413,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
412
413
|
.updateTable("attachments")
|
|
413
414
|
.set({ status: "ready", etag: got?.head.etag ?? head.etag ?? null, pages })
|
|
414
415
|
.where("id", "=", id)
|
|
416
|
+
.where("org_id", "=", orgId)
|
|
415
417
|
.where("status", "=", "pending")
|
|
416
418
|
.execute();
|
|
417
419
|
return view;
|
|
@@ -623,6 +625,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
623
625
|
.updateTable("attachments")
|
|
624
626
|
.set({ conversation_id: conversationId, expires_at: null })
|
|
625
627
|
.where("id", "in", toBind)
|
|
628
|
+
.where("org_id", "=", orgId)
|
|
626
629
|
.execute();
|
|
627
630
|
}
|
|
628
631
|
return blocks;
|
|
@@ -764,6 +767,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
764
767
|
.updateTable("attachments")
|
|
765
768
|
.set({ expires_at: sql `now() + make_interval(hours => ${SKILL_PACKAGE_TTL_HOURS})` })
|
|
766
769
|
.where("id", "=", id)
|
|
770
|
+
.where("org_id", "=", orgId)
|
|
767
771
|
.where("status", "=", "ready")
|
|
768
772
|
.where("purpose", "=", "skill-package")
|
|
769
773
|
.returning(["object_key", "size", "etag"])
|
|
@@ -801,6 +805,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
801
805
|
.updateTable("attachments")
|
|
802
806
|
.set({ status: "deleting", expires_at: sql `now()` })
|
|
803
807
|
.where("id", "=", id)
|
|
808
|
+
.where("org_id", "=", orgId)
|
|
804
809
|
.execute();
|
|
805
810
|
}
|
|
806
811
|
/**
|
|
@@ -838,6 +843,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
838
843
|
.updateTable("attachments")
|
|
839
844
|
.set({ expires_at: sql `now() + make_interval(hours => ${AGENT_AVATAR_TTL_HOURS})` })
|
|
840
845
|
.where("id", "=", id)
|
|
846
|
+
.where("org_id", "=", orgId)
|
|
841
847
|
.where("status", "=", "ready")
|
|
842
848
|
.where("agent_id", "is", null)
|
|
843
849
|
.where("expires_at", "is not", null)
|
|
@@ -867,6 +873,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
867
873
|
.updateTable("attachments")
|
|
868
874
|
.set({ agent_id: agentId, expires_at: null })
|
|
869
875
|
.where("id", "=", id)
|
|
876
|
+
.where("org_id", "=", orgId)
|
|
870
877
|
.execute();
|
|
871
878
|
}
|
|
872
879
|
/**
|
|
@@ -937,7 +944,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
937
944
|
const head = await this.storage
|
|
938
945
|
.kernel(orgId)
|
|
939
946
|
.put(key, file.data, { contentType: contentType || "application/octet-stream" });
|
|
940
|
-
await this.bindRead(id, conversationId, head.size, head.etag ?? null);
|
|
947
|
+
await this.bindRead(orgId, id, conversationId, head.size, head.etag ?? null);
|
|
941
948
|
return { ok: true, attachmentId: id, size: head.size };
|
|
942
949
|
}
|
|
943
950
|
/**
|
|
@@ -984,11 +991,12 @@ let AttachmentsService = class AttachmentsService {
|
|
|
984
991
|
}
|
|
985
992
|
}
|
|
986
993
|
/** Step 4 of {@link storeRead}: binds the unbound row in one transaction. */
|
|
987
|
-
async bindRead(id, conversationId, size, etag) {
|
|
994
|
+
async bindRead(orgId, id, conversationId, size, etag) {
|
|
988
995
|
const bound = await this.db.db
|
|
989
996
|
.updateTable("attachments")
|
|
990
997
|
.set({ conversation_id: conversationId, status: "ready", expires_at: null, size, etag })
|
|
991
998
|
.where("id", "=", id)
|
|
999
|
+
.where("org_id", "=", orgId)
|
|
992
1000
|
.where("purpose", "=", "read")
|
|
993
1001
|
.where("status", "=", "pending")
|
|
994
1002
|
.where("conversation_id", "is", null)
|
|
@@ -1006,6 +1014,8 @@ let AttachmentsService = class AttachmentsService {
|
|
|
1006
1014
|
* Chat attachments of deleted conversations are not touched. Does nothing without an object
|
|
1007
1015
|
* store. Returns the number of rows deleted.
|
|
1008
1016
|
*/
|
|
1017
|
+
// org-filter: deployment-wide cleanup job across all orgs; each claimed row is deleted by its
|
|
1018
|
+
// own id and handled in its own org (r.org_id)
|
|
1009
1019
|
async purgeRead() {
|
|
1010
1020
|
if (!this.storage.available)
|
|
1011
1021
|
return 0;
|
|
@@ -1070,6 +1080,8 @@ let AttachmentsService = class AttachmentsService {
|
|
|
1070
1080
|
* 解出的文件 `skills/<id>/` 只在没有任何技能版本引用时一并删除。
|
|
1071
1081
|
* 没有对象存储时什么也不做。返回删除的附件数。
|
|
1072
1082
|
*/
|
|
1083
|
+
// org-filter: deployment-wide cleanup job across all orgs; each claimed row is deleted by its
|
|
1084
|
+
// own id and handled in its own org (r.org_id)
|
|
1073
1085
|
async deleteExpired() {
|
|
1074
1086
|
if (!this.storage.available)
|
|
1075
1087
|
return 0;
|
|
@@ -309,7 +309,12 @@ let ConversationsService = class ConversationsService {
|
|
|
309
309
|
}
|
|
310
310
|
await this.eventLog.notify(id, written.seq);
|
|
311
311
|
await this.startRun(id);
|
|
312
|
-
return {
|
|
312
|
+
return {
|
|
313
|
+
conversation: await this.rowView(orgId, id),
|
|
314
|
+
event: written,
|
|
315
|
+
events: all,
|
|
316
|
+
created: true,
|
|
317
|
+
};
|
|
313
318
|
}
|
|
314
319
|
/** The conversation row and its first message (undefined: a concurrent retry committed first). */
|
|
315
320
|
// its own transaction: the caller notifies and publishes after the commit
|
|
@@ -403,11 +408,12 @@ let ConversationsService = class ConversationsService {
|
|
|
403
408
|
startRun(conversationId) {
|
|
404
409
|
return this.runs.ensureRunAfterCommit(conversationId);
|
|
405
410
|
}
|
|
406
|
-
async rowView(id) {
|
|
411
|
+
async rowView(orgId, id) {
|
|
407
412
|
return toView(await this.db
|
|
408
413
|
.selectFrom("conversations")
|
|
409
414
|
.select(viewColumns())
|
|
410
415
|
.where("id", "=", id)
|
|
416
|
+
.where("org_id", "=", orgId)
|
|
411
417
|
.executeTakeFirstOrThrow());
|
|
412
418
|
}
|
|
413
419
|
/**
|
|
@@ -420,6 +426,7 @@ let ConversationsService = class ConversationsService {
|
|
|
420
426
|
.updateTable("conversations")
|
|
421
427
|
.set({ title, title_source: "manual" })
|
|
422
428
|
.where("id", "=", conversationId)
|
|
429
|
+
.where("org_id", "=", orgId)
|
|
423
430
|
.returning(viewColumns())
|
|
424
431
|
.executeTakeFirstOrThrow();
|
|
425
432
|
await this.eventLog.publishChanged(conversationId, "title");
|
|
@@ -435,6 +442,7 @@ let ConversationsService = class ConversationsService {
|
|
|
435
442
|
.updateTable("conversations")
|
|
436
443
|
.set({ archived_at: archived ? sql `now()` : null })
|
|
437
444
|
.where("id", "=", conversationId)
|
|
445
|
+
.where("org_id", "=", orgId)
|
|
438
446
|
.returning(viewColumns())
|
|
439
447
|
.executeTakeFirstOrThrow();
|
|
440
448
|
await this.eventLog.publishChanged(conversationId, "archived");
|
|
@@ -489,6 +497,7 @@ let ConversationsService = class ConversationsService {
|
|
|
489
497
|
.selectFrom("conversations")
|
|
490
498
|
.select("device_id")
|
|
491
499
|
.where("id", "=", rootId)
|
|
500
|
+
.where("org_id", "=", orgId)
|
|
492
501
|
.executeTakeFirstOrThrow();
|
|
493
502
|
return {
|
|
494
503
|
orgId,
|
|
@@ -521,6 +530,7 @@ let ConversationsService = class ConversationsService {
|
|
|
521
530
|
.updateTable("conversations")
|
|
522
531
|
.set({ deleted_at: sql `now()` })
|
|
523
532
|
.where("id", "=", conversationId)
|
|
533
|
+
.where("org_id", "=", orgId)
|
|
524
534
|
.execute();
|
|
525
535
|
await this.runs.oweStopDeletedTree(conversationId, accountId, orgId);
|
|
526
536
|
// Queued messages must not start a run on a deleted conversation
|
|
@@ -770,7 +780,8 @@ let ConversationsService = class ConversationsService {
|
|
|
770
780
|
? sql ``
|
|
771
781
|
: sql `AND (c.created_at, c.id) < (
|
|
772
782
|
SELECT c2.created_at, c2.id FROM capybara.conversations c2
|
|
773
|
-
WHERE c2.id = ${opts.after} AND c2.
|
|
783
|
+
WHERE c2.id = ${opts.after} AND c2.org_id = ${orgId}
|
|
784
|
+
AND c2.parent_conversation_id = ${conversationId}
|
|
774
785
|
)`;
|
|
775
786
|
const { rows } = await sql `
|
|
776
787
|
WITH page AS (
|
|
@@ -965,6 +976,7 @@ let ConversationsService = class ConversationsService {
|
|
|
965
976
|
.updateTable("conversations")
|
|
966
977
|
.set({ archived_at: null })
|
|
967
978
|
.where("id", "=", conversationId)
|
|
979
|
+
.where("org_id", "=", orgId)
|
|
968
980
|
.execute();
|
|
969
981
|
await this.eventLog.publishChanged(conversationId, "archived");
|
|
970
982
|
}
|
|
@@ -1138,6 +1150,7 @@ let ConversationsService = class ConversationsService {
|
|
|
1138
1150
|
.updateTable("conversations")
|
|
1139
1151
|
.set({ selection: JSON.stringify(await readSelection(t, conversationId)) })
|
|
1140
1152
|
.where("id", "=", conversationId)
|
|
1153
|
+
.where("org_id", "=", orgId)
|
|
1141
1154
|
.execute();
|
|
1142
1155
|
}
|
|
1143
1156
|
return { events: written, skipped: skips.skipped, skippedToSeq: skips.toSeq };
|
|
@@ -1288,6 +1301,7 @@ let ConversationsService = class ConversationsService {
|
|
|
1288
1301
|
* Marks a person's stop of the root's tree (`tree_stopped_at`, see {@link abort}); committed
|
|
1289
1302
|
* before any stop, so every wake decided after it (under the root's row lock) sees it.
|
|
1290
1303
|
*/
|
|
1304
|
+
// org-filter: conversationId was checked by get(orgId, ...) in abort, the only entry point
|
|
1291
1305
|
async holdTree(conversationId) {
|
|
1292
1306
|
await this.db
|
|
1293
1307
|
.updateTable("conversations")
|
|
@@ -382,6 +382,8 @@ let EventLog = class EventLog {
|
|
|
382
382
|
return r.data;
|
|
383
383
|
}
|
|
384
384
|
/** The append itself, in the context's transaction (both callers open or join one). */
|
|
385
|
+
// org-filter: the log writer is keyed by conversation id only; every append path resolved the
|
|
386
|
+
// conversation in its org first (access check, run claim, channel binding)
|
|
385
387
|
async write(conversationId, events, bodies) {
|
|
386
388
|
const t = this.db;
|
|
387
389
|
// 先锁会话行:之后的幂等查询与 seq 分配都在这把锁内,并发 append 依次执行。The same statement
|
|
@@ -1320,7 +1320,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1320
1320
|
toolKey: z.string(),
|
|
1321
1321
|
expiresAt: z.string(),
|
|
1322
1322
|
/** Which rule asked a tool approval (UI refresh B; display only; absent on the other asks). */
|
|
1323
|
-
policy: z
|
|
1323
|
+
policy: z
|
|
1324
|
+
.enum(["agent", "connector", "member", "default", "role", "org", "fixed"])
|
|
1325
|
+
.optional(),
|
|
1324
1326
|
/**
|
|
1325
1327
|
* A network ask (network ask-to-allow spec §6.1): the hosts the device owner is asked to
|
|
1326
1328
|
* allow. Display only, never model-visible: the model sees the call's `tool_result` only.
|
|
@@ -215,7 +215,7 @@ let ConversationFiles = class ConversationFiles {
|
|
|
215
215
|
start = at + 1;
|
|
216
216
|
}
|
|
217
217
|
const page = ordered.slice(start, start + opts.limit);
|
|
218
|
-
const shares = await this.viewerShares(conversationId, viewer);
|
|
218
|
+
const shares = await this.viewerShares(orgId, conversationId, viewer);
|
|
219
219
|
const store = this.storage.kernel(orgId);
|
|
220
220
|
const files = await mapLimit(page, HEAD_CONCURRENCY, async (e) => {
|
|
221
221
|
if (e.origin === "uploaded") {
|
|
@@ -331,10 +331,11 @@ let ConversationFiles = class ConversationFiles {
|
|
|
331
331
|
* The source paths and attachments the viewer has a share of in the conversation that is not
|
|
332
332
|
* revoked or expired ({@link FileOutput.shared}).
|
|
333
333
|
*/
|
|
334
|
-
async viewerShares(conversationId, viewer) {
|
|
334
|
+
async viewerShares(orgId, conversationId, viewer) {
|
|
335
335
|
const rows = await this.db
|
|
336
336
|
.selectFrom("file_shares")
|
|
337
337
|
.select(["source_path", "file_id"])
|
|
338
|
+
.where("org_id", "=", orgId)
|
|
338
339
|
.where("conversation_id", "=", conversationId)
|
|
339
340
|
.where("created_by", "=", viewer)
|
|
340
341
|
.where("revoked_at", "is", null)
|
|
@@ -151,6 +151,7 @@ let PermissionProfilesService = class PermissionProfilesService {
|
|
|
151
151
|
permission_consent: consent ? JSON.stringify(consent) : null,
|
|
152
152
|
})
|
|
153
153
|
.where("id", "=", id)
|
|
154
|
+
.where("org_id", "=", orgId)
|
|
154
155
|
.execute();
|
|
155
156
|
await this.transitions.recordLocked({
|
|
156
157
|
orgId,
|
|
@@ -271,6 +271,7 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
271
271
|
* The run's facts by spec §2 (outcome, conversation kind and source, trigger) and its hook scope,
|
|
272
272
|
* or why it gets no suggestion.
|
|
273
273
|
*/
|
|
274
|
+
// org-filter: job payload ids are kernel-written at run finish; the row's own org is read here
|
|
274
275
|
async runFacts(conversationId, runId) {
|
|
275
276
|
const conv = await this.db
|
|
276
277
|
.selectFrom("conversations")
|
|
@@ -487,6 +488,7 @@ let PromptSuggestionQueue = class PromptSuggestionQueue {
|
|
|
487
488
|
if (kind !== "completed" && kind !== "max_steps")
|
|
488
489
|
return;
|
|
489
490
|
try {
|
|
491
|
+
// org-filter: conversationId is the finished run's, passed by the kernel, not caller input
|
|
490
492
|
const due = await this.kdb.db
|
|
491
493
|
.selectFrom("conversations as c")
|
|
492
494
|
.select("c.id")
|
|
@@ -138,6 +138,7 @@ export async function appendQueuedIn(t, eventLog, conversationId, r) {
|
|
|
138
138
|
}
|
|
139
139
|
// run context spec §3.4: no browser values were stored with a leftover row; a scheduled task's
|
|
140
140
|
// item stored its task's zone, which wins (scheduled tasks spec §6)
|
|
141
|
+
// org-filter: reads the org of the conversation the caller holds the row lock of
|
|
141
142
|
const org = await t
|
|
142
143
|
.selectFrom("conversations")
|
|
143
144
|
.select("org_id")
|
|
@@ -155,6 +156,7 @@ export async function appendQueuedIn(t, eventLog, conversationId, r) {
|
|
|
155
156
|
.updateTable("conversations")
|
|
156
157
|
.set({ selection: JSON.stringify(await readSelection(t, conversationId)) })
|
|
157
158
|
.where("id", "=", conversationId)
|
|
159
|
+
.where("org_id", "=", org.org_id)
|
|
158
160
|
.execute();
|
|
159
161
|
}
|
|
160
162
|
// As a direct send: the message brings an archived conversation back into the default lists
|
|
@@ -162,6 +164,7 @@ export async function appendQueuedIn(t, eventLog, conversationId, r) {
|
|
|
162
164
|
.updateTable("conversations")
|
|
163
165
|
.set({ archived_at: null })
|
|
164
166
|
.where("id", "=", conversationId)
|
|
167
|
+
.where("org_id", "=", org.org_id)
|
|
165
168
|
.where("archived_at", "is not", null)
|
|
166
169
|
.executeTakeFirst();
|
|
167
170
|
return {
|
|
@@ -175,6 +178,8 @@ async function agentModel(t, conversationId) {
|
|
|
175
178
|
return (await currentAgent(t, conversationId)).definition.model;
|
|
176
179
|
}
|
|
177
180
|
/** The conversation's org, agent and the agent's current definition (inside `t`). */
|
|
181
|
+
// org-filter: returns the conversation's own org; the id comes from a caller that holds the
|
|
182
|
+
// conversation's row lock (queue dispatch), never from a request
|
|
178
183
|
async function currentAgent(t, conversationId) {
|
|
179
184
|
const row = await t
|
|
180
185
|
.selectFrom("conversations as c")
|
|
@@ -208,6 +213,7 @@ export async function queuedSkillBlocked(t, conversationId, r) {
|
|
|
208
213
|
});
|
|
209
214
|
}
|
|
210
215
|
/** Pauses the queue with `reason` (inside `t`, holding the conversation row lock). */
|
|
216
|
+
// org-filter: the caller locked this conversation row in its own (org-checked or kernel) path
|
|
211
217
|
export async function pauseQueueWith(t, conversationId, reason) {
|
|
212
218
|
await t
|
|
213
219
|
.updateTable("conversations")
|
|
@@ -226,6 +232,7 @@ export async function alreadySent(t, conversationId, clientMessageId) {
|
|
|
226
232
|
return row !== undefined;
|
|
227
233
|
}
|
|
228
234
|
/** Clears the pause once the queue is empty (inside `t`, holding the conversation row lock). */
|
|
235
|
+
// org-filter: the caller locked this conversation row in its own (org-checked or kernel) path
|
|
229
236
|
export async function unpauseIfEmpty(t, conversationId) {
|
|
230
237
|
await t
|
|
231
238
|
.updateTable("conversations")
|
|
@@ -277,6 +284,7 @@ export async function dispatchQueuedIn(t, eventLog, conversationId) {
|
|
|
277
284
|
* Pauses the queue of a conversation whose run just failed or was stopped, when it holds items
|
|
278
285
|
* (inside the terminal transaction, see `finishRunIn`).
|
|
279
286
|
*/
|
|
287
|
+
// org-filter: inside a run's terminal transaction; the conversation id is the claimed run's
|
|
280
288
|
export async function pauseQueueIn(t, conversationId) {
|
|
281
289
|
await t
|
|
282
290
|
.updateTable("conversations")
|
|
@@ -41,14 +41,15 @@ let ConversationQueue = class ConversationQueue {
|
|
|
41
41
|
}
|
|
42
42
|
async list(orgId, conversationId, accountId) {
|
|
43
43
|
await this.conversations.get(orgId, conversationId, accountId);
|
|
44
|
-
return this.listIn(conversationId);
|
|
44
|
+
return this.listIn(orgId, conversationId);
|
|
45
45
|
}
|
|
46
|
-
async listIn(conversationId) {
|
|
46
|
+
async listIn(orgId, conversationId) {
|
|
47
47
|
const t = this.db.db;
|
|
48
48
|
const conv = await t
|
|
49
49
|
.selectFrom("conversations")
|
|
50
50
|
.select(["queue_paused", "queue_pause_reason"])
|
|
51
51
|
.where("id", "=", conversationId)
|
|
52
|
+
.where("org_id", "=", orgId)
|
|
52
53
|
.executeTakeFirstOrThrow();
|
|
53
54
|
const rows = await t
|
|
54
55
|
.selectFrom("conversation_queue")
|
|
@@ -112,6 +113,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
112
113
|
.selectFrom("conversations")
|
|
113
114
|
.select("last_seq")
|
|
114
115
|
.where("id", "=", conversationId)
|
|
116
|
+
.where("org_id", "=", orgId)
|
|
115
117
|
.forUpdate()
|
|
116
118
|
.executeTakeFirstOrThrow();
|
|
117
119
|
const existing = await t
|
|
@@ -355,6 +357,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
355
357
|
.updateTable("conversations")
|
|
356
358
|
.set({ queue_paused: false, queue_pause_reason: null })
|
|
357
359
|
.where("id", "=", conversationId)
|
|
360
|
+
.where("org_id", "=", orgId)
|
|
358
361
|
.returning("last_seq")
|
|
359
362
|
.executeTakeFirstOrThrow();
|
|
360
363
|
await this.runs.oweEnsureRun(conversationId, conv.last_seq, orgId);
|
|
@@ -374,6 +377,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
374
377
|
const event = await this.eventLog.findByIdem(conversationId, userMessageIdemKey(clientMessageId));
|
|
375
378
|
return event ? { item: null, event, created: false } : null;
|
|
376
379
|
}
|
|
380
|
+
// org-filter: both callers (remove, sendNow) checked writable(orgId, conversationId, ...) first
|
|
377
381
|
async lockConversation(conversationId) {
|
|
378
382
|
await this.db
|
|
379
383
|
.selectFrom("conversations")
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* (`conversations.source`, migration 0124) and never changed. A missing conversation throws
|
|
4
4
|
* rather than guessing a source (a guess could offer a group chat what only a DM may see).
|
|
5
5
|
*/
|
|
6
|
+
// org-filter: callers pass a conversation id the kernel resolved (an approval row, the running
|
|
7
|
+
// tool's context), never a raw request id
|
|
6
8
|
export async function conversationSourceOf(db, conversationId) {
|
|
7
9
|
const row = await db
|
|
8
10
|
.selectFrom("conversations")
|
|
@@ -121,6 +121,8 @@ const typedText = (content) => {
|
|
|
121
121
|
return first?.type === "text" ? first.text : "";
|
|
122
122
|
};
|
|
123
123
|
/** The attempt number to enqueue for this conversation, or null when no title job is due. */
|
|
124
|
+
// org-filter: called by the kernel after a message it wrote (the title queue), with that
|
|
125
|
+
// conversation's id, never with a request id
|
|
124
126
|
export async function titleAttemptDue(db, conversationId) {
|
|
125
127
|
const row = await db
|
|
126
128
|
.selectFrom("conversations as c")
|
|
@@ -181,6 +183,7 @@ export async function runTitleJob(d, conversationId, attempt) {
|
|
|
181
183
|
return;
|
|
182
184
|
if (d.signal?.aborted)
|
|
183
185
|
return;
|
|
186
|
+
// org-filter: the job payload id is kernel-written (TitleQueue); the row's org is returned here
|
|
184
187
|
const claimed = await d.db
|
|
185
188
|
.updateTable("conversations")
|
|
186
189
|
.set({ title_attempts: attempt + 1 })
|
|
@@ -202,7 +205,8 @@ export async function runTitleJob(d, conversationId, attempt) {
|
|
|
202
205
|
orgId: claimed.org_id,
|
|
203
206
|
accountId: claimed.account_id,
|
|
204
207
|
agentId: claimed.agent_id,
|
|
205
|
-
agentVersion: started?.payload.agentVersion ??
|
|
208
|
+
agentVersion: started?.payload.agentVersion ??
|
|
209
|
+
(await agentVersionOf(d.db, claimed.org_id, claimed.agent_id)),
|
|
206
210
|
conversationId,
|
|
207
211
|
runId: "",
|
|
208
212
|
};
|
|
@@ -237,6 +241,7 @@ export async function runTitleJob(d, conversationId, attempt) {
|
|
|
237
241
|
.updateTable("conversations")
|
|
238
242
|
.set({ title_attempts: TITLE_MAX_ATTEMPTS })
|
|
239
243
|
.where("id", "=", conversationId)
|
|
244
|
+
.where("org_id", "=", claimed.org_id)
|
|
240
245
|
.execute();
|
|
241
246
|
return;
|
|
242
247
|
}
|
|
@@ -294,6 +299,7 @@ async function logUsage(d, conversationId, attempt, u) {
|
|
|
294
299
|
await d.eventLog.notify(conversationId, ev.seq);
|
|
295
300
|
}
|
|
296
301
|
/** Returns a claimed attempt (shutdown before the call was sent). */
|
|
302
|
+
// org-filter: gives back the attempt runTitleJob claimed by the kernel-written job id
|
|
297
303
|
async function giveBack(db, conversationId, attempt) {
|
|
298
304
|
await db
|
|
299
305
|
.updateTable("conversations")
|
|
@@ -303,11 +309,12 @@ async function giveBack(db, conversationId, attempt) {
|
|
|
303
309
|
.where("title_source", "is", null)
|
|
304
310
|
.execute();
|
|
305
311
|
}
|
|
306
|
-
async function agentVersionOf(db, agentId) {
|
|
312
|
+
async function agentVersionOf(db, orgId, agentId) {
|
|
307
313
|
const row = await db
|
|
308
314
|
.selectFrom("agents")
|
|
309
315
|
.select("current_version")
|
|
310
316
|
.where("id", "=", agentId)
|
|
317
|
+
.where("org_id", "=", orgId)
|
|
311
318
|
.executeTakeFirst();
|
|
312
319
|
return row?.current_version ?? 1;
|
|
313
320
|
}
|
|
@@ -423,6 +430,7 @@ let TitleGenerator = class TitleGenerator {
|
|
|
423
430
|
* Appends the call's `usage` event (owing its `usage.report` delivery) and writes the title while
|
|
424
431
|
* `title_source IS NULL` (a rename wins), in one transaction.
|
|
425
432
|
*/
|
|
433
|
+
// org-filter: the title job's kernel-written conversation id, claimed by runTitleJob
|
|
426
434
|
async writeResult(conversationId, attempt, out, title) {
|
|
427
435
|
// Append first: it locks the conversation row FOR UPDATE before this transaction touches it.
|
|
428
436
|
// Updating the title first held the row FOR NO KEY UPDATE, which lets in another
|
|
@@ -10,6 +10,8 @@ const TREE_MAX_LEVELS = 16;
|
|
|
10
10
|
* below `conversationId` (0 for the conversation itself), shallowest first. Deleted conversations
|
|
11
11
|
* are included (a deleted root's tree is still stopped); an unknown id yields nothing.
|
|
12
12
|
*/
|
|
13
|
+
// org-filter: walks parent links from a conversation the caller resolved in its org; a sub-agent
|
|
14
|
+
// conversation is always created in its parent's org
|
|
13
15
|
export async function conversationTree(db, conversationId) {
|
|
14
16
|
const r = await sql `
|
|
15
17
|
WITH RECURSIVE tree(id, level) AS (
|
|
@@ -27,6 +29,8 @@ export async function conversationTree(db, conversationId) {
|
|
|
27
29
|
* sub-agent), nearest first: its parent, the parent's parent and so on up to the root, through
|
|
28
30
|
* `conversations.parent_conversation_id`. Empty for a root or an unknown id.
|
|
29
31
|
*/
|
|
32
|
+
// org-filter: walks parent links only; callers either resolved the id in their org or only test
|
|
33
|
+
// whether their own root is an ancestor (inTree), which a conversation of another org never has
|
|
30
34
|
export async function conversationAncestors(db, conversationId) {
|
|
31
35
|
const r = await sql `
|
|
32
36
|
WITH RECURSIVE up(id, parent, level) AS (
|
|
@@ -49,6 +53,8 @@ export async function conversationAncestors(db, conversationId) {
|
|
|
49
53
|
* while such a path holds the root and waits for the child (40P01). Returns the ids locked (the
|
|
50
54
|
* requested ones and their ancestors); an unknown id is skipped.
|
|
51
55
|
*/
|
|
56
|
+
// org-filter: locks conversations the caller resolved in its org and their ancestors, which a
|
|
57
|
+
// sub-agent conversation always shares the org with
|
|
52
58
|
export async function lockConversationTrees(db, ids) {
|
|
53
59
|
const wanted = [...new Set(ids)];
|
|
54
60
|
if (wanted.length === 0)
|
|
@@ -281,7 +281,9 @@ export interface ExtensionOrgConfigsTable {
|
|
|
281
281
|
plugin: string;
|
|
282
282
|
org_id: string;
|
|
283
283
|
enabled: Generated<boolean>;
|
|
284
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* Retired (the org-only config): neither read nor written; dropped by a later contract migration.
|
|
286
|
+
*/
|
|
285
287
|
config: ColumnType<Record<string, unknown> | null, string | null | undefined, string | null>;
|
|
286
288
|
updated_by: string | null;
|
|
287
289
|
updated_at: Ts;
|
|
@@ -294,6 +294,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
294
294
|
.selectFrom("conversations")
|
|
295
295
|
.select("device_id")
|
|
296
296
|
.where("id", "=", conversationId)
|
|
297
|
+
.where("org_id", "=", orgId)
|
|
297
298
|
.executeTakeFirstOrThrow();
|
|
298
299
|
if (before.device_id !== null)
|
|
299
300
|
return before.device_id;
|
|
@@ -302,12 +303,14 @@ let ConversationDevices = class ConversationDevices {
|
|
|
302
303
|
.updateTable("conversations")
|
|
303
304
|
.set({ device_id: deviceId })
|
|
304
305
|
.where("id", "=", conversationId)
|
|
306
|
+
.where("org_id", "=", orgId)
|
|
305
307
|
.where("device_id", "is", null)
|
|
306
308
|
.execute();
|
|
307
309
|
const row = await this.db
|
|
308
310
|
.selectFrom("conversations")
|
|
309
311
|
.select("device_id")
|
|
310
312
|
.where("id", "=", conversationId)
|
|
313
|
+
.where("org_id", "=", orgId)
|
|
311
314
|
.executeTakeFirstOrThrow();
|
|
312
315
|
return row.device_id ?? deviceId;
|
|
313
316
|
}
|
|
@@ -258,6 +258,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
258
258
|
.selectFrom("conversations")
|
|
259
259
|
.select("id")
|
|
260
260
|
.where("device_id", "=", deviceId)
|
|
261
|
+
.where("org_id", "=", orgId)
|
|
261
262
|
.where("project_name", "=", name)
|
|
262
263
|
.where("project_path", "=", gone.path)
|
|
263
264
|
.execute();
|
|
@@ -272,6 +273,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
272
273
|
permission_revision: eb("permission_revision", "+", 1),
|
|
273
274
|
}))
|
|
274
275
|
.where("id", "in", [...affected])
|
|
276
|
+
.where("org_id", "=", orgId)
|
|
275
277
|
.where("permission_profile", "=", "full-access")
|
|
276
278
|
.execute();
|
|
277
279
|
await audit(this.db.db, {
|
|
@@ -420,6 +420,7 @@ let DevicesService = class DevicesService {
|
|
|
420
420
|
.selectFrom("devices")
|
|
421
421
|
.select(["network_mode", "network_hosts"])
|
|
422
422
|
.where("id", "=", id)
|
|
423
|
+
.where("org_id", "=", orgId)
|
|
423
424
|
.executeTakeFirstOrThrow();
|
|
424
425
|
const own = ownNetwork(row);
|
|
425
426
|
const from = { mode: own.networkMode, hosts: [...own.networkHosts] };
|
|
@@ -475,6 +476,7 @@ let DevicesService = class DevicesService {
|
|
|
475
476
|
updated_at: sql `now()`,
|
|
476
477
|
})
|
|
477
478
|
.where("id", "=", id)
|
|
479
|
+
.where("org_id", "=", orgId)
|
|
478
480
|
.execute();
|
|
479
481
|
await this.ceilings.publishLocked({ orgId, deviceId: id }, "device", (scope, intent) => networkNarrowingRevokes(next, scope, intent), widened);
|
|
480
482
|
await audit(this.db.db, {
|
|
@@ -537,6 +539,7 @@ let DevicesService = class DevicesService {
|
|
|
537
539
|
.selectFrom("devices")
|
|
538
540
|
.select(["network_mode", "network_hosts"])
|
|
539
541
|
.where("id", "=", id)
|
|
542
|
+
.where("org_id", "=", orgId)
|
|
540
543
|
.executeTakeFirstOrThrow();
|
|
541
544
|
const own = ownNetwork(row);
|
|
542
545
|
if (own.networkMode === "none")
|
|
@@ -613,6 +616,7 @@ let DevicesService = class DevicesService {
|
|
|
613
616
|
.updateTable("devices")
|
|
614
617
|
.set({ name, updated_at: sql `now()` })
|
|
615
618
|
.where("id", "=", id)
|
|
619
|
+
.where("org_id", "=", orgId)
|
|
616
620
|
.execute();
|
|
617
621
|
}
|
|
618
622
|
catch (e) {
|
|
@@ -658,6 +662,7 @@ let DevicesService = class DevicesService {
|
|
|
658
662
|
.updateTable("devices")
|
|
659
663
|
.set({ deleted_at: sql `now()`, updated_at: sql `now()` })
|
|
660
664
|
.where("id", "=", id)
|
|
665
|
+
.where("org_id", "=", orgId)
|
|
661
666
|
.execute();
|
|
662
667
|
await this.db
|
|
663
668
|
.deleteFrom("device_defaults")
|