@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
|
@@ -12,6 +12,10 @@ import { connectorToolKey, parseToolKey, validateAllowHost, } from "@capybara-hq
|
|
|
12
12
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
15
|
+
import { readAutomationSettings } from "../automations/effective-settings.js";
|
|
16
|
+
import { GIT_GRANT_SPEC_HASH, gitGrantRefusal, gitPushGrantKey, grantRefusalOf, NETWORK_GRANT_PREFIX, NETWORK_GRANT_SPEC_HASH, networkGrantRefusal, normalizeGitRepo, } from "../automations/grant-rules.js";
|
|
17
|
+
import { AutomationStore } from "../automations/store.js";
|
|
18
|
+
import { unattendedTaskRunOf } from "../automations/unattended.js";
|
|
15
19
|
import { EventLog } from "../conversations/event-log.js";
|
|
16
20
|
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
17
21
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
@@ -38,10 +42,6 @@ import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js
|
|
|
38
42
|
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
39
43
|
import { isSessionGrantableRule } from "../sandbox/review/types.js";
|
|
40
44
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
41
|
-
import { readScheduleSettings } from "../schedules/effective-settings.js";
|
|
42
|
-
import { GIT_GRANT_SPEC_HASH, gitGrantRefusal, gitPushGrantKey, grantRefusalOf, NETWORK_GRANT_PREFIX, NETWORK_GRANT_SPEC_HASH, networkGrantRefusal, normalizeGitRepo, } from "../schedules/grant-rules.js";
|
|
43
|
-
import { ScheduledTaskStore } from "../schedules/store.js";
|
|
44
|
-
import { unattendedTaskRunOf } from "../schedules/unattended.js";
|
|
45
45
|
import { gitPushPolicyName, personalAuth } from "./connector-account-policies.js";
|
|
46
46
|
import { pluginDisplayNames } from "./display-names.js";
|
|
47
47
|
import { ToolRegistry } from "./registry.js";
|
|
@@ -218,7 +218,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
218
218
|
eventLog;
|
|
219
219
|
events;
|
|
220
220
|
txHost;
|
|
221
|
-
|
|
221
|
+
automations;
|
|
222
222
|
registry;
|
|
223
223
|
lockService;
|
|
224
224
|
sandbox;
|
|
@@ -228,7 +228,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
228
228
|
devices;
|
|
229
229
|
permissionLocks;
|
|
230
230
|
permissionGrants;
|
|
231
|
-
constructor(db, config, eventLog, events, txHost,
|
|
231
|
+
constructor(db, config, eventLog, events, txHost, automations,
|
|
232
232
|
/** A trial approval is kept only for a tool the task may hold as a grant (its agent's tools). */
|
|
233
233
|
registry,
|
|
234
234
|
/** One decision of a network ask at a time, across replicas. */
|
|
@@ -248,7 +248,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
248
248
|
this.eventLog = eventLog;
|
|
249
249
|
this.events = events;
|
|
250
250
|
this.txHost = txHost;
|
|
251
|
-
this.
|
|
251
|
+
this.automations = automations;
|
|
252
252
|
this.registry = registry;
|
|
253
253
|
this.lockService = lockService;
|
|
254
254
|
this.sandbox = sandbox;
|
|
@@ -1481,7 +1481,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1481
1481
|
return { record: toRecord(updated), toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
1482
1482
|
}
|
|
1483
1483
|
/**
|
|
1484
|
-
* A trial run of
|
|
1484
|
+
* A trial run of an automation (scheduled tasks spec §7): an approval its creator granted, in
|
|
1485
1485
|
* any scope, is also added to the task's grants with the approved definition's hash, so its
|
|
1486
1486
|
* unattended runs do not ask again. Kept only by the rule `addGrants` applies
|
|
1487
1487
|
* (`grantRefusalOf`, against the task agent's tools now): never a role-escalated approval
|
|
@@ -1500,7 +1500,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1500
1500
|
if (served === null || !served.trial)
|
|
1501
1501
|
return;
|
|
1502
1502
|
const task = await t
|
|
1503
|
-
.selectFrom("
|
|
1503
|
+
.selectFrom("automations as s")
|
|
1504
1504
|
.innerJoin("agents as ag", "ag.id", "s.agent_id")
|
|
1505
1505
|
.leftJoin("agent_versions as v", (j) => j.onRef("v.agent_id", "=", "ag.id").onRef("v.version", "=", "ag.current_version"))
|
|
1506
1506
|
.select(["s.account_id", "v.definition"])
|
|
@@ -1527,21 +1527,21 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1527
1527
|
source: await conversationSourceOf(t, a.conversationId),
|
|
1528
1528
|
});
|
|
1529
1529
|
const tool = tools.find((x) => x.key === a.toolKey);
|
|
1530
|
-
const { forbiddenTools } = await
|
|
1530
|
+
const { forbiddenTools } = await readAutomationSettings(t, this.config, a.orgId);
|
|
1531
1531
|
const why = grantRefusalOf(a.toolKey, tool, {
|
|
1532
1532
|
role: member.role,
|
|
1533
1533
|
forbiddenTools,
|
|
1534
1534
|
});
|
|
1535
1535
|
if (why !== null)
|
|
1536
1536
|
return;
|
|
1537
|
-
await this.
|
|
1537
|
+
await this.automations.addGrant(t, served.taskId, {
|
|
1538
1538
|
toolKey: a.toolKey,
|
|
1539
1539
|
specHash: a.specHash,
|
|
1540
1540
|
connectorId: a.connectorId,
|
|
1541
1541
|
});
|
|
1542
1542
|
}
|
|
1543
1543
|
/**
|
|
1544
|
-
* A trial run of
|
|
1544
|
+
* A trial run of an automation (network ask-to-allow spec §8.1): the hosts its creator allowed
|
|
1545
1545
|
* for this run (「这次允许」) on a network ask about one of their devices become the task's
|
|
1546
1546
|
* `network:<host>` grants, each only when `networkGrantRefusal` allows it (exact host, within the
|
|
1547
1547
|
* org's effective egress, the device takes remote grants). Never for an ask another account
|
|
@@ -1557,7 +1557,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1557
1557
|
if (served === null || !served.trial)
|
|
1558
1558
|
return;
|
|
1559
1559
|
const task = await t
|
|
1560
|
-
.selectFrom("
|
|
1560
|
+
.selectFrom("automations")
|
|
1561
1561
|
.select("account_id")
|
|
1562
1562
|
.where("id", "=", served.taskId)
|
|
1563
1563
|
.where("org_id", "=", a.orgId)
|
|
@@ -1570,7 +1570,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1570
1570
|
if (networkGrantRefusal(host, { limits }) !== null) {
|
|
1571
1571
|
continue;
|
|
1572
1572
|
}
|
|
1573
|
-
await this.
|
|
1573
|
+
await this.automations.addGrant(t, served.taskId, {
|
|
1574
1574
|
toolKey: `${NETWORK_GRANT_PREFIX}${host}`,
|
|
1575
1575
|
specHash: NETWORK_GRANT_SPEC_HASH,
|
|
1576
1576
|
connectorId: null,
|
|
@@ -1598,7 +1598,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1598
1598
|
.execute();
|
|
1599
1599
|
}
|
|
1600
1600
|
/**
|
|
1601
|
-
* A trial run of
|
|
1601
|
+
* A trial run of an automation (sandbox git credentials spec §7): a push its creator allowed
|
|
1602
1602
|
* for this run (「这次允许」) becomes the task's `git:push:<owner>/<repo>` grant, when
|
|
1603
1603
|
* `gitGrantRefusal` allows it (the org does not forbid it). Never for an ask another account
|
|
1604
1604
|
* decided or one asked of someone else. In the decision's transaction.
|
|
@@ -1613,7 +1613,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1613
1613
|
if (served === null || !served.trial)
|
|
1614
1614
|
return;
|
|
1615
1615
|
const task = await t
|
|
1616
|
-
.selectFrom("
|
|
1616
|
+
.selectFrom("automations")
|
|
1617
1617
|
.select("account_id")
|
|
1618
1618
|
.where("id", "=", served.taskId)
|
|
1619
1619
|
.where("org_id", "=", a.orgId)
|
|
@@ -1622,10 +1622,10 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1622
1622
|
if (task?.account_id !== decidedBy)
|
|
1623
1623
|
return;
|
|
1624
1624
|
const key = gitPushGrantKey(a.git.repo);
|
|
1625
|
-
const { forbiddenTools } = await
|
|
1625
|
+
const { forbiddenTools } = await readAutomationSettings(t, this.config, a.orgId);
|
|
1626
1626
|
if (gitGrantRefusal(key, { forbiddenTools }) !== null)
|
|
1627
1627
|
return;
|
|
1628
|
-
await this.
|
|
1628
|
+
await this.automations.addGrant(t, served.taskId, {
|
|
1629
1629
|
toolKey: key,
|
|
1630
1630
|
specHash: GIT_GRANT_SPEC_HASH,
|
|
1631
1631
|
connectorId: null,
|
|
@@ -2189,7 +2189,7 @@ ApprovalsService = __decorate([
|
|
|
2189
2189
|
__param(2, Inject(EventLog)),
|
|
2190
2190
|
__param(3, Inject(KernelEvents)),
|
|
2191
2191
|
__param(4, Inject(TransactionHost)),
|
|
2192
|
-
__param(5, Inject(
|
|
2192
|
+
__param(5, Inject(AutomationStore)),
|
|
2193
2193
|
__param(6, Inject(ToolRegistry)),
|
|
2194
2194
|
__param(7, Inject(LockService)),
|
|
2195
2195
|
__param(8, Inject(SandboxService)),
|
|
@@ -29,11 +29,11 @@ export declare const BUILTIN: {
|
|
|
29
29
|
readonly GenerateImage: "GenerateImage";
|
|
30
30
|
readonly Platform: "Platform";
|
|
31
31
|
readonly CurrentTime: "CurrentTime";
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
36
|
-
readonly
|
|
32
|
+
readonly AutomationCreate: "AutomationCreate";
|
|
33
|
+
readonly AutomationUpdate: "AutomationUpdate";
|
|
34
|
+
readonly AutomationList: "AutomationList";
|
|
35
|
+
readonly AutomationTargets: "AutomationTargets";
|
|
36
|
+
readonly AutomationDelete: "AutomationDelete";
|
|
37
37
|
};
|
|
38
38
|
export type BuiltinName = (typeof BUILTIN)[keyof typeof BUILTIN];
|
|
39
39
|
/**
|
|
@@ -56,11 +56,11 @@ export declare const BASH_COMPANION_TOOLS: readonly BuiltinName[];
|
|
|
56
56
|
*/
|
|
57
57
|
export declare const SANDBOX_ASK_TOOL_NAMES: ReadonlySet<string>;
|
|
58
58
|
/**
|
|
59
|
-
* The builtins that manage the person's
|
|
59
|
+
* The builtins that manage the person's automations (scheduled tasks spec §11): create and
|
|
60
60
|
* update are fixed asks ({@link R3_FIXED_ASK_TOOL_KEYS}), list, targets and delete only read or
|
|
61
61
|
* narrow.
|
|
62
62
|
*/
|
|
63
|
-
export declare const
|
|
63
|
+
export declare const AUTOMATION_TOOL_NAMES: readonly BuiltinName[];
|
|
64
64
|
/**
|
|
65
65
|
* Every builtin name. Saving an agent checks turned-off builtins against this list, not against
|
|
66
66
|
* what is registered now, so the order the implementations land in never affects a saved
|
|
@@ -69,8 +69,8 @@ export declare const SCHEDULE_TOOL_NAMES: readonly BuiltinName[];
|
|
|
69
69
|
* `SendMessage` and `SubagentHandback` are added by the registry ({@link SUBAGENT_MESSAGE_TOOLS}).
|
|
70
70
|
* `Platform` calls the platform's own operations as the run's person (Platform tool spec).
|
|
71
71
|
* `CurrentTime` reads the clock (the run context carries only the date). `GenerateImage` makes
|
|
72
|
-
* images with the org's `image` purpose model (image generation spec §5.3). The
|
|
73
|
-
* manage the person's
|
|
72
|
+
* images with the org's `image` purpose model (image generation spec §5.3). The automation tools
|
|
73
|
+
* manage the person's automations ({@link AUTOMATION_TOOL_NAMES}).
|
|
74
74
|
*/
|
|
75
75
|
export declare const BUILTIN_TOOL_NAMES: readonly BuiltinName[];
|
|
76
76
|
/** The builtin that loads a skill (added by the registry when the log has a skills catalog). */
|
|
@@ -92,7 +92,7 @@ export declare const SUBAGENT_MESSAGE_TOOLS: ReadonlySet<string>;
|
|
|
92
92
|
/**
|
|
93
93
|
/**
|
|
94
94
|
* Tool keys on the spec 3.6 R3 fixed list ("allowed is not confirmed"): their policy is at least
|
|
95
|
-
* `ask` and remembered grants never let them through. `
|
|
95
|
+
* `ask` and remembered grants never let them through. `AutomationCreate` and `AutomationUpdate` set
|
|
96
96
|
* what a task runs unattended, so a person approves every task an agent creates or widens
|
|
97
97
|
* (scheduled tasks spec §11), never covered by a task grant and refused in an unattended run in
|
|
98
98
|
* `fail` mode. Connector and extension tools express the same rule with
|
|
@@ -101,11 +101,11 @@ export declare const SUBAGENT_MESSAGE_TOOLS: ReadonlySet<string>;
|
|
|
101
101
|
export declare const R3_FIXED_ASK_TOOL_KEYS: ReadonlySet<string>;
|
|
102
102
|
/**
|
|
103
103
|
* Tools a sub-agent never gets (sub-agents spec §5.3, §5.5): `AskUserQuestion` (the person does
|
|
104
|
-
* not see the child), `Deliver` (delivering files is the parent's job) and the
|
|
104
|
+
* not see the child), `Deliver` (delivering files is the parent's job) and the automation tools (a
|
|
105
105
|
* person manages tasks from the conversation they see, never from a child). `Agent` is removed
|
|
106
106
|
* only from a child at `subagents.maxDepth` (agent map spec §4.1, `effectiveDefinition`).
|
|
107
107
|
*/
|
|
108
|
-
export declare const CHILD_REMOVED_TOOLS: readonly ["AskUserQuestion", "Deliver", "
|
|
108
|
+
export declare const CHILD_REMOVED_TOOLS: readonly ["AskUserQuestion", "Deliver", "AutomationCreate", "AutomationUpdate", "AutomationList", "AutomationTargets", "AutomationDelete"];
|
|
109
109
|
/**
|
|
110
110
|
* The builtins every agent has unless it turns them off (tools default-on spec §4), in this
|
|
111
111
|
* order: {@link BUILTIN_TOOL_NAMES} without the ones the registry manages by rule (`ToolSearch`,
|
|
@@ -28,11 +28,11 @@ export const BUILTIN = {
|
|
|
28
28
|
GenerateImage: "GenerateImage",
|
|
29
29
|
Platform: "Platform",
|
|
30
30
|
CurrentTime: "CurrentTime",
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
AutomationCreate: "AutomationCreate",
|
|
32
|
+
AutomationUpdate: "AutomationUpdate",
|
|
33
|
+
AutomationList: "AutomationList",
|
|
34
|
+
AutomationTargets: "AutomationTargets",
|
|
35
|
+
AutomationDelete: "AutomationDelete",
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
38
|
* The builtin tools that run in the conversation's sandbox. `TaskOutput` and `TaskStop` read and
|
|
@@ -75,16 +75,16 @@ export const SANDBOX_ASK_TOOL_NAMES = new Set([
|
|
|
75
75
|
BUILTIN.Deliver,
|
|
76
76
|
]);
|
|
77
77
|
/**
|
|
78
|
-
* The builtins that manage the person's
|
|
78
|
+
* The builtins that manage the person's automations (scheduled tasks spec §11): create and
|
|
79
79
|
* update are fixed asks ({@link R3_FIXED_ASK_TOOL_KEYS}), list, targets and delete only read or
|
|
80
80
|
* narrow.
|
|
81
81
|
*/
|
|
82
|
-
export const
|
|
83
|
-
BUILTIN.
|
|
84
|
-
BUILTIN.
|
|
85
|
-
BUILTIN.
|
|
86
|
-
BUILTIN.
|
|
87
|
-
BUILTIN.
|
|
82
|
+
export const AUTOMATION_TOOL_NAMES = [
|
|
83
|
+
BUILTIN.AutomationCreate,
|
|
84
|
+
BUILTIN.AutomationUpdate,
|
|
85
|
+
BUILTIN.AutomationList,
|
|
86
|
+
BUILTIN.AutomationTargets,
|
|
87
|
+
BUILTIN.AutomationDelete,
|
|
88
88
|
];
|
|
89
89
|
/**
|
|
90
90
|
* Every builtin name. Saving an agent checks turned-off builtins against this list, not against
|
|
@@ -94,8 +94,8 @@ export const SCHEDULE_TOOL_NAMES = [
|
|
|
94
94
|
* `SendMessage` and `SubagentHandback` are added by the registry ({@link SUBAGENT_MESSAGE_TOOLS}).
|
|
95
95
|
* `Platform` calls the platform's own operations as the run's person (Platform tool spec).
|
|
96
96
|
* `CurrentTime` reads the clock (the run context carries only the date). `GenerateImage` makes
|
|
97
|
-
* images with the org's `image` purpose model (image generation spec §5.3). The
|
|
98
|
-
* manage the person's
|
|
97
|
+
* images with the org's `image` purpose model (image generation spec §5.3). The automation tools
|
|
98
|
+
* manage the person's automations ({@link AUTOMATION_TOOL_NAMES}).
|
|
99
99
|
*/
|
|
100
100
|
export const BUILTIN_TOOL_NAMES = [
|
|
101
101
|
BUILTIN.AskUserQuestion,
|
|
@@ -110,7 +110,7 @@ export const BUILTIN_TOOL_NAMES = [
|
|
|
110
110
|
BUILTIN.GenerateImage,
|
|
111
111
|
BUILTIN.Platform,
|
|
112
112
|
BUILTIN.CurrentTime,
|
|
113
|
-
...
|
|
113
|
+
...AUTOMATION_TOOL_NAMES,
|
|
114
114
|
];
|
|
115
115
|
/** The builtin that loads a skill (added by the registry when the log has a skills catalog). */
|
|
116
116
|
export const SKILL_LOAD = BUILTIN.Skill;
|
|
@@ -134,30 +134,30 @@ export const SUBAGENT_MESSAGE_TOOLS = new Set([
|
|
|
134
134
|
/**
|
|
135
135
|
/**
|
|
136
136
|
* Tool keys on the spec 3.6 R3 fixed list ("allowed is not confirmed"): their policy is at least
|
|
137
|
-
* `ask` and remembered grants never let them through. `
|
|
137
|
+
* `ask` and remembered grants never let them through. `AutomationCreate` and `AutomationUpdate` set
|
|
138
138
|
* what a task runs unattended, so a person approves every task an agent creates or widens
|
|
139
139
|
* (scheduled tasks spec §11), never covered by a task grant and refused in an unattended run in
|
|
140
140
|
* `fail` mode. Connector and extension tools express the same rule with
|
|
141
141
|
* `annotations.requiresUserInteraction`.
|
|
142
142
|
*/
|
|
143
143
|
export const R3_FIXED_ASK_TOOL_KEYS = new Set([
|
|
144
|
-
BUILTIN.
|
|
145
|
-
BUILTIN.
|
|
144
|
+
BUILTIN.AutomationCreate,
|
|
145
|
+
BUILTIN.AutomationUpdate,
|
|
146
146
|
]);
|
|
147
147
|
/**
|
|
148
148
|
* Tools a sub-agent never gets (sub-agents spec §5.3, §5.5): `AskUserQuestion` (the person does
|
|
149
|
-
* not see the child), `Deliver` (delivering files is the parent's job) and the
|
|
149
|
+
* not see the child), `Deliver` (delivering files is the parent's job) and the automation tools (a
|
|
150
150
|
* person manages tasks from the conversation they see, never from a child). `Agent` is removed
|
|
151
151
|
* only from a child at `subagents.maxDepth` (agent map spec §4.1, `effectiveDefinition`).
|
|
152
152
|
*/
|
|
153
153
|
export const CHILD_REMOVED_TOOLS = [
|
|
154
154
|
BUILTIN.AskUserQuestion,
|
|
155
155
|
BUILTIN.Deliver,
|
|
156
|
-
BUILTIN.
|
|
157
|
-
BUILTIN.
|
|
158
|
-
BUILTIN.
|
|
159
|
-
BUILTIN.
|
|
160
|
-
BUILTIN.
|
|
156
|
+
BUILTIN.AutomationCreate,
|
|
157
|
+
BUILTIN.AutomationUpdate,
|
|
158
|
+
BUILTIN.AutomationList,
|
|
159
|
+
BUILTIN.AutomationTargets,
|
|
160
|
+
BUILTIN.AutomationDelete,
|
|
161
161
|
];
|
|
162
162
|
/**
|
|
163
163
|
* The builtins every agent has unless it turns them off (tools default-on spec §4), in this
|
|
@@ -194,11 +194,11 @@ export const BUILTIN_TOOL_KINDS = {
|
|
|
194
194
|
[BUILTIN.GenerateImage]: "tool",
|
|
195
195
|
[BUILTIN.Platform]: "tool",
|
|
196
196
|
[BUILTIN.CurrentTime]: "tool",
|
|
197
|
-
[BUILTIN.
|
|
198
|
-
[BUILTIN.
|
|
199
|
-
[BUILTIN.
|
|
200
|
-
[BUILTIN.
|
|
201
|
-
[BUILTIN.
|
|
197
|
+
[BUILTIN.AutomationCreate]: "tool",
|
|
198
|
+
[BUILTIN.AutomationUpdate]: "tool",
|
|
199
|
+
[BUILTIN.AutomationList]: "tool",
|
|
200
|
+
[BUILTIN.AutomationTargets]: "tool",
|
|
201
|
+
[BUILTIN.AutomationDelete]: "tool",
|
|
202
202
|
};
|
|
203
203
|
/**
|
|
204
204
|
* Input fields left out when matching a replayed call with a recorded one (full-run replay), per
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventLog } from "../../conversations/event-log.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type FileDeliveries } from "../../files/deliveries.js";
|
|
3
3
|
import type { BuiltinCallContext } from "../registry.js";
|
|
4
4
|
/**
|
|
5
5
|
* The tool error when the deployment has no object store (or it went away): files cannot be
|
|
@@ -10,8 +10,12 @@ export declare const NO_STORAGE = "File storage is not configured in this deploy
|
|
|
10
10
|
export declare const NO_STORAGE_REASON: string;
|
|
11
11
|
/** What {@link storeArtifacts} needs. */
|
|
12
12
|
export interface ArtifactStoreDeps {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
eventLog: Pick<EventLog, "readDeliveryScope"> & Partial<Pick<EventLog, "publishChanged">>;
|
|
14
|
+
/**
|
|
15
|
+
* The blobs and the one transaction of a delivery (file library spec §4). Absent in test stubs
|
|
16
|
+
* without a store: nothing can be delivered then ({@link NO_STORAGE}).
|
|
17
|
+
*/
|
|
18
|
+
deliveries?: Pick<FileDeliveries, "ensureBlob" | "appendDelivered"> | undefined;
|
|
15
19
|
}
|
|
16
20
|
/** One file to deliver as an artifact. */
|
|
17
21
|
export interface ArtifactFile {
|
|
@@ -50,20 +54,24 @@ export declare const REPEAT_TEXT: (name: string, prior: {
|
|
|
50
54
|
artifactId: string;
|
|
51
55
|
}) => string;
|
|
52
56
|
/**
|
|
53
|
-
* Stores `files` as artifacts of the call's conversation, all or none
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
57
|
+
* Stores `files` as artifacts of the call's conversation, all or none (file library spec §4): the
|
|
58
|
+
* bytes of every file become a ready blob of the org ({@link FileDeliveries.ensureBlob}: an
|
|
59
|
+
* existing blob of the same sha256 is reused with no upload, else a new one is written intent
|
|
60
|
+
* first), then all their `artifact_created` events (the call's run and `callId`, the bytes'
|
|
61
|
+
* sha256, `fileId` = the artifact id, `objectKey` = the blob's key) and their files (owner the
|
|
62
|
+
* conversation's owner, origin `generated` for a `generated/` source path, else `delivered`) are
|
|
63
|
+
* written in one transaction. A blob a deletion claimed in between aborts that transaction, and
|
|
64
|
+
* the bytes are ensured again and the whole unit retried (a bounded number of times). Nothing is
|
|
65
|
+
* cleaned up on failure: a blob may serve other files, and an unreferenced one is the blob sweep's.
|
|
66
|
+
* A store that is not there is the {@link NO_STORAGE} tool error. The conversation's files are
|
|
67
|
+
* announced changed once, when something new was stored.
|
|
60
68
|
*
|
|
61
69
|
* With a run, the same bytes reach the user once per delivery scope (truthful delivery spec §2):
|
|
62
70
|
* a file equal to an earlier file of the call, or a repeat by {@link findRepeat} of the scope's
|
|
63
|
-
* artifacts, is not
|
|
71
|
+
* artifacts, is not stored and comes back with `repeatOf`. Each event's idempotency key is
|
|
64
72
|
* `artifact:<runId>:<boundary>:<sha256>:<lastOfSource>`, so two parallel calls that both saw no
|
|
65
73
|
* repeat compute the same key: the append's row lock and the unique key give the second the
|
|
66
|
-
* first's event
|
|
67
|
-
*
|
|
74
|
+
* first's event (and record no file for it), making that file a repeat of the returned event.
|
|
75
|
+
* No process state.
|
|
68
76
|
*/
|
|
69
77
|
export declare function storeArtifacts(deps: ArtifactStoreDeps, ctx: BuiltinCallContext, files: readonly ArtifactFile[]): Promise<StoredArtifact[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { findRepeat } from "../../conversations/delivery-scope.js";
|
|
4
|
+
import { DeliveryBlobGoneError } from "../../files/deliveries.js";
|
|
4
5
|
import { isStorageUnavailable } from "../../storage/storage.service.js";
|
|
5
6
|
/**
|
|
6
7
|
* The tool error when the deployment has no object store (or it went away): files cannot be
|
|
@@ -9,26 +10,32 @@ import { isStorageUnavailable } from "../../storage/storage.service.js";
|
|
|
9
10
|
export const NO_STORAGE = "File storage is not configured in this deployment, so files cannot be delivered; ask an administrator, or provide the result in your reply instead.";
|
|
10
11
|
/** The same as the "tool unavailable" reason (the kernel adds the final period). */
|
|
11
12
|
export const NO_STORAGE_REASON = NO_STORAGE.slice(0, -1);
|
|
13
|
+
/** How often a delivery whose blob was claimed by a deletion meanwhile is tried again. */
|
|
14
|
+
const BLOB_ATTEMPTS = 3;
|
|
12
15
|
/** The clause that says a file repeats an artifact already delivered in the scope. */
|
|
13
16
|
export const REPEAT_CLAUSE = (prior) => `same content as ${prior.name} (artifact ${prior.artifactId}), already delivered to the user since the person last spoke; no new artifact was created.`;
|
|
14
17
|
/** The result text of a file that repeats an artifact already delivered in the scope. */
|
|
15
18
|
export const REPEAT_TEXT = (name, prior) => `${name} has the ${REPEAT_CLAUSE(prior)}`;
|
|
16
19
|
/**
|
|
17
|
-
* Stores `files` as artifacts of the call's conversation, all or none
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* Stores `files` as artifacts of the call's conversation, all or none (file library spec §4): the
|
|
21
|
+
* bytes of every file become a ready blob of the org ({@link FileDeliveries.ensureBlob}: an
|
|
22
|
+
* existing blob of the same sha256 is reused with no upload, else a new one is written intent
|
|
23
|
+
* first), then all their `artifact_created` events (the call's run and `callId`, the bytes'
|
|
24
|
+
* sha256, `fileId` = the artifact id, `objectKey` = the blob's key) and their files (owner the
|
|
25
|
+
* conversation's owner, origin `generated` for a `generated/` source path, else `delivered`) are
|
|
26
|
+
* written in one transaction. A blob a deletion claimed in between aborts that transaction, and
|
|
27
|
+
* the bytes are ensured again and the whole unit retried (a bounded number of times). Nothing is
|
|
28
|
+
* cleaned up on failure: a blob may serve other files, and an unreferenced one is the blob sweep's.
|
|
29
|
+
* A store that is not there is the {@link NO_STORAGE} tool error. The conversation's files are
|
|
30
|
+
* announced changed once, when something new was stored.
|
|
24
31
|
*
|
|
25
32
|
* With a run, the same bytes reach the user once per delivery scope (truthful delivery spec §2):
|
|
26
33
|
* a file equal to an earlier file of the call, or a repeat by {@link findRepeat} of the scope's
|
|
27
|
-
* artifacts, is not
|
|
34
|
+
* artifacts, is not stored and comes back with `repeatOf`. Each event's idempotency key is
|
|
28
35
|
* `artifact:<runId>:<boundary>:<sha256>:<lastOfSource>`, so two parallel calls that both saw no
|
|
29
36
|
* repeat compute the same key: the append's row lock and the unique key give the second the
|
|
30
|
-
* first's event
|
|
31
|
-
*
|
|
37
|
+
* first's event (and record no file for it), making that file a repeat of the returned event.
|
|
38
|
+
* No process state.
|
|
32
39
|
*/
|
|
33
40
|
export async function storeArtifacts(deps, ctx, files) {
|
|
34
41
|
const hashes = files.map((f) => createHash("sha256").update(f.data).digest("hex"));
|
|
@@ -39,16 +46,23 @@ export async function storeArtifacts(deps, ctx, files) {
|
|
|
39
46
|
}));
|
|
40
47
|
/** Per input: the earlier input of the same call it repeats (with a run), else itself. */
|
|
41
48
|
const firstOf = hashes.map((h, i) => (ctx.runId === undefined ? i : hashes.indexOf(h)));
|
|
42
|
-
|
|
43
|
-
/** The inputs written as events, in the order of `events`, with their generated ids. */
|
|
49
|
+
/** The inputs to write as events, in event order, with their generated ids and blobs. */
|
|
44
50
|
const written = [];
|
|
45
|
-
const events = [];
|
|
46
51
|
let stored = [];
|
|
47
52
|
try {
|
|
53
|
+
const deliveries = deps.deliveries;
|
|
54
|
+
if (deliveries === undefined)
|
|
55
|
+
throw new ToolError(NO_STORAGE);
|
|
48
56
|
const scope = ctx.runId === undefined
|
|
49
57
|
? null
|
|
50
58
|
: await deps.eventLog.readDeliveryScope(ctx.conversationId, ctx.runId);
|
|
51
|
-
const
|
|
59
|
+
const ensure = (i) => {
|
|
60
|
+
const f = files[i];
|
|
61
|
+
return deliveries.ensureBlob(ctx.orgId, hashes[i], f.data, {
|
|
62
|
+
contentType: f.contentType,
|
|
63
|
+
signal: ctx.signal,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
52
66
|
for (const [i, f] of files.entries()) {
|
|
53
67
|
if (firstOf[i] !== i)
|
|
54
68
|
continue;
|
|
@@ -63,46 +77,51 @@ export async function storeArtifacts(deps, ctx, files) {
|
|
|
63
77
|
idemKey = `artifact:${ctx.runId}:${scope.boundary}:${sha256}:${lastOfSource}`;
|
|
64
78
|
}
|
|
65
79
|
const artifactId = randomUUID();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
size: f.data.byteLength,
|
|
70
|
-
signal: ctx.signal,
|
|
71
|
-
});
|
|
72
|
-
uploaded.push(objectKey);
|
|
73
|
-
written.push({ index: i, artifactId, objectKey });
|
|
74
|
-
events.push({
|
|
75
|
-
type: "artifact_created",
|
|
76
|
-
...(ctx.runId !== undefined && { runId: ctx.runId }),
|
|
80
|
+
written.push({
|
|
81
|
+
index: i,
|
|
82
|
+
artifactId,
|
|
77
83
|
...(idemKey !== undefined && { idemKey }),
|
|
78
|
-
|
|
79
|
-
artifactId,
|
|
80
|
-
name: f.name,
|
|
81
|
-
contentType: f.contentType,
|
|
82
|
-
size: f.data.byteLength,
|
|
83
|
-
objectKey,
|
|
84
|
-
sourcePath: f.sourcePath,
|
|
85
|
-
callId: ctx.callId,
|
|
86
|
-
sha256,
|
|
87
|
-
},
|
|
84
|
+
blob: await ensure(i),
|
|
88
85
|
});
|
|
89
86
|
out[i] = { artifactId, name: f.name, size: f.data.byteLength };
|
|
90
87
|
}
|
|
91
|
-
// a call stopped while
|
|
88
|
+
// a call stopped while storing writes no event (its blobs are shared or the sweep's)
|
|
92
89
|
ctx.signal.throwIfAborted();
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
for (let attempt = 1; written.length > 0; attempt++) {
|
|
91
|
+
try {
|
|
92
|
+
stored = await deliveries.appendDelivered(ctx.orgId, ctx.conversationId, written.map((w) => artifactEvent(ctx, files[w.index], w, hashes)), written.map((w) => {
|
|
93
|
+
const f = files[w.index];
|
|
94
|
+
return {
|
|
95
|
+
id: w.artifactId,
|
|
96
|
+
blobId: w.blob.id,
|
|
97
|
+
name: f.name,
|
|
98
|
+
contentType: f.contentType,
|
|
99
|
+
size: f.data.byteLength,
|
|
100
|
+
origin: f.sourcePath.startsWith("generated/") ? "generated" : "delivered",
|
|
101
|
+
sourcePath: f.sourcePath,
|
|
102
|
+
};
|
|
103
|
+
}));
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
if (!(e instanceof DeliveryBlobGoneError) || attempt >= BLOB_ATTEMPTS)
|
|
108
|
+
throw e;
|
|
109
|
+
// a deletion claimed the blob after it was ensured: ensure those bytes again
|
|
110
|
+
for (const w of written) {
|
|
111
|
+
if (w.blob.id === e.blobId)
|
|
112
|
+
w.blob = await ensure(w.index);
|
|
113
|
+
}
|
|
114
|
+
ctx.signal.throwIfAborted();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
95
117
|
}
|
|
96
118
|
catch (e) {
|
|
97
|
-
// no event references them: remove what was uploaded (best effort)
|
|
98
|
-
await removeObjects(deps, ctx, uploaded);
|
|
99
119
|
if (isStorageUnavailable(e))
|
|
100
120
|
throw new ToolError(NO_STORAGE);
|
|
101
121
|
throw e;
|
|
102
122
|
}
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
const unused = [];
|
|
123
|
+
// an event that is not the one generated (a parallel call appended the same key first): the
|
|
124
|
+
// file repeats that event
|
|
106
125
|
let fresh = false;
|
|
107
126
|
for (const [j, w] of written.entries()) {
|
|
108
127
|
const ev = stored[j];
|
|
@@ -111,10 +130,8 @@ export async function storeArtifacts(deps, ctx, files) {
|
|
|
111
130
|
fresh = true;
|
|
112
131
|
continue;
|
|
113
132
|
}
|
|
114
|
-
unused.push(w.objectKey);
|
|
115
133
|
setRepeat(out, w.index, payload);
|
|
116
134
|
}
|
|
117
|
-
await removeObjects(deps, ctx, unused);
|
|
118
135
|
// a file equal to an earlier one of the call repeats whatever that one became
|
|
119
136
|
for (const [i, first] of firstOf.entries()) {
|
|
120
137
|
if (first === i)
|
|
@@ -126,6 +143,25 @@ export async function storeArtifacts(deps, ctx, files) {
|
|
|
126
143
|
await deps.eventLog.publishChanged?.(ctx.conversationId, "files");
|
|
127
144
|
return out;
|
|
128
145
|
}
|
|
146
|
+
/** The `artifact_created` event of one written file. */
|
|
147
|
+
function artifactEvent(ctx, f, w, hashes) {
|
|
148
|
+
return {
|
|
149
|
+
type: "artifact_created",
|
|
150
|
+
...(ctx.runId !== undefined && { runId: ctx.runId }),
|
|
151
|
+
...(w.idemKey !== undefined && { idemKey: w.idemKey }),
|
|
152
|
+
payload: {
|
|
153
|
+
artifactId: w.artifactId,
|
|
154
|
+
fileId: w.artifactId,
|
|
155
|
+
name: f.name,
|
|
156
|
+
contentType: f.contentType,
|
|
157
|
+
size: f.data.byteLength,
|
|
158
|
+
objectKey: w.blob.objectKey,
|
|
159
|
+
sourcePath: f.sourcePath,
|
|
160
|
+
callId: ctx.callId,
|
|
161
|
+
sha256: hashes[w.index],
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
129
165
|
function setRepeat(out, i, prior) {
|
|
130
166
|
const cur = out[i];
|
|
131
167
|
out[i] = {
|
|
@@ -135,9 +171,3 @@ function setRepeat(out, i, prior) {
|
|
|
135
171
|
repeatOf: { artifactId: prior.artifactId, name: prior.name },
|
|
136
172
|
};
|
|
137
173
|
}
|
|
138
|
-
/** Deletes `keys` from the org's kernel store, best effort (a failure leaves an orphan object). */
|
|
139
|
-
async function removeObjects(deps, ctx, keys) {
|
|
140
|
-
await Promise.all(keys.map((key) => Promise.resolve()
|
|
141
|
-
.then(() => deps.storage.kernel(ctx.orgId).delete(key))
|
|
142
|
-
.catch(() => { })));
|
|
143
|
-
}
|