@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.43
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 +3 -3
- package/dist/admin/admin.schemas.d.ts +6 -0
- package/dist/admin/org-network.service.d.ts +3 -1
- package/dist/admin/org-network.service.js +10 -2
- package/dist/app.d.ts +4 -0
- package/dist/app.js +2 -0
- package/dist/background/finish.d.ts +9 -1
- package/dist/background/finish.js +57 -4
- package/dist/background/launch.d.ts +23 -0
- package/dist/background/launch.js +55 -1
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +52 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +35 -1
- package/dist/background/poll.job.js +174 -9
- package/dist/background/render.js +1 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
- package/dist/background/retire-legacy-tasks.job.js +149 -0
- package/dist/background/session.d.ts +15 -5
- package/dist/background/session.js +22 -6
- package/dist/background/stop.d.ts +35 -5
- package/dist/background/stop.js +94 -8
- package/dist/background/store.d.ts +110 -3
- package/dist/background/store.js +205 -3
- package/dist/background/tasks.service.d.ts +18 -1
- package/dist/background/tasks.service.js +99 -9
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/inbound.js +2 -0
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +39 -1
- package/dist/config/permission-migration.d.ts +26 -0
- package/dist/config/permission-migration.js +64 -0
- package/dist/config/schema.d.ts +4 -1
- package/dist/config/schema.js +41 -10
- package/dist/conversations/conversations.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.module.js +12 -0
- package/dist/conversations/conversations.service.d.ts +11 -2
- package/dist/conversations/conversations.service.js +97 -27
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -2
- package/dist/conversations/events.d.ts +307 -4
- package/dist/conversations/events.js +286 -32
- package/dist/conversations/permission-profile-store.d.ts +50 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +84 -0
- package/dist/conversations/permission-profiles.controller.js +105 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
- package/dist/conversations/permission-profiles.schemas.js +23 -0
- package/dist/conversations/permission-profiles.service.d.ts +56 -0
- package/dist/conversations/permission-profiles.service.js +179 -0
- package/dist/ctx/create-ctx.d.ts +12 -5
- package/dist/ctx/create-ctx.js +21 -5
- package/dist/db/kernel-schema.d.ts +248 -3
- package/dist/devices/access.js +1 -1
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +8 -29
- package/dist/devices/conversation-devices.js +37 -73
- package/dist/devices/device-projects.service.d.ts +26 -28
- package/dist/devices/device-projects.service.js +123 -127
- package/dist/devices/devices.controller.js +3 -1
- package/dist/devices/devices.module.js +11 -9
- package/dist/devices/devices.service.d.ts +116 -8
- package/dist/devices/devices.service.js +252 -20
- package/dist/devices/dto.d.ts +16 -0
- package/dist/devices/dto.js +34 -6
- package/dist/devices/errors.d.ts +8 -0
- package/dist/devices/errors.js +10 -0
- package/dist/devices/project-rules.d.ts +44 -0
- package/dist/devices/project-rules.js +27 -0
- package/dist/devices/working-root.d.ts +6 -0
- package/dist/devices/working-root.js +12 -1
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +31 -0
- package/dist/evals/reconstruct.d.ts +19 -2
- package/dist/evals/reconstruct.js +40 -2
- package/dist/evals/recorded-permission-context.d.ts +77 -0
- package/dist/evals/recorded-permission-context.js +151 -0
- package/dist/evals/recorded-tools.d.ts +10 -1
- package/dist/evals/recorded-tools.js +27 -3
- package/dist/evals/run-replay.d.ts +8 -2
- package/dist/evals/run-replay.js +18 -2
- package/dist/evals/trajectory.d.ts +1 -1
- package/dist/evals/worker.d.ts +10 -1
- package/dist/evals/worker.js +23 -14
- package/dist/extensions/host.d.ts +4 -1
- package/dist/extensions/host.js +10 -6
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +14 -1
- package/dist/identity/accounts.js +61 -5
- package/dist/identity/identity.module.js +2 -0
- package/dist/identity/settings.d.ts +28 -12
- package/dist/identity/settings.js +89 -33
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +5 -2
- package/dist/infra/cli/permission-cutover.d.ts +59 -0
- package/dist/infra/cli/permission-cutover.js +107 -0
- package/dist/infra/config/kernel-config.service.d.ts +2 -2
- package/dist/infra/config/kernel-config.service.js +35 -11
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +47 -0
- package/dist/infra/database/transaction-host.js +119 -0
- package/dist/infra/database/xact-lock.d.ts +1 -0
- package/dist/infra/database/xact-lock.js +6 -0
- package/dist/infra/outbox/registry.d.ts +39 -0
- package/dist/infra/outbox/registry.js +18 -0
- package/dist/kernel.module.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +55 -28
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +35 -5
- package/dist/local-devices/device-policy.service.js +188 -13
- package/dist/local-devices/instance-bindings.d.ts +82 -0
- package/dist/local-devices/instance-bindings.js +304 -0
- package/dist/local-devices/keys.d.ts +5 -0
- package/dist/local-devices/keys.js +5 -0
- package/dist/local-devices/local-device-gateway.d.ts +19 -4
- package/dist/local-devices/local-device-gateway.js +185 -17
- package/dist/local-devices/local-device-provider.d.ts +42 -7
- package/dist/local-devices/local-device-provider.js +185 -10
- package/dist/local-devices/local-devices.module.d.ts +17 -2
- package/dist/local-devices/local-devices.module.js +49 -8
- package/dist/local-devices/machines.d.ts +35 -12
- package/dist/local-devices/machines.js +203 -8
- package/dist/local-devices/network-grants.js +3 -3
- package/dist/local-devices/network-grants.module.d.ts +2 -0
- package/dist/local-devices/network-grants.module.js +14 -0
- package/dist/local-devices/owner-report.d.ts +79 -0
- package/dist/local-devices/owner-report.js +155 -0
- package/dist/local-devices/owner-reports.d.ts +48 -0
- package/dist/local-devices/owner-reports.js +190 -0
- package/dist/local-devices/policy-summary.d.ts +24 -1
- package/dist/local-devices/policy-summary.js +48 -0
- package/dist/local-devices/relay.d.ts +82 -6
- package/dist/local-devices/relay.js +187 -16
- package/dist/local-devices/targets.d.ts +16 -1
- package/dist/local-devices/targets.js +35 -2
- package/dist/models/image-usable.d.ts +22 -0
- package/dist/models/image-usable.js +29 -0
- package/dist/models/images.d.ts +125 -0
- package/dist/models/images.js +440 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +16 -5
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +28 -3
- package/dist/models/purposes.js +40 -13
- package/dist/orgs/cloud-network-setting.d.ts +33 -0
- package/dist/orgs/cloud-network-setting.js +47 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +8 -2
- package/dist/orgs/org-lock.d.ts +10 -4
- package/dist/orgs/org-lock.js +10 -4
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +8 -2
- package/dist/orgs/settings.controller.d.ts +4 -1
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +48 -56
- package/dist/orgs/settings.service.js +144 -101
- package/dist/overrides.d.ts +6 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin.ops.js +14 -11
- package/dist/platform/ops/agent-skills.ops.js +2 -0
- package/dist/platform/ops/devices.ops.js +10 -2
- package/dist/platform/ops/models.ops.js +10 -0
- package/dist/platform/ops/org-settings.ops.js +6 -6
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker.module.js +4 -0
- package/dist/runtime/context/build.d.ts +3 -1
- package/dist/runtime/context/build.js +19 -3
- package/dist/runtime/context/compaction.js +5 -0
- package/dist/runtime/context/device-paths.d.ts +9 -2
- package/dist/runtime/context/device-paths.js +20 -0
- package/dist/runtime/context/permission-profile.d.ts +46 -0
- package/dist/runtime/context/permission-profile.js +194 -0
- package/dist/runtime/hook-calls.d.ts +11 -1
- package/dist/runtime/hook-calls.js +24 -1
- package/dist/runtime/maintenance.d.ts +7 -1
- package/dist/runtime/maintenance.js +43 -15
- package/dist/runtime/model-call.d.ts +32 -0
- package/dist/runtime/model-call.js +67 -0
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +286 -0
- package/dist/runtime/project/knowledge.d.ts +7 -2
- package/dist/runtime/project/knowledge.js +5 -2
- package/dist/runtime/project/knowledge.service.d.ts +17 -2
- package/dist/runtime/project/knowledge.service.js +76 -12
- package/dist/runtime/providers.d.ts +9 -5
- package/dist/runtime/providers.js +22 -3
- package/dist/runtime/run-execution.d.ts +4 -1
- package/dist/runtime/run-execution.js +14 -5
- package/dist/runtime/run-steps.d.ts +11 -3
- package/dist/runtime/run-steps.js +27 -4
- package/dist/runtime/runtime.module.js +11 -0
- package/dist/runtime/usage-report.d.ts +10 -6
- package/dist/runtime/usage-report.js +31 -11
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
- package/dist/sandbox/cloud-permission-snapshot.js +407 -0
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
- package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
- package/dist/sandbox/held-operations.d.ts +39 -0
- package/dist/sandbox/held-operations.js +119 -0
- package/dist/sandbox/jobs.d.ts +14 -3
- package/dist/sandbox/jobs.js +20 -2
- package/dist/sandbox/kernel-read.d.ts +55 -0
- package/dist/sandbox/kernel-read.js +57 -0
- package/dist/sandbox/legacy-retirement.d.ts +336 -0
- package/dist/sandbox/legacy-retirement.js +1063 -0
- package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
- package/dist/sandbox/legacy-retirement.module.js +25 -0
- package/dist/sandbox/managed-device-context.d.ts +94 -0
- package/dist/sandbox/managed-device-context.js +308 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +33 -0
- package/dist/sandbox/modes.d.ts +56 -8
- package/dist/sandbox/modes.js +92 -8
- package/dist/sandbox/operation-authority-types.d.ts +8 -0
- package/dist/sandbox/operation-authority-types.js +32 -0
- package/dist/sandbox/operation-authority.d.ts +145 -0
- package/dist/sandbox/operation-authority.js +783 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +206 -0
- package/dist/sandbox/operation-intents.js +1252 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +21 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
- package/dist/sandbox/operation-reconcile.job.js +247 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +38 -0
- package/dist/sandbox/permission-authority-lock.js +147 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-availability.d.ts +18 -0
- package/dist/sandbox/permission-availability.js +19 -0
- package/dist/sandbox/permission-call-grants.d.ts +34 -0
- package/dist/sandbox/permission-call-grants.js +349 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +21 -0
- package/dist/sandbox/permission-call-types.d.ts +82 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
- package/dist/sandbox/permission-ceiling-writes.js +223 -0
- package/dist/sandbox/permission-config-publication.d.ts +76 -0
- package/dist/sandbox/permission-config-publication.js +339 -0
- package/dist/sandbox/permission-context-types.d.ts +64 -0
- package/dist/sandbox/permission-context-types.js +24 -0
- package/dist/sandbox/permission-facts.d.ts +206 -0
- package/dist/sandbox/permission-facts.js +627 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +90 -0
- package/dist/sandbox/permission-instance-writes.js +305 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
- package/dist/sandbox/permission-runtime-reports.js +354 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +155 -0
- package/dist/sandbox/platform-full-access.d.ts +128 -0
- package/dist/sandbox/platform-full-access.js +210 -0
- package/dist/sandbox/providers.d.ts +22 -0
- package/dist/sandbox/providers.js +10 -2
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +13 -0
- package/dist/sandbox/request-not-sent.js +13 -0
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +8 -0
- package/dist/sandbox/review/permission-candidate.d.ts +12 -0
- package/dist/sandbox/review/permission-candidate.js +145 -0
- package/dist/sandbox/review/review.service.d.ts +5 -2
- package/dist/sandbox/review/review.service.js +60 -15
- package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
- package/dist/sandbox/sandbox-file-reader.js +51 -7
- package/dist/sandbox/sandbox.module.js +26 -6
- package/dist/sandbox/sandbox.service.d.ts +230 -34
- package/dist/sandbox/sandbox.service.js +1368 -199
- package/dist/sandbox/unreachable.js +17 -3
- package/dist/sandbox/use-context.d.ts +17 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/skills/invoke.d.ts +27 -4
- package/dist/skills/invoke.js +72 -7
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +23 -10
- package/dist/tools/approvals.service.js +104 -26
- package/dist/tools/builtin-names.d.ts +3 -1
- package/dist/tools/builtin-names.js +5 -1
- package/dist/tools/builtins/artifacts.d.ts +43 -0
- package/dist/tools/builtins/artifacts.js +67 -0
- package/dist/tools/builtins/builtin-tools.d.ts +20 -2
- package/dist/tools/builtins/builtin-tools.js +61 -10
- package/dist/tools/builtins/image/generate.d.ts +59 -0
- package/dist/tools/builtins/image/generate.js +535 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
- package/dist/tools/builtins/sandbox/bash.js +201 -5
- package/dist/tools/builtins/sandbox/common.d.ts +92 -20
- package/dist/tools/builtins/sandbox/common.js +201 -17
- package/dist/tools/builtins/sandbox/deliver.js +9 -51
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +2 -2
- package/dist/tools/builtins/sandbox/task-list.js +7 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +172 -0
- package/dist/tools/builtins/sandbox/task-stop.js +25 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.js +9 -6
- package/dist/tools/device-op-resolver.d.ts +1 -1
- package/dist/tools/device-op-resolver.js +13 -3
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +92 -0
- package/dist/tools/pipeline.d.ts +17 -2
- package/dist/tools/pipeline.js +315 -26
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +15 -0
- package/package.json +4 -3
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/src/migrations/0160_model_usage_image_kind.sql +10 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -1,12 +1,84 @@
|
|
|
1
|
-
import type { ConversationSource, FileSystemHandle, GitHostEntry, ParsedTheme, SkillInvocation } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { ConversationSource, FileSystemHandle, GitHostEntry, ParsedTheme, PermissionProfile, SandboxBrowseScope, SandboxExecutionRef, SandboxOperationScope, SandboxPermissionSupport, SandboxRoots, SkillInvocation } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { ColumnType, Generated, Kysely } from "kysely";
|
|
3
3
|
import type { ModelRef } from "../agents/definition.js";
|
|
4
|
+
import type { DeviceNetwork } from "../sandbox/modes.js";
|
|
5
|
+
import type { StartingExecutionGrants } from "../sandbox/operation-authority-types.js";
|
|
6
|
+
import type { AuthorityEpochVector } from "../sandbox/permission-authority-epochs.js";
|
|
7
|
+
import type { PermissionExpansion } from "../sandbox/permission-call-types.js";
|
|
8
|
+
import type { PermissionConfigProjection } from "../sandbox/permission-config-publication.js";
|
|
9
|
+
import type { PermissionRuntimeIdentity } from "../sandbox/permission-runtime-reports.js";
|
|
4
10
|
import type { ScheduleChat, ScheduleMarker, ScheduleMode, SchedulePauseReason, ScheduleStatus, ScheduleTrigger, TaskRunSkipReason, TaskRunStatus } from "../schedules/types.js";
|
|
5
11
|
/** 带默认值的时间戳列:插入可省略,读出为 Date。 */
|
|
6
12
|
type Ts = ColumnType<Date, Date | string | undefined, Date | string>;
|
|
7
13
|
type TsNullable = ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
8
14
|
/** jsonb 列:写入时传 JSON 字符串,读出为已解析对象。 */
|
|
9
15
|
type Json<T = Record<string, unknown>> = ColumnType<T, string | undefined, string>;
|
|
16
|
+
/** Durable operation admission and outcomes; retained independently of conversation deletion. */
|
|
17
|
+
export interface PermissionCallGrantsTable {
|
|
18
|
+
id: string;
|
|
19
|
+
org_id: string;
|
|
20
|
+
root_conversation_id: string;
|
|
21
|
+
conversation_id: string;
|
|
22
|
+
device_id: string;
|
|
23
|
+
account_id: string;
|
|
24
|
+
run_id: string;
|
|
25
|
+
call_id: string;
|
|
26
|
+
tool_key: string;
|
|
27
|
+
spec_hash: string;
|
|
28
|
+
call_input_hash: string;
|
|
29
|
+
resolved_input_hash: string;
|
|
30
|
+
profile: PermissionProfile;
|
|
31
|
+
profile_revision: number;
|
|
32
|
+
scope_revision: string;
|
|
33
|
+
authority_revision: string;
|
|
34
|
+
binding_hash: string;
|
|
35
|
+
expansion: Json<PermissionExpansion>;
|
|
36
|
+
expansion_hash: string;
|
|
37
|
+
candidate_hash: string;
|
|
38
|
+
target_path: string | null;
|
|
39
|
+
scope_kind: "directories-and-hosts";
|
|
40
|
+
source: "human" | "review-model";
|
|
41
|
+
approval_id: string | null;
|
|
42
|
+
review_event_seq: number | null;
|
|
43
|
+
decided_by: string | null;
|
|
44
|
+
created_at: Ts;
|
|
45
|
+
}
|
|
46
|
+
export interface SandboxOperationIntentsTable {
|
|
47
|
+
permission_grant_id: Generated<string | null>;
|
|
48
|
+
operation_id: string;
|
|
49
|
+
org_id: string;
|
|
50
|
+
account_id: string;
|
|
51
|
+
device_id: string;
|
|
52
|
+
root_conversation_id: string | null;
|
|
53
|
+
conversation_id: string | null;
|
|
54
|
+
run_id: string | null;
|
|
55
|
+
call_id: string | null;
|
|
56
|
+
ordinal: number;
|
|
57
|
+
method: "exec" | "backgroundStart" | "readFile" | "writeFile" | "stat" | "list" | "scan";
|
|
58
|
+
execution_grants: ColumnType<StartingExecutionGrants | null, string | null | undefined, string | null>;
|
|
59
|
+
input_hash: string;
|
|
60
|
+
admission_hash: string;
|
|
61
|
+
granted_hosts: Json<string[]>;
|
|
62
|
+
input: Json<unknown>;
|
|
63
|
+
scope: Json<SandboxOperationScope | SandboxBrowseScope>;
|
|
64
|
+
epochs: Json<AuthorityEpochVector>;
|
|
65
|
+
provider: string;
|
|
66
|
+
provider_version: string;
|
|
67
|
+
instance_generation: string;
|
|
68
|
+
deadline: Date;
|
|
69
|
+
retain_until: Date;
|
|
70
|
+
state: Generated<"pending" | "admitted" | "dispatching" | "started-or-unknown" | "background-running" | "completed" | "revoked">;
|
|
71
|
+
/** 0152: the exact typed start result of an acknowledged backgroundStart. */
|
|
72
|
+
execution_ref: ColumnType<SandboxExecutionRef | null, string | null | undefined, string | null>;
|
|
73
|
+
execution_id: string;
|
|
74
|
+
holder_token: Generated<string>;
|
|
75
|
+
result: Json<unknown>;
|
|
76
|
+
reconcile_attempt: Generated<number>;
|
|
77
|
+
outcome_unknown: Generated<boolean>;
|
|
78
|
+
revoke_acknowledged: Generated<boolean>;
|
|
79
|
+
created_at: Ts;
|
|
80
|
+
updated_at: Ts;
|
|
81
|
+
}
|
|
10
82
|
export interface AccountsTable {
|
|
11
83
|
id: string;
|
|
12
84
|
display_name: string;
|
|
@@ -233,6 +305,10 @@ export interface AgentMembersTable {
|
|
|
233
305
|
type Int8 = ColumnType<string, number | string | undefined, number | string>;
|
|
234
306
|
/** 0006_conversations.sql:会话;`last_seq` 为已分配的最大事件序号。 */
|
|
235
307
|
export interface ConversationsTable {
|
|
308
|
+
permission_profile: ColumnType<"request-approval" | "approve-for-me" | "full-access", "request-approval" | "approve-for-me" | "full-access" | undefined, "request-approval" | "approve-for-me" | "full-access">;
|
|
309
|
+
permission_revision: ColumnType<number, number | undefined, number>;
|
|
310
|
+
permission_consent: ColumnType<unknown | null, string | null | undefined, string | null>;
|
|
311
|
+
create_request_hash: ColumnType<string | null, string | null | undefined, string | null>;
|
|
236
312
|
id: string;
|
|
237
313
|
org_id: string;
|
|
238
314
|
agent_id: string;
|
|
@@ -558,7 +634,9 @@ export interface ApprovalsTable {
|
|
|
558
634
|
input: Json<unknown>;
|
|
559
635
|
requested_for: string | null;
|
|
560
636
|
approver_role: string | null;
|
|
561
|
-
status: Generated<"pending" | "approved" | "denied" | "expired" | "cancelled" | "skipped">;
|
|
637
|
+
status: Generated<"pending" | "approved" | "denied" | "expired" | "cancelled" | "skipped" | "superseded">;
|
|
638
|
+
superseded_revision: Generated<number | null>;
|
|
639
|
+
superseded_reason: Generated<string | null>;
|
|
562
640
|
scope: "once" | "session" | "always" | null;
|
|
563
641
|
decided_by: string | null;
|
|
564
642
|
decided_at: TsNullable;
|
|
@@ -883,7 +961,36 @@ export interface BackgroundTasksTable {
|
|
|
883
961
|
stopping_at: ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
884
962
|
/** 0088, renamed in 0105: the device the task runs in. */
|
|
885
963
|
device_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
886
|
-
|
|
964
|
+
/** 0152: the durable launch state of a managed task; `legacy` for SID rows. */
|
|
965
|
+
launch_state: ColumnType<BackgroundLaunchState, BackgroundLaunchState | undefined, BackgroundLaunchState>;
|
|
966
|
+
operation_id: NullableText;
|
|
967
|
+
input_digest: NullableText;
|
|
968
|
+
run_execution_id: NullableText;
|
|
969
|
+
task_tag: NullableText;
|
|
970
|
+
instance_id: NullableText;
|
|
971
|
+
instance_provider: NullableText;
|
|
972
|
+
instance_provider_version: NullableText;
|
|
973
|
+
instance_generation: NullableText;
|
|
974
|
+
profile_revision: ColumnType<number | null, number | null | undefined, number | null>;
|
|
975
|
+
ceiling_revision: NullableText;
|
|
976
|
+
permission_grant_id: NullableText;
|
|
977
|
+
network_authority: ColumnType<StartingExecutionGrants | null, string | null | undefined, string | null>;
|
|
978
|
+
working_root: NullableText;
|
|
979
|
+
retain_until: ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
980
|
+
execution_ref: ColumnType<SandboxExecutionRef | null, string | null | undefined, string | null>;
|
|
981
|
+
cancel_requested_at: ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
982
|
+
/** 0153: when an exact stop of a managed task was last attempted (fair owed-stop order). */
|
|
983
|
+
cancel_attempted_at: ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
984
|
+
/** 0153: who asked for a managed task's cancellation (its finish keeps their wake rule). */
|
|
985
|
+
cancel_requested_by: ColumnType<"tool" | "person" | "conversation_deleted" | "subagent_end" | null, "tool" | "person" | "conversation_deleted" | "subagent_end" | null | undefined, "tool" | "person" | "conversation_deleted" | "subagent_end" | null>;
|
|
986
|
+
/** 0157: the exact incarnation a legacy dispatch was admitted for; null on historical rows. */
|
|
987
|
+
legacy_dispatch_provider: NullableText;
|
|
988
|
+
legacy_dispatch_generation: NullableText;
|
|
989
|
+
/** 0157: whether a legacy launch may have dispatched its command (see the migration). */
|
|
990
|
+
legacy_dispatch: ColumnType<"unknown" | "reserved" | "dispatched", "unknown" | "reserved" | "dispatched" | undefined, "unknown" | "reserved" | "dispatched">;
|
|
991
|
+
}
|
|
992
|
+
/** 0152: see the migration for the meaning of each state. */
|
|
993
|
+
export type BackgroundLaunchState = "legacy" | "pending" | "dispatched" | "acknowledged" | "cancel-pending" | "terminal";
|
|
887
994
|
/** 0023_sandboxes.sql: the legacy per-conversation sandbox; kept only for the cleanup job (0088). */
|
|
888
995
|
export interface LegacySandboxesTable {
|
|
889
996
|
conversation_id: string;
|
|
@@ -934,12 +1041,22 @@ export interface DevicesTable {
|
|
|
934
1041
|
demoted_from_provider: ColumnType<string | null, string | null | undefined, string | null>;
|
|
935
1042
|
/** 0131: a cloud device's narrowing switch (`sandbox`); null follows the platform and the org. */
|
|
936
1043
|
mode: ColumnType<"sandbox" | null, "sandbox" | null | undefined, "sandbox" | null>;
|
|
1044
|
+
/** 0154: a cloud device's owner Full ceiling (B1 snapshot); null: not snapshotted yet. */
|
|
1045
|
+
owner_full_access: ColumnType<boolean | null, boolean | null | undefined, boolean | null>;
|
|
1046
|
+
/** 0154: a cloud device's outer network (B1 snapshot); null: not snapshotted yet. */
|
|
1047
|
+
outer_network: ColumnType<DeviceNetwork | null, string | null | undefined, string | null>;
|
|
1048
|
+
/** 0154: the provenance of the B1 snapshot. */
|
|
1049
|
+
permission_migration: ColumnType<unknown, string | null | undefined, string | null>;
|
|
1050
|
+
/** 0154: the applied limits must be established before any operation is admitted. */
|
|
1051
|
+
permission_reconcile_required: ColumnType<boolean, boolean | undefined, boolean>;
|
|
937
1052
|
created_at: Ts;
|
|
938
1053
|
updated_at: Ts;
|
|
939
1054
|
deleted_at: TsNullable;
|
|
940
1055
|
}
|
|
941
1056
|
/** 0088_environments.sql, renamed in 0105: the instance and file system of a device. */
|
|
942
1057
|
export interface DeviceInstancesTable {
|
|
1058
|
+
permission_roots: ColumnType<SandboxRoots | null, string | null | undefined, string | null>;
|
|
1059
|
+
permission_runtime_identity: ColumnType<PermissionRuntimeIdentity | null, string | null | undefined, string | null>;
|
|
943
1060
|
device_id: string;
|
|
944
1061
|
org_id: string;
|
|
945
1062
|
provider: ColumnType<string | null, string | null | undefined, string | null>;
|
|
@@ -977,6 +1094,8 @@ export interface DeviceInstancesTable {
|
|
|
977
1094
|
*/
|
|
978
1095
|
export interface DeviceMachinesTable {
|
|
979
1096
|
id: Generated<string>;
|
|
1097
|
+
/** 0157: the machine's current OS boot identity (the latest first seen); null: none reported. */
|
|
1098
|
+
boot_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
980
1099
|
org_id: string;
|
|
981
1100
|
device_id: string;
|
|
982
1101
|
account_id: string;
|
|
@@ -1001,6 +1120,8 @@ export interface DeviceMachinesTable {
|
|
|
1001
1120
|
pending_policy_ops: ColumnType<unknown, string | undefined, string>;
|
|
1002
1121
|
/** 0133: the owner's home directory the program reported in its hello; null when not reported. */
|
|
1003
1122
|
home: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1123
|
+
/** 0156: the authenticated owner report (`StoredOwnerReport`, B2); null before any. */
|
|
1124
|
+
owner_report: ColumnType<unknown | null, string | null | undefined, string | null>;
|
|
1004
1125
|
}
|
|
1005
1126
|
/** 0133: a device's projects (project root design §4.1), written only by the kernel. */
|
|
1006
1127
|
export interface DeviceProjectsTable {
|
|
@@ -1245,6 +1366,16 @@ export interface ModelUsageTable {
|
|
|
1245
1366
|
provider: string;
|
|
1246
1367
|
model: string;
|
|
1247
1368
|
input_tokens: number;
|
|
1369
|
+
/** 0160: the call's kind: `embedding` (default) or `image_generation`. */
|
|
1370
|
+
kind: Generated<"embedding" | "image_generation">;
|
|
1371
|
+
/** 0160: images the call produced (0 for an embedding call). */
|
|
1372
|
+
output_images: Generated<number>;
|
|
1373
|
+
/** 0160: the answer's output tokens (0 for an embedding call). */
|
|
1374
|
+
output_tokens: Generated<number>;
|
|
1375
|
+
/** 0160: the answer's cache read tokens (0 for an embedding call). */
|
|
1376
|
+
cache_read_tokens: Generated<number>;
|
|
1377
|
+
/** 0160: the answer's cache write tokens (0 for an embedding call). */
|
|
1378
|
+
cache_write_tokens: Generated<number>;
|
|
1248
1379
|
occurred_at: Ts;
|
|
1249
1380
|
reported_at: TsNullable;
|
|
1250
1381
|
/** Set when the row's `usage.report` job gave up after its last attempt. */
|
|
@@ -1310,8 +1441,121 @@ export interface OrgDataKeysTable {
|
|
|
1310
1441
|
master_key_id: string;
|
|
1311
1442
|
created_at: Ts;
|
|
1312
1443
|
}
|
|
1444
|
+
/** Per-scope revision counters of the permission authority (migration 0146). */
|
|
1445
|
+
export interface PermissionAuthorityEpochsTable {
|
|
1446
|
+
kind: string;
|
|
1447
|
+
id: string;
|
|
1448
|
+
revision: ColumnType<number, number | undefined, number>;
|
|
1449
|
+
full_revision: Generated<number>;
|
|
1450
|
+
}
|
|
1451
|
+
export interface DevicePermissionReportsTable {
|
|
1452
|
+
device_id: string;
|
|
1453
|
+
provider: string;
|
|
1454
|
+
provider_version: string;
|
|
1455
|
+
instance_generation: string;
|
|
1456
|
+
identity_hash: string;
|
|
1457
|
+
report: Json<SandboxPermissionSupport>;
|
|
1458
|
+
observed_at: Ts;
|
|
1459
|
+
}
|
|
1460
|
+
export interface DeviceGenerationHighWaterTable {
|
|
1461
|
+
device_id: string;
|
|
1462
|
+
/** bigint: read as a decimal string. */
|
|
1463
|
+
high_water_ms: ColumnType<string, string | number, string | number>;
|
|
1464
|
+
updated_at: Ts;
|
|
1465
|
+
}
|
|
1466
|
+
export interface DeviceInstanceBindingsTable {
|
|
1467
|
+
device_id: string;
|
|
1468
|
+
instance_generation: string;
|
|
1469
|
+
binding_id: string;
|
|
1470
|
+
provider: string;
|
|
1471
|
+
previous_generation: string | null;
|
|
1472
|
+
status: "awaiting-device" | "installed";
|
|
1473
|
+
machine_id: string | null;
|
|
1474
|
+
runtime_identity: ColumnType<PermissionRuntimeIdentity | null, string | null | undefined, string | null>;
|
|
1475
|
+
created_at: Ts;
|
|
1476
|
+
installed_at: TsNullable;
|
|
1477
|
+
}
|
|
1478
|
+
export interface LegacyLaunchFreezeTable {
|
|
1479
|
+
id: "platform";
|
|
1480
|
+
frozen_at: Generated<Date>;
|
|
1481
|
+
frozen_by: string;
|
|
1482
|
+
/** Migration 0158: when the freeze's enumeration last completed stable; null before. */
|
|
1483
|
+
enumerated_at: TsNullable;
|
|
1484
|
+
}
|
|
1485
|
+
export interface DeviceRetirementObligationsTable {
|
|
1486
|
+
id: Generated<string>;
|
|
1487
|
+
device_id: string;
|
|
1488
|
+
org_id: string;
|
|
1489
|
+
provider: string;
|
|
1490
|
+
instance_generation: string;
|
|
1491
|
+
state: ColumnType<"open" | "quarantined" | "resolved" | "abandoned", "open" | "quarantined" | "resolved" | "abandoned" | undefined, "open" | "quarantined" | "resolved" | "abandoned">;
|
|
1492
|
+
/** When the obligation was abandoned with its deleted device (never evidence). */
|
|
1493
|
+
abandoned_at: TsNullable;
|
|
1494
|
+
/** `exact-cancelled`: every member was a revoked start cancelled by its exact ref (B-22). */
|
|
1495
|
+
resolution: ColumnType<"provider-destroyed" | "host-rebooted" | "exact-cancelled" | null, "provider-destroyed" | "host-rebooted" | "exact-cancelled" | null | undefined, "provider-destroyed" | "host-rebooted" | "exact-cancelled" | null>;
|
|
1496
|
+
/** A local incarnation: the machine and its boot identity when recorded (null: none). */
|
|
1497
|
+
boot_machine_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1498
|
+
boot_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1499
|
+
reason: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1500
|
+
attempts: ColumnType<number, number | undefined, number>;
|
|
1501
|
+
last_attempt_at: TsNullable;
|
|
1502
|
+
last_error: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1503
|
+
created_at: Generated<Date>;
|
|
1504
|
+
resolved_at: TsNullable;
|
|
1505
|
+
}
|
|
1506
|
+
export interface DeviceRetirementMembersTable {
|
|
1507
|
+
obligation_id: string;
|
|
1508
|
+
kind: "legacy-task" | "revoked-start";
|
|
1509
|
+
ref_id: string;
|
|
1510
|
+
settled: ColumnType<boolean, boolean | undefined, boolean>;
|
|
1511
|
+
created_at: Generated<Date>;
|
|
1512
|
+
}
|
|
1513
|
+
export interface DeviceMachineBootsTable {
|
|
1514
|
+
machine_id: string;
|
|
1515
|
+
boot_id: string;
|
|
1516
|
+
/** bigserial: read as a decimal string. */
|
|
1517
|
+
seq: ColumnType<string, string | number | undefined, never>;
|
|
1518
|
+
first_seen_at: Generated<Date>;
|
|
1519
|
+
}
|
|
1520
|
+
export interface DeviceInstanceDestructionsTable {
|
|
1521
|
+
device_id: string;
|
|
1522
|
+
provider: string;
|
|
1523
|
+
instance_generation: string;
|
|
1524
|
+
destroyed_at: Generated<Date>;
|
|
1525
|
+
}
|
|
1526
|
+
export interface SandboxOperationPayloadChunksTable {
|
|
1527
|
+
operation_id: string;
|
|
1528
|
+
slot: "input" | "result";
|
|
1529
|
+
sequence: number;
|
|
1530
|
+
data: Buffer;
|
|
1531
|
+
}
|
|
1532
|
+
export interface PermissionConfigPublicationTable {
|
|
1533
|
+
id: string;
|
|
1534
|
+
fingerprint: string;
|
|
1535
|
+
projection: Json<PermissionConfigProjection>;
|
|
1536
|
+
updated_at: Ts;
|
|
1537
|
+
}
|
|
1313
1538
|
export interface KernelDatabase {
|
|
1539
|
+
permission_authority_epochs: PermissionAuthorityEpochsTable;
|
|
1314
1540
|
accounts: AccountsTable;
|
|
1541
|
+
device_permission_reports: DevicePermissionReportsTable;
|
|
1542
|
+
/** Migration 0155: per-device generation high-water mark; outlives instance rows. */
|
|
1543
|
+
device_generation_high_water: DeviceGenerationHighWaterTable;
|
|
1544
|
+
/** Migration 0155: post-commit binding of a local instance generation. */
|
|
1545
|
+
device_instance_bindings: DeviceInstanceBindingsTable;
|
|
1546
|
+
/** Migration 0157: the durable legacy-launch freeze (one row, never removed). */
|
|
1547
|
+
legacy_launch_freeze: LegacyLaunchFreezeTable;
|
|
1548
|
+
/** Migration 0157: the physical no-reuse obligation of one old instance incarnation. */
|
|
1549
|
+
device_retirement_obligations: DeviceRetirementObligationsTable;
|
|
1550
|
+
/** Migration 0157: what put a retirement obligation there. */
|
|
1551
|
+
device_retirement_members: DeviceRetirementMembersTable;
|
|
1552
|
+
/** Migration 0157: the OS boot identities a machine reported, in the order first seen. */
|
|
1553
|
+
device_machine_boots: DeviceMachineBootsTable;
|
|
1554
|
+
/** Migration 0157: provider-confirmed destruction of a cloud instance incarnation. */
|
|
1555
|
+
device_instance_destructions: DeviceInstanceDestructionsTable;
|
|
1556
|
+
sandbox_operation_intents: SandboxOperationIntentsTable;
|
|
1557
|
+
sandbox_operation_payload_chunks: SandboxOperationPayloadChunksTable;
|
|
1558
|
+
permission_config_publication: PermissionConfigPublicationTable;
|
|
1315
1559
|
org_data_keys: OrgDataKeysTable;
|
|
1316
1560
|
account_initial_passwords: AccountInitialPasswordsTable;
|
|
1317
1561
|
identities: IdentitiesTable;
|
|
@@ -1349,6 +1593,7 @@ export interface KernelDatabase {
|
|
|
1349
1593
|
tool_grants: ToolGrantsTable;
|
|
1350
1594
|
conversation_tool_grants: ConversationToolGrantsTable;
|
|
1351
1595
|
approvals: ApprovalsTable;
|
|
1596
|
+
permission_call_grants: PermissionCallGrantsTable;
|
|
1352
1597
|
questions: QuestionsTable;
|
|
1353
1598
|
tool_outputs: ToolOutputsTable;
|
|
1354
1599
|
tool_specs: ToolSpecsTable;
|
package/dist/devices/access.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
11
11
|
import { ApiError } from "../errors.js";
|
|
12
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
13
|
import { isInternalProvider, SandboxProviders } from "../sandbox/providers.js";
|
|
14
|
-
import { deviceNotFound } from "
|
|
14
|
+
import { deviceNotFound } from "./errors.js";
|
|
15
15
|
/**
|
|
16
16
|
* The provider a device works with: a kernel-internal one (`@local`) as recorded; for a
|
|
17
17
|
* cloud device the one keeping its files or instance once it has any (they are never
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from "@nestjs/common";
|
|
8
|
+
import { SandboxProviderRegistryModule } from "../sandbox/providers.module.js";
|
|
9
|
+
import { DeviceAccess } from "./access.js";
|
|
10
|
+
let DeviceAccessModule = class DeviceAccessModule {
|
|
11
|
+
};
|
|
12
|
+
DeviceAccessModule = __decorate([
|
|
13
|
+
Module({
|
|
14
|
+
imports: [SandboxProviderRegistryModule],
|
|
15
|
+
providers: [DeviceAccess],
|
|
16
|
+
exports: [DeviceAccess],
|
|
17
|
+
})
|
|
18
|
+
], DeviceAccessModule);
|
|
19
|
+
export { DeviceAccessModule };
|
|
@@ -3,10 +3,13 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
3
3
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
4
|
import type { DeviceModeLevel } from "../runtime/context/device-paths.js";
|
|
5
5
|
import type { SandboxMode } from "../sandbox/modes.js";
|
|
6
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
7
|
+
import { PermissionFacts, type WorkingFacts } from "../sandbox/permission-facts.js";
|
|
6
8
|
import { SandboxProviders } from "../sandbox/providers.js";
|
|
7
9
|
import { DeviceAccess } from "./access.js";
|
|
8
10
|
import { DevicesService } from "./devices.service.js";
|
|
9
11
|
import { type WorkingProject } from "./working-root.js";
|
|
12
|
+
export type { WorkingFacts } from "../sandbox/permission-facts.js";
|
|
10
13
|
/** `details[0].reason` of the error an anonymous IM conversation's sandbox call gets. */
|
|
11
14
|
export declare const ANONYMOUS_NO_DEVICE = "anonymous";
|
|
12
15
|
/** Anonymous IM senders have no device (spec §4.2 item 8): their sandbox tools are off. */
|
|
@@ -51,21 +54,6 @@ export interface CommandReviewFacts {
|
|
|
51
54
|
*/
|
|
52
55
|
workingRoot: string | undefined;
|
|
53
56
|
}
|
|
54
|
-
/**
|
|
55
|
-
* What decides the working root of a call (project root spec §4.3), read the same way for a
|
|
56
|
-
* sandbox tool and for the command review, so both decide the same root.
|
|
57
|
-
*/
|
|
58
|
-
export interface WorkingFacts {
|
|
59
|
-
/**
|
|
60
|
-
* The device's workspace: the latest `device_paths` roots recorded in the calling conversation,
|
|
61
|
-
* else the root's, else the machine's reported roots, else the default.
|
|
62
|
-
*/
|
|
63
|
-
workspace: string;
|
|
64
|
-
/** The owner's home: the machine's reported home, else the workspace's home prefix; null: unknown. */
|
|
65
|
-
home: string | null;
|
|
66
|
-
/** The root conversation's latest project snapshot; null: free, or none recorded yet. */
|
|
67
|
-
project: WorkingProject | null;
|
|
68
|
-
}
|
|
69
57
|
/**
|
|
70
58
|
* Which device a conversation works in (spec 2026-11-07-environments-design §4.1 items 1, 3;
|
|
71
59
|
* §4.2 items 8, 9, 12). A conversation is bound once, to a device of its owner
|
|
@@ -80,12 +68,16 @@ export declare class ConversationDevices {
|
|
|
80
68
|
private readonly providers;
|
|
81
69
|
private readonly access;
|
|
82
70
|
private readonly devices;
|
|
83
|
-
|
|
71
|
+
private readonly facts;
|
|
72
|
+
private readonly ceilings;
|
|
73
|
+
constructor(db: KernelDb, txHost: TransactionHost, providers: Pick<SandboxProviders, "cloud"> & Partial<Pick<SandboxProviders, "forName">>, access: Pick<DeviceAccess, "usable">, devices: Pick<DevicesService, "ensureDefault" | "modeLevel" | "projectReach">, facts: Pick<PermissionFacts, "readWorkingFacts" | "workingProject">, ceilings: PermissionCeilingWrites);
|
|
84
74
|
/**
|
|
85
75
|
* The mode and network a call in the device runs at now ({@link DevicesService.modeLevel}),
|
|
86
76
|
* recorded for the model in `device_paths` (auto mode spec §4.2).
|
|
87
77
|
*/
|
|
88
78
|
modeLevel(orgId: string, deviceId: string): Promise<DeviceModeLevel | null>;
|
|
79
|
+
/** How far restricted work may root outside the workspace now (B2; {@link DevicesService.projectReach}). */
|
|
80
|
+
projectReach(orgId: string, deviceId: string): Promise<"workspace" | "os-user">;
|
|
89
81
|
/**
|
|
90
82
|
* The facts the command review reads for a call in the conversation tree rooted at
|
|
91
83
|
* `rootConversationId` (auto mode spec §5.1): the device `forTool` would enter, its mode and
|
|
@@ -102,20 +94,7 @@ export declare class ConversationDevices {
|
|
|
102
94
|
* sandbox tools and the command review decide the working root from.
|
|
103
95
|
*/
|
|
104
96
|
workingFacts(orgId: string, rootConversationId: string, conversationId: string, deviceId: string): Promise<WorkingFacts>;
|
|
105
|
-
/**
|
|
106
|
-
* The project snapshot that decides the working root of the conversation tree rooted at
|
|
107
|
-
* `rootConversationId` (project root spec §4.3): its latest `project_root` event, read only when
|
|
108
|
-
* the conversation is bound to a project (a free conversation reads one row by its key). Null:
|
|
109
|
-
* free, or bound with no snapshot recorded yet.
|
|
110
|
-
*/
|
|
111
97
|
workingProject(orgId: string, rootConversationId: string): Promise<WorkingProject | null>;
|
|
112
|
-
/** The workspace root of a conversation's latest `device_paths` event, or null. */
|
|
113
|
-
private recordedWorkspace;
|
|
114
|
-
/**
|
|
115
|
-
* The workspace root and the owner's home the device's active machine last reported, or null
|
|
116
|
-
* (cloud: no machine).
|
|
117
|
-
*/
|
|
118
|
-
private machineRoots;
|
|
119
98
|
/**
|
|
120
99
|
* The device a new conversation of `accountId` is bound to: the chosen one when it is
|
|
121
100
|
* usable by the person (else `device.not_found` / `device.unavailable`, and nothing
|
|
@@ -7,13 +7,13 @@ 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 { DEFAULT_SANDBOX_ROOTS } from "@capybara-hq/plugin-sdk";
|
|
11
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
-
import { sql } from "kysely";
|
|
13
11
|
import { ApiError } from "../errors.js";
|
|
14
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
13
|
+
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
16
14
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
15
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
16
|
+
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
17
17
|
import { isInternalProvider, SandboxProviders } from "../sandbox/providers.js";
|
|
18
18
|
import { homeOf } from "../sandbox/review/rules.js";
|
|
19
19
|
import { deviceNotFound, sandboxUnavailable } from "../sandbox/sandbox.service.js";
|
|
@@ -38,12 +38,16 @@ let ConversationDevices = class ConversationDevices {
|
|
|
38
38
|
providers;
|
|
39
39
|
access;
|
|
40
40
|
devices;
|
|
41
|
-
|
|
41
|
+
facts;
|
|
42
|
+
ceilings;
|
|
43
|
+
constructor(db, txHost, providers, access, devices, facts, ceilings) {
|
|
42
44
|
this.db = db;
|
|
43
45
|
this.txHost = txHost;
|
|
44
46
|
this.providers = providers;
|
|
45
47
|
this.access = access;
|
|
46
48
|
this.devices = devices;
|
|
49
|
+
this.facts = facts;
|
|
50
|
+
this.ceilings = ceilings;
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* The mode and network a call in the device runs at now ({@link DevicesService.modeLevel}),
|
|
@@ -52,6 +56,10 @@ let ConversationDevices = class ConversationDevices {
|
|
|
52
56
|
modeLevel(orgId, deviceId) {
|
|
53
57
|
return this.devices.modeLevel(orgId, deviceId);
|
|
54
58
|
}
|
|
59
|
+
/** How far restricted work may root outside the workspace now (B2; {@link DevicesService.projectReach}). */
|
|
60
|
+
projectReach(orgId, deviceId) {
|
|
61
|
+
return this.devices.projectReach(orgId, deviceId);
|
|
62
|
+
}
|
|
55
63
|
/**
|
|
56
64
|
* The facts the command review reads for a call in the conversation tree rooted at
|
|
57
65
|
* `rootConversationId` (auto mode spec §5.1): the device `forTool` would enter, its mode and
|
|
@@ -80,7 +88,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
80
88
|
return null;
|
|
81
89
|
throw e;
|
|
82
90
|
}
|
|
83
|
-
const [device, level] = await Promise.all([
|
|
91
|
+
const [device, level, reach] = await Promise.all([
|
|
84
92
|
this.db
|
|
85
93
|
.selectFrom("devices")
|
|
86
94
|
.select("name")
|
|
@@ -88,6 +96,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
88
96
|
.where("org_id", "=", orgId)
|
|
89
97
|
.executeTakeFirst(),
|
|
90
98
|
this.modeLevel(orgId, deviceId),
|
|
99
|
+
this.projectReach(orgId, deviceId),
|
|
91
100
|
]);
|
|
92
101
|
if (device === undefined)
|
|
93
102
|
return null;
|
|
@@ -102,7 +111,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
102
111
|
workspace,
|
|
103
112
|
home,
|
|
104
113
|
deviceHome: homeOf(workspace),
|
|
105
|
-
workingRoot: workingRootOf(project, { mode, workspace, home }),
|
|
114
|
+
workingRoot: workingRootOf(project, { mode, reach, workspace, home }),
|
|
106
115
|
};
|
|
107
116
|
}
|
|
108
117
|
/**
|
|
@@ -111,72 +120,15 @@ let ConversationDevices = class ConversationDevices {
|
|
|
111
120
|
* sandbox tools and the command review decide the working root from.
|
|
112
121
|
*/
|
|
113
122
|
async workingFacts(orgId, rootConversationId, conversationId, deviceId) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const workspace = recorded ?? recordedRoot ?? machine?.workspace ?? DEFAULT_SANDBOX_ROOTS.workspace;
|
|
121
|
-
// never from a project root: the machine's home, else the device workspace's home prefix
|
|
122
|
-
const reported = machine?.home;
|
|
123
|
-
const home = reported?.startsWith("/") ? reported : homeOf(workspace);
|
|
124
|
-
return { workspace, home, project };
|
|
123
|
+
return this.facts.readWorkingFacts({
|
|
124
|
+
orgId,
|
|
125
|
+
rootConversationId,
|
|
126
|
+
holderConversationId: conversationId,
|
|
127
|
+
deviceId,
|
|
128
|
+
});
|
|
125
129
|
}
|
|
126
|
-
/**
|
|
127
|
-
* The project snapshot that decides the working root of the conversation tree rooted at
|
|
128
|
-
* `rootConversationId` (project root spec §4.3): its latest `project_root` event, read only when
|
|
129
|
-
* the conversation is bound to a project (a free conversation reads one row by its key). Null:
|
|
130
|
-
* free, or bound with no snapshot recorded yet.
|
|
131
|
-
*/
|
|
132
130
|
async workingProject(orgId, rootConversationId) {
|
|
133
|
-
|
|
134
|
-
.selectFrom("conversations")
|
|
135
|
-
.select("project_path")
|
|
136
|
-
.where("id", "=", rootConversationId)
|
|
137
|
-
.where("org_id", "=", orgId)
|
|
138
|
-
.executeTakeFirst();
|
|
139
|
-
if (conv?.project_path == null)
|
|
140
|
-
return null;
|
|
141
|
-
const row = await this.db
|
|
142
|
-
.selectFrom("conversation_events")
|
|
143
|
-
.select([
|
|
144
|
-
sql `payload->>'root'`.as("root"),
|
|
145
|
-
sql `payload ? 'unavailable'`.as("unavailable"),
|
|
146
|
-
])
|
|
147
|
-
.where("conversation_id", "=", rootConversationId)
|
|
148
|
-
.where("type", "=", "project_root")
|
|
149
|
-
.orderBy("seq", "desc")
|
|
150
|
-
.limit(1)
|
|
151
|
-
.executeTakeFirst();
|
|
152
|
-
if (row === undefined || typeof row.root !== "string")
|
|
153
|
-
return null;
|
|
154
|
-
return { root: row.root, unavailable: row.unavailable !== false };
|
|
155
|
-
}
|
|
156
|
-
/** The workspace root of a conversation's latest `device_paths` event, or null. */
|
|
157
|
-
async recordedWorkspace(conversationId) {
|
|
158
|
-
const row = await this.db
|
|
159
|
-
.selectFrom("conversation_events")
|
|
160
|
-
.select(sql `payload->'roots'->>'workspace'`.as("workspace"))
|
|
161
|
-
.where("conversation_id", "=", conversationId)
|
|
162
|
-
.where("type", "=", "device_paths")
|
|
163
|
-
.orderBy("seq", "desc")
|
|
164
|
-
.limit(1)
|
|
165
|
-
.executeTakeFirst();
|
|
166
|
-
return row?.workspace ?? null;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* The workspace root and the owner's home the device's active machine last reported, or null
|
|
170
|
-
* (cloud: no machine).
|
|
171
|
-
*/
|
|
172
|
-
async machineRoots(deviceId) {
|
|
173
|
-
const row = await this.db
|
|
174
|
-
.selectFrom("device_machines")
|
|
175
|
-
.select([sql `roots->>'workspace'`.as("workspace"), "home"])
|
|
176
|
-
.where("device_id", "=", deviceId)
|
|
177
|
-
.where("revoked_at", "is", null)
|
|
178
|
-
.executeTakeFirst();
|
|
179
|
-
return row === undefined ? null : { workspace: row.workspace ?? null, home: row.home ?? null };
|
|
131
|
+
return this.facts.workingProject(orgId, rootConversationId);
|
|
180
132
|
}
|
|
181
133
|
/**
|
|
182
134
|
* The device a new conversation of `accountId` is bound to: the chosen one when it is
|
|
@@ -222,7 +174,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
222
174
|
const chosen = await this.defaultFor(orgId, conv.account_id, im);
|
|
223
175
|
if (chosen === null)
|
|
224
176
|
throw sandboxUnavailable();
|
|
225
|
-
deviceId = await this.bind(rootConversationId, chosen);
|
|
177
|
+
deviceId = await withTransactionFencePrelude(() => this.ceilings.lock({ orgId, deviceId: chosen, rootConversationId }, "root"), () => this.bind(orgId, rootConversationId, chosen));
|
|
226
178
|
}
|
|
227
179
|
if (this.providers.cloud() === undefined && !(await this.isInternal(deviceId))) {
|
|
228
180
|
throw sandboxUnavailable();
|
|
@@ -307,7 +259,17 @@ let ConversationDevices = class ConversationDevices {
|
|
|
307
259
|
}
|
|
308
260
|
}
|
|
309
261
|
/** Binds an unbound conversation to `deviceId`; returns what it is bound to now. */
|
|
310
|
-
async bind(conversationId, deviceId) {
|
|
262
|
+
async bind(orgId, conversationId, deviceId) {
|
|
263
|
+
const subject = { orgId, deviceId, rootConversationId: conversationId };
|
|
264
|
+
await this.ceilings.lock(subject, "root");
|
|
265
|
+
const before = await this.db
|
|
266
|
+
.selectFrom("conversations")
|
|
267
|
+
.select("device_id")
|
|
268
|
+
.where("id", "=", conversationId)
|
|
269
|
+
.executeTakeFirstOrThrow();
|
|
270
|
+
if (before.device_id !== null)
|
|
271
|
+
return before.device_id;
|
|
272
|
+
await this.ceilings.publishLocked(subject, "root", false, true);
|
|
311
273
|
await this.db
|
|
312
274
|
.updateTable("conversations")
|
|
313
275
|
.set({ device_id: deviceId })
|
|
@@ -361,7 +323,9 @@ ConversationDevices = __decorate([
|
|
|
361
323
|
__param(1, Inject(TransactionHost)),
|
|
362
324
|
__param(2, Inject(SandboxProviders)),
|
|
363
325
|
__param(3, Inject(DeviceAccess)),
|
|
364
|
-
__param(4, Inject(DevicesService))
|
|
326
|
+
__param(4, Inject(DevicesService)),
|
|
327
|
+
__param(5, Inject(PermissionFacts)),
|
|
328
|
+
__param(6, Inject(PermissionCeilingWrites))
|
|
365
329
|
], ConversationDevices);
|
|
366
330
|
export { ConversationDevices };
|
|
367
331
|
const isDeviceGone = (e) => e instanceof ApiError && (e.code === "device.not_found" || e.code === "device.unavailable");
|