@capybara-hq/kernel 0.1.0-rc.40 → 0.1.0-rc.42
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 +10 -1
- 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 +1 -1
- package/dist/config/schema.js +11 -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 +304 -4
- package/dist/conversations/events.js +279 -29
- 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/db/kernel-schema.d.ts +238 -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/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 +31 -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/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/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/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/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/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 +129 -0
- package/dist/sandbox/review/review.service.d.ts +4 -1
- package/dist/sandbox/review/review.service.js +19 -5
- 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/builtins/builtin-tools.d.ts +16 -2
- package/dist/tools/builtins/builtin-tools.js +38 -10
- 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 +2 -2
- 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 +300 -19
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +12 -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/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -0,0 +1,105 @@
|
|
|
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 { Controller, Get, Inject, Patch, Post, Res } from "@nestjs/common";
|
|
11
|
+
import { CurrentPrincipal, requireUser, SessionOnly, } from "../identity/principal.js";
|
|
12
|
+
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
13
|
+
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
14
|
+
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
15
|
+
import { CreateBody } from "./conversations.controller.js";
|
|
16
|
+
import { ConversationsService } from "./conversations.service.js";
|
|
17
|
+
import { PermissionGetParams, PermissionPatchBody, PermissionPreviewQuery, PermissionSelectionSchema, } from "./permission-profiles.schemas.js";
|
|
18
|
+
import { PermissionProfilesService } from "./permission-profiles.service.js";
|
|
19
|
+
export const FirstMessageBody = CreateBody.required({ message: true })
|
|
20
|
+
.extend({ permission: PermissionSelectionSchema })
|
|
21
|
+
.strict();
|
|
22
|
+
class PermissionParamsDto extends createZodDto(PermissionGetParams, "PermissionParams") {
|
|
23
|
+
}
|
|
24
|
+
class PermissionPatchDto extends createZodDto(PermissionPatchBody, "PermissionPatch") {
|
|
25
|
+
}
|
|
26
|
+
class PermissionPreviewDto extends createZodDto(PermissionPreviewQuery, "PermissionPreview") {
|
|
27
|
+
}
|
|
28
|
+
class FirstMessageDto extends createZodDto(FirstMessageBody, "ConversationFirstMessage") {
|
|
29
|
+
}
|
|
30
|
+
let PermissionProfilesController = class PermissionProfilesController {
|
|
31
|
+
permissions;
|
|
32
|
+
conversations;
|
|
33
|
+
constructor(permissions, conversations) {
|
|
34
|
+
this.permissions = permissions;
|
|
35
|
+
this.conversations = conversations;
|
|
36
|
+
}
|
|
37
|
+
get(org, p, { id }) {
|
|
38
|
+
return this.permissions.get(org.orgId, id, requireUser(p).account.id);
|
|
39
|
+
}
|
|
40
|
+
set(org, p, { id }, body) {
|
|
41
|
+
return this.permissions.set(org.orgId, id, requireUser(p).account.id, body);
|
|
42
|
+
}
|
|
43
|
+
preview(org, p, q) {
|
|
44
|
+
return this.permissions.preview(org.orgId, requireUser(p).account.id, q.deviceId, q.project);
|
|
45
|
+
}
|
|
46
|
+
async first(org, p, body, reply) {
|
|
47
|
+
const { permission, agentId, message, deviceId, project } = body;
|
|
48
|
+
const out = await this.conversations.createWithMessage(org.orgId, requireUser(p).account.id, agentId, {
|
|
49
|
+
text: message.text,
|
|
50
|
+
clientMessageId: message.clientMessageId,
|
|
51
|
+
...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
|
|
52
|
+
...(message.files !== undefined ? { files: message.files } : {}),
|
|
53
|
+
...(message.model !== undefined ? { model: message.model } : {}),
|
|
54
|
+
...(message.effort !== undefined ? { effort: message.effort } : {}),
|
|
55
|
+
...(message.skill !== undefined ? { skill: message.skill } : {}),
|
|
56
|
+
...(message.timeZone !== undefined ? { timeZone: message.timeZone } : {}),
|
|
57
|
+
...(message.locale !== undefined ? { locale: message.locale } : {}),
|
|
58
|
+
}, {
|
|
59
|
+
...(deviceId !== undefined ? { deviceId } : {}),
|
|
60
|
+
...(project !== undefined ? { project } : {}),
|
|
61
|
+
}, { source: "web", initialPermission: permission });
|
|
62
|
+
reply.status(out.created ? 201 : 200);
|
|
63
|
+
return { conversation: out.conversation, event: out.event, events: out.events };
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
Get("conversations/:id/permissions"),
|
|
68
|
+
SessionOnly(),
|
|
69
|
+
OrgAction("agents.use"),
|
|
70
|
+
__param(0, CurrentOrg()),
|
|
71
|
+
__param(1, CurrentPrincipal()),
|
|
72
|
+
__param(2, ZParam(PermissionParamsDto))
|
|
73
|
+
], PermissionProfilesController.prototype, "get", null);
|
|
74
|
+
__decorate([
|
|
75
|
+
Patch("conversations/:id/permissions"),
|
|
76
|
+
SessionOnly(),
|
|
77
|
+
OrgAction("agents.use"),
|
|
78
|
+
__param(0, CurrentOrg()),
|
|
79
|
+
__param(1, CurrentPrincipal()),
|
|
80
|
+
__param(2, ZParam(PermissionParamsDto)),
|
|
81
|
+
__param(3, ZBody(PermissionPatchDto))
|
|
82
|
+
], PermissionProfilesController.prototype, "set", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
Get("conversation-permission-preview"),
|
|
85
|
+
SessionOnly(),
|
|
86
|
+
OrgAction("agents.use"),
|
|
87
|
+
__param(0, CurrentOrg()),
|
|
88
|
+
__param(1, CurrentPrincipal()),
|
|
89
|
+
__param(2, ZQuery(PermissionPreviewDto))
|
|
90
|
+
], PermissionProfilesController.prototype, "preview", null);
|
|
91
|
+
__decorate([
|
|
92
|
+
Post("conversations/first-message"),
|
|
93
|
+
SessionOnly(),
|
|
94
|
+
OrgAction("agents.use"),
|
|
95
|
+
__param(0, CurrentOrg()),
|
|
96
|
+
__param(1, CurrentPrincipal()),
|
|
97
|
+
__param(2, ZBody(FirstMessageDto)),
|
|
98
|
+
__param(3, Res({ passthrough: true }))
|
|
99
|
+
], PermissionProfilesController.prototype, "first", null);
|
|
100
|
+
PermissionProfilesController = __decorate([
|
|
101
|
+
Controller("api/v1/orgs/:orgId"),
|
|
102
|
+
__param(0, Inject(PermissionProfilesService)),
|
|
103
|
+
__param(1, Inject(ConversationsService))
|
|
104
|
+
], PermissionProfilesController);
|
|
105
|
+
export { PermissionProfilesController };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const PermissionProfileSchema: z.ZodEnum<{
|
|
3
|
+
"approve-for-me": "approve-for-me";
|
|
4
|
+
"full-access": "full-access";
|
|
5
|
+
"request-approval": "request-approval";
|
|
6
|
+
}>;
|
|
7
|
+
export declare const PermissionSelectionSchema: z.ZodObject<{
|
|
8
|
+
profile: z.ZodEnum<{
|
|
9
|
+
"approve-for-me": "approve-for-me";
|
|
10
|
+
"full-access": "full-access";
|
|
11
|
+
"request-approval": "request-approval";
|
|
12
|
+
}>;
|
|
13
|
+
consentScopeRevision: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export declare const PermissionPatchBody: z.ZodObject<{
|
|
16
|
+
profile: z.ZodEnum<{
|
|
17
|
+
"approve-for-me": "approve-for-me";
|
|
18
|
+
"full-access": "full-access";
|
|
19
|
+
"request-approval": "request-approval";
|
|
20
|
+
}>;
|
|
21
|
+
consentScopeRevision: z.ZodOptional<z.ZodString>;
|
|
22
|
+
expectedRevision: z.ZodNumber;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export declare const PermissionGetParams: z.ZodObject<{
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const PermissionPreviewQuery: z.ZodObject<{
|
|
28
|
+
deviceId: z.ZodString;
|
|
29
|
+
project: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
30
|
+
}, z.core.$strict>;
|
|
31
|
+
export type PermissionSelection = z.infer<typeof PermissionSelectionSchema>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isDeviceProjectName } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const PermissionProfileSchema = z.enum([
|
|
4
|
+
"request-approval",
|
|
5
|
+
"approve-for-me",
|
|
6
|
+
"full-access",
|
|
7
|
+
]);
|
|
8
|
+
export const PermissionSelectionSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
profile: PermissionProfileSchema,
|
|
11
|
+
consentScopeRevision: z.string().min(1).max(128).optional(),
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
export const PermissionPatchBody = PermissionSelectionSchema.extend({
|
|
15
|
+
expectedRevision: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
16
|
+
}).strict();
|
|
17
|
+
export const PermissionGetParams = z.object({ id: z.string().min(1).max(100) });
|
|
18
|
+
export const PermissionPreviewQuery = z
|
|
19
|
+
.object({
|
|
20
|
+
deviceId: z.string().min(1).max(100),
|
|
21
|
+
project: z.string().refine(isDeviceProjectName).optional(),
|
|
22
|
+
})
|
|
23
|
+
.strict();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DeviceAccess } from "../devices/access.js";
|
|
2
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
+
import { PermissionAuthorityEpochStore } from "../sandbox/permission-authority-epochs.js";
|
|
5
|
+
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
6
|
+
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
7
|
+
import { PermissionTransitions } from "../sandbox/permission-transitions.js";
|
|
8
|
+
import { EventLog } from "./event-log.js";
|
|
9
|
+
import type { ConversationEvent } from "./events.js";
|
|
10
|
+
import { PermissionProfileStore } from "./permission-profile-store.js";
|
|
11
|
+
import type { PermissionSelection } from "./permission-profiles.schemas.js";
|
|
12
|
+
export declare class PermissionProfilesService {
|
|
13
|
+
private readonly transitions;
|
|
14
|
+
private readonly facts;
|
|
15
|
+
private readonly store;
|
|
16
|
+
private readonly db;
|
|
17
|
+
readonly txHost: TransactionHost;
|
|
18
|
+
private readonly devices;
|
|
19
|
+
private readonly locks;
|
|
20
|
+
private readonly epochs;
|
|
21
|
+
private readonly events;
|
|
22
|
+
constructor(transitions: PermissionTransitions, facts: PermissionFacts, store: PermissionProfileStore, db: KernelDb, txHost: TransactionHost, devices: DeviceAccess, locks: PermissionAuthorityLock, epochs: PermissionAuthorityEpochStore, events: EventLog);
|
|
23
|
+
preview(orgId: string, accountId: string, deviceId: string, project?: string): Promise<{
|
|
24
|
+
deviceId: string;
|
|
25
|
+
project: string | null;
|
|
26
|
+
scopeRevision: string;
|
|
27
|
+
availability: import("../sandbox/permission-availability.js").PermissionAvailability;
|
|
28
|
+
fullAccessCeiling: boolean;
|
|
29
|
+
broadProjectReach: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
get(orgId: string, id: string, accountId: string): Promise<{
|
|
32
|
+
profile: import("@capybara-hq/plugin-sdk").PermissionProfile;
|
|
33
|
+
revision: number;
|
|
34
|
+
rootConversationId: string;
|
|
35
|
+
deviceId: string | null;
|
|
36
|
+
consentScope: {
|
|
37
|
+
deviceId: string;
|
|
38
|
+
scopeRevision: string;
|
|
39
|
+
} | null;
|
|
40
|
+
scopeRevision: string | null;
|
|
41
|
+
availability: import("../sandbox/permission-availability.js").PermissionAvailability;
|
|
42
|
+
fullAccessCeiling: boolean;
|
|
43
|
+
broadProjectReach: boolean;
|
|
44
|
+
startingWorkNotice: string;
|
|
45
|
+
}>;
|
|
46
|
+
/** Reserve the root ID and authority before resolving its project or inserting first-send state. */
|
|
47
|
+
lockInitial(orgId: string, id: string, deviceId: string | null): Promise<void>;
|
|
48
|
+
initialize(orgId: string, id: string, accountId: string, deviceId: string | null, projectPath: string | null, project: string | null, selection: PermissionSelection): Promise<ConversationEvent[]>;
|
|
49
|
+
private consent;
|
|
50
|
+
set(orgId: string, id: string, accountId: string, body: PermissionSelection & {
|
|
51
|
+
expectedRevision: number;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
revision: number;
|
|
54
|
+
}>;
|
|
55
|
+
private setLocked;
|
|
56
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
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 { DeviceAccess } from "../devices/access.js";
|
|
12
|
+
import { ApiError } from "../errors.js";
|
|
13
|
+
import { audit } from "../identity/audit.js";
|
|
14
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
|
+
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
16
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
17
|
+
import { PermissionAuthorityEpochStore } from "../sandbox/permission-authority-epochs.js";
|
|
18
|
+
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
19
|
+
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
20
|
+
import { PermissionTransitions } from "../sandbox/permission-transitions.js";
|
|
21
|
+
import { EventLog } from "./event-log.js";
|
|
22
|
+
import { PermissionProfileStore } from "./permission-profile-store.js";
|
|
23
|
+
let PermissionProfilesService = class PermissionProfilesService {
|
|
24
|
+
transitions;
|
|
25
|
+
facts;
|
|
26
|
+
store;
|
|
27
|
+
db;
|
|
28
|
+
txHost;
|
|
29
|
+
devices;
|
|
30
|
+
locks;
|
|
31
|
+
epochs;
|
|
32
|
+
events;
|
|
33
|
+
constructor(transitions, facts, store, db, txHost, devices, locks, epochs, events) {
|
|
34
|
+
this.transitions = transitions;
|
|
35
|
+
this.facts = facts;
|
|
36
|
+
this.store = store;
|
|
37
|
+
this.db = db;
|
|
38
|
+
this.txHost = txHost;
|
|
39
|
+
this.devices = devices;
|
|
40
|
+
this.locks = locks;
|
|
41
|
+
this.epochs = epochs;
|
|
42
|
+
this.events = events;
|
|
43
|
+
}
|
|
44
|
+
preview(orgId, accountId, deviceId, project) {
|
|
45
|
+
return this.facts.preview(orgId, accountId, deviceId, project);
|
|
46
|
+
}
|
|
47
|
+
async get(orgId, id, accountId) {
|
|
48
|
+
return this.facts.view(orgId, accountId, await this.store.readOwnedRoot(orgId, id, accountId));
|
|
49
|
+
}
|
|
50
|
+
/** Reserve the root ID and authority before resolving its project or inserting first-send state. */
|
|
51
|
+
async lockInitial(orgId, id, deviceId) {
|
|
52
|
+
const subject = { orgId, rootConversationId: id, ...(deviceId ? { deviceId } : {}) };
|
|
53
|
+
await this.locks.acquire(subject, { kind: "write", level: "root" });
|
|
54
|
+
}
|
|
55
|
+
async initialize(orgId, id, accountId, deviceId, projectPath, project, selection) {
|
|
56
|
+
const subject = { orgId, rootConversationId: id, ...(deviceId ? { deviceId } : {}) };
|
|
57
|
+
await this.locks.acquire(subject, { kind: "write", level: "root" });
|
|
58
|
+
await this.epochs.readLocked(subject);
|
|
59
|
+
const consent = await this.consent(orgId, accountId, deviceId, projectPath, project, selection);
|
|
60
|
+
await this.db
|
|
61
|
+
.updateTable("conversations")
|
|
62
|
+
.set({
|
|
63
|
+
permission_profile: selection.profile,
|
|
64
|
+
permission_consent: consent ? JSON.stringify(consent) : null,
|
|
65
|
+
})
|
|
66
|
+
.where("id", "=", id)
|
|
67
|
+
.where("org_id", "=", orgId)
|
|
68
|
+
.execute();
|
|
69
|
+
const detail = {
|
|
70
|
+
oldProfile: "approve-for-me",
|
|
71
|
+
newProfile: selection.profile,
|
|
72
|
+
actorAccountId: accountId,
|
|
73
|
+
deviceId,
|
|
74
|
+
scopeRevision: consent?.scopeRevision ?? null,
|
|
75
|
+
revision: 0,
|
|
76
|
+
};
|
|
77
|
+
await audit(this.db.db, {
|
|
78
|
+
orgId,
|
|
79
|
+
actorAccountId: accountId,
|
|
80
|
+
action: "conversation.permission_profile_changed",
|
|
81
|
+
target: id,
|
|
82
|
+
detail,
|
|
83
|
+
});
|
|
84
|
+
return this.events.appendIn(id, [{ type: "permission_profile_changed", payload: detail }]);
|
|
85
|
+
}
|
|
86
|
+
async consent(orgId, accountId, deviceId, projectPath, project, selection) {
|
|
87
|
+
if (deviceId)
|
|
88
|
+
await this.devices.usable(orgId, accountId, deviceId);
|
|
89
|
+
if (selection.profile !== "full-access")
|
|
90
|
+
return null;
|
|
91
|
+
if (!deviceId || !selection.consentScopeRevision)
|
|
92
|
+
throw new ApiError("conflict", "Full access requires an explicitly selected device and displayed scope consent");
|
|
93
|
+
const preview = await this.facts.scope(orgId, deviceId, projectPath, project);
|
|
94
|
+
if (!preview.fullAccessCeiling ||
|
|
95
|
+
preview.availability.state === "unsupported" ||
|
|
96
|
+
preview.scopeRevision !== selection.consentScopeRevision)
|
|
97
|
+
throw new ApiError("conflict", "Device authority changed or Full access is unavailable; refresh the permission preview");
|
|
98
|
+
return { deviceId, scopeRevision: preview.scopeRevision };
|
|
99
|
+
}
|
|
100
|
+
async set(orgId, id, accountId, body) {
|
|
101
|
+
const row = await this.store.own(orgId, id, accountId);
|
|
102
|
+
const subject = {
|
|
103
|
+
orgId,
|
|
104
|
+
rootConversationId: id,
|
|
105
|
+
...(row.device_id ? { deviceId: row.device_id } : {}),
|
|
106
|
+
};
|
|
107
|
+
return withTransactionFencePrelude(() => this.locks.acquire(subject, { kind: "write", level: "root" }), () => this.setLocked(orgId, id, accountId, body, {
|
|
108
|
+
deviceId: row.device_id,
|
|
109
|
+
projectName: row.project_name,
|
|
110
|
+
projectPath: row.project_path,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
async setLocked(orgId, id, accountId, body, binding) {
|
|
114
|
+
let row = await this.store.own(orgId, id, accountId);
|
|
115
|
+
if (row.parent_conversation_id || row.kind !== "chat" || row.scheduled_task_id)
|
|
116
|
+
throw new ApiError("forbidden", "Only interactive root conversations have editable permissions");
|
|
117
|
+
const subject = {
|
|
118
|
+
orgId,
|
|
119
|
+
rootConversationId: id,
|
|
120
|
+
...(binding.deviceId ? { deviceId: binding.deviceId } : {}),
|
|
121
|
+
};
|
|
122
|
+
row = await this.store.own(orgId, id, accountId);
|
|
123
|
+
// A binding writer may have won before root-write. Retry from a fresh subject instead of
|
|
124
|
+
// validating another device under the old locks or acquiring a device lock after the root.
|
|
125
|
+
if (row.device_id !== binding.deviceId ||
|
|
126
|
+
row.project_name !== binding.projectName ||
|
|
127
|
+
row.project_path !== binding.projectPath)
|
|
128
|
+
throw new ApiError("conflict", "The conversation binding changed; refresh and retry");
|
|
129
|
+
if (row.permission_revision !== body.expectedRevision)
|
|
130
|
+
throw new ApiError("conflict", "Permissions changed; refresh and retry");
|
|
131
|
+
const consent = await this.consent(orgId, accountId, row.device_id, row.project_path, row.project_name, body);
|
|
132
|
+
const epochs = await this.epochs.readLocked(subject);
|
|
133
|
+
await this.epochs.bumpLocked("root", id, epochs.root ?? 0);
|
|
134
|
+
const revision = row.permission_revision + 1;
|
|
135
|
+
await this.db
|
|
136
|
+
.updateTable("conversations")
|
|
137
|
+
.set({
|
|
138
|
+
permission_profile: body.profile,
|
|
139
|
+
permission_revision: revision,
|
|
140
|
+
permission_consent: consent ? JSON.stringify(consent) : null,
|
|
141
|
+
})
|
|
142
|
+
.where("id", "=", id)
|
|
143
|
+
.execute();
|
|
144
|
+
await this.transitions.recordLocked({
|
|
145
|
+
orgId,
|
|
146
|
+
rootConversationId: id,
|
|
147
|
+
oldProfile: row.permission_profile,
|
|
148
|
+
newProfile: body.profile,
|
|
149
|
+
actorAccountId: accountId,
|
|
150
|
+
deviceId: row.device_id,
|
|
151
|
+
scopeRevision: consent?.scopeRevision ?? null,
|
|
152
|
+
revision,
|
|
153
|
+
reason: "user",
|
|
154
|
+
}, { subject, level: "root" });
|
|
155
|
+
return { revision };
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
__decorate([
|
|
159
|
+
Transactional({ propagation: "mandatory" })
|
|
160
|
+
], PermissionProfilesService.prototype, "lockInitial", null);
|
|
161
|
+
__decorate([
|
|
162
|
+
Transactional({ propagation: "mandatory" })
|
|
163
|
+
], PermissionProfilesService.prototype, "initialize", null);
|
|
164
|
+
__decorate([
|
|
165
|
+
Transactional()
|
|
166
|
+
], PermissionProfilesService.prototype, "setLocked", null);
|
|
167
|
+
PermissionProfilesService = __decorate([
|
|
168
|
+
Injectable(),
|
|
169
|
+
__param(0, Inject(PermissionTransitions)),
|
|
170
|
+
__param(1, Inject(PermissionFacts)),
|
|
171
|
+
__param(2, Inject(PermissionProfileStore)),
|
|
172
|
+
__param(3, Inject(KernelDb)),
|
|
173
|
+
__param(4, Inject(TransactionHost)),
|
|
174
|
+
__param(5, Inject(DeviceAccess)),
|
|
175
|
+
__param(6, Inject(PermissionAuthorityLock)),
|
|
176
|
+
__param(7, Inject(PermissionAuthorityEpochStore)),
|
|
177
|
+
__param(8, Inject(EventLog))
|
|
178
|
+
], PermissionProfilesService);
|
|
179
|
+
export { PermissionProfilesService };
|