@capybara-hq/kernel 0.1.0-rc.104 → 0.1.0-rc.106
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/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 +3 -3
- package/dist/channels/outbound.d.ts +5 -5
- package/dist/channels/outbound.js +17 -17
- package/dist/channels/threads.d.ts +1 -1
- package/dist/channels/threads.js +1 -1
- package/dist/config/schema.d.ts +5 -1
- package/dist/config/schema.js +44 -6
- package/dist/conversations/approval-profile.d.ts +2 -2
- package/dist/conversations/approval-profile.js +3 -3
- package/dist/conversations/conversations.controller.d.ts +7 -1
- package/dist/conversations/conversations.controller.js +26 -10
- package/dist/conversations/conversations.service.d.ts +103 -25
- package/dist/conversations/conversations.service.js +138 -33
- package/dist/conversations/events.d.ts +48 -1
- package/dist/conversations/events.js +61 -9
- 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 +2 -1
- 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 +20 -14
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +59 -2
- package/dist/db/kernel-schema.d.ts +104 -25
- 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 +47 -13
- package/dist/errors.js +47 -13
- package/dist/evals/reconstruct.d.ts +10 -1
- package/dist/evals/reconstruct.js +7 -0
- package/dist/extensions/host.d.ts +6 -1
- package/dist/extensions/host.js +10 -0
- 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/git/gateway.js +2 -2
- package/dist/handoff/app-schemes.d.ts +28 -0
- package/dist/handoff/app-schemes.js +41 -0
- package/dist/handoff/handoff-paths.d.ts +26 -0
- package/dist/handoff/handoff-paths.js +25 -0
- package/dist/handoff/handoff-tickets.d.ts +28 -0
- package/dist/handoff/handoff-tickets.js +111 -0
- package/dist/handoff/handoff.controller.d.ts +24 -0
- package/dist/handoff/handoff.controller.js +74 -0
- package/dist/handoff/handoff.module.d.ts +7 -0
- package/dist/handoff/handoff.module.js +26 -0
- package/dist/handoff/handoff.schemas.d.ts +13 -0
- package/dist/handoff/handoff.schemas.js +3 -0
- package/dist/handoff/handoff.service.d.ts +49 -0
- package/dist/handoff/handoff.service.js +96 -0
- package/dist/http/api.module.js +13 -5
- package/dist/http/meta.controller.d.ts +1 -0
- package/dist/http/meta.controller.js +7 -0
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/identity/sso.controller.d.ts +30 -6
- package/dist/identity/sso.controller.js +51 -17
- package/dist/identity/sso.d.ts +10 -2
- package/dist/identity/sso.js +15 -3
- 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 +29 -2
- package/dist/infra/outbox/registry.js +30 -7
- package/dist/kernel.module.js +3 -0
- 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 +27 -11
- package/dist/orgs/settings.service.js +42 -24
- package/dist/overrides.d.ts +4 -4
- package/dist/overrides.js +1 -1
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/operation.js +2 -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/connectors.ops.js +4 -2
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +77 -3
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/orgs.ops.js +1 -1
- package/dist/platform/ops/platform.ops.js +4 -4
- package/dist/platform/platform-ops.module.d.ts +2 -2
- package/dist/platform/platform-ops.module.js +5 -5
- package/dist/platform/route-schemas.js +3 -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 +3 -3
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +6 -0
- package/dist/runtime/context/build.js +14 -3
- package/dist/runtime/context/compaction.d.ts +27 -1
- package/dist/runtime/context/compaction.js +102 -37
- package/dist/runtime/context/run-context.d.ts +38 -0
- package/dist/runtime/context/run-context.js +54 -0
- package/dist/runtime/maintenance.d.ts +8 -4
- package/dist/runtime/maintenance.js +37 -16
- package/dist/runtime/model-call.d.ts +6 -4
- package/dist/runtime/model-call.js +17 -7
- package/dist/runtime/project/knowledge.service.d.ts +16 -7
- package/dist/runtime/project/knowledge.service.js +31 -13
- 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-worker.js +7 -1
- package/dist/runtime/runtime.module.js +3 -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/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/{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 +8 -8
- package/dist/tools/builtins/builtin-tools.js +16 -16
- package/dist/tools/call-scope.d.ts +1 -1
- package/dist/tools/connectors.service.d.ts +4 -13
- package/dist/tools/connectors.service.js +12 -21
- 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/oauth/flow.d.ts +16 -2
- package/dist/tools/oauth/flow.js +23 -4
- package/dist/tools/oauth/oauth.controller.d.ts +19 -7
- package/dist/tools/oauth/oauth.controller.js +42 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -1
- package/dist/tools/oauth/oauth.schemas.js +4 -1
- 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 +9 -9
- package/package.json +3 -3
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -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,136 @@
|
|
|
1
|
+
-- Event automations (collaboration spec 2026-11-25 §4.1, §4.5, §4.6): an automation fires on an
|
|
2
|
+
-- extension's trigger event as well as on a time trigger.
|
|
3
|
+
-- - `trigger_events`: the events extensions emit (`ctx.triggers.emit`), once per
|
|
4
|
+
-- (org, plugin, dedupe key);
|
|
5
|
+
-- - `automation_event_deliveries`: which event reached which automation, and the run that served
|
|
6
|
+
-- it (null while coalesced events wait for one, §4.7);
|
|
7
|
+
-- - `automation_conversations`: the one conversation per subject of a `subject`-mode automation;
|
|
8
|
+
-- - `automations` gains `origin`, `principal` and `unattended_ask`, and the `subject` mode;
|
|
9
|
+
-- - `automation_runs` is keyed by `trigger_key` (the tick as `Date.toISOString()` text for time
|
|
10
|
+
-- runs, the event id for event runs) instead of `scheduled_for`, which event runs leave null;
|
|
11
|
+
-- one skip reason for event runs (`subject_rate`; a subject the owner cannot see gets no
|
|
12
|
+
-- delivery at dispatch, so no run);
|
|
13
|
+
-- - `conversations.subject`, `runs.trigger_event_id` and `conversation_queue.automation_event`
|
|
14
|
+
-- (the queued message's event marker, logged as `user_message.automationEvent`).
|
|
15
|
+
-- Ids are text like every kernel id. The three new tables carry `org_id` and their `org_scope`
|
|
16
|
+
-- policies (still dark: nothing enables row level security before phase 5).
|
|
17
|
+
|
|
18
|
+
CREATE TABLE IF NOT EXISTS trigger_events (
|
|
19
|
+
id text PRIMARY KEY,
|
|
20
|
+
org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
|
|
21
|
+
-- the emitting extension
|
|
22
|
+
plugin text NOT NULL,
|
|
23
|
+
type text NOT NULL,
|
|
24
|
+
-- { kind, id, title, url? }
|
|
25
|
+
subject jsonb NOT NULL,
|
|
26
|
+
facts jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
27
|
+
summary text NOT NULL,
|
|
28
|
+
dedupe_key text NOT NULL,
|
|
29
|
+
-- a directed event: { accountId, agentId }; null = every matching automation
|
|
30
|
+
audience jsonb,
|
|
31
|
+
cause_account_id text,
|
|
32
|
+
-- the run whose tool call emitted it (loop depth, §4.7)
|
|
33
|
+
cause_run_id text,
|
|
34
|
+
depth integer NOT NULL DEFAULT 0,
|
|
35
|
+
state text NOT NULL DEFAULT 'pending'
|
|
36
|
+
CHECK (state IN ('pending', 'dispatched', 'undelivered', 'depth_stopped')),
|
|
37
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
CREATE UNIQUE INDEX IF NOT EXISTS trigger_events_dedupe_uq
|
|
41
|
+
ON trigger_events (org_id, plugin, dedupe_key);
|
|
42
|
+
|
|
43
|
+
-- the retention sweep: settled events, oldest first
|
|
44
|
+
CREATE INDEX IF NOT EXISTS trigger_events_settled_idx
|
|
45
|
+
ON trigger_events (created_at) WHERE state <> 'pending';
|
|
46
|
+
|
|
47
|
+
DROP POLICY IF EXISTS org_scope ON trigger_events;
|
|
48
|
+
CREATE POLICY org_scope ON trigger_events USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
|
|
49
|
+
|
|
50
|
+
CREATE TABLE IF NOT EXISTS automation_event_deliveries (
|
|
51
|
+
org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
|
|
52
|
+
automation_id text NOT NULL REFERENCES automations(id) ON DELETE CASCADE,
|
|
53
|
+
event_id text NOT NULL REFERENCES trigger_events(id) ON DELETE CASCADE,
|
|
54
|
+
-- `<subject kind>:<subject id>`: events of one subject coalesce into one run
|
|
55
|
+
subject_key text NOT NULL,
|
|
56
|
+
-- the run that served it; null while it waits for one
|
|
57
|
+
automation_run_id text,
|
|
58
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
59
|
+
PRIMARY KEY (automation_id, event_id)
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
-- the deliveries of a subject still waiting for a run
|
|
63
|
+
CREATE INDEX IF NOT EXISTS automation_event_deliveries_pending_idx
|
|
64
|
+
ON automation_event_deliveries (automation_id, subject_key) WHERE automation_run_id IS NULL;
|
|
65
|
+
|
|
66
|
+
-- an event's deliveries (the retention sweep's check, and the cascade when it deletes the event)
|
|
67
|
+
CREATE INDEX IF NOT EXISTS automation_event_deliveries_event_idx
|
|
68
|
+
ON automation_event_deliveries (event_id);
|
|
69
|
+
|
|
70
|
+
-- the deliveries a run served (the subject rate counts a pair's runs through them)
|
|
71
|
+
CREATE INDEX IF NOT EXISTS automation_event_deliveries_run_idx
|
|
72
|
+
ON automation_event_deliveries (automation_run_id);
|
|
73
|
+
|
|
74
|
+
DROP POLICY IF EXISTS org_scope ON automation_event_deliveries;
|
|
75
|
+
CREATE POLICY org_scope ON automation_event_deliveries USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
|
|
76
|
+
|
|
77
|
+
CREATE TABLE IF NOT EXISTS automation_conversations (
|
|
78
|
+
org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
|
|
79
|
+
automation_id text NOT NULL REFERENCES automations(id) ON DELETE CASCADE,
|
|
80
|
+
subject_kind text NOT NULL,
|
|
81
|
+
subject_id text NOT NULL,
|
|
82
|
+
conversation_id text NOT NULL,
|
|
83
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
84
|
+
PRIMARY KEY (automation_id, subject_kind, subject_id)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
DROP POLICY IF EXISTS org_scope ON automation_conversations;
|
|
88
|
+
CREATE POLICY org_scope ON automation_conversations USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
|
|
89
|
+
|
|
90
|
+
-- Automations: who made it, whom it acts as (reserved for agent principals; null = `account_id`),
|
|
91
|
+
-- and what an unattended question does (null = the default).
|
|
92
|
+
ALTER TABLE automations ADD COLUMN IF NOT EXISTS origin text NOT NULL DEFAULT 'person';
|
|
93
|
+
ALTER TABLE automations DROP CONSTRAINT IF EXISTS automations_origin_check;
|
|
94
|
+
ALTER TABLE automations ADD CONSTRAINT automations_origin_check
|
|
95
|
+
CHECK (origin IN ('person', 'acceptance'));
|
|
96
|
+
ALTER TABLE automations ADD COLUMN IF NOT EXISTS principal jsonb;
|
|
97
|
+
ALTER TABLE automations ADD COLUMN IF NOT EXISTS unattended_ask text;
|
|
98
|
+
ALTER TABLE automations DROP CONSTRAINT IF EXISTS automations_unattended_ask_check;
|
|
99
|
+
ALTER TABLE automations ADD CONSTRAINT automations_unattended_ask_check
|
|
100
|
+
CHECK (unattended_ask IN ('fail', 'wait'));
|
|
101
|
+
|
|
102
|
+
-- The mode CHECK of 0113 (renamed in 0188) gains `subject`: drop and add in this file's one
|
|
103
|
+
-- transaction.
|
|
104
|
+
ALTER TABLE automations DROP CONSTRAINT IF EXISTS automations_mode_check;
|
|
105
|
+
ALTER TABLE automations ADD CONSTRAINT automations_mode_check
|
|
106
|
+
CHECK (mode IN ('new', 'conversation', 'chat', 'subject'));
|
|
107
|
+
|
|
108
|
+
-- Runs: the trigger key, backfilled from the tick as JS `Date.toISOString()` text, then required.
|
|
109
|
+
ALTER TABLE automation_runs ADD COLUMN IF NOT EXISTS trigger_key text;
|
|
110
|
+
UPDATE automation_runs
|
|
111
|
+
SET trigger_key = to_char(scheduled_for AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')
|
|
112
|
+
WHERE trigger_key IS NULL AND scheduled_for IS NOT NULL;
|
|
113
|
+
ALTER TABLE automation_runs ALTER COLUMN trigger_key SET NOT NULL;
|
|
114
|
+
ALTER TABLE automation_runs ALTER COLUMN scheduled_for DROP NOT NULL;
|
|
115
|
+
-- when the run was recorded: an event run has no tick, and `fired_at` is its claim (null until
|
|
116
|
+
-- the fire job claims it), so the run lists and the subject rate order and count by this
|
|
117
|
+
ALTER TABLE automation_runs ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT now();
|
|
118
|
+
|
|
119
|
+
-- The exactly-once guard moves from the tick to the trigger key (trial runs stay free of it).
|
|
120
|
+
DROP INDEX IF EXISTS automation_runs_tick_uq;
|
|
121
|
+
CREATE UNIQUE INDEX IF NOT EXISTS automation_runs_trigger_uq
|
|
122
|
+
ON automation_runs (automation_id, trigger_key) WHERE NOT trial;
|
|
123
|
+
|
|
124
|
+
-- The skip reason CHECK of 0128 (renamed in 0188) gains the event run reason.
|
|
125
|
+
ALTER TABLE automation_runs DROP CONSTRAINT IF EXISTS automation_runs_skip_reason_check;
|
|
126
|
+
ALTER TABLE automation_runs ADD CONSTRAINT automation_runs_skip_reason_check
|
|
127
|
+
CHECK (skip_reason IN ('missed', 'overlap', 'rate_limited', 'queue_paused',
|
|
128
|
+
'removed', 'device_offline', 'creator_inactive', 'agent_gone', 'target_gone',
|
|
129
|
+
'conversation_gone', 'org_disabled', 'unsupported_target', 'task_deleted', 'task_paused',
|
|
130
|
+
'plugin_disabled', 'subject_rate'));
|
|
131
|
+
|
|
132
|
+
-- A conversation's subject ({ source, kind, id, title }, §4.5); the event behind a run; the event
|
|
133
|
+
-- marker of a queued automation message.
|
|
134
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS subject jsonb;
|
|
135
|
+
ALTER TABLE runs ADD COLUMN IF NOT EXISTS trigger_event_id text;
|
|
136
|
+
ALTER TABLE conversation_queue ADD COLUMN IF NOT EXISTS automation_event jsonb;
|
|
@@ -1,509 +0,0 @@
|
|
|
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 { ScheduledTasksService, } from "../../schedules/scheduled-tasks.service.js";
|
|
13
|
-
import { calendarInputOf, createInputOf, grantsOf, ScheduleCalendarQuery, ScheduleChatTargetsQuery, ScheduleCreateBody, ScheduleGrantableQuery, ScheduleGrantParams, ScheduleGrantsBody, ScheduleListQuery, ScheduleParams, ScheduleRunBody, ScheduleRunsQuery, ScheduleUpdateBody, updateInputOf, } from "../../schedules/schedules.schemas.js";
|
|
14
|
-
import { defineOperation } from "../operation.js";
|
|
15
|
-
import { PlatformOperations } from "../registry.js";
|
|
16
|
-
import { named, orElse } from "./summary.js";
|
|
17
|
-
const ListQuery = ScheduleListQuery;
|
|
18
|
-
const CreateBody = ScheduleCreateBody;
|
|
19
|
-
const UpdateBody = ScheduleUpdateBody;
|
|
20
|
-
const RunBody = ScheduleRunBody;
|
|
21
|
-
const RunsQuery = ScheduleRunsQuery;
|
|
22
|
-
const GrantsBody = ScheduleGrantsBody;
|
|
23
|
-
const Id = ScheduleParams.shape.id;
|
|
24
|
-
const ToolKey = ScheduleGrantParams.shape.toolKey;
|
|
25
|
-
const TaskId = z.object({ scheduleId: Id }).strict();
|
|
26
|
-
const EXAMPLE_ID = "7b2d4f60-3a1e-4c85-9e07-5d8f1a2b3c4d";
|
|
27
|
-
/** A task as `schedules.list` shows it: the schedule, the state and the next run. */
|
|
28
|
-
function row(t) {
|
|
29
|
-
return {
|
|
30
|
-
...(t.lastRun !== undefined && { lastRun: t.lastRun }),
|
|
31
|
-
id: t.id,
|
|
32
|
-
name: t.name,
|
|
33
|
-
agentId: t.agentId,
|
|
34
|
-
status: t.status,
|
|
35
|
-
pauseReason: t.pauseReason,
|
|
36
|
-
trigger: t.trigger,
|
|
37
|
-
mode: t.mode,
|
|
38
|
-
nextRunAt: t.nextRunAt,
|
|
39
|
-
creator: t.accountId,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const runRow = (r) => ({
|
|
43
|
-
id: r.id,
|
|
44
|
-
scheduledFor: r.scheduledFor,
|
|
45
|
-
firedAt: r.firedAt,
|
|
46
|
-
trial: r.trial,
|
|
47
|
-
status: r.status,
|
|
48
|
-
skipReason: r.skipReason,
|
|
49
|
-
error: r.error,
|
|
50
|
-
conversationId: r.conversationId,
|
|
51
|
-
missingGrants: r.missingGrants,
|
|
52
|
-
});
|
|
53
|
-
/**
|
|
54
|
-
* Scheduled-task operations of the `Platform` tool (scheduled tasks spec §10): the same service
|
|
55
|
-
* as the HTTP routes. Writes are `personal`. Creating or changing a task and its approved tools
|
|
56
|
-
* are never remembered (`rememberable: false`): an approval, remembered or granted to a task,
|
|
57
|
-
* must never let an unattended run create or widen a task. Delete, run and resume are never
|
|
58
|
-
* remembered either. List, pause and delete are `org.read` like their routes: a creator demoted
|
|
59
|
-
* to guest can still see and stop their own tasks (the service decides by ownership).
|
|
60
|
-
*/
|
|
61
|
-
let SchedulesOperations = class SchedulesOperations {
|
|
62
|
-
registry;
|
|
63
|
-
tasks;
|
|
64
|
-
constructor(registry, tasks) {
|
|
65
|
-
this.registry = registry;
|
|
66
|
-
this.tasks = tasks;
|
|
67
|
-
}
|
|
68
|
-
/** The caller as the service expects (it reads the live role itself). */
|
|
69
|
-
actor(ctx) {
|
|
70
|
-
return { accountId: ctx.actorAccountId };
|
|
71
|
-
}
|
|
72
|
-
/** The task's name for a card; its id when it cannot be read. */
|
|
73
|
-
label(ctx, id) {
|
|
74
|
-
return orElse(async () => named((await this.tasks.get(ctx.orgId, this.actor(ctx), id)).name), id);
|
|
75
|
-
}
|
|
76
|
-
onModuleInit() {
|
|
77
|
-
this.registry.register([
|
|
78
|
-
defineOperation({
|
|
79
|
-
id: "schedules.list",
|
|
80
|
-
description: "List your scheduled tasks: 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.",
|
|
81
|
-
input: ListQuery,
|
|
82
|
-
example: {},
|
|
83
|
-
// a creator demoted to guest still lists their own tasks (to pause or delete them)
|
|
84
|
-
authz: { orgAction: "org.read" },
|
|
85
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules"],
|
|
86
|
-
confirm: "read",
|
|
87
|
-
errors: [
|
|
88
|
-
{
|
|
89
|
-
code: "forbidden",
|
|
90
|
-
next: "Listing every task needs the org admin role: call without all, or ask an org admin.",
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
run: async (input, ctx) => {
|
|
94
|
-
const items = await this.tasks.list(ctx.orgId, this.actor(ctx), {
|
|
95
|
-
all: input.all === "true",
|
|
96
|
-
...(input.conversationId !== undefined && { conversationId: input.conversationId }),
|
|
97
|
-
});
|
|
98
|
-
return { items: items.map(row) };
|
|
99
|
-
},
|
|
100
|
-
}),
|
|
101
|
-
defineOperation({
|
|
102
|
-
id: "schedules.calendar",
|
|
103
|
-
description: "Your scheduled task 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.",
|
|
104
|
-
input: ScheduleCalendarQuery,
|
|
105
|
-
example: {
|
|
106
|
-
from: "2026-11-09T00:00:00+08:00",
|
|
107
|
-
to: "2026-11-16T00:00:00+08:00",
|
|
108
|
-
timeZone: "Asia/Shanghai",
|
|
109
|
-
},
|
|
110
|
-
authz: { orgAction: "org.read" },
|
|
111
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules/calendar"],
|
|
112
|
-
confirm: "read",
|
|
113
|
-
errors: [
|
|
114
|
-
{
|
|
115
|
-
code: "validation_failed",
|
|
116
|
-
next: "Narrow the range to 43 days or less (2 days with taskId), with from before to.",
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
code: "forbidden",
|
|
120
|
-
next: "Reading every task needs the org admin role: call without all, or ask an org admin.",
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
code: "schedule.not_found",
|
|
124
|
-
next: "Check taskId with schedules.list: members see only their own tasks; an org admin finds another member's task id with schedules.list all=true, then reads it here by taskId (all is not needed).",
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
run: async (input, ctx) => {
|
|
128
|
-
const answer = await this.tasks.calendar(ctx.orgId, this.actor(ctx), calendarInputOf(input));
|
|
129
|
-
return {
|
|
130
|
-
...answer,
|
|
131
|
-
tasks: answer.tasks.map((t) => ({
|
|
132
|
-
id: t.id,
|
|
133
|
-
name: t.name,
|
|
134
|
-
agentId: t.agentId,
|
|
135
|
-
status: t.status,
|
|
136
|
-
})),
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
}),
|
|
140
|
-
defineOperation({
|
|
141
|
-
id: "schedules.chat-targets",
|
|
142
|
-
description: "The IM chats you can point a chat-mode scheduled task 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 schedules.create, and the connection's agentId, which the task must use.",
|
|
143
|
-
input: ScheduleChatTargetsQuery,
|
|
144
|
-
example: {},
|
|
145
|
-
authz: { orgAction: "schedules.use" },
|
|
146
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules/chat-targets"],
|
|
147
|
-
confirm: "read",
|
|
148
|
-
errors: [],
|
|
149
|
-
run: async (_input, ctx) => ({
|
|
150
|
-
items: await this.tasks.chatTargets(ctx.orgId, ctx.actorAccountId),
|
|
151
|
-
}),
|
|
152
|
-
}),
|
|
153
|
-
defineOperation({
|
|
154
|
-
id: "schedules.grantable-tools",
|
|
155
|
-
description: "An agent's tools as a scheduled task 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.",
|
|
156
|
-
input: ScheduleGrantableQuery,
|
|
157
|
-
example: { agentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20" },
|
|
158
|
-
authz: { orgAction: "schedules.use" },
|
|
159
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules/grantable-tools"],
|
|
160
|
-
confirm: "read",
|
|
161
|
-
errors: [
|
|
162
|
-
{
|
|
163
|
-
code: "agent.not_found",
|
|
164
|
-
next: "Check the agent id: it must be an agent you can use in this org.",
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
run: async (input, ctx) => ({
|
|
168
|
-
items: await this.tasks.grantableTools(ctx.orgId, ctx.actorAccountId, input.agentId),
|
|
169
|
-
}),
|
|
170
|
-
}),
|
|
171
|
-
defineOperation({
|
|
172
|
-
id: "schedules.get",
|
|
173
|
-
description: "Read one scheduled task in full: prompt, schedule, target, model, effort, device, status, next run, expiry. Takes the id from schedules.list.",
|
|
174
|
-
input: TaskId,
|
|
175
|
-
example: { scheduleId: EXAMPLE_ID },
|
|
176
|
-
authz: { orgAction: "schedules.use" },
|
|
177
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules/:id"],
|
|
178
|
-
renames: { scheduleId: "id" },
|
|
179
|
-
confirm: "read",
|
|
180
|
-
errors: [
|
|
181
|
-
{
|
|
182
|
-
code: "schedule.not_found",
|
|
183
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
184
|
-
},
|
|
185
|
-
],
|
|
186
|
-
run: async (input, ctx) => ({
|
|
187
|
-
task: await this.tasks.get(ctx.orgId, this.actor(ctx), input.scheduleId),
|
|
188
|
-
}),
|
|
189
|
-
}),
|
|
190
|
-
defineOperation({
|
|
191
|
-
id: "schedules.create",
|
|
192
|
-
description: "Create a scheduled task: an agent runs the prompt on a 5-field cron (or once at a local date-time) as you, unattended. The task's time zone is yours; timeZone is only the fallback when you have none set. mode: new (a conversation per run), conversation (post into one conversation) or chat (an IM chat). model ({ provider, model } like an agent definition's), effort and deviceId are for mode new only; a conversation or chat task runs with that conversation's model. Without expiresAt a cron task ends after the org's default expiry, when the org sets one. grants pre-approve tools the unattended run may use.",
|
|
193
|
-
input: CreateBody,
|
|
194
|
-
example: {
|
|
195
|
-
agentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20",
|
|
196
|
-
name: "Daily digest",
|
|
197
|
-
prompt: "Summarize yesterday's activity.",
|
|
198
|
-
trigger: { kind: "cron", expr: "0 9 * * *" },
|
|
199
|
-
mode: "new",
|
|
200
|
-
},
|
|
201
|
-
authz: { orgAction: "schedules.use" },
|
|
202
|
-
mirrors: ["POST /api/v1/orgs/:orgId/schedules"],
|
|
203
|
-
confirm: "personal",
|
|
204
|
-
// an unattended run must never create or widen a task through a remembered approval
|
|
205
|
-
rememberable: false,
|
|
206
|
-
errors: [
|
|
207
|
-
{
|
|
208
|
-
code: "schedule.disabled",
|
|
209
|
-
next: {
|
|
210
|
-
orgAdmin: "Turn scheduled tasks on in the org settings.",
|
|
211
|
-
member: "Scheduled tasks are off here; ask an org admin.",
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
code: "schedule.limit_reached",
|
|
216
|
-
next: "Delete a task you no longer need with schedules.delete, or pause and edit an existing one.",
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
code: "schedule.target_invalid",
|
|
220
|
-
next: "Fix the target named in the message (conversation, chat or device) and call again.",
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
code: "schedule.grant_not_allowed",
|
|
224
|
-
next: "Drop that grant: the task will ask for it as a person when it runs attended, or ask an org admin.",
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
summary: (i) => ({
|
|
228
|
-
zh: `创建定时任务「${named(i.name)}」(${i.trigger.kind === "cron" ? `cron ${named(i.trigger.expr)}` : `一次性 ${named(i.trigger.at)}`}),之后无人值守地以你的身份运行`,
|
|
229
|
-
en: `Create scheduled task "${named(i.name)}" (${i.trigger.kind === "cron" ? `cron ${named(i.trigger.expr)}` : `once at ${named(i.trigger.at)}`}), then run unattended as you`,
|
|
230
|
-
}),
|
|
231
|
-
run: async (input, ctx) => {
|
|
232
|
-
const { input: create, browserTimeZone } = createInputOf(input);
|
|
233
|
-
return {
|
|
234
|
-
task: await this.tasks.create(ctx.orgId, ctx.actorAccountId, create, browserTimeZone),
|
|
235
|
-
};
|
|
236
|
-
},
|
|
237
|
-
}),
|
|
238
|
-
defineOperation({
|
|
239
|
-
id: "schedules.update",
|
|
240
|
-
description: "Change one of your own scheduled tasks (name, prompt, schedule, time zone, target, model, effort, device, expiry; null clears an optional field, and a null expiry on a cron task takes the org's default expiry when set). model, effort and deviceId are 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 schedules.list.",
|
|
241
|
-
input: UpdateBody.extend({ scheduleId: Id }).strict(),
|
|
242
|
-
example: { scheduleId: EXAMPLE_ID, prompt: "Summarize the last two days." },
|
|
243
|
-
authz: { orgAction: "schedules.use" },
|
|
244
|
-
mirrors: ["PATCH /api/v1/orgs/:orgId/schedules/:id"],
|
|
245
|
-
renames: { scheduleId: "id" },
|
|
246
|
-
confirm: "personal",
|
|
247
|
-
rememberable: false,
|
|
248
|
-
errors: [
|
|
249
|
-
{
|
|
250
|
-
code: "schedule.not_found",
|
|
251
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
code: "schedule.forbidden",
|
|
255
|
-
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
code: "schedule.target_invalid",
|
|
259
|
-
next: "Fix the target named in the message and call again.",
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
summary: async (i, ctx) => {
|
|
263
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
264
|
-
return {
|
|
265
|
-
zh: `修改定时任务「${n}」`,
|
|
266
|
-
en: `Change scheduled task "${n}"`,
|
|
267
|
-
};
|
|
268
|
-
},
|
|
269
|
-
run: async (input, ctx) => {
|
|
270
|
-
const { scheduleId, ...patch } = input;
|
|
271
|
-
return {
|
|
272
|
-
task: await this.tasks.update(ctx.orgId, ctx.actorAccountId, scheduleId, updateInputOf(patch)),
|
|
273
|
-
};
|
|
274
|
-
},
|
|
275
|
-
}),
|
|
276
|
-
defineOperation({
|
|
277
|
-
id: "schedules.delete",
|
|
278
|
-
description: "Delete a scheduled task (yours; an org admin can delete any). Takes the id from schedules.list.",
|
|
279
|
-
input: TaskId,
|
|
280
|
-
example: { scheduleId: EXAMPLE_ID },
|
|
281
|
-
authz: { orgAction: "org.read" },
|
|
282
|
-
mirrors: ["DELETE /api/v1/orgs/:orgId/schedules/:id"],
|
|
283
|
-
renames: { scheduleId: "id" },
|
|
284
|
-
confirm: "personal",
|
|
285
|
-
rememberable: false,
|
|
286
|
-
errors: [
|
|
287
|
-
{
|
|
288
|
-
code: "schedule.not_found",
|
|
289
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
summary: async (i, ctx) => {
|
|
293
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
294
|
-
return { zh: `删除定时任务「${n}」`, en: `Delete scheduled task "${n}"` };
|
|
295
|
-
},
|
|
296
|
-
run: async (input, ctx) => {
|
|
297
|
-
await this.tasks.remove(ctx.orgId, this.actor(ctx), input.scheduleId);
|
|
298
|
-
return { id: input.scheduleId, deleted: true };
|
|
299
|
-
},
|
|
300
|
-
}),
|
|
301
|
-
defineOperation({
|
|
302
|
-
id: "schedules.pause",
|
|
303
|
-
description: "Pause a scheduled task so it stops firing (yours; an org admin can pause any, and the creator is told). Resume it with schedules.resume. Takes the id from schedules.list.",
|
|
304
|
-
input: TaskId,
|
|
305
|
-
example: { scheduleId: EXAMPLE_ID },
|
|
306
|
-
authz: { orgAction: "org.read" },
|
|
307
|
-
mirrors: ["POST /api/v1/orgs/:orgId/schedules/:id/pause"],
|
|
308
|
-
renames: { scheduleId: "id" },
|
|
309
|
-
confirm: "personal",
|
|
310
|
-
errors: [
|
|
311
|
-
{
|
|
312
|
-
code: "schedule.not_found",
|
|
313
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
314
|
-
},
|
|
315
|
-
],
|
|
316
|
-
summary: async (i, ctx) => {
|
|
317
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
318
|
-
return { zh: `暂停定时任务「${n}」`, en: `Pause scheduled task "${n}"` };
|
|
319
|
-
},
|
|
320
|
-
run: async (input, ctx) => ({
|
|
321
|
-
task: row(await this.tasks.pause(ctx.orgId, this.actor(ctx), input.scheduleId)),
|
|
322
|
-
}),
|
|
323
|
-
}),
|
|
324
|
-
defineOperation({
|
|
325
|
-
id: "schedules.resume",
|
|
326
|
-
description: "Resume a paused scheduled task: the next run is computed from now (missed ticks are not caught up). An ended task cannot be resumed. Takes the id from schedules.list.",
|
|
327
|
-
input: TaskId,
|
|
328
|
-
example: { scheduleId: EXAMPLE_ID },
|
|
329
|
-
authz: { orgAction: "schedules.use" },
|
|
330
|
-
mirrors: ["POST /api/v1/orgs/:orgId/schedules/:id/resume"],
|
|
331
|
-
renames: { scheduleId: "id" },
|
|
332
|
-
confirm: "personal",
|
|
333
|
-
// a remembered resume would let an unattended run restart a task a person stopped
|
|
334
|
-
rememberable: false,
|
|
335
|
-
errors: [
|
|
336
|
-
{
|
|
337
|
-
code: "schedule.not_found",
|
|
338
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
code: "schedule.once_in_past",
|
|
342
|
-
next: "Its time has passed: set a new time with schedules.update, then resume.",
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
code: "schedule.disabled",
|
|
346
|
-
next: {
|
|
347
|
-
orgAdmin: "Turn scheduled tasks on in the org settings.",
|
|
348
|
-
member: "Scheduled tasks are off here; ask an org admin.",
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
],
|
|
352
|
-
summary: async (i, ctx) => {
|
|
353
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
354
|
-
return { zh: `恢复定时任务「${n}」`, en: `Resume scheduled task "${n}"` };
|
|
355
|
-
},
|
|
356
|
-
run: async (input, ctx) => ({
|
|
357
|
-
task: row(await this.tasks.resume(ctx.orgId, this.actor(ctx), input.scheduleId)),
|
|
358
|
-
}),
|
|
359
|
-
}),
|
|
360
|
-
defineOperation({
|
|
361
|
-
id: "schedules.run",
|
|
362
|
-
description: "Run one of your own scheduled tasks 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. Takes the id from schedules.list.",
|
|
363
|
-
input: RunBody.extend({ scheduleId: Id }).strict(),
|
|
364
|
-
example: { scheduleId: EXAMPLE_ID, trial: true },
|
|
365
|
-
authz: { orgAction: "schedules.use" },
|
|
366
|
-
mirrors: ["POST /api/v1/orgs/:orgId/schedules/:id/run"],
|
|
367
|
-
renames: { scheduleId: "id" },
|
|
368
|
-
confirm: "personal",
|
|
369
|
-
// a remembered run would let an unattended run trigger other tasks
|
|
370
|
-
rememberable: false,
|
|
371
|
-
errors: [
|
|
372
|
-
{
|
|
373
|
-
code: "schedule.not_found",
|
|
374
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
code: "schedule.forbidden",
|
|
378
|
-
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
379
|
-
},
|
|
380
|
-
{ code: "conflict", next: "The task has ended or is being run: wait, or edit it first." },
|
|
381
|
-
],
|
|
382
|
-
summary: async (i, ctx) => {
|
|
383
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
384
|
-
return {
|
|
385
|
-
zh: `立即运行定时任务「${n}」${i.trial === true ? "(试运行)" : ""}`,
|
|
386
|
-
en: `Run scheduled task "${n}" now${i.trial === true ? " as a trial" : ""}`,
|
|
387
|
-
};
|
|
388
|
-
},
|
|
389
|
-
run: async (input, ctx) => ({
|
|
390
|
-
run: runRow(await this.tasks.runNow(ctx.orgId, ctx.actorAccountId, input.scheduleId, {
|
|
391
|
-
trial: input.trial === true,
|
|
392
|
-
})),
|
|
393
|
-
}),
|
|
394
|
-
}),
|
|
395
|
-
defineOperation({
|
|
396
|
-
id: "schedules.runs",
|
|
397
|
-
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 schedules.list.",
|
|
398
|
-
input: RunsQuery.extend({ scheduleId: Id }).strict(),
|
|
399
|
-
example: { scheduleId: EXAMPLE_ID },
|
|
400
|
-
authz: { orgAction: "schedules.use" },
|
|
401
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules/:id/runs"],
|
|
402
|
-
renames: { scheduleId: "id" },
|
|
403
|
-
confirm: "read",
|
|
404
|
-
errors: [
|
|
405
|
-
{
|
|
406
|
-
code: "schedule.not_found",
|
|
407
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
408
|
-
},
|
|
409
|
-
],
|
|
410
|
-
run: async (input, ctx) => ({
|
|
411
|
-
items: (await this.tasks.runs(ctx.orgId, this.actor(ctx), input.scheduleId, input.limit)).map(runRow),
|
|
412
|
-
}),
|
|
413
|
-
}),
|
|
414
|
-
defineOperation({
|
|
415
|
-
id: "schedules.grants-list",
|
|
416
|
-
description: "The tools approved in advance for a scheduled task (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 schedules.list.",
|
|
417
|
-
input: TaskId,
|
|
418
|
-
example: { scheduleId: EXAMPLE_ID },
|
|
419
|
-
authz: { orgAction: "schedules.use" },
|
|
420
|
-
mirrors: ["GET /api/v1/orgs/:orgId/schedules/:id/grants"],
|
|
421
|
-
renames: { scheduleId: "id" },
|
|
422
|
-
confirm: "read",
|
|
423
|
-
errors: [
|
|
424
|
-
{
|
|
425
|
-
code: "schedule.not_found",
|
|
426
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
427
|
-
},
|
|
428
|
-
],
|
|
429
|
-
run: async (input, ctx) => ({
|
|
430
|
-
items: (await this.tasks.grants(ctx.orgId, this.actor(ctx), input.scheduleId)).map((g) => ({ toolKey: g.toolKey, connectorId: g.connectorId, stale: g.stale })),
|
|
431
|
-
}),
|
|
432
|
-
}),
|
|
433
|
-
defineOperation({
|
|
434
|
-
id: "schedules.grants-add",
|
|
435
|
-
description: "Approve tools in advance for one of your own scheduled tasks: 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 schedules.list.",
|
|
436
|
-
input: GrantsBody.extend({ scheduleId: Id }).strict(),
|
|
437
|
-
example: { scheduleId: EXAMPLE_ID, grants: [{ toolKey: "WebFetch" }] },
|
|
438
|
-
authz: { orgAction: "schedules.use" },
|
|
439
|
-
mirrors: ["POST /api/v1/orgs/:orgId/schedules/:id/grants"],
|
|
440
|
-
renames: { scheduleId: "id" },
|
|
441
|
-
confirm: "personal",
|
|
442
|
-
rememberable: false,
|
|
443
|
-
errors: [
|
|
444
|
-
{
|
|
445
|
-
code: "schedule.not_found",
|
|
446
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
code: "schedule.forbidden",
|
|
450
|
-
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
code: "schedule.grant_not_allowed",
|
|
454
|
-
next: "Drop that tool: it cannot be approved in advance for a task.",
|
|
455
|
-
},
|
|
456
|
-
],
|
|
457
|
-
summary: async (i, ctx) => {
|
|
458
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
459
|
-
const keys = i.grants.map((g) => named(g.toolKey)).join(", ");
|
|
460
|
-
return {
|
|
461
|
-
zh: `为定时任务「${n}」预先批准工具:${keys}`,
|
|
462
|
-
en: `Approve tools in advance for scheduled task "${n}": ${keys}`,
|
|
463
|
-
};
|
|
464
|
-
},
|
|
465
|
-
run: async (input, ctx) => ({
|
|
466
|
-
items: (await this.tasks.addGrants(ctx.orgId, ctx.actorAccountId, input.scheduleId, grantsOf(input.grants))).map((g) => ({ toolKey: g.toolKey, connectorId: g.connectorId })),
|
|
467
|
-
}),
|
|
468
|
-
}),
|
|
469
|
-
defineOperation({
|
|
470
|
-
id: "schedules.grants-remove",
|
|
471
|
-
description: "Remove a tool's advance approval from one of your own scheduled tasks (nothing happens if it had none): the unattended run is then refused that tool. Takes the id from schedules.list.",
|
|
472
|
-
input: z.object({ scheduleId: Id, toolKey: ToolKey }).strict(),
|
|
473
|
-
example: { scheduleId: EXAMPLE_ID, toolKey: "WebFetch" },
|
|
474
|
-
authz: { orgAction: "schedules.use" },
|
|
475
|
-
mirrors: ["DELETE /api/v1/orgs/:orgId/schedules/:id/grants/:toolKey"],
|
|
476
|
-
renames: { scheduleId: "id" },
|
|
477
|
-
confirm: "personal",
|
|
478
|
-
rememberable: false,
|
|
479
|
-
errors: [
|
|
480
|
-
{
|
|
481
|
-
code: "schedule.not_found",
|
|
482
|
-
next: "Check the id with schedules.list: you only see your own tasks (org admins see all with all=true).",
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
code: "schedule.forbidden",
|
|
486
|
-
next: "Only the creator can change a task: ask them, or an org admin can pause it.",
|
|
487
|
-
},
|
|
488
|
-
],
|
|
489
|
-
summary: async (i, ctx) => {
|
|
490
|
-
const n = await this.label(ctx, i.scheduleId);
|
|
491
|
-
return {
|
|
492
|
-
zh: `撤销定时任务「${n}」对工具 ${named(i.toolKey)} 的预先批准`,
|
|
493
|
-
en: `Remove the advance approval of ${named(i.toolKey)} from scheduled task "${n}"`,
|
|
494
|
-
};
|
|
495
|
-
},
|
|
496
|
-
run: async (input, ctx) => {
|
|
497
|
-
await this.tasks.removeGrant(ctx.orgId, ctx.actorAccountId, input.scheduleId, input.toolKey);
|
|
498
|
-
return { id: input.scheduleId, toolKey: input.toolKey, removed: true };
|
|
499
|
-
},
|
|
500
|
-
}),
|
|
501
|
-
]);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
SchedulesOperations = __decorate([
|
|
505
|
-
Injectable(),
|
|
506
|
-
__param(0, Inject(PlatformOperations)),
|
|
507
|
-
__param(1, Inject(ScheduledTasksService))
|
|
508
|
-
], SchedulesOperations);
|
|
509
|
-
export { SchedulesOperations };
|