@capybara-hq/kernel 0.1.0-rc.21 → 0.1.0-rc.22
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/admin-agents.d.ts +16 -3
- package/dist/agents/admin-agents.js +65 -7
- package/dist/agents/agents.schemas.d.ts +24 -6
- package/dist/agents/agents.service.d.ts +4 -3
- package/dist/agents/agents.service.js +39 -26
- package/dist/agents/definition.d.ts +44 -6
- package/dist/agents/definition.js +86 -18
- package/dist/agents/from-template.d.ts +6 -3
- package/dist/agents/from-template.js +57 -44
- package/dist/agents/org-templates.js +97 -41
- package/dist/agents/templates.d.ts +6 -0
- package/dist/agents/templates.js +15 -1
- package/dist/catalog/admin-catalog.controller.d.ts +2 -4
- package/dist/catalog/admin-catalog.controller.js +2 -6
- package/dist/catalog/catalog.module.js +3 -0
- package/dist/catalog/claude/report.d.ts +9 -2
- package/dist/catalog/claude/report.js +1 -0
- package/dist/catalog/claude/translate.js +1 -1
- package/dist/catalog/component-promotion.js +1 -2
- package/dist/catalog/component-state.d.ts +13 -1
- package/dist/catalog/component-state.js +14 -5
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/marketplaces.service.js +2 -1
- package/dist/catalog/org-catalog.controller.d.ts +13 -3
- package/dist/catalog/org-catalog.controller.js +26 -4
- package/dist/catalog/org-catalog.schemas.d.ts +13 -0
- package/dist/catalog/org-catalog.schemas.js +34 -0
- package/dist/catalog/org-plugin-uploads.controller.js +0 -1
- package/dist/catalog/org-plugin-uploads.d.ts +0 -1
- package/dist/catalog/org-plugin-uploads.js +0 -3
- package/dist/catalog/org-plugin-uploads.schemas.d.ts +0 -1
- package/dist/catalog/org-plugin-uploads.schemas.js +0 -2
- package/dist/catalog/platform-components.d.ts +0 -1
- package/dist/catalog/platform-components.js +3 -8
- package/dist/catalog/plugin-import.d.ts +0 -8
- package/dist/catalog/plugin-import.js +4 -35
- package/dist/catalog/plugin-install.d.ts +2 -2
- package/dist/catalog/plugin-install.js +2 -2
- package/dist/catalog/plugin-package.d.ts +7 -0
- package/dist/catalog/plugin-package.js +27 -1
- package/dist/catalog/plugin-upgrade.d.ts +5 -6
- package/dist/catalog/plugin-upgrade.js +5 -23
- package/dist/catalog/requests.service.d.ts +66 -10
- package/dist/catalog/requests.service.js +196 -15
- package/dist/channels/actions.d.ts +2 -0
- package/dist/channels/actions.js +19 -4
- package/dist/channels/cards.d.ts +16 -2
- package/dist/channels/cards.js +40 -7
- package/dist/channels/channels.module.js +3 -0
- package/dist/channels/outbound.d.ts +22 -1
- package/dist/channels/outbound.js +116 -7
- package/dist/channels/phrases.d.ts +25 -0
- package/dist/channels/phrases.js +19 -0
- package/dist/channels/threads.d.ts +12 -0
- package/dist/channels/threads.js +34 -0
- package/dist/config/schema.d.ts +23 -1
- package/dist/config/schema.js +105 -5
- package/dist/conversations/conversations.service.d.ts +42 -9
- package/dist/conversations/conversations.service.js +57 -25
- package/dist/conversations/events.d.ts +106 -11
- package/dist/conversations/events.js +121 -18
- package/dist/conversations/message-context.d.ts +6 -3
- package/dist/conversations/message-context.js +14 -10
- package/dist/conversations/queue.d.ts +15 -2
- package/dist/conversations/queue.js +22 -3
- package/dist/conversations/queue.service.d.ts +12 -6
- package/dist/conversations/queue.service.js +36 -13
- package/dist/db/kernel-schema.d.ts +105 -3
- package/dist/devices/conversation-devices.d.ts +8 -1
- package/dist/devices/conversation-devices.js +8 -0
- package/dist/devices/devices.controller.d.ts +21 -4
- package/dist/devices/devices.controller.js +46 -8
- package/dist/devices/devices.schemas.d.ts +9 -1
- package/dist/devices/devices.schemas.js +11 -3
- package/dist/devices/devices.service.d.ts +176 -4
- package/dist/devices/devices.service.js +341 -6
- package/dist/devices/dto.d.ts +56 -3
- package/dist/devices/dto.js +51 -1
- package/dist/devices/public-suffix.d.ts +6 -0
- package/dist/devices/public-suffix.js +79 -0
- package/dist/errors.d.ts +46 -5
- package/dist/errors.js +46 -5
- package/dist/evals/reconstruct.d.ts +18 -13
- package/dist/evals/reconstruct.js +50 -36
- package/dist/evals/recorded-tools.d.ts +7 -7
- package/dist/evals/recorded-tools.js +4 -3
- package/dist/evals/trajectory.d.ts +6 -1
- package/dist/evals/trajectory.js +7 -0
- package/dist/extensions/package.js +2 -2
- package/dist/http/api.module.js +5 -0
- package/dist/inbox/inbox.module.js +2 -1
- package/dist/inbox/inbox.service.d.ts +19 -4
- package/dist/inbox/inbox.service.js +14 -3
- package/dist/infra/config/kernel-config.service.js +11 -0
- package/dist/infra/events/kernel-events.d.ts +2 -1
- package/dist/local-devices/device-policy.service.d.ts +65 -0
- package/dist/local-devices/device-policy.service.js +217 -0
- package/dist/local-devices/local-device-gateway.js +4 -1
- package/dist/local-devices/local-device-provider.d.ts +40 -3
- package/dist/local-devices/local-device-provider.js +109 -7
- package/dist/local-devices/local-devices.module.d.ts +2 -1
- package/dist/local-devices/local-devices.module.js +19 -3
- package/dist/local-devices/machines.d.ts +14 -3
- package/dist/local-devices/machines.js +41 -3
- package/dist/local-devices/network-grants.d.ts +104 -0
- package/dist/local-devices/network-grants.js +288 -0
- package/dist/local-devices/policy-summary.d.ts +20 -0
- package/dist/local-devices/policy-summary.js +63 -0
- package/dist/orgs/orgs.module.js +4 -10
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +4 -0
- package/dist/orgs/settings.controller.js +2 -1
- package/dist/orgs/settings.service.d.ts +164 -12
- package/dist/orgs/settings.service.js +212 -24
- package/dist/platform/exclusions.js +11 -1
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin-items.ops.js +1 -1
- package/dist/platform/ops/agent-skills.ops.js +2 -2
- package/dist/platform/ops/agent-templates.ops.js +2 -2
- package/dist/platform/ops/agents.ops.js +11 -15
- package/dist/platform/ops/devices.ops.js +3 -1
- package/dist/platform/ops/inbox.ops.js +19 -0
- package/dist/platform/ops/org-settings.ops.js +14 -5
- package/dist/platform/ops/platform.ops.d.ts +9 -1
- package/dist/platform/ops/platform.ops.js +34 -12
- package/dist/platform/ops/requests.ops.js +3 -2
- package/dist/platform/ops/schedules.ops.d.ts +21 -0
- package/dist/platform/ops/schedules.ops.js +470 -0
- package/dist/platform/ops/skills.ops.js +3 -3
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +5 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/context/build.js +13 -4
- package/dist/runtime/context/compaction.js +6 -3
- package/dist/runtime/context/device-paths.d.ts +43 -21
- package/dist/runtime/context/device-paths.js +104 -21
- package/dist/runtime/context/run-context.d.ts +9 -0
- package/dist/runtime/context/run-context.js +8 -0
- package/dist/runtime/context/skills.d.ts +14 -1
- package/dist/runtime/context/skills.js +36 -5
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +16 -5
- package/dist/runtime/run-finish.d.ts +6 -1
- package/dist/runtime/run-finish.js +16 -2
- package/dist/runtime/run-queue.js +21 -2
- package/dist/runtime/run-worker.js +14 -33
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/runtime/subagents/definition.d.ts +32 -14
- package/dist/runtime/subagents/definition.js +106 -109
- package/dist/runtime/subagents/dispatch.js +4 -3
- package/dist/runtime/subagents/preamble.d.ts +2 -1
- package/dist/runtime/subagents/preamble.js +2 -1
- package/dist/runtime/waits.js +14 -4
- package/dist/sandbox/sandbox.service.d.ts +120 -10
- package/dist/sandbox/sandbox.service.js +335 -28
- package/dist/sandbox/tiers.d.ts +86 -0
- package/dist/sandbox/tiers.js +96 -0
- package/dist/schedules/effective-settings.d.ts +16 -0
- package/dist/schedules/effective-settings.js +17 -0
- package/dist/schedules/errors.d.ts +8 -0
- package/dist/schedules/errors.js +8 -0
- package/dist/schedules/fire.d.ts +118 -0
- package/dist/schedules/fire.js +625 -0
- package/dist/schedules/grant-rules.d.ts +94 -0
- package/dist/schedules/grant-rules.js +126 -0
- package/dist/schedules/job-ids.d.ts +32 -0
- package/dist/schedules/job-ids.js +27 -0
- package/dist/schedules/pause.d.ts +9 -0
- package/dist/schedules/pause.js +33 -0
- package/dist/schedules/run-tracker.d.ts +81 -0
- package/dist/schedules/run-tracker.js +333 -0
- package/dist/schedules/scan.job.d.ts +64 -0
- package/dist/schedules/scan.job.js +303 -0
- package/dist/schedules/schedule-math.d.ts +31 -0
- package/dist/schedules/schedule-math.js +223 -0
- package/dist/schedules/scheduled-tasks.service.d.ts +351 -0
- package/dist/schedules/scheduled-tasks.service.js +1193 -0
- package/dist/schedules/schedules.controller.d.ts +68 -0
- package/dist/schedules/schedules.controller.js +242 -0
- package/dist/schedules/schedules.module.d.ts +16 -0
- package/dist/schedules/schedules.module.js +65 -0
- package/dist/schedules/schedules.schemas.d.ts +316 -0
- package/dist/schedules/schedules.schemas.js +186 -0
- package/dist/schedules/store.d.ts +81 -0
- package/dist/schedules/store.js +390 -0
- package/dist/schedules/store.module.d.ts +6 -0
- package/dist/schedules/store.module.js +21 -0
- package/dist/schedules/types.d.ts +108 -0
- package/dist/schedules/types.js +1 -0
- package/dist/schedules/unattended.d.ts +117 -0
- package/dist/schedules/unattended.js +228 -0
- package/dist/setup/oauth-token-probe.js +8 -4
- package/dist/skills/agent-skills.service.d.ts +4 -8
- package/dist/skills/agent-skills.service.js +18 -53
- package/dist/skills/catalog.d.ts +65 -62
- package/dist/skills/catalog.js +109 -206
- package/dist/skills/conversation-catalog.d.ts +3 -3
- package/dist/skills/conversation-catalog.js +5 -12
- package/dist/skills/invoke.d.ts +2 -2
- package/dist/skills/skills.controller.d.ts +3 -1
- package/dist/skills/skills.service.d.ts +38 -37
- package/dist/skills/skills.service.js +168 -107
- package/dist/skills/usable.d.ts +57 -8
- package/dist/skills/usable.js +172 -38
- package/dist/tools/approvals.controller.d.ts +4 -2
- package/dist/tools/approvals.controller.js +17 -2
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +182 -7
- package/dist/tools/approvals.service.js +597 -13
- package/dist/tools/builtin-names.d.ts +25 -4
- package/dist/tools/builtin-names.js +45 -4
- package/dist/tools/builtins/builtin-tools.d.ts +8 -0
- package/dist/tools/builtins/builtin-tools.js +23 -2
- package/dist/tools/builtins/sandbox/bash.js +16 -7
- package/dist/tools/builtins/sandbox/common.d.ts +1 -1
- package/dist/tools/builtins/sandbox/common.js +33 -10
- package/dist/tools/builtins/sandbox/edit.js +7 -3
- package/dist/tools/builtins/sandbox/file-state.d.ts +31 -1
- package/dist/tools/builtins/sandbox/file-state.js +33 -3
- package/dist/tools/builtins/sandbox/write.js +8 -4
- package/dist/tools/builtins/schedules.d.ts +107 -0
- package/dist/tools/builtins/schedules.js +789 -0
- package/dist/tools/elicitation.d.ts +2 -0
- package/dist/tools/elicitation.js +1 -1
- package/dist/tools/fixed-ask.d.ts +7 -0
- package/dist/tools/fixed-ask.js +9 -0
- package/dist/tools/network-asks.d.ts +109 -0
- package/dist/tools/network-asks.js +221 -0
- package/dist/tools/pipeline.d.ts +53 -6
- package/dist/tools/pipeline.js +202 -13
- package/dist/tools/policy.d.ts +21 -8
- package/dist/tools/policy.js +63 -9
- package/dist/tools/registry.d.ts +10 -1
- package/dist/tools/tools.module.js +12 -0
- package/package.json +2 -2
- package/src/migrations/0113_scheduled_tasks.sql +108 -0
- package/src/migrations/0114_network_asks.sql +23 -0
- package/src/migrations/0115_network_requests.sql +28 -0
- package/src/migrations/0116_skills_default_on.sql +37 -0
- package/src/migrations/0117_sandbox_tiers.sql +11 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import type { Queue } from "bullmq";
|
|
2
|
+
import { AgentLookup } from "../agents/agent-lookup.js";
|
|
3
|
+
import type { ModelRef } from "../agents/definition.js";
|
|
4
|
+
import { ConversationAccess } from "../conversations/access.js";
|
|
5
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
6
|
+
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
7
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
8
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
10
|
+
import { DevicePolicyService } from "../local-devices/device-policy.service.js";
|
|
11
|
+
import type { KernelLogger } from "../log.js";
|
|
12
|
+
import { OrgLock } from "../orgs/org-lock.js";
|
|
13
|
+
import { ProviderRegistry } from "../runtime/providers.js";
|
|
14
|
+
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
15
|
+
import { ToolRegistry } from "../tools/registry.js";
|
|
16
|
+
import { type GrantContext, type GrantRefusalCode, grantRefusal, grantRefusalOf, networkGrantRefusal } from "./grant-rules.js";
|
|
17
|
+
import { ScheduledTaskStore } from "./store.js";
|
|
18
|
+
import type { ScheduleChat, ScheduledTask, ScheduledTaskGrant, ScheduleMode, SchedulePauseReason, TaskRun } from "./types.js";
|
|
19
|
+
export { type GrantContext, type GrantRefusalCode, grantRefusal, grantRefusalOf, networkGrantRefusal, };
|
|
20
|
+
/** When a task fires, before the zone is fixed (spec §5). */
|
|
21
|
+
export type TriggerInput = {
|
|
22
|
+
kind: "cron";
|
|
23
|
+
expr: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "once";
|
|
26
|
+
at: string;
|
|
27
|
+
};
|
|
28
|
+
/** A scheduled task that needs its creator's attention (spec §8): the inbox item's payload. */
|
|
29
|
+
export interface ScheduleAttention {
|
|
30
|
+
taskId: string;
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* `missing_grants`: the latest run was refused tools or connections the task lacks; `failed`:
|
|
34
|
+
* the latest settled run of an active task failed (its start included); else the pause reason.
|
|
35
|
+
*/
|
|
36
|
+
reason: SchedulePauseReason | "missing_grants" | "failed";
|
|
37
|
+
/** The person who paused the task (`reason: "admin"` names the admin); else null. */
|
|
38
|
+
pausedBy: {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
} | null;
|
|
42
|
+
/**
|
|
43
|
+
* `missing_grants` only: tool keys the latest run was refused and the task has no grant for now,
|
|
44
|
+
* `connection:<slug>` (connect that connector), or `network:<host>` (a domain the run was
|
|
45
|
+
* refused: the task has no grant for it, or the org's network allowlist no longer admits it).
|
|
46
|
+
*/
|
|
47
|
+
missing: string[];
|
|
48
|
+
/** The subset of `missing` the creator cannot pre-approve (the tool needs a higher role). */
|
|
49
|
+
needsRole: string[];
|
|
50
|
+
/**
|
|
51
|
+
* The `network:<host>` keys of `missing` outside the org's network allowlist: only an org admin
|
|
52
|
+
* can add the host (network ask-to-allow spec §8.3); the creator cannot pre-approve them.
|
|
53
|
+
*/
|
|
54
|
+
needsAdmin: string[];
|
|
55
|
+
/**
|
|
56
|
+
* `missing` holds `network:` keys and the task's device reports it takes no network grants from
|
|
57
|
+
* the deployment (`remoteGrants` off): a task grant would not reach it; its owner allows the
|
|
58
|
+
* domains locally (`capybara-device policy add allowedDomains <host>`).
|
|
59
|
+
*/
|
|
60
|
+
deviceRefuses: boolean;
|
|
61
|
+
/** `failed` only: the run's error; else null. */
|
|
62
|
+
error: string | null;
|
|
63
|
+
/** When the pause happened, or when the refused or failed run was due. */
|
|
64
|
+
at: Date;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A tool the creator pre-approves for the task; the service resolves its current `spec_hash`. Or a
|
|
68
|
+
* domain (`toolKey: "network:<host>"`, network ask-to-allow spec §8.1): one exact host the task's
|
|
69
|
+
* unattended runs may reach on the task's device, checked by `networkGrantRefusal`.
|
|
70
|
+
*/
|
|
71
|
+
export interface GrantInput {
|
|
72
|
+
toolKey: string;
|
|
73
|
+
/** The connector the tool comes from; when given it must be the tool's own. */
|
|
74
|
+
connectorId?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface CreateTaskInput {
|
|
77
|
+
agentId: string;
|
|
78
|
+
name: string;
|
|
79
|
+
prompt: string;
|
|
80
|
+
trigger: TriggerInput;
|
|
81
|
+
/** Absent: the creator's effective zone (account, browser, org, UTC). */
|
|
82
|
+
timeZone?: string;
|
|
83
|
+
mode: ScheduleMode;
|
|
84
|
+
/** `conversation` mode only. */
|
|
85
|
+
conversationId?: string;
|
|
86
|
+
/** `chat` mode only. */
|
|
87
|
+
chat?: ScheduleChat;
|
|
88
|
+
/**
|
|
89
|
+
* `new` mode only (a conversation or chat task runs with that conversation's selection and
|
|
90
|
+
* device): the model, which must resolve for the org, and an effort it declares.
|
|
91
|
+
*/
|
|
92
|
+
model?: ModelRef;
|
|
93
|
+
effort?: string;
|
|
94
|
+
deviceId?: string;
|
|
95
|
+
/**
|
|
96
|
+
* When the task ends; it must lie in the future. Absent or null: for a cron task, now + the
|
|
97
|
+
* org's `defaultExpiryDays` when set; otherwise never.
|
|
98
|
+
*/
|
|
99
|
+
expiresAt?: Date | null;
|
|
100
|
+
grants?: GrantInput[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Fields to change; `null` clears an optional one (`expiresAt: null` is the org's default expiry
|
|
104
|
+
* for a cron task, as on create). Grants change through their own methods.
|
|
105
|
+
*/
|
|
106
|
+
export interface UpdateTaskInput {
|
|
107
|
+
agentId?: string;
|
|
108
|
+
name?: string;
|
|
109
|
+
prompt?: string;
|
|
110
|
+
trigger?: TriggerInput;
|
|
111
|
+
timeZone?: string;
|
|
112
|
+
mode?: ScheduleMode;
|
|
113
|
+
conversationId?: string | null;
|
|
114
|
+
chat?: ScheduleChat | null;
|
|
115
|
+
model?: ModelRef | null;
|
|
116
|
+
effort?: string | null;
|
|
117
|
+
deviceId?: string | null;
|
|
118
|
+
expiresAt?: Date | null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Where a grant write comes from: `fromSession` only for a person in a signed-in web session (not a
|
|
122
|
+
* personal access token, the Platform tool or the schedule tools). Network domains are approved
|
|
123
|
+
* only there (network ask-to-allow spec §8.1): an agent must never pre-approve a domain for itself.
|
|
124
|
+
*/
|
|
125
|
+
export interface GrantWriteSource {
|
|
126
|
+
fromSession?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/** Who acts on a task: the service reads their live role itself and decides by that one. */
|
|
129
|
+
export interface ScheduleActor {
|
|
130
|
+
accountId: string;
|
|
131
|
+
}
|
|
132
|
+
/** One of the agent's tools as the task form offers it (`GET …/schedules/grantable-tools`). */
|
|
133
|
+
export interface GrantableTool {
|
|
134
|
+
key: string;
|
|
135
|
+
/** The tool's display title, when it declares one. */
|
|
136
|
+
title: string | null;
|
|
137
|
+
source: "builtin" | "plugin" | "connector";
|
|
138
|
+
connectorId: string | null;
|
|
139
|
+
grantable: boolean;
|
|
140
|
+
/** Why not, when not grantable. */
|
|
141
|
+
reason: GrantRefusalCode | null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* A grant as the task page shows it: `stale` when the tool's definition changed or the tool left
|
|
145
|
+
* (spec §7); null when the agent's tools cannot be read now.
|
|
146
|
+
*/
|
|
147
|
+
export interface ScheduledTaskGrantView extends ScheduledTaskGrant {
|
|
148
|
+
stale: boolean | null;
|
|
149
|
+
}
|
|
150
|
+
/** The latest settled (completed, failed or skipped) non-trial run of a task. */
|
|
151
|
+
export interface TaskLastRun {
|
|
152
|
+
status: "completed" | "failed" | "skipped";
|
|
153
|
+
skipReason: TaskRun["skipReason"];
|
|
154
|
+
/** When it fired; its tick for a skipped one. */
|
|
155
|
+
at: Date;
|
|
156
|
+
}
|
|
157
|
+
/** A task in a list, with its latest settled run. */
|
|
158
|
+
export type ScheduledTaskListItem = ScheduledTask & {
|
|
159
|
+
lastRun: TaskLastRun | null;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* A chat the creator can point a `chat` task at (spec §8): their DM with a connection's bot
|
|
163
|
+
* (a thread row of theirs, archived included), or a group they have talked in when the channel
|
|
164
|
+
* has threads.
|
|
165
|
+
*/
|
|
166
|
+
export interface ChatTarget {
|
|
167
|
+
connectionId: string;
|
|
168
|
+
connectionName: string;
|
|
169
|
+
plugin: string;
|
|
170
|
+
/** The connection's agent: a chat task's agent. */
|
|
171
|
+
agentId: string;
|
|
172
|
+
chatId: string;
|
|
173
|
+
chatType: "dm" | "group";
|
|
174
|
+
/** A name for people: the connection's name (and the group's chat id). */
|
|
175
|
+
label: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Scheduled tasks for people (spec §5, §7–§10): create, edit, pause, resume, delete, their runs
|
|
179
|
+
* and grants. Every write runs in one transaction under the org row lock (`OrgLock`), which also
|
|
180
|
+
* serializes the per-member and per-org caps, re-reads the actor's role there, and holds the task
|
|
181
|
+
* row (`FOR UPDATE`) so the scanner skips it until the write commits.
|
|
182
|
+
*
|
|
183
|
+
* Roles: `schedules.use` (member) creates and edits one's own tasks; `schedules.manage` (admin)
|
|
184
|
+
* lists, pauses, resumes and deletes any task of the org, never edits another person's (the task
|
|
185
|
+
* runs as its creator). A task the caller may not see is `schedule.not_found`.
|
|
186
|
+
*/
|
|
187
|
+
export declare class ScheduledTasksService {
|
|
188
|
+
private readonly db;
|
|
189
|
+
readonly txHost: TransactionHost;
|
|
190
|
+
private readonly config;
|
|
191
|
+
private readonly store;
|
|
192
|
+
private readonly orgLock;
|
|
193
|
+
private readonly agents;
|
|
194
|
+
private readonly access;
|
|
195
|
+
private readonly tools;
|
|
196
|
+
private readonly extensions;
|
|
197
|
+
/** A task's model must resolve for the org and declare its effort (as a message's switch). */
|
|
198
|
+
private readonly providers;
|
|
199
|
+
private readonly log;
|
|
200
|
+
/** "Run now" enqueues the fire job (consumed by the worker role). */
|
|
201
|
+
private readonly maintenance;
|
|
202
|
+
/** Network grants: the org's effective egress (network ask-to-allow spec §8.1). */
|
|
203
|
+
private readonly sandbox;
|
|
204
|
+
/** Network grants: the task's device's local policy summary (`remoteGrants`). */
|
|
205
|
+
private readonly devicePolicy;
|
|
206
|
+
constructor(db: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">, store: ScheduledTaskStore, orgLock: Pick<OrgLock, "lockAndAuthorize">, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">, tools: Pick<ToolRegistry, "forAgent">, extensions: Pick<ExtensionRegistry, "list">,
|
|
207
|
+
/** A task's model must resolve for the org and declare its effort (as a message's switch). */
|
|
208
|
+
providers: Pick<ProviderRegistry, "resolve">, log: Pick<KernelLogger, "warn">,
|
|
209
|
+
/** "Run now" enqueues the fire job (consumed by the worker role). */
|
|
210
|
+
maintenance: Pick<Queue, "add">,
|
|
211
|
+
/** Network grants: the org's effective egress (network ask-to-allow spec §8.1). */
|
|
212
|
+
sandbox: Pick<SandboxService, "ceilingLimits" | "devicePolicy">,
|
|
213
|
+
/** Network grants: the task's device's local policy summary (`remoteGrants`). */
|
|
214
|
+
devicePolicy: Pick<DevicePolicyService, "summary">);
|
|
215
|
+
create(orgId: string, accountId: string, input: CreateTaskInput, browserTimeZone?: string, source?: GrantWriteSource): Promise<ScheduledTask>;
|
|
216
|
+
/** Creator only: an org admin gets `schedule.forbidden`, anyone else `schedule.not_found`. */
|
|
217
|
+
update(orgId: string, accountId: string, id: string, patch: UpdateTaskInput): Promise<ScheduledTask>;
|
|
218
|
+
/** The creator, or an org admin (`schedules.manage`); a task not active is returned as is. */
|
|
219
|
+
pause(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTask>;
|
|
220
|
+
/**
|
|
221
|
+
* The creator (`schedules.use`), or an org admin. The next run is computed from now (missed ticks
|
|
222
|
+
* are not caught up) and the failure count starts over. An ended task cannot be resumed.
|
|
223
|
+
*/
|
|
224
|
+
resume(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTask>;
|
|
225
|
+
/** The creator, or an org admin. */
|
|
226
|
+
remove(orgId: string, actor: ScheduleActor, id: string): Promise<void>;
|
|
227
|
+
/** The creator, or an org admin. */
|
|
228
|
+
get(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTask>;
|
|
229
|
+
/** The actor's own tasks; `all` (org admins only, else `forbidden`): every task of the org. */
|
|
230
|
+
list(orgId: string, actor: ScheduleActor, opts?: {
|
|
231
|
+
all?: boolean;
|
|
232
|
+
conversationId?: string;
|
|
233
|
+
}): Promise<ScheduledTaskListItem[]>;
|
|
234
|
+
/**
|
|
235
|
+
* The tasks of `tasks` that post into the conversation: a `conversation` task naming it, or a
|
|
236
|
+
* `chat` task whose chat the conversation is a thread of (spec §10 side panel).
|
|
237
|
+
*/
|
|
238
|
+
private postingInto;
|
|
239
|
+
/** Each task with its latest settled non-trial run, in one query. */
|
|
240
|
+
private withLastRuns;
|
|
241
|
+
/**
|
|
242
|
+
* The chats the caller can point a `chat` task at (spec §8): per active connection of the org,
|
|
243
|
+
* their DM threads (archived included) and, on a channel with threads, the groups they have a
|
|
244
|
+
* thread in. Members up (`schedules.use`, the route's).
|
|
245
|
+
*/
|
|
246
|
+
chatTargets(orgId: string, accountId: string): Promise<ChatTarget[]>;
|
|
247
|
+
/**
|
|
248
|
+
* The agent's tools (connector tools included) as a task's grant picker offers them, each
|
|
249
|
+
* grantable or why not by {@link grantRefusalOf}, the rule {@link addGrants} applies.
|
|
250
|
+
* `agent.not_found` when the caller can't use the agent.
|
|
251
|
+
*/
|
|
252
|
+
grantableTools(orgId: string, accountId: string, agentId: string): Promise<GrantableTool[]>;
|
|
253
|
+
/** The task's runs, latest first (default 50, at most 200); visible as {@link get}. */
|
|
254
|
+
runs(orgId: string, actor: ScheduleActor, id: string, limit?: number): Promise<TaskRun[]>;
|
|
255
|
+
/** The task's grants; visible as {@link get}. */
|
|
256
|
+
grants(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTaskGrantView[]>;
|
|
257
|
+
/**
|
|
258
|
+
* Creator only; each grant is checked as at create (spec §7); network domains only from a web
|
|
259
|
+
* session (`source.fromSession`).
|
|
260
|
+
*/
|
|
261
|
+
addGrants(orgId: string, accountId: string, id: string, grants: GrantInput[], source?: GrantWriteSource): Promise<ScheduledTaskGrant[]>;
|
|
262
|
+
/** Creator only; removing a grant the task does not have is a no-op. */
|
|
263
|
+
removeGrant(orgId: string, accountId: string, id: string, toolKey: string): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* The creator's scheduled tasks that need attention (spec §8), derived live: a paused task whose
|
|
266
|
+
* reason is not `creator` (resuming clears it), an active task whose latest settled non-trial
|
|
267
|
+
* run failed (the next good run clears it), and a task whose latest settled non-trial run was
|
|
268
|
+
* refused tools, connections or domains (a tool granted since drops out, a domain too while the
|
|
269
|
+
* org's network allowlist admits it; the next clean run clears the rest). Newest first.
|
|
270
|
+
*/
|
|
271
|
+
attentionFor(orgId: string, accountId: string): Promise<ScheduleAttention[]>;
|
|
272
|
+
private roleOrNull;
|
|
273
|
+
/**
|
|
274
|
+
* The agent's tools by key (their `requiredRole` and definition hash) as the creator sees them;
|
|
275
|
+
* empty when the agent is gone or hidden (the task is paused for that anyway); null when they
|
|
276
|
+
* cannot be read now (logged: the caller then cannot tell what is stale or needs a role).
|
|
277
|
+
*/
|
|
278
|
+
private agentToolFacts;
|
|
279
|
+
/**
|
|
280
|
+
* Pauses an active live task for `reason` in the caller's transaction `t` (the fire job, the
|
|
281
|
+
* delivery path); `by` is the account that caused it, null for the kernel. A task already
|
|
282
|
+
* paused or ended keeps its state and reason.
|
|
283
|
+
*/
|
|
284
|
+
pauseFor(t: KernelSchemaDb, taskId: string, reason: SchedulePauseReason, by: string | null): Promise<void>;
|
|
285
|
+
/**
|
|
286
|
+
* "Run now" (spec §6), creator only: a task run for the request time, outside the schedule (no
|
|
287
|
+
* unique-key conflict with a tick, and `next_run_at` does not move), fired at once through the
|
|
288
|
+
* fire job after the commit. `trial`: an attended trial run whose approvals become the task's
|
|
289
|
+
* grants (§7). Counted in the rate limit like any run. An ended task cannot run; a paused one
|
|
290
|
+
* can (only its creator gets here: the run is `manual`, which the fire's paused check lets by).
|
|
291
|
+
*/
|
|
292
|
+
runNow(orgId: string, accountId: string, id: string, opts: {
|
|
293
|
+
trial: boolean;
|
|
294
|
+
}): Promise<TaskRun>;
|
|
295
|
+
/** The live role of a member of the org; not a member → `schedule.not_found`. */
|
|
296
|
+
private liveRole;
|
|
297
|
+
/** The actor's own task, row-locked; another's: `schedule.forbidden` for an admin, else 404. */
|
|
298
|
+
private lockOwn;
|
|
299
|
+
/**
|
|
300
|
+
* A task the actor may pause, resume or delete, row-locked under the org lock: their own (with
|
|
301
|
+
* `creatorAction`), or any as an org admin (`schedules.manage`); otherwise `schedule.not_found`.
|
|
302
|
+
*/
|
|
303
|
+
private lockManaged;
|
|
304
|
+
/**
|
|
305
|
+
* Where runs go (spec §3, §8), checked against the creator:
|
|
306
|
+
* - the mode and its fields agree (`conversation`: a conversation and no chat; `chat`: a chat
|
|
307
|
+
* and no conversation; `new`: neither);
|
|
308
|
+
* - `conversation`: the creator's live chat conversation with this agent, still accessible;
|
|
309
|
+
* - `chat`: the connection is active and bound to this agent; a DM needs a thread row (archived
|
|
310
|
+
* allowed) of the creator in that chat; a group needs the creator's thread row in the group
|
|
311
|
+
* and a channel with threads.
|
|
312
|
+
*/
|
|
313
|
+
private checkTarget;
|
|
314
|
+
/** The channel's declared features; undefined when its extension is not loaded here. */
|
|
315
|
+
private channelFeatures;
|
|
316
|
+
/**
|
|
317
|
+
* A task's model, effort and device (spec §4): `new` mode only, since a conversation or chat
|
|
318
|
+
* task runs with that conversation's selection and device (a task must not switch a person's
|
|
319
|
+
* conversation for their later turns), so another mode refuses them (`validation_failed`).
|
|
320
|
+
* The model must resolve for the org (`agent.model_unavailable`, as a message's switch) and
|
|
321
|
+
* declare the effort (`validation_failed`); the device must be one of the creator's
|
|
322
|
+
* (`checkDevice`, when `deviceChanged`).
|
|
323
|
+
*/
|
|
324
|
+
private checkPick;
|
|
325
|
+
/** The device is one of the creator's live personal devices in the org. */
|
|
326
|
+
private checkDevice;
|
|
327
|
+
/**
|
|
328
|
+
* The grants as stored: each tool resolved among the agent's tools now (its `spec_hash` and
|
|
329
|
+
* source connector), refused by {@link grantRefusal}; each `network:<host>` key (lower-cased)
|
|
330
|
+
* refused by {@link networkGrantRefusal} against the org's effective egress and the summary of
|
|
331
|
+
* `deviceId`, the task's device (null: none can be determined, the device rule is skipped),
|
|
332
|
+
* stored with `spec_hash` `network` and no connector (plan P-D7), and only when
|
|
333
|
+
* `source.fromSession` (a person on the task page; never a token, the Platform tool or the
|
|
334
|
+
* schedule tools). Duplicates keep the last.
|
|
335
|
+
*/
|
|
336
|
+
private resolveGrants;
|
|
337
|
+
/**
|
|
338
|
+
* What a network grant is checked against (network ask-to-allow spec §8.1): the network of the
|
|
339
|
+
* org's sandbox ceiling now (sandbox dev tiers spec §4.2) and the local policy summary of the
|
|
340
|
+
* task's device (null without a device or a connected machine).
|
|
341
|
+
*/
|
|
342
|
+
private networkGrantContext;
|
|
343
|
+
/**
|
|
344
|
+
* The device a task's runs use, as far as the task tells: a `new` task's own device, a
|
|
345
|
+
* `conversation` task's conversation's device (in the org); null when none is chosen, and for a
|
|
346
|
+
* chat task: its IM conversation's device is not known until it runs, so the device rule of a
|
|
347
|
+
* network grant is skipped there (the device still refuses grants at the command when its owner
|
|
348
|
+
* turned them off, and the run notes it).
|
|
349
|
+
*/
|
|
350
|
+
private taskDeviceOf;
|
|
351
|
+
}
|