@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,8 +1,189 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { AgentDefinitionSchema, DisabledSkillRef, DisabledToolRef, ModelRef, } from "../agents/definition.js";
|
|
4
5
|
import { ORG_ROLES } from "../orgs/roles.js";
|
|
6
|
+
import { coversHost } from "../sandbox/modes.js";
|
|
5
7
|
import { TOOL_VIEW_DIFF_MAX_LINES, TOOL_VIEW_LINE_MAX_CHARS, TOOL_VIEW_PATH_MAX_CHARS, } from "../tools/view.js";
|
|
8
|
+
/** Code-point ordering is independent of the host locale and UTF-16 surrogate ordering. */
|
|
9
|
+
export function permissionCodePointCompare(a, b) {
|
|
10
|
+
const left = Array.from(a, (c) => c.codePointAt(0));
|
|
11
|
+
const right = Array.from(b, (c) => c.codePointAt(0));
|
|
12
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
13
|
+
const difference = left[i] - right[i];
|
|
14
|
+
if (difference)
|
|
15
|
+
return difference;
|
|
16
|
+
}
|
|
17
|
+
return left.length - right.length;
|
|
18
|
+
}
|
|
19
|
+
const PermissionProfileSchema = z.custom((value) => value === "request-approval" || value === "approve-for-me" || value === "full-access");
|
|
20
|
+
const PermissionPath = z
|
|
21
|
+
.string()
|
|
22
|
+
.min(1)
|
|
23
|
+
.max(4096)
|
|
24
|
+
.refine((value) => validateSandboxPathShape(value).length === 0, "Expected an absolute bounded device path")
|
|
25
|
+
// the authority's exact spelling: no "." segments and no trailing slash, never repaired here
|
|
26
|
+
.refine((value) => posix.normalize(value) === value && (value === "/" || !value.endsWith("/")), "Expected a normalized device path");
|
|
27
|
+
const PermissionHosts = z
|
|
28
|
+
.array(z
|
|
29
|
+
.string()
|
|
30
|
+
.max(253)
|
|
31
|
+
.refine((value) => validateAllowHost(value).length === 0, "Expected a normalized authority host"))
|
|
32
|
+
.min(1)
|
|
33
|
+
.max(100)
|
|
34
|
+
.refine((values) => values.every((value, i) => i === 0 || permissionCodePointCompare(values[i - 1], value) < 0), "Hosts must be unique and sorted by Unicode code point");
|
|
35
|
+
const PermissionDirectories = z
|
|
36
|
+
.array(PermissionPath)
|
|
37
|
+
.min(1)
|
|
38
|
+
.max(64)
|
|
39
|
+
.refine((values) => values.every((value, i) => i === 0 || permissionCodePointCompare(values[i - 1], value) < 0), "Directories must be unique and sorted by Unicode code point");
|
|
40
|
+
const PermissionRevision = z.string().min(1).max(256);
|
|
41
|
+
const PermissionReason = z
|
|
42
|
+
.string()
|
|
43
|
+
.min(1)
|
|
44
|
+
.max(1000)
|
|
45
|
+
.refine((value) => value.trim().length > 0);
|
|
46
|
+
const PermissionId = z.string().uuid();
|
|
47
|
+
const PermissionScopeSchema = z
|
|
48
|
+
.object({
|
|
49
|
+
location: z.enum(["local", "cloud"]),
|
|
50
|
+
workingRoot: PermissionPath,
|
|
51
|
+
filesystem: z.discriminatedUnion("kind", [
|
|
52
|
+
z.object({ kind: z.literal("device") }).strict(),
|
|
53
|
+
z
|
|
54
|
+
.object({
|
|
55
|
+
kind: z.literal("scoped"),
|
|
56
|
+
readDirectories: PermissionDirectories,
|
|
57
|
+
writeDirectories: PermissionDirectories,
|
|
58
|
+
})
|
|
59
|
+
.strict(),
|
|
60
|
+
]),
|
|
61
|
+
network: z.discriminatedUnion("kind", [
|
|
62
|
+
z.object({ kind: z.literal("none") }).strict(),
|
|
63
|
+
z.object({ kind: z.literal("environment") }).strict(),
|
|
64
|
+
z.object({ kind: z.literal("allowlist"), hosts: PermissionHosts }).strict(),
|
|
65
|
+
]),
|
|
66
|
+
outerNetwork: z.discriminatedUnion("kind", [
|
|
67
|
+
z.object({ kind: z.literal("host-environment") }).strict(),
|
|
68
|
+
z.object({ kind: z.literal("none") }).strict(),
|
|
69
|
+
z.object({ kind: z.literal("open-public") }).strict(),
|
|
70
|
+
z.object({ kind: z.literal("allowlist"), hosts: PermissionHosts }).strict(),
|
|
71
|
+
]),
|
|
72
|
+
})
|
|
73
|
+
.strict();
|
|
74
|
+
/** Complete recorded facts, never a grant or a requested-but-unverified scope. */
|
|
75
|
+
export const PermissionContextV1Schema = z
|
|
76
|
+
.object({
|
|
77
|
+
version: z.literal(1),
|
|
78
|
+
rootConversationId: PermissionId,
|
|
79
|
+
profileRevision: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
80
|
+
selectedProfile: PermissionProfileSchema.nullable(),
|
|
81
|
+
effectiveProfile: PermissionProfileSchema.nullable(),
|
|
82
|
+
execution: z.enum(["interactive", "scheduled"]),
|
|
83
|
+
inherited: z.boolean(),
|
|
84
|
+
deviceId: PermissionId.nullable(),
|
|
85
|
+
scopeRevision: PermissionRevision.nullable(),
|
|
86
|
+
authorityRevision: PermissionRevision.nullable(),
|
|
87
|
+
availability: z.discriminatedUnion("state", [
|
|
88
|
+
z.object({ state: z.literal("supported") }).strict(),
|
|
89
|
+
z.object({ state: z.enum(["unsupported", "unprobed"]), reason: PermissionReason }).strict(),
|
|
90
|
+
z
|
|
91
|
+
.object({
|
|
92
|
+
state: z.literal("unavailable"),
|
|
93
|
+
cause: z.enum(["no-device", "actor-device-access"]),
|
|
94
|
+
reason: PermissionReason,
|
|
95
|
+
})
|
|
96
|
+
.strict(),
|
|
97
|
+
]),
|
|
98
|
+
scope: PermissionScopeSchema.nullable(),
|
|
99
|
+
})
|
|
100
|
+
.strict()
|
|
101
|
+
.superRefine((p, ctx) => {
|
|
102
|
+
const reject = (message) => ctx.addIssue({ code: "custom", message });
|
|
103
|
+
if ((p.profileRevision === null) !== (p.selectedProfile === null))
|
|
104
|
+
reject("Profile and revision nullability must agree");
|
|
105
|
+
if (p.availability.state === "unavailable") {
|
|
106
|
+
if (p.effectiveProfile !== null ||
|
|
107
|
+
p.deviceId !== null ||
|
|
108
|
+
p.scopeRevision !== null ||
|
|
109
|
+
p.authorityRevision !== null ||
|
|
110
|
+
p.scope !== null)
|
|
111
|
+
reject("Unavailable context must not expose device authority");
|
|
112
|
+
if (p.availability.cause === "actor-device-access") {
|
|
113
|
+
if (p.selectedProfile !== null || p.profileRevision !== null)
|
|
114
|
+
reject("Device access refusal must redact the owner's profile");
|
|
115
|
+
if (p.availability.reason !== "This run's actor cannot use the selected device")
|
|
116
|
+
reject("Invalid device access reason");
|
|
117
|
+
}
|
|
118
|
+
else if (p.availability.reason !== "Choose a device to run device operations")
|
|
119
|
+
reject("Invalid no-device reason");
|
|
120
|
+
}
|
|
121
|
+
else if (p.selectedProfile === null ||
|
|
122
|
+
p.effectiveProfile === null ||
|
|
123
|
+
p.profileRevision === null ||
|
|
124
|
+
p.deviceId === null ||
|
|
125
|
+
p.scopeRevision === null ||
|
|
126
|
+
p.authorityRevision === null) {
|
|
127
|
+
reject("Accessible device context requires complete profile and authority identities");
|
|
128
|
+
}
|
|
129
|
+
if ((p.scope !== null) !== (p.availability.state === "supported"))
|
|
130
|
+
reject("Only supported context carries scope");
|
|
131
|
+
if (p.effectiveProfile !== null) {
|
|
132
|
+
if (p.execution === "scheduled" && p.effectiveProfile !== "request-approval")
|
|
133
|
+
reject("Scheduled context requires Request approval");
|
|
134
|
+
if (p.execution === "interactive" &&
|
|
135
|
+
(p.selectedProfile === "full-access"
|
|
136
|
+
? p.effectiveProfile !== "full-access" && p.effectiveProfile !== "approve-for-me"
|
|
137
|
+
: p.selectedProfile !== p.effectiveProfile))
|
|
138
|
+
reject("Invalid effective profile transition");
|
|
139
|
+
}
|
|
140
|
+
const s = p.scope;
|
|
141
|
+
if (!s)
|
|
142
|
+
return;
|
|
143
|
+
if (p.effectiveProfile === "full-access") {
|
|
144
|
+
if (s.filesystem.kind !== "device" || s.network.kind !== "environment")
|
|
145
|
+
reject("Full access requires device filesystem and environment networking");
|
|
146
|
+
}
|
|
147
|
+
else if (s.filesystem.kind !== "scoped" || s.network.kind === "environment")
|
|
148
|
+
reject("Restricted profiles require scoped filesystem and restricted networking");
|
|
149
|
+
if (s.filesystem.kind === "scoped") {
|
|
150
|
+
const { readDirectories, writeDirectories } = s.filesystem;
|
|
151
|
+
if (!readDirectories.includes(s.workingRoot) ||
|
|
152
|
+
!writeDirectories.includes(s.workingRoot) ||
|
|
153
|
+
writeDirectories.some((p) => !readDirectories.includes(p)))
|
|
154
|
+
reject("Writable roots must be readable and both must include the working root");
|
|
155
|
+
if (new Set([...readDirectories, ...writeDirectories]).size > 64)
|
|
156
|
+
reject("At most 64 combined roots are allowed");
|
|
157
|
+
}
|
|
158
|
+
if ((s.location === "local") !== (s.outerNetwork.kind === "host-environment"))
|
|
159
|
+
reject("Outer boundary must match the device location");
|
|
160
|
+
if (s.location === "cloud" && s.network.kind === "allowlist") {
|
|
161
|
+
if (s.outerNetwork.kind === "none")
|
|
162
|
+
reject("Network hosts exceed the disabled outer boundary");
|
|
163
|
+
if (s.outerNetwork.kind === "allowlist") {
|
|
164
|
+
const outer = s.outerNetwork.hosts;
|
|
165
|
+
if (s.network.hosts.some((host) => !outer.some((pattern) => coversHost(pattern, host))))
|
|
166
|
+
reject("Network hosts exceed the applied outer allowlist");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
export const ManagedDevicePathsV1Schema = z
|
|
171
|
+
.object({
|
|
172
|
+
permissionContextVersion: z.literal(1),
|
|
173
|
+
deviceId: PermissionId,
|
|
174
|
+
roots: z
|
|
175
|
+
.object({ workspace: PermissionPath, skills: PermissionPath, tmp: PermissionPath })
|
|
176
|
+
.strict(),
|
|
177
|
+
workingRoot: PermissionPath,
|
|
178
|
+
})
|
|
179
|
+
.strict();
|
|
180
|
+
export const PermissionContextMetaV1Schema = z
|
|
181
|
+
.object({
|
|
182
|
+
version: z.literal(1),
|
|
183
|
+
contextSeq: z.number().int().positive().max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
184
|
+
hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
185
|
+
})
|
|
186
|
+
.strict();
|
|
6
187
|
/** 供应商私有数据(`ProviderOpaque`):原样保存、只回放给同一供应商。 */
|
|
7
188
|
const ProviderOpaqueSchema = z.object({
|
|
8
189
|
provider: z.string(),
|
|
@@ -56,8 +237,40 @@ export const COMMAND_ASK_MAX_CHARS = 32 * 1024;
|
|
|
56
237
|
* `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
|
|
57
238
|
* match a record to what ran.
|
|
58
239
|
*/
|
|
59
|
-
const
|
|
240
|
+
export const PermissionExpansionSchema = z
|
|
60
241
|
.object({
|
|
242
|
+
readDirectories: z.array(z.string().max(4096)).max(64),
|
|
243
|
+
writeDirectories: z.array(z.string().max(4096)).max(64),
|
|
244
|
+
hosts: z.array(z.string().max(253)).max(100),
|
|
245
|
+
})
|
|
246
|
+
.strict();
|
|
247
|
+
export const PermissionCallBindingSchema = z
|
|
248
|
+
.object({
|
|
249
|
+
orgId: z.string(),
|
|
250
|
+
rootConversationId: z.string(),
|
|
251
|
+
conversationId: z.string(),
|
|
252
|
+
deviceId: z.string(),
|
|
253
|
+
accountId: z.string(),
|
|
254
|
+
runId: z.string(),
|
|
255
|
+
callId: z.string(),
|
|
256
|
+
toolKey: z.string(),
|
|
257
|
+
specHash: z.string(),
|
|
258
|
+
callInputHash: z.string(),
|
|
259
|
+
resolvedInputHash: z.string(),
|
|
260
|
+
profile: z.enum(["request-approval", "approve-for-me", "full-access"]),
|
|
261
|
+
profileRevision: z.number().int().nonnegative(),
|
|
262
|
+
scopeRevision: z.string(),
|
|
263
|
+
authorityRevision: z.string(),
|
|
264
|
+
})
|
|
265
|
+
.strict();
|
|
266
|
+
export const ReviewRecordSchema = z
|
|
267
|
+
.object({
|
|
268
|
+
profile: z.enum(["request-approval", "approve-for-me", "full-access"]).optional(),
|
|
269
|
+
profileRevision: z.number().int().nonnegative().optional(),
|
|
270
|
+
scopeRevision: z.string().optional(),
|
|
271
|
+
decisionSource: z
|
|
272
|
+
.enum(["scope", "human", "review-model", "full-access", "task-grant"])
|
|
273
|
+
.optional(),
|
|
61
274
|
decision: z.enum(["allow", "deny"]),
|
|
62
275
|
by: z.enum(["rule", "classifier", "person"]),
|
|
63
276
|
rule: z.string().nullable(),
|
|
@@ -72,6 +285,9 @@ const ReviewRecordSchema = z
|
|
|
72
285
|
/** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
|
|
73
286
|
export const CommandAskSchema = z
|
|
74
287
|
.object({
|
|
288
|
+
permissionScope: PermissionExpansionSchema.optional(),
|
|
289
|
+
targetPath: z.string().max(4096).optional(),
|
|
290
|
+
candidateHash: z.string().optional(),
|
|
75
291
|
/** A shell command or a file write. */
|
|
76
292
|
kind: z.enum(["command", "write"]),
|
|
77
293
|
/** The command text, or the tool key of the write. */
|
|
@@ -225,6 +441,8 @@ const ModelUsageShape = {
|
|
|
225
441
|
outputTokens: count,
|
|
226
442
|
cacheReadTokens: count,
|
|
227
443
|
cacheWriteTokens: count,
|
|
444
|
+
/** Images produced (an image generation call). */
|
|
445
|
+
outputImages: count.exactOptional(),
|
|
228
446
|
};
|
|
229
447
|
/**
|
|
230
448
|
* How a sub-agent's run ended (`subagent_finished`, a `subagent_delivery` finish). `timed_out`:
|
|
@@ -334,6 +552,26 @@ export const PluginContextSchema = z.object({
|
|
|
334
552
|
* 读出时按写入时的形状原样返回。
|
|
335
553
|
*/
|
|
336
554
|
export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
555
|
+
ev("permission_context", PermissionContextV1Schema),
|
|
556
|
+
ev("permission_reviewed", z.object({
|
|
557
|
+
binding: PermissionCallBindingSchema,
|
|
558
|
+
permissionScope: PermissionExpansionSchema,
|
|
559
|
+
targetPath: z.string().max(4096).optional(),
|
|
560
|
+
scopeKind: z.literal("directories-and-hosts"),
|
|
561
|
+
candidateHash: z.string(),
|
|
562
|
+
outcome: z.enum(["allow", "ask", "deny"]),
|
|
563
|
+
reason: z.string(),
|
|
564
|
+
decisionSource: z.literal("review-model"),
|
|
565
|
+
})),
|
|
566
|
+
ev("permission_profile_changed", z.object({
|
|
567
|
+
oldProfile: z.enum(["request-approval", "approve-for-me", "full-access"]),
|
|
568
|
+
newProfile: z.enum(["request-approval", "approve-for-me", "full-access"]),
|
|
569
|
+
actorAccountId: z.string().nullable(),
|
|
570
|
+
reason: z.enum(["user", "authority-changed"]).optional(),
|
|
571
|
+
deviceId: z.string().nullable(),
|
|
572
|
+
scopeRevision: z.string().nullable(),
|
|
573
|
+
revision: z.number().int().nonnegative(),
|
|
574
|
+
})),
|
|
337
575
|
ev("user_message", z.object({
|
|
338
576
|
content: z.array(ContentBlockSchema),
|
|
339
577
|
/**
|
|
@@ -480,6 +718,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
480
718
|
toSeq: seqNo,
|
|
481
719
|
summarySeq: seqNo.nullable(),
|
|
482
720
|
systemHash: z.string(),
|
|
721
|
+
permissionContext: PermissionContextMetaV1Schema.optional(),
|
|
483
722
|
reminderSeqs: z.array(seqNo),
|
|
484
723
|
/**
|
|
485
724
|
* The request's output cap: `min(model cap, maxOutputTokens knob ??
|
|
@@ -598,14 +837,16 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
598
837
|
* `web_fetch` = a `WebFetch` extraction call (web tools spec §5: the tool call's run and step,
|
|
599
838
|
* `callId` = the call; not model-visible, billed and reported, counted on a sub-agent's parent);
|
|
600
839
|
* `review` = the command-review classifier's call (auto mode spec §5.3: not model-visible, billed
|
|
601
|
-
* and reported, `callId` = the reviewed tool call)
|
|
840
|
+
* and reported, `callId` = the reviewed tool call); `image` = a `GenerateImage` call (image
|
|
841
|
+
* generation spec §7: the tool call's run and step, `callId` = the call, `outputImages` = the
|
|
842
|
+
* images produced; not model-visible, billed and reported, counted on a sub-agent's parent).
|
|
602
843
|
*/
|
|
603
844
|
ev("usage", z.object({
|
|
604
845
|
step: count,
|
|
605
846
|
provider: z.string(),
|
|
606
847
|
model: z.string(),
|
|
607
848
|
...ModelUsageShape,
|
|
608
|
-
purpose: z.enum(["compaction", "title", "web_fetch", "review"]).optional(),
|
|
849
|
+
purpose: z.enum(["compaction", "title", "web_fetch", "review", "image"]).optional(),
|
|
609
850
|
/**
|
|
610
851
|
* The chunk a chunked compaction call summarised (1-based), with the number of calls the
|
|
611
852
|
* compaction attempted (the full chunk count on a completed one; on a failed or hook-denied
|
|
@@ -613,7 +854,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
613
854
|
*/
|
|
614
855
|
chunk: count.optional(),
|
|
615
856
|
chunks: count.optional(),
|
|
616
|
-
/** The tool call a `web_fetch` or `
|
|
857
|
+
/** The tool call a `web_fetch`, `review` or `image` usage belongs to. */
|
|
617
858
|
callId: z.string().optional(),
|
|
618
859
|
})),
|
|
619
860
|
ev("reminder", z.object({ step: count, text: z.string() })),
|
|
@@ -646,32 +887,36 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
646
887
|
* they change, before that call's result. **Model-visible**: rendered at its position as a
|
|
647
888
|
* system message (`devicePathsText`); a summary covering it is followed by the latest one again.
|
|
648
889
|
*/
|
|
649
|
-
ev("device_paths", z.
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
/** The current network (`none` on events recorded before auto mode). */
|
|
658
|
-
network: z
|
|
659
|
-
.union([
|
|
660
|
-
z.literal("none"),
|
|
661
|
-
z.object({
|
|
662
|
-
kind: z.enum(["open-public", "allowlist"]),
|
|
663
|
-
hosts: z.array(z.string()),
|
|
890
|
+
ev("device_paths", z.union([
|
|
891
|
+
ManagedDevicePathsV1Schema,
|
|
892
|
+
z.object({
|
|
893
|
+
permissionContextVersion: z.never().optional(),
|
|
894
|
+
roots: z.object({
|
|
895
|
+
workspace: z.string().min(1).max(4096),
|
|
896
|
+
skills: z.string().min(1).max(4096),
|
|
897
|
+
tmp: z.string().min(1).max(4096),
|
|
664
898
|
}),
|
|
665
|
-
|
|
666
|
-
.optional(),
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
899
|
+
tier: z.enum(["strict", "dev", "open"]).optional(),
|
|
900
|
+
isolation: z.enum(["sandbox", "none"]).optional(),
|
|
901
|
+
/** The current network (`none` on events recorded before auto mode). */
|
|
902
|
+
network: z
|
|
903
|
+
.union([
|
|
904
|
+
z.literal("none"),
|
|
905
|
+
z.object({
|
|
906
|
+
kind: z.enum(["open-public", "allowlist"]),
|
|
907
|
+
hosts: z.array(z.string()),
|
|
908
|
+
}),
|
|
909
|
+
])
|
|
910
|
+
.optional(),
|
|
911
|
+
localhost: z.enum(["on", "off-proxy-detected", "off"]).optional(),
|
|
912
|
+
unixSockets: z.enum(["roots", "all-masked", "off"]).optional(),
|
|
913
|
+
unattended: z.literal(true).optional(),
|
|
914
|
+
/** Auto mode: the mode and its ceiling, and whether the device is a connected machine. */
|
|
915
|
+
mode: z.enum(["auto", "sandbox"]).optional(),
|
|
916
|
+
allowedMode: z.enum(["auto", "sandbox"]).optional(),
|
|
917
|
+
local: z.boolean().optional(),
|
|
918
|
+
}),
|
|
919
|
+
])),
|
|
675
920
|
/**
|
|
676
921
|
* The project a bound conversation's run read at its start (project root spec §4.4): the
|
|
677
922
|
* project's name and root, its `AGENTS.md` text, and per skill its name, description and digest;
|
|
@@ -742,7 +987,15 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
742
987
|
}
|
|
743
988
|
})),
|
|
744
989
|
/** 工具调用开始执行之前写入(续跑时「有开始无结果」的调用记为结果未知,不再执行)。 */
|
|
745
|
-
ev("tool_call_started", z.object({
|
|
990
|
+
ev("tool_call_started", z.object({
|
|
991
|
+
step: count,
|
|
992
|
+
callId: z.string(),
|
|
993
|
+
toolKey: z.string(),
|
|
994
|
+
specHash: z.string(),
|
|
995
|
+
permissionInput: z
|
|
996
|
+
.object({ callInputHash: z.string(), resolvedInputHash: z.string() })
|
|
997
|
+
.optional(),
|
|
998
|
+
})),
|
|
746
999
|
/**
|
|
747
1000
|
* 工具调用的结果(模型看到的文本)。构建请求时还原为紧随该步 assistant 消息的 user 消息中的
|
|
748
1001
|
* `tool_result` 块。`outputId`:超长结果转存后的存档 id;`contentTypes`:结果里出现的内容类型。
|
|
@@ -840,7 +1093,8 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
840
1093
|
ev("approval_decided", z.object({
|
|
841
1094
|
approvalId: z.string(),
|
|
842
1095
|
callId: z.string(),
|
|
843
|
-
decision: z.enum(["approved", "denied", "expired", "cancelled", "skipped"]),
|
|
1096
|
+
decision: z.enum(["approved", "denied", "expired", "cancelled", "skipped", "superseded"]),
|
|
1097
|
+
revision: z.number().int().nonnegative().optional(),
|
|
844
1098
|
scope: z.enum(["once", "session", "always"]).optional(),
|
|
845
1099
|
byAccountId: z.string().nullable(),
|
|
846
1100
|
/**
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Selectable } from "kysely";
|
|
2
|
+
import type { ConversationsTable } from "../db/kernel-schema.js";
|
|
3
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
|
+
import { ConversationAccess } from "./access.js";
|
|
5
|
+
export type PermissionRoot = Selectable<ConversationsTable>;
|
|
6
|
+
/** Stored root state and the existing live access checks, without profile views or lifecycle calls. */
|
|
7
|
+
export declare class PermissionProfileStore {
|
|
8
|
+
private readonly db;
|
|
9
|
+
private readonly access;
|
|
10
|
+
constructor(db: KernelDb, access: ConversationAccess);
|
|
11
|
+
own(orgId: string, id: string, accountId: string): Promise<{
|
|
12
|
+
account_id: string;
|
|
13
|
+
agent_id: string;
|
|
14
|
+
archived_at: Date | null;
|
|
15
|
+
consumed_seq: string;
|
|
16
|
+
create_request_hash: string | null;
|
|
17
|
+
create_request_id: string | null;
|
|
18
|
+
created_at: Date;
|
|
19
|
+
deleted_at: Date | null;
|
|
20
|
+
device_id: string | null;
|
|
21
|
+
eval_run_id: string | null;
|
|
22
|
+
id: string;
|
|
23
|
+
kind: import("../db/kernel-schema.js").ConversationKind;
|
|
24
|
+
last_seq: string;
|
|
25
|
+
org_id: string;
|
|
26
|
+
parent_conversation_id: string | null;
|
|
27
|
+
permission_consent: unknown;
|
|
28
|
+
permission_profile: "approve-for-me" | "full-access" | "request-approval";
|
|
29
|
+
permission_revision: number;
|
|
30
|
+
project_name: string | null;
|
|
31
|
+
project_path: string | null;
|
|
32
|
+
queue_pause_reason: string | null;
|
|
33
|
+
queue_paused: boolean;
|
|
34
|
+
scheduled_task_id: string | null;
|
|
35
|
+
selection: unknown;
|
|
36
|
+
source: "channel_dm" | "channel_group" | "subagent" | "web";
|
|
37
|
+
subagent_depth: number;
|
|
38
|
+
subagent_type: string | null;
|
|
39
|
+
title: string | null;
|
|
40
|
+
title_attempts: number;
|
|
41
|
+
title_source: import("../db/kernel-schema.js").TitleSource | null;
|
|
42
|
+
tree_stopped_at: Date | null;
|
|
43
|
+
updated_at: Date;
|
|
44
|
+
}>;
|
|
45
|
+
/** Internal stored facts; request callers use readOwnedRoot to check every ancestor. */
|
|
46
|
+
readRoot(orgId: string, id: string): Promise<PermissionRoot>;
|
|
47
|
+
private read;
|
|
48
|
+
/** Keep the existing account, agent visibility and ancestor checks on every read. */
|
|
49
|
+
readOwnedRoot(orgId: string, id: string, accountId: string): Promise<PermissionRoot>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import { ApiError } from "../errors.js";
|
|
12
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
+
import { ConversationAccess } from "./access.js";
|
|
14
|
+
/** Stored root state and the existing live access checks, without profile views or lifecycle calls. */
|
|
15
|
+
let PermissionProfileStore = class PermissionProfileStore {
|
|
16
|
+
db;
|
|
17
|
+
access;
|
|
18
|
+
constructor(db, access) {
|
|
19
|
+
this.db = db;
|
|
20
|
+
this.access = access;
|
|
21
|
+
}
|
|
22
|
+
async own(orgId, id, accountId) {
|
|
23
|
+
if (!(await this.access.isAccessible(orgId, id, accountId)))
|
|
24
|
+
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
25
|
+
return this.db
|
|
26
|
+
.selectFrom("conversations")
|
|
27
|
+
.selectAll()
|
|
28
|
+
.where("id", "=", id)
|
|
29
|
+
.where("org_id", "=", orgId)
|
|
30
|
+
.executeTakeFirstOrThrow();
|
|
31
|
+
}
|
|
32
|
+
/** Internal stored facts; request callers use readOwnedRoot to check every ancestor. */
|
|
33
|
+
async readRoot(orgId, id) {
|
|
34
|
+
let row = await this.read(orgId, id);
|
|
35
|
+
for (let depth = 0; row.parent_conversation_id && depth < 16; depth++)
|
|
36
|
+
row = await this.read(orgId, row.parent_conversation_id);
|
|
37
|
+
if (row.parent_conversation_id)
|
|
38
|
+
throw new ApiError("conversation.not_found", "Conversation root not found");
|
|
39
|
+
return row;
|
|
40
|
+
}
|
|
41
|
+
async read(orgId, id) {
|
|
42
|
+
const row = await this.db
|
|
43
|
+
.selectFrom("conversations")
|
|
44
|
+
.selectAll()
|
|
45
|
+
.where("id", "=", id)
|
|
46
|
+
.where("org_id", "=", orgId)
|
|
47
|
+
.executeTakeFirst();
|
|
48
|
+
if (!row)
|
|
49
|
+
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
50
|
+
return row;
|
|
51
|
+
}
|
|
52
|
+
/** Keep the existing account, agent visibility and ancestor checks on every read. */
|
|
53
|
+
async readOwnedRoot(orgId, id, accountId) {
|
|
54
|
+
let row = await this.own(orgId, id, accountId);
|
|
55
|
+
for (let depth = 0; row.parent_conversation_id && depth < 16; depth++)
|
|
56
|
+
row = await this.own(orgId, row.parent_conversation_id, accountId);
|
|
57
|
+
if (row.parent_conversation_id)
|
|
58
|
+
throw new ApiError("conversation.not_found", "Conversation root not found");
|
|
59
|
+
return row;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
PermissionProfileStore = __decorate([
|
|
63
|
+
Injectable(),
|
|
64
|
+
__param(0, Inject(KernelDb)),
|
|
65
|
+
__param(1, Inject(ConversationAccess))
|
|
66
|
+
], PermissionProfileStore);
|
|
67
|
+
export { PermissionProfileStore };
|
|
@@ -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 { ConversationAccessModule } from "./access.js";
|
|
9
|
+
import { PermissionProfileStore } from "./permission-profile-store.js";
|
|
10
|
+
let PermissionProfileStoreModule = class PermissionProfileStoreModule {
|
|
11
|
+
};
|
|
12
|
+
PermissionProfileStoreModule = __decorate([
|
|
13
|
+
Module({
|
|
14
|
+
imports: [ConversationAccessModule],
|
|
15
|
+
providers: [PermissionProfileStore],
|
|
16
|
+
exports: [PermissionProfileStore],
|
|
17
|
+
})
|
|
18
|
+
], PermissionProfileStoreModule);
|
|
19
|
+
export { PermissionProfileStoreModule };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { FastifyReply } from "fastify";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import { type Principal } from "../identity/principal.js";
|
|
4
|
+
import { type OrgContext } from "../orgs/org.guard.js";
|
|
5
|
+
import { ConversationsService } from "./conversations.service.js";
|
|
6
|
+
import { PermissionGetParams, PermissionPatchBody, PermissionPreviewQuery } from "./permission-profiles.schemas.js";
|
|
7
|
+
import { PermissionProfilesService } from "./permission-profiles.service.js";
|
|
8
|
+
export declare const FirstMessageBody: z.ZodObject<{
|
|
9
|
+
agentId: z.ZodString;
|
|
10
|
+
deviceId: z.ZodOptional<z.ZodString>;
|
|
11
|
+
project: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
12
|
+
message: z.ZodNonOptional<z.ZodOptional<z.ZodObject<{
|
|
13
|
+
text: z.ZodString;
|
|
14
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
15
|
+
connectorId: z.ZodUUID;
|
|
16
|
+
uri: z.ZodString;
|
|
17
|
+
}, z.core.$strict>>>;
|
|
18
|
+
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
19
|
+
model: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
provider: z.ZodString;
|
|
21
|
+
model: z.ZodString;
|
|
22
|
+
}, z.core.$strict>>;
|
|
23
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
24
|
+
high: "high";
|
|
25
|
+
low: "low";
|
|
26
|
+
max: "max";
|
|
27
|
+
medium: "medium";
|
|
28
|
+
xhigh: "xhigh";
|
|
29
|
+
}>>;
|
|
30
|
+
skill: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
timeZone: z.ZodOptional<z.ZodString>;
|
|
34
|
+
locale: z.ZodOptional<z.ZodEnum<{
|
|
35
|
+
en: "en";
|
|
36
|
+
zh: "zh";
|
|
37
|
+
}>>;
|
|
38
|
+
clientMessageId: z.ZodString;
|
|
39
|
+
}, z.core.$strict>>>;
|
|
40
|
+
permission: z.ZodObject<{
|
|
41
|
+
profile: z.ZodEnum<{
|
|
42
|
+
"approve-for-me": "approve-for-me";
|
|
43
|
+
"full-access": "full-access";
|
|
44
|
+
"request-approval": "request-approval";
|
|
45
|
+
}>;
|
|
46
|
+
consentScopeRevision: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
export declare class PermissionProfilesController {
|
|
50
|
+
private readonly permissions;
|
|
51
|
+
private readonly conversations;
|
|
52
|
+
constructor(permissions: PermissionProfilesService, conversations: ConversationsService);
|
|
53
|
+
get(org: OrgContext, p: Principal, { id }: z.infer<typeof PermissionGetParams>): Promise<{
|
|
54
|
+
profile: import("@capybara-hq/plugin-sdk").PermissionProfile;
|
|
55
|
+
revision: number;
|
|
56
|
+
rootConversationId: string;
|
|
57
|
+
deviceId: string | null;
|
|
58
|
+
consentScope: {
|
|
59
|
+
deviceId: string;
|
|
60
|
+
scopeRevision: string;
|
|
61
|
+
} | null;
|
|
62
|
+
scopeRevision: string | null;
|
|
63
|
+
availability: import("../sandbox/permission-availability.js").PermissionAvailability;
|
|
64
|
+
fullAccessCeiling: boolean;
|
|
65
|
+
broadProjectReach: boolean;
|
|
66
|
+
startingWorkNotice: string;
|
|
67
|
+
}>;
|
|
68
|
+
set(org: OrgContext, p: Principal, { id }: z.infer<typeof PermissionGetParams>, body: z.infer<typeof PermissionPatchBody>): Promise<{
|
|
69
|
+
revision: number;
|
|
70
|
+
}>;
|
|
71
|
+
preview(org: OrgContext, p: Principal, q: z.infer<typeof PermissionPreviewQuery>): Promise<{
|
|
72
|
+
deviceId: string;
|
|
73
|
+
project: string | null;
|
|
74
|
+
scopeRevision: string;
|
|
75
|
+
availability: import("../sandbox/permission-availability.js").PermissionAvailability;
|
|
76
|
+
fullAccessCeiling: boolean;
|
|
77
|
+
broadProjectReach: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
first(org: OrgContext, p: Principal, body: z.infer<typeof FirstMessageBody>, reply: FastifyReply): Promise<{
|
|
80
|
+
conversation: import("./conversations.service.js").ConversationView;
|
|
81
|
+
event: import("./events.js").ConversationEvent;
|
|
82
|
+
events: import("./events.js").ConversationEvent[];
|
|
83
|
+
}>;
|
|
84
|
+
}
|