@capybara-hq/kernel 0.1.0-rc.77 → 0.1.0-rc.79
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 +9 -0
- package/dist/catalog/catalog-content.js +3 -1
- 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.d.ts +4 -1
- package/dist/catalog/component-state.js +4 -2
- package/dist/catalog/marketplace-fetch.d.ts +1 -1
- package/dist/catalog/marketplace-fetch.js +1 -1
- 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.d.ts +3 -0
- package/dist/catalog/plugin-import.js +10 -1
- 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/template-description.d.ts +17 -0
- package/dist/catalog/template-description.js +18 -0
- 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/config/schema.d.ts +1 -1
- package/dist/config/schema.js +13 -13
- 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 +5 -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 +80 -1
- package/dist/extensions/plugin-icons.js +211 -2
- package/dist/extensions/point-defaults.d.ts +17 -18
- package/dist/extensions/point-defaults.js +25 -28
- package/dist/git/gateway.js +1 -1
- package/dist/git/identity.d.ts +1 -1
- package/dist/git/identity.js +2 -2
- 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/net/public-address.d.ts +3 -3
- package/dist/net/public-address.js +3 -3
- 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 +10 -2
- package/dist/packages/npm.js +38 -6
- 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/connectors.ops.js +7 -1
- 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 +37 -9
- package/dist/tools/connectors.controller.js +47 -12
- package/dist/tools/connectors.schemas.d.ts +4 -0
- package/dist/tools/connectors.schemas.js +13 -1
- package/dist/tools/connectors.service.d.ts +17 -0
- package/dist/tools/connectors.service.js +36 -2
- package/dist/tools/drift.js +5 -0
- package/dist/tools/git-push-policy.js +3 -0
- package/dist/tools/oauth/discovery.d.ts +2 -2
- package/dist/tools/oauth/discovery.js +2 -2
- 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/src/migrations/0181_connector_description.sql +3 -0
|
@@ -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;
|
|
@@ -648,6 +650,8 @@ export interface ConnectorsTable {
|
|
|
648
650
|
* re-enables exactly the connectors it disabled.
|
|
649
651
|
*/
|
|
650
652
|
disabled_by_plugin_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
653
|
+
/** 0181: the connector's own description, set by an org admin (null: none). */
|
|
654
|
+
description: ColumnType<string | null, string | null | undefined, string | null>;
|
|
651
655
|
}
|
|
652
656
|
/**
|
|
653
657
|
* 0104: a member's own policy for one tool of a personal-credential connector, for calls made with
|
|
@@ -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")
|
|
@@ -52,6 +52,8 @@ let LegacySandboxCleanupJob = class LegacySandboxCleanupJob {
|
|
|
52
52
|
this.log.info("legacy sandboxes destroyed", { ...res });
|
|
53
53
|
}
|
|
54
54
|
/** One run (see the class); `signal` (the stop, or a lost run lock) is read between rows. */
|
|
55
|
+
// org-filter: deployment-wide sweep of the legacy sandboxes table across all orgs
|
|
56
|
+
// (LockedInterval), each row keyed by its own conversation id
|
|
55
57
|
async runOnce(now = new Date(), signal) {
|
|
56
58
|
const any = await this.db
|
|
57
59
|
.selectFrom("sandboxes")
|
|
@@ -96,12 +98,13 @@ let LegacySandboxCleanupJob = class LegacySandboxCleanupJob {
|
|
|
96
98
|
? AbortSignal.any([signal, AbortSignal.timeout(CALL_TIMEOUT_MS)])
|
|
97
99
|
: AbortSignal.timeout(CALL_TIMEOUT_MS);
|
|
98
100
|
try {
|
|
99
|
-
|
|
101
|
+
// no device lease holds a legacy row: nothing to fence the destroy with
|
|
102
|
+
await impl.destroyByName(name, callSignal(), null);
|
|
100
103
|
await impl.destroyFileSystemByName(name, callSignal());
|
|
101
104
|
if (row.prev_provider !== null && row.prev_provider !== row.provider) {
|
|
102
105
|
const prev = this.providers.forDevice(row.prev_provider)?.impl;
|
|
103
106
|
if (prev !== undefined)
|
|
104
|
-
await prev.destroyByName(name, callSignal());
|
|
107
|
+
await prev.destroyByName(name, callSignal(), null);
|
|
105
108
|
else {
|
|
106
109
|
this.log.warn("legacy sandbox of a replaced provider left: provider not loaded", {
|
|
107
110
|
name,
|
package/dist/dial-in/handlers.js
CHANGED
|
@@ -29,6 +29,8 @@ let DialInHandlers = class DialInHandlers {
|
|
|
29
29
|
this.selection = selection;
|
|
30
30
|
this.registry = registry;
|
|
31
31
|
}
|
|
32
|
+
// org-filter: deviceId is the device of an authenticated machine connection (the gateway); the
|
|
33
|
+
// device row supplies its org
|
|
32
34
|
async forDevice(deviceId) {
|
|
33
35
|
const row = await this.kdb.db
|
|
34
36
|
.selectFrom("devices")
|
package/dist/dial-in/machines.js
CHANGED
|
@@ -60,6 +60,7 @@ let DialInMachines = class DialInMachines {
|
|
|
60
60
|
.selectFrom("device_machines")
|
|
61
61
|
.select(["name", "os", "arch"])
|
|
62
62
|
.where("device_id", "=", input.deviceId)
|
|
63
|
+
.where("org_id", "=", input.orgId)
|
|
63
64
|
.orderBy("created_at", "desc")
|
|
64
65
|
.orderBy("id", "desc")
|
|
65
66
|
.limit(1)
|
|
@@ -68,7 +69,7 @@ let DialInMachines = class DialInMachines {
|
|
|
68
69
|
const moved = prev !== undefined && !sameMachine(prev, input);
|
|
69
70
|
// no stop frame: it would wait on the list and could reach the replacement machine instead
|
|
70
71
|
await this.revokeActive(input.deviceId, "replaced");
|
|
71
|
-
await this.resetInstance(input.deviceId, moved);
|
|
72
|
+
await this.resetInstance(input.orgId, input.deviceId, moved);
|
|
72
73
|
const credential = MACHINE_CREDENTIAL_PREFIX + randomBytes(32).toString("base64url");
|
|
73
74
|
const row = await this.db
|
|
74
75
|
.insertInto("device_machines")
|
|
@@ -98,7 +99,7 @@ let DialInMachines = class DialInMachines {
|
|
|
98
99
|
* or arch differ from the device's previous machine) has other files. Another directory on
|
|
99
100
|
* the same machine is known only to the provider (from the new machine's first hello).
|
|
100
101
|
*/
|
|
101
|
-
async resetInstance(deviceId, moved) {
|
|
102
|
+
async resetInstance(orgId, deviceId, moved) {
|
|
102
103
|
await this.db
|
|
103
104
|
.updateTable("device_instances")
|
|
104
105
|
.set((eb) => ({
|
|
@@ -114,6 +115,7 @@ let DialInMachines = class DialInMachines {
|
|
|
114
115
|
: sql `CASE WHEN fs_status = 'lost' THEN fs_resets + 1 ELSE fs_resets END`,
|
|
115
116
|
}))
|
|
116
117
|
.where("device_id", "=", deviceId)
|
|
118
|
+
.where("org_id", "=", orgId)
|
|
117
119
|
.execute();
|
|
118
120
|
}
|
|
119
121
|
/**
|
|
@@ -150,6 +152,7 @@ let DialInMachines = class DialInMachines {
|
|
|
150
152
|
: null;
|
|
151
153
|
}
|
|
152
154
|
/** Whether the device is deleted (soft-deleted, or gone): why its credential stopped working. */
|
|
155
|
+
// org-filter: deviceId is the device of the connection's authenticated machine credential
|
|
153
156
|
async isDeviceDeleted(deviceId) {
|
|
154
157
|
const row = await this.db
|
|
155
158
|
.selectFrom("devices")
|
|
@@ -164,6 +167,7 @@ let DialInMachines = class DialInMachines {
|
|
|
164
167
|
* host's boot identity (none clears the stored one). Marks the machine seen. A revoked machine
|
|
165
168
|
* is left alone.
|
|
166
169
|
*/
|
|
170
|
+
// org-filter: machineId is the connection's authenticated machine credential, not caller input
|
|
167
171
|
async recordConnect(machineId, program) {
|
|
168
172
|
await this.db
|
|
169
173
|
.updateTable("device_machines")
|
|
@@ -179,6 +183,7 @@ let DialInMachines = class DialInMachines {
|
|
|
179
183
|
.execute();
|
|
180
184
|
}
|
|
181
185
|
/** Marks the machine seen (a ping); writes at most once every 60 seconds. */
|
|
186
|
+
// org-filter: machineId is the connection's authenticated machine credential, not caller input
|
|
182
187
|
async touch(machineId) {
|
|
183
188
|
await this.db
|
|
184
189
|
.updateTable("device_machines")
|
|
@@ -197,6 +202,8 @@ let DialInMachines = class DialInMachines {
|
|
|
197
202
|
* the revoked machine's id. Used by {@link issue} (`replaced`) and the device's deletion
|
|
198
203
|
* (`deleted`).
|
|
199
204
|
*/
|
|
205
|
+
// org-filter: deviceId is a device the caller already checked in its org (issue's sign-in
|
|
206
|
+
// confirmation, the device's deletion); the device row supplies the org for the locks
|
|
200
207
|
async revokeActive(deviceId, reason) {
|
|
201
208
|
const device = await this.db
|
|
202
209
|
.selectFrom("devices")
|
|
@@ -222,6 +229,7 @@ let DialInMachines = class DialInMachines {
|
|
|
222
229
|
* Revokes one machine by id (a sign-in whose credential never reached the program), with the
|
|
223
230
|
* same post-commit disconnect as a replacement (no stop frame). True when it was active.
|
|
224
231
|
*/
|
|
232
|
+
// org-filter: machineId was issued by this sign-in flow (DialInAuth.abandon), not caller input
|
|
225
233
|
async revokeMachine(machineId) {
|
|
226
234
|
const machine = await this.db
|
|
227
235
|
.selectFrom("device_machines")
|
|
@@ -246,6 +254,7 @@ let DialInMachines = class DialInMachines {
|
|
|
246
254
|
return true;
|
|
247
255
|
}
|
|
248
256
|
/** The device's active machine, or null. */
|
|
257
|
+
// org-filter: deviceId is the device the managed device context already resolved in its org
|
|
249
258
|
async activeFor(deviceId) {
|
|
250
259
|
const r = await this.db
|
|
251
260
|
.selectFrom("device_machines")
|
|
@@ -42,6 +42,4 @@ export declare class DeviceTargets {
|
|
|
42
42
|
*/
|
|
43
43
|
current(deviceId: string): Promise<DeviceConnectionInfo | null>;
|
|
44
44
|
state(deviceId: string): Promise<DeviceTargetState>;
|
|
45
|
-
/** The org of a live device, or null (missing or deleted). */
|
|
46
|
-
orgOf(deviceId: string): Promise<string | null>;
|
|
47
45
|
}
|
package/dist/dial-in/targets.js
CHANGED
|
@@ -81,16 +81,6 @@ let DeviceTargets = class DeviceTargets {
|
|
|
81
81
|
return "deleted";
|
|
82
82
|
return row.machine_id === null ? "revoked" : "active";
|
|
83
83
|
}
|
|
84
|
-
/** The org of a live device, or null (missing or deleted). */
|
|
85
|
-
async orgOf(deviceId) {
|
|
86
|
-
const row = await this.db
|
|
87
|
-
.selectFrom("devices")
|
|
88
|
-
.select("org_id")
|
|
89
|
-
.where("id", "=", deviceId)
|
|
90
|
-
.where("deleted_at", "is", null)
|
|
91
|
-
.executeTakeFirst();
|
|
92
|
-
return row?.org_id ?? null;
|
|
93
|
-
}
|
|
94
84
|
};
|
|
95
85
|
DeviceTargets = __decorate([
|
|
96
86
|
Injectable(),
|
package/dist/errors.d.ts
CHANGED
|
@@ -113,7 +113,6 @@ export declare const ERROR_CODES: {
|
|
|
113
113
|
/** The extension registers no tool of that name (org tool switches, layering spec A §7). */
|
|
114
114
|
readonly "extension.tool_not_found": 404;
|
|
115
115
|
readonly "extension.unavailable": 503;
|
|
116
|
-
readonly "extension.no_org_config": 400;
|
|
117
116
|
readonly "extension.config_invalid": 400;
|
|
118
117
|
readonly "extension.config_readonly": 409;
|
|
119
118
|
readonly "extension.field_not_overridable": 400;
|
package/dist/errors.js
CHANGED
|
@@ -113,7 +113,6 @@ export const ERROR_CODES = {
|
|
|
113
113
|
/** The extension registers no tool of that name (org tool switches, layering spec A §7). */
|
|
114
114
|
"extension.tool_not_found": 404,
|
|
115
115
|
"extension.unavailable": 503,
|
|
116
|
-
"extension.no_org_config": 400,
|
|
117
116
|
"extension.config_invalid": 400,
|
|
118
117
|
"extension.config_readonly": 409,
|
|
119
118
|
"extension.field_not_overridable": 400,
|
package/dist/evals/budget.js
CHANGED
|
@@ -26,6 +26,8 @@ export const usageTokens = (u) => u.inputTokens + u.outputTokens + u.cacheReadTo
|
|
|
26
26
|
* 累加用量:`UPDATE … RETURNING`,累加后 ≥ 上限且运行仍在执行 → 同一语句置 `capped`、记 `finished_at`。
|
|
27
27
|
* 运行已不在(被删)时返回 `{ used: 0, capped: true }`,调用方同样停下。
|
|
28
28
|
*/
|
|
29
|
+
// org-filter: by run id only; callers pass a run id read under an org filter or from a kernel-written
|
|
30
|
+
// eval job payload (worker), never a raw caller-supplied id
|
|
29
31
|
export async function consumeTokens(db, runId, tokens) {
|
|
30
32
|
const n = Math.max(0, Math.trunc(tokens));
|
|
31
33
|
const reaches = sql `tokens_used + ${n} >= token_cap AND status IN ('queued', 'running')`;
|
|
@@ -53,6 +55,8 @@ export const TOO_MANY_ERRORS = {
|
|
|
53
55
|
* 同一语句置 `failed`、记原因与 `finished_at`;成功 → 清零。返回运行是否因此被熔断。
|
|
54
56
|
* 多个任务并发时「连续」按写入顺序计(近似),足以挡住「每个请求都失败」的运行。
|
|
55
57
|
*/
|
|
58
|
+
// org-filter: by run id only; callers pass a run id read under an org filter or from a kernel-written
|
|
59
|
+
// eval job payload (worker), never a raw caller-supplied id
|
|
56
60
|
export async function recordOutcome(db, runId, ok, maxConsecutive) {
|
|
57
61
|
if (ok) {
|
|
58
62
|
await db
|
|
@@ -85,6 +89,8 @@ export async function recordOutcome(db, runId, ok, maxConsecutive) {
|
|
|
85
89
|
* 运行停下(取消 / 越限 / 熔断 / 删除评测集)时:还在等评委的结果(`judge_status = 'pending'`)记 `skipped`,
|
|
86
90
|
* 否则这些用例永远算不上做完。给了 `caseId` 只处理该用例。在途的评委请求做完后写不进来(条件是 pending),用量照样计入。
|
|
87
91
|
*/
|
|
92
|
+
// org-filter: by run id only; callers pass a run id read under an org filter or from a kernel-written
|
|
93
|
+
// eval job payload (worker), never a raw caller-supplied id
|
|
88
94
|
export async function skipPendingJudges(db, runId, caseId) {
|
|
89
95
|
let q = db
|
|
90
96
|
.updateTable("eval_results")
|
|
@@ -131,6 +137,8 @@ let EvalBudget = class EvalBudget {
|
|
|
131
137
|
* worker 每做完一个用例、取消、入队失败时都调用。Joins the caller's transaction (the lock is released with it),
|
|
132
138
|
* else runs in its own.
|
|
133
139
|
*/
|
|
140
|
+
// org-filter: by run id only; callers pass a run id read under an org filter or from a
|
|
141
|
+
// kernel-written eval job payload (worker), never a raw caller-supplied id
|
|
134
142
|
async recountCases(runId) {
|
|
135
143
|
const db = this.db.db;
|
|
136
144
|
const row = await db
|
|
@@ -172,7 +180,11 @@ let EvalBudget = class EvalBudget {
|
|
|
172
180
|
.where("status", "in", [...ACTIVE_EVAL_STATUSES]);
|
|
173
181
|
if (scope.agentId !== undefined) {
|
|
174
182
|
const agentId = scope.agentId;
|
|
175
|
-
q = q.where("set_id", "in", (eb) => eb
|
|
183
|
+
q = q.where("set_id", "in", (eb) => eb
|
|
184
|
+
.selectFrom("eval_sets")
|
|
185
|
+
.select("id")
|
|
186
|
+
.where("agent_id", "=", agentId)
|
|
187
|
+
.where("org_id", "=", scope.orgId));
|
|
176
188
|
}
|
|
177
189
|
const runs = await q.returning("id").execute();
|
|
178
190
|
for (const r of runs) {
|
|
@@ -192,6 +204,7 @@ let EvalBudget = class EvalBudget {
|
|
|
192
204
|
* A run that stopped (cancelled, its set deleted): its results not started yet are `skipped`,
|
|
193
205
|
* the pending judges too, and the progress is recounted, in the caller's transaction.
|
|
194
206
|
*/
|
|
207
|
+
// org-filter: by run id only; callers cancelled the run under an org filter in the same transaction
|
|
195
208
|
async skipRun(runId) {
|
|
196
209
|
await this.db
|
|
197
210
|
.updateTable("eval_results")
|
package/dist/evals/run-replay.js
CHANGED
|
@@ -63,6 +63,7 @@ let EvalReplaySeeder = class EvalReplaySeeder {
|
|
|
63
63
|
.selectFrom("eval_runs")
|
|
64
64
|
.select("id")
|
|
65
65
|
.where("id", "=", evalRunId)
|
|
66
|
+
.where("org_id", "=", p.orgId)
|
|
66
67
|
.where("status", "in", [...ACTIVE_EVAL_STATUSES])
|
|
67
68
|
.forShare()
|
|
68
69
|
.executeTakeFirst();
|
|
@@ -256,6 +257,8 @@ export function runBaseline(s) {
|
|
|
256
257
|
* 删掉一个评测对话(崩溃重跑前清掉上一次的残留):先删它各次运行的 checkpoint,再删对话(事件、运行随之级联删除)。
|
|
257
258
|
* 只删 `kind = 'eval'` 的对话。
|
|
258
259
|
*/
|
|
260
|
+
// org-filter: the id is an eval result's own eval_conversation_id (kernel-written, read by the worker
|
|
261
|
+
// from the claimed result row), and only `kind = 'eval'` rows are deleted
|
|
259
262
|
export async function deleteEvalConversation(d, conversationId) {
|
|
260
263
|
await d.hooks?.beforeDeleteConversation?.(conversationId);
|
|
261
264
|
const runs = await d.db
|
|
@@ -334,6 +337,7 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
|
|
|
334
337
|
.selectFrom("eval_runs")
|
|
335
338
|
.select("created_by")
|
|
336
339
|
.where("id", "=", evalRunId)
|
|
340
|
+
.where("org_id", "=", s.orgId)
|
|
337
341
|
.executeTakeFirstOrThrow();
|
|
338
342
|
const accountId = run.created_by;
|
|
339
343
|
const R = start.seq;
|