@capybara-hq/kernel 0.1.0-rc.105 → 0.1.0-rc.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/agents/agents.schemas.d.ts +9 -9
- package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
- package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
- package/dist/automations/automations.module.d.ts +16 -0
- package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
- package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
- package/dist/automations/automations.schemas.js +253 -0
- package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
- package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
- package/dist/{schedules → automations}/calendar.d.ts +8 -8
- package/dist/{schedules → automations}/calendar.js +2 -2
- package/dist/automations/effective-settings.d.ts +28 -0
- package/dist/automations/effective-settings.js +25 -0
- package/dist/automations/errors.d.ts +19 -0
- package/dist/automations/errors.js +19 -0
- package/dist/automations/events/coalesce.d.ts +28 -0
- package/dist/automations/events/coalesce.js +131 -0
- package/dist/automations/events/deadline.d.ts +10 -0
- package/dist/automations/events/deadline.js +24 -0
- package/dist/automations/events/dispatcher.d.ts +74 -0
- package/dist/automations/events/dispatcher.js +353 -0
- package/dist/automations/events/events.module.d.ts +7 -0
- package/dist/automations/events/events.module.js +26 -0
- package/dist/automations/events/guards.d.ts +32 -0
- package/dist/automations/events/guards.js +87 -0
- package/dist/automations/events/sweep.job.d.ts +49 -0
- package/dist/automations/events/sweep.job.js +202 -0
- package/dist/automations/events/token.d.ts +5 -0
- package/dist/automations/events/token.js +5 -0
- package/dist/automations/events/trigger-events.service.d.ts +47 -0
- package/dist/automations/events/trigger-events.service.js +254 -0
- package/dist/{schedules → automations}/fire.d.ts +57 -17
- package/dist/{schedules → automations}/fire.js +311 -79
- package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
- package/dist/{schedules → automations}/grant-rules.js +5 -5
- package/dist/automations/job-ids.d.ts +113 -0
- package/dist/automations/job-ids.js +117 -0
- package/dist/{schedules → automations}/pause.d.ts +3 -3
- package/dist/{schedules → automations}/pause.js +3 -3
- package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
- package/dist/{schedules → automations}/run-tracker.js +68 -56
- package/dist/{schedules → automations}/scan.job.d.ts +12 -8
- package/dist/{schedules → automations}/scan.job.js +39 -23
- package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
- package/dist/{schedules → automations}/schedule-math.js +17 -7
- package/dist/{schedules → automations}/store.d.ts +57 -27
- package/dist/{schedules → automations}/store.js +102 -52
- package/dist/automations/store.module.d.ts +6 -0
- package/dist/{schedules → automations}/store.module.js +9 -9
- package/dist/automations/types.d.ts +178 -0
- package/dist/{schedules → automations}/unattended.d.ts +22 -11
- package/dist/{schedules → automations}/unattended.js +53 -30
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +7 -6
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +8 -8
- package/dist/channels/outbound.js +32 -30
- package/dist/channels/threads.d.ts +1 -1
- package/dist/channels/threads.js +1 -1
- package/dist/config/schema.d.ts +8 -1
- package/dist/config/schema.js +56 -6
- package/dist/conversations/approval-profile.d.ts +2 -2
- package/dist/conversations/approval-profile.js +3 -3
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +6 -19
- package/dist/conversations/attachments.controller.js +8 -59
- package/dist/conversations/attachments.service.d.ts +30 -74
- package/dist/conversations/attachments.service.js +51 -193
- package/dist/conversations/conversations.controller.d.ts +7 -1
- package/dist/conversations/conversations.controller.js +26 -10
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +112 -35
- package/dist/conversations/conversations.service.js +160 -43
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +95 -27
- package/dist/conversations/events.js +108 -10
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- package/dist/conversations/message-context.d.ts +2 -2
- package/dist/conversations/message-context.js +1 -1
- package/dist/conversations/permission-profile-store.d.ts +2 -1
- package/dist/conversations/permission-profiles.controller.d.ts +3 -0
- package/dist/conversations/permission-profiles.service.js +1 -1
- package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
- package/dist/conversations/prompt-suggestion-request.js +4 -2
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- package/dist/conversations/queue.d.ts +7 -4
- package/dist/conversations/queue.js +6 -2
- package/dist/conversations/queue.service.d.ts +5 -5
- package/dist/conversations/queue.service.js +27 -16
- package/dist/ctx/create-ctx.d.ts +23 -2
- package/dist/ctx/create-ctx.js +78 -3
- package/dist/db/kernel-schema.d.ts +184 -27
- package/dist/devices/device-project-files.service.d.ts +88 -0
- package/dist/devices/device-project-files.service.js +249 -0
- package/dist/devices/device-projects.service.d.ts +40 -0
- package/dist/devices/device-projects.service.js +16 -13
- package/dist/devices/devices.controller.d.ts +9 -3
- package/dist/devices/devices.controller.js +27 -5
- package/dist/devices/devices.module.js +9 -1
- package/dist/devices/devices.schemas.js +6 -1
- package/dist/devices/dto.d.ts +15 -0
- package/dist/devices/dto.js +11 -0
- package/dist/devices/project-paths.d.ts +29 -0
- package/dist/devices/project-paths.js +66 -0
- package/dist/devices/project-rules.d.ts +5 -1
- package/dist/devices/project-rules.js +5 -1
- package/dist/errors.d.ts +53 -13
- package/dist/errors.js +53 -13
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.d.ts +10 -1
- package/dist/evals/reconstruct.js +20 -1
- package/dist/evals/recorded-tools.d.ts +0 -2
- package/dist/evals/recorded-tools.js +1 -16
- package/dist/evals/snapshot.d.ts +26 -3
- package/dist/evals/snapshot.js +110 -57
- package/dist/evals/worker.d.ts +4 -3
- package/dist/evals/worker.js +8 -4
- package/dist/extensions/host.d.ts +9 -2
- package/dist/extensions/host.js +12 -0
- package/dist/extensions/instance.d.ts +3 -1
- package/dist/extensions/instance.js +4 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/permission-set.d.ts +17 -1
- package/dist/extensions/permission-set.js +13 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/files/blob-objects.d.ts +124 -0
- package/dist/files/blob-objects.js +341 -0
- package/dist/files/blob-sweep.job.d.ts +122 -0
- package/dist/files/blob-sweep.job.js +389 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +1 -1
- package/dist/files/files.module.js +3 -2
- package/dist/files/hash-job.d.ts +127 -0
- package/dist/files/hash-job.js +447 -0
- package/dist/files/library-backfill.d.ts +63 -0
- package/dist/files/library-backfill.js +143 -0
- package/dist/files/library-files.service.d.ts +255 -0
- package/dist/files/library-files.service.js +883 -0
- package/dist/files/library-jobs.module.d.ts +8 -0
- package/dist/files/library-jobs.module.js +27 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +20 -0
- package/dist/files/previewers.controller.js +47 -0
- package/dist/files/previewers.d.ts +25 -11
- package/dist/files/previewers.js +43 -27
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/git/gateway.js +2 -2
- package/dist/html/html-document.controller.d.ts +8 -1
- package/dist/html/html-document.controller.js +19 -1
- package/dist/html/html-document.service.d.ts +19 -4
- package/dist/html/html-document.service.js +43 -22
- package/dist/html/html-token.d.ts +10 -1
- package/dist/html/html-token.js +14 -0
- package/dist/html/html.module.js +8 -1
- package/dist/http/api.module.js +10 -5
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- package/dist/inbox/inbox.module.js +2 -2
- package/dist/inbox/inbox.service.d.ts +8 -8
- package/dist/inbox/inbox.service.js +7 -7
- package/dist/infra/config/kernel-config.service.js +10 -5
- package/dist/infra/outbox/registry.d.ts +111 -2
- package/dist/infra/outbox/registry.js +104 -9
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.js +6 -0
- package/dist/models/purposes.js +1 -1
- package/dist/orgs/offboarding.js +1 -1
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +3 -3
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.service.d.ts +75 -13
- package/dist/orgs/settings.service.js +104 -26
- package/dist/platform/exclusions.js +45 -8
- package/dist/platform/file-ref.d.ts +18 -3
- package/dist/platform/file-ref.js +22 -11
- package/dist/platform/operation.js +6 -2
- package/dist/platform/ops/admin.ops.js +5 -2
- package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
- package/dist/platform/ops/automations.ops.js +560 -0
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +77 -3
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/platform/ops/platform.ops.js +4 -4
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +3 -2
- package/dist/platform/platform-ops.module.js +10 -5
- package/dist/platform/route-schemas.js +6 -3
- package/dist/push/jobs.d.ts +3 -3
- package/dist/push/jobs.js +2 -2
- package/dist/push/preferences.service.js +1 -1
- package/dist/push/push-owed.d.ts +3 -3
- package/dist/push/push-owed.js +6 -6
- package/dist/push/push.schemas.d.ts +4 -4
- package/dist/push/push.schemas.js +3 -3
- package/dist/push/recipients.d.ts +4 -4
- package/dist/push/recipients.js +23 -23
- package/dist/push/texts.d.ts +3 -3
- package/dist/push/texts.js +2 -2
- package/dist/push/triggers.d.ts +1 -1
- package/dist/roles/worker.module.js +18 -4
- package/dist/runtime/compaction-settings.service.d.ts +13 -1
- package/dist/runtime/compaction-settings.service.js +16 -1
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +24 -1
- package/dist/runtime/context/build.js +33 -11
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +9 -2
- package/dist/runtime/context/compaction.js +64 -21
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/context/run-context.d.ts +38 -0
- package/dist/runtime/context/run-context.js +54 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +16 -4
- package/dist/runtime/maintenance.js +79 -18
- package/dist/runtime/model-call.d.ts +34 -5
- package/dist/runtime/model-call.js +207 -22
- package/dist/runtime/providers.js +11 -1
- package/dist/runtime/run-finish.d.ts +4 -4
- package/dist/runtime/run-finish.js +3 -3
- package/dist/runtime/run-queue.js +12 -7
- package/dist/runtime/run-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/run-worker.js +7 -1
- package/dist/runtime/runtime.module.js +6 -3
- package/dist/runtime/subagents/dispatch.js +11 -3
- package/dist/sandbox/browse-roots.d.ts +8 -0
- package/dist/sandbox/browse-roots.js +22 -0
- package/dist/sandbox/network-grants.d.ts +4 -4
- package/dist/sandbox/network-grants.js +7 -7
- package/dist/sandbox/operation-authority.d.ts +10 -3
- package/dist/sandbox/operation-authority.js +20 -10
- package/dist/sandbox/operation-intents.d.ts +3 -1
- package/dist/sandbox/operation-intents.js +11 -4
- package/dist/sandbox/permission-call-grants.js +2 -2
- package/dist/sandbox/permission-facts.js +1 -1
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +22 -11
- package/dist/sandbox/review/permission-candidate.d.ts +1 -1
- package/dist/sandbox/review/permission-candidate.js +1 -1
- package/dist/sandbox/sandbox.service.d.ts +15 -5
- package/dist/sandbox/sandbox.service.js +14 -8
- package/dist/shares/liveness.d.ts +26 -12
- package/dist/shares/liveness.js +79 -20
- package/dist/shares/revoke.d.ts +16 -11
- package/dist/shares/revoke.js +18 -14
- package/dist/shares/share-objects.d.ts +16 -21
- package/dist/shares/share-objects.js +25 -55
- package/dist/shares/share-open.service.d.ts +8 -4
- package/dist/shares/share-open.service.js +14 -11
- package/dist/shares/shares.controller.d.ts +16 -5
- package/dist/shares/shares.controller.js +39 -5
- package/dist/shares/shares.module.d.ts +4 -4
- package/dist/shares/shares.module.js +7 -6
- package/dist/shares/shares.schemas.d.ts +4 -0
- package/dist/shares/shares.schemas.js +2 -0
- package/dist/shares/shares.service.d.ts +93 -54
- package/dist/shares/shares.service.js +292 -131
- package/dist/shares/sweep.job.d.ts +18 -39
- package/dist/shares/sweep.job.js +47 -206
- package/dist/storage/purge.d.ts +1 -1
- package/dist/storage/purge.js +2 -2
- package/dist/tools/approvals.service.d.ts +6 -6
- package/dist/tools/approvals.service.js +19 -19
- package/dist/tools/builtin-names.d.ts +12 -12
- package/dist/tools/builtin-names.js +29 -29
- package/dist/tools/builtins/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
- package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
- package/dist/tools/builtins/builtin-tools.d.ts +15 -9
- package/dist/tools/builtins/builtin-tools.js +33 -22
- package/dist/tools/builtins/conversation-files.d.ts +23 -13
- package/dist/tools/builtins/conversation-files.js +62 -83
- package/dist/tools/builtins/image/generate.d.ts +7 -1
- package/dist/tools/builtins/image/generate.js +1 -1
- package/dist/tools/builtins/platform.js +1 -0
- package/dist/tools/builtins/sandbox/common.d.ts +6 -2
- package/dist/tools/builtins/sandbox/deliver.js +6 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
- package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
- package/dist/tools/call-scope.d.ts +1 -1
- package/dist/tools/git-asks.js +1 -1
- package/dist/tools/git-push-policy.d.ts +3 -3
- package/dist/tools/git-push-policy.js +6 -6
- package/dist/tools/network-asks.d.ts +3 -3
- package/dist/tools/network-asks.js +3 -3
- package/dist/tools/pipeline.d.ts +4 -4
- package/dist/tools/pipeline.js +2 -2
- package/dist/tools/policy.d.ts +3 -3
- package/dist/tools/policy.js +3 -3
- package/dist/tools/tools.module.js +15 -9
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.js +6 -3
- package/dist/ui/registry.d.ts +21 -5
- package/dist/ui/registry.js +24 -6
- package/dist/ui/ui.schemas.d.ts +22 -0
- package/dist/ui/ui.schemas.js +22 -4
- package/dist/ui/views.controller.d.ts +13 -3
- package/dist/ui/views.controller.js +33 -2
- package/dist/ui/views.d.ts +29 -1
- package/dist/ui/views.js +131 -7
- package/package.json +3 -3
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -0
- package/src/migrations/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -0
- package/dist/platform/ops/schedules.ops.js +0 -509
- package/dist/schedules/effective-settings.d.ts +0 -22
- package/dist/schedules/effective-settings.js +0 -18
- package/dist/schedules/errors.d.ts +0 -8
- package/dist/schedules/errors.js +0 -8
- package/dist/schedules/job-ids.d.ts +0 -81
- package/dist/schedules/job-ids.js +0 -95
- package/dist/schedules/schedules.module.d.ts +0 -16
- package/dist/schedules/schedules.schemas.js +0 -213
- package/dist/schedules/store.module.d.ts +0 -6
- package/dist/schedules/types.d.ts +0 -110
- /package/dist/{schedules → automations}/types.js +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { type ChannelTarget, type Logger } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { type Job, type Worker } from "bullmq";
|
|
3
|
+
import { AutomationsService } from "../automations/automations.service.js";
|
|
3
4
|
import { EventLog } from "../conversations/event-log.js";
|
|
4
5
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
6
|
+
import { BlobsService } from "../files/blobs.service.js";
|
|
5
7
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
6
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
7
9
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
8
10
|
import { ConversationLock } from "../runtime/conversation-lock.js";
|
|
9
11
|
import type { StreamBus } from "../runtime/stream.js";
|
|
10
|
-
import { ScheduledTasksService } from "../schedules/scheduled-tasks.service.js";
|
|
11
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
12
12
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
13
13
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
14
14
|
import { ToolRegistry } from "../tools/registry.js";
|
|
@@ -106,7 +106,7 @@ export declare class ChannelOutbound {
|
|
|
106
106
|
private readonly log;
|
|
107
107
|
readonly txHost: TransactionHost;
|
|
108
108
|
/** Pauses the task of a scheduled run whose chat is gone (scheduled tasks spec §8). */
|
|
109
|
-
private readonly
|
|
109
|
+
private readonly automations;
|
|
110
110
|
private worker;
|
|
111
111
|
private closed;
|
|
112
112
|
/** 停机:进行中的任务在下一个检查点交还队列(由其他副本续投)。 */
|
|
@@ -119,9 +119,9 @@ export declare class ChannelOutbound {
|
|
|
119
119
|
/** 入站任务的处理(worker 上执行 `ChannelInbound.handle`);失败抛错由 BullMQ 重试。 */
|
|
120
120
|
inbound: Pick<ChannelInbound, "handle">, jobs: Pick<ChannelJobs, "enqueue" | "resumeConnection">, config: Pick<KernelConfigService, "get">, log: Pick<Logger, "error" | "warn" | "info">, txHost: TransactionHost,
|
|
121
121
|
/** Pauses the task of a scheduled run whose chat is gone (scheduled tasks spec §8). */
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
|
|
122
|
+
automations: Pick<AutomationsService, "pauseFor">,
|
|
123
|
+
/** The blobs of conversation files sent into the chat (channel file delivery spec §4.2). */
|
|
124
|
+
blobs: Pick<BlobsService, "open">);
|
|
125
125
|
/**
|
|
126
126
|
* Starts consuming (worker role only): `worker` is the `@Processor` worker of the channel queue
|
|
127
127
|
* (its job lock and stalled detection follow the run queue's config).
|
|
@@ -169,9 +169,9 @@ export declare class ChannelOutbound {
|
|
|
169
169
|
/**
|
|
170
170
|
* A delivery failed for good because the chat is gone or the connection's credentials are
|
|
171
171
|
* (`ChannelSendError` `target_gone` / `auth`): when the run being delivered serves a scheduled
|
|
172
|
-
* task run (`runs.
|
|
172
|
+
* task run (`runs.automation_run_id`), its task pauses with `target_gone` (spec §8), so later
|
|
173
173
|
* ticks do not keep running into the same chat. `runId` is the run of the event being delivered;
|
|
174
174
|
* without one (a streaming draft), the conversation's latest run. A person's run pauses nothing.
|
|
175
175
|
*/
|
|
176
|
-
|
|
176
|
+
pauseAutomationIn(conversationId: string, runId: string | null): Promise<void>;
|
|
177
177
|
}
|
|
@@ -12,18 +12,18 @@ import { isChannelSendError, } from "@capybara-hq/plugin-sdk";
|
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { DelayedError, UnrecoverableError } from "bullmq";
|
|
14
14
|
import { sql } from "kysely";
|
|
15
|
+
import { AutomationsService } from "../automations/automations.service.js";
|
|
15
16
|
import { productName } from "../config/product-name.js";
|
|
16
17
|
import { conversationTopic, EventLog, } from "../conversations/event-log.js";
|
|
17
18
|
import { recipientLocale } from "../conversations/message-context.js";
|
|
18
19
|
import { ApiError } from "../errors.js";
|
|
20
|
+
import { BlobsService } from "../files/blobs.service.js";
|
|
19
21
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
20
22
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
21
23
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
22
24
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
23
25
|
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
24
26
|
import { ConversationLock, } from "../runtime/conversation-lock.js";
|
|
25
|
-
import { ScheduledTasksService } from "../schedules/scheduled-tasks.service.js";
|
|
26
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
27
27
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
28
28
|
import { toolInfo } from "../tools/info.js";
|
|
29
29
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
@@ -31,7 +31,7 @@ import { ToolRegistry } from "../tools/registry.js";
|
|
|
31
31
|
import { approvalCard, callSummary, cardMessage, connectUrl, conversationUrl, personFieldsCard, questionCard, webBase, } from "./cards.js";
|
|
32
32
|
import { ChannelConnections, FILE_CALL_TIMEOUT_MS, } from "./connections.service.js";
|
|
33
33
|
import { processDisplayOf, progressCardMessage } from "./features.js";
|
|
34
|
-
import { FileSlots, fileKind, fileLinkText, fileRootText, planFileDelivery, pluginFileName, readArtifactCapped, } from "./file-delivery.js";
|
|
34
|
+
import { FileSlots, fileKind, fileLinkText, fileRootText, planFileDelivery, pluginFileName, readArtifactCapped, referencedBlob, } from "./file-delivery.js";
|
|
35
35
|
import { ChannelInbound } from "./inbound.js";
|
|
36
36
|
import { ChannelJobs, INBOUND_JOB, idempotencyKey, RESUME_JOB, } from "./jobs.js";
|
|
37
37
|
import { phrase } from "./phrases.js";
|
|
@@ -181,7 +181,7 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
181
181
|
config;
|
|
182
182
|
log;
|
|
183
183
|
txHost;
|
|
184
|
-
|
|
184
|
+
automations;
|
|
185
185
|
worker;
|
|
186
186
|
closed = false;
|
|
187
187
|
/** 停机:进行中的任务在下一个检查点交还队列(由其他副本续投)。 */
|
|
@@ -194,16 +194,16 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
194
194
|
/** 入站任务的处理(worker 上执行 `ChannelInbound.handle`);失败抛错由 BullMQ 重试。 */
|
|
195
195
|
inbound, jobs, config, log, txHost,
|
|
196
196
|
/** Pauses the task of a scheduled run whose chat is gone (scheduled tasks spec §8). */
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
|
|
197
|
+
automations,
|
|
198
|
+
/** The blobs of conversation files sent into the chat (channel file delivery spec §4.2). */
|
|
199
|
+
blobs) {
|
|
200
200
|
this.kdb = kdb;
|
|
201
201
|
this.inbound = inbound;
|
|
202
202
|
this.jobs = jobs;
|
|
203
203
|
this.config = config;
|
|
204
204
|
this.log = log;
|
|
205
205
|
this.txHost = txHost;
|
|
206
|
-
this.
|
|
206
|
+
this.automations = automations;
|
|
207
207
|
this.lock = lock.scoped(DELIVER_LOCK_PREFIX);
|
|
208
208
|
this.d = {
|
|
209
209
|
get db() {
|
|
@@ -217,7 +217,7 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
217
217
|
questions,
|
|
218
218
|
config,
|
|
219
219
|
log,
|
|
220
|
-
|
|
220
|
+
blobs,
|
|
221
221
|
// one per process: it bounds this replica's memory (not shared state)
|
|
222
222
|
fileSlots: new FileSlots(config.get().channels.fileConcurrency),
|
|
223
223
|
writes: this,
|
|
@@ -351,7 +351,7 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
351
351
|
if (outcome.error)
|
|
352
352
|
await this.recordError(outcome.error.connectionId, outcome.error.message);
|
|
353
353
|
if (outcome.gone) {
|
|
354
|
-
await this.
|
|
354
|
+
await this.pauseAutomationIn(conversationId, outcome.gone.runId).catch((err) => this.log.warn("cannot pause the automation of a gone chat", { conversationId, err }));
|
|
355
355
|
}
|
|
356
356
|
switch (outcome.kind) {
|
|
357
357
|
case "shutdown":
|
|
@@ -497,25 +497,25 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
497
497
|
/**
|
|
498
498
|
* A delivery failed for good because the chat is gone or the connection's credentials are
|
|
499
499
|
* (`ChannelSendError` `target_gone` / `auth`): when the run being delivered serves a scheduled
|
|
500
|
-
* task run (`runs.
|
|
500
|
+
* task run (`runs.automation_run_id`), its task pauses with `target_gone` (spec §8), so later
|
|
501
501
|
* ticks do not keep running into the same chat. `runId` is the run of the event being delivered;
|
|
502
502
|
* without one (a streaming draft), the conversation's latest run. A person's run pauses nothing.
|
|
503
503
|
*/
|
|
504
|
-
async
|
|
504
|
+
async pauseAutomationIn(conversationId, runId) {
|
|
505
505
|
let q = this.kdb
|
|
506
506
|
.selectFrom("runs as r")
|
|
507
|
-
.innerJoin("
|
|
508
|
-
.select(["tr.
|
|
507
|
+
.innerJoin("automation_runs as tr", "tr.id", "r.automation_run_id")
|
|
508
|
+
.select(["tr.automation_id", "r.automation_run_id"])
|
|
509
509
|
.where("r.conversation_id", "=", conversationId);
|
|
510
510
|
q = runId !== null ? q.where("r.id", "=", runId) : q.orderBy("r.created_at", "desc").limit(1);
|
|
511
511
|
const row = await q.executeTakeFirst();
|
|
512
512
|
if (!row)
|
|
513
513
|
return;
|
|
514
|
-
await this.
|
|
515
|
-
this.log.info("
|
|
514
|
+
await this.automations.pauseFor(this.kdb.db, row.automation_id, "target_gone", null);
|
|
515
|
+
this.log.info("automation paused: its chat is gone", {
|
|
516
516
|
conversationId,
|
|
517
|
-
taskId: row.
|
|
518
|
-
taskRunId: row.
|
|
517
|
+
taskId: row.automation_id,
|
|
518
|
+
taskRunId: row.automation_run_id,
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
521
|
};
|
|
@@ -527,7 +527,7 @@ __decorate([
|
|
|
527
527
|
], ChannelOutbound.prototype, "bindThreadIn", null);
|
|
528
528
|
__decorate([
|
|
529
529
|
Transactional()
|
|
530
|
-
], ChannelOutbound.prototype, "
|
|
530
|
+
], ChannelOutbound.prototype, "pauseAutomationIn", null);
|
|
531
531
|
ChannelOutbound = __decorate([
|
|
532
532
|
Injectable(),
|
|
533
533
|
__param(0, Inject(KernelDb)),
|
|
@@ -543,8 +543,8 @@ ChannelOutbound = __decorate([
|
|
|
543
543
|
__param(10, Inject(KernelConfigService)),
|
|
544
544
|
__param(11, Inject(KERNEL_LOGGER)),
|
|
545
545
|
__param(12, Inject(TransactionHost)),
|
|
546
|
-
__param(13, Inject(
|
|
547
|
-
__param(14, Inject(
|
|
546
|
+
__param(13, Inject(AutomationsService)),
|
|
547
|
+
__param(14, Inject(BlobsService))
|
|
548
548
|
], ChannelOutbound);
|
|
549
549
|
export { ChannelOutbound };
|
|
550
550
|
/** One `bind` card per handoff link, in one message (process blocks spec §6.2). */
|
|
@@ -573,7 +573,7 @@ class Delivery {
|
|
|
573
573
|
persisted = 0;
|
|
574
574
|
/** 正在投递的事件(不可重试失败按它计数)。 */
|
|
575
575
|
handling;
|
|
576
|
-
/** The run of the event being delivered (a gone chat pauses its
|
|
576
|
+
/** The run of the event being delivered (a gone chat pauses its automation). */
|
|
577
577
|
handlingRun = null;
|
|
578
578
|
/**
|
|
579
579
|
* A scheduled group run's thread is still to bind (`pending_thread_account_id` set): the first
|
|
@@ -730,7 +730,7 @@ class Delivery {
|
|
|
730
730
|
if (isChannelSendError(err) && !err.retryable) {
|
|
731
731
|
const message = this.redact(errMsg(err));
|
|
732
732
|
// Ruling A22:机器人被移出群 / 会话不存在 → 停止本轮,不计毒事件(不是连接的问题,不记 last_error)
|
|
733
|
-
// either also pauses the
|
|
733
|
+
// either also pauses the automation of the run being delivered (automations §8)
|
|
734
734
|
const gone = { runId: this.handlingRun };
|
|
735
735
|
if (err.reason === "target_gone") {
|
|
736
736
|
this.d.log.warn("channel delivery target is gone", {
|
|
@@ -1170,16 +1170,18 @@ class Delivery {
|
|
|
1170
1170
|
*/
|
|
1171
1171
|
async deliverArtifact(e) {
|
|
1172
1172
|
const a = e.payload;
|
|
1173
|
+
// the file the event created (its id is the artifact id; earlier events name no fileId)
|
|
1174
|
+
const blob = await referencedBlob(this.d.db, this.s.row.orgId, this.conversationId, a.fileId ?? a.artifactId);
|
|
1173
1175
|
const plan = planFileDelivery({
|
|
1174
|
-
|
|
1176
|
+
referenced: blob !== null,
|
|
1175
1177
|
artifact: a,
|
|
1176
1178
|
features: this.s.features,
|
|
1177
1179
|
canSendFile: this.s.sendFile !== undefined,
|
|
1178
1180
|
fileMaxBytes: this.d.config.get().channels.fileMaxBytes,
|
|
1179
1181
|
});
|
|
1180
|
-
if (plan.mode === "link") {
|
|
1181
|
-
if (
|
|
1182
|
-
this.d.log.warn("channel file
|
|
1182
|
+
if (plan.mode === "link" || blob === null) {
|
|
1183
|
+
if (blob === null) {
|
|
1184
|
+
this.d.log.warn("channel file not referenced by the conversation sent as a link", {
|
|
1183
1185
|
conversationId: this.conversationId,
|
|
1184
1186
|
seq: e.seq,
|
|
1185
1187
|
});
|
|
@@ -1198,7 +1200,7 @@ class Delivery {
|
|
|
1198
1200
|
}
|
|
1199
1201
|
let sent;
|
|
1200
1202
|
try {
|
|
1201
|
-
sent = await this.sendNative(e.seq, a, plan);
|
|
1203
|
+
sent = await this.sendNative(e.seq, a, blob, plan);
|
|
1202
1204
|
}
|
|
1203
1205
|
finally {
|
|
1204
1206
|
release();
|
|
@@ -1211,7 +1213,7 @@ class Delivery {
|
|
|
1211
1213
|
* Reads and sends one file while holding a file slot; false when the link line stands in for it
|
|
1212
1214
|
* (see {@link deliverArtifact}).
|
|
1213
1215
|
*/
|
|
1214
|
-
async sendNative(seq, a, plan) {
|
|
1216
|
+
async sendNative(seq, a, blob, plan) {
|
|
1215
1217
|
// the replica stopped while this delivery waited for its slot: hand the job back untouched
|
|
1216
1218
|
if (this.stopping.aborted)
|
|
1217
1219
|
throw new DeliveryShutdownError();
|
|
@@ -1225,7 +1227,7 @@ class Delivery {
|
|
|
1225
1227
|
let read;
|
|
1226
1228
|
try {
|
|
1227
1229
|
// the read stops with the replica: nothing has reached the platform yet
|
|
1228
|
-
read = await readArtifactCapped(this.d.
|
|
1230
|
+
read = await readArtifactCapped((signal) => this.d.blobs.open(this.s.row.orgId, blob, { signal }), plan.cap, AbortSignal.any([this.stopping, AbortSignal.timeout(FILE_CALL_TIMEOUT_MS)]));
|
|
1229
1231
|
}
|
|
1230
1232
|
catch (err) {
|
|
1231
1233
|
if (this.stopping.aborted)
|
|
@@ -49,7 +49,7 @@ export declare function findThread(db: KernelSchemaDb, k: ThreadKey): Promise<st
|
|
|
49
49
|
export declare function insertThread(db: KernelSchemaDb, k: ThreadKey, conversationId: string): Promise<string>;
|
|
50
50
|
/**
|
|
51
51
|
* The live conversation of a thread, or a new one bound to it, inside the caller's transaction
|
|
52
|
-
* (
|
|
52
|
+
* (an automation posting into a chat, scheduled tasks spec §6): the live thread row's
|
|
53
53
|
* conversation when there is one; otherwise `create()`'s conversation, bound with
|
|
54
54
|
* {@link insertThread} and given the chat as its delivery target (`channel_deliveries`), as an
|
|
55
55
|
* inbound message would. When a concurrent inbound bound the thread first, the empty conversation
|
package/dist/channels/threads.js
CHANGED
|
@@ -150,7 +150,7 @@ export async function insertThread(db, k, conversationId) {
|
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* The live conversation of a thread, or a new one bound to it, inside the caller's transaction
|
|
153
|
-
* (
|
|
153
|
+
* (an automation posting into a chat, scheduled tasks spec §6): the live thread row's
|
|
154
154
|
* conversation when there is one; otherwise `create()`'s conversation, bound with
|
|
155
155
|
* {@link insertThread} and given the chat as its delivery target (`channel_deliveries`), as an
|
|
156
156
|
* inbound message would. When a concurrent inbound bound the thread first, the empty conversation
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -199,6 +199,9 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
199
199
|
storage: z.ZodDefault<z.ZodObject<{
|
|
200
200
|
purgeDeletedOrgsAfterDays: z.ZodDefault<z.ZodNumber>;
|
|
201
201
|
}, z.core.$strict>>;
|
|
202
|
+
files: z.ZodDefault<z.ZodObject<{
|
|
203
|
+
deletedRetentionDays: z.ZodDefault<z.ZodNumber>;
|
|
204
|
+
}, z.core.$strict>>;
|
|
202
205
|
attachments: z.ZodPrefault<z.ZodObject<{
|
|
203
206
|
maxBytes: z.ZodDefault<z.ZodNumber>;
|
|
204
207
|
allowedTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
@@ -248,11 +251,15 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
248
251
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
249
252
|
}, z.core.$strict>>;
|
|
250
253
|
}, z.core.$strict>>;
|
|
251
|
-
|
|
254
|
+
automations: z.ZodPrefault<z.ZodObject<{
|
|
252
255
|
minIntervalFloorMinutes: z.ZodDefault<z.ZodNumber>;
|
|
253
256
|
maxTasksPerMemberCap: z.ZodDefault<z.ZodNumber>;
|
|
254
257
|
maxTasksPerOrgCap: z.ZodDefault<z.ZodNumber>;
|
|
255
258
|
maxRunsPerHourCap: z.ZodDefault<z.ZodNumber>;
|
|
259
|
+
maxEventDepthCap: z.ZodDefault<z.ZodNumber>;
|
|
260
|
+
coalesceSecondsCap: z.ZodDefault<z.ZodNumber>;
|
|
261
|
+
maxEventRunsPerSubjectPerHourCap: z.ZodDefault<z.ZodNumber>;
|
|
262
|
+
eventRetentionDays: z.ZodDefault<z.ZodNumber>;
|
|
256
263
|
}, z.core.$strict>>;
|
|
257
264
|
sandbox: z.ZodPrefault<z.ZodObject<{
|
|
258
265
|
image: z.ZodOptional<z.ZodString>;
|
package/dist/config/schema.js
CHANGED
|
@@ -859,7 +859,9 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
859
859
|
.int()
|
|
860
860
|
.positive()
|
|
861
861
|
.default(60000)
|
|
862
|
-
.meta(meta({
|
|
862
|
+
.meta(meta({
|
|
863
|
+
description: "Timeout of one tool call in milliseconds; also the deadline of a trigger source's events() and visible() calls when an event is dispatched",
|
|
864
|
+
})),
|
|
863
865
|
maxTimeoutMs: z
|
|
864
866
|
.number()
|
|
865
867
|
.int()
|
|
@@ -1162,6 +1164,18 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1162
1164
|
})),
|
|
1163
1165
|
})
|
|
1164
1166
|
.default({ purgeDeletedOrgsAfterDays: 30 }),
|
|
1167
|
+
files: z
|
|
1168
|
+
.strictObject({
|
|
1169
|
+
deletedRetentionDays: z
|
|
1170
|
+
.number()
|
|
1171
|
+
.int()
|
|
1172
|
+
.positive()
|
|
1173
|
+
.default(30)
|
|
1174
|
+
.meta(meta({
|
|
1175
|
+
description: "Days a deleted file keeps its bytes before the blob sweep may delete them.",
|
|
1176
|
+
})),
|
|
1177
|
+
})
|
|
1178
|
+
.default({ deletedRetentionDays: 30 }),
|
|
1165
1179
|
attachments: z
|
|
1166
1180
|
.strictObject({
|
|
1167
1181
|
maxBytes: z
|
|
@@ -1433,7 +1447,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1433
1447
|
.prefault({}),
|
|
1434
1448
|
})
|
|
1435
1449
|
.prefault({}),
|
|
1436
|
-
|
|
1450
|
+
automations: z
|
|
1437
1451
|
.strictObject({
|
|
1438
1452
|
minIntervalFloorMinutes: z
|
|
1439
1453
|
.number()
|
|
@@ -1442,7 +1456,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1442
1456
|
.default(5)
|
|
1443
1457
|
.meta(meta({
|
|
1444
1458
|
hot: true,
|
|
1445
|
-
description: "Smallest value an organization may set for the minimum gap between two fire times of
|
|
1459
|
+
description: "Smallest value an organization may set for the minimum gap between two fire times of an automation, in minutes; a lower org value is clamped up to it",
|
|
1446
1460
|
})),
|
|
1447
1461
|
maxTasksPerMemberCap: z
|
|
1448
1462
|
.number()
|
|
@@ -1451,7 +1465,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1451
1465
|
.default(100)
|
|
1452
1466
|
.meta(meta({
|
|
1453
1467
|
hot: true,
|
|
1454
|
-
description: "Largest number of
|
|
1468
|
+
description: "Largest number of automations per member an organization may allow; a higher org value is clamped down to it",
|
|
1455
1469
|
})),
|
|
1456
1470
|
maxTasksPerOrgCap: z
|
|
1457
1471
|
.number()
|
|
@@ -1460,7 +1474,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1460
1474
|
.default(2000)
|
|
1461
1475
|
.meta(meta({
|
|
1462
1476
|
hot: true,
|
|
1463
|
-
description: "Largest number of
|
|
1477
|
+
description: "Largest number of automations per organization an organization may allow; a higher org value is clamped down to it",
|
|
1464
1478
|
})),
|
|
1465
1479
|
maxRunsPerHourCap: z
|
|
1466
1480
|
.number()
|
|
@@ -1469,7 +1483,43 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1469
1483
|
.default(600)
|
|
1470
1484
|
.meta(meta({
|
|
1471
1485
|
hot: true,
|
|
1472
|
-
description: "Largest
|
|
1486
|
+
description: "Largest value an organization may set for maxRunsPerHour, the automation runs one member's automations may start per hour; a higher org value is clamped down to it",
|
|
1487
|
+
})),
|
|
1488
|
+
maxEventDepthCap: z
|
|
1489
|
+
.number()
|
|
1490
|
+
.int()
|
|
1491
|
+
.positive()
|
|
1492
|
+
.default(16)
|
|
1493
|
+
.meta(meta({
|
|
1494
|
+
hot: true,
|
|
1495
|
+
description: "Largest event chain depth an organization may allow before an event caused by an automation run stops being dispatched; a higher org value is clamped down to it",
|
|
1496
|
+
})),
|
|
1497
|
+
coalesceSecondsCap: z
|
|
1498
|
+
.number()
|
|
1499
|
+
.int()
|
|
1500
|
+
.positive()
|
|
1501
|
+
.default(3600)
|
|
1502
|
+
.meta(meta({
|
|
1503
|
+
hot: true,
|
|
1504
|
+
description: "Longest window, in seconds, an organization may set for coalescing one subject's events into one automation run; a longer org value is clamped down to it",
|
|
1505
|
+
})),
|
|
1506
|
+
maxEventRunsPerSubjectPerHourCap: z
|
|
1507
|
+
.number()
|
|
1508
|
+
.int()
|
|
1509
|
+
.positive()
|
|
1510
|
+
.default(120)
|
|
1511
|
+
.meta(meta({
|
|
1512
|
+
hot: true,
|
|
1513
|
+
description: "Largest value an organization may set for maxEventRunsPerSubjectPerHour: one event automation makes up to that many runs per subject per hour, and a window past it is recorded as a run skipped with subject_rate; a higher org value is clamped down to it",
|
|
1514
|
+
})),
|
|
1515
|
+
eventRetentionDays: z
|
|
1516
|
+
.number()
|
|
1517
|
+
.int()
|
|
1518
|
+
.positive()
|
|
1519
|
+
.default(30)
|
|
1520
|
+
.meta(meta({
|
|
1521
|
+
hot: true,
|
|
1522
|
+
description: "Days a trigger event is kept after it was stored: a dispatched, undelivered or depth-stopped event older than this, none of whose deliveries still waits for a run, is deleted with its deliveries by the trigger event sweep (every five minutes)",
|
|
1473
1523
|
})),
|
|
1474
1524
|
})
|
|
1475
1525
|
.prefault({}),
|
|
@@ -8,8 +8,8 @@ export interface ApprovalProfile {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Resolves the profile that decides an ask addressed to the conversation's person (profiles govern
|
|
11
|
-
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no
|
|
12
|
-
* owner is the person asked has one: any other root,
|
|
11
|
+
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no automation) whose
|
|
12
|
+
* owner is the person asked has one: any other root, an automation's conversation or an ask
|
|
13
13
|
* addressed to another account keeps asking. The profile is the root's effective one as the
|
|
14
14
|
* permission view reads it (Auto falls back to Approve for me where a bound device's consent no
|
|
15
15
|
* longer holds; without a device Auto holds, ruling R8).
|
|
@@ -13,8 +13,8 @@ import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
|
13
13
|
import { PermissionFactsModule } from "../sandbox/permission-facts.module.js";
|
|
14
14
|
/**
|
|
15
15
|
* Resolves the profile that decides an ask addressed to the conversation's person (profiles govern
|
|
16
|
-
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no
|
|
17
|
-
* owner is the person asked has one: any other root,
|
|
16
|
+
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no automation) whose
|
|
17
|
+
* owner is the person asked has one: any other root, an automation's conversation or an ask
|
|
18
18
|
* addressed to another account keeps asking. The profile is the root's effective one as the
|
|
19
19
|
* permission view reads it (Auto falls back to Approve for me where a bound device's consent no
|
|
20
20
|
* longer holds; without a device Auto holds, ruling R8).
|
|
@@ -36,7 +36,7 @@ let ConversationApprovalProfile = class ConversationApprovalProfile {
|
|
|
36
36
|
.executeTakeFirst();
|
|
37
37
|
if (row === undefined ||
|
|
38
38
|
row.kind !== "chat" ||
|
|
39
|
-
row.
|
|
39
|
+
row.automation_id !== null ||
|
|
40
40
|
row.account_id !== input.requestedFor)
|
|
41
41
|
return null;
|
|
42
42
|
const { view } = await this.facts.viewWithAccess(input.orgId, row.account_id, row);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReferencedFiles } from "../files/referenced-files.js";
|
|
2
2
|
import { StorageService } from "../storage/storage.service.js";
|
|
3
3
|
import { ConversationAccess } from "./access.js";
|
|
4
4
|
/** 产物下载跳转的预签名有效期(秒)。 */
|
|
@@ -20,27 +20,30 @@ export interface ArtifactPreview {
|
|
|
20
20
|
truncated: boolean;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* A conversation's files by id (M5 T8 / T11; file library spec §2): any file the conversation
|
|
24
|
+
* refers to (a delivery or an upload sent in it). The conversation must be visible by the event
|
|
25
|
+
* stream's rule (else `conversation.not_found`); the file must be one the conversation refers to,
|
|
26
|
+
* not deleted, its blob readable (else `conversation.artifact_not_found`). Bytes are read through
|
|
27
|
+
* the file's blob (size and etag checked), never an event's `objectKey`.
|
|
26
28
|
*
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* 查找走 `conversation_events` 的主键 `(conversation_id, seq)` 前缀,在 SQL 里按 `type` 与
|
|
34
|
-
* `payload->>'artifactId'` 过滤、`LIMIT 1`(只扫这一个会话的事件,不在 JS 里扫日志;不加迁移)。
|
|
29
|
+
* - Download: a 302 to a presigned address, `attachment` by default (with the file's name and
|
|
30
|
+
* type); `inline` only takes effect for bitmaps (the web's thumbnails).
|
|
31
|
+
* - Text preview: `text/*` and the text formats, the first {@link ARTIFACT_PREVIEW_MAX_BYTES} bytes
|
|
32
|
+
* by range, at most {@link ARTIFACT_PREVIEW_MAX_LINES} lines, as a JSON string (shown as plain
|
|
33
|
+
* text); other types, or NUL bytes in the head (binary after all) →
|
|
34
|
+
* `conversation.artifact_not_previewable`.
|
|
35
35
|
*/
|
|
36
36
|
export declare class ConversationArtifacts {
|
|
37
|
-
private readonly db;
|
|
38
37
|
private readonly storage;
|
|
39
|
-
/**
|
|
38
|
+
/** Conversation visibility (the same rule as the conversation's SSE stream). */
|
|
40
39
|
private readonly access;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
/** The files the conversation refers to, and their bytes. */
|
|
41
|
+
private readonly files;
|
|
42
|
+
constructor(storage: Pick<StorageService, "kernel">,
|
|
43
|
+
/** Conversation visibility (the same rule as the conversation's SSE stream). */
|
|
44
|
+
access: Pick<ConversationAccess, "isAccessible">,
|
|
45
|
+
/** The files the conversation refers to, and their bytes. */
|
|
46
|
+
files: Pick<ReferencedFiles, "references" | "open" | "head">);
|
|
44
47
|
private find;
|
|
45
48
|
downloadUrl(orgId: string, conversationId: string, viewerAccountId: string, artifactId: string, opts?: {
|
|
46
49
|
inline?: boolean;
|
|
@@ -8,9 +8,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
-
import { sql } from "kysely";
|
|
12
11
|
import { ApiError } from "../errors.js";
|
|
13
|
-
import {
|
|
12
|
+
import { isLive, ReferencedFiles } from "../files/referenced-files.js";
|
|
14
13
|
import { StorageService } from "../storage/storage.service.js";
|
|
15
14
|
import { UUID_RE } from "../ui/registry.js";
|
|
16
15
|
import { ConversationAccess } from "./access.js";
|
|
@@ -62,29 +61,31 @@ async function readPrefix(body, max) {
|
|
|
62
61
|
return out.subarray(0, n);
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
64
|
+
* A conversation's files by id (M5 T8 / T11; file library spec §2): any file the conversation
|
|
65
|
+
* refers to (a delivery or an upload sent in it). The conversation must be visible by the event
|
|
66
|
+
* stream's rule (else `conversation.not_found`); the file must be one the conversation refers to,
|
|
67
|
+
* not deleted, its blob readable (else `conversation.artifact_not_found`). Bytes are read through
|
|
68
|
+
* the file's blob (size and etag checked), never an event's `objectKey`.
|
|
68
69
|
*
|
|
69
|
-
* -
|
|
70
|
-
*
|
|
71
|
-
* -
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* 查找走 `conversation_events` 的主键 `(conversation_id, seq)` 前缀,在 SQL 里按 `type` 与
|
|
76
|
-
* `payload->>'artifactId'` 过滤、`LIMIT 1`(只扫这一个会话的事件,不在 JS 里扫日志;不加迁移)。
|
|
70
|
+
* - Download: a 302 to a presigned address, `attachment` by default (with the file's name and
|
|
71
|
+
* type); `inline` only takes effect for bitmaps (the web's thumbnails).
|
|
72
|
+
* - Text preview: `text/*` and the text formats, the first {@link ARTIFACT_PREVIEW_MAX_BYTES} bytes
|
|
73
|
+
* by range, at most {@link ARTIFACT_PREVIEW_MAX_LINES} lines, as a JSON string (shown as plain
|
|
74
|
+
* text); other types, or NUL bytes in the head (binary after all) →
|
|
75
|
+
* `conversation.artifact_not_previewable`.
|
|
77
76
|
*/
|
|
78
77
|
let ConversationArtifacts = class ConversationArtifacts {
|
|
79
|
-
db;
|
|
80
78
|
storage;
|
|
81
79
|
access;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
files;
|
|
81
|
+
constructor(storage,
|
|
82
|
+
/** Conversation visibility (the same rule as the conversation's SSE stream). */
|
|
83
|
+
access,
|
|
84
|
+
/** The files the conversation refers to, and their bytes. */
|
|
85
|
+
files) {
|
|
86
86
|
this.storage = storage;
|
|
87
87
|
this.access = access;
|
|
88
|
+
this.files = files;
|
|
88
89
|
}
|
|
89
90
|
async find(orgId, conversationId, viewerAccountId, artifactId) {
|
|
90
91
|
if (!UUID_RE.test(conversationId))
|
|
@@ -94,25 +95,17 @@ let ConversationArtifacts = class ConversationArtifacts {
|
|
|
94
95
|
}
|
|
95
96
|
if (!UUID_RE.test(artifactId))
|
|
96
97
|
throw artifactNotFound();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
.select("payload")
|
|
100
|
-
.where("conversation_id", "=", conversationId)
|
|
101
|
-
.where("type", "=", "artifact_created")
|
|
102
|
-
.where(sql `payload->>'artifactId'`, "=", artifactId)
|
|
103
|
-
.limit(1)
|
|
104
|
-
.executeTakeFirst();
|
|
105
|
-
if (!row)
|
|
98
|
+
const [f] = await this.files.references(orgId, [conversationId], { ids: [artifactId] });
|
|
99
|
+
if (!f || !isLive(f))
|
|
106
100
|
throw artifactNotFound();
|
|
107
|
-
return
|
|
101
|
+
return f;
|
|
108
102
|
}
|
|
109
103
|
async downloadUrl(orgId, conversationId, viewerAccountId, artifactId, opts = {}) {
|
|
110
104
|
const a = await this.find(orgId, conversationId, viewerAccountId, artifactId);
|
|
111
|
-
|
|
112
|
-
if (!(await store.head(a.objectKey)))
|
|
105
|
+
if (!(await this.files.head(orgId, a)))
|
|
113
106
|
throw artifactNotFound();
|
|
114
107
|
const inline = opts.inline === true && isInlineArtifactType(a.contentType);
|
|
115
|
-
const url = await
|
|
108
|
+
const url = await this.storage.kernel(orgId).presignGet(a.blob.objectKey, {
|
|
116
109
|
ttlSeconds: ARTIFACT_DOWNLOAD_TTL_SECONDS,
|
|
117
110
|
downloadName: a.name,
|
|
118
111
|
disposition: inline ? "inline" : "attachment",
|
|
@@ -125,9 +118,9 @@ let ConversationArtifacts = class ConversationArtifacts {
|
|
|
125
118
|
if (!isTextArtifactType(a.contentType)) {
|
|
126
119
|
throw new ApiError("conversation.artifact_not_previewable", "Only text artifacts have a preview");
|
|
127
120
|
}
|
|
128
|
-
const got = await this.
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
const got = await this.files.open(orgId, a, {
|
|
122
|
+
range: { start: 0, end: ARTIFACT_PREVIEW_MAX_BYTES - 1 },
|
|
123
|
+
});
|
|
131
124
|
if (!got)
|
|
132
125
|
throw artifactNotFound();
|
|
133
126
|
const bytes = await readPrefix(got.body, ARTIFACT_PREVIEW_MAX_BYTES);
|
|
@@ -156,8 +149,8 @@ let ConversationArtifacts = class ConversationArtifacts {
|
|
|
156
149
|
};
|
|
157
150
|
ConversationArtifacts = __decorate([
|
|
158
151
|
Injectable(),
|
|
159
|
-
__param(0, Inject(
|
|
160
|
-
__param(1, Inject(
|
|
161
|
-
__param(2, Inject(
|
|
152
|
+
__param(0, Inject(StorageService)),
|
|
153
|
+
__param(1, Inject(ConversationAccess)),
|
|
154
|
+
__param(2, Inject(ReferencedFiles))
|
|
162
155
|
], ConversationArtifacts);
|
|
163
156
|
export { ConversationArtifacts };
|