@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
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { AutomationCalendarQuery, AutomationChatTargetsQuery, AutomationCreateBody, AutomationEventSourcesQuery, AutomationGrantableQuery, AutomationGrantParams, AutomationGrantsBody, AutomationListQuery, AutomationParams, AutomationRunBody, AutomationRunsQuery, AutomationUpdateBody, calendarInputOf, createInputOf, grantsOf, updateInputOf, } from "../../automations/automations.schemas.js";
|
|
13
|
+
import { AutomationsService, } from "../../automations/automations.service.js";
|
|
14
|
+
import { defineOperation } from "../operation.js";
|
|
15
|
+
import { PlatformOperations } from "../registry.js";
|
|
16
|
+
import { named, orElse } from "./summary.js";
|
|
17
|
+
const ListQuery = AutomationListQuery;
|
|
18
|
+
/** A trigger in words for the approval card (the person's strings are neutralized). */
|
|
19
|
+
function triggerWords(t) {
|
|
20
|
+
if (t.kind === "cron")
|
|
21
|
+
return { zh: `cron ${named(t.expr)}`, en: `cron ${named(t.expr)}` };
|
|
22
|
+
if (t.kind === "once")
|
|
23
|
+
return { zh: `一次性 ${named(t.at)}`, en: `once at ${named(t.at)}` };
|
|
24
|
+
const types = t.types.map(named).join(", ");
|
|
25
|
+
return {
|
|
26
|
+
zh: `${named(t.source)} 的事件 ${types}`,
|
|
27
|
+
en: `events ${types} from ${named(t.source)}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const CreateBody = AutomationCreateBody;
|
|
31
|
+
const UpdateBody = AutomationUpdateBody;
|
|
32
|
+
const RunBody = AutomationRunBody;
|
|
33
|
+
const RunsQuery = AutomationRunsQuery;
|
|
34
|
+
const GrantsBody = AutomationGrantsBody;
|
|
35
|
+
const Id = AutomationParams.shape.id;
|
|
36
|
+
const ToolKey = AutomationGrantParams.shape.toolKey;
|
|
37
|
+
const TaskId = z.object({ automationId: Id }).strict();
|
|
38
|
+
const EXAMPLE_ID = "7b2d4f60-3a1e-4c85-9e07-5d8f1a2b3c4d";
|
|
39
|
+
/** A task as `automations.list` shows it: the schedule, the state and the next run. */
|
|
40
|
+
function row(t) {
|
|
41
|
+
return {
|
|
42
|
+
...(t.lastRun !== undefined && { lastRun: t.lastRun }),
|
|
43
|
+
id: t.id,
|
|
44
|
+
name: t.name,
|
|
45
|
+
agentId: t.agentId,
|
|
46
|
+
status: t.status,
|
|
47
|
+
pauseReason: t.pauseReason,
|
|
48
|
+
trigger: t.trigger,
|
|
49
|
+
mode: t.mode,
|
|
50
|
+
nextRunAt: t.nextRunAt,
|
|
51
|
+
creator: t.accountId,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const runRow = (r) => ({
|
|
55
|
+
id: r.id,
|
|
56
|
+
scheduledFor: r.scheduledFor,
|
|
57
|
+
firedAt: r.firedAt,
|
|
58
|
+
trial: r.trial,
|
|
59
|
+
status: r.status,
|
|
60
|
+
skipReason: r.skipReason,
|
|
61
|
+
error: r.error,
|
|
62
|
+
conversationId: r.conversationId,
|
|
63
|
+
missingGrants: r.missingGrants,
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Automation operations of the `Platform` tool (scheduled tasks spec §10): the same service
|
|
67
|
+
* as the HTTP routes. Writes are `personal`. Creating or changing a task and its approved tools
|
|
68
|
+
* are never remembered (`rememberable: false`): an approval, remembered or granted to a task,
|
|
69
|
+
* must never let an unattended run create or widen a task. Delete, run and resume are never
|
|
70
|
+
* remembered either. List, pause and delete are `org.read` like their routes: a creator demoted
|
|
71
|
+
* to guest can still see and stop their own tasks (the service decides by ownership).
|
|
72
|
+
*/
|
|
73
|
+
let AutomationsOperations = class AutomationsOperations {
|
|
74
|
+
registry;
|
|
75
|
+
tasks;
|
|
76
|
+
constructor(registry, tasks) {
|
|
77
|
+
this.registry = registry;
|
|
78
|
+
this.tasks = tasks;
|
|
79
|
+
}
|
|
80
|
+
/** The caller as the service expects (it reads the live role itself). */
|
|
81
|
+
actor(ctx) {
|
|
82
|
+
return { accountId: ctx.actorAccountId };
|
|
83
|
+
}
|
|
84
|
+
/** The task's name for a card; its id when it cannot be read. */
|
|
85
|
+
label(ctx, id) {
|
|
86
|
+
return orElse(async () => named((await this.tasks.get(ctx.orgId, this.actor(ctx), id)).name), id);
|
|
87
|
+
}
|
|
88
|
+
onModuleInit() {
|
|
89
|
+
this.registry.register([
|
|
90
|
+
defineOperation({
|
|
91
|
+
id: "automations.list",
|
|
92
|
+
description: "List your automations: one compact row each (name, agent, status and why it is paused, schedule with its time zone, where runs post, next run, last settled run). all=true lists every task of the org and needs the org admin role; conversationId keeps the tasks that post into that conversation.",
|
|
93
|
+
input: ListQuery,
|
|
94
|
+
example: {},
|
|
95
|
+
// a creator demoted to guest still lists their own tasks (to pause or delete them)
|
|
96
|
+
authz: { orgAction: "org.read" },
|
|
97
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations"],
|
|
98
|
+
confirm: "read",
|
|
99
|
+
errors: [
|
|
100
|
+
{
|
|
101
|
+
code: "forbidden",
|
|
102
|
+
next: "Listing every task needs the org admin role: call without all, or ask an org admin.",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
run: async (input, ctx) => {
|
|
106
|
+
const items = await this.tasks.list(ctx.orgId, this.actor(ctx), {
|
|
107
|
+
all: input.all === "true",
|
|
108
|
+
...(input.conversationId !== undefined && { conversationId: input.conversationId }),
|
|
109
|
+
});
|
|
110
|
+
return { items: items.map(row) };
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
defineOperation({
|
|
114
|
+
id: "automations.calendar",
|
|
115
|
+
description: "Your automation runs and planned occurrences between two instants (at most 43 days): recorded runs with their status, planned runs computed from each active task's schedule up to 42 days ahead, and dense tasks summarized per day. Org admins see every task with all=true. from and to are ISO instants with an offset; timeZone (IANA) sets the local days used to summarize dense tasks; taskId lists one task's items, never summarized (then at most 2 days). truncated means a limit cut the range at horizon.",
|
|
116
|
+
input: AutomationCalendarQuery,
|
|
117
|
+
example: {
|
|
118
|
+
from: "2026-11-09T00:00:00+08:00",
|
|
119
|
+
to: "2026-11-16T00:00:00+08:00",
|
|
120
|
+
timeZone: "Asia/Shanghai",
|
|
121
|
+
},
|
|
122
|
+
authz: { orgAction: "org.read" },
|
|
123
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/calendar"],
|
|
124
|
+
confirm: "read",
|
|
125
|
+
errors: [
|
|
126
|
+
{
|
|
127
|
+
code: "validation_failed",
|
|
128
|
+
next: "Narrow the range to 43 days or less (2 days with taskId), with from before to.",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
code: "forbidden",
|
|
132
|
+
next: "Reading every task needs the org admin role: call without all, or ask an org admin.",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
code: "automation.not_found",
|
|
136
|
+
next: "Check taskId with automations.list: members see only their own tasks; an org admin finds another member's task id with automations.list all=true, then reads it here by taskId (all is not needed).",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
run: async (input, ctx) => {
|
|
140
|
+
const answer = await this.tasks.calendar(ctx.orgId, this.actor(ctx), calendarInputOf(input));
|
|
141
|
+
return {
|
|
142
|
+
...answer,
|
|
143
|
+
tasks: answer.tasks.map((t) => ({
|
|
144
|
+
id: t.id,
|
|
145
|
+
name: t.name,
|
|
146
|
+
agentId: t.agentId,
|
|
147
|
+
status: t.status,
|
|
148
|
+
})),
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
defineOperation({
|
|
153
|
+
id: "automations.event-sources",
|
|
154
|
+
description: 'The event sources an automation can trigger on: each { source, name, events } for an extension that emits trigger events and is on in this org (and not switched off in the automation settings). Each event is { type, name, directed, facts }: facts maps a name to { type (string, number, boolean or string[]), name, filterable }. Use source, type names and filterable facts in automations.create\'s trigger { kind: "event", source, types, filter }; directed types cannot trigger an automation.',
|
|
155
|
+
input: AutomationEventSourcesQuery,
|
|
156
|
+
example: {},
|
|
157
|
+
authz: { orgAction: "automations.use" },
|
|
158
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/event-sources"],
|
|
159
|
+
confirm: "read",
|
|
160
|
+
errors: [],
|
|
161
|
+
run: async (_input, ctx) => ({ items: await this.tasks.eventSources(ctx.orgId) }),
|
|
162
|
+
}),
|
|
163
|
+
defineOperation({
|
|
164
|
+
id: "automations.chat-targets",
|
|
165
|
+
description: "The IM chats you can point a chat-mode automation at: your direct chats with each active channel connection's bot (one you have messaged before), and the groups you have talked in when the channel has threads. Each gives { connectionId, chatId, chatType } for automations.create, and the connection's agentId, which the task must use.",
|
|
166
|
+
input: AutomationChatTargetsQuery,
|
|
167
|
+
example: {},
|
|
168
|
+
authz: { orgAction: "automations.use" },
|
|
169
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/chat-targets"],
|
|
170
|
+
confirm: "read",
|
|
171
|
+
errors: [],
|
|
172
|
+
run: async (_input, ctx) => ({
|
|
173
|
+
items: await this.tasks.chatTargets(ctx.orgId, ctx.actorAccountId),
|
|
174
|
+
}),
|
|
175
|
+
}),
|
|
176
|
+
defineOperation({
|
|
177
|
+
id: "automations.grantable-tools",
|
|
178
|
+
description: "An agent's tools as an automation can approve them in advance: each { key, title, source, connectorId, grantable, reason }; reason says why not (forbidden by the org, not_grantable by design, needs_role, fixed_ask, not_available). Takes the agent id from the agents list.",
|
|
179
|
+
input: AutomationGrantableQuery,
|
|
180
|
+
example: { agentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20" },
|
|
181
|
+
authz: { orgAction: "automations.use" },
|
|
182
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/grantable-tools"],
|
|
183
|
+
confirm: "read",
|
|
184
|
+
errors: [
|
|
185
|
+
{
|
|
186
|
+
code: "agent.not_found",
|
|
187
|
+
next: "Check the agent id: it must be an agent you can use in this org.",
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
run: async (input, ctx) => ({
|
|
191
|
+
items: await this.tasks.grantableTools(ctx.orgId, ctx.actorAccountId, input.agentId),
|
|
192
|
+
}),
|
|
193
|
+
}),
|
|
194
|
+
defineOperation({
|
|
195
|
+
id: "automations.get",
|
|
196
|
+
description: "Read one automation in full: prompt, schedule, target, model, effort, device, status, next run, expiry. Takes the id from automations.list.",
|
|
197
|
+
input: TaskId,
|
|
198
|
+
example: { automationId: EXAMPLE_ID },
|
|
199
|
+
authz: { orgAction: "automations.use" },
|
|
200
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/:id"],
|
|
201
|
+
renames: { automationId: "id" },
|
|
202
|
+
confirm: "read",
|
|
203
|
+
errors: [
|
|
204
|
+
{
|
|
205
|
+
code: "automation.not_found",
|
|
206
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
run: async (input, ctx) => ({
|
|
210
|
+
task: await this.tasks.get(ctx.orgId, this.actor(ctx), input.automationId),
|
|
211
|
+
}),
|
|
212
|
+
}),
|
|
213
|
+
defineOperation({
|
|
214
|
+
id: "automations.create",
|
|
215
|
+
description: "Create an automation: an agent runs the prompt as you, unattended, on a 5-field cron, once at a local date-time, or when events happen: trigger { kind: \"event\", source, types, filter? } with a source, types and filterable facts from automations.event-sources (filter is a list of { fact, op: eq | in | contains, value }; eq takes a scalar of the fact's type, in a list of strings for a string fact, contains a string for a string[] fact). A time trigger uses your time zone; timeZone is only the fallback when you have none set; an event trigger has none. mode: new (a conversation per run), conversation (post into one conversation), chat (an IM chat; time triggers only) or subject (one conversation per event subject; event triggers only). unattendedAsk (fail | wait) sets what a question in an unattended run does; null follows the org's default. model ({ provider, model } like an agent definition's) and effort are for modes new and subject, deviceId for mode new only; a conversation or chat task runs with that conversation's model. Without expiresAt a cron or event automation ends after the org's default expiry, when the org sets one. grants pre-approve tools the unattended run may use.",
|
|
216
|
+
input: CreateBody,
|
|
217
|
+
example: {
|
|
218
|
+
agentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20",
|
|
219
|
+
name: "Daily digest",
|
|
220
|
+
prompt: "Summarize yesterday's activity.",
|
|
221
|
+
trigger: { kind: "cron", expr: "0 9 * * *" },
|
|
222
|
+
mode: "new",
|
|
223
|
+
},
|
|
224
|
+
authz: { orgAction: "automations.use" },
|
|
225
|
+
mirrors: ["POST /api/v1/orgs/:orgId/automations"],
|
|
226
|
+
confirm: "personal",
|
|
227
|
+
// an unattended run must never create or widen a task through a remembered approval
|
|
228
|
+
rememberable: false,
|
|
229
|
+
errors: [
|
|
230
|
+
{
|
|
231
|
+
code: "automation.disabled",
|
|
232
|
+
next: {
|
|
233
|
+
orgAdmin: "Turn automations on in the org settings.",
|
|
234
|
+
member: "Automations are off here; ask an org admin.",
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
code: "automation.limit_reached",
|
|
239
|
+
next: "Delete a task you no longer need with automations.delete, or pause and edit an existing one.",
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
code: "automation.target_invalid",
|
|
243
|
+
next: "Fix the target named in the message (conversation, chat or device) and call again. Mode subject needs an event trigger; mode chat needs a time trigger.",
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
code: "automation.event_source_unavailable",
|
|
247
|
+
next: "Pick a source from automations.event-sources: it must be enabled in this org and not switched off in the automation settings.",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
code: "automation.event_type_unknown",
|
|
251
|
+
next: "Use event type names the source declares in automations.event-sources; directed types cannot trigger an automation.",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
code: "automation.filter_invalid",
|
|
255
|
+
next: "Filter only on filterable facts the selected event types all declare, with a value of the fact's type (eq: scalar, in: strings on a string fact, contains: a string on a string[] fact).",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
code: "automation.grant_not_allowed",
|
|
259
|
+
next: "Drop that grant: the task will ask for it as a person when it runs attended, or ask an org admin.",
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
summary: (i) => ({
|
|
263
|
+
zh: `创建自动化「${named(i.name)}」(${triggerWords(i.trigger).zh}),之后无人值守地以你的身份运行`,
|
|
264
|
+
en: `Create automation "${named(i.name)}" (${triggerWords(i.trigger).en}), then run unattended as you`,
|
|
265
|
+
}),
|
|
266
|
+
run: async (input, ctx) => {
|
|
267
|
+
const { input: create, browserTimeZone } = createInputOf(input);
|
|
268
|
+
return {
|
|
269
|
+
task: await this.tasks.create(ctx.orgId, ctx.actorAccountId, create, browserTimeZone),
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
}),
|
|
273
|
+
defineOperation({
|
|
274
|
+
id: "automations.update",
|
|
275
|
+
description: "Change one of your own automations (name, prompt, trigger (a schedule or an event trigger, as automations.create takes it), time zone, target, mode, unattendedAsk, model, effort, device, expiry; null clears an optional field, and a null expiry on a cron or event automation takes the org's default expiry when set). model and effort are for modes new and subject, deviceId for mode new only; switching to another mode clears them. Only the creator can; an org admin can pause it instead. Takes the id from automations.list.",
|
|
276
|
+
input: UpdateBody.extend({ automationId: Id }).strict(),
|
|
277
|
+
example: { automationId: EXAMPLE_ID, prompt: "Summarize the last two days." },
|
|
278
|
+
authz: { orgAction: "automations.use" },
|
|
279
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/automations/:id"],
|
|
280
|
+
renames: { automationId: "id" },
|
|
281
|
+
confirm: "personal",
|
|
282
|
+
rememberable: false,
|
|
283
|
+
errors: [
|
|
284
|
+
{
|
|
285
|
+
code: "automation.not_found",
|
|
286
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
code: "automation.forbidden",
|
|
290
|
+
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
code: "automation.target_invalid",
|
|
294
|
+
next: "Fix the target named in the message and call again. Mode subject needs an event trigger; mode chat needs a time trigger; switching trigger kind may need a new mode.",
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
code: "automation.event_source_unavailable",
|
|
298
|
+
next: "Pick a source from automations.event-sources.",
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
code: "automation.event_type_unknown",
|
|
302
|
+
next: "Use event type names the source declares in automations.event-sources.",
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
code: "automation.filter_invalid",
|
|
306
|
+
next: "Filter only on filterable facts of the selected types, with a value of the fact's type.",
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
summary: async (i, ctx) => {
|
|
310
|
+
const n = await this.label(ctx, i.automationId);
|
|
311
|
+
return {
|
|
312
|
+
zh: `修改自动化「${n}」`,
|
|
313
|
+
en: `Change automation "${n}"`,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
run: async (input, ctx) => {
|
|
317
|
+
const { automationId, ...patch } = input;
|
|
318
|
+
return {
|
|
319
|
+
task: await this.tasks.update(ctx.orgId, ctx.actorAccountId, automationId, updateInputOf(patch)),
|
|
320
|
+
};
|
|
321
|
+
},
|
|
322
|
+
}),
|
|
323
|
+
defineOperation({
|
|
324
|
+
id: "automations.delete",
|
|
325
|
+
description: "Delete an automation (yours; an org admin can delete any). Takes the id from automations.list.",
|
|
326
|
+
input: TaskId,
|
|
327
|
+
example: { automationId: EXAMPLE_ID },
|
|
328
|
+
authz: { orgAction: "org.read" },
|
|
329
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/automations/:id"],
|
|
330
|
+
renames: { automationId: "id" },
|
|
331
|
+
confirm: "personal",
|
|
332
|
+
rememberable: false,
|
|
333
|
+
errors: [
|
|
334
|
+
{
|
|
335
|
+
code: "automation.not_found",
|
|
336
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
summary: async (i, ctx) => {
|
|
340
|
+
const n = await this.label(ctx, i.automationId);
|
|
341
|
+
return { zh: `删除自动化「${n}」`, en: `Delete automation "${n}"` };
|
|
342
|
+
},
|
|
343
|
+
run: async (input, ctx) => {
|
|
344
|
+
await this.tasks.remove(ctx.orgId, this.actor(ctx), input.automationId);
|
|
345
|
+
return { id: input.automationId, deleted: true };
|
|
346
|
+
},
|
|
347
|
+
}),
|
|
348
|
+
defineOperation({
|
|
349
|
+
id: "automations.pause",
|
|
350
|
+
description: "Pause an automation so it stops firing (yours; an org admin can pause any, and the creator is told). Resume it with automations.resume. Takes the id from automations.list.",
|
|
351
|
+
input: TaskId,
|
|
352
|
+
example: { automationId: EXAMPLE_ID },
|
|
353
|
+
authz: { orgAction: "org.read" },
|
|
354
|
+
mirrors: ["POST /api/v1/orgs/:orgId/automations/:id/pause"],
|
|
355
|
+
renames: { automationId: "id" },
|
|
356
|
+
confirm: "personal",
|
|
357
|
+
errors: [
|
|
358
|
+
{
|
|
359
|
+
code: "automation.not_found",
|
|
360
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
summary: async (i, ctx) => {
|
|
364
|
+
const n = await this.label(ctx, i.automationId);
|
|
365
|
+
return { zh: `暂停自动化「${n}」`, en: `Pause automation "${n}"` };
|
|
366
|
+
},
|
|
367
|
+
run: async (input, ctx) => ({
|
|
368
|
+
task: row(await this.tasks.pause(ctx.orgId, this.actor(ctx), input.automationId)),
|
|
369
|
+
}),
|
|
370
|
+
}),
|
|
371
|
+
defineOperation({
|
|
372
|
+
id: "automations.resume",
|
|
373
|
+
description: "Resume a paused automation: the next run is computed from now (missed ticks are not caught up). An ended task cannot be resumed. Takes the id from automations.list.",
|
|
374
|
+
input: TaskId,
|
|
375
|
+
example: { automationId: EXAMPLE_ID },
|
|
376
|
+
authz: { orgAction: "automations.use" },
|
|
377
|
+
mirrors: ["POST /api/v1/orgs/:orgId/automations/:id/resume"],
|
|
378
|
+
renames: { automationId: "id" },
|
|
379
|
+
confirm: "personal",
|
|
380
|
+
// a remembered resume would let an unattended run restart a task a person stopped
|
|
381
|
+
rememberable: false,
|
|
382
|
+
errors: [
|
|
383
|
+
{
|
|
384
|
+
code: "automation.not_found",
|
|
385
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
code: "automation.once_in_past",
|
|
389
|
+
next: "Its time has passed: set a new time with automations.update, then resume.",
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
code: "automation.disabled",
|
|
393
|
+
next: {
|
|
394
|
+
orgAdmin: "Turn automations on in the org settings.",
|
|
395
|
+
member: "Automations are off here; ask an org admin.",
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
summary: async (i, ctx) => {
|
|
400
|
+
const n = await this.label(ctx, i.automationId);
|
|
401
|
+
return { zh: `恢复自动化「${n}」`, en: `Resume automation "${n}"` };
|
|
402
|
+
},
|
|
403
|
+
run: async (input, ctx) => ({
|
|
404
|
+
task: row(await this.tasks.resume(ctx.orgId, this.actor(ctx), input.automationId)),
|
|
405
|
+
}),
|
|
406
|
+
}),
|
|
407
|
+
defineOperation({
|
|
408
|
+
id: "automations.run",
|
|
409
|
+
description: "Run one of your own scheduled automations now, outside its schedule (the schedule does not move). trial=true is an attended trial: you approve its tool calls and they become the task's approved tools. Counts toward the hourly run limit. An event automation runs only on its events and cannot be run now. Takes the id from automations.list.",
|
|
410
|
+
input: RunBody.extend({ automationId: Id }).strict(),
|
|
411
|
+
example: { automationId: EXAMPLE_ID, trial: true },
|
|
412
|
+
authz: { orgAction: "automations.use" },
|
|
413
|
+
mirrors: ["POST /api/v1/orgs/:orgId/automations/:id/run"],
|
|
414
|
+
renames: { automationId: "id" },
|
|
415
|
+
confirm: "personal",
|
|
416
|
+
// a remembered run would let an unattended run trigger other tasks
|
|
417
|
+
rememberable: false,
|
|
418
|
+
errors: [
|
|
419
|
+
{
|
|
420
|
+
code: "automation.not_found",
|
|
421
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
code: "automation.forbidden",
|
|
425
|
+
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
426
|
+
},
|
|
427
|
+
{ code: "conflict", next: "The task has ended or is being run: wait, or edit it first." },
|
|
428
|
+
{
|
|
429
|
+
code: "automation.run_now_unsupported",
|
|
430
|
+
next: "An event automation runs only when its events arrive: tell the person to make an event of its source happen to test it, or change its trigger to a schedule with automations.update.",
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
summary: async (i, ctx) => {
|
|
434
|
+
const n = await this.label(ctx, i.automationId);
|
|
435
|
+
return {
|
|
436
|
+
zh: `立即运行自动化「${n}」${i.trial === true ? "(试运行)" : ""}`,
|
|
437
|
+
en: `Run automation "${n}" now${i.trial === true ? " as a trial" : ""}`,
|
|
438
|
+
};
|
|
439
|
+
},
|
|
440
|
+
run: async (input, ctx) => ({
|
|
441
|
+
run: runRow(await this.tasks.runNow(ctx.orgId, ctx.actorAccountId, input.automationId, {
|
|
442
|
+
trial: input.trial === true,
|
|
443
|
+
})),
|
|
444
|
+
}),
|
|
445
|
+
}),
|
|
446
|
+
defineOperation({
|
|
447
|
+
id: "automations.runs",
|
|
448
|
+
description: "A task's run history, latest first (default 50, at most 200): each tick with its status, skip reason, error, conversation and the tools refused for lack of an approval. Takes the id from automations.list.",
|
|
449
|
+
input: RunsQuery.extend({ automationId: Id }).strict(),
|
|
450
|
+
example: { automationId: EXAMPLE_ID },
|
|
451
|
+
authz: { orgAction: "automations.use" },
|
|
452
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/:id/runs"],
|
|
453
|
+
renames: { automationId: "id" },
|
|
454
|
+
confirm: "read",
|
|
455
|
+
errors: [
|
|
456
|
+
{
|
|
457
|
+
code: "automation.not_found",
|
|
458
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
459
|
+
},
|
|
460
|
+
],
|
|
461
|
+
run: async (input, ctx) => ({
|
|
462
|
+
items: (await this.tasks.runs(ctx.orgId, this.actor(ctx), input.automationId, input.limit)).map(runRow),
|
|
463
|
+
}),
|
|
464
|
+
}),
|
|
465
|
+
defineOperation({
|
|
466
|
+
id: "automations.grants-list",
|
|
467
|
+
description: "The tools approved in advance for an automation (what an unattended run may call without asking), each as { toolKey, connectorId, stale }; a stale approval no longer applies because the tool changed. Takes the id from automations.list.",
|
|
468
|
+
input: TaskId,
|
|
469
|
+
example: { automationId: EXAMPLE_ID },
|
|
470
|
+
authz: { orgAction: "automations.use" },
|
|
471
|
+
mirrors: ["GET /api/v1/orgs/:orgId/automations/:id/grants"],
|
|
472
|
+
renames: { automationId: "id" },
|
|
473
|
+
confirm: "read",
|
|
474
|
+
errors: [
|
|
475
|
+
{
|
|
476
|
+
code: "automation.not_found",
|
|
477
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
478
|
+
},
|
|
479
|
+
],
|
|
480
|
+
run: async (input, ctx) => ({
|
|
481
|
+
items: (await this.tasks.grants(ctx.orgId, this.actor(ctx), input.automationId)).map((g) => ({ toolKey: g.toolKey, connectorId: g.connectorId, stale: g.stale })),
|
|
482
|
+
}),
|
|
483
|
+
}),
|
|
484
|
+
defineOperation({
|
|
485
|
+
id: "automations.grants-add",
|
|
486
|
+
description: "Approve tools in advance for one of your own automations: an unattended run may then call them without asking. Only tools you could approve with always-allow yourself; never a Platform operation (each is decided per call) and nothing the org forbids. Returns the task's approved tools as { toolKey, connectorId }. Takes the id from automations.list.",
|
|
487
|
+
input: GrantsBody.extend({ automationId: Id }).strict(),
|
|
488
|
+
example: { automationId: EXAMPLE_ID, grants: [{ toolKey: "WebFetch" }] },
|
|
489
|
+
authz: { orgAction: "automations.use" },
|
|
490
|
+
mirrors: ["POST /api/v1/orgs/:orgId/automations/:id/grants"],
|
|
491
|
+
renames: { automationId: "id" },
|
|
492
|
+
confirm: "personal",
|
|
493
|
+
rememberable: false,
|
|
494
|
+
errors: [
|
|
495
|
+
{
|
|
496
|
+
code: "automation.not_found",
|
|
497
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
code: "automation.forbidden",
|
|
501
|
+
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
code: "automation.grant_not_allowed",
|
|
505
|
+
next: "Drop that tool: it cannot be approved in advance for a task.",
|
|
506
|
+
},
|
|
507
|
+
],
|
|
508
|
+
summary: async (i, ctx) => {
|
|
509
|
+
const n = await this.label(ctx, i.automationId);
|
|
510
|
+
const keys = i.grants.map((g) => named(g.toolKey)).join(", ");
|
|
511
|
+
return {
|
|
512
|
+
zh: `为自动化「${n}」预先批准工具:${keys}`,
|
|
513
|
+
en: `Approve tools in advance for automation "${n}": ${keys}`,
|
|
514
|
+
};
|
|
515
|
+
},
|
|
516
|
+
run: async (input, ctx) => ({
|
|
517
|
+
items: (await this.tasks.addGrants(ctx.orgId, ctx.actorAccountId, input.automationId, grantsOf(input.grants))).map((g) => ({ toolKey: g.toolKey, connectorId: g.connectorId })),
|
|
518
|
+
}),
|
|
519
|
+
}),
|
|
520
|
+
defineOperation({
|
|
521
|
+
id: "automations.grants-remove",
|
|
522
|
+
description: "Remove a tool's advance approval from one of your own automations (nothing happens if it had none): the unattended run is then refused that tool. Takes the id from automations.list.",
|
|
523
|
+
input: z.object({ automationId: Id, toolKey: ToolKey }).strict(),
|
|
524
|
+
example: { automationId: EXAMPLE_ID, toolKey: "WebFetch" },
|
|
525
|
+
authz: { orgAction: "automations.use" },
|
|
526
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/automations/:id/grants/:toolKey"],
|
|
527
|
+
renames: { automationId: "id" },
|
|
528
|
+
confirm: "personal",
|
|
529
|
+
rememberable: false,
|
|
530
|
+
errors: [
|
|
531
|
+
{
|
|
532
|
+
code: "automation.not_found",
|
|
533
|
+
next: "Check the id with automations.list: you only see your own tasks (org admins see all with all=true).",
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
code: "automation.forbidden",
|
|
537
|
+
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
538
|
+
},
|
|
539
|
+
],
|
|
540
|
+
summary: async (i, ctx) => {
|
|
541
|
+
const n = await this.label(ctx, i.automationId);
|
|
542
|
+
return {
|
|
543
|
+
zh: `撤销自动化「${n}」对工具 ${named(i.toolKey)} 的预先批准`,
|
|
544
|
+
en: `Remove the advance approval of ${named(i.toolKey)} from automation "${n}"`,
|
|
545
|
+
};
|
|
546
|
+
},
|
|
547
|
+
run: async (input, ctx) => {
|
|
548
|
+
await this.tasks.removeGrant(ctx.orgId, ctx.actorAccountId, input.automationId, input.toolKey);
|
|
549
|
+
return { id: input.automationId, toolKey: input.toolKey, removed: true };
|
|
550
|
+
},
|
|
551
|
+
}),
|
|
552
|
+
]);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
AutomationsOperations = __decorate([
|
|
556
|
+
Injectable(),
|
|
557
|
+
__param(0, Inject(PlatformOperations)),
|
|
558
|
+
__param(1, Inject(AutomationsService))
|
|
559
|
+
], AutomationsOperations);
|
|
560
|
+
export { AutomationsOperations };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { DeviceProjectFilesService } from "../../devices/device-project-files.service.js";
|
|
2
3
|
import { DeviceProjectsService } from "../../devices/device-projects.service.js";
|
|
3
4
|
import { DevicesService } from "../../devices/devices.service.js";
|
|
4
5
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
@@ -13,8 +14,9 @@ export declare class DevicesOperations implements OnModuleInit {
|
|
|
13
14
|
private readonly registry;
|
|
14
15
|
private readonly devices;
|
|
15
16
|
private readonly projects;
|
|
17
|
+
private readonly projectFiles;
|
|
16
18
|
private readonly kdb;
|
|
17
|
-
constructor(registry: PlatformOperations, devices: DevicesService, projects: DeviceProjectsService, kdb: KernelDb);
|
|
19
|
+
constructor(registry: PlatformOperations, devices: DevicesService, projects: DeviceProjectsService, projectFiles: DeviceProjectFilesService, kdb: KernelDb);
|
|
18
20
|
/**
|
|
19
21
|
* Whether `id` is the device the run works in: the one its root conversation is bound to
|
|
20
22
|
* (sub-agents use the root's). Deleting or wiping it would pull the sandbox from under the run.
|