@capybara-hq/kernel 0.1.0-rc.41 → 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 +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 +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
|
@@ -17,13 +17,15 @@ import { DeviceProjectsService } from "../devices/device-projects.service.js";
|
|
|
17
17
|
import { ApiError } from "../errors.js";
|
|
18
18
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
19
19
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
20
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
20
|
+
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
21
21
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
22
22
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
23
23
|
import { ProviderRegistry } from "../runtime/providers.js";
|
|
24
24
|
import { RunControl as RunControlService } from "../runtime/run-control.js";
|
|
25
25
|
import { RunDeletion } from "../runtime/run-deletion.js";
|
|
26
26
|
import { rootConversationOf } from "../runtime/subagents/child.js";
|
|
27
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
28
|
+
import { permissionScopeHash } from "../sandbox/permission-facts.js";
|
|
27
29
|
import { SkillInvoker } from "../skills/invoke.js";
|
|
28
30
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
29
31
|
import { ConnectorContent } from "../tools/connector-content.js";
|
|
@@ -34,6 +36,7 @@ import { AttachmentsService } from "./attachments.service.js";
|
|
|
34
36
|
import { EventLog } from "./event-log.js";
|
|
35
37
|
import { userMessageIdemKey } from "./idem-keys.js";
|
|
36
38
|
import { readMessageContext, } from "./message-context.js";
|
|
39
|
+
import { PermissionProfilesService } from "./permission-profiles.service.js";
|
|
37
40
|
import { NO_SELECTION, planSelection, readSelection, sameSelection, } from "./selection.js";
|
|
38
41
|
import { conversationTree } from "./tree.js";
|
|
39
42
|
/**
|
|
@@ -149,6 +152,7 @@ const toUsage = (r) => ({
|
|
|
149
152
|
* 不可用时会话也按不存在处理(`conversation.not_found`)。
|
|
150
153
|
*/
|
|
151
154
|
let ConversationsService = class ConversationsService {
|
|
155
|
+
permissions;
|
|
152
156
|
db;
|
|
153
157
|
eventLog;
|
|
154
158
|
agents;
|
|
@@ -165,7 +169,8 @@ let ConversationsService = class ConversationsService {
|
|
|
165
169
|
approvals;
|
|
166
170
|
events;
|
|
167
171
|
txHost;
|
|
168
|
-
|
|
172
|
+
ceilings;
|
|
173
|
+
constructor(permissions, db, eventLog, agents, access,
|
|
169
174
|
/** Starts and stops the conversation's runs. */
|
|
170
175
|
runs,
|
|
171
176
|
/** Resolves a switched-to model and its declared parameters (UI refresh B). */
|
|
@@ -185,7 +190,8 @@ let ConversationsService = class ConversationsService {
|
|
|
185
190
|
/** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
|
|
186
191
|
questions,
|
|
187
192
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
188
|
-
approvals, events, txHost) {
|
|
193
|
+
approvals, events, txHost, ceilings) {
|
|
194
|
+
this.permissions = permissions;
|
|
189
195
|
this.db = db;
|
|
190
196
|
this.eventLog = eventLog;
|
|
191
197
|
this.agents = agents;
|
|
@@ -202,6 +208,7 @@ let ConversationsService = class ConversationsService {
|
|
|
202
208
|
this.approvals = approvals;
|
|
203
209
|
this.events = events;
|
|
204
210
|
this.txHost = txHost;
|
|
211
|
+
this.ceilings = ceilings;
|
|
205
212
|
}
|
|
206
213
|
/**
|
|
207
214
|
* Creates an empty conversation bound to its device (`pick`, see
|
|
@@ -245,8 +252,15 @@ let ConversationsService = class ConversationsService {
|
|
|
245
252
|
* retry answers with the conversation the first send created, its binding unchanged.
|
|
246
253
|
*/
|
|
247
254
|
async createWithMessage(orgId, accountId, agentId, input, pick = {}, internal) {
|
|
255
|
+
if (internal.initialPermission?.profile === "full-access" && !pick.deviceId)
|
|
256
|
+
throw new ApiError("conflict", "Full access requires an explicit device selection");
|
|
257
|
+
const requestHash = internal.initialPermission
|
|
258
|
+
? permissionScopeHash({ agentId, input, pick, permission: internal.initialPermission })
|
|
259
|
+
: undefined;
|
|
260
|
+
if (requestHash)
|
|
261
|
+
internal = { ...internal, createRequestHash: requestHash };
|
|
248
262
|
const agent = await this.agents.get(orgId, agentId, accountId);
|
|
249
|
-
const prior = await this.findCreated(orgId, accountId, agentId, input.clientMessageId);
|
|
263
|
+
const prior = await this.findCreated(orgId, accountId, agentId, input.clientMessageId, requestHash);
|
|
250
264
|
if (prior)
|
|
251
265
|
return prior;
|
|
252
266
|
const deviceId = await this.devices.forNew(orgId, accountId, pick);
|
|
@@ -263,14 +277,14 @@ let ConversationsService = class ConversationsService {
|
|
|
263
277
|
// binding: a refusal here (the project just went away) answers with what the first created
|
|
264
278
|
if (!(e instanceof ApiError))
|
|
265
279
|
throw e;
|
|
266
|
-
const raced = await this.findCreated(orgId, accountId, agentId, input.clientMessageId);
|
|
280
|
+
const raced = await this.findCreated(orgId, accountId, agentId, input.clientMessageId, requestHash);
|
|
267
281
|
if (!raced)
|
|
268
282
|
throw e;
|
|
269
283
|
return raced;
|
|
270
284
|
}
|
|
271
285
|
const written = all?.at(-1);
|
|
272
286
|
if (!all || !written) {
|
|
273
|
-
const raced = await this.findCreated(orgId, accountId, agentId, input.clientMessageId);
|
|
287
|
+
const raced = await this.findCreated(orgId, accountId, agentId, input.clientMessageId, requestHash);
|
|
274
288
|
if (!raced)
|
|
275
289
|
throw new ApiError("conflict", "The conversation is being created; retry");
|
|
276
290
|
return raced;
|
|
@@ -283,6 +297,8 @@ let ConversationsService = class ConversationsService {
|
|
|
283
297
|
// its own transaction: the caller notifies and publishes after the commit
|
|
284
298
|
async createIn(conv, input, next, extra, invoked, internal) {
|
|
285
299
|
const { id, orgId, accountId } = conv;
|
|
300
|
+
if (internal.initialPermission)
|
|
301
|
+
await this.permissions.lockInitial(orgId, id, conv.deviceId);
|
|
286
302
|
const project = await this.bindingFor(orgId, accountId, conv.deviceId, conv.project);
|
|
287
303
|
const row = await this.db
|
|
288
304
|
.insertInto("conversations")
|
|
@@ -295,6 +311,7 @@ let ConversationsService = class ConversationsService {
|
|
|
295
311
|
project_name: project?.name ?? null,
|
|
296
312
|
project_path: project?.path ?? null,
|
|
297
313
|
create_request_id: input.clientMessageId,
|
|
314
|
+
create_request_hash: internal.createRequestHash ?? null,
|
|
298
315
|
scheduled_task_id: internal.schedule?.taskId ?? null,
|
|
299
316
|
source: internal.source,
|
|
300
317
|
})
|
|
@@ -307,9 +324,13 @@ let ConversationsService = class ConversationsService {
|
|
|
307
324
|
// a concurrent retry committed first: answer with its conversation below
|
|
308
325
|
if (!row)
|
|
309
326
|
return undefined;
|
|
327
|
+
const initialEvents = internal.initialPermission
|
|
328
|
+
? await this.permissions.initialize(orgId, id, accountId, conv.deviceId, project?.path ?? null, project?.name ?? null, internal.initialPermission)
|
|
329
|
+
: [];
|
|
310
330
|
const blocks = await this.bindIn(orgId, id, accountId, input.files ?? []);
|
|
311
331
|
// a new conversation has no run yet, so nothing to skip
|
|
312
|
-
|
|
332
|
+
const written = await this.writeMessage(orgId, id, accountId, input, next, extra, blocks, invoked, internal);
|
|
333
|
+
return [...initialEvents, ...written.events];
|
|
313
334
|
}
|
|
314
335
|
/**
|
|
315
336
|
* The project a new conversation binds to (project root design §4.3): `name` resolved against
|
|
@@ -332,18 +353,20 @@ let ConversationsService = class ConversationsService {
|
|
|
332
353
|
* for another agent's conversation → `conflict` (the caller only checked access to `agentId`, so
|
|
333
354
|
* the other conversation is never returned).
|
|
334
355
|
*/
|
|
335
|
-
async findCreated(orgId, accountId, agentId, clientMessageId) {
|
|
356
|
+
async findCreated(orgId, accountId, agentId, clientMessageId, requestHash) {
|
|
336
357
|
const row = await this.db
|
|
337
358
|
.selectFrom("conversations")
|
|
338
359
|
.select(viewColumns())
|
|
339
360
|
.where("org_id", "=", orgId)
|
|
340
361
|
.where("account_id", "=", accountId)
|
|
362
|
+
.select("create_request_hash")
|
|
341
363
|
.where("create_request_id", "=", clientMessageId)
|
|
342
364
|
.where("kind", "=", "chat")
|
|
343
365
|
.executeTakeFirst();
|
|
344
366
|
if (!row)
|
|
345
367
|
return null;
|
|
346
|
-
if (row.agent_id !== agentId
|
|
368
|
+
if (row.agent_id !== agentId ||
|
|
369
|
+
(requestHash !== undefined && row.create_request_hash !== requestHash)) {
|
|
347
370
|
throw new ApiError("conflict", "This clientMessageId was already used for another conversation");
|
|
348
371
|
}
|
|
349
372
|
const event = await this.eventLog.findByIdem(row.id, userMessageIdemKey(clientMessageId));
|
|
@@ -412,13 +435,58 @@ let ConversationsService = class ConversationsService {
|
|
|
412
435
|
async remove(orgId, conversationId, accountId) {
|
|
413
436
|
await this.writable(orgId, conversationId, accountId);
|
|
414
437
|
// Close entrances before the direct stop. The outbox owes the same claim-revoking cleanup.
|
|
415
|
-
|
|
438
|
+
// The root authority lock is the transaction's ordered prelude: inside a run's fence (a
|
|
439
|
+
// Platform call) it follows the org row and precedes the conversation rows
|
|
440
|
+
const subject = await this.deletionSubject(orgId, conversationId);
|
|
441
|
+
await withTransactionFencePrelude(() => this.ceilings.lock(subject, "root"), () => this.markDeleted(orgId, conversationId, accountId, subject));
|
|
416
442
|
await this.deletion.stopTree(conversationId, accountId);
|
|
417
443
|
await this.eventLog.publishChanged(conversationId, "deleted");
|
|
418
444
|
}
|
|
445
|
+
/** The authority subject a deletion locks: the tree's root and its device, read without locks. */
|
|
446
|
+
async deletionSubject(orgId, conversationId) {
|
|
447
|
+
const binding = await this.db
|
|
448
|
+
.selectFrom("conversations")
|
|
449
|
+
.select(["device_id", "parent_conversation_id"])
|
|
450
|
+
.where("id", "=", conversationId)
|
|
451
|
+
.where("org_id", "=", orgId)
|
|
452
|
+
.executeTakeFirst();
|
|
453
|
+
if (!binding)
|
|
454
|
+
throw notFound();
|
|
455
|
+
// Root deletion closes the whole tree; a child is fenced through its actual root's authority.
|
|
456
|
+
let rootId = conversationId, parent = binding.parent_conversation_id;
|
|
457
|
+
for (let depth = 0; parent && depth < 16; depth++) {
|
|
458
|
+
const ancestor = await this.db
|
|
459
|
+
.selectFrom("conversations")
|
|
460
|
+
.select(["id", "parent_conversation_id"])
|
|
461
|
+
.where("id", "=", parent)
|
|
462
|
+
.where("org_id", "=", orgId)
|
|
463
|
+
.executeTakeFirstOrThrow();
|
|
464
|
+
rootId = ancestor.id;
|
|
465
|
+
parent = ancestor.parent_conversation_id;
|
|
466
|
+
}
|
|
467
|
+
if (parent)
|
|
468
|
+
throw notFound();
|
|
469
|
+
const root = await this.db
|
|
470
|
+
.selectFrom("conversations")
|
|
471
|
+
.select("device_id")
|
|
472
|
+
.where("id", "=", rootId)
|
|
473
|
+
.executeTakeFirstOrThrow();
|
|
474
|
+
return {
|
|
475
|
+
orgId,
|
|
476
|
+
rootConversationId: rootId,
|
|
477
|
+
...(root.device_id ? { deviceId: root.device_id } : {}),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
419
480
|
// the publish happens after the commit, in the caller; the tree stop after it is owed here
|
|
420
481
|
// (transactional outbox spec §6), so a process that dies before it still stops the tree
|
|
421
|
-
async markDeleted(orgId, conversationId, accountId) {
|
|
482
|
+
async markDeleted(orgId, conversationId, accountId, locked) {
|
|
483
|
+
// the prelude locked `locked`; a root or device that changed since is not covered by it
|
|
484
|
+
const subject = await this.deletionSubject(orgId, conversationId);
|
|
485
|
+
if (subject.rootConversationId !== locked.rootConversationId ||
|
|
486
|
+
subject.deviceId !== locked.deviceId)
|
|
487
|
+
throw new ApiError("conflict", "The conversation's device changed; retry the deletion");
|
|
488
|
+
await this.ceilings.lock(subject, "root");
|
|
489
|
+
await this.ceilings.publishLocked(subject, "root", (_scope, intent) => conversationId === subject.rootConversationId || intent.conversation_id === conversationId);
|
|
422
490
|
const row = await this.db
|
|
423
491
|
.selectFrom("conversations")
|
|
424
492
|
.select("id")
|
|
@@ -1231,21 +1299,23 @@ __decorate([
|
|
|
1231
1299
|
], ConversationsService.prototype, "holdTree", null);
|
|
1232
1300
|
ConversationsService = __decorate([
|
|
1233
1301
|
Injectable(),
|
|
1234
|
-
__param(0, Inject(
|
|
1235
|
-
__param(1, Inject(
|
|
1236
|
-
__param(2, Inject(
|
|
1237
|
-
__param(3, Inject(
|
|
1238
|
-
__param(4, Inject(
|
|
1239
|
-
__param(5, Inject(
|
|
1240
|
-
__param(6, Inject(
|
|
1241
|
-
__param(7, Inject(
|
|
1242
|
-
__param(8, Inject(
|
|
1243
|
-
__param(9, Inject(
|
|
1244
|
-
__param(10, Inject(
|
|
1245
|
-
__param(11, Inject(
|
|
1246
|
-
__param(12, Inject(
|
|
1247
|
-
__param(13, Inject(
|
|
1248
|
-
__param(14, Inject(
|
|
1249
|
-
__param(15, Inject(
|
|
1302
|
+
__param(0, Inject(PermissionProfilesService)),
|
|
1303
|
+
__param(1, Inject(KernelDb)),
|
|
1304
|
+
__param(2, Inject(EventLog)),
|
|
1305
|
+
__param(3, Inject(AgentLookup)),
|
|
1306
|
+
__param(4, Inject(ConversationAccess)),
|
|
1307
|
+
__param(5, Inject(RunControlService)),
|
|
1308
|
+
__param(6, Inject(ProviderRegistry)),
|
|
1309
|
+
__param(7, Inject(ConnectorContent)),
|
|
1310
|
+
__param(8, Inject(AttachmentsService)),
|
|
1311
|
+
__param(9, Inject(SkillInvoker)),
|
|
1312
|
+
__param(10, Inject(RunDeletion)),
|
|
1313
|
+
__param(11, Inject(ConversationDevices)),
|
|
1314
|
+
__param(12, Inject(DeviceProjectsService)),
|
|
1315
|
+
__param(13, Inject(QuestionsService)),
|
|
1316
|
+
__param(14, Inject(ApprovalsService)),
|
|
1317
|
+
__param(15, Inject(KernelEvents)),
|
|
1318
|
+
__param(16, Inject(TransactionHost)),
|
|
1319
|
+
__param(17, Inject(PermissionCeilingWrites))
|
|
1250
1320
|
], ConversationsService);
|
|
1251
1321
|
export { ConversationsService };
|
|
@@ -98,7 +98,7 @@ export declare class EventLog {
|
|
|
98
98
|
private readonly log;
|
|
99
99
|
private readonly outbox;
|
|
100
100
|
readonly txHost: TransactionHost;
|
|
101
|
-
constructor(db: KernelDb, bus: EventBus, log: Pick<KernelLogger, "warn">, outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
|
|
101
|
+
constructor(db: KernelDb, bus: EventBus | undefined, log: Pick<KernelLogger, "warn">, outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
|
|
102
102
|
/**
|
|
103
103
|
* 追加事件,返回与输入一一对应的事件(幂等命中的为已有事件)。
|
|
104
104
|
* 自开一个独立事务(`requires_new`,与调用方的事务无关),提交后发布 `conv.<id>`。
|
|
@@ -7,7 +7,7 @@ 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 { Inject, Injectable, Module } from "@nestjs/common";
|
|
10
|
+
import { Inject, Injectable, Module, Optional } from "@nestjs/common";
|
|
11
11
|
import { sql } from "kysely";
|
|
12
12
|
import { oweDelivery } from "../channels/deliver-job.js";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
@@ -86,7 +86,10 @@ let EventLog = class EventLog {
|
|
|
86
86
|
log;
|
|
87
87
|
outbox;
|
|
88
88
|
txHost;
|
|
89
|
-
constructor(db,
|
|
89
|
+
constructor(db,
|
|
90
|
+
// Optional: the Redis-free CLI (openKernelCli redis:false) has no bus; publishes are hints whose
|
|
91
|
+
// loss is harmless (readers catch up by seq), so there they are skipped.
|
|
92
|
+
bus, log, outbox, txHost) {
|
|
90
93
|
this.db = db;
|
|
91
94
|
this.bus = bus;
|
|
92
95
|
this.log = log;
|
|
@@ -132,6 +135,8 @@ let EventLog = class EventLog {
|
|
|
132
135
|
}
|
|
133
136
|
/** 发布「日志已推进到 toSeq」;发布失败只记日志(事件已提交,订阅方可按 seq 补读)。 */
|
|
134
137
|
async notify(conversationId, toSeq) {
|
|
138
|
+
if (!this.bus)
|
|
139
|
+
return;
|
|
135
140
|
const msg = { kind: "events", toSeq };
|
|
136
141
|
try {
|
|
137
142
|
await this.bus.publish(conversationTopic(conversationId), msg);
|
|
@@ -145,6 +150,8 @@ let EventLog = class EventLog {
|
|
|
145
150
|
* A failed publish only logs: the state is in PG and the next read sees it.
|
|
146
151
|
*/
|
|
147
152
|
async publishChanged(conversationId, what) {
|
|
153
|
+
if (!this.bus)
|
|
154
|
+
return;
|
|
148
155
|
const msg = { kind: "changed", what };
|
|
149
156
|
try {
|
|
150
157
|
await this.bus.publish(conversationTopic(conversationId), msg);
|
|
@@ -427,6 +434,7 @@ __decorate([
|
|
|
427
434
|
EventLog = __decorate([
|
|
428
435
|
Injectable(),
|
|
429
436
|
__param(0, Inject(KernelDb)),
|
|
437
|
+
__param(1, Optional()),
|
|
430
438
|
__param(1, Inject(KERNEL_BUS)),
|
|
431
439
|
__param(2, Inject(KERNEL_LOGGER)),
|
|
432
440
|
__param(3, Inject(OutboxService)),
|