@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,4 +1,5 @@
|
|
|
1
1
|
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { AutomationStore } from "../../automations/store.js";
|
|
2
3
|
import { BackgroundTaskFinisher } from "../../background/finish.js";
|
|
3
4
|
import { BackgroundTaskStopper } from "../../background/stop.js";
|
|
4
5
|
import { BackgroundTaskStore } from "../../background/store.js";
|
|
@@ -6,6 +7,8 @@ import { AttachmentsService } from "../../conversations/attachments.service.js";
|
|
|
6
7
|
import { EventLog } from "../../conversations/event-log.js";
|
|
7
8
|
import { ConversationDevices } from "../../devices/conversation-devices.js";
|
|
8
9
|
import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
|
|
10
|
+
import { FileDeliveries } from "../../files/deliveries.js";
|
|
11
|
+
import { ReferencedFiles } from "../../files/referenced-files.js";
|
|
9
12
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
10
13
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
11
14
|
import { ModelImages } from "../../models/images.js";
|
|
@@ -20,11 +23,10 @@ import { ProviderRegistry } from "../../runtime/providers.js";
|
|
|
20
23
|
import { StepLog } from "../../runtime/step-log.js";
|
|
21
24
|
import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
|
|
22
25
|
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
23
|
-
import { ScheduledTaskStore } from "../../schedules/store.js";
|
|
24
26
|
import { StorageService } from "../../storage/storage.service.js";
|
|
25
27
|
import { ToolOutputs } from "../outputs.js";
|
|
26
28
|
import type { BuiltinCallContext, BuiltinTool } from "../registry.js";
|
|
27
|
-
import {
|
|
29
|
+
import { AutomationToolsPort, AutomationUpdates } from "./automations.js";
|
|
28
30
|
import { WebPages } from "./web/index.js";
|
|
29
31
|
/**
|
|
30
32
|
* The kernel's builtin tools, built once from the injected services (their specs: names,
|
|
@@ -43,17 +45,21 @@ export declare class BuiltinTools {
|
|
|
43
45
|
sealedInputs: SealedInputs,
|
|
44
46
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
45
47
|
fileRefs: FileRefs,
|
|
46
|
-
/** The
|
|
47
|
-
|
|
48
|
-
/** `
|
|
49
|
-
|
|
50
|
-
/** The task service, bound by `
|
|
51
|
-
|
|
48
|
+
/** The automation tools read tasks and grants; their writes go through the task service. */
|
|
49
|
+
automationStore: AutomationStore,
|
|
50
|
+
/** `AutomationUpdate`'s write: its field change and grant changes in one transaction. */
|
|
51
|
+
automationUpdates: AutomationUpdates,
|
|
52
|
+
/** The task service, bound by `AutomationsModule` at start (a registration port: no cycle). */
|
|
53
|
+
automationPort: AutomationToolsPort,
|
|
52
54
|
/** `GenerateImage`: the image calls, and the image model's availability per listing. */
|
|
53
55
|
images: ModelImages, providers: ProviderRegistry,
|
|
54
56
|
/** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
|
|
55
57
|
/** The managed sandbox route's device context writer (permission context replay spec B3). */
|
|
56
|
-
managedDeviceContext: ManagedDeviceContextRecorder,
|
|
58
|
+
managedDeviceContext: ManagedDeviceContextRecorder,
|
|
59
|
+
/** The library files a conversation refers to (`Read` / `Deliver` by id, `FetchAttachment`). */
|
|
60
|
+
referencedFiles: ReferencedFiles,
|
|
61
|
+
/** `Deliver` and `GenerateImage` store files as library files on shared blobs. */
|
|
62
|
+
deliveries: FileDeliveries, now?: () => number);
|
|
57
63
|
/** The builtin tools, in a fixed order. */
|
|
58
64
|
list(): readonly BuiltinTool[];
|
|
59
65
|
}
|
|
@@ -8,6 +8,7 @@ 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, Optional } from "@nestjs/common";
|
|
11
|
+
import { AutomationStore } from "../../automations/store.js";
|
|
11
12
|
import { BackgroundTaskFinisher } from "../../background/finish.js";
|
|
12
13
|
import { BackgroundTaskStopper } from "../../background/stop.js";
|
|
13
14
|
import { BackgroundTaskStore } from "../../background/store.js";
|
|
@@ -19,6 +20,8 @@ import { ConversationDevices } from "../../devices/conversation-devices.js";
|
|
|
19
20
|
import { ApiError } from "../../errors.js";
|
|
20
21
|
import { ExtensionHost } from "../../extensions/host.js";
|
|
21
22
|
import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
|
|
23
|
+
import { FileDeliveries } from "../../files/deliveries.js";
|
|
24
|
+
import { ReferencedFiles } from "../../files/referenced-files.js";
|
|
22
25
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
23
26
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
24
27
|
import { KERNEL_LOGGER } from "../../infra/tokens.js";
|
|
@@ -35,18 +38,17 @@ import { conversationTimeZone, RUN_CONTEXT_CLOCK } from "../../runtime/run-conte
|
|
|
35
38
|
import { StepLog } from "../../runtime/step-log.js";
|
|
36
39
|
import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
|
|
37
40
|
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
38
|
-
import { ScheduledTaskStore } from "../../schedules/store.js";
|
|
39
41
|
import { StorageService } from "../../storage/storage.service.js";
|
|
40
42
|
import { ToolOutputs } from "../outputs.js";
|
|
41
43
|
import { agentTool } from "./agent.js";
|
|
42
44
|
import { askUserTool } from "./ask-user.js";
|
|
45
|
+
import { AutomationToolsPort, AutomationUpdates, automationTools } from "./automations.js";
|
|
43
46
|
import { currentTimeTool } from "./current-time.js";
|
|
44
47
|
import { handbackTool } from "./handback.js";
|
|
45
48
|
import { generateImageTool } from "./image/index.js";
|
|
46
49
|
import { platformTool } from "./platform.js";
|
|
47
50
|
import { readToolOutputTool } from "./read-tool-output.js";
|
|
48
51
|
import { sandboxTools } from "./sandbox/index.js";
|
|
49
|
-
import { ScheduleToolsPort, ScheduleUpdates, scheduleTools } from "./schedules.js";
|
|
50
52
|
import { sendMessageTool } from "./send-message.js";
|
|
51
53
|
import { skillLoadTool } from "./skill-load.js";
|
|
52
54
|
import { toolSearchTool } from "./tool-search.js";
|
|
@@ -66,17 +68,21 @@ let BuiltinTools = class BuiltinTools {
|
|
|
66
68
|
sealedInputs,
|
|
67
69
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
68
70
|
fileRefs,
|
|
69
|
-
/** The
|
|
70
|
-
|
|
71
|
-
/** `
|
|
72
|
-
|
|
73
|
-
/** The task service, bound by `
|
|
74
|
-
|
|
71
|
+
/** The automation tools read tasks and grants; their writes go through the task service. */
|
|
72
|
+
automationStore,
|
|
73
|
+
/** `AutomationUpdate`'s write: its field change and grant changes in one transaction. */
|
|
74
|
+
automationUpdates,
|
|
75
|
+
/** The task service, bound by `AutomationsModule` at start (a registration port: no cycle). */
|
|
76
|
+
automationPort,
|
|
75
77
|
/** `GenerateImage`: the image calls, and the image model's availability per listing. */
|
|
76
78
|
images, providers,
|
|
77
79
|
/** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
|
|
78
80
|
/** The managed sandbox route's device context writer (permission context replay spec B3). */
|
|
79
|
-
managedDeviceContext,
|
|
81
|
+
managedDeviceContext,
|
|
82
|
+
/** The library files a conversation refers to (`Read` / `Deliver` by id, `FetchAttachment`). */
|
|
83
|
+
referencedFiles,
|
|
84
|
+
/** `Deliver` and `GenerateImage` store files as library files on shared blobs. */
|
|
85
|
+
deliveries, now) {
|
|
80
86
|
// `Read` beyond the device (vision-read design §1): files by id, the vision read with its
|
|
81
87
|
// hooks (as the WebFetch extraction), the stored copies and the chat model's capabilities
|
|
82
88
|
const vision = { purposes, eventLog, stepLog, config, log, hooks: host?.hooks };
|
|
@@ -86,7 +92,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
86
92
|
return db.db;
|
|
87
93
|
},
|
|
88
94
|
attachments,
|
|
89
|
-
|
|
95
|
+
files: referencedFiles,
|
|
90
96
|
},
|
|
91
97
|
reads: attachments,
|
|
92
98
|
vision,
|
|
@@ -101,8 +107,9 @@ let BuiltinTools = class BuiltinTools {
|
|
|
101
107
|
inTree: async (root, id) => id !== root && (await conversationAncestors(db.db, id)).includes(root),
|
|
102
108
|
childrenOf: (orgId, conversationId) => readChildAgents(db.db, orgId, conversationId),
|
|
103
109
|
},
|
|
104
|
-
attachments,
|
|
110
|
+
attachments: referencedFiles,
|
|
105
111
|
storage,
|
|
112
|
+
deliveries,
|
|
106
113
|
eventLog,
|
|
107
114
|
config,
|
|
108
115
|
log,
|
|
@@ -126,7 +133,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
126
133
|
config,
|
|
127
134
|
sandbox,
|
|
128
135
|
devices,
|
|
129
|
-
attachments,
|
|
136
|
+
attachments: referencedFiles,
|
|
130
137
|
eventLog,
|
|
131
138
|
log,
|
|
132
139
|
managedDeviceContext,
|
|
@@ -150,12 +157,14 @@ let BuiltinTools = class BuiltinTools {
|
|
|
150
157
|
providers,
|
|
151
158
|
storage,
|
|
152
159
|
eventLog,
|
|
160
|
+
deliveries,
|
|
153
161
|
stepLog,
|
|
154
162
|
config,
|
|
155
163
|
log,
|
|
156
164
|
hooks: host?.hooks,
|
|
157
165
|
db,
|
|
158
166
|
attachments,
|
|
167
|
+
files: referencedFiles,
|
|
159
168
|
sandbox: sandboxDeps,
|
|
160
169
|
}),
|
|
161
170
|
// the platform's own operations and docs, as the run's person (Platform tool spec)
|
|
@@ -211,13 +220,13 @@ let BuiltinTools = class BuiltinTools {
|
|
|
211
220
|
now: now ?? Date.now,
|
|
212
221
|
timeZoneOf: ({ orgId, conversationId }) => conversationTimeZone(db.db, orgId, conversationId),
|
|
213
222
|
}),
|
|
214
|
-
// the person's
|
|
215
|
-
...
|
|
223
|
+
// the person's automations (scheduled tasks spec §11)
|
|
224
|
+
...automationTools({
|
|
216
225
|
db: () => db.db,
|
|
217
226
|
config,
|
|
218
|
-
store:
|
|
219
|
-
service: () =>
|
|
220
|
-
updates:
|
|
227
|
+
store: automationStore,
|
|
228
|
+
service: () => automationPort.get(),
|
|
229
|
+
updates: automationUpdates,
|
|
221
230
|
timeZoneOf: (orgId, conversationId) => conversationTimeZone(db.db, orgId, conversationId),
|
|
222
231
|
now: now ?? Date.now,
|
|
223
232
|
}),
|
|
@@ -252,14 +261,16 @@ BuiltinTools = __decorate([
|
|
|
252
261
|
__param(19, Inject(AgentDocs)),
|
|
253
262
|
__param(20, Inject(SealedInputs)),
|
|
254
263
|
__param(21, Inject(FileRefs)),
|
|
255
|
-
__param(22, Inject(
|
|
256
|
-
__param(23, Inject(
|
|
257
|
-
__param(24, Inject(
|
|
264
|
+
__param(22, Inject(AutomationStore)),
|
|
265
|
+
__param(23, Inject(AutomationUpdates)),
|
|
266
|
+
__param(24, Inject(AutomationToolsPort)),
|
|
258
267
|
__param(25, Inject(ModelImages)),
|
|
259
268
|
__param(26, Inject(ProviderRegistry)),
|
|
260
269
|
__param(27, Inject(ManagedDeviceContextRecorder)),
|
|
261
|
-
__param(28,
|
|
262
|
-
__param(
|
|
270
|
+
__param(28, Inject(ReferencedFiles)),
|
|
271
|
+
__param(29, Inject(FileDeliveries)),
|
|
272
|
+
__param(30, Optional()),
|
|
273
|
+
__param(30, Inject(RUN_CONTEXT_CLOCK))
|
|
263
274
|
], BuiltinTools);
|
|
264
275
|
export { BuiltinTools };
|
|
265
276
|
/**
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { AttachmentsService } from "../../conversations/attachments.service.js";
|
|
2
|
+
import type { ReferencedFiles } from "../../files/referenced-files.js";
|
|
2
3
|
import type { KernelDb } from "../../infra/database/kernel-db.js";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A file of the conversation by id: a library file the conversation set refers to (an upload, a
|
|
6
|
+
* delivery or a generated image) or a `read` copy (an image a tool showed the agent).
|
|
7
|
+
*/
|
|
5
8
|
export interface ConversationFile {
|
|
9
|
+
/** `attachment`: an upload or a `read` copy; `artifact`: a delivered or generated file. */
|
|
6
10
|
kind: "attachment" | "artifact";
|
|
7
11
|
id: string;
|
|
8
12
|
/**
|
|
@@ -10,13 +14,14 @@ export interface ConversationFile {
|
|
|
10
14
|
* `Read` of a copy that is already the calling conversation's needs no new copy.
|
|
11
15
|
*/
|
|
12
16
|
readCopyOf?: string;
|
|
17
|
+
/** The owner of a library file; absent for a `read` copy. */
|
|
18
|
+
accountId?: string;
|
|
13
19
|
name: string;
|
|
14
20
|
contentType: string;
|
|
15
21
|
size: number;
|
|
16
22
|
/**
|
|
17
|
-
* Reads the bytes, at most `maxBytes` of them when given (the head of a larger file:
|
|
18
|
-
*
|
|
19
|
-
* {@link discard}, exactly once: an attachment holds its stream.
|
|
23
|
+
* Reads the bytes, at most `maxBytes` of them when given (the head of a larger file: the stream
|
|
24
|
+
* is cancelled there). Call it, or {@link discard}, exactly once: the lookup holds the stream.
|
|
20
25
|
*/
|
|
21
26
|
open(opts?: {
|
|
22
27
|
maxBytes?: number;
|
|
@@ -26,23 +31,28 @@ export interface ConversationFile {
|
|
|
26
31
|
}
|
|
27
32
|
export interface ConversationFileDeps {
|
|
28
33
|
db: Pick<KernelDb, "selectFrom">;
|
|
34
|
+
/** The `read` copies. */
|
|
29
35
|
attachments: Pick<AttachmentsService, "openForConversation">;
|
|
30
|
-
|
|
36
|
+
/** The library files the conversations refer to, and their bytes. */
|
|
37
|
+
files: Pick<ReferencedFiles, "referenced" | "referencedBelow" | "open" | "head">;
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
|
-
* A file of the conversation by id, always inside `orgId
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Anything else (a
|
|
38
|
-
*
|
|
40
|
+
* A file of the conversation by id, always inside `orgId` (file library spec §2, §5): a library
|
|
41
|
+
* file referred to (`conversation_files`) by the conversation, by its root, or by a sub-agent
|
|
42
|
+
* conversation below the conversation (so a parent reaches an image its sub-agent's tool returned;
|
|
43
|
+
* tool result images design §5), else a `read` copy bound to one of them (this lookup is the
|
|
44
|
+
* model's, vision-read design §1.1). Anything else (a library file the person never attached, a
|
|
45
|
+
* sibling's or another tree's, another org's, a deleted file, bytes gone or replaced, an id that is
|
|
46
|
+
* not a UUID) is `null`. A library file's size and type come from its rows and its bytes are
|
|
47
|
+
* checked by a HEAD; they are opened only when {@link ConversationFile.open} is called. Storage
|
|
48
|
+
* errors are thrown as they are. `signal` aborts the storage reads.
|
|
39
49
|
*/
|
|
40
50
|
export declare function findConversationFile(deps: ConversationFileDeps, q: {
|
|
41
51
|
orgId: string;
|
|
42
52
|
conversationId: string;
|
|
43
53
|
rootConversationId: string;
|
|
44
54
|
id: string;
|
|
45
|
-
/** The most bytes {@link ConversationFile.open} may be asked for (
|
|
55
|
+
/** The most bytes {@link ConversationFile.open} may be asked for (a range read). */
|
|
46
56
|
maxBytes?: number;
|
|
47
57
|
signal?: AbortSignal;
|
|
48
58
|
}): Promise<ConversationFile | null>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** Lower-case or upper-case UUIDs: attachment and artifact ids. */
|
|
1
|
+
/** Lower-case or upper-case UUIDs: file and `read` copy ids. */
|
|
3
2
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4
3
|
/**
|
|
5
4
|
* The bytes of `body`, at most `maxBytes` (the stream is cancelled once that many are read: a
|
|
@@ -55,108 +54,88 @@ async function isBelow(db, orgId, candidate, ancestor) {
|
|
|
55
54
|
}
|
|
56
55
|
return false;
|
|
57
56
|
}
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
* in `orgId`; null when there is none.
|
|
61
|
-
*/
|
|
62
|
-
async function ownerOf(db, orgId, id) {
|
|
57
|
+
/** The conversation a ready `read` copy of this id is bound to, in `orgId`; null when none. */
|
|
58
|
+
async function readCopyOwner(db, orgId, id) {
|
|
63
59
|
const att = await db
|
|
64
60
|
.selectFrom("attachments")
|
|
65
|
-
.select(
|
|
61
|
+
.select("conversation_id")
|
|
66
62
|
.where("id", "=", id)
|
|
67
63
|
.where("org_id", "=", orgId)
|
|
68
64
|
.where("status", "=", "ready")
|
|
69
|
-
.where("purpose", "
|
|
65
|
+
.where("purpose", "=", "read")
|
|
70
66
|
.executeTakeFirst();
|
|
71
|
-
|
|
72
|
-
return { conversationId: att.conversation_id, purpose: att.purpose };
|
|
73
|
-
const ev = await db
|
|
74
|
-
.selectFrom("conversation_events as e")
|
|
75
|
-
.innerJoin("conversations as c", "c.id", "e.conversation_id")
|
|
76
|
-
.select("e.conversation_id")
|
|
77
|
-
.where("c.org_id", "=", orgId)
|
|
78
|
-
.where("e.type", "=", "artifact_created")
|
|
79
|
-
.where(sql `e.payload->>'artifactId'`, "=", id)
|
|
80
|
-
.limit(1)
|
|
81
|
-
.executeTakeFirst();
|
|
82
|
-
return ev ? { conversationId: ev.conversation_id, purpose: "artifact" } : null;
|
|
67
|
+
return att?.conversation_id ?? null;
|
|
83
68
|
}
|
|
84
69
|
/**
|
|
85
|
-
* A file of the conversation by id, always inside `orgId
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* Anything else (a
|
|
90
|
-
*
|
|
70
|
+
* A file of the conversation by id, always inside `orgId` (file library spec §2, §5): a library
|
|
71
|
+
* file referred to (`conversation_files`) by the conversation, by its root, or by a sub-agent
|
|
72
|
+
* conversation below the conversation (so a parent reaches an image its sub-agent's tool returned;
|
|
73
|
+
* tool result images design §5), else a `read` copy bound to one of them (this lookup is the
|
|
74
|
+
* model's, vision-read design §1.1). Anything else (a library file the person never attached, a
|
|
75
|
+
* sibling's or another tree's, another org's, a deleted file, bytes gone or replaced, an id that is
|
|
76
|
+
* not a UUID) is `null`. A library file's size and type come from its rows and its bytes are
|
|
77
|
+
* checked by a HEAD; they are opened only when {@link ConversationFile.open} is called. Storage
|
|
78
|
+
* errors are thrown as they are. `signal` aborts the storage reads.
|
|
91
79
|
*/
|
|
92
80
|
export async function findConversationFile(deps, q) {
|
|
93
81
|
if (!UUID.test(q.id))
|
|
94
82
|
return null;
|
|
95
83
|
const id = q.id.toLowerCase();
|
|
96
84
|
const conversations = [...new Set([q.conversationId, q.rootConversationId])];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const opened = await deps.attachments.openForConversation(q.orgId, conversationId, id, {
|
|
107
|
-
purposes: ["chat", "read"],
|
|
108
|
-
...(q.maxBytes !== undefined && { maxBytes: q.maxBytes }),
|
|
109
|
-
...(q.signal !== undefined && { signal: q.signal }),
|
|
110
|
-
});
|
|
111
|
-
if (opened === null)
|
|
112
|
-
continue;
|
|
85
|
+
const files = deps.files;
|
|
86
|
+
// the conversation and its root first; only on a miss the sub-agents below the conversation
|
|
87
|
+
let refs = (await files.referenced(q.orgId, conversations, [id])).sort(attachedFirst);
|
|
88
|
+
if (refs.length === 0)
|
|
89
|
+
refs = await files.referencedBelow(q.orgId, q.conversationId, id);
|
|
90
|
+
const file = refs[0];
|
|
91
|
+
if (file !== undefined) {
|
|
92
|
+
if ((await files.head(q.orgId, file)) === null)
|
|
93
|
+
return null;
|
|
113
94
|
return {
|
|
114
|
-
|
|
95
|
+
// an upload, or a delivered file sent into this conversation set, is an attachment here
|
|
96
|
+
kind: file.role === "attached" || file.sourcePath === null ? "attachment" : "artifact",
|
|
115
97
|
id,
|
|
116
|
-
|
|
117
|
-
name:
|
|
118
|
-
contentType:
|
|
119
|
-
size:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
98
|
+
accountId: file.accountId,
|
|
99
|
+
name: file.name,
|
|
100
|
+
contentType: file.contentType,
|
|
101
|
+
size: file.blob.size,
|
|
102
|
+
async open(opts) {
|
|
103
|
+
const max = opts?.maxBytes ?? q.maxBytes;
|
|
104
|
+
// only a larger object is ranged (a range on an empty object is unsatisfiable)
|
|
105
|
+
const got = await files.open(q.orgId, file, {
|
|
106
|
+
...(q.signal !== undefined && { signal: q.signal }),
|
|
107
|
+
...(max !== undefined && file.blob.size > max && { range: { start: 0, end: max - 1 } }),
|
|
108
|
+
});
|
|
109
|
+
if (got === null)
|
|
110
|
+
throw new Error(`file ${id} is no longer available`);
|
|
111
|
+
return bytesOf(got.body, max);
|
|
112
|
+
},
|
|
113
|
+
discard: async () => { },
|
|
123
114
|
};
|
|
124
115
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
.where("e.conversation_id", "in", conversations)
|
|
131
|
-
.where("e.type", "=", "artifact_created")
|
|
132
|
-
.where(sql `e.payload->>'artifactId'`, "=", id)
|
|
133
|
-
.limit(1)
|
|
134
|
-
.executeTakeFirst();
|
|
135
|
-
if (!row)
|
|
116
|
+
const owner = await readCopyOwner(deps.db, q.orgId, id);
|
|
117
|
+
if (owner === null)
|
|
118
|
+
return null;
|
|
119
|
+
if (!conversations.includes(owner) &&
|
|
120
|
+
!(await isBelow(deps.db, q.orgId, owner, q.conversationId))) {
|
|
136
121
|
return null;
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
122
|
+
}
|
|
123
|
+
const opened = await deps.attachments.openForConversation(q.orgId, owner, id, {
|
|
124
|
+
...(q.maxBytes !== undefined && { maxBytes: q.maxBytes }),
|
|
125
|
+
...(q.signal !== undefined && { signal: q.signal }),
|
|
126
|
+
});
|
|
127
|
+
if (opened === null)
|
|
141
128
|
return null;
|
|
142
129
|
return {
|
|
143
|
-
kind: "
|
|
130
|
+
kind: "attachment",
|
|
144
131
|
id,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const ranged = max !== undefined && head.size > max;
|
|
152
|
-
const got = await store.get(a.objectKey, {
|
|
153
|
-
...(q.signal !== undefined && { signal: q.signal }),
|
|
154
|
-
...(ranged && { range: { start: 0, end: max - 1 } }),
|
|
155
|
-
});
|
|
156
|
-
if (got === null)
|
|
157
|
-
throw new Error(`artifact ${id} is no longer available`);
|
|
158
|
-
return bytesOf(got.body, max);
|
|
159
|
-
},
|
|
160
|
-
discard: async () => { },
|
|
132
|
+
readCopyOf: owner,
|
|
133
|
+
name: opened.name,
|
|
134
|
+
contentType: opened.contentType,
|
|
135
|
+
size: opened.size,
|
|
136
|
+
open: (opts) => bytesOf(opened.body, opts?.maxBytes),
|
|
137
|
+
discard: () => opened.body.cancel().catch(() => { }),
|
|
161
138
|
};
|
|
162
139
|
}
|
|
140
|
+
/** References of one file across a conversation set: an `attached` one first. */
|
|
141
|
+
const attachedFirst = (a, b) => (a.role === "attached" ? 0 : 1) - (b.role === "attached" ? 0 : 1);
|
|
@@ -2,6 +2,7 @@ import { type ImageMediaType, type Logger, type ToolSpec } from "@capybara-hq/pl
|
|
|
2
2
|
import type { AttachmentsService } from "../../../conversations/attachments.service.js";
|
|
3
3
|
import type { EventLog } from "../../../conversations/event-log.js";
|
|
4
4
|
import type { DeviceUnusableReason } from "../../../devices/conversation-devices.js";
|
|
5
|
+
import type { FileDeliveries } from "../../../files/deliveries.js";
|
|
5
6
|
import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
|
|
6
7
|
import type { KernelDb } from "../../../infra/database/kernel-db.js";
|
|
7
8
|
import { type ImageInputCaps } from "../../../models/image-usable.js";
|
|
@@ -12,6 +13,7 @@ import { type ProviderRegistry } from "../../../runtime/providers.js";
|
|
|
12
13
|
import type { StepLog } from "../../../runtime/step-log.js";
|
|
13
14
|
import type { StorageService } from "../../../storage/storage.service.js";
|
|
14
15
|
import type { BuiltinTool } from "../../registry.js";
|
|
16
|
+
import { type ConversationFileDeps } from "../conversation-files.js";
|
|
15
17
|
import { type SandboxToolDeps } from "../sandbox/common.js";
|
|
16
18
|
/** The listed spec for an org whose image model accepts `caps` (pure; `n` and references drop or cap). */
|
|
17
19
|
export declare function generateImageSpec(caps: ImageInputCaps, standardPixels: number): ToolSpec;
|
|
@@ -33,7 +35,9 @@ export interface GenerateImageDeps {
|
|
|
33
35
|
purposes: Pick<ModelPurposesService, "resolve">;
|
|
34
36
|
providers: Pick<ProviderRegistry, "resolve">;
|
|
35
37
|
storage: Pick<StorageService, "kernel" | "available">;
|
|
36
|
-
eventLog: Pick<EventLog, "
|
|
38
|
+
eventLog: Pick<EventLog, "notify" | "readDeliveryScope"> & Partial<Pick<EventLog, "publishChanged">>;
|
|
39
|
+
/** The images' blobs and their delivery transaction ({@link storeArtifacts}). */
|
|
40
|
+
deliveries: Pick<FileDeliveries, "ensureBlob" | "appendDelivered">;
|
|
37
41
|
stepLog: Pick<StepLog, "appendCounted" | "appendReported" | "appendAudited">;
|
|
38
42
|
config: Pick<KernelConfigService, "get">;
|
|
39
43
|
log: Pick<Logger, "warn">;
|
|
@@ -42,6 +46,8 @@ export interface GenerateImageDeps {
|
|
|
42
46
|
/** The artifact lookup of `reference_images`. */
|
|
43
47
|
db: Pick<KernelDb, "selectFrom">;
|
|
44
48
|
attachments: Pick<AttachmentsService, "openForConversation">;
|
|
49
|
+
/** The library files of `reference_images` (attached or delivered in the conversation set). */
|
|
50
|
+
files: ConversationFileDeps["files"];
|
|
45
51
|
/** The device copy of `file_path` (the sandbox tools' own dependencies). */
|
|
46
52
|
sandbox: SandboxToolDeps;
|
|
47
53
|
}
|
|
@@ -302,7 +302,7 @@ async function resolveReferences(deps, ctx, ids) {
|
|
|
302
302
|
const out = [];
|
|
303
303
|
for (const [k, id] of ids.entries()) {
|
|
304
304
|
try {
|
|
305
|
-
const found = await findConversationFile({ db: deps.db, attachments: deps.attachments,
|
|
305
|
+
const found = await findConversationFile({ db: deps.db, attachments: deps.attachments, files: deps.files }, { orgId: ctx.orgId, conversationId: ctx.conversationId, rootConversationId: root, id });
|
|
306
306
|
if (found === null)
|
|
307
307
|
throw new ToolError(unknownReferenceText(k));
|
|
308
308
|
const mediaType = found.contentType.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
@@ -4,9 +4,10 @@ import type { BackgroundTaskStopper } from "../../../background/stop.js";
|
|
|
4
4
|
import type { BackgroundTaskStore } from "../../../background/store.js";
|
|
5
5
|
import type { KernelConfig } from "../../../config/schema.js";
|
|
6
6
|
import type { ChildAgent } from "../../../conversations/agent-tree.js";
|
|
7
|
-
import type { AttachmentsService } from "../../../conversations/attachments.service.js";
|
|
8
7
|
import type { EventLog } from "../../../conversations/event-log.js";
|
|
9
8
|
import { type ConversationDevices, type DeviceUnusableReason } from "../../../devices/conversation-devices.js";
|
|
9
|
+
import type { FileDeliveries } from "../../../files/deliveries.js";
|
|
10
|
+
import type { ReferencedFiles } from "../../../files/referenced-files.js";
|
|
10
11
|
import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
|
|
11
12
|
import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
|
|
12
13
|
import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
|
|
@@ -50,8 +51,11 @@ export interface SandboxToolDeps {
|
|
|
50
51
|
finisher: Pick<BackgroundTaskFinisher, "finish">;
|
|
51
52
|
stopper: Pick<BackgroundTaskStopper, "stop">;
|
|
52
53
|
};
|
|
53
|
-
|
|
54
|
+
/** The files sent into a conversation that `FetchAttachment` copies (file library). */
|
|
55
|
+
attachments: Pick<ReferencedFiles, "listForConversation" | "openForConversation">;
|
|
54
56
|
storage: Pick<StorageService, "kernel" | "deployment" | "available">;
|
|
57
|
+
/** `Deliver`'s blobs and delivery transaction (file library spec §4); absent in test stubs. */
|
|
58
|
+
deliveries?: Pick<FileDeliveries, "ensureBlob" | "appendDelivered">;
|
|
55
59
|
/**
|
|
56
60
|
* `readDeliveryScope`: `Deliver`'s delivery scope (truthful delivery spec §2). `publishChanged`:
|
|
57
61
|
* `Deliver` announces `changed: files` (UI refresh B).
|
|
@@ -11,9 +11,8 @@ const SPEC = {
|
|
|
11
11
|
description: "Deliver a file to the user as a downloadable artifact. Use it when the user should receive a " +
|
|
12
12
|
"file you produced (a report, chart, spreadsheet, archive and so on); files that stay on the " +
|
|
13
13
|
"device are not visible to the user, and images in tool results are shown to you, not " +
|
|
14
|
-
"delivered to the user. Pass file_path for a file on the device, or file_id for
|
|
15
|
-
"
|
|
16
|
-
"no device). Each call delivers only that one file, so a directory must first be packed into " +
|
|
14
|
+
"delivered to the user. Pass file_path for a file on the device, or file_id for a file id of " +
|
|
15
|
+
"this conversation, such as the file_id an image in a tool result names (needs no device). Each call delivers only that one file, so a directory must first be packed into " +
|
|
17
16
|
"one archive. The file size is limited (100 MB by default). Do not use it for intermediate " +
|
|
18
17
|
"files the user does not need. An HTML file is shown on its own: files it references by " +
|
|
19
18
|
"relative path are not delivered with it, so inline or embed them.",
|
|
@@ -28,7 +27,7 @@ const SPEC = {
|
|
|
28
27
|
file_id: {
|
|
29
28
|
type: "string",
|
|
30
29
|
minLength: 1,
|
|
31
|
-
description: "Instead of file_path:
|
|
30
|
+
description: "Instead of file_path: a file id of this conversation (a file the user sent, a delivered file, or the file_id of an image in a tool result).",
|
|
32
31
|
},
|
|
33
32
|
name: {
|
|
34
33
|
type: "string",
|
|
@@ -168,9 +167,9 @@ export function sandboxDeliverTool(deps) {
|
|
|
168
167
|
};
|
|
169
168
|
}
|
|
170
169
|
/**
|
|
171
|
-
* A `file_id` delivery:
|
|
172
|
-
* such as a tool result's image
|
|
173
|
-
* artifact's source path is `file_id/<id>`.
|
|
170
|
+
* A `file_id` delivery: a file of the conversation or its root ({@link findConversationFile}: a
|
|
171
|
+
* library file they refer to, or a `read` copy such as a tool result's image) read from the object
|
|
172
|
+
* store, no device; the artifact's source path is `file_id/<id>`.
|
|
174
173
|
*/
|
|
175
174
|
async function deliverById(deps, ctx, id, given, max) {
|
|
176
175
|
if (deps.read === undefined)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { BuiltinTool } from "../../registry.js";
|
|
2
2
|
import { type SandboxToolDeps } from "./common.js";
|
|
3
3
|
/**
|
|
4
|
-
* The builtin `FetchAttachment`: copy one
|
|
5
|
-
* ({@link attachmentsDir}); it runs
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The builtin `FetchAttachment`: copy one file sent into this conversation (its root's: the files
|
|
5
|
+
* its messages attached, file library spec §5) into the device ({@link attachmentsDir}); it runs
|
|
6
|
+
* nothing. A library file the person never attached to the conversation is not in the list.
|
|
7
|
+
* Names come from the conversation's whole attachment list ({@link assignAttachmentNames}), so a
|
|
8
|
+
* given attachment always lands on the same path; copying it twice writes the same bytes and
|
|
9
|
+
* returns the same path. A failure is an ordinary tool error and the run continues.
|
|
9
10
|
*/
|
|
10
11
|
export declare function sandboxFetchAttachmentTool(deps: SandboxToolDeps): BuiltinTool;
|