@capybara-hq/kernel 0.1.0-rc.120 → 0.1.0-rc.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/background/finish.d.ts +5 -1
- package/dist/background/finish.js +29 -18
- package/dist/background/launch.d.ts +0 -5
- package/dist/background/launch.js +1 -6
- package/dist/background/managed.js +1 -4
- package/dist/background/poll.job.d.ts +3 -25
- package/dist/background/poll.job.js +20 -112
- package/dist/background/render.d.ts +2 -8
- package/dist/background/render.js +3 -17
- package/dist/background/stop.d.ts +15 -16
- package/dist/background/stop.js +39 -76
- package/dist/background/store.d.ts +17 -45
- package/dist/background/store.js +60 -94
- package/dist/background/tasks.service.d.ts +2 -5
- package/dist/background/tasks.service.js +9 -20
- package/dist/background/wake.js +3 -2
- package/dist/catalog/admin-catalog.controller.d.ts +2 -18
- package/dist/catalog/admin-catalog.controller.js +2 -28
- package/dist/catalog/catalog-content.d.ts +1 -5
- package/dist/catalog/catalog-items.d.ts +2 -6
- package/dist/catalog/catalog-items.js +5 -26
- package/dist/catalog/catalog-scope.service.d.ts +1 -121
- package/dist/catalog/catalog-scope.service.js +12 -552
- package/dist/catalog/catalog.service.d.ts +4 -15
- package/dist/catalog/catalog.service.js +7 -35
- package/dist/catalog/job-ids.d.ts +0 -18
- package/dist/catalog/job-ids.js +0 -20
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.js +6 -20
- package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
- package/dist/catalog/org-plugin-uploads.controller.js +6 -34
- package/dist/catalog/org-plugin-uploads.d.ts +3 -10
- package/dist/catalog/org-plugin-uploads.js +4 -18
- package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
- package/dist/catalog/owned-items.d.ts +6 -11
- package/dist/catalog/owned-items.js +10 -20
- package/dist/catalog/ownership.d.ts +3 -29
- package/dist/catalog/ownership.js +4 -54
- package/dist/catalog/platform-components.d.ts +5 -11
- package/dist/catalog/platform-components.js +8 -15
- package/dist/catalog/plugin-import.d.ts +3 -42
- package/dist/catalog/plugin-import.js +26 -195
- package/dist/catalog/plugin-install.js +1 -6
- package/dist/catalog/plugin-package.d.ts +1 -0
- package/dist/catalog/plugin-package.js +5 -0
- package/dist/catalog/plugin-upgrade.d.ts +3 -26
- package/dist/catalog/plugin-upgrade.js +20 -103
- package/dist/catalog/request-rules.js +4 -6
- package/dist/catalog/scope-sync.js +2 -4
- package/dist/catalog/scope.d.ts +2 -5
- package/dist/channels/jobs.d.ts +3 -3
- package/dist/channels/jobs.js +4 -3
- package/dist/channels/outbound.d.ts +1 -0
- package/dist/channels/outbound.js +32 -8
- package/dist/config/load.d.ts +0 -25
- package/dist/config/load.js +0 -57
- package/dist/config/schema.js +2 -3
- package/dist/conversations/attachments.service.js +3 -5
- package/dist/conversations/conversations.service.d.ts +3 -3
- package/dist/conversations/conversations.service.js +3 -3
- package/dist/conversations/job-org.d.ts +3 -0
- package/dist/conversations/job-org.js +11 -0
- package/dist/conversations/prompt-suggestions.d.ts +2 -7
- package/dist/conversations/prompt-suggestions.js +29 -27
- package/dist/conversations/titles.d.ts +3 -4
- package/dist/conversations/titles.js +19 -30
- package/dist/db/kernel-schema.d.ts +6 -16
- package/dist/db/pool.js +7 -2
- package/dist/devices/devices.controller.d.ts +0 -5
- package/dist/devices/devices.controller.js +2 -20
- package/dist/devices/devices.service.d.ts +1 -17
- package/dist/devices/devices.service.js +0 -22
- package/dist/errors.d.ts +1 -5
- package/dist/errors.js +1 -5
- package/dist/evals/judge.d.ts +3 -0
- package/dist/evals/judge.js +1 -1
- package/dist/evals/run-replay.d.ts +1 -1
- package/dist/evals/run-replay.js +26 -29
- package/dist/evals/step-replay.d.ts +3 -1
- package/dist/evals/step-replay.js +10 -1
- package/dist/evals/worker.d.ts +3 -1
- package/dist/evals/worker.js +53 -21
- package/dist/extensions/deployment-config-store.js +18 -14
- package/dist/extensions/effective-config.d.ts +1 -5
- package/dist/extensions/effective-config.js +1 -5
- package/dist/extensions/hooks.d.ts +3 -1
- package/dist/extensions/hooks.js +7 -2
- package/dist/extensions/installs.d.ts +2 -14
- package/dist/extensions/installs.js +10 -32
- package/dist/extensions/org-config.d.ts +3 -4
- package/dist/extensions/org-config.js +3 -4
- package/dist/extensions/plugin-guides.d.ts +0 -1
- package/dist/extensions/plugin-guides.js +0 -1
- package/dist/extensions/plugin-icons.d.ts +0 -1
- package/dist/extensions/plugin-icons.js +0 -3
- package/dist/files/blob-sweep.job.d.ts +2 -11
- package/dist/files/blob-sweep.job.js +7 -21
- package/dist/files/hash-job.d.ts +5 -15
- package/dist/files/hash-job.js +14 -33
- package/dist/files/library-jobs.module.d.ts +1 -6
- package/dist/files/library-jobs.module.js +3 -9
- package/dist/identity/api-tokens.js +54 -40
- package/dist/identity/auth.guard.js +2 -2
- package/dist/identity/sessions.js +7 -3
- package/dist/identity/settings.js +5 -21
- package/dist/inbox/inbox.service.d.ts +2 -3
- package/dist/inbox/org-notices.d.ts +0 -14
- package/dist/inbox/platform-inbox.service.d.ts +1 -8
- package/dist/inbox/platform-inbox.service.js +2 -6
- package/dist/inbox/platform-notices.d.ts +3 -3
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -3
- package/dist/infra/database/database.module.js +2 -1
- package/dist/infra/database/org-scope.d.ts +5 -3
- package/dist/infra/database/org-scope.js +7 -1
- package/dist/infra/database/scoped-dialect.d.ts +3 -1
- package/dist/infra/database/scoped-dialect.js +17 -5
- package/dist/infra/events/kernel-events.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.js +10 -0
- package/dist/infra/outbox/registry.d.ts +0 -41
- package/dist/infra/outbox/registry.js +0 -37
- package/dist/models/embeddings.d.ts +0 -5
- package/dist/models/embeddings.js +28 -35
- package/dist/models/images.d.ts +3 -8
- package/dist/models/images.js +19 -37
- package/dist/models/purposes.d.ts +7 -2
- package/dist/models/purposes.js +16 -3
- package/dist/orgs/device-network-setting.d.ts +0 -44
- package/dist/orgs/device-network-setting.js +0 -83
- package/dist/orgs/invitations.service.js +34 -30
- package/dist/orgs/offboarding.d.ts +2 -2
- package/dist/orgs/offboarding.js +2 -2
- package/dist/orgs/orgs.service.d.ts +1 -1
- package/dist/orgs/orgs.service.js +19 -15
- package/dist/orgs/settings.service.d.ts +19 -14
- package/dist/orgs/settings.service.js +12 -37
- package/dist/platform/exclusions.js +0 -11
- package/dist/platform/ops/catalog-admin.ops.js +0 -8
- package/dist/platform/ops/devices.ops.js +0 -28
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/inbox.ops.js +5 -22
- package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
- package/dist/platform/ops/org-plugins.ops.js +11 -67
- package/dist/plugin-reads/plugin-reads.service.js +2 -1
- package/dist/roles/worker.module.js +0 -9
- package/dist/runtime/hook-calls.d.ts +13 -6
- package/dist/runtime/hook-calls.js +26 -4
- package/dist/runtime/maintenance.d.ts +3 -12
- package/dist/runtime/maintenance.js +25 -55
- package/dist/runtime/model-call.d.ts +4 -2
- package/dist/runtime/model-call.js +59 -58
- package/dist/runtime/providers.d.ts +27 -1
- package/dist/runtime/providers.js +57 -0
- package/dist/runtime/run-jobs.d.ts +1 -1
- package/dist/runtime/run-processors.d.ts +3 -9
- package/dist/runtime/run-worker.d.ts +2 -0
- package/dist/runtime/run-worker.js +23 -8
- package/dist/runtime/subagents/deliveries.js +6 -1
- package/dist/runtime/subagents/dispatch.d.ts +3 -3
- package/dist/runtime/write-base.service.d.ts +2 -3
- package/dist/runtime/write-base.service.js +3 -5
- package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
- package/dist/sandbox/device-sandbox-settings.js +19 -325
- package/dist/sandbox/jobs.d.ts +3 -14
- package/dist/sandbox/jobs.js +2 -20
- package/dist/sandbox/modes.d.ts +5 -45
- package/dist/sandbox/modes.js +3 -60
- package/dist/sandbox/operation-authority.js +0 -11
- package/dist/sandbox/operation-intents.d.ts +32 -9
- package/dist/sandbox/operation-intents.js +241 -32
- package/dist/sandbox/operation-intents.module.js +2 -1
- package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
- package/dist/sandbox/operation-reconcile.job.js +119 -33
- package/dist/sandbox/operation-revoke.d.ts +20 -0
- package/dist/sandbox/operation-revoke.js +3 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
- package/dist/sandbox/permission-ceiling-writes.js +3 -6
- package/dist/sandbox/permission-config-publication.d.ts +1 -28
- package/dist/sandbox/permission-config-publication.js +14 -211
- package/dist/sandbox/permission-facts.d.ts +4 -15
- package/dist/sandbox/permission-facts.js +7 -29
- package/dist/sandbox/permission-instance-writes.d.ts +1 -4
- package/dist/sandbox/permission-instance-writes.js +1 -55
- package/dist/sandbox/providers.d.ts +1 -6
- package/dist/sandbox/providers.js +1 -15
- package/dist/sandbox/review/classifier.js +12 -13
- package/dist/sandbox/sandbox.module.js +3 -6
- package/dist/sandbox/sandbox.service.d.ts +17 -123
- package/dist/sandbox/sandbox.service.js +239 -998
- package/dist/shares/liveness.d.ts +1 -2
- package/dist/shares/liveness.js +1 -2
- package/dist/shares/shares.module.d.ts +1 -2
- package/dist/shares/shares.module.js +2 -5
- package/dist/shares/shares.service.js +1 -2
- package/dist/tools/builtins/image/generate.js +7 -15
- package/dist/tools/builtins/sandbox/common.d.ts +0 -2
- package/dist/tools/builtins/sandbox/common.js +1 -27
- package/dist/tools/builtins/sandbox/task-list.js +10 -10
- package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
- package/dist/tools/builtins/sandbox/task-output.js +13 -83
- package/dist/tools/builtins/sandbox/task-stop.js +18 -22
- package/dist/tools/builtins/vision/read-image.js +9 -10
- package/dist/tools/builtins/web/extract.js +9 -10
- package/package.json +3 -3
- package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
- package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
- package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
- package/dist/background/retire-legacy-tasks.job.js +0 -149
- package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
- package/dist/catalog/owned-plugin-cleanup.js +0 -140
- package/dist/config/permission-migration.d.ts +0 -34
- package/dist/config/permission-migration.js +0 -115
- package/dist/devices/legacy-cleanup.job.d.ts +0 -34
- package/dist/devices/legacy-cleanup.job.js +0 -147
- package/dist/files/library-backfill.d.ts +0 -63
- package/dist/files/library-backfill.js +0 -143
- package/dist/infra/cli/permission-cutover.d.ts +0 -59
- package/dist/infra/cli/permission-cutover.js +0 -107
- package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
- package/dist/sandbox/cloud-permission-snapshot.js +0 -430
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
- package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
- package/dist/sandbox/legacy-retirement.d.ts +0 -284
- package/dist/sandbox/legacy-retirement.js +0 -1165
- package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
- package/dist/sandbox/legacy-retirement.module.js +0 -25
- package/dist/shares/share-objects.d.ts +0 -47
- package/dist/shares/share-objects.js +0 -93
|
@@ -565,9 +565,9 @@ let ConversationsService = class ConversationsService {
|
|
|
565
565
|
/**
|
|
566
566
|
* Soft-deletes a conversation (owner only; a sub-agent's conversation is `conversation.read_only`):
|
|
567
567
|
* stops an active run, hides the conversation everywhere for its owner and drops its channel
|
|
568
|
-
* bindings,
|
|
569
|
-
*
|
|
570
|
-
*
|
|
568
|
+
* bindings, requests cancellation of every running background task in its sandbox (its
|
|
569
|
+
* sub-agents' too) after commit, then stops every active run of its sub-agent tree (agent map
|
|
570
|
+
* spec §10). Task cancellations stay owed until the provider confirms them. The tasks
|
|
571
571
|
* are stopped after the conversation is marked deleted, so no finish
|
|
572
572
|
* (the stops' own, or one the poller writes meanwhile) can wake a run on it: `ensureRun` refuses a
|
|
573
573
|
* deleted conversation (the stops' finishes carry `stoppedBy: "deletion"` as well). The event
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
2
|
+
/** Looks up the owning org before a worker processes a conversation job. */
|
|
3
|
+
export async function resolveConversationOrg(db, conversationId) {
|
|
4
|
+
// org-filter: deployment-wide lookup of the org for a queued conversation id
|
|
5
|
+
const row = await asPlatform("resolve the org of a queued conversation", () => db
|
|
6
|
+
.selectFrom("conversations")
|
|
7
|
+
.select("org_id")
|
|
8
|
+
.where("id", "=", conversationId)
|
|
9
|
+
.executeTakeFirst());
|
|
10
|
+
return row?.org_id;
|
|
11
|
+
}
|
|
@@ -86,13 +86,8 @@ export declare class PromptSuggestionGenerator {
|
|
|
86
86
|
* or why it gets no suggestion.
|
|
87
87
|
*/
|
|
88
88
|
private runFacts;
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
* failing closed (a policy extension not loaded on this replica denies), then observe. A denial
|
|
92
|
-
* writes the `hook.denied` audit row (`detail.purpose: "suggestion"`) and no `hook_denied`
|
|
93
|
-
* event (the call is not a step of the run).
|
|
94
|
-
*/
|
|
95
|
-
private allowed;
|
|
89
|
+
/** Audits a denied suggestion request, which is outside the run's steps. */
|
|
90
|
+
private recordDenial;
|
|
96
91
|
/**
|
|
97
92
|
* `model.response` for a sent call (observe only, not awaited). The hooks run on `lifecycle`
|
|
98
93
|
* (the worker stopping), never on the call's own signal: a timed-out call still reports.
|
|
@@ -23,17 +23,19 @@ import { IdentityModule } from "../identity/identity.module.js";
|
|
|
23
23
|
import { SettingsService } from "../identity/settings.js";
|
|
24
24
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
25
25
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
26
|
+
import { withOrgScope } from "../infra/database/org-scope.js";
|
|
26
27
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
27
28
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
28
29
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
29
30
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
30
31
|
import { OrgSettingsModule, OrgSettingsService } from "../orgs/settings.service.js";
|
|
31
32
|
import { resolveCompactionSettings } from "../runtime/compaction-settings.service.js";
|
|
32
|
-
import { fireObserve, hookDeniedAudit, hookDeniedEvent,
|
|
33
|
+
import { fireObserve, hookDeniedAudit, hookDeniedEvent, } from "../runtime/hook-calls.js";
|
|
33
34
|
import { consumeModelStream, deltaChars } from "../runtime/model-call.js";
|
|
34
|
-
import { ProviderRegistry, ProvidersModule } from "../runtime/providers.js";
|
|
35
|
+
import { ModelRequestDenied, ProviderRegistry, ProvidersModule, prepareModelStream, } from "../runtime/providers.js";
|
|
35
36
|
import { UsageReportJobs, UsageReportJobsModule } from "../runtime/usage-report-jobs.js";
|
|
36
37
|
import { EventLog, EventLogModule } from "./event-log.js";
|
|
38
|
+
import { resolveConversationOrg } from "./job-org.js";
|
|
37
39
|
import { buildSuggestionRequest, cleanSuggestion, lastModelCallOf, PROMPT_SUGGESTION_TIMEOUT_MS, suggestionEligible, suggestionStale, } from "./prompt-suggestion-request.js";
|
|
38
40
|
import { PromptSuggestionStore } from "./prompt-suggestion-store.js";
|
|
39
41
|
/**
|
|
@@ -204,15 +206,31 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
204
206
|
runId,
|
|
205
207
|
};
|
|
206
208
|
const signal = AbortSignal.any([AbortSignal.timeout(this.timeoutMs()), shutdown]);
|
|
207
|
-
|
|
209
|
+
let stream;
|
|
210
|
+
try {
|
|
211
|
+
stream = await prepareModelStream(provider, request, {
|
|
212
|
+
...ref,
|
|
213
|
+
orgId: scope.orgId,
|
|
214
|
+
purpose: "suggestion",
|
|
215
|
+
hooks: this.host?.hooks,
|
|
216
|
+
scope,
|
|
217
|
+
step: 0,
|
|
218
|
+
attempt: 1,
|
|
219
|
+
}, signal, this.log);
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
if (!(err instanceof ModelRequestDenied))
|
|
223
|
+
throw err;
|
|
224
|
+
await this.recordDenial(scope, err.verdict);
|
|
208
225
|
return;
|
|
226
|
+
}
|
|
209
227
|
if (signal.aborted)
|
|
210
228
|
return skip("shutdown");
|
|
211
229
|
const sentAt = Date.now();
|
|
212
230
|
let streamedChars = 0;
|
|
213
231
|
let out;
|
|
214
232
|
try {
|
|
215
|
-
out = await consumeModelStream(
|
|
233
|
+
out = await consumeModelStream(stream, request.model, info.streamIdleTimeoutMs ?? this.config.get().runtime.streamIdleMs, signal, (ev) => {
|
|
216
234
|
streamedChars += deltaChars(ev);
|
|
217
235
|
}, this.log);
|
|
218
236
|
}
|
|
@@ -310,27 +328,8 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
310
328
|
afterSeq: Number(finished.seq),
|
|
311
329
|
};
|
|
312
330
|
}
|
|
313
|
-
/**
|
|
314
|
-
|
|
315
|
-
* failing closed (a policy extension not loaded on this replica denies), then observe. A denial
|
|
316
|
-
* writes the `hook.denied` audit row (`detail.purpose: "suggestion"`) and no `hook_denied`
|
|
317
|
-
* event (the call is not a step of the run).
|
|
318
|
-
*/
|
|
319
|
-
async allowed(scope, ref, request, signal) {
|
|
320
|
-
const hooks = this.host?.hooks;
|
|
321
|
-
if (!hooks?.has("model.request"))
|
|
322
|
-
return true;
|
|
323
|
-
const verdict = await hooks.run("model.request", {
|
|
324
|
-
...scope,
|
|
325
|
-
purpose: "suggestion",
|
|
326
|
-
step: 0,
|
|
327
|
-
attempt: 1,
|
|
328
|
-
provider: ref.provider,
|
|
329
|
-
model: ref.model,
|
|
330
|
-
request: hookRequestOf(request, this.log),
|
|
331
|
-
}, signal);
|
|
332
|
-
if (verdict.allowed)
|
|
333
|
-
return true;
|
|
331
|
+
/** Audits a denied suggestion request, which is outside the run's steps. */
|
|
332
|
+
async recordDenial(scope, verdict) {
|
|
334
333
|
const site = {
|
|
335
334
|
orgId: scope.orgId,
|
|
336
335
|
conversationId: scope.conversationId,
|
|
@@ -348,7 +347,6 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
348
347
|
plugin: verdict.plugin,
|
|
349
348
|
cause: verdict.cause,
|
|
350
349
|
});
|
|
351
|
-
return false;
|
|
352
350
|
}
|
|
353
351
|
/**
|
|
354
352
|
* `model.response` for a sent call (observe only, not awaited). The hooks run on `lifecycle`
|
|
@@ -520,7 +518,11 @@ let PromptSuggestionQueue = class PromptSuggestionQueue {
|
|
|
520
518
|
}
|
|
521
519
|
/** One suggestion job (the `@Processor` calls it). */
|
|
522
520
|
async process(j) {
|
|
523
|
-
|
|
521
|
+
const { conversationId, runId, finishedAt } = j.data;
|
|
522
|
+
const orgId = await resolveConversationOrg(this.kdb.db, conversationId);
|
|
523
|
+
if (!orgId)
|
|
524
|
+
return;
|
|
525
|
+
await withOrgScope(orgId, () => this.generator.run(conversationId, runId, finishedAt, this.stopping.signal));
|
|
524
526
|
}
|
|
525
527
|
/** Stops: no more enqueues, the call in flight is aborted (its job dropped), the worker closes. */
|
|
526
528
|
async stop() {
|
|
@@ -70,7 +70,7 @@ export interface TitleDeps {
|
|
|
70
70
|
writes: Pick<TitleGenerator, "writeResult" | "writeUsage" | "auditDenied">;
|
|
71
71
|
}
|
|
72
72
|
/** The attempt number to enqueue for this conversation, or null when no title job is due. */
|
|
73
|
-
export declare function titleAttemptDue(db: KernelSchemaDb, conversationId: string): Promise<number | null>;
|
|
73
|
+
export declare function titleAttemptDue(db: KernelSchemaDb, orgId: string, conversationId: string): Promise<number | null>;
|
|
74
74
|
/**
|
|
75
75
|
* One title attempt. Claims the attempt (`title_attempts = attempt` → `attempt + 1`; a second
|
|
76
76
|
* execution of the same attempt finds nothing to claim and returns), calls the model, writes the
|
|
@@ -78,7 +78,7 @@ export declare function titleAttemptDue(db: KernelSchemaDb, conversationId: stri
|
|
|
78
78
|
* no run, idempotent per attempt) in the same transaction. Errors are logged, not thrown.
|
|
79
79
|
*/
|
|
80
80
|
export declare function runTitleJob(d: TitleDeps, conversationId: string, attempt: number): Promise<void>;
|
|
81
|
-
interface TitleJob {
|
|
81
|
+
export interface TitleJob {
|
|
82
82
|
conversationId: string;
|
|
83
83
|
attempt: number;
|
|
84
84
|
}
|
|
@@ -146,7 +146,7 @@ export declare class TitleQueue {
|
|
|
146
146
|
private readonly stopping;
|
|
147
147
|
constructor(kdb: KernelDb, queue: Queue<TitleJob>, generator: Pick<TitleGenerator, "run">, log: Pick<Logger, "warn" | "error">);
|
|
148
148
|
/** Enqueues the next title attempt when one is due. Never throws (logs instead). */
|
|
149
|
-
maybeEnqueue(conversationId: string): Promise<void>;
|
|
149
|
+
maybeEnqueue(orgId: string, conversationId: string): Promise<void>;
|
|
150
150
|
/** Starts consuming (worker role only): `worker` is the `@Processor` worker of {@link TITLE_QUEUE}. */
|
|
151
151
|
startWorker(worker: Worker<TitleJob>): void;
|
|
152
152
|
/** The worker's `error` event. */
|
|
@@ -159,4 +159,3 @@ export declare class TitleQueue {
|
|
|
159
159
|
/** Conversation titles: the queue and the job (consumed on the worker role). */
|
|
160
160
|
export declare class TitlesModule {
|
|
161
161
|
}
|
|
162
|
-
export {};
|
|
@@ -15,17 +15,19 @@ import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
|
15
15
|
import { ExtensionHost } from "../extensions/host.js";
|
|
16
16
|
import { audit } from "../identity/audit.js";
|
|
17
17
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
18
|
+
import { withOrgScope } from "../infra/database/org-scope.js";
|
|
18
19
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
19
20
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
20
21
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
21
22
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
22
23
|
import { ModelsModule } from "../models/models.module.js";
|
|
23
24
|
import { ModelPurposesService, PurposeAttemptError } from "../models/purposes.js";
|
|
24
|
-
import { fireObserve, hookDeniedAudit, hookDeniedEvent,
|
|
25
|
+
import { fireObserve, hookDeniedAudit, hookDeniedEvent, } from "../runtime/hook-calls.js";
|
|
25
26
|
import { UsageReportJobs, UsageReportJobsModule } from "../runtime/usage-report-jobs.js";
|
|
26
27
|
import { HIDDEN_FORMAT_RE } from "../text.js";
|
|
27
28
|
import { EventLog, EventLogModule } from "./event-log.js";
|
|
28
29
|
import { typedInvocation } from "./events.js";
|
|
30
|
+
import { resolveConversationOrg } from "./job-org.js";
|
|
29
31
|
/**
|
|
30
32
|
* Model-generated conversation titles (UI refresh B, spec §5.1 "Titles").
|
|
31
33
|
*
|
|
@@ -121,13 +123,12 @@ const typedText = (content) => {
|
|
|
121
123
|
return first?.type === "text" ? first.text : "";
|
|
122
124
|
};
|
|
123
125
|
/** The attempt number to enqueue for this conversation, or null when no title job is due. */
|
|
124
|
-
|
|
125
|
-
// conversation's id, never with a request id
|
|
126
|
-
export async function titleAttemptDue(db, conversationId) {
|
|
126
|
+
export async function titleAttemptDue(db, orgId, conversationId) {
|
|
127
127
|
const row = await db
|
|
128
128
|
.selectFrom("conversations as c")
|
|
129
129
|
.select("c.title_attempts")
|
|
130
130
|
.where("c.id", "=", conversationId)
|
|
131
|
+
.where("c.org_id", "=", orgId)
|
|
131
132
|
.where("c.kind", "=", "chat")
|
|
132
133
|
.where("c.title", "is", null)
|
|
133
134
|
.where("c.title_source", "is", null)
|
|
@@ -183,7 +184,7 @@ export async function runTitleJob(d, conversationId, attempt) {
|
|
|
183
184
|
return;
|
|
184
185
|
if (d.signal?.aborted)
|
|
185
186
|
return;
|
|
186
|
-
// org-filter: the
|
|
187
|
+
// org-filter: the title processor runs in the org resolved from the job's conversation
|
|
187
188
|
const claimed = await d.db
|
|
188
189
|
.updateTable("conversations")
|
|
189
190
|
.set({ title_attempts: attempt + 1 })
|
|
@@ -228,8 +229,10 @@ export async function runTitleJob(d, conversationId, attempt) {
|
|
|
228
229
|
...(fallback && { fallback: { model: fallback, params: {} } }),
|
|
229
230
|
// a thinking model spends the small output budget on thinking and returns no text
|
|
230
231
|
paramDefaults: TITLE_PARAM_DEFAULTS,
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
hooks: d.hooks,
|
|
233
|
+
scope,
|
|
234
|
+
onDenied: (verdict) => recordTitleDenial(d, scope, verdict),
|
|
235
|
+
beforeSend: async (target) => {
|
|
233
236
|
sent = { ...target, at: Date.now() };
|
|
234
237
|
},
|
|
235
238
|
});
|
|
@@ -318,26 +321,8 @@ async function agentVersionOf(db, orgId, agentId) {
|
|
|
318
321
|
.executeTakeFirst();
|
|
319
322
|
return row?.current_version ?? 1;
|
|
320
323
|
}
|
|
321
|
-
/**
|
|
322
|
-
|
|
323
|
-
* (including a policy extension not loaded on this replica) writes the `hook.denied` audit row and
|
|
324
|
-
* throws {@link TitleDenied}: the title is skipped and no further attempt is made. No `hook_denied`
|
|
325
|
-
* event: the call is not a step of a run.
|
|
326
|
-
*/
|
|
327
|
-
async function checkTitleHooks(d, scope, target, request, signal) {
|
|
328
|
-
if (!d.hooks?.has("model.request"))
|
|
329
|
-
return;
|
|
330
|
-
const verdict = await d.hooks.run("model.request", {
|
|
331
|
-
...scope,
|
|
332
|
-
purpose: "title",
|
|
333
|
-
step: 0,
|
|
334
|
-
attempt: 1,
|
|
335
|
-
provider: target.provider,
|
|
336
|
-
model: target.model,
|
|
337
|
-
request: hookRequestOf(request, d.log),
|
|
338
|
-
}, signal);
|
|
339
|
-
if (verdict.allowed)
|
|
340
|
-
return;
|
|
324
|
+
/** Records the denial and stops automatic title retries. */
|
|
325
|
+
async function recordTitleDenial(d, scope, verdict) {
|
|
341
326
|
const site = {
|
|
342
327
|
orgId: scope.orgId,
|
|
343
328
|
conversationId: scope.conversationId,
|
|
@@ -513,11 +498,11 @@ let TitleQueue = class TitleQueue {
|
|
|
513
498
|
queue.on("error", (err) => this.log.error("title queue error", { err }));
|
|
514
499
|
}
|
|
515
500
|
/** Enqueues the next title attempt when one is due. Never throws (logs instead). */
|
|
516
|
-
async maybeEnqueue(conversationId) {
|
|
501
|
+
async maybeEnqueue(orgId, conversationId) {
|
|
517
502
|
if (this.closed)
|
|
518
503
|
return;
|
|
519
504
|
try {
|
|
520
|
-
const attempt = await titleAttemptDue(this.kdb.db, conversationId);
|
|
505
|
+
const attempt = await titleAttemptDue(this.kdb.db, orgId, conversationId);
|
|
521
506
|
if (attempt === null)
|
|
522
507
|
return;
|
|
523
508
|
// The previous attempt claims its number before calling the model, so a run completing
|
|
@@ -550,7 +535,11 @@ let TitleQueue = class TitleQueue {
|
|
|
550
535
|
}
|
|
551
536
|
/** One title job (the `@Processor` calls it). */
|
|
552
537
|
async process(j) {
|
|
553
|
-
|
|
538
|
+
const { conversationId, attempt } = j.data;
|
|
539
|
+
const orgId = await resolveConversationOrg(this.kdb.db, conversationId);
|
|
540
|
+
if (!orgId)
|
|
541
|
+
return;
|
|
542
|
+
await withOrgScope(orgId, () => this.generator.run(conversationId, attempt, this.stopping.signal));
|
|
554
543
|
}
|
|
555
544
|
/** Stops: no more enqueues, the call in flight is aborted, the worker closes. */
|
|
556
545
|
async stop() {
|
|
@@ -77,6 +77,7 @@ export interface SandboxOperationIntentsTable {
|
|
|
77
77
|
holder_token: Generated<string>;
|
|
78
78
|
result: Json<unknown>;
|
|
79
79
|
reconcile_attempt: Generated<number>;
|
|
80
|
+
revoke_attempt: Generated<number>;
|
|
80
81
|
outcome_unknown: Generated<boolean>;
|
|
81
82
|
revoke_acknowledged: Generated<boolean>;
|
|
82
83
|
created_at: Ts;
|
|
@@ -283,10 +284,6 @@ export interface ExtensionOrgConfigsTable {
|
|
|
283
284
|
plugin: string;
|
|
284
285
|
org_id: string;
|
|
285
286
|
enabled: Generated<boolean>;
|
|
286
|
-
/**
|
|
287
|
-
* Retired (the org-only config): neither read nor written; dropped by a later contract migration.
|
|
288
|
-
*/
|
|
289
|
-
config: ColumnType<Record<string, unknown> | null, string | null | undefined, string | null>;
|
|
290
287
|
updated_by: string | null;
|
|
291
288
|
updated_at: Ts;
|
|
292
289
|
}
|
|
@@ -969,7 +966,7 @@ export interface AttachmentsTable {
|
|
|
969
966
|
* What an attachment row is for: a chat attachment, a skill package zip, an agent avatar image, or
|
|
970
967
|
* (0163) an image the builtin Read stored with the calling conversation.
|
|
971
968
|
*/
|
|
972
|
-
export type AttachmentPurpose = "
|
|
969
|
+
export type AttachmentPurpose = "skill-package" | "agent-avatar" | "read";
|
|
973
970
|
/** 技能版本的清单(`skill_versions.manifest`)。 */
|
|
974
971
|
export interface SkillManifest {
|
|
975
972
|
name: string;
|
|
@@ -1705,7 +1702,7 @@ export interface PlatformIconsTable {
|
|
|
1705
1702
|
}
|
|
1706
1703
|
/**
|
|
1707
1704
|
* 0161: a link to a frozen snapshot of one conversation file (file sharing spec §1). The row stays
|
|
1708
|
-
* after a revoke or expiry; `
|
|
1705
|
+
* after a revoke or expiry; `blob_id` is null once the snapshot reference is released.
|
|
1709
1706
|
*/
|
|
1710
1707
|
export interface FileSharesTable {
|
|
1711
1708
|
id: string;
|
|
@@ -1721,7 +1718,6 @@ export interface FileSharesTable {
|
|
|
1721
1718
|
content_type: string;
|
|
1722
1719
|
/** bigint: pg returns it as a string. */
|
|
1723
1720
|
size: ColumnType<string, number | string, number | string>;
|
|
1724
|
-
object_key: NullableText;
|
|
1725
1721
|
generation: ColumnType<number, number | undefined, number>;
|
|
1726
1722
|
expires_at: NullableTs;
|
|
1727
1723
|
revoked_at: NullableTs;
|
|
@@ -1730,7 +1726,7 @@ export interface FileSharesTable {
|
|
|
1730
1726
|
last_opened_at: NullableTs;
|
|
1731
1727
|
created_at: Ts;
|
|
1732
1728
|
updated_at: Ts;
|
|
1733
|
-
/** 0190: the blob holding the snapshot
|
|
1729
|
+
/** 0190: the blob holding the snapshot. */
|
|
1734
1730
|
blob_id: NullableText;
|
|
1735
1731
|
/** 0190: the library file the share was made from, when it still exists. */
|
|
1736
1732
|
source_file_id: NullableText;
|
|
@@ -1985,6 +1981,7 @@ export interface DeviceInstanceRetirementIdentitiesTable {
|
|
|
1985
1981
|
attested_at: TsNullable;
|
|
1986
1982
|
}
|
|
1987
1983
|
export interface DeviceInstanceDestructionsTable {
|
|
1984
|
+
confirmed: Generated<boolean>;
|
|
1988
1985
|
device_id: string;
|
|
1989
1986
|
provider: string;
|
|
1990
1987
|
instance_generation: string;
|
|
@@ -2206,7 +2203,7 @@ export interface ExtensionClientReportsTable {
|
|
|
2206
2203
|
last_message: string;
|
|
2207
2204
|
}
|
|
2208
2205
|
/** 0084 (0121 dropped `skill_renamed`): the kinds of {@link OrgNoticesTable}. */
|
|
2209
|
-
export type OrgNoticeKind = "item_shared" | "shared_item_updated"
|
|
2206
|
+
export type OrgNoticeKind = "item_shared" | "shared_item_updated";
|
|
2210
2207
|
/** 0082: a notice for an org's admins (an inbox item), until one of them dismisses it. */
|
|
2211
2208
|
export interface OrgNoticesTable {
|
|
2212
2209
|
id: string;
|
|
@@ -2305,12 +2302,6 @@ export interface CatalogItemsTable {
|
|
|
2305
2302
|
owner_org_id: NullableDflt<string>;
|
|
2306
2303
|
/** 0084: the owner shares it with other orgs (the gate is `owner_org_id IS NULL OR shareable`). */
|
|
2307
2304
|
shareable: Dflt<boolean>;
|
|
2308
|
-
/** 0084: an upload waits for the super admin's confirmation of its permission digest. */
|
|
2309
|
-
awaiting_confirmation: Dflt<boolean>;
|
|
2310
|
-
/** 0084: the uploaded version not yet confirmed. */
|
|
2311
|
-
pending_version: NullableDflt<string>;
|
|
2312
|
-
pending_by: NullableDflt<string>;
|
|
2313
|
-
pending_at: NullableDflt<Date | string>;
|
|
2314
2305
|
}
|
|
2315
2306
|
/** 0075: the orgs a `named` item is offered to. */
|
|
2316
2307
|
export interface CatalogItemScopeOrgsTable {
|
|
@@ -2508,7 +2499,6 @@ export interface CatalogItemVersionsTable {
|
|
|
2508
2499
|
*/
|
|
2509
2500
|
applied_at: TsNullable;
|
|
2510
2501
|
/** 0084 (ruling P3-52): when the super admin rejected this pending org version. */
|
|
2511
|
-
rejected_at: TsNullable;
|
|
2512
2502
|
/**
|
|
2513
2503
|
* 0107: the keys of `suggestedAppearance.replacements` in plugin.json order (jsonb does not keep
|
|
2514
2504
|
* key order); null without replacements.
|
package/dist/db/pool.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
2
|
import pg from "pg";
|
|
3
|
-
import {
|
|
3
|
+
import { unscopedQueryCheck } from "../infra/database/org-scope.js";
|
|
4
|
+
import { captureUnscopedQueryOrigins, ScopedPostgresDialect, } from "../infra/database/scoped-dialect.js";
|
|
4
5
|
/** 内核连接池的 PG `application_name`(便于在 pg_stat_activity 中识别)。 */
|
|
5
6
|
export const KERNEL_APPLICATION_NAME = "capybara-kernel";
|
|
6
7
|
/**
|
|
@@ -29,5 +30,9 @@ export function createDb(url, poolMax, onError = (err) => console.error("[db] id
|
|
|
29
30
|
});
|
|
30
31
|
pool.on("error", onError);
|
|
31
32
|
pool.on("connect", (client) => client.on("error", opts.onClientError ?? onError));
|
|
32
|
-
|
|
33
|
+
const rls = opts.rls ?? "off";
|
|
34
|
+
return new Kysely({
|
|
35
|
+
dialect: new ScopedPostgresDialect({ pool }, rls),
|
|
36
|
+
plugins: rls !== "off" && unscopedQueryCheck() ? [captureUnscopedQueryOrigins] : [],
|
|
37
|
+
});
|
|
33
38
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FastifyReply } from "fastify";
|
|
2
1
|
import type { z } from "zod";
|
|
3
2
|
import { type Principal } from "../identity/principal.js";
|
|
4
3
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
@@ -26,7 +25,6 @@ import { type DeviceCreateBody, type DeviceParams, type DevicePatchBody, type De
|
|
|
26
25
|
* - `DELETE /:id` → 202 (destroyed by a job after the response);
|
|
27
26
|
* - `POST /:id/files/reset` → 202 (the reset is enqueued: a worker empties the files, the next use
|
|
28
27
|
* starts empty; 409 `device.files_on_device` when its provider's report offers no reset);
|
|
29
|
-
* - `POST /:id/retirement/check` → the owner's session asks the local machine for exact evidence;
|
|
30
28
|
* - a device's projects (project root design §4.1, §4.2), owner only (anyone else:
|
|
31
29
|
* `device.not_found`): `GET /:id/projects` → the ones its current mode can read;
|
|
32
30
|
* `GET /:id/projects/candidates` → the device's suggestions under its base;
|
|
@@ -53,9 +51,6 @@ export declare class DevicesController {
|
|
|
53
51
|
}>;
|
|
54
52
|
remove(principal: Principal, org: OrgContext, params: z.infer<typeof DeviceParams>): Promise<void>;
|
|
55
53
|
resetFiles(principal: Principal, org: OrgContext, params: z.infer<typeof DeviceParams>): Promise<void>;
|
|
56
|
-
checkRetirement(principal: Principal, org: OrgContext, params: z.infer<typeof DeviceParams>, reply: FastifyReply): Promise<{
|
|
57
|
-
status: "clear" | "blocked" | "busy";
|
|
58
|
-
}>;
|
|
59
54
|
listProjects(principal: Principal, org: OrgContext, params: z.infer<typeof DeviceParams>): Promise<DeviceProjectList>;
|
|
60
55
|
projectCandidates(principal: Principal, org: OrgContext, params: z.infer<typeof DeviceParams>): Promise<DeviceProjectCandidates>;
|
|
61
56
|
listProjectFiles(principal: Principal, org: OrgContext, params: z.infer<typeof DeviceProjectParams>, query: z.infer<typeof DeviceProjectFilesQuery>): Promise<ProjectFileList>;
|
|
@@ -7,9 +7,8 @@ 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, Patch, Post
|
|
11
|
-
import {
|
|
12
|
-
import { CurrentPrincipal, patTokenId, requireUser, SessionOnly, } from "../identity/principal.js";
|
|
10
|
+
import { Controller, Delete, Get, HttpCode, Inject, Patch, Post } from "@nestjs/common";
|
|
11
|
+
import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
|
|
13
12
|
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
14
13
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
15
14
|
import { DeviceProjectFilesService } from "./device-project-files.service.js";
|
|
@@ -36,7 +35,6 @@ import { DeviceCreateBodyDto, DeviceParamsDto, DevicePatchBodyDto, DeviceProject
|
|
|
36
35
|
* - `DELETE /:id` → 202 (destroyed by a job after the response);
|
|
37
36
|
* - `POST /:id/files/reset` → 202 (the reset is enqueued: a worker empties the files, the next use
|
|
38
37
|
* starts empty; 409 `device.files_on_device` when its provider's report offers no reset);
|
|
39
|
-
* - `POST /:id/retirement/check` → the owner's session asks the local machine for exact evidence;
|
|
40
38
|
* - a device's projects (project root design §4.1, §4.2), owner only (anyone else:
|
|
41
39
|
* `device.not_found`): `GET /:id/projects` → the ones its current mode can read;
|
|
42
40
|
* `GET /:id/projects/candidates` → the device's suggestions under its base;
|
|
@@ -89,12 +87,6 @@ let DevicesController = class DevicesController {
|
|
|
89
87
|
const p = requireUser(principal);
|
|
90
88
|
await this.devices.resetFiles(org.orgId, p.account.id, params.id, patTokenId(p));
|
|
91
89
|
}
|
|
92
|
-
async checkRetirement(principal, org, params, reply) {
|
|
93
|
-
const p = requireUser(principal);
|
|
94
|
-
return {
|
|
95
|
-
status: await this.devices.checkRetirement(org.orgId, p.account.id, params.id, requestSignal(reply)),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
90
|
async listProjects(principal, org, params) {
|
|
99
91
|
const p = requireUser(principal);
|
|
100
92
|
return this.projects.list(org.orgId, p.account.id, params.id);
|
|
@@ -165,16 +157,6 @@ __decorate([
|
|
|
165
157
|
__param(1, CurrentOrg()),
|
|
166
158
|
__param(2, ZParam(DeviceParamsDto))
|
|
167
159
|
], DevicesController.prototype, "resetFiles", null);
|
|
168
|
-
__decorate([
|
|
169
|
-
Post(":id/retirement/check"),
|
|
170
|
-
HttpCode(200),
|
|
171
|
-
SessionOnly(),
|
|
172
|
-
OrgAction("agents.use"),
|
|
173
|
-
__param(0, CurrentPrincipal()),
|
|
174
|
-
__param(1, CurrentOrg()),
|
|
175
|
-
__param(2, ZParam(DeviceParamsDto)),
|
|
176
|
-
__param(3, Res({ passthrough: true }))
|
|
177
|
-
], DevicesController.prototype, "checkRetirement", null);
|
|
178
160
|
__decorate([
|
|
179
161
|
Get(":id/projects"),
|
|
180
162
|
OrgAction("agents.use"),
|
|
@@ -55,22 +55,8 @@ export interface DeviceView {
|
|
|
55
55
|
machine: DeviceMachineView | null;
|
|
56
56
|
/** Its effective device sandbox, the same under every permission profile. */
|
|
57
57
|
sandbox: DeviceSandboxView;
|
|
58
|
-
/**
|
|
59
|
-
* A device whose B1 snapshot found applied limits it could not establish exactly: nothing runs
|
|
60
|
-
* on it until a file reset establishes them (`device.permission_reconcile_required` at
|
|
61
|
-
* admission).
|
|
62
|
-
*/
|
|
63
|
-
reconcileRequired: boolean;
|
|
64
58
|
/** Its file system is gone at the provider; reset the files to use it again. */
|
|
65
59
|
filesLost: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* A retirement obligation refuses every use (permission runtime cutover 8.5): `recreateRequired`
|
|
68
|
-
* when an earlier instance may still run background work no evidence can cover (quarantined:
|
|
69
|
-
* `device.recreate_required`), `pending` while a try to confirm an earlier instance destroyed
|
|
70
|
-
* failed and is retried (`device.unavailable`); null when nothing blocks it (an obligation not
|
|
71
|
-
* tried yet clears at the next use).
|
|
72
|
-
*/
|
|
73
|
-
retirement: "pending" | "recreateRequired" | null;
|
|
74
60
|
instance: {
|
|
75
61
|
status: "running" | "suspended";
|
|
76
62
|
lastUsedAt: string;
|
|
@@ -227,7 +213,7 @@ export declare class DevicesService {
|
|
|
227
213
|
private readonly dialIn;
|
|
228
214
|
/** The providers' device-connection guides. */
|
|
229
215
|
private readonly guides;
|
|
230
|
-
constructor(db: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get" | "fieldSource">, selection: Pick<DeviceProviderSelection, "onInOrg" | "isOnInOrg" | "defaultFor">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "limitsState"
|
|
216
|
+
constructor(db: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get" | "fieldSource">, selection: Pick<DeviceProviderSelection, "onInOrg" | "isOnInOrg" | "defaultFor">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "limitsState">, sandboxJobs: Pick<SandboxJobs, "resetFiles">,
|
|
231
217
|
/** Owes a deleted device's destruction in the delete's transaction. */
|
|
232
218
|
outbox: Pick<OutboxService, "add">, access: Pick<DeviceAccess, "usable">,
|
|
233
219
|
/** Whether a dial-in device's machine is connected now. */
|
|
@@ -252,8 +238,6 @@ export declare class DevicesService {
|
|
|
252
238
|
private catalogDescriptions;
|
|
253
239
|
/** One of the person's live devices; anyone else's (or a missing one) → `not_found`. */
|
|
254
240
|
get(orgId: string, accountId: string, id: string): Promise<DeviceView>;
|
|
255
|
-
/** The owner's web action; the retirement gate rechecks ownership under its lifecycle lease. */
|
|
256
|
-
checkRetirement(orgId: string, accountId: string, deviceId: string, signal: AbortSignal): Promise<"blocked" | "busy" | "clear">;
|
|
257
241
|
/**
|
|
258
242
|
* A new personal device, ready at once (its instance and files are made on first use),
|
|
259
243
|
* bound for life to `input.provider` or, without one, the org's default provider: a provider not
|
|
@@ -197,10 +197,6 @@ let DevicesService = class DevicesService {
|
|
|
197
197
|
throw deviceNotFound();
|
|
198
198
|
return view;
|
|
199
199
|
}
|
|
200
|
-
/** The owner's web action; the retirement gate rechecks ownership under its lifecycle lease. */
|
|
201
|
-
checkRetirement(orgId, accountId, deviceId, signal) {
|
|
202
|
-
return this.sandbox.checkLocalRetirement({ orgId, accountId, deviceId }, signal);
|
|
203
|
-
}
|
|
204
200
|
/**
|
|
205
201
|
* A new personal device, ready at once (its instance and files are made on first use),
|
|
206
202
|
* bound for life to `input.provider` or, without one, the org's default provider: a provider not
|
|
@@ -839,7 +835,6 @@ let DevicesService = class DevicesService {
|
|
|
839
835
|
"e.provider",
|
|
840
836
|
"e.network_mode",
|
|
841
837
|
"e.network_hosts",
|
|
842
|
-
"e.permission_reconcile_required",
|
|
843
838
|
"e.created_at",
|
|
844
839
|
"m.id as machine_id",
|
|
845
840
|
"m.name as machine_name",
|
|
@@ -879,21 +874,6 @@ let DevicesService = class DevicesService {
|
|
|
879
874
|
]);
|
|
880
875
|
return [r.id, { limits, state, box: facts.box, report }];
|
|
881
876
|
})));
|
|
882
|
-
// the devices a retirement obligation blocks: a quarantined one for good, an open one whose
|
|
883
|
-
// last try failed until a retry succeeds
|
|
884
|
-
const retirement = new Map();
|
|
885
|
-
for (const o of await this.db
|
|
886
|
-
.selectFrom("device_retirement_obligations")
|
|
887
|
-
.select(["device_id", "state", "attempts"])
|
|
888
|
-
.where("org_id", "=", orgId)
|
|
889
|
-
.where("device_id", "in", rows.map((r) => r.id))
|
|
890
|
-
.where("state", "in", ["open", "quarantined"])
|
|
891
|
-
.execute()) {
|
|
892
|
-
if (o.state === "quarantined")
|
|
893
|
-
retirement.set(o.device_id, "recreateRequired");
|
|
894
|
-
else if (o.attempts > 0 && !retirement.has(o.device_id))
|
|
895
|
-
retirement.set(o.device_id, "pending");
|
|
896
|
-
}
|
|
897
877
|
// a dial-in device is online while a replica holds its machine's connection
|
|
898
878
|
const dialIn = new Set(rows.filter((r) => this.isDialIn(r.provider)).map((r) => r.id));
|
|
899
879
|
const online = new Map(await Promise.all([...dialIn].map(async (deviceId) => [deviceId, await this.relay.online(deviceId)])));
|
|
@@ -932,9 +912,7 @@ let DevicesService = class DevicesService {
|
|
|
932
912
|
pendingFilesReset: device?.state.pendingFilesReset ?? false,
|
|
933
913
|
recent: recent.get(r.id) ?? [],
|
|
934
914
|
}),
|
|
935
|
-
reconcileRequired: r.permission_reconcile_required,
|
|
936
915
|
filesLost: r.fs_status === "lost",
|
|
937
|
-
retirement: retirement.get(r.id) ?? null,
|
|
938
916
|
instance: live
|
|
939
917
|
? {
|
|
940
918
|
status: r.status,
|
package/dist/errors.d.ts
CHANGED
|
@@ -185,8 +185,6 @@ export declare const ERROR_CODES: {
|
|
|
185
185
|
* platform item another owner has (P3-6).
|
|
186
186
|
*/
|
|
187
187
|
readonly "catalog.not_owned": 409;
|
|
188
|
-
/** The item (or the version asked for) waits for the super admin's confirmation (P3-9). */
|
|
189
|
-
readonly "catalog.item_pending": 409;
|
|
190
188
|
/** Deleting a platform plugin whose extension is still enabled on the deployment. */
|
|
191
189
|
readonly "catalog.extension_enabled": 409;
|
|
192
190
|
/** A super admin confirmation raced the item's removal (P3-21). */
|
|
@@ -290,6 +288,7 @@ export declare const ERROR_CODES: {
|
|
|
290
288
|
/** The deployment setting `orgMarketplaceBrowse` is off: no marketplace requests. */
|
|
291
289
|
readonly "catalog.marketplace_browse_disabled": 409;
|
|
292
290
|
readonly "catalog.custom_disabled": 403;
|
|
291
|
+
readonly "catalog.org_upload_code": 403;
|
|
293
292
|
readonly "catalog.not_deployed": 409;
|
|
294
293
|
/**
|
|
295
294
|
* The connector an install planned to reuse (a template it asked no input for) was removed before
|
|
@@ -321,7 +320,6 @@ export declare const ERROR_CODES: {
|
|
|
321
320
|
readonly "plugin.name_taken": 409;
|
|
322
321
|
readonly "plugin.name_reserved": 409;
|
|
323
322
|
readonly "plugin.dependency_unavailable": 409;
|
|
324
|
-
readonly "plugin.extension_upload_pending": 501;
|
|
325
323
|
readonly "plugin.staging_not_found": 404;
|
|
326
324
|
readonly "plugin.install_failed": 502;
|
|
327
325
|
readonly "plugin.install_not_found": 404;
|
|
@@ -564,9 +562,7 @@ export declare const ERROR_CODES: {
|
|
|
564
562
|
* B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
|
|
565
563
|
* is admitted until a lifecycle action (a file reset) establishes them.
|
|
566
564
|
*/
|
|
567
|
-
readonly "device.permission_reconcile_required": 409;
|
|
568
565
|
/** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
|
|
569
|
-
readonly "device.recreate_required": 503;
|
|
570
566
|
/**
|
|
571
567
|
* A cloud device's network above its org's or the platform's ceiling, a host outside its org's
|
|
572
568
|
* list, or a widening through an API token or the Platform tool (narrow only).
|
package/dist/errors.js
CHANGED
|
@@ -185,8 +185,6 @@ export const ERROR_CODES = {
|
|
|
185
185
|
* platform item another owner has (P3-6).
|
|
186
186
|
*/
|
|
187
187
|
"catalog.not_owned": 409,
|
|
188
|
-
/** The item (or the version asked for) waits for the super admin's confirmation (P3-9). */
|
|
189
|
-
"catalog.item_pending": 409,
|
|
190
188
|
/** Deleting a platform plugin whose extension is still enabled on the deployment. */
|
|
191
189
|
"catalog.extension_enabled": 409,
|
|
192
190
|
/** A super admin confirmation raced the item's removal (P3-21). */
|
|
@@ -290,6 +288,7 @@ export const ERROR_CODES = {
|
|
|
290
288
|
/** The deployment setting `orgMarketplaceBrowse` is off: no marketplace requests. */
|
|
291
289
|
"catalog.marketplace_browse_disabled": 409,
|
|
292
290
|
"catalog.custom_disabled": 403,
|
|
291
|
+
"catalog.org_upload_code": 403,
|
|
293
292
|
"catalog.not_deployed": 409,
|
|
294
293
|
/**
|
|
295
294
|
* The connector an install planned to reuse (a template it asked no input for) was removed before
|
|
@@ -321,7 +320,6 @@ export const ERROR_CODES = {
|
|
|
321
320
|
"plugin.name_taken": 409,
|
|
322
321
|
"plugin.name_reserved": 409,
|
|
323
322
|
"plugin.dependency_unavailable": 409,
|
|
324
|
-
"plugin.extension_upload_pending": 501,
|
|
325
323
|
"plugin.staging_not_found": 404,
|
|
326
324
|
"plugin.install_failed": 502,
|
|
327
325
|
"plugin.install_not_found": 404,
|
|
@@ -564,9 +562,7 @@ export const ERROR_CODES = {
|
|
|
564
562
|
* B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
|
|
565
563
|
* is admitted until a lifecycle action (a file reset) establishes them.
|
|
566
564
|
*/
|
|
567
|
-
"device.permission_reconcile_required": 409,
|
|
568
565
|
/** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
|
|
569
|
-
"device.recreate_required": 503,
|
|
570
566
|
/**
|
|
571
567
|
* A cloud device's network above its org's or the platform's ceiling, a host outside its org's
|
|
572
568
|
* list, or a widening through an API token or the Platform tool (narrow only).
|